From nobody Mon Jun 8 09:49:33 2026 Received: from outbound.baidu.com (mx20.baidu.com [111.202.115.85]) by smtp.subspace.kernel.org (Postfix) with SMTP id 149AC3A963C for ; Sat, 30 May 2026 11:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.115.85 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780140557; cv=none; b=VjxZAVlHc64OBgGSYYPcCDIQZiDv0zcpmj4qYzehfhm9v3MPYtCmAOduq//tRzCV/BFBtiRT/DlPG3zNF0G9O2w/9ef84JfC+nqkpK2JLBLoypgzgpV9CvdOMy0sloGM8p5D3Lrt6v71sj6/EBTztsTMGQ11WtCHvlS/UEe/lTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780140557; c=relaxed/simple; bh=q9Nqs7Vct+E3lnckbJsRpt7hDsrB9skpywJyUx1PshM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ECU0XWGYR4eZp1vfj7hdgNio4ddlmDITRLJ48vdswwmOZReAygMVcT5FGH86c1RSCKdoASiOMKi4rk6m5ltxDwCbIWpj6RWPSwmgrLBtsnB4g9E6GwMCmoIzmnY9V5D36OsD94hW7UtEXAF0rBRWWa4wmpVs446V+qLFHN1LYfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b=XDqZrZJY; arc=none smtp.client-ip=111.202.115.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baidu.com header.i=@baidu.com header.b="XDqZrZJY" X-MD-Sfrom: lirongqing@baidu.com X-MD-SrcIP: 172.31.50.47 From: lirongqing To: Robin Murphy , Joerg Roedel , Will Deacon , Lu Baolu , Luis Chamberlain , Leon Romanovsky , Logan Gunthorpe , Bjorn Helgaas , , CC: Li RongQing Subject: [PATCH] iommu/dma-iommu: Fix wrong scatterlist length assignment in P2PDMA path Date: Sat, 30 May 2026 07:28:52 -0400 Message-ID: <20260530112852.2321-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: bjhj-exc4.internal.baidu.com (172.31.3.14) To bjkjy-exc3.internal.baidu.com (172.31.50.47) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baidu.com; s=selector1; t=1780140545; bh=fXK3xxBmCA0vj7UeNs7YwJFbu2LW0hQ+Blen52r1tBk=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=XDqZrZJYOGUrE3S0U1fujsq7GTHo/gjaxh9+4t46j6nOVL/YgQKtONCqdF58uFC9E wpnFyHDMCwmaoLY7iEKSrnCHnxx94noYE5n/dwnTPdjlqfDgM3YfO/u11yugQKZs7M QU9N0mzQj07OBkvPx+uhXzY7UNR+5/DffUp65BvqJoRUKi6N058rRydkQuCmAt4Tke 3nWCFhmx0ak/EzWtpF7IMS2RXldfgPwlBzqArIEk+OME0IygVARZGBoziasuCh3S3z eQANuJwICp+ncaPWVysULlwB39onNR65cy76X1HfzyCTG/zmQCJaQqIduTqi5giiAD xqL2hEAAcx/vQ== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Li RongQing In iommu_dma_map_sg(), when handling PCI P2PDMA cases, the DMA length of the current scatterlist segment `s` is incorrectly assigned from the head entry `sg->length` instead of the current entry `s->length`. This typo causes all P2PDMA segments in the scatterlist to inherit the length of the first segment, leading to corrupted DMA lengths for multi- segment scatterlists. Fix this by using `s->length` instead of `sg->length`. Fixes: a25e7962db ("PCI/P2PDMA: Refactor the p2pdma mapping helpers") Signed-off-by: Li RongQing Reviewed-by: Logan Gunthorpe --- drivers/iommu/dma-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 54d96e8..e8d4c2d 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1465,7 +1465,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatt= erlist *sg, int nents, */ s->dma_address =3D pci_p2pdma_bus_addr_map( p2pdma_state.mem, sg_phys(s)); - sg_dma_len(s) =3D sg->length; + sg_dma_len(s) =3D s->length; sg_dma_mark_bus_address(s); continue; default: --=20 2.9.4