[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230111090748.751505-5-jiri@resnulli.us>
Date: Wed, 11 Jan 2023 10:07:42 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
edumazet@...gle.com, michael.chan@...adcom.com,
yisen.zhuang@...wei.com, salil.mehta@...wei.com,
jesse.brandeburg@...el.com, anthony.l.nguyen@...el.com,
tariqt@...dia.com, saeedm@...dia.com, leon@...nel.org,
idosch@...dia.com, petrm@...dia.com, mailhol.vincent@...adoo.fr,
jacob.e.keller@...el.com, gal@...dia.com
Subject: [patch net-next v4 04/10] devlink: remove reporters_lock
From: Jiri Pirko <jiri@...dia.com>
Similar to other devlink objects, rely on devlink instance lock
and remove object specific reporters_lock.
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
v2->v3:
- split from v2 patch #4 - "devlink: remove reporters_lock", no change
---
include/net/devlink.h | 1 -
net/devlink/core.c | 2 --
net/devlink/devl_internal.h | 1 -
net/devlink/leftover.c | 53 +++++++------------------------------
4 files changed, 9 insertions(+), 48 deletions(-)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 3e0536f46426..0b318a0209f2 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -146,7 +146,6 @@ struct devlink_port {
initialized:1;
struct delayed_work type_warn_dw;
struct list_head reporter_list;
- struct mutex reporters_lock; /* Protects reporter_list */
struct devlink_rate *devlink_rate;
struct devlink_linecard *linecard;
diff --git a/net/devlink/core.c b/net/devlink/core.c
index e2b9fcb47e22..7e2332adb79d 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -234,7 +234,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
lockdep_register_key(&devlink->lock_key);
mutex_init(&devlink->lock);
lockdep_set_class(&devlink->lock, &devlink->lock_key);
- mutex_init(&devlink->reporters_lock);
refcount_set(&devlink->refcount, 1);
return devlink;
@@ -256,7 +255,6 @@ void devlink_free(struct devlink *devlink)
{
ASSERT_DEVLINK_NOT_REGISTERED(devlink);
- mutex_destroy(&devlink->reporters_lock);
mutex_destroy(&devlink->lock);
lockdep_unregister_key(&devlink->lock_key);
WARN_ON(!list_empty(&devlink->trap_policer_list));
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index d5bc46984039..7eb32c35ad81 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -31,7 +31,6 @@ struct devlink {
struct list_head param_list;
struct list_head region_list;
struct list_head reporter_list;
- struct mutex reporters_lock; /* protects reporter_list */
struct devlink_dpipe_headers *dpipe_headers;
struct list_head trap_list;
struct list_head trap_group_list;
diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c
index d17a8dda85ea..5af7e619fb12 100644
--- a/net/devlink/leftover.c
+++ b/net/devlink/leftover.c
@@ -7281,12 +7281,10 @@ EXPORT_SYMBOL_GPL(devlink_health_reporter_priv);
static struct devlink_health_reporter *
__devlink_health_reporter_find_by_name(struct list_head *reporter_list,
- struct mutex *list_lock,
const char *reporter_name)
{
struct devlink_health_reporter *reporter;
- lockdep_assert_held(list_lock);
list_for_each_entry(reporter, reporter_list, list)
if (!strcmp(reporter->ops->name, reporter_name))
return reporter;
@@ -7298,7 +7296,6 @@ devlink_health_reporter_find_by_name(struct devlink *devlink,
const char *reporter_name)
{
return __devlink_health_reporter_find_by_name(&devlink->reporter_list,
- &devlink->reporters_lock,
reporter_name);
}
@@ -7307,7 +7304,6 @@ devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port,
const char *reporter_name)
{
return __devlink_health_reporter_find_by_name(&devlink_port->reporter_list,
- &devlink_port->reporters_lock,
reporter_name);
}
@@ -7353,22 +7349,18 @@ devl_port_health_reporter_create(struct devlink_port *port,
struct devlink_health_reporter *reporter;
devl_assert_locked(port->devlink);
- mutex_lock(&port->reporters_lock);
+
if (__devlink_health_reporter_find_by_name(&port->reporter_list,
- &port->reporters_lock, ops->name)) {
- reporter = ERR_PTR(-EEXIST);
- goto unlock;
- }
+ ops->name))
+ return ERR_PTR(-EEXIST);
reporter = __devlink_health_reporter_create(port->devlink, ops,
graceful_period, priv);
if (IS_ERR(reporter))
- goto unlock;
+ return reporter;
reporter->devlink_port = port;
list_add_tail(&reporter->list, &port->reporter_list);
-unlock:
- mutex_unlock(&port->reporters_lock);
return reporter;
}
EXPORT_SYMBOL_GPL(devl_port_health_reporter_create);
@@ -7389,20 +7381,16 @@ devl_health_reporter_create(struct devlink *devlink,
struct devlink_health_reporter *reporter;
devl_assert_locked(devlink);
- mutex_lock(&devlink->reporters_lock);
- if (devlink_health_reporter_find_by_name(devlink, ops->name)) {
- reporter = ERR_PTR(-EEXIST);
- goto unlock;
- }
+
+ if (devlink_health_reporter_find_by_name(devlink, ops->name))
+ return ERR_PTR(-EEXIST);
reporter = __devlink_health_reporter_create(devlink, ops,
graceful_period, priv);
if (IS_ERR(reporter))
- goto unlock;
+ return reporter;
list_add_tail(&reporter->list, &devlink->reporter_list);
-unlock:
- mutex_unlock(&devlink->reporters_lock);
return reporter;
}
EXPORT_SYMBOL_GPL(devl_health_reporter_create);
@@ -7453,13 +7441,9 @@ __devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
void
devl_health_reporter_destroy(struct devlink_health_reporter *reporter)
{
- struct mutex *lock = &reporter->devlink->reporters_lock;
-
devl_assert_locked(reporter->devlink);
- mutex_lock(lock);
__devlink_health_reporter_destroy(reporter);
- mutex_unlock(lock);
}
EXPORT_SYMBOL_GPL(devl_health_reporter_destroy);
@@ -7482,13 +7466,9 @@ EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
void
devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter)
{
- struct mutex *lock = &reporter->devlink_port->reporters_lock;
-
devl_assert_locked(reporter->devlink);
- mutex_lock(lock);
__devlink_health_reporter_destroy(reporter);
- mutex_unlock(lock);
}
EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy);
@@ -7731,17 +7711,13 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink,
reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]);
devlink_port = devlink_port_get_from_attrs(devlink, attrs);
if (IS_ERR(devlink_port)) {
- mutex_lock(&devlink->reporters_lock);
reporter = devlink_health_reporter_find_by_name(devlink, reporter_name);
if (reporter)
refcount_inc(&reporter->refcount);
- mutex_unlock(&devlink->reporters_lock);
} else {
- mutex_lock(&devlink_port->reporters_lock);
reporter = devlink_port_health_reporter_find_by_name(devlink_port, reporter_name);
if (reporter)
refcount_inc(&reporter->refcount);
- mutex_unlock(&devlink_port->reporters_lock);
}
return reporter;
@@ -7841,8 +7817,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
if (!devl_is_registered(devlink))
goto next_devlink;
- mutex_lock(&devlink->reporters_lock);
-
list_for_each_entry(reporter, &devlink->reporter_list,
list) {
if (idx < state->idx) {
@@ -7854,7 +7828,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
NLM_F_MULTI);
if (err) {
- mutex_unlock(&devlink->reporters_lock);
devl_unlock(devlink);
devlink_put(devlink);
state->idx = idx;
@@ -7862,10 +7835,8 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
}
idx++;
}
- mutex_unlock(&devlink->reporters_lock);
xa_for_each(&devlink->ports, port_index, port) {
- mutex_lock(&port->reporters_lock);
list_for_each_entry(reporter, &port->reporter_list, list) {
if (idx < state->idx) {
idx++;
@@ -7877,7 +7848,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI);
if (err) {
- mutex_unlock(&port->reporters_lock);
devl_unlock(devlink);
devlink_put(devlink);
state->idx = idx;
@@ -7885,7 +7855,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
}
idx++;
}
- mutex_unlock(&port->reporters_lock);
}
next_devlink:
devl_unlock(devlink);
@@ -9611,12 +9580,9 @@ int devl_port_register(struct devlink *devlink,
devlink_port->index = port_index;
spin_lock_init(&devlink_port->type_lock);
INIT_LIST_HEAD(&devlink_port->reporter_list);
- mutex_init(&devlink_port->reporters_lock);
err = xa_insert(&devlink->ports, port_index, devlink_port, GFP_KERNEL);
- if (err) {
- mutex_destroy(&devlink_port->reporters_lock);
+ if (err)
return err;
- }
INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn);
devlink_port_type_warn_schedule(devlink_port);
@@ -9667,7 +9633,6 @@ void devl_port_unregister(struct devlink_port *devlink_port)
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL);
xa_erase(&devlink_port->devlink->ports, devlink_port->index);
WARN_ON(!list_empty(&devlink_port->reporter_list));
- mutex_destroy(&devlink_port->reporters_lock);
devlink_port->registered = false;
}
EXPORT_SYMBOL_GPL(devl_port_unregister);
--
2.39.0
Powered by blists - more mailing lists