Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* question about arch/riscv/kvm/mmu.c
@ 2022-03-16 21:10 Julia Lawall
  2022-03-31  5:52 ` Palmer Dabbelt
  2022-03-31  6:36 ` Anup Patel
  0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2022-03-16 21:10 UTC (permalink / raw)
  To: kvm-riscv, kvm, linux-riscv, anup

Hello,

The function kvm_riscv_stage2_map contains the code:

mmu_seq = kvm->mmu_notifier_seq;

I noticed that in every other place in the kernel where the
mmu_notifier_seq field is read, there is a read barrier after it.  Is
there some reason why it is not necessary here?

thanks,
julia

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about arch/riscv/kvm/mmu.c
  2022-03-16 21:10 question about arch/riscv/kvm/mmu.c Julia Lawall
@ 2022-03-31  5:52 ` Palmer Dabbelt
  2022-03-31  6:36 ` Anup Patel
  1 sibling, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-03-31  5:52 UTC (permalink / raw)
  To: julia.lawall, anup, Atish Patra; +Cc: kvm-riscv, kvm, linux-riscv

On Wed, 16 Mar 2022 14:10:06 PDT (-0700), julia.lawall@inria.fr wrote:
> Hello,
>
> The function kvm_riscv_stage2_map contains the code:
>
> mmu_seq = kvm->mmu_notifier_seq;
>
> I noticed that in every other place in the kernel where the
> mmu_notifier_seq field is read, there is a read barrier after it.  Is
> there some reason why it is not necessary here?

I guess that's a better question for Atish and Anup, but certainly 
nothing jumps out at me.  There's a pretty good comment in the arm64 
port about their barrier:

        mmu_seq = vcpu->kvm->mmu_notifier_seq;
        /*
         * Ensure the read of mmu_notifier_seq happens before we call
         * gfn_to_pfn_prot (which calls get_user_pages), so that we don't risk
         * the page we just got a reference to gets unmapped before we have a
         * chance to grab the mmu_lock, which ensure that if the page gets
         * unmapped afterwards, the call to kvm_unmap_gfn will take it away
         * from us again properly. This smp_rmb() interacts with the smp_wmb()
         * in kvm_mmu_notifier_invalidate_<page|range_end>.
         *
         * Besides, __gfn_to_pfn_memslot() instead of gfn_to_pfn_prot() is
         * used to avoid unnecessary overhead introduced to locate the memory
         * slot because it's always fixed even @gfn is adjusted for huge pages.
         */
        smp_rmb();

I don't see anything that would invalidate that reasoning for us.  My 
guess is that we should have a similar barrier (and coment, and maybe 
call __gfn_to_pfn_memslot() too).  There's a handful of other 
interesting-looking differences between the riscv and arm64 ports around 
here that might be worth looking into as well.

Might also be worth updating that comment to indicate that the actual 
wmb() is in kvm_dec_notifier_count()?  Also, to make it sound less like 
arm64 is calling gfn_to_pfn_prot()...

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about arch/riscv/kvm/mmu.c
  2022-03-16 21:10 question about arch/riscv/kvm/mmu.c Julia Lawall
  2022-03-31  5:52 ` Palmer Dabbelt
@ 2022-03-31  6:36 ` Anup Patel
  2022-03-31  8:02   ` Julia Lawall
  1 sibling, 1 reply; 4+ messages in thread
From: Anup Patel @ 2022-03-31  6:36 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kvm-riscv, kvm, linux-riscv, Anup Patel

On Thu, Mar 17, 2022 at 2:40 AM Julia Lawall <julia.lawall@inria.fr> wrote:
>
> Hello,
>
> The function kvm_riscv_stage2_map contains the code:
>
> mmu_seq = kvm->mmu_notifier_seq;
>
> I noticed that in every other place in the kernel where the
> mmu_notifier_seq field is read, there is a read barrier after it.  Is
> there some reason why it is not necessary here?

When I did the initial porting of KVM RISC-V (2 years back), I did
not see such a barrier being used along with mmu_notifier_seq
field hence the current code.

I am certainly okay adding it to be consistent with other architectures.

Can you send a patch for this ?

Thanks,
Anup

>
> thanks,
> julia
>
> --
> kvm-riscv mailing list
> kvm-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kvm-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about arch/riscv/kvm/mmu.c
  2022-03-31  6:36 ` Anup Patel
@ 2022-03-31  8:02   ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2022-03-31  8:02 UTC (permalink / raw)
  To: Anup Patel; +Cc: kvm-riscv, kvm, linux-riscv, Anup Patel



On Thu, 31 Mar 2022, Anup Patel wrote:

> On Thu, Mar 17, 2022 at 2:40 AM Julia Lawall <julia.lawall@inria.fr> wrote:
> >
> > Hello,
> >
> > The function kvm_riscv_stage2_map contains the code:
> >
> > mmu_seq = kvm->mmu_notifier_seq;
> >
> > I noticed that in every other place in the kernel where the
> > mmu_notifier_seq field is read, there is a read barrier after it.  Is
> > there some reason why it is not necessary here?
>
> When I did the initial porting of KVM RISC-V (2 years back), I did
> not see such a barrier being used along with mmu_notifier_seq
> field hence the current code.
>
> I am certainly okay adding it to be consistent with other architectures.
>
> Can you send a patch for this ?

Sure, will do.

julia

>
> Thanks,
> Anup
>
> >
> > thanks,
> > julia
> >
> > --
> > kvm-riscv mailing list
> > kvm-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/kvm-riscv
>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-31  8:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-16 21:10 question about arch/riscv/kvm/mmu.c Julia Lawall
2022-03-31  5:52 ` Palmer Dabbelt
2022-03-31  6:36 ` Anup Patel
2022-03-31  8:02   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox