From: Sean Christopherson <seanjc@google.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: David Matlack <dmatlack@google.com>,
Oliver Upton <oliver.upton@linux.dev>,
"Yang, Weijiang" <weijiang.yang@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Huacai Chen <chenhuacai@kernel.org>,
Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>,
Anup Patel <anup@brainfault.org>,
Atish Patra <atishp@atishpatra.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Andrew Morton <akpm@linux-foundation.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
"Amit, Nadav" <namit@vmware.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Vlastimil Babka <vbabka@suse.cz>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Suren Baghdasaryan <surenb@google.com>,
Peter Xu <peterx@redhat.com>, xu xin <cgel.zte@gmail.com>,
Arnd Bergmann <arnd@arndb.de>, Yu Zhao <yuzhao@google.com>,
Colin Cross <ccross@google.com>, Hugh Dickins <hughd@google.com>,
Ben Gardon <bgardon@google.com>,
Mingwei Zhang <mizhang@google.com>,
Krish Sadhukhan <krish.sadhukhan@oracle.com>,
Ricardo Koller <ricarkol@google.com>,
Jing Zhang <jingzhangos@google.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
"linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"kvm-riscv@lists.infradead.org" <kvm-riscv@lists.infradead.org>,
"linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>
Subject: Re: [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role
Date: Wed, 14 Dec 2022 19:42:30 +0000 [thread overview]
Message-ID: <Y5onJulY3UQJNrmW@google.com> (raw)
In-Reply-To: <CAJhGHyBbjyKVEv3KcoOcPGQ28753FjR_rc9uNDEF3Dd-gNTRGQ@mail.gmail.com>
On Wed, Dec 14, 2022, Lai Jiangshan wrote:
> On Tue, Dec 13, 2022 at 1:47 AM Sean Christopherson <seanjc@google.com> wrote:
>
> >
> > My preference would be to leave .smm in x86's page role. IMO, defining multiple
> > address spaces to support SMM emulation was a mistake that should be contained to
> > SMM, i.e. should never be used for any other feature. And with CONFIG_KVM_SMM,
> > even x86 can opt out.
> >
>
>
> I think the name ASID in kvm/x86 should be used for vmcb's ASID,
> vmcs's VPID, and PCID. Using the name ASID for other purposes
> would only result in unnecessary confusion.
I agree in principle, but at this point fixing the problem would require a lot of
churn since "as_id" is pervasive throughout the memslots code.
It should be possible though, as I don't think anything in KVM's uAPI explicitly
takes an as_id, i.e. it's KVM-internal terminology for the most part.
> There is a bug for shadow paging when it uses two separate sets
> of memslots which are using two sets of rmap and page-tracking.
>
> When SMM world is writing to a non-SMM page which happens to be
> a guest pagetable in the non-SMM world, the write operation will
> go smoothly without specially handled and the shadow page for the guest
> pagetable is neither unshadowed nor marked unsync. The shadow paging
> code is unaware that the shadow page has deviated from the guest
> pagetable.
Won't the unsync code work as intended? for_each_gfn_valid_sp_with_gptes()
doesn't consume the slot and I don't see any explicit filtering on role.smm,
i.e. should unsync all SPTEs for the gfn.
Addressing the page-track case is a bit gross, but doesn't appear to be too
difficult. I wouldn't be surprised if there are other SMM => non-SMM bugs lurking
though.
---
arch/x86/include/asm/kvm_page_track.h | 2 +-
arch/x86/kvm/mmu/mmu.c | 7 +++---
arch/x86/kvm/mmu/mmu_internal.h | 3 ++-
arch/x86/kvm/mmu/page_track.c | 32 +++++++++++++++++++--------
arch/x86/kvm/mmu/spte.c | 2 +-
5 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h
index eb186bc57f6a..fdd9de31e160 100644
--- a/arch/x86/include/asm/kvm_page_track.h
+++ b/arch/x86/include/asm/kvm_page_track.h
@@ -63,7 +63,7 @@ void kvm_slot_page_track_add_page(struct kvm *kvm,
void kvm_slot_page_track_remove_page(struct kvm *kvm,
struct kvm_memory_slot *slot, gfn_t gfn,
enum kvm_page_track_mode mode);
-bool kvm_slot_page_track_is_active(struct kvm *kvm,
+bool kvm_slot_page_track_is_active(struct kvm_vcpu *vcpu,
const struct kvm_memory_slot *slot,
gfn_t gfn, enum kvm_page_track_mode mode);
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 254bc46234e0..1c2200042133 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2715,9 +2715,10 @@ static void kvm_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
* were marked unsync (or if there is no shadow page), -EPERM if the SPTE must
* be write-protected.
*/
-int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
+int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu, const struct kvm_memory_slot *slot,
gfn_t gfn, bool can_unsync, bool prefetch)
{
+ struct kvm *kvm = vcpu->kvm;
struct kvm_mmu_page *sp;
bool locked = false;
@@ -2726,7 +2727,7 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
* track machinery is used to write-protect upper-level shadow pages,
* i.e. this guards the role.level == 4K assertion below!
*/
- if (kvm_slot_page_track_is_active(kvm, slot, gfn, KVM_PAGE_TRACK_WRITE))
+ if (kvm_slot_page_track_is_active(vcpu, slot, gfn, KVM_PAGE_TRACK_WRITE))
return -EPERM;
/*
@@ -4127,7 +4128,7 @@ static bool page_fault_handle_page_track(struct kvm_vcpu *vcpu,
* guest is writing the page which is write tracked which can
* not be fixed by page fault handler.
*/
- if (kvm_slot_page_track_is_active(vcpu->kvm, fault->slot, fault->gfn, KVM_PAGE_TRACK_WRITE))
+ if (kvm_slot_page_track_is_active(vcpu, fault->slot, fault->gfn, KVM_PAGE_TRACK_WRITE))
return true;
return false;
diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index ac00bfbf32f6..38040ab27986 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -156,7 +156,8 @@ static inline bool kvm_mmu_page_ad_need_write_protect(struct kvm_mmu_page *sp)
return kvm_x86_ops.cpu_dirty_log_size && sp->role.guest_mode;
}
-int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
+int mmu_try_to_unsync_pages(struct kvm_vcpu *vcpu,
+ const struct kvm_memory_slot *slot,
gfn_t gfn, bool can_unsync, bool prefetch);
void kvm_mmu_gfn_disallow_lpage(const struct kvm_memory_slot *slot, gfn_t gfn);
diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c
index 2e09d1b6249f..0e9bc837257e 100644
--- a/arch/x86/kvm/mmu/page_track.c
+++ b/arch/x86/kvm/mmu/page_track.c
@@ -18,6 +18,7 @@
#include "mmu.h"
#include "mmu_internal.h"
+#include "smm.h"
bool kvm_page_track_write_tracking_enabled(struct kvm *kvm)
{
@@ -171,27 +172,40 @@ void kvm_slot_page_track_remove_page(struct kvm *kvm,
}
EXPORT_SYMBOL_GPL(kvm_slot_page_track_remove_page);
+static bool __kvm_slot_page_track_is_active(const struct kvm_memory_slot *slot,
+ gfn_t gfn, enum kvm_page_track_mode mode)
+{
+ int index;
+
+ if (!slot)
+ return false;
+
+ index = gfn_to_index(gfn, slot->base_gfn, PG_LEVEL_4K);
+ return !!READ_ONCE(slot->arch.gfn_track[mode][index]);
+}
+
/*
* check if the corresponding access on the specified guest page is tracked.
*/
-bool kvm_slot_page_track_is_active(struct kvm *kvm,
+bool kvm_slot_page_track_is_active(struct kvm_vcpu *vcpu,
const struct kvm_memory_slot *slot,
gfn_t gfn, enum kvm_page_track_mode mode)
{
- int index;
-
if (WARN_ON(!page_track_mode_is_valid(mode)))
return false;
- if (!slot)
- return false;
-
if (mode == KVM_PAGE_TRACK_WRITE &&
- !kvm_page_track_write_tracking_enabled(kvm))
+ !kvm_page_track_write_tracking_enabled(vcpu->kvm))
return false;
- index = gfn_to_index(gfn, slot->base_gfn, PG_LEVEL_4K);
- return !!READ_ONCE(slot->arch.gfn_track[mode][index]);
+ if (__kvm_slot_page_track_is_active(slot, gfn, mode))
+ return true;
+
+ if (!is_smm(vcpu))
+ return false;
+
+ return __kvm_slot_page_track_is_active(gfn_to_memslot(vcpu->kvm, gfn),
+ gfn, mode);
}
void kvm_page_track_cleanup(struct kvm *kvm)
diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
index c0fd7e049b4e..89ddd113c1b9 100644
--- a/arch/x86/kvm/mmu/spte.c
+++ b/arch/x86/kvm/mmu/spte.c
@@ -220,7 +220,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
* e.g. it's write-tracked (upper-level SPs) or has one or more
* shadow pages and unsync'ing pages is not allowed.
*/
- if (mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, can_unsync, prefetch)) {
+ if (mmu_try_to_unsync_pages(vcpu, slot, gfn, can_unsync, prefetch)) {
pgprintk("%s: found shadow page for %llx, marking ro\n",
__func__, gfn);
wrprot = true;
base-commit: e0ef1f14e97ff65adf6e2157952dbbd1e482065c
--
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-12-14 19:44 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 19:38 [RFC PATCH 00/37] KVM: Refactor the KVM/x86 TDP MMU into common code David Matlack
2022-12-08 19:38 ` [RFC PATCH 01/37] KVM: x86/mmu: Store the address space ID directly in kvm_mmu_page_role David Matlack
2022-12-09 2:37 ` Yang, Weijiang
2022-12-09 17:24 ` Oliver Upton
2022-12-09 17:40 ` David Matlack
2022-12-12 17:39 ` Sean Christopherson
2022-12-12 18:17 ` Oliver Upton
2022-12-13 1:11 ` David Matlack
2022-12-12 22:50 ` Paolo Bonzini
2022-12-13 1:18 ` David Matlack
2022-12-13 1:42 ` Sean Christopherson
2022-12-14 9:50 ` Lai Jiangshan
2022-12-14 19:42 ` Sean Christopherson [this message]
2022-12-15 7:20 ` Lai Jiangshan
2022-12-08 19:38 ` [RFC PATCH 02/37] KVM: MMU: Move struct kvm_mmu_page_role into common code David Matlack
2022-12-12 17:48 ` Ben Gardon
2022-12-12 23:11 ` Paolo Bonzini
2022-12-13 1:06 ` David Matlack
2022-12-08 19:38 ` [RFC PATCH 03/37] KVM: MMU: Move tdp_ptep_t " David Matlack
2022-12-08 19:38 ` [RFC PATCH 04/37] KVM: x86/mmu: Invert sp->tdp_mmu_page to sp->shadow_mmu_page David Matlack
2022-12-12 23:15 ` Paolo Bonzini
2023-01-11 22:45 ` David Matlack
2022-12-08 19:38 ` [RFC PATCH 05/37] KVM: x86/mmu: Unify TDP MMU and Shadow MMU root refcounts David Matlack
2022-12-08 19:38 ` [RFC PATCH 06/37] KVM: MMU: Move struct kvm_mmu_page to common code David Matlack
2022-12-12 18:07 ` Ben Gardon
2022-12-12 22:32 ` Paolo Bonzini
2022-12-12 22:49 ` David Matlack
2022-12-08 19:38 ` [RFC PATCH 07/37] mm: Introduce architecture-neutral PG_LEVEL macros David Matlack
2022-12-08 19:38 ` [RFC PATCH 08/37] KVM: selftests: Stop assuming stats are contiguous in kvm_binary_stats_test David Matlack
2022-12-08 19:38 ` [RFC PATCH 09/37] KVM: Move page size stats into common code David Matlack
2022-12-08 19:38 ` [RFC PATCH 10/37] KVM: MMU: Move struct kvm_page_fault to " David Matlack
2022-12-12 18:24 ` Ben Gardon
2022-12-12 22:30 ` David Matlack
2022-12-12 22:27 ` Paolo Bonzini
2023-01-09 18:55 ` David Matlack
2022-12-08 19:38 ` [RFC PATCH 11/37] KVM: MMU: Move RET_PF_* into " David Matlack
2022-12-08 19:38 ` [RFC PATCH 12/37] KVM: x86/mmu: Use PG_LEVEL_{PTE,PMD,PUD} in the TDP MMU David Matlack
2022-12-08 19:38 ` [RFC PATCH 13/37] KVM: MMU: Move sptep_to_sp() to common code David Matlack
2022-12-08 19:38 ` [RFC PATCH 14/37] KVM: MMU: Introduce common macros for TDP page tables David Matlack
2022-12-08 19:38 ` [RFC PATCH 15/37] KVM: x86/mmu: Add a common API for inspecting/modifying TDP PTEs David Matlack
2022-12-08 19:38 ` [RFC PATCH 16/37] KVM: x86/mmu: Abstract away TDP MMU root lookup David Matlack
2022-12-08 19:38 ` [RFC PATCH 17/37] KVM: Move struct kvm_gfn_range to kvm_types.h David Matlack
2022-12-12 19:16 ` Ben Gardon
2022-12-08 19:38 ` [RFC PATCH 18/37] KVM: x86/mmu: Add common API for creating TDP PTEs David Matlack
2022-12-08 19:38 ` [RFC PATCH 19/37] KVM: x86/mmu: Add arch hooks for NX Huge Pages David Matlack
2022-12-08 19:38 ` [RFC PATCH 20/37] KVM: x86/mmu: Abstract away computing the max mapping level David Matlack
2022-12-12 19:32 ` Ben Gardon
2022-12-12 21:05 ` David Matlack
2022-12-13 1:02 ` Sean Christopherson
2022-12-08 19:38 ` [RFC PATCH 21/37] KVM: Introduce CONFIG_HAVE_TDP_MMU David Matlack
2022-12-08 19:38 ` [RFC PATCH 22/37] KVM: x86: Select HAVE_TDP_MMU if X86_64 David Matlack
2022-12-08 19:38 ` [RFC PATCH 23/37] KVM: MMU: Move VM-level TDP MMU state to struct kvm David Matlack
2022-12-09 17:31 ` Oliver Upton
2022-12-09 17:57 ` David Matlack
2022-12-09 18:30 ` Oliver Upton
2022-12-08 19:38 ` [RFC PATCH 24/37] KVM: x86/mmu: Move kvm_mmu_hugepage_adjust() up to fault handler David Matlack
2022-12-08 19:38 ` [RFC PATCH 25/37] KVM: x86/mmu: Pass root role to kvm_tdp_mmu_get_vcpu_root_hpa() David Matlack
2022-12-08 19:38 ` [RFC PATCH 26/37] KVM: Move page table cache to struct kvm_vcpu David Matlack
2022-12-08 19:38 ` [RFC PATCH 27/37] KVM: MMU: Move mmu_page_header_cache to common code David Matlack
2022-12-08 19:38 ` [RFC PATCH 28/37] KVM: MMU: Stub out tracepoints on non-x86 architectures David Matlack
2022-12-08 19:38 ` [RFC PATCH 29/37] KVM: x86/mmu: Collapse kvm_flush_remote_tlbs_with_{range,address}() together David Matlack
2022-12-08 19:38 ` [RFC PATCH 30/37] KVM: x86/mmu: Rename kvm_flush_remote_tlbs_with_address() David Matlack
2022-12-08 19:38 ` [RFC PATCH 31/37] KVM: x86/MMU: Use gfn_t in kvm_flush_remote_tlbs_range() David Matlack
2022-12-08 19:38 ` [RFC PATCH 32/37] KVM: Allow range-based TLB invalidation from common code David Matlack
2022-12-08 19:38 ` [RFC PATCH 33/37] KVM: Move kvm_arch_flush_remote_tlbs_memslot() to " David Matlack
2022-12-12 22:03 ` Ben Gardon
2022-12-12 22:42 ` David Matlack
2022-12-08 19:38 ` [RFC PATCH 34/37] KVM: MMU: Move the TDP iterator " David Matlack
2022-12-08 19:38 ` [RFC PATCH 35/37] KVM: x86/mmu: Move tdp_mmu_max_gfn_exclusive() to tdp_pgtable.c David Matlack
2022-12-08 19:38 ` [RFC PATCH 36/37] KVM: x86/mmu: Move is_tdp_mmu_page() to mmu_internal.h David Matlack
2022-12-08 19:38 ` [RFC PATCH 37/37] KVM: MMU: Move the TDP MMU to common code David Matlack
2022-12-09 19:07 ` [RFC PATCH 00/37] KVM: Refactor the KVM/x86 TDP MMU into " Oliver Upton
2022-12-10 1:07 ` David Matlack
2022-12-12 22:54 ` Paolo Bonzini
2022-12-12 23:26 ` Sean Christopherson
2022-12-12 23:43 ` Paolo Bonzini
2023-01-19 17:14 ` David Matlack
2023-01-19 17:23 ` Paolo Bonzini
2023-01-19 17:24 ` Marc Zyngier
2023-01-19 18:38 ` David Matlack
2023-01-19 19:04 ` David Matlack
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=Y5onJulY3UQJNrmW@google.com \
--to=seanjc@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=aleksandar.qemu.devel@gmail.com \
--cc=alexandru.elisei@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=arnd@arndb.de \
--cc=atishp@atishpatra.org \
--cc=bgardon@google.com \
--cc=ccross@google.com \
--cc=cgel.zte@gmail.com \
--cc=chenhuacai@kernel.org \
--cc=dmatlack@google.com \
--cc=hughd@google.com \
--cc=james.morse@arm.com \
--cc=jiangshanlai@gmail.com \
--cc=jingzhangos@google.com \
--cc=krish.sadhukhan@oracle.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maz@kernel.org \
--cc=mizhang@google.com \
--cc=namit@vmware.com \
--cc=oliver.upton@linux.dev \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=ricarkol@google.com \
--cc=surenb@google.com \
--cc=suzuki.poulose@arm.com \
--cc=vbabka@suse.cz \
--cc=weijiang.yang@intel.com \
--cc=willy@infradead.org \
--cc=yuzhao@google.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;
as well as URLs for NNTP newsgroup(s).