From patchwork Tue Mar 15 01:02:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Cathy" X-Patchwork-Id: 12780912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F71EC433EF for ; Tue, 15 Mar 2022 01:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344088AbiCOBDv (ORCPT ); Mon, 14 Mar 2022 21:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344089AbiCOBDs (ORCPT ); Mon, 14 Mar 2022 21:03:48 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 521F54506D; Mon, 14 Mar 2022 18:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647306157; x=1678842157; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=XZwZwketbZYNKIw9FE9no3V9pO4DILmEufF864fa3dA=; b=EJs+gx/y7LXyKujCkFjtjpTx69QW66Vdj3U434P42PpyVejLn1SFDXPO E/V/VKSK819n1CVhVjkcadDztO0eS34JNSs0DM5Wbgpv4uLUp5x1A5h4H YM3FWbDfOFeJjr+QFzXoQohtIfA1UKh+opACuCDacEq4HKALbwI7Mu4yh 8jaCl07+Qr2GvpFy8dwy0datGAY1SVwMOSHK9DhGpev8KaIfkQi+vkIjK OrYF1wwSDvhY0BKyR8By3RIH82gPJanAM/oNsJRIIELlIohrl+Z/mS40v Q6aGwfuDq0DkM2rNLbzCYkh8ssT5qb0WD/gMIUXhr+bGxTPsfMHH6WRGj Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10286"; a="255912346" X-IronPort-AV: E=Sophos;i="5.90,181,1643702400"; d="scan'208";a="255912346" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2022 18:02:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,181,1643702400"; d="scan'208";a="515669307" Received: from cathy-vostro-3670.bj.intel.com ([10.238.156.128]) by orsmga006.jf.intel.com with ESMTP; 14 Mar 2022 18:02:35 -0700 From: Cathy Zhang To: linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@intel.com, ashok.raj@intel.com, cathy.zhang@intel.com Subject: [RFC PATCH v2 02/10] x86/sgx: Provide VA page non-NULL owner Date: Tue, 15 Mar 2022 09:02:52 +0800 Message-Id: <20220315010300.10199-3-cathy.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220315010300.10199-1-cathy.zhang@intel.com> References: <20220315010300.10199-1-cathy.zhang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Provide non-NULL owner for VA page, which tells that the EPC page is allocated for use. Signed-off-by: Cathy Zhang --- arch/x86/kernel/cpu/sgx/encl.h | 2 +- arch/x86/kernel/cpu/sgx/sgx.h | 2 +- arch/x86/kernel/cpu/sgx/encl.c | 5 +++-- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h index 1b6ce1da7c92..1807a7f55065 100644 --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -114,7 +114,7 @@ void sgx_encl_put_backing(struct sgx_backing *backing, bool do_write); int sgx_encl_test_and_clear_young(struct mm_struct *mm, struct sgx_encl_page *page); void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr); -struct sgx_epc_page *sgx_alloc_va_page(void); +struct sgx_epc_page *sgx_alloc_va_page(struct sgx_va_page *va_page); unsigned int sgx_alloc_va_slot(struct sgx_va_page *va_page); void sgx_free_va_slot(struct sgx_va_page *va_page, unsigned int offset); bool sgx_va_page_full(struct sgx_va_page *va_page); diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index dc8cb58100e3..e627c42a6eec 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -33,7 +33,7 @@ struct sgx_epc_page { unsigned int section; u16 flags; u16 poison; - struct sgx_encl_page *owner; + void *owner; struct list_head list; }; diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index d2b428992910..e08c59a049d3 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -990,6 +990,7 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr) /** * sgx_alloc_va_page() - Allocate a Version Array (VA) page + * @va_page: struct sgx_va_page connected to this VA page * * Allocate a free EPC page and convert it to a Version Array (VA) page. * @@ -997,12 +998,12 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr) * a VA page, * -errno otherwise */ -struct sgx_epc_page *sgx_alloc_va_page(void) +struct sgx_epc_page *sgx_alloc_va_page(struct sgx_va_page *va_page) { struct sgx_epc_page *epc_page; int ret; - epc_page = sgx_alloc_epc_page(NULL, true); + epc_page = sgx_alloc_epc_page(va_page, true); if (IS_ERR(epc_page)) return ERR_CAST(epc_page); diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index da3b569a10bd..9eb429aeb319 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -30,7 +30,7 @@ struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl) if (!va_page) return ERR_PTR(-ENOMEM); - va_page->epc_page = sgx_alloc_va_page(); + va_page->epc_page = sgx_alloc_va_page(va_page); if (IS_ERR(va_page->epc_page)) { err = ERR_CAST(va_page->epc_page); kfree(va_page);