[RFC kvm-unit-tests 05/27] arm: Introduce NS_SHARED PTE attribute
Joey Gouly
joey.gouly at arm.com
Fri Jan 27 03:40:46 PST 2023
Introduce a new attribute to indicate the mapping is "Shared" with the
host. This will be used by the Realms to share pages with the Host.
For normal VMs, this is always 0.
For realms, this is dynamic, depending on the IPA width. The top bit of the
IPA is "treated" as the "NS_SHARED" attribute, making the VM access the
unprotected alias of the IPA.
By default, apply the NS_SHARED attribute for all I/O.
Signed-off-by: Joey Gouly <joey.gouly at arm.com>
---
lib/arm/mmu.c | 5 ++++-
lib/arm64/asm/pgtable.h | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index acaf5614..6f1f42f5 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -22,6 +22,8 @@
pgd_t *mmu_idmap;
+/* Used by Realms, depends on IPA size */
+unsigned long prot_ns_shared = 0;
unsigned long phys_mask_shift = 48;
/* CPU 0 starts with disabled MMU */
@@ -194,7 +196,8 @@ void __iomem *__ioremap(phys_addr_t phys_addr, size_t size)
{
phys_addr_t paddr_aligned = phys_addr & PAGE_MASK;
phys_addr_t paddr_end = PAGE_ALIGN(phys_addr + size);
- pgprot_t prot = __pgprot(PTE_UNCACHED | PTE_USER | PTE_UXN | PTE_PXN);
+ pgprot_t prot = __pgprot(PTE_UNCACHED | PTE_USER | PTE_UXN |
+ PTE_PXN | PTE_NS_SHARED);
pgd_t *pgtable;
assert(sizeof(long) == 8 || !(phys_addr >> 32));
diff --git a/lib/arm64/asm/pgtable.h b/lib/arm64/asm/pgtable.h
index 22ce64f0..5b9f40b0 100644
--- a/lib/arm64/asm/pgtable.h
+++ b/lib/arm64/asm/pgtable.h
@@ -22,6 +22,12 @@
#include <linux/compiler.h>
extern unsigned long prot_ns_shared;
+/*
+ * The Non-secure shared bit for Realms is actually part of the output
+ * address, however it is modeled as a PTE attribute.
+*/
+#define PTE_NS_SHARED (prot_ns_shared)
+
/*
* Highest possible physical address supported.
*/
--
2.17.1
More information about the linux-arm-kernel
mailing list