From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB8FE24BCE8 for ; Wed, 10 Sep 2025 08:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757492768; cv=none; b=X6XaX9lh+9QU9zhpLXc4sbLdzdy1jryLORj+7RY3I3eLKZppfyRjsb8/8Rnur7+tz2UOr0lBzPwJ6l8q5EkCPuWt71rm+vmeblwIK9GigoQGCaK0oPcQyO3CPPhTrwBiBFFqCVn091WZmtKCmnNpgQfZPXeIfWg/3+fYJhQclwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757492768; c=relaxed/simple; bh=LGDx5UXVQvNOddW1bShX1KCkaUIEpgFgG6LEtTXv7kU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=bvoythwFZ1SpslDT8rruiZrYON5fexJXzvj8lN+K1jnV8Nzlm8pyfjckmuW1iKqb17fSVEgldS9WrNTiaqhT+Y8I+qXXmGwCJBRD4UO2RHIlRCsum0EutiMsENMa0AP99wKDIR0eCbzvfYQy175zSi5gzGdzorbKsc9vU/+D/b8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iVsFuY7B; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iVsFuY7B" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-74382048b8cso4618569a34.3 for ; Wed, 10 Sep 2025 01:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757492765; x=1758097565; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nQH7snnNQnRZRbg0xLLdaSxYnYx9rFgR1u9eFyrWIv8=; b=iVsFuY7BsYTNYGFv2qtJNSI5I3Kj1rvjngN3lOdOqvQYZNj5jWl8TGX0a76wh5Ls+x OXktHxwGlcrHxoqIVCwI8dgYaJ/05lcQqG0CWAkm3+1kFSjFPKZM0DkqWhtWbqe3uh4U f03T5BPutuT4+AyIP8oDvkF73b+5+H34wPYV1sm1VNYYXuZqzZGaGTdTmFBUcGU95Da2 uBLfNbv+N1gWiRq2Do941zW9NJKxnWM0QPgzsWVDf/y+RKgFzVc7QdccVO+oRFYW2ALs o/J7s+8jd9liYRoUEl1xub0vfsnECwQTOjtZGa3yg5/DPX3LWnyiklD5x45dJj8Qwpl7 BFyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757492765; x=1758097565; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nQH7snnNQnRZRbg0xLLdaSxYnYx9rFgR1u9eFyrWIv8=; b=LbM8+hrMHKoKQPbfePN9bWTM7Q4KoWWpfTtKJIrTpkvQ8CmSq2IFLvK81Oq2AEQ4Mj Hz2iC+tkEpsABKmJWiygIA29tUI9+Wlfii08pjVaix1GEaDdbyvcWHq0XGMWn72AEabh aKzuiYp+kUYVwXmFrez38S7ZqMUUCg2bvM0NwkuJjdFDkVySFlIIos662n/nIFDTMUbj TzL7V6YyS6DlOlRr79jUzk74EOa/0T8B2grXUgRJnNAenlbxvMnLFDyrzZ+V4uTRoEqd 9DkvxyXKonA9Ry8s/or2uzpoNBFnfkgfWBUWAUD5qteiu6R+kcdKHY636xKb8nsJdOXM wjDA== X-Forwarded-Encrypted: i=1; AJvYcCXvNQRu1/+nfSpZemM/MzIDnH5OG1tW4xmy6o5O31l/cZlI4VZkvs1REfD7LSDfECp7MmwkR2ZcdZKZpnE+@vger.kernel.org X-Gm-Message-State: AOJu0YxhondddwRYIpK09D8zQMRh58OpcjoIuUg5qCroSwiSnydICK9m MUPaU26d/+5W667LXjE5n5gT2BdbYE5pX46Eyxm7bpZAd/GCWSCvki/BW3CSaa27qzhd32QH0F+ 0xILfBtJakNTzjHOt2x2c1tu8cYTaM68= X-Gm-Gg: ASbGnctO9khFP4ln61DcXmkJhx5e8QUkHPLTe41t9EFmecWpSYD9avXxf/lJNh+QGMt Jl1fbp9RXJJZ1bGV93UWd3nQO7TjTsOUcyNJjow3vWUc9GHHUK8ILMz2pEibsmj+pCnhAkr5BQx ZneKtMqIGcy/Q3bOOHP3Nnkv0+ZVGUYC+amLTDOXKpS39JMcBzcSuDvDNdCvDhqziL6NnVaKZm8 5nD4w== X-Google-Smtp-Source: AGHT+IG8+X4z7lWHsoiDJ8ey4B9KiZeLoM8QTORaK4x4ttFg5WhTeM8qOcmzY4k1bJV831pksGGd1X5634WxyYNLQpo= X-Received: by 2002:a05:6871:4b10:b0:31d:6b5b:6b57 with SMTP id 586e51a60fabf-32264c16755mr7048854fac.30.1757492764639; Wed, 10 Sep 2025 01:26:04 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250909095611.803898-1-zhangchunyan@iscas.ac.cn> <20250909095611.803898-2-zhangchunyan@iscas.ac.cn> <6b2f12aa-8ed9-476d-a69d-f05ea526f16a@redhat.com> In-Reply-To: <6b2f12aa-8ed9-476d-a69d-f05ea526f16a@redhat.com> From: Chunyan Zhang Date: Wed, 10 Sep 2025 16:25:28 +0800 X-Gm-Features: Ac12FXx-v6pjQQB1q-gdPDWGiaVNDNxmW_UZ1a0xUB3t-SaqR__1RTrhpm4oqiU Message-ID: Subject: Re: [PATCH V10 1/5] mm: softdirty: Add pte_soft_dirty_available() To: David Hildenbrand Cc: Chunyan Zhang , linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Deepak Gupta , Ved Shanbhogue , Alexander Viro , Christian Brauner , Jan Kara , Andrew Morton , Peter Xu , Arnd Bergmann , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Axel Rasmussen , Yuanchu Xie Content-Type: text/plain; charset="UTF-8" Hi David, On Tue, 9 Sept 2025 at 19:42, David Hildenbrand wrote: > > On 09.09.25 11:56, Chunyan Zhang wrote: > > Some platforms can customize the PTE soft dirty bit and make it unavailable > > even if the architecture allows providing the PTE resource. > > > > Add an API which architectures can define their specific implementations > > to detect if the PTE soft-dirty bit is available, on which the kernel > > is running. > > > > Signed-off-by: Chunyan Zhang > > --- > > fs/proc/task_mmu.c | 17 ++++++++++++++++- > > include/linux/pgtable.h | 10 ++++++++++ > > mm/debug_vm_pgtable.c | 9 +++++---- > > mm/huge_memory.c | 10 ++++++---- > > mm/internal.h | 2 +- > > mm/mremap.c | 10 ++++++---- > > mm/userfaultfd.c | 6 ++++-- > > 7 files changed, 48 insertions(+), 16 deletions(-) > > > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > > index 29cca0e6d0ff..20a609ec1ba6 100644 > > --- a/fs/proc/task_mmu.c > > +++ b/fs/proc/task_mmu.c > > @@ -1058,7 +1058,7 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) > > * -Werror=unterminated-string-initialization warning > > * with GCC 15 > > */ > > - static const char mnemonics[BITS_PER_LONG][3] = { > > + static char mnemonics[BITS_PER_LONG][3] = { > > /* > > * In case if we meet a flag we don't know about. > > */ > > @@ -1129,6 +1129,16 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) > > [ilog2(VM_SEALED)] = "sl", > > #endif > > }; > > +/* > > + * We should remove the VM_SOFTDIRTY flag if the PTE soft-dirty bit is > > + * unavailable on which the kernel is running, even if the architecture > > + * allows providing the PTE resource and soft-dirty is compiled in. > > + */ > > +#ifdef CONFIG_MEM_SOFT_DIRTY > > + if (!pte_soft_dirty_available()) > > + mnemonics[ilog2(VM_SOFTDIRTY)][0] = 0; > > +#endif > > + > > size_t i; > > > > seq_puts(m, "VmFlags: "); > > @@ -1531,6 +1541,8 @@ static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, > > static inline void clear_soft_dirty(struct vm_area_struct *vma, > > unsigned long addr, pte_t *pte) > > { > > + if (!pte_soft_dirty_available()) > > + return; > > /* > > * The soft-dirty tracker uses #PF-s to catch writes > > * to pages, so write-protect the pte as well. See the > > @@ -1566,6 +1578,9 @@ static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, > > { > > pmd_t old, pmd = *pmdp; > > > > + if (!pte_soft_dirty_available()) > > + return; > > + > > if (pmd_present(pmd)) { > > /* See comment in change_huge_pmd() */ > > old = pmdp_invalidate(vma, addr, pmdp); > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > > index 4c035637eeb7..c0e2a6dc69f4 100644 > > --- a/include/linux/pgtable.h > > +++ b/include/linux/pgtable.h > > @@ -1538,6 +1538,15 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) > > #endif > > > > #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY > > + > > +/* > > + * Some platforms can customize the PTE soft dirty bit and make it unavailable > > + * even if the architecture allows providing the PTE resource. > > + */ > > +#ifndef pte_soft_dirty_available > > +#define pte_soft_dirty_available() (true) > > +#endif > > + > > #ifndef CONFIG_ARCH_ENABLE_THP_MIGRATION > > static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd) > > { > > @@ -1555,6 +1564,7 @@ static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd) > > } > > #endif > > #else /* !CONFIG_HAVE_ARCH_SOFT_DIRTY */ > > +#define pte_soft_dirty_available() (false) > > static inline int pte_soft_dirty(pte_t pte) > > { > > return 0; > > diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c > > index 830107b6dd08..98ed7e22ccec 100644 > > --- a/mm/debug_vm_pgtable.c > > +++ b/mm/debug_vm_pgtable.c > > @@ -690,7 +690,7 @@ static void __init pte_soft_dirty_tests(struct pgtable_debug_args *args) > > { > > pte_t pte = pfn_pte(args->fixed_pte_pfn, args->page_prot); > > > > - if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY)) > > + if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) || !pte_soft_dirty_available()) > > I suggest that you instead make pte_soft_dirty_available() be false without CONFIG_MEM_SOFT_DIRTY. > > e.g., for the default implementation > > define pte_soft_dirty_available() IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) > > That way you can avoid some ifefs and cleanup these checks. Do you mean something like this: --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1538,6 +1538,16 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) #endif #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY +#ifndef arch_soft_dirty_available +#define arch_soft_dirty_available() (true) +#endif +#define pgtable_soft_dirty_supported() (IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) && arch_soft_dirty_available()) + #ifndef CONFIG_ARCH_ENABLE_THP_MIGRATION static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd) { @@ -1555,6 +1565,7 @@ static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd) } #endif #else /* !CONFIG_HAVE_ARCH_SOFT_DIRTY */ +#define pgtable_soft_dirty_supported() (false) > > > But as we do also have PMD soft-dirty support, I guess we would want to call this > something more abstract "pgtable_soft_dirty_available" or "pgtable_soft_dirty_supported" > > -- > Cheers > > David / dhildenb >