From patchwork Fri Nov 11 18:35:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristen Carlson Accardi X-Patchwork-Id: 18949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp905132wru; Fri, 11 Nov 2022 10:37:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf5EK+PDOftUrYt9Pii6D8a5ejSsiHiNJpNudUz7xaEHNaZ76TWDt6IWEM5Kxrb/A6zAsao/ X-Received: by 2002:a17:90b:3d83:b0:200:7cf7:3d79 with SMTP id pq3-20020a17090b3d8300b002007cf73d79mr3104422pjb.206.1668191847040; Fri, 11 Nov 2022 10:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668191847; cv=none; d=google.com; s=arc-20160816; b=OnVjKR186IqDqnTPo/o8S1mddSO+OrhO4tIUcosGOPRoeYt7WRO/1KUT4T3FYYKXu6 siHl7eghiK2auZ6VXYYKu+nBZod+wGsbwjhmp+4zZOBEa30Ic5k/2tATA3TuISXIbzrw 3PPNN3Ij6lWNQR60QysCDTfsdpuvdGcAPXa5z00cJ1s4Cm3wJXpNOesUySvslYXZnI/E xW4zcmfxrTJqKhDjTlumY2pvhSRMP246xAlHsStfc/HySR9C4NX09htM9ldazFTXC2mL W04RuHw5aMtXDYvf1fR1ABcqqowalD8D1DlagASvC2pANnYyBxLP/iV7gebmGUH0Wa+A upOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O2/bRvxuT6eh6Eh1xx7FDKvFSzWmavUDA4AnwyurF8w=; b=TaZ9Yf8P3U/a1LJO4L3QJrJql+B/CXgXpYaSURtsp8+Acpg3HOxQegf5OsoUhGXwPV 3LATTewMCuROZ09KHk/MrK43vf/I90GgKNTSYktiEmWVaz6GH2yFX1XazLEVV124+E+U h6bwFqO+VCANEVAgn0qFvMENQV8rsE/jIUNrB1MowWLm9XfWCzaEyr1MVyGYGMnKasK4 G1o/rjm21eZRISToOdWP27Fpil1vIWQcqqUIfIeYVCzLccElyPXmXdikhzL4MeinDUKi eyz3IukYRdNXayNCXy9cGNApf2pD+iGDBK/BBdIeMAm+Qbc+F1hOHrbMYkwuPoL0ejXa zGBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FEtJInvr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 33-20020a631361000000b0046fbe60747asi2920508pgt.594.2022.11.11.10.37.12; Fri, 11 Nov 2022 10:37:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FEtJInvr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234441AbiKKSgs (ORCPT + 99 others); Fri, 11 Nov 2022 13:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234055AbiKKSgB (ORCPT ); Fri, 11 Nov 2022 13:36:01 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CC6D814CB; Fri, 11 Nov 2022 10:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668191760; x=1699727760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k+CVp2hi4UWDtXCcGnCdgpBlK4viKY8x8JVMjdD5Pak=; b=FEtJInvrR9Jcy+UGn6nMLT91pW6eoyIwxIrcaQuTuDIgNuvqcmoniPe8 BLfI8e1IsaE+/LGpb/WfiY/0Hm917V4ODBCeMm74eQf8vfBhW0n18zFdA vRQzmbjpVqp1fp4r/5CNfdZUPAN/8YaIsJ+2k80ECI4iZjn1vjURLBj2O KSFc9qsPefjPC9Fgjo7mzaMOobnqFoyNr3/eK7MkpeTHFpBB9zrjQfZLC u3cD/OdIO3jfgp0cuC9t1KLZGvkRrJ4tFwg5ZjSEs86zdfvVLfHfzd4+D siH8eCnSqtYqG/r+4gs81NvDDes4wI11yM27RiMnCQZW4s9wC9Etzk0RC w==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="292050351" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="292050351" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 10:35:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="640089252" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="640089252" Received: from hermesli-mobl.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.212.218.5]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2022 10:35:56 -0800 From: Kristen Carlson Accardi To: jarkko@kernel.org, dave.hansen@linux.kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: zhiquan1.li@intel.com, Kristen Carlson Accardi , Sean Christopherson Subject: [PATCH 09/26] x86/sgx: Allow reclaiming up to 32 pages, but scan 16 by default Date: Fri, 11 Nov 2022 10:35:14 -0800 Message-Id: <20221111183532.3676646-10-kristen@linux.intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221111183532.3676646-1-kristen@linux.intel.com> References: <20221111183532.3676646-1-kristen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749225934548203007?= X-GMAIL-MSGID: =?utf-8?q?1749225934548203007?= From: Sean Christopherson Modify sgx_reclaim_pages() to take a parameter that specifies the number of pages to scan for reclaiming. Specify a max value of 32, but scan 16 in the usual case. This allows the number of pages sgx_reclaim_pages() scans to be specified by the caller, and adjusted in future patches. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 09cc83d7cb97..02b9eafa90a2 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -18,6 +18,8 @@ #include "encl.h" #include "encls.h" +#define SGX_MAX_NR_TO_RECLAIM 32 + struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS]; static int sgx_nr_epc_sections; static struct task_struct *ksgxd_tsk; @@ -273,7 +275,10 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, mutex_unlock(&encl->lock); } -/* +/** + * sgx_reclaim_pages() - Reclaim EPC pages from the consumers + * @nr_to_scan: Number of EPC pages to scan for reclaim + * * Take a fixed number of pages from the head of the active page pool and * reclaim them to the enclave's private shmem files. Skip the pages, which have * been accessed since the last scan. Move those pages to the tail of active @@ -286,9 +291,9 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, * problematic as it would increase the lock contention too much, which would * halt forward progress. */ -static void __sgx_reclaim_pages(void) +static void __sgx_reclaim_pages(int nr_to_scan) { - struct sgx_backing backing[SGX_NR_TO_SCAN]; + struct sgx_backing backing[SGX_MAX_NR_TO_RECLAIM]; struct sgx_epc_page *epc_page, *tmp; struct sgx_encl_page *encl_page; pgoff_t page_index; @@ -297,7 +302,7 @@ static void __sgx_reclaim_pages(void) int i; spin_lock(&sgx_global_lru.lock); - for (i = 0; i < SGX_NR_TO_SCAN; i++) { + for (i = 0; i < nr_to_scan; i++) { epc_page = sgx_epc_peek_reclaimable(&sgx_global_lru); if (!epc_page) break; @@ -327,7 +332,7 @@ static void __sgx_reclaim_pages(void) list_for_each_entry_safe(epc_page, tmp, &iso, list) { encl_page = epc_page->encl_owner; - if (!sgx_reclaimer_age(epc_page)) + if (i == SGX_MAX_NR_TO_RECLAIM || !sgx_reclaimer_age(epc_page)) goto skip; page_index = PFN_DOWN(encl_page->desc - encl_page->encl->base); @@ -368,9 +373,9 @@ static void __sgx_reclaim_pages(void) } } -static void sgx_reclaim_pages(void) +static void sgx_reclaim_pages(int nr_to_scan) { - __sgx_reclaim_pages(); + __sgx_reclaim_pages(nr_to_scan); cond_resched(); } @@ -390,7 +395,7 @@ static bool sgx_should_reclaim(unsigned long watermark) void sgx_reclaim_direct(void) { if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) - __sgx_reclaim_pages(); + __sgx_reclaim_pages(SGX_NR_TO_SCAN); } static int ksgxd(void *p) @@ -416,7 +421,7 @@ static int ksgxd(void *p) sgx_should_reclaim(SGX_NR_HIGH_PAGES)); if (sgx_should_reclaim(SGX_NR_HIGH_PAGES)) - sgx_reclaim_pages(); + sgx_reclaim_pages(SGX_NR_TO_SCAN); } return 0; @@ -591,7 +596,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) break; } - sgx_reclaim_pages(); + sgx_reclaim_pages(SGX_NR_TO_SCAN); } if (sgx_should_reclaim(SGX_NR_LOW_PAGES))