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: <20220825080420.1282569-2-jiri@resnulli.us>
Date:   Thu, 25 Aug 2022 10:04:19 +0200
From:   Jiri Pirko <jiri@...nulli.us>
To:     netdev@...r.kernel.org
Cc:     sthemmin@...rosoft.com, dsahern@...il.com,
        vikas.gupta@...adcom.com, jacob.e.keller@...el.com,
        kuba@...nel.org, moshe@...dia.com, saeedm@...dia.com
Subject: [patch iproute2-next 1/2] devlink: load port-ifname map on demand

From: Jiri Pirko <jiri@...dia.com>

So far, the port-ifname map was loaded during devlink init
no matter if actually needed or not. Port dump cmd which is utilized
for this in kernel takes lock for every devlink instance.
That may lead to unnecessary blockage of command.

Load the map only in time it is needed to lookup ifname.

Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
 devlink/devlink.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index b69c89778804..b2439aef4d10 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -374,6 +374,7 @@ struct dl {
 	bool verbose;
 	bool stats;
 	bool hex;
+	bool map_loaded;
 	struct {
 		bool present;
 		char *bus_name;
@@ -817,13 +818,15 @@ static void ifname_map_fini(struct dl *dl)
 	}
 }
 
-static int ifname_map_init(struct dl *dl)
+static void ifname_map_init(struct dl *dl)
 {
-	struct nlmsghdr *nlh;
-	int err;
-
 	INIT_LIST_HEAD(&dl->ifname_map_list);
+}
 
+static int ifname_map_load(struct dl *dl)
+{
+	struct nlmsghdr *nlh;
+	int err;
 
 	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
 			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
@@ -841,7 +844,16 @@ static int ifname_map_lookup(struct dl *dl, const char *ifname,
 			     uint32_t *p_port_index)
 {
 	struct ifname_map *ifname_map;
+	int err;
 
+	if (!dl->map_loaded) {
+		err = ifname_map_load(dl);
+		if (err) {
+			pr_err("Failed to create index map\n");
+			return err;
+		}
+		dl->map_loaded = true;
+	}
 	list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
 		if (strcmp(ifname, ifname_map->ifname) == 0) {
 			*p_bus_name = ifname_map->bus_name;
@@ -9622,17 +9634,10 @@ static int dl_init(struct dl *dl)
 		return -errno;
 	}
 
-	err = ifname_map_init(dl);
-	if (err) {
-		pr_err("Failed to create index map\n");
-		goto err_ifname_map_create;
-	}
+	ifname_map_init(dl);
+
 	new_json_obj_plain(dl->json_output);
 	return 0;
-
-err_ifname_map_create:
-	mnlu_gen_socket_close(&dl->nlg);
-	return err;
 }
 
 static void dl_fini(struct dl *dl)
-- 
2.37.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ