Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp646930ybh; Tue, 10 Mar 2020 05:48:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsCj4kZwM27wSmYQLjQhQuMPwKoZu6lyRrL/UEkFvSJPwM2PV4LijQsJv4gHhtGuHzkxFoc X-Received: by 2002:a9d:d0f:: with SMTP id 15mr10259855oti.161.1583844525017; Tue, 10 Mar 2020 05:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583844525; cv=none; d=google.com; s=arc-20160816; b=ZHxGIdOkGdXvWAJ2eh7itntkRSrBH0SI7n+mXib8PPXmzNkJFrxY5e17aJ0V2oNWOu BMQRsqxVTc0dCQbGE0OUPUq+gIm4ixW1pPrCYdURfsrumR4jFQSLBlQzlZ9sPqakeVcf JgxCEoAna4Fj2FP+mBHqf4+4h4bYyLsjnS63/FHw8t6UbwRJcN4NdpYTAPhCUqzyL7sL 5yyFEkA9wJDxFXIUVVbTfbNzULc8US5G4Jcv2qKAEvKI61zq+7ES7GPsztZn/7GHxJF5 dmDZrZ3Vo4+OIaIY45vGca82PPp3VzeMoNxFLU5ejbGAzK19QAmNxDHy27WrPcRlE2O+ h1ow== 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=h3KpEMW+NbuGN5785eR/Ki9CVCFx1B+jdcReqHyKmA0=; b=nSHUCQ3WNBRNxD7IS+4JvpDpB+hxtJNDv5ZIJ0n5uM81faHfpU0wdKxe1p259S1lV7 48HhvaNXmCPEZPDMD/It+gI8qG7vipCQwmNU2N15xnVbxMxemy40BFZwN+xA4IEE0lEC /pkFEjUYdRiJ1GYqiiQgnKsLnDJch0G4m+ATKe8z3MX9hI1ORzvpPsOEIM0O/lBema9z 0uuBiyXJITwo5eV5OqpXS243++ZSKPwSWFqZV16wLuGF20M4FBkluktx78T4fzGUEm54 /v2TGkv3x4Nxe/f6uMZQxr0namjq6/Wnr9uHRYdcds2+SCePDzCQ6KDw+rStPynEKgMr qWeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fZeMXetD; 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 l11si2011203oib.32.2020.03.10.05.48.32; Tue, 10 Mar 2020 05:48:45 -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=fZeMXetD; 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 S1727097AbgCJMrp (ORCPT + 99 others); Tue, 10 Mar 2020 08:47:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:51462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727590AbgCJMri (ORCPT ); Tue, 10 Mar 2020 08:47:38 -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 CBA0524696; Tue, 10 Mar 2020 12:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844458; bh=pJimwfwzubgUYkW98CcnwR1xUdPLJwn+qDLHOQG1VGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZeMXetDXvJ4nf0Ix1wra7u8pFnp/uIt3r4a9aVsZtZP5Z2a+jYO6N2sfP0EMN0pU Bt+JKQ2cdg80U+wAblqKxgUWAwcK745lLQ7GnF/8tjeywmFcdtx7EYX+3a0iMrdMFz npCl1GRjo+Srmtg53cuDA0R0/NA0UIjrPauT7BrY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jacob Keller , Sean Christopherson , Borislav Petkov , Dave Hansen Subject: [PATCH 4.9 74/88] x86/pkeys: Manually set X86_FEATURE_OSPKE to preserve existing changes Date: Tue, 10 Mar 2020 13:39:22 +0100 Message-Id: <20200310123623.723656199@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123606.543939933@linuxfoundation.org> References: <20200310123606.543939933@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 735a6dd02222d8d070c7bb748f25895239ca8c92 upstream. Explicitly set X86_FEATURE_OSPKE via set_cpu_cap() instead of calling get_cpu_cap() to pull the feature bit from CPUID after enabling CR4.PKE. Invoking get_cpu_cap() effectively wipes out any {set,clear}_cpu_cap() changes that were made between this_cpu->c_init() and setup_pku(), as all non-synthetic feature words are reinitialized from the CPU's CPUID values. Blasting away capability updates manifests most visibility when running on a VMX capable CPU, but with VMX disabled by BIOS. To indicate that VMX is disabled, init_ia32_feat_ctl() clears X86_FEATURE_VMX, using clear_cpu_cap() instead of setup_clear_cpu_cap() so that KVM can report which CPU is misconfigured (KVM needs to probe every CPU anyways). Restoring X86_FEATURE_VMX from CPUID causes KVM to think VMX is enabled, ultimately leading to an unexpected #GP when KVM attempts to do VMXON. Arguably, init_ia32_feat_ctl() should use setup_clear_cpu_cap() and let KVM figure out a different way to report the misconfigured CPU, but VMX is not the only feature bit that is affected, i.e. there is precedent that tweaking feature bits via {set,clear}_cpu_cap() after ->c_init() is expected to work. Most notably, x86_init_rdrand()'s clearing of X86_FEATURE_RDRAND when RDRAND malfunctions is also overwritten. Fixes: 0697694564c8 ("x86/mm/pkeys: Actually enable Memory Protection Keys in the CPU") Reported-by: Jacob Keller Signed-off-by: Sean Christopherson Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Tested-by: Jacob Keller Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200226231615.13664-1-sean.j.christopherson@intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -388,7 +388,7 @@ static __always_inline void setup_pku(st * cpuid bit to be set. We need to ensure that we * update that bit in this CPU's "cpu_info". */ - get_cpu_cap(c); + set_cpu_cap(c, X86_FEATURE_OSPKE); } #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS