From: Chao Gao <chao.gao@intel.com>
To: xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@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 8/8] VT-d: Add copy_irte_{to, from}_irt for updating irte
Date: Mon, 27 Feb 2017 09:45:49 +0800 [thread overview]
Message-ID: <1488159949-15011-9-git-send-email-chao.gao@intel.com> (raw)
In-Reply-To: <1488159949-15011-1-git-send-email-chao.gao@intel.com>
We used structure assignment to update irte which was not safe when a
interrupt happend during update. It is better to update IRTE atomically
through cmpxchg16b(). When cmpxchg16b is not supported, two 64-bit write
operation can atomically update IRTE when only one the high dword or
low dword is intented to be changed.
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v9:
- Newly added.
xen/drivers/passthrough/vtd/intremap.c | 58 ++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrough/vtd/intremap.c
index 737b886..649bebd 100644
--- a/xen/drivers/passthrough/vtd/intremap.c
+++ b/xen/drivers/passthrough/vtd/intremap.c
@@ -169,6 +169,37 @@ bool_t __init iommu_supports_eim(void)
return 1;
}
+static inline void copy_irte_from_irt(struct iremap_entry *dst,
+ struct iremap_entry *src)
+{
+ *dst = *src;
+}
+
+static void copy_irte_to_irt(struct iremap_entry *dst, struct iremap_entry *src)
+{
+ if ( cpu_has_cx16 )
+ {
+ __uint128_t ret;
+ struct iremap_entry old_ire;
+
+ copy_irte_from_irt(&old_ire, dst);
+ ret = cmpxchg16b(dst, &old_ire, src);
+
+ /*
+ * In the above, we use cmpxchg16 to atomically update the 128-bit
+ * IRTE, and the hardware cannot update the IRTE behind us, so
+ * the return value of cmpxchg16 should be the same as old_ire.
+ * This ASSERT validate it.
+ */
+ ASSERT(ret == old_ire.val);
+ }
+ else
+ {
+ dst->lo = src->lo;
+ dst->hi = src->hi;
+ }
+}
+
/* Mark specified intr remap entry as free */
static void free_remap_entry(struct iommu *iommu, int index)
{
@@ -310,7 +341,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
iremap_entries, iremap_entry);
- new_ire = *iremap_entry;
+ copy_irte_from_irt(&new_ire, iremap_entry);
if ( rte_upper )
{
@@ -353,7 +384,7 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
remap_rte->format = 1; /* indicate remap format */
}
- *iremap_entry = new_ire;
+ copy_irte_to_irt(iremap_entry, &new_ire);
iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry));
iommu_flush_iec_index(iommu, 0, index);
@@ -617,28 +648,7 @@ static int update_irte_for_msi_common(
if ( iremap_entry->val != new_ire.val )
{
- if ( cpu_has_cx16 )
- {
- __uint128_t ret;
- struct iremap_entry old_ire;
-
- old_ire = *iremap_entry;
- ret = cmpxchg16b(iremap_entry, &old_ire, &new_ire);
-
- /*
- * In the above, we use cmpxchg16 to atomically update the 128-bit
- * IRTE, and the hardware cannot update the IRTE behind us, so
- * the return value of cmpxchg16 should be the same as old_ire.
- * This ASSERT validate it.
- */
- ASSERT(ret == old_ire.val);
- }
- else
- {
- iremap_entry->lo = new_ire.lo;
- iremap_entry->hi = new_ire.hi;
- }
-
+ copy_irte_to_irt(iremap_entry, &new_ire);
iommu_flush_cache_entry(iremap_entry, sizeof(*iremap_entry));
iommu_flush_iec_index(iommu, 0, index);
}
--
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 ` [PATCH v9 4/8] VMX: Make sure PI is in proper state before install the hooks Chao Gao
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 ` Chao Gao [this message]
2017-03-02 9:03 ` [PATCH v9 8/8] VT-d: Add copy_irte_{to, from}_irt for updating irte 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-9-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=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).