Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4065555pxk; Tue, 22 Sep 2020 09:26:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlctvhHP2rxIdMI8+2tYbYysLv4jzcvzaAO0frwilTzgo7De8qkcCUZUAsOoV1uzwXdpo8 X-Received: by 2002:a17:907:20e5:: with SMTP id rh5mr5793988ejb.267.1600791966655; Tue, 22 Sep 2020 09:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600791966; cv=none; d=google.com; s=arc-20160816; b=A9W/dtu9IFTaU6GdX37OWFy03SjKqEcNrJN9JvLuZ+lbs4xjQ73gv6krYYq1XNn6TH kp0BuOaHZWPFz9D0Wbh987eBfo1Pdu2VywixSFPUGpKTQWVKP3srxPTLQ6iqIkl01Lgz DADV0I8JZd1rKKWW7VqoPeEBlgfpGN7bmGKAdfWYKXyZi0KtSt+RLkI35ECJ9G87ZjC+ V1hV+a59ktQqj0ZFawjw/zYti5jZrEa/yLQQ9oZrIlwoxHtkO9V5BuqXtBhf5UGs2t1e B7h4xBAGpFsoXeEK8vy+6YCUizvR1/Q6g0AVoK+G3ghzHoqyY9Rywzn0n+InOv1X6TD8 kIqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=fVTPY7H+2DLyIZxEynOOCgCwnBl9bfxzTtgjO7D3VoU=; b=SFHTS0K7iEIuu0mpDSsBVf9s/jF/C3x5dvfGU7+kcDw4XYPFRWSGgTzq7e8P1KM18s aPW510a1YNN+uoDRwVWVBvVIcZ2Q6zh6lZQ+enB1gpROsR4MXZp1DfQ1y8sBXhLGzp5O vjYSUlSIGU/PpgOhsLwFoFUhwfhUUQvOm6VxYsnNmoH6lhiLsA9r+P+VRwiJ+JYEYTJf xkdTPEpSeuTPffpHHA2Wsm9NKabe8+3o/c/hVclqzWv+eUdYtZsKw60rqpCf43/dxi12 4fg9+Z9XlFwZul2mouqjeVaiG4taC7dz/ea2dmgB1cJIUXF6kHYWbqxHNY8Dlqe0TRgh j5dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si8427469eji.297.2020.09.22.09.25.42; Tue, 22 Sep 2020 09:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgIVQYn (ORCPT + 99 others); Tue, 22 Sep 2020 12:24:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:37808 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbgIVQYn (ORCPT ); Tue, 22 Sep 2020 12:24:43 -0400 IronPort-SDR: 7hTIauPfYvYv5uYEyD8OPqvEnLlWxm+mz4R/bfQe8tFBYFw0Fpyeb79PTS9Isw53jubTfugVFd lj7X7STKK+bg== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="158024839" X-IronPort-AV: E=Sophos;i="5.77,291,1596524400"; d="scan'208";a="158024839" 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > > }