Skip to contentSkip to conversation

ynl Makefile cleanup

PATCH Applied Jakub Kicinski 4 participants 12 messages Oct 3, 2023 – Oct 16, 2023

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover ynl Makefile cleanup

While catching up on recent changes I noticed unexpected changes to Makefiles in YNL. Indeed they were not working as intended but the fixes put in place were not what I had in mind :)

Jakub Kicinski (3):
ynl: netdev: drop unnecessary enum-as-flags
tools: ynl: don't regen on every make
tools: ynl: use uAPI include magic for samples

 Documentation/netlink/specs/netdev.yaml | 2 --
 tools/net/ynl/Makefile                  | 1 -
 tools/net/ynl/generated/Makefile        | 2 +-
 tools/net/ynl/samples/Makefile          | 5 ++++-
 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 1/3 ynl: netdev: drop unnecessary enum-as-flags

enum-as-flags can be used when enum declares bit positions but we want to carry bitmask in an attribute. If the definition is already provided as flags there's no need to indicate the flag-iness of the attribute.

---
 Documentation/netlink/specs/netdev.yaml | 2 --
 1 file changed, 2 deletions(-)
Documentation/netlink/specs/netdev.yaml +0 -2
index c46fcc78fc04..14511b13f305 100644
@@ -74,7 +74,6 @@ name: netdev
         doc: Bitmask of enabled xdp-features.
         type: u64
         enum: xdp-act
-        enum-as-flags: true
       -
         name: xdp-zc-max-segs
         doc: max fragment count supported by ZC driver
@@ -87,7 +86,6 @@ name: netdev
              See Documentation/networking/xdp-rx-metadata.rst for more details.
         type: u64
         enum: xdp-rx-metadata
-        enum-as-flags: true
 
 operations:
   list:
Signature · 1 line
2.41.0
author maintainer
#8 lore raw

PATCH 2/3 tools: ynl: don't regen on every make

In reply to Jakub Kicinski

As far as I can tell the normal Makefile dependency tracking works, generated files get re-generated if the YAML was updated. Let make do its job, don't force the re-generation. make hardclean can be used to force regeneration.

---
 tools/net/ynl/Makefile           | 1 -
 tools/net/ynl/generated/Makefile | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
tools/net/ynl/Makefile +0 -1
index 8156f03e23ac..d664b36deb5b 100644
@@ -3,7 +3,6 @@
 SUBDIRS = lib generated samples
 
 all: $(SUBDIRS)
-	./ynl-regen.sh -f -p $(PWD)/../../../
 
 $(SUBDIRS):
 	@if [ -f "$@/Makefile" ] ; then \
tools/net/ynl/generated/Makefile +1 -1
index f8817d2e56e4..0f359ee3c46a 100644
@@ -19,7 +19,7 @@ SRCS=$(patsubst %,%-user.c,${GENS})
 HDRS=$(patsubst %,%-user.h,${GENS})
 OBJS=$(patsubst %,%-user.o,${GENS})
 
-all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) regen
+all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI)
 
 protos.a: $(OBJS)
 	@echo -e "\tAR $@"
Signature · 1 line
2.41.0
author maintainer
#9 lore raw

PATCH 3/3 tools: ynl: use uAPI include magic for samples

In reply to Jakub Kicinski

Makefile.deps provides direct includes in CFLAGS_$(obj). We just need to rewrite the rules to make use of the extra flags, no need to hard-include all of tools/include/uapi.

---
 tools/net/ynl/samples/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/net/ynl/samples/Makefile +4 -1
index 32abbc0af39e..3dbb106e87d9 100644
@@ -4,7 +4,7 @@ include ../Makefile.deps
 
 CC=gcc
 CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
-	-I../../../include/uapi -I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
+	-I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
 ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
 endif
@@ -19,6 +19,9 @@ include $(wildcard *.d)
 all: $(BINS)
 
 $(BINS): ../lib/ynl.a ../generated/protos.a
+	@echo -e '\tCC sample $@'
+	@$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected]
+	@$(LINK.c) [email protected] -o $@  $(LDLIBS)
 
 clean:
 	rm -f *.o *.d *~
Signature · 1 line
2.41.0
Acked-by on the v1 series
#10 lore raw
In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski

While catching up on recent changes I noticed unexpected changes to Makefiles in YNL. Indeed they were not working as intended but the fixes put in place were not what I had in mind :)

Whoops :-[ Thank you for the cleanup!

Quoted 14 lines

Jakub Kicinski (3):
ynl: netdev: drop unnecessary enum-as-flags
tools: ynl: don't regen on every make
tools: ynl: use uAPI include magic for samples

 Documentation/netlink/specs/netdev.yaml | 2 --
 tools/net/ynl/Makefile                  | 1 -
 tools/net/ynl/generated/Makefile        | 2 +-
 tools/net/ynl/samples/Makefile          | 5 ++++-
 4 files changed, 5 insertions(+), 5 deletions(-)

--
2.41.0

#11 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Tue, 3 Oct 2023 08:34:13 -0700 you wrote:

While catching up on recent changes I noticed unexpected changes to Makefiles in YNL. Indeed they were not working as intended but the fixes put in place were not what I had in mind :)

Jakub Kicinski (3):
ynl: netdev: drop unnecessary enum-as-flags
tools: ynl: don't regen on every make
tools: ynl: use uAPI include magic for samples

[...]

Here is the summary with links:
- [net-next,1/3] ynl: netdev: drop unnecessary enum-as-flags

    https://git.kernel.org/netdev/net-next/c/0629f22ec130
  - [net-next,2/3] tools: ynl: don't regen on every make
    https://git.kernel.org/netdev/net-next/c/a50660173c73
  - [net-next,3/3] tools: ynl: use uAPI include magic for samples
    https://git.kernel.org/netdev/net-next/c/e2ca31cee909

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#2 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

In reply to Jakub Kicinski
Quoted 4 lines · Jakub Kicinski

enum-as-flags can be used when enum declares bit positions but we want to carry bitmask in an attribute. If the definition is already provided as flags there's no need to indicate the flag-iness of the attribute.

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

I do see we have special handing for enum-as-flags to parse out the individual fields:
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:

Quoted 28 lines
---
 Documentation/netlink/specs/netdev.yaml | 2 --
 1 file changed, 2 deletions(-)
Documentation/netlink/specs/netdev.yaml +0 -2
index c46fcc78fc04..14511b13f305 100644
@@ -74,7 +74,6 @@ name: netdev
         doc: Bitmask of enabled xdp-features.
         type: u64
         enum: xdp-act
-        enum-as-flags: true
       -
         name: xdp-zc-max-segs
         doc: max fragment count supported by ZC driver
@@ -87,7 +86,6 @@ name: netdev
              See Documentation/networking/xdp-rx-metadata.rst for more details.
         type: u64
         enum: xdp-rx-metadata
-        enum-as-flags: true
 
 operations:
   list:
Signature · 1 line
2.41.0
#3 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

Quoted 20 lines · Stanislav Fomichev
Quoted 4 lines · Jakub Kicinski

enum-as-flags can be used when enum declares bit positions but we want to carry bitmask in an attribute. If the definition is already provided as flags there's no need to indicate the flag-iness of the attribute.

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 10 lines

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

Indeed. The field is now interpreted as a value rather than a bitmap.

More subtly, even for requests that do not fail, all my devices now incorrectly report to support xdp feature timestamp, because that is enum 0.

author maintainer
#4 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

Quoted 24 lines · On Mon, 16 Oct 2023 13:43:07 -0400 Willem de Bruijn wrote:
Quoted 13 lines

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 10 lines

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

Quoted 5 lines

Indeed. The field is now interpreted as a value rather than a bitmap.

More subtly, even for requests that do not fail, all my devices now incorrectly report to support xdp feature timestamp, because that is enum 0.

Sorry about that. This should fix it, right?

tools/net/ynl/lib/ynl.py +1 -1
index 13c4b019a881..28ac35008e65 100644
@@ -474,7 +474,7 @@ genl_family_name_to_id = None
 
     def _decode_enum(self, raw, attr_spec):
         enum = self.consts[attr_spec['enum']]
-        if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
             i = 0
             value = set()
             while raw:
#5 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

Quoted 39 lines · Jakub Kicinski
Quoted 24 lines · On Mon, 16 Oct 2023 13:43:07 -0400 Willem de Bruijn wrote:
Quoted 13 lines

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 10 lines

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

Quoted 5 lines

Indeed. The field is now interpreted as a value rather than a bitmap.

More subtly, even for requests that do not fail, all my devices now incorrectly report to support xdp feature timestamp, because that is enum 0.

Sorry about that. This should fix it, right?

tools/net/ynl/lib/ynl.py +0 -0
index 13c4b019a881..28ac35008e65 100644

tools/net/ynl/lib/ynl.py genl_family_name_to_id = None · line 480

Quoted 8 lines
tools/net/ynl/lib/ynl.py +1 -1
@@ -474,7 +474,7 @@ genl_family_name_to_id = None
 
     def _decode_enum(self, raw, attr_spec):
         enum = self.consts[attr_spec['enum']]
-        if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
             i = 0
             value = set()
             while raw:

Mostly. The "set()" output is unintentional?

# ./cli.py --spec netdev.yaml --dump dev-get
[{'ifindex': 1, 'xdp-features': set(), 'xdp-rx-metadata-features': set()},
 {'ifindex': 2,
  'xdp-features': {'redirect', 'basic', 'rx-sg'},
  'xdp-rx-metadata-features': set()},
 {'ifindex': 3, 'xdp-features': set(), 'xdp-rx-metadata-features': set()}]

Contrast with netdev sample:

# ./netdev
Select ifc ($ifindex; or 0 = dump; or -2 ntf check): 0
      lo[1]     xdp-features (0): xdp-rx-metadata-features (0):
xdp-zc-max-segs=0
    eth0[2]     xdp-features (23): basic redirect rx-sg
xdp-rx-metadata-features (0): xdp-zc-max-segs=0
    sit0[3]     xdp-features (0): xdp-rx-metadata-features (0):
xdp-zc-max-segs=0
#7 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

In reply to Jakub Kicinski
Quoted 26 lines · Jakub Kicinski
Quoted 24 lines · On Mon, 16 Oct 2023 13:43:07 -0400 Willem de Bruijn wrote:
Quoted 23 lines

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

Quoted 7 lines
Quoted 5 lines

Indeed. The field is now interpreted as a value rather than a bitmap.

More subtly, even for requests that do not fail, all my devices now incorrectly report to support xdp feature timestamp, because that is enum 0.

Sorry about that. This should fix it, right?

Yup, that fixes it for me, thanks!

Quoted 13 lines
tools/net/ynl/lib/ynl.py +1 -1
index 13c4b019a881..28ac35008e65 100644
@@ -474,7 +474,7 @@ genl_family_name_to_id = None
 
     def _decode_enum(self, raw, attr_spec):
         enum = self.consts[attr_spec['enum']]
-        if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
             i = 0
             value = set()
             while raw:
#6 lore raw

Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags

In reply to Willem de Bruijn
Quoted 42 lines · Willem de Bruijn
Quoted 40 lines · Jakub Kicinski
Quoted 24 lines · On Mon, 16 Oct 2023 13:43:07 -0400 Willem de Bruijn wrote:
Quoted 13 lines

Jakub, Willem hit an issue with this commit when running cli.py:

./cli.py --spec $KDIR/Documentation/netlink/specs/netdev.yaml --dump dev-get --json='{"ifindex": 12}'

Traceback (most recent call last):
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 60, in <module>

    main()
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/./cli.py", line 51, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 729, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 10 lines

File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 714, in _op
rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 540, in _decode
decoded = self._decode_enum(decoded, attr_spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/sdf/net-next/tools/net/ynl/lib/ynl.py", line 486, in _decode_enum
value = enum.entries_by_val[raw].name
~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 127

Quoted 5 lines

Indeed. The field is now interpreted as a value rather than a bitmap.

More subtly, even for requests that do not fail, all my devices now incorrectly report to support xdp feature timestamp, because that is enum 0.

Sorry about that. This should fix it, right?

tools/net/ynl/lib/ynl.py +0 -0
index 13c4b019a881..28ac35008e65 100644
@@ -474,7 +474,7 @@ genl_family_name_to_id = None
 
Quoted 9 lines

tools/net/ynl/lib/ynl.py genl_family_name_to_id = None · line 480

Quoted 7 lines
tools/net/ynl/lib/ynl.py +1 -1
     def _decode_enum(self, raw, attr_spec):
         enum = self.consts[attr_spec['enum']]
-        if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
             i = 0
             value = set()
             while raw:

Mostly. The "set()" output is unintentional?

Never mind. That is the same at 0629f22ec130~1

Thanks for the quick fix!