[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b70b6803-b12b-420f-8a96-8cb0936773da@linux.intel.com>
Date: Wed, 11 Jun 2025 10:16:28 +0800
From: "Mi, Dapeng" <dapeng1.mi@...ux.intel.com>
To: Sean Christopherson <seanjc@...gle.com>,
Paolo Bonzini <pbonzini@...hat.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Chao Gao <chao.gao@...el.com>, Borislav Petkov <bp@...en8.de>,
Xin Li <xin@...or.com>, Francesco Lavra <francescolavra.fl@...il.com>,
Manali Shukla <Manali.Shukla@....com>
Subject: Re: [PATCH v2 06/32] KVM: SVM: Kill the VM instead of the host if MSR
interception is buggy
On 6/11/2025 6:57 AM, Sean Christopherson wrote:
> WARN and kill the VM instead of panicking the host if KVM attempts to set
> or query MSR interception for an unsupported MSR. Accessing the MSR
> interception bitmaps only meaningfully affects post-VMRUN behavior, and
> KVM_BUG_ON() is guaranteed to prevent the current vCPU from doing VMRUN,
> i.e. there is no need to panic the entire host.
>
> Opportunistically move the sanity checks about their use to index into the
> MSRPM, e.g. so that bugs only WARN and terminate the VM, as opposed to
> doing that _and_ generating an out-of-bounds load.
>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> arch/x86/kvm/svm/svm.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index c75977ca600b..7e39b9df61f1 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -824,11 +824,12 @@ static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr)
> to_svm(vcpu)->msrpm;
>
> offset = svm_msrpm_offset(msr);
> + if (KVM_BUG_ON(offset == MSR_INVALID, vcpu->kvm))
> + return false;
> +
> bit_write = 2 * (msr & 0x0f) + 1;
> tmp = msrpm[offset];
>
> - BUG_ON(offset == MSR_INVALID);
> -
> return test_bit(bit_write, &tmp);
> }
>
> @@ -854,12 +855,13 @@ static void set_msr_interception_bitmap(struct kvm_vcpu *vcpu, u32 *msrpm,
> write = 0;
>
> offset = svm_msrpm_offset(msr);
> + if (KVM_BUG_ON(offset == MSR_INVALID, vcpu->kvm))
> + return;
> +
> bit_read = 2 * (msr & 0x0f);
> bit_write = 2 * (msr & 0x0f) + 1;
> tmp = msrpm[offset];
>
> - BUG_ON(offset == MSR_INVALID);
> -
> read ? clear_bit(bit_read, &tmp) : set_bit(bit_read, &tmp);
> write ? clear_bit(bit_write, &tmp) : set_bit(bit_write, &tmp);
>
Reviewed-by: Dapeng Mi <dapeng1.mi@...ux.intel.com>
Powered by blists - more mailing lists