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

From: Jeff Hugo

Date: Tue Dec 01 2026 - 17:06:34 EST


On 11/24/2026 5:43 AM, Hongxing Xu wrote:
Two questions, both pointing into this patch, so answering them together.

+What: /sys/bus/mhi/devices/.../debug_ports

Why sysfs and not debugfs?

Because this is not a debugging aid. It is a documented ABI that end
users and provisioning tools drive on a shipped system, and it has to
remain available there.

How is this not a debugging aid? Your patch subject says "Add debug port". Your commit text mentions a "debug personality" and "debug ports" among other uses of "debug".

I'm confused, debug != debugging?

I didn't ask this before, but since you are claiming this is not a debugging aid, how does one put the device into this alternate mode? Load a signed APDP (Apps Processor Debug Policy) file? That is a debugging flow, and not something that is easily done in an arbitrary situation.

What userspace gains is the ability to bring up, on demand, a group of
ports that a given firmware product configuration does not enable by
default: the diagnostic interface, and the same applies to the ADB and
AT ports. A single switch that creates or destroys that whole group is
what is needed; poking channels one at a time is not. That is why it is
described alongside the other controller attributes in
Documentation/ABI/stable/sysfs-bus-mhi.

debugfs cannot serve this, for two concrete reasons.

The first is availability. CONFIG_MHI_BUS_DEBUG is a bool with no
default, so it is off in the configurations product kernels ship, and
it is a compile-time switch: with it disabled, debugfs.c is not built
and the calls in mhi_register_controller() resolve to empty stubs. A
user who needs these ports would have to rebuild the kernel to get at
the control, which is not a usable interface.

What product kernels are you referring to? I use CONFIG_MHI_BUS_DEBUG regularly on RHEL and Ubuntu for a variety of device types.

This is starting to look like a niche problem.

The second is capability. MHI's debugfs already exposes states, events,
channels and devices, and all of them are read-only listings. There is
no debugfs entry in MHI that can create or destroy an MHI device, so
this is not a choice between two equivalent interfaces.

I don't know how this is an argument. What you are arguing for does not exist in sysfs either. You are creating it.

There is also a security reason to keep these ports off unless they are
wanted. The diagnostic and ADB ports on a WWAN module are a meaningful
attack surface, and a module that does not need them should not be
exposing them. Hiding that decision behind an interface that is absent
on production kernels would defeat the point.

I thought your argument was that these interfaces are inactive in normal mode. How can they be a security issue?


+ * @debug_ports: Whether the debug port personality is active, ...
+ * @debug_ports_pending: Latest personality requested from userspace,
+ * applied by debug_ports_work
+ * @debug_ports_work: Applies @debug_ports_pending from the ordered
+ * high priority workqueue, ...

Are these optional?

None of the three can be dropped for this feature to work, though none
of them is populated by a driver either.

So every controller must support these? That's not acceptable to me.

debug_ports records the personality that is currently applied. It is
read by mhi_chan_is_available() on every enumeration, which is what
keeps a debug-only channel hidden while the commercial personality is
active, and it backs the sysfs attribute so userspace can read back
what is in effect. It belongs to the controller because the setting
covers the controller as a whole.

debug_ports_pending carries the value userspace has just written. The
create and destroy work cannot run in the store function itself:
channel devices are created and destroyed by the state transitions on
the ordered hiprio_wq, and pm_mutex does not exclude those transitions,
because a transition releases it before calling
device_for_each_child(). So the work has to be queued on that same
ordered workqueue, and by the time it runs it needs somewhere to read
the request from. Keeping it separate from debug_ports also keeps
"requested" and "applied" distinct while a switch is in flight.

debug_ports_work is that work item. It is initialised in
mhi_register_controller() next to the other work items, queued on the
ordered workqueue, and flushed by the store so the write returns only
once the ports exist.

All three are zero-initialised, so a controller that declares no
debug-only channel starts in the commercial personality and behaves
exactly as before. I am happy to say so explicitly in the kernel-doc.

Could I ask what you have in mind here? If the concern is that the docs
should mark driver-populated fields as optional, these are not
driver-populated and I can word it that way. If you would rather this
state lived somewhere other than struct mhi_controller, I would like to
know your preference before reworking it.

You made a mistake, and I initially missed it.

You document these in the controller config struct, but add them to the controller struct. That is not valid. One of those structures is populated by the controller driver, and the other is not.

This will need to be fixed, but I think there are fundamental problems with what you are attempting to accomplish here which should be addressed before this implementation detail becomes relevant.

-Jeff