Skip to content

Commit

Permalink
xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pennyzct authored and Julien Grall committed Nov 20, 2023
1 parent 1bf5c10 commit ee0f41f
Show file tree
Hide file tree
Showing 6 changed files with 1,933 additions and 1,880 deletions.
11 changes: 1 addition & 10 deletions xen/arch/arm/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions xen/arch/arm/include/asm/mmu/p2m.h
Original file line number Diff line number Diff line change
@@ -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:
*/
32 changes: 24 additions & 8 deletions xen/arch/arm/include/asm/p2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
/*
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions xen/arch/arm/mmu/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
obj-y += p2m.o
obj-y += pt.o
obj-y += setup.o
obj-y += smpboot.o

0 comments on commit ee0f41f

Please sign in to comment.