linux-stable/include
Geert Uytterhoeven 848149e899 iopoll: Call cpu_relax() in busy loops
[ Upstream commit b407460ee9 ]

It is considered good practice to call cpu_relax() in busy loops, see
Documentation/process/volatile-considered-harmful.rst.  This can not
only lower CPU power consumption or yield to a hyperthreaded twin
processor, but also allows an architecture to mitigate hardware issues
(e.g. ARM Erratum 754327 for Cortex-A9 prior to r2p0) in the
architecture-specific cpu_relax() implementation.

In addition, cpu_relax() is also a compiler barrier.  It is not
immediately obvious that the @op argument "function" will result in an
actual function call (e.g. in case of inlining).

Where a function call is a C sequence point, this is lost on inlining.
Therefore, with agressive enough optimization it might be possible for
the compiler to hoist the:

        (val) = op(args);

"load" out of the loop because it doesn't see the value changing. The
addition of cpu_relax() would inhibit this.

As the iopoll helpers lack calls to cpu_relax(), people are sometimes
reluctant to use them, and may fall back to open-coded polling loops
(including cpu_relax() calls) instead.

Fix this by adding calls to cpu_relax() to the iopoll helpers:
  - For the non-atomic case, it is sufficient to call cpu_relax() in
    case of a zero sleep-between-reads value, as a call to
    usleep_range() is a safe barrier otherwise.  However, it doesn't
    hurt to add the call regardless, for simplicity, and for similarity
    with the atomic case below.
  - For the atomic case, cpu_relax() must be called regardless of the
    sleep-between-reads value, as there is no guarantee all
    architecture-specific implementations of udelay() handle this.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/45c87bec3397fdd704376807f0eec5cc71be440f.1685692810.git.geert+renesas@glider.be
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-08-23 17:32:26 +02:00
..
acpi ACPI: sleep: Avoid breaking S3 wakeup due to might_sleep() 2023-06-15 18:05:19 +02:00
asm-generic word-at-a-time: use the same return type for has_zero regardless of endianness 2023-08-11 12:14:08 +02:00
clocksource
crypto This update includes the following changes: 2023-04-26 08:32:52 -07:00
drm drm/dp_mst: Clear MSG_RDY flag before sending new message 2023-07-23 13:54:02 +02:00
dt-bindings dt-bindings: power: qcom,rpmpd: Add SA8155P 2023-05-24 20:34:49 -07:00
keys
kunit
kvm KVM: arm64: vgic-v4: Make the doorbell request robust w.r.t preemption 2023-07-27 08:56:43 +02:00
linux iopoll: Call cpu_relax() in busy loops 2023-08-23 17:32:26 +02:00
math-emu
media Revert "media: dvb-core: Fix use-after-free on race condition at dvb_frontend" 2023-06-14 23:16:29 +01:00
memory
misc
net RDMA/mana_ib: Use v2 version of cfg_rx_steer_req to enable RX coalescing 2023-08-23 17:32:26 +02:00
pcmcia
ras
rdma RDMA/cma: Always set static rate to 0 for RoCE 2023-06-11 11:26:02 +03:00
rv
scsi Driver core changes for 6.4-rc1 2023-04-27 11:53:57 -07:00
soc net: dsa: felix: make vsc9959_tas_guard_bands_update() visible to ocelot->ops 2023-07-23 13:53:40 +02:00
sound ASoC: Intel: avs: Account for UID of ACPI device 2023-05-22 11:18:24 +01:00
target scsi: target: iscsi: Remove unused transport_timer 2023-05-22 16:29:39 -04:00
trace tcp: add missing family to tcp_set_ca_state() tracepoint 2023-08-16 18:32:26 +02:00
uapi block: Fix a source code comment in include/uapi/linux/blkzoned.h 2023-08-03 10:25:57 +02:00
ufs scsi: ufs: core: mcq: Fix the incorrect OCS value for the device command 2023-07-19 16:36:16 +02:00
vdso
video
xen