From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75635C0015E for ; Mon, 17 Jul 2023 14:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbjGQOtK (ORCPT ); Mon, 17 Jul 2023 10:49:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbjGQOtJ (ORCPT ); Mon, 17 Jul 2023 10:49:09 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFAEB2 for ; Mon, 17 Jul 2023 07:49:08 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id 4fb4d7f45d1cf-51e02395cf3so3093177a12.1 for ; Mon, 17 Jul 2023 07:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689605346; x=1690210146; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Y4JVBrFfRISuz38C6eY0UVY6Fr1oXZLiDCBYqS66fUc=; b=AFwtAUXxavdRcfXLXYjDr6Bt17+SrIPjz+6ScXk60mtDaQqym9R7hOYdKRSyg1C/eL 8RqQu41wCmuPobt0EURwT3lf8WeRo+4T/6KlMl6uicp8STNfAqIw+jlG/bVjt/dElIaq 5LYptw3ZflWJoBKeaXw/OEhCIuedWjfikP1iuThYZ9X+cYYJWmmQEBUR3hEroy7TpK62 5ZZiJymHTJlsQfBeA38wCTu5BI1DaBTAxqbt2CD5jdNbsWHtQQ70hc/mQJvcvPsKmMiy 14fcRNSshM8RVD5zJb1/hL2SF1iu5agIePDfmWwxe9Ct7PqRfJH/AKklhp9F+uriNJr+ 2/RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689605346; x=1690210146; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y4JVBrFfRISuz38C6eY0UVY6Fr1oXZLiDCBYqS66fUc=; b=Vo8q4oNgEnU1aNU4olqCJuSU/hIPGEtZG8YLwhlHo4mgS1KU2eprw7lyxcstehiBZS fVcnOHCwNJUAGrzfXkrYz4Z9G1RwC4LzE9w0GCAp5JL6uov2OJKFPw/cYKk6iQfWtxza /rEoLIXREoCYFg1x+CdgqfG/fgLlKhyXwE1x6LE99OexZV2P/T/VYmu1fScgKEy2viU/ c55MbKBipdumxgyoXEUQcSkZ8eU5eCWSCGYuLv+MmTmcERhPGqhFNmm7v2lBrtO/zn3W 4Z4WzfQw1CxYKRvpyQ8+E8JNSodHs6TKFjrjliaoc1hSuiFzz0kjKdfxnWOmXFfCx/XP d8Ig== X-Gm-Message-State: ABy/qLZZ/lc3UgaI68fnSo4lyTGzSxzcENpRs7BlUacva0tmfwo+ODuo RRjsl8y6wGIFusR9UydM97R7VplVtNpAyFU= X-Google-Smtp-Source: APBJJlF/KCpsCV/2YIFa7djpxohGDinVuI+bknFgmFlVcG4ErNHMdBT/lnGY7RXpwPOaaurI0nnc+/OpNijt8O4= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a50:9f6e:0:b0:50b:c4b5:bb77 with SMTP id b101-20020a509f6e000000b0050bc4b5bb77mr67283edf.1.1689605346438; Mon, 17 Jul 2023 07:49:06 -0700 (PDT) Date: Mon, 17 Jul 2023 14:49:04 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230717144904.1857663-1-aliceryhl@google.com> Subject: Re: [PATCH v3 6/9] rust: workqueue: add helper for defining work_struct fields From: Alice Ryhl To: benno.lossin@proton.me Cc: alex.gaynor@gmail.com, aliceryhl@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, ojeda@kernel.org, patches@lists.linux.dev, rust-for-linux@vger.kernel.org, tj@kernel.org, wedsonaf@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org Benno Lossin writes: >> +/// Links for a work item. >> +/// >> +/// This struct contains a function pointer to the `run` function from the [`WorkItemPointer`] >> +/// trait, and defines the linked list pointers necessary to enqueue a work item in a workqueue. >> +/// >> +/// Wraps the kernel's C `struct work_struct`. >> +/// >> +/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it. >> +#[repr(transparent)] >> +pub struct Work { >> + work: Opaque, >> + _inner: PhantomData, > > Should this really be `PhantomData`? Are you dropping `T`s in the > destructor of `Work`? I do not think so `PhantomData Box>` > should do the trick. Hmm. The `work_struct` effectively has a field of type `fn(T::Pointer)`, so arguably, that's the type that should be used for the `PhantomData`. This makes `Work` contravariant instead. That said, the type `T` is going to be the struct itself, so, for example, a `MyStruct<'a>` might have a `&'a i32` and a `Work>` field, so it ends up being invariant. By that argument, perhaps we should just make `Work` invariant instead? We can do that with `PhantomData<*mut T>`. >> +pub unsafe trait HasWork { > > Is there a reason that `T` is `Sized` here? Hmm, that's an oversight. In v1 of this patchset, the Sized requirement was correct since T was the pointer type, but now it isn't anymore. Alice