From patchwork Fri Nov 11 18:35:18 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: 18963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp905944wru; Fri, 11 Nov 2022 10:39:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf49pFJUW/Czk/4TdNW+V1bwinrn4cNY2O8YAOfhzP/YLihB8Pny6GBQT+E8OHqj1MMSkosl X-Received: by 2002:a63:e48:0:b0:46f:f26e:e877 with SMTP id 8-20020a630e48000000b0046ff26ee877mr2657488pgo.545.1668191974683; Fri, 11 Nov 2022 10:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668191974; cv=none; d=google.com; s=arc-20160816; b=k8GccZ0KtmF1B0h7xmi88QM0gJgdI3IaRFpjWD98D8BxHJNdguYrtJfoTJ/7QJenBe ydU0wzTLJEDUg8+cN2gpyi+S7cP4w8x44BRdeRrG/P2Cx+3RZUoVsyHI2SHPR4gyuPs3 UZ0WB0Djt9vRej5j4GAEwWWt3a2bnJ3eQJLoazhfnzdcXIoLRnII7sjJ4LAPhxUtjmf6 w/YvG4TYF0QCkeoBZXwGwOFhRMMwEZLM88nY9bJ6FOP1DdyisGssr7NnryfHL4Fcmcz9 nh6YE5Q4SNtY1b5rBaljJF93G4P/A8+8bFR3xMsJnVGJw0+APARxhTFBzx6VDjTlpy41 Lflw== 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=+PGwxn7jSl2Q8Bgtlu5qowluy8L6RVgO8fAc7hriaEk=; b=MmTji4+BfpvkQ7zjLVkiJ4b5tCpM+cg90uZQOwNQbnrPYcsFYLZ6dpLG3+q7GlN3ZP cPA9RvGDdVzaYjFVUqtcnhpmHJYedQCdFIBTXMr52CN2HJsu/m3tvOOatgotqyKMaR3k 2v0RKA3F6WXybd3rJOFiQKCMMzAe2QaOGtHhkOTjAD6r7e6qOVqzHmqjhuBkhuTPsHb8 3KLzP42DL7GvpnTDGejIX8Ic0OIFEVdzs50kQkB88AAjrC33Y0qkhLSbD7cou3RhQstP /JaPlATohjRqiJMHejSrgPG7W0U4uZzpIgQyEMULbFihs0405X51LmOPbyx27WrLHxP3 prtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kQNug6Bu; 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 c132-20020a63358a000000b0046fd05d55e1si3454703pga.185.2022.11.11.10.39.19; Fri, 11 Nov 2022 10:39: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=kQNug6Bu; 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 S234303AbiKKShM (ORCPT + 99 others); Fri, 11 Nov 2022 13:37:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233828AbiKKSgF (ORCPT ); Fri, 11 Nov 2022 13:36:05 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22EB832061; Fri, 11 Nov 2022 10:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668191765; x=1699727765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tdinHlyyGqVYquaFqgcvC9rbRf2JmMok2HdQOnKfOO0=; b=kQNug6BumCzHV+Fz26lBnWpC6rlBPPrsDXL0pxOp5hB0JkA4jnJRgOPi kz5oxfnJZlMIuJDZ7wtPO3eJQe9LOWGnrrLi3DJxcUVMnyPrMuKh19BgB 55MrZUl7rjW065OKk+Lwcl/u0TivsHL7aNU6Em/pltOXyVl/MeMcJdB09 z7AmC0dEZier/ZCijcxdG5Fd37LF7ddD8lBuyosgD0h49oeqEWOuY66Pa 0tosQkA3HwIeb7Hgz4OSM8aqaNlmB2Fuwh4sXWn8AIkD3aj8sTIR4rSj5 dpWLe8XD1HH6rPfIw/1zn8ajBdYtFjtn4ZKYVs1e7sRgoEm/sNrzGtNJ+ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="292050364" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="292050364" 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:05 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="640089302" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="640089302" 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:03 -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 13/26] x86/sgx: Prepare for multiple LRUs Date: Fri, 11 Nov 2022 10:35:18 -0800 Message-Id: <20221111183532.3676646-14-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?1749226068224722421?= X-GMAIL-MSGID: =?utf-8?q?1749226068224722421?= 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 c33966eafab6..b2c050fcc989 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -391,10 +391,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(); } /* @@ -599,7 +604,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) {