ANDROID: arm64: Allow non granule aligned MMIO guard requests

When using protected VMs with MMIO guard, the hypervisor expects the MMIO
ranges to be specified from the running guests. This informs the
hypervisor that only the traps executed within the specified range to
be forwarded to the host. If the guest mismatches the hypervisor page
size, it will fail the MMIO guard enrollment silently and the MMIO
accesses will result in synchronous external aborts injected in the
guest. This however, doesn't happen in the case of non-protected VMs
where we don't have the MMIO guard.
The RAM regions being aligned with the granule size, we can safely
over-guard using this same alignment.
To allow protected VMs to install the guard successully, align the
requested size to the hypervisor granule size.

Bug: 348888423
Bug: 333730505
Bug: 278749606
Change-Id: I6722f7d4388bac5498b9cd54ea68f77046048ba7
Signed-off-by: Sebastian Ene <sebastianene@google.com>
This commit is contained in:
Sebastian Ene 2024-07-10 12:12:23 +00:00
parent bc028c905a
commit b0acaed287

View File

@ -267,6 +267,9 @@ void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size, pgprot_t prot)
VM_BUG_ON(!PAGE_ALIGNED(phys_addr) || !PAGE_ALIGNED(size));
size = ALIGN(size, guard_granule);
phys_addr = ALIGN_DOWN(phys_addr, guard_granule);
mutex_lock(&ioremap_guard_lock);
mas_lock(&mas);
@ -311,6 +314,9 @@ void iounmap_phys_range_hook(phys_addr_t phys_addr, size_t size)
VM_BUG_ON(!PAGE_ALIGNED(phys_addr) || !PAGE_ALIGNED(size));
size = ALIGN(size, guard_granule);
phys_addr = ALIGN_DOWN(phys_addr, guard_granule);
mutex_lock(&ioremap_guard_lock);
mas_lock(&mas);