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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 97780C4727F for ; Mon, 21 Sep 2020 21:55:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F9DC20709 for ; Mon, 21 Sep 2020 21:55:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cct76/7O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F9DC20709 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 851EC6B009E; Mon, 21 Sep 2020 17:55:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 829B16B009F; Mon, 21 Sep 2020 17:55:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73F1B900004; Mon, 21 Sep 2020 17:55:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 5B7926B009E for ; Mon, 21 Sep 2020 17:55:35 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 18E41181AEF07 for ; Mon, 21 Sep 2020 21:55:35 +0000 (UTC) X-FDA: 77288425830.23.join99_0210e4827148 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id E1EFC37604 for ; Mon, 21 Sep 2020 21:55:34 +0000 (UTC) X-HE-Tag: join99_0210e4827148 X-Filterd-Recvd-Size: 4280 Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 21:55:34 +0000 (UTC) Received: by mail-ej1-f67.google.com with SMTP id gx22so10865272ejb.5 for ; Mon, 21 Sep 2020 14:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RrMcSaTkEOALr4bDHp7ymhMGB8bDnOAQN8954Kq+6mQ=; b=cct76/7OEv+D+OtclOJd+ew8Tpda0f3cJNc/Yas9jXEhPJ8NvawHGSYdQJCM2/NsyN 096Z1UkUQRHqPryA08o7CnBm2QJ8Zrf7ujnTySKPm95vLXQABDZdn9FuXbDxKsc6pPPc id478g66NR0G1aBg+Hwtu8+k2fFt09se2rlBAxUCteV2Y6fwAxSUfktUFFMqOpJ0qolF oZoB/zU/53RwQ4U9TL3Wk0XeQuqaFHJZbKOAiQvCHCVstf4v9YLoR65OzwXMsBytyK0Q IEfP1mNNMPGA7/7EAKDcD4mql1mxwwlJX4Rpi6A4psbdkSB0dTZR1uxBzMSqYjhfm/8O T2Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RrMcSaTkEOALr4bDHp7ymhMGB8bDnOAQN8954Kq+6mQ=; b=tXeDBPAcI6KEP3YccEObQDOzmO/30YlkxscFvAoCULzf+p4UhbkBLumXBXm62bQxFj lpbcBRzSE9aulyu84Y0GlGWIBtayk0WrRwybvDddmqPNEUOnGvEXngDwLDCq5sUxGl+A +80Y517e6r2OgKGZZTGLYzAghACgdtA1EaOh8EYjAD/gnEZxVJ6HZQeQSlgdZRtl5b7C f9GfHWIxLRQz5YBYS2rzvgHeK9N8C/B63hS+f7Ztg6ZSgVoIjgRO9kA2y8zunBJs+ldt 2THRjTJfzv712ejkCj+X5gVE8ekDFLpjP86MGtDCsbIvgsZPaTeOTeYrsmT54ZrhkxuT k+lg== X-Gm-Message-State: AOAM530kjdxwRK7TQA51+1oQ3x/GM1vFEDx/zVEx2qt4DjUyzfmHtdoi CZuwPp3IKNLJUzLC9AgUDY/i7b5vHc8ypCQ1f5ff2w== X-Google-Smtp-Source: ABdhPJx968h4djD01uOVY3VldXIQBDXnuIYpDe00ugTXdoYdTTqKqIqaxCvpPeW9Y4XIDE27c5dv0DtU6rYtDhGxJkI= X-Received: by 2002:a17:906:9389:: with SMTP id l9mr1589347ejx.537.1600725333044; Mon, 21 Sep 2020 14:55:33 -0700 (PDT) MIME-Version: 1.0 References: <20200921211744.24758-1-peterx@redhat.com> <20200921212028.25184-1-peterx@redhat.com> In-Reply-To: <20200921212028.25184-1-peterx@redhat.com> From: Jann Horn Date: Mon, 21 Sep 2020 23:55:06 +0200 Message-ID: Subject: Re: [PATCH 4/5] mm: Do early cow for pinned pages during fork() for ptes To: Peter Xu 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 Content-Type: text/plain; charset="UTF-8" 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 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 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).