Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1147209rwb; Thu, 22 Sep 2022 10:41:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JMCjXf1AwVOI2Na0INLfosmNvKfdjUwe8QqBTp4t2fS0RzSHnmVg8y7nkIL2qRiG4u/l9 X-Received: by 2002:a05:6402:2489:b0:454:11de:7698 with SMTP id q9-20020a056402248900b0045411de7698mr4515246eda.214.1663868514053; Thu, 22 Sep 2022 10:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663868514; cv=none; d=google.com; s=arc-20160816; b=Ip+rz5zwmCjzEAAoN8vZkXDtkTjCspRjCb2DYh+mY2W+KZMRYurPNvFyodosb7K0e/ IX6/EjXv40KgvgMWnaVziu3c5oRS0eNs6+ooNYW7qME+WNO15mP7qfQzhjGwv6hyh+E8 JJa4/Elqeat6L84tqRO/D7oQ4/SSR0zAJhy6g96cktjVH639URsmIpHUDpLj9yAmNeHz B4sY0lPMEg46Qu7OGGv0AcoYOkqROie6937EwHpzh5kvu7gsvTDFDH0UUpg0Wsxsb6wR cFGwk3nUAUKSmT3K8wYmN1KCfUllkIuj9kehyABf6oDIW9KaaSBklWfwVW2HRcohG+sq 0MpQ== 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=IZVQJvNa25UeIYgOGs7vv9Gn22JDsUJc4kwfxXAppwg=; b=uujf4ubzvvptLThgKHynDBm27cC2CzXQko4SdjVeJwdh+JLDxT8oeMDWjtoyA4sDso LV8Z1qSGiGVzvWv8HArDiVgG4d4u5eU1O3gHhzjx8DvVPb8OUFayWqOBtChrndpSBJvN yXaHct0vUpMiu40ERiLBawXaWQif+gVa9qlsLlQv/tYmTAIbAzUS74BYJojhX7Mgqpy8 38V8uu908lypRN5D3T53uM8Al3WRytKbf6AxibwpUzC0k0PvRXauTRzSVOplTWAzSv27 loMxHh5DMAEFzZ0QG0xunvstwa3HDJisHY8bewkQqnnQtSLpnpAswtFPqh0irWcCBFI5 DiQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UezCxTzD; 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 dd5-20020a1709069b8500b007807bde7749si6692694ejc.351.2022.09.22.10.41.25; Thu, 22 Sep 2022 10:41:54 -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=UezCxTzD; 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 S230177AbiIVRNL (ORCPT + 99 others); Thu, 22 Sep 2022 13:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbiIVRNG (ORCPT ); Thu, 22 Sep 2022 13:13:06 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 073A8F85AB; Thu, 22 Sep 2022 10:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663866785; x=1695402785; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fdMNPny7GFohOVYJu7HIsWNUmP6XOgvNz9VT3/oKdyc=; b=UezCxTzDIhyqcXaUbH5n4Lkr34G/Qfd/SblliyyA0p7yJ3NWnMajB7fx FRDj83Iy2UAFKJLIyvVdcWLidkxely3pQAGNppg+S1CqkBB2f7rfuHCjS rV9aGaRIC7LVZyjrYGhNwPq+CH6mSUUZgMiTbI2iwLCMtiCIJLrtIqmWY Gh1l6ysVff76Jjq27ki3cfnrGBLYn76dpMp/ckS8Yx1yMQEbiFsiSWZMb 8ltHspwPMt2MprREQcoABQRcohCZTwxY/t5sxBcSXe4plB0IlaAv7vaWm vewp2sFwrIcWE2LFhIeRt4JNQ1zZh5FjQgQiiLbsStM3HWxz+mnjHPw2I Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="283421367" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="283421367" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 10:11:48 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="762270140" 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:33 -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 11/20] x86/sgx: Add option to ignore age of page during EPC reclaim Date: Thu, 22 Sep 2022 10:10:48 -0700 Message-Id: <20220922171057.1236139-12-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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 Add a flag to sgx_reclaim_pages() to instruct it to ignore the age of page, i.e. reclaim the page even if it's young. The EPC cgroup will use the flag to enforce its limits by draining the reclaimable lists before resorting to other measures, e.g. forcefully reclaimable "unreclaimable" pages by killing enclaves. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index fc5aed813834..98531f6fb448 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -278,6 +278,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, /** * sgx_reclaim_pages() - Reclaim EPC pages from the consumers * @nr_to_scan: Number of EPC pages to scan for reclaim + * @ignore_age: Reclaim a page even if it is young * * 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 @@ -293,7 +294,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, * * Return: number of EPC pages reclaimed */ -static int sgx_reclaim_pages(int nr_to_scan) +static int sgx_reclaim_pages(int nr_to_scan, bool ignore_age) { struct sgx_backing backing[SGX_MAX_NR_TO_RECLAIM]; struct sgx_encl_page *encl_page; @@ -334,7 +335,8 @@ static int sgx_reclaim_pages(int nr_to_scan) list_for_each_entry_safe(epc_page, tmp, &iso, list) { encl_page = epc_page->owner; - if (i == SGX_MAX_NR_TO_RECLAIM || !sgx_reclaimer_age(epc_page)) + if (i == SGX_MAX_NR_TO_RECLAIM || + (!ignore_age && !sgx_reclaimer_age(epc_page))) goto skip; page_index = PFN_DOWN(encl_page->desc - encl_page->encl->base); @@ -392,7 +394,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_NR_TO_SCAN); + sgx_reclaim_pages(SGX_NR_TO_SCAN, false); } static int ksgxd(void *p) @@ -418,7 +420,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_NR_TO_SCAN); + sgx_reclaim_pages(SGX_NR_TO_SCAN, false); } return 0; @@ -589,7 +591,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) break; } - sgx_reclaim_pages(SGX_NR_TO_SCAN); + sgx_reclaim_pages(SGX_NR_TO_SCAN, false); } if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) -- 2.37.3