From: Sabrina Dubroca <sd@queasysnail.net>
To: Simon Horman <simon.horman@corigine.com>
Cc: netdev@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net-next] netdevsim: add dummy macsec offload
Date: Tue, 13 Jun 2023 19:28:15 +0200 [thread overview]
Message-ID: <ZIinLxhts7GdknY1@hog> (raw)
In-Reply-To: <ZIcRxM/xvozZ+H9c@corigine.com>
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
prev parent reply other threads:[~2023-06-13 17:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZIinLxhts7GdknY1@hog \
--to=sd@queasysnail.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=simon.horman@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.