[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f60715b1-3d15-4929-95c6-f21b433c14c5@linux.dev>
Date: Fri, 13 Jun 2025 17:46:38 -0700
From: Atish Patra <atish.patra@...ux.dev>
To: Anup Patel <apatel@...tanamicro.com>
Cc: Palmer Dabbelt <palmer@...belt.com>,
Paul Walmsley <paul.walmsley@...ive.com>, Alexandre Ghiti <alex@...ti.fr>,
Andrew Jones <ajones@...tanamicro.com>, Anup Patel <anup@...infault.org>,
kvm@...r.kernel.org, kvm-riscv@...ts.infradead.org,
linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 07/12] RISC-V: KVM: Use ncsr_xyz() in
kvm_riscv_vcpu_trap_redirect()
On 6/12/25 11:57 PM, Anup Patel wrote:
> The H-extension CSRs accessed by kvm_riscv_vcpu_trap_redirect() will
> trap when KVM RISC-V is running as Guest/VM hence remove these traps
> by using ncsr_xyz() instead of csr_xyz().
>
> Signed-off-by: Anup Patel <apatel@...tanamicro.com>
> ---
> arch/riscv/kvm/vcpu_exit.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
> index 6e0c18412795..85c43c83e3b9 100644
> --- a/arch/riscv/kvm/vcpu_exit.c
> +++ b/arch/riscv/kvm/vcpu_exit.c
> @@ -9,6 +9,7 @@
> #include <linux/kvm_host.h>
> #include <asm/csr.h>
> #include <asm/insn-def.h>
> +#include <asm/kvm_nacl.h>
>
> static int gstage_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run,
> struct kvm_cpu_trap *trap)
> @@ -135,7 +136,7 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu,
> void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu,
> struct kvm_cpu_trap *trap)
> {
> - unsigned long vsstatus = csr_read(CSR_VSSTATUS);
> + unsigned long vsstatus = ncsr_read(CSR_VSSTATUS);
>
> /* Change Guest SSTATUS.SPP bit */
> vsstatus &= ~SR_SPP;
> @@ -151,15 +152,15 @@ void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu,
> vsstatus &= ~SR_SIE;
>
> /* Update Guest SSTATUS */
> - csr_write(CSR_VSSTATUS, vsstatus);
> + ncsr_write(CSR_VSSTATUS, vsstatus);
>
> /* Update Guest SCAUSE, STVAL, and SEPC */
> - csr_write(CSR_VSCAUSE, trap->scause);
> - csr_write(CSR_VSTVAL, trap->stval);
> - csr_write(CSR_VSEPC, trap->sepc);
> + ncsr_write(CSR_VSCAUSE, trap->scause);
> + ncsr_write(CSR_VSTVAL, trap->stval);
> + ncsr_write(CSR_VSEPC, trap->sepc);
>
> /* Set Guest PC to Guest exception vector */
> - vcpu->arch.guest_context.sepc = csr_read(CSR_VSTVEC);
> + vcpu->arch.guest_context.sepc = ncsr_read(CSR_VSTVEC);
>
> /* Set Guest privilege mode to supervisor */
> vcpu->arch.guest_context.sstatus |= SR_SPP;
Reviewed-by: Atish Patra <atishp@...osinc.com>
Powered by blists - more mailing lists