Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp341542ybm; Thu, 28 May 2020 04:18:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxysYIvdEyBYNxuTji/myxYgaqaP9vDpE+19T91xRxbi/HtTzqkpNLE7AwR1Mnl+e+YYhJN X-Received: by 2002:a05:6402:719:: with SMTP id w25mr2548502edx.179.1590664700357; Thu, 28 May 2020 04:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590664700; cv=none; d=google.com; s=arc-20160816; b=c7YYH4h3r2iHg/wsedMgwzexy2RMF3x+cHqhl29qBQlc//0fqIgjLqz0Fei8uZ15hj 40XpmdmInH0i9Pfw6B1lzvS9F9qEx7U5LKkWg598axM8L37nTeRBv7ZmZvgR6LCthHRk j5Q4fM0iegsS/c2WhgVD0o2KwSQuwEP1OjK6Ev0HLWVyJLgNvBi2lcc11uzSHlYMDA7Y 5wCQKMoxxOv+5RXGTgG+bWX22d2m0WWJZZCYwfAnmUhNrdHXJ7jKSAfoQkcObsppLKz/ vshf3GEw3WF2IBglSgDqIt4HiNkX5asXcFM1seXW7YOWKU/T+naBgJJIdxBZ1r4xigcP MeuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=8yXKRFxT7FOEl9W69gM17FAZekzEEJgIK4u+uHdyB04=; b=ebAAzn3kcotnm7nxkmBFi0QCZtnBgMOnob3QVVTdIIXf854DfXy7m5ryfj22xLsN2S 3qT0D6SqBNA9Aqbj8zyb/Wpg7Qq253u/W0w0ycVfFfTbnfoncd6qxJynz1ptvxIhdxQG 9MbkrCL9EROL27ouJ3QEtwj4nWUk12HXxTLcSmUafSSmz9pIgLP4J+9UAxxDrBe9QCj+ QX16Z0xyOunFS7rS2VVNRBn3j9IgsF6Xi7v7IVU+JWBDSDwv38BmM85ngiKjvR+AJ0u1 GPFR/ZXqY+Hwmji/vQPYdEukbzDZm7wGVye6zaK8Zn4Rrv9Wbd4GjT3YEeyWugxajE0/ Maeg== 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 h4si3229224edn.453.2020.05.28.04.17.56; Thu, 28 May 2020 04:18:20 -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 S2388260AbgE1LPV (ORCPT + 99 others); Thu, 28 May 2020 07:15:21 -0400 Received: from mga14.intel.com ([192.55.52.115]:49492 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388243AbgE1LPU (ORCPT ); Thu, 28 May 2020 07:15:20 -0400 IronPort-SDR: qM0JWs1/SeoLNIDo4H4L8fJPnV2hBAPZGscfJlPzF1X7M+y0XFuf93uxR5sCeV9O4KPdHerTPI T2uQD53Hds3w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 04:15:19 -0700 IronPort-SDR: lzwrNbDJy/zXwX3C7CwXLxw3KkWOLT7VbR7XhzYmpIoQK7g7gY6AdSSB28DdIOFqbdx1GoqU9d qfhd6wAYoAlg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,444,1583222400"; d="scan'208";a="414568779" Received: from dmescala-mobl1.amr.corp.intel.com (HELO localhost) ([10.252.59.102]) by orsmga004.jf.intel.com with ESMTP; 28 May 2020 04:15:09 -0700 Date: Thu, 28 May 2020 14:15:07 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Haitao Huang , Nathaniel McCallum , linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, Neil Horman , "Huang, Haitao" , andriy.shevchenko@linux.intel.com, tglx@linutronix.de, "Svahn, Kai" , bp@alien8.de, Josh Triplett , luto@kernel.org, kai.huang@intel.com, David Rientjes , "Xing, Cedric" , Patrick Uiterwijk Subject: Re: [PATCH v29 00/20] Intel SGX foundations Message-ID: <20200528111507.GA1666298@linux.intel.com> References: <20200421215316.56503-1-jarkko.sakkinen@linux.intel.com> <20200506221422.GK3329@linux.intel.com> <20200507193459.GA24519@linux.intel.com> <20200508002555.GA24964@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200508002555.GA24964@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 05:25:55PM -0700, Sean Christopherson wrote: > Ah, fudge. shmem_zero_setup() triggers shmem_acct_size() and thus > __vm_enough_memory(). Which I should have rememered because I've stared > at that code several times when dealing with the enclave's backing store. > I wasn't seeing the issue because I happened to use MAP_PRIVATE. > > So, bad analysis, good conclusion, i.e. the kernel is still doing the > right thing, it's just not ideal for userspace. > > > Jarkko, we should update the docs and selftest to recommend and use > > PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS > > or > > PROT_NONE, MAP_SHARED | MAP_NORESERVE | MAP_ANONYMOUS" > > when carving out ELRANGE, with an explicit comment that all the normal > rules for mapping memory still apply. Ugh, had forgotten this. OK, I guess this comment explains it all: " /* * shmem_file_setup pre-accounts the whole fixed size of a VM object, * for shared memory and for shared anonymous (/dev/zero) mappings * (unless MAP_NORESERVE and sysctl_overcommit_memory <= 1), * consistent with the pre-accounting of private mappings ... */ static inline int shmem_acct_size(unsigned long flags, loff_t size) " /Jarkko