ynl Makefile cleanup
Subsystems (3)
Jakub Kicinski
maintainercover 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
Jakub Kicinski
maintainerPATCH 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
@@ -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
Re: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags
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
Signed-off-by Jakub Kicinski <[email protected]>--- Documentation/netlink/specs/netdev.yaml | 2 -- 1 file changed, 2 deletions(-)Documentation/netlink/specs/netdev.yaml +0
-2@@ -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
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.
Jakub Kicinski
maintainerRe: [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
@@ -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:
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: 127Quoted 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
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=0Willem de Bruijn
Tested-byRe: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags
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: 127Quoted 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@@ -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
-1def _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!
Stanislav Fomichev
Tested-byRe: [PATCH net-next 1/3] ynl: netdev: drop unnecessary enum-as-flags
In reply to Jakub KicinskiQuoted 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@@ -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:
Jakub Kicinski
maintainerPATCH 2/3 tools: ynl: don't regen on every make
In reply to Jakub KicinskiAs 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
@@ -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
@@ -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
Jakub Kicinski
maintainerPATCH 3/3 tools: ynl: use uAPI include magic for samples
In reply to Jakub KicinskiMakefile.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
@@ -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
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 samplesDocumentation/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
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