From patchwork Tue Jan 23 15:37:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13527613 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 86F3E60DE5 for ; Tue, 23 Jan 2024 15:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024252; cv=none; b=sGYRIUE6PhBqeApGqCG8vZNircK2WWFUZf0E/uM8YDDtxPa93TIvEk27iI+264ysoHMZCHSrPANd212jl9IR8T53QcOVdkm6fYdoA3BHvnpt74Jdu2MQctik7zghBgGqL4uwnweDKHY8dVHMYD3WnXr+JOHTiJNmug5SBdAEoWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024252; c=relaxed/simple; bh=t6uAJFMViO+HMxmFBNUKRYgjnERIYOpZmhn/2AN2c8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fxa5punrb3tRIFqqbwSd+9ksKNxQDFll/vImao1VjRtqjaadrASyj7JDBSLjr8ck1at7llw2Sfyzk4yDTZGsmlaUoWBwzRewLefnNgobU4jdWEwCx2b72uR2TbbsrQFv3f68iTAgZAqJqt1a50bilb/ZKdrrk3IfwXhYIw29FOY= 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=jugQnHRA; arc=none smtp.client-ip=209.85.167.44 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="jugQnHRA" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-50ea9e189ebso4875870e87.3 for ; Tue, 23 Jan 2024 07:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706024248; x=1706629048; 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=jugQnHRAURw/CWK7AiGJjmqMJiu7YZHy8LBqmpXeCQPnXaMfjsJ54BxQX7xk1c3bXA lorUSLOp7ZYyfmwDASmh0P9splGGxPjEPhfnDSrowubSnsRJr3v/D4TLQPlmZau3pYgi dw6w05nsjTIDqmBBfNfof3/C9xt9jr8wSXpAMgsKlXU3UucUsiPo16u6G02twQOQjNkj 4q9xu47yTuzQucagBgr93tMhzzBOFt5w3Qy+zwBOG2CPZLN323xfXYMTxwF3GRma/3uO DRv/DO4Nh6CMo0StEquYvmRy/M4FknhuiPstVbEDKLx/yKWoyTuWHf+PTk1dBXUHsAC3 IcAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024248; x=1706629048; 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=pr6CCHCxapEsQA9E/MCThYV/4orDmjYetuL4/3vb0gdE5m7S9HuMIofarHn0IxADZg UryOvscHG4eJ9Kb0WGT0nbgGJV3hB9fu/qQabt6kz9diI+Vycbu8jPTG+dQ7FDUtmqvS Yvzia6wzgI2BkN6q8ccwLXL1pkVqxql8CtGr+19hSHPZ7cECjQtHp7VbJM39P+JpjDHz fYdhVaQJBYbp7LoQmEC+cqGzvFDWvwYskLwnzsF9wRMx9nFDPZ0b/HixbaU2obwD3c2e nrdvmNjBL3w4LEN+6uHJdoDEeGIUEXD+ke42oqqMCXv0sdYWzbK4fGp2XBWiwXRlVLDE jiQw== X-Gm-Message-State: AOJu0YwAmz14e0DnxHPTBj3hKcvoZOgGXp6ipqDcgDPEnN4boVYYtsTI yiuaFUo/EfWgACub/aZFbSF3AkP4RgUXm2a1e6vDsy1nqdg9DBnsINmZLltFlfc= X-Google-Smtp-Source: AGHT+IFPao4jpCTPjIUWAvgQ5SK98Il76XVbN67TXhfZYef6P15A89B9DQmxDv6/+zvp20DDi5NJVg== X-Received: by 2002:a05:6512:1243:b0:50e:4fb2:a65d with SMTP id fb3-20020a056512124300b0050e4fb2a65dmr3212895lfb.6.1706024247984; Tue, 23 Jan 2024 07:37:27 -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 h23-20020a19ca57000000b0050ee3e540e4sm2386790lfj.65.2024.01.23.07.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:37:27 -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 net-next 1/5] net: switchdev: Wrap enums in mapper macros Date: Tue, 23 Jan 2024 16:37:03 +0100 Message-Id: <20240123153707.550795-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123153707.550795-1-tobias@waldekranz.com> References: <20240123153707.550795-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 23 15:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13527614 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 5AC2760DEE for ; Tue, 23 Jan 2024 15:37:30 +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=1706024253; cv=none; b=cThYO3Ew0q5I+R9ZkP/EACdeV/n+RYgD3Y40yx8+BkUU8ITcaTS9VcU0vCfFbrJVn4OYqAKHkybgJrl9JtrMGYDQLtrb3X85qY2tx8YU+41AiPoO/sw+LtkrpuRPQb3qtUaxfXIdvlpjKi85Thzk64GGK1E952GqUSmzWs3KXYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024253; c=relaxed/simple; bh=jCjAbkJtriD7ifpw1qebNMZZ8BWgs8SNrPPMBTZcbt0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C2cngByScRonT74gGhEAIeoWJ0v/KOkhKhyzrcHAL+XwMCjA11J4HKK171atJzaHowuWE27V3FPRRNuTXu4HcAnLdXTwuEWeNm38jm9RzZO/EUyxakSKWpRnoG99SUC+B06DaqMcPwvuLIDoOJwrS0BoT7D9+42Q95VwMubNnmc= 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=Sm7tYrJ6; 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="Sm7tYrJ6" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50eaabc36bcso4800394e87.2 for ; Tue, 23 Jan 2024 07:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706024249; x=1706629049; 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=Sm7tYrJ6sRNIWeb6yWs7oI6wGD3zl1fmpUXerP0Z86/vGaazMKRfrtEML7OY9KYjWs KKZNFw+ThRw8L56lt8S3Od/eWNsvehdM0AubYoDsHCPH6qW3PpFrGwPOFQXqv2JYDOXm jBXcFLGz/EXJoWKwkTe5DuPnL19PiP2olQmbIXy0/2NmArSi6++9SxiKQc8ZVWGrY8h7 rBFq34/z/GfpAzK+i7FOK3uw9WwwxpN8cekDCO9h+UEcm9uF957g5bZDzTvAJoMeknIi WG38xPa6DUV1MEnd83oXBCyHqktiqli9D+u0t3GXNCXDHiti7CC3xLCfOmPPZ3po+1Q3 7MXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024249; x=1706629049; 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=AVIvbGJXAUs0Sr1/yB4rdwBO8y1dkGHxmX9sAVKmB+ZAQKMWRKK9jLBlDGr1Notttm /C1pleNBGsPHMmehCgSfvGUliVyHsnlxp3SuTP0+/L6M4Z1DN8DGktq+Iw1xYFLVjl0F P+V7mPypUjuCdRYrD+N1VvV3iJ9DUelq/X/kfJgjrkkBOtmXYI7Z9kjp3IrdcJtoWlms fUgdZrH3JWmQrGUqdeeF7V7hwPF7YbyW8fk230JuW0Y+U1LTGJbLhS/L9jfuXY+8k+7n rXTvd1dtYAOxvl1ULeSrh+abl2mjHBvMTtjCzD85WBk2DC69fNnkRnBmN/3x+HXiOFbg 9JXQ== X-Gm-Message-State: AOJu0YxHVpKJBfL8zP1vdsFR09w4tmQVolmLI4PiNsnJVSjUoCZnJvgg +YtpPFcw/KrFqOgzTgC0PU8P9Jehva2twaWvEu64hGjs7hRhdA7r9rwee1dk/w8= X-Google-Smtp-Source: AGHT+IGSn5CrzlN+/laBMcMd+rqCGstwG6C5pv+WqobE9f+hz4U2/blyIRzhX9e/Kg61UXM8SOisRA== X-Received: by 2002:a19:7001:0:b0:50e:4fa2:4fe4 with SMTP id h1-20020a197001000000b0050e4fa24fe4mr2218128lfc.66.1706024248871; Tue, 23 Jan 2024 07:37:28 -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 h23-20020a19ca57000000b0050ee3e540e4sm2386790lfj.65.2024.01.23.07.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:37:28 -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 net-next 2/5] net: switchdev: Add helpers to display switchdev objects as strings Date: Tue, 23 Jan 2024 16:37:04 +0100 Message-Id: <20240123153707.550795-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123153707.550795-1-tobias@waldekranz.com> References: <20240123153707.550795-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 23 15:37:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13527615 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 D95EE60EEA for ; Tue, 23 Jan 2024 15:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024254; cv=none; b=RNUdCxtOzxqr+YBOe8+BKmVzZ5n5cD/Od00w4fzOay/WbjccY8ZOvHpFYO11mNfOXVWLSftnrF7cw68KikoQjdLuj60vI+oV2m4SZvkT3qcIqrFdsq57bkJuGUrXQeOygVG/AhPnxmTntTHOx9Da84UAzZ2Jk32bEQW5lMWSpTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024254; c=relaxed/simple; bh=1TsJyYbT/1jV7UKlwxvsd6loFO5APSuHrGhqo+8jwhA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IaVhJL67ArExkyLQNQyEClHTQBjp/HpJeko6BGOx0Q1pDELlRaLUcxwHOBQN17KkyTSg4AOTVkZU+PaVO+UI0fSRWyEx0B30GQ3bvfkzwgcIeglG5eR6W+05Pqff+MKg6qqQnYKJ9Hf6fszegZADyLVopy8hZ4f1t0X8V+nFPcM= 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=pyDZMpMV; arc=none smtp.client-ip=209.85.167.48 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="pyDZMpMV" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50e7c6f0487so5032666e87.3 for ; Tue, 23 Jan 2024 07:37:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706024251; x=1706629051; 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=ummukqbZPLomPcHTqdN4PTAj0S043AFrvZ+O3aml3do=; b=pyDZMpMV3sQZNjsTnxv7kH4FRwFtMYchkuRaHwaI9czp69Z1efPimswwdiLiZBsbDQ 9I2Qk5spCHZKgPoQWm+YRam28vV38MTkbqX3LhHAm6j+MKA1/W91/yC1OdyLE8eRYO5Y 1vJsKAVLofb4MrkNocGnAtwRTMY404sbTyGAmmpF8bfjFslveiv16cg3SLrH9uqNs5Cy JRkoF6UyZ4jdKsEIQ9kkuYOqs+ZWOo1vHM+DVXF6m1afAuSGu0NMYsC4uYwd0UazisQt aTTcAVW+pCw8dyMzjFv/aEUcZoMTh4mD5jR8DO893cR4FtM3pW1VFJmZ+8eukkSYLJ+a OlXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024251; x=1706629051; 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=ummukqbZPLomPcHTqdN4PTAj0S043AFrvZ+O3aml3do=; b=SAPJGpw8pIE5dUQGmag1NEs/WX6taTIcYpomelCnMNlY7/SAuchdsOX1WDUNJk8mbe QOM6QHtMmAgdwyrhac97DV4md6svSTtHRZR4UrXXR1s5oVVCDpdAgo3O6FyiuEA5b+Kj fuPSVkl+bw9ZwNUVv2Jgrux5n4zbSHCgiF7JhbSD5B+2BaJXYr6wJRs47uekjdEKVnL+ bfLJ2N5ltZFqLkUu8H4GoGclOiqdSNN4cpIS+cn6H8oigKj33akTzHGscZgrhjwBsjEO lJsDRYO9oo7zwUj6E8mXN8VvYiG7P5SPsPtICJzCSzCES3zTrUyuMWxYsGaKJZROCqoj RGEA== X-Gm-Message-State: AOJu0YyKBsGC8pqnjAzNfAfoyjmNvuHH78WoJ4GpXih+R+41CnLpyV/f 9Ggpyv9EOrRo0Ut8MQQQM2EjhrIjdld3WgfKHF1o4REGa05+RMTowclxqotCbmU= X-Google-Smtp-Source: AGHT+IF4GqCEHYFPDhgvrqbieCdj3I6rehdUcJG37iFiPhk/Neolyfflf2C05+vFqiv1ru5o6lhYKA== X-Received: by 2002:ac2:5e32:0:b0:50e:c7b2:cc77 with SMTP id o18-20020ac25e32000000b0050ec7b2cc77mr1395317lfg.198.1706024250919; Tue, 23 Jan 2024 07:37:30 -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 h23-20020a19ca57000000b0050ee3e540e4sm2386790lfj.65.2024.01.23.07.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:37:29 -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 net-next 3/5] net: switchdev: Relay all replay messages through a central function Date: Tue, 23 Jan 2024 16:37:05 +0100 Message-Id: <20240123153707.550795-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123153707.550795-1-tobias@waldekranz.com> References: <20240123153707.550795-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..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); From patchwork Tue Jan 23 15:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13527616 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 28400612DA for ; Tue, 23 Jan 2024 15:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024256; cv=none; b=YnVmmqYACF5Hsd9aGaIsgHkYEsm70rfT50i6NqyDnURtdn9lcNSqarhfBZU26LkV+5g1Z8sggkS1s071wGNcWOqFAs86M8luNF6ZyryjlXrbWUBS3miBqWFAaAAclwkAiJlvAqXgFBhEUBOXTl4xiVSxgVmDx/NsYlzSoDfpQDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024256; c=relaxed/simple; bh=/RqRUE1mkth4Fx6OlTh2gyGLCEjIzPVJp+v5ODcYjog=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z0totbiqia4PFrIHwrleg9rStQwwiR1APSyqRoxkH2d+y32BBR//LdAWWxzHHwbBZ3bibuldTS9ATp4jj925bqlruHo+Cwk3MOx/XD0499fn2/ymCnt8Z6t8v+13c0GWc14iOn2glUiD8h35hWc2+UTkCe8fSOsH5Oc6fT/qK50= 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=lF/6u8Yk; arc=none smtp.client-ip=209.85.167.48 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="lF/6u8Yk" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50ec948ad31so5108856e87.2 for ; Tue, 23 Jan 2024 07:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706024252; x=1706629052; 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=c5QFONxjqDFPmvYCz3fTIsy79ksSpzxsuuWy1xW2EhQ=; b=lF/6u8Yk/be+ArVPUCP54Hn6GiWZE+3TLzlY6dnl1IHeJIP1YkzemRK7EZQ/d/+DuG rznoQxrimx94g8k8uvJBZ/Qg4ylnPdmCp+sFo32HmHHVobwjmrDFdU1nPahGEPkD942a yhRRtAiFYnSyP4NCUzUgZptEIkpOZDLTrdepOEhVHCogNgtCBKcEppujfrPIRr77k6TE kNCDQa+T4ImHeUlqLvMJ4uJ3zHiZ5JyZaGEtE9mo65rdr81A4tM/0WIU1rtT0BL8ab+v ElVPChxpdND1N366ZuXeb3ucsJiehl8wYP5uTAkcD9x40Vx92a0N21gnxPxRUkWl2P2S Wbjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024252; x=1706629052; 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=c5QFONxjqDFPmvYCz3fTIsy79ksSpzxsuuWy1xW2EhQ=; b=iXknu6JVYYRwzJWMt1lYhc1uvhZzUU+tEhOXXglTIaupjQmoDK6eli1csknwWDED5U EcHQ28ERGl0cG1h1YMmSHoEc8SHssmHsrhPU+rlFCNcBOnAkXkUxp/xWaqq/DgcIJOeD +vswSVMPA+phg2uFI9AOLZcve/NIgy/GwJBoFs25G9Ywx8cJJT2zc10iaC2YS769dYLD 4HUeHuQSVxEV883tpP59Lxmx9hud75AzCsz5q2zW/LXqd6/8kIom9pc6iFA7OKDV+VD5 3cDpnCMAjXzrAmf+ppDpqklSQhrwbnlNqj23+Y0C6ZyoATKniaK78kpWmxLRGMbBhH2G o3Tw== X-Gm-Message-State: AOJu0YzBv02DHBtM2sNnIMojS4mZQ01NmqezWao4ZicHCudl7+5f0SBL 99wyllFfb2PfU5F4hsU+g7NtO4jl7gaLwzX6GkELrUqeDXiqd99HswKeq7SXlZo= X-Google-Smtp-Source: AGHT+IFrRADx7IZqAYiOZ+/0x+Cffzju0ugCtSuIOqkOxn1Z6W4p/ei6B41mn3Yq/2Y5aXuWQMYybA== X-Received: by 2002:ac2:5b05:0:b0:510:c7f:dc9a with SMTP id v5-20020ac25b05000000b005100c7fdc9amr226738lfn.24.1706024252049; Tue, 23 Jan 2024 07:37:32 -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 h23-20020a19ca57000000b0050ee3e540e4sm2386790lfj.65.2024.01.23.07.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:37:31 -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 net-next 4/5] net: switchdev: Prepare deferred notifications before enqueuing them Date: Tue, 23 Jan 2024 16:37:06 +0100 Message-Id: <20240123153707.550795-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123153707.550795-1-tobias@waldekranz.com> References: <20240123153707.550795-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 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); From patchwork Tue Jan 23 15:37:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13527617 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 120BD60DEE for ; Tue, 23 Jan 2024 15:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024256; cv=none; b=SjUacR1o65xN6mcd2psWXmzUjqHT0qoAPtJvPxc2XUX01bY67L2QOSFp85bSKutgMfCFK1KIZXuKw6fzBl8qJC0dTP0WjK8Myjs0SZres7kxk38Eo6SaRdySSHtglrdVRI0x3KjLlWu8PT8sA8Hu/WfMmTPDTM7+B/qutlzNUFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024256; c=relaxed/simple; bh=wyizF49U6tvokpvLf/lsprRLkEW1vFMA16uQzuKNOdQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h8j05JMPZPdvvmMhrG/m1+qXi8lIplfvWrHcGJkaT9eY7ibJuRdSqwDJR9qzi7b2ff7L46iDhkMacP8fh6/0EUDucxeTVJklPuTg+Ew6Ge9o2l3QqrB72wEH3v1POrUGh9GhJLrM1xdHH2ypvRAhC+beXU+0k9DQcaB0x1HkrXc= 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=d9fj9ngZ; arc=none smtp.client-ip=209.85.167.51 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="d9fj9ngZ" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-50eabd1c701so4939274e87.3 for ; Tue, 23 Jan 2024 07:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1706024253; x=1706629053; 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=IgEY3zw7gCnp7Jd7W+bim14DEHc/z3jVzwr5Ze0i4MA=; b=d9fj9ngZEth/43NKon4xcxTroD7v94kZwSZqpCkbacuJBlisctznvfls3UywNOrkfK s5mistU6EpJKQh5Qqxn0Fy1dCQvXwwZtWXszvvOQqnfLsYWgBijJayjuPjxai7hoDOjY TBPesEdpL6LZikP8ANeeKkvraLuNhkBRDBltDV98HgKJA8zKB4kawZO+3wGp+fDKbKJj 9sN2VmfqFnZhcLyx9Dhc3WbLuwGB9hrcBhqudC1E2/rG+9zkeAdW9NuxkCoc5QOMYYWN PaNaD79j1HtSUDAlRXlWaTDktPaOLI2ij2+pkgOf6oLS7RtUzwmrs0/6rzik+qqqaNle Q9uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024253; x=1706629053; 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=IgEY3zw7gCnp7Jd7W+bim14DEHc/z3jVzwr5Ze0i4MA=; b=amjAYxg85R6ihHcdyJpo65SmUqLhUXGBZHeG08/KuGvHIi7/Ij+TGa1J9khp7q1Cn6 vkCJBN553px24x1ljykSONsInRQPBG1vSoHdtHtWqoh2K7tt81rTj6vv7T20ktpkWjJ6 o6irtjy9f7/Sy+9HH3FUbp9PbEwpf6ARtCCssZPY/UnXbRoX61VVaYJH1TEC0WaS42/L /WbEVZx20LVF7P8Ra4UQ3qMFwUjQ/IG123jRjM8g9m+n7LYQbzinUpJlbNUY6DPwxT5n N4l9gTdUinArf8OsSbSxDNRqCntGx/Snaz0YvFjbSW/yXafN0KA98JIHVTZpzl5isuEl 0Baw== X-Gm-Message-State: AOJu0YzaWki/MgEgNoJiEwzg0I+gcmnc8pmMhy6Om08wm0XXIyEh+Sel 0lQQMYy19ffsLDBYYsPCcreRJklDc7MlBsSbBUL8DiL4W89ez3KEjNkwPFqi5ew= X-Google-Smtp-Source: AGHT+IETyN+7Poxhx/NY+J4jPZqQz/BpB9oTqL8PQHr1eatRG4ns8rNuqYk1DpfedCgkPIb7Y66llA== X-Received: by 2002:ac2:4a8b:0:b0:50e:7be1:f0e3 with SMTP id l11-20020ac24a8b000000b0050e7be1f0e3mr2768394lfp.83.1706024253274; Tue, 23 Jan 2024 07:37:33 -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 h23-20020a19ca57000000b0050ee3e540e4sm2386790lfj.65.2024.01.23.07.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:37:32 -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 net-next 5/5] net: switchdev: Add tracepoints Date: Tue, 23 Jan 2024 16:37:07 +0100 Message-Id: <20240123153707.550795-6-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123153707.550795-1-tobias@waldekranz.com> References: <20240123153707.550795-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 6612f8bc79c9..dfd9cf75f397 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);