xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}

Current P2M implementation is designed for MMU system only.
We move the MMU-specific codes into mmu/p2m.c, and only keep generic
codes in p2m.c, like VMID allocator, etc. We also move MMU-specific
definitions and declarations to mmu/p2m.h, such as p2m_tlb_flush_sync().
Also expose previously static functions p2m_vmid_allocator_init(),
p2m_alloc_vmid() for further MPU usage. Since with the code movement
p2m_free_vmid() is now used in two files, also expose p2m_free_vmid().

With the code movement, global variable max_vmid is used in multiple
files instead of a single file (and will be used in MPU P2M
implementation), declare it in the header and remove the "static" of
this variable.

Also, since p2m_invalidate_root() should be MMU only and after the
code movement the only caller of p2m_invalidate_root() outside of
mmu/p2m.c is arch_domain_creation_finished(), creating a new function
named p2m_domain_creation_finished() in mmu/p2m.c for the original
code in arch_domain_creation_finished(), and marking
p2m_invalidate_root() as static.

Take the opportunity to fix the incorrect coding style when possible.
When there is bit shift in macros, take the opportunity to add the
missing 'U' as a compliance of MISRA.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Wei Chen <wei.chen@arm.com>
Signed-off-by: Henry Wang <Henry.Wang@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
This commit is contained in:
Penny Zheng authored and Julien Grall committed 2023-11-20 19:07:45 +00:00
1 parent 1bf5c104fe
commit ee0f41fda3
6 files changed
+1890 -1837

No files matched your search

+1 -10
View File
@@ -870,16 +870,7 @@ int arch_domain_soft_reset(struct domain *d)
void arch_domain_creation_finished(struct domain *d)
{
/*
* To avoid flushing the whole guest RAM on the first Set/Way, we
* invalidate the P2M to track what has been accessed.
*
* This is only turned when IOMMU is not used or the page-table are
* not shared because bit[0] (e.g valid bit) unset will result
* IOMMU fault that could be not fixed-up.
*/
if ( !iommu_use_hap_pt(d) )
p2m_invalidate_root(p2m_get_hostp2m(d));
p2m_domain_creation_finished(d);
}
static int is_guest_pv32_psr(uint32_t psr)
+26
View File
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef __ARM_MMU_P2M_H__
#define __ARM_MMU_P2M_H__
extern unsigned int p2m_root_order;
extern unsigned int p2m_root_level;
#define P2M_ROOT_ORDER p2m_root_order
#define P2M_ROOT_LEVEL p2m_root_level
#define P2M_ROOT_PAGES (1U << P2M_ROOT_ORDER)
struct p2m_domain;
void p2m_force_tlb_flush_sync(struct p2m_domain *p2m);
void p2m_tlb_flush_sync(struct p2m_domain *p2m);
void p2m_clear_root_pages(struct p2m_domain *p2m);
#endif /* __ARM_MMU_P2M_H__ */
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
+24 -8
View File
@@ -14,10 +14,19 @@
/* Holds the bit size of IPAs in p2m tables. */
extern unsigned int p2m_ipa_bits;
extern unsigned int p2m_root_order;
extern unsigned int p2m_root_level;
#define P2M_ROOT_ORDER p2m_root_order
#define P2M_ROOT_LEVEL p2m_root_level
#define MAX_VMID_8_BIT (1UL << 8)
#define MAX_VMID_16_BIT (1UL << 16)
#define INVALID_VMID 0 /* VMID 0 is reserved */
#ifdef CONFIG_ARM_64
extern unsigned int max_vmid;
/* VMID is by default 8 bit width on AArch64 */
#define MAX_VMID max_vmid
#else
/* VMID is always 8 bit width on AArch32 */
#define MAX_VMID MAX_VMID_8_BIT
#endif
struct domain;
@@ -156,6 +165,12 @@ typedef enum {
#endif
#include <xen/p2m-common.h>
#if defined(CONFIG_MMU)
# include <asm/mmu/p2m.h>
#else
# error "Unknown memory management layout"
#endif
static inline bool arch_acquire_resource_check(struct domain *d)
{
/*
@@ -180,6 +195,10 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx)
*/
void p2m_restrict_ipa_bits(unsigned int ipa_bits);
void p2m_vmid_allocator_init(void);
int p2m_alloc_vmid(struct domain *d);
void p2m_free_vmid(struct domain *d);
/* Second stage paging setup, to be called on all CPUs */
void setup_virt_paging(void);
@@ -242,8 +261,6 @@ static inline int p2m_is_write_locked(struct p2m_domain *p2m)
return rw_is_write_locked(&p2m->lock);
}
void p2m_tlb_flush_sync(struct p2m_domain *p2m);
/* Look up the MFN corresponding to a domain's GFN. */
mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t);
@@ -271,8 +288,7 @@ int p2m_set_entry(struct p2m_domain *p2m,
bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn);
void p2m_clear_root_pages(struct p2m_domain *p2m);
void p2m_invalidate_root(struct p2m_domain *p2m);
void p2m_domain_creation_finished(struct domain *d);
/*
* Clean & invalidate caches corresponding to a region [start,end) of guest
+1
View File
@@ -1,3 +1,4 @@
obj-y += p2m.o
obj-y += pt.o
obj-y += setup.o
obj-y += smpboot.o
File diff suppressed because it is too large. Load diff
+4 -1819
View File
File diff suppressed because it is too large. Load diff
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.