aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/kernel-parameters.txt2
-rw-r--r--Documentation/module-signing.txt6
-rw-r--r--Documentation/networking/mpls-sysctl.txt9
-rw-r--r--Documentation/networking/scaling.txt2
-rw-r--r--arch/s390/Kconfig2
-rw-r--r--arch/s390/crypto/crypt_s390.h122
-rw-r--r--arch/s390/crypto/prng.c850
-rw-r--r--arch/s390/include/asm/kexec.h3
-rw-r--r--arch/s390/include/asm/mmu.h4
-rw-r--r--arch/s390/include/asm/mmu_context.h3
-rw-r--r--arch/s390/include/asm/pgalloc.h1
-rw-r--r--arch/s390/include/asm/pgtable.h167
-rw-r--r--arch/s390/mm/hugetlbpage.c66
-rw-r--r--arch/s390/mm/pgtable.c142
-rw-r--r--arch/tile/kernel/setup.c2
-rw-r--r--arch/x86/include/asm/pvclock.h1
-rw-r--r--arch/x86/kernel/pvclock.c44
-rw-r--r--arch/x86/kvm/x86.c33
-rw-r--r--arch/x86/vdso/vclock_gettime.c34
-rw-r--r--drivers/md/dm-ioctl.c17
-rw-r--r--drivers/md/dm.c19
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/bonding/bond_procfs.c1
-rw-r--r--drivers/net/bonding/bonding_priv.h25
-rw-r--r--drivers/net/can/Kconfig2
-rw-r--r--drivers/net/can/usb/kvaser_usb.c2
-rw-r--r--drivers/net/ethernet/8390/etherh.c2
-rw-r--r--drivers/net/ethernet/altera/altera_msgdmahw.h5
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c37
-rw-r--r--drivers/net/ethernet/amd/Kconfig2
-rw-r--r--drivers/net/ethernet/arc/Kconfig5
-rw-r--r--drivers/net/ethernet/broadcom/bgmac.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c49
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c17
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c4
-rw-r--r--drivers/net/ethernet/cadence/macb.c4
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_main.c6
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c4
-rw-r--r--drivers/net/ethernet/marvell/pxa168_eth.c16
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_ethtool.c29
-rw-r--r--drivers/net/ethernet/myricom/myri10ge/myri10ge.c38
-rw-r--r--drivers/net/phy/mdio-gpio.c14
-rw-r--r--drivers/net/phy/mdio-mux-gpio.c60
-rw-r--r--drivers/net/ppp/ppp_mppe.c36
-rw-r--r--drivers/net/vxlan.c6
-rw-r--r--drivers/s390/char/con3215.c2
-rw-r--r--drivers/sh/pm_runtime.c7
-rw-r--r--drivers/tty/serial/8250/8250_pci.c25
-rw-r--r--drivers/tty/serial/atmel_serial.c2
-rw-r--r--drivers/tty/serial/of_serial.c1
-rw-r--r--drivers/tty/serial/samsung.c5
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/serial/uartlite.c11
-rw-r--r--drivers/tty/serial/xilinx_uartps.c12
-rw-r--r--drivers/tty/tty_ioctl.c3
-rw-r--r--drivers/usb/chipidea/otg_fsm.c4
-rw-r--r--drivers/usb/class/cdc-acm.c7
-rw-r--r--drivers/usb/host/ehci-msm.c13
-rw-r--r--drivers/usb/storage/uas-detect.h11
-rw-r--r--drivers/usb/storage/uas.c16
-rw-r--r--drivers/usb/storage/usb.c8
-rw-r--r--include/linux/kexec.h4
-rw-r--r--include/linux/netdevice.h10
-rw-r--r--include/linux/rhashtable.h3
-rw-r--r--include/linux/sched.h8
-rw-r--r--include/linux/skbuff.h1
-rw-r--r--include/linux/tty.h1
-rw-r--r--include/linux/usb_usual.h2
-rw-r--r--include/net/bonding.h7
-rw-r--r--include/net/inet_connection_sock.h20
-rw-r--r--include/net/request_sock.h18
-rw-r--r--kernel/Makefile6
-rw-r--r--kernel/kexec.c2
-rw-r--r--kernel/sched/core.c15
-rw-r--r--lib/rhashtable.c11
-rw-r--r--net/core/dev.c12
-rw-r--r--net/core/skbuff.c30
-rw-r--r--net/dccp/ipv4.c3
-rw-r--r--net/dccp/ipv6.c3
-rw-r--r--net/dccp/minisocks.c3
-rw-r--r--net/ipv4/inet_connection_sock.c34
-rw-r--r--net/ipv4/tcp_ipv4.c3
-rw-r--r--net/ipv4/tcp_minisocks.c7
-rw-r--r--net/ipv4/tcp_output.c64
-rw-r--r--net/ipv6/ip6_gre.c9
-rw-r--r--net/ipv6/tcp_ipv6.c3
-rw-r--r--net/mpls/af_mpls.c125
-rw-r--r--net/mpls/internal.h6
-rw-r--r--net/netfilter/nft_reject.c2
-rw-r--r--net/netfilter/nft_reject_inet.c2
-rw-r--r--net/netlink/af_netlink.c6
-rw-r--r--net/tipc/link.c1
-rw-r--r--net/tipc/server.c9
-rw-r--r--net/tipc/socket.c3
-rw-r--r--net/unix/garbage.c70
95 files changed, 1731 insertions, 798 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index f6befa9855c1..61ab1628a057 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3787,6 +3787,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3787 READ_CAPACITY_16 command); 3787 READ_CAPACITY_16 command);
3788 f = NO_REPORT_OPCODES (don't use report opcodes 3788 f = NO_REPORT_OPCODES (don't use report opcodes
3789 command, uas only); 3789 command, uas only);
3790 g = MAX_SECTORS_240 (don't transfer more than
3791 240 sectors at a time, uas only);
3790 h = CAPACITY_HEURISTICS (decrease the 3792 h = CAPACITY_HEURISTICS (decrease the
3791 reported device capacity by one 3793 reported device capacity by one
3792 sector if the number is odd); 3794 sector if the number is odd);
diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
index 09c2382ad055..c72702ec1ded 100644
--- a/Documentation/module-signing.txt
+++ b/Documentation/module-signing.txt
@@ -119,9 +119,9 @@ Most notably, in the x509.genkey file, the req_distinguished_name section
119should be altered from the default: 119should be altered from the default:
120 120
121 [ req_distinguished_name ] 121 [ req_distinguished_name ]
122 O = Magrathea 122 #O = Unspecified company
123 CN = Glacier signing key 123 CN = Build time autogenerated kernel key
124 emailAddress = slartibartfast@magrathea.h2g2 124 #emailAddress = unspecified.user@unspecified.company
125 125
126The generated RSA key size can also be set with: 126The generated RSA key size can also be set with:
127 127
diff --git a/Documentation/networking/mpls-sysctl.txt b/Documentation/networking/mpls-sysctl.txt
index 639ddf0ece9b..9ed15f86c17c 100644
--- a/Documentation/networking/mpls-sysctl.txt
+++ b/Documentation/networking/mpls-sysctl.txt
@@ -18,3 +18,12 @@ platform_labels - INTEGER
18 18
19 Possible values: 0 - 1048575 19 Possible values: 0 - 1048575
20 Default: 0 20 Default: 0
21
22conf/<interface>/input - BOOL
23 Control whether packets can be input on this interface.
24
25 If disabled, packets will be discarded without further
26 processing.
27
28 0 - disabled (default)
29 not 0 - enabled
diff --git a/Documentation/networking/scaling.txt b/Documentation/networking/scaling.txt
index cbfac0949635..59f4db2a0c85 100644
--- a/Documentation/networking/scaling.txt
+++ b/Documentation/networking/scaling.txt
@@ -282,7 +282,7 @@ following is true:
282 282
283- The current CPU's queue head counter >= the recorded tail counter 283- The current CPU's queue head counter >= the recorded tail counter
284 value in rps_dev_flow[i] 284 value in rps_dev_flow[i]
285- The current CPU is unset (equal to RPS_NO_CPU) 285- The current CPU is unset (>= nr_cpu_ids)
286- The current CPU is offline 286- The current CPU is offline
287 287
288After this check, the packet is sent to the (possibly updated) current 288After this check, the packet is sent to the (possibly updated) current
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 8e58c614c37d..b06dc3839268 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -115,7 +115,7 @@ config S390
115 select HAVE_ARCH_SECCOMP_FILTER 115 select HAVE_ARCH_SECCOMP_FILTER
116 select HAVE_ARCH_TRACEHOOK 116 select HAVE_ARCH_TRACEHOOK
117 select HAVE_ARCH_TRANSPARENT_HUGEPAGE 117 select HAVE_ARCH_TRANSPARENT_HUGEPAGE
118 select HAVE_BPF_JIT if PACK_STACK && HAVE_MARCH_Z9_109_FEATURES 118 select HAVE_BPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES
119 select HAVE_CMPXCHG_DOUBLE 119 select HAVE_CMPXCHG_DOUBLE
120 select HAVE_CMPXCHG_LOCAL 120 select HAVE_CMPXCHG_LOCAL
121 select HAVE_DEBUG_KMEMLEAK 121 select HAVE_DEBUG_KMEMLEAK
diff --git a/arch/s390/crypto/crypt_s390.h b/arch/s390/crypto/crypt_s390.h
index ba3b2aefddf5..d9c4c313fbc6 100644
--- a/arch/s390/crypto/crypt_s390.h
+++ b/arch/s390/crypto/crypt_s390.h
@@ -3,9 +3,10 @@
3 * 3 *
4 * Support for s390 cryptographic instructions. 4 * Support for s390 cryptographic instructions.
5 * 5 *
6 * Copyright IBM Corp. 2003, 2007 6 * Copyright IBM Corp. 2003, 2015
7 * Author(s): Thomas Spatzier 7 * Author(s): Thomas Spatzier
8 * Jan Glauber (jan.glauber@de.ibm.com) 8 * Jan Glauber (jan.glauber@de.ibm.com)
9 * Harald Freudenberger (freude@de.ibm.com)
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 12 * under the terms of the GNU General Public License as published by the Free
@@ -28,15 +29,17 @@
28#define CRYPT_S390_MSA 0x1 29#define CRYPT_S390_MSA 0x1
29#define CRYPT_S390_MSA3 0x2 30#define CRYPT_S390_MSA3 0x2
30#define CRYPT_S390_MSA4 0x4 31#define CRYPT_S390_MSA4 0x4
32#define CRYPT_S390_MSA5 0x8
31 33
32/* s390 cryptographic operations */ 34/* s390 cryptographic operations */
33enum crypt_s390_operations { 35enum crypt_s390_operations {
34 CRYPT_S390_KM = 0x0100, 36 CRYPT_S390_KM = 0x0100,
35 CRYPT_S390_KMC = 0x0200, 37 CRYPT_S390_KMC = 0x0200,
36 CRYPT_S390_KIMD = 0x0300, 38 CRYPT_S390_KIMD = 0x0300,
37 CRYPT_S390_KLMD = 0x0400, 39 CRYPT_S390_KLMD = 0x0400,
38 CRYPT_S390_KMAC = 0x0500, 40 CRYPT_S390_KMAC = 0x0500,
39 CRYPT_S390_KMCTR = 0x0600 41 CRYPT_S390_KMCTR = 0x0600,
42 CRYPT_S390_PPNO = 0x0700
40}; 43};
41 44
42/* 45/*
@@ -138,6 +141,16 @@ enum crypt_s390_kmac_func {
138 KMAC_TDEA_192 = CRYPT_S390_KMAC | 3 141 KMAC_TDEA_192 = CRYPT_S390_KMAC | 3
139}; 142};
140 143
144/*
145 * function codes for PPNO (PERFORM PSEUDORANDOM NUMBER
146 * OPERATION) instruction
147 */
148enum crypt_s390_ppno_func {
149 PPNO_QUERY = CRYPT_S390_PPNO | 0,
150 PPNO_SHA512_DRNG_GEN = CRYPT_S390_PPNO | 3,
151 PPNO_SHA512_DRNG_SEED = CRYPT_S390_PPNO | 0x83
152};
153
141/** 154/**
142 * crypt_s390_km: 155 * crypt_s390_km:
143 * @func: the function code passed to KM; see crypt_s390_km_func 156 * @func: the function code passed to KM; see crypt_s390_km_func
@@ -162,11 +175,11 @@ static inline int crypt_s390_km(long func, void *param,
162 int ret; 175 int ret;
163 176
164 asm volatile( 177 asm volatile(
165 "0: .insn rre,0xb92e0000,%3,%1 \n" /* KM opcode */ 178 "0: .insn rre,0xb92e0000,%3,%1\n" /* KM opcode */
166 "1: brc 1,0b \n" /* handle partial completion */ 179 "1: brc 1,0b\n" /* handle partial completion */
167 " la %0,0\n" 180 " la %0,0\n"
168 "2:\n" 181 "2:\n"
169 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 182 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
170 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) 183 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
171 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 184 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
172 if (ret < 0) 185 if (ret < 0)
@@ -198,11 +211,11 @@ static inline int crypt_s390_kmc(long func, void *param,
198 int ret; 211 int ret;
199 212
200 asm volatile( 213 asm volatile(
201 "0: .insn rre,0xb92f0000,%3,%1 \n" /* KMC opcode */ 214 "0: .insn rre,0xb92f0000,%3,%1\n" /* KMC opcode */
202 "1: brc 1,0b \n" /* handle partial completion */ 215 "1: brc 1,0b\n" /* handle partial completion */
203 " la %0,0\n" 216 " la %0,0\n"
204 "2:\n" 217 "2:\n"
205 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 218 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
206 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) 219 : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
207 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 220 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
208 if (ret < 0) 221 if (ret < 0)
@@ -233,11 +246,11 @@ static inline int crypt_s390_kimd(long func, void *param,
233 int ret; 246 int ret;
234 247
235 asm volatile( 248 asm volatile(
236 "0: .insn rre,0xb93e0000,%1,%1 \n" /* KIMD opcode */ 249 "0: .insn rre,0xb93e0000,%1,%1\n" /* KIMD opcode */
237 "1: brc 1,0b \n" /* handle partial completion */ 250 "1: brc 1,0b\n" /* handle partial completion */
238 " la %0,0\n" 251 " la %0,0\n"
239 "2:\n" 252 "2:\n"
240 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 253 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
241 : "=d" (ret), "+a" (__src), "+d" (__src_len) 254 : "=d" (ret), "+a" (__src), "+d" (__src_len)
242 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 255 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
243 if (ret < 0) 256 if (ret < 0)
@@ -267,11 +280,11 @@ static inline int crypt_s390_klmd(long func, void *param,
267 int ret; 280 int ret;
268 281
269 asm volatile( 282 asm volatile(
270 "0: .insn rre,0xb93f0000,%1,%1 \n" /* KLMD opcode */ 283 "0: .insn rre,0xb93f0000,%1,%1\n" /* KLMD opcode */
271 "1: brc 1,0b \n" /* handle partial completion */ 284 "1: brc 1,0b\n" /* handle partial completion */
272 " la %0,0\n" 285 " la %0,0\n"
273 "2:\n" 286 "2:\n"
274 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 287 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
275 : "=d" (ret), "+a" (__src), "+d" (__src_len) 288 : "=d" (ret), "+a" (__src), "+d" (__src_len)
276 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 289 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
277 if (ret < 0) 290 if (ret < 0)
@@ -302,11 +315,11 @@ static inline int crypt_s390_kmac(long func, void *param,
302 int ret; 315 int ret;
303 316
304 asm volatile( 317 asm volatile(
305 "0: .insn rre,0xb91e0000,%1,%1 \n" /* KLAC opcode */ 318 "0: .insn rre,0xb91e0000,%1,%1\n" /* KLAC opcode */
306 "1: brc 1,0b \n" /* handle partial completion */ 319 "1: brc 1,0b\n" /* handle partial completion */
307 " la %0,0\n" 320 " la %0,0\n"
308 "2:\n" 321 "2:\n"
309 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 322 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
310 : "=d" (ret), "+a" (__src), "+d" (__src_len) 323 : "=d" (ret), "+a" (__src), "+d" (__src_len)
311 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); 324 : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
312 if (ret < 0) 325 if (ret < 0)
@@ -340,11 +353,11 @@ static inline int crypt_s390_kmctr(long func, void *param, u8 *dest,
340 int ret = -1; 353 int ret = -1;
341 354
342 asm volatile( 355 asm volatile(
343 "0: .insn rrf,0xb92d0000,%3,%1,%4,0 \n" /* KMCTR opcode */ 356 "0: .insn rrf,0xb92d0000,%3,%1,%4,0\n" /* KMCTR opcode */
344 "1: brc 1,0b \n" /* handle partial completion */ 357 "1: brc 1,0b\n" /* handle partial completion */
345 " la %0,0\n" 358 " la %0,0\n"
346 "2:\n" 359 "2:\n"
347 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 360 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
348 : "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest), 361 : "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest),
349 "+a" (__ctr) 362 "+a" (__ctr)
350 : "d" (__func), "a" (__param) : "cc", "memory"); 363 : "d" (__func), "a" (__param) : "cc", "memory");
@@ -354,6 +367,47 @@ static inline int crypt_s390_kmctr(long func, void *param, u8 *dest,
354} 367}
355 368
356/** 369/**
370 * crypt_s390_ppno:
371 * @func: the function code passed to PPNO; see crypt_s390_ppno_func
372 * @param: address of parameter block; see POP for details on each func
373 * @dest: address of destination memory area
374 * @dest_len: size of destination memory area in bytes
375 * @seed: address of seed data
376 * @seed_len: size of seed data in bytes
377 *
378 * Executes the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION)
379 * operation of the CPU.
380 *
381 * Returns -1 for failure, 0 for the query func, number of random
382 * bytes stored in dest buffer for generate function
383 */
384static inline int crypt_s390_ppno(long func, void *param,
385 u8 *dest, long dest_len,
386 const u8 *seed, long seed_len)
387{
388 register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
389 register void *__param asm("1") = param; /* param block (240 bytes) */
390 register u8 *__dest asm("2") = dest; /* buf for recv random bytes */
391 register long __dest_len asm("3") = dest_len; /* requested random bytes */
392 register const u8 *__seed asm("4") = seed; /* buf with seed data */
393 register long __seed_len asm("5") = seed_len; /* bytes in seed buf */
394 int ret = -1;
395
396 asm volatile (
397 "0: .insn rre,0xb93c0000,%1,%5\n" /* PPNO opcode */
398 "1: brc 1,0b\n" /* handle partial completion */
399 " la %0,0\n"
400 "2:\n"
401 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
402 : "+d" (ret), "+a"(__dest), "+d"(__dest_len)
403 : "d"(__func), "a"(__param), "a"(__seed), "d"(__seed_len)
404 : "cc", "memory");
405 if (ret < 0)
406 return ret;
407 return (func & CRYPT_S390_FUNC_MASK) ? dest_len - __dest_len : 0;
408}
409
410/**
357 * crypt_s390_func_available: 411 * crypt_s390_func_available:
358 * @func: the function code of the specific function; 0 if op in general 412 * @func: the function code of the specific function; 0 if op in general
359 * 413 *
@@ -373,6 +427,9 @@ static inline int crypt_s390_func_available(int func,
373 return 0; 427 return 0;
374 if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77)) 428 if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77))
375 return 0; 429 return 0;
430 if (facility_mask & CRYPT_S390_MSA5 && !test_facility(57))
431 return 0;
432
376 switch (func & CRYPT_S390_OP_MASK) { 433 switch (func & CRYPT_S390_OP_MASK) {
377 case CRYPT_S390_KM: 434 case CRYPT_S390_KM:
378 ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0); 435 ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0);
@@ -390,8 +447,12 @@ static inline int crypt_s390_func_available(int func,
390 ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0); 447 ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0);
391 break; 448 break;
392 case CRYPT_S390_KMCTR: 449 case CRYPT_S390_KMCTR:
393 ret = crypt_s390_kmctr(KMCTR_QUERY, &status, NULL, NULL, 0, 450 ret = crypt_s390_kmctr(KMCTR_QUERY, &status,
394 NULL); 451 NULL, NULL, 0, NULL);
452 break;
453 case CRYPT_S390_PPNO:
454 ret = crypt_s390_ppno(PPNO_QUERY, &status,
455 NULL, 0, NULL, 0);
395 break; 456 break;
396 default: 457 default:
397 return 0; 458 return 0;
@@ -419,15 +480,14 @@ static inline int crypt_s390_pcc(long func, void *param)
419 int ret = -1; 480 int ret = -1;
420 481
421 asm volatile( 482 asm volatile(
422 "0: .insn rre,0xb92c0000,0,0 \n" /* PCC opcode */ 483 "0: .insn rre,0xb92c0000,0,0\n" /* PCC opcode */
423 "1: brc 1,0b \n" /* handle partial completion */ 484 "1: brc 1,0b\n" /* handle partial completion */
424 " la %0,0\n" 485 " la %0,0\n"
425 "2:\n" 486 "2:\n"
426 EX_TABLE(0b,2b) EX_TABLE(1b,2b) 487 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
427 : "+d" (ret) 488 : "+d" (ret)
428 : "d" (__func), "a" (__param) : "cc", "memory"); 489 : "d" (__func), "a" (__param) : "cc", "memory");
429 return ret; 490 return ret;
430} 491}
431 492
432
433#endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */ 493#endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */
diff --git a/arch/s390/crypto/prng.c b/arch/s390/crypto/prng.c
index 94a35a4c1b48..1f374b39a4ec 100644
--- a/arch/s390/crypto/prng.c
+++ b/arch/s390/crypto/prng.c
@@ -1,106 +1,529 @@
1/* 1/*
2 * Copyright IBM Corp. 2006, 2007 2 * Copyright IBM Corp. 2006, 2015
3 * Author(s): Jan Glauber <jan.glauber@de.ibm.com> 3 * Author(s): Jan Glauber <jan.glauber@de.ibm.com>
4 * Harald Freudenberger <freude@de.ibm.com>
4 * Driver for the s390 pseudo random number generator 5 * Driver for the s390 pseudo random number generator
5 */ 6 */
7
8#define KMSG_COMPONENT "prng"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
6#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/fips.h>
7#include <linux/init.h> 13#include <linux/init.h>
8#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/device.h>
9#include <linux/miscdevice.h> 16#include <linux/miscdevice.h>
10#include <linux/module.h> 17#include <linux/module.h>
11#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/mutex.h>
12#include <linux/random.h> 20#include <linux/random.h>
13#include <linux/slab.h> 21#include <linux/slab.h>
14#include <asm/debug.h> 22#include <asm/debug.h>
15#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/timex.h>
16 25
17#include "crypt_s390.h" 26#include "crypt_s390.h"
18 27
19MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Jan Glauber <jan.glauber@de.ibm.com>"); 29MODULE_AUTHOR("IBM Corporation");
21MODULE_DESCRIPTION("s390 PRNG interface"); 30MODULE_DESCRIPTION("s390 PRNG interface");
22 31
23static int prng_chunk_size = 256; 32
24module_param(prng_chunk_size, int, S_IRUSR | S_IRGRP | S_IROTH); 33#define PRNG_MODE_AUTO 0
34#define PRNG_MODE_TDES 1
35#define PRNG_MODE_SHA512 2
36
37static unsigned int prng_mode = PRNG_MODE_AUTO;
38module_param_named(mode, prng_mode, int, 0);
39MODULE_PARM_DESC(prng_mode, "PRNG mode: 0 - auto, 1 - TDES, 2 - SHA512");
40
41
42#define PRNG_CHUNKSIZE_TDES_MIN 8
43#define PRNG_CHUNKSIZE_TDES_MAX (64*1024)
44#define PRNG_CHUNKSIZE_SHA512_MIN 64
45#define PRNG_CHUNKSIZE_SHA512_MAX (64*1024)
46
47static unsigned int prng_chunk_size = 256;
48module_param_named(chunksize, prng_chunk_size, int, 0);
25MODULE_PARM_DESC(prng_chunk_size, "PRNG read chunk size in bytes"); 49MODULE_PARM_DESC(prng_chunk_size, "PRNG read chunk size in bytes");
26 50
27static int prng_entropy_limit = 4096; 51
28module_param(prng_entropy_limit, int, S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR); 52#define PRNG_RESEED_LIMIT_TDES 4096
29MODULE_PARM_DESC(prng_entropy_limit, 53#define PRNG_RESEED_LIMIT_TDES_LOWER 4096
30 "PRNG add entropy after that much bytes were produced"); 54#define PRNG_RESEED_LIMIT_SHA512 100000
55#define PRNG_RESEED_LIMIT_SHA512_LOWER 10000
56
57static unsigned int prng_reseed_limit;
58module_param_named(reseed_limit, prng_reseed_limit, int, 0);
59MODULE_PARM_DESC(prng_reseed_limit, "PRNG reseed limit");
60
31 61
32/* 62/*
33 * Any one who considers arithmetical methods of producing random digits is, 63 * Any one who considers arithmetical methods of producing random digits is,
34 * of course, in a state of sin. -- John von Neumann 64 * of course, in a state of sin. -- John von Neumann
35 */ 65 */
36 66
37struct s390_prng_data { 67static int prng_errorflag;
38 unsigned long count; /* how many bytes were produced */ 68
39 char *buf; 69#define PRNG_GEN_ENTROPY_FAILED 1
70#define PRNG_SELFTEST_FAILED 2
71#define PRNG_INSTANTIATE_FAILED 3
72#define PRNG_SEED_FAILED 4
73#define PRNG_RESEED_FAILED 5
74#define PRNG_GEN_FAILED 6
75
76struct prng_ws_s {
77 u8 parm_block[32];
78 u32 reseed_counter;
79 u64 byte_counter;
40}; 80};
41 81
42static struct s390_prng_data *p; 82struct ppno_ws_s {
83 u32 res;
84 u32 reseed_counter;
85 u64 stream_bytes;
86 u8 V[112];
87 u8 C[112];
88};
43 89
44/* copied from libica, use a non-zero initial parameter block */ 90struct prng_data_s {
45static unsigned char parm_block[32] = { 91 struct mutex mutex;
460x0F,0x2B,0x8E,0x63,0x8C,0x8E,0xD2,0x52,0x64,0xB7,0xA0,0x7B,0x75,0x28,0xB8,0xF4, 92 union {
470x75,0x5F,0xD2,0xA6,0x8D,0x97,0x11,0xFF,0x49,0xD8,0x23,0xF3,0x7E,0x21,0xEC,0xA0, 93 struct prng_ws_s prngws;
94 struct ppno_ws_s ppnows;
95 };
96 u8 *buf;
97 u32 rest;
98 u8 *prev;
48}; 99};
49 100
50static int prng_open(struct inode *inode, struct file *file) 101static struct prng_data_s *prng_data;
102
103/* initial parameter block for tdes mode, copied from libica */
104static const u8 initial_parm_block[32] __initconst = {
105 0x0F, 0x2B, 0x8E, 0x63, 0x8C, 0x8E, 0xD2, 0x52,
106 0x64, 0xB7, 0xA0, 0x7B, 0x75, 0x28, 0xB8, 0xF4,
107 0x75, 0x5F, 0xD2, 0xA6, 0x8D, 0x97, 0x11, 0xFF,
108 0x49, 0xD8, 0x23, 0xF3, 0x7E, 0x21, 0xEC, 0xA0 };
109
110
111/*** helper functions ***/
112
113static int generate_entropy(u8 *ebuf, size_t nbytes)
51{ 114{
52 return nonseekable_open(inode, file); 115 int n, ret = 0;
116 u8 *pg, *h, hash[32];
117
118 pg = (u8 *) __get_free_page(GFP_KERNEL);
119 if (!pg) {
120 prng_errorflag = PRNG_GEN_ENTROPY_FAILED;
121 return -ENOMEM;
122 }
123
124 while (nbytes) {
125 /* fill page with urandom bytes */
126 get_random_bytes(pg, PAGE_SIZE);
127 /* exor page with stckf values */
128 for (n = 0; n < sizeof(PAGE_SIZE/sizeof(u64)); n++) {
129 u64 *p = ((u64 *)pg) + n;
130 *p ^= get_tod_clock_fast();
131 }
132 n = (nbytes < sizeof(hash)) ? nbytes : sizeof(hash);
133 if (n < sizeof(hash))
134 h = hash;
135 else
136 h = ebuf;
137 /* generate sha256 from this page */
138 if (crypt_s390_kimd(KIMD_SHA_256, h,
139 pg, PAGE_SIZE) != PAGE_SIZE) {
140 prng_errorflag = PRNG_GEN_ENTROPY_FAILED;
141 ret = -EIO;
142 goto out;
143 }
144 if (n < sizeof(hash))
145 memcpy(ebuf, hash, n);
146 ret += n;
147 ebuf += n;
148 nbytes -= n;
149 }
150
151out:
152 free_page((unsigned long)pg);
153 return ret;
53} 154}
54 155
55static void prng_add_entropy(void) 156
157/*** tdes functions ***/
158
159static void prng_tdes_add_entropy(void)
56{ 160{
57 __u64 entropy[4]; 161 __u64 entropy[4];
58 unsigned int i; 162 unsigned int i;
59 int ret; 163 int ret;
60 164
61 for (i = 0; i < 16; i++) { 165 for (i = 0; i < 16; i++) {
62 ret = crypt_s390_kmc(KMC_PRNG, parm_block, (char *)entropy, 166 ret = crypt_s390_kmc(KMC_PRNG, prng_data->prngws.parm_block,
63 (char *)entropy, sizeof(entropy)); 167 (char *)entropy, (char *)entropy,
168 sizeof(entropy));
64 BUG_ON(ret < 0 || ret != sizeof(entropy)); 169 BUG_ON(ret < 0 || ret != sizeof(entropy));
65 memcpy(parm_block, entropy, sizeof(entropy)); 170 memcpy(prng_data->prngws.parm_block, entropy, sizeof(entropy));
66 } 171 }
67} 172}
68 173
69static void prng_seed(int nbytes) 174
175static void prng_tdes_seed(int nbytes)
70{ 176{
71 char buf[16]; 177 char buf[16];
72 int i = 0; 178 int i = 0;
73 179
74 BUG_ON(nbytes > 16); 180 BUG_ON(nbytes > sizeof(buf));
181
75 get_random_bytes(buf, nbytes); 182 get_random_bytes(buf, nbytes);
76 183
77 /* Add the entropy */ 184 /* Add the entropy */
78 while (nbytes >= 8) { 185 while (nbytes >= 8) {
79 *((__u64 *)parm_block) ^= *((__u64 *)(buf+i)); 186 *((__u64 *)prng_data->prngws.parm_block) ^= *((__u64 *)(buf+i));
80 prng_add_entropy(); 187 prng_tdes_add_entropy();
81 i += 8; 188 i += 8;
82 nbytes -= 8; 189 nbytes -= 8;
83 } 190 }
84 prng_add_entropy(); 191 prng_tdes_add_entropy();
192 prng_data->prngws.reseed_counter = 0;
193}
194
195
196static int __init prng_tdes_instantiate(void)
197{
198 int datalen;
199
200 pr_debug("prng runs in TDES mode with "
201 "chunksize=%d and reseed_limit=%u\n",
202 prng_chunk_size, prng_reseed_limit);
203
204 /* memory allocation, prng_data struct init, mutex init */
205 datalen = sizeof(struct prng_data_s) + prng_chunk_size;
206 prng_data = kzalloc(datalen, GFP_KERNEL);
207 if (!prng_data) {
208 prng_errorflag = PRNG_INSTANTIATE_FAILED;
209 return -ENOMEM;
210 }
211 mutex_init(&prng_data->mutex);
212 prng_data->buf = ((u8 *)prng_data) + sizeof(struct prng_data_s);
213 memcpy(prng_data->prngws.parm_block, initial_parm_block, 32);
214
215 /* initialize the PRNG, add 128 bits of entropy */
216 prng_tdes_seed(16);
217
218 return 0;
85} 219}
86 220
87static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes, 221
88 loff_t *ppos) 222static void prng_tdes_deinstantiate(void)
223{
224 pr_debug("The prng module stopped "
225 "after running in triple DES mode\n");
226 kzfree(prng_data);
227}
228
229
230/*** sha512 functions ***/
231
232static int __init prng_sha512_selftest(void)
89{ 233{
90 int chunk, n; 234 /* NIST DRBG testvector for Hash Drbg, Sha-512, Count #0 */
235 static const u8 seed[] __initconst = {
236 0x6b, 0x50, 0xa7, 0xd8, 0xf8, 0xa5, 0x5d, 0x7a,
237 0x3d, 0xf8, 0xbb, 0x40, 0xbc, 0xc3, 0xb7, 0x22,
238 0xd8, 0x70, 0x8d, 0xe6, 0x7f, 0xda, 0x01, 0x0b,
239 0x03, 0xc4, 0xc8, 0x4d, 0x72, 0x09, 0x6f, 0x8c,
240 0x3e, 0xc6, 0x49, 0xcc, 0x62, 0x56, 0xd9, 0xfa,
241 0x31, 0xdb, 0x7a, 0x29, 0x04, 0xaa, 0xf0, 0x25 };
242 static const u8 V0[] __initconst = {
243 0x00, 0xad, 0xe3, 0x6f, 0x9a, 0x01, 0xc7, 0x76,
244 0x61, 0x34, 0x35, 0xf5, 0x4e, 0x24, 0x74, 0x22,
245 0x21, 0x9a, 0x29, 0x89, 0xc7, 0x93, 0x2e, 0x60,
246 0x1e, 0xe8, 0x14, 0x24, 0x8d, 0xd5, 0x03, 0xf1,
247 0x65, 0x5d, 0x08, 0x22, 0x72, 0xd5, 0xad, 0x95,
248 0xe1, 0x23, 0x1e, 0x8a, 0xa7, 0x13, 0xd9, 0x2b,
249 0x5e, 0xbc, 0xbb, 0x80, 0xab, 0x8d, 0xe5, 0x79,
250 0xab, 0x5b, 0x47, 0x4e, 0xdd, 0xee, 0x6b, 0x03,
251 0x8f, 0x0f, 0x5c, 0x5e, 0xa9, 0x1a, 0x83, 0xdd,
252 0xd3, 0x88, 0xb2, 0x75, 0x4b, 0xce, 0x83, 0x36,
253 0x57, 0x4b, 0xf1, 0x5c, 0xca, 0x7e, 0x09, 0xc0,
254 0xd3, 0x89, 0xc6, 0xe0, 0xda, 0xc4, 0x81, 0x7e,
255 0x5b, 0xf9, 0xe1, 0x01, 0xc1, 0x92, 0x05, 0xea,
256 0xf5, 0x2f, 0xc6, 0xc6, 0xc7, 0x8f, 0xbc, 0xf4 };
257 static const u8 C0[] __initconst = {
258 0x00, 0xf4, 0xa3, 0xe5, 0xa0, 0x72, 0x63, 0x95,
259 0xc6, 0x4f, 0x48, 0xd0, 0x8b, 0x5b, 0x5f, 0x8e,
260 0x6b, 0x96, 0x1f, 0x16, 0xed, 0xbc, 0x66, 0x94,
261 0x45, 0x31, 0xd7, 0x47, 0x73, 0x22, 0xa5, 0x86,
262 0xce, 0xc0, 0x4c, 0xac, 0x63, 0xb8, 0x39, 0x50,
263 0xbf, 0xe6, 0x59, 0x6c, 0x38, 0x58, 0x99, 0x1f,
264 0x27, 0xa7, 0x9d, 0x71, 0x2a, 0xb3, 0x7b, 0xf9,
265 0xfb, 0x17, 0x86, 0xaa, 0x99, 0x81, 0xaa, 0x43,
266 0xe4, 0x37, 0xd3, 0x1e, 0x6e, 0xe5, 0xe6, 0xee,
267 0xc2, 0xed, 0x95, 0x4f, 0x53, 0x0e, 0x46, 0x8a,
268 0xcc, 0x45, 0xa5, 0xdb, 0x69, 0x0d, 0x81, 0xc9,
269 0x32, 0x92, 0xbc, 0x8f, 0x33, 0xe6, 0xf6, 0x09,
270 0x7c, 0x8e, 0x05, 0x19, 0x0d, 0xf1, 0xb6, 0xcc,
271 0xf3, 0x02, 0x21, 0x90, 0x25, 0xec, 0xed, 0x0e };
272 static const u8 random[] __initconst = {
273 0x95, 0xb7, 0xf1, 0x7e, 0x98, 0x02, 0xd3, 0x57,
274 0x73, 0x92, 0xc6, 0xa9, 0xc0, 0x80, 0x83, 0xb6,
275 0x7d, 0xd1, 0x29, 0x22, 0x65, 0xb5, 0xf4, 0x2d,
276 0x23, 0x7f, 0x1c, 0x55, 0xbb, 0x9b, 0x10, 0xbf,
277 0xcf, 0xd8, 0x2c, 0x77, 0xa3, 0x78, 0xb8, 0x26,
278 0x6a, 0x00, 0x99, 0x14, 0x3b, 0x3c, 0x2d, 0x64,
279 0x61, 0x1e, 0xee, 0xb6, 0x9a, 0xcd, 0xc0, 0x55,
280 0x95, 0x7c, 0x13, 0x9e, 0x8b, 0x19, 0x0c, 0x7a,
281 0x06, 0x95, 0x5f, 0x2c, 0x79, 0x7c, 0x27, 0x78,
282 0xde, 0x94, 0x03, 0x96, 0xa5, 0x01, 0xf4, 0x0e,
283 0x91, 0x39, 0x6a, 0xcf, 0x8d, 0x7e, 0x45, 0xeb,
284 0xdb, 0xb5, 0x3b, 0xbf, 0x8c, 0x97, 0x52, 0x30,
285 0xd2, 0xf0, 0xff, 0x91, 0x06, 0xc7, 0x61, 0x19,
286 0xae, 0x49, 0x8e, 0x7f, 0xbc, 0x03, 0xd9, 0x0f,
287 0x8e, 0x4c, 0x51, 0x62, 0x7a, 0xed, 0x5c, 0x8d,
288 0x42, 0x63, 0xd5, 0xd2, 0xb9, 0x78, 0x87, 0x3a,
289 0x0d, 0xe5, 0x96, 0xee, 0x6d, 0xc7, 0xf7, 0xc2,
290 0x9e, 0x37, 0xee, 0xe8, 0xb3, 0x4c, 0x90, 0xdd,
291 0x1c, 0xf6, 0xa9, 0xdd, 0xb2, 0x2b, 0x4c, 0xbd,
292 0x08, 0x6b, 0x14, 0xb3, 0x5d, 0xe9, 0x3d, 0xa2,
293 0xd5, 0xcb, 0x18, 0x06, 0x69, 0x8c, 0xbd, 0x7b,
294 0xbb, 0x67, 0xbf, 0xe3, 0xd3, 0x1f, 0xd2, 0xd1,
295 0xdb, 0xd2, 0xa1, 0xe0, 0x58, 0xa3, 0xeb, 0x99,
296 0xd7, 0xe5, 0x1f, 0x1a, 0x93, 0x8e, 0xed, 0x5e,
297 0x1c, 0x1d, 0xe2, 0x3a, 0x6b, 0x43, 0x45, 0xd3,
298 0x19, 0x14, 0x09, 0xf9, 0x2f, 0x39, 0xb3, 0x67,
299 0x0d, 0x8d, 0xbf, 0xb6, 0x35, 0xd8, 0xe6, 0xa3,
300 0x69, 0x32, 0xd8, 0x10, 0x33, 0xd1, 0x44, 0x8d,
301 0x63, 0xb4, 0x03, 0xdd, 0xf8, 0x8e, 0x12, 0x1b,
302 0x6e, 0x81, 0x9a, 0xc3, 0x81, 0x22, 0x6c, 0x13,
303 0x21, 0xe4, 0xb0, 0x86, 0x44, 0xf6, 0x72, 0x7c,
304 0x36, 0x8c, 0x5a, 0x9f, 0x7a, 0x4b, 0x3e, 0xe2 };
305
91 int ret = 0; 306 int ret = 0;
92 int tmp; 307 u8 buf[sizeof(random)];
308 struct ppno_ws_s ws;
309
310 memset(&ws, 0, sizeof(ws));
311
312 /* initial seed */
313 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
314 &ws, NULL, 0,
315 seed, sizeof(seed));
316 if (ret < 0) {
317 pr_err("The prng self test seed operation for the "
318 "SHA-512 mode failed with rc=%d\n", ret);
319 prng_errorflag = PRNG_SELFTEST_FAILED;
320 return -EIO;
321 }
322
323 /* check working states V and C */
324 if (memcmp(ws.V, V0, sizeof(V0)) != 0
325 || memcmp(ws.C, C0, sizeof(C0)) != 0) {
326 pr_err("The prng self test state test "
327 "for the SHA-512 mode failed\n");
328 prng_errorflag = PRNG_SELFTEST_FAILED;
329 return -EIO;
330 }
331
332 /* generate random bytes */
333 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
334 &ws, buf, sizeof(buf),
335 NULL, 0);
336 if (ret < 0) {
337 pr_err("The prng self test generate operation for "
338 "the SHA-512 mode failed with rc=%d\n", ret);
339 prng_errorflag = PRNG_SELFTEST_FAILED;
340 return -EIO;
341 }
342 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
343 &ws, buf, sizeof(buf),
344 NULL, 0);
345 if (ret < 0) {
346 pr_err("The prng self test generate operation for "
347 "the SHA-512 mode failed with rc=%d\n", ret);
348 prng_errorflag = PRNG_SELFTEST_FAILED;
349 return -EIO;
350 }
351
352 /* check against expected data */
353 if (memcmp(buf, random, sizeof(random)) != 0) {
354 pr_err("The prng self test data test "
355 "for the SHA-512 mode failed\n");
356 prng_errorflag = PRNG_SELFTEST_FAILED;
357 return -EIO;
358 }
359
360 return 0;
361}
362
363
364static int __init prng_sha512_instantiate(void)
365{
366 int ret, datalen;
367 u8 seed[64];
368
369 pr_debug("prng runs in SHA-512 mode "
370 "with chunksize=%d and reseed_limit=%u\n",
371 prng_chunk_size, prng_reseed_limit);
372
373 /* memory allocation, prng_data struct init, mutex init */
374 datalen = sizeof(struct prng_data_s) + prng_chunk_size;
375 if (fips_enabled)
376 datalen += prng_chunk_size;
377 prng_data = kzalloc(datalen, GFP_KERNEL);
378 if (!prng_data) {
379 prng_errorflag = PRNG_INSTANTIATE_FAILED;
380 return -ENOMEM;
381 }
382 mutex_init(&prng_data->mutex);
383 prng_data->buf = ((u8 *)prng_data) + sizeof(struct prng_data_s);
384
385 /* selftest */
386 ret = prng_sha512_selftest();
387 if (ret)
388 goto outfree;
389
390 /* generate initial seed bytestring, first 48 bytes of entropy */
391 ret = generate_entropy(seed, 48);
392 if (ret != 48)
393 goto outfree;
394 /* followed by 16 bytes of unique nonce */
395 get_tod_clock_ext(seed + 48);
396
397 /* initial seed of the ppno drng */
398 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
399 &prng_data->ppnows, NULL, 0,
400 seed, sizeof(seed));
401 if (ret < 0) {
402 prng_errorflag = PRNG_SEED_FAILED;
403 ret = -EIO;
404 goto outfree;
405 }
406
407 /* if fips mode is enabled, generate a first block of random
408 bytes for the FIPS 140-2 Conditional Self Test */
409 if (fips_enabled) {
410 prng_data->prev = prng_data->buf + prng_chunk_size;
411 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
412 &prng_data->ppnows,
413 prng_data->prev,
414 prng_chunk_size,
415 NULL, 0);
416 if (ret < 0 || ret != prng_chunk_size) {
417 prng_errorflag = PRNG_GEN_FAILED;
418 ret = -EIO;
419 goto outfree;
420 }
421 }
422
423 return 0;
424
425outfree:
426 kfree(prng_data);
427 return ret;
428}
429
430
431static void prng_sha512_deinstantiate(void)
432{
433 pr_debug("The prng module stopped after running in SHA-512 mode\n");
434 kzfree(prng_data);
435}
436
437
438static int prng_sha512_reseed(void)
439{
440 int ret;
441 u8 seed[32];
442
443 /* generate 32 bytes of fresh entropy */
444 ret = generate_entropy(seed, sizeof(seed));
445 if (ret != sizeof(seed))
446 return ret;
447
448 /* do a reseed of the ppno drng with this bytestring */
449 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_SEED,
450 &prng_data->ppnows, NULL, 0,
451 seed, sizeof(seed));
452 if (ret) {
453 prng_errorflag = PRNG_RESEED_FAILED;
454 return -EIO;
455 }
456
457 return 0;
458}
459
460
461static int prng_sha512_generate(u8 *buf, size_t nbytes)
462{
463 int ret;
464
465 /* reseed needed ? */
466 if (prng_data->ppnows.reseed_counter > prng_reseed_limit) {
467 ret = prng_sha512_reseed();
468 if (ret)
469 return ret;
470 }
471
472 /* PPNO generate */
473 ret = crypt_s390_ppno(PPNO_SHA512_DRNG_GEN,
474 &prng_data->ppnows, buf, nbytes,
475 NULL, 0);
476 if (ret < 0 || ret != nbytes) {
477 prng_errorflag = PRNG_GEN_FAILED;
478 return -EIO;
479 }
480
481 /* FIPS 140-2 Conditional Self Test */
482 if (fips_enabled) {
483 if (!memcmp(prng_data->prev, buf, nbytes)) {
484 prng_errorflag = PRNG_GEN_FAILED;
485 return -EILSEQ;
486 }
487 memcpy(prng_data->prev, buf, nbytes);
488 }
489
490 return ret;
491}
492
493
494/*** file io functions ***/
495
496static int prng_open(struct inode *inode, struct file *file)
497{
498 return nonseekable_open(inode, file);
499}
500
501
502static ssize_t prng_tdes_read(struct file *file, char __user *ubuf,
503 size_t nbytes, loff_t *ppos)
504{
505 int chunk, n, tmp, ret = 0;
506
507 /* lock prng_data struct */
508 if (mutex_lock_interruptible(&prng_data->mutex))
509 return -ERESTARTSYS;
93 510
94 /* nbytes can be arbitrary length, we split it into chunks */
95 while (nbytes) { 511 while (nbytes) {
96 /* same as in extract_entropy_user in random.c */
97 if (need_resched()) { 512 if (need_resched()) {
98 if (signal_pending(current)) { 513 if (signal_pending(current)) {
99 if (ret == 0) 514 if (ret == 0)
100 ret = -ERESTARTSYS; 515 ret = -ERESTARTSYS;
101 break; 516 break;
102 } 517 }
518 /* give mutex free before calling schedule() */
519 mutex_unlock(&prng_data->mutex);
103 schedule(); 520 schedule();
521 /* occopy mutex again */
522 if (mutex_lock_interruptible(&prng_data->mutex)) {
523 if (ret == 0)
524 ret = -ERESTARTSYS;
525 return ret;
526 }
104 } 527 }
105 528
106 /* 529 /*
@@ -112,12 +535,11 @@ static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes,
112 /* PRNG only likes multiples of 8 bytes */ 535 /* PRNG only likes multiples of 8 bytes */
113 n = (chunk + 7) & -8; 536 n = (chunk + 7) & -8;
114 537
115 if (p->count > prng_entropy_limit) 538 if (prng_data->prngws.reseed_counter > prng_reseed_limit)
116 prng_seed(8); 539 prng_tdes_seed(8);
117 540
118 /* if the CPU supports PRNG stckf is present too */ 541 /* if the CPU supports PRNG stckf is present too */
119 asm volatile(".insn s,0xb27c0000,%0" 542 *((unsigned long long *)prng_data->buf) = get_tod_clock_fast();
120 : "=m" (*((unsigned long long *)p->buf)) : : "cc");
121 543
122 /* 544 /*
123 * Beside the STCKF the input for the TDES-EDE is the output 545 * Beside the STCKF the input for the TDES-EDE is the output
@@ -132,35 +554,259 @@ static ssize_t prng_read(struct file *file, char __user *ubuf, size_t nbytes,
132 * Note: you can still get strict X9.17 conformity by setting 554 * Note: you can still get strict X9.17 conformity by setting
133 * prng_chunk_size to 8 bytes. 555 * prng_chunk_size to 8 bytes.
134 */ 556 */
135 tmp = crypt_s390_kmc(KMC_PRNG, parm_block, p->buf, p->buf, n); 557 tmp = crypt_s390_kmc(KMC_PRNG, prng_data->prngws.parm_block,
136 BUG_ON((tmp < 0) || (tmp != n)); 558 prng_data->buf, prng_data->buf, n);
559 if (tmp < 0 || tmp != n) {
560 ret = -EIO;
561 break;
562 }
137 563
138 p->count += n; 564 prng_data->prngws.byte_counter += n;
565 prng_data->prngws.reseed_counter += n;
139 566
140 if (copy_to_user(ubuf, p->buf, chunk)) 567 if (copy_to_user(ubuf, prng_data->buf, chunk))
141 return -EFAULT; 568 return -EFAULT;
142 569
143 nbytes -= chunk; 570 nbytes -= chunk;
144 ret += chunk; 571 ret += chunk;
145 ubuf += chunk; 572 ubuf += chunk;
146 } 573 }
574
575 /* unlock prng_data struct */
576 mutex_unlock(&prng_data->mutex);
577
147 return ret; 578 return ret;
148} 579}
149 580
150static const struct file_operations prng_fops = { 581
582static ssize_t prng_sha512_read(struct file *file, char __user *ubuf,
583 size_t nbytes, loff_t *ppos)
584{
585 int n, ret = 0;
586 u8 *p;
587
588 /* if errorflag is set do nothing and return 'broken pipe' */
589 if (prng_errorflag)
590 return -EPIPE;
591
592 /* lock prng_data struct */
593 if (mutex_lock_interruptible(&prng_data->mutex))
594 return -ERESTARTSYS;
595
596 while (nbytes) {
597 if (need_resched()) {
598 if (signal_pending(current)) {
599 if (ret == 0)
600 ret = -ERESTARTSYS;
601 break;
602 }
603 /* give mutex free before calling schedule() */
604 mutex_unlock(&prng_data->mutex);
605 schedule();
606 /* occopy mutex again */
607 if (mutex_lock_interruptible(&prng_data->mutex)) {
608 if (ret == 0)
609 ret = -ERESTARTSYS;
610 return ret;
611 }
612 }
613 if (prng_data->rest) {
614 /* push left over random bytes from the previous read */
615 p = prng_data->buf + prng_chunk_size - prng_data->rest;
616 n = (nbytes < prng_data->rest) ?
617 nbytes : prng_data->rest;
618 prng_data->rest -= n;
619 } else {
620 /* generate one chunk of random bytes into read buf */
621 p = prng_data->buf;
622 n = prng_sha512_generate(p, prng_chunk_size);
623 if (n < 0) {
624 ret = n;
625 break;
626 }
627 if (nbytes < prng_chunk_size) {
628 n = nbytes;
629 prng_data->rest = prng_chunk_size - n;
630 } else {
631 n = prng_chunk_size;
632 prng_data->rest = 0;
633 }
634 }
635 if (copy_to_user(ubuf, p, n)) {
636 ret = -EFAULT;
637 break;
638 }
639 ubuf += n;
640 nbytes -= n;
641 ret += n;
642 }
643
644 /* unlock prng_data struct */
645 mutex_unlock(&prng_data->mutex);
646
647 return ret;
648}
649
650
651/*** sysfs stuff ***/
652
653static const struct file_operations prng_sha512_fops = {
654 .owner = THIS_MODULE,
655 .open = &prng_open,
656 .release = NULL,
657 .read = &prng_sha512_read,
658 .llseek = noop_llseek,
659};
660static const struct file_operations prng_tdes_fops = {
151 .owner = THIS_MODULE, 661 .owner = THIS_MODULE,
152 .open = &prng_open, 662 .open = &prng_open,
153 .release = NULL, 663 .release = NULL,
154 .read = &prng_read, 664 .read = &prng_tdes_read,
155 .llseek = noop_llseek, 665 .llseek = noop_llseek,
156}; 666};
157 667
158static struct miscdevice prng_dev = { 668static struct miscdevice prng_sha512_dev = {
669 .name = "prandom",
670 .minor = MISC_DYNAMIC_MINOR,
671 .fops = &prng_sha512_fops,
672};
673static struct miscdevice prng_tdes_dev = {
159 .name = "prandom", 674 .name = "prandom",
160 .minor = MISC_DYNAMIC_MINOR, 675 .minor = MISC_DYNAMIC_MINOR,
161 .fops = &prng_fops, 676 .fops = &prng_tdes_fops,
162}; 677};
163 678
679
680/* chunksize attribute (ro) */
681static ssize_t prng_chunksize_show(struct device *dev,
682 struct device_attribute *attr,
683 char *buf)
684{
685 return snprintf(buf, PAGE_SIZE, "%u\n", prng_chunk_size);
686}
687static DEVICE_ATTR(chunksize, 0444, prng_chunksize_show, NULL);
688
689/* counter attribute (ro) */
690static ssize_t prng_counter_show(struct device *dev,
691 struct device_attribute *attr,
692 char *buf)
693{
694 u64 counter;
695
696 if (mutex_lock_interruptible(&prng_data->mutex))
697 return -ERESTARTSYS;
698 if (prng_mode == PRNG_MODE_SHA512)
699 counter = prng_data->ppnows.stream_bytes;
700 else
701 counter = prng_data->prngws.byte_counter;
702 mutex_unlock(&prng_data->mutex);
703
704 return snprintf(buf, PAGE_SIZE, "%llu\n", counter);
705}
706static DEVICE_ATTR(byte_counter, 0444, prng_counter_show, NULL);
707
708/* errorflag attribute (ro) */
709static ssize_t prng_errorflag_show(struct device *dev,
710 struct device_attribute *attr,
711 char *buf)
712{
713 return snprintf(buf, PAGE_SIZE, "%d\n", prng_errorflag);
714}
715static DEVICE_ATTR(errorflag, 0444, prng_errorflag_show, NULL);
716
717/* mode attribute (ro) */
718static ssize_t prng_mode_show(struct device *dev,
719 struct device_attribute *attr,
720 char *buf)
721{
722 if (prng_mode == PRNG_MODE_TDES)
723 return snprintf(buf, PAGE_SIZE, "TDES\n");
724 else
725 return snprintf(buf, PAGE_SIZE, "SHA512\n");
726}
727static DEVICE_ATTR(mode, 0444, prng_mode_show, NULL);
728
729/* reseed attribute (w) */
730static ssize_t prng_reseed_store(struct device *dev,
731 struct device_attribute *attr,
732 const char *buf, size_t count)
733{
734 if (mutex_lock_interruptible(&prng_data->mutex))
735 return -ERESTARTSYS;
736 prng_sha512_reseed();
737 mutex_unlock(&prng_data->mutex);
738
739 return count;
740}
741static DEVICE_ATTR(reseed, 0200, NULL, prng_reseed_store);
742
743/* reseed limit attribute (rw) */
744static ssize_t prng_reseed_limit_show(struct device *dev,
745 struct device_attribute *attr,
746 char *buf)
747{
748 return snprintf(buf, PAGE_SIZE, "%u\n", prng_reseed_limit);
749}
750static ssize_t prng_reseed_limit_store(struct device *dev,
751 struct device_attribute *attr,
752 const char *buf, size_t count)
753{
754 unsigned limit;
755
756 if (sscanf(buf, "%u\n", &limit) != 1)
757 return -EINVAL;
758
759 if (prng_mode == PRNG_MODE_SHA512) {
760 if (limit < PRNG_RESEED_LIMIT_SHA512_LOWER)
761 return -EINVAL;
762 } else {
763 if (limit < PRNG_RESEED_LIMIT_TDES_LOWER)
764 return -EINVAL;
765 }
766
767 prng_reseed_limit = limit;
768
769 return count;
770}
771static DEVICE_ATTR(reseed_limit, 0644,
772 prng_reseed_limit_show, prng_reseed_limit_store);
773
774/* strength attribute (ro) */
775static ssize_t prng_strength_show(struct device *dev,
776 struct device_attribute *attr,
777 char *buf)
778{
779 return snprintf(buf, PAGE_SIZE, "256\n");
780}
781static DEVICE_ATTR(strength, 0444, prng_strength_show, NULL);
782
783static struct attribute *prng_sha512_dev_attrs[] = {
784 &dev_attr_errorflag.attr,
785 &dev_attr_chunksize.attr,
786 &dev_attr_byte_counter.attr,
787 &dev_attr_mode.attr,
788 &dev_attr_reseed.attr,
789 &dev_attr_reseed_limit.attr,
790 &dev_attr_strength.attr,
791 NULL
792};
793static struct attribute *prng_tdes_dev_attrs[] = {
794 &dev_attr_chunksize.attr,
795 &dev_attr_byte_counter.attr,
796 &dev_attr_mode.attr,
797 NULL
798};
799
800static struct attribute_group prng_sha512_dev_attr_group = {
801 .attrs = prng_sha512_dev_attrs
802};
803static struct attribute_group prng_tdes_dev_attr_group = {
804 .attrs = prng_tdes_dev_attrs
805};
806
807
808/*** module init and exit ***/
809
164static int __init prng_init(void) 810static int __init prng_init(void)
165{ 811{
166 int ret; 812 int ret;
@@ -169,43 +815,105 @@ static int __init prng_init(void)
169 if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA)) 815 if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA))
170 return -EOPNOTSUPP; 816 return -EOPNOTSUPP;
171 817
172 if (prng_chunk_size < 8) 818 /* choose prng mode */
173 return -EINVAL; 819 if (prng_mode != PRNG_MODE_TDES) {
820 /* check for MSA5 support for PPNO operations */
821 if (!crypt_s390_func_available(PPNO_SHA512_DRNG_GEN,
822 CRYPT_S390_MSA5)) {
823 if (prng_mode == PRNG_MODE_SHA512) {
824 pr_err("The prng module cannot "
825 "start in SHA-512 mode\n");
826 return -EOPNOTSUPP;
827 }
828 prng_mode = PRNG_MODE_TDES;
829 } else
830 prng_mode = PRNG_MODE_SHA512;
831 }
174 832
175 p = kmalloc(sizeof(struct s390_prng_data), GFP_KERNEL); 833 if (prng_mode == PRNG_MODE_SHA512) {
176 if (!p)
177 return -ENOMEM;
178 p->count = 0;
179 834
180 p->buf = kmalloc(prng_chunk_size, GFP_KERNEL); 835 /* SHA512 mode */
181 if (!p->buf) {
182 ret = -ENOMEM;
183 goto out_free;
184 }
185 836
186 /* initialize the PRNG, add 128 bits of entropy */ 837 if (prng_chunk_size < PRNG_CHUNKSIZE_SHA512_MIN
187 prng_seed(16); 838 || prng_chunk_size > PRNG_CHUNKSIZE_SHA512_MAX)
839 return -EINVAL;
840 prng_chunk_size = (prng_chunk_size + 0x3f) & ~0x3f;
188 841
189 ret = misc_register(&prng_dev); 842 if (prng_reseed_limit == 0)
190 if (ret) 843 prng_reseed_limit = PRNG_RESEED_LIMIT_SHA512;
191 goto out_buf; 844 else if (prng_reseed_limit < PRNG_RESEED_LIMIT_SHA512_LOWER)
192 return 0; 845 return -EINVAL;
846
847 ret = prng_sha512_instantiate();
848 if (ret)
849 goto out;
850
851 ret = misc_register(&prng_sha512_dev);
852 if (ret) {
853 prng_sha512_deinstantiate();
854 goto out;
855 }
856 ret = sysfs_create_group(&prng_sha512_dev.this_device->kobj,
857 &prng_sha512_dev_attr_group);
858 if (ret) {
859 misc_deregister(&prng_sha512_dev);
860 prng_sha512_deinstantiate();
861 goto out;
862 }
193 863
194out_buf: 864 } else {
195 kfree(p->buf); 865
196out_free: 866 /* TDES mode */
197 kfree(p); 867
868 if (prng_chunk_size < PRNG_CHUNKSIZE_TDES_MIN
869 || prng_chunk_size > PRNG_CHUNKSIZE_TDES_MAX)
870 return -EINVAL;
871 prng_chunk_size = (prng_chunk_size + 0x07) & ~0x07;
872
873 if (prng_reseed_limit == 0)
874 prng_reseed_limit = PRNG_RESEED_LIMIT_TDES;
875 else if (prng_reseed_limit < PRNG_RESEED_LIMIT_TDES_LOWER)
876 return -EINVAL;
877
878 ret = prng_tdes_instantiate();
879 if (ret)
880 goto out;
881
882 ret = misc_register(&prng_tdes_dev);
883 if (ret) {
884 prng_tdes_deinstantiate();
885 goto out;
886 }
887 ret = sysfs_create_group(&prng_tdes_dev.this_device->kobj,
888 &prng_tdes_dev_attr_group);
889 if (ret) {
890 misc_deregister(&prng_tdes_dev);
891 prng_tdes_deinstantiate();
892 goto out;
893 }
894
895 }
896
897out:
198 return ret; 898 return ret;
199} 899}
200 900
901
201static void __exit prng_exit(void) 902static void __exit prng_exit(void)
202{ 903{
203 /* wipe me */ 904 if (prng_mode == PRNG_MODE_SHA512) {
204 kzfree(p->buf); 905 sysfs_remove_group(&prng_sha512_dev.this_device->kobj,
205 kfree(p); 906 &prng_sha512_dev_attr_group);
206 907 misc_deregister(&prng_sha512_dev);
207 misc_deregister(&prng_dev); 908 prng_sha512_deinstantiate();
909 } else {
910 sysfs_remove_group(&prng_tdes_dev.this_device->kobj,
911 &prng_tdes_dev_attr_group);
912 misc_deregister(&prng_tdes_dev);
913 prng_tdes_deinstantiate();
914 }
208} 915}
209 916
917
210module_init(prng_init); 918module_init(prng_init);
211module_exit(prng_exit); 919module_exit(prng_exit);
diff --git a/arch/s390/include/asm/kexec.h b/arch/s390/include/asm/kexec.h
index 694bcd6bd927..2f924bc30e35 100644
--- a/arch/s390/include/asm/kexec.h
+++ b/arch/s390/include/asm/kexec.h
@@ -26,6 +26,9 @@
26/* Not more than 2GB */ 26/* Not more than 2GB */
27#define KEXEC_CONTROL_MEMORY_LIMIT (1UL<<31) 27#define KEXEC_CONTROL_MEMORY_LIMIT (1UL<<31)
28 28
29/* Allocate control page with GFP_DMA */
30#define KEXEC_CONTROL_MEMORY_GFP GFP_DMA
31
29/* Maximum address we can use for the crash control pages */ 32/* Maximum address we can use for the crash control pages */
30#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT (-1UL) 33#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT (-1UL)
31 34
diff --git a/arch/s390/include/asm/mmu.h b/arch/s390/include/asm/mmu.h
index a5e656260a70..d29ad9545b41 100644
--- a/arch/s390/include/asm/mmu.h
+++ b/arch/s390/include/asm/mmu.h
@@ -14,7 +14,9 @@ typedef struct {
14 unsigned long asce_bits; 14 unsigned long asce_bits;
15 unsigned long asce_limit; 15 unsigned long asce_limit;
16 unsigned long vdso_base; 16 unsigned long vdso_base;
17 /* The mmu context has extended page tables. */ 17 /* The mmu context allocates 4K page tables. */
18 unsigned int alloc_pgste:1;
19 /* The mmu context uses extended page tables. */
18 unsigned int has_pgste:1; 20 unsigned int has_pgste:1;
19 /* The mmu context uses storage keys. */ 21 /* The mmu context uses storage keys. */
20 unsigned int use_skey:1; 22 unsigned int use_skey:1;
diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h
index d25d9ff10ba8..fb1b93ea3e3f 100644
--- a/arch/s390/include/asm/mmu_context.h
+++ b/arch/s390/include/asm/mmu_context.h
@@ -20,8 +20,11 @@ static inline int init_new_context(struct task_struct *tsk,
20 mm->context.flush_mm = 0; 20 mm->context.flush_mm = 0;
21 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS; 21 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
22 mm->context.asce_bits |= _ASCE_TYPE_REGION3; 22 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
23#ifdef CONFIG_PGSTE
24 mm->context.alloc_pgste = page_table_allocate_pgste;
23 mm->context.has_pgste = 0; 25 mm->context.has_pgste = 0;
24 mm->context.use_skey = 0; 26 mm->context.use_skey = 0;
27#endif
25 mm->context.asce_limit = STACK_TOP_MAX; 28 mm->context.asce_limit = STACK_TOP_MAX;
26 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); 29 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
27 return 0; 30 return 0;
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index 51e7fb634ebc..7b7858f158b4 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -21,6 +21,7 @@ void crst_table_free(struct mm_struct *, unsigned long *);
21unsigned long *page_table_alloc(struct mm_struct *); 21unsigned long *page_table_alloc(struct mm_struct *);
22void page_table_free(struct mm_struct *, unsigned long *); 22void page_table_free(struct mm_struct *, unsigned long *);
23void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long); 23void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long);
24extern int page_table_allocate_pgste;
24 25
25int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, 26int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
26 unsigned long key, bool nq); 27 unsigned long key, bool nq);
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 989cfae9e202..fc642399b489 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -12,12 +12,9 @@
12#define _ASM_S390_PGTABLE_H 12#define _ASM_S390_PGTABLE_H
13 13
14/* 14/*
15 * The Linux memory management assumes a three-level page table setup. For 15 * The Linux memory management assumes a three-level page table setup.
16 * s390 31 bit we "fold" the mid level into the top-level page table, so 16 * For s390 64 bit we use up to four of the five levels the hardware
17 * that we physically have the same two-level page table as the s390 mmu 17 * provides (region first tables are not used).
18 * expects in 31 bit mode. For s390 64 bit we use three of the five levels
19 * the hardware provides (region first and region second tables are not
20 * used).
21 * 18 *
22 * The "pgd_xxx()" functions are trivial for a folded two-level 19 * The "pgd_xxx()" functions are trivial for a folded two-level
23 * setup: the pgd is never bad, and a pmd always exists (as it's folded 20 * setup: the pgd is never bad, and a pmd always exists (as it's folded
@@ -101,8 +98,8 @@ extern unsigned long zero_page_mask;
101 98
102#ifndef __ASSEMBLY__ 99#ifndef __ASSEMBLY__
103/* 100/*
104 * The vmalloc and module area will always be on the topmost area of the kernel 101 * The vmalloc and module area will always be on the topmost area of the
105 * mapping. We reserve 96MB (31bit) / 128GB (64bit) for vmalloc and modules. 102 * kernel mapping. We reserve 128GB (64bit) for vmalloc and modules.
106 * On 64 bit kernels we have a 2GB area at the top of the vmalloc area where 103 * On 64 bit kernels we have a 2GB area at the top of the vmalloc area where
107 * modules will reside. That makes sure that inter module branches always 104 * modules will reside. That makes sure that inter module branches always
108 * happen without trampolines and in addition the placement within a 2GB frame 105 * happen without trampolines and in addition the placement within a 2GB frame
@@ -131,38 +128,6 @@ static inline int is_module_addr(void *addr)
131} 128}
132 129
133/* 130/*
134 * A 31 bit pagetable entry of S390 has following format:
135 * | PFRA | | OS |
136 * 0 0IP0
137 * 00000000001111111111222222222233
138 * 01234567890123456789012345678901
139 *
140 * I Page-Invalid Bit: Page is not available for address-translation
141 * P Page-Protection Bit: Store access not possible for page
142 *
143 * A 31 bit segmenttable entry of S390 has following format:
144 * | P-table origin | |PTL
145 * 0 IC
146 * 00000000001111111111222222222233
147 * 01234567890123456789012345678901
148 *
149 * I Segment-Invalid Bit: Segment is not available for address-translation
150 * C Common-Segment Bit: Segment is not private (PoP 3-30)
151 * PTL Page-Table-Length: Page-table length (PTL+1*16 entries -> up to 256)
152 *
153 * The 31 bit segmenttable origin of S390 has following format:
154 *
155 * |S-table origin | | STL |
156 * X **GPS
157 * 00000000001111111111222222222233
158 * 01234567890123456789012345678901
159 *
160 * X Space-Switch event:
161 * G Segment-Invalid Bit: *
162 * P Private-Space Bit: Segment is not private (PoP 3-30)
163 * S Storage-Alteration:
164 * STL Segment-Table-Length: Segment-table length (STL+1*16 entries -> up to 2048)
165 *
166 * A 64 bit pagetable entry of S390 has following format: 131 * A 64 bit pagetable entry of S390 has following format:
167 * | PFRA |0IPC| OS | 132 * | PFRA |0IPC| OS |
168 * 0000000000111111111122222222223333333333444444444455555555556666 133 * 0000000000111111111122222222223333333333444444444455555555556666
@@ -220,7 +185,6 @@ static inline int is_module_addr(void *addr)
220 185
221/* Software bits in the page table entry */ 186/* Software bits in the page table entry */
222#define _PAGE_PRESENT 0x001 /* SW pte present bit */ 187#define _PAGE_PRESENT 0x001 /* SW pte present bit */
223#define _PAGE_TYPE 0x002 /* SW pte type bit */
224#define _PAGE_YOUNG 0x004 /* SW pte young bit */ 188#define _PAGE_YOUNG 0x004 /* SW pte young bit */
225#define _PAGE_DIRTY 0x008 /* SW pte dirty bit */ 189#define _PAGE_DIRTY 0x008 /* SW pte dirty bit */
226#define _PAGE_READ 0x010 /* SW pte read bit */ 190#define _PAGE_READ 0x010 /* SW pte read bit */
@@ -240,31 +204,34 @@ static inline int is_module_addr(void *addr)
240 * table lock held. 204 * table lock held.
241 * 205 *
242 * The following table gives the different possible bit combinations for 206 * The following table gives the different possible bit combinations for
243 * the pte hardware and software bits in the last 12 bits of a pte: 207 * the pte hardware and software bits in the last 12 bits of a pte
208 * (. unassigned bit, x don't care, t swap type):
244 * 209 *
245 * 842100000000 210 * 842100000000
246 * 000084210000 211 * 000084210000
247 * 000000008421 212 * 000000008421
248 * .IR...wrdytp 213 * .IR.uswrdy.p
249 * empty .10...000000 214 * empty .10.00000000
250 * swap .10...xxxx10 215 * swap .11..ttttt.0
251 * file .11...xxxxx0 216 * prot-none, clean, old .11.xx0000.1
252 * prot-none, clean, old .11...000001 217 * prot-none, clean, young .11.xx0001.1
253 * prot-none, clean, young .11...000101 218 * prot-none, dirty, old .10.xx0010.1
254 * prot-none, dirty, old .10...001001 219 * prot-none, dirty, young .10.xx0011.1
255 * prot-none, dirty, young .10...001101 220 * read-only, clean, old .11.xx0100.1
256 * read-only, clean, old .11...010001 221 * read-only, clean, young .01.xx0101.1
257 * read-only, clean, young .01...010101 222 * read-only, dirty, old .11.xx0110.1
258 * read-only, dirty, old .11...011001 223 * read-only, dirty, young .01.xx0111.1
259 * read-only, dirty, young .01...011101 224 * read-write, clean, old .11.xx1100.1
260 * read-write, clean, old .11...110001 225 * read-write, clean, young .01.xx1101.1
261 * read-write, clean, young .01...110101 226 * read-write, dirty, old .10.xx1110.1
262 * read-write, dirty, old .10...111001 227 * read-write, dirty, young .00.xx1111.1
263 * read-write, dirty, young .00...111101 228 * HW-bits: R read-only, I invalid
229 * SW-bits: p present, y young, d dirty, r read, w write, s special,
230 * u unused, l large
264 * 231 *
265 * pte_present is true for the bit pattern .xx...xxxxx1, (pte & 0x001) == 0x001 232 * pte_none is true for the bit pattern .10.00000000, pte == 0x400
266 * pte_none is true for the bit pattern .10...xxxx00, (pte & 0x603) == 0x400 233 * pte_swap is true for the bit pattern .11..ooooo.0, (pte & 0x201) == 0x200
267 * pte_swap is true for the bit pattern .10...xxxx10, (pte & 0x603) == 0x402 234 * pte_present is true for the bit pattern .xx.xxxxxx.1, (pte & 0x001) == 0x001
268 */ 235 */
269 236
270/* Bits in the segment/region table address-space-control-element */ 237/* Bits in the segment/region table address-space-control-element */
@@ -335,6 +302,8 @@ static inline int is_module_addr(void *addr)
335 * read-write, dirty, young 11..0...0...11 302 * read-write, dirty, young 11..0...0...11
336 * The segment table origin is used to distinguish empty (origin==0) from 303 * The segment table origin is used to distinguish empty (origin==0) from
337 * read-write, old segment table entries (origin!=0) 304 * read-write, old segment table entries (origin!=0)
305 * HW-bits: R read-only, I invalid
306 * SW-bits: y young, d dirty, r read, w write
338 */ 307 */
339 308
340#define _SEGMENT_ENTRY_SPLIT_BIT 11 /* THP splitting bit number */ 309#define _SEGMENT_ENTRY_SPLIT_BIT 11 /* THP splitting bit number */
@@ -423,6 +392,15 @@ static inline int mm_has_pgste(struct mm_struct *mm)
423 return 0; 392 return 0;
424} 393}
425 394
395static inline int mm_alloc_pgste(struct mm_struct *mm)
396{
397#ifdef CONFIG_PGSTE
398 if (unlikely(mm->context.alloc_pgste))
399 return 1;
400#endif
401 return 0;
402}
403
426/* 404/*
427 * In the case that a guest uses storage keys 405 * In the case that a guest uses storage keys
428 * faults should no longer be backed by zero pages 406 * faults should no longer be backed by zero pages
@@ -582,10 +560,9 @@ static inline int pte_none(pte_t pte)
582 560
583static inline int pte_swap(pte_t pte) 561static inline int pte_swap(pte_t pte)
584{ 562{
585 /* Bit pattern: (pte & 0x603) == 0x402 */ 563 /* Bit pattern: (pte & 0x201) == 0x200 */
586 return (pte_val(pte) & (_PAGE_INVALID | _PAGE_PROTECT | 564 return (pte_val(pte) & (_PAGE_PROTECT | _PAGE_PRESENT))
587 _PAGE_TYPE | _PAGE_PRESENT)) 565 == _PAGE_PROTECT;
588 == (_PAGE_INVALID | _PAGE_TYPE);
589} 566}
590 567
591static inline int pte_special(pte_t pte) 568static inline int pte_special(pte_t pte)
@@ -1586,51 +1563,51 @@ static inline int has_transparent_hugepage(void)
1586#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 1563#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1587 1564
1588/* 1565/*
1589 * 31 bit swap entry format:
1590 * A page-table entry has some bits we have to treat in a special way.
1591 * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
1592 * exception will occur instead of a page translation exception. The
1593 * specifiation exception has the bad habit not to store necessary
1594 * information in the lowcore.
1595 * Bits 21, 22, 30 and 31 are used to indicate the page type.
1596 * A swap pte is indicated by bit pattern (pte & 0x603) == 0x402
1597 * This leaves the bits 1-19 and bits 24-29 to store type and offset.
1598 * We use the 5 bits from 25-29 for the type and the 20 bits from 1-19
1599 * plus 24 for the offset.
1600 * 0| offset |0110|o|type |00|
1601 * 0 0000000001111111111 2222 2 22222 33
1602 * 0 1234567890123456789 0123 4 56789 01
1603 *
1604 * 64 bit swap entry format: 1566 * 64 bit swap entry format:
1605 * A page-table entry has some bits we have to treat in a special way. 1567 * A page-table entry has some bits we have to treat in a special way.
1606 * Bits 52 and bit 55 have to be zero, otherwise an specification 1568 * Bits 52 and bit 55 have to be zero, otherwise an specification
1607 * exception will occur instead of a page translation exception. The 1569 * exception will occur instead of a page translation exception. The
1608 * specifiation exception has the bad habit not to store necessary 1570 * specifiation exception has the bad habit not to store necessary
1609 * information in the lowcore. 1571 * information in the lowcore.
1610 * Bits 53, 54, 62 and 63 are used to indicate the page type. 1572 * Bits 54 and 63 are used to indicate the page type.
1611 * A swap pte is indicated by bit pattern (pte & 0x603) == 0x402 1573 * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200
1612 * This leaves the bits 0-51 and bits 56-61 to store type and offset. 1574 * This leaves the bits 0-51 and bits 56-62 to store type and offset.
1613 * We use the 5 bits from 57-61 for the type and the 53 bits from 0-51 1575 * We use the 5 bits from 57-61 for the type and the 52 bits from 0-51
1614 * plus 56 for the offset. 1576 * for the offset.
1615 * | offset |0110|o|type |00| 1577 * | offset |01100|type |00|
1616 * 0000000000111111111122222222223333333333444444444455 5555 5 55566 66 1578 * |0000000000111111111122222222223333333333444444444455|55555|55566|66|
1617 * 0123456789012345678901234567890123456789012345678901 2345 6 78901 23 1579 * |0123456789012345678901234567890123456789012345678901|23456|78901|23|
1618 */ 1580 */
1619 1581
1620#define __SWP_OFFSET_MASK (~0UL >> 11) 1582#define __SWP_OFFSET_MASK ((1UL << 52) - 1)
1583#define __SWP_OFFSET_SHIFT 12
1584#define __SWP_TYPE_MASK ((1UL << 5) - 1)
1585#define __SWP_TYPE_SHIFT 2
1621 1586
1622static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) 1587static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
1623{ 1588{
1624 pte_t pte; 1589 pte_t pte;
1625 offset &= __SWP_OFFSET_MASK; 1590
1626 pte_val(pte) = _PAGE_INVALID | _PAGE_TYPE | ((type & 0x1f) << 2) | 1591 pte_val(pte) = _PAGE_INVALID | _PAGE_PROTECT;
1627 ((offset & 1UL) << 7) | ((offset & ~1UL) << 11); 1592 pte_val(pte) |= (offset & __SWP_OFFSET_MASK) << __SWP_OFFSET_SHIFT;
1593 pte_val(pte) |= (type & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT;
1628 return pte; 1594 return pte;
1629} 1595}
1630 1596
1631#define __swp_type(entry) (((entry).val >> 2) & 0x1f) 1597static inline unsigned long __swp_type(swp_entry_t entry)
1632#define __swp_offset(entry) (((entry).val >> 11) | (((entry).val >> 7) & 1)) 1598{
1633#define __swp_entry(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) }) 1599 return (entry.val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK;
1600}
1601
1602static inline unsigned long __swp_offset(swp_entry_t entry)
1603{
1604 return (entry.val >> __SWP_OFFSET_SHIFT) & __SWP_OFFSET_MASK;
1605}
1606
1607static inline swp_entry_t __swp_entry(unsigned long type, unsigned long offset)
1608{
1609 return (swp_entry_t) { pte_val(mk_swap_pte(type, offset)) };
1610}
1634 1611
1635#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 1612#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
1636#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 1613#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index 210ffede0153..e617e74b7be2 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -14,20 +14,23 @@ static inline pmd_t __pte_to_pmd(pte_t pte)
14 14
15 /* 15 /*
16 * Convert encoding pte bits pmd bits 16 * Convert encoding pte bits pmd bits
17 * .IR...wrdytp dy..R...I...wr 17 * lIR.uswrdy.p dy..R...I...wr
18 * empty .10...000000 -> 00..0...1...00 18 * empty 010.000000.0 -> 00..0...1...00
19 * prot-none, clean, old .11...000001 -> 00..1...1...00 19 * prot-none, clean, old 111.000000.1 -> 00..1...1...00
20 * prot-none, clean, young .11...000101 -> 01..1...1...00 20 * prot-none, clean, young 111.000001.1 -> 01..1...1...00
21 * prot-none, dirty, old .10...001001 -> 10..1...1...00 21 * prot-none, dirty, old 111.000010.1 -> 10..1...1...00
22 * prot-none, dirty, young .10...001101 -> 11..1...1...00 22 * prot-none, dirty, young 111.000011.1 -> 11..1...1...00
23 * read-only, clean, old .11...010001 -> 00..1...1...01 23 * read-only, clean, old 111.000100.1 -> 00..1...1...01
24 * read-only, clean, young .01...010101 -> 01..1...0...01 24 * read-only, clean, young 101.000101.1 -> 01..1...0...01
25 * read-only, dirty, old .11...011001 -> 10..1...1...01 25 * read-only, dirty, old 111.000110.1 -> 10..1...1...01
26 * read-only, dirty, young .01...011101 -> 11..1...0...01 26 * read-only, dirty, young 101.000111.1 -> 11..1...0...01
27 * read-write, clean, old .11...110001 -> 00..0...1...11 27 * read-write, clean, old 111.001100.1 -> 00..1...1...11
28 * read-write, clean, young .01...110101 -> 01..0...0...11 28 * read-write, clean, young 101.001101.1 -> 01..1...0...11
29 * read-write, dirty, old .10...111001 -> 10..0...1...11 29 * read-write, dirty, old 110.001110.1 -> 10..0...1...11
30 * read-write, dirty, young .00...111101 -> 11..0...0...11 30 * read-write, dirty, young 100.001111.1 -> 11..0...0...11
31 * HW-bits: R read-only, I invalid
32 * SW-bits: p present, y young, d dirty, r read, w write, s special,
33 * u unused, l large
31 */ 34 */
32 if (pte_present(pte)) { 35 if (pte_present(pte)) {
33 pmd_val(pmd) = pte_val(pte) & PAGE_MASK; 36 pmd_val(pmd) = pte_val(pte) & PAGE_MASK;
@@ -48,20 +51,23 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
48 51
49 /* 52 /*
50 * Convert encoding pmd bits pte bits 53 * Convert encoding pmd bits pte bits
51 * dy..R...I...wr .IR...wrdytp 54 * dy..R...I...wr lIR.uswrdy.p
52 * empty 00..0...1...00 -> .10...001100 55 * empty 00..0...1...00 -> 010.000000.0
53 * prot-none, clean, old 00..0...1...00 -> .10...000001 56 * prot-none, clean, old 00..1...1...00 -> 111.000000.1
54 * prot-none, clean, young 01..0...1...00 -> .10...000101 57 * prot-none, clean, young 01..1...1...00 -> 111.000001.1
55 * prot-none, dirty, old 10..0...1...00 -> .10...001001 58 * prot-none, dirty, old 10..1...1...00 -> 111.000010.1
56 * prot-none, dirty, young 11..0...1...00 -> .10...001101 59 * prot-none, dirty, young 11..1...1...00 -> 111.000011.1
57 * read-only, clean, old 00..1...1...01 -> .11...010001 60 * read-only, clean, old 00..1...1...01 -> 111.000100.1
58 * read-only, clean, young 01..1...1...01 -> .11...010101 61 * read-only, clean, young 01..1...0...01 -> 101.000101.1
59 * read-only, dirty, old 10..1...1...01 -> .11...011001 62 * read-only, dirty, old 10..1...1...01 -> 111.000110.1
60 * read-only, dirty, young 11..1...1...01 -> .11...011101 63 * read-only, dirty, young 11..1...0...01 -> 101.000111.1
61 * read-write, clean, old 00..0...1...11 -> .10...110001 64 * read-write, clean, old 00..1...1...11 -> 111.001100.1
62 * read-write, clean, young 01..0...1...11 -> .10...110101 65 * read-write, clean, young 01..1...0...11 -> 101.001101.1
63 * read-write, dirty, old 10..0...1...11 -> .10...111001 66 * read-write, dirty, old 10..0...1...11 -> 110.001110.1
64 * read-write, dirty, young 11..0...1...11 -> .10...111101 67 * read-write, dirty, young 11..0...0...11 -> 100.001111.1
68 * HW-bits: R read-only, I invalid
69 * SW-bits: p present, y young, d dirty, r read, w write, s special,
70 * u unused, l large
65 */ 71 */
66 if (pmd_present(pmd)) { 72 if (pmd_present(pmd)) {
67 pte_val(pte) = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN_LARGE; 73 pte_val(pte) = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN_LARGE;
@@ -70,8 +76,8 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
70 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) << 4; 76 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) << 4;
71 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) << 5; 77 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) << 5;
72 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT); 78 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT);
73 pmd_val(pmd) |= (pte_val(pte) & _PAGE_DIRTY) << 10; 79 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY) >> 10;
74 pmd_val(pmd) |= (pte_val(pte) & _PAGE_YOUNG) << 10; 80 pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG) >> 10;
75 } else 81 } else
76 pte_val(pte) = _PAGE_INVALID; 82 pte_val(pte) = _PAGE_INVALID;
77 return pte; 83 return pte;
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 33f589459113..b33f66110ca9 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -18,6 +18,7 @@
18#include <linux/rcupdate.h> 18#include <linux/rcupdate.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/swapops.h> 20#include <linux/swapops.h>
21#include <linux/sysctl.h>
21#include <linux/ksm.h> 22#include <linux/ksm.h>
22#include <linux/mman.h> 23#include <linux/mman.h>
23 24
@@ -920,6 +921,40 @@ unsigned long get_guest_storage_key(struct mm_struct *mm, unsigned long addr)
920} 921}
921EXPORT_SYMBOL(get_guest_storage_key); 922EXPORT_SYMBOL(get_guest_storage_key);
922 923
924static int page_table_allocate_pgste_min = 0;
925static int page_table_allocate_pgste_max = 1;
926int page_table_allocate_pgste = 0;
927EXPORT_SYMBOL(page_table_allocate_pgste);
928
929static struct ctl_table page_table_sysctl[] = {
930 {
931 .procname = "allocate_pgste",
932 .data = &page_table_allocate_pgste,
933 .maxlen = sizeof(int),
934 .mode = S_IRUGO | S_IWUSR,
935 .proc_handler = proc_dointvec,
936 .extra1 = &page_table_allocate_pgste_min,
937 .extra2 = &page_table_allocate_pgste_max,
938 },
939 { }
940};
941
942static struct ctl_table page_table_sysctl_dir[] = {
943 {
944 .procname = "vm",
945 .maxlen = 0,
946 .mode = 0555,
947 .child = page_table_sysctl,
948 },
949 { }
950};
951
952static int __init page_table_register_sysctl(void)
953{
954 return register_sysctl_table(page_table_sysctl_dir) ? 0 : -ENOMEM;
955}
956__initcall(page_table_register_sysctl);
957
923#else /* CONFIG_PGSTE */ 958#else /* CONFIG_PGSTE */
924 959
925static inline int page_table_with_pgste(struct page *page) 960static inline int page_table_with_pgste(struct page *page)
@@ -963,7 +998,7 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
963 struct page *uninitialized_var(page); 998 struct page *uninitialized_var(page);
964 unsigned int mask, bit; 999 unsigned int mask, bit;
965 1000
966 if (mm_has_pgste(mm)) 1001 if (mm_alloc_pgste(mm))
967 return page_table_alloc_pgste(mm); 1002 return page_table_alloc_pgste(mm);
968 /* Allocate fragments of a 4K page as 1K/2K page table */ 1003 /* Allocate fragments of a 4K page as 1K/2K page table */
969 spin_lock_bh(&mm->context.list_lock); 1004 spin_lock_bh(&mm->context.list_lock);
@@ -1165,116 +1200,25 @@ static inline void thp_split_mm(struct mm_struct *mm)
1165} 1200}
1166#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 1201#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
1167 1202
1168static unsigned long page_table_realloc_pmd(struct mmu_gather *tlb,
1169 struct mm_struct *mm, pud_t *pud,
1170 unsigned long addr, unsigned long end)
1171{
1172 unsigned long next, *table, *new;
1173 struct page *page;
1174 spinlock_t *ptl;
1175 pmd_t *pmd;
1176
1177 pmd = pmd_offset(pud, addr);
1178 do {
1179 next = pmd_addr_end(addr, end);
1180again:
1181 if (pmd_none_or_clear_bad(pmd))
1182 continue;
1183 table = (unsigned long *) pmd_deref(*pmd);
1184 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
1185 if (page_table_with_pgste(page))
1186 continue;
1187 /* Allocate new page table with pgstes */
1188 new = page_table_alloc_pgste(mm);
1189 if (!new)
1190 return -ENOMEM;
1191
1192 ptl = pmd_lock(mm, pmd);
1193 if (likely((unsigned long *) pmd_deref(*pmd) == table)) {
1194 /* Nuke pmd entry pointing to the "short" page table */
1195 pmdp_flush_lazy(mm, addr, pmd);
1196 pmd_clear(pmd);
1197 /* Copy ptes from old table to new table */
1198 memcpy(new, table, PAGE_SIZE/2);
1199 clear_table(table, _PAGE_INVALID, PAGE_SIZE/2);
1200 /* Establish new table */
1201 pmd_populate(mm, pmd, (pte_t *) new);
1202 /* Free old table with rcu, there might be a walker! */
1203 page_table_free_rcu(tlb, table, addr);
1204 new = NULL;
1205 }
1206 spin_unlock(ptl);
1207 if (new) {
1208 page_table_free_pgste(new);
1209 goto again;
1210 }
1211 } while (pmd++, addr = next, addr != end);
1212
1213 return addr;
1214}
1215
1216static unsigned long page_table_realloc_pud(struct mmu_gather *tlb,
1217 struct mm_struct *mm, pgd_t *pgd,
1218 unsigned long addr, unsigned long end)
1219{
1220 unsigned long next;
1221 pud_t *pud;
1222
1223 pud = pud_offset(pgd, addr);
1224 do {
1225 next = pud_addr_end(addr, end);
1226 if (pud_none_or_clear_bad(pud))
1227 continue;
1228 next = page_table_realloc_pmd(tlb, mm, pud, addr, next);
1229 if (unlikely(IS_ERR_VALUE(next)))
1230 return next;
1231 } while (pud++, addr = next, addr != end);
1232
1233 return addr;
1234}
1235
1236static unsigned long page_table_realloc(struct mmu_gather *tlb, struct mm_struct *mm,
1237 unsigned long addr, unsigned long end)
1238{
1239 unsigned long next;
1240 pgd_t *pgd;
1241
1242 pgd = pgd_offset(mm, addr);
1243 do {
1244 next = pgd_addr_end(addr, end);
1245 if (pgd_none_or_clear_bad(pgd))
1246 continue;
1247 next = page_table_realloc_pud(tlb, mm, pgd, addr, next);
1248 if (unlikely(IS_ERR_VALUE(next)))
1249 return next;
1250 } while (pgd++, addr = next, addr != end);
1251
1252 return 0;
1253}
1254
1255/* 1203/*
1256 * switch on pgstes for its userspace process (for kvm) 1204 * switch on pgstes for its userspace process (for kvm)
1257 */ 1205 */
1258int s390_enable_sie(void) 1206int s390_enable_sie(void)
1259{ 1207{
1260 struct task_struct *tsk = current; 1208 struct mm_struct *mm = current->mm;
1261 struct mm_struct *mm = tsk->mm;
1262 struct mmu_gather tlb;
1263 1209
1264 /* Do we have pgstes? if yes, we are done */ 1210 /* Do we have pgstes? if yes, we are done */
1265 if (mm_has_pgste(tsk->mm)) 1211 if (mm_has_pgste(mm))
1266 return 0; 1212 return 0;
1267 1213 /* Fail if the page tables are 2K */
1214 if (!mm_alloc_pgste(mm))
1215 return -EINVAL;
1268 down_write(&mm->mmap_sem); 1216 down_write(&mm->mmap_sem);
1217 mm->context.has_pgste = 1;
1269 /* split thp mappings and disable thp for future mappings */ 1218 /* split thp mappings and disable thp for future mappings */
1270 thp_split_mm(mm); 1219 thp_split_mm(mm);
1271 /* Reallocate the page tables with pgstes */
1272 tlb_gather_mmu(&tlb, mm, 0, TASK_SIZE);
1273 if (!page_table_realloc(&tlb, mm, 0, TASK_SIZE))
1274 mm->context.has_pgste = 1;
1275 tlb_finish_mmu(&tlb, 0, TASK_SIZE);
1276 up_write(&mm->mmap_sem); 1220 up_write(&mm->mmap_sem);
1277 return mm->context.has_pgste ? 0 : -ENOMEM; 1221 return 0;
1278} 1222}
1279EXPORT_SYMBOL_GPL(s390_enable_sie); 1223EXPORT_SYMBOL_GPL(s390_enable_sie);
1280 1224
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
index 6873f006f7d0..d366675e4bf8 100644
--- a/arch/tile/kernel/setup.c
+++ b/arch/tile/kernel/setup.c
@@ -774,7 +774,7 @@ static void __init zone_sizes_init(void)
774 * though, there'll be no lowmem, so we just alloc_bootmem 774 * though, there'll be no lowmem, so we just alloc_bootmem
775 * the memmap. There will be no percpu memory either. 775 * the memmap. There will be no percpu memory either.
776 */ 776 */
777 if (i != 0 && cpumask_test_cpu(i, &isolnodes)) { 777 if (i != 0 && node_isset(i, isolnodes)) {
778 node_memmap_pfn[i] = 778 node_memmap_pfn[i] =
779 alloc_bootmem_pfn(0, memmap_size, 0); 779 alloc_bootmem_pfn(0, memmap_size, 0);
780 BUG_ON(node_percpu[i] != 0); 780 BUG_ON(node_percpu[i] != 0);
diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 25b1cc07d496..d6b078e9fa28 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -95,7 +95,6 @@ unsigned __pvclock_read_cycles(const struct pvclock_vcpu_time_info *src,
95 95
96struct pvclock_vsyscall_time_info { 96struct pvclock_vsyscall_time_info {
97 struct pvclock_vcpu_time_info pvti; 97 struct pvclock_vcpu_time_info pvti;
98 u32 migrate_count;
99} __attribute__((__aligned__(SMP_CACHE_BYTES))); 98} __attribute__((__aligned__(SMP_CACHE_BYTES)));
100 99
101#define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info) 100#define PVTI_SIZE sizeof(struct pvclock_vsyscall_time_info)
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index e5ecd20e72dd..2f355d229a58 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -141,46 +141,7 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall_clock,
141 set_normalized_timespec(ts, now.tv_sec, now.tv_nsec); 141 set_normalized_timespec(ts, now.tv_sec, now.tv_nsec);
142} 142}
143 143
144static struct pvclock_vsyscall_time_info *pvclock_vdso_info;
145
146static struct pvclock_vsyscall_time_info *
147pvclock_get_vsyscall_user_time_info(int cpu)
148{
149 if (!pvclock_vdso_info) {
150 BUG();
151 return NULL;
152 }
153
154 return &pvclock_vdso_info[cpu];
155}
156
157struct pvclock_vcpu_time_info *pvclock_get_vsyscall_time_info(int cpu)
158{
159 return &pvclock_get_vsyscall_user_time_info(cpu)->pvti;
160}
161
162#ifdef CONFIG_X86_64 144#ifdef CONFIG_X86_64
163static int pvclock_task_migrate(struct notifier_block *nb, unsigned long l,
164 void *v)
165{
166 struct task_migration_notifier *mn = v;
167 struct pvclock_vsyscall_time_info *pvti;
168
169 pvti = pvclock_get_vsyscall_user_time_info(mn->from_cpu);
170
171 /* this is NULL when pvclock vsyscall is not initialized */
172 if (unlikely(pvti == NULL))
173 return NOTIFY_DONE;
174
175 pvti->migrate_count++;
176
177 return NOTIFY_DONE;
178}
179
180static struct notifier_block pvclock_migrate = {
181 .notifier_call = pvclock_task_migrate,
182};
183
184/* 145/*
185 * Initialize the generic pvclock vsyscall state. This will allocate 146 * Initialize the generic pvclock vsyscall state. This will allocate
186 * a/some page(s) for the per-vcpu pvclock information, set up a 147 * a/some page(s) for the per-vcpu pvclock information, set up a
@@ -194,17 +155,12 @@ int __init pvclock_init_vsyscall(struct pvclock_vsyscall_time_info *i,
194 155
195 WARN_ON (size != PVCLOCK_VSYSCALL_NR_PAGES*PAGE_SIZE); 156 WARN_ON (size != PVCLOCK_VSYSCALL_NR_PAGES*PAGE_SIZE);
196 157
197 pvclock_vdso_info = i;
198
199 for (idx = 0; idx <= (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) { 158 for (idx = 0; idx <= (PVCLOCK_FIXMAP_END-PVCLOCK_FIXMAP_BEGIN); idx++) {
200 __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx, 159 __set_fixmap(PVCLOCK_FIXMAP_BEGIN + idx,
201 __pa(i) + (idx*PAGE_SIZE), 160 __pa(i) + (idx*PAGE_SIZE),
202 PAGE_KERNEL_VVAR); 161 PAGE_KERNEL_VVAR);
203 } 162 }
204 163
205
206 register_task_migration_notifier(&pvclock_migrate);
207
208 return 0; 164 return 0;
209} 165}
210#endif 166#endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ed31c31b2485..c73efcd03e29 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1669,12 +1669,28 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
1669 &guest_hv_clock, sizeof(guest_hv_clock)))) 1669 &guest_hv_clock, sizeof(guest_hv_clock))))
1670 return 0; 1670 return 0;
1671 1671
1672 /* 1672 /* This VCPU is paused, but it's legal for a guest to read another
1673 * The interface expects us to write an even number signaling that the 1673 * VCPU's kvmclock, so we really have to follow the specification where
1674 * update is finished. Since the guest won't see the intermediate 1674 * it says that version is odd if data is being modified, and even after
1675 * state, we just increase by 2 at the end. 1675 * it is consistent.
1676 *
1677 * Version field updates must be kept separate. This is because
1678 * kvm_write_guest_cached might use a "rep movs" instruction, and
1679 * writes within a string instruction are weakly ordered. So there
1680 * are three writes overall.
1681 *
1682 * As a small optimization, only write the version field in the first
1683 * and third write. The vcpu->pv_time cache is still valid, because the
1684 * version field is the first in the struct.
1676 */ 1685 */
1677 vcpu->hv_clock.version = guest_hv_clock.version + 2; 1686 BUILD_BUG_ON(offsetof(struct pvclock_vcpu_time_info, version) != 0);
1687
1688 vcpu->hv_clock.version = guest_hv_clock.version + 1;
1689 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1690 &vcpu->hv_clock,
1691 sizeof(vcpu->hv_clock.version));
1692
1693 smp_wmb();
1678 1694
1679 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */ 1695 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
1680 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED); 1696 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
@@ -1695,6 +1711,13 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
1695 kvm_write_guest_cached(v->kvm, &vcpu->pv_time, 1711 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1696 &vcpu->hv_clock, 1712 &vcpu->hv_clock,
1697 sizeof(vcpu->hv_clock)); 1713 sizeof(vcpu->hv_clock));
1714
1715 smp_wmb();
1716
1717 vcpu->hv_clock.version++;
1718 kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
1719 &vcpu->hv_clock,
1720 sizeof(vcpu->hv_clock.version));
1698 return 0; 1721 return 0;
1699} 1722}
1700 1723
diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
index 40d2473836c9..9793322751e0 100644
--- a/arch/x86/vdso/vclock_gettime.c
+++ b/arch/x86/vdso/vclock_gettime.c
@@ -82,15 +82,18 @@ static notrace cycle_t vread_pvclock(int *mode)
82 cycle_t ret; 82 cycle_t ret;
83 u64 last; 83 u64 last;
84 u32 version; 84 u32 version;
85 u32 migrate_count;
86 u8 flags; 85 u8 flags;
87 unsigned cpu, cpu1; 86 unsigned cpu, cpu1;
88 87
89 88
90 /* 89 /*
91 * When looping to get a consistent (time-info, tsc) pair, we 90 * Note: hypervisor must guarantee that:
92 * also need to deal with the possibility we can switch vcpus, 91 * 1. cpu ID number maps 1:1 to per-CPU pvclock time info.
93 * so make sure we always re-fetch time-info for the current vcpu. 92 * 2. that per-CPU pvclock time info is updated if the
93 * underlying CPU changes.
94 * 3. that version is increased whenever underlying CPU
95 * changes.
96 *
94 */ 97 */
95 do { 98 do {
96 cpu = __getcpu() & VGETCPU_CPU_MASK; 99 cpu = __getcpu() & VGETCPU_CPU_MASK;
@@ -99,27 +102,20 @@ static notrace cycle_t vread_pvclock(int *mode)
99 * __getcpu() calls (Gleb). 102 * __getcpu() calls (Gleb).
100 */ 103 */
101 104
102 /* Make sure migrate_count will change if we leave the VCPU. */ 105 pvti = get_pvti(cpu);
103 do {
104 pvti = get_pvti(cpu);
105 migrate_count = pvti->migrate_count;
106
107 cpu1 = cpu;
108 cpu = __getcpu() & VGETCPU_CPU_MASK;
109 } while (unlikely(cpu != cpu1));
110 106
111 version = __pvclock_read_cycles(&pvti->pvti, &ret, &flags); 107 version = __pvclock_read_cycles(&pvti->pvti, &ret, &flags);
112 108
113 /* 109 /*
114 * Test we're still on the cpu as well as the version. 110 * Test we're still on the cpu as well as the version.
115 * - We must read TSC of pvti's VCPU. 111 * We could have been migrated just after the first
116 * - KVM doesn't follow the versioning protocol, so data could 112 * vgetcpu but before fetching the version, so we
117 * change before version if we left the VCPU. 113 * wouldn't notice a version change.
118 */ 114 */
119 smp_rmb(); 115 cpu1 = __getcpu() & VGETCPU_CPU_MASK;
120 } while (unlikely((pvti->pvti.version & 1) || 116 } while (unlikely(cpu != cpu1 ||
121 pvti->pvti.version != version || 117 (pvti->pvti.version & 1) ||
122 pvti->migrate_count != migrate_count)); 118 pvti->pvti.version != version));
123 119
124 if (unlikely(!(flags & PVCLOCK_TSC_STABLE_BIT))) 120 if (unlikely(!(flags & PVCLOCK_TSC_STABLE_BIT)))
125 *mode = VCLOCK_NONE; 121 *mode = VCLOCK_NONE;
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index c8a18e4ee9dc..720ceeb7fa9b 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1298,21 +1298,22 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1298 goto err_unlock_md_type; 1298 goto err_unlock_md_type;
1299 } 1299 }
1300 1300
1301 if (dm_get_md_type(md) == DM_TYPE_NONE) 1301 if (dm_get_md_type(md) == DM_TYPE_NONE) {
1302 /* Initial table load: acquire type of table. */ 1302 /* Initial table load: acquire type of table. */
1303 dm_set_md_type(md, dm_table_get_type(t)); 1303 dm_set_md_type(md, dm_table_get_type(t));
1304 else if (dm_get_md_type(md) != dm_table_get_type(t)) { 1304
1305 /* setup md->queue to reflect md's type (may block) */
1306 r = dm_setup_md_queue(md);
1307 if (r) {
1308 DMWARN("unable to set up device queue for new table.");
1309 goto err_unlock_md_type;
1310 }
1311 } else if (dm_get_md_type(md) != dm_table_get_type(t)) {
1305 DMWARN("can't change device type after initial table load."); 1312 DMWARN("can't change device type after initial table load.");
1306 r = -EINVAL; 1313 r = -EINVAL;
1307 goto err_unlock_md_type; 1314 goto err_unlock_md_type;
1308 } 1315 }
1309 1316
1310 /* setup md->queue to reflect md's type (may block) */
1311 r = dm_setup_md_queue(md);
1312 if (r) {
1313 DMWARN("unable to set up device queue for new table.");
1314 goto err_unlock_md_type;
1315 }
1316 dm_unlock_md_type(md); 1317 dm_unlock_md_type(md);
1317 1318
1318 /* stage inactive table */ 1319 /* stage inactive table */
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f8c7ca3e8947..a930b72314ac 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1082,18 +1082,26 @@ static void rq_completed(struct mapped_device *md, int rw, bool run_queue)
1082 dm_put(md); 1082 dm_put(md);
1083} 1083}
1084 1084
1085static void free_rq_clone(struct request *clone) 1085static void free_rq_clone(struct request *clone, bool must_be_mapped)
1086{ 1086{
1087 struct dm_rq_target_io *tio = clone->end_io_data; 1087 struct dm_rq_target_io *tio = clone->end_io_data;
1088 struct mapped_device *md = tio->md; 1088 struct mapped_device *md = tio->md;
1089 1089
1090 WARN_ON_ONCE(must_be_mapped && !clone->q);
1091
1090 blk_rq_unprep_clone(clone); 1092 blk_rq_unprep_clone(clone);
1091 1093
1092 if (clone->q->mq_ops) 1094 if (md->type == DM_TYPE_MQ_REQUEST_BASED)
1095 /* stacked on blk-mq queue(s) */
1093 tio->ti->type->release_clone_rq(clone); 1096 tio->ti->type->release_clone_rq(clone);
1094 else if (!md->queue->mq_ops) 1097 else if (!md->queue->mq_ops)
1095 /* request_fn queue stacked on request_fn queue(s) */ 1098 /* request_fn queue stacked on request_fn queue(s) */
1096 free_clone_request(md, clone); 1099 free_clone_request(md, clone);
1100 /*
1101 * NOTE: for the blk-mq queue stacked on request_fn queue(s) case:
1102 * no need to call free_clone_request() because we leverage blk-mq by
1103 * allocating the clone at the end of the blk-mq pdu (see: clone_rq)
1104 */
1097 1105
1098 if (!md->queue->mq_ops) 1106 if (!md->queue->mq_ops)
1099 free_rq_tio(tio); 1107 free_rq_tio(tio);
@@ -1124,7 +1132,7 @@ static void dm_end_request(struct request *clone, int error)
1124 rq->sense_len = clone->sense_len; 1132 rq->sense_len = clone->sense_len;
1125 } 1133 }
1126 1134
1127 free_rq_clone(clone); 1135 free_rq_clone(clone, true);
1128 if (!rq->q->mq_ops) 1136 if (!rq->q->mq_ops)
1129 blk_end_request_all(rq, error); 1137 blk_end_request_all(rq, error);
1130 else 1138 else
@@ -1143,7 +1151,7 @@ static void dm_unprep_request(struct request *rq)
1143 } 1151 }
1144 1152
1145 if (clone) 1153 if (clone)
1146 free_rq_clone(clone); 1154 free_rq_clone(clone, false);
1147} 1155}
1148 1156
1149/* 1157/*
@@ -2662,9 +2670,6 @@ static int dm_init_request_based_queue(struct mapped_device *md)
2662{ 2670{
2663 struct request_queue *q = NULL; 2671 struct request_queue *q = NULL;
2664 2672
2665 if (md->queue->elevator)
2666 return 0;
2667
2668 /* Fully initialize the queue */ 2673 /* Fully initialize the queue */
2669 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL); 2674 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL);
2670 if (!q) 2675 if (!q)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 78dde56ae6e6..3a10551d64cf 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -82,6 +82,8 @@
82#include <net/bond_3ad.h> 82#include <net/bond_3ad.h>
83#include <net/bond_alb.h> 83#include <net/bond_alb.h>
84 84
85#include "bonding_priv.h"
86
85/*---------------------------- Module parameters ----------------------------*/ 87/*---------------------------- Module parameters ----------------------------*/
86 88
87/* monitor all links that often (in milliseconds). <=0 disables monitoring */ 89/* monitor all links that often (in milliseconds). <=0 disables monitoring */
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index 62694cfc05b6..b20b35acb47d 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -4,6 +4,7 @@
4#include <net/netns/generic.h> 4#include <net/netns/generic.h>
5#include <net/bonding.h> 5#include <net/bonding.h>
6 6
7#include "bonding_priv.h"
7 8
8static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) 9static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
9 __acquires(RCU) 10 __acquires(RCU)
diff --git a/drivers/net/bonding/bonding_priv.h b/drivers/net/bonding/bonding_priv.h
new file mode 100644
index 000000000000..5a4d81a9437c
--- /dev/null
+++ b/drivers/net/bonding/bonding_priv.h
@@ -0,0 +1,25 @@
1/*
2 * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
3 *
4 * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
5 * NCM: Network and Communications Management, Inc.
6 *
7 * BUT, I'm the one who modified it for ethernet, so:
8 * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
9 *
10 * This software may be used and distributed according to the terms
11 * of the GNU Public License, incorporated herein by reference.
12 *
13 */
14
15#ifndef _BONDING_PRIV_H
16#define _BONDING_PRIV_H
17
18#define DRV_VERSION "3.7.1"
19#define DRV_RELDATE "April 27, 2011"
20#define DRV_NAME "bonding"
21#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
22
23#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
24
25#endif
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 58808f651452..e8c96b8e86f4 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -112,7 +112,7 @@ config PCH_CAN
112 112
113config CAN_GRCAN 113config CAN_GRCAN
114 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices" 114 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices"
115 depends on OF 115 depends on OF && HAS_DMA
116 ---help--- 116 ---help---
117 Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN. 117 Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN.
118 Note that the driver supports little endian, even though little 118 Note that the driver supports little endian, even though little
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 4643914859b2..8b17a9065b0b 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1102,7 +1102,7 @@ static void kvaser_usb_rx_can_err(const struct kvaser_usb_net_priv *priv,
1102 1102
1103 if (msg->u.rx_can_header.flag & (MSG_FLAG_ERROR_FRAME | 1103 if (msg->u.rx_can_header.flag & (MSG_FLAG_ERROR_FRAME |
1104 MSG_FLAG_NERR)) { 1104 MSG_FLAG_NERR)) {
1105 netdev_err(priv->netdev, "Unknow error (flags: 0x%02x)\n", 1105 netdev_err(priv->netdev, "Unknown error (flags: 0x%02x)\n",
1106 msg->u.rx_can_header.flag); 1106 msg->u.rx_can_header.flag);
1107 1107
1108 stats->rx_errors++; 1108 stats->rx_errors++;
diff --git a/drivers/net/ethernet/8390/etherh.c b/drivers/net/ethernet/8390/etherh.c
index b36ee9e0d220..d686b9cac29f 100644
--- a/drivers/net/ethernet/8390/etherh.c
+++ b/drivers/net/ethernet/8390/etherh.c
@@ -523,7 +523,7 @@ static int etherh_addr(char *addr, struct expansion_card *ec)
523 char *s; 523 char *s;
524 524
525 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) { 525 if (!ecard_readchunk(&cd, ec, 0xf5, 0)) {
526 printk(KERN_ERR "%s: unable to read podule description string\n", 526 printk(KERN_ERR "%s: unable to read module description string\n",
527 dev_name(&ec->dev)); 527 dev_name(&ec->dev));
528 goto no_addr; 528 goto no_addr;
529 } 529 }
diff --git a/drivers/net/ethernet/altera/altera_msgdmahw.h b/drivers/net/ethernet/altera/altera_msgdmahw.h
index eba070f16782..89cd11d86642 100644
--- a/drivers/net/ethernet/altera/altera_msgdmahw.h
+++ b/drivers/net/ethernet/altera/altera_msgdmahw.h
@@ -58,15 +58,12 @@ struct msgdma_extended_desc {
58/* Tx buffer control flags 58/* Tx buffer control flags
59 */ 59 */
60#define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \ 60#define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \
61 MSGDMA_DESC_CTL_TR_ERR_IRQ | \
62 MSGDMA_DESC_CTL_GO) 61 MSGDMA_DESC_CTL_GO)
63 62
64#define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 63#define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_GO)
65 MSGDMA_DESC_CTL_GO)
66 64
67#define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \ 65#define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \
68 MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 66 MSGDMA_DESC_CTL_TR_COMP_IRQ | \
69 MSGDMA_DESC_CTL_TR_ERR_IRQ | \
70 MSGDMA_DESC_CTL_GO) 67 MSGDMA_DESC_CTL_GO)
71 68
72#define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \ 69#define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index 90a76306ad0f..0533c051a3e5 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -777,6 +777,8 @@ static int init_phy(struct net_device *dev)
777 struct altera_tse_private *priv = netdev_priv(dev); 777 struct altera_tse_private *priv = netdev_priv(dev);
778 struct phy_device *phydev; 778 struct phy_device *phydev;
779 struct device_node *phynode; 779 struct device_node *phynode;
780 bool fixed_link = false;
781 int rc = 0;
780 782
781 /* Avoid init phy in case of no phy present */ 783 /* Avoid init phy in case of no phy present */
782 if (!priv->phy_iface) 784 if (!priv->phy_iface)
@@ -789,13 +791,32 @@ static int init_phy(struct net_device *dev)
789 phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0); 791 phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0);
790 792
791 if (!phynode) { 793 if (!phynode) {
792 netdev_dbg(dev, "no phy-handle found\n"); 794 /* check if a fixed-link is defined in device-tree */
793 if (!priv->mdio) { 795 if (of_phy_is_fixed_link(priv->device->of_node)) {
794 netdev_err(dev, 796 rc = of_phy_register_fixed_link(priv->device->of_node);
795 "No phy-handle nor local mdio specified\n"); 797 if (rc < 0) {
796 return -ENODEV; 798 netdev_err(dev, "cannot register fixed PHY\n");
799 return rc;
800 }
801
802 /* In the case of a fixed PHY, the DT node associated
803 * to the PHY is the Ethernet MAC DT node.
804 */
805 phynode = of_node_get(priv->device->of_node);
806 fixed_link = true;
807
808 netdev_dbg(dev, "fixed-link detected\n");
809 phydev = of_phy_connect(dev, phynode,
810 &altera_tse_adjust_link,
811 0, priv->phy_iface);
812 } else {
813 netdev_dbg(dev, "no phy-handle found\n");
814 if (!priv->mdio) {
815 netdev_err(dev, "No phy-handle nor local mdio specified\n");
816 return -ENODEV;
817 }
818 phydev = connect_local_phy(dev);
797 } 819 }
798 phydev = connect_local_phy(dev);
799 } else { 820 } else {
800 netdev_dbg(dev, "phy-handle found\n"); 821 netdev_dbg(dev, "phy-handle found\n");
801 phydev = of_phy_connect(dev, phynode, 822 phydev = of_phy_connect(dev, phynode,
@@ -819,10 +840,10 @@ static int init_phy(struct net_device *dev)
819 /* Broken HW is sometimes missing the pull-up resistor on the 840 /* Broken HW is sometimes missing the pull-up resistor on the
820 * MDIO line, which results in reads to non-existent devices returning 841 * MDIO line, which results in reads to non-existent devices returning
821 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent 842 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
822 * device as well. 843 * device as well. If a fixed-link is used the phy_id is always 0.
823 * Note: phydev->phy_id is the result of reading the UID PHY registers. 844 * Note: phydev->phy_id is the result of reading the UID PHY registers.
824 */ 845 */
825 if (phydev->phy_id == 0) { 846 if ((phydev->phy_id == 0) && !fixed_link) {
826 netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id); 847 netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id);
827 phy_disconnect(phydev); 848 phy_disconnect(phydev);
828 return -ENODEV; 849 return -ENODEV;
diff --git a/drivers/net/ethernet/amd/Kconfig b/drivers/net/ethernet/amd/Kconfig
index c638c85f3954..089c269637b7 100644
--- a/drivers/net/ethernet/amd/Kconfig
+++ b/drivers/net/ethernet/amd/Kconfig
@@ -179,7 +179,7 @@ config SUNLANCE
179 179
180config AMD_XGBE 180config AMD_XGBE
181 tristate "AMD 10GbE Ethernet driver" 181 tristate "AMD 10GbE Ethernet driver"
182 depends on (OF_NET || ACPI) && HAS_IOMEM 182 depends on (OF_NET || ACPI) && HAS_IOMEM && HAS_DMA
183 select PHYLIB 183 select PHYLIB
184 select AMD_XGBE_PHY 184 select AMD_XGBE_PHY
185 select BITREVERSE 185 select BITREVERSE
diff --git a/drivers/net/ethernet/arc/Kconfig b/drivers/net/ethernet/arc/Kconfig
index 8e262e2b39b6..dea29ee24da4 100644
--- a/drivers/net/ethernet/arc/Kconfig
+++ b/drivers/net/ethernet/arc/Kconfig
@@ -25,8 +25,7 @@ config ARC_EMAC_CORE
25config ARC_EMAC 25config ARC_EMAC
26 tristate "ARC EMAC support" 26 tristate "ARC EMAC support"
27 select ARC_EMAC_CORE 27 select ARC_EMAC_CORE
28 depends on OF_IRQ 28 depends on OF_IRQ && OF_NET && HAS_DMA
29 depends on OF_NET
30 ---help--- 29 ---help---
31 On some legacy ARC (Synopsys) FPGA boards such as ARCAngel4/ML50x 30 On some legacy ARC (Synopsys) FPGA boards such as ARCAngel4/ML50x
32 non-standard on-chip ethernet device ARC EMAC 10/100 is used. 31 non-standard on-chip ethernet device ARC EMAC 10/100 is used.
@@ -35,7 +34,7 @@ config ARC_EMAC
35config EMAC_ROCKCHIP 34config EMAC_ROCKCHIP
36 tristate "Rockchip EMAC support" 35 tristate "Rockchip EMAC support"
37 select ARC_EMAC_CORE 36 select ARC_EMAC_CORE
38 depends on OF_IRQ && OF_NET && REGULATOR 37 depends on OF_IRQ && OF_NET && REGULATOR && HAS_DMA
39 ---help--- 38 ---help---
40 Support for Rockchip RK3066/RK3188 EMAC ethernet controllers. 39 Support for Rockchip RK3066/RK3188 EMAC ethernet controllers.
41 This selects Rockchip SoC glue layer support for the 40 This selects Rockchip SoC glue layer support for the
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index de77d3a74abc..21e3c38c7c75 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -1260,7 +1260,7 @@ static int bgmac_poll(struct napi_struct *napi, int weight)
1260 1260
1261 /* Poll again if more events arrived in the meantime */ 1261 /* Poll again if more events arrived in the meantime */
1262 if (bgmac_read(bgmac, BGMAC_INT_STATUS) & (BGMAC_IS_TX0 | BGMAC_IS_RX)) 1262 if (bgmac_read(bgmac, BGMAC_INT_STATUS) & (BGMAC_IS_TX0 | BGMAC_IS_RX))
1263 return handled; 1263 return weight;
1264 1264
1265 if (handled < weight) { 1265 if (handled < weight) {
1266 napi_complete(napi); 1266 napi_complete(napi);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 2f63467bce46..3558a36b1c2d 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -2485,8 +2485,10 @@ static void bnx2x_bz_fp(struct bnx2x *bp, int index)
2485 else if (bp->flags & GRO_ENABLE_FLAG) 2485 else if (bp->flags & GRO_ENABLE_FLAG)
2486 fp->mode = TPA_MODE_GRO; 2486 fp->mode = TPA_MODE_GRO;
2487 2487
2488 /* We don't want TPA on an FCoE L2 ring */ 2488 /* We don't want TPA if it's disabled in bp
2489 if (IS_FCOE_FP(fp)) 2489 * or if this is an FCoE L2 ring.
2490 */
2491 if (bp->disable_tpa || IS_FCOE_FP(fp))
2490 fp->disable_tpa = 1; 2492 fp->disable_tpa = 1;
2491} 2493}
2492 2494
@@ -4809,6 +4811,23 @@ netdev_features_t bnx2x_fix_features(struct net_device *dev,
4809{ 4811{
4810 struct bnx2x *bp = netdev_priv(dev); 4812 struct bnx2x *bp = netdev_priv(dev);
4811 4813
4814 if (pci_num_vf(bp->pdev)) {
4815 netdev_features_t changed = dev->features ^ features;
4816
4817 /* Revert the requested changes in features if they
4818 * would require internal reload of PF in bnx2x_set_features().
4819 */
4820 if (!(features & NETIF_F_RXCSUM) && !bp->disable_tpa) {
4821 features &= ~NETIF_F_RXCSUM;
4822 features |= dev->features & NETIF_F_RXCSUM;
4823 }
4824
4825 if (changed & NETIF_F_LOOPBACK) {
4826 features &= ~NETIF_F_LOOPBACK;
4827 features |= dev->features & NETIF_F_LOOPBACK;
4828 }
4829 }
4830
4812 /* TPA requires Rx CSUM offloading */ 4831 /* TPA requires Rx CSUM offloading */
4813 if (!(features & NETIF_F_RXCSUM)) { 4832 if (!(features & NETIF_F_RXCSUM)) {
4814 features &= ~NETIF_F_LRO; 4833 features &= ~NETIF_F_LRO;
@@ -4839,15 +4858,18 @@ int bnx2x_set_features(struct net_device *dev, netdev_features_t features)
4839 else 4858 else
4840 flags &= ~GRO_ENABLE_FLAG; 4859 flags &= ~GRO_ENABLE_FLAG;
4841 4860
4842 if (features & NETIF_F_LOOPBACK) { 4861 /* VFs or non SRIOV PFs should be able to change loopback feature */
4843 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) { 4862 if (!pci_num_vf(bp->pdev)) {
4844 bp->link_params.loopback_mode = LOOPBACK_BMAC; 4863 if (features & NETIF_F_LOOPBACK) {
4845 bnx2x_reload = true; 4864 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
4846 } 4865 bp->link_params.loopback_mode = LOOPBACK_BMAC;
4847 } else { 4866 bnx2x_reload = true;
4848 if (bp->link_params.loopback_mode != LOOPBACK_NONE) { 4867 }
4849 bp->link_params.loopback_mode = LOOPBACK_NONE; 4868 } else {
4850 bnx2x_reload = true; 4869 if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
4870 bp->link_params.loopback_mode = LOOPBACK_NONE;
4871 bnx2x_reload = true;
4872 }
4851 } 4873 }
4852 } 4874 }
4853 4875
@@ -4931,6 +4953,11 @@ int bnx2x_resume(struct pci_dev *pdev)
4931 } 4953 }
4932 bp = netdev_priv(dev); 4954 bp = netdev_priv(dev);
4933 4955
4956 if (pci_num_vf(bp->pdev)) {
4957 DP(BNX2X_MSG_IOV, "VFs are enabled, can not change MTU\n");
4958 return -EPERM;
4959 }
4960
4934 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 4961 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
4935 BNX2X_ERR("Handling parity error recovery. Try again later\n"); 4962 BNX2X_ERR("Handling parity error recovery. Try again later\n");
4936 return -EAGAIN; 4963 return -EAGAIN;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
index e3d853cab7c9..48ed005ba73f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
@@ -1843,6 +1843,12 @@ static int bnx2x_set_ringparam(struct net_device *dev,
1843 "set ring params command parameters: rx_pending = %d, tx_pending = %d\n", 1843 "set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
1844 ering->rx_pending, ering->tx_pending); 1844 ering->rx_pending, ering->tx_pending);
1845 1845
1846 if (pci_num_vf(bp->pdev)) {
1847 DP(BNX2X_MSG_IOV,
1848 "VFs are enabled, can not change ring parameters\n");
1849 return -EPERM;
1850 }
1851
1846 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 1852 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1847 DP(BNX2X_MSG_ETHTOOL, 1853 DP(BNX2X_MSG_ETHTOOL,
1848 "Handling parity error recovery. Try again later\n"); 1854 "Handling parity error recovery. Try again later\n");
@@ -2899,6 +2905,12 @@ static void bnx2x_self_test(struct net_device *dev,
2899 u8 is_serdes, link_up; 2905 u8 is_serdes, link_up;
2900 int rc, cnt = 0; 2906 int rc, cnt = 0;
2901 2907
2908 if (pci_num_vf(bp->pdev)) {
2909 DP(BNX2X_MSG_IOV,
2910 "VFs are enabled, can not perform self test\n");
2911 return;
2912 }
2913
2902 if (bp->recovery_state != BNX2X_RECOVERY_DONE) { 2914 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
2903 netdev_err(bp->dev, 2915 netdev_err(bp->dev,
2904 "Handling parity error recovery. Try again later\n"); 2916 "Handling parity error recovery. Try again later\n");
@@ -3468,6 +3480,11 @@ static int bnx2x_set_channels(struct net_device *dev,
3468 channels->rx_count, channels->tx_count, channels->other_count, 3480 channels->rx_count, channels->tx_count, channels->other_count,
3469 channels->combined_count); 3481 channels->combined_count);
3470 3482
3483 if (pci_num_vf(bp->pdev)) {
3484 DP(BNX2X_MSG_IOV, "VFs are enabled, can not set channels\n");
3485 return -EPERM;
3486 }
3487
3471 /* We don't support separate rx / tx channels. 3488 /* We don't support separate rx / tx channels.
3472 * We don't allow setting 'other' channels. 3489 * We don't allow setting 'other' channels.
3473 */ 3490 */
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 1270b189a9a2..069952fa5d64 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -18129,7 +18129,9 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
18129 18129
18130 rtnl_lock(); 18130 rtnl_lock();
18131 18131
18132 tp->pcierr_recovery = true; 18132 /* We needn't recover from permanent error */
18133 if (state == pci_channel_io_frozen)
18134 tp->pcierr_recovery = true;
18133 18135
18134 /* We probably don't have netdev yet */ 18136 /* We probably don't have netdev yet */
18135 if (!netdev || !netif_running(netdev)) 18137 if (!netdev || !netif_running(netdev))
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 9f5387249f24..665c29098e3c 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1473,9 +1473,9 @@ static void macb_init_rings(struct macb *bp)
1473 for (i = 0; i < TX_RING_SIZE; i++) { 1473 for (i = 0; i < TX_RING_SIZE; i++) {
1474 bp->queues[0].tx_ring[i].addr = 0; 1474 bp->queues[0].tx_ring[i].addr = 0;
1475 bp->queues[0].tx_ring[i].ctrl = MACB_BIT(TX_USED); 1475 bp->queues[0].tx_ring[i].ctrl = MACB_BIT(TX_USED);
1476 bp->queues[0].tx_head = 0;
1477 bp->queues[0].tx_tail = 0;
1478 } 1476 }
1477 bp->queues[0].tx_head = 0;
1478 bp->queues[0].tx_tail = 0;
1479 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP); 1479 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
1480 1480
1481 bp->rx_tail = 0; 1481 bp->rx_tail = 0;
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c
index 291c87036e17..2a0dc127df3f 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_main.c
+++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c
@@ -3347,7 +3347,7 @@ static int ehea_register_memory_hooks(void)
3347{ 3347{
3348 int ret = 0; 3348 int ret = 0;
3349 3349
3350 if (atomic_inc_and_test(&ehea_memory_hooks_registered)) 3350 if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
3351 return 0; 3351 return 0;
3352 3352
3353 ret = ehea_create_busmap(); 3353 ret = ehea_create_busmap();
@@ -3381,12 +3381,14 @@ out3:
3381out2: 3381out2:
3382 unregister_reboot_notifier(&ehea_reboot_nb); 3382 unregister_reboot_notifier(&ehea_reboot_nb);
3383out: 3383out:
3384 atomic_dec(&ehea_memory_hooks_registered);
3384 return ret; 3385 return ret;
3385} 3386}
3386 3387
3387static void ehea_unregister_memory_hooks(void) 3388static void ehea_unregister_memory_hooks(void)
3388{ 3389{
3389 if (atomic_read(&ehea_memory_hooks_registered)) 3390 /* Only remove the hooks if we've registered them */
3391 if (atomic_read(&ehea_memory_hooks_registered) == 0)
3390 return; 3392 return;
3391 3393
3392 unregister_reboot_notifier(&ehea_reboot_nb); 3394 unregister_reboot_notifier(&ehea_reboot_nb);
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index cd7675ac5bf9..18134766a114 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1238,7 +1238,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1238 return -EINVAL; 1238 return -EINVAL;
1239 1239
1240 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) 1240 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
1241 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) 1241 if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size)
1242 break; 1242 break;
1243 1243
1244 if (i == IBMVETH_NUM_BUFF_POOLS) 1244 if (i == IBMVETH_NUM_BUFF_POOLS)
@@ -1257,7 +1257,7 @@ static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
1257 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { 1257 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1258 adapter->rx_buff_pool[i].active = 1; 1258 adapter->rx_buff_pool[i].active = 1;
1259 1259
1260 if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { 1260 if (new_mtu_oh <= adapter->rx_buff_pool[i].buff_size) {
1261 dev->mtu = new_mtu; 1261 dev->mtu = new_mtu;
1262 vio_cmo_set_dev_desired(viodev, 1262 vio_cmo_set_dev_desired(viodev,
1263 ibmveth_get_desired_dma 1263 ibmveth_get_desired_dma
diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c
index af829c578400..7ace07dad6a3 100644
--- a/drivers/net/ethernet/marvell/pxa168_eth.c
+++ b/drivers/net/ethernet/marvell/pxa168_eth.c
@@ -1508,7 +1508,8 @@ static int pxa168_eth_probe(struct platform_device *pdev)
1508 np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); 1508 np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
1509 if (!np) { 1509 if (!np) {
1510 dev_err(&pdev->dev, "missing phy-handle\n"); 1510 dev_err(&pdev->dev, "missing phy-handle\n");
1511 return -EINVAL; 1511 err = -EINVAL;
1512 goto err_netdev;
1512 } 1513 }
1513 of_property_read_u32(np, "reg", &pep->phy_addr); 1514 of_property_read_u32(np, "reg", &pep->phy_addr);
1514 pep->phy_intf = of_get_phy_mode(pdev->dev.of_node); 1515 pep->phy_intf = of_get_phy_mode(pdev->dev.of_node);
@@ -1526,7 +1527,7 @@ static int pxa168_eth_probe(struct platform_device *pdev)
1526 pep->smi_bus = mdiobus_alloc(); 1527 pep->smi_bus = mdiobus_alloc();
1527 if (pep->smi_bus == NULL) { 1528 if (pep->smi_bus == NULL) {
1528 err = -ENOMEM; 1529 err = -ENOMEM;
1529 goto err_base; 1530 goto err_netdev;
1530 } 1531 }
1531 pep->smi_bus->priv = pep; 1532 pep->smi_bus->priv = pep;
1532 pep->smi_bus->name = "pxa168_eth smi"; 1533 pep->smi_bus->name = "pxa168_eth smi";
@@ -1551,13 +1552,10 @@ err_mdiobus:
1551 mdiobus_unregister(pep->smi_bus); 1552 mdiobus_unregister(pep->smi_bus);
1552err_free_mdio: 1553err_free_mdio:
1553 mdiobus_free(pep->smi_bus); 1554 mdiobus_free(pep->smi_bus);
1554err_base:
1555 iounmap(pep->base);
1556err_netdev: 1555err_netdev:
1557 free_netdev(dev); 1556 free_netdev(dev);
1558err_clk: 1557err_clk:
1559 clk_disable(clk); 1558 clk_disable_unprepare(clk);
1560 clk_put(clk);
1561 return err; 1559 return err;
1562} 1560}
1563 1561
@@ -1574,13 +1572,9 @@ static int pxa168_eth_remove(struct platform_device *pdev)
1574 if (pep->phy) 1572 if (pep->phy)
1575 phy_disconnect(pep->phy); 1573 phy_disconnect(pep->phy);
1576 if (pep->clk) { 1574 if (pep->clk) {
1577 clk_disable(pep->clk); 1575 clk_disable_unprepare(pep->clk);
1578 clk_put(pep->clk);
1579 pep->clk = NULL;
1580 } 1576 }
1581 1577
1582 iounmap(pep->base);
1583 pep->base = NULL;
1584 mdiobus_unregister(pep->smi_bus); 1578 mdiobus_unregister(pep->smi_bus);
1585 mdiobus_free(pep->smi_bus); 1579 mdiobus_free(pep->smi_bus);
1586 unregister_netdev(dev); 1580 unregister_netdev(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
index 3f44e2bbb982..a2ddf3d75ff8 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
@@ -1102,20 +1102,21 @@ static int mlx4_en_check_rxfh_func(struct net_device *dev, u8 hfunc)
1102 struct mlx4_en_priv *priv = netdev_priv(dev); 1102 struct mlx4_en_priv *priv = netdev_priv(dev);
1103 1103
1104 /* check if requested function is supported by the device */ 1104 /* check if requested function is supported by the device */
1105 if ((hfunc == ETH_RSS_HASH_TOP && 1105 if (hfunc == ETH_RSS_HASH_TOP) {
1106 !(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP)) || 1106 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP))
1107 (hfunc == ETH_RSS_HASH_XOR && 1107 return -EINVAL;
1108 !(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))) 1108 if (!(dev->features & NETIF_F_RXHASH))
1109 return -EINVAL; 1109 en_warn(priv, "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1110 return 0;
1111 } else if (hfunc == ETH_RSS_HASH_XOR) {
1112 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))
1113 return -EINVAL;
1114 if (dev->features & NETIF_F_RXHASH)
1115 en_warn(priv, "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1116 return 0;
1117 }
1110 1118
1111 priv->rss_hash_fn = hfunc; 1119 return -EINVAL;
1112 if (hfunc == ETH_RSS_HASH_TOP && !(dev->features & NETIF_F_RXHASH))
1113 en_warn(priv,
1114 "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1115 if (hfunc == ETH_RSS_HASH_XOR && (dev->features & NETIF_F_RXHASH))
1116 en_warn(priv,
1117 "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1118 return 0;
1119} 1120}
1120 1121
1121static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key, 1122static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key,
@@ -1189,6 +1190,8 @@ static int mlx4_en_set_rxfh(struct net_device *dev, const u32 *ring_index,
1189 priv->prof->rss_rings = rss_rings; 1190 priv->prof->rss_rings = rss_rings;
1190 if (key) 1191 if (key)
1191 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE); 1192 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE);
1193 if (hfunc != ETH_RSS_HASH_NO_CHANGE)
1194 priv->rss_hash_fn = hfunc;
1192 1195
1193 if (port_up) { 1196 if (port_up) {
1194 err = mlx4_en_start_port(dev); 1197 err = mlx4_en_start_port(dev);
diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
index 1412f5af05ec..2bae50292dcd 100644
--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
+++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
@@ -69,11 +69,7 @@
69#include <net/ip.h> 69#include <net/ip.h>
70#include <net/tcp.h> 70#include <net/tcp.h>
71#include <asm/byteorder.h> 71#include <asm/byteorder.h>
72#include <asm/io.h>
73#include <asm/processor.h> 72#include <asm/processor.h>
74#ifdef CONFIG_MTRR
75#include <asm/mtrr.h>
76#endif
77#include <net/busy_poll.h> 73#include <net/busy_poll.h>
78 74
79#include "myri10ge_mcp.h" 75#include "myri10ge_mcp.h"
@@ -242,8 +238,7 @@ struct myri10ge_priv {
242 unsigned int rdma_tags_available; 238 unsigned int rdma_tags_available;
243 int intr_coal_delay; 239 int intr_coal_delay;
244 __be32 __iomem *intr_coal_delay_ptr; 240 __be32 __iomem *intr_coal_delay_ptr;
245 int mtrr; 241 int wc_cookie;
246 int wc_enabled;
247 int down_cnt; 242 int down_cnt;
248 wait_queue_head_t down_wq; 243 wait_queue_head_t down_wq;
249 struct work_struct watchdog_work; 244 struct work_struct watchdog_work;
@@ -1905,7 +1900,7 @@ static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
1905 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", 1900 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
1906 "tx_heartbeat_errors", "tx_window_errors", 1901 "tx_heartbeat_errors", "tx_window_errors",
1907 /* device-specific stats */ 1902 /* device-specific stats */
1908 "tx_boundary", "WC", "irq", "MSI", "MSIX", 1903 "tx_boundary", "irq", "MSI", "MSIX",
1909 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", 1904 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
1910 "serial_number", "watchdog_resets", 1905 "serial_number", "watchdog_resets",
1911#ifdef CONFIG_MYRI10GE_DCA 1906#ifdef CONFIG_MYRI10GE_DCA
@@ -1984,7 +1979,6 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1984 data[i] = ((u64 *)&link_stats)[i]; 1979 data[i] = ((u64 *)&link_stats)[i];
1985 1980
1986 data[i++] = (unsigned int)mgp->tx_boundary; 1981 data[i++] = (unsigned int)mgp->tx_boundary;
1987 data[i++] = (unsigned int)mgp->wc_enabled;
1988 data[i++] = (unsigned int)mgp->pdev->irq; 1982 data[i++] = (unsigned int)mgp->pdev->irq;
1989 data[i++] = (unsigned int)mgp->msi_enabled; 1983 data[i++] = (unsigned int)mgp->msi_enabled;
1990 data[i++] = (unsigned int)mgp->msix_enabled; 1984 data[i++] = (unsigned int)mgp->msix_enabled;
@@ -4040,14 +4034,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4040 4034
4041 mgp->board_span = pci_resource_len(pdev, 0); 4035 mgp->board_span = pci_resource_len(pdev, 0);
4042 mgp->iomem_base = pci_resource_start(pdev, 0); 4036 mgp->iomem_base = pci_resource_start(pdev, 0);
4043 mgp->mtrr = -1; 4037 mgp->wc_cookie = arch_phys_wc_add(mgp->iomem_base, mgp->board_span);
4044 mgp->wc_enabled = 0;
4045#ifdef CONFIG_MTRR
4046 mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span,
4047 MTRR_TYPE_WRCOMB, 1);
4048 if (mgp->mtrr >= 0)
4049 mgp->wc_enabled = 1;
4050#endif
4051 mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span); 4038 mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span);
4052 if (mgp->sram == NULL) { 4039 if (mgp->sram == NULL) {
4053 dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n", 4040 dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
@@ -4146,14 +4133,14 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4146 goto abort_with_state; 4133 goto abort_with_state;
4147 } 4134 }
4148 if (mgp->msix_enabled) 4135 if (mgp->msix_enabled)
4149 dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, WC %s\n", 4136 dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
4150 mgp->num_slices, mgp->tx_boundary, mgp->fw_name, 4137 mgp->num_slices, mgp->tx_boundary, mgp->fw_name,
4151 (mgp->wc_enabled ? "Enabled" : "Disabled")); 4138 (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
4152 else 4139 else
4153 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", 4140 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
4154 mgp->msi_enabled ? "MSI" : "xPIC", 4141 mgp->msi_enabled ? "MSI" : "xPIC",
4155 pdev->irq, mgp->tx_boundary, mgp->fw_name, 4142 pdev->irq, mgp->tx_boundary, mgp->fw_name,
4156 (mgp->wc_enabled ? "Enabled" : "Disabled")); 4143 (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
4157 4144
4158 board_number++; 4145 board_number++;
4159 return 0; 4146 return 0;
@@ -4175,10 +4162,7 @@ abort_with_ioremap:
4175 iounmap(mgp->sram); 4162 iounmap(mgp->sram);
4176 4163
4177abort_with_mtrr: 4164abort_with_mtrr:
4178#ifdef CONFIG_MTRR 4165 arch_phys_wc_del(mgp->wc_cookie);
4179 if (mgp->mtrr >= 0)
4180 mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
4181#endif
4182 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4166 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
4183 mgp->cmd, mgp->cmd_bus); 4167 mgp->cmd, mgp->cmd_bus);
4184 4168
@@ -4220,11 +4204,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
4220 pci_restore_state(pdev); 4204 pci_restore_state(pdev);
4221 4205
4222 iounmap(mgp->sram); 4206 iounmap(mgp->sram);
4223 4207 arch_phys_wc_del(mgp->wc_cookie);
4224#ifdef CONFIG_MTRR
4225 if (mgp->mtrr >= 0)
4226 mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
4227#endif
4228 myri10ge_free_slices(mgp); 4208 myri10ge_free_slices(mgp);
4229 kfree(mgp->msix_vectors); 4209 kfree(mgp->msix_vectors);
4230 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4210 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index 49ce7ece5af3..c9cb486c753d 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -80,7 +80,8 @@ static void mdio_dir(struct mdiobb_ctrl *ctrl, int dir)
80 * assume the pin serves as pull-up. If direction is 80 * assume the pin serves as pull-up. If direction is
81 * output, the default value is high. 81 * output, the default value is high.
82 */ 82 */
83 gpio_set_value(bitbang->mdo, 1 ^ bitbang->mdo_active_low); 83 gpio_set_value_cansleep(bitbang->mdo,
84 1 ^ bitbang->mdo_active_low);
84 return; 85 return;
85 } 86 }
86 87
@@ -96,7 +97,8 @@ static int mdio_get(struct mdiobb_ctrl *ctrl)
96 struct mdio_gpio_info *bitbang = 97 struct mdio_gpio_info *bitbang =
97 container_of(ctrl, struct mdio_gpio_info, ctrl); 98 container_of(ctrl, struct mdio_gpio_info, ctrl);
98 99
99 return gpio_get_value(bitbang->mdio) ^ bitbang->mdio_active_low; 100 return gpio_get_value_cansleep(bitbang->mdio) ^
101 bitbang->mdio_active_low;
100} 102}
101 103
102static void mdio_set(struct mdiobb_ctrl *ctrl, int what) 104static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
@@ -105,9 +107,11 @@ static void mdio_set(struct mdiobb_ctrl *ctrl, int what)
105 container_of(ctrl, struct mdio_gpio_info, ctrl); 107 container_of(ctrl, struct mdio_gpio_info, ctrl);
106 108
107 if (bitbang->mdo) 109 if (bitbang->mdo)
108 gpio_set_value(bitbang->mdo, what ^ bitbang->mdo_active_low); 110 gpio_set_value_cansleep(bitbang->mdo,
111 what ^ bitbang->mdo_active_low);
109 else 112 else
110 gpio_set_value(bitbang->mdio, what ^ bitbang->mdio_active_low); 113 gpio_set_value_cansleep(bitbang->mdio,
114 what ^ bitbang->mdio_active_low);
111} 115}
112 116
113static void mdc_set(struct mdiobb_ctrl *ctrl, int what) 117static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
@@ -115,7 +119,7 @@ static void mdc_set(struct mdiobb_ctrl *ctrl, int what)
115 struct mdio_gpio_info *bitbang = 119 struct mdio_gpio_info *bitbang =
116 container_of(ctrl, struct mdio_gpio_info, ctrl); 120 container_of(ctrl, struct mdio_gpio_info, ctrl);
117 121
118 gpio_set_value(bitbang->mdc, what ^ bitbang->mdc_active_low); 122 gpio_set_value_cansleep(bitbang->mdc, what ^ bitbang->mdc_active_low);
119} 123}
120 124
121static struct mdiobb_ops mdio_gpio_ops = { 125static struct mdiobb_ops mdio_gpio_ops = {
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 1a87a585e74d..66edd99bc302 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -12,33 +12,30 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/phy.h> 13#include <linux/phy.h>
14#include <linux/mdio-mux.h> 14#include <linux/mdio-mux.h>
15#include <linux/of_gpio.h> 15#include <linux/gpio/consumer.h>
16 16
17#define DRV_VERSION "1.1" 17#define DRV_VERSION "1.1"
18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver" 18#define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver"
19 19
20#define MDIO_MUX_GPIO_MAX_BITS 8
21
22struct mdio_mux_gpio_state { 20struct mdio_mux_gpio_state {
23 struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS]; 21 struct gpio_descs *gpios;
24 unsigned int num_gpios;
25 void *mux_handle; 22 void *mux_handle;
26}; 23};
27 24
28static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, 25static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
29 void *data) 26 void *data)
30{ 27{
31 int values[MDIO_MUX_GPIO_MAX_BITS];
32 unsigned int n;
33 struct mdio_mux_gpio_state *s = data; 28 struct mdio_mux_gpio_state *s = data;
29 int values[s->gpios->ndescs];
30 unsigned int n;
34 31
35 if (current_child == desired_child) 32 if (current_child == desired_child)
36 return 0; 33 return 0;
37 34
38 for (n = 0; n < s->num_gpios; n++) { 35 for (n = 0; n < s->gpios->ndescs; n++)
39 values[n] = (desired_child >> n) & 1; 36 values[n] = (desired_child >> n) & 1;
40 } 37
41 gpiod_set_array_cansleep(s->num_gpios, s->gpio, values); 38 gpiod_set_array_cansleep(s->gpios->ndescs, s->gpios->desc, values);
42 39
43 return 0; 40 return 0;
44} 41}
@@ -46,56 +43,33 @@ static int mdio_mux_gpio_switch_fn(int current_child, int desired_child,
46static int mdio_mux_gpio_probe(struct platform_device *pdev) 43static int mdio_mux_gpio_probe(struct platform_device *pdev)
47{ 44{
48 struct mdio_mux_gpio_state *s; 45 struct mdio_mux_gpio_state *s;
49 int num_gpios;
50 unsigned int n;
51 int r; 46 int r;
52 47
53 if (!pdev->dev.of_node)
54 return -ENODEV;
55
56 num_gpios = of_gpio_count(pdev->dev.of_node);
57 if (num_gpios <= 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS)
58 return -ENODEV;
59
60 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 48 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
61 if (!s) 49 if (!s)
62 return -ENOMEM; 50 return -ENOMEM;
63 51
64 s->num_gpios = num_gpios; 52 s->gpios = gpiod_get_array(&pdev->dev, NULL, GPIOD_OUT_LOW);
65 53 if (IS_ERR(s->gpios))
66 for (n = 0; n < num_gpios; ) { 54 return PTR_ERR(s->gpios);
67 struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n,
68 GPIOD_OUT_LOW);
69 if (IS_ERR(gpio)) {
70 r = PTR_ERR(gpio);
71 goto err;
72 }
73 s->gpio[n] = gpio;
74 n++;
75 }
76 55
77 r = mdio_mux_init(&pdev->dev, 56 r = mdio_mux_init(&pdev->dev,
78 mdio_mux_gpio_switch_fn, &s->mux_handle, s); 57 mdio_mux_gpio_switch_fn, &s->mux_handle, s);
79 58
80 if (r == 0) { 59 if (r != 0) {
81 pdev->dev.platform_data = s; 60 gpiod_put_array(s->gpios);
82 return 0; 61 return r;
83 }
84err:
85 while (n) {
86 n--;
87 gpiod_put(s->gpio[n]);
88 } 62 }
89 return r; 63
64 pdev->dev.platform_data = s;
65 return 0;
90} 66}
91 67
92static int mdio_mux_gpio_remove(struct platform_device *pdev) 68static int mdio_mux_gpio_remove(struct platform_device *pdev)
93{ 69{
94 unsigned int n;
95 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev); 70 struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev);
96 mdio_mux_uninit(s->mux_handle); 71 mdio_mux_uninit(s->mux_handle);
97 for (n = 0; n < s->num_gpios; n++) 72 gpiod_put_array(s->gpios);
98 gpiod_put(s->gpio[n]);
99 return 0; 73 return 0;
100} 74}
101 75
diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c
index 911b21602ff2..05005c660d4d 100644
--- a/drivers/net/ppp/ppp_mppe.c
+++ b/drivers/net/ppp/ppp_mppe.c
@@ -478,7 +478,6 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
478 struct blkcipher_desc desc = { .tfm = state->arc4 }; 478 struct blkcipher_desc desc = { .tfm = state->arc4 };
479 unsigned ccount; 479 unsigned ccount;
480 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED; 480 int flushed = MPPE_BITS(ibuf) & MPPE_BIT_FLUSHED;
481 int sanity = 0;
482 struct scatterlist sg_in[1], sg_out[1]; 481 struct scatterlist sg_in[1], sg_out[1];
483 482
484 if (isize <= PPP_HDRLEN + MPPE_OVHD) { 483 if (isize <= PPP_HDRLEN + MPPE_OVHD) {
@@ -514,31 +513,19 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
514 "mppe_decompress[%d]: ENCRYPTED bit not set!\n", 513 "mppe_decompress[%d]: ENCRYPTED bit not set!\n",
515 state->unit); 514 state->unit);
516 state->sanity_errors += 100; 515 state->sanity_errors += 100;
517 sanity = 1; 516 goto sanity_error;
518 } 517 }
519 if (!state->stateful && !flushed) { 518 if (!state->stateful && !flushed) {
520 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in " 519 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set in "
521 "stateless mode!\n", state->unit); 520 "stateless mode!\n", state->unit);
522 state->sanity_errors += 100; 521 state->sanity_errors += 100;
523 sanity = 1; 522 goto sanity_error;
524 } 523 }
525 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) { 524 if (state->stateful && ((ccount & 0xff) == 0xff) && !flushed) {
526 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on " 525 printk(KERN_DEBUG "mppe_decompress[%d]: FLUSHED bit not set on "
527 "flag packet!\n", state->unit); 526 "flag packet!\n", state->unit);
528 state->sanity_errors += 100; 527 state->sanity_errors += 100;
529 sanity = 1; 528 goto sanity_error;
530 }
531
532 if (sanity) {
533 if (state->sanity_errors < SANITY_MAX)
534 return DECOMP_ERROR;
535 else
536 /*
537 * Take LCP down if the peer is sending too many bogons.
538 * We don't want to do this for a single or just a few
539 * instances since it could just be due to packet corruption.
540 */
541 return DECOMP_FATALERROR;
542 } 529 }
543 530
544 /* 531 /*
@@ -546,6 +533,13 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
546 */ 533 */
547 534
548 if (!state->stateful) { 535 if (!state->stateful) {
536 /* Discard late packet */
537 if ((ccount - state->ccount) % MPPE_CCOUNT_SPACE
538 > MPPE_CCOUNT_SPACE / 2) {
539 state->sanity_errors++;
540 goto sanity_error;
541 }
542
549 /* RFC 3078, sec 8.1. Rekey for every packet. */ 543 /* RFC 3078, sec 8.1. Rekey for every packet. */
550 while (state->ccount != ccount) { 544 while (state->ccount != ccount) {
551 mppe_rekey(state, 0); 545 mppe_rekey(state, 0);
@@ -649,6 +643,16 @@ mppe_decompress(void *arg, unsigned char *ibuf, int isize, unsigned char *obuf,
649 state->sanity_errors >>= 1; 643 state->sanity_errors >>= 1;
650 644
651 return osize; 645 return osize;
646
647sanity_error:
648 if (state->sanity_errors < SANITY_MAX)
649 return DECOMP_ERROR;
650 else
651 /* Take LCP down if the peer is sending too many bogons.
652 * We don't want to do this for a single or just a few
653 * instances since it could just be due to packet corruption.
654 */
655 return DECOMP_FATALERROR;
652} 656}
653 657
654/* 658/*
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 154116aafd0d..27a5f954f8e9 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -730,12 +730,8 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
730 /* Only change unicasts */ 730 /* Only change unicasts */
731 if (!(is_multicast_ether_addr(f->eth_addr) || 731 if (!(is_multicast_ether_addr(f->eth_addr) ||
732 is_zero_ether_addr(f->eth_addr))) { 732 is_zero_ether_addr(f->eth_addr))) {
733 int rc = vxlan_fdb_replace(f, ip, port, vni, 733 notify |= vxlan_fdb_replace(f, ip, port, vni,
734 ifindex); 734 ifindex);
735
736 if (rc < 0)
737 return rc;
738 notify |= rc;
739 } else 735 } else
740 return -EOPNOTSUPP; 736 return -EOPNOTSUPP;
741 } 737 }
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index c43aca69fb30..0fc3fe5fd5b8 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -667,6 +667,8 @@ static struct raw3215_info *raw3215_alloc_info(void)
667 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); 667 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
668 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA); 668 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
669 if (!info->buffer || !info->inbuf) { 669 if (!info->buffer || !info->inbuf) {
670 kfree(info->inbuf);
671 kfree(info->buffer);
670 kfree(info); 672 kfree(info);
671 return NULL; 673 return NULL;
672 } 674 }
diff --git a/drivers/sh/pm_runtime.c b/drivers/sh/pm_runtime.c
index cd4c293f0dd0..fe8875f0d7be 100644
--- a/drivers/sh/pm_runtime.c
+++ b/drivers/sh/pm_runtime.c
@@ -80,9 +80,10 @@ static int __init sh_pm_runtime_init(void)
80 if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) { 80 if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
81 if (!of_machine_is_compatible("renesas,emev2") && 81 if (!of_machine_is_compatible("renesas,emev2") &&
82 !of_machine_is_compatible("renesas,r7s72100") && 82 !of_machine_is_compatible("renesas,r7s72100") &&
83 !of_machine_is_compatible("renesas,r8a73a4") &&
84#ifndef CONFIG_PM_GENERIC_DOMAINS_OF 83#ifndef CONFIG_PM_GENERIC_DOMAINS_OF
84 !of_machine_is_compatible("renesas,r8a73a4") &&
85 !of_machine_is_compatible("renesas,r8a7740") && 85 !of_machine_is_compatible("renesas,r8a7740") &&
86 !of_machine_is_compatible("renesas,sh73a0") &&
86#endif 87#endif
87 !of_machine_is_compatible("renesas,r8a7778") && 88 !of_machine_is_compatible("renesas,r8a7778") &&
88 !of_machine_is_compatible("renesas,r8a7779") && 89 !of_machine_is_compatible("renesas,r8a7779") &&
@@ -90,9 +91,7 @@ static int __init sh_pm_runtime_init(void)
90 !of_machine_is_compatible("renesas,r8a7791") && 91 !of_machine_is_compatible("renesas,r8a7791") &&
91 !of_machine_is_compatible("renesas,r8a7792") && 92 !of_machine_is_compatible("renesas,r8a7792") &&
92 !of_machine_is_compatible("renesas,r8a7793") && 93 !of_machine_is_compatible("renesas,r8a7793") &&
93 !of_machine_is_compatible("renesas,r8a7794") && 94 !of_machine_is_compatible("renesas,r8a7794"))
94 !of_machine_is_compatible("renesas,sh7372") &&
95 !of_machine_is_compatible("renesas,sh73a0"))
96 return 0; 95 return 0;
97 } 96 }
98 97
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 08da4d3e2162..46bcebba54b2 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1998,6 +1998,8 @@ pci_wch_ch38x_setup(struct serial_private *priv,
1998#define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250 1998#define PCIE_DEVICE_ID_WCH_CH382_2S1P 0x3250
1999#define PCIE_DEVICE_ID_WCH_CH384_4S 0x3470 1999#define PCIE_DEVICE_ID_WCH_CH384_4S 0x3470
2000 2000
2001#define PCI_DEVICE_ID_EXAR_XR17V8358 0x8358
2002
2001/* Unknown vendors/cards - this should not be in linux/pci_ids.h */ 2003/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
2002#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584 2004#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
2003#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588 0x1588 2005#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588 0x1588
@@ -2520,6 +2522,13 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
2520 .subdevice = PCI_ANY_ID, 2522 .subdevice = PCI_ANY_ID,
2521 .setup = pci_xr17v35x_setup, 2523 .setup = pci_xr17v35x_setup,
2522 }, 2524 },
2525 {
2526 .vendor = PCI_VENDOR_ID_EXAR,
2527 .device = PCI_DEVICE_ID_EXAR_XR17V8358,
2528 .subvendor = PCI_ANY_ID,
2529 .subdevice = PCI_ANY_ID,
2530 .setup = pci_xr17v35x_setup,
2531 },
2523 /* 2532 /*
2524 * Xircom cards 2533 * Xircom cards
2525 */ 2534 */
@@ -2999,6 +3008,7 @@ enum pci_board_num_t {
2999 pbn_exar_XR17V352, 3008 pbn_exar_XR17V352,
3000 pbn_exar_XR17V354, 3009 pbn_exar_XR17V354,
3001 pbn_exar_XR17V358, 3010 pbn_exar_XR17V358,
3011 pbn_exar_XR17V8358,
3002 pbn_exar_ibm_saturn, 3012 pbn_exar_ibm_saturn,
3003 pbn_pasemi_1682M, 3013 pbn_pasemi_1682M,
3004 pbn_ni8430_2, 3014 pbn_ni8430_2,
@@ -3685,6 +3695,14 @@ static struct pciserial_board pci_boards[] = {
3685 .reg_shift = 0, 3695 .reg_shift = 0,
3686 .first_offset = 0, 3696 .first_offset = 0,
3687 }, 3697 },
3698 [pbn_exar_XR17V8358] = {
3699 .flags = FL_BASE0,
3700 .num_ports = 16,
3701 .base_baud = 7812500,
3702 .uart_offset = 0x400,
3703 .reg_shift = 0,
3704 .first_offset = 0,
3705 },
3688 [pbn_exar_ibm_saturn] = { 3706 [pbn_exar_ibm_saturn] = {
3689 .flags = FL_BASE0, 3707 .flags = FL_BASE0,
3690 .num_ports = 1, 3708 .num_ports = 1,
@@ -5080,7 +5098,7 @@ static struct pci_device_id serial_pci_tbl[] = {
5080 0, 5098 0,
5081 0, pbn_exar_XR17C158 }, 5099 0, pbn_exar_XR17C158 },
5082 /* 5100 /*
5083 * Exar Corp. XR17V35[248] Dual/Quad/Octal PCIe UARTs 5101 * Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs
5084 */ 5102 */
5085 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V352, 5103 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V352,
5086 PCI_ANY_ID, PCI_ANY_ID, 5104 PCI_ANY_ID, PCI_ANY_ID,
@@ -5094,7 +5112,10 @@ static struct pci_device_id serial_pci_tbl[] = {
5094 PCI_ANY_ID, PCI_ANY_ID, 5112 PCI_ANY_ID, PCI_ANY_ID,
5095 0, 5113 0,
5096 0, pbn_exar_XR17V358 }, 5114 0, pbn_exar_XR17V358 },
5097 5115 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V8358,
5116 PCI_ANY_ID, PCI_ANY_ID,
5117 0,
5118 0, pbn_exar_XR17V8358 },
5098 /* 5119 /*
5099 * Topic TP560 Data/Fax/Voice 56k modem (reported by Evan Clarke) 5120 * Topic TP560 Data/Fax/Voice 56k modem (reported by Evan Clarke)
5100 */ 5121 */
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d58fe4763d9e..27dade29646b 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -880,6 +880,7 @@ static int atmel_prepare_tx_dma(struct uart_port *port)
880 config.direction = DMA_MEM_TO_DEV; 880 config.direction = DMA_MEM_TO_DEV;
881 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 881 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
882 config.dst_addr = port->mapbase + ATMEL_US_THR; 882 config.dst_addr = port->mapbase + ATMEL_US_THR;
883 config.dst_maxburst = 1;
883 884
884 ret = dmaengine_slave_config(atmel_port->chan_tx, 885 ret = dmaengine_slave_config(atmel_port->chan_tx,
885 &config); 886 &config);
@@ -1059,6 +1060,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)
1059 config.direction = DMA_DEV_TO_MEM; 1060 config.direction = DMA_DEV_TO_MEM;
1060 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 1061 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
1061 config.src_addr = port->mapbase + ATMEL_US_RHR; 1062 config.src_addr = port->mapbase + ATMEL_US_RHR;
1063 config.src_maxburst = 1;
1062 1064
1063 ret = dmaengine_slave_config(atmel_port->chan_rx, 1065 ret = dmaengine_slave_config(atmel_port->chan_rx,
1064 &config); 1066 &config);
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 5b73afb9f9f3..137381e649e5 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -346,7 +346,6 @@ static const struct of_device_id of_platform_serial_table[] = {
346 { .compatible = "ibm,qpace-nwp-serial", 346 { .compatible = "ibm,qpace-nwp-serial",
347 .data = (void *)PORT_NWPSERIAL, }, 347 .data = (void *)PORT_NWPSERIAL, },
348#endif 348#endif
349 { .type = "serial", .data = (void *)PORT_UNKNOWN, },
350 { /* end of list */ }, 349 { /* end of list */ },
351}; 350};
352 351
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index cf08876922f1..a0ae942d9562 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -1068,8 +1068,9 @@ static int s3c64xx_serial_startup(struct uart_port *port)
1068 spin_lock_irqsave(&port->lock, flags); 1068 spin_lock_irqsave(&port->lock, flags);
1069 1069
1070 ufcon = rd_regl(port, S3C2410_UFCON); 1070 ufcon = rd_regl(port, S3C2410_UFCON);
1071 ufcon |= S3C2410_UFCON_RESETRX | S3C2410_UFCON_RESETTX | 1071 ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8;
1072 S5PV210_UFCON_RXTRIG8; 1072 if (!uart_console(port))
1073 ufcon |= S3C2410_UFCON_RESETTX;
1073 wr_regl(port, S3C2410_UFCON, ufcon); 1074 wr_regl(port, S3C2410_UFCON, ufcon);
1074 1075
1075 enable_rx_pio(ourport); 1076 enable_rx_pio(ourport);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index eb5b03be9dfd..0b7bb12dfc68 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1770,7 +1770,7 @@ static const struct file_operations uart_proc_fops = {
1770 * @port: the port to write the message 1770 * @port: the port to write the message
1771 * @s: array of characters 1771 * @s: array of characters
1772 * @count: number of characters in string to write 1772 * @count: number of characters in string to write
1773 * @write: function to write character to port 1773 * @putchar: function to write character to port
1774 */ 1774 */
1775void uart_console_write(struct uart_port *port, const char *s, 1775void uart_console_write(struct uart_port *port, const char *s,
1776 unsigned int count, 1776 unsigned int count,
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 708eead850b0..b1c6bd3d483f 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -632,7 +632,8 @@ MODULE_DEVICE_TABLE(of, ulite_of_match);
632 632
633static int ulite_probe(struct platform_device *pdev) 633static int ulite_probe(struct platform_device *pdev)
634{ 634{
635 struct resource *res, *res2; 635 struct resource *res;
636 int irq;
636 int id = pdev->id; 637 int id = pdev->id;
637#ifdef CONFIG_OF 638#ifdef CONFIG_OF
638 const __be32 *prop; 639 const __be32 *prop;
@@ -646,11 +647,11 @@ static int ulite_probe(struct platform_device *pdev)
646 if (!res) 647 if (!res)
647 return -ENODEV; 648 return -ENODEV;
648 649
649 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 650 irq = platform_get_irq(pdev, 0);
650 if (!res2) 651 if (irq <= 0)
651 return -ENODEV; 652 return -ENXIO;
652 653
653 return ulite_assign(&pdev->dev, id, res->start, res2->start); 654 return ulite_assign(&pdev->dev, id, res->start, irq);
654} 655}
655 656
656static int ulite_remove(struct platform_device *pdev) 657static int ulite_remove(struct platform_device *pdev)
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index f218ec658f5d..3ddbac767db3 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1331,9 +1331,9 @@ static SIMPLE_DEV_PM_OPS(cdns_uart_dev_pm_ops, cdns_uart_suspend,
1331 */ 1331 */
1332static int cdns_uart_probe(struct platform_device *pdev) 1332static int cdns_uart_probe(struct platform_device *pdev)
1333{ 1333{
1334 int rc, id; 1334 int rc, id, irq;
1335 struct uart_port *port; 1335 struct uart_port *port;
1336 struct resource *res, *res2; 1336 struct resource *res;
1337 struct cdns_uart *cdns_uart_data; 1337 struct cdns_uart *cdns_uart_data;
1338 1338
1339 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), 1339 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data),
@@ -1380,9 +1380,9 @@ static int cdns_uart_probe(struct platform_device *pdev)
1380 goto err_out_clk_disable; 1380 goto err_out_clk_disable;
1381 } 1381 }
1382 1382
1383 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1383 irq = platform_get_irq(pdev, 0);
1384 if (!res2) { 1384 if (irq <= 0) {
1385 rc = -ENODEV; 1385 rc = -ENXIO;
1386 goto err_out_clk_disable; 1386 goto err_out_clk_disable;
1387 } 1387 }
1388 1388
@@ -1411,7 +1411,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
1411 * and triggers invocation of the config_port() entry point. 1411 * and triggers invocation of the config_port() entry point.
1412 */ 1412 */
1413 port->mapbase = res->start; 1413 port->mapbase = res->start;
1414 port->irq = res2->start; 1414 port->irq = irq;
1415 port->dev = &pdev->dev; 1415 port->dev = &pdev->dev;
1416 port->uartclk = clk_get_rate(cdns_uart_data->uartclk); 1416 port->uartclk = clk_get_rate(cdns_uart_data->uartclk);
1417 port->private_data = cdns_uart_data; 1417 port->private_data = cdns_uart_data;
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 632fc8152061..8e53fe469664 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -536,7 +536,7 @@ EXPORT_SYMBOL(tty_termios_hw_change);
536 * Locking: termios_rwsem 536 * Locking: termios_rwsem
537 */ 537 */
538 538
539static int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) 539int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
540{ 540{
541 struct ktermios old_termios; 541 struct ktermios old_termios;
542 struct tty_ldisc *ld; 542 struct tty_ldisc *ld;
@@ -569,6 +569,7 @@ static int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
569 up_write(&tty->termios_rwsem); 569 up_write(&tty->termios_rwsem);
570 return 0; 570 return 0;
571} 571}
572EXPORT_SYMBOL_GPL(tty_set_termios);
572 573
573/** 574/**
574 * set_termios - set termios values for a tty 575 * set_termios - set termios values for a tty
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index 083acf45ad5a..19d655a743b5 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -520,7 +520,6 @@ static int ci_otg_start_host(struct otg_fsm *fsm, int on)
520{ 520{
521 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 521 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm);
522 522
523 mutex_unlock(&fsm->lock);
524 if (on) { 523 if (on) {
525 ci_role_stop(ci); 524 ci_role_stop(ci);
526 ci_role_start(ci, CI_ROLE_HOST); 525 ci_role_start(ci, CI_ROLE_HOST);
@@ -529,7 +528,6 @@ static int ci_otg_start_host(struct otg_fsm *fsm, int on)
529 hw_device_reset(ci); 528 hw_device_reset(ci);
530 ci_role_start(ci, CI_ROLE_GADGET); 529 ci_role_start(ci, CI_ROLE_GADGET);
531 } 530 }
532 mutex_lock(&fsm->lock);
533 return 0; 531 return 0;
534} 532}
535 533
@@ -537,12 +535,10 @@ static int ci_otg_start_gadget(struct otg_fsm *fsm, int on)
537{ 535{
538 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 536 struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm);
539 537
540 mutex_unlock(&fsm->lock);
541 if (on) 538 if (on)
542 usb_gadget_vbus_connect(&ci->gadget); 539 usb_gadget_vbus_connect(&ci->gadget);
543 else 540 else
544 usb_gadget_vbus_disconnect(&ci->gadget); 541 usb_gadget_vbus_disconnect(&ci->gadget);
545 mutex_lock(&fsm->lock);
546 542
547 return 0; 543 return 0;
548} 544}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 3e15add665e2..5c8f58114677 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1142,11 +1142,16 @@ static int acm_probe(struct usb_interface *intf,
1142 } 1142 }
1143 1143
1144 while (buflen > 0) { 1144 while (buflen > 0) {
1145 elength = buffer[0];
1146 if (!elength) {
1147 dev_err(&intf->dev, "skipping garbage byte\n");
1148 elength = 1;
1149 goto next_desc;
1150 }
1145 if (buffer[1] != USB_DT_CS_INTERFACE) { 1151 if (buffer[1] != USB_DT_CS_INTERFACE) {
1146 dev_err(&intf->dev, "skipping garbage\n"); 1152 dev_err(&intf->dev, "skipping garbage\n");
1147 goto next_desc; 1153 goto next_desc;
1148 } 1154 }
1149 elength = buffer[0];
1150 1155
1151 switch (buffer[2]) { 1156 switch (buffer[2]) {
1152 case USB_CDC_UNION_TYPE: /* we've found it */ 1157 case USB_CDC_UNION_TYPE: /* we've found it */
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9db74ca7e5b9..275c92e53a59 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -88,13 +88,20 @@ static int ehci_msm_probe(struct platform_device *pdev)
88 } 88 }
89 89
90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 90 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 hcd->regs = devm_ioremap_resource(&pdev->dev, res); 91 if (!res) {
92 if (IS_ERR(hcd->regs)) { 92 dev_err(&pdev->dev, "Unable to get memory resource\n");
93 ret = PTR_ERR(hcd->regs); 93 ret = -ENODEV;
94 goto put_hcd; 94 goto put_hcd;
95 } 95 }
96
96 hcd->rsrc_start = res->start; 97 hcd->rsrc_start = res->start;
97 hcd->rsrc_len = resource_size(res); 98 hcd->rsrc_len = resource_size(res);
99 hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
100 if (!hcd->regs) {
101 dev_err(&pdev->dev, "ioremap failed\n");
102 ret = -ENOMEM;
103 goto put_hcd;
104 }
98 105
99 /* 106 /*
100 * OTG driver takes care of PHY initialization, clock management, 107 * OTG driver takes care of PHY initialization, clock management,
diff --git a/drivers/usb/storage/uas-detect.h b/drivers/usb/storage/uas-detect.h
index 9893d696fc97..f58caa9e6a27 100644
--- a/drivers/usb/storage/uas-detect.h
+++ b/drivers/usb/storage/uas-detect.h
@@ -51,7 +51,8 @@ static int uas_find_endpoints(struct usb_host_interface *alt,
51} 51}
52 52
53static int uas_use_uas_driver(struct usb_interface *intf, 53static int uas_use_uas_driver(struct usb_interface *intf,
54 const struct usb_device_id *id) 54 const struct usb_device_id *id,
55 unsigned long *flags_ret)
55{ 56{
56 struct usb_host_endpoint *eps[4] = { }; 57 struct usb_host_endpoint *eps[4] = { };
57 struct usb_device *udev = interface_to_usbdev(intf); 58 struct usb_device *udev = interface_to_usbdev(intf);
@@ -73,7 +74,7 @@ static int uas_use_uas_driver(struct usb_interface *intf,
73 * this writing the following versions exist: 74 * this writing the following versions exist:
74 * ASM1051 - no uas support version 75 * ASM1051 - no uas support version
75 * ASM1051 - with broken (*) uas support 76 * ASM1051 - with broken (*) uas support
76 * ASM1053 - with working uas support 77 * ASM1053 - with working uas support, but problems with large xfers
77 * ASM1153 - with working uas support 78 * ASM1153 - with working uas support
78 * 79 *
79 * Devices with these chips re-use a number of device-ids over the 80 * Devices with these chips re-use a number of device-ids over the
@@ -103,6 +104,9 @@ static int uas_use_uas_driver(struct usb_interface *intf,
103 } else if (usb_ss_max_streams(&eps[1]->ss_ep_comp) == 32) { 104 } else if (usb_ss_max_streams(&eps[1]->ss_ep_comp) == 32) {
104 /* Possibly an ASM1051, disable uas */ 105 /* Possibly an ASM1051, disable uas */
105 flags |= US_FL_IGNORE_UAS; 106 flags |= US_FL_IGNORE_UAS;
107 } else {
108 /* ASM1053, these have issues with large transfers */
109 flags |= US_FL_MAX_SECTORS_240;
106 } 110 }
107 } 111 }
108 112
@@ -132,5 +136,8 @@ static int uas_use_uas_driver(struct usb_interface *intf,
132 return 0; 136 return 0;
133 } 137 }
134 138
139 if (flags_ret)
140 *flags_ret = flags;
141
135 return 1; 142 return 1;
136} 143}
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 6cdabdc119a7..6d3122afeed3 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -759,7 +759,10 @@ static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd)
759 759
760static int uas_slave_alloc(struct scsi_device *sdev) 760static int uas_slave_alloc(struct scsi_device *sdev)
761{ 761{
762 sdev->hostdata = (void *)sdev->host->hostdata; 762 struct uas_dev_info *devinfo =
763 (struct uas_dev_info *)sdev->host->hostdata;
764
765 sdev->hostdata = devinfo;
763 766
764 /* USB has unusual DMA-alignment requirements: Although the 767 /* USB has unusual DMA-alignment requirements: Although the
765 * starting address of each scatter-gather element doesn't matter, 768 * starting address of each scatter-gather element doesn't matter,
@@ -778,6 +781,11 @@ static int uas_slave_alloc(struct scsi_device *sdev)
778 */ 781 */
779 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); 782 blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
780 783
784 if (devinfo->flags & US_FL_MAX_SECTORS_64)
785 blk_queue_max_hw_sectors(sdev->request_queue, 64);
786 else if (devinfo->flags & US_FL_MAX_SECTORS_240)
787 blk_queue_max_hw_sectors(sdev->request_queue, 240);
788
781 return 0; 789 return 0;
782} 790}
783 791
@@ -887,8 +895,9 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
887 struct Scsi_Host *shost = NULL; 895 struct Scsi_Host *shost = NULL;
888 struct uas_dev_info *devinfo; 896 struct uas_dev_info *devinfo;
889 struct usb_device *udev = interface_to_usbdev(intf); 897 struct usb_device *udev = interface_to_usbdev(intf);
898 unsigned long dev_flags;
890 899
891 if (!uas_use_uas_driver(intf, id)) 900 if (!uas_use_uas_driver(intf, id, &dev_flags))
892 return -ENODEV; 901 return -ENODEV;
893 902
894 if (uas_switch_interface(udev, intf)) 903 if (uas_switch_interface(udev, intf))
@@ -910,8 +919,7 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id)
910 devinfo->udev = udev; 919 devinfo->udev = udev;
911 devinfo->resetting = 0; 920 devinfo->resetting = 0;
912 devinfo->shutdown = 0; 921 devinfo->shutdown = 0;
913 devinfo->flags = id->driver_info; 922 devinfo->flags = dev_flags;
914 usb_stor_adjust_quirks(udev, &devinfo->flags);
915 init_usb_anchor(&devinfo->cmd_urbs); 923 init_usb_anchor(&devinfo->cmd_urbs);
916 init_usb_anchor(&devinfo->sense_urbs); 924 init_usb_anchor(&devinfo->sense_urbs);
917 init_usb_anchor(&devinfo->data_urbs); 925 init_usb_anchor(&devinfo->data_urbs);
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 5600c33fcadb..6c10c888f35f 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -479,7 +479,8 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
479 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT | 479 US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
480 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | 480 US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 |
481 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE | 481 US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE |
482 US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES); 482 US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES |
483 US_FL_MAX_SECTORS_240);
483 484
484 p = quirks; 485 p = quirks;
485 while (*p) { 486 while (*p) {
@@ -520,6 +521,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)
520 case 'f': 521 case 'f':
521 f |= US_FL_NO_REPORT_OPCODES; 522 f |= US_FL_NO_REPORT_OPCODES;
522 break; 523 break;
524 case 'g':
525 f |= US_FL_MAX_SECTORS_240;
526 break;
523 case 'h': 527 case 'h':
524 f |= US_FL_CAPACITY_HEURISTICS; 528 f |= US_FL_CAPACITY_HEURISTICS;
525 break; 529 break;
@@ -1080,7 +1084,7 @@ static int storage_probe(struct usb_interface *intf,
1080 1084
1081 /* If uas is enabled and this device can do uas then ignore it. */ 1085 /* If uas is enabled and this device can do uas then ignore it. */
1082#if IS_ENABLED(CONFIG_USB_UAS) 1086#if IS_ENABLED(CONFIG_USB_UAS)
1083 if (uas_use_uas_driver(intf, id)) 1087 if (uas_use_uas_driver(intf, id, NULL))
1084 return -ENXIO; 1088 return -ENXIO;
1085#endif 1089#endif
1086 1090
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index e60a745ac198..e804306ef5e8 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -40,6 +40,10 @@
40#error KEXEC_CONTROL_MEMORY_LIMIT not defined 40#error KEXEC_CONTROL_MEMORY_LIMIT not defined
41#endif 41#endif
42 42
43#ifndef KEXEC_CONTROL_MEMORY_GFP
44#define KEXEC_CONTROL_MEMORY_GFP GFP_KERNEL
45#endif
46
43#ifndef KEXEC_CONTROL_PAGE_SIZE 47#ifndef KEXEC_CONTROL_PAGE_SIZE
44#error KEXEC_CONTROL_PAGE_SIZE not defined 48#error KEXEC_CONTROL_PAGE_SIZE not defined
45#endif 49#endif
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index bcbde799ec69..dbad4d728b4b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -60,6 +60,7 @@ struct phy_device;
60struct wireless_dev; 60struct wireless_dev;
61/* 802.15.4 specific */ 61/* 802.15.4 specific */
62struct wpan_dev; 62struct wpan_dev;
63struct mpls_dev;
63 64
64void netdev_set_default_ethtool_ops(struct net_device *dev, 65void netdev_set_default_ethtool_ops(struct net_device *dev,
65 const struct ethtool_ops *ops); 66 const struct ethtool_ops *ops);
@@ -1627,6 +1628,9 @@ struct net_device {
1627 void *ax25_ptr; 1628 void *ax25_ptr;
1628 struct wireless_dev *ieee80211_ptr; 1629 struct wireless_dev *ieee80211_ptr;
1629 struct wpan_dev *ieee802154_ptr; 1630 struct wpan_dev *ieee802154_ptr;
1631#if IS_ENABLED(CONFIG_MPLS_ROUTING)
1632 struct mpls_dev __rcu *mpls_ptr;
1633#endif
1630 1634
1631/* 1635/*
1632 * Cache lines mostly used on receive path (including eth_type_trans()) 1636 * Cache lines mostly used on receive path (including eth_type_trans())
@@ -2021,10 +2025,10 @@ struct pcpu_sw_netstats {
2021({ \ 2025({ \
2022 typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \ 2026 typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
2023 if (pcpu_stats) { \ 2027 if (pcpu_stats) { \
2024 int i; \ 2028 int __cpu; \
2025 for_each_possible_cpu(i) { \ 2029 for_each_possible_cpu(__cpu) { \
2026 typeof(type) *stat; \ 2030 typeof(type) *stat; \
2027 stat = per_cpu_ptr(pcpu_stats, i); \ 2031 stat = per_cpu_ptr(pcpu_stats, __cpu); \
2028 u64_stats_init(&stat->syncp); \ 2032 u64_stats_init(&stat->syncp); \
2029 } \ 2033 } \
2030 } \ 2034 } \
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index e23d242d1230..dbcbcc59aa92 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -282,7 +282,8 @@ static inline bool rht_shrink_below_30(const struct rhashtable *ht,
282static inline bool rht_grow_above_100(const struct rhashtable *ht, 282static inline bool rht_grow_above_100(const struct rhashtable *ht,
283 const struct bucket_table *tbl) 283 const struct bucket_table *tbl)
284{ 284{
285 return atomic_read(&ht->nelems) > tbl->size; 285 return atomic_read(&ht->nelems) > tbl->size &&
286 (!ht->p.max_size || tbl->size < ht->p.max_size);
286} 287}
287 288
288/* The bucket lock is selected based on the hash and protects mutations 289/* The bucket lock is selected based on the hash and protects mutations
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8222ae40ecb0..26a2e6122734 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -175,14 +175,6 @@ extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load);
175extern void calc_global_load(unsigned long ticks); 175extern void calc_global_load(unsigned long ticks);
176extern void update_cpu_load_nohz(void); 176extern void update_cpu_load_nohz(void);
177 177
178/* Notifier for when a task gets migrated to a new CPU */
179struct task_migration_notifier {
180 struct task_struct *task;
181 int from_cpu;
182 int to_cpu;
183};
184extern void register_task_migration_notifier(struct notifier_block *n);
185
186extern unsigned long get_parent_ip(unsigned long addr); 178extern unsigned long get_parent_ip(unsigned long addr);
187 179
188extern void dump_cpu_task(int cpu); 180extern void dump_cpu_task(int cpu);
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 06793b598f44..66e374d62f64 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -773,6 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
773 773
774struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags, 774struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
775 int node); 775 int node);
776struct sk_buff *__build_skb(void *data, unsigned int frag_size);
776struct sk_buff *build_skb(void *data, unsigned int frag_size); 777struct sk_buff *build_skb(void *data, unsigned int frag_size);
777static inline struct sk_buff *alloc_skb(unsigned int size, 778static inline struct sk_buff *alloc_skb(unsigned int size,
778 gfp_t priority) 779 gfp_t priority)
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 358a337af598..fe5623c9af71 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -491,6 +491,7 @@ static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
491 491
492extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); 492extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
493extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); 493extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b);
494extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
494 495
495extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 496extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
496extern void tty_ldisc_deref(struct tty_ldisc *); 497extern void tty_ldisc_deref(struct tty_ldisc *);
diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
index a7f2604c5f25..7f5f78bd15ad 100644
--- a/include/linux/usb_usual.h
+++ b/include/linux/usb_usual.h
@@ -77,6 +77,8 @@
77 /* Cannot handle ATA_12 or ATA_16 CDBs */ \ 77 /* Cannot handle ATA_12 or ATA_16 CDBs */ \
78 US_FLAG(NO_REPORT_OPCODES, 0x04000000) \ 78 US_FLAG(NO_REPORT_OPCODES, 0x04000000) \
79 /* Cannot handle MI_REPORT_SUPPORTED_OPERATION_CODES */ \ 79 /* Cannot handle MI_REPORT_SUPPORTED_OPERATION_CODES */ \
80 US_FLAG(MAX_SECTORS_240, 0x08000000) \
81 /* Sets max_sectors to 240 */ \
80 82
81#define US_FLAG(name, value) US_FL_##name = value , 83#define US_FLAG(name, value) US_FL_##name = value ,
82enum { US_DO_ALL_FLAGS }; 84enum { US_DO_ALL_FLAGS };
diff --git a/include/net/bonding.h b/include/net/bonding.h
index fda6feeb6c1f..78ed135e9dea 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -30,13 +30,6 @@
30#include <net/bond_alb.h> 30#include <net/bond_alb.h>
31#include <net/bond_options.h> 31#include <net/bond_options.h>
32 32
33#define DRV_VERSION "3.7.1"
34#define DRV_RELDATE "April 27, 2011"
35#define DRV_NAME "bonding"
36#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
37
38#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
39
40#define BOND_MAX_ARP_TARGETS 16 33#define BOND_MAX_ARP_TARGETS 16
41 34
42#define BOND_DEFAULT_MIIMON 100 35#define BOND_DEFAULT_MIIMON 100
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 7b5887cd1172..48a815823587 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -279,12 +279,6 @@ static inline void inet_csk_reqsk_queue_add(struct sock *sk,
279void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, 279void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
280 unsigned long timeout); 280 unsigned long timeout);
281 281
282static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
283 struct request_sock *req)
284{
285 reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
286}
287
288static inline void inet_csk_reqsk_queue_added(struct sock *sk, 282static inline void inet_csk_reqsk_queue_added(struct sock *sk,
289 const unsigned long timeout) 283 const unsigned long timeout)
290{ 284{
@@ -306,19 +300,7 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
306 return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue); 300 return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
307} 301}
308 302
309static inline void inet_csk_reqsk_queue_unlink(struct sock *sk, 303void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
310 struct request_sock *req)
311{
312 reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req);
313}
314
315static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
316 struct request_sock *req)
317{
318 inet_csk_reqsk_queue_unlink(sk, req);
319 inet_csk_reqsk_queue_removed(sk, req);
320 reqsk_put(req);
321}
322 304
323void inet_csk_destroy_sock(struct sock *sk); 305void inet_csk_destroy_sock(struct sock *sk);
324void inet_csk_prepare_forced_close(struct sock *sk); 306void inet_csk_prepare_forced_close(struct sock *sk);
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index fe41f3ceb008..9f4265ce8892 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -212,24 +212,6 @@ static inline int reqsk_queue_empty(struct request_sock_queue *queue)
212 return queue->rskq_accept_head == NULL; 212 return queue->rskq_accept_head == NULL;
213} 213}
214 214
215static inline void reqsk_queue_unlink(struct request_sock_queue *queue,
216 struct request_sock *req)
217{
218 struct listen_sock *lopt = queue->listen_opt;
219 struct request_sock **prev;
220
221 spin_lock(&queue->syn_wait_lock);
222
223 prev = &lopt->syn_table[req->rsk_hash];
224 while (*prev != req)
225 prev = &(*prev)->dl_next;
226 *prev = req->dl_next;
227
228 spin_unlock(&queue->syn_wait_lock);
229 if (del_timer(&req->rsk_timer))
230 reqsk_put(req);
231}
232
233static inline void reqsk_queue_add(struct request_sock_queue *queue, 215static inline void reqsk_queue_add(struct request_sock_queue *queue,
234 struct request_sock *req, 216 struct request_sock *req,
235 struct sock *parent, 217 struct sock *parent,
diff --git a/kernel/Makefile b/kernel/Makefile
index 0f8f8b0bc1bf..60c302cfb4d3 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -197,9 +197,9 @@ x509.genkey:
197 @echo >>x509.genkey "x509_extensions = myexts" 197 @echo >>x509.genkey "x509_extensions = myexts"
198 @echo >>x509.genkey 198 @echo >>x509.genkey
199 @echo >>x509.genkey "[ req_distinguished_name ]" 199 @echo >>x509.genkey "[ req_distinguished_name ]"
200 @echo >>x509.genkey "O = Magrathea" 200 @echo >>x509.genkey "#O = Unspecified company"
201 @echo >>x509.genkey "CN = Glacier signing key" 201 @echo >>x509.genkey "CN = Build time autogenerated kernel key"
202 @echo >>x509.genkey "emailAddress = slartibartfast@magrathea.h2g2" 202 @echo >>x509.genkey "#emailAddress = unspecified.user@unspecified.company"
203 @echo >>x509.genkey 203 @echo >>x509.genkey
204 @echo >>x509.genkey "[ myexts ]" 204 @echo >>x509.genkey "[ myexts ]"
205 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE" 205 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE"
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 38c25b1f2fd5..7a36fdcca5bf 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -707,7 +707,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image,
707 do { 707 do {
708 unsigned long pfn, epfn, addr, eaddr; 708 unsigned long pfn, epfn, addr, eaddr;
709 709
710 pages = kimage_alloc_pages(GFP_KERNEL, order); 710 pages = kimage_alloc_pages(KEXEC_CONTROL_MEMORY_GFP, order);
711 if (!pages) 711 if (!pages)
712 break; 712 break;
713 pfn = page_to_pfn(pages); 713 pfn = page_to_pfn(pages);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f9123a82cbb6..fe22f7510bce 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1016,13 +1016,6 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
1016 rq_clock_skip_update(rq, true); 1016 rq_clock_skip_update(rq, true);
1017} 1017}
1018 1018
1019static ATOMIC_NOTIFIER_HEAD(task_migration_notifier);
1020
1021void register_task_migration_notifier(struct notifier_block *n)
1022{
1023 atomic_notifier_chain_register(&task_migration_notifier, n);
1024}
1025
1026#ifdef CONFIG_SMP 1019#ifdef CONFIG_SMP
1027void set_task_cpu(struct task_struct *p, unsigned int new_cpu) 1020void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
1028{ 1021{
@@ -1053,18 +1046,10 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
1053 trace_sched_migrate_task(p, new_cpu); 1046 trace_sched_migrate_task(p, new_cpu);
1054 1047
1055 if (task_cpu(p) != new_cpu) { 1048 if (task_cpu(p) != new_cpu) {
1056 struct task_migration_notifier tmn;
1057
1058 if (p->sched_class->migrate_task_rq) 1049 if (p->sched_class->migrate_task_rq)
1059 p->sched_class->migrate_task_rq(p, new_cpu); 1050 p->sched_class->migrate_task_rq(p, new_cpu);
1060 p->se.nr_migrations++; 1051 p->se.nr_migrations++;
1061 perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0); 1052 perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0);
1062
1063 tmn.task = p;
1064 tmn.from_cpu = task_cpu(p);
1065 tmn.to_cpu = new_cpu;
1066
1067 atomic_notifier_call_chain(&task_migration_notifier, 0, &tmn);
1068 } 1053 }
1069 1054
1070 __set_task_cpu(p, new_cpu); 1055 __set_task_cpu(p, new_cpu);
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 4898442b837f..b28df4019ade 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -405,13 +405,18 @@ int rhashtable_insert_rehash(struct rhashtable *ht)
405 405
406 if (rht_grow_above_75(ht, tbl)) 406 if (rht_grow_above_75(ht, tbl))
407 size *= 2; 407 size *= 2;
408 /* More than two rehashes (not resizes) detected. */ 408 /* Do not schedule more than one rehash */
409 else if (WARN_ON(old_tbl != tbl && old_tbl->size == size)) 409 else if (old_tbl != tbl)
410 return -EBUSY; 410 return -EBUSY;
411 411
412 new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC); 412 new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
413 if (new_tbl == NULL) 413 if (new_tbl == NULL) {
414 /* Schedule async resize/rehash to try allocation
415 * non-atomic context.
416 */
417 schedule_work(&ht->run_work);
414 return -ENOMEM; 418 return -ENOMEM;
419 }
415 420
416 err = rhashtable_rehash_attach(ht, tbl, new_tbl); 421 err = rhashtable_rehash_attach(ht, tbl, new_tbl);
417 if (err) { 422 if (err) {
diff --git a/net/core/dev.c b/net/core/dev.c
index 1796cef55ab5..c7ba0388f1be 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3079,7 +3079,7 @@ static struct rps_dev_flow *
3079set_rps_cpu(struct net_device *dev, struct sk_buff *skb, 3079set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3080 struct rps_dev_flow *rflow, u16 next_cpu) 3080 struct rps_dev_flow *rflow, u16 next_cpu)
3081{ 3081{
3082 if (next_cpu != RPS_NO_CPU) { 3082 if (next_cpu < nr_cpu_ids) {
3083#ifdef CONFIG_RFS_ACCEL 3083#ifdef CONFIG_RFS_ACCEL
3084 struct netdev_rx_queue *rxqueue; 3084 struct netdev_rx_queue *rxqueue;
3085 struct rps_dev_flow_table *flow_table; 3085 struct rps_dev_flow_table *flow_table;
@@ -3184,7 +3184,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3184 * If the desired CPU (where last recvmsg was done) is 3184 * If the desired CPU (where last recvmsg was done) is
3185 * different from current CPU (one in the rx-queue flow 3185 * different from current CPU (one in the rx-queue flow
3186 * table entry), switch if one of the following holds: 3186 * table entry), switch if one of the following holds:
3187 * - Current CPU is unset (equal to RPS_NO_CPU). 3187 * - Current CPU is unset (>= nr_cpu_ids).
3188 * - Current CPU is offline. 3188 * - Current CPU is offline.
3189 * - The current CPU's queue tail has advanced beyond the 3189 * - The current CPU's queue tail has advanced beyond the
3190 * last packet that was enqueued using this table entry. 3190 * last packet that was enqueued using this table entry.
@@ -3192,14 +3192,14 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3192 * have been dequeued, thus preserving in order delivery. 3192 * have been dequeued, thus preserving in order delivery.
3193 */ 3193 */
3194 if (unlikely(tcpu != next_cpu) && 3194 if (unlikely(tcpu != next_cpu) &&
3195 (tcpu == RPS_NO_CPU || !cpu_online(tcpu) || 3195 (tcpu >= nr_cpu_ids || !cpu_online(tcpu) ||
3196 ((int)(per_cpu(softnet_data, tcpu).input_queue_head - 3196 ((int)(per_cpu(softnet_data, tcpu).input_queue_head -
3197 rflow->last_qtail)) >= 0)) { 3197 rflow->last_qtail)) >= 0)) {
3198 tcpu = next_cpu; 3198 tcpu = next_cpu;
3199 rflow = set_rps_cpu(dev, skb, rflow, next_cpu); 3199 rflow = set_rps_cpu(dev, skb, rflow, next_cpu);
3200 } 3200 }
3201 3201
3202 if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) { 3202 if (tcpu < nr_cpu_ids && cpu_online(tcpu)) {
3203 *rflowp = rflow; 3203 *rflowp = rflow;
3204 cpu = tcpu; 3204 cpu = tcpu;
3205 goto done; 3205 goto done;
@@ -3240,14 +3240,14 @@ bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index,
3240 struct rps_dev_flow_table *flow_table; 3240 struct rps_dev_flow_table *flow_table;
3241 struct rps_dev_flow *rflow; 3241 struct rps_dev_flow *rflow;
3242 bool expire = true; 3242 bool expire = true;
3243 int cpu; 3243 unsigned int cpu;
3244 3244
3245 rcu_read_lock(); 3245 rcu_read_lock();
3246 flow_table = rcu_dereference(rxqueue->rps_flow_table); 3246 flow_table = rcu_dereference(rxqueue->rps_flow_table);
3247 if (flow_table && flow_id <= flow_table->mask) { 3247 if (flow_table && flow_id <= flow_table->mask) {
3248 rflow = &flow_table->flows[flow_id]; 3248 rflow = &flow_table->flows[flow_id];
3249 cpu = ACCESS_ONCE(rflow->cpu); 3249 cpu = ACCESS_ONCE(rflow->cpu);
3250 if (rflow->filter == filter_id && cpu != RPS_NO_CPU && 3250 if (rflow->filter == filter_id && cpu < nr_cpu_ids &&
3251 ((int)(per_cpu(softnet_data, cpu).input_queue_head - 3251 ((int)(per_cpu(softnet_data, cpu).input_queue_head -
3252 rflow->last_qtail) < 3252 rflow->last_qtail) <
3253 (int)(10 * flow_table->mask))) 3253 (int)(10 * flow_table->mask)))
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d1967dab9cc6..3cfff2a3d651 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -280,13 +280,14 @@ nodata:
280EXPORT_SYMBOL(__alloc_skb); 280EXPORT_SYMBOL(__alloc_skb);
281 281
282/** 282/**
283 * build_skb - build a network buffer 283 * __build_skb - build a network buffer
284 * @data: data buffer provided by caller 284 * @data: data buffer provided by caller
285 * @frag_size: size of fragment, or 0 if head was kmalloced 285 * @frag_size: size of data, or 0 if head was kmalloced
286 * 286 *
287 * Allocate a new &sk_buff. Caller provides space holding head and 287 * Allocate a new &sk_buff. Caller provides space holding head and
288 * skb_shared_info. @data must have been allocated by kmalloc() only if 288 * skb_shared_info. @data must have been allocated by kmalloc() only if
289 * @frag_size is 0, otherwise data should come from the page allocator. 289 * @frag_size is 0, otherwise data should come from the page allocator
290 * or vmalloc()
290 * The return is the new skb buffer. 291 * The return is the new skb buffer.
291 * On a failure the return is %NULL, and @data is not freed. 292 * On a failure the return is %NULL, and @data is not freed.
292 * Notes : 293 * Notes :
@@ -297,7 +298,7 @@ EXPORT_SYMBOL(__alloc_skb);
297 * before giving packet to stack. 298 * before giving packet to stack.
298 * RX rings only contains data buffers, not full skbs. 299 * RX rings only contains data buffers, not full skbs.
299 */ 300 */
300struct sk_buff *build_skb(void *data, unsigned int frag_size) 301struct sk_buff *__build_skb(void *data, unsigned int frag_size)
301{ 302{
302 struct skb_shared_info *shinfo; 303 struct skb_shared_info *shinfo;
303 struct sk_buff *skb; 304 struct sk_buff *skb;
@@ -311,7 +312,6 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
311 312
312 memset(skb, 0, offsetof(struct sk_buff, tail)); 313 memset(skb, 0, offsetof(struct sk_buff, tail));
313 skb->truesize = SKB_TRUESIZE(size); 314 skb->truesize = SKB_TRUESIZE(size);
314 skb->head_frag = frag_size != 0;
315 atomic_set(&skb->users, 1); 315 atomic_set(&skb->users, 1);
316 skb->head = data; 316 skb->head = data;
317 skb->data = data; 317 skb->data = data;
@@ -328,6 +328,23 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
328 328
329 return skb; 329 return skb;
330} 330}
331
332/* build_skb() is wrapper over __build_skb(), that specifically
333 * takes care of skb->head and skb->pfmemalloc
334 * This means that if @frag_size is not zero, then @data must be backed
335 * by a page fragment, not kmalloc() or vmalloc()
336 */
337struct sk_buff *build_skb(void *data, unsigned int frag_size)
338{
339 struct sk_buff *skb = __build_skb(data, frag_size);
340
341 if (skb && frag_size) {
342 skb->head_frag = 1;
343 if (virt_to_head_page(data)->pfmemalloc)
344 skb->pfmemalloc = 1;
345 }
346 return skb;
347}
331EXPORT_SYMBOL(build_skb); 348EXPORT_SYMBOL(build_skb);
332 349
333struct netdev_alloc_cache { 350struct netdev_alloc_cache {
@@ -348,7 +365,8 @@ static struct page *__page_frag_refill(struct netdev_alloc_cache *nc,
348 gfp_t gfp = gfp_mask; 365 gfp_t gfp = gfp_mask;
349 366
350 if (order) { 367 if (order) {
351 gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY; 368 gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY |
369 __GFP_NOMEMALLOC;
352 page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order); 370 page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order);
353 nc->frag.size = PAGE_SIZE << (page ? order : 0); 371 nc->frag.size = PAGE_SIZE << (page ? order : 0);
354 } 372 }
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 2b4f21d34df6..ccf4c5629b3c 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -453,7 +453,8 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
453 iph->saddr, iph->daddr); 453 iph->saddr, iph->daddr);
454 if (req) { 454 if (req) {
455 nsk = dccp_check_req(sk, skb, req); 455 nsk = dccp_check_req(sk, skb, req);
456 reqsk_put(req); 456 if (!nsk)
457 reqsk_put(req);
457 return nsk; 458 return nsk;
458 } 459 }
459 nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo, 460 nsk = inet_lookup_established(sock_net(sk), &dccp_hashinfo,
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 9d0551092c6c..5165571f397a 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -301,7 +301,8 @@ static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
301 &iph->daddr, inet6_iif(skb)); 301 &iph->daddr, inet6_iif(skb));
302 if (req) { 302 if (req) {
303 nsk = dccp_check_req(sk, skb, req); 303 nsk = dccp_check_req(sk, skb, req);
304 reqsk_put(req); 304 if (!nsk)
305 reqsk_put(req);
305 return nsk; 306 return nsk;
306 } 307 }
307 nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo, 308 nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo,
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 5f566663e47f..30addee2dd03 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -186,8 +186,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
186 if (child == NULL) 186 if (child == NULL)
187 goto listen_overflow; 187 goto listen_overflow;
188 188
189 inet_csk_reqsk_queue_unlink(sk, req); 189 inet_csk_reqsk_queue_drop(sk, req);
190 inet_csk_reqsk_queue_removed(sk, req);
191 inet_csk_reqsk_queue_add(sk, req, child); 190 inet_csk_reqsk_queue_add(sk, req, child);
192out: 191out:
193 return child; 192 return child;
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 5c3dd6267ed3..8976ca423a07 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -564,6 +564,40 @@ int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req)
564} 564}
565EXPORT_SYMBOL(inet_rtx_syn_ack); 565EXPORT_SYMBOL(inet_rtx_syn_ack);
566 566
567/* return true if req was found in the syn_table[] */
568static bool reqsk_queue_unlink(struct request_sock_queue *queue,
569 struct request_sock *req)
570{
571 struct listen_sock *lopt = queue->listen_opt;
572 struct request_sock **prev;
573 bool found = false;
574
575 spin_lock(&queue->syn_wait_lock);
576
577 for (prev = &lopt->syn_table[req->rsk_hash]; *prev != NULL;
578 prev = &(*prev)->dl_next) {
579 if (*prev == req) {
580 *prev = req->dl_next;
581 found = true;
582 break;
583 }
584 }
585
586 spin_unlock(&queue->syn_wait_lock);
587 if (del_timer(&req->rsk_timer))
588 reqsk_put(req);
589 return found;
590}
591
592void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req)
593{
594 if (reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req)) {
595 reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
596 reqsk_put(req);
597 }
598}
599EXPORT_SYMBOL(inet_csk_reqsk_queue_drop);
600
567static void reqsk_timer_handler(unsigned long data) 601static void reqsk_timer_handler(unsigned long data)
568{ 602{
569 struct request_sock *req = (struct request_sock *)data; 603 struct request_sock *req = (struct request_sock *)data;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3571f2be4470..fc1c658ec6c1 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1348,7 +1348,8 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
1348 req = inet_csk_search_req(sk, th->source, iph->saddr, iph->daddr); 1348 req = inet_csk_search_req(sk, th->source, iph->saddr, iph->daddr);
1349 if (req) { 1349 if (req) {
1350 nsk = tcp_check_req(sk, skb, req, false); 1350 nsk = tcp_check_req(sk, skb, req, false);
1351 reqsk_put(req); 1351 if (!nsk)
1352 reqsk_put(req);
1352 return nsk; 1353 return nsk;
1353 } 1354 }
1354 1355
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 63d6311b5365..e5d7649136fc 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -755,10 +755,11 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
755 if (!child) 755 if (!child)
756 goto listen_overflow; 756 goto listen_overflow;
757 757
758 inet_csk_reqsk_queue_unlink(sk, req); 758 inet_csk_reqsk_queue_drop(sk, req);
759 inet_csk_reqsk_queue_removed(sk, req);
760
761 inet_csk_reqsk_queue_add(sk, req, child); 759 inet_csk_reqsk_queue_add(sk, req, child);
760 /* Warning: caller must not call reqsk_put(req);
761 * child stole last reference on it.
762 */
762 return child; 763 return child;
763 764
764listen_overflow: 765listen_overflow:
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 8c8d7e06b72f..a369e8a70b2c 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2812,39 +2812,65 @@ begin_fwd:
2812 } 2812 }
2813} 2813}
2814 2814
2815/* Send a fin. The caller locks the socket for us. This cannot be 2815/* We allow to exceed memory limits for FIN packets to expedite
2816 * allowed to fail queueing a FIN frame under any circumstances. 2816 * connection tear down and (memory) recovery.
2817 * Otherwise tcp_send_fin() could be tempted to either delay FIN
2818 * or even be forced to close flow without any FIN.
2819 */
2820static void sk_forced_wmem_schedule(struct sock *sk, int size)
2821{
2822 int amt, status;
2823
2824 if (size <= sk->sk_forward_alloc)
2825 return;
2826 amt = sk_mem_pages(size);
2827 sk->sk_forward_alloc += amt * SK_MEM_QUANTUM;
2828 sk_memory_allocated_add(sk, amt, &status);
2829}
2830
2831/* Send a FIN. The caller locks the socket for us.
2832 * We should try to send a FIN packet really hard, but eventually give up.
2817 */ 2833 */
2818void tcp_send_fin(struct sock *sk) 2834void tcp_send_fin(struct sock *sk)
2819{ 2835{
2836 struct sk_buff *skb, *tskb = tcp_write_queue_tail(sk);
2820 struct tcp_sock *tp = tcp_sk(sk); 2837 struct tcp_sock *tp = tcp_sk(sk);
2821 struct sk_buff *skb = tcp_write_queue_tail(sk);
2822 int mss_now;
2823 2838
2824 /* Optimization, tack on the FIN if we have a queue of 2839 /* Optimization, tack on the FIN if we have one skb in write queue and
2825 * unsent frames. But be careful about outgoing SACKS 2840 * this skb was not yet sent, or we are under memory pressure.
2826 * and IP options. 2841 * Note: in the latter case, FIN packet will be sent after a timeout,
2842 * as TCP stack thinks it has already been transmitted.
2827 */ 2843 */
2828 mss_now = tcp_current_mss(sk); 2844 if (tskb && (tcp_send_head(sk) || sk_under_memory_pressure(sk))) {
2829 2845coalesce:
2830 if (tcp_send_head(sk)) { 2846 TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN;
2831 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_FIN; 2847 TCP_SKB_CB(tskb)->end_seq++;
2832 TCP_SKB_CB(skb)->end_seq++;
2833 tp->write_seq++; 2848 tp->write_seq++;
2849 if (!tcp_send_head(sk)) {
2850 /* This means tskb was already sent.
2851 * Pretend we included the FIN on previous transmit.
2852 * We need to set tp->snd_nxt to the value it would have
2853 * if FIN had been sent. This is because retransmit path
2854 * does not change tp->snd_nxt.
2855 */
2856 tp->snd_nxt++;
2857 return;
2858 }
2834 } else { 2859 } else {
2835 /* Socket is locked, keep trying until memory is available. */ 2860 skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
2836 for (;;) { 2861 if (unlikely(!skb)) {
2837 skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation); 2862 if (tskb)
2838 if (skb) 2863 goto coalesce;
2839 break; 2864 return;
2840 yield();
2841 } 2865 }
2866 skb_reserve(skb, MAX_TCP_HEADER);
2867 sk_forced_wmem_schedule(sk, skb->truesize);
2842 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */ 2868 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
2843 tcp_init_nondata_skb(skb, tp->write_seq, 2869 tcp_init_nondata_skb(skb, tp->write_seq,
2844 TCPHDR_ACK | TCPHDR_FIN); 2870 TCPHDR_ACK | TCPHDR_FIN);
2845 tcp_queue_skb(sk, skb); 2871 tcp_queue_skb(sk, skb);
2846 } 2872 }
2847 __tcp_push_pending_frames(sk, mss_now, TCP_NAGLE_OFF); 2873 __tcp_push_pending_frames(sk, tcp_current_mss(sk), TCP_NAGLE_OFF);
2848} 2874}
2849 2875
2850/* We get here when a process closes a file descriptor (either due to 2876/* We get here when a process closes a file descriptor (either due to
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b5e6cc1d4a73..a38d3ac0f18f 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1246,7 +1246,6 @@ static void ip6gre_tunnel_setup(struct net_device *dev)
1246static int ip6gre_tunnel_init(struct net_device *dev) 1246static int ip6gre_tunnel_init(struct net_device *dev)
1247{ 1247{
1248 struct ip6_tnl *tunnel; 1248 struct ip6_tnl *tunnel;
1249 int i;
1250 1249
1251 tunnel = netdev_priv(dev); 1250 tunnel = netdev_priv(dev);
1252 1251
@@ -1260,16 +1259,10 @@ static int ip6gre_tunnel_init(struct net_device *dev)
1260 if (ipv6_addr_any(&tunnel->parms.raddr)) 1259 if (ipv6_addr_any(&tunnel->parms.raddr))
1261 dev->header_ops = &ip6gre_header_ops; 1260 dev->header_ops = &ip6gre_header_ops;
1262 1261
1263 dev->tstats = alloc_percpu(struct pcpu_sw_netstats); 1262 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1264 if (!dev->tstats) 1263 if (!dev->tstats)
1265 return -ENOMEM; 1264 return -ENOMEM;
1266 1265
1267 for_each_possible_cpu(i) {
1268 struct pcpu_sw_netstats *ip6gre_tunnel_stats;
1269 ip6gre_tunnel_stats = per_cpu_ptr(dev->tstats, i);
1270 u64_stats_init(&ip6gre_tunnel_stats->syncp);
1271 }
1272
1273 return 0; 1266 return 0;
1274} 1267}
1275 1268
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index ad51df85aa00..b6575d665568 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -946,7 +946,8 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk, struct sk_buff *skb)
946 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb)); 946 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb));
947 if (req) { 947 if (req) {
948 nsk = tcp_check_req(sk, skb, req, false); 948 nsk = tcp_check_req(sk, skb, req, false);
949 reqsk_put(req); 949 if (!nsk)
950 reqsk_put(req);
950 return nsk; 951 return nsk;
951 } 952 }
952 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo, 953 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo,
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index db8a2ea6d4de..954810c76a86 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -53,6 +53,11 @@ static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
53 return rt; 53 return rt;
54} 54}
55 55
56static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
57{
58 return rcu_dereference_rtnl(dev->mpls_ptr);
59}
60
56static bool mpls_output_possible(const struct net_device *dev) 61static bool mpls_output_possible(const struct net_device *dev)
57{ 62{
58 return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev); 63 return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev);
@@ -136,6 +141,7 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
136 struct mpls_route *rt; 141 struct mpls_route *rt;
137 struct mpls_entry_decoded dec; 142 struct mpls_entry_decoded dec;
138 struct net_device *out_dev; 143 struct net_device *out_dev;
144 struct mpls_dev *mdev;
139 unsigned int hh_len; 145 unsigned int hh_len;
140 unsigned int new_header_size; 146 unsigned int new_header_size;
141 unsigned int mtu; 147 unsigned int mtu;
@@ -143,6 +149,10 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
143 149
144 /* Careful this entire function runs inside of an rcu critical section */ 150 /* Careful this entire function runs inside of an rcu critical section */
145 151
152 mdev = mpls_dev_get(dev);
153 if (!mdev || !mdev->input_enabled)
154 goto drop;
155
146 if (skb->pkt_type != PACKET_HOST) 156 if (skb->pkt_type != PACKET_HOST)
147 goto drop; 157 goto drop;
148 158
@@ -352,9 +362,9 @@ static int mpls_route_add(struct mpls_route_config *cfg)
352 if (!dev) 362 if (!dev)
353 goto errout; 363 goto errout;
354 364
355 /* For now just support ethernet devices */ 365 /* Ensure this is a supported device */
356 err = -EINVAL; 366 err = -EINVAL;
357 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK)) 367 if (!mpls_dev_get(dev))
358 goto errout; 368 goto errout;
359 369
360 err = -EINVAL; 370 err = -EINVAL;
@@ -428,10 +438,89 @@ errout:
428 return err; 438 return err;
429} 439}
430 440
441#define MPLS_PERDEV_SYSCTL_OFFSET(field) \
442 (&((struct mpls_dev *)0)->field)
443
444static const struct ctl_table mpls_dev_table[] = {
445 {
446 .procname = "input",
447 .maxlen = sizeof(int),
448 .mode = 0644,
449 .proc_handler = proc_dointvec,
450 .data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled),
451 },
452 { }
453};
454
455static int mpls_dev_sysctl_register(struct net_device *dev,
456 struct mpls_dev *mdev)
457{
458 char path[sizeof("net/mpls/conf/") + IFNAMSIZ];
459 struct ctl_table *table;
460 int i;
461
462 table = kmemdup(&mpls_dev_table, sizeof(mpls_dev_table), GFP_KERNEL);
463 if (!table)
464 goto out;
465
466 /* Table data contains only offsets relative to the base of
467 * the mdev at this point, so make them absolute.
468 */
469 for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++)
470 table[i].data = (char *)mdev + (uintptr_t)table[i].data;
471
472 snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name);
473
474 mdev->sysctl = register_net_sysctl(dev_net(dev), path, table);
475 if (!mdev->sysctl)
476 goto free;
477
478 return 0;
479
480free:
481 kfree(table);
482out:
483 return -ENOBUFS;
484}
485
486static void mpls_dev_sysctl_unregister(struct mpls_dev *mdev)
487{
488 struct ctl_table *table;
489
490 table = mdev->sysctl->ctl_table_arg;
491 unregister_net_sysctl_table(mdev->sysctl);
492 kfree(table);
493}
494
495static struct mpls_dev *mpls_add_dev(struct net_device *dev)
496{
497 struct mpls_dev *mdev;
498 int err = -ENOMEM;
499
500 ASSERT_RTNL();
501
502 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
503 if (!mdev)
504 return ERR_PTR(err);
505
506 err = mpls_dev_sysctl_register(dev, mdev);
507 if (err)
508 goto free;
509
510 rcu_assign_pointer(dev->mpls_ptr, mdev);
511
512 return mdev;
513
514free:
515 kfree(mdev);
516 return ERR_PTR(err);
517}
518
431static void mpls_ifdown(struct net_device *dev) 519static void mpls_ifdown(struct net_device *dev)
432{ 520{
433 struct mpls_route __rcu **platform_label; 521 struct mpls_route __rcu **platform_label;
434 struct net *net = dev_net(dev); 522 struct net *net = dev_net(dev);
523 struct mpls_dev *mdev;
435 unsigned index; 524 unsigned index;
436 525
437 platform_label = rtnl_dereference(net->mpls.platform_label); 526 platform_label = rtnl_dereference(net->mpls.platform_label);
@@ -443,14 +532,35 @@ static void mpls_ifdown(struct net_device *dev)
443 continue; 532 continue;
444 rt->rt_dev = NULL; 533 rt->rt_dev = NULL;
445 } 534 }
535
536 mdev = mpls_dev_get(dev);
537 if (!mdev)
538 return;
539
540 mpls_dev_sysctl_unregister(mdev);
541
542 RCU_INIT_POINTER(dev->mpls_ptr, NULL);
543
544 kfree(mdev);
446} 545}
447 546
448static int mpls_dev_notify(struct notifier_block *this, unsigned long event, 547static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
449 void *ptr) 548 void *ptr)
450{ 549{
451 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 550 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
551 struct mpls_dev *mdev;
452 552
453 switch(event) { 553 switch(event) {
554 case NETDEV_REGISTER:
555 /* For now just support ethernet devices */
556 if ((dev->type == ARPHRD_ETHER) ||
557 (dev->type == ARPHRD_LOOPBACK)) {
558 mdev = mpls_add_dev(dev);
559 if (IS_ERR(mdev))
560 return notifier_from_errno(PTR_ERR(mdev));
561 }
562 break;
563
454 case NETDEV_UNREGISTER: 564 case NETDEV_UNREGISTER:
455 mpls_ifdown(dev); 565 mpls_ifdown(dev);
456 break; 566 break;
@@ -536,6 +646,15 @@ int nla_get_labels(const struct nlattr *nla,
536 if ((dec.bos != bos) || dec.ttl || dec.tc) 646 if ((dec.bos != bos) || dec.ttl || dec.tc)
537 return -EINVAL; 647 return -EINVAL;
538 648
649 switch (dec.label) {
650 case LABEL_IMPLICIT_NULL:
651 /* RFC3032: This is a label that an LSR may
652 * assign and distribute, but which never
653 * actually appears in the encapsulation.
654 */
655 return -EINVAL;
656 }
657
539 label[i] = dec.label; 658 label[i] = dec.label;
540 } 659 }
541 *labels = nla_labels; 660 *labels = nla_labels;
@@ -912,7 +1031,7 @@ static int mpls_platform_labels(struct ctl_table *table, int write,
912 return ret; 1031 return ret;
913} 1032}
914 1033
915static struct ctl_table mpls_table[] = { 1034static const struct ctl_table mpls_table[] = {
916 { 1035 {
917 .procname = "platform_labels", 1036 .procname = "platform_labels",
918 .data = NULL, 1037 .data = NULL,
diff --git a/net/mpls/internal.h b/net/mpls/internal.h
index fb6de92052c4..693877d69606 100644
--- a/net/mpls/internal.h
+++ b/net/mpls/internal.h
@@ -22,6 +22,12 @@ struct mpls_entry_decoded {
22 u8 bos; 22 u8 bos;
23}; 23};
24 24
25struct mpls_dev {
26 int input_enabled;
27
28 struct ctl_table_header *sysctl;
29};
30
25struct sk_buff; 31struct sk_buff;
26 32
27static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) 33static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
diff --git a/net/netfilter/nft_reject.c b/net/netfilter/nft_reject.c
index 57d3e1af5630..0522fc9bfb0a 100644
--- a/net/netfilter/nft_reject.c
+++ b/net/netfilter/nft_reject.c
@@ -63,6 +63,8 @@ int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
63 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) 63 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
64 goto nla_put_failure; 64 goto nla_put_failure;
65 break; 65 break;
66 default:
67 break;
66 } 68 }
67 69
68 return 0; 70 return 0;
diff --git a/net/netfilter/nft_reject_inet.c b/net/netfilter/nft_reject_inet.c
index 62cabee42fbe..635dbba93d01 100644
--- a/net/netfilter/nft_reject_inet.c
+++ b/net/netfilter/nft_reject_inet.c
@@ -108,6 +108,8 @@ static int nft_reject_inet_dump(struct sk_buff *skb,
108 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) 108 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
109 goto nla_put_failure; 109 goto nla_put_failure;
110 break; 110 break;
111 default:
112 break;
111 } 113 }
112 114
113 return 0; 115 return 0;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 19909d0786a2..ec4adbdcb9b4 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1629,13 +1629,11 @@ static struct sk_buff *netlink_alloc_large_skb(unsigned int size,
1629 if (data == NULL) 1629 if (data == NULL)
1630 return NULL; 1630 return NULL;
1631 1631
1632 skb = build_skb(data, size); 1632 skb = __build_skb(data, size);
1633 if (skb == NULL) 1633 if (skb == NULL)
1634 vfree(data); 1634 vfree(data);
1635 else { 1635 else
1636 skb->head_frag = 0;
1637 skb->destructor = netlink_skb_destructor; 1636 skb->destructor = netlink_skb_destructor;
1638 }
1639 1637
1640 return skb; 1638 return skb;
1641} 1639}
diff --git a/net/tipc/link.c b/net/tipc/link.c
index a6b30df6ec02..57be6e6aff99 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -2143,7 +2143,6 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb)
2143 err = __tipc_nl_add_node_links(net, &msg, node, 2143 err = __tipc_nl_add_node_links(net, &msg, node,
2144 &prev_link); 2144 &prev_link);
2145 tipc_node_unlock(node); 2145 tipc_node_unlock(node);
2146 tipc_node_put(node);
2147 if (err) 2146 if (err)
2148 goto out; 2147 goto out;
2149 2148
diff --git a/net/tipc/server.c b/net/tipc/server.c
index ab6183cdb121..77ff03ed1e18 100644
--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -102,7 +102,7 @@ static void tipc_conn_kref_release(struct kref *kref)
102 } 102 }
103 saddr->scope = -TIPC_NODE_SCOPE; 103 saddr->scope = -TIPC_NODE_SCOPE;
104 kernel_bind(sock, (struct sockaddr *)saddr, sizeof(*saddr)); 104 kernel_bind(sock, (struct sockaddr *)saddr, sizeof(*saddr));
105 sk_release_kernel(sk); 105 sock_release(sock);
106 con->sock = NULL; 106 con->sock = NULL;
107 } 107 }
108 108
@@ -321,12 +321,9 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
321 struct socket *sock = NULL; 321 struct socket *sock = NULL;
322 int ret; 322 int ret;
323 323
324 ret = sock_create_kern(AF_TIPC, SOCK_SEQPACKET, 0, &sock); 324 ret = __sock_create(s->net, AF_TIPC, SOCK_SEQPACKET, 0, &sock, 1);
325 if (ret < 0) 325 if (ret < 0)
326 return NULL; 326 return NULL;
327
328 sk_change_net(sock->sk, s->net);
329
330 ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE, 327 ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE,
331 (char *)&s->imp, sizeof(s->imp)); 328 (char *)&s->imp, sizeof(s->imp));
332 if (ret < 0) 329 if (ret < 0)
@@ -376,7 +373,7 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
376 373
377create_err: 374create_err:
378 kernel_sock_shutdown(sock, SHUT_RDWR); 375 kernel_sock_shutdown(sock, SHUT_RDWR);
379 sk_release_kernel(sock->sk); 376 sock_release(sock);
380 return NULL; 377 return NULL;
381} 378}
382 379
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index ee90d74d7516..9074b5cede38 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1764,13 +1764,14 @@ static int tipc_sk_enqueue(struct sk_buff_head *inputq, struct sock *sk,
1764int tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq) 1764int tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq)
1765{ 1765{
1766 u32 dnode, dport = 0; 1766 u32 dnode, dport = 0;
1767 int err = -TIPC_ERR_NO_PORT; 1767 int err;
1768 struct sk_buff *skb; 1768 struct sk_buff *skb;
1769 struct tipc_sock *tsk; 1769 struct tipc_sock *tsk;
1770 struct tipc_net *tn; 1770 struct tipc_net *tn;
1771 struct sock *sk; 1771 struct sock *sk;
1772 1772
1773 while (skb_queue_len(inputq)) { 1773 while (skb_queue_len(inputq)) {
1774 err = -TIPC_ERR_NO_PORT;
1774 skb = NULL; 1775 skb = NULL;
1775 dport = tipc_skb_peek_port(inputq, dport); 1776 dport = tipc_skb_peek_port(inputq, dport);
1776 tsk = tipc_sk_lookup(net, dport); 1777 tsk = tipc_sk_lookup(net, dport);
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 99f7012b23b9..a73a226f2d33 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -95,39 +95,36 @@ static DECLARE_WAIT_QUEUE_HEAD(unix_gc_wait);
95 95
96unsigned int unix_tot_inflight; 96unsigned int unix_tot_inflight;
97 97
98
99struct sock *unix_get_socket(struct file *filp) 98struct sock *unix_get_socket(struct file *filp)
100{ 99{
101 struct sock *u_sock = NULL; 100 struct sock *u_sock = NULL;
102 struct inode *inode = file_inode(filp); 101 struct inode *inode = file_inode(filp);
103 102
104 /* 103 /* Socket ? */
105 * Socket ?
106 */
107 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) { 104 if (S_ISSOCK(inode->i_mode) && !(filp->f_mode & FMODE_PATH)) {
108 struct socket *sock = SOCKET_I(inode); 105 struct socket *sock = SOCKET_I(inode);
109 struct sock *s = sock->sk; 106 struct sock *s = sock->sk;
110 107
111 /* 108 /* PF_UNIX ? */
112 * PF_UNIX ?
113 */
114 if (s && sock->ops && sock->ops->family == PF_UNIX) 109 if (s && sock->ops && sock->ops->family == PF_UNIX)
115 u_sock = s; 110 u_sock = s;
116 } 111 }
117 return u_sock; 112 return u_sock;
118} 113}
119 114
120/* 115/* Keep the number of times in flight count for the file
121 * Keep the number of times in flight count for the file 116 * descriptor if it is for an AF_UNIX socket.
122 * descriptor if it is for an AF_UNIX socket.
123 */ 117 */
124 118
125void unix_inflight(struct file *fp) 119void unix_inflight(struct file *fp)
126{ 120{
127 struct sock *s = unix_get_socket(fp); 121 struct sock *s = unix_get_socket(fp);
122
128 if (s) { 123 if (s) {
129 struct unix_sock *u = unix_sk(s); 124 struct unix_sock *u = unix_sk(s);
125
130 spin_lock(&unix_gc_lock); 126 spin_lock(&unix_gc_lock);
127
131 if (atomic_long_inc_return(&u->inflight) == 1) { 128 if (atomic_long_inc_return(&u->inflight) == 1) {
132 BUG_ON(!list_empty(&u->link)); 129 BUG_ON(!list_empty(&u->link));
133 list_add_tail(&u->link, &gc_inflight_list); 130 list_add_tail(&u->link, &gc_inflight_list);
@@ -142,10 +139,13 @@ void unix_inflight(struct file *fp)
142void unix_notinflight(struct file *fp) 139void unix_notinflight(struct file *fp)
143{ 140{
144 struct sock *s = unix_get_socket(fp); 141 struct sock *s = unix_get_socket(fp);
142
145 if (s) { 143 if (s) {
146 struct unix_sock *u = unix_sk(s); 144 struct unix_sock *u = unix_sk(s);
145
147 spin_lock(&unix_gc_lock); 146 spin_lock(&unix_gc_lock);
148 BUG_ON(list_empty(&u->link)); 147 BUG_ON(list_empty(&u->link));
148
149 if (atomic_long_dec_and_test(&u->inflight)) 149 if (atomic_long_dec_and_test(&u->inflight))
150 list_del_init(&u->link); 150 list_del_init(&u->link);
151 unix_tot_inflight--; 151 unix_tot_inflight--;
@@ -161,32 +161,27 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
161 161
162 spin_lock(&x->sk_receive_queue.lock); 162 spin_lock(&x->sk_receive_queue.lock);
163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 163 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
164 /* 164 /* Do we have file descriptors ? */
165 * Do we have file descriptors ?
166 */
167 if (UNIXCB(skb).fp) { 165 if (UNIXCB(skb).fp) {
168 bool hit = false; 166 bool hit = false;
169 /* 167 /* Process the descriptors of this socket */
170 * Process the descriptors of this socket
171 */
172 int nfd = UNIXCB(skb).fp->count; 168 int nfd = UNIXCB(skb).fp->count;
173 struct file **fp = UNIXCB(skb).fp->fp; 169 struct file **fp = UNIXCB(skb).fp->fp;
170
174 while (nfd--) { 171 while (nfd--) {
175 /* 172 /* Get the socket the fd matches if it indeed does so */
176 * Get the socket the fd matches
177 * if it indeed does so
178 */
179 struct sock *sk = unix_get_socket(*fp++); 173 struct sock *sk = unix_get_socket(*fp++);
174
180 if (sk) { 175 if (sk) {
181 struct unix_sock *u = unix_sk(sk); 176 struct unix_sock *u = unix_sk(sk);
182 177
183 /* 178 /* Ignore non-candidates, they could
184 * Ignore non-candidates, they could
185 * have been added to the queues after 179 * have been added to the queues after
186 * starting the garbage collection 180 * starting the garbage collection
187 */ 181 */
188 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) { 182 if (test_bit(UNIX_GC_CANDIDATE, &u->gc_flags)) {
189 hit = true; 183 hit = true;
184
190 func(u); 185 func(u);
191 } 186 }
192 } 187 }
@@ -203,24 +198,22 @@ static void scan_inflight(struct sock *x, void (*func)(struct unix_sock *),
203static void scan_children(struct sock *x, void (*func)(struct unix_sock *), 198static void scan_children(struct sock *x, void (*func)(struct unix_sock *),
204 struct sk_buff_head *hitlist) 199 struct sk_buff_head *hitlist)
205{ 200{
206 if (x->sk_state != TCP_LISTEN) 201 if (x->sk_state != TCP_LISTEN) {
207 scan_inflight(x, func, hitlist); 202 scan_inflight(x, func, hitlist);
208 else { 203 } else {
209 struct sk_buff *skb; 204 struct sk_buff *skb;
210 struct sk_buff *next; 205 struct sk_buff *next;
211 struct unix_sock *u; 206 struct unix_sock *u;
212 LIST_HEAD(embryos); 207 LIST_HEAD(embryos);
213 208
214 /* 209 /* For a listening socket collect the queued embryos
215 * For a listening socket collect the queued embryos
216 * and perform a scan on them as well. 210 * and perform a scan on them as well.
217 */ 211 */
218 spin_lock(&x->sk_receive_queue.lock); 212 spin_lock(&x->sk_receive_queue.lock);
219 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) { 213 skb_queue_walk_safe(&x->sk_receive_queue, skb, next) {
220 u = unix_sk(skb->sk); 214 u = unix_sk(skb->sk);
221 215
222 /* 216 /* An embryo cannot be in-flight, so it's safe
223 * An embryo cannot be in-flight, so it's safe
224 * to use the list link. 217 * to use the list link.
225 */ 218 */
226 BUG_ON(!list_empty(&u->link)); 219 BUG_ON(!list_empty(&u->link));
@@ -249,8 +242,7 @@ static void inc_inflight(struct unix_sock *usk)
249static void inc_inflight_move_tail(struct unix_sock *u) 242static void inc_inflight_move_tail(struct unix_sock *u)
250{ 243{
251 atomic_long_inc(&u->inflight); 244 atomic_long_inc(&u->inflight);
252 /* 245 /* If this still might be part of a cycle, move it to the end
253 * If this still might be part of a cycle, move it to the end
254 * of the list, so that it's checked even if it was already 246 * of the list, so that it's checked even if it was already
255 * passed over 247 * passed over
256 */ 248 */
@@ -263,8 +255,7 @@ static bool gc_in_progress;
263 255
264void wait_for_unix_gc(void) 256void wait_for_unix_gc(void)
265{ 257{
266 /* 258 /* If number of inflight sockets is insane,
267 * If number of inflight sockets is insane,
268 * force a garbage collect right now. 259 * force a garbage collect right now.
269 */ 260 */
270 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress) 261 if (unix_tot_inflight > UNIX_INFLIGHT_TRIGGER_GC && !gc_in_progress)
@@ -288,8 +279,7 @@ void unix_gc(void)
288 goto out; 279 goto out;
289 280
290 gc_in_progress = true; 281 gc_in_progress = true;
291 /* 282 /* First, select candidates for garbage collection. Only
292 * First, select candidates for garbage collection. Only
293 * in-flight sockets are considered, and from those only ones 283 * in-flight sockets are considered, and from those only ones
294 * which don't have any external reference. 284 * which don't have any external reference.
295 * 285 *
@@ -320,15 +310,13 @@ void unix_gc(void)
320 } 310 }
321 } 311 }
322 312
323 /* 313 /* Now remove all internal in-flight reference to children of
324 * Now remove all internal in-flight reference to children of
325 * the candidates. 314 * the candidates.
326 */ 315 */
327 list_for_each_entry(u, &gc_candidates, link) 316 list_for_each_entry(u, &gc_candidates, link)
328 scan_children(&u->sk, dec_inflight, NULL); 317 scan_children(&u->sk, dec_inflight, NULL);
329 318
330 /* 319 /* Restore the references for children of all candidates,
331 * Restore the references for children of all candidates,
332 * which have remaining references. Do this recursively, so 320 * which have remaining references. Do this recursively, so
333 * only those remain, which form cyclic references. 321 * only those remain, which form cyclic references.
334 * 322 *
@@ -350,8 +338,7 @@ void unix_gc(void)
350 } 338 }
351 list_del(&cursor); 339 list_del(&cursor);
352 340
353 /* 341 /* not_cycle_list contains those sockets which do not make up a
354 * not_cycle_list contains those sockets which do not make up a
355 * cycle. Restore these to the inflight list. 342 * cycle. Restore these to the inflight list.
356 */ 343 */
357 while (!list_empty(&not_cycle_list)) { 344 while (!list_empty(&not_cycle_list)) {
@@ -360,8 +347,7 @@ void unix_gc(void)
360 list_move_tail(&u->link, &gc_inflight_list); 347 list_move_tail(&u->link, &gc_inflight_list);
361 } 348 }
362 349
363 /* 350 /* Now gc_candidates contains only garbage. Restore original
364 * Now gc_candidates contains only garbage. Restore original
365 * inflight counters for these as well, and remove the skbuffs 351 * inflight counters for these as well, and remove the skbuffs
366 * which are creating the cycle(s). 352 * which are creating the cycle(s).
367 */ 353 */