diff mbox series

powerpc: Split PAGE_SHIFT/SIZE into vdso/page.h

Message ID 20231221120410.2226678-1-mpe@ellerman.id.au (mailing list archive)
State Superseded
Headers show
Series powerpc: Split PAGE_SHIFT/SIZE into vdso/page.h | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Michael Ellerman Dec. 21, 2023, 12:04 p.m. UTC
The VDSO needs PAGE_SHIFT/SIZE defined, so it includes asm/page.h.

However when COMPAT=y the VDSO is built 32-bit, even though the kernel
is 64-bit. That can lead to odd warnings because some kernel constants
are 64-bit, but unsigned long is 32-bit, for example:

    VDSO32C arch/powerpc/kernel/vdso/vgettimeofday-32.o
  In file included from <built-in>:4:
  In file included from /home/michael/linux/lib/vdso/gettimeofday.c:5:
  In file included from ../include/vdso/datapage.h:137:
  In file included from ../arch/powerpc/include/asm/vdso/gettimeofday.h:7:
  ../arch/powerpc/include/asm/page.h:230:9: warning: result of comparison of constant 13835058055282163712 with expression of type 'unsigned long' is always true
    230 |         return __pa(kaddr) >> PAGE_SHIFT;
        |                ^~~~~~~~~~~

Fix it by moving the PAGE_SHIFT/SIZE constants into a separate header,
which can be included by the VDSO, and also by the existing kernel
headers. That avoids exposing the rest of the header to the non-standard
build environment of the compat VDSO.

The particular warning above was introduced by commit 58b6fed89ab0
("powerpc: Make virt_to_pfn() a static inline"), though it is not at
fault, it just exposed the fact that the VDSO was including parts of
page.h that weren't needed or appropriate for the VDSO.

Don't copy the comment about page sizes, it just risks becoming
outdated, that information is better available in the Kconfig
dependencies and help text.

Fixes: 58b6fed89ab0 ("powerpc: Make virt_to_pfn() a static inline")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311061940.4pBrm44u-lkp@intel.com/
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/include/asm/page.h              | 10 +---------
 arch/powerpc/include/asm/vdso/gettimeofday.h |  2 +-
 arch/powerpc/include/asm/vdso/page.h         | 10 ++++++++++
 arch/powerpc/kernel/vdso/vdso32.lds.S        |  2 +-
 arch/powerpc/kernel/vdso/vdso64.lds.S        |  2 +-
 arch/powerpc/kernel/vdso32_wrapper.S         |  2 +-
 arch/powerpc/kernel/vdso64_wrapper.S         |  2 +-
 7 files changed, 16 insertions(+), 14 deletions(-)
 create mode 100644 arch/powerpc/include/asm/vdso/page.h

Comments

Linus Walleij Dec. 21, 2023, 12:26 p.m. UTC | #1
On Thu, Dec 21, 2023 at 1:04 PM Michael Ellerman <mpe@ellerman.id.au> wrote:

> The VDSO needs PAGE_SHIFT/SIZE defined, so it includes asm/page.h.
>
> However when COMPAT=y the VDSO is built 32-bit, even though the kernel
> is 64-bit. That can lead to odd warnings because some kernel constants
> are 64-bit, but unsigned long is 32-bit, for example:
>
>     VDSO32C arch/powerpc/kernel/vdso/vgettimeofday-32.o
>   In file included from <built-in>:4:
>   In file included from /home/michael/linux/lib/vdso/gettimeofday.c:5:
>   In file included from ../include/vdso/datapage.h:137:
>   In file included from ../arch/powerpc/include/asm/vdso/gettimeofday.h:7:
>   ../arch/powerpc/include/asm/page.h:230:9: warning: result of comparison of constant 13835058055282163712 with expression of type 'unsigned long' is always true
>     230 |         return __pa(kaddr) >> PAGE_SHIFT;
>         |                ^~~~~~~~~~~
>
> Fix it by moving the PAGE_SHIFT/SIZE constants into a separate header,
> which can be included by the VDSO, and also by the existing kernel
> headers. That avoids exposing the rest of the header to the non-standard
> build environment of the compat VDSO.
>
> The particular warning above was introduced by commit 58b6fed89ab0
> ("powerpc: Make virt_to_pfn() a static inline"), though it is not at
> fault, it just exposed the fact that the VDSO was including parts of
> page.h that weren't needed or appropriate for the VDSO.
>
> Don't copy the comment about page sizes, it just risks becoming
> outdated, that information is better available in the Kconfig
> dependencies and help text.
>
> Fixes: 58b6fed89ab0 ("powerpc: Make virt_to_pfn() a static inline")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202311061940.4pBrm44u-lkp@intel.com/
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Clearly a working solution!
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Just a note:

> diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
(...)
> +#include <asm/vdso/page.h>

(...)
> +++ b/arch/powerpc/include/asm/vdso/page.h
> @@ -0,0 +1,10 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +#ifndef _ASM_POWERPC_VDSO_PAGE_H
> +#define _ASM_POWERPC_VDSO_PAGE_H
> +
> +#include <vdso/const.h>

Now the whole kernel includes <vdso/const.h>, is this necessary?

Yours,
Linus Walleij
Michael Ellerman Dec. 21, 2023, 11:42 p.m. UTC | #2
Linus Walleij <linus.walleij@linaro.org> writes:
> On Thu, Dec 21, 2023 at 1:04 PM Michael Ellerman <mpe@ellerman.id.au> wrote:
>
>> The VDSO needs PAGE_SHIFT/SIZE defined, so it includes asm/page.h.
>>
>> However when COMPAT=y the VDSO is built 32-bit, even though the kernel
>> is 64-bit. That can lead to odd warnings because some kernel constants
>> are 64-bit, but unsigned long is 32-bit, for example:
>>
>>     VDSO32C arch/powerpc/kernel/vdso/vgettimeofday-32.o
>>   In file included from <built-in>:4:
>>   In file included from /home/michael/linux/lib/vdso/gettimeofday.c:5:
>>   In file included from ../include/vdso/datapage.h:137:
>>   In file included from ../arch/powerpc/include/asm/vdso/gettimeofday.h:7:
>>   ../arch/powerpc/include/asm/page.h:230:9: warning: result of comparison of constant 13835058055282163712 with expression of type 'unsigned long' is always true
>>     230 |         return __pa(kaddr) >> PAGE_SHIFT;
>>         |                ^~~~~~~~~~~
>>
>> Fix it by moving the PAGE_SHIFT/SIZE constants into a separate header,
>> which can be included by the VDSO, and also by the existing kernel
>> headers. That avoids exposing the rest of the header to the non-standard
>> build environment of the compat VDSO.
>>
>> The particular warning above was introduced by commit 58b6fed89ab0
>> ("powerpc: Make virt_to_pfn() a static inline"), though it is not at
>> fault, it just exposed the fact that the VDSO was including parts of
>> page.h that weren't needed or appropriate for the VDSO.
>>
>> Don't copy the comment about page sizes, it just risks becoming
>> outdated, that information is better available in the Kconfig
>> dependencies and help text.
>>
>> Fixes: 58b6fed89ab0 ("powerpc: Make virt_to_pfn() a static inline")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202311061940.4pBrm44u-lkp@intel.com/
>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>
> Clearly a working solution!
> Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks.

> Just a note:
>
>> diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
> (...)
>> +#include <asm/vdso/page.h>
>
> (...)
>> +++ b/arch/powerpc/include/asm/vdso/page.h
>> @@ -0,0 +1,10 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +#ifndef _ASM_POWERPC_VDSO_PAGE_H
>> +#define _ASM_POWERPC_VDSO_PAGE_H
>> +
>> +#include <vdso/const.h>
>
> Now the whole kernel includes <vdso/const.h>, is this necessary?

It's already included by approximately the whole kernel via:
  include/linux/kernel.h
   - include/uapi/linux/kernel.h
     - include/linux/const.h
       - include/vdso/const.h

And arch/powerpc/include/asm/page.h already includes linux/kernel.h, so
includers of page.h should not see any new headers other than
asm/vdso/page.h.

cheers
Michael Ellerman April 22, 2024, 9:36 a.m. UTC | #3
Michael Ellerman <mpe@ellerman.id.au> writes:
> The VDSO needs PAGE_SHIFT/SIZE defined, so it includes asm/page.h.

For the archives, this was superseeded by Arnd's rework:

  https://lore.kernel.org/all/20240320180228.136371-1-arnd@kernel.org/

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index e5fcc79b5bfb..79b463f6f0d7 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -14,15 +14,7 @@ 
 #include <asm/types.h>
 #endif
 #include <asm/asm-const.h>
-
-/*
- * On regular PPC32 page size is 4K (but we support 4K/16K/64K/256K pages
- * on PPC44x and 4K/16K on 8xx). For PPC64 we support either 4K or 64K software
- * page size. When using 64K pages however, whether we are really supporting
- * 64K pages in HW or not is irrelevant to those definitions.
- */
-#define PAGE_SHIFT		CONFIG_PPC_PAGE_SHIFT
-#define PAGE_SIZE		(ASM_CONST(1) << PAGE_SHIFT)
+#include <asm/vdso/page.h>
 
 #ifndef __ASSEMBLY__
 #ifndef CONFIG_HUGETLB_PAGE
diff --git a/arch/powerpc/include/asm/vdso/gettimeofday.h b/arch/powerpc/include/asm/vdso/gettimeofday.h
index f0a4cf01e85c..81e82777b0f9 100644
--- a/arch/powerpc/include/asm/vdso/gettimeofday.h
+++ b/arch/powerpc/include/asm/vdso/gettimeofday.h
@@ -4,7 +4,7 @@ 
 
 #ifndef __ASSEMBLY__
 
-#include <asm/page.h>
+#include <asm/vdso/page.h>
 #include <asm/vdso/timebase.h>
 #include <asm/barrier.h>
 #include <asm/unistd.h>
diff --git a/arch/powerpc/include/asm/vdso/page.h b/arch/powerpc/include/asm/vdso/page.h
new file mode 100644
index 000000000000..fa30ad64c88e
--- /dev/null
+++ b/arch/powerpc/include/asm/vdso/page.h
@@ -0,0 +1,10 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _ASM_POWERPC_VDSO_PAGE_H
+#define _ASM_POWERPC_VDSO_PAGE_H
+
+#include <vdso/const.h>
+
+#define PAGE_SHIFT	CONFIG_PPC_PAGE_SHIFT
+#define PAGE_SIZE	(UL(1) << PAGE_SHIFT)
+
+#endif // _ASM_POWERPC_VDSO_PAGE_H
diff --git a/arch/powerpc/kernel/vdso/vdso32.lds.S b/arch/powerpc/kernel/vdso/vdso32.lds.S
index 426e1ccc6971..3a6b232c4147 100644
--- a/arch/powerpc/kernel/vdso/vdso32.lds.S
+++ b/arch/powerpc/kernel/vdso/vdso32.lds.S
@@ -4,7 +4,7 @@ 
  * library
  */
 #include <asm/vdso.h>
-#include <asm/page.h>
+#include <asm/vdso/page.h>
 #include <asm-generic/vmlinux.lds.h>
 
 #ifdef __LITTLE_ENDIAN__
diff --git a/arch/powerpc/kernel/vdso/vdso64.lds.S b/arch/powerpc/kernel/vdso/vdso64.lds.S
index bda6c8cdd459..806005092197 100644
--- a/arch/powerpc/kernel/vdso/vdso64.lds.S
+++ b/arch/powerpc/kernel/vdso/vdso64.lds.S
@@ -4,7 +4,7 @@ 
  * library
  */
 #include <asm/vdso.h>
-#include <asm/page.h>
+#include <asm/vdso/page.h>
 #include <asm-generic/vmlinux.lds.h>
 
 #ifdef __LITTLE_ENDIAN__
diff --git a/arch/powerpc/kernel/vdso32_wrapper.S b/arch/powerpc/kernel/vdso32_wrapper.S
index 10f92f265d51..3d9d0824a91c 100644
--- a/arch/powerpc/kernel/vdso32_wrapper.S
+++ b/arch/powerpc/kernel/vdso32_wrapper.S
@@ -1,6 +1,6 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 #include <linux/linkage.h>
-#include <asm/page.h>
+#include <asm/vdso/page.h>
 
 	__PAGE_ALIGNED_DATA
 
diff --git a/arch/powerpc/kernel/vdso64_wrapper.S b/arch/powerpc/kernel/vdso64_wrapper.S
index 839d1a61411d..0e3ff78d7c58 100644
--- a/arch/powerpc/kernel/vdso64_wrapper.S
+++ b/arch/powerpc/kernel/vdso64_wrapper.S
@@ -1,6 +1,6 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 #include <linux/linkage.h>
-#include <asm/page.h>
+#include <asm/vdso/page.h>
 
 	__PAGE_ALIGNED_DATA