* target/i386: qemu-vmsr-helper fixes

* target/i386: mask off SGX/SGX_LC feature words for non-PC machine
 * tests/vm/openbsd: Install tomli
 * fix issue with 64-bit features (vmx kvm-unit-tests)
 -----BEGIN PGP SIGNATURE-----
 
 iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmaqHL4UHHBib256aW5p
 QHJlZGhhdC5jb20ACgkQv/vSX3jHroPuuwgAhZwTHl1MkjIbIX7IRq39ORmOmk9a
 vNqn32MLsUnSpV1JYrwzLgsNciTDhNkEL56Y4XwFbSUUyen0vvmcEH+/bCVKWb98
 jBk0iHXzfkk3GBd/ZLd4NW/LEeOZY4YBFNzyfhQGP47vSUAle/+VDdqukfJ9rj3J
 o8Mx3YJjYcvoI21WZyhyLGdJtj/yBPwCfxrmhhJAWctIES78/sp1tP0UfmFcysss
 nd7PrAoAXPc2MhBTJk7IwyXSJCnGnDsE4rQXqiVV+TN0S60Zcz+1jzqx0vgzHAk4
 2oFKdnqxwSO8A2LVDdFpkSAM9F+LFv5a1hrHPikuBjIad9WdDIoPNU6qiw==
 =9vso
 -----END PGP SIGNATURE-----

Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging

* target/i386: qemu-vmsr-helper fixes
* target/i386: mask off SGX/SGX_LC feature words for non-PC machine
* tests/vm/openbsd: Install tomli
* fix issue with 64-bit features (vmx kvm-unit-tests)

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmaqHL4UHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroPuuwgAhZwTHl1MkjIbIX7IRq39ORmOmk9a
# vNqn32MLsUnSpV1JYrwzLgsNciTDhNkEL56Y4XwFbSUUyen0vvmcEH+/bCVKWb98
# jBk0iHXzfkk3GBd/ZLd4NW/LEeOZY4YBFNzyfhQGP47vSUAle/+VDdqukfJ9rj3J
# o8Mx3YJjYcvoI21WZyhyLGdJtj/yBPwCfxrmhhJAWctIES78/sp1tP0UfmFcysss
# nd7PrAoAXPc2MhBTJk7IwyXSJCnGnDsE4rQXqiVV+TN0S60Zcz+1jzqx0vgzHAk4
# 2oFKdnqxwSO8A2LVDdFpkSAM9F+LFv5a1hrHPikuBjIad9WdDIoPNU6qiw==
# =9vso
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 31 Jul 2024 09:15:10 PM AEST
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [full]

* tag 'for-upstream' of https://gitlab.com/bonzini/qemu:
  qemu-vmsr-helper: implement --verbose/-v
  qemu-vmsr-helper: fix socket loop breakage
  target/i386: Clean up error cases for vmsr_read_thread_stat()
  target/i386: Fix typo that assign same value twice
  target/i386/cpu: Mask off SGX/SGX_LC feature words for non-PC machine
  target/i386/cpu: Add dependencies of CPUID 0x12 leaves
  target/i386/cpu: Explicitly express SGX_LC and SGX feature words dependency
  target/i386/cpu: Remove unnecessary SGX feature words checks
  target/i386: Change unavail from u32 to u64
  tests/vm/openbsd: Install tomli

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2024-08-01 07:31:49 +10:00
commit e9d2db818f
8 changed files with 69 additions and 31 deletions

View File

@ -32,6 +32,11 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState)); memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState));
} }
bool check_sgx_support(void)
{
return false;
}
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
{ {
return true; return true;

View File

@ -266,6 +266,14 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict)
size); size);
} }
bool check_sgx_support(void)
{
if (!object_dynamic_cast(qdev_get_machine(), TYPE_PC_MACHINE)) {
return false;
}
return true;
}
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
{ {
PCMachineState *pcms = PCMachineState *pcms =

View File

@ -58,6 +58,7 @@ typedef struct SGXEPCState {
int nr_sections; int nr_sections;
} SGXEPCState; } SGXEPCState;
bool check_sgx_support(void);
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size); bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size);
void sgx_epc_build_srat(GArray *table_data); void sgx_epc_build_srat(GArray *table_data);

View File

@ -1730,6 +1730,22 @@ static FeatureDep feature_dependencies[] = {
.from = { FEAT_7_1_EAX, CPUID_7_1_EAX_WRMSRNS }, .from = { FEAT_7_1_EAX, CPUID_7_1_EAX_WRMSRNS },
.to = { FEAT_7_1_EAX, CPUID_7_1_EAX_FRED }, .to = { FEAT_7_1_EAX, CPUID_7_1_EAX_FRED },
}, },
{
.from = { FEAT_7_0_EBX, CPUID_7_0_EBX_SGX },
.to = { FEAT_7_0_ECX, CPUID_7_0_ECX_SGX_LC },
},
{
.from = { FEAT_7_0_EBX, CPUID_7_0_EBX_SGX },
.to = { FEAT_SGX_12_0_EAX, ~0ull },
},
{
.from = { FEAT_7_0_EBX, CPUID_7_0_EBX_SGX },
.to = { FEAT_SGX_12_0_EBX, ~0ull },
},
{
.from = { FEAT_7_0_EBX, CPUID_7_0_EBX_SGX },
.to = { FEAT_SGX_12_1_EAX, ~0ull },
},
}; };
typedef struct X86RegisterInfo32 { typedef struct X86RegisterInfo32 {
@ -6039,7 +6055,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
{ {
FeatureWordInfo *wi = &feature_word_info[w]; FeatureWordInfo *wi = &feature_word_info[w];
uint64_t r = 0; uint64_t r = 0;
uint32_t unavail = 0; uint64_t unavail = 0;
if (kvm_enabled()) { if (kvm_enabled()) {
switch (wi->type) { switch (wi->type) {
@ -6087,6 +6103,21 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
} }
break; break;
case FEAT_7_0_EBX:
#ifndef CONFIG_USER_ONLY
if (!check_sgx_support()) {
unavail = CPUID_7_0_EBX_SGX;
}
#endif
break;
case FEAT_7_0_ECX:
#ifndef CONFIG_USER_ONLY
if (!check_sgx_support()) {
unavail = CPUID_7_0_ECX_SGX_LC;
}
#endif
break;
default: default:
break; break;
} }
@ -6537,8 +6568,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
case 7: case 7:
/* Structured Extended Feature Flags Enumeration Leaf */ /* Structured Extended Feature Flags Enumeration Leaf */
if (count == 0) { if (count == 0) {
uint32_t eax_0_unused, ebx_0, ecx_0, edx_0_unused;
/* Maximum ECX value for sub-leaves */ /* Maximum ECX value for sub-leaves */
*eax = env->cpuid_level_func7; *eax = env->cpuid_level_func7;
*ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */ *ebx = env->features[FEAT_7_0_EBX]; /* Feature flags */
@ -6547,23 +6576,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
*ecx |= CPUID_7_0_ECX_OSPKE; *ecx |= CPUID_7_0_ECX_OSPKE;
} }
*edx = env->features[FEAT_7_0_EDX]; /* Feature flags */ *edx = env->features[FEAT_7_0_EDX]; /* Feature flags */
/*
* SGX cannot be emulated in software. If hardware does not
* support enabling SGX and/or SGX flexible launch control,
* then we need to update the VM's CPUID values accordingly.
*/
x86_cpu_get_supported_cpuid(0x7, 0,
&eax_0_unused, &ebx_0,
&ecx_0, &edx_0_unused);
if ((*ebx & CPUID_7_0_EBX_SGX) && !(ebx_0 & CPUID_7_0_EBX_SGX)) {
*ebx &= ~CPUID_7_0_EBX_SGX;
}
if ((*ecx & CPUID_7_0_ECX_SGX_LC)
&& (!(*ebx & CPUID_7_0_EBX_SGX) || !(ecx_0 & CPUID_7_0_ECX_SGX_LC))) {
*ecx &= ~CPUID_7_0_ECX_SGX_LC;
}
} else if (count == 1) { } else if (count == 1) {
*eax = env->features[FEAT_7_1_EAX]; *eax = env->features[FEAT_7_1_EAX];
*edx = env->features[FEAT_7_1_EDX]; *edx = env->features[FEAT_7_1_EDX];

View File

@ -2694,8 +2694,8 @@ static void *kvm_msr_energy_thread(void *data)
while (true) { while (true) {
/* Get all qemu threads id */ /* Get all qemu threads id */
g_autofree pid_t *thread_ids = g_autofree pid_t *thread_ids
thread_ids = vmsr_get_thread_ids(vmsr->pid, &num_threads); = vmsr_get_thread_ids(vmsr->pid, &num_threads);
if (thread_ids == NULL) { if (thread_ids == NULL) {
goto clean; goto clean;

View File

@ -270,7 +270,7 @@ void vmsr_read_thread_stat(pid_t pid,
FILE *file = fopen(path, "r"); FILE *file = fopen(path, "r");
if (file == NULL) { if (file == NULL) {
pid = -1; error_report("Error opening %s", path_name);
return; return;
} }
@ -279,7 +279,8 @@ void vmsr_read_thread_stat(pid_t pid,
" %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %*u %*u %u", " %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %*u %*u %u",
utime, stime, cpu_id) != 3) utime, stime, cpu_id) != 3)
{ {
pid = -1; fclose(file);
error_report("Error fscanf did not report the right amount of items");
return; return;
} }

View File

@ -32,6 +32,7 @@ class OpenBSDVM(basevm.BaseVM):
"pkgconf", "pkgconf",
"bzip2", "xz", "bzip2", "xz",
"ninja", "ninja",
"py3-tomli",
# gnu tools # gnu tools
"bash", "bash",

View File

@ -54,6 +54,7 @@ static enum { RUNNING, TERMINATE, TERMINATING } state;
static QIOChannelSocket *server_ioc; static QIOChannelSocket *server_ioc;
static int server_watch; static int server_watch;
static int num_active_sockets = 1; static int num_active_sockets = 1;
static bool verbose;
#ifdef CONFIG_LIBCAP_NG #ifdef CONFIG_LIBCAP_NG
static int uid = -1; static int uid = -1;
@ -227,19 +228,17 @@ static void coroutine_fn vh_co_entry(void *opaque)
&peer_pid, &peer_pid,
&local_err); &local_err);
if (r < 0) { if (r < 0) {
error_report_err(local_err);
goto out; goto out;
} }
while (r < 0) { for (;;) {
/* /*
* Read the requested MSR * Read the requested MSR
* Only RAPL MSR in rapl-msr-index.h is allowed * Only RAPL MSR in rapl-msr-index.h is allowed
*/ */
r = qio_channel_read_all(QIO_CHANNEL(client->ioc), r = qio_channel_read_all_eof(QIO_CHANNEL(client->ioc),
(char *) &request, sizeof(request), &local_err); (char *) &request, sizeof(request), &local_err);
if (r < 0) { if (r <= 0) {
error_report_err(local_err);
break; break;
} }
@ -261,11 +260,19 @@ static void coroutine_fn vh_co_entry(void *opaque)
sizeof(vmsr), sizeof(vmsr),
&local_err); &local_err);
if (r < 0) { if (r < 0) {
error_report_err(local_err);
break; break;
} }
} }
out: out:
if (local_err) {
if (!verbose) {
error_free(local_err);
} else {
error_report_err(local_err);
}
}
object_unref(OBJECT(client->ioc)); object_unref(OBJECT(client->ioc));
g_free(client); g_free(client);
} }
@ -429,6 +436,9 @@ int main(int argc, char **argv)
case 'd': case 'd':
daemonize = true; daemonize = true;
break; break;
case 'v':
verbose = true;
break;
case 'T': case 'T':
trace_opt_parse(optarg); trace_opt_parse(optarg);
break; break;