[an error occurred while processing this directive]
|
|
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250825-69a3c8b588e0bb1fbb5b7beb@orel>
Date: Mon, 25 Aug 2025 11:22:11 -0500
From: Andrew Jones <ajones@...tanamicro.com>
To: Jinyu Tang <tjytimi@....com>
Cc: Anup Patel <anup@...infault.org>, Atish Patra <atish.patra@...ux.dev>,
Conor Dooley <conor.dooley@...rochip.com>, Yong-Xuan Wang <yongxuan.wang@...ive.com>,
Paul Walmsley <paul.walmsley@...ive.com>, Nutty Liu <nutty.liu@...mail.com>, kvm@...r.kernel.org,
kvm-riscv@...ts.infradead.org, linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] riscv: skip csr restore if vcpu preempted reload
On Mon, Aug 25, 2025 at 08:14:11PM +0800, Jinyu Tang wrote:
> The kvm_arch_vcpu_load() function is called in two cases for riscv:
> 1. When entering KVM_RUN from userspace ioctl.
> 2. When a preempted VCPU is scheduled back.
>
> In the second case, if no other KVM VCPU has run on this CPU since the
> current VCPU was preempted, the guest CSR (including AIA CSRS and HGTAP)
> values are still valid in the hardware and do not need to be restored.
>
> This patch is to skip the CSR write path when:
> 1. The VCPU was previously preempted
> (vcpu->scheduled_out == 1).
> 2. It is being reloaded on the same physical CPU
> (vcpu->arch.last_exit_cpu == cpu).
> 3. No other KVM VCPU has used this CPU in the meantime
> (vcpu == __this_cpu_read(kvm_former_vcpu)).
>
> This reduces many CSR writes with frequent preemption on the same CPU.
>
> Signed-off-by: Jinyu Tang <tjytimi@....com>
> Reviewed-by: Nutty Liu <nutty.liu@...mail.com>
> ---
> v2 -> v3:
> v2 was missing a critical check because I generated the patch from my
> wrong (experimental) branch. This is fixed in v3. Sorry for my trouble.
>
> v1 -> v2:
> Apply the logic to aia csr load. Thanks for
> Andrew Jones's advice.
>
> arch/riscv/kvm/vcpu.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
Reviewed-by: Andrew Jones <ajones@...tanamicro.com>
Powered by blists - more mailing lists