kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Li RongQing <lirongqing@baidu.com>
Cc: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com,
	x86@kernel.org, kvm@vger.kernel.org, lirongqing@baidu.com
Subject: Re: [PATCH][resend] KVM: x86: check steal time address when enable steal time
Date: Mon, 07 Mar 2022 10:12:39 +0100	[thread overview]
Message-ID: <87sfru9ldk.fsf@redhat.com> (raw)
In-Reply-To: <1646641011-55068-1-git-send-email-lirongqing@baidu.com>

Li RongQing <lirongqing@baidu.com> writes:

> check steal time address when enable steal time, do not update
> arch.st.msr_val if the address is invalid,  and return in #GP
>
> this can avoid unnecessary write/read invalid memory when guest
> is running
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  arch/x86/kvm/x86.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index eb402966..3ed0949 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3616,6 +3616,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  		if (data & KVM_STEAL_RESERVED_MASK)
>  			return 1;
>  
> +		if (!kvm_vcpu_gfn_to_memslot(vcpu, data >> PAGE_SHIFT))
> +			return 1;
> +

What about we use stronger kvm_is_visible_gfn() instead? I didn't put
much thought to what's going to happen if we put e.g. APIC access page
addr to the MSR, let's just cut any possibility.

>  		vcpu->arch.st.msr_val = data;
>  
>  		if (!(data & KVM_MSR_ENABLED))

-- 
Vitaly


  reply	other threads:[~2022-03-07  9:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07  8:16 [PATCH][resend] KVM: x86: check steal time address when enable steal time Li RongQing
2022-03-07  9:12 ` Vitaly Kuznetsov [this message]
2022-03-08  0:57   ` Sean Christopherson

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=87sfru9ldk.fsf@redhat.com \
    --to=vkuznets@redhat.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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;
as well as URLs for NNTP newsgroup(s).