From: Simon Horman <horms@kernel.org>
To: weibunny.kernel@gmail.com
Cc: Simon Horman <horms@kernel.org>,
edumazet@google.com, willemdebruijn.kernel@gmail.com,
netdev@vger.kernel.org, weibunny@fb.com, daniel.zahka@gmail.com,
bobbyeshleman@meta.com, kuba@kernel.org, davem@davemloft.net,
dw@davidwei.uk, andrew+netdev@lunn.ch
Subject: Re: [PATCH v7 net-next 1/5] psp: add admin/non-admin version of psp_device_get_locked
Date: Mon, 23 Mar 2026 18:23:38 +0000 [thread overview]
Message-ID: <20260323182339.177058-1-horms@kernel.org> (raw)
In-Reply-To: <20260322040704.991766-2-weibunny.kernel@gmail.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
psp: add admin/non-admin version of psp_device_get_locked
This commit introduces two versions of psp_device_get_locked to distinguish
between admin operations (dev-set, key-rotation) and non-admin operations
(dev-get, rx-assoc, tx-assoc, get-stats).
> diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
> index f3a57782d2cf..fe2cdc966604 100644
> --- a/Documentation/netlink/specs/psp.yaml
> +++ b/Documentation/netlink/specs/psp.yaml
[ ... ]
> diff --git a/net/psp/psp-nl-gen.h b/net/psp/psp-nl-gen.h
> index 599c5f1c82f2..977355455395 100644
> --- a/net/psp/psp-nl-gen.h
> +++ b/net/psp/psp-nl-gen.h
[ ... ]
> diff --git a/net/psp/psp.h b/net/psp/psp.h
> index 9f19137593a0..0f9c4e4e52cb 100644
> --- a/net/psp/psp.h
> +++ b/net/psp/psp.h
[ ... ]
> diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
> index 9508b6c38003..82de78a1d6bd 100644
> --- a/net/psp/psp_main.c
> +++ b/net/psp/psp_main.c
[ ... ]
> diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c
> index 6afd7707ec12..b988f35412df 100644
> --- a/net/psp/psp_nl.c
> +++ b/net/psp/psp_nl.c
> @@ -41,7 +41,8 @@ static int psp_nl_reply_send(struct sk_buff *rsp, struct genl_info *info)
> /* Device stuff */
>
> static struct psp_dev *
> -psp_device_get_and_lock(struct net *net, struct nlattr *dev_id)
> +psp_device_get_and_lock(struct net *net, struct nlattr *dev_id,
> + bool admin)
> {
> struct psp_dev *psd;
> int err;
> @@ -56,7 +57,7 @@ psp_device_get_and_lock(struct net *net, struct nlattr *dev_id)
> mutex_lock(&psd->lock);
> mutex_unlock(&psp_devs_lock);
>
> - err = psp_dev_check_access(psd, net);
> + err = psp_dev_check_access(psd, net, admin);
> if (err) {
> mutex_unlock(&psd->lock);
> return ERR_PTR(err);
> @@ -65,6 +66,18 @@ psp_device_get_and_lock(struct net *net, struct nlattr *dev_id)
> return psd;
> }
>
> +int psp_device_get_locked_admin(const struct genl_split_ops *ops,
> + struct sk_buff *skb, struct genl_info *info)
> +{
> + if (GENL_REQ_ATTR_CHECK(info, PSP_A_DEV_ID))
> + return -EINVAL;
> +
> + info->user_ptr[0] = psp_device_get_and_lock(genl_info_net(info),
> + info->attrs[PSP_A_DEV_ID],
> + true);
> + return PTR_ERR_OR_ZERO(info->user_ptr[0]);
> +}
> +
> int psp_device_get_locked(const struct genl_split_ops *ops,
> struct sk_buff *skb, struct genl_info *info)
> {
> @@ -72,7 +85,8 @@ int psp_device_get_locked(const struct genl_split_ops *ops,
> return -EINVAL;
>
> info->user_ptr[0] = psp_device_get_and_lock(genl_info_net(info),
> - info->attrs[PSP_A_DEV_ID]);
> + info->attrs[PSP_A_DEV_ID],
> + false);
> return PTR_ERR_OR_ZERO(info->user_ptr[0]);
> }
This isn't a bug, but psp_device_get_locked_admin() and
psp_device_get_locked() are identical except for the true/false parameter
passed to psp_device_get_and_lock(). Would it be cleaner to introduce
a common helper like __psp_device_get_locked(bool admin) to avoid the
duplication?
Reference: https://lore.kernel.org/netdev/6fde8fe3-1ac9-4a47-89f5-b6f759c2f103@gmail.com/
Daniel Zahka raised this refactoring suggestion in v2, noting the two
functions are entirely identical modulo the admin parameter.
> @@ -160,7 +174,7 @@ static int
> psp_nl_dev_get_dumpit_one(struct sk_buff *rsp, struct netlink_callback *cb,
> struct psp_dev *psd)
> {
> - if (psp_dev_check_access(psd, sock_net(rsp->sk)))
> + if (psp_dev_check_access(psd, sock_net(rsp->sk), false))
> return 0;
>
> return psp_nl_dev_fill(psd, rsp, genl_info_dump(cb));
[ ... ]
next prev parent reply other threads:[~2026-03-23 18:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 4:06 [PATCH v7 net-next 0/5] psp: Add support for dev-assoc/disassoc Wei Wang
2026-03-22 4:06 ` [PATCH v7 net-next 1/5] psp: add admin/non-admin version of psp_device_get_locked Wei Wang
2026-03-23 18:23 ` Simon Horman [this message]
2026-03-26 5:21 ` Wei Wang
2026-03-22 4:06 ` [PATCH v7 net-next 2/5] psp: add new netlink cmd for dev-assoc and dev-disassoc Wei Wang
2026-03-23 18:23 ` Simon Horman
2026-03-26 5:21 ` Wei Wang
2026-03-22 4:06 ` [PATCH v7 net-next 3/5] psp: add a new netdev event for dev unregister Wei Wang
2026-03-23 18:24 ` Simon Horman
2026-03-26 5:21 ` Wei Wang
2026-03-22 4:06 ` [PATCH v7 net-next 4/5] selftests/net: Add bpf skb forwarding program Wei Wang
2026-03-22 4:06 ` [PATCH v7 net-next 5/5] selftest/net: psp: Add test for dev-assoc/disassoc Wei Wang
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=20260323182339.177058-1-horms@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bobbyeshleman@meta.com \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=weibunny.kernel@gmail.com \
--cc=weibunny@fb.com \
--cc=willemdebruijn.kernel@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox