From patchwork Fri Nov 11 18:35:16 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: 18951 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp905239wru; Fri, 11 Nov 2022 10:37:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ytY18cZXrGbcHeW/fuIGwghA5YPErv6TjBMXRQERt798OeU5D8p0cHeLh8AzdHjYh7mBN X-Received: by 2002:a17:903:278a:b0:176:a9d6:ed53 with SMTP id jw10-20020a170903278a00b00176a9d6ed53mr3772060plb.5.1668191863452; Fri, 11 Nov 2022 10:37:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668191863; cv=none; d=google.com; s=arc-20160816; b=kVgOdAs0J6lrepMW2AkPIoTm6FAs+iWrtwfzrPhkb4Hds8oRG4i77aFxkeMGBpJbUR WHsPoEUMY6uH1b6FxyDWTsAayD7hq61ZEhlEfsEMgpeppavrP49tAaqQjvKTaTej5Het b41BBbcQ2T8Y8Qr0CqzjlqI/t1MGYLx2NAldrbIZbtI0QzXJ/hi1VUi56RRGBXc7N9vI dtCiIvbEKUdcbQV+CUHMm7O840CtShhs4ODHFte5Y4VjzGgKgSHQZqfuOWOyAgS8w9Gj HMR0+FUX9hBjaZ2X5gP14JWXf9Orr0+veoxlac6FeMuUcIIdXnNy3JfS32obYqwz2m2Z Ai4A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a17090aa10c00b00215e0e55a9esi3089811pjp.38.2022.11.11.10.37.29; Fri, 11 Nov 2022 10:37:43 -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 + 99 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 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?1749225951471575858?= X-GMAIL-MSGID: =?utf-8?q?1749225951471575858?= 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))