Message ID | 20221202183655.3767674-7-kristen@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1015704wrr; Fri, 2 Dec 2022 10:42:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf765yrk53pVKY7kwfPSSppOPRklSYp72gnckp2vKhxeBqmXlISKPiALfFAx+qDK9FsziYAR X-Received: by 2002:a17:90a:9312:b0:218:6f4b:8366 with SMTP id p18-20020a17090a931200b002186f4b8366mr79318644pjo.137.1670006553733; Fri, 02 Dec 2022 10:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670006553; cv=none; d=google.com; s=arc-20160816; b=iDAlGvtOmK75AuJTJ5QA7gZK+U8aFeQC2CIPE9DkGTlthiHJ+2DHqX2TsShDGOGu6s ECWx2TElKKoMsf8Xl7b0aTQox7cmR5FGuLL1jNtku104bz7nqzxaXuoqLkuzj3SMf92K rOqeE/15ejyXKhjLSRZjTvuWyWvvlqyHn5PPwNC92uCyF9tW4up8lqmX/7JO+SHkaB4+ VaGM2/R+e1CfIqQnnn7flVOKAjCK5+k+YfcLsO7vHnM6JpxEYT8Wig8KENMEAtrLgUHP O6/Tr4vY520ATwnXbOffWpj8qItC16RDhdl+dodkQ3ZaTrpQbg9MsbAPiYCtUtA83rP4 52tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ijfOVYEj5nexjtxd0isF62SGW/p2VDBhJ/h3aHOhorg=; b=vzZUjMtGhOLysFUAWy0hjOzRNdULIXaJsAUdrCt12IKIpLLGlJEMGIEUnAiDwWd6lK Vit+QYHSRZUvMSCP4NGL5kOmhsnGdtN1s3EnJW1m1qMz6TF269svMIx/uHYeltaHREnO 9zGgkik2TDH3YMnt4JiJWpijymCRnKVPiLxUrMOo0GaY55hxBkAOXrckdfpG4uSL94hb iJkq16G4N0MH4TRGqoWDC0q4JUKLDu6iZu/dpGwaswkLEjKHUM03yPm572Txr0k4C4iS aidhQ/qZNNkQwslpjrx+F1Phd9fGZbhU0mGYWszUGx25NyNpRLSMEjGoNLTqc5c0RuSJ DHqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CAz3Zzbs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id on17-20020a17090b1d1100b00218de7c19efsi12728624pjb.108.2022.12.02.10.42.20; Fri, 02 Dec 2022 10:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CAz3Zzbs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234377AbiLBShg (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Fri, 2 Dec 2022 13:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbiLBSh2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 2 Dec 2022 13:37:28 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CB3BEFD01; Fri, 2 Dec 2022 10:37:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670006237; x=1701542237; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XCIiHboLqkGB7+8+/nwb/H+5rbZwuSnGijn3+bFrq9g=; b=CAz3ZzbsfFL4r45Kb8TWwr8PKzA1t8wzyJx/28cE3Hdn8bZtqnx0wHuS ls5aJKfjuUErwVsylRzTtV0VMi8+MuELeplpu+EkaCOREQqPT00la9I4N qAMfujU8qsgBFLnVc476RvS22UPjzq02jXqpj2nR2TdokuTC4QXqRuy6W iIlCFQ69I2L4LDaxyzxIw1RSz6hqhj+3EZOxJtGjjFhQVRmUu9M7uU06l UYtUStsYHqVu0wjEDTrQbrfNJTc5IfHF0Ctz0V2VQLT5Qec9NFQSjqmTb RlkooN39AJKywDEjKl3IL8KmNFfVqQ+Sd/PgXgDYWeAbFBz4mmYLIIm/K A==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="314724549" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="314724549" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="713717427" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="713717427" Received: from kcaskeyx-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.251.1.207]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:15 -0800 From: Kristen Carlson Accardi <kristen@linux.intel.com> To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com> Cc: zhiquan1.li@intel.com, Kristen Carlson Accardi <kristen@linux.intel.com>, Sean Christopherson <seanjc@google.com> Subject: [PATCH v2 06/18] x86/sgx: Introduce RECLAIM_IN_PROGRESS flag for EPC pages Date: Fri, 2 Dec 2022 10:36:42 -0800 Message-Id: <20221202183655.3767674-7-kristen@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221202183655.3767674-1-kristen@linux.intel.com> References: <20221202183655.3767674-1-kristen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751128792340349602?= X-GMAIL-MSGID: =?utf-8?q?1751128792340349602?= |
Series |
Add Cgroup support for SGX EPC memory
|
|
Commit Message
Kristen Carlson Accardi
Dec. 2, 2022, 6:36 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com> When selecting pages to be reclaimed from the page pool (sgx_global_lru), the list of reclaimable pages is walked, and any page that is both reclaimable and not in the process of being freed is added to a list of potential candidates to be reclaimed. After that, this separate list is further examined and may or may not ultimately be reclaimed. In order to prevent this page from being removed from the sgx_epc_lru_lists struct in a separate thread by sgx_drop_epc_page(), keep track of whether the EPC page is in the middle of being reclaimed with the addtion of a RECLAIM_IN_PROGRESS flag, and do not delete the page off the LRU in sgx_drop_epc_page() if it has not yet finished being reclaimed. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com> Cc: Sean Christopherson <seanjc@google.com> --- arch/x86/kernel/cpu/sgx/main.c | 15 ++++++++++----- arch/x86/kernel/cpu/sgx/sgx.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-)
Comments
On 12/2/22 10:36, Kristen Carlson Accardi wrote: > When selecting pages to be reclaimed from the page pool (sgx_global_lru), > the list of reclaimable pages is walked, and any page that is both > reclaimable and not in the process of being freed is added to a list of > potential candidates to be reclaimed. After that, this separate list is > further examined and may or may not ultimately be reclaimed. In order > to prevent this page from being removed from the sgx_epc_lru_lists > struct in a separate thread by sgx_drop_epc_page(), keep track of > whether the EPC page is in the middle of being reclaimed with > the addtion of a RECLAIM_IN_PROGRESS flag, and do not delete the page > off the LRU in sgx_drop_epc_page() if it has not yet finished being > reclaimed. This never really comes out and tells us what problem is being addressed.
On Fri, Dec 02, 2022 at 10:36:42AM -0800, Kristen Carlson Accardi wrote: > From: Sean Christopherson <sean.j.christopherson@intel.com> > > When selecting pages to be reclaimed from the page pool (sgx_global_lru), > the list of reclaimable pages is walked, and any page that is both > reclaimable and not in the process of being freed is added to a list of > potential candidates to be reclaimed. After that, this separate list is > further examined and may or may not ultimately be reclaimed. In order > to prevent this page from being removed from the sgx_epc_lru_lists > struct in a separate thread by sgx_drop_epc_page(), keep track of > whether the EPC page is in the middle of being reclaimed with > the addtion of a RECLAIM_IN_PROGRESS flag, and do not delete the page > off the LRU in sgx_drop_epc_page() if it has not yet finished being > reclaimed. > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> > Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com> > Cc: Sean Christopherson <seanjc@google.com> > --- > arch/x86/kernel/cpu/sgx/main.c | 15 ++++++++++----- > arch/x86/kernel/cpu/sgx/sgx.h | 2 ++ > 2 files changed, 12 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c > index ecd7f8e704cc..bad72498b0a7 100644 > --- a/arch/x86/kernel/cpu/sgx/main.c > +++ b/arch/x86/kernel/cpu/sgx/main.c > @@ -305,13 +305,15 @@ static void __sgx_reclaim_pages(void) > > encl_page = epc_page->encl_owner; > > - if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) > + if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) { > + epc_page->flags |= SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; > chunk[cnt++] = epc_page; > - else > + } else { > /* The owner is freeing the page. No need to add the > * page back to the list of reclaimable pages. > */ > epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; > + } > } > spin_unlock(&sgx_global_lru.lock); > > @@ -337,6 +339,7 @@ static void __sgx_reclaim_pages(void) > > skip: > spin_lock(&sgx_global_lru.lock); > + epc_page->flags &= ~SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; > sgx_epc_push_reclaimable(&sgx_global_lru, epc_page); > spin_unlock(&sgx_global_lru.lock); > > @@ -360,7 +363,8 @@ static void __sgx_reclaim_pages(void) > sgx_reclaimer_write(epc_page, &backing[i]); > > kref_put(&encl_page->encl->refcount, sgx_encl_release); > - epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; > + epc_page->flags &= ~(SGX_EPC_PAGE_RECLAIMER_TRACKED | > + SGX_EPC_PAGE_RECLAIM_IN_PROGRESS); > > sgx_free_epc_page(epc_page); > } > @@ -508,7 +512,8 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) > void sgx_record_epc_page(struct sgx_epc_page *page, unsigned long flags) > { > spin_lock(&sgx_global_lru.lock); > - WARN_ON(page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED); > + WARN_ON(page->flags & (SGX_EPC_PAGE_RECLAIMER_TRACKED | > + SGX_EPC_PAGE_RECLAIM_IN_PROGRESS)); > page->flags |= flags; > if (flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) > sgx_epc_push_reclaimable(&sgx_global_lru, page); > @@ -532,7 +537,7 @@ int sgx_drop_epc_page(struct sgx_epc_page *page) > spin_lock(&sgx_global_lru.lock); > if (page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) { > /* The page is being reclaimed. */ > - if (list_empty(&page->list)) { > + if (page->flags & SGX_EPC_PAGE_RECLAIM_IN_PROGRESS) { > spin_unlock(&sgx_global_lru.lock); > return -EBUSY; > } > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h > index ba4338b7303f..37d66bc6ca27 100644 > --- a/arch/x86/kernel/cpu/sgx/sgx.h > +++ b/arch/x86/kernel/cpu/sgx/sgx.h > @@ -30,6 +30,8 @@ > #define SGX_EPC_PAGE_IS_FREE BIT(1) > /* Pages allocated for KVM guest */ > #define SGX_EPC_PAGE_KVM_GUEST BIT(2) > +/* page flag to indicate reclaim is in progress */ > +#define SGX_EPC_PAGE_RECLAIM_IN_PROGRESS BIT(3) > > struct sgx_epc_page { > unsigned int section; > -- > 2.38.1 > I would create: enum sgx_epc_state { SGX_EPC_STATE_READY = 0, SGX_EPC_STATE_RECLAIMER_TRACKED = 1, SGX_EPC_STATE_RECLAIM_IN_PROGRESS = 2, }; I.e. not a bitmask because page should have only one state at a time for any of this to make any sense. We have an FSM, right? And then allocate 2 upper bits to store this information from flags. And probably would make sense to have inline helper functions to setting and getting the state that does the bitshifting and masking shenanigangs. This would be a patch prepending this. In this patch you should then describe in the context of FSM how EPC page moves between these states. With that knowledge we can then reflect the actual code change. The point is not to get right but more like a mindset that we can discuss right or wrong in thee first place so just do your best but don't stress too much. BR, Jarkko
On Thu, 2022-12-08 at 15:46 +0000, Jarkko Sakkinen wrote: > On Fri, Dec 02, 2022 at 10:36:42AM -0800, Kristen Carlson Accardi > wrote: > > From: Sean Christopherson <sean.j.christopherson@intel.com> > > > > When selecting pages to be reclaimed from the page pool > > (sgx_global_lru), > > the list of reclaimable pages is walked, and any page that is both > > reclaimable and not in the process of being freed is added to a > > list of > > potential candidates to be reclaimed. After that, this separate > > list is > > further examined and may or may not ultimately be reclaimed. In > > order > > to prevent this page from being removed from the sgx_epc_lru_lists > > struct in a separate thread by sgx_drop_epc_page(), keep track of > > whether the EPC page is in the middle of being reclaimed with > > the addtion of a RECLAIM_IN_PROGRESS flag, and do not delete the > > page > > off the LRU in sgx_drop_epc_page() if it has not yet finished being > > reclaimed. > > > > Signed-off-by: Sean Christopherson > > <sean.j.christopherson@intel.com> > > Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com> > > Cc: Sean Christopherson <seanjc@google.com> > > --- > > arch/x86/kernel/cpu/sgx/main.c | 15 ++++++++++----- > > arch/x86/kernel/cpu/sgx/sgx.h | 2 ++ > > 2 files changed, 12 insertions(+), 5 deletions(-) > > > > diff --git a/arch/x86/kernel/cpu/sgx/main.c > > b/arch/x86/kernel/cpu/sgx/main.c > > index ecd7f8e704cc..bad72498b0a7 100644 > > --- a/arch/x86/kernel/cpu/sgx/main.c > > +++ b/arch/x86/kernel/cpu/sgx/main.c > > @@ -305,13 +305,15 @@ static void __sgx_reclaim_pages(void) > > > > encl_page = epc_page->encl_owner; > > > > - if (kref_get_unless_zero(&encl_page->encl- > > >refcount) != 0) > > + if (kref_get_unless_zero(&encl_page->encl- > > >refcount) != 0) { > > + epc_page->flags |= > > SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; > > chunk[cnt++] = epc_page; > > - else > > + } else { > > /* The owner is freeing the page. No need > > to add the > > * page back to the list of reclaimable > > pages. > > */ > > epc_page->flags &= > > ~SGX_EPC_PAGE_RECLAIMER_TRACKED; > > + } > > } > > spin_unlock(&sgx_global_lru.lock); > > > > @@ -337,6 +339,7 @@ static void __sgx_reclaim_pages(void) > > > > skip: > > spin_lock(&sgx_global_lru.lock); > > + epc_page->flags &= > > ~SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; > > sgx_epc_push_reclaimable(&sgx_global_lru, > > epc_page); > > spin_unlock(&sgx_global_lru.lock); > > > > @@ -360,7 +363,8 @@ static void __sgx_reclaim_pages(void) > > sgx_reclaimer_write(epc_page, &backing[i]); > > > > kref_put(&encl_page->encl->refcount, > > sgx_encl_release); > > - epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; > > + epc_page->flags &= ~(SGX_EPC_PAGE_RECLAIMER_TRACKED > > | > > + > > SGX_EPC_PAGE_RECLAIM_IN_PROGRESS); > > > > sgx_free_epc_page(epc_page); > > } > > @@ -508,7 +512,8 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) > > void sgx_record_epc_page(struct sgx_epc_page *page, unsigned long > > flags) > > { > > spin_lock(&sgx_global_lru.lock); > > - WARN_ON(page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED); > > + WARN_ON(page->flags & (SGX_EPC_PAGE_RECLAIMER_TRACKED | > > + SGX_EPC_PAGE_RECLAIM_IN_PROGRESS)); > > page->flags |= flags; > > if (flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) > > sgx_epc_push_reclaimable(&sgx_global_lru, page); > > @@ -532,7 +537,7 @@ int sgx_drop_epc_page(struct sgx_epc_page > > *page) > > spin_lock(&sgx_global_lru.lock); > > if (page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) { > > /* The page is being reclaimed. */ > > - if (list_empty(&page->list)) { > > + if (page->flags & SGX_EPC_PAGE_RECLAIM_IN_PROGRESS) > > { > > spin_unlock(&sgx_global_lru.lock); > > return -EBUSY; > > } > > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h > > b/arch/x86/kernel/cpu/sgx/sgx.h > > index ba4338b7303f..37d66bc6ca27 100644 > > --- a/arch/x86/kernel/cpu/sgx/sgx.h > > +++ b/arch/x86/kernel/cpu/sgx/sgx.h > > @@ -30,6 +30,8 @@ > > #define SGX_EPC_PAGE_IS_FREE BIT(1) > > /* Pages allocated for KVM guest */ > > #define SGX_EPC_PAGE_KVM_GUEST BIT(2) > > +/* page flag to indicate reclaim is in progress */ > > +#define SGX_EPC_PAGE_RECLAIM_IN_PROGRESS BIT(3) > > > > struct sgx_epc_page { > > unsigned int section; > > -- > > 2.38.1 > > > > I would create: > > enum sgx_epc_state { > SGX_EPC_STATE_READY = 0, > SGX_EPC_STATE_RECLAIMER_TRACKED = 1, > SGX_EPC_STATE_RECLAIM_IN_PROGRESS = 2, > }; > > I.e. not a bitmask because page should have only one state at > a time for any of this to make any sense. We have an FSM, > right? > I can experiment with it and see if it can work for the flags to represent a state machine. They don't work like that right now obviously, since you can have both RECLAIMER_TRACKED and RECLAIM_IN_PROGRESS set at the same time. > And then allocate 2 upper bits to store this information from > flags. > > And probably would make sense to have inline helper functions > to setting and getting the state that does the bitshifting and > masking shenanigangs. > > This would be a patch prepending this. > > In this patch you should then describe in the context of FSM > how EPC page moves between these states. With that knowledge > we can then reflect the actual code change. > > The point is not to get right but more like a mindset that we > can discuss right or wrong in thee first place so just do your > best but don't stress too much. > > BR, Jarkko
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index ecd7f8e704cc..bad72498b0a7 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -305,13 +305,15 @@ static void __sgx_reclaim_pages(void) encl_page = epc_page->encl_owner; - if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) + if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) { + epc_page->flags |= SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; chunk[cnt++] = epc_page; - else + } else { /* The owner is freeing the page. No need to add the * page back to the list of reclaimable pages. */ epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; + } } spin_unlock(&sgx_global_lru.lock); @@ -337,6 +339,7 @@ static void __sgx_reclaim_pages(void) skip: spin_lock(&sgx_global_lru.lock); + epc_page->flags &= ~SGX_EPC_PAGE_RECLAIM_IN_PROGRESS; sgx_epc_push_reclaimable(&sgx_global_lru, epc_page); spin_unlock(&sgx_global_lru.lock); @@ -360,7 +363,8 @@ static void __sgx_reclaim_pages(void) sgx_reclaimer_write(epc_page, &backing[i]); kref_put(&encl_page->encl->refcount, sgx_encl_release); - epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED; + epc_page->flags &= ~(SGX_EPC_PAGE_RECLAIMER_TRACKED | + SGX_EPC_PAGE_RECLAIM_IN_PROGRESS); sgx_free_epc_page(epc_page); } @@ -508,7 +512,8 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) void sgx_record_epc_page(struct sgx_epc_page *page, unsigned long flags) { spin_lock(&sgx_global_lru.lock); - WARN_ON(page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED); + WARN_ON(page->flags & (SGX_EPC_PAGE_RECLAIMER_TRACKED | + SGX_EPC_PAGE_RECLAIM_IN_PROGRESS)); page->flags |= flags; if (flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) sgx_epc_push_reclaimable(&sgx_global_lru, page); @@ -532,7 +537,7 @@ int sgx_drop_epc_page(struct sgx_epc_page *page) spin_lock(&sgx_global_lru.lock); if (page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) { /* The page is being reclaimed. */ - if (list_empty(&page->list)) { + if (page->flags & SGX_EPC_PAGE_RECLAIM_IN_PROGRESS) { spin_unlock(&sgx_global_lru.lock); return -EBUSY; } diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index ba4338b7303f..37d66bc6ca27 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -30,6 +30,8 @@ #define SGX_EPC_PAGE_IS_FREE BIT(1) /* Pages allocated for KVM guest */ #define SGX_EPC_PAGE_KVM_GUEST BIT(2) +/* page flag to indicate reclaim is in progress */ +#define SGX_EPC_PAGE_RECLAIM_IN_PROGRESS BIT(3) struct sgx_epc_page { unsigned int section;