From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477628; b=sDhpUyt0EmEAKxyfqcO5oqamQcVgNoKjBf4zBcSWX+lrVNvIJn4hw1sv7jkO0MzuEsj8 DMSegSPKkl7JN37n0GiqhOlP0A9eyPKyj7NwV8rTH+V/KS/u8O8mdWSkFtE9orqlpuxti doTwinO1821Ysq3rJiiC1dmSpLerkOldmbBGZyOKm4qOXsUupP3L98ViZr6nbThc8sxJp VAAzjAZaCEGo5MEl4sGynxBiwyzsBI2D+s6DM9o5rOOBTsDdExDixNBAz67fnO9AsLKa9 HP+fj21Mj1x9dFXiczs0wAQ5HrFVfwtvAhK8wtRdVvHMxgvNuumuwYsA7mn59E1IArg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477628; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=ihLT9KbeWJH54YB/Wmu9wOSnF3fZjlaDEvputsiFDT4=; b=lXDOFrbzK8tbKOt4xp0De/z2HgZd331N6RBFnq3UCyd5ylOQPGixiOGDbP1wDZ9hbbnk lsfywCxl+Ko/Iha08V3bnqDBY68t1Jh2xiviznU6XxDlkoTzWAN/mBQN29ivpxUf5shcp YjYsZV+0HEDog+vHLgTdRAdvuEpz6NdKuab4Mk4uplJgoHWB4NZeQLYUwo9TOSc88WOAA mnTpHLEsA4M0Lxcc025qkF6FJOMk0hrow42Cw8hHw4IGGCjWfGO1l35QRWntTB5nHnv3H AXCBA4ImRFq81qiySPb7jRrtVgWd54EKS0oF5gI0rDISRW8emmFYonIBNbI0QwuL+LQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qdsczsi7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 EB3B760A2624 for ; Sat, 5 Dec 2026 13:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qdsczsi7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 939E91F00A2E; Sat, 5 Dec 2026 13:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796477627; bh=ihLT9KbeWJH54YB/Wmu9wOSnF3fZjlaDEvputsiFDT4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Qdsczsi7fs9YNl751q1crZ4iu+gGg3lSKTxbksUtLQMnWvh7/jK1woboL7be/SUOP gCKgs0uUpDtX/kqunzNm2Gc/F78XyMU83MhPQF3znmMKf1tcQWr7J3ecVdSx1i8QV1 RNoZOcF02iHRPOdOfCOhjHiV84/5XrysLuz0IxEW5vm1yRLg/uknYQUuLv5Pv38fuy TlgOOEEG1e710vd5lsizaDGULk+PJdoi/4ERBS4VlpA7JqCRjaQw6tfwd2T+sDoFU5 VKTA0FF8iRywbgM58sooH/xkM8ttlp2hFlKU117zpVoKpkj/yR/GAvmWgwqiAcOEpQ 3ByBDUqbtjmPw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 5/5] rust: drm: gem: shmem: Implement prime_import_sg_table callback Reply-To: sashiko-reviews@lists.linux.dev To: "Janne Grunau" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?Qmo=?= =?utf-8?b?w7ZybiBSb3kgQmFyb24=?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?b?T251ciDDlnprYW4=?= , "David Airlie" , "Simona Vetter" , "Sami Tolvanen" , "Lyude Paul" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "Sumit Semwal" , =?utf-8?b?Q2hyaXN0aWFuIEvDtm5pZw==?= , "Philipp Stanner" Cc: dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, stable+noautosel@kernel.org, "Deborah Brouwer" , media-ci@linuxtv.org In-Reply-To: <20261205-rust-drm-gem-shmem-imported-sgt-v4-5-f6ccbdafbb76@jannau.net> References: <20261205-rust-drm-gem-shmem-imported-sgt-v4-0-f6ccbdafbb76@jannau.net> <20261205-rust-drm-gem-shmem-imported-sgt-v4-5-f6ccbdafbb76@jannau.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 13:33:46 +0000 X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] rust: drm: shmem: narrowed provenance in prime_import_sg_table_callback() - [Low] rust: drm: shmem: no INVARIANT comment in prime_import_sg_table_callback() -- commit 93fbf9fffcbe36057059749efd20c7a4b1a389f5 Author: Janne Grunau rust: drm: gem: shmem: Implement prime_import_sg_table callback This commit implements a Rust gem_prime_import_sg_table callback for shmem GEM objects to avoid C-side object allocation and teardown, and adds a create_imported() constructor to DriverObject for Nova, Tyr, and the KUnit test driver. Link: https://lore.kernel.org/rust-for-linux/20261118114102.490384-1-alicer= yhl@google.com/ > diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs > index 41f31adb23717..e0af54eb36564 100644 > --- a/rust/kernel/drm/gem/shmem.rs > +++ b/rust/kernel/drm/gem/shmem.rs [ ... ] > @@ -346,6 +347,67 @@ pub fn new( > Ok(obj) > } > =20 > + /// Create a new shmem GEM object from another driver's scatter/gath= er table of pinned pages. > + /// > + /// This is a Rust re-implemetation of `drm_gem_shmem_prime_import_s= g_table()` to avoid > + /// creating and destroying `Self` in C code. > + /// This function imports a scatter/gather table exported via DMA-BU= F by another driver. > + /// It should be only called via the &drm_driver.gem_prime_import_sg= _table callback. > + extern "C" fn prime_import_sg_table_callback( > + raw_dev: *mut bindings::drm_device, > + raw_attach: *mut bindings::dma_buf_attachment, > + raw_sgt: *mut bindings::sg_table, > + ) -> *mut bindings::drm_gem_object { [ ... ] > + let new: Pin> =3D match KBox::try_pin_init( > + try_pin_init!(Self { > + obj <- Opaque::init_zeroed(), > + parent_resv_obj: None, > + sgt_res: ManuallyDrop::new(SetOnce::new()), > + sgt_lock <- new_mutex!(()), > + inner <- T::create_imported(dev, size), > + }), > + GFP_KERNEL, > + ) { > + Ok(new) =3D> new, > + Err(e) =3D> return e.to_ptr(), > + }; [Severity: Low] Object documents an "# Invariants" section covering the initialized drm_gem_shmem_object and the imported sgt field. Per the kernel Rust coding guidelines, should constructing Self here carry an // INVARIANT: comment explaining how those invariants are satisfied? [ ... ] > + // SAFETY: We never move out of `self`. Ownership of the allocat= ion is transferred to the > + // C side. > + let new =3D KBox::into_raw(unsafe { Pin::into_inner_unchecked(ne= w) }); > + > + // SAFETY: `new` was just produced by `KBox::into_raw` and so is= a valid pointer to an > + // initialized `Self`. `obj.base` is the embedded `drm_gem_objec= t` the caller expects. > + unsafe { &raw mut (*(*new).obj.get()).base } > + } [Severity: Medium] Does (*new).obj.get() narrow pointer provenance to the obj field here? Opaque::get() takes &self, so (*new).obj.get() creates a temporary shared reference restricted to the obj subobject. When C later passes the returned pointer to Object::free_callback(), container_of! accesses sibling fields and frees the full Object via KBox::from_raw(). Under Rust's aliasing models that is undefined behavior. Using &raw mut (*Opaque::cast_into(&raw const (*new).obj)).base avoids the intermediate reference and preserves the full allocation provenance. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-rust-drm-g= em-shmem-imported-sgt-v4-0-f6ccbdafbb76@jannau.net?part=3D5