From: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
To: mpe@ellerman.id.au, aneesh.kumar@linux.vnet.ibm.com,
bsingharora@gmail.com, linuxppc-dev@lists.ozlabs.org
Cc: clombard@linux.vnet.ibm.com, alistair@popple.id.au,
vaibhav@linux.vnet.ibm.com
Subject: [PATCH v3 3/3] cxl: Add memory barrier to guarantee TLBI scope
Date: Wed, 2 Aug 2017 22:29:30 +0200 [thread overview]
Message-ID: <20170802202930.5616-4-fbarrat@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170802202930.5616-1-fbarrat@linux.vnet.ibm.com>
With the hash memory model, all TLBIs become global when the cxl
driver is active, i.e. as soon as one context is open.
It is theoretically possible to send a TLBI with the wrong scope as
there's currently no memory barrier between when the driver is marked
as in use, and attaching a context to the device, therefore we are
exposed to re-ordering. It is highly unlikely as the use count for the
driver is incremented on open() and the attachment to the device
happens on a different system call (ioctl)
Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
---
include/misc/cxl-base.h | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/include/misc/cxl-base.h b/include/misc/cxl-base.h
index b2ebc91fe09a..25afe6bbe0a9 100644
--- a/include/misc/cxl-base.h
+++ b/include/misc/cxl-base.h
@@ -25,17 +25,33 @@ extern atomic_t cxl_use_count;
static inline bool cxl_ctx_in_use(void)
{
- return (atomic_read(&cxl_use_count) != 0);
+ /*
+ * This is called when sending an TLBI, to know whether it
+ * should be global or local.
+ *
+ * We need to make sure the PTE update is happening before
+ * reading the context global flag. Otherwise, reading the
+ * flag may be re-ordered and happen first, and we could end
+ * up in a situation where the old PTE is seen by the device,
+ * but the TLBI is not global.
+ */
+ mb();
+ return (atomic_read(&cxl_use_count) != 0);
}
static inline void cxl_ctx_get(void)
{
- atomic_inc(&cxl_use_count);
+ atomic_inc(&cxl_use_count);
+ /*
+ * Barrier guarantees that the device will receive all TLBIs
+ * from that point on
+ */
+ wmb();
}
static inline void cxl_ctx_put(void)
{
- atomic_dec(&cxl_use_count);
+ atomic_dec(&cxl_use_count);
}
struct cxl_afu *cxl_afu_get(struct cxl_afu *afu);
--
2.11.0
next prev parent reply other threads:[~2017-08-02 20:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-02 20:29 [PATCH v3 0/3] powerpc/mm: Mark memory contexts requiring global TLBIs Frederic Barrat
2017-08-02 20:29 ` [PATCH v3 1/3] powerpc/mm: Add marker for contexts requiring global TLB invalidations Frederic Barrat
2017-08-03 7:16 ` Balbir Singh
2017-08-22 3:11 ` Alistair Popple
2017-08-02 20:29 ` [PATCH v3 2/3] cxl: Mark context requiring global TLBIs Frederic Barrat
2017-08-03 7:22 ` Balbir Singh
2017-08-22 3:09 ` Alistair Popple
2017-08-02 20:29 ` Frederic Barrat [this message]
2017-08-30 13:29 ` [PATCH v3 0/3] powerpc/mm: Mark memory contexts " Frederic Barrat
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=20170802202930.5616-4-fbarrat@linux.vnet.ibm.com \
--to=fbarrat@linux.vnet.ibm.com \
--cc=alistair@popple.id.au \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=bsingharora@gmail.com \
--cc=clombard@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=vaibhav@linux.vnet.ibm.com \
/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).