From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B38FE2E88A4; Sat, 12 Sep 2026 07:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789198592; cv=none; b=V1avHSMWzmoi3KhQ5kPNjgIgdpuKSwqOBGjpQSS0XjH3GZ9l5fklhVdsf/oKD+WumDBxUew1eWJdW+yz05koZCaKYVCl7INgcXT1Q2DceuaPxbrxF73DgbjBWcuBPWt/T1vyjKTIVEaxLhzLCzU8hTeKBpKKpcf489lEE9nuDjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789198592; c=relaxed/simple; bh=wdtTN9pssIe7SAvR96kmfPhXgzDTZQiy9Fdb9GRKe00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BTyaAAqt6zvT+OkLNXDs4A5nmCdci5f3brjekbsA1jit2KXnD1X5cIy6Kr7V9pEDHXtKrSM00YtymurqG9uXxYiIrzA4iAyQUGYOSI9ITf3ORCKHyZZPsTSPbI16qAQkUb4RxhEmvcqGv/TqrdXwg+tclw0kEc1TF7bnQa/9NLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=XPwmJWoQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="XPwmJWoQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B815E1F000FF; Sat, 12 Sep 2026 07:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789198591; bh=aH20NVLhrmpLAjwNF7qiCVpsojccKGRFSsJaAjJmKBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XPwmJWoQKXt/3KoAB763FgIB9njuG7CPtDCx6c3VJu6GWNdUJAn1pz0hhiiSnUplC /gCknHFxYzuemWACkaiE15z0WpJFC73X3fAWnpFrxlW9X3L9Pr1I3EDCbTKCEo4tZd qRkhzisEdgOCMM+bwbZ/b0AjXiL+es2KK6gzq1cQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sami Tolvanen , Alice Ryhl , Sasha Levin Subject: [PATCH 7.2 0369/1815] rust: drm: gpuvm: require Send + Sync for the drivers associated data Date: Sat, 12 Sep 2026 08:35:19 +0200 Message-ID: <20260912065657.565860280@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sami Tolvanen [ Upstream commit b59ec72fec247b90dc26f17c5b1ee9f1e0fe334c ] DriverGpuVm permitted !Send/!Sync associated data on an abstraction whose handles are shared and dropped across threads: obtain() runs from many threads and the VA API performs deferred cross-thread drops. That is unsound. Require Send + Sync on the trait and its associated data so the GpuVm and UniqueRefGpuVm handle impls need no per-impl bounds. Fixes: 82b78182eacf ("rust: drm: add base GPUVM immediate mode abstraction") Signed-off-by: Sami Tolvanen Link: https://patch.msgid.link/20260611-gpuvm-sync-send-v4-1-6c7f4ab2778a@google.com Signed-off-by: Alice Ryhl Signed-off-by: Sasha Levin --- rust/kernel/drm/gpuvm/mod.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rust/kernel/drm/gpuvm/mod.rs b/rust/kernel/drm/gpuvm/mod.rs index a625fcd9b5f22..70cf11346ceee 100644 --- a/rust/kernel/drm/gpuvm/mod.rs +++ b/rust/kernel/drm/gpuvm/mod.rs @@ -72,10 +72,12 @@ pub struct GpuVm { data: UnsafeCell, } -// SAFETY: The GPUVM api does not assume that it is tied to a specific thread. The destructor will -// drop the `data` field, which is okay because it is guaranteed `Send` by the `DriverGpuVm` trait. +// SAFETY: It is safe to send a `GpuVm` to another thread: all data reachable through it +// (`T`, `T::VmBoData`, and the GEM `T::Object`) is `Send` by the `DriverGpuVm` bounds. unsafe impl Send for GpuVm {} -// SAFETY: The GPUVM api is designed to allow &self methods to be called in parallel. +// SAFETY: It is safe to share a `&GpuVm` between threads: `&self` methods only alias data +// that is `Sync` by the `DriverGpuVm` bounds, and any thread may drop that data, or upgrade the +// reference and ultimately drop `T`, which the same bounds make `Send`. unsafe impl Sync for GpuVm {} // SAFETY: By type invariants, the allocation is managed by the refcount in `self.vm`. @@ -250,18 +252,22 @@ impl GpuVm { } /// The manager for a GPUVM. -pub trait DriverGpuVm: Sized + Send { +pub trait DriverGpuVm: Sized + Send + Sync { /// Parent `Driver` for this object. type Driver: drm::Driver; /// The kind of GEM object stored in this GPUVM. - type Object: drm::driver::AllocImpl; + type Object: drm::driver::AllocImpl + Send + Sync; /// Data stored with each [`struct drm_gpuva`](struct@GpuVa). - type VaData; + /// + /// Only `Send` is required: the data has a single owner at all times, moving + /// between threads by value (handed back as a [`GpuVaRemoved`]) but never + /// accessed by two threads concurrently. + type VaData: Send; /// Data stored with each [`struct drm_gpuvm_bo`](struct@GpuVmBo). - type VmBoData; + type VmBoData: Send + Sync; /// The private data passed to callbacks. type SmContext<'ctx>; @@ -296,12 +302,10 @@ pub trait DriverGpuVm: Sized + Send { /// # Invariants /// /// Each `GpuVm` instance has at most one `UniqueRefGpuVm` reference. +// `Send`/`Sync` derive from `ARef>`; the trait bounds make them correct for the unique +// handle's `&mut T` access. pub struct UniqueRefGpuVm(ARef>); -// SAFETY: The GPUVM api is designed to allow &self methods to be called in parallel, and -// concurrent access to `data` is safe due to the `T: Sync` requirement. -unsafe impl Sync for UniqueRefGpuVm {} - impl UniqueRefGpuVm { /// Access the data owned by this `UniqueRefGpuVm` immutably. #[inline] -- 2.53.0