Skip to content

Commit 44472d1

Browse files
arndbPeter Zijlstra
authored andcommitted
atomic: Skip alignment check for try_cmpxchg() old arg
The 'old' argument in atomic_try_cmpxchg() and related functions is a pointer to a normal non-atomic integer number, which does not require to be naturally aligned, unlike the atomic_t/atomic64_t types themselves. In order to add an alignment check with CONFIG_DEBUG_ATOMIC into the normal instrument_atomic_read_write() helper, change this check to use the non-atomic instrument_read_write(), the same way that was done earlier for try_cmpxchg() in commit ec57032 ("locking/atomic: Correct (cmp)xchg() instrumentation"). This prevents warnings on m68k calling the 32-bit atomic_try_cmpxchg() with 16-bit aligned arguments as well as several more architectures including x86-32 when calling atomic64_try_cmpxchg() with 32-bit aligned u64 arguments. Reported-by: Finn Thain <fthain@linux-m68k.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/all/cover.1757810729.git.fthain@linux-m68k.org/
1 parent 66f1ea8 commit 44472d1

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

include/linux/atomic/atomic-instrumented.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ atomic_try_cmpxchg(atomic_t *v, int *old, int new)
12761276
{
12771277
kcsan_mb();
12781278
instrument_atomic_read_write(v, sizeof(*v));
1279-
instrument_atomic_read_write(old, sizeof(*old));
1279+
instrument_read_write(old, sizeof(*old));
12801280
return raw_atomic_try_cmpxchg(v, old, new);
12811281
}
12821282

@@ -1298,7 +1298,7 @@ static __always_inline bool
12981298
atomic_try_cmpxchg_acquire(atomic_t *v, int *old, int new)
12991299
{
13001300
instrument_atomic_read_write(v, sizeof(*v));
1301-
instrument_atomic_read_write(old, sizeof(*old));
1301+
instrument_read_write(old, sizeof(*old));
13021302
return raw_atomic_try_cmpxchg_acquire(v, old, new);
13031303
}
13041304

@@ -1321,7 +1321,7 @@ atomic_try_cmpxchg_release(atomic_t *v, int *old, int new)
13211321
{
13221322
kcsan_release();
13231323
instrument_atomic_read_write(v, sizeof(*v));
1324-
instrument_atomic_read_write(old, sizeof(*old));
1324+
instrument_read_write(old, sizeof(*old));
13251325
return raw_atomic_try_cmpxchg_release(v, old, new);
13261326
}
13271327

@@ -1343,7 +1343,7 @@ static __always_inline bool
13431343
atomic_try_cmpxchg_relaxed(atomic_t *v, int *old, int new)
13441344
{
13451345
instrument_atomic_read_write(v, sizeof(*v));
1346-
instrument_atomic_read_write(old, sizeof(*old));
1346+
instrument_read_write(old, sizeof(*old));
13471347
return raw_atomic_try_cmpxchg_relaxed(v, old, new);
13481348
}
13491349

@@ -2854,7 +2854,7 @@ atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new)
28542854
{
28552855
kcsan_mb();
28562856
instrument_atomic_read_write(v, sizeof(*v));
2857-
instrument_atomic_read_write(old, sizeof(*old));
2857+
instrument_read_write(old, sizeof(*old));
28582858
return raw_atomic64_try_cmpxchg(v, old, new);
28592859
}
28602860

@@ -2876,7 +2876,7 @@ static __always_inline bool
28762876
atomic64_try_cmpxchg_acquire(atomic64_t *v, s64 *old, s64 new)
28772877
{
28782878
instrument_atomic_read_write(v, sizeof(*v));
2879-
instrument_atomic_read_write(old, sizeof(*old));
2879+
instrument_read_write(old, sizeof(*old));
28802880
return raw_atomic64_try_cmpxchg_acquire(v, old, new);
28812881
}
28822882

@@ -2899,7 +2899,7 @@ atomic64_try_cmpxchg_release(atomic64_t *v, s64 *old, s64 new)
28992899
{
29002900
kcsan_release();
29012901
instrument_atomic_read_write(v, sizeof(*v));
2902-
instrument_atomic_read_write(old, sizeof(*old));
2902+
instrument_read_write(old, sizeof(*old));
29032903
return raw_atomic64_try_cmpxchg_release(v, old, new);
29042904
}
29052905

@@ -2921,7 +2921,7 @@ static __always_inline bool
29212921
atomic64_try_cmpxchg_relaxed(atomic64_t *v, s64 *old, s64 new)
29222922
{
29232923
instrument_atomic_read_write(v, sizeof(*v));
2924-
instrument_atomic_read_write(old, sizeof(*old));
2924+
instrument_read_write(old, sizeof(*old));
29252925
return raw_atomic64_try_cmpxchg_relaxed(v, old, new);
29262926
}
29272927

@@ -4432,7 +4432,7 @@ atomic_long_try_cmpxchg(atomic_long_t *v, long *old, long new)
44324432
{
44334433
kcsan_mb();
44344434
instrument_atomic_read_write(v, sizeof(*v));
4435-
instrument_atomic_read_write(old, sizeof(*old));
4435+
instrument_read_write(old, sizeof(*old));
44364436
return raw_atomic_long_try_cmpxchg(v, old, new);
44374437
}
44384438

@@ -4454,7 +4454,7 @@ static __always_inline bool
44544454
atomic_long_try_cmpxchg_acquire(atomic_long_t *v, long *old, long new)
44554455
{
44564456
instrument_atomic_read_write(v, sizeof(*v));
4457-
instrument_atomic_read_write(old, sizeof(*old));
4457+
instrument_read_write(old, sizeof(*old));
44584458
return raw_atomic_long_try_cmpxchg_acquire(v, old, new);
44594459
}
44604460

@@ -4477,7 +4477,7 @@ atomic_long_try_cmpxchg_release(atomic_long_t *v, long *old, long new)
44774477
{
44784478
kcsan_release();
44794479
instrument_atomic_read_write(v, sizeof(*v));
4480-
instrument_atomic_read_write(old, sizeof(*old));
4480+
instrument_read_write(old, sizeof(*old));
44814481
return raw_atomic_long_try_cmpxchg_release(v, old, new);
44824482
}
44834483

@@ -4499,7 +4499,7 @@ static __always_inline bool
44994499
atomic_long_try_cmpxchg_relaxed(atomic_long_t *v, long *old, long new)
45004500
{
45014501
instrument_atomic_read_write(v, sizeof(*v));
4502-
instrument_atomic_read_write(old, sizeof(*old));
4502+
instrument_read_write(old, sizeof(*old));
45034503
return raw_atomic_long_try_cmpxchg_relaxed(v, old, new);
45044504
}
45054505

@@ -5050,4 +5050,4 @@ atomic_long_dec_if_positive(atomic_long_t *v)
50505050

50515051

50525052
#endif /* _LINUX_ATOMIC_INSTRUMENTED_H */
5053-
// 8829b337928e9508259079d32581775ececd415b
5053+
// f618ac667f868941a84ce0ab2242f1786e049ed4

scripts/atomic/gen-atomic-instrumented.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@ gen_param_check()
1212
local arg="$1"; shift
1313
local type="${arg%%:*}"
1414
local name="$(gen_param_name "${arg}")"
15-
local rw="write"
15+
local rw="atomic_write"
1616

1717
case "${type#c}" in
1818
i) return;;
1919
esac
2020

2121
if [ ${type#c} != ${type} ]; then
2222
# We don't write to constant parameters.
23-
rw="read"
23+
rw="atomic_read"
24+
elif [ "${type}" = "p" ] ; then
25+
# The "old" argument in try_cmpxchg() gets accessed non-atomically
26+
rw="read_write"
2427
elif [ "${meta}" != "s" ]; then
2528
# An atomic RMW: if this parameter is not a constant, and this atomic is
2629
# not just a 's'tore, this parameter is both read from and written to.
27-
rw="read_write"
30+
rw="atomic_read_write"
2831
fi
2932

30-
printf "\tinstrument_atomic_${rw}(${name}, sizeof(*${name}));\n"
33+
printf "\tinstrument_${rw}(${name}, sizeof(*${name}));\n"
3134
}
3235

3336
#gen_params_checks(meta, arg...)

0 commit comments

Comments
 (0)