Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3197460imu; Mon, 17 Dec 2018 15:18:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/X3aBwveR5+4KibsADfsEBHmY0fXT9E3+FZCp2UbZlCpBN3gbmLk/67kSq9i+LQEyMZhR9d X-Received: by 2002:a17:902:8484:: with SMTP id c4mr13954201plo.59.1545088691916; Mon, 17 Dec 2018 15:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545088691; cv=none; d=google.com; s=arc-20160816; b=uZZuNYxHE/LqB8JAz0sq8r6JYqgK2TTdJkK1XVE2EL1gOGc9C/pd4BNoyM31T4+lBM hF+FUFgU2uSE5yDN4aDQyLsAAx6UNxbJfyD/lIiXr563B/DLZvq7vh+yheOPEJO3H5dD GYMIYb/8+KV9Vd9B7esTQApjVde+66Q1l/g+h1o3hbdiqI9YeE2eQNvBw8VnErS/NHOm ggBAYMz9yazV/1Gf7qQNVElD5FF8aneADi3gJ+kHztiujZroHnwVAmKnIyB+2eKeeq+I zBAO2wv+EE7PSL+I3VnrpsJVliVA6Qrt8PJCtW7T5bPugwcGLWyyqUgu7y7dDN5VKhnO w6cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lIe6vTXUKhprXzqbOPurynY9GRGgxY4h5QuvMo6FtNc=; b=zSnk/aoZS9cfh7eNpYB5XQm8cWW+2F7QJq1HxpEKQK8x1y2TUmwOlZXiB4CV9ONj9D wc5Q9eou/dlOFU9FD2yb2zLawQo/T4Va3rtdjVhX5ciFXoRBbPu8s1RtmYTVm6gmGR1I CmWrxCxaOeLcJx7mqPnaiB0T7lGkkCcYb6Xnw8B2zkH5hdFEuiBfaD45tbmF6DYnuB6q SuNFOornMP1ZuIdW/nLr7JYpxci2gThWarWnpsu9hi0S3WLWdTYeRVA/W9uhihQxZEvg eO+UMfTuCey/A8p0nVMKzd51+/VdwQX6pEswQrP1wScbfJkghscDlmI+XMPiXbhHti3h AcPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b5si11316396plr.355.2018.12.17.15.17.57; Mon, 17 Dec 2018 15:18:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2388135AbeLQThF (ORCPT + 99 others); Mon, 17 Dec 2018 14:37:05 -0500 Received: from mga01.intel.com ([192.55.52.88]:42828 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeLQThF (ORCPT ); Mon, 17 Dec 2018 14:37:05 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 11:37:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,366,1539673200"; d="scan'208";a="304565982" Received: from quwen-mobl.ccr.corp.intel.com (HELO localhost) ([10.249.254.215]) by fmsmga005.fm.intel.com with ESMTP; 17 Dec 2018 11:36:57 -0800 Date: Mon, 17 Dec 2018 21:36:56 +0200 From: Jarkko Sakkinen To: Sean Christopherson Cc: "Dr. Greg" , Andy Lutomirski , Andy Lutomirski , X86 ML , Platform Driver , linux-sgx@vger.kernel.org, Dave Hansen , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, haitao.huang@linux.intel.com, Andy Shevchenko , Thomas Gleixner , "Svahn, Kai" , mark.shanahan@intel.com, Suresh Siddha , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , LKML , jethro@fortanix.com Subject: Re: [PATCH v17 18/23] platform/x86: Intel SGX driver Message-ID: <20181217193656.GB29785@linux.intel.com> References: <20181214235917.GA14049@wind.enjellic.com> <20181215000627.GA5799@linux.intel.com> <20181217132859.GA31936@linux.intel.com> <20181217133928.GA32706@linux.intel.com> <20181217140811.GA4601@linux.intel.com> <20181217173106.GB12491@linux.intel.com> <20181217174935.GA12617@linux.intel.com> <20181217180957.GC12491@linux.intel.com> <20181217182319.GA13288@linux.intel.com> <20181217184625.GE12491@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181217184625.GE12491@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 17, 2018 at 10:46:25AM -0800, Sean Christopherson wrote: > On Mon, Dec 17, 2018 at 08:23:19PM +0200, Jarkko Sakkinen wrote: > > On Mon, Dec 17, 2018 at 10:09:57AM -0800, Sean Christopherson wrote: > > > No, EREMOVE should never fail if the enclave is being released, i.e. all > > > references to the enclave are gone. And failure during sgx_encl_release() > > > means we leaked an EPC page, which warrants a WARN. > > > > Right that what I was suspecting as swapper should hold a ref to the > > enclave while it is working on it. It is a programming error when this > > happens. > > > > Maybe change the boolean parameter to flags parameter have a flag to > > use sgx_free_page()? > > I tried that approach when I first split it to __sgx_free_page() and > sgx_free_page(), but IMO the code is more difficult to read and harder > to maintain since sgx_free_page() should be used except under special > circumstances, e.g. race with reclaim or the freeing is "untrusted", > i.e. requested by userspace via sgx_ioc_enclave_remove_pages(). I mean inside sgx_invalidate() call either __sgx_free_page() or sgx_free_page() depending on a flag. /Jarkko