Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1832732rdh; Sat, 25 Nov 2023 04:52:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6LCNF1KpXjgKwG43ui2+2XP0tG+z1wS22ZudqK8/C88ZrggsORS3AWymP45JLE3v7T6ps X-Received: by 2002:a05:6a20:8f10:b0:18c:285f:c07c with SMTP id b16-20020a056a208f1000b0018c285fc07cmr3354235pzk.12.1700916764273; Sat, 25 Nov 2023 04:52:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700916764; cv=none; d=google.com; s=arc-20160816; b=DTTGt8wd7iykLTc/otJpQFnGrpTK5XX145EfZN5z8/nhMEY8w/PASevt4+YKwbdRPb QcSe57CHUgor7q1nTmSUD69SVMev/Ch+NpoVb6t+LloMUfxJcntxca7U1LneAIStJ1/h Z8XGwqHP4sUhqCB0Woran6uLnd+g1t7CA3uM+PDdA7MnaCaLwC7TXBPHUVNYJ31b7CJh Rk5BYflkR8d1vVO8+DGzG8jmQFJMNVSm2c+fChXjR4+zIIhx7KquyPhEGuevxQ2ICQuB PYuleK3H2bVcdYdllRBZeCmZmcJ0JcfMHu928zE7Tqn39ddq7KPOoBtUskx1D7PQ3v1v W0Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:message-id:subject:cc:from:to:date:dkim-signature; bh=5cwlw0HuMDDbZgo/K1At3+rO2e/15vaUqRXcq/BERzM=; fh=MKp4uwIS2qcobQvLDCgvPbRKPggooUfCgyYyA4DDQfU=; b=RtmqNOf9jAYW+dXnRq3TpFj3RnKOrgjC5peLLtFoj/kgiXE+a8DBUKUZIjmZvvVtit uDF1M3dyrEesL9bX+XfLP9JuBZAl8AaV1HEfSSH2WoMQgOVo5Kdr8ON5Ii9VPE6w0m3j DdlaF0gdc58CxztZ7x/hjFE90cHuTRi3BkqB7okJVOOQL87miV477uiaFQlgLO4tb8I5 yUIIF6VeKYv7gvL8qDRixneGpP5jt6Rsq05Y9cfnNUnAW1QTDdMeIkGxzCZxeKpjIVN1 0xQOlobdMYCX1nniC2Ab0Di/1XsDbqSyd+pA/6KWYhx+1slmmq63DzTRTHBK2g4ku68L kfuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=FS3ez3D8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id fi6-20020a056a00398600b00691019fd0efsi5686594pfb.75.2023.11.25.04.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 04:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=FS3ez3D8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 92C258063D63; Sat, 25 Nov 2023 04:51:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232088AbjKYMvb (ORCPT + 99 others); Sat, 25 Nov 2023 07:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbjKYMv3 (ORCPT ); Sat, 25 Nov 2023 07:51:29 -0500 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9D618C for ; Sat, 25 Nov 2023 04:51:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1700916693; x=1701175893; bh=5cwlw0HuMDDbZgo/K1At3+rO2e/15vaUqRXcq/BERzM=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=FS3ez3D8nDEmE+MRVnSjRM9nxTRr8v9kzeCCfjs7zZYj3YGzeyW4G2sPVZfmcU2hW CDdNb/nAxVfWR0uZ5lu30LwUdKIGM1ZzwAkldj471VMulFRmoTbdgN6qS2QSrYELEU QSfRsiwmR0lL4KrlQTAsZA0hZ5BXW4cWJFaRDPkD0E22LxezynuZqdKe2JJiD2huVr HOfNXZciWch/10Vm/Bu2ZLszU5hX6vGLGtAu8nBEomhkCbmT/PkPOVNrssLXl8I30g ++D2QaElRThHrNYAUL9TUrIYwdqTGST66IGS560BcK817bPYxTnr7Jw0KOdZO2/mYq 2hX2k5YW7GDhw== Date: Sat, 25 Nov 2023 12:51:23 +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 , Tejun Heo From: Benno Lossin Cc: Wedson Almeida Filho , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] rust: workqueue: add `#[pin_data]` to `Work` Message-ID: <20231125125024.1235933-3-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sat, 25 Nov 2023 04:51:52 -0800 (PST) The previous two patches made it possible to add `#[pin_data]` to structs with default values to const generic paramters. 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 `pin_init!` macro. Signed-off-by: Benno Lossin --- @Miguel: This patch is based on v6.7-rc2, because `workqueue.rs` has yet to land in rust-next. The first two patches also apply to rust-next. 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 b67fb1ba168e..15bcfdb1ed33 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -334,8 +334,10 @@ pub trait WorkItem { /// Wraps the kernel's C `struct work_struct`. /// /// This is a helper type used to associate a `work_struct` with the [`Wor= kItem`] that uses it. +#[pin_data] #[repr(transparent)] pub struct Work { + #[pin] work: Opaque, _inner: PhantomData, } @@ -357,21 +359,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.40.1