Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3960358pxk; Tue, 22 Sep 2020 07:07:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP5I+NBWnE7BuNatKKQnLTm03uUgDC2Ont7IA4hpZ9hwPigHicTstUQky0PkTQSoz3VjVm X-Received: by 2002:a05:6402:17ed:: with SMTP id t13mr4164992edy.163.1600783649251; Tue, 22 Sep 2020 07:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600783649; cv=none; d=google.com; s=arc-20160816; b=M11gAYwUlj9XVNxJJCbaUt6NI2YJJj73DPDzU1O83F64cw/fpsGMAb1KGG4oqkOjh+ a/hGkr9Ox9U/fQR9mfY5q/Doelffocc1FlkIrDDAyemHPcqMxT6TknzQsYfqOsk42HHp S38i2Q4Iqrt0A5x285QaJAfhLvChElGAcLpjAzZNu6xTdQuJ0C2aX9eH0ktAZ3E6AYDg yRtpyFsjjPAMCDDmQUsZ5eoS9f3kRfid1BFn0LfMBX+q09zX5j/QAV7kb8FFg9PFU014 iOPaoM19GgclqcTIJr0C1iAeyz0fHCh8VQMHv7Rc/xr7MDO6ibpLy9GfcepS4lq/KmA6 bnfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=wGdHtOz/bO+GV0sC/5GxL+uiPg+D1NHuiTGs0uWgMiA=; b=s8bao/CuBiHj75AU0ftbYZIlj8flftjtvRoqzz+bcmqOGEo06btB8pokSoLPmnrqbK GT00k/+DXx+3brNqizF5Nzbi2I7r7eDGXsroL7YpukefK5UCAWocryTG6o86otejJoBn Tpk408Bx7dHGt7Smf/ePvmocsiQVQ5vs3uINcr/wboR/huyR2l72ynD+JgV4I+2ZRyKH btTCCpqzfnWd/rxH1vznPMZIj107FPwz1y0IKydxwWqBwXNrHdDmbvTH8UhCJw3eOWIb Yge1qx6YsJx45CmVWzZdAFffhs5AGLfobbucbX/MUEwXiPLeAuOYbKjeomS35qx5fsgw 3LhA== 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 n11si10515191ejh.372.2020.09.22.07.07.02; Tue, 22 Sep 2020 07:07:29 -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 S1726613AbgIVODi (ORCPT + 99 others); Tue, 22 Sep 2020 10:03:38 -0400 Received: from mga18.intel.com ([134.134.136.126]:38185 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbgIVODh (ORCPT ); Tue, 22 Sep 2020 10:03:37 -0400 IronPort-SDR: gISH8xOQdQgHhDJZhCQEBJTQNtIlshRNdTaBOB0H9o/dLttka2op45rdjUqQHS00r7wu0yRTpT Gh4AxmJMC4/A== X-IronPort-AV: E=McAfee;i="6000,8403,9751"; a="148355521" X-IronPort-AV: E=Sophos;i="5.77,290,1596524400"; d="scan'208";a="148355521" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 07:03:35 -0700 IronPort-SDR: //JSbquJ3crr4TnUhHSTmhoc61lX1lZnrVo/7i0jEjzvAlM9YcztaO3dOz1MyPS+XOyldSh/i7 Jgkt4gJvsYXA== X-IronPort-AV: E=Sophos;i="5.77,290,1596524400"; d="scan'208";a="485970502" Received: from haijindi-mobl.ger.corp.intel.com (HELO localhost) ([10.249.47.132]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 07:03:25 -0700 Date: Tue, 22 Sep 2020 17:03:23 +0300 From: Jarkko Sakkinen To: Borislav Petkov Cc: 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 , Sean Christopherson , 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: <20200922140314.GA164527@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> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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: > > + * %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 > > ... So what's wrong over here? > > @@ -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... > > Also, should the growing happen *after* the SECS validation? Yes, it would make sense. I'll move it. > Let's add some comment blurb about "Write back/invalidate an EPC page" > to at least start to explain what that "ewb" is. OK, I'll try to write something understandable. > > + spin_lock(&sgx_active_page_list_lock); > > + for (i = 0; i < SGX_NR_TO_SCAN; i++) { > > + if (list_empty(&sgx_active_page_list)) > > Isn't it enough to do this once, i.e., not in the loop? You're holding > sgx_active_page_list_lock... I think that would make sense. Distantly analogous to the EINIT discussion. Too complex code for yet to be known problem workloads I'd say. > > static void sgx_sanitize_section(struct sgx_epc_section *section) > > ... Is this about documenting this function? > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette Thanks, this was valuable feedback. /Jarkko