From: Thomas Huth <thuth@redhat.com>
To: Christoph Hellwig <hch@lst.de>, Arnd Bergmann <arnd@arndb.de>
Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-snps-arc@lists.infradead.org,
linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org,
linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev,
linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
sparclinux@vger.kernel.org, linux-um@lists.infradead.org,
linux-arch@vger.kernel.org
Subject: Re: [PATCH 2/2] asm-generic: add an optional pfn_valid check to pfn_valid
Date: Tue, 15 Oct 2024 07:44:22 +0200 [thread overview]
Message-ID: <c5c5f85b-06aa-46c1-8a2f-439ae5e90f11@redhat.com> (raw)
In-Reply-To: <20241014144506.51754-3-hch@lst.de>
On 14/10/2024 16.44, Christoph Hellwig wrote:
> page_to_pfn is usually implemented by pointer arithmetics on the memory
> map, which means that bogus input can lead to even more bogus output.
>
> Powerpc had a pfn_valid check on the regult to it's page_to_phys
s/regult/result/
> implementation when CONFIG_DEBUG_VIRTUAL is defined, which seems
> generally useful, so add that to the generic version.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> include/asm-generic/memory_model.h | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h
> index a73a140cbecdd7..6d1fb6162ac1a6 100644
> --- a/include/asm-generic/memory_model.h
> +++ b/include/asm-generic/memory_model.h
> @@ -64,7 +64,17 @@ static inline int pfn_valid(unsigned long pfn)
> #define page_to_pfn __page_to_pfn
> #define pfn_to_page __pfn_to_page
>
> +#ifdef CONFIG_DEBUG_VIRTUAL
> +#define page_to_phys(page) \
> +({ \
> + unsigned long __pfn = page_to_pfn(page); \
> + \
> + WARN_ON_ONCE(!pfn_valid(__pfn)); \
> + PFN_PHYS(__pfn); \
> +})
> +#else
> #define page_to_phys(page) PFN_PHYS(page_to_pfn(page))
> +#endif /* CONFIG_DEBUG_VIRTUAL */
> #define phys_to_page(phys) pfn_to_page(PHYS_PFN(phys))
>
> #endif /* __ASSEMBLY__ */
With the typo fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>
prev parent reply other threads:[~2024-10-15 5:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 14:44 provide generic page_to_phys and phys_to_page implementations v2 Christoph Hellwig
2024-10-14 14:44 ` [PATCH 1/2] asm-generic: provide generic page_to_phys and phys_to_page implementations Christoph Hellwig
2024-10-14 14:44 ` [PATCH 2/2] asm-generic: add an optional pfn_valid check to pfn_valid Christoph Hellwig
2024-10-15 5:44 ` Thomas Huth [this message]
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=c5c5f85b-06aa-46c1-8a2f-439ae5e90f11@redhat.com \
--to=thuth@redhat.com \
--cc=arnd@arndb.de \
--cc=hch@lst.de \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-um@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=sparclinux@vger.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;
as well as URLs for NNTP newsgroup(s).