From: David Hildenbrand Subject: Re: [PATCH] kvm: x86: Disallow illegal IA32_APIC_BASE MSR values Date: Wed, 9 Aug 2017 11:13:02 +0200 Message-ID: <14bc7c98-d4a8-7e97-3da2-b5792a4b3e22@redhat.com> References: <20170808232726.118570-1-jmattson@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: Jim Mattson , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55054 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752333AbdHIJNE (ORCPT ); Wed, 9 Aug 2017 05:13:04 -0400 In-Reply-To: <20170808232726.118570-1-jmattson@google.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 09.08.2017 01:27, Jim Mattson wrote: > Host-initiated writes to the IA32_APIC_BASE MSR do not have to follow > local APIC state transition constraints, but the value written must be > valid. > > Signed-off-by: Jim Mattson > --- > arch/x86/kvm/x86.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index d734aa8c5b4f..fb786d9feef1 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -313,10 +313,11 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > u64 reserved_bits = ((~0ULL) << cpuid_maxphyaddr(vcpu)) | > 0x2ff | (guest_cpuid_has_x2apic(vcpu) ? 0 : X2APIC_ENABLE); > > + if ((msr_info->data & reserved_bits) != 0 || > + new_state == X2APIC_ENABLE) I'd drop the != 0 here and fit it into one line. > + return 1; > if (!msr_info->host_initiated && > - ((msr_info->data & reserved_bits) != 0 || > - new_state == X2APIC_ENABLE || > - (new_state == MSR_IA32_APICBASE_ENABLE && > + ((new_state == MSR_IA32_APICBASE_ENABLE && > old_state == (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE)) || > (new_state == (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE) && > old_state == 0))) > @@ -7444,7 +7445,8 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, > kvm_x86_ops->set_efer(vcpu, sregs->efer); > apic_base_msr.data = sregs->apic_base; > apic_base_msr.host_initiated = true; > - kvm_set_apic_base(vcpu, &apic_base_msr); > + if (kvm_set_apic_base(vcpu, &apic_base_msr)) > + return -EINVAL; I assume we don't have to document this new behavior. > > mmu_reset_needed |= kvm_read_cr0(vcpu) != sregs->cr0; > kvm_x86_ops->set_cr0(vcpu, sregs->cr0); > >From what I can tell, this looks good to me. -- Thanks, David