* [PATCH net-next] netdevsim: add dummy macsec offload
@ 2023-06-11 15:45 Sabrina Dubroca
2023-06-11 17:08 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Sabrina Dubroca @ 2023-06-11 15:45 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca, kuba
When the kernel is compiled with MACsec support, add the
NETIF_F_HW_MACSEC feature to netdevsim devices and implement
macsec_ops.
To allow easy testing of failure from the device, support is limited
to 3 SecY's per netdevsim device, and 1 RXSC per SecY.
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
drivers/net/netdevsim/Makefile | 4 +
drivers/net/netdevsim/macsec.c | 355 ++++++++++++++++++++++++++++++
drivers/net/netdevsim/netdev.c | 3 +
drivers/net/netdevsim/netdevsim.h | 34 +++
4 files changed, 396 insertions(+)
create mode 100644 drivers/net/netdevsim/macsec.c
diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile
index 5735e5b1a2cb..f8de93bc5f5b 100644
--- a/drivers/net/netdevsim/Makefile
+++ b/drivers/net/netdevsim/Makefile
@@ -17,3 +17,7 @@ endif
ifneq ($(CONFIG_PSAMPLE),)
netdevsim-objs += psample.o
endif
+
+ifneq ($(CONFIG_MACSEC),)
+netdevsim-objs += macsec.o
+endif
diff --git a/drivers/net/netdevsim/macsec.c b/drivers/net/netdevsim/macsec.c
new file mode 100644
index 000000000000..355ba2f313df
--- /dev/null
+++ b/drivers/net/netdevsim/macsec.c
@@ -0,0 +1,355 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <net/macsec.h>
+#include "netdevsim.h"
+
+static int nsim_macsec_find_secy(struct netdevsim *ns, sci_t sci)
+{
+ int i;
+
+ for (i = 0; i < NSIM_MACSEC_MAX_SECY_COUNT; i++) {
+ if (ns->macsec.nsim_secy[i].sci == sci)
+ return i;
+ }
+
+ return -1;
+}
+
+static int nsim_macsec_find_rxsc(struct nsim_secy *ns_secy, sci_t sci)
+{
+ int i;
+
+ for (i = 0; i < NSIM_MACSEC_MAX_RXSC_COUNT; i++) {
+ if (ns_secy->nsim_rxsc[i].sci == sci)
+ return i;
+ }
+
+ return -1;
+}
+
+static int nsim_macsec_add_secy(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ int idx;
+
+ if (ns->macsec.nsim_secy_count == NSIM_MACSEC_MAX_SECY_COUNT)
+ return -ENOSPC;
+
+ for (idx = 0; idx < NSIM_MACSEC_MAX_SECY_COUNT; idx++) {
+ if (!ns->macsec.nsim_secy[idx].used)
+ break;
+ }
+
+ if (idx == NSIM_MACSEC_MAX_SECY_COUNT)
+ netdev_err(ctx->netdev, "%s: nsim_secy_count not full but all SecYs used\n",
+ __func__);
+
+ netdev_dbg(ctx->netdev, "%s: adding new secy with sci %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->secy->sci), idx);
+ ns->macsec.nsim_secy[idx].used = true;
+ ns->macsec.nsim_secy[idx].nsim_rxsc_count = 0;
+ ns->macsec.nsim_secy[idx].sci = ctx->secy->sci;
+ ns->macsec.nsim_secy_count++;
+
+ return 0;
+}
+
+static int nsim_macsec_upd_secy(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: updating secy with sci %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->secy->sci), idx);
+
+ return 0;
+}
+
+static int nsim_macsec_del_secy(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: removing SecY with SCI %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->secy->sci), idx);
+
+ ns->macsec.nsim_secy[idx].used = false;
+ memset(&ns->macsec.nsim_secy[idx], 0, sizeof(ns->macsec.nsim_secy[idx]));
+ ns->macsec.nsim_secy_count--;
+
+ return 0;
+}
+
+static int nsim_macsec_add_rxsc(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ if (secy->nsim_rxsc_count == NSIM_MACSEC_MAX_RXSC_COUNT)
+ return -ENOSPC;
+
+ for (idx = 0; idx < NSIM_MACSEC_MAX_RXSC_COUNT; idx++) {
+ if (!secy->nsim_rxsc[idx].used)
+ break;
+ }
+
+ if (idx == NSIM_MACSEC_MAX_RXSC_COUNT)
+ netdev_err(ctx->netdev, "%s: nsim_rxsc_count not full but all RXSCs used\n",
+ __func__);
+
+ netdev_dbg(ctx->netdev, "%s: adding new rxsc with sci %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->rx_sc->sci), idx);
+ secy->nsim_rxsc[idx].used = true;
+ secy->nsim_rxsc[idx].sci = ctx->rx_sc->sci;
+ secy->nsim_rxsc_count++;
+
+ return 0;
+}
+
+static int nsim_macsec_upd_rxsc(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ idx = nsim_macsec_find_rxsc(secy, ctx->rx_sc->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in RXSC table\n",
+ __func__, be64_to_cpu(ctx->rx_sc->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: updating RXSC with sci %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->rx_sc->sci), idx);
+
+ return 0;
+}
+
+static int nsim_macsec_del_rxsc(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ idx = nsim_macsec_find_rxsc(secy, ctx->rx_sc->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in RXSC table\n",
+ __func__, be64_to_cpu(ctx->rx_sc->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: removing RXSC with sci %08llx at index %d\n",
+ __func__, be64_to_cpu(ctx->rx_sc->sci), idx);
+
+ secy->nsim_rxsc[idx].used = false;
+ memset(&secy->nsim_rxsc[idx], 0, sizeof(secy->nsim_rxsc[idx]));
+ secy->nsim_rxsc_count--;
+
+ return 0;
+}
+
+static int nsim_macsec_add_rxsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ idx = nsim_macsec_find_rxsc(secy, ctx->sa.rx_sa->sc->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in RXSC table\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: RXSC with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static int nsim_macsec_upd_rxsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ idx = nsim_macsec_find_rxsc(secy, ctx->sa.rx_sa->sc->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in RXSC table\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: RXSC with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static int nsim_macsec_del_rxsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ idx = nsim_macsec_find_rxsc(secy, ctx->sa.rx_sa->sc->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in RXSC table\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci));
+ return -ENOENT;
+ }
+
+ netdev_dbg(ctx->netdev, "%s: RXSC with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->sa.rx_sa->sc->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static int nsim_macsec_add_txsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static int nsim_macsec_upd_txsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static int nsim_macsec_del_txsa(struct macsec_context *ctx)
+{
+ struct netdevsim *ns = netdev_priv(ctx->netdev);
+ struct nsim_secy *secy;
+ int idx;
+
+ idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
+ if (idx < 0) {
+ netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
+ __func__, be64_to_cpu(ctx->secy->sci));
+ return -ENOENT;
+ }
+ secy = &ns->macsec.nsim_secy[idx];
+
+ netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
+ __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
+
+ return 0;
+}
+
+static const struct macsec_ops nsim_macsec_ops = {
+ .mdo_add_secy = nsim_macsec_add_secy,
+ .mdo_upd_secy = nsim_macsec_upd_secy,
+ .mdo_del_secy = nsim_macsec_del_secy,
+ .mdo_add_rxsc = nsim_macsec_add_rxsc,
+ .mdo_upd_rxsc = nsim_macsec_upd_rxsc,
+ .mdo_del_rxsc = nsim_macsec_del_rxsc,
+ .mdo_add_rxsa = nsim_macsec_add_rxsa,
+ .mdo_upd_rxsa = nsim_macsec_upd_rxsa,
+ .mdo_del_rxsa = nsim_macsec_del_rxsa,
+ .mdo_add_txsa = nsim_macsec_add_txsa,
+ .mdo_upd_txsa = nsim_macsec_upd_txsa,
+ .mdo_del_txsa = nsim_macsec_del_txsa,
+};
+
+void nsim_macsec_init(struct netdevsim *ns)
+{
+ ns->netdev->macsec_ops = &nsim_macsec_ops;
+ ns->netdev->features |= NETIF_F_HW_MACSEC;
+ memset(&ns->macsec, 0, sizeof(ns->macsec));
+}
+
+void nsim_macsec_teardown(struct netdevsim *ns)
+{
+}
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 35fa1ca98671..0c8daeb0d62b 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -304,6 +304,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
if (err)
goto err_utn_destroy;
+ nsim_macsec_init(ns);
nsim_ipsec_init(ns);
err = register_netdevice(ns->netdev);
@@ -314,6 +315,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
err_ipsec_teardown:
nsim_ipsec_teardown(ns);
+ nsim_macsec_teardown(ns);
nsim_bpf_uninit(ns);
err_utn_destroy:
rtnl_unlock();
@@ -374,6 +376,7 @@ void nsim_destroy(struct netdevsim *ns)
rtnl_lock();
unregister_netdevice(dev);
if (nsim_dev_port_is_pf(ns->nsim_dev_port)) {
+ nsim_macsec_teardown(ns);
nsim_ipsec_teardown(ns);
nsim_bpf_uninit(ns);
}
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 7d8ed8d8df5c..7be98b7dcca9 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -23,6 +23,7 @@
#include <net/devlink.h>
#include <net/udp_tunnel.h>
#include <net/xdp.h>
+#include <net/macsec.h>
#define DRV_NAME "netdevsim"
@@ -52,6 +53,25 @@ struct nsim_ipsec {
u32 ok;
};
+#define NSIM_MACSEC_MAX_SECY_COUNT 3
+#define NSIM_MACSEC_MAX_RXSC_COUNT 1
+struct nsim_rxsc {
+ sci_t sci;
+ bool used;
+};
+
+struct nsim_secy {
+ sci_t sci;
+ struct nsim_rxsc nsim_rxsc[NSIM_MACSEC_MAX_RXSC_COUNT];
+ u8 nsim_rxsc_count;
+ bool used;
+};
+
+struct nsim_macsec {
+ struct nsim_secy nsim_secy[NSIM_MACSEC_MAX_SECY_COUNT];
+ u8 nsim_secy_count;
+};
+
struct nsim_ethtool_pauseparam {
bool rx;
bool tx;
@@ -93,6 +113,7 @@ struct netdevsim {
bool bpf_map_accept;
struct nsim_ipsec ipsec;
+ struct nsim_macsec macsec;
struct {
u32 inject_error;
u32 sleep;
@@ -366,6 +387,19 @@ static inline bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb)
}
#endif
+#if IS_ENABLED(CONFIG_MACSEC)
+void nsim_macsec_init(struct netdevsim *ns);
+void nsim_macsec_teardown(struct netdevsim *ns);
+#else
+static inline void nsim_macsec_init(struct netdevsim *ns)
+{
+}
+
+static inline void nsim_macsec_teardown(struct netdevsim *ns)
+{
+}
+#endif
+
struct nsim_bus_dev {
struct device dev;
struct list_head list;
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netdevsim: add dummy macsec offload
2023-06-11 15:45 [PATCH net-next] netdevsim: add dummy macsec offload Sabrina Dubroca
@ 2023-06-11 17:08 ` kernel test robot
2023-06-11 17:50 ` kernel test robot
2023-06-12 12:38 ` Simon Horman
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-06-11 17:08 UTC (permalink / raw)
To: Sabrina Dubroca, netdev; +Cc: oe-kbuild-all, Sabrina Dubroca, kuba
Hi Sabrina,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Sabrina-Dubroca/netdevsim-add-dummy-macsec-offload/20230611-234644
base: net-next/main
patch link: https://lore.kernel.org/r/0b87a0b7f9faf82de05c5689fbe8b8b4a83aa25d.1686494112.git.sd%40queasysnail.net
patch subject: [PATCH net-next] netdevsim: add dummy macsec offload
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20230612/202306120129.MSWI7cn1-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add net-next https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
git fetch net-next main
git checkout net-next/main
b4 shazam https://lore.kernel.org/r/0b87a0b7f9faf82de05c5689fbe8b8b4a83aa25d.1686494112.git.sd@queasysnail.net
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=s390 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306120129.MSWI7cn1-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_add_txsa':
>> drivers/net/netdevsim/macsec.c:274:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
274 | struct nsim_secy *secy;
| ^~~~
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_upd_txsa':
drivers/net/netdevsim/macsec.c:294:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
294 | struct nsim_secy *secy;
| ^~~~
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_del_txsa':
drivers/net/netdevsim/macsec.c:314:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
314 | struct nsim_secy *secy;
| ^~~~
vim +/secy +274 drivers/net/netdevsim/macsec.c
270
271 static int nsim_macsec_add_txsa(struct macsec_context *ctx)
272 {
273 struct netdevsim *ns = netdev_priv(ctx->netdev);
> 274 struct nsim_secy *secy;
275 int idx;
276
277 idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
278 if (idx < 0) {
279 netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
280 __func__, be64_to_cpu(ctx->secy->sci));
281 return -ENOENT;
282 }
283 secy = &ns->macsec.nsim_secy[idx];
284
285 netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
286 __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
287
288 return 0;
289 }
290
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netdevsim: add dummy macsec offload
2023-06-11 15:45 [PATCH net-next] netdevsim: add dummy macsec offload Sabrina Dubroca
2023-06-11 17:08 ` kernel test robot
@ 2023-06-11 17:50 ` kernel test robot
2023-06-12 12:38 ` Simon Horman
2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-06-11 17:50 UTC (permalink / raw)
To: Sabrina Dubroca, netdev; +Cc: oe-kbuild-all, Sabrina Dubroca, kuba
Hi Sabrina,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Sabrina-Dubroca/netdevsim-add-dummy-macsec-offload/20230611-234644
base: net-next/main
patch link: https://lore.kernel.org/r/0b87a0b7f9faf82de05c5689fbe8b8b4a83aa25d.1686494112.git.sd%40queasysnail.net
patch subject: [PATCH net-next] netdevsim: add dummy macsec offload
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230612/202306120146.8tukbUAq-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build):
git remote add net-next https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
git fetch net-next main
git checkout net-next/main
b4 shazam https://lore.kernel.org/r/0b87a0b7f9faf82de05c5689fbe8b8b4a83aa25d.1686494112.git.sd@queasysnail.net
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/netdevsim/
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306120146.8tukbUAq-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_add_txsa':
>> drivers/net/netdevsim/macsec.c:274:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
274 | struct nsim_secy *secy;
| ^~~~
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_upd_txsa':
drivers/net/netdevsim/macsec.c:294:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
294 | struct nsim_secy *secy;
| ^~~~
drivers/net/netdevsim/macsec.c: In function 'nsim_macsec_del_txsa':
drivers/net/netdevsim/macsec.c:314:27: warning: variable 'secy' set but not used [-Wunused-but-set-variable]
314 | struct nsim_secy *secy;
| ^~~~
vim +/secy +274 drivers/net/netdevsim/macsec.c
270
271 static int nsim_macsec_add_txsa(struct macsec_context *ctx)
272 {
273 struct netdevsim *ns = netdev_priv(ctx->netdev);
> 274 struct nsim_secy *secy;
275 int idx;
276
277 idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
278 if (idx < 0) {
279 netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
280 __func__, be64_to_cpu(ctx->secy->sci));
281 return -ENOENT;
282 }
283 secy = &ns->macsec.nsim_secy[idx];
284
285 netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
286 __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
287
288 return 0;
289 }
290
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netdevsim: add dummy macsec offload
2023-06-11 15:45 [PATCH net-next] netdevsim: add dummy macsec offload Sabrina Dubroca
2023-06-11 17:08 ` kernel test robot
2023-06-11 17:50 ` kernel test robot
@ 2023-06-12 12:38 ` Simon Horman
2023-06-13 17:28 ` Sabrina Dubroca
2 siblings, 1 reply; 5+ messages in thread
From: Simon Horman @ 2023-06-12 12:38 UTC (permalink / raw)
To: Sabrina Dubroca; +Cc: netdev, kuba
On Sun, Jun 11, 2023 at 05:45:33PM +0200, Sabrina Dubroca wrote:
...
> diff --git a/drivers/net/netdevsim/macsec.c b/drivers/net/netdevsim/macsec.c
> new file mode 100644
> index 000000000000..355ba2f313df
> --- /dev/null
...
> +static int nsim_macsec_add_secy(struct macsec_context *ctx)
> +{
> + struct netdevsim *ns = netdev_priv(ctx->netdev);
> + int idx;
> +
> + if (ns->macsec.nsim_secy_count == NSIM_MACSEC_MAX_SECY_COUNT)
> + return -ENOSPC;
> +
> + for (idx = 0; idx < NSIM_MACSEC_MAX_SECY_COUNT; idx++) {
> + if (!ns->macsec.nsim_secy[idx].used)
> + break;
> + }
> +
> + if (idx == NSIM_MACSEC_MAX_SECY_COUNT)
> + netdev_err(ctx->netdev, "%s: nsim_secy_count not full but all SecYs used\n",
> + __func__);
Hi Sabrina,
It seems that if this condition is met, then ns->macsec.nsim_secy will
overflow below.
> +
> + netdev_dbg(ctx->netdev, "%s: adding new secy with sci %08llx at index %d\n",
> + __func__, be64_to_cpu(ctx->secy->sci), idx);
> + ns->macsec.nsim_secy[idx].used = true;
> + ns->macsec.nsim_secy[idx].nsim_rxsc_count = 0;
> + ns->macsec.nsim_secy[idx].sci = ctx->secy->sci;
> + ns->macsec.nsim_secy_count++;
> +
> + return 0;
> +}
...
> +static int nsim_macsec_add_txsa(struct macsec_context *ctx)
> +{
> + struct netdevsim *ns = netdev_priv(ctx->netdev);
> + struct nsim_secy *secy;
> + int idx;
> +
> + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> + if (idx < 0) {
> + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> + __func__, be64_to_cpu(ctx->secy->sci));
Sparse seems pretty unhappy about the type of the argement to be64_to_cpu()
here and elsewhere. I'm unsure what is the best option but one that
sprang to mind would be conversion helpers, that cast appropriately.
f.e. sci_to_cpu()
> + return -ENOENT;
> + }
> + secy = &ns->macsec.nsim_secy[idx];
As also reported by the kernel test robot, a W=1 build complains that secy
is set but unused here and in to other places below.
> +
> + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> +
> + return 0;
> +}
> +
> +static int nsim_macsec_upd_txsa(struct macsec_context *ctx)
> +{
> + struct netdevsim *ns = netdev_priv(ctx->netdev);
> + struct nsim_secy *secy;
> + int idx;
> +
> + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> + if (idx < 0) {
> + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> + __func__, be64_to_cpu(ctx->secy->sci));
> + return -ENOENT;
> + }
> + secy = &ns->macsec.nsim_secy[idx];
> +
> + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> +
> + return 0;
> +}
> +
> +static int nsim_macsec_del_txsa(struct macsec_context *ctx)
> +{
> + struct netdevsim *ns = netdev_priv(ctx->netdev);
> + struct nsim_secy *secy;
> + int idx;
> +
> + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> + if (idx < 0) {
> + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> + __func__, be64_to_cpu(ctx->secy->sci));
> + return -ENOENT;
> + }
> + secy = &ns->macsec.nsim_secy[idx];
> +
> + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> +
> + return 0;
> +}
...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] netdevsim: add dummy macsec offload
2023-06-12 12:38 ` Simon Horman
@ 2023-06-13 17:28 ` Sabrina Dubroca
0 siblings, 0 replies; 5+ messages in thread
From: Sabrina Dubroca @ 2023-06-13 17:28 UTC (permalink / raw)
To: Simon Horman; +Cc: netdev, kuba
2023-06-12, 14:38:28 +0200, Simon Horman wrote:
> On Sun, Jun 11, 2023 at 05:45:33PM +0200, Sabrina Dubroca wrote:
>
> ...
>
> > diff --git a/drivers/net/netdevsim/macsec.c b/drivers/net/netdevsim/macsec.c
> > new file mode 100644
> > index 000000000000..355ba2f313df
> > --- /dev/null
>
> ...
>
> > +static int nsim_macsec_add_secy(struct macsec_context *ctx)
> > +{
> > + struct netdevsim *ns = netdev_priv(ctx->netdev);
> > + int idx;
> > +
> > + if (ns->macsec.nsim_secy_count == NSIM_MACSEC_MAX_SECY_COUNT)
> > + return -ENOSPC;
> > +
> > + for (idx = 0; idx < NSIM_MACSEC_MAX_SECY_COUNT; idx++) {
> > + if (!ns->macsec.nsim_secy[idx].used)
> > + break;
> > + }
> > +
> > + if (idx == NSIM_MACSEC_MAX_SECY_COUNT)
> > + netdev_err(ctx->netdev, "%s: nsim_secy_count not full but all SecYs used\n",
> > + __func__);
>
> Hi Sabrina,
>
> It seems that if this condition is met, then ns->macsec.nsim_secy will
> overflow below.
Right, thanks. It should never happen but I'll change that to return
-ENOSPC as well.
> > +
> > + netdev_dbg(ctx->netdev, "%s: adding new secy with sci %08llx at index %d\n",
> > + __func__, be64_to_cpu(ctx->secy->sci), idx);
> > + ns->macsec.nsim_secy[idx].used = true;
> > + ns->macsec.nsim_secy[idx].nsim_rxsc_count = 0;
> > + ns->macsec.nsim_secy[idx].sci = ctx->secy->sci;
> > + ns->macsec.nsim_secy_count++;
> > +
> > + return 0;
> > +}
>
> ...
>
> > +static int nsim_macsec_add_txsa(struct macsec_context *ctx)
> > +{
> > + struct netdevsim *ns = netdev_priv(ctx->netdev);
> > + struct nsim_secy *secy;
> > + int idx;
> > +
> > + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> > + if (idx < 0) {
> > + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> > + __func__, be64_to_cpu(ctx->secy->sci));
>
> Sparse seems pretty unhappy about the type of the argement to be64_to_cpu()
> here and elsewhere. I'm unsure what is the best option but one that
> sprang to mind would be conversion helpers, that cast appropriately.
> f.e. sci_to_cpu()
Ok. Since we've never needed that conversion in drivers/net/macsec.c,
I'll drop the helper in here, unless someone objects to that.
> > + return -ENOENT;
> > + }
> > + secy = &ns->macsec.nsim_secy[idx];
>
> As also reported by the kernel test robot, a W=1 build complains that secy
> is set but unused here and in to other places below.
Yes [facepalm]
Thanks for the review.
> > +
> > + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> > + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> > +
> > + return 0;
> > +}
> > +
> > +static int nsim_macsec_upd_txsa(struct macsec_context *ctx)
> > +{
> > + struct netdevsim *ns = netdev_priv(ctx->netdev);
> > + struct nsim_secy *secy;
> > + int idx;
> > +
> > + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> > + if (idx < 0) {
> > + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> > + __func__, be64_to_cpu(ctx->secy->sci));
> > + return -ENOENT;
> > + }
> > + secy = &ns->macsec.nsim_secy[idx];
> > +
> > + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> > + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> > +
> > + return 0;
> > +}
> > +
> > +static int nsim_macsec_del_txsa(struct macsec_context *ctx)
> > +{
> > + struct netdevsim *ns = netdev_priv(ctx->netdev);
> > + struct nsim_secy *secy;
> > + int idx;
> > +
> > + idx = nsim_macsec_find_secy(ns, ctx->secy->sci);
> > + if (idx < 0) {
> > + netdev_err(ctx->netdev, "%s: sci %08llx not found in secy table\n",
> > + __func__, be64_to_cpu(ctx->secy->sci));
> > + return -ENOENT;
> > + }
> > + secy = &ns->macsec.nsim_secy[idx];
> > +
> > + netdev_dbg(ctx->netdev, "%s: SECY with sci %08llx, AN %u\n",
> > + __func__, be64_to_cpu(ctx->secy->sci), ctx->sa.assoc_num);
> > +
> > + return 0;
> > +}
>
> ...
--
Sabrina
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-13 17:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-11 15:45 [PATCH net-next] netdevsim: add dummy macsec offload Sabrina Dubroca
2023-06-11 17:08 ` kernel test robot
2023-06-11 17:50 ` kernel test robot
2023-06-12 12:38 ` Simon Horman
2023-06-13 17:28 ` Sabrina Dubroca
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).