From b605b094e971affa5409ee5ca0438b7536e6b430 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 12 Aug 2024 14:09:52 +0200 Subject: [PATCH] 5.4-stable patches added patches: genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch tracing-fix-overflow-in-get_free_elt.patch x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch --- ...ller-provided-affinity-in-alloc_desc.patch | 43 ++++++++++++ ...r-fix-constant_charge_voltage-writes.patch | 39 +++++++++++ ...-constant_charge_voltage-writes-down.patch | 56 ++++++++++++++++ queue-5.4/series | 5 ++ ...tracing-fix-overflow-in-get_free_elt.patch | 65 +++++++++++++++++++ ...fixed-mtrrs-exist-before-saving-them.patch | 44 +++++++++++++ 6 files changed, 252 insertions(+) create mode 100644 queue-5.4/genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch create mode 100644 queue-5.4/power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch create mode 100644 queue-5.4/power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch create mode 100644 queue-5.4/tracing-fix-overflow-in-get_free_elt.patch create mode 100644 queue-5.4/x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch diff --git a/queue-5.4/genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch b/queue-5.4/genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch new file mode 100644 index 00000000000..5f17d9e663c --- /dev/null +++ b/queue-5.4/genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch @@ -0,0 +1,43 @@ +From edbbaae42a56f9a2b39c52ef2504dfb3fb0a7858 Mon Sep 17 00:00:00 2001 +From: Shay Drory +Date: Tue, 6 Aug 2024 10:20:44 +0300 +Subject: genirq/irqdesc: Honor caller provided affinity in alloc_desc() + +From: Shay Drory + +commit edbbaae42a56f9a2b39c52ef2504dfb3fb0a7858 upstream. + +Currently, whenever a caller is providing an affinity hint for an +interrupt, the allocation code uses it to calculate the node and copies the +cpumask into irq_desc::affinity. + +If the affinity for the interrupt is not marked 'managed' then the startup +of the interrupt ignores irq_desc::affinity and uses the system default +affinity mask. + +Prevent this by setting the IRQD_AFFINITY_SET flag for the interrupt in the +allocator, which causes irq_setup_affinity() to use irq_desc::affinity on +interrupt startup if the mask contains an online CPU. + +[ tglx: Massaged changelog ] + +Fixes: 45ddcecbfa94 ("genirq: Use affinity hint in irqdesc allocation") +Signed-off-by: Shay Drory +Signed-off-by: Thomas Gleixner +Cc: +Link: https://lore.kernel.org/all/20240806072044.837827-1-shayd@nvidia.com +Signed-off-by: Greg Kroah-Hartman +--- + kernel/irq/irqdesc.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/kernel/irq/irqdesc.c ++++ b/kernel/irq/irqdesc.c +@@ -491,6 +491,7 @@ static int alloc_descs(unsigned int star + flags = IRQD_AFFINITY_MANAGED | + IRQD_MANAGED_SHUTDOWN; + } ++ flags |= IRQD_AFFINITY_SET; + mask = &affinity->mask; + node = cpu_to_node(cpumask_first(mask)); + affinity++; diff --git a/queue-5.4/power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch b/queue-5.4/power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch new file mode 100644 index 00000000000..222280ceec2 --- /dev/null +++ b/queue-5.4/power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch @@ -0,0 +1,39 @@ +From b34ce4a59cfe9cd0d6f870e6408e8ec88a964585 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 17 Jul 2024 22:03:32 +0200 +Subject: power: supply: axp288_charger: Fix constant_charge_voltage writes + +From: Hans de Goede + +commit b34ce4a59cfe9cd0d6f870e6408e8ec88a964585 upstream. + +info->max_cv is in millivolts, divide the microvolt value being written +to constant_charge_voltage by 1000 *before* clamping it to info->max_cv. + +Before this fix the code always tried to set constant_charge_voltage +to max_cv / 1000 = 4 millivolt, which ends up in setting it to 4.1V +which is the lowest supported value. + +Fixes: 843735b788a4 ("power: axp288_charger: axp288 charger driver") +Cc: stable@vger.kernel.org +Signed-off-by: Hans de Goede +Link: https://lore.kernel.org/r/20240717200333.56669-1-hdegoede@redhat.com +Signed-off-by: Sebastian Reichel +Signed-off-by: Greg Kroah-Hartman +--- + drivers/power/supply/axp288_charger.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/drivers/power/supply/axp288_charger.c ++++ b/drivers/power/supply/axp288_charger.c +@@ -371,8 +371,8 @@ static int axp288_charger_usb_set_proper + dev_warn(&info->pdev->dev, "set charge current failed\n"); + break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: +- scaled_val = min(val->intval, info->max_cv); +- scaled_val = DIV_ROUND_CLOSEST(scaled_val, 1000); ++ scaled_val = DIV_ROUND_CLOSEST(val->intval, 1000); ++ scaled_val = min(scaled_val, info->max_cv); + ret = axp288_charger_set_cv(info, scaled_val); + if (ret < 0) + dev_warn(&info->pdev->dev, "set charge voltage failed\n"); diff --git a/queue-5.4/power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch b/queue-5.4/power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch new file mode 100644 index 00000000000..8a7cb134ff5 --- /dev/null +++ b/queue-5.4/power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch @@ -0,0 +1,56 @@ +From 81af7f2342d162e24ac820c10e68684d9f927663 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 17 Jul 2024 22:03:33 +0200 +Subject: power: supply: axp288_charger: Round constant_charge_voltage writes down + +From: Hans de Goede + +commit 81af7f2342d162e24ac820c10e68684d9f927663 upstream. + +Round constant_charge_voltage writes down to the first supported lower +value, rather then rounding them up to the first supported higher value. + +This fixes e.g. writing 4250000 resulting in a value of 4350000 which +might be dangerous, instead writing 4250000 will now result in a safe +4200000 value. + +Fixes: 843735b788a4 ("power: axp288_charger: axp288 charger driver") +Cc: stable@vger.kernel.org +Signed-off-by: Hans de Goede +Link: https://lore.kernel.org/r/20240717200333.56669-2-hdegoede@redhat.com +Signed-off-by: Sebastian Reichel +Signed-off-by: Greg Kroah-Hartman +--- + drivers/power/supply/axp288_charger.c | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +--- a/drivers/power/supply/axp288_charger.c ++++ b/drivers/power/supply/axp288_charger.c +@@ -168,18 +168,18 @@ static inline int axp288_charger_set_cv( + u8 reg_val; + int ret; + +- if (cv <= CV_4100MV) { +- reg_val = CHRG_CCCV_CV_4100MV; +- cv = CV_4100MV; +- } else if (cv <= CV_4150MV) { +- reg_val = CHRG_CCCV_CV_4150MV; +- cv = CV_4150MV; +- } else if (cv <= CV_4200MV) { ++ if (cv >= CV_4350MV) { ++ reg_val = CHRG_CCCV_CV_4350MV; ++ cv = CV_4350MV; ++ } else if (cv >= CV_4200MV) { + reg_val = CHRG_CCCV_CV_4200MV; + cv = CV_4200MV; ++ } else if (cv >= CV_4150MV) { ++ reg_val = CHRG_CCCV_CV_4150MV; ++ cv = CV_4150MV; + } else { +- reg_val = CHRG_CCCV_CV_4350MV; +- cv = CV_4350MV; ++ reg_val = CHRG_CCCV_CV_4100MV; ++ cv = CV_4100MV; + } + + reg_val = reg_val << CHRG_CCCV_CV_BIT_POS; diff --git a/queue-5.4/series b/queue-5.4/series index 65be843d3e1..a03b0121589 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -240,3 +240,8 @@ ntp-safeguard-against-time_constant-overflow.patch scsi-mpt3sas-remove-scsi_dma_map-error-messages.patch scsi-mpt3sas-avoid-iommu-page-faults-on-report-zones.patch serial-core-check-uartclk-for-zero-to-avoid-divide-by-zero.patch +genirq-irqdesc-honor-caller-provided-affinity-in-alloc_desc.patch +power-supply-axp288_charger-fix-constant_charge_voltage-writes.patch +power-supply-axp288_charger-round-constant_charge_voltage-writes-down.patch +tracing-fix-overflow-in-get_free_elt.patch +x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch diff --git a/queue-5.4/tracing-fix-overflow-in-get_free_elt.patch b/queue-5.4/tracing-fix-overflow-in-get_free_elt.patch new file mode 100644 index 00000000000..f2adf30386f --- /dev/null +++ b/queue-5.4/tracing-fix-overflow-in-get_free_elt.patch @@ -0,0 +1,65 @@ +From bcf86c01ca4676316557dd482c8416ece8c2e143 Mon Sep 17 00:00:00 2001 +From: Tze-nan Wu +Date: Mon, 5 Aug 2024 13:59:22 +0800 +Subject: tracing: Fix overflow in get_free_elt() + +From: Tze-nan Wu + +commit bcf86c01ca4676316557dd482c8416ece8c2e143 upstream. + +"tracing_map->next_elt" in get_free_elt() is at risk of overflowing. + +Once it overflows, new elements can still be inserted into the tracing_map +even though the maximum number of elements (`max_elts`) has been reached. +Continuing to insert elements after the overflow could result in the +tracing_map containing "tracing_map->max_size" elements, leaving no empty +entries. +If any attempt is made to insert an element into a full tracing_map using +`__tracing_map_insert()`, it will cause an infinite loop with preemption +disabled, leading to a CPU hang problem. + +Fix this by preventing any further increments to "tracing_map->next_elt" +once it reaches "tracing_map->max_elt". + +Cc: stable@vger.kernel.org +Cc: Masami Hiramatsu +Fixes: 08d43a5fa063e ("tracing: Add lock-free tracing_map") +Co-developed-by: Cheng-Jui Wang +Link: https://lore.kernel.org/20240805055922.6277-1-Tze-nan.Wu@mediatek.com +Signed-off-by: Cheng-Jui Wang +Signed-off-by: Tze-nan Wu +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Greg Kroah-Hartman +--- + kernel/trace/tracing_map.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--- a/kernel/trace/tracing_map.c ++++ b/kernel/trace/tracing_map.c +@@ -454,7 +454,7 @@ static struct tracing_map_elt *get_free_ + struct tracing_map_elt *elt = NULL; + int idx; + +- idx = atomic_inc_return(&map->next_elt); ++ idx = atomic_fetch_add_unless(&map->next_elt, 1, map->max_elts); + if (idx < map->max_elts) { + elt = *(TRACING_MAP_ELT(map->elts, idx)); + if (map->ops && map->ops->elt_init) +@@ -699,7 +699,7 @@ void tracing_map_clear(struct tracing_ma + { + unsigned int i; + +- atomic_set(&map->next_elt, -1); ++ atomic_set(&map->next_elt, 0); + atomic64_set(&map->hits, 0); + atomic64_set(&map->drops, 0); + +@@ -783,7 +783,7 @@ struct tracing_map *tracing_map_create(u + + map->map_bits = map_bits; + map->max_elts = (1 << map_bits); +- atomic_set(&map->next_elt, -1); ++ atomic_set(&map->next_elt, 0); + + map->map_size = (1 << (map_bits + 1)); + map->ops = ops; diff --git a/queue-5.4/x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch b/queue-5.4/x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch new file mode 100644 index 00000000000..30da4db047e --- /dev/null +++ b/queue-5.4/x86-mtrr-check-if-fixed-mtrrs-exist-before-saving-them.patch @@ -0,0 +1,44 @@ +From 919f18f961c03d6694aa726c514184f2311a4614 Mon Sep 17 00:00:00 2001 +From: Andi Kleen +Date: Wed, 7 Aug 2024 17:02:44 -0700 +Subject: x86/mtrr: Check if fixed MTRRs exist before saving them + +From: Andi Kleen + +commit 919f18f961c03d6694aa726c514184f2311a4614 upstream. + +MTRRs have an obsolete fixed variant for fine grained caching control +of the 640K-1MB region that uses separate MSRs. This fixed variant has +a separate capability bit in the MTRR capability MSR. + +So far all x86 CPUs which support MTRR have this separate bit set, so it +went unnoticed that mtrr_save_state() does not check the capability bit +before accessing the fixed MTRR MSRs. + +Though on a CPU that does not support the fixed MTRR capability this +results in a #GP. The #GP itself is harmless because the RDMSR fault is +handled gracefully, but results in a WARN_ON(). + +Add the missing capability check to prevent this. + +Fixes: 2b1f6278d77c ("[PATCH] x86: Save the MTRRs of the BSP before booting an AP") +Signed-off-by: Andi Kleen +Signed-off-by: Thomas Gleixner +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/all/20240808000244.946864-1-ak@linux.intel.com +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kernel/cpu/mtrr/mtrr.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/arch/x86/kernel/cpu/mtrr/mtrr.c ++++ b/arch/x86/kernel/cpu/mtrr/mtrr.c +@@ -817,7 +817,7 @@ void mtrr_save_state(void) + { + int first_cpu; + +- if (!mtrr_enabled()) ++ if (!mtrr_enabled() || !mtrr_state.have_fixed) + return; + + first_cpu = cpumask_first(cpu_online_mask); -- 2.47.3