Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp424375ybl; Fri, 9 Aug 2019 08:03:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKOICRVLKH2+5EonI1VgwBAD4giKJiA7U5V4BkB6/Hf1mbzvbG4cTNEcX9IvEmwidc4Ghg X-Received: by 2002:a17:902:704c:: with SMTP id h12mr18531158plt.318.1565363029956; Fri, 09 Aug 2019 08:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565363029; cv=none; d=google.com; s=arc-20160816; b=YRD4kPlx75fTGOt6GaUmQujferCzqkvu8CcB/Q3GsBel3iEFbtvDGCK0JoWBMLIZYt bx8thHTa4BIWjJ+4ckagt4DI0d+gb+/nA/76Ins0Ih1CSGMZ1ytRFBXKlVFDgQA5Ej2/ 4jMwhFOu+iQbPzokqmgdH7kr2llTEKUz1HW0uFcCPq4UsB6fLmlvVFLvfM161XYTWr2E n4ZHw7BQIxA9Hq6TFPezW0Nh+L8THzbldvhFiXQXE9whIxbJX+X+xcR2TdxWK7FzOTcF XBTpy73jxfjK+ICOSLm3YMSFtr4bS2qLsnvsZqtqeGQxw9kjjtilxMEjPF5RC00eziiV 9qpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=QGc8Kx72bnejv9TEDVU9X1FmqhO+Y6QVLa+L2cSYP+Q=; b=Oomf/23BEvvwAz6s/6KZrxTrCq2udtowmJ1uXuWX6+/v2Ru8lZCYeqZ8e/NlDOcU59 1b2JOBffuGyDWRsjDcywUSo6Jlw/NAuIXt52e/3mKZjsHSpyDYMBi47p71bwotMps1uK +KqAFQ7lccZeCP2cgfx8jSTnvXjFyBjF72jqR0rrC5U6Z+x5dECU/ynvlUe4OZsvNY6p J2a9NXnf8OHw2pmdkV6g4T5XM2NIiWHOFWcgCk9YYX6PPXTr0wB5qS6tJYcErAnghAiP 8FhiruOy5KdBrwm49WqMTBIEMHxe5dMV4AsQs7ODobVlEt/CZiJjZc2PCEgLLXnOfo+c MtWw== 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 y9si58537666pfm.236.2019.08.09.08.03.31; Fri, 09 Aug 2019 08:03:49 -0700 (PDT) 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 S2407249AbfHIPCS (ORCPT + 99 others); Fri, 9 Aug 2019 11:02:18 -0400 Received: from mga14.intel.com ([192.55.52.115]:39284 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbfHIPCS (ORCPT ); Fri, 9 Aug 2019 11:02:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Aug 2019 08:02:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,364,1559545200"; d="scan'208";a="186688037" Received: from jsakkine-mobl1.tm.intel.com ([10.237.50.189]) by orsmga002.jf.intel.com with ESMTP; 09 Aug 2019 08:02:09 -0700 Message-ID: Subject: Re: [PATCH v21 16/28] x86/sgx: Add the Linux SGX Enclave Driver From: Jarkko Sakkinen To: Sean Christopherson Cc: "Ayoun, Serge" , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "linux-sgx@vger.kernel.org" , "akpm@linux-foundation.org" , "Hansen, Dave" , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Katz-zamir, Shay" , "Huang, Haitao" , "andriy.shevchenko@linux.intel.com" , "tglx@linutronix.de" , "Svahn, Kai" , "bp@alien8.de" , "josh@joshtriplett.org" , "luto@kernel.org" , "Huang, Kai" , "rientjes@google.com" , "Xing, Cedric" Date: Fri, 09 Aug 2019 18:02:08 +0300 In-Reply-To: <20190808154000.GB23156@linux.intel.com> References: <20190713170804.2340-1-jarkko.sakkinen@linux.intel.com> <20190713170804.2340-17-jarkko.sakkinen@linux.intel.com> <88B7642769729B409B4A93D7C5E0C5E7C65ABB8D@hasmsx108.ger.corp.intel.com> <20190807151534.kxsletvhbn3lno6w@linux.intel.com> <20190808154000.GB23156@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.1-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-08-08 at 08:40 -0700, Sean Christopherson wrote: > On Wed, Aug 07, 2019 at 06:15:34PM +0300, Jarkko Sakkinen wrote: > > On Mon, Jul 29, 2019 at 11:17:57AM +0000, Ayoun, Serge wrote: > > > > + /* TCS pages need to be RW in the PTEs, but can be 0 in the EPCM. */ > > > > + if ((secinfo.flags & SGX_SECINFO_PAGE_TYPE_MASK) == > > > > SGX_SECINFO_TCS) > > > > + prot |= PROT_READ | PROT_WRITE; > > > > > > For TCS pages you add both RD and WR maximum protection bits. > > > For the enclave to be able to run, user mode will have to change the > > > "vma->vm_flags" from PROT_NONE to PROT_READ | PROT_WRITE (otherwise > > > eenter fails). This is exactly what your selftest does. > > > > Recap where the TCS requirements came from? Why does it need > > RW in PTEs and can be 0 in the EPCM? The comment should explain > > it rather leave it as a claim IMHO. > > Hardware ignores SECINFO.FLAGS.{R,W,X} coming from userspace and instead > forces RWX=0. It does this to prevent software from directly accessing > the TCS. But hardware still accesses the TCS through a virtual address, > e.g. to allow software to zap the page for reclaim, which means hardware > generates reads and writes to the TCS, i.e. the PTEs need RW permissions. Manipulating a PTE should not require any specific permissions on the page that it is defining. Why RW is required in SGX context? > So, for the EADD ioctl(), it's not unreasonable for userspace to provide > SECINFO.FLAGS.{R,W,X} = 0 for the TCS to match what will actually get > jammed into the EPCM. Allowing userspace to specify RWX=0 means the > kernel needs to manually add PROT_READ and PROT_WRITE to the allowed prot > bits so that mmap()/mprotect() work as expected. Anyway, appreciate your throughtout explanation, thanks. /Jarkko