Re: [PATCH 1/2] bus: mhi: host: Add debug port personality switching

From: Manivannan Sadhasivam

Date: Wed Dec 02 2026 - 07:35:09 EST


On 2026-11-13 20:23 +0800, Hongxing Xu wrote:
> Modems expose two different sets of MHI channels depending on the product
> configuration they are running. In the commercial personality only the
> channels that carry user traffic are usable, so the host must not create
> WWAN ports for the diagnostic and debugger channels. In the debug
> personality those channels are active as well and userspace needs a
> device node for each of them, e.g. one for the diagnostic interface on
> top of the MBIM and AT ports.
>
> Which channels are usable is a property of the firmware that is running,
> so the host cannot know it at probe time. It has to be told at runtime,
> after the device has booted into mission mode. There was no way to do
> that: mhi_create_devices() unconditionally created a device for every
> configured channel whose EE mask matched, so the debug channels either
> always appeared or never did, depending on whether the controller driver
> declared them.
>
> Add a per-channel debug_only flag and a debug_ports attribute that lets
> userspace switch the personality. Channels carrying the flag are skipped
> by mhi_create_devices() unless the debug personality is active, and are
> created or destroyed when it changes. The flag defaults to false, so
> existing controllers keep behaving exactly as before and the attribute
> describes itself as having no effect on a controller that does not
> declare any debug-only channel.
>
> The attribute is part of the bus-wide attribute group, like the
> existing controller attributes. That group is applied to every MHI
> device, including the channel devices created here, so debug_ports_store()
> accepts a write only from the controller device. A write from a channel
> device would otherwise tear down the device that is executing the store.
>
> Device creation and destruction cannot be done from the sysfs store
> directly. The state transitions create and destroy devices on
> hiprio_wq, and pm_mutex does not exclude them: they drop it before
> calling mhi_destroy_device() through device_for_each_child(). The
> request is therefore queued on that same ordered workqueue, which
> serialises it against the transitions. The store flushes the work before
> it returns, so the ports are in place when userspace regains control.
>
> mhi_create_devices() is split so that the bidirectional pairing logic
> has a single instance. mhi_create_device() takes the channel index by
> reference and advances it past a UL/DL pair, which is what lets
> mhi_update_debug_devices() walk the channel array without revisiting the
> second half of a pair.
>
> Signed-off-by: Hongxing Xu <xing1989093@xxxxxxx>

NACK to both patches as they are fundamentally wrong. I don't see any sane
reason to guard any of the currently exposed channels to userspace, certainly
not DIAG, which you are guarding in patch 2. And the reasoning you gave to Jeff
were not at all justifying (atleast on why these properties were exposed as
sysfs attributes).

- Mani