Re: [PATCH v3 1/2] x86/ioremap: fix the pfn calculation mistake in __ioremap_check_ram()
From: Yaohui Wang
Date: Sun Jul 04 2021 - 22:11:37 EST
On 2021/7/2 22:49, Dave Hansen wrote:
Do you know why this check:
if ((res->flags & IORESOURCE_SYSTEM_RAM) != IORESOURCE_SYSTEM_RAM)
return false;
did not catch your out-of-tree driver's errant ioremap()?
If ioremap() is invoked on an area that contains normal memory, then:
(res->flags & IORESOURCE_SYSTEM_RAM) == IORESOURCE_SYSTEM_RAM)
is true, so the original check is false. The code following the check
will continue to scan whether this area contains any page that is not
PageReserved (i.e. that is truly normal RAM).
Your idea should be:
if ((res->flags & IORESOURCE_SYSTEM_RAM) == IORESOURCE_SYSTEM_RAM)
return IORES_MAP_SYSTEM_RAM;
But this check is too strict as IORESOURCE_SYSTEM_RAM area may contain
PageReserved pages, and PageReserved pages should be ioremap-able. So
the checking logic of the original __ioremap_check_ram() function is
reasonable.