From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (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 73FDE1A9F82 for ; Mon, 6 Oct 2025 23:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759792191; cv=none; b=lWh7z2lhFqjVCV+8NzvgOsd0zkMRmyd9oMDX/6mHCqF2SMwU2zRFcwm4QwukgungoGRNrbPxNl0JKP+U27nvpmpj0cFthwEuXZFUO4c/FwrkQEt6pwBQ/ODz2pIM+hBTd6WgFHBxEPPY1RnbJG7gtydpjP916Q8fpEWx3DcOpmI= 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.181 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-f181.google.com with SMTP id d75a77b69052e-4b109c6b9fcso56054431cf.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=OFiXSwU6THujusLX2N6l5fXq515B59Xi+FObJglW5p1cCbjWZ1s4k4iTsgYbPCS396 5VJJA4at9OSE7n1a8ho3GNJmC/yd+cLCpG6rdqKQJf4MdCh/zl6L+G7I3+ah/14ZsX2m 8BT6ZZkHhO1mtv2gxesl07nDZj21ICcgQkxgmMfjM8KDbsNhh225qknA6mGGyX8/RbxW 5yJ59pdGkYc6fGknWTWVOv53op2ZC1INefxBo1jMXB1Tzh2qZsPq1ko18kRVs4thPVxF PjWe72Xtr6Co2kOXjQA2XNvL1UrwvDV56ENpac0PymiluVwlF4bzhHyj/pWfiRJut1tb P+cQ== X-Forwarded-Encrypted: i=1; AJvYcCWR7gpyrgDPWgMifx4vskp1vVJavWzL6fb6fK3DSOGRKbpUAjRCXE6ZpW7TBbxmUy7HAS08PI6n63k=@vger.kernel.org X-Gm-Message-State: AOJu0YyRZdYLUv3v7sgP0UZGde+iwndp1XgbCBaExNc0sI42IONaBwkE St+cTvFfmyJqNIdw4Ijn+ErtLkps/g3IBtUIJTYTgNuSCd8Sp95zMuGk X-Gm-Gg: ASbGnctL1DrlXFwqsNGnxn0zmCPjjHILk+Ti/0YvPOELfEkSMs3Is2Qmol7f/OtQN2u BIAIUeo9iFLIhXRGXpWif3N7hLF20PTw3Ujv+ho9UjkUdgWDD2+tQjtYvbl4MUhqKSNo1VWgj0a ro/sMVJJs6uXdw6X+hWdZX2w6muTIWUR5jo/os+SqsLl9hb5ioIQpALbZQST0B+TS0tEC0Oo9ZQ 7c6hSZ8OdPgv1yw9BDlcXzg8mYAaVSIsEs1p2eurcl522NyQI30fq7c0eeHZyGOI58n2Udlbcqf /u0NhZ5/5K962OXJcEplV/gY2pI6bc4DiVadS+EBeCiKvgrREjcUixROTksDssCA+R9RcbdbkvB Q8wHlh++HhvvKrpw4XvifsHXcDJ/0g/yUdDCCP3zbyNkd3CcrI/GUzfqoNc3Qe9/+FzSZ8NLFtj ZcMWc5srr6gqk+FRsl/mzFKpAwWMGfBc26RSkGVCW1Pdok3a8= X-Google-Smtp-Source: AGHT+IFreUBAqPeM2h2ornDIoHcelDSJDRklng9KnvFrE/xsqQejPQGKywtCZzD+qAhNnKO9SG6+Wg== X-Received: by 2002:ac8:7d8e:0:b0:4b7:9f86:8705 with 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-doc@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 >