From nobody Fri Sep 25 11:05:07 2026 Received: from mx1.mail-out.lima-city.de (mx1.mail-out.lima-city.de [91.216.248.203]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C7A237DADD; Sun, 13 Sep 2026 21:08:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.216.248.203 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789333729; cv=none; b=oVC/wHAfqr7izmm2UyYi2YedyPrQB0Dl3Gf9a4JHWBowuVDYVU6dEIT1lB6qt+20QOf/DCgpXwRj39pNJqLk78Qx028+zEUCs3B0qTxsOlJ1Vf8nLlVEh3vmni7/iFKYCw57YU19/F5mKiNBJbwqgQES94NSt9z4ryWAWvsMuN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789333729; c=relaxed/simple; bh=YAfzGGez1KlfbwFRmw6Z8+ppdhSswn0ovC86+tjumRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EBFGtBwSDffKWvmoB2myZZnFbLaVAWNseMDYFH68MiwqH0XYQwUAfn9AyBrLRcPyCMPUBVuFlDQsHIR+3K9un30edpPI2zvCIEPQ3NpuFy7kgRPuOf9jnhAdQ5dnHLZUTHZ40KQAzKBvj8TWeiDWrjIs/EPXfu5GiA46v9fSMvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de; spf=pass smtp.mailfrom=matt3o12.de; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.b=iCUHrDVC; arc=none smtp.client-ip=91.216.248.203 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.b="iCUHrDVC" From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1789333726; bh=YAfzGGez1KlfbwFRmw6Z8+ppdhSswn0ovC86+tjumRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCUHrDVCx5pMJJkUSJ5nLeZX2odZx2TdJUQFVxerVFcRiOZ6Xwg+NfCy1znXa0/+z s5LKhhlOMfxWbViL4c3m84lkUKO5PCxnfkypVosDgMePDEW1SIevHQcgXi3fJKyeTG O+uUZF/OgXAV4ARKG9adA1PR6tBtvRzGWRTNl9+M5bzWFZ4v0LGRAQ6nDu5pVG9ePX Bgp0pGN4AiBXYHiL4aWLWAt53DgPOFd/g/ITYRtRj6jcXvqrYHZUs5xvUTPCX9Ysgg bUnEOlm+wIx5RUatkQoV7I4xCAc2l9G7pNK6pL1BMVz65HnYrwHzYrfOJ1qpfmdmrI 3DJbU/mczEwRA== To: dakr@kernel.org, acourbot@nvidia.com Cc: aliceryhl@google.com, ojeda@kernel.org, airlied@gmail.com, simona@ffwll.ch, abdiel.janulgue@gmail.com, daniel.almeida@collabora.com, robin.murphy@arm.com, a.hindborg@kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Matteo Kloiber Subject: [PATCH v2 1/2] gpu: nova-core: declare unlimited DMA max segment size Date: Sun, 13 Sep 2026 23:08:27 +0200 Message-ID: <20260913210828.125655-2-kernel@matt3o12.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260913210828.125655-1-kernel@matt3o12.de> References: <20260913210828.125655-1-kernel@matt3o12.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The PCI default max_seg_size is 64 KiB. nova-core never raises it, so mapping the GSP firmware image (~60 MiB) as a scatter-gather table triggers a DMA-API debug warning when contiguous pages coalesce into segments that exceed the default: DMA-API: nova-core 0000:00:03.0: mapping sg segment longer than device claims to support [len=3D62914560] [max=3D65536] CONFIG_DMA_API_DEBUG=3Dy is required to see this warning. Assisted-by: LLM Signed-off-by: Matteo Kloiber --- drivers/gpu/nova-core/gpu.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index fd1414004dd0..edc0207c01a0 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -343,6 +343,13 @@ pub(crate) fn new<'a>( // still constructing it, so no concurrent DMA allocations= can exist. unsafe { pdev.dma_set_mask_and_coherent(dma_mask)? }; =20 + // Nova walks SG segments to build page tables, so their l= ength is + // irrelevant to the device. + // + // SAFETY: `Gpu` owns all DMA allocations for this device,= and we are + // still constructing it, so no concurrent DMA allocations= can exist. + unsafe { pdev.dma_set_max_seg_size(u32::MAX) }; + hal.wait_gfw_boot_completion(bar) .inspect_err(|_| dev_err!(dev, "GFW boot did not compl= ete\n"))?; }, --=20 2.51.2 From nobody Fri Sep 25 11:05:07 2026 Received: from mx1.mail-out.lima-city.de (mx1.mail-out.lima-city.de [91.216.248.203]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A8737DAD5; Sun, 13 Sep 2026 21:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.216.248.203 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789333732; cv=none; b=aTeL1PTtlhv64ZYJbY4Y3Cy9xvXo3dLlFW66FosjW9DbG+Zf15ZWwD2b/oCDyV/Fmrsd2EzencwIhBqDoZlChUrzBJWbLjhUheMtT2OBZGg+rU6mGOZNpEVX2DbyWoWuf+IoDZWs0EAjA5wi9tdSdeYfKHC4nXNs4uD6GcpNTTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789333732; c=relaxed/simple; bh=3xNCv3SnT48TuYnliag8Bk7AVkdX7pKFEQAlaBFdBH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hoZwmtXOrlsoKj3XrrOOlnRmuy/ZZqB3rHDKKir7T8VUMlQv0V76QEZSGErL+Fz59kGYFpia4HBDBNexel9uIPuvsd/IIFgocry9AneBjcjvxHtHX6U4qnk1xjCTIUL2OWgq+80NjlecGgNp/s5P3fKCCRQPPctAlISoEN8Eq2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de; spf=pass smtp.mailfrom=matt3o12.de; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.b=gNeodVX7; arc=none smtp.client-ip=91.216.248.203 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=matt3o12.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=matt3o12.de header.i=@matt3o12.de header.b="gNeodVX7" From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1789333728; bh=3xNCv3SnT48TuYnliag8Bk7AVkdX7pKFEQAlaBFdBH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNeodVX7TzeceRRgx4Ydsps/z73ttUdXg47D3c1ub60rePywFnE4wltDIhQ7n7twN YCY1gO/6IH311sfLCUVs8NLMS1Ke9oLl9Lh26u1O1a6cxsFdZbZCCKBfN1ya9roA2I xznQ21T+6jZdN923TW4G/cBcFjV8jpi23TBOojOtnL4JSJOL1aB6JYIGs1Ca+t7Fny b2A38wGn7XTh8BrX61XUdqB2+YZIMiblxlwKSe0upuXny7F33PtIS1CxTz4hjdWdot +9ytZtlSvQ3Y/+YgldmzyU9CJiEMQrtDeZ737WRgMroS3jehElxpWlaDDpH011AjfG IDk/1c+WZGS0g== To: dakr@kernel.org, acourbot@nvidia.com Cc: aliceryhl@google.com, ojeda@kernel.org, airlied@gmail.com, simona@ffwll.ch, abdiel.janulgue@gmail.com, daniel.almeida@collabora.com, robin.murphy@arm.com, a.hindborg@kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Matteo Kloiber Subject: [PATCH v2 2/2] rust: scatterlist: honor the device's maximum segment size Date: Sun, 13 Sep 2026 23:08:28 +0200 Message-ID: <20260913210828.125655-3-kernel@matt3o12.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260913210828.125655-1-kernel@matt3o12.de> References: <20260913210828.125655-1-kernel@matt3o12.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SGTable::new() caps segment length at dma_max_mapping_size() only, which limits the DMA mapping path (e.g. swiotlb), not the device itself. The per-device limit from dma_set_max_seg_size() is ignored, so contiguous page segments can be longer than the declared max segment size, potentially causing problems for future drivers that use this abstraction. Fixes: 05aa6fb1c21d ("rust: scatterlist: Add abstraction for sg_table") Signed-off-by: Matteo Kloiber Reviewed-by: Alexandre Courbot --- rust/helpers/dma.c | 5 +++++ rust/kernel/scatterlist.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c index 9fbeb507b08c..ff8f24dae9df 100644 --- a/rust/helpers/dma.c +++ b/rust/helpers/dma.c @@ -49,3 +49,8 @@ __rust_helper void rust_helper_dma_set_max_seg_size(struc= t device *dev, { dma_set_max_seg_size(dev, size); } + +__rust_helper unsigned int rust_helper_dma_get_max_seg_size(struct device = *dev) +{ + return dma_get_max_seg_size(dev); +} diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs index b83c468b5c63..44eeafed05e3 100644 --- a/rust/kernel/scatterlist.rs +++ b/rust/kernel/scatterlist.rs @@ -350,15 +350,23 @@ fn new( page_vec.push(page.as_ptr(), flags)?; } =20 + // Cap segments at both the DMA mapping-path limit and the device'= s declared + // max segment size. + // // `dma_max_mapping_size` returns `size_t`, but `sg_alloc_table_fr= om_pages_segment()` takes // an `unsigned int`. // // SAFETY: `dev.as_raw()` is a valid pointer to a `struct device`. - let max_segment =3D match unsafe { bindings::dma_max_mapping_size(= dev.as_raw()) } { + let max_mapping_size =3D match unsafe { bindings::dma_max_mapping_= size(dev.as_raw()) } { 0 =3D> u32::MAX, - max_segment =3D> u32::try_from(max_segment).unwrap_or(u32::MAX= ), + max_mapping_size =3D> u32::try_from(max_mapping_size).unwrap_o= r(u32::MAX), }; =20 + // SAFETY: `dev.as_raw()` is a valid pointer to a `struct device`. + let max_seg_size =3D unsafe { bindings::dma_get_max_seg_size(dev.a= s_raw()) }; + + let max_segment =3D max_mapping_size.min(max_seg_size); + Ok(try_pin_init!(&this in Self { // SAFETY: // - `page_vec` is a `KVec` of valid `struct page *` obtained = from `pages`. --=20 2.51.2