From: sashiko-bot@kernel.org
To: "Ayush Singh" <ayush@beagleboard.org>,
"Jason Kridner" <jkridner@beagleboard.org>,
robertcnelson@gmail.com, "Johan Hovold" <johan@kernel.org>,
"Alex Elder" <elder@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Eric Biggers" <ebiggers@kernel.org>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Ayush Singh" <ayush@beagleboard.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Markus Probst" <markus.probst@posteo.de>
Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v6 7/9] drivers: greybus: Add software SVC implementation
Date: Fri, 04 Dec 2026 11:07:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-249656@kernel.org> (raw)
In-Reply-To: <20261204-gb-uart-transport-v6-7-668b333ae71d@beagleboard.org>
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 <ayush@beagleboard.org>
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
>
> +GREYBUS SOFTSVC DRIVERS
> +M: Ayush Singh <ayush@beagleboard.org>
> +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<P: AsBytes>(&self, hd: &hd::Device, ty: u8, payload: P) -> Result<()> {
> + let msg = 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 = protocols::GbSvcModuleRemovedRequest::new(intf_id);
> + let res = 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 drop
returns. A later Module::new() reusing those IDs is also rejected by
gb_svc_process_module_inserted() while stale connections route traffic to it.
[ ... ]
> + let mut buf = 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 failures.
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 calls
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 = faux.as_ref().as_ref();
> + let hd = hd::Registration::new(dev, GB_OPERATION_SIZE_MAX, CPORT_ID_MAX + 1, Ok(data))?;
[Severity: Medium]
Should GreybusSoftSvc::init() check greybus_disabled() before registering
the host device?
When booting with nogreybus=1 (and CONFIG_GREYBUS=y, 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 for 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, modprobe
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 = GLOBAL_STATE.lock();
> + let state = 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 requires
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=__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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org?part=7
next prev parent reply other threads:[~2026-12-04 11:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:30 [PATCH v6 0/9] Add Greybus Sotfsvc and UART Node drivers Ayush Singh
2026-12-04 10:30 ` [PATCH v6 1/9] greybus: operation: keep request active across message_send Ayush Singh
2026-12-04 10:55 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 2/9] greybus: operation: arm request timeout before sending Ayush Singh
2026-12-04 10:52 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 3/9] greybus: svc: add gb_svc_flush() Ayush Singh
2026-12-04 10:43 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 4/9] greybus: connection: Add greybus_data_rcvd_by_intf() Ayush Singh
2026-12-04 10:52 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 5/9] rust: crc_ccitt: add CRC-CCITT abstraction Ayush Singh
2026-12-04 10:30 ` [PATCH v6 6/9] rust: kernel: Add greybus abstractions Ayush Singh
2026-12-04 11:06 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 7/9] drivers: greybus: Add software SVC implementation Ayush Singh
2026-12-04 11:07 ` sashiko-bot [this message]
2026-12-04 10:30 ` [PATCH v6 8/9] dt-bindings: beagle: Add BeagleConnect Freedom Ayush Singh
2026-12-04 11:03 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 9/9] greybus: Add Rust UART node driver Ayush Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-249656@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=ayush@beagleboard.com \
--cc=ayush@beagleboard.org \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=ebiggers@kernel.org \
--cc=elder@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jkridner@beagleboard.org \
--cc=johan@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=liam@infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=robertcnelson@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox