Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2868169rdb; Wed, 15 Nov 2023 13:02:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY8iGktUgIDSQYuD4ZcP/6kpNfkV72i4CYmCggi6YotBgv07Kts4oi71cTwQYbcuGI4Onc X-Received: by 2002:a05:620a:d8e:b0:77b:c502:c86e with SMTP id q14-20020a05620a0d8e00b0077bc502c86emr6428168qkl.56.1700082121994; Wed, 15 Nov 2023 13:02:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700082121; cv=none; d=google.com; s=arc-20160816; b=Vb3bBwEDX1fSszw0AaSW5BWpj2SkIJNIq353ZOnJ5rNk7h2Tn5KGFCmSw0yyH3Jwnz w7lSMbj55OKheaaIPfe5h7Hawk/2BBswowYr7tZkg72wJz3y39FGKy+SwI5isfgQtwhE fiCMYb1JEtBZ/yceyxyuOJpZ5GDf3kIM/TZw9NjXmZdLjPZgF4zt3kLKRs9Agx92UEY3 RFtZwZ1dGKjRrw4NtZkPe+nwu6W+84xMrpMQZW08lYlcy/P2TLnrgd8xlql++yyAYsBd ojhWLFTOFpw7C8b98+Y6rjhqL4f37VOFfDKAUx5B8RIpXtS4GRHMemiIDSD2W4YXKKHO zRXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=UbA0Q2xeWEkAkgVir9pg+9jplIMjokobTbmG4jwtkfI=; fh=g2HrtGQ2SKEJjmO4h3B/NWxQLF02BrQLKX946LuMoK4=; b=sayjWPnAhJFLhHMck83YBAFW1IC5uDX5VdmauGqhwLMRSwk//x7437toQbgPc6OBLp XbiDlE6ciMl8z5dv0S43P/b6kgcob2/+awKeD8lbN5gETF91HebM1GoaXFwEqnQ9jzAJ rlCWCpT3PK5FbLjTm9aWIa17P7xsifGpVDnjzQcetzQN9AGTiZGMqSaGGeyYWtyry4Qo 4rbObeam1kW+BgoCveungFiIExL7POR5JQXeya3ueV0uYe9iRQp1uQsSva1lianjXA8h /KlMEDNg/BGg2DytTyfAnZX7A9jLkaSYR2tsowggUqUiVBtDCHwFrqEwHuj4B3Bm/btZ Ki6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXjkHzBV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id ou18-20020a05620a621200b007758709cfefsi9512864qkn.215.2023.11.15.13.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 13:02:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QXjkHzBV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id ADBCE806BE17; Wed, 15 Nov 2023 13:01:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344645AbjKOVAg (ORCPT + 99 others); Wed, 15 Nov 2023 16:00:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235637AbjKOVAV (ORCPT ); Wed, 15 Nov 2023 16:00:21 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F04021FDB; Wed, 15 Nov 2023 12:59:46 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67D51C433D9; Wed, 15 Nov 2023 20:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700081986; bh=cGbVOGrDBir77EpazpzYMNtu/vjZuZ+xwCpP4c+mNjE=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=QXjkHzBV8aNvcErUZuxqfo4cSdxhQuEdcFH5/2XSvlrDdsF+O+tCXCUz3CrkVJz7L 0D8AJz1jc5BQlWGPEJdjpXZSorMzOUWX8ycfttw3ZlCNvew0NplH11NgmQe3eJ8vD7 Ec7kPiIY5O6vULChUallAi9zqmFsFdD8AZLkKtfJaIy3V4LsCT4OKDGzxtZt7DWDrE 9QiHb/sERKYQdu/+vbJR0VOgwjLnsWxwCuzge75XSP7+G1syNuXfSU3pDsHLAi7iiM iPXksBS69hosBqHcsR4ecPZfrRJ1TAuRfknQFRm52VuJNH+6v8IoP4RuQEXftelxkQ GCDLTL0WHU/Jg== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 15 Nov 2023 22:59:40 +0200 Message-Id: Cc: , , , , , , , "Sean Christopherson" Subject: Re: [PATCH v6 08/12] x86/sgx: Use a list to track to-be-reclaimed pages From: "Jarkko Sakkinen" To: "Haitao Huang" , , , , , , , , , , , , X-Mailer: aerc 0.15.2 References: <20231030182013.40086-1-haitao.huang@linux.intel.com> <20231030182013.40086-9-haitao.huang@linux.intel.com> In-Reply-To: <20231030182013.40086-9-haitao.huang@linux.intel.com> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 15 Nov 2023 13:01:42 -0800 (PST) On Mon Oct 30, 2023 at 8:20 PM EET, Haitao Huang wrote: > From: Sean Christopherson > > Change sgx_reclaim_pages() to use a list rather than an array for > storing the epc_pages which will be reclaimed. This change is needed > to transition to the LRU implementation for EPC cgroup support. > > When the EPC cgroup is implemented, the reclaiming process will do a > pre-order tree walk for the subtree starting from the limit-violating > cgroup. When each node is visited, candidate pages are selected from > its "reclaimable" LRU list and moved into this temporary list. Passing a > list from node to node for temporary storage in this walk is more > straightforward than using an array. > > Signed-off-by: Sean Christopherson > Co-developed-by: Kristen Carlson Accardi > Signed-off-by: Kristen Carlson Accardi > Co-developed-by: Haitao Huang > Signed-off-by: Haitao Huang > Cc: Sean Christopherson > --- > V6: > - Remove extra list_del_init and style fix (Kai) > > V4: > - Changes needed for patch reordering > - Revised commit message > > V3: > - Removed list wrappers > --- > arch/x86/kernel/cpu/sgx/main.c | 35 +++++++++++++++------------------- > 1 file changed, 15 insertions(+), 20 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/mai= n.c > index e27ac73d8843..33bcba313d40 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -296,12 +296,11 @@ static void sgx_reclaimer_write(struct sgx_epc_page= *epc_page, > */ > static void sgx_reclaim_pages(void) > { > - struct sgx_epc_page *chunk[SGX_NR_TO_SCAN]; > struct sgx_backing backing[SGX_NR_TO_SCAN]; > + struct sgx_epc_page *epc_page, *tmp; > struct sgx_encl_page *encl_page; > - struct sgx_epc_page *epc_page; > pgoff_t page_index; > - int cnt =3D 0; > + LIST_HEAD(iso); > int ret; > int i; > =20 > @@ -317,7 +316,7 @@ static void sgx_reclaim_pages(void) > =20 > if (kref_get_unless_zero(&encl_page->encl->refcount) !=3D 0) { > sgx_epc_page_set_state(epc_page, SGX_EPC_PAGE_RECLAIM_IN_PROGRESS); > - chunk[cnt++] =3D epc_page; > + list_move_tail(&epc_page->list, &iso); > } else > /* The owner is freeing the page. No need to add the > * page back to the list of reclaimable pages. > @@ -326,8 +325,11 @@ static void sgx_reclaim_pages(void) > } > spin_unlock(&sgx_global_lru.lock); > =20 > - for (i =3D 0; i < cnt; i++) { > - epc_page =3D chunk[i]; > + if (list_empty(&iso)) > + return; > + > + i =3D 0; > + list_for_each_entry_safe(epc_page, tmp, &iso, list) { > encl_page =3D epc_page->owner; > =20 > if (!sgx_reclaimer_age(epc_page)) > @@ -342,6 +344,7 @@ static void sgx_reclaim_pages(void) > goto skip; > } > =20 > + i++; > encl_page->desc |=3D SGX_ENCL_PAGE_BEING_RECLAIMED; > mutex_unlock(&encl_page->encl->lock); > continue; > @@ -349,27 +352,19 @@ static void sgx_reclaim_pages(void) > skip: > spin_lock(&sgx_global_lru.lock); > sgx_epc_page_set_state(epc_page, SGX_EPC_PAGE_RECLAIMABLE); > - list_add_tail(&epc_page->list, &sgx_global_lru.reclaimable); > + list_move_tail(&epc_page->list, &sgx_global_lru.reclaimable); > spin_unlock(&sgx_global_lru.lock); > =20 > kref_put(&encl_page->encl->refcount, sgx_encl_release); > - > - chunk[i] =3D NULL; > - } > - > - for (i =3D 0; i < cnt; i++) { > - epc_page =3D chunk[i]; > - if (epc_page) > - sgx_reclaimer_block(epc_page); > } > =20 > - for (i =3D 0; i < cnt; i++) { > - epc_page =3D chunk[i]; > - if (!epc_page) > - continue; > + list_for_each_entry(epc_page, &iso, list) > + sgx_reclaimer_block(epc_page); > =20 > + i =3D 0; > + list_for_each_entry_safe(epc_page, tmp, &iso, list) { > encl_page =3D epc_page->owner; > - sgx_reclaimer_write(epc_page, &backing[i]); > + sgx_reclaimer_write(epc_page, &backing[i++]); Couldn't you alternatively "&backing[--i]" and not reset i to zero before the loop? > =20 > kref_put(&encl_page->encl->refcount, sgx_encl_release); > sgx_epc_page_reset_state(epc_page); BR, Jarkko