Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp444682ybf; Wed, 26 Feb 2020 16:16:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwTPqQB8OH27Ft/ACYSeIlCPDbSIl+BUw6yjiibfEJ6gEFz52QMIbCLWabYM8TUuaSZa1Uq X-Received: by 2002:aca:2b04:: with SMTP id i4mr1316606oik.21.1582762597050; Wed, 26 Feb 2020 16:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582762597; cv=none; d=google.com; s=arc-20160816; b=Q6DemfTs9CyOtC7HaXxTERZTlLZN142guavNbtEe1AqCnTh/+KOS5ZFxzmMawC9PDD GFh5lVmk5dWo+h0EmNdL3nUXWRxp3fK1CsZUXkEFA/tvfEg1bkefMGRrtqPs6V/T/B1o 4bB0VZkp17pnbQe/DkyiFDJGuNuCBETdk4QDyE9legdAEheRyTtH5DUiYsxZkqNRtcDK lxKnq8rxCT2xREsYHQB5TK8afVTyk3C33w32Lh1KR9evsUnDigsi0n+DqrUm2nHDaLIM F3A7ZigJvaPX1KMn8eHimzLUmwoQVzhVY2Dxjh1WFREYXQ1BzoDgLa/7VB5XbuBZETTN RppA== 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; bh=Oz6f6baO86AzHut3SsFziC2AKO9S2gmslCXejzcRkXQ=; b=qn2nuQlRRIsbH4EIJrLxxd2BKtay5X58h+1e+9i6PGjyJmM/gjVLhX3mDVT1oy8yiD z5AnzvvMeQeBEvFQUMhxEpqqC6QFXqZDs96POu5deG5VdIGRPalwIWrS7uZxW0o8NLgt 8w27Yu7hT+2WkgHXvV//LjVic2D2LJD64f9XhmKm9bXfG4ozPH2BHYJDi4d8ppj+6aax xux4/5Rm17ev+nGkHPNToXP1pc3GKNUTeWn25CGnDxejNZL7UqNUMgTNJAFGEjaUQzLj m0wEIIUweR02UQ+pJKMv2bV01PlyO2TtDfBjzkBiA0/iL3979XYO3DUD58x1dfAMHvzh ZXFQ== 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 t28si625602otr.16.2020.02.26.16.16.24; Wed, 26 Feb 2020 16:16:37 -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 S1728062AbgB0AQP (ORCPT + 99 others); Wed, 26 Feb 2020 19:16:15 -0500 Received: from mga06.intel.com ([134.134.136.31]:18213 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728012AbgB0AQO (ORCPT ); Wed, 26 Feb 2020 19:16:14 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 16:16:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,490,1574150400"; d="scan'208";a="350518753" Received: from jekeller-mobl1.amr.corp.intel.com (HELO [134.134.177.84]) ([134.134.177.84]) by fmsmga001.fm.intel.com with ESMTP; 26 Feb 2020 16:16:13 -0800 Subject: Re: [PATCH] x86/pkeys: Manually set X86_FEATURE_OSPKE to preserve existing changes To: Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, Dave Hansen References: <20200226231615.13664-1-sean.j.christopherson@intel.com> From: Jacob Keller Organization: Intel Corporation Message-ID: Date: Wed, 26 Feb 2020 16:16:13 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200226231615.13664-1-sean.j.christopherson@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/26/2020 3:16 PM, Sean Christopherson wrote: > 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 tested this and it resolves my report! Thanks for a timely fix. I agree with the analysis. Perhaps it would make sense in the long term to find a solution where get_cpu_cap can remember what was cleared for each CPU and restore those? It already does this using the global variables... Thanks, Jake