From: Catalin Marinas <catalin.marinas@arm.com>
To: Ard Biesheuvel <ardb+git@google.com>
Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org,
Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH] arm64/mm: Sanity check PTE address before runtime P4D/PUD folding
Date: Mon, 4 Nov 2024 13:50:09 +0000 [thread overview]
Message-ID: <ZyjREXyABoQtkV8O@arm.com> (raw)
In-Reply-To: <20241101155800.3917462-2-ardb+git@google.com>
On Fri, Nov 01, 2024 at 04:58:01PM +0100, Ard Biesheuvel wrote:
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index dd5dcf7ae056..0d729adf894c 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -740,6 +740,11 @@ static inline bool pud_table(pud_t pud) { return true; }
> PUD_TYPE_TABLE)
> #endif
>
> +static inline long sign_of(unsigned long addr)
> +{
> + return (int)(addr >> 24) >> 31L; // bit 55 is the sign bit
> +}
That's a pretty generic name that trickles into the core code. It should
be renamed to something that suggests arm64 addresses (and maybe some
underscores to imply private). Also, this assumes untagged addresses but
I haven't checked whether that's the case for all call sites.
> extern pgd_t init_pg_dir[];
> extern pgd_t init_pg_end[];
> extern pgd_t swapper_pg_dir[];
> @@ -932,6 +937,8 @@ static inline phys_addr_t p4d_page_paddr(p4d_t p4d)
>
> static inline pud_t *p4d_to_folded_pud(p4d_t *p4dp, unsigned long addr)
> {
> + VM_BUG_ON(((u64)p4dp / sizeof(p4d_t) - sign_of(addr)) % PTRS_PER_P4D);
> +
> return (pud_t *)PTR_ALIGN_DOWN(p4dp, PAGE_SIZE) + pud_index(addr);
> }
I think I get it but please add a comment in the code, otherwise in a
week time I'll wonder what this is.
Even better if it could be written in a less cryptic way ;).
--
Catalin
next prev parent reply other threads:[~2024-11-04 14:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 15:58 [PATCH] arm64/mm: Sanity check PTE address before runtime P4D/PUD folding Ard Biesheuvel
2024-11-04 13:50 ` Catalin Marinas [this message]
2024-11-04 13:57 ` Ard Biesheuvel
2024-11-04 16:02 ` Catalin Marinas
2024-11-04 16:43 ` Ard Biesheuvel
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=ZyjREXyABoQtkV8O@arm.com \
--to=catalin.marinas@arm.com \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.