From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 AB5FB1D8E01 for ; Mon, 15 Jun 2026 07:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781507322; cv=none; b=sLX6+RT+we2Mr5A/MvsJu+IpW3paVgsm5ArobKj8wME8dVnSv1tNNjRb2574ffuu32Y9f9RDD5/MSvc0SUsMFX7XRWTdBskrf0wzovENlSlGPaCZPtN0FO3wnBv31MkVZPjxHF6TQpvJgrIb1dm/t3Fixu02BHggjaJ9TdUwWVU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781507322; c=relaxed/simple; bh=EtZsHXGORBwVqeszQ5g1BnT8+YvHTVwsuxAimPeUMB4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JhRwaSFnNA0fnjlTr6JjEbKwxF1aoibtXmvN6yng0qosAuqQOcEYe2lfWG02f7jO/t6zNRngI7JumJk9jnMb8tBFykB0kd4tNJwcEpPymEHqdFi59W2m5hT/snhlk27e6qhtwTcf26Bk/3VpbYqhqWMANi30SrKPDuoDP6pqIb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=g7AgYQCY; arc=none smtp.client-ip=209.85.218.74 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=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="g7AgYQCY" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-beefe797002so181506166b.2 for ; Mon, 15 Jun 2026 00:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781507319; x=1782112119; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=3avcrL+feJ8XKIwf79VCKKYQ6jkIiCpMK32dW2x0aSs=; b=g7AgYQCY2n1ly+fmYnhVyXaJInK64ImZIR+3Naiy9qybhMhPC0Y6lhMHApUrA5R46R vNrGLuSw/i8bGlTzg1C2r+mR1Hg+BS4ekYx6faMnoqFzM3QjMZ4Ye5oc90c1iVcohoR1 iAbgBcYdrM9UAf54STEq4ImnLL41olUZYkz36YaPXRr4cPkEyXCVEnXUbyfJ+9+30Rc9 84CVrvNWzu3MYmWBZzTZ24+IdPnK4JrthycqE1BjyMnCqBajTMy5L7f/U1KaE51UUt0I K6cvMHr+u+8o5Lw/nVxjPzV9TGn1ybmCc54CyfXLPP3saYNXkf+zo7aQRSgDw6DPxh5B 2r2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781507319; x=1782112119; h=content-transfer-encoding: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=3avcrL+feJ8XKIwf79VCKKYQ6jkIiCpMK32dW2x0aSs=; b=Thidsb3IyE9qmaz0s3ig3TGpA6xEpl4Hll4xfYMmZ2N4ASpRbLUFBi3CHg3PfFsZX3 gNR2BV83RW1/B+eauoDq+seZoZ4UzoCZA2XFVJEBUW6FgnrY3JinFzk3digq8BDUGyB6 r29opiAbeIZ1JyQHDIZqYkFv75DXLHjFe1OVG9otmJTNdA/fPRa3fiLkQIRb8y0vDmGV hVyBTHaH7YMZocYajYxO+UMBIer+rpJT5snf3vxKve/XWP5852NuZTJ2XAD78HxZbOjt A5q8dwPnIKMyR8aqOQNL0u/kT0eHnpsgvcK4UtCuWGA0lzFwIw0wVg6oMt/yFE5Vgjyt PiCQ== X-Forwarded-Encrypted: i=1; AFNElJ8Ywt+zvK5cyluZ/cJLHqOYycv/ydtVdIv4YaDkj4FpfDL2SgyQwnleKrbfLP3ib3ht1V3L/AkxG3CTyNM=@vger.kernel.org X-Gm-Message-State: AOJu0YxSA1OJSTTCHA6FROcyGiMFJHgYLIJBCT5Oyt20aUKN/EA8mZfw YeFTDdCaF9w4xn/oYwSCUlI/FF1jcFdGHeJZLpf+qJOBm92AGzI9lUbG27YxRhunbgDXji5mo33 KMvoYoRtRwycQzFeVmA== X-Received: from ejbay10.prod.google.com ([2002:a17:906:d28a:b0:bef:4adc:89c0]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3f87:b0:bd5:151d:2d31 with SMTP id a640c23a62f3a-bfe28907f3emr585984166b.13.1781507318912; Mon, 15 Jun 2026 00:08:38 -0700 (PDT) Date: Mon, 15 Jun 2026 07:08:37 +0000 In-Reply-To: <20260612194633.350011-2-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260612194633.350011-1-work@onurozkan.dev> <20260612194633.350011-2-work@onurozkan.dev> Message-ID: Subject: Re: [PATCH v2 1/1] rust: workqueue: add cancel_sync support From: Alice Ryhl To: "Onur =?utf-8?B?w5Z6a2Fu?=" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org, tamird@kernel.org, daniel.almeida@collabora.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 12, 2026 at 10:45:42PM +0300, Onur =C3=96zkan wrote: > Drivers can use this during teardown to cancel pending work and wait for > running work to finish before dropping related resources. >=20 > This is not implemented for Pin> because queuing a boxed work > item transfers ownership of the box to the workqueue. There is therefore > no separate safe owner that can cancel the boxed work while it is pending= . >=20 > Signed-off-by: Onur =C3=96zkan Overall looks reasonable to me, but some comments below. > rust/kernel/workqueue.rs | 116 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 116 insertions(+) >=20 > diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs > index 7e253b6f299c..4d61d7a10fae 100644 > --- a/rust/kernel/workqueue.rs > +++ b/rust/kernel/workqueue.rs > @@ -471,6 +471,23 @@ pub trait WorkItem { > fn run(this: Self::Pointer); > } > =20 > +/// Work item pointers that support cancellation. > +/// > +/// # Safety > +/// > +/// Implementers must ensure that `from_raw_work` rebuilds the exact own= ership transferred > +/// by a successful [`RawWorkItem::__enqueue`] call. > +pub unsafe trait SupportsCancelling: WorkItemPointer = + Sized { Nit; I think it reads nicer as SupportsCancel. > + /// Rebuild this work item's pointer from its embedded `work_struct`= . > + /// > + /// # Safety > + /// > + /// The provided `work_struct` pointer must originate from a previou= s call to > + /// [`RawWorkItem::__enqueue`] where the `queue_work_on` closure ret= urned true > + /// and the pointer must still be valid. > + unsafe fn from_raw_work(ptr: *mut bindings::work_struct) -> Self; I think you're missing some condition here about ownership having been transferred *out* from the workqueue by cancel_sync() or similar methods. Otherwise this currently says I can call the method even though the workqueue still owns the work item. > + /// # Note > + /// > + /// Should be called from a sleepable context if the work was last q= ueued on a non-BH > + /// workqueue. Nit: I'd either reword "Note" to something more specific to what the note is about, or remove the heading. > + #[inline] > + pub fn cancel_sync(&self) -> Option > + where > + T: WorkItem, > + T::Pointer: SupportsCancelling, > + { > + let ptr =3D self.dwork.get(); > + > + // SAFETY: `ptr` is a valid embedded `delayed_work`. > + if unsafe { bindings::cancel_delayed_work_sync(ptr) } { > + // SAFETY: A `true` return means the work was pending and go= t canceled, so the queued > + // ownership transfer performed by `__enqueue` is reclaimed = here. > + Some(unsafe { T::Pointer::from_raw_work(core::ptr::addr_of_m= ut!((*ptr).work)) }) Nit: The addr_of_mut! macro is no longer required. You can do: &raw mut (*p= tr).work Alice