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=0tPYe4WO2768YAWmLxpZtOe4+VQi3VsXQUml487+OtJ7Zmh8Ezc93Jag/EdGHSJS6lP7 IbWaj+kSrXl8YJLfIXgck/ZjK+01aOFXwyG2+4+bfbm/P1ODSFv774cMl0M9HYoSsj/a8 1RfdChcXLsAZ4POR6zTuyZRlCdhEzbc1shJMPRqzyUrlBCkaPfMKTZ81KsqfJQ/Ay1fXE 44H4e7TfKvHFX5ZKx6dlcBzd2m0R2TRnzMfQ0TGDfKuaEH25UnJgk0I/GCdNbtKMwSNdV 7gEcP4wqhs3//KZd7cG1BBnguZ0W1MwNyldrjzRbWgfpRtHsEwoh5rhVUnraT/oTQ4g== 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=QmIP49CJDuON2ATVuaT2AYWUbisi8B5sPicbraaGNDI=; b=agwm55055ZNyeLKuOyHFycepUTEWNqQXtVh+TNtA5f6ulq+6DJVg8lVGn8vREh0/b5lj n3luavkhlgAt6iy93Ypt13jOCWGU9eQcd7lYiQHQaR6VYNfRKIMLue1/4fw5AbHzPIJVW L6l/E0ss0M0eeGz9Qfx7avwB2AW/HXKcC//u9QopDrhT/ykt0S2Wv6PjDbN5lNbA8On13 EwPbU2W5Oh1v7cqRKSz0JgAt6b7V0pOPUobjOaAJA8WCnmKfptK7ST2n0MyOb8BUZhtXT 4KyHP6+dv3oL3E+ARlqV8Gpsu2KV5kbtUC35Gp6VBKOaVlYJeozNVPRkf1TVPa5gIbg== 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=MEwg1ABd; 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 2FA01606A6AE; Sun, 29 Nov 2026 22:25:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2FA01606A6AE 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=MEwg1ABd From: Matteo Kloiber DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=matt3o12.de; s=securedbylima-20230709; t=1795991104; bh=79RdmsKs2OAl1NaTb6H3t5upEvjq1LRdTgYS3P9xb5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MEwg1ABdn421S/xdTO8Hdlcldw1JT59tjgY9RUjVFm8ZIQHfxfCJwGk+9TXTOXjz2 p7YdoUqY6cOlk8/omvJJYvK+lswHkE3NikiwsQE0kh0Qedrc1bzYd+z7nfjJLWTzvv 0cwwywDljP53zCnTX6+FAiNEORs6v7EeESPFNN9VxcllHBBUhug5VKPSSR8undTfia Ow4AjPb2IsVrR0OuxTorIwZMoMbYIlqS3w4fcR5XDcbNmzyc0KC63XBD3zWbuTu+Bx FwEg/Xib3CTCtcVGKzuKW4namxOQ1X8aHOtH54zTZnoG5pZoTU3fpJeQ7Kj+Chz38q 7msH6dT813Gsg== 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 08/10] rust: iommu: require a dma::Handle for IoPageTable::new() Date: Sun, 29 Nov 2026 23:24:27 +0100 Message-ID: <20261129222429.2380652-9-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 The io-pgtable code DMA-maps its table pages for the device when the tables are not walked coherently, which depends on the device's DMA parameters. Take a dma::Handle instead of the device in IoPageTable::new(), and record in the type invariant that the device has been configured. Convert Tyr, the only user. Signed-off-by: Matteo Kloiber --- drivers/gpu/drm/tyr/mmu/address_space.rs | 2 +- rust/kernel/iommu/pgtable.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs index de7dce8e9ee6..ed131b8a6b57 100644 --- a/drivers/gpu/drm/tyr/mmu/address_space.rs +++ b/drivers/gpu/drm/tyr/mmu/address_space.rs @@ -102,7 +102,7 @@ pub(crate) fn new<'a>( coherent_walk: false, }; - let page_table_init = IoPageTable::new(dma.device(), pt_config); + let page_table_init = IoPageTable::new(dma, pt_config); try_pin_init!(Self { as_seat: LockedBy::new(&mmu.as_manager, Seat::NoSeat), diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs index 5f9b42ca92c2..78acef800011 100644 --- a/rust/kernel/iommu/pgtable.rs +++ b/rust/kernel/iommu/pgtable.rs @@ -12,10 +12,7 @@ use crate::{ alloc, bindings, - device::{ - Bound, - Device, // - }, + dma, error::to_result, io::PhysAddr, prelude::*, // @@ -57,10 +54,11 @@ pub struct Config { /// /// # Invariants /// -/// The pointer references a valid io page table. +/// The pointer references a valid io page table whose device's DMA parameters have been +/// configured and remain unchanged for the lifetime of the page table. pub struct IoPageTable<'a, F: IoPageTableFmt> { ptr: NonNull, - _dev: PhantomData<&'a Device>, + _dma: PhantomData>, _marker: PhantomData, } @@ -77,8 +75,10 @@ pub trait IoPageTableFmt: 'static { impl<'a, F: IoPageTableFmt> IoPageTable<'a, F> { /// Create a new `IoPageTable`. + /// + /// Requires a configured DMA handle because non-coherent page tables may use DMA mappings. #[inline] - pub fn new(dev: &'a Device, config: Config) -> Result> { + pub fn new(dma: dma::Handle<'a>, config: Config) -> Result> { let mut raw_cfg = bindings::io_pgtable_cfg { quirks: config.quirks, pgsize_bitmap: config.pgsize_bitmap, @@ -86,7 +86,7 @@ pub fn new(dev: &'a Device, config: Config) -> Result> oas: config.oas, coherent_walk: config.coherent_walk, tlb: &raw const NOOP_FLUSH_OPS, - iommu_dev: dev.as_raw(), + iommu_dev: dma.as_raw(), ..Zeroable::zeroed() }; @@ -94,15 +94,17 @@ pub fn new(dev: &'a Device, config: Config) -> Result> // * The raw_cfg pointer is valid for the duration of this call. // * The provided `FLUSH_OPS` contains valid function pointers that accept a null pointer // as cookie. - // * The caller ensures that the io pgtable does not outlive the device. + // * The DMA handle ensures that the device is configured and remains bound for `'a`. + // The returned page table cannot outlive this lifetime. let ops = unsafe { bindings::alloc_io_pgtable_ops(F::FORMAT, &mut raw_cfg, core::ptr::null_mut()) }; - // INVARIANT: We successfully created a valid page table. + // INVARIANT: We successfully created a valid page table. The DMA handle guarantees + // that its device's parameters are configured and remain unchanged for `'a`. Ok(IoPageTable { ptr: NonNull::new(ops).ok_or(ENOMEM)?, - _dev: PhantomData, + _dma: PhantomData, _marker: PhantomData, }) } -- 2.51.2