From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.128.47 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796058305; b=37EA7uai8pduL8dd5WTbyxOtiApLf1OEoqiiL4HQDa7MKqP/K/ddjYbUCmAXHqh6DXMI urir2c/IOGsZkN+BnMpgzZJobqcCfQwQy5/J8Alonzj82C1r+sNx/TV8RQqwho2ZKVY3Q 8/R7+T0NR3X4WrBO+XA0mc0zNvy0mX9BuoytCLTNbRYGuTEOzT2YsBxOS2nzyeV+2EQlk fjaPAKQYGjWYG9GEp2DMyvR39Gmwte20OHWO/VZ5lxOnlDEsWlwxUJVV54GLNFbUlvUvx mT8FCmavncAQoHsEMg0CPKqmU7Ms/hDs5DQgHLayuYmQKSmbCktSfKxHjps+wLVNrxw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058305; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: MIME-Version:References:In-Reply-To:From:Date:X-Gm-Features: Message-ID:Subject:To:Cc:Content-Type:Content-Transfer-Encoding; bh=oYVM8Yy1e47McKB4PgDffoL03AzxFOTT+5zxNBwjJxw=; b=05iuMt4kJMqZpaoYZWWbPB4FnAef1YWafVOs1vXS9JRuvgitoTXudhrMcrkLMgeKM4WR +LT6JPC6apIJkd2dRnURU6JXzdZR/oqJpN4mBhQXl+aVNrVLLC+3x45DOuWmUEfvkLuIV glHQiiWRIu9MibJgKm7aIFRxLw0TQ8AgA4IJeAxAUMpxodbho2Y1E4R4+6bacH5RVI96V UatOKOZ7PP86qBKoWSdIN+RmFg0zc/gu8sQHtreMzEqHDgfBOIHVlTtf/LEkkVvdbg5Y2 /FuRDiah402gmVYhITaLmPZ+IsYtinh7XS7WoeYEHKIgSsxpYuVgHxA5GTQuqGVBvHg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Wc1Zqs+n; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E1A3606A337 for ; Mon, 30 Nov 2026 17:05:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E1A3606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Wc1Zqs+n Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4b467581b98so100553985e9.0 for ; Mon, 30 Nov 2026 09:05:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796058303; cv=none; d=google.com; s=arc-20260327; b=EU3w6vhU3tueRvGCnCIbhSwKH1ioyO0RmL7SlcjoY+dK4/K+5mPyGa/AN+Omw7cJku hDSaj80I+DdXqU2ZMyI02Mf9eHqc2UEOJgGWsQFWMWvxPB66HlRmh5aMyxSbVv2ACrQP 1X/GNLNMngkUzVoCfkIGILKFrzfwAREmWfZZw5l/M1bnWOjxeVVgMzmZi4vjHQuqD9od 2iK/Cu8sOBkUOdUkKLxgjE6aZy/Mwq6fkeMtvYhQcOD9a2w7B2UwkjsK3LgOnz5wayxr 7bBL92z80KjTfBCkaFU11f1TVXnm7R0eLU8exInOirknRrgKKU4iOmfBCd32ulaAbGYr oeEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oYVM8Yy1e47McKB4PgDffoL03AzxFOTT+5zxNBwjJxw=; fh=IcLqxwB8PFBCfL11x0qp+ATre2Imwv//pzhyTBx1RMU=; b=b4Do8VUj25FtMu8e8R81p2dtl2LG2a8AaVAcJ20rCDOH721NYA4jXX2GodzeaCUOhf 7s0KHu4J2sAmvtgFGA4LFWrHFmLcm4puTKxN0xkJGUImhnRUT6znXfUfDsGLfS7xc8Fi p4Lnu2rIYf9i2Br0Nz2ivJEhQtVxmwAhZAvPV4ODMd6YiqdfbkbVK+6xb2dNRu0qpYft H9zX6z0OrapvquvpySndNAyeB5BmMAdDw4T7/TdHBaNXVSss0A68+nUA1JEPHD0j22Z9 c+s5xnlAFPtOGWUZXoYNyBR1bfGXi1gCsVlKeHujNIF6cjpjl82g925PdDp44XnFXw73 /neg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796058303; x=1796663103; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=oYVM8Yy1e47McKB4PgDffoL03AzxFOTT+5zxNBwjJxw=; b=Wc1Zqs+nVOxk6e3uw4UPBBljUUwZlUXAY1of+oBgWnb58tnp/JI8VXaKFvT1x1ZwhC iqmn97rFs6wN6q3WGcUWomDKyzhbP5zSTwgBhA3yBTRB5kn7ie6jSGQE9RyBZfi6IGIH XAQKUYS+K943ueFE1GZfeUOxiQP2t3ODuit+KM6t0hVnL7hUgv6Z7dFAQJ7fO9fpQvC4 h2FJ+R9qxWUnFjO8qA4fP7AooQhkn4PCyH7SIl5OcOv+szQjnhIPrf8Lx2hztFC25Xrd 2pUTczX4JORpfNHZOvV1htvveddA2o4FmlQha1MECMxKQfEimpAvukjvE4G2h9hN9eGi +a3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796058303; x=1796663103; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oYVM8Yy1e47McKB4PgDffoL03AzxFOTT+5zxNBwjJxw=; b=i0eBY4uejUA3+zLtSW/P5mKmXojEYXg/Vi1+utXWJdn/hlV4B+Phep2eN3zUby/3I3 5rXaoulc3nH+fplvOx9eHVLbSaOP9+uQDhmQe5vO8kVRaxkmNKBqNQ887rUCCf5z/PGC cUoOLBjEBnNty59Xm4DPrGuwxPTMS5cFEO9B0i5z50o5yKu6sRBl0ZT8RNj55EiweX/+ kiWGj5exh2m/HH4sFqARfxZY5H0gBx10CGT76pyY8Qx/46BrzhMF6RT2wuk3N/BnN41n 9l6q+ZW7wavqvjDyoBog69AhWoi/cABjVZzl/iwb/6vUyiTevAZHkBy5s+DdTSG8jltX uYKg== X-Forwarded-Encrypted: i=1; AL+hErF/4bCgOQCJZvN+yFpy0B62ClZ98LvIbS7kHVfwtC/14XnDViQWupWNDetGZaqreuWPK0rXH2dfwNPuKaE=@vger.kernel.org X-Gm-Message-State: APuU4Z+vBZdbrGUGMCSgqWiPY9Wd/Nt+hskF361uBrYQztFx4xjI/+Td cjKILlZdhuetSY/0Fa7vbDnHd9oISCjrVxUVFWVIRjSy+CEpx9OOOs5zpGayqGVIylNPi5y7mlA z/Pt4N9oy7nsTD+JVsdgiO676p1JtAr6nsRXZx6Al X-Gm-Gg: AZFdTZf/TMkrhNdMgayityPa2q9N0k8ZWSrNHsYonkLhFEnyFFrZJsh+Nbaz/hO6jPa QSYqRHxFhS5ILiOgpCwj8TiVqK1lZZngfXlaCxWfYbtOMdmD2tn3l2A6UJAE74GWJ/hYrCBign9 zPiZr9ha16s48E6fCeKTRlJVZFivwTfToiDxWd73tenu4sMsppC2LFqYVCOR6EfU0jqyg4ivMBb a1e/6HPYPs2rGWPOaBSPsCjnACV7BROYr6CXxXkcDbcHXGYCjkH72dpdjbuHXeWlvbsL0JoIcHS n9ui40JJVyAdJkBOEinh3T2Kj+uYx1hSV4UAMUxZaWxzSj9go3nlRF9Hws/XYz0DTUk8oXXTJmB u5cj4QTuA62wKEtx3f3bTk8Q/3T3l7iqwBPnTyAKoFZTaeTaNLJ7Y4R3s4QLLuZp+rGCQ+tWZXQ == X-Received: by 2002:a05:600c:6708:b0:4ba:7e6:53d6 with SMTP id 5b1f17b1804b1-4bb88940848mr611335765e9.33.1796058302382; Mon, 30 Nov 2026 09:05:02 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 References: <20261119-rust-workqueue-v4-0-707c68994940@google.com> <20261119-rust-workqueue-v4-5-707c68994940@google.com> <5eec17370f67438e43bb1c82b1d6a16b@kernel.org> <20261125181752.2027207-1-aliceryhl@google.com> <2ac377700fd9cd17c32aae2a9d3dbea7@kernel.org> In-Reply-To: <2ac377700fd9cd17c32aae2a9d3dbea7@kernel.org> From: Alice Ryhl Date: Mon, 30 Nov 2026 18:04:50 +0100 X-Gm-Features: Aa3M54qUEsfFkpWdNjjBVrk-wSFwz2p7NQzGyv5ncBHPGPKLktqQxQ7qxZcXVGQ Message-ID: Subject: Re: [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items To: Tejun Heo Cc: Lai Jiangshan , Danilo Krummrich , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?Q?Onur_=C3=96zkan?= , John Hubbard , Philipp Stanner , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Nov 27, 2026 at 5:12=E2=80=AFPM Tejun Heo wrote: > > Hello, Alice. > > On Thu, Nov 26, 2026 at 12:43:07PM +0000, Alice Ryhl wrote: > > Of course, there may be other ways to enforce the non-reentrance > > conditions hold, which could let me get rid of the lifetime. But the > > lifetime is there to handle the cleanup before destroy_workqueue() is > > called case, so a percpu refcount does not come into play. > > I didn't explain myself well. I'm not saying that the current scheme > doesn't work. My concern is how easy the interface is to use, and I wonde= r > whether taking workqueue lifetime out of the compiler-managed lifetime > rules could make it simpler. Something like the following: > > - Every Rust work item and delayed work item is bound to one workqueue. > > - A Rust workqueue has a percpu refcnt and each work item bound to it > holds a reference. > > - Destroying the workqueue waits for the refcnt to reach zero. A leaked > work item then stalls workqueue destruction, which seems like an okay > failure mode. > > Work items bound this way never move between workqueues, and neither > delayed work items nor ScopedWork would need the workqueue to be 'static > or carry its lifetime. This doesn't solve data or device lifetimes but it > decouples them from the workqueue's, and device accesses can use workqueu= e > destruction as the draining point. > > We can add whatever is needed on the workqueue side to make draining work > well, e.g. an operation which expires a workqueue so that work items > queued on it afterwards are dropped without running, self-freeing ones > included. > > Workqueue looks the way it does because it's C and leaves all lifetime > management to its users. Carrying the same model over to Rust and then > wrapping it for each use case seems like a missed opportunity. I don't > know Rust well, so I could just be blowing hot air. I guess we could always just store the address of the workqueue it's tied to, and require a reference to it on enqueue(), with an equality check. That way, it's not a problem if the workqueue gets freed before the work item, but we still enforce no workqueue migration. Alice