[lvc-project] [PATCH] KVM: x86: Add SRCU protection for KVM_GET_SREGS2
Sean Christopherson
seanjc at google.com
Fri Jan 23 20:24:17 MSK 2026
On Fri, Jan 16, 2026, Vasiliy Kovalev wrote:
> ---
> Note 1: commit 85e5ba83c016 ("KVM: x86: Do all post-set CPUID processing
> during vCPU creation") in v6.14+ reduces the likelihood of hitting this
> path by ensuring proper MMU initialization, but does not eliminate the
> requirement for SRCU protection when accessing guest memory.
>
> Note 2: KVM_SET_SREGS2 is not modified because __set_sregs_common()
> already acquires SRCU when update_pdptrs=true, which covers the case
> when PDPTRs must be loaded from guest memory.
On the topic of the update_pdptrs behavior, what if we scope the fix to precisely
reading the PDPTRs? Not for performance reasons, but for documentation purposes,
e.g. so that future readers don't look at __get_sregs() and wonder why that call
isn't wrapped with SRCU protection.
I.e.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e013392fe20c..a5a65dde89c0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12145,9 +12145,11 @@ static void __get_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2)
return;
if (is_pae_paging(vcpu)) {
+ kvm_vcpu_srcu_read_lock(vcpu);
for (i = 0 ; i < 4 ; i++)
sregs2->pdptrs[i] = kvm_pdptr_read(vcpu, i);
sregs2->flags |= KVM_SREGS2_FLAGS_PDPTRS_VALID;
+ kvm_vcpu_srcu_read_unlock(vcpu);
}
}
> ---
> arch/x86/kvm/x86.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 8acfdfc583a1..73c900c72f31 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6619,7 +6619,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
> r = -ENOMEM;
> if (!u.sregs2)
> goto out;
> + kvm_vcpu_srcu_read_lock(vcpu);
> __get_sregs2(vcpu, u.sregs2);
> + kvm_vcpu_srcu_read_unlock(vcpu);
> r = -EFAULT;
> if (copy_to_user(argp, u.sregs2, sizeof(struct kvm_sregs2)))
> goto out;
> --
> 2.50.1
>
More information about the lvc-project
mailing list