From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 8152C23958E; Thu, 6 Feb 2025 17:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738862327; cv=none; b=jB74kk9XEM+xFvUo5p82FJpRNKDscZ0gn8e1EZkUDTRW2F82DJyJfiYPb3eQBo9DPZ/+bcejgdtx/zG209awpoDb1bOQViYHWielaFceN7P8ctTgd3SjDrBFQBFmogeRdekhvo1RHAwjD0yhvZKOtOSNgTNrpSQ8FNQX1d1x8Hs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738862327; c=relaxed/simple; bh=hign94Go9lk4AYPopq+TYKCuIxjzdqNnqTCBcL9Y1Bo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PMP/XZQA3YgHJIojBamNS1oJy5LzdatCGlMDVtNoh5kRavvJ65AVaiMvTYlef3eBnaYLpl3RDj1Gyj9R+KV5NZqsmXh6fPuQV7ZVZHQEFFw+mR72uZ+5PsgGLf3O7WpoGHpb+96x7VJXNAhhxmOMNH0/vdKP/RMFPuTy6lobvmo= 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=ZA/RB2v1; arc=none smtp.client-ip=209.85.160.174 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="ZA/RB2v1" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-46785fbb949so12981021cf.3; Thu, 06 Feb 2025 09:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738862324; x=1739467124; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=NWZE34TSmahB5AibwSst6U5NVP6NbGfoRI+yy3U6I1c=; b=ZA/RB2v1bqUkieU5vUKFp22+J4mX4hKOqDCON8VcT6LPRTLt1yy0TTgLO46NO1CuHq vtwSKxKsUX/IAsIpDyaM+1MKfpFNQ32tEGE2BffrGyxx77x29USTJLHcEPrw2cWXcj80 OJiTo7sdKCoszYDJcuEK1GonIm6GPnc0F5sW9LIjkEFKYL6E+OU+cvBXf0X6IGUiENkf vI80ghXtEiImge1NBxi1xHJipd6FLuzj5cXlYHJUk3e6kcYMM1n8fyZs9WsVvortgmz+ jp3Pn75Bys/6IxbuW9IOBx53nyo/NWoLGbcYoHjh1uugDucKwBHaqBRtf8v+kpKXhMPO KQNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738862324; x=1739467124; h=in-reply-to: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=NWZE34TSmahB5AibwSst6U5NVP6NbGfoRI+yy3U6I1c=; b=LKUJEd7fA2Qzsp8tKWRxsVOG9HLWMzgB71EZ47H2j3DznuwLmfRAGYnFbWxtib6Bp5 ewsAESj+29Y4G2tT0cgOgCs+0SpGmHjANTd/0Tje7yZGEPetPZ0hDPCosfg+mp1pctQh WlMUSMos1O2dE48ib4Gk/Lk87+7tzOGX49w+78Yg2zpSrQAXSmMutRNYlMOdQq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g== X-Google-Smtp-Source: AGHT+IFcuW/XgSmCC4i0dttCgM1I/hD7fjOkOntHg5kN5NTOknxD30oPuuJ8aQkhu6PUzCNg/tjPvQ== X-Received: by 2002:ac8:58cc:0:b0:467:61da:1ce2 with SMTP id d75a77b69052e-471679ec4f7mr702191cf.16.1738862324283; Thu, 06 Feb 2025 09:18:44 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-471492c333csm7340371cf.48.2025.02.06.09.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2025 09:18:43 -0800 (PST) Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id 2930C1200043; Thu, 6 Feb 2025 12:18:43 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Thu, 06 Feb 2025 12:18:43 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvieeljecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilh drtghomheqnecuggftrfgrthhtvghrnhephedugfduffffteeutddvheeuveelvdfhleel ieevtdeguefhgeeuveeiudffiedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghl ihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepgh hmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopedvuddpmhho uggvpehsmhhtphhouhhtpdhrtghpthhtohepthgrmhhirhgusehgmhgrihhlrdgtohhmpd hrtghpthhtohepuggrkhhrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehojhgvuggr sehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrlhgvgidrghgrhihnohhrsehgmhgrih hlrdgtohhmpdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthht ohepsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtohepsg gvnhhnohdrlhhoshhsihhnsehprhhothhonhdrmhgvpdhrtghpthhtoheprgdrhhhinhgu sghorhhgsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrlhhitggvrhihhhhlsehgoh hoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Feb 2025 12:18:42 -0500 (EST) Date: Thu, 6 Feb 2025 09:18:40 -0800 From: Boqun Feng To: Tamir Duberstein Cc: Danilo Krummrich , Miguel Ojeda , Alex Gaynor , 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" , =?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 v15 2/3] rust: xarray: Add an abstraction for XArray Message-ID: References: <20250206-rust-xarray-bindings-v15-0-a22b5dcacab3@gmail.com> <20250206-rust-xarray-bindings-v15-2-a22b5dcacab3@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=us-ascii Content-Disposition: inline In-Reply-To: <20250206-rust-xarray-bindings-v15-2-a22b5dcacab3@gmail.com> Hi Tamir, This looks good to me overall, a few comments below: On Thu, Feb 06, 2025 at 11:24:44AM -0500, Tamir Duberstein wrote: [...] > +impl<'a, T: ForeignOwnable> Guard<'a, T> { [...] > + /// Loads an entry from the array. > + /// > + /// Returns the entry at the given index. > + pub fn get(&self, index: usize) -> Option> { > + self.load(index, |ptr| { > + // SAFETY: `ptr` came from `T::into_foreign`. > + unsafe { T::borrow(ptr.as_ptr()) } > + }) > + } > + > + /// Loads an entry from the array. Nit: firstly, this function has the same description of `get()`, also I would prefer something like "Returns a [`T::Borrowed`] of the object at `index`" rather then "Loads an entry from the array", thoughts? > + /// > + /// Returns the entry at the given index. > + pub fn get_mut(&mut self, index: usize) -> Option> { > + self.load(index, |ptr| { > + // SAFETY: `ptr` came from `T::into_foreign`. > + unsafe { T::borrow_mut(ptr.as_ptr()) } > + }) > + } > + > + /// Erases an entry from the array. Nit: s/Erases/Removes? > + /// > + /// Returns the entry which was previously at the given index. > + pub fn remove(&mut self, index: usize) -> Option { > + // SAFETY: `self.xa.xa` is always valid by the type invariant. > + // > + // SAFETY: The caller holds the lock. > + let ptr = unsafe { bindings::__xa_erase(self.xa.xa.get(), index) }.cast(); > + // SAFETY: `ptr` is either NULL or came from `T::into_foreign`. SAFETY comment here needs to mention why there is no alive `T::Borrowed` or `T::BorrowedMut` out there per the safety requirement. Regards, Boqun > + unsafe { T::try_from_foreign(ptr) } > + } > + [...]