ANDROID: mm/vmalloc: Add arch-specific callbacks to track io{remap,unmap} physical pages

Add a pair of hooks (ioremap_phys_range_hook/iounmap_phys_range_hook)
that can be implemented by an architecture. Contrary to the existing
arch_sync_kernel_mappings(), this one tracks things at the physical
address level.

This is specially useful in these virtualised environments where
the guest has to tell the host whether (and how) it intends to use
a MMIO device.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Bug: 233587962
Change-Id: I970c2e632cb2b01060d5e66e4194fa9248188f43
Signed-off-by: Will Deacon <willdeacon@google.com>
This commit is contained in:
Marc Zyngier
2021-06-30 13:24:32 +01:00
committed by Will Deacon
parent 9f78e5888d
commit d7ddd989d6
3 changed files with 18 additions and 1 deletions

View File

@@ -38,6 +38,7 @@
#include <linux/pgtable.h>
#include <linux/uaccess.h>
#include <linux/hugetlb.h>
#include <linux/io.h>
#include <asm/tlbflush.h>
#include <asm/shmparam.h>
@@ -316,9 +317,14 @@ int ioremap_page_range(unsigned long addr, unsigned long end,
{
int err;
err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot),
prot = pgprot_nx(prot);
err = vmap_range_noflush(addr, end, phys_addr, prot,
ioremap_max_page_shift);
flush_cache_vmap(addr, end);
if (IS_ENABLED(CONFIG_ARCH_HAS_IOREMAP_PHYS_HOOKS) && !err)
ioremap_phys_range_hook(phys_addr, end - addr, prot);
return err;
}
@@ -2628,6 +2634,10 @@ static void __vunmap(const void *addr, int deallocate_pages)
kasan_poison_vmalloc(area->addr, get_vm_area_size(area));
if (IS_ENABLED(CONFIG_ARCH_HAS_IOREMAP_PHYS_HOOKS) &&
area->flags & VM_IOREMAP)
iounmap_phys_range_hook(area->phys_addr, get_vm_area_size(area));
vm_remove_mappings(area, deallocate_pages);
if (deallocate_pages) {