Re: [PATCH v13 5/5] riscv_cbqri: Add CBQRI capacity allocation platform driver

From: Drew Fustini

Date: Thu Dec 03 2026 - 17:08:01 EST


On Thu, Dec 03, 2026 at 10:18:44AM +0000, sashiko-bot@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] riscv_cbqri: async probe in cbqri_capacity_driver can race
> late_initcall
> - [Medium] riscv_cbqri: cbqri_capacity_of_cache() misses offline
> clusters at boot
> --
>
> commit f9a576951d9d7e095fba9697627996ee2c9c8612
> Author: Drew Fustini <fustini@xxxxxxxxxx>
>
> riscv_cbqri: Add CBQRI capacity allocation platform driver
>
> This commit adds a platform driver for RISC-V CBQRI capacity controllers
> described in device tree. It maps the controller's register block, resolves
> its cache level and id from cacheinfo via the riscv,cbqri-cache phandle, and
> registers it with the CBQRI core.
>
> > diff --git a/drivers/resctrl/cbqri_capacity.c b/drivers/resctrl/cbqri_capacity.c
> > new file mode 100644
> > index 0000000000000..9e3920b97d6c3
> > --- /dev/null
> > +++ b/drivers/resctrl/cbqri_capacity.c
> > @@ -0,0 +1,148 @@
>
> [ ... ]
>
> > + cpus_read_lock();
> > + for_each_online_cpu(cpu) {
> > + struct cacheinfo *ci = get_cpu_cacheinfo_level(cpu, *cache_level);
> > +
> > + if (ci && ci->fw_token == cache_np) {
> > + *cache_id = ci->id;
> > + found = true;
> > + break;
> > + }
> > + }
> > + cpus_read_unlock();
> > +
> > + if (!found)
> > + return dev_err_probe(dev, -ENODEV,
> > + "%pOF: no online hart reports an L%u cache with a cache id for this node\n",
> > + cache_np, *cache_level);
>
> [Severity: Medium]
> Can this permanently miss capacity controllers for caches whose harts are
> offline at boot?
>
> If a multi-cluster system boots with secondary clusters offline (such as
> with maxcpus=1), for_each_online_cpu() skips them and probe fails with
> -ENODEV.
>
> When those harts are later brought online via CPU hotplug,
> cbqri_attach_cpu_to_all_ctrls() finds no registered controller for their
> cache id and leaves them permanently outside resctrl control.
>
> Since cache_of_set_id() in drivers/base/cacheinfo.c derives DT cache IDs
> directly from CPU device-tree nodes, sharing an OF cache-id helper would
> avoid depending on online harts at probe time.

This is a known limit of the initial support. A cache that has no online
hart when the driver probes does not get a resctrl domain

> > +static struct platform_driver cbqri_capacity_driver = {
> > + .probe = cbqri_capacity_probe,
> > + .driver = {
> > + .name = "cbqri-capacity",
> > + .of_match_table = cbqri_capacity_of_match,
> > + /*
> > + * The controller is registered permanently into the
> > + * CBQRI core for the life of the system. Block unbind
> > + * so userspace cannot leave a dangling controller.
> > + */
> > + .suppress_bind_attrs = true,
> > + },
> > +};
> > +
> > +/*
> > + * Register at device_initcall so probe runs before the resctrl glue's
> > + * late_initcall, which copies the cbqri_controllers list.
> > + */
> > +builtin_platform_driver(cbqri_capacity_driver);
>
> [Severity: Medium]
> Can asynchronous probing cause cbqri_capacity_probe() to race with
> cbqri_arch_late_init()?
>
> Because .probe_type is left unset (PROBE_DEFAULT_STRATEGY), booting with
> driver_async_probe=* makes __driver_attach() schedule cbqri_capacity_probe()
> asynchronously and return immediately. do_initcalls() then advances to
> late_initcall without waiting for async probes:
>
> init thread async kworker
> do_initcalls() (device_initcall)
> __driver_attach()
> async_schedule_dev(...)
> __driver_attach_async_helper()
> cbqri_capacity_probe()
> do_initcalls() (late_initcall)
> cbqri_arch_late_init()
> cbqri_resctrl_pick_caches() <-- misses unregistered controller
> riscv_cbqri_register_cc()
>
> Any controller that finishes probing after cbqri_resctrl_pick_caches() is
> permanently ignored by resctrl, causing resctrl setup to either fail with
> -ENODEV or come up missing cache domains while leaving the late controller
> and its MMIO mapping unused.
>
> Setting .probe_type = PROBE_FORCE_SYNCHRONOUS on cbqri_capacity_driver.driver
> would prevent this race.

I don' think cmdline with driver_async_probe= is very likely, but I will
set probe_type to PROBE_FORCE_SYNCHRONOUS in the next revision.

Drew