Re: [PATCH] riscv: kvm: Skip preventive hfence.gvma for new G-stage mappings with Svvptc
Anup Patel <[email protected]> Mon, 13 Jul 2026 18:09:30 +0530
| Newsgroups | org.infradead.lists.kvm-riscv,org.infradead.lists.linux-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAAhSdy1YZYA6etr+Z552QNSGKM-iMpU7uGwDcYGydpb0b4qULg@mail.gmail.com> |
On Wed, Jul 1, 2026 at 1:23 PM Dylan.Wu <[email protected]> wrote: > > For Invalid->Valid G-stage leaf PTE updates, the flush in > kvm_riscv_gstage_set_pte() is preventive. When Svvptc is available, new > valid PTEs become visible to the page-table walker within a bounded > time, so an immediate hfence.gvma is unnecessary. > > Skip gstage_tlb_flush() for that case. Permission-restricting updates > continue to use the existing flush path. > > Assisted-by: YuanSheng: deepseek-v4-pro > Co-developed-by: Quan Zhou <[email protected]> > Signed-off-by: Quan Zhou <[email protected]> > Signed-off-by: Dylan.Wu <[email protected]> The patch subject is unnecessarily long and needs some simplification. Also, there is minor warning reported by checkpatch.pl related to include of asm/cpufeature.h. I will take care of both of these at the time of merging this patch. Reviewed-by: Anup Patel <[email protected]> Queued this patch as a fix for Linux-7.2-rcX Thanks, Anup > --- > arch/riscv/kvm/gstage.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c > index c4c3b7956..7b805112d 100644 > --- a/arch/riscv/kvm/gstage.c > +++ b/arch/riscv/kvm/gstage.c > @@ -10,6 +10,8 @@ > #include <linux/module.h> > #include <linux/pgtable.h> > #include <asm/kvm_gstage.h> > +#include <asm/cpufeature.h> > +#include <asm/hwcap.h> > > #ifdef CONFIG_64BIT > unsigned long kvm_riscv_gstage_max_pgd_levels __ro_after_init = 3; > @@ -171,8 +173,11 @@ int kvm_riscv_gstage_set_pte(struct kvm_gstage *gstage, > } > > if (pte_val(*ptep) != pte_val(map->pte)) { > + bool was_invalid = !pte_val(*ptep); > set_pte(ptep, map->pte); > - if (gstage_pte_leaf(ptep)) > + if (gstage_pte_leaf(ptep) && > + !(was_invalid && > + riscv_has_extension_unlikely(RISCV_ISA_EXT_SVVPTC))) > gstage_tlb_flush(gstage, current_level, map->addr); > } > > -- > 2.34.1 > -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv