[PATCH 2/2] arm64: Use simpler arithmetics for the linear map macros

Ard Biesheuvel ardb at kernel.org
Mon Feb 1 18:05:10 EST 2021


On Mon, 1 Feb 2021 at 20:06, Catalin Marinas <catalin.marinas at arm.com> wrote:
>
> Because of the tagged addresses, the __is_lm_address() and
> __lm_to_phys() macros grew to some harder to understand bitwise
> operations using PAGE_OFFSET. Since these macros only accept untagged
> addresses, use a simple subtract operation.
>
> Signed-off-by: Catalin Marinas <catalin.marinas at arm.com>
> Cc: Will Deacon <will at kernel.org>
> Cc: Ard Biesheuvel <ardb at kernel.org>
> Cc: Mark Rutland <mark.rutland at arm.com>
> ---
>  arch/arm64/include/asm/memory.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
> index 3c1aaa522cbd..ff4732785c32 100644
> --- a/arch/arm64/include/asm/memory.h
> +++ b/arch/arm64/include/asm/memory.h
> @@ -251,9 +251,9 @@ static inline const void *__tag_set(const void *addr, u8 tag)
>   * lives in the [PAGE_OFFSET, PAGE_END) interval at the bottom of the
>   * kernel's TTBR1 address range.
>   */
> -#define __is_lm_address(addr)  (((u64)(addr) ^ PAGE_OFFSET) < (PAGE_END - PAGE_OFFSET))
> +#define __is_lm_address(addr)  (((u64)(addr) - PAGE_OFFSET) < (PAGE_END - PAGE_OFFSET))
>

Why still subtract PAGE_OFFSET on both sides of the comparison here?

> -#define __lm_to_phys(addr)     (((addr) & ~PAGE_OFFSET) + PHYS_OFFSET)
> +#define __lm_to_phys(addr)     (((addr) - PAGE_OFFSET) + PHYS_OFFSET)
>  #define __kimg_to_phys(addr)   ((addr) - kimage_voffset)
>
>  #define __virt_to_phys_nodebug(x) ({                                   \



More information about the linux-arm-kernel mailing list