From: Chao Gao <chao.gao@intel.com>
To: xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@intel.com>, Feng Wu <feng.wu@intel.com>,
Jun Nakajima <jun.nakajima@intel.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Dario Faggioli <dario.faggioli@citrix.com>,
Jan Beulich <jbeulich@suse.com>, Chao Gao <chao.gao@intel.com>
Subject: [PATCH v10 3/6] VMX: Fixup PI descriptor when cpu is offline
Date: Wed, 15 Mar 2017 13:11:19 +0800 [thread overview]
Message-ID: <1489554682-6126-4-git-send-email-chao.gao@intel.com> (raw)
In-Reply-To: <1489554682-6126-1-git-send-email-chao.gao@intel.com>
From: Feng Wu <feng.wu@intel.com>
When cpu is offline, we need to move all the vcpus in its blocking
list to another online cpu, this patch handles it.
Signed-off-by: Feng Wu <feng.wu@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
---
v7:
- Pass unsigned int to vmx_pi_desc_fixup()
v6:
- Carefully suppress 'SN' to avoid missing notification event
during moving the vcpu to the new list
v5:
- Add some comments to explain why it doesn't cause deadlock
for the ABBA deadlock scenario.
v4:
- Remove the pointless check since we are in machine stop
context and no other cpus go down in parallel.
xen/arch/x86/hvm/vmx/vmcs.c | 1 +
xen/arch/x86/hvm/vmx/vmx.c | 70 +++++++++++++++++++++++++++++++++++++++
xen/include/asm-x86/hvm/vmx/vmx.h | 1 +
3 files changed, 72 insertions(+)
diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index 0c1b711..b7f6a5e 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -591,6 +591,7 @@ void vmx_cpu_dead(unsigned int cpu)
vmx_free_vmcs(per_cpu(vmxon_region, cpu));
per_cpu(vmxon_region, cpu) = 0;
nvmx_cpu_dead(cpu);
+ vmx_pi_desc_fixup(cpu);
}
int vmx_cpu_up(void)
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 894d7d4..dee0463 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -199,6 +199,76 @@ static void vmx_pi_do_resume(struct vcpu *v)
vmx_pi_unblock_vcpu(v);
}
+void vmx_pi_desc_fixup(unsigned int cpu)
+{
+ unsigned int new_cpu, dest;
+ unsigned long flags;
+ struct arch_vmx_struct *vmx, *tmp;
+ spinlock_t *new_lock, *old_lock = &per_cpu(vmx_pi_blocking, cpu).lock;
+ struct list_head *blocked_vcpus = &per_cpu(vmx_pi_blocking, cpu).list;
+
+ if ( !iommu_intpost )
+ return;
+
+ /*
+ * We are in the context of CPU_DEAD or CPU_UP_CANCELED notification,
+ * and it is impossible for a second CPU go down in parallel. So we
+ * can safely acquire the old cpu's lock and then acquire the new_cpu's
+ * lock after that.
+ */
+ spin_lock_irqsave(old_lock, flags);
+
+ list_for_each_entry_safe(vmx, tmp, blocked_vcpus, pi_blocking.list)
+ {
+ /*
+ * Suppress notification or we may miss an interrupt when the
+ * target cpu is dying.
+ */
+ pi_set_sn(&vmx->pi_desc);
+
+ /*
+ * Check whether a notification is pending before doing the
+ * movement, if that is the case we need to wake up it directly
+ * other than moving it to the new cpu's list.
+ */
+ if ( pi_test_on(&vmx->pi_desc) )
+ {
+ list_del(&vmx->pi_blocking.list);
+ vmx->pi_blocking.lock = NULL;
+ vcpu_unblock(container_of(vmx, struct vcpu, arch.hvm_vmx));
+ }
+ else
+ {
+ /*
+ * We need to find an online cpu as the NDST of the PI descriptor, it
+ * doesn't matter whether it is within the cpupool of the domain or
+ * not. As long as it is online, the vCPU will be woken up once the
+ * notification event arrives.
+ */
+ new_cpu = cpumask_any(&cpu_online_map);
+ new_lock = &per_cpu(vmx_pi_blocking, new_cpu).lock;
+
+ spin_lock(new_lock);
+
+ ASSERT(vmx->pi_blocking.lock == old_lock);
+
+ dest = cpu_physical_id(new_cpu);
+ write_atomic(&vmx->pi_desc.ndst,
+ x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK));
+
+ list_move(&vmx->pi_blocking.list,
+ &per_cpu(vmx_pi_blocking, new_cpu).list);
+ vmx->pi_blocking.lock = new_lock;
+
+ spin_unlock(new_lock);
+ }
+
+ pi_clear_sn(&vmx->pi_desc);
+ }
+
+ spin_unlock_irqrestore(old_lock, flags);
+}
+
/*
* To handle posted interrupts correctly, we need to set the following
* state:
diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h
index 2b781ab..5ead57c 100644
--- a/xen/include/asm-x86/hvm/vmx/vmx.h
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h
@@ -597,6 +597,7 @@ void free_p2m_hap_data(struct p2m_domain *p2m);
void p2m_init_hap_data(struct p2m_domain *p2m);
void vmx_pi_per_cpu_init(unsigned int cpu);
+void vmx_pi_desc_fixup(unsigned int cpu);
void vmx_pi_hooks_assign(struct domain *d);
void vmx_pi_hooks_deassign(struct domain *d);
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-15 5:11 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-15 5:11 [PATCH v10 0/6] VMX: Properly handle pi descriptor and per-cpu blocking list Chao Gao
2017-03-15 5:11 ` [PATCH v10 1/6] VT-d: Introduce new fields in msi_desc to track binding with guest interrupt Chao Gao
2017-03-15 16:41 ` Jan Beulich
2017-03-15 21:21 ` Chao Gao
2017-03-16 10:24 ` Jan Beulich
2017-03-22 5:59 ` Tian, Kevin
2017-03-22 0:18 ` Chao Gao
2017-03-22 8:32 ` Tian, Kevin
2017-03-15 5:11 ` [PATCH v10 2/6] VT-d: Some cleanups Chao Gao
2017-03-15 5:11 ` Chao Gao [this message]
2017-03-15 5:11 ` [PATCH v10 4/6] VT-d: introduce update_irte to update irte safely Chao Gao
2017-03-15 16:48 ` Jan Beulich
2017-03-15 22:39 ` Chao Gao
2017-03-16 10:29 ` Jan Beulich
2017-03-17 1:52 ` Chao Gao
2017-03-17 9:08 ` Jan Beulich
2017-03-22 6:26 ` Tian, Kevin
2017-03-24 8:44 ` Tian, Kevin
2017-03-15 5:11 ` [PATCH v10 5/6] passthrough/io: don't migrate pirq when it is delivered through VT-d PI Chao Gao
2017-03-17 10:43 ` Jan Beulich
2017-03-20 1:59 ` Chao Gao
2017-03-20 9:18 ` Jan Beulich
2017-03-20 2:38 ` Chao Gao
2017-03-20 10:26 ` Jan Beulich
2017-03-20 5:22 ` Chao Gao
2017-03-20 12:50 ` Jan Beulich
2017-03-20 6:11 ` Chao Gao
2017-03-15 5:11 ` [PATCH v10 6/6] passthrough/io: Fall back to remapping interrupt when we can't use " Chao Gao
2017-03-17 10:48 ` Jan Beulich
2017-03-22 6:34 ` Tian, Kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1489554682-6126-4-git-send-email-chao.gao@intel.com \
--to=chao.gao@intel.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=dario.faggioli@citrix.com \
--cc=feng.wu@intel.com \
--cc=jbeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).