From 314e86225918b9da8c394cc1f96140d28d4dcc47 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sat, 5 Dec 2020 17:19:18 +0100 Subject: [PATCH 1/9] genirq, i2c: Provide and use generic_dispatch_irq() Carlos reported that on his system booting with 'threadirqs' on the command line result in the following warning: irq 31 handler irq_default_primary_handler+0x0/0x10 enabled interrupts WARNING: CPU: 2 PID: 989 at kernel/irq/handle.c:153 __handle_irq_event_percpu+0x19f/0x1b0 The reason is in the i2c stack: i801_isr() i801_host_notify_isr() i2c_handle_smbus_host_notify() generic_handle_irq() and that explodes with forced interrupt threading because it's called with interrupts enabled. It would be possible to set IRQF_NO_THREAD on the i801 interrupt to exclude it from force threading, but that would break on RT and require a larger update. It's also unclear whether there are other drivers which can reach that code path via i2c_slave_host_notify_cb(). As there are enough i2c drivers which use threaded interrupt handlers by default it seems not completely impossible that this can happen even without force threaded interrupts. For a quick fix provide a wrapper around generic_handle_irq() which has a local_irq_save/restore() around the invocation and use it in the i2c code. Reported-by: Carlos Jimenez Signed-off-by: Thomas Gleixner Link: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1873673 Link: https://bugzilla.kernel.org/show_bug.cgi?id=202453 Link: https://lore.kernel.org/lkml/20201204201930.vtvitsq6xcftjj3o@spock.localdomain/ Signed-off-by: Oleksandr Natalenko --- drivers/i2c/i2c-core-base.c | 2 +- include/linux/irqdesc.h | 1 + kernel/irq/irqdesc.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 54964fbe3..310d0ec2d 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1517,7 +1517,7 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr) if (irq <= 0) return -ENXIO; - generic_handle_irq(irq); + generic_dispatch_irq(irq); return 0; } diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index 59aea3978..f10ab7332 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -160,6 +160,7 @@ static inline void generic_handle_irq_desc(struct irq_desc *desc) int handle_irq_desc(struct irq_desc *desc); int generic_handle_irq(unsigned int irq); +int generic_dispatch_irq(unsigned int irq); #ifdef CONFIG_IRQ_DOMAIN /* diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 4e3c29bb6..fa146ad93 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -676,6 +676,27 @@ int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq) } EXPORT_SYMBOL_GPL(generic_handle_domain_irq); +/** + * generic_dispatch_irq - Dispatch an interrupt from an interrupt handler + * @irq: The irq number to handle + * + * A wrapper around generic_handle_irq() which ensures that interrupts are + * disabled when the primary handler of the dispatched irq is invoked. + * This is useful for interrupt handlers with dispatching to be safe for + * the forced threaded case. + */ +int generic_dispatch_irq(unsigned int irq) +{ + unsigned long flags; + int ret; + + local_irq_save(flags); + ret = generic_handle_irq(irq); + local_irq_restore(flags); + return ret; +} +EXPORT_SYMBOL_GPL(generic_dispatch_irq); + #ifdef CONFIG_HANDLE_DOMAIN_IRQ /** * handle_domain_irq - Invoke the handler for a HW irq belonging to a domain, -- 2.33.1.711.g9d530dc002 From 0ebb0592320a42c310f2b340ebef59252abb9696 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Wed, 18 Aug 2021 17:43:05 -0700 Subject: [PATCH 2/9] x86: ACPI: cstate: Optimize C3 entry on AMD CPUs AMD CPU which support C3 shares cache. Its not necessary to flush the caches in software before entering C3. This will cause performance drop for the cores which share some caches. ARB_DIS is not used with current AMD C state implementation. So set related flags correctly. Signed-off-by: Deepak Sharma --- arch/x86/kernel/acpi/cstate.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index 7de599eba..62a5986d6 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -79,6 +79,21 @@ void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags, */ flags->bm_control = 0; } + if (c->x86_vendor == X86_VENDOR_AMD) { + /* + * For all AMD CPUs that support C3, caches should not be + * flushed by software while entering C3 type state. Set + * bm->check to 1 so that kernel doesn't need to execute + * cache flush operation. + */ + flags->bm_check = 1; + /* + * In current AMD C state implementation ARB_DIS is no longer + * used. So set bm_control to zero to indicate ARB_DIS is not + * required while entering C3 type state. + */ + flags->bm_control = 0; + } } EXPORT_SYMBOL(acpi_processor_power_init_bm_check); -- 2.33.1.711.g9d530dc002 From 4ce584c7394b1f3c70c4f193f95c2a29f00dc71d Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Tue, 13 Jul 2021 10:27:20 +0200 Subject: [PATCH 3/9] net: replace WARN_ONCE with pr_warn_once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following warning: ``` igb_poll+0x0/0x13f0 [igb] exceeded budget in poll WARNING: CPU: 1 PID: 43231 at net/core/netpoll.c:154 netpoll_poll_dev+0x18a/0x1a0 … Call Trace: netpoll_send_skb+0x1a0/0x260 write_msg+0xd8/0xf0 [netconsole] console_unlock+0x3f2/0x710 suspend_devices_and_enter+0x2a9/0x7f0 pm_suspend.cold+0x321/0x36c state_store+0x96/0x130 kernfs_fop_write_iter+0x11c/0x1b0 new_sync_write+0x15b/0x1f0 vfs_write+0x1b5/0x2b0 __x64_sys_write+0x6c/0xf0 ``` and turn it into a simple message. This happens on resume from suspend with netconsole enabled. Link: https://lists.osuosl.org/pipermail/intel-wired-lan/Week-of-Mon-20210503/024220.html Link: https://bugzilla.kernel.org/show_bug.cgi?id=212573 Signed-off-by: Oleksandr Natalenko --- net/core/netpoll.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index edfc0f801..7aaaeec08 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -152,7 +152,8 @@ static void poll_one_napi(struct napi_struct *napi) * indicate that we are clearing the Tx path only. */ work = napi->poll(napi, 0); - WARN_ONCE(work, "%pS exceeded budget in poll\n", napi->poll); + if (unlikely(work)) + pr_warn_once("%pS exceeded budget in poll\n", napi->poll); trace_napi_poll(napi, work, 0); clear_bit(NAPI_STATE_NPSVC, &napi->state); -- 2.33.1.711.g9d530dc002 From ae68617f576a45016978d2b7216010059158ca15 Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Fri, 8 Oct 2021 09:26:24 +0200 Subject: [PATCH 4/9] mac80211: minstrel_ht: force ampdu_len to be > 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following crash: ``` divide error: 0000 [#1] PREEMPT SMP PTI CPU: 2 PID: 683 Comm: mt76-tx phy0 Tainted: G C 5.12.0-pf4 #1 Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./J3710-ITX, BIOS P1.50 04/16/2018 RIP: 0010:minstrel_ht_get_tp_avg+0xb1/0x100 [mac80211] … Call Trace: minstrel_ht_update_stats+0x1fe/0x1320 [mac80211] minstrel_ht_tx_status+0x67f/0x710 [mac80211] rate_control_tx_status+0x6e/0xb0 [mac80211] ieee80211_tx_status_ext+0x22e/0xb00 [mac80211] ieee80211_tx_status+0x7d/0xa0 [mac80211] mt76_tx_status_unlock+0x83/0xa0 [mt76] mt76x02_send_tx_status+0x1b7/0x400 [mt76x02_lib] mt76x02_tx_worker+0x8f/0xd0 [mt76x02_lib] __mt76_worker_fn+0x78/0xb0 [mt76] kthread+0x183/0x1b0 ret_from_fork+0x22/0x30 ``` Link: https://lore.kernel.org/lkml/20210529165728.bskaozwtmwxnvucx@spock.localdomain/ Signed-off-by: Oleksandr Natalenko --- net/mac80211/rc80211_minstrel_ht.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c index 72b44d4c4..f60003530 100644 --- a/net/mac80211/rc80211_minstrel_ht.c +++ b/net/mac80211/rc80211_minstrel_ht.c @@ -440,8 +440,13 @@ minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate, if (minstrel_ht_is_legacy_group(group)) overhead = mi->overhead_legacy; - else + else { ampdu_len = minstrel_ht_avg_ampdu_len(mi); + if (unlikely(!ampdu_len)) { + pr_err_once("%s: ampdu_len == 0!\n", __func__); + ampdu_len = 1; + } + } nsecs = 1000 * overhead / ampdu_len; nsecs += minstrel_mcs_groups[group].duration[rate] << -- 2.33.1.711.g9d530dc002 From 653828b38d2385ca1d3b11b5e3a379f02813a946 Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Fri, 8 Oct 2021 09:25:03 +0200 Subject: [PATCH 5/9] mac80211: rate: replace WARN_ON with pr_warn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following warning: ``` WARNING: CPU: 0 PID: 680 at net/mac80211/rate.c:671 ieee80211_get_tx_rates+0xa9c/0xb60 [mac80211] … Call Trace: ath_tx_start+0x122/0x2d0 [ath9k] ath9k_tx+0xd5/0x220 [ath9k] __ieee80211_tx+0x2ea/0x3b0 [mac80211] ieee80211_tx+0x11a/0x150 [mac80211] ieee80211_tx_pending+0xc2/0x2f0 [mac80211] tasklet_action_common.constprop.0+0x137/0x190 __do_softirq+0xd1/0x2c6 do_softirq+0x79/0xa0 __local_bh_enable_ip+0x57/0x70 irq_forced_thread_fn+0x7b/0x90 irq_thread+0x203/0x2b0 kthread+0x1b1/0x1e0 ret_from_fork+0x22/0x30 ``` and turn it into a simple message. This happens with the following hardware: ``` 02:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01) ``` running in AP mode using hostapd. Signed-off-by: Oleksandr Natalenko --- net/mac80211/rate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index 8c6416129..6d36c5eff 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c @@ -664,7 +664,9 @@ static void rate_fixup_ratelist(struct ieee80211_vif *vif, * needs to be fixed. */ if (rates[i].flags & IEEE80211_TX_RC_MCS) { - WARN_ON(rates[i].idx > 76); + if (unlikely(rates[i].idx > 76)) + pr_warn("%s: rates[%d].idx == %d > 76\n", + __func__, i, rates[i].idx); if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) && info->control.use_cts_prot) -- 2.33.1.711.g9d530dc002 From e87eba78dd7bf7d8563a7e1e983c6f00a7f30eaf Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Fri, 8 Oct 2021 09:21:54 +0200 Subject: [PATCH 6/9] mac80211: airtime: replace WARN_ON_ONCE with pr_warn_once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following warning: ``` WARNING: CPU: 3 PID: 684 at net/mac80211/airtime.c:456 ieee80211_calc_rx_airtime+0x12d/0x1d0 [mac80211] … Call Trace: ieee80211_calc_tx_airtime+0x10c/0x1b0 [mac80211] mt76x02_send_tx_status+0x1de/0x400 [mt76x02_lib] mt76x02_tx_worker+0x8f/0xd0 [mt76x02_lib] __mt76_worker_fn+0x4c/0x80 [mt76] kthread+0x1b1/0x1e0 ret_from_fork+0x22/0x30 ``` and turn it into a simple message. This happens with the following hardware: ``` 01:00.0 Network controller: MEDIATEK Corp. MT7612E 802.11acbgn PCI Express Wireless Network Adapter ``` running in AP mode using hostapd. Signed-off-by: Oleksandr Natalenko --- net/mac80211/airtime.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c index 26d2f8ba7..03fb8070b 100644 --- a/net/mac80211/airtime.c +++ b/net/mac80211/airtime.c @@ -453,9 +453,17 @@ static u32 ieee80211_get_rate_duration(struct ieee80211_hw *hw, return 0; } - if (WARN_ON_ONCE((status->encoding != RX_ENC_HE && streams > 4) || - (status->encoding == RX_ENC_HE && streams > 8))) + if (unlikely(status->encoding != RX_ENC_HE && streams > 4)) { + pr_warn_once("%s: status->encoding != RX_ENC_HE (%u != %d) && streams > 4 (%d > 4)\n", + __func__, status->encoding, RX_ENC_HE, streams); return 0; + } + + if (unlikely(status->encoding == RX_ENC_HE && streams > 8)) { + pr_warn_once("%s: status->encoding == RX_ENC_HE (%u == %d) && streams > 8 (%d > 8)\n", + __func__, status->encoding, RX_ENC_HE, streams); + return 0; + } duration = airtime_mcs_groups[group].duration[idx]; duration <<= airtime_mcs_groups[group].shift; -- 2.33.1.711.g9d530dc002 From 798db21cdd3de05ce5343aaf66bd0202ac4fdef0 Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Fri, 8 Oct 2021 09:31:15 +0200 Subject: [PATCH 7/9] mac80211: rate: replace WARN_ON_ONCE with pr_warn_once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following warning: ``` WARNING: CPU: 2 PID: 656 at net/mac80211/rate.c:693 ieee80211_get_tx_rates+0xa3b/0xb50 [mac80211] … Call Trace: ath_tx_start+0x122/0x2d0 [ath9k] ath9k_tx+0xd5/0x220 [ath9k] __ieee80211_tx+0x2ea/0x3b0 [mac80211] ieee80211_tx+0x11a/0x150 [mac80211] ieee80211_tx_pending+0xc2/0x2f0 [mac80211] tasklet_action_common.constprop.0+0x137/0x190 __do_softirq+0xd1/0x2c6 do_softirq+0x79/0xa0 __local_bh_enable_ip+0x57/0x70 irq_forced_thread_fn+0x7b/0x90 irq_thread+0x203/0x2b0 kthread+0x1b1/0x1e0 ret_from_fork+0x22/0x30 ``` and turn it into a simple message. This happens with the following hardware: ``` 02:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01) ``` running in AP mode using hostapd. Signed-off-by: Oleksandr Natalenko --- net/mac80211/rate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index 6d36c5eff..8a732b013 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c @@ -687,7 +687,9 @@ static void rate_fixup_ratelist(struct ieee80211_vif *vif, } /* RC is busted */ - if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) { + if (unlikely(rates[i].idx >= sband->n_bitrates)) { + pr_warn_once("%s: rates[%d].idx == %d >= sband->n_bitrates == %d\n", + __func__, i, rates[i].idx, sband->n_bitrates); rates[i].idx = -1; continue; } -- 2.33.1.711.g9d530dc002 From 7d39678b340fd76455f52cf924c89dcbf9052b3f Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Fri, 8 Oct 2021 09:23:59 +0200 Subject: [PATCH 8/9] mac80211: rate: replace WARN_ON with pr_warn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack. Work around the following warning: ``` WARNING: CPU: 2 PID: 656 at net/mac80211/rate.c:682 ieee80211_get_tx_rates+0x604/0xb50 [mac80211] … Call Trace: ath_tx_start+0x122/0x2d0 [ath9k] ath9k_tx+0xd5/0x220 [ath9k] __ieee80211_tx+0x2ea/0x3b0 [mac80211] ieee80211_tx+0x11a/0x150 [mac80211] ieee80211_tx_pending+0xc2/0x2f0 [mac80211] tasklet_action_common.constprop.0+0x137/0x190 __do_softirq+0xd1/0x2c6 do_softirq+0x79/0xa0 __local_bh_enable_ip+0x57/0x70 irq_forced_thread_fn+0x7b/0x90 irq_thread+0x203/0x2b0 kthread+0x1b1/0x1e0 ret_from_fork+0x22/0x30 ``` and turn it into a simple message. This happens with the following hardware: ``` 02:00.0 Network controller: Qualcomm Atheros AR9462 Wireless Network Adapter (rev 01) ``` running in AP mode using hostapd. Signed-off-by: Oleksandr Natalenko --- net/mac80211/rate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c index 8a732b013..810ea5cd6 100644 --- a/net/mac80211/rate.c +++ b/net/mac80211/rate.c @@ -676,7 +676,9 @@ static void rate_fixup_ratelist(struct ieee80211_vif *vif, } if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) { - WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9); + if (unlikely(ieee80211_rate_get_vht_mcs(&rates[i]) > 9)) + pr_warn("%s: ieee80211_rate_get_vht_mcs(&rates[%d]) == %d > 9\n", + __func__, i, ieee80211_rate_get_vht_mcs(&rates[i])); continue; } -- 2.33.1.711.g9d530dc002 From e4c4cc33a8ffe845e62041a5dab2db32cb68dd70 Mon Sep 17 00:00:00 2001 From: Oleksandr Natalenko Date: Thu, 25 Nov 2021 09:26:50 +0100 Subject: [PATCH 9/9] Revert "net: replace WARN_ONCE with pr_warn_once" This reverts commit 27ee8dfd787409588f0a6c4ef1019fd41bbf3605. --- net/core/netpoll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 7aaaeec08..edfc0f801 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -152,8 +152,7 @@ static void poll_one_napi(struct napi_struct *napi) * indicate that we are clearing the Tx path only. */ work = napi->poll(napi, 0); - if (unlikely(work)) - pr_warn_once("%pS exceeded budget in poll\n", napi->poll); + WARN_ONCE(work, "%pS exceeded budget in poll\n", napi->poll); trace_napi_poll(napi, work, 0); clear_bit(NAPI_STATE_NPSVC, &napi->state); -- 2.33.1.711.g9d530dc002