From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 A94D2486408; Tue, 15 Sep 2026 10:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789469928; cv=none; b=R6XjkbNyeDM7Aa2alFsSWYQK0ifEiubgRw2gX3Irk5uN8knA6Xv0ThpP3F/9UlVeLqxH6dGRQlCnYUN/N3sTLegE32pys1fJzM1xbw3TqyIQbNdLr/nga19daKq7MEJ81usBH8066H/cy3+H2FePBklgZboBHiE5RVRr3XL7dwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789469928; c=relaxed/simple; bh=sBlK784vZ/oqRMvO5qMK02PMD1Gt0+oIJw0QmxBvQ2A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZGifDtaX+f+A/3uwkz1Tt0Rjf+mvj0Wh3mcFpftaEWjGOWK8GwhRRAGrWSUoc/yl7WFBMwuiUjaKjyd9rqXeYghvmBBIjSpW42nk/oG0/r2MSGdZAh1HliENKBWX5uqfuHotom1Ilm1pWte1+KGBHLX4ggTWpNQTNV2jLRiqvNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=oPTvglxf; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="oPTvglxf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1789469924; bh=sBlK784vZ/oqRMvO5qMK02PMD1Gt0+oIJw0QmxBvQ2A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oPTvglxf1y1Q5InX+Qtm4qblgd5bYGkk/CBKck5i5h0bb1eIQi5EkqiOdxBQtxLus KpkBNnHPvBecAmROpFK3kKYz3SvRS51+nmJZMf/bUR+K1HF23Z7RfERzlsMoADFlE+ L4IEYMO/Q6+s1Imgj4xRuvb9lJkOEufpKML/typHwrOj1RtrXLDfUTfUpKn+ehd67M x58/UJ6BuQmNa34V7R2c3cIUU/8uJS8OrOVUuxfgW4vvw9VPrnsgjN+scMG1OwCmTK ZGiONEJ1SMVfdFGVL/rhsG0YUeofmpUFfCSmpV+G5veyjErwKgIQhiIgaPMfFZ1Bme V/VNc8dPg28pQ== Received: from laura.lan (unknown [100.64.0.215]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: laura.nao) by bali.collaboradmins.com (Postfix) with ESMTPSA id 0053617E0A27; Tue, 15 Sep 2026 12:58:43 +0200 (CEST) From: Laura Nao Date: Tue, 15 Sep 2026 12:57:36 +0200 Subject: [PATCH 3/9] drm/tyr: add MappedBo, a kernel BO with an always-valid CPU mapping 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260915-tyr-interfaces-v1-3-5d28f1f75aca@collabora.com> References: <20260915-tyr-interfaces-v1-0-5d28f1f75aca@collabora.com> In-Reply-To: <20260915-tyr-interfaces-v1-0-5d28f1f75aca@collabora.com> To: Danilo Krummrich , Alice Ryhl , Daniel Almeida , David Airlie , Simona Vetter , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, kernel@collabora.com, Laura Nao X-Mailer: b4 0.14.3 From: Daniel Almeida Firmware sections need CPU access at well-defined points: once at load time to copy the section payload in, and, for the shared section, for the lifetime of the driver to talk to the CSF interface blocks. Introduce MappedBo, which pairs a KernelBo with one persistent vmap so the GPU mapping and the CPU mapping share a single lifetime, and hold it in Section instead of the bare KernelBo. Section payload initialization now writes through the persistent mapping. This is the foundation for resolving firmware-reported MCU virtual addresses into validated views of the shared section: the object that owns both mappings is the natural place for those checks to live. Signed-off-by: Daniel Almeida Signed-off-by: Laura Nao --- drivers/gpu/drm/tyr/fw.rs | 14 ++++++------- drivers/gpu/drm/tyr/gem.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/tyr/fw.rs b/drivers/gpu/drm/tyr/fw.rs index 19bdeee858ce..fb4d47ab35a3 100644 --- a/drivers/gpu/drm/tyr/fw.rs +++ b/drivers/gpu/drm/tyr/fw.rs @@ -144,7 +144,7 @@ struct Section<'drm> { // Keep the BO backing this firmware section so that both the // GPU mapping and CPU mapping remain valid until the Section is dropped. #[expect(dead_code)] - mem: gem::KernelBo<'drm>, + mem: Arc>, } /// Loaded firmware with sections mapped into MCU VM. @@ -171,13 +171,13 @@ fn drop(&mut self) { } impl<'drm> Firmware<'drm> { - fn init_section_mem(dev: &Device, mem: &mut KernelBo<'drm>, data: &KVec) -> Result { + fn init_section_mem(dev: &Device, mem: &gem::MappedBo<'drm>, data: &KVec) -> Result { if data.is_empty() { return Ok(()); } - let vmap = mem.bo().vmap::<0>()?; - let size = mem.bo().size(); + let vmap = mem.vmap(); + let size = mem.size(); if data.len() > size { dev_err!(dev, "fw section {} bigger than BO {}", data.len(), size); @@ -235,13 +235,13 @@ pub(crate) fn new( let va = u64::from(parsed.va.start); - let mut mem = KernelBo::new( + let mem = gem::MappedBo::new(KernelBo::new( ddev, vm.clone(), size, KernelBoVaAlloc::Explicit(va), parsed.vm_map_flags, - )?; + )?)?; let section_start = parsed.data_range.start as usize; let section_end = parsed.data_range.end as usize; @@ -252,7 +252,7 @@ pub(crate) fn new( let bytes = fw_data.get(section_start..section_end).ok_or(EINVAL)?; data.extend_from_slice(bytes, GFP_KERNEL)?; - Self::init_section_mem(dev, &mut mem, &data)?; + Self::init_section_mem(dev, &mem, &data)?; sections.push(Section { data, mem }, GFP_KERNEL)?; } diff --git a/drivers/gpu/drm/tyr/gem.rs b/drivers/gpu/drm/tyr/gem.rs index 3bf3787f5c3f..4763b5b2cd80 100644 --- a/drivers/gpu/drm/tyr/gem.rs +++ b/drivers/gpu/drm/tyr/gem.rs @@ -136,6 +136,12 @@ pub(crate) fn new( pub(crate) fn bo(&self) -> &Bo { &self.bo } + + /// Returns the GPU virtual address range occupied by this buffer. + #[expect(dead_code)] + pub(crate) fn va_range(&self) -> Range { + self.va_range.clone() + } } impl Drop for KernelBo<'_> { @@ -158,3 +164,46 @@ fn drop(&mut self) { } } } + +/// A kernel-owned buffer object with an always-valid kernel (CPU) mapping. +/// +/// This pairs a [`KernelBo`] with a persistent vmap of its backing GEM object, +/// so the GPU mapping and the CPU mapping share one lifetime. Consumers that +/// need CPU access to the buffer contents (e.g. the firmware interface blocks +/// in the CSF shared section) hold an `Arc` instead of creating +/// short-lived vmaps at every use site. +pub(crate) struct MappedBo<'drm> { + /// Persistent CPU mapping of `kernel_bo`'s backing object. + /// + /// Declared before `kernel_bo` so the mapping is dropped first. + vmap: shmem::VMapOwned, + /// The underlying kernel-owned buffer object. + #[expect(dead_code)] + kernel_bo: KernelBo<'drm>, +} + +impl<'drm> MappedBo<'drm> { + /// Wraps `kernel_bo` together with a persistent CPU mapping of its buffer. + pub(crate) fn new(kernel_bo: KernelBo<'drm>) -> Result> { + let vmap = kernel_bo.bo.owned_vmap::<0>()?; + Ok(Arc::new(Self { vmap, kernel_bo }, GFP_KERNEL)?) + } + + /// Returns the persistent CPU mapping of the buffer. + pub(crate) fn vmap(&self) -> &shmem::VMapOwned { + &self.vmap + } + + /// Returns the GPU virtual address range occupied by the buffer. + pub(crate) fn va_range(&self) -> Range { + self.kernel_bo.va_range() + } +} + +impl core::ops::Deref for MappedBo<'_> { + type Target = Bo; + + fn deref(&self) -> &Bo { + self.vmap.owner() + } +} -- 2.39.5