Skip to contentSkip to conversation

FAILED: patch "[PATCH] s390/perf_cpum_cf: Add missing array_index_nospec() to" failed to apply to 6.1-stable tree

PATCH New [email protected] 2 participants 6 messages Jul 20 – Jul 23

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 49145bce539117db4b6e9e83c0e5ef528e361050
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072026-chess-imitate-9c14@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 49145bce539117db4b6e9e83c0e5ef528e361050 Mon Sep 17 00:00:00 2001
From: Sumanth Korikkar <[email protected]>
Date: Mon, 6 Jul 2026 12:46:31 +0200
Subject: [PATCH] s390/perf_cpum_cf: Add missing array_index_nospec() to
__hw_perf_event_init()

ev variable is userspace controlled via event->attr.config and used as an array index after bounds checking, but without speculation barriers.

Add the missing array_index_nospec() call to prevent speculative execution.

Fixes 212188a596d1 ("[S390] perf: add support for s390x CPU counters")
arch/s390/kernel/perf_cpum_cf.c +3 -0
index 7aa655664ecc..2076ac22e2c4 100644
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/miscdevice.h>
 #include <linux/perf_event.h>
+#include <linux/nospec.h>
 
 #include <asm/cpu_mf.h>
 #include <asm/hwctrset.h>
@@ -768,6 +769,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
 			if (!is_userspace_event(ev)) {
 				if (ev >= ARRAY_SIZE(cpumf_generic_events_user))
 					return -EOPNOTSUPP;
+				ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_user));
 				ev = cpumf_generic_events_user[ev];
 			}
 		} else if (!attr->exclude_kernel && attr->exclude_user) {
@@ -778,6 +780,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
 			if (!is_userspace_event(ev)) {
 				if (ev >= ARRAY_SIZE(cpumf_generic_events_basic))
 					return -EOPNOTSUPP;
+				ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_basic));
 				ev = cpumf_generic_events_basic[ev];
 			}
 		}
maintainer
#1 lore raw

PATCH 1/5 s390/cpum_cf: move cpum_cf_ctrset_size()

From: Thomas Richter <[email protected]>

[ Upstream commit 345d2a4dcdb7d0f33ebd990a19aeb3f3f458817d ]

Function cpum_cf_ctrset_size() is defined in one source file and the only user is in another source file. Move this function to the source file where it is used and remove its prototype from the header file. No functional change.

Stable-dep-of: 49145bce5391 ("s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()")

---
 arch/s390/include/asm/cpu_mcf.h        |  2 --
 arch/s390/kernel/perf_cpum_cf.c        | 47 ++++++++++++++++++++++++++
 arch/s390/kernel/perf_cpum_cf_common.c | 46 -------------------------
 3 files changed, 47 insertions(+), 48 deletions(-)
arch/s390/include/asm/cpu_mcf.h +0 -2
index f87a4788c19c8e..387e169597b065 100644
@@ -105,8 +105,6 @@ static inline int stccm_avail(void)
 	return test_facility(142);
 }
 
-size_t cpum_cf_ctrset_size(enum cpumf_ctr_set ctrset,
-			   struct cpumf_ctr_info *info);
 int cfset_online_cpu(unsigned int cpu);
 int cfset_offline_cpu(unsigned int cpu);
 #endif /* _ASM_S390_CPU_MCF_H */
arch/s390/kernel/perf_cpum_cf.c +47 -0

53 lines not on this page · raw message

arch/s390/kernel/perf_cpum_cf_common.c +0 -46

52 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/5 s390/cpum_cf: move stccm_avail()

From: Thomas Richter <[email protected]>

[ Upstream commit 7a8f09ac1850b17ca0cc9e1e4d6621a64661347e ]

Function stccm_avail() is defined in a header file and the only user is one single source file. Move this function to the source file where it is also used and remove it from the header file. No functional change.

Stable-dep-of: 49145bce5391 ("s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()")

---
 arch/s390/include/asm/cpu_mcf.h | 6 ------
 arch/s390/kernel/perf_cpum_cf.c | 6 ++++++
 2 files changed, 6 insertions(+), 6 deletions(-)
arch/s390/include/asm/cpu_mcf.h +0 -6
index 387e169597b065..4b29c31c0e0435 100644
@@ -99,12 +99,6 @@ static inline void kernel_cpumcf_end(void)
 	preempt_enable();
 }
 
-/* Return true if store counter set multiple instruction is available */
-static inline int stccm_avail(void)
-{
-	return test_facility(142);
-}
-
 int cfset_online_cpu(unsigned int cpu);
 int cfset_offline_cpu(unsigned int cpu);
 #endif /* _ASM_S390_CPU_MCF_H */
arch/s390/kernel/perf_cpum_cf.c +6 -0
index 0e53df6d107215..3e6c46d9cd0851 100644
@@ -821,6 +821,12 @@ static struct pmu cpumf_pmu = {
 	.read	      = cpumf_pmu_read,
 };
 
+/* Return true if store counter set multiple instruction is available */
+static inline int stccm_avail(void)
+{
+	return test_facility(142);
+}
+
 static int cfset_init(void);
 static int __init cpumf_pmu_init(void)
 {
Signature · 1 line
2.53.0
maintainer
#3 lore raw

PATCH 3/5 s390/cpum_cf: remove in-kernel counting facility interface

In reply to Sasha Levin

From: Thomas Richter <[email protected]>

[ Upstream commit ea53e6995f45e857fd34e4fbfbd436b5457da5f7 ]

Commit 17bebcc68eee ("s390/cpum_cf: Add minimal in-kernel interface for counter measurements") introduced a small in-kernel interface for CPU Measurement counter facility.
There are no users of this interface, therefore remove it.

The following functions are removed:
kernel_cpumcf_alert(),
kernel_cpumcf_begin(),
kernel_cpumcf_end(),
kernel_cpumcf_avail()
there is no need for them anymore.
With the removal of function kernel_cpumcf_alert(), also remove member alert in struct cpu_cf_events. Its purpose was to counter measurement alert interrupts for the in-kernel interface.

Stable-dep-of: 49145bce5391 ("s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()")

---
 arch/s390/include/asm/cpu_mcf.h        | 17 -----------------
 arch/s390/kernel/perf_cpum_cf.c        |  2 +-
 arch/s390/kernel/perf_cpum_cf_common.c | 24 ------------------------
 3 files changed, 1 insertion(+), 42 deletions(-)
arch/s390/include/asm/cpu_mcf.h +0 -17
index 4b29c31c0e0435..88fc115ebfbe9e 100644
@@ -67,7 +67,6 @@ static inline int ctr_stcctm(enum cpumf_ctr_set set, u64 range, u64 *dest)
 struct cpu_cf_events {
 	struct cpumf_ctr_info	info;
 	atomic_t		ctr_set[CPUMF_CTR_SET_MAX];
-	atomic64_t		alert;
 	u64			state;		/* For perf_event_open SVC */
 	u64			dev_state;	/* For /dev/hwctr */
 	unsigned int		flags;
@@ -80,25 +79,9 @@ struct cpu_cf_events {
 };
 DECLARE_PER_CPU(struct cpu_cf_events, cpu_cf_events);
 
-bool kernel_cpumcf_avail(void);
 int __kernel_cpumcf_begin(void);
-unsigned long kernel_cpumcf_alert(int clear);
 void __kernel_cpumcf_end(void);
 
-static inline int kernel_cpumcf_begin(void)
-{
-	if (!cpum_cf_avail())
-		return -ENODEV;
-
-	preempt_disable();
-	return __kernel_cpumcf_begin();
-}
-static inline void kernel_cpumcf_end(void)
-{
-	__kernel_cpumcf_end();
-	preempt_enable();
-}
-
 int cfset_online_cpu(unsigned int cpu);
 int cfset_offline_cpu(unsigned int cpu);
 #endif /* _ASM_S390_CPU_MCF_H */
arch/s390/kernel/perf_cpum_cf.c +1 -1
index 3e6c46d9cd0851..fd9d07b3ee12e0 100644
@@ -832,7 +832,7 @@ static int __init cpumf_pmu_init(void)
 {
 	int rc;
 
-	if (!kernel_cpumcf_avail())
+	if (!cpum_cf_avail())
 		return -ENODEV;
 
 	/* Setup s390dbf facility */
arch/s390/kernel/perf_cpum_cf_common.c +0 -24
index 4824e3461b5b3b..99523dc3fc8bb8 100644
@@ -27,7 +27,6 @@ DEFINE_PER_CPU(struct cpu_cf_events, cpu_cf_events) = {
 		[CPUMF_CTR_SET_EXT]	= ATOMIC_INIT(0),
 		[CPUMF_CTR_SET_MT_DIAG] = ATOMIC_INIT(0),
 	},
-	.alert = ATOMIC64_INIT(0),
 	.state = 0,
 	.dev_state = 0,
 	.flags = 0,
@@ -67,9 +66,6 @@ static void cpumf_measurement_alert(struct ext_code ext_code,
 	if (alert & CPU_MF_INT_CF_MTDA)
 		pr_warn("CPU[%i] MT counter data was lost\n",
 			smp_processor_id());
-
-	/* store alert for special handling by in-kernel users */
-	atomic64_or(alert, &cpuhw->alert);
 }
 
 #define PMC_INIT      0
@@ -94,12 +90,6 @@ static void cpum_cf_setup_cpu(void *flags)
 	lcctl(0);
 }
 
-bool kernel_cpumcf_avail(void)
-{
-	return cpum_cf_initalized;
-}
-EXPORT_SYMBOL(kernel_cpumcf_avail);
-
 /* Initialize the CPU-measurement counter facility */
 int __kernel_cpumcf_begin(void)
 {
@@ -112,20 +102,6 @@ int __kernel_cpumcf_begin(void)
 }
 EXPORT_SYMBOL(__kernel_cpumcf_begin);
 
-/* Obtain the CPU-measurement alerts for the counter facility */
-unsigned long kernel_cpumcf_alert(int clear)
-{
-	struct cpu_cf_events *cpuhw = this_cpu_ptr(&cpu_cf_events);
-	unsigned long alert;
-
-	alert = atomic64_read(&cpuhw->alert);
-	if (clear)
-		atomic64_set(&cpuhw->alert, 0);
-
-	return alert;
-}
-EXPORT_SYMBOL(kernel_cpumcf_alert);
-
 /* Release the CPU-measurement counter facility */
 void __kernel_cpumcf_end(void)
 {
Signature · 1 line
2.53.0
maintainer
#4 lore raw

PATCH 4/5 s390/cpum_cf: merge source files for CPU Measurement counter facility

In reply to Sasha Levin

From: Thomas Richter <[email protected]>

[ Upstream commit 1e99c242acb2fc211aa9f57cd1060622e66bbf63 ]

With no in-kernel user, the source files can be merged.

Move all functions and the variable definitions to file perf_cpum_cf.c This file now contains all the necessary functions and definitions for the CPU Measurement counter facility device driver.

The files cpu_mcf.h and perf_cpum_cf_common.c are deleted.

Stable-dep-of: 49145bce5391 ("s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()")

---
 arch/s390/include/asm/cpu_mcf.h        |  87 ----------
 arch/s390/kernel/Makefile              |   2 +-
 arch/s390/kernel/perf_cpum_cf.c        | 214 ++++++++++++++++++++++++-
 arch/s390/kernel/perf_cpum_cf_common.c | 163 -------------------
 arch/s390/kernel/perf_pai_ext.c        |   2 +-
 5 files changed, 208 insertions(+), 260 deletions(-)
 delete mode 100644 arch/s390/include/asm/cpu_mcf.h
 delete mode 100644 arch/s390/kernel/perf_cpum_cf_common.c
arch/s390/include/asm/cpu_mcf.h deleted +0 -87
deleted file mode 100644
index 88fc115ebfbe9e..00000000000000
@@ -1,87 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Counter facility support definitions for the Linux perf
- *
- * Copyright IBM Corp. 2019
- * Author(s): Hendrik Brueckner <[email protected]>
- */
-#ifndef _ASM_S390_CPU_MCF_H
-#define _ASM_S390_CPU_MCF_H
-
-#include <linux/perf_event.h>
-#include <asm/cpu_mf.h>
-
-enum cpumf_ctr_set {
-	CPUMF_CTR_SET_BASIC   = 0,    /* Basic Counter Set */
-	CPUMF_CTR_SET_USER    = 1,    /* Problem-State Counter Set */
-	CPUMF_CTR_SET_CRYPTO  = 2,    /* Crypto-Activity Counter Set */
-	CPUMF_CTR_SET_EXT     = 3,    /* Extended Counter Set */
-	CPUMF_CTR_SET_MT_DIAG = 4,    /* MT-diagnostic Counter Set */
-
-	/* Maximum number of counter sets */
-	CPUMF_CTR_SET_MAX,
-};
-
-#define CPUMF_LCCTL_ENABLE_SHIFT    16
-#define CPUMF_LCCTL_ACTCTL_SHIFT     0
-
-static inline void ctr_set_enable(u64 *state, u64 ctrsets)
-{
-	*state |= ctrsets << CPUMF_LCCTL_ENABLE_SHIFT;
-}
-
-static inline void ctr_set_disable(u64 *state, u64 ctrsets)
-{
-	*state &= ~(ctrsets << CPUMF_LCCTL_ENABLE_SHIFT);
-}
-
-static inline void ctr_set_start(u64 *state, u64 ctrsets)
-{
-	*state |= ctrsets << CPUMF_LCCTL_ACTCTL_SHIFT;
-}
-
-static inline void ctr_set_stop(u64 *state, u64 ctrsets)
-{
-	*state &= ~(ctrsets << CPUMF_LCCTL_ACTCTL_SHIFT);
-}
-
-static inline int ctr_stcctm(enum cpumf_ctr_set set, u64 range, u64 *dest)
-{
-	switch (set) {
-	case CPUMF_CTR_SET_BASIC:
-		return stcctm(BASIC, range, dest);
-	case CPUMF_CTR_SET_USER:
-		return stcctm(PROBLEM_STATE, range, dest);
-	case CPUMF_CTR_SET_CRYPTO:
-		return stcctm(CRYPTO_ACTIVITY, range, dest);
-	case CPUMF_CTR_SET_EXT:
-		return stcctm(EXTENDED, range, dest);
-	case CPUMF_CTR_SET_MT_DIAG:
-		return stcctm(MT_DIAG_CLEARING, range, dest);
-	case CPUMF_CTR_SET_MAX:
-		return 3;
-	}
-	return 3;
-}
-
-struct cpu_cf_events {
-	struct cpumf_ctr_info	info;
-	atomic_t		ctr_set[CPUMF_CTR_SET_MAX];
-	u64			state;		/* For perf_event_open SVC */
-	u64			dev_state;	/* For /dev/hwctr */
-	unsigned int		flags;
-	size_t used;			/* Bytes used in data */
-	size_t usedss;			/* Bytes used in start/stop */
-	unsigned char start[PAGE_SIZE];	/* Counter set at event add */
-	unsigned char stop[PAGE_SIZE];	/* Counter set at event delete */
-	unsigned char data[PAGE_SIZE];	/* Counter set at /dev/hwctr */
-	unsigned int sets;		/* # Counter set saved in memory */
-};
-DECLARE_PER_CPU(struct cpu_cf_events, cpu_cf_events);
-
-int __kernel_cpumcf_begin(void);
-void __kernel_cpumcf_end(void);
-
-int cfset_online_cpu(unsigned int cpu);
-int cfset_offline_cpu(unsigned int cpu);
-#endif /* _ASM_S390_CPU_MCF_H */
arch/s390/kernel/Makefile +1 -1
index 7d92aa57715ac8..d29aed18aa3269 100644
@@ -70,7 +70,7 @@ obj-$(CONFIG_KEXEC_FILE)	+= kexec_elf.o
 
 obj-$(CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT)	+= ima_arch.o
 
-obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o perf_cpum_cf_common.o
+obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o
 obj-$(CONFIG_PERF_EVENTS)	+= perf_cpum_cf.o perf_cpum_sf.o
 obj-$(CONFIG_PERF_EVENTS)	+= perf_cpum_cf_events.o perf_regs.o
 obj-$(CONFIG_PERF_EVENTS)	+= perf_pai_crypto.o perf_pai_ext.o
arch/s390/kernel/perf_cpum_cf.c +206 -8

286 lines not on this page · raw message

arch/s390/kernel/perf_cpum_cf_common.c deleted +0 -163

163 lines not on this page · raw message

arch/s390/kernel/perf_pai_ext.c +1 -1
index b4d89654183a21..e630cfd6af3aa5 100644
@@ -16,8 +16,8 @@
 #include <linux/init.h>
 #include <linux/export.h>
 #include <linux/io.h>
+#include <linux/perf_event.h>
 
-#include <asm/cpu_mcf.h>
 #include <asm/ctl_reg.h>
 #include <asm/pai.h>
 #include <asm/debug.h>
Signature · 1 line
2.53.0
maintainer
#5 lore raw

PATCH 5/5 s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()

In reply to Sasha Levin

From: Sumanth Korikkar <[email protected]>

[ Upstream commit 49145bce539117db4b6e9e83c0e5ef528e361050 ]

ev variable is userspace controlled via event->attr.config and used as an array index after bounds checking, but without speculation barriers.

Add the missing array_index_nospec() call to prevent speculative execution.

Fixes 212188a596d1 ("[S390] perf: add support for s390x CPU counters")
---
 arch/s390/kernel/perf_cpum_cf.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/kernel/perf_cpum_cf.c +3 -0
index 3e5e88536aa27a..4a2cd39ed38e7f 100644
@@ -17,6 +17,7 @@
 #include <linux/export.h>
 #include <linux/miscdevice.h>
 #include <linux/perf_event.h>
+#include <linux/nospec.h>
 
 #include <asm/cpu_mf.h>
 #include <asm/hwctrset.h>
@@ -633,6 +634,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
 			if (!is_userspace_event(ev)) {
 				if (ev >= ARRAY_SIZE(cpumf_generic_events_user))
 					return -EOPNOTSUPP;
+				ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_user));
 				ev = cpumf_generic_events_user[ev];
 			}
 		} else if (!attr->exclude_kernel && attr->exclude_user) {
@@ -643,6 +645,7 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
 			if (!is_userspace_event(ev)) {
 				if (ev >= ARRAY_SIZE(cpumf_generic_events_basic))
 					return -EOPNOTSUPP;
+				ev = array_index_nospec(ev, ARRAY_SIZE(cpumf_generic_events_basic));
 				ev = cpumf_generic_events_basic[ev];
 			}
 		}
Signature · 1 line
2.53.0