Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp394537ybf; Wed, 26 Feb 2020 15:16:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwXYRLMGKDH0hWd36SxJrzSpnqxGyRO3Zaz66ewbvxPtQdmUzp2sSO4ve5DN7ckfbusG4Nt X-Received: by 2002:a9d:23b6:: with SMTP id t51mr974276otb.15.1582758999806; Wed, 26 Feb 2020 15:16:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582758999; cv=none; d=google.com; s=arc-20160816; b=M4zVhJVehZzp2ImZIqp4VXLcwR5kXevYeNSeyoZtxOOIzlxPUFaDvuN7QG5kgXaR81 7N6TIlfWAD9DlNdMF+dLCKP/P9HYZ4JEK31t3yXjUlQILOknXGc46BX9AGxmSZ5po4E3 VhsKyb2dLnZpzxWxYZ40WCiVne32Z58JM5mbfWb5fR+iRQgPdZVBk/IjxLepLZroSHRp uCu0GKDx2v6eF6IgYUV69g6bJc7H5yh3A+X7iggoo1Q0DOHbNSdUwHFZITy9qDPJfaVi 0kPr8ZEqvTtDKeMp0kE2w6uJCFVd+M6ZRfmJpy3rfzLDM9q6fsf989Q5mj8ZBi1UNTXI KhmA== 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 :message-id:date:subject:cc:to:from; bh=1S6NAqbTYdK66eK4kCI9HdFiq2NFJC/4tonMQ2M5v0Y=; b=VoZmVMpc0lr9PcRl6WHQ2upCrWqnrGXY59xixgrKGGky913IC/c3icdnPqbEi6SrQg Dynq2y99cOfHMjtbYyQsDY738Z68KQf6V1KiVffsgMKjNJRn/GgR4/lqbdowLApgXtp4 CflclXdzBLv2krVnEAS8Ara8IvvTfbUKTRgaSHkKNTHV7srlk6O4oVrCBpWzOFfGZ+3m +ra3dd+KShdzFD7nN31mOZPL3HTo202YTZMC/9opj0dZjJG3KAwjUQFkJEHk+zAQwwrP YwYbB1EQNvJDByD2SNPbdZHKceZP0Zbi+vctrDA1y0gqKXstUNJFZuUK4Onmkc+8vAh9 nAhw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14si504710otr.131.2020.02.26.15.16.26; Wed, 26 Feb 2020 15:16:39 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727910AbgBZXQT (ORCPT + 99 others); Wed, 26 Feb 2020 18:16:19 -0500 Received: from mga04.intel.com ([192.55.52.120]:3614 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgBZXQS (ORCPT ); Wed, 26 Feb 2020 18:16:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 15:16:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,489,1574150400"; d="scan'208";a="410797453" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by orsmga005.jf.intel.com with ESMTP; 26 Feb 2020 15:16:18 -0800 From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, Dave Hansen , Jacob Keller Subject: [PATCH] x86/pkeys: Manually set X86_FEATURE_OSPKE to preserve existing changes Date: Wed, 26 Feb 2020 15:16:15 -0800 Message-Id: <20200226231615.13664-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Cc: stable@vger.kernel.org Cc: Dave Hansen Reported-by: Jacob Keller Signed-off-by: Sean Christopherson --- I considered adding a WARN_ON check of cpuid_ecx(7) to ensure OSPKE is set and bail if it's not, but that seemed like useless paranoia. I don't love that using clear_cpu_cap() is a bit fragile, especially where init_ia32_feat_ctl() is concerned, but the existing RDRAND usage, which predates setup_pku(), makes a pretty strong argument that setup_pku() is in the wrong. The other potential issue is late microcode updates, which refreshes the feature bits from CPUID, but at least in that case the kernel will print a warning if something changed. arch/x86/kernel/cpu/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 52c9bfbbdb2a..4cdb123ff66a 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -445,7 +445,7 @@ static __always_inline void setup_pku(struct cpuinfo_x86 *c) * 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 -- 2.24.1