locking/percpu-rwsem: Use this_cpu_{inc,dec}() for read_count
authorHou Tao <houtao1@huawei.com>
Tue, 15 Sep 2020 14:07:50 +0000 (22:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Sep 2020 10:59:58 +0000 (12:59 +0200)
commitce2b5fe9e7c6b6417cfc5fababf2da25b58c234e
treebe4a9059f803a676c4a7289433977b83a175721f
parentabd90e56bcb30627d962469ac4fa85bef01440f5
locking/percpu-rwsem: Use this_cpu_{inc,dec}() for read_count

[ Upstream commit e6b1a44eccfcab5e5e280be376f65478c3b2c7a2 ]

The __this_cpu*() accessors are (in general) IRQ-unsafe which, given
that percpu-rwsem is a blocking primitive, should be just fine.

However, file_end_write() is used from IRQ context and will cause
load-store issues on architectures where the per-cpu accessors are not
natively irq-safe.

Fix it by using the IRQ-safe this_cpu_*() for operations on
read_count. This will generate more expensive code on a number of
platforms, which might cause a performance regression for some of the
other percpu-rwsem users.

If any such is reported, we can consider alternative solutions.

Fixes: 70fe2f48152e ("aio: fix freeze protection of aio writes")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lkml.kernel.org/r/20200915140750.137881-1-houtao1@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/percpu-rwsem.h
kernel/locking/percpu-rwsem.c