From: Feng Wu <feng.wu@intel.com>
To: xen-devel@lists.xen.org
Cc: kevin.tian@intel.com, Feng Wu <feng.wu@intel.com>,
george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
dario.faggioli@citrix.com, jbeulich@suse.com
Subject: [PATCH v6 4/7] VMX: Make sure PI is in proper state before install the hooks
Date: Fri, 28 Oct 2016 10:37:36 +0800 [thread overview]
Message-ID: <1477622259-3476-5-git-send-email-feng.wu@intel.com> (raw)
In-Reply-To: <1477622259-3476-1-git-send-email-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>
---
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 1bd875a..e8e3616 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 eb4770c..58694ce 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -206,14 +206,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.vmx.vcpu_block);
- d->arch.hvm_domain.vmx.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.vmx.pi_switch_from = vmx_pi_switch_from;
d->arch.hvm_domain.vmx.pi_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.vmx.vcpu_block = vmx_vcpu_block;
d->arch.hvm_domain.vmx.pi_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 4cdd9b1..2f0435c 100644
--- a/xen/include/asm-x86/hvm/vmx/vmx.h
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h
@@ -573,6 +573,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 */
#define _EPT_READ_VIOLATION 0
#define EPT_READ_VIOLATION (1UL<<_EPT_READ_VIOLATION)
--
2.1.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-10-28 2:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-28 2:37 [PATCH v6 0/7] VMX: Properly handle pi descriptor and per-cpu blocking list Feng Wu
2016-10-28 2:37 ` [PATCH v6 1/7] VMX: Permanently assign PI hook vmx_pi_switch_to() Feng Wu
2016-10-28 13:04 ` Jan Beulich
2016-10-28 13:18 ` Jan Beulich
2016-10-31 1:11 ` Wu, Feng
2016-10-28 2:37 ` [PATCH v6 2/7] VMX: Properly handle pi when all the assigned devices are removed Feng Wu
2016-10-28 13:19 ` Jan Beulich
2016-11-03 7:45 ` Wu, Feng
2016-11-03 9:07 ` Jan Beulich
2016-11-03 9:10 ` Wu, Feng
2016-10-28 2:37 ` [PATCH v6 3/7] VMX: Cleanup PI per-cpu blocking list when vcpu is destroyed Feng Wu
2016-10-28 13:23 ` Jan Beulich
2016-10-28 2:37 ` Feng Wu [this message]
2016-10-28 13:24 ` [PATCH v6 4/7] VMX: Make sure PI is in proper state before install the hooks Jan Beulich
2016-10-28 2:37 ` [PATCH v6 5/7] VT-d: No need to set irq affinity for posted format IRTE Feng Wu
2016-10-31 14:57 ` Jan Beulich
2016-11-03 7:46 ` Wu, Feng
2016-11-03 9:15 ` Jan Beulich
2016-10-28 2:37 ` [PATCH v6 6/7] VT-d: Some cleanups Feng Wu
2016-10-31 15:00 ` Jan Beulich
2016-10-28 2:37 ` [PATCH v6 7/7] VMX: Fixup PI descriptor when cpu is offline Feng Wu
2016-10-31 15:50 ` Jan Beulich
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=1477622259-3476-5-git-send-email-feng.wu@intel.com \
--to=feng.wu@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=dario.faggioli@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jbeulich@suse.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).