Linux cryptographic layer development
 help / color / mirror / Atom feed
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 v5 7/9] drivers: greybus: Add software SVC implementation
Date: Tue, 03 Nov 2026 16:32:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-195729@kernel.org> (raw)
In-Reply-To: <20261103-gb-uart-transport-v5-7-f8e326d6561f@beagleboard.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] greybus: gb_softsvc: unsynchronized async SVC handshake in init() and drop()
- [Medium] greybus: gb_softsvc: unchecked response result in GbHdDriver::svc_handler()
- [Low] greybus: gb_softsvc: commit message describes outdated NodeOps API
--

commit ee105f38d9a9f65cae00900a000f4081ef4dbafb
Author: Ayush Singh <ayush@beagleboard.org>

drivers: greybus: Add software SVC implementation

This commit adds gb-softsvc, an in-kernel software implementation of a
Greybus Supervisory Controller (SVC) in Rust for transports that do not
have a hardware SVC on the bus.

>     drivers: greybus: Add software SVC implementation
>     
>     A Greybus network requires an SVC (Supervisory Controller) to bring
>     interfaces up, assign device IDs and connect CPorts to the AP. On a
>     UniPro network the SVC is a real entity on the bus, but transports that
>     merely carry Greybus messages - a UART, an I2C bus, a network link -
>     have no such entity, so every host driver for those transports ends up
>     open-coding an SVC emulation of its own.
>     
>     Add gb-softsvc, a Rust implementation of the SVC that lives in the
>     kernel and registers itself as a Greybus host device. It answers the
>     SVC-side operations the core expects during interface bring-up and
>     teardown.
>     
>     Host drivers use it through a small in-kernel interface. A driver
>     implements the NodeOps trait to send data towards its node and then
>     calls module_insert() to announce a new node, submit_message() to hand
>     incoming Greybus messages back to the core, and module_remove() on
>     disconnect. Interface IDs are allocated by the SVC and returned from
>     module_insert().
>     
>     Connection create/destroy and interface activate/resume currently just
>     acknowledge the request; callbacks into NodeOps can be added later if
>     transports need to act on them.
>     
>     gb_softsvc_exports.c exports the Rust symbols for dependent modules, as
>     the build system does not yet support Rust cross-module dependencies
>     natively. This hack is taken from nova-core [0].
>     
>     [0]: https://lore.kernel.org/all/20260622-nova-exports-v5-0-6191773fc977@nvidia.com/
>     
>     Signed-off-by: Ayush Singh <ayush@beagleboard.org>

[Severity: Low]
As reported by Sashiko on v4 [1], does the commit message still describe an
older version of the public API?

The changelog states that host drivers implement NodeOps and call
module_insert() (to obtain allocated interface IDs) and module_remove(). In
drivers/greybus/gb_softsvc.rs, the public trait is InterfaceOps,
module_insert() and module_remove() are private methods on Svc, and drivers
use Module::new(), Module::submit_message() with a module-relative interface
index, and Drop for Module.

> diff --git a/drivers/greybus/gb_softsvc.rs b/drivers/greybus/gb_softsvc.rs
> new file mode 100644
> index 0000000000000..c9bff6a5fa658
> --- /dev/null
> +++ b/drivers/greybus/gb_softsvc.rs

[ ... ]

> @@ -0,0 +1,533 @@
> +            (
> +                false,
> +                protocols::GB_SVC_TYPE_INTF_UNIPRO_ENABLE
> +                | protocols::GB_SVC_TYPE_INTF_UNIPRO_DISABLE,
> +            ) => self.0.intf_unipro_enable_disable(hd, hdr),
> +            (false, protocols::GB_SVC_TYPE_INTF_ACTIVATE) => self.0.intf_activate(hd, msg),
> +            (false, protocols::GB_SVC_TYPE_INTF_RESUME) => self.0.intf_resume(hd, msg),
> +            (true, protocols::GB_SVC_TYPE_PROTOCOL_VERSION) => self.0.send_svc_hello(hd)?,
> +            (true, protocols::GB_SVC_TYPE_SVC_HELLO) => {
> +                let global_state = GlobalState::new(self.0.clone(), hd.into());
> +                let _ = GLOBAL_STATE.lock().replace(global_state);
> +            }

[Severity: Medium]
Should GbHdDriver::svc_handler() verify that the response header result is
GB_OP_SUCCESS before advancing the handshake and populating GLOBAL_STATE?

In drivers/greybus/operation.c, gb_operation_request_handle() always calls
gb_operation_response_send(operation, status) for non-unidirectional requests:

drivers/greybus/operation.c:gb_operation_response_send() {
    ...
    /* Fill in the response header and send it */
    operation->response->header->result = gb_operation_errno_map(errno);

    ret = gb_message_send(operation->response, GFP_KERNEL);
    ...
}

If gb_svc_version_request() or gb_svc_hello() fails in drivers/greybus/svc.c,
the core still sends a response over GB_SVC_CPORT_ID with a non-zero error
code in header->result and leaves svc->state uninitialized. Because
GbHdDriver::svc_handler() only matches on (hdr.is_response(),
hdr.request_type()), it will treat the failed response as a success and
publish an uninitialized SVC in GLOBAL_STATE.

> +            (
> +                true,
> +                protocols::GB_SVC_TYPE_MODULE_INSERTED | protocols::GB_SVC_TYPE_MODULE_REMOVED,
> +            ) => {}
> +            (false, ty) => {
> +                dev_warn!(hd.as_ref(), "unsupported request 0x{:02x}\n", ty);
> +                let rsp = Msg::response(hdr, protocols::GB_OP_PROTOCOL_BAD, ());
> +                hd.data_rcvd(protocols::GB_SVC_CPORT_ID, rsp.as_bytes());
> +            }
> +            (true, ty) => dev_warn!(hd.as_ref(), "unexpected response 0x{:02x}\n", ty),
> +        };
> +
> +        Ok(())
> +    }
> +}

[ ... ]

> +impl kernel::Module for GreybusSoftSvc {
> +    fn init(_module: &'static ThisModule) -> Result<Self> {
> +        pr_info!("gb_softsvc (init)\n");
> +
> +        // SAFETY: This runs once at module init, before anything else can reach `GLOBAL_STATE`.
> +        unsafe { GLOBAL_STATE.init() };
> +
> +        let faux = faux::Registration::new(c_str!("gb-softsvc"), None)?;
> +        let svc = Arc::pin_init(Svc::new(), GFP_KERNEL)?;
> +        let data = GbHdDriver(svc.clone());
> +
> +        let dev = faux.as_ref().as_ref();
> +        let hd = hd::Registration::new(dev, GB_OPERATION_SIZE_MAX, CPORT_ID_MAX + 1, Ok(data))?;
> +
> +        svc.send_version(hd.as_ref())?;
> +
> +        Ok(GreybusSoftSvc {
> +            _hd: hd,
> +            _faux: faux,
> +        })
> +    }
> +}
> +
> +impl Drop for GreybusSoftSvc {
> +    fn drop(&mut self) {
> +        let _ = GLOBAL_STATE.lock().take();
> +        pr_info!("gb_softsvc (exit)\n");
> +    }
> +}

[Severity: High]
Because the SVC handshake runs asynchronously on svc->connection->wq, can
GreybusSoftSvc::init() and GreybusSoftSvc::drop() race with the handshake work
items?

In GreybusSoftSvc::init(), svc.send_version() calls hd.data_rcvd() ->
greybus_data_rcvd() -> gb_connection_recv_request(), which only queues the
incoming GB_SVC_TYPE_PROTOCOL_VERSION request onto svc->connection->wq.
GreybusSoftSvc::init() returns before that work item and the subsequent
GB_SVC_TYPE_SVC_HELLO request complete and populate GLOBAL_STATE in
GbHdDriver::svc_handler(), so a consumer calling Module::new() right after
module init will see GLOBAL_STATE as None and fail with EAGAIN:

    pub fn new(intfs: &[Arc<dyn InterfaceOps>]) -> Result<Self> {
        ...
        let guard = GLOBAL_STATE.lock();
        let state = guard.as_ref().ok_or(code::EAGAIN)?;

In addition, when GreybusSoftSvc is dropped, GreybusSoftSvc::drop() runs
GLOBAL_STATE.lock().take() before its _hd field is dropped via
Registration::drop() -> gb_hd_del() -> gb_svc_del() ->
gb_connection_disable_rx(). If the asynchronous GB_SVC_TYPE_SVC_HELLO response
is processed on svc->connection->wq after GreybusSoftSvc::drop() clears
GLOBAL_STATE but before _hd is unregistered, GbHdDriver::svc_handler() will
reinstall GlobalState into GLOBAL_STATE and leak the Arc<Svc> and
ARef<hd::Device> references.

[1] https://lore.kernel.org/r/20261021-gb-uart-transport-v4-4-c308ce821d45@beagleboard.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261103-gb-uart-transport-v5-0-f8e326d6561f@beagleboard.org?part=7

  reply	other threads:[~2026-11-03 16:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 16:11 [PATCH v5 0/9] Add Greybus Sotfsvc and UART Node drivers Ayush Singh
2026-11-03 16:11 ` [PATCH v5 1/9] greybus: operation: keep request active across message_send Ayush Singh
2026-11-03 16:30   ` sashiko-bot
2026-11-03 16:11 ` [PATCH v5 2/9] greybus: svc: add gb_svc_flush() Ayush Singh
2026-11-03 16:11 ` [PATCH v5 3/9] greybus: operation: arm request timeout before sending Ayush Singh
2026-11-03 16:27   ` sashiko-bot
2026-11-03 16:11 ` [PATCH v5 4/9] greybus: connection: Add greybus_data_rcvd_by_intf() Ayush Singh
2026-11-03 16:11 ` [PATCH v5 5/9] rust: crc_ccitt: add CRC-CCITT abstraction Ayush Singh
2026-11-03 16:11 ` [PATCH v5 6/9] rust: kernel: Add greybus abstractions Ayush Singh
2026-11-03 16:28   ` sashiko-bot
2026-11-03 16:11 ` [PATCH v5 7/9] drivers: greybus: Add software SVC implementation Ayush Singh
2026-11-03 16:32   ` sashiko-bot [this message]
2026-11-03 16:11 ` [PATCH v5 8/9] dt-bindings: beagle: Add BeagleConnect Freedom Ayush Singh
2026-11-03 16:11 ` [PATCH v5 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-195729@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