MIPS: io: add a barrier after register read in readX()
Subsystems (2)
PATCH v2 1/1 MIPS: io: add a barrier after register read in readX()
While a barrier is present in writeX() function before the register write, a similar barrier is missing in the readX() function after the register read. This could allow memory accesses following readX() to observe stale data.
--- arch/mips/include/asm/io.h | 1 + 1 file changed, 1 insertion(+)
arch/mips/include/asm/io.h +1 -0
@@ -377,6 +377,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \BUG (); \ } \ \ +war_io_reorder_wmb (); \ return pfx##ioswab##bwlq(__mem, __val); \ }
Signature · 1 line
2.7.4
Quoted 16 lines · Sinan Kaya
While a barrier is present in
writeX()function before the register write, a similar barrier is missing in thereadX()function after the register read. This could allow memory accesses followingreadX()to observe stale data.Signed-off-by Sinan Kaya <[email protected]>Reported-by Arnd Bergmann <[email protected]>--- arch/mips/include/asm/io.h | 1 + 1 file changed, 1 insertion(+)arch/mips/include/asm/io.h +0
-0
arch/mips/include/asm/io.h static inline type pfx##read##bwlq(const volatile void __iomem *mem) \ · line 382
Quoted 6 lines
arch/mips/include/asm/io.h +1
-0@@ -377,6 +377,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \BUG (); \ } \ \ +war_io_reorder_wmb (); \ return pfx##ioswab##bwlq(__mem, __val); \ }
I'm not sure if this is the right barrier: what we want here is a read barrier to
prevent any following memory access from being prefetched ahead of the readl(), so I would have expected a kind of rmb() rather than wmb().
The barrier you used here is defined as
#if defined(CONFIG_CPU_CAVIUM_OCTEON) || defined(CONFIG_LOONGSON3_ENHANCEMENT)
#define war_io_reorder_wmb() wmb()
#else
#define war_io_reorder_wmb() do { } while (0)
#endif
which appears to list the particular CPUs that have a reordering write buffer. That may not be the same set of CPUs that have the capability to do out-of-order loads.
Arnd
Quoted 12 lines · Arnd Bergmann
Quoted 11 lines · Sinan Kaya
While a barrier is present in
writeX()function before the register write, a similar barrier is missing in thereadX()function after the register read. This could allow memory accesses followingreadX()to observe stale data.Signed-off-by Sinan Kaya <[email protected]>Reported-by Arnd Bergmann <[email protected]>--- arch/mips/include/asm/io.h | 1 + 1 file changed, 1 insertion(+)
Quoted 17 lines
arch/mips/include/asm/io.h static inline type pfx##read##bwlq(const volatile void __iomem *mem) \ · line 382
Quoted 11 lines
arch/mips/include/asm/io.h +1
-0@@ -377,6 +377,7 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem) \BUG (); \ } \ \ +war_io_reorder_wmb (); \ return pfx##ioswab##bwlq(__mem, __val); \ }I'm not sure if this is the right barrier: what we want here is a read barrier to
prevent any following memory access from being prefetched ahead of thereadl(), so I would have expected a kind ofrmb()rather thanwmb().
That's true. There was too much macro-ism in the code. I was thinking war_io_reorder_wmb() to be a mb() under the hood. I'll fix and post an update.
Quoted 14 lines
The barrier you used here is defined as
#if
defined(CONFIG_CPU_CAVIUM_OCTEON)||defined(CONFIG_LOONGSON3_ENHANCEMENT)
#definewar_io_reorder_wmb()wmb()
#else
#definewar_io_reorder_wmb()do { } while (0)
#endifwhich appears to list the particular CPUs that have a reordering write buffer. That may not be the same set of CPUs that have the capability to do out-of-order loads.
Arnd
Signature · 3 lines
Sinan Kaya Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.