All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: "Denis V. Lunev" <den@openvz.org>, andrey.zhadchenko@virtuozzo.com
Cc: svt-core@virtuozzo.com, den@openvz.org
Subject: Re: [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
Date: Thu, 29 Oct 2026 12:29:31 +0000	[thread overview]
Message-ID: <010701a187a30bcd-9b498923-9320-45fc-9049-596cdebb62be-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261029122527.365104-3-den@openvz.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] i386: x-tsx-compat keeps HLE/RTM without checking host TSX support
--

commit 958d84e4025a51fe913636203f3656b7b19673c8
Author: Denis V. Lunev <den@openvz.org>

i386: keep hle and rtm on Virtuozzo machine types up to vz9.2.0 #PSBM-149402

This patch adds an x-tsx-compat CPU property. When it is set, HLE and RTM
requested by an Intel CPU model are not filtered out under KVM. The property
is turned on by pc_vz_9_2_compat for vz9.2.0 and all older vz machine types.
The goal is that a guest started with TSX can still be migrated, restored or
reverted on a host where microcode or tsx=off has disabled TSX.

> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c

[ ... ]

> +GlobalProperty pc_vz_9_2_compat[] = {
> +    { TYPE_X86_CPU, "x-tsx-compat", "on" },
> +};
> +const size_t pc_vz_9_2_compat_len = G_N_ELEMENTS(pc_vz_9_2_compat);

[Severity: Medium]
Because this is a machine type property, it is also on for a cold boot of
every vz type up to vz9.2.0, not only for incoming migration.

Can a cold-booted guest end up with HLE and RTM in its CPUID on a host that
has no TSX silicon, for example an AMD host running an Intel-named CPU
model, or an Intel part that never had TSX?

> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c

[ ... ]

> +/* Requested features that a vz compat property keeps despite the host */
> +static uint64_t x86_cpu_compat_kept_features(X86CPU *cpu, FeatureWord w)
> +{
> +    CPUX86State *env = &cpu->env;
> +    uint64_t kept = 0;
> +
> +    if (!kvm_enabled()) {
> +        return 0;
> +    }
> +
> +    switch (w) {
> +    case FEAT_7_0_EBX:
> +        if (cpu->tsx_compat && IS_INTEL_CPU(env)) {
> +            kept = CPUID_7_0_EBX_HLE | CPUID_7_0_EBX_RTM;
> +        }
> +        break;

[Severity: Medium]
The guard in x86_cpu_compat_kept_features() checks only kvm_enabled(),
cpu->tsx_compat and IS_INTEL_CPU(env). IS_INTEL_CPU(env) tests the vendor of
the guest CPU model, not of the host.

Nothing here checks whether the host implements TSX, as opposed to having it
disabled by microcode through TSX_CTRL or RTM_ALWAYS_ABORT. The commit
message justifies the bypass only for the second case, where XBEGIN aborts.

On silicon without TSX, XBEGIN raises #UD instead of aborting. Could a guest
that trusts CPUID and uses RTM (glibc lock elision, libitm) then take an
invalid-opcode fault?

Would it make sense to restrict the kept bits to hosts where TSX exists but
is disabled?

This also bypasses the existing safeguard in kvm_arch_get_supported_cpuid():

target/i386/kvm/kvm.c:kvm_arch_get_supported_cpuid() {
    ...
        if (host_tsx_broken()) {
            ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
        }
    ...
}

The commit message says this is intended for Haswell parts with the erratum.
Is it also intended for hosts with no TSX at all?

[ ... ]

> @@ -9126,7 +9149,8 @@ static bool x86_cpu_filter_features(X86CPU *cpu, bool verbose)
>          uint64_t host_feat =
>              x86_cpu_get_supported_feature_word(NULL, w);
>          uint64_t requested_features = env->features[w];
> -        uint64_t unavailable_features = requested_features & ~host_feat;
> +        uint64_t unavailable_features = requested_features & ~host_feat &
> +            ~x86_cpu_compat_kept_features(cpu, w);
>          mark_unavailable_features(cpu, w, unavailable_features, prefix);

[Severity: Medium]
In x86_cpu_filter_features(), the kept bits are removed from
unavailable_features before mark_unavailable_features() is called.

The bits therefore stay in env->features and go into the guest CPUID. They
are also never added to cpu->filtered_features, so the check and enforce
warnings and errors stay silent for them.

Is it intended that enforce can no longer reject HLE or RTM on a host that
lacks TSX entirely?

I did not trace the KVM_SET_CPUID2 path in kvm_arch_init_vcpu(). The commit
message says KVM ignores unsupported bits, but the kernel does not validate
userspace-supplied guest CPUID against host capability.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261029122527.365104-1-den@openvz.org?part=2

  reply	other threads:[~2026-10-29 12:29 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 [this message]
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 ` [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 Denis V. Lunev
2026-10-29 12:33   ` 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=010701a187a30bcd-9b498923-9320-45fc-9049-596cdebb62be-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=den@openvz.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.