Virtuozzo QEMU development (svt-core@virtuozzo.com)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: andrey.zhadchenko@virtuozzo.com
Cc: svt-core@virtuozzo.com, den@openvz.org
Subject: [PATCH v3 hci-8.0/hci-8.1 6/6] i386: keep SVM leaf features without svm on vz types up to vz9.2.0 #PSBM-144630
Date: Thu, 29 Oct 2026 13:25:27 +0100	[thread overview]
Message-ID: <20261029122527.365104-7-den@openvz.org> (raw)
In-Reply-To: <20261029122527.365104-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

Since commit 730319aef0f ("i386: Mask SVM features if nested SVM is
disabled", QEMU 5.1) the features of CPUID leaf 0x8000000a are dropped
when svm is off. QEMU 2.12 on Vz7 kept them, and a Vz7 host-model
guest runs with svm=off,npt=on,nrip-save=on. Moving it to a newer QEMU
fails in libvirt (PSBM-144630):

  guest CPU doesn't match specification: missing features: npt,nrip-save

Add x-svm-features-compat and turn it on in pc_vz_9_2_compat: under KVM
requested SVM leaf features stay when svm is off, both against the
dependency on svm and against the host. The guest sees the CPUID it
saw on QEMU 2.12: cpu_x86_cpuid() reports leaf 0x8000000a only with
svm, and the kept features raise the automatic xlevel to 0x8000000a
as they did there. With svm off every FEAT_SVM bit is kept, including
the ones -cpu host takes from the host, which the guest cannot see
either. TCG keeps dropping the features, since it cannot provide them.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
 hw/i386/pc.c      |  1 +
 target/i386/cpu.c | 13 +++++++++++++
 target/i386/cpu.h |  1 +
 3 files changed, 15 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 5b2b2de4064..9b6b51bd5f7 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -553,6 +553,7 @@ GlobalProperty pc_vz_9_2_compat[] = {
     { TYPE_X86_CPU, "x-spec-ctrl-compat", "on" },
     { TYPE_X86_CPU, "x-bus-lock-detect-compat", "on" },
     { TYPE_X86_CPU, "x-v-vmsave-vmload-compat", "on" },
+    { TYPE_X86_CPU, "x-svm-features-compat", "on" },
 };
 const size_t pc_vz_9_2_compat_len = G_N_ELEMENTS(pc_vz_9_2_compat);
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 47027a2b828..29e7b4b7e15 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -8996,6 +8996,13 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
 
     for (i = 0; i < ARRAY_SIZE(feature_dependencies); i++) {
         FeatureDep *d = &feature_dependencies[i];
+
+        /* CPUID leaf 0x8000000a stays empty without svm anyway */
+        if (cpu->svm_features_compat && kvm_enabled() &&
+            d->to.index == FEAT_SVM) {
+            continue;
+        }
+
         if (!(env->features[d->from.index] & d->from.mask)) {
             uint64_t unavailable_features = env->features[d->to.index] & d->to.mask;
 
@@ -9138,6 +9145,10 @@ static uint64_t x86_cpu_compat_kept_features(X86CPU *cpu, FeatureWord w)
         if (cpu->v_vmsave_vmload_compat && IS_AMD_CPU(env)) {
             kept = CPUID_SVM_V_VMSAVE_VMLOAD;
         }
+        if (cpu->svm_features_compat &&
+            !(env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM)) {
+            kept = ~0ULL;
+        }
         break;
     default:
         break;
@@ -10109,6 +10120,8 @@ static const Property x86_cpu_properties[] = {
                      bus_lock_detect_compat, false),
     DEFINE_PROP_BOOL("x-v-vmsave-vmload-compat", X86CPU,
                      v_vmsave_vmload_compat, false),
+    DEFINE_PROP_BOOL("x-svm-features-compat", X86CPU,
+                     svm_features_compat, false),
 };
 
 #ifndef CONFIG_USER_ONLY
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 4f8bcbe600a..97e38013e46 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2340,6 +2340,7 @@ struct ArchCPU {
     bool spec_ctrl_compat;
     bool bus_lock_detect_compat;
     bool v_vmsave_vmload_compat;
+    bool svm_features_compat;
 
     /* Number of physical address bits supported */
     uint32_t phys_bits;
-- 
2.53.0


  parent reply	other threads:[~2026-10-29 12:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 12:25 [PATCH v3 hci-8.0/hci-8.1 0/6] i386: keep CPU features of guests from older nodes on vz machine types #VSTOR-152264 Denis V. Lunev
2026-10-29 12:25 ` [PATCH v3 hci-8.0/hci-8.1 1/6] i386/pc: raise the limit of compat arrays per Virtuozzo machine type to four #VSTOR-152264 Denis V. Lunev
2026-10-29 12:27   ` no-reply
2026-10-29 12:25 ` [PATCH v3 hci-8.0/hci-8.1 2/6] i386: keep hle and rtm on Virtuozzo machine types up to vz9.2.0 #PSBM-149402 Denis V. Lunev
2026-10-29 12:29   ` no-reply
2026-10-29 12:25 ` [PATCH v3 hci-8.0/hci-8.1 3/6] i386: keep spec-ctrl for AMD guests on vz machine types up to vz9.2.0 #VSTOR-151770 Denis V. Lunev
2026-10-29 12:29   ` no-reply
2026-10-29 12:25 ` [PATCH v3 hci-8.0/hci-8.1 4/6] i386: keep bus-lock-detect for AMD guests on vz machine types up to vz9.2.0 #VSTOR-152291 Denis V. Lunev
2026-10-29 12:30   ` no-reply
2026-10-29 12:25 ` [PATCH v3 hci-8.0/hci-8.1 5/6] i386: keep v-vmsave-vmload for nested AMD guests on vz types up to vz9.2.0 #VSTOR-152264 Denis V. Lunev
2026-10-29 12:30   ` no-reply
2026-10-29 12:25 ` Denis V. Lunev [this message]
2026-10-29 12:33   ` [PATCH v3 hci-8.0/hci-8.1 6/6] i386: keep SVM leaf features without svm on vz types up to vz9.2.0 #PSBM-144630 no-reply
2026-10-29 13:30 ` [PATCH v3 hci-8.0/hci-8.1 0/6] i386: keep CPU features of guests from older nodes on vz machine types #VSTOR-152264 Andrey Drobyshev
2026-10-29 13:47   ` Andrey Drobyshev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029122527.365104-7-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox