From patchwork Tue Jan 30 20:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13537956 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5403471B41 for ; Tue, 30 Jan 2024 20:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645989; cv=none; b=MT2r4qzLXDDckoJVYs3XdBa6g71JdboS0R731qXH5mI5Fs6SKGR6yZ3/gn6gzl7RFD7JTDc1VjdGYXn1Lgbfsg8jvPNlKQtIwXsNWHfQK48cb8IPdZxJWYA/uBTn3ncrcnTHlH5n0yckxjAf4XQXAGkNBktoRaK4mMEccDUB04U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645989; c=relaxed/simple; bh=t6uAJFMViO+HMxmFBNUKRYgjnERIYOpZmhn/2AN2c8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UrBPNE2ULcBlTC+81UGs1VMw2qBtC9DinHojvhR27aomElHTPeXrFS/1k/zich8SZC/Qe1msorTh9vNnmgzpCoPflixWKryPpGdGO/12nx72yk/mxylBdiyoUB/+AoWbNctAtbspgVzlDlXCtufp+SrOwAxY3SOh/A5Ld0wQb9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=eScS3OeL; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="eScS3OeL" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51124983d6aso14191e87.0 for ; Tue, 30 Jan 2024 12:19:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706645985; x=1707250785; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=fPaQcwVDm1hs7rZIx/MRtZyeT8rTUy8NvGG7kGqel6E=; b=eScS3OeL/lzsv40EpDYybNhG7LlohDyshvByKfgRtm2FRRiLX2NMqx/342nUh3BCvj 0MTHKrLg9rHf/19u3A0l4mhVew6UCpwxuw89mWz0WgnFwiQUGy1G2jHt5/DnRVsC8EBD M41UZAMnnfG4Vd0VD1MN5M5JjiWaI3Pb+DtV1+M7nsbgO/NJL68bCjLDZcPGRkcnCrpk jQmVX+8csP68xFLZ1UDw2KjiA8sYC3YUxLYc/OwbxhRGGVjK8zNz3CAxe6esrSiaK2aM YsQ2pyvZ4P1gw+M617xenz61xyxaKgRNpU2xPE2DObJqqB1T2mJjAkdWX+TXQMWxkY+N dpLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706645985; x=1707250785; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fPaQcwVDm1hs7rZIx/MRtZyeT8rTUy8NvGG7kGqel6E=; b=vKwk0meDMfC2ZksCKVj2cEC1huF4hqNaR0XDwAI6+/W4FpcKo3yxVGcvxYT48kLGDu 9CBSL6NurFr+jB4Sak1t6GE/8qOHgC3ciUfd437G1YdDQxtL9rO+lDR9ezXEb1igT8yN 1yaL24t0oWdQmhJuPszGfLG3l6te86QYObjYUwzdzWvHqJDQ6ZnoA2ml78MhZzm5cBxD F2N5zJc5VyM6d3KaYbIXE4EZJAc6NyJzEYAft2fI5Xi6F8rK9PBhCk9EvlP0XyGrzMpo gruUrm5DF08oaX9R3etd9pG0MCBwEUdllU5gvJpIYvRGOQvWFIE6IkG0/dIUClyjaNes 53Cw== X-Gm-Message-State: AOJu0YzXCkpgsb6Ej9pNQy/+6a4LZT4hcu4FAssBEPuKTD1irIeVPu1l LEVXKgC+YSqidnblLJ7ufoGYXYi6W+PtO1coCn6OkfrdICjaPCGx+de7JnlXrN8= X-Google-Smtp-Source: AGHT+IHVFNSV8RrsmxF7rB9qO1wDYJNJ81lroNkUywKlt3ACrS5kOQcymNfQt+XC6TRgrh/CGOyWFQ== X-Received: by 2002:ac2:5f0f:0:b0:511:17f1:8e09 with SMTP id 15-20020ac25f0f000000b0051117f18e09mr2478972lfq.35.1706645985304; Tue, 30 Jan 2024 12:19:45 -0800 (PST) Received: from wkz-x13.addiva.ad (h-158-174-187-194.NA.cust.bahnhof.se. [158.174.187.194]) by smtp.gmail.com with ESMTPSA id eo15-20020a056512480f00b0051011f64e1bsm1553239lfb.142.2024.01.30.12.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:19:44 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: jiri@resnulli.us, ivecera@redhat.com, netdev@vger.kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 net-next 1/5] net: switchdev: Wrap enums in mapper macros Date: Tue, 30 Jan 2024 21:19:33 +0100 Message-Id: <20240130201937.1897766-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130201937.1897766-1-tobias@waldekranz.com> References: <20240130201937.1897766-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 { From patchwork Tue Jan 30 20:19:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13537957 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0EA71B53 for ; Tue, 30 Jan 2024 20:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645990; cv=none; b=YReNVHbOu9DDj3s1+kf6MZ95nInXpU3YxeaQi486dlnlDCEb+1MFmPe/Xtl06WIp9gLa8Fu6P0j2i+mh1Vt8B8K253D4SIheVbJ07qhm5PRNKjRXPT99K19mGYQOHj1GKrQEb9uEqiwEMKUck3qipYnbGHl/CXMhhT89+QIsbu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645990; c=relaxed/simple; bh=jCjAbkJtriD7ifpw1qebNMZZ8BWgs8SNrPPMBTZcbt0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rpf69wqH40YBWqQUUyRJ67769/ez675Ti0x85wNfZBHUtCmQBpM/teJIxXZWtCjgw9xwSgqVmk7ENf/8V1Gf5c9jWP+NMz9HdES+u1eSDe8ko8sE7iYeds07jLkQLhmM3/s8dogmFjwvYoXQOlcgXIURsuKBizODqzKiij2BPeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=yc7p5Ai7; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="yc7p5Ai7" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5111f40b8beso1069540e87.2 for ; Tue, 30 Jan 2024 12:19:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706645987; x=1707250787; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=/kR0u0El9IYx1DrH3bIc67HSSi50NSYYpP/QMJclvuE=; b=yc7p5Ai7FrLtVJkFf/l5EORcZFayOK4J7J1L0ejgFFiKXwpIu8mwyI/9Ggdk5AQcnV EqoJa41j4uHl3AMq3SPUoUMbb8wXAjIExrE1H9T5pLOjK6y3htMfvHl+ZzBqWMcqKmoO 0RuIJHbC4lKlqKMVNmqWx5fh5Baec+zO6u30EUQ8tkKPSFxtxSqXxTFbLXULbef/9OyU aXjemEnq2ZnieF5oslb6QsJMkXqxqklAI6aiIvxoU+dpyR64WM0ndm0slt1nelWffX0m +AaD3VFv87Cutfs8YM6RXdc9ltzEIkoVT7ujF08Ld4NMonSrw7vOihjN792Z8hFHCZZp cHhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706645987; x=1707250787; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/kR0u0El9IYx1DrH3bIc67HSSi50NSYYpP/QMJclvuE=; b=tdQa02/Dvu+BpiEUrqwXaJ00POwV8vvF742YVsmTdZN6oIKJWUyPtFhd6JT8X3C4RP Fks6XF91CaF6/d71uuRQ05ioG/HWd4p0bZCICzB4XMFbKloul5rJliQ87rb3tRgoAqdq rjgvgCS+4d/GHwSd1PeiHdUOQGgqLaEajQlPBXhPmwSOaMlDWU/LWGX2HO4CkXXv3Cat 9hOY2lYHad47IirAAV54+tGBT+4uUrTBgoOLzIK4a2ShBaqGY6uyXBYtS2/sZdF2FJSY E7PKWRHuK1PMAaU14+Z0iVhE46zvNmu3h1BleVmry/R/grHg3nE4v8SU5GaQEQiN16gI qsNQ== X-Gm-Message-State: AOJu0YxyC11px3ovo5f2cTEn/qAcJsF1UORYehldvEyo4UNpW6v3EOws vgUio/jokU5ZvheTig3qzw8o52IXcNSmXAk9ZZND0TC+6Fbuh1MD0DogYR7+WAA= X-Google-Smtp-Source: AGHT+IFh0HHVll5sw5Nq4AgsSSSI6YdJFc2R2Mq9ChKyGSUXQib91Y/1HO7g3O8kQlRBD9kVGoUQwA== X-Received: by 2002:a05:6512:3046:b0:50e:7124:8953 with SMTP id b6-20020a056512304600b0050e71248953mr7611361lfb.26.1706645986755; Tue, 30 Jan 2024 12:19:46 -0800 (PST) Received: from wkz-x13.addiva.ad (h-158-174-187-194.NA.cust.bahnhof.se. [158.174.187.194]) by smtp.gmail.com with ESMTPSA id eo15-20020a056512480f00b0051011f64e1bsm1553239lfb.142.2024.01.30.12.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:19:45 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: jiri@resnulli.us, ivecera@redhat.com, netdev@vger.kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings Date: Tue, 30 Jan 2024 21:19:34 +0100 Message-Id: <20240130201937.1897766-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130201937.1897766-1-tobias@waldekranz.com> References: <20240130201937.1897766-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Useful both in error messages and in tracepoints. Signed-off-by: Tobias Waldekranz --- 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 +#include + +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); From patchwork Tue Jan 30 20:19:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13537958 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04860762CC for ; Tue, 30 Jan 2024 20:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645992; cv=none; b=SwlpFtS7GB/Iv9ClKnfljo94ksjL/3ppp13W26ATP/bESYIsdeegwX5ZHknvMp8B5dWDslY6WZDCDTr10U6UuEVwMxnvUz/eSCY9sqVffjl4nhRuJHF1nxovI4JfBmJr4qSH6THU3tb6cuGPa47jxWMcTKk39FQt2IbtFqJ2eiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645992; c=relaxed/simple; bh=dDP0qs8DhKtLjMFYjmLFo4VHMamdrl6xaZ2AkfXYAoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bCGUjRcTwJwPye21HOgvkq1UrcLZVWZn6jaxK1pX4snozKtlBWqJfJ6rhWz//3j3X9UZ4+F5NoIw+oldc7PyEAaN2jLrnbWJsT/8jeXy1xdcfyk10iSOKe32YiKIlpNJhjhGVABBqK1k3YyPyc4l3YNgLt+sozvAiiKldNBMjaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=2s6U+sKq; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="2s6U+sKq" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d05df82b28so13088891fa.1 for ; Tue, 30 Jan 2024 12:19:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706645988; x=1707250788; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=AsxS6NRjh94C5E7qE0lZySKxuu+izJy1bIEhTVzYMDA=; b=2s6U+sKqyIWITwBZUQbjPxeo01J8APUhWRt9ciEPSuuPZF+LnNK4/sv2guewZSGDwl 1tmSEiDBMR8q1IolCsxqOnvY8YQy0rC7ZE00GFQ+61V2XGA9HszgIs3yJJK2vIOU63qB 5DzcXqavdJmx9gYBY6txQHKz2MQy3dfM+HU+iAhGwuTzx4VspH/7JHsTXFT3ZbbGzHyl 3WMeG6lanKJ+UVFBZOUrBAW2n9WUyB0S3LBjcGOpOTuwtXAqIDS7MlKRwJv/7JwAWEAZ DnhHBuRYteFptWwchjygd4vd9Zm3GZs8n1gtOycH0uW/9zWcb9dujml+TIRTP32cs9VZ F3Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706645988; x=1707250788; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AsxS6NRjh94C5E7qE0lZySKxuu+izJy1bIEhTVzYMDA=; b=TVWqsseZvNcnQu5w5ePGEqiiuZr+NlQComyeNyUi5nnEXGhvnkq1HJtDurdi6NBk+i klzim/M4Qlo5ay503XFJqJdkMOCcJITYgUK5itXGPLnDmp/OmvdqrJpuopoM5roDn6R3 FJqeyMlI5Jqn7fMrpVbfTOmQXffvyJTY2AKIFtm4v653flDBlqwX6ebctYJEWsAM8bUw ie2kLqywqnUgb6mzmdVgTsUi332+hWLKIMpc2CaF+IPm/SkJ74wgeBD6mjmOIJlqsD83 Gc5IOp0Rc0mDDUxX8o1OTYzxM0/eg9EIyGvZ2O7EeDLEu/e8OsIrUxuXpTROwc1eNaw9 HegA== X-Gm-Message-State: AOJu0Yx+5CGbvfqHIFjbXEKOXBeC8MIFJ2VqoRhzOoJrpQ6QzADD2Mf0 y/Abf8qDEFoVDxSvLbUlhYn9DxV84nb2kDDqjsiODIrLEmItnPCzOOD3wMTq0Cs= X-Google-Smtp-Source: AGHT+IF8GONpbLNPK+lC7Gr5bM7GG2hs5GaIlwvCk3P5ob0qBim2niYmBL22jido4U3k8fFb0UdVAw== X-Received: by 2002:a05:6512:11e2:b0:510:44d9:ccdb with SMTP id p2-20020a05651211e200b0051044d9ccdbmr294255lfs.59.1706645988125; Tue, 30 Jan 2024 12:19:48 -0800 (PST) Received: from wkz-x13.addiva.ad (h-158-174-187-194.NA.cust.bahnhof.se. [158.174.187.194]) by smtp.gmail.com with ESMTPSA id eo15-20020a056512480f00b0051011f64e1bsm1553239lfb.142.2024.01.30.12.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:19:47 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: jiri@resnulli.us, ivecera@redhat.com, netdev@vger.kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 net-next 3/5] net: switchdev: Relay all replay messages through a central function Date: Tue, 30 Jan 2024 21:19:35 +0100 Message-Id: <20240130201937.1897766-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130201937.1897766-1-tobias@waldekranz.com> References: <20240130201937.1897766-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org This will make it easier to add a tracepoint for all replay messages later on. Signed-off-by: Tobias Waldekranz --- 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..e50863a03095 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_call_replay - Replay switchdev message to driver + * @nb: notifier block to send the message to + * @type: 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); From patchwork Tue Jan 30 20:19:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13537959 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 328BD762DE for ; Tue, 30 Jan 2024 20:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645993; cv=none; b=MSBaUCEQkNt4KdMiccB2XWJFFTlRHN7YBBhr/fOV0Jzauo3j6ZJlhNW28Wddst66OlAAp0ZDK0VmKxGD+nWIYMWKEWPF7nugPdWXDcrOxfHHsWtSP452iNcxwvEwl9YVHw/xEMxu2n+hjZWVes+RcguPfKtMv2uMJ4GG/NMYws4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645993; c=relaxed/simple; bh=BapIGbjTv4sPl9p+qsdrvQS42GSfWfLQDFaWd63oDPI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tZz14zngCEDVWpCNsumbF2q/VbyG9ej4SdNRlowqtCH46vTUxeOimRTIYK8JfUebzE1LI369yamxmsnXzQpjG348AeblonC4HAvbmYDTCj07XV7ef1rYICmIuKLx543opwJERULed328F/nkDnLlIR/1YeIPnlE8cSiLwCdhqYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=qokZFpw+; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="qokZFpw+" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51121637524so656704e87.1 for ; Tue, 30 Jan 2024 12:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706645989; x=1707250789; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=6IqLnC7Qt5c9O6JLoW4lXxD7qv4Fiq09H4uLYuiQRTQ=; b=qokZFpw+ktITi9NHTIrEofKMviN4fx8OsCyo/g2yzQL7kKI4j2bYmQCVwTXGiGgaKC 3/oBbWauQj8aeGBDixsiJKq5OrzX3NBy8pb+noBvtdSO1FwwwIiDoj7jBvx/zwJJPgO5 Ci2TsjoR4BCrYGQOT2qbQWvvoCttz9e8Rz/kMqI/1fSBPjUX1IWpjaHjp+RBRs2EE4CM 0/8+Y2JHNjAFeRWw4gdf4/n6RJIaZUn0b+h2LiBD5eMx0+wbiRicg4mYp+8QfL8mJTPq z4oijAQicRgxXrTBoO/UQS7Ow5tM/ouoQYA1NpxhVAbNmlCbcAkU3Bq1c4aL3mbFrZYn /ODg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706645989; x=1707250789; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6IqLnC7Qt5c9O6JLoW4lXxD7qv4Fiq09H4uLYuiQRTQ=; b=sdsZfdiZY49+cXl6onxuq36yFiy3gLla260dpiet1IqHehun0ZzvqDhXUYSRC4TkgA +ZliM1628/SRBVlzAijCOTnM1cbNR/m7grZOvEREey/CqGtRuu/qqMf/q3uapGpiPciR d9aMWJSoCbLQBlzZeXtZ3aQVYYCyhhu6Bx8wrK3E1Yt4OlV4wRyJCMu1KeoFKVFVf+rp N65XHDC87Zc0NVuRcKlI3qEMmuXSdaOIAi13/qGFmKlgAZbpX6pGRmiMaO0hq9PPPm8j mfQgNYX7jb2ggrMtn2Qh4L9xDBmkNbGdNxXOFDhvFjUG9OCSSeLrpudCbTyswfp0AveQ J4Qg== X-Gm-Message-State: AOJu0Yzv6rMoZnCQIiWT/mB6xahT10uAoIm33f7opl4RHJ5SG3vwsrVy e/NHwG2mOxDZK82E/4sEDYj7FePuDuXn8AKwurmRQaSmVcIkQl29e5TOFbGbswY= X-Google-Smtp-Source: AGHT+IG9xBVa3UbjflAWcqCxOCqVmwqzOVXMJ08I7VEJoBUQtKwgVTlomzljcxK9lFma3n16UnFzEw== X-Received: by 2002:ac2:47f2:0:b0:50e:7702:a189 with SMTP id b18-20020ac247f2000000b0050e7702a189mr7301248lfp.22.1706645989212; Tue, 30 Jan 2024 12:19:49 -0800 (PST) Received: from wkz-x13.addiva.ad (h-158-174-187-194.NA.cust.bahnhof.se. [158.174.187.194]) by smtp.gmail.com with ESMTPSA id eo15-20020a056512480f00b0051011f64e1bsm1553239lfb.142.2024.01.30.12.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:19:48 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: jiri@resnulli.us, ivecera@redhat.com, netdev@vger.kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them Date: Tue, 30 Jan 2024 21:19:36 +0100 Message-Id: <20240130201937.1897766-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130201937.1897766-1-tobias@waldekranz.com> References: <20240130201937.1897766-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 e50863a03095..309e6d68b179 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); From patchwork Tue Jan 30 20:19:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13537960 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B350E69E1E for ; Tue, 30 Jan 2024 20:19:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645994; cv=none; b=VrzbJsGf+JPo21gPwFfj3zmiB2A41aIhtwCz2vW6M6vHRyT+oozR9fl9C4ZqW8onkAmNdmm4gOxub7uMPSNLAS2/4+Gx5Y0UaCyGQ9YB1rdYwcE1ks9xAvEJ2HrxyxTaOG6MCH7kGa2GBTgOzz65LmL7xSebsodyFvAftn/hjP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706645994; c=relaxed/simple; bh=UdqvnuexMAm+G55J7+COkIYKBfcY+c/M1qBu+dF2yVk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qDYQ0fLYHKEYSmegiCViUTjimrC+nmA6k0s3GEo2C1hlOtMbs7EGKlgM6v082dzZA8/3sKaR8mx3pG0Lk1fqoSpKV8xe57pDm6UWsQo0KrA+n1hNaHLBOzaxZtPFIkzy3jD3fJxt/6aY49ahUQBJpPg+pSrGlagemz5Ced+BjJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=B5fpxlRe; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="B5fpxlRe" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-511234430a4so226732e87.3 for ; Tue, 30 Jan 2024 12:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706645991; x=1707250791; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=SIuAP6PQUuGPqXCgFtQD+C1lmQsDIZ+6D81ojLLsb8o=; b=B5fpxlRe7Rfk9FmSaaQ9jF7fVFafnsI8qNEMrmEeeG5sGwCl+5h3bO4TlO7AovsAr/ FlLxLffiWFyC/XntA5+XGO8YLIV5K4SWDb1zyuUeOib5vy7miNtsH1ptZBmy3DVnYnIR MvlmMcB/SkCboA8ezLJLJDDV8PwqUp4Wk6vp/Z2hPcGOjaagmSO0Y5z9x2FJtCBdm0dM 6Sw09pW80WhLqe88tEli/bPyJBSaGZfaif9w+sC+D8m+VVYwalr3pGbSl/dPuKAeI54e gWoMjLtHDidQEhID7uVKEMTPu/Y8A0SDb2f/LjVvRGuI87fw3kH3DvrnE23dWZDbn13s ZY6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706645991; x=1707250791; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SIuAP6PQUuGPqXCgFtQD+C1lmQsDIZ+6D81ojLLsb8o=; b=Gb6A8KmSGVvgSJvhIjoxByZdg6dqw0dYPY+8G933Fooj+prLNaJfuOs7HeAHYOXVjf QfOLq8o6OuxNV1+GFExBQIhJhPcG2D2lycYf+/dDjpoIaHGa7SKe6gYj3tD1r9fA40O+ 6QO7kZ3vSSk8fOmn/AHOJyinNNhm1BIGv3I8fd6M08xszs+U47UwltzcBi/UGIyrXwKH 1dgXM11ZXKx7hO+Ti4eN/H9f9/BVUHoUNbwTHG7iGPlF3T3EVKy9Hmc3rRTBKnmnUiCO THf8/O+871DjMCGOKrlVlvGEL7eFIOwG9/NlG4pQ5toAZpYPmbWkMF3ZcH8h8SfK+ch5 m/lg== X-Gm-Message-State: AOJu0YyNibz2MW7tqoZd+BbExTyxw0jUTCqNH7UOp408IgzoMulejolr QXTu57CCIS8d32M5gmZwkMFlPFGP/42m81XGn6KIHjcKsF5MrxYx/dfEKEzDu04= X-Google-Smtp-Source: AGHT+IFmAHANnc8lBuMLQU9Bl7IRpJYPUmp56zsYq4M0h8z7F4wob9ymtRBl4oy5k0AvQ5bTalzhDA== X-Received: by 2002:a05:6512:3996:b0:510:67d:7251 with SMTP id j22-20020a056512399600b00510067d7251mr7082285lfu.47.1706645990624; Tue, 30 Jan 2024 12:19:50 -0800 (PST) Received: from wkz-x13.addiva.ad (h-158-174-187-194.NA.cust.bahnhof.se. [158.174.187.194]) by smtp.gmail.com with ESMTPSA id eo15-20020a056512480f00b0051011f64e1bsm1553239lfb.142.2024.01.30.12.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:19:49 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: jiri@resnulli.us, ivecera@redhat.com, netdev@vger.kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, rostedt@goodmis.org, mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 net-next 5/5] net: switchdev: Add tracepoints Date: Tue, 30 Jan 2024 21:19:37 +0100 Message-Id: <20240130201937.1897766-6-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240130201937.1897766-1-tobias@waldekranz.com> References: <20240130201937.1897766-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 +#include + +#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 diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 309e6d68b179..078a8c68e9e8 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -19,6 +19,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + 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);