* [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping
@ 2026-05-28 11:38 Inochi Amaoto
2026-06-05 6:49 ` Anup Patel
2026-06-05 14:54 ` Anup Patel
0 siblings, 2 replies; 4+ messages in thread
From: Inochi Amaoto @ 2026-05-28 11:38 UTC (permalink / raw)
To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti
Cc: Inochi Amaoto, kvm, kvm-riscv, linux-riscv, linux-kernel,
Yixun Lan, Longbin Li
When enabling dirty ring, the dirty bitmap is disable, and the logging
check is always false as the RISC-V architecture does not select
"NEED_KVM_DIRTY_RING_WITH_BITMAP". Although the dirty log is recorded
since the write path already trying to add the dirty log, the logic for
logging check is broken and some side effect will occurs.
Enhance the logging check for mmu mapping so it can check both the dirty
ring and the dirty bitmap.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
arch/riscv/kvm/mmu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index 2d3def024270..b5873bca9dce 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -142,9 +142,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
enum kvm_mr_change change)
{
/*
- * At this point memslot has been committed and there is an
- * allocated dirty_bitmap[], dirty pages will be tracked while
- * the memory slot is write protected.
+ * At this point memslot has been committed and dirty pages will be
+ * tracked while the memory slot is write protected.
*/
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
if (kvm_dirty_log_manual_protect_and_init_set(kvm))
@@ -433,8 +432,8 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
struct vm_area_struct *vma;
struct kvm *kvm = vcpu->kvm;
struct kvm_mmu_memory_cache *pcache = &vcpu->arch.mmu_page_cache;
- bool logging = (memslot->dirty_bitmap &&
- !(memslot->flags & KVM_MEM_READONLY)) ? true : false;
+ bool logging = kvm_slot_dirty_track_enabled(memslot) &&
+ !(memslot->flags & KVM_MEM_READONLY);
unsigned long vma_pagesize, mmu_seq;
struct kvm_gstage gstage;
struct page *page;
--
2.54.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping
2026-05-28 11:38 [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping Inochi Amaoto
@ 2026-06-05 6:49 ` Anup Patel
2026-06-05 7:58 ` Inochi Amaoto
2026-06-05 14:54 ` Anup Patel
1 sibling, 1 reply; 4+ messages in thread
From: Anup Patel @ 2026-06-05 6:49 UTC (permalink / raw)
To: Inochi Amaoto
Cc: Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, kvm, kvm-riscv, linux-riscv, linux-kernel,
Yixun Lan, Longbin Li
On Thu, May 28, 2026 at 5:08 PM Inochi Amaoto <inochiama@gmail.com> wrote:
>
> When enabling dirty ring, the dirty bitmap is disable, and the logging
> check is always false as the RISC-V architecture does not select
> "NEED_KVM_DIRTY_RING_WITH_BITMAP". Although the dirty log is recorded
> since the write path already trying to add the dirty log, the logic for
> logging check is broken and some side effect will occurs.
>
> Enhance the logging check for mmu mapping so it can check both the dirty
> ring and the dirty bitmap.
>
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> ---
> arch/riscv/kvm/mmu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
> index 2d3def024270..b5873bca9dce 100644
> --- a/arch/riscv/kvm/mmu.c
> +++ b/arch/riscv/kvm/mmu.c
> @@ -142,9 +142,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
> enum kvm_mr_change change)
> {
> /*
> - * At this point memslot has been committed and there is an
> - * allocated dirty_bitmap[], dirty pages will be tracked while
> - * the memory slot is write protected.
> + * At this point memslot has been committed and dirty pages will be
> + * tracked while the memory slot is write protected.
> */
> if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
> if (kvm_dirty_log_manual_protect_and_init_set(kvm))
> @@ -433,8 +432,8 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
> struct vm_area_struct *vma;
> struct kvm *kvm = vcpu->kvm;
> struct kvm_mmu_memory_cache *pcache = &vcpu->arch.mmu_page_cache;
> - bool logging = (memslot->dirty_bitmap &&
> - !(memslot->flags & KVM_MEM_READONLY)) ? true : false;
Why is this not correct approach to determine whether logging is enabled ?
KVM ARM64 does a very similar thing (Refer, memslot_is_logging() in
arch/arm64/kvm/mmu.c).
> + bool logging = kvm_slot_dirty_track_enabled(memslot) &&
> + !(memslot->flags & KVM_MEM_READONLY);
> unsigned long vma_pagesize, mmu_seq;
> struct kvm_gstage gstage;
> struct page *page;
> --
> 2.54.0
>
Regards,
Anup
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping
2026-06-05 6:49 ` Anup Patel
@ 2026-06-05 7:58 ` Inochi Amaoto
0 siblings, 0 replies; 4+ messages in thread
From: Inochi Amaoto @ 2026-06-05 7:58 UTC (permalink / raw)
To: Anup Patel, Inochi Amaoto
Cc: Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, kvm, kvm-riscv, linux-riscv, linux-kernel,
Yixun Lan, Longbin Li
On Fri, Jun 05, 2026 at 12:19:03PM +0530, Anup Patel wrote:
> On Thu, May 28, 2026 at 5:08 PM Inochi Amaoto <inochiama@gmail.com> wrote:
> >
> > When enabling dirty ring, the dirty bitmap is disable, and the logging
> > check is always false as the RISC-V architecture does not select
> > "NEED_KVM_DIRTY_RING_WITH_BITMAP". Although the dirty log is recorded
> > since the write path already trying to add the dirty log, the logic for
> > logging check is broken and some side effect will occurs.
> >
> > Enhance the logging check for mmu mapping so it can check both the dirty
> > ring and the dirty bitmap.
> >
> > Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
> > ---
> > arch/riscv/kvm/mmu.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
> > index 2d3def024270..b5873bca9dce 100644
> > --- a/arch/riscv/kvm/mmu.c
> > +++ b/arch/riscv/kvm/mmu.c
> > @@ -142,9 +142,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
> > enum kvm_mr_change change)
> > {
> > /*
> > - * At this point memslot has been committed and there is an
> > - * allocated dirty_bitmap[], dirty pages will be tracked while
> > - * the memory slot is write protected.
> > + * At this point memslot has been committed and dirty pages will be
> > + * tracked while the memory slot is write protected.
> > */
> > if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
> > if (kvm_dirty_log_manual_protect_and_init_set(kvm))
> > @@ -433,8 +432,8 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
> > struct vm_area_struct *vma;
> > struct kvm *kvm = vcpu->kvm;
> > struct kvm_mmu_memory_cache *pcache = &vcpu->arch.mmu_page_cache;
> > - bool logging = (memslot->dirty_bitmap &&
> > - !(memslot->flags & KVM_MEM_READONLY)) ? true : false;
>
> Why is this not correct approach to determine whether logging is enabled ?
>
> KVM ARM64 does a very similar thing (Refer, memslot_is_logging() in
> arch/arm64/kvm/mmu.c).
>
ARM64 is correct as it select NEED_KVM_DIRTY_RING_WITH_BITMAP, which
will add a backup bitmap when enabling dirty ring. However, the RISCV
does not select this, which means the bitmap is not present when the
dirty ring is used.
Although we still have dirty log with dirty ring now, it comes from
the check in the mark_page_dirty_in_slot(). And the check for variable
"logging" is always false when enabling dirty ring.
Regards,
Inochi
> > + bool logging = kvm_slot_dirty_track_enabled(memslot) &&
> > + !(memslot->flags & KVM_MEM_READONLY);
> > unsigned long vma_pagesize, mmu_seq;
> > struct kvm_gstage gstage;
> > struct page *page;
> > --
> > 2.54.0
> >
>
> Regards,
> Anup
>
> --
> kvm-riscv mailing list
> kvm-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping
2026-05-28 11:38 [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping Inochi Amaoto
2026-06-05 6:49 ` Anup Patel
@ 2026-06-05 14:54 ` Anup Patel
1 sibling, 0 replies; 4+ messages in thread
From: Anup Patel @ 2026-06-05 14:54 UTC (permalink / raw)
To: Inochi Amaoto
Cc: Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, kvm, kvm-riscv, linux-riscv, linux-kernel,
Yixun Lan, Longbin Li
On Thu, May 28, 2026 at 5:08 PM Inochi Amaoto <inochiama@gmail.com> wrote:
>
> When enabling dirty ring, the dirty bitmap is disable, and the logging
> check is always false as the RISC-V architecture does not select
> "NEED_KVM_DIRTY_RING_WITH_BITMAP". Although the dirty log is recorded
> since the write path already trying to add the dirty log, the logic for
> logging check is broken and some side effect will occurs.
>
> Enhance the logging check for mmu mapping so it can check both the dirty
> ring and the dirty bitmap.
>
> Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Queued this patch for Linux-7.2
Thanks,
Anup
> ---
> arch/riscv/kvm/mmu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
> index 2d3def024270..b5873bca9dce 100644
> --- a/arch/riscv/kvm/mmu.c
> +++ b/arch/riscv/kvm/mmu.c
> @@ -142,9 +142,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
> enum kvm_mr_change change)
> {
> /*
> - * At this point memslot has been committed and there is an
> - * allocated dirty_bitmap[], dirty pages will be tracked while
> - * the memory slot is write protected.
> + * At this point memslot has been committed and dirty pages will be
> + * tracked while the memory slot is write protected.
> */
> if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
> if (kvm_dirty_log_manual_protect_and_init_set(kvm))
> @@ -433,8 +432,8 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
> struct vm_area_struct *vma;
> struct kvm *kvm = vcpu->kvm;
> struct kvm_mmu_memory_cache *pcache = &vcpu->arch.mmu_page_cache;
> - bool logging = (memslot->dirty_bitmap &&
> - !(memslot->flags & KVM_MEM_READONLY)) ? true : false;
> + bool logging = kvm_slot_dirty_track_enabled(memslot) &&
> + !(memslot->flags & KVM_MEM_READONLY);
> unsigned long vma_pagesize, mmu_seq;
> struct kvm_gstage gstage;
> struct page *page;
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-05 14:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-28 11:38 [PATCH] RISC-V: KVM: Enhance the logging check for mmu mapping Inochi Amaoto
2026-06-05 6:49 ` Anup Patel
2026-06-05 7:58 ` Inochi Amaoto
2026-06-05 14:54 ` Anup Patel
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®