linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] oslat: Avoid out-of-order memory accesses to precede counter read
@ 2021-09-14 17:55 Nicolas Saenz Julienne
  2021-09-14 18:01 ` Peter Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Saenz Julienne @ 2021-09-14 17:55 UTC (permalink / raw)
  To: linux-rt-users, peterx; +Cc: williams, jkacur, nsaenzju, Punit Agrawal

In arm64 it's possible for the processor to access memory appearing in
program order after the read of the counter before the counter has been
read. This would skew the counter value to a later point than intended.

Fix this my adding an isb() following the counter read instruction.

Suggested-by: Punit Agrawal <punitagrawal@gmail.com>
Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
---
 src/oslat/oslat.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index 5fce223..50ddc81 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -92,6 +92,13 @@ static inline void frc(uint64_t *pval)
 	 */
 	__asm__ __volatile__("isb" : : : "memory");
 	__asm__ __volatile__("mrs %0, cntvct_el0" : "=r" (*pval) :: "memory");
+	/*
+	 * This isb() is required to prevent the processor from accessing
+	 * memory appearing in program order after the read of the counter
+	 * before the counter has been read. Which would skew the counter value
+	 * to a later point than intended.
+	 */
+	__asm__ __volatile__("isb" : : : "memory");
 
 }
 # else
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] oslat: Avoid out-of-order memory accesses to precede counter read
  2021-09-14 17:55 [PATCH] oslat: Avoid out-of-order memory accesses to precede counter read Nicolas Saenz Julienne
@ 2021-09-14 18:01 ` Peter Xu
  2021-09-14 18:35   ` John Kacur
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2021-09-14 18:01 UTC (permalink / raw)
  To: Nicolas Saenz Julienne; +Cc: linux-rt-users, williams, jkacur, Punit Agrawal

On Tue, Sep 14, 2021 at 07:55:42PM +0200, Nicolas Saenz Julienne wrote:
> In arm64 it's possible for the processor to access memory appearing in
> program order after the read of the counter before the counter has been
> read. This would skew the counter value to a later point than intended.
> 
> Fix this my adding an isb() following the counter read instruction.
> 
> Suggested-by: Punit Agrawal <punitagrawal@gmail.com>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>

Acked-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] oslat: Avoid out-of-order memory accesses to precede counter read
  2021-09-14 18:01 ` Peter Xu
@ 2021-09-14 18:35   ` John Kacur
  0 siblings, 0 replies; 3+ messages in thread
From: John Kacur @ 2021-09-14 18:35 UTC (permalink / raw)
  To: Peter Xu; +Cc: Nicolas Saenz Julienne, linux-rt-users, williams, Punit Agrawal



On Tue, 14 Sep 2021, Peter Xu wrote:

> On Tue, Sep 14, 2021 at 07:55:42PM +0200, Nicolas Saenz Julienne wrote:
> > In arm64 it's possible for the processor to access memory appearing in
> > program order after the read of the counter before the counter has been
> > read. This would skew the counter value to a later point than intended.
> > 
> > Fix this my adding an isb() following the counter read instruction.
> > 
> > Suggested-by: Punit Agrawal <punitagrawal@gmail.com>
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
> 
> Acked-by: Peter Xu <peterx@redhat.com>
> 
> -- 
> Peter Xu
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-14 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 17:55 [PATCH] oslat: Avoid out-of-order memory accesses to precede counter read Nicolas Saenz Julienne
2021-09-14 18:01 ` Peter Xu
2021-09-14 18:35   ` John Kacur

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).