From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender5-op-o11.zoho.com (sender5-op-o11.zoho.com [165.173.182.11]) (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 878563C1F; Wed, 23 Sep 2026 20:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=165.173.182.11 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790196201; cv=pass; b=M3kwUdgDlPsHGx/nwBlV3lBUr7pJKWAAD+mA73eEGmcE6DP3GjQTHtSoSl0kA/PWYlhoZ1yHbOKWN4DHgZJssCyhV8vZVVa9ECyuvulANox6/BZ22RjkjeYqB5HA1EMB+1z17QHGZ8vrInqLTyJ6Cd+khflhDAq85qY0q9U3fDY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790196201; c=relaxed/simple; bh=cQpgbVCfz1vyJ7PhUgvYbUvDkQyLBFh/zIn1QkfzTtE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=XNcIKaDChcz6dEoYiCQMa3A9IgZwcILUUGiDJ4WrVcGasHRQTPkc9neKhGFYxPlaxwM/xuJKwN1QYGxhGKw4pKYh59N2LFxK/OCrSuUHygCd3B57LzT+ixU4/7GopbAIVTdAsVGRLeYSYoAMItKI0YuwOQqV/kVLIVmxYsvSybw= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b=gK9GgW7F; arc=pass smtp.client-ip=165.173.182.11 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 (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b="gK9GgW7F" ARC-Seal: i=1; a=rsa-sha256; t=1790196154; cv=none; d=zohomail.com; s=zohoarc; b=J8Qty4xuAwmy9p1FDA6M4MKIbduEQW68wW5K4RMKvg8qAeHjvbdt6gLa560gn5SKk1/3ODoSz+B2LiVShTnEffY774x4pasKBFCtCaWX0DMMZzQRqYxO27sWZqCxf6F3iNts4KA0msRVm/K5Umrv+AasYLLUCBFALEgb3a3u9os= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790196154; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=xo7cgqIIFuStSgCn4luUGcQPHzo3wUQwdn1Qq+BTVqQ=; b=VBP0PCfW+ucS19AZr6VA2IULlPDugAlAIpeQwf0OWzJJEfklrHFGXPKce+yFKmMbUa4yoOjafYG8YkUU5dykK4KC2vX+B+Y/3fCU9SRlk1waiQeEQw4fUQ5LqUr8loaVKY01yAFrKHztVNX79a+vqpFBuXel2u7bS92KclvLlLw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=daniel.almeida@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1790196154; s=zohomail; d=collabora.com; i=daniel.almeida@collabora.com; h=Content-Type:Mime-Version:Subject:Subject:From:From:In-Reply-To:Date:Date:Cc:Cc:Content-Transfer-Encoding:Message-Id:Message-Id:To:To:Reply-To; bh=xo7cgqIIFuStSgCn4luUGcQPHzo3wUQwdn1Qq+BTVqQ=; b=gK9GgW7FLv0FVaPmeWXVOMiQb9TTQjskMlrMhkP8EZyo/jX1CKGHWQ0N4vnJzwr2 8I0KBZ0v6hseD7/Xhwd52EoxDtpeeUnNiz14hQfR+09smb7Gc+miE9elMMzw7lsXhGQ pCmhQUJi9rL9Nfsfu8+xvXlvBOBhewEkTfu6U2ZM= Received: by smtp.zohomail.com with SMTPS id 1790196153019663.532298405788; Wed, 23 Sep 2026 13:42:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.100.1.1.11\)) Subject: Re: [PATCH 4/9] drm/tyr: add McuVa and claim-checked MappedBo views From: Daniel Almeida In-Reply-To: <20260915-tyr-interfaces-v1-4-5d28f1f75aca@collabora.com> Date: Wed, 23 Sep 2026 17:42:13 -0300 Cc: Danilo Krummrich , Alice Ryhl , 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 , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, kernel@collabora.com Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260915-tyr-interfaces-v1-0-5d28f1f75aca@collabora.com> <20260915-tyr-interfaces-v1-4-5d28f1f75aca@collabora.com> To: Laura Nao X-Mailer: Apple Mail (2.3901.100.1.1.11) X-ZohoMailClient: External Hi Laura, It=E2=80=99s been a while since I wrote this, and I now see this could = use some improvements. I think the first problem is that this conflates "MappedBo" with "the = MappedBo backing the shared region". As soon as we try to add more users, this = will be a problem. I propose that we split this into two types that build upon = each other: a) a generic layer MappedBo, which remains roughly as-is: gem.rs: pub(crate) struct MappedBo<'drm> { vmap: shmem::VMapOwned, bo: KernelBo<'drm>, } impl<'drm> MappedBo<'drm> { // pub(crate) API: // no Arc, McuMappedBo has to hold it by value, otherwise a second = holder // could write around the claims. fn new(bo: KernelBo<'drm>) -> Result fn va_range(...) -> ... fn vmap(...) -> ... } impl Deref for MappedBo<'_> { type Target =3D Bo ... } b) A MCU-specific BO type with the claims + offset logic: fw/mcu_bo.rs: pub(super) struct McuVa(...) + related McuVa impls. #[pin_data] pub(super) struct McuMappedBo<'drm> { bo: MappedBo<'drm>, // private, no accessor #[pin] claims: Mutex>> } impl<'drm> McuMappedBo<'drm> { // pub super API // builds its own MappedBo, checks the 32-bit range before allocating = and // copies the section data from the fw binary before any view can = exist. new(ddev, mcu_vm: Arc>, va: McuVa, size: u64, flags: = VmMapFlags, data: &[u8]) -> Result> {...} // views borrow: &'a self instead of self: &Arc fn try_view<'a>(&'a self, va: McuVa, len: u64, reach: u64) -> Result> fn try_view_mut<'a>(&'a self, va: McuVa, len: u64, reach: u64) -> Result> } c) Views get renamed to McuView, McuViewMut: #[derive(Clone)] pub(super) struct McuView<'a> { vmap: &'a VMapOwned, base: u64, range: Range, reach: u64, // <=E2=80=94=E2=80=94=E2=80=94=E2=80=94 Store this } pub(super) struct McuViewMut<'a> { view: McuView<'a>, claims: &'a Mutex>>, } impl<'a> Deref for McuViewMut<'a> { type Target =3D McuView<'a>; fn deref(&self) -> &Self::Target { &self.view } } impl Drop for McuViewMut<'_> { // return claim here. } >=20 > +// SAFETY: `MappedBo` may move between threads: the CPU mapping's = address is > +// valid from any thread; `KernelBo`'s teardown (GPU unmap through = `Arc` > +// and the GEM object release) goes through thread-safe C APIs; and = the only > +// interior mutability (`claims`) is mutex-protected. > +unsafe impl Send for MappedBo<'_> {} > +// SAFETY: `&MappedBo` exposes the mutex-protected claims table, the = `Deref` > +// surface to the GEM object (thread-safe C APIs), and the mapping = itself, > +// whose contents are only ever accessed through volatile operations. = The > +// memory is shared with the MCU by design, so concurrent access is = part of > +// the model rather than a race the type system must rule out. > +unsafe impl Sync for MappedBo<'_> {} I don=E2=80=99t think we need a manual implementation here. The rest of the patch looks good to me. =E2=80=94 Daniel