|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC PATCH 2/7] common: Track latest pCPU that ran the vCPU
Track on which pCPU each vCPU of a domain ran. This will
be used to know whether a TLB flush is required or not
when the vCPU is migrated on another pCPU.
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
I wonder if there is a way to move
curr->domain->latest_vcpu[cpu] = curr->vcpu_id
into a (at least more) common code ?
xen/arch/x86/hvm/svm/svm.c | 3 +++
xen/arch/x86/hvm/vmx/vmx.c | 3 +++
xen/common/domain.c | 8 ++++++++
xen/include/xen/sched.h | 4 ++++
4 files changed, 18 insertions(+)
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index ced6166847..58e927ae04 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -967,6 +967,7 @@ void asmlinkage svm_vmenter_helper(void)
const struct cpu_user_regs *regs = guest_cpu_user_regs();
struct vcpu *curr = current;
struct vmcb_struct *vmcb = curr->arch.hvm.svm.vmcb;
+ unsigned int cpu = smp_processor_id();
ASSERT(hvmemul_cache_disabled(curr));
@@ -977,6 +978,8 @@ void asmlinkage svm_vmenter_helper(void)
svm_sync_vmcb(curr, vmcb_needs_vmsave);
+ curr->domain->latest_vcpu[cpu] = curr->vcpu_id;
+
vmcb->rax = regs->rax;
vmcb->rip = regs->rip;
vmcb->rsp = regs->rsp;
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 269ca56433..ec0a790336 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -4934,6 +4934,7 @@ bool asmlinkage vmx_vmenter_helper(const struct
cpu_user_regs *regs)
u32 new_asid, old_asid;
struct hvm_vcpu_asid *p_asid;
bool need_flush;
+ unsigned int cpu = smp_processor_id();
ASSERT(hvmemul_cache_disabled(curr));
@@ -4977,6 +4978,8 @@ bool asmlinkage vmx_vmenter_helper(const struct
cpu_user_regs *regs)
if ( unlikely(need_flush) )
vpid_sync_all();
+ currd->latest_vcpu[cpu] = curr->vcpu_id;
+
if ( paging_mode_hap(curr->domain) )
{
struct ept_data *ept = &p2m_get_hostp2m(currd)->ept;
diff --git a/xen/common/domain.c b/xen/common/domain.c
index bb9e210c28..7867166411 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -758,6 +758,7 @@ static void _domain_destroy(struct domain *d)
rangeset_domain_destroy(d);
free_cpumask_var(d->dirty_cpumask);
+ xfree(d->latest_vcpu);
xsm_free_security_domain(d);
@@ -992,6 +993,13 @@ struct domain *domain_create(domid_t domid,
if ( !zalloc_cpumask_var(&d->dirty_cpumask) )
goto fail;
+ err = -ENOMEM;
+ d->latest_vcpu = xmalloc_array(int, nr_cpu_ids);
+ if ( !d->latest_vcpu )
+ goto fail;
+ for (unsigned int i = 0; i < nr_cpu_ids; i++)
+ d->latest_vcpu[i] = -1;
+
rangeset_domain_initialise(d);
if ( is_idle_domain(d) )
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 212c7d765c..4b8ae21b51 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -567,6 +567,10 @@ struct domain
/* Bitmask of CPUs which are holding onto this domain's state. */
cpumask_var_t dirty_cpumask;
+ /* Mapping of the latest vCPU that ran on a specific CPU
+ * (-1 if the vCPU hasn't ran yet) */
+ int *latest_vcpu;
+
struct arch_domain arch;
void *ssid; /* sHype security subject identifier */
--
2.52.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |