FAILED: patch "[PATCH] s390/mm: Fix __ptep_rdp() inline assembly" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-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.12.y
git checkout FETCH_HEAD
git cherry-pick -x 31475b88110c4725b4f9a79c3a0d9bbf97e69e1c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025112418-impish-remix-d936@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 31475b88110c4725b4f9a79c3a0d9bbf97e69e1c Mon Sep 17 00:00:00 2001
From: Heiko Carstens <[email protected]>
Date: Thu, 13 Nov 2025 13:21:47 +0100
Subject: [PATCH] s390/mm: Fix __ptep_rdp() inline assembly
When a zero ASCE is passed to the __ptep_rdp() inline assembly, the generated instruction should have the R3 field of the instruction set to zero. However the inline assembly is written incorrectly: for such cases a zero is loaded into a register allocated by the compiler and this register is then used by the instruction.
This means that selected TLB entries may not be flushed since the specified ASCE does not match the one which was used when the selected TLB entries were created.
Fix this by removing the asce and opt parameters of __ptep_rdp(), since all callers always pass zero, and use a hard-coded register zero for the R3 field.
arch/s390/include/asm/pgtable.h +5 -7
@@ -1154,17 +1154,15 @@ static inline pte_t pte_mkhuge(pte_t pte)#define IPTE_NODAT 0x400#define IPTE_GUEST_ASCE 0x800 -static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, -unsigned long opt,unsigned long asce, -int local) +static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, int local) {unsigned long pto; pto =__pa (ptep) & ~(PTRS_PER_PTE *sizeof (pte_t) -1 ); - asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%[asce],%[m4]" + asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%%r0,%[m4]" :"+m" (*ptep) - : [r1]"a" (pto), [r2]"a" ((addr &PAGE_MASK ) | opt), - [asce]"a" (asce), [m4]"i" (local)); + : [r1]"a" (pto), [r2]"a" (addr &PAGE_MASK ), + [m4]"i" (local)); } static __always_inline void __ptep_ipte(unsigned long address, pte_t *ptep,
@@ -1348,7 +1346,7 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,* A local RDP can be used to do the flush. */ if (cpu_has_rdp () && !(pte_val (*ptep) & _PAGE_PROTECT)) -__ptep_rdp (address, ptep,0 ,0 ,1 ); +__ptep_rdp (address, ptep,1 ); }#define flush_tlb_fix_spurious_fault flush_tlb_fix_spurious_fault
arch/s390/mm/pgtable.c +2 -2
@@ -274,9 +274,9 @@ void ptep_reset_dat_prot(struct mm_struct *mm, unsigned long addr, pte_t *ptep,preempt_disable ();atomic_inc (&mm->context.flush_count);if (cpumask_equal (mm_cpumask (mm),cpumask_of (smp_processor_id ()))) -__ptep_rdp (addr, ptep,0 ,0 ,1 ); +__ptep_rdp (addr, ptep,1 );else -__ptep_rdp (addr, ptep,0 ,0 ,0 ); +__ptep_rdp (addr, ptep,0 );/* * PTE is not invalidated by RDP, only _PAGE_PROTECT is cleared. That * means it is still valid and active, and must not be changed according
Sasha Levin
maintainerPATCH 1/3 s390/cpufeature: Convert MACHINE_HAS_SEQ_INSN to cpu_has_seq_insn()
From: Heiko Carstens <[email protected]>
[ Upstream commit 679b110bb662fc107f38ebd5088af56a156dd82f ]
Convert MACHINE_HAS_... to cpu_has_...() which uses test_facility() instead of testing the machine_flags lowcore member if the feature is present.
test_facility() generates better code since it results in a static branch without accessing memory. The branch is patched via alternatives by the decompressor depending on the availability of the required facility.
Stable-dep-of: 31475b88110c ("s390/mm: Fix __ptep_rdp() inline assembly")
--- arch/s390/include/asm/cpufeature.h | 4 ++++ arch/s390/include/asm/setup.h | 2 -- arch/s390/kernel/early.c | 2 -- arch/s390/kernel/ftrace.c | 11 ++++++----- arch/s390/kernel/kprobes.c | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-)
arch/s390/include/asm/cpufeature.h +4 -0
@@ -9,6 +9,8 @@#ifndef __ASM_S390_CPUFEATURE_H#define __ASM_S390_CPUFEATURE_H +#include <asm/facility.h> +enum {S390_CPU_FEATURE_MSA , S390_CPU_FEATURE_VXRS,
@@ -20,4 +22,6 @@ enum {int cpu_have_feature (unsigned int nr); +#define cpu_has_seq_insn () test_facility(85) +#endif /* __ASM_S390_CPUFEATURE_H */
arch/s390/include/asm/setup.h +0 -2
@@ -34,7 +34,6 @@#define MACHINE_FLAG_SCC BIT(17)#define MACHINE_FLAG_PCI_MIO BIT(18)#define MACHINE_FLAG_RDP BIT(19) -#define MACHINE_FLAG_SEQ_INSN BIT(20)#define LPP_MAGIC BIT(31)#define LPP_PID_MASK _AC(0xffffffff, UL)
@@ -96,7 +95,6 @@ extern unsigned long mio_wb_bit_mask;#define MACHINE_HAS_SCC (get_lowcore()->machine_flags & MACHINE_FLAG_SCC)#define MACHINE_HAS_PCI_MIO (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO)#define MACHINE_HAS_RDP (get_lowcore()->machine_flags & MACHINE_FLAG_RDP) -#define MACHINE_HAS_SEQ_INSN (get_lowcore()->machine_flags & MACHINE_FLAG_SEQ_INSN)/* * Console mode. Override with conmode=
arch/s390/kernel/early.c +0 -2
@@ -269,8 +269,6 @@ static __init void detect_machine_facilities(void) }if (test_facility (194 ))get_lowcore ()->machine_flags |=MACHINE_FLAG_RDP ; -if (test_facility (85 )) -get_lowcore ()->machine_flags |=MACHINE_FLAG_SEQ_INSN ; }static inline void save_vector_registers (void )
arch/s390/kernel/ftrace.c +6 -5
@@ -13,6 +13,7 @@#include <linux/kernel.h> #include <linux/types.h> #include <linux/kmsan-checks.h> +#include <linux/cpufeature.h> #include <linux/kprobes.h> #include <linux/execmem.h> #include <trace/syscall.h>
@@ -69,7 +70,7 @@ static const char *ftrace_shared_hotpatch_trampoline(const char **end)bool ftrace_need_init_nop (void ) { -return !MACHINE_HAS_SEQ_INSN ; +return !cpu_has_seq_insn (); }int ftrace_init_nop (struct module *mod,struct dyn_ftrace *rec)
@@ -189,7 +190,7 @@ static int ftrace_modify_trampoline_call(struct dyn_ftrace *rec,int ftrace_modify_call (struct dyn_ftrace *rec,unsigned long old_addr,unsigned long addr) { -if (MACHINE_HAS_SEQ_INSN ) +if (cpu_has_seq_insn ())return ftrace_patch_branch_insn (rec->ip, old_addr, addr);else return ftrace_modify_trampoline_call (rec, old_addr, addr);
@@ -213,8 +214,8 @@ static int ftrace_patch_branch_mask(void *addr, u16 expected, bool enable)int ftrace_make_nop (struct module *mod,struct dyn_ftrace *rec,unsigned long addr) { -/* Expect brcl 0xf,... for the !MACHINE_HAS_SEQ_INSN case */ -if (MACHINE_HAS_SEQ_INSN ) +/* Expect brcl 0xf,... for the !cpu_has_seq_insn() case */ +if (cpu_has_seq_insn ())return ftrace_patch_branch_insn (rec->ip, addr,0 );else return ftrace_patch_branch_mask ((void *)rec->ip,0xc0f4 , false);
@@ -234,7 +235,7 @@ static int ftrace_make_trampoline_call(struct dyn_ftrace *rec, unsigned long addint ftrace_make_call (struct dyn_ftrace *rec,unsigned long addr) { -if (MACHINE_HAS_SEQ_INSN ) +if (cpu_has_seq_insn ())return ftrace_patch_branch_insn (rec->ip,0 , addr);else return ftrace_make_trampoline_call (rec, addr);
arch/s390/kernel/kprobes.c +3 -2
@@ -13,6 +13,7 @@#include <linux/ptrace.h> #include <linux/preempt.h> #include <linux/stop_machine.h> +#include <linux/cpufeature.h> #include <linux/kdebug.h> #include <linux/uaccess.h> #include <linux/extable.h>
@@ -153,7 +154,7 @@ void arch_arm_kprobe(struct kprobe *p) {struct swap_insn_args args = {.p = p, .arm_kprobe =1 }; -if (MACHINE_HAS_SEQ_INSN ) { +if (cpu_has_seq_insn ()) {swap_instruction (&args);text_poke_sync (); }else {
@@ -166,7 +167,7 @@ void arch_disarm_kprobe(struct kprobe *p) {struct swap_insn_args args = {.p = p, .arm_kprobe =0 }; -if (MACHINE_HAS_SEQ_INSN ) { +if (cpu_has_seq_insn ()) {swap_instruction (&args);text_poke_sync (); }else {
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/3 s390/cpufeature: Convert MACHINE_HAS_RDP to cpu_has_rdp()
From: Heiko Carstens <[email protected]>
[ Upstream commit 15a36036e792f4eec0fc59833dde688024e036fc ]
Convert MACHINE_HAS_... to cpu_has_...() which uses test_facility() instead of testing the machine_flags lowcore member if the feature is present.
test_facility() generates better code since it results in a static branch without accessing memory. The branch is patched via alternatives by the decompressor depending on the availability of the required facility.
Stable-dep-of: 31475b88110c ("s390/mm: Fix __ptep_rdp() inline assembly")
--- arch/s390/include/asm/cpufeature.h | 1 + arch/s390/include/asm/pgtable.h | 5 +++-- arch/s390/include/asm/setup.h | 2 -- arch/s390/kernel/early.c | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-)
arch/s390/include/asm/cpufeature.h +1 -0
@@ -22,6 +22,7 @@ enum {int cpu_have_feature (unsigned int nr); +#define cpu_has_rdp () test_facility(194)#define cpu_has_seq_insn () test_facility(85)#endif /* __ASM_S390_CPUFEATURE_H */
arch/s390/include/asm/pgtable.h +3 -2
@@ -14,6 +14,7 @@#include <linux/sched.h> #include <linux/mm_types.h> +#include <linux/cpufeature.h> #include <linux/page-flags.h> #include <linux/radix-tree.h> #include <linux/atomic.h>
@@ -1302,7 +1303,7 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,* PTE does not have _PAGE_PROTECT set, to avoid unnecessary overhead. * A local RDP can be used to do the flush. */ -if (MACHINE_HAS_RDP && !(pte_val (*ptep) & _PAGE_PROTECT)) +if (cpu_has_rdp () && !(pte_val (*ptep) & _PAGE_PROTECT))__ptep_rdp (address, ptep,0 ,0 ,1 ); }#define flush_tlb_fix_spurious_fault flush_tlb_fix_spurious_fault
@@ -1317,7 +1318,7 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma, {if (pte_same (*ptep, entry))return 0 ; -if (MACHINE_HAS_RDP && !mm_has_pgste (vma->vm_mm) &&pte_allow_rdp (*ptep, entry)) +if (cpu_has_rdp () && !mm_has_pgste (vma->vm_mm) &&pte_allow_rdp (*ptep, entry))ptep_reset_dat_prot (vma->vm_mm, addr, ptep, entry);else ptep_xchg_direct (vma->vm_mm, addr, ptep, entry);
arch/s390/include/asm/setup.h +0 -2
@@ -33,7 +33,6 @@#define MACHINE_FLAG_GS BIT(16)#define MACHINE_FLAG_SCC BIT(17)#define MACHINE_FLAG_PCI_MIO BIT(18) -#define MACHINE_FLAG_RDP BIT(19)#define LPP_MAGIC BIT(31)#define LPP_PID_MASK _AC(0xffffffff, UL)
@@ -94,7 +93,6 @@ extern unsigned long mio_wb_bit_mask;#define MACHINE_HAS_GS (get_lowcore()->machine_flags & MACHINE_FLAG_GS)#define MACHINE_HAS_SCC (get_lowcore()->machine_flags & MACHINE_FLAG_SCC)#define MACHINE_HAS_PCI_MIO (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO) -#define MACHINE_HAS_RDP (get_lowcore()->machine_flags & MACHINE_FLAG_RDP)/* * Console mode. Override with conmode=
arch/s390/kernel/early.c +0 -2
@@ -267,8 +267,6 @@ static __init void detect_machine_facilities(void)get_lowcore ()->machine_flags |=MACHINE_FLAG_PCI_MIO ;/* the control bit is set during PCI initialization */ } -if (test_facility (194 )) -get_lowcore ()->machine_flags |=MACHINE_FLAG_RDP ; }static inline void save_vector_registers (void )
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 3/3 s390/mm: Fix __ptep_rdp() inline assembly
In reply to Sasha LevinFrom: Heiko Carstens <[email protected]>
[ Upstream commit 31475b88110c4725b4f9a79c3a0d9bbf97e69e1c ]
When a zero ASCE is passed to the __ptep_rdp() inline assembly, the generated instruction should have the R3 field of the instruction set to zero. However the inline assembly is written incorrectly: for such cases a zero is loaded into a register allocated by the compiler and this register is then used by the instruction.
This means that selected TLB entries may not be flushed since the specified ASCE does not match the one which was used when the selected TLB entries were created.
Fix this by removing the asce and opt parameters of __ptep_rdp(), since all callers always pass zero, and use a hard-coded register zero for the R3 field.
--- arch/s390/include/asm/pgtable.h | 12 +++++------- arch/s390/mm/pgtable.c | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-)
arch/s390/include/asm/pgtable.h +5 -7
@@ -1110,17 +1110,15 @@ static inline pte_t pte_mkhuge(pte_t pte)#define IPTE_NODAT 0x400#define IPTE_GUEST_ASCE 0x800 -static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, -unsigned long opt,unsigned long asce, -int local) +static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, int local) {unsigned long pto; pto =__pa (ptep) & ~(PTRS_PER_PTE *sizeof (pte_t) -1 ); - asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%[asce],%[m4]" + asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%%r0,%[m4]" :"+m" (*ptep) - : [r1]"a" (pto), [r2]"a" ((addr &PAGE_MASK ) | opt), - [asce]"a" (asce), [m4]"i" (local)); + : [r1]"a" (pto), [r2]"a" (addr &PAGE_MASK ), + [m4]"i" (local)); } static __always_inline void __ptep_ipte(unsigned long address, pte_t *ptep,
@@ -1304,7 +1302,7 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,* A local RDP can be used to do the flush. */ if (cpu_has_rdp () && !(pte_val (*ptep) & _PAGE_PROTECT)) -__ptep_rdp (address, ptep,0 ,0 ,1 ); +__ptep_rdp (address, ptep,1 ); }#define flush_tlb_fix_spurious_fault flush_tlb_fix_spurious_fault
arch/s390/mm/pgtable.c +2 -2
@@ -293,9 +293,9 @@ void ptep_reset_dat_prot(struct mm_struct *mm, unsigned long addr, pte_t *ptep,preempt_disable ();atomic_inc (&mm->context.flush_count);if (cpumask_equal (mm_cpumask (mm),cpumask_of (smp_processor_id ()))) -__ptep_rdp (addr, ptep,0 ,0 ,1 ); +__ptep_rdp (addr, ptep,1 );else -__ptep_rdp (addr, ptep,0 ,0 ,0 ); +__ptep_rdp (addr, ptep,0 );/* * PTE is not invalidated by RDP, only _PAGE_PROTECT is cleared. That * means it is still valid and active, and must not be changed according
Signature · 1 line
2.51.0
Heiko Carstens
maintainerRe: [PATCH 6.12.y 3/3] s390/mm: Fix __ptep_rdp() inline assembly
Quoted 27 lines · Sasha Levin
From: Heiko Carstens <[email protected]>
[ Upstream commit
31475b88110c4725b4f9a79c3a0d9bbf97e69e1c]When a zero ASCE is passed to the
__ptep_rdp()inline assembly, the generated instruction should have the R3 field of the instruction set to zero. However the inline assembly is written incorrectly: for such cases a zero is loaded into a register allocated by the compiler and this register is then used by the instruction.This means that selected TLB entries may not be flushed since the specified ASCE does not match the one which was used when the selected TLB entries were created.
Fix this by removing the asce and opt parameters of
__ptep_rdp(), since all callers always pass zero, and use a hard-coded register zero for the R3 field.Fixes 0807b856521f ("s390/mm: add support for RDP (Reset DAT-Protection)")Reviewed-by Gerald Schaefer <[email protected]>Signed-off-by Heiko Carstens <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/s390/include/asm/pgtable.h | 12 +++++------- arch/s390/mm/pgtable.c | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-)
...
arch/s390/include/asm/pgtable.h static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma, · line 1306
Quoted 7 lines
arch/s390/include/asm/pgtable.h +1
-1@@ -1304,7 +1302,7 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,* A local RDP can be used to do the flush. */ if (cpu_has_rdp () && !(pte_val (*ptep) & _PAGE_PROTECT)) -__ptep_rdp (address, ptep,0 ,0 ,1 ); +__ptep_rdp (address, ptep,1 ); }
I don't think it makes too much sense to backport only two of the many cpu_has_xxx() conversion patches just to avoid the minimal difference in context for this patch. From my point of view this puts the stable branch into an inconsistent state wrt s390 and cpu features - old and new interfaces are mixed.
I will provide a different stable backport patch which addresses only the context diff. Then you can decide.
Heiko Carstens
maintainerPATCH 1/1 s390/mm: Fix __ptep_rdp() inline assembly
In reply to [email protected][ Upstream commit 31475b88110c4725b4f9a79c3a0d9bbf97e69e1c ]
When a zero ASCE is passed to the __ptep_rdp() inline assembly, the generated instruction should have the R3 field of the instruction set to zero. However the inline assembly is written incorrectly: for such cases a zero is loaded into a register allocated by the compiler and this register is then used by the instruction.
This means that selected TLB entries may not be flushed since the specified ASCE does not match the one which was used when the selected TLB entries were created.
Fix this by removing the asce and opt parameters of __ptep_rdp(), since all callers always pass zero, and use a hard-coded register zero for the R3 field.
--- arch/s390/include/asm/pgtable.h | 12 +++++------- arch/s390/mm/pgtable.c | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-)
arch/s390/include/asm/pgtable.h +5 -7
@@ -1109,17 +1109,15 @@ static inline pte_t pte_mkhuge(pte_t pte)#define IPTE_NODAT 0x400#define IPTE_GUEST_ASCE 0x800 -static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, -unsigned long opt,unsigned long asce, -int local) +static __always_inline void __ptep_rdp(unsigned long addr, pte_t *ptep, int local) {unsigned long pto; pto =__pa (ptep) & ~(PTRS_PER_PTE *sizeof (pte_t) -1 ); - asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%[asce],%[m4]" + asmvolatile (".insn rrf,0xb98b0000,%[r1],%[r2],%%r0,%[m4]" :"+m" (*ptep) - : [r1]"a" (pto), [r2]"a" ((addr &PAGE_MASK ) | opt), - [asce]"a" (asce), [m4]"i" (local)); + : [r1]"a" (pto), [r2]"a" (addr &PAGE_MASK ), + [m4]"i" (local)); } static __always_inline void __ptep_ipte(unsigned long address, pte_t *ptep,
@@ -1303,7 +1301,7 @@ static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,* A local RDP can be used to do the flush. */ if (MACHINE_HAS_RDP && !(pte_val (*ptep) & _PAGE_PROTECT)) -__ptep_rdp (address, ptep,0 ,0 ,1 ); +__ptep_rdp (address, ptep,1 ); }#define flush_tlb_fix_spurious_fault flush_tlb_fix_spurious_fault
arch/s390/mm/pgtable.c +2 -2
@@ -293,9 +293,9 @@ void ptep_reset_dat_prot(struct mm_struct *mm, unsigned long addr, pte_t *ptep,preempt_disable ();atomic_inc (&mm->context.flush_count);if (cpumask_equal (mm_cpumask (mm),cpumask_of (smp_processor_id ()))) -__ptep_rdp (addr, ptep,0 ,0 ,1 ); +__ptep_rdp (addr, ptep,1 );else -__ptep_rdp (addr, ptep,0 ,0 ,0 ); +__ptep_rdp (addr, ptep,0 );/* * PTE is not invalidated by RDP, only _PAGE_PROTECT is cleared. That * means it is still valid and active, and must not be changed according
Signature · 1 line
2.48.1
Sasha Levin
maintainerRe: [PATCH 6.12.y] s390/mm: Fix __ptep_rdp() inline assembly
This patch has been queued up for the 6.12 stable tree.
Subject: s390/mm: Fix __ptep_rdp() inline assembly
Queue: 6.12
Thanks for the backport!