Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1138661rwb; Thu, 22 Sep 2022 10:34:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+Uil5tS9ZF9Zu4HhTdNd9r8kfJ7Iqpcv91xNMTijXsMpTJEPbbUeqqObeHJv94tPKq+/v X-Received: by 2002:a17:90b:4a85:b0:202:4f3f:1f65 with SMTP id lp5-20020a17090b4a8500b002024f3f1f65mr4793630pjb.241.1663868083016; Thu, 22 Sep 2022 10:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663868083; cv=none; d=google.com; s=arc-20160816; b=JpsxCRFdhxZaxbP87C9LLnfW3WxeveBizE1TsEldDxC7cfaAHLRMhzn+YgJ+pZtEK4 LTmmftCxUbom4oozNfmoWL20aQ2/ZOTS+ZxH0JH9r5D2bMdWz6W0hMOQaGh0JOMYhwtG TswFFPwQ96kSTXpClTo47dOu/D4OucPZOaxnet83VQUlALz1EaQYnLNqAfJTP55V07In rZK+r1zUPPN43s0LS3AgME5CL/OhHh85ZaUYkYOXYCMvSOS9JSp/KwDvGkCjZqm26Kyz CzLKrhCQOpyZa1zWYcdJNSjVybtpIozkFGIJAAl0yMoaH7h7QmMCpHzHtbNDzY8cb62k Htsg== 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=Zr7xr5Fli9f8jWNnW6UjQHRRrJRf/EKPZRV0icNaCOc=; b=RYeIx6Xui5M73MAJAPBD5C1g6GtvMrgAzrKTP5Vd1fpeydvURBcOtMcsqWXTbvHl9R wMG56ZSM7BflH4qCZsL9ZeubtiscmEy9vrQmPoCQ1NsbV+tnTGuJ8AqKDuZ62pEZAzPR Nl1RTlgJAuiBVSMC8EQG8beFZVxm6b5mLIboBP9W1IkfU2GrMpv7qmvyIQWcPoKfPjBk t7l69WbFW9+X2WvDBZ8/PhQ/IohgrblL1svu1heIiDHuQ1vLUii1Fr8KZMeouuWc74Cp JlidyYp1Cm36Hcu50J1/MWmZY0oEwsjD5HxYaoZFh1m+jEyjF5yGqB9kZaX2qzOeJQc6 ZMGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QB2pUA5r; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a170902c7cd00b0017854cfd6b3si305960pla.317.2022.09.22.10.34.28; Thu, 22 Sep 2022 10:34:43 -0700 (PDT) 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=QB2pUA5r; 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 S231965AbiIVRMJ (ORCPT + 99 others); Thu, 22 Sep 2022 13:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231982AbiIVRLx (ORCPT ); Thu, 22 Sep 2022 13:11:53 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DCF4100AA4; Thu, 22 Sep 2022 10:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663866708; x=1695402708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YYmyfKC3KMAXnaj8uAGWA1KxL3gThquOW2nfx+FoyxM=; b=QB2pUA5r0oWn0mSF4286hqTK36NxZRmicAWUphAmDGHoTlDkESUdczRw B3KhfNXHf0bUC3UHiCyYEDygDvTMGdMmEp8REQ4oX2MlI5+o0LGlYBi/6 WVUJTq/Kn4E53PYMY15hzCy486b73v3mxObds6nfb6+iaamTUiOdWmUmY KpG8Zdi9ZP9JnovkDLU5fKx5R0aA5zatg8caugg/xATJEa8JVn5EUNXkz lNDGkJefxERcNRZah4R6tBE2cZbS9r8v4cEVfVCueHP4Q37/vWaJcyvpU mGSd+LLSMt94XvKAA7NjGtfAiWQ+9ErTXn6nk0EBU0fqRsn0lmeeleCFJ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="299081597" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="299081597" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 10:11:47 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="762270115" Received: from sknaidu-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.212.165.187]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 10:11:29 -0700 From: Kristen Carlson Accardi To: linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Jarkko Sakkinen , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: Kristen Carlson Accardi , Sean Christopherson Subject: [RFC PATCH 09/20] x86/sgx: Allow reclaiming up to 32 pages, but scan 16 by default Date: Thu, 22 Sep 2022 10:10:46 -0700 Message-Id: <20220922171057.1236139-10-kristen@linux.intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220922171057.1236139-1-kristen@linux.intel.com> References: <20220922171057.1236139-1-kristen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 3c0d33b72896..0010ed1b2e98 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_encl_page *encl_page; struct sgx_epc_page *epc_page, *tmp; 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++) { if (list_empty(&sgx_global_lru.reclaimable)) 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->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); @@ -384,7 +389,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) @@ -410,7 +415,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; @@ -581,7 +586,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)) -- 2.37.3