Skip to content

Commit c86fa34

Browse files
committed
arm64: mm: Add confidential computing hook to ioremap_prot()
Confidential Computing environments such as pKVM and Arm's CCA distinguish between shared (i.e. emulated) and private (i.e. assigned) MMIO regions. Introduce a hook into our implementation of ioremap_prot() so that MMIO regions can be shared if necessary. Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Steven Price <[email protected]> Acked-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent ebc59b1 commit c86fa34

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

arch/arm64/include/asm/io.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ __iowrite64_copy(void __iomem *to, const void *from, size_t count)
271271
* I/O memory mapping functions.
272272
*/
273273

274+
typedef int (*ioremap_prot_hook_t)(phys_addr_t phys_addr, size_t size,
275+
pgprot_t *prot);
276+
int arm64_ioremap_prot_hook_register(const ioremap_prot_hook_t hook);
277+
274278
#define ioremap_prot ioremap_prot
275279

276280
#define _PAGE_IOREMAP PROT_DEVICE_nGnRE

arch/arm64/mm/ioremap.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
#include <linux/mm.h>
44
#include <linux/io.h>
55

6+
static ioremap_prot_hook_t ioremap_prot_hook;
7+
8+
int arm64_ioremap_prot_hook_register(ioremap_prot_hook_t hook)
9+
{
10+
if (WARN_ON(ioremap_prot_hook))
11+
return -EBUSY;
12+
13+
ioremap_prot_hook = hook;
14+
return 0;
15+
}
16+
617
void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
718
unsigned long prot)
819
{
920
unsigned long last_addr = phys_addr + size - 1;
21+
pgprot_t pgprot = __pgprot(prot);
1022

1123
/* Don't allow outside PHYS_MASK */
1224
if (last_addr & ~PHYS_MASK)
@@ -16,7 +28,16 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
1628
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
1729
return NULL;
1830

19-
return generic_ioremap_prot(phys_addr, size, __pgprot(prot));
31+
/*
32+
* If a hook is registered (e.g. for confidential computing
33+
* purposes), call that now and barf if it fails.
34+
*/
35+
if (unlikely(ioremap_prot_hook) &&
36+
WARN_ON(ioremap_prot_hook(phys_addr, size, &pgprot))) {
37+
return NULL;
38+
}
39+
40+
return generic_ioremap_prot(phys_addr, size, pgprot);
2041
}
2142
EXPORT_SYMBOL(ioremap_prot);
2243

0 commit comments

Comments
 (0)