From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF8AB3ED5AE for ; Thu, 11 Jun 2026 11:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781179182; cv=none; b=Q/VKJW3XDWURNgJBL/IiUr1ob1sflPcjl0jjRs9lbSILGJUiVq+HRmN6jltgqUXgIEH0dLGMEfqBWB/24rSMa66XRU30QIUm24I/vHTRoWOLiGf+9pRXe4Zl+xGi9dSvkTH/nBsV27JBoN0TVBD0Nz6ZF+90QKgaNLQbYy/yj6o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781179182; c=relaxed/simple; bh=HXI+6KUA5mCzTZAPeYkUL5Bgn+onXknGZaQEl5FIVI8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ouQ1uzEM2d7kK5OZSWdde1GvoeydiKoJY503iZf6C7ec3k7FzvVuPkMJTcXAXvEpsNOELu8CZVDj/oWR9BN3IEYg/mBeJljrTQdDJezPeJxc7HnXDzFFvx6hbJYujcNgGrCM+KH0LHLNPDIMm8kark0PowwS1Mn3hpOaf/TNQv4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=iRJUZgRp; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="iRJUZgRp" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-9158643e538so701957985a.1 for ; Thu, 11 Jun 2026 04:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1781179180; x=1781783980; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tvizeKh300V4RgKQE8JEUwSI0zRPQK5L8Dj7T0K8bjs=; b=iRJUZgRpyBew8pSeMUHkVO/n8N5I4vVQghrGWIeYO+68w7MHX4Af2sdOQS9MmET7ER O1uz+qA8gbsuR4OoRfdiCLAB6KuPxuoqMxpx1dTdPbPG61AxZe3TQXEJOxTf9Q8FdyuI /fXO3APiKdpJkABHLuvcFNVmiupz8U3etIO8V5gtK4WrO/h0F4U+gMffc0HLTjlWg07d SKjqBX65h50YWMEjetPRdB3Ud8yhaJEgcv0AULjNBeLv+BcyeaHyGo3FVWSkjd0qlW12 +6AwH7MOiuEPBuPFBJIe1VijlK5nLIxpX/iLrKK7yaPj+omM0Skk7s/bj5+eaYpNykYA Kq1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781179180; x=1781783980; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tvizeKh300V4RgKQE8JEUwSI0zRPQK5L8Dj7T0K8bjs=; b=srMk8bxbWdLvSFQyVPyatiQfOCA1gFGgGlUJAz+oNeiS/1jFTtQI8XE+q8ZgrrwGar p0ClWQGE2wSfOGwveTQDTEzVEhWgIEG7zuAbciTPr1OFRDLZD4TYwgoadXY4SRmy8kXK 8nxiGjvAz+JrJtU7tr2CWqhSVUXpIK3lSMmIrDmmDO8GJcDQDv9OBLzHVv7kS9PPZu2t N37uqLKOu7e5DlVPMuoO8AFEa3tUJWb/3G5TnnCc8pItxREGsGlkSs3OOKcfn/iQwLLZ rmi8TnQCBb8gsjq3ZvKfJWbXZnaH9/m20QdAovu6FbdAsE+SyT9lJvS/X5I7MWM9CkY8 1Lhg== X-Forwarded-Encrypted: i=1; AFNElJ/Gz1YEvSExN3SgoQvuRte5g0BWtLRCXuKAf+3SurTRAzQltyaSAbvT+0LnbVh9earUOSpUNJxJuzTO6mg=@vger.kernel.org X-Gm-Message-State: AOJu0YxJrGH2t1cMjYkypfg9qdKW91WKNvaKEETUB/pdVigKMx+JFdAI KfqayfogOrfkLH5cnqlONK34YhVCT+o6USLf7a5YRe8QRCNU+aMn6C/VIA+Fj5t7+0Q= X-Gm-Gg: Acq92OEWDe3fl6vSHxgTUdmooIyH1Q6FXNzOOLbZ5TENPvxDibg0KTbJIdxFTICJvyg ffrdtyiUDdROfie3jhx3DTC8dmLZbt2qflFej3HsqA8X6A9dd0wy57LrAfelS1nbaZwFlQyT/Rf Es7r8i61ksEzA08adz41nh2OiwustVkbzlGgQ6+Wj9NvzhYAL6jOQiiPvwUMD0D2RbH1jPwyPP2 5GCZP3Wu9bnTUcmbvfTOVj3nd4sWC8ARBV1z6xAaOTc+5XZl4R+lGDVOOwE+9VjpsK8rosHVyVG Ggik8GgQ0ezh1OBA7U4eYcoKUahXH5sALHHIuPTiclQApaokASrc1FLcp02spYix6MFKLNVRnEz lMNjzlNiYjalY3GNPTHjoEOv4a69ysTqUvNpnQQvY4c5/NvU4aT2lZ+e+nIv9I10gi1TDTkQOf+ 0Xpm3DnKGXfkghjItJuVs/xptWfHYBuKUAuOZdWNqCXpmgM2zu1EvXr/BEIwX+qZETjvtI+09fD 3RjaXDoFSeIl+7fDSzg5QGkDWg= X-Received: by 2002:a05:620a:2681:b0:914:b65f:6abe with SMTP id af79cd13be357-9160ac976ffmr356715185a.5.1781179179928; Thu, 11 Jun 2026 04:59:39 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9160adf5832sm163280985a.31.2026.06.11.04.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 04:59:39 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wXe4Q-00000005hL0-1GzB; Thu, 11 Jun 2026 08:59:38 -0300 Date: Thu, 11 Jun 2026 08:59:38 -0300 From: Jason Gunthorpe To: Logan Gunthorpe Cc: "Li,Rongqing" , Robin Murphy , Joerg Roedel , Will Deacon , Lu Baolu , Luis Chamberlain , Leon Romanovsky , Bjorn Helgaas , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "hch@lst.de" Subject: Re: =?utf-8?B?562U5aSNOiBb5aSW6YOo6YKu5Lu2?= =?utf-8?Q?=5D_Re=3A_=5BPATCH=5D_iommu=2Fdma-iommu?= =?utf-8?Q?=3A?= Fix wrong scatterlist length assignment in P2PDMA path Message-ID: <20260611115938.GF1066031@ziepe.ca> References: <20260530112852.2321-1-lirongqing@baidu.com> <5e2f30a4121e4672ab309460630d011b@baidu.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jun 02, 2026 at 09:42:40AM -0600, Logan Gunthorpe wrote: > Hi Li, > > On 2026-06-02 00:12, Li,Rongqing wrote: > >>> Fixes: a25e7962db ("PCI/P2PDMA: Refactor the p2pdma mapping helpers") > >>> Signed-off-by: Li RongQing > >> > >> Hmm, I thought I had tested this stuff pretty thoroughly so I'm surprised I > >> missed that. But I guess seeing the users of these specifically don't allow > >> mixing with anonymous memory the vast majority of tests would only have > >> one segment. > >> > >> Can you confirm that you've reproduced and tested this and it actually fixes a > >> bug? Not just seeing something that looks strange. I have a vague feeling it > >> was intentional but looking at the code it looks wrong to me too. > >> > >> Thanks, > >> > > Cc: Christoph Hellwig > > > > Thanks for your feedback! > > > > This was found via code inspection. You are right that if nents == 1, or if nents > 1 but all segments happen to have the exact same length, this typo remains benign by pure coincidence. > > > > However, for a multi-segment scatterlist with varying lengths (e.g., a short 2KB head segment followed by standard 4KB segments), sg_dma_len(s) will mistakenly assign the 2KB head length to all subsequent 4KB segments. This will inevitably lead to silent data truncation or IOMMU page faults. > > > > Since sg_phys(s) correctly takes the current segment's address, sg_dma_len(s) should definitely use s->length to match it. > > > > I don't have a specific P2PDMA test rig to force multi-segment lists on hand right now, but the typo and its impact on varied segment lengths seem deterministic. > > Ok, yeah, I think you are correct. My tests that ran multiple segments > happened to all have the same length. But I don't have the hardware I > used at the moment so I can't test it either. > > Reviewed-by: Logan Gunthorpe Rongqing can you please send a proper series with both of these fixes without threading so Joerg can pick them up? Thanks, Jason