From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B8D31D63F0 for ; Sat, 13 Jun 2026 08:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781338046; cv=none; b=lscihNP3UAzogjU94rdcge5UBkD6WGw6NkbdR4hwqEqaHT3hMF/LjwECsl7ZQIdFYtaI04QipasvYRDcAMJ1+V12UD2vm+7sWy+3OmxbsY6SCaPlFwfemjCJvrX+CxMTHAHXKY3+JqyPRogmbtsi95UEBffpF08TB+CHtXXMzmc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781338046; c=relaxed/simple; bh=EfNp9NXgIKd2xI/5jA0ptLY4gchAsxSAUqxcGjOm8F0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kQoQntb4Uc4oIlEde+wGvjyeghHv8xk4KfihGgU82T5GBiwlktcNi/lmpjq94rS50VRu4cvQ4OV09QjISAjjRYwwzuA6ezrSGq7ZvjPqhdHvMClxcxxpv5eBra9HlHDyTQ15S7RVpMwTuK1i0tGNiaoAIZOwBwYvO56jwoNTsuo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hPUwD8Ke; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hPUwD8Ke" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781338045; x=1812874045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EfNp9NXgIKd2xI/5jA0ptLY4gchAsxSAUqxcGjOm8F0=; b=hPUwD8Ke2mVqQRKV6JupL+3wCsF9I6+xIbVx+mPzwwXE3co069w3MK74 gLE5GePZAZTZr3PrJL24kWA0yelCDqb0TGC/lAlUExpoXEnqrth5TuVUm g9VNjIDyGkuFqmiItFa6ptLeiuSXl9pmY7jok3gtdKoDjGxhmfahBtxSv fo8YIDDvqxj0mwPts59JBEtXM/AV4i4PkJq1sTq9ToTzbhe++SmavovP3 Yyuf05MFkgb4LObpTSt/2dUtfnUme+pfPTZZr0MVNFyq4vPi08fFm44eg js9weVPKcnHFwaSFcRAF/UNXsXYiFUpklET9WOgd2ZMgw/mGMJKPUJxof g==; X-CSE-ConnectionGUID: avsmtRSVSTWwLiWUOra5tA== X-CSE-MsgGUID: aTk3qE3WQgiETzmlJFRK3Q== X-IronPort-AV: E=McAfee;i="6800,10657,11815"; a="99739074" X-IronPort-AV: E=Sophos;i="6.24,202,1774335600"; d="scan'208";a="99739074" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2026 01:07:24 -0700 X-CSE-ConnectionGUID: OJOvvmrYRtaoR+OSshVjSg== X-CSE-MsgGUID: zYyVhsMrR+axNlwbHQ6LAg== X-ExtLoop1: 1 Received: from chenyu-dev.sh.intel.com ([10.239.62.107]) by fmviesa003.fm.intel.com with ESMTP; 13 Jun 2026 01:07:21 -0700 From: Chen Yu To: tony.luck@intel.com, reinette.chatre@intel.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, tglx@kernel.org, bp@alien8.de, mingo@redhat.com, dave.hansen@linux.intel.com, hpa@zytor.com, dave.martin@arm.com, james.morse@arm.com, fenghuay@nvidia.com, babu.moger@amd.com, anil.keshavamurthy@broadcom.com Subject: [PATCH v4 5/6] fs/resctrl: Do not invoke smp_processor_id() in preemptible context Date: Sat, 13 Jun 2026 15:57:33 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tony Luck Currently, mon_evt::any_cpu is false for all events associated with RDT_RESOURCE_L3. The MMIO-based CMT will set any_cpu to true in a follow-up patch. This change will trigger a warning when calling smp_processor_id() inside __l3_mon_event_count(), because __l3_mon_event_count() may be invoked from arbitrary CPUs in task context. Since the calling context is preemptible here, smp_processor_id() will emit a debug warning. To prepare for MMIO-based CMT reads, skip the current CPU lookup when an event's any_cpu flag is set. Events with this flag do not require execution on a specific CPU. Signed-off-by: Tony Luck Tested-by: Hongyu Ning Signed-off-by: Chen Yu --- v3->v4: Revise the commit log to explain the background of this patch. Add Hongyu's tag. --- fs/resctrl/monitor.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 9fd901c78dc6..593974f64f40 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -417,9 +417,37 @@ static void mbm_cntr_free(struct rdt_l3_mon_domain *d, int cntr_id) memset(&d->cntr_cfg[cntr_id], 0, sizeof(*d->cntr_cfg)); } +/** + * cpu_on_correct_domain() - Check if current CPU is in the correct + * domain for the event. + * @rr: The rmid_read structure containing event and domain information. + * + * Context: Preemptible process context when @rr->evt->any_cpu is set. + * Non-migratable process context (via smp_call_on_cpu()) or + * non-preemptible context (via smp_call_function_any()) when + * the event must be read on a specific CPU. + * Return: true if the current CPU can read this event, false otherwise. + */ +static bool cpu_on_correct_domain(struct rmid_read *rr) +{ + int cpu; + + /* Any CPU is OK for this event */ + if (rr->evt->any_cpu) + return true; + + cpu = smp_processor_id(); + + /* Single domain. Must be on a CPU in that domain. */ + if (rr->hdr) + return cpumask_test_cpu(cpu, &rr->hdr->cpu_mask); + + /* Summing domains that share a cache, must be on a CPU for that cache. */ + return cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map); +} + static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) { - int cpu = smp_processor_id(); u32 closid = rdtgrp->closid; u32 rmid = rdtgrp->mon.rmid; struct rdt_l3_mon_domain *d; @@ -452,9 +480,6 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) return 0; } - /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) - return -EINVAL; if (rr->is_mbm_cntr) rr->err = resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id, rr->evt->evtid, &tval); @@ -472,7 +497,6 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) static int __l3_mon_event_count_sum(struct rdtgroup *rdtgrp, struct rmid_read *rr) { - int cpu = smp_processor_id(); u32 closid = rdtgrp->closid; u32 rmid = rdtgrp->mon.rmid; struct rdt_l3_mon_domain *d; @@ -490,10 +514,6 @@ static int __l3_mon_event_count_sum(struct rdtgroup *rdtgrp, struct rmid_read *r return -EINVAL; } - /* Summing domains that share a cache, must be on a CPU for that cache. */ - if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) - return -EINVAL; - /* * Legacy files must report the sum of an event across all * domains that share the same L3 cache instance. @@ -524,7 +544,9 @@ static int __mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr) { switch (rr->r->rid) { case RDT_RESOURCE_L3: - WARN_ON_ONCE(rr->evt->any_cpu); + if (!cpu_on_correct_domain(rr)) + return -EINVAL; + if (rr->hdr) return __l3_mon_event_count(rdtgrp, rr); else -- 2.25.1