Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1414453rdb; Fri, 16 Feb 2024 15:33:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWLVWM3dvf9ICC1Bxv6kADy9yZjUC1UHZdf0IX4xRgY1L2W8/evz4zlgmTQvmAlgeOPRFYTzctzDBQ32paDhsweWUyDXCpGUPX6o4+VtQ== X-Google-Smtp-Source: AGHT+IH1fqfHot47DyIQGmb6LM6sywiBVqkB0IL5IZygVZ7XQry5zW36PtiXpuFnC7R+VyCKt/JZ X-Received: by 2002:a9d:6b08:0:b0:6e4:34ba:add2 with SMTP id g8-20020a9d6b08000000b006e434baadd2mr3649077otp.5.1708126407254; Fri, 16 Feb 2024 15:33:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708126407; cv=pass; d=google.com; s=arc-20160816; b=JdDmjq74fxeMGWw8ZLYXoe9z27sHCDCQt+BjjO+7KTGsbwdhusFateabYYQjOIX+oO 8fm3rWjUUN3i7I69YJjw7WTZ5lF/CiO64BgWK9e842Xy4aewP+iuhKr6zobXScTr91dm jd+U1EsqeLxgc+39UsM8iAGsxxMenhpSGkIN6/1aB1yC/qEJ4rVZbqaWDN1DFpwZ9beg PZLMwy4Hc/e3saccIfvMyptpUxU/wxZvcisNbHabw1jK4FYqz95EPvlW3GvD/zC4DMHy k4Q/AYl2gdEliw9Rw977inGmOHNw344VlYSW+OZqa3xvnklafhsm1ZarugrpojYtJbf3 TcGQ== 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=vWJBOzjzKSZmovoPc4XO6nEcfcyVoAhAonbp5NleOKc=; fh=r0O0apHiyivtQqi5P5imwHiZ+9a74UMFQzypzdVXr8Q=; b=P/T4ovTtcavMcs7Aq2J5tBpE/+9wNv9nBS+WW1KJ+z2mzqlNDT6otBnBSXBA04SxqA mqoMKh6zlU2ug5EYff+nXmT1d/lO09mf82BlrW4xzIr6DJLbrYC/i9WB6xHcXIu3qJQA UCHsK7w17VqIO/++u8y1QCTWx+n6BeVJ5loTc8u5t5saxyH5qdn+9avIEa6mho9H1/qA NF44iIBpbPpYqouKjjOBmI9zkjjHeuIil8jc5JTQB2Xop25m5vDNoxSSOHrkVBd2LrEp UtHpOaI1D/Ovgaj1Eh1631aSFyRQPR78P0w9U3g1lXRtLzHnW7rS7wGv/e+SJDuHp64Z GkBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QUo9qF9i; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69485-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69485-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 n17-20020a05622a11d100b0042c4e104ec3si1015336qtk.220.2024.02.16.15.33.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:33:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69485-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=QUo9qF9i; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-69485-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69485-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 046BA1C21F75 for ; Fri, 16 Feb 2024 23:33:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04213148FE7; Fri, 16 Feb 2024 23:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QUo9qF9i" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 26F5D146900; Fri, 16 Feb 2024 23:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708126397; cv=none; b=sEZhpthdzidMXgWKcDjjUQbqP4WSeEoNksHVTmrisHBNaTMP1I37D5K5+o5tOAZ50eWKhYGfIa0SCQc566kTIFsvdrswxLxLhubD4LIKHsP7TG2dPWDnDQZuJDYOyssN8cv72yR92+mMfMDPD37/+Srb4zWI9fPBPVwm2o1x9Jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708126397; c=relaxed/simple; bh=Cd475hAGgyuF2aGmyxhl9VvNyX0OKqZk6zOdf4II6mU=; h=Content-Type:To:Cc:Subject:References:Date:MIME-Version:From: Message-ID:In-Reply-To; b=nYvORzbCeYdsKUuCrKpYvnTSURe7N8FgF6gSqWC0wIqX3SmxMs9D0Z3vAoFRfwcf/hLm5tBNTB1naDBhCfRcraoi4b/FTOWAgiXfLokDWO87x4aq+WwJjOhZecSPKFjvSS0TaU0xzOboqkkGVYwdEbaTmFeraJJDymjGFxzbLVA= 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=QUo9qF9i; arc=none smtp.client-ip=192.198.163.11 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=1708126395; x=1739662395; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=Cd475hAGgyuF2aGmyxhl9VvNyX0OKqZk6zOdf4II6mU=; b=QUo9qF9iy1aUfNh5mbCHoP2tqLbREIiMflR2o+kmbvLZMELfyEhVWwGq ajzIAqUASOt75YWZNp4WjyP1iYZUdrwgsTXSHHCXh6HssTAcrhhcYc383 e3Ls45EJWUCKqspGr0cnen93quJQ80YkaDL8MloLMGWK6GBKAOKcagc8z Xcsop8YrIhKakVviEDoBMgfSH7ok4zony49RwB0YsDAik/cPIpZelXjMy i8SDkXJmysLbZHztVcnxIAByxmljEl/O/z4znVzIy08Z66yemEZqZvMQn 6Lu4pqXhhmye2eCXOZQUTW4BpJKTJqBlJJunJAYfsY9zt23SHERoUViiL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10986"; a="12898553" X-IronPort-AV: E=Sophos;i="6.06,165,1705392000"; d="scan'208";a="12898553" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 15:33:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,165,1705392000"; d="scan'208";a="4020035" Received: from hhuan26-mobl.amr.corp.intel.com ([10.92.17.168]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 16 Feb 2024 15:33:10 -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> <0ab99d42-c3fe-4415-b993-57fb1fec21a4@intel.com> Date: Fri, 16 Feb 2024 17:33:07 -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: <0ab99d42-c3fe-4415-b993-57fb1fec21a4@intel.com> User-Agent: Opera Mail/1.0 (Win32) On Fri, 16 Feb 2024 15:55:10 -0600, Dave Hansen wrote: > On 2/16/24 13:38, Haitao Huang wrote: >> On Fri, 16 Feb 2024 09:15:59 -0600, Dave Hansen >> wrote: > ... >>> 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(). > > Right, because there was only one possible way that mm could be NULL but > it wasn't obvious from the code what that way was. > >> 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. > > No, I think that focuses on the symptom and not on the fundamental > problem. > > The fundamental problem is that you need an mm in order to charge your > allocations to the right group. Indirect reclaim means you are not in a > context which is connected to the mm that should be charged while direct > reclaim is. > >>> 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? > > Pass around a: > > struct mm_struct *charge_mm > > Then, at the bottom do: > > /* > * Backing RAM allocations need to be charged to some mm and > * associated cgroup. If this context does not have an mm to > * charge, search the enclave's mm_list to find some mm > * associated with this enclave. > */ > if (!charge_mm) > ... do slow mm lookup > else > return mm_to_cgroup_whatever(charge_mm); > > Then just comment the call sites where the initial charge_mm comes in: > > > /* Indirect SGX reclaim, no mm to charge, so NULL: */ > foo(..., NULL); > > > /* Direct SGX reclaim, charge current mm for allocations: */ > foo(..., current->mm); > > Okay. got it now. Thank you very much! Haitao