Compare

519abe8d9acba75678a2bc91a2f6c855b9d1c54e..e2c278bc37b52222e53d5f88971ffcfacd6c97be

Merge tag 'trace-v7.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing fixes from Steven Rostedt:

 - Fix NULL dereference when copying histogram field variable

   If event_hist_trigger_parse() creates an action that uses one of
   pseudo fields for its keys, the hist_data field element will have a
   NULL for its field member. When looking to match that key, the lookup
   uses key_field->field->name which will dereference a NULL pointer.
   Instead use the helper function that handles such cases:
   expr_field_str().

 - Take the trace_types_lock when dropping the buffer_meta reference

   The tracing_buffer_meta_open() error return drops the trace_array
   reference with __trace_array_put() instead of trace_array_put() where
   the former doesn't take the lock and the latter does.

 - Fix NULL pointer dereference when reading per_cpu/cpuN/buffer_meta

   These files are created for every possible CPU. But it only contains
   data for CPUs that have come online. If one is read for a CPU that
   hasn't come online yet, it triggers a NULL pointer dereference.

   Have reading of CPUs that have not come on line yet return -ENODEV.

 - Fix an out-of-bounds shift in the log2 histogram modifier

   Histograms can take a log2 modifier to have the buckets defined by
   log2 increments. If a shift is greater than ULONG_MAX or above 2^63,
   the key falls into a lower order bucket.

   Use order_base_2() instead of "ilog2(n - 1) + 1" to have all
   overflowed keys go into the top bucket.

 - Fix the persistent ring buffer rb_meta_subbuf_idx() accounting

   The algorithm for finding the index of a sub-buffer in a persistent
   ring buffer buffer did not take into account the meta data at the
   beginning of the buffer causing the wrong index to be returned.

   As rb_subbufs_from_meta() does the proper accounting to find the
   first sub-buffer, use that function instead of repeating the logic
   (incorrectly) and make the calculations based off of that.

 - Fix the symbol name checks for the remote buffer code

   The remote ring buffer has a build time check to make sure its not
   using any code that will not be in the hypervisor. For various
   architectures, there has been false positive reports from this
   checker.

   Fix them.

 - Fix false warning in ring_buffer_map_get_reader()

   There is a WARN_ON() after rb_get_reader_page() if no reader is
   returned. But there are legitimate cases where this can happen.
   Remove the WARN_ON() and also a check that covers one of the
   legitimate cases that tries to exit out early. There's no need for
   the check if it just simply allows the return of NULL from
   rb_get_reader_page().

 - Fix the ignored return value from resize_buffer_duplicate_size()

   Some clean up of the code in tracing_snapshot_write() removed
   checking the return value of resize_buffer_duplicate_size() and if
   that failed it would not be detected.

 - Fix the histogram timestamps for buffered events

   The histogram timestamps are taken from the events that are recorded.
   It currently reads ring_buffer_event_time_stamp() but if the event is
   buffered it does not read it properly. Use tracing_event_time_stamp()
   which handles both buffered and normal events.

 - Do not initialize tracefs if tracing is disabled at boot

   If tracing fails to allocate or some other error is detected,
   tracing_disabled is set. Do not initialize tracefs in this case as it
   may expect data to be initialized but is not.

 - Free eventfs inode after an RCU grace period

   Currently eventfs_inodes are freed after a SRCU grace period as the
   iterations in the code use SRCU. There are locations that the inode
   may still be accessed from the VFS that uses RCU which does not have
   the same synchronization as SRCU. Add an RCU wait before free eventfs
   inodes.

 - Do not fail persistent and remote buffers under memory pressure

   As persistent and remote buffers have their own pre-allocated memory,
   there's no reason to check how much memory is available before
   created them. By checking the memory pressure, these buffers may fail
   to be created even though their memory is already present.

 - Account for subbuffer size when checking how much memory is available

   Before allocating a ring buffer, the size is checked against the
   current memory pressure of the system. But it assumes every
   sub-buffer is of page size. This is no longer the case. Use the
   actual sub-buffer size when calculating how much memory will be used.

 - Reject non-stack fields for synthetic stacktrace fields

   Stack traces are special fields and the checks currently do not do
   enough to make sure that the fields being processed as stack traces
   are indeed stack traces. Update the logic to properly detect what is
   or is not a stack trace.

 - Fix a crash in print_graph_function_event()

   When a tracer does not define static or default flags the
   tr->current_trace_flags is set to NULL. If the ring buffer is not
   cleared when switching tracers, the previous tracers events could be
   read. The function_graph entries will dereference the
   tr->current_trace_flags and cause a crash.

   Set the tr->current_trace_flags to a empty set of flags to prevent it
   from being NULL.

 - Separate tracing filter predicate count from allocation

   The amount allocated for the predicate program is the number of
   predicates defined plus two for adding "true" and "false" at the end.
   The nr_preds is incremented by two to accommodate the booleans but is
   then used as the limit check for number of predicates. This is
   incorrect as it is now two higher than what is expected.

   Use a separate variable for the size of the predicate array.

 - Fix the filter operator stack check

   The operator stack increments the pointer and then writes the content
   onto the stack. The check for overflow compared the current pointer
   to see if it was greater than the stack size before doing so. This is
   an off by 2 error as the write will be at the size - 1 and the
   compare is done before the increment. Adjust the check accordingly.

* tag 'trace-v7.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  tracing: Check operator stack capacity before pushing
  tracing: Keep the predicate limit separate from program capacity
  tracing: Fix crash in print_graph_function_event()
  tracing/histograms: Reject non-stacktrace fields for synthetic stacktrace fields
  ring-buffer: Use subbuf_order in available memory estimation
  ring-buffer: Skip si_mem_available() for persistent and remote buffers
  eventfs: Free the eventfs_inode after an rcu grace period too
  tracing: Do not initialize tracefs work if tracing is disabled
  tracing: Fix hist trigger timestamps for buffered events
  tracing: Fix ignored return value of resize_buffer_duplicate_size()
  ring-buffer: Fix false warning in ring_buffer_map_get_reader()
  tracing: Fix simple_ring_buffer undef check on sparc64
  tracing: Fix simple_ring_buffer undef check on parisc
  tracing: Fix empty symbol names in simple_ring_buffer undef check
  ring-buffer: Fix the sub-buffer array base in rb_meta_subbuf_idx()
  tracing: Fix the shift out of bounds in the log2 histogram modifier
  ring-buffer: Do not show buffer_meta for CPUs without a buffer
  tracing: Take trace_types_lock when dropping the buffer_meta reference
  tracing: Fix NULL dereference when copying keys for a field variable

Linus Torvalds <torvalds@linux-foundation.org> · 2026-10-17 00:27 UTC

Browse files
57 files changed, +518 −203
modified drivers/gpio/gpio-mxc.c
@@ -7,6 +7,7 @@
7 7 // Authors: Daniel Mack, Juergen Beisert.
8 8 // Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
9 9
10 + #include <linux/bitops.h>
10 11 #include <linux/cleanup.h>
11 12 #include <linux/clk.h>
12 13 #include <linux/err.h>
@@ -68,11 +69,11 @@ struct mxc_gpio_port {
68 69 struct irq_domain *domain;
69 70 struct gpio_generic_chip gen_gc;
70 71 struct device *dev;
71 - u32 both_edges;
72 + unsigned long both_edges;
72 73 struct mxc_gpio_reg_saved gpio_saved_reg;
73 74 bool power_off;
74 - u32 wakeup_pads;
75 75 bool is_pad_wakeup;
76 + unsigned long wakeup_pads;
76 77 u32 pad_type[32];
77 78 const struct mxc_gpio_hwdata *hwdata;
78 79 };
@@ -168,7 +169,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
168 169 int edge;
169 170 void __iomem *reg = port->base;
170 171
171 - port->both_edges &= ~(1 << gpio_idx);
172 + clear_bit(gpio_idx, &port->both_edges);
172 173 switch (type) {
173 174 case IRQ_TYPE_EDGE_RISING:
174 175 edge = GPIO_INT_RISE_EDGE;
@@ -188,7 +189,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
188 189 edge = GPIO_INT_HIGH_LEV;
189 190 pr_debug("mxc: set GPIO %d to high trigger\n", gpio_idx);
190 191 }
191 - port->both_edges |= 1 << gpio_idx;
192 + set_bit(gpio_idx, &port->both_edges);
192 193 }
193 194 break;
194 195 case IRQ_TYPE_LEVEL_LOW:
@@ -259,7 +260,7 @@ static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
259 260 while (irq_stat != 0) {
260 261 int irqoffset = fls(irq_stat) - 1;
261 262
262 - if (port->both_edges & (1 << irqoffset))
263 + if (test_bit(irqoffset, &port->both_edges))
263 264 mxc_flip_edge(port, irqoffset);
264 265
265 266 generic_handle_domain_irq(port->domain, irqoffset);
@@ -330,16 +331,18 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable)
330 331 ret = enable_irq_wake(port->irq_high);
331 332 else
332 333 ret = enable_irq_wake(port->irq);
333 - port->wakeup_pads |= BIT(gpio_idx);
334 334 } else {
335 335 if (port->irq_high && (gpio_idx >= 16))
336 336 ret = disable_irq_wake(port->irq_high);
337 337 else
338 338 ret = disable_irq_wake(port->irq);
339 - port->wakeup_pads &= ~BIT(gpio_idx);
340 339 }
340 + if (ret)
341 + return ret;
341 342
342 - return ret;
343 + assign_bit(gpio_idx, &port->wakeup_pads, enable);
344 +
345 + return 0;
343 346 }
344 347
345 348 static int mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
@@ -474,8 +477,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
474 477 } else
475 478 port->mx_irq_handler = mx3_gpio_irq_handler;
476 479
477 - mxc_update_irq_chained_handler(port, true);
478 -
479 480 config.dev = &pdev->dev;
480 481 config.sz = 4;
481 482 config.dat = port->base + GPIO_PSR;
@@ -499,10 +500,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
499 500 else /* silence boot time warning */
500 501 port->gen_gc.gc.base = -1;
501 502
502 - err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
503 - if (err)
504 - goto out_bgio;
505 -
506 503 irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id());
507 504 if (irq_base < 0) {
508 505 err = irq_base;
@@ -523,8 +520,19 @@ static int mxc_gpio_probe(struct platform_device *pdev)
523 520 if (err < 0)
524 521 goto out_irqdomain_remove;
525 522
523 + /*
524 + * Register the GPIO chip last: devm_gpiochip_add_data() makes the
525 + * chip visible to consumers immediately, so the IRQ domain and
526 + * generic irq chip must be ready before any to_irq() call.
527 + */
528 + err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
529 + if (err)
530 + goto out_irqdomain_remove;
531 +
526 532 list_add_tail(&port->node, &mxc_gpio_ports);
527 533
534 + mxc_update_irq_chained_handler(port, true);
535 +
528 536 platform_set_drvdata(pdev, port);
529 537 pm_runtime_put_autosuspend(&pdev->dev);
530 538
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 = false;
447 + data->gpio.can_sleep = true;
448 448 data->gpio.owner = THIS_MODULE;
449 449 data->gpio.ngpio = NCT6694_NR_GPIO;
450 450
modified drivers/gpio/gpiolib-kunit.c
@@ -28,6 +28,8 @@
28 28
29 29 #define GPIO_TEST_PROVIDER_NGPIO 4
30 30
31 + KUNIT_DEFINE_ACTION_WRAPPER(gpio_device_put_wrapper, gpio_device_put, struct gpio_device *);
32 +
31 33 /*
32 34 * The test provider tracks per-line direction and value so that lines can be
33 35 * driven as both inputs and outputs - this is needed to exercise input as well
@@ -770,6 +772,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
770 772 struct property_entry properties[2];
771 773 struct platform_device *pdev;
772 774 struct fwnode_handle *fwnode;
775 + struct gpio_device *gdev;
773 776 struct gpio_desc *desc;
774 777 bool bound = true;
775 778 int ret;
@@ -789,10 +792,12 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
789 792 wait_for_device_probe();
790 793
791 794 /* The hog must have configured the line with the expected direction. */
792 - struct gpio_device *gdev __free(gpio_device_put) =
793 - gpio_device_find_by_label(GPIO_CONSUMER_NAME);
795 + gdev = gpio_device_find_by_label(GPIO_CONSUMER_NAME);
794 796 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev);
795 797
798 + ret = kunit_add_action_or_reset(test, gpio_device_put_wrapper, gdev);
799 + KUNIT_ASSERT_EQ(test, ret, 0);
800 +
796 801 desc = gpio_device_get_desc(gdev, offset);
797 802 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc);
798 803
modified drivers/gpio/gpiolib-shared.c
@@ -449,10 +449,14 @@ 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;
454 452 struct gpio_shared_entry *entry;
455 453 struct gpio_shared_ref *ref;
454 + const char *dev_id;
455 +
456 + if (!consumer)
457 + return -EOPNOTSUPP;
458 +
459 + dev_id = dev_name(consumer);
456 460
457 461 list_for_each_entry(entry, &gpio_shared_list, list) {
458 462 list_for_each_entry(ref, &entry->refs, list) {
@@ -480,18 +484,22 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
480 484 if (!key)
481 485 return -ENOMEM;
482 486
483 - lookup = kzalloc_flex(*lookup, table, 2);
487 + struct gpiod_lookup_table *lookup __free(kfree) =
488 + kzalloc_flex(*lookup, table, 2);
484 489 if (!lookup)
485 490 return -ENOMEM;
486 491
487 492 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
488 493 dev_id, key, ref->con_id ?: "none");
489 494
490 - lookup->dev_id = dev_id;
495 + lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
496 + if (!lookup->dev_id)
497 + return -ENOMEM;
498 +
491 499 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
492 500 ref->con_id, lflags);
493 501
494 - ref->lookup = lookup;
502 + ref->lookup = no_free_ptr(lookup);
495 503 gpiod_add_lookup_table(ref->lookup);
496 504
497 505 return 0;
@@ -611,6 +619,7 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
611 619 if (ref->lookup) {
612 620 gpiod_remove_lookup_table(ref->lookup);
613 621 kfree(ref->lookup->table[0].key);
622 + kfree(ref->lookup->dev_id);
614 623 kfree(ref->lookup);
615 624 ref->lookup = NULL;
616 625 }
modified drivers/gpio/gpiolib.c
@@ -3954,16 +3954,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
3954 3954 } while ((i < array_size) &&
3955 3955 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3956 3956 /* push collected bits to outputs */
3957 - if (count != 0) {
3957 + ret = 0;
3958 + if (count != 0)
3958 3959 ret = gpiochip_set_multiple(guard.gc, mask, bits);
3959 - if (ret)
3960 - return ret;
3961 - }
3962 3960
3963 3961 if (mask != fastpath_mask)
3964 3962 bitmap_free(mask);
3965 3963 if (bits != fastpath_bits)
3966 3964 bitmap_free(bits);
3965 +
3966 + if (ret)
3967 + return ret;
3967 3968 }
3968 3969 return 0;
3969 3970 }
modified drivers/pinctrl/pinctrl-amd.c
@@ -886,6 +886,15 @@ static void amd_gpio_irq_init(struct amd_gpio *gpio_dev)
886 886
887 887 mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3);
888 888
889 + #ifdef CONFIG_ACPI
890 + /*
891 + * Platforms without _AEI leave GPIO wake sources to firmware, so
892 + * preserve their S4 wake bits.
893 + */
894 + if (acpi_has_method(ACPI_HANDLE(&gpio_dev->pdev->dev), "_AEI"))
895 + mask |= BIT(WAKE_CNTRL_OFF_S4);
896 + #endif
897 +
889 898 for (i = 0; i < desc->npins; i++) {
890 899 int pin = desc->pins[i].number;
891 900 const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
modified drivers/pinctrl/qcom/pinctrl-hawi.c
@@ -47,6 +47,7 @@
47 47 .intr_wakeup_present_bit = 6, \
48 48 .intr_wakeup_enable_bit = 7, \
49 49 .intr_target_bit = 8, \
50 + .intr_target_width = 4, \
50 51 .intr_target_kpss_val = 3, \
51 52 .intr_raw_status_bit = 4, \
52 53 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-ipq5018.c
@@ -361,7 +361,7 @@ static const char * const blsp1_uart0_groups[] = {
361 361 };
362 362
363 363 static const char * const gcc_plltest_groups[] = {
364 - "gpio10", "gpio12",
364 + "gpio10",
365 365 };
366 366
367 367 static const char * const gcc_tlmm_groups[] = {
@@ -539,7 +539,7 @@ static const char * const qdss_tracectl_b_groups[] = {
539 539 };
540 540
541 541 static const char * const pwm0_groups[] = {
542 - "gpio42",
542 + "gpio42", "gpio46",
543 543 };
544 544
545 545 static const char * const qdss_cti_trig_out_b0_groups[] = {
@@ -547,7 +547,7 @@ static const char * const qdss_cti_trig_out_b0_groups[] = {
547 547 };
548 548
549 549 static const char * const pwm1_groups[] = {
550 - "gpio43",
550 + "gpio43", "gpio1",
551 551 };
552 552
553 553 static const char * const qdss_cti_trig_in_b0_groups[] = {
@@ -555,7 +555,7 @@ static const char * const qdss_cti_trig_in_b0_groups[] = {
555 555 };
556 556
557 557 static const char * const pwm2_groups[] = {
558 - "gpio44",
558 + "gpio12", "gpio44",
559 559 };
560 560
561 561 static const char * const qdss_cti_trig_out_b1_groups[] = {
@@ -563,7 +563,7 @@ static const char * const qdss_cti_trig_out_b1_groups[] = {
563 563 };
564 564
565 565 static const char * const pwm3_groups[] = {
566 - "gpio45",
566 + "gpio45", "gpio30", "gpio13",
567 567 };
568 568
569 569 static const char * const qdss_cti_trig_in_b1_groups[] = {
@@ -677,7 +677,7 @@ static const struct pinfunction ipq5018_functions[] = {
677 677
678 678 static const struct msm_pingroup ipq5018_groups[] = {
679 679 PINGROUP(0, atest_char, _, qdss_cti_trig_out_a0, wci_txd, wci_rxd, xfem, _, _, _),
680 - PINGROUP(1, atest_char, _, qdss_cti_trig_in_a0, wci_txd, wci_rxd, xfem, _, _, _),
680 + PINGROUP(1, atest_char, pwm1, qdss_cti_trig_in_a0, wci_txd, wci_rxd, xfem, _, _, _),
681 681 PINGROUP(2, atest_char, _, qdss_cti_trig_out_a1, wci_txd, wci_rxd, xfem, _, _, _),
682 682 PINGROUP(3, atest_char, _, qdss_cti_trig_in_a1, wci_txd, wci_rxd, xfem, _, _, _),
683 683 PINGROUP(4, sdc1_data, qspi_data, blsp1_spi1, btss, dbg_out, qdss_traceclk_a, _, burn0, _),
@@ -688,8 +688,8 @@ static const struct msm_pingroup ipq5018_groups[] = {
688 688 PINGROUP(9, sdc1_clk, qspi_clk, _, qdss_tracedata_a, _, _, _, _, _),
689 689 PINGROUP(10, blsp0_spi, blsp1_uart0, led0, gcc_plltest, qdss_tracedata_a, _, _, _, _),
690 690 PINGROUP(11, blsp0_spi, blsp1_uart0, _, gcc_tlmm, qdss_tracedata_a, _, _, _, _),
691 - PINGROUP(12, blsp0_spi, blsp0_i2c, blsp1_uart0, _, gcc_plltest, qdss_tracedata_a, _, _, _),
692 - PINGROUP(13, blsp0_spi, blsp0_i2c, blsp1_uart0, _, qdss_tracedata_a, _, _, _, _),
691 + PINGROUP(12, blsp0_spi, blsp0_i2c, blsp1_uart0, _, pwm2, qdss_tracedata_a, _, _, _),
692 + PINGROUP(13, blsp0_spi, blsp0_i2c, blsp1_uart0, pwm3, qdss_tracedata_a, _, _, _, _),
693 693 PINGROUP(14, pcie0_clk, _, _, cri_trng0, qdss_tracedata_a, _, _, _, _),
694 694 PINGROUP(15, _, _, cri_trng1, qdss_tracedata_a, _, _, _, _, _),
695 695 PINGROUP(16, pcie0_wake, _, _, cri_trng, qdss_tracedata_a, _, _, _, _),
@@ -706,7 +706,7 @@ static const struct msm_pingroup ipq5018_groups[] = {
706 706 PINGROUP(27, audio_txmclk, wsa_swrm, audio_txmclk, blsp2_spi, btss, _, qdss_tracedata_b, _, _),
707 707 PINGROUP(28, audio_txbclk, wsa_swrm, blsp0_uart1, btss, qdss_tracedata_b, _, _, _, _),
708 708 PINGROUP(29, audio_txfsync, _, blsp0_uart1, _, qdss_tracedata_b, _, _, _, _),
709 - PINGROUP(30, audio_txd, led2, led0, _, _, _, _, _, _),
709 + PINGROUP(30, audio_txd, led2, led0, pwm3, _, _, _, _, _),
710 710 PINGROUP(31, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _, _),
711 711 PINGROUP(32, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _, _),
712 712 PINGROUP(33, blsp2_i2c0, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _),
@@ -722,7 +722,7 @@ static const struct msm_pingroup ipq5018_groups[] = {
722 722 PINGROUP(43, pwm1, qdss_cti_trig_in_b0, wci_txd, wci_rxd, xfem, _, _, _, _),
723 723 PINGROUP(44, pwm2, qdss_cti_trig_out_b1, wci_txd, wci_rxd, xfem, _, _, _, _),
724 724 PINGROUP(45, pwm3, qdss_cti_trig_in_b1, wci_txd, wci_rxd, xfem, _, _, _, _),
725 - PINGROUP(46, led0, _, _, _, _, _, _, _, _),
725 + PINGROUP(46, led0, pwm0, _, _, _, _, _, _, _),
726 726 };
727 727
728 728 static const struct msm_pinctrl_soc_data ipq5018_pinctrl = {
modified drivers/pinctrl/qcom/pinctrl-maili.c
@@ -47,6 +47,7 @@
47 47 .intr_wakeup_present_bit = 6, \
48 48 .intr_wakeup_enable_bit = 7, \
49 49 .intr_target_bit = 8, \
50 + .intr_target_width = 4, \
50 51 .intr_target_kpss_val = 3, \
51 52 .intr_raw_status_bit = 4, \
52 53 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-nord.c
@@ -32,6 +32,7 @@
32 32 .intr_wakeup_present_bit = 6, \
33 33 .intr_wakeup_enable_bit = 7, \
34 34 .intr_target_bit = 8, \
35 + .intr_target_width = 4, \
35 36 .intr_target_kpss_val = 3, \
36 37 .intr_raw_status_bit = 4, \
37 38 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-qcs8300.c
@@ -45,6 +45,7 @@
45 45 .intr_enable_bit = 0, \
46 46 .intr_status_bit = 0, \
47 47 .intr_target_bit = 5, \
48 + .intr_target_width = 4, \
48 49 .intr_target_kpss_val = 3, \
49 50 .intr_raw_status_bit = 4, \
50 51 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -734,29 +734,50 @@ static int pmic_gpio_get_direction(struct gpio_chip *chip, unsigned pin)
734 734 (!pad->input_enabled && !pad->output_enabled))
735 735 return -EINVAL;
736 736
737 - /* Make sure the state is aligned on what pmic_gpio_get() returns */
738 - return pad->input_enabled ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
737 + /*
738 + * An open-drain or open-source pad keeps its input buffer enabled while
739 + * driving, so the output buffer is what tells the direction.
740 + */
741 + return pad->output_enabled ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
739 742 }
740 743
741 744 static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned pin)
742 745 {
743 746 struct pmic_gpio_state *state = gpiochip_get_data(chip);
744 - unsigned long config;
747 + unsigned long configs[2];
745 748
746 - config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
749 + configs[0] = pinconf_to_config_packed(PIN_CONFIG_OUTPUT_ENABLE, 0);
750 + configs[1] = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
747 751
748 - return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
752 + return pmic_gpio_config_set(state->ctrl, pin, configs,
753 + ARRAY_SIZE(configs));
749 754 }
750 755
751 756 static int pmic_gpio_direction_output(struct gpio_chip *chip,
752 757 unsigned pin, int val)
753 758 {
754 759 struct pmic_gpio_state *state = gpiochip_get_data(chip);
755 - unsigned long config;
760 + struct pmic_gpio_pad *pad = state->ctrl->desc->pins[pin].drv_data;
761 + unsigned long configs[2];
756 762
757 - config = pinconf_to_config_packed(PIN_CONFIG_LEVEL, val);
763 + /*
764 + * An open-drain or open-source pad only ever drives one rail, so the
765 + * line can still be sampled while the pad is an output. Keep the input
766 + * buffer enabled for those, so that pmic_gpio_get() reports what is on
767 + * the wire rather than the value last written, and disable it for a
768 + * CMOS pad, so that the pad ends up in DIGITAL_OUTPUT rather than
769 + * DIGITAL_INPUT_OUTPUT. Program it either way, as the buffer may have
770 + * been left in the opposite state by the bootloader or by an earlier
771 + * direction change with a different buffer type. gpiolib applies
772 + * PIN_CONFIG_DRIVE_OPEN_DRAIN before calling this, so buffer_type is
773 + * already up to date here.
774 + */
775 + configs[0] = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE,
776 + pad->buffer_type != PMIC_GPIO_OUT_BUF_CMOS);
777 + configs[1] = pinconf_to_config_packed(PIN_CONFIG_LEVEL, val);
758 778
759 - return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
779 + return pmic_gpio_config_set(state->ctrl, pin, configs,
780 + ARRAY_SIZE(configs));
760 781 }
761 782
762 783 static int pmic_gpio_get(struct gpio_chip *chip, unsigned pin)
modified drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
@@ -84,6 +84,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
84 84 * Find the total number of pins.
85 85 * Also work out how much memory we need to store all the pin names.
86 86 */
87 + desc->npins = 0;
87 88 for (i = 0; i < SUNXI_PINCTRL_MAX_BANKS; i++) {
88 89 desc->npins += pins_per_bank[i];
89 90 if (pins_per_bank[i] < 10) {
modified drivers/power/sequencing/pwrseq-qcom-wcn.c
@@ -496,15 +496,8 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)
496 496 return dev_err_probe(dev, PTR_ERR(ctx->bt_gpio),
497 497 "Failed to get the Bluetooth enable GPIO\n");
498 498
499 - /*
500 - * FIXME: This should actually be GPIOD_OUT_LOW, but doing so would
501 - * cause the WLAN power to be toggled, resulting in PCIe link down.
502 - * Since the PCIe controller driver is not handling link down currently,
503 - * the device becomes unusable. So we need to keep this workaround until
504 - * the link down handling is implemented in the controller driver.
505 - */
506 499 ctx->wlan_gpio = devm_gpiod_get_optional(dev, "wlan-enable",
507 - GPIOD_ASIS);
500 + GPIOD_OUT_LOW);
508 501 if (IS_ERR(ctx->wlan_gpio))
509 502 return dev_err_probe(dev, PTR_ERR(ctx->wlan_gpio),
510 503 "Failed to get the WLAN enable GPIO\n");
@@ -515,13 +508,6 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)
515 508 return dev_err_probe(dev, PTR_ERR(ctx->xo_clk_gpio),
516 509 "Failed to get the XO_CLK GPIO\n");
517 510
518 - /*
519 - * Set direction to output but keep the current value in order to not
520 - * disable the WLAN module accidentally if it's already powered on.
521 - */
522 - gpiod_direction_output(ctx->wlan_gpio,
523 - gpiod_get_value_cansleep(ctx->wlan_gpio));
524 -
525 511 ctx->clk = devm_clk_get_optional(dev, NULL);
526 512 if (IS_ERR(ctx->clk))
527 513 return dev_err_probe(dev, PTR_ERR(ctx->clk),
modified fs/9p/v9fs.h
@@ -137,6 +137,7 @@ struct v9fs_session_info {
137 137 struct list_head slist; /* list of sessions registered with v9fs */
138 138 struct rw_semaphore rename_sem;
139 139 long session_lock_timeout; /* retry interval for blocking locks */
140 + struct rcu_head rcu; /* v9fs_vfs_get_link_dotl() reads ->cache in rcu pathwalk */
140 141 };
141 142
142 143 #define NDENTRY_TIMEOUT_NEVER (-1U)
modified fs/9p/vfs_super.c
@@ -173,8 +173,8 @@ static void v9fs_kill_super(struct super_block *s)
173 173
174 174 v9fs_session_cancel(v9ses);
175 175 v9fs_session_close(v9ses);
176 - kfree(v9ses);
177 - s->s_fs_info = NULL;
176 + /* v9fs_vfs_get_link_dotl() may still read ->cache in rcu pathwalk */
177 + kfree_rcu(v9ses, rcu);
178 178 p9_debug(P9_DEBUG_VFS, "exiting kill_super\n");
179 179 }
180 180
modified fs/afs/internal.h
@@ -251,6 +251,8 @@ struct afs_super_info {
251 251 struct afs_volume *volume; /* volume record */
252 252 enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
253 253 bool dyn_root; /* True if dynamic root */
254 + /* afs_atcell_get_link() reads ->net_ns in rcu pathwalk */
255 + struct rcu_head rcu;
254 256 };
255 257
256 258 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
modified fs/afs/super.c
@@ -523,7 +523,7 @@ static void afs_destroy_sbi(struct afs_super_info *as)
523 523 afs_put_volume(as->volume, afs_volume_trace_put_destroy_sbi);
524 524 afs_unuse_cell(as->cell, afs_cell_trace_unuse_sbi);
525 525 put_net(as->net_ns);
526 - kfree(as);
526 + kfree_rcu(as, rcu);
527 527 }
528 528 }
529 529
modified fs/autofs/waitq.c
@@ -12,15 +12,13 @@
12 12 */
13 13 static autofs_wqt_t autofs_next_wait_queue = 1;
14 14
15 - void autofs_catatonic_mode(struct autofs_sb_info *sbi)
15 + static void autofs_catatonic_mode_locked(struct autofs_sb_info *sbi)
16 16 {
17 17 struct autofs_wait_queue *wq, *nwq;
18 18
19 - mutex_lock(&sbi->wq_mutex);
20 - if (sbi->flags & AUTOFS_SBI_CATATONIC) {
21 - mutex_unlock(&sbi->wq_mutex);
19 + lockdep_assert_held(&sbi->wq_mutex);
20 + if (sbi->flags & AUTOFS_SBI_CATATONIC)
22 21 return;
23 - }
24 22
25 23 pr_debug("entering catatonic mode\n");
26 24
@@ -40,6 +38,21 @@ void autofs_catatonic_mode(struct autofs_sb_info *sbi)
40 38 fput(sbi->pipe); /* Close the pipe */
41 39 sbi->pipe = NULL;
42 40 sbi->pipefd = -1;
41 + }
42 +
43 + void autofs_catatonic_mode(struct autofs_sb_info *sbi)
44 + {
45 + mutex_lock(&sbi->wq_mutex);
46 + autofs_catatonic_mode_locked(sbi);
47 + mutex_unlock(&sbi->wq_mutex);
48 + }
49 +
50 + static void autofs_catatonic_mode_for_pipe(struct autofs_sb_info *sbi,
51 + struct file *pipe)
52 + {
53 + mutex_lock(&sbi->wq_mutex);
54 + if (sbi->pipe == pipe)
55 + autofs_catatonic_mode_locked(sbi);
43 56 mutex_unlock(&sbi->wq_mutex);
44 57 }
45 58
@@ -170,7 +183,7 @@ static void autofs_notify_daemon(struct autofs_sb_info *sbi,
170 183 autofs_wait_release(sbi, wq->wait_queue_token, ret);
171 184 break;
172 185 default:
173 - autofs_catatonic_mode(sbi);
186 + autofs_catatonic_mode_for_pipe(sbi, pipe);
174 187 break;
175 188 }
176 189 fput(pipe);
modified fs/ext4/ext4.h
@@ -1774,6 +1774,8 @@ struct ext4_sb_info {
1774 1774 struct list_head s_es_list; /* List of inodes with reclaimable extents */
1775 1775 long s_es_nr_inode;
1776 1776 struct ext4_es_stats s_es_stats;
1777 + /* ext4_get_link() reads the sbi in rcu pathwalk */
1778 + struct rcu_head s_rcu;
1777 1779 struct mb_cache *s_ea_block_cache;
1778 1780 struct mb_cache *s_ea_inode_cache;
1779 1781
modified fs/ext4/extents-test.c
@@ -151,6 +151,7 @@ static void extents_kunit_exit(struct kunit *test)
151 151
152 152 sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
153 153 ext4_es_unregister_shrinker(sbi);
154 + ext4_es_destroy_stats(sbi);
154 155 deactivate_super(sbi->s_sb);
155 156 kfree(sbi);
156 157 kfree(k_ctx.k_ei);
@@ -340,6 +341,7 @@ out:
340 341 k_ctx.k_data = NULL;
341 342
342 343 ext4_es_unregister_shrinker(sbi);
344 + ext4_es_destroy_stats(sbi);
343 345 out_deactivate:
344 346 deactivate_locked_super(sb);
345 347 kfree(sbi);
modified fs/ext4/extents.c
@@ -6409,6 +6409,7 @@ EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);
6409 6409 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);
6410 6410 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
6411 6411 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);
6412 + EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_destroy_stats);
6412 6413 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);
6413 6414 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
6414 6415 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
modified fs/ext4/extents_status.c
@@ -1881,12 +1881,17 @@ err1:
1881 1881 }
1882 1882
1883 1883 void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
1884 + {
1885 + shrinker_free(sbi->s_es_shrinker);
1886 + }
1887 +
1888 + /* ext4_get_link() bumps the hit and miss counters in rcu pathwalk */
1889 + void ext4_es_destroy_stats(struct ext4_sb_info *sbi)
1884 1890 {
1885 1891 percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits);
1886 1892 percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses);
1887 1893 percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
1888 1894 percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
1889 - shrinker_free(sbi->s_es_shrinker);
1890 1895 }
1891 1896
1892 1897 /*
modified fs/ext4/extents_status.h
@@ -238,6 +238,7 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
238 238
239 239 extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
240 240 extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
241 + extern void ext4_es_destroy_stats(struct ext4_sb_info *sbi);
241 242
242 243 extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v);
243 244
modified fs/ext4/super.c
@@ -1279,6 +1279,14 @@ static void ext4_flex_groups_free(struct ext4_sb_info *sbi)
1279 1279 }
1280 1280 }
1281 1281
1282 + static void ext4_put_sbi_rcu(struct rcu_head *head)
1283 + {
1284 + struct ext4_sb_info *sbi = container_of(head, struct ext4_sb_info, s_rcu);
1285 +
1286 + ext4_es_destroy_stats(sbi);
1287 + kfree(sbi);
1288 + }
1289 +
1282 1290 static void ext4_put_super(struct super_block *sb)
1283 1291 {
1284 1292 struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -1374,7 +1382,6 @@ static void ext4_put_super(struct super_block *sb)
1374 1382 ext4_stop_mmpd(sbi);
1375 1383
1376 1384 brelse(sbi->s_sbh);
1377 - sb->s_fs_info = NULL;
1378 1385 /*
1379 1386 * Now that we are completely done shutting down the
1380 1387 * superblock, we need to actually destroy the kobject.
@@ -1387,7 +1394,8 @@ static void ext4_put_super(struct super_block *sb)
1387 1394 #if IS_ENABLED(CONFIG_UNICODE)
1388 1395 utf8_unload(sb->s_encoding);
1389 1396 #endif
1390 - kfree(sbi);
1397 + /* ext4_get_link() reads the sbi and the counters in rcu pathwalk */
1398 + call_rcu(&sbi->s_rcu, ext4_put_sbi_rcu);
1391 1399 }
1392 1400
1393 1401 static struct kmem_cache *ext4_inode_cachep;
@@ -5806,6 +5814,7 @@ failed_mount3a:
5806 5814 /* Drain deferred EA inode iputs from journal replay */
5807 5815 flush_delayed_work(&sbi->s_ea_inode_work);
5808 5816 ext4_es_unregister_shrinker(sbi);
5817 + ext4_es_destroy_stats(sbi);
5809 5818 failed_mount3:
5810 5819 /* flush s_sb_upd_work before sbi destroy */
5811 5820 flush_work(&sbi->s_sb_upd_work);
modified fs/namei.c
@@ -2086,33 +2086,6 @@ all_done: // pure jump
2086 2086 return NULL;
2087 2087 }
2088 2088
2089 - /*
2090 - * Be careful in case the dentry is unlinked or renamed. Any mounts
2091 - * stacked on top of it are going away. We need to make sure that we
2092 - * don't reveal the underyling dentry during refwalk. In rcuwalk we
2093 - * catch this via d_seq and another lookup for the name. Give the same
2094 - * guarantee in refwalk.
2095 - */
2096 - static bool unlink_may_reveal(struct nameidata *nd, int flags,
2097 - struct path *path, struct dentry *dentry)
2098 - {
2099 - /* ".." and LOOKUP_DOWN may land on an unhashed directory */
2100 - if (flags & WALK_NOFOLLOW)
2101 - return false;
2102 - if (nd->flags & LOOKUP_REVAL)
2103 - return false;
2104 - /* We crossed onto a mount and the name led us here while it still existed */
2105 - if (path->mnt != nd->path.mnt)
2106 - return false;
2107 - /* only a name on its way out is flagged */
2108 - if (likely(!cant_mount(dentry)))
2109 - return false;
2110 - if (!d_unlinked(dentry))
2111 - return false;
2112 - dput(no_free_ptr(path->dentry));
2113 - return true;
2114 - }
2115 -
2116 2089 /*
2117 2090 * Do we need to follow links? We _really_ want to be able
2118 2091 * to do this check without having to look at inode->i_op,
@@ -2142,8 +2115,6 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,
2142 2115 if (unlikely(!inode))
2143 2116 return ERR_PTR(-ENOENT);
2144 2117 } else {
2145 - if (unlikely(unlink_may_reveal(nd, flags, &path, dentry)))
2146 - return ERR_PTR(-ESTALE);
2147 2118 dput(nd->path.dentry);
2148 2119 if (nd->path.mnt != path.mnt)
2149 2120 mntput(nd->path.mnt);
@@ -4750,8 +4721,7 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
4750 4721 return dentry;
4751 4722
4752 4723 if (open_flag & O_CREAT) {
4753 - /* Discard negative dentries. Need inode_lock to do the create */
4754 - if (!dentry->d_inode) {
4724 + if (d_is_negative(dentry)) {
4755 4725 if (!(nd->flags & LOOKUP_RCU))
4756 4726 dput(dentry);
4757 4727 dentry = NULL;
modified fs/namespace.c
@@ -297,7 +297,11 @@ int mnt_get_count(struct mount *mnt)
297 297 /* puts first, so a put counted here has its get counted below */
298 298 for_each_possible_cpu(cpu)
299 299 puts += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_puts;
300 - smp_mb(); /* pairs with the smp_wmb() in mntput_no_expire() */
300 + /*
301 + * Pairs with the smp_wmb() in mntput_no_expire() and with the
302 + * smp_mb() in __legitimize_mnt().
303 + */
304 + smp_mb();
301 305 for_each_possible_cpu(cpu)
302 306 gets += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_gets;
303 307
@@ -782,7 +786,7 @@ int __legitimize_mnt(struct vfsmount *bastard, unsigned seq)
782 786 return 0;
783 787 mnt = real_mount(bastard);
784 788 mnt_inc_count(mnt);
785 - smp_mb(); /* see mntput_no_expire_slowpath() and do_umount() */
789 + smp_mb(); /* pairs with the smp_mb() in mnt_get_count() */
786 790 if (likely(!read_seqretry(&mount_lock, seq)))
787 791 return 0;
788 792 lock_mount_hash();
@@ -1419,11 +1423,6 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
1419 1423
1420 1424 VFS_BUG_ON(mnt->mnt_ns);
1421 1425 lock_mount_hash();
1422 - /*
1423 - * make sure that if __legitimize_mnt() has not seen us grab
1424 - * mount_lock, we'll see their refcount increment here.
1425 - */
1426 - smp_mb();
1427 1426 mnt_dec_count(mnt);
1428 1427 count = mnt_get_count(mnt);
1429 1428 if (count != 0) {
@@ -2006,7 +2005,6 @@ static int do_umount(struct mount *mnt, int flags)
2006 2005 umount_tree(mnt, UMOUNT_PROPAGATE);
2007 2006 retval = 0;
2008 2007 } else {
2009 - smp_mb(); // paired with __legitimize_mnt()
2010 2008 shrink_submounts(mnt);
2011 2009 retval = -EBUSY;
2012 2010 if (!propagate_mount_busy(mnt, 2)) {
@@ -2254,6 +2252,11 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
2254 2252 }
2255 2253 if (!(flag & CL_COPY_MNT_NS_FILE) &&
2256 2254 is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
2255 + if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
2256 + /* Both a mount namespace file and locked. */
2257 + dst_mnt = ERR_PTR(-EPERM);
2258 + goto out;
2259 + }
2257 2260 src_mnt = skip_mnt_tree(src_mnt);
2258 2261 continue;
2259 2262 }
@@ -3649,8 +3652,9 @@ static bool mount_is_ancestor(const struct mount *p1, const struct mount *p2)
3649 3652 * @mnt_to: mount under which to mount
3650 3653 * @mp: mountpoint of @mnt_to
3651 3654 *
3652 - * - Make sure that the caller can unmount the topmost mount ensuring
3653 - * that the caller could reveal the underlying mountpoint.
3655 + * - Make sure that @mnt_from can take over the lock of @mnt_to. A
3656 + * mount of a mount namespace file is left out of a copy of the tree
3657 + * and can't.
3654 3658 * - Ensure that nothing has been mounted on top of @mnt_from before we
3655 3659 * grabbed @namespace_sem to avoid creating pointless shadow mounts.
3656 3660 * - Prevent mounting beneath a mount if the propagation relationship
@@ -3666,6 +3670,15 @@ static int can_move_mount_beneath(const struct mount *mnt_from,
3666 3670 {
3667 3671 struct mount *parent_mnt_to = mnt_to->mnt_parent;
3668 3672
3673 + /*
3674 + * @mnt_from takes over the lock of @mnt_to. copy_tree() leaves a
3675 + * mount of a mount namespace file out of every copy made without
3676 + * CL_COPY_MNT_NS_FILE, together with what is mounted on it, so it
3677 + * can't keep anything hidden.
3678 + */
3679 + if (IS_MNT_LOCKED(mnt_to) && is_mnt_ns_file(mnt_from->mnt.mnt_root))
3680 + return -EINVAL;
3681 +
3669 3682 /* Avoid creating shadow mounts during mount propagation. */
3670 3683 if (mnt_from->overmount)
3671 3684 return -EINVAL;
modified fs/notify/mark.c
@@ -929,6 +929,11 @@ restart:
929 929 goto restart;
930 930 }
931 931
932 + if (conn->flags & FSNOTIFY_CONN_FLAG_DESTROYING) {
933 + err = -ENOENT;
934 + goto out_err;
935 + }
936 +
932 937 /* is mark the first mark? */
933 938 if (hlist_empty(&conn->list)) {
934 939 hlist_add_head_rcu(&mark->obj_list, &conn->list);
@@ -1116,6 +1121,12 @@ void fsnotify_destroy_marks(fsnotify_connp_t *connp)
1116 1121 conn = fsnotify_grab_connector(connp);
1117 1122 if (!conn)
1118 1123 return;
1124 + /*
1125 + * New marks could be inserted before our cursor and survive the final
1126 + * detachment of the connector from the object. Prevent additions to
1127 + * this connector before dropping its lock.
1128 + */
1129 + conn->flags |= FSNOTIFY_CONN_FLAG_DESTROYING;
1119 1130 /*
1120 1131 * We have to be careful since we can race with e.g.
1121 1132 * fsnotify_clear_marks_by_group() and once we drop the conn->lock, the
modified fs/ntfs3/dir.c
@@ -186,11 +186,20 @@ int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
186 186 {
187 187 int ret, slen, i;
188 188 const u8 *end;
189 - struct nls_table *nls = sbi->options->nls;
189 + struct ntfs_mount_options *opts;
190 + struct nls_table *nls;
191 + bool ads;
190 192 u16 *uname = uni->name;
191 193
192 194 static_assert(sizeof(wchar_t) == sizeof(u16));
193 195
196 + /* ntfs_fs_reconfigure() may replace the options, but not ->nls */
197 + rcu_read_lock();
198 + opts = READ_ONCE(sbi->options);
199 + nls = opts->nls;
200 + ads = opts->ads;
201 + rcu_read_unlock();
202 +
194 203 if (!nls) {
195 204 /* utf8 -> utf16 */
196 205 ret = _utf8s_to_utf16s(name, name_len, endian, uname, max_ulen);
@@ -230,7 +239,7 @@ int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
230 239
231 240 uni->len = ret;
232 241 uni->ads_len = 0;
233 - if (ret > 0 && sbi->options->ads) {
242 + if (ret > 0 && ads) {
234 243 uname = uni->name;
235 244 /* Find delimiter in range [1 : ret-2). */
236 245 for (i = 1; i + 1 < ret; i++) {
modified fs/ntfs3/ntfs_fs.h
@@ -91,6 +91,8 @@ enum utf16_endian;
91 91 struct ntfs_mount_options {
92 92 char *nls_name;
93 93 struct nls_table *nls;
94 + /* ->d_hash() and ->d_compare() read the options in rcu pathwalk */
95 + struct rcu_head rcu;
94 96
95 97 kuid_t fs_uid;
96 98 kgid_t fs_gid;
@@ -211,6 +213,7 @@ struct ntfs_index {
211 213 /* Ntfs file system in-core superblock data. */
212 214 struct ntfs_sb_info {
213 215 struct super_block *sb;
216 + struct rcu_head rcu;
214 217
215 218 u32 discard_granularity;
216 219 u64 discard_granularity_mask_inv; // ~(discard_granularity_mask_inv-1)
modified fs/ntfs3/super.c
@@ -196,7 +196,7 @@ void *ntfs_set_shared(void *ptr, u32 bytes)
196 196 void *ret = NULL;
197 197 int i, j = -1;
198 198
199 - spin_lock(&s_shared_lock);
199 + spin_lock_bh(&s_shared_lock);
200 200 for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
201 201 if (!s_shared[i].cnt) {
202 202 j = i;
@@ -214,7 +214,7 @@ void *ntfs_set_shared(void *ptr, u32 bytes)
214 214 s_shared[j].cnt = 1;
215 215 ret = ptr;
216 216 }
217 - spin_unlock(&s_shared_lock);
217 + spin_unlock_bh(&s_shared_lock);
218 218
219 219 return ret;
220 220 }
@@ -231,7 +231,7 @@ void *ntfs_put_shared(void *ptr)
231 231 void *ret = ptr;
232 232 int i;
233 233
234 - spin_lock(&s_shared_lock);
234 + spin_lock_bh(&s_shared_lock);
235 235 for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
236 236 if (s_shared[i].cnt && s_shared[i].ptr == ptr) {
237 237 if (--s_shared[i].cnt)
@@ -239,7 +239,7 @@ void *ntfs_put_shared(void *ptr)
239 239 break;
240 240 }
241 241 }
242 - spin_unlock(&s_shared_lock);
242 + spin_unlock_bh(&s_shared_lock);
243 243
244 244 return ret;
245 245 }
@@ -251,6 +251,11 @@ static inline void put_mount_options(struct ntfs_mount_options *options)
251 251 kfree(options);
252 252 }
253 253
254 + static void put_mount_options_rcu(struct rcu_head *head)
255 + {
256 + put_mount_options(container_of(head, struct ntfs_mount_options, rcu));
257 + }
258 +
254 259 enum Opt {
255 260 Opt_uid,
256 261 Opt_gid,
@@ -444,6 +449,7 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
444 449 struct super_block *sb = fc->root->d_sb;
445 450 struct ntfs_sb_info *sbi = sb->s_fs_info;
446 451 struct ntfs_mount_options *new_opts = fc->fs_private;
452 + struct ntfs_mount_options *old_opts;
447 453 int ro_rw;
448 454
449 455 ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY);
@@ -473,7 +479,15 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
473 479 }
474 480
475 481 sync_filesystem(sb);
476 - swap(sbi->options, fc->fs_private);
482 + old_opts = sbi->options;
483 + /* pairs with the READ_ONCE() in ntfs_nls_to_utf16() */
484 + smp_store_release(&sbi->options, new_opts);
485 + fc->fs_private = NULL;
486 + /*
487 + * ntfs_d_hash() and ntfs_d_compare() of a pathwalk in rcu mode may
488 + * still read the old options through the sbi.
489 + */
490 + call_rcu(&old_opts->rcu, put_mount_options_rcu);
477 491
478 492 return 0;
479 493 }
@@ -708,6 +722,8 @@ static noinline void ntfs3_put_sbi(struct ntfs_sb_info *sbi)
708 722
709 723 static void ntfs3_free_sbi(struct ntfs_sb_info *sbi)
710 724 {
725 + if (sbi->options)
726 + put_mount_options(sbi->options);
711 727 kfree(sbi->new_rec);
712 728 kvfree(ntfs_put_shared(sbi->upcase));
713 729 kvfree(sbi->def_table);
@@ -719,6 +735,11 @@ static void ntfs3_free_sbi(struct ntfs_sb_info *sbi)
719 735 kfree(sbi);
720 736 }
721 737
738 + static void ntfs3_free_sbi_rcu(struct rcu_head *head)
739 + {
740 + ntfs3_free_sbi(container_of(head, struct ntfs_sb_info, rcu));
741 + }
742 +
722 743 static void ntfs_put_super(struct super_block *sb)
723 744 {
724 745 struct ntfs_sb_info *sbi = sb->s_fs_info;
@@ -728,11 +749,11 @@ static void ntfs_put_super(struct super_block *sb)
728 749 /* Mark rw ntfs as clear, if possible. */
729 750 ntfs_set_state(sbi, NTFS_DIRTY_CLEAR);
730 751
731 - if (sbi->options) {
732 - put_mount_options(sbi->options);
733 - sbi->options = NULL;
734 - }
735 -
752 + /*
753 + * The mount options stay until the sbi is freed: ->d_hash() and
754 + * ->d_compare() of a pathwalk in rcu mode read the nls table through
755 + * them.
756 + */
736 757 ntfs3_put_sbi(sbi);
737 758 }
738 759
@@ -1939,9 +1960,11 @@ static void ntfs3_kill_sb(struct super_block *sb)
1939 1960
1940 1961 kill_block_super(sb);
1941 1962
1942 - if (sbi->options)
1943 - put_mount_options(sbi->options);
1944 - ntfs3_free_sbi(sbi);
1963 + /*
1964 + * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare()
1965 + * and read the upcase table and the nls table through the sbi.
1966 + */
1967 + call_rcu(&sbi->rcu, ntfs3_free_sbi_rcu);
1945 1968 }
1946 1969
1947 1970 // clang-format off
modified fs/ocfs2/dlm/dlmcommon.h
@@ -435,6 +435,8 @@ enum {
435 435 DLM_DEREF_LOCKRES_DONE = 522,
436 436 };
437 437
438 + extern spinlock_t dlm_reco_state_lock;
439 +
438 440 struct dlm_reco_node_data
439 441 {
440 442 int state;
modified fs/ocfs2/dlm/dlmdebug.c
@@ -736,8 +736,11 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
736 736 buf + out, len - out);
737 737 out += scnprintf(buf + out, len - out, "\n");
738 738
739 + spin_unlock(&dlm->spinlock);
740 +
739 741 /* Recovery Node State: */
740 742 out += scnprintf(buf + out, len - out, "Recovery Node State:\n");
743 + spin_lock(&dlm_reco_state_lock);
741 744 list_for_each_entry(node, &dlm->reco.node_data, list) {
742 745 switch (node->state) {
743 746 case DLM_RECO_NODE_DATA_INIT:
@@ -769,7 +772,7 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
769 772 node->node_num, state);
770 773 }
771 774
772 - spin_unlock(&dlm->spinlock);
775 + spin_unlock(&dlm_reco_state_lock);
773 776
774 777 return out;
775 778 }
modified fs/ocfs2/dlm/dlmrecovery.c
@@ -80,7 +80,7 @@ static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
80 80
81 81 static u64 dlm_get_next_mig_cookie(void);
82 82
83 - static DEFINE_SPINLOCK(dlm_reco_state_lock);
83 + DEFINE_SPINLOCK(dlm_reco_state_lock);
84 84 static DEFINE_SPINLOCK(dlm_mig_cookie_lock);
85 85 static u64 dlm_mig_cookie = 1;
86 86
modified fs/overlayfs/params.c
@@ -216,6 +216,9 @@ static ssize_t ovl_parse_param_split_lowerdirs(char *str)
216 216 if (*s == '\\') {
217 217 /* keep esc chars in split lowerdir */
218 218 *d++ = *s++;
219 + /* A trailing backslash escapes nothing. */
220 + if (!*s)
221 + return -EINVAL;
219 222 } else if (*s == ':') {
220 223 bool next_colon = (*(s + 1) == ':');
221 224
modified fs/pipe.c
@@ -838,9 +838,11 @@ pipe_fasync(int fd, struct file *filp, int on)
838 838 if (filp->f_mode & FMODE_READ)
839 839 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
840 840 if ((filp->f_mode & FMODE_WRITE) && retval >= 0) {
841 + int read_ret = retval;
842 +
841 843 retval = fasync_helper(fd, filp, on, &pipe->fasync_writers);
842 - if (retval < 0 && (filp->f_mode & FMODE_READ))
843 - /* this can happen only if on == T */
844 + /* Undo only a reader entry added by this call. */
845 + if (retval < 0 && read_ret > 0)
844 846 fasync_helper(-1, filp, 0, &pipe->fasync_readers);
845 847 }
846 848 mutex_unlock(&pipe->mutex);
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 fs/unicode/utf8-core.c
@@ -3,6 +3,7 @@
3 3 #include <linux/kernel.h>
4 4 #include <linux/string.h>
5 5 #include <linux/slab.h>
6 + #include <linux/rcupdate.h>
6 7 #include <linux/parser.h>
7 8 #include <linux/errno.h>
8 9 #include <linux/stringhash.h>
@@ -183,12 +184,24 @@ out_free_um:
183 184 }
184 185 EXPORT_SYMBOL(utf8_load);
185 186
187 + static void utf8_unload_rcu(struct rcu_head *head)
188 + {
189 + struct unicode_map *um = container_of(head, struct unicode_map, rcu);
190 +
191 + symbol_put(utf8_data_table);
192 + kfree(um);
193 + }
194 +
195 + /*
196 + * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare() of a
197 + * filesystem that is being torn down and read the map through its
198 + * superblock, so the map and the tables it points to have to outlive the
199 + * grace period.
200 + */
186 201 void utf8_unload(struct unicode_map *um)
187 202 {
188 - if (um) {
189 - symbol_put(utf8_data_table);
190 - kfree(um);
191 - }
203 + if (um)
204 + call_rcu(&um->rcu, utf8_unload_rcu);
192 205 }
193 206 EXPORT_SYMBOL(utf8_unload);
194 207
modified include/linux/fsnotify_backend.h
@@ -566,6 +566,7 @@ struct fsnotify_mark_connector {
566 566 unsigned char prio; /* Highest priority group */
567 567 #define FSNOTIFY_CONN_FLAG_IS_WATCHED 0x01
568 568 #define FSNOTIFY_CONN_FLAG_HAS_IREF 0x02
569 + #define FSNOTIFY_CONN_FLAG_DESTROYING 0x04
569 570 unsigned short flags; /* flags [lock] */
570 571 union {
571 572 /* Object pointer [lock] */
modified include/linux/sched/signal.h
@@ -130,8 +130,8 @@ struct signal_struct {
130 130 * process will inherit a flag if they should look for a
131 131 * child_subreaper process at exit.
132 132 */
133 - unsigned int is_child_subreaper:1;
134 - unsigned int has_child_subreaper:1;
133 + bool is_child_subreaper;
134 + bool has_child_subreaper;
135 135 unsigned int autoreap:1;
136 136
137 137 #ifdef CONFIG_POSIX_TIMERS
modified include/linux/unicode.h
@@ -53,6 +53,7 @@ struct unicode_map {
53 53 unsigned int version;
54 54 const struct utf8data *ntab[UTF8_NMAX];
55 55 const struct utf8data_table *tables;
56 + struct rcu_head rcu;
56 57 };
57 58
58 59 int utf8_validate(const struct unicode_map *um, const struct qstr *str);
modified ipc/namespace.c
@@ -96,7 +96,7 @@ fail_ipc:
96 96 fail_mq_sysctls:
97 97 retire_mq_sysctls(ns);
98 98 fail_mq_mount:
99 - mntput(ns->mq_mnt);
99 + kern_unmount(ns->mq_mnt);
100 100 fail_put:
101 101 put_user_ns(ns->user_ns);
102 102 ns_common_free(ns);
modified kernel/exit.c
@@ -1729,7 +1729,7 @@ static long do_wait(struct wait_opts *wo)
1729 1729 add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1730 1730
1731 1731 do {
1732 - set_current_state(TASK_INTERRUPTIBLE);
1732 + set_current_state(TASK_INTERRUPTIBLE | TASK_FREEZABLE);
1733 1733 retval = __do_wait(wo);
1734 1734 if (retval != -ERESTARTSYS)
1735 1735 break;
modified kernel/fork.c
@@ -1619,7 +1619,13 @@ static int copy_exec_state(u64 clone_flags, struct task_struct *tsk)
1619 1619 return task_exec_state_copy(tsk);
1620 1620 }
1621 1621
1622 - static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1622 + enum copy_fs_flags_t {
1623 + COPY_FS_UMH = (1 << 0),
1624 + COPY_FS_IDLE = (1 << 1),
1625 + };
1626 +
1627 + static int copy_fs(u64 clone_flags, struct task_struct *tsk,
1628 + enum copy_fs_flags_t flags)
1623 1629 {
1624 1630 struct fs_struct *fs;
1625 1631
@@ -1629,19 +1635,20 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1629 1635 * filesystem state, or be started from a non-initial mount
1630 1636 * namespace.
1631 1637 */
1632 - if (umh) {
1638 + if (flags & COPY_FS_UMH) {
1633 1639 if (clone_flags & (CLONE_NEWNS | CLONE_FS))
1634 1640 return -EINVAL;
1635 1641 if (current->nsproxy->mnt_ns != &init_mnt_ns)
1636 1642 return -EINVAL;
1637 1643 fs = userspace_init_fs;
1644 + } else if (flags & COPY_FS_IDLE) {
1645 + fs = &init_fs;
1638 1646 } else {
1639 1647 fs = current->fs;
1640 1648 VFS_WARN_ON_ONCE(current->fs != current->real_fs);
1641 1649 }
1642 1650
1643 1651 if (clone_flags & CLONE_FS) {
1644 - /* tsk->fs is already what we want */
1645 1652 read_seqlock_excl(&fs->seq);
1646 1653 /* "users" and "in_exec" locked for check_unsafe_exec() */
1647 1654 if (fs->in_exec) {
@@ -1650,6 +1657,7 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1650 1657 }
1651 1658 fs->users++;
1652 1659 read_sequnlock_excl(&fs->seq);
1660 + tsk->real_fs = tsk->fs = fs;
1653 1661 return 0;
1654 1662 }
1655 1663 tsk->real_fs = tsk->fs = copy_fs_struct(fs);
@@ -2299,7 +2307,9 @@ __latent_entropy struct task_struct *copy_process(
2299 2307 retval = copy_files(clone_flags, p, args->no_files);
2300 2308 if (retval)
2301 2309 goto bad_fork_cleanup_semundo;
2302 - retval = copy_fs(clone_flags, p, args->umh);
2310 + retval = copy_fs(clone_flags, p,
2311 + (args->umh ? COPY_FS_UMH : 0) |
2312 + (args->idle ? COPY_FS_IDLE : 0));
2303 2313 if (retval)
2304 2314 goto bad_fork_cleanup_files;
2305 2315 retval = copy_sighand(clone_flags, p);
@@ -2671,7 +2681,7 @@ struct task_struct * __init fork_idle(int cpu)
2671 2681 {
2672 2682 struct task_struct *task;
2673 2683 struct kernel_clone_args args = {
2674 - .flags = CLONE_VM,
2684 + .flags = CLONE_VM | CLONE_FS,
2675 2685 .fn = &idle_dummy,
2676 2686 .fn_arg = NULL,
2677 2687 .kthread = 1,
modified kernel/pid_namespace.c
@@ -268,7 +268,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
268 268 * free_pid() will awaken this task.
269 269 */
270 270 for (;;) {
271 - set_current_state(TASK_INTERRUPTIBLE);
271 + set_current_state(TASK_IDLE | TASK_FREEZABLE);
272 272 if (pid_ns->pid_allocated == init_pids)
273 273 break;
274 274 schedule();
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;
@@ -2440,22 +2443,33 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2440 2443 unsigned long nr_pages, struct list_head *pages)
2441 2444 {
2442 2445 struct trace_buffer *buffer = cpu_buffer->buffer;
2446 + unsigned int subbuf_order = buffer->subbuf_order;
2443 2447 struct ring_buffer_cpu_meta *meta = NULL;
2444 2448 struct buffer_page *bpage, *tmp;
2445 - bool user_thread = current->mm != NULL;
2446 2449 struct ring_buffer_desc *desc = NULL;
2450 + bool user_thread = false;
2447 2451 long i;
2448 2452
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;
2453 + if (buffer->range_addr_start) {
2454 + meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2455 + } else if (buffer->remote) {
2456 + desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2457 + if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2458 + return -EINVAL;
2459 + } else {
2460 + /*
2461 + * Check if the available memory is there first.
2462 + * Note, si_mem_available() only gives us a rough estimate of available
2463 + * memory. It may not be accurate. But we don't care, we just want
2464 + * to prevent doing any allocation when it is obvious that it is
2465 + * not going to succeed.
2466 + */
2467 + i = si_mem_available();
2468 + if (i < (nr_pages << subbuf_order))
2469 + return -ENOMEM;
2470 +
2471 + user_thread = current->mm != NULL;
2472 + }
2459 2473
2460 2474 /*
2461 2475 * If a user thread allocates too much, and si_mem_available()
@@ -2469,15 +2483,6 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2469 2483 if (user_thread)
2470 2484 set_current_oom_origin();
2471 2485
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 2486 for (i = 0; i < nr_pages; i++) {
2482 2487
2483 2488 bpage = alloc_cpu_page(cpu_buffer->cpu);
@@ -2513,12 +2518,11 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2513 2518 bpage->id = i + 1;
2514 2519 cpu_buffer->subbuf_ids[i + 1] = bpage;
2515 2520 } else {
2516 - bpage->page = alloc_cpu_data(cpu_buffer->cpu,
2517 - cpu_buffer->buffer->subbuf_order);
2521 + bpage->page = alloc_cpu_data(cpu_buffer->cpu, subbuf_order);
2518 2522 if (!bpage->page)
2519 2523 goto free_pages;
2520 2524 }
2521 - bpage->order = cpu_buffer->buffer->subbuf_order;
2525 + bpage->order = subbuf_order;
2522 2526
2523 2527 if (user_thread && fatal_signal_pending(current))
2524 2528 goto free_pages;
@@ -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
@@ -99,6 +99,12 @@ struct tracers {
99 99 struct tracer_flags *flags;
100 100 };
101 101
102 + /*
103 + * Tracers that do not define their own flags use these empty flags,
104 + * as tr->current_trace_flags must never be NULL.
105 + */
106 + static struct tracer_flags no_tracer_flags;
107 +
102 108 /*
103 109 * To prevent the comm cache from being overwritten when no
104 110 * tracing is active, only save the comm when a trace event
@@ -1318,7 +1324,12 @@ static int run_tracer_selftest(struct tracer *type)
1318 1324 tracing_reset_online_cpus(&tr->array_buffer);
1319 1325
1320 1326 tr->current_trace = type;
1321 - tr->current_trace_flags = type->flags ? : type->default_flags;
1327 + if (type->flags)
1328 + tr->current_trace_flags = type->flags;
1329 + else if (type->default_flags)
1330 + tr->current_trace_flags = type->default_flags;
1331 + else
1332 + tr->current_trace_flags = &no_tracer_flags;
1322 1333
1323 1334 #ifdef CONFIG_TRACER_MAX_TRACE
1324 1335 if (tracer_uses_snapshot(type)) {
@@ -5089,7 +5100,12 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
5089 5100 return ret;
5090 5101 }
5091 5102
5092 - tr->current_trace_flags = t->flags ? : t->tracer->flags;
5103 + if (t->flags)
5104 + tr->current_trace_flags = t->flags;
5105 + else if (t->tracer->flags)
5106 + tr->current_trace_flags = t->tracer->flags;
5107 + else
5108 + tr->current_trace_flags = &no_tracer_flags;
5093 5109
5094 5110 if (trace->init) {
5095 5111 ret = tracer_init(trace, tr);
@@ -5881,7 +5897,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
5881 5897
5882 5898 ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu);
5883 5899 if (ret < 0)
5884 - __trace_array_put(tr);
5900 + trace_array_put(tr);
5885 5901 return ret;
5886 5902 }
5887 5903
@@ -9287,6 +9303,12 @@ static struct notifier_block trace_module_nb = {
9287 9303
9288 9304 static __init void tracer_init_tracefs_work_func(struct work_struct *work)
9289 9305 {
9306 + /*
9307 + * Do not attempt to initialize tracefs if tracing was disabled or
9308 + * failed to allocate
9309 + */
9310 + if (tracing_disabled)
9311 + return;
9290 9312
9291 9313 event_trace_init();
9292 9314
modified kernel/trace/trace_events_filter.c
@@ -482,18 +482,17 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
482 482 int len;
483 483 int N = 0;
484 484 int i;
485 -
486 - nr_preds += 2; /* For TRUE and FALSE */
485 + int nr_preds_alloc = nr_preds + 2; /* For TRUE and FALSE */
487 486
488 487 op_stack = kmalloc_objs(*op_stack, nr_parens);
489 488 if (!op_stack)
490 489 return ERR_PTR(-ENOMEM);
491 - prog_stack = kzalloc_objs(*prog_stack, nr_preds);
490 + prog_stack = kzalloc_objs(*prog_stack, nr_preds_alloc);
492 491 if (!prog_stack) {
493 492 parse_error(pe, -ENOMEM, 0);
494 493 goto out_free;
495 494 }
496 - inverts = kmalloc_array(nr_preds, sizeof(*inverts), GFP_KERNEL);
495 + inverts = kmalloc_array(nr_preds_alloc, sizeof(*inverts), GFP_KERNEL);
497 496 if (!inverts) {
498 497 parse_error(pe, -ENOMEM, 0);
499 498 goto out_free;
@@ -512,7 +511,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
512 511
513 512 switch (*next) {
514 513 case '(': /* #2 */
515 - if (top - op_stack > nr_parens) {
514 + if (top - op_stack >= nr_parens - 1) {
516 515 ret = -EINVAL;
517 516 goto out_free;
518 517 }
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);
@@ -2121,7 +2121,8 @@ static int init_var_ref(struct hist_field *ref_field,
2121 2121 ref_field->size = var_field->size;
2122 2122 ref_field->is_signed = var_field->is_signed;
2123 2123 ref_field->flags |= var_field->flags &
2124 - (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS);
2124 + (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS |
2125 + HIST_FIELD_FL_STACKTRACE);
2125 2126
2126 2127 if (system) {
2127 2128 ref_field->system = kstrdup(system, GFP_KERNEL);
@@ -3090,7 +3091,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
3090 3091 key_field = hist_data->fields[i];
3091 3092 if (!first)
3092 3093 seq_buf_putc(&s, ',');
3093 - seq_buf_puts(&s, key_field->field->name);
3094 + expr_field_str(key_field, &s);
3094 3095 first = false;
3095 3096 }
3096 3097
@@ -3318,6 +3319,7 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
3318 3319 ret = PTR_ERR(var);
3319 3320 goto err;
3320 3321 }
3322 + var->flags |= val->flags & HIST_FIELD_FL_STACKTRACE;
3321 3323
3322 3324 field_var = kzalloc_obj(struct field_var);
3323 3325 if (!field_var) {
@@ -3946,7 +3948,10 @@ static int check_synth_field(struct synth_event *event,
3946 3948 && field->is_dynamic)
3947 3949 return 0;
3948 3950
3949 - if (strstr(hist_field->type, "long[") && field->is_stack)
3951 + if (!!(hist_field->flags & HIST_FIELD_FL_STACKTRACE) != field->is_stack)
3952 + return -EINVAL;
3953 +
3954 + if (field->is_stack)
3950 3955 return 0;
3951 3956
3952 3957 if (strcmp(field->type, hist_field->type) != 0) {
@@ -4487,7 +4492,8 @@ static int create_var_field(struct hist_trigger_data *hist_data,
4487 4492 if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_EXECNAME)
4488 4493 update_var_execname(hist_data->fields[val_idx]);
4489 4494
4490 - if (!ret && hist_data->fields[val_idx]->flags &
4495 + if (!ret && !(hist_data->fields[val_idx]->flags & HIST_FIELD_FL_ALIAS) &&
4496 + hist_data->fields[val_idx]->flags &
4491 4497 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE))
4492 4498 hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++;
4493 4499
@@ -5228,7 +5234,8 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
5228 5234 if (hist_field->flags & HIST_FIELD_FL_VAR) {
5229 5235 var_idx = hist_field->var.idx;
5230 5236
5231 - if (hist_field->flags &
5237 + if (!(hist_field->flags & HIST_FIELD_FL_ALIAS) &&
5238 + hist_field->flags &
5232 5239 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE)) {
5233 5240 unsigned int str_start, var_str_idx, idx;
5234 5241 char *str, *val_str;
modified kernel/trace/trace_probe.c
@@ -2287,7 +2287,6 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
2287 2287 int *new_argc, char *buf, int bufsize,
2288 2288 struct traceprobe_parse_context *ctx)
2289 2289 {
2290 - const struct btf_param *params = NULL;
2291 2290 int i, j, n, used, ret, args_idx = -1;
2292 2291 const char **new_argv __free(kfree) = NULL;
2293 2292
@@ -2305,7 +2304,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
2305 2304 if (args_idx != -1) {
2306 2305 /* $arg* requires BTF info */
2307 2306 trace_probe_log_err(0, NOSUP_BTFARG);
2308 - return (const char **)params;
2307 + return ERR_PTR(-EOPNOTSUPP);
2309 2308 }
2310 2309 *new_argc = argc;
2311 2310 return NULL;
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 kernel/watch_queue.c
@@ -101,7 +101,7 @@ static bool post_one_notification(struct watch_queue *wqueue,
101 101 struct pipe_inode_info *pipe = wqueue->pipe;
102 102 struct pipe_buffer *buf;
103 103 struct page *page;
104 - unsigned int head, tail, note, offset, len;
104 + unsigned int head, tail, note, offset, len, nr_notes;
105 105 bool done = false;
106 106
107 107 spin_lock_irq(&pipe->rd_wait.lock);
@@ -111,8 +111,10 @@ static bool post_one_notification(struct watch_queue *wqueue,
111 111 if (pipe_full(head, tail, pipe->ring_size))
112 112 goto lost;
113 113
114 - note = find_first_bit(wqueue->notes_bitmap, wqueue->nr_notes);
115 - if (note >= wqueue->nr_notes)
114 + /* Pairs with the smp_store_release() in watch_queue_set_size(). */
115 + nr_notes = smp_load_acquire(&wqueue->nr_notes);
116 + note = find_first_bit(wqueue->notes_bitmap, nr_notes);
117 + if (note >= nr_notes)
116 118 goto lost;
117 119
118 120 page = wqueue->notes[note / WATCH_QUEUE_NOTES_PER_PAGE];
@@ -297,7 +299,8 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
297 299 wqueue->notes = pages;
298 300 wqueue->notes_bitmap = bitmap;
299 301 wqueue->nr_pages = nr_pages;
300 - wqueue->nr_notes = nr_notes;
302 + /* Pairs with the smp_load_acquire() in post_one_notification(). */
303 + smp_store_release(&wqueue->nr_notes, nr_notes);
301 304 return 0;
302 305
303 306 error_p:
modified samples/pidfd/Makefile
@@ -1,4 +1,4 @@
1 1 # SPDX-License-Identifier: GPL-2.0
2 - usertprogs-always-y += pidfd-metadata
2 + userprogs-always-y += pidfd-metadata
3 3
4 4 userccflags += -I usr/include
modified tools/gpio/Makefile
@@ -7,7 +7,13 @@ 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
10 13 ifndef building_out_of_srctree
14 + update_srctree := 1
15 + endif
16 + ifeq ($(update_srctree),1)
11 17 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 18 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 19 endif
modified tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
@@ -9,6 +9,8 @@
9 9 #include <errno.h>
10 10 #include <fcntl.h>
11 11 #include <sched.h>
12 + #include <stdbool.h>
13 + #include <signal.h>
12 14 #include <stdio.h>
13 15 #include <stdlib.h>
14 16 #include <string.h>
@@ -27,6 +29,12 @@
27 29 #ifndef MOVE_MOUNT_BENEATH
28 30 #define MOVE_MOUNT_BENEATH 0x00000200
29 31 #endif
32 + #ifndef OPEN_TREE_CLONE
33 + #define OPEN_TREE_CLONE 1
34 + #endif
35 + #ifndef OPEN_TREE_CLOEXEC
36 + #define OPEN_TREE_CLOEXEC O_CLOEXEC
37 + #endif
30 38
31 39 #define DIR_LEN 64
32 40 #define PATH_LEN 192
@@ -120,6 +128,35 @@ static bool covered(const char *path)
120 128 return fd < 0;
121 129 }
122 130
131 + /* What @path reads, "" if it can't be read. */
132 + static int read_word(const char *path, char *buf, size_t len)
133 + {
134 + ssize_t n = 0;
135 + int fd;
136 +
137 + fd = open(path, O_RDONLY | O_CLOEXEC);
138 + if (fd >= 0) {
139 + n = read(fd, buf, len - 1);
140 + close(fd);
141 + }
142 + buf[n > 0 ? n : 0] = 0;
143 + return fd < 0 ? -1 : 0;
144 + }
145 +
146 + /* Put a clone of the mount at @src beneath the top mount at @where. */
147 + static int move_beneath(const char *src, const char *where)
148 + {
149 + int fd, ret;
150 +
151 + fd = syscall(__NR_open_tree, AT_FDCWD, src, OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
152 + if (fd < 0)
153 + return -1;
154 + ret = syscall(__NR_move_mount, fd, "", AT_FDCWD, where,
155 + MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_BENEATH);
156 + close(fd);
157 + return ret;
158 + }
159 +
123 160 FIXTURE(locked_mount) {
124 161 char base[DIR_LEN];
125 162 bool tracing; /* debugfs with the tracefs automount is there */
@@ -429,4 +466,89 @@ TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)
429 466 EXPECT_EQ(ret, CHILD_OK);
430 467 }
431 468
469 + /*
470 + * A mount of a mount namespace file is left out of the copy that
471 + * unshare(CLONE_NEWNS) makes, together with everything mounted on it, so
472 + * it can't take over the lock of a cover it is moved beneath. The child
473 + * tries just that with the namespace file of a grandchild and gets EINVAL.
474 + * A bind of an ordinary file takes the lock over, and the file is still
475 + * covered in the next copy of the mount namespace.
476 + */
477 + static int ns_file_child(const char *base)
478 + {
479 + char secret[PATH_LEN], mine[PATH_LEN], nsfile[PATH_LEN], buf[32];
480 + int ret = CHILD_OK, pfd[2];
481 + pid_t pid;
482 +
483 + snprintf(secret, sizeof(secret), "%s/P/secret", base);
484 + snprintf(mine, sizeof(mine), "%s/mine", base);
485 +
486 + if (enter_userns() || pipe(pfd))
487 + return CHILD_SETUP;
488 + /* the cover is locked */
489 + if (!umount2(secret, 0) || errno != EINVAL)
490 + return CHILD_STEP1;
491 +
492 + /* a mount namespace newer than our own, so that a bind of it is allowed */
493 + pid = fork();
494 + if (pid < 0)
495 + return CHILD_SETUP;
496 + if (pid == 0) {
497 + if (unshare(CLONE_NEWNS) || send_byte(pfd[1]))
498 + _exit(1);
499 + pause();
500 + _exit(0);
501 + }
502 + if (wait_byte(pfd[0]))
503 + return CHILD_SETUP;
504 + snprintf(nsfile, sizeof(nsfile), "/proc/%d/ns/mnt", pid);
505 + if (!move_beneath(nsfile, secret) || errno != EINVAL)
506 + ret = CHILD_STEP2;
507 + kill(pid, SIGKILL);
508 + waitpid(pid, NULL, 0);
509 + if (ret)
510 + return ret;
511 +
512 + /* an ordinary file beneath the cover takes the lock over */
513 + if (move_beneath(mine, secret))
514 + return CHILD_STEP3;
515 + if (umount2(secret, 0))
516 + return CHILD_STEP3;
517 + if (!umount2(secret, 0) || errno != EINVAL)
518 + return CHILD_STEP3;
519 + /* and it is in the next copy of the namespace */
520 + if (unshare(CLONE_NEWNS))
521 + return CHILD_SETUP;
522 + if (read_word(secret, buf, sizeof(buf)) || strcmp(buf, "mine"))
523 + return CHILD_STEP4;
524 + return CHILD_OK;
525 + }
526 +
527 + TEST_F(locked_mount, mount_namespace_file_cant_take_the_lock)
528 + {
529 + char p[PATH_LEN], q[PATH_LEN];
530 + pid_t pid;
531 + int ret;
532 +
533 + snprintf(p, sizeof(p), "%s/P", self->base);
534 + ASSERT_EQ(mkdir(p, 0755), 0);
535 + ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
536 + snprintf(p, sizeof(p), "%s/P/secret", self->base);
537 + ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
538 + snprintf(q, sizeof(q), "%s/P/empty", self->base);
539 + ASSERT_EQ(create_file(q, ""), 0);
540 + /* the cover: an empty file over the secret */
541 + ASSERT_EQ(mount(q, p, NULL, MS_BIND, NULL), 0);
542 + snprintf(q, sizeof(q), "%s/mine", self->base);
543 + ASSERT_EQ(create_file(q, "mine"), 0);
544 +
545 + pid = fork();
546 + ASSERT_GE(pid, 0);
547 + if (pid == 0)
548 + _exit(ns_file_child(self->base));
549 + ret = wait_child(pid);
550 + TH_LOG("child exit code %d", ret);
551 + EXPECT_EQ(ret, CHILD_OK);
552 + }
553 +
432 554 TEST_HARNESS_MAIN