From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDEDC4363D for ; Tue, 22 Sep 2020 16:24:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4BAFA239D2 for ; Tue, 22 Sep 2020 16:24:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BAFA239D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 943816B0099; Tue, 22 Sep 2020 12:24:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F4896B009B; Tue, 22 Sep 2020 12:24:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743006B009D; Tue, 22 Sep 2020 12:24:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 5BAD46B0099 for ; Tue, 22 Sep 2020 12:24:45 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 165771EF1 for ; Tue, 22 Sep 2020 16:24:45 +0000 (UTC) X-FDA: 77291220930.27.river77_2d11c402714f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id E361A3D663 for ; Tue, 22 Sep 2020 16:24:44 +0000 (UTC) X-HE-Tag: river77_2d11c402714f X-Filterd-Recvd-Size: 4812 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 16:24:43 +0000 (UTC) IronPort-SDR: pYccrH8LVCI3TVoWvjSEGrGbG4spQGYy9BTyS9aFZO5XreooHhvSNcgfyEsuOSbJswBn3BnNTY UzWTDDf82F4A== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="158024840" X-IronPort-AV: E=Sophos;i="5.77,291,1596524400"; d="scan'208";a="158024840" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 09:24:40 -0700 IronPort-SDR: wuqh49QQJio1BVTpfU/c7hE0z70Jgl7uxuSoosblsld/K3Pa7LM/WNKsClx4w1yR5Mktgys9zW BQH7r5068EnA== X-IronPort-AV: E=Sophos;i="5.77,291,1596524400"; d="scan'208";a="335081762" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 09:24:39 -0700 Date: Tue, 22 Sep 2020 09:24:38 -0700 From: Sean Christopherson To: Borislav Petkov Cc: Jarkko Sakkinen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jethro Beekman , Jordan Hand , Nathaniel McCallum , Chunyang Hui , Seth Moore , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v38 16/24] x86/sgx: Add a page reclaimer Message-ID: <20200922162437.GA30827@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> <20200915112842.897265-17-jarkko.sakkinen@linux.intel.com> <20200922104538.GE22660@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922104538.GE22660@zn.tnic> User-Agent: Mutt/1.5.24 (2015-08-30) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 22, 2020 at 12:45:38PM +0200, Borislav Petkov wrote: > On Tue, Sep 15, 2020 at 02:28:34PM +0300, Jarkko Sakkinen wrote: > > + * %SGX_ENCL_PAGE_VA_OFFSET_MASK: Holds the offset in the Version Array > > + * (VA) page for a swapped page. > > * %SGX_ENCL_PAGE_ADDR_MASK: Holds the virtual address of the page. > > * > > * The page address for SECS is zero and is used by the subsystem to recognize > > ... > > > @@ -86,24 +123,34 @@ static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs) > > { > > unsigned long encl_size = secs->size + PAGE_SIZE; > > struct sgx_epc_page *secs_epc; > > + struct sgx_va_page *va_page; > > struct sgx_pageinfo pginfo; > > struct sgx_secinfo secinfo; > > struct file *backing; > > long ret; > > > > + va_page = sgx_encl_grow(encl); > > + if (IS_ERR(va_page)) > > + return PTR_ERR(va_page); > > + else if (va_page) > > Not "else" simply? > > AFAICT, sgx_encl_grow() would either return an ERR_PTR or the actual > page... > The "else if" is correct. Version Array (VA) pages have 512 slots that hold metadata for evicted EPC pages, i.e. swapping a page out of the EPC requires a VA slot. For simplicity (LOL), the approach we are taking for initial support is to reserve a VA slot when adding a page to the enclave[*]. In most cases, reserving a slot does not require allocating a new VA page, e.g. to reserve slots 1-511 of the "current" VA page. The if-elif is handling the case where the current VA page is fully reserved and a new one needs to be allocated. The if handles the error, the elif handles success, i.e. if (IS_ERR(va_page)) <- needed a new VA page, allocation failed return PTR_ERR(va_page); else if (va_page) <- needed a new VA page, allocation succeeded list_add(&va_page->list, &encl->va_pages); else <- reused the current VA page When reusing a VA page, we obviously don't want to readd the page to the list of va_pages, and the error handling path also shouldn't free the VA page. > Also, should the growing happen *after* the SECS validation? > > > + list_add(&va_page->list, &encl->va_pages); > > + > > if (sgx_validate_secs(secs)) { > > pr_debug("invalid SECS\n"); > > - return -EINVAL; > > + ret = -EINVAL; > > + goto err_out_shrink; > > }