On 26.02.2026 12:51, Oleksii Kurochko wrote:
> Introduce vcpu_csr_init() to initialise hypervisor CSRs that control
> vCPU execution and virtualization behaviour before the vCPU is first
> scheduled.
> The function configures trap and interrupt delegation to VS-mode by
> setting the appropriate bits in the hedeleg and hideleg registers,
> initializes hstatus so that execution enters VS-mode when control is
> passed to the guest, and restricts guest access to hardware performance
> counters by initializing hcounteren, as unrestricted access would
> require additional handling in Xen.
> When the Smstateen and SSAIA extensions are available, access to AIA
> CSRs and IMSIC guest interrupt files is enabled by setting the
> corresponding bits in hstateen0, avoiding unnecessary traps into Xen
> (note that SVSLCT(Supervisor Virtual Select) name is used intead of
> CSRIND as OpenSBI uses such name and riscv_encoding.h is mostly based
> on it).
> If the Svpbmt extension is supported, the PBMTE bit is set in
> henvcfg to allow its use for VS-stage address translation. Guest
> access to the ENVCFG CSR is also enabled by setting ENVCFG bit in
> hstateen0, as a guest may need to control certain characteristics of
> the U-mode (VU-mode when V=1) execution environment.
> 
> For CSRs that may contain read-only bits (e.g. hedeleg, hideleg,
> hstateen0), to the written value a correspondent mask is applied to
> avoid divergence between the software state and the actual CSR
> contents.
> 
> As hstatus is not part of struct arch_vcpu (it already resides in
> struct cpu_user_regs), introduce vcpu_guest_cpu_user_regs() to provide
> a uniform way to access hstatus and other guest CPU user registers.
> 
> This establishes a consistent and well-defined initial CSR state for
> vCPUs prior to their first context switch.
> 
> Signed-off-by: Oleksii Kurochko <[email protected]>

Acked-by: Jan Beulich <[email protected]>


Reply via email to