Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3311253imm; Sun, 13 May 2018 08:34:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZolPB0wnwsRmgs5xON3VtD38Xl8mlpgQ3O0v3JYEcWqLPTMVtIVwmNFpwtoWAK4spemH5wC X-Received: by 2002:a63:69c4:: with SMTP id e187-v6mr5649031pgc.415.1526225689276; Sun, 13 May 2018 08:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526225689; cv=none; d=google.com; s=arc-20160816; b=hS7kQDeU0uA85PMmJjBQy1NiJTmJBQKSsCM8IfZEM9fynY3ZG9inE7Gr+8RIYuHcuD qmYx5Kb1e8jGsFDA2aONrGoTBP2zlTeImXhhT2/mePvNZpM3nfkEg4W2RoZoLaqb2voT aOt+WOHcTeJlkqMlEyrDK203xw7kl+oAB52XB6BC19iAakh2ENFonP1JrKtUlv8oKIaq rgqqqhvgwG3ThHB3uP4UrHFfVp9WJjcxJjzVkLsUSMO5NJiV88DMAL6Gpi2+90rYImAQ 7PnA1un0uTfvGC6JV15ftQy7gBuEZ+3eGH1pKZ2XPSXR6f7A3TiGdTSRxIBxfHx3VHH3 aQZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=02rFDSIKh/IPDE9EyatIvnlvzTIxRhY9NVFOQbWgkaw=; b=vaw3/XLarwwSZYRmC2AYIAGnT6vd/xDA06ZFJigbuMqBm/9xoU/fiuDMdwV9P/Qpe+ +Se36zgfs22oibtAAvqB9J8FWFqOPOvJ3l84QUVznsZh9BZo6kqbDmW0ap3T1yFAkO+3 PzAuHe0n+yGDoMk5o3k/pjwBvFUzNLi09Zl6iq+p1PhA02ILjytozsi6oXA5IKWe+lVW 1ZBPnfYi5B53wHZ/LEH20AVADmKwmnE0e8gY64hxJ8/pcXnXyXkG9rblt5MRxgvG0F4F UHlHGmLANezUpkps442MwlUvo06CYmlpzxJl4OBNOL9S/Aa24WOTyT0xmSg7XNkUSYUG f86A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q5ogV0Fk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t17-v6si7167455plo.266.2018.05.13.08.34.20; Sun, 13 May 2018 08:34:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q5ogV0Fk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751790AbeEMPeL (ORCPT + 99 others); Sun, 13 May 2018 11:34:11 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40412 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751449AbeEMPeJ (ORCPT ); Sun, 13 May 2018 11:34:09 -0400 Received: by mail-pf0-f194.google.com with SMTP id f189-v6so4855686pfa.7 for ; Sun, 13 May 2018 08:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=02rFDSIKh/IPDE9EyatIvnlvzTIxRhY9NVFOQbWgkaw=; b=q5ogV0FkQ/yx1ZZRgOiWASDapVVVIrFyYpzlPUD1iMkcebQt/Q072Y82c7TJ9Dr42G pkuA15/xxn7tUA3c5yKZswUx0v2l0vV6hveOkdDP/LCst/XS+jquWNJ0xe5qotGpjQv5 5orjoKDPdNv1xhFuws87JLIhqVnodWl8+zaLWdm2eoyIo8CSO7m9z3OGRqlWN3vQxfFz 9moe5CSXQR+MD9bgejlurRtTDS2DWbSzyg1+7D0vORrVhYQWnf7ZwFNg75WHHlSd4pvJ MRwXRUJpOxNA28M7LOB7oNUpCs/0GwfpDtSuUe9OKt9IiM7P2J3io4WCo5Yui4kthXOi F+ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=02rFDSIKh/IPDE9EyatIvnlvzTIxRhY9NVFOQbWgkaw=; b=iIvOCGBAh1up5ZGPUHH2f1NvmihzuTdeRmcgqJ56PCpvoTUHnPeezvSncV5nt7Fl1f YRDm4ccKSSO/p02HE8Ru1xXTmuUfLanaO+1gOlIpr8rg4W7+F1ZHWdmv5st1nfOUqFB5 U0NI6BX45L7mLuRpGc171XXqxvxHxnP0Lc4w0MR1py+Z0/oslRarUQIz4ifAbDnVs0fU EBP283qtcDYsD4uruBOfTtnwIfLu0Y4f4ls4t5A42OZ81g1N2TlEunojdBtqM5ou4vsM 5e2fYHxvqrm+nNrvAEhs3nPcMxSDb/8617ewIoOdoFXT0EZwV8HsRnx2QhwUmShyp3EL JOow== X-Gm-Message-State: ALKqPwdkpksiYnuHT/iMH6HV0GtJhOwdgxNPc3VQoZfSaRu880VVg9ci y5ys9u3CL5MJUrYgMZCUpxQSjQ== X-Received: by 2002:a62:b509:: with SMTP id y9-v6mr6894596pfe.121.1526225648967; Sun, 13 May 2018 08:34:08 -0700 (PDT) Received: from [172.26.49.109] ([172.26.49.109]) by smtp.gmail.com with ESMTPSA id z131-v6sm12834839pgz.86.2018.05.13.08.34.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 May 2018 08:34:07 -0700 (PDT) Subject: Re: [PATCH v2] KVM: X86: Fix CR3 reserve bits To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Liran Alon References: <1526203487-4967-1-git-send-email-wanpengli@tencent.com> From: Junaid Shahid Organization: Google Message-ID: <29625752-1e02-dcd7-7b26-1d5c8c30a8db@google.com> Date: Sun, 13 May 2018 08:34:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1526203487-4967-1-git-send-email-wanpengli@tencent.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/13/2018 02:24 AM, Wanpeng Li wrote: > From: Wanpeng Li > > MSB of CR3 is a reserved bit if the PCIDE bit is not set in CR4. > It should be checked when PCIDE bit is not set, however commit > 'd1cd3ce900441 ("KVM: MMU: check guest CR3 reserved bits based on > its physical address width")' removes the bit 63 checking > unconditionally. This patch fixes it by checking bit 63 of CR3 > when PCIDE bit is not set in CR4. > > Fixes: d1cd3ce900441 (KVM: MMU: check guest CR3 reserved bits based on its physical address width) > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Junaid Shahid > Cc: Liran Alon > Signed-off-by: Wanpeng Li > --- > v1 -> v2: > * remove CR3_PCID_INVD in rsvd when PCIDE is 1 instead of > removing CR3_PCID_INVD in new_value > > arch/x86/kvm/emulate.c | 4 +++- > arch/x86/kvm/x86.c | 2 +- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index b3705ae..143b7ae 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -4189,7 +4189,9 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt) > maxphyaddr = eax & 0xff; > else > maxphyaddr = 36; > - rsvd = rsvd_bits(maxphyaddr, 62); > + rsvd = rsvd_bits(maxphyaddr, 63); > + if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) > + rsvd &= ~CR3_PCID_INVD; > } > > if (new_val & rsvd) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 87e4805..9a90668 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -863,7 +863,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) > } > > if (is_long_mode(vcpu) && > - (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 62))) > + (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63))) > return 1; > else if (is_pae(vcpu) && is_paging(vcpu) && > !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) > Reviewed-by: Junaid Shahid