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=1795018476; b=4g9uO/qLDnlbNEmyzaCTw739M9S6I4u+xrsEDWh4y1zml+Vrxm2nuNBeJ9q0wWEtaeXW qAOepjHvAu1RgfXq9ZhecCLNUWFixQeuVkrlk6TWjEk9g0GE5VFYAGkr9qmzppnfzytLr I2cDjNHvTi7yGsp0mjmKT3Qs9/LQ1f1TA/G2qrNsMR6rNl3/nFwZvwMw5F+RQu9Ppf6n8 3cyy8EVxwvAdVn/+yPH88MTfRKeOqSHBd0ZejaU8K0M2XfHkVsVrmKn/pL1UjzzWFL4/4 cv0vV6UN6EQUWG499dt4qkBwbbE3X6stzDFbwlGmHvrGYi/uvdW8IRDyBzFvfuJb10Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795018476; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=VjIIdNNne2+zcEtAYXLSHE5qq1PJuLTZ5cCiEzEUt9o=; b=W8VKcmJA58+HtVmTO4uWFVa5TNHa8YCyDq+d7JheGPWpqAskv+HMQtqUXpHLtNzPFkDv jYcBubOzyACfIaoRfCVGTSDMGmFcdfxF9K/2mqIoAVvwkJaPHDQpXLikgm2q5hJHs42PQ UOcGWUngFwmiw6b80ekM9fk0dx7Zq0id8jqFst6Vg/Yg9oMFJEmSwM33I481OlFtvPGro B9WMq77YPg+SLWGAR43sZ82lilcjRRY9jYFXa/MJBtN8feLwW26yc+xDbAtpijTsIiapf MrWGgk8A86tfpBOEVvWYhDeWc+5upjwKyq77nQnRRqKs6YBYlFpJDQnafJy+v3avIAQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xQeg9PV3; 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 DCAD1606A320; Wed, 18 Nov 2026 16:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xQeg9PV3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D1BF1F000C4; Wed, 18 Nov 2026 16:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795018476; bh=VjIIdNNne2+zcEtAYXLSHE5qq1PJuLTZ5cCiEzEUt9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xQeg9PV3XBHCZLpKeVLFkwcaO/9cn0RN6B6lbrkuOFpglejtt90T8edgxio3SvbIl OyqyHluXSIyrC+nSbGtoBXKZA+xKxSSaNzOdUqsKWmuxFOZlbJ8p4up1RcCJfrJL5O 3rpWv8EdfBjt2KtpjLVYSigXSyC4n+JyDloX2Bms= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot@kernel.org, Dave Jiang , Jonathan Cameron , Will Deacon , Sasha Levin Subject: [PATCH 7.3 1253/2651] perf/cxl: Clear stale event fields before reprogramming a counter Date: Wed, 18 Nov 2026 15:41:33 +0100 Message-ID: <20261118150333.088240613@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Jiang [ Upstream commit 7406d6cf76b1dad53084f3988dc65ab967209344 ] cxl_pmu_event_start() ORs the event group id, event mask, edge and invert selections into a configurable counter's config register without clearing them first, and cxl_pmu_event_stop() leaves them set. Reuse the counter for another event and the new selection lands on top of the old one, so the counter counts the wrong events with stale edge and invert behaviour. Use FIELD_MODIFY() so each field is replaced rather than accumulated. Fixes: 5d7107c72796 ("perf: CXL Performance Monitoring Unit driver") Reported-by: sashiko-bot@kernel.org Closes: https://sashiko.dev/#/patchset/20260715191454.459673-1-dave@stgolabs.net?part=1 Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Dave Jiang Reviewed-by: Jonathan Cameron Link: https://sashiko.dev/#/patchset/20260715191454.459673-1-dave@stgolabs.net?part=1 Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/perf/cxl_pmu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/perf/cxl_pmu.c b/drivers/perf/cxl_pmu.c index 2a5635e4e39f8..8232dc566bd5f 100644 --- a/drivers/perf/cxl_pmu.c +++ b/drivers/perf/cxl_pmu.c @@ -759,17 +759,17 @@ static void cxl_pmu_event_start(struct perf_event *event, int flags) cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_INT_ON_OVRFLW, 1); cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_FREEZE_ON_OVRFLW, 1); cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_ENABLE, 1); - cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EDGE, - cxl_pmu_config1_get_edge(event) ? 1 : 0); - cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_INVERT, - cxl_pmu_config1_get_invert(event) ? 1 : 0); + FIELD_MODIFY(CXL_PMU_COUNTER_CFG_EDGE, &cfg, + cxl_pmu_config1_get_edge(event) ? 1 : 0); + FIELD_MODIFY(CXL_PMU_COUNTER_CFG_INVERT, &cfg, + cxl_pmu_config1_get_invert(event) ? 1 : 0); /* Fixed purpose counters have next two fields RO */ if (test_bit(hwc->idx, info->conf_counter_bm)) { - cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK, - hwc->event_base); - cfg |= FIELD_PREP(CXL_PMU_COUNTER_CFG_EVENTS_MSK, - cxl_pmu_config_get_mask(event)); + FIELD_MODIFY(CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK, &cfg, + hwc->event_base); + FIELD_MODIFY(CXL_PMU_COUNTER_CFG_EVENTS_MSK, &cfg, + cxl_pmu_config_get_mask(event)); } cfg &= ~CXL_PMU_COUNTER_CFG_THRESHOLD_MSK; /* -- 2.53.0