Memory access and ALTP2M are two seperate features, while both depending on helper xenmem_access_to_p2m_access(). So it betters lives in common p2m.c, other than mem_access.c which will be compiled out when VM_EVENT=n && ALTP2M=y. Guard xenmem_access_to_p2m_access() with VM_EVENT || ALTP2M, otherwise it will become unreachable when both VM_EVENT=n and ALTP2M=n, and hence violating Misra rule 2.1 We also need to move declaration from mem_access.h to p2m-common.h An extra blank line is inserted after each case-block to correct coding style at the same time.
Signed-off-by: Penny Zheng <[email protected]> --- v1 -> v2: - Guard xenmem_access_to_p2m_access() with VM_EVENT || ALTP2M - Move declaration from mem_access.h to p2m-common.h - refine commit message --- xen/arch/x86/mm/mem_access.c | 36 -------------------------------- xen/arch/x86/mm/p2m.c | 40 ++++++++++++++++++++++++++++++++++++ xen/include/xen/mem_access.h | 5 ----- xen/include/xen/p2m-common.h | 3 +++ 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index e6b609064c..e55e53f44c 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -298,42 +298,6 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m, return rc; } -bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, - xenmem_access_t xaccess, - p2m_access_t *paccess) -{ - static const p2m_access_t memaccess[] = { -#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac - ACCESS(n), - ACCESS(r), - ACCESS(w), - ACCESS(rw), - ACCESS(x), - ACCESS(rx), - ACCESS(wx), - ACCESS(rwx), - ACCESS(rx2rw), - ACCESS(n2rwx), - ACCESS(r_pw), -#undef ACCESS - }; - - switch ( xaccess ) - { - case 0 ... ARRAY_SIZE(memaccess) - 1: - xaccess = array_index_nospec(xaccess, ARRAY_SIZE(memaccess)); - *paccess = memaccess[xaccess]; - break; - case XENMEM_access_default: - *paccess = p2m->default_access; - break; - default: - return false; - } - - return true; -} - /* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type. diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index e2a00a0efd..2763f9a6be 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2189,6 +2189,46 @@ void p2m_log_dirty_range(struct domain *d, unsigned long begin_pfn, guest_flush_tlb_mask(d, d->dirty_cpumask); } +#if defined(CONFIG_VM_EVENT) || defined(CONFIG_ALTP2M) +bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess) +{ + static const p2m_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), + ACCESS(r_pw), +#undef ACCESS + }; + + switch ( xaccess ) + { + case 0 ... ARRAY_SIZE(memaccess) - 1: + xaccess = array_index_nospec(xaccess, ARRAY_SIZE(memaccess)); + *paccess = memaccess[xaccess]; + break; + + case XENMEM_access_default: + *paccess = p2m->default_access; + break; + + default: + return false; + } + + return true; +} +#endif /* VM_EVENT || ALTP2M */ + /* * Local variables: * mode: C diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index 4de651038d..8e7d9ea2e3 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -73,11 +73,6 @@ typedef enum { /* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t; -struct p2m_domain; -bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, - xenmem_access_t xaccess, - p2m_access_t *paccess); - /* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type. diff --git a/xen/include/xen/p2m-common.h b/xen/include/xen/p2m-common.h index f0bd9a6b98..bd4169caee 100644 --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -43,5 +43,8 @@ int __must_check check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, p2m_type_t *p2mt_p, struct page_info **page_p); +bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess); #endif /* _XEN_P2M_COMMON_H */ -- 2.34.1
