Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp175997lqh; Wed, 27 Mar 2024 20:12:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0JEWcWdr3IahiOJL4Wed9KQdaOuxFyptN1xdhCH/X0e0iHfbc0yREVBV8uJT5QgtLIaWlNdZEsaQMRVY6LS4OgUhDBYUGWzZa9hlkQA== X-Google-Smtp-Source: AGHT+IG/teG4bS7Ad7BiW+QnsTYEFBl07tWL/dAkdZvcLUS8w/0czbZcKr7qviczScTmWT10YXIX X-Received: by 2002:a5d:58d4:0:b0:341:d765:8715 with SMTP id o20-20020a5d58d4000000b00341d7658715mr1080857wrf.35.1711595559299; Wed, 27 Mar 2024 20:12:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711595559; cv=pass; d=google.com; s=arc-20160816; b=bz9CWXs34eFKDQDGeqGlfo53mpj/Ux1rDYIi8kW6vR/v+vZOyGjf0iim2xTuju61Q8 hUxglmOu3VejDhLgfVRgv64mk8AJAMcsGC/gA8ruSnistZ41gNf26lJrMjI5m8T8Ewcr s8BSVcd9odeQc7zppIzhoBX17aUYaD8wYkL/mFEmnMC1Jezm2ssb7OYo8jaR4Xhd3s5l 8X4IOX8l7MUA7BiTRI/L6YuSWDk8uWwhhHGtTJ5rlREQVSYt22gEDWgtvZrWN9+pcepf EuMXBgxIb9Trg77pZOpDly1DeHXxQNeG6VKWs2IHyGvbBVRQJ5NR2czvEOMgb8QTX2vF 5HuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HICuO/39JB5XZeHzy8jEb95gfkae1H7EuoRgwWgOXjs=; fh=G1r0sJ0F/0v82zumykPUwC7a5Du5vVkWNEWao5ifD3o=; b=kd1J//INXmrqWQjTiFMV5UBtowaVES5XxNY+iX6bsdKZAG2EZwhpqpSKYb9BvvPZ9h /ksmTYk9q0VciMGftq+6tKNMUYeDGzqV+TMek+UMISatFjHaO+lopyI6hM5qhOOp+6Di BwGwhUih4ZJbwlE+ApJyVomXBCQCcGF3vdZa/0m+aGdX+Uq5yUmBgH1T2oW5T/r6N/UC JQyR+mG20x9UwX+iwIRT0OohDhNf/xWgJAqws/D1rnHb0b8OONXxflscg6bHziYmQ93J YP7dG8FwInuo90V6dmqK5WP2/bn511vMvJzQ/PRfRQolduYvLYyEZ2UwbMYzWSQVizqD iuJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ea7Pzo3S; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-122225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122225-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n6-20020a509346000000b0056763d0295dsi272944eda.333.2024.03.27.20.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 20:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ea7Pzo3S; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-122225-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122225-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 41C311F33E1D for ; Thu, 28 Mar 2024 00:25:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B411539FD5; Thu, 28 Mar 2024 00:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ea7Pzo3S" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B99032C1A7; Thu, 28 Mar 2024 00:22:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711585373; cv=none; b=nWAB0rE4ZHSHTkfCAA6aLLcz+ryFXDPPvp+8TOLzF6iNgbU0E8b2C6FN658Ag6nh+5ypXhsOXmivcF2x3jp5kGIx3xUIxo1vqy7RoEM1r/ZE2Of3Q3IkkfxQkS9Rc8YwYMN6e1tWL86O3mwfOJNOssP+ks/6TlaZktzG0zsyO64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711585373; c=relaxed/simple; bh=D8GJmWGrqyOPL7eN3YG5swGQXwtVD67H2VeACexvADs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dD5eeJQC61hUnQX2QIKiCUrGqSm+vDRpzgVRTGvJZEjmTyNG1QhQRBZPDAtOTNu/L1z/Q0J+aadELfOFfoqUre691XwtVjZ2aJ77wo4uAMSv1A7ynii+hDBH7ndmDNY3a3n0vZXIOy/er1PwlVjb4n8eXY0NSdcYPL1TyA9/2n8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ea7Pzo3S; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711585372; x=1743121372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D8GJmWGrqyOPL7eN3YG5swGQXwtVD67H2VeACexvADs=; b=ea7Pzo3SYnvknMg3JOBUoB5m66M1OxbWqPqx46kWLu6rlK3OHSVePaHZ Ftnnc5P7Wmx+2z1E1F6qMEu0lnCbtjzDpprGeS8DMurYgRpEFT5FKd45C JROtw7YbEeuEdIncR/GR4psW9TJKYy0UcuYb87dIKedyfhZqBSkNBwacy J+8hmRPlf7ozptaey7e2rRtXpflSveIcfwz1CLN6NXF2zxX7ZvTKOzbYy hWuXfJqqupCIqq05xzxR2tK5qsHbxVp64wt+ZWAr+baF2AfKldgeKuemL J7NWwQ2akVBArlQ4WPdZN8h1O4NdezXj2RbqiAXCb/+itsSk6/Jny/Q/G Q==; X-CSE-ConnectionGUID: EUvgI1ikQUCW+UEH7VXcTg== X-CSE-MsgGUID: GrMRnBPqTNG1NVki7Mtc5Q== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="6580728" X-IronPort-AV: E=Sophos;i="6.07,160,1708416000"; d="scan'208";a="6580728" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2024 17:22:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,160,1708416000"; d="scan'208";a="16411815" Received: from b4969161e530.jf.intel.com ([10.165.56.46]) by orviesa009.jf.intel.com with ESMTP; 27 Mar 2024 17:22:32 -0700 From: Haitao Huang To: jarkko@kernel.org, dave.hansen@linux.intel.com, kai.huang@intel.com, tj@kernel.org, mkoutny@suse.com, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, x86@kernel.org, cgroups@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sohil.mehta@intel.com, tim.c.chen@linux.intel.com Cc: zhiquan1.li@intel.com, kristen@linux.intel.com, seanjc@google.com, zhanb@microsoft.com, anakrish@microsoft.com, mikko.ylinen@linux.intel.com, yangjie@microsoft.com, chrisyan@microsoft.com Subject: [PATCH v10 11/14] x86/sgx: Abstract check for global reclaimable pages Date: Wed, 27 Mar 2024 17:22:26 -0700 Message-Id: <20240328002229.30264-12-haitao.huang@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240328002229.30264-1-haitao.huang@linux.intel.com> References: <20240328002229.30264-1-haitao.huang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kristen Carlson Accardi To determine if any page available for reclamation at the global level, only checking for emptiness of the global LRU is not adequate when pages are tracked in multiple LRUs, one per cgroup. For this purpose, create a new helper, sgx_can_reclaim(), currently only checks the global LRU, later will check emptiness of LRUs of all cgroups when per-cgroup tracking is turned on. Replace all the checks of the global LRU, list_empty(&sgx_global_lru.reclaimable), with calls to sgx_can_reclaim(). Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V10: - Add comments for the new function. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index c94f8b49e6f2..7f92455d957d 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -37,6 +37,14 @@ static inline struct sgx_epc_lru_list *sgx_lru_list(struct sgx_epc_page *epc_pag return &sgx_global_lru; } +/* + * Check if there is any reclaimable page at global level. + */ +static inline bool sgx_can_reclaim(void) +{ + return !list_empty(&sgx_global_lru.reclaimable); +} + static atomic_long_t sgx_nr_free_pages = ATOMIC_LONG_INIT(0); /* Nodes with one or more EPC sections. */ @@ -391,7 +399,7 @@ unsigned int sgx_reclaim_pages(struct sgx_epc_lru_list *lru, struct mm_struct *c 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(); } static void sgx_reclaim_pages_global(struct mm_struct *charge_mm) @@ -593,7 +601,7 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, enum sgx_reclaim reclaim) break; } - if (list_empty(&sgx_global_lru.reclaimable)) { + if (!sgx_can_reclaim()) { page = ERR_PTR(-ENOMEM); break; } -- 2.25.1