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=40.93.194.49 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796315201; b=T/B6VySf/m8mO5Tis6bJ+DXGp8Jq8wHrDWTJqItU2w+CHdnQYMHq5TXneJeyz4DRT4fA fEaQ8iCwkqH8/vcB4+NIRo0AfKO0+nShz1Z9vbWOriEI04GXfbkESh42ElBQWtM44WwAk yWR3W2aDNxGHs/xAG8/sGSHiHR7fL0d6S9ynfnDKeCuANDH2jL8k9gEU+cEIzALGUCZ/I vBE5PM4arZrDjhBNpHk4SFQ1MniwGx2TK8jOEkalhDgAdGl8Gayhop1tsZm0rJHoAdtFC RdSXXnH9TrmNkHmJd8KNs7fY5ZBM7+j6Rnh6EkDDembTNjJDnUUbEKHRfbUj/NB32zw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796315201; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding: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=G9pY7nA9EUY1SD6ykJudfsftobH2FJ+lzs0UpWOCVSk=; b=Oroidfb4xdcF81+3xwzRZjjC7k/ZQV0YjpzXQ5QOlT1BfGrAxBcoD7xXJtDy9G9ca3VI V5aAxynyb3FPvWnR8SMK+WQfznZrxfHfF4VZwfmVBEYkMlEXsvJ3bWc6fqUBKJlE97I9M QrPv1mdz4PmXBHmfBnP/jupIPkHYdiSCA1EbHktfjkq2tV0otyecIkUpZxVq1O5AW5dNi zAVnlAGZQxrlxI2JCVkP38gvwmYO4C+pvKJ9hDOD8N3gFMCFhnkg86pydUsfMVqTed/aF 8iOTF+yOi53ZLPhGC0w/TBbWGmJ1za/uzVa3/4PijPGl0ddlC5rl3Mx8WhZXXof3myQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=V7kY9fHA; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.194.49 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011049.outbound.protection.outlook.com [40.93.194.49]) (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 9ADB1606A336; Thu, 3 Dec 2026 16:26:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9ADB1606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=V7kY9fHA ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nXtuYy8Z/4EUzz2JBEYAOecdRk4VQ+g571WGmwDeT/RJQSwcH1AZB0jjPndEW9lsrcCtHqYm0tp9QZ/GO82XRlT573t19CVJZeVRyAx/RCfNb7BbXbUuBwyqvST9vHVgRXiI+SwQ2RlYP8g3aRCpaX5P3KPUheETq9MOsXQE13EQ5QzaPlQJfrd+T7KdvoDsOC4pAeVsa65BcnMhVXeGw8qJfr3dtcXWKV4vTau35t4Tuh9Dg8gbP7QLXRS1KI/0fkAYyKCnTCbVnlume56eOcNS4jttrBnHoLSY3Ym0czGAqamX+h569iAoFgCQ8hsrr4yEIAJH/BaxaaEwGRDu8A== 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=G9pY7nA9EUY1SD6ykJudfsftobH2FJ+lzs0UpWOCVSk=; b=QkjhtmdlUedXS/NV2U05c+OKGOJ2sO1JCN5twO/ranYXJtiuKbtCcXaU1/rmxgTwaLZu0M4XlIa2Yfj792dlzKZ+gOZMC5VnTR5aCvlcq5yimOTNhZJKBuQAwKBzALCSPFpQT3dHFtwh7XdJjGPOYHQrn6HT8i0K1RI7p12JICY45TmCB4Elv2yUh8CEnF6iFgQab4zTQMGVP85Vu+bBxm+CF/2N0tcIIn1L6NhgTScx64PMvuKrbAdnKWoDw6ExA7hQFXx83yVb92XYCWTmX9zGYp8hN7/zn8XQUBjM4FoxXzO8jo+SH7vMWddMCsvqMy4ZngAajDYdKXdzJmVtyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G9pY7nA9EUY1SD6ykJudfsftobH2FJ+lzs0UpWOCVSk=; b=V7kY9fHAzRPWXD/AnWD2qb7Ipk2izGwzPSJ7zipgyiFNhuB+HpyoIIqHdXYOVH4eiODq88ffYnFuUZGE3uw3EGK/tmlQOtPbAouUfILguigBEcfW9iKi+Bv2IZ7beoDsAS+7rlhVlrD7inWV74tEXMosYbZcpAGGLrmKTQoFDTZru4OsTFzn+7UJ87hUF4GDSyLtYs1NrLvou4lxBVxUOQ6hRHwuPgcPmoe/QAdzxoRasM6g7I6ziruggMQW9r10rb2DjcHleSAabqv+6MPwidpJ6fwZil208bQfu9U7p5XKBcgSnjNjxwIWjDISo8ny2zX8ymY5RwWmZSQcfbtlMQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6549.namprd12.prod.outlook.com (2603:10b6:930:43::6) by SA1PR12MB7344.namprd12.prod.outlook.com (2603:10b6:806:2b7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Thu, 3 Dec 2026 16:26:35 +0000 Received: from CY5PR12MB6549.namprd12.prod.outlook.com ([fe80::2cdd:a549:db13:202b]) by CY5PR12MB6549.namprd12.prod.outlook.com ([fe80::2cdd:a549:db13:202b%4]) with mapi id 15.21.0688.009; Thu, 3 Dec 2026 16:26:35 +0000 Message-ID: <30de192f-8bc5-421f-9dd8-c1054a13575d@nvidia.com> Date: Thu, 3 Dec 2026 11:26:25 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/5] rust: vfio: add common VFIO device handling To: Gary Guo , Danilo Krummrich Cc: acourbot@nvidia.com, kvm@vger.kernel.org, rust-for-linux@vger.kernel.org, nova-gpu@lists.linux.dev, linux-pci@vger.kernel.org, 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, 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, linux-kernel@vger.kernel.org, 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 References: <20261127224928.1511382-1-xinmengs@nvidia.com> <20261127224928.1511382-2-xinmengs@nvidia.com> Content-Language: en-US From: Simon Song In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR05CA0088.namprd05.prod.outlook.com (2603:10b6:a03:332::33) To CY5PR12MB6549.namprd12.prod.outlook.com (2603:10b6:930:43::6) X-Mailing-List: linux-kernel@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: CY5PR12MB6549:EE_|SA1PR12MB7344:EE_ X-MS-Office365-Filtering-Correlation-Id: e2182c6a-e3fa-4c81-5af3-08df515a3281 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|7416014|376014|366016|1800799024|261028144727099003|261026121527099003|261102123227099003|261022105027099003|261022075727099003|261026140227099003|261021121427099003|11063799006|4143699003|56012099006|10067099003|261009223027099003|18002099003|22082099003|6133799003; X-Microsoft-Antispam-Message-Info: UpBJJBvFzd31KOxoluE1CcSdSGIX+l4ooc9JzlfkgJuLbME963c4J8iFokWdpppctGCAreT38Z616uSIdVHrJXi0l+1PnE/8moJvQ+3xpFyhwMPDBNvDCNGi0iSOSLcrdU8ZVJhGniEVi1NfDZ7G3xd/JLNx40tGo+AZLbN9RI+3yyLB3DtdbIKCzsJG0uaHliYA5Cr0LawMBNJDL79PKaVYiD75oM6laWix3nkNSYBvgnjz9jqExSze8EVCpnCrO+miEhJAgASPepP5kn1ZiKO/HJynl0Q/P62rfobQuL1+wbmlAOTFmqGcKl4MXkoLXl1XtKz/H2oqFRefmJjRvejak0GFKt4uj4lI5qIgkPN1BLYOvs/2zM8yOND4oC4w4jWvylDtjiAtSBcPf/ZP8a9amX6gsm44bANO1eufcXGGi+gqQK/v03yRm/Q5/Jl9l8NXCuuaA3B5Ygz+CripXnwElf3gFBL9ELG6mHtNCRS/08A5mCgxYJld/JZQgT9NUweA0yF6VIzrppchYbtdiWurZjC9mGkuo9OAz1esMS6N5hRZNaMcsc9j3Ocjj9XRZf9FNWAs0AYrFA0rbI3Kw9kJnd01TwVJq7/JFuqZMbAT/ZLx3zMhccntTmlQX89GiXERkAsRBm5wTX3llUf7mkU9bJwt55IgDmgmhn9pIg8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6549.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(7416014)(376014)(366016)(1800799024)(261028144727099003)(261026121527099003)(261102123227099003)(261022105027099003)(261022075727099003)(261026140227099003)(261021121427099003)(11063799006)(4143699003)(56012099006)(10067099003)(261009223027099003)(18002099003)(22082099003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-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TW16VHdyenQ1VkpNMmNpQ0N3YUNib241VHJaQ29KRUx2Q2M5VGFaTUkr?= =?utf-8?B?K1pjN0dRTHorb2dHMGRmaitBYTc0REJ2UjdyQnF6cGtUNDlHTHFFd3VYOUNL?= =?utf-8?B?b0c5UkNCa0IxNWtWOFB4TkJCR2VCNlpIL1lQZ0Z3dkZiL2Jkc2RjV0Q2THdD?= =?utf-8?B?RTJUL3RQUWVReitmMHhMeG9aenBMdDdlV0RpRDZDQldhajZBdkZNc0NERHp1?= =?utf-8?B?eDlEQzgrL1k5K2IySGFRNml6TXp6Qjl4OWZGK0ZKTzhxU1lYOE05Y2JvMnBD?= =?utf-8?B?R1A2Q3NHMGFDT1ZEZG15aDQvdHk1TEdYRXd1bWF6M1ZiMlBxeURCeVRaU3B2?= =?utf-8?B?TCtPMEtBa1hhR1g1Q1VPYVF5RGpGOVgrL3hBNHBVQkw2eUhLclFRLzlWL1gv?= =?utf-8?B?QU5ER21BN0ZWZkgyaEI1Vi9pZmd1ajVYeTdFbkgwdXFmMHNRckJxN2tRQ3J5?= =?utf-8?B?NDBSSWhXOFlDMytLL0IrcDV3UW5wSGpiU3VibDVNcGx5WFBuc2NNVHVUdkc5?= =?utf-8?B?WDNUcVNSWGluNk01RnVDY1ZZNXh3WVRMYjIwa3BONEF3WnpOVVNzdz09?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2182c6a-e3fa-4c81-5af3-08df515a3281 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6549.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 16:26:34.8573 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: q5/ppJUd0U1Gf4cUJi9wMT7qfi7Ykpoc8L/PVNjPSee2xEuQio9m0Ej+dFKbxEb9qAwFpJWYKAudTz8Mn1cVrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7344 On 12/2/2026 1:43 PM, Gary Guo wrote: > 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`. Per-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 borrowed 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 RegistrationData >> is constrained by and 'open is the lifetime OpenData is constrained by; since >> 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 "borrows". >> >> 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. will rename to 'res / 'reg > >> >> I'm fine with both; but in case of the latter I'd probably prefer 'res over 'a. >> >>>> +#[expect(dead_code)] >>>> +impl DeviceBase { >>>> + /// Publishes the registration data passed to callbacks. >>>> + /// >>>> + /// Returns [`EBUSY`] if registration data has been published before, so that a device can >>>> + /// be registered at most once. >>>> + /// >>>> + /// # Safety >>>> + /// >>>> + /// The caller must serialize calls for this device. `data` must point to pinned data that >>>> + /// remains valid until the device has been unregistered or, if registration fails, is not >>>> + /// accessed through this device. >>>> + unsafe fn publish_registration_data<'reg>( >>>> + &self, >>>> + data: NonNull>, >>>> + ) -> Result { >>>> + // SAFETY: The caller serializes publication, and callbacks only 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 device >>> 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 registration >>> and expose it to the user via registration only. >>> >>> - (drm approach) If there're some configuration needed on the device before >>> registering, create a `UnregisteredDevice` (or `UnpublishedRegistration`) >>> 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 more >> 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 unregistered > 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 direct > registration creation as a shorthand). > for the respin, will make Device::new() internal and allow Registration::new() allocate the device itself this also gets rid of the EBUSY path in publish_registration_data() since it cannot fail >> >>>> +/// 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 — it is only 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. This 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 prioritize it. >> >> IIRC, I did bring this up previously too. I don't think adding the User type >> should be a blocker for this series though. >> >> We should be able to pass a UserSlice in the callbacks and take it from there >> 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, // >> + }, // >> +}; >> >> /// A pointer into userspace. >> /// >> @@ -217,6 +223,16 @@ pub struct UserSliceReader { >> } >> >> 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 its current address. >> + pub fn truncate(&mut self, length: usize) { >> + self.length = 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 { >> } >> >> 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 its current address. >> + pub fn truncate(&mut self, length: usize) { >> + self.length = 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 = self.length.checked_sub(num_skip).ok_or(EFAULT)?; >> + self.ptr = 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 existing > 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 I will pick up this change by Danilo in next series, also I agree with Danilo that forward traversal will suffice for now, and will add the #[inline] as suggested.