From: Mark Rutland <mark.rutland@arm.com>
To: Miles Chen <miles.chen@mediatek.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
wsd_upstream@mediatek.com
Subject: Re: [PATCH] arm64: trap illegal translations in __virt_to_phys()
Date: Mon, 7 Jan 2019 15:00:19 +0000 [thread overview]
Message-ID: <20190107150019.GC46743@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com>
On Mon, Jan 07, 2019 at 07:21:20PM +0800, Miles Chen wrote:
> Current __virt_to_phys() only print warning messages for non-linear
> addresses. It's hard to catch all warnings by those messages.
Why? Are you seeing a large number of warnings somewhere?
> So add a VIRTUAL_BUG_ON() to trap all non-linear and non-symbol
> addresses (e.g., stack addresses)
>
> Tested by pass stack addresses and symbol addresses to __pa(). Result:
> stack addresses: kernel BUG()
Either:
* Stacks are vmap'd, and __is_lm_address(stack_addr) is false. We'll
produce a WARNING() today (and return a junk physical address).
* Stacks are linear mapped, and cannot be distinguished from other
linear mapped addresses. The physical address will be valid.
... so I don't understand why you need to change this.
> symbol addresses: kernel warning message
That should already be the case today, since the kernel image is mapped
separately from the linear map, so __is_lm_address(symbol_addr) should
be false.
>
> Maybe we should trap all non-linear address translations in the future.
>
> Signed-off-by: Miles Chen <miles.chen@mediatek.com>
> ---
> arch/arm64/mm/physaddr.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c
> index 67a9ba9eaa96..f6b935dad19c 100644
> --- a/arch/arm64/mm/physaddr.c
> +++ b/arch/arm64/mm/physaddr.c
> @@ -14,6 +14,11 @@ phys_addr_t __virt_to_phys(unsigned long x)
> (void *)x,
> (void *)x);
>
> + /* trap all non-linear and non-symbol addresses */
> + VIRTUAL_BUG_ON(!__is_lm_address(x) &&
> + (x < (unsigned long)KERNEL_START ||
> + x > (unsigned long)KERNEL_END));
The KERNEL_START and KERNEL_END definitions refer to the kernel image,
not the linear map, so it doesn't make any sense to permit those here.
It is *not* valid to call __virt_to_phys() with a symbol address. We
only support those in __virt_to_phys_nodebug() so that broken code has a
chance of stumbling on.
If you want the kernel to die immediately when it hits a warning here,
please set panic_on_warn.
Thanks,
Mark.
next prev parent reply other threads:[~2019-01-07 15:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 11:21 [PATCH] arm64: trap illegal translations in __virt_to_phys() Miles Chen
2019-01-07 15:00 ` Mark Rutland [this message]
2019-01-08 3:24 ` Miles Chen
2019-01-08 12:14 ` Mark Rutland
2019-01-09 1:35 ` Miles Chen
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=20190107150019.GC46743@lakrids.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=miles.chen@mediatek.com \
--cc=will.deacon@arm.com \
--cc=wsd_upstream@mediatek.com \
/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