Skip to content

Commit 4eb2eb1

Browse files
andrea-parripalmer-dabbelt
authored andcommitted
riscv,mmio: Fix readX()-to-delay() ordering
Section 2.1 of the Platform Specification [1] states: Unless otherwise specified by a given I/O device, I/O devices are on ordering channel 0 (i.e., they are point-to-point strongly ordered). which is not sufficient to guarantee that a readX() by a hart completes before a subsequent delay() on the same hart (cf. memory-barriers.txt, "Kernel I/O barrier effects"). Set the I(nput) bit in __io_ar() to restore the ordering, align inline comments. [1] https://github.com/riscv/riscv-platform-specs Signed-off-by: Andrea Parri <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: fab957c ("RISC-V: Atomic and Locking Code") Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6514f81 commit 4eb2eb1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/riscv/include/asm/mmio.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
101101
* Relaxed I/O memory access primitives. These follow the Device memory
102102
* ordering rules but do not guarantee any ordering relative to Normal memory
103103
* accesses. These are defined to order the indicated access (either a read or
104-
* write) with all other I/O memory accesses. Since the platform specification
105-
* defines that all I/O regions are strongly ordered on channel 2, no explicit
106-
* fences are required to enforce this ordering.
104+
* write) with all other I/O memory accesses to the same peripheral. Since the
105+
* platform specification defines that all I/O regions are strongly ordered on
106+
* channel 0, no explicit fences are required to enforce this ordering.
107107
*/
108108
/* FIXME: These are now the same as asm-generic */
109109
#define __io_rbr() do {} while (0)
@@ -125,14 +125,14 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
125125
#endif
126126

127127
/*
128-
* I/O memory access primitives. Reads are ordered relative to any
129-
* following Normal memory access. Writes are ordered relative to any prior
130-
* Normal memory access. The memory barriers here are necessary as RISC-V
128+
* I/O memory access primitives. Reads are ordered relative to any following
129+
* Normal memory read and delay() loop. Writes are ordered relative to any
130+
* prior Normal memory write. The memory barriers here are necessary as RISC-V
131131
* doesn't define any ordering between the memory space and the I/O space.
132132
*/
133133
#define __io_br() do {} while (0)
134-
#define __io_ar(v) __asm__ __volatile__ ("fence i,r" : : : "memory")
135-
#define __io_bw() __asm__ __volatile__ ("fence w,o" : : : "memory")
134+
#define __io_ar(v) ({ __asm__ __volatile__ ("fence i,ir" : : : "memory"); })
135+
#define __io_bw() ({ __asm__ __volatile__ ("fence w,o" : : : "memory"); })
136136
#define __io_aw() mmiowb_set_pending()
137137

138138
#define readb(c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; })

0 commit comments

Comments
 (0)