From nobody Fri Nov 1 06:28:43 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 810721B2EC5; Fri, 30 Aug 2024 16:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725036094; cv=none; b=vB+wnYkk2oiQsk+U0lrCjv1RX/nsEgD+nmwiiDTvW8RHwJj83HnbcW4VmO9WMnkhD12orAk5ptJiPTHha/2swnm9mPbcFvwEc5riYyyFPR6lC4IYZyqPUjB76gg89SJc17lmrEcwJIVe5E74QytD+VU76JzkMArWQ61M0uel5S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725036094; c=relaxed/simple; bh=aBp+AO4BxlLvxNYOsjganDc4V0zfIfXD4mqngD4w4vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cMjzikfV6U4LPkdiy5vOsGgTwbYF0QsAYNcEZwANynXZnez5aQX4EJ6HbZgK3eaD7fA4nRXnWWRh58CXK+WjuPr9/kZH0slSdtc9hvHFEM5jMUiXp+XM2xtSdkxIL8sVbSsaX62NZG3ORk0W0MhGpQf1HM/eG5PwQ9/G+U9DLkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZkYVwpJ+; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZkYVwpJ+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725036092; x=1756572092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aBp+AO4BxlLvxNYOsjganDc4V0zfIfXD4mqngD4w4vw=; b=ZkYVwpJ+1ZDz6Z/W29l9EVE5cgL0TwmiUGYzIEDgPipq9PUH+rj+l6vi yJnEC7H1m/BOIJ+aX80woH35VySZU8vHI1c+khDysLfajRFBV7n11Xjd4 BmEe0svTVbhXgQx0uDjuwwKrEw7CHSbava1tvsHYHxtDw0UKcDU3PpGi3 3Z3zWgsVdMppIfWGUDNigXfGIedt+uJyblch08ycgAAC/LU9jONbii/4I YX0pXdEbmHazoIS8SfePvnYfOLRnvLR5wM+virb9FhFUMwoS/VK4UAR9f h0fQZYFc3rNyKHOwqzcsXv+7BTlZOV5r9qoYTo8kBTKWw11mr2ipeHbgh g==; X-CSE-ConnectionGUID: gWSsdHIkSM+3ZO7w6h25OQ== X-CSE-MsgGUID: EjwDtvGtTk+GKD8TmvmXsw== X-IronPort-AV: E=McAfee;i="6700,10204,11180"; a="34299912" X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="34299912" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 09:40:51 -0700 X-CSE-ConnectionGUID: +ozK9Qf7SAyVvYnX4/vZHw== X-CSE-MsgGUID: 2ozohFFjQ5OCeYySSB2XbA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="101440450" Received: from b4969164b36c.jf.intel.com ([10.165.59.5]) by orviesa001.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 09:40:52 -0700 From: Haitao Huang To: jarkko@kernel.org, dave.hansen@linux.intel.com, kai.huang@intel.com, tj@kernel.org, mkoutny@suse.com, chenridong@huawei.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sohil.mehta@intel.com, tim.c.chen@linux.intel.com Cc: zhiquan1.li@intel.com, kristen@linux.intel.com, seanjc@google.com, zhanb@microsoft.com, anakrish@microsoft.com, mikko.ylinen@linux.intel.com, yangjie@microsoft.com, chrisyan@microsoft.com Subject: [PATCH v17 01/16] x86/sgx: Replace boolean parameters with enums Date: Fri, 30 Aug 2024 09:40:22 -0700 Message-ID: <20240830164038.39343-2-haitao.huang@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240830164038.39343-1-haitao.huang@linux.intel.com> References: <20240830164038.39343-1-haitao.huang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace boolean parameters for 'reclaim' in the function sgx_alloc_epc_page() and its callers with an enum. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkko Sakkinen Suggested-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- arch/x86/kernel/cpu/sgx/encl.c | 12 ++++++------ arch/x86/kernel/cpu/sgx/encl.h | 4 ++-- arch/x86/kernel/cpu/sgx/ioctl.c | 10 +++++----- arch/x86/kernel/cpu/sgx/main.c | 14 +++++++------- arch/x86/kernel/cpu/sgx/sgx.h | 13 +++++++++++-- arch/x86/kernel/cpu/sgx/virt.c | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index 279148e72459..f474179b6f77 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -217,7 +217,7 @@ static struct sgx_epc_page *sgx_encl_eldu(struct sgx_en= cl_page *encl_page, struct sgx_epc_page *epc_page; int ret; =20 - epc_page =3D sgx_alloc_epc_page(encl_page, false); + epc_page =3D sgx_alloc_epc_page(encl_page, SGX_NO_RECLAIM); if (IS_ERR(epc_page)) return epc_page; =20 @@ -359,14 +359,14 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_s= truct *vma, goto err_out_unlock; } =20 - epc_page =3D sgx_alloc_epc_page(encl_page, false); + epc_page =3D sgx_alloc_epc_page(encl_page, SGX_NO_RECLAIM); if (IS_ERR(epc_page)) { if (PTR_ERR(epc_page) =3D=3D -EBUSY) vmret =3D VM_FAULT_NOPAGE; goto err_out_unlock; } =20 - va_page =3D sgx_encl_grow(encl, false); + va_page =3D sgx_encl_grow(encl, SGX_NO_RECLAIM); if (IS_ERR(va_page)) { if (PTR_ERR(va_page) =3D=3D -EBUSY) vmret =3D VM_FAULT_NOPAGE; @@ -1232,8 +1232,8 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsi= gned long addr) =20 /** * sgx_alloc_va_page() - Allocate a Version Array (VA) page - * @reclaim: Reclaim EPC pages directly if none available. Enclave - * mutex should not be held if this is set. + * @reclaim: Whether reclaim EPC pages directly if none available. Enclave + * mutex should not be held for SGX_DO_RECLAIM. * * Allocate a free EPC page and convert it to a Version Array (VA) page. * @@ -1241,7 +1241,7 @@ void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsi= gned long addr) * a VA page, * -errno otherwise */ -struct sgx_epc_page *sgx_alloc_va_page(bool reclaim) +struct sgx_epc_page *sgx_alloc_va_page(enum sgx_reclaim reclaim) { struct sgx_epc_page *epc_page; int ret; diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h index f94ff14c9486..fe15ade02ca1 100644 --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -116,14 +116,14 @@ struct sgx_encl_page *sgx_encl_page_alloc(struct sgx_= encl *encl, unsigned long offset, u64 secinfo_flags); void sgx_zap_enclave_ptes(struct sgx_encl *encl, unsigned long addr); -struct sgx_epc_page *sgx_alloc_va_page(bool reclaim); +struct sgx_epc_page *sgx_alloc_va_page(enum sgx_reclaim reclaim); 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); void sgx_encl_free_epc_page(struct sgx_epc_page *page); struct sgx_encl_page *sgx_encl_load_page(struct sgx_encl *encl, unsigned long addr); -struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, bool reclaim); +struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, enum sgx_reclaim = reclaim); void sgx_encl_shrink(struct sgx_encl *encl, struct sgx_va_page *va_page); =20 #endif /* _X86_ENCL_H */ diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioct= l.c index b65ab214bdf5..793a0ba2cb16 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -17,7 +17,7 @@ #include "encl.h" #include "encls.h" =20 -struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, bool reclaim) +struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl, enum sgx_reclaim = reclaim) { struct sgx_va_page *va_page =3D NULL; void *err; @@ -64,7 +64,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struct = sgx_secs *secs) struct file *backing; long ret; =20 - va_page =3D sgx_encl_grow(encl, true); + va_page =3D sgx_encl_grow(encl, SGX_DO_RECLAIM); if (IS_ERR(va_page)) return PTR_ERR(va_page); else if (va_page) @@ -83,7 +83,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struct = sgx_secs *secs) =20 encl->backing =3D backing; =20 - secs_epc =3D sgx_alloc_epc_page(&encl->secs, true); + secs_epc =3D sgx_alloc_epc_page(&encl->secs, SGX_DO_RECLAIM); if (IS_ERR(secs_epc)) { ret =3D PTR_ERR(secs_epc); goto err_out_backing; @@ -269,13 +269,13 @@ static int sgx_encl_add_page(struct sgx_encl *encl, u= nsigned long src, if (IS_ERR(encl_page)) return PTR_ERR(encl_page); =20 - epc_page =3D sgx_alloc_epc_page(encl_page, true); + epc_page =3D sgx_alloc_epc_page(encl_page, SGX_DO_RECLAIM); if (IS_ERR(epc_page)) { kfree(encl_page); return PTR_ERR(epc_page); } =20 - va_page =3D sgx_encl_grow(encl, true); + va_page =3D sgx_encl_grow(encl, SGX_DO_RECLAIM); if (IS_ERR(va_page)) { ret =3D PTR_ERR(va_page); goto err_out_free; diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 27892e57c4ef..e64073fb4256 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -464,14 +464,14 @@ static struct sgx_epc_page *__sgx_alloc_epc_page_from= _node(int nid) /** * __sgx_alloc_epc_page() - Allocate an EPC page * - * Iterate through NUMA nodes and reserve ia free EPC page to the caller. = Start + * Iterate through NUMA nodes and reserve a free EPC page to the caller. S= tart * from the NUMA node, where the caller is executing. * * Return: * - an EPC page: A borrowed EPC pages were available. * - NULL: Out of EPC pages. */ -struct sgx_epc_page *__sgx_alloc_epc_page(void) +static struct sgx_epc_page *__sgx_alloc_epc_page(void) { struct sgx_epc_page *page; int nid_of_current =3D numa_node_id(); @@ -543,12 +543,12 @@ int sgx_unmark_page_reclaimable(struct sgx_epc_page *= page) /** * sgx_alloc_epc_page() - Allocate an EPC page * @owner: the owner of the EPC page - * @reclaim: reclaim pages if necessary + * @reclaim: whether reclaim pages if necessary * * Iterate through EPC sections and borrow a free EPC page to the caller. = When a * page is no longer needed it must be released with sgx_free_epc_page(). = If - * @reclaim is set to true, directly reclaim pages when we are out of page= s. No - * mm's can be locked when @reclaim is set to true. + * @reclaim is set to SGX_DO_RECLAIM, directly reclaim pages when we are o= ut of + * pages. No mm's can be locked for SGX_DO_RECLAIM. * * Finally, wake up ksgxd when the number of pages goes below the watermark * before returning back to the caller. @@ -557,7 +557,7 @@ int sgx_unmark_page_reclaimable(struct sgx_epc_page *pa= ge) * an EPC page, * -errno on error */ -struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) +struct sgx_epc_page *sgx_alloc_epc_page(void *owner, enum sgx_reclaim recl= aim) { struct sgx_epc_page *page; =20 @@ -571,7 +571,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bo= ol reclaim) if (list_empty(&sgx_active_page_list)) return ERR_PTR(-ENOMEM); =20 - if (!reclaim) { + if (reclaim =3D=3D SGX_NO_RECLAIM) { page =3D ERR_PTR(-EBUSY); break; } diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index d2dad21259a8..ca34cd4f58ac 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -29,6 +29,16 @@ /* Pages on free list */ #define SGX_EPC_PAGE_IS_FREE BIT(1) =20 +/** + * enum sgx_reclaim - Whether EPC reclamation is allowed within a function. + * %SGX_NO_RECLAIM: Do not reclaim EPC pages. + * %SGX_DO_RECLAIM: Reclaim EPC pages as needed. + */ +enum sgx_reclaim { + SGX_NO_RECLAIM, + SGX_DO_RECLAIM +}; + struct sgx_epc_page { unsigned int section; u16 flags; @@ -83,13 +93,12 @@ static inline void *sgx_get_epc_virt_addr(struct sgx_ep= c_page *page) return section->virt_addr + index * PAGE_SIZE; } =20 -struct sgx_epc_page *__sgx_alloc_epc_page(void); void sgx_free_epc_page(struct sgx_epc_page *page); =20 void sgx_reclaim_direct(void); void sgx_mark_page_reclaimable(struct sgx_epc_page *page); int sgx_unmark_page_reclaimable(struct sgx_epc_page *page); -struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim); +struct sgx_epc_page *sgx_alloc_epc_page(void *owner, enum sgx_reclaim recl= aim); =20 void sgx_ipi_cb(void *info); =20 diff --git a/arch/x86/kernel/cpu/sgx/virt.c b/arch/x86/kernel/cpu/sgx/virt.c index 7aaa3652e31d..e7fdc3a9abae 100644 --- a/arch/x86/kernel/cpu/sgx/virt.c +++ b/arch/x86/kernel/cpu/sgx/virt.c @@ -46,7 +46,7 @@ static int __sgx_vepc_fault(struct sgx_vepc *vepc, if (epc_page) return 0; =20 - epc_page =3D sgx_alloc_epc_page(vepc, false); + epc_page =3D sgx_alloc_epc_page(vepc, SGX_NO_RECLAIM); if (IS_ERR(epc_page)) return PTR_ERR(epc_page); =20 --=20 2.43.0