Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7140008rwr; Tue, 2 May 2023 10:00:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DgnE0jtnti0AxGGRqFtcgLezkfzGWLKEfz2OA5iH+mDVcI4RsvS3FI0w2f42hmRgGwJX3 X-Received: by 2002:a05:6870:5241:b0:177:c8b4:5c46 with SMTP id o1-20020a056870524100b00177c8b45c46mr6134044oai.33.1683046853781; Tue, 02 May 2023 10:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683046853; cv=none; d=google.com; s=arc-20160816; b=a1KXnM8e82xdlcUJeuD/TT+pQ4GSzxbVxDVhJSEGbxFRtw76y0P1GJKfmvmuAfaBnr 2WOu38ZF1hTMC2P28HomoccFnQR4T5NvoAWNZ3mxH0ay0Mc1BR6LxWJwMeyy8eN+Fh+6 RbafLgyHx15VY12OlP/c+wZSJyY/ZG9sA/iwl6Glz0YFLdxeVUn6sFwfm2jVI5iKHvKP 4koS7cMmL1ESFGlTjdD+I4oQ0ZvIlpyK1FfJyzpefSXgG/u0NyKRRB61AJa7kk4xtQvn sCeTazCQBacLsTPA6UYyzem+KRmg23Ha5bDpQcjGyh9YsKa1RtMaeaEd3wKsFjaixDal YjTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=//ueAGz3V8W57PcJ5eJNuZMKi6dMcIUI5CwGFhgH/3E=; b=TNpluYnWTqEkWatsnOvDttIsv8hVuHmZzUJJ/BlLaZeBovojF4r8Nfr5+vdl5GGsNw s9+2j+pQ4XZnw/Q/Z75atgfupmzMzKNBN5jdng5qht4Fn487RL2eW8t8Wey7gOMkFMWX K2rHDcRUK7cwB3XO1hbdtpHNq2hzoVnhCt9kYb1U1huhliyvmZeT9YzYgJEUiZAQU59x 1hYdnGhFZhihHEcaEG+3CWpZX+zo7lSf658Y32CVybkwjOwShzYSsk2DCaO0f89F4cDp wpHH9slZhgYH8ZKp9K6Nh8Wpdo2MnKwIoEDKUgrUQ93DbggNLXDTcEP2rhIMBT5juKk4 vJYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cWMvu6h8; 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 z11-20020a05687041cb00b001928843b802si1231490oac.295.2023.05.02.10.00.39; Tue, 02 May 2023 10:00:53 -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=cWMvu6h8; 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 S234203AbjEBQjw (ORCPT + 99 others); Tue, 2 May 2023 12:39:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233936AbjEBQjs (ORCPT ); Tue, 2 May 2023 12:39:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826EFE78 for ; Tue, 2 May 2023 09:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683045538; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=//ueAGz3V8W57PcJ5eJNuZMKi6dMcIUI5CwGFhgH/3E=; b=cWMvu6h8uufQ46QoRckkWZjxo5hhvga6v9Cm2XrpblclYyw3SnEZXI/TqTIwZKzI1oT9VQ AW9W/me3WwyXqmKGl6bQTUBd78kMtnK6WcswKNGbFKuk+OHz6A0XFRwfg0YlkKMpesnTqb HrWTZqFzG8eaEGwxl+mI32oN1wVbMm8= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-qwiQQ8I-O6ikAskp3fgijA-1; Tue, 02 May 2023 12:38:57 -0400 X-MC-Unique: qwiQQ8I-O6ikAskp3fgijA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-302cdf5d034so2363535f8f.0 for ; Tue, 02 May 2023 09:38:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683045536; x=1685637536; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=//ueAGz3V8W57PcJ5eJNuZMKi6dMcIUI5CwGFhgH/3E=; b=SqtaqoDBavjtXG3+D8//xm3rpveqrJiMGF85tPKEPj6h1naFElY5QN+Q6EUBQe9O5n h/bOZGRWRT9FmWamGuyxtuQtgFrfoImZQXrfWwKYuD7hSJJbLRw7VdDFm0p2gMVriKfu YjlsAY63sqYL4R0YJuH4vb3R2Emoo7kmX10ZxsN25K5Pxgzj1gpfD5MZy4V0aMAPAYSg uNgiUbqEowiKAa+m0Qq3ceuucXguJI4XJqUYCAcU3jsmXU+uCaXosfCux7Ekrfm+aJWP z0n2q24xUsrrvh2xPAb+5ebTVL60HFJpS0nbd3cyv6Yy0EMHQHwL2+XYE1nmH56T6u9U z0cQ== X-Gm-Message-State: AC+VfDy5g/H6vqSR9CuxG5ohRURDS+QJnI9cCwCxDJQKUQOEAGe6cC62 5I8nbuulgnbmq0Bh1zJK2D1S/mzQfhr2YPpjfnQAxVFns8OSY9A/3/Fb+eifQ3Oo7eMFh7hWzM+ zIkAnWOGOo8U+eoahNsOfclHV X-Received: by 2002:adf:e70c:0:b0:306:343a:aede with SMTP id c12-20020adfe70c000000b00306343aaedemr3147804wrm.65.1683045536333; Tue, 02 May 2023 09:38:56 -0700 (PDT) X-Received: by 2002:adf:e70c:0:b0:306:343a:aede with SMTP id c12-20020adfe70c000000b00306343aaedemr3147785wrm.65.1683045535940; Tue, 02 May 2023 09:38:55 -0700 (PDT) Received: from ?IPV6:2003:cb:c700:2400:6b79:2aa:9602:7016? (p200300cbc70024006b7902aa96027016.dip0.t-ipconnect.de. [2003:cb:c700:2400:6b79:2aa:9602:7016]) by smtp.gmail.com with ESMTPSA id e14-20020adfef0e000000b003063938bf7bsm1902212wro.86.2023.05.02.09.38.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 May 2023 09:38:55 -0700 (PDT) Message-ID: <56696a72-24fa-958e-e6a1-7a17c9e54081@redhat.com> Date: Tue, 2 May 2023 18:38:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v7 1/3] mm/mmap: separate writenotify and dirty tracking logic Content-Language: en-US To: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Jason Gunthorpe , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Oleg Nesterov , Jason Gunthorpe , John Hubbard , Jan Kara , "Kirill A . Shutemov" , Pavel Begunkov , Mika Penttila , Dave Chinner , Theodore Ts'o , Peter Xu , Matthew Rosato , "Paul E . McKenney" , Christian Borntraeger References: <72a90af5a9e4445a33ae44efa710f112c2694cb1.1683044162.git.lstoakes@gmail.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <72a90af5a9e4445a33ae44efa710f112c2694cb1.1683044162.git.lstoakes@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 02.05.23 18:34, Lorenzo Stoakes wrote: > vma_wants_writenotify() is specifically intended for setting PTE page table > flags, accounting for existing PTE flag state and whether that might > already be read-only while mixing this check with a check whether the > filesystem performs dirty tracking. > > Separate out the notions of dirty tracking and a PTE write notify checking > in order that we can invoke the dirty tracking check from elsewhere. > > Note that this change introduces a very small duplicate check of the > separated out vm_ops_needs_writenotify(). This is necessary to avoid making > vma_needs_dirty_tracking() needlessly complicated (e.g. passing a > check_writenotify flag or having it assume this check was already > performed). This is such a small check that it doesn't seem too egregious > to do this. > > Signed-off-by: Lorenzo Stoakes > Reviewed-by: John Hubbard > Reviewed-by: Mika Penttilä > Reviewed-by: Jan Kara > Reviewed-by: Jason Gunthorpe > --- > include/linux/mm.h | 1 + > mm/mmap.c | 36 +++++++++++++++++++++++++++--------- > 2 files changed, 28 insertions(+), 9 deletions(-) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 27ce77080c79..7b1d4e7393ef 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2422,6 +2422,7 @@ extern unsigned long move_page_tables(struct vm_area_struct *vma, > #define MM_CP_UFFD_WP_ALL (MM_CP_UFFD_WP | \ > MM_CP_UFFD_WP_RESOLVE) > > +bool vma_needs_dirty_tracking(struct vm_area_struct *vma); > int vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); > static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma) > { > diff --git a/mm/mmap.c b/mm/mmap.c > index 5522130ae606..295c5f2e9bd9 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1475,6 +1475,31 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg) > } > #endif /* __ARCH_WANT_SYS_OLD_MMAP */ > > +/* Do VMA operations imply write notify is required? */ > +static bool vm_ops_needs_writenotify(const struct vm_operations_struct *vm_ops) > +{ > + return vm_ops && (vm_ops->page_mkwrite || vm_ops->pfn_mkwrite); > +} > + > +/* > + * Does this VMA require the underlying folios to have their dirty state > + * tracked? > + */ > +bool vma_needs_dirty_tracking(struct vm_area_struct *vma) > +{ Sorry for not noticing this earlier, but ... what about MAP_PRIVATE mappings? When we write, we populate an anon page, which will work as expected ... because we don't have to notify the fs? I think you really also want the "If it was private or non-writable, the write bit is already clear */" part as well and remove "false" in that case. Or was there a good reason to disallow private mappings as well? -- Thanks, David / dhildenb