From patchwork Tue Aug 29 17:56:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9927857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DF9F860383 for ; Tue, 29 Aug 2017 17:57:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D542C289E6 for ; Tue, 29 Aug 2017 17:57:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA552289E8; Tue, 29 Aug 2017 17:57:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5052A289ED for ; Tue, 29 Aug 2017 17:57:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AC00321E47D6F; Tue, 29 Aug 2017 10:54:20 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6F12B21E47D70 for ; Tue, 29 Aug 2017 10:54:19 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2017 10:56:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,445,1498546800"; d="scan'208";a="123739750" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.137]) by orsmga004.jf.intel.com with ESMTP; 29 Aug 2017 10:56:59 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Tue, 29 Aug 2017 10:56:36 -0700 Message-Id: <1504029396-3353-3-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504029396-3353-1-git-send-email-sean.j.christopherson@intel.com> References: <1504029396-3353-1-git-send-email-sean.j.christopherson@intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 2/2] intel_sgx: remove option to build as a module X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Project: Intel® Software Guard Extensions for Linux*: https://01.org/intel-software-guard-extensions" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-sgx-kernel-dev-bounces@lists.01.org Sender: "intel-sgx-kernel-dev" X-Virus-Scanned: ClamAV using ClamSMTP Build SGX support directly into the kernel, utilizing syscore_ops instead of dev_pm_ops to hook into the suspend flow. Signed-off-by: Sean Christopherson --- arch/x86/Kconfig | 4 +- arch/x86/kernel/cpu/intel_sgx/Makefile | 13 +++--- arch/x86/kernel/cpu/intel_sgx/sgx_main.c | 74 ++++++++------------------------ 3 files changed, 24 insertions(+), 67 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index fb8c91f..5f4d414 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1788,8 +1788,8 @@ config X86_INTEL_MEMORY_PROTECTION_KEYS If unsure, say y. config INTEL_SGX - tristate "Intel(R) SGX Driver" - default n + prompt "Intel SGX (Secure Guard Extensions)" + def_bool n depends on X86 select MMU_NOTIFIER ---help--- diff --git a/arch/x86/kernel/cpu/intel_sgx/Makefile b/arch/x86/kernel/cpu/intel_sgx/Makefile index b87f4e1..71b85b5 100644 --- a/arch/x86/kernel/cpu/intel_sgx/Makefile +++ b/arch/x86/kernel/cpu/intel_sgx/Makefile @@ -2,11 +2,8 @@ # Intel SGX # -obj-$(CONFIG_INTEL_SGX) += intel_sgx.o - -intel_sgx-$(CONFIG_INTEL_SGX) += \ - sgx_ioctl.o \ - sgx_main.o \ - sgx_page_cache.o \ - sgx_util.o \ - sgx_vma.o \ +obj-y += sgx_ioctl.o \ + sgx_main.o \ + sgx_page_cache.o \ + sgx_util.o \ + sgx_vma.o \ diff --git a/arch/x86/kernel/cpu/intel_sgx/sgx_main.c b/arch/x86/kernel/cpu/intel_sgx/sgx_main.c index 50d9af8..5f411b5 100644 --- a/arch/x86/kernel/cpu/intel_sgx/sgx_main.c +++ b/arch/x86/kernel/cpu/intel_sgx/sgx_main.c @@ -59,22 +59,12 @@ */ #include "sgx.h" -#include #include #include #include -#include -#include #include #include -#include - -#define DRV_DESCRIPTION "Intel SGX Driver" -#define DRV_VERSION "0.10" - -MODULE_DESCRIPTION(DRV_DESCRIPTION); -MODULE_AUTHOR("Jarkko Sakkinen "); -MODULE_VERSION(DRV_VERSION); +#include /* * Global data. @@ -159,7 +149,7 @@ static struct miscdevice sgx_dev = { .mode = 0666, }; -static int sgx_pm_suspend(struct device *dev) +static int sgx_pm_suspend(void) { struct sgx_tgid_ctx *ctx; struct sgx_encl *encl; @@ -175,9 +165,12 @@ static int sgx_pm_suspend(struct device *dev) return 0; } -static SIMPLE_DEV_PM_OPS(sgx_drv_pm, sgx_pm_suspend, NULL); -static int sgx_dev_init(struct device *dev) +static struct syscore_ops sgx_syscore_ops = { + .suspend = sgx_pm_suspend, +}; + +static int __init sgx_dev_init(void) { unsigned int eax, ebx, ecx, edx; unsigned long pa; @@ -186,8 +179,6 @@ static int sgx_dev_init(struct device *dev) int ret; int i; - pr_info("intel_sgx: " DRV_DESCRIPTION " v" DRV_VERSION "\n"); - if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) return -ENODEV; @@ -199,7 +190,7 @@ static int sgx_dev_init(struct device *dev) pa = ((u64)(ebx & 0xfffff) << 32) + (u64)(eax & 0xfffff000); size = ((u64)(edx & 0xfffff) << 32) + (u64)(ecx & 0xfffff000); - dev_info(dev, "EPC bank 0x%lx-0x%lx\n", pa, pa + size); + pr_info("intel_sgx: EPC bank 0x%lx-0x%lx\n", pa, pa + size); sgx_epc_banks[i].pa = pa; sgx_epc_banks[i].size = size; @@ -238,10 +229,11 @@ static int sgx_dev_init(struct device *dev) if (!sgx_add_page_wq) { pr_err("intel_sgx: alloc_workqueue() failed\n"); ret = -ENOMEM; - goto out_iounmap; + goto out_pagecache; } - sgx_dev.parent = dev; + register_syscore_ops(&sgx_syscore_ops); + ret = misc_register(&sgx_dev); if (ret) { pr_err("intel_sgx: misc_register() failed\n"); @@ -250,7 +242,10 @@ static int sgx_dev_init(struct device *dev) return 0; out_workqueue: + unregister_syscore_ops(&sgx_syscore_ops); destroy_workqueue(sgx_add_page_wq); +out_pagecache: + sgx_page_cache_teardown(); out_iounmap: #ifdef CONFIG_X86_64 for (i = 0; i < sgx_nr_epc_banks; i++) @@ -259,7 +254,7 @@ static int sgx_dev_init(struct device *dev) return ret; } -static int sgx_drv_probe(struct platform_device *pdev) +static int __init sgx_init(void) { unsigned int eax, ebx, ecx, edx; int i; @@ -307,42 +302,7 @@ static int sgx_drv_probe(struct platform_device *pdev) #endif sgx_encl_size_max_32 = 1ULL << (edx & 0xFF); - return sgx_dev_init(&pdev->dev); + return sgx_dev_init(); } -static int sgx_drv_remove(struct platform_device *pdev) -{ - int i; - - misc_deregister(&sgx_dev); - destroy_workqueue(sgx_add_page_wq); -#ifdef CONFIG_X86_64 - for (i = 0; i < sgx_nr_epc_banks; i++) - iounmap((void *)sgx_epc_banks[i].va); -#endif - sgx_page_cache_teardown(); - - return 0; -} - -#ifdef CONFIG_ACPI -static struct acpi_device_id sgx_device_ids[] = { - {"INT0E0C", 0}, - {"", 0}, -}; -MODULE_DEVICE_TABLE(acpi, sgx_device_ids); -#endif - -static struct platform_driver sgx_drv = { - .probe = sgx_drv_probe, - .remove = sgx_drv_remove, - .driver = { - .name = "intel_sgx", - .pm = &sgx_drv_pm, - .acpi_match_table = ACPI_PTR(sgx_device_ids), - }, -}; - -module_platform_driver(sgx_drv); - -MODULE_LICENSE("Dual BSD/GPL"); +device_initcall(sgx_init);