From: sashiko-bot@kernel.org
To: "Vitaly Kuznetsov" <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 4/4] KVM: selftests: Check VMPTRLD with active eVMCS
Date: Tue, 18 Aug 2026 17:05:33 +0000 [thread overview]
Message-ID: <20260818170534.07B561F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818165258.2613603-5-vkuznets@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Code relying on CPU flags after `KVM_ASM_SAFE` incorrectly evaluates them because the macro's cleanup instructions unconditionally clobber the flags.
--
--- Patch [4]: [PATCH v2 4/4] KVM: selftests: Check VMPTRLD with active eVMCS ---
commit d5821824a958c354147206d0cf6cf26eaeb71cc6
Author: Vitaly Kuznetsov <vkuznets@redhat.com>
KVM: selftests: Check VMPTRLD with active eVMCS
This commit verifies that VMPTRLD triggers a #UD when eVMCS is active.
It uses the KVM_ASM_SAFE framework to safely handle the expected
exceptions from VMPTRLD testing.
> diff --git a/tools/testing/selftests/kvm/include/x86/vmx.h b/tools/testing/selftests/kvm/include/x86/vmx.h
> index 047d02aa96889..e6adde3970d4d 100644
> --- a/tools/testing/selftests/kvm/include/x86/vmx.h
> +++ b/tools/testing/selftests/kvm/include/x86/vmx.h
[ ... ]
> @@ -336,6 +333,22 @@ static inline int vmptrld(u64 vmcs_pa)
> return ret;
> }
>
> +static inline int vmptrld_safe(u64 vmcs_pa)
> +{
> + u64 error_code;
> + u8 vector;
> + u8 failed;
> +
> + asm volatile(KVM_ASM_SAFE("vmptrld %[pa]")
> + "\n\tsetna %[failed]"
[Severity: Medium]
Will this setna instruction incorrectly evaluate CPU flags?
The KVM_ASM_SAFE macro executes xor %%r9, %%r9 on its success path, which
unconditionally clears the Carry Flag (CF=0) and sets the Zero Flag (ZF=1).
Because setna evaluates flags immediately after KVM_ASM_SAFE finishes its
cleanup instructions, it captures these clobbered flags and always evaluates
to true.
Does this cause vmptrld_safe() to incorrectly return -EINVAL upon successful
execution?
> + : KVM_ASM_SAFE_OUTPUTS(vector, error_code),
> + [failed]"=qm"(failed)
> + : [pa]"m"(vmcs_pa)
> + : "cc", "memory", KVM_ASM_SAFE_CLOBBERS);
> +
> + return vector ? vector : failed ? -EINVAL : 0;
> +}
> +
[Severity: Medium]
This isn't a bug introduced by this patch, but is a pre-existing issue in
guest_execute_fastop_div() located in
tools/testing/selftests/kvm/x86/fastops_test.c:
Does guest_execute_fastop_div() suffer from a similar flag evaluation issue?
__asm__ __volatile__(fastop(__KVM_ASM_SAFE(insn " %[denom]"))
The fastop macro invokes __KVM_ASM_SAFE, and captures flags via pushfq.
Does capturing flags after the macro result in saving the clobbered flags
from the internal xor instruction rather than the actual result of the
instruction under test?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818165258.2613603-1-vkuznets@redhat.com?part=4
next prev parent reply other threads:[~2026-08-18 17:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 16:52 [PATCH v2 0/4] KVM: nVMX: Adjust VMPTRLD/VMPTRST behavior with active eVMCS Vitaly Kuznetsov
2026-08-18 16:52 ` [PATCH v2 1/4] KVM: nVMX: Make VMPTRLD result in #UD when eVMCS is used Vitaly Kuznetsov
2026-08-18 17:03 ` sashiko-bot
2026-08-18 16:52 ` [PATCH v2 2/4] KVM: nVMX: Make VMPTRST return eVMCS GPA when it " Vitaly Kuznetsov
2026-08-18 16:52 ` [PATCH v2 3/4] KVM: selftests: Adapt to the updated VMPTRST behavior when eVMCS " Vitaly Kuznetsov
2026-08-18 16:52 ` [PATCH v2 4/4] KVM: selftests: Check VMPTRLD with active eVMCS Vitaly Kuznetsov
2026-08-18 17:05 ` sashiko-bot [this message]
2026-08-18 17:16 ` Sean Christopherson
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=20260818170534.07B561F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkuznets@redhat.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.