netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor
@ 2025-11-15  2:51 Parav Pandit
  2025-11-18  3:41 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Parav Pandit @ 2025-11-15  2:51 UTC (permalink / raw)
  To: netdev; +Cc: davem, edumazet, kuba, pabeni, horms, Parav Pandit, Jiri Pirko

When eswitch mode changes, notify such change to the devlink monitoring
process.

After this notification, a devlink monitoring process can see following
output:

$ devlink mon
[eswitch,set] pci/0000:06:00.0: mode switchdev inline-mode none encap-mode basic
[eswitch,set] pci/0000:06:00.0: mode legacy inline-mode none encap-mode basic

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Parav Pandit <parav@nvidia.com>
---
 net/devlink/dev.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index 02602704bdea..012211455f97 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -701,6 +701,30 @@ int devlink_nl_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info)
 	return genlmsg_reply(msg, info);
 }
 
+static void devlink_eswitch_notify(struct devlink *devlink)
+{
+	struct sk_buff *msg;
+	int err;
+
+	WARN_ON(!devl_is_registered(devlink));
+
+	if (!devlink_nl_notify_need(devlink))
+		return;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return;
+
+	err = devlink_nl_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_SET,
+				      0, 0, 0);
+	if (err) {
+		nlmsg_free(msg);
+		return;
+	}
+
+	devlink_nl_notify_send(devlink, msg);
+}
+
 int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct devlink *devlink = info->user_ptr[0];
@@ -742,6 +766,7 @@ int devlink_nl_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info)
 			return err;
 	}
 
+	devlink_eswitch_notify(devlink);
 	return 0;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor
  2025-11-15  2:51 [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor Parav Pandit
@ 2025-11-18  3:41 ` Jakub Kicinski
  2025-11-18  5:25   ` Parav Pandit
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-11-18  3:41 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, davem, edumazet, pabeni, horms, Jiri Pirko

On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
> +	err = devlink_nl_eswitch_fill(msg, devlink, DEVLINK_CMD_ESWITCH_SET,

I've never seen action command ID being used for a notification.
Either use an existing type which has the same message format,
or if no message which naturally fits exists allocate a new ID.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor
  2025-11-18  3:41 ` Jakub Kicinski
@ 2025-11-18  5:25   ` Parav Pandit
  2025-11-18 20:15     ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Parav Pandit @ 2025-11-18  5:25 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, horms@kernel.org, Jiri Pirko



> From: Jakub Kicinski <kuba@kernel.org>
> Sent: 18 November 2025 09:11 AM
> 
> On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
> > +	err = devlink_nl_eswitch_fill(msg, devlink,
> DEVLINK_CMD_ESWITCH_SET,
> 
> I've never seen action command ID being used for a notification.
> Either use an existing type which has the same message format, or if no
> message which naturally fits exists allocate a new ID.

I am not sure fully.
1. devlink_notify() uses DEVLINK_CMD_NEW.

2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input cmd on port creation supplied by the user space.

3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.

Do you mean #1 and #3 are not user-initiated commands, hence such an action command ID is ok vs #2 is not ok?
I probably misunderstanding your comment.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor
  2025-11-18  5:25   ` Parav Pandit
@ 2025-11-18 20:15     ` Jakub Kicinski
  2025-11-19 13:49       ` Parav Pandit
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-11-18 20:15 UTC (permalink / raw)
  To: Parav Pandit
  Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, horms@kernel.org, Jiri Pirko

On Tue, 18 Nov 2025 05:25:23 +0000 Parav Pandit wrote:
> > From: Jakub Kicinski <kuba@kernel.org>
> > Sent: 18 November 2025 09:11 AM
> > 
> > On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:  
> > > +	err = devlink_nl_eswitch_fill(msg, devlink,  
> > DEVLINK_CMD_ESWITCH_SET,
> > 
> > I've never seen action command ID being used for a notification.
> > Either use an existing type which has the same message format, or if no
> > message which naturally fits exists allocate a new ID.  
> 
> I am not sure fully.
> 1. devlink_notify() uses DEVLINK_CMD_NEW.
> 
> 2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input
> cmd on port creation supplied by the user space.
> 
> 3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.
> 
> Do you mean #1 and #3 are not user-initiated commands, hence such an
> action command ID is ok vs #2 is not ok? I probably misunderstanding
> your comment.

Let me put it more simply at some cost to accuracy..
The notification types and command ids usually match the response
to a GET command. Please TAL at the messages which are generated 
in response to a GET for the objects you listed...

Netlink command IDs are not required to match in a request-response
pair. In "modern" families we recommend that they do match, not because
the old model was wrong, but because a casual contributors usually got
it wrong.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor
  2025-11-18 20:15     ` Jakub Kicinski
@ 2025-11-19 13:49       ` Parav Pandit
  0 siblings, 0 replies; 5+ messages in thread
From: Parav Pandit @ 2025-11-19 13:49 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, horms@kernel.org, Jiri Pirko


> From: Jakub Kicinski <kuba@kernel.org>
> Sent: 19 November 2025 01:46 AM
> 
> On Tue, 18 Nov 2025 05:25:23 +0000 Parav Pandit wrote:
> > > From: Jakub Kicinski <kuba@kernel.org>
> > > Sent: 18 November 2025 09:11 AM
> > >
> > > On Sat, 15 Nov 2025 04:51:25 +0200 Parav Pandit wrote:
> > > > +	err = devlink_nl_eswitch_fill(msg, devlink,
> > > DEVLINK_CMD_ESWITCH_SET,
> > >
> > > I've never seen action command ID being used for a notification.
> > > Either use an existing type which has the same message format, or if
> > > no message which naturally fits exists allocate a new ID.
> >
> > I am not sure fully.
> > 1. devlink_notify() uses DEVLINK_CMD_NEW.
> >
> > 2. devlink_port_notify() uses DEVLINK_CMD_PORT_NEW which is the input
> > cmd on port creation supplied by the user space.
> >
> > 3. devlink_params_notify_register() uses DEVLINK_CMD_PARAM_NEW.
> >
> > Do you mean #1 and #3 are not user-initiated commands, hence such an
> > action command ID is ok vs #2 is not ok? I probably misunderstanding
> > your comment.
> 
> Let me put it more simply at some cost to accuracy..
> The notification types and command ids usually match the response to a GET
> command. Please TAL at the messages which are generated in response to a
> GET for the objects you listed...
> 
Got it.
Will change to reuse the id same as GET method.
In the eswitch case it is DEVLINK_CMD_ESWITCH_GET.
It fits the existing get command.
Ideally a change opcode like DPLL_CMD_DEVICE_CHANGE_X would be good too.
But ESWITCH_GET seems good enough as we don't have ESWITCH_NEW/ESWITCH_DEL.

> Netlink command IDs are not required to match in a request-response pair. In
> "modern" families we recommend that they do match, not because the old
> model was wrong, but because a casual contributors usually got it wrong.

Sending v1.

Thank you for the good explanation.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-19 13:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-15  2:51 [PATCH net-next] devlink: Notify eswitch mode changes to devlink monitor Parav Pandit
2025-11-18  3:41 ` Jakub Kicinski
2025-11-18  5:25   ` Parav Pandit
2025-11-18 20:15     ` Jakub Kicinski
2025-11-19 13:49       ` Parav Pandit

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).