diff --git a/xen/arch/x86/include/asm/mem_access.h b/xen/arch/x86/include/asm/mem_access.h index 257ed33de1..84af05a8c6 100644 --- a/xen/arch/x86/include/asm/mem_access.h +++ b/xen/arch/x86/include/asm/mem_access.h @@ -34,6 +34,11 @@ bool p2m_mem_access_emulate_check(struct vcpu *v, /* Sanity check for mem_access hardware support */ bool p2m_mem_access_sanity_check(const struct domain *d); +struct p2m_domain; +bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess); + #endif /*__ASM_X86_MEM_ACCESS_H__ */ /* 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 759f3273d3..8d34357bcb 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2203,6 +2203,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..998ec680d4 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -33,10 +33,6 @@ */ struct vm_event_st; -#ifdef CONFIG_VM_EVENT -#include -#endif - /* * Additional access types, which are used to further restrict * the permissions given my the p2m_type_t memory type. Violations @@ -73,10 +69,9 @@ 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); +#if defined(CONFIG_VM_EVENT) || defined(CONFIG_ALTP2M) +#include +#endif /* * Set access type for a region of gfns.