lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMgjq7Bc6r2=BcAPCeVPcVJ_hP8bXTs_pya2fWg8ZL-vTG9SAg@mail.gmail.com>
Date: Fri, 12 Sep 2025 20:36:38 +0800
From: Kairui Song <ryncsn@...il.com>
To: Baolin Wang <baolin.wang@...ux.alibaba.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>, 
	Matthew Wilcox <willy@...radead.org>, Hugh Dickins <hughd@...gle.com>, Chris Li <chrisl@...nel.org>, 
	Barry Song <baohua@...nel.org>, Baoquan He <bhe@...hat.com>, Nhat Pham <nphamcs@...il.com>, 
	Kemeng Shi <shikemeng@...weicloud.com>, Ying Huang <ying.huang@...ux.alibaba.com>, 
	Johannes Weiner <hannes@...xchg.org>, David Hildenbrand <david@...hat.com>, 
	Yosry Ahmed <yosryahmed@...gle.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, 
	Zi Yan <ziy@...dia.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 09/15] mm/shmem, swap: remove redundant error handling
 for replacing folio

On Fri, Sep 12, 2025 at 4:22 PM Baolin Wang
<baolin.wang@...ux.alibaba.com> wrote:
> On 2025/9/11 00:08, Kairui Song wrote:
> > From: Kairui Song <kasong@...cent.com>
> >
> > Shmem may replace a folio in the swap cache if the cached one doesn't
> > fit the swapin's GFP zone. When doing so, shmem has already double
> > checked that the swap cache folio is locked, still has the swap cache
> > flag set, and contains the wanted swap entry. So it is impossible to
> > fail due to an XArray mismatch. There is even a comment for that.
> >
> > Delete the defensive error handling path, and add a WARN_ON instead:
> > if that happened, something has broken the basic principle of how the
> > swap cache works, we should catch and fix that.
> >
> > Signed-off-by: Kairui Song <kasong@...cent.com>
> > Reviewed-by: David Hildenbrand <david@...hat.com>
> > ---
> >   mm/shmem.c | 42 ++++++++++++------------------------------
> >   1 file changed, 12 insertions(+), 30 deletions(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index 410f27bc4752..5f395fab489c 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -1661,13 +1661,13 @@ int shmem_writeout(struct folio *folio, struct swap_iocb **plug,
> >               }
> >
> >               /*
> > -              * The delete_from_swap_cache() below could be left for
> > +              * The swap_cache_del_folio() below could be left for
> >                * shrink_folio_list()'s folio_free_swap() to dispose of;
> >                * but I'm a little nervous about letting this folio out of
> >                * shmem_writeout() in a hybrid half-tmpfs-half-swap state
> >                * e.g. folio_mapping(folio) might give an unexpected answer.
> >                */
> > -             delete_from_swap_cache(folio);
> > +             swap_cache_del_folio(folio);
> >               goto redirty;
> >       }
> >       if (nr_pages > 1)
> > @@ -2045,7 +2045,7 @@ static struct folio *shmem_swap_alloc_folio(struct inode *inode,
> >       new->swap = entry;
> >
> >       memcg1_swapin(entry, nr_pages);
> > -     shadow = get_shadow_from_swap_cache(entry);
> > +     shadow = swap_cache_get_shadow(entry);
>
> Again, there are still some issues with the patch split. The swapcache
> related APIs replacement should be placed in Patch 8, otherwise there
> will be buidling errors after applying Patch 8.
>
> With this issue fixed:
> Reviewed-by: Baolin Wang <baolin.wang@...ux.alibaba.com>
>

Hi Baolin

Yeah you are right, I need to move these few changes to patch 8.

BTW I also found that the WARN_ON and irq unlock needs following fix,
the stats update need to be done with irq disabled:

diff --git a/mm/shmem.c b/mm/shmem.c
index 957e40caba6e..c4d491c93506 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2121,14 +2121,14 @@ static int shmem_replace_folio(struct folio
**foliop, gfp_t gfp,
        /* Swap cache still stores N entries instead of a high-order entry */
        xa_lock_irq(&swap_mapping->i_pages);
        for (i = 0; i < nr_pages; i++) {
-               WARN_ON_ONCE(xas_store(&xas, new));
+               WARN_ON_ONCE(xas_store(&xas, new) != old);
                xas_next(&xas);
        }
-       xa_unlock_irq(&swap_mapping->i_pages);

        mem_cgroup_replace_folio(old, new);
        shmem_update_stats(new, nr_pages);
        shmem_update_stats(old, -nr_pages);
+       xa_unlock_irq(&swap_mapping->i_pages);

        folio_add_lru(new);
        *foliop = new;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ