Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Drew Fustini" <fustini@kernel.org>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v13 2/5] riscv_cbqri: resctrl: Add cache allocation via capacity block mask
Date: Thu, 03 Dec 2026 10:27:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-247572@kernel.org> (raw)
In-Reply-To: <20261203-dfustini-atl-sc-cbqri-dt-v13-2-eaa688b1624c@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] riscv_cbqri: data race on cpu_srmcfg_default in
  __switch_to_srmcfg()
- [Medium] riscv_cbqri: uncached MMIO polling in
  resctrl_arch_get_config()
- [Low] riscv_cbqri: include asm/cpufeature.h instead of empty
  linux/cpufeature.h
--

commit 21e413228d8cd3e68495d3d480940fdf4b9ecd1e
Author: Drew Fustini <fustini@kernel.org>

riscv_cbqri: resctrl: Add cache allocation via capacity block mask

This commit wires RISC-V CBQRI capacity controllers into resctrl as L2
and L3 cache allocation resources and creates control domains via CPU
hotplug callbacks.

> diff --git a/drivers/resctrl/cbqri_resctrl.c b/drivers/resctrl/cbqri_resctrl.c
> new file mode 100644
> index 0000000000000..997dcb0a85766
> --- /dev/null
> +++ b/drivers/resctrl/cbqri_resctrl.c
> @@ -0,0 +1,873 @@

[ ... ]

> +#include <linux/cpu.h>
> +#include <linux/cpufeature.h>
> +#include <linux/cpuhotplug.h>

[Severity: Low]
Should this include asm/cpufeature.h instead of linux/cpufeature.h?

Everything in include/linux/cpufeature.h is guarded by
CONFIG_GENERIC_CPU_AUTOPROBE, which RISC-V does not select, so this
include expands to nothing.  cbqri_arch_late_init() currently sees
riscv_isa_extension_available() only through an accidental transitive
include via asm/cmpxchg.h, which could break if those headers change.

[ ... ]

> +void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid)
> +{
> +	u32 srmcfg = FIELD_PREP(SRMCFG_RCID_MASK, closid) |
> +		     FIELD_PREP(SRMCFG_MCID_MASK, rmid);
> +
> +	WRITE_ONCE(per_cpu(cpu_srmcfg_default, cpu), srmcfg);
> +}

[Severity: Medium]
Can this WRITE_ONCE() to cpu_srmcfg_default race with the plain read in
__switch_to_srmcfg()?

When a resctrl group is removed, rdtgroup_rmdir_ctrl() calls
resctrl_arch_set_cpu_default_closid_rmid() remotely for each CPU in
rdtgrp->cpu_mask before sending the synchronizing IPI:

CPU0                                CPU1
rdtgroup_rmdir_ctrl()
  resctrl_arch_set_cpu_default_closid_rmid(1, ...)
    WRITE_ONCE(cpu_srmcfg_default)
                                    switch_to()
                                      __switch_to_srmcfg()
                                        __this_cpu_read(cpu_srmcfg_default)
                                          <-- data race

On RISC-V, __this_cpu_read() expands via raw_cpu_generic_read() to a plain
dereference without READ_ONCE().  Beyond triggering KCSAN, the compiler may
reload default_srmcfg between updating cpu_srmcfg and writing CSR_SRMCFG,
leaving the cached CSR value out of sync with hardware.

Reading cpu_srmcfg_default with READ_ONCE(*this_cpu_ptr(&cpu_srmcfg_default))
in __switch_to_srmcfg() would pair properly with this WRITE_ONCE().

[ ... ]

> +int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
> +{
> +	struct resctrl_staged_config *cfg;
> +	enum resctrl_conf_type t;
> +	struct rdt_ctrl_domain *d;
> +	int err = 0;
> +
> +	/* Walking r->ctrl_domains, ensure it can't race with cpuhp */
> +	lockdep_assert_cpus_held();
> +
> +	list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
> +		for (t = 0; t < CDP_NUM_TYPES; t++) {
> +			cfg = &d->staged_config[t];
> +			if (!cfg->have_new_ctrl)
> +				continue;
> +			err = resctrl_arch_update_one(r, d, closid, t, cfg->new_ctrl);
> +			if (err)
> +				return err;
> +		}
> +	}
> +	return err;
> +}
> +
> +u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
> +			    u32 closid, enum resctrl_conf_type type)
> +{
> +	struct cbqri_resctrl_dom *hw_dom;
> +	struct cbqri_controller *ctrl;
> +	u32 at;
> +	u32 val;
> +	int err;
> +
> +	hw_dom = container_of(d, struct cbqri_resctrl_dom, resctrl_ctrl_dom);
> +	ctrl = hw_dom->hw_ctrl;
> +	val = resctrl_get_default_ctrl(r);
> +
> +	if (!r->alloc_capable)
> +		return val;
> +
> +	switch (r->rid) {
> +	case RDT_RESOURCE_L2:
> +	case RDT_RESOURCE_L3:
> +		at = (type == CDP_CODE) ? CBQRI_CONTROL_REGISTERS_AT_CODE :
> +					  CBQRI_CONTROL_REGISTERS_AT_DATA;
> +		err = cbqri_read_cache_config(ctrl, closid, at, &val);
> +		if (err < 0)
> +			val = resctrl_get_default_ctrl(r);
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	return val;
> +}

[Severity: Medium]
Will calling cbqri_read_cache_config() on every resctrl_arch_get_config()
cause severe latency spikes under cpus_read_lock() and rdtgroup_mutex?

Every schemata write holds cpus_read_lock() and rdtgroup_mutex while
parse_cbm() calls rdtgroup_cbm_overlaps() twice per domain.  Inside
__rdtgroup_cbm_overlaps(), resctrl_arch_get_config() is called for every
CLOSID up to closids_supported() (up to 4096 RCIDs) before checking whether
the CLOSID is allocated.

Because each call runs a mutex-serialized synchronous MMIO READ_LIMIT
command with busy polling instead of an O(1) memory lookup, a single
schemata write can issue thousands of MMIO round-trips and stall CPU
hotplug and concurrent resctrl operations.  Without a per-domain shadow
cache, resctrl_arch_update_domains() also unconditionally reprograms
hardware even when cfg->new_ctrl is unchanged.

Caching the configured CBM per domain and RCID in cbqri_resctrl_dom would
make resctrl_arch_get_config() an in-memory lookup and let
resctrl_arch_update_domains() skip unchanged domains.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-dfustini-atl-sc-cbqri-dt-v13-0-eaa688b1624c@kernel.org?part=2

  reply	other threads:[~2026-12-03 10:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:57 [PATCH v13 0/5] riscv: Add initial CBQRI resctrl support Drew Fustini
2026-12-03  9:57 ` [PATCH v13 1/5] riscv_cbqri: Add capacity controller core Drew Fustini
2026-12-03 10:14   ` sashiko-bot
2026-12-03  9:57 ` [PATCH v13 2/5] riscv_cbqri: resctrl: Add cache allocation via capacity block mask Drew Fustini
2026-12-03 10:27   ` sashiko-bot [this message]
2026-12-03  9:57 ` [PATCH v13 3/5] riscv_cbqri: Make RESCTRL_FS available on RISC-V Drew Fustini
2026-12-03  9:57 ` [PATCH v13 4/5] dt-bindings: riscv: Add binding for CBQRI controllers Drew Fustini
2026-12-03 10:14   ` sashiko-bot
2026-12-03  9:57 ` [PATCH v13 5/5] riscv_cbqri: Add CBQRI capacity allocation platform driver Drew Fustini
2026-12-03 10:18   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247572@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fustini@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox