Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions KVM/qemu/buslock_de.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
- buslock_de:
type = buslock_de
only Linux
virt_test_type = qemu
vm_accelerator = kvm
force_create_image = no
remove_image = no
start_vm = yes
kill_vm = yes
auto_cpu_model = "no"
cpu_model = host
vga = std
test_dir = '/tmp'
reboot_settle_time = 20
cmdline_check_retry = 3
cmdline_check_retry_sleep = 5
cpuid_src_subdir = tools/cpuid_check
cpuid_source_file = 'cpuid_check.c'
cpuid_exec_file = 'cpuid_check'
cpuid = "7 0 0 0 c 24"
deps_subdir = "bus_lock"
bus_lock_source_file = bus_lock.c
bus_lock_exec_file = bus_lock.out
bus_lock_common_file = bus_lock_common.h
variants:
- buslock_de_warn:
split_lock_mode = warn
expected_msr_bit = 1
expected_dmesg_delta = ge1
check_core_dump = yes
expect_exception_nmi = yes
- buslock_de_off:
split_lock_mode = off
expected_msr_bit = 0
expected_dmesg_delta = zero
expect_exception_nmi = no
- buslock_de_fatal:
split_lock_mode = fatal
expected_msr_bit = 1
expected_dmesg_delta = zero
expect_bus_error = yes
expect_exception_nmi = yes
- buslock_de_ratelimit:
split_lock_mode = ratelimit:5
bus_lock_source_file = bus_lock_10.c
bus_lock_exec_file = bus_lock_10.out
expected_msr_bit = 1
expected_dmesg_delta = exact
expected_dmesg_count = 5
expect_exception_nmi = yes
ratelimit_retry = yes
variants:
- vm:
- td:
machine_type_extra_params = "kernel-irqchip=split"
vm_secure_guest_type = tdx
bus_lock_source_file_tdx = bus_lock_64.c
bus_lock_exec_file_tdx = bus_lock_64.out
24 changes: 24 additions & 0 deletions KVM/qemu/deps/bus_lock/bus_lock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2026 Intel Corporation

#include <stdio.h>
#include <stdlib.h>

#include "bus_lock_common.h"

int main(void)
{
unsigned char *buffer;
int *int_ptr;
int cache_line_size;

cache_line_size = get_cache_line_size_cpuid();
printf("The cache line size is %d bytes.\n", cache_line_size);

buffer = (unsigned char *)aligned_alloc(cache_line_size,
2 * cache_line_size);
int_ptr = (int *)(buffer + cache_line_size - 1);
locked_add_1(int_ptr);

return 0;
}
27 changes: 27 additions & 0 deletions KVM/qemu/deps/bus_lock/bus_lock_10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2026 Intel Corporation

#include <stdio.h>
#include <stdlib.h>

#include "bus_lock_common.h"

int main(void)
{
unsigned char *buffer;
int *int_ptr;
int cache_line_size;
int idx;

cache_line_size = get_cache_line_size_cpuid();
printf("The cache line size is %d bytes.\n", cache_line_size);

buffer = (unsigned char *)aligned_alloc(cache_line_size,
2 * cache_line_size);
int_ptr = (int *)(buffer + cache_line_size - 1);

for (idx = 0; idx < 10; idx++)
locked_add_1(int_ptr);

return 0;
}
33 changes: 33 additions & 0 deletions KVM/qemu/deps/bus_lock/bus_lock_64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2026 Intel Corporation

#include <stdio.h>
#include <stdlib.h>

#include "bus_lock_common.h"

int main(void)
{
unsigned char *buffer;
int *int_ptr;
int cache_line_size;
int idx;

cache_line_size = 64;
printf("The cache line size is %d bytes.\n", cache_line_size);

/* allocate a cache_line_size aligned memory */
buffer = (unsigned char *)aligned_alloc(cache_line_size,
2 * cache_line_size);

/*
* Increment the pointer by cache_line_size - 1, making it 4-byte int_ptr that
* across two cache line
*/
int_ptr = (int *)(buffer + cache_line_size - 1);

for (idx = 0; idx < 10; idx++)
locked_add_1(int_ptr);

return 0;
}
37 changes: 37 additions & 0 deletions KVM/qemu/deps/bus_lock/bus_lock_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2026 Intel Corporation */

#ifndef BUS_LOCK_COMMON_H
#define BUS_LOCK_COMMON_H

#define CPUID_80000006_ECX_CACHE_LINE_SIZE 0x000000FF

static inline void do_cpuid(int leaf, int subleaf, int *eax, int *ebx,
int *ecx, int *edx)
{
asm volatile("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (leaf), "2" (subleaf)
: "memory");
}

static inline void locked_add_1(int *ptr)
{
asm volatile("lock; addl $1,%0\n\t"
: "+m"(*ptr)
:
: "memory");
}

static inline int get_cache_line_size_cpuid(void)
{
int eax, ecx;

do_cpuid(0x80000006, 0, &eax, &eax, &ecx, &eax);
return ecx & CPUID_80000006_ECX_CACHE_LINE_SIZE;
}

#endif
63 changes: 63 additions & 0 deletions KVM/qemu/provider/cpuid_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python3

# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2026 Intel Corporation

"""Shared helpers for compiling and running cpuid check tools."""

from avocado.core import exceptions
from avocado.utils import process

from virttest import utils_package


def prepare_cpuid(test, params, src_dir, vm=None, session=None):
"""
Compile the cpuid test tool in host or guest.

:param test: QEMU test object
:param params: Dictionary with the test parameters
:param src_dir: Test tool source code directory of absolute path
:param vm: The VM object
:param session: Guest session
:return: The executable test tool with absolute path
"""
source_file = params["source_file"]
exec_file = params["exec_file"]
src_cpuid = src_dir + "/" + source_file
if session:
test_dir = params["test_dir"]
vm.copy_files_to(src_cpuid, test_dir)
else:
test_dir = src_dir

if not utils_package.package_install("gcc", session):
test.cancel("Failed to install package gcc.")

compile_cmd = "cd %s && gcc %s -o %s" % (test_dir, source_file, exec_file)
if session:
status = session.cmd_status(compile_cmd)
else:
status = process.system(compile_cmd, shell=True)
if status:
raise exceptions.TestError("Test suite compile failed.")

return test_dir + "/" + exec_file


def check_cpuid(cpuid_arg, exec_bin, session=None):
"""
Run cpuid test in host or guest.

:param cpuid_arg: The feature to be checked
:param exec_bin: The executable binary tool with absolute path
:param session: Guest session
:return: Command exit status
"""
check_cmd = "%s %s" % (exec_bin, cpuid_arg)
func = process.getstatusoutput
if session:
func = session.cmd_status_output
status, output = func(check_cmd)

return status
Loading
Loading