Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3867655pxk; Tue, 22 Sep 2020 04:55:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvF/W3op8MhNuBAR2j8NJMZSdmPk4lthmUapZoB0chkYNmqnMIG7xzqbRd39UM8geJf24/ X-Received: by 2002:a05:6402:292:: with SMTP id l18mr3628253edv.6.1600775756315; Tue, 22 Sep 2020 04:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600775756; cv=none; d=google.com; s=arc-20160816; b=G8/tleY/DEGbOq0mJpmIiJ1lnWRr05kmEKX3aHYI/BZ+fv9uIW68PEZ2ZNZhSp2pub zDusrNZKjVF7m36SDmYCUgOLd7AKpKE2ofF6P2F13Icd7PeF0VLniZpP75ZkyufXGhV2 yhjQwJgTl3N/+K/dVRu3IbXiHDBMFRl1abm5qeUh+3SomTmrcO/q88OP/XKY2zyA0EDP lW7ovosB0w0XmPloMvCgfZDaRkigUIjtQpoa0IKDhD9lX3Z9vZmrqgjSD7SSj8NVC+5d mQMFwxzbAbwd3xQspmf1WfT0kjqm+NRIqiJ3OcIWKxDg4xB8wdDWao7J/Su7Wgjep9l/ xGiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nmyfYbTxASalyuC4ipdAUYFHF4U9gSVwG5N7T0tPGkw=; b=KOg4G07bjJvXIS1SgJY32b3mqo9zWD3k7UmUJBesHXTjV6eM4GJZ9Iz3SVJfwhkKtc SDyZXr1ymONtXLEyZ6TtOSReQnOQE0ggkJrnj1Bif7qyeVY2CmJnm2aqYikYrZuH1JSz hv0T4qM6mj1VnjscOg2WN4ZzDv9X9NAMgJ95xpcYc+AGDi0b2GL4v/Yhl49STSHMrahn XxiacH0MmcOLtVB8/ixOJI5hQUM4mWExGNviOkpLx/Ry6U/PhVVhWhLGu1hLZG8I80SP lM9IUvRV7yEv2vVKWl9ASUTWaDN3dOlIXGS0uN9djJ3hwfkdq6NHhk8rXWIgGw1ppTXp qprw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b="M8M2c/P5"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si9877552edw.458.2020.09.22.04.55.32; Tue, 22 Sep 2020 04:55:56 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b="M8M2c/P5"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbgIVLyj (ORCPT + 99 others); Tue, 22 Sep 2020 07:54:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbgIVLyi (ORCPT ); Tue, 22 Sep 2020 07:54:38 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D9CC061755 for ; Tue, 22 Sep 2020 04:54:38 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id o5so18601426qke.12 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=IfWVNoWeNe+Ceglo0OEbQDKWGF8stnBZQTYXfA/LM9VK+2KkJnJBLCyaiLm+7ckfPj dIHMrdRgWEUYLMwBG8lE3BdjSVN50Gf8T5eyMkjXSh1edoFGs6/IoQWD7oEWDvAMdULb x3CfH7ZBgGKPrfZHp27XySaIM8aRY3fzhVEPTG/JH4U+RuiKlXDw+CnQdVOcGvqURrRq sYJ7Dvn6MuifeoHb1RUr+ogBsLejlDN862CsGEH7KZQ1isqoQz0qGf8aj6rEjCNliD84 IB0YYXLOYjlZOfN/Fj2uj7k63Aizmj7Gpr2Czd50GO3FNfLLh4zI3P7/FGC4Bp4hwz5S /VMA== X-Gm-Message-State: AOAM530zU6o/2juUsdP4rA5NHXFaD+HHxA0ldGR+4KJUG700w7QYN15B EP47rMSJdmRV3OKGF8obSOlZqQ== 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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