From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5991939BFF5 for ; Thu, 30 Apr 2026 07:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777533683; cv=none; b=YH413w5ysDEvsKhBj3t2YUUWvXtHD0Y+bVpn8l4xkfDXSghNMLJGg0izkgEBqx0NwcZ5r/Dbx5XFAoi3M92lOaXpe+yuhdkysZAPnIV7VPI4PGS0eScXcRDIA69mhXTDcWqhPst6F5d3N8JOJ3Hg/xyFBYox3x7E3y/ljAODnf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777533683; c=relaxed/simple; bh=i3+WLAKfAX+e6Ihn2lZUEvyidiW3sc/I2J2M/ndOF9Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uPEd37LhlORuQxcsxxxc3L/3dR/kk+f/NpBMVLS9B9hgIaXiRKl9pG7GrFY7KjNmpL1JNbN19KxLKBOQ3A1f2mznZHfsvC1ZaRC/WfON1hZyANtm+s+OUUz09WY85C03cRt6WmifbAr8A0rmc4b7yeoI/0gBCMzWBD0kV0avcE0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pXjhJNzn; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pXjhJNzn" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-82f69adeecbso270816b3a.2 for ; Thu, 30 Apr 2026 00:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777533681; x=1778138481; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=GPGHrVasPB+CXaTZu+4tkkYEz/qnx98TzFtc857Z9wM=; b=pXjhJNzn7Pb4oVQBzZiFzoQiNQ9O998L3UWnTsyz8GlmhnoJa+CU8fyWOE2slSW6tI Y7656gi9h6O9IeRrwJV2WtfBq5jsRSsLxW0Z9f4Ezuh6KnDEeyaUwDhSywDo1LVdB+s2 eXHl3U5ZIV9putW8gRQjSsBVvRlxkm3uzQ+dqd7erLQD0c+jmLRs/Adv8tTj4yUsq3x2 zY/Ry/VQLXJ5LtcQU1/loArd8/LMwEol4bKE6PHsZFO/tg933qwseMs5ZXvnO3/KCvQ6 PchTOPkjILOZbvgylvW3hXP3LWUSSBZID6LZfrsCDZrky1tgHE0x1pmBsjadNJ7eh+aQ rJ1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777533681; x=1778138481; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GPGHrVasPB+CXaTZu+4tkkYEz/qnx98TzFtc857Z9wM=; b=p4P1krCW+l2CSQa/vDSNvO37qfr3viVk8KaxYG/xSZ0dTQFQk9aWTYskhN4Eib38mg zTarV08ojuIEUycTtv2hz2c4JnXpXY1pVDkOMZ1u2MZwMFh1NztmsZwXMiRrRphszX/5 gGNKUN70rCGUfgeDiDlP6rvrsjspC4aFV8zvWFKbLUMFnYyqAmLtvoPWT1nZOvpAcg6X RrL/Kv9vdlQYLilw/ecloCpI/I6FsOut0HiA0ElrEa64zG5SpfHxhL/sLpmoih+vbrmb qUOhpaepsWenTNIe9bnNSZ1JtXayGR6+r14XFs2+af9Z8wg3bK3VMgE2ifKDZc277sxu Q4xA== X-Forwarded-Encrypted: i=1; AFNElJ85Q6yQq8l7xmhDYoy1WZQUVSQvMgaXYWj1Y1JR3JBBQvqNRghsg3pNu6Uar2LQAJek69EdeBQntLYzbE4=@vger.kernel.org X-Gm-Message-State: AOJu0YyVXRvZytvPN9gawCWeWfBHpZc0ckvMoR3le71HYQ7VMB4L6pha Y0NsEirXspjEV/eqlRE88rWg5F6fy5m0kZKwiGlw7Hi1zHtxOlxQFesv X-Gm-Gg: AeBDieuKiEKuB/pfMHwridnZRZwpN9jmE5hK6GuQZXA6N17tLgW9SNwKChquECs+1Qx eRzlEvKxYhTA80fPNQgoLKPiZBNh8H3D3Hzch3vdnOp10Cx1PSXLCEgKzKMgNLSU38JHDtUXPvX I6YKOX0O3gaSFG14fHsZYq/DtKjQNx0xfXRcEej+1J433I/6yscQcmFiH7s3IdyYZ2AqbV+JnAP oF1FkjZHuf9M/HKN2r4db32+rc2ES5bxuCsDmn/sspW6RDkrKr/J/w3vmj9GxU40Wfq3X2rkMTn oRzwOEiRiNE6B5ySCJ0OmZ2k5P+AH4YBV2vnbV7UKu/+J4y1oNqTbAHicBsM0+vQlFLTdBJiTEK nY+t+aU3QkJGvyrsDQV278aDcLxMLvtkERTC3piA0dy4zFxG8TGTO+lwUPLaF0EJEReyDfFUoS5 Vi/Kf9q9fspn1GHwiPXkIAC50g+Ax4Q8eSNlLXHgAzUfQLjxC4R9w= X-Received: by 2002:a05:6a00:1d94:b0:82f:52dd:4446 with SMTP id d2e1a72fcca58-834fe25dac2mr1882826b3a.45.1777533681515; Thu, 30 Apr 2026 00:21:21 -0700 (PDT) Received: from Nighthawk.localdomain ([223.178.220.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed5cd3b8sm4593856b3a.16.2026.04.30.00.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 00:21:21 -0700 (PDT) From: Sagar Taunk To: Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , Daniel Almeida , Sagar Taunk , Viresh Kumar , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] rust: workqueue: replace SAFETY TODO for `WorkItemPointer` impl on `Pin>` Date: Thu, 30 Apr 2026 12:49:28 +0530 Message-ID: <20260430071930.73696-1-sagartaunk2@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The original implementation left a `SAFETY: TODO` comment on the `WorkItemPointer` implementation for `Pin>`. This patch documents the safety requirements that make this implementation sound. The safety argument follows the same structure as the `Arc` implementation and relies on three guarantees: `__enqueue` strips the `Pin` wrapper via `Pin::into_inner_unchecked` and leaks the box via `KBox::into_raw`, producing `*mut T` whose allocation remains live for the duration of the queued work; `work_container_of` safely reverses the `raw_get_work` offset arithmetic to recover the exact `*mut T` that `__enqueue` produced; and the workqueue guarantees `run` is called exactly once, making `KBox::from_raw` sound. Signed-off-by: Sagar Taunk --- rust/kernel/workqueue.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 74c59f2b1c09..676ade0539e3 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -881,7 +881,15 @@ unsafe impl RawDelayedWorkItem for Arc { } -// SAFETY: TODO. +// SAFETY: The `__enqueue` implementation in `RawWorkItem` uses a `work_struct` initialized with +// the `run` method of this trait as the function pointer because: +// - `__enqueue` gets the `work_struct` from the `Work` field embedded in `T`, +// using `T::raw_get_work` on the pointer obtained from `KBox::into_raw`. +// - The only safe way to create a `Work` object is through `Work::new`. +// - `Work::new` makes sure that `T::Pointer::run` is passed to `init_work_with_key`. +// - Finally, `Work` and `RawWorkItem` guarantee the correct `Work` field is used +// because of the `ID` const generic bound, and `Work::new` picks the correct +// implementation of `WorkItemPointer` for `Pin>`. unsafe impl WorkItemPointer for Pin> where T: WorkItem, -- 2.54.0