Revert "kbuild: give the SUBLEVEL more room in KERNEL_VERSION"
Subsystems (6)
PATCH 1/3 Revert "kbuild: give the SUBLEVEL more room in KERNEL_VERSION"
This reverts commit 537896fabed11f8d9788886d1aacdb977213c7b3.
This turns out to be a bad idea: userspace has coded the structure of KERNEL_VERSION on it's own and assumes the 2-1-1 byte split, making it userspace ABI we can't break.
The reverted patch didn't make it past linux-next, so no userspace was hurt in the process.
--- Makefile | 7 ++----- drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 ++-- drivers/usb/core/hcd.c | 4 ++-- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 4 ++-- include/linux/usb/composite.h | 4 ++-- kernel/sys.c | 2 +- tools/perf/tests/bpf-script-example.c | 2 +- tools/perf/tests/bpf-script-test-kbuild.c | 2 +- tools/perf/tests/bpf-script-test-prologue.c | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-)
Makefile +2 -5
@@ -1259,11 +1259,8 @@ endef define filechk_version.h echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \ - echo \#define LINUX_VERSION_MAJOR $(VERSION); \ - echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ - echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 24) + ((b) << 16) + (c))' + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' endef $(version_h): FORCE
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -2
@@ -237,8 +237,8 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev) remaining_size =max_t (int,0 , driver_ver_sz -strlen (string));snprintf (string +strlen (string), remaining_size,"%u.%u.%u" , - (u8)(LINUX_VERSION_MAJOR ), (u8)(LINUX_VERSION_PATCHLEVEL ), - (u16)(LINUX_VERSION_SUBLEVEL )); + (u8)((LINUX_VERSION_CODE >>16 ) &0xff ), (u8)((LINUX_VERSION_CODE >>8 ) &0xff ), + (u16)(LINUX_VERSION_CODE &0xffff ));/*Send the command*/ MLX5_SET(set_driver_version_in, in, opcode,
drivers/usb/core/hcd.c +2 -2
@@ -111,8 +111,8 @@ DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);*/ /*-------------------------------------------------------------------------*/ -#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) -#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL) +#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) +#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))/* usb 3.1 root hub device descriptor */ static const u8 usb31_rh_dev_descriptor[18 ] = {
drivers/usb/gadget/udc/aspeed-vhub/hub.c +2 -2
@@ -46,8 +46,8 @@* - Make vid/did overridable * - make it look like usb1 if usb1 mode forced */ -#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) -#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL) +#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) +#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))enum {AST_VHUB_STR_INDEX_MAX =4 ,
include/linux/usb/composite.h +2 -2
@@ -575,8 +575,8 @@ static inline u16 get_default_bcdDevice(void) {u16 bcdDevice; - bcdDevice =bin2bcd (LINUX_VERSION_MAJOR ) <<8 ; - bcdDevice |=bin2bcd (LINUX_VERSION_PATCHLEVEL ); + bcdDevice =bin2bcd ((LINUX_VERSION_CODE >>16 &0xff )) <<8 ; + bcdDevice |=bin2bcd ((LINUX_VERSION_CODE >>8 &0xff ));return bcdDevice; }
kernel/sys.c +1 -1
@@ -1242,7 +1242,7 @@ static int override_release(char __user *release, size_t len)break ; rest++; } - v =LINUX_VERSION_PATCHLEVEL +60 ; + v = ((LINUX_VERSION_CODE >>8 ) &0xff ) +60 ; copy =clamp_t (size_t, len,1 ,sizeof (buf)); copy =scnprintf (buf, copy,"2.6.%u%s" , v, rest); ret =copy_to_user (release, buf, copy +1 );
tools/perf/tests/bpf-script-example.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define BPF_ANY 0#define BPF_MAP_TYPE_ARRAY 2
tools/perf/tests/bpf-script-test-kbuild.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))
tools/perf/tests/bpf-script-test-prologue.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))
Signature · 1 line
2.27.0
PATCH 2/3 kbuild: clamp SUBLEVEL to 255
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.
--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Makefile +9 -3
@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' + if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endef $(version_h): FORCE
Signature · 1 line
2.27.0
Re: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
Quoted 8 lines · Sasha Levin
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Quoted 5 lines
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>
Re: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
In reply to Sasha LevinQuoted 9 lines · Sasha Levin
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Quoted 5 lines
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>
I applied 2/3 to linux-kbuild.
Please resend only 3/3.
Thanks.
Quoted 30 lines
--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Makefile +9
-4@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' + if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endef $(version_h): FORCE --2.27.0
Signature · 2 lines
Best Regards Masahiro Yamada
RE: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
In reply to Sasha LevinFrom: Sasha Levin
Quoted 30 lines
Sent: 06 February 2021 03:51
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Makefile +0
-3@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
Makefile define filechk_utsrelease.h · line 1270
Quoted 10 lines
Makefile +9
-0+ if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endef
Why not use KERNEL_VERSION to define LINUX_VERSION_CODE ? Basically just:
echo '#define LINUX_VERSION_CODE KERNEL_VERSION($(VERSION), $(PATCHLEVEL)+0, $(SUBLEVEL)+0)'
If PATCHLEVEL and SUBLEVEL are guaranteed to be non-empty the +0 can be removed.
The patch assumes they are non-empty, the original pre-prended 0 to stop syntax error for empty version strings.
Note that the expr version will process 08 and 09. gcc will treat them as octal, and may error them.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
[email protected]
maintainerRe: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
Quoted 44 lines · David Laight
From: Sasha Levin
Quoted 30 lines
Sent: 06 February 2021 03:51
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Makefile +0
-3@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'Makefile define filechk_utsrelease.h · line 1270
Quoted 10 lines
Makefile +9
-0+ if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endefWhy not use
KERNEL_VERSIONto defineLINUX_VERSION_CODE? Basically just:
Quoted 1 line
echo '#define LINUX_VERSION_CODE KERNEL_VERSION($(VERSION), $(PATCHLEVEL)+0, $(SUBLEVEL)+0)'
Because we are "clamping" LINUX_VERSION_CODE() at a x.y.255, while KERNEL_VERSION() continues on with the "real" minor number.
thanks,
greg k-h
RE: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
From: [email protected]
Quoted 49 lines
Sent: 08 February 2021 14:09
Quoted 44 lines · David Laight
From: Sasha Levin
Quoted 30 lines
Sent: 06 February 2021 03:51
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Makefile +0
-3@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'Makefile define filechk_utsrelease.h · line 1270
Quoted 10 lines
Makefile +9
-0+ if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endefWhy not use
KERNEL_VERSIONto defineLINUX_VERSION_CODE? Basically just:Quoted 1 line
echo '#define LINUX_VERSION_CODE KERNEL_VERSION($(VERSION), $(PATCHLEVEL)+0, $(SUBLEVEL)+0)'
Quoted 2 lines
Because we are "clamping"
LINUX_VERSION_CODE()at a x.y.255, whileKERNEL_VERSION()continues on with the "real" minor number.
That particular patch (which I think Sasha applied) clamps both.
I know you (personally) don't care about OOT mudules, but a lot of people do.
They will contain comparisons of KERNEL_VERSION against LINUX_VERSION_CODE. They almost certainly don't care about the SUBLEVEL, but using different encodings will break things.
The only real saving grace is that OOT modules tend to get built against distro kernels which are likely to be 4.9.4-123456 so not hit whatever broken mapping you use for LTS kernels.
Another strange set of '#ifs' for new kernels is just part of the job. It keeps me in work.
For a comparison the same driver object will load into windows 7 (and maybe even vista) and the current windows 10 kernel. (But getting a windows driver signed is hard work.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Re: [PATCH 2/3] kbuild: clamp SUBLEVEL to 255
In reply to David LaightQuoted 45 lines · David Laight
From: Sasha Levin
Quoted 30 lines
Sent: 06 February 2021 03:51
Right now if SUBLEVEL becomes larger than 255 it will overflow into the territory of PATCHLEVEL, causing havoc in userspace that tests for specific kernel version.
While userspace code tests for MAJOR and PATCHLEVEL, it doesn't test SUBLEVEL at any point as ABI changes don't happen in the context of stable tree.
Thus, to avoid overflows, simply clamp SUBLEVEL to it's maximum value in the context of
LINUX_VERSION_CODE. This does not affect "make kernelversion" and such.Signed-off-by Sasha Levin <[email protected]>--- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)Makefile +0
-3@@ -1258,9 +1258,15 @@ define filechk_utsrelease.h endef define filechk_version.h - echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'Makefile define filechk_utsrelease.h · line 1270
Quoted 10 lines
Makefile +9
-0+ if [ $(SUBLEVEL) -gt 255 ]; then \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 255); \ + else \ + echo \#define LINUX_VERSION_CODE $(shell \ + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ + fi; \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ + ((c) > 255 ? 255 : (c)))' endefWhy not use
KERNEL_VERSIONto defineLINUX_VERSION_CODE? Basically just:
Quoted 1 line
echo '#define LINUX_VERSION_CODE KERNEL_VERSION($(VERSION), $(PATCHLEVEL)+0, $(SUBLEVEL)+0)'
It was not possible to macrofy LINUX_VERSION_CODE. (build error when CONFIG_KALLSYMS is disabled)
Presumably, this restriction will go away
with the following commit in linux-next.
commit e06af0b2ba02fc0cc2219a14c4c04ff0296a6f9f
Author: Masahiro Yamada <[email protected]> Date: Thu Jan 28 18:42:30 2021 +1100
init/version.c: remove Version_<LINUX_VERSION_CODE> symbol
My plan is to refactor LINUX_VERSION_CODE in the next development cycle.
Quoted 5 lines
If PATCHLEVEL and SUBLEVEL are guaranteed to be non-empty the +0 can be removed.
The patch assumes they are non-empty, the original pre-prended 0 to stop syntax error for empty version strings.
Quoted 9 lines
Note that the expr version will process 08 and 09. gcc will treat them as octal, and may error them.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
--
Best Regards
Masahiro Yamada
PATCH 3/3 kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
In reply to Sasha LevinSUBLEVEL only has 8 bits of space, which means that we'll overflow it once it reaches 256.
Few of the stable branches will imminently overflow SUBLEVEL while there's no risk of overflowing VERSION.
Thus, give SUBLEVEL 8 more bits which will be stolen from VERSION, this should create a better balance between the different version numbers we use.
We can't however use the original KERNEL_VERSION and LINUX_VERSION_CODE as userspace has created ABI dependency on their structure, and we risk breaking this userspace by modifying the layout of the version integers.
--- Makefile | 8 +++++++- drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 ++-- drivers/usb/core/hcd.c | 4 ++-- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 4 ++-- include/linux/usb/composite.h | 4 ++-- kernel/sys.c | 2 +- tools/perf/tests/bpf-script-example.c | 2 +- tools/perf/tests/bpf-script-test-kbuild.c | 2 +- tools/perf/tests/bpf-script-test-prologue.c | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-)
Makefile +7 -1
@@ -1266,7 +1266,13 @@ define filechk_version.h expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ fi; \ echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ - ((c) > 255 ? 255 : (c)))' + ((c) > 255 ? 255 : (c)))'; \ + echo \#define LINUX_VERSION_CODE2 $(shell \ + expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \ + echo \#define LINUX_VERSION_MAJOR $(VERSION); \ + echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ + echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL); \ + echo '#define KERNEL_VERSION2(a,b,c) (((a) << 24) + ((b) << 16) + (c))' endef $(version_h): FORCE
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -2
@@ -237,8 +237,8 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev) remaining_size =max_t (int,0 , driver_ver_sz -strlen (string));snprintf (string +strlen (string), remaining_size,"%u.%u.%u" , - (u8)((LINUX_VERSION_CODE >>16 ) &0xff ), (u8)((LINUX_VERSION_CODE >>8 ) &0xff ), - (u16)(LINUX_VERSION_CODE &0xffff )); + (u8)(LINUX_VERSION_MAJOR ), (u8)(LINUX_VERSION_PATCHLEVEL ), + (u16)(LINUX_VERSION_SUBLEVEL ));/*Send the command*/ MLX5_SET(set_driver_version_in, in, opcode,
drivers/usb/core/hcd.c +2 -2
@@ -111,8 +111,8 @@ DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);*/ /*-------------------------------------------------------------------------*/ -#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) -#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff)) +#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) +#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL)/* usb 3.1 root hub device descriptor */ static const u8 usb31_rh_dev_descriptor[18 ] = {
drivers/usb/gadget/udc/aspeed-vhub/hub.c +2 -2
@@ -46,8 +46,8 @@* - Make vid/did overridable * - make it look like usb1 if usb1 mode forced */ -#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) -#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff)) +#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) +#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL)enum {AST_VHUB_STR_INDEX_MAX =4 ,
include/linux/usb/composite.h +2 -2
@@ -575,8 +575,8 @@ static inline u16 get_default_bcdDevice(void) {u16 bcdDevice; - bcdDevice =bin2bcd ((LINUX_VERSION_CODE >>16 &0xff )) <<8 ; - bcdDevice |=bin2bcd ((LINUX_VERSION_CODE >>8 &0xff )); + bcdDevice =bin2bcd (LINUX_VERSION_MAJOR ) <<8 ; + bcdDevice |=bin2bcd (LINUX_VERSION_PATCHLEVEL );return bcdDevice; }
kernel/sys.c +1 -1
@@ -1242,7 +1242,7 @@ static int override_release(char __user *release, size_t len)break ; rest++; } - v = ((LINUX_VERSION_CODE >>8 ) &0xff ) +60 ; + v =LINUX_VERSION_PATCHLEVEL +60 ; copy =clamp_t (size_t, len,1 ,sizeof (buf)); copy =scnprintf (buf, copy,"2.6.%u%s" , v, rest); ret =copy_to_user (release, buf, copy +1 );
tools/perf/tests/bpf-script-example.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'#endif #define BPF_ANY 0#define BPF_MAP_TYPE_ARRAY 2
tools/perf/tests/bpf-script-test-kbuild.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))
tools/perf/tests/bpf-script-test-prologue.c +1 -1
@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))
Signature · 1 line
2.27.0
Re: [PATCH 3/3] kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
Quoted 10 lines · Sasha Levin
SUBLEVEL only has 8 bits of space, which means that we'll overflow it once it reaches 256.
Few of the stable branches will imminently overflow SUBLEVEL while there's no risk of overflowing VERSION.
Thus, give SUBLEVEL 8 more bits which will be stolen from VERSION, this should create a better balance between the different version numbers we use.
Quoted 8 lines
We can't however use the original
KERNEL_VERSIONandLINUX_VERSION_CODEas userspace has created ABI dependency on their structure, and we risk breaking this userspace by modifying the layout of the version integers.Signed-off-by Sasha Levin <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>
I wanted to re-use an older commit but forgot to drop the two tags above. The tags from Masahiro and Greg shouldn't be here, sorry about that.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 3/3] kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
In reply to Sasha LevinQuoted 37 lines · Sasha Levin
SUBLEVEL only has 8 bits of space, which means that we'll overflow it once it reaches 256.
Few of the stable branches will imminently overflow SUBLEVEL while there's no risk of overflowing VERSION.
Thus, give SUBLEVEL 8 more bits which will be stolen from VERSION, this should create a better balance between the different version numbers we use.
We can't however use the original
KERNEL_VERSIONandLINUX_VERSION_CODEas userspace has created ABI dependency on their structure, and we risk breaking this userspace by modifying the layout of the version integers.Signed-off-by Sasha Levin <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- Makefile | 8 +++++++- drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 ++-- drivers/usb/core/hcd.c | 4 ++-- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 4 ++-- include/linux/usb/composite.h | 4 ++-- kernel/sys.c | 2 +- tools/perf/tests/bpf-script-example.c | 2 +- tools/perf/tests/bpf-script-test-kbuild.c | 2 +- tools/perf/tests/bpf-script-test-prologue.c | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-)Makefile +0
-0
Makefile define filechk_version.h · line 1271
Quoted 7 lines
Makefile +3
-1@@ -1266,7 +1266,13 @@ define filechk_version.h expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ fi; \ echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ - ((c) > 255 ? 255 : (c)))' + ((c) > 255 ? 255 : (c)))'; \ + echo \#define LINUX_VERSION_CODE2 $(shell \ + expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \
Is this needed?
No one in this patch uses LINUX_VERSION_CODE2.
The in-kernel code can use
LINUX_VERSION_MAJOR/PATCHLEVEL/SUBLEVEL directly.
Userspace does not need LINUX_VERSION_CODE2 either.
Your comment in 2/3 states that
userspace only decodes MAJOR and PATCHLEVEL fields, so LINUX_VERSION_CODE will still do well.
tools/perf/tests/bpf-script-example.c line 8
Quoted 9 lines
index
ab4b98b3165db..a56bf381335e9100644tools/perf/tests/bpf-script-example.c +1
-1@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'
Is this change needed?
Quoted 32 lines
tools/perf/tests/bpf-script-example.c +0
-0#endif #define BPF_ANY 0#define BPF_MAP_TYPE_ARRAY 2tools/perf/tests/bpf-script-test-kbuild.c +1
-1@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))tools/perf/tests/bpf-script-test-prologue.c +1
-2@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used)) --2.27.0
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 3/3] kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
Quoted 14 lines · Masahiro Yamada
Makefile define filechk_version.h · line 1271
Quoted 4 lines · Sasha Levin
Makefile +3
-1- ((c) > 255 ? 255 : (c)))' + ((c) > 255 ? 255 : (c)))'; \ + echo \#define LINUX_VERSION_CODE2 $(shell \ + expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \Is this needed?
No one in this patch usesLINUX_VERSION_CODE2.The in-kernel code can use
LINUX_VERSION_MAJOR/PATCHLEVEL/SUBLEVEL directly.
Quoted 5 lines
Userspace does not need
LINUX_VERSION_CODE2either.Your comment in 2/3 states that
userspace only decodes MAJOR and PATCHLEVEL fields, soLINUX_VERSION_CODEwill still do well.
Yes, that's fair. I wanted to have that to make it easy for out of tree code to handle in-kernel ABI changes but as we don't care about such code there's no strict need for LINUX_VERSION_CODE2. I'll drop it.
Quoted 4 lines
Quoted 4 lines
index
ab4b98b3165db..a56bf381335e9100644tools/perf/tests/bpf-script-example.c +0
-0@@ -5,7 +5,7 @@
Quoted 8 lines
tools/perf/tests/bpf-script-example.c line 8
Quoted 5 lines
tools/perf/tests/bpf-script-example.c +1
-1*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig'Is this change needed?
Good point, no. I'll resend.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 3/3] kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
In reply to Sasha LevinQuoted 14 lines · Sasha Levin
SUBLEVEL only has 8 bits of space, which means that we'll overflow it once it reaches 256.
Few of the stable branches will imminently overflow SUBLEVEL while there's no risk of overflowing VERSION.
Thus, give SUBLEVEL 8 more bits which will be stolen from VERSION, this should create a better balance between the different version numbers we use.
We can't however use the original
KERNEL_VERSIONandLINUX_VERSION_CODEas userspace has created ABI dependency on their structure, and we risk breaking this userspace by modifying the layout of the version integers.
Quoted 5 lines
Signed-off-by Sasha Levin <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Greg KH
maintainerRe: [PATCH 3/3] kbuild: introduce KERNEL_VERSION2 and LINUX_VERSION_CODE2
In reply to Sasha LevinQuoted 36 lines · Sasha Levin
SUBLEVEL only has 8 bits of space, which means that we'll overflow it once it reaches 256.
Few of the stable branches will imminently overflow SUBLEVEL while there's no risk of overflowing VERSION.
Thus, give SUBLEVEL 8 more bits which will be stolen from VERSION, this should create a better balance between the different version numbers we use.
We can't however use the original
KERNEL_VERSIONandLINUX_VERSION_CODEas userspace has created ABI dependency on their structure, and we risk breaking this userspace by modifying the layout of the version integers.Signed-off-by Sasha Levin <[email protected]>Reviewed-by Greg Kroah-Hartman <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- Makefile | 8 +++++++- drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 ++-- drivers/usb/core/hcd.c | 4 ++-- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 4 ++-- include/linux/usb/composite.h | 4 ++-- kernel/sys.c | 2 +- tools/perf/tests/bpf-script-example.c | 2 +- tools/perf/tests/bpf-script-test-kbuild.c | 2 +- tools/perf/tests/bpf-script-test-prologue.c | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-)Makefile +0
-0
Makefile define filechk_version.h · line 1270
Quoted 6 lines
Makefile +2
-1@@ -1266,7 +1266,13 @@ define filechk_version.h expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ fi; \ echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ - ((c) > 255 ? 255 : (c)))' + ((c) > 255 ? 255 : (c)))'; \ + echo \#define LINUX_VERSION_CODE2 $(shell \
Wait, no, who will use LINUX_VERSION_CODE2()? Why export something like this to userspace that no one is asking for?
Makefile define filechk_version.h · line 1274
Quoted 4 lines
Makefile +4
-0+ expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \ + echo \#define LINUX_VERSION_MAJOR $(VERSION); \ + echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ + echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL); \
These are good to have, and clean up kernel code.
thanks,
greg k-h
Quoted 6 lines · Sasha Levin
This reverts commit
537896fabed11f8d9788886d1aacdb977213c7b3.This turns out to be a bad idea: userspace has coded the structure of
KERNEL_VERSIONon it's own and assumes the 2-1-1 byte split, making it userspace ABI we can't break.
It is unfortunate...
I will drop this from my tree.
This did not hit Linus' tree yet.
Quoted 149 lines
The reverted patch didn't make it past linux-next, so no userspace was hurt in the process.
Signed-off-by Sasha Levin <[email protected]>--- Makefile | 7 ++----- drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 ++-- drivers/usb/core/hcd.c | 4 ++-- drivers/usb/gadget/udc/aspeed-vhub/hub.c | 4 ++-- include/linux/usb/composite.h | 4 ++-- kernel/sys.c | 2 +- tools/perf/tests/bpf-script-example.c | 2 +- tools/perf/tests/bpf-script-test-kbuild.c | 2 +- tools/perf/tests/bpf-script-test-prologue.c | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-)Makefile +2
-5@@ -1259,11 +1259,8 @@ endef define filechk_version.h echo \#define LINUX_VERSION_CODE $(shell \ - expr $(VERSION) \* 16777216 + 0$(PATCHLEVEL) \* 65536 + 0$(SUBLEVEL)); \ - echo \#define LINUX_VERSION_MAJOR $(VERSION); \ - echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ - echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL); \ - echo '#define KERNEL_VERSION(a,b,c) (((a) << 24) + ((b) << 16) + (c))' + expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ + echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' endef $(version_h): FORCEdrivers/net/ethernet/mellanox/mlx5/core/main.c +2
-2@@ -237,8 +237,8 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev) remaining_size =max_t (int,0 , driver_ver_sz -strlen (string));snprintf (string +strlen (string), remaining_size,"%u.%u.%u" , - (u8)(LINUX_VERSION_MAJOR ), (u8)(LINUX_VERSION_PATCHLEVEL ), - (u16)(LINUX_VERSION_SUBLEVEL )); + (u8)((LINUX_VERSION_CODE >>16 ) &0xff ), (u8)((LINUX_VERSION_CODE >>8 ) &0xff ), + (u16)(LINUX_VERSION_CODE &0xffff ));/*Send the command*/ MLX5_SET(set_driver_version_in, in, opcode,drivers/usb/core/hcd.c +2
-2@@ -111,8 +111,8 @@ DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);*/ /*-------------------------------------------------------------------------*/ -#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) -#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL) +#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) +#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))/* usb 3.1 root hub device descriptor */ static const u8 usb31_rh_dev_descriptor[18 ] = {drivers/usb/gadget/udc/aspeed-vhub/hub.c +2
-2@@ -46,8 +46,8 @@* - Make vid/did overridable * - make it look like usb1 if usb1 mode forced */ -#define KERNEL_REL bin2bcd(LINUX_VERSION_MAJOR) -#define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL) +#define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff)) +#define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))enum {AST_VHUB_STR_INDEX_MAX =4 ,include/linux/usb/composite.h +2
-2@@ -575,8 +575,8 @@ static inline u16 get_default_bcdDevice(void) {u16 bcdDevice; - bcdDevice =bin2bcd (LINUX_VERSION_MAJOR ) <<8 ; - bcdDevice |=bin2bcd (LINUX_VERSION_PATCHLEVEL ); + bcdDevice =bin2bcd ((LINUX_VERSION_CODE >>16 &0xff )) <<8 ; + bcdDevice |=bin2bcd ((LINUX_VERSION_CODE >>8 &0xff ));return bcdDevice; }kernel/sys.c +1
-1@@ -1242,7 +1242,7 @@ static int override_release(char __user *release, size_t len)break ; rest++; } - v =LINUX_VERSION_PATCHLEVEL +60 ; + v = ((LINUX_VERSION_CODE >>8 ) &0xff ) +60 ; copy =clamp_t (size_t, len,1 ,sizeof (buf)); copy =scnprintf (buf, copy,"2.6.%u%s" , v, rest); ret =copy_to_user (release, buf, copy +1 );tools/perf/tests/bpf-script-example.c +1
-1@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define BPF_ANY 0#define BPF_MAP_TYPE_ARRAY 2tools/perf/tests/bpf-script-test-kbuild.c +1
-1@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used))tools/perf/tests/bpf-script-test-prologue.c +1
-2@@ -5,7 +5,7 @@*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE -# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x4020000" into llvm section of ~/.perfconfig' +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'#endif #define SEC (NAME ) __attribute__((section(NAME), used)) --2.27.0
Signature · 2 lines
Best Regards Masahiro Yamada