* [PATCH net-next 0/5] net: switchdev: Tracepoints
@ 2024-01-23 15:37 Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 1/5] net: switchdev: Wrap enums in mapper macros Tobias Waldekranz
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
This series starts off (1-2/5) by creating stringifiers for common
switchdev objects. This will primarily be used by the tracepoints for
decoding switchdev notifications, but drivers could also make use of
them to provide richer debug/error messages.
Then follows two refactoring commits (3-4/5), with no (intended)
functional changes:
- 3/5: Wrap all replay callbacks in br_switchdev.c in a switchdev
function to make it easy to trace all of these.
- 4/5: Instead of using a different format for deferred items, reuse
the existing notification structures when enqueuing. This lets
us share a bit more code, and it unifies the data presented by
the tracepoints.
Finally, add the tracepoints.
Tobias Waldekranz (5):
net: switchdev: Wrap enums in mapper macros
net: switchdev: Add helpers to display switchdev objects as strings
net: switchdev: Relay all replay messages through a central function
net: switchdev: Prepare deferred notifications before enqueuing them
net: switchdev: Add tracepoints
include/net/switchdev.h | 130 ++++++++----
include/trace/events/switchdev.h | 89 ++++++++
net/bridge/br_switchdev.c | 10 +-
net/switchdev/Makefile | 2 +-
net/switchdev/switchdev-str.c | 278 +++++++++++++++++++++++++
net/switchdev/switchdev.c | 346 +++++++++++++++++--------------
6 files changed, 650 insertions(+), 205 deletions(-)
create mode 100644 include/trace/events/switchdev.h
create mode 100644 net/switchdev/switchdev-str.c
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next 1/5] net: switchdev: Wrap enums in mapper macros
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
@ 2024-01-23 15:37 ` Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings Tobias Waldekranz
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
In order to avoid having to maintain separate mappings from enum
values to strings, wrap enumerators in mapper macros, so that
enum-to-string tables can be generated.
This will make it easier to create helpers that convert switchdev
objects to strings.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
include/net/switchdev.h | 113 ++++++++++++++++++++++++----------------
1 file changed, 68 insertions(+), 45 deletions(-)
diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index a43062d4c734..76eabf95c647 100644
--- a/include/net/switchdev.h
+++ b/include/net/switchdev.h
@@ -16,21 +16,28 @@
#define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)
#define SWITCHDEV_F_DEFER BIT(2)
+#define SWITCHDEV_ATTR_ID_MAPPER(_fn) \
+ _fn(UNDEFINED), \
+ _fn(PORT_STP_STATE), \
+ _fn(PORT_MST_STATE), \
+ _fn(PORT_BRIDGE_FLAGS), \
+ _fn(PORT_PRE_BRIDGE_FLAGS), \
+ _fn(PORT_MROUTER), \
+ _fn(BRIDGE_AGEING_TIME), \
+ _fn(BRIDGE_VLAN_FILTERING), \
+ _fn(BRIDGE_VLAN_PROTOCOL), \
+ _fn(BRIDGE_MC_DISABLED), \
+ _fn(BRIDGE_MROUTER), \
+ _fn(BRIDGE_MST), \
+ _fn(MRP_PORT_ROLE), \
+ _fn(VLAN_MSTI), \
+ /* */
+
+#define SWITCHDEV_ATTR_ID_ENUMERATOR(_id) \
+ SWITCHDEV_ATTR_ID_ ## _id
+
enum switchdev_attr_id {
- SWITCHDEV_ATTR_ID_UNDEFINED,
- SWITCHDEV_ATTR_ID_PORT_STP_STATE,
- SWITCHDEV_ATTR_ID_PORT_MST_STATE,
- SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
- SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS,
- SWITCHDEV_ATTR_ID_PORT_MROUTER,
- SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
- SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
- SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL,
- SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
- SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
- SWITCHDEV_ATTR_ID_BRIDGE_MST,
- SWITCHDEV_ATTR_ID_MRP_PORT_ROLE,
- SWITCHDEV_ATTR_ID_VLAN_MSTI,
+ SWITCHDEV_ATTR_ID_MAPPER(SWITCHDEV_ATTR_ID_ENUMERATOR)
};
struct switchdev_mst_state {
@@ -69,18 +76,25 @@ struct switchdev_attr {
} u;
};
+#define SWITCHDEV_OBJ_ID_MAPPER(_fn) \
+ _fn(UNDEFINED), \
+ _fn(PORT_VLAN), \
+ _fn(PORT_MDB), \
+ _fn(HOST_MDB), \
+ _fn(MRP), \
+ _fn(RING_TEST_MRP), \
+ _fn(RING_ROLE_MRP), \
+ _fn(RING_STATE_MRP), \
+ _fn(IN_TEST_MRP), \
+ _fn(IN_ROLE_MRP), \
+ _fn(IN_STATE_MRP), \
+ /* */
+
+#define SWITCHDEV_OBJ_ID_ENUMERATOR(_id) \
+ SWITCHDEV_OBJ_ID_ ## _id
+
enum switchdev_obj_id {
- SWITCHDEV_OBJ_ID_UNDEFINED,
- SWITCHDEV_OBJ_ID_PORT_VLAN,
- SWITCHDEV_OBJ_ID_PORT_MDB,
- SWITCHDEV_OBJ_ID_HOST_MDB,
- SWITCHDEV_OBJ_ID_MRP,
- SWITCHDEV_OBJ_ID_RING_TEST_MRP,
- SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
- SWITCHDEV_OBJ_ID_RING_STATE_MRP,
- SWITCHDEV_OBJ_ID_IN_TEST_MRP,
- SWITCHDEV_OBJ_ID_IN_ROLE_MRP,
- SWITCHDEV_OBJ_ID_IN_STATE_MRP,
+ SWITCHDEV_OBJ_ID_MAPPER(SWITCHDEV_OBJ_ID_ENUMERATOR)
};
struct switchdev_obj {
@@ -209,27 +223,36 @@ struct switchdev_brport {
bool tx_fwd_offload;
};
+#define SWITCHDEV_TYPE_MAPPER(_fn) \
+ _fn(UNKNOWN), \
+ \
+ _fn(FDB_ADD_TO_BRIDGE), \
+ _fn(FDB_DEL_TO_BRIDGE), \
+ _fn(FDB_ADD_TO_DEVICE), \
+ _fn(FDB_DEL_TO_DEVICE), \
+ _fn(FDB_OFFLOADED), \
+ _fn(FDB_FLUSH_TO_BRIDGE), \
+ \
+ _fn(PORT_OBJ_ADD), \
+ _fn(PORT_OBJ_DEL), \
+ _fn(PORT_ATTR_SET), \
+ \
+ _fn(VXLAN_FDB_ADD_TO_BRIDGE), \
+ _fn(VXLAN_FDB_DEL_TO_BRIDGE), \
+ _fn(VXLAN_FDB_ADD_TO_DEVICE), \
+ _fn(VXLAN_FDB_DEL_TO_DEVICE), \
+ _fn(VXLAN_FDB_OFFLOADED), \
+ \
+ _fn(BRPORT_OFFLOADED), \
+ _fn(BRPORT_UNOFFLOADED), \
+ _fn(BRPORT_REPLAY), \
+ /* */
+
+#define SWITCHDEV_TYPE_ENUMERATOR(_id) \
+ SWITCHDEV_ ## _id
+
enum switchdev_notifier_type {
- SWITCHDEV_FDB_ADD_TO_BRIDGE = 1,
- SWITCHDEV_FDB_DEL_TO_BRIDGE,
- SWITCHDEV_FDB_ADD_TO_DEVICE,
- SWITCHDEV_FDB_DEL_TO_DEVICE,
- SWITCHDEV_FDB_OFFLOADED,
- SWITCHDEV_FDB_FLUSH_TO_BRIDGE,
-
- SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */
- SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */
- SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */
-
- SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE,
- SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE,
- SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE,
- SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE,
- SWITCHDEV_VXLAN_FDB_OFFLOADED,
-
- SWITCHDEV_BRPORT_OFFLOADED,
- SWITCHDEV_BRPORT_UNOFFLOADED,
- SWITCHDEV_BRPORT_REPLAY,
+ SWITCHDEV_TYPE_MAPPER(SWITCHDEV_TYPE_ENUMERATOR)
};
struct switchdev_notifier_info {
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 1/5] net: switchdev: Wrap enums in mapper macros Tobias Waldekranz
@ 2024-01-23 15:37 ` Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function Tobias Waldekranz
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
Useful both in error messages and in tracepoints.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
include/net/switchdev.h | 14 ++
net/switchdev/Makefile | 2 +-
net/switchdev/switchdev-str.c | 278 ++++++++++++++++++++++++++++++++++
3 files changed, 293 insertions(+), 1 deletion(-)
create mode 100644 net/switchdev/switchdev-str.c
diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index 76eabf95c647..250053748c08 100644
--- a/include/net/switchdev.h
+++ b/include/net/switchdev.h
@@ -391,6 +391,20 @@ int switchdev_handle_port_attr_set(struct net_device *dev,
int (*set_cb)(struct net_device *dev, const void *ctx,
const struct switchdev_attr *attr,
struct netlink_ext_ack *extack));
+
+/* switchdev-str.c */
+ssize_t switchdev_attr_str(const struct switchdev_attr *attr,
+ char *buf, size_t len);
+ssize_t switchdev_obj_str(const struct switchdev_obj *obj,
+ char *buf, size_t len);
+ssize_t switchdev_fdb_info_str(enum switchdev_notifier_type nt,
+ const struct switchdev_notifier_fdb_info *fdbi,
+ char *buf, size_t len);
+ssize_t switchdev_brport_str(const struct switchdev_brport *brport,
+ char *buf, size_t len);
+ssize_t switchdev_notifier_str(enum switchdev_notifier_type nt,
+ const struct switchdev_notifier_info *info,
+ char *buf, size_t len);
#else
static inline int
diff --git a/net/switchdev/Makefile b/net/switchdev/Makefile
index c5561d7f3a7c..a40e4421087b 100644
--- a/net/switchdev/Makefile
+++ b/net/switchdev/Makefile
@@ -3,4 +3,4 @@
# Makefile for the Switch device API
#
-obj-y += switchdev.o
+obj-y += switchdev.o switchdev-str.o
diff --git a/net/switchdev/switchdev-str.c b/net/switchdev/switchdev-str.c
new file mode 100644
index 000000000000..a1fa7315cc28
--- /dev/null
+++ b/net/switchdev/switchdev-str.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/if_bridge.h>
+#include <net/switchdev.h>
+
+static ssize_t switchdev_str_write_id(char *buf, size_t len, unsigned long id,
+ const char *const *names, size_t n_names)
+{
+ if (id < n_names && names[id])
+ return snprintf(buf, len, "%s", names[id]);
+
+ return snprintf(buf, len, "UNKNOWN<%lu>", id);
+}
+
+ssize_t switchdev_attr_str(const struct switchdev_attr *attr,
+ char *buf, size_t len)
+{
+#define _ATTR_ID_STRINGER(_id) [SWITCHDEV_ATTR_ID_ ## _id] = #_id
+ static const char *const attr_id_strs[] = {
+ SWITCHDEV_ATTR_ID_MAPPER(_ATTR_ID_STRINGER)
+ };
+#undef _ATTR_ID_STRINGER
+
+ static const char *const stp_state_strs[] = {
+ [BR_STATE_DISABLED] = "disabled",
+ [BR_STATE_LISTENING] = "listening",
+ [BR_STATE_LEARNING] = "learning",
+ [BR_STATE_FORWARDING] = "forwarding",
+ [BR_STATE_BLOCKING] = "blocking",
+ };
+
+ char *cur = buf;
+ ssize_t n;
+
+ n = switchdev_str_write_id(cur, len, attr->id, attr_id_strs,
+ ARRAY_SIZE(attr_id_strs));
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ n = snprintf(cur, len, "(flags %#x orig %s) ", attr->flags,
+ attr->orig_dev ? netdev_name(attr->orig_dev) : "(null)");
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ switch (attr->id) {
+ case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
+ n = switchdev_str_write_id(cur, len, attr->u.stp_state,
+ stp_state_strs, ARRAY_SIZE(stp_state_strs));
+ break;
+ case SWITCHDEV_ATTR_ID_PORT_MST_STATE:
+ n = snprintf(cur, len, "msti %u", attr->u.mst_state.msti);
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ n = switchdev_str_write_id(cur, len, attr->u.mst_state.state,
+ stp_state_strs, ARRAY_SIZE(stp_state_strs));
+ break;
+ case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
+ case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
+ n = snprintf(cur, len, "val %#lx mask %#lx",
+ attr->u.brport_flags.val,
+ attr->u.brport_flags.mask);
+ break;
+ case SWITCHDEV_ATTR_ID_PORT_MROUTER:
+ case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER:
+ n = snprintf(cur, len, "%s",
+ attr->u.mrouter ? "enabled" : "disabled");
+ break;
+ case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
+ n = snprintf(cur, len, "%ums",
+ jiffies_to_msecs(clock_t_to_jiffies(attr->u.ageing_time)));
+ break;
+ case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
+ n = snprintf(cur, len, "%s",
+ attr->u.vlan_filtering ? "enabled" : "disabled");
+ break;
+ case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL:
+ n = snprintf(cur, len, "%#x", attr->u.vlan_protocol);
+ break;
+ case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED:
+ n = snprintf(cur, len, "%s",
+ attr->u.mc_disabled ? "active" : "inactive");
+ break;
+ case SWITCHDEV_ATTR_ID_BRIDGE_MST:
+ n = snprintf(cur, len, "%s",
+ attr->u.mst ? "enabled" : "disabled");
+ break;
+ case SWITCHDEV_ATTR_ID_VLAN_MSTI:
+ n = snprintf(cur, len, "vid %u msti %u",
+ attr->u.vlan_msti.vid, attr->u.vlan_msti.msti);
+ break;
+ default:
+ /* Trim trailing space */
+ return --cur - buf;
+ }
+
+ if (n < 0)
+ return n;
+
+ cur += n;
+ return cur - buf;
+}
+EXPORT_SYMBOL_GPL(switchdev_attr_str);
+
+ssize_t switchdev_obj_str(const struct switchdev_obj *obj,
+ char *buf, size_t len)
+{
+#define _OBJ_ID_STRINGER(_id) [SWITCHDEV_OBJ_ID_ ## _id] = #_id
+ static const char *const obj_id_strs[] = {
+ SWITCHDEV_OBJ_ID_MAPPER(_OBJ_ID_STRINGER)
+ };
+#undef _OBJ_ID_STRINGER
+
+ const struct switchdev_obj_port_vlan *vlan;
+ const struct switchdev_obj_port_mdb *mdb;
+ char *cur = buf;
+ ssize_t n;
+
+ n = switchdev_str_write_id(cur, len, obj->id, obj_id_strs,
+ ARRAY_SIZE(obj_id_strs));
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ n = snprintf(cur, len, "(flags %#x orig %s) ", obj->flags,
+ obj->orig_dev ? netdev_name(obj->orig_dev) : "(null)");
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ switch (obj->id) {
+ case SWITCHDEV_OBJ_ID_PORT_VLAN:
+ vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+ n = snprintf(cur, len, "vid %u flags %#x%s", vlan->vid,
+ vlan->flags, vlan->changed ? "(changed)" : "");
+ break;
+ case SWITCHDEV_OBJ_ID_PORT_MDB:
+ case SWITCHDEV_OBJ_ID_HOST_MDB:
+ mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
+ n = snprintf(cur, len, "vid %u addr %pM", mdb->vid, mdb->addr);
+ break;
+ default:
+ /* Trim trailing space */
+ return --cur - buf;
+ }
+
+ if (n < 0)
+ return n;
+
+ cur += n;
+ return cur - buf;
+}
+EXPORT_SYMBOL_GPL(switchdev_obj_str);
+
+ssize_t switchdev_fdb_info_str(enum switchdev_notifier_type nt,
+ const struct switchdev_notifier_fdb_info *fdbi,
+ char *buf, size_t len)
+{
+ switch (nt) {
+ case SWITCHDEV_FDB_FLUSH_TO_BRIDGE:
+ return snprintf(buf, len, "vid %u", fdbi->vid);
+ case SWITCHDEV_FDB_ADD_TO_BRIDGE:
+ case SWITCHDEV_FDB_DEL_TO_BRIDGE:
+ case SWITCHDEV_FDB_ADD_TO_DEVICE:
+ case SWITCHDEV_FDB_DEL_TO_DEVICE:
+ case SWITCHDEV_FDB_OFFLOADED:
+ case SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE:
+ case SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE:
+ case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE:
+ case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE:
+ case SWITCHDEV_VXLAN_FDB_OFFLOADED:
+ return snprintf(buf, len, "vid %u addr %pM%s%s%s%s",
+ fdbi->vid, fdbi->addr,
+ fdbi->added_by_user ? " added_by_user" : "",
+ fdbi->is_local ? " is_local" : "",
+ fdbi->locked ? " locked" : "",
+ fdbi->offloaded ? " offloaded" : "");
+ default:
+ break;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(switchdev_fdb_info_str);
+
+ssize_t switchdev_brport_str(const struct switchdev_brport *brport,
+ char *buf, size_t len)
+{
+ return snprintf(buf, len, "dev %s%s",
+ brport->dev ? netdev_name(brport->dev) : "(null)",
+ brport->tx_fwd_offload ? " tx_fwd_offload" : "");
+}
+EXPORT_SYMBOL_GPL(switchdev_brport_str);
+
+ssize_t switchdev_notifier_str(enum switchdev_notifier_type nt,
+ const struct switchdev_notifier_info *info,
+ char *buf, size_t len)
+{
+#define _TYPE_STRINGER(_id) [SWITCHDEV_ ## _id] = #_id
+ static const char *const type_strs[] = {
+ SWITCHDEV_TYPE_MAPPER(_TYPE_STRINGER)
+ };
+#undef _TYPE_STRINGER
+
+ const struct switchdev_notifier_port_attr_info *attri;
+ const struct switchdev_notifier_brport_info *brporti;
+ const struct switchdev_notifier_port_obj_info *obji;
+ const struct switchdev_notifier_fdb_info *fdbi;
+ char *cur = buf;
+ ssize_t n;
+
+ n = switchdev_str_write_id(cur, len, nt, type_strs,
+ ARRAY_SIZE(type_strs));
+ if (n < 0)
+ return n;
+
+ cur += n;
+ len -= n;
+
+ if (len > 0) {
+ *cur++ = ' ';
+ len--;
+ }
+
+ switch (nt) {
+ case SWITCHDEV_FDB_FLUSH_TO_BRIDGE:
+ case SWITCHDEV_FDB_ADD_TO_BRIDGE:
+ case SWITCHDEV_FDB_DEL_TO_BRIDGE:
+ case SWITCHDEV_FDB_ADD_TO_DEVICE:
+ case SWITCHDEV_FDB_DEL_TO_DEVICE:
+ case SWITCHDEV_FDB_OFFLOADED:
+ case SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE:
+ case SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE:
+ case SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE:
+ case SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE:
+ case SWITCHDEV_VXLAN_FDB_OFFLOADED:
+ fdbi = container_of(info, typeof(*fdbi), info);
+ n = switchdev_fdb_info_str(nt, fdbi, cur, len);
+ break;
+ case SWITCHDEV_PORT_OBJ_ADD:
+ case SWITCHDEV_PORT_OBJ_DEL:
+ obji = container_of(info, typeof(*obji), info);
+ n = switchdev_obj_str(obji->obj, cur, len);
+ break;
+ case SWITCHDEV_PORT_ATTR_SET:
+ attri = container_of(info, typeof(*attri), info);
+ n = switchdev_attr_str(attri->attr, cur, len);
+ break;
+ case SWITCHDEV_BRPORT_OFFLOADED:
+ case SWITCHDEV_BRPORT_UNOFFLOADED:
+ case SWITCHDEV_BRPORT_REPLAY:
+ brporti = container_of(info, typeof(*brporti), info);
+ n = switchdev_brport_str(&brporti->brport, cur, len);
+ break;
+ default:
+ /* Trim trailing space */
+ return --cur - buf;
+ }
+
+ if (n < 0)
+ return n;
+
+ cur += n;
+ return cur - buf;
+}
+EXPORT_SYMBOL_GPL(switchdev_notifier_str);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 1/5] net: switchdev: Wrap enums in mapper macros Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings Tobias Waldekranz
@ 2024-01-23 15:37 ` Tobias Waldekranz
2024-01-24 10:14 ` Simon Horman
2024-01-26 6:07 ` kernel test robot
2024-01-23 15:37 ` [PATCH net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 5/5] net: switchdev: Add tracepoints Tobias Waldekranz
4 siblings, 2 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
This will make it easier to add a tracepoint for all replay messages
later on.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
include/net/switchdev.h | 3 +++
net/bridge/br_switchdev.c | 10 +++++-----
net/switchdev/switchdev.c | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/include/net/switchdev.h b/include/net/switchdev.h
index 250053748c08..974cd8467131 100644
--- a/include/net/switchdev.h
+++ b/include/net/switchdev.h
@@ -337,6 +337,9 @@ int switchdev_port_obj_add(struct net_device *dev,
int switchdev_port_obj_del(struct net_device *dev,
const struct switchdev_obj *obj);
+int switchdev_call_replay(struct notifier_block *nb, unsigned long type,
+ struct switchdev_notifier_info *info);
+
int register_switchdev_notifier(struct notifier_block *nb);
int unregister_switchdev_notifier(struct notifier_block *nb);
int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index ee84e783e1df..b9e69b522544 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -306,7 +306,7 @@ br_switchdev_fdb_replay_one(struct net_bridge *br, struct notifier_block *nb,
br_switchdev_fdb_populate(br, &item, fdb, ctx);
- err = nb->notifier_call(nb, action, &item);
+ err = switchdev_call_replay(nb, action, &item.info);
return notifier_to_errno(err);
}
@@ -376,8 +376,8 @@ static int br_switchdev_vlan_attr_replay(struct net_device *br_dev,
attr.u.vlan_msti.vid = v->vid;
attr.u.vlan_msti.msti = v->msti;
- err = nb->notifier_call(nb, SWITCHDEV_PORT_ATTR_SET,
- &attr_info);
+ err = switchdev_call_replay(nb, SWITCHDEV_PORT_ATTR_SET,
+ &attr_info.info);
err = notifier_to_errno(err);
if (err)
return err;
@@ -404,7 +404,7 @@ br_switchdev_vlan_replay_one(struct notifier_block *nb,
};
int err;
- err = nb->notifier_call(nb, action, &obj_info);
+ err = switchdev_call_replay(nb, action, &obj_info.info);
return notifier_to_errno(err);
}
@@ -590,7 +590,7 @@ br_switchdev_mdb_replay_one(struct notifier_block *nb, struct net_device *dev,
};
int err;
- err = nb->notifier_call(nb, action, &obj_info);
+ err = switchdev_call_replay(nb, action, &obj_info.info);
return notifier_to_errno(err);
}
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 5b045284849e..05f22f971312 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -307,6 +307,23 @@ int switchdev_port_obj_del(struct net_device *dev,
}
EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
+/**
+ * switchdev_replay - Replay switchdev message to driver
+ * @nb: notifier block to send the message to
+ * @val: value passed unmodified to notifier function
+ * @info: notifier information data
+ *
+ * Typically issued by the bridge, as a response to a replay
+ * request initiated by a port that is either attaching to, or
+ * detaching from, that bridge.
+ */
+int switchdev_call_replay(struct notifier_block *nb, unsigned long type,
+ struct switchdev_notifier_info *info)
+{
+ return nb->notifier_call(nb, type, info);
+}
+EXPORT_SYMBOL_GPL(switchdev_call_replay);
+
static ATOMIC_NOTIFIER_HEAD(switchdev_notif_chain);
static BLOCKING_NOTIFIER_HEAD(switchdev_blocking_notif_chain);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
` (2 preceding siblings ...)
2024-01-23 15:37 ` [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function Tobias Waldekranz
@ 2024-01-23 15:37 ` Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 5/5] net: switchdev: Add tracepoints Tobias Waldekranz
4 siblings, 0 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
Instead of having a separate format for storing the canned objects and
attributes going to the deferred queue, store it using the
notification structures that will be needed once the item is dequeued
and sent to the driver.
This will be useful when we add switchdev tracepoints, as we can
uniformly trace deferred and immediate calls.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
net/switchdev/switchdev.c | 307 +++++++++++++++++++-------------------
1 file changed, 156 insertions(+), 151 deletions(-)
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 05f22f971312..6612f8bc79c9 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -22,17 +22,103 @@
static LIST_HEAD(deferred);
static DEFINE_SPINLOCK(deferred_lock);
-typedef void switchdev_deferred_func_t(struct net_device *dev,
- const void *data);
-
struct switchdev_deferred_item {
struct list_head list;
- struct net_device *dev;
+
+ enum switchdev_notifier_type nt;
+ union {
+ /* Guaranteed to be first in all subtypes */
+ struct switchdev_notifier_info info;
+
+ struct {
+ struct switchdev_notifier_port_attr_info info;
+ struct switchdev_attr attr;
+ } attr;
+
+ struct {
+ struct switchdev_notifier_port_obj_info info;
+ union {
+ struct switchdev_obj_port_vlan vlan;
+ struct switchdev_obj_port_mdb mdb;
+ };
+ } obj;
+ };
netdevice_tracker dev_tracker;
- switchdev_deferred_func_t *func;
- unsigned long data[];
};
+static int switchdev_port_notify(struct net_device *dev,
+ enum switchdev_notifier_type nt,
+ struct switchdev_notifier_info *info,
+ struct netlink_ext_ack *extack)
+{
+ const struct switchdev_notifier_port_attr_info *attri;
+ const struct switchdev_notifier_port_obj_info *obji;
+ int err;
+ int rc;
+
+ rc = call_switchdev_blocking_notifiers(nt, dev, info, extack);
+ err = notifier_to_errno(rc);
+
+ switch (nt) {
+ case SWITCHDEV_PORT_ATTR_SET:
+ attri = container_of(info, typeof(*attri), info);
+ if (err) {
+ WARN_ON(!attri->handled);
+ return err;
+ }
+ if (!attri->handled)
+ return -EOPNOTSUPP;
+ break;
+ case SWITCHDEV_PORT_OBJ_ADD:
+ case SWITCHDEV_PORT_OBJ_DEL:
+ obji = container_of(info, typeof(*obji), info);
+ if (err) {
+ WARN_ON(!obji->handled);
+ return err;
+ }
+ if (!obji->handled)
+ return -EOPNOTSUPP;
+ break;
+ default:
+ break;
+ }
+
+ return err;
+}
+
+static void switchdev_deferred_notify(struct switchdev_deferred_item *dfitem)
+{
+ const struct switchdev_attr *attr;
+ const struct switchdev_obj *obj;
+ char info_str[128];
+ int err;
+
+ err = switchdev_port_notify(dfitem->info.dev, dfitem->nt, &dfitem->info, NULL);
+ if (err && err != -EOPNOTSUPP) {
+ switchdev_notifier_str(dfitem->nt, &dfitem->info,
+ info_str, sizeof(info_str));
+ netdev_err(dfitem->info.dev,
+ "deferred switchdev call failed (err=%d): %s",
+ err, info_str);
+ }
+
+ switch (dfitem->nt) {
+ case SWITCHDEV_PORT_ATTR_SET:
+ attr = &dfitem->attr.attr;
+ if (attr->complete)
+ attr->complete(dfitem->info.dev, err, attr->complete_priv);
+ break;
+ case SWITCHDEV_PORT_OBJ_ADD:
+ case SWITCHDEV_PORT_OBJ_DEL:
+ obj = dfitem->obj.info.obj;
+ if (obj->complete)
+ obj->complete(dfitem->info.dev, err, obj->complete_priv);
+ break;
+ default:
+ break;
+ }
+}
+
static struct switchdev_deferred_item *switchdev_deferred_dequeue(void)
{
struct switchdev_deferred_item *dfitem;
@@ -63,8 +149,8 @@ void switchdev_deferred_process(void)
ASSERT_RTNL();
while ((dfitem = switchdev_deferred_dequeue())) {
- dfitem->func(dfitem->dev, dfitem->data);
- netdev_put(dfitem->dev, &dfitem->dev_tracker);
+ switchdev_deferred_notify(dfitem);
+ netdev_put(dfitem->info.dev, &dfitem->dev_tracker);
kfree(dfitem);
}
}
@@ -79,19 +165,9 @@ static void switchdev_deferred_process_work(struct work_struct *work)
static DECLARE_WORK(deferred_process_work, switchdev_deferred_process_work);
-static int switchdev_deferred_enqueue(struct net_device *dev,
- const void *data, size_t data_len,
- switchdev_deferred_func_t *func)
+static int switchdev_deferred_enqueue(struct switchdev_deferred_item *dfitem)
{
- struct switchdev_deferred_item *dfitem;
-
- dfitem = kmalloc(struct_size(dfitem, data, data_len), GFP_ATOMIC);
- if (!dfitem)
- return -ENOMEM;
- dfitem->dev = dev;
- dfitem->func = func;
- memcpy(dfitem->data, data, data_len);
- netdev_hold(dev, &dfitem->dev_tracker, GFP_ATOMIC);
+ netdev_hold(dfitem->info.dev, &dfitem->dev_tracker, GFP_ATOMIC);
spin_lock_bh(&deferred_lock);
list_add_tail(&dfitem->list, &deferred);
spin_unlock_bh(&deferred_lock);
@@ -99,62 +175,24 @@ static int switchdev_deferred_enqueue(struct net_device *dev,
return 0;
}
-static int switchdev_port_attr_notify(enum switchdev_notifier_type nt,
- struct net_device *dev,
- const struct switchdev_attr *attr,
- struct netlink_ext_ack *extack)
+static int switchdev_port_attr_defer(struct net_device *dev,
+ const struct switchdev_attr *attr)
{
- int err;
- int rc;
-
- struct switchdev_notifier_port_attr_info attr_info = {
- .attr = attr,
- .handled = false,
- };
-
- rc = call_switchdev_blocking_notifiers(nt, dev,
- &attr_info.info, extack);
- err = notifier_to_errno(rc);
- if (err) {
- WARN_ON(!attr_info.handled);
- return err;
- }
+ struct switchdev_deferred_item *dfitem;
- if (!attr_info.handled)
- return -EOPNOTSUPP;
+ dfitem = kzalloc(sizeof(*dfitem), GFP_ATOMIC);
+ if (!dfitem)
+ return -ENOMEM;
+ dfitem->nt = SWITCHDEV_PORT_ATTR_SET;
+ dfitem->info.dev = dev;
+ dfitem->attr.attr = *attr;
+ dfitem->attr.info.attr = &dfitem->attr.attr;
+ dfitem->attr.info.handled = false;
+ switchdev_deferred_enqueue(dfitem);
return 0;
}
-static int switchdev_port_attr_set_now(struct net_device *dev,
- const struct switchdev_attr *attr,
- struct netlink_ext_ack *extack)
-{
- return switchdev_port_attr_notify(SWITCHDEV_PORT_ATTR_SET, dev, attr,
- extack);
-}
-
-static void switchdev_port_attr_set_deferred(struct net_device *dev,
- const void *data)
-{
- const struct switchdev_attr *attr = data;
- int err;
-
- err = switchdev_port_attr_set_now(dev, attr, NULL);
- if (err && err != -EOPNOTSUPP)
- netdev_err(dev, "failed (err=%d) to set attribute (id=%d)\n",
- err, attr->id);
- if (attr->complete)
- attr->complete(dev, err, attr->complete_priv);
-}
-
-static int switchdev_port_attr_set_defer(struct net_device *dev,
- const struct switchdev_attr *attr)
-{
- return switchdev_deferred_enqueue(dev, attr, sizeof(*attr),
- switchdev_port_attr_set_deferred);
-}
-
/**
* switchdev_port_attr_set - Set port attribute
*
@@ -169,73 +207,75 @@ int switchdev_port_attr_set(struct net_device *dev,
const struct switchdev_attr *attr,
struct netlink_ext_ack *extack)
{
+ struct switchdev_notifier_port_attr_info attr_info = {
+ .attr = attr,
+ .handled = false,
+ };
+
if (attr->flags & SWITCHDEV_F_DEFER)
- return switchdev_port_attr_set_defer(dev, attr);
+ return switchdev_port_attr_defer(dev, attr);
+
ASSERT_RTNL();
- return switchdev_port_attr_set_now(dev, attr, extack);
+ return switchdev_port_notify(dev, SWITCHDEV_PORT_ATTR_SET,
+ &attr_info.info, extack);
}
EXPORT_SYMBOL_GPL(switchdev_port_attr_set);
-static size_t switchdev_obj_size(const struct switchdev_obj *obj)
+static int switchdev_port_obj_defer(struct net_device *dev,
+ enum switchdev_notifier_type nt,
+ const struct switchdev_obj *obj)
{
+ const struct switchdev_obj_port_vlan *vlan;
+ const struct switchdev_obj_port_mdb *mdb;
+ struct switchdev_deferred_item *dfitem;
+
+ dfitem = kzalloc(sizeof(*dfitem), GFP_ATOMIC);
+ if (!dfitem)
+ return -ENOMEM;
+
+ dfitem->nt = nt;
+ dfitem->info.dev = dev;
+ dfitem->obj.info.handled = false;
+
switch (obj->id) {
case SWITCHDEV_OBJ_ID_PORT_VLAN:
- return sizeof(struct switchdev_obj_port_vlan);
+ vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+ dfitem->obj.vlan = *vlan;
+ dfitem->obj.info.obj = &dfitem->obj.vlan.obj;
+ break;
case SWITCHDEV_OBJ_ID_PORT_MDB:
- return sizeof(struct switchdev_obj_port_mdb);
case SWITCHDEV_OBJ_ID_HOST_MDB:
- return sizeof(struct switchdev_obj_port_mdb);
+ mdb = SWITCHDEV_OBJ_PORT_MDB(obj);
+ dfitem->obj.mdb = *mdb;
+ dfitem->obj.info.obj = &dfitem->obj.mdb.obj;
+ break;
default:
- BUG();
+ goto err_free;
}
+
+ switchdev_deferred_enqueue(dfitem);
return 0;
+
+err_free:
+ kfree(dfitem);
+ return -EINVAL;
}
-static int switchdev_port_obj_notify(enum switchdev_notifier_type nt,
- struct net_device *dev,
- const struct switchdev_obj *obj,
- struct netlink_ext_ack *extack)
+static int switchdev_port_obj_op(struct net_device *dev,
+ enum switchdev_notifier_type nt,
+ const struct switchdev_obj *obj,
+ struct netlink_ext_ack *extack)
{
- int rc;
- int err;
-
struct switchdev_notifier_port_obj_info obj_info = {
.obj = obj,
.handled = false,
};
- rc = call_switchdev_blocking_notifiers(nt, dev, &obj_info.info, extack);
- err = notifier_to_errno(rc);
- if (err) {
- WARN_ON(!obj_info.handled);
- return err;
- }
- if (!obj_info.handled)
- return -EOPNOTSUPP;
- return 0;
-}
-
-static void switchdev_port_obj_add_deferred(struct net_device *dev,
- const void *data)
-{
- const struct switchdev_obj *obj = data;
- int err;
+ if (obj->flags & SWITCHDEV_F_DEFER)
+ return switchdev_port_obj_defer(dev, nt, obj);
ASSERT_RTNL();
- err = switchdev_port_obj_notify(SWITCHDEV_PORT_OBJ_ADD,
- dev, obj, NULL);
- if (err && err != -EOPNOTSUPP)
- netdev_err(dev, "failed (err=%d) to add object (id=%d)\n",
- err, obj->id);
- if (obj->complete)
- obj->complete(dev, err, obj->complete_priv);
-}
-
-static int switchdev_port_obj_add_defer(struct net_device *dev,
- const struct switchdev_obj *obj)
-{
- return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj),
- switchdev_port_obj_add_deferred);
+ return switchdev_port_notify(dev, nt, &obj_info.info, extack);
}
/**
@@ -252,42 +292,10 @@ int switchdev_port_obj_add(struct net_device *dev,
const struct switchdev_obj *obj,
struct netlink_ext_ack *extack)
{
- if (obj->flags & SWITCHDEV_F_DEFER)
- return switchdev_port_obj_add_defer(dev, obj);
- ASSERT_RTNL();
- return switchdev_port_obj_notify(SWITCHDEV_PORT_OBJ_ADD,
- dev, obj, extack);
+ return switchdev_port_obj_op(dev, SWITCHDEV_PORT_OBJ_ADD, obj, extack);
}
EXPORT_SYMBOL_GPL(switchdev_port_obj_add);
-static int switchdev_port_obj_del_now(struct net_device *dev,
- const struct switchdev_obj *obj)
-{
- return switchdev_port_obj_notify(SWITCHDEV_PORT_OBJ_DEL,
- dev, obj, NULL);
-}
-
-static void switchdev_port_obj_del_deferred(struct net_device *dev,
- const void *data)
-{
- const struct switchdev_obj *obj = data;
- int err;
-
- err = switchdev_port_obj_del_now(dev, obj);
- if (err && err != -EOPNOTSUPP)
- netdev_err(dev, "failed (err=%d) to del object (id=%d)\n",
- err, obj->id);
- if (obj->complete)
- obj->complete(dev, err, obj->complete_priv);
-}
-
-static int switchdev_port_obj_del_defer(struct net_device *dev,
- const struct switchdev_obj *obj)
-{
- return switchdev_deferred_enqueue(dev, obj, switchdev_obj_size(obj),
- switchdev_port_obj_del_deferred);
-}
-
/**
* switchdev_port_obj_del - Delete port object
*
@@ -300,10 +308,7 @@ static int switchdev_port_obj_del_defer(struct net_device *dev,
int switchdev_port_obj_del(struct net_device *dev,
const struct switchdev_obj *obj)
{
- if (obj->flags & SWITCHDEV_F_DEFER)
- return switchdev_port_obj_del_defer(dev, obj);
- ASSERT_RTNL();
- return switchdev_port_obj_del_now(dev, obj);
+ return switchdev_port_obj_op(dev, SWITCHDEV_PORT_OBJ_DEL, obj, NULL);
}
EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 5/5] net: switchdev: Add tracepoints
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
` (3 preceding siblings ...)
2024-01-23 15:37 ` [PATCH net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them Tobias Waldekranz
@ 2024-01-23 15:37 ` Tobias Waldekranz
4 siblings, 0 replies; 8+ messages in thread
From: Tobias Waldekranz @ 2024-01-23 15:37 UTC (permalink / raw)
To: davem, kuba
Cc: jiri, ivecera, netdev, roopa, razor, bridge, rostedt, mhiramat,
linux-trace-kernel
Add a basic set of tracepoints:
- switchdev_defer: Triggers whenever an operation is enqueued to the
switchdev workqueue.
- switchdev_call_atomic/switchdev_call_blocking: Triggers whenever a
notification is sent on the corresponding notifier block.
- switchdev_call_replay: Triggers whenever a notification is sent back
to a driver's own notifier block, in response to a replay request.
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
include/trace/events/switchdev.h | 89 ++++++++++++++++++++++++++++++++
net/switchdev/switchdev.c | 24 +++++++--
2 files changed, 109 insertions(+), 4 deletions(-)
create mode 100644 include/trace/events/switchdev.h
diff --git a/include/trace/events/switchdev.h b/include/trace/events/switchdev.h
new file mode 100644
index 000000000000..b587965da2f6
--- /dev/null
+++ b/include/trace/events/switchdev.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM switchdev
+
+#if !defined(_TRACE_SWITCHDEV_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SWITCHDEV_H
+
+#include <linux/tracepoint.h>
+#include <net/switchdev.h>
+
+#define SWITCHDEV_TRACE_MSG_MAX 128
+
+TRACE_EVENT(switchdev_defer,
+ TP_PROTO(unsigned long val,
+ const struct switchdev_notifier_info *info),
+
+ TP_ARGS(val, info),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, val)
+ __string(dev, info->dev ? netdev_name(info->dev) : "(null)")
+ __field(const struct switchdev_notifier_info *, info)
+ __array(char, msg, SWITCHDEV_TRACE_MSG_MAX)
+ ),
+
+ TP_fast_assign(
+ __entry->val = val;
+ __assign_str(dev, info->dev ? netdev_name(info->dev) : "(null)");
+ __entry->info = info;
+ switchdev_notifier_str(val, info, __entry->msg, SWITCHDEV_TRACE_MSG_MAX);
+ ),
+
+ TP_printk("dev %s %s", __get_str(dev), __entry->msg)
+);
+
+DECLARE_EVENT_CLASS(switchdev_call,
+ TP_PROTO(unsigned long val,
+ const struct switchdev_notifier_info *info,
+ int err),
+
+ TP_ARGS(val, info, err),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, val)
+ __string(dev, info->dev ? netdev_name(info->dev) : "(null)")
+ __field(const struct switchdev_notifier_info *, info)
+ __field(int, err)
+ __array(char, msg, SWITCHDEV_TRACE_MSG_MAX)
+ ),
+
+ TP_fast_assign(
+ __entry->val = val;
+ __assign_str(dev, info->dev ? netdev_name(info->dev) : "(null)");
+ __entry->info = info;
+ __entry->err = err;
+ switchdev_notifier_str(val, info, __entry->msg, SWITCHDEV_TRACE_MSG_MAX);
+ ),
+
+ TP_printk("dev %s %s -> %d", __get_str(dev), __entry->msg, __entry->err)
+);
+
+DEFINE_EVENT(switchdev_call, switchdev_call_atomic,
+ TP_PROTO(unsigned long val,
+ const struct switchdev_notifier_info *info,
+ int err),
+
+ TP_ARGS(val, info, err)
+);
+
+DEFINE_EVENT(switchdev_call, switchdev_call_blocking,
+ TP_PROTO(unsigned long val,
+ const struct switchdev_notifier_info *info,
+ int err),
+
+ TP_ARGS(val, info, err)
+);
+
+DEFINE_EVENT(switchdev_call, switchdev_call_replay,
+ TP_PROTO(unsigned long val,
+ const struct switchdev_notifier_info *info,
+ int err),
+
+ TP_ARGS(val, info, err)
+);
+
+#endif /* _TRACE_SWITCHDEV_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 6612f8bc79c9..dfd9cf75f397 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -19,6 +19,9 @@
#include <linux/rtnetlink.h>
#include <net/switchdev.h>
+#define CREATE_TRACE_POINTS
+#include <trace/events/switchdev.h>
+
static LIST_HEAD(deferred);
static DEFINE_SPINLOCK(deferred_lock);
@@ -171,6 +174,7 @@ static int switchdev_deferred_enqueue(struct switchdev_deferred_item *dfitem)
spin_lock_bh(&deferred_lock);
list_add_tail(&dfitem->list, &deferred);
spin_unlock_bh(&deferred_lock);
+ trace_switchdev_defer(dfitem->nt, &dfitem->info);
schedule_work(&deferred_process_work);
return 0;
}
@@ -325,7 +329,11 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
int switchdev_call_replay(struct notifier_block *nb, unsigned long type,
struct switchdev_notifier_info *info)
{
- return nb->notifier_call(nb, type, info);
+ int ret;
+
+ ret = nb->notifier_call(nb, type, info);
+ trace_switchdev_call_replay(type, info, notifier_to_errno(ret));
+ return ret;
}
EXPORT_SYMBOL_GPL(switchdev_call_replay);
@@ -368,9 +376,13 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
struct switchdev_notifier_info *info,
struct netlink_ext_ack *extack)
{
+ int ret;
+
info->dev = dev;
info->extack = extack;
- return atomic_notifier_call_chain(&switchdev_notif_chain, val, info);
+ ret = atomic_notifier_call_chain(&switchdev_notif_chain, val, info);
+ trace_switchdev_call_atomic(val, info, notifier_to_errno(ret));
+ return ret;
}
EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
@@ -394,10 +406,14 @@ int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev,
struct switchdev_notifier_info *info,
struct netlink_ext_ack *extack)
{
+ int ret;
+
info->dev = dev;
info->extack = extack;
- return blocking_notifier_call_chain(&switchdev_blocking_notif_chain,
- val, info);
+ ret = blocking_notifier_call_chain(&switchdev_blocking_notif_chain,
+ val, info);
+ trace_switchdev_call_blocking(val, info, notifier_to_errno(ret));
+ return ret;
}
EXPORT_SYMBOL_GPL(call_switchdev_blocking_notifiers);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function
2024-01-23 15:37 ` [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function Tobias Waldekranz
@ 2024-01-24 10:14 ` Simon Horman
2024-01-26 6:07 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: Simon Horman @ 2024-01-24 10:14 UTC (permalink / raw)
To: Tobias Waldekranz
Cc: davem, kuba, jiri, ivecera, netdev, roopa, razor, bridge, rostedt,
mhiramat, linux-trace-kernel
On Tue, Jan 23, 2024 at 04:37:05PM +0100, Tobias Waldekranz wrote:
...
> diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
> index 5b045284849e..05f22f971312 100644
> --- a/net/switchdev/switchdev.c
> +++ b/net/switchdev/switchdev.c
> @@ -307,6 +307,23 @@ int switchdev_port_obj_del(struct net_device *dev,
> }
> EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
>
> +/**
> + * switchdev_replay - Replay switchdev message to driver
nit: switchdev_call_replay
> + * @nb: notifier block to send the message to
> + * @val: value passed unmodified to notifier function
nit: this should document @type rather than @value
> + * @info: notifier information data
> + *
> + * Typically issued by the bridge, as a response to a replay
> + * request initiated by a port that is either attaching to, or
> + * detaching from, that bridge.
> + */
> +int switchdev_call_replay(struct notifier_block *nb, unsigned long type,
> + struct switchdev_notifier_info *info)
> +{
> + return nb->notifier_call(nb, type, info);
> +}
> +EXPORT_SYMBOL_GPL(switchdev_call_replay);
> +
> static ATOMIC_NOTIFIER_HEAD(switchdev_notif_chain);
> static BLOCKING_NOTIFIER_HEAD(switchdev_blocking_notif_chain);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function
2024-01-23 15:37 ` [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function Tobias Waldekranz
2024-01-24 10:14 ` Simon Horman
@ 2024-01-26 6:07 ` kernel test robot
1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2024-01-26 6:07 UTC (permalink / raw)
To: Tobias Waldekranz, davem, kuba
Cc: llvm, oe-kbuild-all, jiri, ivecera, netdev, roopa, razor, bridge,
rostedt, mhiramat, linux-trace-kernel
Hi Tobias,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Tobias-Waldekranz/net-switchdev-Wrap-enums-in-mapper-macros/20240123-234801
base: net-next/main
patch link: https://lore.kernel.org/r/20240123153707.550795-4-tobias%40waldekranz.com
patch subject: [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function
config: i386-buildonly-randconfig-003-20240126 (https://download.01.org/0day-ci/archive/20240126/202401261325.D8Hg7ign-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240126/202401261325.D8Hg7ign-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401261325.D8Hg7ign-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> net/switchdev/switchdev.c:322: warning: Function parameter or struct member 'type' not described in 'switchdev_call_replay'
>> net/switchdev/switchdev.c:322: warning: expecting prototype for switchdev_replay(). Prototype was for switchdev_call_replay() instead
vim +322 net/switchdev/switchdev.c
309
310 /**
311 * switchdev_replay - Replay switchdev message to driver
312 * @nb: notifier block to send the message to
313 * @val: value passed unmodified to notifier function
314 * @info: notifier information data
315 *
316 * Typically issued by the bridge, as a response to a replay
317 * request initiated by a port that is either attaching to, or
318 * detaching from, that bridge.
319 */
320 int switchdev_call_replay(struct notifier_block *nb, unsigned long type,
321 struct switchdev_notifier_info *info)
> 322 {
323 return nb->notifier_call(nb, type, info);
324 }
325 EXPORT_SYMBOL_GPL(switchdev_call_replay);
326
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-01-26 6:07 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 15:37 [PATCH net-next 0/5] net: switchdev: Tracepoints Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 1/5] net: switchdev: Wrap enums in mapper macros Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 3/5] net: switchdev: Relay all replay messages through a central function Tobias Waldekranz
2024-01-24 10:14 ` Simon Horman
2024-01-26 6:07 ` kernel test robot
2024-01-23 15:37 ` [PATCH net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them Tobias Waldekranz
2024-01-23 15:37 ` [PATCH net-next 5/5] net: switchdev: Add tracepoints Tobias Waldekranz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).