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: <20250910134240.GA1111@cmpxchg.org>
Date: Wed, 10 Sep 2025 09:42:40 -0400
From: Johannes Weiner <hannes@...xchg.org>
To: Yosry Ahmed <yosry.ahmed@...ux.dev>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
	Nhat Pham <nphamcs@...il.com>,
	Chengming Zhou <zhouchengming@...edance.com>, linux-mm@...ck.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] mm: zswap: interact directly with zsmalloc

On Tue, Sep 09, 2025 at 08:10:43PM +0000, Yosry Ahmed wrote:
> On Tue, Sep 09, 2025 at 04:01:56PM +0100, Johannes Weiner wrote:
> > On Fri, Sep 05, 2025 at 06:53:15PM +0000, Yosry Ahmed wrote:
> > > On Fri, Aug 29, 2025 at 05:15:26PM +0100, Johannes Weiner wrote:
> > > > zswap goes through the zpool layer to enable runtime-switching of
> > > > allocator backends for compressed data. However, since zbud and z3fold
> > > > were removed in 6.15, zsmalloc has been the only option available.
> > > > 
> > > > As such, the zpool indirection is unnecessary. Make zswap deal with
> > > > zsmalloc directly. This is comparable to zram, which also directly
> > > > interacts with zsmalloc and has never supported a different backend.
> > > > 
> > > > Note that this does not preclude future improvements and experiments
> > > > with different allocation strategies. Should it become necessary, it's
> > > > possible to provide an alternate implementation for the zsmalloc API,
> > > > selectable at compile time. However, zsmalloc is also rather mature
> > > > and feature rich, with years of widespread production exposure; it's
> > > > encouraged to make incremental improvements rather than fork it.
> > > > 
> > > > In any case, the complexity of runtime pluggability seems excessive
> > > > and unjustified at this time. Switch zswap to zsmalloc to remove the
> > > > last user of the zpool API.
> > > > 
> > > > Signed-off-by: Johannes Weiner <hannes@...xchg.org>
> > > > ---
> > > [..]
> > > > @@ -315,52 +292,29 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
> > > >  error:
> > > >  	if (pool->acomp_ctx)
> > > >  		free_percpu(pool->acomp_ctx);
> > > > -	if (pool->zpool)
> > > > -		zpool_destroy_pool(pool->zpool);
> > > > +	if (pool->zs_pool)
> > > > +		zs_destroy_pool(pool->zs_pool);
> > > >  	kfree(pool);
> > > >  	return NULL;
> > > >  }
> > > >  
> > > >  static struct zswap_pool *__zswap_pool_create_fallback(void)
> > > >  {
> > > > -	bool has_comp, has_zpool;
> > > > -
> > > > -	has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
> > > > -	if (!has_comp && strcmp(zswap_compressor,
> > > > -				CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
> > > > +	if (!crypto_has_acomp(zswap_compressor, 0, 0) &&
> > > > +	    strcmp(zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
> > > >  		pr_err("compressor %s not available, using default %s\n",
> > > >  		       zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
> > > >  		param_free_charp(&zswap_compressor);
> > > >  		zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
> > > > -		has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
> > > > -	}
> > > > -	if (!has_comp) {
> > > > -		pr_err("default compressor %s not available\n",
> > > > -		       zswap_compressor);
> > > > -		param_free_charp(&zswap_compressor);
> > > > -		zswap_compressor = ZSWAP_PARAM_UNSET;
> > > > -	}
> > > > -
> > > > -	has_zpool = zpool_has_pool(zswap_zpool_type);
> > > > -	if (!has_zpool && strcmp(zswap_zpool_type,
> > > > -				 CONFIG_ZSWAP_ZPOOL_DEFAULT)) {
> > > > -		pr_err("zpool %s not available, using default %s\n",
> > > > -		       zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT);
> > > > -		param_free_charp(&zswap_zpool_type);
> > > > -		zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
> > > > -		has_zpool = zpool_has_pool(zswap_zpool_type);
> > > > -	}
> > > > -	if (!has_zpool) {
> > > > -		pr_err("default zpool %s not available\n",
> > > > -		       zswap_zpool_type);
> > > > -		param_free_charp(&zswap_zpool_type);
> > > > -		zswap_zpool_type = ZSWAP_PARAM_UNSET;
> > > > +		if (!crypto_has_acomp(zswap_compressor, 0, 0)) {
> > > > +			pr_err("default compressor %s not available\n",
> > > > +			       zswap_compressor);
> > > > +			zswap_compressor = ZSWAP_PARAM_UNSET;
> > > > +			return NULL;
> > > > +		}
> > > 
> > > Hmm it seems like there may be a change of behavior here. If
> > > zswap_compressor == CONFIG_ZSWAP_COMPRESSOR_DEFAULT at the beginning and
> > > crypto_has_acomp() returns false, the old code will go into the second
> > > if (!has_comp) block, printing an error, freeing the string, and setting
> > > zswap_compressor to ZSWAP_PARAM_UNSET, then we eventually return NULL.
> > > 
> > > It seems like the new code will just call zswap_pool_create() anyway.
> > > 
> > > Am I missing something here?
> > 
> > I don't think that scenario is possible, due to the way the Kconfig
> > works. Whatever backend I select for CONFIG_ZSWAP_COMPRESSOR_DEFAULT
> > pulls in the crypto module as built-in/=y. It should always be there.
> 
> What if none of the CONFIG_ZSWAP_COMPRESSOR_DEFAULT_* options are
> selected (i.e. empty string)? Also, can CONFIG_ZSWAP_COMPRESSOR_DEFAULT
> be set directly to an arbitrary string?

No, that isn't possible. It's a multiple choice symbol that forces one
of the options and has a valid default value. I tried to made it an
empty string in .config by hand, but oldconfig restored it; if I
remove the DEFAULT_* line entirely, oldconfig reprompts.

> I would prefer if the code behavior did not change to rely on the config
> possibilities.

How about this on top?

>From f842e1338594c4b78456f878731a261a074d5277 Mon Sep 17 00:00:00 2001
From: Johannes Weiner <hannes@...xchg.org>
Date: Wed, 10 Sep 2025 09:00:01 -0400
Subject: [PATCH] yosry

Signed-off-by: Johannes Weiner <hannes@...xchg.org>
---
 mm/zswap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/zswap.c b/mm/zswap.c
index c88ad61b232c..991fe380c61e 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -314,6 +314,10 @@ static struct zswap_pool *__zswap_pool_create_fallback(void)
 		}
 	}
 
+	/* Kconfig bug? */
+	if (WARN_ON(!crypto_has_acomp(zswap_compressor, 0, 0)))
+		return NULL;
+
 	return zswap_pool_create(zswap_compressor);
 }
 
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ