Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5816084imw; Wed, 20 Jul 2022 13:09:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vh/759Dp4oLAAOHwqI/m/4lHLl0JfdJV0+khqQ91xf7vxQF1SlzvyvsMBJx7eBrrqP9Ku1 X-Received: by 2002:a63:ec03:0:b0:41a:6f6e:bc3b with SMTP id j3-20020a63ec03000000b0041a6f6ebc3bmr2749996pgh.45.1658347767487; Wed, 20 Jul 2022 13:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658347767; cv=none; d=google.com; s=arc-20160816; b=xgbBHhhdniciFflhLmQFE4UwSYNajrUtgUHvMh6zuBow/ku38B849HCKdADCOPkob0 m9bcRXlEGrRJ98dS3e0h/4SWESIqJnSvE0uhYKulGcFqbw5wGvM3I0vR6qp/czeRSMNd AxQtzswk/ire9dn0U39gH2KlWtvMcg8x5rKdiaRDSFGFLr/wo+eOgvpPjDqhJ+JUbXfy 5vxgw/9j+P00+Z1eTwsokXQ4DPuB+6wj7O/13sXoJTVBpUy9o2LvXPRiMO/9IEagYf6m iMmBhnTFUyDq2/ZSBSXNGnE2Bz9ECqaBref9s7eQAsTLObMpsai0iUuj/7c+hRq9fYEg U4OA== 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=on26dLEQi6M3Nk1WhKYkITpAvq0MqN0cNhOtwo2yh7c=; b=wpambVuMEK2dDy8foVh5G594vv8othnw55dmDbj+1MtrqPatHD8afeJSyNqC3IxunH tj4s4iKk6aB9/dMXgzW0qW5fBWHdmV69ewbdleEyv1yOVlnQXh36hDqMTW5SmVBZQbIR fl90SnKvsRqBxlWtVEVgjoX7jELGGv1M8RO1r9QgdiFE0+ltCJRiQUecEO6UO5LqrRru h3XXLwfjR3XVmqEB3gQmOCwt7xIUwxEiA7U0AHYdknJR2Ssx+qsnamU321Hn08qZQfHt bR+jAJXzIzK44YLkR5pHK9sWb0w5IkKkVWf/HqEFFZSPVDPVO+D6euBHpS3zWL9JVKMl LzeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZrAUY2gn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63b218000000b0040882f6ed9fsi26141516pge.876.2022.07.20.13.09.12; Wed, 20 Jul 2022 13:09:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZrAUY2gn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230242AbiGTTsi (ORCPT + 99 others); Wed, 20 Jul 2022 15:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiGTTse (ORCPT ); Wed, 20 Jul 2022 15:48:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA5E34D83E for ; Wed, 20 Jul 2022 12:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658346511; 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=on26dLEQi6M3Nk1WhKYkITpAvq0MqN0cNhOtwo2yh7c=; b=ZrAUY2gnjh+F3bqPiewufd/Ul076St3+vgM7NYPSZAp4mecXXZescKRpEa7wFbgiFb9264 B4QZbobOa3tNqKOfh6maW+L2sKh+X/VKqLaaMUWvqu6pw6FCGdVoxB+4YHcmeXy8wPEFIl lY9CqgKAQkVUG7JHNU2JA5LNcwPjWTo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-8yH7f-YYOaKlfElVT4od_w-1; Wed, 20 Jul 2022 15:48:30 -0400 X-MC-Unique: 8yH7f-YYOaKlfElVT4od_w-1 Received: by mail-qv1-f71.google.com with SMTP id k7-20020a056214102700b004740a13b3bcso769703qvr.4 for ; Wed, 20 Jul 2022 12:48:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=on26dLEQi6M3Nk1WhKYkITpAvq0MqN0cNhOtwo2yh7c=; b=BQgwA4g7mtPGPuameHHogYkaMc/yel55YxQFSi7J0AiMmyqAK/NymEHOTK4x4fSC8y QQzlXWy9fjosZJIgyJcb9HHcSzX9eZ/eJCfV1JVbjhcA2mMHMr1I9UWID07pb8ZBWAIL /MvZZn5lsNUQwKl60zZI1OCS9eEfynyUgSEAxExKBrWOjGtTKDx/asjx+3rApvp9Eoqm 4wCpHA5tOyYDQdi1hkoKgetKbDZ2MqSQ2itlfIG1ECa4SJYaAdockG2qQVrm6YO77rNG v18X6eaNxyZWbfftXKiGnYisiQ4RuyEqI6encqptv+Xl07y1aXDyGZ0sCd6fTRzFd5Mx eeOQ== X-Gm-Message-State: AJIora8Vj/vyLAXSuxKfsQrrAdkI04IJAdwF6oylDXKeADvALYt6wkh3 7r/OITo/yLGun7tIlNzmEek5jAi3OZ4aUTalZl3pKK/IaMpnVdngmX23AnQWa4Fw1A7LWmzhAc+ FOC0+vpLho+HuFWjjHd0IZvD/ X-Received: by 2002:ae9:e715:0:b0:6b5:db75:150e with SMTP id m21-20020ae9e715000000b006b5db75150emr14737800qka.23.1658346509560; Wed, 20 Jul 2022 12:48:29 -0700 (PDT) X-Received: by 2002:ae9:e715:0:b0:6b5:db75:150e with SMTP id m21-20020ae9e715000000b006b5db75150emr14737766qka.23.1658346509217; Wed, 20 Jul 2022 12:48:29 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-37-74-12-30-48.dsl.bell.ca. [74.12.30.48]) by smtp.gmail.com with ESMTPSA id x9-20020a05620a448900b006b614fe291bsm56937qkp.28.2022.07.20.12.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 12:48:28 -0700 (PDT) Date: Wed, 20 Jul 2022 15:48:27 -0400 From: Peter Xu To: David Hildenbrand Cc: Nadav Amit , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport , Axel Rasmussen , Nadav Amit , Andrea Arcangeli , Andrew Cooper , Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin Subject: Re: [RFC PATCH 01/14] userfaultfd: set dirty and young on writeprotect Message-ID: References: <20220718120212.3180-1-namit@vmware.com> <20220718120212.3180-2-namit@vmware.com> <017facf0-7ef8-3faf-138d-3013a20b37db@redhat.com> <2b4393ce-95c9-dd3e-8495-058a139e771e@redhat.com> <69022bad-d6f1-d830-224d-eb8e5c90d5c7@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <69022bad-d6f1-d830-224d-eb8e5c90d5c7@redhat.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 20, 2022 at 09:33:35PM +0200, David Hildenbrand wrote: > On 20.07.22 21:15, Peter Xu wrote: > > On Wed, Jul 20, 2022 at 05:10:37PM +0200, David Hildenbrand wrote: > >> For pagecache pages it may as well be *plain wrong* to bypass the write > >> fault handler and simply mark pages dirty+map them writable. > > > > Could you elaborate? > > Write-fault handling for some filesystems (that even require this > "slow path") is a bit special. > > For example, do_shared_fault() might have to call page_mkwrite(). > > AFAIK file systems use that for lazy allocation of disk blocks. > If you simply go ahead and map a !dirty pagecache page writable > and mark it dirty, it will not trigger page_mkwrite() and you might > end up corrupting data. > > That's why we the old change_pte_range() code never touched > anything if the pte wasn't already dirty. I don't think that pte_dirty() check was for the pagecache code. For any fs that has page_mkwrite() defined, it'll already have vma_wants_writenotify() return 1, so we'll never try to add write bit, hence we'll never even try to check pte_dirty(). > Because as long as it's not writable, > the FS might have to be informed about the write-unprotect. > > And we end up in the case here for VM_SHARED with vma_wants_writenotify(). > Where we, for example, check > > /* The backer wishes to know when pages are first written to? * > if (vm_ops && (vm_ops->page_mkwrite || vm_ops->pfn_mkwrite))$ > return 1; > > > Long story short, we should be really careful with write-fault handler bypasses, > especially when deciding to set dirty bits. For pagecache pages, we have to be > especially careful. Since you mentioned page_mkwrite, IMHO it's really the write bit not dirty bit that matters here (and IMHO that's why it's called page_mkwrite() not page_mkdirty()). Here Nadav's patch added pte_mkdirty() only if pte_mkwrite() happens. So I'm a bit confused on what's your worry, and what you're against doing. Say, even if with my original proposal to set dirty unconditionally, it'll be still be after the pte_mkwrite(). I never see how that could affect page_mkwrite not to mention it'll not even reach there. > > For exclusive anon pages it's mostly ok, because wp_page_reuse() > doesn't really contain that much magic. The only thing to consider for ordinary > mprotect() is that there is -- IMHO -- absolutely no guarantee that someone will > write to a specific write-unprotected page soon. For uffd-wp-unprotect it might be > easier to guess, especially, if we un-protect only a single page. Yeh, as mentioned I think that's a valid point - looks good to me to attach the dirty bit only when with a hint. Thanks, -- Peter Xu