From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85136C2D0E2 for ; Tue, 22 Sep 2020 14:28:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F16F820C09 for ; Tue, 22 Sep 2020 14:28:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e0G/mvwC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F16F820C09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5B99390008B; Tue, 22 Sep 2020 10:28:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 569F1900086; Tue, 22 Sep 2020 10:28:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4589990008B; Tue, 22 Sep 2020 10:28:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 2A8D8900086 for ; Tue, 22 Sep 2020 10:28:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DAE533628 for ; Tue, 22 Sep 2020 14:28:12 +0000 (UTC) X-FDA: 77290927224.16.bells26_43120b42714e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 92635100EC697 for ; Tue, 22 Sep 2020 14:28:12 +0000 (UTC) X-HE-Tag: bells26_43120b42714e X-Filterd-Recvd-Size: 6650 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 14:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600784891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4KeBzI9+ks+mK6pPN0E4gOcdT+Ebd4ElJn6Z0ui1YyE=; b=e0G/mvwCLH5jC3D3FlYb9KOd2avSX+JkW9IY7EuZ/3eWsWB5RNoxaq12L7iTYuqz4nXKWc SWGbtDL4nvzHb6C4doBM60zKItzPRIhFv8v2snVTfbsBbFw5PFEvMYa58gYjcyxz+nchgz f5huDjAH6ovqFF0DZzmb36AE6SKd/Ns= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-K818KcYwMoaEiEPycSm99A-1; Tue, 22 Sep 2020 10:28:06 -0400 X-MC-Unique: K818KcYwMoaEiEPycSm99A-1 Received: by mail-qt1-f200.google.com with SMTP id e6so16092998qtg.13 for ; Tue, 22 Sep 2020 07:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4KeBzI9+ks+mK6pPN0E4gOcdT+Ebd4ElJn6Z0ui1YyE=; b=Bro2Z2qTqwaVFvcWr1E01zif/b4O/VwzqHNB6iQYl+41c5D8G5EtXkJ1Sh8RnBaYqv Obihbq13IIJ/yFZxEShxtT1QsTp0Bt9VKrY0TdjhmAFG9UjXRaAavk/V9iHd7x8C2w43 EgwSppWJclzZhXXBHT3rIYv5/svbWSkv0ko0J9jAbMYjl335XOwg80MIkWTOWLmoHhYf h1rHwxGTIMuT73fk7rye7HTf6jyrpu35VPqkASz3+fUZED19oLRSL5pud2o8PBxX3yPh f4qdW4bP/NjqDTzgjETXp7qCE/gDmsKl1/HR6GBABytFp8/95CviSbaMPCxP6g1Mrh54 agjg== X-Gm-Message-State: AOAM530hGDeCF/GU7y8SjMpg5jPnt/Yrrg2QYvPHTFUX8WhkPB9NogGp GDWmssXrjZ6q5bQPXJb4bGCjJvC9wqamBWCQClGFVaJMxqc2Fe9ZO7adGlSPgWrdTTqQrqQCFaj 3wDSvL1xCHSQ= X-Received: by 2002:a37:5c1:: with SMTP id 184mr4440857qkf.99.1600784885582; Tue, 22 Sep 2020 07:28:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylHcnqrRD1BI8HRprNv69q7Oj4TDomf93YpD0/nIEvv8cyk8WrP0pxxrObzx/B0MHlffDvEA== X-Received: by 2002:a37:5c1:: with SMTP id 184mr4440815qkf.99.1600784885209; Tue, 22 Sep 2020 07:28:05 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id m196sm12167980qke.87.2020.09.22.07.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 07:28:04 -0700 (PDT) Date: Tue, 22 Sep 2020 10:28:02 -0400 From: Peter Xu To: Jason Gunthorpe Cc: Jann Horn , Linux-MM , kernel list , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , John Hubbard , Oleg Nesterov , Leon Romanovsky , Linus Torvalds Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200922142802.GC19098@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921211744.24758-2-peterx@redhat.com> <20200921223004.GB19098@xz-x1> <20200922115436.GG8409@ziepe.ca> MIME-Version: 1.0 In-Reply-To: <20200922115436.GG8409@ziepe.ca> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 22, 2020 at 08:54:36AM -0300, Jason Gunthorpe wrote: > On Tue, Sep 22, 2020 at 12:47:11AM +0200, Jann Horn wrote: > > On Tue, Sep 22, 2020 at 12:30 AM Peter Xu wrote: > > > On Mon, Sep 21, 2020 at 11:43:38PM +0200, Jann Horn wrote: > > > > On Mon, Sep 21, 2020 at 11:17 PM Peter Xu wrote: > > > > > (Commit message collected from Jason Gunthorpe) > > > > > > > > > > Reduce the chance of false positive from page_maybe_dma_pinned() by keeping > > > > > track if the mm_struct has ever been used with pin_user_pages(). mm_structs > > > > > that have never been passed to pin_user_pages() cannot have a positive > > > > > page_maybe_dma_pinned() by definition. > > > > > > > > There are some caveats here, right? E.g. this isn't necessarily true > > > > for pagecache pages, I think? > > > > > > Sorry I didn't follow here. Could you help explain with some details? > > > > The commit message says "mm_structs that have never been passed to > > pin_user_pages() cannot have a positive page_maybe_dma_pinned() by > > definition"; but that is not true for pages which may also be mapped > > in a second mm and may have been passed to pin_user_pages() through > > that second mm (meaning they must be writable over there and not > > shared with us via CoW). > > The message does need a few more words to explain this trick can only > be used with COW'able pages. > > > Process A: > > > > fd_a = open("/foo/bar", O_RDWR); > > mapping_a = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd_a, 0); > > pin_user_pages(mapping_a, 1, ...); > > > > Process B: > > > > fd_b = open("/foo/bar", O_RDONLY); > > mapping_b = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd_b, 0); > > *(volatile char *)mapping_b; > > > > At this point, process B has never called pin_user_pages(), but > > page_maybe_dma_pinned() on the page at mapping_b would return true. > > My expectation is the pin_user_pages() should have already broken the > COW for the MAP_PRIVATE, so process B should not have a > page_maybe_dma_pinned() When process B maps with PROT_READ only (w/o PROT_WRITE) then it seems the same page will be mapped. I think I get the point from Jann now. Maybe it's easier I just remove the whole "mm_structs that have never been passed to pin_user_pages() cannot have a positive page_maybe_dma_pinned() by definition" sentence if that's misleading, because the rest seem to be clear enough on what this new field is used for. Thanks, -- Peter Xu