From: Paolo Bonzini <pbonzini@redhat.com>
To: Hou Wenlong <houwenlong.hwl@antgroup.com>, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] KVM: x86/emulator: Emulate RDPID only if it is enabled in guest
Date: Tue, 15 Mar 2022 23:18:11 +0100 [thread overview]
Message-ID: <8968615c-4ef2-49b9-77eb-82d580259a9c@redhat.com> (raw)
In-Reply-To: <45a2dbcbf694c48f1fb6a834a0f97a36a226a172.1646655860.git.houwenlong.hwl@antgroup.com>
On 3/7/22 13:26, Hou Wenlong wrote:
> When RDTSCP is supported but RDPID is not supported in host,
> RDPID emulation is available. However, __kvm_get_msr() would
> only fail when RDTSCP/RDPID both are disabled in guest, so
> the emulator wouldn't inject a #UD when RDPID is disabled but
> RDTSCP is enabled in guest.
>
> Fixes: fb6d4d340e05 ("KVM: x86: emulate RDPID")
> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
> ---
> arch/x86/kvm/emulate.c | 4 +++-
> arch/x86/kvm/kvm_emulate.h | 1 +
> arch/x86/kvm/x86.c | 6 ++++++
> 3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 3497a35bd085..be83c9c8482d 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -3521,8 +3521,10 @@ static int em_rdpid(struct x86_emulate_ctxt *ctxt)
> {
> u64 tsc_aux = 0;
>
> - if (ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux))
> + if (!ctxt->ops->guest_has_rdpid(ctxt))
> return emulate_ud(ctxt);
> +
> + ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux);
> ctxt->dst.val = tsc_aux;
> return X86EMUL_CONTINUE;
> }
> diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h
> index 29ac5a9679e5..1cbd46cf71f9 100644
> --- a/arch/x86/kvm/kvm_emulate.h
> +++ b/arch/x86/kvm/kvm_emulate.h
> @@ -228,6 +228,7 @@ struct x86_emulate_ops {
> bool (*guest_has_long_mode)(struct x86_emulate_ctxt *ctxt);
> bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt);
> bool (*guest_has_fxsr)(struct x86_emulate_ctxt *ctxt);
> + bool (*guest_has_rdpid)(struct x86_emulate_ctxt *ctxt);
>
> void (*set_nmi_mask)(struct x86_emulate_ctxt *ctxt, bool masked);
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 09c5677f4186..44f97038d3e5 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -7723,6 +7723,11 @@ static bool emulator_guest_has_fxsr(struct x86_emulate_ctxt *ctxt)
> return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_FXSR);
> }
>
> +static bool emulator_guest_has_rdpid(struct x86_emulate_ctxt *ctxt)
> +{
> + return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_RDPID);
> +}
> +
> static ulong emulator_read_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg)
> {
> return kvm_register_read_raw(emul_to_vcpu(ctxt), reg);
> @@ -7807,6 +7812,7 @@ static const struct x86_emulate_ops emulate_ops = {
> .guest_has_long_mode = emulator_guest_has_long_mode,
> .guest_has_movbe = emulator_guest_has_movbe,
> .guest_has_fxsr = emulator_guest_has_fxsr,
> + .guest_has_rdpid = emulator_guest_has_rdpid,
> .set_nmi_mask = emulator_set_nmi_mask,
> .get_hflags = emulator_get_hflags,
> .exiting_smm = emulator_exiting_smm,
Queued, thanks.
Would you try replacing the ->guest_has_... callbacks with just one that
takes an X86_FEATURE_* constant as a second argument?
Paolo
prev parent reply other threads:[~2022-03-15 22:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 13:15 [PATCH] " Hou Wenlong
2022-03-07 12:26 ` [PATCH v2 1/2] KVM: x86: Only do MSR filtering when access MSR by rdmsr/wrmsr Hou Wenlong
2022-03-07 12:26 ` [PATCH v2 2/2] KVM: x86/emulator: Emulate RDPID only if it is enabled in guest Hou Wenlong
2022-03-15 22:18 ` Paolo Bonzini [this message]
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=8968615c-4ef2-49b9-77eb-82d580259a9c@redhat.com \
--to=pbonzini@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=houwenlong.hwl@antgroup.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®