return rc;
fail:
+ paging_vcpu_teardown(v);
vcpu_destroy_fpu(v);
xfree(v->arch.msrs);
v->arch.msrs = NULL;
paging_unlock(d);
}
+void hap_vcpu_teardown(struct vcpu *v)
+{
+ struct domain *d = v->domain;
+ mfn_t mfn;
+
+ paging_lock(d);
+
+ if ( !paging_mode_hap(d) || !v->arch.paging.mode )
+ goto out;
+
+ mfn = pagetable_get_mfn(v->arch.hvm.monitor_table);
+ if ( mfn_x(mfn) )
+ hap_destroy_monitor_table(v, mfn);
+ v->arch.hvm.monitor_table = pagetable_null();
+
+ out:
+ paging_unlock(d);
+}
+
void hap_teardown(struct domain *d, bool *preempted)
{
struct vcpu *v;
- mfn_t mfn;
ASSERT(d->is_dying);
ASSERT(d != current->domain);
- paging_lock(d); /* Keep various asserts happy */
+ /* TODO - Remove when the teardown path is better structured. */
+ for_each_vcpu ( d, v )
+ hap_vcpu_teardown(v);
- if ( paging_mode_enabled(d) )
- {
- /* release the monitor table held by each vcpu */
- for_each_vcpu ( d, v )
- {
- if ( paging_get_hostmode(v) && paging_mode_external(d) )
- {
- mfn = pagetable_get_mfn(v->arch.hvm.monitor_table);
- if ( mfn_valid(mfn) && (mfn_x(mfn) != 0) )
- hap_destroy_monitor_table(v, mfn);
- v->arch.hvm.monitor_table = pagetable_null();
- }
- }
- }
+ paging_lock(d); /* Keep various asserts happy */
if ( d->arch.paging.hap.total_pages != 0 )
{
}
#endif /* PG_log_dirty */
+void paging_vcpu_teardown(struct vcpu *v)
+{
+ if ( hap_enabled(v->domain) )
+ hap_vcpu_teardown(v);
+ else
+ shadow_vcpu_teardown(v);
+}
+
/* Call when destroying a domain */
int paging_teardown(struct domain *d)
{
return rv;
}
+void shadow_vcpu_teardown(struct vcpu *v)
+{
+ struct domain *d = v->domain;
+
+ paging_lock(d);
+
+ if ( !paging_mode_shadow(d) || !v->arch.paging.mode )
+ goto out;
+
+ v->arch.paging.mode->shadow.detach_old_tables(v);
+#ifdef CONFIG_HVM
+ if ( shadow_mode_external(d) )
+ {
+ mfn_t mfn = pagetable_get_mfn(v->arch.hvm.monitor_table);
+
+ if ( mfn_x(mfn) )
+ sh_destroy_monitor_table(
+ v, mfn,
+ v->arch.paging.mode->shadow.shadow_levels);
+
+ v->arch.hvm.monitor_table = pagetable_null();
+ }
+#endif
+
+ out:
+ paging_unlock(d);
+}
+
void shadow_teardown(struct domain *d, bool *preempted)
/* Destroy the shadow pagetables of this domain and free its shadow memory.
* Should only be called for dying domains. */
ASSERT(d->is_dying);
ASSERT(d != current->domain);
- paging_lock(d);
-
- if ( shadow_mode_enabled(d) )
- {
- /* Release the shadow and monitor tables held by each vcpu */
- for_each_vcpu(d, v)
- {
- if ( v->arch.paging.mode )
- {
- v->arch.paging.mode->shadow.detach_old_tables(v);
-#ifdef CONFIG_HVM
- if ( shadow_mode_external(d) )
- {
- mfn_t mfn = pagetable_get_mfn(v->arch.hvm.monitor_table);
+ /* TODO - Remove when the teardown path is better structured. */
+ for_each_vcpu ( d, v )
+ shadow_vcpu_teardown(v);
- if ( mfn_valid(mfn) && (mfn_x(mfn) != 0) )
- sh_destroy_monitor_table(
- v, mfn,
- v->arch.paging.mode->shadow.shadow_levels);
- v->arch.hvm.monitor_table = pagetable_null();
- }
-#endif /* CONFIG_HVM */
- }
- }
- }
+ paging_lock(d);
#if (SHADOW_OPTIMIZATIONS & (SHOPT_VIRTUAL_TLB|SHOPT_OUT_OF_SYNC))
/* Free the virtual-TLB array attached to each vcpu */
XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
int hap_enable(struct domain *d, u32 mode);
void hap_final_teardown(struct domain *d);
+void hap_vcpu_teardown(struct vcpu *v);
void hap_teardown(struct domain *d, bool *preempted);
void hap_vcpu_init(struct vcpu *v);
int hap_track_dirty_vram(struct domain *d,
/* Helper hypercall for dealing with continuations. */
long paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
-/* Call when destroying a domain */
+/* Call when destroying a vcpu/domain */
+void paging_vcpu_teardown(struct vcpu *v);
int paging_teardown(struct domain *d);
/* Call once all of the references to the domain have gone away */
struct xen_domctl_shadow_op *sc,
XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
-/* Call when destroying a domain */
+/* Call when destroying a vcpu/domain */
+void shadow_vcpu_teardown(struct vcpu *v);
void shadow_teardown(struct domain *d, bool *preempted);
/* Call once all of the references to the domain have gone away */