Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7142007ybi; Thu, 13 Jun 2019 10:15:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhWNGzakFXkeMZ/HoLO0JlLlo6qEHa0ZoTiRh7XMskXogH+JTwA+3UcyI37qKfiXJ7dTcG X-Received: by 2002:a17:902:b594:: with SMTP id a20mr9442885pls.259.1560446137956; Thu, 13 Jun 2019 10:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560446137; cv=none; d=google.com; s=arc-20160816; b=Rz0ph3YUOwONuiqcIVD1OBeu9AF4J/U2EPqoONt7rbQl5riFVFQH4Z9ll7VN95V/2P t6RjGD6I2GjxdJ6RJgYSsE4mqzqtwrqhFsBhKqLeUq9OCQBTyKCO9g1PtWoHwRxUYBAU 3Q8oVDVVr/XVoPxBIm00JT6ORtgptv6Qazfwd6h/exhRDYkcRQglRzmypS8KKEB2upUz 4teaGHvE1pyrgjODq2nihAZNEkroK2VoP0o2ty3baoK0y+2Cbt9IA7mQ56yOn1FIOxrJ I2JgxHGcLt6fWnbGKcEVq26QkHdI7D60t420WuKHSJSMgViyaG6SGAYfAX/RHL1NwOCs yOOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NafhEzqgOIsISJZna18JOZFqqD3H1s4MvoN8CLn3148=; b=uC9I9e3zySho6z2IyHTsPMBOyHaXE57e/h5GguRap63AfGtgUaA1Js0jAgRli+c9t4 CqFA1r8VBTN+iIC6pPa4nOfWwIbBg6I2TAmRE6NSJ+z/bE1zK7liFJICHgv3ZnR1Exed dGmdSuwsk9bMXPAJLQfR6XHZ4oyfaUSoerEWYc2wkd+ZrjQSb/Ney7SDtRe8saFmX+wm L1LwRfNteujpZrINO+Xv0GgeSCEWU76kfVXswfR8pkypqjPHKfFeo5qWKd4ScuDuNo1a uOzRQ54YhBIOigCCUshPQytXg8Aoj6U1XbdYpP9bNIS2U2+PPcm8HfI7O3bjEkz5L20F ngRw== 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 2si237487pgy.541.2019.06.13.10.15.23; Thu, 13 Jun 2019 10:15:37 -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 S1729108AbfFMRPQ (ORCPT + 99 others); Thu, 13 Jun 2019 13:15:16 -0400 Received: from mga14.intel.com ([192.55.52.115]:2618 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393579AbfFMROz (ORCPT ); Thu, 13 Jun 2019 13:14:55 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2019 10:14:55 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by orsmga006.jf.intel.com with ESMTP; 13 Jun 2019 10:14:52 -0700 Date: Thu, 13 Jun 2019 10:14:51 -0700 From: Sean Christopherson To: "Xing, Cedric" Cc: Jarkko Sakkinen , Andy Lutomirski , Andy Lutomirski , Stephen Smalley , James Morris , "Serge E . Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , Linus Torvalds , LKML , X86 ML , "linux-sgx@vger.kernel.org" , Andrew Morton , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes , "Roberts, William C" , "Tricca, Philip B" Subject: Re: [RFC PATCH 2/9] x86/sgx: Do not naturally align MAP_FIXED address Message-ID: <20190613171451.GD5850@linux.intel.com> References: <20190531233159.30992-1-sean.j.christopherson@intel.com> <20190531233159.30992-3-sean.j.christopherson@intel.com> <20190604114951.GC30594@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654EDBDE@ORSMSX116.amr.corp.intel.com> <20190605151653.GK11331@linux.intel.com> <5A85C1D7-A159-437E-B42A-3F4254E07305@amacapital.net> <20190606153710.GB25112@linux.intel.com> <20190613134800.GA12791@linux.intel.com> <960B34DE67B9E140824F1DCDEC400C0F65503A93@ORSMSX116.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F65503A93@ORSMSX116.amr.corp.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 13, 2019 at 09:47:06AM -0700, Xing, Cedric wrote: > > From: Jarkko Sakkinen [mailto:jarkko.sakkinen@linux.intel.com] > > Sent: Thursday, June 13, 2019 6:48 AM > > > > On Thu, Jun 06, 2019 at 06:37:10PM +0300, Jarkko Sakkinen wrote: > > > On Wed, Jun 05, 2019 at 01:14:04PM -0700, Andy Lutomirski wrote: > > > > > > > > > > > > > On Jun 5, 2019, at 8:17 AM, Jarkko Sakkinen > > wrote: > > > > > > > > > >> On Tue, Jun 04, 2019 at 10:10:22PM +0000, Xing, Cedric wrote: > > > > >> A bit off topic here. This mmap()/mprotect() discussion reminds > > > > >> me a question (guess for Jarkko): Now that > > > > >> vma->vm_file->private_data keeps a pointer to the enclave, why do > > we store it again in vma->vm_private? > > > > >> It isn't a big deal but non-NULL vm_private does prevent > > > > >> mprotect() from merging adjacent VMAs. > > > > > > > > > > Same semantics as with a regular mmap i.e. you can close the file > > > > > and still use the mapping. > > > > > > > > > > > > > > > > > > The file should be properly refcounted — vm_file should not go away > > while it’s mapped. > > > > mm already takes care of that so vm_file does not go away. Still we need > > an internal refcount for enclaves to synchronize with the swapper. In > > summary nothing needs to be done. > > I don't get this. The swapper takes a read lock on mm->mmap_sem, which locks > the vma, which in turn reference counts vma->vm_file. Why is the internal > refcount still needed? mmap_sem is only held when reclaim is touching PTEs, e.g. to test/clear its accessed bit and to zap the PTE. The liveliness of the enclave needs to be guaranteed for the entire duration of reclaim, e.g. we can't have the enclave disappearing when we go to do EWB. It's also worth nothing that a single reclaim may operate on more than one mmap_sem, as enclaves can be shared across processes (mm_structs).