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 v9 4/8] VMX: Make sure PI is in proper state before install the hooks
Date: Mon, 27 Feb 2017 09:45:45 +0800 [thread overview]
Message-ID: <1488159949-15011-5-git-send-email-chao.gao@intel.com> (raw)
In-Reply-To: <1488159949-15011-1-git-send-email-chao.gao@intel.com>
From: Feng Wu <feng.wu@intel.com>
We may hit the last ASSERT() in vmx_vcpu_block in the current code,
since vmx_vcpu_block() may get called before vmx_pi_switch_to()
has been installed or executed. Here We use cmpxchg to update
the NDST field, this can make sure we only update the NDST when
vmx_pi_switch_to() has not been called. So the NDST is in a
proper state in vmx_vcpu_block().
Suggested-by: Jan Beulich <JBeulich@suse.com>
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>
---
v6:
- Comments changes
- Define macro 'APIC_INVALID_DEST' for '0xffffffff'
v5:
- Use 0xffffffff as the invalid value for NDST field.
v4:
- This patch is previously called "Pause/Unpause the domain before/after
assigning PI hooks"
- Remove the pause/unpause method
- Use cmpxchg to update NDST
xen/arch/x86/hvm/vmx/vmcs.c | 13 +++++--------
xen/arch/x86/hvm/vmx/vmx.c | 27 ++++++++++++++++++++++++++-
xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index 0b77dbc..7905d3e 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -956,16 +956,13 @@ void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val)
*/
static void pi_desc_init(struct vcpu *v)
{
- uint32_t dest;
-
v->arch.hvm_vmx.pi_desc.nv = posted_intr_vector;
- dest = cpu_physical_id(v->processor);
-
- if ( x2apic_enabled )
- v->arch.hvm_vmx.pi_desc.ndst = dest;
- else
- v->arch.hvm_vmx.pi_desc.ndst = MASK_INSR(dest, PI_xAPIC_NDST_MASK);
+ /*
+ * Mark NDST as invalid, then we can use this invalid value as a
+ * marker to whether update NDST or not in vmx_pi_hooks_assign().
+ */
+ v->arch.hvm_vmx.pi_desc.ndst = APIC_INVALID_DEST;
}
static int construct_vmcs(struct vcpu *v)
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index a7a70e7..e03786b 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -246,14 +246,39 @@ static void vmx_pi_do_resume(struct vcpu *v)
/* This function is called when pcidevs_lock is held */
void vmx_pi_hooks_assign(struct domain *d)
{
+ struct vcpu *v;
+
if ( !iommu_intpost || !has_hvm_container_domain(d) )
return;
ASSERT(!d->arch.hvm_domain.pi_ops.vcpu_block);
- d->arch.hvm_domain.pi_ops.vcpu_block = vmx_vcpu_block;
+ /*
+ * We carefully handle the timing here:
+ * - Install the context switch first
+ * - Then set the NDST field
+ * - Install the block and resume hooks in the end
+ *
+ * This can make sure the PI (especially the NDST feild) is
+ * in proper state when we call vmx_vcpu_block().
+ */
d->arch.hvm_domain.pi_ops.switch_from = vmx_pi_switch_from;
d->arch.hvm_domain.pi_ops.switch_to = vmx_pi_switch_to;
+
+ for_each_vcpu ( d, v )
+ {
+ unsigned int dest = cpu_physical_id(v->processor);
+ struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc;
+
+ /*
+ * We don't need to update NDST if vmx_pi_switch_to()
+ * has already got called.
+ */
+ (void)cmpxchg(&pi_desc->ndst, APIC_INVALID_DEST,
+ x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK));
+ }
+
+ d->arch.hvm_domain.pi_ops.vcpu_block = vmx_vcpu_block;
d->arch.hvm_domain.pi_ops.do_resume = vmx_pi_do_resume;
}
diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h
index f4183d9..00e6f0d 100644
--- a/xen/include/asm-x86/hvm/vmx/vmx.h
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h
@@ -601,6 +601,8 @@ void vmx_pi_per_cpu_init(unsigned int cpu);
void vmx_pi_hooks_assign(struct domain *d);
void vmx_pi_hooks_deassign(struct domain *d);
+#define APIC_INVALID_DEST 0xffffffff
+
/* EPT violation qualifications definitions */
typedef union ept_qual {
unsigned long raw;
--
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-02-27 1:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 1:45 [PATCH v9 0/8] VMX: Properly handle pi descriptor and per-cpu Chao Gao
2017-02-27 1:45 ` [PATCH v9 1/8] VMX: Permanently assign PI hook vmx_pi_switch_to() Chao Gao
2017-02-28 16:43 ` Jan Beulich
2017-03-01 0:01 ` Chao Gao
2017-03-01 7:41 ` Jan Beulich
2017-03-03 8:29 ` Tian, Kevin
2017-03-03 10:49 ` Jan Beulich
2017-03-03 11:54 ` Tian, Kevin
2017-02-27 1:45 ` [PATCH v9 2/8] xen/passthrough: Reject self-(de)assignment of devices Chao Gao
2017-02-28 16:46 ` Jan Beulich
2017-02-27 1:45 ` [PATCH v9 3/8] VMX: Properly handle pi when all the assigned devices are removed Chao Gao
2017-03-03 11:51 ` Tian, Kevin
2017-02-27 1:45 ` Chao Gao [this message]
2017-02-27 1:45 ` [PATCH v9 5/8] VT-d: Introduce a new function update_irte_for_msi_common Chao Gao
2017-03-02 8:58 ` Jan Beulich
2017-03-02 7:14 ` Chao Gao
2017-03-02 14:32 ` Jan Beulich
2017-02-27 1:45 ` [PATCH v9 6/8] VT-d: Some cleanups Chao Gao
2017-02-27 1:45 ` [PATCH v9 7/8] VMX: Fixup PI descriptor when cpu is offline Chao Gao
2017-02-27 1:45 ` [PATCH v9 8/8] VT-d: Add copy_irte_{to, from}_irt for updating irte Chao Gao
2017-03-02 9:03 ` Jan Beulich
2017-03-15 10:38 ` 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=1488159949-15011-5-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).