xen/arm: Add Armv8-R64 MPU support to Xen - Part#1
Re: [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system
In reply to Ayan Kumar HalderHi Ayan
Quoted 53 lines · Ayan Kumar Halder
Hi Penny,
Quoted 39 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Xen is using page as the smallest granularity for memory managment. And we want to follow the same concept in MPU system.
That is, structurepage_infoand the frametable which is used for storing and managing the smallest memory managment unit is also required in MPU system.In MPU system, since we can not use a fixed VA
address(FRAMETABLE_VIRT_START)to map frametable like MMU system does and everything is 1:1 mapping, we instead define a variable "structpage_info*frame_table" as frametable pointer, and ask boot allocator to allocate appropriate memory for frametable.As frametable is successfully initialized, the convertion between machine frame number/machine address/"virtual address" and page-info structure is ready too, like mfn_to_page/maddr_to_page/virt_to_page, etc
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- addASSERT()to confirm the MFN you pass is covered by the frametable.
---
xen/arch/arm/include/asm/mm.h | 14 ++++++++++++++xen/arch/arm/include/asm/mpu/mm.h| 3 +++ xen/arch/arm/mpu/mm.c | 27 +++++++++++++++++++++++++++3 files changed, 44 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -341,6 +341,19 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa, #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) +#ifdef CONFIG_HAS_MPU +/* Convert between virtual address to page-info structure. */ xen/arch/arm/include/asm/mm.h static inline uint64_t gvirt_to_maddr(vaddr_t va, · line 356
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+static inline struct page_info *virt_to_page (const void *v) +{ + unsigned long pdx; + + pdx = paddr_to_pdx(virt_to_maddr(v)); + ASSERT(pdx >= frametable_base_pdx); + ASSERT(pdx < frametable_pdx_end); + + return frame_table + pdx - frametable_base_pdx; +}This should go in
xen/arch/arm/include/asm/mpu/mm.h. Then you don't need ifdef
Quoted 10 lines
xen/arch/arm/include/asm/mm.h static inline struct page_info *virt_to_page(const · line 370
Quoted 9 lines
xen/arch/arm/include/asm/mm.h +1
-0+#else /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v){
xen/arch/arm/include/asm/mm.h +0
-0@@ -354,6 +367,7 @@ static inline struct page_info *virt_to_page(const void *v) pdx += mfn_to_pdx(directmap_mfn_start); return frame_table + pdx - frametable_base_pdx; }Consequently, this should be in
xen/arch/arm/include/asm/mmu/mm.h
The reason why I don't put virt_to_page()/page_to_virt() in specific header is that we are using some helpers, which are defined just a few lines before, like mfn_to_virt(), etc.
If you are moving mfn_to_virt() to specific header too, that will
result in a lot dulplication.
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/include/asm/mm.h +1
-0+#endif static inline void *page_to_virt(const struct page_info *pg){
xen/arch/arm/include/asm/mpu/mm.h +0
-0@@ -2,6 +2,9 @@ #ifndef __ARCH_ARM_MM_MPU__ #define __ARCH_ARM_MM_MPU__
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 5
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern struct page_info *frame_table;If you define
frame_tableinxen/arch/arm/include/asm/mm.h, then you don't need the above declaration.
It is a variable only in MPU. In MMU, it is a fixed value. "#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)"
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 6
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern unsigned long frametable_pdx_end;Also you don't need extern as this is only used by
xen/arch/arm/mpu/mm.c.
sure.
Quoted 46 lines
xen/arch/arm/include/asm/mpu/mm.h line 8
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h +1
-0+ extern int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags);You don't need extern here as it should be used only in
xen/arch/arm/mpu/mm.cCurrently, I see the following in
xen/arch/arm/mm.c,int map_pages_to_xen(unsigned long virt,
mfn_tmfn,
unsigned longnr_mfns,
unsigned int flags)
{
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(virt, mfn, nr_mfns, flags);
#else
returnxen_mpumap_update(mfn_to_maddr(mfn), mfn_to_maddr(mfn_add(mfn, nr_mfns)), flags);
#endif
}int
destroy_xen_mappings(unsigned long s, unsigned long e){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0);
#else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), 0);
#endif
}int
modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));
ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags);
#else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), flags);
#endif
}
Quoted 2 lines
It would be better to have 2 implementations for
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()inxen/arch/arm/mpu/mm.candxen/arch/arm/mmu/mm.c.
I prefer them staying in the common file, using #ifdef to go to the different path.
Since if not and when anyone wants to update map_pages_to_xen(), destroy_xen_mappings() and modify_xen_mappings() in the future, it is possible for them to leave changes in only one file.
Quoted 58 lines
xen/arch/arm/mpu/mm.c line 31
Quoted 12 lines
xen/arch/arm/include/asm/mpu/mm.h +0
-0extern void setup_staticheap_mappings(void);xen/arch/arm/mpu/mm.c +2
-0@@ -27,6 +27,10 @@ #include <asm/page.h> #include <asm/setup.h> +/* Override macros from asm/mm.h to make them work with mfn_t */ +#undef mfn_to_virtWhy do we have to do this ?
Quoted 44 lines
xen/arch/arm/mpu/mm.c +25
-0+#define mfn_to_virt (mfn) __mfn_to_virt(mfn_x(mfn)) + #ifdef NDEBUG static inline void __attribute__ ((__format__ (__printf__, 1, 2))) region_printk(const char *fmt, ...) {}@@ -58,6 +62,9 @@ static DEFINE_SPINLOCK(xen_mpumap_lock); static DEFINE_SPINLOCK(xen_mpumap_alloc_lock); +struct page_info *frame_table; +unsigned long frametable_pdx_end__read_mostly ; + /* Write a MPU protection region */ #define WRITE_PROTECTION_REGION(pr, prbar_el2, prlar_el2) ({ \ const pr_t *_pr = pr; \@@ -513,6 +520,26 @@ void __init setup_staticheap_mappings(void) } } +/* Map a frame table to cover physical addresses ps through pe */ +void __init setup_frametable_mappings (paddr_t ps,paddr_t pe) +{ + mfn_t base_mfn; + unsigned long nr_pdxs = mfn_to_pdx(mfn_add(maddr_to_mfn(pe), -1)) - + mfn_to_pdx(maddr_to_mfn(ps)) + 1; + unsigned long frametable_size = nr_pdxs * sizeof(struct page_info); + + frametable_base_pdx = paddr_to_pdx(ps); + frametable_size = ROUNDUP(frametable_size, PAGE_SIZE); + frametable_pdx_end = frametable_base_pdx + nr_pdxs; + + base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 1); + frame_table = (struct page_info *)mfn_to_virt(base_mfn); + + memset(&frame_table[0], 0, nr_pdxs * sizeof(struct page_info)); + memset(&frame_table[nr_pdxs], -1, + frametable_size - (nr_pdxs * sizeof(struct page_info))); +} + /** Local variables: * mode: C Signature · 1 line
2.25.1- Ayan
Re: [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system
Hi,
Quoted 85 lines · Penny Zheng
Quoted 53 lines · Ayan Kumar Halder
Hi Penny,
Quoted 39 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Xen is using page as the smallest granularity for memory managment. And we want to follow the same concept in MPU system.
That is, structurepage_infoand the frametable which is used for storing and managing the smallest memory managment unit is also required in MPU system.In MPU system, since we can not use a fixed VA
address(FRAMETABLE_VIRT_START)to map frametable like MMU system does and everything is 1:1 mapping, we instead define a variable "structpage_info*frame_table" as frametable pointer, and ask boot allocator to allocate appropriate memory for frametable.As frametable is successfully initialized, the convertion between machine frame number/machine address/"virtual address" and page-info structure is ready too, like mfn_to_page/maddr_to_page/virt_to_page, etc
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- addASSERT()to confirm the MFN you pass is covered by the frametable.
---
xen/arch/arm/include/asm/mm.h | 14 ++++++++++++++xen/arch/arm/include/asm/mpu/mm.h| 3 +++ xen/arch/arm/mpu/mm.c | 27 +++++++++++++++++++++++++++3 files changed, 44 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -341,6 +341,19 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa, #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) +#ifdef CONFIG_HAS_MPU +/* Convert between virtual address to page-info structure. */ xen/arch/arm/include/asm/mm.h static inline uint64_t gvirt_to_maddr(vaddr_t · line 356
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+static inline struct page_info *virt_to_page (const void *v) +{ + unsigned long pdx; + + pdx = paddr_to_pdx(virt_to_maddr(v)); + ASSERT(pdx >= frametable_base_pdx); + ASSERT(pdx < frametable_pdx_end); + + return frame_table + pdx - frametable_base_pdx; +}This should go in
xen/arch/arm/include/asm/mpu/mm.h. Then you don't need ifdefQuoted 10 lines
xen/arch/arm/include/asm/mm.h static inline struct page_info · line 370
Quoted 9 lines
xen/arch/arm/include/asm/mm.h +1
-0+#else /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v){
xen/arch/arm/include/asm/mm.h +0
-0@@ -354,6 +367,7 @@ static inline struct page_info *virt_to_page(const void *v) pdx += mfn_to_pdx(directmap_mfn_start); return frame_table + pdx - frametable_base_pdx; }Consequently, this should be in
xen/arch/arm/include/asm/mmu/mm.hThe reason why I don't put virt_to_page()/page_to_virt() in specific header is that we are using some helpers, which are defined just a few lines before, like
mfn_to_virt(), etc.
If you are movingmfn_to_virt()to specific header too, that will
result in a lot dulplication.Quoted 12 lines
Quoted 12 lines
xen/arch/arm/include/asm/mm.h +1
-0+#endif static inline void *page_to_virt(const struct page_info *pg){
xen/arch/arm/include/asm/mpu/mm.h +0
-0@@ -2,6 +2,9 @@ #ifndef __ARCH_ARM_MM_MPU__ #define __ARCH_ARM_MM_MPU__Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 5
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern struct page_info *frame_table;If you define
frame_tableinxen/arch/arm/include/asm/mm.h, then you don't need the above declaration.
Quoted 25 lines
It is a variable only in MPU. In MMU, it is a fixed value. "#define
frame_table((structpage_info*)FRAMETABLE_VIRT_START)"Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 6
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern unsigned long frametable_pdx_end;Also you don't need extern as this is only used by
xen/arch/arm/mpu/mm.c.sure.
Quoted 17 lines
xen/arch/arm/include/asm/mpu/mm.h line 8
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h +1
-0+ extern int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags);You don't need extern here as it should be used only in
xen/arch/arm/mpu/mm.cCurrently, I see the following in
xen/arch/arm/mm.c,int map_pages_to_xen(unsigned long virt,
mfn_tmfn,
unsigned longnr_mfns,
unsigned int flags)
{
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(virt, mfn, nr_mfns, flags); #else
return xen_mpumap_update(mfn_to_maddr(mfn),mfn_to_maddr(mfn_add(mfn, nr_mfns)),
You are ignoring 'virt' here. Shouldn't you at least check that 'virt == mfn_to_maddr(mfn)'?
Quoted 30 lines
Quoted 30 lines
flags);
#endif
}int
destroy_xen_mappings(unsigned long s, unsigned long e){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0); #else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), 0); #endif
}int
modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));
ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); #else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), flags); #endif
}
Quoted 5 lines
Quoted 2 lines
It would be better to have 2 implementations for
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()inxen/arch/arm/mpu/mm.candxen/arch/arm/mmu/mm.c.I prefer them staying in the common file, using #ifdef to go to the different path.
I don't like the #ifdef solution in this situation. You are only doing it for the benefits of the ASSERT(). But they don't seem to have any value for xen_mpumap_update() (you are still passing an address rather than a frame).
Quoted 1 line
Since if not and when anyone wants to update
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()in the future, it is possible for them to leave changes in only one file.
The helpers are just wrappers. I doubt they will change in the future. So I think it would be OK to duplicate.
The alternative would to have a common prototype for xen_pt_update() and xen_mpumap_update() and avoid any #ifdery. That said, this is not my preference at least if they are not static inline.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system
Hi,
Quoted 114 lines · Julien Grall
Hi,
Quoted 86 lines · Penny Zheng
Quoted 54 lines · Ayan Kumar Halder
Hi Penny,
Quoted 40 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Xen is using page as the smallest granularity for memory managment. And we want to follow the same concept in MPU system.
That is, structurepage_infoand the frametable which is used for storing and managing the smallest memory managment unit is also required in MPU system.In MPU system, since we can not use a fixed VA
address(FRAMETABLE_VIRT_START)to map frametable like MMU system does and everything is 1:1 mapping, we instead define a variable "structpage_info*frame_table" as frametable pointer, and ask boot allocator to allocate appropriate memory for frametable.As frametable is successfully initialized, the convertion between machine frame number/machine address/"virtual address" and page-info structure is ready too, like mfn_to_page/maddr_to_page/virt_to_page, etc
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- addASSERT()to confirm the MFN you pass is covered by the frametable.
---
xen/arch/arm/include/asm/mm.h | 14 ++++++++++++++xen/arch/arm/include/asm/mpu/mm.h| 3 +++ xen/arch/arm/mpu/mm.c | 27 +++++++++++++++++++++++++++3 files changed, 44 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -341,6 +341,19 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa, #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) +#ifdef CONFIG_HAS_MPU +/* Convert between virtual address to page-info structure. */ xen/arch/arm/include/asm/mm.h static inline uint64_t gvirt_to_maddr(vaddr_t · line 356
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+static inline struct page_info *virt_to_page (const void *v) +{ + unsigned long pdx; + + pdx = paddr_to_pdx(virt_to_maddr(v)); + ASSERT(pdx >= frametable_base_pdx); + ASSERT(pdx < frametable_pdx_end); + + return frame_table + pdx - frametable_base_pdx; +}This should go in
xen/arch/arm/include/asm/mpu/mm.h. Then you don't need ifdefQuoted 10 lines
xen/arch/arm/include/asm/mm.h static inline struct page_info · line 370
Quoted 9 lines
xen/arch/arm/include/asm/mm.h +1
-0+#else /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v){
xen/arch/arm/include/asm/mm.h +0
-0@@ -354,6 +367,7 @@ static inline struct page_info *virt_to_page(const void *v) pdx += mfn_to_pdx(directmap_mfn_start); return frame_table + pdx - frametable_base_pdx; }Consequently, this should be in
xen/arch/arm/include/asm/mmu/mm.hThe reason why I don't put virt_to_page()/page_to_virt() in specific header is that we are using some helpers, which are defined just a few lines before, like
mfn_to_virt(), etc.
If you are movingmfn_to_virt()to specific header too, that will
result in a lot dulplication.Quoted 12 lines
Quoted 12 lines
xen/arch/arm/include/asm/mm.h +1
-0+#endif static inline void *page_to_virt(const struct page_info *pg){
xen/arch/arm/include/asm/mpu/mm.h +0
-0@@ -2,6 +2,9 @@ #ifndef __ARCH_ARM_MM_MPU__ #define __ARCH_ARM_MM_MPU__Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 5
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern struct page_info *frame_table;If you define
frame_tableinxen/arch/arm/include/asm/mm.h, then you don't need the above declaration.Quoted 25 lines
It is a variable only in MPU. In MMU, it is a fixed value. "#define
frame_table((structpage_info*)FRAMETABLE_VIRT_START)"Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h line 6
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+extern unsigned long frametable_pdx_end;Also you don't need extern as this is only used by
xen/arch/arm/mpu/mm.c.sure.
Quoted 17 lines
xen/arch/arm/include/asm/mpu/mm.h line 8
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h +1
-0+ extern int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags);You don't need extern here as it should be used only in
xen/arch/arm/mpu/mm.cCurrently, I see the following in
xen/arch/arm/mm.c,int map_pages_to_xen(unsigned long virt,
mfn_tmfn,
unsigned longnr_mfns,
unsigned int flags)
{
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(virt, mfn, nr_mfns, flags); #else
return xen_mpumap_update(mfn_to_maddr(mfn),mfn_to_maddr(mfn_add(mfn, nr_mfns)),
Quoted 2 lines
You are ignoring 'virt' here. Shouldn't you at least check that 'virt ==
mfn_to_maddr(mfn)'?
Sure, I'll do the check.
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
flags);
#endif
}int
destroy_xen_mappings(unsigned long s, unsigned long e){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0); #else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), 0); #endif
}int
modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags){
ASSERT(IS_ALIGNED(s, PAGE_SIZE));
ASSERT(IS_ALIGNED(e, PAGE_SIZE));
ASSERT(s <= e);
#ifndefCONFIG_HAS_MPU
returnxen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); #else
returnxen_mpumap_update(virt_to_maddr((void *)s), virt_to_maddr((void *)e), flags); #endif
}
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
It would be better to have 2 implementations for
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()inxen/arch/arm/mpu/mm.candxen/arch/arm/mmu/mm.c.I prefer them staying in the common file, using #ifdef to go to the different path.
I don't like the #ifdef solution in this situation. You are only doing it for the benefits of the
ASSERT(). But they don't seem to have any value forxen_mpumap_update()(you are still passing an address rather than a frame).
Okay, I will pass a page or a valid mfn next version.
Quoted 6 lines
Quoted 1 line
Since if not and when anyone wants to update
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()in the future, it is possible for them to leave changes in only one file.The helpers are just wrappers. I doubt they will change in the future. So I think it would be OK to duplicate.
The alternative would to have a common prototype for
xen_pt_update()andxen_mpumap_update()and avoid any #ifdery. That said, this is not my preference at least if they are not static inline.
Correct me if I'm wrong, you are suggesting something like this:
A more-generic wrapper like xen_mm_update, and we introduce static inline implementation in mmu/mm.h with xen_pt_update(), and static inline implementation in mpu/mm.h with xen_mpumap_update().
Quoted 2 lines
Cheers,
Re: [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system
Hi,
Quoted 10 lines · Penny Zheng
Quoted 6 lines
Quoted 1 line
Since if not and when anyone wants to update
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()in the future, it is possible for them to leave changes in only one file.The helpers are just wrappers. I doubt they will change in the future. So I think it would be OK to duplicate.
The alternative would to have a common prototype for
xen_pt_update()andxen_mpumap_update()and avoid any #ifdery. That said, this is not my preference at least if they are not static inline.Correct me if I'm wrong, you are suggesting something like this:
A more-generic wrapper likexen_mm_update, and we introduce static inline implementation inmmu/mm.hwithxen_pt_update(), and static inline implementation inmpu/mm.hwithxen_mpumap_update().
Yes as an alternative proposal. But my preference here is to duplicate the helpers in mm-mmu.c and mm-mpu.c.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system
Hi,
Quoted 7 lines · Julien Grall
Hi,
Quoted 4 lines · Penny Zheng
Quoted 4 lines
Quoted 1 line
Since if not and when anyone wants to update
map_pages_to_xen(),destroy_xen_mappings()andmodify_xen_mappings()in the future, it is possible for them to leave changes in only one file.The helpers are just wrappers. I doubt they will change in the future. So I think it would be OK to duplicate.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
The alternative would to have a common prototype for
xen_pt_update()andxen_mpumap_update()and avoid any #ifdery. That said, this is not my preference at least if they are not static inline.Correct me if I'm wrong, you are suggesting something like this:
A more-generic wrapper likexen_mm_update, and we introduce static inline implementation inmmu/mm.hwithxen_pt_update(), and static inline implementation inmpu/mm.hwithxen_mpumap_update().Yes as an alternative proposal. But my preference here is to duplicate the helpers in
mm-mmu.candmm-mpu.c.
Understood, I'll do the duplication.
Quoted 2 lines
Cheers,
PATCH v3 34/52 xen/mpu: destroy an existing entry in Xen MPU memory mapping table
In reply to Penny ZhengThis commit expands xen_mpumap_update/xen_mpumap_update_entry to include destroying an existing entry.
We define a new helper "control_xen_mpumap_region_from_index" to enable/disable the MPU region based on index. If region is within [0, 31], we could quickly disable the MPU region through PRENR_EL2 which provides direct access to the PRLAR_EL2.EN bits of EL2 MPU regions.
Rignt now, we only support destroying a *WHOLE* MPU memory region, part-region removing is not supported, as in worst case, it will leave two fragments behind.
---
v3:
- make pr_get_base()/pr_get_limit() static inline
- need an isb to ensure register write visible before zeroing the entry
--- xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/mm.c | 5 ++ xen/arch/arm/mpu/mm.c | 74 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+)
xen/arch/arm/include/asm/arm64/mpu.h +2 -0
@@ -25,6 +25,8 @@#define REGION_UART_SEL 0x07#define MPUIR_REGION_MASK ((_AC(1, UL) << 8) - 1) +#define MPU_PRENR_BITS 32 +/* Access permission attributes. */ /* Read/Write at EL2, No Access at EL1/EL0. */ #define AP_RW_EL2 0x0
xen/arch/arm/include/asm/arm64/sysregs.h +3 -0
@@ -509,6 +509,9 @@/* MPU Type registers encode */ #define MPUIR_EL2 S3_4_C0_C0_4 +/* MPU Protection Region Enable Register encode */ +#define PRENR_EL2 S3_4_C6_C1_1 +#endif /* Access to system registers */
xen/arch/arm/mm.c +5 -0
@@ -164,7 +164,12 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)ASSERT (IS_ALIGNED (s,PAGE_SIZE ));ASSERT (IS_ALIGNED (e,PAGE_SIZE ));ASSERT (s <= e); +#ifndef CONFIG_HAS_MPU return xen_pt_update (s,INVALID_MFN , (e - s) >>PAGE_SHIFT ,0 ); +#else +return xen_mpumap_update (virt_to_maddr ((void *)s), +virt_to_maddr ((void *)e),0 ); +#endif }int modify_xen_mappings (unsigned long s,unsigned long e,unsigned int flags)
xen/arch/arm/mpu/mm.c +74 -0
86 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 34/52] xen/mpu: destroy an existing entry in Xen MPU memory mapping table
Quoted 33 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
This commit expands xen_mpumap_update/xen_mpumap_update_entry to include destroying an existing entry.
We define a new helper "
control_xen_mpumap_region_from_index" to enable/disable the MPU region based on index. If region is within [0, 31], we could quickly disable the MPU region throughPRENR_EL2which provides direct access to the PRLAR_EL2.EN bits of EL2 MPU regions.Rignt now, we only support destroying a *WHOLE* MPU memory region, part-region removing is not supported, as in worst case, it will leave two fragments behind.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- make pr_get_base()/pr_get_limit() static inline
- need an isb to ensure register write visible before zeroing the entry--- xen/arch/arm/include/asm/arm64/mpu.h | 2 + xen/arch/arm/include/asm/arm64/sysregs.h | 3 + xen/arch/arm/mm.c | 5 ++ xen/arch/arm/mpu/mm.c | 74 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+)xen/arch/arm/include/asm/arm64/mpu.h +0
-0
xen/arch/arm/include/asm/arm64/mpu.h line 28
Quoted 4 lines
xen/arch/arm/include/asm/arm64/mpu.h +1
-0@@ -25,6 +25,8 @@#define REGION_UART_SEL 0x07#define MPUIR_REGION_MASK ((_AC(1, UL) << 8) - 1) +#define MPU_PRENR_BITS 32
This is common to R52 and R82.
Thus, you can put it in the common file (may be xen/arch/arm/include/asm/mpu/mm.h)
Quoted 23 lines
xen/arch/arm/include/asm/arm64/mpu.h +1
-0+/* Access permission attributes. */ /* Read/Write at EL2, No Access at EL1/EL0. */ #define AP_RW_EL2 0x0xen/arch/arm/include/asm/arm64/sysregs.h +3
-0@@ -509,6 +509,9 @@/* MPU Type registers encode */ #define MPUIR_EL2 S3_4_C0_C0_4 +/* MPU Protection Region Enable Register encode */ +#define PRENR_EL2 S3_4_C6_C1_1 +#endif /* Access to system registers */ xen/arch/arm/mm.c +0
-0
xen/arch/arm/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 173
Quoted 10 lines
xen/arch/arm/mm.c +5
-0@@ -164,7 +164,12 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)ASSERT (IS_ALIGNED (s,PAGE_SIZE ));ASSERT (IS_ALIGNED (e,PAGE_SIZE ));ASSERT (s <= e); +#ifndef CONFIG_HAS_MPU return xen_pt_update (s,INVALID_MFN , (e - s) >>PAGE_SHIFT ,0 ); +#else +return xen_mpumap_update (virt_to_maddr ((void *)s), +virt_to_maddr ((void *)e),0 ); +#endif }
Refer my comment in previous patch.
You can have two implementations of this function 1) xen/arch/arm/mmu/mm.c 2) xen/arch/arm/mpu/mm.h
Quoted 37 lines
xen/arch/arm/mm.c +0
-0int modify_xen_mappings (unsigned long s,unsigned long e,unsigned int flags)xen/arch/arm/mpu/mm.c +27
-0@@ -425,6 +425,59 @@ static int mpumap_contain_region(pr_t *table, uint8_t nr_regions,return MPUMAP_REGION_FAILED ; } +/* Disable or enable EL2 MPU memory region at index #index */ +static void control_mpu_region_from_index (uint8_t index,bool enable) +{ +pr_t region; + +read_protection_region (®ion, index); +if ( !region_is_valid (®ion) ^ enable ) + { +printk (XENLOG_WARNING +"mpu: MPU memory region[%u] is already %s\n" , index, + enable ?"enabled" :"disabled" ); +return ; + } + +/* +* ARM64v8R provides PRENR_EL2 to have direct access to the +* PRLAR_EL2.EN bits of EL2 MPU regions from 0 to 31. +*/ +if ( index <MPU_PRENR_BITS ) + { +uint64_t orig, after; + + orig =READ_SYSREG (PRENR_EL2 ); +if ( enable ) +/* Set respective bit */ + after = orig | (1UL << index); +else
xen/arch/arm/mpu/mm.c static int mpumap_contain_region(pr_t *table, uint8_t nr_regions, · line 464
Quoted 10 lines
xen/arch/arm/mpu/mm.c +10
-0+/* Clear respective bit */ + after = orig & (~(1UL << index)); +WRITE_SYSREG (after,PRENR_EL2 ); + } +else + { + region.prlar.reg.en = enable ?1 :0 ; +write_protection_region ((const pr_t *)®ion, index); + } +/* Ensure the write before zeroing the entry */
dsb(); /* to ensure write completes */
Quoted 48 lines
xen/arch/arm/mpu/mm.c +37
-1+isb (); + +/* Update according bitfield in xen_mpumap_mask */ +spin_lock (&xen_mpumap_alloc_lock); + +if ( enable ) +set_bit (index, xen_mpumap_mask); +else + { +clear_bit (index, xen_mpumap_mask); +memset (&xen_mpumap[index],0 ,sizeof (pr_t)); + } + +spin_unlock (&xen_mpumap_alloc_lock); +} +/* * Update an entry in Xen MPU memory region mapping table(xen_mpumap) at * the index @idx. @@ -461,6 +514,27 @@ static int xen_mpumap_update_entry(paddr_t base, paddr_t limit,write_protection_region ((const pr_t *)(&xen_mpumap[idx]), idx); } +else + { +/* +* Currently, we only support destroying a *WHOLE* MPU memory region, +* part-region removing is not supported, as in worst case, it will +* leave two fragments behind. +* part-region removing will be introduced only when actual usage +* comes. +*/ +if ( rc ==MPUMAP_REGION_INCLUSIVE ) + { +region_printk ("mpu: part-region removing is not supported\n" ); +return -EINVAL ; + } + +/* We are removing the region */ +if ( rc !=MPUMAP_REGION_FOUND ) +return -EINVAL ; + +control_mpu_region_from_index (idx, false); + }return 0 ; } --
Quoted 3 lines
2.25.1
- Ayan
Re: [PATCH v3 34/52] xen/mpu: destroy an existing entry in Xen MPU memory mapping table
Hi Ayan
Quoted 38 lines · Ayan Kumar Halder
Quoted 36 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
This commit expands xen_mpumap_update/xen_mpumap_update_entry to include destroying an existing entry.
We define a new helper "
control_xen_mpumap_region_from_index" to enable/disable the MPU region based on index. If region is within [0, 31], we could quickly disable the MPU region throughPRENR_EL2which provides direct access to the PRLAR_EL2.EN bits of EL2 MPU regions.Rignt now, we only support destroying a *WHOLE* MPU memory region, part-region removing is not supported, as in worst case, it will leave two fragments behind.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- make pr_get_base()/pr_get_limit() static inline
- need an isb to ensure register write visible before zeroing the entry
---
xen/arch/arm/include/asm/arm64/mpu.h | 2 +xen/arch/arm/include/asm/arm64/sysregs.h| 3 + xen/arch/arm/mm.c | 5 ++ xen/arch/arm/mpu/mm.c | 74 ++++++++++++++++++++++++4 files changed, 84 insertions(+)xen/arch/arm/include/asm/arm64/mpu.h +0
-0@@ -25,6 +25,8 @@ #define REGION_UART_SEL 0x07 #define MPUIR_REGION_MASK ((_AC(1, UL) << 8) - 1)
Quoted 6 lines
xen/arch/arm/include/asm/arm64/mpu.h line 28
Quoted 1 line
xen/arch/arm/include/asm/arm64/mpu.h +1
-0+#define MPU_PRENR_BITS 32This is common to R52 and R82.
Thus, you can put it in the common file (may be
xen/arch/arm/include/asm/mpu/mm.h)
Will do.
Quoted 37 lines
Quoted 24 lines
xen/arch/arm/include/asm/arm64/mpu.h +1
-0+ /* Access permission attributes. */ /* Read/Write at EL2, No Access at EL1/EL0. */ #define AP_RW_EL2 0x0xen/arch/arm/include/asm/arm64/sysregs.h +3
-0@@ -509,6 +509,9 @@ /* MPU Type registers encode */ #define MPUIR_EL2 S3_4_C0_C0_4 +/* MPU Protection Region Enable Register encode */ +#define PRENR_EL2 S3_4_C6_C1_1 + #endif /* Access to system registers */xen/arch/arm/mm.c +0
-0@@ -164,7 +164,12 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)xen/arch/arm/mm.c int destroy_xen_mappings(unsigned long s, · line 174
Quoted 10 lines
xen/arch/arm/mm.c +5
-0ASSERT(IS_ALIGNED(s, PAGE_SIZE)); ASSERT(IS_ALIGNED(e, PAGE_SIZE)); ASSERT(s <= e); +#ifndef CONFIG_HAS_MPU return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0); +#else + return xen_mpumap_update(virt_to_maddr((void *)s), + virt_to_maddr((void *)e), 0); +#endif }Refer my comment in previous patch.
Quoted 2 lines
You can have two implementations of this function 1)
xen/arch/arm/mmu/mm.c2)xen/arch/arm/mpu/mm.h
Refer my comment in previous patch.
I prefer #ifdef in destroy_xen_mappings()
Quoted 106 lines
Quoted 38 lines
xen/arch/arm/mm.c +0
-0int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags)xen/arch/arm/mpu/mm.c +27
-0@@ -425,6 +425,59 @@ static int mpumap_contain_region(pr_t *table,uint8_t nr_regions, return MPUMAP_REGION_FAILED; } +/* Disable or enable EL2 MPU memory region at index #index */ +static void control_mpu_region_from_index (uint8_t index,bool enable) +{ + pr_t region; + + read_protection_region(®ion, index); + if ( !region_is_valid(®ion) ^ enable ) + { + printk(XENLOG_WARNING + "mpu: MPU memory region[%u] is already %s\n", index, + enable ? "enabled" : "disabled"); + return; + } + + /* + * ARM64v8R provides PRENR_EL2 to have direct access to the + * PRLAR_EL2.EN bits of EL2 MPU regions from 0 to 31. + */ + if ( index < MPU_PRENR_BITS ) + { + uint64_t orig, after; + + orig = READ_SYSREG(PRENR_EL2); + if ( enable ) + /* Set respective bit */ + after = orig | (1UL << index); + elsexen/arch/arm/mpu/mm.c static int mpumap_contain_region(pr_t *table, · line 465
Quoted 10 lines
xen/arch/arm/mpu/mm.c +10
-0+ /* Clear respective bit */ + after = orig & (~(1UL << index)); + WRITE_SYSREG(after, PRENR_EL2); + } + else + { + region.prlar.reg.en = enable ? 1 : 0; + write_protection_region((const pr_t*)®ion, index); + } + /* Ensure the write before zeroing the entry */
dsb(); /* to ensure write completes */Quoted 50 lines
xen/arch/arm/mpu/mm.c +16
-0+ isb(); + + /* Update according bitfield in xen_mpumap_mask */ + spin_lock(&xen_mpumap_alloc_lock); + + if ( enable ) + set_bit(index, xen_mpumap_mask); + else + { + clear_bit(index, xen_mpumap_mask); + memset(&xen_mpumap[index], 0, sizeof(pr_t)); + } + + spin_unlock(&xen_mpumap_alloc_lock); +} + /** Update an entry in Xen MPU memory region mapping table(xen_mpumap) at * the index @idx.
xen/arch/arm/mpu/mm.c +5
-0@@ -461,6 +514,27 @@ static int xen_mpumap_update_entry(paddr_t base,paddr_t limit, write_protection_region((const pr_t*)(&xen_mpumap[idx]), idx); } + else + { + /* +* Currently, we only support destroying a *WHOLE* MPU memory region, +* part-region removing is not supported, as in worst case, it will
+ * leave two fragments behind.
+ * part-region removing will be introduced only when actual usage
+ * comes.
+ */
+ if ( rc ==MPUMAP_REGION_INCLUSIVE)
+ {
+region_printk("mpu: part-region removing is not supported\n");
+ return-EINVAL;
+ }xen/arch/arm/mpu/mm.c +7
-0+ + /* We are removing the region */ + if ( rc != MPUMAP_REGION_FOUND ) + return -EINVAL; + + control_mpu_region_from_index(idx, false); + }Quoted 6 lines
return 0;
}Signature · 1 line
2.25.1- Ayan
PATCH v3 35/52 xen/arm: map static memory on demand
In reply to Penny ZhengIn function init_staticmem_pages, we need the access to static memory for proper initialization.
It is not a problem in MMU system, as Xen map the whole RAM in setup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM.
As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization.
---
v3:
- new commit
--- xen/arch/arm/include/asm/mm.h | 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+)
xen/arch/arm/include/asm/mm.h +2 -0
@@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void);extern void setup_frametable_mappings (paddr_t ps,paddr_t pe);/* map a physical range in virtual memory */ void __iomem *ioremap_attr (paddr_t start,size_t len,unsigned int attributes); +extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end); +extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end);static inline void __iomem *ioremap_nocache (paddr_t start,size_t len) {
xen/arch/arm/mmu/mm.c +10 -0
@@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns)return xen_pt_update (virt,INVALID_MFN , nr_mfns, _PAGE_POPULATE); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return 0 ; +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return 0 ; +} +/* * Local variables: * mode: C
xen/arch/arm/mpu/mm.c +10 -0
@@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return xen_mpumap_update (start, end,PAGE_HYPERVISOR | _PAGE_TRANSIENT); +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return xen_mpumap_update (start, end,0 ); +} +/* * Local variables: * mode: C
xen/arch/arm/setup.c +21 -0
@@ -637,12 +637,33 @@ void __init init_staticmem_pages(void)mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start));unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size);mfn_t bank_end =mfn_add (bank_start, bank_pages); +int res;if (mfn_x (bank_end) <=mfn_x (bank_start) )return ; +/* Map temporarily before initialization */ + res =map_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); +if ( res ) + { +printk (XENLOG_ERR "Failed to map static memory to Xen: %d\n" , + res); +return ; + } +unprepare_staticmem_pages (mfn_to_page (bank_start), bank_pages, false); + +/* Unmap immediately after initialization */ + res =unmap_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); +if ( res ) + { +printk (XENLOG_ERR "Failed to unmap static memory to Xen: %d\n" , + res); +return ; + } } }#endif
Signature · 1 line
2.25.1
Re: [PATCH v3 35/52] xen/arm: map static memory on demand
Hi Penny,
Quoted 11 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
In function
init_staticmem_pages, we need the access to static memory for proper initialization.
It is not a problem in MMU system, as Xen map the whole RAM insetup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM.
As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization.
I could see that you are using _PAGE_TRANSIENT to map memory temporarily. However, I don't see this being translated to any of the MPU hardware features (ie _PAGE_TRANSIENT does not seem to translate to any of the attributes in PRBAR, PRLAR, PRENR, etc). Thus, how is it different from mapping the memory in "non temporary" way ?
Please let me know what I am missing.
- Ayan
Quoted 110 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit--- xen/arch/arm/include/asm/mm.h | 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void);extern void setup_frametable_mappings (paddr_t ps,paddr_t pe);/* map a physical range in virtual memory */ void __iomem *ioremap_attr (paddr_t start,size_t len,unsigned int attributes); +extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end); +extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end);static inline void __iomem *ioremap_nocache (paddr_t start,size_t len) {xen/arch/arm/mmu/mm.c +10
-0@@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns)return xen_pt_update (virt,INVALID_MFN , nr_mfns, _PAGE_POPULATE); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return 0 ; +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return 0 ; +} +/* * Local variables: * mode: C xen/arch/arm/mpu/mm.c +10
-0@@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return xen_mpumap_update (start, end,PAGE_HYPERVISOR | _PAGE_TRANSIENT); +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ +return xen_mpumap_update (start, end,0 ); +} +/* * Local variables: * mode: C xen/arch/arm/setup.c +21
-1@@ -637,12 +637,33 @@ void __init init_staticmem_pages(void)mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start));unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size);mfn_t bank_end =mfn_add (bank_start, bank_pages); +int res;if (mfn_x (bank_end) <=mfn_x (bank_start) )return ; +/* Map temporarily before initialization */ + res =map_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); +if ( res ) + { +printk (XENLOG_ERR "Failed to map static memory to Xen: %d\n" , + res); +return ; + } +unprepare_staticmem_pages (mfn_to_page (bank_start), bank_pages, false); + +/* Unmap immediately after initialization */ + res =unmap_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); +if ( res ) + { +printk (XENLOG_ERR "Failed to unmap static memory to Xen: %d\n" , + res); +return ; + } } }#endif --2.25.1
Re: [PATCH v3 35/52] xen/arm: map static memory on demand
Hi Ayan
Quoted 15 lines · Ayan Kumar Halder
Hi Penny,
Quoted 11 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
In function
init_staticmem_pages, we need the access to static memory for proper initialization.
It is not a problem in MMU system, as Xen map the whole RAM insetup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM.
As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization.
Quoted 2 lines
I could see that you are using _PAGE_TRANSIENT to map memory temporarily. However, I don't see this being translated to any of the MPU hardware features (ie
_PAGE_TRANSIENTdoes not seem to translate to any of the attributes in PRBAR, PRLAR, PRENR, etc). Thus, how is it different from mapping the memory in "non temporary" way ?
It is only software feature.
It is designed for implementing functions like ioremap_xxx(), or map_staticmem_pages_to_xen() here, which are always occuring with its reverse unmapping function nearby like iounmap(), or unmap_staticmem_pages_to_xen(), to map a chunk of memory *temporarily*, for a very short time. I want to check this flag in the unmapping function, to ensure that we are unmapping the proper MPU region.
Fixed MPU regions are like Xen text section, Xen data section, etc.
Quoted 119 lines
Please let me know what I am missing.
- Ayan
Quoted 115 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit
---
xen/arch/arm/include/asm/mm.h| 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++4 files changed, 43 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void); extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes); +extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end); +extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end); static inline void __iomem *ioremap_nocache(paddr_t start, size_t len) {xen/arch/arm/mmu/mm.c +10
-0@@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns) return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + /** Local variables: * mode: C
xen/arch/arm/mpu/mm.c +10
-0@@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, PAGE_HYPERVISOR | _PAGE_TRANSIENT); +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, 0); +} + /** Local variables:
* mode: Cxen/arch/arm/setup.c +21
-0@@ -637,12 +637,33 @@ void __init init_staticmem_pages(void) mfn_t bank_start = _mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start)); unsigned long bank_pages = PFN_DOWN(bootinfo.reserved_mem.bank[bank].size); mfn_t bank_end = mfn_add(bank_start, bank_pages); + int res; if ( mfn_x(bank_end) <= mfn_x(bank_start) ) return; + /* Map temporarily before initialization */ + res = map_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to map static memory to Xen: %d\n", + res); + return; + } + unprepare_staticmem_pages(mfn_to_page(bank_start), bank_pages, false); + + /* Unmap immediately after initialization */ + res = unmap_staticmem_pages_to_xen(mfn_to_maddr(bank_start), + mfn_to_maddr(bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to unmap static memory to Xen: %d\n", + res); + return; + } }}
#endifSignature · 1 line
2.25.1
Re: [PATCH v3 35/52] xen/arm: map static memory on demand
Quoted 1 line · Penny Zheng
Hi Ayan
Hi Penny,
Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines
Hi Penny,
Quoted 11 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
In function
init_staticmem_pages, we need the access to static memory for proper initialization.
It is not a problem in MMU system, as Xen map the whole RAM insetup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM.
As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization.
Quoted 5 lines
Quoted 2 lines
I could see that you are using _PAGE_TRANSIENT to map memory temporarily. However, I don't see this being translated to any of the MPU hardware features (ie
_PAGE_TRANSIENTdoes not seem to translate to any of the attributes in PRBAR, PRLAR, PRENR, etc). Thus, how is it different from mapping the memory in "non temporary" way ?It is only software feature.
It is designed for implementing functions likeioremap_xxx(), ormap_staticmem_pages_to_xen()here, which are always occuring with its reverse unmapping function nearby likeiounmap(), orunmap_staticmem_pages_to_xen(), to map a chunk of memory *temporarily*, for a very short time.
I understand that it is a software only feature. But why does the software need to know if the memory is mapped temporarily or not ? What difference does it make ?
Quoted 1 line
I want to check this flag in the unmapping function, to ensure that we are unmapping the proper MPU region.
I had a look at unmap_staticmem_pages_to_xen() --> xen_mpumap_update() --> control_mpu_region_from_index() and I don't see this flag used anywhere.
- Ayan
Quoted 123 lines
Fixed MPU regions are like Xen text section, Xen data section, etc.
Quoted 120 lines
Please let me know what I am missing.
- Ayan
Quoted 116 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit
---
xen/arch/arm/include/asm/mm.h| 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++4 files changed, 43 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void); extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes); +extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end); +extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end); static inline void __iomem *ioremap_nocache(paddr_t start, size_t len) {xen/arch/arm/mmu/mm.c +10
-0@@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns) return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + /** Local variables: * mode: C
xen/arch/arm/mpu/mm.c +10
-0@@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, PAGE_HYPERVISOR | _PAGE_TRANSIENT); +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, 0); +} + /** Local variables:
* mode: Cxen/arch/arm/setup.c +21
-0@@ -637,12 +637,33 @@ void __init init_staticmem_pages(void) mfn_t bank_start = _mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start)); unsigned long bank_pages = PFN_DOWN(bootinfo.reserved_mem.bank[bank].size); mfn_t bank_end = mfn_add(bank_start, bank_pages); + int res; if ( mfn_x(bank_end) <= mfn_x(bank_start) ) return; + /* Map temporarily before initialization */ + res = map_staticmem_pages_to_xen(mfn_to_maddr(bank_start), +mfn_to_maddr (bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to map static memory to Xen: %d\n", + res); + return; + } +unprepare_staticmem_pages (mfn_to_page (bank_start), bank_pages, false); + + /* Unmap immediately after initialization */ + res =unmap_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to unmap static memory to Xen: %d\n", + res); + return; + }}
}
#endifSignature · 1 line
2.25.1
Re: [PATCH v3 35/52] xen/arm: map static memory on demand
Hi Ayan
Quoted 21 lines · Ayan Kumar Halder
Quoted 1 line · Penny Zheng
Hi Ayan
Hi Penny,
Quoted 17 lines · Ayan Kumar Halder
Quoted 15 lines
Hi Penny,
Quoted 11 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
In function
init_staticmem_pages, we need the access to static memory for proper initialization.
It is not a problem in MMU system, as Xen map the whole RAM insetup_mm(). However, with limited MPU memory regions, it is too luxury to map the whole RAM.
As a result, we follow the rule of "map on demand", to map static memory temporarily before its initialization, and unmap immediately after its initialization.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
I could see that you are using _PAGE_TRANSIENT to map memory temporarily. However, I don't see this being translated to any of the MPU hardware features (ie
_PAGE_TRANSIENTdoes not seem to translate to any of the attributes in PRBAR, PRLAR, PRENR, etc). Thus, how is it different from mapping the memory in "non temporary" way ?It is only software feature.
It is designed for implementing functions likeioremap_xxx(), ormap_staticmem_pages_to_xen()here, which are always occuring with its reverse unmapping function nearby likeiounmap(), orunmap_staticmem_pages_to_xen(), to map a chunk of memory *temporarily*, for a very short time.I understand that it is a software only feature. But why does the software need to know if the memory is mapped temporarily or not ? What difference does it make ?
See this pair map_domain_page()/unmap_domain_page(), which is used to map/unmap page of guest RAM. vcpu in different mode is facing different scenario.
Taking usage in copy_guest() as example:
When vcpu in guest mode trying to access its own memory(e.g. copy hypercall param), there is no need to do the mapping/unmapping in MPU, as page is already mapped at both EL1/EL2. Checking if it is transient region in unmap_domain_page() is definitely necessary to help avoid unmapping it here. When vcpu in hypervisor mode at boot time copying kernel image to guest memory, we need to map page as transient MPU region to do the copying and pasting.
Quoted 131 lines
Quoted 1 line
I want to check this flag in the unmapping function, to ensure that we are unmapping the proper MPU region.
I had a look at
unmap_staticmem_pages_to_xen()-->xen_mpumap_update()-->control_mpu_region_from_index()and I don't see this flag used anywhere.- Ayan
Quoted 123 lines
Fixed MPU regions are like Xen text section, Xen data section, etc.
Quoted 120 lines
Please let me know what I am missing.
- Ayan
Quoted 116 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit
---
xen/arch/arm/include/asm/mm.h| 2 ++ xen/arch/arm/mmu/mm.c | 10 ++++++++++ xen/arch/arm/mpu/mm.c | 10 ++++++++++ xen/arch/arm/setup.c | 21 +++++++++++++++++++++4 files changed, 43 insertions(+)xen/arch/arm/include/asm/mm.h +2
-0@@ -224,6 +224,8 @@ extern void mm_init_secondary_cpu(void); extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); /* map a physical range in virtual memory */ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes); +extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end); +extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end); static inline void __iomem *ioremap_nocache(paddr_t start, size_t len) {xen/arch/arm/mmu/mm.c +10
-0@@ -1113,6 +1113,16 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns) return xen_pt_update(virt, INVALID_MFN, nr_mfns, _PAGE_POPULATE); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return 0; +} + /** Local variables: * mode: C
xen/arch/arm/mpu/mm.c +10
-0@@ -614,6 +614,16 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe) frametable_size - (nr_pdxs * sizeof(struct page_info))); } +int __init map_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, PAGE_HYPERVISOR | _PAGE_TRANSIENT); +} + +int __init unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end) +{ + return xen_mpumap_update(start, end, 0); +} + /** Local variables:
* mode: Cxen/arch/arm/setup.c +21
-0@@ -637,12 +637,33 @@ void __init init_staticmem_pages(void) mfn_t bank_start = _mfn(PFN_UP(bootinfo.reserved_mem.bank[bank].start)); unsigned long bank_pages = PFN_DOWN(bootinfo.reserved_mem.bank[bank].size); mfn_t bank_end = mfn_add(bank_start, bank_pages); + int res; if ( mfn_x(bank_end) <= mfn_x(bank_start) ) return; + /* Map temporarily before initialization */ + res = map_staticmem_pages_to_xen(mfn_to_maddr(bank_start), +mfn_to_maddr (bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to map static memory to Xen: %d\n", + res); + return; + } +unprepare_staticmem_pages (mfn_to_page (bank_start), bank_pages, false); + + /* Unmap immediately after initialization */ + res =unmap_staticmem_pages_to_xen (mfn_to_maddr (bank_start), +mfn_to_maddr (bank_end)); + if ( res ) + { + printk(XENLOG_ERR "Failed to unmap static memory to Xen: %d\n", + res); + return; + }}
}
#endifSignature · 1 line
2.25.1
PATCH v3 36/52 xen/mpu: implememt ioremap_xxx in MPU
In reply to Penny ZhengA set of function ioremap_xxx are designed to map deivce memory or remap part of memory temporarily for short-time special purpose, like using ioremap_wc to temporarily remap guest kernel non-cacheable, for copying it to guest memory.
As virtual translation is not supported in MPU, and we always follow the rule of "map in demand" in MPU, we implement MPU version of ioremap_xxx, through mapping the memory with a transient MPU memory region.
---
v3:
- adapt to the new rule of "map in demand"
--- xen/arch/arm/include/asm/arm64/mpu.h | 4 + xen/arch/arm/include/asm/mm.h | 6 + xen/arch/arm/mpu/mm.c | 185 +++++++++++++++++++++++++++ 3 files changed, 195 insertions(+)
xen/arch/arm/include/asm/arm64/mpu.h +4 -0
@@ -121,6 +121,10 @@ static inline bool region_is_valid(pr_t *pr)return pr->prlar.reg.en; } +static inline bool region_is_transient (pr_t *pr) +{ +return pr->prlar.reg.tran; +}#endif /* __ASSEMBLY__ */ #endif /* __ARM64_MPU_H__ */
xen/arch/arm/include/asm/mm.h +6 -0
@@ -227,6 +227,7 @@ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes);extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end);extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end); +#ifndef CONFIG_HAS_MPU static inline void __iomem *ioremap_nocache (paddr_t start,size_t len) {return ioremap_attr (start, len,PAGE_HYPERVISOR_NOCACHE );
@@ -241,6 +242,11 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len) {return ioremap_attr (start, len,PAGE_HYPERVISOR_WC ); } +#else +extern void __iomem *ioremap_nocache (paddr_t start,size_t len); +extern void __iomem *ioremap_cache (paddr_t start,size_t len); +extern void __iomem *ioremap_wc (paddr_t start,size_t len); +#endif /* XXX -- account for base */ #define mfn_valid (mfn) ({ \
xen/arch/arm/mpu/mm.c +185 -0
191 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 36/52] xen/mpu: implememt ioremap_xxx in MPU
Hi Penny,
Quoted 146 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
A set of function
ioremap_xxxare designed to map deivce memory or remap part of memory temporarily for short-time special purpose, like usingioremap_wcto temporarily remap guest kernel non-cacheable, for copying it to guest memory.As virtual translation is not supported in MPU, and we always follow the rule of "map in demand" in MPU, we implement MPU version of
ioremap_xxx, through mapping the memory with a transient MPU memory region.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- adapt to the new rule of "map in demand"--- xen/arch/arm/include/asm/arm64/mpu.h | 4 + xen/arch/arm/include/asm/mm.h | 6 + xen/arch/arm/mpu/mm.c | 185 +++++++++++++++++++++++++++ 3 files changed, 195 insertions(+)xen/arch/arm/include/asm/arm64/mpu.h +4
-0@@ -121,6 +121,10 @@ static inline bool region_is_valid(pr_t *pr)return pr->prlar.reg.en; } +static inline bool region_is_transient (pr_t *pr) +{ +return pr->prlar.reg.tran; +}#endif /* __ASSEMBLY__ */ #endif /* __ARM64_MPU_H__ */ xen/arch/arm/include/asm/mm.h +6
-0@@ -227,6 +227,7 @@ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes);extern int map_staticmem_pages_to_xen (paddr_t start,paddr_t end);extern int unmap_staticmem_pages_to_xen (paddr_t start,paddr_t end); +#ifndef CONFIG_HAS_MPU static inline void __iomem *ioremap_nocache (paddr_t start,size_t len) {return ioremap_attr (start, len,PAGE_HYPERVISOR_NOCACHE );@@ -241,6 +242,11 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len) {return ioremap_attr (start, len,PAGE_HYPERVISOR_WC ); } +#else +extern void __iomem *ioremap_nocache (paddr_t start,size_t len); +extern void __iomem *ioremap_cache (paddr_t start,size_t len); +extern void __iomem *ioremap_wc (paddr_t start,size_t len); +#endif /* XXX -- account for base */ #define mfn_valid (mfn) ({ \xen/arch/arm/mpu/mm.c +76
-0@@ -624,6 +624,191 @@ int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end)return xen_mpumap_update (start, end,0 ); } +/* +* Check whether memory range [pa, pa + len) is mapped in Xen MPU +* memory mapping table xen_mpumap. +* +* If it is mapped, the associated index will be returned. +* If it is not mapped, INVALID_REGION_IDX will be returned. +*/ +static uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len) +{ +int rc; +uint8_t idx; + + rc =mpumap_contain_region (xen_mpumap, max_xen_mpumap, pa, pa + len -1 , + &idx); +if ( (rc ==MPUMAP_REGION_FOUND ) || (rc ==MPUMAP_REGION_INCLUSIVE ) ) +return idx; + +if ( rc ==MPUMAP_REGION_OVERLAP ) +panic ("mpu: can not deal with overlapped MPU memory region\n" ); +/* Not mapped */ +return INVALID_REGION_IDX ; +} + +static bool is_mm_attr_match (pr_t *region,unsigned int attributes) +{ +if ( region->prbar.reg.ap !=PAGE_AP_MASK (attributes) ) + { +printk (XENLOG_WARNING "region permission is not matched (0x%x -> 0x%x)\n" , + region->prbar.reg.ap,PAGE_AP_MASK (attributes)); +return false; + } + +if ( region->prbar.reg.xn !=PAGE_XN_MASK (attributes) ) + { +printk (XENLOG_WARNING "region execution permission is not matched (0x%x -> 0x%x)\n" , + region->prbar.reg.xn,PAGE_XN_MASK (attributes)); +return false; + } + +if ( region->prlar.reg.ai !=PAGE_AI_MASK (attributes) ) + { +printk (XENLOG_WARNING "region memory attributes is not matched (0x%x -> 0x%x)\n" , + region->prlar.reg.ai,PAGE_AI_MASK (attributes)); +return false; + } + +return true; +} + +/* +* Check whether memory range [pa, pa + len) is mapped with memory +* attributes #attr in Xen MPU memory mapping table xen_mpumap. +* +* If it is mapped but with different memory attributes, Errno -EINVAL +* will be returned. +* If it is not mapped at all, Errno -ENOENT will be returned. +*/ +static int is_mm_range_mapped_with_attr (paddr_t pa,paddr_t len, +unsigned int attr) +{ +uint8_t idx; + + idx =is_mm_range_mapped (pa, len); +if ( idx !=INVALID_REGION_IDX ) + { +pr_t *region; + + region = &xen_mpumap[idx]; +if ( !is_mm_attr_match (region, attr) ) +return -EINVAL ; + +return 0 ; + } + +return -ENOENT ; +}
xen/arch/arm/mpu/mm.c int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) · line 712
Quoted 10 lines
xen/arch/arm/mpu/mm.c +10
-0+ +/* +* map_mm_range shall work with unmap_mm_range to map a chunk +* of memory with a transient MPU memory region for a period of short time. +*/ +static void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes) +{ +if (xen_mpumap_update (pa, pa + len, attributes | _PAGE_TRANSIENT) ) +printk (XENLOG_ERR "Failed to map_mm_range 0x%" PRIpaddr"-0x%" PRIpaddr"\n" , + pa, pa + len);
Don't you want to return NULL or something from here ?
Quoted 17 lines
xen/arch/arm/mpu/mm.c +17
-0+ +return maddr_to_virt (pa); +} + +static void unmap_mm_range (paddr_t pa) +{ +uint8_t idx; + +/* +* The mapping size in map_mm_range is at least PAGE_SIZE. +* Find the MPU memory region mapped through map_mm_range, and associated +* idx will be returned. +*/ + idx =is_mm_range_mapped (pa,PAGE_SIZE ); +if ( idx ==INVALID_REGION_IDX ) + { + printk(XENLOG_ERR "Failed to unmap_mm_range MPU memory region at 0x%"PRIpaddr"\n",
xen/arch/arm/mpu/mm.c int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) · line 739
Quoted 10 lines
xen/arch/arm/mpu/mm.c +10
-0+ pa); +return ; + } + +if ( !region_is_transient (&xen_mpumap[idx]) ) + { +printk (XENLOG_WARNING "Failed to unmap MPU memory region at 0x%" PRIpaddr"\n, as it is not transient\n" , + pa); +return ; + }
Does this mean you only allow unmapping of transient memory ?
So, is the non transient memory always expected to be mapped throughout the lifetime of the system ?
Quoted 8 lines
xen/arch/arm/mpu/mm.c +8
-0+ +/* Disable MPU memory region and clear the according entry in xen_mpumap */ +control_mpu_region_from_index (idx, false); +} + +/* +* It works with "iounmap" as a pair to temporarily map a chunk of memory +* with a transient MPU memory region, for short-time special accessing.
xen/arch/arm/mpu/mm.c int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) · line 757
Quoted 10 lines
xen/arch/arm/mpu/mm.c +10
-0+*/ +void *ioremap_attr (paddr_t pa,size_t len,unsigned int attributes) +{ +return map_mm_range (round_pgdown (pa),round_pgup (len), attributes); +} + +/* ioremap_nocache is normally used to map device memory */ +void __iomem *ioremap_nocache (paddr_t start,size_t len) +{ +int rc;
For this function and others (ioremap_xxx()), don't we need to check if the memory is transient ?
- Ayan
Quoted 61 lines
xen/arch/arm/mpu/mm.c +54
-1+ +/* Check whether it is already mapped as device memory */ + rc =is_mm_range_mapped_with_attr (start, len,PAGE_HYPERVISOR_NOCACHE ); +if ( rc == -ENOENT ) +return ioremap_attr (start, len,PAGE_HYPERVISOR_NOCACHE ); +else if ( rc !=0 ) +return NULL ; + +/* Already mapped */ +return maddr_to_virt (start); +} + +/* +* ioremap_cache which is working with iounmap as a pair, is normally used to +* map a chunck of cacheable memory temporarily for short-time special purpose. +*/ +void __iomem *ioremap_cache (paddr_t start,size_t len) +{ +int rc; + + rc =is_mm_range_mapped_with_attr (start, len,PAGE_HYPERVISOR ); +if ( rc == -ENOENT ) +return ioremap_attr (start, len,PAGE_HYPERVISOR ); +else if ( rc !=0 ) +return NULL ; + +/* Already mapped */ +return maddr_to_virt (start); +} + +/* +* ioremap_wc which is working with iounmap as a pair, is normally used to +* map a chunck of non-cacheable memory temporarily for short-time special +* purpose. +*/ +void __iomem *ioremap_wc (paddr_t start,size_t len) +{ +int rc; + + rc =is_mm_range_mapped_with_attr (start, len,PAGE_HYPERVISOR_WC ); +if ( rc == -ENOENT ) +ioremap_attr (start, len,PAGE_HYPERVISOR_WC ); +else if ( rc !=0 ) +return NULL ; + +/* Already mapped */ +return maddr_to_virt (start); +} + +void iounmap (void __iomem *va) +{ +unmap_mm_range (virt_to_maddr (va)); +} +/* * Local variables: * mode: C -- 2.25.1
Re: [PATCH v3 36/52] xen/mpu: implememt ioremap_xxx in MPU
Hi Ayan
Quoted 163 lines · Ayan Kumar Halder
Hi Penny,
Quoted 160 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
A set of function
ioremap_xxxare designed to map deivce memory or remap part of memory temporarily for short-time special purpose, like usingioremap_wcto temporarily remap guest kernel non-cacheable, for copying it to guest memory.As virtual translation is not supported in MPU, and we always follow the rule of "map in demand" in MPU, we implement MPU version of
ioremap_xxx, through mapping the memory with a transient MPU memory region.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- adapt to the new rule of "map in demand"
---
xen/arch/arm/include/asm/arm64/mpu.h| 4 + xen/arch/arm/include/asm/mm.h | 6 + xen/arch/arm/mpu/mm.c | 185 +++++++++++++++++++++++++++3 files changed, 195 insertions(+)xen/arch/arm/include/asm/arm64/mpu.h +4
-0@@ -121,6 +121,10 @@ static inline bool region_is_valid(pr_t *pr) return pr->prlar.reg.en; } +static inline bool region_is_transient (pr_t *pr) +{ + return pr->prlar.reg.tran; +} #endif /* __ASSEMBLY__ */ #endif /* __ARM64_MPU_H__ */xen/arch/arm/include/asm/mm.h +1
-0@@ -227,6 +227,7 @@ void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int attributes); extern int map_staticmem_pages_to_xen(paddr_t start, paddr_t end); extern int unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end); +#ifndef CONFIG_HAS_MPU static inline void __iomem *ioremap_nocache(paddr_t start, size_t len) {return
ioremap_attr(start, len, PAGE_HYPERVISOR_NOCACHE);xen/arch/arm/include/asm/mm.h +5
-0@@ -241,6 +242,11 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len) { return ioremap_attr(start, len, PAGE_HYPERVISOR_WC); } +#else +extern void __iomem *ioremap_nocache (paddr_t start,size_t len); +extern void __iomem *ioremap_cache (paddr_t start,size_t len); +extern void __iomem *ioremap_wc (paddr_t start,size_t len); +#endif /* XXX -- account for base */#define
mfn_valid(mfn)({ \xen/arch/arm/mpu/mm.c +35
-1@@ -624,6 +624,191 @@ int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) return xen_mpumap_update(start, end, 0); } +/* +* Check whether memory range [pa, pa + len) is mapped in Xen MPU +* memory mapping table xen_mpumap. +* +* If it is mapped, the associated index will be returned. +* If it is not mapped, INVALID_REGION_IDX will be returned. +*/ +static uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len) +{ + int rc; + uint8_t idx; + + rc = mpumap_contain_region(xen_mpumap, max_xen_mpumap, pa, pa + len -1 , + &idx); + if ( (rc == MPUMAP_REGION_FOUND) || (rc ==MPUMAP_REGION_INCLUSIVE ) ) + return idx; + + if ( rc == MPUMAP_REGION_OVERLAP ) + panic("mpu: can not deal with overlapped MPU memory region\n"); + /* Not mapped */ + return INVALID_REGION_IDX; +} + +static bool is_mm_attr_match(pr_t *region, unsigned int attributes) +{ + if ( region->prbar.reg.ap != PAGE_AP_MASK(attributes) ) + { + printk(XENLOG_WARNING "region permission is not matched (0x%x -> 0x%x)\n", + region->prbar.reg.ap, PAGE_AP_MASK(attributes)); + return false; + } + + if ( region->prbar.reg.xn != PAGE_XN_MASK(attributes) ) + { + printk(XENLOG_WARNING "region execution permission is notmatched (0x%x -> 0x%x)\n",
+region->prbar.reg.xn,PAGE_XN_MASK(attributes)); + return false;
+ }
+
+ if (region->prlar.reg.ai!=PAGE_AI_MASK(attributes)) + {
+ printk(XENLOG_WARNING "region memory attributes is not matched (0x%x -> 0x%x)\n",
+region->prlar.reg.ai,PAGE_AI_MASK(attributes)); + return false;
+ }xen/arch/arm/mpu/mm.c +35
-0+ + return true; +} + +/* +* Check whether memory range [pa, pa + len) is mapped with memory +* attributes #attr in Xen MPU memory mapping table xen_mpumap. +* +* If it is mapped but with different memory attributes, Errno -EINVAL +* will be returned. +* If it is not mapped at all, Errno -ENOENT will be returned. +*/ +static int is_mm_range_mapped_with_attr (paddr_t pa,paddr_t len, + unsigned int attr) +{ + uint8_t idx; + + idx = is_mm_range_mapped(pa, len); + if ( idx != INVALID_REGION_IDX ) + { + pr_t *region; + + region = &xen_mpumap[idx]; + if ( !is_mm_attr_match(region, attr) ) + return -EINVAL; + + return 0; + } + + return -ENOENT; +} + +/* +* map_mm_range shall work with unmap_mm_range to map a chunk +* of memory with a transient MPU memory region for a period of short time.
+ */
Quoted 8 lines
Quoted 7 lines
+static void *map_mm_range(paddr_t pa,
size_tlen, unsigned int attributes)
+{
+ if (xen_mpumap_update(pa, pa + len, attributes | _PAGE_TRANSIENT)) + printk(XENLOG_ERR "Failed tomap_mm_range0x%"PRIpaddr"-0x%"PRIpaddr"\n",
+ pa, pa + len);Don't you want to return NULL or something from here ?
Right, I shall return NULL. Will fix.
Quoted 24 lines
Quoted 24 lines
xen/arch/arm/mpu/mm.c +11
-0+ + return maddr_to_virt(pa); +} + +static void unmap_mm_range (paddr_t pa) +{ + uint8_t idx; + + /* +* The mapping size in map_mm_range is at least PAGE_SIZE. +* Find the MPU memory region mapped through map_mm_range, and associated
+ * idx will be returned.
+ */
+ idx =is_mm_range_mapped(pa, PAGE_SIZE);
+ if ( idx ==INVALID_REGION_IDX)
+ {
+ printk(XENLOG_ERR "Failed tounmap_mm_rangeMPU memory region at 0x%"PRIpaddr"\n",
+ pa);
+ return;
+ }
+
+ if ( !region_is_transient(&xen_mpumap[idx]) )
Quoted 8 lines
Quoted 6 lines
+ {
+ printk(XENLOG_WARNING "Failed to unmap MPU memory region at 0x%"PRIpaddr"\n, as it is not transient\n",
+ pa);
+ return;
+ }Does this mean you only allow unmapping of transient memory ?
For this function, yes.
Quoted 3 lines
So, is the non transient memory always expected to be mapped throughout the lifetime of the system ?
Maybe I should rename this pair helpers to map_mm_transient()/unmap_mm_transient() for better understanding. For mapping memory with transient MPU region, we are suggesting to
use map_mm_transient()/unmap_mm_transient().
You could see that, in Xen, Functions like, ioremap_xxx()/iounmap(), map_domain_page()/unmap_domain_page(), are always working as a pair and showing up with each other nearby. "Transient" is referring to this kind of senario.
So for "non-transient" memory, it is more pointing to the memory not mapped from functions like ioremap_xxx() and map_domain_page(). We could use xen_mpumap_update to do the mapping/unmapping for them.
Quoted 14 lines
Quoted 14 lines
+
+ /* Disable MPU memory region and clear the according entry inxen_mpumap*/
+control_mpu_region_from_index(idx, false);xen/arch/arm/mpu/mm.c +4
-0+} + +/* +* It works with "iounmap" as a pair to temporarily map a chunk of memory
+ * with a transient MPU memory region, for short-time special accessing.
+ */xen/arch/arm/mpu/mm.c +3
-0+void *ioremap_attr (paddr_t pa,size_t len,unsigned int attributes) +{ + return map_mm_range(round_pgdown(pa), round_pgup(len), attributes);
Quoted 9 lines
xen/arch/arm/mpu/mm.c int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end) · line 757
Quoted 6 lines
xen/arch/arm/mpu/mm.c +6
-0+} + +/* ioremap_nocache is normally used to map device memory */ +void __iomem *ioremap_nocache (paddr_t start,size_t len) +{ + int rc;For this function and others (
ioremap_xxx()), don't we need to check if the memory is transient ?
Checking if the memory is transient should lay in unmapping function, like iounmap(). Since in function iounmap(), we shall only unmap the "transient" memory, memory that is mapped through ioremap_xxx().
The reason why I add checking is_mm_range_mapped_with_attr() here is that, in some corner cases, memory is already mapped as expected, there is no need to map again. In MMU, it is only a redundant mapping. However, in MPU, it could lead to failure of "Overlapping MPU memory region".
For example,
If earlyprintk is enabled, uart0 will be mapped at assembly by setup_early_uart(), see commit "[PATCH v3 26/52] xen/mpu: map early uart when earlyprintk on".
Then later when we are doing uart initialization in pl011_uart_init(), ioremap_nocache() will try to map it twice if there is no checking.
Quoted 68 lines
- Ayan
Quoted 66 lines
+
+ /* Check whether it is already mapped as device memory */ + rc =is_mm_range_mapped_with_attr(start, len, PAGE_HYPERVISOR_NOCACHE);
+ if ( rc ==-ENOENT)
+ returnioremap_attr(start, len, PAGE_HYPERVISOR_NOCACHE); + else if ( rc != 0 )
+ return NULL;xen/arch/arm/mpu/mm.c +7
-0+ + /* Already mapped */ + return maddr_to_virt(start); +} + +/* +* ioremap_cache which is working with iounmap as a pair, is normally used to
+ * map a chunck of cacheable memory temporarily for short-time special purpose.
+ */xen/arch/arm/mpu/mm.c +16
-0+void __iomem *ioremap_cache (paddr_t start,size_t len) +{ + int rc; + + rc = is_mm_range_mapped_with_attr(start, len, PAGE_HYPERVISOR); + if ( rc == -ENOENT ) + return ioremap_attr(start, len, PAGE_HYPERVISOR); + else if ( rc != 0 ) + return NULL; + + /* Already mapped */ + return maddr_to_virt(start); +} + +/* +* ioremap_wc which is working with iounmap as a pair, is normally used to
+ * map a chunck of non-cacheable memory temporarily for short-time special
+ * purpose.
+ */xen/arch/arm/mpu/mm.c +19
-0+void __iomem *ioremap_wc (paddr_t start,size_t len) +{ + int rc; + + rc = is_mm_range_mapped_with_attr(start, len, PAGE_HYPERVISOR_WC); + if ( rc == -ENOENT ) + ioremap_attr(start, len, PAGE_HYPERVISOR_WC); + else if ( rc != 0 ) + return NULL; + + /* Already mapped */ + return maddr_to_virt(start); +} + +void iounmap (void __iomem *va) +{ + unmap_mm_range(virt_to_maddr(va)); +} +/*
* Local variables:
* mode: CSignature · 1 line
2.25.1
PATCH v3 37/52 xen/mpu: implement MPU version of copy_from_paddr
In reply to Penny ZhengWhen implementing MPU version of copy_from_paddr, if source physical address is not accessible, we shall map it temporarily with a transient MPU memory region for copying and pasting.
---
v3:
- new patch
--- xen/arch/arm/include/asm/mpu/mm.h | 3 +++ xen/arch/arm/mpu/mm.c | 6 +++--- xen/arch/arm/mpu/setup.c | 32 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/mpu/mm.h +3 -0
@@ -7,6 +7,9 @@ extern unsigned long frametable_pdx_end;extern int xen_mpumap_update (paddr_t base,paddr_t limit,unsigned int flags);extern void setup_staticheap_mappings (void ); +extern uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len); +extern void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes); +extern void unmap_mm_range (paddr_t pa);#endif /* __ARCH_ARM_MM_MPU__ */
xen/arch/arm/mpu/mm.c +3 -3
@@ -631,7 +631,7 @@ int __init unmap_staticmem_pages_to_xen(paddr_t start, paddr_t end)* If it is mapped, the associated index will be returned. * If it is not mapped, INVALID_REGION_IDX will be returned. */ -static uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len) +uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len) {int rc;uint8_t idx;
@@ -705,7 +705,7 @@ static int is_mm_range_mapped_with_attr(paddr_t pa, paddr_t len,* map_mm_range shall work with unmap_mm_range to map a chunk * of memory with a transient MPU memory region for a period of short time. */ -static void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes) +void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes) {if (xen_mpumap_update (pa, pa + len, attributes | _PAGE_TRANSIENT) ) printk(XENLOG_ERR "Failed to map_mm_range 0x%"PRIpaddr"-0x%"PRIpaddr"\n",
@@ -714,7 +714,7 @@ static void *map_mm_range(paddr_t pa, size_t len, unsigned int attributes)return maddr_to_virt (pa); } -static void unmap_mm_range (paddr_t pa) +void unmap_mm_range (paddr_t pa) {uint8_t idx;
xen/arch/arm/mpu/setup.c +32 -0
@@ -22,6 +22,7 @@#include <xen/init.h> #include <xen/mm.h> #include <xen/pfn.h> +#include <asm/arm64/mpu.h> #include <asm/mpu/mm.h> #include <asm/page.h> #include <asm/setup.h>
@@ -60,6 +61,37 @@ void __init setup_mm(void)init_staticmem_pages (); } +/* +* copy_from_paddr - copy data from a physical address +* @dst: destination virtual address +* @paddr: source physical address +* @len: length to copy +*/ +void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) +{ +void *src, *rc =NULL ; +uint8_t idx; + + idx =is_mm_range_mapped (round_pgdown (paddr),round_pgup (len)); +if ( idx ==INVALID_REGION_IDX ) + { +/* +* If source physical address is not accessible, we shall map it +* temporarily for copying and pasting +*/ + rc =map_mm_range (round_pgdown (paddr),round_pgup (len), +PAGE_HYPERVISOR_WC ); +if ( !rc ) +return ; + } + + src =maddr_to_virt (paddr); +memcpy (dst, src, len); + +if ( rc ) +unmap_mm_range (round_pgdown (paddr)); +} +/* * Local variables: * mode: C
Signature · 1 line
2.25.1
PATCH v3 38/52 xen/mpu: map domain page in MPU system
In reply to Penny ZhengIn MPU system, we implement map_domain_page()/unmap_domain_page() through mapping the domain page with a transient MPU region on demand.
---
v3:
- new patch
--- xen/arch/arm/Makefile | 4 ++ xen/arch/arm/include/asm/mpu/mm.h | 1 + xen/arch/arm/mpu/domain_page.c | 68 +++++++++++++++++++++++++++++++ xen/arch/arm/mpu/mm.c | 17 ++++++++ 4 files changed, 90 insertions(+) create mode 100644 xen/arch/arm/mpu/domain_page.c
xen/arch/arm/Makefile +4 -0
@@ -17,7 +17,11 @@ obj-y += device.o obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o obj-y += domain_build.init.o +ifneq ($(CONFIG_HAS_MPU),y) obj-$(CONFIG_ARCH_MAP_DOMAIN_PAGE) += domain_page.o +else +obj-$(CONFIG_ARCH_MAP_DOMAIN_PAGE) += mpu/domain_page.o +endif obj-y += domctl.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += efi/
xen/arch/arm/include/asm/mpu/mm.h +1 -0
@@ -10,6 +10,7 @@ extern void setup_staticheap_mappings(void);extern uint8_t is_mm_range_mapped (paddr_t pa,paddr_t len);extern void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes);extern void unmap_mm_range (paddr_t pa); +extern bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len);#endif /* __ARCH_ARM_MM_MPU__ */
xen/arch/arm/mpu/domain_page.c new file +68 -0
68 lines not on this page · raw message
xen/arch/arm/mpu/mm.c +17 -0
@@ -809,6 +809,23 @@ void iounmap(void __iomem *va)unmap_mm_range (virt_to_maddr (va)); } +bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len) +{ +uint8_t idx; + + idx =is_mm_range_mapped (pa, len); +if ( idx !=INVALID_REGION_IDX ) + { +pr_t *region; + + region = &xen_mpumap[idx]; +if (region_is_transient (region) ) +return true; + } + +return false; +} +/* * Local variables: * mode: C
Signature · 1 line
2.25.1
PATCH v3 39/52 xen/mpu: support free_init_memory in MPU system
In reply to Penny ZhengThis commit refines free_init_memory() to make it support in MPU system.
We are supporting modify_xen_mappings() in MPU system too, and it is responsible for modifying memory permission of a existing MPU memory region. Currently, we only support modifying a *WHOLE* MPU memory region, part-region modification is not supported, as in worst case, it will leave three fragments behind.
In MPU system, we map init text and init data section, each with a MPU memory region. So we shall destroy it seperately in free_init_memory().
---
v3:
- As MMU and MPU could share a lot of codes, we made the changes in original function free_init_memory() in mm.c
--- xen/arch/arm/mm.c | 14 +++++++++++++- xen/arch/arm/mpu/mm.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-)
xen/arch/arm/mm.c +13 -1
@@ -177,7 +177,12 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags)ASSERT (IS_ALIGNED (s,PAGE_SIZE ));ASSERT (IS_ALIGNED (e,PAGE_SIZE ));ASSERT (s <= e); +#ifndef CONFIG_HAS_MPU return xen_pt_update (s,INVALID_MFN , (e - s) >>PAGE_SHIFT , flags); +#else +return xen_mpumap_update (virt_to_maddr ((void *)s), +virt_to_maddr ((void *)e), flags); +#endif }/* Release all __init and __initdata ranges to be reused */
@@ -212,10 +217,17 @@ void free_init_memory(void)for ( i =0 ; i < nr; i++ ) *(p + i) = insn; +/* Remove init text section */ rc =destroy_xen_mappings ((unsigned long )__init_begin, + (unsigned long )inittext_end); +if ( rc ) +panic ("Unable to remove the init text section (rc = %d)\n" , rc); + +/* Remove init data section */ + rc =destroy_xen_mappings ((unsigned long )inittext_end, (unsigned long )__init_end);if ( rc ) -panic ("Unable to remove the init section (rc = %d)\n" , rc); +panic ("Unable to remove the init data section (rc = %d)\n" , rc);if ( !xen_is_using_staticheap () ) {
xen/arch/arm/mpu/mm.c +32 -1
@@ -496,8 +496,39 @@ static int xen_mpumap_update_entry(paddr_t base, paddr_t limit,if ( (rc <0 ) || (rc ==MPUMAP_REGION_OVERLAP ) )return -EINVAL ; +/* We are updating the permission. */ +if ( (flags & _PAGE_PRESENT) && (rc ==MPUMAP_REGION_FOUND || + rc ==MPUMAP_REGION_INCLUSIVE ) ) + { +/* +* Currently, we only support modifying a *WHOLE* MPU memory region, +* part-region modification is not supported, as in worst case, it will +* leave three fragments behind. +* part-region modification will be introduced only when actual usage +* come +*/ +if ( rc ==MPUMAP_REGION_INCLUSIVE ) + { +region_printk ("mpu: part-region modification is not supported\n" ); +return -EINVAL ; + } + +/* We don't allow changing memory attributes. */ +if (xen_mpumap[idx].prlar.reg.ai !=PAGE_AI_MASK (flags) ) + { +region_printk ("Modifying memory attributes is not allowed (0x%x -> 0x%x).\n" , + xen_mpumap[idx].prlar.reg.ai,PAGE_AI_MASK (flags)); +return -EINVAL ; + } + +/* Set new permission */ + xen_mpumap[idx].prbar.reg.ap =PAGE_AP_MASK (flags); + xen_mpumap[idx].prbar.reg.xn =PAGE_XN_MASK (flags); + +write_protection_region ((const pr_t *)(&xen_mpumap[idx]), idx); + }/* We are inserting a mapping => Create new region. */ -if ( flags & _PAGE_PRESENT ) +else if ( flags & _PAGE_PRESENT ) {if ( rc !=MPUMAP_REGION_FAILED )return -EINVAL ;
Signature · 1 line
2.25.1
PATCH v3 40/52 xen/mpu: implement remove_early_mappings in MPU system
In reply to Penny ZhengWe implement remove_early_mappings() to remove early mappings of FDT in MPU system.
When mapping FDT in early_fdt_map(), we mapped the first 2MB firstly, and check the size and then map with an extra 2MB if needed. So the unmapping shall follow the same strategy.
In MMU, we could use fixed virtual address to remove the mapping. As it is not workable for MPU, we pass the FDT physical address in remove_early_mappings() for MPU to destroy the mapping.
---
v3:
- adapt to the change of mapping FDT in two 2MB chunks if needed
--- xen/arch/arm/include/asm/mm.h | 2 +- xen/arch/arm/mmu/mm.c | 2 +- xen/arch/arm/mpu/mm.c | 15 +++++++++++++++ xen/arch/arm/setup.c | 3 +-- 4 files changed, 18 insertions(+), 4 deletions(-)
xen/arch/arm/include/asm/mm.h +1 -1
@@ -209,7 +209,7 @@ extern bool flags_has_rwx(unsigned int flags);/* Map FDT in boot pagetable */ extern void *early_fdt_map (paddr_t fdt_paddr);/* Remove early mappings */ -extern void remove_early_mappings (void ); +extern void remove_early_mappings (paddr_t dtb_paddr);/* * Allocate and initialise memory mapping for a secondary CPU. * Sets init_mm to the new memory mapping table
xen/arch/arm/mmu/mm.c +1 -1
@@ -361,7 +361,7 @@ lpae_t pte_of_xenaddr(vaddr_t va)return mfn_to_xen_entry (maddr_to_mfn (ma),MT_NORMAL ); } -void __init remove_early_mappings (void ) +void __init remove_early_mappings (paddr_t dtb_paddr) {int rc;
xen/arch/arm/mpu/mm.c +15 -0
@@ -20,9 +20,11 @@*/ #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/mm.h> #include <xen/page-size.h> #include <xen/pfn.h> +#include <xen/sizes.h> #include <asm/arm64/mpu.h> #include <asm/page.h> #include <asm/setup.h>
@@ -857,6 +859,19 @@ bool is_mm_range_mapped_transient(paddr_t pa, paddr_t len)return false; } +void __init remove_early_mappings (paddr_t dtb_paddr) +{ +paddr_t pa = dtb_paddr &PAGE_MASK , offset = dtb_paddr %PAGE_SIZE ; +uint32_t size =fdt_totalsize (maddr_to_virt (dtb_paddr)); + +if (xen_mpumap_update (pa, pa +SZ_2M ,0 ) ) +panic ("Unable to destroy early Device-Tree mapping.\n" ); + +if ( (offset + size) >SZ_2M ) +if (xen_mpumap_update (pa +SZ_2M , pa +SZ_2M +SZ_2M ,0 ) ) +panic ("Unable to destroy early Device-Tree mapping.\n" ); +} +/* * Local variables: * mode: C
xen/arch/arm/setup.c +1 -2
@@ -529,8 +529,6 @@ void __init discard_initial_modules(void) mi->nr_mods =0 ; } - -remove_early_mappings (); }/* Relocate the FDT in Xen heap */
@@ -973,6 +971,7 @@ void __init start_xen(unsigned long boot_phys_offset,* will be scrubbed (unless suppressed). */ discard_initial_modules (); +remove_early_mappings (fdt_paddr);heap_init_late ();
Signature · 1 line
2.25.1
PATCH v3 41/52 xen/mpu: Use secure hypervisor timer in MPU system
In reply to Penny ZhengAs MPU system only has one secure state, we have to use secure EL2 hypervisor timer for Xen in secure EL2.
In this patch, we introduce a new Kconfig option ARM_SECURE_STATE and a set of secure hypervisor timer registers CNTHPS_*_EL2.
We alias CNTHP_*_EL2 to CNTHPS_*_EL2 to keep the timer code flow unchanged.
---
v3:
- alias CNTHP_*_EL2 to CNTHPS_*_EL2 to avoid renaming
--- xen/arch/arm/Kconfig | 4 ++++ xen/arch/arm/include/asm/arm64/sysregs.h | 15 +++++++++++++++ 2 files changed, 19 insertions(+)
xen/arch/arm/Kconfig +4 -0
@@ -92,6 +92,10 @@ config ARM_EFI UEFI firmware. A UEFI stub is provided to allow Xen to be booted as an EFI application. +config ARM_SECURE_STATE + bool "Xen will run in Arm Secure State" + default n + config GICV3 bool "GICv3 driver" depends on !NEW_VGIC
xen/arch/arm/include/asm/arm64/sysregs.h +15 -0
@@ -514,6 +514,21 @@#endif +#ifdef CONFIG_ARM_SECURE_STATE +/* +* The Armv8-R AArch64 architecture always executes code in Secure +* state with EL2 as the highest Exception. +* +* Hypervisor timer registers for Secure EL2. +*/ +#define CNTHPS_TVAL_EL2 S3_4_C14_C5_0 +#define CNTHPS_CTL_EL2 S3_4_C14_C5_1 +#define CNTHPS_CVAL_EL2 S3_4_C14_C5_2 +#define CNTHP_TVAL_EL2 CNTHPS_TVAL_EL2 +#define CNTHP_CTL_EL2 CNTHPS_CTL_EL2 +#define CNTHP_CVAL_EL2 CNTHPS_CVAL_EL2 +#endif +/* Access to system registers */ #define WRITE_SYSREG64 (v, name) do { \
Signature · 1 line
2.25.1
PATCH v3 42/52 xen/mpu: implement setup_virt_paging for MPU system
In reply to Penny ZhengFor MMU system, setup_virt_paging is used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.
For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2
The default option will be the second, unless the platform could not support, which could be checked against MSA_frac bit in Memory Model Feature Register 0( ID_AA64MMFR0_EL1).
---
v3:
- no change
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/cpufeature.h | 7 ++ xen/arch/arm/include/asm/p2m.h | 8 +++ xen/arch/arm/include/asm/processor.h | 13 ++++ xen/arch/arm/mpu/p2m.c | 92 +++++++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 xen/arch/arm/mpu/p2m.c
xen/arch/arm/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-y += mmu/p2m.o else obj-y += mpu/mm.o obj-y += mpu/setup.o +obj-y += mpu/p2m.o endif obj-y += mm.o obj-y += monitor.o
xen/arch/arm/include/asm/cpufeature.h +7 -0
@@ -250,6 +250,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_HAS_MPU + unsigned long __res:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res0:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;
@@ -257,6 +263,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;
xen/arch/arm/include/asm/p2m.h +8 -0
@@ -16,8 +16,16 @@ extern unsigned int p2m_ipa_bits;extern unsigned int p2m_root_order;extern unsigned int p2m_root_level; +#ifdef CONFIG_HAS_MPU +/* +* A 4KB Page is enough for stage 2 translation in MPU system, which could +* store at most 255 EL2 MPU memory regions. +*/ +#define P2M_ROOT_ORDER 0 +#else #define P2M_ROOT_ORDER p2m_root_order#define P2M_ROOT_LEVEL p2m_root_level +#endif #define MAX_VMID_8_BIT (1UL << 8)#define MAX_VMID_16_BIT (1UL << 16)
xen/arch/arm/include/asm/processor.h +13 -0
@@ -389,6 +389,12 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#ifdef CONFIG_HAS_MPU +#define VTCR_MSA_VMSA (_AC(0x1,UL)<<31) +#define VTCR_MSA_PMSA ~(_AC(0x1,UL)<<31) +#define NSA_SEL2 ~(_AC(0x1,UL)<<30) +#endif +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */
@@ -449,6 +455,13 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif +#ifdef CONFIG_HAS_MPU +#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif +#ifndef __ASSEMBLY__extern register_t __cpu_logical_map[];
xen/arch/arm/mpu/p2m.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 42/52] xen/mpu: implement setup_virt_paging for MPU system
Hi Penny,
Most of these are specific to ARM_64, thus we can add "#ifdef CONFIG_ARM_64" as follows :-
Quoted 91 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
For MMU system,
setup_virt_pagingis used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2
The default option will be the second, unless the platform could not support, which could be checked againstMSA_fracbit in Memory Model Feature Register 0(ID_AA64MMFR0_EL1).Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- no change--- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/cpufeature.h | 7 ++ xen/arch/arm/include/asm/p2m.h | 8 +++ xen/arch/arm/include/asm/processor.h | 13 ++++ xen/arch/arm/mpu/p2m.c | 92 +++++++++++++++++++++++++++ 5 files changed, 121 insertions(+)create mode 100644
xen/arch/arm/mpu/p2m.cxen/arch/arm/Makefile +1
-0@@ -47,6 +47,7 @@ obj-y += mmu/p2m.o else obj-y += mpu/mm.o obj-y += mpu/setup.o +obj-y += mpu/p2m.o endif obj-y += mm.o obj-y += monitor.oxen/arch/arm/include/asm/cpufeature.h +7
-0@@ -250,6 +250,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_HAS_MPU + unsigned long __res:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res0:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;@@ -257,6 +263,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;xen/arch/arm/include/asm/p2m.h +8
-0@@ -16,8 +16,16 @@ extern unsigned int p2m_ipa_bits;extern unsigned int p2m_root_order;extern unsigned int p2m_root_level; +#ifdef CONFIG_HAS_MPU +/* +* A 4KB Page is enough for stage 2 translation in MPU system, which could +* store at most 255 EL2 MPU memory regions. +*/ +#define P2M_ROOT_ORDER 0 +#else #define P2M_ROOT_ORDER p2m_root_order#define P2M_ROOT_LEVEL p2m_root_level +#endif #define MAX_VMID_8_BIT (1UL << 8)#define MAX_VMID_16_BIT (1UL << 16)xen/arch/arm/include/asm/processor.h +0
-0
xen/arch/arm/include/asm/processor.h line 392
Quoted 4 lines
xen/arch/arm/include/asm/processor.h +1
-0@@ -389,6 +389,12 @@#define VTCR_RES1 (_AC(1,UL)<<31) +#ifdef CONFIG_HAS_MPU
&& ARM_64 /* As these are specific to ID_AA64MMFR0EL1 */
xen/arch/arm/include/asm/processor.h line 458
Quoted 13 lines
xen/arch/arm/include/asm/processor.h +6
-0+#define VTCR_MSA_VMSA (_AC(0x1,UL)<<31) +#define VTCR_MSA_PMSA ~(_AC(0x1,UL)<<31) +#define NSA_SEL2 ~(_AC(0x1,UL)<<30) +#endif +/* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30))#define HCPTR_TTA ((_AC(1,U)<<20))/* Trap trace registers */ @@ -449,6 +455,13 @@#define MM64_VMID_16_BITS_SUPPORT 0x2#endif +#ifdef CONFIG_HAS_MPU
&& ARM_64 /* As these are specific to ID_AA64MMFR0EL1 */
Quoted 22 lines
xen/arch/arm/include/asm/processor.h +6
-0+#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif +#ifndef __ASSEMBLY__extern register_t __cpu_logical_map[];xen/arch/arm/mpu/p2m.c new file +7
-0@@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <xen/lib.h> +#include <xen/mm-frame.h> +#include <xen/sched.h> +#include <xen/warning.h> + +#include <asm/p2m.h>
xen/arch/arm/mpu/p2m.c line 17
Quoted 10 lines
xen/arch/arm/mpu/p2m.c new file +10
-0+#include <asm/processor.h> +#include <asm/sysregs.h> + +void __init setup_virt_paging (void ) +{ +uint64_t val =0 ; +bool p2m_vmsa = true; + +/* PA size */ +const unsigned int pa_range_info[] = {32 ,36 ,40 ,42 ,44 ,48 ,52 ,0 ,/* Invalid */ };
As this file is common between ARM_32 and ARM_64 and the following is specific to ARM_64, please add
#ifdef CONFIG_ARM_64
Quoted 47 lines
xen/arch/arm/mpu/p2m.c new file +47
-0+ +/* +* Restrict "p2m_ipa_bits" if needed. As P2M table is always configured +* with IPA bits == PA bits, compare against "pabits". +*/ +if ( pa_range_info[system_cpuinfo.mm64.pa_range] < p2m_ipa_bits ) + p2m_ipa_bits = pa_range_info[system_cpuinfo.mm64.pa_range]; + +/* In ARMV8R, hypervisor in secure EL2. */ + val &=NSA_SEL2 ; + +/* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register +* identify the memory system configurations supported at EL1. +* In Armv8-R AArch64, the only permitted value for ID_AA64MMFR0_EL1.MSA is +* 0b1111. When ID_AA64MMFR0_EL1.MSA_frac is 0b0010, the stage 1 of the +* Secure EL1&0 translation regime can enable PMSAv8-64 or VMSAv8-64 +* architecture. +*/ +if ( system_cpuinfo.mm64.msa ==MM64_MSA_PMSA_SUPPORT ) + { +if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT ) + goto fault; + +if ( system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT ) + { + p2m_vmsa = false; +warning_add ("Be aware of that there is no support for VMSAv8-64 at EL1 on this platform.\n" ); + } + } +else + goto fault; + +/* +* If PE supports both PMSAv8-64 and VMSAv8-64 at EL1, then VTCR_EL2.MSA +* determines the memory system architecture enabled at stage 1 of the +* Secure EL1&0 translation regime. +* +* Normally, we set the initial VTCR_EL2.MSA value VMSAv8-64 support, +* unless this platform only supports PMSAv8-64. +*/ +if ( !p2m_vmsa ) + val &=VTCR_MSA_PMSA ; +else + val |=VTCR_MSA_VMSA ; + +/*
xen/arch/arm/mpu/p2m.c line 74
Quoted 10 lines
xen/arch/arm/mpu/p2m.c new file +10
-0+* cpuinfo sanitization makes sure we support 16bits VMID only if +* all cores are supporting it. +*/ +if ( system_cpuinfo.mm64.vmid_bits ==MM64_VMID_16_BITS_SUPPORT ) + max_vmid =MAX_VMID_16_BIT ; + +/* Set the VS bit only if 16 bit VMID is supported. */ +if (MAX_VMID ==MAX_VMID_16_BIT ) + val |=VTCR_VS ; +
#endif
- Ayan
Quoted 22 lines
xen/arch/arm/mpu/p2m.c new file +18
-1+p2m_vmid_allocator_init (); + +WRITE_SYSREG (val,VTCR_EL2 ); + +return ; + +fault: +panic ("Hardware with no PMSAv8-64 support in any translation regime.\n" ); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ --2.25.1
Re: [PATCH v3 42/52] xen/mpu: implement setup_virt_paging for MPU system
Hi Ayan
Quoted 3 lines · Ayan Kumar Halder
Hi Penny,
Most of these are specific to
ARM_64, thus we can add "#ifdefCONFIG_ARM_64" as follows :-
Yes, you're right.
Quoted 95 lines · Penny Zheng
Quoted 93 lines
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
For MMU system,
setup_virt_pagingis used to configure stage 2 address translation regime, like IPA bits, VMID allocator set up, etc. Some could be inherited in MPU system, like VMID allocator set up, etc.For MPU system, we could have the following memory translation regime:
- PMSAv8-64 at both EL1/EL0 and EL2
- VMSAv8-64 at EL1/EL0 and PMSAv8-64 at EL2
The default option will be the second, unless the platform could not support, which could be checked againstMSA_fracbit in Memory Model Feature Register 0(ID_AA64MMFR0_EL1).Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- no change
---
xen/arch/arm/Makefile | 1 +xen/arch/arm/include/asm/cpufeature.h| 7 ++ xen/arch/arm/include/asm/p2m.h | 8 +++ xen/arch/arm/include/asm/processor.h | 13 ++++ xen/arch/arm/mpu/p2m.c | 92 +++++++++++++++++++++++++++5 files changed, 121 insertions(+)create mode 100644
xen/arch/arm/mpu/p2m.cxen/arch/arm/Makefile +0
-0@@ -47,6 +47,7 @@ obj-y += mmu/p2m.oelse
obj-y +=mpu/mm.o
obj-y +=mpu/setup.o
+obj-y +=mpu/p2m.o
endif
obj-y += mm.o
obj-y += monitor.oxen/arch/arm/include/asm/cpufeature.h +7
-0@@ -250,6 +250,12 @@ struct cpuinfo_arm { unsigned long tgranule_16K:4; unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; +#ifdef CONFIG_HAS_MPU + unsigned long __res:16; + unsigned long msa:4; + unsigned long msa_frac:4; + unsigned long __res0:8; +#else unsigned long tgranule_16k_2:4; unsigned long tgranule_64k_2:4; unsigned long tgranule_4k_2:4;@@ -257,6 +263,7 @@ struct cpuinfo_arm { unsigned long __res0:8; unsigned long fgt:4; unsigned long ecv:4; +#endif /* MMFR1 */ unsigned long hafdbs:4;xen/arch/arm/include/asm/p2m.h +3
-0@@ -16,8 +16,16 @@ extern unsigned int p2m_ipa_bits; extern unsigned int p2m_root_order; extern unsigned int p2m_root_level; +#ifdef CONFIG_HAS_MPU +/* +* A 4KB Page is enough for stage 2 translation in MPU system, which could
+ * store at most 255 EL2 MPU memory regions.
+ */xen/arch/arm/include/asm/p2m.h +2
-0+#define P2M_ROOT_ORDER 0 +#else #define P2M_ROOT_ORDER
p2m_root_order
#defineP2M_ROOT_LEVELp2m_root_level
+#endif#define MAX_VMID_8_BIT (1UL << 8)
#defineMAX_VMID_16_BIT(1UL << 16)xen/arch/arm/include/asm/processor.h +0
-0@@ -389,6 +389,12 @@
Quoted 4 lines
xen/arch/arm/include/asm/processor.h line 392
Quoted 3 lines
xen/arch/arm/include/asm/processor.h +1
-0#define VTCR_RES1 (_AC(1,UL)<<31) +#ifdef CONFIG_HAS_MPU &&
ARM_64/* As these are specific toID_AA64MMFR0EL1*/
Will do
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/include/asm/processor.h +5
-0+#define VTCR_MSA_VMSA (_AC(0x1,UL)<<31) +#define VTCR_MSA_PMSA ~(_AC(0x1,UL)<<31) +#define NSA_SEL2 ~(_AC(0x1,UL)<<30) +#endif + /* HCPTR Hyp. Coprocessor Trap Register */ #define HCPTR_TAM ((_AC(1,U)<<30)) #define HCPTR_TTA ((_AC(1,U)<<20)) /* Trap trace registers */@@ -449,6 +455,13 @@ #define MM64_VMID_16_BITS_SUPPORT 0x2 #endif
Quoted 2 lines
xen/arch/arm/include/asm/processor.h line 458
Quoted 1 line
xen/arch/arm/include/asm/processor.h +1
-0+#ifdef CONFIG_HAS_MPU &&
ARM_64/* As these are specific toID_AA64MMFR0EL1*/
Will do
Quoted 36 lines
Quoted 32 lines
xen/arch/arm/include/asm/processor.h +6
-0+#define MM64_MSA_PMSA_SUPPORT 0xf +#define MM64_MSA_FRAC_NONE_SUPPORT 0x0 +#define MM64_MSA_FRAC_PMSA_SUPPORT 0x1 +#define MM64_MSA_FRAC_VMSA_SUPPORT 0x2 +#endif + #ifndef __ASSEMBLY__ extern register_t __cpu_logical_map[];xen/arch/arm/mpu/p2m.c new file +17
-0@@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <xen/lib.h> +#include <xen/mm-frame.h> +#include <xen/sched.h> +#include <xen/warning.h> + +#include <asm/p2m.h> +#include <asm/processor.h> +#include <asm/sysregs.h> + +void __init setup_virt_paging (void ) +{ + uint64_t val = 0; + bool p2m_vmsa = true; + + /* PA size */ + const unsigned int pa_range_info[] = { 32, 36, 40, 42, 44, 48,Quoted 1 line
52, 0, /* Invalid */ };
As this file is common between
ARM_32andARM_64and the following is specific toARM_64, please add
Quoted 1 line
#ifdef
CONFIG_ARM_64
Will do
Quoted 95 lines
Quoted 57 lines
+
+ /*
+ * Restrict "p2m_ipa_bits" if needed. As P2M table is always configured
+ * with IPA bits == PA bits, compare against "pabits". + */
+ if ( pa_range_info[system_cpuinfo.mm64.pa_range] <p2m_ipa_bits) +p2m_ipa_bits= pa_range_info[system_cpuinfo.mm64.pa_range];xen/arch/arm/mpu/p2m.c new file +8
-0+ + /* In ARMV8R, hypervisor in secure EL2. */ + val &= NSA_SEL2; + + /* +* The MSA and MSA_frac fields in the ID_AA64MMFR0_EL1 register +* identify the memory system configurations supported at EL1. +* In Armv8-R AArch64, the only permitted value for ID_AA64MMFR0_EL1.MSA is
+ * 0b1111. When ID_AA64MMFR0_EL1.MSA_frac is 0b0010, the stage 1 of the
+ * Secure EL1&0 translation regime can enable PMSAv8-64 or VMSAv8-64 + * architecture.
+ */
+ if ( system_cpuinfo.mm64.msa ==MM64_MSA_PMSA_SUPPORT) + {
+ if ( system_cpuinfo.mm64.msa_frac ==MM64_MSA_FRAC_NONE_SUPPORT)
+ goto fault;
+
+ if ( system_cpuinfo.mm64.msa_frac !=MM64_MSA_FRAC_VMSA_SUPPORT)
+ {
+p2m_vmsa= false;
+warning_add("Be aware of that there is no support for VMSAv8-64 at EL1 on this platform.\n");
+ }
+ }
+ else
+ goto fault;
+
+ /*
+ * If PE supports both PMSAv8-64 and VMSAv8-64 at EL1, then VTCR_EL2.MSA
+ * determines the memory system architecture enabled at stage 1 of the
+ * Secure EL1&0 translation regime.
+ *
+ * Normally, we set the initial VTCR_EL2.MSA value VMSAv8-64 support,
+ * unless this platform only supports PMSAv8-64.
+ */
+ if ( !p2m_vmsa )
+ val &=VTCR_MSA_PMSA;
+ else
+ val |=VTCR_MSA_VMSA;xen/arch/arm/mpu/p2m.c new file +2
-0+ + /*xen/arch/arm/mpu/p2m.c line 74
Quoted 10 lines
xen/arch/arm/mpu/p2m.c new file +10
-0+* cpuinfo sanitization makes sure we support 16bits VMID only if +* all cores are supporting it. +*/ + if ( system_cpuinfo.mm64.vmid_bits == MM64_VMID_16_BITS_SUPPORT ) + max_vmid = MAX_VMID_16_BIT; + + /* Set the VS bit only if 16 bit VMID is supported. */ + if ( MAX_VMID == MAX_VMID_16_BIT ) + val |= VTCR_VS; +#endif
- Ayan
Quoted 23 lines
+
p2m_vmid_allocator_init();xen/arch/arm/mpu/p2m.c new file +7
-0+ + WRITE_SYSREG(val, VTCR_EL2); + + return; + +fault: + panic("Hardware with no PMSAv8-64 support in any translationregime.\n");
xen/arch/arm/mpu/p2m.c new file +10
-0+} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ Signature · 1 line
2.25.1
PATCH v3 43/52 xen/mpu: configure VSTCR_EL2 in MPU system
In reply to Penny ZhengVSTCR_EL2, Virtualization Secure Translation Control Register,is the control register for stage 2 of the Secure EL1&0 translation regime.
VSTCR_EL2.SA defines secure stage 2 translation output address space. To make sure that all stage 2 translations for the Secure PA space access the Secure PA space, we keep SA bit as 0. VSTCR_EL2.SC is NS check enable bit.
To make sure that Stage 2 NS configuration is checked against stage 1 NS configuration in EL1&0 translation regime for the given address, and generates a fault if they are different, we set SC bit 1.
---
v3:
- new commit
--- xen/arch/arm/include/asm/arm64/sysregs.h | 6 ++++++ xen/arch/arm/mpu/p2m.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/arm64/sysregs.h +6 -0
@@ -512,6 +512,12 @@/* MPU Protection Region Enable Register encode */ #define PRENR_EL2 S3_4_C6_C1_1 +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2 S3_4_C2_C6_2 +#define VSTCR_EL2_RES1_SHIFT 31 +#define VSTCR_EL2_SA ~(_AC(0x1,UL)<<30) +#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) +#endif #ifdef CONFIG_ARM_SECURE_STATE
xen/arch/arm/mpu/p2m.c +16 -1
@@ -10,7 +10,7 @@void __init setup_virt_paging (void ) { -uint64_t val =0 ; +uint64_t val =0 , val2 =0 ;bool p2m_vmsa = true;/* PA size */
@@ -76,6 +76,21 @@ void __init setup_virt_paging(void)WRITE_SYSREG (val,VTCR_EL2 ); +/* +* VSTCR_EL2.SA defines secure stage 2 translation output address space. +* To make sure that all stage 2 translations for the Secure PA space +* access the Secure PA space, we keep SA bit as 0. +* +* VSTCR_EL2.SC is NS check enable bit. +* To make sure that Stage 2 NS configuration is checked against stage 1 +* NS configuration in EL1&0 translation regime for the given address, and +* generates a fault if they are different, we set SC bit 1. +*/ + val2 =1 <<VSTCR_EL2_RES1_SHIFT ; + val2 &=VSTCR_EL2_SA ; + val2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (val2,VSTCR_EL2 ); +return ; fault:
Signature · 1 line
2.25.1
Re: [PATCH v3 43/52] xen/mpu: configure VSTCR_EL2 in MPU system
Quoted 55 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
VSTCR_EL2, Virtualization Secure Translation Control Register,is the control register for stage 2 of the Secure EL1&0 translation regime.VSTCR_EL2.SA defines secure stage 2 translation output address space. To make sure that all stage 2 translations for the Secure PA space access the Secure PA space, we keep SA bit as 0. VSTCR_EL2.SC is NS check enable bit.
To make sure that Stage 2 NS configuration is checked against stage 1 NS configuration in EL1&0 translation regime for the given address, and generates a fault if they are different, we set SC bit 1.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit--- xen/arch/arm/include/asm/arm64/sysregs.h | 6 ++++++ xen/arch/arm/mpu/p2m.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)xen/arch/arm/include/asm/arm64/sysregs.h +6
-0@@ -512,6 +512,12 @@/* MPU Protection Region Enable Register encode */ #define PRENR_EL2 S3_4_C6_C1_1 +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2 S3_4_C2_C6_2 +#define VSTCR_EL2_RES1_SHIFT 31 +#define VSTCR_EL2_SA ~(_AC(0x1,UL)<<30) +#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) +#endif #ifdef CONFIG_ARM_SECURE_STATE xen/arch/arm/mpu/p2m.c +1
-1@@ -10,7 +10,7 @@void __init setup_virt_paging (void ) { -uint64_t val =0 ; +uint64_t val =0 , val2 =0 ;bool p2m_vmsa = true;/* PA size */
xen/arch/arm/mpu/p2m.c void __init setup_virt_paging(void) · line 77
Quoted 2 lines
xen/arch/arm/mpu/p2m.c +0
-0@@ -76,6 +76,21 @@ void __init setup_virt_paging(void)WRITE_SYSREG (val,VTCR_EL2 );
#ifdef CONFIG_ARM_64
Quoted 5 lines
xen/arch/arm/mpu/p2m.c +4
-0+/* +* VSTCR_EL2.SA defines secure stage 2 translation output address space. +* To make sure that all stage 2 translations for the Secure PA space +* access the Secure PA space, we keep SA bit as 0.
xen/arch/arm/mpu/p2m.c void __init setup_virt_paging(void) · line 92
Quoted 10 lines
xen/arch/arm/mpu/p2m.c +10
-0+* +* VSTCR_EL2.SC is NS check enable bit. +* To make sure that Stage 2 NS configuration is checked against stage 1 +* NS configuration in EL1&0 translation regime for the given address, and +* generates a fault if they are different, we set SC bit 1. +*/ + val2 =1 <<VSTCR_EL2_RES1_SHIFT ; + val2 &=VSTCR_EL2_SA ; + val2 |=VSTCR_EL2_SC ; +WRITE_SYSREG (val2,VSTCR_EL2 );
#endif
Quoted 8 lines
xen/arch/arm/mpu/p2m.c +1
-1+return ; fault: --2.25.1
Re: [PATCH v3 43/52] xen/mpu: configure VSTCR_EL2 in MPU system
Hi Ayan
Quoted 79 lines · Ayan Kumar Halder
Quoted 55 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
VSTCR_EL2, Virtualization Secure Translation Control Register,is the control register for stage 2 of the Secure EL1&0 translation regime.VSTCR_EL2.SA defines secure stage 2 translation output address space. To make sure that all stage 2 translations for the Secure PA space access the Secure PA space, we keep SA bit as 0. VSTCR_EL2.SC is NS check enable bit.
To make sure that Stage 2 NS configuration is checked against stage 1 NS configuration in EL1&0 translation regime for the given address, and generates a fault if they are different, we set SC bit 1.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit
---
xen/arch/arm/include/asm/arm64/sysregs.h| 6 ++++++ xen/arch/arm/mpu/p2m.c | 17 ++++++++++++++++-2 files changed, 22 insertions(+), 1 deletion(-)xen/arch/arm/include/asm/arm64/sysregs.h +6
-0@@ -512,6 +512,12 @@ /* MPU Protection Region Enable Register encode */ #define PRENR_EL2 S3_4_C6_C1_1 +/* Virtualization Secure Translation Control Register */ +#define VSTCR_EL2 S3_4_C2_C6_2 +#define VSTCR_EL2_RES1_SHIFT 31 +#define VSTCR_EL2_SA ~(_AC(0x1,UL)<<30) +#define VSTCR_EL2_SC (_AC(0x1,UL)<<20) + #endif #ifdef CONFIG_ARM_SECURE_STATExen/arch/arm/mpu/p2m.c +1
-1@@ -10,7 +10,7 @@ void __init setup_virt_paging(void) { - uint64_t val = 0; + uint64_t val = 0, val2 = 0; bool p2m_vmsa = true; /* PA size */xen/arch/arm/mpu/p2m.c void __init setup_virt_paging(void) · line 77
Quoted 2 lines
xen/arch/arm/mpu/p2m.c +0
-0@@ -76,6 +76,21 @@ void __init setup_virt_paging(void) WRITE_SYSREG(val, VTCR_EL2);#ifdef
CONFIG_ARM_64Quoted 11 lines
xen/arch/arm/mpu/p2m.c +2
-0+ /* +* VSTCR_EL2.SA defines secure stage 2 translation output address space.
+ * To make sure that all stage 2 translations for the Secure PA space
+ * access the Secure PA space, we keep SA bit as 0.
+ *
+ * VSTCR_EL2.SC is NS check enable bit.
+ * To make sure that Stage 2 NS configuration is checked against stage 1Quoted 8 lines
+ * NS configuration in EL1&0 translation regime for the given address, and
+ * generates a fault if they are different, we set SC bit 1. + */
+ val2 = 1 <<VSTCR_EL2_RES1_SHIFT;
+ val2 &=VSTCR_EL2_SA;
+ val2 |=VSTCR_EL2_SC;
+WRITE_SYSREG(val2, VSTCR_EL2);
Quoted 1 line
#endif
Understood, will fix.
Quoted 8 lines
Quoted 8 lines
+
return;fault:
Signature · 1 line
2.25.1
PATCH v3 44/52 xen/mpu: P2M initialization in MPU system
In reply to Penny ZhengWe inherit p2m_init() to do P2M initialization in MPU system, including VMID assignment, setting up P2M MPU region mapping table, etc.
p2m_alloc_table() is responsible for allocating per-domain P2M MPU memory region mapping table. As a MPU memory region structure(pr_t) takes 16 bytes, even with maximum supported MPU memory regions, 255, MPU memory mapping table at most takes up less than 4KB.
VSCTLR_EL2, Virtualization System Control Register, provides configuration information for VMSAv8-64 and PMSAv8-64 virtualization using stage 2 of EL1&0 translation regime, bit[63:48] of which determines VMID for the EL1-Guest-OS.
---
v3:
- new commit
--- xen/arch/arm/include/asm/mpu/mm.h | 3 ++ xen/arch/arm/include/asm/p2m.h | 5 +++ xen/arch/arm/mpu/mm.c | 22 ++++++++++ xen/arch/arm/mpu/p2m.c | 69 +++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+)
xen/arch/arm/include/asm/mpu/mm.h +3 -0
@@ -2,6 +2,8 @@#ifndef __ARCH_ARM_MM_MPU__#define __ARCH_ARM_MM_MPU__ +#include <asm/arm64/mpu.h> +extern struct page_info *frame_table;extern unsigned long frametable_pdx_end;
@@ -11,6 +13,7 @@ extern uint8_t is_mm_range_mapped(paddr_t pa, paddr_t len);extern void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes);extern void unmap_mm_range (paddr_t pa);extern bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len); +extern pr_t *alloc_mpumap (void );#endif /* __ARCH_ARM_MM_MPU__ */
xen/arch/arm/include/asm/p2m.h +5 -0
@@ -61,8 +61,13 @@ struct p2m_domain {/* Current VMID in use */ uint16_t vmid; +#ifndef CONFIG_HAS_MPU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +uint64_t vsctlr; +#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;
xen/arch/arm/mpu/mm.c +22 -0
@@ -872,6 +872,28 @@ void __init remove_early_mappings(paddr_t dtb_paddr)panic ("Unable to destroy early Device-Tree mapping.\n" ); } +/* +* Standard entry to dynamically allocate MPU memory region mapping table. +* A 4KB page is enough for holding the maximum supported MPU memory +* regions. +*/ +pr_t *alloc_mpumap (void ) +{ +pr_t *map; + +/* +* A MPU memory region structure(pr_t) takes 16 bytes, even with maximum +* supported MPU memory regions, 255, MPU memory mapping table at most +* takes up less than 4KB. +*/ + map =alloc_xenheap_pages (0 ,0 ); +if ( map ==NULL ) +return NULL ; + +clear_page (map); +return map; +} +/* * Local variables: * mode: C
xen/arch/arm/mpu/p2m.c +69 -0
81 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 44/52] xen/mpu: P2M initialization in MPU system
Hi Penny,
Quoted 33 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
We inherit
p2m_init()to do P2M initialization in MPU system, including VMID assignment, setting up P2M MPU region mapping table, etc.
p2m_alloc_table()is responsible for allocating per-domain P2M MPU memory region mapping table. As a MPU memory regionstructure(pr_t)takes 16 bytes, even with maximum supported MPU memory regions, 255, MPU memory mapping table at most takes up less than 4KB.
VSCTLR_EL2, Virtualization System Control Register, provides configuration information for VMSAv8-64 and PMSAv8-64 virtualization using stage 2 of EL1&0 translation regime, bit[63:48] of which determines VMID for the EL1-Guest-OS.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit--- xen/arch/arm/include/asm/mpu/mm.h | 3 ++ xen/arch/arm/include/asm/p2m.h | 5 +++ xen/arch/arm/mpu/mm.c | 22 ++++++++++ xen/arch/arm/mpu/p2m.c | 69 +++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+)xen/arch/arm/include/asm/mpu/mm.h +0
-0
xen/arch/arm/include/asm/mpu/mm.h line 3
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h +0
-0@@ -2,6 +2,8 @@#ifndef __ARCH_ARM_MM_MPU__#define __ARCH_ARM_MM_MPU__
#ifdef CONFIG_ARM_64
xen/arch/arm/include/asm/mpu/mm.h line 5
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+#include <asm/arm64/mpu.h>
#endif
Quoted 17 lines
xen/arch/arm/include/asm/mpu/mm.h +2
-0+extern struct page_info *frame_table;extern unsigned long frametable_pdx_end;@@ -11,6 +13,7 @@ extern uint8_t is_mm_range_mapped(paddr_t pa, paddr_t len);extern void *map_mm_range (paddr_t pa,size_t len,unsigned int attributes);extern void unmap_mm_range (paddr_t pa);extern bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len); +extern pr_t *alloc_mpumap (void );#endif /* __ARCH_ARM_MM_MPU__ */ xen/arch/arm/include/asm/p2m.h +0
-0
xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 69
Quoted 9 lines
xen/arch/arm/include/asm/p2m.h +4
-0@@ -61,8 +61,13 @@ struct p2m_domain {/* Current VMID in use */ uint16_t vmid; +#ifndef CONFIG_HAS_MPU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else +/* Current Virtualization System Control Register for the p2m */ +uint64_t vsctlr;
register_t vsctlr;
So that it is 64-bit for ARM_64 and 32-bit for ARM_32.
Quoted 50 lines
xen/arch/arm/include/asm/p2m.h +1
-0+#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;xen/arch/arm/mpu/mm.c +22
-0@@ -872,6 +872,28 @@ void __init remove_early_mappings(paddr_t dtb_paddr)panic ("Unable to destroy early Device-Tree mapping.\n" ); } +/* +* Standard entry to dynamically allocate MPU memory region mapping table. +* A 4KB page is enough for holding the maximum supported MPU memory +* regions. +*/ +pr_t *alloc_mpumap (void ) +{ +pr_t *map; + +/* +* A MPU memory region structure(pr_t) takes 16 bytes, even with maximum +* supported MPU memory regions, 255, MPU memory mapping table at most +* takes up less than 4KB. +*/ + map =alloc_xenheap_pages (0 ,0 ); +if ( map ==NULL ) +return NULL ; + +clear_page (map); +return map; +} +/* * Local variables: * mode: C xen/arch/arm/mpu/p2m.c +1
-0@@ -4,6 +4,7 @@#include <xen/sched.h> #include <xen/warning.h> +#include <asm/mpu/mm.h> #include <asm/p2m.h> #include <asm/processor.h> #include <asm/sysregs.h>
xen/arch/arm/mpu/p2m.c fault: · line 104
Quoted 7 lines
xen/arch/arm/mpu/p2m.c +4
-0@@ -97,6 +98,74 @@ fault:panic ("Hardware with no PMSAv8-64 support in any translation regime.\n" ); } +static uint64_t __init generate_vsctlr (uint16_t vmid) +{ +return ((uint64_t )vmid <<48 ); +}
Please move ^^^ to ./xen/arch/arm/include/asm/arm64/mpu.h as it differs between R82 and R52
- Ayan
Quoted 71 lines
xen/arch/arm/mpu/p2m.c +64
-1+ +static int __init p2m_alloc_table (struct domain *d) +{ +struct p2m_domain *p2m =p2m_get_hostp2m (d); +pr_t * p2m_map; + + p2m_map =alloc_mpumap (); +if ( !p2m_map ) + { +printk (XENLOG_G_ERR "DOM%pd: p2m: unable to allocate P2M MPU mapping table\n" , d); +return -ENOMEM ; + } + + p2m->root =virt_to_page ((const void *)p2m_map); + +return 0 ; +} + +int p2m_init (struct domain *d) +{ +struct p2m_domain *p2m =p2m_get_hostp2m (d); +int rc =0 ; +unsigned int cpu; + +rwlock_init (&p2m->lock); +spin_lock_init (&d->arch.paging.lock); + + p2m->vmid =INVALID_VMID ; + p2m->max_mapped_gfn =_gfn (0 ); + p2m->lowest_mapped_gfn =_gfn (ULONG_MAX ); + + p2m->default_access = p2m_access_rwx; +/* mem_access is NOT supported in MPU system. */ + p2m->mem_access_enabled = false; + +/* +* Make sure that the type chosen to is able to store an vCPU ID +* between 0 and the maximum of virtual CPUS supported as long as +* the INVALID_VCPU_ID. +*/ +BUILD_BUG_ON ((1 << (sizeof (p2m->last_vcpu_ran[0 ]) *8 )) <MAX_VIRT_CPUS ); +BUILD_BUG_ON ((1 << (sizeof (p2m->last_vcpu_ran[0 ]) *8 )) <INVALID_VCPU_ID ); + +for_each_possible_cpu (cpu) + p2m->last_vcpu_ran[cpu] =INVALID_VCPU_ID ; + +/* +* "Trivial" initialisation is now complete. Set the backpointer so +* p2m_teardown() and friends know to do something. +*/ + p2m->domain = d; + + rc =p2m_alloc_vmid (d); +if ( rc ) +return rc; + p2m->vsctlr =generate_vsctlr (p2m->vmid); + + rc =p2m_alloc_table (d); +if ( rc ) +return rc; + +return rc; +} +/* * Local variables: * mode: C -- 2.25.1
Re: [PATCH v3 44/52] xen/mpu: P2M initialization in MPU system
Hi, Ayan
Quoted 71 lines · Ayan Kumar Halder
Hi Penny,
Quoted 33 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
We inherit
p2m_init()to do P2M initialization in MPU system, including VMID assignment, setting up P2M MPU region mapping table, etc.
p2m_alloc_table()is responsible for allocating per-domain P2M MPU memory region mapping table. As a MPU memory regionstructure(pr_t)takes 16 bytes, even with maximum supported MPU memory regions, 255, MPU memory mapping table at most takes up less than 4KB.
VSCTLR_EL2, Virtualization System Control Register, provides configuration information for VMSAv8-64 and PMSAv8-64 virtualization using stage 2 of EL1&0 translation regime, bit[63:48] of which determines VMID for the EL1-Guest-OS.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit
---
xen/arch/arm/include/asm/mpu/mm.h| 3 ++ xen/arch/arm/include/asm/p2m.h | 5 +++ xen/arch/arm/mpu/mm.c | 22 ++++++++++ xen/arch/arm/mpu/p2m.c | 69 +++++++++++++++++++++++++++++++4 files changed, 99 insertions(+)xen/arch/arm/include/asm/mpu/mm.h +0
-0xen/arch/arm/include/asm/mpu/mm.h line 3
Quoted 2 lines
xen/arch/arm/include/asm/mpu/mm.h +0
-0@@ -2,6 +2,8 @@ #ifndef __ARCH_ARM_MM_MPU__ #define __ARCH_ARM_MM_MPU__#ifdef
CONFIG_ARM_64xen/arch/arm/include/asm/mpu/mm.h line 5
Quoted 1 line
xen/arch/arm/include/asm/mpu/mm.h +1
-0+#include <asm/arm64/mpu.h> #endif
Quoted 18 lines
xen/arch/arm/include/asm/mpu/mm.h +2
-0+ extern struct page_info *frame_table; extern unsigned long frametable_pdx_end;@@ -11,6 +13,7 @@ extern uint8_t is_mm_range_mapped(paddr_t pa, paddr_t len); extern void *map_mm_range(paddr_t pa, size_t len, unsigned int attributes); extern void unmap_mm_range(paddr_t pa); extern bool is_mm_range_mapped_transient(paddr_t pa, paddr_t len); +extern pr_t *alloc_mpumap (void ); #endif /* __ARCH_ARM_MM_MPU__ */xen/arch/arm/include/asm/p2m.h +0
-0xen/arch/arm/include/asm/p2m.h struct p2m_domain { · line 69
Quoted 9 lines
xen/arch/arm/include/asm/p2m.h +4
-0@@ -61,8 +61,13 @@ struct p2m_domain { /* Current VMID in use */ uint16_t vmid; +#ifndef CONFIG_HAS_MPU /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; +#else + /* Current Virtualization System Control Register for the p2m */ + uint64_t vsctlr;
register_tvsctlr;
Quoted 2 lines
So that it is 64-bit for
ARM_64and 32-bit forARM_32.
Understood, will fix
Quoted 56 lines
Quoted 56 lines
xen/arch/arm/include/asm/p2m.h +1
-0+#endif /* Highest guest frame that's ever been mapped in the p2m */ gfn_t max_mapped_gfn;xen/arch/arm/mpu/mm.c +2
-0@@ -872,6 +872,28 @@ void __init remove_early_mappings(paddr_t dtb_paddr) panic("Unable to destroy early Device-Tree mapping.\n"); } +/* +* Standard entry to dynamically allocate MPU memory region mapping table.
+ * A 4KB page is enough for holding the maximum supported MPU memory
+ * regions.
+ */xen/arch/arm/mpu/mm.c +6
-0+pr_t *alloc_mpumap (void ) +{ + pr_t *map; + + /* +* A MPU memory region structure(pr_t) takes 16 bytes, even with maximum
+ * supported MPU memory regions, 255, MPU memory mapping table at most
+ * takes up less than 4KB.
+ */
+ map =alloc_xenheap_pages(0, 0);
+ if ( map == NULL )
+ return NULL;xen/arch/arm/mpu/mm.c +5
-0+ + clear_page(map); + return map; +} +/*
* Local variables:
* mode: Cxen/arch/arm/mpu/p2m.c +1
-0@@ -4,6 +4,7 @@ #include <xen/sched.h> #include <xen/warning.h> +#include <asm/mpu/mm.h> #include <asm/p2m.h> #include <asm/processor.h> #include <asm/sysregs.h>@@ -97,6 +98,74 @@ fault: panic("Hardware with no PMSAv8-64 support in any translation regime.\n"); }
Quoted 7 lines
xen/arch/arm/mpu/p2m.c fault: · line 104
Quoted 4 lines
xen/arch/arm/mpu/p2m.c +4
-0+static uint64_t __init generate_vsctlr (uint16_t vmid) +{ + return ((uint64_t)vmid << 48); +}Please move ^^^ to
./xen/arch/arm/include/asm/arm64/mpu.has it differs between R82 and R52
Sure, will do
Quoted 76 lines
- Ayan
Quoted 74 lines
xen/arch/arm/mpu/p2m.c +64
-0+ +static int __init p2m_alloc_table (struct domain *d) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + pr_t* p2m_map; + + p2m_map = alloc_mpumap(); + if ( !p2m_map ) + { + printk(XENLOG_G_ERR "DOM%pd: p2m: unable to allocate P2M MPU mapping table\n", d); + return -ENOMEM; + } + + p2m->root = virt_to_page((const void *)p2m_map); + + return 0; +} + +int p2m_init (struct domain *d) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + int rc = 0; + unsigned int cpu; + + rwlock_init(&p2m->lock); + spin_lock_init(&d->arch.paging.lock); + + p2m->vmid = INVALID_VMID; + p2m->max_mapped_gfn = _gfn(0); + p2m->lowest_mapped_gfn = _gfn(ULONG_MAX); + + p2m->default_access = p2m_access_rwx; + /* mem_access is NOT supported in MPU system. */ + p2m->mem_access_enabled = false; + + /* + * Make sure that the type chosen to is able to store an vCPU ID + * between 0 and the maximum of virtual CPUS supported as long as + * the INVALID_VCPU_ID. + */ + BUILD_BUG_ON((1 << (sizeof(p2m->last_vcpu_ran[0]) * 8)) <MAX_VIRT_CPUS ); + BUILD_BUG_ON((1 << (sizeof(p2m->last_vcpu_ran[0]) * 8)) <INVALID_VCPU_ID ); + + for_each_possible_cpu(cpu) + p2m->last_vcpu_ran[cpu] = INVALID_VCPU_ID; + + /* + * "Trivial" initialisation is now complete. Set the backpointer so + * p2m_teardown() and friends know to do something. + */ + p2m->domain = d; + + rc = p2m_alloc_vmid(d); + if ( rc ) + return rc; + p2m->vsctlr = generate_vsctlr(p2m->vmid); + + rc = p2m_alloc_table(d); + if ( rc ) + return rc; + + return rc; +} +/*
* Local variables:
* mode: CSignature · 1 line
2.25.1
PATCH v3 45/52 xen/mpu: insert an new entry into guest physmap in MPU system
In reply to Penny ZhengFunction p2m_set_entry/__p2m_set_entry is responsible for inserting an entry in the p2m. In MPU system, it includes the following steps:
- checking whether mapping already exists(sgfn -> mfn)
- constituting a new P2M MPU memory region structure(pr_t) through standard entry region_to_p2m_entry()
- insert the new entry into domain P2M table(p2m->root)
---
v3:
- new commit
--- xen/arch/arm/include/asm/arm64/mpu.h | 3 +- xen/arch/arm/include/asm/mpu/mm.h | 6 + xen/arch/arm/include/asm/p2m.h | 3 + xen/arch/arm/mpu/mm.c | 4 +- xen/arch/arm/mpu/p2m.c | 172 +++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/arm64/mpu.h +2 -1
@@ -61,7 +61,8 @@ typedef union { unsigned long ap:2; /* Acess Permission */ unsigned long sh:2; /* Sharebility */ unsigned long base:42; /* Base Address */ - unsigned long pad:16; + unsigned long pad:12; + unsigned long p2m_type:4; /* Ignore by hardware. Used to store p2m types.*/ } reg;uint64_t bits; } prbar_t;
xen/arch/arm/include/asm/mpu/mm.h +6 -0
@@ -14,6 +14,12 @@ extern void *map_mm_range(paddr_t pa, size_t len, unsigned int attributes);extern void unmap_mm_range (paddr_t pa);extern bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len);extern pr_t *alloc_mpumap (void ); +#define MPUMAP_REGION_FAILED 0 +#define MPUMAP_REGION_FOUND 1 +#define MPUMAP_REGION_INCLUSIVE 2 +#define MPUMAP_REGION_OVERLAP 3 +extern int mpumap_contain_region (pr_t *table,uint8_t nr_regions, +paddr_t base,paddr_t limit,uint8_t *index);#endif /* __ARCH_ARM_MM_MPU__ */
xen/arch/arm/include/asm/p2m.h +3 -0
@@ -67,6 +67,9 @@ struct p2m_domain {#else /* Current Virtualization System Control Register for the p2m */ uint64_t vsctlr; + +/* Number of MPU memory regions in P2M MPU memory mapping table. */ +uint8_t nr_regions;#endif /* Highest guest frame that's ever been mapped in the p2m */
xen/arch/arm/mpu/mm.c +2 -2
@@ -378,8 +378,8 @@ out:* MPUMAP_REGION_INCLUSIVE: find an inclusive match in #table * MPUMAP_REGION_OVERLAP: overlap with the existing mapping */ -static int mpumap_contain_region (pr_t *table,uint8_t nr_regions, -paddr_t base,paddr_t limit,uint8_t *index) +int mpumap_contain_region (pr_t *table,uint8_t nr_regions, +paddr_t base,paddr_t limit,uint8_t *index) {uint8_t i =0 , _index =INVALID_REGION_IDX ;
xen/arch/arm/mpu/p2m.c +172 -0
178 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 45/52] xen/mpu: insert an new entry into guest physmap in MPU system
Quoted 28 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Function p2m_set_entry/__p2m_set_entry is responsible for inserting an entry in the p2m. In MPU system, it includes the following steps:
- checking whether mapping alreadyexists(sgfn -> mfn)
- constituting a new P2M MPU memory regionstructure(pr_t)through standard entryregion_to_p2m_entry()
- insert the new entry into domain P2Mtable(p2m->root)Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- new commit--- xen/arch/arm/include/asm/arm64/mpu.h | 3 +- xen/arch/arm/include/asm/mpu/mm.h | 6 + xen/arch/arm/include/asm/p2m.h | 3 + xen/arch/arm/mpu/mm.c | 4 +- xen/arch/arm/mpu/p2m.c | 172 +++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 3 deletions(-)xen/arch/arm/include/asm/arm64/mpu.h +0
-0
xen/arch/arm/include/asm/arm64/mpu.h typedef union { · line 65
Quoted 6 lines
xen/arch/arm/include/asm/arm64/mpu.h +2
-1@@ -61,7 +61,8 @@ typedef union { unsigned long ap:2; /* Acess Permission */ unsigned long sh:2; /* Sharebility */ unsigned long base:42; /* Base Address */ - unsigned long pad:16; + unsigned long pad:12; + unsigned long p2m_type:4; /* Ignore by hardware. Used to store p2m types.*/
This will change based on the outcome of " [PATCH v3 31/52] xen/mpu: make early_fdt_map support in MPU systems".
Anyhow, we can't use RES0 bits for software purposes.
- Ayan
Quoted 236 lines
xen/arch/arm/include/asm/arm64/mpu.h +0
-0} reg;uint64_t bits; } prbar_t;xen/arch/arm/include/asm/mpu/mm.h +6
-0@@ -14,6 +14,12 @@ extern void *map_mm_range(paddr_t pa, size_t len, unsigned int attributes);extern void unmap_mm_range (paddr_t pa);extern bool is_mm_range_mapped_transient (paddr_t pa,paddr_t len);extern pr_t *alloc_mpumap (void ); +#define MPUMAP_REGION_FAILED 0 +#define MPUMAP_REGION_FOUND 1 +#define MPUMAP_REGION_INCLUSIVE 2 +#define MPUMAP_REGION_OVERLAP 3 +extern int mpumap_contain_region (pr_t *table,uint8_t nr_regions, +paddr_t base,paddr_t limit,uint8_t *index);#endif /* __ARCH_ARM_MM_MPU__ */ xen/arch/arm/include/asm/p2m.h +3
-0@@ -67,6 +67,9 @@ struct p2m_domain {#else /* Current Virtualization System Control Register for the p2m */ uint64_t vsctlr; + +/* Number of MPU memory regions in P2M MPU memory mapping table. */ +uint8_t nr_regions;#endif /* Highest guest frame that's ever been mapped in the p2m */ xen/arch/arm/mpu/mm.c +2
-2@@ -378,8 +378,8 @@ out:* MPUMAP_REGION_INCLUSIVE: find an inclusive match in #table * MPUMAP_REGION_OVERLAP: overlap with the existing mapping */ -static int mpumap_contain_region (pr_t *table,uint8_t nr_regions, -paddr_t base,paddr_t limit,uint8_t *index) +int mpumap_contain_region (pr_t *table,uint8_t nr_regions, +paddr_t base,paddr_t limit,uint8_t *index) {uint8_t i =0 , _index =INVALID_REGION_IDX ;xen/arch/arm/mpu/p2m.c +172
-1@@ -166,6 +166,178 @@ int p2m_init(struct domain *d)return rc; } +static void p2m_set_permission (pr_t *region,p2m_type_t t) +{ +switch ( t ) + { +case p2m_ram_rw: + region->prbar.reg.xn =XN_DISABLED ; + region->prbar.reg.ap =AP_RW_ALL ; +break ; + +case p2m_ram_ro: + region->prbar.reg.xn =XN_DISABLED ; + region->prbar.reg.ap =AP_RO_ALL ; +break ; + +case p2m_invalid: + region->prbar.reg.xn =XN_P2M_ENABLED ; + region->prbar.reg.ap =AP_RO_ALL ; +break ; + +case p2m_max_real_type: +BUG (); +break ; + +case p2m_mmio_direct_dev: +case p2m_mmio_direct_nc: +case p2m_mmio_direct_c: +case p2m_iommu_map_ro: +case p2m_iommu_map_rw: +case p2m_map_foreign_ro: +case p2m_map_foreign_rw: +case p2m_grant_map_ro: +case p2m_grant_map_rw: +panic (XENLOG_G_ERR "p2m: UNIMPLEMENTED p2m permission in MPU system\n" ); +break ; + } +} + +static inline pr_t region_to_p2m_entry (mfn_t smfn,unsigned long nr_mfn, +p2m_type_t t) +{ +prbar_t prbar; +prlar_t prlar; +pr_t region; + + prbar = (prbar_t ) { + .reg = { + .p2m_type = t,/* P2M Type */ + }}; + + prlar = (prlar_t ) { + .reg = { + .ns =0 ,/* Hyp mode is in secure world */ + .en =1 ,/* Region enabled */ + }}; + +BUILD_BUG_ON (p2m_max_real_type > (1 <<4 )); + +switch ( t ) + { +case p2m_invalid: +case p2m_ram_rw: +case p2m_ram_ro: +case p2m_max_real_type: + prbar.reg.sh =LPAE_SH_INNER ; + prlar.reg.ai =MT_NORMAL ; +break ; + +default : +panic (XENLOG_G_ERR "p2m: UNIMPLEMENTED p2m type in MPU system\n" ); +break ; + } + + region = (pr_t ) { + .prbar = prbar, + .prlar = prlar, + }; + +/* +* xn and ap bit will be defined in the p2m_set_permission +* based on t. +*/ +p2m_set_permission (®ion, t); + +/* Set base address and limit address */ +pr_set_base (®ion,mfn_to_maddr (smfn)); +pr_set_limit (®ion, (mfn_to_maddr (mfn_add (smfn, nr_mfn)) -1 )); + +return region; +} + +/* +* Check whether guest memory [sgfn, sgfn + nr_gfns) is mapped. +* +* If it is mapped, the index of associated MPU memory region will be filled +* up, and 0 is returned. +* If it is not mapped, -ENOENT errno will be returned. +*/ +static int is_gfns_mapped (struct p2m_domain *p2m,gfn_t sgfn, +unsigned long nr_gfns,uint8_t *idx) +{ +paddr_t gbase =gfn_to_gaddr (sgfn), + glimit =gfn_to_gaddr (gfn_add (sgfn, nr_gfns)) -1 ; +int rc; +pr_t *table; + + table = (pr_t *)page_to_virt (p2m->root); +if ( !table ) +return -EEXIST ; + + rc =mpumap_contain_region (table, p2m->nr_regions, gbase, glimit, idx); +if ( (rc ==MPUMAP_REGION_FOUND ) || (rc ==MPUMAP_REGION_INCLUSIVE ) ) +return 0 ; +else if ( rc ==MPUMAP_REGION_FAILED ) +return -ENOENT ; + +/* Partially mapped */ +return -EINVAL ; +} + +int __p2m_set_entry (struct p2m_domain *p2m,gfn_t sgfn,unsigned int nr, +mfn_t smfn,p2m_type_t t,p2m_access_t a) +{ +pr_t *table; +mfn_t emfn =mfn_add (smfn, nr); +uint8_t idx =INVALID_REGION_IDX ; + +/* +* Other than removing mapping (i.e MFN_INVALID), +* gfn == mfn in MPU system. +*/ +if ( !mfn_eq (smfn,INVALID_MFN ) ) +if (gfn_x (sgfn) !=mfn_x (smfn) ) + { +printk (XENLOG_G_ERR "Unable to map MFN %#" PRI_mfn" at %#" PRI_mfn"\n" , +mfn_x (smfn),gfn_x (sgfn)); +return -EINVAL ; + } + +if (is_gfns_mapped (p2m, sgfn, nr, &idx) != -ENOENT ) + { +printk (XENLOG_G_ERR "p2m: unable to insert P2M MPU memory region 0x%" PRIpaddr"-0x%" PRIpaddr"\n" , +gfn_to_gaddr (sgfn),gfn_to_gaddr (gfn_add (sgfn, nr))); +return -EINVAL ; + } + + table = (pr_t *)page_to_virt (p2m->root); +if ( !table ) +return -EEXIST ; + table[p2m->nr_regions] =region_to_p2m_entry (smfn, nr, t); + p2m->nr_regions++; + + p2m->max_mapped_gfn =gfn_max (p2m->max_mapped_gfn,_gfn (mfn_x (emfn))); + p2m->lowest_mapped_gfn =gfn_min (p2m->lowest_mapped_gfn,_gfn (mfn_x (smfn))); + +return 0 ; +} + +int p2m_set_entry (struct p2m_domain *p2m,gfn_t sgfn,unsigned long nr, +mfn_t smfn,p2m_type_t t,p2m_access_t a) +{ +/* +* Any reference taken by the P2M mappings (e.g. foreign mapping) will +* be dropped in relinquish_p2m_mapping(). As the P2M will still +* be accessible after, we need to prevent mapping to be added when the +* domain is dying. +*/ +if (unlikely (p2m->domain->is_dying) ) +return -ENOMEM ; + +return __p2m_set_entry (p2m, sgfn, nr, smfn, t, a); +} +/* * Local variables: * mode: C -- 2.25.1
PATCH v3 46/52 xen/mpu: look up entry in p2m table
In reply to Penny ZhengFunction p2m_lookup() is responsible for looking up an entry in p2m table. In MPU system, We check whether mapping exists. If it does, we get the details of the guest MPU memory region in domain P2M table(p2m->root) through p2m_get_mpu_region()
---
v3:
- new commit
--- xen/arch/arm/include/asm/mpu/p2m.h | 18 ++++++++ xen/arch/arm/include/asm/p2m.h | 2 + xen/arch/arm/mpu/p2m.c | 73 ++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 xen/arch/arm/include/asm/mpu/p2m.h
xen/arch/arm/include/asm/mpu/p2m.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _XEN_P2M_MPU_H +#define _XEN_P2M_MPU_H + +static inline bool region_is_p2m_valid (pr_t *pr) +{ +return (pr->prbar.reg.p2m_type != p2m_invalid); +} + +#endif /* _XEN_P2M_MPU_H */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/include/asm/p2m.h +2 -0
@@ -188,6 +188,8 @@ typedef enum {#ifdef CONFIG_HAS_MMU #include <asm/mmu/p2m.h> +#else +#include <asm/mpu/p2m.h> #endif static inline bool arch_acquire_resource_check (struct domain *d)
xen/arch/arm/mpu/p2m.c +73 -0
79 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 47/52 xen/mpu: support vcpu context switch in MPU system
In reply to Penny ZhengWhen vcpu switching into guest mode, in MMU system, we update VTTBR_EL2 with the incoming guest's P2M table, simple and fast.
While in MPU system, we have MPU register PRBAR_EL2/PRLAR_EL2 for both stage 1 EL2 address translation and stage 2 EL1&EL0 address translation. That is, MPU memory region mapping table(xen_mpumap) shall be also updated with P2M regions during context switch.
In p2m_save_state(), we need to manually disable all P2M MPU memory regions from last-running vcpu, and in p2m_restore_state(), we need to manually enable incoming guest's P2M MPU memory regions.
---
v3:
- new commit
--- xen/arch/arm/include/asm/arm64/sysregs.h | 3 ++ xen/arch/arm/include/asm/page.h | 4 ++ xen/arch/arm/mpu/mm.c | 6 ++- xen/arch/arm/mpu/p2m.c | 61 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/arm64/sysregs.h +3 -0
@@ -512,6 +512,9 @@/* MPU Protection Region Enable Register encode */ #define PRENR_EL2 S3_4_C6_C1_1 +/* Virtualization System Control Register */ +#define VSCTLR_EL2 S3_4_C2_C0_0 +/* Virtualization Secure Translation Control Register */ #define VSTCR_EL2 S3_4_C2_C6_2#define VSTCR_EL2_RES1_SHIFT 31
xen/arch/arm/include/asm/page.h +4 -0
@@ -99,22 +99,26 @@* [7] Region Present * [8] Transient Region, e.g. MPU memory region is temproraily * mapped for a short time +* [9] P2M Region for stage 2 translation */ #define _PAGE_AI_BIT 0#define _PAGE_XN_BIT 3#define _PAGE_AP_BIT 5#define _PAGE_PRESENT_BIT 7#define _PAGE_TRANSIENT_BIT 8 +#define _PAGE_P2M_BIT 9#define _PAGE_AI (7U << _PAGE_AI_BIT)#define _PAGE_XN (2U << _PAGE_XN_BIT)#define _PAGE_RO (2U << _PAGE_AP_BIT)#define _PAGE_PRESENT (1U << _PAGE_PRESENT_BIT)#define _PAGE_TRANSIENT (1U << _PAGE_TRANSIENT_BIT) +#define _PAGE_P2M (1U << _PAGE_P2M_BIT)#define PAGE_AI_MASK (x) (((x) >> _PAGE_AI_BIT) & 0x7U)#define PAGE_XN_MASK (x) (((x) >> _PAGE_XN_BIT) & 0x3U)#define PAGE_AP_MASK (x) (((x) >> _PAGE_AP_BIT) & 0x3U)#define PAGE_RO_MASK (x) (((x) >> _PAGE_AP_BIT) & 0x2U)#define PAGE_TRANSIENT_MASK (x) (((x) >> _PAGE_TRANSIENT_BIT) & 0x1U) +#define PAGE_P2M_MASK (x) (((x) >> _PAGE_P2M_BIT) & 0x1U)#endif /* CONFIG_HAS_MPU */ /*
xen/arch/arm/mpu/mm.c +5 -1
@@ -580,7 +580,11 @@ int xen_mpumap_update(paddr_t base, paddr_t limit, unsigned int flags) {int rc; -if (flags_has_rwx (flags) ) +/* +* Mappings should not be both Writeable and Executable, unless +* it is for guest P2M mapping. +*/ +if (flags_has_rwx (flags) && !PAGE_P2M_MASK (flags) ) {region_printk ("Mappings should not be both Writeable and Executable\n" );return -EINVAL ;
xen/arch/arm/mpu/p2m.c +61 -0
67 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 48/52 xen/mpu: enable MMIO region trap in MPU system
In reply to Penny ZhengMMIO region traps, generating from insufficient access permissions, will lead to data abort with Permission Fault in MPU system.
It is different with MMU system, which generates Translation Fault instead.
We extract common codes for dealing with MMIO trap into a new helper do_mmio_trap_stage2_abort_guest().
---
v3:
- new commit
--- xen/arch/arm/traps.c | 81 +++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 27 deletions(-)
xen/arch/arm/traps.c +54 -27
@@ -1848,6 +1848,45 @@ static inline bool check_p2m(bool is_data, paddr_t gpa)return false; } +static int do_mmio_trap_stage2_abort_guest (struct cpu_user_regs *regs, +const union hsr hsr, +mmio_info_t *info, +vaddr_t gva,paddr_t gpa) +{ +enum io_state state; + + state =try_handle_mmio (regs, info); +switch ( state ) + { +case IO_ABORT : + goto inject_abt; +case IO_HANDLED : +/* +* If the instruction was decoded and has executed successfully +* on the MMIO region, then Xen should execute the next part of +* the instruction. (for eg increment the rn if it is a +* post-indexing instruction. +*/ +finalize_instr_emulation (&info->dabt_instr); +advance_pc (regs, hsr); +return 0 ; +case IO_RETRY : +/* finish later */ +return 0 ; +case IO_UNHANDLED : +/* IO unhandled, try another way to handle it. */ +return -EFAULT ; + } + +inject_abt: +gdprintk (XENLOG_DEBUG , +"HSR=%#" PRIregister" pc=%#" PRIregister" gva=%#" PRIvaddr" gpa=%#" PRIpaddr"\n" , + hsr.bits, regs->pc, gva, gpa); +inject_dabt_exception (regs, gva, hsr.len); + +return 0 ; +} +static void do_trap_stage2_abort_guest (struct cpu_user_regs *regs,const union hsr hsr) {
@@ -1862,7 +1901,6 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,uint8_t fsc = xabt.fsc & ~FSC_LL_MASK ;bool is_data = (hsr.ec ==HSR_EC_DATA_ABORT_LOWER_EL );mmio_info_t info; -enum io_state state;/* * If this bit has been set, it means that this stage-2 abort is caused
@@ -1896,6 +1934,8 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,return ;/* Try again */ } + info.gpa = gpa; + info.dabt = hsr.dabt;switch ( fsc ) {case FSC_FLT_PERM :
@@ -1909,6 +1949,17 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, };p2m_mem_access_check (gpa, gva, npfec); + +#ifdef CONFIG_HAS_MPU +/* +* MMIO region traps, generating from insufficient access permissions, +* will lead to data abort with Permission fault. +*/ +if ( is_data && + (do_mmio_trap_stage2_abort_guest (regs, hsr, &info, gva, gpa) ==0 ) ) +return ; +#endif +/* * The only way to get here right now is because of mem_access, * thus reinjecting the exception to the guest is never required.
@@ -1917,9 +1968,6 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, }case FSC_FLT_TRANS : { - info.gpa = gpa; - info.dabt = hsr.dabt; -/* * Assumption :- Most of the times when we get a data abort and the ISS * is invalid or an instruction abort, the underlying cause is that the
@@ -1948,29 +1996,8 @@ static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs,if ( info.dabt_instr.state ==INSTR_ERROR ) goto inject_abt; - state =try_handle_mmio (regs, &info); - -switch ( state ) - { -case IO_ABORT : - goto inject_abt; -case IO_HANDLED : -/* -* If the instruction was decoded and has executed successfully -* on the MMIO region, then Xen should execute the next part of -* the instruction. (for eg increment the rn if it is a -* post-indexing instruction. -*/ -finalize_instr_emulation (&info.dabt_instr); -advance_pc (regs, hsr); -return ; -case IO_RETRY : -/* finish later */ -return ; -case IO_UNHANDLED : -/* IO unhandled, try another way to handle it. */ -break ; - } +if (do_mmio_trap_stage2_abort_guest (regs, hsr, &info, gva, gpa) ==0 ) +return ;/* * If the instruction syndrome was invalid, then we already checked if
Signature · 1 line
2.25.1
PATCH v3 49/52 xen/mpu: enable device passthrough in MPU system
In reply to Penny ZhengIn order to enable device passthrough in MPU system, we only need to provide p2m_mmio_direct_dev permission set up.
---
v3:
- new commit
--- xen/arch/arm/mpu/p2m.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/arm/mpu/p2m.c +10 -1
@@ -185,11 +185,15 @@ static void p2m_set_permission(pr_t *region, p2m_type_t t) region->prbar.reg.ap =AP_RO_ALL ;break ; +case p2m_mmio_direct_dev: + region->prbar.reg.xn =XN_P2M_ENABLED ; + region->prbar.reg.ap =AP_RW_ALL ; +break ; +case p2m_max_real_type:BUG ();break ; -case p2m_mmio_direct_dev:case p2m_mmio_direct_nc:case p2m_mmio_direct_c:case p2m_iommu_map_ro:
@@ -233,6 +237,11 @@ static inline pr_t region_to_p2m_entry(mfn_t smfn, unsigned long nr_mfn, prlar.reg.ai =MT_NORMAL ;break ; +case p2m_mmio_direct_dev: + prbar.reg.sh =LPAE_SH_OUTER ; + prlar.reg.ai = MT_DEVICE_nGnRE; +break ; +default :panic (XENLOG_G_ERR "p2m: UNIMPLEMENTED p2m type in MPU system\n" );break ;
Signature · 1 line
2.25.1
PATCH v3 50/52 xen/mpu: dump debug message in MPU system
In reply to Penny ZhengA set of helpers dump_xxx and show_registers are responsible for dumping memory mapping info and register info when debugging. In this commit, we implement them all in MPU system too.
---
v3:
- new commit
--- xen/arch/arm/include/asm/mpu/mm.h | 3 +++ xen/arch/arm/mpu/mm.c | 35 +++++++++++++++++++++++++++++++ xen/arch/arm/mpu/p2m.c | 11 ++++++++++ xen/arch/arm/p2m.c | 4 ++++ xen/arch/arm/traps.c | 16 ++++++++++++++ 5 files changed, 69 insertions(+)
xen/arch/arm/include/asm/mpu/mm.h +3 -0
@@ -21,6 +21,9 @@ extern pr_t *alloc_mpumap(void);extern int mpumap_contain_region (pr_t *table,uint8_t nr_regions,paddr_t base,paddr_t limit,uint8_t *index); +/* Print a walk of a MPU memory mapping table */ +void dump_mpu_walk (pr_t *table,uint8_t nr_regions); +#endif /* __ARCH_ARM_MM_MPU__ */ /*
xen/arch/arm/mpu/mm.c +35 -0
@@ -898,6 +898,41 @@ pr_t *alloc_mpumap(void)return map; } +void dump_mpu_walk (pr_t *table,uint8_t nr_regions) +{ +uint8_t i =0 ; + +for ( ; i < nr_regions; i++ ) + { +paddr_t base, limit; + +if (region_is_valid (&table[i]) ) + { + base =pr_get_base (&table[i]); + limit =pr_get_limit (&table[i]); + +printk (XENLOG_INFO +"Walking MPU memory mapping table: Region[%u]: 0x%" PRIpaddr"-0x%" PRIpaddr"\n" , + i, base, limit); + } + } +} + +void dump_hyp_walk (vaddr_t addr) +{ +uint8_t i =0 ; +pr_t region; + +for ( i =0 ; i < max_xen_mpumap; i++ ) + { +read_protection_region (®ion, i); +if (region_is_valid (®ion) ) +printk (XENLOG_INFO +"Walking hypervisor MPU memory region [%u]: 0x%" PRIpaddr"-0x%" PRIpaddr"\n" , + i,pr_get_base (®ion),pr_get_limit (®ion)); + } +} +/* * Local variables: * mode: C
xen/arch/arm/mpu/p2m.c +11 -0
@@ -481,6 +481,17 @@ void p2m_restore_state(struct vcpu *n) *last_vcpu_ran = n->vcpu_id; } +void p2m_dump_info (struct domain *d) +{ +struct p2m_domain *p2m =p2m_get_hostp2m (d); + +p2m_read_lock (p2m); +printk ("p2m mappings for domain %d (vmid %d):\n" , + d->domain_id, p2m->vmid); +printk (" Number of P2M Memory Region: %u \n" , p2m->nr_regions); +p2m_read_unlock (p2m); +} +/* * Local variables: * mode: C
xen/arch/arm/p2m.c +4 -0
@@ -51,8 +51,12 @@ void dump_p2m_lookup(struct domain *d, paddr_t addr)printk ("P2M @ %p mfn:%#" PRI_mfn"\n" , p2m->root,mfn_x (page_to_mfn (p2m->root))); +#ifndef CONFIG_HAS_MPU dump_pt_walk (page_to_maddr (p2m->root), addr,P2M_ROOT_LEVEL ,P2M_ROOT_PAGES ); +#else +dump_mpu_walk ((pr_t *)page_to_virt (p2m->root), p2m->nr_regions); +#endif }mfn_t p2m_lookup (struct domain *d,gfn_t gfn,p2m_type_t *t)
xen/arch/arm/traps.c +16 -0
@@ -710,7 +710,11 @@ struct reg_ctxt {#endif /* Hypervisor-side state */ +#ifdef CONFIG_HAS_MPU +uint64_t vsctlr_el2; +#else uint64_t vttbr_el2; +#endif };static const char *mode_string (register_t cpsr)
@@ -908,7 +912,11 @@ static void _show_registers(const struct cpu_user_regs *regs,#endif }printk (" VTCR_EL2: %" PRIregister"\n" ,READ_SYSREG (VTCR_EL2 )); +#ifndef CONFIG_HAS_MPU printk (" VTTBR_EL2: %016" PRIx64"\n" , ctxt->vttbr_el2); +#else +printk (" VSCTLR_EL2: %016" PRIx64"\n" , ctxt->vsctlr_el2); +#endif printk ("\n" );printk (" SCTLR_EL2: %" PRIregister"\n" ,READ_SYSREG (SCTLR_EL2 ));
@@ -945,7 +953,11 @@ void show_registers(const struct cpu_user_regs *regs)if (guest_mode (regs) &&is_32bit_domain (current->domain) ) ctxt.ifsr32_el2 =READ_SYSREG (IFSR32_EL2 );#endif +#ifndef CONFIG_HAS_MPU ctxt.vttbr_el2 =READ_SYSREG64 (VTTBR_EL2 ); +#else + ctxt.vsctlr_el2 =READ_SYSREG64 (VSCTLR_EL2 ); +#endif _show_registers (regs, &ctxt,guest_mode (regs), current); }
@@ -968,7 +980,11 @@ void vcpu_show_registers(const struct vcpu *v) ctxt.ifsr32_el2 = v->arch.ifsr;#endif +#ifdef CONFIG_HAS_MPU + ctxt.vsctlr_el2 = v->domain->arch.p2m.vsctlr; +#else ctxt.vttbr_el2 = v->domain->arch.p2m.vttbr; +#endif _show_registers (&v->arch.cpu_info->guest_cpu_user_regs, &ctxt,1 , v); }
Signature · 1 line
2.25.1
PATCH v3 51/52 xen/mpu: create stubs of function/variables for UNSUPPORTED features
In reply to Penny ZhengAs we are not introduing features like SMP, SET/WAY emulation, etc, in MPU system, so we create empty stubs of function/variables and warnings for these UNSUPPORTED features.
---
v3:
- new commit
--- xen/arch/arm/arm64/mpu/head.S | 6 ++++++ xen/arch/arm/mpu/mm.c | 16 ++++++++++++++++ xen/arch/arm/mpu/p2m.c | 16 ++++++++++++++++ 3 files changed, 38 insertions(+)
xen/arch/arm/arm64/mpu/head.S +6 -0
@@ -241,6 +241,12 @@ ENTRY(setup_early_uart) #endif ENDPROC(setup_early_uart) +ENTRY(enable_runtime_mm) + PRINT("- SMP NOT SUPPORTED -\r\n") +1: wfe + b 1b +ENDPROC(enable_runtime_mm) + /* * Local variables: * mode: ASM
xen/arch/arm/mpu/mm.c +16 -0
@@ -933,6 +933,22 @@ void dump_hyp_walk(vaddr_t addr) } } +void mm_init_secondary_cpu (void ) +{ +printk (XENLOG_ERR "SMP not *SUPPORTED*\n" ); +} + +int init_secondary_mm (int cpu) +{ +printk (XENLOG_ERR "mpu: SMP not *SUPPORTED*\n" ); +return -EINVAL ; +} + +void update_mm_mapping (bool enable) +{ +printk (XENLOG_ERR "mpu: SMP not *SUPPORTED*\n" ); +} +/* * Local variables: * mode: C
xen/arch/arm/mpu/p2m.c +16 -0
@@ -492,6 +492,22 @@ void p2m_dump_info(struct domain *d)p2m_read_unlock (p2m); } +void setup_virt_paging_one (void *data) +{ +printk (XENLOG_ERR "mpu: SMP not *SUPPORTED*\n" ); +} + +void p2m_invalidate_root (struct p2m_domain *p2m) +{ +printk (XENLOG_ERR "mpu: p2m_invalidate_root() not *SUPPORTED*\n" ); +} + +bool p2m_resolve_translation_fault (struct domain *d,gfn_t gfn) +{ +printk (XENLOG_ERR "mpu: p2m_resolve_translation_fault() not *SUPPORTED*\n" ); +return false; +} +/* * Local variables: * mode: C
Signature · 1 line
2.25.1
PATCH v3 52/52 xen/arm: add Kconfig option CONFIG_HAS_MPU to enable MPU system support
In reply to Penny ZhengIntroduce a Kconfig option CONFIG_HAS_MPU to enable MPU architecture support. STATIC_MEMORY, ARCH_MAP_DOMAIN_PAGE and ARM_SECURE_STATE will be selected by MPU system by default. Also, features like, ARM_EFI, are not supported right now.
Current MPU system design is only for ARM 64-bit platform.
---
v3:
- select ARCH_MAP_DOMAIN_PAGE and ARM_SECURE_STATE
- remove platform-specific config: CONFIG_ARM_V8R
--- xen/arch/arm/Kconfig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/arm/Kconfig +13 -1
@@ -62,6 +62,7 @@ source "arch/Kconfig" config HAS_MMU bool "Memory Management Unit support in a VMSA system" default y + depends on !HAS_MPU select HAS_PAGING_MEMPOOL select HAS_PMAP select HAS_VMAP
@@ -70,6 +71,17 @@ config HAS_MMU a memory system through a set of virtual to physical address mappings and associated memory properties held in memory-mapped tables known as translation tables. +config HAS_MPU + bool "Memory Protection Unit support in a PMSA system" + default n + depends on ARM_64 + select ARCH_MAP_DOMAIN_PAGE + select ARM_SECURE_STATE + select STATIC_MEMORY + help + The PMSA is based on a Memory Protection Unit (MPU), which provides a much simpler + memory protection scheme than the MMU based VMSA. + config HAS_FIXMAP bool "Provide special-purpose 4K mapping slots in a VMSA" depends on HAS_MMU
@@ -85,7 +97,7 @@ config ACPI config ARM_EFI bool "UEFI boot service support" - depends on ARM_64 + depends on ARM_64 && !HAS_MPU default y help This option provides support for boot services through
Signature · 1 line
2.25.1
Re: [PATCH v3 52/52] xen/arm: add Kconfig option CONFIG_HAS_MPU to enable MPU system support
Quoted 33 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Introduce a
KconfigoptionCONFIG_HAS_MPUto enable MPU architecture support.STATIC_MEMORY,ARCH_MAP_DOMAIN_PAGEandARM_SECURE_STATEwill be selected by MPU system by default. Also, features like,ARM_EFI, are not supported right now.Current MPU system design is only for ARM 64-bit platform.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- selectARCH_MAP_DOMAIN_PAGEandARM_SECURE_STATE
- remove platform-specific config:CONFIG_ARM_V8R--- xen/arch/arm/Kconfig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +1
-0@@ -62,6 +62,7 @@ source "arch/Kconfig" config HAS_MMU bool "Memory Management Unit support in a VMSA system" default y + depends on !HAS_MPU select HAS_PAGING_MEMPOOL select HAS_PMAP select HAS_VMAP
xen/arch/arm/Kconfig config HAS_MMU · line 77
Quoted 7 lines
xen/arch/arm/Kconfig +4
-0@@ -70,6 +71,17 @@ config HAS_MMU a memory system through a set of virtual to physical address mappings and associated memory properties held in memory-mapped tables known as translation tables. +config HAS_MPU + bool "Memory Protection Unit support in a PMSA system" + default n + depends on ARM_64
This will not be true as R52 will support MPU
xen/arch/arm/Kconfig config HAS_MMU · line 79
Quoted 2 lines
xen/arch/arm/Kconfig +2
-0+ select ARCH_MAP_DOMAIN_PAGE + select ARM_SECURE_STATE
Also, R52 does not support secure state.
xen/arch/arm/Kconfig config HAS_MMU · line 84
Quoted 5 lines
xen/arch/arm/Kconfig +5
-0+ select STATIC_MEMORY + help + The PMSA is based on a Memory Protection Unit (MPU), which provides a much simpler + memory protection scheme than the MMU based VMSA. +
Instead, I will suggest something like this :-
config ARM_V8R
bool "ARMv8-R AArch64 architecture support (UNSUPPORTED)" if UNSUPPORTED default n
select HAS_MPU
select ARM_SECURE_STATE
select STATIC_MEMORY
depends on ARM_64
help
This option enables Armv8-R profile for Arm64. Enabling this option results in selecting MPU.
So, that later on we can add :-
config AARCH32_V8R
bool "AArch32 Arm V8R Support (UNSUPPORTED)" if UNSUPPORTED default n
select HAS_MPU
select STATIC_MEMORY
depends on ARM_32
help
This option enables Armv8-R profile for Arm32.
- Ayan
Quoted 16 lines
xen/arch/arm/Kconfig +1
-2config HAS_FIXMAP bool "Provide special-purpose 4K mapping slots in a VMSA" depends on HAS_MMU@@ -85,7 +97,7 @@ config ACPI config ARM_EFI bool "UEFI boot service support" - depends on ARM_64 + depends on ARM_64 && !HAS_MPU default y help This option provides support for boot services through --2.25.1
Re: [PATCH v3 52/52] xen/arm: add Kconfig option CONFIG_HAS_MPU to enable MPU system support
Hi,
Quoted 38 lines · Ayan Kumar Halder
Quoted 36 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Introduce a
KconfigoptionCONFIG_HAS_MPUto enable MPU architecture support.STATIC_MEMORY,ARCH_MAP_DOMAIN_PAGEandARM_SECURE_STATEwill be selected by MPU system by default. Also, features like,ARM_EFI, are not supported right now.Current MPU system design is only for ARM 64-bit platform.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>---
v3:
- selectARCH_MAP_DOMAIN_PAGEandARM_SECURE_STATE
- remove platform-specific config:CONFIG_ARM_V8R
---
xen/arch/arm/Kconfig | 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)xen/arch/arm/Kconfig +0
-0@@ -62,6 +62,7 @@ source "arch/Kconfig"config
HAS_MMU
bool "Memory Management Unit support in a VMSA system" default y
+ depends on !HAS_MPU
selectHAS_PAGING_MEMPOOL
selectHAS_PMAP
selectHAS_VMAPxen/arch/arm/Kconfig +0
-0@@ -70,6 +71,17 @@ config HAS_MMUa memory system through a set of virtual to physical address mappings and associated memory properties held in memory-mapped tables known as translation tables.
Quoted 5 lines
Quoted 4 lines
+config
HAS_MPU
+ bool "Memory Protection Unit support in a PMSA system" + default n
+ depends onARM_64This will not be true as R52 will support MPU
But the code will not compile until you work is added, correct? If so, I think it make sense to depend on ARM_64 for now.
Quoted 27 lines
Quoted 2 lines
+ select
ARCH_MAP_DOMAIN_PAGE
+ selectARM_SECURE_STATEAlso, R52 does not support secure state.
Quoted 6 lines
+ select
STATIC_MEMORY
+ help
+ The PMSA is based on a Memory Protection Unit (MPU), which provides a much simpler
+ memory protection scheme than the MMU based VMSA. +Instead, I will suggest something like this :-
config
ARM_V8R
bool "ARMv8-R AArch64 architecture support (UNSUPPORTED)" if
UNSUPPORTED
default n
selectHAS_MPU
selectARM_SECURE_STATE
selectSTATIC_MEMORY
depends onARM_64
help
This option enables Armv8-R profile for Arm64. Enabling this option results in selecting MPU.So, that later on we can add :-
Quoted 8 lines
config
AARCH32_V8R
bool "AArch32 Arm V8R Support (UNSUPPORTED)" if UNSUPPORTED default n
selectHAS_MPU
selectSTATIC_MEMORY
depends onARM_32
help
This option enables Armv8-R profile for Arm32.
I believe the the duplication can be avoided if you write:
config ARM_MPU
bool "..." if UNSUPPORTED
default n
select ARM_SECURE_STATE if ARM_64
select STATIC_MEMORY
help
...
Not that I didn't use your proposed name because in the future there might be an ArmVx-R and we don't want to rename everything. So a more generic name is better.
Cheers,
Signature · 1 line
Julien Grall
Quoted 100 lines · Penny Zheng
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
So sorry for the long long wait before v3 serie, since I got sidetracked to a new high priority internal project for quite a time.
The Armv8-R architecture profile was designed to support use cases that have a high sensitivity to deterministic execution. (e.g. Fuel Injection, Brake control, Drive trains, Motor control etc)
Arm announced Armv8-R in 2013, it is the latest generation Arm architecture targeted at the Real-time profile. It introduces virtualization at the highest security level while retaining the Protected Memory System Architecture (PMSA) based on a Memory Protection Unit (MPU). In 2020, Arm announced Cortex-R82, which is the first Arm 64-bit Cortex-R processor based on Armv8-R64. The latest Armv8-R64 document can be found [1]. And the features of Armv8-R64 architecture:
- An exception model that is compatible with the Armv8-A model
- Virtualization with support for guest operating systems
- PMSA virtualization using MPUs In EL2.
- Adds support for the 64-bit A64 instruction set.
- Supports up to 48-bit physical addressing.
- Supports three Exception Levels (ELs)
- Secure EL2 - The Highest Privilege
- Secure EL1 - RichOS (MMU) or RTOS (MPU)
- Secure EL0 - Application Workloads
- Supports only a single Security state - Secure.
- MPU in EL1 & EL2 is configurable, MMU in EL1 is configurable.These patch series are implementing the Armv8-R64 MPU support for Xen, which are based on the discussion of "Proposal for Porting Xen to Armv8-R64 - DraftC" [2].
We will implement the Armv8-R64 and MPU support in three stages:
1. Support to boot MMU domains on Armv8-R64 Xen.
2. Support to boot MPU domains on Armv8-R64 Xen.
3. SMP and other advanced features of Xen support on Armv8-R64.For having a overall undestanding for reviewers about MPU framework on Xen, we have introduced a large patch serie here, including 52 commits. At this stage, we could successfully boot a linux guest on
FVP_BaseR_AEMv8Rmodel[3].We will split these patches to several parts, this series is the part#1, v1 is in [4], the full PoC can be found in [5]. More software for Armv8-R64 can be found in [6];
[1] https://developer.arm.com/documentation/ddi0600/latest
[2] https://lists.xenproject.org/archives/html/xen-devel/2022-05/msg00643.html
[3] https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
[4] https://lists.xenproject.org/archives/html/xen-devel/2022-11/msg00289.html
[5] https://gitlab.com/xen-project/people/weic/xen/-/tree/integration/mpu_v3
[6] https://armv8r64-refstack.docs.arm.com/en/v5.0/Penny Zheng (41):
xen/arm: introduceCONFIG_HAS_MMU
xen/arm: mmu: fold FIXMAP into MMU system
xen/mmu: extract early uart mapping fromsetup_fixmapxen/mmu: move MMU-specificsetup_mmtommu/setup.c
xen: make VMAP only support in MMU system
xen/mmu: relocatecopy_from_paddrintosetup.c
xen/arm: do not give memory back to static heap
xen/arm: only map the init text section RW infree_init_memoryxen/arm: switch to useioremap_xxxin common file xen/mmu: move MMU specific P2M code tommu/p2m.candmmu/p2m.h
xen: introduceCONFIG_HAS_PAGING_MEMPOOL
xen/mmu: enable SMMU subsystem only in MMU
xen/mpu: build up start-of-day Xen MPU memory region map xen/mpu: introduce helpers for MPU enablement
xen/mpu: map early uart when earlyprintk on
xen/mpu: introducesetup_mm_mappings
xen/mpu: plumpvirt/maddrconversion in MPU system xen/mpu: introduce a pair helper
read_protection_region()/write_protection_region()
xen/mpu: populate a new region in Xen MPU mapping table xen/mpu: makeearly_fdt_mapsupport in MPU systems xen/mpu: implement MPU version ofsetup_mminmpu/setup.cxen/mpu: initialize frametable in MPU system
xen/mpu: destroy an existing entry in Xen MPU memory mapping table xen/arm: map static memory on demand
xen/mpu: implememtioremap_xxxin MPU
xen/mpu: implement MPU version ofcopy_from_paddrxen/mpu: map domain page in MPU system
xen/mpu: supportfree_init_memoryin MPU system
xen/mpu: implementremove_early_mappingsin MPU system xen/mpu: Use secure hypervisor timer in MPU system xen/mpu: implementsetup_virt_pagingfor MPU system xen/mpu: configureVSTCR_EL2in MPU system
xen/mpu: P2M initialization in MPU system
xen/mpu: insert an new entry into guest physmap in MPU system xen/mpu: look up entry in p2m table
xen/mpu: support vcpu context switch in MPU system xen/mpu: enable MMIO region trap in MPU system
xen/mpu: enable device passthrough in MPU system
xen/mpu: dump debug message in MPU system
xen/mpu: create stubs of function/variables for UNSUPPORTED features xen/arm: addKconfigoptionCONFIG_HAS_MPUto enable MPU system
support
Quoted 12 lines
Wei Chen (11):
xen/arm: removexen_phys_startandxenheap_phys_endfromconfig.hxen/arm: makeARM_EFIselectable for Arm64
xen/arm: add an option to define Xen start address for Armv8-R xen/arm: add .text.idmap in ld script for Xen identity map sections xen/arm64: head: Introduceenable_boot_mmuandenable_runtime_mmuxen/arm64: prepare for moving MMU related code fromhead.Sxen/arm64: move MMU related code fromhead.Stommu/head.Sxen/arm: use PA == VA forEARLY_UART_VIRTUAL_ADDRESSon MPU systems xen/arm: Move MMU related definitions fromconfig.htommu/layout.hxen/mmu: extract mmu-specific codes frommm.c/mm.hxen/arm: creatempu/layout.hfor MPU related address definitions
Hi All,
I had a look at the first 22 patches (which touch the MMU code) and I did not find anything which will impact the R52 work directly.
- Ayan
Quoted 79 lines
xen/arch/arm/Kconfig | 52 +- xen/arch/arm/Kconfig.debug | 7 + xen/arch/arm/Makefile | 15 +- xen/arch/arm/arm32/head.S | 2 +- xen/arch/arm/arm64/Makefile | 7 +- xen/arch/arm/arm64/head.S | 472 +----- xen/arch/arm/arm64/mmu/head.S | 463 ++++++ xen/arch/arm/arm64/{ => mmu}/mm.c | 7 +- xen/arch/arm/arm64/mpu/head.S | 255 ++++ xen/arch/arm/arm64/smpboot.c | 6 +- xen/arch/arm/bootfdt.c | 2 +- xen/arch/arm/domain.c | 2 + xen/arch/arm/domain_build.c | 2 + xen/arch/arm/include/asm/arm64/macros.h | 51 + xen/arch/arm/include/asm/arm64/mm.h | 7 +- xen/arch/arm/include/asm/arm64/mpu.h | 140 ++ xen/arch/arm/include/asm/arm64/sysregs.h | 76 + xen/arch/arm/include/asm/config.h | 129 +- xen/arch/arm/include/asm/cpufeature.h | 7 + xen/arch/arm/include/asm/early_printk.h | 20 + xen/arch/arm/include/asm/fixmap.h | 31 +- xen/arch/arm/include/asm/mm.h | 79 +- xen/arch/arm/include/asm/mmu/layout.h | 141 ++ xen/arch/arm/include/asm/mmu/mm.h | 54 + xen/arch/arm/include/asm/mmu/p2m.h | 18 + xen/arch/arm/include/asm/mpu/layout.h | 32 + xen/arch/arm/include/asm/mpu/mm.h | 36 + xen/arch/arm/include/asm/mpu/p2m.h | 18 + xen/arch/arm/include/asm/p2m.h | 48 +- xen/arch/arm/include/asm/page.h | 46 +- xen/arch/arm/include/asm/processor.h | 14 + xen/arch/arm/include/asm/setup.h | 16 +- xen/arch/arm/kernel.c | 42 +- xen/arch/arm/mm.c | 1160 +------------- xen/arch/arm/mmu/mm.c | 1133 ++++++++++++++ xen/arch/arm/mmu/p2m.c | 1612 +++++++++++++++++++ xen/arch/arm/mmu/setup.c | 379 +++++ xen/arch/arm/mpu/domain_page.c | 68 + xen/arch/arm/mpu/mm.c | 959 ++++++++++++ xen/arch/arm/mpu/p2m.c | 518 +++++++ xen/arch/arm/mpu/setup.c | 102 ++ xen/arch/arm/p2m.c | 1782 ++-------------------- xen/arch/arm/platforms/Kconfig | 8 +- xen/arch/arm/setup.c | 388 +---- xen/arch/arm/smpboot.c | 6 +- xen/arch/arm/traps.c | 97 +- xen/arch/arm/xen.lds.S | 6 +- xen/arch/x86/Kconfig | 2 + xen/arch/x86/setup.c | 2 + xen/common/Kconfig | 8 + xen/common/Makefile | 2 +- xen/common/domctl.c | 2 + xen/common/vmap.c | 7 + xen/drivers/passthrough/Kconfig | 3 +- xen/include/xen/vmap.h | 11 +- 55 files changed, 6730 insertions(+), 3822 deletions(-)create mode 100644
xen/arch/arm/arm64/mmu/head.Srename xen/arch/arm/arm64/{ =>mmu}/mm.c(97%) create mode 100644xen/arch/arm/arm64/mpu/head.Screate mode 100644xen/arch/arm/include/asm/arm64/mpu.hcreate mode 100644xen/arch/arm/include/asm/mmu/layout.hcreate mode 100644xen/arch/arm/include/asm/mmu/mm.hcreate mode 100644xen/arch/arm/include/asm/mmu/p2m.hcreate mode 100644xen/arch/arm/include/asm/mpu/layout.hcreate mode 100644xen/arch/arm/include/asm/mpu/mm.hcreate mode 100644xen/arch/arm/include/asm/mpu/p2m.hcreate mode 100644xen/arch/arm/mmu/mm.c
create mode 100644xen/arch/arm/mmu/p2m.ccreate mode 100644xen/arch/arm/mmu/setup.ccreate mode 100644xen/arch/arm/mpu/domain_page.ccreate mode 100644xen/arch/arm/mpu/mm.c
create mode 100644xen/arch/arm/mpu/p2m.ccreate mode 100644xen/arch/arm/mpu/setup.c--
2.25.1
Hi Penny,
Quoted 3 lines · Penny Zheng
Wei Chen (11):
xen/arm: removexen_phys_startandxenheap_phys_endfromconfig.hxen/arm: makeARM_EFIselectable for Arm64
I have committed these two patches.
Cheers,
Signature · 1 line
Julien Grall
Hi Penny,
Quoted 45 lines · Penny Zheng
So sorry for the long long wait before v3 serie, since I got sidetracked to a new high priority internal project for quite a time.
The Armv8-R architecture profile was designed to support use cases that have a high sensitivity to deterministic execution. (e.g. Fuel Injection, Brake control, Drive trains, Motor control etc)
Arm announced Armv8-R in 2013, it is the latest generation Arm architecture targeted at the Real-time profile. It introduces virtualization at the highest security level while retaining the Protected Memory System Architecture (PMSA) based on a Memory Protection Unit (MPU). In 2020, Arm announced Cortex-R82, which is the first Arm 64-bit Cortex-R processor based on Armv8-R64. The latest Armv8-R64 document can be found [1]. And the features of Armv8-R64 architecture:
- An exception model that is compatible with the Armv8-A model
- Virtualization with support for guest operating systems
- PMSA virtualization using MPUs In EL2.
- Adds support for the 64-bit A64 instruction set.
- Supports up to 48-bit physical addressing.
- Supports three Exception Levels (ELs)
- Secure EL2 - The Highest Privilege
- Secure EL1 - RichOS (MMU) or RTOS (MPU)
- Secure EL0 - Application Workloads
- Supports only a single Security state - Secure.
- MPU in EL1 & EL2 is configurable, MMU in EL1 is configurable.These patch series are implementing the Armv8-R64 MPU support for Xen, which are based on the discussion of "Proposal for Porting Xen to Armv8-R64 - DraftC" [2].
We will implement the Armv8-R64 and MPU support in three stages:
1. Support to boot MMU domains on Armv8-R64 Xen.
2. Support to boot MPU domains on Armv8-R64 Xen.
3. SMP and other advanced features of Xen support on Armv8-R64.For having a overall undestanding for reviewers about MPU framework on Xen, we have introduced a large patch serie here, including 52 commits. At this stage, we could successfully boot a linux guest on
FVP_BaseR_AEMv8Rmodel[3].We will split these patches to several parts, this series is the part#1, v1 is in [4], the full PoC can be found in [5]. More software for Armv8-R64 can be found in [6];
Quoted 5 lines
[1] https://developer.arm.com/documentation/ddi0600/latest
[2] https://lists.xenproject.org/archives/html/xen-devel/2022-05/msg00643.html
[3] https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
[4] https://lists.xenproject.org/archives/html/xen-devel/2022-11/msg00289.html
[5] https://gitlab.com/xen-project/people/weic/xen/-/tree/integration/mpu_v3
The first few patches in this tree seems to be different compare to this series. Can you provide a tree with all the patches from this series applied?
Cheers,
Signature · 1 line
Julien Grall