From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) (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 75F8B193429 for ; Sat, 15 Mar 2025 09:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742031032; cv=none; b=qBA+8anr/5n4Q+e4Rne/wZLaBgoYnv0Ar/JcoCeOPzm75TwUyfjC1BE17+ZjSsoM9bJ+BYbZEEfb1DRTjA8IeMI3js4gwBePiZyQbkYDMyAvPtyRwYsHG2Bw9yQUHI8hYjLGDOlLKlbaxonWdMSxkkdILUodCxUB6fCCL/N9LtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742031032; c=relaxed/simple; bh=97kGKNN5hQbr04or/PK2XNq/0J/Oc6yIvn3Fz2Ytif0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wl/073OHVAHSugMRwIVsSdLqpShXuyKTJg5cL02FjL0rf5hWurowaZY/EgXrYJqrSrEqVRZjheCJDzXPtR+lRg8sTF6otNakd+CGK84UkdiCwiKEFgsksglIDOzZ6cLpfDpq7eZ/9UBbcvPwgTae2Fqwd0fByKdrbBSB9Ooh1nY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=A0CgfKPH; arc=none smtp.client-ip=109.224.244.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="A0CgfKPH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742031021; x=1742290221; bh=9N+3i6PB6m15+3SqKPg5OJJzxL52G/8lBjymGMBlRHE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=A0CgfKPHxzKRVkLYzcYywyC7IC/PMmsiRHRDd8W/Wi6RMGXP34ILn/wHmsVjvIDGy BoZLtAo4x4DTxd/L/Xi+8bwEMCLwITVL9i2NuAcfh44GspvnEInonm1XckH2MEVmuY 0j9EiqLhRRJGOZVfIx60PcMLG4cnamNHWb7sADlgp9EWeINpS4xR5GgINXB45Gxv5P 3wg/C4WkOpdxtNoagJRbMM8HhOe3kFrtK7hwQ9bKbI0Ppt71dRl7ZlNcigXqs/djwZ 8eATJ3VGyaOstsYIZfZ2emqulBgBXjPhEDEKeiJWzkaB8Zm+MQeD8PoAOn25+X8HYk U/pk4+WaxuOPQ== Date: Sat, 15 Mar 2025 09:30:14 +0000 To: Tamir Duberstein From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Bjorn Helgaas , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH 2/2] rust: workqueue: remove HasWork::OFFSET Message-ID: In-Reply-To: References: <20250307-no-offset-v1-0-0c728f63b69c@gmail.com> <20250307-no-offset-v1-2-0c728f63b69c@gmail.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 9f88381a8e82266ee6b415dd7cb86d51df4e7f89 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=utf-8 Content-Transfer-Encoding: quoted-printable On Fri Mar 14, 2025 at 9:44 PM CET, Tamir Duberstein wrote: > On Fri, Mar 14, 2025 at 3:20=E2=80=AFPM Benno Lossin wrote: >> >> On Fri Mar 7, 2025 at 10:58 PM CET, Tamir Duberstein wrote: >> > Implement `HasWork::work_container_of` in `impl_has_work!`, narrowing >> > the interface of `HasWork` and replacing pointer arithmetic with >> > `container_of!`. Remove the provided implementation of >> > `HasWork::get_work_offset` without replacement; an implementation is >> > already generated in `impl_has_work!`. Remove the `Self: Sized` bound = on >> > `HasWork::work_container_of` which was apparently necessary to access >> > `OFFSET` as `OFFSET` no longer exists. >> > >> > A similar API change was discussed on the hrtimer series[1]. >> > >> > Link: https://lore.kernel.org/all/20250224-hrtimer-v3-v6-12-rc2-v9-1-5= bd3bf0ce6cc@kernel.org/ [1] >> > Signed-off-by: Tamir Duberstein >> > --- >> > rust/kernel/workqueue.rs | 45 ++++++++++++---------------------------= ------ >> > 1 file changed, 12 insertions(+), 33 deletions(-) >> >> What is the motivation of this change? I didn't follow the discussion, >> so if you explained it there, it would be nice if you could also add it >> to this commit message. > > The motivation is right at the top: it narrows the interface and > replaces pointer arithmetic with an existing macro, and then deletes > unnecessary code. > >> > diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs >> > index 0cd100d2aefb..0e2e0ecc58a6 100644 >> > --- a/rust/kernel/workqueue.rs >> > +++ b/rust/kernel/workqueue.rs >> > @@ -429,51 +429,23 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut = bindings::work_struct { >> > /// >> > /// # Safety >> > /// >> > -/// The [`OFFSET`] constant must be the offset of a field in `Self` o= f type [`Work`]. The >> > -/// methods on this trait must have exactly the behavior that the def= initions given below have. >> > +/// The methods on this trait must have exactly the behavior that the= definitions given below have. >> > /// >> > /// [`impl_has_work!`]: crate::impl_has_work >> > -/// [`OFFSET`]: HasWork::OFFSET >> > pub unsafe trait HasWork { >> > - /// The offset of the [`Work`] field. >> > - const OFFSET: usize; >> > - >> > - /// Returns the offset of the [`Work`] field. >> > - /// >> > - /// This method exists because the [`OFFSET`] constant cannot be = accessed if the type is not >> > - /// [`Sized`]. >> > - /// >> > - /// [`OFFSET`]: HasWork::OFFSET >> > - #[inline] >> > - fn get_work_offset(&self) -> usize { >> > - Self::OFFSET >> > - } >> > - >> > /// Returns a pointer to the [`Work`] field. >> > /// >> > /// # Safety >> > /// >> > /// The provided pointer must point at a valid struct of type `Se= lf`. >> > - #[inline] >> > - unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work { >> > - // SAFETY: The caller promises that the pointer is valid. >> > - unsafe { (ptr as *mut u8).add(Self::OFFSET) as *mut Work } >> > - } >> > + unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work; >> > >> > /// Returns a pointer to the struct containing the [`Work`= ] field. >> > /// >> > /// # Safety >> > /// >> > /// The pointer must point at a [`Work`] field in a struct= of type `Self`. >> > - #[inline] >> > - unsafe fn work_container_of(ptr: *mut Work) -> *mut Self >> > - where >> > - Self: Sized, >> >> This bound is required in order to allow the usage of `dyn HasWork` (ie >> object safety), so it should stay. >> >> Maybe add a comment explaining why it's there. > > I guess a doctest would be better, but I still don't understand why > the bound is needed. Sorry, can you cite something or explain in more > detail please? Here is a link: https://doc.rust-lang.org/reference/items/traits.html#dyn-c= ompatibility But I realized that the trait wasn't object safe to begin with due to the `OFFSET` associated constant. So I'm not sure we need this. Alice, do you need `dyn HasWork`? --- Cheers, Benno