From patchwork Thu Jan 12 14:33:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9513335 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 35AA5601E5 for ; Thu, 12 Jan 2017 14:34:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26025286C3 for ; Thu, 12 Jan 2017 14:34:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AD5C286DC; Thu, 12 Jan 2017 14:34:07 +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 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 76BB6286C3 for ; Thu, 12 Jan 2017 14:33:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 39B1F81A64 for ; Thu, 12 Jan 2017 06:33:26 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 2412B81A64 for ; Thu, 12 Jan 2017 06:33:25 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 12 Jan 2017 06:33:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,349,1477983600"; d="scan'208"; a="1111613722" Received: from tkoyox-mobl.gar.corp.intel.com (HELO localhost) ([10.252.35.215]) by fmsmga002.fm.intel.com with ESMTP; 12 Jan 2017 06:33:22 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Thu, 12 Jan 2017 16:33:16 +0200 Message-Id: <20170112143316.15094-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 Subject: [intel-sgx-kernel-dev] [PATCH] intel_sgx: use VM_DONTCOPY X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.21 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 In order to get stable and well defined semantics use VM_DONTCOPY instead of custom hacks that eventually break in a way or another. Signed-off-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx_main.c | 7 ++----- drivers/platform/x86/intel_sgx_vma.c | 27 +-------------------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_main.c b/drivers/platform/x86/intel_sgx_main.c index 93dd708..b5e414a 100644 --- a/drivers/platform/x86/intel_sgx_main.c +++ b/drivers/platform/x86/intel_sgx_main.c @@ -103,11 +103,8 @@ long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) static int sgx_mmap(struct file *file, struct vm_area_struct *vma) { vma->vm_ops = &sgx_vm_ops; -#if !defined(VM_RESERVED) - vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO; -#else - vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_RESERVED | VM_IO; -#endif + vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO | + VM_DONTCOPY; return 0; } diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index e670405..cba50c2 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -71,42 +71,17 @@ static void sgx_vma_open(struct vm_area_struct *vma) { struct sgx_encl *encl = vma->vm_private_data; - - /* When forking for the second time vm_private_data is already set to - * NULL. - */ - if (!encl) { - zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); - return; - } - - /* Invalidate enclave when the process has been forked. */ - mutex_lock(&encl->lock); - if (encl->mm != vma->vm_mm) { - sgx_invalidate(encl); - vma->vm_private_data = NULL; - } - mutex_unlock(&encl->lock); - - if (vma->vm_private_data) - kref_get(&encl->refcount); + kref_get(&encl->refcount); } static void sgx_vma_close(struct vm_area_struct *vma) { struct sgx_encl *encl = vma->vm_private_data; - /* When forking for the second time vm_private_data is already set to - * NULL. - */ - if (!encl) - return; - mutex_lock(&encl->lock); zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start); encl->flags |= SGX_ENCL_DEAD; mutex_unlock(&encl->lock); - kref_put(&encl->refcount, sgx_encl_release); }