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 1383F2E8B80; Wed, 8 Oct 2025 10:18:30 +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=1759918711; cv=none; b=qIY67VmKCMJatqMumPf2rM8VtJVbCrXJFdzgfDHgCxFDX3narCAwcA/HkN6eZdUhLPzK91vPWFpHwSl/If7ly0EE8KiludDqUD6EcnvG70Idi+bUmJwVfvspPe8KND9gKvaBL4FOFFyst92wns0BBtjjmBDemxFUOJrhrEjQRVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759918711; c=relaxed/simple; bh=b/FTtui6gRJ0e8SceFeHMggEt9pTm3eBkrK95al13n4=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=noDzglgPftmCrq8mdm3P6BONYjd27vefncrzaeGKvgX1L26ZWiJT9+FB6Tna7fgYcIfQZeEPcGAU9qdZvRjqmcmhvAKhPK38ITmmWeW/7Mt1P9S0Fjt1Ul2n2RYe7HhXYQFbNj1vu1e7t5tsQ3cJxhn1CC3sJVmz0/3SkbiQmBQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fNIFBteU; 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="fNIFBteU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1A85C116C6; Wed, 8 Oct 2025 10:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759918710; bh=b/FTtui6gRJ0e8SceFeHMggEt9pTm3eBkrK95al13n4=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=fNIFBteU5oXqlXy5snUMg4wnv4ymZxQNvlmghhT3xY3rBznehwKbSRFDnStR9p4s6 r48i2oLx463jKd4eYL6LBAJ25yLSDXfiJBiFNknLJUmOVYvDcSW+sjp1CCnZfkKLb/ rH+rM75edc1xTbEDnAJb6uS5iZLCp92bV/nSrDo7bhiYEeXwwgyXH0dhkJznNGQi39 JDmF1yRptuK0FKjfZEXbn2f0pD8ngnETbmCoPbATpRnBbjw6l2ecFN7E46RZty2j9+ jBjyHPTkReCELApres82FOslhT8aapoU+cbWDq90GSGhtYEWJZcxumKi3+7WLIKRBZ j3YMjO8sVWLJg== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 08 Oct 2025 12:18:24 +0200 Message-Id: Cc: =?utf-8?q?Onur_=C3=96zkan?= , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH 1/3] rust: xarray: abstract `xa_alloc` From: "Benno Lossin" To: "Alice Ryhl" X-Mailer: aerc 0.21.0 References: <20251006163024.18473-1-work@onurozkan.dev> <20251006163024.18473-2-work@onurozkan.dev> In-Reply-To: On Tue Oct 7, 2025 at 12:58 PM CEST, Alice Ryhl wrote: > On Mon, Oct 06, 2025 at 09:31:43PM +0200, Benno Lossin wrote: >> On Mon Oct 6, 2025 at 6:30 PM CEST, Onur =C3=96zkan wrote: >> > Implements `alloc` function to `XArray` that wraps >> > `xa_alloc` safely. >> > >> > Resolves a task from the nova/core task list under the "XArray >> > bindings [XARR]" section in "Documentation/gpu/nova/core/todo.rst" >> > file. >> > >> > Signed-off-by: Onur =C3=96zkan >> > --- >> > rust/kernel/xarray.rs | 39 +++++++++++++++++++++++++++++++++++++++ >> > 1 file changed, 39 insertions(+) >> > >> > diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs >> > index a49d6db28845..1b882cd2f58b 100644 >> > --- a/rust/kernel/xarray.rs >> > +++ b/rust/kernel/xarray.rs >> > @@ -266,6 +266,45 @@ pub fn store( >> > Ok(unsafe { T::try_from_foreign(old) }) >> > } >> > } >> > + >> > + /// Allocates an empty slot within the given limit range and stor= es `value` there. >> > + /// >> > + /// May drop the lock if needed to allocate memory, and then reac= quire it afterwards. >> > + /// >> > + /// On success, returns the allocated id. >> > + /// >> > + /// On failure, returns the element which was attempted to be sto= red. >> > + pub fn alloc( >> > + &mut self, >> > + limit: bindings::xa_limit, >> > + value: T, >> > + gfp: alloc::Flags, >> > + ) -> Result> { >>=20 >> I think it would be a good idea to make the id a newtype wrapper around >> u32. Maybe not even allow users to manually construct it or even inspect >> it if possible. > > What? People need to know what the assigned index is. The documentation says "allocated id", so I assumed that it was some internal, implementation-dependent thing, not an index. In that case we should change the docs instead. --- Cheers, Benno