From: "Radim Krčmář" <rkrcmar@ventanamicro.com>
To: "Atish Patra" <atish.patra@linux.dev>,
"Anup Patel" <anup@brainfault.org>,
"Atish Patra" <atishp@atishpatra.org>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alexandre Ghiti" <alex@ghiti.fr>
Cc: <kvm@vger.kernel.org>, <kvm-riscv@lists.infradead.org>,
<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
"linux-riscv" <linux-riscv-bounces@lists.infradead.org>
Subject: Re: [PATCH 0/5] Enable hstateen bits lazily for the KVM RISC-V Guests
Date: Wed, 07 May 2025 16:36:30 +0200 [thread overview]
Message-ID: <D9Q05T702L8Y.3UTLG7VXIFXOK@ventanamicro.com> (raw)
In-Reply-To: <bc0f1273-d596-47dd-bcc6-be9894157828@linux.dev>
2025-05-06T11:24:41-07:00, Atish Patra <atish.patra@linux.dev>:
> On 5/6/25 2:24 AM, Radim Krčmář wrote:
>> 2025-05-05T14:39:25-07:00, Atish Patra <atishp@rivosinc.com>:
>>> This series adds support for enabling hstateen bits lazily at runtime
>>> instead of statically at bootime. The boot time enabling happens for
>>> all the guests if the required extensions are present in the host and/or
>>> guest. That may not be necessary if the guest never exercise that
>>> feature. We can enable the hstateen bits that controls the access lazily
>>> upon first access. This providers KVM more granular control of which
>>> feature is enabled in the guest at runtime.
>>>
>>> Currently, the following hstateen bits are supported to control the access
>>> from VS mode.
>>>
>>> 1. BIT(58): IMSIC : STOPEI and IMSIC guest interrupt file
>>> 2. BIT(59): AIA : SIPH/SIEH/STOPI
>>> 3. BIT(60): AIA_ISEL : Indirect csr access via siselect/sireg
>>> 4. BIT(62): HSENVCFG : SENVCFG access
>>> 5. BIT(63): SSTATEEN0 : SSTATEEN0 access
>>>
>>> KVM already support trap/enabling of BIT(58) and BIT(60) in order
>>> to support sw version of the guest interrupt file.
>> I don't think KVM toggles the hstateen bits at runtime, because that
>> would mean there is a bug even in current KVM.
>
> This was a typo. I meant to say trap/emulate BIT(58) and BIT(60).
> This patch series is trying to enable the toggling of the hstateen bits
> upon first access.
>
> Sorry for the confusion.
No worries, it's my fault for misreading.
I got confused, because the code looked like generic lazy enablement,
while it's really only for the upper 32 bits and this series is not lazy
toggling any VS-mode visible bits.
>>> This series extends
>>> those to enable to correpsonding hstateen bits in PATCH1. The remaining
>>> patches adds lazy enabling support of the other bits.
>> The ISA has a peculiar design for hstateen/sstateen interaction:
>>
>> For every bit in an hstateen CSR that is zero (whether read-only zero
>> or set to zero), the same bit appears as read-only zero in sstateen
>> when accessed in VS-mode.
>
> Correct.
>
>> This means we must clear bit 63 in hstateen and trap on sstateen
>> accesses if any of the sstateen bits are not supposed to be read-only 0
>> to the guest while the hypervisor wants to have them as 0.
>
> Currently, there are two bits in sstateen. FCSR and ZVT which are not
> used anywhere in opensbi/Linux/KVM stack.
True, I guess we can just make sure the current code can't by mistake
lazily enable any of the bottom 32 hstateen bits and handle the case
properly later.
> In case, we need to enable one of the bits in the future, does hypevisor
> need to trap every sstateen access ?
We need to trap sstateen accesses if the guest is supposed to be able to
control a bit in sstateen, but the hypervisor wants to lazily enable
that feature and sets 0 in hstateen until the first trap.
If hstateen is 1 for all features that the guest could control through
sstateen, we can and should just set the SE bit (63) to 1 as well.
> As per my understanding, it should be handled in the hardware and any
> write access to to those bits should be masked
> with hstateen bit value so that it matches. That's what we do in Qemu as
> well.
Right, hardware will do the job most of the time. It's really only for
the lazy masking, beause if we don't trap the stateen accesses, they
would differ from what the guest should see.
next prev parent reply other threads:[~2025-05-07 14:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 21:39 [PATCH 0/5] Enable hstateen bits lazily for the KVM RISC-V Guests Atish Patra
2025-05-05 21:39 ` [PATCH 1/5] RISC-V: KVM: Lazy enable hstateen IMSIC & ISEL bit Atish Patra
2025-05-08 13:31 ` Radim Krčmář
2025-05-05 21:39 ` [PATCH 2/5] RISC-V: KVM: Add a hstateen lazy enabler helper function Atish Patra
2025-05-05 21:39 ` [PATCH 3/5] RISC-V: KVM: Support lazy enabling of siselect and aia bits Atish Patra
2025-05-05 21:39 ` [PATCH 4/5] RISC-V: KVM: Enable envcfg and sstateen bits lazily Atish Patra
2025-05-08 13:32 ` Radim Krčmář
2025-05-09 22:38 ` Atish Patra
2025-05-12 10:25 ` Radim Krčmář
2025-05-05 21:39 ` [PATCH 5/5] RISC-V: KVM: Remove the boot time enabling of hstateen bits Atish Patra
2025-05-06 9:24 ` [PATCH 0/5] Enable hstateen bits lazily for the KVM RISC-V Guests Radim Krčmář
2025-05-06 18:24 ` Atish Patra
2025-05-07 14:36 ` Radim Krčmář [this message]
2025-05-08 0:34 ` Atish Patra
2025-05-08 13:45 ` Radim Krčmář
2025-05-09 22:26 ` Atish Patra
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=D9Q05T702L8Y.3UTLG7VXIFXOK@ventanamicro.com \
--to=rkrcmar@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=atish.patra@linux.dev \
--cc=atishp@atishpatra.org \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv-bounces@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.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