From: Maxim Levitsky <mlevitsk@redhat.com>
To: Chao Gao <chao.gao@intel.com>, Sean Christopherson <seanjc@google.com>
Cc: Zeng Guang <guang.zeng@intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
"Luck, Tony" <tony.luck@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Kim Phillips <kim.phillips@amd.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Jethro Beekman <jethro@fortanix.com>,
"Huang, Kai" <kai.huang@intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Hu, Robert" <robert.hu@intel.com>
Subject: Re: [PATCH v5 7/8] KVM: VMX: Update PID-pointer table entry when APIC ID is changed
Date: Fri, 14 Jan 2022 10:17:34 +0200 [thread overview]
Message-ID: <4b9fb845bf698f7efa6b46d525b37e329dd693ea.camel@redhat.com> (raw)
In-Reply-To: <20220114025825.GA3010@gao-cwp>
[-- Attachment #1: Type: text/plain, Size: 1462 bytes --]
On Fri, 2022-01-14 at 10:58 +0800, Chao Gao wrote:
> On Thu, Jan 13, 2022 at 10:19:21PM +0000, Sean Christopherson wrote:
> > On Tue, Jan 11, 2022, Maxim Levitsky wrote:
> > > Both Intel and AMD's PRM also state that changing APIC ID is implementation
> > > dependent.
> > >
> > > I vote to forbid changing apic id, at least in the case any APIC acceleration
> > > is used, be that APICv or AVIC.
> >
> > That has my vote as well. For IPIv in particular there's not much concern with
> > backwards compability, i.e. we can tie the behavior to enable_ipiv.
Great!
>
> Hi Sean and Levitsky,
>
> Let's align on the implementation.
>
> To disable changes for xAPIC ID when IPIv/AVIC is enabled:
>
> 1. introduce a variable (forbid_apicid_change) for this behavior in kvm.ko
> and export it so that kvm-intel, kvm-amd can set it when IPIv/AVIC is
> enabled. To reduce complexity, this variable is a module level setting.
>
> 2. when guest attempts to change xAPIC ID but it is forbidden, KVM prints
> a warning on host and injects a #GP to guest.
>
> 3. remove AVIC code that deals with changes to xAPIC ID.
>
I have a patch for both, I attached them.
I haven't tested either of these patches that much other than a smoke test,
but I did test all of the guests I have and none broke in regard to boot.
I will send those patches as part of larger patch series that implements
nesting for AVIC. I hope to do this next week.
Best regards,
Maxim Levitsky
[-- Attachment #2: 0001-KVM-x86-lapic-don-t-allow-to-change-APIC-ID-when-api.patch --]
[-- Type: text/x-patch, Size: 1241 bytes --]
From 4a70416b98c4725dc28608152b66ec42a233b2e8 Mon Sep 17 00:00:00 2001
From: Maxim Levitsky <mlevitsk@redhat.com>
Date: Sun, 9 Jan 2022 18:09:08 +0200
Subject: [PATCH 1/8] KVM: x86: lapic: don't allow to change APIC ID when apic
acceleration is enabled
No sane guest would change physical APIC IDs, and allowing this introduces bugs
into APIC acceleration code.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/kvm/lapic.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 6e1fbbf4c508b..56bc494cadd3e 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2007,10 +2007,16 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
switch (reg) {
case APIC_ID: /* Local APIC ID */
- if (!apic_x2apic_mode(apic))
- kvm_apic_set_xapic_id(apic, val >> 24);
- else
+ if (!apic_x2apic_mode(apic) ||
+ /*
+ * Don't allow setting APIC ID with any APIC acceleration
+ * enabled to avoid unexpected issues
+ */
+ (enable_apicv && ((val >> 24) != apic->vcpu->vcpu_id))) {
ret = 1;
+ break;
+ }
+ kvm_apic_set_xapic_id(apic, val >> 24);
break;
case APIC_TASKPRI:
--
2.26.3
[-- Attachment #3: 0002-KVM-x86-AVIC-remove-broken-code-that-updated-APIC-ID.patch --]
[-- Type: text/x-patch, Size: 2144 bytes --]
From 3200924ed056efe58b3d1d12675c194bea98c0fc Mon Sep 17 00:00:00 2001
From: Maxim Levitsky <mlevitsk@redhat.com>
Date: Sun, 9 Jan 2022 18:14:12 +0200
Subject: [PATCH 2/8] KVM: x86: AVIC: remove broken code that updated APIC ID
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/kvm/svm/avic.c | 37 ++++---------------------------------
1 file changed, 4 insertions(+), 33 deletions(-)
diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index f3ab00f407d5b..8655b35043134 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -480,35 +480,6 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
return ret;
}
-static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu)
-{
- u64 *old, *new;
- struct vcpu_svm *svm = to_svm(vcpu);
- u32 id = kvm_xapic_id(vcpu->arch.apic);
-
- if (vcpu->vcpu_id == id)
- return 0;
-
- old = avic_get_physical_id_entry(vcpu, vcpu->vcpu_id);
- new = avic_get_physical_id_entry(vcpu, id);
- if (!new || !old)
- return 1;
-
- /* We need to move physical_id_entry to new offset */
- *new = *old;
- *old = 0ULL;
- to_svm(vcpu)->avic_physical_id_cache = new;
-
- /*
- * Also update the guest physical APIC ID in the logical
- * APIC ID table entry if already setup the LDR.
- */
- if (svm->ldr_reg)
- avic_handle_ldr_update(vcpu);
-
- return 0;
-}
-
static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -529,8 +500,10 @@ static int avic_unaccel_trap_write(struct vcpu_svm *svm)
switch (offset) {
case APIC_ID:
- if (avic_handle_apic_id_update(&svm->vcpu))
- return 0;
+ /* restore the value that we had, we don't support APIC ID
+ * changes, but due to trap VM exit, the value was
+ * already written*/
+ kvm_lapic_reg_write(apic, offset, svm->vcpu.vcpu_id << 24);
break;
case APIC_LDR:
if (avic_handle_ldr_update(&svm->vcpu))
@@ -624,8 +597,6 @@ int avic_init_vcpu(struct vcpu_svm *svm)
void avic_post_state_restore(struct kvm_vcpu *vcpu)
{
- if (avic_handle_apic_id_update(vcpu) != 0)
- return;
avic_handle_dfr_update(vcpu);
avic_handle_ldr_update(vcpu);
}
--
2.26.3
next prev parent reply other threads:[~2022-01-14 8:18 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-31 14:28 [PATCH v5 0/8] IPI virtualization support for VM Zeng Guang
2021-12-31 14:28 ` [PATCH v5 1/8] x86/cpu: Add new VMX feature, Tertiary VM-Execution control Zeng Guang
2021-12-31 14:28 ` [PATCH v5 2/8] KVM: VMX: Extend BUILD_CONTROLS_SHADOW macro to support 64-bit variation Zeng Guang
2021-12-31 14:28 ` [PATCH v5 3/8] KVM: VMX: Detect Tertiary VM-Execution control when setup VMCS config Zeng Guang
2021-12-31 14:28 ` [PATCH v5 4/8] KVM: VMX: dump_vmcs() reports tertiary_exec_control field as well Zeng Guang
2022-01-13 21:03 ` Sean Christopherson
2022-01-14 4:19 ` Zeng Guang
2022-01-20 1:06 ` Sean Christopherson
2022-01-20 5:34 ` Zeng Guang
2021-12-31 14:28 ` [PATCH v5 5/8] KVM: x86: Support interrupt dispatch in x2APIC mode with APIC-write VM exit Zeng Guang
2022-01-13 21:29 ` Sean Christopherson
2022-01-14 7:52 ` Zeng Guang
2022-01-14 17:34 ` Sean Christopherson
2022-01-15 2:08 ` Zeng Guang
2022-01-18 0:44 ` Yuan Yao
2022-01-18 3:06 ` Zeng Guang
2022-01-18 18:17 ` Sean Christopherson
2022-01-19 2:48 ` Zeng Guang
2021-12-31 14:28 ` [PATCH v5 6/8] KVM: VMX: enable IPI virtualization Zeng Guang
2022-01-13 21:47 ` Sean Christopherson
2022-01-14 5:36 ` Zeng Guang
2021-12-31 14:28 ` [PATCH v5 7/8] KVM: VMX: Update PID-pointer table entry when APIC ID is changed Zeng Guang
2022-01-05 19:13 ` Tom Lendacky
2022-01-06 1:44 ` Zeng Guang
2022-01-06 14:06 ` Tom Lendacky
2022-01-07 8:05 ` Zeng Guang
2022-01-07 8:31 ` Maxim Levitsky
2022-01-10 7:45 ` Chao Gao
2022-01-10 22:24 ` Maxim Levitsky
2022-01-13 22:19 ` Sean Christopherson
2022-01-14 2:58 ` Chao Gao
2022-01-14 8:17 ` Maxim Levitsky [this message]
2022-01-17 3:17 ` Chao Gao
2022-02-02 23:23 ` Sean Christopherson
2022-02-03 20:22 ` Sean Christopherson
2022-02-23 6:10 ` Chao Gao
2022-02-23 10:26 ` Maxim Levitsky
2022-01-14 0:22 ` Yuan Yao
2021-12-31 14:28 ` [PATCH v5 8/8] KVM: VMX: Resize PID-ponter table on demand for IPI virtualization Zeng Guang
2022-01-13 22:09 ` Sean Christopherson
2022-01-14 15:59 ` Zeng Guang
2022-01-14 16:18 ` Sean Christopherson
2022-01-17 15:04 ` Zeng Guang
2022-01-18 17:15 ` Sean Christopherson
2022-01-19 7:55 ` Zeng Guang
2022-01-20 1:01 ` Sean Christopherson
2022-01-24 16:40 ` Zeng Guang
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=4b9fb845bf698f7efa6b46d525b37e329dd693ea.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=guang.zeng@intel.com \
--cc=hpa@zytor.com \
--cc=jarkko@kernel.org \
--cc=jethro@fortanix.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kai.huang@intel.com \
--cc=kan.liang@linux.intel.com \
--cc=kim.phillips@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=robert.hu@intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=tony.luck@intel.com \
--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;
as well as URLs for NNTP newsgroup(s).