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=-4.1 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 C6E90C433E1 for ; Tue, 11 Aug 2020 15:28:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7CCBE2078E for ; Tue, 11 Aug 2020 15:28:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YB3nCNrl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CCBE2078E 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 05FF36B0006; Tue, 11 Aug 2020 11:28:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 010FD6B0007; Tue, 11 Aug 2020 11:28:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E422E8D0001; Tue, 11 Aug 2020 11:28:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id CD8266B0006 for ; Tue, 11 Aug 2020 11:28:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2FCEB2C9D for ; Tue, 11 Aug 2020 15:28:06 +0000 (UTC) X-FDA: 77138668572.06.sugar74_1f0336826fe3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id EEFF41006983C for ; Tue, 11 Aug 2020 15:28:05 +0000 (UTC) X-HE-Tag: sugar74_1f0336826fe3 X-Filterd-Recvd-Size: 6151 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Aug 2020 15:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597159684; 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=kntGr4b8AGMa950lPlvHff9JxOpLqYWCa31pRH+o+N8=; b=YB3nCNrly9y/cPdKwvY1mMZr4TMu++Qgl5I9b+0gQGFKEPXpGK47uSQkjTgTcrQdD7qB98 D4p3kyphVD+TCHzY0hfjLGerD4wGsMidXL1Ig7HpIvxHo0dRBVqAMst1U0Y7WTRBpagjIG x0KYmbToXxcMnl3xl0iuYpOq783jAGU= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-475-dveSCr6aMm6XAaocUH3kkw-1; Tue, 11 Aug 2020 11:28:02 -0400 X-MC-Unique: dveSCr6aMm6XAaocUH3kkw-1 Received: by mail-qv1-f71.google.com with SMTP id x4so9826217qvu.18 for ; Tue, 11 Aug 2020 08:28:02 -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=kntGr4b8AGMa950lPlvHff9JxOpLqYWCa31pRH+o+N8=; b=iZGjpbEZA/qcQ/yVQZNyGCuYKem8hvSz3pfzeMQ9QmSJcKXHRQRGqYxUGp64p2UPne efrm34F8ecF8LcNhAUFZVPQjKn0ucv4Hyf/MksxC1wc9QhX/LkmazCRVBd5wSRUMAGeS lX4EyGhspoj1ANnREcbY1LaImKjRvwN2QrZfSkqNVaKSOeliYLqhjt7TMzqLsisfr3zn UtPJhUiP5evRpQ9bn4m7OnjWCxWo8QJWWqA9KFkq8XpPsVMySkhAWaes420IYRtDtTQe Hi9RusaM4MoxQyLRChHawD46ISHqexGmN0H5hCgoYHhcRtAB5iHK+0WJSbnECriF5YFo GhVA== X-Gm-Message-State: AOAM531SkfHeyWycEr+TVxnc/Lp3gNuUgY68gXHGE//YgxnLYALAQCGP LfU997E/HJZc6pM39nh+TC9at9nMdPcvJl3+EPpPtb/7Cq+qWctnxivUGui7xbq0Oq6NNqUP97B upiPD6Vt6jtg= X-Received: by 2002:a37:e89:: with SMTP id 131mr1632424qko.279.1597159680784; Tue, 11 Aug 2020 08:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTYChHahVyWGo6bHIYjUeN8Nr/1KqCb72Lik8z7WOi9WG/C2DjjMZQyPq8XLNgOv7ZtnMbsQ== X-Received: by 2002:a37:e89:: with SMTP id 131mr1632402qko.279.1597159680464; Tue, 11 Aug 2020 08:28:00 -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 t187sm4247605qka.26.2020.08.11.08.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 08:27:59 -0700 (PDT) Date: Tue, 11 Aug 2020 11:27:57 -0400 From: Peter Xu To: Linus Torvalds Cc: Jann Horn , Linux-MM , Linux Kernel Mailing List , Andrew Morton , Marty Mcfadden , Andrea Arcangeli , Christoph Hellwig , Oleg Nesterov , Kirill Shutemov , Jan Kara Subject: Re: [PATCH v2] mm/gup: Allow real explicit breaking of COW Message-ID: <20200811152757.GC132381@xz-x1> References: <20200810145701.129228-1-peterx@redhat.com> <20200810191520.GA132381@xz-x1> <20200810215734.GB132381@xz-x1> 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-Rspamd-Queue-Id: EEFF41006983C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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, Aug 11, 2020 at 08:05:22AM -0700, Linus Torvalds wrote: > On Mon, Aug 10, 2020 at 4:39 PM Jann Horn wrote: > > > > The way I understand Peter, he doesn't want to avoid doing COW; he > > wants to decouple userfaultfd-WP's fault handling from COW, so that > > userfaultfd-wp notifies only when a previously-write-protected page is > > actually written to. In other words, he wants the COW to basically > > happen as it happens now, but it should only create a readonly PTE; > > and if someone later triggers a real write fault, the fault handling > > path would run again, and this time userfaultfd-wp would be notified > > before that readonly PTE is turned into a writable one. Yes, that's what I meant. Appreciate your help, Jann. > > Ahh. > > A light goes on. > > Thank you. > > And apologies to Peter - I misread that patch entirely. > > That said, now that I (finally) understand what Peter wants to do, I > don't think the patch does what you say. > > Because the GUP will now indeed avoid userfaultfd-wp unless it's > _actually_ a write, but then any reads will cause a COW that turns > things writable. There is no second fault. > > So now later writes will never cause any userfaultfd-wp notifications at all. > > Which for all I know might be acceptable and ok, but it seems to be > against userfaultfd rules, and against the whole synchronization idea. > > So I think the patch is broken, but I'm less fundamentally concerned about it. > > Because at that point, it's "only" userfaultfd that might break. Right, v2 is broken on that. That's why I pasted another chunk in my previous reply to still inherit the UFFD_WP bit even for COW [1]. Previously it was not needed because UFFD_WP must have been turned off for the pte/pmd/.. before COW happens. However with enforced COW that's not guaranteed any more. I'll post v3 soon. [1] https://lore.kernel.org/lkml/20200810191520.GA132381@xz-x1/ Thanks, -- Peter Xu