Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp238404lqk; Sat, 9 Mar 2024 07:55:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWrl6MV6V8F7Hkdg7SGDyaUjI1PCMnlU1IJTvt4n9bPNb0ueC9SObZ0fjMHW+hXoCY1GglVv0Myzp4a0Ecor7XBkMAl1PFtHrtwcduaTw== X-Google-Smtp-Source: AGHT+IEW4XcD5DEy2dSAvHV+jvzQJm8c5cwmUvajZ9oHf1Pvc0vZ5E6V0OA4usSawkXmR7WGoRNS X-Received: by 2002:a17:906:557:b0:a44:7a34:e620 with SMTP id k23-20020a170906055700b00a447a34e620mr1212728eja.4.1709999734565; Sat, 09 Mar 2024 07:55:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709999734; cv=pass; d=google.com; s=arc-20160816; b=jjauEhTrani2NGPhWxiPMnjXa+R97d8Hcddr4NIQr7imCx/gL/6CYVXhjYogsta56j 9B8oOSzYR8nbRrhhqf0sRbRLfZgfmuH6rGLPv3CBz5dpHLfoqvgUQu87PlA5zur/TMPg +PreZnbYmYJoukzr9/P4ymj3ycBGQthMElQTQU02c9Fvxj+Xfr9hF6Cu5BkpPxD0hYhe DKpzN2NmZ3U1xInWmMW8oNWLeyEB5H0LhhRtKdajJxsCrv3Gz3xR0HbxaE/IOYMd00fF 2FwxVjKOYFXyHIcOacD579x6fL6rMGtBf/8oT4GKZR1gYysshAiffjwm5y7yXDJNFvFT EkKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=/tByVpPOQqxliq0F4vWuV5WVPpv3O6Lr3QVczYQPpwQ=; fh=jU17u8dDd/x13LvNeBuyjOm/7BL5s+ns7QEjsVBzRaY=; b=xjm51OGSmFReEP3DdQZIT9KHC7Wu/N4XywVTNnDtV6nqKvMxI/+scico97OBTZBvdE npG+T/UNmIgteb8SkbMw94Purt/XNx0807Ye5wTOHhd0GLk2SGxCiiCtbQHNKTmB36jz A53ogzUmGGqJcV6mVCJ2DXFCZQhss8/l0+Q23qK7Me+toA7YR9g8aKC3CM1zqPeTBPfG iFykQNmsJaI6BsQ3i2pqFvCMZTuoZq98fYC0LBSyQav+cVzC0n2JaDnJWFPNGtFZhsNA vmONPtLyuhxdClLhDWESN9K4Ghy91QJIiQlOG4YcWpUSw7mUkszRFSxK1y3V6JCDiWx5 9DFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=TmbVPr7Q; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-97945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ld15-20020a170906f94f00b00a45bfa91e83si815196ejb.465.2024.03.09.07.55.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 07:55:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=TmbVPr7Q; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-97945-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 41DC91F21537 for ; Sat, 9 Mar 2024 15:55:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 378B945951; Sat, 9 Mar 2024 15:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="TmbVPr7Q" Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) (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 952414503E for ; Sat, 9 Mar 2024 15:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709999726; cv=none; b=G+fBj4uuN8olYxIE2N64PD92ylU1Htpqb0ghdJtTND4SN7nQCaWCYFIIxhGssPlhuPSjkoO2XkuLs+NkwuGs++VxllqnSfG05vVhuXa/eX7/IEvjSAE+gsfYPyxPp/O+V0T8RQLQI/QMwE2PAW9UGWwnOF3bczunzv+Nsp0xrgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709999726; c=relaxed/simple; bh=d6ujX5QMz1tmNKIt/U0yYWjhSRY/osTOtHSTIF8XBXY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MBQhbBJqiypvWghi7avp01hLpIGF0epqURTrzurc7RSstZ+CESA9YPYlti9UGLBzLmcCyjefzy3QPa15FkLfN3ljEBE7cMmeBPmn4/xm4oiPbiU6y3NHIMna+24r0cJOOK7cdswjcIxihwEQJAk5JoRqKqRxZdOnMLbJ+cZRkAg= 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=TmbVPr7Q; arc=none smtp.client-ip=185.70.40.133 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1709999717; x=1710258917; bh=/tByVpPOQqxliq0F4vWuV5WVPpv3O6Lr3QVczYQPpwQ=; 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; b=TmbVPr7QReeFYM1W8tqBdf0dUBVpQYXsZpnJwNQkoaD6ipTtjqCT2c9t7Xrhg29Bv ulf2b5GTTXcI51YeklSyz0mNa9lSw7es2yPXTGrMhN0Ik0l60CDnnomLUrRP/wqCeS DU4Db0UsmK4TbWgNNL/fzJdSGuXOZ3sjEmQVk6rlZRxwhG7z4nrD/QjfAOciz+A+U/ km++O759mdJZXYH7Ilx5J9EfIV5WYyo+xEhQsPULNDUNSzni1TkkPcXa644nBjanMO drkeXgQuD2raIJHjkCRnBYLa6nfGsyUO+JPVz2YlE1krkDoV+aPK7AIzqJQKZxyRGS GXFQ14h2w4lqw== Date: Sat, 09 Mar 2024 15:54:52 +0000 To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , Valentin Obst From: Benno Lossin Cc: Wedson Almeida Filho , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] rust: workqueue: add `#[pin_data]` to `Work` Message-ID: <20240309155243.482334-3-benno.lossin@proton.me> In-Reply-To: <20240309155243.482334-1-benno.lossin@proton.me> References: <20240309155243.482334-1-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton 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 The previous two patches made it possible to add `#[pin_data]` on structs with default generic parameter values. This patch makes `Work` use `#[pin_data]` and removes an invocation of `pin_init_from_closure`. This function is intended as a low level manual escape hatch, so it is better to rely on the safe `pin_init!` macro. Signed-off-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Gary Guo Reviewed-by: Alice Ryhl Tested-by: Alice Ryhl --- v2 -> v3: no changes v1 -> v2: - improve commit message wording - change `:` to `<-` in `pin_init!` invocation rust/kernel/workqueue.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 544f0c51f1b7..ab4d64fbdb78 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -342,8 +342,10 @@ pub trait WorkItem { /// This is a helper type used to associate a `work_struct` with the [`Wor= kItem`] that uses it. /// /// [`run`]: WorkItemPointer::run +#[pin_data] #[repr(transparent)] pub struct Work { + #[pin] work: Opaque, _inner: PhantomData, } @@ -365,21 +367,22 @@ pub fn new(name: &'static CStr, key: &'static LockCla= ssKey) -> impl PinInit, { - // SAFETY: The `WorkItemPointer` implementation promises that `run= ` can be used as the work - // item function. - unsafe { - kernel::init::pin_init_from_closure(move |slot| { - let slot =3D Self::raw_get(slot); - bindings::init_work_with_key( - slot, - Some(T::Pointer::run), - false, - name.as_char_ptr(), - key.as_ptr(), - ); - Ok(()) - }) - } + pin_init!(Self { + work <- Opaque::ffi_init(|slot| { + // SAFETY: The `WorkItemPointer` implementation promises t= hat `run` can be used as + // the work item function. + unsafe { + bindings::init_work_with_key( + slot, + Some(T::Pointer::run), + false, + name.as_char_ptr(), + key.as_ptr(), + ) + } + }), + _inner: PhantomData, + }) } =20 /// Get a pointer to the inner `work_struct`. --=20 2.42.0