From 2ff8dacf3278469970a4fbe14179ac70a7782d04 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 30 Jan 2022 21:52:00 -0500 Subject: [PATCH] Fixes for 5.15 Signed-off-by: Sasha Levin --- ...ealtek-rtl-fix-off-by-one-in-routing.patch | 64 ++++++++ ...realtek-rtl-map-control-data-to-virq.patch | 39 +++++ ...ore-fix-cgroup-event-list-management.patch | 77 ++++++++++ ...but-not-used-warnings-when-config_pr.patch | 141 ++++++++++++++++++ ...ous-prototype-warnings-when-config_c.patch | 68 +++++++++ queue-5.15/series | 5 + 6 files changed, 394 insertions(+) create mode 100644 queue-5.15/irqchip-realtek-rtl-fix-off-by-one-in-routing.patch create mode 100644 queue-5.15/irqchip-realtek-rtl-map-control-data-to-virq.patch create mode 100644 queue-5.15/perf-core-fix-cgroup-event-list-management.patch create mode 100644 queue-5.15/psi-fix-defined-but-not-used-warnings-when-config_pr.patch create mode 100644 queue-5.15/psi-fix-no-previous-prototype-warnings-when-config_c.patch diff --git a/queue-5.15/irqchip-realtek-rtl-fix-off-by-one-in-routing.patch b/queue-5.15/irqchip-realtek-rtl-fix-off-by-one-in-routing.patch new file mode 100644 index 00000000000..5c522f66122 --- /dev/null +++ b/queue-5.15/irqchip-realtek-rtl-fix-off-by-one-in-routing.patch @@ -0,0 +1,64 @@ +From a88c27297971160e5a76abb659cdab418564b022 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 9 Jan 2022 15:54:33 +0100 +Subject: irqchip/realtek-rtl: Fix off-by-one in routing + +From: Sander Vanheule + +[ Upstream commit 91351b5dd0fd494eb2d85e1bb6aca77b067447e0 ] + +There is an offset between routing values (1..6) and the connected MIPS +CPU interrupts (2..7), but no distinction was made between these two +values. + +This issue was previously hidden during testing, because an interrupt +mapping was used where for each required interrupt another (unused) +routing was configured, with an offset of +1. + +Offset the CPU IRQ numbers by -1 to retrieve the correct routing value. + +Fixes: 9f3a0f34b84a ("irqchip: Add support for Realtek RTL838x/RTL839x interrupt controller") +Signed-off-by: Sander Vanheule +Signed-off-by: Marc Zyngier +Link: https://lore.kernel.org/r/177b920aa8d8610615692d0e657e509f363c85ca.1641739718.git.sander@svanheule.net +Signed-off-by: Sasha Levin +--- + drivers/irqchip/irq-realtek-rtl.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/drivers/irqchip/irq-realtek-rtl.c b/drivers/irqchip/irq-realtek-rtl.c +index d6788dd93c7bb..568614edd88f4 100644 +--- a/drivers/irqchip/irq-realtek-rtl.c ++++ b/drivers/irqchip/irq-realtek-rtl.c +@@ -95,7 +95,8 @@ static void realtek_irq_dispatch(struct irq_desc *desc) + * SoC interrupts are cascaded to MIPS CPU interrupts according to the + * interrupt-map in the device tree. Each SoC interrupt gets 4 bits for + * the CPU interrupt in an Interrupt Routing Register. Max 32 SoC interrupts +- * thus go into 4 IRRs. ++ * thus go into 4 IRRs. A routing value of '0' means the interrupt is left ++ * disconnected. Routing values {1..15} connect to output lines {0..14}. + */ + static int __init map_interrupts(struct device_node *node, struct irq_domain *domain) + { +@@ -134,7 +135,7 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *do + of_node_put(cpu_ictl); + + cpu_int = be32_to_cpup(imap + 2); +- if (cpu_int > 7) ++ if (cpu_int > 7 || cpu_int < 2) + return -EINVAL; + + if (!(mips_irqs_set & BIT(cpu_int))) { +@@ -143,7 +144,8 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *do + mips_irqs_set |= BIT(cpu_int); + } + +- regs[(soc_int * 4) / 32] |= cpu_int << (soc_int * 4) % 32; ++ /* Use routing values (1..6) for CPU interrupts (2..7) */ ++ regs[(soc_int * 4) / 32] |= (cpu_int - 1) << (soc_int * 4) % 32; + imap += 3; + } + +-- +2.34.1 + diff --git a/queue-5.15/irqchip-realtek-rtl-map-control-data-to-virq.patch b/queue-5.15/irqchip-realtek-rtl-map-control-data-to-virq.patch new file mode 100644 index 00000000000..2996e237e7a --- /dev/null +++ b/queue-5.15/irqchip-realtek-rtl-map-control-data-to-virq.patch @@ -0,0 +1,39 @@ +From e4e3c93ff8b4d8be627e0d888ee972fcfcf418c5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 9 Jan 2022 15:54:32 +0100 +Subject: irqchip/realtek-rtl: Map control data to virq + +From: Sander Vanheule + +[ Upstream commit 291e79c7e2eb6fdc016453597b78482e06199d0f ] + +The driver assigned the irqchip and irq handler to the hardware irq, +instead of the virq. This is incorrect, and only worked because these +irq numbers happened to be the same on the devices used for testing the +original driver. + +Fixes: 9f3a0f34b84a ("irqchip: Add support for Realtek RTL838x/RTL839x interrupt controller") +Signed-off-by: Sander Vanheule +Signed-off-by: Marc Zyngier +Link: https://lore.kernel.org/r/4b4936606480265db47df152f00bc2ed46340599.1641739718.git.sander@svanheule.net +Signed-off-by: Sasha Levin +--- + drivers/irqchip/irq-realtek-rtl.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/irqchip/irq-realtek-rtl.c b/drivers/irqchip/irq-realtek-rtl.c +index fd9f275592d29..d6788dd93c7bb 100644 +--- a/drivers/irqchip/irq-realtek-rtl.c ++++ b/drivers/irqchip/irq-realtek-rtl.c +@@ -62,7 +62,7 @@ static struct irq_chip realtek_ictl_irq = { + + static int intc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) + { +- irq_set_chip_and_handler(hw, &realtek_ictl_irq, handle_level_irq); ++ irq_set_chip_and_handler(irq, &realtek_ictl_irq, handle_level_irq); + + return 0; + } +-- +2.34.1 + diff --git a/queue-5.15/perf-core-fix-cgroup-event-list-management.patch b/queue-5.15/perf-core-fix-cgroup-event-list-management.patch new file mode 100644 index 00000000000..5f7ecc0b5ac --- /dev/null +++ b/queue-5.15/perf-core-fix-cgroup-event-list-management.patch @@ -0,0 +1,77 @@ +From fc22bcd303c65f86197e0a71c67670b6e0547a1e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 24 Jan 2022 11:58:08 -0800 +Subject: perf/core: Fix cgroup event list management + +From: Namhyung Kim + +[ Upstream commit c5de60cd622a2607c043ba65e25a6e9998a369f9 ] + +The active cgroup events are managed in the per-cpu cgrp_cpuctx_list. +This list is only accessed from current cpu and not protected by any +locks. But from the commit ef54c1a476ae ("perf: Rework +perf_event_exit_event()"), it's possible to access (actually modify) +the list from another cpu. + +In the perf_remove_from_context(), it can remove an event from the +context without an IPI when the context is not active. This is not +safe with cgroup events which can have some active events in the +context even if ctx->is_active is 0 at the moment. The target cpu +might be in the middle of list iteration at the same time. + +If the event is enabled when it's about to be closed, it might call +perf_cgroup_event_disable() and list_del() with the cgrp_cpuctx_list +on a different cpu. + +This resulted in a crash due to an invalid list pointer access during +the cgroup list traversal on the cpu which the event belongs to. + +Let's fallback to IPI to access the cgrp_cpuctx_list from that cpu. +Similarly, perf_install_in_context() should use IPI for the cgroup +events too. + +Fixes: ef54c1a476ae ("perf: Rework perf_event_exit_event()") +Signed-off-by: Namhyung Kim +Signed-off-by: Peter Zijlstra (Intel) +Link: https://lkml.kernel.org/r/20220124195808.2252071-1-namhyung@kernel.org +Signed-off-by: Sasha Levin +--- + kernel/events/core.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/kernel/events/core.c b/kernel/events/core.c +index 0153f8f972834..c7581e3fb8ab1 100644 +--- a/kernel/events/core.c ++++ b/kernel/events/core.c +@@ -2458,7 +2458,11 @@ static void perf_remove_from_context(struct perf_event *event, unsigned long fla + * event_function_call() user. + */ + raw_spin_lock_irq(&ctx->lock); +- if (!ctx->is_active) { ++ /* ++ * Cgroup events are per-cpu events, and must IPI because of ++ * cgrp_cpuctx_list. ++ */ ++ if (!ctx->is_active && !is_cgroup_event(event)) { + __perf_remove_from_context(event, __get_cpu_context(ctx), + ctx, (void *)flags); + raw_spin_unlock_irq(&ctx->lock); +@@ -2891,11 +2895,14 @@ perf_install_in_context(struct perf_event_context *ctx, + * perf_event_attr::disabled events will not run and can be initialized + * without IPI. Except when this is the first event for the context, in + * that case we need the magic of the IPI to set ctx->is_active. ++ * Similarly, cgroup events for the context also needs the IPI to ++ * manipulate the cgrp_cpuctx_list. + * + * The IOC_ENABLE that is sure to follow the creation of a disabled + * event will issue the IPI and reprogram the hardware. + */ +- if (__perf_effective_state(event) == PERF_EVENT_STATE_OFF && ctx->nr_events) { ++ if (__perf_effective_state(event) == PERF_EVENT_STATE_OFF && ++ ctx->nr_events && !is_cgroup_event(event)) { + raw_spin_lock_irq(&ctx->lock); + if (ctx->task == TASK_TOMBSTONE) { + raw_spin_unlock_irq(&ctx->lock); +-- +2.34.1 + diff --git a/queue-5.15/psi-fix-defined-but-not-used-warnings-when-config_pr.patch b/queue-5.15/psi-fix-defined-but-not-used-warnings-when-config_pr.patch new file mode 100644 index 00000000000..01d335ac853 --- /dev/null +++ b/queue-5.15/psi-fix-defined-but-not-used-warnings-when-config_pr.patch @@ -0,0 +1,141 @@ +From dc5538a89c0e60f1b8bdd328fbde5cd083e4faf1 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 29 Jan 2022 13:41:20 -0800 +Subject: psi: fix "defined but not used" warnings when CONFIG_PROC_FS=n + +From: Suren Baghdasaryan + +[ Upstream commit 44585f7bc0cb01095bc2ad4258049c02bbad21ef ] + +When CONFIG_PROC_FS is disabled psi code generates the following +warnings: + + kernel/sched/psi.c:1364:30: warning: 'psi_cpu_proc_ops' defined but not used [-Wunused-const-variable=] + 1364 | static const struct proc_ops psi_cpu_proc_ops = { + | ^~~~~~~~~~~~~~~~ + kernel/sched/psi.c:1355:30: warning: 'psi_memory_proc_ops' defined but not used [-Wunused-const-variable=] + 1355 | static const struct proc_ops psi_memory_proc_ops = { + | ^~~~~~~~~~~~~~~~~~~ + kernel/sched/psi.c:1346:30: warning: 'psi_io_proc_ops' defined but not used [-Wunused-const-variable=] + 1346 | static const struct proc_ops psi_io_proc_ops = { + | ^~~~~~~~~~~~~~~ + +Make definitions of these structures and related functions conditional +on CONFIG_PROC_FS config. + +Link: https://lkml.kernel.org/r/20220119223940.787748-3-surenb@google.com +Fixes: 0e94682b73bf ("psi: introduce psi monitor") +Signed-off-by: Suren Baghdasaryan +Reported-by: kernel test robot +Acked-by: Johannes Weiner +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + kernel/sched/psi.c | 79 ++++++++++++++++++++++++---------------------- + 1 file changed, 41 insertions(+), 38 deletions(-) + +diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c +index ab460f8b77d13..422f3b0445cf1 100644 +--- a/kernel/sched/psi.c ++++ b/kernel/sched/psi.c +@@ -1082,44 +1082,6 @@ int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res) + return 0; + } + +-static int psi_io_show(struct seq_file *m, void *v) +-{ +- return psi_show(m, &psi_system, PSI_IO); +-} +- +-static int psi_memory_show(struct seq_file *m, void *v) +-{ +- return psi_show(m, &psi_system, PSI_MEM); +-} +- +-static int psi_cpu_show(struct seq_file *m, void *v) +-{ +- return psi_show(m, &psi_system, PSI_CPU); +-} +- +-static int psi_open(struct file *file, int (*psi_show)(struct seq_file *, void *)) +-{ +- if (file->f_mode & FMODE_WRITE && !capable(CAP_SYS_RESOURCE)) +- return -EPERM; +- +- return single_open(file, psi_show, NULL); +-} +- +-static int psi_io_open(struct inode *inode, struct file *file) +-{ +- return psi_open(file, psi_io_show); +-} +- +-static int psi_memory_open(struct inode *inode, struct file *file) +-{ +- return psi_open(file, psi_memory_show); +-} +- +-static int psi_cpu_open(struct inode *inode, struct file *file) +-{ +- return psi_open(file, psi_cpu_show); +-} +- + struct psi_trigger *psi_trigger_create(struct psi_group *group, + char *buf, size_t nbytes, enum psi_res res) + { +@@ -1278,6 +1240,45 @@ __poll_t psi_trigger_poll(void **trigger_ptr, + return ret; + } + ++#ifdef CONFIG_PROC_FS ++static int psi_io_show(struct seq_file *m, void *v) ++{ ++ return psi_show(m, &psi_system, PSI_IO); ++} ++ ++static int psi_memory_show(struct seq_file *m, void *v) ++{ ++ return psi_show(m, &psi_system, PSI_MEM); ++} ++ ++static int psi_cpu_show(struct seq_file *m, void *v) ++{ ++ return psi_show(m, &psi_system, PSI_CPU); ++} ++ ++static int psi_open(struct file *file, int (*psi_show)(struct seq_file *, void *)) ++{ ++ if (file->f_mode & FMODE_WRITE && !capable(CAP_SYS_RESOURCE)) ++ return -EPERM; ++ ++ return single_open(file, psi_show, NULL); ++} ++ ++static int psi_io_open(struct inode *inode, struct file *file) ++{ ++ return psi_open(file, psi_io_show); ++} ++ ++static int psi_memory_open(struct inode *inode, struct file *file) ++{ ++ return psi_open(file, psi_memory_show); ++} ++ ++static int psi_cpu_open(struct inode *inode, struct file *file) ++{ ++ return psi_open(file, psi_cpu_show); ++} ++ + static ssize_t psi_write(struct file *file, const char __user *user_buf, + size_t nbytes, enum psi_res res) + { +@@ -1392,3 +1393,5 @@ static int __init psi_proc_init(void) + return 0; + } + module_init(psi_proc_init); ++ ++#endif /* CONFIG_PROC_FS */ +-- +2.34.1 + diff --git a/queue-5.15/psi-fix-no-previous-prototype-warnings-when-config_c.patch b/queue-5.15/psi-fix-no-previous-prototype-warnings-when-config_c.patch new file mode 100644 index 00000000000..efb052214e6 --- /dev/null +++ b/queue-5.15/psi-fix-no-previous-prototype-warnings-when-config_c.patch @@ -0,0 +1,68 @@ +From a596b52103fd79544a5df125e77ec7f36d866052 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 29 Jan 2022 13:41:17 -0800 +Subject: psi: fix "no previous prototype" warnings when CONFIG_CGROUPS=n + +From: Suren Baghdasaryan + +[ Upstream commit 51e50fbd3efc6064c30ed73a5e009018b36e290a ] + +When CONFIG_CGROUPS is disabled psi code generates the following +warnings: + + kernel/sched/psi.c:1112:21: warning: no previous prototype for 'psi_trigger_create' [-Wmissing-prototypes] + 1112 | struct psi_trigger *psi_trigger_create(struct psi_group *group, + | ^~~~~~~~~~~~~~~~~~ + kernel/sched/psi.c:1182:6: warning: no previous prototype for 'psi_trigger_destroy' [-Wmissing-prototypes] + 1182 | void psi_trigger_destroy(struct psi_trigger *t) + | ^~~~~~~~~~~~~~~~~~~ + kernel/sched/psi.c:1249:10: warning: no previous prototype for 'psi_trigger_poll' [-Wmissing-prototypes] + 1249 | __poll_t psi_trigger_poll(void **trigger_ptr, + | ^~~~~~~~~~~~~~~~ + +Change the declarations of these functions in the header to provide the +prototypes even when they are unused. + +Link: https://lkml.kernel.org/r/20220119223940.787748-2-surenb@google.com +Fixes: 0e94682b73bf ("psi: introduce psi monitor") +Signed-off-by: Suren Baghdasaryan +Reported-by: kernel test robot +Acked-by: Johannes Weiner +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + include/linux/psi.h | 11 +++++------ + 1 file changed, 5 insertions(+), 6 deletions(-) + +diff --git a/include/linux/psi.h b/include/linux/psi.h +index 74f7148dfb9f4..57823b30c2d3d 100644 +--- a/include/linux/psi.h ++++ b/include/linux/psi.h +@@ -24,18 +24,17 @@ void psi_memstall_enter(unsigned long *flags); + void psi_memstall_leave(unsigned long *flags); + + int psi_show(struct seq_file *s, struct psi_group *group, enum psi_res res); +- +-#ifdef CONFIG_CGROUPS +-int psi_cgroup_alloc(struct cgroup *cgrp); +-void psi_cgroup_free(struct cgroup *cgrp); +-void cgroup_move_task(struct task_struct *p, struct css_set *to); +- + struct psi_trigger *psi_trigger_create(struct psi_group *group, + char *buf, size_t nbytes, enum psi_res res); + void psi_trigger_destroy(struct psi_trigger *t); + + __poll_t psi_trigger_poll(void **trigger_ptr, struct file *file, + poll_table *wait); ++ ++#ifdef CONFIG_CGROUPS ++int psi_cgroup_alloc(struct cgroup *cgrp); ++void psi_cgroup_free(struct cgroup *cgrp); ++void cgroup_move_task(struct task_struct *p, struct css_set *to); + #endif + + #else /* CONFIG_PSI */ +-- +2.34.1 + diff --git a/queue-5.15/series b/queue-5.15/series index 69fba433e67..cd71011ab7e 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -159,3 +159,8 @@ ipv4-tcp-send-zero-ipid-in-synack-messages.patch ipv4-remove-sparse-error-in-ip_neigh_gw4.patch net-bridge-vlan-fix-memory-leak-in-__allowed_ingress.patch bluetooth-refactor-malicious-adv-data-check.patch +irqchip-realtek-rtl-map-control-data-to-virq.patch +irqchip-realtek-rtl-fix-off-by-one-in-routing.patch +perf-core-fix-cgroup-event-list-management.patch +psi-fix-no-previous-prototype-warnings-when-config_c.patch +psi-fix-defined-but-not-used-warnings-when-config_pr.patch -- 2.47.3