Re: [PATCH 1/2] RISC-V: KVM: Batch user accesses when updating steal time
From: Andrew Jones
Date: Sat Nov 21 2026 - 07:24:31 EST
On Sat, Nov 21, 2026 at 02:20:17AM +0900, Koichiro Den wrote:
> On Fri, Nov 20, 2026 at 05:40:29PM +0100, Andrew Jones wrote:
> > On Wed, Nov 18, 2026 at 03:22:41PM +0900, Koichiro Den wrote:
> > > Updating the SBI STA shared structure performs 2x get_user() + 3x
> > > put_user() calls, each of which toggles sstatus.SUM.
> > >
> > > Keep SUM enabled across all five accesses to the shared structure.
> > >
> > > Note that write barriers are added to order the odd sequence store
> > > before the steal-time update and the even sequence store after it.
>
> Hi Andrew, thanks for the review.
>
> >
> > The barrier additions should probably be posted separately with a Fixes
> > tag.
>
> That's exactly what I wasn't sure about when I read the ISA spec.
> It was unclear to me from the Zicsr ordering rules whether the SUM toggle in
> the old code's get_user() and put_user() calls also order the stores to 'sequence'
> and 'steal' as seen by another hart.
> (I don't think they do, but I'm not 100% sure. It feels a bit like trying to
> prove a negative, as I couldn't find a clear statement. I may have missed one
> though. OTOH, the new code surely needs the barrier, so I included them.)
>
> Do you read the spec as allowing another hart to observe those stores out of
> order in the old code? If so, I agree the barriers can go in a separate patch.
Yes, we always needed the barriers since we need something to pair with
the virt_rmb()'s in pv_time_steal_clock(). get/put_user weren't covering
for that omission either because CSR accesses are weakly ordered.
>
> >
> > >
> > > Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
> > > ---
> > > To reviewers: please let me know if you'd prefer
> > > scoped_user_rw_access() here.
For scoped_ or not, whatever you think reads the best. I prefer scoped_
when it makes sense, as it's harder to get wrong, but readability also
matters.
Thanks,
drew