Apply the recoverable per-CPU address handling to addition and bitwise AND/OR operations. Use the common RMW helpers through the void wrapper to make the updates atomic against interrupt handlers without masking local interrupts or disabling preemption. Link: https://lore.kernel.org/r/20260826010748.zphu3wh2hlm4t4o2@offworld Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/percpu.h | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percpu.h index cd88618889494..e39210ddd5026 100644 --- a/arch/riscv/include/asm/percpu.h +++ b/arch/riscv/include/asm/percpu.h @@ -221,6 +221,23 @@ PERCPU_RW_OPS("ld", "sd", 64) PERCPU_RW_OPS("lw", "sw", 32) #endif +__PERCPU_AMO_OP_CASE(add, 32, .w, +) +__PERCPU_AMO_OP_CASE(and, 32, .w, &) +__PERCPU_AMO_OP_CASE(or, 32, .w, |) + +#ifdef CONFIG_64BIT +__PERCPU_AMO_OP_CASE(add, 64, .d, +) +__PERCPU_AMO_OP_CASE(and, 64, .d, &) +__PERCPU_AMO_OP_CASE(or, 64, .d, |) +#endif + +__PERCPU_8_16_OP_CASE(add, 8, .b, +) +__PERCPU_8_16_OP_CASE(add, 16, .h, +) +__PERCPU_8_16_OP_CASE(and, 8, .b, &) +__PERCPU_8_16_OP_CASE(and, 16, .h, &) +__PERCPU_8_16_OP_CASE(or, 8, .b, |) +__PERCPU_8_16_OP_CASE(or, 16, .h, |) + #define this_cpu_read_1(pcp) _pcp_wrap_return(__percpu_read_8, pcp) #define this_cpu_read_2(pcp) _pcp_wrap_return(__percpu_read_16, pcp) #define this_cpu_read_4(pcp) _pcp_wrap_return(__percpu_read_32, pcp) @@ -241,6 +258,27 @@ PERCPU_RW_OPS("lw", "sw", 32) _pcp_wrap(__percpu_write_64, pcp, (unsigned long)(val)) #endif +#define this_cpu_add_1(pcp, val) _pcp_wrap(__percpu_add_amo_case_8, pcp, val) +#define this_cpu_add_2(pcp, val) _pcp_wrap(__percpu_add_amo_case_16, pcp, val) +#define this_cpu_add_4(pcp, val) _pcp_wrap(__percpu_add_amo_case_32, pcp, val) +#ifdef CONFIG_64BIT +#define this_cpu_add_8(pcp, val) _pcp_wrap(__percpu_add_amo_case_64, pcp, val) +#endif + +#define this_cpu_and_1(pcp, val) _pcp_wrap(__percpu_and_amo_case_8, pcp, val) +#define this_cpu_and_2(pcp, val) _pcp_wrap(__percpu_and_amo_case_16, pcp, val) +#define this_cpu_and_4(pcp, val) _pcp_wrap(__percpu_and_amo_case_32, pcp, val) +#ifdef CONFIG_64BIT +#define this_cpu_and_8(pcp, val) _pcp_wrap(__percpu_and_amo_case_64, pcp, val) +#endif + +#define this_cpu_or_1(pcp, val) _pcp_wrap(__percpu_or_amo_case_8, pcp, val) +#define this_cpu_or_2(pcp, val) _pcp_wrap(__percpu_or_amo_case_16, pcp, val) +#define this_cpu_or_4(pcp, val) _pcp_wrap(__percpu_or_amo_case_32, pcp, val) +#ifdef CONFIG_64BIT +#define this_cpu_or_8(pcp, val) _pcp_wrap(__percpu_or_amo_case_64, pcp, val) +#endif + #undef __PERCPU_AMO #undef PERCPU_RW_OPS #undef __PERCPU_AMO_OP_CASE