Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2820115rdb; Mon, 12 Feb 2024 19:22:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWlB+dkERgcfFgirke9OS7vk4HVrGdj28MH5QGRfR2Aw64z36a1C43gjSGMFLIyIGPD3Wj/IXxOnN1sZkdS8uwbYNT71YZdGXJfRnCHqw== X-Google-Smtp-Source: AGHT+IGsHeCjJiGTZuhwsXSzjLYH/fcCuuIoG2x0ao3fT8cTIBNKL+4ivV3Dy2cUlQh4Aa6MsgQ3 X-Received: by 2002:a17:906:e916:b0:a3b:b947:af77 with SMTP id ju22-20020a170906e91600b00a3bb947af77mr5311119ejb.67.1707794527359; Mon, 12 Feb 2024 19:22:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707794527; cv=pass; d=google.com; s=arc-20160816; b=sEAXpNoJ8BKyPEa8gXVr0v2Bdr3VjbF9eJur3jpqtmaQlocUtW+efFopmD62aPT/HJ tDuc4Ydug2BQIoKJuihvHr/6cE5qnuy80D8NyDwMtpclX5sovLumwNg2DpgBOJMOjZKG J0HVma+EbMHNRfBFtUUmJBg6owPT7gGhWcnVYCbhiqhLx2ao0YrcbjHnoj7lEmIh6ZCk kesf4h7jApuqmOhlqVsE/IT9LDbCxUISZEZfM++R4enLgc+YsmiDw5yeqnHJwCVvkJc+ PIxZzT//wlQgRtqufCeWdWZiqVCGPWvzxGRa14qg9mU0vYCOtfEOLri+XfAErbWEHswq w+ZQ== 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=ODd3QtNeXI0lOgwYUwMgd0oIdJCK9PKD8jCM0NB1vp8=; fh=FE73ZZ6ntUAoEjRGLujphMR6MjFZ5yeIq/S8qGTn1ME=; b=zTQUjyMj7GcxImP8+i/w8p+62mxRD2QbeA+/L+B5ox1Lu40ZSPLFT4nCUaVnntQPIK m5QhIctggSwh6t9zocceaHMXTuaEYyB/dII1CF11Rm2HGP7wG+KdG3Wa4i5sU+7XGVep 1qupPlWraUim+vrARSsZGK8ud1cMHFQ2HV5oI12Z/m5USW6CELv+Phug3u+Qw889s9B/ ImnQwhRtAN2tbXEcf2OTEfGA2auf14ZlUDoQuED+PIy6gzGlIPi9ishYQtpfI3/rfFJJ V3AE1FbQR0xPcUmx0pc+yB/OgoBdOf4PtBGUyAO2ZSriXNBXbns0+DsZZdFRbBkcxRYG To8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WD7+87SC; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62906-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVEuxAaBQs9D8jrqOwP1A54i/0vL7TMJ57aTjE9uL7rBetoNB9RfGCjyGS/VMz+5vQO/16IwybBtkZjbbgdWIxJYDRRb2qLeDEhBkOc4g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hq32-20020a1709073f2000b00a3bacd5a868si874783ejc.598.2024.02.12.19.22.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 19:22:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WD7+87SC; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62906-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 AE0291F22EDD for ; Tue, 13 Feb 2024 03:22:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C708A92E; Tue, 13 Feb 2024 03:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WD7+87SC" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 C2E278BFC; Tue, 13 Feb 2024 03:21:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707794513; cv=none; b=G+iyDHQVoI4H1+yHjOpaQrQJGvEGAXEIcIx4mWOLuU6pPgi0M4dBh1Hc86pHDT8CbRQ2b9NTFn3OjUMFk7bv/fhzS7ZbQtDkWWohZfd3W+oweZMk7ftoKUohDTRhKYRLxH82O+iDd0lPCCA/uxbAKTXdZyUvK2VI7t9Uaaz0rdw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707794513; c=relaxed/simple; bh=COC+DgrRwbOsMKFiXhxGIvmheeowK1HumSOtDo0gkkc=; h=Content-Type:To:Cc:Subject:References:Date:MIME-Version:From: Message-ID:In-Reply-To; b=SepHE84sR4B1OX9KprxyEAtecCGsViJD2ihd0frR1RHpY3CD7AO73z+XxigyhxlydqXs3+rxW+3ZIu65nH4NhE27dESZR+UUzQl6nRqoHDHvlQHzP8Lnr02DcQrKdo/Jv82JTjVg0oGZGbrM+u9wbKGvSivzEEG2KsVuTITwHHM= 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=WD7+87SC; arc=none smtp.client-ip=198.175.65.16 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=1707794512; x=1739330512; h=to:cc:subject:references:date:mime-version: content-transfer-encoding:from:message-id:in-reply-to; bh=COC+DgrRwbOsMKFiXhxGIvmheeowK1HumSOtDo0gkkc=; b=WD7+87SCjTdrGx6z19Nt0fti1JFFp0jyyzOu7Ma53VCv0Pt6BflsmpSB 3d3VbhfIpsGi0p+lby9avWFhN+uE7SuRQN9YdU2NbFNMzBpCRN4JGPxTb DS9xqQjT6U/3Eyze9hx003+5ywDvxiAGPTis216KUeypUpA8PcJHXQdrJ nxIPR1a204Arj1FzwwQwscMPpPW6IhVmdT/AssHJaa5S63A8c08Xzsxai 0gkgvsBailO0b3/Bab3pc+fMXKs3dOa4pQb72AQCLwqfIoNJfIJfwH/Mv 5DGzQiovCnMrjDBQL6pdJMZFJvo4YYKnMiJV6wEWPEOKkXDh+VX2brUrx g==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="1944980" X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="1944980" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 19:21:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="7402632" Received: from hhuan26-mobl.amr.corp.intel.com ([10.92.17.168]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 12 Feb 2024 19:21:49 -0800 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: 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, "Jarkko Sakkinen" 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: Mon, 12 Feb 2024 21:21:47 -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 Mon, 12 Feb 2024 13:46:06 -0600, Jarkko Sakkinen wrote: > On Mon Feb 5, 2024 at 11:06 PM EET, Haitao Huang wrote: >> Enclave Page Cache(EPC) memory can be swapped out to regular system > > "Enclave Page Cache (EPC)" > ~ > Will fix. [...] >> int sgx_encl_alloc_backing(struct sgx_encl *encl, unsigned long >> page_index, >> - struct sgx_backing *backing) >> + struct sgx_backing *backing, bool indirect) > > Boolean parameters should be avoided when possible because they confuse > in the call sites. > >> { >> - struct mem_cgroup *encl_memcg = sgx_encl_get_mem_cgroup(encl); >> - struct mem_cgroup *memcg = set_active_memcg(encl_memcg); >> + struct mem_cgroup *encl_memcg; >> + struct mem_cgroup *memcg; >> int ret; >> >> - ret = __sgx_encl_get_backing(encl, page_index, backing); >> + if (!indirect) >> + return __sgx_encl_get_backing(encl, page_index, backing); > > If a call is either in heead or tail of the code block, then > obviously better option is to make __sgx_encl_get_backing() > as non-static sgx_encl_get_backing() and call it in those > call sites that would call this with "false". > > I.e. you need a new patch where this preparation is done. > This would actually require more intrusive changes to the call stack for global and cgroup reclaim: {sgx_epc_cgroup_reclaim_pages(),sgx_reclaim_pages_global()}->sgx_reclaim_pages()[->sgx_reclaimer_write()]->sgx_encl_alloc_backing() We need make two versions of each of those functions. It'd be especially complicated in refactoring sgx_reclaim_pages() for two versions. I now double checked the history of current_is_ksgxd()[1], it seemed the intent was to replace "current->mm == NULL" criteria so it is more obvious we are running in ksgxd. @Dave, @Kristen, Can we restore the original criteria like below so it works for the cgroup work-queues? bool current_is_ksgxd(void) { return current == ksgxd_tsk; } ---> bool current_is_kthread(void) { return current->mm == NULL; } I'm not experienced in this area and not sure how reliable it is to use current->mm == NULL for kthread and work-queues. But it would eliminate the need for the boolean parameter. Would appreciate the input. Haitao [1]https://lore.kernel.org/linux-sgx/9c269c70-35fe-a1a4-34c9-b1e62ab3bb3b@intel.com/