cxl/list: apply bus and port filters to anonymous memdevs
Alison Schofield
maintainerPATCH 1/1 cxl/list: apply bus and port filters to anonymous memdevs
Anonymous memdevs are disabled memdevs that do not nest in the topology output and are reported separately in the "anon memdevs" array.
A user reports that cxl list -M -i with a port filter may return anonymous memdevs that are not part of the selected port. In this case, QEMU-defined disabled memdevs were returned in a query of a cxl_test bus port.
The issue has two parts. First, util_cxl_memdev_filter_by_port() does not properly constrain bus-filtered queries. It treats the bus name as a port identifier, allowing memdevs from other buses to match.
Second, cxl_filter_walk() collects anonymous memdevs in a global pre-pass without applying decoder, bus, or port filters, so disabled memdevs outside the requested scope are included.
Update util_cxl_memdev_filter_by_port() to limit the search to the selected bus and match ports only within that bus. Apply decoder and bus/port filtering to anonymous memdevs so they follow the same rules as other memdev listings.
Found with CXL unit test cxl-topology.sh
--- cxl/filter.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
cxl/filter.c +11 -5
@@ -615,12 +615,12 @@ util_cxl_memdev_filter_by_port(struct cxl_memdev *memdev, const char *bus_ident,struct cxl_port *port, *top; port =cxl_bus_get_port (bus); -if (util_cxl_bus_filter (bus, bus_ident)) -if (__memdev_filter_by_port (memdev, port, -cxl_bus_get_devname (bus))) -return memdev; + +if (!util_cxl_bus_filter (bus, bus_ident)) +continue ;if (__memdev_filter_by_port (memdev, port, port_ident)) -return memdev; +return memdev; + top = port;cxl_port_foreach_all (top, port) if (__memdev_filter_by_port(memdev, port, port_ident))
@@ -1125,6 +1125,12 @@ struct json_object *cxl_filter_walk(struct cxl_ctx *ctx,if (!util_cxl_memdev_filter (memdev, p->memdev_filter, p->serial_filter))continue ; +if (!util_cxl_memdev_filter_by_decoder (memdev, + p->decoder_filter)) +continue ; +if (!util_cxl_memdev_filter_by_port (memdev, p->bus_filter, + p->port_filter)) +continue ;if (cxl_memdev_is_enabled (memdev))continue ;if (!p->idle)
Signature · 1 line
2.37.3
Quoted 22 lines · Alison Schofield
Anonymous memdevs are disabled memdevs that do not nest in the topology output and are reported separately in the "anon memdevs" array.
A user reports that cxl list -M -i with a port filter may return anonymous memdevs that are not part of the selected port. In this case, QEMU-defined disabled memdevs were returned in a query of a
cxl_testbus port.The issue has two parts. First,
util_cxl_memdev_filter_by_port()does not properly constrain bus-filtered queries. It treats the bus name as a port identifier, allowing memdevs from other buses to match.Second,
cxl_filter_walk()collects anonymous memdevs in a global pre-pass without applying decoder, bus, or port filters, so disabled memdevs outside the requested scope are included.Update
util_cxl_memdev_filter_by_port()to limit the search to the selected bus and match ports only within that bus. Apply decoder and bus/port filtering to anonymous memdevs so they follow the same rules as other memdev listings.
Quoted 4 lines
Found with CXL unit test
cxl-topology.shReported-by Dave Jiang <[email protected]>Signed-off-by Alison Schofield <[email protected]>
Thanks for the quick fix.
Quoted 39 lines
--- cxl/filter.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)cxl/filter.c +11
-5@@ -615,12 +615,12 @@ util_cxl_memdev_filter_by_port(struct cxl_memdev *memdev, const char *bus_ident,struct cxl_port *port, *top; port =cxl_bus_get_port (bus); -if (util_cxl_bus_filter (bus, bus_ident)) -if (__memdev_filter_by_port (memdev, port, -cxl_bus_get_devname (bus))) -return memdev; + +if (!util_cxl_bus_filter (bus, bus_ident)) +continue ;if (__memdev_filter_by_port (memdev, port, port_ident)) -return memdev; +return memdev; + top = port;cxl_port_foreach_all (top, port) if (__memdev_filter_by_port(memdev, port, port_ident))@@ -1125,6 +1125,12 @@ struct json_object *cxl_filter_walk(struct cxl_ctx *ctx,if (!util_cxl_memdev_filter (memdev, p->memdev_filter, p->serial_filter))continue ; +if (!util_cxl_memdev_filter_by_decoder (memdev, + p->decoder_filter)) +continue ; +if (!util_cxl_memdev_filter_by_port (memdev, p->bus_filter, + p->port_filter)) +continue ;if (cxl_memdev_is_enabled (memdev))continue ;if (!p->idle)