linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT
@ 2023-07-25 20:24 Zhang Jianhua
  2023-08-03 17:06 ` Catalin Marinas
  0 siblings, 1 reply; 4+ messages in thread
From: Zhang Jianhua @ 2023-07-25 20:24 UTC (permalink / raw)
  To: catalin.marinas, ill, mark.rutland, ryan.roberts, joey.gouly,
	ardb, anshuman.khandual, bhe, thunder.leizhen, broonie
  Cc: chris.zjh, linux-arm-kernel, linux-kernel

When building with W=1, the following warning occurs.

arch/arm64/include/asm/kernel-pgtable.h:129:41: error: "PUD_SHIFT" is not defined, evaluates to 0 [-Werror=undef]
  129 | #define ARM64_MEMSTART_SHIFT            PUD_SHIFT
      |                                         ^~~~~~~~~
arch/arm64/include/asm/kernel-pgtable.h:142:5: note: in expansion of macro ‘ARM64_MEMSTART_SHIFT’
  142 | #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
      |     ^~~~~~~~~~~~~~~~~~~~

The reason is that PUD_SHIFT isn't defined if CONFIG_PGTABLE_LEVELS == 3
and CONFIG_VA_BITS == 39. Now move the macro ARM64_MEMSTART_SHIFT and
ARM64_MEMSTART_ALIGN to arch/arm64/mm/init.c where it is used to avoid
this issue, and also there is no other place to call these two macro.

Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>
---
v3:
	Move the defination of macro ARM64_MEMSTART_SHIFT and ARM64_MEMSTART_ALIGN
	from arch/arm64/include/asm/kernel-pgtable.h to arch/arm64/mm/init.c

v2:
	Add define judgement of PUD_SHIFT/CONT_PMD_SHIFT/CONT_PMD_SHIFT
	before use them, instead of define PUD_SHIFT only.
---
---
 arch/arm64/include/asm/kernel-pgtable.h | 27 -------------------------
 arch/arm64/mm/init.c                    | 27 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index 577773870b66..85d26143faa5 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -118,31 +118,4 @@
 #define SWAPPER_RX_MMUFLAGS	(SWAPPER_RW_MMUFLAGS | PTE_RDONLY)
 #endif
 
-/*
- * To make optimal use of block mappings when laying out the linear
- * mapping, round down the base of physical memory to a size that can
- * be mapped efficiently, i.e., either PUD_SIZE (4k granule) or PMD_SIZE
- * (64k granule), or a multiple that can be mapped using contiguous bits
- * in the page tables: 32 * PMD_SIZE (16k granule)
- */
-#if defined(CONFIG_ARM64_4K_PAGES)
-#define ARM64_MEMSTART_SHIFT		PUD_SHIFT
-#elif defined(CONFIG_ARM64_16K_PAGES)
-#define ARM64_MEMSTART_SHIFT		CONT_PMD_SHIFT
-#else
-#define ARM64_MEMSTART_SHIFT		PMD_SHIFT
-#endif
-
-/*
- * sparsemem vmemmap imposes an additional requirement on the alignment of
- * memstart_addr, due to the fact that the base of the vmemmap region
- * has a direct correspondence, and needs to appear sufficiently aligned
- * in the virtual address space.
- */
-#if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
-#define ARM64_MEMSTART_ALIGN	(1UL << SECTION_SIZE_BITS)
-#else
-#define ARM64_MEMSTART_ALIGN	(1UL << ARM64_MEMSTART_SHIFT)
-#endif
-
 #endif	/* __ASM_KERNEL_PGTABLE_H */
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index d31c3a9290c5..4fcb88a445ef 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -73,6 +73,33 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
 
 #define DEFAULT_CRASH_KERNEL_LOW_SIZE	(128UL << 20)
 
+/*
+ * To make optimal use of block mappings when laying out the linear
+ * mapping, round down the base of physical memory to a size that can
+ * be mapped efficiently, i.e., either PUD_SIZE (4k granule) or PMD_SIZE
+ * (64k granule), or a multiple that can be mapped using contiguous bits
+ * in the page tables: 32 * PMD_SIZE (16k granule)
+ */
+#if defined(CONFIG_ARM64_4K_PAGES)
+#define ARM64_MEMSTART_SHIFT		PUD_SHIFT
+#elif defined(CONFIG_ARM64_16K_PAGES)
+#define ARM64_MEMSTART_SHIFT		CONT_PMD_SHIFT
+#else
+#define ARM64_MEMSTART_SHIFT		PMD_SHIFT
+#endif
+
+/*
+ * sparsemem vmemmap imposes an additional requirement on the alignment of
+ * memstart_addr, due to the fact that the base of the vmemmap region
+ * has a direct correspondence, and needs to appear sufficiently aligned
+ * in the virtual address space.
+ */
+#if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
+#define ARM64_MEMSTART_ALIGN	(1UL << SECTION_SIZE_BITS)
+#else
+#define ARM64_MEMSTART_ALIGN	(1UL << ARM64_MEMSTART_SHIFT)
+#endif
+
 static int __init reserve_crashkernel_low(unsigned long long low_size)
 {
 	unsigned long long low_base;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT
  2023-07-25 20:24 [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT Zhang Jianhua
@ 2023-08-03 17:06 ` Catalin Marinas
  2023-08-04  6:24   ` Anshuman Khandual
  0 siblings, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2023-08-03 17:06 UTC (permalink / raw)
  To: Zhang Jianhua
  Cc: will, mark.rutland, ryan.roberts, joey.gouly, ardb,
	anshuman.khandual, bhe, thunder.leizhen, broonie,
	linux-arm-kernel, linux-kernel

On Tue, Jul 25, 2023 at 08:24:04PM +0000, Zhang Jianhua wrote:
> When building with W=1, the following warning occurs.
> 
> arch/arm64/include/asm/kernel-pgtable.h:129:41: error: "PUD_SHIFT" is not defined, evaluates to 0 [-Werror=undef]
>   129 | #define ARM64_MEMSTART_SHIFT            PUD_SHIFT
>       |                                         ^~~~~~~~~
> arch/arm64/include/asm/kernel-pgtable.h:142:5: note: in expansion of macro ‘ARM64_MEMSTART_SHIFT’
>   142 | #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
>       |     ^~~~~~~~~~~~~~~~~~~~
> 
> The reason is that PUD_SHIFT isn't defined if CONFIG_PGTABLE_LEVELS == 3
> and CONFIG_VA_BITS == 39.

The correct description is that the generic PUD_SHIFT isn't defined for
asm files, we still have it defined for C files (there's an #ifndef
__ASSEMBLY__ guard).

> Now move the macro ARM64_MEMSTART_SHIFT and
> ARM64_MEMSTART_ALIGN to arch/arm64/mm/init.c where it is used to avoid
> this issue, and also there is no other place to call these two macro.
> 
> Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>

This fix works for me. I'll leave it to Will for 6.6 as apart from the
warning with W=1, there's no other issue (ARM64_MEMSTART_* are not used
in any asm files).

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT
  2023-08-03 17:06 ` Catalin Marinas
@ 2023-08-04  6:24   ` Anshuman Khandual
  2023-08-04  6:39     ` zhangjianhua (E)
  0 siblings, 1 reply; 4+ messages in thread
From: Anshuman Khandual @ 2023-08-04  6:24 UTC (permalink / raw)
  To: Catalin Marinas, Zhang Jianhua
  Cc: will, mark.rutland, ryan.roberts, joey.gouly, ardb, bhe,
	thunder.leizhen, broonie, linux-arm-kernel, linux-kernel



On 8/3/23 22:36, Catalin Marinas wrote:
> On Tue, Jul 25, 2023 at 08:24:04PM +0000, Zhang Jianhua wrote:
>> When building with W=1, the following warning occurs.
>>
>> arch/arm64/include/asm/kernel-pgtable.h:129:41: error: "PUD_SHIFT" is not defined, evaluates to 0 [-Werror=undef]
>>   129 | #define ARM64_MEMSTART_SHIFT            PUD_SHIFT
>>       |                                         ^~~~~~~~~
>> arch/arm64/include/asm/kernel-pgtable.h:142:5: note: in expansion of macro ‘ARM64_MEMSTART_SHIFT’
>>   142 | #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
>>       |     ^~~~~~~~~~~~~~~~~~~~
>>
>> The reason is that PUD_SHIFT isn't defined if CONFIG_PGTABLE_LEVELS == 3
>> and CONFIG_VA_BITS == 39.
> 
> The correct description is that the generic PUD_SHIFT isn't defined for
> asm files, we still have it defined for C files (there's an #ifndef
> __ASSEMBLY__ guard).

Agreed, please rework the commit message explaining how generic PUD_SHIFT
definition is not available for assembly files, prompting this code block
movement. CONFIG_PGTABLE_LEVELS == 3 with CONFIG_VA_BITS == 39 just help
in exposing this problem.

> 
>> Now move the macro ARM64_MEMSTART_SHIFT and
>> ARM64_MEMSTART_ALIGN to arch/arm64/mm/init.c where it is used to avoid
>> this issue, and also there is no other place to call these two macro.
>>
>> Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>
> 
> This fix works for me. I'll leave it to Will for 6.6 as apart from the
> warning with W=1, there's no other issue (ARM64_MEMSTART_* are not used
> in any asm files).

Right, not real a problem to be fixed, this can wait till 6.6

> 
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT
  2023-08-04  6:24   ` Anshuman Khandual
@ 2023-08-04  6:39     ` zhangjianhua (E)
  0 siblings, 0 replies; 4+ messages in thread
From: zhangjianhua (E) @ 2023-08-04  6:39 UTC (permalink / raw)
  To: Anshuman Khandual, Catalin Marinas
  Cc: will, mark.rutland, ryan.roberts, joey.gouly, ardb, bhe,
	thunder.leizhen, broonie, linux-arm-kernel, linux-kernel


在 2023/8/4 14:24, Anshuman Khandual 写道:
>
> On 8/3/23 22:36, Catalin Marinas wrote:
>> On Tue, Jul 25, 2023 at 08:24:04PM +0000, Zhang Jianhua wrote:
>>> When building with W=1, the following warning occurs.
>>>
>>> arch/arm64/include/asm/kernel-pgtable.h:129:41: error: "PUD_SHIFT" is not defined, evaluates to 0 [-Werror=undef]
>>>    129 | #define ARM64_MEMSTART_SHIFT            PUD_SHIFT
>>>        |                                         ^~~~~~~~~
>>> arch/arm64/include/asm/kernel-pgtable.h:142:5: note: in expansion of macro ‘ARM64_MEMSTART_SHIFT’
>>>    142 | #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
>>>        |     ^~~~~~~~~~~~~~~~~~~~
>>>
>>> The reason is that PUD_SHIFT isn't defined if CONFIG_PGTABLE_LEVELS == 3
>>> and CONFIG_VA_BITS == 39.
>> The correct description is that the generic PUD_SHIFT isn't defined for
>> asm files, we still have it defined for C files (there's an #ifndef
>> __ASSEMBLY__ guard).
> Agreed, please rework the commit message explaining how generic PUD_SHIFT
> definition is not available for assembly files, prompting this code block
> movement. CONFIG_PGTABLE_LEVELS == 3 with CONFIG_VA_BITS == 39 just help
> in exposing this problem.
No problem, I will send a new patch soon.
>>> Now move the macro ARM64_MEMSTART_SHIFT and
>>> ARM64_MEMSTART_ALIGN to arch/arm64/mm/init.c where it is used to avoid
>>> this issue, and also there is no other place to call these two macro.
>>>
>>> Signed-off-by: Zhang Jianhua <chris.zjh@huawei.com>
>> This fix works for me. I'll leave it to Will for 6.6 as apart from the
>> warning with W=1, there's no other issue (ARM64_MEMSTART_* are not used
>> in any asm files).
> Right, not real a problem to be fixed, this can wait till 6.6
>
>> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-04  6:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-25 20:24 [PATCH -next v3] arm64: fix build warning for ARM64_MEMSTART_SHIFT Zhang Jianhua
2023-08-03 17:06 ` Catalin Marinas
2023-08-04  6:24   ` Anshuman Khandual
2023-08-04  6:39     ` zhangjianhua (E)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).