Skip to contentSkip to conversation

4.19.178-rc1 review

PATCH In review Greg Kroah-Hartman 11 participants 277 messages Mar 1, 2021 – Mar 2, 2022 Page 2 of 2

Subsystems (8)
lore
Share & tools
lore
author maintainer
#178 lore raw

PATCH 154/247 misc: eeprom_93xx46: Fix module alias to enable module autoprobe

In reply to Greg Kroah-Hartman

From: Aswath Govindraju <[email protected]>

[ Upstream commit 13613a2246bf531f5fc04e8e62e8f21a3d39bf1c ]

Fix module autoprobe by correcting module alias to match the string from /sys/class/.../spi1.0/modalias content.

Fixes 06b4501e88ad ("misc/eeprom: add driver for microwire 93xx46 EEPROMs")
---
 drivers/misc/eeprom/eeprom_93xx46.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/eeprom/eeprom_93xx46.c +1 -1
index 38766968bfa20..afaa717207b37 100644
@@ -522,4 +522,4 @@ module_spi_driver(eeprom_93xx46_driver);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Driver for 93xx46 EEPROMs");
 MODULE_AUTHOR("Anatolij Gustschin <[email protected]>");
-MODULE_ALIAS("spi:93xx46");
+MODULE_ALIAS("spi:eeprom-93xx46");
Signature · 1 line
2.27.0
author maintainer
#179 lore raw

PATCH 155/247 misc: eeprom_93xx46: Add module alias to avoid breaking support for non device tree users

In reply to Greg Kroah-Hartman

From: Aswath Govindraju <[email protected]>

[ Upstream commit 4540b9fbd8ebb21bb3735796d300a1589ee5fbf2 ]

Module alias "spi:93xx46" is used by non device tree users like drivers/misc/eeprom/digsy_mtc_eeprom.c and removing it will break support for them.

Fix this by adding back the module alias "spi:93xx46".

Fixes 13613a2246bf ("misc: eeprom_93xx46: Fix module alias to enable module autoprobe")
---
 drivers/misc/eeprom/eeprom_93xx46.c | 1 +
 1 file changed, 1 insertion(+)
drivers/misc/eeprom/eeprom_93xx46.c +1 -0
index afaa717207b37..a3248ebd28c62 100644
@@ -522,4 +522,5 @@ module_spi_driver(eeprom_93xx46_driver);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Driver for 93xx46 EEPROMs");
 MODULE_AUTHOR("Anatolij Gustschin <[email protected]>");
+MODULE_ALIAS("spi:93xx46");
 MODULE_ALIAS("spi:eeprom-93xx46");
Signature · 1 line
2.27.0
author maintainer
#180 lore raw

PATCH 156/247 pwm: rockchip: rockchip_pwm_probe(): Remove superfluous clk_unprepare()

In reply to Greg Kroah-Hartman

From: Simon South <[email protected]>

[ Upstream commit d5d8d675865ccddfe4da26c85f22c55cec663bf2 ]

If rockchip_pwm_probe() fails to register a PWM device it calls clk_unprepare() for the device's PWM clock, without having first disabled the clock and before jumping to an error handler that also unprepares it. This is likely to produce warnings from the kernel about the clock being unprepared when it is still enabled, and then being unprepared when it has already been unprepared.

Prevent these warnings by removing this unnecessary call to clk_unprepare().

Fixes 48cf973cae33 ("pwm: rockchip: Avoid glitches on already running PWMs")
---
 drivers/pwm/pwm-rockchip.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pwm/pwm-rockchip.c +0 -1
index 4d99d468df09a..48bcc853d57a7 100644
@@ -370,7 +370,6 @@ static int rockchip_pwm_probe(struct platform_device *pdev)
 
 	ret = pwmchip_add(&pc->chip);
 	if (ret < 0) {
-		clk_unprepare(pc->clk);
 		dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
 		goto err_pclk;
 	}
Signature · 1 line
2.27.0
author maintainer
#181 lore raw

PATCH 157/247 VMCI: Use set_page_dirty_lock() when unregistering guest memory

In reply to Greg Kroah-Hartman

From: Jorgen Hansen <[email protected]>

[ Upstream commit 5a16c535409f8dcb7568e20737309e3027ae3e49 ]

When the VMCI host support releases guest memory in the case where the VM was killed, the pinned guest pages aren't locked. Use set_page_dirty_lock() instead of set_page_dirty().

Testing done: Killed VM while having an active VMCI based vSocket connection and observed warning from ext4. With this fix, no warning was observed. Ran various vSocket tests without issues.

---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/vmw_vmci/vmci_queue_pair.c +1 -1
index 5e0d1ac67f73f..36025e1058169 100644
@@ -645,7 +645,7 @@ static void qp_release_pages(struct page **pages,
 
 	for (i = 0; i < num_pages; i++) {
 		if (dirty)
-			set_page_dirty(pages[i]);
+			set_page_dirty_lock(pages[i]);
 
 		put_page(pages[i]);
 		pages[i] = NULL;
Signature · 1 line
2.27.0
author maintainer
#182 lore raw

PATCH 158/247 PCI: Align checking of syscall user config accessors

In reply to Greg Kroah-Hartman

From: Heiner Kallweit <[email protected]>

[ Upstream commit ef9e4005cbaf022c6251263aa27836acccaef65d ]

After 34e3207205ef ("PCI: handle positive error codes"), pci_user_read_config_*() and pci_user_write_config_*() return 0 or negative errno values, not PCIBIOS_* values like PCIBIOS_SUCCESSFUL or PCIBIOS_BAD_REGISTER_NUMBER.

Remove comparisons with PCIBIOS_SUCCESSFUL and check only for non-zero. It happens that PCIBIOS_SUCCESSFUL is zero, so this is not a functional change, but it aligns this code with the user accessors.

[bhelgaas: commit log]
Fixes 34e3207205ef ("PCI: handle positive error codes")
---
 drivers/pci/syscall.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/syscall.c +5 -5
index d96626c614f56..a7bdd10fccf33 100644
@@ -19,7 +19,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
 	u16 word;
 	u32 dword;
 	long err;
-	long cfg_ret;
+	int cfg_ret;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -45,7 +45,7 @@ SYSCALL_DEFINE5(pciconfig_read, unsigned long, bus, unsigned long, dfn,
 	}
 
 	err = -EIO;
-	if (cfg_ret != PCIBIOS_SUCCESSFUL)
+	if (cfg_ret)
 		goto error;
 
 	switch (len) {
@@ -103,7 +103,7 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
 		if (err)
 			break;
 		err = pci_user_write_config_byte(dev, off, byte);
-		if (err != PCIBIOS_SUCCESSFUL)
+		if (err)
 			err = -EIO;
 		break;
 
@@ -112,7 +112,7 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
 		if (err)
 			break;
 		err = pci_user_write_config_word(dev, off, word);
-		if (err != PCIBIOS_SUCCESSFUL)
+		if (err)
 			err = -EIO;
 		break;
 
@@ -121,7 +121,7 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
 		if (err)
 			break;
 		err = pci_user_write_config_dword(dev, off, dword);
-		if (err != PCIBIOS_SUCCESSFUL)
+		if (err)
 			err = -EIO;
 		break;
 
Signature · 1 line
2.27.0
author maintainer
#183 lore raw

PATCH 159/247 drm/msm/dsi: Correct io_start for MSM8994 (20nm PHY)

In reply to Greg Kroah-Hartman

From: Konrad Dybcio <[email protected]>

[ Upstream commit 33a7808ce1aea6e2edc1af25db25928137940c02 ]

The previous registers were *almost* correct, but instead of PHYs, they were pointing at DSI PLLs, resulting in the PHY id autodetection failing miserably.

Fixes dcefc117cc19 ("drm/msm/dsi: Add support for msm8x94")
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_20nm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/dsi/phy/dsi_phy_20nm.c +1 -1
index 1ca6c69516f57..4c037d855b272 100644
@@ -147,7 +147,7 @@ const struct msm_dsi_phy_cfg dsi_phy_20nm_cfgs = {
 		.disable = dsi_20nm_phy_disable,
 		.init = msm_dsi_phy_init_common,
 	},
-	.io_start = { 0xfd998300, 0xfd9a0300 },
+	.io_start = { 0xfd998500, 0xfd9a0500 },
 	.num_dsi_phy = 2,
 };
 
Signature · 1 line
2.27.0
author maintainer
#184 lore raw

PATCH 160/247 ext4: fix potential htree index checksum corruption

In reply to Greg Kroah-Hartman

From: Theodore Ts'o <[email protected]>

[ Upstream commit b5776e7524afbd4569978ff790864755c438bba7 ]

In the case where we need to do an interior node split, and immediately afterwards, we are unable to allocate a new directory leaf block due to ENOSPC, the directory index checksum's will not be filled in correctly (and indeed, will not be correctly journalled).

This looks like a bug that was introduced when we added largedir support. The original code doesn't make any sense (and should have been caught in code review), but it was hidden because most of the time, the index node checksum will be set by do_split(). But if do_split bails out due to ENOSPC, then ext4_handle_dirty_dx_node() won't get called, and so the directory index checksum field will not get set, leading to:

EXT4-fs error (device sdb): dx_probe:858: inode #6635543: block 4022: comm nfsd: Directory index failed checksum

Google-Bug-Id: 176345532

Fixes e08ac99fa2a2 ("ext4: add largedir feature")
Cc Artem Blagodarenko <[email protected]>
---
 fs/ext4/namei.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/namei.c +3 -4
index 8f7e0ad5b5ef1..0dde6385a1258 100644
@@ -2315,11 +2315,10 @@ again:
 						   (frame - 1)->bh);
 			if (err)
 				goto journal_error;
-			if (restart) {
-				err = ext4_handle_dirty_dx_node(handle, dir,
-							   frame->bh);
+			err = ext4_handle_dirty_dx_node(handle, dir,
+							frame->bh);
+			if (err)
 				goto journal_error;
-			}
 		} else {
 			struct dx_root *dxroot;
 			memcpy((char *) entries2, (char *) entries,
Signature · 1 line
2.27.0
author maintainer
#185 lore raw

PATCH 161/247 regmap: sdw: use _no_pm functions in regmap_read/write

In reply to Greg Kroah-Hartman

From: Bard Liao <[email protected]>

[ Upstream commit d288a5712ef961e16d588bbdb2d846e00b5ef154 ]

sdw_update_slave_status will be invoked when a codec is attached, and the codec driver will initialize the codec with regmap functions while the codec device is pm_runtime suspended.

regmap routines currently rely on regular SoundWire IO functions, which will call pm_runtime_get_sync()/put_autosuspend.

This causes a deadlock where the resume routine waits for an initialization complete signal that while the initialization complete can only be reached when the resume completes.

The only solution if we allow regmap functions to be used in resume operations as well as during codec initialization is to use _no_pm routines. The duty of making sure the bus is operational needs to be handled above the regmap level.

---
 drivers/base/regmap/regmap-sdw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regmap-sdw.c +2 -2
index 50a66382d87d0..e75168b941d0c 100644
@@ -12,7 +12,7 @@ static int regmap_sdw_write(void *context, unsigned int reg, unsigned int val)
 	struct device *dev = context;
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 
-	return sdw_write(slave, reg, val);
+	return sdw_write_no_pm(slave, reg, val);
 }
 
 static int regmap_sdw_read(void *context, unsigned int reg, unsigned int *val)
@@ -21,7 +21,7 @@ static int regmap_sdw_read(void *context, unsigned int reg, unsigned int *val)
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	int read;
 
-	read = sdw_read(slave, reg);
+	read = sdw_read_no_pm(slave, reg);
 	if (read < 0)
 		return read;
 
Signature · 1 line
2.27.0
author maintainer
#186 lore raw

PATCH 162/247 i40e: Fix flow for IPv6 next header (extension header)

In reply to Greg Kroah-Hartman

From: Slawomir Laba <[email protected]>

[ Upstream commit 92c6058024e87087cf1b99b0389d67c0a886360e ]

When a packet contains an IPv6 header with next header which is an extension header and not a protocol one, the kernel function skb_transport_header called with such sk_buff will return a pointer to the extension header and not to the TCP one.

The above explained call caused a problem with packet processing for skb with encapsulation for tunnel with I40E_TX_CTX_EXT_IP_IPV6. The extension header was not skipped at all.

The ipv6_skip_exthdr function does check if next header of the IPV6 header is an extension header and doesn't modify the l4_proto pointer if it points to a protocol header value so its safe to omit the comparison of exthdr and l4.hdr pointers. The ipv6_skip_exthdr can return value -1. This means that the skipping process failed and there is something wrong with the packet so it will be dropped.

Fixes a3fd9d8876a5 ("i40e/i40evf: Handle IPv6 extension headers in checksum offload")
---
 drivers/net/ethernet/intel/i40e/i40e_txrx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_txrx.c +6 -3
index b5042d1a63c0b..9ccbcd88bf1e6 100644
@@ -3070,13 +3070,16 @@ static int i40e_tx_enable_csum(struct sk_buff *skb, u32 *tx_flags,
 
 			l4_proto = ip.v4->protocol;
 		} else if (*tx_flags & I40E_TX_FLAGS_IPV6) {
+			int ret;
+
 			tunnel |= I40E_TX_CTX_EXT_IP_IPV6;
 
 			exthdr = ip.hdr + sizeof(*ip.v6);
 			l4_proto = ip.v6->nexthdr;
-			if (l4.hdr != exthdr)
-				ipv6_skip_exthdr(skb, exthdr - skb->data,
-						 &l4_proto, &frag_off);
+			ret = ipv6_skip_exthdr(skb, exthdr - skb->data,
+					       &l4_proto, &frag_off);
+			if (ret < 0)
+				return -1;
 		}
 
 		/* define outer transport */
Signature · 1 line
2.27.0
author maintainer
#187 lore raw

PATCH 163/247 i40e: Add zero-initialization of AQ command structures

In reply to Greg Kroah-Hartman

From: Mateusz Palczewski <[email protected]>

[ Upstream commit d2c788f739b6f68090e968a2ee31b543701e795f ]

Zero-initialize AQ command data structures to comply with API specifications.

Fixes 2f4b411a3d67 ("i40e: Enable cloud filters via tc-flower")
Fixes f4492db16df8 ("i40e: Add NPAR BW get and set functions")
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/i40e/i40e_main.c +6 -0
index a728b6a7872cb..2518e2d6484c0 100644
@@ -7007,6 +7007,8 @@ int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
 	if (filter->flags >= ARRAY_SIZE(flag_table))
 		return I40E_ERR_CONFIG;
 
+	memset(&cld_filter, 0, sizeof(cld_filter));
+
 	/* copy element needed to add cloud filter from filter */
 	i40e_set_cld_element(filter, &cld_filter);
 
@@ -7074,6 +7076,8 @@ int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
 	    !ipv6_addr_any(&filter->ip.v6.src_ip6))
 		return -EOPNOTSUPP;
 
+	memset(&cld_filter, 0, sizeof(cld_filter));
+
 	/* copy element needed to add cloud filter from filter */
 	i40e_set_cld_element(filter, &cld_filter.element);
 
@@ -11107,6 +11111,8 @@ i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
 	struct i40e_aqc_configure_partition_bw_data bw_data;
 	i40e_status status;
 
+	memset(&bw_data, 0, sizeof(bw_data));
+
 	/* Set the valid bit for this PF */
 	bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
 	bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
Signature · 1 line
2.27.0
author maintainer
#188 lore raw

PATCH 164/247 i40e: Fix overwriting flow control settings during driver loading

In reply to Greg Kroah-Hartman

From: Mateusz Palczewski <[email protected]>

[ Upstream commit 4cdb9f80dcd46aab3c0020b4a6920c22735c5d6e ]

During driver loading flow control settings were written to FW using a variable which was always zero, since it was being set only by ethtool. This behavior has been corrected and driver no longer overwrites the default FW/NVM settings.

---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 27 ---------------------
 1 file changed, 27 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +0 -27
index 2518e2d6484c0..7a9d8bf2e1d5f 100644
@@ -9403,7 +9403,6 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
 {
 	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
 	struct i40e_hw *hw = &pf->hw;
-	u8 set_fc_aq_fail = 0;
 	i40e_status ret;
 	u32 val;
 	int v;
@@ -9484,13 +9483,6 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
 			 i40e_stat_str(&pf->hw, ret),
 			 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
 
-	/* make sure our flow control settings are restored */
-	ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
-	if (ret)
-		dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
-			i40e_stat_str(&pf->hw, ret),
-			i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
-
 	/* Rebuild the VSIs and VEBs that existed before reset.
 	 * They are still in our local switch element arrays, so only
 	 * need to rebuild the switch model in the HW.
@@ -13629,7 +13621,6 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	int err;
 	u32 val;
 	u32 i;
-	u8 set_fc_aq_fail;
 
 	err = pci_enable_device_mem(pdev);
 	if (err)
@@ -13909,24 +13900,6 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
 
-	/* Make sure flow control is set according to current settings */
-	err = i40e_set_fc(hw, &set_fc_aq_fail, true);
-	if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
-		dev_dbg(&pf->pdev->dev,
-			"Set fc with err %s aq_err %s on get_phy_cap\n",
-			i40e_stat_str(hw, err),
-			i40e_aq_str(hw, hw->aq.asq_last_status));
-	if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
-		dev_dbg(&pf->pdev->dev,
-			"Set fc with err %s aq_err %s on set_phy_config\n",
-			i40e_stat_str(hw, err),
-			i40e_aq_str(hw, hw->aq.asq_last_status));
-	if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
-		dev_dbg(&pf->pdev->dev,
-			"Set fc with err %s aq_err %s on get_link_info\n",
-			i40e_stat_str(hw, err),
-			i40e_aq_str(hw, hw->aq.asq_last_status));
-
 	/* if FDIR VSI was set up, start it now */
 	for (i = 0; i < pf->num_alloc_vsi; i++) {
 		if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Signature · 1 line
2.27.0
author maintainer
#189 lore raw

PATCH 165/247 i40e: Fix VFs not created

In reply to Greg Kroah-Hartman

From: Sylwester Dziedziuch <[email protected]>

[ Upstream commit dc8812626440fa6a27f1f3f654f6dc435e042e42 ]

When creating VFs they were sometimes not getting resources. It was caused by not executing i40e_reset_all_vfs due to flag __I40E_VF_DISABLE being set on PF. Because of this IAVF was never able to finish setup sequence never getting reset indication from PF.
Changed test_and_set_bit __I40E_VF_DISABLE in i40e_sync_filters_subtask to test_bit and removed clear_bit. This function should not set this bit it should only check if it hasn't been already set.

Fixes a7542b876075 ("i40e: check __I40E_VF_DISABLE bit in i40e_sync_filters_subtask")
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -2
index 7a9d8bf2e1d5f..eba6f7b118a9b 100644
@@ -2577,7 +2577,7 @@ static void i40e_sync_filters_subtask(struct i40e_pf *pf)
 		return;
 	if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state))
 		return;
-	if (test_and_set_bit(__I40E_VF_DISABLE, pf->state)) {
+	if (test_bit(__I40E_VF_DISABLE, pf->state)) {
 		set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
 		return;
 	}
@@ -2595,7 +2595,6 @@ static void i40e_sync_filters_subtask(struct i40e_pf *pf)
 			}
 		}
 	}
-	clear_bit(__I40E_VF_DISABLE, pf->state);
 }
 
 /**
Signature · 1 line
2.27.0
author maintainer
#190 lore raw

PATCH 166/247 Take mmap lock in cacheflush syscall

In reply to Greg Kroah-Hartman

From: Jann Horn <[email protected]>

[ Upstream commit c26958cb5a0d9053d1358258827638773f3d36ed ]

We need to take the mmap lock around find_vma() and subsequent use of the VMA. Otherwise, we can race with concurrent operations like munmap(), which can lead to use-after-free accesses to freed VMAs.

Fixes 1000197d8013 ("nios2: System calls handling")
---
 arch/nios2/kernel/sys_nios2.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/nios2/kernel/sys_nios2.c +9 -2
index cd390ec4f88bf..b1ca856999521 100644
@@ -22,6 +22,7 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
 				unsigned int op)
 {
 	struct vm_area_struct *vma;
+	struct mm_struct *mm = current->mm;
 
 	if (len == 0)
 		return 0;
@@ -34,16 +35,22 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
 	if (addr + len < addr)
 		return -EFAULT;
 
+	if (mmap_read_lock_killable(mm))
+		return -EINTR;
+
 	/*
 	 * Verify that the specified address region actually belongs
 	 * to this process.
 	 */
-	vma = find_vma(current->mm, addr);
-	if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
+	vma = find_vma(mm, addr);
+	if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) {
+		mmap_read_unlock(mm);
 		return -EFAULT;
+	}
 
 	flush_cache_range(vma, addr, addr + len);
 
+	mmap_read_unlock(mm);
 	return 0;
 }
 
Signature · 1 line
2.27.0
author maintainer
#191 lore raw

PATCH 167/247 i40e: Fix add TC filter for IPv6

In reply to Greg Kroah-Hartman

From: Mateusz Palczewski <[email protected]>

[ Upstream commit 61c1e0eb8375def7c891bfe857bb795a57090526 ]

Fix insufficient distinction between IPv4 and IPv6 addresses when creating a filter.
IPv4 and IPv6 are kept in the same memory area. If IPv6 is added, then it's caught by IPv4 check, which leads to err -95.

Fixes 2f4b411a3d67 ("i40e: Enable cloud filters via tc-flower")
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +3 -2
index eba6f7b118a9b..fe9da568ee196 100644
@@ -7071,7 +7071,8 @@ int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
 		return -EOPNOTSUPP;
 
 	/* adding filter using src_port/src_ip is not supported at this stage */
-	if (filter->src_port || filter->src_ipv4 ||
+	if (filter->src_port ||
+	    (filter->src_ipv4 && filter->n_proto != ETH_P_IPV6) ||
 	    !ipv6_addr_any(&filter->ip.v6.src_ip6))
 		return -EOPNOTSUPP;
 
@@ -7100,7 +7101,7 @@ int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
 			cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
 		}
 
-	} else if (filter->dst_ipv4 ||
+	} else if ((filter->dst_ipv4 && filter->n_proto != ETH_P_IPV6) ||
 		   !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
 		cld_filter.element.flags =
 				cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
Signature · 1 line
2.27.0
author maintainer
#192 lore raw

PATCH 168/247 net/mlx4_core: Add missed mlx4_free_cmd_mailbox()

In reply to Greg Kroah-Hartman

From: Chuhong Yuan <[email protected]>

[ Upstream commit 8eb65fda4a6dbd59cd5de24b106a10b6ee0d2176 ]

mlx4_do_mirror_rule() forgets to call mlx4_free_cmd_mailbox() to free the memory region allocated by mlx4_alloc_cmd_mailbox() before an exit.
Add the missed call to fix it.

Fixes 78efed275117 ("net/mlx4_core: Support mirroring VF DMFS rules on both ports")
---
 drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c +1 -0
index a4c1ed65f620c..550e4893253ee 100644
@@ -4990,6 +4990,7 @@ static int mlx4_do_mirror_rule(struct mlx4_dev *dev, struct res_fs_rule *fs_rule
 
 	if (!fs_rule->mirr_mbox) {
 		mlx4_err(dev, "rule mirroring mailbox is null\n");
+		mlx4_free_cmd_mailbox(dev, mailbox);
 		return -EINVAL;
 	}
 	memcpy(mailbox->buf, fs_rule->mirr_mbox, fs_rule->mirr_mbox_size);
Signature · 1 line
2.27.0
author maintainer
#193 lore raw

PATCH 169/247 vxlan: move debug check after netdev unregister

In reply to Greg Kroah-Hartman

From: Taehee Yoo <[email protected]>

[ Upstream commit 92584ddf550ae72d492858c19d1f9025e07a9350 ]

The debug check must be done after unregister_netdevice_many() call -- the hlist_del_rcu() for this is done inside .ndo_stop.

This is the same with commit 0fda7600c2e1 ("geneve: move debug check after netdev unregister")

Test commands:
ip netns del A
ip netns add A
ip netns add B

ip netns exec B ip link add vxlan0 type vxlan vni 100 local 10.0.0.1 \
remote 10.0.0.2 dstport 4789 srcport 4789 4789
ip netns exec B ip link set vxlan0 netns A
ip netns exec A ip link set vxlan0 up
ip netns del B

Splat looks like:

[   73.176249][    T7] ------------[ cut here ]------------
[   73.178662][    T7] WARNING: CPU: 4 PID: 7 at drivers/net/vxlan.c:4743 vxlan_exit_batch_net+0x52e/0x720 [vxlan]
[   73.182597][    T7] Modules linked in: vxlan openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 mlx5_core nfp mlxfw ixgbevf tls sch_fq_codel nf_tables nfnetlink ip_tables x_tables unix
[   73.190113][    T7] CPU: 4 PID: 7 Comm: kworker/u16:0 Not tainted 5.11.0-rc7+ #838
[   73.193037][    T7] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
[   73.196986][    T7] Workqueue: netns cleanup_net
[   73.198946][    T7] RIP: 0010:vxlan_exit_batch_net+0x52e/0x720 [vxlan]
[   73.201509][    T7] Code: 00 01 00 00 0f 84 39 fd ff ff 48 89 ca 48 c1 ea 03 80 3c 1a 00 0f 85 a6 00 00 00 89 c2 48 83 c2 02 49 8b 14 d4 48 85 d2 74 ce <0f> 0b eb ca e8 b9 51 db dd 84 c0 0f 85 4a fe ff ff 48 c7 c2 80 bc
[   73.208813][    T7] RSP: 0018:ffff888100907c10 EFLAGS: 00010286
[   73.211027][    T7] RAX: 000000000000003c RBX: dffffc0000000000 RCX: ffff88800ec411f0
[   73.213702][    T7] RDX: ffff88800a278000 RSI: ffff88800fc78c70 RDI: ffff88800fc78070
[   73.216169][    T7] RBP: ffff88800b5cbdc0 R08: fffffbfff424de61 R09: fffffbfff424de61
[   73.218463][    T7] R10: ffffffffa126f307 R11: fffffbfff424de60 R12: ffff88800ec41000
[   73.220794][    T7] R13: ffff888100907d08 R14: ffff888100907c50 R15: ffff88800fc78c40
[   73.223337][    T7] FS:  0000000000000000(0000) GS:ffff888114800000(0000) knlGS:0000000000000000
[   73.225814][    T7] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   73.227616][    T7] CR2: 0000562b5cb4f4d0 CR3: 0000000105fbe001 CR4: 00000000003706e0
[   73.229700][    T7] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[   73.231820][    T7] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[   73.233844][    T7] Call Trace:
[   73.234698][    T7]  ? vxlan_err_lookup+0x3c0/0x3c0 [vxlan]
[   73.235962][    T7]  ? ops_exit_list.isra.11+0x93/0x140
[   73.237134][    T7]  cleanup_net+0x45e/0x8a0

[ ... ]

Fixes 57b61127ab7d ("vxlan: speedup vxlan tunnels dismantle")
---
 drivers/net/vxlan.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/vxlan.c +8 -3
index 66fffbd64a33f..49e8c6d42cda4 100644
@@ -3812,7 +3812,6 @@ static void vxlan_destroy_tunnels(struct net *net, struct list_head *head)
 	struct vxlan_net *vn = net_generic(net, vxlan_net_id);
 	struct vxlan_dev *vxlan, *next;
 	struct net_device *dev, *aux;
-	unsigned int h;
 
 	for_each_netdev_safe(net, dev, aux)
 		if (dev->rtnl_link_ops == &vxlan_link_ops)
@@ -3826,14 +3825,13 @@ static void vxlan_destroy_tunnels(struct net *net, struct list_head *head)
 			unregister_netdevice_queue(vxlan->dev, head);
 	}
 
-	for (h = 0; h < PORT_HASH_SIZE; ++h)
-		WARN_ON_ONCE(!hlist_empty(&vn->sock_list[h]));
 }
 
 static void __net_exit vxlan_exit_batch_net(struct list_head *net_list)
 {
 	struct net *net;
 	LIST_HEAD(list);
+	unsigned int h;
 
 	rtnl_lock();
 	list_for_each_entry(net, net_list, exit_list)
@@ -3841,6 +3839,13 @@ static void __net_exit vxlan_exit_batch_net(struct list_head *net_list)
 
 	unregister_netdevice_many(&list);
 	rtnl_unlock();
+
+	list_for_each_entry(net, net_list, exit_list) {
+		struct vxlan_net *vn = net_generic(net, vxlan_net_id);
+
+		for (h = 0; h < PORT_HASH_SIZE; ++h)
+			WARN_ON_ONCE(!hlist_empty(&vn->sock_list[h]));
+	}
 }
 
 static struct pernet_operations vxlan_net_ops = {
Signature · 1 line
2.27.0
author maintainer
#194 lore raw

PATCH 170/247 ocfs2: fix a use after free on error

In reply to Greg Kroah-Hartman

From: Dan Carpenter <[email protected]>

[ Upstream commit c57d117f2b2f2a19b570c36f2819ef8d8210af20 ]

The error handling in this function frees "reg" but it is still on the "o2hb_all_regions" list so it will lead to a use after freew. Joseph Qi points out that we need to clear the bit in the "o2hb_region_bitmap" as well

---
 fs/ocfs2/cluster/heartbeat.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ocfs2/cluster/heartbeat.c +7 -1
index 9b2ed62dd6385..19b0d358a0d6e 100644
@@ -2154,7 +2154,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 			o2hb_nego_timeout_handler,
 			reg, NULL, &reg->hr_handler_list);
 	if (ret)
-		goto free;
+		goto remove_item;
 
 	ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key,
 			sizeof(struct o2hb_nego_msg),
@@ -2173,6 +2173,12 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g
 
 unregister_handler:
 	o2net_unregister_handler_list(&reg->hr_handler_list);
+remove_item:
+	spin_lock(&o2hb_live_lock);
+	list_del(&reg->hr_all_item);
+	if (o2hb_global_heartbeat_active())
+		clear_bit(reg->hr_region_num, o2hb_region_bitmap);
+	spin_unlock(&o2hb_live_lock);
 free:
 	kfree(reg);
 	return ERR_PTR(ret);
Signature · 1 line
2.27.0
author maintainer
#195 lore raw

PATCH 171/247 mm/memory.c: fix potential pte_unmap_unlock pte error

In reply to Greg Kroah-Hartman

From: Miaohe Lin <[email protected]>

[ Upstream commit 90a3e375d324b2255b83e3dd29e99e2b05d82aaf ]

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Andi said:

"While the fix is correct, I'm not sure if it actually is a real bug.
Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug"

Fixes 42e4089c789 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings")
Cc Thomas Gleixner <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Josh Poimboeuf <[email protected]>
---
 mm/memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memory.c +3 -3
index eeae63bd95027..4bd37296df89b 100644
@@ -1995,11 +1995,11 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd,
 			unsigned long addr, unsigned long end,
 			unsigned long pfn, pgprot_t prot)
 {
-	pte_t *pte;
+	pte_t *pte, *mapped_pte;
 	spinlock_t *ptl;
 	int err = 0;
 
-	pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
+	mapped_pte = pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
 	if (!pte)
 		return -ENOMEM;
 	arch_enter_lazy_mmu_mode();
@@ -2013,7 +2013,7 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd,
 		pfn++;
 	} while (pte++, addr += PAGE_SIZE, addr != end);
 	arch_leave_lazy_mmu_mode();
-	pte_unmap_unlock(pte - 1, ptl);
+	pte_unmap_unlock(mapped_pte, ptl);
 	return err;
 }
 
Signature · 1 line
2.27.0
author maintainer
#196 lore raw

PATCH 172/247 mm/hugetlb: fix potential double free in hugetlb_register_node() error path

In reply to Greg Kroah-Hartman

From: Miaohe Lin <[email protected]>

[ Upstream commit cc2205a67dec5a700227a693fc113441e73e4641 ]

In hugetlb_sysfs_add_hstate(), we would do kobject_put() on hstate_kobjs when failed to create sysfs group but forget to set hstate_kobjs to NULL. Then in hugetlb_register_node() error path, we may free it again via hugetlb_unregister_node().

---
 mm/hugetlb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/hugetlb.c +3 -1
index df89aed023029..9eb5c25fabc9e 100644
@@ -2648,8 +2648,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
 		return -ENOMEM;
 
 	retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group);
-	if (retval)
+	if (retval) {
 		kobject_put(hstate_kobjs[hi]);
+		hstate_kobjs[hi] = NULL;
+	}
 
 	return retval;
 }
Signature · 1 line
2.27.0
author maintainer
#197 lore raw

PATCH 173/247 r8169: fix jumbo packet handling on RTL8168e

In reply to Greg Kroah-Hartman

From: Heiner Kallweit <[email protected]>

[ Upstream commit 6cf739131a15e4177e58a1b4f2bede9d5da78552 ]

Josef reported [0] that using jumbo packets fails on RTL8168e. Aligning the values for register MaxTxPacketSize with the vendor driver fixes the problem.

[0] https://bugzilla.kernel.org/show_bug.cgi?id=211827

---
 drivers/net/ethernet/realtek/r8169.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/realtek/r8169.c +2 -2
index 6b901bf1cd54d..6fd1a639ec533 100644
@@ -4365,7 +4365,7 @@ static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp)
 
 static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
 {
-	RTL_W8(tp, MaxTxPacketSize, 0x3f);
+	RTL_W8(tp, MaxTxPacketSize, 0x24);
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
 	RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01);
 	rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B);
@@ -4373,7 +4373,7 @@ static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
 
 static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp)
 {
-	RTL_W8(tp, MaxTxPacketSize, 0x0c);
+	RTL_W8(tp, MaxTxPacketSize, 0x3f);
 	RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
 	RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01);
 	rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
Signature · 1 line
2.27.0
author maintainer
#198 lore raw

PATCH 174/247 arm64: Add missing ISB after invalidating TLB in __primary_switch

In reply to Greg Kroah-Hartman

From: Marc Zyngier <[email protected]>

[ Upstream commit 9d41053e8dc115c92b8002c3db5f545d7602498b ]

Although there has been a bit of back and forth on the subject, it appears that invalidating TLBs requires an ISB instruction when FEAT_ETS is not implemented by the CPU.

Quoted 1 line

From the bible:

  | In an implementation that does not implement FEAT_ETS, a TLB
  | maintenance instruction executed by a PE, PEx, can complete at any
  | time after it is issued, but is only guaranteed to be finished for a
  | PE, PEx, after the execution of DSB by the PEx followed by a Context
  | synchronization event

Add the missing ISB in __primary_switch, just in case.

Fixes 3c5e9f238bc4 ("arm64: head.S: move KASLR processing out of __enable_mmu()")
---
 arch/arm64/kernel/head.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/head.S +1 -0
index d22ab8d9edc95..c85ea70b92936 100644
@@ -867,6 +867,7 @@ __primary_switch:
 
 	tlbi	vmalle1				// Remove any stale TLB entries
 	dsb	nsh
+	isb
 
 	msr	sctlr_el1, x19			// re-enable the MMU
 	isb
Signature · 1 line
2.27.0
author maintainer
#199 lore raw

PATCH 175/247 i2c: brcmstb: Fix brcmstd_send_i2c_cmd condition

In reply to Greg Kroah-Hartman

From: Maxime Ripard <[email protected]>

[ Upstream commit a1858ce0cfe31368b23ba55794e409fb57ced4a4 ]

The brcmstb_send_i2c_cmd currently has a condition that is (CMD_RD || CMD_WR) which always evaluates to true, while the obvious fix is to test whether the cmd variable passed as parameter holds one of these two values.

Fixes dd1aa2524bc5 ("i2c: brcmstb: Add Broadcom settop SoC i2c controller driver")
---
 drivers/i2c/busses/i2c-brcmstb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-brcmstb.c +1 -1
index 826d320499961..2086a96307bf9 100644
@@ -318,7 +318,7 @@ static int brcmstb_send_i2c_cmd(struct brcmstb_i2c_dev *dev,
 		goto cmd_out;
 	}
 
-	if ((CMD_RD || CMD_WR) &&
+	if ((cmd == CMD_RD || cmd == CMD_WR) &&
 	    bsc_readl(dev, iic_enable) & BSC_IIC_EN_NOACK_MASK) {
 		rc = -EREMOTEIO;
 		dev_dbg(dev->device, "controller received NOACK intr for %s\n",
Signature · 1 line
2.27.0
author maintainer
#200 lore raw

PATCH 176/247 mm/rmap: fix potential pte_unmap on an not mapped pte

In reply to Greg Kroah-Hartman

From: Miaohe Lin <[email protected]>

[ Upstream commit 5d5d19eda6b0ee790af89c45e3f678345be6f50f ]

For PMD-mapped page (usually THP), pvmw->pte is NULL. For PTE-mapped THP, pvmw->pte is mapped. But for HugeTLB pages, pvmw->pte is not mapped and set to the relevant page table entry. So in page_vma_mapped_walk_done(), we may do pte_unmap() for HugeTLB pte which is not mapped. Fix this by checking pvmw->page against PageHuge before trying to do pte_unmap().

Fixes ace71a19cec5 ("mm: introduce page_vma_mapped_walk()")
Cc Kees Cook <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Michel Lespinasse <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Wei Yang <[email protected]>
Cc Dmitry Safonov <[email protected]>
Cc Brian Geffon <[email protected]>
---
 include/linux/rmap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/rmap.h +2 -1
index 988d176472df7..d7d6d4eb17949 100644
@@ -214,7 +214,8 @@ struct page_vma_mapped_walk {
 
 static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw)
 {
-	if (pvmw->pte)
+	/* HugeTLB pte is set to the relevant page table entry without pte_mapped. */
+	if (pvmw->pte && !PageHuge(pvmw->page))
 		pte_unmap(pvmw->pte);
 	if (pvmw->ptl)
 		spin_unlock(pvmw->ptl);
Signature · 1 line
2.27.0
author maintainer
#201 lore raw

PATCH 177/247 scsi: bnx2fc: Fix Kconfig warning & CNIC build errors

In reply to Greg Kroah-Hartman

From: Randy Dunlap <[email protected]>

[ Upstream commit eefb816acb0162e94a85a857f3a55148f671d5a5 ]

CNIC depends on MMU, but since 'select' does not follow any dependency chains, SCSI_BNX2X_FCOE also needs to depend on MMU, so that erroneous configs are not generated, which cause build errors in cnic.

WARNING: unmet direct dependencies detected for CNIC
Depends on [n]: NETDEVICES [=y] && ETHERNET [=y] && NET_VENDOR_BROADCOM [=y] && PCI [=y] && (IPV6 [=n] || IPV6 [=n]=n) && MMU [=n] Selected by [y]:
- SCSI_BNX2X_FCOE [=y] && SCSI_LOWLEVEL [=y] && SCSI [=y] && PCI [=y] && (IPV6 [=n] || IPV6 [=n]=n) && LIBFC [=y] && LIBFCOE [=y]

riscv64-linux-ld: drivers/net/ethernet/broadcom/cnic.o: in function `.L154':
cnic.c:(.text+0x1094): undefined reference to `uio_event_notify'
riscv64-linux-ld: cnic.c:(.text+0x10bc): undefined reference to `uio_event_notify'
riscv64-linux-ld: drivers/net/ethernet/broadcom/cnic.o: in function `.L1442':
cnic.c:(.text+0x96a8): undefined reference to `__uio_register_device'
riscv64-linux-ld: drivers/net/ethernet/broadcom/cnic.o: in function `.L0 ':
cnic.c:(.text.unlikely+0x68): undefined reference to `uio_unregister_device'

Fixes 853e2bd2103a ("[SCSI] bnx2fc: Broadcom FCoE offload driver")
Cc Saurav Kashyap <[email protected]>
Cc Javed Hasan <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 drivers/scsi/bnx2fc/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/bnx2fc/Kconfig +1 -0
index d401a096dfc7e..2eb2476852b11 100644
@@ -4,6 +4,7 @@ config SCSI_BNX2X_FCOE
 	depends on (IPV6 || IPV6=n)
 	depends on LIBFC
 	depends on LIBFCOE
+	depends on MMU
 	select NETDEVICES
 	select ETHERNET
 	select NET_VENDOR_BROADCOM
Signature · 1 line
2.27.0
author maintainer
#202 lore raw

PATCH 178/247 blk-settings: align max_sectors on "logical_block_size" boundary

In reply to Greg Kroah-Hartman

From: Mikulas Patocka <[email protected]>

commit 97f433c3601a24d3513d06f575a389a2ca4e11e4 upstream.

We get I/O errors when we run md-raid1 on the top of dm-integrity on the top of ramdisk.
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb

The ramdisk device has logical_block_size 512 and max_sectors 255. The dm-integrity device uses logical_block_size 4096 and it doesn't affect the "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have a device with max_sectors not aligned on logical_block_size.

The md-raid device sees that the underlying leg has max_sectors 255 and it will split the bios on 255-sector boundary, making the bios unaligned on logical_block_size.

In order to fix the bug, we round down max_sectors to logical_block_size.

---
 block/blk-settings.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
block/blk-settings.c +12 -0
@@ -513,6 +513,14 @@ void blk_queue_io_opt(struct request_que
 }
 EXPORT_SYMBOL(blk_queue_io_opt);
 
+static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
+{
+	sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
+	if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
+		sectors = PAGE_SIZE >> SECTOR_SHIFT;
+	return sectors;
+}
+
 /**
  * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
  * @t:	the stacking driver (top)
@@ -639,6 +647,10 @@ int blk_stack_limits(struct queue_limits
 		ret = -1;
 	}
 
+	t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
+	t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
+	t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
+
 	/* Discard alignment and granularity */
 	if (b->discard_granularity) {
 		alignment = queue_limit_discard_alignment(b, start);
author maintainer
#203 lore raw

PATCH 179/247 ACPI: property: Fix fwnode string properties matching

In reply to Greg Kroah-Hartman

From: Rafael J. Wysocki <[email protected]>

commit e1e6bd2995ac0e1ad0c2a2d906a06f59ce2ed293 upstream.

Property matching does not work for ACPI fwnodes if the value of the given property is not represented as a package in the _DSD package containing it. For example, the "compatible" property in the _DSD below

  Name (_DSD, Package () {
    ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
    Package () {
      Package () {"compatible", "ethernet-phy-ieee802.3-c45"}
    }
  })

will not be found by fwnode_property_match_string(), because the ACPI code handling device properties does not regard the single value as a "list" in that case.

Namely, fwnode_property_match_string() invoked to match a given string property value first calls fwnode_property_read_string_array() with the last two arguments equal to NULL and 0, respectively, in order to count the items in the value of the given property, with the assumption that this value may be an array. For ACPI fwnodes, that operation is carried out by acpi_node_prop_read() which calls acpi_data_prop_read() for this purpose. However, when the return (val) pointer is NULL, that function only looks for a property whose value is a package without checking the single-value case at all.

To fix that, make acpi_data_prop_read() check the single-value case if its return pointer argument is NULL and modify acpi_data_prop_read_single() handling that case to attempt to read the value of the property if the return pointer is NULL and return 1 if that succeeds.

Fixes 3708184afc77 ("device property: Move FW type specific functionality to FW specific files")
Cc 4.13+ <[email protected]> # 4.13+
---
 drivers/acpi/property.c |   44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)
drivers/acpi/property.c +33 -11
@@ -720,9 +720,6 @@ static int acpi_data_prop_read_single(co
 	const union acpi_object *obj;
 	int ret;
 
-	if (!val)
-		return -EINVAL;
-
 	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
 		if (ret)
@@ -732,28 +729,43 @@ static int acpi_data_prop_read_single(co
 		case DEV_PROP_U8:
 			if (obj->integer.value > U8_MAX)
 				return -EOVERFLOW;
-			*(u8 *)val = obj->integer.value;
+
+			if (val)
+				*(u8 *)val = obj->integer.value;
+
 			break;
 		case DEV_PROP_U16:
 			if (obj->integer.value > U16_MAX)
 				return -EOVERFLOW;
-			*(u16 *)val = obj->integer.value;
+
+			if (val)
+				*(u16 *)val = obj->integer.value;
+
 			break;
 		case DEV_PROP_U32:
 			if (obj->integer.value > U32_MAX)
 				return -EOVERFLOW;
-			*(u32 *)val = obj->integer.value;
+
+			if (val)
+				*(u32 *)val = obj->integer.value;
+
 			break;
 		default:
-			*(u64 *)val = obj->integer.value;
+			if (val)
+				*(u64 *)val = obj->integer.value;
+
 			break;
 		}
+
+		if (!val)
+			return 1;
 	} else if (proptype == DEV_PROP_STRING) {
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
 		if (ret)
 			return ret;
 
-		*(char **)val = obj->string.pointer;
+		if (val)
+			*(char **)val = obj->string.pointer;
 
 		return 1;
 	} else {
@@ -767,7 +779,7 @@ int acpi_dev_prop_read_single(struct acp
 {
 	int ret;
 
-	if (!adev)
+	if (!adev || !val)
 		return -EINVAL;
 
 	ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val);
@@ -861,10 +873,20 @@ static int acpi_data_prop_read(const str
 	const union acpi_object *items;
 	int ret;
 
-	if (val && nval == 1) {
+	if (nval == 1 || !val) {
 		ret = acpi_data_prop_read_single(data, propname, proptype, val);
-		if (ret >= 0)
+		/*
+		 * The overflow error means that the property is there and it is
+		 * single-value, but its type does not match, so return.
+		 */
+		if (ret >= 0 || ret == -EOVERFLOW)
 			return ret;
+
+		/*
+		 * Reading this property as a single-value one failed, but its
+		 * value may still be represented as one-element array, so
+		 * continue.
+		 */
 	}
 
 	ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
author maintainer
#204 lore raw

PATCH 180/247 ACPI: configfs: add missing check after configfs_register_default_group()

In reply to Greg Kroah-Hartman

From: Qinglang Miao <[email protected]>

commit 67e40054de86aae520ddc2a072d7f6951812a14f upstream.

A list_add corruption is reported by Hulk Robot like this:
==============
list_add corruption.

Call Trace:
link_obj+0xc0/0x1c0
link_group+0x21/0x140
configfs_register_subsystem+0xdb/0x380
acpi_configfs_init+0x25/0x1000 [acpi_configfs]
do_one_initcall+0x149/0x820
do_init_module+0x1ef/0x720
load_module+0x35c8/0x4380
__do_sys_finit_module+0x10d/0x1a0
do_syscall_64+0x34/0x80

It's because of the missing check after configfs_register_default_group, where configfs_unregister_subsystem should be called once failure.

Fixes 612bd01fc6e0 ("ACPI: add support for loading SSDTs via configfs")
Cc 4.10+ <[email protected]> # 4.10+
---
 drivers/acpi/acpi_configfs.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/acpi/acpi_configfs.c +6 -1
@@ -269,7 +269,12 @@ static int __init acpi_configfs_init(voi
 
 	acpi_table_group = configfs_register_default_group(root, "table",
 							   &acpi_tables_type);
-	return PTR_ERR_OR_ZERO(acpi_table_group);
+	if (IS_ERR(acpi_table_group)) {
+		configfs_unregister_subsystem(&acpi_configfs);
+		return PTR_ERR(acpi_table_group);
+	}
+
+	return 0;
 }
 module_init(acpi_configfs_init);
 
author maintainer
#205 lore raw

PATCH 181/247 HID: wacom: Ignore attempts to overwrite the touch_max value from HID

In reply to Greg Kroah-Hartman

From: Jason Gerecke <[email protected]>

commit 88f38846bfb1a452a3d47e38aeab20a4ceb74294 upstream.

The wacom_feature_mapping function is careful to only set the the touch_max value a single time, but this care does not extend to the wacom_wac_finger_event function. In particular, if a device sends multiple HID_DG_CONTACTMAX items in a single feature report, the driver will end up retaining the value of last item.

The HID descriptor for the Cintiq Companion 2 does exactly this. It incorrectly sets a "Report Count" of 2, which will cause the driver to process two HID_DG_CONTACTCOUNT items. The first item has the actual count, while the second item should have been declared as a constant zero. The constant zero is the value the driver ends up using, however, since it is the last HID_DG_CONTACTCOUNT in the report.

Report ID (16),
Usage (Contact Count Maximum), ; Contact count maximum (55h, static value) Report Count (2),
Logical Maximum (10),
Feature (Variable),

To address this, we add a check that the touch_max is not already set within the wacom_wac_finger_event function that processes the HID_DG_TOUCHMAX item. We emit a warning if the value is set and ignore the updated value.

This could potentially cause problems if there is a tablet which has a similar issue but requires the last item to be used. This is unlikely, however, since it would have to have a different non-zero value for HID_DG_CONTACTMAX earlier in the same report, which makes no sense except in the case of a firmware bug. Note that cases where the HID_DG_CONTACTMAX items are in different reports is already handled (and similarly ignored) by wacom_feature_mapping as mentioned above.

Fixes 184eccd40389 ("HID: wacom: generic: read HID_DG_CONTACTMAX from any feature report")
---
 drivers/hid/wacom_wac.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hid/wacom_wac.c +6 -1
@@ -2557,7 +2557,12 @@ static void wacom_wac_finger_event(struc
 		wacom_wac->hid_data.tipswitch = value;
 		break;
 	case HID_DG_CONTACTMAX:
-		features->touch_max = value;
+		if (!features->touch_max) {
+			features->touch_max = value;
+		} else {
+			hid_warn(hdev, "%s: ignoring attempt to overwrite non-zero touch_max "
+				 "%d -> %d\n", __func__, features->touch_max, value);
+		}
 		return;
 	}
 
author maintainer
#206 lore raw

PATCH 182/247 Input: raydium_ts_i2c - do not send zero length

In reply to Greg Kroah-Hartman

From: jeffrey.lin <[email protected]>

commit fafd320ae51b9c72d371585b2501f86640ea7b7d upstream.

Add default write command package to prevent i2c quirk error of zero data length as Raydium touch firmware update is executed.

---
 drivers/input/touchscreen/raydium_i2c_ts.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/touchscreen/raydium_i2c_ts.c +2 -1
@@ -419,6 +419,7 @@ static int raydium_i2c_write_object(stru
 				    enum raydium_bl_ack state)
 {
 	int error;
+	static const u8 cmd[] = { 0xFF, 0x39 };
 
 	error = raydium_i2c_send(client, RM_CMD_BOOT_WRT, data, len);
 	if (error) {
@@ -427,7 +428,7 @@ static int raydium_i2c_write_object(stru
 		return error;
 	}
 
-	error = raydium_i2c_send(client, RM_CMD_BOOT_ACK, NULL, 0);
+	error = raydium_i2c_send(client, RM_CMD_BOOT_ACK, cmd, sizeof(cmd));
 	if (error) {
 		dev_err(&client->dev, "Ack obj command failed: %d\n", error);
 		return error;
author maintainer
#207 lore raw

PATCH 183/247 Input: xpad - add support for PowerA Enhanced Wired Controller for Xbox Series X|S

In reply to Greg Kroah-Hartman

From: Olivier Crête <[email protected]>

commit 42ffcd1dba1796bcda386eb6f260df9fc23c90af upstream.

---
 drivers/input/joystick/xpad.c |    1 +
 1 file changed, 1 insertion(+)
drivers/input/joystick/xpad.c +1 -0
@@ -319,6 +319,7 @@ static const struct xpad_device {
 	{ 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 },
 	{ 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 },
 	{ 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
+	{ 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
 	{ 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
 	{ 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
 	{ 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
author maintainer
#208 lore raw

PATCH 184/247 Input: joydev - prevent potential read overflow in ioctl

In reply to Greg Kroah-Hartman

From: Dan Carpenter <[email protected]>

commit 182d679b2298d62bf42bb14b12a8067b8e17b617 upstream.

The problem here is that "len" might be less than "joydev->nabs" so the loops which verfy abspam[i] and keypam[] might read beyond the buffer.

Fixes 999b874f4aa3 ("Input: joydev - validate axis/button maps before clobbering current ones")
[dtor: additional check for len being even in joydev_handle_JSIOCSBTNMAP]
---
 drivers/input/joydev.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/input/joydev.c +5 -2
@@ -460,7 +460,7 @@ static int joydev_handle_JSIOCSAXMAP(str
 	if (IS_ERR(abspam))
 		return PTR_ERR(abspam);
 
-	for (i = 0; i < joydev->nabs; i++) {
+	for (i = 0; i < len && i < joydev->nabs; i++) {
 		if (abspam[i] > ABS_MAX) {
 			retval = -EINVAL;
 			goto out;
@@ -484,6 +484,9 @@ static int joydev_handle_JSIOCSBTNMAP(st
 	int i;
 	int retval = 0;
 
+	if (len % sizeof(*keypam))
+		return -EINVAL;
+
 	len = min(len, sizeof(joydev->keypam));
 
 	/* Validate the map. */
@@ -491,7 +494,7 @@ static int joydev_handle_JSIOCSBTNMAP(st
 	if (IS_ERR(keypam))
 		return PTR_ERR(keypam);
 
-	for (i = 0; i < joydev->nkey; i++) {
+	for (i = 0; i < (len / 2) && i < joydev->nkey; i++) {
 		if (keypam[i] > KEY_MAX || keypam[i] < BTN_MISC) {
 			retval = -EINVAL;
 			goto out;
author maintainer
#209 lore raw

PATCH 185/247 Input: i8042 - add ASUS Zenbook Flip to noselftest list

In reply to Greg Kroah-Hartman

From: Marcos Paulo de Souza <[email protected]>

commit b5d6e7ab7fe7d186878142e9fc1a05e4c3b65eb9 upstream.

After commit 77b425399f6d ("Input: i8042 - use chassis info to skip selftest on Asus laptops"), all modern Asus laptops have the i8042 selftest disabled. It has done by using chassys type "10" (laptop).

The Asus Zenbook Flip suffers from similar suspend/resume issues, but it _sometimes_ work and sometimes it doesn't. Setting noselftest makes it work reliably. In this case, we need to add chassis type "31" (convertible) in order to avoid selftest in this device.

---
 drivers/input/serio/i8042-x86ia64io.h |    4 ++++
 1 file changed, 4 insertions(+)
drivers/input/serio/i8042-x86ia64io.h +4 -0
@@ -592,6 +592,10 @@ static const struct dmi_system_id i8042_
 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 			DMI_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
 		},
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible Notebook */
+		},
 	},
 	{ }
 };
author maintainer
#210 lore raw

PATCH 186/247 USB: serial: option: update interface mapping for ZTE P685M

In reply to Greg Kroah-Hartman

From: Lech Perczak <[email protected]>

commit 6420a569504e212d618d4a4736e2c59ed80a8478 upstream.

This patch prepares for qmi_wwan driver support for the device. Previously "option" driver mapped itself to interfaces 0 and 3 (matching ff/ff/ff), while interface 3 is in fact a QMI port. Interfaces 1 and 2 (matching ff/00/00) expose AT commands, and weren't supported previously at all.
Without this patch, a possible conflict would exist if device ID was added to qmi_wwan driver for interface 3.

Update and simplify device ID to match interfaces 0-2 directly, to expose QCDM (0), PCUI (1), and modem (2) ports and avoid conflict with QMI (3), and ADB (4).

The modem is used inside ZTE MF283+ router and carriers identify it as such.
Interface mapping is:
0: QCDM, 1: AT (PCUI), 2: AT (Modem), 3: QMI, 4: ADB

T:  Bus=02 Lev=02 Prnt=02 Port=05 Cnt=01 Dev#=  3 Spd=480  MxCh= 0
D:  Ver= 2.01 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=19d2 ProdID=1275 Rev=f0.00
S:  Manufacturer=ZTE,Incorporated
S:  Product=ZTE Technologies MSM
S:  SerialNumber=P685M510ZTED0000CP&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&0
C:* #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
E:  Ad=83(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
E:  Ad=85(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=qmi_wwan
E:  Ad=87(I) Atr=03(Int.) MxPS=   8 Ivl=32ms
E:  Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I:* If#= 4 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=(none)
E:  Ad=88(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
---
 drivers/usb/serial/option.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/serial/option.c +2 -1
@@ -1569,7 +1569,8 @@ static const struct usb_device_id option
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1272, 0xff, 0xff, 0xff) },
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1273, 0xff, 0xff, 0xff) },
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1274, 0xff, 0xff, 0xff) },
-	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1275, 0xff, 0xff, 0xff) },
+	{ USB_DEVICE(ZTE_VENDOR_ID, 0x1275),	/* ZTE P685M */
+	  .driver_info = RSVD(3) | RSVD(4) },
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1276, 0xff, 0xff, 0xff) },
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1277, 0xff, 0xff, 0xff) },
 	{ USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1278, 0xff, 0xff, 0xff) },
author maintainer
#211 lore raw

PATCH 187/247 usb: musb: Fix runtime PM race in musb_queue_resume_work

In reply to Greg Kroah-Hartman

From: Paul Cercueil <[email protected]>

commit 0eaa1a3714db34a59ce121de5733c3909c529463 upstream.

musb_queue_resume_work() would call the provided callback if the runtime PM status was 'active'. Otherwise, it would enqueue the request if the hardware was still suspended (musb->is_runtime_suspended is true).

This causes a race with the runtime PM handlers, as it is possible to be in the case where the runtime PM status is not yet 'active', but the hardware has been awaken (PM resume function has been called).

When hitting the race, the resume work was not enqueued, which probably triggered other bugs further down the stack. For instance, a telnet connection on Ingenic SoCs would result in a 50/50 chance of a segmentation fault somewhere in the musb code.

Rework the code so that either we call the callback directly if (musb->is_runtime_suspended == 0), or enqueue the query otherwise.

Fixes ea2f35c01d5e ("usb: musb: Fix sleeping function called from invalid context for hdrc glue")
---
 drivers/usb/musb/musb_core.c |   31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/usb/musb/musb_core.c +17 -14
@@ -2108,32 +2108,35 @@ int musb_queue_resume_work(struct musb *
 {
 	struct musb_pending_work *w;
 	unsigned long flags;
+	bool is_suspended;
 	int error;
 
 	if (WARN_ON(!callback))
 		return -EINVAL;
 
-	if (pm_runtime_active(musb->controller))
-		return callback(musb, data);
+	spin_lock_irqsave(&musb->list_lock, flags);
+	is_suspended = musb->is_runtime_suspended;
 
-	w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC);
-	if (!w)
-		return -ENOMEM;
+	if (is_suspended) {
+		w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC);
+		if (!w) {
+			error = -ENOMEM;
+			goto out_unlock;
+		}
+
+		w->callback = callback;
+		w->data = data;
 
-	w->callback = callback;
-	w->data = data;
-	spin_lock_irqsave(&musb->list_lock, flags);
-	if (musb->is_runtime_suspended) {
 		list_add_tail(&w->node, &musb->pending_list);
 		error = 0;
-	} else {
-		dev_err(musb->controller, "could not add resume work %p\n",
-			callback);
-		devm_kfree(musb->controller, w);
-		error = -EINPROGRESS;
 	}
+
+out_unlock:
 	spin_unlock_irqrestore(&musb->list_lock, flags);
 
+	if (!is_suspended)
+		error = callback(musb, data);
+
 	return error;
 }
 EXPORT_SYMBOL_GPL(musb_queue_resume_work);
author maintainer
#212 lore raw

PATCH 188/247 usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1

In reply to Greg Kroah-Hartman

From: Thinh Nguyen <[email protected]>

commit a1679af85b2ae35a2b78ad04c18bb069c37330cc upstream.

Valid range for DEPCFG.bInterval_m1 is from 0 to 13, and it must be set to 0 when the controller operates in full-speed. See the programming guide for DEPCFG command section 3.2.2.1 (v3.30a).

---
 drivers/usb/dwc3/gadget.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +11 -1
@@ -593,7 +593,17 @@ static int dwc3_gadget_set_ep_config(str
 		params.param0 |= DWC3_DEPCFG_FIFO_NUMBER(dep->number >> 1);
 
 	if (desc->bInterval) {
-		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(desc->bInterval - 1);
+		u8 bInterval_m1;
+
+		/*
+		 * Valid range for DEPCFG.bInterval_m1 is from 0 to 13, and it
+		 * must be set to 0 when the controller operates in full-speed.
+		 */
+		bInterval_m1 = min_t(u8, desc->bInterval - 1, 13);
+		if (dwc->gadget.speed == USB_SPEED_FULL)
+			bInterval_m1 = 0;
+
+		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(bInterval_m1);
 		dep->interval = 1 << (desc->bInterval - 1);
 	}
 
author maintainer
#213 lore raw

PATCH 189/247 usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt

In reply to Greg Kroah-Hartman

From: Thinh Nguyen <[email protected]>

commit 4b049f55ed95cd889bcdb3034fd75e1f01852b38 upstream.

The dep->interval captures the number of frames/microframes per interval from bInterval. Fullspeed interrupt endpoint bInterval is the number of frames per interval and not 2^(bInterval - 1). So fix it here. This change is only for debugging purpose and should not affect the interrupt endpoint operation.

---
 drivers/usb/dwc3/gadget.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +6 -1
@@ -603,8 +603,13 @@ static int dwc3_gadget_set_ep_config(str
 		if (dwc->gadget.speed == USB_SPEED_FULL)
 			bInterval_m1 = 0;
 
+		if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
+		    dwc->gadget.speed == USB_SPEED_FULL)
+			dep->interval = desc->bInterval;
+		else
+			dep->interval = 1 << (desc->bInterval - 1);
+
 		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(bInterval_m1);
-		dep->interval = 1 << (desc->bInterval - 1);
 	}
 
 	return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, &params);
author maintainer
#214 lore raw

PATCH 190/247 USB: serial: ftdi_sio: fix FTX sub-integer prescaler

In reply to Greg Kroah-Hartman

From: Johan Hovold <[email protected]>

commit 528222d0c8ce93e435a95cd1e476b60409dd5381 upstream.

The most-significant bit of the sub-integer-prescaler index is set in the high byte of the baudrate request wIndex also for FTX devices.

This fixes rates like 1152000 which got mapped to 1.2 MBd.

---
 drivers/usb/serial/ftdi_sio.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/serial/ftdi_sio.c +3 -2
@@ -1370,8 +1370,9 @@ static int change_speed(struct tty_struc
 	index_value = get_ftdi_divisor(tty, port);
 	value = (u16)index_value;
 	index = (u16)(index_value >> 16);
-	if ((priv->chip_type == FT2232C) || (priv->chip_type == FT2232H) ||
-		(priv->chip_type == FT4232H) || (priv->chip_type == FT232H)) {
+	if (priv->chip_type == FT2232C || priv->chip_type == FT2232H ||
+			priv->chip_type == FT4232H || priv->chip_type == FT232H ||
+			priv->chip_type == FTX) {
 		/* Probably the BM type needs the MSB of the encoded fractional
 		 * divider also moved like for the chips above. Any infos? */
 		index = (u16)((index << 8) | priv->interface);
author maintainer
#215 lore raw

PATCH 191/247 USB: serial: mos7840: fix error code in mos7840_write()

In reply to Greg Kroah-Hartman

From: Dan Carpenter <[email protected]>

commit a70aa7dc60099bbdcbd6faca42a915d80f31161e upstream.

This should return -ENOMEM instead of 0 if the kmalloc() fails.

Fixes 3f5429746d91 ("USB: Moschip 7840 USB-Serial Driver")
---
 drivers/usb/serial/mos7840.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/serial/mos7840.c +3 -1
@@ -1340,8 +1340,10 @@ static int mos7840_write(struct tty_stru
 	if (urb->transfer_buffer == NULL) {
 		urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
 					       GFP_ATOMIC);
-		if (!urb->transfer_buffer)
+		if (!urb->transfer_buffer) {
+			bytes_sent = -ENOMEM;
 			goto exit;
+		}
 	}
 	transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
 
author maintainer
#216 lore raw

PATCH 192/247 USB: serial: mos7720: fix error code in mos7720_write()

In reply to Greg Kroah-Hartman

From: Dan Carpenter <[email protected]>

commit fea7372cbc40869876df0f045e367f6f97a1666c upstream.

This code should return -ENOMEM if the kmalloc() fails but instead it returns success.

Fixes 0f64478cbc7a ("USB: add USB serial mos7720 driver")
---
 drivers/usb/serial/mos7720.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/serial/mos7720.c +3 -1
@@ -1250,8 +1250,10 @@ static int mos7720_write(struct tty_stru
 	if (urb->transfer_buffer == NULL) {
 		urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
 					       GFP_ATOMIC);
-		if (!urb->transfer_buffer)
+		if (!urb->transfer_buffer) {
+			bytes_sent = -ENOMEM;
 			goto exit;
+		}
 	}
 	transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
 
author maintainer
#217 lore raw

PATCH 193/247 ALSA: hda/realtek: modify EAPD in the ALC886

In reply to Greg Kroah-Hartman

From: PeiSen Hou <[email protected]>

commit 4841b8e6318a7f0ae57c4e5ec09032ea057c97a8 upstream.

Modify 0x20 index 7 bit 5 to 1, make the 0x15 EAPD the same as 0x14.

---
 sound/pci/hda/patch_realtek.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
sound/pci/hda/patch_realtek.c +11 -0
@@ -1880,6 +1880,7 @@ enum {
 	ALC889_FIXUP_FRONT_HP_NO_PRESENCE,
 	ALC889_FIXUP_VAIO_TT,
 	ALC888_FIXUP_EEE1601,
+	ALC886_FIXUP_EAPD,
 	ALC882_FIXUP_EAPD,
 	ALC883_FIXUP_EAPD,
 	ALC883_FIXUP_ACER_EAPD,
@@ -2213,6 +2214,15 @@ static const struct hda_fixup alc882_fix
 			{ }
 		}
 	},
+	[ALC886_FIXUP_EAPD] = {
+		.type = HDA_FIXUP_VERBS,
+		.v.verbs = (const struct hda_verb[]) {
+			/* change to EAPD mode */
+			{ 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
+			{ 0x20, AC_VERB_SET_PROC_COEF, 0x0068 },
+			{ }
+		}
+	},
 	[ALC882_FIXUP_EAPD] = {
 		.type = HDA_FIXUP_VERBS,
 		.v.verbs = (const struct hda_verb[]) {
@@ -2485,6 +2495,7 @@ static const struct snd_pci_quirk alc882
 	SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_MBA11_VREF),
 
 	SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
+	SND_PCI_QUIRK(0x13fe, 0x1009, "Advantech MIT-W101", ALC886_FIXUP_EAPD),
 	SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3/Z87X-UD3H", ALC889_FIXUP_FRONT_HP_NO_PRESENCE),
 	SND_PCI_QUIRK(0x1458, 0xa0b8, "Gigabyte AZ370-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS),
 	SND_PCI_QUIRK(0x1458, 0xa0cd, "Gigabyte X570 Aorus Master", ALC1220_FIXUP_CLEVO_P950),
author maintainer
#218 lore raw

PATCH 194/247 tpm_tis: Fix check_locality for correct locality acquisition

In reply to Greg Kroah-Hartman

From: James Bottomley <[email protected]>

commit 3d9ae54af1d02a7c0edc55c77d7df2b921e58a87 upstream.

The TPM TIS specification says the TPM signals the acquisition of locality when the TMP_ACCESS_REQUEST_USE bit goes to one *and* the TPM_ACCESS_REQUEST_USE bit goes to zero. Currently we only check the former not the latter, so check both. Adding the check on TPM_ACCESS_REQUEST_USE should fix the case where the locality is re-requested before the TPM has released it. In this case the locality may get released briefly before it is reacquired, which causes all sorts of problems. However, with the added check, TPM_ACCESS_REQUEST_USE should remain 1 until the second request for the locality is granted.

Fixes 27084efee0c3 ("[PATCH] tpm: driver for next generation TPM chips")
---
 drivers/char/tpm/tpm_tis_core.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +2 -1
@@ -129,7 +129,8 @@ static bool check_locality(struct tpm_ch
 	if (rc < 0)
 		return false;
 
-	if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
+	if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID
+		       | TPM_ACCESS_REQUEST_USE)) ==
 	    (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
 		priv->locality = l;
 		return true;
author maintainer
#219 lore raw

PATCH 195/247 tpm_tis: Clean up locality release

In reply to Greg Kroah-Hartman

From: James Bottomley <[email protected]>

commit e42acf104d6e0bd7ccd2f09103d5be5e6d3c637c upstream.

The current release locality code seems to be based on the misunderstanding that the TPM interrupts when a locality is released:
it doesn't, only when the locality is acquired.

Furthermore, there seems to be no point in waiting for the locality to be released. All it does is penalize the last TPM user. However, if there's no next TPM user, this is a pointless wait and if there is a next TPM user, they'll pay the penalty waiting for the new locality (or possibly not if it's the same as the old locality).

Fix the code by making release_locality as simple write to release with no waiting for completion.

Fixes 33bafe90824b ("tpm_tis: verify locality released before returning from release_locality")
---
 drivers/char/tpm/tpm_tis_core.c |   47 ----------------------------------------
 1 file changed, 1 insertion(+), 46 deletions(-)
drivers/char/tpm/tpm_tis_core.c +1 -46
@@ -139,58 +139,13 @@ static bool check_locality(struct tpm_ch
 	return false;
 }
 
-static bool locality_inactive(struct tpm_chip *chip, int l)
-{
-	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
-	int rc;
-	u8 access;
-
-	rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
-	if (rc < 0)
-		return false;
-
-	if ((access & (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY))
-	    == TPM_ACCESS_VALID)
-		return true;
-
-	return false;
-}
-
 static int release_locality(struct tpm_chip *chip, int l)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
-	unsigned long stop, timeout;
-	long rc;
 
 	tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY);
 
-	stop = jiffies + chip->timeout_a;
-
-	if (chip->flags & TPM_CHIP_FLAG_IRQ) {
-again:
-		timeout = stop - jiffies;
-		if ((long)timeout <= 0)
-			return -1;
-
-		rc = wait_event_interruptible_timeout(priv->int_queue,
-						      (locality_inactive(chip, l)),
-						      timeout);
-
-		if (rc > 0)
-			return 0;
-
-		if (rc == -ERESTARTSYS && freezing(current)) {
-			clear_thread_flag(TIF_SIGPENDING);
-			goto again;
-		}
-	} else {
-		do {
-			if (locality_inactive(chip, l))
-				return 0;
-			tpm_msleep(TPM_TIMEOUT);
-		} while (time_before(jiffies, stop));
-	}
-	return -1;
+	return 0;
 }
 
 static int request_locality(struct tpm_chip *chip, int l)
author maintainer
#220 lore raw

PATCH 196/247 KEYS: trusted: Fix migratable=1 failing

In reply to Greg Kroah-Hartman

From: Jarkko Sakkinen <[email protected]>

commit 8da7520c80468c48f981f0b81fc1be6599e3b0ad upstream.

Consider the following transcript:

$ keyctl add trusted kmk "new 32 blobauth=helloworld keyhandle=80000000 migratable=1" @u
add_key: Invalid argument

The documentation has the following description:

migratable= 0|1 indicating permission to reseal to new PCR values,
default 1 (resealing allowed)

The consequence is that "migratable=1" should succeed. Fix this by allowing this condition to pass instead of return -EINVAL.

[*] Documentation/security/keys/trusted-encrypted.rst

Cc "James E.J. Bottomley" <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc David Howells <[email protected]>
Fixes d00a1c72f7f4 ("keys: add new trusted key-type")
---
 security/keys/trusted.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/trusted.c +1 -1
@@ -796,7 +796,7 @@ static int getoptions(char *c, struct tr
 		case Opt_migratable:
 			if (*args[0].from == '0')
 				pay->migratable = 0;
-			else
+			else if (*args[0].from != '1')
 				return -EINVAL;
 			break;
 		case Opt_pcrlock:
author maintainer
#221 lore raw

PATCH 197/247 btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root

In reply to Greg Kroah-Hartman

From: Josef Bacik <[email protected]>

commit 867ed321f90d06aaba84e2c91de51cd3038825ef upstream.

While testing my error handling patches, I added a error injection site at btrfs_inc_extent_ref, to validate the error handling I added was doing the correct thing. However I hit a pretty ugly corruption while doing this check, with the following error injection stack trace:

btrfs_inc_extent_ref
btrfs_copy_root
create_reloc_root
btrfs_init_reloc_root
btrfs_record_root_in_trans
btrfs_start_transaction
btrfs_update_inode
btrfs_update_time
touch_atime
file_accessed
btrfs_file_mmap

This is because we do not catch the error from btrfs_inc_extent_ref, which in practice would be ENOMEM, which means we lose the extent references for a root that has already been allocated and inserted, which is the problem. Fix this by aborting the transaction if we fail to do the reference modification.

---
 fs/btrfs/ctree.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/ctree.c +3 -2
@@ -267,9 +267,10 @@ int btrfs_copy_root(struct btrfs_trans_h
 		ret = btrfs_inc_ref(trans, root, cow, 1);
 	else
 		ret = btrfs_inc_ref(trans, root, cow, 0);
-
-	if (ret)
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
 		return ret;
+	}
 
 	btrfs_mark_buffer_dirty(cow);
 	*cow_ret = cow;
author maintainer
#222 lore raw

PATCH 198/247 btrfs: fix reloc root leak with 0 ref reloc roots on recovery

In reply to Greg Kroah-Hartman

From: Josef Bacik <[email protected]>

commit c78a10aebb275c38d0cfccae129a803fe622e305 upstream.

When recovering a relocation, if we run into a reloc root that has 0 refs we simply add it to the reloc_control->reloc_roots list, and then clean it up later. The problem with this is __del_reloc_root() doesn't do anything if the root isn't in the radix tree, which in this case it won't be because we never call __add_reloc_root() on the reloc_root.

This exit condition simply isn't correct really. During normal operation we can remove ourselves from the rb tree and then we're meant to clean up later at merge_reloc_roots() time, and this happens correctly. During recovery we're depending on free_reloc_roots() to drop our references, but we're short-circuiting.

Fix this by continuing to check if we're on the list and dropping ourselves from the reloc_control root list and dropping our reference appropriately. Change the corresponding BUG_ON() to an ASSERT() that does the correct thing if we aren't in the rb tree.

---
 fs/btrfs/relocation.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/relocation.c +1 -3
@@ -1291,9 +1291,7 @@ static void __del_reloc_root(struct btrf
 			RB_CLEAR_NODE(&node->rb_node);
 		}
 		spin_unlock(&rc->reloc_root_tree.lock);
-		if (!node)
-			return;
-		BUG_ON((struct btrfs_root *)node->data != root);
+		ASSERT(!node || (struct btrfs_root *)node->data == root);
 	}
 
 	spin_lock(&fs_info->trans_lock);
author maintainer
#223 lore raw

PATCH 199/247 btrfs: fix extent buffer leak on failure to copy root

In reply to Greg Kroah-Hartman

From: Filipe Manana <[email protected]>

commit 72c9925f87c8b74f36f8e75a4cd93d964538d3ca upstream.

At btrfs_copy_root(), if the call to btrfs_inc_ref() fails we end up returning without unlocking and releasing our reference on the extent buffer named "cow" we previously allocated with btrfs_alloc_tree_block().

So fix that by unlocking the extent buffer and dropping our reference on it before returning.

Fixes be20aa9dbadc8c ("Btrfs: Add mount option to turn off data cow")
---
 fs/btrfs/ctree.c |    2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/ctree.c +2 -0
@@ -268,6 +268,8 @@ int btrfs_copy_root(struct btrfs_trans_h
 	else
 		ret = btrfs_inc_ref(trans, root, cow, 0);
 	if (ret) {
+		btrfs_tree_unlock(cow);
+		free_extent_buffer(cow);
 		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
author maintainer
#224 lore raw

PATCH 200/247 crypto: arm64/sha - add missing module aliases

In reply to Greg Kroah-Hartman

From: Ard Biesheuvel <[email protected]>

commit 0df07d8117c3576f1603b05b84089742a118d10a upstream.

The accelerated, instruction based implementations of SHA1, SHA2 and SHA3 are autoloaded based on CPU capabilities, given that the code is modest in size, and widely used, which means that resolving the algo name, loading all compatible modules and picking the one with the highest priority is taken to be suboptimal.

However, if these algorithms are requested before this CPU feature based matching and autoloading occurs, these modules are not even considered, and we end up with suboptimal performance.

So add the missing module aliases for the various SHA implementations.

---
 arch/arm64/crypto/sha1-ce-glue.c   |    1 +
 arch/arm64/crypto/sha2-ce-glue.c   |    2 ++
 arch/arm64/crypto/sha3-ce-glue.c   |    4 ++++
 arch/arm64/crypto/sha512-ce-glue.c |    2 ++
 4 files changed, 9 insertions(+)
arch/arm64/crypto/sha1-ce-glue.c +1 -0
@@ -21,6 +21,7 @@
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
 MODULE_LICENSE("GPL v2");
+MODULE_ALIAS_CRYPTO("sha1");
 
 struct sha1_ce_state {
 	struct sha1_state	sst;
arch/arm64/crypto/sha2-ce-glue.c +2 -0
@@ -21,6 +21,8 @@
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
 MODULE_LICENSE("GPL v2");
+MODULE_ALIAS_CRYPTO("sha224");
+MODULE_ALIAS_CRYPTO("sha256");
 
 struct sha256_ce_state {
 	struct sha256_state	sst;
arch/arm64/crypto/sha3-ce-glue.c +4 -0
@@ -22,6 +22,10 @@
 MODULE_DESCRIPTION("SHA3 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
 MODULE_LICENSE("GPL v2");
+MODULE_ALIAS_CRYPTO("sha3-224");
+MODULE_ALIAS_CRYPTO("sha3-256");
+MODULE_ALIAS_CRYPTO("sha3-384");
+MODULE_ALIAS_CRYPTO("sha3-512");
 
 asmlinkage void sha3_ce_transform(u64 *st, const u8 *data, int blocks,
 				  int md_len);
arch/arm64/crypto/sha512-ce-glue.c +2 -0
@@ -22,6 +22,8 @@
 MODULE_DESCRIPTION("SHA-384/SHA-512 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
 MODULE_LICENSE("GPL v2");
+MODULE_ALIAS_CRYPTO("sha384");
+MODULE_ALIAS_CRYPTO("sha512");
 
 asmlinkage void sha512_ce_transform(struct sha512_state *sst, u8 const *src,
 				    int blocks);
author maintainer
#225 lore raw

PATCH 201/247 crypto: sun4i-ss - checking sg length is not sufficient

In reply to Greg Kroah-Hartman

From: Corentin Labbe <[email protected]>

commit 7bdcd851fa7eb66e8922aa7f6cba9e2f2427a7cf upstream.

The optimized cipher function need length multiple of 4 bytes. But it get sometimes odd length.
This is due to SG data could be stored with an offset.

So the fix is to check also if the offset is aligned with 4 bytes.

Fixes 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +2 -2
@@ -189,12 +189,12 @@ static int sun4i_ss_cipher_poll(struct s
 	 * we can use the SS optimized function
 	 */
 	while (in_sg && no_chunk == 1) {
-		if (in_sg->length % 4)
+		if ((in_sg->length | in_sg->offset) & 3u)
 			no_chunk = 0;
 		in_sg = sg_next(in_sg);
 	}
 	while (out_sg && no_chunk == 1) {
-		if (out_sg->length % 4)
+		if ((out_sg->length | out_sg->offset) & 3u)
 			no_chunk = 0;
 		out_sg = sg_next(out_sg);
 	}
author maintainer
#226 lore raw

PATCH 202/247 crypto: sun4i-ss - IV register does not work on A10 and A13

In reply to Greg Kroah-Hartman

From: Corentin Labbe <[email protected]>

commit b756f1c8fc9d84e3f546d7ffe056c5352f4aab05 upstream.

Allwinner A10 and A13 SoC have a version of the SS which produce invalid IV in IVx register.

Instead of adding a variant for those, let's convert SS to produce IV directly from data.

Fixes 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c |   34 ++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)
drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +28 -6
@@ -24,6 +24,7 @@ static int sun4i_ss_opti_poll(struct skc
 	unsigned int ivsize = crypto_skcipher_ivsize(tfm);
 	struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
 	u32 mode = ctx->mode;
+	void *backup_iv = NULL;
 	/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
 	u32 rx_cnt = SS_RX_DEFAULT;
 	u32 tx_cnt = 0;
@@ -53,6 +54,13 @@ static int sun4i_ss_opti_poll(struct skc
 		return -EINVAL;
 	}
 
+	if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+		backup_iv = kzalloc(ivsize, GFP_KERNEL);
+		if (!backup_iv)
+			return -ENOMEM;
+		scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0);
+	}
+
 	spin_lock_irqsave(&ss->slock, flags);
 
 	for (i = 0; i < op->keylen; i += 4)
@@ -126,9 +134,12 @@ static int sun4i_ss_opti_poll(struct skc
 	} while (oleft);
 
 	if (areq->iv) {
-		for (i = 0; i < 4 && i < ivsize / 4; i++) {
-			v = readl(ss->base + SS_IV0 + i * 4);
-			*(u32 *)(areq->iv + i * 4) = v;
+		if (mode & SS_DECRYPTION) {
+			memcpy(areq->iv, backup_iv, ivsize);
+			kfree_sensitive(backup_iv);
+		} else {
+			scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize,
+						 ivsize, 0);
 		}
 	}
 
@@ -160,6 +171,7 @@ static int sun4i_ss_cipher_poll(struct s
 	unsigned int ileft = areq->cryptlen;
 	unsigned int oleft = areq->cryptlen;
 	unsigned int todo;
+	void *backup_iv = NULL;
 	struct sg_mapping_iter mi, mo;
 	unsigned long pi = 0, po = 0; /* progress for in and out */
 	bool miter_err;
@@ -202,6 +214,13 @@ static int sun4i_ss_cipher_poll(struct s
 	if (no_chunk == 1)
 		return sun4i_ss_opti_poll(areq);
 
+	if (areq->iv && ivsize > 0 && mode & SS_DECRYPTION) {
+		backup_iv = kzalloc(ivsize, GFP_KERNEL);
+		if (!backup_iv)
+			return -ENOMEM;
+		scatterwalk_map_and_copy(backup_iv, areq->src, areq->cryptlen - ivsize, ivsize, 0);
+	}
+
 	spin_lock_irqsave(&ss->slock, flags);
 
 	for (i = 0; i < op->keylen; i += 4)
@@ -330,9 +349,12 @@ static int sun4i_ss_cipher_poll(struct s
 		sg_miter_stop(&mo);
 	}
 	if (areq->iv) {
-		for (i = 0; i < 4 && i < ivsize / 4; i++) {
-			v = readl(ss->base + SS_IV0 + i * 4);
-			*(u32 *)(areq->iv + i * 4) = v;
+		if (mode & SS_DECRYPTION) {
+			memcpy(areq->iv, backup_iv, ivsize);
+			kfree_sensitive(backup_iv);
+		} else {
+			scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize,
+						 ivsize, 0);
 		}
 	}
 
author maintainer
#227 lore raw

PATCH 203/247 crypto: sun4i-ss - handle BigEndian for cipher

In reply to Greg Kroah-Hartman

From: Corentin Labbe <[email protected]>

commit 5ab6177fa02df15cd8a02a1f1fb361d2d5d8b946 upstream.

Ciphers produce invalid results on BE.
Key and IV need to be written in LE.

Fixes 6298e948215f2 ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +6 -6
@@ -63,13 +63,13 @@ static int sun4i_ss_opti_poll(struct skc
 
 	spin_lock_irqsave(&ss->slock, flags);
 
-	for (i = 0; i < op->keylen; i += 4)
-		writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+	for (i = 0; i < op->keylen / 4; i++)
+		writesl(ss->base + SS_KEY0 + i * 4, &op->key[i], 1);
 
 	if (areq->iv) {
 		for (i = 0; i < 4 && i < ivsize / 4; i++) {
 			v = *(u32 *)(areq->iv + i * 4);
-			writel(v, ss->base + SS_IV0 + i * 4);
+			writesl(ss->base + SS_IV0 + i * 4, &v, 1);
 		}
 	}
 	writel(mode, ss->base + SS_CTL);
@@ -223,13 +223,13 @@ static int sun4i_ss_cipher_poll(struct s
 
 	spin_lock_irqsave(&ss->slock, flags);
 
-	for (i = 0; i < op->keylen; i += 4)
-		writel(*(op->key + i / 4), ss->base + SS_KEY0 + i);
+	for (i = 0; i < op->keylen / 4; i++)
+		writesl(ss->base + SS_KEY0 + i * 4, &op->key[i], 1);
 
 	if (areq->iv) {
 		for (i = 0; i < 4 && i < ivsize / 4; i++) {
 			v = *(u32 *)(areq->iv + i * 4);
-			writel(v, ss->base + SS_IV0 + i * 4);
+			writesl(ss->base + SS_IV0 + i * 4, &v, 1);
 		}
 	}
 	writel(mode, ss->base + SS_CTL);
author maintainer
#228 lore raw

PATCH 204/247 seccomp: Add missing return in non-void function

In reply to Greg Kroah-Hartman

From: Paul Cercueil <[email protected]>

commit 04b38d012556199ba4c31195940160e0c44c64f0 upstream.

We don't actually care about the value, since the kernel will panic before that; but a value should nonetheless be returned, otherwise the compiler will complain.

---
 kernel/seccomp.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/seccomp.c +2 -0
@@ -771,6 +771,8 @@ static int __seccomp_filter(int this_sys
 			    const bool recheck_after_trace)
 {
 	BUG();
+
+	return -1;
 }
 #endif
 
author maintainer
#229 lore raw

PATCH 205/247 misc: rtsx: init of rts522a add OCP power off when no card is present

In reply to Greg Kroah-Hartman

From: Ricky Wu <[email protected]>

commit 920fd8a70619074eac7687352c8f1c6f3c2a64a5 upstream.

Power down OCP for power consumption
when no SD/MMC card is present

---
 drivers/misc/cardreader/rts5227.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/misc/cardreader/rts5227.c +5 -0
@@ -339,6 +339,11 @@ static int rts522a_extra_init_hw(struct
 {
 	rts5227_extra_init_hw(pcr);
 
+	/* Power down OCP for power consumption */
+	if (!pcr->card_exist)
+		rtsx_pci_write_register(pcr, FPDCTL, OC_POWER_DOWN,
+				OC_POWER_DOWN);
+
 	rtsx_pci_write_register(pcr, FUNC_FORCE_CTL, FUNC_FORCE_UPME_XMT_DBG,
 		FUNC_FORCE_UPME_XMT_DBG);
 	rtsx_pci_write_register(pcr, PCLK_CTL, 0x04, 0x04);
author maintainer
#230 lore raw

PATCH 206/247 drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue

In reply to Greg Kroah-Hartman

From: Sabyrzhan Tasbolatov <[email protected]>

commit 2fd10bcf0310b9525b2af9e1f7aa9ddd87c3772e upstream.

syzbot found WARNING in qp_broker_alloc[1] in qp_host_alloc_queue() when num_pages is 0x100001, giving queue_size + queue_page_size bigger than KMALLOC_MAX_SIZE for kzalloc(), resulting order >= MAX_ORDER condition.

queue_size + queue_page_size=0x8000d8, where KMALLOC_MAX_SIZE=0x400000.

[1]

Call Trace:
 alloc_pages include/linux/gfp.h:547 [inline]
 kmalloc_order+0x40/0x130 mm/slab_common.c:837
 kmalloc_order_trace+0x15/0x70 mm/slab_common.c:853
 kmalloc_large include/linux/slab.h:481 [inline]
 __kmalloc+0x257/0x330 mm/slub.c:3959
 kmalloc include/linux/slab.h:557 [inline]
 kzalloc include/linux/slab.h:682 [inline]
 qp_host_alloc_queue drivers/misc/vmw_vmci/vmci_queue_pair.c:540 [inline]
 qp_broker_create drivers/misc/vmw_vmci/vmci_queue_pair.c:1351 [inline]
 qp_broker_alloc+0x936/0x2740 drivers/misc/vmw_vmci/vmci_queue_pair.c:1739
---
 drivers/misc/vmw_vmci/vmci_queue_pair.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/misc/vmw_vmci/vmci_queue_pair.c +3 -0
@@ -552,6 +552,9 @@ static struct vmci_queue *qp_host_alloc_
 
 	queue_page_size = num_pages * sizeof(*queue->kernel_if->u.h.page);
 
+	if (queue_size + queue_page_size > KMALLOC_MAX_SIZE)
+		return NULL;
+
 	queue = kzalloc(queue_size + queue_page_size, GFP_KERNEL);
 	if (queue) {
 		queue->q_header = NULL;
author maintainer
#231 lore raw

PATCH 207/247 pstore: Fix typo in compression option name

In reply to Greg Kroah-Hartman

From: Jiri Bohac <[email protected]>

commit 19d8e9149c27b689c6224f5c84b96a159342195a upstream.

Both pstore_compress() and decompress_record() use a mistyped config option name ("PSTORE_COMPRESSION" instead of "PSTORE_COMPRESS"). As a result compression and decompression of pstore records was always disabled.

Use the correct config option name.

---
 fs/pstore/platform.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/platform.c +2 -2
@@ -250,7 +250,7 @@ static int pstore_compress(const void *i
 {
 	int ret;
 
-	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESSION))
+	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS))
 		return -EINVAL;
 
 	ret = crypto_comp_compress(tfm, in, inlen, out, &outlen);
@@ -650,7 +650,7 @@ static void decompress_record(struct pst
 	int unzipped_len;
 	char *decompressed;
 
-	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESSION) || !record->compressed)
+	if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !record->compressed)
 		return;
 
 	/* Only PSTORE_TYPE_DMESG support compression. */
author maintainer
#232 lore raw

PATCH 208/247 dts64: mt7622: fix slow sd card access

In reply to Greg Kroah-Hartman

From: Frank Wunderlich <[email protected]>

commit dc2e76175417e69c41d927dba75a966399f18354 upstream.

Fix extreme slow speed (200MB takes ~20 min) on writing sdcard on bananapi-r64 by adding reset-control for mmc1 like it's done for mmc0/emmc.

---
 arch/arm64/boot/dts/mediatek/mt7622.dtsi |    2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/mediatek/mt7622.dtsi +2 -0
@@ -641,6 +641,8 @@
 		clocks = <&pericfg CLK_PERI_MSDC30_1_PD>,
 			 <&topckgen CLK_TOP_AXI_SEL>;
 		clock-names = "source", "hclk";
+		resets = <&pericfg MT7622_PERI_MSDC1_SW_RST>;
+		reset-names = "hrst";
 		status = "disabled";
 	};
 
author maintainer
#233 lore raw

PATCH 209/247 staging/mt7621-dma: mtk-hsdma.c->hsdma-mt7621.c

In reply to Greg Kroah-Hartman

From: Ilya Lipnitskiy <[email protected]>

commit 1f92798cbe7fe923479cff754dd06dd23d352e36 upstream.

Also use KBUILD_MODNAME for module name.

This driver is only used by RALINK MIPS MT7621 SoCs. Tested by building against that target using OpenWrt with Linux 5.10.10.

Fixes the following error:
error: the following would cause module name conflict:
drivers/dma/mediatek/mtk-hsdma.ko drivers/staging/mt7621-dma/mtk-hsdma.ko

---
 drivers/staging/mt7621-dma/Makefile       |    2 
 drivers/staging/mt7621-dma/hsdma-mt7621.c |  771 ++++++++++++++++++++++++++++++
 drivers/staging/mt7621-dma/mtk-hsdma.c    |  771 ------------------------------
 3 files changed, 772 insertions(+), 772 deletions(-)
 rename drivers/staging/mt7621-dma/{mtk-hsdma.c => hsdma-mt7621.c} (99%)
drivers/staging/mt7621-dma/Makefile +1 -1
@@ -1,4 +1,4 @@
 obj-$(CONFIG_DMA_RALINK) += ralink-gdma.o
-obj-$(CONFIG_MTK_HSDMA) += mtk-hsdma.o
+obj-$(CONFIG_MTK_HSDMA) += hsdma-mt7621.o
 
 ccflags-y += -I$(srctree)/drivers/dma
drivers/staging/mt7621-dma/hsdma-mt7621.c new file +771 -0

771 lines not on this page · raw message

drivers/staging/mt7621-dma/mtk-hsdma.c deleted +0 -771

771 lines not on this page · raw message

#234 lore raw

Re: [PATCH 4.19 209/247] staging/mt7621-dma: mtk-hsdma.c->hsdma-mt7621.c

Sorry, I should have been more clear in my original email, but we don't strictly need this in 4.19 as the check only became fatal in 5.10 (actually, before 5.10, but 5.10 is the first stable release with it). Feel free to take or omit this from 4.19.

Quoted 1,585 lines · Greg Kroah-Hartman

From: Ilya Lipnitskiy <[email protected]>

commit 1f92798cbe7fe923479cff754dd06dd23d352e36 upstream.

Also use KBUILD_MODNAME for module name.

This driver is only used by RALINK MIPS MT7621 SoCs. Tested by building against that target using OpenWrt with Linux 5.10.10.

Fixes the following error:
error: the following would cause module name conflict:
drivers/dma/mediatek/mtk-hsdma.ko drivers/staging/mt7621-dma/mtk-hsdma.ko

---
 drivers/staging/mt7621-dma/Makefile       |    2
 drivers/staging/mt7621-dma/hsdma-mt7621.c |  771 ++++++++++++++++++++++++++++++
 drivers/staging/mt7621-dma/mtk-hsdma.c    |  771 ------------------------------
 3 files changed, 772 insertions(+), 772 deletions(-)
 rename drivers/staging/mt7621-dma/{mtk-hsdma.c => hsdma-mt7621.c} (99%)
drivers/staging/mt7621-dma/Makefile +1 -1
@@ -1,4 +1,4 @@
 obj-$(CONFIG_DMA_RALINK) += ralink-gdma.o
-obj-$(CONFIG_MTK_HSDMA) += mtk-hsdma.o
+obj-$(CONFIG_MTK_HSDMA) += hsdma-mt7621.o
 
 ccflags-y += -I$(srctree)/drivers/dma
drivers/staging/mt7621-dma/hsdma-mt7621.c new file +771 -0
@@ -0,0 +1,771 @@
+/*
+ *  Copyright (C) 2015, Michael Lee <[email protected]>
+ *  MTK HSDMA support
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under  the terms of the GNU General         Public License as published by the
+ *  Free Software Foundation;  either version 2 of the License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/irq.h>
+#include <linux/of_dma.h>
+#include <linux/reset.h>
+#include <linux/of_device.h>
+
+#include "virt-dma.h"
+
+#define HSDMA_BASE_OFFSET              0x800
+
+#define HSDMA_REG_TX_BASE              0x00
+#define HSDMA_REG_TX_CNT               0x04
+#define HSDMA_REG_TX_CTX               0x08
+#define HSDMA_REG_TX_DTX               0x0c
+#define HSDMA_REG_RX_BASE              0x100
+#define HSDMA_REG_RX_CNT               0x104
+#define HSDMA_REG_RX_CRX               0x108
+#define HSDMA_REG_RX_DRX               0x10c
+#define HSDMA_REG_INFO                 0x200
+#define HSDMA_REG_GLO_CFG              0x204
+#define HSDMA_REG_RST_CFG              0x208
+#define HSDMA_REG_DELAY_INT            0x20c
+#define HSDMA_REG_FREEQ_THRES          0x210
+#define HSDMA_REG_INT_STATUS           0x220
+#define HSDMA_REG_INT_MASK             0x228
+#define HSDMA_REG_SCH_Q01              0x280
+#define HSDMA_REG_SCH_Q23              0x284
+
+#define HSDMA_DESCS_MAX                        0xfff
+#define HSDMA_DESCS_NUM                        8
+#define HSDMA_DESCS_MASK               (HSDMA_DESCS_NUM - 1)
+#define HSDMA_NEXT_DESC(x)             (((x) + 1) & HSDMA_DESCS_MASK)
+
+/* HSDMA_REG_INFO */
+#define HSDMA_INFO_INDEX_MASK          0xf
+#define HSDMA_INFO_INDEX_SHIFT         24
+#define HSDMA_INFO_BASE_MASK           0xff
+#define HSDMA_INFO_BASE_SHIFT          16
+#define HSDMA_INFO_RX_MASK             0xff
+#define HSDMA_INFO_RX_SHIFT            8
+#define HSDMA_INFO_TX_MASK             0xff
+#define HSDMA_INFO_TX_SHIFT            0
+
+/* HSDMA_REG_GLO_CFG */
+#define HSDMA_GLO_TX_2B_OFFSET         BIT(31)
+#define HSDMA_GLO_CLK_GATE             BIT(30)
+#define HSDMA_GLO_BYTE_SWAP            BIT(29)
+#define HSDMA_GLO_MULTI_DMA            BIT(10)
+#define HSDMA_GLO_TWO_BUF              BIT(9)
+#define HSDMA_GLO_32B_DESC             BIT(8)
+#define HSDMA_GLO_BIG_ENDIAN           BIT(7)
+#define HSDMA_GLO_TX_DONE              BIT(6)
+#define HSDMA_GLO_BT_MASK              0x3
+#define HSDMA_GLO_BT_SHIFT             4
+#define HSDMA_GLO_RX_BUSY              BIT(3)
+#define HSDMA_GLO_RX_DMA               BIT(2)
+#define HSDMA_GLO_TX_BUSY              BIT(1)
+#define HSDMA_GLO_TX_DMA               BIT(0)
+
+#define HSDMA_BT_SIZE_16BYTES          (0 << HSDMA_GLO_BT_SHIFT)
+#define HSDMA_BT_SIZE_32BYTES          (1 << HSDMA_GLO_BT_SHIFT)
+#define HSDMA_BT_SIZE_64BYTES          (2 << HSDMA_GLO_BT_SHIFT)
+#define HSDMA_BT_SIZE_128BYTES         (3 << HSDMA_GLO_BT_SHIFT)
+
+#define HSDMA_GLO_DEFAULT              (HSDMA_GLO_MULTI_DMA | \
+               HSDMA_GLO_RX_DMA | HSDMA_GLO_TX_DMA | HSDMA_BT_SIZE_32BYTES)
+
+/* HSDMA_REG_RST_CFG */
+#define HSDMA_RST_RX_SHIFT             16
+#define HSDMA_RST_TX_SHIFT             0
+
+/* HSDMA_REG_DELAY_INT */
+#define HSDMA_DELAY_INT_EN             BIT(15)
+#define HSDMA_DELAY_PEND_OFFSET                8
+#define HSDMA_DELAY_TIME_OFFSET                0
+#define HSDMA_DELAY_TX_OFFSET          16
+#define HSDMA_DELAY_RX_OFFSET          0
+
+#define HSDMA_DELAY_INIT(x)            (HSDMA_DELAY_INT_EN | \
+               ((x) << HSDMA_DELAY_PEND_OFFSET))
+#define HSDMA_DELAY(x)                 ((HSDMA_DELAY_INIT(x) << \
+               HSDMA_DELAY_TX_OFFSET) | HSDMA_DELAY_INIT(x))
+
+/* HSDMA_REG_INT_STATUS */
+#define HSDMA_INT_DELAY_RX_COH         BIT(31)
+#define HSDMA_INT_DELAY_RX_INT         BIT(30)
+#define HSDMA_INT_DELAY_TX_COH         BIT(29)
+#define HSDMA_INT_DELAY_TX_INT         BIT(28)
+#define HSDMA_INT_RX_MASK              0x3
+#define HSDMA_INT_RX_SHIFT             16
+#define HSDMA_INT_RX_Q0                        BIT(16)
+#define HSDMA_INT_TX_MASK              0xf
+#define HSDMA_INT_TX_SHIFT             0
+#define HSDMA_INT_TX_Q0                        BIT(0)
+
+/* tx/rx dma desc flags */
+#define HSDMA_PLEN_MASK                        0x3fff
+#define HSDMA_DESC_DONE                        BIT(31)
+#define HSDMA_DESC_LS0                 BIT(30)
+#define HSDMA_DESC_PLEN0(_x)           (((_x) & HSDMA_PLEN_MASK) << 16)
+#define HSDMA_DESC_TAG                 BIT(15)
+#define HSDMA_DESC_LS1                 BIT(14)
+#define HSDMA_DESC_PLEN1(_x)           ((_x) & HSDMA_PLEN_MASK)
+
+/* align 4 bytes */
+#define HSDMA_ALIGN_SIZE               3
+/* align size 128bytes */
+#define HSDMA_MAX_PLEN                 0x3f80
+
+struct hsdma_desc {
+       u32 addr0;
+       u32 flags;
+       u32 addr1;
+       u32 unused;
+};
+
+struct mtk_hsdma_sg {
+       dma_addr_t src_addr;
+       dma_addr_t dst_addr;
+       u32 len;
+};
+
+struct mtk_hsdma_desc {
+       struct virt_dma_desc vdesc;
+       unsigned int num_sgs;
+       struct mtk_hsdma_sg sg[1];
+};
+
+struct mtk_hsdma_chan {
+       struct virt_dma_chan vchan;
+       unsigned int id;
+       dma_addr_t desc_addr;
+       int tx_idx;
+       int rx_idx;
+       struct hsdma_desc *tx_ring;
+       struct hsdma_desc *rx_ring;
+       struct mtk_hsdma_desc *desc;
+       unsigned int next_sg;
+};
+
+struct mtk_hsdam_engine {
+       struct dma_device ddev;
+       struct device_dma_parameters dma_parms;
+       void __iomem *base;
+       struct tasklet_struct task;
+       volatile unsigned long chan_issued;
+
+       struct mtk_hsdma_chan chan[1];
+};
+
+static inline struct mtk_hsdam_engine *mtk_hsdma_chan_get_dev(
+               struct mtk_hsdma_chan *chan)
+{
+       return container_of(chan->vchan.chan.device, struct mtk_hsdam_engine,
+                       ddev);
+}
+
+static inline struct mtk_hsdma_chan *to_mtk_hsdma_chan(struct dma_chan *c)
+{
+       return container_of(c, struct mtk_hsdma_chan, vchan.chan);
+}
+
+static inline struct mtk_hsdma_desc *to_mtk_hsdma_desc(
+               struct virt_dma_desc *vdesc)
+{
+       return container_of(vdesc, struct mtk_hsdma_desc, vdesc);
+}
+
+static inline u32 mtk_hsdma_read(struct mtk_hsdam_engine *hsdma, u32 reg)
+{
+       return readl(hsdma->base + reg);
+}
+
+static inline void mtk_hsdma_write(struct mtk_hsdam_engine *hsdma,
+                                  unsigned reg, u32 val)
+{
+       writel(val, hsdma->base + reg);
+}
+
+static void mtk_hsdma_reset_chan(struct mtk_hsdam_engine *hsdma,
+                                struct mtk_hsdma_chan *chan)
+{
+       chan->tx_idx = 0;
+       chan->rx_idx = HSDMA_DESCS_NUM - 1;
+
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CTX, chan->tx_idx);
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CRX, chan->rx_idx);
+
+       mtk_hsdma_write(hsdma, HSDMA_REG_RST_CFG,
+                       0x1 << (chan->id + HSDMA_RST_TX_SHIFT));
+       mtk_hsdma_write(hsdma, HSDMA_REG_RST_CFG,
+                       0x1 << (chan->id + HSDMA_RST_RX_SHIFT));
+}
+
+static void hsdma_dump_reg(struct mtk_hsdam_engine *hsdma)
+{
+       dev_dbg(hsdma->ddev.dev, "tbase %08x, tcnt %08x, " \
+                       "tctx %08x, tdtx: %08x, rbase %08x, " \
+                       "rcnt %08x, rctx %08x, rdtx %08x\n",
+                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_BASE),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_CNT),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_CTX),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_DTX),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_BASE),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_CNT),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_CRX),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX));
+
+       dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, " \
+                       "intr_stat %08x, intr_mask %08x\n",
+                       mtk_hsdma_read(hsdma, HSDMA_REG_INFO),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_DELAY_INT),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_INT_STATUS),
+                       mtk_hsdma_read(hsdma, HSDMA_REG_INT_MASK));
+}
+
+static void hsdma_dump_desc(struct mtk_hsdam_engine *hsdma,
+                           struct mtk_hsdma_chan *chan)
+{
+       struct hsdma_desc *tx_desc;
+       struct hsdma_desc *rx_desc;
+       int i;
+
+       dev_dbg(hsdma->ddev.dev, "tx idx: %d, rx idx: %d\n",
+                       chan->tx_idx, chan->rx_idx);
+
+       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
+               tx_desc = &chan->tx_ring[i];
+               rx_desc = &chan->rx_ring[i];
+
+               dev_dbg(hsdma->ddev.dev, "%d tx addr0: %08x, flags %08x, " \
+                               "tx addr1: %08x, rx addr0 %08x, flags %08x\n",
+                               i, tx_desc->addr0, tx_desc->flags, \
+                               tx_desc->addr1, rx_desc->addr0, rx_desc->flags);
+       }
+}
+
+static void mtk_hsdma_reset(struct mtk_hsdam_engine *hsdma,
+                           struct mtk_hsdma_chan *chan)
+{
+       int i;
+
+       /* disable dma */
+       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, 0);
+
+       /* disable intr */
+       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, 0);
+
+       /* init desc value */
+       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
+               chan->tx_ring[i].addr0 = 0;
+               chan->tx_ring[i].flags = HSDMA_DESC_LS0 |
+                       HSDMA_DESC_DONE;
+       }
+       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
+               chan->rx_ring[i].addr0 = 0;
+               chan->rx_ring[i].flags = 0;
+       }
+
+       /* reset */
+       mtk_hsdma_reset_chan(hsdma, chan);
+
+       /* enable intr */
+       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, HSDMA_INT_RX_Q0);
+
+       /* enable dma */
+       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, HSDMA_GLO_DEFAULT);
+}
+
+static int mtk_hsdma_terminate_all(struct dma_chan *c)
+{
+       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
+       struct mtk_hsdam_engine *hsdma = mtk_hsdma_chan_get_dev(chan);
+       unsigned long timeout;
+       LIST_HEAD(head);
+
+       spin_lock_bh(&chan->vchan.lock);
+       chan->desc = NULL;
+       clear_bit(chan->id, &hsdma->chan_issued);
+       vchan_get_all_descriptors(&chan->vchan, &head);
+       spin_unlock_bh(&chan->vchan.lock);
+
+       vchan_dma_desc_free_list(&chan->vchan, &head);
+
+       /* wait dma transfer complete */
+       timeout = jiffies + msecs_to_jiffies(2000);
+       while (mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG) &
+                       (HSDMA_GLO_RX_BUSY | HSDMA_GLO_TX_BUSY)) {
+               if (time_after_eq(jiffies, timeout)) {
+                       hsdma_dump_desc(hsdma, chan);
+                       mtk_hsdma_reset(hsdma, chan);
+                       dev_err(hsdma->ddev.dev, "timeout, reset it\n");
+                       break;
+               }
+               cpu_relax();
+       }
+
+       return 0;
+}
+
+static int mtk_hsdma_start_transfer(struct mtk_hsdam_engine *hsdma,
+                                   struct mtk_hsdma_chan *chan)
+{
+       dma_addr_t src, dst;
+       size_t len, tlen;
+       struct hsdma_desc *tx_desc, *rx_desc;
+       struct mtk_hsdma_sg *sg;
+       unsigned int i;
+       int rx_idx;
+
+       sg = &chan->desc->sg[0];
+       len = sg->len;
+       chan->desc->num_sgs = DIV_ROUND_UP(len, HSDMA_MAX_PLEN);
+
+       /* tx desc */
+       src = sg->src_addr;
+       for (i = 0; i < chan->desc->num_sgs; i++) {
+               tx_desc = &chan->tx_ring[chan->tx_idx];
+
+               if (len > HSDMA_MAX_PLEN)
+                       tlen = HSDMA_MAX_PLEN;
+               else
+                       tlen = len;
+
+               if (i & 0x1) {
+                       tx_desc->addr1 = src;
+                       tx_desc->flags |= HSDMA_DESC_PLEN1(tlen);
+               } else {
+                       tx_desc->addr0 = src;
+                       tx_desc->flags = HSDMA_DESC_PLEN0(tlen);
+
+                       /* update index */
+                       chan->tx_idx = HSDMA_NEXT_DESC(chan->tx_idx);
+               }
+
+               src += tlen;
+               len -= tlen;
+       }
+       if (i & 0x1)
+               tx_desc->flags |= HSDMA_DESC_LS0;
+       else
+               tx_desc->flags |= HSDMA_DESC_LS1;
+
+       /* rx desc */
+       rx_idx = HSDMA_NEXT_DESC(chan->rx_idx);
+       len = sg->len;
+       dst = sg->dst_addr;
+       for (i = 0; i < chan->desc->num_sgs; i++) {
+               rx_desc = &chan->rx_ring[rx_idx];
+               if (len > HSDMA_MAX_PLEN)
+                       tlen = HSDMA_MAX_PLEN;
+               else
+                       tlen = len;
+
+               rx_desc->addr0 = dst;
+               rx_desc->flags = HSDMA_DESC_PLEN0(tlen);
+
+               dst += tlen;
+               len -= tlen;
+
+               /* update index */
+               rx_idx = HSDMA_NEXT_DESC(rx_idx);
+       }
+
+       /* make sure desc and index all up to date */
+       wmb();
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CTX, chan->tx_idx);
+
+       return 0;
+}
+
+static int gdma_next_desc(struct mtk_hsdma_chan *chan)
+{
+       struct virt_dma_desc *vdesc;
+
+       vdesc = vchan_next_desc(&chan->vchan);
+       if (!vdesc) {
+               chan->desc = NULL;
+               return 0;
+       }
+       chan->desc = to_mtk_hsdma_desc(vdesc);
+       chan->next_sg = 0;
+
+       return 1;
+}
+
+static void mtk_hsdma_chan_done(struct mtk_hsdam_engine *hsdma,
+                               struct mtk_hsdma_chan *chan)
+{
+       struct mtk_hsdma_desc *desc;
+       int chan_issued;
+
+       chan_issued = 0;
+       spin_lock_bh(&chan->vchan.lock);
+       desc = chan->desc;
+       if (likely(desc)) {
+               if (chan->next_sg == desc->num_sgs) {
+                       list_del(&desc->vdesc.node);
+                       vchan_cookie_complete(&desc->vdesc);
+                       chan_issued = gdma_next_desc(chan);
+               }
+       } else
+               dev_dbg(hsdma->ddev.dev, "no desc to complete\n");
+
+       if (chan_issued)
+               set_bit(chan->id, &hsdma->chan_issued);
+       spin_unlock_bh(&chan->vchan.lock);
+}
+
+static irqreturn_t mtk_hsdma_irq(int irq, void *devid)
+{
+       struct mtk_hsdam_engine *hsdma = devid;
+       u32 status;
+
+       status = mtk_hsdma_read(hsdma, HSDMA_REG_INT_STATUS);
+       if (unlikely(!status))
+               return IRQ_NONE;
+
+       if (likely(status & HSDMA_INT_RX_Q0))
+               tasklet_schedule(&hsdma->task);
+       else
+               dev_dbg(hsdma->ddev.dev, "unhandle irq status %08x\n",
+                       status);
+       /* clean intr bits */
+       mtk_hsdma_write(hsdma, HSDMA_REG_INT_STATUS, status);
+
+       return IRQ_HANDLED;
+}
+
+static void mtk_hsdma_issue_pending(struct dma_chan *c)
+{
+       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
+       struct mtk_hsdam_engine *hsdma = mtk_hsdma_chan_get_dev(chan);
+
+       spin_lock_bh(&chan->vchan.lock);
+       if (vchan_issue_pending(&chan->vchan) && !chan->desc) {
+               if (gdma_next_desc(chan)) {
+                       set_bit(chan->id, &hsdma->chan_issued);
+                       tasklet_schedule(&hsdma->task);
+               } else
+                       dev_dbg(hsdma->ddev.dev, "no desc to issue\n");
+       }
+       spin_unlock_bh(&chan->vchan.lock);
+}
+
+static struct dma_async_tx_descriptor *mtk_hsdma_prep_dma_memcpy(
+               struct dma_chan *c, dma_addr_t dest, dma_addr_t src,
+               size_t len, unsigned long flags)
+{
+       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
+       struct mtk_hsdma_desc *desc;
+
+       if (len <= 0)
+               return NULL;
+
+       desc = kzalloc(sizeof(struct mtk_hsdma_desc), GFP_ATOMIC);
+       if (!desc) {
+               dev_err(c->device->dev, "alloc memcpy decs error\n");
+               return NULL;
+       }
+
+       desc->sg[0].src_addr = src;
+       desc->sg[0].dst_addr = dest;
+       desc->sg[0].len = len;
+
+       return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
+}
+
+static enum dma_status mtk_hsdma_tx_status(struct dma_chan *c,
+                                          dma_cookie_t cookie,
+                                          struct dma_tx_state *state)
+{
+       return dma_cookie_status(c, cookie, state);
+}
+
+static void mtk_hsdma_free_chan_resources(struct dma_chan *c)
+{
+       vchan_free_chan_resources(to_virt_chan(c));
+}
+
+static void mtk_hsdma_desc_free(struct virt_dma_desc *vdesc)
+{
+       kfree(container_of(vdesc, struct mtk_hsdma_desc, vdesc));
+}
+
+static void mtk_hsdma_tx(struct mtk_hsdam_engine *hsdma)
+{
+       struct mtk_hsdma_chan *chan;
+
+       if (test_and_clear_bit(0, &hsdma->chan_issued)) {
+               chan = &hsdma->chan[0];
+               if (chan->desc)
+                       mtk_hsdma_start_transfer(hsdma, chan);
+               else
+                       dev_dbg(hsdma->ddev.dev, "chan 0 no desc to issue\n");
+       }
+}
+
+static void mtk_hsdma_rx(struct mtk_hsdam_engine *hsdma)
+{
+       struct mtk_hsdma_chan *chan;
+       int next_idx, drx_idx, cnt;
+
+       chan = &hsdma->chan[0];
+       next_idx = HSDMA_NEXT_DESC(chan->rx_idx);
+       drx_idx = mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX);
+
+       cnt = (drx_idx - next_idx) & HSDMA_DESCS_MASK;
+       if (!cnt)
+               return;
+
+       chan->next_sg += cnt;
+       chan->rx_idx = (chan->rx_idx + cnt) & HSDMA_DESCS_MASK;
+
+       /* update rx crx */
+       wmb();
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CRX, chan->rx_idx);
+
+       mtk_hsdma_chan_done(hsdma, chan);
+}
+
+static void mtk_hsdma_tasklet(unsigned long arg)
+{
+       struct mtk_hsdam_engine *hsdma = (struct mtk_hsdam_engine *)arg;
+
+       mtk_hsdma_rx(hsdma);
+       mtk_hsdma_tx(hsdma);
+}
+
+static int mtk_hsdam_alloc_desc(struct mtk_hsdam_engine *hsdma,
+                               struct mtk_hsdma_chan *chan)
+{
+       int i;
+
+       chan->tx_ring = dma_alloc_coherent(hsdma->ddev.dev,
+                       2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
+                       &chan->desc_addr, GFP_ATOMIC | __GFP_ZERO);
+       if (!chan->tx_ring)
+               goto no_mem;
+
+       chan->rx_ring = &chan->tx_ring[HSDMA_DESCS_NUM];
+
+       /* init tx ring value */
+       for (i = 0; i < HSDMA_DESCS_NUM; i++)
+               chan->tx_ring[i].flags = HSDMA_DESC_LS0 | HSDMA_DESC_DONE;
+
+       return 0;
+no_mem:
+       return -ENOMEM;
+}
+
+static void mtk_hsdam_free_desc(struct mtk_hsdam_engine *hsdma,
+                               struct mtk_hsdma_chan *chan)
+{
+       if (chan->tx_ring) {
+               dma_free_coherent(hsdma->ddev.dev,
+                               2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
+                               chan->tx_ring, chan->desc_addr);
+               chan->tx_ring = NULL;
+               chan->rx_ring = NULL;
+       }
+}
+
+static int mtk_hsdma_init(struct mtk_hsdam_engine *hsdma)
+{
+       struct mtk_hsdma_chan *chan;
+       int ret;
+       u32 reg;
+
+       /* init desc */
+       chan = &hsdma->chan[0];
+       ret = mtk_hsdam_alloc_desc(hsdma, chan);
+       if (ret)
+               return ret;
+
+       /* tx */
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_BASE, chan->desc_addr);
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CNT, HSDMA_DESCS_NUM);
+       /* rx */
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_BASE, chan->desc_addr +
+                       (sizeof(struct hsdma_desc) * HSDMA_DESCS_NUM));
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CNT, HSDMA_DESCS_NUM);
+       /* reset */
+       mtk_hsdma_reset_chan(hsdma, chan);
+
+       /* enable rx intr */
+       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, HSDMA_INT_RX_Q0);
+
+       /* enable dma */
+       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, HSDMA_GLO_DEFAULT);
+
+       /* hardware info */
+       reg = mtk_hsdma_read(hsdma, HSDMA_REG_INFO);
+       dev_info(hsdma->ddev.dev, "rx: %d, tx: %d\n",
+                (reg >> HSDMA_INFO_RX_SHIFT) & HSDMA_INFO_RX_MASK,
+                (reg >> HSDMA_INFO_TX_SHIFT) & HSDMA_INFO_TX_MASK);
+
+       hsdma_dump_reg(hsdma);
+
+       return ret;
+}
+
+static void mtk_hsdma_uninit(struct mtk_hsdam_engine *hsdma)
+{
+       struct mtk_hsdma_chan *chan;
+
+       /* disable dma */
+       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, 0);
+
+       /* disable intr */
+       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, 0);
+
+       /* free desc */
+       chan = &hsdma->chan[0];
+       mtk_hsdam_free_desc(hsdma, chan);
+
+       /* tx */
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_BASE, 0);
+       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CNT, 0);
+       /* rx */
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_BASE, 0);
+       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CNT, 0);
+       /* reset */
+       mtk_hsdma_reset_chan(hsdma, chan);
+}
+
+static const struct of_device_id mtk_hsdma_of_match[] = {
+       { .compatible = "mediatek,mt7621-hsdma" },
+       { },
+};
+
+static int mtk_hsdma_probe(struct platform_device *pdev)
+{
+       const struct of_device_id *match;
+       struct mtk_hsdma_chan *chan;
+       struct mtk_hsdam_engine *hsdma;
+       struct dma_device *dd;
+       struct resource *res;
+       int ret;
+       int irq;
+       void __iomem *base;
+
+       ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+       if (ret)
+               return ret;
+
+       match = of_match_device(mtk_hsdma_of_match, &pdev->dev);
+       if (!match)
+               return -EINVAL;
+
+       hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL);
+       if (!hsdma) {
+               dev_err(&pdev->dev, "alloc dma device failed\n");
+               return -EINVAL;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(base))
+               return PTR_ERR(base);
+       hsdma->base = base + HSDMA_BASE_OFFSET;
+       tasklet_init(&hsdma->task, mtk_hsdma_tasklet, (unsigned long)hsdma);
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(&pdev->dev, "failed to get irq\n");
+               return -EINVAL;
+       }
+       ret = devm_request_irq(&pdev->dev, irq, mtk_hsdma_irq,
+                              0, dev_name(&pdev->dev), hsdma);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to request irq\n");
+               return ret;
+       }
+
+       device_reset(&pdev->dev);
+
+       dd = &hsdma->ddev;
+       dma_cap_set(DMA_MEMCPY, dd->cap_mask);
+       dd->copy_align = HSDMA_ALIGN_SIZE;
+       dd->device_free_chan_resources = mtk_hsdma_free_chan_resources;
+       dd->device_prep_dma_memcpy = mtk_hsdma_prep_dma_memcpy;
+       dd->device_terminate_all = mtk_hsdma_terminate_all;
+       dd->device_tx_status = mtk_hsdma_tx_status;
+       dd->device_issue_pending = mtk_hsdma_issue_pending;
+       dd->dev = &pdev->dev;
+       dd->dev->dma_parms = &hsdma->dma_parms;
+       dma_set_max_seg_size(dd->dev, HSDMA_MAX_PLEN);
+       INIT_LIST_HEAD(&dd->channels);
+
+       chan = &hsdma->chan[0];
+       chan->id = 0;
+       chan->vchan.desc_free = mtk_hsdma_desc_free;
+       vchan_init(&chan->vchan, dd);
+
+       /* init hardware */
+       ret = mtk_hsdma_init(hsdma);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to alloc ring descs\n");
+               return ret;
+       }
+
+       ret = dma_async_device_register(dd);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register dma device\n");
+               goto err_uninit_hsdma;
+       }
+
+       ret = of_dma_controller_register(pdev->dev.of_node,
+                                        of_dma_xlate_by_chan_id, hsdma);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register of dma controller\n");
+               goto err_unregister;
+       }
+
+       platform_set_drvdata(pdev, hsdma);
+
+       return 0;
+
+err_unregister:
+       dma_async_device_unregister(dd);
+err_uninit_hsdma:
+       mtk_hsdma_uninit(hsdma);
+       return ret;
+}
+
+static int mtk_hsdma_remove(struct platform_device *pdev)
+{
+       struct mtk_hsdam_engine *hsdma = platform_get_drvdata(pdev);
+
+       mtk_hsdma_uninit(hsdma);
+
+       of_dma_controller_free(pdev->dev.of_node);
+       dma_async_device_unregister(&hsdma->ddev);
+
+       return 0;
+}
+
+static struct platform_driver mtk_hsdma_driver = {
+       .probe = mtk_hsdma_probe,
+       .remove = mtk_hsdma_remove,
+       .driver = {
+               .name = KBUILD_MODNAME,
+               .of_match_table = mtk_hsdma_of_match,
+       },
+};
+module_platform_driver(mtk_hsdma_driver);
+
+MODULE_AUTHOR("Michael Lee <[email protected]>");
+MODULE_DESCRIPTION("MTK HSDMA driver");
+MODULE_LICENSE("GPL v2");
drivers/staging/mt7621-dma/mtk-hsdma.c deleted +0 -771
@@ -1,771 +0,0 @@
-/*
- *  Copyright (C) 2015, Michael Lee <[email protected]>
- *  MTK HSDMA support
- *
- *  This program is free software; you can redistribute it and/or modify it
- *  under  the terms of the GNU General         Public License as published by the
- *  Free Software Foundation;  either version 2 of the License, or (at your
- *  option) any later version.
- *
- */
-
-#include <linux/dmaengine.h>
-#include <linux/dma-mapping.h>
-#include <linux/err.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/irq.h>
-#include <linux/of_dma.h>
-#include <linux/reset.h>
-#include <linux/of_device.h>
-
-#include "virt-dma.h"
-
-#define HSDMA_BASE_OFFSET              0x800
-
-#define HSDMA_REG_TX_BASE              0x00
-#define HSDMA_REG_TX_CNT               0x04
-#define HSDMA_REG_TX_CTX               0x08
-#define HSDMA_REG_TX_DTX               0x0c
-#define HSDMA_REG_RX_BASE              0x100
-#define HSDMA_REG_RX_CNT               0x104
-#define HSDMA_REG_RX_CRX               0x108
-#define HSDMA_REG_RX_DRX               0x10c
-#define HSDMA_REG_INFO                 0x200
-#define HSDMA_REG_GLO_CFG              0x204
-#define HSDMA_REG_RST_CFG              0x208
-#define HSDMA_REG_DELAY_INT            0x20c
-#define HSDMA_REG_FREEQ_THRES          0x210
-#define HSDMA_REG_INT_STATUS           0x220
-#define HSDMA_REG_INT_MASK             0x228
-#define HSDMA_REG_SCH_Q01              0x280
-#define HSDMA_REG_SCH_Q23              0x284
-
-#define HSDMA_DESCS_MAX                        0xfff
-#define HSDMA_DESCS_NUM                        8
-#define HSDMA_DESCS_MASK               (HSDMA_DESCS_NUM - 1)
-#define HSDMA_NEXT_DESC(x)             (((x) + 1) & HSDMA_DESCS_MASK)
-
-/* HSDMA_REG_INFO */
-#define HSDMA_INFO_INDEX_MASK          0xf
-#define HSDMA_INFO_INDEX_SHIFT         24
-#define HSDMA_INFO_BASE_MASK           0xff
-#define HSDMA_INFO_BASE_SHIFT          16
-#define HSDMA_INFO_RX_MASK             0xff
-#define HSDMA_INFO_RX_SHIFT            8
-#define HSDMA_INFO_TX_MASK             0xff
-#define HSDMA_INFO_TX_SHIFT            0
-
-/* HSDMA_REG_GLO_CFG */
-#define HSDMA_GLO_TX_2B_OFFSET         BIT(31)
-#define HSDMA_GLO_CLK_GATE             BIT(30)
-#define HSDMA_GLO_BYTE_SWAP            BIT(29)
-#define HSDMA_GLO_MULTI_DMA            BIT(10)
-#define HSDMA_GLO_TWO_BUF              BIT(9)
-#define HSDMA_GLO_32B_DESC             BIT(8)
-#define HSDMA_GLO_BIG_ENDIAN           BIT(7)
-#define HSDMA_GLO_TX_DONE              BIT(6)
-#define HSDMA_GLO_BT_MASK              0x3
-#define HSDMA_GLO_BT_SHIFT             4
-#define HSDMA_GLO_RX_BUSY              BIT(3)
-#define HSDMA_GLO_RX_DMA               BIT(2)
-#define HSDMA_GLO_TX_BUSY              BIT(1)
-#define HSDMA_GLO_TX_DMA               BIT(0)
-
-#define HSDMA_BT_SIZE_16BYTES          (0 << HSDMA_GLO_BT_SHIFT)
-#define HSDMA_BT_SIZE_32BYTES          (1 << HSDMA_GLO_BT_SHIFT)
-#define HSDMA_BT_SIZE_64BYTES          (2 << HSDMA_GLO_BT_SHIFT)
-#define HSDMA_BT_SIZE_128BYTES         (3 << HSDMA_GLO_BT_SHIFT)
-
-#define HSDMA_GLO_DEFAULT              (HSDMA_GLO_MULTI_DMA | \
-               HSDMA_GLO_RX_DMA | HSDMA_GLO_TX_DMA | HSDMA_BT_SIZE_32BYTES)
-
-/* HSDMA_REG_RST_CFG */
-#define HSDMA_RST_RX_SHIFT             16
-#define HSDMA_RST_TX_SHIFT             0
-
-/* HSDMA_REG_DELAY_INT */
-#define HSDMA_DELAY_INT_EN             BIT(15)
-#define HSDMA_DELAY_PEND_OFFSET                8
-#define HSDMA_DELAY_TIME_OFFSET                0
-#define HSDMA_DELAY_TX_OFFSET          16
-#define HSDMA_DELAY_RX_OFFSET          0
-
-#define HSDMA_DELAY_INIT(x)            (HSDMA_DELAY_INT_EN | \
-               ((x) << HSDMA_DELAY_PEND_OFFSET))
-#define HSDMA_DELAY(x)                 ((HSDMA_DELAY_INIT(x) << \
-               HSDMA_DELAY_TX_OFFSET) | HSDMA_DELAY_INIT(x))
-
-/* HSDMA_REG_INT_STATUS */
-#define HSDMA_INT_DELAY_RX_COH         BIT(31)
-#define HSDMA_INT_DELAY_RX_INT         BIT(30)
-#define HSDMA_INT_DELAY_TX_COH         BIT(29)
-#define HSDMA_INT_DELAY_TX_INT         BIT(28)
-#define HSDMA_INT_RX_MASK              0x3
-#define HSDMA_INT_RX_SHIFT             16
-#define HSDMA_INT_RX_Q0                        BIT(16)
-#define HSDMA_INT_TX_MASK              0xf
-#define HSDMA_INT_TX_SHIFT             0
-#define HSDMA_INT_TX_Q0                        BIT(0)
-
-/* tx/rx dma desc flags */
-#define HSDMA_PLEN_MASK                        0x3fff
-#define HSDMA_DESC_DONE                        BIT(31)
-#define HSDMA_DESC_LS0                 BIT(30)
-#define HSDMA_DESC_PLEN0(_x)           (((_x) & HSDMA_PLEN_MASK) << 16)
-#define HSDMA_DESC_TAG                 BIT(15)
-#define HSDMA_DESC_LS1                 BIT(14)
-#define HSDMA_DESC_PLEN1(_x)           ((_x) & HSDMA_PLEN_MASK)
-
-/* align 4 bytes */
-#define HSDMA_ALIGN_SIZE               3
-/* align size 128bytes */
-#define HSDMA_MAX_PLEN                 0x3f80
-
-struct hsdma_desc {
-       u32 addr0;
-       u32 flags;
-       u32 addr1;
-       u32 unused;
-};
-
-struct mtk_hsdma_sg {
-       dma_addr_t src_addr;
-       dma_addr_t dst_addr;
-       u32 len;
-};
-
-struct mtk_hsdma_desc {
-       struct virt_dma_desc vdesc;
-       unsigned int num_sgs;
-       struct mtk_hsdma_sg sg[1];
-};
-
-struct mtk_hsdma_chan {
-       struct virt_dma_chan vchan;
-       unsigned int id;
-       dma_addr_t desc_addr;
-       int tx_idx;
-       int rx_idx;
-       struct hsdma_desc *tx_ring;
-       struct hsdma_desc *rx_ring;
-       struct mtk_hsdma_desc *desc;
-       unsigned int next_sg;
-};
-
-struct mtk_hsdam_engine {
-       struct dma_device ddev;
-       struct device_dma_parameters dma_parms;
-       void __iomem *base;
-       struct tasklet_struct task;
-       volatile unsigned long chan_issued;
-
-       struct mtk_hsdma_chan chan[1];
-};
-
-static inline struct mtk_hsdam_engine *mtk_hsdma_chan_get_dev(
-               struct mtk_hsdma_chan *chan)
-{
-       return container_of(chan->vchan.chan.device, struct mtk_hsdam_engine,
-                       ddev);
-}
-
-static inline struct mtk_hsdma_chan *to_mtk_hsdma_chan(struct dma_chan *c)
-{
-       return container_of(c, struct mtk_hsdma_chan, vchan.chan);
-}
-
-static inline struct mtk_hsdma_desc *to_mtk_hsdma_desc(
-               struct virt_dma_desc *vdesc)
-{
-       return container_of(vdesc, struct mtk_hsdma_desc, vdesc);
-}
-
-static inline u32 mtk_hsdma_read(struct mtk_hsdam_engine *hsdma, u32 reg)
-{
-       return readl(hsdma->base + reg);
-}
-
-static inline void mtk_hsdma_write(struct mtk_hsdam_engine *hsdma,
-                                  unsigned reg, u32 val)
-{
-       writel(val, hsdma->base + reg);
-}
-
-static void mtk_hsdma_reset_chan(struct mtk_hsdam_engine *hsdma,
-                                struct mtk_hsdma_chan *chan)
-{
-       chan->tx_idx = 0;
-       chan->rx_idx = HSDMA_DESCS_NUM - 1;
-
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CTX, chan->tx_idx);
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CRX, chan->rx_idx);
-
-       mtk_hsdma_write(hsdma, HSDMA_REG_RST_CFG,
-                       0x1 << (chan->id + HSDMA_RST_TX_SHIFT));
-       mtk_hsdma_write(hsdma, HSDMA_REG_RST_CFG,
-                       0x1 << (chan->id + HSDMA_RST_RX_SHIFT));
-}
-
-static void hsdma_dump_reg(struct mtk_hsdam_engine *hsdma)
-{
-       dev_dbg(hsdma->ddev.dev, "tbase %08x, tcnt %08x, " \
-                       "tctx %08x, tdtx: %08x, rbase %08x, " \
-                       "rcnt %08x, rctx %08x, rdtx %08x\n",
-                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_BASE),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_CNT),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_CTX),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_TX_DTX),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_BASE),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_CNT),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_CRX),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX));
-
-       dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, " \
-                       "intr_stat %08x, intr_mask %08x\n",
-                       mtk_hsdma_read(hsdma, HSDMA_REG_INFO),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_DELAY_INT),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_INT_STATUS),
-                       mtk_hsdma_read(hsdma, HSDMA_REG_INT_MASK));
-}
-
-static void hsdma_dump_desc(struct mtk_hsdam_engine *hsdma,
-                           struct mtk_hsdma_chan *chan)
-{
-       struct hsdma_desc *tx_desc;
-       struct hsdma_desc *rx_desc;
-       int i;
-
-       dev_dbg(hsdma->ddev.dev, "tx idx: %d, rx idx: %d\n",
-                       chan->tx_idx, chan->rx_idx);
-
-       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
-               tx_desc = &chan->tx_ring[i];
-               rx_desc = &chan->rx_ring[i];
-
-               dev_dbg(hsdma->ddev.dev, "%d tx addr0: %08x, flags %08x, " \
-                               "tx addr1: %08x, rx addr0 %08x, flags %08x\n",
-                               i, tx_desc->addr0, tx_desc->flags, \
-                               tx_desc->addr1, rx_desc->addr0, rx_desc->flags);
-       }
-}
-
-static void mtk_hsdma_reset(struct mtk_hsdam_engine *hsdma,
-                           struct mtk_hsdma_chan *chan)
-{
-       int i;
-
-       /* disable dma */
-       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, 0);
-
-       /* disable intr */
-       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, 0);
-
-       /* init desc value */
-       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
-               chan->tx_ring[i].addr0 = 0;
-               chan->tx_ring[i].flags = HSDMA_DESC_LS0 |
-                       HSDMA_DESC_DONE;
-       }
-       for (i = 0; i < HSDMA_DESCS_NUM; i++) {
-               chan->rx_ring[i].addr0 = 0;
-               chan->rx_ring[i].flags = 0;
-       }
-
-       /* reset */
-       mtk_hsdma_reset_chan(hsdma, chan);
-
-       /* enable intr */
-       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, HSDMA_INT_RX_Q0);
-
-       /* enable dma */
-       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, HSDMA_GLO_DEFAULT);
-}
-
-static int mtk_hsdma_terminate_all(struct dma_chan *c)
-{
-       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
-       struct mtk_hsdam_engine *hsdma = mtk_hsdma_chan_get_dev(chan);
-       unsigned long timeout;
-       LIST_HEAD(head);
-
-       spin_lock_bh(&chan->vchan.lock);
-       chan->desc = NULL;
-       clear_bit(chan->id, &hsdma->chan_issued);
-       vchan_get_all_descriptors(&chan->vchan, &head);
-       spin_unlock_bh(&chan->vchan.lock);
-
-       vchan_dma_desc_free_list(&chan->vchan, &head);
-
-       /* wait dma transfer complete */
-       timeout = jiffies + msecs_to_jiffies(2000);
-       while (mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG) &
-                       (HSDMA_GLO_RX_BUSY | HSDMA_GLO_TX_BUSY)) {
-               if (time_after_eq(jiffies, timeout)) {
-                       hsdma_dump_desc(hsdma, chan);
-                       mtk_hsdma_reset(hsdma, chan);
-                       dev_err(hsdma->ddev.dev, "timeout, reset it\n");
-                       break;
-               }
-               cpu_relax();
-       }
-
-       return 0;
-}
-
-static int mtk_hsdma_start_transfer(struct mtk_hsdam_engine *hsdma,
-                                   struct mtk_hsdma_chan *chan)
-{
-       dma_addr_t src, dst;
-       size_t len, tlen;
-       struct hsdma_desc *tx_desc, *rx_desc;
-       struct mtk_hsdma_sg *sg;
-       unsigned int i;
-       int rx_idx;
-
-       sg = &chan->desc->sg[0];
-       len = sg->len;
-       chan->desc->num_sgs = DIV_ROUND_UP(len, HSDMA_MAX_PLEN);
-
-       /* tx desc */
-       src = sg->src_addr;
-       for (i = 0; i < chan->desc->num_sgs; i++) {
-               tx_desc = &chan->tx_ring[chan->tx_idx];
-
-               if (len > HSDMA_MAX_PLEN)
-                       tlen = HSDMA_MAX_PLEN;
-               else
-                       tlen = len;
-
-               if (i & 0x1) {
-                       tx_desc->addr1 = src;
-                       tx_desc->flags |= HSDMA_DESC_PLEN1(tlen);
-               } else {
-                       tx_desc->addr0 = src;
-                       tx_desc->flags = HSDMA_DESC_PLEN0(tlen);
-
-                       /* update index */
-                       chan->tx_idx = HSDMA_NEXT_DESC(chan->tx_idx);
-               }
-
-               src += tlen;
-               len -= tlen;
-       }
-       if (i & 0x1)
-               tx_desc->flags |= HSDMA_DESC_LS0;
-       else
-               tx_desc->flags |= HSDMA_DESC_LS1;
-
-       /* rx desc */
-       rx_idx = HSDMA_NEXT_DESC(chan->rx_idx);
-       len = sg->len;
-       dst = sg->dst_addr;
-       for (i = 0; i < chan->desc->num_sgs; i++) {
-               rx_desc = &chan->rx_ring[rx_idx];
-               if (len > HSDMA_MAX_PLEN)
-                       tlen = HSDMA_MAX_PLEN;
-               else
-                       tlen = len;
-
-               rx_desc->addr0 = dst;
-               rx_desc->flags = HSDMA_DESC_PLEN0(tlen);
-
-               dst += tlen;
-               len -= tlen;
-
-               /* update index */
-               rx_idx = HSDMA_NEXT_DESC(rx_idx);
-       }
-
-       /* make sure desc and index all up to date */
-       wmb();
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CTX, chan->tx_idx);
-
-       return 0;
-}
-
-static int gdma_next_desc(struct mtk_hsdma_chan *chan)
-{
-       struct virt_dma_desc *vdesc;
-
-       vdesc = vchan_next_desc(&chan->vchan);
-       if (!vdesc) {
-               chan->desc = NULL;
-               return 0;
-       }
-       chan->desc = to_mtk_hsdma_desc(vdesc);
-       chan->next_sg = 0;
-
-       return 1;
-}
-
-static void mtk_hsdma_chan_done(struct mtk_hsdam_engine *hsdma,
-                               struct mtk_hsdma_chan *chan)
-{
-       struct mtk_hsdma_desc *desc;
-       int chan_issued;
-
-       chan_issued = 0;
-       spin_lock_bh(&chan->vchan.lock);
-       desc = chan->desc;
-       if (likely(desc)) {
-               if (chan->next_sg == desc->num_sgs) {
-                       list_del(&desc->vdesc.node);
-                       vchan_cookie_complete(&desc->vdesc);
-                       chan_issued = gdma_next_desc(chan);
-               }
-       } else
-               dev_dbg(hsdma->ddev.dev, "no desc to complete\n");
-
-       if (chan_issued)
-               set_bit(chan->id, &hsdma->chan_issued);
-       spin_unlock_bh(&chan->vchan.lock);
-}
-
-static irqreturn_t mtk_hsdma_irq(int irq, void *devid)
-{
-       struct mtk_hsdam_engine *hsdma = devid;
-       u32 status;
-
-       status = mtk_hsdma_read(hsdma, HSDMA_REG_INT_STATUS);
-       if (unlikely(!status))
-               return IRQ_NONE;
-
-       if (likely(status & HSDMA_INT_RX_Q0))
-               tasklet_schedule(&hsdma->task);
-       else
-               dev_dbg(hsdma->ddev.dev, "unhandle irq status %08x\n",
-                       status);
-       /* clean intr bits */
-       mtk_hsdma_write(hsdma, HSDMA_REG_INT_STATUS, status);
-
-       return IRQ_HANDLED;
-}
-
-static void mtk_hsdma_issue_pending(struct dma_chan *c)
-{
-       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
-       struct mtk_hsdam_engine *hsdma = mtk_hsdma_chan_get_dev(chan);
-
-       spin_lock_bh(&chan->vchan.lock);
-       if (vchan_issue_pending(&chan->vchan) && !chan->desc) {
-               if (gdma_next_desc(chan)) {
-                       set_bit(chan->id, &hsdma->chan_issued);
-                       tasklet_schedule(&hsdma->task);
-               } else
-                       dev_dbg(hsdma->ddev.dev, "no desc to issue\n");
-       }
-       spin_unlock_bh(&chan->vchan.lock);
-}
-
-static struct dma_async_tx_descriptor *mtk_hsdma_prep_dma_memcpy(
-               struct dma_chan *c, dma_addr_t dest, dma_addr_t src,
-               size_t len, unsigned long flags)
-{
-       struct mtk_hsdma_chan *chan = to_mtk_hsdma_chan(c);
-       struct mtk_hsdma_desc *desc;
-
-       if (len <= 0)
-               return NULL;
-
-       desc = kzalloc(sizeof(struct mtk_hsdma_desc), GFP_ATOMIC);
-       if (!desc) {
-               dev_err(c->device->dev, "alloc memcpy decs error\n");
-               return NULL;
-       }
-
-       desc->sg[0].src_addr = src;
-       desc->sg[0].dst_addr = dest;
-       desc->sg[0].len = len;
-
-       return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
-}
-
-static enum dma_status mtk_hsdma_tx_status(struct dma_chan *c,
-                                          dma_cookie_t cookie,
-                                          struct dma_tx_state *state)
-{
-       return dma_cookie_status(c, cookie, state);
-}
-
-static void mtk_hsdma_free_chan_resources(struct dma_chan *c)
-{
-       vchan_free_chan_resources(to_virt_chan(c));
-}
-
-static void mtk_hsdma_desc_free(struct virt_dma_desc *vdesc)
-{
-       kfree(container_of(vdesc, struct mtk_hsdma_desc, vdesc));
-}
-
-static void mtk_hsdma_tx(struct mtk_hsdam_engine *hsdma)
-{
-       struct mtk_hsdma_chan *chan;
-
-       if (test_and_clear_bit(0, &hsdma->chan_issued)) {
-               chan = &hsdma->chan[0];
-               if (chan->desc)
-                       mtk_hsdma_start_transfer(hsdma, chan);
-               else
-                       dev_dbg(hsdma->ddev.dev, "chan 0 no desc to issue\n");
-       }
-}
-
-static void mtk_hsdma_rx(struct mtk_hsdam_engine *hsdma)
-{
-       struct mtk_hsdma_chan *chan;
-       int next_idx, drx_idx, cnt;
-
-       chan = &hsdma->chan[0];
-       next_idx = HSDMA_NEXT_DESC(chan->rx_idx);
-       drx_idx = mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX);
-
-       cnt = (drx_idx - next_idx) & HSDMA_DESCS_MASK;
-       if (!cnt)
-               return;
-
-       chan->next_sg += cnt;
-       chan->rx_idx = (chan->rx_idx + cnt) & HSDMA_DESCS_MASK;
-
-       /* update rx crx */
-       wmb();
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CRX, chan->rx_idx);
-
-       mtk_hsdma_chan_done(hsdma, chan);
-}
-
-static void mtk_hsdma_tasklet(unsigned long arg)
-{
-       struct mtk_hsdam_engine *hsdma = (struct mtk_hsdam_engine *)arg;
-
-       mtk_hsdma_rx(hsdma);
-       mtk_hsdma_tx(hsdma);
-}
-
-static int mtk_hsdam_alloc_desc(struct mtk_hsdam_engine *hsdma,
-                               struct mtk_hsdma_chan *chan)
-{
-       int i;
-
-       chan->tx_ring = dma_alloc_coherent(hsdma->ddev.dev,
-                       2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
-                       &chan->desc_addr, GFP_ATOMIC | __GFP_ZERO);
-       if (!chan->tx_ring)
-               goto no_mem;
-
-       chan->rx_ring = &chan->tx_ring[HSDMA_DESCS_NUM];
-
-       /* init tx ring value */
-       for (i = 0; i < HSDMA_DESCS_NUM; i++)
-               chan->tx_ring[i].flags = HSDMA_DESC_LS0 | HSDMA_DESC_DONE;
-
-       return 0;
-no_mem:
-       return -ENOMEM;
-}
-
-static void mtk_hsdam_free_desc(struct mtk_hsdam_engine *hsdma,
-                               struct mtk_hsdma_chan *chan)
-{
-       if (chan->tx_ring) {
-               dma_free_coherent(hsdma->ddev.dev,
-                               2 * HSDMA_DESCS_NUM * sizeof(*chan->tx_ring),
-                               chan->tx_ring, chan->desc_addr);
-               chan->tx_ring = NULL;
-               chan->rx_ring = NULL;
-       }
-}
-
-static int mtk_hsdma_init(struct mtk_hsdam_engine *hsdma)
-{
-       struct mtk_hsdma_chan *chan;
-       int ret;
-       u32 reg;
-
-       /* init desc */
-       chan = &hsdma->chan[0];
-       ret = mtk_hsdam_alloc_desc(hsdma, chan);
-       if (ret)
-               return ret;
-
-       /* tx */
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_BASE, chan->desc_addr);
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CNT, HSDMA_DESCS_NUM);
-       /* rx */
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_BASE, chan->desc_addr +
-                       (sizeof(struct hsdma_desc) * HSDMA_DESCS_NUM));
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CNT, HSDMA_DESCS_NUM);
-       /* reset */
-       mtk_hsdma_reset_chan(hsdma, chan);
-
-       /* enable rx intr */
-       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, HSDMA_INT_RX_Q0);
-
-       /* enable dma */
-       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, HSDMA_GLO_DEFAULT);
-
-       /* hardware info */
-       reg = mtk_hsdma_read(hsdma, HSDMA_REG_INFO);
-       dev_info(hsdma->ddev.dev, "rx: %d, tx: %d\n",
-                (reg >> HSDMA_INFO_RX_SHIFT) & HSDMA_INFO_RX_MASK,
-                (reg >> HSDMA_INFO_TX_SHIFT) & HSDMA_INFO_TX_MASK);
-
-       hsdma_dump_reg(hsdma);
-
-       return ret;
-}
-
-static void mtk_hsdma_uninit(struct mtk_hsdam_engine *hsdma)
-{
-       struct mtk_hsdma_chan *chan;
-
-       /* disable dma */
-       mtk_hsdma_write(hsdma, HSDMA_REG_GLO_CFG, 0);
-
-       /* disable intr */
-       mtk_hsdma_write(hsdma, HSDMA_REG_INT_MASK, 0);
-
-       /* free desc */
-       chan = &hsdma->chan[0];
-       mtk_hsdam_free_desc(hsdma, chan);
-
-       /* tx */
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_BASE, 0);
-       mtk_hsdma_write(hsdma, HSDMA_REG_TX_CNT, 0);
-       /* rx */
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_BASE, 0);
-       mtk_hsdma_write(hsdma, HSDMA_REG_RX_CNT, 0);
-       /* reset */
-       mtk_hsdma_reset_chan(hsdma, chan);
-}
-
-static const struct of_device_id mtk_hsdma_of_match[] = {
-       { .compatible = "mediatek,mt7621-hsdma" },
-       { },
-};
-
-static int mtk_hsdma_probe(struct platform_device *pdev)
-{
-       const struct of_device_id *match;
-       struct mtk_hsdma_chan *chan;
-       struct mtk_hsdam_engine *hsdma;
-       struct dma_device *dd;
-       struct resource *res;
-       int ret;
-       int irq;
-       void __iomem *base;
-
-       ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
-       if (ret)
-               return ret;
-
-       match = of_match_device(mtk_hsdma_of_match, &pdev->dev);
-       if (!match)
-               return -EINVAL;
-
-       hsdma = devm_kzalloc(&pdev->dev, sizeof(*hsdma), GFP_KERNEL);
-       if (!hsdma) {
-               dev_err(&pdev->dev, "alloc dma device failed\n");
-               return -EINVAL;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       base = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(base))
-               return PTR_ERR(base);
-       hsdma->base = base + HSDMA_BASE_OFFSET;
-       tasklet_init(&hsdma->task, mtk_hsdma_tasklet, (unsigned long)hsdma);
-
-       irq = platform_get_irq(pdev, 0);
-       if (irq < 0) {
-               dev_err(&pdev->dev, "failed to get irq\n");
-               return -EINVAL;
-       }
-       ret = devm_request_irq(&pdev->dev, irq, mtk_hsdma_irq,
-                              0, dev_name(&pdev->dev), hsdma);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to request irq\n");
-               return ret;
-       }
-
-       device_reset(&pdev->dev);
-
-       dd = &hsdma->ddev;
-       dma_cap_set(DMA_MEMCPY, dd->cap_mask);
-       dd->copy_align = HSDMA_ALIGN_SIZE;
-       dd->device_free_chan_resources = mtk_hsdma_free_chan_resources;
-       dd->device_prep_dma_memcpy = mtk_hsdma_prep_dma_memcpy;
-       dd->device_terminate_all = mtk_hsdma_terminate_all;
-       dd->device_tx_status = mtk_hsdma_tx_status;
-       dd->device_issue_pending = mtk_hsdma_issue_pending;
-       dd->dev = &pdev->dev;
-       dd->dev->dma_parms = &hsdma->dma_parms;
-       dma_set_max_seg_size(dd->dev, HSDMA_MAX_PLEN);
-       INIT_LIST_HEAD(&dd->channels);
-
-       chan = &hsdma->chan[0];
-       chan->id = 0;
-       chan->vchan.desc_free = mtk_hsdma_desc_free;
-       vchan_init(&chan->vchan, dd);
-
-       /* init hardware */
-       ret = mtk_hsdma_init(hsdma);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to alloc ring descs\n");
-               return ret;
-       }
-
-       ret = dma_async_device_register(dd);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to register dma device\n");
-               goto err_uninit_hsdma;
-       }
-
-       ret = of_dma_controller_register(pdev->dev.of_node,
-                                        of_dma_xlate_by_chan_id, hsdma);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to register of dma controller\n");
-               goto err_unregister;
-       }
-
-       platform_set_drvdata(pdev, hsdma);
-
-       return 0;
-
-err_unregister:
-       dma_async_device_unregister(dd);
-err_uninit_hsdma:
-       mtk_hsdma_uninit(hsdma);
-       return ret;
-}
-
-static int mtk_hsdma_remove(struct platform_device *pdev)
-{
-       struct mtk_hsdam_engine *hsdma = platform_get_drvdata(pdev);
-
-       mtk_hsdma_uninit(hsdma);
-
-       of_dma_controller_free(pdev->dev.of_node);
-       dma_async_device_unregister(&hsdma->ddev);
-
-       return 0;
-}
-
-static struct platform_driver mtk_hsdma_driver = {
-       .probe = mtk_hsdma_probe,
-       .remove = mtk_hsdma_remove,
-       .driver = {
-               .name = "hsdma-mt7621",
-               .of_match_table = mtk_hsdma_of_match,
-       },
-};
-module_platform_driver(mtk_hsdma_driver);
-
-MODULE_AUTHOR("Michael Lee <[email protected]>");
-MODULE_DESCRIPTION("MTK HSDMA driver");
-MODULE_LICENSE("GPL v2");
author maintainer
#235 lore raw

Re: [PATCH 4.19 209/247] staging/mt7621-dma: mtk-hsdma.c->hsdma-mt7621.c

Quoted 4 lines · Ilya Lipnitskiy

Sorry, I should have been more clear in my original email, but we don't strictly need this in 4.19 as the check only became fatal in 5.10 (actually, before 5.10, but 5.10 is the first stable release with it). Feel free to take or omit this from 4.19.

I'll leave it in as having duplicate module names is not good no matter what kernel tree it is in.

thanks for the review!

greg k-h

author maintainer
#236 lore raw

PATCH 210/247 staging: gdm724x: Fix DMA from stack

In reply to Greg Kroah-Hartman

From: Amey Narkhede <[email protected]>

commit 7c3a0635cd008eaca9a734dc802709ee0b81cac5 upstream.

Stack allocated buffers cannot be used for DMA on all architectures so allocate hci_packet buffer using kmalloc.

---
 drivers/staging/gdm724x/gdm_usb.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/staging/gdm724x/gdm_usb.c +7 -3
@@ -56,20 +56,24 @@ static int gdm_usb_recv(void *priv_dev,
 
 static int request_mac_address(struct lte_udev *udev)
 {
-	u8 buf[16] = {0,};
-	struct hci_packet *hci = (struct hci_packet *)buf;
+	struct hci_packet *hci;
 	struct usb_device *usbdev = udev->usbdev;
 	int actual;
 	int ret = -1;
 
+	hci = kmalloc(struct_size(hci, data, 1), GFP_KERNEL);
+	if (!hci)
+		return -ENOMEM;
+
 	hci->cmd_evt = gdm_cpu_to_dev16(udev->gdm_ed, LTE_GET_INFORMATION);
 	hci->len = gdm_cpu_to_dev16(udev->gdm_ed, 1);
 	hci->data[0] = MAC_ADDRESS;
 
-	ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
+	ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), hci, 5,
 			   &actual, 1000);
 
 	udev->request_mac_addr = 1;
+	kfree(hci);
 
 	return ret;
 }
author maintainer
#237 lore raw

PATCH 211/247 staging: rtl8188eu: Add Edimax EW-7811UN V2 to device table

In reply to Greg Kroah-Hartman

From: Martin Kaiser <[email protected]>

commit 7a8d2f1908a59003e55ef8691d09efb7fbc51625 upstream.

The Edimax EW-7811UN V2 uses an RTL8188EU chipset and works with this driver.

---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c |    1 +
 1 file changed, 1 insertion(+)
drivers/staging/rtl8188eu/os_dep/usb_intf.c +1 -0
@@ -41,6 +41,7 @@ static const struct usb_device_id rtw_us
 	{USB_DEVICE(0x2357, 0x0111)}, /* TP-Link TL-WN727N v5.21 */
 	{USB_DEVICE(0x2C4E, 0x0102)}, /* MERCUSYS MW150US v2 */
 	{USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */
+	{USB_DEVICE(0x7392, 0xb811)}, /* Edimax EW-7811UN V2 */
 	{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xffef)}, /* Rosewill RNX-N150NUB */
 	{}	/* Terminating entry */
 };
author maintainer
#238 lore raw

PATCH 212/247 media: ipu3-cio2: Fix mbus_code processing in cio2_subdev_set_fmt()

In reply to Greg Kroah-Hartman

From: Pavel Machek <[email protected]>

commit 334de4b45892f7e67074e1b1b2ac36fd3e091118 upstream.

Loop was useless as it would always exit on the first iteration. Fix it with right condition.

Fixes a86cf9b29e8b ("media: ipu3-cio2: Validate mbus format in setting subdev format")
Cc [email protected] # v4.16 and up
---
 drivers/media/pci/intel/ipu3/ipu3-cio2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1 -1
@@ -1290,7 +1290,7 @@ static int cio2_subdev_set_fmt(struct v4
 	fmt->format.code = formats[0].mbus_code;
 
 	for (i = 0; i < ARRAY_SIZE(formats); i++) {
-		if (formats[i].mbus_code == fmt->format.code) {
+		if (formats[i].mbus_code == mbus_code) {
 			fmt->format.code = mbus_code;
 			break;
 		}
author maintainer
#239 lore raw

PATCH 213/247 x86/reboot: Force all cpus to exit VMX root if VMX is supported

In reply to Greg Kroah-Hartman

From: Sean Christopherson <[email protected]>

commit ed72736183c45a413a8d6974dd04be90f514cb6b upstream.

Force all CPUs to do VMXOFF (via NMI shootdown) during an emergency reboot if VMX is _supported_, as VMX being off on the current CPU does not prevent other CPUs from being in VMX root (post-VMXON). This fixes a bug where a crash/panic reboot could leave other CPUs in VMX root and prevent them from being woken via INIT-SIPI-SIPI in the new kernel.

Fixes d176720d34c7 ("x86: disable VMX on all CPUs on reboot")
[sean: reworked changelog and further tweaked comment]

Message-Id: <[email protected]>

---
 arch/x86/kernel/reboot.c |   29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)
arch/x86/kernel/reboot.c +10 -19
@@ -538,29 +538,20 @@ static void emergency_vmx_disable_all(vo
 	local_irq_disable();
 
 	/*
-	 * We need to disable VMX on all CPUs before rebooting, otherwise
-	 * we risk hanging up the machine, because the CPU ignore INIT
-	 * signals when VMX is enabled.
+	 * Disable VMX on all CPUs before rebooting, otherwise we risk hanging
+	 * the machine, because the CPU blocks INIT when it's in VMX root.
 	 *
-	 * We can't take any locks and we may be on an inconsistent
-	 * state, so we use NMIs as IPIs to tell the other CPUs to disable
-	 * VMX and halt.
+	 * We can't take any locks and we may be on an inconsistent state, so
+	 * use NMIs as IPIs to tell the other CPUs to exit VMX root and halt.
 	 *
-	 * For safety, we will avoid running the nmi_shootdown_cpus()
-	 * stuff unnecessarily, but we don't have a way to check
-	 * if other CPUs have VMX enabled. So we will call it only if the
-	 * CPU we are running on has VMX enabled.
-	 *
-	 * We will miss cases where VMX is not enabled on all CPUs. This
-	 * shouldn't do much harm because KVM always enable VMX on all
-	 * CPUs anyway. But we can miss it on the small window where KVM
-	 * is still enabling VMX.
+	 * Do the NMI shootdown even if VMX if off on _this_ CPU, as that
+	 * doesn't prevent a different CPU from being in VMX root operation.
 	 */
-	if (cpu_has_vmx() && cpu_vmx_enabled()) {
-		/* Disable VMX on this CPU. */
-		cpu_vmxoff();
+	if (cpu_has_vmx()) {
+		/* Safely force _this_ CPU out of VMX root operation. */
+		__cpu_emergency_vmxoff();
 
-		/* Halt and disable VMX on the other CPUs */
+		/* Halt and exit VMX root operation on the other CPUs. */
 		nmi_shootdown_cpus(vmxoff_nmi);
 
 	}
author maintainer
#240 lore raw

PATCH 214/247 floppy: reintroduce O_NDELAY fix

In reply to Greg Kroah-Hartman

From: Jiri Kosina <[email protected]>

commit 8a0c014cd20516ade9654fc13b51345ec58e7be8 upstream.

This issue was originally fixed in 09954bad4 ("floppy: refactor open() flags handling").

The fix as a side-effect, however, introduce issue for open(O_ACCMODE) that is being used for ioctl-only open. I wrote a fix for that, but instead of it being merged, full revert of 09954bad4 was performed, re-introducing the O_NDELAY / O_NONBLOCK issue, and it strikes again.

This is a forward-port of the original fix to current codebase; the original submission had the changelog below:

====
Commit 09954bad4 ("floppy: refactor open() flags handling"), as a side-effect, causes open(/dev/fdX, O_ACCMODE) to fail. It turns out that this is being used setfdprm userspace for ioctl-only open().

Reintroduce back the original behavior wrt !(FMODE_READ|FMODE_WRITE) modes, while still keeping the original O_NDELAY bug fixed.

Reported-and-tested-by Kurt Garloff <[email protected]>
Fixes 09954bad4 ("floppy: refactor open() flags handling")
Fixes f2791e7ead ("Revert "floppy: refactor open() flags handling"")
---
 drivers/block/floppy.c |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/block/floppy.c +14 -13
@@ -4074,21 +4074,22 @@ static int floppy_open(struct block_devi
 	if (UFDCS->rawcmd == 1)
 		UFDCS->rawcmd = 2;
 
-	if (!(mode & FMODE_NDELAY)) {
-		if (mode & (FMODE_READ|FMODE_WRITE)) {
-			UDRS->last_checked = 0;
-			clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
-			check_disk_change(bdev);
-			if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
-				goto out;
-			if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
-				goto out;
-		}
-		res = -EROFS;
-		if ((mode & FMODE_WRITE) &&
-		    !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
+	if (mode & (FMODE_READ|FMODE_WRITE)) {
+		UDRS->last_checked = 0;
+		clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
+		check_disk_change(bdev);
+		if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
+			goto out;
+		if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
 			goto out;
 	}
+
+	res = -EROFS;
+
+	if ((mode & FMODE_WRITE) &&
+			!test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
+		goto out;
+
 	mutex_unlock(&open_lock);
 	mutex_unlock(&floppy_mutex);
 	return 0;
author maintainer
#241 lore raw

PATCH 215/247 arm64: uprobe: Return EOPNOTSUPP for AARCH32 instruction probing

In reply to Greg Kroah-Hartman

From: He Zhe <[email protected]>

commit d47422d953e258ad587b5edf2274eb95d08bdc7d upstream.

As stated in linux/errno.h, ENOTSUPP should never be seen by user programs. When we set up uprobe with 32-bit perf and arm64 kernel, we would see the following vague error without useful hint.

The sys_perf_event_open() syscall returned with 524 (INTERNAL ERROR:
strerror_r(524, [buf], 128)=22)

Use EOPNOTSUPP instead to indicate such cases.

---
 arch/arm64/kernel/probes/uprobes.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/probes/uprobes.c +1 -1
@@ -41,7 +41,7 @@ int arch_uprobe_analyze_insn(struct arch
 
 	/* TODO: Currently we do not support AARCH32 instruction probing */
 	if (mm->context.flags & MMCF_AARCH32)
-		return -ENOTSUPP;
+		return -EOPNOTSUPP;
 	else if (!IS_ALIGNED(addr, AARCH64_INSN_SIZE))
 		return -EINVAL;
 
author maintainer
#242 lore raw

PATCH 216/247 watchdog: mei_wdt: request stop on unregister

In reply to Greg Kroah-Hartman

From: Alexander Usyskin <[email protected]>

commit 740c0a57b8f1e36301218bf549f3c9cc833a60be upstream.

The MEI bus has a special behavior on suspend it destroys all the attached devices, this is due to the fact that also firmware context is not persistent across power flows.

If watchdog on MEI bus is ticking before suspending the firmware times out and reports that the OS is missing watchdog tick. Send the stop command to the firmware on watchdog unregistered to eliminate the false event on suspend.
This does not make the things worse from the user-space perspective as a user-space should re-open watchdog device after suspending before this patch.

---
 drivers/watchdog/mei_wdt.c |    1 +
 1 file changed, 1 insertion(+)
drivers/watchdog/mei_wdt.c +1 -0
@@ -382,6 +382,7 @@ static int mei_wdt_register(struct mei_w
 
 	watchdog_set_drvdata(&wdt->wdd, wdt);
 	watchdog_stop_on_reboot(&wdt->wdd);
+	watchdog_stop_on_unregister(&wdt->wdd);
 
 	ret = watchdog_register_device(&wdt->wdd);
 	if (ret) {
author maintainer
#243 lore raw

PATCH 217/247 mtd: spi-nor: hisi-sfc: Put child node np on error path

In reply to Greg Kroah-Hartman

From: Pan Bian <[email protected]>

commit fe6653460ee7a7dbe0cd5fd322992af862ce5ab0 upstream.

Put the child node np when it fails to get or register device.

Fixes e523f11141bd ("mtd: spi-nor: add hisilicon spi-nor flash controller driver")
[ta: Add Fixes tag and Cc stable]
---
 drivers/mtd/spi-nor/hisi-sfc.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/hisi-sfc.c +3 -1
@@ -408,8 +408,10 @@ static int hisi_spi_nor_register_all(str
 
 	for_each_available_child_of_node(dev->of_node, np) {
 		ret = hisi_spi_nor_register(np, host);
-		if (ret)
+		if (ret) {
+			of_node_put(np);
 			goto fail;
+		}
 
 		if (host->num_chip == HIFMC_MAX_CHIP_NUM) {
 			dev_warn(dev, "Flash device number exceeds the maximum chipselect number\n");
author maintainer
#244 lore raw

PATCH 218/247 fs/affs: release old buffer head on error path

In reply to Greg Kroah-Hartman

From: Pan Bian <[email protected]>

commit 70779b897395b330ba5a47bed84f94178da599f9 upstream.

The reference count of the old buffer head should be decremented on path that fails to get the new buffer head.

Fixes 6b4657667ba0 ("fs/affs: add rename exchange")
---
 fs/affs/namei.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/affs/namei.c +3 -1
@@ -460,8 +460,10 @@ affs_xrename(struct inode *old_dir, stru
 		return -EIO;
 
 	bh_new = affs_bread(sb, d_inode(new_dentry)->i_ino);
-	if (!bh_new)
+	if (!bh_new) {
+		affs_brelse(bh_old);
 		return -EIO;
+	}
 
 	/* Remove old header from its parent directory. */
 	affs_lock_dir(old_dir);
author maintainer
#245 lore raw

PATCH 219/247 seq_file: document how per-entry resources are managed.

In reply to Greg Kroah-Hartman

From: NeilBrown <[email protected]>

commit b3656d8227f4c45812c6b40815d8f4e446ed372a upstream.

Patch series "Fix some seq_file users that were recently broken".

A recent change to seq_file broke some users which were using seq_file in a non-"standard" way ... though the "standard" isn't documented, so they can be excused. The result is a possible leak - of memory in one case, of references to a 'transport' in the other.

These three patches:
1/ document and explain the problem
2/ fix the problem user in x86
3/ fix the problem user in net/sctp

This patch (of 3):

Users of seq_file will sometimes find it convenient to take a resource, such as a lock or memory allocation, in the ->start or ->next operations. These are per-entry resources, distinct from per-session resources which are taken in ->start and released in ->stop.

The preferred management of these is release the resource on the subsequent call to ->next or ->stop.

However prior to Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") it happened that ->show would always be called after ->start or ->next, and a few users chose to release the resource in ->show.

This is no longer reliable. Since the mentioned commit, ->next will always come after a successful ->show (to ensure m->index is updated correctly), so the original ordering cannot be maintained.

This patch updates the documentation to clearly state the required behaviour. Other patches will fix the few problematic users.

[[email protected]: fix typo, per Willy]

Fixes 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface")
Cc Xin Long <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Vlad Yasevich <[email protected]>
Cc Neil Horman <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 Documentation/filesystems/seq_file.txt |    6 ++++++
 1 file changed, 6 insertions(+)
Documentation/filesystems/seq_file.txt +6 -0
@@ -192,6 +192,12 @@ between the calls to start() and stop(),
 is a reasonable thing to do. The seq_file code will also avoid taking any
 other locks while the iterator is active.
 
+The iterater value returned by start() or next() is guaranteed to be
+passed to a subsequent next() or stop() call.  This allows resources
+such as locks that were taken to be reliably released.  There is *no*
+guarantee that the iterator will be passed to show(), though in practice
+it often will be.
+
 
 Formatted output
 
author maintainer
#246 lore raw

PATCH 220/247 x86: fix seq_file iteration for pat/memtype.c

In reply to Greg Kroah-Hartman

From: NeilBrown <[email protected]>

commit 3d2fc4c082448e9c05792f9b2a11c1d5db408b85 upstream.

The memtype seq_file iterator allocates a buffer in the ->start and ->next functions and frees it in the ->show function. The preferred handling for such resources is to free them in the subsequent ->next or ->stop function call.

Since Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") there is no guarantee that ->show will be called after ->next, so this function can now leak memory.

So move the freeing of the buffer to ->next and ->stop.

Fixes 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface")
Cc Xin Long <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc Neil Horman <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Vlad Yasevich <[email protected]>
---
 arch/x86/mm/pat.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/pat.c +2 -1
@@ -1131,12 +1131,14 @@ static void *memtype_seq_start(struct se
 
 static void *memtype_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
+	kfree(v);
 	++*pos;
 	return memtype_get_idx(*pos);
 }
 
 static void memtype_seq_stop(struct seq_file *seq, void *v)
 {
+	kfree(v);
 }
 
 static int memtype_seq_show(struct seq_file *seq, void *v)
@@ -1145,7 +1147,6 @@ static int memtype_seq_show(struct seq_f
 
 	seq_printf(seq, "%s @ 0x%Lx-0x%Lx\n", cattr_name(print_entry->type),
 			print_entry->start, print_entry->end);
-	kfree(print_entry);
 
 	return 0;
 }
author maintainer
#247 lore raw

PATCH 221/247 hugetlb: fix copy_huge_page_from_user contig page struct assumption

In reply to Greg Kroah-Hartman

From: Mike Kravetz <[email protected]>

commit 3272cfc2525b3a2810a59312d7a1e6f04a0ca3ef upstream.

page structs are not guaranteed to be contiguous for gigantic pages. The routine copy_huge_page_from_user can encounter gigantic pages, yet it assumes page structs are contiguous when copying pages from user space.

Since page structs for the target gigantic page are not contiguous, the data copied from user space could overwrite other pages not associated with the gigantic page and cause data corruption.

Non-contiguous page structs are generally not an issue. However, they can exist with a specific kernel configuration and hotplug operations. For
example: Configure the kernel with CONFIG_SPARSEMEM and !CONFIG_SPARSEMEM_VMEMMAP. Then, hotplug add memory for the area where the gigantic page will be allocated.

Fixes 8fb5debc5fcd ("userfaultfd: hugetlbfs: add hugetlb_mcopy_atomic_pte for userfaultfd support")
Cc Zi Yan <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc "Kirill A . Shutemov" <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Joao Martins <[email protected]>
---
 mm/memory.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
mm/memory.c +6 -4
@@ -4885,17 +4885,19 @@ long copy_huge_page_from_user(struct pag
 	void *page_kaddr;
 	unsigned long i, rc = 0;
 	unsigned long ret_val = pages_per_huge_page * PAGE_SIZE;
+	struct page *subpage = dst_page;
 
-	for (i = 0; i < pages_per_huge_page; i++) {
+	for (i = 0; i < pages_per_huge_page;
+	     i++, subpage = mem_map_next(subpage, dst_page, i)) {
 		if (allow_pagefault)
-			page_kaddr = kmap(dst_page + i);
+			page_kaddr = kmap(subpage);
 		else
-			page_kaddr = kmap_atomic(dst_page + i);
+			page_kaddr = kmap_atomic(subpage);
 		rc = copy_from_user(page_kaddr,
 				(const void __user *)(src + i * PAGE_SIZE),
 				PAGE_SIZE);
 		if (allow_pagefault)
-			kunmap(dst_page + i);
+			kunmap(subpage);
 		else
 			kunmap_atomic(page_kaddr);
 
author maintainer
#248 lore raw

PATCH 222/247 libnvdimm/dimm: Avoid race between probe and available_slots_show()

In reply to Greg Kroah-Hartman

From: Dan Williams <[email protected]>

commit 7018c897c2f243d4b5f1b94bc6b4831a7eab80fb upstream

Richard reports that the following test:

(while true; do
cat /sys/bus/nd/devices/nmem*/available_slots 2>&1 > /dev/null
done) &

while true; do
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/bind
done
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/unbind
done
done

...fails with a crash signature like:

    divide error: 0000 [#1] SMP KASAN PTI
    RIP: 0010:nd_label_nfree+0x134/0x1a0 [libnvdimm]
    [..]
    Call Trace:
     available_slots_show+0x4e/0x120 [libnvdimm]
     dev_attr_show+0x42/0x80
     ? memset+0x20/0x40
     sysfs_kf_seq_show+0x218/0x410

The root cause is that available_slots_show() consults driver-data, but fails to synchronize against device-unbind setting up a TOCTOU race to access uninitialized memory.

Validate driver-data under the device-lock.

Fixes 4d88a97aa9e8 ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver infrastructure")
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Coly Li <[email protected]>
[sudip: use device_lock()]
---
 drivers/nvdimm/dimm_devs.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/nvdimm/dimm_devs.c +15 -3
@@ -359,16 +359,16 @@ static ssize_t state_show(struct device
 }
 static DEVICE_ATTR_RO(state);
 
-static ssize_t available_slots_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
+static ssize_t __available_slots_show(struct nvdimm_drvdata *ndd, char *buf)
 {
-	struct nvdimm_drvdata *ndd = dev_get_drvdata(dev);
+	struct device *dev;
 	ssize_t rc;
 	u32 nfree;
 
 	if (!ndd)
 		return -ENXIO;
 
+	dev = ndd->dev;
 	nvdimm_bus_lock(dev);
 	nfree = nd_label_nfree(ndd);
 	if (nfree - 1 > nfree) {
@@ -380,6 +380,18 @@ static ssize_t available_slots_show(stru
 	nvdimm_bus_unlock(dev);
 	return rc;
 }
+
+static ssize_t available_slots_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	ssize_t rc;
+
+	device_lock(dev);
+	rc = __available_slots_show(dev_get_drvdata(dev), buf);
+	device_unlock(dev);
+
+	return rc;
+}
 static DEVICE_ATTR_RO(available_slots);
 
 static struct attribute *nvdimm_attributes[] = {
author maintainer
#249 lore raw

PATCH 223/247 arm64: Extend workaround for erratum 1024718 to all versions of Cortex-A55

In reply to Greg Kroah-Hartman

From: Suzuki K Poulose <[email protected]>

commit c0b15c25d25171db4b70cc0b7dbc1130ee94017d upstream.

The erratum 1024718 affects Cortex-A55 r0p0 to r2p0. However we apply the work around for r0p0 - r1p0. Unfortunately this won't be fixed for the future revisions for the CPU. Thus extend the work around for all versions of A55, to cover for r2p0 and any future revisions.

---
 arch/arm64/Kconfig             |    2 +-
 arch/arm64/kernel/cpufeature.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -473,7 +473,7 @@ config ARM64_ERRATUM_1024718
 	help
 	  This option adds work around for Arm Cortex-A55 Erratum 1024718.
 
-	  Affected Cortex-A55 cores (r0p0, r0p1, r1p0) could cause incorrect
+	  Affected Cortex-A55 cores (all revisions) could cause incorrect
 	  update of the hardware dirty bit when the DBM/AP bits are updated
 	  without a break-before-make. The work around is to disable the usage
 	  of hardware DBM locally on the affected cores. CPUs not affected by
arch/arm64/kernel/cpufeature.c +1 -1
@@ -1012,7 +1012,7 @@ static bool cpu_has_broken_dbm(void)
 	/* List of CPUs which have broken DBM support. */
 	static const struct midr_range cpus[] = {
 #ifdef CONFIG_ARM64_ERRATUM_1024718
-		MIDR_RANGE(MIDR_CORTEX_A55, 0, 0, 1, 0),  // A55 r0p0 -r1p0
+		MIDR_ALL_VERSIONS(MIDR_CORTEX_A55),
 #endif
 		{},
 	};
author maintainer
#250 lore raw

PATCH 224/247 module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols

In reply to Greg Kroah-Hartman

From: Fangrui Song <[email protected]>

commit ebfac7b778fac8b0e8e92ec91d0b055f046b4604 upstream.

clang-12 -fno-pic (since
https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6)
can emit call __stack_chk_fail@PLT instead of call __stack_chk_fail on x86. The two forms should have identical behaviors on x86-64 but the former causes GNU as<2.37 to produce an unreferenced undefined symbol _GLOBAL_OFFSET_TABLE_.

(On x86-32, there is an R_386_PC32 vs R_386_PLT32 difference but the linker behavior is identical as far as Linux kernel is concerned.)

Simply ignore _GLOBAL_OFFSET_TABLE_ for now, like what scripts/mod/modpost.c:ignore_undef_symbol does. This also fixes the problem for gcc/clang -fpie and -fpic, which may emit call foo@PLT for external function calls on x86.

Note: ld -z defs and dynamic loaders do not error for unreferenced undefined symbols so the module loader is reading too much. If we ever need to ignore more symbols, the code should be refactored to ignore unreferenced symbols.

---
 kernel/module.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
kernel/module.c +19 -2
@@ -2274,6 +2274,21 @@ static int verify_export_symbols(struct
 	return 0;
 }
 
+static bool ignore_undef_symbol(Elf_Half emachine, const char *name)
+{
+	/*
+	 * On x86, PIC code and Clang non-PIC code may have call foo@PLT. GNU as
+	 * before 2.37 produces an unreferenced _GLOBAL_OFFSET_TABLE_ on x86-64.
+	 * i386 has a similar problem but may not deserve a fix.
+	 *
+	 * If we ever have to ignore many symbols, consider refactoring the code to
+	 * only warn if referenced by a relocation.
+	 */
+	if (emachine == EM_386 || emachine == EM_X86_64)
+		return !strcmp(name, "_GLOBAL_OFFSET_TABLE_");
+	return false;
+}
+
 /* Change all symbols so that st_value encodes the pointer directly. */
 static int simplify_symbols(struct module *mod, const struct load_info *info)
 {
@@ -2319,8 +2334,10 @@ static int simplify_symbols(struct modul
 				break;
 			}
 
-			/* Ok if weak.  */
-			if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
+			/* Ok if weak or ignored.  */
+			if (!ksym &&
+			    (ELF_ST_BIND(sym[i].st_info) == STB_WEAK ||
+			     ignore_undef_symbol(info->hdr->e_machine, name)))
 				break;
 
 			ret = PTR_ERR(ksym) ?: -ENOENT;
author maintainer
#251 lore raw

PATCH 225/247 mmc: sdhci-esdhc-imx: fix kernel panic when remove module

In reply to Greg Kroah-Hartman

From: Frank Li <[email protected]>

commit a56f44138a2c57047f1ea94ea121af31c595132b upstream.

In sdhci_esdhc_imx_remove() the SDHCI_INT_STATUS in read. Under some circumstances, this may be done while the device is runtime suspended, triggering the below splat.

Fix the problem by adding a pm_runtime_get_sync(), before reading the register, which will turn on clocks etc making the device accessible again.

[ 1811.323148] mmc1: card aaaa removed
[ 1811.347483] Internal error: synchronous external abort: 96000210 [#1] PREEMPT SMP
[ 1811.354988] Modules linked in: sdhci_esdhc_imx(-) sdhci_pltfm sdhci cqhci mmc_block mmc_core [last unloaded: mmc_core]
[ 1811.365726] CPU: 0 PID: 3464 Comm: rmmod Not tainted 5.10.1-sd-99871-g53835a2e8186 #5
[ 1811.373559] Hardware name: Freescale i.MX8DXL EVK (DT)
[ 1811.378705] pstate: 60000005 (nZCv daif -PAN -UAO -TCO BTYPE=--)
[ 1811.384723] pc : sdhci_esdhc_imx_remove+0x28/0x15c [sdhci_esdhc_imx]
[ 1811.391090] lr : platform_drv_remove+0x2c/0x50
[ 1811.395536] sp : ffff800012c7bcb0
[ 1811.398855] x29: ffff800012c7bcb0 x28: ffff00002c72b900
[ 1811.404181] x27: 0000000000000000 x26: 0000000000000000
[ 1811.409497] x25: 0000000000000000 x24: 0000000000000000
[ 1811.414814] x23: ffff0000042b3890 x22: ffff800009127120
[ 1811.420131] x21: ffff00002c4c9580 x20: ffff0000042d0810
[ 1811.425456] x19: ffff0000042d0800 x18: 0000000000000020
[ 1811.430773] x17: 0000000000000000 x16: 0000000000000000
[ 1811.436089] x15: 0000000000000004 x14: ffff000004019c10
[ 1811.441406] x13: 0000000000000000 x12: 0000000000000020
[ 1811.446723] x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f
[ 1811.452040] x9 : fefefeff6364626d x8 : 7f7f7f7f7f7f7f7f
[ 1811.457356] x7 : 78725e6473607372 x6 : 0000000080808080
[ 1811.462673] x5 : 0000000000000000 x4 : 0000000000000000
[ 1811.467990] x3 : ffff800011ac1cb0 x2 : 0000000000000000
[ 1811.473307] x1 : ffff8000091214d4 x0 : ffff8000133a0030
[ 1811.478624] Call trace:
[ 1811.481081]  sdhci_esdhc_imx_remove+0x28/0x15c [sdhci_esdhc_imx]
[ 1811.487098]  platform_drv_remove+0x2c/0x50
[ 1811.491198]  __device_release_driver+0x188/0x230
[ 1811.495818]  driver_detach+0xc0/0x14c
[ 1811.499487]  bus_remove_driver+0x5c/0xb0
[ 1811.503413]  driver_unregister+0x30/0x60
[ 1811.507341]  platform_driver_unregister+0x14/0x20
[ 1811.512048]  sdhci_esdhc_imx_driver_exit+0x1c/0x3a8 [sdhci_esdhc_imx]
[ 1811.518495]  __arm64_sys_delete_module+0x19c/0x230
[ 1811.523291]  el0_svc_common.constprop.0+0x78/0x1a0
[ 1811.528086]  do_el0_svc+0x24/0x90
[ 1811.531405]  el0_svc+0x14/0x20
[ 1811.534461]  el0_sync_handler+0x1a4/0x1b0
[ 1811.538474]  el0_sync+0x174/0x180
[ 1811.541801] Code: a9025bf5 f9403e95 f9400ea0 9100c000 (b9400000)
[ 1811.547902] ---[ end trace 3fb1a3bd48ff7be5 ]---
---
 drivers/mmc/host/sdhci-esdhc-imx.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-esdhc-imx.c +2 -1
@@ -1370,9 +1370,10 @@ static int sdhci_esdhc_imx_remove(struct
 	struct sdhci_host *host = platform_get_drvdata(pdev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
-	int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
+	int dead;
 
 	pm_runtime_get_sync(&pdev->dev);
+	dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 
author maintainer
#252 lore raw

PATCH 226/247 gpio: pcf857x: Fix missing first interrupt

In reply to Greg Kroah-Hartman

From: Maxim Kiselev <[email protected]>

commit a8002a35935aaefcd6a42ad3289f62bab947f2ca upstream.

If no n_latch value will be provided at driver probe then all pins will be used as an input:

    gpio->out = ~n_latch;

In that case initial state for all pins is "one":

    gpio->status = gpio->out;

So if pcf857x IRQ happens with change pin value from "zero" to "one" then we miss it, because of "one" from IRQ and "one" from initial state leaves corresponding pin unchanged:
change = (gpio->status ^ status) & gpio->irq_enabled;

The right solution will be to read actual state at driver probe.

Fixes 6e20a0a429bd ("gpio: pcf857x: enable gpio_to_irq() support")
---
 drivers/gpio/gpio-pcf857x.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pcf857x.c +1 -1
@@ -357,7 +357,7 @@ static int pcf857x_probe(struct i2c_clie
 	 * reset state.  Otherwise it flags pins to be driven low.
 	 */
 	gpio->out = ~n_latch;
-	gpio->status = gpio->out;
+	gpio->status = gpio->read(gpio->client);
 
 	status = devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio);
 	if (status < 0)
author maintainer
#253 lore raw

PATCH 227/247 printk: fix deadlock when kernel panic

In reply to Greg Kroah-Hartman

From: Muchun Song <[email protected]>

commit 8a8109f303e25a27f92c1d8edd67d7cbbc60a4eb upstream.

printk_safe_flush_on_panic() caused the following deadlock on our server:

CPU0: CPU1:
panic rcu_dump_cpu_stacks
kdump_nmi_shootdown_cpus nmi_trigger_cpumask_backtrace

    register_nmi_handler(crash_nmi_callback)      printk_safe_flush
                                                    __printk_safe_flush
                                                      raw_spin_lock_irqsave(&read_lock)
    // send NMI to other processors
    apic_send_IPI_allbutself(NMI_VECTOR)
                                                        // NMI interrupt, dead loop
                                                        crash_nmi_callback
  printk_safe_flush_on_panic
    printk_safe_flush
      __printk_safe_flush
        // deadlock
        raw_spin_lock_irqsave(&read_lock)

DEADLOCK: read_lock is taken on CPU1 and will never get released.

It happens when panic() stops a CPU by NMI while it has been in the middle of printk_safe_flush().

Handle the lock the same way as logbuf_lock. The printk_safe buffers are flushed only when both locks can be safely taken. It can avoid the deadlock _in this particular case_ at expense of losing contents of printk_safe buffers.

Note: It would actually be safe to re-init the locks when all CPUs were
stopped by NMI. But it would require passing this information from arch-specific code. It is not worth the complexity. Especially because logbuf_lock and printk_safe buffers have been obsoleted by the lockless ring buffer.

---
 kernel/printk/printk_safe.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
kernel/printk/printk_safe.c +12 -4
@@ -55,6 +55,8 @@ struct printk_safe_seq_buf {
 static DEFINE_PER_CPU(struct printk_safe_seq_buf, safe_print_seq);
 static DEFINE_PER_CPU(int, printk_context);
 
+static DEFINE_RAW_SPINLOCK(safe_read_lock);
+
 #ifdef CONFIG_PRINTK_NMI
 static DEFINE_PER_CPU(struct printk_safe_seq_buf, nmi_print_seq);
 #endif
@@ -190,8 +192,6 @@ static void report_message_lost(struct p
  */
 static void __printk_safe_flush(struct irq_work *work)
 {
-	static raw_spinlock_t read_lock =
-		__RAW_SPIN_LOCK_INITIALIZER(read_lock);
 	struct printk_safe_seq_buf *s =
 		container_of(work, struct printk_safe_seq_buf, work);
 	unsigned long flags;
@@ -205,7 +205,7 @@ static void __printk_safe_flush(struct i
 	 * different CPUs. This is especially important when printing
 	 * a backtrace.
 	 */
-	raw_spin_lock_irqsave(&read_lock, flags);
+	raw_spin_lock_irqsave(&safe_read_lock, flags);
 
 	i = 0;
 more:
@@ -242,7 +242,7 @@ more:
 
 out:
 	report_message_lost(s);
-	raw_spin_unlock_irqrestore(&read_lock, flags);
+	raw_spin_unlock_irqrestore(&safe_read_lock, flags);
 }
 
 /**
@@ -288,6 +288,14 @@ void printk_safe_flush_on_panic(void)
 		raw_spin_lock_init(&logbuf_lock);
 	}
 
+	if (raw_spin_is_locked(&safe_read_lock)) {
+		if (num_online_cpus() > 1)
+			return;
+
+		debug_locks_off();
+		raw_spin_lock_init(&safe_read_lock);
+	}
+
 	printk_safe_flush();
 }
 
author maintainer
#254 lore raw

PATCH 228/247 cpufreq: intel_pstate: Get per-CPU max freq via MSR_HWP_CAPABILITIES if available

In reply to Greg Kroah-Hartman

From: Chen Yu <[email protected]>

commit 6f67e060083a84a4cc364eab6ae40c717165fb0c upstream.

Currently, when turbo is disabled (either by BIOS or by the user), the intel_pstate driver reads the max non-turbo frequency from the package-wide MSR_PLATFORM_INFO(0xce) register.

However, on asymmetric platforms it is possible in theory that small and big core with HWP enabled might have different max non-turbo CPU frequency, because MSR_HWP_CAPABILITIES is per-CPU scope according to Intel Software Developer Manual.

The turbo max freq is already per-CPU in current code, so make similar change to the max non-turbo frequency as well.

[ rjw: Subject and changelog edits ]
Cc 4.18+ <[email protected]> # 4.18+: a45ee4d4e13b: cpufreq: intel_pstate: Change intel_pstate_get_hwp_max() argument
---
 drivers/cpufreq/intel_pstate.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +3 -2
@@ -1420,11 +1420,9 @@ static void intel_pstate_max_within_limi
 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
 {
 	cpu->pstate.min_pstate = pstate_funcs.get_min();
-	cpu->pstate.max_pstate = pstate_funcs.get_max();
 	cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical();
 	cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
 	cpu->pstate.scaling = pstate_funcs.get_scaling();
-	cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;
 
 	if (hwp_active && !hwp_mode_bdw) {
 		unsigned int phy_max, current_max;
@@ -1432,9 +1430,12 @@ static void intel_pstate_get_cpu_pstates
 		intel_pstate_get_hwp_max(cpu->cpu, &phy_max, &current_max);
 		cpu->pstate.turbo_freq = phy_max * cpu->pstate.scaling;
 		cpu->pstate.turbo_pstate = phy_max;
+		cpu->pstate.max_pstate = HWP_GUARANTEED_PERF(READ_ONCE(cpu->hwp_cap_cached));
 	} else {
 		cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
+		cpu->pstate.max_pstate = pstate_funcs.get_max();
 	}
+	cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling;
 
 	if (pstate_funcs.get_aperf_mperf_shift)
 		cpu->aperf_mperf_shift = pstate_funcs.get_aperf_mperf_shift();
author maintainer
#255 lore raw

PATCH 229/247 f2fs: fix out-of-repair __setattr_copy()

In reply to Greg Kroah-Hartman

From: Chao Yu <[email protected]>

commit 2562515f0ad7342bde6456602c491b64c63fe950 upstream.

__setattr_copy() was copied from setattr_copy() in fs/attr.c, there is two missing patches doesn't cover this inner function, fix it.

Commit 7fa294c8991c ("userns: Allow chown and setgid preservation") Commit 23adbe12ef7d ("fs,userns: Change inode_capable to capable_wrt_inode_uidgid")

Fixes fbfa2cc58d53 ("f2fs: add file operations")
---
 fs/f2fs/file.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/file.c +2 -1
@@ -760,7 +760,8 @@ static void __setattr_copy(struct inode
 	if (ia_valid & ATTR_MODE) {
 		umode_t mode = attr->ia_mode;
 
-		if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
+		if (!in_group_p(inode->i_gid) &&
+			!capable_wrt_inode_uidgid(inode, CAP_FSETID))
 			mode &= ~S_ISGID;
 		set_acl_inode(inode, mode);
 	}
author maintainer
#256 lore raw

PATCH 230/247 sparc32: fix a user-triggerable oops in clear_user()

In reply to Greg Kroah-Hartman

From: Al Viro <[email protected]>

commit 7780918b36489f0b2f9a3749d7be00c2ceaec513 upstream.

Back in 2.1.29 the clear_user() guts (__bzero()) had been merged with memset(). Unfortunately, while all exception handlers had been copied, one of the exception table entries got lost. As the result, clear_user() starting at 128*n bytes before the end of page and spanning between 8 and 127 bytes into the next page would oops when the second page is unmapped. It's trivial to reproduce - all it takes is

main()

{
	int fd = open("/dev/zero", O_RDONLY);
	char *p = mmap(NULL, 16384, PROT_READ|PROT_WRITE,
			MAP_PRIVATE|MAP_ANON, -1, 0);
	munmap(p + 8192, 8192);
	read(fd, p + 8192 - 128, 192);
}

which had been oopsing since March 1997. Says something about the quality of test coverage... ;-/ And while today sparc32 port is nearly dead, back in '97 it had been very much alive; in fact, sparc64 had only been in mainline for 3 months by that point...

---
 arch/sparc/lib/memset.S |    1 +
 1 file changed, 1 insertion(+)
arch/sparc/lib/memset.S +1 -0
@@ -142,6 +142,7 @@ __bzero:
 	ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
 	ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
 13:
+	EXT(12b, 13b, 21f)
 	be	8f
 	 andcc	%o1, 4, %g0
 
author maintainer
#257 lore raw

PATCH 231/247 gfs2: Dont skip dlm unlock if glock has an lvb

In reply to Greg Kroah-Hartman

From: Bob Peterson <[email protected]>

commit 78178ca844f0eb88f21f31c7fde969384be4c901 upstream.

Patch fb6791d100d1 was designed to allow gfs2 to unmount quicker by skipping the step where it tells dlm to unlock glocks in EX with lvbs. This was done because when gfs2 unmounts a file system, it destroys the dlm lockspace shortly after it destroys the glocks so it doesn't need to unlock them all: the unlock is implied when the lockspace is destroyed by dlm.

However, that patch introduced a use-after-free in dlm: as part of its normal dlm_recoverd process, it can call ls_recovery to recover dead locks. In so doing, it can call recover_rsbs which calls recover_lvb for any mastered rsbs. Func recover_lvb runs through the list of lkbs queued to the given rsb (if the glock is cached but unlocked, it will still be queued to the lkb, but in NL--Unlocked--mode) and if it has an lvb, copies it to the rsb, thus trying to preserve the lkb. However, when gfs2 skips the dlm unlock step, it frees the glock and its lvb, which means dlm's function recover_lvb references the now freed lvb pointer, copying the freed lvb memory to the rsb.

This patch changes the check in gdlm_put_lock so that it calls dlm_unlock for all glocks that contain an lvb pointer.

Fixes fb6791d100d1 ("GFS2: skip dlm_unlock calls in unmount")
---
 fs/gfs2/lock_dlm.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
fs/gfs2/lock_dlm.c +2 -6
@@ -283,7 +283,6 @@ static void gdlm_put_lock(struct gfs2_gl
 {
 	struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
 	struct lm_lockstruct *ls = &sdp->sd_lockstruct;
-	int lvb_needs_unlock = 0;
 	int error;
 
 	if (gl->gl_lksb.sb_lkid == 0) {
@@ -296,13 +295,10 @@ static void gdlm_put_lock(struct gfs2_gl
 	gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
 	gfs2_update_request_times(gl);
 
-	/* don't want to skip dlm_unlock writing the lvb when lock is ex */
-
-	if (gl->gl_lksb.sb_lvbptr && (gl->gl_state == LM_ST_EXCLUSIVE))
-		lvb_needs_unlock = 1;
+	/* don't want to skip dlm_unlock writing the lvb when lock has one */
 
 	if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) &&
-	    !lvb_needs_unlock) {
+	    !gl->gl_lksb.sb_lvbptr) {
 		gfs2_glock_free(gl);
 		return;
 	}
author maintainer
#258 lore raw

PATCH 232/247 dm: fix deadlock when swapping to encrypted device

In reply to Greg Kroah-Hartman

From: Mikulas Patocka <[email protected]>

commit a666e5c05e7c4aaabb2c5d58117b0946803d03d2 upstream.

The system would deadlock when swapping to a dm-crypt device. The reason is that for each incoming write bio, dm-crypt allocates memory that holds encrypted data. These excessive allocations exhaust all the memory and the result is either deadlock or OOM trigger.

This patch limits the number of in-flight swap bios, so that the memory consumed by dm-crypt is limited. The limit is enforced if the target set the "limit_swap_bios" variable and if the bio has REQ_SWAP set.

Non-swap bios are not affected becuase taking the semaphore would cause performance degradation.

This is similar to request-based drivers - they will also block when the number of requests is over the limit.

---
 drivers/md/dm-core.h          |    4 ++
 drivers/md/dm-crypt.c         |    1 
 drivers/md/dm.c               |   60 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |    5 +++
 4 files changed, 70 insertions(+)
drivers/md/dm-core.h +4 -0
@@ -110,6 +110,10 @@ struct mapped_device {
 	/* zero-length flush that will be cloned and submitted to targets */
 	struct bio flush_bio;
 
+	int swap_bios;
+	struct semaphore swap_bios_semaphore;
+	struct mutex swap_bios_lock;
+
 	struct dm_stats stats;
 
 	struct kthread_worker kworker;
drivers/md/dm-crypt.c +1 -0
@@ -2852,6 +2852,7 @@ static int crypt_ctr(struct dm_target *t
 	wake_up_process(cc->write_thread);
 
 	ti->num_flush_bios = 1;
+	ti->limit_swap_bios = true;
 
 	return 0;
 
drivers/md/dm.c +60 -0

118 lines not on this page · raw message

include/linux/device-mapper.h +5 -0
@@ -315,6 +315,11 @@ struct dm_target {
 	 * on max_io_len boundary.
 	 */
 	bool split_discard_bios:1;
+
+	/*
+	 * Set if we need to limit the number of in-flight bios when swapping.
+	 */
+	bool limit_swap_bios:1;
 };
 
 /* Each target can link one of these into the table */
author maintainer
#259 lore raw

PATCH 233/247 dm era: Recover committed writeset after crash

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit de89afc1e40fdfa5f8b666e5d07c43d21a1d3be0 upstream.

Following a system crash, dm-era fails to recover the committed writeset for the current era, leading to lost writes. That is, we lose the information about what blocks were written during the affected era.

dm-era assumes that the writeset of the current era is archived when the device is suspended. So, when resuming the device, it just moves on to the next era, ignoring the committed writeset.

This assumption holds when the device is properly shut down. But, when the system crashes, the code that suspends the target never runs, so the writeset for the current era is not archived.

There are three issues that cause the committed writeset to get lost:

1. dm-era doesn't load the committed writeset when opening the metadata
2. The code that resizes the metadata wipes the information about the committed writeset (assuming it was loaded at step 1)
3. era_preresume() starts a new era, without taking into account that the current era might not have been archived, due to a system crash.

To fix this:

1. Load the committed writeset when opening the metadata
2. Fix the code that resizes the metadata to make sure it doesn't wipe the loaded writeset
3. Fix era_preresume() to check for a loaded writeset and archive it, before starting a new era.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/md/dm-era-target.c +9 -8
@@ -70,8 +70,6 @@ static size_t bitset_size(unsigned nr_bi
  */
 static int writeset_alloc(struct writeset *ws, dm_block_t nr_blocks)
 {
-	ws->md.nr_bits = nr_blocks;
-	ws->md.root = INVALID_WRITESET_ROOT;
 	ws->bits = vzalloc(bitset_size(nr_blocks));
 	if (!ws->bits) {
 		DMERR("%s: couldn't allocate in memory bitset", __func__);
@@ -84,12 +82,14 @@ static int writeset_alloc(struct writese
 /*
  * Wipes the in-core bitset, and creates a new on disk bitset.
  */
-static int writeset_init(struct dm_disk_bitset *info, struct writeset *ws)
+static int writeset_init(struct dm_disk_bitset *info, struct writeset *ws,
+			 dm_block_t nr_blocks)
 {
 	int r;
 
-	memset(ws->bits, 0, bitset_size(ws->md.nr_bits));
+	memset(ws->bits, 0, bitset_size(nr_blocks));
 
+	ws->md.nr_bits = nr_blocks;
 	r = setup_on_disk_bitset(info, ws->md.nr_bits, &ws->md.root);
 	if (r) {
 		DMERR("%s: setup_on_disk_bitset failed", __func__);
@@ -578,6 +578,7 @@ static int open_metadata(struct era_meta
 	md->nr_blocks = le32_to_cpu(disk->nr_blocks);
 	md->current_era = le32_to_cpu(disk->current_era);
 
+	ws_unpack(&disk->current_writeset, &md->current_writeset->md);
 	md->writeset_tree_root = le64_to_cpu(disk->writeset_tree_root);
 	md->era_array_root = le64_to_cpu(disk->era_array_root);
 	md->metadata_snap = le64_to_cpu(disk->metadata_snap);
@@ -869,7 +870,6 @@ static int metadata_era_archive(struct e
 	}
 
 	ws_pack(&md->current_writeset->md, &value);
-	md->current_writeset->md.root = INVALID_WRITESET_ROOT;
 
 	keys[0] = md->current_era;
 	__dm_bless_for_disk(&value);
@@ -881,6 +881,7 @@ static int metadata_era_archive(struct e
 		return r;
 	}
 
+	md->current_writeset->md.root = INVALID_WRITESET_ROOT;
 	md->archived_writesets = true;
 
 	return 0;
@@ -897,7 +898,7 @@ static int metadata_new_era(struct era_m
 	int r;
 	struct writeset *new_writeset = next_writeset(md);
 
-	r = writeset_init(&md->bitset_info, new_writeset);
+	r = writeset_init(&md->bitset_info, new_writeset, md->nr_blocks);
 	if (r) {
 		DMERR("%s: writeset_init failed", __func__);
 		return r;
@@ -950,7 +951,7 @@ static int metadata_commit(struct era_me
 	int r;
 	struct dm_block *sblock;
 
-	if (md->current_writeset->md.root != SUPERBLOCK_LOCATION) {
+	if (md->current_writeset->md.root != INVALID_WRITESET_ROOT) {
 		r = dm_bitset_flush(&md->bitset_info, md->current_writeset->md.root,
 				    &md->current_writeset->md.root);
 		if (r) {
@@ -1579,7 +1580,7 @@ static int era_preresume(struct dm_targe
 
 	start_worker(era);
 
-	r = in_worker0(era, metadata_new_era);
+	r = in_worker0(era, metadata_era_rollover);
 	if (r) {
 		DMERR("%s: metadata_era_rollover failed", __func__);
 		return r;
author maintainer
#260 lore raw

PATCH 234/247 dm era: Verify the data block size hasnt changed

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit c8e846ff93d5eaa5384f6f325a1687ac5921aade upstream.

dm-era doesn't support changing the data block size of existing devices, so check explicitly that the requested block size for a new target matches the one stored in the metadata.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/md/dm-era-target.c +9 -1
@@ -563,6 +563,15 @@ static int open_metadata(struct era_meta
 	}
 
 	disk = dm_block_data(sblock);
+
+	/* Verify the data block size hasn't changed */
+	if (le32_to_cpu(disk->data_block_size) != md->block_size) {
+		DMERR("changing the data block size (from %u to %llu) is not supported",
+		      le32_to_cpu(disk->data_block_size), md->block_size);
+		r = -EINVAL;
+		goto bad;
+	}
+
 	r = dm_tm_open_with_sm(md->bm, SUPERBLOCK_LOCATION,
 			       disk->metadata_space_map_root,
 			       sizeof(disk->metadata_space_map_root),
@@ -574,7 +583,6 @@ static int open_metadata(struct era_meta
 
 	setup_infos(md);
 
-	md->block_size = le32_to_cpu(disk->data_block_size);
 	md->nr_blocks = le32_to_cpu(disk->nr_blocks);
 	md->current_era = le32_to_cpu(disk->current_era);
 
author maintainer
#261 lore raw

PATCH 235/247 dm era: Fix bitset memory leaks

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit 904e6b266619c2da5c58b5dce14ae30629e39645 upstream.

Deallocate the memory allocated for the in-core bitsets when destroying the target and in error paths.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/md/dm-era-target.c +6 -0
@@ -46,6 +46,7 @@ struct writeset {
 static void writeset_free(struct writeset *ws)
 {
 	vfree(ws->bits);
+	ws->bits = NULL;
 }
 
 static int setup_on_disk_bitset(struct dm_disk_bitset *info,
@@ -810,6 +811,8 @@ static struct era_metadata *metadata_ope
 
 static void metadata_close(struct era_metadata *md)
 {
+	writeset_free(&md->writesets[0]);
+	writeset_free(&md->writesets[1]);
 	destroy_persistent_data_objects(md);
 	kfree(md);
 }
@@ -847,6 +850,7 @@ static int metadata_resize(struct era_me
 	r = writeset_alloc(&md->writesets[1], *new_size);
 	if (r) {
 		DMERR("%s: writeset_alloc failed for writeset 1", __func__);
+		writeset_free(&md->writesets[0]);
 		return r;
 	}
 
@@ -857,6 +861,8 @@ static int metadata_resize(struct era_me
 			    &value, &md->era_array_root);
 	if (r) {
 		DMERR("%s: dm_array_resize failed", __func__);
+		writeset_free(&md->writesets[0]);
+		writeset_free(&md->writesets[1]);
 		return r;
 	}
 
author maintainer
#262 lore raw

PATCH 236/247 dm era: Use correct value size in equality function of writeset tree

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit 64f2d15afe7b336aafebdcd14cc835ecf856df4b upstream.

Fix the writeset tree equality test function to use the right value size when comparing two btree values.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-era-target.c +1 -1
@@ -388,7 +388,7 @@ static void ws_dec(void *context, const
 
 static int ws_eq(void *context, const void *value1, const void *value2)
 {
-	return !memcmp(value1, value2, sizeof(struct writeset_metadata));
+	return !memcmp(value1, value2, sizeof(struct writeset_disk));
 }
 
 /*----------------------------------------------------------------*/
author maintainer
#263 lore raw

PATCH 237/247 dm era: Reinitialize bitset cache before digesting a new writeset

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit 2524933307fd0036d5c32357c693c021ab09a0b0 upstream.

In case of devices with at most 64 blocks, the digestion of consecutive eras uses the writeset of the first era as the writeset of all eras to digest, leading to lost writes. That is, we lose the information about what blocks were written during the affected eras.

The digestion code uses a dm_disk_bitset object to access the archived writesets. This structure includes a one word (64-bit) cache to reduce the number of array lookups.

This structure is initialized only once, in metadata_digest_start(), when we kick off digestion.

But, when we insert a new writeset into the writeset tree, before the digestion of the previous writeset is done, or equivalently when there are multiple writesets in the writeset tree to digest, then all these writesets are digested using the same cache and the cache is not re-initialized when moving from one writeset to the next.

For devices with more than 64 blocks, i.e., the size of the cache, the cache is indirectly invalidated when we move to a next set of blocks, so we avoid the bug.

But for devices with at most 64 blocks we end up using the same cached data for digesting all archived writesets, i.e., the cache is loaded when digesting the first writeset and it never gets reloaded, until the digestion is done.

As a result, the writeset of the first era to digest is used as the writeset of all the following archived eras, leading to lost writes.

Fix this by reinitializing the dm_disk_bitset structure, and thus invalidating the cache, every time the digestion code starts digesting a new writeset.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-era-target.c +6 -6
@@ -755,6 +755,12 @@ static int metadata_digest_lookup_writes
 	ws_unpack(&disk, &d->writeset);
 	d->value = cpu_to_le32(key);
 
+	/*
+	 * We initialise another bitset info to avoid any caching side effects
+	 * with the previous one.
+	 */
+	dm_disk_bitset_init(md->tm, &d->info);
+
 	d->nr_bits = min(d->writeset.nr_bits, md->nr_blocks);
 	d->current_bit = 0;
 	d->step = metadata_digest_transcribe_writeset;
@@ -768,12 +774,6 @@ static int metadata_digest_start(struct
 		return 0;
 
 	memset(d, 0, sizeof(*d));
-
-	/*
-	 * We initialise another bitset info to avoid any caching side
-	 * effects with the previous one.
-	 */
-	dm_disk_bitset_init(md->tm, &d->info);
 	d->step = metadata_digest_lookup_writeset;
 
 	return 0;
author maintainer
#264 lore raw

PATCH 238/247 dm era: only resize metadata in preresume

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit cca2c6aebe86f68103a8615074b3578e854b5016 upstream.

Metadata resize shouldn't happen in the ctr. The ctr loads a temporary (inactive) table that will only become active upon resume. That is why resize should always be done in terms of resume. Otherwise a load (ctr) whose inactive table never becomes active will incorrectly resize the metadata.

Also, perform the resize directly in preresume, instead of using the worker to do it.

The worker might run other metadata operations, e.g., it could start digestion, before resizing the metadata. These operations will end up using the old size.

This could lead to errors, like:

device-mapper: era: metadata_digest_transcribe_writeset: dm_array_set_value failed
device-mapper: era: process_old_eras: digest step failed, stopping digestion

The reason of the above error is that the worker started the digestion of the archived writeset using the old, larger size.

As a result, metadata_digest_transcribe_writeset tried to write beyond the end of the era array.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |   21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/md/dm-era-target.c +10 -11
@@ -1500,15 +1500,6 @@ static int era_ctr(struct dm_target *ti,
 	}
 	era->md = md;
 
-	era->nr_blocks = calc_nr_blocks(era);
-
-	r = metadata_resize(era->md, &era->nr_blocks);
-	if (r) {
-		ti->error = "couldn't resize metadata";
-		era_destroy(era);
-		return -ENOMEM;
-	}
-
 	era->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM);
 	if (!era->wq) {
 		ti->error = "could not create workqueue for metadata object";
@@ -1585,9 +1576,17 @@ static int era_preresume(struct dm_targe
 	dm_block_t new_size = calc_nr_blocks(era);
 
 	if (era->nr_blocks != new_size) {
-		r = in_worker1(era, metadata_resize, &new_size);
-		if (r)
+		r = metadata_resize(era->md, &new_size);
+		if (r) {
+			DMERR("%s: metadata_resize failed", __func__);
+			return r;
+		}
+
+		r = metadata_commit(era->md);
+		if (r) {
+			DMERR("%s: metadata_commit failed", __func__);
 			return r;
+		}
 
 		era->nr_blocks = new_size;
 	}
author maintainer
#265 lore raw

PATCH 239/247 icmp: introduce helper for natd source address in network device context

In reply to Greg Kroah-Hartman

From: Jason A. Donenfeld <[email protected]>

commit 0b41713b606694257b90d61ba7e2712d8457648b upstream.

This introduces a helper function to be called only by network drivers that wraps calls to icmp[v6]_send in a conntrack transformation, in case NAT has been used. We don't want to pollute the non-driver path, though, so we introduce this as a helper to be called by places that actually make use of this, as suggested by Florian.

---
 include/linux/icmpv6.h |    6 ++++++
 include/net/icmp.h     |    6 ++++++
 net/ipv4/icmp.c        |   33 +++++++++++++++++++++++++++++++++
 net/ipv6/ip6_icmp.c    |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+)
include/linux/icmpv6.h +6 -0
@@ -31,6 +31,12 @@ static inline void icmpv6_send(struct sk
 }
 #endif
 
+#if IS_ENABLED(CONFIG_NF_NAT)
+void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
+#else
+#define icmpv6_ndo_send icmpv6_send
+#endif
+
 extern int				icmpv6_init(void);
 extern int				icmpv6_err_convert(u8 type, u8 code,
 							   int *err);
include/net/icmp.h +6 -0
@@ -47,6 +47,12 @@ static inline void icmp_send(struct sk_b
 	__icmp_send(skb_in, type, code, info, &IPCB(skb_in)->opt);
 }
 
+#if IS_ENABLED(CONFIG_NF_NAT)
+void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info);
+#else
+#define icmp_ndo_send icmp_send
+#endif
+
 int icmp_rcv(struct sk_buff *skb);
 void icmp_err(struct sk_buff *skb, u32 info);
 int icmp_init(void);
net/ipv4/icmp.c +33 -0
@@ -755,6 +755,39 @@ out:;
 }
 EXPORT_SYMBOL(__icmp_send);
 
+#if IS_ENABLED(CONFIG_NF_NAT)
+#include <net/netfilter/nf_conntrack.h>
+void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info)
+{
+	struct sk_buff *cloned_skb = NULL;
+	enum ip_conntrack_info ctinfo;
+	struct nf_conn *ct;
+	__be32 orig_ip;
+
+	ct = nf_ct_get(skb_in, &ctinfo);
+	if (!ct || !(ct->status & IPS_SRC_NAT)) {
+		icmp_send(skb_in, type, code, info);
+		return;
+	}
+
+	if (skb_shared(skb_in))
+		skb_in = cloned_skb = skb_clone(skb_in, GFP_ATOMIC);
+
+	if (unlikely(!skb_in || skb_network_header(skb_in) < skb_in->head ||
+	    (skb_network_header(skb_in) + sizeof(struct iphdr)) >
+	    skb_tail_pointer(skb_in) || skb_ensure_writable(skb_in,
+	    skb_network_offset(skb_in) + sizeof(struct iphdr))))
+		goto out;
+
+	orig_ip = ip_hdr(skb_in)->saddr;
+	ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip;
+	icmp_send(skb_in, type, code, info);
+	ip_hdr(skb_in)->saddr = orig_ip;
+out:
+	consume_skb(cloned_skb);
+}
+EXPORT_SYMBOL(icmp_ndo_send);
+#endif
 
 static void icmp_socket_deliver(struct sk_buff *skb, u32 info)
 {
net/ipv6/ip6_icmp.c +34 -0
@@ -45,4 +45,38 @@ out:
 	rcu_read_unlock();
 }
 EXPORT_SYMBOL(icmpv6_send);
+
+#if IS_ENABLED(CONFIG_NF_NAT)
+#include <net/netfilter/nf_conntrack.h>
+void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
+{
+	struct sk_buff *cloned_skb = NULL;
+	enum ip_conntrack_info ctinfo;
+	struct in6_addr orig_ip;
+	struct nf_conn *ct;
+
+	ct = nf_ct_get(skb_in, &ctinfo);
+	if (!ct || !(ct->status & IPS_SRC_NAT)) {
+		icmpv6_send(skb_in, type, code, info);
+		return;
+	}
+
+	if (skb_shared(skb_in))
+		skb_in = cloned_skb = skb_clone(skb_in, GFP_ATOMIC);
+
+	if (unlikely(!skb_in || skb_network_header(skb_in) < skb_in->head ||
+	    (skb_network_header(skb_in) + sizeof(struct ipv6hdr)) >
+	    skb_tail_pointer(skb_in) || skb_ensure_writable(skb_in,
+	    skb_network_offset(skb_in) + sizeof(struct ipv6hdr))))
+		goto out;
+
+	orig_ip = ipv6_hdr(skb_in)->saddr;
+	ipv6_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.in6;
+	icmpv6_send(skb_in, type, code, info);
+	ipv6_hdr(skb_in)->saddr = orig_ip;
+out:
+	consume_skb(cloned_skb);
+}
+EXPORT_SYMBOL(icmpv6_ndo_send);
+#endif
 #endif
author maintainer
#266 lore raw

PATCH 240/247 gtp: use icmp_ndo_send helper

In reply to Greg Kroah-Hartman

From: Jason A. Donenfeld <[email protected]>

commit e0fce6f945a26d4e953a147fe7ca11410322c9fe upstream.

Because gtp is calling icmp from network device context, it should use the ndo helper so that the rate limiting applies correctly.

---
 drivers/net/gtp.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/gtp.c +2 -2
@@ -550,8 +550,8 @@ static int gtp_build_skb_ip4(struct sk_b
 	    mtu < ntohs(iph->tot_len)) {
 		netdev_dbg(dev, "packet too big, fragmentation needed\n");
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
-		icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
-			  htonl(mtu));
+		icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+			      htonl(mtu));
 		goto err_rt;
 	}
 
author maintainer
#267 lore raw

PATCH 241/247 sunvnet: use icmp_ndo_send helper

In reply to Greg Kroah-Hartman

From: Jason A. Donenfeld <[email protected]>

commit 67c9a7e1e3ac491b5df018803639addc36f154ba upstream.

Because sunvnet is calling icmp from network device context, it should use the ndo helper so that the rate limiting applies correctly. While we're at it, doing the additional route lookup before calling icmp_ndo_send is superfluous, since this is the job of the icmp code in the first place.

---
 drivers/net/ethernet/sun/sunvnet_common.c |   23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
drivers/net/ethernet/sun/sunvnet_common.c +4 -19
@@ -1353,27 +1353,12 @@ sunvnet_start_xmit_common(struct sk_buff
 		if (vio_version_after_eq(&port->vio, 1, 3))
 			localmtu -= VLAN_HLEN;
 
-		if (skb->protocol == htons(ETH_P_IP)) {
-			struct flowi4 fl4;
-			struct rtable *rt = NULL;
-
-			memset(&fl4, 0, sizeof(fl4));
-			fl4.flowi4_oif = dev->ifindex;
-			fl4.flowi4_tos = RT_TOS(ip_hdr(skb)->tos);
-			fl4.daddr = ip_hdr(skb)->daddr;
-			fl4.saddr = ip_hdr(skb)->saddr;
-
-			rt = ip_route_output_key(dev_net(dev), &fl4);
-			if (!IS_ERR(rt)) {
-				skb_dst_set(skb, &rt->dst);
-				icmp_send(skb, ICMP_DEST_UNREACH,
-					  ICMP_FRAG_NEEDED,
-					  htonl(localmtu));
-			}
-		}
+		if (skb->protocol == htons(ETH_P_IP))
+			icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+				      htonl(localmtu));
 #if IS_ENABLED(CONFIG_IPV6)
 		else if (skb->protocol == htons(ETH_P_IPV6))
-			icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, localmtu);
+			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, localmtu);
 #endif
 		goto out_dropped;
 	}
author maintainer
#268 lore raw

PATCH 242/247 xfrm: interface: use icmp_ndo_send helper

In reply to Greg Kroah-Hartman

From: Jason A. Donenfeld <[email protected]>

commit 45942ba890e6f35232727a5fa33d732681f4eb9f upstream.

Because xfrmi is calling icmp from network device context, it should use the ndo helper so that the rate limiting applies correctly.

---
 net/xfrm/xfrm_interface.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_interface.c +3 -3
@@ -300,10 +300,10 @@ xfrmi_xmit2(struct sk_buff *skb, struct
 			if (mtu < IPV6_MIN_MTU)
 				mtu = IPV6_MIN_MTU;
 
-			icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
 		} else {
-			icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
-				  htonl(mtu));
+			icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
+				      htonl(mtu));
 		}
 
 		dst_release(dst);
author maintainer
#269 lore raw

PATCH 243/247 ipv6: icmp6: avoid indirect call for icmpv6_send()

In reply to Greg Kroah-Hartman

From: Eric Dumazet <[email protected]>

commit cc7a21b6fbd945f8d8f61422ccd27203c1fafeb7 upstream.

If IPv6 is builtin, we do not need an expensive indirect call to reach icmp6_send().

v2: put inline keyword before the type to avoid sparse warnings.

---
 include/linux/icmpv6.h |   22 +++++++++++++++++++++-
 net/ipv6/icmp.c        |    5 +++--
 net/ipv6/ip6_icmp.c    |   10 +++++-----
 3 files changed, 29 insertions(+), 8 deletions(-)
include/linux/icmpv6.h +21 -1
@@ -13,12 +13,32 @@ static inline struct icmp6hdr *icmp6_hdr
 #include <linux/netdevice.h>
 
 #if IS_ENABLED(CONFIG_IPV6)
-extern void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info);
 
 typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 			     const struct in6_addr *force_saddr);
+#if IS_BUILTIN(CONFIG_IPV6)
+void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
+		const struct in6_addr *force_saddr);
+static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
+{
+	icmp6_send(skb, type, code, info, NULL);
+}
+static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
+{
+	BUILD_BUG_ON(fn != icmp6_send);
+	return 0;
+}
+static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn)
+{
+	BUILD_BUG_ON(fn != icmp6_send);
+	return 0;
+}
+#else
+extern void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info);
 extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
 extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
+#endif
+
 int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
 			       unsigned int data_len);
 
net/ipv6/icmp.c +3 -2
@@ -418,8 +418,8 @@ static int icmp6_iif(const struct sk_buf
 /*
  *	Send an ICMP message in response to a packet in error
  */
-static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
-		       const struct in6_addr *force_saddr)
+void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
+		const struct in6_addr *force_saddr)
 {
 	struct inet6_dev *idev = NULL;
 	struct ipv6hdr *hdr = ipv6_hdr(skb);
@@ -592,6 +592,7 @@ out:
 out_bh_enable:
 	local_bh_enable();
 }
+EXPORT_SYMBOL(icmp6_send);
 
 /* Slightly more convenient version of icmp6_send.
  */
net/ipv6/ip6_icmp.c +5 -5
@@ -9,6 +9,8 @@
 
 #if IS_ENABLED(CONFIG_IPV6)
 
+#if !IS_BUILTIN(CONFIG_IPV6)
+
 static ip6_icmp_send_t __rcu *ip6_icmp_send;
 
 int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
@@ -37,14 +39,12 @@ void icmpv6_send(struct sk_buff *skb, u8
 
 	rcu_read_lock();
 	send = rcu_dereference(ip6_icmp_send);
-
-	if (!send)
-		goto out;
-	send(skb, type, code, info, NULL);
-out:
+	if (send)
+		send(skb, type, code, info, NULL);
 	rcu_read_unlock();
 }
 EXPORT_SYMBOL(icmpv6_send);
+#endif
 
 #if IS_ENABLED(CONFIG_NF_NAT)
 #include <net/netfilter/nf_conntrack.h>
author maintainer
#270 lore raw

PATCH 244/247 ipv6: silence compilation warning for non-IPV6 builds

In reply to Greg Kroah-Hartman

From: Leon Romanovsky <[email protected]>

commit 1faba27f11c8da244e793546a1b35a9b1da8208e upstream.

The W=1 compilation of allmodconfig generates the following warning:

net/ipv6/icmp.c:448:6: warning: no previous prototype for 'icmp6_send' [-Wmissing-prototypes]
448 | void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,

      |      ^~~~~~~~~~

Fix it by providing function declaration for builds with ipv6 as a module.

---
 include/linux/icmpv6.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/icmpv6.h +1 -1
@@ -16,9 +16,9 @@ static inline struct icmp6hdr *icmp6_hdr
 
 typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 			     const struct in6_addr *force_saddr);
-#if IS_BUILTIN(CONFIG_IPV6)
 void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 		const struct in6_addr *force_saddr);
+#if IS_BUILTIN(CONFIG_IPV6)
 static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
 {
 	icmp6_send(skb, type, code, info, NULL);
author maintainer
#271 lore raw

PATCH 245/247 net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending

In reply to Greg Kroah-Hartman

From: Jason A. Donenfeld <[email protected]>

commit ee576c47db60432c37e54b1e2b43a8ca6d3a8dca upstream.

The icmp{,v6}_send functions make all sorts of use of skb->cb, casting it with IPCB or IP6CB, assuming the skb to have come directly from the inet layer. But when the packet comes from the ndo layer, especially when forwarded, there's no telling what might be in skb->cb at that point. As a result, the icmp sending code risks reading bogus memory contents, which can result in nasty stack overflows such as this one reported by a user:

    panic+0x108/0x2ea
    __stack_chk_fail+0x14/0x20
    __icmp_send+0x5bd/0x5c0
    icmp_ndo_send+0x148/0x160

In icmp_send, skb->cb is cast with IPCB and an ip_options struct is read from it. The optlen parameter there is of particular note, as it can induce writes beyond bounds. There are quite a few ways that can happen in __ip_options_echo. For example:

    // sptr/skb are attacker-controlled skb bytes
    sptr = skb_network_header(skb);
    // dptr/dopt points to stack memory allocated by __icmp_send
    dptr = dopt->__data;
    // sopt is the corrupt skb->cb in question
    if (sopt->rr) {
        optlen  = sptr[sopt->rr+1]; // corrupt skb->cb + skb->data
        soffset = sptr[sopt->rr+2]; // corrupt skb->cb + skb->data
	// this now writes potentially attacker-controlled data, over
	// flowing the stack:
        memcpy(dptr, sptr+sopt->rr, optlen);
    }

In the icmpv6_send case, the story is similar, but not as dire, as only IP6CB(skb)->iif and IP6CB(skb)->dsthao are used. The dsthao case is worse than the iif case, but it is passed to ipv6_find_tlv, which does a bit of bounds checking on the value.

This is easy to simulate by doing a memset(skb->cb, 0x41, sizeof(skb->cb)); before calling icmp{,v6}_ndo_send, and it's only by good fortune and the rarity of icmp sending from that context that we've avoided reports like this until now. For example, in KASAN:

    BUG: KASAN: stack-out-of-bounds in __ip_options_echo+0xa0e/0x12b0
    Write of size 38 at addr ffff888006f1f80e by task ping/89
    CPU: 2 PID: 89 Comm: ping Not tainted 5.10.0-rc7-debug+ #5
    Call Trace:
     dump_stack+0x9a/0xcc
     print_address_description.constprop.0+0x1a/0x160
     __kasan_report.cold+0x20/0x38
     kasan_report+0x32/0x40
     check_memory_region+0x145/0x1a0
     memcpy+0x39/0x60
     __ip_options_echo+0xa0e/0x12b0
     __icmp_send+0x744/0x1700

Actually, out of the 4 drivers that do this, only gtp zeroed the cb for the v4 case, while the rest did not. So this commit actually removes the gtp-specific zeroing, while putting the code where it belongs in the shared infrastructure of icmp{,v6}_ndo_send.

This commit fixes the issue by passing an empty IPCB or IP6CB along to the functions that actually do the work. For the icmp_send, this was already trivial, thanks to __icmp_send providing the plumbing function. For icmpv6_send, this required a tiny bit of refactoring to make it behave like the v4 case, after which it was straight forward.

---
 drivers/net/gtp.c      |    1 -
 include/linux/icmpv6.h |   26 ++++++++++++++++++++------
 include/linux/ipv6.h   |    2 +-
 include/net/icmp.h     |    6 +++++-
 net/ipv4/icmp.c        |    5 +++--
 net/ipv6/icmp.c        |   16 ++++++++--------
 net/ipv6/ip6_icmp.c    |   12 +++++++-----
 7 files changed, 44 insertions(+), 24 deletions(-)
drivers/net/gtp.c +0 -1
@@ -549,7 +549,6 @@ static int gtp_build_skb_ip4(struct sk_b
 	if (!skb_is_gso(skb) && (iph->frag_off & htons(IP_DF)) &&
 	    mtu < ntohs(iph->tot_len)) {
 		netdev_dbg(dev, "packet too big, fragmentation needed\n");
-		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
 		icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
 			      htonl(mtu));
 		goto err_rt;
include/linux/icmpv6.h +20 -6
@@ -3,6 +3,7 @@
 #define _LINUX_ICMPV6_H
 
 #include <linux/skbuff.h>
+#include <linux/ipv6.h>
 #include <uapi/linux/icmpv6.h>
 
 static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
@@ -15,13 +16,16 @@ static inline struct icmp6hdr *icmp6_hdr
 #if IS_ENABLED(CONFIG_IPV6)
 
 typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
-			     const struct in6_addr *force_saddr);
+			     const struct in6_addr *force_saddr,
+			     const struct inet6_skb_parm *parm);
 void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
-		const struct in6_addr *force_saddr);
+		const struct in6_addr *force_saddr,
+		const struct inet6_skb_parm *parm);
 #if IS_BUILTIN(CONFIG_IPV6)
-static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
+static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
+				 const struct inet6_skb_parm *parm)
 {
-	icmp6_send(skb, type, code, info, NULL);
+	icmp6_send(skb, type, code, info, NULL, parm);
 }
 static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
 {
@@ -34,11 +38,17 @@ static inline int inet6_unregister_icmp_
 	return 0;
 }
 #else
-extern void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info);
+extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
+			  const struct inet6_skb_parm *parm);
 extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
 extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
 #endif
 
+static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
+{
+	__icmpv6_send(skb, type, code, info, IP6CB(skb));
+}
+
 int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
 			       unsigned int data_len);
 
@@ -54,7 +64,11 @@ static inline void icmpv6_send(struct sk
 #if IS_ENABLED(CONFIG_NF_NAT)
 void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
 #else
-#define icmpv6_ndo_send icmpv6_send
+static inline void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
+{
+	struct inet6_skb_parm parm = { 0 };
+	__icmpv6_send(skb_in, type, code, info, &parm);
+}
 #endif
 
 extern int				icmpv6_init(void);
include/linux/ipv6.h +1 -1
@@ -3,6 +3,7 @@
 #define _IPV6_H
 
 #include <uapi/linux/ipv6.h>
+#include <uapi/linux/icmpv6.h>
 
 #define ipv6_optlen(p)  (((p)->hdrlen+1) << 3)
 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
@@ -83,7 +84,6 @@ struct ipv6_params {
 	__s32 autoconf;
 };
 extern struct ipv6_params ipv6_defaults;
-#include <linux/icmpv6.h>
 #include <linux/tcp.h>
 #include <linux/udp.h>
 
include/net/icmp.h +5 -1
@@ -50,7 +50,11 @@ static inline void icmp_send(struct sk_b
 #if IS_ENABLED(CONFIG_NF_NAT)
 void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info);
 #else
-#define icmp_ndo_send icmp_send
+static inline void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info)
+{
+	struct ip_options opts = { 0 };
+	__icmp_send(skb_in, type, code, info, &opts);
+}
 #endif
 
 int icmp_rcv(struct sk_buff *skb);
net/ipv4/icmp.c +3 -2
@@ -760,13 +760,14 @@ EXPORT_SYMBOL(__icmp_send);
 void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __be32 info)
 {
 	struct sk_buff *cloned_skb = NULL;
+	struct ip_options opts = { 0 };
 	enum ip_conntrack_info ctinfo;
 	struct nf_conn *ct;
 	__be32 orig_ip;
 
 	ct = nf_ct_get(skb_in, &ctinfo);
 	if (!ct || !(ct->status & IPS_SRC_NAT)) {
-		icmp_send(skb_in, type, code, info);
+		__icmp_send(skb_in, type, code, info, &opts);
 		return;
 	}
 
@@ -781,7 +782,7 @@ void icmp_ndo_send(struct sk_buff *skb_i
 
 	orig_ip = ip_hdr(skb_in)->saddr;
 	ip_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.ip;
-	icmp_send(skb_in, type, code, info);
+	__icmp_send(skb_in, type, code, info, &opts);
 	ip_hdr(skb_in)->saddr = orig_ip;
 out:
 	consume_skb(cloned_skb);
net/ipv6/icmp.c +8 -8
@@ -309,10 +309,9 @@ static int icmpv6_getfrag(void *from, ch
 }
 
 #if IS_ENABLED(CONFIG_IPV6_MIP6)
-static void mip6_addr_swap(struct sk_buff *skb)
+static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt)
 {
 	struct ipv6hdr *iph = ipv6_hdr(skb);
-	struct inet6_skb_parm *opt = IP6CB(skb);
 	struct ipv6_destopt_hao *hao;
 	struct in6_addr tmp;
 	int off;
@@ -329,7 +328,7 @@ static void mip6_addr_swap(struct sk_buf
 	}
 }
 #else
-static inline void mip6_addr_swap(struct sk_buff *skb) {}
+static inline void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt) {}
 #endif
 
 static struct dst_entry *icmpv6_route_lookup(struct net *net,
@@ -419,7 +418,8 @@ static int icmp6_iif(const struct sk_buf
  *	Send an ICMP message in response to a packet in error
  */
 void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
-		const struct in6_addr *force_saddr)
+		const struct in6_addr *force_saddr,
+		const struct inet6_skb_parm *parm)
 {
 	struct inet6_dev *idev = NULL;
 	struct ipv6hdr *hdr = ipv6_hdr(skb);
@@ -512,7 +512,7 @@ void icmp6_send(struct sk_buff *skb, u8
 	if (!(skb->dev->flags&IFF_LOOPBACK) && !icmpv6_global_allow(type))
 		goto out_bh_enable;
 
-	mip6_addr_swap(skb);
+	mip6_addr_swap(skb, parm);
 
 	memset(&fl6, 0, sizeof(fl6));
 	fl6.flowi6_proto = IPPROTO_ICMPV6;
@@ -598,7 +598,7 @@ EXPORT_SYMBOL(icmp6_send);
  */
 void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos)
 {
-	icmp6_send(skb, ICMPV6_PARAMPROB, code, pos, NULL);
+	icmp6_send(skb, ICMPV6_PARAMPROB, code, pos, NULL, IP6CB(skb));
 	kfree_skb(skb);
 }
 
@@ -655,10 +655,10 @@ int ip6_err_gen_icmpv6_unreach(struct sk
 	}
 	if (type == ICMP_TIME_EXCEEDED)
 		icmp6_send(skb2, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
-			   info, &temp_saddr);
+			   info, &temp_saddr, IP6CB(skb2));
 	else
 		icmp6_send(skb2, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH,
-			   info, &temp_saddr);
+			   info, &temp_saddr, IP6CB(skb2));
 	if (rt)
 		ip6_rt_put(rt);
 
net/ipv6/ip6_icmp.c +7 -5
@@ -33,23 +33,25 @@ int inet6_unregister_icmp_sender(ip6_icm
 }
 EXPORT_SYMBOL(inet6_unregister_icmp_sender);
 
-void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
+void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
+		   const struct inet6_skb_parm *parm)
 {
 	ip6_icmp_send_t *send;
 
 	rcu_read_lock();
 	send = rcu_dereference(ip6_icmp_send);
 	if (send)
-		send(skb, type, code, info, NULL);
+		send(skb, type, code, info, NULL, parm);
 	rcu_read_unlock();
 }
-EXPORT_SYMBOL(icmpv6_send);
+EXPORT_SYMBOL(__icmpv6_send);
 #endif
 
 #if IS_ENABLED(CONFIG_NF_NAT)
 #include <net/netfilter/nf_conntrack.h>
 void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
 {
+	struct inet6_skb_parm parm = { 0 };
 	struct sk_buff *cloned_skb = NULL;
 	enum ip_conntrack_info ctinfo;
 	struct in6_addr orig_ip;
@@ -57,7 +59,7 @@ void icmpv6_ndo_send(struct sk_buff *skb
 
 	ct = nf_ct_get(skb_in, &ctinfo);
 	if (!ct || !(ct->status & IPS_SRC_NAT)) {
-		icmpv6_send(skb_in, type, code, info);
+		__icmpv6_send(skb_in, type, code, info, &parm);
 		return;
 	}
 
@@ -72,7 +74,7 @@ void icmpv6_ndo_send(struct sk_buff *skb
 
 	orig_ip = ipv6_hdr(skb_in)->saddr;
 	ipv6_hdr(skb_in)->saddr = ct->tuplehash[0].tuple.src.u3.in6;
-	icmpv6_send(skb_in, type, code, info);
+	__icmpv6_send(skb_in, type, code, info, &parm);
 	ipv6_hdr(skb_in)->saddr = orig_ip;
 out:
 	consume_skb(cloned_skb);
author maintainer
#272 lore raw

PATCH 246/247 dm era: Update in-core bitset after committing the metadata

In reply to Greg Kroah-Hartman

From: Nikos Tsironis <[email protected]>

commit 2099b145d77c1d53f5711f029c37cc537897cee6 upstream.

In case of a system crash, dm-era might fail to mark blocks as written in its metadata, although the corresponding writes to these blocks were passed down to the origin device and completed successfully.

Consider the following sequence of events:

1. We write to a block that has not been yet written in the current era
2. era_map() checks the in-core bitmap for the current era and sees that the block is not marked as written.
3. The write is deferred for submission after the metadata have been updated and committed.
4. The worker thread processes the deferred write (process_deferred_bios()) and marks the block as written in the in-core bitmap, **before** committing the metadata.
5. The worker thread starts committing the metadata.
6. We do more writes that map to the same block as the write of step (1)
7. era_map() checks the in-core bitmap and sees that the block is marked as written, **although the metadata have not been committed yet**.
8. These writes are passed down to the origin device immediately and the device reports them as completed.
9. The system crashes, e.g., power failure, before the commit from step
(5) finishes.

When the system recovers and we query the dm-era target for the list of written blocks it doesn't report the aforementioned block as written, although the writes of step (6) completed successfully.

The issue is that era_map() decides whether to defer or not a write based on non committed information. The root cause of the bug is that we update the in-core bitmap, **before** committing the metadata.

Fix this by updating the in-core bitmap **after** successfully committing the metadata.

Fixes eec40579d84873 ("dm: add era target")
Cc [email protected] # v3.15+
---
 drivers/md/dm-era-target.c |   25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/md/dm-era-target.c +19 -6
@@ -134,7 +134,7 @@ static int writeset_test_and_set(struct
 {
 	int r;
 
-	if (!test_and_set_bit(block, ws->bits)) {
+	if (!test_bit(block, ws->bits)) {
 		r = dm_bitset_set_bit(info, ws->md.root, block, &ws->md.root);
 		if (r) {
 			/* FIXME: fail mode */
@@ -1240,8 +1240,10 @@ static void process_deferred_bios(struct
 	int r;
 	struct bio_list deferred_bios, marked_bios;
 	struct bio *bio;
+	struct blk_plug plug;
 	bool commit_needed = false;
 	bool failed = false;
+	struct writeset *ws = era->md->current_writeset;
 
 	bio_list_init(&deferred_bios);
 	bio_list_init(&marked_bios);
@@ -1251,9 +1253,11 @@ static void process_deferred_bios(struct
 	bio_list_init(&era->deferred_bios);
 	spin_unlock(&era->deferred_lock);
 
+	if (bio_list_empty(&deferred_bios))
+		return;
+
 	while ((bio = bio_list_pop(&deferred_bios))) {
-		r = writeset_test_and_set(&era->md->bitset_info,
-					  era->md->current_writeset,
+		r = writeset_test_and_set(&era->md->bitset_info, ws,
 					  get_block(era, bio));
 		if (r < 0) {
 			/*
@@ -1261,7 +1265,6 @@ static void process_deferred_bios(struct
 			 * FIXME: finish.
 			 */
 			failed = true;
-
 		} else if (r == 0)
 			commit_needed = true;
 
@@ -1277,9 +1280,19 @@ static void process_deferred_bios(struct
 	if (failed)
 		while ((bio = bio_list_pop(&marked_bios)))
 			bio_io_error(bio);
-	else
-		while ((bio = bio_list_pop(&marked_bios)))
+	else {
+		blk_start_plug(&plug);
+		while ((bio = bio_list_pop(&marked_bios))) {
+			/*
+			 * Only update the in-core writeset if the on-disk one
+			 * was updated too.
+			 */
+			if (commit_needed)
+				set_bit(get_block(era, bio), ws->bits);
 			generic_make_request(bio);
+		}
+		blk_finish_plug(&plug);
+	}
 }
 
 static void process_rpc_calls(struct era *era)
author maintainer
#273 lore raw

PATCH 247/247 net: qrtr: Fix memory leak in qrtr_tun_open

In reply to Greg Kroah-Hartman

From: Takeshi Misawa <[email protected]>

commit fc0494ead6398609c49afa37bc949b61c5c16b91 upstream.

If qrtr_endpoint_register() failed, tun is leaked. Fix this, by freeing tun in error path.

syzbot report:

BUG: memory leak
unreferenced object 0xffff88811848d680 (size 64):
  comm "syz-executor684", pid 10171, jiffies 4294951561 (age 26.070s)
  hex dump (first 32 bytes):
    80 dd 0a 84 ff ff ff ff 00 00 00 00 00 00 00 00  ................
    90 d6 48 18 81 88 ff ff 90 d6 48 18 81 88 ff ff  ..H.......H.....
  backtrace:
    [<0000000018992a50>] kmalloc include/linux/slab.h:552 [inline]
    [<0000000018992a50>] kzalloc include/linux/slab.h:682 [inline]
    [<0000000018992a50>] qrtr_tun_open+0x22/0x90 net/qrtr/tun.c:35
    [<0000000003a453ef>] misc_open+0x19c/0x1e0 drivers/char/misc.c:141
    [<00000000dec38ac8>] chrdev_open+0x10d/0x340 fs/char_dev.c:414
    [<0000000079094996>] do_dentry_open+0x1e6/0x620 fs/open.c:817
    [<000000004096d290>] do_open fs/namei.c:3252 [inline]
    [<000000004096d290>] path_openat+0x74a/0x1b00 fs/namei.c:3369
    [<00000000b8e64241>] do_filp_open+0xa0/0x190 fs/namei.c:3396
    [<00000000a3299422>] do_sys_openat2+0xed/0x230 fs/open.c:1172
    [<000000002c1bdcef>] do_sys_open fs/open.c:1188 [inline]
    [<000000002c1bdcef>] __do_sys_openat fs/open.c:1204 [inline]
    [<000000002c1bdcef>] __se_sys_openat fs/open.c:1199 [inline]
    [<000000002c1bdcef>] __x64_sys_openat+0x7f/0xe0 fs/open.c:1199
    [<00000000f3a5728f>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
    [<000000004b38b7ec>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
Fixes 28fb4e59a47d ("net: qrtr: Expose tunneling endpoint to user space")
Reported-by [email protected]
---
 net/qrtr/tun.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
net/qrtr/tun.c +11 -1
@@ -31,6 +31,7 @@ static int qrtr_tun_send(struct qrtr_end
 static int qrtr_tun_open(struct inode *inode, struct file *filp)
 {
 	struct qrtr_tun *tun;
+	int ret;
 
 	tun = kzalloc(sizeof(*tun), GFP_KERNEL);
 	if (!tun)
@@ -43,7 +44,16 @@ static int qrtr_tun_open(struct inode *i
 
 	filp->private_data = tun;
 
-	return qrtr_endpoint_register(&tun->ep, QRTR_EP_NID_AUTO);
+	ret = qrtr_endpoint_register(&tun->ep, QRTR_EP_NID_AUTO);
+	if (ret)
+		goto out;
+
+	return 0;
+
+out:
+	filp->private_data = NULL;
+	kfree(tun);
+	return ret;
 }
 
 static ssize_t qrtr_tun_read_iter(struct kiocb *iocb, struct iov_iter *to)
Tested-by on the v1 series
#274 lore raw
In reply to Greg Kroah-Hartman
Quoted 9 lines · Greg Kroah-Hartman

This is the start of the stable review cycle for the 4.19.178 release. There are 247 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.

Responses should be made by Wed, 03 Mar 2021 16:09:49 +0000. Anything received after that time might be too late.

The whole patch series can be found in one patch at:

Quoted 9 lines
	https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.178-rc1.gz

or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-4.19.y
and the diffstat can be found below.

thanks,

greg k-h

Compiled and booted on my test system. No dmesg regressions.

thanks,
-- Shuah

Tested-by Hulk Robot on the v1 series
#275 lore raw
In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

This is the start of the stable review cycle for the 4.19.178 release. There are 247 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.

Responses should be made by Wed, 03 Mar 2021 16:09:49 +0000. Anything received after that time might be too late.

Tested both on x86 [1] and ARM64 [2] server,

Thanks
Hanjun

[1]:
Arch: x86 (confirmed that no kernel failures)
--------------------------------------------------------------------
Testcase Result Summary:
total_num: 4681
succeed_num: 4677
failed_num: 4
timeout_num: 1

[2]:
Arch: arm64
--------------------------------------------------------------------
Testcase Result Summary:
total_num: 4675
succeed_num: 4675
failed_num: 0
timeout_num: 0

Tested-by Hulk Robot on the v1 series
#276 lore raw
In reply to Greg Kroah-Hartman
Quoted 7 lines · Greg Kroah-Hartman

This is the start of the stable review cycle for the 4.19.178 release. There are 247 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.

Responses should be made by Wed, 03 Mar 2021 16:09:49 +0000. Anything received after that time might be too late.

Tested on arm64 and x86 for 4.19.178-rc3+,

arm64:
--------------------------------------------------------------------
Testcase Result Summary:
total_num: 4674
succeed_num: 4674
failed_num: 0
timeout_num: 0

x86 (No kernel failures)
--------------------------------------------------------------------
Testcase Result Summary:
total_num: 4674
succeed_num: 4673
failed_num: 1
timeout_num: 0