/* Prefetch the VMCB if we expect to use it later in the context switch */
if ( cpu_has_svm && is_pv_domain(nd) && !is_pv_32bit_domain(nd) &&
!is_idle_domain(nd) )
- svm_load_segs(0, 0, 0, 0, 0);
+ svm_load_segs_prefetch();
#endif
if ( need_full_gdt(nd) && !per_cpu(full_gdt_loaded, cpu) )
}
#ifdef CONFIG_PV
+void svm_load_segs_prefetch(void)
+{
+ const struct vmcb_struct *vmcb = this_cpu(host_vmcb_va);
+
+ if ( vmcb )
+ /*
+ * The main reason for this prefetch is for the TLB fill. Use the
+ * opportunity to fetch the lowest address used, to get the best
+ * behaviour out of hardware's next-line prefetcher.
+ */
+ prefetchw(&vmcb->fs);
+}
+
bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
unsigned long fs_base, unsigned long gs_base,
unsigned long gs_shadow)
if ( unlikely(!vmcb) )
return false;
- if ( !ldt_base )
- {
- /*
- * The actual structure field used here was arbitrarily chosen.
- * Empirically it doesn't seem to matter much which element is used,
- * and a clear explanation of the otherwise poor performance has not
- * been found/provided so far.
- */
- prefetchw(&vmcb->ldtr);
- return true;
- }
+ vmcb->fs.sel = 0;
+ vmcb->fs.attr = 0;
+ vmcb->fs.limit = 0;
+ vmcb->fs.base = fs_base;
+
+ vmcb->gs.sel = 0;
+ vmcb->gs.attr = 0;
+ vmcb->gs.limit = 0;
+ vmcb->gs.base = gs_base;
if ( likely(!ldt_ents) )
memset(&vmcb->ldtr, 0, sizeof(vmcb->ldtr));
vmcb->ldtr.base = ldt_base;
}
- vmcb->fs.sel = 0;
- vmcb->fs.attr = 0;
- vmcb->fs.limit = 0;
- vmcb->fs.base = fs_base;
-
- vmcb->gs.sel = 0;
- vmcb->gs.attr = 0;
- vmcb->gs.limit = 0;
- vmcb->gs.base = gs_base;
-
vmcb->kerngsbase = gs_shadow;
svm_vmload_pa(per_cpu(host_vmcb, cpu));
void svm_update_guest_cr(struct vcpu *, unsigned int cr, unsigned int flags);
/*
- * PV context switch helper. Calls with zero ldt_base request a prefetch of
- * the VMCB area to be loaded from, instead of an actual load of state.
+ * PV context switch helpers. Prefetching the VMCB area itself has been shown
+ * to be useful for performance.
*
* Must only be used for NUL FS/GS, as the segment attributes/limits are not
* read from the GDT/LDT.
*/
+void svm_load_segs_prefetch(void);
bool svm_load_segs(unsigned int ldt_ents, unsigned long ldt_base,
unsigned long fs_base, unsigned long gs_base,
unsigned long gs_shadow);