public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output
@ 2026-03-16 15:44 Jiri Pirko
  2026-03-16 15:44 ` [PATCH iproute2-next 1/3] update kernel headers Jiri Pirko
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jiri Pirko @ 2026-03-16 15:44 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

From: Jiri Pirko <jiri@nvidia.com>

Support for identifying devlink instances by a unique index was recently
added on the kernel side:
https://lore.kernel.org/all/20260312100407.551173-1-jiri@resnulli.us/

This patchset adds the necessary userspace support.

First, as a dependency, introduce a fallback for mnl_attr_get_uint()
to handle the NLA_UINT variable-width attribute type used by the
kernel for the index, with backward compatibility for older libmnl
versions.

Then, display the devlink instance index in dev show output when
the kernel provides it.

Jiri Pirko (3):
  update kernel headers
  mnl: add fallback implementation for mnl_attr_get_uint()
  devlink: show devlink instance index in dev output

 configure                    | 22 ++++++++++++++++++++++
 devlink/devlink.c            |  6 +++++-
 include/mnl_utils.h          |  4 ++++
 include/uapi/linux/devlink.h |  4 ++++
 lib/mnl_utils.c              | 17 +++++++++++++++++
 5 files changed, 52 insertions(+), 1 deletion(-)

-- 
2.51.1


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

* [PATCH iproute2-next 1/3] update kernel headers
  2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
@ 2026-03-16 15:44 ` Jiri Pirko
  2026-03-16 15:44 ` [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint() Jiri Pirko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Pirko @ 2026-03-16 15:44 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

From: Jiri Pirko <jiri@nvidia.com>

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 include/uapi/linux/devlink.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 3a8f8a3cc342..8040b9f58a8a 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -19,6 +19,8 @@
 #define DEVLINK_GENL_VERSION 0x1
 #define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
 
+#define DEVLINK_INDEX_BUS_NAME "devlink_index"
+
 enum devlink_command {
 	/* don't change the order or add anything between, this is ABI! */
 	DEVLINK_CMD_UNSPEC,
@@ -642,6 +644,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_PARAM_VALUE_DEFAULT,	/* dynamic */
 	DEVLINK_ATTR_PARAM_RESET_DEFAULT,	/* flag */
 
+	DEVLINK_ATTR_INDEX,			/* uint */
+
 	/* Add new attributes above here, update the spec in
 	 * Documentation/netlink/specs/devlink.yaml and re-generate
 	 * net/devlink/netlink_gen.c.
-- 
2.51.1


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

* [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
  2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
  2026-03-16 15:44 ` [PATCH iproute2-next 1/3] update kernel headers Jiri Pirko
@ 2026-03-16 15:44 ` Jiri Pirko
  2026-03-16 16:12   ` Stephen Hemminger
  2026-03-16 15:44 ` [PATCH iproute2-next 3/3] devlink: show devlink instance index in dev output Jiri Pirko
  2026-03-23  0:20 ` [PATCH iproute2-next 0/3] " patchwork-bot+netdevbpf
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Pirko @ 2026-03-16 15:44 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

From: Jiri Pirko <jiri@nvidia.com>

libmnl introduced mnl_attr_get_uint() to handle NLA_UINT
variable-width attributes. Add a configure check to detect it
and provide a fallback implementation for older libmnl versions.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 configure           | 22 ++++++++++++++++++++++
 include/mnl_utils.h |  4 ++++
 lib/mnl_utils.c     | 17 +++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/configure b/configure
index 7437db4f22a8..ebc0d97a6f26 100755
--- a/configure
+++ b/configure
@@ -366,6 +366,24 @@ check_tirpc()
 	fi
 }
 
+have_mnl_attr_get_uint()
+{
+    cat >$TMPDIR/mnl_attr_get_uint_test.c <<EOF
+#include <libmnl/libmnl.h>
+int main(int argc, char **argv)
+{
+	return !!mnl_attr_get_uint(NULL);
+}
+EOF
+
+    $CC -I$INCLUDE $(${PKG_CONFIG} libmnl --cflags --libs 2>/dev/null) \
+	    -o $TMPDIR/mnl_attr_get_uint_test $TMPDIR/mnl_attr_get_uint_test.c >/dev/null 2>&1
+    local ret=$?
+
+    rm -f $TMPDIR/mnl_attr_get_uint_test.c $TMPDIR/mnl_attr_get_uint_test
+    return $ret
+}
+
 check_mnl()
 {
 	if ${PKG_CONFIG} libmnl --exists; then
@@ -374,6 +392,10 @@ check_mnl()
 
 		echo 'CFLAGS += -DHAVE_LIBMNL' "$(${PKG_CONFIG} libmnl --cflags)" >>$CONFIG
 		echo 'LDLIBS +=' "$(${PKG_CONFIG} libmnl --libs)" >> $CONFIG
+
+		if have_mnl_attr_get_uint; then
+			echo "CFLAGS += -DHAVE_MNL_ATTR_GET_UINT" >>$CONFIG
+		fi
 	else
 		echo "no"
 	fi
diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index 0ddf2932db62..4df9e398e591 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -33,4 +33,8 @@ int mnlu_gen_socket_recv_run(struct mnlu_gen_socket *nlg, mnl_cb_t cb,
 			     void *data);
 int mnlu_gen_cmd_dump_policy(struct mnlu_gen_socket *nlg, uint8_t cmd);
 
+#ifndef HAVE_MNL_ATTR_GET_UINT
+uint64_t mnl_attr_get_uint(const struct nlattr *attr);
+#endif
+
 #endif /* __MNL_UTILS_H__ */
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index 5f6671bf94cc..43b4cd1a9e40 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -381,3 +381,20 @@ int mnlu_gen_cmd_dump_policy(struct mnlu_gen_socket *nlg, uint8_t cmd)
 
 	return 0;
 }
+
+#ifndef HAVE_MNL_ATTR_GET_UINT
+uint64_t mnl_attr_get_uint(const struct nlattr *attr)
+{
+	switch (mnl_attr_get_payload_len(attr)) {
+	case sizeof(uint8_t):
+		return mnl_attr_get_u8(attr);
+	case sizeof(uint16_t):
+		return mnl_attr_get_u16(attr);
+	case sizeof(uint32_t):
+		return mnl_attr_get_u32(attr);
+	case sizeof(uint64_t):
+		return mnl_attr_get_u64(attr);
+	}
+	return -1ULL;
+}
+#endif
-- 
2.51.1


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

* [PATCH iproute2-next 3/3] devlink: show devlink instance index in dev output
  2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
  2026-03-16 15:44 ` [PATCH iproute2-next 1/3] update kernel headers Jiri Pirko
  2026-03-16 15:44 ` [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint() Jiri Pirko
@ 2026-03-16 15:44 ` Jiri Pirko
  2026-03-23  0:20 ` [PATCH iproute2-next 0/3] " patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: Jiri Pirko @ 2026-03-16 15:44 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

From: Jiri Pirko <jiri@nvidia.com>

Print devlink instance index in dev show output when
the kernel provides it.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 devlink/devlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 39b0fac098c8..730515a78950 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -4095,8 +4095,12 @@ static void pr_out_dev(struct dl *dl, const struct nlmsghdr *nlh,
 {
 	if ((tb[DEVLINK_ATTR_RELOAD_FAILED] && mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED])) ||
 	    (tb[DEVLINK_ATTR_DEV_STATS] && dl->stats) ||
-	     tb[DEVLINK_ATTR_NESTED_DEVLINK]) {
+	     tb[DEVLINK_ATTR_NESTED_DEVLINK] ||
+	     tb[DEVLINK_ATTR_INDEX]) {
 		__pr_out_handle_start(dl, tb, true, false);
+		if (tb[DEVLINK_ATTR_INDEX])
+			print_uint(PRINT_ANY, "index", " index %u",
+				   mnl_attr_get_uint(tb[DEVLINK_ATTR_INDEX]));
 		pr_out_reload_data(dl, tb);
 		pr_out_dev_nested(dl, nlh);
 		pr_out_handle_end(dl);
-- 
2.51.1


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

* Re: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
  2026-03-16 15:44 ` [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint() Jiri Pirko
@ 2026-03-16 16:12   ` Stephen Hemminger
  2026-03-17  8:17     ` Jiri Pirko
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2026-03-16 16:12 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, dsahern

On Mon, 16 Mar 2026 16:44:17 +0100
Jiri Pirko <jiri@resnulli.us> wrote:

> From: Jiri Pirko <jiri@nvidia.com>
> 
> libmnl introduced mnl_attr_get_uint() to handle NLA_UINT
> variable-width attributes. Add a configure check to detect it
> and provide a fallback implementation for older libmnl versions.
> 
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>

How far back was this? If it was relatively recent would
prefer not adding another set of config tests.

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

* Re: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
  2026-03-16 16:12   ` Stephen Hemminger
@ 2026-03-17  8:17     ` Jiri Pirko
  2026-03-18  2:31       ` David Ahern
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Pirko @ 2026-03-17  8:17 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, dsahern

Mon, Mar 16, 2026 at 05:12:45PM +0100, stephen@networkplumber.org wrote:
>On Mon, 16 Mar 2026 16:44:17 +0100
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> From: Jiri Pirko <jiri@nvidia.com>
>> 
>> libmnl introduced mnl_attr_get_uint() to handle NLA_UINT
>> variable-width attributes. Add a configure check to detect it
>> and provide a fallback implementation for older libmnl versions.
>> 
>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>
>How far back was this? If it was relatively recent would
>prefer not adding another set of config tests.

https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d

I'm not sure what you suggest as alternative...

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

* Re: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
  2026-03-17  8:17     ` Jiri Pirko
@ 2026-03-18  2:31       ` David Ahern
  0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2026-03-18  2:31 UTC (permalink / raw)
  To: Jiri Pirko, Stephen Hemminger; +Cc: netdev

On 3/17/26 2:17 AM, Jiri Pirko wrote:
> Mon, Mar 16, 2026 at 05:12:45PM +0100, stephen@networkplumber.org wrote:
>> On Mon, 16 Mar 2026 16:44:17 +0100
>> Jiri Pirko <jiri@resnulli.us> wrote:
>>
>>> From: Jiri Pirko <jiri@nvidia.com>
>>>
>>> libmnl introduced mnl_attr_get_uint() to handle NLA_UINT
>>> variable-width attributes. Add a configure check to detect it
>>> and provide a fallback implementation for older libmnl versions.
>>>
>>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>>
>> How far back was this? If it was relatively recent would
>> prefer not adding another set of config tests.
> 
> https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d
> 
> I'm not sure what you suggest as alternative...

that is less than 1 stable release cycle. I think we should keep the
configure probe and fallback.

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

* Re: [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output
  2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
                   ` (2 preceding siblings ...)
  2026-03-16 15:44 ` [PATCH iproute2-next 3/3] devlink: show devlink instance index in dev output Jiri Pirko
@ 2026-03-23  0:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-23  0:20 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, stephen, dsahern

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Mon, 16 Mar 2026 16:44:15 +0100 you wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> Support for identifying devlink instances by a unique index was recently
> added on the kernel side:
> https://lore.kernel.org/all/20260312100407.551173-1-jiri@resnulli.us/
> 
> This patchset adds the necessary userspace support.
> 
> [...]

Here is the summary with links:
  - [iproute2-next,1/3] update kernel headers
    (no matching commit)
  - [iproute2-next,2/3] mnl: add fallback implementation for mnl_attr_get_uint()
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=bef61beb2edf
  - [iproute2-next,3/3] devlink: show devlink instance index in dev output
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=36252727bfc6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-03-23  0:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
2026-03-16 15:44 ` [PATCH iproute2-next 1/3] update kernel headers Jiri Pirko
2026-03-16 15:44 ` [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint() Jiri Pirko
2026-03-16 16:12   ` Stephen Hemminger
2026-03-17  8:17     ` Jiri Pirko
2026-03-18  2:31       ` David Ahern
2026-03-16 15:44 ` [PATCH iproute2-next 3/3] devlink: show devlink instance index in dev output Jiri Pirko
2026-03-23  0:20 ` [PATCH iproute2-next 0/3] " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox