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 CC180C4727C for ; Mon, 21 Sep 2020 22:27:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D7CF23A5B for ; Mon, 21 Sep 2020 22:27:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HBeoGyb1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D7CF23A5B 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 A7042900008; Mon, 21 Sep 2020 18:27:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F949900007; Mon, 21 Sep 2020 18:27:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C02F900008; Mon, 21 Sep 2020 18:27:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id 6F770900007 for ; Mon, 21 Sep 2020 18:27:27 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3B5E81EE6 for ; Mon, 21 Sep 2020 22:27:27 +0000 (UTC) X-FDA: 77288506134.06.fight58_2e13d7d27148 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 13D35100B95AA for ; Mon, 21 Sep 2020 22:27:27 +0000 (UTC) X-HE-Tag: fight58_2e13d7d27148 X-Filterd-Recvd-Size: 6039 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 22:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600727246; 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=3Y3BFMMga4eqj/OQvqbNbqZ9EEiAzPKsrbE58dm7rTQ=; b=HBeoGyb1oOHWkKB93hztD+SJJ2ViFcuiYBYU305nqPIMI+o3x+slq+H41dWCYXB4jPdFor TNT1JTwFk4X7WaXUbAyUonxdOvYkCcEelbGIBOZTXxsMqt1/xn9ZPCRpPI9WW2y92t/51I 8+7KXHGnRiwN4VulxO/RiJMRZjF6rwo= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-412-Q0VIclBlNOicwHjPXIzMOg-1; Mon, 21 Sep 2020 18:27:24 -0400 X-MC-Unique: Q0VIclBlNOicwHjPXIzMOg-1 Received: by mail-qt1-f199.google.com with SMTP id f12so14309750qtq.5 for ; Mon, 21 Sep 2020 15:27:24 -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=3Y3BFMMga4eqj/OQvqbNbqZ9EEiAzPKsrbE58dm7rTQ=; b=UPndfHFj+HqcmeaonxvbNOedLyedckLM/2Z3t1lLMZrLkcW17JU3WGWWq6qL8cQT/U JfIb5m8Ay1ddAW5GekX/+bG8IDAObl3xr4xgv5WOlLydcdzkRhDbrInU28jZ7CRSWDC1 MsgYb26Oef87AYQqwzeGaJjHxI+HAJJeyLRzy6i+kd0ip+68cd9CKJZa5hYUxakxNyG6 /S2PE2tB/1QV7/opIijKoFVn62bwLoOyozT33XLUKKsVQY28RAKOEWZRCvBG/Iy8AKlI x347D53YV79wG097DAY3iqhPJLRi28H4Ww5xlyMB5ySi5KAdRwfktTpSUOHvUTZwLy4m JB2w== X-Gm-Message-State: AOAM5325Qg5PJxeWu2Bvkp61zf9QI1/cUR0oL9KJQQ00oP/9bGEyBJnQ 9SBLUZLux3tpWIb1xW9YLmjEoMiQlId6nKxrvYeyVU/e1qusFIWkuocXlAyegxyZqAgWdq6uOLX EeM1XT18pHuA= X-Received: by 2002:a37:638d:: with SMTP id x135mr2133316qkb.60.1600727243757; Mon, 21 Sep 2020 15:27:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXeszQ8v+I0gHuiyOcxO+4Ql50Jhun0n7Wk3k1WQyONvPgUy/yCr+GWhmxVp1Dq/luFIF0Tg== X-Received: by 2002:a37:638d:: with SMTP id x135mr2133284qkb.60.1600727243472; Mon, 21 Sep 2020 15:27:23 -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 c1sm11539452qta.86.2020.09.21.15.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 15:27:22 -0700 (PDT) Date: Mon, 21 Sep 2020 18:27:20 -0400 From: Peter Xu To: Jann Horn Cc: Linux-MM , kernel list , Linus Torvalds , Michal Hocko , Kirill Shutemov , Oleg Nesterov , Kirill Tkhai , Hugh Dickins , Leon Romanovsky , Jan Kara , John Hubbard , Christoph Hellwig , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli Subject: Re: [PATCH 4/5] mm: Do early cow for pinned pages during fork() for ptes Message-ID: <20200921222720.GA19098@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921212028.25184-1-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: 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: Hi, Jann, On Mon, Sep 21, 2020 at 11:55:06PM +0200, Jann Horn wrote: > On Mon, Sep 21, 2020 at 11:20 PM Peter Xu wrote: > > This patch is greatly inspired by the discussions on the list from Linus, Jason > > Gunthorpe and others [1]. > > > > It allows copy_pte_range() to do early cow if the pages were pinned on the > > source mm. Currently we don't have an accurate way to know whether a page is > > pinned or not. The only thing we have is page_maybe_dma_pinned(). However > > that's good enough for now. Especially, with the newly added mm->has_pinned > > flag to make sure we won't affect processes that never pinned any pages. > > To clarify: This patch only handles pin_user_pages() callers and > doesn't try to address other GUP users, right? E.g. if task A uses > process_vm_write() on task B while task B is going through fork(), > that can still race in such a way that the written data only shows up > in the child and not in B, right? I saw that process_vm_write() is using pin_user_pages_remote(), so I think after this patch applied the data will only be written to B but not the child. Because when B fork() with these temp pinned pages, it will copy the pages rather than write-protect them any more. IIUC the child could still have partial data, but at last (after unpinned) B should always have the complete data set. > > I dislike the whole pin_user_pages() concept because (as far as I > understand) it fundamentally tries to fix a problem in the subset of > cases that are more likely to occur in practice (long-term pins > overlapping with things like writeback), and ignores the rarer cases > ("short-term" GUP). John/Jason or others may be better on commenting on this one. From my own understanding, I thought it was the right thing to do so that we'll always guarantee process B gets the whole data. From that pov this patch should make sense even for short term gups. But maybe I've missed something. -- Peter Xu