All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Johannes Berg <johannes.berg@intel.com>,
	Mordechay Goodstein <mordechay.goodstein@intel.com>,
	Luca Coelho <luciano.coelho@intel.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.9 040/105] iwlwifi: pcie: limit memory read spin time
Date: Mon, 14 Dec 2020 18:28:14 +0100	[thread overview]
Message-ID: <20201214172557.208545474@linuxfoundation.org> (raw)
In-Reply-To: <20201214172555.280929671@linuxfoundation.org>

From: Johannes Berg <johannes.berg@intel.com>

[ Upstream commit 04516706bb99889986ddfa3a769ed50d2dc7ac13 ]

When we read device memory, we lock a spinlock, write the address we
want to read from the device and then spin in a loop reading the data
in 32-bit quantities from another register.

As the description makes clear, this is rather inefficient, incurring
a PCIe bus transaction for every read. In a typical device today, we
want to read 786k SMEM if it crashes, leading to 192k register reads.
Occasionally, we've seen the whole loop take over 20 seconds and then
triggering the soft lockup detector.

Clearly, it is unreasonable to spin here for such extended periods of
time.

To fix this, break the loop down into an outer and an inner loop, and
break out of the inner loop if more than half a second elapsed. To
avoid too much overhead, check for that only every 128 reads, though
there's no particular reason for that number. Then, unlock and relock
to obtain NIC access again, reprogram the start address and continue.

This will keep (interrupt) latencies on the CPU down to a reasonable
time.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Mordechay Goodstein <mordechay.goodstein@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/iwlwifi.20201022165103.45878a7e49aa.I3b9b9c5a10002915072312ce75b68ed5b3dc6e14@changeid
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 .../net/wireless/intel/iwlwifi/pcie/trans.c   | 36 ++++++++++++++-----
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
index e5160d6208688..6393e895f95c6 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
@@ -2155,18 +2155,36 @@ static int iwl_trans_pcie_read_mem(struct iwl_trans *trans, u32 addr,
 				   void *buf, int dwords)
 {
 	unsigned long flags;
-	int offs, ret = 0;
+	int offs = 0;
 	u32 *vals = buf;
 
-	if (iwl_trans_grab_nic_access(trans, &flags)) {
-		iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
-		for (offs = 0; offs < dwords; offs++)
-			vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
-		iwl_trans_release_nic_access(trans, &flags);
-	} else {
-		ret = -EBUSY;
+	while (offs < dwords) {
+		/* limit the time we spin here under lock to 1/2s */
+		ktime_t timeout = ktime_add_us(ktime_get(), 500 * USEC_PER_MSEC);
+
+		if (iwl_trans_grab_nic_access(trans, &flags)) {
+			iwl_write32(trans, HBUS_TARG_MEM_RADDR,
+				    addr + 4 * offs);
+
+			while (offs < dwords) {
+				vals[offs] = iwl_read32(trans,
+							HBUS_TARG_MEM_RDAT);
+				offs++;
+
+				/* calling ktime_get is expensive so
+				 * do it once in 128 reads
+				 */
+				if (offs % 128 == 0 && ktime_after(ktime_get(),
+								   timeout))
+					break;
+			}
+			iwl_trans_release_nic_access(trans, &flags);
+		} else {
+			return -EBUSY;
+		}
 	}
-	return ret;
+
+	return 0;
 }
 
 static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
-- 
2.27.0




  parent reply	other threads:[~2020-12-14 19:06 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 17:27 [PATCH 5.9 000/105] 5.9.15-rc1 review Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 001/105] Kbuild: do not emit debug info for assembly with LLVM_IAS=1 Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 002/105] mm/zsmalloc.c: drop ZSMALLOC_PGTABLE_MAPPING Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 003/105] kprobes: Remove NMI context check Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 004/105] kprobes: Tell lockdep about kprobe nesting Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 005/105] ASoC: Intel: bytcr_rt5640: Fix HP Pavilion x2 Detachable quirks Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 006/105] tools/bootconfig: Fix to check the write failure correctly Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 007/105] net, xsk: Avoid taking multiple skbuff references Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 008/105] bpftool: Fix error return value in build_btf_type_table Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 009/105] vhost-vdpa: fix page pinning leakage in error path (rework) Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 010/105] powerpc/64s: Fix hash ISA v3.0 TLBIEL instruction generation Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 011/105] batman-adv: Consider fragmentation for needed_headroom Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 012/105] batman-adv: Reserve needed_*room for fragments Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 013/105] batman-adv: Dont always reallocate the fragmentation skb head Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 014/105] ipvs: fix possible memory leak in ip_vs_control_net_init Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 015/105] ibmvnic: handle inconsistent login with reset Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 016/105] ibmvnic: stop free_all_rwi on failed reset Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 017/105] ibmvnic: avoid memset null scrq msgs Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 018/105] ibmvnic: delay next reset if hard reset fails Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 019/105] ibmvnic: track pending login Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 020/105] ibmvnic: send_login should check for crq errors Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 021/105] ibmvnic: reduce wait for completion time Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 022/105] drm/rockchip: Avoid uninitialized use of endpoint id in LVDS Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 023/105] drm/panel: sony-acx565akm: Fix race condition in probe Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 024/105] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 025/105] can: sja1000: sja1000_err(): dont count arbitration lose as an error Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 026/105] can: sun4i_can: sun4i_can_err(): " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 027/105] can: c_can: c_can_power_up(): fix error handling Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 028/105] can: kvaser_pciefd: kvaser_pciefd_open(): " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 029/105] samples/ftrace: Mark my_tramp[12]? global Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 030/105] scsi: storvsc: Fix error return in storvsc_probe() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 031/105] net: broadcom CNIC: requires MMU Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 032/105] vdpa: mlx5: fix vdpa/vhost dependencies Greg Kroah-Hartman
2020-12-14 17:28   ` Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 033/105] iwlwifi: pcie: invert values of NO_160 device config entries Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 034/105] perf/x86/intel: Fix a warning on x86_pmu_stop() with large PEBS Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 035/105] usb: ohci-omap: Fix descriptor conversion Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 036/105] zlib: export S390 symbols for zlib modules Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 037/105] mm/mmap.c: fix mmap return value when vma is merged after call_mmap() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 038/105] phy: usb: Fix incorrect clearing of tca_drv_sel bit in SETUP reg for 7211 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 039/105] arm64: dts: rockchip: Remove system-power-controller from pmic on Odroid Go Advance Greg Kroah-Hartman
2020-12-14 17:28 ` Greg Kroah-Hartman [this message]
2020-12-14 17:28 ` [PATCH 5.9 041/105] arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 042/105] arm64: dts: rockchip: Reorder LED triggers from mmc devices on rk3399-roc-pc Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 043/105] iwlwifi: sta: set max HE max A-MPDU according to HE capa Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 044/105] iwlwifi: pcie: set LTR to avoid completion timeout Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 045/105] iwlwifi: mvm: fix kernel panic in case of assert during CSA Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 046/105] powerpc: Drop -me200 addition to build flags Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 047/105] arm64: dts: broadcom: clear the warnings caused by empty dma-ranges Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 048/105] ARC: stack unwinding: dont assume non-current task is sleeping Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 049/105] scsi: ufs: Fix unexpected values from ufshcd_read_desc_param() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 050/105] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 051/105] interconnect: qcom: msm8916: Remove rpm-ids from non-RPM nodes Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 052/105] interconnect: qcom: qcs404: Remove GPU and display RPM IDs Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 053/105] ibmvnic: skip tx timeout reset while in resetting Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 054/105] irqchip/gic-v3-its: Unconditionally save/restore the ITS state on suspend Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 055/105] drm/exynos: depend on COMMON_CLK to fix compile tests Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 056/105] spi: spi-nxp-fspi: fix fspi panic by unexpected interrupts Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 057/105] arm-smmu-qcom: Ensure the qcom_scm driver has finished probing Greg Kroah-Hartman
2020-12-14 17:28   ` Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 058/105] habanalabs/gaudi: fix missing code in ECC handling Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 059/105] btrfs: do nofs allocations when adding and removing qgroup relations Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 060/105] btrfs: fix lockdep splat when enabling and disabling qgroups Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 061/105] soc: fsl: dpio: Get the cpumask through cpumask_of(cpu) Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 062/105] sched/idle: Fix arch_cpu_idle() vs tracing Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 063/105] intel_idle: Fix intel_idle() " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 064/105] arm64: tegra: Disable the ACONNECT for Jetson TX2 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 065/105] platform/x86: thinkpad_acpi: add P1 gen3 second fan support Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 066/105] platform/x86: thinkpad_acpi: Do not report SW_TABLET_MODE on Yoga 11e Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 067/105] platform/x86: thinkpad_acpi: Add BAT1 is primary battery quirk for Thinkpad Yoga 11e 4th gen Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 068/105] platform/x86: thinkpad_acpi: Whitelist P15 firmware for dual fan control Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 069/105] platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 070/105] platform/x86: intel-vbtn: Support for tablet mode on HP Pavilion 13 x360 PC Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 071/105] platform/x86: touchscreen_dmi: Add info for the Predia Basic tablet Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 072/105] platform/x86: touchscreen_dmi: Add info for the Irbis TW118 tablet Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 073/105] can: m_can: m_can_dev_setup(): add support for bosch mcan version 3.3.0 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 074/105] s390: fix irq state tracing Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 075/105] intel_idle: Build fix Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 076/105] media: pulse8-cec: fix duplicate free at disconnect or probe error Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 077/105] media: pulse8-cec: add support for FW v10 and up Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 078/105] mmc: mediatek: Fix system suspend/resume support for CQHCI Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 079/105] mmc: mediatek: Extend recheck_sdio_irq fix to more variants Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 080/105] ktest.pl: Fix incorrect reboot for grub2bls Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 081/105] xen: add helpers for caching grant mapping pages Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 082/105] xen: dont use page->lru for ZONE_DEVICE memory Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 083/105] Input: cm109 - do not stomp on control URB Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 084/105] Input: i8042 - add Acer laptops to the i8042 reset list Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 085/105] pinctrl: jasperlake: Fix HOSTSW_OWN offset Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 086/105] pinctrl: amd: remove debounce filter setting in IRQ type setting Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 087/105] mmc: sdhci-of-arasan: Fix clock registration error for Keem Bay SOC Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 088/105] mmc: block: Fixup condition for CMD13 polling for RPMB requests Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 089/105] drm/amdgpu/disply: set num_crtc earlier Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 090/105] drm/i915/gem: Propagate error from cancelled submit due to context closure Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 091/105] drm/i915/display/dp: Compute the correct slice count for VDSC on DP Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 092/105] drm/i915/gt: Declare gen9 has 64 mocs entries! Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 093/105] drm/i915/gt: Ignore repeated attempts to suspend request flow across reset Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 094/105] drm/i915/gt: Cancel the preemption timeout on responding to it Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 095/105] drm/amdgpu: fix sdma instance fw version and feature version init Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 096/105] kbuild: avoid static_assert for genksyms Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 097/105] proc: use untagged_addr() for pagemap_read addresses Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 098/105] mm/hugetlb: clear compound_nr before freeing gigantic pages Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 099/105] zonefs: fix page reference and BIO leak Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 100/105] scsi: be2iscsi: Revert "Fix a theoretical leak in beiscsi_create_eqs()" Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 101/105] x86/mm/mem_encrypt: Fix definition of PMD_FLAGS_DEC_WP Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 102/105] x86/membarrier: Get rid of a dubious optimization Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 103/105] x86/apic/vector: Fix ordering in vector assignment Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 104/105] x86/kprobes: Fix optprobe to detect INT3 padding correctly Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 105/105] compiler.h: fix barrier_data() on clang Greg Kroah-Hartman
2020-12-14 22:06 ` [PATCH 5.9 000/105] 5.9.15-rc1 review Jeffrin Jose T
2020-12-14 23:53 ` Shuah Khan
2020-12-16 13:20   ` Greg Kroah-Hartman
2020-12-15  2:27 ` Naresh Kamboju
2020-12-16 13:20   ` Greg Kroah-Hartman
2020-12-15  9:06 ` Jon Hunter
2020-12-16 13:21   ` Greg Kroah-Hartman
2020-12-15 20:32 ` Guenter Roeck
2020-12-16 13:21   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201214172557.208545474@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=johannes.berg@intel.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    --cc=mordechay.goodstein@intel.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.