Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3999649pxk; Tue, 29 Sep 2020 11:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTsVS0BnoOyG+VVEfcNlD+JruS6BbkqlNtGCD9jeeGqRivVOqoDuRO8aluJe7Xf97EV1Qk X-Received: by 2002:aa7:d959:: with SMTP id l25mr4576499eds.383.1601403987314; Tue, 29 Sep 2020 11:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601403987; cv=none; d=google.com; s=arc-20160816; b=PAOi8tplwu9SEKaBa7vpnEb8Pq3bCJOx4VsDhplewveZrJ9NspaOIAOe6ndmNCF51W fgyCEylQisu6MJYWqsw7I/9LO+6MdbtR51geofiO10sCrORDZKFXzTPoUM7ccB9qSOIU JkS0bxleIA28Adqh6YaA5TWR7dih5H1u76elvQEivXNpUAyMeTMjPOtHmtDWFbESNL6a 3as9dQzNAFG6y5XARt2KM4KRzaBD0UqhXN8jJyetUq/YfeboD27F2jZ76f5ANxQsgTLw H4cwB9gSmULQcbBgi3B1lC8zD/hbQ5l7gU1YrUfiMdIavnSBOe0nunVIQvSQdkrXhwBA opwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fzOf2ZTdQx7hKMmV0m1j7NYX5yJpXAzf2MggKz0ecNE=; b=RZ9gX8//j1Pw3nlcrsIHKShJ9jxozXL8D+MGUV2sE0sZs1PJd5WW7JgSyRkTpjL4hG 1vpyg7bTDyHlQfJs+YMz1pzZDurp/BCLXwxVpcIHC/7ZxJffZgoXf0klaYoFnr9kXbsf TLzsN9oXALi55j0BdzgP9D1VH/2UvRr3efR7OZzcdOYlNIJ/ruEgWChARmkJfSGPVfO4 L4Trq2YMG0M48czz8tfDAfGnJ0YVPf7h0ZAlYU3a7Knbi6BDGVsBcbh00Pg7q9lffZ8a 3lpPJmoIvYwzMadU7Dz8+4vRD9T0jP5gf0SjfxHHsDJvi0STQhHCWc1hAyRPTcRFXEQM ODTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bOUY3n/p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si3343110ejd.289.2020.09.29.11.26.04; Tue, 29 Sep 2020 11:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bOUY3n/p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728914AbgI2MTr (ORCPT + 99 others); Tue, 29 Sep 2020 08:19:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:49134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729903AbgI2Lfs (ORCPT ); Tue, 29 Sep 2020 07:35:48 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 86B7F23A9A; Tue, 29 Sep 2020 11:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379046; bh=+WEjsZAfxXc7dZ+kCapToSzhy5JDph/1fcjsmdCCZBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOUY3n/pR5Llczw1uD+3J6Q3fv+dYvxjoMBPKKinD2p7xpVqdDpijQDzlN6q03RIv I/JKS2nZVLOl3nAnqedMH3+JQWX4lZGX88k6QR1BYNXwO7LxRB6T/4pdMT3tDUR41O WmQsXHpOfg74hso9xquCfLdJyytAefVTG/2Ty5Us= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Mattson , Peter Shier , Oliver Upton , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.19 234/245] KVM: x86: Reset MMU context if guest toggles CR4.SMAP or CR4.PKE Date: Tue, 29 Sep 2020 13:01:25 +0200 Message-Id: <20200929105958.378273091@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105946.978650816@linuxfoundation.org> References: <20200929105946.978650816@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson [ Upstream commit 8d214c481611b29458a57913bd786f0ac06f0605 ] Reset the MMU context during kvm_set_cr4() if SMAP or PKE is toggled. Recent commits to (correctly) not reload PDPTRs when SMAP/PKE are toggled inadvertantly skipped the MMU context reset due to the mask of bits that triggers PDPTR loads also being used to trigger MMU context resets. Fixes: 427890aff855 ("kvm: x86: Toggling CR4.SMAP does not load PDPTEs in PAE mode") Fixes: cb957adb4ea4 ("kvm: x86: Toggling CR4.PKE does not load PDPTEs in PAE mode") Cc: Jim Mattson Cc: Peter Shier Cc: Oliver Upton Signed-off-by: Sean Christopherson Message-Id: <20200923215352.17756-1-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 620ed1fa35119..dd182228be714 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -858,6 +858,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) unsigned long old_cr4 = kvm_read_cr4(vcpu); unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_SMEP; + unsigned long mmu_role_bits = pdptr_bits | X86_CR4_SMAP | X86_CR4_PKE; if (kvm_valid_cr4(vcpu, cr4)) return 1; @@ -885,7 +886,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) if (kvm_x86_ops->set_cr4(vcpu, cr4)) return 1; - if (((cr4 ^ old_cr4) & pdptr_bits) || + if (((cr4 ^ old_cr4) & mmu_role_bits) || (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE))) kvm_mmu_reset_context(vcpu); -- 2.25.1