From patchwork Fri Dec 2 18:36:47 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: 29069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1016495wrr; Fri, 2 Dec 2022 10:44:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EXvJxu8dgGdB3904vpnnAMuQY6iW/LOy6NjlOK0kbvSAiniUxd4zYZSC5d5/fwfIQQNFE X-Received: by 2002:a17:906:5dd2:b0:7c0:af0b:b3a2 with SMTP id p18-20020a1709065dd200b007c0af0bb3a2mr2402433ejv.654.1670006681010; Fri, 02 Dec 2022 10:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670006681; cv=none; d=google.com; s=arc-20160816; b=h+jABEFPNj/w9036zTAno8/90ELQv0u7L/W4fD/rpxbhfZEFCTPTm0teuSl0Kc4cCe F08VNb414O9C1U2waxUYjOYv4JTsg737IDhnACrSkieuItYQspt31Q42gvrNbSu3o4Nt HXpmPeqhqqB5m9nY4blkP4zYi9zjrwxqzSHV/xplevE2kUXv/RWoBmO824dV278SgA8Z oxDkjFjQFS//cUpWy4bqjmBJvWVFUVxVZpzr8BgZdPtV4qOylo/8O9KzO+xD0rGGaa90 zGyAdbTtJLQHmlH+cjgRdGUfnkScR+LCvt9oR+Z/PCVWkQ9AiGf8RZxYniBUj7rnShab Sv+w== 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=mY214QnNK6FoyLzDfPbVjB9mniryc0WmkrrNwJniIbU=; b=FHtnrPEysDR0MA04V1P3B1HrtLd9bgoSU7uqTlxEL0HyN2Ba+zThgEGp3b8XKLexZ7 vIiZYkyhGUNiocgWZzwo4fX4Mnm0GTstdvGhJQzTl41gJthiNZ5oTbKebqQarH15cBWP TTspRrZIFcN6ODcVbKG/jEA0Z4c7DdQDpNRqTufNJ77F3CllZjCO7y8CJT21zmZNV1dn ISBP7Tc8LC+2LWWcp+EwoxMAU+jAU5FmvVKUPe5xO8DUvoD5vHLOjlE7bX7Y82vLxXhQ 97znT2TwwD+rDCmQJLBgU+MzSgwmJcr+U6HaKhs4HLtQQQ5ALzFW+iEYmdLQ9C22O6Qm mprA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XbcsOr+W; 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 f5-20020aa7d845000000b004674aa77346si6485570eds.72.2022.12.02.10.44.18; Fri, 02 Dec 2022 10:44:40 -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=XbcsOr+W; 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 S234584AbiLBSi1 (ORCPT + 99 others); Fri, 2 Dec 2022 13:38:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234174AbiLBShv (ORCPT ); Fri, 2 Dec 2022 13:37:51 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6466EBCBF; Fri, 2 Dec 2022 10:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670006246; x=1701542246; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UYpUlq+6H1OK5zNVWPbJu6ZZ/ARyRWJyKUaDzZw64U4=; b=XbcsOr+W7KNHyshrAEZOusqAx5gaBk4z2MtzqvNjf6HLhjwk5n678+Gk 9tnmKoaopQFpGbB6UZg/RAnD2bQmmBSZPBbKkhryB2t3j8soUeYs15B1R z2PZUgXCTaz2V6IBtbh/14jVofCds1X5aQ+zAkR4w/b22Y8j9dwur1rAy hPA5GOlwnA7Lt1Z4d/K6lqy9HMTo5FsuAE4aSWkJyz//igtdb+vZtGxTX pl5J28hGUD7z+cVl1xHvZc2+bc94Xm09k4ymHMvdt+5alrAVSwFCKQJIj oGG0iiA3ROdhWGhfLRZxhgNCwiBvi5EJj/VGuQ7kBiX+4YUllAgQnSdRl w==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="314724623" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="314724623" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="713717527" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="713717527" Received: from kcaskeyx-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.251.1.207]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:24 -0800 From: Kristen Carlson Accardi To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: zhiquan1.li@intel.com, Kristen Carlson Accardi , Sean Christopherson Subject: [PATCH v2 11/18] x86/sgx: Prepare for multiple LRUs Date: Fri, 2 Dec 2022 10:36:47 -0800 Message-Id: <20221202183655.3767674-12-kristen@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221202183655.3767674-1-kristen@linux.intel.com> References: <20221202183655.3767674-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?1751128925338293482?= X-GMAIL-MSGID: =?utf-8?q?1751128925338293482?= From: Sean Christopherson Add sgx_can_reclaim() wrapper so that in a subsequent patch, multiple LRUs can be used cleanly. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index db96483e2e74..96399e2016a8 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -394,10 +394,15 @@ static int sgx_reclaim_pages(int nr_to_scan, bool ignore_age) return ret; } +static bool sgx_can_reclaim(void) +{ + return !list_empty(&sgx_global_lru.reclaimable); +} + static bool sgx_should_reclaim(unsigned long watermark) { return atomic_long_read(&sgx_nr_free_pages) < watermark && - !list_empty(&sgx_global_lru.reclaimable); + sgx_can_reclaim(); } /* @@ -606,7 +611,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) break; } - if (list_empty(&sgx_global_lru.reclaimable)) + if (!sgx_can_reclaim()) return ERR_PTR(-ENOMEM); if (!reclaim) {