Clarify logic of RSEQ_ASM*_CMP* macros
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 22 Feb 2024 15:42:08 +0000 (10:42 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 22 Feb 2024 15:42:08 +0000 (10:42 -0500)
commit769ec9a57004ba64365e001d73ad015d1636b2b2
treedc0ad245849cc25c6b0174f6e1c326219f8aa809
parent470c530bcb81593ac6e62a79e67e4bd5c09c14e5
Clarify logic of RSEQ_ASM*_CMP* macros

The RSEQ_ASM*_CMP* macros come from the x86 implementation which has
"RSEQ_ASM_CMP_CPU_ID()" and static inline functions such as
"rseq_cmpeqv_storev()". The meaning of the "cmp" here is that the
critical section does _not_ abort (does not branch) if the comparison
matches.

But I understand how the ASM helpers that were contributed for other
architectures such as "RSEQ_ASM_OP_CMPEQ()", with the same semantic
of "do not branch to abort if the comparison matches" can be misleading
for someone used to reading assembler on pretty much any architecture,
where the conditional branch is expected to be taken if the condition
matches. So what I have here in librseq is backwards.

Fortunately, librseq is still just a master branch (no releases yet),
and the copy in the Linux kernel selftests is internal to that selftest,
so there are no stable API expectations at this stage.

So I don't think the semantic of e.g. "rseq_cmpeqv_storev()" is
misleading: it proceeds to do the store if the comparison matches.

However, the ASM macros would benefit from a logic flip.

Introduce this in a way that will allow users of the API to catch the
change at compile-time.

This commit applies the following remapping of the macros for added
clarity:

RSEQ_ASM_OP_CMPNE becomes RSEQ_ASM_OP_CBEQ (compare and branch if equal)
RSEQ_ASM_OP_CMPEQ becomes RSEQ_ASM_OP_CBNE (compare and branch if not equal)
RSEQ_ASM_CMP_CPU_ID becomes RSEQ_ASM_CBNE_CPU_ID (compare and branch if cpu id is not equal)

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I13bff7e22569b11565a23aca87cf571431d57106
14 files changed:
include/rseq/rseq-arm-bits.h
include/rseq/rseq-arm.h
include/rseq/rseq-arm64-bits.h
include/rseq/rseq-arm64.h
include/rseq/rseq-mips-bits.h
include/rseq/rseq-mips.h
include/rseq/rseq-ppc-bits.h
include/rseq/rseq-ppc.h
include/rseq/rseq-riscv-bits.h
include/rseq/rseq-riscv.h
include/rseq/rseq-s390-bits.h
include/rseq/rseq-s390.h
include/rseq/rseq-x86-bits.h
include/rseq/rseq-x86.h
This page took 0.024323 seconds and 4 git commands to generate.