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: 13527619 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 35BFF60DD6 for ; Tue, 23 Jan 2024 15:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024253; cv=none; b=WX33/xm+l0RzDIAbdLs96DvA8EK59FsqdjYetpy8pUci1o2GjmdWlmWbgYm9/yE7vuT/zLJ4GkNM6acK5huXypIy9/+tgA2TjcuJRxQ4tcWFlFj0+wLcE7Hgm3ndMHna74Zy/YCOk8GItcXKX5lMHDIJlTjYnzB2S43AcNeHEdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024253; c=relaxed/simple; bh=t6uAJFMViO+HMxmFBNUKRYgjnERIYOpZmhn/2AN2c8Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QggeVk6Lb7bHAaxvuARkpiWHxogNu04We+AcAaSjXlKMYbf6vLwPcl5c517L7GQrN1sFqLP72Aw9DkKxviQ5BZOeYEKMWMXn8zPeYyBo5BTL8OuAShVBtY29WV917BQYZtq6jjRPCz+IM+d6HL6jhjfGD2ou8P4Wnp4T8f9zlkk= 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.54 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-f54.google.com with SMTP id 2adb3069b0e04-50e78f1f41fso4587326e87.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=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=kbcLWd0mjETUFf5T0+r55eTYH0TGGoQqRfCIGBY98aKP0yUalr+mIT2wKmM+zQHtnr m4t36gD93ANUscDG8BdpSV28eM0ZRktwu0On6ziaNv3YxjHTg3qtE4MLsCan/Eg3wk3c mJK3VysKsRU6tk0LZHzs0WVKvKPfTjpGkSM7s7B7VsFjzznZMkJ5zRdthRMUNwCqPg8U aMhUvkQbZAn5R/W987N5mfBvjPMw8NG7BEol1xx7VQ86TuA+U6wZ9neO9MbaCJ+ZEQJt AV/k8OPyxr7bA3Ry3sPObDY1WTiyFDZPYqGWEU3EHDdNA6akMJ4Lh0ESd5vgwCYBYZsv Ejrw== X-Gm-Message-State: AOJu0YzW4uBWmDX+zQMsk8j2pZEZyz2i1nIXSHiCEkitiLC4w0fx4uKJ +IX5duxWoUWuzm6ax74SqC4uJXfXdEFZI9iV+3yyeEwOXrTrrFOH81dKYAh4Ze0= 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: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik 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: 13527620 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 6368560DEF for ; Tue, 23 Jan 2024 15:37:30 +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=1706024253; cv=none; b=ZOpecu+y9JBT9VbjrBH7K8jbZCKCiCcaJInRBmxCVZIopF5xFYiveA9xjBmW7lEyzT1wd+yMmtApr6p/rgkypC36teTyjk6718Pb16HddtBHbwORFmkonmsAyNm8NU+3AhI3mdA36Pw0HHySP2O28VWflR7Rth4+hMlYI6uBEIA= 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.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="Sm7tYrJ6" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50f11e3ba3aso6346611e87.1 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=O7B7KENC7RiaZo/SnVGZP+WlzzBc87Kv/M7wos0XZGvA56yhO/FbHChFS48sYLV7Dm AjnGe3OCD7AVIzx4J1JxfUrK3JAQfXSrVJ0ntKzq7sWXxU3znVXtepaPuvmM5ngZuijb OyOHpmOF5glakpn4pS9DeoOyqBYJFvTmCcCmJrfS3Mk4IlcEHpeL2vpeFBf6XkX9Toh7 5hA8BH7aoKaN1CwXFho2pQNSxgY5XrVfhamTDVTmBkjvjVe5FIGWA67gCLypmD/Ad+vz 3zuKm1Qny6h23xjIvmqxS8YdPy9bhnavMeInvXU5VKAnWAG3x+UfOBoOOtMV/e6IAYYQ 9OtQ== X-Gm-Message-State: AOJu0Yz47yNf530W95j5WtAQanXFJeJ61eeywf29ln7yEiyHwqJUExcw QL9h+iqferyE2SZZF+FAxaoY7mdiYOyzlNMAvlxfio2Z53knYciTm9GAEmcogFQ= 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: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik 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: 13527621 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 BE83060EE0 for ; Tue, 23 Jan 2024 15:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024255; cv=none; b=NX8M8RhA05wf5RmA8i5kIfrs6qbu/2kNbREIAc/xOW9Y061+Qm7m5WbXX/lduCcD1976wznqO8L8172iQ2NLSVVHxAKTvFDVuwrikTOygi4HIQhw4caCM45mtg/b0UbvPHIUMomF/MeZjedyqaIsOcNagfCW++lVSsu4a5G7BI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024255; c=relaxed/simple; bh=1TsJyYbT/1jV7UKlwxvsd6loFO5APSuHrGhqo+8jwhA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dpir/7/JTYxCeA4SPMukAamRPcPg3DFpxJJS7HHme/yKyNOtuUnaTd9rHEDa2DK3XLPGpO3y1gU+dknnq2L57naC0myeUHbNcQZbPMS7PQgLNkwI/ChgLh0q8jHljuCWtWlRUxIigyvVN2vv65yT2Y+cx3uDab69kg0qY+fZZXg= 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.54 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-f54.google.com with SMTP id 2adb3069b0e04-51005675963so1449718e87.0 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=Jk++YZapeRLn1JU6HI2+EKJiLcOdHkmUD+/ZeIc4aZK3rbkI9pgLbsA5EaPxTxQ+Nd AyuwJ1bPmlkbURpqVMnKVGsT/YNmFbkKgxkK5MFbdPEbBxZGFokcQHSzYIKeZ5PAadbs J79xPqjy7ZpFJD6OwoTXN0/hT4r2DU3WFfb1SewGsObSCCOIztKPhZVMv2QitznZMHqu 9yD/CYVcdfY4dqXdjzCIC0tmEqxw6rhKdi3ZAnoh+XkA0H4RMVOqT/3bSc2ZJ25+4xLU qSzlCx4zh2lQFi84Ri5SUWhC4V50xMaWQ6jnAHaekbyc80hliFv7+bvFRy2xkSF5656E U6Ow== X-Gm-Message-State: AOJu0Yyg+xADFa1q3HH5LZgfy5j93hb7CMbY5bj7G3ptVIUN5n/5+ZbE tdeZvBHYI0hSdTt1G/w8yDghXT5nigKzGscTrBSr09m+QPl6qk5cJIU/wH4jjsc= 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: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik 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: 13527622 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 E433F5FEEC for ; Tue, 23 Jan 2024 15:37:33 +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=1706024255; cv=none; b=c5DsLyYUXkv9boe03RUPOhCeUfB2reGaIRRmCPp85v6qgzCfS2SXw0lJrOeoCkoIsK3A+3G0wSz8uT+teSmvR4KbPu4b2OLrNcLGabq3rVI442MNJ9FumRyXo/cB0an7pBoV24icvbvhYCyhw4/P3n69NUGkoku/GHqGNkyOGV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024255; c=relaxed/simple; bh=/RqRUE1mkth4Fx6OlTh2gyGLCEjIzPVJp+v5ODcYjog=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IBbxBXSnZC/yoJv+vgxFzIOsKgCSjyegupBV56WPqndmMATQ2FeqfL74QT+KO8VfODmRLSqJ9mI+McxKO0WAJwT9f8bf4cpX/fVaZglloGeNMrVJzcM8wnbU3jOQDn8Ld3P1J8i0aCxhPCslveLoo5rclEak6N8gmC5TJFLOgJ4= 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.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="lF/6u8Yk" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50e766937ddso5237932e87.3 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=hzJE/t0zmaYkGpI6kqGdpJpT/Idznguw5BrFkFwYij3A56zfkIMRVc9tpZs6izFNAa uypSoFXml3O+hRMyno3TwybhxE7Zu9HTpCcqnbYBCUMAMgkIBMUmJIYwP9k4OL5bz9oY PnfmTIApKaja26EhkQuofAypb/Qvq8uOI8s/FhedIq+3CHX4mAwO4E6rxU3usf/Z3YTK yJT8znLJEzyS54vJPQgnY/vCl1BCG8A/d/MVDF4pOjvzxUXZUXbohencvF0lBJXT0kKe 0IX24GN0mK8aa9rF6QiVetR0To+bs1I2JJisHuDIFCRIjDMSmJ01A3EzWPKEFsKT97O0 0brg== X-Gm-Message-State: AOJu0YyUWC+h4vpZzI6RgAo8K299kDKmQDtiJxBUZh7JiaWWD4/jezwr PTlU2OQKAy3YQC3JSPo2aLnAtiUqCJqnGRlcZt1Gf/fWJFtSTCEnfdan0cBF6Mo= 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: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik 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: 13527623 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 16CF6612EB for ; Tue, 23 Jan 2024 15:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706024256; cv=none; b=dDwLYCw86PXPaBsv+efyw2jPW1pJp7uDe3OVxN5Yau6V5ag1l0Ug/mYjfp9Q/2fhbGqHjbYT3CdTS7IP6sEu30HPjecfd38tbUzgMgHJEoUVAnGtPFaUZimIW54ohZ6LKlRqYCINH/Rsn5HUkJ/yNSnOnSSbt3u0WuOPq8MkhP0= 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.49 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-f49.google.com with SMTP id 2adb3069b0e04-5100c3f7df1so485725e87.0 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=tTGWxWiCgl/sALEjjRduUHp0aGtFazretBN9dpYeIwi2C6ZyiNtYJtjvRniuFCztPT ClGcem6NYPS8ylS4dzH6S53AEWTLkyKUzRvXSM+u+e4ERDgZBXy60QqJXDvKfUhATfL0 kj1zvLAPqW/riq3LdZiIPtUPBGXiq5NVmWkCvzDhFO8AsvVS9qWbOwBqoQ/7EJPILEcG wy8KIYkbrz/ebzAZ1R8pUZk+q4o893WeTRuY1tKXi9qBn2LlsNwL1S99IyueysvKiJc1 ZMRq6ivkB1KtP6sOm/WI2e1Nys1c+5dkgmtyMY+56viWqYepeLrdINY4VqSIjaRdiOI6 BXpA== X-Gm-Message-State: AOJu0Yw8Z1Q5PHYSXc7//dqd2jaeZHmzvCE6ypTcIVPhq9HvqIc1yejt fgJBxO1AFK8HLIHjWbXcrJ9oK6nUpmMVqnU/sBDpGl+AYX3dsHVkpDQWoq2oKHA= 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: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik 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);