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=1796444347; b=0rgf9DLmJh8J32z0SDmHgct3vrD+ioAKO1lHIq+wTC6r6pGFBPWBrPso0H4IymogYpX/ PTFbPD95a5s6f9/y8Z+vM4i2KK4ll+iCII70L4HZ65jwpa+wKBiLPUjZSHdjPKxZStEJg UhL5niT3Umz5iT24IDu5qbn+4k75H8qAqeFIM0dQqRq2KACJz+OY2GE+T2nxD6HNvy1k3 e4YBoSVKOMzV1qoYF0wad5s7piMxpqwYYV0udrNKxUsIa9uAKtldJkFB4otRM4slw+tNh EyWAiyX9u+DZEmN4TI3q+qe3h+PC0DAQK9cC77Wriljw/pu6wk3jFaVpm2RMQk/TGig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796444347; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=IpLpgJ6d7akMB40Bp8Ehv1ak6+N7RayHID1hvDkkhlw=; b=p1cHbadOx8FGseuj9v7VaeQaZKh/ignoZgoDA9Co/BzS6jfPnuWko62iSZLSvyp3PBbr mR90sfU+gMegXMoSaJb+FCMxhSYXJaL0MV3UipAM76qUda05vJRp0XCNpOlQfY4q08R6A flK07aWoMhkkVo3Z3NMRoSRLFOD+Npbx0A+aPqLGpxFM5+fKGnd2D1GL5KKGsVPanRTXr r/Om+yo+bMK2qfJWqN2nRbWhTPxlnLEUBIlJvmGfhZvrbuayx9tFw07Rzcl1dU+T34oBA o2ZLoHB6CYW3sohEKk8Z20KYmh48syB+i/KWqi86TJFZzVvhe1sDrvXQT7AtgrD6Scg== 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=NXTnEdiF; 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 85BC7606A333; Sat, 5 Dec 2026 04:19:07 +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=NXTnEdiF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 694931F0092B; Sat, 5 Dec 2026 04:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796444347; bh=IpLpgJ6d7akMB40Bp8Ehv1ak6+N7RayHID1hvDkkhlw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NXTnEdiFuqSHhN1jn1qjYphpOVLRMfWXA2v3vzb1xzrrrmuk5nLf63aawJs747Beb wbS4WWalujPfChDz3Q8EtjBctBaBsBzaM/wwQO9YzpHqhf8DLuzUYXAVuj886tVfMr C7BeSflV5L76F5i4jliwYnshq1DLNsZXnA2zs3HQADbHPeq1ll63/BaKRZ+FdV1f8j m3OOjHsuvV04towgQlEcswdOdAOxhc7u1efp3sLv0gt0ENvU+cgkx/aHU7xmtXqTCq uIkOcFK/oujGYK75p/bF1RaPVuTWeoVUpUaqIBNAiCjSiL2TL46qfTnrX75R57x9qa NO653PfnayCRQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 2/4] rust: vfio: add common VFIO device handling Reply-To: sashiko-reviews@lists.linux.dev To: "Simon Song" , dakr@kernel.org, acourbot@nvidia.com, kvm@vger.kernel.org, nova-gpu@lists.linux.dev, linux-pci@vger.kernel.org Cc: "Zhi Wang" , alex@shazbot.org, jgg@nvidia.com, yishaih@nvidia.com, skolothumtho@nvidia.com, kevin.tian@intel.com, airlied@gmail.com, simona@ffwll.ch, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, jhubbard@nvidia.com, ecourtney@nvidia.com, cjia@nvidia.com, smitra@nvidia.com, kjaju@nvidia.com, alkumar@nvidia.com, ankita@nvidia.com, aniketa@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, zhiwang@kernel.org, boqun@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org, work@onurozkan.dev, jgg@ziepe.ca, bhelgaas@google.com, kwilczynski@kernel.org, dri-devel@lists.freedesktop.org, peter@colberg.org, "Liam R. Howlett" , linux-mm@kvack.org, "Lorenzo Stoakes" In-Reply-To: <20261204041727.4021092-3-xinmengs@nvidia.com> References: <20261204041727.4021092-1-xinmengs@nvidia.com> <20261204041727.4021092-3-xinmengs@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:19:05 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Low] rust: vfio: missing #[inline] on small DeviceBase helpers - [Low] rust: vfio: DeviceBase::callback_data() bypasses ForeignOwnable::borrow() - [Low] rust: vfio: AlwaysRefCounted reaches into private vfio_device::device field -- commit 00c5e0b75ff0082149fe02d0ba3c927a81f1b2c9 Author: Zhi Wang rust: vfio: add common VFIO device handling This commit adds the core Rust VFIO device abstraction (DeviceBase and Device), along with callback context types, registration and open data storage, reference counting, and InfoCap. > diff --git a/rust/kernel/vfio.rs b/rust/kernel/vfio.rs > new file mode 100644 > index 0000000000000..30a593634a72b > --- /dev/null > +++ b/rust/kernel/vfio.rs > @@ -0,0 +1,357 @@ [ ... ] > + unsafe fn init(this: *mut Self) { > + // SAFETY: The caller provides exclusive access to a suitable al= location. > + // INVARIANT: No data is published, and no open data exists. > + unsafe { > + (&raw mut (*this).data).write(CallbackData { > + reg_data: UnsafeCell::new(None), > + open_data: UnsafeCell::new(None), > + }) > + }; > + // SAFETY: By the same reasoning above, `_context` can be writte= n. > + unsafe { (&raw mut (*this)._context).write(PhantomData) }; > + } [Severity: Low] Should DeviceBase::init(), DeviceBase::publish_registration_data(), and DeviceBase::callback_data() be marked #[inline]? Kernel crate convention is to mark small abstraction helpers #[inline], matching the other small helpers in this module. [ ... ] > + let open_data =3D unsafe { *self.data.open_data.get() } > + .expect("VFIO OpenData is expected to be populated."); > + // SAFETY: By the same reasoning above, the registration data is= valid for this callback. > + let reg_data =3D unsafe { reg_data.as_ref() }; > + // SAFETY: By the same reasoning above, the open data is valid f= or this callback. > + let open_data =3D unsafe { open_data.as_ref() }; > + // SAFETY: By the same reasoning above, the open data is pinned = until the last close. > + (reg_data, unsafe { Pin::new_unchecked(open_data) }) [Severity: Low] Should callback_data() borrow open_data via Pin::>>::borrow() instead of dereferencing the raw pointer directly? DeviceBase::open() produces this pointer with ForeignOwnable::into_foreign(), which documents that using the pointer outside from_foreign(), try_from_foreign(), borrow(), or borrow_mut() can cause undefined behavior. Calling borrow(open_data.as_ptr().cast()) matches close()'s use of from_foreign() and avoids relying on Pin>'s internal pointer representation. [ ... ] > +// SAFETY: VFIO uses the embedded class device's refcount to own the ful= l allocation. > +unsafe impl AlwaysRefCounted for DeviceBase { > + #[inline] > + fn inc_ref(&self) { > + // SAFETY: A shared reference keeps the initialized VFIO device = alive. > + unsafe { bindings::get_device(&raw mut (*self.as_raw_vfio()).dev= ice) }; > + } > + > + #[inline] > + unsafe fn dec_ref(obj: NonNull) { > + // By the type invariants, `Raw` begins with its `vfio_device`, = and `raw` is the first > + // field of `Self`. > + let vdev =3D obj.as_ptr().cast::(); > + // SAFETY: The caller owns the VFIO reference being released. > + unsafe { bindings::put_device(&raw mut (*vdev).device) }; > + } > +} [Severity: Low] Should AlwaysRefCounted avoid reaching into struct vfio_device::device directly? In include/linux/vfio.h, vfio_device::device is marked private and not for driver use, and vfio_put_device() is already the public release helper. Bypassing it risks silently diverging if VFIO changes its internal refcounting or adds logic to vfio_put_device(). Adding a paired vfio_get_device() helper in include/linux/vfio.h and wrapping both via rust/helpers/vfio.c would keep this within the public VFIO API. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204041727.4021= 092-1-xinmengs@nvidia.com?part=3D2