From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.100.110 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796236996; b=kyALfT+orKYxKZLBh6e+ATq4MI5lI23ghySCvAWgjd/vHCTdO0oUOa0sxivY16xiHrVS eM6+waNh2SzI+IGHeUTqd//Ef++nulNswqcnayaejTzyuI+ODO46OFSIk/MwUA4uFDuFf iPGIpGAyxjtXkPWz9UM9PjSLzSmJcmQKjbLKhVfb5uWt6C4NJ5WB8cQ5tPbQPCMuKqtW6 dP7Utv18KJTPLLvZHvxZQYIc4vf7A41M37MLuv8+KOv463ly75XaHF/GH2EcrlX48hrqV bUfW/9kwjBPwoaFD0N5OxudkyMrRaytmPDNYxa7JUFW0yfR2/dO0Ja7J/XA0/cixPYg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796236996; h=DMARC-Filter:DKIM-Signature:Received:Received: Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:From: To:Cc:X-Mailer:References:In-Reply-To:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=vv39kbQHDV7j4sQeIxIFJb1KOj5ghe2cEqYBcgGUAjs=; b=XV8hIShpkDBhQbeECfDSTfcCDmbxEIcoZK4nM0VOCABJyl2Lnl/ozxPNI8KQSX93uYjy vow6LEdlMT3dvog/ob/RIQyKwK1DUarxbqixr/pIqT8XYHv60uCcXnX6UCnGhFSomB/rH Oq9JP8cSYrk+C2WSUCwqOUXBFqxcXHDZqZuMvZlvUWxZPoOG2lpT1GCiBxpjGk8XEr8JB wLhbAe4C12ldv4NcvzhIqm3oxRuAjCWhQVbPo9gwdj0ns9CAHy/DaGJ1ftK9VApdP+BUq WJv1j7MP73v4J4KQzFxDNRyxbqiU0xx2omUf+LTWHN3JDKtHAe/pPj+eUAC/8XbZNvA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=ioOkWyJu; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.100.110 Received: from CWXP265CU009.outbound.protection.outlook.com (mail-ukwestazon11021110.outbound.protection.outlook.com [52.101.100.110]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B8AF606A6B8; Wed, 2 Dec 2026 18:43:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B8AF606A6B8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=ioOkWyJu ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oPVf+8GpDBz2TM1LkYHh1RZ7UESV3EUdcyPbkUhA0YkQ70ffppMAC5d3onoLEXLFVMgSoqU2RrSCwXwHS2jcKHtaCnw+oxrPMJ+li01xgRnTUwRUb93HORWPYbZnNnvhDtcN1pG8AoEgVOSE4QuMJi/vFm/JDxbctG8uLqYtGK69b4P8+JrX3Cy31ocRYN3bmky5K6PRpDB9M2BcUBIkJk+GnFwRpGKTl/ChHpANU0BOUe6OXHyTrE2/zggVJdV3gk5DgWaWBldpCOyaJ0uo/z76wnSTLV/vkHCRpjeRIwsIx5WIfi8hMinttsj+rH0WSkC9OfGWaXlQnG30IcUNBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vv39kbQHDV7j4sQeIxIFJb1KOj5ghe2cEqYBcgGUAjs=; b=wSrU4snkVKYHmpBtJnLom2WkFkoXlf4iIE+XHjJAzDSUZ5zAIt0OICVZWpimC42T5B4v+4fwrqUyMCZ0I20CiBXuor1NIiUcpXt262z6ZJYWvaChJ/cDa36orSIDLouNzoANsPFR+Dz9uJSywcTu3ReyvuamZkXI3ELUOaSLG9ABW+U/Tq1RMjlSdwV+dEfzKptZvLoHok2cM6VQ9aUU7i9QNLJyvHUWex8bC/WorjxcF3TVinvt/B6CExJ47VvuTC8fgrWHwstdUkjrs61fMU3zm5ZjUC3qJUbWpaE9JrLEL2yMjJ1UUVW+pKfx6Q6enZ4iQ2BigFlQiXGGvmqbLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vv39kbQHDV7j4sQeIxIFJb1KOj5ghe2cEqYBcgGUAjs=; b=ioOkWyJuGUmsnDDLBk3mQKxYNXGqnUpZzMNaGfVAkfjurSif2m1M2EVg/8BOo5oULloX1aVxqXzAV42S17QECBFRSnAJoY99BHqMYeaPbjvtprx/uJPZG4BM+1pQqtaZd946E1cV9yXKiC3qC8FF6nVN0MguZd+LySRCc1+Tjw0= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) by CWLP265MB3364.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:d7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 18:43:04 +0000 Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3]) by CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3%2]) with mapi id 15.21.0688.010; Wed, 2 Dec 2026 18:43:04 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Dec 2026 18:43:03 +0000 Message-Id: Subject: Re: [PATCH v4 1/5] rust: vfio: add common VFIO device handling From: "Gary Guo" To: "Danilo Krummrich" , "Gary Guo" Cc: "Simon Song" , , , , , , "Zhi Wang" , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "Liam R. Howlett" , , "Lorenzo Stoakes" X-Mailer: aerc 0.22.0 References: <20261127224928.1511382-1-xinmengs@nvidia.com> <20261127224928.1511382-2-xinmengs@nvidia.com> In-Reply-To: X-ClientProxiedBy: LO0P265CA0014.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::16) To CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP265MB6051:EE_|CWLP265MB3364:EE_ X-MS-Office365-Filtering-Correlation-Id: e90378ef-9142-4881-700d-08df50a4196b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|10070799003|366016|1800799024|376014|7416014|4143699003|6133799003|261009223027099003|22082099003|18002099003|56012099006|261028144727099003|261026121527099003|261102123227099003|261022105027099003|261021121427099003|261022075727099003|10067099003|261026140227099003; X-Microsoft-Antispam-Message-Info: tzQLBl/pKK+COK1xskNfwt41gVUnzNBBuuk3uFan6fMh/kSPkNip+ktRNAyZhioreYF+bV5hvL4pt1ydVNI2bgugHN4Thlpd5TPLhEhn1nmJTnNep47awy28oCyIVw0gpqW32WOBPcwWqJUkXPqgEL/22bZWotwaxbfUsxp36O04TVlkN/gj7Jt4X/Gw0cNdZIk8C66nZjLjsH3xdhYql4C+dpBKEYCwWKKJA7PIPjHyxbuRf3e7hNq8+O4suxUYWDfyNp8RFB8ZYsQoH1dmma+V7sBTROi7y3+QThTfkaH/dOytBtz9lxGhx+hVkiY5DPKvNTu9Un8VmwkL773D34uL0RN8cRRHp8z8iW4N0w07R1saMFrWOgKNisthq5opnEU6aubZJQMowjc2NCHQi2ZpYl2woB//cg+M7WnQat3so4uG6fgHXKJ5M0Pd7YFG7o/LA3fB6D8JlZKzhfZzLuf579lL6YBMZrXptp/cr+b8MV/WyXXQwRsN8/C4QhWn6xHUiPtCvv4pIgrVOG/jHkVaBzZsyqjqQfn2vgVYuwUeWDHrOjPaBTTm64kr5YpRT8Ax8ulH8VQboTgck1BOQyBdh4Cvkd7ndbBSvp1c/jVpK1J7lEJAjboozmhfEhJSVS2w8coCthZNcdGE7Cr6eCeRLvZLJK8NVyyBYw4JV2Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(10070799003)(366016)(1800799024)(376014)(7416014)(4143699003)(6133799003)(261009223027099003)(22082099003)(18002099003)(56012099006)(261028144727099003)(261026121527099003)(261102123227099003)(261022105027099003)(261021121427099003)(261022075727099003)(10067099003)(261026140227099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?a0x4VjB2NFNxQm1iSFhaeFpPd0hGREFzUU1TdmdGbDR2VmxSa1A0c0hwSjNY?= =?utf-8?B?U1BOdm05SlRwc1J2c0lNbHI0Y1VGOE9pRmxmbkp6aWsvSzNLTFE0L1haTDcw?= =?utf-8?B?VnpuY1N0MnlDYXI4anJZdTBLUEtVS2p1ZU95Ky9oamZJaWR6dGNFdGFXamN1?= =?utf-8?B?a3NpQjUzQlF0eHM5OUNaR1RnZGdPV0MvbWJYc2pXSHMvNWFrKzFFS2FuLy96?= =?utf-8?B?cUVWVk1qS3RxOWk3d3pIWnF6eE1rZFNhQzFCYTloWnpiU3E0eEt1OFEzT1Ez?= =?utf-8?B?MzQzNTc5VjFIMmNXdkxGRUR4VkJ1NXE4NnZYUzlMcVh5am1TVTF2eVd2bC9M?= =?utf-8?B?aUtYZ1daRG1wVjhpbUpKQ1Y4UTc3K2VNa2NBWW9OU2xTNXcwUElFUDhUSE9R?= =?utf-8?B?bzFjd2l4UHV4R2xueXBDTkxBY1NEZEt6TnpKVWlQOHVKQ0xBd01EZlc4dGZN?= =?utf-8?B?U3dTTEJKQk9zNDNVeGNrMVF6WTZ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-8?B?alM4WHBKOW15SDdYeGFJNXJZZUh0ak1GWURjVWI5Skh5bFdMUjlhZz09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: e90378ef-9142-4881-700d-08df50a4196b X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 18:43:04.2569 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XfrVCvIpp9uu+xzS6TrcX6Kapq6u6I2jqCghvVPubn0QfT/CljkLYlvxe+K4y392mNnfrOnV2WPYFBM9Y6aeWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB3364 On Wed Dec 2, 2026 at 5:55 PM GMT, Danilo Krummrich wrote: > On Wed Dec 2, 2026 at 4:58 PM CET, Gary Guo wrote: >> On Fri Nov 27, 2026 at 10:49 PM GMT, Simon Song wrote: >>> rust/bindings/bindings_helper.h | 2 + >>> rust/kernel/lib.rs | 2 + >>> rust/kernel/vfio.rs | 454 ++++++++++++++++++++++++++++++++ > >>> +/// The data the driver of a [`Device`] shares with its callbacks. >>> +/// >>> +/// Bus-specific operations traits extend this trait. >>> +pub trait Operations: Sized + Send + Sync + 'static { >>> + /// Data owned by the registration and passed to VFIO callbacks. >>> + /// >>> + /// It can borrow resources of the driver's binding for `'reg`. Pe= r-device state lives here. >>> + type RegistrationData<'reg>: Send + Sync + 'reg; >>> + >>> + /// Data shared by callbacks from the first successful open until = the last close. >>> + /// >>> + /// It can borrow the registration data, of lifetime `'reg`, for `= 'open`. >>> + type OpenData<'open, 'reg: 'open>: Send + Sync + 'open; >> >> The lifetime here is confusing. `'open` is actually the lifetime borrowe= d from >> `'reg`, and the `'reg` is lifetime borrowed (usually) from the device. > > I think it's reasonable if this is read as 'reg is the lifetime Registrat= ionData > is constrained by and 'open is the lifetime OpenData is constrained by; s= ince > OpenData may borrow RegistrationData, we require 'reg: 'open. > > With that reading, I think the above shouldn't say "the registration data= , of > lifetime `'reg`" though, as this is misleading. > > That said, I can see why you say it is confusing if you read it as "borro= ws". > > In this case we'd probably want something like > > type RegistrationData<'a>: Send + Sync + 'a; > > type OpenData<'reg, 'a: 'reg>: Send + Sync + 'reg; > > 'a is usually the lifetime of borrowed device resources, so it could also= be > called 'res. That's okay to me. > > I'm fine with both; but in case of the latter I'd probably prefer 'res ov= er 'a. > >>> +#[expect(dead_code)] >>> +impl DeviceBase { >>> + /// Publishes the registration data passed to callbacks. >>> + /// >>> + /// Returns [`EBUSY`] if registration data has been published befo= re, so that a device can >>> + /// be registered at most once. >>> + /// >>> + /// # Safety >>> + /// >>> + /// The caller must serialize calls for this device. `data` must p= oint to pinned data that >>> + /// remains valid until the device has been unregistered or, if re= gistration fails, is not >>> + /// accessed through this device. >>> + unsafe fn publish_registration_data<'reg>( >>> + &self, >>> + data: NonNull>, >>> + ) -> Result { >>> + // SAFETY: The caller serializes publication, and callbacks on= ly read the slot. >>> + if unsafe { (*self.data.reg_data.get()).is_some() } { >>> + return Err(EBUSY); >>> + } >> >> This looks quite strange. >> >> I believe this is only here so you can never call `Registration::new()` = twice. >> But this raises the question on why you'd want the user to create the de= vice >> first before giving it to the registration. >> >> I think this should be one of the either approach: >> >> - Never allow user to create the device directly. Create it inside regis= tration >> and expose it to the user via registration only. >> >> - (drm approach) If there're some configuration needed on the device bef= ore >> registering, create a `UnregisteredDevice` (or `UnpublishedRegistratio= n`) >> type. It is then converted to a `Registration`. > > I think this is fair and in my PoC I did it that way to make it a bit mor= e > accessible reading it coming from C; I think it should be the former for = now. >From patch 5 it does seem that there's no use case currently for an unregis= tered device, so yeah we should go for first approach (even if we need to do configruation on unregistered device, we can add that while keeping the dir= ect registration creation as a shorthand). > >>> +/// Opaque wrapper around a `char __user *` buffer from a VFIO read or= write callback. >>> +/// >>> +/// Provides bounds-checked copying of kernel data into the user-space= buffer. >>> +/// >>> +/// This type cannot be constructed by driver code =E2=80=94 it is onl= y created by the >>> +/// callback trampoline. >>> +pub struct UserBuf { >>> + ptr: UserPtr, >>> + count: usize, >>> +} >> >> No ad-hoc infrastructure for what's supposed to be in uaccess please. Th= is looks >> like like it should just be `User<[u8]>` (the generic user pointer type = that >> integrates with I/O projection); I have that in my plan and I can priori= tize it. > > IIRC, I did bring this up previously too. I don't think adding the User t= ype > should be a blocker for this series though. > > We should be able to pass a UserSlice in the callbacks and take it from t= here > with UserSliceReader and UserSliceWriter, e.g. with core_read() taking a > UserSliceWriter as argument. > > The only change we need in uaccess is something like this: > > diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs > index f1aecda7a90c..5e95d017b52e 100644 > --- a/rust/kernel/uaccess.rs > +++ b/rust/kernel/uaccess.rs > @@ -15,7 +15,13 @@ > ptr::KnownSize, > transmute::{AsBytes, FromBytes}, > }; > -use core::mem::{size_of, MaybeUninit}; > +use core::{ > + cmp, > + mem::{ > + size_of, > + MaybeUninit, // > + }, // > +}; > =20 > /// A pointer into userspace. > /// > @@ -217,6 +223,16 @@ pub struct UserSliceReader { > } > =20 > impl UserSliceReader { > + /// Returns the current userspace pointer. > + pub(crate) fn as_ptr(&self) -> UserPtr { > + self.ptr > + } > + > + /// Limits the remaining buffer to at most `length` bytes, keeping i= ts current address. > + pub fn truncate(&mut self, length: usize) { > + self.length =3D cmp::min(self.length, length); > + } > + > /// Skip the provided number of bytes. > /// > /// Returns an error if skipping more than the length of the buffer. > @@ -449,6 +465,25 @@ pub struct UserSliceWriter { > } > =20 > impl UserSliceWriter { > + /// Returns the current userspace pointer. > + pub(crate) fn as_ptr(&self) -> UserPtr { > + self.ptr > + } > + > + /// Limits the remaining buffer to at most `length` bytes, keeping i= ts current address. > + pub fn truncate(&mut self, length: usize) { > + self.length =3D cmp::min(self.length, length); > + } > + > + /// Skips the provided number of bytes without writing to them. > + /// > + /// Returns an error if skipping more than the length of the buffer. > + pub fn skip(&mut self, num_skip: usize) -> Result { > + self.length =3D self.length.checked_sub(num_skip).ok_or(EFAULT)?= ; > + self.ptr =3D self.as_ptr().wrapping_byte_add(num_skip); > + Ok(()) > + } > + > /// Returns the amount of space remaining in this buffer. > /// > /// Note that even writing less than this number of bytes may fail. So there's no need to actually do read/write at arbitrary position? The exi= sting helpers added feel like it's needed. Also, I don't understand the name `read_overlapping` and `write_overlapping= ` as currently defined in the patch. But if vfio can work with the diff above that you have, I think that's reasonable addition to unblock the series (with `#[inline]` added, that is)= . Best, Gary