Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame^] | 1 | From 57ccbfa6a8a79c7b84394c2097efaf7935607aa5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Michael Jeanson <mjeanson@efficios.com> |
| 3 | Date: Tue, 25 Aug 2020 10:56:29 -0400 |
| 4 | Subject: [PATCH 06/10] fix: removal of [smp_]read_barrier_depends (v5.9) |
| 5 | |
| 6 | See upstream commits: |
| 7 | |
| 8 | commit 76ebbe78f7390aee075a7f3768af197ded1bdfbb |
| 9 | Author: Will Deacon <will@kernel.org> |
| 10 | Date: Tue Oct 24 11:22:47 2017 +0100 |
| 11 | |
| 12 | locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE() |
| 13 | |
| 14 | In preparation for the removal of lockless_dereference(), which is the |
| 15 | same as READ_ONCE() on all architectures other than Alpha, add an |
| 16 | implicit smp_read_barrier_depends() to READ_ONCE() so that it can be |
| 17 | used to head dependency chains on all architectures. |
| 18 | |
| 19 | commit 76ebbe78f7390aee075a7f3768af197ded1bdfbb |
| 20 | Author: Will Deacon <will.deacon@arm.com> |
| 21 | Date: Tue Oct 24 11:22:47 2017 +0100 |
| 22 | |
| 23 | locking/barriers: Add implicit smp_read_barrier_depends() to READ_ONCE() |
| 24 | |
| 25 | In preparation for the removal of lockless_dereference(), which is the |
| 26 | same as READ_ONCE() on all architectures other than Alpha, add an |
| 27 | implicit smp_read_barrier_depends() to READ_ONCE() so that it can be |
| 28 | used to head dependency chains on all architectures. |
| 29 | |
| 30 | Upstream-Status: Backport |
| 31 | |
| 32 | Change-Id: Ife8880bd9378dca2972da8838f40fc35ccdfaaac |
| 33 | Signed-off-by: Michael Jeanson <mjeanson@efficios.com> |
| 34 | Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 35 | --- |
| 36 | instrumentation/events/lttng-module/i2c.h | 4 ++-- |
| 37 | lib/ringbuffer/backend.h | 2 +- |
| 38 | lib/ringbuffer/backend_internal.h | 2 +- |
| 39 | lib/ringbuffer/frontend.h | 4 ++-- |
| 40 | lib/ringbuffer/ring_buffer_frontend.c | 4 ++-- |
| 41 | lib/ringbuffer/ring_buffer_iterator.c | 2 +- |
| 42 | lttng-events.c | 8 ++++---- |
| 43 | probes/lttng-kprobes.c | 6 +++--- |
| 44 | probes/lttng-kretprobes.c | 6 +++--- |
| 45 | probes/lttng-tracepoint-event-impl.h | 12 ++++++------ |
| 46 | probes/lttng-uprobes.c | 6 +++--- |
| 47 | wrapper/compiler.h | 18 ++++++++++++++++++ |
| 48 | wrapper/trace-clock.h | 15 +++++---------- |
| 49 | 13 files changed, 51 insertions(+), 38 deletions(-) |
| 50 | |
| 51 | diff --git a/instrumentation/events/lttng-module/i2c.h b/instrumentation/events/lttng-module/i2c.h |
| 52 | index dcbabf6..131d134 100644 |
| 53 | --- a/instrumentation/events/lttng-module/i2c.h |
| 54 | +++ b/instrumentation/events/lttng-module/i2c.h |
| 55 | @@ -23,7 +23,7 @@ LTTNG_TRACEPOINT_EVENT_CODE(i2c_write, |
| 56 | |
| 57 | TP_code_pre( |
| 58 | tp_locvar->extract_sensitive_payload = |
| 59 | - READ_ONCE(extract_sensitive_payload); |
| 60 | + LTTNG_READ_ONCE(extract_sensitive_payload); |
| 61 | ), |
| 62 | |
| 63 | TP_FIELDS( |
| 64 | @@ -78,7 +78,7 @@ LTTNG_TRACEPOINT_EVENT_CODE(i2c_reply, |
| 65 | |
| 66 | TP_code_pre( |
| 67 | tp_locvar->extract_sensitive_payload = |
| 68 | - READ_ONCE(extract_sensitive_payload); |
| 69 | + LTTNG_READ_ONCE(extract_sensitive_payload); |
| 70 | ), |
| 71 | |
| 72 | TP_FIELDS( |
| 73 | diff --git a/lib/ringbuffer/backend.h b/lib/ringbuffer/backend.h |
| 74 | index da937f2..43e1d47 100644 |
| 75 | --- a/lib/ringbuffer/backend.h |
| 76 | +++ b/lib/ringbuffer/backend.h |
| 77 | @@ -156,7 +156,7 @@ size_t lib_ring_buffer_do_strcpy(const struct lib_ring_buffer_config *config, |
| 78 | * Only read source character once, in case it is |
| 79 | * modified concurrently. |
| 80 | */ |
| 81 | - c = READ_ONCE(src[count]); |
| 82 | + c = LTTNG_READ_ONCE(src[count]); |
| 83 | if (!c) |
| 84 | break; |
| 85 | lib_ring_buffer_do_copy(config, &dest[count], &c, 1); |
| 86 | diff --git a/lib/ringbuffer/backend_internal.h b/lib/ringbuffer/backend_internal.h |
| 87 | index 2d6a345..1226fd8 100644 |
| 88 | --- a/lib/ringbuffer/backend_internal.h |
| 89 | +++ b/lib/ringbuffer/backend_internal.h |
| 90 | @@ -367,7 +367,7 @@ void lib_ring_buffer_clear_noref(const struct lib_ring_buffer_config *config, |
| 91 | * Performing a volatile access to read the sb_pages, because we want to |
| 92 | * read a coherent version of the pointer and the associated noref flag. |
| 93 | */ |
| 94 | - id = READ_ONCE(bufb->buf_wsb[idx].id); |
| 95 | + id = LTTNG_READ_ONCE(bufb->buf_wsb[idx].id); |
| 96 | for (;;) { |
| 97 | /* This check is called on the fast path for each record. */ |
| 98 | if (likely(!subbuffer_id_is_noref(config, id))) { |
| 99 | diff --git a/lib/ringbuffer/frontend.h b/lib/ringbuffer/frontend.h |
| 100 | index 6f516d9..41382fe 100644 |
| 101 | --- a/lib/ringbuffer/frontend.h |
| 102 | +++ b/lib/ringbuffer/frontend.h |
| 103 | @@ -79,7 +79,7 @@ void *channel_destroy(struct channel *chan); |
| 104 | #define for_each_channel_cpu(cpu, chan) \ |
| 105 | for ((cpu) = -1; \ |
| 106 | ({ (cpu) = cpumask_next(cpu, (chan)->backend.cpumask); \ |
| 107 | - smp_read_barrier_depends(); (cpu) < nr_cpu_ids; });) |
| 108 | + smp_rmb(); (cpu) < nr_cpu_ids; });) |
| 109 | |
| 110 | extern struct lib_ring_buffer *channel_get_ring_buffer( |
| 111 | const struct lib_ring_buffer_config *config, |
| 112 | @@ -155,7 +155,7 @@ static inline |
| 113 | int lib_ring_buffer_is_finalized(const struct lib_ring_buffer_config *config, |
| 114 | struct lib_ring_buffer *buf) |
| 115 | { |
| 116 | - int finalized = READ_ONCE(buf->finalized); |
| 117 | + int finalized = LTTNG_READ_ONCE(buf->finalized); |
| 118 | /* |
| 119 | * Read finalized before counters. |
| 120 | */ |
| 121 | diff --git a/lib/ringbuffer/ring_buffer_frontend.c b/lib/ringbuffer/ring_buffer_frontend.c |
| 122 | index 3cab365..4980d20 100644 |
| 123 | --- a/lib/ringbuffer/ring_buffer_frontend.c |
| 124 | +++ b/lib/ringbuffer/ring_buffer_frontend.c |
| 125 | @@ -1074,7 +1074,7 @@ int lib_ring_buffer_snapshot(struct lib_ring_buffer *buf, |
| 126 | int finalized; |
| 127 | |
| 128 | retry: |
| 129 | - finalized = READ_ONCE(buf->finalized); |
| 130 | + finalized = LTTNG_READ_ONCE(buf->finalized); |
| 131 | /* |
| 132 | * Read finalized before counters. |
| 133 | */ |
| 134 | @@ -1245,7 +1245,7 @@ int lib_ring_buffer_get_subbuf(struct lib_ring_buffer *buf, |
| 135 | return -EBUSY; |
| 136 | } |
| 137 | retry: |
| 138 | - finalized = READ_ONCE(buf->finalized); |
| 139 | + finalized = LTTNG_READ_ONCE(buf->finalized); |
| 140 | /* |
| 141 | * Read finalized before counters. |
| 142 | */ |
| 143 | diff --git a/lib/ringbuffer/ring_buffer_iterator.c b/lib/ringbuffer/ring_buffer_iterator.c |
| 144 | index d25db72..7b4f20a 100644 |
| 145 | --- a/lib/ringbuffer/ring_buffer_iterator.c |
| 146 | +++ b/lib/ringbuffer/ring_buffer_iterator.c |
| 147 | @@ -46,7 +46,7 @@ restart: |
| 148 | switch (iter->state) { |
| 149 | case ITER_GET_SUBBUF: |
| 150 | ret = lib_ring_buffer_get_next_subbuf(buf); |
| 151 | - if (ret && !READ_ONCE(buf->finalized) |
| 152 | + if (ret && !LTTNG_READ_ONCE(buf->finalized) |
| 153 | && config->alloc == RING_BUFFER_ALLOC_GLOBAL) { |
| 154 | /* |
| 155 | * Use "pull" scheme for global buffers. The reader |
| 156 | diff --git a/lttng-events.c b/lttng-events.c |
| 157 | index be7e389..d719294 100644 |
| 158 | --- a/lttng-events.c |
| 159 | +++ b/lttng-events.c |
| 160 | @@ -1719,7 +1719,7 @@ int lttng_metadata_printf(struct lttng_session *session, |
| 161 | size_t len; |
| 162 | va_list ap; |
| 163 | |
| 164 | - WARN_ON_ONCE(!READ_ONCE(session->active)); |
| 165 | + WARN_ON_ONCE(!LTTNG_READ_ONCE(session->active)); |
| 166 | |
| 167 | va_start(ap, fmt); |
| 168 | str = kvasprintf(GFP_KERNEL, fmt, ap); |
| 169 | @@ -2305,7 +2305,7 @@ int _lttng_event_metadata_statedump(struct lttng_session *session, |
| 170 | { |
| 171 | int ret = 0; |
| 172 | |
| 173 | - if (event->metadata_dumped || !READ_ONCE(session->active)) |
| 174 | + if (event->metadata_dumped || !LTTNG_READ_ONCE(session->active)) |
| 175 | return 0; |
| 176 | if (chan->channel_type == METADATA_CHANNEL) |
| 177 | return 0; |
| 178 | @@ -2377,7 +2377,7 @@ int _lttng_channel_metadata_statedump(struct lttng_session *session, |
| 179 | { |
| 180 | int ret = 0; |
| 181 | |
| 182 | - if (chan->metadata_dumped || !READ_ONCE(session->active)) |
| 183 | + if (chan->metadata_dumped || !LTTNG_READ_ONCE(session->active)) |
| 184 | return 0; |
| 185 | |
| 186 | if (chan->channel_type == METADATA_CHANNEL) |
| 187 | @@ -2604,7 +2604,7 @@ int _lttng_session_metadata_statedump(struct lttng_session *session) |
| 188 | struct lttng_event *event; |
| 189 | int ret = 0; |
| 190 | |
| 191 | - if (!READ_ONCE(session->active)) |
| 192 | + if (!LTTNG_READ_ONCE(session->active)) |
| 193 | return 0; |
| 194 | |
| 195 | lttng_metadata_begin(session); |
| 196 | diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c |
| 197 | index a44eaa1..38fb72e 100644 |
| 198 | --- a/probes/lttng-kprobes.c |
| 199 | +++ b/probes/lttng-kprobes.c |
| 200 | @@ -31,11 +31,11 @@ int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) |
| 201 | int ret; |
| 202 | unsigned long data = (unsigned long) p->addr; |
| 203 | |
| 204 | - if (unlikely(!READ_ONCE(chan->session->active))) |
| 205 | + if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) |
| 206 | return 0; |
| 207 | - if (unlikely(!READ_ONCE(chan->enabled))) |
| 208 | + if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) |
| 209 | return 0; |
| 210 | - if (unlikely(!READ_ONCE(event->enabled))) |
| 211 | + if (unlikely(!LTTNG_READ_ONCE(event->enabled))) |
| 212 | return 0; |
| 213 | |
| 214 | lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, sizeof(data), |
| 215 | diff --git a/probes/lttng-kretprobes.c b/probes/lttng-kretprobes.c |
| 216 | index ab98ff2..a6bcd21 100644 |
| 217 | --- a/probes/lttng-kretprobes.c |
| 218 | +++ b/probes/lttng-kretprobes.c |
| 219 | @@ -51,11 +51,11 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, |
| 220 | unsigned long parent_ip; |
| 221 | } payload; |
| 222 | |
| 223 | - if (unlikely(!READ_ONCE(chan->session->active))) |
| 224 | + if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) |
| 225 | return 0; |
| 226 | - if (unlikely(!READ_ONCE(chan->enabled))) |
| 227 | + if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) |
| 228 | return 0; |
| 229 | - if (unlikely(!READ_ONCE(event->enabled))) |
| 230 | + if (unlikely(!LTTNG_READ_ONCE(event->enabled))) |
| 231 | return 0; |
| 232 | |
| 233 | payload.ip = (unsigned long) krpi->rp->kp.addr; |
| 234 | diff --git a/probes/lttng-tracepoint-event-impl.h b/probes/lttng-tracepoint-event-impl.h |
| 235 | index 77b8638..72a669e 100644 |
| 236 | --- a/probes/lttng-tracepoint-event-impl.h |
| 237 | +++ b/probes/lttng-tracepoint-event-impl.h |
| 238 | @@ -1132,11 +1132,11 @@ static void __event_probe__##_name(void *__data, _proto) \ |
| 239 | \ |
| 240 | if (!_TP_SESSION_CHECK(session, __session)) \ |
| 241 | return; \ |
| 242 | - if (unlikely(!READ_ONCE(__session->active))) \ |
| 243 | + if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ |
| 244 | return; \ |
| 245 | - if (unlikely(!READ_ONCE(__chan->enabled))) \ |
| 246 | + if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \ |
| 247 | return; \ |
| 248 | - if (unlikely(!READ_ONCE(__event->enabled))) \ |
| 249 | + if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ |
| 250 | return; \ |
| 251 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
| 252 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ |
| 253 | @@ -1225,11 +1225,11 @@ static void __event_probe__##_name(void *__data) \ |
| 254 | \ |
| 255 | if (!_TP_SESSION_CHECK(session, __session)) \ |
| 256 | return; \ |
| 257 | - if (unlikely(!READ_ONCE(__session->active))) \ |
| 258 | + if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ |
| 259 | return; \ |
| 260 | - if (unlikely(!READ_ONCE(__chan->enabled))) \ |
| 261 | + if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \ |
| 262 | return; \ |
| 263 | - if (unlikely(!READ_ONCE(__event->enabled))) \ |
| 264 | + if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ |
| 265 | return; \ |
| 266 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
| 267 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ |
| 268 | diff --git a/probes/lttng-uprobes.c b/probes/lttng-uprobes.c |
| 269 | index bc10128..bda1d9b 100644 |
| 270 | --- a/probes/lttng-uprobes.c |
| 271 | +++ b/probes/lttng-uprobes.c |
| 272 | @@ -40,11 +40,11 @@ int lttng_uprobes_handler_pre(struct uprobe_consumer *uc, struct pt_regs *regs) |
| 273 | unsigned long ip; |
| 274 | } payload; |
| 275 | |
| 276 | - if (unlikely(!READ_ONCE(chan->session->active))) |
| 277 | + if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) |
| 278 | return 0; |
| 279 | - if (unlikely(!READ_ONCE(chan->enabled))) |
| 280 | + if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) |
| 281 | return 0; |
| 282 | - if (unlikely(!READ_ONCE(event->enabled))) |
| 283 | + if (unlikely(!LTTNG_READ_ONCE(event->enabled))) |
| 284 | return 0; |
| 285 | |
| 286 | lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, |
| 287 | diff --git a/wrapper/compiler.h b/wrapper/compiler.h |
| 288 | index 1496f33..b9f8c51 100644 |
| 289 | --- a/wrapper/compiler.h |
| 290 | +++ b/wrapper/compiler.h |
| 291 | @@ -9,6 +9,7 @@ |
| 292 | #define _LTTNG_WRAPPER_COMPILER_H |
| 293 | |
| 294 | #include <linux/compiler.h> |
| 295 | +#include <linux/version.h> |
| 296 | |
| 297 | /* |
| 298 | * Don't allow compiling with buggy compiler. |
| 299 | @@ -39,4 +40,21 @@ |
| 300 | # define WRITE_ONCE(x, val) ({ ACCESS_ONCE(x) = val; }) |
| 301 | #endif |
| 302 | |
| 303 | +/* |
| 304 | + * In v4.15 a smp read barrier was added to READ_ONCE to replace |
| 305 | + * lockless_dereference(), replicate this behavior on prior kernels |
| 306 | + * and remove calls to smp_read_barrier_depends which was dropped |
| 307 | + * in v5.9. |
| 308 | + */ |
| 309 | +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)) |
| 310 | +#define LTTNG_READ_ONCE(x) READ_ONCE(x) |
| 311 | +#else |
| 312 | +#define LTTNG_READ_ONCE(x) \ |
| 313 | +({ \ |
| 314 | + typeof(x) __val = READ_ONCE(x); \ |
| 315 | + smp_read_barrier_depends(); \ |
| 316 | + __val; \ |
| 317 | +}) |
| 318 | +#endif |
| 319 | + |
| 320 | #endif /* _LTTNG_WRAPPER_COMPILER_H */ |
| 321 | diff --git a/wrapper/trace-clock.h b/wrapper/trace-clock.h |
| 322 | index 9f4e366..187fc82 100644 |
| 323 | --- a/wrapper/trace-clock.h |
| 324 | +++ b/wrapper/trace-clock.h |
| 325 | @@ -160,33 +160,30 @@ static inline void put_trace_clock(void) |
| 326 | |
| 327 | static inline u64 trace_clock_read64(void) |
| 328 | { |
| 329 | - struct lttng_trace_clock *ltc = READ_ONCE(lttng_trace_clock); |
| 330 | + struct lttng_trace_clock *ltc = LTTNG_READ_ONCE(lttng_trace_clock); |
| 331 | |
| 332 | if (likely(!ltc)) { |
| 333 | return trace_clock_read64_monotonic(); |
| 334 | } else { |
| 335 | - read_barrier_depends(); /* load ltc before content */ |
| 336 | return ltc->read64(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static inline u64 trace_clock_freq(void) |
| 341 | { |
| 342 | - struct lttng_trace_clock *ltc = READ_ONCE(lttng_trace_clock); |
| 343 | + struct lttng_trace_clock *ltc = LTTNG_READ_ONCE(lttng_trace_clock); |
| 344 | |
| 345 | if (!ltc) { |
| 346 | return trace_clock_freq_monotonic(); |
| 347 | } else { |
| 348 | - read_barrier_depends(); /* load ltc before content */ |
| 349 | return ltc->freq(); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | static inline int trace_clock_uuid(char *uuid) |
| 354 | { |
| 355 | - struct lttng_trace_clock *ltc = READ_ONCE(lttng_trace_clock); |
| 356 | + struct lttng_trace_clock *ltc = LTTNG_READ_ONCE(lttng_trace_clock); |
| 357 | |
| 358 | - read_barrier_depends(); /* load ltc before content */ |
| 359 | /* Use default UUID cb when NULL */ |
| 360 | if (!ltc || !ltc->uuid) { |
| 361 | return trace_clock_uuid_monotonic(uuid); |
| 362 | @@ -197,24 +194,22 @@ static inline int trace_clock_uuid(char *uuid) |
| 363 | |
| 364 | static inline const char *trace_clock_name(void) |
| 365 | { |
| 366 | - struct lttng_trace_clock *ltc = READ_ONCE(lttng_trace_clock); |
| 367 | + struct lttng_trace_clock *ltc = LTTNG_READ_ONCE(lttng_trace_clock); |
| 368 | |
| 369 | if (!ltc) { |
| 370 | return trace_clock_name_monotonic(); |
| 371 | } else { |
| 372 | - read_barrier_depends(); /* load ltc before content */ |
| 373 | return ltc->name(); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static inline const char *trace_clock_description(void) |
| 378 | { |
| 379 | - struct lttng_trace_clock *ltc = READ_ONCE(lttng_trace_clock); |
| 380 | + struct lttng_trace_clock *ltc = LTTNG_READ_ONCE(lttng_trace_clock); |
| 381 | |
| 382 | if (!ltc) { |
| 383 | return trace_clock_description_monotonic(); |
| 384 | } else { |
| 385 | - read_barrier_depends(); /* load ltc before content */ |
| 386 | return ltc->description(); |
| 387 | } |
| 388 | } |
| 389 | -- |
| 390 | 2.19.1 |
| 391 | |