Skip to contentSkip to conversation

9p: Avoid creating multiple slab caches with the same name

PATCH In review Pedro Falcato 7 participants 13 messages Aug 7, 2024 – Oct 21, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9p: Avoid creating multiple slab caches with the same name

In the spirit of [1], avoid creating multiple slab caches with the same name. Instead, add the dev_name into the mix.

[1]: https://lore.kernel.org/all/[email protected]/

---
 net/9p/client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/9p/client.c +9 -1
index 5cd94721d97..9e7b9151816 100644
@@ -979,6 +979,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
 	int err;
 	struct p9_client *clnt;
 	char *client_id;
+	char *cache_name;
 
 	clnt = kmalloc(sizeof(*clnt), GFP_KERNEL);
 	if (!clnt)
@@ -1035,15 +1036,22 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
 	if (err)
 		goto close_trans;
 
+	cache_name = kasprintf(GFP_KERNEL, "9p-fcall-cache-%s", dev_name);
+	if (!cache_name) {
+		err = -ENOMEM;
+		goto close_trans;
+	}
+
 	/* P9_HDRSZ + 4 is the smallest packet header we can have that is
 	 * followed by data accessed from userspace by read
 	 */
 	clnt->fcall_cache =
-		kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize,
+		kmem_cache_create_usercopy(cache_name, clnt->msize,
 					   0, 0, P9_HDRSZ + 4,
 					   clnt->msize - (P9_HDRSZ + 4),
 					   NULL);
 
+	kfree(cache_name);
 	return clnt;
 
 close_trans:
Signature · 1 line
2.46.0
#1 lore raw
Quoted 9 lines · Pedro Falcato

In the spirit of [1], avoid creating multiple slab caches with the same name. Instead, add the dev_name into the mix.

[1]: https://lore.kernel.org/all/[email protected]/

---
 net/9p/client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Can this get picked up to rc4 please?

It is causing regressions in my environment

#regzbot introduced: 4c39529663b9

Thanks,
Jason

#2 lore raw
Quoted 5 lines · Jason Gunthorpe
Quoted 3 lines · Pedro Falcato

In the spirit of [1], avoid creating multiple slab caches with the same name. Instead, add the dev_name into the mix.

Quoted 8 lines
Quoted 6 lines

[1]: https://lore.kernel.org/all/[email protected]/

---
 net/9p/client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Can this get picked up to rc4 please?

FWIW, seems to have been picked up into 9pfs-next
(https://github.com/martinetd/linux/commit/79efebae4afc2221fa814c3cae001bede66ab259).
Seems like we're just missing a PR to Linus?

Signature · 1 line
Pedro
#3 lore raw

[reinserting a bit of quotation below for Linus]

TLDR: Linus, I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
), which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there. Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

For details see below.

Quoted 6 lines · Pedro Falcato
Quoted 5 lines · Jason Gunthorpe
Quoted 3 lines · Pedro Falcato

In the spirit of [1], avoid creating multiple slab caches with the same name. Instead, add the dev_name into the mix.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1]: https://lore.kernel.org/all/[email protected]/

---
 net/9p/client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Can this get picked up to rc4 please?

Eric apparently has not much time or upstream work currently (but recently showed up in a discussion about another regression:
https://lore.kernel.org/all/[email protected]/ ).

Quoted 2 lines
Quoted 2 lines

It is causing regressions in my environment
#regzbot introduced: 4c39529663b9

If anyone wonders, that is 4c39529663b931 ("slab: Warn on duplicate cache names when DEBUG_VM=y") [v6.12-rc1]. That's also why I'm CCing Vlastimil, so he knows about this.

Quoted 3 lines

FWIW, seems to have been picked up into 9pfs-next
(https://github.com/martinetd/linux/commit/79efebae4afc2221fa814c3cae001bede66ab259).
Seems like we're just missing a PR to Linus?

In that case: Linus, given the circumstances I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
) directly, which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

Ciao, Thorsten

#4 lore raw
Quoted 31 lines · Thorsten Leemhuis

[reinserting a bit of quotation below for Linus]

TLDR: Linus, I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
), which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there. Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

For details see below.

Quoted 6 lines · Pedro Falcato
Quoted 5 lines · Jason Gunthorpe
Quoted 3 lines · Pedro Falcato

In the spirit of [1], avoid creating multiple slab caches with the same name. Instead, add the dev_name into the mix.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1]: https://lore.kernel.org/all/[email protected]/

---
 net/9p/client.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Can this get picked up to rc4 please?

Eric apparently has not much time or upstream work currently (but recently showed up in a discussion about another regression:
https://lore.kernel.org/all/[email protected]/ ).

Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

It is causing regressions in my environment
#regzbot introduced: 4c39529663b9

If anyone wonders, that is 4c39529663b931 ("slab: Warn on duplicate cache names when DEBUG_VM=y") [v6.12-rc1]. That's also why I'm CCing Vlastimil, so he knows about this.

Quoted 3 lines

FWIW, seems to have been picked up into 9pfs-next
(https://github.com/martinetd/linux/commit/79efebae4afc2221fa814c3cae001bede66ab259).
Seems like we're just missing a PR to Linus?

If was Dominique, not Eric, see:
https://lore.kernel.org/all/[email protected]/

Can you send it as mentioned in the email? :)

Quoted 8 lines

In that case: Linus, given the circumstances I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
) directly, which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

Ciao, Thorsten

#5 lore raw

Vlastimil Babka wrote on Fri, Oct 18, 2024 at 11:38:04PM +0200:

Quoted 6 lines
Quoted 6 lines

In that case: Linus, given the circumstances I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
) directly, which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

Sorry to everyone involved, I've just sent the merge request - I wasn't much at computer in the past few weeks so wanted to wait until I got back home to send it just in case, as I didn't realize this was a recent regression that caused actual harm (it sounded like an old warning that someone just recently happened to hit, and sounded easy enough to work around locally if there is only one specific setup involved); I should have sent the fix separately or at least corrected myself about the schedule.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

It is causing regressions in my environment
#regzbot introduced: 4c39529663b9

If anyone wonders, that is 4c39529663b931 ("slab: Warn on duplicate cache names when DEBUG_VM=y") [v6.12-rc1]. That's also why I'm CCing Vlastimil, so he knows about this.

(that might have been nice to have as a Fixes tag for eventual backport, but at least that commit doesn't appear to have been picked up by stable so it's probably fine as is)

Thanks,

Signature · 1 line
Dominique Martinet | Asmadeus
#6 lore raw
Quoted 20 lines · Dominique Martinet

Vlastimil Babka wrote on Fri, Oct 18, 2024 at 11:38:04PM +0200:

Quoted 6 lines
Quoted 6 lines

In that case: Linus, given the circumstances I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
) directly, which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

Sorry to everyone involved, I've just sent the merge request - I wasn't much at computer in the past few weeks so wanted to wait until I got back home to send it just in case, as I didn't realize this was a recent regression that caused actual harm (it sounded like an old warning that someone just recently happened to hit, and sounded easy enough to work around locally if there is only one specific setup involved); I should have sent the fix separately or at least corrected myself about the schedule.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

It is causing regressions in my environment
#regzbot introduced: 4c39529663b9

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

If anyone wonders, that is 4c39529663b931 ("slab: Warn on duplicate cache names when DEBUG_VM=y") [v6.12-rc1]. That's also why I'm CCing Vlastimil, so he knows about this.

(that might have been nice to have as a Fixes tag for eventual backport, but at least that commit doesn't appear to have been picked up by stable so it's probably fine as is)

Yeah it's missing the tag because I believe Pedro sent the 9p fix before sending the new warning patch itself, so there was even no commit ID yet. The plan was to introduce the warning only after all pre-existing in-tree code that would triggers it was fixed. I just assumed the fix would be mainlined before/at the same time as the warning itself, but forgot to check. In any case if I see e.g. autosel picking the warning patch for stable, I'll object.

Thanks,
Vlastimil

Quoted 2 lines

Thanks,

#7 lore raw
Quoted 37 lines · Vlastimil Babka
Quoted 20 lines · Dominique Martinet

Vlastimil Babka wrote on Fri, Oct 18, 2024 at 11:38:04PM +0200:

Quoted 6 lines
Quoted 6 lines

In that case: Linus, given the circumstances I wonder if it would be best if you could merge the patch at the start of this thread
(https://lore.kernel.org/all/[email protected]/
) directly, which can also be found as 79efebae4afc22 in -next if you prefer to cherry-pick it from there Either now or after 24 to 36 hours, which would give Eric a chance to ACK/NACK this if he sees this mail.

Sorry to everyone involved, I've just sent the merge request - I wasn't much at computer in the past few weeks so wanted to wait until I got back home to send it just in case, as I didn't realize this was a recent regression that caused actual harm (it sounded like an old warning that someone just recently happened to hit, and sounded easy enough to work around locally if there is only one specific setup involved); I should have sent the fix separately or at least corrected myself about the schedule.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

It is causing regressions in my environment
#regzbot introduced: 4c39529663b9

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

If anyone wonders, that is 4c39529663b931 ("slab: Warn on duplicate cache names when DEBUG_VM=y") [v6.12-rc1]. That's also why I'm CCing Vlastimil, so he knows about this.

(that might have been nice to have as a Fixes tag for eventual backport, but at least that commit doesn't appear to have been picked up by stable so it's probably fine as is)

Yeah it's missing the tag because I believe Pedro sent the 9p fix before sending the new warning patch itself, so there was even no commit ID yet. The plan was to introduce the warning only after all pre-existing in-tree code that would triggers it was fixed. I just assumed the fix would be mainlined before/at the same time as the warning itself, but forgot to check. In any case if I see e.g. autosel picking the warning patch for stable, I'll object.

Quoted 2 lines

Thanks,
Vlastimil

FYI, drgn's CI started getting EIO errors from getdents("/sys/kernel/slab") that I bisected to this patch. The problem is that dev_name can be an arbitrary string. In my case, it is "/dev/root". This trips verify_dirent_name(), which fails if a filename contains a slash.

This needs to use a different unique identifier. Maybe clnt->msize? But then the kmem_caches will need to be shared between different mounts using the same msize.

In any case, can this be reverted for now?

Thanks,
Omar

#8 lore raw
Quoted 6 lines · Omar Sandoval

FYI, drgn's CI started getting EIO errors from getdents("/sys/kernel/slab") that I bisected to this patch. The problem is that dev_name can be an arbitrary string. In my case, it is "/dev/root". This trips verify_dirent_name(), which fails if a filename contains a slash.

Bah. Does something silly like this fix it:

--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -977,6 +977,7 @@ static int p9_client_version(struct p9_client *c)
struct p9_client *p9_client_create(const char *dev_name, char *options)

   {
        int err;
  +     static atomic_t seqno = ATOMIC_INIT(0);
        struct p9_client *clnt;
        char *client_id;
        char *cache_name;
  @@ -1036,7 +1037,8 @@ struct p9_client *p9_client_create(const char
*dev_name, char *options)
        if (err)
                goto close_trans;

- cache_name = kasprintf(GFP_KERNEL, "9p-fcall-cache-%s", dev_name);
+ cache_name = kasprintf(GFP_KERNEL,

  +             "9p-fcall-cache-%d", atomic_inc_return(&seqno));
        if (!cache_name) {
                err = -ENOMEM;
                goto close_trans;

(whitespace-damaged, but you get the idea)

Linus

Tested-by
#9 lore raw
Quoted 25 lines · Linus Torvalds
Quoted 6 lines · Omar Sandoval

FYI, drgn's CI started getting EIO errors from getdents("/sys/kernel/slab") that I bisected to this patch. The problem is that dev_name can be an arbitrary string. In my case, it is "/dev/root". This trips verify_dirent_name(), which fails if a filename contains a slash.

Bah. Does something silly like this fix it:

--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -977,6 +977,7 @@ static int p9_client_version(struct p9_client *c)
struct p9_client *p9_client_create(const char *dev_name, char *options)

   {
        int err;
  +     static atomic_t seqno = ATOMIC_INIT(0);
        struct p9_client *clnt;
        char *client_id;
        char *cache_name;
  @@ -1036,7 +1037,8 @@ struct p9_client *p9_client_create(const char
*dev_name, char *options)
        if (err)
                goto close_trans;
Quoted 8 lines

- cache_name = kasprintf(GFP_KERNEL, "9p-fcall-cache-%s", dev_name);
+ cache_name = kasprintf(GFP_KERNEL,

  +             "9p-fcall-cache-%d", atomic_inc_return(&seqno));
        if (!cache_name) {
                err = -ENOMEM;
                goto close_trans;

(whitespace-damaged, but you get the idea)

Yup, that works here.

#11 lore raw
In reply to Omar Sandoval
Quoted 11 lines · Omar Sandoval

On Mon, Oct 21, 2024 at 10:42:02AM +0200, Vlastimil Babka wrote:

FYI, drgn's CI started getting EIO errors from getdents("/sys/kernel/slab") that I bisected to this patch. The problem is that dev_name can be an arbitrary string. In my case, it is "/dev/root". This trips verify_dirent_name(), which fails if a filename contains a slash.

This needs to use a different unique identifier. Maybe clnt->msize? But then the kmem_caches will need to be shared between different mounts using the same msize.

Yep, Dominique mentioned that here too:

https://lore.kernel.org/all/[email protected]/

And yes, slab has internal merging of compatible caches enabled by default. But since it can be disabled, that would indeed result in duplicate names again if 9p mounts didn't track and reuse caches with same msize accross mounts on its own.

Linus's suggestion seems like the easiest fix for now.

Quoted 4 lines

In any case, can this be reverted for now?

Thanks,
Omar

#12 lore raw
In reply to Vlastimil Babka
Quoted 8 lines · Vlastimil Babka
Quoted 3 lines · Thorsten Leemhuis
Quoted 3 lines

FWIW, seems to have been picked up into 9pfs-next
(https://github.com/martinetd/linux/commit/79efebae4afc2221fa814c3cae001bede66ab259).
Seems like we're just missing a PR to Linus?

If was Dominique, not Eric, see:
https://lore.kernel.org/all/[email protected]/

Ahh, sorry, missed that. Apologies again.

Quoted 1 line

Can you send it as mentioned in the email? :)

Dominique: thx for sending that PR!

Ciao, Thorsten