From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5B56D218ADD; Mon, 17 Feb 2025 11:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739792153; cv=none; b=i3MiIZ+B34RJg0tsPCLrA8WVQekvvmDKTOmnrjpmYBBIZ9TU9m2WibMkI9Vw3tE/Y5+dLUbKu60FrMyc3liE55ICIRKFqYZ3GXzs7cgxpiquF1Ed3N1MgqieQBKoF3QqqP2/i3llAu3IfSaaVlomCAbAQ/FAJSUsNnQwvhTHfw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739792153; c=relaxed/simple; bh=+IGG54n1lmfSbU9emZ51GaDiateiqm/EMpg9ehhM86w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TvR2P3agYKxaoFGK/N/ApxIYZfJnULwg+y8tV2HrHFCJXtkF3972FRDfo9Ipstz6BvR/TZUG3pilTivNUEWwxSF05PrAITbZk/xih2OjvQkDnYWoblleGKDjrb0IlhCe208kJIV59+LPlzNvjv6sVl5XqIQiSAF7M3VPYoCViGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dDhlAgJW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dDhlAgJW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 760D6C4CED1; Mon, 17 Feb 2025 11:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739792152; bh=+IGG54n1lmfSbU9emZ51GaDiateiqm/EMpg9ehhM86w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dDhlAgJWcH8yw/tYPDr27ADbMMiim3kxn9Fhxmq+D1Qt28Ejs7cIOjrGKbYcf2tvJ CLlT7Xp/ZMcveUlu/EiJFxcWNe0nsQCg9Ji5p+sUZCSEqnXTKwwlkfAYcLLl4AE6QA 4iX+bPA+Rdw3W4gW29pNnEnDcUHXfds4lO+iyYWvqsVj1QU/3zlP1VQStSL8MzPQbX 9W7cu9s/cdLL+pX7sx342DyG0a1ARoir2Ja+se4d9nCE2/Mpo5hwSUnxBYbuSjN507 P0j3Pe3jhUEmoZVhT/ny9C0wTu/CXnBRy0ICie7Ba8WT+3m0gVAAn3jQwWgNWRXfm6 9dGkgbWLXXZcA== Date: Mon, 17 Feb 2025 12:35:45 +0100 From: Danilo Krummrich To: Tamir Duberstein Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Matthew Wilcox , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" , FUJITA Tomonori , "Rob Herring (Arm)" , =?iso-8859-1?Q?Ma=EDra?= Canal , Asahi Lina , rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH v16 3/4] rust: xarray: Add an abstraction for XArray Message-ID: References: <20250207-rust-xarray-bindings-v16-0-256b0cf936bd@gmail.com> <20250207-rust-xarray-bindings-v16-3-256b0cf936bd@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20250207-rust-xarray-bindings-v16-3-256b0cf936bd@gmail.com> On Fri, Feb 07, 2025 at 08:58:26AM -0500, Tamir Duberstein wrote: > `XArray` is an efficient sparse array of pointers. Add a Rust > abstraction for this type. > > This implementation bounds the element type on `ForeignOwnable` and > requires explicit locking for all operations. Future work may leverage > RCU to enable lockless operation. > > Inspired-by: Maíra Canal > Inspired-by: Asahi Lina > Reviewed-by: Andreas Hindborg > Reviewed-by: Alice Ryhl > Signed-off-by: Tamir Duberstein > --- > rust/bindings/bindings_helper.h | 6 + > rust/helpers/helpers.c | 1 + > rust/helpers/xarray.c | 28 ++++ > rust/kernel/alloc.rs | 5 + > rust/kernel/lib.rs | 1 + > rust/kernel/xarray.rs | 276 ++++++++++++++++++++++++++++++++++++++++ > 6 files changed, 317 insertions(+) > > diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs > index fc9c9c41cd79..77840413598d 100644 > --- a/rust/kernel/alloc.rs > +++ b/rust/kernel/alloc.rs > @@ -39,6 +39,11 @@ > pub struct Flags(u32); > > impl Flags { > + /// Get a flags value with all bits unset. > + pub fn empty() -> Self { > + Self(0) > + } No! Zero is not a reasonable default for GFP flags. In fact, I don't know any place in the kernel where we would want no reclaim + no IO + no FS without any other flags (such as high-priority or kswapd can wake). Especially, because for NOIO and NOFS, memalloc_noio_{save, restore} and memalloc_nofs_{save, restore} guards should be used instead. You also don't seem to use this anywhere anyways. Please also make sure to not bury such changes in unrelated other patches. > +/// The error returned by [`store`](Guard::store). > +/// > +/// Contains the underlying error and the value that was not stored. > +pub struct StoreError { > + /// The error that occurred. > + pub error: Error, > + /// The value that was not stored. > + pub value: T, > +} > + > +impl From> for Error { > + fn from(value: StoreError) -> Self { > + let StoreError { error, value: _ } = value; > + error Why not just `value.error`?