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: <aK5/1so7a0i80+dz@MiWiFi-R3L-srv>
Date: Wed, 27 Aug 2025 11:47:34 +0800
From: Baoquan He <bhe@...hat.com>
To: Kairui Song <kasong@...cent.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>, Nhat Pham <nphamcs@...il.com>,
	Kemeng Shi <shikemeng@...weicloud.com>,
	Baolin Wang <baolin.wang@...ux.alibaba.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 4/9] mm, swap: tidy up swap device and cluster info
 helpers

On 08/23/25 at 03:20am, Kairui Song wrote:
......
> diff --git a/mm/swap.h b/mm/swap.h
> index 223b40f2d37e..7b3efaa51624 100644
> --- a/mm/swap.h
> +++ b/mm/swap.h
> @@ -15,6 +15,8 @@ extern int page_cluster;
>  #define swap_entry_order(order)	0
>  #endif
>  
> +extern struct swap_info_struct *swap_info[];
> +
>  /*
>   * We use this to track usage of a cluster. A cluster is a block of swap disk
>   * space with SWAPFILE_CLUSTER pages long and naturally aligns in disk. All
> @@ -53,9 +55,28 @@ enum swap_cluster_flags {
>  #include <linux/swapops.h> /* for swp_offset */
>  #include <linux/blk_types.h> /* for bio_end_io_t */
>  
> +/*
> + * Callers of all swp_* helpers here must ensure the entry is valid, and
> + * pin the swap device by reference or in other ways.
> + */
> +static inline struct swap_info_struct *swp_type_info(int type)
> +{
> +	struct swap_info_struct *si;
> +
> +	si = READ_ONCE(swap_info[type]); /* rcu_dereference() */
> +	VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */
> +	return si;
> +}
> +
> +static inline struct swap_info_struct *swp_info(swp_entry_t entry)
> +{
> +	return swp_type_info(swp_type(entry));
> +}

swp_type_info() is only used by swp_info() in the whole series, can we
open code it in swp_info()?

If you plan to use it in later phase of swap table patchset, then please
ignore this.

> +
>  static inline struct swap_cluster_info *swp_offset_cluster(
>  		struct swap_info_struct *si, pgoff_t offset)
>  {
> +	VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */
>  	return &si->cluster_info[offset / SWAPFILE_CLUSTER];
>  }
>  
> @@ -65,6 +86,7 @@ static inline struct swap_cluster_info *swap_cluster_lock(
>  {
>  	struct swap_cluster_info *ci = swp_offset_cluster(si, offset);
>  
> +	VM_WARN_ON_ONCE(percpu_ref_is_zero(&si->users)); /* race with swapoff */
>  	spin_lock(&ci->lock);
>  	return ci;
>  }
> @@ -164,7 +186,7 @@ void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma,
>  
>  static inline unsigned int folio_swap_flags(struct folio *folio)
>  {
> -	return swp_swap_info(folio->swap)->flags;
> +	return swp_info(folio->swap)->flags;
>  }
>  
>  /*
> @@ -175,7 +197,7 @@ static inline unsigned int folio_swap_flags(struct folio *folio)
>  static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr,
>  		bool *is_zeromap)
>  {
> -	struct swap_info_struct *sis = swp_swap_info(entry);
> +	struct swap_info_struct *sis = swp_info(entry);
>  	unsigned long start = swp_offset(entry);
>  	unsigned long end = start + max_nr;
>  	bool first_bit;
> @@ -194,7 +216,7 @@ static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr,
>  
>  static inline int non_swapcache_batch(swp_entry_t entry, int max_nr)
>  {
> -	struct swap_info_struct *si = swp_swap_info(entry);
> +	struct swap_info_struct *si = swp_info(entry);
>  	pgoff_t offset = swp_offset(entry);
>  	int i;
>  
> @@ -213,6 +235,11 @@ static inline int non_swapcache_batch(swp_entry_t entry, int max_nr)
>  
>  #else /* CONFIG_SWAP */
>  struct swap_iocb;
> +static inline struct swap_info_struct *swp_info(swp_entry_t entry)
> +{
> +	return NULL;
> +}
> +
>  static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
>  {
>  }
......


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ