From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.216.248.212 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795991111; b=ccKlulh0sHKWMPAsa5wCwUDlDCMZ7GvnxDgKAVNNGxPtEn6aEszq31c4NNPsNmbqLET5 neZ4k9v+5tNQFFNYf3GSaEEsnsPGAfHhid9fpvhO3W5YDjsFtl+40csV23O4QMkeJAI3M sEjZDBrZEm8nZz7z0ttZ1WxutRopTwRPXTvKnIhLDnk3x0yPeUoX7PPMroUHEmTTaRj6V 0mfrFn/f1DhF47uy4TBSHvk8oM4hfI0I52sYuH9cP8VE5/7azuvngbOpd9EsA2eSQ08+O YAeMWcqZaemFthIb/XCQOiQCUg9UBNq0iLdneEQNINf666nWRqycfkLN6dlL4qgVJNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795991111; h=DMARC-Filter:From:DKIM-Signature:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Q7ychZJ4y8+JzBajZa1a46Y9VWvJVU4nKv58AEj50M4=; b=HbjAkquP5Mkm/mHZnXnpAv9JWO/9SDTLdYJ6KoWK2eSkGJBI4rL92pFkVLFfarNpPVai KaqAmWhk1o8J6wpSAdhONGNM63XczRK48Ati0u1WLUGWalWB/z2psClEK6gYft9JPp414 RB0h1fcuy83sJEmBkvNkrXKMp2uH2aYRnoGdgQo4U7/CE6hGkC6D3WgTWULukoqJdKQCi 4cS611JvrrGldF8k333mwxsrwVhZQbyozCQYDytGiL8B5VLTZSSHKuSkCFbJq3yQL1xYi F6tXVQiagrhz4u2hAb/9/NpVEmk7F7RDjWibtl5lunLDcITVuokHuGmzoeIK3d+BaAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=matt3o12.de; spf=pass smtp.mailfrom=matt3o12.de; dkim=pass header.d=matt3o12.de header.i=@matt3o12.de header.a=rsa-sha256 header.s=securedbylima-20230709 header.b=M9ctF1Pz; arc=none smtp.remote-ip=91.216.248.212 Received: from bulk0.mail-out.lima-city.de (bulk0.mail-out.lima-city.de [91.216.248.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA7C606A6BA; Sun, 29 Nov 2026 22:25:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BA7C606A6BA 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.a=rsa-sha256 header.s=securedbylima-20230709 header.b=M9ctF1Pz From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991103; bh=gt+PLLpDWiFy/1+S4MNIBNuEIE/gZ0e7eQS2OWQR+/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M9ctF1PzIR4LgeAfbqsmwNKFz7tQLLgkmzu2LLjvUSYa80gJ0ym6rlkc2vbtcUM0w EwPBDOCjFGGab9Cdw32z05+PkFKW84ENDT99Tz+JkpO4ZW434UNaSw5JVDDK+b/3hF t3m67NTr6sLecKmFB+WhVwyC4XjwemFV6KL9RreZnK17KJFEE6yt2WH9+5DatcEC68 rabLUXB13yA2RDg3YalRYVkSZaENJVLErHCR1DcaSIgHzauiIhsxnTYyvDrsG32jwU DN5dTz5MiqNuAPjhv4NCZARixYKd5EjIv3u4aDdoOtb44qf0ktI55pmFOlWiGLxnSA 9131Ko+N8Tgfg== To: Danilo Krummrich , Alexandre Courbot , Alice Ryhl , Abdiel Janulgue , Robin Murphy , Andreas Hindborg , Gary Guo Cc: Daniel Almeida , Miguel Ojeda , David Airlie , Simona Vetter , Bjorn Helgaas , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kernel@vger.kernel.org, Matteo Kloiber Subject: [RFC PATCH v2 07/10] rust: scatterlist: require a dma::Handle for SGTable::new() Date: Sun, 29 Nov 2026 23:24:26 +0100 Message-ID: <20261129222429.2380652-8-kernel@matt3o12.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de> References: <20261129222429.2380652-1-kernel@matt3o12.de> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit SGTable::new() maps pages for a plain bound device. The mapping depends on the device's DMA mask and maximum segment size, so it must not be created before they are set. Take a dma::Handle instead of the device. Convert nova-core and the DMA sample, which already hold one. Signed-off-by: Matteo Kloiber --- drivers/gpu/nova-core/firmware/radix3.rs | 7 +++---- rust/kernel/scatterlist.rs | 22 +++++++++++----------- samples/rust/rust_dma.rs | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/nova-core/firmware/radix3.rs b/drivers/gpu/nova-core/firmware/radix3.rs index a00a583f7351..1dfe6b96ab45 100644 --- a/drivers/gpu/nova-core/firmware/radix3.rs +++ b/drivers/gpu/nova-core/firmware/radix3.rs @@ -52,19 +52,18 @@ pub(crate) struct Radix3<'a> { impl<'a> Radix3<'a> { /// Builds a radix3 page table over `data`, mapped for the device to read. May sleep. pub(crate) fn new(dma: dma::Handle<'a>, data: VVec) -> impl PinInit + 'a { - let dev = dma.device(); let size = data.len(); pin_init::pin_init_scope(move || { Ok(try_pin_init!(Self { - data <- SGTable::new(dev, data, DataDirection::ToDevice, GFP_KERNEL), + data <- SGTable::new(dma, data, DataDirection::ToDevice, GFP_KERNEL), level2 <- { build_lvl(&data) - .map(|l2| SGTable::new(dev, l2, DataDirection::ToDevice, GFP_KERNEL))? + .map(|l2| SGTable::new(dma, l2, DataDirection::ToDevice, GFP_KERNEL))? }, level1 <- { build_lvl(&level2) - .map(|l1| SGTable::new(dev, l1, DataDirection::ToDevice, GFP_KERNEL))? + .map(|l1| SGTable::new(dma, l1, DataDirection::ToDevice, GFP_KERNEL))? }, level0: { // Allocate the level 0 page table as a device-visible DMA object, and map the diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs index 3a5250f85000..9a9deb7ace2e 100644 --- a/rust/kernel/scatterlist.rs +++ b/rust/kernel/scatterlist.rs @@ -333,12 +333,13 @@ impl

Owned

where for<'a> P: page::AsPageIter = VmallocPageIter<'a>> + 'static, { - fn new( - dev: &Device, + fn new<'a>( + dma: dma::Handle<'a>, mut pages: P, dir: dma::DataDirection, flags: alloc::Flags, - ) -> Result + '_> { + ) -> Result + 'a> { + let dev = dma.device(); let page_iter = pages.page_iter(); let size = page_iter.size(); @@ -406,7 +407,7 @@ impl

SGTable> /// /// # Parameters /// - /// * `dev`: The [`Device`] that will be performing the DMA. + /// * `dma`: A handle for the device whose DMA parameters have been configured. /// * `pages`: The entity providing the backing pages. It must implement [`page::AsPageIter`]. /// The ownership of this entity is moved into the new [`SGTable`]. /// * `dir`: The [`dma::DataDirection`] of the DMA transfer. @@ -416,18 +417,17 @@ impl

SGTable> /// /// ``` /// use kernel::{ - /// device::{Bound, Device}, /// dma, page, /// prelude::*, /// scatterlist::{SGTable, Owned}, /// }; /// - /// fn test(dev: &Device) -> Result { + /// fn test(dma: dma::Handle<'_>) -> Result { /// let size = 4 * page::PAGE_SIZE; /// let pages = VVec::::with_capacity(size, GFP_KERNEL)?; /// /// let sgt = KBox::pin_init(SGTable::new( - /// dev, + /// dma, /// pages, /// dma::DataDirection::ToDevice, /// GFP_KERNEL, @@ -436,14 +436,14 @@ impl

SGTable> /// Ok(()) /// } /// ``` - pub fn new( - dev: &Device, + pub fn new<'a>( + dma: dma::Handle<'a>, pages: P, dir: dma::DataDirection, flags: alloc::Flags, - ) -> impl PinInit + '_ { + ) -> impl PinInit + 'a { try_pin_init!(Self { - inner <- Owned::new(dev, pages, dir, flags)? + inner <- Owned::new(dma, pages, dir, flags)? }) } } diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 1233aac8fe23..8fb5b90d7aaa 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -105,7 +105,7 @@ fn probe<'bound>( let size = 4 * page::PAGE_SIZE; let pages = VVec::with_capacity(size, GFP_KERNEL)?; - let sgt = SGTable::new(dma.device(), pages, DataDirection::ToDevice, GFP_KERNEL); + let sgt = SGTable::new(dma, pages, DataDirection::ToDevice, GFP_KERNEL); Ok(try_pin_init!(Self::Data { pdev, -- 2.51.2