Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp450806imm; Tue, 15 May 2018 04:16:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZryOD4vPRMrTZkOEDlpzu8zX6PSkfxrLCw46FNBq3AN/xChm47c6YD0/fHqwfGop7KDtkQP X-Received: by 2002:a62:22db:: with SMTP id p88-v6mr14727652pfj.239.1526383018133; Tue, 15 May 2018 04:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526383018; cv=none; d=google.com; s=arc-20160816; b=fw9BR+6yHihUyZCewsGBnGRhZEdysmf/kwTE69dU0PhPDByYitwfctfXjKgZ3tsuvw zGhm1iDbn1LUo+xAV9YiGbsKKma9gCLiWmPfgRsY6YUt05xnAsiSOp6wZZXu2rJg5rnx GtGNjtqKl3k45ttV8cUN3Agmvl68w/rmsUgoLFRGFRMMiXX2ODKJJgVLQYbxcttAGfVf vZi0JyTP9LbGpLyWe1y3CQ4H7KeZSYTiMpjptXyM6xIuDlRIQq/eh5FbZR2kyaVW198X ViaTfyztwRiutwyDw6xu4b7bBKXaZ0TGHXTCyM6klO9unLVPaiajHO64Evl0KJkbfFCX rYxA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=MSv6Vc0LoieyxH0A/y6VmAXnrCcgs6Q2VGNnfsFhhD4=; b=BxALB20w5ditBcAvYBWWsbYp1CsQoktgmr/gyjzCIsjJAmgaw8jYHVMADDqfCVhhxP hI2/rDW3EIEoev13Lrbg9YKCqjIj/YECU86XE160NueJ7CMsG2u40PPs4D80+3sEv4vU zuZ0ZFcTDozkKJkpNwR0Q5NfZeFvo+2ILAeM3kolEZbSzk2hHI1jTG8DrwQOFpfX7LW5 CIj/u3C5634kn6QuGygWW+VG5TF/HWtCTI9LM2CozfnxW5CaujdZuBZXWVOfAOSZn7hh bgt+98LIroqY5CciMO8FZOFuDQ37Oh6AIXLdmMdmkcw2U9y5R5VaeLvDxiu14vAiRxtP Pb9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rYQZvRWV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m79-v6si11512454pfi.236.2018.05.15.04.16.43; Tue, 15 May 2018 04:16:58 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=rYQZvRWV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752764AbeEOLMF (ORCPT + 99 others); Tue, 15 May 2018 07:12:05 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58486 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752591AbeEOLME (ORCPT ); Tue, 15 May 2018 07:12:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MSv6Vc0LoieyxH0A/y6VmAXnrCcgs6Q2VGNnfsFhhD4=; b=rYQZvRWV0FkfbJ+WbQ3tSBx8a vQet0hSmrm+TYwFeENdrDe6NEmhG6pbY9iBiAnZFnsi7fDThRe3EVahtbuLwSDwBHiLhhy8xZ6Pn0 xS59u6970SA+mgC0h/QRiTbWEwBPLCzUgH9wH6H1ntaZm6Vi9Dv9Bo9TRgwp3wKZU3znUGp09xb0c x/Ut+m0O+RSzHP+6VKRrFwxo9TntgFjVK6gzLgtYEzexSr3zx8VbYzR3q0B12w7p5ymUEn7y0Le8C yWeeeaFU/eBxmgluqF6wpdnRWKTXXHmCwz7jViXq2OgHtkU1EeUx1ip+AZ8NTDXv0Dk+Hc/QZnV9r 8c1C6YnxQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIXs7-0004qs-Lc; Tue, 15 May 2018 11:11:59 +0000 Date: Tue, 15 May 2018 04:11:59 -0700 From: Matthew Wilcox To: Boaz Harrosh Cc: Jeff Moyer , Andrew Morton , "Kirill A. Shutemov" , linux-kernel , linux-fsdevel , "linux-mm@kvack.org" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Peter Zijlstra , Dave Hansen , Rik van Riel , Jan Kara , Matthew Wilcox , Amit Golander Subject: Re: [PATCH] mm: Add new vma flag VM_LOCAL_CPU Message-ID: <20180515111159.GA31599@bombadil.infradead.org> References: <0efb5547-9250-6b6c-fe8e-cf4f44aaa5eb@netapp.com> <20180514191551.GA27939@bombadil.infradead.org> <7ec6fa37-8529-183d-d467-df3642bcbfd2@netapp.com> <20180515004137.GA5168@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 15, 2018 at 01:43:23PM +0300, Boaz Harrosh wrote: > On 15/05/18 03:41, Matthew Wilcox wrote: > > On Mon, May 14, 2018 at 10:37:38PM +0300, Boaz Harrosh wrote: > >> On 14/05/18 22:15, Matthew Wilcox wrote: > >>> On Mon, May 14, 2018 at 08:28:01PM +0300, Boaz Harrosh wrote: > >>>> On a call to mmap an mmap provider (like an FS) can put > >>>> this flag on vma->vm_flags. > >>>> > >>>> The VM_LOCAL_CPU flag tells the Kernel that the vma will be used > >>>> from a single-core only, and therefore invalidation (flush_tlb) of > >>>> PTE(s) need not be a wide CPU scheduling. > >>> > >>> I still don't get this. You're opening the kernel up to being exploited > >>> by any application which can persuade it to set this flag on a VMA. > >>> > >> > >> No No this is not an application accessible flag this can only be set > >> by the mmap implementor at ->mmap() time (Say same as VM_VM_MIXEDMAP). > >> > >> Please see the zuf patches for usage (Again apologise for pushing before > >> a user) > >> > >> The mmap provider has all the facilities to know that this can not be > >> abused, not even by a trusted Server. > > > > I don't think page tables work the way you think they work. > > > > + err = vm_insert_pfn_prot(zt->vma, zt_addr, pfn, prot); > > > > That doesn't just insert it into the local CPU's page table. Any CPU > > which directly accesses or even prefetches that address will also get > > the translation into its cache. > > Yes I know, but that is exactly the point of this flag. I know that this > address is only ever accessed from a single core. Because it is an mmap (vma) > of an O_TMPFILE-exclusive file created in a core-pinned thread and I allow > only that thread any kind of access to this vma. Both the filehandle and the > mmaped pointer are kept on the thread stack and have no access from outside. > > So the all point of this flag is the kernel driver telling mm that this > address is enforced to only be accessed from one core-pinned thread. You're still thinking about this from the wrong perspective. If you were writing a program to attack this facility, how would you do it? It's not exactly hard to leak one pointer's worth of information.