From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293623; b=zn58kCAZhYvRIJbUvshaCWenNuVjo7yU8jCeHimwmjHVtfPVH+oIfU5GnZeanz7M3HnF jNDpTYRA+Ay2SfolVmyy8VSD5LEKKxcnRamQa8rSwRxnt4FuVSB7cZVzwQ/4e2qN929/B vTWaoMGpvDWhUbbUos1sfBJETjHJJ0dtaWBoNUSlmP8YWXI+DDOcejW1w6olQUKlIilnZ Ffh4p204prWqHLESh0QhKpv3JIajW4C47v2OKuH/H/C4n1RdtzdLG+Igt2dhWdE/UpOCr /Rb6QzWiN6j1ePbJCR25DFHU8oQsaQQqG8jl9JNtNc73R9JQpui6DLRacRKYniki5ZA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293623; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sHJDGXIkURsuTR9/PNgrQM85+UJUXdsxTI7m6GeinPA=; b=b2Opz0eQY4S5uzA1JfsgciRTwyrex3ammy22A6cVGhLuxgbRG6E1Qt2Uk72W4rXzkse1 4qza6EeHtg6ZbzzCFvy3MJSeV0tyPoQDtLZuuUAdvdJNXX9SvbjeI6JlaB8jjnCbk5nKh lf4RlCEcQQ7RmAb4XMaokQDa3YtdWmp+YrnsS97dunKRIzTgbgMYFVdwtyEPQB2ISLuV4 lmc+I1twZ+gBi8nsRxRVgkHN0YYv64XHtz2mzbWA2SU6um+FOLihE/Ezru2Cro46hWd4D OSprSSNnQV0G+BEDUNblnI6GzLYxLWCErylgBGQZWhUgw7/jsxzrd6YeoYjxfYqdrSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oprs5KM1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26AEC606A322 for ; Thu, 3 Dec 2026 10:27:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oprs5KM1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C64F51F00898; Thu, 3 Dec 2026 10:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796293623; bh=sHJDGXIkURsuTR9/PNgrQM85+UJUXdsxTI7m6GeinPA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=oprs5KM1HexYQwczlrOmmoyGRMoHmeS1Exxd2ZRrjdmhFWdM31260gNvmVUsMoCIg lVMjfJqoXH8Z0m2UqFSHLjS+YdtcIioSctPPUVsz9DpLI5rK9+XJ22/36n5aezJSyZ 4PiHiv719mMOU3Ym+blXj12fMwasHvW++lXf8vvcj1YEQ7fwHA8UT26uGZUhSQoeo/ md8vGFE4ettODpbqsEhLRl6pwTsfnWD1ySFgRSvO7KaaXZIY3g2G9MN8sXQKf6Iujs iwkffdxNwWI9kvjamctvQM7i9+8xqYmW7ZiChaBgTSFerufMA6BmWMIIrv5n4zQiQm uhwDuxiyfcxYg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 2/5] riscv_cbqri: resctrl: Add cache allocation via capacity block mask Reply-To: sashiko-reviews@lists.linux.dev To: "Drew Fustini" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203-dfustini-atl-sc-cbqri-dt-v13-2-eaa688b1624c@kernel.org> References: <20261203-dfustini-atl-sc-cbqri-dt-v13-0-eaa688b1624c@kernel.org> <20261203-dfustini-atl-sc-cbqri-dt-v13-2-eaa688b1624c@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 10:27:02 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_resc= trl.c > new file mode 100644 > index 0000000000000..997dcb0a85766 > --- /dev/null > +++ b/drivers/resctrl/cbqri_resctrl.c > @@ -0,0 +1,873 @@ [ ... ] > +#include > +#include > +#include [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 r= mid) > +{ > + u32 srmcfg =3D 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 =3D 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 =3D 0; t < CDP_NUM_TYPES; t++) { > + cfg =3D &d->staged_config[t]; > + if (!cfg->have_new_ctrl) > + continue; > + err =3D 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_doma= in *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 =3D container_of(d, struct cbqri_resctrl_dom, resctrl_ctrl_dom); > + ctrl =3D hw_dom->hw_ctrl; > + val =3D resctrl_get_default_ctrl(r); > + > + if (!r->alloc_capable) > + return val; > + > + switch (r->rid) { > + case RDT_RESOURCE_L2: > + case RDT_RESOURCE_L3: > + at =3D (type =3D=3D CDP_CODE) ? CBQRI_CONTROL_REGISTERS_AT_CODE : > + CBQRI_CONTROL_REGISTERS_AT_DATA; > + err =3D cbqri_read_cache_config(ctrl, closid, at, &val); > + if (err < 0) > + val =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-dfustini-a= tl-sc-cbqri-dt-v13-0-eaa688b1624c@kernel.org?part=3D2