vdso: change PAGE_MASK to signed on all 32-bit architectures
PATCH 1/1 vdso: change PAGE_MASK to signed on all 32-bit architectures
From: Arnd Bergmann <[email protected]>
With the introduction of an architecture-independent defintion of PAGE_MASK, we had to make a choice between defining it as 'unsigned long' as on 64-bit architectures, or as signed 'long' as required for architectures with a 64-bit phys_addr_t.
To reduce the risk for regressions and minimize the changes in behavior, the result was using the signed value only when CONFIG_PHYS_ADDR_T_64BIT is set, but that ended up causing a regression after all in the early_init_dt_add_memory_arch() function that uses 64-bit integers for address calculation.
Presumably the same regression also affects mips32 and powerpc32 when dealing with large amounts of memory on DT platforms: like arm32, they were using the signed version unconditionally.
The two most sensible options that I see for addressing the regiression are either to go back to an architecture specific definition, using a signed constant on arm/powerpc/mips and unsigned on the others, or to use the same definition everywhere.
Use the simpler of those two and change them all to the signed version, in the hope that this does not cause a different type of bug. Most of the other 32-bit architectures have no large physical address support and are rarely used, so it seems more likely that using the same definition helps than hurts here.
In particular, x86-32 does have physical addressing extensions, so it already changed to the signed version after the previous patch, so it makes sense to use the same version on non-PAE as well.
--- include/vdso/page.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/vdso/page.h +4 -3
@@ -14,13 +14,14 @@#define PAGE_SIZE (_AC(1,UL) << CONFIG_PAGE_SHIFT) -#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && !defined(CONFIG_64BIT ) +#if !defined(CONFIG_64BIT )/* -* Applies only to 32-bit architectures with a 64-bit phys_addr_t. +* Applies only to 32-bit architectures. * * Subtle: (1 << CONFIG_PAGE_SHIFT) is an int, not an unsigned long. * So if we assign PAGE_MASK to a larger type it gets extended the -* way we want (i.e. with 1s in the high bits) +* way we want (i.e. with 1s in the high bits) while masking a +* 64-bit value such as phys_addr_t. */ #define PAGE_MASK (~((1 << CONFIG_PAGE_SHIFT) - 1))#else
Signature · 1 line
2.39.5
Quoted 32 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With the introduction of an architecture-independent defintion of
PAGE_MASK, we had to make a choice between defining it as 'unsigned long' as on 64-bit architectures, or as signed 'long' as required for architectures with a 64-bitphys_addr_t.To reduce the risk for regressions and minimize the changes in behavior, the result was using the signed value only when
CONFIG_PHYS_ADDR_T_64BITis set, but that ended up causing a regression after all in theearly_init_dt_add_memory_arch()function that uses 64-bit integers for address calculation.Presumably the same regression also affects mips32 and powerpc32 when dealing with large amounts of memory on DT platforms: like arm32, they were using the signed version unconditionally.
The two most sensible options that I see for addressing the regiression are either to go back to an architecture specific definition, using a signed constant on arm/powerpc/mips and unsigned on the others, or to use the same definition everywhere.
Use the simpler of those two and change them all to the signed version, in the hope that this does not cause a different type of bug. Most of the other 32-bit architectures have no large physical address support and are rarely used, so it seems more likely that using the same definition helps than hurts here.
In particular, x86-32 does have physical addressing extensions, so it already changed to the signed version after the previous patch, so it makes sense to use the same version on non-PAE as well.
Quoted 5 lines
Fixes efe8419ae78d ("vdso: Introduce vdso/page.h")Reported-by Naresh Kamboju <[email protected]>Tested-by Anders Roxell <[email protected]>Cc Alex Bennee <[email protected]>,
Thanks Arnd, I tested it this morning and seems working correctly with qemu 9.1.1.
With this:
Quoted 27 lines
Signed-off-by Arnd Bergmann <[email protected]>--- include/vdso/page.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)include/vdso/page.h +4
-3@@ -14,13 +14,14 @@#define PAGE_SIZE (_AC(1,UL) << CONFIG_PAGE_SHIFT) -#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && !defined(CONFIG_64BIT ) +#if !defined(CONFIG_64BIT )/* -* Applies only to 32-bit architectures with a 64-bit phys_addr_t. +* Applies only to 32-bit architectures. * * Subtle: (1 << CONFIG_PAGE_SHIFT) is an int, not an unsigned long. * So if we assign PAGE_MASK to a larger type it gets extended the -* way we want (i.e. with 1s in the high bits) +* way we want (i.e. with 1s in the high bits) while masking a +* 64-bit value such as phys_addr_t. */ #define PAGE_MASK (~((1 << CONFIG_PAGE_SHIFT) - 1))#else
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] vdso: Change PAGE_MASK to signed on all 32-bit architectures
In reply to Arnd BergmannThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: d4a65302dd849fade9e2ca712826c35b8d068ecb Gitweb: https://git.kernel.org/tip/d4a65302dd849fade9e2ca712826c35b8d068ecb Author: Arnd Bergmann <[email protected]> AuthorDate: Thu, 24 Oct 2024 13:34:26 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 28 Oct 2024 16:56:15 +01:00
vdso: Change PAGE_MASK to signed on all 32-bit architectures
With the introduction of an architecture-independent defintion of PAGE_MASK, we had to make a choice between defining it as 'unsigned long' as on 64-bit architectures, or as signed 'long' as required for architectures with a 64-bit phys_addr_t.
To reduce the risk for regressions and minimize the changes in behavior, the result was using the signed value only when CONFIG_PHYS_ADDR_T_64BIT is set, but that ended up causing a regression after all in the early_init_dt_add_memory_arch() function that uses 64-bit integers for address calculation.
Presumably the same regression also affects mips32 and powerpc32 when dealing with large amounts of memory on DT platforms: like arm32, they were using the signed version unconditionally.
The two most sensible options for addressing the regression are either to go back to an architecture specific definition, using a signed constant on arm/powerpc/mips and unsigned on the others, or to use the same definition everywhere.
Use the simpler of those two and change them all to the signed version, in the hope that this does not cause a different type of bug. Most of the other 32-bit architectures have no large physical address support and are rarely used, so it seems more likely that using the same definition helps than hurts here.
In particular, x86-32 does have physical addressing extensions, so it already changed to the signed version after the previous patch, so it makes sense to use the same version on non-PAE as well.
--- include/vdso/page.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/vdso/page.h +4 -3
@@ -14,13 +14,14 @@#define PAGE_SIZE (_AC(1,UL) << CONFIG_PAGE_SHIFT) -#if defined(CONFIG_PHYS_ADDR_T_64BIT ) && !defined(CONFIG_64BIT ) +#if !defined(CONFIG_64BIT )/* -* Applies only to 32-bit architectures with a 64-bit phys_addr_t. +* Applies only to 32-bit architectures. * * Subtle: (1 << CONFIG_PAGE_SHIFT) is an int, not an unsigned long. * So if we assign PAGE_MASK to a larger type it gets extended the -* way we want (i.e. with 1s in the high bits) +* way we want (i.e. with 1s in the high bits) while masking a +* 64-bit value such as phys_addr_t. */ #define PAGE_MASK (~((1 << CONFIG_PAGE_SHIFT) - 1))#else