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=-3.9 required=3.0 tests=BAYES_00,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 AB7C8C2D0E2 for ; Tue, 22 Sep 2020 11:54:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 08CC923600 for ; Tue, 22 Sep 2020 11:54:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="M8M2c/P5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08CC923600 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 723AE900070; Tue, 22 Sep 2020 07:54:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D258900063; Tue, 22 Sep 2020 07:54:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E976900070; Tue, 22 Sep 2020 07:54:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 45ABB900063 for ; Tue, 22 Sep 2020 07:54:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 03DB1181AEF0B for ; Tue, 22 Sep 2020 11:54:39 +0000 (UTC) X-FDA: 77290540278.07.goose87_0d07d302714d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id DC7341803F9A4 for ; Tue, 22 Sep 2020 11:54:38 +0000 (UTC) X-HE-Tag: goose87_0d07d302714d X-Filterd-Recvd-Size: 5738 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 11:54:38 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id n133so18597698qkn.11 for ; Tue, 22 Sep 2020 04:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=nmyfYbTxASalyuC4ipdAUYFHF4U9gSVwG5N7T0tPGkw=; b=M8M2c/P5kA3kctisYfatlJSTe3yNJfvr/qJcqyp8WWIgUO8Iaevb9o+QyPCWN0ocd+ a7PMpwCvVNKDpZD6hm/COdKdM2J73m8cGhP72vfX/lw4++ryqH2Sv02dJap6C0NzDK0y 4P33uJfGqwaUWYclQREZnwrK1FGz3z1EFFFbEv6tYN9QLm09kvMMmLcUOP5MhzeUoAI5 WLq1czQUCz8a2MiqOxjJbPtxNjU66E6kWCTGE9jx42KzpRi8zm7WeCdvwrKS9SJ7gdrK sKvKmP290SCSRtc/dLoAglzH+MiCdMnG6nWSn99BFVdDtKtZxkurV7zdGbhm9OHOeECr tq6A== 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=nmyfYbTxASalyuC4ipdAUYFHF4U9gSVwG5N7T0tPGkw=; b=DvGJowBESMpxXFKN/vc8xO8O4m1YEaoIxlJuLM+MlNRx36tu0Ij8QMr2PIzyJcsz/r C0yo4WOm1Zxw8wgIGUG7MYgke588P7NrdoUF7xiqVZa7KhRR/t3IgGu1y/Bn2Ro+uxK6 kkHSRj4qIsYUrOsJ9xqH/PTQfRkXB+eIzzrx+Ha/AxORLokGe/84B9iF1kpcgVXyGTSE gANMk3Mo8dXC31OOfVFtkbYme4Z7WDMdweAX0Jf3lIuSsdoEp+dquE2qb9bA4ZZ5Vmwd twZCVMeAzqUyYDj68g+bWDVpcc1RoQ08NOI6wNVRb1274x9fpm9LhF4lRPgvToQcHV69 vvwA== X-Gm-Message-State: AOAM5306I3smigLwZYpuOqUfmAlgMwEVP3x2YBH8S0cI1NqIHIDzubhn IHZs/NNFoi6xBRN2Nw+pn7iwXw== X-Google-Smtp-Source: ABdhPJyBI6tbzANIZBC4sRXyAIkxkM/AIH7Z52WGQkODT5CFUJRzxXkZquA1Zt5/2T0sAuJsIk2vpw== X-Received: by 2002:a05:620a:64b:: with SMTP id a11mr4286993qka.313.1600775677699; Tue, 22 Sep 2020 04:54:37 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id q7sm12738125qte.95.2020.09.22.04.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 04:54:37 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kKgsW-0030cN-BO; Tue, 22 Sep 2020 08:54:36 -0300 Date: Tue, 22 Sep 2020 08:54:36 -0300 From: Jason Gunthorpe To: Jann Horn Cc: Peter Xu , 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: <20200922115436.GG8409@ziepe.ca> References: <20200921211744.24758-1-peterx@redhat.com> <20200921211744.24758-2-peterx@redhat.com> <20200921223004.GB19098@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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() Jason