Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3237775ybh; Mon, 5 Aug 2019 14:42:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqNO+DYe/ZS60FoaZnyWx8pP9ni5CEeTHLlSENUmS4nZ6NiGE9v3hp4xwl0LW0SIX0zddQ X-Received: by 2002:a17:90a:c20e:: with SMTP id e14mr18058459pjt.0.1565041320914; Mon, 05 Aug 2019 14:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565041320; cv=none; d=google.com; s=arc-20160816; b=y8XXYIFyc9I1IrFZsTOLuEYaNDNG/qiJXIrOJv+rfhDcBRTxnxJp2dvugw62JYvxLK Wr20ZS/je6gUoVhntafnhRZQyrf9w7N3qO9FXOewCvcEzUm8BKtp/CArbJ/lxU29Tpz3 IkykF92WOMQze+qd54c7wbDEUDPN+Z2iNGRAGdBFkuuHOjYK0CnALxzgKfxVT6nARvbD WxQXhStnyEWWyPRGe72l/Yx1rfExSKTOOsBjVJonesXh0XsLfwczaZr/LqPGZ95rq+sM QwwOxg+zWe7H1kL5JycXprHbPRK70+Xek3sGHIevgIhUPAX+F3GZOlVG5wxskpUl7JlH GzcA== 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=Pek35roxBWs+ByH4O6R1YfwirrBVRBmrlE+usVw2qSw=; b=gpAw2FmDMzXw+5xZZQRoMIV3TTG7rDhDk5L+1W7NuTOkLOhmCdy59X6l2AkrlOJ/bz Tln/t8HnY7BTQ1yT6SB59LSV1Qt7m7cUNyUS15L2Ra/M2ezKDtHzE1WUyf3wghrPhXrB 2As8Hcm1rSekWF71UV5tSIohbo+l5R+UOa8fMcjNRRqwtgkBF1G4H9tMCHz9XDbpnkLJ hJSMuuzLPCKE0Iw7YHHXKF71YV87ohnYRb87ZLTSG/tUT/mL+IHukVtaPJx9LdjEEB1v 2Nmnvx9+uLN9nEmk5yiqP6iLRGchyMLBKqM3Wrr0NkESnnkvJKK5pMRP3T59KGl29iTQ +vAA== 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 b4si46307512pfg.49.2019.08.05.14.41.45; Mon, 05 Aug 2019 14:42:00 -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 S1730036AbfHEVj6 (ORCPT + 99 others); Mon, 5 Aug 2019 17:39:58 -0400 Received: from mga17.intel.com ([192.55.52.151]:58423 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbfHEVj6 (ORCPT ); Mon, 5 Aug 2019 17:39:58 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 14:39:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,350,1559545200"; d="scan'208";a="176434585" Received: from unknown (HELO localhost) ([10.252.52.83]) by orsmga003.jf.intel.com with ESMTP; 05 Aug 2019 14:39:48 -0700 Date: Tue, 6 Aug 2019 00:39:46 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, Suresh Siddha Subject: Re: [PATCH v21 16/28] x86/sgx: Add the Linux SGX Enclave Driver Message-ID: <20190805213909.x5wv26zrgwqfrp4d@linux.intel.com> References: <20190713170804.2340-1-jarkko.sakkinen@linux.intel.com> <20190713170804.2340-17-jarkko.sakkinen@linux.intel.com> <20190805161644.GD29275@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190805161644.GD29275@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 05, 2019 at 09:16:44AM -0700, Sean Christopherson wrote: > On Sat, Jul 13, 2019 at 08:07:52PM +0300, Jarkko Sakkinen wrote: > > +static unsigned long sgx_get_unmapped_area(struct file *file, > > + unsigned long addr, > > + unsigned long len, > > + unsigned long pgoff, > > + unsigned long flags) > > +{ > > + if (flags & MAP_PRIVATE) > > + return -EINVAL; > > + > > + if (flags & MAP_FIXED) > > + return addr; > > + > > + if (len < 2 * PAGE_SIZE || len & (len - 1)) > > + return -EINVAL; > > + > > + addr = current->mm->get_unmapped_area(file, addr, 2 * len, pgoff, > > + flags); > > + if (IS_ERR_VALUE(addr)) > > + return addr; > > + > > + addr = (addr + (len - 1)) & ~(len - 1); > > + > > + return addr; > > +} > > Thinking about this more, I don't think the driver should verify or adjust > @addr and @len during non-fixed mmap(). There is no requirement that > userspace must map the full ELRANGE, or that an enclave's ELRANGE can > *never* be mapped to non-EPC. The architectural requirement is that an > access that hits ELRANGE must map to the EPC *if* the CPU is executing the > associated enclave. Yeah, well, these were done in a quite different "ecosystem" where range was the enclave and not like now. Can be considered as cruft that we have simply missed when moving the fd associated enclaves. In the current framework of things it definitely makes sense to remove these calculations. So, I guess we will end up to: static unsigned long sgx_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { if (flags & MAP_PRIVATE) return -EINVAL; if (flags & MAP_FIXED) return addr; return current->mm->get_unmapped_area(file, addr, len, pgoff, flags); } /Jarkko