Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752322AbdHNHhE (ORCPT ); Mon, 14 Aug 2017 03:37:04 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37691 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbdHNHhC (ORCPT ); Mon, 14 Aug 2017 03:37:02 -0400 Subject: Re: [PATCH v1 1/4] KVM: MMU: check guest CR3 reserved bits based on its physical address width. To: Yu Zhang , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, xiaoguangrong@tencent.com, joro@8bytes.org References: <1502544906-1108-1-git-send-email-yu.c.zhang@linux.intel.com> <1502544906-1108-2-git-send-email-yu.c.zhang@linux.intel.com> From: Paolo Bonzini Message-ID: Date: Mon, 14 Aug 2017 09:36:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1502544906-1108-2-git-send-email-yu.c.zhang@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 996 Lines: 36 On 12/08/2017 15:35, Yu Zhang wrote: > + ctxt->ops->get_cpuid(ctxt, &eax, NULL, NULL, NULL); > + maxphyaddr = eax * 0xff; This is "&", not "*". You can also use rsvd_bits here. > + rsvd = (~((1UL << maxphyaddr) - 1)) & > + ~CR3_PCID_INVD; > + } > > if (new_val & rsvd) > return emulate_gp(ctxt, 0); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index e40a779..d9100c4 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -813,10 +813,10 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) > return 0; > } > > - if (is_long_mode(vcpu)) { > - if (cr3 & CR3_L_MODE_RESERVED_BITS) > - return 1; > - } else if (is_pae(vcpu) && is_paging(vcpu) && > + if (is_long_mode(vcpu) && > + (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63))) > + return 1; 62 is a little better, since 63 is the PCID invalidate bit. Paolo > + else if (is_pae(vcpu) && is_paging(vcpu) && > !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) > return 1; >