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=1796382447; b=gr1gNRpdrL3gM9GXXFR1TXm8elkIk4D3ZEeb5dIADfl5Ec2BT3saz9a1GY+IuVB489B4 u+ZegWXBZkOyzmTfb5GmfyXHrG9QvoUUJB/eKgMcip0iP28EgocJjtEcziPeSlc3nstPX 3I3PlWMZQ/55YJ23E6OdRkhFSeMSSfwuUQTkf/rZLICdHO1Dqu1/+IvCt7AoBQUc7NIC+ r/XvunVjlqUSyxHAG7af3LgEFxEbuiyp+CcnqRuFUFQBztRlZvGRmC9Xx2oPQIpHLpvSf lyUEV6TGOdys/oytDtBrpN6cBnMxlFubbEi7JKhfA9+fdfyaNgvZh6bsqtQ2VUILjew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382447; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=R+RrmKnIqhUyC52UqSvQHtBScGni2kFjpRcuMQS6w9w=; b=dD4fQA78VGpwHXbofTL1Pl+VgX9D2K9yNMW3zVJx/Jss7wysGukPXqX23awiPmJZ6C/m ya+8jQhIh1Lz/8SP0Q8WC60g5NTLQdiP5xC3dhmlUVarOgak4JxesA+pDEHy+yhW/EMCb 1qlYT8sS/dcz9Yp1khpyKfzsskN0ipMdhoL8KMgvwYvSLq6vVoXxPJvQwb1LfbZJMGG8L kIYcPYL4z921iFejYLBG5n67Q5r+C8nK9oNfhuQCxDlAOFWkczSRWv4EEmCSW/ftK1Q+R nQBJNTVju7zs63rMMafqmiS5KnMNfjf6eVsg/K2F4uG+A75npQTno72yVad53HScHXw== 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=iShj8v8I; 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 5621E606A682; Fri, 4 Dec 2026 11:07:27 +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=iShj8v8I Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7B2A1F000C2; Fri, 4 Dec 2026 11:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796382447; bh=R+RrmKnIqhUyC52UqSvQHtBScGni2kFjpRcuMQS6w9w=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=iShj8v8ICDzv94ObyGRb0W7x281pYHzK2aGR7jRBCy+kpjWg+HEy3/xN+P6e5LrDO Aln/EBxVOL0RMbZQwEmjeD/YWcYdJdYAOD9LWzqcoxHVV6vhzWqV/SmKJNcsDIgZk8 wqz8gU+1eGVoqJsIQHRu+2r7K0UcNwgpvoR3IEWB3h0jRVtAxFyBdDfh55xUAfogxu 40gFei8yX9Ltb0mhNgUpaVf/Ddujd0kPnZM49tADYSEmGEDAnKHokdJ0se4Ada7J5i /gGXr3UkQizLke81VWSzvCNVZIeq3Q+lENQr7uKB0msUuQAHbq7j+WQ2wTkeBtAKrf jxJyAv1lrdeeQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 7/9] drivers: greybus: Add software SVC implementation 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-7-668b333ae71d@beagleboard.org> References: <20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org> <20261204-gb-uart-transport-v6-7-668b333ae71d@beagleboard.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:07:25 +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 8 potential issues to consider: - [High] greybus: double active/kref put in gb_operation_request_send() on send error - [Medium] greybus: gb_softsvc: missing greybus_disabled() check in GreybusSoftSvc::init() - [Medium] greybus: gb_softsvc: unbounded wait_for_completion() hangs GreybusSoftSvc::init() - [Medium] greybus: gb_softsvc: Svc::module_remove() frees IDs when MODULE_REMOVED fails - [Medium] greybus: permanent operation ID leak in Svc::send_request() - [Medium] greybus: redundant order-4 KVec allocation and copy in message_send() - [Medium] greybus: Module::new() can lock uninitialized GLOBAL_STATE mutex - [Low] greybus: MAINTAINERS entry omits drivers/greybus/gb_softsvc_exports.c -- commit dd5c33419b4fec58a4c57145f2773045c26979af Author: Ayush Singh drivers: greybus: Add software SVC implementation This commit adds the gb-softsvc Rust module, which implements an in-kernel software Greybus SVC and registers a Greybus host device for transports without a hardware SVC. > diff --git a/MAINTAINERS b/MAINTAINERS > index 6791104ed3ee4..a5399350a59e4 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -11690,6 +11690,12 @@ S: Maintained > F: Documentation/devicetree/bindings/net/ti,cc1352p7.yaml > F: drivers/greybus/gb-beagleplay.c > =20 > +GREYBUS SOFTSVC DRIVERS > +M: Ayush Singh > +L: greybus-dev@lists.linaro.org (moderated for non-subscribers) > +S: Maintained > +F: drivers/greybus/gb_softsvc.rs > + [Severity: Low] Should this entry also list drivers/greybus/gb_softsvc_exports.c, which is added in this patch to build gb-softsvc? [ ... ] > diff --git a/drivers/greybus/gb_softsvc.rs b/drivers/greybus/gb_softsvc.rs > new file mode 100644 > index 0000000000000..8fbcfe98e0848 > --- /dev/null > +++ b/drivers/greybus/gb_softsvc.rs > @@ -0,0 +1,570 @@ [ ... ] > + fn send_request(&self, hd: &hd::Device, ty: u8, payload:= P) -> Result<()> { > + let msg =3D Msg::request(self.new_operation_id()?, ty, payload); > + hd.data_rcvd(protocols::GB_SVC_CPORT_ID, msg.as_bytes()); > + Ok(()) > + } [Severity: Medium] Does send_request() permanently leak an operation ID from svc_operation_id whenever the Greybus core drops an incoming request? Operation IDs are only released in GbHdDriver::svc_handler() when a response arrives. However, gb_connection_recv_request() drops the request without sending a response on GFP_ATOMIC allocation failure, and gb_operation_response_send() does the same if response allocation fails. Once the pool is exhausted, new_operation_id() returns EOVERFLOW and blocks further SVC requests including Module::new() and Module::drop(). Since gb_softsvc never tracks pending requests by operation_id, a wrapping atomic counter like connection->op_cycle would avoid this leak. [ ... ] > + fn module_remove(&self, hd: &hd::Device, intf_id: u8, intf_count: u8= ) { > + let payload =3D protocols::GbSvcModuleRemovedRequest::new(intf_i= d); > + let res =3D self.send_request(hd, protocols::GB_SVC_TYPE_MODULE_= REMOVED, payload); > + > + if res.is_err() { > + dev_warn!( > + hd.as_ref(), > + "Failed to send module_removed svc request for {}", > + intf_id > + ); > + } > + > + // The ids stay taken until the core has removed the module, or = a new module could be > + // given them while the old connections still exist. > + hd.svc_flush(); > + > + self.map_remove(intf_id, intf_count, hd.as_ref()); > + } [Severity: Medium] Can module_remove() free interface IDs in intf_map while the old module and its connections are still live in the Greybus core? If send_request() fails, or if the core drops GB_SVC_TYPE_MODULE_REMOVED on allocation failure in gb_svc_queue_deferred_request(), gb_module_del() never runs. hd.svc_flush() then returns with the old module and its connections still registered. Calling map_remove() anyway breaks Module::drop()'s quiescing guarantee, as in-flight message_send() calls can still run InterfaceOps::write() after dr= op returns. A later Module::new() reusing those IDs is also rejected by gb_svc_process_module_inserted() while stale connections route traffic to i= t. [ ... ] > + let mut buf =3D KVec::with_capacity(msg.header().size().into= (), gfp_mask)?; > + > + buf.extend_from_slice(msg.header().as_bytes(), gfp_mask)?; > + buf.extend_from_slice(msg.payload_bytes(), gfp_mask)?; [Severity: Medium] Is this per-message KVec allocation and double copy necessary when gb_operation_message_init() already lays out header and payload contiguously in message->buffer? Because GreybusSoftSvc::init() advertises GB_OPERATION_SIZE_MAX (65535 bytes), bulk transfers over 32 KiB trigger order-4 kmalloc allocations on every outbound message, risking reclaim stalls and avoidable ENOMEM failure= s. Exposing a borrowed slice over message->buffer on kernel::greybus::Message, as es2.c uses directly, would eliminate both the allocation and the copies. > + > + intf.write(&buf, conn.intf_cport_id(), gfp_mask) [Severity: High] Can an error from intf.write() cause a use-after-free and active-count underflow on struct gb_operation when a timeout or cancellation races with message_send()? gb_operation_request_send() takes two active counts and two kref references and arms operation->timer before calling gb_message_send(). When intf.write() returns an error, HdDriverVTable::message_send() propagates the errno to gb_operation_request_send() without calling greybus_message_sent(). If operation->timer expires (or gb_operation_cancel() runs) while intf.write() is blocked, gb_operation_work() is queued and drops one active count and one kref. err_put_active in gb_operation_request_send() only cal= ls timer_delete_sync() and unconditionally puts both active counts and both krefs without checking whether completion was already claimed: CPU0 CPU1 gb_operation_request_send() get_active x2, kref_get x2 add_timer(&operation->timer) gb_message_send() GbHdDriver::message_send() intf.write() [blocks] gb_operation_timeout() gb_operation_result_set(-ETIMEDOUT) queue_work(&operation->work) gb_operation_work() gb_operation_put_active() [2 -> 1] gb_operation_put() [3 -> 2] intf.write() returns Err err_put_active: timer_delete_sync() gb_operation_put_active() x2 <-- active underflows to -1 gb_operation_put() x2 <-- frees operation early caller: gb_operation_put() <-- use-after-free / double free If err_put_active runs before gb_operation_work(), the worker instead hits a use-after-free on the freed operation. Underflowing operation->active to -1 also leaves gb_operation_cancel() stuck forever waiting for !gb_operation_is_active(operation). [ ... ] > + let dev =3D faux.as_ref().as_ref(); > + let hd =3D hd::Registration::new(dev, GB_OPERATION_SIZE_MAX, CPO= RT_ID_MAX + 1, Ok(data))?; [Severity: Medium] Should GreybusSoftSvc::init() check greybus_disabled() before registering the host device? When booting with nogreybus=3D1 (and CONFIG_GREYBUS=3Dy, as selected by RUST_GREYBUS_ABSTRACTIONS), gb_init() returns -ENODEV before registering greybus_bus_type or calling gb_hd_init() to initialize gb_hd_bus_id_map. Because gb_hd_bus_id_map is a zero-initialized static struct ida rather than DEFINE_IDA, hd::Registration::new() -> gb_hd_create() calls ida_alloc_min() on an uninitialized IDA (triggering lockdep or spinlock failures) and then adds the device to an unregistered bus. > + > + svc.send_version(hd.as_ref())?; > + > + // The handshake runs on the SVC connection's workqueue. Wait fo= r it, so `Module::new()` > + // works as soon as this module is loaded, and no handshake work= is left once it is. > + svc.handshake.wait_for_completion(); [Severity: Medium] Can this unbounded wait_for_completion() hang GreybusSoftSvc::init() forever? svc.send_version() and svc.send_svc_hello() submit requests via void hd.data_rcvd(), and svc.handshake.complete_all() only runs when a response reaches svc_handler(). If the core drops either handshake request or fails response allocation under memory pressure, no response ever arrives. Because wait_for_completion() is uninterruptible and has no timeout, modpro= be or built-in kernel boot would wedge permanently in TASK_UNINTERRUPTIBLE. Using wait_for_completion_timeout() (or an interruptible timeout) would let init fail cleanly and unwind. [ ... ] > + let guard =3D GLOBAL_STATE.lock(); > + let state =3D guard.as_ref().ok_or(code::EAGAIN)?; [Severity: Medium] Can Module::new() lock GLOBAL_STATE before GreybusSoftSvc::init() has called GLOBAL_STATE.init()? GLOBAL_STATE is declared with unsafe(uninit) via global_lock!, which requir= es init() before any lock() call. Because CONFIG_GREYBUS_SOFTSVC is tristate and drivers/greybus/ is linked after transport subsystems in drivers/Makefile, a built-in caller can reach Module::new() first. The same happens if initcall_blacklist=3D__gb_softsvc_init skips init when built-in. Locking the uninitialized struct mutex violates GlobalLock::new(= )'s safety contract and triggers immediate debug-mutex or lockdep failures. Returning EAGAIN instead of EPROBE_DEFER also causes call_driver_probe() to fail probe permanently instead of deferring. Guarding GLOBAL_STATE with a const-initialized Atomic flag (Release after init(), Acquire in Module::new= ()) and returning EPROBE_DEFER when unset would address both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-gb-uart-tr= ansport-v6-0-668b333ae71d@beagleboard.org?part=3D7