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=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 85BB3C4CEC9 for ; Tue, 17 Sep 2019 23:05:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5ACEE216C8 for ; Tue, 17 Sep 2019 23:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727465AbfIQXFT (ORCPT ); Tue, 17 Sep 2019 19:05:19 -0400 Received: from mga02.intel.com ([134.134.136.20]:38081 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727208AbfIQXFT (ORCPT ); Tue, 17 Sep 2019 19:05:19 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Sep 2019 16:05:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,518,1559545200"; d="scan'208";a="191539280" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga006.jf.intel.com with ESMTP; 17 Sep 2019 16:05:18 -0700 Date: Tue, 17 Sep 2019 16:05:18 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org, Shay Katz-zamir , Serge Ayoun Subject: Re: [PATCH v3 16/17] x86/sgx: Introduce sgx_encl_get_backing() Message-ID: <20190917230518.GD10319@linux.intel.com> References: <20190916101803.30726-1-jarkko.sakkinen@linux.intel.com> <20190916101803.30726-17-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190916101803.30726-17-jarkko.sakkinen@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org On Mon, Sep 16, 2019 at 01:18:02PM +0300, Jarkko Sakkinen wrote: > Since __sgx_encl_eldu() and __sgx_encl_ewb() pin the backing storage in the > same way, consolidate this to sgx_encl_get_backing() replacing > sgx_encl_get_backing_page(). > > Cc: Sean Christopherson > Cc: Shay Katz-zamir > Cc: Serge Ayoun > Signed-off-by: Jarkko Sakkinen > --- > arch/x86/kernel/cpu/sgx/encl.c | 86 +++++++++++++++++++------------ > arch/x86/kernel/cpu/sgx/encl.h | 20 +++---- > arch/x86/kernel/cpu/sgx/reclaim.c | 39 ++++---------- > 3 files changed, 71 insertions(+), 74 deletions(-) > > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c > index 66762b9c1517..a71414ce05b1 100644 > --- a/arch/x86/kernel/cpu/sgx/encl.c > +++ b/arch/x86/kernel/cpu/sgx/encl.c > @@ -17,11 +17,8 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page, > unsigned long va_offset = SGX_ENCL_PAGE_VA_OFFSET(encl_page); > struct sgx_encl *encl = encl_page->encl; > struct sgx_pageinfo pginfo; > - unsigned long pcmd_offset; > - struct page *backing; > + struct sgx_backing b; > pgoff_t page_index; > - pgoff_t pcmd_index; > - struct page *pcmd; > int ret; > > if (secs_page) > @@ -29,24 +26,14 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page, > else > page_index = PFN_DOWN(encl->size); > > - pcmd_index = sgx_pcmd_index(encl, page_index); > - pcmd_offset = sgx_pcmd_offset(page_index); > - > - backing = sgx_encl_get_backing_page(encl, page_index); > - if (IS_ERR(backing)) { > - ret = PTR_ERR(backing); > - goto err_backing; > - } > - > - pcmd = sgx_encl_get_backing_page(encl, pcmd_index); > - if (IS_ERR(pcmd)) { > - ret = PTR_ERR(pcmd); > - goto err_pcmd; > - } > + ret = sgx_encl_get_backing(encl, page_index, &b); > + if (ret) > + return ret; > > pginfo.addr = SGX_ENCL_PAGE_ADDR(encl_page); > - pginfo.contents = (unsigned long)kmap_atomic(backing); > - pginfo.metadata = (unsigned long)kmap_atomic(pcmd) + pcmd_offset; > + pginfo.contents = (unsigned long)kmap_atomic(b.contents); > + pginfo.metadata = (unsigned long)kmap_atomic(b.pcmd) + > + b.pcmd_offset; > > if (secs_page) > pginfo.secs = (u64)sgx_epc_addr(secs_page); > @@ -62,15 +49,12 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page, > ret = -EFAULT; > } > > - kunmap_atomic((void *)(unsigned long)(pginfo.metadata - pcmd_offset)); > + kunmap_atomic((void *)(unsigned long)(pginfo.metadata - b.pcmd_offset)); > kunmap_atomic((void *)(unsigned long)pginfo.contents); > > - put_page(pcmd); > + put_page(b.pcmd); > + put_page(b.contents); If we're going to have sgx_encl_get_backing(), it should be paired with sgx_encl_put_backing(), e.g. it's not immediately obvious whose doing the "get page" corresponding to the put_page() calls.