Re: [PATCH v13 1/5] riscv_cbqri: Add capacity controller core

From: Drew Fustini

Date: Thu Dec 03 2026 - 14:38:47 EST


On Thu, Dec 03, 2026 at 10:14:14AM +0000, sashiko-bot@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] riscv_cbqri: incomplete AT-mirror verification in
> cbqri_apply_cache_config()
> --
>
> commit a00d96c0d30cb11391c930e3a47a96f149912607
> Author: Drew Fustini <fustini@xxxxxxxxxx>
>
> riscv_cbqri: Add capacity controller core
>
> This commit adds the core driver for RISC-V CBQRI capacity controllers,
> including capability probing and MMIO operations to program and read back
> per-RCID capacity block masks.
>
> > diff --git a/drivers/resctrl/cbqri_devices.c b/drivers/resctrl/cbqri_devices.c
> > new file mode 100644
> > index 0000000000000..d6c2e08a5546d
> > --- /dev/null
> > +++ b/drivers/resctrl/cbqri_devices.c
>
> [ ... ]
>
> > +int cbqri_apply_cache_config(struct cbqri_controller *ctrl, u32 closid,
> > + const struct cbqri_cc_config *cfg)
> > +{
>
> [ ... ]
>
> > + /* Capacity config limit operation for the AT half implied by cfg->at */
> > + err = cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_CONFIG_LIMIT,
> > + closid, cfg->at, cfg->cbm);
> > + if (err < 0)
> > + return err;
> > +
> > + /*
> > + * CDP-off mirror: on AT-capable controllers, also program the
> > + * other AT half with the same mask so the two halves stay in sync.
> > + */
> > + if (need_at_mirror) {
> > + u32 other = (cfg->at == CBQRI_CONTROL_REGISTERS_AT_CODE) ?
> > + CBQRI_CONTROL_REGISTERS_AT_DATA :
> > + CBQRI_CONTROL_REGISTERS_AT_CODE;
> > +
> > + err = cbqri_cc_alloc_op(ctrl,
> > + CBQRI_CC_ALLOC_CTL_OP_CONFIG_LIMIT,
> > + closid, other, cfg->cbm);
> > + if (err < 0) {
> > + int rerr;
> > +
> > + /*
> > + * Best-effort revert of the cfg->at half so the two
> > + * halves stay in sync. A schemata read sees only one
> > + * half, so silent divergence would otherwise report
> > + * the new value as if the write had succeeded.
> > + */
> > + rerr = cbqri_cc_alloc_op(ctrl,
> > + CBQRI_CC_ALLOC_CTL_OP_CONFIG_LIMIT,
> > + closid, cfg->at, saved_cbm);
> > + if (rerr < 0)
> > + pr_err_ratelimited("AT-mirror revert failed (err=%d), AT halves diverged\n",
> > + rerr);
> > + return err;
> > + }
> > + }
> > +
> > + /* Read the limit back to verify the block mask landed */
> > + err = cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT,
> > + closid, cfg->at, 0);
> > + if (err < 0)
> > + return err;
> > +
> > + /*
> > + * Read the capacity block mask and narrow to u32 to match resctrl's CBM
> > + * width. cbqri_probe_cc() rejects ncblks > 32 so the upper bits are
> > + * reserved zero.
> > + */
> > + reg = cbqri_readq(ctrl->base + CBQRI_CC_BLOCK_MASK_OFF);
> > + if (lower_32_bits(reg) != cfg->cbm) {
> > + pr_err_ratelimited("CBM verify mismatch (reg=%llx != cbm=%llx)\n",
> > + reg, cfg->cbm);
> > + err = -EIO;
> > + }
>
> [Severity: Low]
> Can the two AT halves still diverge when need_at_mirror is true?
>
> The post-write CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT check only reads back
> cfg->at, so a silent failure to apply cfg->cbm on the mirrored other
> half goes undetected and cbqri_apply_cache_config() returns 0.
>
> In addition, because cfg->at is verified after other has already been
> written, a readback error or mismatch on cfg->at returns -EIO without
> reverting other to saved_cbm.
>
> Verifying cfg->at before programming other, and then verifying other
> while reverting cfg->at to saved_cbm on either error or mismatch, would
> keep both halves checked and consistent.

This is not a problem. Both CONFIG_LIMIT operations check the status
that the controller reports, and a failed mirror write already puts the
first half back. The read back only catches a controller that reports
success without applying the mask.

Drew