Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp566730imd; Sat, 3 Nov 2018 06:06:27 -0700 (PDT) X-Google-Smtp-Source: AJdET5cdgvDscBieLFTj7O60WdemkNycPWq5y/BQGwrVT8P6semgvAdbwdW+vrU34WvlCv+rnmgn X-Received: by 2002:a62:1e83:: with SMTP id e125-v6mr15188573pfe.231.1541250387129; Sat, 03 Nov 2018 06:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541250387; cv=none; d=google.com; s=arc-20160816; b=M+jcIq7xTMfUzuJVyPESI+/t4EmG+ElQiRcuCDkGZ/kKcQK+lNT5apkOPOZue7JDJj cfsuWv1Tw5kz78gmsZYC8Ogx+NuGaWRXc8vgg0RKZutlaYFRi9+IqC37crDGP4+wH1hg Rd4h+FVEdl7KS+heG3NXfZzppehtN4ige+8fNr9wcIkCjcar1vcYdKx4+4gMgmuCYJ80 boqqvBE/7p9AuwtFSOPDFMpA0qmcmY+PEYLMtT139LAtqXjwfY/nQGVflGextccGCgvi zzBhw4m1T/sh9cIej9gJRUuQhcC0ZhQOI5qvWqBQOh76bcA74y4ZIfAu6cwAI8WxEGHb INbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=aB4G3w4rpmdu6ojkMiW7GyduUFi8xbFWz6k4BN3jvjQ=; b=Onrt+jJEzjkcBgNEspztAr4ENn8K6QCXlLgfRvNCIKV0Rjak5HiHNwlRBljgRr+RJT fc5IoNNCOTN/+i3P8Ez4ALZddze7BxM99X1gULMKec2inU81CK/VBWaeD6FO9sKyX8eZ IQBe7zgXbyHDHJN7yXQZiEaT38EOyuZlAitJbywB9buyJ9vNO2fzg8oizRlTZsul6lWh eMsEEh9S2NQbAmf+T46x91TgVq8jciUuwdQliAOUaZ9C3lcWEiGbFYQ5JHv8sUKG5Afm LWR+37MKvmt21oEL2ah6aPU3RW2MK/5Qd84sQG9s0O+imYEYyIKzBwNnAEi9GyrzIuTP G/ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nhR9GdnF; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z66-v6si2865420pfb.104.2018.11.03.06.06.11; Sat, 03 Nov 2018 06:06:27 -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=@gmail.com header.s=20161025 header.b=nhR9GdnF; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728593AbeKCWRI (ORCPT + 99 others); Sat, 3 Nov 2018 18:17:08 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:43366 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728441AbeKCWRI (ORCPT ); Sat, 3 Nov 2018 18:17:08 -0400 Received: by mail-qk1-f196.google.com with SMTP id r71so7468122qkr.10; Sat, 03 Nov 2018 06:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aB4G3w4rpmdu6ojkMiW7GyduUFi8xbFWz6k4BN3jvjQ=; b=nhR9GdnF/UdVgznjZyCToBxldtIL8n7A9Y6o0KZ9KKiS6eVqbfSnTUUGpVE3wHar94 u/fwrxNPl6nTk/0FpADSp8LcYtvfD/hrp2jra85Uh19hiYsJNZk7A7emhT6OHb93IV9I vpDf7iuFwPUUFj2aWjcLQsTAidZfvi34StCkIpzQ+QqR2LlLG2KBM0ZWcya4MRIjXR0t CfovdKj9isD3FYYxzc9F3AsY4x1Z1VdpYToiuUCA/BTCP6WwYPixvNfpGYEiMkstGTq2 oCUsKyrTP/FggPDlsAh1Hj9S57TkQ2yr4lFgioQY/SE7QizMvNPyGDakxXYEHHU7VYHr GJfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aB4G3w4rpmdu6ojkMiW7GyduUFi8xbFWz6k4BN3jvjQ=; b=rfSmnsi9eQ7It4DikKGR756vf6PjZ1/Qjdre4ZFHRVE6VvJX/INo2btnLgVSEVNQB4 d5eEKuv+o6jltXG13BW+9HonMycEr85+4ZukDCKFfXZQfviU9rIZnh1R6aeoDMEM9WVq Du3MPK07Cj/Pa763DHMf4L2I+oW1N9+OBWGP0HJY1OtmYbqYuQqo74JERPnIM0/lYMFr 6x52eglhuHJT+OCHYJN121UWsfVQUkglKHfgt9ZEAlVrHADU+MYge+uZCelh3kT18+q0 vJhSjkeg72vPDrnFYz252RXr1O4zaA5gOaO0HmzblDTrdV1dZuHvJiiJQIKiLSLGBPgO yqTw== X-Gm-Message-State: AGRZ1gKwfXBP8ASFgs/iPwWSX4SKluhvH6CiSJBX1ePthkmkqcRO8lwq vBtXOVQPH5nRG+uHqh0OZNE8HVTu0tt/kb6Tp08= X-Received: by 2002:a37:7983:: with SMTP id u125-v6mr13236258qkc.219.1541250350399; Sat, 03 Nov 2018 06:05:50 -0700 (PDT) MIME-Version: 1.0 References: <20181102231320.29164-1-jarkko.sakkinen@linux.intel.com> <20181102231320.29164-6-jarkko.sakkinen@linux.intel.com> In-Reply-To: <20181102231320.29164-6-jarkko.sakkinen@linux.intel.com> From: Andy Shevchenko Date: Sat, 3 Nov 2018 15:05:39 +0200 Message-ID: Subject: Re: [PATCH v15 05/23] x86/cpu/intel: Detect SGX support and update caps appropriately To: Jarkko Sakkinen Cc: "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Platform Driver , linux-sgx@vger.kernel.org, Dave Hansen , sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, mark.shanahan@intel.com, Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Konrad Rzeszutek Wilk , David Woodhouse , davidwang@zhaoxin.com, "Kirill A. Shutemov" , "Levin, Alexander (Sasha Levin)" , qianyue.zj@alibaba-inc.com, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 3, 2018 at 1:16 AM Jarkko Sakkinen wrote: > > From: Sean Christopherson > > Similar to other large Intel features such as VMX and TXT, SGX must be > explicitly enabled in IA32_FEATURE_CONTROL MSR to be truly usable. > Clear all SGX related capabilities if SGX is not fully enabled in > IA32_FEATURE_CONTROL or if the SGX1 instruction set isn't supported > (impossible on bare metal, theoretically possible in a VM if the VMM > is doing something weird). > > Signed-off-by: Sean Christopherson > --- > arch/x86/kernel/cpu/intel.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c > index fc3c07fe7df5..9bf8fe2c04ac 100644 > --- a/arch/x86/kernel/cpu/intel.c > +++ b/arch/x86/kernel/cpu/intel.c > @@ -596,6 +596,30 @@ static void detect_tme(struct cpuinfo_x86 *c) > c->x86_phys_bits -= keyid_bits; > } > > +static void detect_sgx(struct cpuinfo_x86 *c) > +{ > + bool unsupported = false; > + unsigned long long fc; > + > + rdmsrl(MSR_IA32_FEATURE_CONTROL, fc); > + if (!(fc & FEATURE_CONTROL_LOCKED)) { > + pr_err_once("sgx: IA32_FEATURE_CONTROL MSR is not locked\n"); > + unsupported = true; > + } else if (!(fc & FEATURE_CONTROL_SGX_ENABLE)) { > + pr_err_once("sgx: not enabled in IA32_FEATURE_CONTROL MSR\n"); > + unsupported = true; > + } else if (!cpu_has(c, X86_FEATURE_SGX1)) { > + pr_err_once("sgx: SGX1 instruction set not supported\n"); > + unsupported = true; > + } If you do } else { /* Supported */ return; } here, you may get rid of temporary variable. (Up to you) > + > + if (unsupported) { > + setup_clear_cpu_cap(X86_FEATURE_SGX); > + setup_clear_cpu_cap(X86_FEATURE_SGX1); > + setup_clear_cpu_cap(X86_FEATURE_SGX2); > + } > +} > + > static void init_intel_energy_perf(struct cpuinfo_x86 *c) > { > u64 epb; > @@ -763,6 +787,9 @@ static void init_intel(struct cpuinfo_x86 *c) > if (cpu_has(c, X86_FEATURE_TME)) > detect_tme(c); > > + if (cpu_has(c, X86_FEATURE_SGX)) > + detect_sgx(c); > + > init_intel_energy_perf(c); > > init_intel_misc_features(c); > -- > 2.19.1 > -- With Best Regards, Andy Shevchenko