Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2547291rwb; Fri, 11 Nov 2022 10:50:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gfXElzoQmWeOVgrqzYe+Nl+I24GplxR0PNVqGKxYiorJDvIAwHRM7QbUD2ZOUYlF6vQAq X-Received: by 2002:a17:906:1245:b0:7ad:d250:b905 with SMTP id u5-20020a170906124500b007add250b905mr2745613eja.742.1668192634834; Fri, 11 Nov 2022 10:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668192634; cv=none; d=google.com; s=arc-20160816; b=n2Vpppi51vIO6DOxFTqjLd2WGd3B26x5i9fGT4oQnsAQz/pFZwQa74L6mV0VNl5DEk AwvU2j/BDh3HY/UuQEG8vXjFZFaiCJ55DaV2thd9EsMMwGNVbYe0db9gBT+fQa44VTmz d37H57rtjsP0nT8ygLkVHX2xFBJkZOiJ3iXHoNbIaeN3FO6hBnuHfAWVVmrFEchyiyEl yr0DWDB6XJ9axTel9NvjMAYTtaefoa/LovdpjEIpdNuAFFBsnaVgZJIDz5oeM+7+JsDx kRzIdhdyKrLr1ObK2zNNFumFuoGHzlEJov7+LBx368TkwHiHKkRa+ka+rGo2hqz5rKEA QGbw== 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=oK+aORvK1xhpic1bQzKh5nWxxU13QOoO570Y5rqNMn4=; b=OBnlxe/E6WNFXqaa256yoWiv0FPVQmZCxzoEOqNNpCuHlVNV2vbc08M4qB3gqHFR0R w2fJpOuODQMfbQ/OnCkNqwZpxPBhGr71sMTpqtVsYWMFzNOi4bJDwb2m9TcGnF47spj2 +xuENj6cm2d08qTkM8xUAz33tVwxjbbYj0o6JvX5d/ZhgxVm4rC+GWPvriXHngcQW8Hw he9KsK4wXOBZYEV6J9uH0OjGLuhKl5ed0iFp2+rq7fBjlNGPgIU98Jiu7Nep02Q3sbkI MEzXP8UE/DzMOTDllEXh/yUsKrVriMHQHzZFHMLh6teCVruYxcwhNjyh1scStuLYRQv+ 9aGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XkUwzZ3a; 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 k9-20020a17090646c900b0073dc32ccd9fsi1852682ejs.104.2022.11.11.10.50.12; Fri, 11 Nov 2022 10:50:34 -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=XkUwzZ3a; 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 S234185AbiKKShC (ORCPT + 90 others); Fri, 11 Nov 2022 13:37:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233593AbiKKSgC (ORCPT ); Fri, 11 Nov 2022 13:36:02 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95241814D1; Fri, 11 Nov 2022 10:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668191761; x=1699727761; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T3P7Q3xIri7oBiVTNsBMGR4O8OWA5OQYl9qvR3LdFVU=; b=XkUwzZ3aHIemRjo/noiKurMhPxOTF54mZDv4Cq1yMUGABab6eXeoUeeW e0QW9HCj8qQIdygxumVqKLqfoSsD5sbZDZuA1OvUcZlOv28HynRETJuKa UAZjLwQMa2VaZyYBIgw3N+rMtiyIDgPw4N8RsFaTo+KC3EDeQRhZ/Ur3S omM39GLEu/QErO96sWoScPvvQzzTxUVy8OlSEMkyTROVFZehPGES8HNg/ PoUxJTxTU//YUKWXiPF97MlKM6Hd+BUobHPEfqfiI1m1X1CDkz/3LqfFE HKBlM8AzJqbjuTMimnlZ8n6HTRr734pVSAVC89q/V6jzQr4j/bG8ACdFt Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="292050357" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="292050357" 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:36:01 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="640089262" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="640089262" 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:36:00 -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 11/26] x86/sgx: Add option to ignore age of page during EPC reclaim Date: Fri, 11 Nov 2022 10:35:16 -0800 Message-Id: <20221111183532.3676646-12-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 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 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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index dfd76c605ef2..b72b5868dd01 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 @@ -291,7 +292,7 @@ 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 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_epc_page *epc_page, *tmp; @@ -332,7 +333,8 @@ static int __sgx_reclaim_pages(int nr_to_scan) list_for_each_entry_safe(epc_page, tmp, &iso, list) { encl_page = epc_page->encl_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); @@ -374,11 +376,11 @@ static int __sgx_reclaim_pages(int nr_to_scan) return i; } -static int sgx_reclaim_pages(int nr_to_scan) +static int sgx_reclaim_pages(int nr_to_scan, bool ignore_age) { int ret; - ret = __sgx_reclaim_pages(nr_to_scan); + ret = __sgx_reclaim_pages(nr_to_scan, ignore_age); cond_resched(); return ret; } @@ -399,7 +401,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) @@ -425,7 +427,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; @@ -600,7 +602,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