From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381739; b=mioB6ubsjDCkPbbJyfdrTV1w1z/uQhUbkNkI0b6ITCYvoIZ9iHkPUOlFTc0nlRCTdqP5 IThobGtV+d8oOMhnjY2VcF6GtSIMi6XaaA52Aak1nH6bWAE+N0IK9kMhmm51NMhNfbqp9 Yg3dxMBTfAFgWjAkaraSsiSewIxdCNf2DqYUPkrfIEdayWPu+6S43QQqe1kU/BGxednyL t0wklWf84eNx5Rr31QQhLM4Tv6JGw3+sACc5DBSIvzOIt7nWyUb3JjdTlrPlEaGiuD/Hl z9KLL/cpGbqS3gAeoQfIJW2aGjJtG9xYpVRDNp8YbVnCUUD1Tx+ObRG5/ri2stZ1ToQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381739; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=yGRIAS7ma8St/qDSgbywY08pMb06Mt90KIOVtrUI0SY=; b=okDdiAHxFTzlEJUudgPk6FfMhTDJWo2Y2+qqQzrofB0rWmsSQMnQojagSpzOO78ZmhZA uNbFQncyK0sq9VAGl4SjMjAbLj6bdfYDUve4OuVQ2JEESN92g4nOQanXn7ZExY03+Dz7v uoAN2UsgakIS0upkszPLa0NEn3IxdJhBl7oSk44TmHhgz1v1N1+fwQr2I0odkGu0878MY DqfwpY9kfNk0bFwvSEQRWg5QvGWMnCDAt9l/RuRHIl5b3u3vs0AiHDy77wW1o5duSL3tZ 16rB7US8b4EVTbHWFKTkMhrJn2meyucEwprNDqAkTMPCYCzKHw9+1cv0ZA//3K31dmw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iLGcL6oz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B419C606A33A; Fri, 4 Dec 2026 10:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iLGcL6oz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 037791F00897; Fri, 4 Dec 2026 10:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796381739; bh=yGRIAS7ma8St/qDSgbywY08pMb06Mt90KIOVtrUI0SY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=iLGcL6ozXvjEn0ZOHxXAHKBe0O51aSOmu9z2XVQr4tSWQOMkcLPI8hp2uDDbmqrCi 2pD8RA6oDmwvz7Utxyz9boeJRALJ/acB8BDLjWSaKvQ5jAu8LWrTpDoN9/YkpoIeNu G79RWPp4N8+7ZwpnjIA5kSBzWFuEBBpWsqXCbWY3O2O//R+Fz4hWunrZCGpL3dipjY 7noRafgZILiWr+dBSn+TBWp7F7ZHqqQ+8PO6OQtS18uJWls0T9/0zAdRQRyRWmRl6R kuz5U0DtED3tNd7jHhxx8j0qiUJPIwHoQpT4RtVAB3p1iXYuHXcj93IhZKjUs8Mmmx W7/nc4WWlRpdQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 1/9] greybus: operation: keep request active across message_send Reply-To: sashiko-reviews@lists.linux.dev To: "Ayush Singh" , "Jason Kridner" , robertcnelson@gmail.com, "Johan Hovold" , "Alex Elder" , "Greg Kroah-Hartman" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?Qmo=?= =?utf-8?b?w7ZybiBSb3kgQmFyb24=?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?b?T251ciDDlnprYW4=?= , "Eric Biggers" , "Ard Biesheuvel" , "Ayush Singh" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Lorenzo Stoakes" , "Vlastimil Babka" , "Liam R. Howlett" , "Uladzislau Rezki" , "Markus Probst" Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org In-Reply-To: <20261204-gb-uart-transport-v6-1-668b333ae71d@beagleboard.org> References: <20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org> <20261204-gb-uart-transport-v6-1-668b333ae71d@beagleboard.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:55:37 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] greybus: double put on gb_message_send() error races with cancellation - [Medium] greybus: gb_operation_cancel() skips gb_message_cancel() on set result - [Medium] greybus: commit message and greybus_message_sent() comment are stale - [Low] greybus: commit message is missing Fixes trailer for teardown bug fix - [Low] greybus: open-coded connection->lock in gb_operation_request_send() - [Low] greybus: missing Fixes trailer for teardown active-count race fix -- commit 2a2ce0ef899bb0644246f2ca7d0a08a37a9ea029 Author: Ayush Singh > greybus: operation: keep request active across message_send > > gb_operation_request_send() takes a single active count, and completion > drops it. This would be fine normally, but in case of cancellation (in > gb_softsvc context, this would happen in module_removed), completion > (gb_operation_work), can drop the active count, while message_send is > running. > The core does call message_cancel before dropping the active count, > but in most normal circumstances, cancelling an operation that is > already writing over a protocol (UART) is not really possible. So we > are only left with making the core wait for the said write to complete > instead of making active count 0 while message_send is in progress. > The patch takes a second reference and active count before the send > and drop them once it returns. If the connection starts tearing down > between the two calls, return 0 and let the cancel complete the > operation. > Since it took at least me a while to truely understand what the initial > sashiko-bot report meant, here is an example: > Thread A Thread B + worker ac= tive > ------------------------ ------------------------------ --= ---- > 1 get_active() 1 > 2 gb_message_send() > 3 GbNode::write() ... > 4 ... blocked state =3D DISCONNECTING > 5 ... blocked gb_operation_cancel() > 6 ... blocked result_set(-ESHUTDOWN) > 7 ... blocked queue_work(completion) > 8 ... blocked wait_event(!active) [sleeps] > 9 ... blocked [worker] gb_operation_work() > 10 ... blocked [worker] put_active() [:292] 0 > 11 ... blocked wait_event wakes, returns <- = too early > 12 ... blocked gb_module_del() returns > 13 ... blocked [softsvc] Module::drop finishes > 14 ... blocked serdev port closed, unbind done <- = bad > 15 write() returns > 16 return to caller > > This patch simply takes an extra active count when calling > gb_message_send. in core. It also treats both requests and response > the same, i.e. clear an active count when gb_message_sent() is > called. Earlier, this was only being done for responses. > > Signed-off-by: Ayush Singh [Severity: Medium] Does the third paragraph of the commit message match the actual code? It says the patch drops the second reference and active count once gb_message_send() returns and returns 0 if the connection starts tearing do= wn between the two calls. The implementation instead acquires both active cou= nts atomically under one connection->lock via __gb_operation_get_active() and drops the second count in greybus_message_sent(), which runs asynchronously for drivers such as es2. The final paragraph also misspells greybus_message_sent() as gb_message_sen= t() and has a stray period in "gb_message_send. in core.". In addition, the comment in greybus_message_sent() keeps the obsolete response-only paragraph directly above the new unified description. [Severity: Low] This fixes a connection teardown active-count race introduced when per-connection active-operation tracking was added. Should this include: Fixes: 008974cb528d ("greybus: operation: fix connection tear down") > diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c > index 7e12ffb2dd60d..a9eada39ec793 100644 > --- a/drivers/greybus/operation.c > +++ b/drivers/greybus/operation.c [ ... ] > @@ -758,11 +772,17 @@ int gb_operation_request_send(struct gb_operation *= operation, > gb_operation_result_set(operation, -EINPROGRESS); > =20 > /* > - * Get an extra reference on the operation. It'll be dropped when the > - * operation completes. > + * Take two references and active counts. One is dropped when the > + * operation completes, the other when the host driver is done with the > + * request, so that cancelling the operation waits for both. Take both > + * counts under one lock, so the operation can't be cancelled in betwee= n. > */ > gb_operation_get(operation); > - ret =3D gb_operation_get_active(operation); > + gb_operation_get(operation); > + > + spin_lock_irqsave(&connection->lock, flags); > + ret =3D __gb_operation_get_active(operation, 2); > + spin_unlock_irqrestore(&connection->lock, flags); > if (ret) > goto err_put; [Severity: Low] This isn't a bug, but __gb_operation_get_active() is only called from gb_operation_get_active() and here, and no other work is done under connection->lock. Having a locked helper take the count argument would avo= id open-coding spin_lock_irqsave()/spin_unlock_irqrestore() in gb_operation_request_send(). [ ... ] > @@ -779,8 +799,10 @@ int gb_operation_request_send(struct gb_operation *o= peration, > =20 > err_put_active: > gb_operation_put_active(operation); > + gb_operation_put_active(operation); > err_put: > gb_operation_put(operation); > + gb_operation_put(operation); > =20 > return ret; > } [Severity: High] Can err_put_active underflow operation->active and double-put operation if gb_operation_cancel() runs while a failing gb_message_send() is in progress? While gb_message_send() is sleeping (for example in hdlc_tx_frames() in drivers/greybus/gb-beagleplay.c before returning an error), connection teardown can cancel the operation and queue gb_operation_work(): CPU0 CPU1 kworker gb_operation_request_send() __gb_operation_get_active(..., 2) gb_message_send() gb_operation_cancel() result_set(-ESHUTDOWN) queue_work(&op->work) wait_event(!is_active) gb_operation_work() op->callback(op) put_active() [2->1] put() /* returns error */ err_put_active: put_active() [1->0] put_active() [0->-1] <-- active underflow put() put() <-- extra put / use-after-free Because gb_operation_is_active() converts signed int operation->active to bool, -1 stays true permanently and gb_operation_cancel() hangs in wait_event() while holding connection->mutex. The extra gb_operation_put() causes a use-after-free on operation, and returning non-zero after operation->callback() has already run causes async callers such as gb_loopback_async_operation() to double free op_async and underflow outstanding_operations. Even if cancellation does not race during gb_message_send(), calling gb_operation_put_active() twice in separate lock sections leaves operation = on connection->operations with active =3D=3D 1 in between. If gb_operation_wo= rk() runs after err_put_active instead of before, operation can also be freed wh= ile operation->work is still queued. On gb_message_send() failure, calling gb_operation_result_set(operation, re= t) can arbitrate completion ownership: if it returns true, drop both active counts under one connection->lock and both krefs and return ret; otherwise drop only the host driver's active count and kref and return 0. [ ... ] > @@ -892,15 +917,15 @@ void greybus_message_sent(struct gb_host_device *hd, > "%s: error sending response 0x%02x: %d\n", > connection->name, operation->type, status); > } > - > - gb_operation_put_active(operation); > - gb_operation_put(operation); > } else if (status || gb_operation_is_unidirectional(operation)) { > if (gb_operation_result_set(operation, status)) { > queue_work(gb_operation_completion_wq, > &operation->work); > } > } > + > + gb_operation_put_active(operation); > + gb_operation_put(operation); > } [Severity: Medium] Now that greybus_message_sent() drops the second active count for outgoing requests, can gb_operation_cancel() hang if operation->errno was already set before teardown? With an async host driver such as es2, if gb_connection_recv_response() set= s a non-ETIMEDOUT result before the bulk-OUT URB completes, gb_operation_work() does not cancel the request message and drops operation->active from 2 to 1. A subsequent gb_operation_cancel() then skips gb_message_cancel(): drivers/greybus/operation.c:gb_operation_cancel() { ... if (gb_operation_result_set(operation, errno)) { gb_message_cancel(operation->request); queue_work(gb_operation_completion_wq, &operation->work); } trace_gb_message_cancel_outgoing(operation->request); atomic_inc(&operation->waiters); wait_event(gb_operation_cancellation_queue, !gb_operation_is_active(operation)); ... } If the bulk-OUT URB is stalled, greybus_message_sent() never runs and teardown blocks indefinitely in wait_event() while holding connection->mute= x, unlike gb_operation_cancel_incoming() which cancels the message even when gb_operation_result_set() returns false. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-gb-uart-tr= ansport-v6-0-668b333ae71d@beagleboard.org?part=3D1