Re: [PATCH v3 1/3] RISC-V: KVM: Treat -EEXIST from G-stage map as success
Anup Patel <[email protected]> Wed, 29 Jul 2026 21:36:14 +0530
| Newsgroups | org.infradead.lists.linux-riscv,org.infradead.lists.kvm-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <CAAhSdy3ziS_1iiUjC5HSVqX9iMgckyS7Yro=xwZyomxXC=MC7w@mail.gmail.com> |
On Wed, Jul 29, 2026 at 5:37 PM Bingyu.Xian <[email protected]> wrote: > > When a concurrent vCPU installs the same G-stage mapping while we are > waiting for mmu_lock, kvm_riscv_gstage_map_page() returns -EEXIST. > This is not an error -- the page is correctly mapped and the faulting > vCPU can simply retry the guest instruction -- but KVM was treating it > as one: printing "Failed to map in G-stage" to dmesg and propagating > -EEXIST all the way to userspace. The kvm_riscv_gstage_map_page() return -EEXIST only when a leaf-PTE of higher-order already exists. It does not return error when leaf-PTE at same level already exists so this is an invalid fix. Regards, Anup > > Align RISC-V with x86 and arm64, which already swallow -EEXIST in > their respective fault handlers. This also lets kvm_release_faultin_page() > drop its "ret && ret != -EEXIST" special case: with ret normalized to 0 > the regular release path is correct. > > Fixes: 9d05c1fee837 ("RISC-V: KVM: Implement stage2 page table programming") > Cc: [email protected] > Assisted-by: YuanSheng: deepseek-v4-pro > Co-developed-by: Quan Zhou <[email protected]> > Signed-off-by: Quan Zhou <[email protected]> > Signed-off-by: Bingyu Xian <[email protected]> > --- > arch/riscv/kvm/mmu.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c > index 8a0aa5e0e216..943d8dc72105 100644 > --- a/arch/riscv/kvm/mmu.c > +++ b/arch/riscv/kvm/mmu.c > @@ -652,11 +652,13 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot, > vma_pagesize, true, true, out_map); > } > > - if (ret) > + if (ret == -EEXIST) > + ret = 0; > + else if (ret) > kvm_err("Failed to map in G-stage\n"); > > out_unlock: > - kvm_release_faultin_page(kvm, page, ret && ret != -EEXIST, writable); > + kvm_release_faultin_page(kvm, page, ret, writable); > write_unlock(&kvm->mmu_lock); > return ret; > } > -- > 2.54.0 > _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv