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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A81FC77B7E for ; Tue, 2 May 2023 16:38:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1909E900006; Tue, 2 May 2023 12:38:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 119E4900002; Tue, 2 May 2023 12:38:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED6B2900006; Tue, 2 May 2023 12:38:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by kanga.kvack.org (Postfix) with ESMTP id CE8C8900002 for ; Tue, 2 May 2023 12:38:58 -0400 (EDT) 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-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-6H4hQv4vPJm40kDTAZTR-Q-1; Tue, 02 May 2023 12:38:57 -0400 X-MC-Unique: 6H4hQv4vPJm40kDTAZTR-Q-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-306286b3573so1896009f8f.2 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=gypjgukwJEVJylZZdlEy+JPd/03Cdmw3v4Nag2ngLLZwVwE1qn/i/bLFz5AdkKRbm7 1AGnK3JzCZhDTSWasynViFaS4kQsYQFazmN/ZezvomPBwhaM7/z29ayLntnjQy9PAk/d 0qsfUMrb0cSbw+Hhdc7eY8KVIL6IBKtroejYmkD+LQIhw70UnLAJE37xj9ozXwzJN+89 Dp8lx7M/d2Buy4C7TJBg984QsCBHnibs01vSoGX34hqGFFnWm8h0kx0ZZj9S3CUSLAHw igDGg8h1JM3gV1oaJ8b97isr3q0CpHf4wo98j6PYJkrdMV075eW6ENrc5S8j8q71fzr2 sjaA== X-Gm-Message-State: AC+VfDzNk2yZkw7elZp6+B4G3Vu89QKLi81h15WGIrK6xV9/8gi2qVzU Jr6FxXm86ZrmxK0r4O3sEIrKESdwxrhEnymv6baD5u3272K7+Q8FTSkUXkdy5vG+a6gDbQ7jnTY sB/rSaGQzCjM= X-Received: by 2002:adf:e70c:0:b0:306:343a:aede with SMTP id c12-20020adfe70c000000b00306343aaedemr3147844wrm.65.1683045536338; Tue, 02 May 2023 09:38:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EmG3a0XC/sdR5E9/CYjrZuR0kZDQoMEtH1BB1xSpjm98KMTPPAbET06MnmTllLBOKtehSVA== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 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