Skip to content

atomics: generate atomic headers / instrument arm64

Mark Rutland linux-arm-kernel lkml 6 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 posting 3/36 patches 9 repliesIn review
  2. v4 Latest12 patches 9 repliesIn review
  3. v3 posting 2/312 patches 6 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v3 posting 1/30 of 12 patches1 replySuperseded
v211 patches23 repliesSuperseded
v17 patches23 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12atomic/tty: Fix up atomic abuse in ldsemdrivers/tty/tty_ldsem.c include/linux/tty_ldisc.h+37 -497 replies
2/12atomics/x86: reduce arch_cmpxchg64*() instrumentationarch/x86/include/asm/cmpxchg_64.h+2 -21 reply
3/12atomics: simplify cmpxchg() instrumentationinclude/asm-generic/atomic-instrumented.h+15 -850 replies
4/12atomics/treewide: instrument xchg()arch/x86/include/asm/atomic.h arch/x86/include/asm/atomic64_64.h arch/x86/include/asm/cmpxchg.h +1 more+10 -30 replies
5/12atomics: instrument cmpxchg_double*()include/asm-generic/atomic-instrumented.h+8 -130 replies
6/12atomics/treewide: rework ordering barriersarch/alpha/include/asm/atomic.h arch/powerpc/include/asm/atomic.h arch/riscv/include/asm/atomic.h +1 more+36 -440 replies
7/12atomics: add common header generation filesMAINTAINERS scripts/atomic/atomic-tbl.sh scripts/atomic/atomics.tbl +22 more+924 -00 replies
8/12atomics: switch to generated fallbacksinclude/linux/atomic-fallback.h include/linux/atomic.h+2295 -12400 replies
9/12atomics: switch to generated atomic-longinclude/asm-generic/atomic-long.h+958 -2150 replies
10/12atomics: switch to generated instrumentationinclude/asm-generic/atomic-instrumented.h+1504 -1840 replies
11/12atomics: check generated headers are up-to-dateKbuild scripts/atomic/check-atomics.sh+35 -20 replies
12/12arm64: use instrumented atomicsarch/arm64/include/asm/atomic.h arch/arm64/include/asm/atomic_ll_sc.h arch/arm64/include/asm/atomic_lse.h +2 more+193 -1860 replies

Reviews trailers per patch

11 of 12 patches have a Reviewed-by or Acked-by.

PatchWill DeaconAndy ShevchenkoPeter Zijlstra (Intel)Thomas Gleixner
1/12A-b R-b
2/12A-b A-b A-b
3/12A-b A-b
4/12A-b A-b
5/12A-b A-b
6/12A-b A-b
7/12A-b
8/12A-b A-b
9/12A-b A-b
10/12A-b A-b
11/12
12/12A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCHv4 00/12] atomics: generate atomic headers / instrument arm64

Hi Ingo,

Are you happy to pick this series? Both Will and Peter are happy with v3, and since then I've only made a minor cleanup to the commit messages for patches 8-10 (as requested by Peter), and added Will's Acked-by tags.

This series scripts the generation of the various atomic headers, to ensure that the various atomic APIs remain consistent, reducing the risk of human error, and simplifying future rework. This fleshes out the instrumented atomics such that arm64 can be migrated over to them.

Since v1 [1]:
* Use 'p' instead of 'I' for pointer to base int type
* Use Peter's patch for ldsem
* Rename atomic acquire/release barriers
* Handle xchg/cmpxchg variants
* Typo fixes
* Migrate arm64 to instrumented atomics

Since v2 [2]:
* Drop undefs for __atomic_*_fence()
* Rename __atomic_{pre,post}_fence => __atomic_{pre,post}_full_fence()
* Restore atomic_long_cond_read_relaxed()
* Add Kbuild step to verify atomic headers are up-to-date
* Rework arm64 atomic naming
* Commit message cleanups
* Accumulate acks

Since v3 [3]:
* Add Will's Acked-by tags
* Clean up rationale for patches 8-10 given we check at kbuild time

The series is based on my atomic API cleanup patches [4], which have been queued in the tip locking/core branch.

The first six patches clean up some issues with the existing atomic instrumentation, with patch six introducing the header generation infrastructure. The subsequent three patches migrate to each generated header in turn, with the final patch moving arm64 over to the instrumented atomics.

The scripts themselves are mostly POSIX sh (modulo local), without bashisms, and work in dash and bash.

Per Linus request that it is possible to use git grep to inspect the atomic headers [3], the headers are committed (and not generated by kbuild). Since we now expand the fallback definitions inline, each *should* be easier to find with grep. Each header also has a comment at the top with a path to the script used to generate it.

That scripting comes to ~900 lines, and replaces ~1700 lines of hand-written boilerplate with ~4700 lines of generated code. Some of that increase in line count is due to filling in missing portions of the API (e.g. adding all the ordering variants to the instrumented atomics), while some of that is due to expanding fallbacks in place, and consistently spreading these across multiple lines.

I've build-tested this for x86_64 and arm64 (with and without LSE), and given this some basic boot testing on an Arm Juno platform.

I've pushed the series out to my atomics/generated branch [5], based atop of tip locking/core.

Thanks,
Mark.

[1] https://lkml.kernel.org/r/20180529180746.29684-1-mark.rutland at arm.com
[2] https://lkml.kernel.org/r/20180625105952.3756-1-mark.rutland at arm.com
[3] https://lkml.kernel.org/r/20180705164053.10073-1-mark.rutland at arm.com
[4] https://lkml.kernel.org/r/20180621121321.4761-1-mark.rutland at arm.com
[5] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/generated

Mark Rutland (11):
atomics/x86: reduce arch_cmpxchg64*() instrumentation
atomics: simplify cmpxchg() instrumentation atomics/treewide: instrument xchg()
atomics: instrument cmpxchg_double*() atomics/treewide: rework ordering barriers
atomics: add common header generation files
atomics: switch to generated fallbacks
atomics: switch to generated atomic-long
atomics: switch to generated instrumentation
atomics: check generated headers are up-to-date
arm64: use instrumented atomics

Peter Zijlstra (1):
atomic/tty: Fix up atomic abuse in ldsem

 Kbuild                                       |   18 +-
 MAINTAINERS                                  |    1 +
 arch/alpha/include/asm/atomic.h              |    8 +-
 arch/arm64/include/asm/atomic.h              |  237 +--
 arch/arm64/include/asm/atomic_ll_sc.h        |   28 +-
 arch/arm64/include/asm/atomic_lse.h          |   38 +-
 arch/arm64/include/asm/cmpxchg.h             |   60 +-
 arch/arm64/include/asm/sync_bitops.h         |   16 +-
 arch/powerpc/include/asm/atomic.h            |   17 +-
 arch/riscv/include/asm/atomic.h              |   17 +-
 arch/x86/include/asm/atomic.h                |    2 +-
 arch/x86/include/asm/atomic64_64.h           |    2 +-
 arch/x86/include/asm/cmpxchg.h               |    2 +-
 arch/x86/include/asm/cmpxchg_64.h            |    4 +-
 drivers/tty/tty_ldsem.c                      |   82 +-
 include/asm-generic/atomic-instrumented.h    | 1770 +++++++++++++++++---
 include/asm-generic/atomic-long.h            | 1173 ++++++++++---
 include/linux/atomic-fallback.h              | 2294 ++++++++++++++++++++++++++
 include/linux/atomic.h                       | 1279 +-------------
 include/linux/tty_ldisc.h                    |    4 +-
 scripts/atomic/atomic-tbl.sh                 |  186 +++
 scripts/atomic/atomics.tbl                   |   41 +
 scripts/atomic/check-atomics.sh              |   19 +
 scripts/atomic/fallbacks/acquire             |    9 +
 scripts/atomic/fallbacks/add_negative        |   16 +
 scripts/atomic/fallbacks/add_unless          |   16 +
 scripts/atomic/fallbacks/andnot              |    7 +
 scripts/atomic/fallbacks/dec                 |    7 +
 scripts/atomic/fallbacks/dec_and_test        |   15 +
 scripts/atomic/fallbacks/dec_if_positive     |   15 +
 scripts/atomic/fallbacks/dec_unless_positive |   14 +
 scripts/atomic/fallbacks/fence               |   11 +
 scripts/atomic/fallbacks/fetch_add_unless    |   23 +
 scripts/atomic/fallbacks/inc                 |    7 +
 scripts/atomic/fallbacks/inc_and_test        |   15 +
 scripts/atomic/fallbacks/inc_not_zero        |   14 +
 scripts/atomic/fallbacks/inc_unless_negative |   14 +
 scripts/atomic/fallbacks/read_acquire        |    7 +
 scripts/atomic/fallbacks/release             |    8 +
 scripts/atomic/fallbacks/set_release         |    7 +
 scripts/atomic/fallbacks/sub_and_test        |   16 +
 scripts/atomic/fallbacks/try_cmpxchg         |   11 +
 scripts/atomic/gen-atomic-fallback.sh        |  181 ++
 scripts/atomic/gen-atomic-instrumented.sh    |  182 ++
 scripts/atomic/gen-atomic-long.sh            |  101 ++
 45 files changed, 5994 insertions(+), 2000 deletions(-)
 create mode 100644 include/linux/atomic-fallback.h
 create mode 100755 scripts/atomic/atomic-tbl.sh
 create mode 100644 scripts/atomic/atomics.tbl
 create mode 100755 scripts/atomic/check-atomics.sh
 create mode 100644 scripts/atomic/fallbacks/acquire
 create mode 100644 scripts/atomic/fallbacks/add_negative
 create mode 100644 scripts/atomic/fallbacks/add_unless
 create mode 100644 scripts/atomic/fallbacks/andnot
 create mode 100644 scripts/atomic/fallbacks/dec
 create mode 100644 scripts/atomic/fallbacks/dec_and_test
 create mode 100644 scripts/atomic/fallbacks/dec_if_positive
 create mode 100644 scripts/atomic/fallbacks/dec_unless_positive
 create mode 100644 scripts/atomic/fallbacks/fence
 create mode 100644 scripts/atomic/fallbacks/fetch_add_unless
 create mode 100644 scripts/atomic/fallbacks/inc
 create mode 100644 scripts/atomic/fallbacks/inc_and_test
 create mode 100644 scripts/atomic/fallbacks/inc_not_zero
 create mode 100644 scripts/atomic/fallbacks/inc_unless_negative
 create mode 100644 scripts/atomic/fallbacks/read_acquire
 create mode 100644 scripts/atomic/fallbacks/release
 create mode 100644 scripts/atomic/fallbacks/set_release
 create mode 100644 scripts/atomic/fallbacks/sub_and_test
 create mode 100644 scripts/atomic/fallbacks/try_cmpxchg
 create mode 100755 scripts/atomic/gen-atomic-fallback.sh
 create mode 100755 scripts/atomic/gen-atomic-instrumented.sh
 create mode 100755 scripts/atomic/gen-atomic-long.sh
Signature · 1 line
2.11.0