• Will Deacon's avatar
    arm64: cmpxchg: truncate sub-word signed types before comparison · a14949e0
    Will Deacon authored
    When performing a cmpxchg operation on a signed sub-word type (e.g. s8),
    we need to ensure that the upper register bits of the "old" value used
    for comparison are zeroed, otherwise we may erroneously fail the cmpxchg
    which may even be interpreted as success by the caller (if the compiler
    performs the truncation as part of its check). This has been observed
    in mod_state, where negative values where causing problems with
    this_cpu_cmpxchg.
    
    This patch fixes the issue by explicitly casting 8-bit and 16-bit "old"
    values using unsigned types in our cmpxchg wrappers. 32-bit types can be
    left alone, since the underlying asm makes use of W registers in this
    case.
    Reported-by: default avatarMark Rutland <mark.rutland@arm.com>
    Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
    a14949e0
cmpxchg.h 5.4 KB