From: SeungJu Cheon <suunj1331@gmail.com>
To: anup@brainfault.org, atish.patra@linux.dev
Cc: tjytimi@163.com, inochiama@gmail.com, pjw@kernel.org,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
andrew.jones@linux.dev, pbonzini@redhat.com, seanjc@google.com,
kvm-riscv@lists.infradead.org, kvm@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, SeungJu Cheon <suunj1331@gmail.com>
Subject: [PATCH] KVM: riscv: Set Accessed bit in dirty-log write fault fast path
Date: Fri, 16 Oct 2026 19:14:58 +0900 [thread overview]
Message-ID: <20261016101458.221648-1-suunj1331@gmail.com> (raw)
kvm_riscv_mmu_dirty_log_write_fault_fast() considers a leaf with W
and D set already handled, even if aging has cleared its A bit.
On hardware that faults when A is clear, the fast path returns
true without setting A and skips the slow path that would set it.
The guest retries the same store, but A is still clear, so it
faults again. This repeats indefinitely, preventing the guest
from making progress.
Host reclaim or page_idle can trigger this while dirty logging is
enabled, potentially hanging vCPUs during live migration.
Require _PAGE_ACCESSED in addition to W and D before treating the
fault as handled, and set A along with W and D. The existing
cmpxchg loop retries if aging changes the PTE before the update.
Fixes: 7705be59eb2d ("KVM: riscv: Fast-path dirty logging write faults")
Cc: stable@vger.kernel.org # 7.2+
Signed-off-by: SeungJu Cheon <suunj1331@gmail.com>
---
Testing:
On a HiFive Premier P550 (EIC7700X, which traps on clear A/D bits),
run:
dirty_log_perf_test -v 3 -b 256M -i 3
While the test runs, repeatedly mark all system RAM idle through
/sys/kernel/mm/page_idle/bitmap.
Before the fix, the test did not complete its first iteration in
over 11 minutes, with lock_stat showing about 16k read-side
mmu_lock acquisitions per second from the fast path.
After the fix, all three iterations complete, each taking about
29 seconds under the same aging workload.
arch/riscv/kvm/mmu.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index 78a1826c466d..042d1e3b3547 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -591,14 +591,15 @@ static bool kvm_riscv_mmu_dirty_log_write_fault_fast(struct kvm *kvm,
dirty_marked = true;
}
- if ((pte_val(old_pte) & (_PAGE_WRITE | _PAGE_DIRTY)) ==
- (_PAGE_WRITE | _PAGE_DIRTY)) {
+ if ((pte_val(old_pte) &
+ (_PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)) ==
+ (_PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)) {
new_pte = old_pte;
ret = true;
break;
}
- new_pte = pte_mkdirty(pte_mkwrite_novma(old_pte));
+ new_pte = pte_mkyoung(pte_mkdirty(pte_mkwrite_novma(old_pte)));
if (kvm_riscv_gstage_try_update_pte(&gstage, ptep_level, gpa,
ptep, old_pte, new_pte)) {
--
2.52.0
reply other threads:[~2026-10-16 10:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261016101458.221648-1-suunj1331@gmail.com \
--to=suunj1331@gmail.com \
--cc=alex@ghiti.fr \
--cc=andrew.jones@linux.dev \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=inochiama@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=pjw@kernel.org \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
--cc=tjytimi@163.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®