From: Ryan Roberts <ryan.roberts@arm.com>
To: Mark Rutland <mark.rutland@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64/mm: Explicit cast conversions to correct data type
Date: Tue, 25 Feb 2025 13:00:40 +0000 [thread overview]
Message-ID: <9e1721a1-54a4-4007-a0f5-d651f5f21ae2@arm.com> (raw)
In-Reply-To: <Z724Q1ofM1GvKquV@J2N7QTR9R3>
On 25/02/2025 12:32, Mark Rutland wrote:
> On Wed, Feb 19, 2025 at 09:26:46AM +0530, Anshuman Khandual wrote:
>> From: Ryan Roberts <ryan.roberts@arm.com>
>>
>> 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.
>
> Does 128-bit page table not imply 52-bit PAs?
Not to my knowledge. For now the prototype code base is explicitly sticking to
48-bit PA and 44-bit VA (for initial simplicitly because that's the limit for 4
levels).
>
>> Fix the warnings by explicitly casting to the correct type after doing the
>> conversion.
>
> I think it would be simpler and clearer if we replaced the macros with
> functions, such that __pte_to_phys() and __phys_to_pte_val() are
> *always* functions.
Yeah, agreed. This was initially just a hack I did to get things working.
>
> That way it's easier to compar the CONFIG_ARM64_PA_BITS_52=y and
> CONFIG_ARM64_PA_BITS_52=n versions, and the types are always explciit
> for inputs and outputs, so there'd be less room for error and the
> compiler can warn us of type safety issues in any configuration.
>
> That and we can delete the comment block immediately above at the same
> time.
>
> Mark.
>
>> 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: Ryan Roberts <ryan.roberts@arm.com>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>> This patch applies on v6.14-rc3
>>
>> arch/arm64/include/asm/pgtable.h | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index 0b2a2ad1b9e8..1da2421c9a15 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -84,8 +84,8 @@ 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)
>> +#define __pte_to_phys(pte) ((phys_addr_t)(pte_val(pte) & PTE_ADDR_LOW))
>> +#define __phys_to_pte_val(phys) ((pteval_t)(phys))
>> #endif
>>
>> #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT)
>> --
>> 2.25.1
>>
>>
next prev parent reply other threads:[~2025-02-25 13:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 3:56 Anshuman Khandual
2025-02-25 12:32 ` Mark Rutland
2025-02-25 13:00 ` Ryan Roberts [this message]
2025-02-25 13:52 ` Mark Rutland
2025-02-26 11:45 ` Anshuman Khandual
2025-02-26 12:19 ` Ryan Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e1721a1-54a4-4007-a0f5-d651f5f21ae2@arm.com \
--to=ryan.roberts@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®