From: Maxim Levitsky <mlevitsk@redhat.com>
To: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com, jon.grimm@amd.com,
Zeng Guang <guang.zeng@intel.com>
Subject: Re: [PATCH] KVM: x86: Do not block APIC write for non ICR registers
Date: Mon, 18 Jul 2022 12:37:07 +0300 [thread overview]
Message-ID: <028a575079cee20cbbf41bca8a734e16535d179e.camel@redhat.com> (raw)
In-Reply-To: <20220718083913.222140-1-suravee.suthikulpanit@amd.com>
On Mon, 2022-07-18 at 03:39 -0500, Suravee Suthikulpanit wrote:
> The commit 5413bcba7ed5 ("KVM: x86: Add support for vICR APIC-write
> VM-Exits in x2APIC mode") introduces logic to prevent APIC write
> for offset other than ICR. This breaks x2AVIC support, which requires
> KVM to trap and emulate x2APIC MSR writes.
>
> Therefore, removes the warning and modify to logic to allow MSR write.
>
> Fixes: 5413bcba7ed5 ("KVM: x86: Add support for vICR APIC-write VM-Exits in x2APIC mode")
> Cc: Zeng Guang <guang.zeng@intel.com>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> ---
> arch/x86/kvm/lapic.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 9d4f73c4dc02..f688090d98b0 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -69,6 +69,7 @@ static bool lapic_timer_advance_dynamic __read_mostly;
> /* step-by-step approximation to mitigate fluctuation */
> #define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
> static int kvm_lapic_msr_read(struct kvm_lapic *apic, u32 reg, u64 *data);
> +static int kvm_lapic_msr_write(struct kvm_lapic *apic, u32 reg, u64 data);
>
> static inline void __kvm_lapic_set_reg(char *regs, int reg_off, u32 val)
> {
> @@ -2284,17 +2285,23 @@ void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)
> u64 val;
>
> if (apic_x2apic_mode(apic)) {
> + kvm_lapic_msr_read(apic, offset, &val);
> +
> /*
> * When guest APIC is in x2APIC mode and IPI virtualization
> * is enabled, accessing APIC_ICR may cause trap-like VM-exit
> * on Intel hardware. Other offsets are not possible.
> + *
> + * For AMD AVIC, write to some APIC registers can cause
> + * trap-like VM-exit (see arch/x86/kvm/svm/avic.c:
> + * avic_unaccel_trap_write()).
> */
> - if (WARN_ON_ONCE(offset != APIC_ICR))
> + if (offset == APIC_ICR) {
> + kvm_apic_send_ipi(apic, (u32)val, (u32)(val >> 32));
> + trace_kvm_apic_write(APIC_ICR, val);
> return;
> -
> - kvm_lapic_msr_read(apic, offset, &val);
> - kvm_apic_send_ipi(apic, (u32)val, (u32)(val >> 32));
> - trace_kvm_apic_write(APIC_ICR, val);
> + }
> + kvm_lapic_msr_write(apic, offset, val);
> } else {
> val = kvm_lapic_get_reg(apic, offset);
>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Best regards,
Maxim Levitsky
next prev parent reply other threads:[~2022-07-18 9:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 8:39 Suravee Suthikulpanit
2022-07-18 9:37 ` Maxim Levitsky [this message]
2022-07-18 17:28 ` Sean Christopherson
2022-07-19 3:24 ` Suthikulpanit, Suravee
2022-07-20 9:50 ` Suravee Suthikulpanit
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=028a575079cee20cbbf41bca8a734e16535d179e.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=guang.zeng@intel.com \
--cc=jon.grimm@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=suravee.suthikulpanit@amd.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
all inboxes | Powered by JetHome®