aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-07-03 18:39:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-03 18:39:36 -0400
commite0f3e8f14da868047c524a0cf11e08b95fd1b008 (patch)
tree34dbd1fcd3b1b0631b235831ab672562bdc6de8f
parente5859eb84576ce7a0d95be6224d2e269c8daa741 (diff)
parent9e293b5a7062981016ace93160c56a980fcb73b8 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Pull s390 updates from Martin Schwidefsky: "The bulk of the s390 patches for 4.13. Some new things but mostly bug fixes and cleanups. Noteworthy changes: - The SCM block driver is converted to blk-mq - Switch s390 to 5 level page tables. The virtual address space for a user space process can now have up to 16EB-4KB. - Introduce a ELF phdr flag for qemu to avoid the global vm.alloc_pgste which forces all processes to large page tables - A couple of PCI improvements to improve error recovery - Included is the merge of the base support for proper machine checks for KVM" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (52 commits) s390/dasd: Fix faulty ENODEV for RO sysfs attribute s390/pci: recognize name clashes with uids s390/pci: provide more debug information s390/pci: fix handling of PEC 306 s390/pci: improve pci hotplug s390/pci: introduce clp_get_state s390/pci: improve error handling during fmb (de)registration s390/pci: improve unreg_ioat error handling s390/pci: improve error handling during interrupt deregistration s390/pci: don't cleanup in arch_setup_msi_irqs KVM: s390: Backup the guest's machine check info s390/nmi: s390: New low level handling for machine check happening in guest s390/fpu: export save_fpu_regs for all configs s390/kvm: avoid global config of vm.alloc_pgste=1 s390: rename struct psw_bits members s390: rename psw_bits enums s390/mm: use correct address space when enabling DAT s390/cio: introduce io_subchannel_type s390/ipl: revert Load Normal semantics for LPAR CCW-type re-IPL s390/dumpstack: remove raw stack dump ...
-rw-r--r--arch/s390/Kconfig3
-rw-r--r--arch/s390/crypto/Makefile3
-rw-r--r--arch/s390/crypto/arch_random.c1
-rw-r--r--arch/s390/include/asm/Kbuild2
-rw-r--r--arch/s390/include/asm/device.h10
-rw-r--r--arch/s390/include/asm/elf.h32
-rw-r--r--arch/s390/include/asm/fb.h12
-rw-r--r--arch/s390/include/asm/io.h4
-rw-r--r--arch/s390/include/asm/kvm_host.h17
-rw-r--r--arch/s390/include/asm/mmu_context.h4
-rw-r--r--arch/s390/include/asm/nmi.h7
-rw-r--r--arch/s390/include/asm/page.h3
-rw-r--r--arch/s390/include/asm/pci.h15
-rw-r--r--arch/s390/include/asm/pci_insn.h2
-rw-r--r--arch/s390/include/asm/pgalloc.h25
-rw-r--r--arch/s390/include/asm/pgtable.h105
-rw-r--r--arch/s390/include/asm/processor.h6
-rw-r--r--arch/s390/include/asm/ptrace.h54
-rw-r--r--arch/s390/include/asm/sigp.h2
-rw-r--r--arch/s390/include/asm/thread_info.h1
-rw-r--r--arch/s390/include/asm/tlb.h15
-rw-r--r--arch/s390/kernel/asm-offsets.c3
-rw-r--r--arch/s390/kernel/dumpstack.c33
-rw-r--r--arch/s390/kernel/entry.S30
-rw-r--r--arch/s390/kernel/nmi.c84
-rw-r--r--arch/s390/kernel/perf_cpum_sf.c10
-rw-r--r--arch/s390/kernel/perf_event.c3
-rw-r--r--arch/s390/kernel/ptrace.c15
-rw-r--r--arch/s390/kernel/smp.c3
-rw-r--r--arch/s390/kernel/traps.c1
-rw-r--r--arch/s390/kernel/uprobes.c12
-rw-r--r--arch/s390/kernel/vdso.c91
-rw-r--r--arch/s390/kernel/vtime.c14
-rw-r--r--arch/s390/kvm/gaccess.c22
-rw-r--r--arch/s390/kvm/gaccess.h4
-rw-r--r--arch/s390/kvm/guestdbg.c6
-rw-r--r--arch/s390/kvm/kvm-s390.c1
-rw-r--r--arch/s390/kvm/priv.c8
-rw-r--r--arch/s390/mm/dump_pagetables.c23
-rw-r--r--arch/s390/mm/fault.c2
-rw-r--r--arch/s390/mm/gmap.c11
-rw-r--r--arch/s390/mm/gup.c33
-rw-r--r--arch/s390/mm/hugetlbpage.c30
-rw-r--r--arch/s390/mm/init.c6
-rw-r--r--arch/s390/mm/mmap.c4
-rw-r--r--arch/s390/mm/pageattr.c30
-rw-r--r--arch/s390/mm/pgalloc.c57
-rw-r--r--arch/s390/mm/pgtable.c6
-rw-r--r--arch/s390/mm/vmem.c44
-rw-r--r--arch/s390/pci/pci.c173
-rw-r--r--arch/s390/pci/pci_clp.c77
-rw-r--r--arch/s390/pci/pci_dma.c4
-rw-r--r--arch/s390/pci/pci_event.c14
-rw-r--r--arch/s390/pci/pci_insn.c10
-rw-r--r--arch/s390/tools/gen_facilities.c2
-rw-r--r--drivers/crypto/Kconfig15
-rw-r--r--drivers/s390/block/Kconfig7
-rw-r--r--drivers/s390/block/Makefile3
-rw-r--r--drivers/s390/block/dasd.c76
-rw-r--r--drivers/s390/block/dasd_devmap.c75
-rw-r--r--drivers/s390/block/scm_blk.c262
-rw-r--r--drivers/s390/block/scm_blk.h60
-rw-r--r--drivers/s390/block/scm_blk_cluster.c255
-rw-r--r--drivers/s390/cio/css.c49
-rw-r--r--drivers/s390/cio/device.c42
-rw-r--r--drivers/s390/cio/vfio_ccw_drv.c58
-rw-r--r--drivers/s390/crypto/ap_bus.c21
-rw-r--r--drivers/s390/crypto/pkey_api.c6
-rw-r--r--drivers/s390/crypto/zcrypt_api.c12
-rw-r--r--drivers/s390/crypto/zcrypt_cca_key.h115
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype6.c4
-rw-r--r--drivers/tty/hvc/Kconfig2
72 files changed, 1135 insertions, 1116 deletions
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 6967addc6a89..37abe86e5bc9 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -64,6 +64,7 @@ config ARCH_SUPPORTS_UPROBES
64 64
65config S390 65config S390
66 def_bool y 66 def_bool y
67 select ARCH_BINFMT_ELF_STATE
67 select ARCH_HAS_DEVMEM_IS_ALLOWED 68 select ARCH_HAS_DEVMEM_IS_ALLOWED
68 select ARCH_HAS_ELF_RANDOMIZE 69 select ARCH_HAS_ELF_RANDOMIZE
69 select ARCH_HAS_GCOV_PROFILE_ALL 70 select ARCH_HAS_GCOV_PROFILE_ALL
@@ -184,7 +185,7 @@ config SCHED_OMIT_FRAME_POINTER
184 185
185config PGTABLE_LEVELS 186config PGTABLE_LEVELS
186 int 187 int
187 default 4 188 default 5
188 189
189source "init/Kconfig" 190source "init/Kconfig"
190 191
diff --git a/arch/s390/crypto/Makefile b/arch/s390/crypto/Makefile
index 678d9863e3f0..ad4bd777768d 100644
--- a/arch/s390/crypto/Makefile
+++ b/arch/s390/crypto/Makefile
@@ -6,7 +6,8 @@ obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o
6obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256_s390.o sha_common.o 6obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256_s390.o sha_common.o
7obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o 7obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o
8obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o 8obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o
9obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o paes_s390.o 9obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o
10obj-$(CONFIG_CRYPTO_PAES_S390) += paes_s390.o
10obj-$(CONFIG_S390_PRNG) += prng.o 11obj-$(CONFIG_S390_PRNG) += prng.o
11obj-$(CONFIG_CRYPTO_GHASH_S390) += ghash_s390.o 12obj-$(CONFIG_CRYPTO_GHASH_S390) += ghash_s390.o
12obj-$(CONFIG_CRYPTO_CRC32_S390) += crc32-vx_s390.o 13obj-$(CONFIG_CRYPTO_CRC32_S390) += crc32-vx_s390.o
diff --git a/arch/s390/crypto/arch_random.c b/arch/s390/crypto/arch_random.c
index 9317b3e645e2..36aefc07d10c 100644
--- a/arch/s390/crypto/arch_random.c
+++ b/arch/s390/crypto/arch_random.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/atomic.h> 14#include <linux/atomic.h>
15#include <linux/random.h>
15#include <linux/static_key.h> 16#include <linux/static_key.h>
16#include <asm/cpacf.h> 17#include <asm/cpacf.h>
17 18
diff --git a/arch/s390/include/asm/Kbuild b/arch/s390/include/asm/Kbuild
index 45092b12f54f..b3c88479feba 100644
--- a/arch/s390/include/asm/Kbuild
+++ b/arch/s390/include/asm/Kbuild
@@ -1,10 +1,12 @@
1generic-y += asm-offsets.h 1generic-y += asm-offsets.h
2generic-y += cacheflush.h 2generic-y += cacheflush.h
3generic-y += clkdev.h 3generic-y += clkdev.h
4generic-y += device.h
4generic-y += dma-contiguous.h 5generic-y += dma-contiguous.h
5generic-y += div64.h 6generic-y += div64.h
6generic-y += emergency-restart.h 7generic-y += emergency-restart.h
7generic-y += export.h 8generic-y += export.h
9generic-y += fb.h
8generic-y += irq_regs.h 10generic-y += irq_regs.h
9generic-y += irq_work.h 11generic-y += irq_work.h
10generic-y += kmap_types.h 12generic-y += kmap_types.h
diff --git a/arch/s390/include/asm/device.h b/arch/s390/include/asm/device.h
deleted file mode 100644
index 5203fc87f080..000000000000
--- a/arch/s390/include/asm/device.h
+++ /dev/null
@@ -1,10 +0,0 @@
1/*
2 * Arch specific extensions to struct device
3 *
4 * This file is released under the GPLv2
5 */
6struct dev_archdata {
7};
8
9struct pdev_archdata {
10};
diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
index e8f623041769..ec024c08dabe 100644
--- a/arch/s390/include/asm/elf.h
+++ b/arch/s390/include/asm/elf.h
@@ -117,6 +117,9 @@
117#define ELF_DATA ELFDATA2MSB 117#define ELF_DATA ELFDATA2MSB
118#define ELF_ARCH EM_S390 118#define ELF_ARCH EM_S390
119 119
120/* s390 specific phdr types */
121#define PT_S390_PGSTE 0x70000000
122
120/* 123/*
121 * ELF register definitions.. 124 * ELF register definitions..
122 */ 125 */
@@ -151,6 +154,35 @@ extern unsigned int vdso_enabled;
151 && (x)->e_ident[EI_CLASS] == ELF_CLASS) 154 && (x)->e_ident[EI_CLASS] == ELF_CLASS)
152#define compat_start_thread start_thread31 155#define compat_start_thread start_thread31
153 156
157struct arch_elf_state {
158 int rc;
159};
160
161#define INIT_ARCH_ELF_STATE { .rc = 0 }
162
163#define arch_check_elf(ehdr, interp, interp_ehdr, state) (0)
164#ifdef CONFIG_PGSTE
165#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) \
166({ \
167 struct arch_elf_state *_state = state; \
168 if ((phdr)->p_type == PT_S390_PGSTE && \
169 !page_table_allocate_pgste && \
170 !test_thread_flag(TIF_PGSTE) && \
171 !current->mm->context.alloc_pgste) { \
172 set_thread_flag(TIF_PGSTE); \
173 set_pt_regs_flag(task_pt_regs(current), \
174 PIF_SYSCALL_RESTART); \
175 _state->rc = -EAGAIN; \
176 } \
177 _state->rc; \
178})
179#else
180#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) \
181({ \
182 (state)->rc; \
183})
184#endif
185
154/* For SVR4/S390 the function pointer to be registered with `atexit` is 186/* For SVR4/S390 the function pointer to be registered with `atexit` is
155 passed in R14. */ 187 passed in R14. */
156#define ELF_PLAT_INIT(_r, load_addr) \ 188#define ELF_PLAT_INIT(_r, load_addr) \
diff --git a/arch/s390/include/asm/fb.h b/arch/s390/include/asm/fb.h
deleted file mode 100644
index c7df38030992..000000000000
--- a/arch/s390/include/asm/fb.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef _ASM_FB_H_
2#define _ASM_FB_H_
3#include <linux/fb.h>
4
5#define fb_pgprotect(...) do {} while (0)
6
7static inline int fb_is_primary_device(struct fb_info *info)
8{
9 return 0;
10}
11
12#endif /* _ASM_FB_H_ */
diff --git a/arch/s390/include/asm/io.h b/arch/s390/include/asm/io.h
index 437e9af96688..904e4b3af95d 100644
--- a/arch/s390/include/asm/io.h
+++ b/arch/s390/include/asm/io.h
@@ -25,8 +25,6 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
25 25
26#define IO_SPACE_LIMIT 0 26#define IO_SPACE_LIMIT 0
27 27
28#ifdef CONFIG_PCI
29
30#define ioremap_nocache(addr, size) ioremap(addr, size) 28#define ioremap_nocache(addr, size) ioremap(addr, size)
31#define ioremap_wc ioremap_nocache 29#define ioremap_wc ioremap_nocache
32#define ioremap_wt ioremap_nocache 30#define ioremap_wt ioremap_nocache
@@ -49,6 +47,8 @@ static inline void ioport_unmap(void __iomem *p)
49{ 47{
50} 48}
51 49
50#ifdef CONFIG_PCI
51
52/* 52/*
53 * s390 needs a private implementation of pci_iomap since ioremap with its 53 * s390 needs a private implementation of pci_iomap since ioremap with its
54 * offset parameter isn't sufficient. That's because BAR spaces are not 54 * offset parameter isn't sufficient. That's because BAR spaces are not
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 65d07ac34647..6baae236f461 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -107,6 +107,20 @@ struct esca_block {
107 struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS]; 107 struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
108} __packed; 108} __packed;
109 109
110/*
111 * This struct is used to store some machine check info from lowcore
112 * for machine checks that happen while the guest is running.
113 * This info in host's lowcore might be overwritten by a second machine
114 * check from host when host is in the machine check's high-level handling.
115 * The size is 24 bytes.
116 */
117struct mcck_volatile_info {
118 __u64 mcic;
119 __u64 failing_storage_address;
120 __u32 ext_damage_code;
121 __u32 reserved;
122};
123
110#define CPUSTAT_STOPPED 0x80000000 124#define CPUSTAT_STOPPED 0x80000000
111#define CPUSTAT_WAIT 0x10000000 125#define CPUSTAT_WAIT 0x10000000
112#define CPUSTAT_ECALL_PEND 0x08000000 126#define CPUSTAT_ECALL_PEND 0x08000000
@@ -264,7 +278,8 @@ struct kvm_s390_itdb {
264 278
265struct sie_page { 279struct sie_page {
266 struct kvm_s390_sie_block sie_block; 280 struct kvm_s390_sie_block sie_block;
267 __u8 reserved200[1024]; /* 0x0200 */ 281 struct mcck_volatile_info mcck_info; /* 0x0200 */
282 __u8 reserved218[1000]; /* 0x0218 */
268 struct kvm_s390_itdb itdb; /* 0x0600 */ 283 struct kvm_s390_itdb itdb; /* 0x0600 */
269 __u8 reserved700[2304]; /* 0x0700 */ 284 __u8 reserved700[2304]; /* 0x0700 */
270} __packed; 285} __packed;
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index 8712e11bead4..4541ac44b35f 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -25,7 +25,9 @@ static inline int init_new_context(struct task_struct *tsk,
25 mm->context.gmap_asce = 0; 25 mm->context.gmap_asce = 0;
26 mm->context.flush_mm = 0; 26 mm->context.flush_mm = 0;
27#ifdef CONFIG_PGSTE 27#ifdef CONFIG_PGSTE
28 mm->context.alloc_pgste = page_table_allocate_pgste; 28 mm->context.alloc_pgste = page_table_allocate_pgste ||
29 test_thread_flag(TIF_PGSTE) ||
30 current->mm->context.alloc_pgste;
29 mm->context.has_pgste = 0; 31 mm->context.has_pgste = 0;
30 mm->context.use_skey = 0; 32 mm->context.use_skey = 0;
31 mm->context.use_cmma = 0; 33 mm->context.use_cmma = 0;
diff --git a/arch/s390/include/asm/nmi.h b/arch/s390/include/asm/nmi.h
index e3e8895f5d3e..13623b9991d4 100644
--- a/arch/s390/include/asm/nmi.h
+++ b/arch/s390/include/asm/nmi.h
@@ -14,7 +14,14 @@
14#include <linux/const.h> 14#include <linux/const.h>
15#include <linux/types.h> 15#include <linux/types.h>
16 16
17#define MCIC_SUBCLASS_MASK (1ULL<<63 | 1ULL<<62 | 1ULL<<61 | \
18 1ULL<<59 | 1ULL<<58 | 1ULL<<56 | \
19 1ULL<<55 | 1ULL<<54 | 1ULL<<53 | \
20 1ULL<<52 | 1ULL<<47 | 1ULL<<46 | \
21 1ULL<<45 | 1ULL<<44)
17#define MCCK_CODE_SYSTEM_DAMAGE _BITUL(63) 22#define MCCK_CODE_SYSTEM_DAMAGE _BITUL(63)
23#define MCCK_CODE_EXT_DAMAGE _BITUL(63 - 5)
24#define MCCK_CODE_CP _BITUL(63 - 9)
18#define MCCK_CODE_CPU_TIMER_VALID _BITUL(63 - 46) 25#define MCCK_CODE_CPU_TIMER_VALID _BITUL(63 - 46)
19#define MCCK_CODE_PSW_MWP_VALID _BITUL(63 - 20) 26#define MCCK_CODE_PSW_MWP_VALID _BITUL(63 - 20)
20#define MCCK_CODE_PSW_IA_VALID _BITUL(63 - 23) 27#define MCCK_CODE_PSW_IA_VALID _BITUL(63 - 23)
diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h
index 69b8a41fca84..624deaa44230 100644
--- a/arch/s390/include/asm/page.h
+++ b/arch/s390/include/asm/page.h
@@ -74,6 +74,7 @@ typedef struct { unsigned long pgste; } pgste_t;
74typedef struct { unsigned long pte; } pte_t; 74typedef struct { unsigned long pte; } pte_t;
75typedef struct { unsigned long pmd; } pmd_t; 75typedef struct { unsigned long pmd; } pmd_t;
76typedef struct { unsigned long pud; } pud_t; 76typedef struct { unsigned long pud; } pud_t;
77typedef struct { unsigned long p4d; } p4d_t;
77typedef struct { unsigned long pgd; } pgd_t; 78typedef struct { unsigned long pgd; } pgd_t;
78typedef pte_t *pgtable_t; 79typedef pte_t *pgtable_t;
79 80
@@ -82,12 +83,14 @@ typedef pte_t *pgtable_t;
82#define pte_val(x) ((x).pte) 83#define pte_val(x) ((x).pte)
83#define pmd_val(x) ((x).pmd) 84#define pmd_val(x) ((x).pmd)
84#define pud_val(x) ((x).pud) 85#define pud_val(x) ((x).pud)
86#define p4d_val(x) ((x).p4d)
85#define pgd_val(x) ((x).pgd) 87#define pgd_val(x) ((x).pgd)
86 88
87#define __pgste(x) ((pgste_t) { (x) } ) 89#define __pgste(x) ((pgste_t) { (x) } )
88#define __pte(x) ((pte_t) { (x) } ) 90#define __pte(x) ((pte_t) { (x) } )
89#define __pmd(x) ((pmd_t) { (x) } ) 91#define __pmd(x) ((pmd_t) { (x) } )
90#define __pud(x) ((pud_t) { (x) } ) 92#define __pud(x) ((pud_t) { (x) } )
93#define __p4d(x) ((p4d_t) { (x) } )
91#define __pgd(x) ((pgd_t) { (x) } ) 94#define __pgd(x) ((pgd_t) { (x) } )
92#define __pgprot(x) ((pgprot_t) { (x) } ) 95#define __pgprot(x) ((pgprot_t) { (x) } )
93 96
diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h
index 4e3186649578..f36b4b726057 100644
--- a/arch/s390/include/asm/pci.h
+++ b/arch/s390/include/asm/pci.h
@@ -70,11 +70,10 @@ struct zpci_fmb {
70} __packed __aligned(128); 70} __packed __aligned(128);
71 71
72enum zpci_state { 72enum zpci_state {
73 ZPCI_FN_STATE_RESERVED, 73 ZPCI_FN_STATE_STANDBY = 0,
74 ZPCI_FN_STATE_STANDBY, 74 ZPCI_FN_STATE_CONFIGURED = 1,
75 ZPCI_FN_STATE_CONFIGURED, 75 ZPCI_FN_STATE_RESERVED = 2,
76 ZPCI_FN_STATE_ONLINE, 76 ZPCI_FN_STATE_ONLINE = 3,
77 NR_ZPCI_FN_STATES,
78}; 77};
79 78
80struct zpci_bar_struct { 79struct zpci_bar_struct {
@@ -109,7 +108,7 @@ struct zpci_dev {
109 u64 msi_addr; /* MSI address */ 108 u64 msi_addr; /* MSI address */
110 unsigned int max_msi; /* maximum number of MSI's */ 109 unsigned int max_msi; /* maximum number of MSI's */
111 struct airq_iv *aibv; /* adapter interrupt bit vector */ 110 struct airq_iv *aibv; /* adapter interrupt bit vector */
112 unsigned int aisb; /* number of the summary bit */ 111 unsigned long aisb; /* number of the summary bit */
113 112
114 /* DMA stuff */ 113 /* DMA stuff */
115 unsigned long *dma_table; 114 unsigned long *dma_table;
@@ -159,11 +158,12 @@ extern const struct attribute_group *zpci_attr_groups[];
159----------------------------------------------------------------------------- */ 158----------------------------------------------------------------------------- */
160/* Base stuff */ 159/* Base stuff */
161int zpci_create_device(struct zpci_dev *); 160int zpci_create_device(struct zpci_dev *);
161void zpci_remove_device(struct zpci_dev *zdev);
162int zpci_enable_device(struct zpci_dev *); 162int zpci_enable_device(struct zpci_dev *);
163int zpci_disable_device(struct zpci_dev *); 163int zpci_disable_device(struct zpci_dev *);
164void zpci_stop_device(struct zpci_dev *);
165int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64); 164int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
166int zpci_unregister_ioat(struct zpci_dev *, u8); 165int zpci_unregister_ioat(struct zpci_dev *, u8);
166void zpci_remove_reserved_devices(void);
167 167
168/* CLP */ 168/* CLP */
169int clp_scan_pci_devices(void); 169int clp_scan_pci_devices(void);
@@ -172,6 +172,7 @@ int clp_rescan_pci_devices_simple(void);
172int clp_add_pci_device(u32, u32, int); 172int clp_add_pci_device(u32, u32, int);
173int clp_enable_fh(struct zpci_dev *, u8); 173int clp_enable_fh(struct zpci_dev *, u8);
174int clp_disable_fh(struct zpci_dev *); 174int clp_disable_fh(struct zpci_dev *);
175int clp_get_state(u32 fid, enum zpci_state *state);
175 176
176#ifdef CONFIG_PCI 177#ifdef CONFIG_PCI
177/* Error handling and recovery */ 178/* Error handling and recovery */
diff --git a/arch/s390/include/asm/pci_insn.h b/arch/s390/include/asm/pci_insn.h
index 649eb62c52b3..34abcf275799 100644
--- a/arch/s390/include/asm/pci_insn.h
+++ b/arch/s390/include/asm/pci_insn.h
@@ -76,7 +76,7 @@ struct zpci_fib {
76 u32 gd; 76 u32 gd;
77} __packed __aligned(8); 77} __packed __aligned(8);
78 78
79int zpci_mod_fc(u64 req, struct zpci_fib *fib); 79u8 zpci_mod_fc(u64 req, struct zpci_fib *fib, u8 *status);
80int zpci_refresh_trans(u64 fn, u64 addr, u64 range); 80int zpci_refresh_trans(u64 fn, u64 addr, u64 range);
81int zpci_load(u64 *data, u64 req, u64 offset); 81int zpci_load(u64 *data, u64 req, u64 offset);
82int zpci_store(u64 data, u64 req, u64 offset); 82int zpci_store(u64 data, u64 req, u64 offset);
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index 166f703dad7c..bb0ff1bb0c4a 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -51,12 +51,24 @@ static inline unsigned long pgd_entry_type(struct mm_struct *mm)
51 return _SEGMENT_ENTRY_EMPTY; 51 return _SEGMENT_ENTRY_EMPTY;
52 if (mm->context.asce_limit <= (1UL << 42)) 52 if (mm->context.asce_limit <= (1UL << 42))
53 return _REGION3_ENTRY_EMPTY; 53 return _REGION3_ENTRY_EMPTY;
54 return _REGION2_ENTRY_EMPTY; 54 if (mm->context.asce_limit <= (1UL << 53))
55 return _REGION2_ENTRY_EMPTY;
56 return _REGION1_ENTRY_EMPTY;
55} 57}
56 58
57int crst_table_upgrade(struct mm_struct *); 59int crst_table_upgrade(struct mm_struct *mm, unsigned long limit);
58void crst_table_downgrade(struct mm_struct *); 60void crst_table_downgrade(struct mm_struct *);
59 61
62static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long address)
63{
64 unsigned long *table = crst_table_alloc(mm);
65
66 if (table)
67 crst_table_init(table, _REGION2_ENTRY_EMPTY);
68 return (p4d_t *) table;
69}
70#define p4d_free(mm, p4d) crst_table_free(mm, (unsigned long *) p4d)
71
60static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address) 72static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
61{ 73{
62 unsigned long *table = crst_table_alloc(mm); 74 unsigned long *table = crst_table_alloc(mm);
@@ -86,9 +98,14 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
86 crst_table_free(mm, (unsigned long *) pmd); 98 crst_table_free(mm, (unsigned long *) pmd);
87} 99}
88 100
89static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud) 101static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d)
102{
103 pgd_val(*pgd) = _REGION1_ENTRY | __pa(p4d);
104}
105
106static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
90{ 107{
91 pgd_val(*pgd) = _REGION2_ENTRY | __pa(pud); 108 p4d_val(*p4d) = _REGION2_ENTRY | __pa(pud);
92} 109}
93 110
94static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) 111static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index e6e3b887bee3..57057fb1cc07 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -24,7 +24,6 @@
24 * the S390 page table tree. 24 * the S390 page table tree.
25 */ 25 */
26#ifndef __ASSEMBLY__ 26#ifndef __ASSEMBLY__
27#include <asm-generic/5level-fixup.h>
28#include <linux/sched.h> 27#include <linux/sched.h>
29#include <linux/mm_types.h> 28#include <linux/mm_types.h>
30#include <linux/page-flags.h> 29#include <linux/page-flags.h>
@@ -87,12 +86,15 @@ extern unsigned long zero_page_mask;
87 */ 86 */
88#define PMD_SHIFT 20 87#define PMD_SHIFT 20
89#define PUD_SHIFT 31 88#define PUD_SHIFT 31
90#define PGDIR_SHIFT 42 89#define P4D_SHIFT 42
90#define PGDIR_SHIFT 53
91 91
92#define PMD_SIZE (1UL << PMD_SHIFT) 92#define PMD_SIZE (1UL << PMD_SHIFT)
93#define PMD_MASK (~(PMD_SIZE-1)) 93#define PMD_MASK (~(PMD_SIZE-1))
94#define PUD_SIZE (1UL << PUD_SHIFT) 94#define PUD_SIZE (1UL << PUD_SHIFT)
95#define PUD_MASK (~(PUD_SIZE-1)) 95#define PUD_MASK (~(PUD_SIZE-1))
96#define P4D_SIZE (1UL << P4D_SHIFT)
97#define P4D_MASK (~(P4D_SIZE-1))
96#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 98#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
97#define PGDIR_MASK (~(PGDIR_SIZE-1)) 99#define PGDIR_MASK (~(PGDIR_SIZE-1))
98 100
@@ -105,6 +107,7 @@ extern unsigned long zero_page_mask;
105#define PTRS_PER_PTE 256 107#define PTRS_PER_PTE 256
106#define PTRS_PER_PMD 2048 108#define PTRS_PER_PMD 2048
107#define PTRS_PER_PUD 2048 109#define PTRS_PER_PUD 2048
110#define PTRS_PER_P4D 2048
108#define PTRS_PER_PGD 2048 111#define PTRS_PER_PGD 2048
109 112
110#define FIRST_USER_ADDRESS 0UL 113#define FIRST_USER_ADDRESS 0UL
@@ -115,6 +118,8 @@ extern unsigned long zero_page_mask;
115 printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e)) 118 printk("%s:%d: bad pmd %p.\n", __FILE__, __LINE__, (void *) pmd_val(e))
116#define pud_ERROR(e) \ 119#define pud_ERROR(e) \
117 printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e)) 120 printk("%s:%d: bad pud %p.\n", __FILE__, __LINE__, (void *) pud_val(e))
121#define p4d_ERROR(e) \
122 printk("%s:%d: bad p4d %p.\n", __FILE__, __LINE__, (void *) p4d_val(e))
118#define pgd_ERROR(e) \ 123#define pgd_ERROR(e) \
119 printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e)) 124 printk("%s:%d: bad pgd %p.\n", __FILE__, __LINE__, (void *) pgd_val(e))
120 125
@@ -296,8 +301,6 @@ static inline int is_module_addr(void *addr)
296#define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INVALID) 301#define _REGION3_ENTRY_EMPTY (_REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INVALID)
297 302
298#define _REGION3_ENTRY_ORIGIN_LARGE ~0x7fffffffUL /* large page address */ 303#define _REGION3_ENTRY_ORIGIN_LARGE ~0x7fffffffUL /* large page address */
299#define _REGION3_ENTRY_ORIGIN ~0x7ffUL/* region third table origin */
300
301#define _REGION3_ENTRY_DIRTY 0x2000 /* SW region dirty bit */ 304#define _REGION3_ENTRY_DIRTY 0x2000 /* SW region dirty bit */
302#define _REGION3_ENTRY_YOUNG 0x1000 /* SW region young bit */ 305#define _REGION3_ENTRY_YOUNG 0x1000 /* SW region young bit */
303#define _REGION3_ENTRY_LARGE 0x0400 /* RTTE-format control, large page */ 306#define _REGION3_ENTRY_LARGE 0x0400 /* RTTE-format control, large page */
@@ -310,8 +313,8 @@ static inline int is_module_addr(void *addr)
310#define _REGION3_ENTRY_SOFT_DIRTY 0x0000 /* SW region soft dirty bit */ 313#define _REGION3_ENTRY_SOFT_DIRTY 0x0000 /* SW region soft dirty bit */
311#endif 314#endif
312 315
313#define _REGION_ENTRY_BITS 0xfffffffffffff227UL 316#define _REGION_ENTRY_BITS 0xfffffffffffff22fUL
314#define _REGION_ENTRY_BITS_LARGE 0xffffffff8000fe27UL 317#define _REGION_ENTRY_BITS_LARGE 0xffffffff8000fe2fUL
315 318
316/* Bits in the segment table entry */ 319/* Bits in the segment table entry */
317#define _SEGMENT_ENTRY_BITS 0xfffffffffffffe33UL 320#define _SEGMENT_ENTRY_BITS 0xfffffffffffffe33UL
@@ -560,18 +563,23 @@ static inline void crdte(unsigned long old, unsigned long new,
560} 563}
561 564
562/* 565/*
563 * pgd/pmd/pte query functions 566 * pgd/p4d/pud/pmd/pte query functions
564 */ 567 */
568static inline int pgd_folded(pgd_t pgd)
569{
570 return (pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R1;
571}
572
565static inline int pgd_present(pgd_t pgd) 573static inline int pgd_present(pgd_t pgd)
566{ 574{
567 if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2) 575 if (pgd_folded(pgd))
568 return 1; 576 return 1;
569 return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL; 577 return (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) != 0UL;
570} 578}
571 579
572static inline int pgd_none(pgd_t pgd) 580static inline int pgd_none(pgd_t pgd)
573{ 581{
574 if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2) 582 if (pgd_folded(pgd))
575 return 0; 583 return 0;
576 return (pgd_val(pgd) & _REGION_ENTRY_INVALID) != 0UL; 584 return (pgd_val(pgd) & _REGION_ENTRY_INVALID) != 0UL;
577} 585}
@@ -589,16 +597,48 @@ static inline int pgd_bad(pgd_t pgd)
589 return (pgd_val(pgd) & mask) != 0; 597 return (pgd_val(pgd) & mask) != 0;
590} 598}
591 599
600static inline int p4d_folded(p4d_t p4d)
601{
602 return (p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2;
603}
604
605static inline int p4d_present(p4d_t p4d)
606{
607 if (p4d_folded(p4d))
608 return 1;
609 return (p4d_val(p4d) & _REGION_ENTRY_ORIGIN) != 0UL;
610}
611
612static inline int p4d_none(p4d_t p4d)
613{
614 if (p4d_folded(p4d))
615 return 0;
616 return p4d_val(p4d) == _REGION2_ENTRY_EMPTY;
617}
618
619static inline unsigned long p4d_pfn(p4d_t p4d)
620{
621 unsigned long origin_mask;
622
623 origin_mask = _REGION_ENTRY_ORIGIN;
624 return (p4d_val(p4d) & origin_mask) >> PAGE_SHIFT;
625}
626
627static inline int pud_folded(pud_t pud)
628{
629 return (pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3;
630}
631
592static inline int pud_present(pud_t pud) 632static inline int pud_present(pud_t pud)
593{ 633{
594 if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3) 634 if (pud_folded(pud))
595 return 1; 635 return 1;
596 return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL; 636 return (pud_val(pud) & _REGION_ENTRY_ORIGIN) != 0UL;
597} 637}
598 638
599static inline int pud_none(pud_t pud) 639static inline int pud_none(pud_t pud)
600{ 640{
601 if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R3) 641 if (pud_folded(pud))
602 return 0; 642 return 0;
603 return pud_val(pud) == _REGION3_ENTRY_EMPTY; 643 return pud_val(pud) == _REGION3_ENTRY_EMPTY;
604} 644}
@@ -614,7 +654,7 @@ static inline unsigned long pud_pfn(pud_t pud)
614{ 654{
615 unsigned long origin_mask; 655 unsigned long origin_mask;
616 656
617 origin_mask = _REGION3_ENTRY_ORIGIN; 657 origin_mask = _REGION_ENTRY_ORIGIN;
618 if (pud_large(pud)) 658 if (pud_large(pud))
619 origin_mask = _REGION3_ENTRY_ORIGIN_LARGE; 659 origin_mask = _REGION3_ENTRY_ORIGIN_LARGE;
620 return (pud_val(pud) & origin_mask) >> PAGE_SHIFT; 660 return (pud_val(pud) & origin_mask) >> PAGE_SHIFT;
@@ -641,6 +681,13 @@ static inline int pud_bad(pud_t pud)
641 return (pud_val(pud) & ~_REGION_ENTRY_BITS) != 0; 681 return (pud_val(pud) & ~_REGION_ENTRY_BITS) != 0;
642} 682}
643 683
684static inline int p4d_bad(p4d_t p4d)
685{
686 if ((p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) < _REGION_ENTRY_TYPE_R2)
687 return pud_bad(__pud(p4d_val(p4d)));
688 return (p4d_val(p4d) & ~_REGION_ENTRY_BITS) != 0;
689}
690
644static inline int pmd_present(pmd_t pmd) 691static inline int pmd_present(pmd_t pmd)
645{ 692{
646 return pmd_val(pmd) != _SEGMENT_ENTRY_EMPTY; 693 return pmd_val(pmd) != _SEGMENT_ENTRY_EMPTY;
@@ -794,8 +841,14 @@ static inline int pte_unused(pte_t pte)
794 841
795static inline void pgd_clear(pgd_t *pgd) 842static inline void pgd_clear(pgd_t *pgd)
796{ 843{
797 if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2) 844 if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R1)
798 pgd_val(*pgd) = _REGION2_ENTRY_EMPTY; 845 pgd_val(*pgd) = _REGION1_ENTRY_EMPTY;
846}
847
848static inline void p4d_clear(p4d_t *p4d)
849{
850 if ((p4d_val(*p4d) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
851 p4d_val(*p4d) = _REGION2_ENTRY_EMPTY;
799} 852}
800 853
801static inline void pud_clear(pud_t *pud) 854static inline void pud_clear(pud_t *pud)
@@ -1089,6 +1142,7 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
1089} 1142}
1090 1143
1091#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) 1144#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
1145#define p4d_index(address) (((address) >> P4D_SHIFT) & (PTRS_PER_P4D-1))
1092#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1)) 1146#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
1093#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) 1147#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
1094#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1)) 1148#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE-1))
@@ -1098,19 +1152,31 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
1098 1152
1099#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) 1153#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN)
1100#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN) 1154#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN)
1155#define p4d_deref(pud) (p4d_val(pud) & _REGION_ENTRY_ORIGIN)
1101#define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) 1156#define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN)
1102 1157
1103static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address) 1158static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
1104{ 1159{
1105 pud_t *pud = (pud_t *) pgd; 1160 p4d_t *p4d = (p4d_t *) pgd;
1106 if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2) 1161
1107 pud = (pud_t *) pgd_deref(*pgd); 1162 if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R1)
1108 return pud + pud_index(address); 1163 p4d = (p4d_t *) pgd_deref(*pgd);
1164 return p4d + p4d_index(address);
1165}
1166
1167static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
1168{
1169 pud_t *pud = (pud_t *) p4d;
1170
1171 if ((p4d_val(*p4d) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
1172 pud = (pud_t *) p4d_deref(*p4d);
1173 return pud + pud_index(address);
1109} 1174}
1110 1175
1111static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address) 1176static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
1112{ 1177{
1113 pmd_t *pmd = (pmd_t *) pud; 1178 pmd_t *pmd = (pmd_t *) pud;
1179
1114 if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) 1180 if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
1115 pmd = (pmd_t *) pud_deref(*pud); 1181 pmd = (pmd_t *) pud_deref(*pud);
1116 return pmd + pmd_index(address); 1182 return pmd + pmd_index(address);
@@ -1122,6 +1188,7 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
1122 1188
1123#define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd)) 1189#define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd))
1124#define pud_page(pud) pfn_to_page(pud_pfn(pud)) 1190#define pud_page(pud) pfn_to_page(pud_pfn(pud))
1191#define p4d_page(pud) pfn_to_page(p4d_pfn(p4d))
1125 1192
1126/* Find an entry in the lowest level page table.. */ 1193/* Find an entry in the lowest level page table.. */
1127#define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr)) 1194#define pte_offset(pmd, addr) ((pte_t *) pmd_deref(*(pmd)) + pte_index(addr))
diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index aeac013968f2..c25d57e0aad3 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -20,6 +20,7 @@
20#define CIF_FPU 4 /* restore FPU registers */ 20#define CIF_FPU 4 /* restore FPU registers */
21#define CIF_IGNORE_IRQ 5 /* ignore interrupt (for udelay) */ 21#define CIF_IGNORE_IRQ 5 /* ignore interrupt (for udelay) */
22#define CIF_ENABLED_WAIT 6 /* in enabled wait state */ 22#define CIF_ENABLED_WAIT 6 /* in enabled wait state */
23#define CIF_MCCK_GUEST 7 /* machine check happening in guest */
23 24
24#define _CIF_MCCK_PENDING _BITUL(CIF_MCCK_PENDING) 25#define _CIF_MCCK_PENDING _BITUL(CIF_MCCK_PENDING)
25#define _CIF_ASCE_PRIMARY _BITUL(CIF_ASCE_PRIMARY) 26#define _CIF_ASCE_PRIMARY _BITUL(CIF_ASCE_PRIMARY)
@@ -28,6 +29,7 @@
28#define _CIF_FPU _BITUL(CIF_FPU) 29#define _CIF_FPU _BITUL(CIF_FPU)
29#define _CIF_IGNORE_IRQ _BITUL(CIF_IGNORE_IRQ) 30#define _CIF_IGNORE_IRQ _BITUL(CIF_IGNORE_IRQ)
30#define _CIF_ENABLED_WAIT _BITUL(CIF_ENABLED_WAIT) 31#define _CIF_ENABLED_WAIT _BITUL(CIF_ENABLED_WAIT)
32#define _CIF_MCCK_GUEST _BITUL(CIF_MCCK_GUEST)
31 33
32#ifndef __ASSEMBLY__ 34#ifndef __ASSEMBLY__
33 35
@@ -92,11 +94,11 @@ extern void execve_tail(void);
92 */ 94 */
93 95
94#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_31BIT) ? \ 96#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_31BIT) ? \
95 (1UL << 31) : (1UL << 53)) 97 (1UL << 31) : -PAGE_SIZE)
96#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \ 98#define TASK_UNMAPPED_BASE (test_thread_flag(TIF_31BIT) ? \
97 (1UL << 30) : (1UL << 41)) 99 (1UL << 30) : (1UL << 41))
98#define TASK_SIZE TASK_SIZE_OF(current) 100#define TASK_SIZE TASK_SIZE_OF(current)
99#define TASK_SIZE_MAX (1UL << 53) 101#define TASK_SIZE_MAX (-PAGE_SIZE)
100 102
101#define STACK_TOP (test_thread_flag(TIF_31BIT) ? \ 103#define STACK_TOP (test_thread_flag(TIF_31BIT) ? \
102 (1UL << 31) : (1UL << 42)) 104 (1UL << 31) : (1UL << 42))
diff --git a/arch/s390/include/asm/ptrace.h b/arch/s390/include/asm/ptrace.h
index 99bc456cc26a..853b01245c20 100644
--- a/arch/s390/include/asm/ptrace.h
+++ b/arch/s390/include/asm/ptrace.h
@@ -11,9 +11,11 @@
11 11
12#define PIF_SYSCALL 0 /* inside a system call */ 12#define PIF_SYSCALL 0 /* inside a system call */
13#define PIF_PER_TRAP 1 /* deliver sigtrap on return to user */ 13#define PIF_PER_TRAP 1 /* deliver sigtrap on return to user */
14#define PIF_SYSCALL_RESTART 2 /* restart the current system call */
14 15
15#define _PIF_SYSCALL _BITUL(PIF_SYSCALL) 16#define _PIF_SYSCALL _BITUL(PIF_SYSCALL)
16#define _PIF_PER_TRAP _BITUL(PIF_PER_TRAP) 17#define _PIF_PER_TRAP _BITUL(PIF_PER_TRAP)
18#define _PIF_SYSCALL_RESTART _BITUL(PIF_SYSCALL_RESTART)
17 19
18#ifndef __ASSEMBLY__ 20#ifndef __ASSEMBLY__
19 21
@@ -24,38 +26,38 @@
24 PSW_MASK_PSTATE | PSW_ASC_PRIMARY) 26 PSW_MASK_PSTATE | PSW_ASC_PRIMARY)
25 27
26struct psw_bits { 28struct psw_bits {
27 unsigned long : 1; 29 unsigned long : 1;
28 unsigned long r : 1; /* PER-Mask */ 30 unsigned long per : 1; /* PER-Mask */
29 unsigned long : 3; 31 unsigned long : 3;
30 unsigned long t : 1; /* DAT Mode */ 32 unsigned long dat : 1; /* DAT Mode */
31 unsigned long i : 1; /* Input/Output Mask */ 33 unsigned long io : 1; /* Input/Output Mask */
32 unsigned long e : 1; /* External Mask */ 34 unsigned long ext : 1; /* External Mask */
33 unsigned long key : 4; /* PSW Key */ 35 unsigned long key : 4; /* PSW Key */
34 unsigned long : 1; 36 unsigned long : 1;
35 unsigned long m : 1; /* Machine-Check Mask */ 37 unsigned long mcheck : 1; /* Machine-Check Mask */
36 unsigned long w : 1; /* Wait State */ 38 unsigned long wait : 1; /* Wait State */
37 unsigned long p : 1; /* Problem State */ 39 unsigned long pstate : 1; /* Problem State */
38 unsigned long as : 2; /* Address Space Control */ 40 unsigned long as : 2; /* Address Space Control */
39 unsigned long cc : 2; /* Condition Code */ 41 unsigned long cc : 2; /* Condition Code */
40 unsigned long pm : 4; /* Program Mask */ 42 unsigned long pm : 4; /* Program Mask */
41 unsigned long ri : 1; /* Runtime Instrumentation */ 43 unsigned long ri : 1; /* Runtime Instrumentation */
42 unsigned long : 6; 44 unsigned long : 6;
43 unsigned long eaba : 2; /* Addressing Mode */ 45 unsigned long eaba : 2; /* Addressing Mode */
44 unsigned long : 31; 46 unsigned long : 31;
45 unsigned long ia : 64; /* Instruction Address */ 47 unsigned long ia : 64; /* Instruction Address */
46}; 48};
47 49
48enum { 50enum {
49 PSW_AMODE_24BIT = 0, 51 PSW_BITS_AMODE_24BIT = 0,
50 PSW_AMODE_31BIT = 1, 52 PSW_BITS_AMODE_31BIT = 1,
51 PSW_AMODE_64BIT = 3 53 PSW_BITS_AMODE_64BIT = 3
52}; 54};
53 55
54enum { 56enum {
55 PSW_AS_PRIMARY = 0, 57 PSW_BITS_AS_PRIMARY = 0,
56 PSW_AS_ACCREG = 1, 58 PSW_BITS_AS_ACCREG = 1,
57 PSW_AS_SECONDARY = 2, 59 PSW_BITS_AS_SECONDARY = 2,
58 PSW_AS_HOME = 3 60 PSW_BITS_AS_HOME = 3
59}; 61};
60 62
61#define psw_bits(__psw) (*({ \ 63#define psw_bits(__psw) (*({ \
diff --git a/arch/s390/include/asm/sigp.h b/arch/s390/include/asm/sigp.h
index 72df5f2de6b0..020a8814d511 100644
--- a/arch/s390/include/asm/sigp.h
+++ b/arch/s390/include/asm/sigp.h
@@ -59,7 +59,7 @@ static inline int __pcpu_sigp(u16 addr, u8 order, unsigned long parm,
59 int cc; 59 int cc;
60 60
61 cc = ____pcpu_sigp(addr, order, parm, &_status); 61 cc = ____pcpu_sigp(addr, order, parm, &_status);
62 if (status && cc == 1) 62 if (status && cc == SIGP_CC_STATUS_STORED)
63 *status = _status; 63 *status = _status;
64 return cc; 64 return cc;
65} 65}
diff --git a/arch/s390/include/asm/thread_info.h b/arch/s390/include/asm/thread_info.h
index 0b3ee083a665..1aecf432c48d 100644
--- a/arch/s390/include/asm/thread_info.h
+++ b/arch/s390/include/asm/thread_info.h
@@ -58,6 +58,7 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
58#define TIF_UPROBE 3 /* breakpointed or single-stepping */ 58#define TIF_UPROBE 3 /* breakpointed or single-stepping */
59#define TIF_GUARDED_STORAGE 4 /* load guarded storage control block */ 59#define TIF_GUARDED_STORAGE 4 /* load guarded storage control block */
60#define TIF_PATCH_PENDING 5 /* pending live patching update */ 60#define TIF_PATCH_PENDING 5 /* pending live patching update */
61#define TIF_PGSTE 6 /* New mm's will use 4K page tables */
61 62
62#define TIF_31BIT 16 /* 32bit process */ 63#define TIF_31BIT 16 /* 32bit process */
63#define TIF_MEMDIE 17 /* is terminating due to OOM killer */ 64#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h
index 853b2a3d8dee..7317b3108a88 100644
--- a/arch/s390/include/asm/tlb.h
+++ b/arch/s390/include/asm/tlb.h
@@ -137,6 +137,21 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
137} 137}
138 138
139/* 139/*
140 * p4d_free_tlb frees a pud table and clears the CRSTE for the
141 * region second table entry from the tlb.
142 * If the mm uses a four level page table the single p4d is freed
143 * as the pgd. p4d_free_tlb checks the asce_limit against 8PB
144 * to avoid the double free of the p4d in this case.
145 */
146static inline void p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
147 unsigned long address)
148{
149 if (tlb->mm->context.asce_limit <= (1UL << 53))
150 return;
151 tlb_remove_table(tlb, p4d);
152}
153
154/*
140 * pud_free_tlb frees a pud table and clears the CRSTE for the 155 * pud_free_tlb frees a pud table and clears the CRSTE for the
141 * region third table entry from the tlb. 156 * region third table entry from the tlb.
142 * If the mm uses a three level page table the single pud is freed 157 * If the mm uses a three level page table the single pud is freed
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index 6bb29633e1f1..b65c414b6c0e 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -58,6 +58,9 @@ int main(void)
58 OFFSET(__SF_BACKCHAIN, stack_frame, back_chain); 58 OFFSET(__SF_BACKCHAIN, stack_frame, back_chain);
59 OFFSET(__SF_GPRS, stack_frame, gprs); 59 OFFSET(__SF_GPRS, stack_frame, gprs);
60 OFFSET(__SF_EMPTY, stack_frame, empty1); 60 OFFSET(__SF_EMPTY, stack_frame, empty1);
61 OFFSET(__SF_SIE_CONTROL, stack_frame, empty1[0]);
62 OFFSET(__SF_SIE_SAVEAREA, stack_frame, empty1[1]);
63 OFFSET(__SF_SIE_REASON, stack_frame, empty1[2]);
61 BLANK(); 64 BLANK();
62 /* timeval/timezone offsets for use by vdso */ 65 /* timeval/timezone offsets for use by vdso */
63 OFFSET(__VDSO_UPD_COUNT, vdso_data, tb_update_count); 66 OFFSET(__VDSO_UPD_COUNT, vdso_data, tb_update_count);
diff --git a/arch/s390/kernel/dumpstack.c b/arch/s390/kernel/dumpstack.c
index 829e1c53005c..dab78babfab6 100644
--- a/arch/s390/kernel/dumpstack.c
+++ b/arch/s390/kernel/dumpstack.c
@@ -98,8 +98,10 @@ static int show_address(void *data, unsigned long address, int reliable)
98 return 0; 98 return 0;
99} 99}
100 100
101static void show_trace(struct task_struct *task, unsigned long sp) 101void show_stack(struct task_struct *task, unsigned long *stack)
102{ 102{
103 unsigned long sp = (unsigned long) stack;
104
103 if (!sp) 105 if (!sp)
104 sp = task ? task->thread.ksp : current_stack_pointer(); 106 sp = task ? task->thread.ksp : current_stack_pointer();
105 printk("Call Trace:\n"); 107 printk("Call Trace:\n");
@@ -109,29 +111,6 @@ static void show_trace(struct task_struct *task, unsigned long sp)
109 debug_show_held_locks(task); 111 debug_show_held_locks(task);
110} 112}
111 113
112void show_stack(struct task_struct *task, unsigned long *sp)
113{
114 unsigned long *stack;
115 int i;
116
117 stack = sp;
118 if (!stack) {
119 if (!task)
120 stack = (unsigned long *)current_stack_pointer();
121 else
122 stack = (unsigned long *)task->thread.ksp;
123 }
124 printk(KERN_DEFAULT "Stack:\n");
125 for (i = 0; i < 20; i++) {
126 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
127 break;
128 if (i % 4 == 0)
129 printk(KERN_DEFAULT " ");
130 pr_cont("%016lx%c", *stack++, i % 4 == 3 ? '\n' : ' ');
131 }
132 show_trace(task, (unsigned long)sp);
133}
134
135static void show_last_breaking_event(struct pt_regs *regs) 114static void show_last_breaking_event(struct pt_regs *regs)
136{ 115{
137 printk("Last Breaking-Event-Address:\n"); 116 printk("Last Breaking-Event-Address:\n");
@@ -149,8 +128,8 @@ void show_registers(struct pt_regs *regs)
149 pr_cont(" (%pSR)", (void *)regs->psw.addr); 128 pr_cont(" (%pSR)", (void *)regs->psw.addr);
150 pr_cont("\n"); 129 pr_cont("\n");
151 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x " 130 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
152 "P:%x AS:%x CC:%x PM:%x", psw->r, psw->t, psw->i, psw->e, 131 "P:%x AS:%x CC:%x PM:%x", psw->per, psw->dat, psw->io, psw->ext,
153 psw->key, psw->m, psw->w, psw->p, psw->as, psw->cc, psw->pm); 132 psw->key, psw->mcheck, psw->wait, psw->pstate, psw->as, psw->cc, psw->pm);
154 pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba); 133 pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba);
155 printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode, 134 printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
156 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]); 135 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
@@ -169,7 +148,7 @@ void show_regs(struct pt_regs *regs)
169 show_registers(regs); 148 show_registers(regs);
170 /* Show stack backtrace if pt_regs is from kernel mode */ 149 /* Show stack backtrace if pt_regs is from kernel mode */
171 if (!user_mode(regs)) 150 if (!user_mode(regs))
172 show_trace(NULL, regs->gprs[15]); 151 show_stack(NULL, (unsigned long *) regs->gprs[15]);
173 show_last_breaking_event(regs); 152 show_last_breaking_event(regs);
174} 153}
175 154
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 6315037335ba..21900e1cee9c 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -52,7 +52,7 @@ _TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
52 _TIF_SYSCALL_TRACEPOINT) 52 _TIF_SYSCALL_TRACEPOINT)
53_CIF_WORK = (_CIF_MCCK_PENDING | _CIF_ASCE_PRIMARY | \ 53_CIF_WORK = (_CIF_MCCK_PENDING | _CIF_ASCE_PRIMARY | \
54 _CIF_ASCE_SECONDARY | _CIF_FPU) 54 _CIF_ASCE_SECONDARY | _CIF_FPU)
55_PIF_WORK = (_PIF_PER_TRAP) 55_PIF_WORK = (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
56 56
57#define BASED(name) name-cleanup_critical(%r13) 57#define BASED(name) name-cleanup_critical(%r13)
58 58
@@ -225,6 +225,7 @@ ENTRY(sie64a)
225 jnz .Lsie_skip 225 jnz .Lsie_skip
226 TSTMSK __LC_CPU_FLAGS,_CIF_FPU 226 TSTMSK __LC_CPU_FLAGS,_CIF_FPU
227 jo .Lsie_skip # exit if fp/vx regs changed 227 jo .Lsie_skip # exit if fp/vx regs changed
228.Lsie_entry:
228 sie 0(%r14) 229 sie 0(%r14)
229.Lsie_skip: 230.Lsie_skip:
230 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE 231 ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE
@@ -334,6 +335,8 @@ ENTRY(system_call)
334 jo .Lsysc_mcck_pending 335 jo .Lsysc_mcck_pending
335 TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED 336 TSTMSK __TI_flags(%r12),_TIF_NEED_RESCHED
336 jo .Lsysc_reschedule 337 jo .Lsysc_reschedule
338 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
339 jo .Lsysc_syscall_restart
337#ifdef CONFIG_UPROBES 340#ifdef CONFIG_UPROBES
338 TSTMSK __TI_flags(%r12),_TIF_UPROBE 341 TSTMSK __TI_flags(%r12),_TIF_UPROBE
339 jo .Lsysc_uprobe_notify 342 jo .Lsysc_uprobe_notify
@@ -347,6 +350,8 @@ ENTRY(system_call)
347 jo .Lsysc_patch_pending # handle live patching just before 350 jo .Lsysc_patch_pending # handle live patching just before
348 # signals and possible syscall restart 351 # signals and possible syscall restart
349#endif 352#endif
353 TSTMSK __PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
354 jo .Lsysc_syscall_restart
350 TSTMSK __TI_flags(%r12),_TIF_SIGPENDING 355 TSTMSK __TI_flags(%r12),_TIF_SIGPENDING
351 jo .Lsysc_sigpending 356 jo .Lsysc_sigpending
352 TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME 357 TSTMSK __TI_flags(%r12),_TIF_NOTIFY_RESUME
@@ -448,6 +453,15 @@ ENTRY(system_call)
448 jg do_per_trap 453 jg do_per_trap
449 454
450# 455#
456# _PIF_SYSCALL_RESTART is set, repeat the current system call
457#
458.Lsysc_syscall_restart:
459 ni __PT_FLAGS+7(%r11),255-_PIF_SYSCALL_RESTART
460 lmg %r1,%r7,__PT_R1(%r11) # load svc arguments
461 lg %r2,__PT_ORIG_GPR2(%r11)
462 j .Lsysc_do_svc
463
464#
451# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before 465# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
452# and after the system call 466# and after the system call
453# 467#
@@ -881,9 +895,7 @@ ENTRY(save_fpu_regs)
881 oi __LC_CPU_FLAGS+7,_CIF_FPU 895 oi __LC_CPU_FLAGS+7,_CIF_FPU
882 br %r14 896 br %r14
883.Lsave_fpu_regs_end: 897.Lsave_fpu_regs_end:
884#if IS_ENABLED(CONFIG_KVM)
885EXPORT_SYMBOL(save_fpu_regs) 898EXPORT_SYMBOL(save_fpu_regs)
886#endif
887 899
888/* 900/*
889 * Load floating-point controls and floating-point or vector registers. 901 * Load floating-point controls and floating-point or vector registers.
@@ -1111,7 +1123,13 @@ cleanup_critical:
1111 .quad .Lsie_done 1123 .quad .Lsie_done
1112 1124
1113.Lcleanup_sie: 1125.Lcleanup_sie:
1114 lg %r9,__SF_EMPTY(%r15) # get control block pointer 1126 cghi %r11,__LC_SAVE_AREA_ASYNC #Is this in normal interrupt?
1127 je 1f
1128 slg %r9,BASED(.Lsie_crit_mcck_start)
1129 clg %r9,BASED(.Lsie_crit_mcck_length)
1130 jh 1f
1131 oi __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
11321: lg %r9,__SF_EMPTY(%r15) # get control block pointer
1115 ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE 1133 ni __SIE_PROG0C+3(%r9),0xfe # no longer in SIE
1116 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce 1134 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
1117 larl %r9,sie_exit # skip forward to sie_exit 1135 larl %r9,sie_exit # skip forward to sie_exit
@@ -1296,6 +1314,10 @@ cleanup_critical:
1296 .quad .Lsie_gmap 1314 .quad .Lsie_gmap
1297.Lsie_critical_length: 1315.Lsie_critical_length:
1298 .quad .Lsie_done - .Lsie_gmap 1316 .quad .Lsie_done - .Lsie_gmap
1317.Lsie_crit_mcck_start:
1318 .quad .Lsie_entry
1319.Lsie_crit_mcck_length:
1320 .quad .Lsie_skip - .Lsie_entry
1299#endif 1321#endif
1300 1322
1301 .section .rodata, "a" 1323 .section .rodata, "a"
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index 985589523970..31d03a84126c 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -25,6 +25,8 @@
25#include <asm/crw.h> 25#include <asm/crw.h>
26#include <asm/switch_to.h> 26#include <asm/switch_to.h>
27#include <asm/ctl_reg.h> 27#include <asm/ctl_reg.h>
28#include <asm/asm-offsets.h>
29#include <linux/kvm_host.h>
28 30
29struct mcck_struct { 31struct mcck_struct {
30 unsigned int kill_task : 1; 32 unsigned int kill_task : 1;
@@ -274,12 +276,39 @@ static int notrace s390_validate_registers(union mci mci, int umode)
274 return kill_task; 276 return kill_task;
275} 277}
276 278
279/*
280 * Backup the guest's machine check info to its description block
281 */
282static void notrace s390_backup_mcck_info(struct pt_regs *regs)
283{
284 struct mcck_volatile_info *mcck_backup;
285 struct sie_page *sie_page;
286
287 /* r14 contains the sie block, which was set in sie64a */
288 struct kvm_s390_sie_block *sie_block =
289 (struct kvm_s390_sie_block *) regs->gprs[14];
290
291 if (sie_block == NULL)
292 /* Something's seriously wrong, stop system. */
293 s390_handle_damage();
294
295 sie_page = container_of(sie_block, struct sie_page, sie_block);
296 mcck_backup = &sie_page->mcck_info;
297 mcck_backup->mcic = S390_lowcore.mcck_interruption_code &
298 ~(MCCK_CODE_CP | MCCK_CODE_EXT_DAMAGE);
299 mcck_backup->ext_damage_code = S390_lowcore.external_damage_code;
300 mcck_backup->failing_storage_address
301 = S390_lowcore.failing_storage_address;
302}
303
277#define MAX_IPD_COUNT 29 304#define MAX_IPD_COUNT 29
278#define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */ 305#define MAX_IPD_TIME (5 * 60 * USEC_PER_SEC) /* 5 minutes */
279 306
280#define ED_STP_ISLAND 6 /* External damage STP island check */ 307#define ED_STP_ISLAND 6 /* External damage STP island check */
281#define ED_STP_SYNC 7 /* External damage STP sync check */ 308#define ED_STP_SYNC 7 /* External damage STP sync check */
282 309
310#define MCCK_CODE_NO_GUEST (MCCK_CODE_CP | MCCK_CODE_EXT_DAMAGE)
311
283/* 312/*
284 * machine check handler. 313 * machine check handler.
285 */ 314 */
@@ -291,6 +320,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
291 struct mcck_struct *mcck; 320 struct mcck_struct *mcck;
292 unsigned long long tmp; 321 unsigned long long tmp;
293 union mci mci; 322 union mci mci;
323 unsigned long mcck_dam_code;
294 324
295 nmi_enter(); 325 nmi_enter();
296 inc_irq_stat(NMI_NMI); 326 inc_irq_stat(NMI_NMI);
@@ -301,7 +331,13 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
301 /* System damage -> stopping machine */ 331 /* System damage -> stopping machine */
302 s390_handle_damage(); 332 s390_handle_damage();
303 } 333 }
304 if (mci.pd) { 334
335 /*
336 * Reinject the instruction processing damages' machine checks
337 * including Delayed Access Exception into the guest
338 * instead of damaging the host if they happen in the guest.
339 */
340 if (mci.pd && !test_cpu_flag(CIF_MCCK_GUEST)) {
305 if (mci.b) { 341 if (mci.b) {
306 /* Processing backup -> verify if we can survive this */ 342 /* Processing backup -> verify if we can survive this */
307 u64 z_mcic, o_mcic, t_mcic; 343 u64 z_mcic, o_mcic, t_mcic;
@@ -345,6 +381,14 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
345 mcck->mcck_code = mci.val; 381 mcck->mcck_code = mci.val;
346 set_cpu_flag(CIF_MCCK_PENDING); 382 set_cpu_flag(CIF_MCCK_PENDING);
347 } 383 }
384
385 /*
386 * Backup the machine check's info if it happens when the guest
387 * is running.
388 */
389 if (test_cpu_flag(CIF_MCCK_GUEST))
390 s390_backup_mcck_info(regs);
391
348 if (mci.cd) { 392 if (mci.cd) {
349 /* Timing facility damage */ 393 /* Timing facility damage */
350 s390_handle_damage(); 394 s390_handle_damage();
@@ -358,15 +402,22 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
358 if (mcck->stp_queue) 402 if (mcck->stp_queue)
359 set_cpu_flag(CIF_MCCK_PENDING); 403 set_cpu_flag(CIF_MCCK_PENDING);
360 } 404 }
361 if (mci.se) 405
362 /* Storage error uncorrected */ 406 /*
363 s390_handle_damage(); 407 * Reinject storage related machine checks into the guest if they
364 if (mci.ke) 408 * happen when the guest is running.
365 /* Storage key-error uncorrected */ 409 */
366 s390_handle_damage(); 410 if (!test_cpu_flag(CIF_MCCK_GUEST)) {
367 if (mci.ds && mci.fa) 411 if (mci.se)
368 /* Storage degradation */ 412 /* Storage error uncorrected */
369 s390_handle_damage(); 413 s390_handle_damage();
414 if (mci.ke)
415 /* Storage key-error uncorrected */
416 s390_handle_damage();
417 if (mci.ds && mci.fa)
418 /* Storage degradation */
419 s390_handle_damage();
420 }
370 if (mci.cp) { 421 if (mci.cp) {
371 /* Channel report word pending */ 422 /* Channel report word pending */
372 mcck->channel_report = 1; 423 mcck->channel_report = 1;
@@ -377,6 +428,19 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
377 mcck->warning = 1; 428 mcck->warning = 1;
378 set_cpu_flag(CIF_MCCK_PENDING); 429 set_cpu_flag(CIF_MCCK_PENDING);
379 } 430 }
431
432 /*
433 * If there are only Channel Report Pending and External Damage
434 * machine checks, they will not be reinjected into the guest
435 * because they refer to host conditions only.
436 */
437 mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);
438 if (test_cpu_flag(CIF_MCCK_GUEST) &&
439 (mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) {
440 /* Set exit reason code for host's later handling */
441 *((long *)(regs->gprs[15] + __SF_SIE_REASON)) = -EINTR;
442 }
443 clear_cpu_flag(CIF_MCCK_GUEST);
380 nmi_exit(); 444 nmi_exit();
381} 445}
382 446
diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c
index ca960d0370d5..0c82f7903fc7 100644
--- a/arch/s390/kernel/perf_cpum_sf.c
+++ b/arch/s390/kernel/perf_cpum_sf.c
@@ -995,11 +995,11 @@ static int perf_push_sample(struct perf_event *event, struct sf_raw_sample *sfr)
995 regs.int_parm = CPU_MF_INT_SF_PRA; 995 regs.int_parm = CPU_MF_INT_SF_PRA;
996 sde_regs = (struct perf_sf_sde_regs *) &regs.int_parm_long; 996 sde_regs = (struct perf_sf_sde_regs *) &regs.int_parm_long;
997 997
998 psw_bits(regs.psw).ia = sfr->basic.ia; 998 psw_bits(regs.psw).ia = sfr->basic.ia;
999 psw_bits(regs.psw).t = sfr->basic.T; 999 psw_bits(regs.psw).dat = sfr->basic.T;
1000 psw_bits(regs.psw).w = sfr->basic.W; 1000 psw_bits(regs.psw).wait = sfr->basic.W;
1001 psw_bits(regs.psw).p = sfr->basic.P; 1001 psw_bits(regs.psw).per = sfr->basic.P;
1002 psw_bits(regs.psw).as = sfr->basic.AS; 1002 psw_bits(regs.psw).as = sfr->basic.AS;
1003 1003
1004 /* 1004 /*
1005 * Use the hardware provided configuration level to decide if the 1005 * Use the hardware provided configuration level to decide if the
diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
index 955a7b6fa0a4..93a386f4a3b5 100644
--- a/arch/s390/kernel/perf_event.c
+++ b/arch/s390/kernel/perf_event.c
@@ -245,6 +245,5 @@ ssize_t cpumf_events_sysfs_show(struct device *dev,
245 struct perf_pmu_events_attr *pmu_attr; 245 struct perf_pmu_events_attr *pmu_attr;
246 246
247 pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr); 247 pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
248 return sprintf(page, "event=0x%04llx,name=%s\n", 248 return sprintf(page, "event=0x%04llx\n", pmu_attr->id);
249 pmu_attr->id, attr->attr.name);
250} 249}
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index 488c5bb8dc77..252ed61a128b 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -1160,6 +1160,8 @@ static int s390_gs_cb_get(struct task_struct *target,
1160 return -ENODEV; 1160 return -ENODEV;
1161 if (!data) 1161 if (!data)
1162 return -ENODATA; 1162 return -ENODATA;
1163 if (target == current)
1164 save_gs_cb(data);
1163 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, 1165 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1164 data, 0, sizeof(struct gs_cb)); 1166 data, 0, sizeof(struct gs_cb));
1165} 1167}
@@ -1170,6 +1172,7 @@ static int s390_gs_cb_set(struct task_struct *target,
1170 const void *kbuf, const void __user *ubuf) 1172 const void *kbuf, const void __user *ubuf)
1171{ 1173{
1172 struct gs_cb *data = target->thread.gs_cb; 1174 struct gs_cb *data = target->thread.gs_cb;
1175 int rc;
1173 1176
1174 if (!MACHINE_HAS_GS) 1177 if (!MACHINE_HAS_GS)
1175 return -ENODEV; 1178 return -ENODEV;
@@ -1177,10 +1180,18 @@ static int s390_gs_cb_set(struct task_struct *target,
1177 data = kzalloc(sizeof(*data), GFP_KERNEL); 1180 data = kzalloc(sizeof(*data), GFP_KERNEL);
1178 if (!data) 1181 if (!data)
1179 return -ENOMEM; 1182 return -ENOMEM;
1183 data->gsd = 25;
1180 target->thread.gs_cb = data; 1184 target->thread.gs_cb = data;
1185 if (target == current)
1186 __ctl_set_bit(2, 4);
1187 } else if (target == current) {
1188 save_gs_cb(data);
1181 } 1189 }
1182 return user_regset_copyin(&pos, &count, &kbuf, &ubuf, 1190 rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1183 data, 0, sizeof(struct gs_cb)); 1191 data, 0, sizeof(struct gs_cb));
1192 if (target == current)
1193 restore_gs_cb(data);
1194 return rc;
1184} 1195}
1185 1196
1186static int s390_gs_bc_get(struct task_struct *target, 1197static int s390_gs_bc_get(struct task_struct *target,
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index 363000a77ffc..1020a11a24e5 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/kernel_stat.h> 28#include <linux/kernel_stat.h>
29#include <linux/kmemleak.h>
29#include <linux/delay.h> 30#include <linux/delay.h>
30#include <linux/interrupt.h> 31#include <linux/interrupt.h>
31#include <linux/irqflags.h> 32#include <linux/irqflags.h>
@@ -207,6 +208,8 @@ static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
207 kmem_cache_alloc(pcpu_mcesa_cache, GFP_KERNEL); 208 kmem_cache_alloc(pcpu_mcesa_cache, GFP_KERNEL);
208 if (!mcesa_origin) 209 if (!mcesa_origin)
209 goto out; 210 goto out;
211 /* The pointer is stored with mcesa_bits ORed in */
212 kmemleak_not_leak((void *) mcesa_origin);
210 mcesa_bits = MACHINE_HAS_GS ? 11 : 0; 213 mcesa_bits = MACHINE_HAS_GS ? 11 : 0;
211 } 214 }
212 } else { 215 } else {
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index f787b9d8f54c..442e5423ce3d 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -21,6 +21,7 @@
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24#include <linux/cpu.h>
24#include <asm/fpu/api.h> 25#include <asm/fpu/api.h>
25#include "entry.h" 26#include "entry.h"
26 27
diff --git a/arch/s390/kernel/uprobes.c b/arch/s390/kernel/uprobes.c
index 314e0ee3016a..d94baa8db507 100644
--- a/arch/s390/kernel/uprobes.c
+++ b/arch/s390/kernel/uprobes.c
@@ -27,12 +27,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
27 27
28int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs) 28int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
29{ 29{
30 if (psw_bits(regs->psw).eaba == PSW_AMODE_24BIT) 30 if (psw_bits(regs->psw).eaba == PSW_BITS_AMODE_24BIT)
31 return -EINVAL; 31 return -EINVAL;
32 if (!is_compat_task() && psw_bits(regs->psw).eaba == PSW_AMODE_31BIT) 32 if (!is_compat_task() && psw_bits(regs->psw).eaba == PSW_BITS_AMODE_31BIT)
33 return -EINVAL; 33 return -EINVAL;
34 clear_pt_regs_flag(regs, PIF_PER_TRAP); 34 clear_pt_regs_flag(regs, PIF_PER_TRAP);
35 auprobe->saved_per = psw_bits(regs->psw).r; 35 auprobe->saved_per = psw_bits(regs->psw).per;
36 auprobe->saved_int_code = regs->int_code; 36 auprobe->saved_int_code = regs->int_code;
37 regs->int_code = UPROBE_TRAP_NR; 37 regs->int_code = UPROBE_TRAP_NR;
38 regs->psw.addr = current->utask->xol_vaddr; 38 regs->psw.addr = current->utask->xol_vaddr;
@@ -81,7 +81,7 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
81 81
82 clear_tsk_thread_flag(current, TIF_UPROBE_SINGLESTEP); 82 clear_tsk_thread_flag(current, TIF_UPROBE_SINGLESTEP);
83 update_cr_regs(current); 83 update_cr_regs(current);
84 psw_bits(regs->psw).r = auprobe->saved_per; 84 psw_bits(regs->psw).per = auprobe->saved_per;
85 regs->int_code = auprobe->saved_int_code; 85 regs->int_code = auprobe->saved_int_code;
86 86
87 if (fixup & FIXUP_PSW_NORMAL) 87 if (fixup & FIXUP_PSW_NORMAL)
@@ -372,8 +372,8 @@ static void handle_insn_ril(struct arch_uprobe *auprobe, struct pt_regs *regs)
372 372
373bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) 373bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
374{ 374{
375 if ((psw_bits(regs->psw).eaba == PSW_AMODE_24BIT) || 375 if ((psw_bits(regs->psw).eaba == PSW_BITS_AMODE_24BIT) ||
376 ((psw_bits(regs->psw).eaba == PSW_AMODE_31BIT) && 376 ((psw_bits(regs->psw).eaba == PSW_BITS_AMODE_31BIT) &&
377 !is_compat_task())) { 377 !is_compat_task())) {
378 regs->psw.addr = __rewind_psw(regs->psw, UPROBE_SWBP_INSN_SIZE); 378 regs->psw.addr = __rewind_psw(regs->psw, UPROBE_SWBP_INSN_SIZE);
379 do_report_trap(regs, SIGILL, ILL_ILLADR, NULL); 379 do_report_trap(regs, SIGILL, ILL_ILLADR, NULL);
diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index 10516ae3b55e..b89d19f6f2ab 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -50,6 +50,56 @@ static struct page **vdso64_pagelist;
50 */ 50 */
51unsigned int __read_mostly vdso_enabled = 1; 51unsigned int __read_mostly vdso_enabled = 1;
52 52
53static int vdso_fault(const struct vm_special_mapping *sm,
54 struct vm_area_struct *vma, struct vm_fault *vmf)
55{
56 struct page **vdso_pagelist;
57 unsigned long vdso_pages;
58
59 vdso_pagelist = vdso64_pagelist;
60 vdso_pages = vdso64_pages;
61#ifdef CONFIG_COMPAT
62 if (is_compat_task()) {
63 vdso_pagelist = vdso32_pagelist;
64 vdso_pages = vdso32_pages;
65 }
66#endif
67
68 if (vmf->pgoff >= vdso_pages)
69 return VM_FAULT_SIGBUS;
70
71 vmf->page = vdso_pagelist[vmf->pgoff];
72 get_page(vmf->page);
73 return 0;
74}
75
76static int vdso_mremap(const struct vm_special_mapping *sm,
77 struct vm_area_struct *vma)
78{
79 unsigned long vdso_pages;
80
81 vdso_pages = vdso64_pages;
82#ifdef CONFIG_COMPAT
83 if (is_compat_task())
84 vdso_pages = vdso32_pages;
85#endif
86
87 if ((vdso_pages << PAGE_SHIFT) != vma->vm_end - vma->vm_start)
88 return -EINVAL;
89
90 if (WARN_ON_ONCE(current->mm != vma->vm_mm))
91 return -EFAULT;
92
93 current->mm->context.vdso_base = vma->vm_start;
94 return 0;
95}
96
97static const struct vm_special_mapping vdso_mapping = {
98 .name = "[vdso]",
99 .fault = vdso_fault,
100 .mremap = vdso_mremap,
101};
102
53static int __init vdso_setup(char *s) 103static int __init vdso_setup(char *s)
54{ 104{
55 unsigned long val; 105 unsigned long val;
@@ -181,7 +231,7 @@ static void vdso_init_cr5(void)
181int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) 231int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
182{ 232{
183 struct mm_struct *mm = current->mm; 233 struct mm_struct *mm = current->mm;
184 struct page **vdso_pagelist; 234 struct vm_area_struct *vma;
185 unsigned long vdso_pages; 235 unsigned long vdso_pages;
186 unsigned long vdso_base; 236 unsigned long vdso_base;
187 int rc; 237 int rc;
@@ -194,13 +244,10 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
194 if (!uses_interp) 244 if (!uses_interp)
195 return 0; 245 return 0;
196 246
197 vdso_pagelist = vdso64_pagelist;
198 vdso_pages = vdso64_pages; 247 vdso_pages = vdso64_pages;
199#ifdef CONFIG_COMPAT 248#ifdef CONFIG_COMPAT
200 if (is_compat_task()) { 249 if (is_compat_task())
201 vdso_pagelist = vdso32_pagelist;
202 vdso_pages = vdso32_pages; 250 vdso_pages = vdso32_pages;
203 }
204#endif 251#endif
205 /* 252 /*
206 * vDSO has a problem and was disabled, just don't "enable" it for 253 * vDSO has a problem and was disabled, just don't "enable" it for
@@ -209,8 +256,6 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
209 if (vdso_pages == 0) 256 if (vdso_pages == 0)
210 return 0; 257 return 0;
211 258
212 current->mm->context.vdso_base = 0;
213
214 /* 259 /*
215 * pick a base address for the vDSO in process space. We try to put 260 * pick a base address for the vDSO in process space. We try to put
216 * it at vdso_base which is the "natural" base for it, but we might 261 * it at vdso_base which is the "natural" base for it, but we might
@@ -225,13 +270,6 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
225 } 270 }
226 271
227 /* 272 /*
228 * Put vDSO base into mm struct. We need to do this before calling
229 * install_special_mapping or the perf counter mmap tracking code
230 * will fail to recognise it as a vDSO (since arch_vma_name fails).
231 */
232 current->mm->context.vdso_base = vdso_base;
233
234 /*
235 * our vma flags don't have VM_WRITE so by default, the process 273 * our vma flags don't have VM_WRITE so by default, the process
236 * isn't allowed to write those pages. 274 * isn't allowed to write those pages.
237 * gdb can break that with ptrace interface, and thus trigger COW 275 * gdb can break that with ptrace interface, and thus trigger COW
@@ -241,24 +279,23 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
241 * It's fine to use that for setting breakpoints in the vDSO code 279 * It's fine to use that for setting breakpoints in the vDSO code
242 * pages though. 280 * pages though.
243 */ 281 */
244 rc = install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT, 282 vma = _install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
245 VM_READ|VM_EXEC| 283 VM_READ|VM_EXEC|
246 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, 284 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
247 vdso_pagelist); 285 &vdso_mapping);
248 if (rc) 286 if (IS_ERR(vma)) {
249 current->mm->context.vdso_base = 0; 287 rc = PTR_ERR(vma);
288 goto out_up;
289 }
290
291 current->mm->context.vdso_base = vdso_base;
292 rc = 0;
293
250out_up: 294out_up:
251 up_write(&mm->mmap_sem); 295 up_write(&mm->mmap_sem);
252 return rc; 296 return rc;
253} 297}
254 298
255const char *arch_vma_name(struct vm_area_struct *vma)
256{
257 if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso_base)
258 return "[vdso]";
259 return NULL;
260}
261
262static int __init vdso_init(void) 299static int __init vdso_init(void)
263{ 300{
264 int i; 301 int i;
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 072d84ba42a3..dd7178fbb4f3 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -110,11 +110,10 @@ static inline u64 scale_vtime(u64 vtime)
110 return vtime; 110 return vtime;
111} 111}
112 112
113static void account_system_index_scaled(struct task_struct *p, 113static void account_system_index_scaled(struct task_struct *p, u64 cputime,
114 u64 cputime, u64 scaled,
115 enum cpu_usage_stat index) 114 enum cpu_usage_stat index)
116{ 115{
117 p->stimescaled += cputime_to_nsecs(scaled); 116 p->stimescaled += cputime_to_nsecs(scale_vtime(cputime));
118 account_system_index_time(p, cputime_to_nsecs(cputime), index); 117 account_system_index_time(p, cputime_to_nsecs(cputime), index);
119} 118}
120 119
@@ -176,14 +175,11 @@ static int do_account_vtime(struct task_struct *tsk)
176 } 175 }
177 176
178 if (system) 177 if (system)
179 account_system_index_scaled(tsk, system, scale_vtime(system), 178 account_system_index_scaled(tsk, system, CPUTIME_SYSTEM);
180 CPUTIME_SYSTEM);
181 if (hardirq) 179 if (hardirq)
182 account_system_index_scaled(tsk, hardirq, scale_vtime(hardirq), 180 account_system_index_scaled(tsk, hardirq, CPUTIME_IRQ);
183 CPUTIME_IRQ);
184 if (softirq) 181 if (softirq)
185 account_system_index_scaled(tsk, softirq, scale_vtime(softirq), 182 account_system_index_scaled(tsk, softirq, CPUTIME_SOFTIRQ);
186 CPUTIME_SOFTIRQ);
187 183
188 steal = S390_lowcore.steal_timer; 184 steal = S390_lowcore.steal_timer;
189 if ((s64) steal > 0) { 185 if ((s64) steal > 0) {
diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
index 3b297fa3aa67..875f8bea8c67 100644
--- a/arch/s390/kvm/gaccess.c
+++ b/arch/s390/kvm/gaccess.c
@@ -551,26 +551,26 @@ static int get_vcpu_asce(struct kvm_vcpu *vcpu, union asce *asce,
551 int rc; 551 int rc;
552 struct psw_bits psw = psw_bits(vcpu->arch.sie_block->gpsw); 552 struct psw_bits psw = psw_bits(vcpu->arch.sie_block->gpsw);
553 553
554 if (!psw.t) { 554 if (!psw.dat) {
555 asce->val = 0; 555 asce->val = 0;
556 asce->r = 1; 556 asce->r = 1;
557 return 0; 557 return 0;
558 } 558 }
559 559
560 if (mode == GACC_IFETCH) 560 if ((mode == GACC_IFETCH) && (psw.as != PSW_BITS_AS_HOME))
561 psw.as = psw.as == PSW_AS_HOME ? PSW_AS_HOME : PSW_AS_PRIMARY; 561 psw.as = PSW_BITS_AS_PRIMARY;
562 562
563 switch (psw.as) { 563 switch (psw.as) {
564 case PSW_AS_PRIMARY: 564 case PSW_BITS_AS_PRIMARY:
565 asce->val = vcpu->arch.sie_block->gcr[1]; 565 asce->val = vcpu->arch.sie_block->gcr[1];
566 return 0; 566 return 0;
567 case PSW_AS_SECONDARY: 567 case PSW_BITS_AS_SECONDARY:
568 asce->val = vcpu->arch.sie_block->gcr[7]; 568 asce->val = vcpu->arch.sie_block->gcr[7];
569 return 0; 569 return 0;
570 case PSW_AS_HOME: 570 case PSW_BITS_AS_HOME:
571 asce->val = vcpu->arch.sie_block->gcr[13]; 571 asce->val = vcpu->arch.sie_block->gcr[13];
572 return 0; 572 return 0;
573 case PSW_AS_ACCREG: 573 case PSW_BITS_AS_ACCREG:
574 rc = ar_translation(vcpu, asce, ar, mode); 574 rc = ar_translation(vcpu, asce, ar, mode);
575 if (rc > 0) 575 if (rc > 0)
576 return trans_exc(vcpu, rc, ga, ar, mode, PROT_TYPE_ALC); 576 return trans_exc(vcpu, rc, ga, ar, mode, PROT_TYPE_ALC);
@@ -771,7 +771,7 @@ static int low_address_protection_enabled(struct kvm_vcpu *vcpu,
771 771
772 if (!ctlreg0.lap) 772 if (!ctlreg0.lap)
773 return 0; 773 return 0;
774 if (psw_bits(*psw).t && asce.p) 774 if (psw_bits(*psw).dat && asce.p)
775 return 0; 775 return 0;
776 return 1; 776 return 1;
777} 777}
@@ -790,7 +790,7 @@ static int guest_page_range(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
790 return trans_exc(vcpu, PGM_PROTECTION, ga, ar, mode, 790 return trans_exc(vcpu, PGM_PROTECTION, ga, ar, mode,
791 PROT_TYPE_LA); 791 PROT_TYPE_LA);
792 ga &= PAGE_MASK; 792 ga &= PAGE_MASK;
793 if (psw_bits(*psw).t) { 793 if (psw_bits(*psw).dat) {
794 rc = guest_translate(vcpu, ga, pages, asce, mode); 794 rc = guest_translate(vcpu, ga, pages, asce, mode);
795 if (rc < 0) 795 if (rc < 0)
796 return rc; 796 return rc;
@@ -831,7 +831,7 @@ int access_guest(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, void *data,
831 pages = vmalloc(nr_pages * sizeof(unsigned long)); 831 pages = vmalloc(nr_pages * sizeof(unsigned long));
832 if (!pages) 832 if (!pages)
833 return -ENOMEM; 833 return -ENOMEM;
834 need_ipte_lock = psw_bits(*psw).t && !asce.r; 834 need_ipte_lock = psw_bits(*psw).dat && !asce.r;
835 if (need_ipte_lock) 835 if (need_ipte_lock)
836 ipte_lock(vcpu); 836 ipte_lock(vcpu);
837 rc = guest_page_range(vcpu, ga, ar, pages, nr_pages, asce, mode); 837 rc = guest_page_range(vcpu, ga, ar, pages, nr_pages, asce, mode);
@@ -899,7 +899,7 @@ int guest_translate_address(struct kvm_vcpu *vcpu, unsigned long gva, u8 ar,
899 mode, PROT_TYPE_LA); 899 mode, PROT_TYPE_LA);
900 } 900 }
901 901
902 if (psw_bits(*psw).t && !asce.r) { /* Use DAT? */ 902 if (psw_bits(*psw).dat && !asce.r) { /* Use DAT? */
903 rc = guest_translate(vcpu, gva, gpa, asce, mode); 903 rc = guest_translate(vcpu, gva, gpa, asce, mode);
904 if (rc > 0) 904 if (rc > 0)
905 return trans_exc(vcpu, rc, gva, 0, mode, PROT_TYPE_DAT); 905 return trans_exc(vcpu, rc, gva, 0, mode, PROT_TYPE_DAT);
diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/gaccess.h
index 7ce47fd36f28..bec42b852246 100644
--- a/arch/s390/kvm/gaccess.h
+++ b/arch/s390/kvm/gaccess.h
@@ -57,9 +57,9 @@ static inline unsigned long kvm_s390_logical_to_effective(struct kvm_vcpu *vcpu,
57{ 57{
58 psw_t *psw = &vcpu->arch.sie_block->gpsw; 58 psw_t *psw = &vcpu->arch.sie_block->gpsw;
59 59
60 if (psw_bits(*psw).eaba == PSW_AMODE_64BIT) 60 if (psw_bits(*psw).eaba == PSW_BITS_AMODE_64BIT)
61 return ga; 61 return ga;
62 if (psw_bits(*psw).eaba == PSW_AMODE_31BIT) 62 if (psw_bits(*psw).eaba == PSW_BITS_AMODE_31BIT)
63 return ga & ((1UL << 31) - 1); 63 return ga & ((1UL << 31) - 1);
64 return ga & ((1UL << 24) - 1); 64 return ga & ((1UL << 24) - 1);
65} 65}
diff --git a/arch/s390/kvm/guestdbg.c b/arch/s390/kvm/guestdbg.c
index 23d9a4e12da1..c2e0ddc1356e 100644
--- a/arch/s390/kvm/guestdbg.c
+++ b/arch/s390/kvm/guestdbg.c
@@ -613,15 +613,15 @@ int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu)
613 * instruction. Check primary and home space-switch-event 613 * instruction. Check primary and home space-switch-event
614 * controls. (theoretically home -> home produced no event) 614 * controls. (theoretically home -> home produced no event)
615 */ 615 */
616 if (((new_as == PSW_AS_HOME) ^ old_as_is_home(vcpu)) && 616 if (((new_as == PSW_BITS_AS_HOME) ^ old_as_is_home(vcpu)) &&
617 (pssec(vcpu) || hssec(vcpu))) 617 (pssec(vcpu) || hssec(vcpu)))
618 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH; 618 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH;
619 619
620 /* 620 /*
621 * PT, PTI, PR, PC instruction operate on primary AS only. Check 621 * PT, PTI, PR, PC instruction operate on primary AS only. Check
622 * if the primary-space-switch-event control was or got set. 622 * if the primary-space-switch-event control was or got set.
623 */ 623 */
624 if (new_as == PSW_AS_PRIMARY && !old_as_is_home(vcpu) && 624 if (new_as == PSW_BITS_AS_PRIMARY && !old_as_is_home(vcpu) &&
625 (pssec(vcpu) || old_ssec(vcpu))) 625 (pssec(vcpu) || old_ssec(vcpu)))
626 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH; 626 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH;
627 } 627 }
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index f28e2e776931..b0d7de5a533d 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2067,6 +2067,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
2067 if (!vcpu) 2067 if (!vcpu)
2068 goto out; 2068 goto out;
2069 2069
2070 BUILD_BUG_ON(sizeof(struct sie_page) != 4096);
2070 sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL); 2071 sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL);
2071 if (!sie_page) 2072 if (!sie_page)
2072 goto out_free_cpu; 2073 goto out_free_cpu;
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index c03106c428cf..e53292a89257 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -361,7 +361,7 @@ static int handle_sske(struct kvm_vcpu *vcpu)
361 } 361 }
362 } 362 }
363 if (m3 & SSKE_MB) { 363 if (m3 & SSKE_MB) {
364 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_AMODE_64BIT) 364 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_BITS_AMODE_64BIT)
365 vcpu->run->s.regs.gprs[reg2] &= ~PAGE_MASK; 365 vcpu->run->s.regs.gprs[reg2] &= ~PAGE_MASK;
366 else 366 else
367 vcpu->run->s.regs.gprs[reg2] &= ~0xfffff000UL; 367 vcpu->run->s.regs.gprs[reg2] &= ~0xfffff000UL;
@@ -374,7 +374,7 @@ static int handle_sske(struct kvm_vcpu *vcpu)
374static int handle_ipte_interlock(struct kvm_vcpu *vcpu) 374static int handle_ipte_interlock(struct kvm_vcpu *vcpu)
375{ 375{
376 vcpu->stat.instruction_ipte_interlock++; 376 vcpu->stat.instruction_ipte_interlock++;
377 if (psw_bits(vcpu->arch.sie_block->gpsw).p) 377 if (psw_bits(vcpu->arch.sie_block->gpsw).pstate)
378 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); 378 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
379 wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu)); 379 wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu));
380 kvm_s390_retry_instr(vcpu); 380 kvm_s390_retry_instr(vcpu);
@@ -901,7 +901,7 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
901 /* only support 2G frame size if EDAT2 is available and we are 901 /* only support 2G frame size if EDAT2 is available and we are
902 not in 24-bit addressing mode */ 902 not in 24-bit addressing mode */
903 if (!test_kvm_facility(vcpu->kvm, 78) || 903 if (!test_kvm_facility(vcpu->kvm, 78) ||
904 psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_AMODE_24BIT) 904 psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_BITS_AMODE_24BIT)
905 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 905 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
906 end = (start + (1UL << 31)) & ~((1UL << 31) - 1); 906 end = (start + (1UL << 31)) & ~((1UL << 31) - 1);
907 break; 907 break;
@@ -938,7 +938,7 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
938 start += PAGE_SIZE; 938 start += PAGE_SIZE;
939 } 939 }
940 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { 940 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) {
941 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_AMODE_64BIT) { 941 if (psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_BITS_AMODE_64BIT) {
942 vcpu->run->s.regs.gprs[reg2] = end; 942 vcpu->run->s.regs.gprs[reg2] = end;
943 } else { 943 } else {
944 vcpu->run->s.regs.gprs[reg2] &= ~0xffffffffUL; 944 vcpu->run->s.regs.gprs[reg2] &= ~0xffffffffUL;
diff --git a/arch/s390/mm/dump_pagetables.c b/arch/s390/mm/dump_pagetables.c
index 1b553d847140..049c3c455b32 100644
--- a/arch/s390/mm/dump_pagetables.c
+++ b/arch/s390/mm/dump_pagetables.c
@@ -149,7 +149,7 @@ static void walk_pmd_level(struct seq_file *m, struct pg_state *st,
149} 149}
150 150
151static void walk_pud_level(struct seq_file *m, struct pg_state *st, 151static void walk_pud_level(struct seq_file *m, struct pg_state *st,
152 pgd_t *pgd, unsigned long addr) 152 p4d_t *p4d, unsigned long addr)
153{ 153{
154 unsigned int prot; 154 unsigned int prot;
155 pud_t *pud; 155 pud_t *pud;
@@ -157,7 +157,7 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st,
157 157
158 for (i = 0; i < PTRS_PER_PUD && addr < max_addr; i++) { 158 for (i = 0; i < PTRS_PER_PUD && addr < max_addr; i++) {
159 st->current_address = addr; 159 st->current_address = addr;
160 pud = pud_offset(pgd, addr); 160 pud = pud_offset(p4d, addr);
161 if (!pud_none(*pud)) 161 if (!pud_none(*pud))
162 if (pud_large(*pud)) { 162 if (pud_large(*pud)) {
163 prot = pud_val(*pud) & 163 prot = pud_val(*pud) &
@@ -172,6 +172,23 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st,
172 } 172 }
173} 173}
174 174
175static void walk_p4d_level(struct seq_file *m, struct pg_state *st,
176 pgd_t *pgd, unsigned long addr)
177{
178 p4d_t *p4d;
179 int i;
180
181 for (i = 0; i < PTRS_PER_P4D && addr < max_addr; i++) {
182 st->current_address = addr;
183 p4d = p4d_offset(pgd, addr);
184 if (!p4d_none(*p4d))
185 walk_pud_level(m, st, p4d, addr);
186 else
187 note_page(m, st, _PAGE_INVALID, 2);
188 addr += P4D_SIZE;
189 }
190}
191
175static void walk_pgd_level(struct seq_file *m) 192static void walk_pgd_level(struct seq_file *m)
176{ 193{
177 unsigned long addr = 0; 194 unsigned long addr = 0;
@@ -184,7 +201,7 @@ static void walk_pgd_level(struct seq_file *m)
184 st.current_address = addr; 201 st.current_address = addr;
185 pgd = pgd_offset_k(addr); 202 pgd = pgd_offset_k(addr);
186 if (!pgd_none(*pgd)) 203 if (!pgd_none(*pgd))
187 walk_pud_level(m, &st, pgd, addr); 204 walk_p4d_level(m, &st, pgd, addr);
188 else 205 else
189 note_page(m, &st, _PAGE_INVALID, 1); 206 note_page(m, &st, _PAGE_INVALID, 1);
190 addr += PGDIR_SIZE; 207 addr += PGDIR_SIZE;
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 5845d3028ffc..14f25798b001 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -130,7 +130,7 @@ static int bad_address(void *p)
130 130
131static void dump_pagetable(unsigned long asce, unsigned long address) 131static void dump_pagetable(unsigned long asce, unsigned long address)
132{ 132{
133 unsigned long *table = __va(asce & PAGE_MASK); 133 unsigned long *table = __va(asce & _ASCE_ORIGIN);
134 134
135 pr_alert("AS:%016lx ", asce); 135 pr_alert("AS:%016lx ", asce);
136 switch (asce & _ASCE_TYPE_MASK) { 136 switch (asce & _ASCE_TYPE_MASK) {
diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index 7f6db1e6c048..4fb3d3cdb370 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -125,7 +125,7 @@ static void gmap_radix_tree_free(struct radix_tree_root *root)
125 struct radix_tree_iter iter; 125 struct radix_tree_iter iter;
126 unsigned long indices[16]; 126 unsigned long indices[16];
127 unsigned long index; 127 unsigned long index;
128 void **slot; 128 void __rcu **slot;
129 int i, nr; 129 int i, nr;
130 130
131 /* A radix tree is freed by deleting all of its entries */ 131 /* A radix tree is freed by deleting all of its entries */
@@ -150,7 +150,7 @@ static void gmap_rmap_radix_tree_free(struct radix_tree_root *root)
150 struct radix_tree_iter iter; 150 struct radix_tree_iter iter;
151 unsigned long indices[16]; 151 unsigned long indices[16];
152 unsigned long index; 152 unsigned long index;
153 void **slot; 153 void __rcu **slot;
154 int i, nr; 154 int i, nr;
155 155
156 /* A radix tree is freed by deleting all of its entries */ 156 /* A radix tree is freed by deleting all of its entries */
@@ -537,6 +537,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr)
537 unsigned long *table; 537 unsigned long *table;
538 spinlock_t *ptl; 538 spinlock_t *ptl;
539 pgd_t *pgd; 539 pgd_t *pgd;
540 p4d_t *p4d;
540 pud_t *pud; 541 pud_t *pud;
541 pmd_t *pmd; 542 pmd_t *pmd;
542 int rc; 543 int rc;
@@ -573,7 +574,9 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr)
573 mm = gmap->mm; 574 mm = gmap->mm;
574 pgd = pgd_offset(mm, vmaddr); 575 pgd = pgd_offset(mm, vmaddr);
575 VM_BUG_ON(pgd_none(*pgd)); 576 VM_BUG_ON(pgd_none(*pgd));
576 pud = pud_offset(pgd, vmaddr); 577 p4d = p4d_offset(pgd, vmaddr);
578 VM_BUG_ON(p4d_none(*p4d));
579 pud = pud_offset(p4d, vmaddr);
577 VM_BUG_ON(pud_none(*pud)); 580 VM_BUG_ON(pud_none(*pud));
578 /* large puds cannot yet be handled */ 581 /* large puds cannot yet be handled */
579 if (pud_large(*pud)) 582 if (pud_large(*pud))
@@ -1008,7 +1011,7 @@ EXPORT_SYMBOL_GPL(gmap_read_table);
1008static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr, 1011static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr,
1009 struct gmap_rmap *rmap) 1012 struct gmap_rmap *rmap)
1010{ 1013{
1011 void **slot; 1014 void __rcu **slot;
1012 1015
1013 BUG_ON(!gmap_is_shadow(sg)); 1016 BUG_ON(!gmap_is_shadow(sg));
1014 slot = radix_tree_lookup_slot(&sg->host_to_rmap, vmaddr >> PAGE_SHIFT); 1017 slot = radix_tree_lookup_slot(&sg->host_to_rmap, vmaddr >> PAGE_SHIFT);
diff --git a/arch/s390/mm/gup.c b/arch/s390/mm/gup.c
index b7b779c40a5b..8ecc25e760fa 100644
--- a/arch/s390/mm/gup.c
+++ b/arch/s390/mm/gup.c
@@ -166,15 +166,15 @@ static int gup_huge_pud(pud_t *pudp, pud_t pud, unsigned long addr,
166 return 1; 166 return 1;
167} 167}
168 168
169static inline int gup_pud_range(pgd_t *pgdp, pgd_t pgd, unsigned long addr, 169static inline int gup_pud_range(p4d_t *p4dp, p4d_t p4d, unsigned long addr,
170 unsigned long end, int write, struct page **pages, int *nr) 170 unsigned long end, int write, struct page **pages, int *nr)
171{ 171{
172 unsigned long next; 172 unsigned long next;
173 pud_t *pudp, pud; 173 pud_t *pudp, pud;
174 174
175 pudp = (pud_t *) pgdp; 175 pudp = (pud_t *) p4dp;
176 if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2) 176 if ((p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R2)
177 pudp = (pud_t *) pgd_deref(pgd); 177 pudp = (pud_t *) p4d_deref(p4d);
178 pudp += pud_index(addr); 178 pudp += pud_index(addr);
179 do { 179 do {
180 pud = *pudp; 180 pud = *pudp;
@@ -194,6 +194,29 @@ static inline int gup_pud_range(pgd_t *pgdp, pgd_t pgd, unsigned long addr,
194 return 1; 194 return 1;
195} 195}
196 196
197static inline int gup_p4d_range(pgd_t *pgdp, pgd_t pgd, unsigned long addr,
198 unsigned long end, int write, struct page **pages, int *nr)
199{
200 unsigned long next;
201 p4d_t *p4dp, p4d;
202
203 p4dp = (p4d_t *) pgdp;
204 if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R1)
205 p4dp = (p4d_t *) pgd_deref(pgd);
206 p4dp += p4d_index(addr);
207 do {
208 p4d = *p4dp;
209 barrier();
210 next = p4d_addr_end(addr, end);
211 if (p4d_none(p4d))
212 return 0;
213 if (!gup_pud_range(p4dp, p4d, addr, next, write, pages, nr))
214 return 0;
215 } while (p4dp++, addr = next, addr != end);
216
217 return 1;
218}
219
197/* 220/*
198 * Like get_user_pages_fast() except its IRQ-safe in that it won't fall 221 * Like get_user_pages_fast() except its IRQ-safe in that it won't fall
199 * back to the regular GUP. 222 * back to the regular GUP.
@@ -228,7 +251,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
228 next = pgd_addr_end(addr, end); 251 next = pgd_addr_end(addr, end);
229 if (pgd_none(pgd)) 252 if (pgd_none(pgd))
230 break; 253 break;
231 if (!gup_pud_range(pgdp, pgd, addr, next, write, pages, &nr)) 254 if (!gup_p4d_range(pgdp, pgd, addr, next, write, pages, &nr))
232 break; 255 break;
233 } while (pgdp++, addr = next, addr != end); 256 } while (pgdp++, addr = next, addr != end);
234 local_irq_restore(flags); 257 local_irq_restore(flags);
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index 9b4050caa4e9..d3a5e39756f6 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -162,16 +162,20 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
162 unsigned long addr, unsigned long sz) 162 unsigned long addr, unsigned long sz)
163{ 163{
164 pgd_t *pgdp; 164 pgd_t *pgdp;
165 p4d_t *p4dp;
165 pud_t *pudp; 166 pud_t *pudp;
166 pmd_t *pmdp = NULL; 167 pmd_t *pmdp = NULL;
167 168
168 pgdp = pgd_offset(mm, addr); 169 pgdp = pgd_offset(mm, addr);
169 pudp = pud_alloc(mm, pgdp, addr); 170 p4dp = p4d_alloc(mm, pgdp, addr);
170 if (pudp) { 171 if (p4dp) {
171 if (sz == PUD_SIZE) 172 pudp = pud_alloc(mm, p4dp, addr);
172 return (pte_t *) pudp; 173 if (pudp) {
173 else if (sz == PMD_SIZE) 174 if (sz == PUD_SIZE)
174 pmdp = pmd_alloc(mm, pudp, addr); 175 return (pte_t *) pudp;
176 else if (sz == PMD_SIZE)
177 pmdp = pmd_alloc(mm, pudp, addr);
178 }
175 } 179 }
176 return (pte_t *) pmdp; 180 return (pte_t *) pmdp;
177} 181}
@@ -179,16 +183,20 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
179pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr) 183pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
180{ 184{
181 pgd_t *pgdp; 185 pgd_t *pgdp;
186 p4d_t *p4dp;
182 pud_t *pudp; 187 pud_t *pudp;
183 pmd_t *pmdp = NULL; 188 pmd_t *pmdp = NULL;
184 189
185 pgdp = pgd_offset(mm, addr); 190 pgdp = pgd_offset(mm, addr);
186 if (pgd_present(*pgdp)) { 191 if (pgd_present(*pgdp)) {
187 pudp = pud_offset(pgdp, addr); 192 p4dp = p4d_offset(pgdp, addr);
188 if (pud_present(*pudp)) { 193 if (p4d_present(*p4dp)) {
189 if (pud_large(*pudp)) 194 pudp = pud_offset(p4dp, addr);
190 return (pte_t *) pudp; 195 if (pud_present(*pudp)) {
191 pmdp = pmd_offset(pudp, addr); 196 if (pud_large(*pudp))
197 return (pte_t *) pudp;
198 pmdp = pmd_offset(pudp, addr);
199 }
192 } 200 }
193 } 201 }
194 return (pte_t *) pmdp; 202 return (pte_t *) pmdp;
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index ee6a1d3d4983..3348e60dd8ad 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -81,6 +81,7 @@ void __init paging_init(void)
81{ 81{
82 unsigned long max_zone_pfns[MAX_NR_ZONES]; 82 unsigned long max_zone_pfns[MAX_NR_ZONES];
83 unsigned long pgd_type, asce_bits; 83 unsigned long pgd_type, asce_bits;
84 psw_t psw;
84 85
85 init_mm.pgd = swapper_pg_dir; 86 init_mm.pgd = swapper_pg_dir;
86 if (VMALLOC_END > (1UL << 42)) { 87 if (VMALLOC_END > (1UL << 42)) {
@@ -100,7 +101,10 @@ void __init paging_init(void)
100 __ctl_load(S390_lowcore.kernel_asce, 1, 1); 101 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
101 __ctl_load(S390_lowcore.kernel_asce, 7, 7); 102 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
102 __ctl_load(S390_lowcore.kernel_asce, 13, 13); 103 __ctl_load(S390_lowcore.kernel_asce, 13, 13);
103 __arch_local_irq_stosm(0x04); 104 psw.mask = __extract_psw();
105 psw_bits(psw).dat = 1;
106 psw_bits(psw).as = PSW_BITS_AS_HOME;
107 __load_psw_mask(psw.mask);
104 108
105 sparse_memory_present_with_active_regions(MAX_NUMNODES); 109 sparse_memory_present_with_active_regions(MAX_NUMNODES);
106 sparse_init(); 110 sparse_init();
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index b854b1da281a..2e10d2b8ad35 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -120,7 +120,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
120 120
121check_asce_limit: 121check_asce_limit:
122 if (addr + len > current->mm->context.asce_limit) { 122 if (addr + len > current->mm->context.asce_limit) {
123 rc = crst_table_upgrade(mm); 123 rc = crst_table_upgrade(mm, addr + len);
124 if (rc) 124 if (rc)
125 return (unsigned long) rc; 125 return (unsigned long) rc;
126 } 126 }
@@ -184,7 +184,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
184 184
185check_asce_limit: 185check_asce_limit:
186 if (addr + len > current->mm->context.asce_limit) { 186 if (addr + len > current->mm->context.asce_limit) {
187 rc = crst_table_upgrade(mm); 187 rc = crst_table_upgrade(mm, addr + len);
188 if (rc) 188 if (rc)
189 return (unsigned long) rc; 189 return (unsigned long) rc;
190 } 190 }
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index 49e721f3645e..180481589246 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -229,14 +229,14 @@ static void modify_pud_page(pud_t *pudp, unsigned long addr,
229 pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3); 229 pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3);
230} 230}
231 231
232static int walk_pud_level(pgd_t *pgd, unsigned long addr, unsigned long end, 232static int walk_pud_level(p4d_t *p4d, unsigned long addr, unsigned long end,
233 unsigned long flags) 233 unsigned long flags)
234{ 234{
235 unsigned long next; 235 unsigned long next;
236 pud_t *pudp; 236 pud_t *pudp;
237 int rc = 0; 237 int rc = 0;
238 238
239 pudp = pud_offset(pgd, addr); 239 pudp = pud_offset(p4d, addr);
240 do { 240 do {
241 if (pud_none(*pudp)) 241 if (pud_none(*pudp))
242 return -EINVAL; 242 return -EINVAL;
@@ -259,6 +259,26 @@ static int walk_pud_level(pgd_t *pgd, unsigned long addr, unsigned long end,
259 return rc; 259 return rc;
260} 260}
261 261
262static int walk_p4d_level(pgd_t *pgd, unsigned long addr, unsigned long end,
263 unsigned long flags)
264{
265 unsigned long next;
266 p4d_t *p4dp;
267 int rc = 0;
268
269 p4dp = p4d_offset(pgd, addr);
270 do {
271 if (p4d_none(*p4dp))
272 return -EINVAL;
273 next = p4d_addr_end(addr, end);
274 rc = walk_pud_level(p4dp, addr, next, flags);
275 p4dp++;
276 addr = next;
277 cond_resched();
278 } while (addr < end && !rc);
279 return rc;
280}
281
262static DEFINE_MUTEX(cpa_mutex); 282static DEFINE_MUTEX(cpa_mutex);
263 283
264static int change_page_attr(unsigned long addr, unsigned long end, 284static int change_page_attr(unsigned long addr, unsigned long end,
@@ -278,7 +298,7 @@ static int change_page_attr(unsigned long addr, unsigned long end,
278 if (pgd_none(*pgdp)) 298 if (pgd_none(*pgdp))
279 break; 299 break;
280 next = pgd_addr_end(addr, end); 300 next = pgd_addr_end(addr, end);
281 rc = walk_pud_level(pgdp, addr, next, flags); 301 rc = walk_p4d_level(pgdp, addr, next, flags);
282 if (rc) 302 if (rc)
283 break; 303 break;
284 cond_resched(); 304 cond_resched();
@@ -319,6 +339,7 @@ void __kernel_map_pages(struct page *page, int numpages, int enable)
319 unsigned long address; 339 unsigned long address;
320 int nr, i, j; 340 int nr, i, j;
321 pgd_t *pgd; 341 pgd_t *pgd;
342 p4d_t *p4d;
322 pud_t *pud; 343 pud_t *pud;
323 pmd_t *pmd; 344 pmd_t *pmd;
324 pte_t *pte; 345 pte_t *pte;
@@ -326,7 +347,8 @@ void __kernel_map_pages(struct page *page, int numpages, int enable)
326 for (i = 0; i < numpages;) { 347 for (i = 0; i < numpages;) {
327 address = page_to_phys(page + i); 348 address = page_to_phys(page + i);
328 pgd = pgd_offset_k(address); 349 pgd = pgd_offset_k(address);
329 pud = pud_offset(pgd, address); 350 p4d = p4d_offset(pgd, address);
351 pud = pud_offset(p4d, address);
330 pmd = pmd_offset(pud, address); 352 pmd = pmd_offset(pud, address);
331 pte = pte_offset_kernel(pmd, address); 353 pte = pte_offset_kernel(pmd, address);
332 nr = (unsigned long)pte >> ilog2(sizeof(long)); 354 nr = (unsigned long)pte >> ilog2(sizeof(long));
diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
index f502cbe657af..18918e394ce4 100644
--- a/arch/s390/mm/pgalloc.c
+++ b/arch/s390/mm/pgalloc.c
@@ -76,29 +76,46 @@ static void __crst_table_upgrade(void *arg)
76 __tlb_flush_local(); 76 __tlb_flush_local();
77} 77}
78 78
79int crst_table_upgrade(struct mm_struct *mm) 79int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
80{ 80{
81 unsigned long *table, *pgd; 81 unsigned long *table, *pgd;
82 int rc, notify;
82 83
83 /* upgrade should only happen from 3 to 4 levels */ 84 /* upgrade should only happen from 3 to 4, 3 to 5, or 4 to 5 levels */
84 BUG_ON(mm->context.asce_limit != (1UL << 42)); 85 BUG_ON(mm->context.asce_limit < (1UL << 42));
85 86 if (end >= TASK_SIZE_MAX)
86 table = crst_table_alloc(mm);
87 if (!table)
88 return -ENOMEM; 87 return -ENOMEM;
89 88 rc = 0;
90 spin_lock_bh(&mm->page_table_lock); 89 notify = 0;
91 pgd = (unsigned long *) mm->pgd; 90 while (mm->context.asce_limit < end) {
92 crst_table_init(table, _REGION2_ENTRY_EMPTY); 91 table = crst_table_alloc(mm);
93 pgd_populate(mm, (pgd_t *) table, (pud_t *) pgd); 92 if (!table) {
94 mm->pgd = (pgd_t *) table; 93 rc = -ENOMEM;
95 mm->context.asce_limit = 1UL << 53; 94 break;
96 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH | 95 }
97 _ASCE_USER_BITS | _ASCE_TYPE_REGION2; 96 spin_lock_bh(&mm->page_table_lock);
98 spin_unlock_bh(&mm->page_table_lock); 97 pgd = (unsigned long *) mm->pgd;
99 98 if (mm->context.asce_limit == (1UL << 42)) {
100 on_each_cpu(__crst_table_upgrade, mm, 0); 99 crst_table_init(table, _REGION2_ENTRY_EMPTY);
101 return 0; 100 p4d_populate(mm, (p4d_t *) table, (pud_t *) pgd);
101 mm->pgd = (pgd_t *) table;
102 mm->context.asce_limit = 1UL << 53;
103 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
104 _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
105 } else {
106 crst_table_init(table, _REGION1_ENTRY_EMPTY);
107 pgd_populate(mm, (pgd_t *) table, (p4d_t *) pgd);
108 mm->pgd = (pgd_t *) table;
109 mm->context.asce_limit = -PAGE_SIZE;
110 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
111 _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
112 }
113 notify = 1;
114 spin_unlock_bh(&mm->page_table_lock);
115 }
116 if (notify)
117 on_each_cpu(__crst_table_upgrade, mm, 0);
118 return rc;
102} 119}
103 120
104void crst_table_downgrade(struct mm_struct *mm) 121void crst_table_downgrade(struct mm_struct *mm)
@@ -274,7 +291,7 @@ static void __tlb_remove_table(void *_table)
274 struct page *page = pfn_to_page(__pa(table) >> PAGE_SHIFT); 291 struct page *page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
275 292
276 switch (mask) { 293 switch (mask) {
277 case 0: /* pmd or pud */ 294 case 0: /* pmd, pud, or p4d */
278 free_pages((unsigned long) table, 2); 295 free_pages((unsigned long) table, 2);
279 break; 296 break;
280 case 1: /* lower 2K of a 4K page table */ 297 case 1: /* lower 2K of a 4K page table */
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 947b66a5cdba..d4d409ba206b 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -610,6 +610,7 @@ bool test_and_clear_guest_dirty(struct mm_struct *mm, unsigned long addr)
610{ 610{
611 spinlock_t *ptl; 611 spinlock_t *ptl;
612 pgd_t *pgd; 612 pgd_t *pgd;
613 p4d_t *p4d;
613 pud_t *pud; 614 pud_t *pud;
614 pmd_t *pmd; 615 pmd_t *pmd;
615 pgste_t pgste; 616 pgste_t pgste;
@@ -618,7 +619,10 @@ bool test_and_clear_guest_dirty(struct mm_struct *mm, unsigned long addr)
618 bool dirty; 619 bool dirty;
619 620
620 pgd = pgd_offset(mm, addr); 621 pgd = pgd_offset(mm, addr);
621 pud = pud_alloc(mm, pgd, addr); 622 p4d = p4d_alloc(mm, pgd, addr);
623 if (!p4d)
624 return false;
625 pud = pud_alloc(mm, p4d, addr);
622 if (!pud) 626 if (!pud)
623 return false; 627 return false;
624 pmd = pmd_alloc(mm, pud, addr); 628 pmd = pmd_alloc(mm, pud, addr);
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index c33c94b4be60..d8398962a723 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -38,6 +38,17 @@ static void __ref *vmem_alloc_pages(unsigned int order)
38 return (void *) memblock_alloc(size, size); 38 return (void *) memblock_alloc(size, size);
39} 39}
40 40
41static inline p4d_t *vmem_p4d_alloc(void)
42{
43 p4d_t *p4d = NULL;
44
45 p4d = vmem_alloc_pages(2);
46 if (!p4d)
47 return NULL;
48 clear_table((unsigned long *) p4d, _REGION2_ENTRY_EMPTY, PAGE_SIZE * 4);
49 return p4d;
50}
51
41static inline pud_t *vmem_pud_alloc(void) 52static inline pud_t *vmem_pud_alloc(void)
42{ 53{
43 pud_t *pud = NULL; 54 pud_t *pud = NULL;
@@ -85,6 +96,7 @@ static int vmem_add_mem(unsigned long start, unsigned long size)
85 unsigned long end = start + size; 96 unsigned long end = start + size;
86 unsigned long address = start; 97 unsigned long address = start;
87 pgd_t *pg_dir; 98 pgd_t *pg_dir;
99 p4d_t *p4_dir;
88 pud_t *pu_dir; 100 pud_t *pu_dir;
89 pmd_t *pm_dir; 101 pmd_t *pm_dir;
90 pte_t *pt_dir; 102 pte_t *pt_dir;
@@ -102,12 +114,19 @@ static int vmem_add_mem(unsigned long start, unsigned long size)
102 while (address < end) { 114 while (address < end) {
103 pg_dir = pgd_offset_k(address); 115 pg_dir = pgd_offset_k(address);
104 if (pgd_none(*pg_dir)) { 116 if (pgd_none(*pg_dir)) {
117 p4_dir = vmem_p4d_alloc();
118 if (!p4_dir)
119 goto out;
120 pgd_populate(&init_mm, pg_dir, p4_dir);
121 }
122 p4_dir = p4d_offset(pg_dir, address);
123 if (p4d_none(*p4_dir)) {
105 pu_dir = vmem_pud_alloc(); 124 pu_dir = vmem_pud_alloc();
106 if (!pu_dir) 125 if (!pu_dir)
107 goto out; 126 goto out;
108 pgd_populate(&init_mm, pg_dir, pu_dir); 127 p4d_populate(&init_mm, p4_dir, pu_dir);
109 } 128 }
110 pu_dir = pud_offset(pg_dir, address); 129 pu_dir = pud_offset(p4_dir, address);
111 if (MACHINE_HAS_EDAT2 && pud_none(*pu_dir) && address && 130 if (MACHINE_HAS_EDAT2 && pud_none(*pu_dir) && address &&
112 !(address & ~PUD_MASK) && (address + PUD_SIZE <= end) && 131 !(address & ~PUD_MASK) && (address + PUD_SIZE <= end) &&
113 !debug_pagealloc_enabled()) { 132 !debug_pagealloc_enabled()) {
@@ -161,6 +180,7 @@ static void vmem_remove_range(unsigned long start, unsigned long size)
161 unsigned long end = start + size; 180 unsigned long end = start + size;
162 unsigned long address = start; 181 unsigned long address = start;
163 pgd_t *pg_dir; 182 pgd_t *pg_dir;
183 p4d_t *p4_dir;
164 pud_t *pu_dir; 184 pud_t *pu_dir;
165 pmd_t *pm_dir; 185 pmd_t *pm_dir;
166 pte_t *pt_dir; 186 pte_t *pt_dir;
@@ -172,7 +192,12 @@ static void vmem_remove_range(unsigned long start, unsigned long size)
172 address += PGDIR_SIZE; 192 address += PGDIR_SIZE;
173 continue; 193 continue;
174 } 194 }
175 pu_dir = pud_offset(pg_dir, address); 195 p4_dir = p4d_offset(pg_dir, address);
196 if (p4d_none(*p4_dir)) {
197 address += P4D_SIZE;
198 continue;
199 }
200 pu_dir = pud_offset(p4_dir, address);
176 if (pud_none(*pu_dir)) { 201 if (pud_none(*pu_dir)) {
177 address += PUD_SIZE; 202 address += PUD_SIZE;
178 continue; 203 continue;
@@ -213,6 +238,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
213 unsigned long pgt_prot, sgt_prot; 238 unsigned long pgt_prot, sgt_prot;
214 unsigned long address = start; 239 unsigned long address = start;
215 pgd_t *pg_dir; 240 pgd_t *pg_dir;
241 p4d_t *p4_dir;
216 pud_t *pu_dir; 242 pud_t *pu_dir;
217 pmd_t *pm_dir; 243 pmd_t *pm_dir;
218 pte_t *pt_dir; 244 pte_t *pt_dir;
@@ -227,13 +253,21 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
227 for (address = start; address < end;) { 253 for (address = start; address < end;) {
228 pg_dir = pgd_offset_k(address); 254 pg_dir = pgd_offset_k(address);
229 if (pgd_none(*pg_dir)) { 255 if (pgd_none(*pg_dir)) {
256 p4_dir = vmem_p4d_alloc();
257 if (!p4_dir)
258 goto out;
259 pgd_populate(&init_mm, pg_dir, p4_dir);
260 }
261
262 p4_dir = p4d_offset(pg_dir, address);
263 if (p4d_none(*p4_dir)) {
230 pu_dir = vmem_pud_alloc(); 264 pu_dir = vmem_pud_alloc();
231 if (!pu_dir) 265 if (!pu_dir)
232 goto out; 266 goto out;
233 pgd_populate(&init_mm, pg_dir, pu_dir); 267 p4d_populate(&init_mm, p4_dir, pu_dir);
234 } 268 }
235 269
236 pu_dir = pud_offset(pg_dir, address); 270 pu_dir = pud_offset(p4_dir, address);
237 if (pud_none(*pu_dir)) { 271 if (pud_none(*pu_dir)) {
238 pm_dir = vmem_pmd_alloc(); 272 pm_dir = vmem_pmd_alloc();
239 if (!pm_dir) 273 if (!pm_dir)
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 8051df109db3..7b30af5da222 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -86,6 +86,25 @@ struct zpci_dev *get_zdev_by_fid(u32 fid)
86 return zdev; 86 return zdev;
87} 87}
88 88
89void zpci_remove_reserved_devices(void)
90{
91 struct zpci_dev *tmp, *zdev;
92 enum zpci_state state;
93 LIST_HEAD(remove);
94
95 spin_lock(&zpci_list_lock);
96 list_for_each_entry_safe(zdev, tmp, &zpci_list, entry) {
97 if (zdev->state == ZPCI_FN_STATE_STANDBY &&
98 !clp_get_state(zdev->fid, &state) &&
99 state == ZPCI_FN_STATE_RESERVED)
100 list_move_tail(&zdev->entry, &remove);
101 }
102 spin_unlock(&zpci_list_lock);
103
104 list_for_each_entry_safe(zdev, tmp, &remove, entry)
105 zpci_remove_device(zdev);
106}
107
89static struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus) 108static struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus)
90{ 109{
91 return (bus && bus->sysdata) ? (struct zpci_dev *) bus->sysdata : NULL; 110 return (bus && bus->sysdata) ? (struct zpci_dev *) bus->sysdata : NULL;
@@ -108,6 +127,7 @@ static int zpci_set_airq(struct zpci_dev *zdev)
108{ 127{
109 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_REG_INT); 128 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_REG_INT);
110 struct zpci_fib fib = {0}; 129 struct zpci_fib fib = {0};
130 u8 status;
111 131
112 fib.isc = PCI_ISC; 132 fib.isc = PCI_ISC;
113 fib.sum = 1; /* enable summary notifications */ 133 fib.sum = 1; /* enable summary notifications */
@@ -117,60 +137,58 @@ static int zpci_set_airq(struct zpci_dev *zdev)
117 fib.aisb = (unsigned long) zpci_aisb_iv->vector + (zdev->aisb/64)*8; 137 fib.aisb = (unsigned long) zpci_aisb_iv->vector + (zdev->aisb/64)*8;
118 fib.aisbo = zdev->aisb & 63; 138 fib.aisbo = zdev->aisb & 63;
119 139
120 return zpci_mod_fc(req, &fib); 140 return zpci_mod_fc(req, &fib, &status) ? -EIO : 0;
121} 141}
122 142
123struct mod_pci_args { 143/* Modify PCI: Unregister adapter interruptions */
124 u64 base; 144static int zpci_clear_airq(struct zpci_dev *zdev)
125 u64 limit;
126 u64 iota;
127 u64 fmb_addr;
128};
129
130static int mod_pci(struct zpci_dev *zdev, int fn, u8 dmaas, struct mod_pci_args *args)
131{ 145{
132 u64 req = ZPCI_CREATE_REQ(zdev->fh, dmaas, fn); 146 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_DEREG_INT);
133 struct zpci_fib fib = {0}; 147 struct zpci_fib fib = {0};
148 u8 cc, status;
134 149
135 fib.pba = args->base; 150 cc = zpci_mod_fc(req, &fib, &status);
136 fib.pal = args->limit; 151 if (cc == 3 || (cc == 1 && status == 24))
137 fib.iota = args->iota; 152 /* Function already gone or IRQs already deregistered. */
138 fib.fmb_addr = args->fmb_addr; 153 cc = 0;
139 154
140 return zpci_mod_fc(req, &fib); 155 return cc ? -EIO : 0;
141} 156}
142 157
143/* Modify PCI: Register I/O address translation parameters */ 158/* Modify PCI: Register I/O address translation parameters */
144int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas, 159int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
145 u64 base, u64 limit, u64 iota) 160 u64 base, u64 limit, u64 iota)
146{ 161{
147 struct mod_pci_args args = { base, limit, iota, 0 }; 162 u64 req = ZPCI_CREATE_REQ(zdev->fh, dmaas, ZPCI_MOD_FC_REG_IOAT);
163 struct zpci_fib fib = {0};
164 u8 status;
148 165
149 WARN_ON_ONCE(iota & 0x3fff); 166 WARN_ON_ONCE(iota & 0x3fff);
150 args.iota |= ZPCI_IOTA_RTTO_FLAG; 167 fib.pba = base;
151 return mod_pci(zdev, ZPCI_MOD_FC_REG_IOAT, dmaas, &args); 168 fib.pal = limit;
169 fib.iota = iota | ZPCI_IOTA_RTTO_FLAG;
170 return zpci_mod_fc(req, &fib, &status) ? -EIO : 0;
152} 171}
153 172
154/* Modify PCI: Unregister I/O address translation parameters */ 173/* Modify PCI: Unregister I/O address translation parameters */
155int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas) 174int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
156{ 175{
157 struct mod_pci_args args = { 0, 0, 0, 0 }; 176 u64 req = ZPCI_CREATE_REQ(zdev->fh, dmaas, ZPCI_MOD_FC_DEREG_IOAT);
158 177 struct zpci_fib fib = {0};
159 return mod_pci(zdev, ZPCI_MOD_FC_DEREG_IOAT, dmaas, &args); 178 u8 cc, status;
160}
161
162/* Modify PCI: Unregister adapter interruptions */
163static int zpci_clear_airq(struct zpci_dev *zdev)
164{
165 struct mod_pci_args args = { 0, 0, 0, 0 };
166 179
167 return mod_pci(zdev, ZPCI_MOD_FC_DEREG_INT, 0, &args); 180 cc = zpci_mod_fc(req, &fib, &status);
181 if (cc == 3) /* Function already gone. */
182 cc = 0;
183 return cc ? -EIO : 0;
168} 184}
169 185
170/* Modify PCI: Set PCI function measurement parameters */ 186/* Modify PCI: Set PCI function measurement parameters */
171int zpci_fmb_enable_device(struct zpci_dev *zdev) 187int zpci_fmb_enable_device(struct zpci_dev *zdev)
172{ 188{
173 struct mod_pci_args args = { 0, 0, 0, 0 }; 189 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
190 struct zpci_fib fib = {0};
191 u8 cc, status;
174 192
175 if (zdev->fmb || sizeof(*zdev->fmb) < zdev->fmb_length) 193 if (zdev->fmb || sizeof(*zdev->fmb) < zdev->fmb_length)
176 return -EINVAL; 194 return -EINVAL;
@@ -185,25 +203,35 @@ int zpci_fmb_enable_device(struct zpci_dev *zdev)
185 atomic64_set(&zdev->mapped_pages, 0); 203 atomic64_set(&zdev->mapped_pages, 0);
186 atomic64_set(&zdev->unmapped_pages, 0); 204 atomic64_set(&zdev->unmapped_pages, 0);
187 205
188 args.fmb_addr = virt_to_phys(zdev->fmb); 206 fib.fmb_addr = virt_to_phys(zdev->fmb);
189 return mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args); 207 cc = zpci_mod_fc(req, &fib, &status);
208 if (cc) {
209 kmem_cache_free(zdev_fmb_cache, zdev->fmb);
210 zdev->fmb = NULL;
211 }
212 return cc ? -EIO : 0;
190} 213}
191 214
192/* Modify PCI: Disable PCI function measurement */ 215/* Modify PCI: Disable PCI function measurement */
193int zpci_fmb_disable_device(struct zpci_dev *zdev) 216int zpci_fmb_disable_device(struct zpci_dev *zdev)
194{ 217{
195 struct mod_pci_args args = { 0, 0, 0, 0 }; 218 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_SET_MEASURE);
196 int rc; 219 struct zpci_fib fib = {0};
220 u8 cc, status;
197 221
198 if (!zdev->fmb) 222 if (!zdev->fmb)
199 return -EINVAL; 223 return -EINVAL;
200 224
201 /* Function measurement is disabled if fmb address is zero */ 225 /* Function measurement is disabled if fmb address is zero */
202 rc = mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args); 226 cc = zpci_mod_fc(req, &fib, &status);
227 if (cc == 3) /* Function already gone. */
228 cc = 0;
203 229
204 kmem_cache_free(zdev_fmb_cache, zdev->fmb); 230 if (!cc) {
205 zdev->fmb = NULL; 231 kmem_cache_free(zdev_fmb_cache, zdev->fmb);
206 return rc; 232 zdev->fmb = NULL;
233 }
234 return cc ? -EIO : 0;
207} 235}
208 236
209static int zpci_cfg_load(struct zpci_dev *zdev, int offset, u32 *val, u8 len) 237static int zpci_cfg_load(struct zpci_dev *zdev, int offset, u32 *val, u8 len)
@@ -372,22 +400,21 @@ int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
372 struct msi_msg msg; 400 struct msi_msg msg;
373 int rc, irq; 401 int rc, irq;
374 402
403 zdev->aisb = -1UL;
375 if (type == PCI_CAP_ID_MSI && nvec > 1) 404 if (type == PCI_CAP_ID_MSI && nvec > 1)
376 return 1; 405 return 1;
377 msi_vecs = min_t(unsigned int, nvec, zdev->max_msi); 406 msi_vecs = min_t(unsigned int, nvec, zdev->max_msi);
378 407
379 /* Allocate adapter summary indicator bit */ 408 /* Allocate adapter summary indicator bit */
380 rc = -EIO;
381 aisb = airq_iv_alloc_bit(zpci_aisb_iv); 409 aisb = airq_iv_alloc_bit(zpci_aisb_iv);
382 if (aisb == -1UL) 410 if (aisb == -1UL)
383 goto out; 411 return -EIO;
384 zdev->aisb = aisb; 412 zdev->aisb = aisb;
385 413
386 /* Create adapter interrupt vector */ 414 /* Create adapter interrupt vector */
387 rc = -ENOMEM;
388 zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK); 415 zdev->aibv = airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK);
389 if (!zdev->aibv) 416 if (!zdev->aibv)
390 goto out_si; 417 return -ENOMEM;
391 418
392 /* Wire up shortcut pointer */ 419 /* Wire up shortcut pointer */
393 zpci_aibv[aisb] = zdev->aibv; 420 zpci_aibv[aisb] = zdev->aibv;
@@ -398,10 +425,10 @@ int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
398 rc = -EIO; 425 rc = -EIO;
399 irq = irq_alloc_desc(0); /* Alloc irq on node 0 */ 426 irq = irq_alloc_desc(0); /* Alloc irq on node 0 */
400 if (irq < 0) 427 if (irq < 0)
401 goto out_msi; 428 return -ENOMEM;
402 rc = irq_set_msi_desc(irq, msi); 429 rc = irq_set_msi_desc(irq, msi);
403 if (rc) 430 if (rc)
404 goto out_msi; 431 return rc;
405 irq_set_chip_and_handler(irq, &zpci_irq_chip, 432 irq_set_chip_and_handler(irq, &zpci_irq_chip,
406 handle_simple_irq); 433 handle_simple_irq);
407 msg.data = hwirq; 434 msg.data = hwirq;
@@ -415,27 +442,9 @@ int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
415 /* Enable adapter interrupts */ 442 /* Enable adapter interrupts */
416 rc = zpci_set_airq(zdev); 443 rc = zpci_set_airq(zdev);
417 if (rc) 444 if (rc)
418 goto out_msi; 445 return rc;
419 446
420 return (msi_vecs == nvec) ? 0 : msi_vecs; 447 return (msi_vecs == nvec) ? 0 : msi_vecs;
421
422out_msi:
423 for_each_pci_msi_entry(msi, pdev) {
424 if (hwirq-- == 0)
425 break;
426 irq_set_msi_desc(msi->irq, NULL);
427 irq_free_desc(msi->irq);
428 msi->msg.address_lo = 0;
429 msi->msg.address_hi = 0;
430 msi->msg.data = 0;
431 msi->irq = 0;
432 }
433 zpci_aibv[aisb] = NULL;
434 airq_iv_release(zdev->aibv);
435out_si:
436 airq_iv_free_bit(zpci_aisb_iv, aisb);
437out:
438 return rc;
439} 448}
440 449
441void arch_teardown_msi_irqs(struct pci_dev *pdev) 450void arch_teardown_msi_irqs(struct pci_dev *pdev)
@@ -451,6 +460,8 @@ void arch_teardown_msi_irqs(struct pci_dev *pdev)
451 460
452 /* Release MSI interrupts */ 461 /* Release MSI interrupts */
453 for_each_pci_msi_entry(msi, pdev) { 462 for_each_pci_msi_entry(msi, pdev) {
463 if (!msi->irq)
464 continue;
454 if (msi->msi_attrib.is_msix) 465 if (msi->msi_attrib.is_msix)
455 __pci_msix_desc_mask_irq(msi, 1); 466 __pci_msix_desc_mask_irq(msi, 1);
456 else 467 else
@@ -463,9 +474,15 @@ void arch_teardown_msi_irqs(struct pci_dev *pdev)
463 msi->irq = 0; 474 msi->irq = 0;
464 } 475 }
465 476
466 zpci_aibv[zdev->aisb] = NULL; 477 if (zdev->aisb != -1UL) {
467 airq_iv_release(zdev->aibv); 478 zpci_aibv[zdev->aisb] = NULL;
468 airq_iv_free_bit(zpci_aisb_iv, zdev->aisb); 479 airq_iv_free_bit(zpci_aisb_iv, zdev->aisb);
480 zdev->aisb = -1UL;
481 }
482 if (zdev->aibv) {
483 airq_iv_release(zdev->aibv);
484 zdev->aibv = NULL;
485 }
469} 486}
470 487
471static void zpci_map_resources(struct pci_dev *pdev) 488static void zpci_map_resources(struct pci_dev *pdev)
@@ -719,6 +736,16 @@ static int zpci_alloc_domain(struct zpci_dev *zdev)
719{ 736{
720 if (zpci_unique_uid) { 737 if (zpci_unique_uid) {
721 zdev->domain = (u16) zdev->uid; 738 zdev->domain = (u16) zdev->uid;
739 if (zdev->domain >= ZPCI_NR_DEVICES)
740 return 0;
741
742 spin_lock(&zpci_domain_lock);
743 if (test_bit(zdev->domain, zpci_domain)) {
744 spin_unlock(&zpci_domain_lock);
745 return -EEXIST;
746 }
747 set_bit(zdev->domain, zpci_domain);
748 spin_unlock(&zpci_domain_lock);
722 return 0; 749 return 0;
723 } 750 }
724 751
@@ -735,7 +762,7 @@ static int zpci_alloc_domain(struct zpci_dev *zdev)
735 762
736static void zpci_free_domain(struct zpci_dev *zdev) 763static void zpci_free_domain(struct zpci_dev *zdev)
737{ 764{
738 if (zpci_unique_uid) 765 if (zdev->domain >= ZPCI_NR_DEVICES)
739 return; 766 return;
740 767
741 spin_lock(&zpci_domain_lock); 768 spin_lock(&zpci_domain_lock);
@@ -755,6 +782,7 @@ void pcibios_remove_bus(struct pci_bus *bus)
755 list_del(&zdev->entry); 782 list_del(&zdev->entry);
756 spin_unlock(&zpci_list_lock); 783 spin_unlock(&zpci_list_lock);
757 784
785 zpci_dbg(3, "rem fid:%x\n", zdev->fid);
758 kfree(zdev); 786 kfree(zdev);
759} 787}
760 788
@@ -847,15 +875,14 @@ out:
847 return rc; 875 return rc;
848} 876}
849 877
850void zpci_stop_device(struct zpci_dev *zdev) 878void zpci_remove_device(struct zpci_dev *zdev)
851{ 879{
852 zpci_dma_exit_device(zdev); 880 if (!zdev->bus)
853 /* 881 return;
854 * Note: SCLP disables fh via set-pci-fn so don't 882
855 * do that here. 883 pci_stop_root_bus(zdev->bus);
856 */ 884 pci_remove_root_bus(zdev->bus);
857} 885}
858EXPORT_SYMBOL_GPL(zpci_stop_device);
859 886
860int zpci_report_error(struct pci_dev *pdev, 887int zpci_report_error(struct pci_dev *pdev,
861 struct zpci_report_error_header *report) 888 struct zpci_report_error_header *report)
diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c
index 1c3332ac1957..bd534b4d40e3 100644
--- a/arch/s390/pci/pci_clp.c
+++ b/arch/s390/pci/pci_clp.c
@@ -193,12 +193,12 @@ out:
193int clp_add_pci_device(u32 fid, u32 fh, int configured) 193int clp_add_pci_device(u32 fid, u32 fh, int configured)
194{ 194{
195 struct zpci_dev *zdev; 195 struct zpci_dev *zdev;
196 int rc; 196 int rc = -ENOMEM;
197 197
198 zpci_dbg(3, "add fid:%x, fh:%x, c:%d\n", fid, fh, configured); 198 zpci_dbg(3, "add fid:%x, fh:%x, c:%d\n", fid, fh, configured);
199 zdev = kzalloc(sizeof(*zdev), GFP_KERNEL); 199 zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
200 if (!zdev) 200 if (!zdev)
201 return -ENOMEM; 201 goto error;
202 202
203 zdev->fh = fh; 203 zdev->fh = fh;
204 zdev->fid = fid; 204 zdev->fid = fid;
@@ -219,6 +219,7 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured)
219 return 0; 219 return 0;
220 220
221error: 221error:
222 zpci_dbg(0, "add fid:%x, rc:%d\n", fid, rc);
222 kfree(zdev); 223 kfree(zdev);
223 return rc; 224 return rc;
224} 225}
@@ -295,8 +296,8 @@ int clp_disable_fh(struct zpci_dev *zdev)
295 return rc; 296 return rc;
296} 297}
297 298
298static int clp_list_pci(struct clp_req_rsp_list_pci *rrb, 299static int clp_list_pci(struct clp_req_rsp_list_pci *rrb, void *data,
299 void (*cb)(struct clp_fh_list_entry *entry)) 300 void (*cb)(struct clp_fh_list_entry *, void *))
300{ 301{
301 u64 resume_token = 0; 302 u64 resume_token = 0;
302 int entries, i, rc; 303 int entries, i, rc;
@@ -327,21 +328,13 @@ static int clp_list_pci(struct clp_req_rsp_list_pci *rrb,
327 328
328 resume_token = rrb->response.resume_token; 329 resume_token = rrb->response.resume_token;
329 for (i = 0; i < entries; i++) 330 for (i = 0; i < entries; i++)
330 cb(&rrb->response.fh_list[i]); 331 cb(&rrb->response.fh_list[i], data);
331 } while (resume_token); 332 } while (resume_token);
332out: 333out:
333 return rc; 334 return rc;
334} 335}
335 336
336static void __clp_add(struct clp_fh_list_entry *entry) 337static void __clp_add(struct clp_fh_list_entry *entry, void *data)
337{
338 if (!entry->vendor_id)
339 return;
340
341 clp_add_pci_device(entry->fid, entry->fh, entry->config_state);
342}
343
344static void __clp_rescan(struct clp_fh_list_entry *entry)
345{ 338{
346 struct zpci_dev *zdev; 339 struct zpci_dev *zdev;
347 340
@@ -349,22 +342,11 @@ static void __clp_rescan(struct clp_fh_list_entry *entry)
349 return; 342 return;
350 343
351 zdev = get_zdev_by_fid(entry->fid); 344 zdev = get_zdev_by_fid(entry->fid);
352 if (!zdev) { 345 if (!zdev)
353 clp_add_pci_device(entry->fid, entry->fh, entry->config_state); 346 clp_add_pci_device(entry->fid, entry->fh, entry->config_state);
354 return;
355 }
356
357 if (!entry->config_state) {
358 /*
359 * The handle is already disabled, that means no iota/irq freeing via
360 * the firmware interfaces anymore. Need to free resources manually
361 * (DMA memory, debug, sysfs)...
362 */
363 zpci_stop_device(zdev);
364 }
365} 347}
366 348
367static void __clp_update(struct clp_fh_list_entry *entry) 349static void __clp_update(struct clp_fh_list_entry *entry, void *data)
368{ 350{
369 struct zpci_dev *zdev; 351 struct zpci_dev *zdev;
370 352
@@ -387,7 +369,7 @@ int clp_scan_pci_devices(void)
387 if (!rrb) 369 if (!rrb)
388 return -ENOMEM; 370 return -ENOMEM;
389 371
390 rc = clp_list_pci(rrb, __clp_add); 372 rc = clp_list_pci(rrb, NULL, __clp_add);
391 373
392 clp_free_block(rrb); 374 clp_free_block(rrb);
393 return rc; 375 return rc;
@@ -398,11 +380,13 @@ int clp_rescan_pci_devices(void)
398 struct clp_req_rsp_list_pci *rrb; 380 struct clp_req_rsp_list_pci *rrb;
399 int rc; 381 int rc;
400 382
383 zpci_remove_reserved_devices();
384
401 rrb = clp_alloc_block(GFP_KERNEL); 385 rrb = clp_alloc_block(GFP_KERNEL);
402 if (!rrb) 386 if (!rrb)
403 return -ENOMEM; 387 return -ENOMEM;
404 388
405 rc = clp_list_pci(rrb, __clp_rescan); 389 rc = clp_list_pci(rrb, NULL, __clp_add);
406 390
407 clp_free_block(rrb); 391 clp_free_block(rrb);
408 return rc; 392 return rc;
@@ -417,7 +401,40 @@ int clp_rescan_pci_devices_simple(void)
417 if (!rrb) 401 if (!rrb)
418 return -ENOMEM; 402 return -ENOMEM;
419 403
420 rc = clp_list_pci(rrb, __clp_update); 404 rc = clp_list_pci(rrb, NULL, __clp_update);
405
406 clp_free_block(rrb);
407 return rc;
408}
409
410struct clp_state_data {
411 u32 fid;
412 enum zpci_state state;
413};
414
415static void __clp_get_state(struct clp_fh_list_entry *entry, void *data)
416{
417 struct clp_state_data *sd = data;
418
419 if (entry->fid != sd->fid)
420 return;
421
422 sd->state = entry->config_state;
423}
424
425int clp_get_state(u32 fid, enum zpci_state *state)
426{
427 struct clp_req_rsp_list_pci *rrb;
428 struct clp_state_data sd = {fid, ZPCI_FN_STATE_RESERVED};
429 int rc;
430
431 rrb = clp_alloc_block(GFP_KERNEL);
432 if (!rrb)
433 return -ENOMEM;
434
435 rc = clp_list_pci(rrb, &sd, __clp_get_state);
436 if (!rc)
437 *state = sd.state;
421 438
422 clp_free_block(rrb); 439 clp_free_block(rrb);
423 return rc; 440 return rc;
diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c
index 9081a57fa340..8eb1cc341dab 100644
--- a/arch/s390/pci/pci_dma.c
+++ b/arch/s390/pci/pci_dma.c
@@ -601,7 +601,9 @@ void zpci_dma_exit_device(struct zpci_dev *zdev)
601 */ 601 */
602 WARN_ON(zdev->s390_domain); 602 WARN_ON(zdev->s390_domain);
603 603
604 zpci_unregister_ioat(zdev, 0); 604 if (zpci_unregister_ioat(zdev, 0))
605 return;
606
605 dma_cleanup_tables(zdev->dma_table); 607 dma_cleanup_tables(zdev->dma_table);
606 zdev->dma_table = NULL; 608 zdev->dma_table = NULL;
607 vfree(zdev->iommu_bitmap); 609 vfree(zdev->iommu_bitmap);
diff --git a/arch/s390/pci/pci_event.c b/arch/s390/pci/pci_event.c
index c2b27ad8e94d..0bbc04af4418 100644
--- a/arch/s390/pci/pci_event.c
+++ b/arch/s390/pci/pci_event.c
@@ -74,6 +74,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
74{ 74{
75 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid); 75 struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
76 struct pci_dev *pdev = NULL; 76 struct pci_dev *pdev = NULL;
77 enum zpci_state state;
77 int ret; 78 int ret;
78 79
79 if (zdev) 80 if (zdev)
@@ -108,6 +109,8 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
108 clp_add_pci_device(ccdf->fid, ccdf->fh, 0); 109 clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
109 break; 110 break;
110 case 0x0303: /* Deconfiguration requested */ 111 case 0x0303: /* Deconfiguration requested */
112 if (!zdev)
113 break;
111 if (pdev) 114 if (pdev)
112 pci_stop_and_remove_bus_device_locked(pdev); 115 pci_stop_and_remove_bus_device_locked(pdev);
113 116
@@ -121,7 +124,9 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
121 zdev->state = ZPCI_FN_STATE_STANDBY; 124 zdev->state = ZPCI_FN_STATE_STANDBY;
122 125
123 break; 126 break;
124 case 0x0304: /* Configured -> Standby */ 127 case 0x0304: /* Configured -> Standby|Reserved */
128 if (!zdev)
129 break;
125 if (pdev) { 130 if (pdev) {
126 /* Give the driver a hint that the function is 131 /* Give the driver a hint that the function is
127 * already unusable. */ 132 * already unusable. */
@@ -132,6 +137,10 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
132 zdev->fh = ccdf->fh; 137 zdev->fh = ccdf->fh;
133 zpci_disable_device(zdev); 138 zpci_disable_device(zdev);
134 zdev->state = ZPCI_FN_STATE_STANDBY; 139 zdev->state = ZPCI_FN_STATE_STANDBY;
140 if (!clp_get_state(ccdf->fid, &state) &&
141 state == ZPCI_FN_STATE_RESERVED) {
142 zpci_remove_device(zdev);
143 }
135 break; 144 break;
136 case 0x0306: /* 0x308 or 0x302 for multiple devices */ 145 case 0x0306: /* 0x308 or 0x302 for multiple devices */
137 clp_rescan_pci_devices(); 146 clp_rescan_pci_devices();
@@ -139,8 +148,7 @@ static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
139 case 0x0308: /* Standby -> Reserved */ 148 case 0x0308: /* Standby -> Reserved */
140 if (!zdev) 149 if (!zdev)
141 break; 150 break;
142 pci_stop_root_bus(zdev->bus); 151 zpci_remove_device(zdev);
143 pci_remove_root_bus(zdev->bus);
144 break; 152 break;
145 default: 153 default:
146 break; 154 break;
diff --git a/arch/s390/pci/pci_insn.c b/arch/s390/pci/pci_insn.c
index fa8d7d4b9751..ea34086c8674 100644
--- a/arch/s390/pci/pci_insn.c
+++ b/arch/s390/pci/pci_insn.c
@@ -40,20 +40,20 @@ static inline u8 __mpcifc(u64 req, struct zpci_fib *fib, u8 *status)
40 return cc; 40 return cc;
41} 41}
42 42
43int zpci_mod_fc(u64 req, struct zpci_fib *fib) 43u8 zpci_mod_fc(u64 req, struct zpci_fib *fib, u8 *status)
44{ 44{
45 u8 cc, status; 45 u8 cc;
46 46
47 do { 47 do {
48 cc = __mpcifc(req, fib, &status); 48 cc = __mpcifc(req, fib, status);
49 if (cc == 2) 49 if (cc == 2)
50 msleep(ZPCI_INSN_BUSY_DELAY); 50 msleep(ZPCI_INSN_BUSY_DELAY);
51 } while (cc == 2); 51 } while (cc == 2);
52 52
53 if (cc) 53 if (cc)
54 zpci_err_insn(cc, status, req, 0); 54 zpci_err_insn(cc, *status, req, 0);
55 55
56 return (cc) ? -EIO : 0; 56 return cc;
57} 57}
58 58
59/* Refresh PCI Translations */ 59/* Refresh PCI Translations */
diff --git a/arch/s390/tools/gen_facilities.c b/arch/s390/tools/gen_facilities.c
index be63fbd699fd..025ea20fc4b4 100644
--- a/arch/s390/tools/gen_facilities.c
+++ b/arch/s390/tools/gen_facilities.c
@@ -34,8 +34,6 @@ static struct facility_def facility_defs[] = {
34 18, /* long displacement facility */ 34 18, /* long displacement facility */
35#endif 35#endif
36#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES 36#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
37 7, /* stfle */
38 17, /* message security assist */
39 21, /* extended-immediate facility */ 37 21, /* extended-immediate facility */
40 25, /* store clock fast */ 38 25, /* store clock fast */
41#endif 39#endif
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index fb1e60f5002e..9c7951bb05ac 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -89,6 +89,20 @@ config PKEY
89 requires to have at least one CEX card in coprocessor mode 89 requires to have at least one CEX card in coprocessor mode
90 available at runtime. 90 available at runtime.
91 91
92config CRYPTO_PAES_S390
93 tristate "PAES cipher algorithms"
94 depends on S390
95 depends on ZCRYPT
96 depends on PKEY
97 select CRYPTO_ALGAPI
98 select CRYPTO_BLKCIPHER
99 help
100 This is the s390 hardware accelerated implementation of the
101 AES cipher algorithms for use with protected key.
102
103 Select this option if you want to use the paes cipher
104 for example to use protected key encrypted devices.
105
92config CRYPTO_SHA1_S390 106config CRYPTO_SHA1_S390
93 tristate "SHA1 digest algorithm" 107 tristate "SHA1 digest algorithm"
94 depends on S390 108 depends on S390
@@ -137,7 +151,6 @@ config CRYPTO_AES_S390
137 depends on S390 151 depends on S390
138 select CRYPTO_ALGAPI 152 select CRYPTO_ALGAPI
139 select CRYPTO_BLKCIPHER 153 select CRYPTO_BLKCIPHER
140 select PKEY
141 help 154 help
142 This is the s390 hardware accelerated implementation of the 155 This is the s390 hardware accelerated implementation of the
143 AES cipher algorithms (FIPS-197). 156 AES cipher algorithms (FIPS-197).
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index 0acb8c2f9475..31f014b57bfc 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -82,10 +82,3 @@ config SCM_BLOCK
82 82
83 To compile this driver as a module, choose M here: the 83 To compile this driver as a module, choose M here: the
84 module will be called scm_block. 84 module will be called scm_block.
85
86config SCM_BLOCK_CLUSTER_WRITE
87 def_bool y
88 prompt "SCM force cluster writes"
89 depends on SCM_BLOCK
90 help
91 Force writes to Storage Class Memory (SCM) to be in done in clusters.
diff --git a/drivers/s390/block/Makefile b/drivers/s390/block/Makefile
index c2f4e673e031..b64e2b32c753 100644
--- a/drivers/s390/block/Makefile
+++ b/drivers/s390/block/Makefile
@@ -19,7 +19,4 @@ obj-$(CONFIG_BLK_DEV_XPRAM) += xpram.o
19obj-$(CONFIG_DCSSBLK) += dcssblk.o 19obj-$(CONFIG_DCSSBLK) += dcssblk.o
20 20
21scm_block-objs := scm_drv.o scm_blk.o 21scm_block-objs := scm_drv.o scm_blk.o
22ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
23scm_block-objs += scm_blk_cluster.o
24endif
25obj-$(CONFIG_SCM_BLOCK) += scm_block.o 22obj-$(CONFIG_SCM_BLOCK) += scm_block.o
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index b7cbd5d2cdea..0f1fe4ff7f51 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1965,8 +1965,12 @@ static int __dasd_device_is_unusable(struct dasd_device *device,
1965{ 1965{
1966 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM); 1966 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1967 1967
1968 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) { 1968 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1969 /* dasd is being set offline. */ 1969 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1970 /*
1971 * dasd is being set offline
1972 * but it is no safe offline where we have to allow I/O
1973 */
1970 return 1; 1974 return 1;
1971 } 1975 }
1972 if (device->stopped) { 1976 if (device->stopped) {
@@ -3570,57 +3574,69 @@ int dasd_generic_set_offline(struct ccw_device *cdev)
3570 else 3574 else
3571 pr_warn("%s: The DASD cannot be set offline while it is in use\n", 3575 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3572 dev_name(&cdev->dev)); 3576 dev_name(&cdev->dev));
3573 clear_bit(DASD_FLAG_OFFLINE, &device->flags); 3577 rc = -EBUSY;
3574 goto out_busy; 3578 goto out_err;
3575 } 3579 }
3576 } 3580 }
3577 3581
3578 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { 3582 /*
3579 /* 3583 * Test if the offline processing is already running and exit if so.
3580 * safe offline already running 3584 * If a safe offline is being processed this could only be a normal
3581 * could only be called by normal offline so safe_offline flag 3585 * offline that should be able to overtake the safe offline and
3582 * needs to be removed to run normal offline and kill all I/O 3586 * cancel any I/O we do not want to wait for any longer
3583 */ 3587 */
3584 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) 3588 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3585 /* Already doing normal offline processing */ 3589 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3586 goto out_busy; 3590 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3587 else 3591 &device->flags);
3588 clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); 3592 } else {
3589 } else { 3593 rc = -EBUSY;
3590 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) 3594 goto out_err;
3591 /* Already doing offline processing */ 3595 }
3592 goto out_busy;
3593 } 3596 }
3594
3595 set_bit(DASD_FLAG_OFFLINE, &device->flags); 3597 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3596 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3597 3598
3598 /* 3599 /*
3599 * if safe_offline called set safe_offline_running flag and 3600 * if safe_offline is called set safe_offline_running flag and
3600 * clear safe_offline so that a call to normal offline 3601 * clear safe_offline so that a call to normal offline
3601 * can overrun safe_offline processing 3602 * can overrun safe_offline processing
3602 */ 3603 */
3603 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) && 3604 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3604 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { 3605 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3606 /* need to unlock here to wait for outstanding I/O */
3607 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3605 /* 3608 /*
3606 * If we want to set the device safe offline all IO operations 3609 * If we want to set the device safe offline all IO operations
3607 * should be finished before continuing the offline process 3610 * should be finished before continuing the offline process
3608 * so sync bdev first and then wait for our queues to become 3611 * so sync bdev first and then wait for our queues to become
3609 * empty 3612 * empty
3610 */ 3613 */
3611 /* sync blockdev and partitions */
3612 if (device->block) { 3614 if (device->block) {
3613 rc = fsync_bdev(device->block->bdev); 3615 rc = fsync_bdev(device->block->bdev);
3614 if (rc != 0) 3616 if (rc != 0)
3615 goto interrupted; 3617 goto interrupted;
3616 } 3618 }
3617 /* schedule device tasklet and wait for completion */
3618 dasd_schedule_device_bh(device); 3619 dasd_schedule_device_bh(device);
3619 rc = wait_event_interruptible(shutdown_waitq, 3620 rc = wait_event_interruptible(shutdown_waitq,
3620 _wait_for_empty_queues(device)); 3621 _wait_for_empty_queues(device));
3621 if (rc != 0) 3622 if (rc != 0)
3622 goto interrupted; 3623 goto interrupted;
3624
3625 /*
3626 * check if a normal offline process overtook the offline
3627 * processing in this case simply do nothing beside returning
3628 * that we got interrupted
3629 * otherwise mark safe offline as not running any longer and
3630 * continue with normal offline
3631 */
3632 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3633 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3634 rc = -ERESTARTSYS;
3635 goto out_err;
3636 }
3637 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3623 } 3638 }
3639 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3624 3640
3625 dasd_set_target_state(device, DASD_STATE_NEW); 3641 dasd_set_target_state(device, DASD_STATE_NEW);
3626 /* dasd_delete_device destroys the device reference. */ 3642 /* dasd_delete_device destroys the device reference. */
@@ -3632,22 +3648,18 @@ int dasd_generic_set_offline(struct ccw_device *cdev)
3632 */ 3648 */
3633 if (block) 3649 if (block)
3634 dasd_free_block(block); 3650 dasd_free_block(block);
3651
3635 return 0; 3652 return 0;
3636 3653
3637interrupted: 3654interrupted:
3638 /* interrupted by signal */ 3655 /* interrupted by signal */
3639 clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); 3656 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3640 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags); 3657 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3641 clear_bit(DASD_FLAG_OFFLINE, &device->flags); 3658 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3642 dasd_put_device(device); 3659out_err:
3643
3644 return rc;
3645
3646out_busy:
3647 dasd_put_device(device); 3660 dasd_put_device(device);
3648 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); 3661 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3649 3662 return rc;
3650 return -EBUSY;
3651} 3663}
3652EXPORT_SYMBOL_GPL(dasd_generic_set_offline); 3664EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3653 3665
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 1164b51d09f3..7c7351276d2e 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -315,45 +315,58 @@ static int __init dasd_parse_range(const char *range)
315 char *features_str = NULL; 315 char *features_str = NULL;
316 char *from_str = NULL; 316 char *from_str = NULL;
317 char *to_str = NULL; 317 char *to_str = NULL;
318 size_t len = strlen(range) + 1; 318 int rc = 0;
319 char tmp[len]; 319 char *tmp;
320 320
321 strlcpy(tmp, range, len); 321 tmp = kstrdup(range, GFP_KERNEL);
322 if (!tmp)
323 return -ENOMEM;
322 324
323 if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) 325 if (dasd_evaluate_range_param(tmp, &from_str, &to_str, &features_str)) {
324 goto out_err; 326 rc = -EINVAL;
327 goto out;
328 }
325 329
326 if (dasd_busid(from_str, &from_id0, &from_id1, &from)) 330 if (dasd_busid(from_str, &from_id0, &from_id1, &from)) {
327 goto out_err; 331 rc = -EINVAL;
332 goto out;
333 }
328 334
329 to = from; 335 to = from;
330 to_id0 = from_id0; 336 to_id0 = from_id0;
331 to_id1 = from_id1; 337 to_id1 = from_id1;
332 if (to_str) { 338 if (to_str) {
333 if (dasd_busid(to_str, &to_id0, &to_id1, &to)) 339 if (dasd_busid(to_str, &to_id0, &to_id1, &to)) {
334 goto out_err; 340 rc = -EINVAL;
341 goto out;
342 }
335 if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) { 343 if (from_id0 != to_id0 || from_id1 != to_id1 || from > to) {
336 pr_err("%s is not a valid device range\n", range); 344 pr_err("%s is not a valid device range\n", range);
337 goto out_err; 345 rc = -EINVAL;
346 goto out;
338 } 347 }
339 } 348 }
340 349
341 features = dasd_feature_list(features_str); 350 features = dasd_feature_list(features_str);
342 if (features < 0) 351 if (features < 0) {
343 goto out_err; 352 rc = -EINVAL;
353 goto out;
354 }
344 /* each device in dasd= parameter should be set initially online */ 355 /* each device in dasd= parameter should be set initially online */
345 features |= DASD_FEATURE_INITIAL_ONLINE; 356 features |= DASD_FEATURE_INITIAL_ONLINE;
346 while (from <= to) { 357 while (from <= to) {
347 sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++); 358 sprintf(bus_id, "%01x.%01x.%04x", from_id0, from_id1, from++);
348 devmap = dasd_add_busid(bus_id, features); 359 devmap = dasd_add_busid(bus_id, features);
349 if (IS_ERR(devmap)) 360 if (IS_ERR(devmap)) {
350 return PTR_ERR(devmap); 361 rc = PTR_ERR(devmap);
362 goto out;
363 }
351 } 364 }
352 365
353 return 0; 366out:
367 kfree(tmp);
354 368
355out_err: 369 return rc;
356 return -EINVAL;
357} 370}
358 371
359/* 372/*
@@ -735,13 +748,22 @@ static ssize_t
735dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf) 748dasd_ro_show(struct device *dev, struct device_attribute *attr, char *buf)
736{ 749{
737 struct dasd_devmap *devmap; 750 struct dasd_devmap *devmap;
738 int ro_flag; 751 struct dasd_device *device;
752 int ro_flag = 0;
739 753
740 devmap = dasd_find_busid(dev_name(dev)); 754 devmap = dasd_find_busid(dev_name(dev));
741 if (!IS_ERR(devmap)) 755 if (IS_ERR(devmap))
742 ro_flag = (devmap->features & DASD_FEATURE_READONLY) != 0; 756 goto out;
743 else 757
744 ro_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_READONLY) != 0; 758 ro_flag = !!(devmap->features & DASD_FEATURE_READONLY);
759
760 spin_lock(&dasd_devmap_lock);
761 device = devmap->device;
762 if (device)
763 ro_flag |= test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
764 spin_unlock(&dasd_devmap_lock);
765
766out:
745 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n"); 767 return snprintf(buf, PAGE_SIZE, ro_flag ? "1\n" : "0\n");
746} 768}
747 769
@@ -764,7 +786,7 @@ dasd_ro_store(struct device *dev, struct device_attribute *attr,
764 786
765 device = dasd_device_from_cdev(cdev); 787 device = dasd_device_from_cdev(cdev);
766 if (IS_ERR(device)) 788 if (IS_ERR(device))
767 return PTR_ERR(device); 789 return count;
768 790
769 spin_lock_irqsave(get_ccwdev_lock(cdev), flags); 791 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
770 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); 792 val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
@@ -928,11 +950,14 @@ dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
928{ 950{
929 struct ccw_device *cdev = to_ccwdev(dev); 951 struct ccw_device *cdev = to_ccwdev(dev);
930 struct dasd_device *device; 952 struct dasd_device *device;
953 unsigned long flags;
931 int rc; 954 int rc;
932 955
933 device = dasd_device_from_cdev(cdev); 956 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
957 device = dasd_device_from_cdev_locked(cdev);
934 if (IS_ERR(device)) { 958 if (IS_ERR(device)) {
935 rc = PTR_ERR(device); 959 rc = PTR_ERR(device);
960 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
936 goto out; 961 goto out;
937 } 962 }
938 963
@@ -940,12 +965,14 @@ dasd_safe_offline_store(struct device *dev, struct device_attribute *attr,
940 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) { 965 test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
941 /* Already doing offline processing */ 966 /* Already doing offline processing */
942 dasd_put_device(device); 967 dasd_put_device(device);
968 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
943 rc = -EBUSY; 969 rc = -EBUSY;
944 goto out; 970 goto out;
945 } 971 }
946 972
947 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags); 973 set_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags);
948 dasd_put_device(device); 974 dasd_put_device(device);
975 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
949 976
950 rc = ccw_device_set_offline(cdev); 977 rc = ccw_device_set_offline(cdev);
951 978
diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c
index 3c2c84b72877..42018a20f2b7 100644
--- a/drivers/s390/block/scm_blk.c
+++ b/drivers/s390/block/scm_blk.c
@@ -13,6 +13,7 @@
13#include <linux/mempool.h> 13#include <linux/mempool.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/blk-mq.h>
16#include <linux/genhd.h> 17#include <linux/genhd.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/list.h> 19#include <linux/list.h>
@@ -42,7 +43,6 @@ static void __scm_free_rq(struct scm_request *scmrq)
42 struct aob_rq_header *aobrq = to_aobrq(scmrq); 43 struct aob_rq_header *aobrq = to_aobrq(scmrq);
43 44
44 free_page((unsigned long) scmrq->aob); 45 free_page((unsigned long) scmrq->aob);
45 __scm_free_rq_cluster(scmrq);
46 kfree(scmrq->request); 46 kfree(scmrq->request);
47 kfree(aobrq); 47 kfree(aobrq);
48} 48}
@@ -82,9 +82,6 @@ static int __scm_alloc_rq(void)
82 if (!scmrq->request) 82 if (!scmrq->request)
83 goto free; 83 goto free;
84 84
85 if (__scm_alloc_rq_cluster(scmrq))
86 goto free;
87
88 INIT_LIST_HEAD(&scmrq->list); 85 INIT_LIST_HEAD(&scmrq->list);
89 spin_lock_irq(&list_lock); 86 spin_lock_irq(&list_lock);
90 list_add(&scmrq->list, &inactive_requests); 87 list_add(&scmrq->list, &inactive_requests);
@@ -114,13 +111,13 @@ static struct scm_request *scm_request_fetch(void)
114{ 111{
115 struct scm_request *scmrq = NULL; 112 struct scm_request *scmrq = NULL;
116 113
117 spin_lock(&list_lock); 114 spin_lock_irq(&list_lock);
118 if (list_empty(&inactive_requests)) 115 if (list_empty(&inactive_requests))
119 goto out; 116 goto out;
120 scmrq = list_first_entry(&inactive_requests, struct scm_request, list); 117 scmrq = list_first_entry(&inactive_requests, struct scm_request, list);
121 list_del(&scmrq->list); 118 list_del(&scmrq->list);
122out: 119out:
123 spin_unlock(&list_lock); 120 spin_unlock_irq(&list_lock);
124 return scmrq; 121 return scmrq;
125} 122}
126 123
@@ -234,130 +231,123 @@ static inline void scm_request_init(struct scm_blk_dev *bdev,
234 scmrq->error = BLK_STS_OK; 231 scmrq->error = BLK_STS_OK;
235 /* We don't use all msbs - place aidaws at the end of the aob page. */ 232 /* We don't use all msbs - place aidaws at the end of the aob page. */
236 scmrq->next_aidaw = (void *) &aob->msb[nr_requests_per_io]; 233 scmrq->next_aidaw = (void *) &aob->msb[nr_requests_per_io];
237 scm_request_cluster_init(scmrq);
238} 234}
239 235
240static void scm_ensure_queue_restart(struct scm_blk_dev *bdev) 236static void scm_request_requeue(struct scm_request *scmrq)
241{
242 if (atomic_read(&bdev->queued_reqs)) {
243 /* Queue restart is triggered by the next interrupt. */
244 return;
245 }
246 blk_delay_queue(bdev->rq, SCM_QUEUE_DELAY);
247}
248
249void scm_request_requeue(struct scm_request *scmrq)
250{ 237{
251 struct scm_blk_dev *bdev = scmrq->bdev; 238 struct scm_blk_dev *bdev = scmrq->bdev;
252 int i; 239 int i;
253 240
254 scm_release_cluster(scmrq);
255 for (i = 0; i < nr_requests_per_io && scmrq->request[i]; i++) 241 for (i = 0; i < nr_requests_per_io && scmrq->request[i]; i++)
256 blk_requeue_request(bdev->rq, scmrq->request[i]); 242 blk_mq_requeue_request(scmrq->request[i], false);
257 243
258 atomic_dec(&bdev->queued_reqs); 244 atomic_dec(&bdev->queued_reqs);
259 scm_request_done(scmrq); 245 scm_request_done(scmrq);
260 scm_ensure_queue_restart(bdev); 246 blk_mq_kick_requeue_list(bdev->rq);
261} 247}
262 248
263void scm_request_finish(struct scm_request *scmrq) 249static void scm_request_finish(struct scm_request *scmrq)
264{ 250{
265 struct scm_blk_dev *bdev = scmrq->bdev; 251 struct scm_blk_dev *bdev = scmrq->bdev;
266 int i; 252 int i;
267 253
268 scm_release_cluster(scmrq); 254 for (i = 0; i < nr_requests_per_io && scmrq->request[i]; i++) {
269 for (i = 0; i < nr_requests_per_io && scmrq->request[i]; i++) 255 if (scmrq->error)
270 blk_end_request_all(scmrq->request[i], scmrq->error); 256 blk_mq_end_request(scmrq->request[i], scmrq->error);
257 else
258 blk_mq_complete_request(scmrq->request[i]);
259 }
271 260
272 atomic_dec(&bdev->queued_reqs); 261 atomic_dec(&bdev->queued_reqs);
273 scm_request_done(scmrq); 262 scm_request_done(scmrq);
274} 263}
275 264
276static int scm_request_start(struct scm_request *scmrq) 265static void scm_request_start(struct scm_request *scmrq)
277{ 266{
278 struct scm_blk_dev *bdev = scmrq->bdev; 267 struct scm_blk_dev *bdev = scmrq->bdev;
279 int ret;
280 268
281 atomic_inc(&bdev->queued_reqs); 269 atomic_inc(&bdev->queued_reqs);
282 if (!scmrq->aob->request.msb_count) { 270 if (eadm_start_aob(scmrq->aob)) {
283 scm_request_requeue(scmrq);
284 return -EINVAL;
285 }
286
287 ret = eadm_start_aob(scmrq->aob);
288 if (ret) {
289 SCM_LOG(5, "no subchannel"); 271 SCM_LOG(5, "no subchannel");
290 scm_request_requeue(scmrq); 272 scm_request_requeue(scmrq);
291 } 273 }
292 return ret;
293} 274}
294 275
295static void scm_blk_request(struct request_queue *rq) 276struct scm_queue {
277 struct scm_request *scmrq;
278 spinlock_t lock;
279};
280
281static int scm_blk_request(struct blk_mq_hw_ctx *hctx,
282 const struct blk_mq_queue_data *qd)
296{ 283{
297 struct scm_device *scmdev = rq->queuedata; 284 struct scm_device *scmdev = hctx->queue->queuedata;
298 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev); 285 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
299 struct scm_request *scmrq = NULL; 286 struct scm_queue *sq = hctx->driver_data;
300 struct request *req; 287 struct request *req = qd->rq;
288 struct scm_request *scmrq;
301 289
302 while ((req = blk_peek_request(rq))) { 290 spin_lock(&sq->lock);
303 if (!scm_permit_request(bdev, req)) 291 if (!scm_permit_request(bdev, req)) {
304 goto out; 292 spin_unlock(&sq->lock);
293 return BLK_MQ_RQ_QUEUE_BUSY;
294 }
305 295
296 scmrq = sq->scmrq;
297 if (!scmrq) {
298 scmrq = scm_request_fetch();
306 if (!scmrq) { 299 if (!scmrq) {
307 scmrq = scm_request_fetch(); 300 SCM_LOG(5, "no request");
308 if (!scmrq) { 301 spin_unlock(&sq->lock);
309 SCM_LOG(5, "no request"); 302 return BLK_MQ_RQ_QUEUE_BUSY;
310 goto out;
311 }
312 scm_request_init(bdev, scmrq);
313 } 303 }
314 scm_request_set(scmrq, req); 304 scm_request_init(bdev, scmrq);
305 sq->scmrq = scmrq;
306 }
307 scm_request_set(scmrq, req);
315 308
316 if (!scm_reserve_cluster(scmrq)) { 309 if (scm_request_prepare(scmrq)) {
317 SCM_LOG(5, "cluster busy"); 310 SCM_LOG(5, "aidaw alloc failed");
318 scm_request_set(scmrq, NULL); 311 scm_request_set(scmrq, NULL);
319 if (scmrq->aob->request.msb_count)
320 goto out;
321 312
322 scm_request_done(scmrq); 313 if (scmrq->aob->request.msb_count)
323 return; 314 scm_request_start(scmrq);
324 }
325 315
326 if (scm_need_cluster_request(scmrq)) { 316 sq->scmrq = NULL;
327 if (scmrq->aob->request.msb_count) { 317 spin_unlock(&sq->lock);
328 /* Start cluster requests separately. */ 318 return BLK_MQ_RQ_QUEUE_BUSY;
329 scm_request_set(scmrq, NULL); 319 }
330 if (scm_request_start(scmrq)) 320 blk_mq_start_request(req);
331 return;
332 } else {
333 atomic_inc(&bdev->queued_reqs);
334 blk_start_request(req);
335 scm_initiate_cluster_request(scmrq);
336 }
337 scmrq = NULL;
338 continue;
339 }
340 321
341 if (scm_request_prepare(scmrq)) { 322 if (qd->last || scmrq->aob->request.msb_count == nr_requests_per_io) {
342 SCM_LOG(5, "aidaw alloc failed"); 323 scm_request_start(scmrq);
343 scm_request_set(scmrq, NULL); 324 sq->scmrq = NULL;
344 goto out; 325 }
345 } 326 spin_unlock(&sq->lock);
346 blk_start_request(req); 327 return BLK_MQ_RQ_QUEUE_OK;
328}
347 329
348 if (scmrq->aob->request.msb_count < nr_requests_per_io) 330static int scm_blk_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
349 continue; 331 unsigned int idx)
332{
333 struct scm_queue *qd = kzalloc(sizeof(*qd), GFP_KERNEL);
350 334
351 if (scm_request_start(scmrq)) 335 if (!qd)
352 return; 336 return -ENOMEM;
353 337
354 scmrq = NULL; 338 spin_lock_init(&qd->lock);
355 } 339 hctx->driver_data = qd;
356out: 340
357 if (scmrq) 341 return 0;
358 scm_request_start(scmrq); 342}
359 else 343
360 scm_ensure_queue_restart(bdev); 344static void scm_blk_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
345{
346 struct scm_queue *qd = hctx->driver_data;
347
348 WARN_ON(qd->scmrq);
349 kfree(hctx->driver_data);
350 hctx->driver_data = NULL;
361} 351}
362 352
363static void __scmrq_log_error(struct scm_request *scmrq) 353static void __scmrq_log_error(struct scm_request *scmrq)
@@ -377,21 +367,6 @@ static void __scmrq_log_error(struct scm_request *scmrq)
377 scmrq->error); 367 scmrq->error);
378} 368}
379 369
380void scm_blk_irq(struct scm_device *scmdev, void *data, blk_status_t error)
381{
382 struct scm_request *scmrq = data;
383 struct scm_blk_dev *bdev = scmrq->bdev;
384
385 scmrq->error = error;
386 if (error)
387 __scmrq_log_error(scmrq);
388
389 spin_lock(&bdev->lock);
390 list_add_tail(&scmrq->list, &bdev->finished_requests);
391 spin_unlock(&bdev->lock);
392 tasklet_hi_schedule(&bdev->tasklet);
393}
394
395static void scm_blk_handle_error(struct scm_request *scmrq) 370static void scm_blk_handle_error(struct scm_request *scmrq)
396{ 371{
397 struct scm_blk_dev *bdev = scmrq->bdev; 372 struct scm_blk_dev *bdev = scmrq->bdev;
@@ -419,54 +394,46 @@ restart:
419 return; 394 return;
420 395
421requeue: 396requeue:
422 spin_lock_irqsave(&bdev->rq_lock, flags);
423 scm_request_requeue(scmrq); 397 scm_request_requeue(scmrq);
424 spin_unlock_irqrestore(&bdev->rq_lock, flags);
425} 398}
426 399
427static void scm_blk_tasklet(struct scm_blk_dev *bdev) 400void scm_blk_irq(struct scm_device *scmdev, void *data, blk_status_t error)
428{ 401{
429 struct scm_request *scmrq; 402 struct scm_request *scmrq = data;
430 unsigned long flags;
431
432 spin_lock_irqsave(&bdev->lock, flags);
433 while (!list_empty(&bdev->finished_requests)) {
434 scmrq = list_first_entry(&bdev->finished_requests,
435 struct scm_request, list);
436 list_del(&scmrq->list);
437 spin_unlock_irqrestore(&bdev->lock, flags);
438 403
439 if (scmrq->error && scmrq->retries-- > 0) { 404 scmrq->error = error;
405 if (error) {
406 __scmrq_log_error(scmrq);
407 if (scmrq->retries-- > 0) {
440 scm_blk_handle_error(scmrq); 408 scm_blk_handle_error(scmrq);
441 409 return;
442 /* Request restarted or requeued, handle next. */
443 spin_lock_irqsave(&bdev->lock, flags);
444 continue;
445 } 410 }
411 }
446 412
447 if (scm_test_cluster_request(scmrq)) { 413 scm_request_finish(scmrq);
448 scm_cluster_request_irq(scmrq); 414}
449 spin_lock_irqsave(&bdev->lock, flags);
450 continue;
451 }
452 415
453 scm_request_finish(scmrq); 416static void scm_blk_request_done(struct request *req)
454 spin_lock_irqsave(&bdev->lock, flags); 417{
455 } 418 blk_mq_end_request(req, 0);
456 spin_unlock_irqrestore(&bdev->lock, flags);
457 /* Look out for more requests. */
458 blk_run_queue(bdev->rq);
459} 419}
460 420
461static const struct block_device_operations scm_blk_devops = { 421static const struct block_device_operations scm_blk_devops = {
462 .owner = THIS_MODULE, 422 .owner = THIS_MODULE,
463}; 423};
464 424
425static const struct blk_mq_ops scm_mq_ops = {
426 .queue_rq = scm_blk_request,
427 .complete = scm_blk_request_done,
428 .init_hctx = scm_blk_init_hctx,
429 .exit_hctx = scm_blk_exit_hctx,
430};
431
465int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev) 432int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
466{ 433{
467 struct request_queue *rq;
468 int len, ret = -ENOMEM;
469 unsigned int devindex, nr_max_blk; 434 unsigned int devindex, nr_max_blk;
435 struct request_queue *rq;
436 int len, ret;
470 437
471 devindex = atomic_inc_return(&nr_devices) - 1; 438 devindex = atomic_inc_return(&nr_devices) - 1;
472 /* scma..scmz + scmaa..scmzz */ 439 /* scma..scmz + scmaa..scmzz */
@@ -477,18 +444,23 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
477 444
478 bdev->scmdev = scmdev; 445 bdev->scmdev = scmdev;
479 bdev->state = SCM_OPER; 446 bdev->state = SCM_OPER;
480 spin_lock_init(&bdev->rq_lock);
481 spin_lock_init(&bdev->lock); 447 spin_lock_init(&bdev->lock);
482 INIT_LIST_HEAD(&bdev->finished_requests);
483 atomic_set(&bdev->queued_reqs, 0); 448 atomic_set(&bdev->queued_reqs, 0);
484 tasklet_init(&bdev->tasklet,
485 (void (*)(unsigned long)) scm_blk_tasklet,
486 (unsigned long) bdev);
487 449
488 rq = blk_init_queue(scm_blk_request, &bdev->rq_lock); 450 bdev->tag_set.ops = &scm_mq_ops;
489 if (!rq) 451 bdev->tag_set.nr_hw_queues = nr_requests;
452 bdev->tag_set.queue_depth = nr_requests_per_io * nr_requests;
453 bdev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
454
455 ret = blk_mq_alloc_tag_set(&bdev->tag_set);
456 if (ret)
490 goto out; 457 goto out;
491 458
459 rq = blk_mq_init_queue(&bdev->tag_set);
460 if (IS_ERR(rq)) {
461 ret = PTR_ERR(rq);
462 goto out_tag;
463 }
492 bdev->rq = rq; 464 bdev->rq = rq;
493 nr_max_blk = min(scmdev->nr_max_block, 465 nr_max_blk = min(scmdev->nr_max_block,
494 (unsigned int) (PAGE_SIZE / sizeof(struct aidaw))); 466 (unsigned int) (PAGE_SIZE / sizeof(struct aidaw)));
@@ -498,12 +470,12 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
498 blk_queue_max_segments(rq, nr_max_blk); 470 blk_queue_max_segments(rq, nr_max_blk);
499 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, rq); 471 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, rq);
500 queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, rq); 472 queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, rq);
501 scm_blk_dev_cluster_setup(bdev);
502 473
503 bdev->gendisk = alloc_disk(SCM_NR_PARTS); 474 bdev->gendisk = alloc_disk(SCM_NR_PARTS);
504 if (!bdev->gendisk) 475 if (!bdev->gendisk) {
476 ret = -ENOMEM;
505 goto out_queue; 477 goto out_queue;
506 478 }
507 rq->queuedata = scmdev; 479 rq->queuedata = scmdev;
508 bdev->gendisk->private_data = scmdev; 480 bdev->gendisk->private_data = scmdev;
509 bdev->gendisk->fops = &scm_blk_devops; 481 bdev->gendisk->fops = &scm_blk_devops;
@@ -528,6 +500,8 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
528 500
529out_queue: 501out_queue:
530 blk_cleanup_queue(rq); 502 blk_cleanup_queue(rq);
503out_tag:
504 blk_mq_free_tag_set(&bdev->tag_set);
531out: 505out:
532 atomic_dec(&nr_devices); 506 atomic_dec(&nr_devices);
533 return ret; 507 return ret;
@@ -535,9 +509,9 @@ out:
535 509
536void scm_blk_dev_cleanup(struct scm_blk_dev *bdev) 510void scm_blk_dev_cleanup(struct scm_blk_dev *bdev)
537{ 511{
538 tasklet_kill(&bdev->tasklet);
539 del_gendisk(bdev->gendisk); 512 del_gendisk(bdev->gendisk);
540 blk_cleanup_queue(bdev->gendisk->queue); 513 blk_cleanup_queue(bdev->gendisk->queue);
514 blk_mq_free_tag_set(&bdev->tag_set);
541 put_disk(bdev->gendisk); 515 put_disk(bdev->gendisk);
542} 516}
543 517
@@ -558,7 +532,7 @@ static bool __init scm_blk_params_valid(void)
558 if (!nr_requests_per_io || nr_requests_per_io > 64) 532 if (!nr_requests_per_io || nr_requests_per_io > 64)
559 return false; 533 return false;
560 534
561 return scm_cluster_size_valid(); 535 return true;
562} 536}
563 537
564static int __init scm_blk_init(void) 538static int __init scm_blk_init(void)
diff --git a/drivers/s390/block/scm_blk.h b/drivers/s390/block/scm_blk.h
index cd598d1a4eae..71288dd9dd7f 100644
--- a/drivers/s390/block/scm_blk.h
+++ b/drivers/s390/block/scm_blk.h
@@ -4,6 +4,7 @@
4#include <linux/interrupt.h> 4#include <linux/interrupt.h>
5#include <linux/spinlock.h> 5#include <linux/spinlock.h>
6#include <linux/blkdev.h> 6#include <linux/blkdev.h>
7#include <linux/blk-mq.h>
7#include <linux/genhd.h> 8#include <linux/genhd.h>
8#include <linux/list.h> 9#include <linux/list.h>
9 10
@@ -14,18 +15,14 @@
14#define SCM_QUEUE_DELAY 5 15#define SCM_QUEUE_DELAY 5
15 16
16struct scm_blk_dev { 17struct scm_blk_dev {
17 struct tasklet_struct tasklet;
18 struct request_queue *rq; 18 struct request_queue *rq;
19 struct gendisk *gendisk; 19 struct gendisk *gendisk;
20 struct blk_mq_tag_set tag_set;
20 struct scm_device *scmdev; 21 struct scm_device *scmdev;
21 spinlock_t rq_lock; /* guard the request queue */ 22 spinlock_t lock;
22 spinlock_t lock; /* guard the rest of the blockdev */
23 atomic_t queued_reqs; 23 atomic_t queued_reqs;
24 enum {SCM_OPER, SCM_WR_PROHIBIT} state; 24 enum {SCM_OPER, SCM_WR_PROHIBIT} state;
25 struct list_head finished_requests; 25 struct list_head finished_requests;
26#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
27 struct list_head cluster_list;
28#endif
29}; 26};
30 27
31struct scm_request { 28struct scm_request {
@@ -36,13 +33,6 @@ struct scm_request {
36 struct list_head list; 33 struct list_head list;
37 u8 retries; 34 u8 retries;
38 blk_status_t error; 35 blk_status_t error;
39#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
40 struct {
41 enum {CLUSTER_NONE, CLUSTER_READ, CLUSTER_WRITE} state;
42 struct list_head list;
43 void **buf;
44 } cluster;
45#endif
46}; 36};
47 37
48#define to_aobrq(rq) container_of((void *) rq, struct aob_rq_header, data) 38#define to_aobrq(rq) container_of((void *) rq, struct aob_rq_header, data)
@@ -52,55 +42,11 @@ void scm_blk_dev_cleanup(struct scm_blk_dev *);
52void scm_blk_set_available(struct scm_blk_dev *); 42void scm_blk_set_available(struct scm_blk_dev *);
53void scm_blk_irq(struct scm_device *, void *, blk_status_t); 43void scm_blk_irq(struct scm_device *, void *, blk_status_t);
54 44
55void scm_request_finish(struct scm_request *);
56void scm_request_requeue(struct scm_request *);
57
58struct aidaw *scm_aidaw_fetch(struct scm_request *scmrq, unsigned int bytes); 45struct aidaw *scm_aidaw_fetch(struct scm_request *scmrq, unsigned int bytes);
59 46
60int scm_drv_init(void); 47int scm_drv_init(void);
61void scm_drv_cleanup(void); 48void scm_drv_cleanup(void);
62 49
63#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
64void __scm_free_rq_cluster(struct scm_request *);
65int __scm_alloc_rq_cluster(struct scm_request *);
66void scm_request_cluster_init(struct scm_request *);
67bool scm_reserve_cluster(struct scm_request *);
68void scm_release_cluster(struct scm_request *);
69void scm_blk_dev_cluster_setup(struct scm_blk_dev *);
70bool scm_need_cluster_request(struct scm_request *);
71void scm_initiate_cluster_request(struct scm_request *);
72void scm_cluster_request_irq(struct scm_request *);
73bool scm_test_cluster_request(struct scm_request *);
74bool scm_cluster_size_valid(void);
75#else /* CONFIG_SCM_BLOCK_CLUSTER_WRITE */
76static inline void __scm_free_rq_cluster(struct scm_request *scmrq) {}
77static inline int __scm_alloc_rq_cluster(struct scm_request *scmrq)
78{
79 return 0;
80}
81static inline void scm_request_cluster_init(struct scm_request *scmrq) {}
82static inline bool scm_reserve_cluster(struct scm_request *scmrq)
83{
84 return true;
85}
86static inline void scm_release_cluster(struct scm_request *scmrq) {}
87static inline void scm_blk_dev_cluster_setup(struct scm_blk_dev *bdev) {}
88static inline bool scm_need_cluster_request(struct scm_request *scmrq)
89{
90 return false;
91}
92static inline void scm_initiate_cluster_request(struct scm_request *scmrq) {}
93static inline void scm_cluster_request_irq(struct scm_request *scmrq) {}
94static inline bool scm_test_cluster_request(struct scm_request *scmrq)
95{
96 return false;
97}
98static inline bool scm_cluster_size_valid(void)
99{
100 return true;
101}
102#endif /* CONFIG_SCM_BLOCK_CLUSTER_WRITE */
103
104extern debug_info_t *scm_debug; 50extern debug_info_t *scm_debug;
105 51
106#define SCM_LOG(imp, txt) do { \ 52#define SCM_LOG(imp, txt) do { \
diff --git a/drivers/s390/block/scm_blk_cluster.c b/drivers/s390/block/scm_blk_cluster.c
deleted file mode 100644
index 7497ddde2dd6..000000000000
--- a/drivers/s390/block/scm_blk_cluster.c
+++ /dev/null
@@ -1,255 +0,0 @@
1/*
2 * Block driver for s390 storage class memory.
3 *
4 * Copyright IBM Corp. 2012
5 * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
6 */
7
8#include <linux/spinlock.h>
9#include <linux/module.h>
10#include <linux/blkdev.h>
11#include <linux/genhd.h>
12#include <linux/slab.h>
13#include <linux/list.h>
14#include <asm/eadm.h>
15#include "scm_blk.h"
16
17static unsigned int write_cluster_size = 64;
18module_param(write_cluster_size, uint, S_IRUGO);
19MODULE_PARM_DESC(write_cluster_size,
20 "Number of pages used for contiguous writes.");
21
22#define CLUSTER_SIZE (write_cluster_size * PAGE_SIZE)
23
24void __scm_free_rq_cluster(struct scm_request *scmrq)
25{
26 int i;
27
28 if (!scmrq->cluster.buf)
29 return;
30
31 for (i = 0; i < 2 * write_cluster_size; i++)
32 free_page((unsigned long) scmrq->cluster.buf[i]);
33
34 kfree(scmrq->cluster.buf);
35}
36
37int __scm_alloc_rq_cluster(struct scm_request *scmrq)
38{
39 int i;
40
41 scmrq->cluster.buf = kzalloc(sizeof(void *) * 2 * write_cluster_size,
42 GFP_KERNEL);
43 if (!scmrq->cluster.buf)
44 return -ENOMEM;
45
46 for (i = 0; i < 2 * write_cluster_size; i++) {
47 scmrq->cluster.buf[i] = (void *) get_zeroed_page(GFP_DMA);
48 if (!scmrq->cluster.buf[i])
49 return -ENOMEM;
50 }
51 INIT_LIST_HEAD(&scmrq->cluster.list);
52 return 0;
53}
54
55void scm_request_cluster_init(struct scm_request *scmrq)
56{
57 scmrq->cluster.state = CLUSTER_NONE;
58}
59
60static bool clusters_intersect(struct request *A, struct request *B)
61{
62 unsigned long firstA, lastA, firstB, lastB;
63
64 firstA = ((u64) blk_rq_pos(A) << 9) / CLUSTER_SIZE;
65 lastA = (((u64) blk_rq_pos(A) << 9) +
66 blk_rq_bytes(A) - 1) / CLUSTER_SIZE;
67
68 firstB = ((u64) blk_rq_pos(B) << 9) / CLUSTER_SIZE;
69 lastB = (((u64) blk_rq_pos(B) << 9) +
70 blk_rq_bytes(B) - 1) / CLUSTER_SIZE;
71
72 return (firstB <= lastA && firstA <= lastB);
73}
74
75bool scm_reserve_cluster(struct scm_request *scmrq)
76{
77 struct request *req = scmrq->request[scmrq->aob->request.msb_count];
78 struct scm_blk_dev *bdev = scmrq->bdev;
79 struct scm_request *iter;
80 int pos, add = 1;
81
82 if (write_cluster_size == 0)
83 return true;
84
85 spin_lock(&bdev->lock);
86 list_for_each_entry(iter, &bdev->cluster_list, cluster.list) {
87 if (iter == scmrq) {
88 /*
89 * We don't have to use clusters_intersect here, since
90 * cluster requests are always started separately.
91 */
92 add = 0;
93 continue;
94 }
95 for (pos = 0; pos < iter->aob->request.msb_count; pos++) {
96 if (clusters_intersect(req, iter->request[pos]) &&
97 (rq_data_dir(req) == WRITE ||
98 rq_data_dir(iter->request[pos]) == WRITE)) {
99 spin_unlock(&bdev->lock);
100 return false;
101 }
102 }
103 }
104 if (add)
105 list_add(&scmrq->cluster.list, &bdev->cluster_list);
106 spin_unlock(&bdev->lock);
107
108 return true;
109}
110
111void scm_release_cluster(struct scm_request *scmrq)
112{
113 struct scm_blk_dev *bdev = scmrq->bdev;
114 unsigned long flags;
115
116 if (write_cluster_size == 0)
117 return;
118
119 spin_lock_irqsave(&bdev->lock, flags);
120 list_del(&scmrq->cluster.list);
121 spin_unlock_irqrestore(&bdev->lock, flags);
122}
123
124void scm_blk_dev_cluster_setup(struct scm_blk_dev *bdev)
125{
126 INIT_LIST_HEAD(&bdev->cluster_list);
127 blk_queue_io_opt(bdev->rq, CLUSTER_SIZE);
128}
129
130static int scm_prepare_cluster_request(struct scm_request *scmrq)
131{
132 struct scm_blk_dev *bdev = scmrq->bdev;
133 struct scm_device *scmdev = bdev->gendisk->private_data;
134 struct request *req = scmrq->request[0];
135 struct msb *msb = &scmrq->aob->msb[0];
136 struct req_iterator iter;
137 struct aidaw *aidaw;
138 struct bio_vec bv;
139 int i = 0;
140 u64 addr;
141
142 switch (scmrq->cluster.state) {
143 case CLUSTER_NONE:
144 scmrq->cluster.state = CLUSTER_READ;
145 /* fall through */
146 case CLUSTER_READ:
147 msb->bs = MSB_BS_4K;
148 msb->oc = MSB_OC_READ;
149 msb->flags = MSB_FLAG_IDA;
150 msb->blk_count = write_cluster_size;
151
152 addr = scmdev->address + ((u64) blk_rq_pos(req) << 9);
153 msb->scm_addr = round_down(addr, CLUSTER_SIZE);
154
155 if (msb->scm_addr !=
156 round_down(addr + (u64) blk_rq_bytes(req) - 1,
157 CLUSTER_SIZE))
158 msb->blk_count = 2 * write_cluster_size;
159
160 aidaw = scm_aidaw_fetch(scmrq, msb->blk_count * PAGE_SIZE);
161 if (!aidaw)
162 return -ENOMEM;
163
164 scmrq->aob->request.msb_count = 1;
165 msb->data_addr = (u64) aidaw;
166 for (i = 0; i < msb->blk_count; i++) {
167 aidaw->data_addr = (u64) scmrq->cluster.buf[i];
168 aidaw++;
169 }
170
171 break;
172 case CLUSTER_WRITE:
173 aidaw = (void *) msb->data_addr;
174 msb->oc = MSB_OC_WRITE;
175
176 for (addr = msb->scm_addr;
177 addr < scmdev->address + ((u64) blk_rq_pos(req) << 9);
178 addr += PAGE_SIZE) {
179 aidaw->data_addr = (u64) scmrq->cluster.buf[i];
180 aidaw++;
181 i++;
182 }
183 rq_for_each_segment(bv, req, iter) {
184 aidaw->data_addr = (u64) page_address(bv.bv_page);
185 aidaw++;
186 i++;
187 }
188 for (; i < msb->blk_count; i++) {
189 aidaw->data_addr = (u64) scmrq->cluster.buf[i];
190 aidaw++;
191 }
192 break;
193 }
194 return 0;
195}
196
197bool scm_need_cluster_request(struct scm_request *scmrq)
198{
199 int pos = scmrq->aob->request.msb_count;
200
201 if (rq_data_dir(scmrq->request[pos]) == READ)
202 return false;
203
204 return blk_rq_bytes(scmrq->request[pos]) < CLUSTER_SIZE;
205}
206
207/* Called with queue lock held. */
208void scm_initiate_cluster_request(struct scm_request *scmrq)
209{
210 if (scm_prepare_cluster_request(scmrq))
211 goto requeue;
212 if (eadm_start_aob(scmrq->aob))
213 goto requeue;
214 return;
215requeue:
216 scm_request_requeue(scmrq);
217}
218
219bool scm_test_cluster_request(struct scm_request *scmrq)
220{
221 return scmrq->cluster.state != CLUSTER_NONE;
222}
223
224void scm_cluster_request_irq(struct scm_request *scmrq)
225{
226 struct scm_blk_dev *bdev = scmrq->bdev;
227 unsigned long flags;
228
229 switch (scmrq->cluster.state) {
230 case CLUSTER_NONE:
231 BUG();
232 break;
233 case CLUSTER_READ:
234 if (scmrq->error) {
235 scm_request_finish(scmrq);
236 break;
237 }
238 scmrq->cluster.state = CLUSTER_WRITE;
239 spin_lock_irqsave(&bdev->rq_lock, flags);
240 scm_initiate_cluster_request(scmrq);
241 spin_unlock_irqrestore(&bdev->rq_lock, flags);
242 break;
243 case CLUSTER_WRITE:
244 scm_request_finish(scmrq);
245 break;
246 }
247}
248
249bool scm_cluster_size_valid(void)
250{
251 if (write_cluster_size == 1 || write_cluster_size > 128)
252 return false;
253
254 return !(write_cluster_size & (write_cluster_size - 1));
255}
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index e2aa944eb566..d3e504c3c362 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -296,6 +296,51 @@ static const struct attribute_group *default_subch_attr_groups[] = {
296 NULL, 296 NULL,
297}; 297};
298 298
299static ssize_t chpids_show(struct device *dev,
300 struct device_attribute *attr,
301 char *buf)
302{
303 struct subchannel *sch = to_subchannel(dev);
304 struct chsc_ssd_info *ssd = &sch->ssd_info;
305 ssize_t ret = 0;
306 int mask;
307 int chp;
308
309 for (chp = 0; chp < 8; chp++) {
310 mask = 0x80 >> chp;
311 if (ssd->path_mask & mask)
312 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
313 else
314 ret += sprintf(buf + ret, "00 ");
315 }
316 ret += sprintf(buf + ret, "\n");
317 return ret;
318}
319static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
320
321static ssize_t pimpampom_show(struct device *dev,
322 struct device_attribute *attr,
323 char *buf)
324{
325 struct subchannel *sch = to_subchannel(dev);
326 struct pmcw *pmcw = &sch->schib.pmcw;
327
328 return sprintf(buf, "%02x %02x %02x\n",
329 pmcw->pim, pmcw->pam, pmcw->pom);
330}
331static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
332
333static struct attribute *io_subchannel_type_attrs[] = {
334 &dev_attr_chpids.attr,
335 &dev_attr_pimpampom.attr,
336 NULL,
337};
338ATTRIBUTE_GROUPS(io_subchannel_type);
339
340static const struct device_type io_subchannel_type = {
341 .groups = io_subchannel_type_groups,
342};
343
299int css_register_subchannel(struct subchannel *sch) 344int css_register_subchannel(struct subchannel *sch)
300{ 345{
301 int ret; 346 int ret;
@@ -304,6 +349,10 @@ int css_register_subchannel(struct subchannel *sch)
304 sch->dev.parent = &channel_subsystems[0]->device; 349 sch->dev.parent = &channel_subsystems[0]->device;
305 sch->dev.bus = &css_bus_type; 350 sch->dev.bus = &css_bus_type;
306 sch->dev.groups = default_subch_attr_groups; 351 sch->dev.groups = default_subch_attr_groups;
352
353 if (sch->st == SUBCHANNEL_TYPE_IO)
354 sch->dev.type = &io_subchannel_type;
355
307 /* 356 /*
308 * We don't want to generate uevents for I/O subchannels that don't 357 * We don't want to generate uevents for I/O subchannels that don't
309 * have a working ccw device behind them since they will be 358 * have a working ccw device behind them since they will be
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index b8006ea9099c..7be01a58b44f 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -208,44 +208,6 @@ int __init io_subchannel_init(void)
208 208
209/************************ device handling **************************/ 209/************************ device handling **************************/
210 210
211/*
212 * A ccw_device has some interfaces in sysfs in addition to the
213 * standard ones.
214 * The following entries are designed to export the information which
215 * resided in 2.4 in /proc/subchannels. Subchannel and device number
216 * are obvious, so they don't have an entry :)
217 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
218 */
219static ssize_t
220chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
221{
222 struct subchannel *sch = to_subchannel(dev);
223 struct chsc_ssd_info *ssd = &sch->ssd_info;
224 ssize_t ret = 0;
225 int chp;
226 int mask;
227
228 for (chp = 0; chp < 8; chp++) {
229 mask = 0x80 >> chp;
230 if (ssd->path_mask & mask)
231 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
232 else
233 ret += sprintf(buf + ret, "00 ");
234 }
235 ret += sprintf (buf+ret, "\n");
236 return min((ssize_t)PAGE_SIZE, ret);
237}
238
239static ssize_t
240pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
241{
242 struct subchannel *sch = to_subchannel(dev);
243 struct pmcw *pmcw = &sch->schib.pmcw;
244
245 return sprintf (buf, "%02x %02x %02x\n",
246 pmcw->pim, pmcw->pam, pmcw->pom);
247}
248
249static ssize_t 211static ssize_t
250devtype_show (struct device *dev, struct device_attribute *attr, char *buf) 212devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
251{ 213{
@@ -636,8 +598,6 @@ static ssize_t vpm_show(struct device *dev, struct device_attribute *attr,
636 return sprintf(buf, "%02x\n", sch->vpm); 598 return sprintf(buf, "%02x\n", sch->vpm);
637} 599}
638 600
639static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
640static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
641static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); 601static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
642static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); 602static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
643static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); 603static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
@@ -647,8 +607,6 @@ static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
647static DEVICE_ATTR(vpm, 0444, vpm_show, NULL); 607static DEVICE_ATTR(vpm, 0444, vpm_show, NULL);
648 608
649static struct attribute *io_subchannel_attrs[] = { 609static struct attribute *io_subchannel_attrs[] = {
650 &dev_attr_chpids.attr,
651 &dev_attr_pimpampom.attr,
652 &dev_attr_logging.attr, 610 &dev_attr_logging.attr,
653 &dev_attr_vpm.attr, 611 &dev_attr_vpm.attr,
654 NULL, 612 NULL,
diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index e90dd43d2a55..a25367ebaa89 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -90,54 +90,6 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work)
90} 90}
91 91
92/* 92/*
93 * Sysfs interfaces
94 */
95static ssize_t chpids_show(struct device *dev,
96 struct device_attribute *attr,
97 char *buf)
98{
99 struct subchannel *sch = to_subchannel(dev);
100 struct chsc_ssd_info *ssd = &sch->ssd_info;
101 ssize_t ret = 0;
102 int chp;
103 int mask;
104
105 for (chp = 0; chp < 8; chp++) {
106 mask = 0x80 >> chp;
107 if (ssd->path_mask & mask)
108 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
109 else
110 ret += sprintf(buf + ret, "00 ");
111 }
112 ret += sprintf(buf+ret, "\n");
113 return ret;
114}
115
116static ssize_t pimpampom_show(struct device *dev,
117 struct device_attribute *attr,
118 char *buf)
119{
120 struct subchannel *sch = to_subchannel(dev);
121 struct pmcw *pmcw = &sch->schib.pmcw;
122
123 return sprintf(buf, "%02x %02x %02x\n",
124 pmcw->pim, pmcw->pam, pmcw->pom);
125}
126
127static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
128static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
129
130static struct attribute *vfio_subchannel_attrs[] = {
131 &dev_attr_chpids.attr,
132 &dev_attr_pimpampom.attr,
133 NULL,
134};
135
136static struct attribute_group vfio_subchannel_attr_group = {
137 .attrs = vfio_subchannel_attrs,
138};
139
140/*
141 * Css driver callbacks 93 * Css driver callbacks
142 */ 94 */
143static void vfio_ccw_sch_irq(struct subchannel *sch) 95static void vfio_ccw_sch_irq(struct subchannel *sch)
@@ -174,13 +126,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
174 if (ret) 126 if (ret)
175 goto out_free; 127 goto out_free;
176 128
177 ret = sysfs_create_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
178 if (ret)
179 goto out_disable;
180
181 ret = vfio_ccw_mdev_reg(sch); 129 ret = vfio_ccw_mdev_reg(sch);
182 if (ret) 130 if (ret)
183 goto out_rm_group; 131 goto out_disable;
184 132
185 INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); 133 INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo);
186 atomic_set(&private->avail, 1); 134 atomic_set(&private->avail, 1);
@@ -188,8 +136,6 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
188 136
189 return 0; 137 return 0;
190 138
191out_rm_group:
192 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
193out_disable: 139out_disable:
194 cio_disable_subchannel(sch); 140 cio_disable_subchannel(sch);
195out_free: 141out_free:
@@ -206,8 +152,6 @@ static int vfio_ccw_sch_remove(struct subchannel *sch)
206 152
207 vfio_ccw_mdev_unreg(sch); 153 vfio_ccw_mdev_unreg(sch);
208 154
209 sysfs_remove_group(&sch->dev.kobj, &vfio_subchannel_attr_group);
210
211 dev_set_drvdata(&sch->dev, NULL); 155 dev_set_drvdata(&sch->dev, NULL);
212 156
213 kfree(private); 157 kfree(private);
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index ea099910b4e9..6dee598979e7 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -766,7 +766,7 @@ static ssize_t ap_domain_store(struct bus_type *bus,
766 ap_domain_index = domain; 766 ap_domain_index = domain;
767 spin_unlock_bh(&ap_domain_lock); 767 spin_unlock_bh(&ap_domain_lock);
768 768
769 AP_DBF(DBF_DEBUG, "store new default domain=%d\n", domain); 769 AP_DBF(DBF_DEBUG, "stored new default domain=%d\n", domain);
770 770
771 return count; 771 return count;
772} 772}
@@ -952,6 +952,7 @@ static int ap_select_domain(void)
952 } 952 }
953 if (best_domain >= 0){ 953 if (best_domain >= 0){
954 ap_domain_index = best_domain; 954 ap_domain_index = best_domain;
955 AP_DBF(DBF_DEBUG, "new ap_domain_index=%d\n", ap_domain_index);
955 spin_unlock_bh(&ap_domain_lock); 956 spin_unlock_bh(&ap_domain_lock);
956 return 0; 957 return 0;
957 } 958 }
@@ -988,7 +989,7 @@ static void ap_scan_bus(struct work_struct *unused)
988 ap_qid_t qid; 989 ap_qid_t qid;
989 int depth = 0, type = 0; 990 int depth = 0, type = 0;
990 unsigned int functions = 0; 991 unsigned int functions = 0;
991 int rc, id, dom, borked, domains; 992 int rc, id, dom, borked, domains, defdomdevs = 0;
992 993
993 AP_DBF(DBF_DEBUG, "ap_scan_bus running\n"); 994 AP_DBF(DBF_DEBUG, "ap_scan_bus running\n");
994 995
@@ -1052,6 +1053,8 @@ static void ap_scan_bus(struct work_struct *unused)
1052 put_device(dev); 1053 put_device(dev);
1053 if (!borked) { 1054 if (!borked) {
1054 domains++; 1055 domains++;
1056 if (dom == ap_domain_index)
1057 defdomdevs++;
1055 continue; 1058 continue;
1056 } 1059 }
1057 } 1060 }
@@ -1098,6 +1101,8 @@ static void ap_scan_bus(struct work_struct *unused)
1098 continue; 1101 continue;
1099 } 1102 }
1100 domains++; 1103 domains++;
1104 if (dom == ap_domain_index)
1105 defdomdevs++;
1101 } /* end domain loop */ 1106 } /* end domain loop */
1102 if (ac) { 1107 if (ac) {
1103 /* remove card dev if there are no queue devices */ 1108 /* remove card dev if there are no queue devices */
@@ -1106,6 +1111,11 @@ static void ap_scan_bus(struct work_struct *unused)
1106 put_device(&ac->ap_dev.device); 1111 put_device(&ac->ap_dev.device);
1107 } 1112 }
1108 } /* end device loop */ 1113 } /* end device loop */
1114
1115 if (defdomdevs < 1)
1116 AP_DBF(DBF_INFO, "no queue device with default domain %d available\n",
1117 ap_domain_index);
1118
1109out: 1119out:
1110 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ); 1120 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1111} 1121}
@@ -1174,14 +1184,14 @@ int __init ap_module_init(void)
1174 ap_init_configuration(); 1184 ap_init_configuration();
1175 1185
1176 if (ap_configuration) 1186 if (ap_configuration)
1177 max_domain_id = ap_max_domain_id ? : (AP_DOMAINS - 1); 1187 max_domain_id =
1188 ap_max_domain_id ? ap_max_domain_id : AP_DOMAINS - 1;
1178 else 1189 else
1179 max_domain_id = 15; 1190 max_domain_id = 15;
1180 if (ap_domain_index < -1 || ap_domain_index > max_domain_id) { 1191 if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
1181 pr_warn("%d is not a valid cryptographic domain\n", 1192 pr_warn("%d is not a valid cryptographic domain\n",
1182 ap_domain_index); 1193 ap_domain_index);
1183 rc = -EINVAL; 1194 ap_domain_index = -1;
1184 goto out_free;
1185 } 1195 }
1186 /* In resume callback we need to know if the user had set the domain. 1196 /* In resume callback we need to know if the user had set the domain.
1187 * If so, we can not just reset it. 1197 * If so, we can not just reset it.
@@ -1254,7 +1264,6 @@ out:
1254 unregister_reset_call(&ap_reset_call); 1264 unregister_reset_call(&ap_reset_call);
1255 if (ap_using_interrupts()) 1265 if (ap_using_interrupts())
1256 unregister_adapter_interrupt(&ap_airq); 1266 unregister_adapter_interrupt(&ap_airq);
1257out_free:
1258 kfree(ap_configuration); 1267 kfree(ap_configuration);
1259 return rc; 1268 return rc;
1260} 1269}
diff --git a/drivers/s390/crypto/pkey_api.c b/drivers/s390/crypto/pkey_api.c
index ea86da8c75f9..f61fa47135a6 100644
--- a/drivers/s390/crypto/pkey_api.c
+++ b/drivers/s390/crypto/pkey_api.c
@@ -178,9 +178,9 @@ static inline void prep_xcrb(struct ica_xcRB *pxcrb,
178 pxcrb->user_defined = (cardnr == 0xFFFF ? AUTOSELECT : cardnr); 178 pxcrb->user_defined = (cardnr == 0xFFFF ? AUTOSELECT : cardnr);
179 pxcrb->request_control_blk_length = 179 pxcrb->request_control_blk_length =
180 preqcblk->cprb_len + preqcblk->req_parml; 180 preqcblk->cprb_len + preqcblk->req_parml;
181 pxcrb->request_control_blk_addr = (void *) preqcblk; 181 pxcrb->request_control_blk_addr = (void __user *) preqcblk;
182 pxcrb->reply_control_blk_length = preqcblk->rpl_msgbl; 182 pxcrb->reply_control_blk_length = preqcblk->rpl_msgbl;
183 pxcrb->reply_control_blk_addr = (void *) prepcblk; 183 pxcrb->reply_control_blk_addr = (void __user *) prepcblk;
184} 184}
185 185
186/* 186/*
@@ -1194,7 +1194,7 @@ static struct miscdevice pkey_dev = {
1194/* 1194/*
1195 * Module init 1195 * Module init
1196 */ 1196 */
1197int __init pkey_init(void) 1197static int __init pkey_init(void)
1198{ 1198{
1199 cpacf_mask_t pckmo_functions; 1199 cpacf_mask_t pckmo_functions;
1200 1200
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index 93015f85d4a6..b1c27e28859b 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -821,8 +821,10 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
821 do { 821 do {
822 rc = zcrypt_rsa_modexpo(&mex); 822 rc = zcrypt_rsa_modexpo(&mex);
823 } while (rc == -EAGAIN); 823 } while (rc == -EAGAIN);
824 if (rc) 824 if (rc) {
825 ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSAMODEXPO rc=%d", rc);
825 return rc; 826 return rc;
827 }
826 return put_user(mex.outputdatalength, &umex->outputdatalength); 828 return put_user(mex.outputdatalength, &umex->outputdatalength);
827 } 829 }
828 case ICARSACRT: { 830 case ICARSACRT: {
@@ -838,8 +840,10 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
838 do { 840 do {
839 rc = zcrypt_rsa_crt(&crt); 841 rc = zcrypt_rsa_crt(&crt);
840 } while (rc == -EAGAIN); 842 } while (rc == -EAGAIN);
841 if (rc) 843 if (rc) {
844 ZCRYPT_DBF(DBF_DEBUG, "ioctl ICARSACRT rc=%d", rc);
842 return rc; 845 return rc;
846 }
843 return put_user(crt.outputdatalength, &ucrt->outputdatalength); 847 return put_user(crt.outputdatalength, &ucrt->outputdatalength);
844 } 848 }
845 case ZSECSENDCPRB: { 849 case ZSECSENDCPRB: {
@@ -855,6 +859,8 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
855 do { 859 do {
856 rc = zcrypt_send_cprb(&xcRB); 860 rc = zcrypt_send_cprb(&xcRB);
857 } while (rc == -EAGAIN); 861 } while (rc == -EAGAIN);
862 if (rc)
863 ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDCPRB rc=%d", rc);
858 if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB))) 864 if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
859 return -EFAULT; 865 return -EFAULT;
860 return rc; 866 return rc;
@@ -872,6 +878,8 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
872 do { 878 do {
873 rc = zcrypt_send_ep11_cprb(&xcrb); 879 rc = zcrypt_send_ep11_cprb(&xcrb);
874 } while (rc == -EAGAIN); 880 } while (rc == -EAGAIN);
881 if (rc)
882 ZCRYPT_DBF(DBF_DEBUG, "ioctl ZSENDEP11CPRB rc=%d", rc);
875 if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb))) 883 if (copy_to_user(uxcrb, &xcrb, sizeof(xcrb)))
876 return -EFAULT; 884 return -EFAULT;
877 return rc; 885 return rc;
diff --git a/drivers/s390/crypto/zcrypt_cca_key.h b/drivers/s390/crypto/zcrypt_cca_key.h
index ca0cdbe46368..12cff6262566 100644
--- a/drivers/s390/crypto/zcrypt_cca_key.h
+++ b/drivers/s390/crypto/zcrypt_cca_key.h
@@ -48,26 +48,6 @@ struct cca_token_hdr {
48 48
49#define CCA_TKN_HDR_ID_EXT 0x1E 49#define CCA_TKN_HDR_ID_EXT 0x1E
50 50
51/**
52 * mapping for the cca private ME section
53 */
54struct cca_private_ext_ME_sec {
55 unsigned char section_identifier;
56 unsigned char version;
57 unsigned short section_length;
58 unsigned char private_key_hash[20];
59 unsigned char reserved1[4];
60 unsigned char key_format;
61 unsigned char reserved2;
62 unsigned char key_name_hash[20];
63 unsigned char key_use_flags[4];
64 unsigned char reserved3[6];
65 unsigned char reserved4[24];
66 unsigned char confounder[24];
67 unsigned char exponent[128];
68 unsigned char modulus[128];
69} __attribute__((packed));
70
71#define CCA_PVT_USAGE_ALL 0x80 51#define CCA_PVT_USAGE_ALL 0x80
72 52
73/** 53/**
@@ -124,77 +104,6 @@ struct cca_pvt_ext_CRT_sec {
124#define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40 104#define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40
125 105
126/** 106/**
127 * Set up private key fields of a type6 MEX message.
128 * Note that all numerics in the key token are big-endian,
129 * while the entries in the key block header are little-endian.
130 *
131 * @mex: pointer to user input data
132 * @p: pointer to memory area for the key
133 *
134 * Returns the size of the key area or -EFAULT
135 */
136static inline int zcrypt_type6_mex_key_de(struct ica_rsa_modexpo *mex,
137 void *p, int big_endian)
138{
139 static struct cca_token_hdr static_pvt_me_hdr = {
140 .token_identifier = 0x1E,
141 .token_length = 0x0183,
142 };
143 static struct cca_private_ext_ME_sec static_pvt_me_sec = {
144 .section_identifier = 0x02,
145 .section_length = 0x016C,
146 .key_use_flags = {0x80,0x00,0x00,0x00},
147 };
148 static struct cca_public_sec static_pub_me_sec = {
149 .section_identifier = 0x04,
150 .section_length = 0x000F,
151 .exponent_len = 0x0003,
152 };
153 static char pk_exponent[3] = { 0x01, 0x00, 0x01 };
154 struct {
155 struct T6_keyBlock_hdr t6_hdr;
156 struct cca_token_hdr pvtMeHdr;
157 struct cca_private_ext_ME_sec pvtMeSec;
158 struct cca_public_sec pubMeSec;
159 char exponent[3];
160 } __attribute__((packed)) *key = p;
161 unsigned char *temp;
162
163 memset(key, 0, sizeof(*key));
164
165 if (big_endian) {
166 key->t6_hdr.blen = cpu_to_be16(0x189);
167 key->t6_hdr.ulen = cpu_to_be16(0x189 - 2);
168 } else {
169 key->t6_hdr.blen = cpu_to_le16(0x189);
170 key->t6_hdr.ulen = cpu_to_le16(0x189 - 2);
171 }
172 key->pvtMeHdr = static_pvt_me_hdr;
173 key->pvtMeSec = static_pvt_me_sec;
174 key->pubMeSec = static_pub_me_sec;
175 /*
176 * In a private key, the modulus doesn't appear in the public
177 * section. So, an arbitrary public exponent of 0x010001 will be
178 * used.
179 */
180 memcpy(key->exponent, pk_exponent, 3);
181
182 /* key parameter block */
183 temp = key->pvtMeSec.exponent +
184 sizeof(key->pvtMeSec.exponent) - mex->inputdatalength;
185 if (copy_from_user(temp, mex->b_key, mex->inputdatalength))
186 return -EFAULT;
187
188 /* modulus */
189 temp = key->pvtMeSec.modulus +
190 sizeof(key->pvtMeSec.modulus) - mex->inputdatalength;
191 if (copy_from_user(temp, mex->n_modulus, mex->inputdatalength))
192 return -EFAULT;
193 key->pubMeSec.modulus_bit_len = 8 * mex->inputdatalength;
194 return sizeof(*key);
195}
196
197/**
198 * Set up private key fields of a type6 MEX message. The _pad variant 107 * Set up private key fields of a type6 MEX message. The _pad variant
199 * strips leading zeroes from the b_key. 108 * strips leading zeroes from the b_key.
200 * Note that all numerics in the key token are big-endian, 109 * Note that all numerics in the key token are big-endian,
@@ -205,8 +114,7 @@ static inline int zcrypt_type6_mex_key_de(struct ica_rsa_modexpo *mex,
205 * 114 *
206 * Returns the size of the key area or -EFAULT 115 * Returns the size of the key area or -EFAULT
207 */ 116 */
208static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex, 117static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex, void *p)
209 void *p, int big_endian)
210{ 118{
211 static struct cca_token_hdr static_pub_hdr = { 119 static struct cca_token_hdr static_pub_hdr = {
212 .token_identifier = 0x1E, 120 .token_identifier = 0x1E,
@@ -251,13 +159,8 @@ static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex,
251 2*mex->inputdatalength - i; 159 2*mex->inputdatalength - i;
252 key->pubHdr.token_length = 160 key->pubHdr.token_length =
253 key->pubSec.section_length + sizeof(key->pubHdr); 161 key->pubSec.section_length + sizeof(key->pubHdr);
254 if (big_endian) { 162 key->t6_hdr.ulen = key->pubHdr.token_length + 4;
255 key->t6_hdr.ulen = cpu_to_be16(key->pubHdr.token_length + 4); 163 key->t6_hdr.blen = key->pubHdr.token_length + 6;
256 key->t6_hdr.blen = cpu_to_be16(key->pubHdr.token_length + 6);
257 } else {
258 key->t6_hdr.ulen = cpu_to_le16(key->pubHdr.token_length + 4);
259 key->t6_hdr.blen = cpu_to_le16(key->pubHdr.token_length + 6);
260 }
261 return sizeof(*key) + 2*mex->inputdatalength - i; 164 return sizeof(*key) + 2*mex->inputdatalength - i;
262} 165}
263 166
@@ -271,8 +174,7 @@ static inline int zcrypt_type6_mex_key_en(struct ica_rsa_modexpo *mex,
271 * 174 *
272 * Returns the size of the key area or -EFAULT 175 * Returns the size of the key area or -EFAULT
273 */ 176 */
274static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt, 177static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt, void *p)
275 void *p, int big_endian)
276{ 178{
277 static struct cca_public_sec static_cca_pub_sec = { 179 static struct cca_public_sec static_cca_pub_sec = {
278 .section_identifier = 4, 180 .section_identifier = 4,
@@ -298,13 +200,8 @@ static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt,
298 size = sizeof(*key) + key_len + sizeof(*pub) + 3; 200 size = sizeof(*key) + key_len + sizeof(*pub) + 3;
299 201
300 /* parameter block.key block */ 202 /* parameter block.key block */
301 if (big_endian) { 203 key->t6_hdr.blen = size;
302 key->t6_hdr.blen = cpu_to_be16(size); 204 key->t6_hdr.ulen = size - 2;
303 key->t6_hdr.ulen = cpu_to_be16(size - 2);
304 } else {
305 key->t6_hdr.blen = cpu_to_le16(size);
306 key->t6_hdr.ulen = cpu_to_le16(size - 2);
307 }
308 205
309 /* key token header */ 206 /* key token header */
310 key->token.token_identifier = CCA_TKN_HDR_ID_EXT; 207 key->token.token_identifier = CCA_TKN_HDR_ID_EXT;
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index e5563ffeb839..4fddb4319481 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -291,7 +291,7 @@ static int ICAMEX_msg_to_type6MEX_msgX(struct zcrypt_queue *zq,
291 return -EFAULT; 291 return -EFAULT;
292 292
293 /* Set up key which is located after the variable length text. */ 293 /* Set up key which is located after the variable length text. */
294 size = zcrypt_type6_mex_key_en(mex, msg->text+mex->inputdatalength, 1); 294 size = zcrypt_type6_mex_key_en(mex, msg->text+mex->inputdatalength);
295 if (size < 0) 295 if (size < 0)
296 return size; 296 return size;
297 size += sizeof(*msg) + mex->inputdatalength; 297 size += sizeof(*msg) + mex->inputdatalength;
@@ -353,7 +353,7 @@ static int ICACRT_msg_to_type6CRT_msgX(struct zcrypt_queue *zq,
353 return -EFAULT; 353 return -EFAULT;
354 354
355 /* Set up key which is located after the variable length text. */ 355 /* Set up key which is located after the variable length text. */
356 size = zcrypt_type6_crt_key(crt, msg->text + crt->inputdatalength, 1); 356 size = zcrypt_type6_crt_key(crt, msg->text + crt->inputdatalength);
357 if (size < 0) 357 if (size < 0)
358 return size; 358 return size;
359 size += sizeof(*msg) + crt->inputdatalength; /* total size of msg */ 359 size += sizeof(*msg) + crt->inputdatalength; /* total size of msg */
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index 574da15fe618..b8d5ea0ae26b 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -44,7 +44,7 @@ config HVC_RTAS
44 44
45config HVC_IUCV 45config HVC_IUCV
46 bool "z/VM IUCV Hypervisor console support (VM only)" 46 bool "z/VM IUCV Hypervisor console support (VM only)"
47 depends on S390 47 depends on S390 && NET
48 select HVC_DRIVER 48 select HVC_DRIVER
49 select IUCV 49 select IUCV
50 default y 50 default y