Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6825772imm; Tue, 28 Aug 2018 01:29:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYhhIdMIDkd8EdE5x75cgnjOipUMVULI+CWZcupBcYoLCGsM4/f8DZMRW/r9RObXSCpVo07 X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr497781plq.337.1535444986708; Tue, 28 Aug 2018 01:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535444986; cv=none; d=google.com; s=arc-20160816; b=DFsksUDFoTuL8xGZrQKKU1iucmR3U2AWJjSjPT9cqogcXOVzSntoUo6yll1+TpNyx4 iVm8rDQfJUv3p+zZXv5J0IpbseJnVXe8te8uRow3eXTWIK50iMqJqDWtTjutTMSxL9ka LP3bLOFSE6dtUwvziVF27AEqJF891g9xQbX8Vsvps8yUaLODWGMTMtMbnRpiJPYxraxG 3brjVHtrfY/3H8WXCFCKPazsF4ZDIHSr4/tRnsDrmIm3AEMSONMIrNcyW7EnW8vWZP2Y lCXW/mW356GBli/1tQ9RxveAzGQZwPVobc96kmc93M6Zzn4d7PyhXeO7DIihzW8wbSo7 LHRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=6AxecISW1aNILkDH1F1z82zEkrlYtR57f7VRGjAQ6pU=; b=jBkhRprnwSQEmiuum4oVRKpevQQ0ngmD6MWxhksp9fT/O8mHykNxGq4uXmbcE4wnOo 0WiJ7FujlWNgRzYd2Ops7D/wprE7sQeVUWu4bNbV1LQ7DumW3livTPTJPJboTvPINb+N xpKjP3lw0n7MVxKPSOjiJxQ58UnR39VH7itaZFTB9i5Iy3p0rQtvRRyo0Nm8PsbBYZws TQpY1yYy7FJkWnmmvmf4TeWkVUWpLUK5w+C1bqN8Pctkpxg7tIn4tuIsz9RJG3KKgCo/ /0xZc5uiL3dWvFL8le9kUhwyzeyxOuC+zJh68APHEdqTYAyY/MfGxKVmsGd1pftiBD0Z yPBQ== 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 v11-v6si417415pfk.165.2018.08.28.01.29.28; Tue, 28 Aug 2018 01:29:46 -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; 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 S1727135AbeH1MSu (ORCPT + 99 others); Tue, 28 Aug 2018 08:18:50 -0400 Received: from mga04.intel.com ([192.55.52.120]:35159 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbeH1MSu (ORCPT ); Tue, 28 Aug 2018 08:18:50 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2018 01:28:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,298,1531810800"; d="scan'208";a="76138005" Received: from jsakkine-mobl1.fi.intel.com (HELO localhost) ([10.237.66.39]) by FMSMGA003.fm.intel.com with ESMTP; 28 Aug 2018 01:28:11 -0700 Date: Tue, 28 Aug 2018 11:28:11 +0300 From: Jarkko Sakkinen To: Dave Hansen Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, linux-sgx@vger.kernel.org, Suresh Siddha , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Serge Ayoun , "Rafael J. Wysocki" , Borislav Petkov , Reinette Chatre , Andi Kleen , Greg Kroah-Hartman , "Kirill A. Shutemov" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v13 06/13] x86/sgx: Detect Intel SGX Message-ID: <20180828082811.GG15508@linux.intel.com> References: <20180827185507.17087-1-jarkko.sakkinen@linux.intel.com> <20180827185507.17087-7-jarkko.sakkinen@linux.intel.com> <50c199b6-e8eb-9120-0d2a-5e60ac0139b4@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50c199b6-e8eb-9120-0d2a-5e60ac0139b4@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 27, 2018 at 12:53:59PM -0700, Dave Hansen wrote: > > +config INTEL_SGX_CORE > > + prompt "Intel SGX core functionality" > > + def_bool n > > + depends on X86_64 && CPU_SUP_INTEL > > + help > > + Intel Software Guard eXtensions (SGX) is a set of CPU instructions > > + that allows ring 3 applications to create enclaves, private regions > > + of memory that are protected, by hardware, from unauthorized access > > + and/or modification. > > This is a bit comma-crazy. Also, considering some of our recent CVE > fun, I'd probably not claim hardware protection. :) Agreed :) > Maybe: > > Intel Software Guard eXtensions (SGX) CPU feature that allows > ring 3 applications to create enclaves: private regions > of memory that are architecturally protected from unauthorized > access and/or modification. Yeah, looks way more better structured. > > + This option enables kernel recognition of SGX, high-level management > > + of the Enclave Page Cache (EPC), tracking and writing of SGX Launch > > + Enclave Hash MSRs, and allows for virtualization of SGX via KVM. By > > + iteslf, this option does not provide SGX support to userspace. > > itself > > > > diff --git a/arch/x86/include/asm/sgx_pr.h b/arch/x86/include/asm/sgx_pr.h > > new file mode 100644 > > index 000000000000..c68578127620 > > --- /dev/null > > +++ b/arch/x86/include/asm/sgx_pr.h > > @@ -0,0 +1,13 @@ > > +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) > > +// Copyright(c) 2016-17 Intel Corporation. > > + > > +#ifndef _ASM_X86_SGX_PR_H > > +#define _ASM_X86_SGX_PR_H > > + > > +#include > > +#include > > + > > +#undef pr_fmt > > +#define pr_fmt(fmt) "sgx: " fmt > > + > > +#endif /* _ASM_X86_SGX_PR_H */ > > I don't think this belongs in a generic header. Generally, we do the > pr_fmt stuff in .c files, not in headers. If someone includes this > header directly or indirectly, they'll get a big surprise. > > If you *must* have this in a .h file, put it in > arch/x86/kernel/cpu/intel_sgx.h or something and #include "intel_sgx.h" > in all the .c files where you want this. I think for intel_sgx.c (the core part) we could just manually add the "sgx:" prefix because there are only few log messages. I would move the definition to drivers/platform/x86/intel_sgx/sgx.h because the prefix makes sense for all .c files there AFAIK. > > +static __init int sgx_init(void) > > +{ > > + unsigned long fc; > > + > > + if (!boot_cpu_has(X86_FEATURE_SGX)) > > + return false; > > + > > + if (!boot_cpu_has(X86_FEATURE_SGX1)) > > + return false; > > + > > + rdmsrl(MSR_IA32_FEATURE_CONTROL, fc); > > + if (!(fc & FEATURE_CONTROL_LOCKED)) { > > + pr_info("IA32_FEATURE_CONTROL MSR is not locked\n"); > > + return false; > > + } > > This is a rather crummy error message. Doesn't this keep sgx from > initializing? Would something like this be more informative? > > pr_info("failed init: IA32_FEATURE_CONTROL MSR not locked\n"); What about: pr_err(FW_BUG "IA32_FEATURE_CONTROL MSR not locked\n"); > > + if (!(fc & FEATURE_CONTROL_SGX_ENABLE)) { > > + pr_info("disabled by the firmware\n"); > > + return false; > > + } > > + > > + if (!(fc & FEATURE_CONTROL_SGX_LE_WR)) > > + pr_info("IA32_SGXLEPUBKEYHASHn MSRs are not writable\n"); > > How about something that might help an end user? Perhaps: > > pr_warn("launch configuration not available\n"); I think this message is a false flag here in the first place as KVM does not require writable MSRs. It really should be moved to the driver. > > + sgx_enabled = true; > > + sgx_lc_enabled = !!(fc & FEATURE_CONTROL_SGX_LE_WR); > > + return 0; > > +} > > + > > +arch_initcall(sgx_init); > > > > /Jarkko