mirror of
https://github.com/torvalds/linux.git
synced 2025-04-12 06:49:52 +00:00

ioremap_prot() currently accepts pgprot_val parameter as an unsigned long, thus implicitly assuming that pgprot_val and pgprot_t could never be bigger than unsigned long. But this assumption soon will not be true on arm64 when using D128 pgtables. In 128 bit page table configuration, unsigned long is 64 bit, but pgprot_t is 128 bit. Passing platform abstracted pgprot_t argument is better as compared to size based data types. Let's change the parameter to directly pass pgprot_t like another similar helper generic_ioremap_prot(). Without this change in place, D128 configuration does not work on arm64 as the top 64 bits gets silently stripped when passing the protection value to this function. Link: https://lkml.kernel.org/r/20250218101954.415331-1-anshuman.khandual@arm.com Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Co-developed-by: Anshuman Khandual <anshuman.khandual@arm.com> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> [arm64] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/io.h>
|
|
|
|
static ioremap_prot_hook_t ioremap_prot_hook;
|
|
|
|
int arm64_ioremap_prot_hook_register(ioremap_prot_hook_t hook)
|
|
{
|
|
if (WARN_ON(ioremap_prot_hook))
|
|
return -EBUSY;
|
|
|
|
ioremap_prot_hook = hook;
|
|
return 0;
|
|
}
|
|
|
|
void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
|
|
pgprot_t pgprot)
|
|
{
|
|
unsigned long last_addr = phys_addr + size - 1;
|
|
|
|
/* Don't allow outside PHYS_MASK */
|
|
if (last_addr & ~PHYS_MASK)
|
|
return NULL;
|
|
|
|
/* Don't allow RAM to be mapped. */
|
|
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
|
|
return NULL;
|
|
|
|
/*
|
|
* If a hook is registered (e.g. for confidential computing
|
|
* purposes), call that now and barf if it fails.
|
|
*/
|
|
if (unlikely(ioremap_prot_hook) &&
|
|
WARN_ON(ioremap_prot_hook(phys_addr, size, &pgprot))) {
|
|
return NULL;
|
|
}
|
|
|
|
return generic_ioremap_prot(phys_addr, size, pgprot);
|
|
}
|
|
EXPORT_SYMBOL(ioremap_prot);
|
|
|
|
/*
|
|
* Must be called after early_fixmap_init
|
|
*/
|
|
void __init early_ioremap_init(void)
|
|
{
|
|
early_ioremap_setup();
|
|
}
|
|
|
|
bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
|
|
unsigned long flags)
|
|
{
|
|
unsigned long pfn = PHYS_PFN(offset);
|
|
|
|
return pfn_is_map_memory(pfn);
|
|
}
|