Compare

cf73c3fc03c43a8a86fd487c62390b4744eff9ec..c9fc60c18b6d42efdea0cd88ca132b2f452157c3

ring-buffer: Skip si_mem_available() for persistent and remote buffers

Persistent and remote buffer memory is pre-allocated by the time
__rb_allocate_pages() is called. Skip si_mem_available() to avoid
wrongly failing the allocation under memory pressure.

For the same reason, unset user_thread.

Link: https://patch.msgid.link/20261013102047.1488347-2-vdonnefort@google.com
Fixes: be68d63a139b ("ring-buffer: Add ring_buffer_alloc_range()")
Fixes: 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Vincent Donnefort <vdonnefort@google.com> · 2026-10-13 10:20 UTC · committed by Steven Rostedt

Browse files
10 files changed, +62 −58
modified drivers/gpio/gpio-nct6694.c
@@ -444,7 +444,7 @@ static int nct6694_gpio_probe(struct platform_device *pdev)
444 444 data->gpio.set_config = nct6694_set_config;
445 445 data->gpio.init_valid_mask = nct6694_init_valid_mask;
446 446 data->gpio.base = -1;
447 - data->gpio.can_sleep = true;
447 + data->gpio.can_sleep = false;
448 448 data->gpio.owner = THIS_MODULE;
449 449 data->gpio.ngpio = NCT6694_NR_GPIO;
450 450
modified drivers/gpio/gpiolib-shared.c
@@ -449,14 +449,10 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
449 449 int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *fwnode,
450 450 const char *con_id, unsigned long lflags)
451 451 {
452 + const char *dev_id = dev_name(consumer);
453 + struct gpiod_lookup_table *lookup;
452 454 struct gpio_shared_entry *entry;
453 455 struct gpio_shared_ref *ref;
454 - const char *dev_id;
455 -
456 - if (!consumer)
457 - return -EOPNOTSUPP;
458 -
459 - dev_id = dev_name(consumer);
460 456
461 457 list_for_each_entry(entry, &gpio_shared_list, list) {
462 458 list_for_each_entry(ref, &entry->refs, list) {
@@ -484,22 +480,18 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
484 480 if (!key)
485 481 return -ENOMEM;
486 482
487 - struct gpiod_lookup_table *lookup __free(kfree) =
488 - kzalloc_flex(*lookup, table, 2);
483 + lookup = kzalloc_flex(*lookup, table, 2);
489 484 if (!lookup)
490 485 return -ENOMEM;
491 486
492 487 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
493 488 dev_id, key, ref->con_id ?: "none");
494 489
495 - lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
496 - if (!lookup->dev_id)
497 - return -ENOMEM;
498 -
490 + lookup->dev_id = dev_id;
499 491 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
500 492 ref->con_id, lflags);
501 493
502 - ref->lookup = no_free_ptr(lookup);
494 + ref->lookup = lookup;
503 495 gpiod_add_lookup_table(ref->lookup);
504 496
505 497 return 0;
@@ -619,7 +611,6 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
619 611 if (ref->lookup) {
620 612 gpiod_remove_lookup_table(ref->lookup);
621 613 kfree(ref->lookup->table[0].key);
622 - kfree(ref->lookup->dev_id);
623 614 kfree(ref->lookup);
624 615 ref->lookup = NULL;
625 616 }
modified fs/tracefs/event_inode.c
@@ -91,6 +91,14 @@ static void free_ei_rcu(struct rcu_head *rcu)
91 91 }
92 92 }
93 93
94 + /* read under eventfs_srcu and, by tracefs_d_revalidate(), in rcu pathwalk */
95 + static void free_ei_srcu(struct rcu_head *rcu)
96 + {
97 + struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu);
98 +
99 + call_rcu(&ei->rcu, free_ei_rcu);
100 + }
101 +
94 102 /*
95 103 * eventfs_inode reference count management.
96 104 *
@@ -112,7 +120,7 @@ static void release_ei(struct kref *ref)
112 120 entry->release(entry->name, ei->data);
113 121 }
114 122
115 - call_srcu(&eventfs_srcu, &ei->rcu, free_ei_rcu);
123 + call_srcu(&eventfs_srcu, &ei->rcu, free_ei_srcu);
116 124 }
117 125
118 126 static inline void put_ei(struct eventfs_inode *ei)
modified kernel/trace/Makefile
@@ -146,11 +146,12 @@ KASAN_SANITIZE_undefsyms_base.o := y
146 146
147 147 UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __msan \
148 148 __aeabi_unwind_cpp __s390_indirect_jump __x86_indirect_thunk simple_ring_buffer \
149 - $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}')
149 + current_thread_info_reg \
150 + $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}')
150 151
151 152 quiet_cmd_check_undefined = NM $<
152 153 cmd_check_undefined = \
153 - undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
154 + undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
154 155 if [ -n "$$undefsyms" ]; then \
155 156 echo "Unexpected symbols in $<:" >&2; \
156 157 echo "$$undefsyms" >&2; \
modified kernel/trace/ring_buffer.c
@@ -2380,6 +2380,9 @@ int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, in
2380 2380 struct seq_file *m;
2381 2381 int ret;
2382 2382
2383 + if (!cpumask_test_cpu(cpu, buffer->cpumask))
2384 + return -ENODEV;
2385 +
2383 2386 ret = seq_open(file, &rb_meta_seq_ops);
2384 2387 if (ret)
2385 2388 return ret;
@@ -2442,20 +2445,30 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2442 2445 struct trace_buffer *buffer = cpu_buffer->buffer;
2443 2446 struct ring_buffer_cpu_meta *meta = NULL;
2444 2447 struct buffer_page *bpage, *tmp;
2445 - bool user_thread = current->mm != NULL;
2446 2448 struct ring_buffer_desc *desc = NULL;
2449 + bool user_thread = false;
2447 2450 long i;
2448 2451
2449 - /*
2450 - * Check if the available memory is there first.
2451 - * Note, si_mem_available() only gives us a rough estimate of available
2452 - * memory. It may not be accurate. But we don't care, we just want
2453 - * to prevent doing any allocation when it is obvious that it is
2454 - * not going to succeed.
2455 - */
2456 - i = si_mem_available();
2457 - if (i < nr_pages)
2458 - return -ENOMEM;
2452 + if (buffer->range_addr_start) {
2453 + meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2454 + } else if (buffer->remote) {
2455 + desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2456 + if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2457 + return -EINVAL;
2458 + } else {
2459 + /*
2460 + * Check if the available memory is there first.
2461 + * Note, si_mem_available() only gives us a rough estimate of available
2462 + * memory. It may not be accurate. But we don't care, we just want
2463 + * to prevent doing any allocation when it is obvious that it is
2464 + * not going to succeed.
2465 + */
2466 + i = si_mem_available();
2467 + if (i < nr_pages)
2468 + return -ENOMEM;
2469 +
2470 + user_thread = current->mm != NULL;
2471 + }
2459 2472
2460 2473 /*
2461 2474 * If a user thread allocates too much, and si_mem_available()
@@ -2469,15 +2482,6 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2469 2482 if (user_thread)
2470 2483 set_current_oom_origin();
2471 2484
2472 - if (buffer->range_addr_start)
2473 - meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2474 -
2475 - if (buffer->remote) {
2476 - desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2477 - if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2478 - return -EINVAL;
2479 - }
2480 -
2481 2485 for (i = 0; i < nr_pages; i++) {
2482 2486
2483 2487 bpage = alloc_cpu_page(cpu_buffer->cpu);
@@ -3627,10 +3631,8 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
3627 3631 /* Return the index into the sub-buffers for a given sub-buffer */
3628 3632 static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf)
3629 3633 {
3630 - void *subbuf_array;
3634 + void *subbuf_array = rb_subbufs_from_meta(meta);
3631 3635
3632 - subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs;
3633 - subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size);
3634 3636 return (subbuf - subbuf_array) / meta->subbuf_size;
3635 3637 }
3636 3638
@@ -7997,12 +7999,8 @@ consume:
7997 7999 goto out;
7998 8000 }
7999 8001
8000 - /* Did the reader catch up with the writer? */
8001 - if (cpu_buffer->reader_page == cpu_buffer->commit_page)
8002 - goto out;
8003 -
8004 8002 reader = rb_get_reader_page(cpu_buffer);
8005 - if (WARN_ON(!reader))
8003 + if (!reader)
8006 8004 goto out;
8007 8005
8008 8006 /* Check if any events were dropped */
modified kernel/trace/trace.c
@@ -5881,7 +5881,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
5881 5881
5882 5882 ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu);
5883 5883 if (ret < 0)
5884 - __trace_array_put(tr);
5884 + trace_array_put(tr);
5885 5885 return ret;
5886 5886 }
5887 5887
@@ -9287,6 +9287,12 @@ static struct notifier_block trace_module_nb = {
9287 9287
9288 9288 static __init void tracer_init_tracefs_work_func(struct work_struct *work)
9289 9289 {
9290 + /*
9291 + * Do not attempt to initialize tracefs if tracing was disabled or
9292 + * failed to allocate
9293 + */
9294 + if (tracing_disabled)
9295 + return;
9290 9296
9291 9297 event_trace_init();
9292 9298
modified kernel/trace/trace_events_hist.c
@@ -289,7 +289,7 @@ static u64 hist_field_log2(struct hist_field *hist_field,
289 289
290 290 u64 val = hist_fn_call(operand, elt, buffer, rbe, event);
291 291
292 - return (u64) ilog2(roundup_pow_of_two(val));
292 + return order_base_2(val);
293 293 }
294 294
295 295 static u64 hist_field_bucket(struct hist_field *hist_field,
@@ -873,7 +873,7 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
873 873 struct hist_trigger_data *hist_data = hist_field->hist_data;
874 874 struct trace_array *tr = hist_data->event_file->tr;
875 875
876 - u64 ts = ring_buffer_event_time_stamp(buffer, rbe);
876 + u64 ts = tracing_event_time_stamp(buffer, rbe);
877 877
878 878 if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr))
879 879 ts = ns2usecs(ts);
@@ -3090,7 +3090,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
3090 3090 key_field = hist_data->fields[i];
3091 3091 if (!first)
3092 3092 seq_buf_putc(&s, ',');
3093 - seq_buf_puts(&s, key_field->field->name);
3093 + expr_field_str(key_field, &s);
3094 3094 first = false;
3095 3095 }
3096 3096
modified kernel/trace/trace_snapshot.c
@@ -675,9 +675,12 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
675 675 if (iter->cpu_file != RING_BUFFER_ALL_CPUS)
676 676 return -EINVAL;
677 677 #endif
678 - if (tr->allocated_snapshot)
678 + if (tr->allocated_snapshot) {
679 679 ret = resize_buffer_duplicate_size(&tr->snapshot_buffer,
680 680 &tr->array_buffer, iter->cpu_file);
681 + if (ret < 0)
682 + return ret;
683 + }
681 684
682 685 ret = tracing_arm_snapshot_locked(tr);
683 686 if (ret)
modified kernel/trace/undefsyms_base.c
@@ -9,6 +9,7 @@
9 9
10 10 #include <linux/atomic.h>
11 11 #include <linux/string.h>
12 + #include <asm/local.h>
12 13 #include <asm/page.h>
13 14
14 15 void undefsyms_base(void *p, int n);
@@ -18,11 +19,13 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
18 19 void undefsyms_base(void *p, int n)
19 20 {
20 21 char buffer[256] = { 0 };
21 -
22 22 u32 u = 0;
23 +
23 24 memset((char * volatile)page, 8, PAGE_SIZE);
24 25 memset((char * volatile)buffer, 8, sizeof(buffer));
25 26 memcpy((void * volatile)p, buffer, sizeof(buffer));
26 27 cmpxchg((u32 * volatile)&u, 0, 8);
28 + cmpxchg((unsigned long *)p, 0, 8);
29 + local_set((local_t *)p, 8);
27 30 WARN_ON(n == 0xdeadbeef);
28 31 }
modified tools/gpio/Makefile
@@ -7,13 +7,7 @@ bindir ?= /usr/bin
7 7 # isn't set and when invoked from selftests build, where srctree
8 8 # is set to ".". building_out_of_srctree is undefined for in srctree
9 9 # builds
10 - ifeq ($(srctree),)
11 - update_srctree := 1
12 - endif
13 10 ifndef building_out_of_srctree
14 - update_srctree := 1
15 - endif
16 - ifeq ($(update_srctree),1)
17 11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
18 12 srctree := $(patsubst %/,%,$(dir $(srctree)))
19 13 endif