From: Nadav Amit <namit-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org>
To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org
Cc: Nadav Amit <namit-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org>,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [PATCH] iommu/vt-d: Avoid write-tearing on PTE clear
Date: Sat, 21 May 2016 02:51:23 -0700 [thread overview]
Message-ID: <1463824283-1683-1-git-send-email-namit@vmware.com> (raw)
When a PTE is cleared, the write may be teared or perform by multiple
writes. In addition, in 32-bit kernel, writes are currently performed
using a single 64-bit write, which does not guarantee order.
The byte-code right now does not seem to cause a problem, but it may
still occur in theory.
Avoid this scenario by using WRITE_ONCE, and order the writes on
32-bit kernels.
Signed-off-by: Nadav Amit <namit-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org>
---
drivers/iommu/intel-iommu.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index e1852e8..4f488a5 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -326,9 +326,26 @@ struct dma_pte {
u64 val;
};
+#ifndef CONFIG_64BIT
+union split_dma_pte {
+ struct {
+ u32 val_low;
+ u32 val_high;
+ };
+ u64 val;
+};
+#endif
+
static inline void dma_clear_pte(struct dma_pte *pte)
{
- pte->val = 0;
+#ifdef CONFIG_64BIT
+ WRITE_ONCE(pte->val, 0);
+#else
+ union split_dma_pte *sdma_pte = (union split_dma_pte *)pte;
+
+ WRITE_ONCE(sdma_pte->val_low, 0);
+ sdma_pte->val_high = 0;
+#endif
}
static inline u64 dma_pte_addr(struct dma_pte *pte)
--
2.7.4
next reply other threads:[~2016-05-21 9:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-21 9:51 Nadav Amit [this message]
[not found] ` <1463824283-1683-1-git-send-email-namit-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org>
2016-06-03 17:55 ` [PATCH] iommu/vt-d: Avoid write-tearing on PTE clear Nadav Amit
2016-06-15 11:48 ` Joerg Roedel
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=1463824283-1683-1-git-send-email-namit@vmware.com \
--to=namit-pghwnbhtmq7qt0dzr+alfa@public.gmane.org \
--cc=dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.