From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Peng Hongchi <hongchi.peng@siengine.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
hminas@synopsys.com, linux-usb@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 04/15] usb: dwc2: gadget: Don't write invalid mapped sg entries into dma_desc with iommu enabled
Date: Sun, 28 Jul 2024 12:07:48 -0400 [thread overview]
Message-ID: <20240728160813.2053107-4-sashal@kernel.org> (raw)
In-Reply-To: <20240728160813.2053107-1-sashal@kernel.org>
From: Peng Hongchi <hongchi.peng@siengine.com>
[ Upstream commit 1134289b6b93d73721340b66c310fd985385e8fa ]
When using dma_map_sg() to map the scatterlist with iommu enabled,
the entries in the scatterlist can be mergerd into less but longer
entries in the function __finalise_sg(). So that the number of
valid mapped entries is actually smaller than ureq->num_reqs,and
there are still some invalid entries in the scatterlist with
dma_addr=0xffffffff and len=0. Writing these invalid sg entries
into the dma_desc can cause a data transmission error.
The function dma_map_sg() returns the number of valid map entries
and the return value is assigned to usb_request::num_mapped_sgs in
function usb_gadget_map_request_by_dev(). So that just write valid
mapped entries into dma_desc according to the usb_request::num_mapped_sgs,
and set the IOC bit if it's the last valid mapped entry.
This patch poses no risk to no-iommu situation, cause
ureq->num_mapped_sgs equals ureq->num_sgs while using dma_direct_map_sg()
to map the scatterlist whith iommu disabled.
Signed-off-by: Peng Hongchi <hongchi.peng@siengine.com>
Link: https://lore.kernel.org/r/20240523100315.7226-1-hongchi.peng@siengine.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/usb/dwc2/gadget.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index cb29f9fae2f23..1c8141d80e25d 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -886,10 +886,10 @@ static void dwc2_gadget_config_nonisoc_xfer_ddma(struct dwc2_hsotg_ep *hs_ep,
}
/* DMA sg buffer */
- for_each_sg(ureq->sg, sg, ureq->num_sgs, i) {
+ for_each_sg(ureq->sg, sg, ureq->num_mapped_sgs, i) {
dwc2_gadget_fill_nonisoc_xfer_ddma_one(hs_ep, &desc,
sg_dma_address(sg) + sg->offset, sg_dma_len(sg),
- sg_is_last(sg));
+ (i == (ureq->num_mapped_sgs - 1)));
desc_count += hs_ep->desc_count;
}
--
2.43.0
next prev parent reply other threads:[~2024-07-28 16:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-28 16:07 [PATCH AUTOSEL 6.1 01/15] PCI: Add ACS quirk for Broadcom BCM5760X NIC Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 02/15] PCI: Use preserve_config in place of pci_flags Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 03/15] usb: cdns3: Add quirk flag to enable suspend residency Sasha Levin
2024-07-28 16:07 ` Sasha Levin [this message]
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 05/15] usb: typec: ucsi: Fix null pointer dereference in trace Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 06/15] MIPS: Loongson64: DTS: Fix msi node for ls7a Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 07/15] MIPS: Loongson64: DTS: Fix PCIe port nodes " Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 08/15] PCI/AER: Disable AER service on suspend Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 09/15] ASoC: Intel: sof_sdw: fix jack detection on ADL-N variant RVP Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 10/15] ASoC: Intel: sof_sdw: add quirk for Dell SKU 0B8C Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 11/15] usb: gadget: aspeed_udc: validate endpoint index for ast udc Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 12/15] PCI: keystone: Add workaround for Errata #i2037 (AM65x SR 1.0) Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 13/15] PCI: vmd: Create domain symlink before pci_bus_add_devices() Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 14/15] PCI: Add missing bridge lock to pci_bus_lock() Sasha Levin
2024-07-28 16:07 ` [PATCH AUTOSEL 6.1 15/15] ALSA: usb: Fix UBSAN warning in parse_audio_unit() Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240728160813.2053107-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hminas@synopsys.com \
--cc=hongchi.peng@siengine.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox