From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64288606A337 for ; Sat, 5 Dec 2026 04:19:16 +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 kanga.kvack.org (Postfix) id 6C1E46B05B1; Fri, 4 Dec 2026 23:19:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 671F76B05B2; Fri, 4 Dec 2026 23:19:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58B096B05B5; Fri, 4 Dec 2026 23:19:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D4B6D6B05B1 for ; Fri, 4 Dec 2026 23:19:09 -0500 (EST) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 582DDA020C for ; Sat, 5 Dec 2026 04:19:09 +0000 (UTC) X-FDA: 85508624418.28.9B3099D Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf21.hostedemail.com (Postfix) with ESMTP id BDDD21C0006 for ; Sat, 5 Dec 2026 04:19:07 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=NXTnEdiF; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796444347; b=8TL5TLZc4x79V9HV6Kub4gewlm8OlqLhMOI9CXldvEY05VKFAzIKuPDVud4GZyuXHfH7Ih UGPoOfj1n+FXsjLjikLUNFBQnW/PAMb46OGOEXpOwuubvAa47d9RNAuQ5gI40UxArIPbRV b8SxgiLx3riReYcN40JzYTg275+iCvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796444347; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IpLpgJ6d7akMB40Bp8Ehv1ak6+N7RayHID1hvDkkhlw=; b=ydLtoxHdLrFjn3TivlCoGGwISW20TKKWzBtIiXzkLM2TIArHibU1d+ncRlzlvZ8LhS691f MLxEPZD7upQ9MYJpy0I9pudkOZ/RBim3a4NgubCK4/Mtc1z7rgfo3b4qiHK5phyvnjzAMs gVl4bF8mdgCBucGnWhQI5Hwc8+p/XzI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=NXTnEdiF; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 5981261498; Sat, 5 Dec 2026 04:19:07 +0000 (UTC) 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BDDD21C0006 X-Stat-Signature: z661z6obdwi71ur9rxr3u1njqxtpwe7k X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796444347-327182 X-HE-Meta: U2FsdGVkX1+H8+BJwp7d+Q8GLZwkZrlrvsOxIUwzCbDrdRvXyjqNZoq4aA6F/AScMjFF+Q73Qor4KShFBmqK+MBQa/KZGpyAKTmUR43vWigN/KsDplE8I6u3SaDsYgvTmWMchDVbFyotFEXawTt5KTwELHEKZeIFadiQoERtybWFyBZ6L9EI62b3I0ZRAr99URyS0X1MXzOVuhF9Nw6s3pMBef4Fm9J5Q2SqVmFMOOV5f/WCK0DP2hS8Jb55kt2nHP5s/r54fHPRBtqnfhKUc9lkqn8tyia5zvC6ESq1ZDDkd+qB9zqYJbSU46PVQZvTgP2JKwgarZOXgu+2Ba5C+OApjEDEUiMhLSHSTs6/UdeBB8XQxNKUJR7VtQ8aOtPkxOZ60Nzb04+kn2j2H0b4piT860Nu2cCXRvYXd1tZoPfpw9zmcF4xbr+GiAt7az/XOsJqj8HHushT65v15Rep31atmviu3lLB9BGdrN+xbMJPgX4PYZvh/ZA80bddbMaJ4YwijMKiKaVCdwAEDW+XBhVCwBxg9nm0IFzoDrs4pq7Tp+Lh2GznIWbuUrcHnMDTvjyPbKuQwEdjlpD+YreB/vdRGNWdYRdLvQBH2rq2epW0ZF0yGzUMDMZufV4tAGY5ymEfrU+rK8pl/E7ynUk1TdwYVo8MKgIoFz3LhL2eO6wkXeoOBIuNDOsWsHKanx+pxyal4SyXL4XsOIT8Kpml8SCq0Hl2SHd+LtB2UvjCEn3M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c9ZuFVJ/kGuLxGKjN96pNDolsjqhgIKW4XNjoOKk1nQcPOphrs34Qg2+NDpRP/3UN4UgU88= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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