Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1916172rwd; Fri, 2 Jun 2023 01:56:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56E0+/WF/dZw9DofrG6LvtZvNZtpOOd6tkDilV40PSaIkJVNd9OpWZaVty5fNl51aB6xC4 X-Received: by 2002:a05:6a20:a11c:b0:10b:cb77:5403 with SMTP id q28-20020a056a20a11c00b0010bcb775403mr14715533pzk.52.1685696171852; Fri, 02 Jun 2023 01:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696171; cv=none; d=google.com; s=arc-20160816; b=jcXeUePjuthP3bVht27CSJmtZmLUHOW8pGGThXx03H9s3+gXalNH0UaYRlxOwxWRTs rl45X7jEb/x35h2laUEpqNsgG1+Myw+m99R/AeKit6oCCeyHrK4C7M6j6qlK6ZKfjR3R +LorIJmZFrl187QQqp6KKZoNynEIfJglKnOznQwVZ5T+0u5HT3YvWCNlhqcTbITt9yvF f/3Tu9HRbyDTww6LOOGWpxNINVMFAWCHIamUm5kc8BnPG49nPU8OEm7ylLrPZBUHAoDR p+XEL4quxcQ4QLeoLgRc22+PjTNnMe7D4x7JDoP0ZSTmadIgZOBcjr4y2Djs71gTSj8N R90A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Jda3uobQ4e/ZCA/aiprMO5o6cFc2zo/SCaAFYYc33tg=; b=XyCEnyFU/ullePpphhncAFJXgXzsvFD4IfzqMYm5p0o7jznucTgTPiGioE/1R2h208 REimPUCxdH3hkn2J1FaMEu5kAC3mQpmyi2B2ZJAbPX7CIUyDiQoZDYdaVOBr5Rxm6/TB nJrqIMIgkFvZ5evn4ArEQHQhmBolfvQz90hXKO/SPSYATDtd9s89gAolMcJoC6QT9LgN ZeeGjiqPQgVMzIKFLkBS1UahFX8bTtHShPSZVJQ9+z5wIuzDuakGJEHFsjTXXIwoIETy KGd3lttpP7xKt16CVSvI5L0+nclGJsPe56gq2eR6IKO/goLGkEBBwPAXVruxXFCjhSz2 8CiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=DFvkh47N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020a637319000000b0053fec3ed061si638885pgc.718.2023.06.02.01.55.58; Fri, 02 Jun 2023 01:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=DFvkh47N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234110AbjFBIjJ (ORCPT + 99 others); Fri, 2 Jun 2023 04:39:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234569AbjFBIjB (ORCPT ); Fri, 2 Jun 2023 04:39:01 -0400 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A54B61A1 for ; Fri, 2 Jun 2023 01:39:00 -0700 (PDT) Received: by mail-ej1-x64a.google.com with SMTP id a640c23a62f3a-96fffd1ba46so123860266b.0 for ; Fri, 02 Jun 2023 01:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685695139; x=1688287139; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Jda3uobQ4e/ZCA/aiprMO5o6cFc2zo/SCaAFYYc33tg=; b=DFvkh47N53HAnKMaSELW4V5UCNV57afHZfDpHsQbNPQWG6vVmWUAMyY6VtEXz1YQiR 3Lu8UG9kFZRFFyB7VZynWl6GfzLf/9jfmOZzCopbdFVjW9mWsEnD5D4sTMlZu8abGq9S 95d1erpNNU62jVar/aq2xsolB5nR8c9G424Pu1mpSvMhhYLphXkcBe9vFcPYXTsglELv RfFFxliEjuCBwqR0XXwlZ7n2k7vawot5a6B+4TrWtqV54/bqkwEaK+plPxtRgCkZo6P4 xGI1AxScgSkVR93gdRmYPvkXiil7QfLJA9bZBVk8Gcp26NbOAJcfT1CEbOWO+GElbUGu Jl5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685695139; x=1688287139; 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=Jda3uobQ4e/ZCA/aiprMO5o6cFc2zo/SCaAFYYc33tg=; b=aJWAyNgrlXNStkksy2d6hJIU4pnE2MBYO8Y8Ydd4AIToK1yKVgZhxqizRuVXZXLszi KzgB3dFADOa3ho8U/A7QrxH/GcLggHamflJPhaPxhzNYaPwQx2hBf521Y0uELX/nv81N H5b/qg2YyZl805BBB14yTishVGw0fo4KnknP4rwqpo+6FsQAbJb1h6inAr6OYC/vOgq5 nbwFx0ukqMznPOzbCSNpI1QZDsTDqdIC0oKLyevm+r/jqjD8cqyOD3bnW5A/HqKozT5W C7VwkhDCCrJiN0mjTQ4VsYBLRH0JWdniMuhCdUchsf2sNUqWZULxaT9G7w8WLFn5Yqxf H1jw== X-Gm-Message-State: AC+VfDylvIdFh3u7uZEFKPONk+jLlv63ws1xy/TTDW4JMQ9eLB0XLm49 iN2kLeJqnCuZIoMoaRFUXC9OkWJV+NUed6Q= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a17:907:270c:b0:965:b935:91f6 with SMTP id w12-20020a170907270c00b00965b93591f6mr2890718ejk.14.1685695139208; Fri, 02 Jun 2023 01:38:59 -0700 (PDT) Date: Fri, 2 Jun 2023 08:38:56 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230602083856.1035444-1-aliceryhl@google.com> Subject: Re: [PATCH v2 5/8] rust: workqueue: add helper for defining work_struct fields From: Alice Ryhl To: boqun.feng@gmail.com Cc: alex.gaynor@gmail.com, aliceryhl@google.com, benno.lossin@proton.me, bjorn3_gh@protonmail.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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Boqun Feng writes: > On Thu, Jun 01, 2023 at 01:49:43PM +0000, Alice Ryhl wrote: >> diff --git a/rust/helpers.c b/rust/helpers.c >> index 81e80261d597..7f0c2fe2fbeb 100644 >> --- a/rust/helpers.c >> +++ b/rust/helpers.c >> @@ -26,6 +26,7 @@ >> #include >> #include >> #include >> +#include >> >> __noreturn void rust_helper_BUG(void) >> { >> @@ -128,6 +129,13 @@ void rust_helper_put_task_struct(struct task_struct *t) >> } >> EXPORT_SYMBOL_GPL(rust_helper_put_task_struct); >> >> +void rust_helper___INIT_WORK(struct work_struct *work, work_func_t func, >> + bool on_stack) >> +{ >> + __INIT_WORK(work, func, on_stack); > > Note here all the work items in Rust will share the same lockdep class. > That could be problematic: the lockdep classes for work are for > detecting deadlocks in the following scenario: > > step 1: queue a work "foo", whose work function is: > > mutex_lock(&bar); > do_something(...); > mutex_unlock(&bar); > > step 2: in another thread do: > > mutex_lock(&bar); > flush_work(foo); // wait until work "foo" is finished. > > if this case, if step 2 get the lock "bar" first, it's a deadlock. > > With the current implementation, all the work items share the same > lockdep class, so the following will be treated as deadlock: > > > mutex_lock(&bar); > do_something(...); > mutex_unlock(&bar); > > > mutex_lock(&bar); > flush_work(work2); // flush work2 intead of work1. > > which is a false positive. We at least need some changes in C side to > make it work: > > https://lore.kernel.org/rust-for-linux/20220802015052.10452-7-ojeda@kernel.org/ > > however, that still has the disadvantage that all Rust work items have > the same name for the lockdep classes.. maybe we should extend that for > an extra "name" parameter. And then it's not necessary to be a macro. Yeah, I did know about this issue, but I didn't know what the best way to fix it is. What solution would you like me to use? Alice