[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D9QTFAE7R84D.2V08QTHORJTAH@ventanamicro.com>
Date: Thu, 08 May 2025 15:32:25 +0200
From: Radim Krčmář <rkrcmar@...tanamicro.com>
To: "Atish Patra" <atishp@...osinc.com>, "Anup Patel" <anup@...infault.org>,
"Atish Patra" <atishp@...shpatra.org>, "Paul Walmsley"
<paul.walmsley@...ive.com>, "Palmer Dabbelt" <palmer@...belt.com>,
"Alexandre Ghiti" <alex@...ti.fr>
Cc: <kvm@...r.kernel.org>, <kvm-riscv@...ts.infradead.org>,
<linux-riscv@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
"linux-riscv" <linux-riscv-bounces@...ts.infradead.org>
Subject: Re: [PATCH 4/5] RISC-V: KVM: Enable envcfg and sstateen bits lazily
2025-05-05T14:39:29-07:00, Atish Patra <atishp@...osinc.com>:
> SENVCFG and SSTATEEN CSRs are controlled by HSENVCFG(62) and
> SSTATEEN0(63) bits in hstateen. Enable them lazily at runtime
> instead of bootime.
>
> Signed-off-by: Atish Patra <atishp@...osinc.com>
> ---
> diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c
> @@ -256,9 +256,37 @@ int kvm_riscv_vcpu_hstateen_lazy_enable(struct kvm_vcpu *vcpu, unsigned int csr_
> return KVM_INSN_CONTINUE_SAME_SEPC;
> }
>
> +static int kvm_riscv_vcpu_hstateen_enable_senvcfg(struct kvm_vcpu *vcpu,
> + unsigned int csr_num,
> + unsigned long *val,
> + unsigned long new_val,
> + unsigned long wr_mask)
> +{
> + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_HSENVCFG);
> +}
Basically the same comments as for [1/5]:
Why don't we want to set the ENVCFG bit (62) unconditionally?
It would save us the trap on first access. We don't get anything from
the trap, so it looks like a net negative to me.
> +
> +static int kvm_riscv_vcpu_hstateen_enable_stateen(struct kvm_vcpu *vcpu,
> + unsigned int csr_num,
> + unsigned long *val,
> + unsigned long new_val,
> + unsigned long wr_mask)
> +{
> + const unsigned long *isa = vcpu->arch.isa;
> +
> + if (riscv_isa_extension_available(isa, SMSTATEEN))
> + return kvm_riscv_vcpu_hstateen_lazy_enable(vcpu, csr_num, SMSTATEEN0_SSTATEEN0);
> + else
> + return KVM_INSN_EXIT_TO_USER_SPACE;
> +}
The same argument applies to the SE0 bit (63) when the guest has the
sstateen extension.
KVM doesn't want to do anything other than stop trapping and reenter, so
it seems to me we could just not trap in the first place.
Thanks.
Powered by blists - more mailing lists