From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9202C1DF261 for ; Mon, 6 Oct 2025 23:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759792191; cv=none; b=uX818eKmEoYTFuyQTp0M5n7M6u/AbU/HnTsBRGh46J0/NhT/du12TNxNBy6P2H9QnBUeeYeJwENtD399Z3IqQO/YGlkAby9uUi+nXx49bOd6VF6XIiRDEpOtK0DQ5EJ0YDQKr32/ql9kcTf+7Ieu5XFvRXEm50cNvBqRRbm4a0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759792191; c=relaxed/simple; bh=NQ8J43I4uNCJEJQ0QsFSMKAS5RFA5CEyKQ6v5lKmyLc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FpwsNTXYMUWUXLo1L77uqUN4gTY3fft4YTHL0G7UFDapKcsLDWTsmYA4ilZz7oI30IBmjCtoCuktZZ+haEBLb5OQpBaaKs+lpgvy9BqJ/rbTo8sTdhUl1FLkOn1uHHaStObcu/+xaT6qhaWirWltPMegrknD5aC2x6SjlHwxL4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ACd35Qs0; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ACd35Qs0" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4b109c6b9fcso56054441cf.3 for ; Mon, 06 Oct 2025 16:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759792187; x=1760396987; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=3EJTfcu8h4GhEEKd8FZr25euFK3dzJW/aZJwSSRQB9Y=; b=ACd35Qs0tflW5xK4gwx3MfmO4jWIEj4rT8bVEoZx/sPO4ZoEMIn57TRsRFXG6PaJFy cQoqV5jaN5CFYk8jFkbvr2w9inz4Nas0uovcRIFNpHSdwNY+dbrVdU4hPoOhwp/sbRiO 1ocWR4W8gw+g/TWIjKP6wgP2ekGUg5UPinCv8vCxTVmirdcbKI3HKYuTcXwDihUfUd+i 8NN7ihRyOCjF/WiwAAB0A62w4TMvD2Z9n8vXnOQ87U4h20hVEyhzJU05Innv4BLzAHfl BIqpaygfc4E+iTZ+67UNiFGseQs/QhdiyIcbNLbQSPOFj/FJICl0odXzrJrqeNyVxEKV 1PdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759792187; x=1760396987; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3EJTfcu8h4GhEEKd8FZr25euFK3dzJW/aZJwSSRQB9Y=; b=lApJ828a1eW3UlcWWW+Pz3o350yEVUe2S103FzSwTT1MmTu6rP5cW5tTR3xjUlrrfu rHZPeKJIpr/kcGuK28JC6JRQtoiXpVVJcHeitAPNElNWWAljj0xDnSKOQZr8jzgz+KF6 q90dG/gyylCr/DUPMkWWLl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SMTP id d75a77b69052e-4e576b15df1mr138802431cf.65.1759792187194; Mon, 06 Oct 2025 16:09:47 -0700 (PDT) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4e55a34b607sm131310111cf.4.2025.10.06.16.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Oct 2025 16:09:46 -0700 (PDT) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfauth.phl.internal (Postfix) with ESMTP id 887B0F4006A; Mon, 6 Oct 2025 19:09:45 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Mon, 06 Oct 2025 19:09:45 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdelkeekvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertd dttddunecuhfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhm rghilhdrtghomheqnecuggftrfgrthhtvghrnheptdegheelveffudejffegvdelgffhhf elkeeiieefgeevteejvdegveeuffeihefhnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsoh hnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhg peepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopedvud dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepfihorhhksehonhhurhhoiihkrghn rdguvghvpdhrtghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheprghlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhopehgrg hrhiesghgrrhihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhho thhonhhmrghilhdrtghomhdprhgtphhtthhopehlohhsshhinheskhgvrhhnvghlrdhorh hgpdhrtghpthhtoheprghlihgtvghrhihhlhesghhoohhglhgvrdgtohhmpdhrtghpthht ohepthhmghhrohhsshesuhhmihgthhdrvgguuh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 Oct 2025 19:09:44 -0400 (EDT) Date: Mon, 6 Oct 2025 16:09:42 -0700 From: Boqun Feng To: Onur =?iso-8859-1?Q?=D6zkan?= Cc: rust-for-linux@vger.kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, acourbot@nvidia.com, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, corbet@lwn.net, lyude@redhat.com, linux-doc@vger.kernel.org Subject: Re: [PATCH 1/3] rust: xarray: abstract `xa_alloc` Message-ID: References: <20251006163024.18473-1-work@onurozkan.dev> <20251006163024.18473-2-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@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: <20251006163024.18473-2-work@onurozkan.dev> HI Onur, On Mon, Oct 06, 2025 at 07:30:22PM +0300, Onur Özkan 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. > Having this information is good, however I feel it's better if you explain/expand what exact the usage will be on the XArray, otherwise, it'll be hard for people to dig in the history and find out why we add this. Thanks! Regards, Boqun > Signed-off-by: Onur Özkan > --- > 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 stores `value` there. > + /// > + /// May drop the lock if needed to allocate memory, and then reacquire it afterwards. > + /// > + /// On success, returns the allocated id. > + /// > + /// On failure, returns the element which was attempted to be stored. > + pub fn alloc( > + &mut self, > + limit: bindings::xa_limit, > + value: T, > + gfp: alloc::Flags, > + ) -> Result> { > + build_assert!( > + T::FOREIGN_ALIGN >= 4, > + "pointers stored in XArray must be 4-byte aligned" > + ); > + > + let new = value.into_foreign(); > + let mut id: u32 = 0; > + > + // SAFETY: > + // - `self.xa.xa` is valid by the type invariant. > + // - `new` came from `T::into_foreign`. > + let ret = > + unsafe { bindings::__xa_alloc(self.xa.xa.get(), &mut id, new, limit, gfp.as_raw()) }; > + > + if ret < 0 { > + // SAFETY: `__xa_alloc` doesn't take ownership on error. > + let value = unsafe { T::from_foreign(new) }; > + return Err(StoreError { > + value, > + error: Error::from_errno(ret), > + }); > + } > + > + Ok(id) > + } > } > > // SAFETY: `XArray` has no shared mutable state so it is `Send` iff `T` is `Send`. > -- > 2.51.0 >