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=1796334486; b=l0MR9V4BhYwBq1gwFo+k+UgN+ZgY3sjmVRFAdP6fn5k6AYBpnD3mv4Su9pDJ3joS9ah6 5pXbkIeU5Z+hxmPUYoTAZp7x/aWV+tDCwWkx8o0evXZ1svD2kSGOQ9kDsINFVkhiKrDkv b2ktHqWd88sdgMmUVmffa4oNd3T5A/V5ZIRnQTtQawZ+JhQjvlruS3r5CcFWV9sYlfgNl aDcF8DA6opzWEkdhCLu2TkjcQVazjRp/ukJnyelItFsJpYCw1A1HV8kr4hfd572XNbkEt b2Y+lpncrcOCYuCMauq3on9w5SjoajBwGchY2109IhCiEz8JoVQnw5RsM9r9nWU9BNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334486; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=W0Fsa9Eeu337l51cV5nHmzvq/8r7kFkhXtTOWfhjHA0=; b=ucPf6qFZkl3QjBBAchUimNvEv+4ZGRMO6JuQ+3GaZgBeahHBfCDcg7IbxWV5dWVC0oD/ O3Xfqrf8RLi+GrTBHEF9WexlhgXYgLGjSBullUOydc+G2B2ihhf/q501zt4Qeauakv+VT Upid7HPCGtsOj0eBfUNEYt/3l7ZChtcTFGPWPhAD1g3IOP7q0W7T5A+XK8BaHJU2PUi1L f8gy/MOs2KMlQ6Wvn0UTpzkt+IMSdv4jQssqnoDhmRDKR5iIeJtd1hv0UWdChhxvDbyVB z/O2/ZVO+tzgMmfjJFDW7BZjKj+TX9aR1CCDSfqmmzK+9MgkZfnPSAamaKDz/gjoUmg== 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=QL43UagP; 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 D4BD0606A322; Thu, 3 Dec 2026 21:48:06 +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=QL43UagP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 637E11F000C2; Thu, 3 Dec 2026 21:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796334486; bh=W0Fsa9Eeu337l51cV5nHmzvq/8r7kFkhXtTOWfhjHA0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=QL43UagPVc6C4nxnqFCsII93JQWAAVlwDuANa8JH/QVqNNINxlgcGqq208mI9lDCk WsplSexjOl5SJBOa3F93+xnJbf+KZTG0zyg+je3UN6s64nzXW+b0DIztVRLI+yHLrA FrStqcw+zcNGc8XB+loSkuD5gsT+JYwBZN+dg4b0ANs6y0L3Axi9QIzsRd5CNm412N Atf9ycBYVrWfaxVchlr28YZTgj10U7zA13v2Pdfj1vjcoQ46oUJiAlDDoB1ih6LlKV o8HR26EPqjt+uEJS4kYCy4WBoVFg8+AXtxXyhjIM7cJDW6CqvqceoFkdWvmeDAwxsS e8Be3N1qoFcRQ== Date: Thu, 3 Dec 2026 13:48:05 -0800 From: Drew Fustini To: sashiko-reviews@lists.linux.dev Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v13 2/5] riscv_cbqri: resctrl: Add cache allocation via capacity block mask Message-ID: References: <20261203-dfustini-atl-sc-cbqri-dt-v13-0-eaa688b1624c@kernel.org> <20261203-dfustini-atl-sc-cbqri-dt-v13-2-eaa688b1624c@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Dec 03, 2026 at 10:27:02AM +0000, sashiko-bot@kernel.org wrote: > 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_resctrl.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. This is valid. I will use asm/cpufeature.h in next rev. > > +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(). This is not a problem in practice because update_closid_rmid() runs resctrl_arch_sched_in() on those cpus right after the write. However, it wouldn't hurt to use READ_ONCE() in the next revision so that it pairs with the WRITE_ONCE() as x86 does. > > +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. I don't think this is a practical issue. Ascalon has only 16 RCIDs. I don't expect there to be any platform with more than 100. If there ever is such a system, then we could implement an optimization at that point. Drew