altp2m: Rename p2m_*_altp2m functions and move declarations out of p2m.h
RFC PATCH v6 8/43 altp2m: Rename p2m_*_altp2m functions and move declarations out of p2m.h
This commit renames altp2m functions with a p2m prefix. These functions were originally defined in p2m.c, hence the p2m prefix. When they were moved to altp2m.c in commit ae7584f63678, the function names were kept and the declarations remained in p2m.h. This commit finishes that move by renaming these functions to have an altp2m prefix and moving the declarations to altp2m.h.
Since these functions will either be moved to the common altp2m.c, or implemented separately for ARM, it doesn't seem to make sense to continue with this naming convention. Therefore, this commit preemptively renames the x86 implementations of these functions so they can later be implemented with altp2m function name prefixes in common code or for ARM.
For convenience, here is the full list of renames:
- p2m_init_altp2m -> altp2m_init
- p2m_teardown_altp2m -> altp2m_teardown
- p2m_flush_altp2m -> altp2m_flush
- p2m_altp2m_get_or_propagate -> altp2m_get_or_propagate
- p2m_altp2m_propagate_change -> altp2m_propagate_change
- p2m_get_altp2m -> altp2m_get_altp2m
- p2m_set_altp2m -> altp2m_set_altp2m
- p2m_reset_altp2m -> altp2m_reset_altp2m
- p2m_activate_altp2m -> altp2m_activate_altp2m
- p2m_init_altp2m_by_id -> altp2m_init_by_id
- p2m_init_next_altp2m -> altp2m_init_next_available
- p2m_destroy_altp2m_by_id -> altp2m_destroy_by_id
- p2m_switch_domain_altp2m_by_id -> altp2m_switch_domain_altp2m_by_id
- p2m_change_altp2m_gfn -> altp2m_change_gfn
- p2m_set_altp2m_view_visibility -> altp2m_set_view_visibility
This commit contains only function renames and code movement, and no functional change is intended.
This is commit 8/8 of the preparation phase.
---
v6: Introduced this patch.
--- xen/arch/arm/altp2m.c | 2 +- xen/arch/x86/hvm/hvm.c | 30 ++++---- xen/arch/x86/hvm/monitor.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 6 +- xen/arch/x86/include/asm/altp2m.h | 116 +++++++++++++++++++++++++++++- xen/arch/x86/include/asm/p2m.h | 109 ---------------------------- xen/arch/x86/mm/altp2m.c | 76 ++++++++++---------- xen/arch/x86/mm/mem_access.c | 13 ++-- xen/arch/x86/mm/p2m-basic.c | 4 +- xen/arch/x86/mm/p2m-ept.c | 4 +- xen/arch/x86/mm/p2m.h | 3 - xen/common/vm_event.c | 2 +- xen/include/xen/p2m-common.h | 2 +- 13 files changed, 186 insertions(+), 183 deletions(-)
xen/arch/arm/altp2m.c +1 -1
@@ -8,7 +8,7 @@#include <asm/p2m.h> /* Check to see if vcpu should be switched to a different p2m. */ -void p2m_altp2m_check (struct vcpu *v,uint16_t idx) +void altp2m_check (struct vcpu *v,uint16_t idx) {/* Not yet implemented */ BUG ();
xen/arch/x86/hvm/hvm.c +15 -15
@@ -1885,15 +1885,15 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,if (altp2m_active (currd) ) { - p2m =p2m_get_altp2m (curr); + p2m =altp2m_get_altp2m (curr);/* * Get the altp2m entry if present; or if not, propagate from * the host p2m. NB that this returns with gfn locked in the * altp2m. */ -if (p2m_altp2m_get_or_propagate (p2m, gfn, &mfn, &p2mt, - &p2ma, &page_order) ) +if (altp2m_get_or_propagate (p2m, gfn, &mfn, &p2mt, &p2ma, + &page_order) ) {/* Entry was copied from host -- retry fault */ rc =1 ;
@@ -2036,7 +2036,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,paging_mark_pfn_dirty (currd,_pfn (gfn));/* * If p2m is really an altp2m, unlock it before changing the type, -* as p2m_altp2m_propagate_change() needs to acquire the +* as altp2m_propagate_change() needs to acquire the * altp2m_list lock. */ if ( p2m != hostp2m )
@@ -4663,7 +4663,7 @@ static int do_altp2m_op(/* If the alternate p2m state has changed, handle appropriately */ if ( d->altp2m_active != ostate && - (ostate || !(rc =p2m_init_altp2m_by_id (d,0 ))) ) + (ostate || !(rc =altp2m_init_by_id (d,0 ))) ) {for_each_vcpu ( d, v ) {
@@ -4674,7 +4674,7 @@ static int do_altp2m_op( }if ( ostate ) -p2m_flush_altp2m (d); +altp2m_flush (d); }else if ( rc ) d->altp2m_active = false;
@@ -4729,17 +4729,18 @@ static int do_altp2m_op( }case HVMOP_altp2m_create_p2m: -if ( !(rc =p2m_init_next_altp2m (d, &a.u.view.view, - a.u.view.hvmmem_default_access)) ) + rc =altp2m_init_next_available (d, &a.u.view.view, + a.u.view.hvmmem_default_access); +if ( !rc ) rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;break ;case HVMOP_altp2m_destroy_p2m: - rc =p2m_destroy_altp2m_by_id (d, a.u.view.view); + rc =altp2m_destroy_by_id (d, a.u.view.view);break ;case HVMOP_altp2m_switch_p2m: - rc =p2m_switch_domain_altp2m_by_id (d, a.u.view.view); + rc =altp2m_switch_domain_altp2m_by_id (d, a.u.view.view);break ;case HVMOP_altp2m_set_suppress_ve:
@@ -4871,9 +4872,9 @@ static int do_altp2m_op(if ( a.u.change_gfn.pad1 || a.u.change_gfn.pad2 ) rc = -EINVAL ;else - rc =p2m_change_altp2m_gfn (d, a.u.change_gfn.view, -_gfn (a.u.change_gfn.old_gfn), -_gfn (a.u.change_gfn.new_gfn)); + rc =altp2m_change_gfn (d, a.u.change_gfn.view, +_gfn (a.u.change_gfn.old_gfn), +_gfn (a.u.change_gfn.new_gfn));break ;case HVMOP_altp2m_get_p2m_idx:
@@ -4906,8 +4907,7 @@ static int do_altp2m_op(else if ( !altp2m_active (d) ) rc = -EOPNOTSUPP ;else - rc =p2m_set_altp2m_view_visibility (d, idx, - a.u.set_visibility.visible); + rc =altp2m_set_view_visibility (d, idx, a.u.set_visibility.visible);break ; }
xen/arch/x86/hvm/monitor.c +1 -1
@@ -182,7 +182,7 @@ int hvm_monitor_debug(unsigned long rip, enum hvm_monitor_debug_type type,#ifdef CONFIG_ALTP2M if ( curr->arch.hvm.fast_single_step.enabled ) { -p2m_altp2m_check (curr, curr->arch.hvm.fast_single_step.p2midx); +altp2m_check (curr, curr->arch.hvm.fast_single_step.p2midx); curr->arch.hvm.single_step = false; curr->arch.hvm.fast_single_step.enabled = false; curr->arch.hvm.fast_single_step.p2midx =0 ;
xen/arch/x86/hvm/vmx/vmx.c +3 -3
@@ -2452,7 +2452,7 @@ static void cf_check vmx_vcpu_update_eptp(struct vcpu *v)struct ept_data *ept;if (altp2m_active (d) ) - p2m =p2m_get_altp2m (v); + p2m =altp2m_get_altp2m (v);if ( !p2m ) p2m =p2m_get_hostp2m (d);
@@ -2521,7 +2521,7 @@ static int cf_check vmx_vcpu_emulate_vmfunc(const struct cpu_user_regs *regs)if ( !cpu_has_vmx_vmfunc &&altp2m_active (curr->domain) && regs->eax ==0 && -p2m_switch_vcpu_altp2m_by_id (curr, regs->ecx) ) +altp2m_switch_vcpu_by_id (curr, regs->ecx) ) rc =X86EMUL_OKAY ;return rc;
@@ -4277,7 +4277,7 @@ void asmlinkage vmx_vmexit_handler(struct cpu_user_regs *regs) } } -p2m_set_altp2m (v, idx); +altp2m_set_altp2m (v, idx); } if ( vm_event_is_enabled(v) &&
xen/arch/x86/include/asm/altp2m.h +115 -1
140 lines not on this page · raw message
xen/arch/x86/include/asm/p2m.h +0 -109
121 lines not on this page · raw message
xen/arch/x86/mm/altp2m.c +38 -38
231 lines not on this page · raw message
xen/arch/x86/mm/mem_access.c +7 -6
@@ -81,7 +81,7 @@ bool p2m_mem_access_emulate_check(struct vcpu *v,struct p2m_domain *p2m =NULL ;if (altp2m_active (d) ) - p2m =p2m_get_altp2m (v); + p2m =altp2m_get_altp2m (v);if ( !p2m ) p2m =p2m_get_hostp2m (d);
@@ -145,7 +145,7 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,int rc;if (altp2m_active (d) ) - p2m =p2m_get_altp2m (v); + p2m =altp2m_get_altp2m (v);if ( !p2m ) p2m =p2m_get_hostp2m (d);
@@ -252,9 +252,10 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,return (p2ma != p2m_access_n2rwx); } -static int p2m_set_altp2m_mem_access (struct domain *d,struct p2m_domain *hp2m, -struct p2m_domain *ap2m,p2m_access_t a, -gfn_t gfn) +static int altp2m_set_altp2m_mem_access (struct domain *d, +struct p2m_domain *hp2m, +struct p2m_domain *ap2m,p2m_access_t a, +gfn_t gfn) {mfn_t mfn;p2m_type_t t;
@@ -281,7 +282,7 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m,if ( ap2m ) { - rc =p2m_set_altp2m_mem_access (d, p2m, ap2m, a, gfn); + rc =altp2m_set_altp2m_mem_access (d, p2m, ap2m, a, gfn);/* If the corresponding mfn is invalid we will want to just skip it */ if ( rc == -ESRCH ) rc =0 ;
xen/arch/x86/mm/p2m-basic.c +2 -2
@@ -128,7 +128,7 @@ int p2m_init(struct domain *d)return rc; } - rc =altp2m_supported () ?p2m_init_altp2m (d) :0 ; + rc =altp2m_supported () ?altp2m_init (d) :0 ;if ( rc ) {p2m_teardown_hostp2m (d);
@@ -198,7 +198,7 @@ void p2m_final_teardown(struct domain *d)if (is_hvm_domain (d) ) {if (altp2m_supported () ) -p2m_teardown_altp2m (d); +altp2m_teardown (d);/* * We must tear down nestedp2m unconditionally because * we initialise it unconditionally.
xen/arch/x86/mm/p2m-ept.c +2 -2
@@ -773,7 +773,7 @@ bool ept_handle_misconfig(uint64_t gpa)int rc;if (altp2m_active (curr->domain) ) - p2m =p2m_get_altp2m (curr); + p2m =altp2m_get_altp2m (curr);p2m_lock (p2m);
@@ -997,7 +997,7 @@ out:if (altp2m_supported () && entry_written &&p2m_is_hostp2m (p2m) ) { - ret =p2m_altp2m_propagate_change (d,_gfn (gfn), mfn, order, p2mt, p2ma); + ret =altp2m_propagate_change (d,_gfn (gfn), mfn, order, p2mt, p2ma);if ( !rc ) rc = ret; }
xen/arch/x86/mm/p2m.h +0 -3
@@ -19,9 +19,6 @@ static inline int p2m_init_logdirty(struct p2m_domain *p2m) { return 0; }static inline void p2m_free_logdirty (struct p2m_domain *p2m) {}#endif -int p2m_init_altp2m (struct domain *d); -void p2m_teardown_altp2m (struct domain *d); -void p2m_flush_table_locked (struct p2m_domain *p2m);int __must_check p2m_remove_entry (struct p2m_domain *p2m,gfn_t gfn,mfn_t mfn,unsigned int page_order);
xen/common/vm_event.c +1 -1
@@ -433,7 +433,7 @@ static int vm_event_resume(struct domain *d, struct vm_event_domain *ved)/* Check for altp2m switch */ if (IS_ENABLED (CONFIG_ALTP2M ) && rsp.flags &VM_EVENT_FLAG_ALTERNATE_P2M ) -p2m_altp2m_check (v, rsp.altp2m_idx); +altp2m_check (v, rsp.altp2m_idx);if ( rsp.flags &VM_EVENT_FLAG_SET_REGISTERS )vm_event_set_registers (v, &rsp);
xen/include/xen/p2m-common.h +1 -1
@@ -25,7 +25,7 @@ int unmap_mmio_regions(struct domain *d, mfn_t mfn);/* Check to see if vcpu should be switched to a different p2m. */ -void p2m_altp2m_check (struct vcpu *v,uint16_t idx); +void altp2m_check (struct vcpu *v,uint16_t idx);/* * Populate-on-Demand
Signature · 1 line
2.34.1
RFC PATCH v6 9/43 altp2m: Move do_altp2m_op to common code
This commit moves the altp2m HVMOP implementation to common code, making it possible to re-use it across architectures. In this commit, the entire implementation is gated behind CONFIG_X86, with no changes to the body of do_altp2m_op. A stub implementation is added for ARM, which will be removed once do_altp2m_op has been modified to add ARM support.
This commit contains only code movement, and no change in functionality is intended.
This is commit 1/2 of the common do_altp2m_op phase.
---
v6: Introduced this patch.
--- xen/arch/x86/hvm/hvm.c | 400 ------------------------------------- xen/common/altp2m.c | 413 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/altp2m.h | 11 ++ 3 files changed, 424 insertions(+), 400 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -400
@@ -4526,406 +4526,6 @@ static int hvmop_get_param(return rc; } -/* -* altp2m operations are envisioned as being used in several different -* modes: -* -* - external: All control and decisions are made by an external agent -* running domain 0. -* -* - internal: altp2m operations are used exclusively by an in-guest -* agent to protect itself from the guest kernel and in-guest -* attackers. -* -* - coordinated: An in-guest agent handles #VE and VMFUNCs locally, -* but makes requests of an agent running outside the domain for -* bigger changes (such as modifying altp2m entires). -* -* This corresponds to the three values for HVM_PARAM_ALTP2M -* (external, mixed, limited). All three models have advantages and -* disadvantages. -* -* Normally hypercalls made by a program in domain 0 in order to -* control a guest would be DOMCTLs rather than HVMOPs. But in order -* to properly enable the 'internal' use case, as well as to avoid -* fragmentation, all altp2m subops should come under this single -* HVMOP. -* -* Note that 'internal' mode (HVM_PARAM_ALTP2M == XEN_ALTP2M_mixed) -* has not been evaluated for safety from a security perspective. -* Before using this mode in a security-critical environment, each -* subop should be evaluated for safety, with unsafe subops -* blacklisted in xsm_hvm_altp2mhvm_op(). -*/ -static int do_altp2m_op ( -XEN_GUEST_HANDLE_PARAM (void ) arg) -{ -#ifdef CONFIG_ALTP2M -struct xen_hvm_altp2m_op a; -struct domain *d =NULL ; -int rc =0 ; -uint64_t mode; - -if ( !altp2m_supported () ) -return -EOPNOTSUPP ; - -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - -if ( a.pad1 || a.pad2 || - (a.version !=HVMOP_ALTP2M_INTERFACE_VERSION ) ) -return -EINVAL ; - -switch ( a.cmd ) - { -case HVMOP_altp2m_get_domain_state: -case HVMOP_altp2m_set_domain_state: -case HVMOP_altp2m_vcpu_enable_notify: -case HVMOP_altp2m_vcpu_disable_notify: -case HVMOP_altp2m_create_p2m: -case HVMOP_altp2m_destroy_p2m: -case HVMOP_altp2m_switch_p2m: -case HVMOP_altp2m_set_suppress_ve: -case HVMOP_altp2m_set_suppress_ve_multi: -case HVMOP_altp2m_get_suppress_ve: -case HVMOP_altp2m_set_mem_access: -case HVMOP_altp2m_set_mem_access_multi: -case HVMOP_altp2m_get_mem_access: -case HVMOP_altp2m_change_gfn: -case HVMOP_altp2m_get_p2m_idx: -case HVMOP_altp2m_set_visibility: -break ; - -default : -return -EOPNOTSUPP ; - } - - d =rcu_lock_domain_by_any_id (a.domain); - -if ( d ==NULL ) -return -ESRCH ; - -if ( !is_hvm_domain (d) ) - { - rc = -EOPNOTSUPP ; - goto out; - } - -if ( (a.cmd != HVMOP_altp2m_get_domain_state) && - (a.cmd != HVMOP_altp2m_set_domain_state) && - !d->altp2m_active ) - { - rc = -EOPNOTSUPP ; - goto out; - } - - mode = d->arch.hvm.params[HVM_PARAM_ALTP2M ]; - -if ( XEN_ALTP2M_disabled == mode ) - { - rc = -EINVAL ; - goto out; - } - -if ( d->nr_altp2m ==0 ) - { - rc = -EOPNOTSUPP ; - goto out; - } - -if ( (rc =xsm_hvm_altp2mhvm_op (XSM_OTHER , d, mode, a.cmd)) ) - goto out; - -switch ( a.cmd ) - { -case HVMOP_altp2m_get_domain_state: - a.u.domain_state.state =altp2m_active (d); - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -break ; - -case HVMOP_altp2m_set_domain_state: - { -struct vcpu *v; -bool ostate; - -if (nestedhvm_enabled (d) ) - { - rc = -EINVAL ; -break ; - } - - rc =domain_pause_except_self (d); -if ( rc ) -break ; - - ostate = d->altp2m_active; - d->altp2m_active = !!a.u.domain_state.state; - -/* If the alternate p2m state has changed, handle appropriately */ -if ( d->altp2m_active != ostate && - (ostate || !(rc =altp2m_init_by_id (d,0 ))) ) - { -for_each_vcpu ( d, v ) - { -if ( !ostate ) -altp2m_vcpu_initialise (v); -else -altp2m_vcpu_destroy (v); - } - -if ( ostate ) -altp2m_flush (d); - } -else if ( rc ) - d->altp2m_active = false; - -domain_unpause_except_self (d); -break ; - } - -case HVMOP_altp2m_vcpu_enable_notify: - { -struct vcpu *v; - -if ( a.u.enable_notify.pad || - a.u.enable_notify.vcpu_id >= d->max_vcpus ) - { - rc = -EINVAL ; -break ; - } - -if ( !cpu_has_vmx_virt_exceptions ) - { - rc = -EOPNOTSUPP ; -break ; - } - - v = d->vcpu[a.u.enable_notify.vcpu_id]; - - rc =altp2m_vcpu_enable_ve (v,_gfn (a.u.enable_notify.gfn)); -break ; - } - -case HVMOP_altp2m_vcpu_disable_notify: - { -struct vcpu *v; - -if ( a.u.disable_notify.vcpu_id >= d->max_vcpus ) - { - rc = -EINVAL ; -break ; - } - -if ( !cpu_has_vmx_virt_exceptions ) - { - rc = -EOPNOTSUPP ; -break ; - } - - v = d->vcpu[a.u.enable_notify.vcpu_id]; - -altp2m_vcpu_disable_ve (v); -break ; - } - -case HVMOP_altp2m_create_p2m: - rc =altp2m_init_next_available (d, &a.u.view.view, - a.u.view.hvmmem_default_access); -if ( !rc ) - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -break ; - -case HVMOP_altp2m_destroy_p2m: - rc =altp2m_destroy_by_id (d, a.u.view.view); -break ; - -case HVMOP_altp2m_switch_p2m: - rc =altp2m_switch_domain_altp2m_by_id (d, a.u.view.view); -break ; - -case HVMOP_altp2m_set_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) - rc = -EINVAL ; -else - { -gfn_t gfn =_gfn (a.u.suppress_ve.gfn); -unsigned int altp2m_idx = a.u.suppress_ve.view; -bool suppress_ve = a.u.suppress_ve.suppress_ve; - - rc =p2m_set_suppress_ve (d, gfn, suppress_ve, altp2m_idx); - } -break ; - -case HVMOP_altp2m_set_suppress_ve_multi: - { -uint64_t max_phys_addr = (1UL << d->arch.cpuid->extd.maxphysaddr) -1 ; - - a.u.suppress_ve_multi.last_gfn =min (a.u.suppress_ve_multi.last_gfn, - max_phys_addr); - -if ( a.u.suppress_ve_multi.pad1 || - a.u.suppress_ve_multi.first_gfn > a.u.suppress_ve_multi.last_gfn ) - rc = -EINVAL ; -else - { - rc =p2m_set_suppress_ve_multi (d, &a.u.suppress_ve_multi); -if ( (!rc || rc == -ERESTART ) &&__copy_to_guest (arg, &a,1 ) ) - rc = -EFAULT ; - } -break ; - } - -case HVMOP_altp2m_get_suppress_ve: -if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) - rc = -EINVAL ; -else - { -gfn_t gfn =_gfn (a.u.suppress_ve.gfn); -unsigned int altp2m_idx = a.u.suppress_ve.view; -bool suppress_ve; - - rc =p2m_get_suppress_ve (d, gfn, &suppress_ve, altp2m_idx); -if ( !rc ) - { - a.u.suppress_ve.suppress_ve = suppress_ve; - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; - } - } -break ; - -case HVMOP_altp2m_set_mem_access: -if ( !vm_event_is_enabled (current) ) - { - rc = -EOPNOTSUPP ; -break ; - } - -if ( a.u.mem_access.pad ) - rc = -EINVAL ; -else - rc =p2m_set_mem_access (d,_gfn (a.u.mem_access.gfn),1 ,0 ,0 , - a.u.mem_access.access, - a.u.mem_access.view); -break ; - -case HVMOP_altp2m_set_mem_access_multi: -if ( !vm_event_is_enabled (current) ) - { - rc = -EOPNOTSUPP ; -break ; - } - -if ( a.u.set_mem_access_multi.pad || - a.u.set_mem_access_multi.opaque > a.u.set_mem_access_multi.nr ) - { - rc = -EINVAL ; -break ; - } - -/* -* Unlike XENMEM_access_op_set_access_multi, we don't need any bits of -* the 'continuation' counter to be zero (to stash a command in). -* However, 0x40 is a good 'stride' to make sure that we make -* a reasonable amount of forward progress before yielding, -* so use a mask of 0x3F here. -*/ - rc =p2m_set_mem_access_multi (d, a.u.set_mem_access_multi.pfn_list, - a.u.set_mem_access_multi.access_list, - a.u.set_mem_access_multi.nr, - a.u.set_mem_access_multi.opaque, -0x3F , - a.u.set_mem_access_multi.view); -if ( rc >0 ) - { - a.u.set_mem_access_multi.opaque = rc; - rc = -ERESTART ; -if (__copy_field_to_guest (guest_handle_cast (arg, xen_hvm_altp2m_op_t), - &a, u.set_mem_access_multi.opaque) ) - rc = -EFAULT ; - } -break ; - -case HVMOP_altp2m_get_mem_access: -if ( !vm_event_is_enabled (current) ) - { - rc = -EOPNOTSUPP ; -break ; - } - -if ( a.u.mem_access.pad ) - rc = -EINVAL ; -else - { -xenmem_access_t access; - - rc =p2m_get_mem_access (d,_gfn (a.u.mem_access.gfn), &access, - a.u.mem_access.view); -if ( !rc ) - { - a.u.mem_access.access = access; - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; - } - } -break ; - -case HVMOP_altp2m_change_gfn: -if ( a.u.change_gfn.pad1 || a.u.change_gfn.pad2 ) - rc = -EINVAL ; -else - rc =altp2m_change_gfn (d, a.u.change_gfn.view, -_gfn (a.u.change_gfn.old_gfn), -_gfn (a.u.change_gfn.new_gfn)); -break ; - -case HVMOP_altp2m_get_p2m_idx: - { -struct vcpu *v; - -if ( !altp2m_active (d) ) - { - rc = -EOPNOTSUPP ; -break ; - } - -if ( (v =domain_vcpu (d, a.u.get_vcpu_p2m_idx.vcpu_id)) ==NULL ) - { - rc = -EINVAL ; -break ; - } - - a.u.get_vcpu_p2m_idx.altp2m_idx =altp2m_vcpu_idx (v); - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -break ; - } - -case HVMOP_altp2m_set_visibility: - { -unsigned int idx = a.u.set_visibility.altp2m_idx; - -if ( a.u.set_visibility.pad ) - rc = -EINVAL ; -else if ( !altp2m_active (d) ) - rc = -EOPNOTSUPP ; -else - rc =altp2m_set_view_visibility (d, idx, a.u.set_visibility.visible); -break ; - } - -default : -ASSERT_UNREACHABLE (); - rc = -EOPNOTSUPP ; -break ; - } - - out: -rcu_unlock_domain (d); - -return rc; -#else /* !CONFIG_ALTP2M */ -return -EOPNOTSUPP ; -#endif /* CONFIG_ALTP2M */ -} -DEFINE_XEN_GUEST_HANDLE (compat_hvm_altp2m_op_t);/*
xen/common/altp2m.c +413 -0
418 lines not on this page · raw message
xen/include/xen/altp2m.h +11 -0
@@ -2,8 +2,12 @@#ifndef __XEN_ALTP2M_H__#define __XEN_ALTP2M_H__ +#include <xen/errno.h> +#include <xen/param.h> #include <xen/sched.h> +#include <public/hvm/hvm_op.h> +#ifdef CONFIG_ALTP2M /* Alternate p2m HVM on/off per domain */
@@ -12,6 +16,8 @@ static inline bool altp2m_active(const struct domain *d) return d->altp2m_active; } +int do_altp2m_op (XEN_GUEST_HANDLE_PARAM (void ) arg); +#else /* CONFIG_ALTP2M */ static inline bool altp2m_active (const struct domain *d)
@@ -19,6 +25,11 @@ static inline bool altp2m_active(const struct domain *d)return false; } +static inline int do_altp2m_op (XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +return -EOPNOTSUPP ; +} +#endif /* CONFIG_ALTP2M */ #endif /* __XEN_ALTP2M_H__ */
Signature · 1 line
2.34.1
RFC PATCH v6 10/43 altp2m: Add ARM support to do_altp2m_op
In reply to Rose SpanglerThis commit makes the minimum required changes necessary for do_altp2m_op to compile on ARM. All altp2m commands in the switch statement are gated by CONFIG_X86, with a default case of returning EOPNOTSUPP. This allows future commits to move the #ifdef CONFIG_X86 down as support for ARM is added.
Additionally, a call to do_altp2m_op is added in the ARM HVMOP code.
This is commit 2/2 of the common do_altp2m_op phase.
---
v6: Replaced patches 2 and 3 from v4/v5 patch set with this patch.
Made HVM_PARAM_ALTP2M read-only, following the change to the x86 implementation in commit 0291089f6ea8. The DOMCTL to enable altp2m on ARM is implemented in a later commit in this patch series.
--- xen/arch/arm/hvm.c | 9 +++++++++ xen/common/altp2m.c | 29 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-)
xen/arch/arm/hvm.c +9 -0
@@ -5,6 +5,7 @@* Arch-specific hardware virtual machine abstractions. */ +#include <xen/altp2m.h> #include <xen/init.h> #include <xen/lib.h> #include <xen/errno.h>
@@ -23,6 +24,10 @@ static int hvm_allow_set_param(const struct domain *d, unsigned int param) {switch ( param ) { +/* The following parameters are read-only. */ +case HVM_PARAM_ALTP2M : +return -EEXIST ; +/* * The following parameters are intended for toolstack usage only. * They may not be set by the domain.
@@ -123,6 +128,10 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = -EINVAL ;break ; +case HVMOP_altp2m: + rc =do_altp2m_op (arg); +break ; +default : {gdprintk (XENLOG_DEBUG ,"HVMOP op=%lu: not implemented\n" , op);
xen/common/altp2m.c +14 -15
@@ -9,8 +9,10 @@#include <xsm/xsm.h> -#ifdef CONFIG_X86 +#if defined(CONFIG_X86 ) && defined(CONFIG_HVM )#include <asm/hvm/nestedhvm.h> +#endif +/* * altp2m operations are envisioned as being used in several different * modes:
@@ -18,13 +20,13 @@* - external: All control and decisions are made by an external agent * running domain 0. * -* - internal: altp2m operations are used exclusively by an in-guest -* agent to protect itself from the guest kernel and in-guest -* attackers. +* - internal (x86 only): altp2m operations are used exclusively by an +* in-guest agent to protect itself from the guest kernel and +* in-guest attackers. * -* - coordinated: An in-guest agent handles #VE and VMFUNCs locally, -* but makes requests of an agent running outside the domain for -* bigger changes (such as modifying altp2m entires). +* - coordinated (x86 only): An in-guest agent handles #VE and VMFUNCs +* locally, but makes requests of an agent running outside the +* domain for bigger changes (such as modifying altp2m entires). * * This corresponds to the three values for HVM_PARAM_ALTP2M * (external, mixed, limited). All three models have advantages and
@@ -97,7 +99,7 @@ int do_altp2m_op(if ( (a.cmd != HVMOP_altp2m_get_domain_state) && (a.cmd != HVMOP_altp2m_set_domain_state) && - !d->altp2m_active ) + !altp2m_active (d) ) { rc = -EOPNOTSUPP ; goto out;
@@ -122,6 +124,7 @@ int do_altp2m_op(switch ( a.cmd ) { +#ifdef CONFIG_X86 case HVMOP_altp2m_get_domain_state: a.u.domain_state.state =altp2m_active (d); rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;
@@ -394,9 +397,12 @@ int do_altp2m_op( rc =altp2m_set_view_visibility (d, idx, a.u.set_visibility.visible); break; } +#endif /* CONFIG_X86 */ default : +#ifdef CONFIG_X86 ASSERT_UNREACHABLE (); +#endif rc = -EOPNOTSUPP ;break ; }
@@ -406,13 +412,6 @@ int do_altp2m_op(return rc; } -#else -int do_altp2m_op ( -XEN_GUEST_HANDLE_PARAM (void ) arg) -{ -return -EOPNOTSUPP ; -} -#endif /* * Local variables:
Signature · 1 line
2.34.1
RFC PATCH v6 11/43 arm/altp2m: Add support for HVMOP_altp2m_get_domain_state
In reply to Rose SpanglerThis commit adds support for the altp2m_get_domain_state HVMOP on ARM. All code used in the command implementation already works on ARM, so no further changes beyond moving the #ifdef are necessary.
This is commit 1/1 of the get_domain_state phase.
---
v6: Introduced this patch.
This commit can be squashed into the previous commit for the actual submission if that would be preferred, but I thought it might be easier to understand the command #ifdef gate approach by splitting this into a separate patch.
--- xen/common/altp2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/altp2m.c +1 -1
@@ -124,12 +124,12 @@ int do_altp2m_op(switch ( a.cmd ) { -#ifdef CONFIG_X86 case HVMOP_altp2m_get_domain_state: a.u.domain_state.state =altp2m_active (d); rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;break ; +#ifdef CONFIG_X86 case HVMOP_altp2m_set_domain_state: {struct vcpu *v;
Signature · 1 line
2.34.1
RFC PATCH v6 12/43 x86/p2m: Move p2m_{init,free}_one declarations to arch header
In reply to Rose SpanglerThis commit moves the p2m_init_one and p2m_free_one declarations from the x86-only p2m.h header file to the asm/p2m.h header. This makes it possible to use these functions in the common altp2m init/teardown routines.
This is commit 1/12 of the altp2m_init/altp2m_teardown routines phase.
---
v6: Introduced this patch.
--- xen/arch/x86/include/asm/p2m.h | 3 +++ xen/arch/x86/mm/p2m.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/p2m.h +3 -0
@@ -592,6 +592,9 @@ int p2m_alloc_table(struct p2m_domain *p2m);void p2m_teardown (struct p2m_domain *p2m,bool remove_root,bool *preempted);void p2m_final_teardown (struct domain *d); +struct p2m_domain *p2m_init_one (struct domain *d); +void p2m_free_one (struct p2m_domain *p2m); +/* Add/remove a page to/from a domain's p2m table. */ int p2m_add_page (struct domain *d,gfn_t gfn,mfn_t mfn,unsigned int page_order,p2m_type_t t);
xen/arch/x86/mm/p2m.h +0 -3
@@ -6,9 +6,6 @@#ifndef __ARCH_MM_P2M_H__#define __ARCH_MM_P2M_H__ -struct p2m_domain *p2m_init_one (struct domain *d); -void p2m_free_one (struct p2m_domain *p2m); -void p2m_pod_init (struct p2m_domain *p2m);#ifdef CONFIG_HVM
Signature · 1 line
2.34.1
RFC PATCH v6 13/43 x86/altp2m: Add lock functions accessible from common code
In reply to Rose SpanglerThis commit adds three altp2m_lock functions which wrap the corresponding altp2m_list_lock functions present in "mm-locks.h". The "mm-locks.h" file is only accessible in x86 code. In order to make altp2m common across architectures, it must be possible to acquire the altp2m lock without including an x86-specific header file.
These functions cannot be static inline like their "mm-locks.h" counterparts, since "mm-locks.h" is only included in source files, not header files. Therefore, these functions might introduce a slight function call overhead over their "mm-locks.h" counterparts. However, the altp2m lock is mostly used in init/teardown routines and HVMOP implementations. For these cases, the altp2m_list_lock functions have been switched out for the altp2m_lock functions so they can be later migrated to common code. The only other function using the altp2m lock is altp2m_get_or_propagate, which is in the hot path of the page fault handler, so the altp2m_list_lock calls have not been replaced for that function.
This is commit 2/12 of the altp2m_init/altp2m_teardown routines phase.
---
v6: Introduced this patch.
This seems like the solution which makes the most sense here, but it would be nicer if it could be static inline. I'm also not sure if the "mm-locks.h" functions are really supposed to be exposed outside of their translation unit like this, so feedback on this is appreciated.
--- xen/arch/x86/include/asm/altp2m.h | 4 +++ xen/arch/x86/mm/altp2m.c | 42 ++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 15 deletions(-)
xen/arch/x86/include/asm/altp2m.h +4 -0
@@ -156,6 +156,10 @@ int p2m_set_suppress_ve_multi(struct domain *d,int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve,unsigned int altp2m_idx); +void altp2m_lock_init (struct domain *d); +void altp2m_lock (struct domain *d); +void altp2m_unlock (struct domain *d); +#else static inline bool altp2m_is_eptp_valid(const struct domain *d,
xen/arch/x86/mm/altp2m.c +27 -15
135 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v6 14/43 altp2m: Move altp2m_{init,teardown} to common code
In reply to Rose SpanglerThis commit moves the init and teardown routines into common code. The functions are gated by CONFIG_X86, so there is effectively no difference despite common code normally being compiled for ARM.
This commit contains only renames/code movement, and no functional change is intended.
This is commit 3/12 of the altp2m_init/altp2m_teardown routines phase.
---
v6: Introduced this patch.
--- xen/arch/x86/include/asm/altp2m.h | 8 ----- xen/arch/x86/mm/altp2m.c | 45 ---------------------------- xen/arch/x86/mm/p2m-basic.c | 1 + xen/common/altp2m.c | 49 +++++++++++++++++++++++++++++++ xen/include/xen/altp2m.h | 13 ++++++++ 5 files changed, 63 insertions(+), 53 deletions(-)
xen/arch/x86/include/asm/altp2m.h +0 -8
@@ -97,12 +97,6 @@ static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx)return true; } -/* Initialize altp2m views */ -int altp2m_init (struct domain *d); - -/* Free altp2m views */ -void altp2m_teardown (struct domain *d); -/* Switch alternate p2m for a single vcpu */ bool altp2m_switch_vcpu_by_id (struct vcpu *v,unsigned int idx);
@@ -184,8 +178,6 @@ static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m,_altp2m_get_effective_entry (ap2m, gfn, mfn, t, a) /* Only declaration is needed. DCE will optimise it out when linking. */ -int altp2m_init (struct domain *d); -void altp2m_teardown (struct domain *d);struct p2m_domain *altp2m_get_altp2m (struct vcpu *v);bool altp2m_set_altp2m (struct vcpu *v,unsigned int idx);uint16_t altp2m_vcpu_idx (const struct vcpu *v);
xen/arch/x86/mm/altp2m.c +0 -45
51 lines not on this page · raw message
xen/arch/x86/mm/p2m-basic.c +1 -0
@@ -11,6 +11,7 @@* Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. */ +#include <xen/altp2m.h> #include <xen/event.h> #include <xen/types.h> #include <asm/altp2m.h>
xen/common/altp2m.c +49 -0
63 lines not on this page · raw message
xen/include/xen/altp2m.h +13 -0
@@ -8,6 +8,19 @@#include <public/hvm/hvm_op.h> +/* +* Common alternate p2m declarations that need to be visible +* regardless of CONFIG_ALTP2M +*/ + +#ifdef CONFIG_X86 +/* Initialize altp2m views */ +int altp2m_init (struct domain *d); + +/* Free altp2m views */ +void altp2m_teardown (struct domain *d); +#endif +#ifdef CONFIG_ALTP2M /* Alternate p2m HVM on/off per domain */
Signature · 1 line
2.34.1
RFC PATCH v6 15/43 arm/p2m: Allocate hostp2m with xzalloc
In reply to Rose SpanglerThis commit replaces the concrete p2m_domain member in arch_domain with a pointer to p2m_domain, which is allocated with xzalloc during p2m initialization.
In the following commits, the altp2m_init and altp2m_teardown routines from x86 are be moved to common code. These routines (respectively) allocate and free the p2m_domain structs for altp2m views.
While it would be possible to have special code paths for allocating/freeing altp2m views while keeping the hostp2m as an concrete member, this results in code duplication and increases complexity without any clear benefit. Therefore, switching the hostp2m to be allocated separately from arch_domain (similarly to x86) makes it possible to use the same functions for both allocation/teardown/freeing of the hostp2m and altp2m views.
This is commit 4/12 of the altp2m_init/altp2m_teardown routines phase.
---
v6: Introduced this patch.
--- xen/arch/arm/domain.c | 2 +- xen/arch/arm/include/asm/domain.h | 2 +- xen/arch/arm/include/asm/p2m.h | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/arm/mmu/p2m.c | 27 +++++++++++++++++++++--- xen/arch/arm/traps.c | 2 +- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 2 +- xen/drivers/passthrough/arm/smmu-v3.c | 2 +- xen/drivers/passthrough/arm/smmu.c | 2 +- 9 files changed, 32 insertions(+), 11 deletions(-)
xen/arch/arm/domain.c +1 -1
@@ -1099,7 +1099,7 @@ int domain_relinquish_resources(struct domain *d)* We are about to free the intermediate page-tables, so clear the * root to prevent any walk to use them. */ -p2m_clear_root_pages (&d->arch.p2m); +p2m_clear_root_pages (d->arch.p2m); PROGRESS(p2m): ret =p2m_teardown (d);
xen/arch/arm/include/asm/domain.h +1 -1
@@ -72,7 +72,7 @@ struct arch_domain#endif /* Virtual MMU */ -struct p2m_domain p2m; +struct p2m_domain *p2m;struct hvm_domain hvm;
xen/arch/arm/include/asm/p2m.h +1 -1
@@ -410,7 +410,7 @@ static inline int get_page_and_type(struct page_info *page, }/* get host p2m table */ -#define p2m_get_hostp2m (d) (&(d)->arch.p2m) +#define p2m_get_hostp2m (d) ((d)->arch.p2m)static inline bool p2m_vm_event_sanity_check (struct domain *d) {
xen/arch/arm/mm.c +1 -1
@@ -116,7 +116,7 @@ bool page_is_offlinable(mfn_t mfn)unsigned long domain_get_maximum_gpfn (struct domain *d) { -return gfn_x (d->arch.p2m.max_mapped_gfn); +return gfn_x (d->arch.p2m->max_mapped_gfn); } void share_xen_page_with_guest(struct page_info *page, struct domain *d,
xen/arch/arm/mmu/p2m.c +24 -3
@@ -5,6 +5,7 @@#include <xen/lib.h> #include <xen/sched.h> #include <xen/softirq.h> +#include <xen/xmalloc.h> #include <asm/alternative.h> #include <asm/event.h>
@@ -1475,7 +1476,7 @@ void p2m_final_teardown(struct domain *d)/* p2m not actually initialized */ if ( !p2m->domain ) -return ; + goto free_p2m;/* * No need to call relinquish_p2m_mapping() here because
@@ -1499,11 +1500,13 @@ void p2m_final_teardown(struct domain *d)radix_tree_destroy (&p2m->mem_access_settings,NULL ); p2m->domain =NULL ; + +free_p2m: +xfree (p2m); } -int p2m_init (struct domain *d) +static int p2m_initialise (struct domain *d,struct p2m_domain *p2m) { -struct p2m_domain *p2m =p2m_get_hostp2m (d);int rc;unsigned int cpu;
@@ -1556,6 +1559,24 @@ int p2m_init(struct domain *d)return 0 ; } +int p2m_init (struct domain *d) +{ + struct p2m_domain *p2m = xzalloc(struct p2m_domain); +int rc; + +if ( !p2m ) +return -ENOMEM ; + + rc =p2m_initialise (d, p2m); + +if ( !rc ) + d->arch.p2m = p2m; +else +xfree (p2m); + +return rc; +} +/* * The function will go through the p2m and remove page reference when it * is required. The mapping will be removed from the p2m.
xen/arch/arm/traps.c +1 -1
@@ -984,7 +984,7 @@ void vcpu_show_registers(struct vcpu *v)#endif #ifdef CONFIG_MMU - ctxt.vttbr_el2 = v->domain->arch.p2m.vttbr; + ctxt.vttbr_el2 = v->domain->arch.p2m->vttbr;#endif _show_registers (&v->arch.cpu_info->guest_cpu_user_regs, &ctxt,1 , v);
xen/drivers/passthrough/arm/ipmmu-vmsa.c +1 -1
@@ -565,7 +565,7 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)* Use P2M table for this Xen domain. */ ASSERT (domain->d !=NULL ); - ttbr =page_to_maddr (domain->d->arch.p2m.root); + ttbr =page_to_maddr (domain->d->arch.p2m->root);dev_info (domain->mmu->root->dev,"%pd: Set IPMMU context %u (pgd 0x%" PRIx64")\n" , domain->d, domain->context_id, ttbr);
xen/drivers/passthrough/arm/smmu-v3.c +1 -1
@@ -1205,7 +1205,7 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, vtcr->tsz =64 - p2m_ipa_bits; vtcr->sl =2 -P2M_ROOT_LEVEL ; - arm_lpae_s2_cfg.vttbr =page_to_maddr (smmu_domain->d->arch.p2m.root); + arm_lpae_s2_cfg.vttbr =page_to_maddr (smmu_domain->d->arch.p2m->root); vmid =arm_smmu_bitmap_alloc (smmu->vmid_map, smmu->vmid_bits);if (vmid <0 )
xen/drivers/passthrough/arm/smmu.c +1 -1
@@ -1247,7 +1247,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)/* TTBR0 */ /* Xen: The page table is shared with the P2M code */ ASSERT (smmu_domain->cfg.domain !=NULL ); - p2maddr =page_to_maddr (smmu_domain->cfg.domain->arch.p2m.root); + p2maddr =page_to_maddr (smmu_domain->cfg.domain->arch.p2m->root);dev_notice (smmu->dev,"d%u: p2maddr 0x%" PRIpaddr"\n" , smmu_domain->cfg.domain->domain_id, p2maddr);
Signature · 1 line
2.34.1
RFC PATCH v6 16/43 arm/p2m: Cosmetic fix - substitute _gfn(ULONG_MAX) for INVALID_GFN
In reply to Rose SpanglerFrom: Sergej Proskurin <[email protected]>
In ./xen/arch/arm/p2m.c, we compare the gfn's with INVALID_GFN throughout the code. Thus it makes sense to use the macro INVALID_GFN instead of a hard coded value to initialize "p2m->lowest_mapped_gfn".
This is commit 5/12 of the altp2m_init/altp2m_teardown routines phase.
--- xen/arch/arm/mmu/p2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/mmu/p2m.c +1 -1
@@ -1517,7 +1517,7 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m) p2m->vmid =INVALID_VMID ; p2m->max_mapped_gfn =_gfn (0 ); - p2m->lowest_mapped_gfn =_gfn (ULONG_MAX ); + p2m->lowest_mapped_gfn =INVALID_GFN ; p2m->default_access = p2m_access_rwx; p2m->mem_access_enabled = false;
Signature · 1 line
2.34.1
RFC PATCH v6 17/43 arm/p2m: Move hostp2m init/teardown to individual functions
In reply to Rose SpanglerThis commit pulls out generic init/teardown functionality out of "p2m_init" and "p2m_teardown" into "p2m_init_one", "p2m_teardown_one", "p2m_free_one", and "p2m_flush_table" functions. This allows our future implementation to reuse existing code for the initialization/teardown of altp2m views.
On failure, the p2m_init_one function returns a null pointer. This means p2m_init_one doesn't return an error code, which prevents it from propagating the exact error from p2m_initialise (specifically, ENOMEM if allocation fails and EBUSY if the VMID pool is exhausted). However, returning a p2m_domain pointer simplifies usage for callers of p2m_init_one, as they can receive an allocated and initialized p2m_domain without needing to handle allocation separately. Therefore, the main p2m_init function will now return ENOMEM instead of EBUSY when the VMID pool is exhausted.
This is commit 6/12 of the altp2m_init/altp2m_teardown routines phase.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
---
v2: Added the function p2m_flush_table to the previous version.
v3: Removed struct vttbr.
Moved define INVALID_VTTBR to p2m.h.
Exported function prototypes of "p2m_flush_table", "p2m_init_one", and "p2m_teardown_one" in p2m.h.
Extended the function "p2m_flush_table" by additionally resetting the fields lowest_mapped_gfn and max_mapped_gfn.
Added a "p2m_flush_tlb" call in "p2m_flush_table". On altp2m reset in function "altp2m_reset", it is important to flush the TLBs after clearing the root table pages and before clearing the intermediate altp2m page tables to prevent illegal access to stalled TLB entries on currently active VCPUs.
Added a check checking whether p2m->root is NULL in p2m_flush_table.
Renamed the function "p2m_free_one" to "p2m_teardown_one".
Removed resetting p2m->vttbr in "p2m_teardown_one", as it the p2m will be destroyed afterwards.
Moved call to "p2m_alloc_table" back to "p2m_init_one".
Moved the introduction of the type p2m_class_t out of this patch.
Moved the backpointer to the struct domain out of the struct p2m_domain.
v4: Replaced the former use of clear_and_clean_page in p2m_flush_table
by a routine that invalidates every p2m entry atomically. This avoids inconsistencies on CPUs that continue to use the views that are to be flushed (e.g., see altp2m_reset).
Removed unnecessary initializations in the functions "p2m_init_one" and "p2m_teardown_one".
Removed the define INVALID_VTTBR as it is not used any more.
Cosmetic fixes.
v6: Reworked to accommodate the hostp2m being allocated separately from
arch_domain.
Split p2m_teardown_one into p2m_teardown_one and p2m_free_one, with both having the same semantics as their x86 counterparts.
The previous version of this patch also added code to p2m_flush_table. This has been split out into a separate commit to minimize the number of actual changes in this commit.
Updated to account for the introduction of p2m_final_teardown. The code which previously was used to reclaim resources from the hostp2m during p2m_final_teardown was extracted into p2m_free_one. Now, p2m_final_teardown will call p2m_free_one on the hostp2m instead. The check for whether the p2m was actually initialized was moved into p2m_free_one. This means there is a slight behavior change where p2m_teardown_allocation will always be called, even if the p2m_domain was never initialized. I'm not sure if this is really a big deal (it does require the lock to be obtained, but this shouldn't be an issue at final teardown?), but if it is then I can duplicate the check from p2m_free_one to the top of p2m_final_teardown, which would replicate the previous behavior.
For the sake of making the p2m_init_one function simple to use (and match the x86 function prototype), it returns a null pointer on error rather than an error code. While on x86 an error from p2m_init_one is always due to an ENOMEM return code (from xzalloc, zalloc_cpumask_var), on ARM p2m_initialise (called by p2m_init_one) can actually return EBUSY if the VMID pool is exhausted. Therefore, in this error case the null pointer return value of p2m_init_one obscures the true error code (EBUSY). Callers of p2m_init_one always return ENOMEM when p2m_init_one returns a null pointer, so this error will be propagated up as ENOMEM rather than EBUSY. The alternative to this would be to have callers pass a null **p2m_domain to p2m_init_one while still returning an integer return code. In order to preserve a common altp2m_init routine, this change would also have to be made on x86 (where there wouldn't be any real benefit, the return code is truly only ever ENOMEM). Therefore, it seems like an acceptable tradeoff to me to obscure the error in this case, but if other folks think we should handle this differently than I can revisit this.
The p2m_teardown_allocation call and p2m_init_one return code changes mentioned above should be the only actual behavior changes in this patch, otherwise it should be just code movement.
--- xen/arch/arm/include/asm/p2m.h | 12 ++++++ xen/arch/arm/mmu/p2m.c | 77 +++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 24 deletions(-)
xen/arch/arm/include/asm/p2m.h +12 -0
@@ -216,6 +216,18 @@ int p2m_init(struct domain *d);int p2m_teardown (struct domain *d);void p2m_final_teardown (struct domain *d); +/* Flushes the page table held by the p2m. */ +int p2m_flush_table (struct p2m_domain *p2m); + +/* Initialize the p2m structure. */ +struct p2m_domain *p2m_init_one (struct domain *d); + +/* Release resources held by the p2m structure. */ +int p2m_teardown_one (struct p2m_domain *p2m); + +/* Free the p2m structure allocation. */ +void p2m_free_one (struct p2m_domain *p2m); +/* * Remove mapping refcount on each mapping page in the p2m *
xen/arch/arm/mmu/p2m.c +53 -24
139 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v6 18/43 arm/p2m: Invalidate root page table entries and flush TLB in p2m_flush_table
In reply to Rose SpanglerThis commit invalidates the root page table entries and flushes the TLB when the table is flushed. The TLB is flushed to ensure that altp2m views after being reset or torn down. Previously, the code in p2m_flush_table was only used to free p2m pages during domain teardown. This function will later be used to teardown/reset altp2m views of a still-running domain, so the page table entries must be properly invalidated.
Additionally, the p2m_invalidate_root function is split into p2m_invalidate_root and p2m_invalidate_root_locked. The p2m_flush_table function already holds the lock, so it calls p2m_invalidate_root_locked directly, as opposed to the existing callers which don't already hold the lock.
This is commit 7/12 of the altp2m_init/altp2m_teardown routines phase.
---
v3: Added a "p2m_flush_tlb" call in "p2m_flush_table". On altp2m reset
in function "altp2m_reset", it is important to flush the TLBs after clearing the root table pages and before clearing the intermediate altp2m page tables to prevent illegal access to stalled TLB entries on currently active VCPUs.
v4: Replaced the former use of clear_and_clean_page in p2m_flush_table
by a routine that invalidates every p2m entry atomically. This avoids inconsistencies on CPUs that continue to use the views that are to be flushed (e.g., see altp2m_reset).
v6: Introduced this patch. While the code in this patch is mostly new, it
is the same in spirit as the p2m_flush_table additions in the original patch series, so the relevant comments have been reproduced above.
In the v4/v5 versions of this patch series, this patch was a part of the previous patch. It has been split out to minimize the number of functionality changes in the previous patch.
Additionally, the original patch series used a routine here which was nearly identical to p2m_invalidate_root, which was implemented a few years after the patch series. Therefore, the existing p2m_invalidate_root implementation is used here instead.
Also, since the original patch series p2m_teardown (and by extension p2m_flush_table, as it was extracted from p2m_teardown) was made preemptible. As a consequence of this, introducing a call to p2m_invalidate_root here also means that p2m_invalidate_root and p2m_tlb_flush_sync is called each time p2m_flush_table is called, even if a previous call to p2m_flush_table was preempted. This might cause some additional overhead, as p2m_flush_table will iterate over the root page tables and flush the TLB before it can return to freeing p2m pages. I'm not sure if there's a better way of handling this, or if the overhead here is negligible/acceptable.
I'm not sure how IOMMU interacts with altp2m here. I haven't looked into it extensively, so I would appreciate some feedback here. I've just copied over the iommu_use_hap_pt conditional from p2m_domain_creation_finished, but this is probably not the right behavior since we probably still need to invalidate the altp2m view page tables on flush somehow. Is the issue with invalidating root page tables when using IOMMU only relevant for the hostp2m, or is it also relevant for the altp2m views?
--- xen/arch/arm/mmu/p2m.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
xen/arch/arm/mmu/p2m.c +13 -3
@@ -1271,17 +1271,20 @@ void p2m_clear_root_pages(struct p2m_domain *p2m)* p2m_invalid_root() should not be called when the P2M is shared with * the IOMMU because it will cause IOMMU fault. */ -static void p2m_invalidate_root (struct p2m_domain *p2m) +static void p2m_invalidate_root_locked (struct p2m_domain *p2m) {unsigned int i;ASSERT (!iommu_use_hap_pt (p2m->domain)); -p2m_write_lock (p2m); -for ( i =0 ; i <P2M_ROOT_PAGES ; i++ )p2m_invalidate_table (p2m,page_to_mfn (p2m->root + i)); +} +static void p2m_invalidate_root (struct p2m_domain *p2m) +{ +p2m_write_lock (p2m); +p2m_invalidate_root_locked (p2m);p2m_write_unlock (p2m); }
@@ -1449,6 +1452,13 @@ int p2m_flush_table(struct p2m_domain *p2m)unsigned long count =0 ;struct page_info *pg; +/* TODO: How does IOMMU interact with altp2m? */ +if ( !iommu_use_hap_pt (p2m->domain) ) + { +p2m_invalidate_root_locked (p2m); +p2m_tlb_flush_sync (p2m); + } +while ( (pg =page_list_remove_head (&p2m->pages)) ) {p2m_free_page (p2m->domain, pg);
Signature · 1 line
2.34.1
RFC PATCH v6 19/43 arm/p2m: Change function prototype of p2m_alloc_table
In reply to Rose SpanglerFrom: Sergej Proskurin <[email protected]>
The function "p2m_alloc_table" should be able to allocate 2nd stage translation tables not only for the host's p2m but also for alternate p2m's.
This commit is a refactor and contains no functional changes.
This is commit 8/12 of the altp2m_init/altp2m_teardown routines phase.
---
v2: Removed altp2m table initialization from "p2m_table_init".
v3: Removed initialization of the field d->arch.altp2m_active in
"p2m_table_init" to avoid altp2m initialization throughout different files.
Merged the function "p2m_alloc_table" and "p2m_table_init".
--- xen/arch/arm/mmu/p2m.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
xen/arch/arm/mmu/p2m.c +2 -4
@@ -1426,10 +1426,8 @@ static struct page_info *p2m_allocate_root(void)return page; } -static int p2m_alloc_table (struct domain *d) +static int p2m_alloc_table (struct p2m_domain *p2m) { -struct p2m_domain *p2m =p2m_get_hostp2m (d); - p2m->root =p2m_allocate_root ();if ( !p2m->root )return -ENOMEM ;
@@ -1576,7 +1574,7 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)if ( rc )return rc; - rc =p2m_alloc_table (d); + rc =p2m_alloc_table (p2m);if ( rc )return rc;
Signature · 1 line
2.34.1
RFC PATCH v6 20/43 arm/p2m: Rename parameter in p2m_alloc_vmid
In reply to Rose SpanglerFrom: Sergej Proskurin <[email protected]>
This commit does not change or introduce any additional functionality but rather is a part of the following commit that alters the functionality of the function "p2m_alloc_vmid".
This is commit 9/12 of the altp2m_init/altp2m_teardown routines phase.
--- xen/arch/arm/p2m.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/arm/p2m.c +6 -6
@@ -286,24 +286,24 @@ int p2m_alloc_vmid(struct domain *d) {struct p2m_domain *p2m =p2m_get_hostp2m (d); -int rc, nr; +int rc, vmid;spin_lock (&vmid_alloc_lock); - nr =find_first_zero_bit (vmid_mask,MAX_VMID ); + vmid =find_first_zero_bit (vmid_mask,MAX_VMID ); -ASSERT (nr !=INVALID_VMID ); +ASSERT (vmid !=INVALID_VMID ); -if ( nr ==MAX_VMID ) +if ( vmid ==MAX_VMID ) { rc = -EBUSY ;printk (XENLOG_ERR "p2m.c: dom%d: VMID pool exhausted\n" , d->domain_id); goto out; } -set_bit (nr, vmid_mask); +set_bit (vmid, vmid_mask); - p2m->vmid = nr; + p2m->vmid = vmid; rc =0 ;
Signature · 1 line
2.34.1
RFC PATCH v6 21/43 arm/p2m: Change func prototype and impl of p2m_{alloc,free}_vmid
In reply to Rose SpanglerFrom: Sergej Proskurin <[email protected]>
This commit changes the prototype and implementation of the functions "p2m_alloc_vmid" and "p2m_free_vmid". The function "p2m_alloc_vmid" does not expect the struct domain as argument anymore and returns an allocated vmid. The function "p2m_free_vmid" takes only the vmid that is to be freed as argument.
This is commit 10/12 of the altp2m_init/altp2m_teardown routines phase.
---
v3: Changed function prototypes and implementation of the functions
"p2m_alloc_vmid" and "p2m_free_vmid".
Changes in "p2m_alloc_vmid":
This function does not expect any arguments. Also, in this commit, the function "p2m_alloc_vmid" returns either the successfully allocated vmid or the value INVALID_VMID. Thus, it is now the responsibility of the caller to set the returned vmid in the associated fields.
Changes in "p2m_free_vmid":
This function expects now only the vmid of type uint8_t.
--- xen/arch/arm/include/asm/p2m.h | 4 ++-- xen/arch/arm/mmu/p2m.c | 8 ++++---- xen/arch/arm/p2m.c | 23 ++++++++--------------- 3 files changed, 14 insertions(+), 21 deletions(-)
xen/arch/arm/include/asm/p2m.h +2 -2
@@ -195,8 +195,8 @@ static inline bool arch_acquire_resource_check(struct domain *d)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); +uint8_t p2m_alloc_vmid (void ); +void p2m_free_vmid (uint8_t vmid);/* Second stage paging setup, to be called on all CPUs */ void setup_virt_paging (void );
xen/arch/arm/mmu/p2m.c +4 -4
@@ -1519,7 +1519,7 @@ void p2m_free_one(struct p2m_domain *p2m) p2m->root =NULL ; -p2m_free_vmid (p2m->domain); +p2m_free_vmid (p2m->vmid);radix_tree_destroy (&p2m->mem_access_settings,NULL );
@@ -1570,9 +1570,9 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)*/ p2m->domain = d; - rc =p2m_alloc_vmid (d); -if ( rc ) -return rc; + p2m->vmid =p2m_alloc_vmid (); +if ( p2m->vmid ==INVALID_VMID ) +return -EBUSY ; rc =p2m_alloc_table (p2m);if ( rc )
xen/arch/arm/p2m.c +8 -15
@@ -282,11 +282,9 @@ void p2m_vmid_allocator_init(void)set_bit (INVALID_VMID , vmid_mask); } -int p2m_alloc_vmid (struct domain *d) +uint8_t p2m_alloc_vmid (void ) { -struct p2m_domain *p2m =p2m_get_hostp2m (d); - -int rc, vmid; +uint8_t vmid;spin_lock (&vmid_alloc_lock);
@@ -296,28 +294,23 @@ int p2m_alloc_vmid(struct domain *d)if ( vmid ==MAX_VMID ) { - rc = -EBUSY ; -printk (XENLOG_ERR "p2m.c: dom%d: VMID pool exhausted\n" , d->domain_id); + vmid =INVALID_VMID ; +printk (XENLOG_ERR "p2m.c: VMID pool exhausted\n" ); goto out; }set_bit (vmid, vmid_mask); - p2m->vmid = vmid; - - rc =0 ; - out:spin_unlock (&vmid_alloc_lock); -return rc; +return vmid; } -void p2m_free_vmid (struct domain *d) +void p2m_free_vmid (uint8_t vmid) { -struct p2m_domain *p2m =p2m_get_hostp2m (d);spin_lock (&vmid_alloc_lock); -if ( p2m->vmid !=INVALID_VMID ) -clear_bit (p2m->vmid, vmid_mask); +if ( vmid !=INVALID_VMID ) +clear_bit (vmid, vmid_mask);spin_unlock (&vmid_alloc_lock); }
Signature · 1 line
2.34.1
RFC PATCH v6 22/43 arm/p2m: Introduce p2m_is_{hostp2m,altp2m}
In reply to Rose SpanglerFrom: Sergej Proskurin <[email protected]>
This commit adds a p2m class to the struct p2m_domain to distinguish between the host's original p2m and alternate p2m's. The need for this functionality will be shown in the following commits.
This is commit 11/12 of the altp2m_init/altp2m_teardown routines phase.
---
v4: Change return type of p2m_is_(hostp2m|altp2m) from bool_t to bool.
--- xen/arch/arm/include/asm/p2m.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
xen/arch/arm/include/asm/p2m.h +18 -0
@@ -32,6 +32,11 @@ struct domain;extern void memory_type_changed (struct domain *d); +typedef enum { + p2m_host, + p2m_alternate, +}p2m_class_t ; +/* Per-p2m-table state */ struct p2m_domain {/*
@@ -111,6 +116,9 @@ struct p2m_domain {/* Keeping track on which CPU this p2m was used and for which vCPU */ uint8_t last_vcpu_ran[NR_CPUS ]; + +/* Choose between: host/alternate. */ +p2m_class_t p2m_class; };/*
@@ -424,6 +432,16 @@ static inline int get_page_and_type(struct page_info *page,/* get host p2m table */ #define p2m_get_hostp2m (d) ((d)->arch.p2m) +static inline bool p2m_is_hostp2m (const struct p2m_domain *p2m) +{ +return p2m->p2m_class == p2m_host; +} + +static inline bool p2m_is_altp2m (const struct p2m_domain *p2m) +{ +return p2m->p2m_class == p2m_alternate; +} +static inline bool p2m_vm_event_sanity_check (struct domain *d) {return true;
Signature · 1 line
2.34.1
RFC PATCH v6 23/43 arm/altp2m: Add support for altp2m init/teardown routines
In reply to Rose SpanglerThe p2m initialization now invokes initialization routines responsible for the allocation and initialization of altp2m structures. The same applies to teardown routines.
This commit adds the prerequisites for the common altp2m_init and altp2m_teardown functions to work on ARM; No further changes were necessary other than removing the CONFIG_X86 gating.
This is commit 12/12 of the altp2m_init/altp2m_teardown routines phase.
---
v2: Shared code between host/altp2m init/teardown functions.
Added conditional init/teardown of altp2m. Altp2m related functions are moved to altp2m.c
v3: Removed locking the altp2m_lock in altp2m_teardown. Locking this
lock at this point is unnecessary.
Removed re-setting altp2m_vttbr, altp2m_p2m, and altp2m_active values in the function "altp2m_teardown". Re-setting these values is unnecessary as the entire domain will be destroyed right afterwards.
Removed check for "altp2m_enabled" in "p2m_init" as altp2m has not yet been enabled by libxl at this point.
Removed check for "altp2m_enabled" before tearing down altp2m within the function "p2m_teardown" so that altp2m gets destroyed even if the HVM_PARAM_ALTP2M gets reset before "p2m_teardown" is called.
Added initialization of the field d->arch.altp2m_active in "altp2m_init".
Removed check for already initialized vmid's in "altp2m_init_one", as "altp2m_init_one" is now called always with an uninitialized p2m.
Removed the array altp2m_vttbr[] in struct arch_domain.
v4: Removed initialization of altp2m_p2m[] to NULL in altp2m_init, as
the "struct arch_domain" is already initialized to zero.
We moved the definition of the macro MAX_ALTP2M to a common place in a separate commit.
v6: Reworked to use common altp2m init and teardown routines.
Added altp2m_lock_init macro for use in altp2m_init.
Split altp2m initialization in p2m_init into a separate function, p2m_init_altp2m, to more easily gate code behind CONFIG_ALTP2M.
Pulled in addition of active_vcpus from a later patch in the patch series.
Split teardown and free of altp2m views into p2m_teardown and p2m_teardown_final (part of altp2m_teardown), respectively.
--- xen/arch/arm/include/asm/altp2m.h | 4 +++ xen/arch/arm/include/asm/domain.h | 8 ++++++ xen/arch/arm/include/asm/p2m.h | 5 ++++ xen/arch/arm/mmu/p2m.c | 44 ++++++++++++++++++++++++++++++- xen/common/altp2m.c | 2 -- xen/include/xen/altp2m.h | 2 -- 6 files changed, 60 insertions(+), 5 deletions(-)
xen/arch/arm/include/asm/altp2m.h +4 -0
@@ -19,6 +19,10 @@ static inline bool altp2m_supported(void)return true; } +#define altp2m_lock_init (d) spin_lock_init(&(d)->arch.altp2m_lock) +#define altp2m_lock (d) spin_lock(&(d)->arch.altp2m_lock) +#define altp2m_unlock (d) spin_unlock(&(d)->arch.altp2m_lock) +/* Alternate p2m VCPU */ static inline uint16_t altp2m_vcpu_idx (const struct vcpu *v) {
xen/arch/arm/include/asm/domain.h +8 -0
@@ -128,6 +128,14 @@ struct arch_domain#endif struct resume_info resume_ctx; + +#ifdef CONFIG_ALTP2M +/* +* Lock that protects critical altp2m operations that must not be performed +* concurrently. +*/ +spinlock_t altp2m_lock; +#endif } __cacheline_aligned;struct arch_vcpu
xen/arch/arm/include/asm/p2m.h +5 -0
@@ -9,6 +9,8 @@#include <asm/current.h> #include <asm/hsr.h> +#include <asm/atomic.h> +#define paddr_bits PADDR_BITS/* Holds the bit size of IPAs in p2m tables. */
@@ -117,6 +119,9 @@ struct p2m_domain {/* Keeping track on which CPU this p2m was used and for which vCPU */ uint8_t last_vcpu_ran[NR_CPUS ]; +/* Alternate p2m: count of vcpu's currently using this p2m. */ +atomic_t active_vcpus; +/* Choose between: host/alternate. */ p2m_class_t p2m_class; };
xen/arch/arm/mmu/p2m.c +43 -1
81 lines not on this page · raw message
xen/common/altp2m.c +0 -2
@@ -15,7 +15,6 @@#include <asm/hvm/nestedhvm.h> #endif -#if CONFIG_X86 int altp2m_init (struct domain *d) {unsigned int i;
@@ -60,7 +59,6 @@ void altp2m_teardown(struct domain *d)XVFREE (d->altp2m_p2m); } -#endif /* CONFIG_X86 */ /* * altp2m operations are envisioned as being used in several different
xen/include/xen/altp2m.h +0 -2
@@ -13,13 +13,11 @@* regardless of CONFIG_ALTP2M */ -#ifdef CONFIG_X86 /* Initialize altp2m views */ int altp2m_init (struct domain *d);/* Free altp2m views */ void altp2m_teardown (struct domain *d); -#endif #ifdef CONFIG_ALTP2M
Signature · 1 line
2.34.1
RFC PATCH v6 24/43 altp2m: Move altp2m_{get,set}_altp2m to common code
In reply to Rose SpanglerThis commit moves the altp2m_get_altp2m and altp2m_set_altp2m functions to the common code. This make sit possible to use them in other common routines (namely, altp2m_vcpu_{initialise,destroy}).
This commit contains only code movement, and no change in functionality is intended.
This is commit 1/4 of the altp2m_{get,set}_altp2m phase.
---
v6: Introduced this patch.
--- xen/arch/x86/include/asm/altp2m.h | 35 ------------------------- xen/arch/x86/include/asm/domain.h | 2 -- xen/common/altp2m.c | 1 - xen/include/xen/altp2m.h | 43 +++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 38 deletions(-)
xen/arch/x86/include/asm/altp2m.h +0 -35
@@ -64,39 +64,6 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)* Alternate p2m: shadow p2m tables used for alternate memory views */ -/* get current alternate p2m table */ -static inline struct p2m_domain *altp2m_get_altp2m (struct vcpu *v) -{ -unsigned int index =vcpu_altp2m (v).p2midx; - -if ( index ==INVALID_ALTP2M ) -return NULL ; - -BUG_ON (index >= v->domain->nr_altp2m); - -return v->domain->altp2m_p2m[index]; -} - -/* set current alternate p2m table */ -static inline bool altp2m_set_altp2m (struct vcpu *v,unsigned int idx) -{ -struct p2m_domain *orig; - -BUG_ON (idx >= v->domain->nr_altp2m); - -if ( idx ==vcpu_altp2m (v).p2midx ) -return false; - - orig =altp2m_get_altp2m (v); -BUG_ON (!orig); -atomic_dec (&orig->active_vcpus); - -vcpu_altp2m (v).p2midx = idx; -atomic_inc (&v->domain->altp2m_p2m[idx]->active_vcpus); - -return true; -} -/* Switch alternate p2m for a single vcpu */ bool altp2m_switch_vcpu_by_id (struct vcpu *v,unsigned int idx);
@@ -178,8 +145,6 @@ static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m,_altp2m_get_effective_entry (ap2m, gfn, mfn, t, a) /* Only declaration is needed. DCE will optimise it out when linking. */ -struct p2m_domain *altp2m_get_altp2m (struct vcpu *v); -bool altp2m_set_altp2m (struct vcpu *v,unsigned int idx);uint16_t altp2m_vcpu_idx (const struct vcpu *v);void altp2m_vcpu_initialise (struct vcpu *v);void altp2m_vcpu_destroy (struct vcpu *v);
xen/arch/x86/include/asm/domain.h +0 -2
@@ -277,8 +277,6 @@ struct paging_vcpu {#define MAX_NR_ALTP2M MAX_EPTP#define MAX_NESTEDP2M 10 -#define INVALID_ALTP2M 0xffff -struct p2m_domain ;struct time_scale {int shift;
xen/common/altp2m.c +0 -1
@@ -5,7 +5,6 @@#include <xen/xvmalloc.h> #include <asm/altp2m.h> -#include <asm/p2m.h> #include <public/hvm/params.h>
xen/include/xen/altp2m.h +43 -0
61 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v6 25/43 arm/altp2m: Add altp2m index to arch_vcpu
In reply to Rose SpanglerThis commit adds ap2m_idx to the VCPU struct on ARM. This makes it possible to track the current altp2m view being used by a VCPU.
This is commit 2/4 of the altp2m_{get,set}_altp2m phase.
---
v6: This patch was originally part of the "arm/p2m: Add
HVMOP_altp2m_set_domain_state" patch from the v4/v5 patch series. It has been extracted into its own commit to make the patch series easier to follow. If it would be preferred, this commit can be squashed into another commit.
Added support for the CONFIG_ALTP2M option.
--- xen/arch/arm/include/asm/altp2m.h | 4 +--- xen/arch/arm/include/asm/domain.h | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/altp2m.h +1 -3
@@ -26,9 +26,7 @@ static inline bool altp2m_supported(void)/* Alternate p2m VCPU */ static inline uint16_t altp2m_vcpu_idx (const struct vcpu *v) { -/* Not implemented yet */ -BUG (); -return 0 ; +return v->arch.ap2m_idx; }#else /* CONFIG_ALTP2M */
xen/arch/arm/include/asm/domain.h +5 -0
@@ -249,6 +249,11 @@ struct arch_vcpustruct vtimer virt_timer;bool vtimer_initialized; +#if CONFIG_ALTP2M +/* Alternate p2m index */ +uint16_t ap2m_idx; +#endif +/* * The full P2M may require some cleaning (e.g when emulation * set/way). As the action can take a long time, it requires
Signature · 1 line
2.34.1
RFC PATCH v6 26/43 altp2m: Add altp2m_set_vcpu_idx
In reply to Rose SpanglerThis commit adds the altp2m_set_vcpu_idx function for both x86 and ARM. Since the altp2m VCPU index is stored differently depending on which architecture is used, the altp2m_set_vcpu_idx function makes it possible to set this value in an architecture independent way for common code routines.
This is commit 3/4 of the altp2m_{get,set}_altp2m phase.
---
v6: Introduced this patch.
--- xen/arch/arm/include/asm/altp2m.h | 5 +++++ xen/arch/x86/include/asm/altp2m.h | 5 +++++ 2 files changed, 10 insertions(+)
xen/arch/arm/include/asm/altp2m.h +5 -0
@@ -29,6 +29,11 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) return v->arch.ap2m_idx; } +static inline void altp2m_set_vcpu_idx (struct vcpu *v,unsigned int idx) +{ + v->arch.ap2m_idx = idx; +} +#else /* CONFIG_ALTP2M */ static inline bool altp2m_supported (void )
xen/arch/x86/include/asm/altp2m.h +5 -0
@@ -60,6 +60,11 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)return vcpu_altp2m (v).p2midx; } +static inline void altp2m_set_vcpu_idx (struct vcpu *v,unsigned int idx) +{ +vcpu_altp2m (v).p2midx = idx; +} +/* * Alternate p2m: shadow p2m tables used for alternate memory views */
Signature · 1 line
2.34.1
RFC PATCH v6 27/43 arm/altp2m: Add support for altp2m_{get,set}_altp2m
In reply to Rose SpanglerThis commit adds support for altp2m_get_altp2m and altp2m_set_altp2m on ARM. The x86-specific VCPU accesses have been replaced with the architecture independent functions altp2m_vcpu_idx and altp2m_set_vcpu_idx.
This is commit 4/4 of the altp2m_{get,set}_altp2m phase.
---
v6: Introduced this patch.
--- xen/include/xen/altp2m.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
xen/include/xen/altp2m.h +4 -5
@@ -8,6 +8,7 @@#include <public/hvm/hvm_op.h> +#include <asm/altp2m.h> #include <asm/p2m.h> #define INVALID_ALTP2M 0xffff
@@ -31,11 +32,10 @@ static inline bool altp2m_active(const struct domain *d)return d->altp2m_active; } -#ifdef CONFIG_X86 /* get current alternate p2m table */ static inline struct p2m_domain *altp2m_get_altp2m (struct vcpu *v) { -unsigned int index =vcpu_altp2m (v).p2midx; +unsigned int index =altp2m_vcpu_idx (v);if ( index ==INVALID_ALTP2M )return NULL ;
@@ -52,19 +52,18 @@ static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx)BUG_ON (idx >= v->domain->nr_altp2m); -if ( idx ==vcpu_altp2m (v).p2midx ) +if ( idx ==altp2m_vcpu_idx (v) )return false; orig =altp2m_get_altp2m (v);BUG_ON (!orig);atomic_dec (&orig->active_vcpus); -vcpu_altp2m (v).p2midx = idx; +altp2m_set_vcpu_idx (v, idx);atomic_inc (&v->domain->altp2m_p2m[idx]->active_vcpus);return true; } -#endif int do_altp2m_op (XEN_GUEST_HANDLE_PARAM (void ) arg);
Signature · 1 line
2.34.1
RFC PATCH v6 28/43 altp2m: Move altp2m_vcpu_{initialise,destroy} to common code
In reply to Rose SpanglerThis commit moves the altp2m_vcpu_initialise and altp2m_vcpu_destroy functions to common code. This makes it possible to use them in the common implementation of HVMOP_altp2m_set_domain_state.
This commit contains only code movement, and no change in functionality is intended.
This is commit 1/2 of the altp2m_vcpu_{initialise,destroy} phase.
---
v6: Introduced this patch.
--- xen/arch/x86/include/asm/altp2m.h | 6 ----- xen/arch/x86/mm/altp2m.c | 41 ------------------------------- xen/common/altp2m.c | 41 +++++++++++++++++++++++++++++++ xen/include/xen/altp2m.h | 6 +++++ 4 files changed, 47 insertions(+), 47 deletions(-)
xen/arch/x86/include/asm/altp2m.h +0 -6
@@ -105,10 +105,6 @@ int altp2m_get_effective_entry(struct p2m_domain *ap2m, gfn_t gfn, mfn_t *mfn, p2m_type_t *t, p2m_access_t *a, bool prepopulate); -/* Alternate p2m VCPU */ -void altp2m_vcpu_initialise (struct vcpu *v); -void altp2m_vcpu_destroy (struct vcpu *v); -int altp2m_vcpu_enable_ve (struct vcpu *v,gfn_t gfn);void altp2m_vcpu_disable_ve (struct vcpu *v);
@@ -151,8 +147,6 @@ static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m,/* Only declaration is needed. DCE will optimise it out when linking. */ uint16_t altp2m_vcpu_idx (const struct vcpu *v); -void altp2m_vcpu_initialise (struct vcpu *v); -void altp2m_vcpu_destroy (struct vcpu *v);int altp2m_vcpu_enable_ve (struct vcpu *v,gfn_t gfn);void altp2m_vcpu_disable_ve (struct vcpu *v);
xen/arch/x86/mm/altp2m.c +0 -41
47 lines not on this page · raw message
xen/common/altp2m.c +41 -0
47 lines not on this page · raw message
xen/include/xen/altp2m.h +6 -0
@@ -24,6 +24,12 @@ int altp2m_init(struct domain *d);/* Free altp2m views */ void altp2m_teardown (struct domain *d); +#ifdef CONFIG_X86 +/* Alternate p2m VCPU */ +void altp2m_vcpu_initialise (struct vcpu *v); +void altp2m_vcpu_destroy (struct vcpu *v); +#endif +#ifdef CONFIG_ALTP2M /* Alternate p2m HVM on/off per domain */
Signature · 1 line
2.34.1
RFC PATCH v6 29/43 arm/altp2m: Add support for altp2m_vcpu_{initialise,destroy}
In reply to Rose SpanglerThis commit adds support for the altp2m_vcpu_initialise and altp2m_vcpu_destroy functions on ARM. The x86-specific function calls, altp2m_vcpu_disable_ve and altp2m_vcpu_update_p2m, are gated with #ifdef CONFIG_X86.
This is commit 2/2 of the altp2m_vcpu_{initialise,destroy} phase.
---
v6: Introduced this patch.
The equivalent to this patch in the v4/v5 was originally part of the patch named "arm/altp2m: Add HVMOP_altp2m_set_domain_state". In that patch, the check that the VCPU passed to altp2m_vcpu_initialise isn't the current CPU was removed. This was because ARM only implements the external altp2m mode, meaning the current VCPU could never be a VCPU of the guest for which altp2m is being initialized for. Therefore, skipping this check was a slight optimization. I've removed that here because altp2m_vcpu_initialise is only called during an HVMOP, and skipping this check on ARM (especially when x86 also implements the external altp2m mode) causes more confusion than the slight optimization is worth in my view.
--- xen/common/altp2m.c | 14 ++++++++++---- xen/include/xen/altp2m.h | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-)
xen/common/altp2m.c +10 -4
@@ -11,6 +11,7 @@#include <xsm/xsm.h> #if defined(CONFIG_X86 ) && defined(CONFIG_HVM ) +#include <asm/hvm/hvm.h> #include <asm/hvm/nestedhvm.h> #endif
@@ -59,7 +60,6 @@ void altp2m_teardown(struct domain *d)XVFREE (d->altp2m_p2m); } -#ifdef CONFIG_X86 void altp2m_vcpu_initialise (struct vcpu *v) {if ( !v->domain->nr_altp2m )
@@ -68,10 +68,12 @@ void altp2m_vcpu_initialise(struct vcpu *v)if ( v != current )vcpu_pause (v); -vcpu_altp2m (v).p2midx =0 ; +altp2m_set_vcpu_idx (v,0 );atomic_inc (&altp2m_get_altp2m (v)->active_vcpus); +#ifdef CONFIG_X86 altp2m_vcpu_update_p2m (v); +#endif if ( v != current )vcpu_unpause (v);
@@ -90,15 +92,19 @@ void altp2m_vcpu_destroy(struct vcpu *v)if ( (p2m =altp2m_get_altp2m (v)) )atomic_dec (&p2m->active_vcpus); +#ifdef CONFIG_X86 altp2m_vcpu_disable_ve (v); +#endif -vcpu_altp2m (v).p2midx =INVALID_ALTP2M ; +altp2m_set_vcpu_idx (v,INVALID_ALTP2M ); + +#ifdef CONFIG_X86 altp2m_vcpu_update_p2m (v); +#endif if ( v != current )vcpu_unpause (v); } -#endif /* * altp2m operations are envisioned as being used in several different
xen/include/xen/altp2m.h +0 -2
@@ -24,11 +24,9 @@ int altp2m_init(struct domain *d);/* Free altp2m views */ void altp2m_teardown (struct domain *d); -#ifdef CONFIG_X86 /* Alternate p2m VCPU */ void altp2m_vcpu_initialise (struct vcpu *v);void altp2m_vcpu_destroy (struct vcpu *v); -#endif #ifdef CONFIG_ALTP2M
Signature · 1 line
2.34.1