Re: [PATCH v2 5/5] LoongArch: KVM: Enable separate vmid feature

[email protected]
Newsgroups org.kernel.vger.kvm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `CSR_GTLBC_USEVMID` bit is not cleared when virtualization is disabled, leaking guest TLB hardware state into the host execution environment.
--

--- Patch [5]: [PATCH v2 5/5] LoongArch: KVM: Enable separate vmid feature ---
commit 3bea8b9a7dbd607efeb389e6233ef3a1a4c29bf9
Author: Bibo Mao <[email protected]>

LoongArch: KVM: Enable separate vmid feature

This commit enables the separate VMID feature on LoongArch KVM if
cpu_has_guestid is true when LVZ is enabled and the LVZ version is 2.
It updates cpu-probe to set LOONGARCH_CPU_GUESTID and modifies
kvm_arch_enable_virtualization_cpu() to configure the new bit.

[ ... ]

> diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
> index 72c1d23156e50..712b078db0d54 100644
> --- a/arch/loongarch/kvm/main.c
> +++ b/arch/loongarch/kvm/main.c
> @@ -359,7 +359,7 @@ int kvm_arch_enable_virtualization_cpu(void)
>  	write_csr_gcfg(0);
>  	write_csr_gstat(0);
>  	write_csr_gintc(0);
> -	clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI);
> +	clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI | CSR_GTLBC_USEVMID);

[Severity: Medium]
Should CSR_GTLBC_USEVMID also be cleared when virtualization is disabled?

When KVM is unloaded or a CPU is brought offline, the hardware virtualization
state is supposed to be fully restored. While this patch updates
kvm_arch_enable_virtualization_cpu() to clear CSR_GTLBC_USEVMID during
initialization, the corresponding disable function seems to miss it:

arch/loongarch/kvm/main.c:kvm_arch_disable_virtualization_cpu() {
	write_csr_gcfg(0);
	write_csr_gstat(0);
	write_csr_gintc(0);
	clear_csr_gtlbc(CSR_GTLBC_USETGID | CSR_GTLBC_TOTI);
	...
}

Does this cause the USEVMID configuration to leak into the host execution
environment?

Although the host operates in root mode (VMID 0), leaving hypervisor
hardware features enabled could potentially interfere with kexec or
secondary hypervisor setups.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.