Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2546389rwb; Fri, 11 Nov 2022 10:49:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf74Bq3dgPNpvNoJzEDDtgiQTzqd+RPRq+WxMTkbyselrqhnQwh+0d9rgqyZmi+SBh5H3Qpt X-Received: by 2002:a17:906:3551:b0:7ae:43f5:a2a3 with SMTP id s17-20020a170906355100b007ae43f5a2a3mr2821410eja.595.1668192580109; Fri, 11 Nov 2022 10:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668192580; cv=none; d=google.com; s=arc-20160816; b=ADb5uJG2cvzi4Rc0YqM/hHEfy1wfafyJndgX2JHBFAfd+ZtJY2uHZ+BWBuU0aA+y7U OZ/hvgnKrUI93bNnfUObpcaqcccAt1RjE85j1bd8sWSwxFtduQhsurxAHFuKzxMA4o6T yHfOc6Zr45DsxXv9iwND3I2ZYTsB3fChOVj1ILOyibkBT30IgFEXmX+5kxYOFpbPeNaX 1l1FE8MLLv3gKTpuMTzy6Mrqr77Cz/zubl/r0wK3mVyN7XjTBtr8/K8M79pM8YUCSDfm ZyO+TtKxAcVssku150ftFYTGK5zTRlyYVLzmuX2NSuH8o685j0yiyygc3K5dk0m6gZNc pM1Q== 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=cjTx/eXtuSAaeN8N6INO4IttQYO0BqJZHC+aL8hEEMY=; b=k7ebgCJF1GParNlXCLEDaDcyHZnZ/cMGi4iINzCGMKeIaW0DdeRl2ZrGyJlb6wbghM DpVIhT9G1ffG8tf0SFeTBBLp4uEo9e5Apr8QKFnh+qXokCc+jNsyYttPnxdFWp9zzKk/ myGiE+HowoYGkjZX88+EGKQVjRR2kmaBznka+O3nPAOwiFXcof4CvzFijq9J6Hi6j4L5 j4yuUoFUEtZd22GjhQ81UsRaBYh4yn1Uw6CQZGXHJQBWRQ/LxZOSUT27cEPEw8XNp2gd jUN6v5pnhL4XgahNvDf10HIejrTt4BmCl6drRV/kNnQJ+Q7/V/9Khm8Jhj3RfyUNLWgo 80Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CNDqOLMH; 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 wt13-20020a170906ee8d00b0078d1e08f1e5si2754562ejb.919.2022.11.11.10.49.18; Fri, 11 Nov 2022 10:49: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=CNDqOLMH; 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 S234327AbiKKSg1 (ORCPT + 91 others); Fri, 11 Nov 2022 13:36:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbiKKSf7 (ORCPT ); Fri, 11 Nov 2022 13:35:59 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6170E5CD2A; Fri, 11 Nov 2022 10:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668191754; x=1699727754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i0mg8Ya6R+UXd/hAsIcofGbYCmr7Xzm1K38RaWFQY70=; b=CNDqOLMHTa4HyF22yTy5WC1SQvkE+UOPvmF/Z/ohxbg0p3xSoeicnVvz 0QPol+rgKnUJZlI9u4HJb5OTa7blLX6g7bfMrEkOW55t0Z23Pjy2FZMTP YkLeo3ESHTw+iOOOV2wQMC3kLx9ZDMVuv318Jwj4KD5vanP3CKf6QZHJW 4xoBE2BuQ1OfNQcGEeuyQbf2fkMGyQCLCtGrONBtkZFpPn05WSr4xqu9O QRgiFpXYFVLOrysUTSixdwwLyomt/y6yf2apCNc6rnenz8Pfekg7XrIZY rrdCLDDrU7IppIFMLQoVm/eCqYb19N3+NQ1wK/lhd2rWc+RWDY2XkuZ44 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="292050306" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="292050306" 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:35:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10528"; a="640089177" X-IronPort-AV: E=Sophos;i="5.96,157,1665471600"; d="scan'208";a="640089177" 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:35:44 -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 04/26] x86/sgx: Use sgx_epc_lru for existing active page list Date: Fri, 11 Nov 2022 10:35:09 -0800 Message-Id: <20221111183532.3676646-5-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 Replace the existing sgx_active_page_list and its spinlock with a global sgx_epc_lru struct. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 39 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index ffce6fc70a1f..aa938e4d4a73 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -26,10 +26,9 @@ static DEFINE_XARRAY(sgx_epc_address_space); /* * These variables are part of the state of the reclaimer, and must be accessed - * with sgx_reclaimer_lock acquired. + * with sgx_global_lru.lock acquired. */ -static LIST_HEAD(sgx_active_page_list); -static DEFINE_SPINLOCK(sgx_reclaimer_lock); +static struct sgx_epc_lru sgx_global_lru; static atomic_long_t sgx_nr_free_pages = ATOMIC_LONG_INIT(0); @@ -298,14 +297,12 @@ static void __sgx_reclaim_pages(void) int ret; int i; - spin_lock(&sgx_reclaimer_lock); + spin_lock(&sgx_global_lru.lock); for (i = 0; i < SGX_NR_TO_SCAN; i++) { - if (list_empty(&sgx_active_page_list)) + epc_page = sgx_epc_pop_reclaimable(&sgx_global_lru); + if (!epc_page) break; - epc_page = list_first_entry(&sgx_active_page_list, - struct sgx_epc_page, list); - list_del_init(&epc_page->list); encl_page = epc_page->encl_owner; if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) @@ -316,7 +313,7 @@ static void __sgx_reclaim_pages(void) */ epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; } - spin_unlock(&sgx_reclaimer_lock); + spin_unlock(&sgx_global_lru.lock); for (i = 0; i < cnt; i++) { epc_page = chunk[i]; @@ -339,9 +336,9 @@ static void __sgx_reclaim_pages(void) continue; skip: - spin_lock(&sgx_reclaimer_lock); - list_add_tail(&epc_page->list, &sgx_active_page_list); - spin_unlock(&sgx_reclaimer_lock); + spin_lock(&sgx_global_lru.lock); + sgx_epc_push_reclaimable(&sgx_global_lru, epc_page); + spin_unlock(&sgx_global_lru.lock); kref_put(&encl_page->encl->refcount, sgx_encl_release); @@ -378,7 +375,7 @@ static void sgx_reclaim_pages(void) static bool sgx_should_reclaim(unsigned long watermark) { return atomic_long_read(&sgx_nr_free_pages) < watermark && - !list_empty(&sgx_active_page_list); + !list_empty(&sgx_global_lru.reclaimable); } /* @@ -433,6 +430,8 @@ static bool __init sgx_page_reclaimer_init(void) ksgxd_tsk = tsk; + sgx_lru_init(&sgx_global_lru); + return true; } @@ -508,10 +507,10 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) */ void sgx_mark_page_reclaimable(struct sgx_epc_page *page) { - spin_lock(&sgx_reclaimer_lock); + spin_lock(&sgx_global_lru.lock); page->flags |= SGX_EPC_PAGE_RECLAIMER_TRACKED; - list_add_tail(&page->list, &sgx_active_page_list); - spin_unlock(&sgx_reclaimer_lock); + sgx_epc_push_reclaimable(&sgx_global_lru, page); + spin_unlock(&sgx_global_lru.lock); } /** @@ -526,18 +525,18 @@ void sgx_mark_page_reclaimable(struct sgx_epc_page *page) */ int sgx_unmark_page_reclaimable(struct sgx_epc_page *page) { - spin_lock(&sgx_reclaimer_lock); + spin_lock(&sgx_global_lru.lock); if (page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) { /* The page is being reclaimed. */ if (list_empty(&page->list)) { - spin_unlock(&sgx_reclaimer_lock); + spin_unlock(&sgx_global_lru.lock); return -EBUSY; } list_del(&page->list); page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; } - spin_unlock(&sgx_reclaimer_lock); + spin_unlock(&sgx_global_lru.lock); return 0; } @@ -574,7 +573,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) break; } - if (list_empty(&sgx_active_page_list)) + if (list_empty(&sgx_global_lru.reclaimable)) return ERR_PTR(-ENOMEM); if (!reclaim) { -- 2.37.3