Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1369619rdb; Fri, 16 Feb 2024 13:38:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV2BFwvPI5JTSJmjd9eslYZVDn765eze/yLM9sGSbuAybK7GLjMo9bCgPCQFPvFoL7c3pvT3XC6zNSI7Fe6QJKZkIsTQdrWAWsLl2Jdlg== X-Google-Smtp-Source: AGHT+IEk7ua7yu74BFDth6jnN+k4rU3nmM97UDp5HZILU9x+xdcZtLndWKsFK3SQ7meYyjT6iAzU X-Received: by 2002:a0c:dd87:0:b0:68f:d8c:5c8 with SMTP id v7-20020a0cdd87000000b0068f0d8c05c8mr5790614qvk.10.1708119529909; Fri, 16 Feb 2024 13:38:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708119529; cv=pass; d=google.com; s=arc-20160816; b=rf5z00ELJWlkt6JjaqK7eeGK8JaiqmFn0wsXVNpXOSxUrSZD+UYY5v81Ue5JmGHUG4 1o2pyP61ZkR4kI16mJJm1S7uKqKrOiyTVyVOUTvn5UJ317sEjyJBIKtOXPKgXKclnn0l j2gjBiiozADIX2qDOeB82zbwS/Hp0GWbJEkpKnAeawCknSgC/JrrUCcxQVaP/cPHjhcr LRHBkkCvJKye+btvSG4H5g2Suvga3n+BcGQm540+pOd3OGUgfSidr9RsteCHNeOVOqV5 ZkTEa+SOEIJ4dHDgSjsNLsFjYPrEtGpodNpy14LWmuYUuKNifwRie3Y+tBXO8yCKGd5z M3zw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:message-id:organization:from :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:references:subject:cc:to :dkim-signature; bh=omkchZwC57+rc7mhyYoHiNIYaLdGmlL5w+O8K/HzasE=; fh=r0O0apHiyivtQqi5P5imwHiZ+9a74UMFQzypzdVXr8Q=; b=C4gxbHbUdNNPsolwlJ+t5TUwUpFyMo5BX4+Y5FcgyASc/mUjtky5jdruDGsJsw+vqO /48e09mPn4MA5fWYHbQZWeNGcAaI5tsH6/NdZytC1YwrHn4KxYm9IAUQ6Z2QZDa7ooK9 dsCLCgRKd9QAAh7giKVmAiisglLsGKQEKJ3bDGwKM7tIgEyOCWUzOG3MGrNWwcfXcjzq 4qNkXKjwQnKjHNqnfLOGaYAzR3b+DOov63UinMUs2AIAe0Bea2I6AOHop+KzP86wFobh V/txcsH2HCWFyu6x2F2bLXpekw5fYBFau9nRcX50WUbeIrZtIqMr1pWMwNTnsuyR3dha fMnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Jz/5jP5i"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jz8-20020a0562140e6800b0068c8aaec623si689070qvb.81.2024.02.16.13.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 13:38:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Jz/5jP5i"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69369-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7E09E1C21240 for ; Fri, 16 Feb 2024 21:38:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D25511468ED; Fri, 16 Feb 2024 21:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Jz/5jP5i" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 F2E7A136658; Fri, 16 Feb 2024 21:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708119521; cv=none; b=OEPEleSo96R/2QlSSz4EUVDEYe3UIvU4a+GJKEqE6jtbkxSD/0A0loutrPla7IW74Up+mZp3A8t6NPWaMAmDsZyLsOgoLm2Of1bgZI+rGtPjRU23f9mm7PsA8SAhU2VWsoNZCkZlAA5F9B+HUrrgtX9iHpFnwKzUyVetcXKyZ1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708119521; c=relaxed/simple; bh=/03tnYSZHlsXQ79nRDv6eIA74CKPn0RoZElqyfXPpq0=; h=Content-Type:To:Cc:Subject:References:Date:MIME-Version:From: Message-ID:In-Reply-To; b=XcjYOwpRjByC6M/G+Lvbsivsmg4kbUIOMB1eIC4Hpk2TvlxtH9kEUVQDk3qjqHi3UIhc20oRRPcP/1DfDDETXYhCrFpNMIXok5env5LEMFily/nOFDr+AgQIgm5dFiGlRHqmdFZpTroggnjhxmFBCqOsXqJPgPz4bZ+H5cFgoZ4= 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=Jz/5jP5i; arc=none smtp.client-ip=192.198.163.10 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=1708119519; x=1739655519; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=/03tnYSZHlsXQ79nRDv6eIA74CKPn0RoZElqyfXPpq0=; b=Jz/5jP5iADifMxbcEZmEZdFyVbIzuNWzuy9EjyDW70qfNvE+z9UPNxzI 9Rfg1AwdWwC3QKwnJU+e+k7Bn1UWs23y8WzNeO0VnUjS7YKmAY3nGv/p9 NardYOQxoE0C1IDdVA/9ndaXGOIVo6FeMQp+ssuz4WJMMNAbZPOQ2EHVf xeIKpLi8BXChUHbFt5LSnZYuYF+3QYTkG3WWFpBwRULXH1AQ06zPkLwlu zJRCHaskskgh79qF2SB24SYlu5gBbRoILO+3nCV0PEN2Ksfmd0e+2X/93 nm+B75CqFS4nOb1eFzcIMyYYGJXZDwFIGiLDx7/N9TmMKNXpKQdvfhvsr Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="13657967" X-IronPort-AV: E=Sophos;i="6.06,165,1705392000"; d="scan'208";a="13657967" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 13:38:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,165,1705392000"; d="scan'208";a="8548746" Received: from hhuan26-mobl.amr.corp.intel.com ([10.92.17.168]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 16 Feb 2024 13:38:34 -0800 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: jarkko@kernel.org, dave.hansen@linux.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, "Dave Hansen" 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: Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation References: <20240205210638.157741-1-haitao.huang@linux.intel.com> <20240205210638.157741-10-haitao.huang@linux.intel.com> Date: Fri, 16 Feb 2024 15:38:32 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Haitao Huang" Organization: Intel Message-ID: In-Reply-To: User-Agent: Opera Mail/1.0 (Win32) On Fri, 16 Feb 2024 09:15:59 -0600, Dave Hansen wrote: > On 2/5/24 13:06, Haitao Huang wrote: >> @@ -414,7 +416,7 @@ static void sgx_reclaim_pages_global(void) >> void sgx_reclaim_direct(void) >> { >> if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) >> - sgx_reclaim_pages_global(); >> + sgx_reclaim_pages_global(false); >> } >> >> static int ksgxd(void *p) >> @@ -437,7 +439,7 @@ static int ksgxd(void *p) >> sgx_should_reclaim(SGX_NR_HIGH_PAGES)); >> >> if (sgx_should_reclaim(SGX_NR_HIGH_PAGES)) >> - sgx_reclaim_pages_global(); >> + sgx_reclaim_pages_global(true); >> >> cond_resched(); >> } > > First, I'm never a fan of random true/false or 0/1 arguments to > functions like this. You end up having to go look at the called > function to make any sense of it. You can either do an enum, or some > construct like this: > > if (sgx_should_reclaim(SGX_NR_HIGH_PAGES)) { > bool indirect = true; > sgx_reclaim_pages_global(indirect); > } > > Yeah, it takes a few more lines but it saves you having to comment the > thing. > > Does this 'indirect' change any behavior other than whether it does a > search for an mm to find a place to charge the backing storage? No. > Instead of passing a flag around, why not just pass the mm? > There is no need to pass in mm. We could just check if current->mm == NULL for the need of doing the search in the enclave mm list. But you had a concern [1] that the purpose was not clear hence suggested current_is_ksgxd(). Would it be OK if we replace current_is_ksgxd() with (current->flags & PF_KTHREAD)? That would express the real intent of checking if calling context is not in a user context. > This refactoring out of 'indirect' or passing the mm around really wants > to be in its own patch anyway. > Looks like I could do: 1) refactoring of 'indirect' value/enum suggested above. This seems the most straightforward without depending on any assumptions of other kernel code. 2) replace current_is_ksgxd() with current->mm == NULL. This assumes kthreads has no mm. 3) replace current_is_ksgxd() with current->flags & PF_KTHREAD. This is direct use of the flag PF_KTHREAD, so it should be better than #2? Any preference or further thoughts? Thanks Haitao [1] https://lore.kernel.org/linux-sgx/9c269c70-35fe-a1a4-34c9-b1e62ab3bb3b@intel.com/