* [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions
@ 2025-02-27 2:24 Anshuman Khandual
2025-02-27 9:04 ` Ryan Roberts
2025-03-05 19:32 ` Catalin Marinas
0 siblings, 2 replies; 3+ messages in thread
From: Anshuman Khandual @ 2025-02-27 2:24 UTC (permalink / raw)
To: linux-arm-kernel
Cc: mark.rutland, ryan.roberts, Anshuman Khandual, Catalin Marinas,
Will Deacon, linux-kernel
When CONFIG_ARM64_PA_BITS_52 is enabled, page table helpers __pte_to_phys()
and __phys_to_pte_val() are functions which return phys_addr_t and pteval_t
respectively as expected. But otherwise without this config being enabled,
they are defined as macros and their return types are implicit.
Until now this has worked out correctly as both pte_t and phys_addr_t data
types have been 64 bits. But with the introduction of 128 bit page tables,
pte_t becomes 128 bits. Hence this ends up with incorrect widths after the
conversions, which leads to compiler warnings.
Fix these warnings by converting __pte_to_phys() and __phys_to_pte_val()
as functions instead where the return types are handled explicitly.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This patch applies on v6.14-rc3
Changes in V2:
- Changed the helper macros as functions instead per Mark
- Dropped irrelevant (now) in-code comments per Mark
Changes in V1:
https://lore.kernel.org/all/20250219035646.536707-1-anshuman.khandual@arm.com/
arch/arm64/include/asm/pgtable.h | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 0b2a2ad1b9e8..4ebfa60ea5c6 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -68,10 +68,6 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
#define pte_ERROR(e) \
pr_err("%s:%d: bad pte %016llx.\n", __FILE__, __LINE__, pte_val(e))
-/*
- * Macros to convert between a physical address and its placement in a
- * page table entry, taking care of 52-bit addresses.
- */
#ifdef CONFIG_ARM64_PA_BITS_52
static inline phys_addr_t __pte_to_phys(pte_t pte)
{
@@ -84,8 +80,15 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK;
}
#else
-#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_LOW)
-#define __phys_to_pte_val(phys) (phys)
+static inline phys_addr_t __pte_to_phys(pte_t pte)
+{
+ return pte_val(pte) & PTE_ADDR_LOW;
+}
+
+static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
+{
+ return phys;
+}
#endif
#define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT)
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions
2025-02-27 2:24 [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions Anshuman Khandual
@ 2025-02-27 9:04 ` Ryan Roberts
2025-03-05 19:32 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Ryan Roberts @ 2025-02-27 9:04 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: mark.rutland, Catalin Marinas, Will Deacon, linux-kernel
On 27/02/2025 02:24, Anshuman Khandual wrote:
> When CONFIG_ARM64_PA_BITS_52 is enabled, page table helpers __pte_to_phys()
> and __phys_to_pte_val() are functions which return phys_addr_t and pteval_t
> respectively as expected. But otherwise without this config being enabled,
> they are defined as macros and their return types are implicit.
>
> Until now this has worked out correctly as both pte_t and phys_addr_t data
> types have been 64 bits. But with the introduction of 128 bit page tables,
> pte_t becomes 128 bits. Hence this ends up with incorrect widths after the
> conversions, which leads to compiler warnings.
>
> Fix these warnings by converting __pte_to_phys() and __phys_to_pte_val()
> as functions instead where the return types are handled explicitly.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> This patch applies on v6.14-rc3
>
> Changes in V2:
>
> - Changed the helper macros as functions instead per Mark
> - Dropped irrelevant (now) in-code comments per Mark
>
> Changes in V1:
>
> https://lore.kernel.org/all/20250219035646.536707-1-anshuman.khandual@arm.com/
>
> arch/arm64/include/asm/pgtable.h | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 0b2a2ad1b9e8..4ebfa60ea5c6 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -68,10 +68,6 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
> #define pte_ERROR(e) \
> pr_err("%s:%d: bad pte %016llx.\n", __FILE__, __LINE__, pte_val(e))
>
> -/*
> - * Macros to convert between a physical address and its placement in a
> - * page table entry, taking care of 52-bit addresses.
> - */
> #ifdef CONFIG_ARM64_PA_BITS_52
> static inline phys_addr_t __pte_to_phys(pte_t pte)
> {
> @@ -84,8 +80,15 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
> return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK;
> }
> #else
> -#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_LOW)
> -#define __phys_to_pte_val(phys) (phys)
> +static inline phys_addr_t __pte_to_phys(pte_t pte)
> +{
> + return pte_val(pte) & PTE_ADDR_LOW;
> +}
> +
> +static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
> +{
> + return phys;
> +}
> #endif
>
> #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions
2025-02-27 2:24 [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions Anshuman Khandual
2025-02-27 9:04 ` Ryan Roberts
@ 2025-03-05 19:32 ` Catalin Marinas
1 sibling, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2025-03-05 19:32 UTC (permalink / raw)
To: linux-arm-kernel, Anshuman Khandual
Cc: Will Deacon, mark.rutland, ryan.roberts, linux-kernel
On Thu, 27 Feb 2025 07:54:12 +0530, Anshuman Khandual wrote:
> When CONFIG_ARM64_PA_BITS_52 is enabled, page table helpers __pte_to_phys()
> and __phys_to_pte_val() are functions which return phys_addr_t and pteval_t
> respectively as expected. But otherwise without this config being enabled,
> they are defined as macros and their return types are implicit.
>
> Until now this has worked out correctly as both pte_t and phys_addr_t data
> types have been 64 bits. But with the introduction of 128 bit page tables,
> pte_t becomes 128 bits. Hence this ends up with incorrect widths after the
> conversions, which leads to compiler warnings.
>
> [...]
Applied to arm64 (for-next/pgtable-cleanups), thanks!
[1/1] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions
https://git.kernel.org/arm64/c/2d7872f3ae3b
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-05 19:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-27 2:24 [PATCH V2] arm64/mm: Convert __pte_to_phys() and __phys_to_pte_val() as functions Anshuman Khandual
2025-02-27 9:04 ` Ryan Roberts
2025-03-05 19:32 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®