public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Vasiliy Kovalev <kovalev@altlinux.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	x86@kernel.org, kvm@vger.kernel.org,
	 linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: Re: [PATCH] KVM: x86: Add SRCU protection for KVM_GET_SREGS2
Date: Fri, 23 Jan 2026 09:24:17 -0800	[thread overview]
Message-ID: <aXOuwWI3WcvT6Ccb@google.com> (raw)
In-Reply-To: <20260116151523.291892-1-kovalev@altlinux.org>

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
> 

  reply	other threads:[~2026-01-23 17:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 15:15 [PATCH] KVM: x86: Add SRCU protection for KVM_GET_SREGS2 Vasiliy Kovalev
2026-01-23 17:24 ` Sean Christopherson [this message]
2026-01-23 22:46   ` Vasiliy Kovalev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aXOuwWI3WcvT6Ccb@google.com \
    --to=seanjc@google.com \
    --cc=kovalev@altlinux.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=pbonzini@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox