From: James Houghton <jthoughton@google.com>
To: kvm-riscv@lists.infradead.org
Subject: [PATCH v4 6/7] KVM: arm64: Relax locking for kvm_test_age_gfn and kvm_age_gfn
Date: Wed, 29 May 2024 18:05:09 +0000 [thread overview]
Message-ID: <20240529180510.2295118-7-jthoughton@google.com> (raw)
In-Reply-To: <20240529180510.2295118-1-jthoughton@google.com>
Replace the MMU write locks for read locks.
Grabbing the read lock instead of the write lock is safe because the
only requirement we have is that the stage-2 page tables do not get
deallocated while we are walking them. The stage2_age_walker() callback
is safe to race with itself; update the comment to reflect the
synchronization change.
Signed-off-by: James Houghton <jthoughton@google.com>
---
arch/arm64/kvm/hyp/pgtable.c | 9 ++++-----
arch/arm64/kvm/mmu.c | 8 ++++----
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
index 9e2bbee77491..eabb07c66a07 100644
--- a/arch/arm64/kvm/hyp/pgtable.c
+++ b/arch/arm64/kvm/hyp/pgtable.c
@@ -1319,10 +1319,8 @@ static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx,
data->young = true;
/*
- * stage2_age_walker() is always called while holding the MMU lock for
- * write, so this will always succeed. Nonetheless, this deliberately
- * follows the race detection pattern of the other stage-2 walkers in
- * case the locking mechanics of the MMU notifiers is ever changed.
+ * This walk may not be exclusive; the PTE is permitted to change
+ * from under us.
*/
if (data->mkold && !stage2_try_set_pte(ctx, new))
return -EAGAIN;
@@ -1345,7 +1343,8 @@ bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr,
struct kvm_pgtable_walker walker = {
.cb = stage2_age_walker,
.arg = &data,
- .flags = KVM_PGTABLE_WALK_LEAF,
+ .flags = KVM_PGTABLE_WALK_LEAF |
+ KVM_PGTABLE_WALK_SHARED,
};
WARN_ON(kvm_pgtable_walk(pgt, addr, size, &walker));
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 8337009dde77..40e7427462a7 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1775,7 +1775,7 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
u64 size = (range->end - range->start) << PAGE_SHIFT;
bool young = false;
- write_lock(&kvm->mmu_lock);
+ read_lock(&kvm->mmu_lock);
if (!kvm->arch.mmu.pgt)
goto out;
@@ -1785,7 +1785,7 @@ bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
size, true);
out:
- write_unlock(&kvm->mmu_lock);
+ read_unlock(&kvm->mmu_lock);
return young;
}
@@ -1794,7 +1794,7 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
u64 size = (range->end - range->start) << PAGE_SHIFT;
bool young = false;
- write_lock(&kvm->mmu_lock);
+ read_lock(&kvm->mmu_lock);
if (!kvm->arch.mmu.pgt)
goto out;
@@ -1804,7 +1804,7 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
size, false);
out:
- write_unlock(&kvm->mmu_lock);
+ read_unlock(&kvm->mmu_lock);
return young;
}
--
2.45.1.288.g0e0cd299f1-goog
next prev parent reply other threads:[~2024-05-29 18:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 18:05 [PATCH v4 0/7] mm: multi-gen LRU: Walk secondary MMU page tables while aging James Houghton
2024-05-29 18:05 ` [PATCH v4 1/7] mm/Kconfig: Add LRU_GEN_WALKS_SECONDARY_MMU James Houghton
2024-05-29 18:05 ` [PATCH v4 2/7] mm: multi-gen LRU: Have secondary MMUs participate in aging James Houghton
2024-05-29 21:03 ` Yu Zhao
2024-05-29 21:59 ` Sean Christopherson
2024-05-29 22:21 ` Yu Zhao
2024-05-29 22:58 ` Sean Christopherson
2024-05-30 1:08 ` James Houghton
2024-05-31 6:06 ` Yu Zhao
2024-05-31 7:02 ` Oliver Upton
2024-05-31 16:45 ` Yu Zhao
2024-05-31 18:41 ` Oliver Upton
2024-06-03 22:45 ` James Houghton
2024-06-03 23:03 ` Sean Christopherson
2024-06-03 23:16 ` James Houghton
2024-06-04 0:23 ` Sean Christopherson
2024-05-31 7:24 ` Oliver Upton
2024-05-31 20:31 ` Yu Zhao
2024-05-31 21:06 ` David Matlack
2024-05-31 21:09 ` David Matlack
2024-05-31 21:18 ` Oliver Upton
2024-05-29 18:05 ` [PATCH v4 3/7] KVM: Add lockless memslot walk to KVM James Houghton
2024-05-29 21:51 ` Sean Christopherson
2024-05-30 3:26 ` James Houghton
2024-05-29 18:05 ` [PATCH v4 4/7] KVM: Move MMU lock acquisition for test/clear_young to architecture James Houghton
2024-05-29 21:55 ` Sean Christopherson
2024-05-30 3:27 ` James Houghton
2024-05-29 18:05 ` [PATCH v4 5/7] KVM: x86: Relax locking for kvm_test_age_gfn and kvm_age_gfn James Houghton
2024-05-29 18:05 ` James Houghton [this message]
2024-05-31 19:11 ` [PATCH v4 6/7] KVM: arm64: " Oliver Upton
2024-05-31 19:18 ` Oliver Upton
2024-06-04 22:20 ` James Houghton
2024-06-04 23:00 ` Oliver Upton
2024-06-04 23:36 ` Sean Christopherson
2024-05-29 18:05 ` [PATCH v4 7/7] KVM: selftests: Add multi-gen LRU aging to access_tracking_perf_test James Houghton
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=20240529180510.2295118-7-jthoughton@google.com \
--to=jthoughton@google.com \
--cc=kvm-riscv@lists.infradead.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