Skip to contentSkip to conversation

nfsd: register pernet ops last, unregister first

PATCH In review J. Bruce Fields 2 participants 4 messages Feb 3, 2021

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

PATCH 1/1 nfsd: register pernet ops last, unregister first

From: "J. Bruce Fields" <[email protected]>

These pernet operations may depend on stuff set up or torn down in the module init/exit functions. And they may be called at any time in between. So it makes more sense for them to be the last to be registered in the init function, and the first to be unregistered in the exit function.

In particular, without this, the drc slab is being destroyed before all the per-net drcs are shut down, resulting in an "Objects remaining in nfsd_drc on __kmem_cache_shutdown()" warning in exit_nfsd.

Fixes 3ba75830ce17 "nfsd4: drc containerization"
---
 fs/nfsd/nfsctl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/nfsctl.c +7 -7
index f6d5d783f4a4..0759e589ab52 100644
@@ -1522,12 +1522,9 @@ static int __init init_nfsd(void)
 	int retval;
 	printk(KERN_INFO "Installing knfsd (copyright (C) 1996 [email protected]).\n");
 
-	retval = register_pernet_subsys(&nfsd_net_ops);
-	if (retval < 0)
-		return retval;
 	retval = register_cld_notifier();
 	if (retval)
-		goto out_unregister_pernet;
+		return retval;
 	retval = nfsd4_init_slabs();
 	if (retval)
 		goto out_unregister_notifier;
@@ -1544,9 +1541,14 @@ static int __init init_nfsd(void)
 		goto out_free_lockd;
 	retval = register_filesystem(&nfsd_fs_type);
 	if (retval)
+		goto out_free_exports;
+	retval = register_pernet_subsys(&nfsd_net_ops);
+	if (retval < 0)
 		goto out_free_all;
 	return 0;
 out_free_all:
+	unregister_pernet_subsys(&nfsd_net_ops);
+out_free_exports:
 	remove_proc_entry("fs/nfs/exports", NULL);
 	remove_proc_entry("fs/nfs", NULL);
 out_free_lockd:
@@ -1559,13 +1561,12 @@ static int __init init_nfsd(void)
 	nfsd4_free_slabs();
 out_unregister_notifier:
 	unregister_cld_notifier();
-out_unregister_pernet:
-	unregister_pernet_subsys(&nfsd_net_ops);
 	return retval;
 }
 
 static void __exit exit_nfsd(void)
 {
+	unregister_pernet_subsys(&nfsd_net_ops);
 	nfsd_drc_slab_free();
 	remove_proc_entry("fs/nfs/exports", NULL);
 	remove_proc_entry("fs/nfs", NULL);
@@ -1575,7 +1576,6 @@ static void __exit exit_nfsd(void)
 	nfsd4_exit_pnfs();
 	unregister_filesystem(&nfsd_fs_type);
 	unregister_cld_notifier();
-	unregister_pernet_subsys(&nfsd_net_ops);
 }
 
 MODULE_AUTHOR("Olaf Kirch <[email protected]>");
Signature · 1 line
2.29.2
#1 lore raw

Hi Bruce-

Quoted 10 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

These pernet operations may depend on stuff set up or torn down in the module init/exit functions. And they may be called at any time in between. So it makes more sense for them to be the last to be registered in the init function, and the first to be unregistered in the exit function.

Quoted 7 lines

In particular, without this, the drc slab is being destroyed before all the per-net drcs are shut down, resulting in an "Objects remaining in nfsd_drc on __kmem_cache_shutdown()" warning in exit_nfsd.

Fixes 3ba75830ce17 "nfsd4: drc containerization"

I can't tell how urgent this is. Does it belong in 5.11-rc?

Quoted 63 lines

---
fs/nfsd/nfsctl.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/nfsctl.c +4 -4
index f6d5d783f4a4..0759e589ab52 100644
@@ -1522,12 +1522,9 @@ static int __init init_nfsd(void)
 	int retval;
 	printk(KERN_INFO "Installing knfsd (copyright (C) 1996 [email protected]).\n");
 
-	retval = register_pernet_subsys(&nfsd_net_ops);
-	if (retval < 0)
-		return retval;
 	retval = register_cld_notifier();
 	if (retval)
-		goto out_unregister_pernet;
+		return retval;
 	retval = nfsd4_init_slabs();
 	if (retval)
 		goto out_unregister_notifier;
@@ -1544,9 +1541,14 @@ static int __init init_nfsd(void)
 		goto out_free_lockd;
 	retval = register_filesystem(&nfsd_fs_type);
 	if (retval)
+		goto out_free_exports;
+	retval = register_pernet_subsys(&nfsd_net_ops);
+	if (retval < 0)
 		goto out_free_all;
 	return 0;

out_free_all:

fs/nfsd/nfsctl.c +2 -0
+	unregister_pernet_subsys(&nfsd_net_ops);
+out_free_exports:
	remove_proc_entry("fs/nfs/exports", NULL);
	remove_proc_entry("fs/nfs", NULL);

out_free_lockd:

fs/nfsd/nfsctl.c +0 -0
@@ -1559,13 +1561,12 @@ static int __init init_nfsd(void)
 	nfsd4_free_slabs();

out_unregister_notifier:

	unregister_cld_notifier();
fs/nfsd/nfsctl.c +0 -2
-out_unregister_pernet:
-	unregister_pernet_subsys(&nfsd_net_ops);
	return retval;
}

static void __exit exit_nfsd(void)
{

fs/nfsd/nfsctl.c +1 -0
+	unregister_pernet_subsys(&nfsd_net_ops);
	nfsd_drc_slab_free();
	remove_proc_entry("fs/nfs/exports", NULL);
	remove_proc_entry("fs/nfs", NULL);
fs/nfsd/nfsctl.c +0 -1
@@ -1575,7 +1576,6 @@ static void __exit exit_nfsd(void)
 	nfsd4_exit_pnfs();
 	unregister_filesystem(&nfsd_fs_type);
 	unregister_cld_notifier();
-	unregister_pernet_subsys(&nfsd_net_ops);
 }
 
 MODULE_AUTHOR("Olaf Kirch <[email protected]>");
Signature · 1 line
2.29.2

--
Chuck Lever

#2 lore raw
Quoted 17 lines · Chuck Lever

Hi Bruce-

Quoted 14 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

These pernet operations may depend on stuff set up or torn down in the module init/exit functions. And they may be called at any time in between. So it makes more sense for them to be the last to be registered in the init function, and the first to be unregistered in the exit function.

In particular, without this, the drc slab is being destroyed before all the per-net drcs are shut down, resulting in an "Objects remaining in nfsd_drc on __kmem_cache_shutdown()" warning in exit_nfsd.

Quoted 5 lines
Quoted 3 lines
Fixes 3ba75830ce17 "nfsd4: drc containerization"

I can't tell how urgent this is. Does it belong in 5.11-rc?

I dunno, I wonder what happens when you try to write to and then free a bunch of objects that were allocated from a slab that no longer exists.

But, it's triggered by unloading nfsd, and I find it hard to be super concerned about module unloading bugs (does anyone actually *need* to unload the nfsd module?).

--b.

Quoted 70 lines
Quoted 65 lines

---
fs/nfsd/nfsctl.c | 14 +++++++-------

1 file changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/nfsctl.c +4 -4
index f6d5d783f4a4..0759e589ab52 100644
@@ -1522,12 +1522,9 @@ static int __init init_nfsd(void)
 	int retval;
 	printk(KERN_INFO "Installing knfsd (copyright (C) 1996 [email protected]).\n");
 
-	retval = register_pernet_subsys(&nfsd_net_ops);
-	if (retval < 0)
-		return retval;
 	retval = register_cld_notifier();
 	if (retval)
-		goto out_unregister_pernet;
+		return retval;
 	retval = nfsd4_init_slabs();
 	if (retval)
 		goto out_unregister_notifier;
@@ -1544,9 +1541,14 @@ static int __init init_nfsd(void)
 		goto out_free_lockd;
 	retval = register_filesystem(&nfsd_fs_type);
 	if (retval)
+		goto out_free_exports;
+	retval = register_pernet_subsys(&nfsd_net_ops);
+	if (retval < 0)
 		goto out_free_all;
 	return 0;

out_free_all:

fs/nfsd/nfsctl.c +2 -0
+	unregister_pernet_subsys(&nfsd_net_ops);
+out_free_exports:
	remove_proc_entry("fs/nfs/exports", NULL);
	remove_proc_entry("fs/nfs", NULL);

out_free_lockd:

fs/nfsd/nfsctl.c +0 -0
@@ -1559,13 +1561,12 @@ static int __init init_nfsd(void)
 	nfsd4_free_slabs();

out_unregister_notifier:

	unregister_cld_notifier();
fs/nfsd/nfsctl.c +0 -2
-out_unregister_pernet:
-	unregister_pernet_subsys(&nfsd_net_ops);
	return retval;
}

static void __exit exit_nfsd(void)
{

fs/nfsd/nfsctl.c +1 -0
+	unregister_pernet_subsys(&nfsd_net_ops);
	nfsd_drc_slab_free();
	remove_proc_entry("fs/nfs/exports", NULL);
	remove_proc_entry("fs/nfs", NULL);
fs/nfsd/nfsctl.c +0 -1
@@ -1575,7 +1576,6 @@ static void __exit exit_nfsd(void)
 	nfsd4_exit_pnfs();
 	unregister_filesystem(&nfsd_fs_type);
 	unregister_cld_notifier();
-	unregister_pernet_subsys(&nfsd_net_ops);
 }
 
 MODULE_AUTHOR("Olaf Kirch <[email protected]>");
Signature · 1 line
2.29.2

--
Chuck Lever

#3 lore raw
Quoted 25 lines · Bruce Fields
Quoted 21 lines · Chuck Lever

Hi Bruce-

Quoted 17 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

These pernet operations may depend on stuff set up or torn down in the module init/exit functions. And they may be called at any time in between. So it makes more sense for them to be the last to be registered in the init function, and the first to be unregistered in the exit function.

In particular, without this, the drc slab is being destroyed before all the per-net drcs are shut down, resulting in an "Objects remaining in nfsd_drc on __kmem_cache_shutdown()" warning in exit_nfsd.

Fixes 3ba75830ce17 "nfsd4: drc containerization"
Quoted 8 lines
Quoted 1 line

I can't tell how urgent this is. Does it belong in 5.11-rc?

I dunno, I wonder what happens when you try to write to and then free a bunch of objects that were allocated from a slab that no longer exists.

But, it's triggered by unloading nfsd, and I find it hard to be super concerned about module unloading bugs (does anyone actually *need* to unload the nfsd module?).

This doesn't sound urgent, then. My initial 5.12 changeset is closed, so I'll send this in the first 5.12-rc, unless someone grumbles.

--
Chuck Lever