Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp72283ybp; Thu, 3 Oct 2019 10:19:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYgwvc5MYoTJAx6Twuiux8M6HFYau0UWqc4YlJWhSwmfD/ARSDEabztgEH3Fo7CavFA8pB X-Received: by 2002:a17:906:4a81:: with SMTP id x1mr1063613eju.320.1570123186034; Thu, 03 Oct 2019 10:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123186; cv=none; d=google.com; s=arc-20160816; b=yYM/5RnMghvdBLiiuuJA+lnz5WJy7yiHZ+ugV9MAbr3cOzRJnF/DRm7DqSxFVfd3M0 lTp/rnf8m+hMNf17mk5EThJSTFQ11OWSZQSGPOKuF1aw4sllUBdM51/XhpTII5kCG2XM x2WbmOaHWk/0VMmF0YdcyAMeQ1Kl2BChPt5CsOl7uJ0/u9SpriSRTkgNRH/TBWUW9yw+ 9dnpwLiW/lH8LKyzG6G+pi/F3bSWpWy1OLlJPLTmT0WVbDXw6MHxigQgFD/Z3S51liiS Uy9NxJv0revzyS8XR0porJ4yB0IqoW/PQD68c/5d0Mt1a/zmiez6+xJLWdYxp9Uy6sy/ iFOg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zcXDe5unkZ466I5kNlTQm5n3T18uS9C6QBf83JWNFa4=; b=HM6ZlirG7QHF2YH6EWrAOiQGkaa3R/Fwnv8IW/4tTei2JULYdLro/sJJejw9TYznsg 3mnhQEbiUWdKrLaVEQDvsLz4UVWTK5ICXSz7I9Z2Md+drtTNQ5teLFADORYXb4T+aqOy 0sT/FTd6Ty0TBb69lLbhdfS/wVxLbUjeSoJA4qZId5nL6L/f8ES2Yi4reuJX/h5p7q6I FZnmfAGmzJL6YHTS5gCThwZvULq40FjD/6tcFhiA4e1/3gvLpArYRqBja16SArL/DTGW ent5osoCODCgNVM647nLQ8V+jUJoRv8xslEFxGafbBXuZE+jbAeaVNqL5yVRmr1AAHwS vwfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=srSud1pA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a94si1997426edf.110.2019.10.03.10.19.21; Thu, 03 Oct 2019 10:19:46 -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=@kernel.org header.s=default header.b=srSud1pA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391612AbfJCRRu (ORCPT + 99 others); Thu, 3 Oct 2019 13:17:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389571AbfJCQV4 (ORCPT ); Thu, 3 Oct 2019 12:21:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0219A21A4C; Thu, 3 Oct 2019 16:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119714; bh=SnQEhVM8RTG3LPNrFMAJntGs+Y+Ic60hMP54tSb/Xss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srSud1pA5II9ttftUSdMWVaaVkDKDo3b1A4XHFLJXzcRBVTJgQB9fcGknnOTnQ08U CuWj+pdTnMHgmZ+F48NnfXQ79if/IQ07AZ7FEljE0+bF6ITrFcHd2D+dLBgxAIXjJU 8nNUeyTHuW4jcMgzAEEleNLKNUABNLhcqkJ77vW4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nadav Amit , Doug Reiland , Sean Christopherson , Peter Xu , Paolo Bonzini Subject: [PATCH 4.19 167/211] KVM: x86: Manually calculate reserved bits when loading PDPTRS Date: Thu, 3 Oct 2019 17:53:53 +0200 Message-Id: <20191003154525.870373223@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 16cfacc8085782dab8e365979356ce1ca87fd6cc upstream. Manually generate the PDPTR reserved bit mask when explicitly loading PDPTRs. The reserved bits that are being tracked by the MMU reflect the current paging mode, which is unlikely to be PAE paging in the vast majority of flows that use load_pdptrs(), e.g. CR0 and CR4 emulation, __set_sregs(), etc... This can cause KVM to incorrectly signal a bad PDPTR, or more likely, miss a reserved bit check and subsequently fail a VM-Enter due to a bad VMCS.GUEST_PDPTR. Add a one off helper to generate the reserved bits instead of sharing code across the MMU's calculations and the PDPTR emulation. The PDPTR reserved bits are basically set in stone, and pushing a helper into the MMU's calculation adds unnecessary complexity without improving readability. Oppurtunistically fix/update the comment for load_pdptrs(). Note, the buggy commit also introduced a deliberate functional change, "Also remove bit 5-6 from rsvd_bits_mask per latest SDM.", which was effectively (and correctly) reverted by commit cd9ae5fe47df ("KVM: x86: Fix page-tables reserved bits"). A bit of SDM archaeology shows that the SDM from late 2008 had a bug (likely a copy+paste error) where it listed bits 6:5 as AVL and A for PDPTEs used for 4k entries but reserved for 2mb entries. I.e. the SDM contradicted itself, and bits 6:5 are and always have been reserved. Fixes: 20c466b56168d ("KVM: Use rsvd_bits_mask in load_pdptrs()") Cc: stable@vger.kernel.org Cc: Nadav Amit Reported-by: Doug Reiland Signed-off-by: Sean Christopherson Reviewed-by: Peter Xu Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -581,8 +581,14 @@ static int kvm_read_nested_guest_page(st data, offset, len, access); } +static inline u64 pdptr_rsvd_bits(struct kvm_vcpu *vcpu) +{ + return rsvd_bits(cpuid_maxphyaddr(vcpu), 63) | rsvd_bits(5, 8) | + rsvd_bits(1, 2); +} + /* - * Load the pae pdptrs. Return true is they are all valid. + * Load the pae pdptrs. Return 1 if they are all valid, 0 otherwise. */ int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3) { @@ -601,8 +607,7 @@ int load_pdptrs(struct kvm_vcpu *vcpu, s } for (i = 0; i < ARRAY_SIZE(pdpte); ++i) { if ((pdpte[i] & PT_PRESENT_MASK) && - (pdpte[i] & - vcpu->arch.mmu.guest_rsvd_check.rsvd_bits_mask[0][2])) { + (pdpte[i] & pdptr_rsvd_bits(vcpu))) { ret = 0; goto out; }