projects/linux·commit 10de638d

Merge tag 's390-6.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux

10de638d · Linus Torvalds <[email protected]> · 2023-04-30 11:43:31 -07:00

Pull s390 updates from Vasily Gorbik:

 - Add support for stackleak feature. Also allow specifying
   architecture-specific stackleak poison function to enable faster
   implementation. On s390, the mvc-based implementation helps decrease
   typical overhead from a factor of 3 to just 25%

 - Convert all assembler files to use SYM* style macros, deprecating the
   ENTRY() macro and other annotations. Select ARCH_USE_SYM_ANNOTATIONS

 - Improve KASLR to also randomize module and special amode31 code base
   load addresses

 - Rework decompressor memory tracking to support memory holes and
   improve error handling

 - Add support for protected virtualization AP binding

 - Add support for set_direct_map() calls

 - Implement set_memory_rox() and noexec module_alloc()

 - Remove obsolete overriding of mem*() functions for KASAN

 - Rework kexec/kdump to avoid using nodat_stack to call purgatory

 - Convert the rest of the s390 code to use flexible-array member
   instead of a zero-length array

 - Clean up uaccess inline asm

 - Enable ARCH_HAS_MEMBARRIER_SYNC_CORE

 - Convert to using CONFIG_FUNCTION_ALIGNMENT and enable
   DEBUG_FORCE_FUNCTION_ALIGN_64B

 - Resolve last_break in userspace fault reports

 - Simplify one-level sysctl registration

 - Clean up branch prediction handling

 - Rework CPU counter facility to retrieve available counter sets just
   once

 - Other various small fixes and improvements all over the code

* tag 's390-6.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (118 commits)
  s390/stackleak: provide fast __stackleak_poison() implementation
  stackleak: allow to specify arch specific stackleak poison function
  s390: select ARCH_USE_SYM_ANNOTATIONS
  s390/mm: use VM_FLUSH_RESET_PERMS in module_alloc()
  s390: wire up memfd_secret system call
  s390/mm: enable ARCH_HAS_SET_DIRECT_MAP
  s390/mm: use BIT macro to generate SET_MEMORY bit masks
  s390/relocate_kernel: adjust indentation
  s390/relocate_kernel: use SYM* macros instead of ENTRY(), etc.
  s390/entry: use SYM* macros instead of ENTRY(), etc.
  s390/purgatory: use SYM* macros instead of ENTRY(), etc.
  s390/kprobes: use SYM* macros instead of ENTRY(), etc.
  s390/reipl: use SYM* macros instead of ENTRY(), etc.
  s390/head64: use SYM* macros instead of ENTRY(), etc.
  s390/earlypgm: use SYM* macros instead of ENTRY(), etc.
  s390/mcount: use SYM* macros instead of ENTRY(), etc.
  s390/crc32le: use SYM* macros instead of ENTRY(), etc.
  s390/crc32be: use SYM* macros instead of ENTRY(), etc.
  s390/crypto,chacha: use SYM* macros instead of ENTRY(), etc.
  s390/amode31: use SYM* macros instead of ENTRY(), etc.
  ...
Commit
10de638d8ea57ebab4231ea077bed01d9bade775
Parents
d55571c0 · 2a405f6b

Merge commit. Changes below are compared with the first parent: d55571c0.

Changes

98 files changed · +2642 −2294

FileStatusAddDelContent
Documentation/features/sched/membarrier-sync-core/arch-support.txtmodified+2−2View file
arch/s390/Kconfigmodified+6−4View file
arch/s390/appldata/appldata_base.cmodified+9−23View file
arch/s390/boot/Makefilemodified+1−1View file
arch/s390/boot/boot.hmodified+35−7View file
arch/s390/boot/install.shmodified+4−4View file
arch/s390/boot/ipl_parm.cmodified+3−3View file
arch/s390/boot/ipl_report.cmodified+49−57View file
arch/s390/boot/kaslr.cmodified+83−88View file
arch/s390/boot/pgm_check_info.cmodified+3−4View file
arch/s390/boot/mem_detect.c → arch/s390/boot/physmem_info.crenamed+186−49View file
arch/s390/boot/startup.cmodified+73−56View file
arch/s390/boot/vmem.cmodified+223−61View file
arch/s390/boot/vmlinux.lds.Smodified+2−0View file
arch/s390/crypto/chacha-s390.Smodified+24−23View file
arch/s390/crypto/crc32be-vx.Smodified+9−8View file
arch/s390/crypto/crc32le-vx.Smodified+16−14View file
arch/s390/include/asm/ap.hmodified+128−24View file
arch/s390/include/asm/checksum.hmodified+2−8View file
arch/s390/include/asm/diag.hmodified+1−1View file
arch/s390/include/asm/entry-common.hmodified+0−5View file
arch/s390/include/asm/fcx.hmodified+1−1View file
arch/s390/include/asm/kasan.hmodified+1−30View file
arch/s390/include/asm/linkage.hmodified+1−1View file
arch/s390/include/asm/mem_detect.hdeleted+0−117View before deletion
arch/s390/include/asm/nospec-insn.hmodified+2−1View file
arch/s390/include/asm/perf_event.hmodified+0−2View file
arch/s390/include/asm/pgtable.hmodified+1−1View file
arch/s390/include/asm/physmem_info.hadded+171−0View file
arch/s390/include/asm/processor.hmodified+42−4View file
arch/s390/include/asm/set_memory.hmodified+31−5View file
arch/s390/include/asm/setup.hmodified+8−12View file
arch/s390/include/asm/stacktrace.hmodified+44−8View file
arch/s390/include/asm/string.hmodified+3−12View file
arch/s390/include/asm/thread_info.hmodified+5−5View file
arch/s390/kernel/debug.cmodified+2−12View file
arch/s390/kernel/dumpstack.cmodified+21−25View file
arch/s390/kernel/early.cmodified+9−14View file
arch/s390/kernel/earlypgm.Smodified+2−2View file
arch/s390/kernel/entry.Smodified+70−82View file
arch/s390/kernel/ftrace.cmodified+1−21View file
arch/s390/kernel/head64.Smodified+6−8View file
arch/s390/kernel/ipl.cmodified+3−4View file
arch/s390/kernel/kprobes.cmodified+1−1View file
arch/s390/kernel/kprobes_insn_page.Smodified+2−2View file
arch/s390/kernel/machine_kexec.cmodified+22−34View file
arch/s390/kernel/mcount.Smodified+20−6View file
arch/s390/kernel/module.cmodified+25−4View file
arch/s390/kernel/perf_cpum_cf.cmodified+91−115View file
arch/s390/kernel/perf_cpum_sf.cmodified+2−12View file
arch/s390/kernel/process.cmodified+4−6View file
arch/s390/kernel/processor.cmodified+0−18View file
arch/s390/kernel/reipl.Smodified+5−5View file
arch/s390/kernel/relocate_kernel.Smodified+47−49View file
arch/s390/kernel/setup.cmodified+48−104View file
arch/s390/kernel/smp.cmodified+4−7View file
arch/s390/kernel/syscalls/syscall.tblmodified+1−1View file
arch/s390/kernel/text_amode31.Smodified+31−44View file
arch/s390/kernel/topology.cmodified+1−11View file
arch/s390/kernel/vdso32/vdso_user_wrapper.Smodified+2−1View file
arch/s390/kernel/vdso64/vdso_user_wrapper.Smodified+3−2View file
arch/s390/kernel/vmlinux.lds.Smodified+9−1View file
arch/s390/lib/mem.Smodified+17−11View file
arch/s390/lib/uaccess.cmodified+71−66View file
arch/s390/mm/Makefilemodified+0−3View file
arch/s390/mm/cmm.cmodified+1−11View file
arch/s390/mm/init.cmodified+2−3View file
arch/s390/mm/kasan_init.cdeleted+0−301View before deletion
arch/s390/mm/pageattr.cmodified+86−8View file
arch/s390/mm/pgalloc.cmodified+2−18View file
arch/s390/mm/vmem.cmodified+20−15View file
arch/s390/pci/pci.cmodified+3−20View file
arch/s390/pci/pci_bus.cmodified+3−8View file
arch/s390/purgatory/head.Smodified+19−43View file
arch/s390/purgatory/kexec-purgatory.Smodified+6−8View file
drivers/s390/char/sclp.hmodified+1−1View file
drivers/s390/char/sclp_cmd.cmodified+1−1View file
drivers/s390/char/sclp_early_core.cmodified+4−4View file
drivers/s390/cio/chsc.cmodified+1−1View file
drivers/s390/cio/chsc.hmodified+1−1View file
drivers/s390/crypto/ap_bus.cmodified+151−103View file
drivers/s390/crypto/ap_bus.hmodified+44−26View file
drivers/s390/crypto/ap_card.cmodified+11−12View file
drivers/s390/crypto/ap_queue.cmodified+348−62View file
drivers/s390/crypto/vfio_ap_drv.cmodified+0−6View file
drivers/s390/crypto/vfio_ap_ops.cmodified+7−9View file
drivers/s390/crypto/zcrypt_api.cmodified+20−40View file
drivers/s390/crypto/zcrypt_card.cmodified+3−3View file
drivers/s390/crypto/zcrypt_cca_key.hmodified+13−24View file
drivers/s390/crypto/zcrypt_ccamisc.cmodified+36−38View file
drivers/s390/crypto/zcrypt_cex2c.cmodified+31−35View file
drivers/s390/crypto/zcrypt_cex4.cmodified+66−75View file
drivers/s390/crypto/zcrypt_ep11misc.cmodified+1−1View file
drivers/s390/crypto/zcrypt_msgtype50.cmodified+9−6View file
drivers/s390/crypto/zcrypt_msgtype6.cmodified+47−92View file
drivers/s390/crypto/zcrypt_queue.cmodified+2−2View file
kernel/stackleak.cmodified+13−4View file
lib/Kconfig.debugmodified+1−1View file

Only the first 600 diff lines are shown. Download the complete patch.

Documentation/features/sched/membarrier-sync-core/arch-support.txt

View file
diff --git a/Documentation/features/sched/membarrier-sync-core/arch-support.txt b/Documentation/features/sched/membarrier-sync-core/arch-support.txt
index 1e51614..23260ca 100644
--- a/Documentation/features/sched/membarrier-sync-core/arch-support.txt
+++ b/Documentation/features/sched/membarrier-sync-core/arch-support.txt
@@ -5,7 +5,7 @@
#
# Architecture requirements
#
-# * arm/arm64/powerpc
+# * arm/arm64/powerpc/s390
#
# Rely on implicit context synchronization as a result of exception return
# when returning from IPI handler, and when returning to user-space.
@@ -45,7 +45,7 @@
| parisc: | TODO |
| powerpc: | ok |
| riscv: | TODO |
- | s390: | TODO |
+ | s390: | ok |
| sh: | TODO |
| sparc: | TODO |
| um: | TODO |

arch/s390/Kconfig

View file
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 61d7783..beb62f7 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -26,10 +26,6 @@ config GENERIC_BUG
config GENERIC_BUG_RELATIVE_POINTERS
def_bool y
-config GENERIC_CSUM
- bool
- default y if KASAN
-
config GENERIC_LOCKBREAK
def_bool y if PREEMPTION
@@ -76,10 +72,12 @@ config S390
select ARCH_HAS_GCOV_PROFILE_ALL
select ARCH_HAS_GIGANTIC_PAGE
select ARCH_HAS_KCOV
+ select ARCH_HAS_MEMBARRIER_SYNC_CORE
select ARCH_HAS_MEM_ENCRYPT
select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SCALED_CPUTIME
+ select ARCH_HAS_SET_DIRECT_MAP
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_STRICT_KERNEL_RWX
select ARCH_HAS_STRICT_MODULE_RWX
@@ -123,6 +121,7 @@ config S390
select ARCH_SUPPORTS_PER_VMA_LOCK
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF
+ select ARCH_USE_SYM_ANNOTATIONS
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
select ARCH_WANTS_NO_INSTR
select ARCH_WANT_DEFAULT_BPF_JIT
@@ -132,6 +131,8 @@ config S390
select CLONE_BACKWARDS2
select DMA_OPS if PCI
select DYNAMIC_FTRACE if FUNCTION_TRACER
+ select FUNCTION_ALIGNMENT_8B if CC_IS_GCC
+ select FUNCTION_ALIGNMENT_16B if !CC_IS_GCC
select GCC12_NO_ARRAY_BOUNDS
select GENERIC_ALLOCATOR
select GENERIC_CPU_AUTOPROBE
@@ -153,6 +154,7 @@ config S390
select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_SOFT_DIRTY
+ select HAVE_ARCH_STACKLEAK
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
select HAVE_ARCH_VMAP_STACK

arch/s390/appldata/appldata_base.c

View file
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index c0fd291..b07b061 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -66,16 +66,6 @@ static struct ctl_table appldata_table[] = {
{ },
};
-static struct ctl_table appldata_dir_table[] = {
- {
- .procname = appldata_proc_name,
- .maxlen = 0,
- .mode = S_IRUGO | S_IXUGO,
- .child = appldata_table,
- },
- { },
-};
-
/*
* Timer
*/
@@ -291,7 +281,7 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
mutex_lock(&appldata_ops_mutex);
list_for_each(lh, &appldata_ops_list) {
tmp_ops = list_entry(lh, struct appldata_ops, list);
- if (&tmp_ops->ctl_table[2] == ctl) {
+ if (&tmp_ops->ctl_table[0] == ctl) {
found = 1;
}
}
@@ -361,7 +351,8 @@ int appldata_register_ops(struct appldata_ops *ops)
if (ops->size > APPLDATA_MAX_REC_SIZE)
return -EINVAL;
- ops->ctl_table = kcalloc(4, sizeof(struct ctl_table), GFP_KERNEL);
+ /* The last entry must be an empty one */
+ ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL);
if (!ops->ctl_table)
return -ENOMEM;
@@ -369,17 +360,12 @@ int appldata_register_ops(struct appldata_ops *ops)
list_add(&ops->list, &appldata_ops_list);
mutex_unlock(&appldata_ops_mutex);
- ops->ctl_table[0].procname = appldata_proc_name;
- ops->ctl_table[0].maxlen = 0;
- ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
- ops->ctl_table[0].child = &ops->ctl_table[2];
-
- ops->ctl_table[2].procname = ops->name;
- ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
- ops->ctl_table[2].proc_handler = appldata_generic_handler;
- ops->ctl_table[2].data = ops;
+ ops->ctl_table[0].procname = ops->name;
+ ops->ctl_table[0].mode = S_IRUGO | S_IWUSR;
+ ops->ctl_table[0].proc_handler = appldata_generic_handler;
+ ops->ctl_table[0].data = ops;
- ops->sysctl_header = register_sysctl_table(ops->ctl_table);
+ ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table);
if (!ops->sysctl_header)
goto out;
return 0;
@@ -422,7 +408,7 @@ static int __init appldata_init(void)
appldata_wq = alloc_ordered_workqueue("appldata", 0);
if (!appldata_wq)
return -ENOMEM;
- appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
+ appldata_sysctl_header = register_sysctl(appldata_proc_name, appldata_table);
return 0;
}

arch/s390/boot/Makefile

View file
diff --git a/arch/s390/boot/Makefile b/arch/s390/boot/Makefile
index cebd4ca..c7c81e5 100644
--- a/arch/s390/boot/Makefile
+++ b/arch/s390/boot/Makefile
@@ -35,7 +35,7 @@ endif
CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
-obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o vmem.o
+obj-y := head.o als.o startup.o physmem_info.o ipl_parm.o ipl_report.o vmem.o
obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
obj-y += version.o pgm_check_info.o ctype.o ipl_data.o machine_kexec_reloc.o
obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o

arch/s390/boot/boot.h

View file
diff --git a/arch/s390/boot/boot.h b/arch/s390/boot/boot.h
index 58ce701..222c688 100644
--- a/arch/s390/boot/boot.h
+++ b/arch/s390/boot/boot.h
@@ -8,6 +8,8 @@
#ifndef __ASSEMBLY__
+#include <asm/physmem_info.h>
+
struct machine_info {
unsigned char has_edat1 : 1;
unsigned char has_edat2 : 1;
@@ -30,24 +32,46 @@ struct vmlinux_info {
unsigned long init_mm_off;
unsigned long swapper_pg_dir_off;
unsigned long invalid_pg_dir_off;
+#ifdef CONFIG_KASAN
+ unsigned long kasan_early_shadow_page_off;
+ unsigned long kasan_early_shadow_pte_off;
+ unsigned long kasan_early_shadow_pmd_off;
+ unsigned long kasan_early_shadow_pud_off;
+ unsigned long kasan_early_shadow_p4d_off;
+#endif
};
void startup_kernel(void);
-unsigned long detect_memory(unsigned long *safe_addr);
-void mem_detect_set_usable_limit(unsigned long limit);
+unsigned long detect_max_physmem_end(void);
+void detect_physmem_online_ranges(unsigned long max_physmem_end);
+void physmem_set_usable_limit(unsigned long limit);
+void physmem_reserve(enum reserved_range_type type, unsigned long addr, unsigned long size);
+void physmem_free(enum reserved_range_type type);
+/* for continuous/multiple allocations per type */
+unsigned long physmem_alloc_top_down(enum reserved_range_type type, unsigned long size,
+ unsigned long align);
+/* for single allocations, 1 per type */
+unsigned long physmem_alloc_range(enum reserved_range_type type, unsigned long size,
+ unsigned long align, unsigned long min, unsigned long max,
+ bool die_on_oom);
+unsigned long get_physmem_alloc_pos(void);
+bool ipl_report_certs_intersects(unsigned long addr, unsigned long size,
+ unsigned long *intersection_start);
bool is_ipl_block_dump(void);
void store_ipl_parmblock(void);
-unsigned long read_ipl_report(unsigned long safe_addr);
+int read_ipl_report(void);
+void save_ipl_cert_comp_list(void);
void setup_boot_command_line(void);
void parse_boot_command_line(void);
void verify_facilities(void);
void print_missing_facilities(void);
void sclp_early_setup_buffer(void);
void print_pgm_check_info(void);
-unsigned long get_random_base(unsigned long safe_addr);
+unsigned long randomize_within_range(unsigned long size, unsigned long align,
+ unsigned long min, unsigned long max);
void setup_vmem(unsigned long asce_limit);
-unsigned long vmem_estimate_memory_needs(unsigned long online_mem_total);
void __printf(1, 2) decompressor_printk(const char *fmt, ...);
+void print_stacktrace(unsigned long sp);
void error(char *m);
extern struct machine_info machine;
@@ -57,12 +81,11 @@ extern const char kernel_version[];
extern unsigned long memory_limit;
extern unsigned long vmalloc_size;
extern int vmalloc_size_set;
-extern int kaslr_enabled;
extern char __boot_data_start[], __boot_data_end[];
extern char __boot_data_preserved_start[], __boot_data_preserved_end[];
extern char _decompressor_syms_start[], _decompressor_syms_end[];
extern char _stack_start[], _stack_end[];
-extern char _end[];
+extern char _end[], _decompressor_end[];
extern unsigned char _compressed_start[];
extern unsigned char _compressed_end[];
extern struct vmlinux_info _vmlinux_info;
@@ -70,5 +93,10 @@ extern struct vmlinux_info _vmlinux_info;
#define __abs_lowcore_pa(x) (((unsigned long)(x) - __abs_lowcore) % sizeof(struct lowcore))
+static inline bool intersects(unsigned long addr0, unsigned long size0,
+ unsigned long addr1, unsigned long size1)
+{
+ return addr0 + size0 > addr1 && addr1 + size1 > addr0;
+}
#endif /* __ASSEMBLY__ */
#endif /* BOOT_BOOT_H */

arch/s390/boot/install.sh

View file
diff --git a/arch/s390/boot/install.sh b/arch/s390/boot/install.sh
index 616ba16..a13dd2f 100755
--- a/arch/s390/boot/install.sh
+++ b/arch/s390/boot/install.sh
@@ -17,8 +17,8 @@
echo "Warning: '${INSTALLKERNEL}' command not available - additional " \
"bootloader config required" >&2
-if [ -f $4/vmlinuz-$1 ]; then mv $4/vmlinuz-$1 $4/vmlinuz-$1.old; fi
-if [ -f $4/System.map-$1 ]; then mv $4/System.map-$1 $4/System.map-$1.old; fi
+if [ -f "$4/vmlinuz-$1" ]; then mv -- "$4/vmlinuz-$1" "$4/vmlinuz-$1.old"; fi
+if [ -f "$4/System.map-$1" ]; then mv -- "$4/System.map-$1" "$4/System.map-$1.old"; fi
-cat $2 > $4/vmlinuz-$1
-cp $3 $4/System.map-$1
+cat -- "$2" > "$4/vmlinuz-$1"
+cp -- "$3" "$4/System.map-$1"

arch/s390/boot/ipl_parm.c

View file
diff --git a/arch/s390/boot/ipl_parm.c b/arch/s390/boot/ipl_parm.c
index c1f8f79..8753cb0 100644
--- a/arch/s390/boot/ipl_parm.c
+++ b/arch/s390/boot/ipl_parm.c
@@ -24,11 +24,11 @@ int __bootdata(noexec_disabled);
unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
struct ipl_parameter_block __bootdata_preserved(ipl_block);
int __bootdata_preserved(ipl_block_valid);
+int __bootdata_preserved(__kaslr_enabled);
unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
unsigned long memory_limit;
int vmalloc_size_set;
-int kaslr_enabled;
static inline int __diag308(unsigned long subcode, void *addr)
{
@@ -264,7 +264,7 @@ void parse_boot_command_line(void)
char *args;
int rc;
- kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
+ __kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
args = strcpy(command_line_buf, early_command_line);
while (*args) {
args = next_arg(args, &param, &val);
@@ -300,7 +300,7 @@ void parse_boot_command_line(void)
modify_fac_list(val);
if (!strcmp(param, "nokaslr"))
- kaslr_enabled = 0;
+ __kaslr_enabled = 0;
#if IS_ENABLED(CONFIG_KVM)
if (!strcmp(param, "prot_virt")) {

arch/s390/boot/ipl_report.c

View file
diff --git a/arch/s390/boot/ipl_report.c b/arch/s390/boot/ipl_report.c
index 74b5cd2..1803035 100644
--- a/arch/s390/boot/ipl_report.c
+++ b/arch/s390/boot/ipl_report.c
@@ -5,6 +5,7 @@
#include <asm/sclp.h>
#include <asm/sections.h>
#include <asm/boot_data.h>
+#include <asm/physmem_info.h>
#include <uapi/asm/ipl.h>
#include "boot.h"
@@ -16,20 +17,16 @@ unsigned long __bootdata_preserved(ipl_cert_list_size);
unsigned long __bootdata(early_ipl_comp_list_addr);
unsigned long __bootdata(early_ipl_comp_list_size);
+static struct ipl_rb_certificates *certs;
+static struct ipl_rb_components *comps;
+static bool ipl_report_needs_saving;
+
#define for_each_rb_entry(entry, rb) \
for (entry = rb->entries; \
(void *) entry + sizeof(*entry) <= (void *) rb + rb->len; \
entry++)
-static inline bool intersects(unsigned long addr0, unsigned long size0,
- unsigned long addr1, unsigned long size1)
-{
- return addr0 + size0 > addr1 && addr1 + size1 > addr0;
-}
-
-static unsigned long find_bootdata_space(struct ipl_rb_components *comps,
- struct ipl_rb_certificates *certs,
- unsigned long safe_addr)
+static unsigned long get_cert_comp_list_size(void)
{
struct ipl_rb_certificate_entry *cert;
struct ipl_rb_component_entry *comp;
@@ -44,44 +41,27 @@ static unsigned long find_bootdata_space(struct ipl_rb_components *comps,
ipl_cert_list_size = 0;
for_each_rb_entry(cert, certs)
ipl_cert_list_size += sizeof(unsigned int) + cert->len;
- size = ipl_cert_list_size + early_ipl_comp_list_size;
+ return ipl_cert_list_size + early_ipl_comp_list_size;
+}
- /*
- * Start from safe_addr to find a free memory area large
- * enough for the IPL report boot data. This area is used
- * for ipl_cert_list_addr/ipl_cert_list_size and
- * early_ipl_comp_list_addr/early_ipl_comp_list_size. It must
- * not overlap with any component or any certificate.
- */
-repeat:
- if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_data.start && initrd_data.size &&
- intersects(initrd_data.start, initrd_data.size, safe_addr, size))
- safe_addr = initrd_data.start + initrd_data.size;
- if (intersects(safe_addr, size, (unsigned long)comps, comps->len)) {
- safe_addr = (unsigned long)comps + comps->len;
- goto repeat;
- }
- for_each_rb_entry(comp, comps)
- if (intersects(safe_addr, size, comp->addr, comp->len)) {
- safe_addr = comp->addr + comp->len;
- goto repeat;
+bool ipl_report_certs_intersects(unsigned long addr, unsigned long size,
+ unsigned long *intersection_start)
+{
+ struct ipl_rb_certificate_entry *cert;
+
+ if (!ipl_report_needs_saving)
+ return false;
+
+ for_each_rb_entry(cert, certs) {
+ if (intersects(addr, size, cert->addr, cert->len)) {
+ *intersection_start = cert->addr;
+ return true;
}
- if (intersects(safe_addr, size, (unsigned long)certs, certs->len)) {
- safe_addr = (unsigned long)certs + certs->len;
- goto repeat;
}
- for_each_rb_entry(cert, certs)
- if (intersects(safe_addr, size, cert->addr, cert->len)) {
- safe_addr = cert->addr + cert->len;
- goto repeat;
- }
- early_ipl_comp_list_addr = safe_addr;
- ipl_cert_list_addr = safe_addr + early_ipl_comp_list_size;
-
- return safe_addr + size;
+ return false;
}
-static void copy_components_bootdata(struct ipl_rb_components *comps)
+static void copy_components_bootdata(void)
{
struct ipl_rb_component_entry *comp, *ptr;
@@ -90,7 +70,7 @@ static void copy_components_bootdata(struct ipl_rb_components *comps)
memcpy(ptr++, comp, sizeof(*ptr));
}
-static void copy_certificates_bootdata(struct ipl_rb_certificates *certs)
+static void copy_certificates_bootdata(void)
{
struct ipl_rb_certificate_entry *cert;
void *ptr;
@@ -104,10 +84,8 @@ static void copy_certificates_bootdata(struct ipl_rb_certificates *certs)
}
}
-unsigned long read_ipl_report(unsigned long safe_addr)
+int read_ipl_report(void)
{
- struct ipl_rb_certificates *certs;
- struct ipl_rb_components *comps;
struct ipl_pl_hdr *pl_hdr;
struct ipl_rl_hdr *rl_hdr;
struct ipl_rb_hdr *rb_hdr;
@@ -120,7 +98,7 @@ unsigned long read_ipl_report(unsigned long safe_addr)
*/
if (!ipl_block_valid ||
!(ipl_block.hdr.flags & IPL_PL_FLAG_IPLSR))
- return safe_addr;
+ return -1;
ipl_secure_flag = !!(ipl_block.hdr.flags & IPL_PL_FLAG_SIPL);
/*
* There is an IPL report, to find it load the pointer to the
@@ -158,16 +136,30 @@ unsigned long read_ipl_report(unsigned long safe_addr)
* With either the component list or the certificate list
* missing the kernel will stay ignorant of secure IPL.
*/
- if (!comps || !certs)
- return safe_addr;
+ if (!comps || !certs) {
+ certs = NULL;
+ return -1;
+ }
- /*
- * Copy component and certificate list to a safe area
- * where the decompressed kernel can find them.
- */
- safe_addr = find_bootdata_space(comps, certs, safe_addr);
- copy_components_bootdata(comps);
- copy_certificates_bootdata(certs);
+ ipl_report_needs_saving = true;
+ physmem_reserve(RR_IPLREPORT, (unsigned long)pl_hdr,
+ (unsigned long)rl_end - (unsigned long)pl_hdr);
+ return 0;
+}
+
+void save_ipl_cert_comp_list(void)
+{
+ unsigned long size;
+
+ if (!ipl_report_needs_saving)
+ return;
+
+ size = get_cert_comp_list_size();
+ early_ipl_comp_list_addr = physmem_alloc_top_down(RR_CERT_COMP_LIST, size, sizeof(int));
+ ipl_cert_list_addr = early_ipl_comp_list_addr + early_ipl_comp_list_size;
- return safe_addr;
+ copy_components_bootdata();
+ copy_certificates_bootdata();
+ physmem_free(RR_IPLREPORT);
+ ipl_report_needs_saving = false;
}

arch/s390/boot/kaslr.c

View file
diff --git a/arch/s390/boot/kaslr.c b/arch/s390/boot/kaslr.c
index 3e3d846..9060210 100644
--- a/arch/s390/boot/kaslr.c
+++ b/arch/s390/boot/kaslr.c
@@ -3,7 +3,7 @@
* Copyright IBM Corp. 2019
*/
#include <linux/pgtable.h>
-#include <asm/mem_detect.h>
+#include <asm/physmem_info.h>
#include <asm/cpacf.h>
#include <asm/timex.h>
#include <asm/sclp.h>
@@ -91,113 +91,108 @@ static int get_random(unsigned long limit, unsigned long *value)
return 0;
}
-/*
- * To randomize kernel base address we have to consider several facts:
- * 1. physical online memory might not be continuous and have holes. mem_detect
- * info contains list of online memory ranges we should consider.
- * 2. we have several memory regions which are occupied and we should not
- * overlap and destroy them. Currently safe_addr tells us the border below
- * which all those occupied regions are. We are safe to use anything above
- * safe_addr.
- * 3. the upper limit might apply as well, even if memory above that limit is
- * online. Currently those limitations are:
- * 3.1. Limit set by "mem=" kernel command line option
- * 3.2. memory reserved at the end for kasan initialization.
- * 4. kernel base address must be aligned to THREAD_SIZE (kernel stack size).
- * Which is required for CONFIG_CHECK_STACK. Currently THREAD_SIZE is 4 pages
- * (16 pages when the kernel is built with kasan enabled)
- * Assumptions:
- * 1. kernel size (including .bss size) and upper memory limit are page aligned.
- * 2. mem_detect memory region start is THREAD_SIZE aligned / end is PAGE_SIZE
- * aligned (in practice memory configurations granularity on z/VM and LPAR
- * is 1mb).
- *
- * To guarantee uniform distribution of kernel base address among all suitable
- * addresses we generate random value just once. For that we need to build a
- * continuous range in which every value would be suitable. We can build this
- * range by simply counting all suitable addresses (let's call them positions)
- * which would be valid as kernel base address. To count positions we iterate
- * over online memory ranges. For each range which is big enough for the
- * kernel image we count all suitable addresses we can put the kernel image at
- * that is
- * (end - start - kernel_size) / THREAD_SIZE + 1
- * Two functions count_valid_kernel_positions and position_to_address help
- * to count positions in memory range given and then convert position back
- * to address.
- */
-static unsigned long count_valid_kernel_positions(unsigned long kernel_size,
- unsigned long _min,
- unsigned long _max)
+static void sort_reserved_ranges(struct reserved_range *res, unsigned long size)
{
- unsigned long start, end, pos = 0;
- int i;
-
- for_each_mem_detect_usable_block(i, &start, &end) {
- if (_min >= end)
- continue;
- if (start >= _max)
- break;
- start = max(_min, start);
- end = min(_max, end);
- if (end - start < kernel_size)
- continue;
- pos += (end - start - kernel_size) / THREAD_SIZE + 1;
+ struct reserved_range tmp;
+ int i, j;
+
+ for (i = 1; i < size; i++) {
+ tmp = res[i];
+ for (j = i - 1; j >= 0 && res[j].start > tmp.start; j--)
+ res[j + 1] = res[j];
+ res[j + 1] = tmp;
}
-
- return pos;
}
-static unsigned long position_to_address(unsigned long pos, unsigned long kernel_size,
- unsigned long _min, unsigned long _max)
+static unsigned long iterate_valid_positions(unsigned long size, unsigned long align,
+ unsigned long _min, unsigned long _max,
+ struct reserved_range *res, size_t res_count,
+ bool pos_count, unsigned long find_pos)
{
- unsigned long start, end;
+ unsigned long start, end, tmp_end, range_pos, pos = 0;
+ struct reserved_range *res_end = res + res_count;
+ struct reserved_range *skip_res;
int i;
- for_each_mem_detect_usable_block(i, &start, &end) {
+ align = max(align, 8UL);
+ _min = round_up(_min, align);
+ for_each_physmem_usable_range(i, &start, &end) {
if (_min >= end)
continue;
+ start = round_up(start, align);
if (start >= _max)
break;
start = max(_min, start);
end = min(_max, end);
- if (end - start < kernel_size)
- continue;
- if ((end - start - kernel_size) / THREAD_SIZE + 1 >= pos)
- return start + (pos - 1) * THREAD_SIZE;
- pos -= (end - start - kernel_size) / THREAD_SIZE + 1;
+
+ while (start + size <= end) {
+ /* skip reserved ranges below the start */
+ while (res && res->end <= start) {
+ res++;
+ if (res >= res_end)
+ res = NULL;
+ }
+ skip_res = NULL;
+ tmp_end = end;
+ /* has intersecting reserved range */
+ if (res && res->start < end) {
+ skip_res = res;
+ tmp_end = res->start;
+ }
+ if (start + size <= tmp_end) {
+ range_pos = (tmp_end - start - size) / align + 1;

This diff is incomplete. Download the complete patch.

arch/s390/boot/pgm_check_info.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/boot/physmem_info.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/boot/startup.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/boot/vmem.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/boot/vmlinux.lds.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/crypto/chacha-s390.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/crypto/crc32be-vx.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/crypto/crc32le-vx.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/ap.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/checksum.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/diag.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/entry-common.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/fcx.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/kasan.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/linkage.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/mem_detect.h

View before deletion

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/nospec-insn.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/perf_event.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/pgtable.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/physmem_info.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/processor.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/set_memory.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/setup.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/stacktrace.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/string.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/include/asm/thread_info.h

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/debug.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/dumpstack.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/early.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/earlypgm.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/entry.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/ftrace.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/head64.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/ipl.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/kprobes.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/kprobes_insn_page.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/machine_kexec.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/mcount.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/module.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/perf_cpum_cf.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/perf_cpum_sf.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/process.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/processor.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/reipl.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/relocate_kernel.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/setup.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/smp.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/syscalls/syscall.tbl

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/text_amode31.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/topology.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/vdso32/vdso_user_wrapper.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/vdso64/vdso_user_wrapper.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/kernel/vmlinux.lds.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/lib/mem.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/lib/uaccess.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/Makefile

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/cmm.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/init.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/kasan_init.c

View before deletion

This diff is incomplete. Download the complete patch.

arch/s390/mm/pageattr.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/pgalloc.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/mm/vmem.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/pci/pci.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/pci/pci_bus.c

View file

This diff is incomplete. Download the complete patch.

arch/s390/purgatory/head.S

View file

This diff is incomplete. Download the complete patch.

arch/s390/purgatory/kexec-purgatory.S

View file

This diff is incomplete. Download the complete patch.

drivers/s390/char/sclp.h

View file

This diff is incomplete. Download the complete patch.

drivers/s390/char/sclp_cmd.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/char/sclp_early_core.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/cio/chsc.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/cio/chsc.h

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/ap_bus.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/ap_bus.h

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/ap_card.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/ap_queue.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/vfio_ap_drv.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/vfio_ap_ops.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_api.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_card.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_cca_key.h

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_ccamisc.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_cex2c.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_cex4.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_ep11misc.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_msgtype50.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_msgtype6.c

View file

This diff is incomplete. Download the complete patch.

drivers/s390/crypto/zcrypt_queue.c

View file

This diff is incomplete. Download the complete patch.

kernel/stackleak.c

View file

This diff is incomplete. Download the complete patch.

lib/Kconfig.debug

View file

This diff is incomplete. Download the complete patch.