From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012060.outbound.protection.outlook.com [40.107.200.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDC843546EA; Fri, 16 Oct 2026 01:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.60 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792115655; cv=fail; b=jlUONBHqTscXEKl4sEqQJg75j1JrVzBHqvMmzG0HslU27/UQixDLsH1XY02vdv4c+353x60GHDA23/79q/zr9RiC/dYdo1FWNU7/k/P1bM5VTRAp/ZRnluPr50+YgqG+Rm9xu1oqcEY/Ww7HMLIG6XS4eZDRojNcVb14hTn8qJo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792115655; c=relaxed/simple; bh=ZsY1+sCdLgjB+jk/p7j+bbsf9i0NkQcRJ1yn7U3/6cg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=s3LQCY0hqr0rzdzG04WgrPzPeLlLRtUJiQ2ZFFe84LsvqBi7sNDp+P8KEIFnk/S3dgTIJUuW1hsSel97RmWpKHnzkARepDe5vmY+pKH6AV1okwMh9K+Z4RHFTUXIIEgTBMelaxvi/Mq+8C2sDu5h/L+lhGZtOxF0UndFWYNatZo= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=GFwtAPFg; arc=fail smtp.client-ip=40.107.200.60 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) header.d=Nvidia.com header.i=@Nvidia.com header.b="GFwtAPFg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=warStiOefukf/Bq2ZAhrycFtpuP6bAxb5ML9CTi+sas38ToK5ZJVUvVvaoFVZzFQIMmPqAkIOuJtigVCADQ3bLpMo4bx1QMeNCnZnNdtgCQSEbXBKPhEInDwmK3DbOKoHNZz+9JapJm0qDvNc+tuL4we359eEPD3+8Az87gNmkX509S/o06nD7D9WmzQfurC5sU5Oe62Z7aKR5wUT9KgMhjDtkR5uF9wTdXhl2R4tzUEKxzy8mdhmwZVctLIslaxOMfV3g8AswlQsSJslqo0q7MulgfZCiq9m788RxP8S0/8cRUTlzy8JGGMlgcI5jOTxlIp3c5XNHituBueAquerw== 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=/NY0IHZdchcKP0cmNwiZFx5Xy9jJpcqnRjEOtOdqKnE=; b=evlKM9S+A09G5LiWEvgGtOT8b5PNEBVD+VSk6/u+ddI4de5OwTqHO4ECc3gyyr0AwGpOd0wM23SSQq+lJl3oqw10zS/J5rO5UKx6uqKmlWzX3kfaADrl20YeUWqFxO7uAfV63fyF+79ZPTSRx5EvJ5afzsV1foW45kcduckMeZehonUKn8jv+FthcGdnGxt512K0GU9/tXFEHSXlO56/tT7dUdQIUnFJy9B1X5rJ5vsidXbpoAQsyXh/QkMvwzH/mVt4KT4QNPebZNJ4AnkAromSFQPGfTXeYCqFY+Q140/MbqymszQiuEXHEuTevBoF02x4Gqv8t7/1NlLvTvm4Pg== 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=/NY0IHZdchcKP0cmNwiZFx5Xy9jJpcqnRjEOtOdqKnE=; b=GFwtAPFgDCcSyLzQujQCX188S1x0lxtre6x9qYsslpdX2Djnn5ziw6OALXfC+tiv+FoXGNhFiUBzjwY5vaGu55QX6Vxl9gX9KCRrwMSYfKLgXxsLrnvnfTcSpYN75QCJfhP8Iqr3lqRoaeK2c9O+Ou6smHpqWk0OmBg8P0Q19ml8Ao79oKSUVO05SeAYPySfa68oENzgwPdoUdPbdlHAql8IvGkbCV2xmTFkoNQZa6NlwcmQOLQ58ojEjPsmCMuH2fOQ4QwSAUFE0akSiQfhEG2J0fQUumVxmUffuFJueT5ydcySh0WFvvexe4/cuC8ItjEwpagSSJ5F9EqfTi+66g== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) by SA1PR12MB999230.namprd12.prod.outlook.com (2603:10b6:806:4de::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.522.14; Fri, 16 Oct 2026 01:54:11 +0000 Received: from DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa]) by DS0PR12MB6413.namprd12.prod.outlook.com ([fe80::e82a:6673:4142:37fa%5]) with mapi id 15.21.0496.021; Fri, 16 Oct 2026 01:54:10 +0000 From: Eliot Courtney Date: Fri, 16 Oct 2026 10:53:37 +0900 Subject: [PATCH v4 1/7] rust: alloc: add Vec::try_push_init and Vec::push_init Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261016-b4-nvkv-v4-1-e8b92b91aa5b@nvidia.com> References: <20261016-b4-nvkv-v4-0-e8b92b91aa5b@nvidia.com> In-Reply-To: <20261016-b4-nvkv-v4-0-e8b92b91aa5b@nvidia.com> To: Danilo Krummrich , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Uladzislau Rezki , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , David Airlie , Simona Vetter Cc: John Hubbard , Alistair Popple , Timur Tabi , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, Eliot Courtney X-Mailer: b4 0.15.2 X-ClientProxiedBy: TY6P301CA0025.JPNP301.PROD.OUTLOOK.COM (2603:1096:405:3bf::7) To DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB6413:EE_|SA1PR12MB999230:EE_ X-MS-Office365-Filtering-Correlation-Id: 81ece3d9-a7dc-4a88-50b6-08df2b285f30 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|23010399003|10070799003|366016|376014|6133799003|18002099003|10067099003|22082099003|921020|261009223027099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: XvqdtGf8hnJ1Z1LLNlTU03LRA8W3/TsrSCZk6lWGH4ql4BpX4acExDfaz2Nu2J4MoqDzZXZxbtCfO5EK8ddE2fSAFZm3bCdBYZNdkVZCSc4EbwQh4ZL0X1PGYqpTa7NfJlmVLATAVWwUmKmloGl+4LnRhvFNL0FXWKxC4SIqBBCPYU4Fm0+algwBxYN5TgIxsL/EoQAKRu/LZ8MEnubicCyiIYt62c2RmEkhkmsonrsaaH9yd++Vp2PAxXz/aspdxs9RqZGS/38feLOy8CpvhImSczmQnohxFK9ZiZ0qWJxeWyxhFgsAnxDoYK1wu6YDwYDjqPaIQr1jMwzZSSi4f/qejsOqG8mnGIxBqFEDNWBSVrjoxt8mJXtq7FY2yFwjrT8MakUR38iaVfW+zj9rRBGpInG/aDu0TbiJDAKgoXVIJ9WLuiYreNibroPxr4yXVkSKkwEv2a4AwOknHb8c5b3YwZae7QKGLJv3IHDvEukUel/9fux0prdFZh9Hg/UarShDl+CvmWz+44QZQ8rKUyHEyH3CX1sP+sMP4EXRw5K3Bi4vbKD7u9K8p3xcgHc4GsQKGOgaTcz3NC+2QymG+y9GZ1RzmqQTI+8I9IgRe6ShA8n7bHHDBAF4ZmSL9xCvvitlEkjL8mQY/B4Y4UdCzLQ0KQASp4IiY/91OmT8Fxz+lGuVoNYKvphqs485FWjdW4zq/ulgtvUIRHOOXXRtZg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB6413.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(23010399003)(10070799003)(366016)(376014)(6133799003)(18002099003)(10067099003)(22082099003)(921020)(261009223027099003)(11063799006)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VVpWbDlZeGxEdGZvSlNIMDBVVVNBbmdCNjJROXdDMTMvMDM0Q24rYm9HeWFJ?= =?utf-8?B?RGRQVG5VWTRqL0R3ZXBHdGxnODhxWmlaMGNFVFVsUDVCMXFFekpHZEg3NkZY?= =?utf-8?B?Qjc1aXJwTlExeC9HTEdTNUhVdjBuQWltbzk0Wno2dFA3Wld6UlBReD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RZWnhTQ0hlQThVZzA0ZWlRVzFlaWY4eU44S3U0Qjd4?= =?utf-8?B?a2NOTmg5bWZlUjdtUGlnbFYyMnlINm5Ycmo0SXBtM3FhUW9Oa2VVTUw0K3p1?= =?utf-8?B?eVFVdDA1N1RFaDZnT3VXU1ZoZEFvWlBwWFV3S2t2ZGYzRkVWNXMyd29VLzdv?= =?utf-8?B?Y2cydGsrbHV1Q09uSGdKMlp4eGFsTzZBQWc0Si9mVS9RdnBtazBVdlVod3FJ?= =?utf-8?B?QTArUXF5YWNWOE56Mkt4WEJhTmJkRWl0a3drbDlyWTVxaXpPVFJ1bzJPVWRQ?= =?utf-8?B?NE9pRXdsUlVBYnA3ZmUrSmdBbGtJS3A3T2JkWXhjMEhoSmQ0N1RTOGp1Q0ZP?= =?utf-8?B?U2JlSDlJMFJiaE9NQjFLbzExZCtycktzTDk5ZXc4Q1JYNkpzejNiTXB2aGcw?= =?utf-8?Q?SD1P5R9x5+rdezQ0aWV9XAYSv/wLbZjvzePf3XdqkYKNz?= X-MS-Exchange-AntiSpam-MessageData-1: LbLdUcsVAjOrFQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81ece3d9-a7dc-4a88-50b6-08df2b285f30 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB6413.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2026 01:54:10.6841 (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: YxY41xdi/YWAC8iq/5CzhScAbQM61F/jpat6YhhZZb7uu7orLUNQiuZVfU7mD8iBUmxQUkd2mTsB3sktdvYZQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB999230 Add `Vec::try_push_init` for fallible initializers (`impl Init`) and a new sum error type `TryPushInitError` that it returns. If allocation fails, it hands back the original initializer. A `From` impl for `Error` lets callers decay the `TryPushInitError` to a regular Error if they want. Add `Vec::push_init` which is the init-infallible version of `try_push_init`. Signed-off-by: Eliot Courtney --- rust/kernel/alloc/kvec.rs | 85 +++++++++++++++++++++++++++++++++++++++- rust/kernel/alloc/kvec/errors.rs | 30 ++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index c7546b9da4fa..c8b312f64657 100644 --- a/rust/kernel/alloc/kvec.rs +++ b/rust/kernel/alloc/kvec.rs @@ -52,10 +52,18 @@ }, // }; -use pin_init::Zeroable; +use pin_init::{ + Init, + Zeroable, // +}; mod errors; -pub use self::errors::{InsertError, PushError, RemoveError}; +pub use self::errors::{ + InsertError, + PushError, + RemoveError, + TryPushInitError, // +}; /// Create a [`KVec`] containing the arguments. /// @@ -359,6 +367,79 @@ pub fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError> { Ok(()) } + /// Appends an element to the back of the [`Vec`] instance by initializing it in place. + /// + /// # Examples + /// + /// ``` + /// use pin_init::init_zeroed; + /// + /// let mut v = KVec::<[u8; 200]>::new(); + /// v.push_init(init_zeroed(), GFP_KERNEL)?; + /// assert_eq!(v[0], [0; 200]); + /// # Ok::<(), Error>(()) + /// ``` + #[inline] + pub fn push_init(&mut self, init: impl Init, flags: Flags) -> Result<(), AllocError> { + self.try_push_init(init, flags) + .map_err(|TryPushInitError::AllocError(_)| AllocError) + } + + /// Appends an element to the back of the [`Vec`] instance by initializing it in place. + /// + /// Unlike [`Vec::push_init`], the initializer may be fallible. If the allocation fails, the + /// original initializer `init` is handed back in [`TryPushInitError::AllocError`]. If the + /// initializer itself fails, its error is returned in [`TryPushInitError::InitError`]. + /// + /// # Examples + /// + /// ``` + /// struct Element { + /// value: u8, + /// } + /// + /// impl Element { + /// fn new(value: u32) -> impl Init { + /// try_init!(Element { + /// value: u8::try_from(value)?, + /// }? Error) + /// } + /// } + /// + /// let mut v: KVec = KVec::new(); + /// v.try_push_init(Element::new(16), GFP_KERNEL)?; + /// assert_eq!(v[0].value, 16); + /// + /// // The initializer fails because 256 does not fit in a `u8`. + /// assert!(v.try_push_init(Element::new(256), GFP_KERNEL).is_err()); + /// assert_eq!(v.len(), 1); + /// # Ok::<(), Error>(()) + /// ``` + pub fn try_push_init( + &mut self, + init: I, + flags: Flags, + ) -> Result<(), TryPushInitError> + where + I: Init, + { + if self.reserve(1, flags).is_err() { + return Err(TryPushInitError::AllocError(init)); + } + // SAFETY: The call to `reserve` was successful, so there is at least one spare slot. + let slot = unsafe { self.spare_capacity_mut().get_unchecked_mut(0) }.as_mut_ptr(); + // SAFETY: + // - `slot` points to a spare slot, which is valid, uninitialized memory. + // - If `raw_try_init` fails, this returns without increasing the length or touching `slot`. + // - `init` implements `Init`, which removes the pinning requirement. + unsafe { pin_init::raw_try_init(slot, init) }.map_err(TryPushInitError::InitError)?; + // SAFETY: The call to `raw_try_init` returned `Ok`, so the first spare slot now holds an + // initialized `T`. The new length does not exceed the capacity because `reserve` ensured + // the capacity is greater than the length by at least one. + unsafe { self.inc_len(1) }; + Ok(()) + } + /// Appends an element to the back of the [`Vec`] instance without reallocating. /// /// Fails if the vector does not have capacity for the new element. diff --git a/rust/kernel/alloc/kvec/errors.rs b/rust/kernel/alloc/kvec/errors.rs index aaca6446516a..d24dfe22834a 100644 --- a/rust/kernel/alloc/kvec/errors.rs +++ b/rust/kernel/alloc/kvec/errors.rs @@ -25,6 +25,36 @@ fn from(_: PushError) -> Error { } } +/// Error type for [`Vec::try_push_init`]. +pub enum TryPushInitError { + /// The allocation failed. Hand the initializer back. + AllocError(I), + /// The initializer failed. + InitError(E), +} + +impl fmt::Debug for TryPushInitError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TryPushInitError::AllocError(_) => write!(f, "Failed to allocate"), + TryPushInitError::InitError(_) => write!(f, "Initializer failed"), + } + } +} + +impl From> for Error +where + Error: From, +{ + #[inline] + fn from(e: TryPushInitError) -> Error { + match e { + TryPushInitError::AllocError(_) => ENOMEM, + TryPushInitError::InitError(e) => Error::from(e), + } + } +} + /// Error type for [`Vec::remove`]. pub struct RemoveError; -- 2.56.0