Skip to contentSkip to conversation

SUNRPC: Load the GSS module by OID only when the mechanism is missing

PATCH In review Sasha Levin 3 participants 3 messages Nov 10

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

PATCH 1/1 SUNRPC: Load the GSS module by OID only when the mechanism is missing

gss_mech_get_by_OID() calls request_module() before it looks at the list of registered mechanisms, so every lookup forks a modprobe, even when the mechanism is already registered or built in. gss_mech_get_by_name() and gss_mech_get_by_pseudoflavor() only load the module when the lookup fails.

The read handler of /proc/net/rpc/gss_krb5_enctypes uses this lookup, so every read() of that file runs modprobe, two per cat. The file is present in every /proc/<pid>/net/rpc and /proc/<pid>/task/<tid>/net/rpc directory, and LTP read_all gives each read one second. On a slow board in KernelCI its workers stall on this file and the test times out.

Look up the mechanism first and call request_module() only when it is not found, as the other two lookup functions do.

Fixes f783288f0cf4 ("SUNRPC: Load GSS kernel module by OID")
---
 net/sunrpc/auth_gss/gss_mech_switch.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
net/sunrpc/auth_gss/gss_mech_switch.c +17 -6
index 78eab245f94a7..d8b6ff9505399 100644
@@ -157,14 +157,9 @@ struct gss_api_mech * gss_mech_get_by_name(const char *name)
 	return gm;
 }
 
-struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
+static struct gss_api_mech *_gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
 {
 	struct gss_api_mech	*pos, *gm = NULL;
-	char buf[32];
-
-	if (sprint_oid(obj->data, obj->len, buf, sizeof(buf)) < 0)
-		return NULL;
-	request_module("rpc-auth-gss-%s", buf);
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(pos, &registered_mechs, gm_list) {
@@ -177,6 +172,22 @@ struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
 		}
 	}
 	rcu_read_unlock();
+	return gm;
+}
+
+struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
+{
+	struct gss_api_mech *gm;
+	char buf[32];
+
+	if (sprint_oid(obj->data, obj->len, buf, sizeof(buf)) < 0)
+		return NULL;
+
+	gm = _gss_mech_get_by_OID(obj);
+	if (!gm) {
+		request_module("rpc-auth-gss-%s", buf);
+		gm = _gss_mech_get_by_OID(obj);
+	}
 	if (!gm)
 		trace_rpcgss_oid_to_mech(buf);
 	return gm;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · Sasha Levin

gss_mech_get_by_OID() calls request_module() before it looks at the list of registered mechanisms, so every lookup forks a modprobe, even when the mechanism is already registered or built in. gss_mech_get_by_name() and gss_mech_get_by_pseudoflavor() only load the module when the lookup fails.

The read handler of /proc/net/rpc/gss_krb5_enctypes uses this lookup, so every read() of that file runs modprobe, two per cat. The file is present in every /proc/<pid>/net/rpc and /proc/<pid>/task/<tid>/net/rpc directory, and LTP read_all gives each read one second. On a slow board in KernelCI its workers stall on this file and the test times out.

Look up the mechanism first and call request_module() only when it is not found, as the other two lookup functions do.

Fixes f783288f0cf4 ("SUNRPC: Load GSS kernel module by OID")
---
 net/sunrpc/auth_gss/gss_mech_switch.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
net/sunrpc/auth_gss/gss_mech_switch.c +10 -6
index 78eab245f94a7..d8b6ff9505399 100644
@@ -157,14 +157,9 @@ struct gss_api_mech * gss_mech_get_by_name(const char *name)
 	return gm;
 }
 
-struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
+static struct gss_api_mech *_gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
 {
 	struct gss_api_mech	*pos, *gm = NULL;
-	char buf[32];
-
-	if (sprint_oid(obj->data, obj->len, buf, sizeof(buf)) < 0)
-		return NULL;
-	request_module("rpc-auth-gss-%s", buf);
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(pos, &registered_mechs, gm_list) {
@@ -177,6 +172,22 @@ struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
 		}
 	}
 	rcu_read_unlock();
+	return gm;
+}
+
+struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj)
+{
+	struct gss_api_mech *gm;
+	char buf[32];
+
+	if (sprint_oid(obj->data, obj->len, buf, sizeof(buf)) < 0)

net/sunrpc/auth_gss/gss_mech_switch.c struct gss_api_mech *gss_mech_get_by_OID(struct rpcsec_gss_oid *obj) · line 193

Quoted 10 lines
net/sunrpc/auth_gss/gss_mech_switch.c +7 -0
+		return NULL;
+
+	gm = _gss_mech_get_by_OID(obj);
+	if (!gm) {
+		request_module("rpc-auth-gss-%s", buf);
+		gm = _gss_mech_get_by_OID(obj);
+	}
 	if (!gm)
 		trace_rpcgss_oid_to_mech(buf);
 	return gm;

Nice catch!

maintainer
#2 lore raw
In reply to Sasha Levin
Quoted 6 lines · Sasha Levin

gss_mech_get_by_OID() calls request_module() before it looks at the list of registered mechanisms, so every lookup forks a modprobe, even when the mechanism is already registered or built in. gss_mech_get_by_name() and gss_mech_get_by_pseudoflavor() only load the module when the lookup fails.

Quoted 7 lines

The read handler of /proc/net/rpc/gss_krb5_enctypes uses this lookup, so every read() of that file runs modprobe, two per cat. The file is present in every /proc/<pid>/net/rpc and /proc/<pid>/task/<tid>/net/rpc directory, and LTP read_all gives each read one second. On a slow board in KernelCI its workers stall on this file and the test times out.

[...]

Applied to nfsd-testing, thanks!

[1/1] SUNRPC: Load the GSS module by OID only when the mechanism is missing

      commit: f7ef2ce48812080b87572a2f0fdec93cb2d2a629

--
Chuck Lever <[email protected]>