From: Koichiro Den <den@valinux.co.jp>
To: Andrew Jones <andrew.jones@linux.dev>
Cc: Anup Patel <anup@brainfault.org>,
Atish Patra <atish.patra@linux.dev>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Bingyu Xian <shanbeeyoo@gmail.com>,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] RISC-V: KVM: Batch user accesses when updating steal time
Date: Sat, 21 Nov 2026 23:59:33 +0900 [thread overview]
Message-ID: <awGevuQAuA349gO8@z790sl> (raw)
In-Reply-To: <awGJaUFUmBOa4xfO@orel>
On Sat, Nov 21, 2026 at 01:23:43PM +0100, Andrew Jones wrote:
> 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.
Thanks. What I had in mind was the exception in [1] for a CSR access that
"modifies the execution behavior of the instruction that performs the explicit
memory access". I wondered whether toggling it between the stores in the old
code also ordered them as seen by another hart. I agree we can't rely on that.
I'll split the barriers out into the first patch of v2 and add a Fixes tag.
[1] https://docs.riscv.org/reference/isa/v20260120/unpriv/zicsr.html#5-1-1-1-csr-access-ordering
>
> >
> > >
> > > >
> > > > Signed-off-by: Koichiro Den <den@valinux.co.jp>
> > > > ---
> > > > 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.
Makes sense. After polishing up the scoped_ version locally and looking at both
side by side, I now agree the scoped_ version looks a bit cleaner. I'll use it
in v2.
Thanks for the review.
Best regards,
Koichiro Den
>
> Thanks,
> drew
next prev parent reply other threads:[~2026-11-21 14:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 6:22 [PATCH 0/2] RISC-V: KVM: Lessen steal time update overhead Koichiro Den
2026-11-18 6:22 ` [PATCH 1/2] RISC-V: KVM: Batch user accesses when updating steal time Koichiro Den
2026-11-20 16:40 ` Andrew Jones
2026-11-20 17:20 ` Koichiro Den
2026-11-21 12:23 ` Andrew Jones
2026-11-21 14:59 ` Koichiro Den [this message]
2026-11-18 6:22 ` [PATCH 2/2] RISC-V: KVM: Skip steal-time updates when run_delay is unchanged Koichiro Den
2026-11-20 16:45 ` Andrew Jones
2026-11-20 17:25 ` Koichiro Den
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awGevuQAuA349gO8@z790sl \
--to=den@valinux.co.jp \
--cc=alex@ghiti.fr \
--cc=andrew.jones@linux.dev \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=shanbeeyoo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®