Received: by 10.213.65.68 with SMTP id h4csp329026imn; Tue, 13 Mar 2018 05:52:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELvYL4c4GXani3D2q6LwK/mUMyL9Zoo8MvZjo7IVQelb3sPp1Q3/2N4JwGXR4BGuQ1zhzlnw X-Received: by 2002:a17:902:768b:: with SMTP id m11-v6mr476700pll.185.1520945529505; Tue, 13 Mar 2018 05:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520945529; cv=none; d=google.com; s=arc-20160816; b=HL3UAoq29juCMpFR5BQABG/p85aKIGmmmzd1Fl2yPJtqznTprOh8IPdn2vlo1GVvVB wWC+StZ4xsl680jPb3Jw339jNDNX9F5UPzcGp/l5/fUesAf6f3VA3xuYGp3ySCTZv9Mg fojWsoaThrgKP0MnYsbpOGujtoaWhOVA/WWo9E82wkBP4JjCe/1Rpqcj8YO+jRXGx6/x WRfFy4pk17KQao7kUgjLCS+AQdc1+kehRGH0jMO+BvpCimp7EZhXD9mrzpRNM2tcmnRy RGcZVHXLzWPF0Bii8mM0jOvHhTbu3bG/asVgV1fJ8xF05uckCYFe7UZAPHnvfNR6Erdj cM5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=yf5cfJaSrFC/jhHji4BYQzywJ8mgZMkYhy3Quhnsrck=; b=eG5N/F/h7zbqeMBRAtUr2UdpLvu9sKhi+uYldmceqmjD4RDipvfxYkmi8JyIcKligQ LEjkrb6kRXDrpVupvPc5QPx9fua0Ca5V7xtx5gdKcEmuIkLhC9ljT7Pl5u4WD3+ECmlb nJbTnt0veDgL2OeWQgcBwcegE1Cw2u7dFLa/qvW+Ytze7wnfxQ1FzIBjw5tt6S7Dj4Sy kj7Qt9ky1Gwth/KIPO4rncSrm3OUprlQPQwyMbgclCt1vgx7WyWiJCq8tdYxncgvj7zk duDOsqufZidtU6RMfYDAQqDsu2W6suVeb3H74SxseY/xJdgSYsa83/X0iHvXtIWhIwPQ Zjqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=c0GlssT7; 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 99-v6si90119plc.601.2018.03.13.05.51.55; Tue, 13 Mar 2018 05:52:09 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=c0GlssT7; 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 S932242AbeCMMuX (ORCPT + 99 others); Tue, 13 Mar 2018 08:50:23 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35320 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752252AbeCMMuV (ORCPT ); Tue, 13 Mar 2018 08:50:21 -0400 Received: by mail-wr0-f195.google.com with SMTP id n12so11199994wra.2 for ; Tue, 13 Mar 2018 05:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yf5cfJaSrFC/jhHji4BYQzywJ8mgZMkYhy3Quhnsrck=; b=c0GlssT7vsHgMT6AkWVP66GyzlKGRJ6TsaIqOMfgmKBcJb4C7X3gu456TN6IC8rpTc wvjZq2YqRdsolxhyLhbY38IG2202qLaOBx390sEwN8QuepPUqbogswFgjaNc4egFLyru I+a/FtskTevO5gmp7hsGs31v23gTfMHncIDYD7GS1mQe9B3JE2rVrkvefkHBWhm5Etm3 succNQUOUXhGQqYacvkCy/+5tqhDQ1WNkzAn+iYG1kv5/Z25E3UZtJ+sMsYvYpzQUevG 0CluPR8TdO/TKatzLE+sUkH2VN4RmpNBpGUQuiFRdnAftqLeesuo6S5DW681Vzhoio8a 2niA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yf5cfJaSrFC/jhHji4BYQzywJ8mgZMkYhy3Quhnsrck=; b=HtD0HAXThA0XvCdVHN5PibzeSc7a2+ZevHXSTTA8f04+SrnmICh8IlLD7hsiguD+Ev dJiyejHU06vU4BiaQEpnrlrrevd8wQ5nA+PaCrfFR0bBRl/pGaHdgCGbkYFrpVYrFqJd jTuv8JExFRFyCT51tLHMsmyc0LcKvk8HG+DlRUU5qX45wc5+5c53uLKOIWR0IPZEskNo zR09sx5ZgIKExZgkg95kGEr7Ab0qB+TnjWkOtKquuaP6roXntq+yeIxzVqfLXc964YGw cz6+aQpsIPpWbnI04fxRJaKH84wgvw804sNyILTnAJIJ55d1EQQExsKlMZwhyLFbCccm 72lw== X-Gm-Message-State: AElRT7E8yRZgJLOzCPh4n5TDUmgHQvjhs7BI7IgItvza/wQgHQToiEru mrJFGwDyMRrsQAw3Hit73aQngg== X-Received: by 10.28.107.9 with SMTP id g9mr687292wmc.157.1520945419626; Tue, 13 Mar 2018 05:50:19 -0700 (PDT) Received: from node.shutemov.name (mm-147-73-44-37.mgts.dynamic.pppoe.byfly.by. [37.44.73.147]) by smtp.gmail.com with ESMTPSA id f8sm198698wmc.1.2018.03.13.05.50.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 05:50:18 -0700 (PDT) Received: by node.shutemov.name (Postfix, from userid 1000) id 25BAD648D520; Tue, 13 Mar 2018 15:49:56 +0300 (+03) Date: Tue, 13 Mar 2018 15:49:56 +0300 From: "Kirill A. Shutemov" To: Kai Huang Cc: dave.hansen@intel.com, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, kirill.shutemov@linux.intel.com, thomas.lendacky@amd.com, linux-tip-commits@vger.kernel.org Subject: Re: [tip:x86/mm] x86/tme: Detect if TME and MKTME is activated by BIOS Message-ID: <20180313124956.z426zmsr4xl6zomx@node.shutemov.name> References: <20180305162610.37510-3-kirill.shutemov@linux.intel.com> <1520907122.6421.8.camel@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1520907122.6421.8.camel@linux.intel.com> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 03:12:02PM +1300, Kai Huang wrote: > It seems setup_pku() will call get_cpu_cap to restore c->x86_phys_bits > later? In which case I think you need to change setup_pku as well. Thanks for catching this. I think setup_pku() shouldn't call get_cpu_cap(). Any objections against this: diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 348cf4821240..ce10d8ae4cd6 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -362,6 +362,8 @@ static bool pku_disabled; static __always_inline void setup_pku(struct cpuinfo_x86 *c) { + u32 eax, ebx, ecx, edx; + /* check the boot processor, plus compile options for PKU: */ if (!cpu_feature_enabled(X86_FEATURE_PKU)) return; @@ -377,7 +379,8 @@ 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); + cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); + c->x86_capability[CPUID_7_ECX] = ecx; } #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS > And for the comments here, I think it can be refined. It is true that > VM guest needs to know bits of physical address, but this info is not > used only by VM. I think the reason we need to update is this is simply > the fact. Fair enough. Like this? diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index e8ddc6dcfd53..ac45ba7398d9 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -612,11 +612,8 @@ static void detect_tme(struct cpuinfo_x86 *c) #endif /* - * Exclude KeyID bits from physical address bits. - * - * We have to do this even if we are not going to use KeyID bits - * ourself. VM guests still have to know that these bits are not usable - * for physical address. + * KeyID bits effectively lower number of physical address bits. + * Let's update cpuinfo_x86::x86_phys_bits to reflect the fact. */ c->x86_phys_bits -= keyid_bits; } -- Kirill A. Shutemov