aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/pci/hisilicon-pcie.txt10
-rw-r--r--Documentation/devicetree/bindings/power/power_domain.txt4
-rw-r--r--Documentation/devicetree/bindings/power/rockchip-io-domain.txt1
-rw-r--r--Documentation/power/runtime_pm.txt19
-rw-r--r--MAINTAINERS19
-rw-r--r--Makefile2
-rw-r--r--arch/arm/boot/dts/ste-dbx5x0.dtsi5
-rw-r--r--arch/parisc/include/asm/uaccess.h86
-rw-r--r--arch/powerpc/include/asm/exception-64s.h8
-rw-r--r--arch/powerpc/kernel/entry_64.S6
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S2
-rw-r--r--arch/s390/include/asm/pgtable.h2
-rw-r--r--arch/sparc/Kconfig2
-rw-r--r--arch/sparc/mm/hugetlbpage.c16
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-genpool.c2
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-internal.h2
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c17
-rw-r--r--block/blk-mq.c11
-rw-r--r--block/elevator.c12
-rw-r--r--crypto/ahash.c79
-rw-r--r--crypto/algif_aead.c12
-rw-r--r--crypto/lrw.c16
-rw-r--r--crypto/xts.c16
-rw-r--r--drivers/acpi/power.c1
-rw-r--r--drivers/base/power/domain.c68
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c2
-rw-r--r--drivers/clk/clk-stm32f4.c13
-rw-r--r--drivers/clk/sunxi-ng/Kconfig2
-rw-r--r--drivers/clk/sunxi-ng/ccu-sun8i-a33.c11
-rw-r--r--drivers/clk/sunxi-ng/ccu_common.c49
-rw-r--r--drivers/clk/sunxi-ng/ccu_common.h12
-rw-r--r--drivers/cpufreq/Kconfig.arm6
-rw-r--r--drivers/cpufreq/Makefile1
-rw-r--r--drivers/cpufreq/dbx500-cpufreq.c20
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c17
-rw-r--r--drivers/cpufreq/intel_pstate.c910
-rw-r--r--drivers/cpufreq/mt8173-cpufreq.c23
-rw-r--r--drivers/cpufreq/qoriq-cpufreq.c24
-rw-r--r--drivers/cpufreq/tegra186-cpufreq.c275
-rw-r--r--drivers/cpuidle/cpuidle-cps.c3
-rw-r--r--drivers/cpuidle/cpuidle-powernv.c69
-rw-r--r--drivers/devfreq/governor.h29
-rw-r--r--drivers/hid/wacom_wac.c12
-rw-r--r--drivers/input/mouse/elantech.c8
-rw-r--r--drivers/mmc/core/sdio_bus.c12
-rw-r--r--drivers/mmc/host/dw_mmc.c11
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c1
-rw-r--r--drivers/mtd/ubi/upd.c8
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.c1
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.h1
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.c31
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.h12
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_dcbx.c13
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c122
-rw-r--r--drivers/net/ethernet/sfc/efx.c7
-rw-r--r--drivers/net/ethernet/sfc/falcon/efx.c7
-rw-r--r--drivers/net/phy/dp83640.c2
-rw-r--r--drivers/net/phy/micrel.c17
-rw-r--r--drivers/net/usb/ch9200.c9
-rw-r--r--drivers/net/usb/cx82310_eth.c7
-rw-r--r--drivers/net/usb/kaweth.c18
-rw-r--r--drivers/net/usb/lan78xx.c9
-rw-r--r--drivers/net/usb/smsc75xx.c8
-rw-r--r--drivers/net/usb/smsc95xx.c12
-rw-r--r--drivers/net/usb/sr9700.c9
-rw-r--r--drivers/net/vrf.c2
-rw-r--r--drivers/nvme/host/core.c23
-rw-r--r--drivers/nvme/host/nvme.h5
-rw-r--r--drivers/nvme/host/pci.c26
-rw-r--r--drivers/pci/dwc/pcie-hisi.c6
-rw-r--r--drivers/power/avs/rockchip-io-domain.c41
-rw-r--r--drivers/thermal/Kconfig12
-rw-r--r--drivers/thermal/Makefile1
-rw-r--r--drivers/thermal/db8500_cpufreq_cooling.c105
-rw-r--r--drivers/video/backlight/pwm_bl.c7
-rw-r--r--fs/cifs/smb1ops.c10
-rw-r--r--fs/nfsd/nfs4proc.c2
-rw-r--r--fs/nsfs.c1
-rw-r--r--fs/ubifs/debug.c10
-rw-r--r--fs/ubifs/dir.c18
-rw-r--r--include/crypto/internal/hash.h10
-rw-r--r--include/linux/cpufreq.h7
-rw-r--r--include/linux/devfreq.h30
-rw-r--r--include/linux/mmc/sdio_func.h2
-rw-r--r--include/linux/pm_domain.h1
-rw-r--r--include/linux/tick.h1
-rw-r--r--include/uapi/linux/ipv6_route.h2
-rw-r--r--kernel/bpf/syscall.c8
-rw-r--r--kernel/irq/affinity.c2
-rw-r--r--kernel/locking/lockdep_internals.h6
-rw-r--r--kernel/sched/cpufreq_schedutil.c82
-rw-r--r--kernel/time/tick-sched.c12
-rw-r--r--kernel/trace/ftrace.c9
-rw-r--r--kernel/trace/ring_buffer.c16
-rw-r--r--kernel/trace/trace.c9
-rw-r--r--kernel/trace/trace.h2
-rw-r--r--lib/Kconfig.debug6
-rw-r--r--mm/migrate.c2
-rw-r--r--mm/page_alloc.c43
-rw-r--r--mm/vmstat.c3
-rw-r--r--net/core/netpoll.c10
-rw-r--r--net/core/skbuff.c19
-rw-r--r--net/ipv4/ip_sockglue.c10
-rw-r--r--net/ipv4/ipmr.c11
-rw-r--r--net/ipv4/raw.c2
-rw-r--r--net/ipv6/datagram.c10
-rw-r--r--net/ipv6/exthdrs.c1
-rw-r--r--net/ipv6/ip6_input.c7
-rw-r--r--net/ipv6/ip6mr.c13
-rw-r--r--net/ipv6/route.c4
-rw-r--r--net/ipv6/seg6.c3
-rw-r--r--net/key/af_key.c93
-rw-r--r--net/mac80211/rx.c86
-rw-r--r--net/qrtr/qrtr.c4
-rw-r--r--net/sched/act_api.c55
-rw-r--r--security/keys/gc.c2
-rw-r--r--security/keys/keyctl.c20
-rw-r--r--security/keys/process_keys.c44
-rw-r--r--tools/testing/selftests/bpf/test_maps.c4
-rw-r--r--tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc117
-rw-r--r--tools/testing/selftests/net/psock_fanout.c22
-rw-r--r--tools/testing/selftests/net/psock_lib.h13
122 files changed, 2095 insertions, 1198 deletions
diff --git a/Documentation/devicetree/bindings/pci/hisilicon-pcie.txt b/Documentation/devicetree/bindings/pci/hisilicon-pcie.txt
index b7fa3b97986d..a339dbb15493 100644
--- a/Documentation/devicetree/bindings/pci/hisilicon-pcie.txt
+++ b/Documentation/devicetree/bindings/pci/hisilicon-pcie.txt
@@ -44,13 +44,19 @@ Hip05 Example (note that Hip06 is the same except compatible):
44 }; 44 };
45 45
46HiSilicon Hip06/Hip07 PCIe host bridge DT (almost-ECAM) description. 46HiSilicon Hip06/Hip07 PCIe host bridge DT (almost-ECAM) description.
47
48Some BIOSes place the host controller in a mode where it is ECAM
49compliant for all devices other than the root complex. In such cases,
50the host controller should be described as below.
51
47The properties and their meanings are identical to those described in 52The properties and their meanings are identical to those described in
48host-generic-pci.txt except as listed below. 53host-generic-pci.txt except as listed below.
49 54
50Properties of the host controller node that differ from 55Properties of the host controller node that differ from
51host-generic-pci.txt: 56host-generic-pci.txt:
52 57
53- compatible : Must be "hisilicon,pcie-almost-ecam" 58- compatible : Must be "hisilicon,hip06-pcie-ecam", or
59 "hisilicon,hip07-pcie-ecam"
54 60
55- reg : Two entries: First the ECAM configuration space for any 61- reg : Two entries: First the ECAM configuration space for any
56 other bus underneath the root bus. Second, the base 62 other bus underneath the root bus. Second, the base
@@ -59,7 +65,7 @@ host-generic-pci.txt:
59 65
60Example: 66Example:
61 pcie0: pcie@a0090000 { 67 pcie0: pcie@a0090000 {
62 compatible = "hisilicon,pcie-almost-ecam"; 68 compatible = "hisilicon,hip06-pcie-ecam";
63 reg = <0 0xb0000000 0 0x2000000>, /* ECAM configuration space */ 69 reg = <0 0xb0000000 0 0x2000000>, /* ECAM configuration space */
64 <0 0xa0090000 0 0x10000>; /* host bridge registers */ 70 <0 0xa0090000 0 0x10000>; /* host bridge registers */
65 bus-range = <0 31>; 71 bus-range = <0 31>;
diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
index 723e1ad937da..940707d095cc 100644
--- a/Documentation/devicetree/bindings/power/power_domain.txt
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -31,7 +31,9 @@ Optional properties:
31 31
32- domain-idle-states : A phandle of an idle-state that shall be soaked into a 32- domain-idle-states : A phandle of an idle-state that shall be soaked into a
33 generic domain power state. The idle state definitions are 33 generic domain power state. The idle state definitions are
34 compatible with domain-idle-state specified in [1]. 34 compatible with domain-idle-state specified in [1]. phandles
35 that are not compatible with domain-idle-state will be
36 ignored.
35 The domain-idle-state property reflects the idle state of this PM domain and 37 The domain-idle-state property reflects the idle state of this PM domain and
36 not the idle states of the devices or sub-domains in the PM domain. Devices 38 not the idle states of the devices or sub-domains in the PM domain. Devices
37 and sub-domains have their own idle-states independent of the parent 39 and sub-domains have their own idle-states independent of the parent
diff --git a/Documentation/devicetree/bindings/power/rockchip-io-domain.txt b/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
index d23dc002a87e..d3a5a93a65cd 100644
--- a/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
+++ b/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
@@ -33,6 +33,7 @@ Required properties:
33- compatible: should be one of: 33- compatible: should be one of:
34 - "rockchip,rk3188-io-voltage-domain" for rk3188 34 - "rockchip,rk3188-io-voltage-domain" for rk3188
35 - "rockchip,rk3288-io-voltage-domain" for rk3288 35 - "rockchip,rk3288-io-voltage-domain" for rk3288
36 - "rockchip,rk3328-io-voltage-domain" for rk3328
36 - "rockchip,rk3368-io-voltage-domain" for rk3368 37 - "rockchip,rk3368-io-voltage-domain" for rk3368
37 - "rockchip,rk3368-pmu-io-voltage-domain" for rk3368 pmu-domains 38 - "rockchip,rk3368-pmu-io-voltage-domain" for rk3368 pmu-domains
38 - "rockchip,rk3399-io-voltage-domain" for rk3399 39 - "rockchip,rk3399-io-voltage-domain" for rk3399
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt
index 64546eb9a16a..ee69d7532172 100644
--- a/Documentation/power/runtime_pm.txt
+++ b/Documentation/power/runtime_pm.txt
@@ -478,15 +478,23 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
478 - set the power.last_busy field to the current time 478 - set the power.last_busy field to the current time
479 479
480 void pm_runtime_use_autosuspend(struct device *dev); 480 void pm_runtime_use_autosuspend(struct device *dev);
481 - set the power.use_autosuspend flag, enabling autosuspend delays 481 - set the power.use_autosuspend flag, enabling autosuspend delays; call
482 pm_runtime_get_sync if the flag was previously cleared and
483 power.autosuspend_delay is negative
482 484
483 void pm_runtime_dont_use_autosuspend(struct device *dev); 485 void pm_runtime_dont_use_autosuspend(struct device *dev);
484 - clear the power.use_autosuspend flag, disabling autosuspend delays 486 - clear the power.use_autosuspend flag, disabling autosuspend delays;
487 decrement the device's usage counter if the flag was previously set and
488 power.autosuspend_delay is negative; call pm_runtime_idle
485 489
486 void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); 490 void pm_runtime_set_autosuspend_delay(struct device *dev, int delay);
487 - set the power.autosuspend_delay value to 'delay' (expressed in 491 - set the power.autosuspend_delay value to 'delay' (expressed in
488 milliseconds); if 'delay' is negative then runtime suspends are 492 milliseconds); if 'delay' is negative then runtime suspends are
489 prevented 493 prevented; if power.use_autosuspend is set, pm_runtime_get_sync may be
494 called or the device's usage counter may be decremented and
495 pm_runtime_idle called depending on if power.autosuspend_delay is
496 changed to or from a negative value; if power.use_autosuspend is clear,
497 pm_runtime_idle is called
490 498
491 unsigned long pm_runtime_autosuspend_expiration(struct device *dev); 499 unsigned long pm_runtime_autosuspend_expiration(struct device *dev);
492 - calculate the time when the current autosuspend delay period will expire, 500 - calculate the time when the current autosuspend delay period will expire,
@@ -836,9 +844,8 @@ of the non-autosuspend counterparts:
836 Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend. 844 Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend.
837 845
838Drivers may also continue to use the non-autosuspend helper functions; they 846Drivers may also continue to use the non-autosuspend helper functions; they
839will behave normally, not taking the autosuspend delay into account. 847will behave normally, which means sometimes taking the autosuspend delay into
840Similarly, if the power.use_autosuspend field isn't set then the autosuspend 848account (see pm_runtime_idle).
841helper functions will behave just like the non-autosuspend counterparts.
842 849
843Under some circumstances a driver or subsystem may want to prevent a device 850Under some circumstances a driver or subsystem may want to prevent a device
844from autosuspending immediately, even though the usage counter is zero and the 851from autosuspending immediately, even though the usage counter is zero and the
diff --git a/MAINTAINERS b/MAINTAINERS
index 676c139bc883..56a92ec7d3f7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2585,12 +2585,26 @@ F: include/uapi/linux/if_bonding.h
2585 2585
2586BPF (Safe dynamic programs and tools) 2586BPF (Safe dynamic programs and tools)
2587M: Alexei Starovoitov <ast@kernel.org> 2587M: Alexei Starovoitov <ast@kernel.org>
2588M: Daniel Borkmann <daniel@iogearbox.net>
2588L: netdev@vger.kernel.org 2589L: netdev@vger.kernel.org
2589L: linux-kernel@vger.kernel.org 2590L: linux-kernel@vger.kernel.org
2590S: Supported 2591S: Supported
2592F: arch/x86/net/bpf_jit*
2593F: Documentation/networking/filter.txt
2594F: include/linux/bpf*
2595F: include/linux/filter.h
2596F: include/uapi/linux/bpf*
2597F: include/uapi/linux/filter.h
2591F: kernel/bpf/ 2598F: kernel/bpf/
2592F: tools/testing/selftests/bpf/ 2599F: kernel/trace/bpf_trace.c
2593F: lib/test_bpf.c 2600F: lib/test_bpf.c
2601F: net/bpf/
2602F: net/core/filter.c
2603F: net/sched/act_bpf.c
2604F: net/sched/cls_bpf.c
2605F: samples/bpf/
2606F: tools/net/bpf*
2607F: tools/testing/selftests/bpf/
2594 2608
2595BROADCOM B44 10/100 ETHERNET DRIVER 2609BROADCOM B44 10/100 ETHERNET DRIVER
2596M: Michael Chan <michael.chan@broadcom.com> 2610M: Michael Chan <michael.chan@broadcom.com>
@@ -3449,6 +3463,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
3449T: git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates) 3463T: git git://git.linaro.org/people/vireshk/linux.git (For ARM Updates)
3450B: https://bugzilla.kernel.org 3464B: https://bugzilla.kernel.org
3451F: Documentation/cpu-freq/ 3465F: Documentation/cpu-freq/
3466F: Documentation/devicetree/bindings/cpufreq/
3452F: drivers/cpufreq/ 3467F: drivers/cpufreq/
3453F: include/linux/cpufreq.h 3468F: include/linux/cpufreq.h
3454F: tools/testing/selftests/cpufreq/ 3469F: tools/testing/selftests/cpufreq/
@@ -8761,6 +8776,7 @@ W: http://www.linuxfoundation.org/en/Net
8761Q: http://patchwork.ozlabs.org/project/netdev/list/ 8776Q: http://patchwork.ozlabs.org/project/netdev/list/
8762T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 8777T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
8763T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 8778T: git git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
8779B: mailto:netdev@vger.kernel.org
8764S: Maintained 8780S: Maintained
8765F: net/ 8781F: net/
8766F: include/net/ 8782F: include/net/
@@ -12464,7 +12480,6 @@ F: drivers/clk/ti/
12464F: include/linux/clk/ti.h 12480F: include/linux/clk/ti.h
12465 12481
12466TI ETHERNET SWITCH DRIVER (CPSW) 12482TI ETHERNET SWITCH DRIVER (CPSW)
12467M: Mugunthan V N <mugunthanvnm@ti.com>
12468R: Grygorii Strashko <grygorii.strashko@ti.com> 12483R: Grygorii Strashko <grygorii.strashko@ti.com>
12469L: linux-omap@vger.kernel.org 12484L: linux-omap@vger.kernel.org
12470L: netdev@vger.kernel.org 12485L: netdev@vger.kernel.org
diff --git a/Makefile b/Makefile
index 5039b9148d15..779302695453 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 4 1VERSION = 4
2PATCHLEVEL = 11 2PATCHLEVEL = 11
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc7 4EXTRAVERSION = -rc8
5NAME = Fearless Coyote 5NAME = Fearless Coyote
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/boot/dts/ste-dbx5x0.dtsi b/arch/arm/boot/dts/ste-dbx5x0.dtsi
index 162e1eb5373d..6c5affe2d0f5 100644
--- a/arch/arm/boot/dts/ste-dbx5x0.dtsi
+++ b/arch/arm/boot/dts/ste-dbx5x0.dtsi
@@ -1189,11 +1189,6 @@
1189 status = "disabled"; 1189 status = "disabled";
1190 }; 1190 };
1191 1191
1192 cpufreq-cooling {
1193 compatible = "stericsson,db8500-cpufreq-cooling";
1194 status = "disabled";
1195 };
1196
1197 mcde@a0350000 { 1192 mcde@a0350000 {
1198 compatible = "stericsson,mcde"; 1193 compatible = "stericsson,mcde";
1199 reg = <0xa0350000 0x1000>, /* MCDE */ 1194 reg = <0xa0350000 0x1000>, /* MCDE */
diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
index 8442727f28d2..cbd4f4af8108 100644
--- a/arch/parisc/include/asm/uaccess.h
+++ b/arch/parisc/include/asm/uaccess.h
@@ -39,10 +39,10 @@
39#define get_user __get_user 39#define get_user __get_user
40 40
41#if !defined(CONFIG_64BIT) 41#if !defined(CONFIG_64BIT)
42#define LDD_USER(ptr) __get_user_asm64(ptr) 42#define LDD_USER(val, ptr) __get_user_asm64(val, ptr)
43#define STD_USER(x, ptr) __put_user_asm64(x, ptr) 43#define STD_USER(x, ptr) __put_user_asm64(x, ptr)
44#else 44#else
45#define LDD_USER(ptr) __get_user_asm("ldd", ptr) 45#define LDD_USER(val, ptr) __get_user_asm(val, "ldd", ptr)
46#define STD_USER(x, ptr) __put_user_asm("std", x, ptr) 46#define STD_USER(x, ptr) __put_user_asm("std", x, ptr)
47#endif 47#endif
48 48
@@ -97,63 +97,87 @@ struct exception_data {
97 " mtsp %0,%%sr2\n\t" \ 97 " mtsp %0,%%sr2\n\t" \
98 : : "r"(get_fs()) : ) 98 : : "r"(get_fs()) : )
99 99
100#define __get_user(x, ptr) \ 100#define __get_user_internal(val, ptr) \
101({ \ 101({ \
102 register long __gu_err __asm__ ("r8") = 0; \ 102 register long __gu_err __asm__ ("r8") = 0; \
103 register long __gu_val; \ 103 \
104 \ 104 switch (sizeof(*(ptr))) { \
105 load_sr2(); \ 105 case 1: __get_user_asm(val, "ldb", ptr); break; \
106 switch (sizeof(*(ptr))) { \ 106 case 2: __get_user_asm(val, "ldh", ptr); break; \
107 case 1: __get_user_asm("ldb", ptr); break; \ 107 case 4: __get_user_asm(val, "ldw", ptr); break; \
108 case 2: __get_user_asm("ldh", ptr); break; \ 108 case 8: LDD_USER(val, ptr); break; \
109 case 4: __get_user_asm("ldw", ptr); break; \ 109 default: BUILD_BUG(); \
110 case 8: LDD_USER(ptr); break; \ 110 } \
111 default: BUILD_BUG(); break; \ 111 \
112 } \ 112 __gu_err; \
113 \
114 (x) = (__force __typeof__(*(ptr))) __gu_val; \
115 __gu_err; \
116}) 113})
117 114
118#define __get_user_asm(ldx, ptr) \ 115#define __get_user(val, ptr) \
116({ \
117 load_sr2(); \
118 __get_user_internal(val, ptr); \
119})
120
121#define __get_user_asm(val, ldx, ptr) \
122{ \
123 register long __gu_val; \
124 \
119 __asm__("1: " ldx " 0(%%sr2,%2),%0\n" \ 125 __asm__("1: " ldx " 0(%%sr2,%2),%0\n" \
120 "9:\n" \ 126 "9:\n" \
121 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 127 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
122 : "=r"(__gu_val), "=r"(__gu_err) \ 128 : "=r"(__gu_val), "=r"(__gu_err) \
123 : "r"(ptr), "1"(__gu_err)); 129 : "r"(ptr), "1"(__gu_err)); \
130 \
131 (val) = (__force __typeof__(*(ptr))) __gu_val; \
132}
124 133
125#if !defined(CONFIG_64BIT) 134#if !defined(CONFIG_64BIT)
126 135
127#define __get_user_asm64(ptr) \ 136#define __get_user_asm64(val, ptr) \
137{ \
138 union { \
139 unsigned long long l; \
140 __typeof__(*(ptr)) t; \
141 } __gu_tmp; \
142 \
128 __asm__(" copy %%r0,%R0\n" \ 143 __asm__(" copy %%r0,%R0\n" \
129 "1: ldw 0(%%sr2,%2),%0\n" \ 144 "1: ldw 0(%%sr2,%2),%0\n" \
130 "2: ldw 4(%%sr2,%2),%R0\n" \ 145 "2: ldw 4(%%sr2,%2),%R0\n" \
131 "9:\n" \ 146 "9:\n" \
132 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ 147 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
133 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ 148 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
134 : "=r"(__gu_val), "=r"(__gu_err) \ 149 : "=&r"(__gu_tmp.l), "=r"(__gu_err) \
135 : "r"(ptr), "1"(__gu_err)); 150 : "r"(ptr), "1"(__gu_err)); \
151 \
152 (val) = __gu_tmp.t; \
153}
136 154
137#endif /* !defined(CONFIG_64BIT) */ 155#endif /* !defined(CONFIG_64BIT) */
138 156
139 157
140#define __put_user(x, ptr) \ 158#define __put_user_internal(x, ptr) \
141({ \ 159({ \
142 register long __pu_err __asm__ ("r8") = 0; \ 160 register long __pu_err __asm__ ("r8") = 0; \
143 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \ 161 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
144 \ 162 \
145 load_sr2(); \
146 switch (sizeof(*(ptr))) { \ 163 switch (sizeof(*(ptr))) { \
147 case 1: __put_user_asm("stb", __x, ptr); break; \ 164 case 1: __put_user_asm("stb", __x, ptr); break; \
148 case 2: __put_user_asm("sth", __x, ptr); break; \ 165 case 2: __put_user_asm("sth", __x, ptr); break; \
149 case 4: __put_user_asm("stw", __x, ptr); break; \ 166 case 4: __put_user_asm("stw", __x, ptr); break; \
150 case 8: STD_USER(__x, ptr); break; \ 167 case 8: STD_USER(__x, ptr); break; \
151 default: BUILD_BUG(); break; \ 168 default: BUILD_BUG(); \
152 } \ 169 } \
153 \ 170 \
154 __pu_err; \ 171 __pu_err; \
155}) 172})
156 173
174#define __put_user(x, ptr) \
175({ \
176 load_sr2(); \
177 __put_user_internal(x, ptr); \
178})
179
180
157/* 181/*
158 * The "__put_user/kernel_asm()" macros tell gcc they read from memory 182 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
159 * instead of writing. This is because they do not write to any memory 183 * instead of writing. This is because they do not write to any memory
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 14752eee3d0c..ed3beadd2cc5 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -236,9 +236,9 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
236 mtctr reg; \ 236 mtctr reg; \
237 bctr 237 bctr
238 238
239#define BRANCH_LINK_TO_FAR(reg, label) \ 239#define BRANCH_LINK_TO_FAR(label) \
240 __LOAD_FAR_HANDLER(reg, label); \ 240 __LOAD_FAR_HANDLER(r12, label); \
241 mtctr reg; \ 241 mtctr r12; \
242 bctrl 242 bctrl
243 243
244/* 244/*
@@ -265,7 +265,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
265#define BRANCH_TO_COMMON(reg, label) \ 265#define BRANCH_TO_COMMON(reg, label) \
266 b label 266 b label
267 267
268#define BRANCH_LINK_TO_FAR(reg, label) \ 268#define BRANCH_LINK_TO_FAR(label) \
269 bl label 269 bl label
270 270
271#define BRANCH_TO_KVM(reg, label) \ 271#define BRANCH_TO_KVM(reg, label) \
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 6432d4bf08c8..767ef6d68c9e 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -689,7 +689,7 @@ resume_kernel:
689 689
690 addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */ 690 addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
691 691
692 lwz r3,GPR1(r1) 692 ld r3,GPR1(r1)
693 subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */ 693 subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
694 mr r4,r1 /* src: current exception frame */ 694 mr r4,r1 /* src: current exception frame */
695 mr r1,r3 /* Reroute the trampoline frame to r1 */ 695 mr r1,r3 /* Reroute the trampoline frame to r1 */
@@ -703,8 +703,8 @@ resume_kernel:
703 addi r6,r6,8 703 addi r6,r6,8
704 bdnz 2b 704 bdnz 2b
705 705
706 /* Do real store operation to complete stwu */ 706 /* Do real store operation to complete stdu */
707 lwz r5,GPR1(r1) 707 ld r5,GPR1(r1)
708 std r8,0(r5) 708 std r8,0(r5)
709 709
710 /* Clear _TIF_EMULATE_STACK_STORE flag */ 710 /* Clear _TIF_EMULATE_STACK_STORE flag */
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 857bf7c5b946..6353019966e6 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -982,7 +982,7 @@ TRAMP_REAL_BEGIN(hmi_exception_early)
982 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN) 982 EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
983 EXCEPTION_PROLOG_COMMON_3(0xe60) 983 EXCEPTION_PROLOG_COMMON_3(0xe60)
984 addi r3,r1,STACK_FRAME_OVERHEAD 984 addi r3,r1,STACK_FRAME_OVERHEAD
985 BRANCH_LINK_TO_FAR(r4, hmi_exception_realmode) 985 BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */
986 /* Windup the stack. */ 986 /* Windup the stack. */
987 /* Move original HSRR0 and HSRR1 into the respective regs */ 987 /* Move original HSRR0 and HSRR1 into the respective regs */
988 ld r9,_MSR(r1) 988 ld r9,_MSR(r1)
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 93e37b12e882..ecec682bb516 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1051,6 +1051,8 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1051{ 1051{
1052 if (!MACHINE_HAS_NX) 1052 if (!MACHINE_HAS_NX)
1053 pte_val(entry) &= ~_PAGE_NOEXEC; 1053 pte_val(entry) &= ~_PAGE_NOEXEC;
1054 if (pte_present(entry))
1055 pte_val(entry) &= ~_PAGE_UNUSED;
1054 if (mm_has_pgste(mm)) 1056 if (mm_has_pgste(mm))
1055 ptep_set_pte_at(mm, addr, ptep, entry); 1057 ptep_set_pte_at(mm, addr, ptep, entry);
1056 else 1058 else
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 68ac5c7cd982..a59deaef21e5 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -43,7 +43,7 @@ config SPARC
43 select ARCH_HAS_SG_CHAIN 43 select ARCH_HAS_SG_CHAIN
44 select CPU_NO_EFFICIENT_FFS 44 select CPU_NO_EFFICIENT_FFS
45 select HAVE_ARCH_HARDENED_USERCOPY 45 select HAVE_ARCH_HARDENED_USERCOPY
46 select PROVE_LOCKING_SMALL if PROVE_LOCKING 46 select LOCKDEP_SMALL if LOCKDEP
47 select ARCH_WANT_RELAX_ORDER 47 select ARCH_WANT_RELAX_ORDER
48 48
49config SPARC32 49config SPARC32
diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
index ee5273ad918d..7c29d38e6b99 100644
--- a/arch/sparc/mm/hugetlbpage.c
+++ b/arch/sparc/mm/hugetlbpage.c
@@ -461,6 +461,22 @@ void hugetlb_free_pgd_range(struct mmu_gather *tlb,
461 pgd_t *pgd; 461 pgd_t *pgd;
462 unsigned long next; 462 unsigned long next;
463 463
464 addr &= PMD_MASK;
465 if (addr < floor) {
466 addr += PMD_SIZE;
467 if (!addr)
468 return;
469 }
470 if (ceiling) {
471 ceiling &= PMD_MASK;
472 if (!ceiling)
473 return;
474 }
475 if (end - 1 > ceiling - 1)
476 end -= PMD_SIZE;
477 if (addr > end - 1)
478 return;
479
464 pgd = pgd_offset(tlb->mm, addr); 480 pgd = pgd_offset(tlb->mm, addr);
465 do { 481 do {
466 next = pgd_addr_end(addr, end); 482 next = pgd_addr_end(addr, end);
diff --git a/arch/x86/kernel/cpu/mcheck/mce-genpool.c b/arch/x86/kernel/cpu/mcheck/mce-genpool.c
index 1e5a50c11d3c..217cd4449bc9 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-genpool.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-genpool.c
@@ -85,7 +85,7 @@ void mce_gen_pool_process(struct work_struct *__unused)
85 head = llist_reverse_order(head); 85 head = llist_reverse_order(head);
86 llist_for_each_entry_safe(node, tmp, head, llnode) { 86 llist_for_each_entry_safe(node, tmp, head, llnode) {
87 mce = &node->mce; 87 mce = &node->mce;
88 atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce); 88 blocking_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
89 gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node)); 89 gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));
90 } 90 }
91} 91}
diff --git a/arch/x86/kernel/cpu/mcheck/mce-internal.h b/arch/x86/kernel/cpu/mcheck/mce-internal.h
index 903043e6a62b..19592ba1a320 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-internal.h
+++ b/arch/x86/kernel/cpu/mcheck/mce-internal.h
@@ -13,7 +13,7 @@ enum severity_level {
13 MCE_PANIC_SEVERITY, 13 MCE_PANIC_SEVERITY,
14}; 14};
15 15
16extern struct atomic_notifier_head x86_mce_decoder_chain; 16extern struct blocking_notifier_head x86_mce_decoder_chain;
17 17
18#define ATTR_LEN 16 18#define ATTR_LEN 16
19#define INITIAL_CHECK_INTERVAL 5 * 60 /* 5 minutes */ 19#define INITIAL_CHECK_INTERVAL 5 * 60 /* 5 minutes */
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 5accfbdee3f0..af44ebeb593f 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -123,7 +123,7 @@ static void (*quirk_no_way_out)(int bank, struct mce *m, struct pt_regs *regs);
123 * CPU/chipset specific EDAC code can register a notifier call here to print 123 * CPU/chipset specific EDAC code can register a notifier call here to print
124 * MCE errors in a human-readable form. 124 * MCE errors in a human-readable form.
125 */ 125 */
126ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain); 126BLOCKING_NOTIFIER_HEAD(x86_mce_decoder_chain);
127 127
128/* Do initial initialization of a struct mce */ 128/* Do initial initialization of a struct mce */
129void mce_setup(struct mce *m) 129void mce_setup(struct mce *m)
@@ -220,7 +220,7 @@ void mce_register_decode_chain(struct notifier_block *nb)
220 220
221 WARN_ON(nb->priority > MCE_PRIO_LOWEST && nb->priority < MCE_PRIO_EDAC); 221 WARN_ON(nb->priority > MCE_PRIO_LOWEST && nb->priority < MCE_PRIO_EDAC);
222 222
223 atomic_notifier_chain_register(&x86_mce_decoder_chain, nb); 223 blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
224} 224}
225EXPORT_SYMBOL_GPL(mce_register_decode_chain); 225EXPORT_SYMBOL_GPL(mce_register_decode_chain);
226 226
@@ -228,7 +228,7 @@ void mce_unregister_decode_chain(struct notifier_block *nb)
228{ 228{
229 atomic_dec(&num_notifiers); 229 atomic_dec(&num_notifiers);
230 230
231 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, nb); 231 blocking_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
232} 232}
233EXPORT_SYMBOL_GPL(mce_unregister_decode_chain); 233EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
234 234
@@ -321,18 +321,7 @@ static void __print_mce(struct mce *m)
321 321
322static void print_mce(struct mce *m) 322static void print_mce(struct mce *m)
323{ 323{
324 int ret = 0;
325
326 __print_mce(m); 324 __print_mce(m);
327
328 /*
329 * Print out human-readable details about the MCE error,
330 * (if the CPU has an implementation for that)
331 */
332 ret = atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m);
333 if (ret == NOTIFY_STOP)
334 return;
335
336 pr_emerg_ratelimited(HW_ERR "Run the above through 'mcelog --ascii'\n"); 325 pr_emerg_ratelimited(HW_ERR "Run the above through 'mcelog --ascii'\n");
337} 326}
338 327
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 572966f49596..c7836a1ded97 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2928,8 +2928,17 @@ bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
2928 hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)]; 2928 hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
2929 if (!blk_qc_t_is_internal(cookie)) 2929 if (!blk_qc_t_is_internal(cookie))
2930 rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie)); 2930 rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
2931 else 2931 else {
2932 rq = blk_mq_tag_to_rq(hctx->sched_tags, blk_qc_t_to_tag(cookie)); 2932 rq = blk_mq_tag_to_rq(hctx->sched_tags, blk_qc_t_to_tag(cookie));
2933 /*
2934 * With scheduling, if the request has completed, we'll
2935 * get a NULL return here, as we clear the sched tag when
2936 * that happens. The request still remains valid, like always,
2937 * so we should be safe with just the NULL check.
2938 */
2939 if (!rq)
2940 return false;
2941 }
2933 2942
2934 return __blk_mq_poll(hctx, rq); 2943 return __blk_mq_poll(hctx, rq);
2935} 2944}
diff --git a/block/elevator.c b/block/elevator.c
index dbeecf7be719..4d9084a14c10 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -1098,12 +1098,20 @@ int elevator_change(struct request_queue *q, const char *name)
1098} 1098}
1099EXPORT_SYMBOL(elevator_change); 1099EXPORT_SYMBOL(elevator_change);
1100 1100
1101static inline bool elv_support_iosched(struct request_queue *q)
1102{
1103 if (q->mq_ops && q->tag_set && (q->tag_set->flags &
1104 BLK_MQ_F_NO_SCHED))
1105 return false;
1106 return true;
1107}
1108
1101ssize_t elv_iosched_store(struct request_queue *q, const char *name, 1109ssize_t elv_iosched_store(struct request_queue *q, const char *name,
1102 size_t count) 1110 size_t count)
1103{ 1111{
1104 int ret; 1112 int ret;
1105 1113
1106 if (!(q->mq_ops || q->request_fn)) 1114 if (!(q->mq_ops || q->request_fn) || !elv_support_iosched(q))
1107 return count; 1115 return count;
1108 1116
1109 ret = __elevator_change(q, name); 1117 ret = __elevator_change(q, name);
@@ -1135,7 +1143,7 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name)
1135 len += sprintf(name+len, "[%s] ", elv->elevator_name); 1143 len += sprintf(name+len, "[%s] ", elv->elevator_name);
1136 continue; 1144 continue;
1137 } 1145 }
1138 if (__e->uses_mq && q->mq_ops) 1146 if (__e->uses_mq && q->mq_ops && elv_support_iosched(q))
1139 len += sprintf(name+len, "%s ", __e->elevator_name); 1147 len += sprintf(name+len, "%s ", __e->elevator_name);
1140 else if (!__e->uses_mq && !q->mq_ops) 1148 else if (!__e->uses_mq && !q->mq_ops)
1141 len += sprintf(name+len, "%s ", __e->elevator_name); 1149 len += sprintf(name+len, "%s ", __e->elevator_name);
diff --git a/crypto/ahash.c b/crypto/ahash.c
index e58c4970c22b..826cd7ab4d4a 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -32,6 +32,7 @@ struct ahash_request_priv {
32 crypto_completion_t complete; 32 crypto_completion_t complete;
33 void *data; 33 void *data;
34 u8 *result; 34 u8 *result;
35 u32 flags;
35 void *ubuf[] CRYPTO_MINALIGN_ATTR; 36 void *ubuf[] CRYPTO_MINALIGN_ATTR;
36}; 37};
37 38
@@ -253,6 +254,8 @@ static int ahash_save_req(struct ahash_request *req, crypto_completion_t cplt)
253 priv->result = req->result; 254 priv->result = req->result;
254 priv->complete = req->base.complete; 255 priv->complete = req->base.complete;
255 priv->data = req->base.data; 256 priv->data = req->base.data;
257 priv->flags = req->base.flags;
258
256 /* 259 /*
257 * WARNING: We do not backup req->priv here! The req->priv 260 * WARNING: We do not backup req->priv here! The req->priv
258 * is for internal use of the Crypto API and the 261 * is for internal use of the Crypto API and the
@@ -267,38 +270,44 @@ static int ahash_save_req(struct ahash_request *req, crypto_completion_t cplt)
267 return 0; 270 return 0;
268} 271}
269 272
270static void ahash_restore_req(struct ahash_request *req) 273static void ahash_restore_req(struct ahash_request *req, int err)
271{ 274{
272 struct ahash_request_priv *priv = req->priv; 275 struct ahash_request_priv *priv = req->priv;
273 276
277 if (!err)
278 memcpy(priv->result, req->result,
279 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
280
274 /* Restore the original crypto request. */ 281 /* Restore the original crypto request. */
275 req->result = priv->result; 282 req->result = priv->result;
276 req->base.complete = priv->complete; 283
277 req->base.data = priv->data; 284 ahash_request_set_callback(req, priv->flags,
285 priv->complete, priv->data);
278 req->priv = NULL; 286 req->priv = NULL;
279 287
280 /* Free the req->priv.priv from the ADJUSTED request. */ 288 /* Free the req->priv.priv from the ADJUSTED request. */
281 kzfree(priv); 289 kzfree(priv);
282} 290}
283 291
284static void ahash_op_unaligned_finish(struct ahash_request *req, int err) 292static void ahash_notify_einprogress(struct ahash_request *req)
285{ 293{
286 struct ahash_request_priv *priv = req->priv; 294 struct ahash_request_priv *priv = req->priv;
295 struct crypto_async_request oreq;
287 296
288 if (err == -EINPROGRESS) 297 oreq.data = priv->data;
289 return;
290
291 if (!err)
292 memcpy(priv->result, req->result,
293 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
294 298
295 ahash_restore_req(req); 299 priv->complete(&oreq, -EINPROGRESS);
296} 300}
297 301
298static void ahash_op_unaligned_done(struct crypto_async_request *req, int err) 302static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
299{ 303{
300 struct ahash_request *areq = req->data; 304 struct ahash_request *areq = req->data;
301 305
306 if (err == -EINPROGRESS) {
307 ahash_notify_einprogress(areq);
308 return;
309 }
310
302 /* 311 /*
303 * Restore the original request, see ahash_op_unaligned() for what 312 * Restore the original request, see ahash_op_unaligned() for what
304 * goes where. 313 * goes where.
@@ -309,7 +318,7 @@ static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
309 */ 318 */
310 319
311 /* First copy req->result into req->priv.result */ 320 /* First copy req->result into req->priv.result */
312 ahash_op_unaligned_finish(areq, err); 321 ahash_restore_req(areq, err);
313 322
314 /* Complete the ORIGINAL request. */ 323 /* Complete the ORIGINAL request. */
315 areq->base.complete(&areq->base, err); 324 areq->base.complete(&areq->base, err);
@@ -325,7 +334,12 @@ static int ahash_op_unaligned(struct ahash_request *req,
325 return err; 334 return err;
326 335
327 err = op(req); 336 err = op(req);
328 ahash_op_unaligned_finish(req, err); 337 if (err == -EINPROGRESS ||
338 (err == -EBUSY && (ahash_request_flags(req) &
339 CRYPTO_TFM_REQ_MAY_BACKLOG)))
340 return err;
341
342 ahash_restore_req(req, err);
329 343
330 return err; 344 return err;
331} 345}
@@ -360,25 +374,14 @@ int crypto_ahash_digest(struct ahash_request *req)
360} 374}
361EXPORT_SYMBOL_GPL(crypto_ahash_digest); 375EXPORT_SYMBOL_GPL(crypto_ahash_digest);
362 376
363static void ahash_def_finup_finish2(struct ahash_request *req, int err) 377static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
364{ 378{
365 struct ahash_request_priv *priv = req->priv; 379 struct ahash_request *areq = req->data;
366 380
367 if (err == -EINPROGRESS) 381 if (err == -EINPROGRESS)
368 return; 382 return;
369 383
370 if (!err) 384 ahash_restore_req(areq, err);
371 memcpy(priv->result, req->result,
372 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
373
374 ahash_restore_req(req);
375}
376
377static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
378{
379 struct ahash_request *areq = req->data;
380
381 ahash_def_finup_finish2(areq, err);
382 385
383 areq->base.complete(&areq->base, err); 386 areq->base.complete(&areq->base, err);
384} 387}
@@ -389,11 +392,15 @@ static int ahash_def_finup_finish1(struct ahash_request *req, int err)
389 goto out; 392 goto out;
390 393
391 req->base.complete = ahash_def_finup_done2; 394 req->base.complete = ahash_def_finup_done2;
392 req->base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP; 395
393 err = crypto_ahash_reqtfm(req)->final(req); 396 err = crypto_ahash_reqtfm(req)->final(req);
397 if (err == -EINPROGRESS ||
398 (err == -EBUSY && (ahash_request_flags(req) &
399 CRYPTO_TFM_REQ_MAY_BACKLOG)))
400 return err;
394 401
395out: 402out:
396 ahash_def_finup_finish2(req, err); 403 ahash_restore_req(req, err);
397 return err; 404 return err;
398} 405}
399 406
@@ -401,7 +408,16 @@ static void ahash_def_finup_done1(struct crypto_async_request *req, int err)
401{ 408{
402 struct ahash_request *areq = req->data; 409 struct ahash_request *areq = req->data;
403 410
411 if (err == -EINPROGRESS) {
412 ahash_notify_einprogress(areq);
413 return;
414 }
415
416 areq->base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
417
404 err = ahash_def_finup_finish1(areq, err); 418 err = ahash_def_finup_finish1(areq, err);
419 if (areq->priv)
420 return;
405 421
406 areq->base.complete(&areq->base, err); 422 areq->base.complete(&areq->base, err);
407} 423}
@@ -416,6 +432,11 @@ static int ahash_def_finup(struct ahash_request *req)
416 return err; 432 return err;
417 433
418 err = tfm->update(req); 434 err = tfm->update(req);
435 if (err == -EINPROGRESS ||
436 (err == -EBUSY && (ahash_request_flags(req) &
437 CRYPTO_TFM_REQ_MAY_BACKLOG)))
438 return err;
439
419 return ahash_def_finup_finish1(req, err); 440 return ahash_def_finup_finish1(req, err);
420} 441}
421 442
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c
index 5a8053758657..ef59d9926ee9 100644
--- a/crypto/algif_aead.c
+++ b/crypto/algif_aead.c
@@ -40,6 +40,7 @@ struct aead_async_req {
40 struct aead_async_rsgl first_rsgl; 40 struct aead_async_rsgl first_rsgl;
41 struct list_head list; 41 struct list_head list;
42 struct kiocb *iocb; 42 struct kiocb *iocb;
43 struct sock *sk;
43 unsigned int tsgls; 44 unsigned int tsgls;
44 char iv[]; 45 char iv[];
45}; 46};
@@ -379,12 +380,10 @@ unlock:
379 380
380static void aead_async_cb(struct crypto_async_request *_req, int err) 381static void aead_async_cb(struct crypto_async_request *_req, int err)
381{ 382{
382 struct sock *sk = _req->data; 383 struct aead_request *req = _req->data;
383 struct alg_sock *ask = alg_sk(sk); 384 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
384 struct aead_ctx *ctx = ask->private;
385 struct crypto_aead *tfm = crypto_aead_reqtfm(&ctx->aead_req);
386 struct aead_request *req = aead_request_cast(_req);
387 struct aead_async_req *areq = GET_ASYM_REQ(req, tfm); 385 struct aead_async_req *areq = GET_ASYM_REQ(req, tfm);
386 struct sock *sk = areq->sk;
388 struct scatterlist *sg = areq->tsgl; 387 struct scatterlist *sg = areq->tsgl;
389 struct aead_async_rsgl *rsgl; 388 struct aead_async_rsgl *rsgl;
390 struct kiocb *iocb = areq->iocb; 389 struct kiocb *iocb = areq->iocb;
@@ -447,11 +446,12 @@ static int aead_recvmsg_async(struct socket *sock, struct msghdr *msg,
447 memset(&areq->first_rsgl, '\0', sizeof(areq->first_rsgl)); 446 memset(&areq->first_rsgl, '\0', sizeof(areq->first_rsgl));
448 INIT_LIST_HEAD(&areq->list); 447 INIT_LIST_HEAD(&areq->list);
449 areq->iocb = msg->msg_iocb; 448 areq->iocb = msg->msg_iocb;
449 areq->sk = sk;
450 memcpy(areq->iv, ctx->iv, crypto_aead_ivsize(tfm)); 450 memcpy(areq->iv, ctx->iv, crypto_aead_ivsize(tfm));
451 aead_request_set_tfm(req, tfm); 451 aead_request_set_tfm(req, tfm);
452 aead_request_set_ad(req, ctx->aead_assoclen); 452 aead_request_set_ad(req, ctx->aead_assoclen);
453 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 453 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
454 aead_async_cb, sk); 454 aead_async_cb, req);
455 used -= ctx->aead_assoclen; 455 used -= ctx->aead_assoclen;
456 456
457 /* take over all tx sgls from ctx */ 457 /* take over all tx sgls from ctx */
diff --git a/crypto/lrw.c b/crypto/lrw.c
index 3ea095adafd9..a8bfae4451bf 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -345,6 +345,13 @@ static void encrypt_done(struct crypto_async_request *areq, int err)
345 struct rctx *rctx; 345 struct rctx *rctx;
346 346
347 rctx = skcipher_request_ctx(req); 347 rctx = skcipher_request_ctx(req);
348
349 if (err == -EINPROGRESS) {
350 if (rctx->left != req->cryptlen)
351 return;
352 goto out;
353 }
354
348 subreq = &rctx->subreq; 355 subreq = &rctx->subreq;
349 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG; 356 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
350 357
@@ -352,6 +359,7 @@ static void encrypt_done(struct crypto_async_request *areq, int err)
352 if (rctx->left) 359 if (rctx->left)
353 return; 360 return;
354 361
362out:
355 skcipher_request_complete(req, err); 363 skcipher_request_complete(req, err);
356} 364}
357 365
@@ -389,6 +397,13 @@ static void decrypt_done(struct crypto_async_request *areq, int err)
389 struct rctx *rctx; 397 struct rctx *rctx;
390 398
391 rctx = skcipher_request_ctx(req); 399 rctx = skcipher_request_ctx(req);
400
401 if (err == -EINPROGRESS) {
402 if (rctx->left != req->cryptlen)
403 return;
404 goto out;
405 }
406
392 subreq = &rctx->subreq; 407 subreq = &rctx->subreq;
393 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG; 408 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
394 409
@@ -396,6 +411,7 @@ static void decrypt_done(struct crypto_async_request *areq, int err)
396 if (rctx->left) 411 if (rctx->left)
397 return; 412 return;
398 413
414out:
399 skcipher_request_complete(req, err); 415 skcipher_request_complete(req, err);
400} 416}
401 417
diff --git a/crypto/xts.c b/crypto/xts.c
index c976bfac29da..89ace5ebc2da 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -286,6 +286,13 @@ static void encrypt_done(struct crypto_async_request *areq, int err)
286 struct rctx *rctx; 286 struct rctx *rctx;
287 287
288 rctx = skcipher_request_ctx(req); 288 rctx = skcipher_request_ctx(req);
289
290 if (err == -EINPROGRESS) {
291 if (rctx->left != req->cryptlen)
292 return;
293 goto out;
294 }
295
289 subreq = &rctx->subreq; 296 subreq = &rctx->subreq;
290 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG; 297 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
291 298
@@ -293,6 +300,7 @@ static void encrypt_done(struct crypto_async_request *areq, int err)
293 if (rctx->left) 300 if (rctx->left)
294 return; 301 return;
295 302
303out:
296 skcipher_request_complete(req, err); 304 skcipher_request_complete(req, err);
297} 305}
298 306
@@ -330,6 +338,13 @@ static void decrypt_done(struct crypto_async_request *areq, int err)
330 struct rctx *rctx; 338 struct rctx *rctx;
331 339
332 rctx = skcipher_request_ctx(req); 340 rctx = skcipher_request_ctx(req);
341
342 if (err == -EINPROGRESS) {
343 if (rctx->left != req->cryptlen)
344 return;
345 goto out;
346 }
347
333 subreq = &rctx->subreq; 348 subreq = &rctx->subreq;
334 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG; 349 subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
335 350
@@ -337,6 +352,7 @@ static void decrypt_done(struct crypto_async_request *areq, int err)
337 if (rctx->left) 352 if (rctx->left)
338 return; 353 return;
339 354
355out:
340 skcipher_request_complete(req, err); 356 skcipher_request_complete(req, err);
341} 357}
342 358
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index fcd4ce6f78d5..1c2b846c5776 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -200,6 +200,7 @@ static int acpi_power_get_list_state(struct list_head *list, int *state)
200 return -EINVAL; 200 return -EINVAL;
201 201
202 /* The state of the list is 'on' IFF all resources are 'on'. */ 202 /* The state of the list is 'on' IFF all resources are 'on'. */
203 cur_state = 0;
203 list_for_each_entry(entry, list, node) { 204 list_for_each_entry(entry, list, node) {
204 struct acpi_power_resource *resource = entry->resource; 205 struct acpi_power_resource *resource = entry->resource;
205 acpi_handle handle = resource->device.handle; 206 acpi_handle handle = resource->device.handle;
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index e697dec9d25b..ad196427b4f2 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -121,7 +121,9 @@ static const struct genpd_lock_ops genpd_spin_ops = {
121#define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p) 121#define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p)
122#define genpd_unlock(p) p->lock_ops->unlock(p) 122#define genpd_unlock(p) p->lock_ops->unlock(p)
123 123
124#define genpd_status_on(genpd) (genpd->status == GPD_STATE_ACTIVE)
124#define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) 125#define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE)
126#define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON)
125 127
126static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, 128static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev,
127 struct generic_pm_domain *genpd) 129 struct generic_pm_domain *genpd)
@@ -130,8 +132,12 @@ static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev,
130 132
131 ret = pm_runtime_is_irq_safe(dev) && !genpd_is_irq_safe(genpd); 133 ret = pm_runtime_is_irq_safe(dev) && !genpd_is_irq_safe(genpd);
132 134
133 /* Warn once if IRQ safe dev in no sleep domain */ 135 /*
134 if (ret) 136 * Warn once if an IRQ safe device is attached to a no sleep domain, as
137 * to indicate a suboptimal configuration for PM. For an always on
138 * domain this isn't case, thus don't warn.
139 */
140 if (ret && !genpd_is_always_on(genpd))
135 dev_warn_once(dev, "PM domain %s will not be powered off\n", 141 dev_warn_once(dev, "PM domain %s will not be powered off\n",
136 genpd->name); 142 genpd->name);
137 143
@@ -296,11 +302,15 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
296 * (1) The domain is already in the "power off" state. 302 * (1) The domain is already in the "power off" state.
297 * (2) System suspend is in progress. 303 * (2) System suspend is in progress.
298 */ 304 */
299 if (genpd->status == GPD_STATE_POWER_OFF 305 if (!genpd_status_on(genpd) || genpd->prepared_count > 0)
300 || genpd->prepared_count > 0)
301 return 0; 306 return 0;
302 307
303 if (atomic_read(&genpd->sd_count) > 0) 308 /*
309 * Abort power off for the PM domain in the following situations:
310 * (1) The domain is configured as always on.
311 * (2) When the domain has a subdomain being powered on.
312 */
313 if (genpd_is_always_on(genpd) || atomic_read(&genpd->sd_count) > 0)
304 return -EBUSY; 314 return -EBUSY;
305 315
306 list_for_each_entry(pdd, &genpd->dev_list, list_node) { 316 list_for_each_entry(pdd, &genpd->dev_list, list_node) {
@@ -373,7 +383,7 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth)
373 struct gpd_link *link; 383 struct gpd_link *link;
374 int ret = 0; 384 int ret = 0;
375 385
376 if (genpd->status == GPD_STATE_ACTIVE) 386 if (genpd_status_on(genpd))
377 return 0; 387 return 0;
378 388
379 /* 389 /*
@@ -752,7 +762,7 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock,
752{ 762{
753 struct gpd_link *link; 763 struct gpd_link *link;
754 764
755 if (genpd->status == GPD_STATE_POWER_OFF) 765 if (!genpd_status_on(genpd) || genpd_is_always_on(genpd))
756 return; 766 return;
757 767
758 if (genpd->suspended_count != genpd->device_count 768 if (genpd->suspended_count != genpd->device_count
@@ -761,7 +771,8 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock,
761 771
762 /* Choose the deepest state when suspending */ 772 /* Choose the deepest state when suspending */
763 genpd->state_idx = genpd->state_count - 1; 773 genpd->state_idx = genpd->state_count - 1;
764 _genpd_power_off(genpd, false); 774 if (_genpd_power_off(genpd, false))
775 return;
765 776
766 genpd->status = GPD_STATE_POWER_OFF; 777 genpd->status = GPD_STATE_POWER_OFF;
767 778
@@ -793,7 +804,7 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock,
793{ 804{
794 struct gpd_link *link; 805 struct gpd_link *link;
795 806
796 if (genpd->status == GPD_STATE_ACTIVE) 807 if (genpd_status_on(genpd))
797 return; 808 return;
798 809
799 list_for_each_entry(link, &genpd->slave_links, slave_node) { 810 list_for_each_entry(link, &genpd->slave_links, slave_node) {
@@ -1329,8 +1340,7 @@ static int genpd_add_subdomain(struct generic_pm_domain *genpd,
1329 genpd_lock(subdomain); 1340 genpd_lock(subdomain);
1330 genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING); 1341 genpd_lock_nested(genpd, SINGLE_DEPTH_NESTING);
1331 1342
1332 if (genpd->status == GPD_STATE_POWER_OFF 1343 if (!genpd_status_on(genpd) && genpd_status_on(subdomain)) {
1333 && subdomain->status != GPD_STATE_POWER_OFF) {
1334 ret = -EINVAL; 1344 ret = -EINVAL;
1335 goto out; 1345 goto out;
1336 } 1346 }
@@ -1346,7 +1356,7 @@ static int genpd_add_subdomain(struct generic_pm_domain *genpd,
1346 list_add_tail(&link->master_node, &genpd->master_links); 1356 list_add_tail(&link->master_node, &genpd->master_links);
1347 link->slave = subdomain; 1357 link->slave = subdomain;
1348 list_add_tail(&link->slave_node, &subdomain->slave_links); 1358 list_add_tail(&link->slave_node, &subdomain->slave_links);
1349 if (subdomain->status != GPD_STATE_POWER_OFF) 1359 if (genpd_status_on(subdomain))
1350 genpd_sd_counter_inc(genpd); 1360 genpd_sd_counter_inc(genpd);
1351 1361
1352 out: 1362 out:
@@ -1406,7 +1416,7 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
1406 list_del(&link->master_node); 1416 list_del(&link->master_node);
1407 list_del(&link->slave_node); 1417 list_del(&link->slave_node);
1408 kfree(link); 1418 kfree(link);
1409 if (subdomain->status != GPD_STATE_POWER_OFF) 1419 if (genpd_status_on(subdomain))
1410 genpd_sd_counter_dec(genpd); 1420 genpd_sd_counter_dec(genpd);
1411 1421
1412 ret = 0; 1422 ret = 0;
@@ -1492,6 +1502,10 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
1492 genpd->dev_ops.start = pm_clk_resume; 1502 genpd->dev_ops.start = pm_clk_resume;
1493 } 1503 }
1494 1504
1505 /* Always-on domains must be powered on at initialization. */
1506 if (genpd_is_always_on(genpd) && !genpd_status_on(genpd))
1507 return -EINVAL;
1508
1495 /* Use only one "off" state if there were no states declared */ 1509 /* Use only one "off" state if there were no states declared */
1496 if (genpd->state_count == 0) { 1510 if (genpd->state_count == 0) {
1497 ret = genpd_set_default_power_state(genpd); 1511 ret = genpd_set_default_power_state(genpd);
@@ -1700,12 +1714,12 @@ int of_genpd_add_provider_simple(struct device_node *np,
1700 1714
1701 mutex_lock(&gpd_list_lock); 1715 mutex_lock(&gpd_list_lock);
1702 1716
1703 if (pm_genpd_present(genpd)) 1717 if (pm_genpd_present(genpd)) {
1704 ret = genpd_add_provider(np, genpd_xlate_simple, genpd); 1718 ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
1705 1719 if (!ret) {
1706 if (!ret) { 1720 genpd->provider = &np->fwnode;
1707 genpd->provider = &np->fwnode; 1721 genpd->has_provider = true;
1708 genpd->has_provider = true; 1722 }
1709 } 1723 }
1710 1724
1711 mutex_unlock(&gpd_list_lock); 1725 mutex_unlock(&gpd_list_lock);
@@ -2079,11 +2093,6 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state,
2079 int err; 2093 int err;
2080 u32 residency; 2094 u32 residency;
2081 u32 entry_latency, exit_latency; 2095 u32 entry_latency, exit_latency;
2082 const struct of_device_id *match_id;
2083
2084 match_id = of_match_node(idle_state_match, state_node);
2085 if (!match_id)
2086 return -EINVAL;
2087 2096
2088 err = of_property_read_u32(state_node, "entry-latency-us", 2097 err = of_property_read_u32(state_node, "entry-latency-us",
2089 &entry_latency); 2098 &entry_latency);
@@ -2132,6 +2141,7 @@ int of_genpd_parse_idle_states(struct device_node *dn,
2132 int err, ret; 2141 int err, ret;
2133 int count; 2142 int count;
2134 struct of_phandle_iterator it; 2143 struct of_phandle_iterator it;
2144 const struct of_device_id *match_id;
2135 2145
2136 count = of_count_phandle_with_args(dn, "domain-idle-states", NULL); 2146 count = of_count_phandle_with_args(dn, "domain-idle-states", NULL);
2137 if (count <= 0) 2147 if (count <= 0)
@@ -2144,6 +2154,9 @@ int of_genpd_parse_idle_states(struct device_node *dn,
2144 /* Loop over the phandles until all the requested entry is found */ 2154 /* Loop over the phandles until all the requested entry is found */
2145 of_for_each_phandle(&it, err, dn, "domain-idle-states", NULL, 0) { 2155 of_for_each_phandle(&it, err, dn, "domain-idle-states", NULL, 0) {
2146 np = it.node; 2156 np = it.node;
2157 match_id = of_match_node(idle_state_match, np);
2158 if (!match_id)
2159 continue;
2147 ret = genpd_parse_state(&st[i++], np); 2160 ret = genpd_parse_state(&st[i++], np);
2148 if (ret) { 2161 if (ret) {
2149 pr_err 2162 pr_err
@@ -2155,8 +2168,11 @@ int of_genpd_parse_idle_states(struct device_node *dn,
2155 } 2168 }
2156 } 2169 }
2157 2170
2158 *n = count; 2171 *n = i;
2159 *states = st; 2172 if (!i)
2173 kfree(st);
2174 else
2175 *states = st;
2160 2176
2161 return 0; 2177 return 0;
2162} 2178}
@@ -2221,7 +2237,7 @@ static int pm_genpd_summary_one(struct seq_file *s,
2221 2237
2222 if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup))) 2238 if (WARN_ON(genpd->status >= ARRAY_SIZE(status_lookup)))
2223 goto exit; 2239 goto exit;
2224 if (genpd->status == GPD_STATE_POWER_OFF) 2240 if (!genpd_status_on(genpd))
2225 snprintf(state, sizeof(state), "%s-%u", 2241 snprintf(state, sizeof(state), "%s-%u",
2226 status_lookup[genpd->status], genpd->state_idx); 2242 status_lookup[genpd->status], genpd->state_idx);
2227 else 2243 else
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index f96ab717534c..1d1dc11aa5fa 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -3969,7 +3969,7 @@ static int mtip_block_initialize(struct driver_data *dd)
3969 dd->tags.reserved_tags = 1; 3969 dd->tags.reserved_tags = 1;
3970 dd->tags.cmd_size = sizeof(struct mtip_cmd); 3970 dd->tags.cmd_size = sizeof(struct mtip_cmd);
3971 dd->tags.numa_node = dd->numa_node; 3971 dd->tags.numa_node = dd->numa_node;
3972 dd->tags.flags = BLK_MQ_F_SHOULD_MERGE; 3972 dd->tags.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_NO_SCHED;
3973 dd->tags.driver_data = dd; 3973 dd->tags.driver_data = dd;
3974 dd->tags.timeout = MTIP_NCQ_CMD_TIMEOUT_MS; 3974 dd->tags.timeout = MTIP_NCQ_CMD_TIMEOUT_MS;
3975 3975
diff --git a/drivers/clk/clk-stm32f4.c b/drivers/clk/clk-stm32f4.c
index ab609a76706f..cf9449b3dbd9 100644
--- a/drivers/clk/clk-stm32f4.c
+++ b/drivers/clk/clk-stm32f4.c
@@ -429,6 +429,13 @@ static const struct clk_div_table pll_divp_table[] = {
429 { 0, 2 }, { 1, 4 }, { 2, 6 }, { 3, 8 }, { 0 } 429 { 0, 2 }, { 1, 4 }, { 2, 6 }, { 3, 8 }, { 0 }
430}; 430};
431 431
432static const struct clk_div_table pll_divq_table[] = {
433 { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 },
434 { 8, 8 }, { 9, 9 }, { 10, 10 }, { 11, 11 }, { 12, 12 }, { 13, 13 },
435 { 14, 14 }, { 15, 15 },
436 { 0 }
437};
438
432static const struct clk_div_table pll_divr_table[] = { 439static const struct clk_div_table pll_divr_table[] = {
433 { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 0 } 440 { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 0 }
434}; 441};
@@ -496,9 +503,9 @@ struct stm32f4_div_data {
496 503
497#define MAX_PLL_DIV 3 504#define MAX_PLL_DIV 3
498static const struct stm32f4_div_data div_data[MAX_PLL_DIV] = { 505static const struct stm32f4_div_data div_data[MAX_PLL_DIV] = {
499 { 16, 2, 0, pll_divp_table }, 506 { 16, 2, 0, pll_divp_table },
500 { 24, 4, CLK_DIVIDER_ONE_BASED, NULL }, 507 { 24, 4, 0, pll_divq_table },
501 { 28, 3, 0, pll_divr_table }, 508 { 28, 3, 0, pll_divr_table },
502}; 509};
503 510
504struct stm32f4_pll_data { 511struct stm32f4_pll_data {
diff --git a/drivers/clk/sunxi-ng/Kconfig b/drivers/clk/sunxi-ng/Kconfig
index 72109d2cf41b..1c2357301017 100644
--- a/drivers/clk/sunxi-ng/Kconfig
+++ b/drivers/clk/sunxi-ng/Kconfig
@@ -1,6 +1,7 @@
1config SUNXI_CCU 1config SUNXI_CCU
2 bool "Clock support for Allwinner SoCs" 2 bool "Clock support for Allwinner SoCs"
3 depends on ARCH_SUNXI || COMPILE_TEST 3 depends on ARCH_SUNXI || COMPILE_TEST
4 select RESET_CONTROLLER
4 default ARCH_SUNXI 5 default ARCH_SUNXI
5 6
6if SUNXI_CCU 7if SUNXI_CCU
@@ -135,6 +136,7 @@ config SUN8I_V3S_CCU
135config SUN9I_A80_CCU 136config SUN9I_A80_CCU
136 bool "Support for the Allwinner A80 CCU" 137 bool "Support for the Allwinner A80 CCU"
137 select SUNXI_CCU_DIV 138 select SUNXI_CCU_DIV
139 select SUNXI_CCU_MULT
138 select SUNXI_CCU_GATE 140 select SUNXI_CCU_GATE
139 select SUNXI_CCU_NKMP 141 select SUNXI_CCU_NKMP
140 select SUNXI_CCU_NM 142 select SUNXI_CCU_NM
diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-a33.c b/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
index a7b3c08ed0e2..2c69b631967a 100644
--- a/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
+++ b/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
@@ -752,6 +752,13 @@ static const struct sunxi_ccu_desc sun8i_a33_ccu_desc = {
752 .num_resets = ARRAY_SIZE(sun8i_a33_ccu_resets), 752 .num_resets = ARRAY_SIZE(sun8i_a33_ccu_resets),
753}; 753};
754 754
755static struct ccu_pll_nb sun8i_a33_pll_cpu_nb = {
756 .common = &pll_cpux_clk.common,
757 /* copy from pll_cpux_clk */
758 .enable = BIT(31),
759 .lock = BIT(28),
760};
761
755static struct ccu_mux_nb sun8i_a33_cpu_nb = { 762static struct ccu_mux_nb sun8i_a33_cpu_nb = {
756 .common = &cpux_clk.common, 763 .common = &cpux_clk.common,
757 .cm = &cpux_clk.mux, 764 .cm = &cpux_clk.mux,
@@ -783,6 +790,10 @@ static void __init sun8i_a33_ccu_setup(struct device_node *node)
783 790
784 sunxi_ccu_probe(node, reg, &sun8i_a33_ccu_desc); 791 sunxi_ccu_probe(node, reg, &sun8i_a33_ccu_desc);
785 792
793 /* Gate then ungate PLL CPU after any rate changes */
794 ccu_pll_notifier_register(&sun8i_a33_pll_cpu_nb);
795
796 /* Reparent CPU during PLL CPU rate changes */
786 ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk, 797 ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
787 &sun8i_a33_cpu_nb); 798 &sun8i_a33_cpu_nb);
788} 799}
diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 8a47bafd7890..9d8724715a43 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -14,11 +14,13 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16 16
17#include <linux/clk.h>
17#include <linux/clk-provider.h> 18#include <linux/clk-provider.h>
18#include <linux/iopoll.h> 19#include <linux/iopoll.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20 21
21#include "ccu_common.h" 22#include "ccu_common.h"
23#include "ccu_gate.h"
22#include "ccu_reset.h" 24#include "ccu_reset.h"
23 25
24static DEFINE_SPINLOCK(ccu_lock); 26static DEFINE_SPINLOCK(ccu_lock);
@@ -39,6 +41,53 @@ void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock)
39 WARN_ON(readl_relaxed_poll_timeout(addr, reg, reg & lock, 100, 70000)); 41 WARN_ON(readl_relaxed_poll_timeout(addr, reg, reg & lock, 100, 70000));
40} 42}
41 43
44/*
45 * This clock notifier is called when the frequency of a PLL clock is
46 * changed. In common PLL designs, changes to the dividers take effect
47 * almost immediately, while changes to the multipliers (implemented
48 * as dividers in the feedback loop) take a few cycles to work into
49 * the feedback loop for the PLL to stablize.
50 *
51 * Sometimes when the PLL clock rate is changed, the decrease in the
52 * divider is too much for the decrease in the multiplier to catch up.
53 * The PLL clock rate will spike, and in some cases, might lock up
54 * completely.
55 *
56 * This notifier callback will gate and then ungate the clock,
57 * effectively resetting it, so it proceeds to work. Care must be
58 * taken to reparent consumers to other temporary clocks during the
59 * rate change, and that this notifier callback must be the first
60 * to be registered.
61 */
62static int ccu_pll_notifier_cb(struct notifier_block *nb,
63 unsigned long event, void *data)
64{
65 struct ccu_pll_nb *pll = to_ccu_pll_nb(nb);
66 int ret = 0;
67
68 if (event != POST_RATE_CHANGE)
69 goto out;
70
71 ccu_gate_helper_disable(pll->common, pll->enable);
72
73 ret = ccu_gate_helper_enable(pll->common, pll->enable);
74 if (ret)
75 goto out;
76
77 ccu_helper_wait_for_lock(pll->common, pll->lock);
78
79out:
80 return notifier_from_errno(ret);
81}
82
83int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb)
84{
85 pll_nb->clk_nb.notifier_call = ccu_pll_notifier_cb;
86
87 return clk_notifier_register(pll_nb->common->hw.clk,
88 &pll_nb->clk_nb);
89}
90
42int sunxi_ccu_probe(struct device_node *node, void __iomem *reg, 91int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
43 const struct sunxi_ccu_desc *desc) 92 const struct sunxi_ccu_desc *desc)
44{ 93{
diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_common.h
index 73d81dc58fc5..d6fdd7a789aa 100644
--- a/drivers/clk/sunxi-ng/ccu_common.h
+++ b/drivers/clk/sunxi-ng/ccu_common.h
@@ -83,6 +83,18 @@ struct sunxi_ccu_desc {
83 83
84void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock); 84void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock);
85 85
86struct ccu_pll_nb {
87 struct notifier_block clk_nb;
88 struct ccu_common *common;
89
90 u32 enable;
91 u32 lock;
92};
93
94#define to_ccu_pll_nb(_nb) container_of(_nb, struct ccu_pll_nb, clk_nb)
95
96int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb);
97
86int sunxi_ccu_probe(struct device_node *node, void __iomem *reg, 98int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
87 const struct sunxi_ccu_desc *desc); 99 const struct sunxi_ccu_desc *desc);
88 100
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 74fa5c5904d3..74ed7e9a7f27 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -247,6 +247,12 @@ config ARM_TEGRA124_CPUFREQ
247 help 247 help
248 This adds the CPUFreq driver support for Tegra124 SOCs. 248 This adds the CPUFreq driver support for Tegra124 SOCs.
249 249
250config ARM_TEGRA186_CPUFREQ
251 tristate "Tegra186 CPUFreq support"
252 depends on ARCH_TEGRA && TEGRA_BPMP
253 help
254 This adds the CPUFreq driver support for Tegra186 SOCs.
255
250config ARM_TI_CPUFREQ 256config ARM_TI_CPUFREQ
251 bool "Texas Instruments CPUFreq support" 257 bool "Texas Instruments CPUFreq support"
252 depends on ARCH_OMAP2PLUS 258 depends on ARCH_OMAP2PLUS
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 9f5a8045f36d..b7e78f063c4f 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -77,6 +77,7 @@ obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
77obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-cpufreq.o 77obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-cpufreq.o
78obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o 78obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o
79obj-$(CONFIG_ARM_TEGRA124_CPUFREQ) += tegra124-cpufreq.o 79obj-$(CONFIG_ARM_TEGRA124_CPUFREQ) += tegra124-cpufreq.o
80obj-$(CONFIG_ARM_TEGRA186_CPUFREQ) += tegra186-cpufreq.o
80obj-$(CONFIG_ARM_TI_CPUFREQ) += ti-cpufreq.o 81obj-$(CONFIG_ARM_TI_CPUFREQ) += ti-cpufreq.o
81obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o 82obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
82obj-$(CONFIG_ACPI_CPPC_CPUFREQ) += cppc_cpufreq.o 83obj-$(CONFIG_ACPI_CPPC_CPUFREQ) += cppc_cpufreq.o
diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c
index 5c3ec1dd4921..3575b82210ba 100644
--- a/drivers/cpufreq/dbx500-cpufreq.c
+++ b/drivers/cpufreq/dbx500-cpufreq.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
14#include <linux/cpu_cooling.h>
14#include <linux/delay.h> 15#include <linux/delay.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
@@ -18,6 +19,7 @@
18 19
19static struct cpufreq_frequency_table *freq_table; 20static struct cpufreq_frequency_table *freq_table;
20static struct clk *armss_clk; 21static struct clk *armss_clk;
22static struct thermal_cooling_device *cdev;
21 23
22static int dbx500_cpufreq_target(struct cpufreq_policy *policy, 24static int dbx500_cpufreq_target(struct cpufreq_policy *policy,
23 unsigned int index) 25 unsigned int index)
@@ -32,6 +34,22 @@ static int dbx500_cpufreq_init(struct cpufreq_policy *policy)
32 return cpufreq_generic_init(policy, freq_table, 20 * 1000); 34 return cpufreq_generic_init(policy, freq_table, 20 * 1000);
33} 35}
34 36
37static int dbx500_cpufreq_exit(struct cpufreq_policy *policy)
38{
39 if (!IS_ERR(cdev))
40 cpufreq_cooling_unregister(cdev);
41 return 0;
42}
43
44static void dbx500_cpufreq_ready(struct cpufreq_policy *policy)
45{
46 cdev = cpufreq_cooling_register(policy->cpus);
47 if (IS_ERR(cdev))
48 pr_err("Failed to register cooling device %ld\n", PTR_ERR(cdev));
49 else
50 pr_info("Cooling device registered: %s\n", cdev->type);
51}
52
35static struct cpufreq_driver dbx500_cpufreq_driver = { 53static struct cpufreq_driver dbx500_cpufreq_driver = {
36 .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS | 54 .flags = CPUFREQ_STICKY | CPUFREQ_CONST_LOOPS |
37 CPUFREQ_NEED_INITIAL_FREQ_CHECK, 55 CPUFREQ_NEED_INITIAL_FREQ_CHECK,
@@ -39,6 +57,8 @@ static struct cpufreq_driver dbx500_cpufreq_driver = {
39 .target_index = dbx500_cpufreq_target, 57 .target_index = dbx500_cpufreq_target,
40 .get = cpufreq_generic_get, 58 .get = cpufreq_generic_get,
41 .init = dbx500_cpufreq_init, 59 .init = dbx500_cpufreq_init,
60 .exit = dbx500_cpufreq_exit,
61 .ready = dbx500_cpufreq_ready,
42 .name = "DBX500", 62 .name = "DBX500",
43 .attr = cpufreq_generic_attr, 63 .attr = cpufreq_generic_attr,
44}; 64};
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index 7719b02e04f5..9c13f097fd8c 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -161,8 +161,13 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
161 161
162static int imx6q_cpufreq_init(struct cpufreq_policy *policy) 162static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
163{ 163{
164 int ret;
165
164 policy->clk = arm_clk; 166 policy->clk = arm_clk;
165 return cpufreq_generic_init(policy, freq_table, transition_latency); 167 ret = cpufreq_generic_init(policy, freq_table, transition_latency);
168 policy->suspend_freq = policy->max;
169
170 return ret;
166} 171}
167 172
168static struct cpufreq_driver imx6q_cpufreq_driver = { 173static struct cpufreq_driver imx6q_cpufreq_driver = {
@@ -173,6 +178,7 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
173 .init = imx6q_cpufreq_init, 178 .init = imx6q_cpufreq_init,
174 .name = "imx6q-cpufreq", 179 .name = "imx6q-cpufreq",
175 .attr = cpufreq_generic_attr, 180 .attr = cpufreq_generic_attr,
181 .suspend = cpufreq_generic_suspend,
176}; 182};
177 183
178static int imx6q_cpufreq_probe(struct platform_device *pdev) 184static int imx6q_cpufreq_probe(struct platform_device *pdev)
@@ -222,6 +228,13 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
222 arm_reg = regulator_get(cpu_dev, "arm"); 228 arm_reg = regulator_get(cpu_dev, "arm");
223 pu_reg = regulator_get_optional(cpu_dev, "pu"); 229 pu_reg = regulator_get_optional(cpu_dev, "pu");
224 soc_reg = regulator_get(cpu_dev, "soc"); 230 soc_reg = regulator_get(cpu_dev, "soc");
231 if (PTR_ERR(arm_reg) == -EPROBE_DEFER ||
232 PTR_ERR(soc_reg) == -EPROBE_DEFER ||
233 PTR_ERR(pu_reg) == -EPROBE_DEFER) {
234 ret = -EPROBE_DEFER;
235 dev_dbg(cpu_dev, "regulators not ready, defer\n");
236 goto put_reg;
237 }
225 if (IS_ERR(arm_reg) || IS_ERR(soc_reg)) { 238 if (IS_ERR(arm_reg) || IS_ERR(soc_reg)) {
226 dev_err(cpu_dev, "failed to get regulators\n"); 239 dev_err(cpu_dev, "failed to get regulators\n");
227 ret = -ENOENT; 240 ret = -ENOENT;
@@ -255,7 +268,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
255 ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); 268 ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
256 if (ret) { 269 if (ret) {
257 dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret); 270 dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
258 goto put_reg; 271 goto out_free_opp;
259 } 272 }
260 273
261 /* Make imx6_soc_volt array's size same as arm opp number */ 274 /* Make imx6_soc_volt array's size same as arm opp number */
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 283491f742d3..b7de5bd76a31 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -37,7 +37,11 @@
37#include <asm/cpufeature.h> 37#include <asm/cpufeature.h>
38#include <asm/intel-family.h> 38#include <asm/intel-family.h>
39 39
40#define INTEL_PSTATE_DEFAULT_SAMPLING_INTERVAL (10 * NSEC_PER_MSEC)
41#define INTEL_PSTATE_HWP_SAMPLING_INTERVAL (50 * NSEC_PER_MSEC)
42
40#define INTEL_CPUFREQ_TRANSITION_LATENCY 20000 43#define INTEL_CPUFREQ_TRANSITION_LATENCY 20000
44#define INTEL_CPUFREQ_TRANSITION_DELAY 500
41 45
42#ifdef CONFIG_ACPI 46#ifdef CONFIG_ACPI
43#include <acpi/processor.h> 47#include <acpi/processor.h>
@@ -74,6 +78,11 @@ static inline int ceiling_fp(int32_t x)
74 return ret; 78 return ret;
75} 79}
76 80
81static inline int32_t percent_fp(int percent)
82{
83 return div_fp(percent, 100);
84}
85
77static inline u64 mul_ext_fp(u64 x, u64 y) 86static inline u64 mul_ext_fp(u64 x, u64 y)
78{ 87{
79 return (x * y) >> EXT_FRAC_BITS; 88 return (x * y) >> EXT_FRAC_BITS;
@@ -186,45 +195,22 @@ struct _pid {
186}; 195};
187 196
188/** 197/**
189 * struct perf_limits - Store user and policy limits 198 * struct global_params - Global parameters, mostly tunable via sysfs.
190 * @no_turbo: User requested turbo state from intel_pstate sysfs 199 * @no_turbo: Whether or not to use turbo P-states.
191 * @turbo_disabled: Platform turbo status either from msr 200 * @turbo_disabled: Whethet or not turbo P-states are available at all,
192 * MSR_IA32_MISC_ENABLE or when maximum available pstate 201 * based on the MSR_IA32_MISC_ENABLE value and whether or
193 * matches the maximum turbo pstate 202 * not the maximum reported turbo P-state is different from
194 * @max_perf_pct: Effective maximum performance limit in percentage, this 203 * the maximum reported non-turbo one.
195 * is minimum of either limits enforced by cpufreq policy 204 * @min_perf_pct: Minimum capacity limit in percent of the maximum turbo
196 * or limits from user set limits via intel_pstate sysfs 205 * P-state capacity.
197 * @min_perf_pct: Effective minimum performance limit in percentage, this 206 * @max_perf_pct: Maximum capacity limit in percent of the maximum turbo
198 * is maximum of either limits enforced by cpufreq policy 207 * P-state capacity.
199 * or limits from user set limits via intel_pstate sysfs
200 * @max_perf: This is a scaled value between 0 to 255 for max_perf_pct
201 * This value is used to limit max pstate
202 * @min_perf: This is a scaled value between 0 to 255 for min_perf_pct
203 * This value is used to limit min pstate
204 * @max_policy_pct: The maximum performance in percentage enforced by
205 * cpufreq setpolicy interface
206 * @max_sysfs_pct: The maximum performance in percentage enforced by
207 * intel pstate sysfs interface, unused when per cpu
208 * controls are enforced
209 * @min_policy_pct: The minimum performance in percentage enforced by
210 * cpufreq setpolicy interface
211 * @min_sysfs_pct: The minimum performance in percentage enforced by
212 * intel pstate sysfs interface, unused when per cpu
213 * controls are enforced
214 *
215 * Storage for user and policy defined limits.
216 */ 208 */
217struct perf_limits { 209struct global_params {
218 int no_turbo; 210 bool no_turbo;
219 int turbo_disabled; 211 bool turbo_disabled;
220 int max_perf_pct; 212 int max_perf_pct;
221 int min_perf_pct; 213 int min_perf_pct;
222 int32_t max_perf;
223 int32_t min_perf;
224 int max_policy_pct;
225 int max_sysfs_pct;
226 int min_policy_pct;
227 int min_sysfs_pct;
228}; 214};
229 215
230/** 216/**
@@ -245,9 +231,10 @@ struct perf_limits {
245 * @prev_cummulative_iowait: IO Wait time difference from last and 231 * @prev_cummulative_iowait: IO Wait time difference from last and
246 * current sample 232 * current sample
247 * @sample: Storage for storing last Sample data 233 * @sample: Storage for storing last Sample data
248 * @perf_limits: Pointer to perf_limit unique to this CPU 234 * @min_perf: Minimum capacity limit as a fraction of the maximum
249 * Not all field in the structure are applicable 235 * turbo P-state capacity.
250 * when per cpu controls are enforced 236 * @max_perf: Maximum capacity limit as a fraction of the maximum
237 * turbo P-state capacity.
251 * @acpi_perf_data: Stores ACPI perf information read from _PSS 238 * @acpi_perf_data: Stores ACPI perf information read from _PSS
252 * @valid_pss_table: Set to true for valid ACPI _PSS entries found 239 * @valid_pss_table: Set to true for valid ACPI _PSS entries found
253 * @epp_powersave: Last saved HWP energy performance preference 240 * @epp_powersave: Last saved HWP energy performance preference
@@ -279,7 +266,8 @@ struct cpudata {
279 u64 prev_tsc; 266 u64 prev_tsc;
280 u64 prev_cummulative_iowait; 267 u64 prev_cummulative_iowait;
281 struct sample sample; 268 struct sample sample;
282 struct perf_limits *perf_limits; 269 int32_t min_perf;
270 int32_t max_perf;
283#ifdef CONFIG_ACPI 271#ifdef CONFIG_ACPI
284 struct acpi_processor_performance acpi_perf_data; 272 struct acpi_processor_performance acpi_perf_data;
285 bool valid_pss_table; 273 bool valid_pss_table;
@@ -324,7 +312,7 @@ struct pstate_adjust_policy {
324 * @get_scaling: Callback to get frequency scaling factor 312 * @get_scaling: Callback to get frequency scaling factor
325 * @get_val: Callback to convert P state to actual MSR write value 313 * @get_val: Callback to convert P state to actual MSR write value
326 * @get_vid: Callback to get VID data for Atom platforms 314 * @get_vid: Callback to get VID data for Atom platforms
327 * @get_target_pstate: Callback to a function to calculate next P state to use 315 * @update_util: Active mode utilization update callback.
328 * 316 *
329 * Core and Atom CPU models have different way to get P State limits. This 317 * Core and Atom CPU models have different way to get P State limits. This
330 * structure is used to store those callbacks. 318 * structure is used to store those callbacks.
@@ -337,43 +325,31 @@ struct pstate_funcs {
337 int (*get_scaling)(void); 325 int (*get_scaling)(void);
338 u64 (*get_val)(struct cpudata*, int pstate); 326 u64 (*get_val)(struct cpudata*, int pstate);
339 void (*get_vid)(struct cpudata *); 327 void (*get_vid)(struct cpudata *);
340 int32_t (*get_target_pstate)(struct cpudata *); 328 void (*update_util)(struct update_util_data *data, u64 time,
329 unsigned int flags);
341}; 330};
342 331
343/** 332static struct pstate_funcs pstate_funcs __read_mostly;
344 * struct cpu_defaults- Per CPU model default config data 333static struct pstate_adjust_policy pid_params __read_mostly = {
345 * @pid_policy: PID config data 334 .sample_rate_ms = 10,
346 * @funcs: Callback function data 335 .sample_rate_ns = 10 * NSEC_PER_MSEC,
347 */ 336 .deadband = 0,
348struct cpu_defaults { 337 .setpoint = 97,
349 struct pstate_adjust_policy pid_policy; 338 .p_gain_pct = 20,
350 struct pstate_funcs funcs; 339 .d_gain_pct = 0,
340 .i_gain_pct = 0,
351}; 341};
352 342
353static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu);
354static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu);
355
356static struct pstate_adjust_policy pid_params __read_mostly;
357static struct pstate_funcs pstate_funcs __read_mostly;
358static int hwp_active __read_mostly; 343static int hwp_active __read_mostly;
359static bool per_cpu_limits __read_mostly; 344static bool per_cpu_limits __read_mostly;
360 345
361static bool driver_registered __read_mostly; 346static struct cpufreq_driver *intel_pstate_driver __read_mostly;
362 347
363#ifdef CONFIG_ACPI 348#ifdef CONFIG_ACPI
364static bool acpi_ppc; 349static bool acpi_ppc;
365#endif 350#endif
366 351
367static struct perf_limits global; 352static struct global_params global;
368
369static void intel_pstate_init_limits(struct perf_limits *limits)
370{
371 memset(limits, 0, sizeof(*limits));
372 limits->max_perf_pct = 100;
373 limits->max_perf = int_ext_tofp(1);
374 limits->max_policy_pct = 100;
375 limits->max_sysfs_pct = 100;
376}
377 353
378static DEFINE_MUTEX(intel_pstate_driver_lock); 354static DEFINE_MUTEX(intel_pstate_driver_lock);
379static DEFINE_MUTEX(intel_pstate_limits_lock); 355static DEFINE_MUTEX(intel_pstate_limits_lock);
@@ -530,29 +506,6 @@ static inline void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)
530} 506}
531#endif 507#endif
532 508
533static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
534 int deadband, int integral) {
535 pid->setpoint = int_tofp(setpoint);
536 pid->deadband = int_tofp(deadband);
537 pid->integral = int_tofp(integral);
538 pid->last_err = int_tofp(setpoint) - int_tofp(busy);
539}
540
541static inline void pid_p_gain_set(struct _pid *pid, int percent)
542{
543 pid->p_gain = div_fp(percent, 100);
544}
545
546static inline void pid_i_gain_set(struct _pid *pid, int percent)
547{
548 pid->i_gain = div_fp(percent, 100);
549}
550
551static inline void pid_d_gain_set(struct _pid *pid, int percent)
552{
553 pid->d_gain = div_fp(percent, 100);
554}
555
556static signed int pid_calc(struct _pid *pid, int32_t busy) 509static signed int pid_calc(struct _pid *pid, int32_t busy)
557{ 510{
558 signed int result; 511 signed int result;
@@ -590,23 +543,17 @@ static signed int pid_calc(struct _pid *pid, int32_t busy)
590 return (signed int)fp_toint(result); 543 return (signed int)fp_toint(result);
591} 544}
592 545
593static inline void intel_pstate_busy_pid_reset(struct cpudata *cpu) 546static inline void intel_pstate_pid_reset(struct cpudata *cpu)
594{
595 pid_p_gain_set(&cpu->pid, pid_params.p_gain_pct);
596 pid_d_gain_set(&cpu->pid, pid_params.d_gain_pct);
597 pid_i_gain_set(&cpu->pid, pid_params.i_gain_pct);
598
599 pid_reset(&cpu->pid, pid_params.setpoint, 100, pid_params.deadband, 0);
600}
601
602static inline void intel_pstate_reset_all_pid(void)
603{ 547{
604 unsigned int cpu; 548 struct _pid *pid = &cpu->pid;
605 549
606 for_each_online_cpu(cpu) { 550 pid->p_gain = percent_fp(pid_params.p_gain_pct);
607 if (all_cpu_data[cpu]) 551 pid->d_gain = percent_fp(pid_params.d_gain_pct);
608 intel_pstate_busy_pid_reset(all_cpu_data[cpu]); 552 pid->i_gain = percent_fp(pid_params.i_gain_pct);
609 } 553 pid->setpoint = int_tofp(pid_params.setpoint);
554 pid->last_err = pid->setpoint - int_tofp(100);
555 pid->deadband = int_tofp(pid_params.deadband);
556 pid->integral = 0;
610} 557}
611 558
612static inline void update_turbo_state(void) 559static inline void update_turbo_state(void)
@@ -621,6 +568,14 @@ static inline void update_turbo_state(void)
621 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); 568 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate);
622} 569}
623 570
571static int min_perf_pct_min(void)
572{
573 struct cpudata *cpu = all_cpu_data[0];
574
575 return DIV_ROUND_UP(cpu->pstate.min_pstate * 100,
576 cpu->pstate.turbo_pstate);
577}
578
624static s16 intel_pstate_get_epb(struct cpudata *cpu_data) 579static s16 intel_pstate_get_epb(struct cpudata *cpu_data)
625{ 580{
626 u64 epb; 581 u64 epb;
@@ -838,96 +793,80 @@ static struct freq_attr *hwp_cpufreq_attrs[] = {
838 NULL, 793 NULL,
839}; 794};
840 795
841static void intel_pstate_hwp_set(struct cpufreq_policy *policy) 796static void intel_pstate_hwp_set(unsigned int cpu)
842{ 797{
843 int min, hw_min, max, hw_max, cpu; 798 struct cpudata *cpu_data = all_cpu_data[cpu];
844 struct perf_limits *perf_limits = &global; 799 int min, hw_min, max, hw_max;
845 u64 value, cap; 800 u64 value, cap;
801 s16 epp;
846 802
847 for_each_cpu(cpu, policy->cpus) { 803 rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap);
848 struct cpudata *cpu_data = all_cpu_data[cpu]; 804 hw_min = HWP_LOWEST_PERF(cap);
849 s16 epp; 805 if (global.no_turbo)
850 806 hw_max = HWP_GUARANTEED_PERF(cap);
851 if (per_cpu_limits) 807 else
852 perf_limits = all_cpu_data[cpu]->perf_limits; 808 hw_max = HWP_HIGHEST_PERF(cap);
853
854 rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap);
855 hw_min = HWP_LOWEST_PERF(cap);
856 if (global.no_turbo)
857 hw_max = HWP_GUARANTEED_PERF(cap);
858 else
859 hw_max = HWP_HIGHEST_PERF(cap);
860
861 max = fp_ext_toint(hw_max * perf_limits->max_perf);
862 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE)
863 min = max;
864 else
865 min = fp_ext_toint(hw_max * perf_limits->min_perf);
866 809
867 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); 810 max = fp_ext_toint(hw_max * cpu_data->max_perf);
811 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE)
812 min = max;
813 else
814 min = fp_ext_toint(hw_max * cpu_data->min_perf);
868 815
869 value &= ~HWP_MIN_PERF(~0L); 816 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
870 value |= HWP_MIN_PERF(min);
871 817
872 value &= ~HWP_MAX_PERF(~0L); 818 value &= ~HWP_MIN_PERF(~0L);
873 value |= HWP_MAX_PERF(max); 819 value |= HWP_MIN_PERF(min);
874 820
875 if (cpu_data->epp_policy == cpu_data->policy) 821 value &= ~HWP_MAX_PERF(~0L);
876 goto skip_epp; 822 value |= HWP_MAX_PERF(max);
877 823
878 cpu_data->epp_policy = cpu_data->policy; 824 if (cpu_data->epp_policy == cpu_data->policy)
825 goto skip_epp;
879 826
880 if (cpu_data->epp_saved >= 0) { 827 cpu_data->epp_policy = cpu_data->policy;
881 epp = cpu_data->epp_saved;
882 cpu_data->epp_saved = -EINVAL;
883 goto update_epp;
884 }
885 828
886 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) { 829 if (cpu_data->epp_saved >= 0) {
887 epp = intel_pstate_get_epp(cpu_data, value); 830 epp = cpu_data->epp_saved;
888 cpu_data->epp_powersave = epp; 831 cpu_data->epp_saved = -EINVAL;
889 /* If EPP read was failed, then don't try to write */ 832 goto update_epp;
890 if (epp < 0) 833 }
891 goto skip_epp;
892 834
835 if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) {
836 epp = intel_pstate_get_epp(cpu_data, value);
837 cpu_data->epp_powersave = epp;
838 /* If EPP read was failed, then don't try to write */
839 if (epp < 0)
840 goto skip_epp;
893 841
894 epp = 0; 842 epp = 0;
895 } else { 843 } else {
896 /* skip setting EPP, when saved value is invalid */ 844 /* skip setting EPP, when saved value is invalid */
897 if (cpu_data->epp_powersave < 0) 845 if (cpu_data->epp_powersave < 0)
898 goto skip_epp; 846 goto skip_epp;
899 847
900 /* 848 /*
901 * No need to restore EPP when it is not zero. This 849 * No need to restore EPP when it is not zero. This
902 * means: 850 * means:
903 * - Policy is not changed 851 * - Policy is not changed
904 * - user has manually changed 852 * - user has manually changed
905 * - Error reading EPB 853 * - Error reading EPB
906 */ 854 */
907 epp = intel_pstate_get_epp(cpu_data, value); 855 epp = intel_pstate_get_epp(cpu_data, value);
908 if (epp) 856 if (epp)
909 goto skip_epp; 857 goto skip_epp;
910 858
911 epp = cpu_data->epp_powersave; 859 epp = cpu_data->epp_powersave;
912 } 860 }
913update_epp: 861update_epp:
914 if (static_cpu_has(X86_FEATURE_HWP_EPP)) { 862 if (static_cpu_has(X86_FEATURE_HWP_EPP)) {
915 value &= ~GENMASK_ULL(31, 24); 863 value &= ~GENMASK_ULL(31, 24);
916 value |= (u64)epp << 24; 864 value |= (u64)epp << 24;
917 } else { 865 } else {
918 intel_pstate_set_epb(cpu, epp); 866 intel_pstate_set_epb(cpu, epp);
919 }
920skip_epp:
921 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value);
922 } 867 }
923} 868skip_epp:
924 869 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value);
925static int intel_pstate_hwp_set_policy(struct cpufreq_policy *policy)
926{
927 if (hwp_active)
928 intel_pstate_hwp_set(policy);
929
930 return 0;
931} 870}
932 871
933static int intel_pstate_hwp_save_state(struct cpufreq_policy *policy) 872static int intel_pstate_hwp_save_state(struct cpufreq_policy *policy)
@@ -944,20 +883,17 @@ static int intel_pstate_hwp_save_state(struct cpufreq_policy *policy)
944 883
945static int intel_pstate_resume(struct cpufreq_policy *policy) 884static int intel_pstate_resume(struct cpufreq_policy *policy)
946{ 885{
947 int ret;
948
949 if (!hwp_active) 886 if (!hwp_active)
950 return 0; 887 return 0;
951 888
952 mutex_lock(&intel_pstate_limits_lock); 889 mutex_lock(&intel_pstate_limits_lock);
953 890
954 all_cpu_data[policy->cpu]->epp_policy = 0; 891 all_cpu_data[policy->cpu]->epp_policy = 0;
955 892 intel_pstate_hwp_set(policy->cpu);
956 ret = intel_pstate_hwp_set_policy(policy);
957 893
958 mutex_unlock(&intel_pstate_limits_lock); 894 mutex_unlock(&intel_pstate_limits_lock);
959 895
960 return ret; 896 return 0;
961} 897}
962 898
963static void intel_pstate_update_policies(void) 899static void intel_pstate_update_policies(void)
@@ -971,9 +907,14 @@ static void intel_pstate_update_policies(void)
971/************************** debugfs begin ************************/ 907/************************** debugfs begin ************************/
972static int pid_param_set(void *data, u64 val) 908static int pid_param_set(void *data, u64 val)
973{ 909{
910 unsigned int cpu;
911
974 *(u32 *)data = val; 912 *(u32 *)data = val;
975 pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC; 913 pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC;
976 intel_pstate_reset_all_pid(); 914 for_each_possible_cpu(cpu)
915 if (all_cpu_data[cpu])
916 intel_pstate_pid_reset(all_cpu_data[cpu]);
917
977 return 0; 918 return 0;
978} 919}
979 920
@@ -1084,7 +1025,7 @@ static ssize_t show_turbo_pct(struct kobject *kobj,
1084 1025
1085 mutex_lock(&intel_pstate_driver_lock); 1026 mutex_lock(&intel_pstate_driver_lock);
1086 1027
1087 if (!driver_registered) { 1028 if (!intel_pstate_driver) {
1088 mutex_unlock(&intel_pstate_driver_lock); 1029 mutex_unlock(&intel_pstate_driver_lock);
1089 return -EAGAIN; 1030 return -EAGAIN;
1090 } 1031 }
@@ -1109,7 +1050,7 @@ static ssize_t show_num_pstates(struct kobject *kobj,
1109 1050
1110 mutex_lock(&intel_pstate_driver_lock); 1051 mutex_lock(&intel_pstate_driver_lock);
1111 1052
1112 if (!driver_registered) { 1053 if (!intel_pstate_driver) {
1113 mutex_unlock(&intel_pstate_driver_lock); 1054 mutex_unlock(&intel_pstate_driver_lock);
1114 return -EAGAIN; 1055 return -EAGAIN;
1115 } 1056 }
@@ -1129,7 +1070,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
1129 1070
1130 mutex_lock(&intel_pstate_driver_lock); 1071 mutex_lock(&intel_pstate_driver_lock);
1131 1072
1132 if (!driver_registered) { 1073 if (!intel_pstate_driver) {
1133 mutex_unlock(&intel_pstate_driver_lock); 1074 mutex_unlock(&intel_pstate_driver_lock);
1134 return -EAGAIN; 1075 return -EAGAIN;
1135 } 1076 }
@@ -1157,7 +1098,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
1157 1098
1158 mutex_lock(&intel_pstate_driver_lock); 1099 mutex_lock(&intel_pstate_driver_lock);
1159 1100
1160 if (!driver_registered) { 1101 if (!intel_pstate_driver) {
1161 mutex_unlock(&intel_pstate_driver_lock); 1102 mutex_unlock(&intel_pstate_driver_lock);
1162 return -EAGAIN; 1103 return -EAGAIN;
1163 } 1104 }
@@ -1174,6 +1115,15 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
1174 1115
1175 global.no_turbo = clamp_t(int, input, 0, 1); 1116 global.no_turbo = clamp_t(int, input, 0, 1);
1176 1117
1118 if (global.no_turbo) {
1119 struct cpudata *cpu = all_cpu_data[0];
1120 int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate;
1121
1122 /* Squash the global minimum into the permitted range. */
1123 if (global.min_perf_pct > pct)
1124 global.min_perf_pct = pct;
1125 }
1126
1177 mutex_unlock(&intel_pstate_limits_lock); 1127 mutex_unlock(&intel_pstate_limits_lock);
1178 1128
1179 intel_pstate_update_policies(); 1129 intel_pstate_update_policies();
@@ -1195,18 +1145,14 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
1195 1145
1196 mutex_lock(&intel_pstate_driver_lock); 1146 mutex_lock(&intel_pstate_driver_lock);
1197 1147
1198 if (!driver_registered) { 1148 if (!intel_pstate_driver) {
1199 mutex_unlock(&intel_pstate_driver_lock); 1149 mutex_unlock(&intel_pstate_driver_lock);
1200 return -EAGAIN; 1150 return -EAGAIN;
1201 } 1151 }
1202 1152
1203 mutex_lock(&intel_pstate_limits_lock); 1153 mutex_lock(&intel_pstate_limits_lock);
1204 1154
1205 global.max_sysfs_pct = clamp_t(int, input, 0 , 100); 1155 global.max_perf_pct = clamp_t(int, input, global.min_perf_pct, 100);
1206 global.max_perf_pct = min(global.max_policy_pct, global.max_sysfs_pct);
1207 global.max_perf_pct = max(global.min_policy_pct, global.max_perf_pct);
1208 global.max_perf_pct = max(global.min_perf_pct, global.max_perf_pct);
1209 global.max_perf = percent_ext_fp(global.max_perf_pct);
1210 1156
1211 mutex_unlock(&intel_pstate_limits_lock); 1157 mutex_unlock(&intel_pstate_limits_lock);
1212 1158
@@ -1229,18 +1175,15 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
1229 1175
1230 mutex_lock(&intel_pstate_driver_lock); 1176 mutex_lock(&intel_pstate_driver_lock);
1231 1177
1232 if (!driver_registered) { 1178 if (!intel_pstate_driver) {
1233 mutex_unlock(&intel_pstate_driver_lock); 1179 mutex_unlock(&intel_pstate_driver_lock);
1234 return -EAGAIN; 1180 return -EAGAIN;
1235 } 1181 }
1236 1182
1237 mutex_lock(&intel_pstate_limits_lock); 1183 mutex_lock(&intel_pstate_limits_lock);
1238 1184
1239 global.min_sysfs_pct = clamp_t(int, input, 0 , 100); 1185 global.min_perf_pct = clamp_t(int, input,
1240 global.min_perf_pct = max(global.min_policy_pct, global.min_sysfs_pct); 1186 min_perf_pct_min(), global.max_perf_pct);
1241 global.min_perf_pct = min(global.max_policy_pct, global.min_perf_pct);
1242 global.min_perf_pct = min(global.max_perf_pct, global.min_perf_pct);
1243 global.min_perf = percent_ext_fp(global.min_perf_pct);
1244 1187
1245 mutex_unlock(&intel_pstate_limits_lock); 1188 mutex_unlock(&intel_pstate_limits_lock);
1246 1189
@@ -1554,132 +1497,10 @@ static int knl_get_turbo_pstate(void)
1554 return ret; 1497 return ret;
1555} 1498}
1556 1499
1557static struct cpu_defaults core_params = { 1500static int intel_pstate_get_base_pstate(struct cpudata *cpu)
1558 .pid_policy = {
1559 .sample_rate_ms = 10,
1560 .deadband = 0,
1561 .setpoint = 97,
1562 .p_gain_pct = 20,
1563 .d_gain_pct = 0,
1564 .i_gain_pct = 0,
1565 },
1566 .funcs = {
1567 .get_max = core_get_max_pstate,
1568 .get_max_physical = core_get_max_pstate_physical,
1569 .get_min = core_get_min_pstate,
1570 .get_turbo = core_get_turbo_pstate,
1571 .get_scaling = core_get_scaling,
1572 .get_val = core_get_val,
1573 .get_target_pstate = get_target_pstate_use_performance,
1574 },
1575};
1576
1577static const struct cpu_defaults silvermont_params = {
1578 .pid_policy = {
1579 .sample_rate_ms = 10,
1580 .deadband = 0,
1581 .setpoint = 60,
1582 .p_gain_pct = 14,
1583 .d_gain_pct = 0,
1584 .i_gain_pct = 4,
1585 },
1586 .funcs = {
1587 .get_max = atom_get_max_pstate,
1588 .get_max_physical = atom_get_max_pstate,
1589 .get_min = atom_get_min_pstate,
1590 .get_turbo = atom_get_turbo_pstate,
1591 .get_val = atom_get_val,
1592 .get_scaling = silvermont_get_scaling,
1593 .get_vid = atom_get_vid,
1594 .get_target_pstate = get_target_pstate_use_cpu_load,
1595 },
1596};
1597
1598static const struct cpu_defaults airmont_params = {
1599 .pid_policy = {
1600 .sample_rate_ms = 10,
1601 .deadband = 0,
1602 .setpoint = 60,
1603 .p_gain_pct = 14,
1604 .d_gain_pct = 0,
1605 .i_gain_pct = 4,
1606 },
1607 .funcs = {
1608 .get_max = atom_get_max_pstate,
1609 .get_max_physical = atom_get_max_pstate,
1610 .get_min = atom_get_min_pstate,
1611 .get_turbo = atom_get_turbo_pstate,
1612 .get_val = atom_get_val,
1613 .get_scaling = airmont_get_scaling,
1614 .get_vid = atom_get_vid,
1615 .get_target_pstate = get_target_pstate_use_cpu_load,
1616 },
1617};
1618
1619static const struct cpu_defaults knl_params = {
1620 .pid_policy = {
1621 .sample_rate_ms = 10,
1622 .deadband = 0,
1623 .setpoint = 97,
1624 .p_gain_pct = 20,
1625 .d_gain_pct = 0,
1626 .i_gain_pct = 0,
1627 },
1628 .funcs = {
1629 .get_max = core_get_max_pstate,
1630 .get_max_physical = core_get_max_pstate_physical,
1631 .get_min = core_get_min_pstate,
1632 .get_turbo = knl_get_turbo_pstate,
1633 .get_scaling = core_get_scaling,
1634 .get_val = core_get_val,
1635 .get_target_pstate = get_target_pstate_use_performance,
1636 },
1637};
1638
1639static const struct cpu_defaults bxt_params = {
1640 .pid_policy = {
1641 .sample_rate_ms = 10,
1642 .deadband = 0,
1643 .setpoint = 60,
1644 .p_gain_pct = 14,
1645 .d_gain_pct = 0,
1646 .i_gain_pct = 4,
1647 },
1648 .funcs = {
1649 .get_max = core_get_max_pstate,
1650 .get_max_physical = core_get_max_pstate_physical,
1651 .get_min = core_get_min_pstate,
1652 .get_turbo = core_get_turbo_pstate,
1653 .get_scaling = core_get_scaling,
1654 .get_val = core_get_val,
1655 .get_target_pstate = get_target_pstate_use_cpu_load,
1656 },
1657};
1658
1659static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
1660{ 1501{
1661 int max_perf = cpu->pstate.turbo_pstate; 1502 return global.no_turbo || global.turbo_disabled ?
1662 int max_perf_adj; 1503 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
1663 int min_perf;
1664 struct perf_limits *perf_limits = &global;
1665
1666 if (global.no_turbo || global.turbo_disabled)
1667 max_perf = cpu->pstate.max_pstate;
1668
1669 if (per_cpu_limits)
1670 perf_limits = cpu->perf_limits;
1671
1672 /*
1673 * performance can be limited by user through sysfs, by cpufreq
1674 * policy, or by cpu specific default values determined through
1675 * experimentation.
1676 */
1677 max_perf_adj = fp_ext_toint(max_perf * perf_limits->max_perf);
1678 *max = clamp_t(int, max_perf_adj,
1679 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
1680
1681 min_perf = fp_ext_toint(max_perf * perf_limits->min_perf);
1682 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
1683} 1504}
1684 1505
1685static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) 1506static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
@@ -1702,11 +1523,13 @@ static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1702 1523
1703static void intel_pstate_max_within_limits(struct cpudata *cpu) 1524static void intel_pstate_max_within_limits(struct cpudata *cpu)
1704{ 1525{
1705 int min_pstate, max_pstate; 1526 int pstate;
1706 1527
1707 update_turbo_state(); 1528 update_turbo_state();
1708 intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate); 1529 pstate = intel_pstate_get_base_pstate(cpu);
1709 intel_pstate_set_pstate(cpu, max_pstate); 1530 pstate = max(cpu->pstate.min_pstate,
1531 fp_ext_toint(pstate * cpu->max_perf));
1532 intel_pstate_set_pstate(cpu, pstate);
1710} 1533}
1711 1534
1712static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) 1535static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
@@ -1767,7 +1590,11 @@ static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
1767 * that sample.time will always be reset before setting the utilization 1590 * that sample.time will always be reset before setting the utilization
1768 * update hook and make the caller skip the sample then. 1591 * update hook and make the caller skip the sample then.
1769 */ 1592 */
1770 return !!cpu->last_sample_time; 1593 if (cpu->last_sample_time) {
1594 intel_pstate_calc_avg_perf(cpu);
1595 return true;
1596 }
1597 return false;
1771} 1598}
1772 1599
1773static inline int32_t get_avg_frequency(struct cpudata *cpu) 1600static inline int32_t get_avg_frequency(struct cpudata *cpu)
@@ -1788,6 +1615,9 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
1788 int32_t busy_frac, boost; 1615 int32_t busy_frac, boost;
1789 int target, avg_pstate; 1616 int target, avg_pstate;
1790 1617
1618 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE)
1619 return cpu->pstate.turbo_pstate;
1620
1791 busy_frac = div_fp(sample->mperf, sample->tsc); 1621 busy_frac = div_fp(sample->mperf, sample->tsc);
1792 1622
1793 boost = cpu->iowait_boost; 1623 boost = cpu->iowait_boost;
@@ -1824,6 +1654,9 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
1824 int32_t perf_scaled, max_pstate, current_pstate, sample_ratio; 1654 int32_t perf_scaled, max_pstate, current_pstate, sample_ratio;
1825 u64 duration_ns; 1655 u64 duration_ns;
1826 1656
1657 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE)
1658 return cpu->pstate.turbo_pstate;
1659
1827 /* 1660 /*
1828 * perf_scaled is the ratio of the average P-state during the last 1661 * perf_scaled is the ratio of the average P-state during the last
1829 * sampling period to the P-state requested last time (in percent). 1662 * sampling period to the P-state requested last time (in percent).
@@ -1858,11 +1691,13 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
1858 1691
1859static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) 1692static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate)
1860{ 1693{
1861 int max_perf, min_perf; 1694 int max_pstate = intel_pstate_get_base_pstate(cpu);
1695 int min_pstate;
1862 1696
1863 intel_pstate_get_min_max(cpu, &min_perf, &max_perf); 1697 min_pstate = max(cpu->pstate.min_pstate,
1864 pstate = clamp_t(int, pstate, min_perf, max_perf); 1698 fp_ext_toint(max_pstate * cpu->min_perf));
1865 return pstate; 1699 max_pstate = max(min_pstate, fp_ext_toint(max_pstate * cpu->max_perf));
1700 return clamp_t(int, pstate, min_pstate, max_pstate);
1866} 1701}
1867 1702
1868static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) 1703static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate)
@@ -1874,16 +1709,11 @@ static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate)
1874 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); 1709 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate));
1875} 1710}
1876 1711
1877static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) 1712static void intel_pstate_adjust_pstate(struct cpudata *cpu, int target_pstate)
1878{ 1713{
1879 int from, target_pstate; 1714 int from = cpu->pstate.current_pstate;
1880 struct sample *sample; 1715 struct sample *sample;
1881 1716
1882 from = cpu->pstate.current_pstate;
1883
1884 target_pstate = cpu->policy == CPUFREQ_POLICY_PERFORMANCE ?
1885 cpu->pstate.turbo_pstate : pstate_funcs.get_target_pstate(cpu);
1886
1887 update_turbo_state(); 1717 update_turbo_state();
1888 1718
1889 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); 1719 target_pstate = intel_pstate_prepare_request(cpu, target_pstate);
@@ -1902,76 +1732,155 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
1902 fp_toint(cpu->iowait_boost * 100)); 1732 fp_toint(cpu->iowait_boost * 100));
1903} 1733}
1904 1734
1735static void intel_pstate_update_util_hwp(struct update_util_data *data,
1736 u64 time, unsigned int flags)
1737{
1738 struct cpudata *cpu = container_of(data, struct cpudata, update_util);
1739 u64 delta_ns = time - cpu->sample.time;
1740
1741 if ((s64)delta_ns >= INTEL_PSTATE_HWP_SAMPLING_INTERVAL)
1742 intel_pstate_sample(cpu, time);
1743}
1744
1745static void intel_pstate_update_util_pid(struct update_util_data *data,
1746 u64 time, unsigned int flags)
1747{
1748 struct cpudata *cpu = container_of(data, struct cpudata, update_util);
1749 u64 delta_ns = time - cpu->sample.time;
1750
1751 if ((s64)delta_ns < pid_params.sample_rate_ns)
1752 return;
1753
1754 if (intel_pstate_sample(cpu, time)) {
1755 int target_pstate;
1756
1757 target_pstate = get_target_pstate_use_performance(cpu);
1758 intel_pstate_adjust_pstate(cpu, target_pstate);
1759 }
1760}
1761
1905static void intel_pstate_update_util(struct update_util_data *data, u64 time, 1762static void intel_pstate_update_util(struct update_util_data *data, u64 time,
1906 unsigned int flags) 1763 unsigned int flags)
1907{ 1764{
1908 struct cpudata *cpu = container_of(data, struct cpudata, update_util); 1765 struct cpudata *cpu = container_of(data, struct cpudata, update_util);
1909 u64 delta_ns; 1766 u64 delta_ns;
1910 1767
1911 if (pstate_funcs.get_target_pstate == get_target_pstate_use_cpu_load) { 1768 if (flags & SCHED_CPUFREQ_IOWAIT) {
1912 if (flags & SCHED_CPUFREQ_IOWAIT) { 1769 cpu->iowait_boost = int_tofp(1);
1913 cpu->iowait_boost = int_tofp(1); 1770 } else if (cpu->iowait_boost) {
1914 } else if (cpu->iowait_boost) { 1771 /* Clear iowait_boost if the CPU may have been idle. */
1915 /* Clear iowait_boost if the CPU may have been idle. */ 1772 delta_ns = time - cpu->last_update;
1916 delta_ns = time - cpu->last_update; 1773 if (delta_ns > TICK_NSEC)
1917 if (delta_ns > TICK_NSEC) 1774 cpu->iowait_boost = 0;
1918 cpu->iowait_boost = 0;
1919 }
1920 cpu->last_update = time;
1921 } 1775 }
1922 1776 cpu->last_update = time;
1923 delta_ns = time - cpu->sample.time; 1777 delta_ns = time - cpu->sample.time;
1924 if ((s64)delta_ns >= pid_params.sample_rate_ns) { 1778 if ((s64)delta_ns < INTEL_PSTATE_DEFAULT_SAMPLING_INTERVAL)
1925 bool sample_taken = intel_pstate_sample(cpu, time); 1779 return;
1926 1780
1927 if (sample_taken) { 1781 if (intel_pstate_sample(cpu, time)) {
1928 intel_pstate_calc_avg_perf(cpu); 1782 int target_pstate;
1929 if (!hwp_active) 1783
1930 intel_pstate_adjust_busy_pstate(cpu); 1784 target_pstate = get_target_pstate_use_cpu_load(cpu);
1931 } 1785 intel_pstate_adjust_pstate(cpu, target_pstate);
1932 } 1786 }
1933} 1787}
1934 1788
1789static struct pstate_funcs core_funcs = {
1790 .get_max = core_get_max_pstate,
1791 .get_max_physical = core_get_max_pstate_physical,
1792 .get_min = core_get_min_pstate,
1793 .get_turbo = core_get_turbo_pstate,
1794 .get_scaling = core_get_scaling,
1795 .get_val = core_get_val,
1796 .update_util = intel_pstate_update_util_pid,
1797};
1798
1799static const struct pstate_funcs silvermont_funcs = {
1800 .get_max = atom_get_max_pstate,
1801 .get_max_physical = atom_get_max_pstate,
1802 .get_min = atom_get_min_pstate,
1803 .get_turbo = atom_get_turbo_pstate,
1804 .get_val = atom_get_val,
1805 .get_scaling = silvermont_get_scaling,
1806 .get_vid = atom_get_vid,
1807 .update_util = intel_pstate_update_util,
1808};
1809
1810static const struct pstate_funcs airmont_funcs = {
1811 .get_max = atom_get_max_pstate,
1812 .get_max_physical = atom_get_max_pstate,
1813 .get_min = atom_get_min_pstate,
1814 .get_turbo = atom_get_turbo_pstate,
1815 .get_val = atom_get_val,
1816 .get_scaling = airmont_get_scaling,
1817 .get_vid = atom_get_vid,
1818 .update_util = intel_pstate_update_util,
1819};
1820
1821static const struct pstate_funcs knl_funcs = {
1822 .get_max = core_get_max_pstate,
1823 .get_max_physical = core_get_max_pstate_physical,
1824 .get_min = core_get_min_pstate,
1825 .get_turbo = knl_get_turbo_pstate,
1826 .get_scaling = core_get_scaling,
1827 .get_val = core_get_val,
1828 .update_util = intel_pstate_update_util_pid,
1829};
1830
1831static const struct pstate_funcs bxt_funcs = {
1832 .get_max = core_get_max_pstate,
1833 .get_max_physical = core_get_max_pstate_physical,
1834 .get_min = core_get_min_pstate,
1835 .get_turbo = core_get_turbo_pstate,
1836 .get_scaling = core_get_scaling,
1837 .get_val = core_get_val,
1838 .update_util = intel_pstate_update_util,
1839};
1840
1935#define ICPU(model, policy) \ 1841#define ICPU(model, policy) \
1936 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_APERFMPERF,\ 1842 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_APERFMPERF,\
1937 (unsigned long)&policy } 1843 (unsigned long)&policy }
1938 1844
1939static const struct x86_cpu_id intel_pstate_cpu_ids[] = { 1845static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
1940 ICPU(INTEL_FAM6_SANDYBRIDGE, core_params), 1846 ICPU(INTEL_FAM6_SANDYBRIDGE, core_funcs),
1941 ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_params), 1847 ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_funcs),
1942 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_params), 1848 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_funcs),
1943 ICPU(INTEL_FAM6_IVYBRIDGE, core_params), 1849 ICPU(INTEL_FAM6_IVYBRIDGE, core_funcs),
1944 ICPU(INTEL_FAM6_HASWELL_CORE, core_params), 1850 ICPU(INTEL_FAM6_HASWELL_CORE, core_funcs),
1945 ICPU(INTEL_FAM6_BROADWELL_CORE, core_params), 1851 ICPU(INTEL_FAM6_BROADWELL_CORE, core_funcs),
1946 ICPU(INTEL_FAM6_IVYBRIDGE_X, core_params), 1852 ICPU(INTEL_FAM6_IVYBRIDGE_X, core_funcs),
1947 ICPU(INTEL_FAM6_HASWELL_X, core_params), 1853 ICPU(INTEL_FAM6_HASWELL_X, core_funcs),
1948 ICPU(INTEL_FAM6_HASWELL_ULT, core_params), 1854 ICPU(INTEL_FAM6_HASWELL_ULT, core_funcs),
1949 ICPU(INTEL_FAM6_HASWELL_GT3E, core_params), 1855 ICPU(INTEL_FAM6_HASWELL_GT3E, core_funcs),
1950 ICPU(INTEL_FAM6_BROADWELL_GT3E, core_params), 1856 ICPU(INTEL_FAM6_BROADWELL_GT3E, core_funcs),
1951 ICPU(INTEL_FAM6_ATOM_AIRMONT, airmont_params), 1857 ICPU(INTEL_FAM6_ATOM_AIRMONT, airmont_funcs),
1952 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, core_params), 1858 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, core_funcs),
1953 ICPU(INTEL_FAM6_BROADWELL_X, core_params), 1859 ICPU(INTEL_FAM6_BROADWELL_X, core_funcs),
1954 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, core_params), 1860 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, core_funcs),
1955 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params), 1861 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_funcs),
1956 ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_params), 1862 ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_funcs),
1957 ICPU(INTEL_FAM6_XEON_PHI_KNM, knl_params), 1863 ICPU(INTEL_FAM6_XEON_PHI_KNM, knl_funcs),
1958 ICPU(INTEL_FAM6_ATOM_GOLDMONT, bxt_params), 1864 ICPU(INTEL_FAM6_ATOM_GOLDMONT, bxt_funcs),
1865 ICPU(INTEL_FAM6_ATOM_GEMINI_LAKE, bxt_funcs),
1959 {} 1866 {}
1960}; 1867};
1961MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); 1868MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids);
1962 1869
1963static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = { 1870static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = {
1964 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params), 1871 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_funcs),
1965 ICPU(INTEL_FAM6_BROADWELL_X, core_params), 1872 ICPU(INTEL_FAM6_BROADWELL_X, core_funcs),
1966 ICPU(INTEL_FAM6_SKYLAKE_X, core_params), 1873 ICPU(INTEL_FAM6_SKYLAKE_X, core_funcs),
1967 {} 1874 {}
1968}; 1875};
1969 1876
1970static const struct x86_cpu_id intel_pstate_cpu_ee_disable_ids[] = { 1877static const struct x86_cpu_id intel_pstate_cpu_ee_disable_ids[] = {
1971 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, core_params), 1878 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, core_funcs),
1972 {} 1879 {}
1973}; 1880};
1974 1881
1882static bool pid_in_use(void);
1883
1975static int intel_pstate_init_cpu(unsigned int cpunum) 1884static int intel_pstate_init_cpu(unsigned int cpunum)
1976{ 1885{
1977 struct cpudata *cpu; 1886 struct cpudata *cpu;
@@ -1979,18 +1888,11 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
1979 cpu = all_cpu_data[cpunum]; 1888 cpu = all_cpu_data[cpunum];
1980 1889
1981 if (!cpu) { 1890 if (!cpu) {
1982 unsigned int size = sizeof(struct cpudata); 1891 cpu = kzalloc(sizeof(*cpu), GFP_KERNEL);
1983
1984 if (per_cpu_limits)
1985 size += sizeof(struct perf_limits);
1986
1987 cpu = kzalloc(size, GFP_KERNEL);
1988 if (!cpu) 1892 if (!cpu)
1989 return -ENOMEM; 1893 return -ENOMEM;
1990 1894
1991 all_cpu_data[cpunum] = cpu; 1895 all_cpu_data[cpunum] = cpu;
1992 if (per_cpu_limits)
1993 cpu->perf_limits = (struct perf_limits *)(cpu + 1);
1994 1896
1995 cpu->epp_default = -EINVAL; 1897 cpu->epp_default = -EINVAL;
1996 cpu->epp_powersave = -EINVAL; 1898 cpu->epp_powersave = -EINVAL;
@@ -2009,14 +1911,12 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
2009 intel_pstate_disable_ee(cpunum); 1911 intel_pstate_disable_ee(cpunum);
2010 1912
2011 intel_pstate_hwp_enable(cpu); 1913 intel_pstate_hwp_enable(cpu);
2012 pid_params.sample_rate_ms = 50; 1914 } else if (pid_in_use()) {
2013 pid_params.sample_rate_ns = 50 * NSEC_PER_MSEC; 1915 intel_pstate_pid_reset(cpu);
2014 } 1916 }
2015 1917
2016 intel_pstate_get_cpu_pstates(cpu); 1918 intel_pstate_get_cpu_pstates(cpu);
2017 1919
2018 intel_pstate_busy_pid_reset(cpu);
2019
2020 pr_debug("controlling: cpu %d\n", cpunum); 1920 pr_debug("controlling: cpu %d\n", cpunum);
2021 1921
2022 return 0; 1922 return 0;
@@ -2039,7 +1939,7 @@ static void intel_pstate_set_update_util_hook(unsigned int cpu_num)
2039 /* Prevent intel_pstate_update_util() from using stale data. */ 1939 /* Prevent intel_pstate_update_util() from using stale data. */
2040 cpu->sample.time = 0; 1940 cpu->sample.time = 0;
2041 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, 1941 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util,
2042 intel_pstate_update_util); 1942 pstate_funcs.update_util);
2043 cpu->update_util_set = true; 1943 cpu->update_util_set = true;
2044} 1944}
2045 1945
@@ -2055,46 +1955,68 @@ static void intel_pstate_clear_update_util_hook(unsigned int cpu)
2055 synchronize_sched(); 1955 synchronize_sched();
2056} 1956}
2057 1957
1958static int intel_pstate_get_max_freq(struct cpudata *cpu)
1959{
1960 return global.turbo_disabled || global.no_turbo ?
1961 cpu->pstate.max_freq : cpu->pstate.turbo_freq;
1962}
1963
2058static void intel_pstate_update_perf_limits(struct cpufreq_policy *policy, 1964static void intel_pstate_update_perf_limits(struct cpufreq_policy *policy,
2059 struct perf_limits *limits) 1965 struct cpudata *cpu)
2060{ 1966{
1967 int max_freq = intel_pstate_get_max_freq(cpu);
2061 int32_t max_policy_perf, min_policy_perf; 1968 int32_t max_policy_perf, min_policy_perf;
2062 1969
2063 max_policy_perf = div_ext_fp(policy->max, policy->cpuinfo.max_freq); 1970 max_policy_perf = div_ext_fp(policy->max, max_freq);
2064 max_policy_perf = clamp_t(int32_t, max_policy_perf, 0, int_ext_tofp(1)); 1971 max_policy_perf = clamp_t(int32_t, max_policy_perf, 0, int_ext_tofp(1));
2065 if (policy->max == policy->min) { 1972 if (policy->max == policy->min) {
2066 min_policy_perf = max_policy_perf; 1973 min_policy_perf = max_policy_perf;
2067 } else { 1974 } else {
2068 min_policy_perf = div_ext_fp(policy->min, 1975 min_policy_perf = div_ext_fp(policy->min, max_freq);
2069 policy->cpuinfo.max_freq);
2070 min_policy_perf = clamp_t(int32_t, min_policy_perf, 1976 min_policy_perf = clamp_t(int32_t, min_policy_perf,
2071 0, max_policy_perf); 1977 0, max_policy_perf);
2072 } 1978 }
2073 1979
2074 /* Normalize user input to [min_perf, max_perf] */ 1980 /* Normalize user input to [min_perf, max_perf] */
2075 limits->min_perf = max(min_policy_perf, 1981 if (per_cpu_limits) {
2076 percent_ext_fp(limits->min_sysfs_pct)); 1982 cpu->min_perf = min_policy_perf;
2077 limits->min_perf = min(limits->min_perf, max_policy_perf); 1983 cpu->max_perf = max_policy_perf;
2078 limits->max_perf = min(max_policy_perf, 1984 } else {
2079 percent_ext_fp(limits->max_sysfs_pct)); 1985 int32_t global_min, global_max;
2080 limits->max_perf = max(min_policy_perf, limits->max_perf); 1986
1987 /* Global limits are in percent of the maximum turbo P-state. */
1988 global_max = percent_ext_fp(global.max_perf_pct);
1989 global_min = percent_ext_fp(global.min_perf_pct);
1990 if (max_freq != cpu->pstate.turbo_freq) {
1991 int32_t turbo_factor;
1992
1993 turbo_factor = div_ext_fp(cpu->pstate.turbo_pstate,
1994 cpu->pstate.max_pstate);
1995 global_min = mul_ext_fp(global_min, turbo_factor);
1996 global_max = mul_ext_fp(global_max, turbo_factor);
1997 }
1998 global_min = clamp_t(int32_t, global_min, 0, global_max);
1999
2000 cpu->min_perf = max(min_policy_perf, global_min);
2001 cpu->min_perf = min(cpu->min_perf, max_policy_perf);
2002 cpu->max_perf = min(max_policy_perf, global_max);
2003 cpu->max_perf = max(min_policy_perf, cpu->max_perf);
2081 2004
2082 /* Make sure min_perf <= max_perf */ 2005 /* Make sure min_perf <= max_perf */
2083 limits->min_perf = min(limits->min_perf, limits->max_perf); 2006 cpu->min_perf = min(cpu->min_perf, cpu->max_perf);
2007 }
2084 2008
2085 limits->max_perf = round_up(limits->max_perf, EXT_FRAC_BITS); 2009 cpu->max_perf = round_up(cpu->max_perf, EXT_FRAC_BITS);
2086 limits->min_perf = round_up(limits->min_perf, EXT_FRAC_BITS); 2010 cpu->min_perf = round_up(cpu->min_perf, EXT_FRAC_BITS);
2087 limits->max_perf_pct = fp_ext_toint(limits->max_perf * 100);
2088 limits->min_perf_pct = fp_ext_toint(limits->min_perf * 100);
2089 2011
2090 pr_debug("cpu:%d max_perf_pct:%d min_perf_pct:%d\n", policy->cpu, 2012 pr_debug("cpu:%d max_perf_pct:%d min_perf_pct:%d\n", policy->cpu,
2091 limits->max_perf_pct, limits->min_perf_pct); 2013 fp_ext_toint(cpu->max_perf * 100),
2014 fp_ext_toint(cpu->min_perf * 100));
2092} 2015}
2093 2016
2094static int intel_pstate_set_policy(struct cpufreq_policy *policy) 2017static int intel_pstate_set_policy(struct cpufreq_policy *policy)
2095{ 2018{
2096 struct cpudata *cpu; 2019 struct cpudata *cpu;
2097 struct perf_limits *perf_limits = &global;
2098 2020
2099 if (!policy->cpuinfo.max_freq) 2021 if (!policy->cpuinfo.max_freq)
2100 return -ENODEV; 2022 return -ENODEV;
@@ -2105,19 +2027,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
2105 cpu = all_cpu_data[policy->cpu]; 2027 cpu = all_cpu_data[policy->cpu];
2106 cpu->policy = policy->policy; 2028 cpu->policy = policy->policy;
2107 2029
2108 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
2109 policy->max < policy->cpuinfo.max_freq &&
2110 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {
2111 pr_debug("policy->max > max non turbo frequency\n");
2112 policy->max = policy->cpuinfo.max_freq;
2113 }
2114
2115 if (per_cpu_limits)
2116 perf_limits = cpu->perf_limits;
2117
2118 mutex_lock(&intel_pstate_limits_lock); 2030 mutex_lock(&intel_pstate_limits_lock);
2119 2031
2120 intel_pstate_update_perf_limits(policy, perf_limits); 2032 intel_pstate_update_perf_limits(policy, cpu);
2121 2033
2122 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { 2034 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
2123 /* 2035 /*
@@ -2130,38 +2042,38 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
2130 2042
2131 intel_pstate_set_update_util_hook(policy->cpu); 2043 intel_pstate_set_update_util_hook(policy->cpu);
2132 2044
2133 intel_pstate_hwp_set_policy(policy); 2045 if (hwp_active)
2046 intel_pstate_hwp_set(policy->cpu);
2134 2047
2135 mutex_unlock(&intel_pstate_limits_lock); 2048 mutex_unlock(&intel_pstate_limits_lock);
2136 2049
2137 return 0; 2050 return 0;
2138} 2051}
2139 2052
2053static void intel_pstate_adjust_policy_max(struct cpufreq_policy *policy,
2054 struct cpudata *cpu)
2055{
2056 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
2057 policy->max < policy->cpuinfo.max_freq &&
2058 policy->max > cpu->pstate.max_freq) {
2059 pr_debug("policy->max > max non turbo frequency\n");
2060 policy->max = policy->cpuinfo.max_freq;
2061 }
2062}
2063
2140static int intel_pstate_verify_policy(struct cpufreq_policy *policy) 2064static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
2141{ 2065{
2142 struct cpudata *cpu = all_cpu_data[policy->cpu]; 2066 struct cpudata *cpu = all_cpu_data[policy->cpu];
2143 2067
2144 update_turbo_state(); 2068 update_turbo_state();
2145 policy->cpuinfo.max_freq = global.turbo_disabled || global.no_turbo ? 2069 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
2146 cpu->pstate.max_freq : 2070 intel_pstate_get_max_freq(cpu));
2147 cpu->pstate.turbo_freq;
2148
2149 cpufreq_verify_within_cpu_limits(policy);
2150 2071
2151 if (policy->policy != CPUFREQ_POLICY_POWERSAVE && 2072 if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
2152 policy->policy != CPUFREQ_POLICY_PERFORMANCE) 2073 policy->policy != CPUFREQ_POLICY_PERFORMANCE)
2153 return -EINVAL; 2074 return -EINVAL;
2154 2075
2155 /* When per-CPU limits are used, sysfs limits are not used */ 2076 intel_pstate_adjust_policy_max(policy, cpu);
2156 if (!per_cpu_limits) {
2157 unsigned int max_freq, min_freq;
2158
2159 max_freq = policy->cpuinfo.max_freq *
2160 global.max_sysfs_pct / 100;
2161 min_freq = policy->cpuinfo.max_freq *
2162 global.min_sysfs_pct / 100;
2163 cpufreq_verify_within_limits(policy, min_freq, max_freq);
2164 }
2165 2077
2166 return 0; 2078 return 0;
2167} 2079}
@@ -2202,8 +2114,8 @@ static int __intel_pstate_cpu_init(struct cpufreq_policy *policy)
2202 2114
2203 cpu = all_cpu_data[policy->cpu]; 2115 cpu = all_cpu_data[policy->cpu];
2204 2116
2205 if (per_cpu_limits) 2117 cpu->max_perf = int_ext_tofp(1);
2206 intel_pstate_init_limits(cpu->perf_limits); 2118 cpu->min_perf = 0;
2207 2119
2208 policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; 2120 policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling;
2209 policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; 2121 policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
@@ -2257,10 +2169,12 @@ static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy)
2257 struct cpudata *cpu = all_cpu_data[policy->cpu]; 2169 struct cpudata *cpu = all_cpu_data[policy->cpu];
2258 2170
2259 update_turbo_state(); 2171 update_turbo_state();
2260 policy->cpuinfo.max_freq = global.no_turbo || global.turbo_disabled ? 2172 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
2261 cpu->pstate.max_freq : cpu->pstate.turbo_freq; 2173 intel_pstate_get_max_freq(cpu));
2262 2174
2263 cpufreq_verify_within_cpu_limits(policy); 2175 intel_pstate_adjust_policy_max(policy, cpu);
2176
2177 intel_pstate_update_perf_limits(policy, cpu);
2264 2178
2265 return 0; 2179 return 0;
2266} 2180}
@@ -2324,6 +2238,7 @@ static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy)
2324 return ret; 2238 return ret;
2325 2239
2326 policy->cpuinfo.transition_latency = INTEL_CPUFREQ_TRANSITION_LATENCY; 2240 policy->cpuinfo.transition_latency = INTEL_CPUFREQ_TRANSITION_LATENCY;
2241 policy->transition_delay_us = INTEL_CPUFREQ_TRANSITION_DELAY;
2327 /* This reflects the intel_pstate_get_cpu_pstates() setting. */ 2242 /* This reflects the intel_pstate_get_cpu_pstates() setting. */
2328 policy->cur = policy->cpuinfo.min_freq; 2243 policy->cur = policy->cpuinfo.min_freq;
2329 2244
@@ -2341,7 +2256,13 @@ static struct cpufreq_driver intel_cpufreq = {
2341 .name = "intel_cpufreq", 2256 .name = "intel_cpufreq",
2342}; 2257};
2343 2258
2344static struct cpufreq_driver *intel_pstate_driver = &intel_pstate; 2259static struct cpufreq_driver *default_driver = &intel_pstate;
2260
2261static bool pid_in_use(void)
2262{
2263 return intel_pstate_driver == &intel_pstate &&
2264 pstate_funcs.update_util == intel_pstate_update_util_pid;
2265}
2345 2266
2346static void intel_pstate_driver_cleanup(void) 2267static void intel_pstate_driver_cleanup(void)
2347{ 2268{
@@ -2358,26 +2279,26 @@ static void intel_pstate_driver_cleanup(void)
2358 } 2279 }
2359 } 2280 }
2360 put_online_cpus(); 2281 put_online_cpus();
2282 intel_pstate_driver = NULL;
2361} 2283}
2362 2284
2363static int intel_pstate_register_driver(void) 2285static int intel_pstate_register_driver(struct cpufreq_driver *driver)
2364{ 2286{
2365 int ret; 2287 int ret;
2366 2288
2367 intel_pstate_init_limits(&global); 2289 memset(&global, 0, sizeof(global));
2290 global.max_perf_pct = 100;
2368 2291
2292 intel_pstate_driver = driver;
2369 ret = cpufreq_register_driver(intel_pstate_driver); 2293 ret = cpufreq_register_driver(intel_pstate_driver);
2370 if (ret) { 2294 if (ret) {
2371 intel_pstate_driver_cleanup(); 2295 intel_pstate_driver_cleanup();
2372 return ret; 2296 return ret;
2373 } 2297 }
2374 2298
2375 mutex_lock(&intel_pstate_limits_lock); 2299 global.min_perf_pct = min_perf_pct_min();
2376 driver_registered = true;
2377 mutex_unlock(&intel_pstate_limits_lock);
2378 2300
2379 if (intel_pstate_driver == &intel_pstate && !hwp_active && 2301 if (pid_in_use())
2380 pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load)
2381 intel_pstate_debug_expose_params(); 2302 intel_pstate_debug_expose_params();
2382 2303
2383 return 0; 2304 return 0;
@@ -2388,14 +2309,9 @@ static int intel_pstate_unregister_driver(void)
2388 if (hwp_active) 2309 if (hwp_active)
2389 return -EBUSY; 2310 return -EBUSY;
2390 2311
2391 if (intel_pstate_driver == &intel_pstate && !hwp_active && 2312 if (pid_in_use())
2392 pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load)
2393 intel_pstate_debug_hide_params(); 2313 intel_pstate_debug_hide_params();
2394 2314
2395 mutex_lock(&intel_pstate_limits_lock);
2396 driver_registered = false;
2397 mutex_unlock(&intel_pstate_limits_lock);
2398
2399 cpufreq_unregister_driver(intel_pstate_driver); 2315 cpufreq_unregister_driver(intel_pstate_driver);
2400 intel_pstate_driver_cleanup(); 2316 intel_pstate_driver_cleanup();
2401 2317
@@ -2404,7 +2320,7 @@ static int intel_pstate_unregister_driver(void)
2404 2320
2405static ssize_t intel_pstate_show_status(char *buf) 2321static ssize_t intel_pstate_show_status(char *buf)
2406{ 2322{
2407 if (!driver_registered) 2323 if (!intel_pstate_driver)
2408 return sprintf(buf, "off\n"); 2324 return sprintf(buf, "off\n");
2409 2325
2410 return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ? 2326 return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ?
@@ -2416,11 +2332,11 @@ static int intel_pstate_update_status(const char *buf, size_t size)
2416 int ret; 2332 int ret;
2417 2333
2418 if (size == 3 && !strncmp(buf, "off", size)) 2334 if (size == 3 && !strncmp(buf, "off", size))
2419 return driver_registered ? 2335 return intel_pstate_driver ?
2420 intel_pstate_unregister_driver() : -EINVAL; 2336 intel_pstate_unregister_driver() : -EINVAL;
2421 2337
2422 if (size == 6 && !strncmp(buf, "active", size)) { 2338 if (size == 6 && !strncmp(buf, "active", size)) {
2423 if (driver_registered) { 2339 if (intel_pstate_driver) {
2424 if (intel_pstate_driver == &intel_pstate) 2340 if (intel_pstate_driver == &intel_pstate)
2425 return 0; 2341 return 0;
2426 2342
@@ -2429,13 +2345,12 @@ static int intel_pstate_update_status(const char *buf, size_t size)
2429 return ret; 2345 return ret;
2430 } 2346 }
2431 2347
2432 intel_pstate_driver = &intel_pstate; 2348 return intel_pstate_register_driver(&intel_pstate);
2433 return intel_pstate_register_driver();
2434 } 2349 }
2435 2350
2436 if (size == 7 && !strncmp(buf, "passive", size)) { 2351 if (size == 7 && !strncmp(buf, "passive", size)) {
2437 if (driver_registered) { 2352 if (intel_pstate_driver) {
2438 if (intel_pstate_driver != &intel_pstate) 2353 if (intel_pstate_driver == &intel_cpufreq)
2439 return 0; 2354 return 0;
2440 2355
2441 ret = intel_pstate_unregister_driver(); 2356 ret = intel_pstate_unregister_driver();
@@ -2443,8 +2358,7 @@ static int intel_pstate_update_status(const char *buf, size_t size)
2443 return ret; 2358 return ret;
2444 } 2359 }
2445 2360
2446 intel_pstate_driver = &intel_cpufreq; 2361 return intel_pstate_register_driver(&intel_cpufreq);
2447 return intel_pstate_register_driver();
2448 } 2362 }
2449 2363
2450 return -EINVAL; 2364 return -EINVAL;
@@ -2465,23 +2379,17 @@ static int __init intel_pstate_msrs_not_valid(void)
2465 return 0; 2379 return 0;
2466} 2380}
2467 2381
2468static void __init copy_pid_params(struct pstate_adjust_policy *policy)
2469{
2470 pid_params.sample_rate_ms = policy->sample_rate_ms;
2471 pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC;
2472 pid_params.p_gain_pct = policy->p_gain_pct;
2473 pid_params.i_gain_pct = policy->i_gain_pct;
2474 pid_params.d_gain_pct = policy->d_gain_pct;
2475 pid_params.deadband = policy->deadband;
2476 pid_params.setpoint = policy->setpoint;
2477}
2478
2479#ifdef CONFIG_ACPI 2382#ifdef CONFIG_ACPI
2480static void intel_pstate_use_acpi_profile(void) 2383static void intel_pstate_use_acpi_profile(void)
2481{ 2384{
2482 if (acpi_gbl_FADT.preferred_profile == PM_MOBILE) 2385 switch (acpi_gbl_FADT.preferred_profile) {
2483 pstate_funcs.get_target_pstate = 2386 case PM_MOBILE:
2484 get_target_pstate_use_cpu_load; 2387 case PM_TABLET:
2388 case PM_APPLIANCE_PC:
2389 case PM_DESKTOP:
2390 case PM_WORKSTATION:
2391 pstate_funcs.update_util = intel_pstate_update_util;
2392 }
2485} 2393}
2486#else 2394#else
2487static void intel_pstate_use_acpi_profile(void) 2395static void intel_pstate_use_acpi_profile(void)
@@ -2498,7 +2406,7 @@ static void __init copy_cpu_funcs(struct pstate_funcs *funcs)
2498 pstate_funcs.get_scaling = funcs->get_scaling; 2406 pstate_funcs.get_scaling = funcs->get_scaling;
2499 pstate_funcs.get_val = funcs->get_val; 2407 pstate_funcs.get_val = funcs->get_val;
2500 pstate_funcs.get_vid = funcs->get_vid; 2408 pstate_funcs.get_vid = funcs->get_vid;
2501 pstate_funcs.get_target_pstate = funcs->get_target_pstate; 2409 pstate_funcs.update_util = funcs->update_util;
2502 2410
2503 intel_pstate_use_acpi_profile(); 2411 intel_pstate_use_acpi_profile();
2504} 2412}
@@ -2637,28 +2545,30 @@ static const struct x86_cpu_id hwp_support_ids[] __initconst = {
2637 2545
2638static int __init intel_pstate_init(void) 2546static int __init intel_pstate_init(void)
2639{ 2547{
2640 const struct x86_cpu_id *id; 2548 int rc;
2641 struct cpu_defaults *cpu_def;
2642 int rc = 0;
2643 2549
2644 if (no_load) 2550 if (no_load)
2645 return -ENODEV; 2551 return -ENODEV;
2646 2552
2647 if (x86_match_cpu(hwp_support_ids) && !no_hwp) { 2553 if (x86_match_cpu(hwp_support_ids)) {
2648 copy_cpu_funcs(&core_params.funcs); 2554 copy_cpu_funcs(&core_funcs);
2649 hwp_active++; 2555 if (no_hwp) {
2650 intel_pstate.attr = hwp_cpufreq_attrs; 2556 pstate_funcs.update_util = intel_pstate_update_util;
2651 goto hwp_cpu_matched; 2557 } else {
2652 } 2558 hwp_active++;
2653 2559 intel_pstate.attr = hwp_cpufreq_attrs;
2654 id = x86_match_cpu(intel_pstate_cpu_ids); 2560 pstate_funcs.update_util = intel_pstate_update_util_hwp;
2655 if (!id) 2561 goto hwp_cpu_matched;
2656 return -ENODEV; 2562 }
2563 } else {
2564 const struct x86_cpu_id *id;
2657 2565
2658 cpu_def = (struct cpu_defaults *)id->driver_data; 2566 id = x86_match_cpu(intel_pstate_cpu_ids);
2567 if (!id)
2568 return -ENODEV;
2659 2569
2660 copy_pid_params(&cpu_def->pid_policy); 2570 copy_cpu_funcs((struct pstate_funcs *)id->driver_data);
2661 copy_cpu_funcs(&cpu_def->funcs); 2571 }
2662 2572
2663 if (intel_pstate_msrs_not_valid()) 2573 if (intel_pstate_msrs_not_valid())
2664 return -ENODEV; 2574 return -ENODEV;
@@ -2685,7 +2595,7 @@ hwp_cpu_matched:
2685 intel_pstate_sysfs_expose_params(); 2595 intel_pstate_sysfs_expose_params();
2686 2596
2687 mutex_lock(&intel_pstate_driver_lock); 2597 mutex_lock(&intel_pstate_driver_lock);
2688 rc = intel_pstate_register_driver(); 2598 rc = intel_pstate_register_driver(default_driver);
2689 mutex_unlock(&intel_pstate_driver_lock); 2599 mutex_unlock(&intel_pstate_driver_lock);
2690 if (rc) 2600 if (rc)
2691 return rc; 2601 return rc;
@@ -2706,7 +2616,7 @@ static int __init intel_pstate_setup(char *str)
2706 no_load = 1; 2616 no_load = 1;
2707 } else if (!strcmp(str, "passive")) { 2617 } else if (!strcmp(str, "passive")) {
2708 pr_info("Passive mode enabled\n"); 2618 pr_info("Passive mode enabled\n");
2709 intel_pstate_driver = &intel_cpufreq; 2619 default_driver = &intel_cpufreq;
2710 no_hwp = 1; 2620 no_hwp = 1;
2711 } 2621 }
2712 if (!strcmp(str, "no_hwp")) { 2622 if (!strcmp(str, "no_hwp")) {
diff --git a/drivers/cpufreq/mt8173-cpufreq.c b/drivers/cpufreq/mt8173-cpufreq.c
index ab25b1235a5e..fd1886faf33a 100644
--- a/drivers/cpufreq/mt8173-cpufreq.c
+++ b/drivers/cpufreq/mt8173-cpufreq.c
@@ -573,14 +573,33 @@ static struct platform_driver mt8173_cpufreq_platdrv = {
573 .probe = mt8173_cpufreq_probe, 573 .probe = mt8173_cpufreq_probe,
574}; 574};
575 575
576static int mt8173_cpufreq_driver_init(void) 576/* List of machines supported by this driver */
577static const struct of_device_id mt8173_cpufreq_machines[] __initconst = {
578 { .compatible = "mediatek,mt817x", },
579 { .compatible = "mediatek,mt8173", },
580 { .compatible = "mediatek,mt8176", },
581
582 { }
583};
584
585static int __init mt8173_cpufreq_driver_init(void)
577{ 586{
587 struct device_node *np;
588 const struct of_device_id *match;
578 struct platform_device *pdev; 589 struct platform_device *pdev;
579 int err; 590 int err;
580 591
581 if (!of_machine_is_compatible("mediatek,mt8173")) 592 np = of_find_node_by_path("/");
593 if (!np)
582 return -ENODEV; 594 return -ENODEV;
583 595
596 match = of_match_node(mt8173_cpufreq_machines, np);
597 of_node_put(np);
598 if (!match) {
599 pr_warn("Machine is not compatible with mt8173-cpufreq\n");
600 return -ENODEV;
601 }
602
584 err = platform_driver_register(&mt8173_cpufreq_platdrv); 603 err = platform_driver_register(&mt8173_cpufreq_platdrv);
585 if (err) 604 if (err)
586 return err; 605 return err;
diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index bfec1bcd3835..e2ea433a5f9c 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -52,17 +52,27 @@ static u32 get_bus_freq(void)
52{ 52{
53 struct device_node *soc; 53 struct device_node *soc;
54 u32 sysfreq; 54 u32 sysfreq;
55 struct clk *pltclk;
56 int ret;
55 57
58 /* get platform freq by searching bus-frequency property */
56 soc = of_find_node_by_type(NULL, "soc"); 59 soc = of_find_node_by_type(NULL, "soc");
57 if (!soc) 60 if (soc) {
58 return 0; 61 ret = of_property_read_u32(soc, "bus-frequency", &sysfreq);
59 62 of_node_put(soc);
60 if (of_property_read_u32(soc, "bus-frequency", &sysfreq)) 63 if (!ret)
61 sysfreq = 0; 64 return sysfreq;
65 }
62 66
63 of_node_put(soc); 67 /* get platform freq by its clock name */
68 pltclk = clk_get(NULL, "cg-pll0-div1");
69 if (IS_ERR(pltclk)) {
70 pr_err("%s: can't get bus frequency %ld\n",
71 __func__, PTR_ERR(pltclk));
72 return PTR_ERR(pltclk);
73 }
64 74
65 return sysfreq; 75 return clk_get_rate(pltclk);
66} 76}
67 77
68static struct clk *cpu_to_clk(int cpu) 78static struct clk *cpu_to_clk(int cpu)
diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
new file mode 100644
index 000000000000..fe7875311d62
--- /dev/null
+++ b/drivers/cpufreq/tegra186-cpufreq.c
@@ -0,0 +1,275 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 */
13
14#include <linux/cpufreq.h>
15#include <linux/dma-mapping.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/platform_device.h>
19
20#include <soc/tegra/bpmp.h>
21#include <soc/tegra/bpmp-abi.h>
22
23#define EDVD_CORE_VOLT_FREQ(core) (0x20 + (core) * 0x4)
24#define EDVD_CORE_VOLT_FREQ_F_SHIFT 0
25#define EDVD_CORE_VOLT_FREQ_V_SHIFT 16
26
27struct tegra186_cpufreq_cluster_info {
28 unsigned long offset;
29 int cpus[4];
30 unsigned int bpmp_cluster_id;
31};
32
33#define NO_CPU -1
34static const struct tegra186_cpufreq_cluster_info tegra186_clusters[] = {
35 /* Denver cluster */
36 {
37 .offset = SZ_64K * 7,
38 .cpus = { 1, 2, NO_CPU, NO_CPU },
39 .bpmp_cluster_id = 0,
40 },
41 /* A57 cluster */
42 {
43 .offset = SZ_64K * 6,
44 .cpus = { 0, 3, 4, 5 },
45 .bpmp_cluster_id = 1,
46 },
47};
48
49struct tegra186_cpufreq_cluster {
50 const struct tegra186_cpufreq_cluster_info *info;
51 struct cpufreq_frequency_table *table;
52};
53
54struct tegra186_cpufreq_data {
55 void __iomem *regs;
56
57 size_t num_clusters;
58 struct tegra186_cpufreq_cluster *clusters;
59};
60
61static int tegra186_cpufreq_init(struct cpufreq_policy *policy)
62{
63 struct tegra186_cpufreq_data *data = cpufreq_get_driver_data();
64 unsigned int i;
65
66 for (i = 0; i < data->num_clusters; i++) {
67 struct tegra186_cpufreq_cluster *cluster = &data->clusters[i];
68 const struct tegra186_cpufreq_cluster_info *info =
69 cluster->info;
70 int core;
71
72 for (core = 0; core < ARRAY_SIZE(info->cpus); core++) {
73 if (info->cpus[core] == policy->cpu)
74 break;
75 }
76 if (core == ARRAY_SIZE(info->cpus))
77 continue;
78
79 policy->driver_data =
80 data->regs + info->offset + EDVD_CORE_VOLT_FREQ(core);
81 cpufreq_table_validate_and_show(policy, cluster->table);
82 }
83
84 policy->cpuinfo.transition_latency = 300 * 1000;
85
86 return 0;
87}
88
89static int tegra186_cpufreq_set_target(struct cpufreq_policy *policy,
90 unsigned int index)
91{
92 struct cpufreq_frequency_table *tbl = policy->freq_table + index;
93 void __iomem *edvd_reg = policy->driver_data;
94 u32 edvd_val = tbl->driver_data;
95
96 writel(edvd_val, edvd_reg);
97
98 return 0;
99}
100
101static struct cpufreq_driver tegra186_cpufreq_driver = {
102 .name = "tegra186",
103 .flags = CPUFREQ_STICKY | CPUFREQ_HAVE_GOVERNOR_PER_POLICY,
104 .verify = cpufreq_generic_frequency_table_verify,
105 .target_index = tegra186_cpufreq_set_target,
106 .init = tegra186_cpufreq_init,
107 .attr = cpufreq_generic_attr,
108};
109
110static struct cpufreq_frequency_table *init_vhint_table(
111 struct platform_device *pdev, struct tegra_bpmp *bpmp,
112 unsigned int cluster_id)
113{
114 struct cpufreq_frequency_table *table;
115 struct mrq_cpu_vhint_request req;
116 struct tegra_bpmp_message msg;
117 struct cpu_vhint_data *data;
118 int err, i, j, num_rates = 0;
119 dma_addr_t phys;
120 void *virt;
121
122 virt = dma_alloc_coherent(bpmp->dev, sizeof(*data), &phys,
123 GFP_KERNEL | GFP_DMA32);
124 if (!virt)
125 return ERR_PTR(-ENOMEM);
126
127 data = (struct cpu_vhint_data *)virt;
128
129 memset(&req, 0, sizeof(req));
130 req.addr = phys;
131 req.cluster_id = cluster_id;
132
133 memset(&msg, 0, sizeof(msg));
134 msg.mrq = MRQ_CPU_VHINT;
135 msg.tx.data = &req;
136 msg.tx.size = sizeof(req);
137
138 err = tegra_bpmp_transfer(bpmp, &msg);
139 if (err) {
140 table = ERR_PTR(err);
141 goto free;
142 }
143
144 for (i = data->vfloor; i <= data->vceil; i++) {
145 u16 ndiv = data->ndiv[i];
146
147 if (ndiv < data->ndiv_min || ndiv > data->ndiv_max)
148 continue;
149
150 /* Only store lowest voltage index for each rate */
151 if (i > 0 && ndiv == data->ndiv[i - 1])
152 continue;
153
154 num_rates++;
155 }
156
157 table = devm_kcalloc(&pdev->dev, num_rates + 1, sizeof(*table),
158 GFP_KERNEL);
159 if (!table) {
160 table = ERR_PTR(-ENOMEM);
161 goto free;
162 }
163
164 for (i = data->vfloor, j = 0; i <= data->vceil; i++) {
165 struct cpufreq_frequency_table *point;
166 u16 ndiv = data->ndiv[i];
167 u32 edvd_val = 0;
168
169 if (ndiv < data->ndiv_min || ndiv > data->ndiv_max)
170 continue;
171
172 /* Only store lowest voltage index for each rate */
173 if (i > 0 && ndiv == data->ndiv[i - 1])
174 continue;
175
176 edvd_val |= i << EDVD_CORE_VOLT_FREQ_V_SHIFT;
177 edvd_val |= ndiv << EDVD_CORE_VOLT_FREQ_F_SHIFT;
178
179 point = &table[j++];
180 point->driver_data = edvd_val;
181 point->frequency = data->ref_clk_hz * ndiv / data->pdiv /
182 data->mdiv / 1000;
183 }
184
185 table[j].frequency = CPUFREQ_TABLE_END;
186
187free:
188 dma_free_coherent(bpmp->dev, sizeof(*data), virt, phys);
189
190 return table;
191}
192
193static int tegra186_cpufreq_probe(struct platform_device *pdev)
194{
195 struct tegra186_cpufreq_data *data;
196 struct tegra_bpmp *bpmp;
197 struct resource *res;
198 unsigned int i = 0, err;
199
200 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
201 if (!data)
202 return -ENOMEM;
203
204 data->clusters = devm_kcalloc(&pdev->dev, ARRAY_SIZE(tegra186_clusters),
205 sizeof(*data->clusters), GFP_KERNEL);
206 if (!data->clusters)
207 return -ENOMEM;
208
209 data->num_clusters = ARRAY_SIZE(tegra186_clusters);
210
211 bpmp = tegra_bpmp_get(&pdev->dev);
212 if (IS_ERR(bpmp))
213 return PTR_ERR(bpmp);
214
215 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
216 data->regs = devm_ioremap_resource(&pdev->dev, res);
217 if (IS_ERR(data->regs)) {
218 err = PTR_ERR(data->regs);
219 goto put_bpmp;
220 }
221
222 for (i = 0; i < data->num_clusters; i++) {
223 struct tegra186_cpufreq_cluster *cluster = &data->clusters[i];
224
225 cluster->info = &tegra186_clusters[i];
226 cluster->table = init_vhint_table(
227 pdev, bpmp, cluster->info->bpmp_cluster_id);
228 if (IS_ERR(cluster->table)) {
229 err = PTR_ERR(cluster->table);
230 goto put_bpmp;
231 }
232 }
233
234 tegra_bpmp_put(bpmp);
235
236 tegra186_cpufreq_driver.driver_data = data;
237
238 err = cpufreq_register_driver(&tegra186_cpufreq_driver);
239 if (err)
240 return err;
241
242 return 0;
243
244put_bpmp:
245 tegra_bpmp_put(bpmp);
246
247 return err;
248}
249
250static int tegra186_cpufreq_remove(struct platform_device *pdev)
251{
252 cpufreq_unregister_driver(&tegra186_cpufreq_driver);
253
254 return 0;
255}
256
257static const struct of_device_id tegra186_cpufreq_of_match[] = {
258 { .compatible = "nvidia,tegra186-ccplex-cluster", },
259 { }
260};
261MODULE_DEVICE_TABLE(of, tegra186_cpufreq_of_match);
262
263static struct platform_driver tegra186_cpufreq_platform_driver = {
264 .driver = {
265 .name = "tegra186-cpufreq",
266 .of_match_table = tegra186_cpufreq_of_match,
267 },
268 .probe = tegra186_cpufreq_probe,
269 .remove = tegra186_cpufreq_remove,
270};
271module_platform_driver(tegra186_cpufreq_platform_driver);
272
273MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
274MODULE_DESCRIPTION("NVIDIA Tegra186 cpufreq driver");
275MODULE_LICENSE("GPL v2");
diff --git a/drivers/cpuidle/cpuidle-cps.c b/drivers/cpuidle/cpuidle-cps.c
index 926ba9871c62..12b9145913de 100644
--- a/drivers/cpuidle/cpuidle-cps.c
+++ b/drivers/cpuidle/cpuidle-cps.c
@@ -118,7 +118,7 @@ static void __init cps_cpuidle_unregister(void)
118 118
119static int __init cps_cpuidle_init(void) 119static int __init cps_cpuidle_init(void)
120{ 120{
121 int err, cpu, core, i; 121 int err, cpu, i;
122 struct cpuidle_device *device; 122 struct cpuidle_device *device;
123 123
124 /* Detect supported states */ 124 /* Detect supported states */
@@ -160,7 +160,6 @@ static int __init cps_cpuidle_init(void)
160 } 160 }
161 161
162 for_each_possible_cpu(cpu) { 162 for_each_possible_cpu(cpu) {
163 core = cpu_data[cpu].core;
164 device = &per_cpu(cpuidle_dev, cpu); 163 device = &per_cpu(cpuidle_dev, cpu);
165 device->cpu = cpu; 164 device->cpu = cpu;
166#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED 165#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index cda8f62d555b..12409a519cc5 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -56,10 +56,9 @@ static int snooze_loop(struct cpuidle_device *dev,
56 56
57 snooze_exit_time = get_tb() + snooze_timeout; 57 snooze_exit_time = get_tb() + snooze_timeout;
58 ppc64_runlatch_off(); 58 ppc64_runlatch_off();
59 HMT_very_low();
59 while (!need_resched()) { 60 while (!need_resched()) {
60 HMT_low(); 61 if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time)
61 HMT_very_low();
62 if (snooze_timeout_en && get_tb() > snooze_exit_time)
63 break; 62 break;
64 } 63 }
65 64
@@ -215,11 +214,25 @@ static inline void add_powernv_state(int index, const char *name,
215 stop_psscr_table[index].mask = psscr_mask; 214 stop_psscr_table[index].mask = psscr_mask;
216} 215}
217 216
217/*
218 * Returns 0 if prop1_len == prop2_len. Else returns -1
219 */
220static inline int validate_dt_prop_sizes(const char *prop1, int prop1_len,
221 const char *prop2, int prop2_len)
222{
223 if (prop1_len == prop2_len)
224 return 0;
225
226 pr_warn("cpuidle-powernv: array sizes don't match for %s and %s\n",
227 prop1, prop2);
228 return -1;
229}
230
218static int powernv_add_idle_states(void) 231static int powernv_add_idle_states(void)
219{ 232{
220 struct device_node *power_mgt; 233 struct device_node *power_mgt;
221 int nr_idle_states = 1; /* Snooze */ 234 int nr_idle_states = 1; /* Snooze */
222 int dt_idle_states; 235 int dt_idle_states, count;
223 u32 latency_ns[CPUIDLE_STATE_MAX]; 236 u32 latency_ns[CPUIDLE_STATE_MAX];
224 u32 residency_ns[CPUIDLE_STATE_MAX]; 237 u32 residency_ns[CPUIDLE_STATE_MAX];
225 u32 flags[CPUIDLE_STATE_MAX]; 238 u32 flags[CPUIDLE_STATE_MAX];
@@ -244,6 +257,21 @@ static int powernv_add_idle_states(void)
244 goto out; 257 goto out;
245 } 258 }
246 259
260 count = of_property_count_u32_elems(power_mgt,
261 "ibm,cpu-idle-state-latencies-ns");
262
263 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
264 "ibm,cpu-idle-state-latencies-ns",
265 count) != 0)
266 goto out;
267
268 count = of_property_count_strings(power_mgt,
269 "ibm,cpu-idle-state-names");
270 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
271 "ibm,cpu-idle-state-names",
272 count) != 0)
273 goto out;
274
247 /* 275 /*
248 * Since snooze is used as first idle state, max idle states allowed is 276 * Since snooze is used as first idle state, max idle states allowed is
249 * CPUIDLE_STATE_MAX -1 277 * CPUIDLE_STATE_MAX -1
@@ -278,6 +306,22 @@ static int powernv_add_idle_states(void)
278 has_stop_states = (flags[0] & 306 has_stop_states = (flags[0] &
279 (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP)); 307 (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP));
280 if (has_stop_states) { 308 if (has_stop_states) {
309 count = of_property_count_u64_elems(power_mgt,
310 "ibm,cpu-idle-state-psscr");
311 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
312 dt_idle_states,
313 "ibm,cpu-idle-state-psscr",
314 count) != 0)
315 goto out;
316
317 count = of_property_count_u64_elems(power_mgt,
318 "ibm,cpu-idle-state-psscr-mask");
319 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
320 dt_idle_states,
321 "ibm,cpu-idle-state-psscr-mask",
322 count) != 0)
323 goto out;
324
281 if (of_property_read_u64_array(power_mgt, 325 if (of_property_read_u64_array(power_mgt,
282 "ibm,cpu-idle-state-psscr", psscr_val, dt_idle_states)) { 326 "ibm,cpu-idle-state-psscr", psscr_val, dt_idle_states)) {
283 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n"); 327 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n");
@@ -292,8 +336,21 @@ static int powernv_add_idle_states(void)
292 } 336 }
293 } 337 }
294 338
295 rc = of_property_read_u32_array(power_mgt, 339 count = of_property_count_u32_elems(power_mgt,
296 "ibm,cpu-idle-state-residency-ns", residency_ns, dt_idle_states); 340 "ibm,cpu-idle-state-residency-ns");
341
342 if (count < 0) {
343 rc = count;
344 } else if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
345 dt_idle_states,
346 "ibm,cpu-idle-state-residency-ns",
347 count) != 0) {
348 goto out;
349 } else {
350 rc = of_property_read_u32_array(power_mgt,
351 "ibm,cpu-idle-state-residency-ns",
352 residency_ns, dt_idle_states);
353 }
297 354
298 for (i = 0; i < dt_idle_states; i++) { 355 for (i = 0; i < dt_idle_states; i++) {
299 unsigned int exit_latency, target_residency; 356 unsigned int exit_latency, target_residency;
diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
index 71576b8bdfef..a4f2fa1091e4 100644
--- a/drivers/devfreq/governor.h
+++ b/drivers/devfreq/governor.h
@@ -25,6 +25,35 @@
25#define DEVFREQ_GOV_SUSPEND 0x4 25#define DEVFREQ_GOV_SUSPEND 0x4
26#define DEVFREQ_GOV_RESUME 0x5 26#define DEVFREQ_GOV_RESUME 0x5
27 27
28/**
29 * struct devfreq_governor - Devfreq policy governor
30 * @node: list node - contains registered devfreq governors
31 * @name: Governor's name
32 * @immutable: Immutable flag for governor. If the value is 1,
33 * this govenror is never changeable to other governor.
34 * @get_target_freq: Returns desired operating frequency for the device.
35 * Basically, get_target_freq will run
36 * devfreq_dev_profile.get_dev_status() to get the
37 * status of the device (load = busy_time / total_time).
38 * If no_central_polling is set, this callback is called
39 * only with update_devfreq() notified by OPP.
40 * @event_handler: Callback for devfreq core framework to notify events
41 * to governors. Events include per device governor
42 * init and exit, opp changes out of devfreq, suspend
43 * and resume of per device devfreq during device idle.
44 *
45 * Note that the callbacks are called with devfreq->lock locked by devfreq.
46 */
47struct devfreq_governor {
48 struct list_head node;
49
50 const char name[DEVFREQ_NAME_LEN];
51 const unsigned int immutable;
52 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
53 int (*event_handler)(struct devfreq *devfreq,
54 unsigned int event, void *data);
55};
56
28/* Caution: devfreq->lock must be locked before calling update_devfreq */ 57/* Caution: devfreq->lock must be locked before calling update_devfreq */
29extern int update_devfreq(struct devfreq *devfreq); 58extern int update_devfreq(struct devfreq *devfreq);
30 59
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 94250c293be2..c68ac65db7ff 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -2006,7 +2006,7 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field
2006 return; 2006 return;
2007 case HID_DG_TOOLSERIALNUMBER: 2007 case HID_DG_TOOLSERIALNUMBER:
2008 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); 2008 wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL);
2009 wacom_wac->serial[0] |= value; 2009 wacom_wac->serial[0] |= (__u32)value;
2010 return; 2010 return;
2011 case WACOM_HID_WD_SENSE: 2011 case WACOM_HID_WD_SENSE:
2012 wacom_wac->hid_data.sense_state = value; 2012 wacom_wac->hid_data.sense_state = value;
@@ -2176,6 +2176,16 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
2176 wacom_wac->hid_data.cc_index = field->index; 2176 wacom_wac->hid_data.cc_index = field->index;
2177 wacom_wac->hid_data.cc_value_index = usage->usage_index; 2177 wacom_wac->hid_data.cc_value_index = usage->usage_index;
2178 break; 2178 break;
2179 case HID_DG_CONTACTID:
2180 if ((field->logical_maximum - field->logical_minimum) < touch_max) {
2181 /*
2182 * The HID descriptor for G11 sensors leaves logical
2183 * maximum set to '1' despite it being a multitouch
2184 * device. Override to a sensible number.
2185 */
2186 field->logical_maximum = 255;
2187 }
2188 break;
2179 } 2189 }
2180} 2190}
2181 2191
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index efc8ec342351..e73d968023f7 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1118,6 +1118,7 @@ static int elantech_get_resolution_v4(struct psmouse *psmouse,
1118 * Asus UX32VD 0x361f02 00, 15, 0e clickpad 1118 * Asus UX32VD 0x361f02 00, 15, 0e clickpad
1119 * Avatar AVIU-145A2 0x361f00 ? clickpad 1119 * Avatar AVIU-145A2 0x361f00 ? clickpad
1120 * Fujitsu LIFEBOOK E544 0x470f00 d0, 12, 09 2 hw buttons 1120 * Fujitsu LIFEBOOK E544 0x470f00 d0, 12, 09 2 hw buttons
1121 * Fujitsu LIFEBOOK E547 0x470f00 50, 12, 09 2 hw buttons
1121 * Fujitsu LIFEBOOK E554 0x570f01 40, 14, 0c 2 hw buttons 1122 * Fujitsu LIFEBOOK E554 0x570f01 40, 14, 0c 2 hw buttons
1122 * Fujitsu T725 0x470f01 05, 12, 09 2 hw buttons 1123 * Fujitsu T725 0x470f01 05, 12, 09 2 hw buttons
1123 * Fujitsu H730 0x570f00 c0, 14, 0c 3 hw buttons (**) 1124 * Fujitsu H730 0x570f00 c0, 14, 0c 3 hw buttons (**)
@@ -1524,6 +1525,13 @@ static const struct dmi_system_id elantech_dmi_force_crc_enabled[] = {
1524 }, 1525 },
1525 }, 1526 },
1526 { 1527 {
1528 /* Fujitsu LIFEBOOK E547 does not work with crc_enabled == 0 */
1529 .matches = {
1530 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
1531 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E547"),
1532 },
1533 },
1534 {
1527 /* Fujitsu LIFEBOOK E554 does not work with crc_enabled == 0 */ 1535 /* Fujitsu LIFEBOOK E554 does not work with crc_enabled == 0 */
1528 .matches = { 1536 .matches = {
1529 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 1537 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index e992a7f8a16f..2b32b88949ba 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -267,7 +267,7 @@ static void sdio_release_func(struct device *dev)
267 sdio_free_func_cis(func); 267 sdio_free_func_cis(func);
268 268
269 kfree(func->info); 269 kfree(func->info);
270 270 kfree(func->tmpbuf);
271 kfree(func); 271 kfree(func);
272} 272}
273 273
@@ -282,6 +282,16 @@ struct sdio_func *sdio_alloc_func(struct mmc_card *card)
282 if (!func) 282 if (!func)
283 return ERR_PTR(-ENOMEM); 283 return ERR_PTR(-ENOMEM);
284 284
285 /*
286 * allocate buffer separately to make sure it's properly aligned for
287 * DMA usage (incl. 64 bit DMA)
288 */
289 func->tmpbuf = kmalloc(4, GFP_KERNEL);
290 if (!func->tmpbuf) {
291 kfree(func);
292 return ERR_PTR(-ENOMEM);
293 }
294
285 func->card = card; 295 func->card = card;
286 296
287 device_initialize(&func->dev); 297 device_initialize(&func->dev);
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index a9ac0b457313..8718432751c5 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -22,6 +22,7 @@
22#include <linux/ioport.h> 22#include <linux/ioport.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
25#include <linux/seq_file.h> 26#include <linux/seq_file.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27#include <linux/stat.h> 28#include <linux/stat.h>
@@ -1621,10 +1622,16 @@ static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card)
1621 1622
1622 if (card->type == MMC_TYPE_SDIO || 1623 if (card->type == MMC_TYPE_SDIO ||
1623 card->type == MMC_TYPE_SD_COMBO) { 1624 card->type == MMC_TYPE_SD_COMBO) {
1624 set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); 1625 if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags)) {
1626 pm_runtime_get_noresume(mmc->parent);
1627 set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
1628 }
1625 clk_en_a = clk_en_a_old & ~clken_low_pwr; 1629 clk_en_a = clk_en_a_old & ~clken_low_pwr;
1626 } else { 1630 } else {
1627 clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags); 1631 if (test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags)) {
1632 pm_runtime_put_noidle(mmc->parent);
1633 clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
1634 }
1628 clk_en_a = clk_en_a_old | clken_low_pwr; 1635 clk_en_a = clk_en_a_old | clken_low_pwr;
1629 } 1636 }
1630 1637
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 7123ef96ed18..445fc47dc3e7 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -830,6 +830,7 @@ static int esdhc_change_pinstate(struct sdhci_host *host,
830 830
831 switch (uhs) { 831 switch (uhs) {
832 case MMC_TIMING_UHS_SDR50: 832 case MMC_TIMING_UHS_SDR50:
833 case MMC_TIMING_UHS_DDR50:
833 pinctrl = imx_data->pins_100mhz; 834 pinctrl = imx_data->pins_100mhz;
834 break; 835 break;
835 case MMC_TIMING_UHS_SDR104: 836 case MMC_TIMING_UHS_SDR104:
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 0134ba32a057..39712560b4c1 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -148,11 +148,11 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
148 return err; 148 return err;
149 } 149 }
150 150
151 if (bytes == 0) { 151 err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL);
152 err = ubi_wl_flush(ubi, UBI_ALL, UBI_ALL); 152 if (err)
153 if (err) 153 return err;
154 return err;
155 154
155 if (bytes == 0) {
156 err = clear_update_marker(ubi, vol, 0); 156 err = clear_update_marker(ubi, vol, 0);
157 if (err) 157 if (err)
158 return err; 158 return err;
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 64a1095e4d14..a0ca68ce3fbb 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -134,6 +134,7 @@ static void set_max_bgx_per_node(struct pci_dev *pdev)
134 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdevid); 134 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sdevid);
135 switch (sdevid) { 135 switch (sdevid) {
136 case PCI_SUBSYS_DEVID_81XX_BGX: 136 case PCI_SUBSYS_DEVID_81XX_BGX:
137 case PCI_SUBSYS_DEVID_81XX_RGX:
137 max_bgx_per_node = MAX_BGX_PER_CN81XX; 138 max_bgx_per_node = MAX_BGX_PER_CN81XX;
138 break; 139 break;
139 case PCI_SUBSYS_DEVID_83XX_BGX: 140 case PCI_SUBSYS_DEVID_83XX_BGX:
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
index c5080f2cead5..6b7fe6fdd13b 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
@@ -16,6 +16,7 @@
16/* Subsystem device IDs */ 16/* Subsystem device IDs */
17#define PCI_SUBSYS_DEVID_88XX_BGX 0xA126 17#define PCI_SUBSYS_DEVID_88XX_BGX 0xA126
18#define PCI_SUBSYS_DEVID_81XX_BGX 0xA226 18#define PCI_SUBSYS_DEVID_81XX_BGX 0xA226
19#define PCI_SUBSYS_DEVID_81XX_RGX 0xA254
19#define PCI_SUBSYS_DEVID_83XX_BGX 0xA326 20#define PCI_SUBSYS_DEVID_83XX_BGX 0xA326
20 21
21#define MAX_BGX_THUNDER 8 /* Max 2 nodes, 4 per node */ 22#define MAX_BGX_THUNDER 8 /* Max 2 nodes, 4 per node */
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 9e757684816d..93949139e62c 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -613,7 +613,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
613 struct mtk_mac *mac = netdev_priv(dev); 613 struct mtk_mac *mac = netdev_priv(dev);
614 struct mtk_eth *eth = mac->hw; 614 struct mtk_eth *eth = mac->hw;
615 struct mtk_tx_dma *itxd, *txd; 615 struct mtk_tx_dma *itxd, *txd;
616 struct mtk_tx_buf *tx_buf; 616 struct mtk_tx_buf *itx_buf, *tx_buf;
617 dma_addr_t mapped_addr; 617 dma_addr_t mapped_addr;
618 unsigned int nr_frags; 618 unsigned int nr_frags;
619 int i, n_desc = 1; 619 int i, n_desc = 1;
@@ -627,8 +627,8 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
627 fport = (mac->id + 1) << TX_DMA_FPORT_SHIFT; 627 fport = (mac->id + 1) << TX_DMA_FPORT_SHIFT;
628 txd4 |= fport; 628 txd4 |= fport;
629 629
630 tx_buf = mtk_desc_to_tx_buf(ring, itxd); 630 itx_buf = mtk_desc_to_tx_buf(ring, itxd);
631 memset(tx_buf, 0, sizeof(*tx_buf)); 631 memset(itx_buf, 0, sizeof(*itx_buf));
632 632
633 if (gso) 633 if (gso)
634 txd4 |= TX_DMA_TSO; 634 txd4 |= TX_DMA_TSO;
@@ -647,9 +647,11 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
647 return -ENOMEM; 647 return -ENOMEM;
648 648
649 WRITE_ONCE(itxd->txd1, mapped_addr); 649 WRITE_ONCE(itxd->txd1, mapped_addr);
650 tx_buf->flags |= MTK_TX_FLAGS_SINGLE0; 650 itx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
651 dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr); 651 itx_buf->flags |= (!mac->id) ? MTK_TX_FLAGS_FPORT0 :
652 dma_unmap_len_set(tx_buf, dma_len0, skb_headlen(skb)); 652 MTK_TX_FLAGS_FPORT1;
653 dma_unmap_addr_set(itx_buf, dma_addr0, mapped_addr);
654 dma_unmap_len_set(itx_buf, dma_len0, skb_headlen(skb));
653 655
654 /* TX SG offload */ 656 /* TX SG offload */
655 txd = itxd; 657 txd = itxd;
@@ -685,11 +687,13 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
685 last_frag * TX_DMA_LS0)); 687 last_frag * TX_DMA_LS0));
686 WRITE_ONCE(txd->txd4, fport); 688 WRITE_ONCE(txd->txd4, fport);
687 689
688 tx_buf->skb = (struct sk_buff *)MTK_DMA_DUMMY_DESC;
689 tx_buf = mtk_desc_to_tx_buf(ring, txd); 690 tx_buf = mtk_desc_to_tx_buf(ring, txd);
690 memset(tx_buf, 0, sizeof(*tx_buf)); 691 memset(tx_buf, 0, sizeof(*tx_buf));
691 692 tx_buf->skb = (struct sk_buff *)MTK_DMA_DUMMY_DESC;
692 tx_buf->flags |= MTK_TX_FLAGS_PAGE0; 693 tx_buf->flags |= MTK_TX_FLAGS_PAGE0;
694 tx_buf->flags |= (!mac->id) ? MTK_TX_FLAGS_FPORT0 :
695 MTK_TX_FLAGS_FPORT1;
696
693 dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr); 697 dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr);
694 dma_unmap_len_set(tx_buf, dma_len0, frag_map_size); 698 dma_unmap_len_set(tx_buf, dma_len0, frag_map_size);
695 frag_size -= frag_map_size; 699 frag_size -= frag_map_size;
@@ -698,7 +702,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
698 } 702 }
699 703
700 /* store skb to cleanup */ 704 /* store skb to cleanup */
701 tx_buf->skb = skb; 705 itx_buf->skb = skb;
702 706
703 WRITE_ONCE(itxd->txd4, txd4); 707 WRITE_ONCE(itxd->txd4, txd4);
704 WRITE_ONCE(itxd->txd3, (TX_DMA_SWC | TX_DMA_PLEN0(skb_headlen(skb)) | 708 WRITE_ONCE(itxd->txd3, (TX_DMA_SWC | TX_DMA_PLEN0(skb_headlen(skb)) |
@@ -1012,17 +1016,16 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget)
1012 1016
1013 while ((cpu != dma) && budget) { 1017 while ((cpu != dma) && budget) {
1014 u32 next_cpu = desc->txd2; 1018 u32 next_cpu = desc->txd2;
1015 int mac; 1019 int mac = 0;
1016 1020
1017 desc = mtk_qdma_phys_to_virt(ring, desc->txd2); 1021 desc = mtk_qdma_phys_to_virt(ring, desc->txd2);
1018 if ((desc->txd3 & TX_DMA_OWNER_CPU) == 0) 1022 if ((desc->txd3 & TX_DMA_OWNER_CPU) == 0)
1019 break; 1023 break;
1020 1024
1021 mac = (desc->txd4 >> TX_DMA_FPORT_SHIFT) &
1022 TX_DMA_FPORT_MASK;
1023 mac--;
1024
1025 tx_buf = mtk_desc_to_tx_buf(ring, desc); 1025 tx_buf = mtk_desc_to_tx_buf(ring, desc);
1026 if (tx_buf->flags & MTK_TX_FLAGS_FPORT1)
1027 mac = 1;
1028
1026 skb = tx_buf->skb; 1029 skb = tx_buf->skb;
1027 if (!skb) { 1030 if (!skb) {
1028 condition = 1; 1031 condition = 1;
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index 99b1c8e9f16f..08285a96ff70 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -406,12 +406,18 @@ struct mtk_hw_stats {
406 struct u64_stats_sync syncp; 406 struct u64_stats_sync syncp;
407}; 407};
408 408
409/* PDMA descriptor can point at 1-2 segments. This enum allows us to track how
410 * memory was allocated so that it can be freed properly
411 */
412enum mtk_tx_flags { 409enum mtk_tx_flags {
410 /* PDMA descriptor can point at 1-2 segments. This enum allows us to
411 * track how memory was allocated so that it can be freed properly.
412 */
413 MTK_TX_FLAGS_SINGLE0 = 0x01, 413 MTK_TX_FLAGS_SINGLE0 = 0x01,
414 MTK_TX_FLAGS_PAGE0 = 0x02, 414 MTK_TX_FLAGS_PAGE0 = 0x02,
415
416 /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
417 * SKB out instead of looking up through hardware TX descriptor.
418 */
419 MTK_TX_FLAGS_FPORT0 = 0x04,
420 MTK_TX_FLAGS_FPORT1 = 0x08,
415}; 421};
416 422
417/* This enum allows us to identify how the clock is defined on the array of the 423/* This enum allows us to identify how the clock is defined on the array of the
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index 5bd36a4a8fcd..a6e2bbe629bd 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -583,6 +583,13 @@ qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
583 p_params->ets_cbs, 583 p_params->ets_cbs,
584 p_ets->pri_tc_tbl[0], p_params->max_ets_tc); 584 p_ets->pri_tc_tbl[0], p_params->max_ets_tc);
585 585
586 if (p_params->ets_enabled && !p_params->max_ets_tc) {
587 p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
588 DP_VERBOSE(p_hwfn, QED_MSG_DCB,
589 "ETS params: max_ets_tc is forced to %d\n",
590 p_params->max_ets_tc);
591 }
592
586 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are 593 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
587 * encoded in a type u32 array of size 2. 594 * encoded in a type u32 array of size 2.
588 */ 595 */
@@ -1001,6 +1008,8 @@ qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
1001 u8 pfc_map = 0; 1008 u8 pfc_map = 0;
1002 int i; 1009 int i;
1003 1010
1011 *pfc &= ~DCBX_PFC_ERROR_MASK;
1012
1004 if (p_params->pfc.willing) 1013 if (p_params->pfc.willing)
1005 *pfc |= DCBX_PFC_WILLING_MASK; 1014 *pfc |= DCBX_PFC_WILLING_MASK;
1006 else 1015 else
@@ -1255,7 +1264,7 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1255{ 1264{
1256 struct qed_dcbx_get *dcbx_info; 1265 struct qed_dcbx_get *dcbx_info;
1257 1266
1258 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL); 1267 dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_ATOMIC);
1259 if (!dcbx_info) 1268 if (!dcbx_info)
1260 return NULL; 1269 return NULL;
1261 1270
@@ -2073,6 +2082,8 @@ static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
2073 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) 2082 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
2074 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i)); 2083 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
2075 2084
2085 dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
2086
2076 ptt = qed_ptt_acquire(hwfn); 2087 ptt = qed_ptt_acquire(hwfn);
2077 if (!ptt) 2088 if (!ptt)
2078 return -EINVAL; 2089 return -EINVAL;
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 54248775f227..f68c4db656ed 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1127,12 +1127,70 @@ static struct mdiobb_ops bb_ops = {
1127 .get_mdio_data = sh_get_mdio, 1127 .get_mdio_data = sh_get_mdio,
1128}; 1128};
1129 1129
1130/* free Tx skb function */
1131static int sh_eth_tx_free(struct net_device *ndev, bool sent_only)
1132{
1133 struct sh_eth_private *mdp = netdev_priv(ndev);
1134 struct sh_eth_txdesc *txdesc;
1135 int free_num = 0;
1136 int entry;
1137 bool sent;
1138
1139 for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
1140 entry = mdp->dirty_tx % mdp->num_tx_ring;
1141 txdesc = &mdp->tx_ring[entry];
1142 sent = !(txdesc->status & cpu_to_le32(TD_TACT));
1143 if (sent_only && !sent)
1144 break;
1145 /* TACT bit must be checked before all the following reads */
1146 dma_rmb();
1147 netif_info(mdp, tx_done, ndev,
1148 "tx entry %d status 0x%08x\n",
1149 entry, le32_to_cpu(txdesc->status));
1150 /* Free the original skb. */
1151 if (mdp->tx_skbuff[entry]) {
1152 dma_unmap_single(&ndev->dev, le32_to_cpu(txdesc->addr),
1153 le32_to_cpu(txdesc->len) >> 16,
1154 DMA_TO_DEVICE);
1155 dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
1156 mdp->tx_skbuff[entry] = NULL;
1157 free_num++;
1158 }
1159 txdesc->status = cpu_to_le32(TD_TFP);
1160 if (entry >= mdp->num_tx_ring - 1)
1161 txdesc->status |= cpu_to_le32(TD_TDLE);
1162
1163 if (sent) {
1164 ndev->stats.tx_packets++;
1165 ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16;
1166 }
1167 }
1168 return free_num;
1169}
1170
1130/* free skb and descriptor buffer */ 1171/* free skb and descriptor buffer */
1131static void sh_eth_ring_free(struct net_device *ndev) 1172static void sh_eth_ring_free(struct net_device *ndev)
1132{ 1173{
1133 struct sh_eth_private *mdp = netdev_priv(ndev); 1174 struct sh_eth_private *mdp = netdev_priv(ndev);
1134 int ringsize, i; 1175 int ringsize, i;
1135 1176
1177 if (mdp->rx_ring) {
1178 for (i = 0; i < mdp->num_rx_ring; i++) {
1179 if (mdp->rx_skbuff[i]) {
1180 struct sh_eth_rxdesc *rxdesc = &mdp->rx_ring[i];
1181
1182 dma_unmap_single(&ndev->dev,
1183 le32_to_cpu(rxdesc->addr),
1184 ALIGN(mdp->rx_buf_sz, 32),
1185 DMA_FROM_DEVICE);
1186 }
1187 }
1188 ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
1189 dma_free_coherent(NULL, ringsize, mdp->rx_ring,
1190 mdp->rx_desc_dma);
1191 mdp->rx_ring = NULL;
1192 }
1193
1136 /* Free Rx skb ringbuffer */ 1194 /* Free Rx skb ringbuffer */
1137 if (mdp->rx_skbuff) { 1195 if (mdp->rx_skbuff) {
1138 for (i = 0; i < mdp->num_rx_ring; i++) 1196 for (i = 0; i < mdp->num_rx_ring; i++)
@@ -1141,27 +1199,18 @@ static void sh_eth_ring_free(struct net_device *ndev)
1141 kfree(mdp->rx_skbuff); 1199 kfree(mdp->rx_skbuff);
1142 mdp->rx_skbuff = NULL; 1200 mdp->rx_skbuff = NULL;
1143 1201
1144 /* Free Tx skb ringbuffer */
1145 if (mdp->tx_skbuff) {
1146 for (i = 0; i < mdp->num_tx_ring; i++)
1147 dev_kfree_skb(mdp->tx_skbuff[i]);
1148 }
1149 kfree(mdp->tx_skbuff);
1150 mdp->tx_skbuff = NULL;
1151
1152 if (mdp->rx_ring) {
1153 ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring;
1154 dma_free_coherent(NULL, ringsize, mdp->rx_ring,
1155 mdp->rx_desc_dma);
1156 mdp->rx_ring = NULL;
1157 }
1158
1159 if (mdp->tx_ring) { 1202 if (mdp->tx_ring) {
1203 sh_eth_tx_free(ndev, false);
1204
1160 ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; 1205 ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring;
1161 dma_free_coherent(NULL, ringsize, mdp->tx_ring, 1206 dma_free_coherent(NULL, ringsize, mdp->tx_ring,
1162 mdp->tx_desc_dma); 1207 mdp->tx_desc_dma);
1163 mdp->tx_ring = NULL; 1208 mdp->tx_ring = NULL;
1164 } 1209 }
1210
1211 /* Free Tx skb ringbuffer */
1212 kfree(mdp->tx_skbuff);
1213 mdp->tx_skbuff = NULL;
1165} 1214}
1166 1215
1167/* format skb and descriptor buffer */ 1216/* format skb and descriptor buffer */
@@ -1409,43 +1458,6 @@ static void sh_eth_dev_exit(struct net_device *ndev)
1409 update_mac_address(ndev); 1458 update_mac_address(ndev);
1410} 1459}
1411 1460
1412/* free Tx skb function */
1413static int sh_eth_txfree(struct net_device *ndev)
1414{
1415 struct sh_eth_private *mdp = netdev_priv(ndev);
1416 struct sh_eth_txdesc *txdesc;
1417 int free_num = 0;
1418 int entry;
1419
1420 for (; mdp->cur_tx - mdp->dirty_tx > 0; mdp->dirty_tx++) {
1421 entry = mdp->dirty_tx % mdp->num_tx_ring;
1422 txdesc = &mdp->tx_ring[entry];
1423 if (txdesc->status & cpu_to_le32(TD_TACT))
1424 break;
1425 /* TACT bit must be checked before all the following reads */
1426 dma_rmb();
1427 netif_info(mdp, tx_done, ndev,
1428 "tx entry %d status 0x%08x\n",
1429 entry, le32_to_cpu(txdesc->status));
1430 /* Free the original skb. */
1431 if (mdp->tx_skbuff[entry]) {
1432 dma_unmap_single(&ndev->dev, le32_to_cpu(txdesc->addr),
1433 le32_to_cpu(txdesc->len) >> 16,
1434 DMA_TO_DEVICE);
1435 dev_kfree_skb_irq(mdp->tx_skbuff[entry]);
1436 mdp->tx_skbuff[entry] = NULL;
1437 free_num++;
1438 }
1439 txdesc->status = cpu_to_le32(TD_TFP);
1440 if (entry >= mdp->num_tx_ring - 1)
1441 txdesc->status |= cpu_to_le32(TD_TDLE);
1442
1443 ndev->stats.tx_packets++;
1444 ndev->stats.tx_bytes += le32_to_cpu(txdesc->len) >> 16;
1445 }
1446 return free_num;
1447}
1448
1449/* Packet receive function */ 1461/* Packet receive function */
1450static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota) 1462static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1451{ 1463{
@@ -1690,7 +1702,7 @@ static void sh_eth_error(struct net_device *ndev, u32 intr_status)
1690 intr_status, mdp->cur_tx, mdp->dirty_tx, 1702 intr_status, mdp->cur_tx, mdp->dirty_tx,
1691 (u32)ndev->state, edtrr); 1703 (u32)ndev->state, edtrr);
1692 /* dirty buffer free */ 1704 /* dirty buffer free */
1693 sh_eth_txfree(ndev); 1705 sh_eth_tx_free(ndev, true);
1694 1706
1695 /* SH7712 BUG */ 1707 /* SH7712 BUG */
1696 if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) { 1708 if (edtrr ^ sh_eth_get_edtrr_trns(mdp)) {
@@ -1751,7 +1763,7 @@ static irqreturn_t sh_eth_interrupt(int irq, void *netdev)
1751 /* Clear Tx interrupts */ 1763 /* Clear Tx interrupts */
1752 sh_eth_write(ndev, intr_status & cd->tx_check, EESR); 1764 sh_eth_write(ndev, intr_status & cd->tx_check, EESR);
1753 1765
1754 sh_eth_txfree(ndev); 1766 sh_eth_tx_free(ndev, true);
1755 netif_wake_queue(ndev); 1767 netif_wake_queue(ndev);
1756 } 1768 }
1757 1769
@@ -2412,7 +2424,7 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
2412 2424
2413 spin_lock_irqsave(&mdp->lock, flags); 2425 spin_lock_irqsave(&mdp->lock, flags);
2414 if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) { 2426 if ((mdp->cur_tx - mdp->dirty_tx) >= (mdp->num_tx_ring - 4)) {
2415 if (!sh_eth_txfree(ndev)) { 2427 if (!sh_eth_tx_free(ndev, true)) {
2416 netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n"); 2428 netif_warn(mdp, tx_queued, ndev, "TxFD exhausted.\n");
2417 netif_stop_queue(ndev); 2429 netif_stop_queue(ndev);
2418 spin_unlock_irqrestore(&mdp->lock, flags); 2430 spin_unlock_irqrestore(&mdp->lock, flags);
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 50d28261b6b9..b9cb697b2818 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -1371,6 +1371,13 @@ static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
1371 free_cpumask_var(thread_mask); 1371 free_cpumask_var(thread_mask);
1372 } 1372 }
1373 1373
1374 if (count > EFX_MAX_RX_QUEUES) {
1375 netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1376 "Reducing number of rx queues from %u to %u.\n",
1377 count, EFX_MAX_RX_QUEUES);
1378 count = EFX_MAX_RX_QUEUES;
1379 }
1380
1374 /* If RSS is requested for the PF *and* VFs then we can't write RSS 1381 /* If RSS is requested for the PF *and* VFs then we can't write RSS
1375 * table entries that are inaccessible to VFs 1382 * table entries that are inaccessible to VFs
1376 */ 1383 */
diff --git a/drivers/net/ethernet/sfc/falcon/efx.c b/drivers/net/ethernet/sfc/falcon/efx.c
index f5e5cd1659a1..29614da91cbf 100644
--- a/drivers/net/ethernet/sfc/falcon/efx.c
+++ b/drivers/net/ethernet/sfc/falcon/efx.c
@@ -1354,6 +1354,13 @@ static unsigned int ef4_wanted_parallelism(struct ef4_nic *efx)
1354 free_cpumask_var(thread_mask); 1354 free_cpumask_var(thread_mask);
1355 } 1355 }
1356 1356
1357 if (count > EF4_MAX_RX_QUEUES) {
1358 netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
1359 "Reducing number of rx queues from %u to %u.\n",
1360 count, EF4_MAX_RX_QUEUES);
1361 count = EF4_MAX_RX_QUEUES;
1362 }
1363
1357 return count; 1364 return count;
1358} 1365}
1359 1366
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index e2460a57e4b1..ed0d10f54f26 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1438,8 +1438,6 @@ static bool dp83640_rxtstamp(struct phy_device *phydev,
1438 skb_info->tmo = jiffies + SKB_TIMESTAMP_TIMEOUT; 1438 skb_info->tmo = jiffies + SKB_TIMESTAMP_TIMEOUT;
1439 skb_queue_tail(&dp83640->rx_queue, skb); 1439 skb_queue_tail(&dp83640->rx_queue, skb);
1440 schedule_delayed_work(&dp83640->ts_work, SKB_TIMESTAMP_TIMEOUT); 1440 schedule_delayed_work(&dp83640->ts_work, SKB_TIMESTAMP_TIMEOUT);
1441 } else {
1442 netif_rx_ni(skb);
1443 } 1441 }
1444 1442
1445 return true; 1443 return true;
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 6742070ca676..1326d99771c1 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -798,9 +798,6 @@ static struct phy_driver ksphy_driver[] = {
798 .read_status = genphy_read_status, 798 .read_status = genphy_read_status,
799 .ack_interrupt = kszphy_ack_interrupt, 799 .ack_interrupt = kszphy_ack_interrupt,
800 .config_intr = kszphy_config_intr, 800 .config_intr = kszphy_config_intr,
801 .get_sset_count = kszphy_get_sset_count,
802 .get_strings = kszphy_get_strings,
803 .get_stats = kszphy_get_stats,
804 .suspend = genphy_suspend, 801 .suspend = genphy_suspend,
805 .resume = genphy_resume, 802 .resume = genphy_resume,
806}, { 803}, {
@@ -940,9 +937,6 @@ static struct phy_driver ksphy_driver[] = {
940 .read_status = genphy_read_status, 937 .read_status = genphy_read_status,
941 .ack_interrupt = kszphy_ack_interrupt, 938 .ack_interrupt = kszphy_ack_interrupt,
942 .config_intr = kszphy_config_intr, 939 .config_intr = kszphy_config_intr,
943 .get_sset_count = kszphy_get_sset_count,
944 .get_strings = kszphy_get_strings,
945 .get_stats = kszphy_get_stats,
946 .suspend = genphy_suspend, 940 .suspend = genphy_suspend,
947 .resume = genphy_resume, 941 .resume = genphy_resume,
948}, { 942}, {
@@ -952,6 +946,7 @@ static struct phy_driver ksphy_driver[] = {
952 .features = PHY_GBIT_FEATURES, 946 .features = PHY_GBIT_FEATURES,
953 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 947 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
954 .driver_data = &ksz9021_type, 948 .driver_data = &ksz9021_type,
949 .probe = kszphy_probe,
955 .config_init = ksz9021_config_init, 950 .config_init = ksz9021_config_init,
956 .config_aneg = genphy_config_aneg, 951 .config_aneg = genphy_config_aneg,
957 .read_status = genphy_read_status, 952 .read_status = genphy_read_status,
@@ -971,6 +966,7 @@ static struct phy_driver ksphy_driver[] = {
971 .features = PHY_GBIT_FEATURES, 966 .features = PHY_GBIT_FEATURES,
972 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT, 967 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
973 .driver_data = &ksz9021_type, 968 .driver_data = &ksz9021_type,
969 .probe = kszphy_probe,
974 .config_init = ksz9031_config_init, 970 .config_init = ksz9031_config_init,
975 .config_aneg = genphy_config_aneg, 971 .config_aneg = genphy_config_aneg,
976 .read_status = ksz9031_read_status, 972 .read_status = ksz9031_read_status,
@@ -989,9 +985,6 @@ static struct phy_driver ksphy_driver[] = {
989 .config_init = kszphy_config_init, 985 .config_init = kszphy_config_init,
990 .config_aneg = ksz8873mll_config_aneg, 986 .config_aneg = ksz8873mll_config_aneg,
991 .read_status = ksz8873mll_read_status, 987 .read_status = ksz8873mll_read_status,
992 .get_sset_count = kszphy_get_sset_count,
993 .get_strings = kszphy_get_strings,
994 .get_stats = kszphy_get_stats,
995 .suspend = genphy_suspend, 988 .suspend = genphy_suspend,
996 .resume = genphy_resume, 989 .resume = genphy_resume,
997}, { 990}, {
@@ -1003,9 +996,6 @@ static struct phy_driver ksphy_driver[] = {
1003 .config_init = kszphy_config_init, 996 .config_init = kszphy_config_init,
1004 .config_aneg = genphy_config_aneg, 997 .config_aneg = genphy_config_aneg,
1005 .read_status = genphy_read_status, 998 .read_status = genphy_read_status,
1006 .get_sset_count = kszphy_get_sset_count,
1007 .get_strings = kszphy_get_strings,
1008 .get_stats = kszphy_get_stats,
1009 .suspend = genphy_suspend, 999 .suspend = genphy_suspend,
1010 .resume = genphy_resume, 1000 .resume = genphy_resume,
1011}, { 1001}, {
@@ -1017,9 +1007,6 @@ static struct phy_driver ksphy_driver[] = {
1017 .config_init = kszphy_config_init, 1007 .config_init = kszphy_config_init,
1018 .config_aneg = ksz8873mll_config_aneg, 1008 .config_aneg = ksz8873mll_config_aneg,
1019 .read_status = ksz8873mll_read_status, 1009 .read_status = ksz8873mll_read_status,
1020 .get_sset_count = kszphy_get_sset_count,
1021 .get_strings = kszphy_get_strings,
1022 .get_stats = kszphy_get_stats,
1023 .suspend = genphy_suspend, 1010 .suspend = genphy_suspend,
1024 .resume = genphy_resume, 1011 .resume = genphy_resume,
1025} }; 1012} };
diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
index 8a40202c0a17..c4f1c363e24b 100644
--- a/drivers/net/usb/ch9200.c
+++ b/drivers/net/usb/ch9200.c
@@ -254,14 +254,9 @@ static struct sk_buff *ch9200_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
254 tx_overhead = 0x40; 254 tx_overhead = 0x40;
255 255
256 len = skb->len; 256 len = skb->len;
257 if (skb_headroom(skb) < tx_overhead) { 257 if (skb_cow_head(skb, tx_overhead)) {
258 struct sk_buff *skb2;
259
260 skb2 = skb_copy_expand(skb, tx_overhead, 0, flags);
261 dev_kfree_skb_any(skb); 258 dev_kfree_skb_any(skb);
262 skb = skb2; 259 return NULL;
263 if (!skb)
264 return NULL;
265 } 260 }
266 261
267 __skb_push(skb, tx_overhead); 262 __skb_push(skb, tx_overhead);
diff --git a/drivers/net/usb/cx82310_eth.c b/drivers/net/usb/cx82310_eth.c
index e221bfcee76b..947bea81d924 100644
--- a/drivers/net/usb/cx82310_eth.c
+++ b/drivers/net/usb/cx82310_eth.c
@@ -293,12 +293,9 @@ static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
293{ 293{
294 int len = skb->len; 294 int len = skb->len;
295 295
296 if (skb_headroom(skb) < 2) { 296 if (skb_cow_head(skb, 2)) {
297 struct sk_buff *skb2 = skb_copy_expand(skb, 2, 0, flags);
298 dev_kfree_skb_any(skb); 297 dev_kfree_skb_any(skb);
299 skb = skb2; 298 return NULL;
300 if (!skb)
301 return NULL;
302 } 299 }
303 skb_push(skb, 2); 300 skb_push(skb, 2);
304 301
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 876f02f4945e..2a2c3edb6bad 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -803,18 +803,12 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
803 } 803 }
804 804
805 /* We now decide whether we can put our special header into the sk_buff */ 805 /* We now decide whether we can put our special header into the sk_buff */
806 if (skb_cloned(skb) || skb_headroom(skb) < 2) { 806 if (skb_cow_head(skb, 2)) {
807 /* no such luck - we make our own */ 807 kaweth->stats.tx_errors++;
808 struct sk_buff *copied_skb; 808 netif_start_queue(net);
809 copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC); 809 spin_unlock_irq(&kaweth->device_lock);
810 dev_kfree_skb_irq(skb); 810 dev_kfree_skb_any(skb);
811 skb = copied_skb; 811 return NETDEV_TX_OK;
812 if (!copied_skb) {
813 kaweth->stats.tx_errors++;
814 netif_start_queue(net);
815 spin_unlock_irq(&kaweth->device_lock);
816 return NETDEV_TX_OK;
817 }
818 } 812 }
819 813
820 private_header = (__le16 *)__skb_push(skb, 2); 814 private_header = (__le16 *)__skb_push(skb, 2);
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 9889a70ff4f6..636f48f19d1e 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -2607,14 +2607,9 @@ static struct sk_buff *lan78xx_tx_prep(struct lan78xx_net *dev,
2607{ 2607{
2608 u32 tx_cmd_a, tx_cmd_b; 2608 u32 tx_cmd_a, tx_cmd_b;
2609 2609
2610 if (skb_headroom(skb) < TX_OVERHEAD) { 2610 if (skb_cow_head(skb, TX_OVERHEAD)) {
2611 struct sk_buff *skb2;
2612
2613 skb2 = skb_copy_expand(skb, TX_OVERHEAD, 0, flags);
2614 dev_kfree_skb_any(skb); 2611 dev_kfree_skb_any(skb);
2615 skb = skb2; 2612 return NULL;
2616 if (!skb)
2617 return NULL;
2618 } 2613 }
2619 2614
2620 if (lan78xx_linearize(skb) < 0) 2615 if (lan78xx_linearize(skb) < 0)
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 0b17b40d7a4f..190de9a90f73 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -2203,13 +2203,9 @@ static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
2203{ 2203{
2204 u32 tx_cmd_a, tx_cmd_b; 2204 u32 tx_cmd_a, tx_cmd_b;
2205 2205
2206 if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) { 2206 if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) {
2207 struct sk_buff *skb2 =
2208 skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags);
2209 dev_kfree_skb_any(skb); 2207 dev_kfree_skb_any(skb);
2210 skb = skb2; 2208 return NULL;
2211 if (!skb)
2212 return NULL;
2213 } 2209 }
2214 2210
2215 tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS; 2211 tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 831aa33d078a..5f19fb0f025d 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -2001,13 +2001,13 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
2001 /* We do not advertise SG, so skbs should be already linearized */ 2001 /* We do not advertise SG, so skbs should be already linearized */
2002 BUG_ON(skb_shinfo(skb)->nr_frags); 2002 BUG_ON(skb_shinfo(skb)->nr_frags);
2003 2003
2004 if (skb_headroom(skb) < overhead) { 2004 /* Make writable and expand header space by overhead if required */
2005 struct sk_buff *skb2 = skb_copy_expand(skb, 2005 if (skb_cow_head(skb, overhead)) {
2006 overhead, 0, flags); 2006 /* Must deallocate here as returning NULL to indicate error
2007 * means the skb won't be deallocated in the caller.
2008 */
2007 dev_kfree_skb_any(skb); 2009 dev_kfree_skb_any(skb);
2008 skb = skb2; 2010 return NULL;
2009 if (!skb)
2010 return NULL;
2011 } 2011 }
2012 2012
2013 if (csum) { 2013 if (csum) {
diff --git a/drivers/net/usb/sr9700.c b/drivers/net/usb/sr9700.c
index 4a1e9c489f1f..aadfe1d1c37e 100644
--- a/drivers/net/usb/sr9700.c
+++ b/drivers/net/usb/sr9700.c
@@ -456,14 +456,9 @@ static struct sk_buff *sr9700_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
456 456
457 len = skb->len; 457 len = skb->len;
458 458
459 if (skb_headroom(skb) < SR_TX_OVERHEAD) { 459 if (skb_cow_head(skb, SR_TX_OVERHEAD)) {
460 struct sk_buff *skb2;
461
462 skb2 = skb_copy_expand(skb, SR_TX_OVERHEAD, 0, flags);
463 dev_kfree_skb_any(skb); 460 dev_kfree_skb_any(skb);
464 skb = skb2; 461 return NULL;
465 if (!skb)
466 return NULL;
467 } 462 }
468 463
469 __skb_push(skb, SR_TX_OVERHEAD); 464 __skb_push(skb, SR_TX_OVERHEAD);
diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index d6988db1930d..7d909c8183e9 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -1128,7 +1128,7 @@ static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it)
1128 goto nla_put_failure; 1128 goto nla_put_failure;
1129 1129
1130 /* rule only needs to appear once */ 1130 /* rule only needs to appear once */
1131 nlh->nlmsg_flags &= NLM_F_EXCL; 1131 nlh->nlmsg_flags |= NLM_F_EXCL;
1132 1132
1133 frh = nlmsg_data(nlh); 1133 frh = nlmsg_data(nlh);
1134 memset(frh, 0, sizeof(*frh)); 1134 memset(frh, 0, sizeof(*frh));
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9583a5f58a1d..eeb409c287b8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1316,6 +1316,14 @@ static void nvme_configure_apst(struct nvme_ctrl *ctrl)
1316 table->entries[state] = target; 1316 table->entries[state] = target;
1317 1317
1318 /* 1318 /*
1319 * Don't allow transitions to the deepest state
1320 * if it's quirked off.
1321 */
1322 if (state == ctrl->npss &&
1323 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS))
1324 continue;
1325
1326 /*
1319 * Is this state a useful non-operational state for 1327 * Is this state a useful non-operational state for
1320 * higher-power states to autonomously transition to? 1328 * higher-power states to autonomously transition to?
1321 */ 1329 */
@@ -1387,16 +1395,15 @@ struct nvme_core_quirk_entry {
1387}; 1395};
1388 1396
1389static const struct nvme_core_quirk_entry core_quirks[] = { 1397static const struct nvme_core_quirk_entry core_quirks[] = {
1390 /*
1391 * Seen on a Samsung "SM951 NVMe SAMSUNG 256GB": using APST causes
1392 * the controller to go out to lunch. It dies when the watchdog
1393 * timer reads CSTS and gets 0xffffffff.
1394 */
1395 { 1398 {
1396 .vid = 0x144d, 1399 /*
1397 .fr = "BXW75D0Q", 1400 * This Toshiba device seems to die using any APST states. See:
1401 * https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1678184/comments/11
1402 */
1403 .vid = 0x1179,
1404 .mn = "THNSF5256GPUK TOSHIBA",
1398 .quirks = NVME_QUIRK_NO_APST, 1405 .quirks = NVME_QUIRK_NO_APST,
1399 }, 1406 }
1400}; 1407};
1401 1408
1402/* match is null-terminated but idstr is space-padded. */ 1409/* match is null-terminated but idstr is space-padded. */
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 2aa20e3e5675..ab2d6ec7eb5c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -83,6 +83,11 @@ enum nvme_quirks {
83 * APST should not be used. 83 * APST should not be used.
84 */ 84 */
85 NVME_QUIRK_NO_APST = (1 << 4), 85 NVME_QUIRK_NO_APST = (1 << 4),
86
87 /*
88 * The deepest sleep state should not be used.
89 */
90 NVME_QUIRK_NO_DEEPEST_PS = (1 << 5),
86}; 91};
87 92
88/* 93/*
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 26a5fd05fe88..5d309535abbd 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -19,6 +19,7 @@
19#include <linux/blk-mq-pci.h> 19#include <linux/blk-mq-pci.h>
20#include <linux/cpu.h> 20#include <linux/cpu.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/dmi.h>
22#include <linux/errno.h> 23#include <linux/errno.h>
23#include <linux/fs.h> 24#include <linux/fs.h>
24#include <linux/genhd.h> 25#include <linux/genhd.h>
@@ -1943,10 +1944,31 @@ static int nvme_dev_map(struct nvme_dev *dev)
1943 return -ENODEV; 1944 return -ENODEV;
1944} 1945}
1945 1946
1947static unsigned long check_dell_samsung_bug(struct pci_dev *pdev)
1948{
1949 if (pdev->vendor == 0x144d && pdev->device == 0xa802) {
1950 /*
1951 * Several Samsung devices seem to drop off the PCIe bus
1952 * randomly when APST is on and uses the deepest sleep state.
1953 * This has been observed on a Samsung "SM951 NVMe SAMSUNG
1954 * 256GB", a "PM951 NVMe SAMSUNG 512GB", and a "Samsung SSD
1955 * 950 PRO 256GB", but it seems to be restricted to two Dell
1956 * laptops.
1957 */
1958 if (dmi_match(DMI_SYS_VENDOR, "Dell Inc.") &&
1959 (dmi_match(DMI_PRODUCT_NAME, "XPS 15 9550") ||
1960 dmi_match(DMI_PRODUCT_NAME, "Precision 5510")))
1961 return NVME_QUIRK_NO_DEEPEST_PS;
1962 }
1963
1964 return 0;
1965}
1966
1946static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1967static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1947{ 1968{
1948 int node, result = -ENOMEM; 1969 int node, result = -ENOMEM;
1949 struct nvme_dev *dev; 1970 struct nvme_dev *dev;
1971 unsigned long quirks = id->driver_data;
1950 1972
1951 node = dev_to_node(&pdev->dev); 1973 node = dev_to_node(&pdev->dev);
1952 if (node == NUMA_NO_NODE) 1974 if (node == NUMA_NO_NODE)
@@ -1978,8 +2000,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1978 if (result) 2000 if (result)
1979 goto put_pci; 2001 goto put_pci;
1980 2002
2003 quirks |= check_dell_samsung_bug(pdev);
2004
1981 result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops, 2005 result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
1982 id->driver_data); 2006 quirks);
1983 if (result) 2007 if (result)
1984 goto release_pools; 2008 goto release_pools;
1985 2009
diff --git a/drivers/pci/dwc/pcie-hisi.c b/drivers/pci/dwc/pcie-hisi.c
index fd66a3199db7..cf9d6a9d9fd4 100644
--- a/drivers/pci/dwc/pcie-hisi.c
+++ b/drivers/pci/dwc/pcie-hisi.c
@@ -380,9 +380,13 @@ struct pci_ecam_ops hisi_pcie_platform_ops = {
380 380
381static const struct of_device_id hisi_pcie_almost_ecam_of_match[] = { 381static const struct of_device_id hisi_pcie_almost_ecam_of_match[] = {
382 { 382 {
383 .compatible = "hisilicon,pcie-almost-ecam", 383 .compatible = "hisilicon,hip06-pcie-ecam",
384 .data = (void *) &hisi_pcie_platform_ops, 384 .data = (void *) &hisi_pcie_platform_ops,
385 }, 385 },
386 {
387 .compatible = "hisilicon,hip07-pcie-ecam",
388 .data = (void *) &hisi_pcie_platform_ops,
389 },
386 {}, 390 {},
387}; 391};
388 392
diff --git a/drivers/power/avs/rockchip-io-domain.c b/drivers/power/avs/rockchip-io-domain.c
index 56bce1908be2..85812521b6ba 100644
--- a/drivers/power/avs/rockchip-io-domain.c
+++ b/drivers/power/avs/rockchip-io-domain.c
@@ -43,6 +43,10 @@
43#define RK3288_SOC_CON2_FLASH0 BIT(7) 43#define RK3288_SOC_CON2_FLASH0 BIT(7)
44#define RK3288_SOC_FLASH_SUPPLY_NUM 2 44#define RK3288_SOC_FLASH_SUPPLY_NUM 2
45 45
46#define RK3328_SOC_CON4 0x410
47#define RK3328_SOC_CON4_VCCIO2 BIT(7)
48#define RK3328_SOC_VCCIO2_SUPPLY_NUM 1
49
46#define RK3368_SOC_CON15 0x43c 50#define RK3368_SOC_CON15 0x43c
47#define RK3368_SOC_CON15_FLASH0 BIT(14) 51#define RK3368_SOC_CON15_FLASH0 BIT(14)
48#define RK3368_SOC_FLASH_SUPPLY_NUM 2 52#define RK3368_SOC_FLASH_SUPPLY_NUM 2
@@ -166,6 +170,25 @@ static void rk3288_iodomain_init(struct rockchip_iodomain *iod)
166 dev_warn(iod->dev, "couldn't update flash0 ctrl\n"); 170 dev_warn(iod->dev, "couldn't update flash0 ctrl\n");
167} 171}
168 172
173static void rk3328_iodomain_init(struct rockchip_iodomain *iod)
174{
175 int ret;
176 u32 val;
177
178 /* if no vccio2 supply we should leave things alone */
179 if (!iod->supplies[RK3328_SOC_VCCIO2_SUPPLY_NUM].reg)
180 return;
181
182 /*
183 * set vccio2 iodomain to also use this framework
184 * instead of a special gpio.
185 */
186 val = RK3328_SOC_CON4_VCCIO2 | (RK3328_SOC_CON4_VCCIO2 << 16);
187 ret = regmap_write(iod->grf, RK3328_SOC_CON4, val);
188 if (ret < 0)
189 dev_warn(iod->dev, "couldn't update vccio2 vsel ctrl\n");
190}
191
169static void rk3368_iodomain_init(struct rockchip_iodomain *iod) 192static void rk3368_iodomain_init(struct rockchip_iodomain *iod)
170{ 193{
171 int ret; 194 int ret;
@@ -247,6 +270,20 @@ static const struct rockchip_iodomain_soc_data soc_data_rk3288 = {
247 .init = rk3288_iodomain_init, 270 .init = rk3288_iodomain_init,
248}; 271};
249 272
273static const struct rockchip_iodomain_soc_data soc_data_rk3328 = {
274 .grf_offset = 0x410,
275 .supply_names = {
276 "vccio1",
277 "vccio2",
278 "vccio3",
279 "vccio4",
280 "vccio5",
281 "vccio6",
282 "pmuio",
283 },
284 .init = rk3328_iodomain_init,
285};
286
250static const struct rockchip_iodomain_soc_data soc_data_rk3368 = { 287static const struct rockchip_iodomain_soc_data soc_data_rk3368 = {
251 .grf_offset = 0x900, 288 .grf_offset = 0x900,
252 .supply_names = { 289 .supply_names = {
@@ -312,6 +349,10 @@ static const struct of_device_id rockchip_iodomain_match[] = {
312 .data = (void *)&soc_data_rk3288 349 .data = (void *)&soc_data_rk3288
313 }, 350 },
314 { 351 {
352 .compatible = "rockchip,rk3328-io-voltage-domain",
353 .data = (void *)&soc_data_rk3328
354 },
355 {
315 .compatible = "rockchip,rk3368-io-voltage-domain", 356 .compatible = "rockchip,rk3368-io-voltage-domain",
316 .data = (void *)&soc_data_rk3368 357 .data = (void *)&soc_data_rk3368
317 }, 358 },
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 776b34396144..0a16cf4bed39 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -291,18 +291,6 @@ config ARMADA_THERMAL
291 Enable this option if you want to have support for thermal management 291 Enable this option if you want to have support for thermal management
292 controller present in Armada 370 and Armada XP SoC. 292 controller present in Armada 370 and Armada XP SoC.
293 293
294config DB8500_CPUFREQ_COOLING
295 tristate "DB8500 cpufreq cooling"
296 depends on ARCH_U8500 || COMPILE_TEST
297 depends on HAS_IOMEM
298 depends on CPU_THERMAL
299 default y
300 help
301 Adds DB8500 cpufreq cooling devices, and these cooling devices can be
302 bound to thermal zone trip points. When a trip point reached, the
303 bound cpufreq cooling device turns active to set CPU frequency low to
304 cool down the CPU.
305
306config INTEL_POWERCLAMP 294config INTEL_POWERCLAMP
307 tristate "Intel PowerClamp idle injection driver" 295 tristate "Intel PowerClamp idle injection driver"
308 depends on THERMAL 296 depends on THERMAL
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 7adae2029355..c2372f10dae5 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -41,7 +41,6 @@ obj-$(CONFIG_TANGO_THERMAL) += tango_thermal.o
41obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o 41obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
42obj-$(CONFIG_MAX77620_THERMAL) += max77620_thermal.o 42obj-$(CONFIG_MAX77620_THERMAL) += max77620_thermal.o
43obj-$(CONFIG_QORIQ_THERMAL) += qoriq_thermal.o 43obj-$(CONFIG_QORIQ_THERMAL) += qoriq_thermal.o
44obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
45obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o 44obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
46obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o 45obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
47obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.o 46obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.o
diff --git a/drivers/thermal/db8500_cpufreq_cooling.c b/drivers/thermal/db8500_cpufreq_cooling.c
deleted file mode 100644
index e58bd0b658b5..000000000000
--- a/drivers/thermal/db8500_cpufreq_cooling.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * db8500_cpufreq_cooling.c - DB8500 cpufreq works as cooling device.
3 *
4 * Copyright (C) 2012 ST-Ericsson
5 * Copyright (C) 2012 Linaro Ltd.
6 *
7 * Author: Hongbo Zhang <hongbo.zhang@linaro.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/cpu_cooling.h>
21#include <linux/err.h>
22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26
27static int db8500_cpufreq_cooling_probe(struct platform_device *pdev)
28{
29 struct thermal_cooling_device *cdev;
30
31 cdev = cpufreq_cooling_register(cpu_present_mask);
32 if (IS_ERR(cdev)) {
33 int ret = PTR_ERR(cdev);
34
35 if (ret != -EPROBE_DEFER)
36 dev_err(&pdev->dev,
37 "Failed to register cooling device %d\n",
38 ret);
39
40 return ret;
41 }
42
43 platform_set_drvdata(pdev, cdev);
44
45 dev_info(&pdev->dev, "Cooling device registered: %s\n", cdev->type);
46
47 return 0;
48}
49
50static int db8500_cpufreq_cooling_remove(struct platform_device *pdev)
51{
52 struct thermal_cooling_device *cdev = platform_get_drvdata(pdev);
53
54 cpufreq_cooling_unregister(cdev);
55
56 return 0;
57}
58
59static int db8500_cpufreq_cooling_suspend(struct platform_device *pdev,
60 pm_message_t state)
61{
62 return -ENOSYS;
63}
64
65static int db8500_cpufreq_cooling_resume(struct platform_device *pdev)
66{
67 return -ENOSYS;
68}
69
70#ifdef CONFIG_OF
71static const struct of_device_id db8500_cpufreq_cooling_match[] = {
72 { .compatible = "stericsson,db8500-cpufreq-cooling" },
73 {},
74};
75MODULE_DEVICE_TABLE(of, db8500_cpufreq_cooling_match);
76#endif
77
78static struct platform_driver db8500_cpufreq_cooling_driver = {
79 .driver = {
80 .name = "db8500-cpufreq-cooling",
81 .of_match_table = of_match_ptr(db8500_cpufreq_cooling_match),
82 },
83 .probe = db8500_cpufreq_cooling_probe,
84 .suspend = db8500_cpufreq_cooling_suspend,
85 .resume = db8500_cpufreq_cooling_resume,
86 .remove = db8500_cpufreq_cooling_remove,
87};
88
89static int __init db8500_cpufreq_cooling_init(void)
90{
91 return platform_driver_register(&db8500_cpufreq_cooling_driver);
92}
93
94static void __exit db8500_cpufreq_cooling_exit(void)
95{
96 platform_driver_unregister(&db8500_cpufreq_cooling_driver);
97}
98
99/* Should be later than db8500_cpufreq_register */
100late_initcall(db8500_cpufreq_cooling_init);
101module_exit(db8500_cpufreq_cooling_exit);
102
103MODULE_AUTHOR("Hongbo Zhang <hongbo.zhang@stericsson.com>");
104MODULE_DESCRIPTION("DB8500 cpufreq cooling driver");
105MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index d7efcb632f7d..002f1ce22bd0 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -297,14 +297,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
297 } 297 }
298 298
299 /* 299 /*
300 * If the GPIO is configured as input, change the direction to output 300 * If the GPIO is not known to be already configured as output, that
301 * and set the GPIO as active. 301 * is, if gpiod_get_direction returns either GPIOF_DIR_IN or -EINVAL,
302 * change the direction to output and set the GPIO as active.
302 * Do not force the GPIO to active when it was already output as it 303 * Do not force the GPIO to active when it was already output as it
303 * could cause backlight flickering or we would enable the backlight too 304 * could cause backlight flickering or we would enable the backlight too
304 * early. Leave the decision of the initial backlight state for later. 305 * early. Leave the decision of the initial backlight state for later.
305 */ 306 */
306 if (pb->enable_gpio && 307 if (pb->enable_gpio &&
307 gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN) 308 gpiod_get_direction(pb->enable_gpio) != GPIOF_DIR_OUT)
308 gpiod_direction_output(pb->enable_gpio, 1); 309 gpiod_direction_output(pb->enable_gpio, 1);
309 310
310 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 311 pb->power_supply = devm_regulator_get(&pdev->dev, "power");
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index cc93ba4da9b5..27bc360c7ffd 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -1015,6 +1015,15 @@ cifs_dir_needs_close(struct cifsFileInfo *cfile)
1015 return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle; 1015 return !cfile->srch_inf.endOfSearch && !cfile->invalidHandle;
1016} 1016}
1017 1017
1018static bool
1019cifs_can_echo(struct TCP_Server_Info *server)
1020{
1021 if (server->tcpStatus == CifsGood)
1022 return true;
1023
1024 return false;
1025}
1026
1018struct smb_version_operations smb1_operations = { 1027struct smb_version_operations smb1_operations = {
1019 .send_cancel = send_nt_cancel, 1028 .send_cancel = send_nt_cancel,
1020 .compare_fids = cifs_compare_fids, 1029 .compare_fids = cifs_compare_fids,
@@ -1049,6 +1058,7 @@ struct smb_version_operations smb1_operations = {
1049 .get_dfs_refer = CIFSGetDFSRefer, 1058 .get_dfs_refer = CIFSGetDFSRefer,
1050 .qfs_tcon = cifs_qfs_tcon, 1059 .qfs_tcon = cifs_qfs_tcon,
1051 .is_path_accessible = cifs_is_path_accessible, 1060 .is_path_accessible = cifs_is_path_accessible,
1061 .can_echo = cifs_can_echo,
1052 .query_path_info = cifs_query_path_info, 1062 .query_path_info = cifs_query_path_info,
1053 .query_file_info = cifs_query_file_info, 1063 .query_file_info = cifs_query_file_info,
1054 .get_srv_inum = cifs_get_srv_inum, 1064 .get_srv_inum = cifs_get_srv_inum,
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index cbeeda1e94a2..d86031b6ad79 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -2489,7 +2489,7 @@ bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
2489 2489
2490int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) 2490int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
2491{ 2491{
2492 if (op->opnum == OP_ILLEGAL) 2492 if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
2493 return op_encode_hdr_size * sizeof(__be32); 2493 return op_encode_hdr_size * sizeof(__be32);
2494 2494
2495 BUG_ON(OPDESC(op)->op_rsize_bop == NULL); 2495 BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
diff --git a/fs/nsfs.c b/fs/nsfs.c
index 1656843e87d2..323f492e0822 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -91,6 +91,7 @@ slow:
91 return ERR_PTR(-ENOMEM); 91 return ERR_PTR(-ENOMEM);
92 } 92 }
93 d_instantiate(dentry, inode); 93 d_instantiate(dentry, inode);
94 dentry->d_flags |= DCACHE_RCUACCESS;
94 dentry->d_fsdata = (void *)ns->ops; 95 dentry->d_fsdata = (void *)ns->ops;
95 d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry); 96 d = atomic_long_cmpxchg(&ns->stashed, 0, (unsigned long)dentry);
96 if (d) { 97 if (d) {
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 1e712a364680..718b749fa11a 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -32,6 +32,7 @@
32#include <linux/math64.h> 32#include <linux/math64.h>
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <linux/random.h> 34#include <linux/random.h>
35#include <linux/ctype.h>
35#include "ubifs.h" 36#include "ubifs.h"
36 37
37static DEFINE_SPINLOCK(dbg_lock); 38static DEFINE_SPINLOCK(dbg_lock);
@@ -286,8 +287,10 @@ void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode)
286 break; 287 break;
287 } 288 }
288 289
289 pr_err("\t%d: %s (%s)\n", 290 pr_err("\t%d: inode %llu, type %s, len %d\n",
290 count++, dent->name, get_dent_type(dent->type)); 291 count++, (unsigned long long) le64_to_cpu(dent->inum),
292 get_dent_type(dent->type),
293 le16_to_cpu(dent->nlen));
291 294
292 fname_name(&nm) = dent->name; 295 fname_name(&nm) = dent->name;
293 fname_len(&nm) = le16_to_cpu(dent->nlen); 296 fname_len(&nm) = le16_to_cpu(dent->nlen);
@@ -464,7 +467,8 @@ void ubifs_dump_node(const struct ubifs_info *c, const void *node)
464 pr_err("(bad name length, not printing, bad or corrupted node)"); 467 pr_err("(bad name length, not printing, bad or corrupted node)");
465 else { 468 else {
466 for (i = 0; i < nlen && dent->name[i]; i++) 469 for (i = 0; i < nlen && dent->name[i]; i++)
467 pr_cont("%c", dent->name[i]); 470 pr_cont("%c", isprint(dent->name[i]) ?
471 dent->name[i] : '?');
468 } 472 }
469 pr_cont("\n"); 473 pr_cont("\n");
470 474
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 30825d882aa9..b777bddaa1dd 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -606,8 +606,8 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
606 } 606 }
607 607
608 while (1) { 608 while (1) {
609 dbg_gen("feed '%s', ino %llu, new f_pos %#x", 609 dbg_gen("ino %llu, new f_pos %#x",
610 dent->name, (unsigned long long)le64_to_cpu(dent->inum), 610 (unsigned long long)le64_to_cpu(dent->inum),
611 key_hash_flash(c, &dent->key)); 611 key_hash_flash(c, &dent->key));
612 ubifs_assert(le64_to_cpu(dent->ch.sqnum) > 612 ubifs_assert(le64_to_cpu(dent->ch.sqnum) >
613 ubifs_inode(dir)->creat_sqnum); 613 ubifs_inode(dir)->creat_sqnum);
@@ -748,6 +748,11 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
748 goto out_fname; 748 goto out_fname;
749 749
750 lock_2_inodes(dir, inode); 750 lock_2_inodes(dir, inode);
751
752 /* Handle O_TMPFILE corner case, it is allowed to link a O_TMPFILE. */
753 if (inode->i_nlink == 0)
754 ubifs_delete_orphan(c, inode->i_ino);
755
751 inc_nlink(inode); 756 inc_nlink(inode);
752 ihold(inode); 757 ihold(inode);
753 inode->i_ctime = ubifs_current_time(inode); 758 inode->i_ctime = ubifs_current_time(inode);
@@ -768,6 +773,8 @@ out_cancel:
768 dir->i_size -= sz_change; 773 dir->i_size -= sz_change;
769 dir_ui->ui_size = dir->i_size; 774 dir_ui->ui_size = dir->i_size;
770 drop_nlink(inode); 775 drop_nlink(inode);
776 if (inode->i_nlink == 0)
777 ubifs_add_orphan(c, inode->i_ino);
771 unlock_2_inodes(dir, inode); 778 unlock_2_inodes(dir, inode);
772 ubifs_release_budget(c, &req); 779 ubifs_release_budget(c, &req);
773 iput(inode); 780 iput(inode);
@@ -1068,8 +1075,10 @@ static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
1068 } 1075 }
1069 1076
1070 err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); 1077 err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm);
1071 if (err) 1078 if (err) {
1079 kfree(dev);
1072 goto out_budg; 1080 goto out_budg;
1081 }
1073 1082
1074 sz_change = CALC_DENT_SIZE(fname_len(&nm)); 1083 sz_change = CALC_DENT_SIZE(fname_len(&nm));
1075 1084
@@ -1316,9 +1325,6 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
1316 unsigned int uninitialized_var(saved_nlink); 1325 unsigned int uninitialized_var(saved_nlink);
1317 struct fscrypt_name old_nm, new_nm; 1326 struct fscrypt_name old_nm, new_nm;
1318 1327
1319 if (flags & ~RENAME_NOREPLACE)
1320 return -EINVAL;
1321
1322 /* 1328 /*
1323 * Budget request settings: deletion direntry, new direntry, removing 1329 * Budget request settings: deletion direntry, new direntry, removing
1324 * the old inode, and changing old and new parent directory inodes. 1330 * the old inode, and changing old and new parent directory inodes.
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h
index 1d4f365d8f03..f6d9af3efa45 100644
--- a/include/crypto/internal/hash.h
+++ b/include/crypto/internal/hash.h
@@ -166,6 +166,16 @@ static inline struct ahash_instance *ahash_alloc_instance(
166 return crypto_alloc_instance2(name, alg, ahash_instance_headroom()); 166 return crypto_alloc_instance2(name, alg, ahash_instance_headroom());
167} 167}
168 168
169static inline void ahash_request_complete(struct ahash_request *req, int err)
170{
171 req->base.complete(&req->base, err);
172}
173
174static inline u32 ahash_request_flags(struct ahash_request *req)
175{
176 return req->base.flags;
177}
178
169static inline struct crypto_ahash *crypto_spawn_ahash( 179static inline struct crypto_ahash *crypto_spawn_ahash(
170 struct crypto_ahash_spawn *spawn) 180 struct crypto_ahash_spawn *spawn)
171{ 181{
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 87165f06a307..a5ce0bbeadb5 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -120,6 +120,13 @@ struct cpufreq_policy {
120 bool fast_switch_possible; 120 bool fast_switch_possible;
121 bool fast_switch_enabled; 121 bool fast_switch_enabled;
122 122
123 /*
124 * Preferred average time interval between consecutive invocations of
125 * the driver to set the frequency for this policy. To be set by the
126 * scaling driver (0, which is the default, means no preference).
127 */
128 unsigned int transition_delay_us;
129
123 /* Cached frequency lookup from cpufreq_driver_resolve_freq. */ 130 /* Cached frequency lookup from cpufreq_driver_resolve_freq. */
124 unsigned int cached_target_freq; 131 unsigned int cached_target_freq;
125 int cached_resolved_idx; 132 int cached_resolved_idx;
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index e0acb0e5243b..6c220e4ebb6b 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -27,6 +27,7 @@
27#define DEVFREQ_POSTCHANGE (1) 27#define DEVFREQ_POSTCHANGE (1)
28 28
29struct devfreq; 29struct devfreq;
30struct devfreq_governor;
30 31
31/** 32/**
32 * struct devfreq_dev_status - Data given from devfreq user device to 33 * struct devfreq_dev_status - Data given from devfreq user device to
@@ -101,35 +102,6 @@ struct devfreq_dev_profile {
101}; 102};
102 103
103/** 104/**
104 * struct devfreq_governor - Devfreq policy governor
105 * @node: list node - contains registered devfreq governors
106 * @name: Governor's name
107 * @immutable: Immutable flag for governor. If the value is 1,
108 * this govenror is never changeable to other governor.
109 * @get_target_freq: Returns desired operating frequency for the device.
110 * Basically, get_target_freq will run
111 * devfreq_dev_profile.get_dev_status() to get the
112 * status of the device (load = busy_time / total_time).
113 * If no_central_polling is set, this callback is called
114 * only with update_devfreq() notified by OPP.
115 * @event_handler: Callback for devfreq core framework to notify events
116 * to governors. Events include per device governor
117 * init and exit, opp changes out of devfreq, suspend
118 * and resume of per device devfreq during device idle.
119 *
120 * Note that the callbacks are called with devfreq->lock locked by devfreq.
121 */
122struct devfreq_governor {
123 struct list_head node;
124
125 const char name[DEVFREQ_NAME_LEN];
126 const unsigned int immutable;
127 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
128 int (*event_handler)(struct devfreq *devfreq,
129 unsigned int event, void *data);
130};
131
132/**
133 * struct devfreq - Device devfreq structure 105 * struct devfreq - Device devfreq structure
134 * @node: list node - contains the devices with devfreq that have been 106 * @node: list node - contains the devices with devfreq that have been
135 * registered. 107 * registered.
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
index aab032a6ae61..97ca105347a6 100644
--- a/include/linux/mmc/sdio_func.h
+++ b/include/linux/mmc/sdio_func.h
@@ -53,7 +53,7 @@ struct sdio_func {
53 unsigned int state; /* function state */ 53 unsigned int state; /* function state */
54#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */ 54#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
55 55
56 u8 tmpbuf[4]; /* DMA:able scratch buffer */ 56 u8 *tmpbuf; /* DMA:able scratch buffer */
57 57
58 unsigned num_info; /* number of info strings */ 58 unsigned num_info; /* number of info strings */
59 const char **info; /* info strings */ 59 const char **info; /* info strings */
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 5339ed5bd6f9..9b6abe632587 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -20,6 +20,7 @@
20/* Defines used for the flags field in the struct generic_pm_domain */ 20/* Defines used for the flags field in the struct generic_pm_domain */
21#define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */ 21#define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */
22#define GENPD_FLAG_IRQ_SAFE (1U << 1) /* PM domain operates in atomic */ 22#define GENPD_FLAG_IRQ_SAFE (1U << 1) /* PM domain operates in atomic */
23#define GENPD_FLAG_ALWAYS_ON (1U << 2) /* PM domain is always powered on */
23 24
24enum gpd_status { 25enum gpd_status {
25 GPD_STATE_ACTIVE = 0, /* PM domain is active */ 26 GPD_STATE_ACTIVE = 0, /* PM domain is active */
diff --git a/include/linux/tick.h b/include/linux/tick.h
index a04fea19676f..fe01e68bf520 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -117,6 +117,7 @@ extern void tick_nohz_idle_enter(void);
117extern void tick_nohz_idle_exit(void); 117extern void tick_nohz_idle_exit(void);
118extern void tick_nohz_irq_exit(void); 118extern void tick_nohz_irq_exit(void);
119extern ktime_t tick_nohz_get_sleep_length(void); 119extern ktime_t tick_nohz_get_sleep_length(void);
120extern unsigned long tick_nohz_get_idle_calls(void);
120extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); 121extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
121extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); 122extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
122#else /* !CONFIG_NO_HZ_COMMON */ 123#else /* !CONFIG_NO_HZ_COMMON */
diff --git a/include/uapi/linux/ipv6_route.h b/include/uapi/linux/ipv6_route.h
index 85bbb1799df3..d496c02e14bc 100644
--- a/include/uapi/linux/ipv6_route.h
+++ b/include/uapi/linux/ipv6_route.h
@@ -35,7 +35,7 @@
35#define RTF_PREF(pref) ((pref) << 27) 35#define RTF_PREF(pref) ((pref) << 27)
36#define RTF_PREF_MASK 0x18000000 36#define RTF_PREF_MASK 0x18000000
37 37
38#define RTF_PCPU 0x40000000 38#define RTF_PCPU 0x40000000 /* read-only: can not be set by user */
39#define RTF_LOCAL 0x80000000 39#define RTF_LOCAL 0x80000000
40 40
41 41
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 7af0dcc5d755..821f9e807de5 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -617,6 +617,14 @@ static void fixup_bpf_calls(struct bpf_prog *prog)
617 if (insn->imm == BPF_FUNC_xdp_adjust_head) 617 if (insn->imm == BPF_FUNC_xdp_adjust_head)
618 prog->xdp_adjust_head = 1; 618 prog->xdp_adjust_head = 1;
619 if (insn->imm == BPF_FUNC_tail_call) { 619 if (insn->imm == BPF_FUNC_tail_call) {
620 /* If we tail call into other programs, we
621 * cannot make any assumptions since they
622 * can be replaced dynamically during runtime
623 * in the program array.
624 */
625 prog->cb_access = 1;
626 prog->xdp_adjust_head = 1;
627
620 /* mark bpf_tail_call as different opcode 628 /* mark bpf_tail_call as different opcode
621 * to avoid conditional branch in 629 * to avoid conditional branch in
622 * interpeter for every normal call 630 * interpeter for every normal call
diff --git a/kernel/irq/affinity.c b/kernel/irq/affinity.c
index d052947fe785..e2d356dd7581 100644
--- a/kernel/irq/affinity.c
+++ b/kernel/irq/affinity.c
@@ -98,7 +98,7 @@ irq_create_affinity_masks(int nvecs, const struct irq_affinity *affd)
98 int ncpus, v, vecs_to_assign, vecs_per_node; 98 int ncpus, v, vecs_to_assign, vecs_per_node;
99 99
100 /* Spread the vectors per node */ 100 /* Spread the vectors per node */
101 vecs_per_node = (affv - curvec) / nodes; 101 vecs_per_node = (affv - (curvec - affd->pre_vectors)) / nodes;
102 102
103 /* Get the cpus on this node which are in the mask */ 103 /* Get the cpus on this node which are in the mask */
104 cpumask_and(nmsk, cpu_online_mask, cpumask_of_node(n)); 104 cpumask_and(nmsk, cpu_online_mask, cpumask_of_node(n));
diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h
index c2b88490d857..c08fbd2f5ba9 100644
--- a/kernel/locking/lockdep_internals.h
+++ b/kernel/locking/lockdep_internals.h
@@ -46,13 +46,13 @@ enum {
46 (LOCKF_USED_IN_HARDIRQ_READ | LOCKF_USED_IN_SOFTIRQ_READ) 46 (LOCKF_USED_IN_HARDIRQ_READ | LOCKF_USED_IN_SOFTIRQ_READ)
47 47
48/* 48/*
49 * CONFIG_PROVE_LOCKING_SMALL is defined for sparc. Sparc requires .text, 49 * CONFIG_LOCKDEP_SMALL is defined for sparc. Sparc requires .text,
50 * .data and .bss to fit in required 32MB limit for the kernel. With 50 * .data and .bss to fit in required 32MB limit for the kernel. With
51 * PROVE_LOCKING we could go over this limit and cause system boot-up problems. 51 * CONFIG_LOCKDEP we could go over this limit and cause system boot-up problems.
52 * So, reduce the static allocations for lockdeps related structures so that 52 * So, reduce the static allocations for lockdeps related structures so that
53 * everything fits in current required size limit. 53 * everything fits in current required size limit.
54 */ 54 */
55#ifdef CONFIG_PROVE_LOCKING_SMALL 55#ifdef CONFIG_LOCKDEP_SMALL
56/* 56/*
57 * MAX_LOCKDEP_ENTRIES is the maximum number of lock dependencies 57 * MAX_LOCKDEP_ENTRIES is the maximum number of lock dependencies
58 * we track. 58 * we track.
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 54c577578da6..76877a62b5fa 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -61,6 +61,11 @@ struct sugov_cpu {
61 unsigned long util; 61 unsigned long util;
62 unsigned long max; 62 unsigned long max;
63 unsigned int flags; 63 unsigned int flags;
64
65 /* The field below is for single-CPU policies only. */
66#ifdef CONFIG_NO_HZ_COMMON
67 unsigned long saved_idle_calls;
68#endif
64}; 69};
65 70
66static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu); 71static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
@@ -93,22 +98,23 @@ static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time,
93{ 98{
94 struct cpufreq_policy *policy = sg_policy->policy; 99 struct cpufreq_policy *policy = sg_policy->policy;
95 100
101 if (sg_policy->next_freq == next_freq)
102 return;
103
104 if (sg_policy->next_freq > next_freq)
105 next_freq = (sg_policy->next_freq + next_freq) >> 1;
106
107 sg_policy->next_freq = next_freq;
96 sg_policy->last_freq_update_time = time; 108 sg_policy->last_freq_update_time = time;
97 109
98 if (policy->fast_switch_enabled) { 110 if (policy->fast_switch_enabled) {
99 if (sg_policy->next_freq == next_freq) {
100 trace_cpu_frequency(policy->cur, smp_processor_id());
101 return;
102 }
103 sg_policy->next_freq = next_freq;
104 next_freq = cpufreq_driver_fast_switch(policy, next_freq); 111 next_freq = cpufreq_driver_fast_switch(policy, next_freq);
105 if (next_freq == CPUFREQ_ENTRY_INVALID) 112 if (next_freq == CPUFREQ_ENTRY_INVALID)
106 return; 113 return;
107 114
108 policy->cur = next_freq; 115 policy->cur = next_freq;
109 trace_cpu_frequency(next_freq, smp_processor_id()); 116 trace_cpu_frequency(next_freq, smp_processor_id());
110 } else if (sg_policy->next_freq != next_freq) { 117 } else {
111 sg_policy->next_freq = next_freq;
112 sg_policy->work_in_progress = true; 118 sg_policy->work_in_progress = true;
113 irq_work_queue(&sg_policy->irq_work); 119 irq_work_queue(&sg_policy->irq_work);
114 } 120 }
@@ -192,6 +198,19 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, unsigned long *util,
192 sg_cpu->iowait_boost >>= 1; 198 sg_cpu->iowait_boost >>= 1;
193} 199}
194 200
201#ifdef CONFIG_NO_HZ_COMMON
202static bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu)
203{
204 unsigned long idle_calls = tick_nohz_get_idle_calls();
205 bool ret = idle_calls == sg_cpu->saved_idle_calls;
206
207 sg_cpu->saved_idle_calls = idle_calls;
208 return ret;
209}
210#else
211static inline bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) { return false; }
212#endif /* CONFIG_NO_HZ_COMMON */
213
195static void sugov_update_single(struct update_util_data *hook, u64 time, 214static void sugov_update_single(struct update_util_data *hook, u64 time,
196 unsigned int flags) 215 unsigned int flags)
197{ 216{
@@ -200,6 +219,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
200 struct cpufreq_policy *policy = sg_policy->policy; 219 struct cpufreq_policy *policy = sg_policy->policy;
201 unsigned long util, max; 220 unsigned long util, max;
202 unsigned int next_f; 221 unsigned int next_f;
222 bool busy;
203 223
204 sugov_set_iowait_boost(sg_cpu, time, flags); 224 sugov_set_iowait_boost(sg_cpu, time, flags);
205 sg_cpu->last_update = time; 225 sg_cpu->last_update = time;
@@ -207,40 +227,37 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
207 if (!sugov_should_update_freq(sg_policy, time)) 227 if (!sugov_should_update_freq(sg_policy, time))
208 return; 228 return;
209 229
230 busy = sugov_cpu_is_busy(sg_cpu);
231
210 if (flags & SCHED_CPUFREQ_RT_DL) { 232 if (flags & SCHED_CPUFREQ_RT_DL) {
211 next_f = policy->cpuinfo.max_freq; 233 next_f = policy->cpuinfo.max_freq;
212 } else { 234 } else {
213 sugov_get_util(&util, &max); 235 sugov_get_util(&util, &max);
214 sugov_iowait_boost(sg_cpu, &util, &max); 236 sugov_iowait_boost(sg_cpu, &util, &max);
215 next_f = get_next_freq(sg_policy, util, max); 237 next_f = get_next_freq(sg_policy, util, max);
238 /*
239 * Do not reduce the frequency if the CPU has not been idle
240 * recently, as the reduction is likely to be premature then.
241 */
242 if (busy && next_f < sg_policy->next_freq)
243 next_f = sg_policy->next_freq;
216 } 244 }
217 sugov_update_commit(sg_policy, time, next_f); 245 sugov_update_commit(sg_policy, time, next_f);
218} 246}
219 247
220static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, 248static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu)
221 unsigned long util, unsigned long max,
222 unsigned int flags)
223{ 249{
224 struct sugov_policy *sg_policy = sg_cpu->sg_policy; 250 struct sugov_policy *sg_policy = sg_cpu->sg_policy;
225 struct cpufreq_policy *policy = sg_policy->policy; 251 struct cpufreq_policy *policy = sg_policy->policy;
226 unsigned int max_f = policy->cpuinfo.max_freq;
227 u64 last_freq_update_time = sg_policy->last_freq_update_time; 252 u64 last_freq_update_time = sg_policy->last_freq_update_time;
253 unsigned long util = 0, max = 1;
228 unsigned int j; 254 unsigned int j;
229 255
230 if (flags & SCHED_CPUFREQ_RT_DL)
231 return max_f;
232
233 sugov_iowait_boost(sg_cpu, &util, &max);
234
235 for_each_cpu(j, policy->cpus) { 256 for_each_cpu(j, policy->cpus) {
236 struct sugov_cpu *j_sg_cpu; 257 struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j);
237 unsigned long j_util, j_max; 258 unsigned long j_util, j_max;
238 s64 delta_ns; 259 s64 delta_ns;
239 260
240 if (j == smp_processor_id())
241 continue;
242
243 j_sg_cpu = &per_cpu(sugov_cpu, j);
244 /* 261 /*
245 * If the CPU utilization was last updated before the previous 262 * If the CPU utilization was last updated before the previous
246 * frequency update and the time elapsed between the last update 263 * frequency update and the time elapsed between the last update
@@ -254,7 +271,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu,
254 continue; 271 continue;
255 } 272 }
256 if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL) 273 if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL)
257 return max_f; 274 return policy->cpuinfo.max_freq;
258 275
259 j_util = j_sg_cpu->util; 276 j_util = j_sg_cpu->util;
260 j_max = j_sg_cpu->max; 277 j_max = j_sg_cpu->max;
@@ -289,7 +306,11 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
289 sg_cpu->last_update = time; 306 sg_cpu->last_update = time;
290 307
291 if (sugov_should_update_freq(sg_policy, time)) { 308 if (sugov_should_update_freq(sg_policy, time)) {
292 next_f = sugov_next_freq_shared(sg_cpu, util, max, flags); 309 if (flags & SCHED_CPUFREQ_RT_DL)
310 next_f = sg_policy->policy->cpuinfo.max_freq;
311 else
312 next_f = sugov_next_freq_shared(sg_cpu);
313
293 sugov_update_commit(sg_policy, time, next_f); 314 sugov_update_commit(sg_policy, time, next_f);
294 } 315 }
295 316
@@ -473,7 +494,6 @@ static int sugov_init(struct cpufreq_policy *policy)
473{ 494{
474 struct sugov_policy *sg_policy; 495 struct sugov_policy *sg_policy;
475 struct sugov_tunables *tunables; 496 struct sugov_tunables *tunables;
476 unsigned int lat;
477 int ret = 0; 497 int ret = 0;
478 498
479 /* State should be equivalent to EXIT */ 499 /* State should be equivalent to EXIT */
@@ -512,10 +532,16 @@ static int sugov_init(struct cpufreq_policy *policy)
512 goto stop_kthread; 532 goto stop_kthread;
513 } 533 }
514 534
515 tunables->rate_limit_us = LATENCY_MULTIPLIER; 535 if (policy->transition_delay_us) {
516 lat = policy->cpuinfo.transition_latency / NSEC_PER_USEC; 536 tunables->rate_limit_us = policy->transition_delay_us;
517 if (lat) 537 } else {
518 tunables->rate_limit_us *= lat; 538 unsigned int lat;
539
540 tunables->rate_limit_us = LATENCY_MULTIPLIER;
541 lat = policy->cpuinfo.transition_latency / NSEC_PER_USEC;
542 if (lat)
543 tunables->rate_limit_us *= lat;
544 }
519 545
520 policy->governor_data = sg_policy; 546 policy->governor_data = sg_policy;
521 sg_policy->tunables = tunables; 547 sg_policy->tunables = tunables;
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 7fe53be86077..64c97fc130c4 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -993,6 +993,18 @@ ktime_t tick_nohz_get_sleep_length(void)
993 return ts->sleep_length; 993 return ts->sleep_length;
994} 994}
995 995
996/**
997 * tick_nohz_get_idle_calls - return the current idle calls counter value
998 *
999 * Called from the schedutil frequency scaling governor in scheduler context.
1000 */
1001unsigned long tick_nohz_get_idle_calls(void)
1002{
1003 struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
1004
1005 return ts->idle_calls;
1006}
1007
996static void tick_nohz_account_idle_ticks(struct tick_sched *ts) 1008static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
997{ 1009{
998#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE 1010#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 27bb2e61276e..dd3e91d68dc7 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5566,6 +5566,15 @@ static void clear_ftrace_pids(struct trace_array *tr)
5566 trace_free_pid_list(pid_list); 5566 trace_free_pid_list(pid_list);
5567} 5567}
5568 5568
5569void ftrace_clear_pids(struct trace_array *tr)
5570{
5571 mutex_lock(&ftrace_lock);
5572
5573 clear_ftrace_pids(tr);
5574
5575 mutex_unlock(&ftrace_lock);
5576}
5577
5569static void ftrace_pid_reset(struct trace_array *tr) 5578static void ftrace_pid_reset(struct trace_array *tr)
5570{ 5579{
5571 mutex_lock(&ftrace_lock); 5580 mutex_lock(&ftrace_lock);
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 54e7a90db848..ca47a4fa2986 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3405,11 +3405,23 @@ EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
3405int ring_buffer_iter_empty(struct ring_buffer_iter *iter) 3405int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
3406{ 3406{
3407 struct ring_buffer_per_cpu *cpu_buffer; 3407 struct ring_buffer_per_cpu *cpu_buffer;
3408 struct buffer_page *reader;
3409 struct buffer_page *head_page;
3410 struct buffer_page *commit_page;
3411 unsigned commit;
3408 3412
3409 cpu_buffer = iter->cpu_buffer; 3413 cpu_buffer = iter->cpu_buffer;
3410 3414
3411 return iter->head_page == cpu_buffer->commit_page && 3415 /* Remember, trace recording is off when iterator is in use */
3412 iter->head == rb_commit_index(cpu_buffer); 3416 reader = cpu_buffer->reader_page;
3417 head_page = cpu_buffer->head_page;
3418 commit_page = cpu_buffer->commit_page;
3419 commit = rb_page_commit(commit_page);
3420
3421 return ((iter->head_page == commit_page && iter->head == commit) ||
3422 (iter->head_page == reader && commit_page == head_page &&
3423 head_page->read == commit &&
3424 iter->head == rb_page_commit(cpu_buffer->reader_page)));
3413} 3425}
3414EXPORT_SYMBOL_GPL(ring_buffer_iter_empty); 3426EXPORT_SYMBOL_GPL(ring_buffer_iter_empty);
3415 3427
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f35109514a01..0ad75e9698f6 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6733,11 +6733,13 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
6733 return ret; 6733 return ret;
6734 6734
6735 out_reg: 6735 out_reg:
6736 ret = register_ftrace_function_probe(glob, ops, count); 6736 ret = alloc_snapshot(&global_trace);
6737 if (ret < 0)
6738 goto out;
6737 6739
6738 if (ret >= 0) 6740 ret = register_ftrace_function_probe(glob, ops, count);
6739 alloc_snapshot(&global_trace);
6740 6741
6742 out:
6741 return ret < 0 ? ret : 0; 6743 return ret < 0 ? ret : 0;
6742} 6744}
6743 6745
@@ -7402,6 +7404,7 @@ static int instance_rmdir(const char *name)
7402 7404
7403 tracing_set_nop(tr); 7405 tracing_set_nop(tr);
7404 event_trace_del_tracer(tr); 7406 event_trace_del_tracer(tr);
7407 ftrace_clear_pids(tr);
7405 ftrace_destroy_function_files(tr); 7408 ftrace_destroy_function_files(tr);
7406 tracefs_remove_recursive(tr->dir); 7409 tracefs_remove_recursive(tr->dir);
7407 free_trace_buffers(tr); 7410 free_trace_buffers(tr);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index ae1cce91fead..d19d52d600d6 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -896,6 +896,7 @@ int using_ftrace_ops_list_func(void);
896void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer); 896void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
897void ftrace_init_tracefs_toplevel(struct trace_array *tr, 897void ftrace_init_tracefs_toplevel(struct trace_array *tr,
898 struct dentry *d_tracer); 898 struct dentry *d_tracer);
899void ftrace_clear_pids(struct trace_array *tr);
899#else 900#else
900static inline int ftrace_trace_task(struct trace_array *tr) 901static inline int ftrace_trace_task(struct trace_array *tr)
901{ 902{
@@ -914,6 +915,7 @@ ftrace_init_global_array_ops(struct trace_array *tr) { }
914static inline void ftrace_reset_array_ops(struct trace_array *tr) { } 915static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
915static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { } 916static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
916static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { } 917static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
918static inline void ftrace_clear_pids(struct trace_array *tr) { }
917/* ftace_func_t type is not defined, use macro instead of static inline */ 919/* ftace_func_t type is not defined, use macro instead of static inline */
918#define ftrace_init_array_ops(tr, func) do { } while (0) 920#define ftrace_init_array_ops(tr, func) do { } while (0)
919#endif /* CONFIG_FUNCTION_TRACER */ 921#endif /* CONFIG_FUNCTION_TRACER */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 97d62c2da6c2..fa16c0f82d6e 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1103,9 +1103,6 @@ config PROVE_LOCKING
1103 1103
1104 For more details, see Documentation/locking/lockdep-design.txt. 1104 For more details, see Documentation/locking/lockdep-design.txt.
1105 1105
1106config PROVE_LOCKING_SMALL
1107 bool
1108
1109config LOCKDEP 1106config LOCKDEP
1110 bool 1107 bool
1111 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT 1108 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
@@ -1114,6 +1111,9 @@ config LOCKDEP
1114 select KALLSYMS 1111 select KALLSYMS
1115 select KALLSYMS_ALL 1112 select KALLSYMS_ALL
1116 1113
1114config LOCKDEP_SMALL
1115 bool
1116
1117config LOCK_STAT 1117config LOCK_STAT
1118 bool "Lock usage statistics" 1118 bool "Lock usage statistics"
1119 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT 1119 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
diff --git a/mm/migrate.c b/mm/migrate.c
index ed97c2c14fa8..738f1d5f8350 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -184,9 +184,9 @@ void putback_movable_pages(struct list_head *l)
184 unlock_page(page); 184 unlock_page(page);
185 put_page(page); 185 put_page(page);
186 } else { 186 } else {
187 putback_lru_page(page);
188 dec_node_page_state(page, NR_ISOLATED_ANON + 187 dec_node_page_state(page, NR_ISOLATED_ANON +
189 page_is_file_cache(page)); 188 page_is_file_cache(page));
189 putback_lru_page(page);
190 } 190 }
191 } 191 }
192} 192}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f3d603cef2c0..07efbc3a8656 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1090,10 +1090,10 @@ static void free_pcppages_bulk(struct zone *zone, int count,
1090{ 1090{
1091 int migratetype = 0; 1091 int migratetype = 0;
1092 int batch_free = 0; 1092 int batch_free = 0;
1093 unsigned long nr_scanned, flags; 1093 unsigned long nr_scanned;
1094 bool isolated_pageblocks; 1094 bool isolated_pageblocks;
1095 1095
1096 spin_lock_irqsave(&zone->lock, flags); 1096 spin_lock(&zone->lock);
1097 isolated_pageblocks = has_isolate_pageblock(zone); 1097 isolated_pageblocks = has_isolate_pageblock(zone);
1098 nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED); 1098 nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
1099 if (nr_scanned) 1099 if (nr_scanned)
@@ -1142,7 +1142,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,
1142 trace_mm_page_pcpu_drain(page, 0, mt); 1142 trace_mm_page_pcpu_drain(page, 0, mt);
1143 } while (--count && --batch_free && !list_empty(list)); 1143 } while (--count && --batch_free && !list_empty(list));
1144 } 1144 }
1145 spin_unlock_irqrestore(&zone->lock, flags); 1145 spin_unlock(&zone->lock);
1146} 1146}
1147 1147
1148static void free_one_page(struct zone *zone, 1148static void free_one_page(struct zone *zone,
@@ -1150,9 +1150,8 @@ static void free_one_page(struct zone *zone,
1150 unsigned int order, 1150 unsigned int order,
1151 int migratetype) 1151 int migratetype)
1152{ 1152{
1153 unsigned long nr_scanned, flags; 1153 unsigned long nr_scanned;
1154 spin_lock_irqsave(&zone->lock, flags); 1154 spin_lock(&zone->lock);
1155 __count_vm_events(PGFREE, 1 << order);
1156 nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED); 1155 nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
1157 if (nr_scanned) 1156 if (nr_scanned)
1158 __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, -nr_scanned); 1157 __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, -nr_scanned);
@@ -1162,7 +1161,7 @@ static void free_one_page(struct zone *zone,
1162 migratetype = get_pfnblock_migratetype(page, pfn); 1161 migratetype = get_pfnblock_migratetype(page, pfn);
1163 } 1162 }
1164 __free_one_page(page, pfn, zone, order, migratetype); 1163 __free_one_page(page, pfn, zone, order, migratetype);
1165 spin_unlock_irqrestore(&zone->lock, flags); 1164 spin_unlock(&zone->lock);
1166} 1165}
1167 1166
1168static void __meminit __init_single_page(struct page *page, unsigned long pfn, 1167static void __meminit __init_single_page(struct page *page, unsigned long pfn,
@@ -1240,6 +1239,7 @@ void __meminit reserve_bootmem_region(phys_addr_t start, phys_addr_t end)
1240 1239
1241static void __free_pages_ok(struct page *page, unsigned int order) 1240static void __free_pages_ok(struct page *page, unsigned int order)
1242{ 1241{
1242 unsigned long flags;
1243 int migratetype; 1243 int migratetype;
1244 unsigned long pfn = page_to_pfn(page); 1244 unsigned long pfn = page_to_pfn(page);
1245 1245
@@ -1247,7 +1247,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
1247 return; 1247 return;
1248 1248
1249 migratetype = get_pfnblock_migratetype(page, pfn); 1249 migratetype = get_pfnblock_migratetype(page, pfn);
1250 local_irq_save(flags);
1251 __count_vm_events(PGFREE, 1 << order);
1250 free_one_page(page_zone(page), page, pfn, order, migratetype); 1252 free_one_page(page_zone(page), page, pfn, order, migratetype);
1253 local_irq_restore(flags);
1251} 1254}
1252 1255
1253static void __init __free_pages_boot_core(struct page *page, unsigned int order) 1256static void __init __free_pages_boot_core(struct page *page, unsigned int order)
@@ -2219,9 +2222,8 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
2219 int migratetype, bool cold) 2222 int migratetype, bool cold)
2220{ 2223{
2221 int i, alloced = 0; 2224 int i, alloced = 0;
2222 unsigned long flags;
2223 2225
2224 spin_lock_irqsave(&zone->lock, flags); 2226 spin_lock(&zone->lock);
2225 for (i = 0; i < count; ++i) { 2227 for (i = 0; i < count; ++i) {
2226 struct page *page = __rmqueue(zone, order, migratetype); 2228 struct page *page = __rmqueue(zone, order, migratetype);
2227 if (unlikely(page == NULL)) 2229 if (unlikely(page == NULL))
@@ -2257,7 +2259,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
2257 * pages added to the pcp list. 2259 * pages added to the pcp list.
2258 */ 2260 */
2259 __mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order)); 2261 __mod_zone_page_state(zone, NR_FREE_PAGES, -(i << order));
2260 spin_unlock_irqrestore(&zone->lock, flags); 2262 spin_unlock(&zone->lock);
2261 return alloced; 2263 return alloced;
2262} 2264}
2263 2265
@@ -2485,20 +2487,17 @@ void free_hot_cold_page(struct page *page, bool cold)
2485{ 2487{
2486 struct zone *zone = page_zone(page); 2488 struct zone *zone = page_zone(page);
2487 struct per_cpu_pages *pcp; 2489 struct per_cpu_pages *pcp;
2490 unsigned long flags;
2488 unsigned long pfn = page_to_pfn(page); 2491 unsigned long pfn = page_to_pfn(page);
2489 int migratetype; 2492 int migratetype;
2490 2493
2491 if (in_interrupt()) {
2492 __free_pages_ok(page, 0);
2493 return;
2494 }
2495
2496 if (!free_pcp_prepare(page)) 2494 if (!free_pcp_prepare(page))
2497 return; 2495 return;
2498 2496
2499 migratetype = get_pfnblock_migratetype(page, pfn); 2497 migratetype = get_pfnblock_migratetype(page, pfn);
2500 set_pcppage_migratetype(page, migratetype); 2498 set_pcppage_migratetype(page, migratetype);
2501 preempt_disable(); 2499 local_irq_save(flags);
2500 __count_vm_event(PGFREE);
2502 2501
2503 /* 2502 /*
2504 * We only track unmovable, reclaimable and movable on pcp lists. 2503 * We only track unmovable, reclaimable and movable on pcp lists.
@@ -2515,7 +2514,6 @@ void free_hot_cold_page(struct page *page, bool cold)
2515 migratetype = MIGRATE_MOVABLE; 2514 migratetype = MIGRATE_MOVABLE;
2516 } 2515 }
2517 2516
2518 __count_vm_event(PGFREE);
2519 pcp = &this_cpu_ptr(zone->pageset)->pcp; 2517 pcp = &this_cpu_ptr(zone->pageset)->pcp;
2520 if (!cold) 2518 if (!cold)
2521 list_add(&page->lru, &pcp->lists[migratetype]); 2519 list_add(&page->lru, &pcp->lists[migratetype]);
@@ -2529,7 +2527,7 @@ void free_hot_cold_page(struct page *page, bool cold)
2529 } 2527 }
2530 2528
2531out: 2529out:
2532 preempt_enable(); 2530 local_irq_restore(flags);
2533} 2531}
2534 2532
2535/* 2533/*
@@ -2654,8 +2652,6 @@ static struct page *__rmqueue_pcplist(struct zone *zone, int migratetype,
2654{ 2652{
2655 struct page *page; 2653 struct page *page;
2656 2654
2657 VM_BUG_ON(in_interrupt());
2658
2659 do { 2655 do {
2660 if (list_empty(list)) { 2656 if (list_empty(list)) {
2661 pcp->count += rmqueue_bulk(zone, 0, 2657 pcp->count += rmqueue_bulk(zone, 0,
@@ -2686,8 +2682,9 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone,
2686 struct list_head *list; 2682 struct list_head *list;
2687 bool cold = ((gfp_flags & __GFP_COLD) != 0); 2683 bool cold = ((gfp_flags & __GFP_COLD) != 0);
2688 struct page *page; 2684 struct page *page;
2685 unsigned long flags;
2689 2686
2690 preempt_disable(); 2687 local_irq_save(flags);
2691 pcp = &this_cpu_ptr(zone->pageset)->pcp; 2688 pcp = &this_cpu_ptr(zone->pageset)->pcp;
2692 list = &pcp->lists[migratetype]; 2689 list = &pcp->lists[migratetype];
2693 page = __rmqueue_pcplist(zone, migratetype, cold, pcp, list); 2690 page = __rmqueue_pcplist(zone, migratetype, cold, pcp, list);
@@ -2695,7 +2692,7 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone,
2695 __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order); 2692 __count_zid_vm_events(PGALLOC, page_zonenum(page), 1 << order);
2696 zone_statistics(preferred_zone, zone); 2693 zone_statistics(preferred_zone, zone);
2697 } 2694 }
2698 preempt_enable(); 2695 local_irq_restore(flags);
2699 return page; 2696 return page;
2700} 2697}
2701 2698
@@ -2711,7 +2708,7 @@ struct page *rmqueue(struct zone *preferred_zone,
2711 unsigned long flags; 2708 unsigned long flags;
2712 struct page *page; 2709 struct page *page;
2713 2710
2714 if (likely(order == 0) && !in_interrupt()) { 2711 if (likely(order == 0)) {
2715 page = rmqueue_pcplist(preferred_zone, zone, order, 2712 page = rmqueue_pcplist(preferred_zone, zone, order,
2716 gfp_flags, migratetype); 2713 gfp_flags, migratetype);
2717 goto out; 2714 goto out;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 809025ed97ea..5a4f5c5a31e8 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1768,8 +1768,7 @@ void __init init_mm_internals(void)
1768{ 1768{
1769 int ret __maybe_unused; 1769 int ret __maybe_unused;
1770 1770
1771 mm_percpu_wq = alloc_workqueue("mm_percpu_wq", 1771 mm_percpu_wq = alloc_workqueue("mm_percpu_wq", WQ_MEM_RECLAIM, 0);
1772 WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1773 1772
1774#ifdef CONFIG_SMP 1773#ifdef CONFIG_SMP
1775 ret = cpuhp_setup_state_nocalls(CPUHP_MM_VMSTAT_DEAD, "mm/vmstat:dead", 1774 ret = cpuhp_setup_state_nocalls(CPUHP_MM_VMSTAT_DEAD, "mm/vmstat:dead",
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 9424673009c1..29be2466970c 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -105,15 +105,21 @@ static void queue_process(struct work_struct *work)
105 while ((skb = skb_dequeue(&npinfo->txq))) { 105 while ((skb = skb_dequeue(&npinfo->txq))) {
106 struct net_device *dev = skb->dev; 106 struct net_device *dev = skb->dev;
107 struct netdev_queue *txq; 107 struct netdev_queue *txq;
108 unsigned int q_index;
108 109
109 if (!netif_device_present(dev) || !netif_running(dev)) { 110 if (!netif_device_present(dev) || !netif_running(dev)) {
110 kfree_skb(skb); 111 kfree_skb(skb);
111 continue; 112 continue;
112 } 113 }
113 114
114 txq = skb_get_tx_queue(dev, skb);
115
116 local_irq_save(flags); 115 local_irq_save(flags);
116 /* check if skb->queue_mapping is still valid */
117 q_index = skb_get_queue_mapping(skb);
118 if (unlikely(q_index >= dev->real_num_tx_queues)) {
119 q_index = q_index % dev->real_num_tx_queues;
120 skb_set_queue_mapping(skb, q_index);
121 }
122 txq = netdev_get_tx_queue(dev, q_index);
117 HARD_TX_LOCK(dev, txq, smp_processor_id()); 123 HARD_TX_LOCK(dev, txq, smp_processor_id());
118 if (netif_xmit_frozen_or_stopped(txq) || 124 if (netif_xmit_frozen_or_stopped(txq) ||
119 netpoll_start_xmit(skb, dev, txq) != NETDEV_TX_OK) { 125 netpoll_start_xmit(skb, dev, txq) != NETDEV_TX_OK) {
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 9f781092fda9..f86bf69cfb8d 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3082,22 +3082,32 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
3082 if (sg && csum && (mss != GSO_BY_FRAGS)) { 3082 if (sg && csum && (mss != GSO_BY_FRAGS)) {
3083 if (!(features & NETIF_F_GSO_PARTIAL)) { 3083 if (!(features & NETIF_F_GSO_PARTIAL)) {
3084 struct sk_buff *iter; 3084 struct sk_buff *iter;
3085 unsigned int frag_len;
3085 3086
3086 if (!list_skb || 3087 if (!list_skb ||
3087 !net_gso_ok(features, skb_shinfo(head_skb)->gso_type)) 3088 !net_gso_ok(features, skb_shinfo(head_skb)->gso_type))
3088 goto normal; 3089 goto normal;
3089 3090
3090 /* Split the buffer at the frag_list pointer. 3091 /* If we get here then all the required
3091 * This is based on the assumption that all 3092 * GSO features except frag_list are supported.
3092 * buffers in the chain excluding the last 3093 * Try to split the SKB to multiple GSO SKBs
3093 * containing the same amount of data. 3094 * with no frag_list.
3095 * Currently we can do that only when the buffers don't
3096 * have a linear part and all the buffers except
3097 * the last are of the same length.
3094 */ 3098 */
3099 frag_len = list_skb->len;
3095 skb_walk_frags(head_skb, iter) { 3100 skb_walk_frags(head_skb, iter) {
3101 if (frag_len != iter->len && iter->next)
3102 goto normal;
3096 if (skb_headlen(iter)) 3103 if (skb_headlen(iter))
3097 goto normal; 3104 goto normal;
3098 3105
3099 len -= iter->len; 3106 len -= iter->len;
3100 } 3107 }
3108
3109 if (len != frag_len)
3110 goto normal;
3101 } 3111 }
3102 3112
3103 /* GSO partial only requires that we trim off any excess that 3113 /* GSO partial only requires that we trim off any excess that
@@ -3807,6 +3817,7 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb,
3807 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; 3817 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
3808 serr->ee.ee_info = tstype; 3818 serr->ee.ee_info = tstype;
3809 serr->opt_stats = opt_stats; 3819 serr->opt_stats = opt_stats;
3820 serr->header.h4.iif = skb->dev ? skb->dev->ifindex : 0;
3810 if (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID) { 3821 if (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID) {
3811 serr->ee.ee_data = skb_shinfo(skb)->tskey; 3822 serr->ee.ee_data = skb_shinfo(skb)->tskey;
3812 if (sk->sk_protocol == IPPROTO_TCP && 3823 if (sk->sk_protocol == IPPROTO_TCP &&
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index ebd953bc5607..1d46d05efb0f 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -488,16 +488,15 @@ static bool ipv4_datagram_support_cmsg(const struct sock *sk,
488 return false; 488 return false;
489 489
490 /* Support IP_PKTINFO on tstamp packets if requested, to correlate 490 /* Support IP_PKTINFO on tstamp packets if requested, to correlate
491 * timestamp with egress dev. Not possible for packets without dev 491 * timestamp with egress dev. Not possible for packets without iif
492 * or without payload (SOF_TIMESTAMPING_OPT_TSONLY). 492 * or without payload (SOF_TIMESTAMPING_OPT_TSONLY).
493 */ 493 */
494 if ((!(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_CMSG)) || 494 info = PKTINFO_SKB_CB(skb);
495 (!skb->dev)) 495 if (!(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_CMSG) ||
496 !info->ipi_ifindex)
496 return false; 497 return false;
497 498
498 info = PKTINFO_SKB_CB(skb);
499 info->ipi_spec_dst.s_addr = ip_hdr(skb)->saddr; 499 info->ipi_spec_dst.s_addr = ip_hdr(skb)->saddr;
500 info->ipi_ifindex = skb->dev->ifindex;
501 return true; 500 return true;
502} 501}
503 502
@@ -591,6 +590,7 @@ static bool setsockopt_needs_rtnl(int optname)
591 case MCAST_LEAVE_GROUP: 590 case MCAST_LEAVE_GROUP:
592 case MCAST_LEAVE_SOURCE_GROUP: 591 case MCAST_LEAVE_SOURCE_GROUP:
593 case MCAST_UNBLOCK_SOURCE: 592 case MCAST_UNBLOCK_SOURCE:
593 case IP_ROUTER_ALERT:
594 return true; 594 return true;
595 } 595 }
596 return false; 596 return false;
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index c0317c940bcd..b036e85e093b 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1278,7 +1278,7 @@ static void mrtsock_destruct(struct sock *sk)
1278 struct net *net = sock_net(sk); 1278 struct net *net = sock_net(sk);
1279 struct mr_table *mrt; 1279 struct mr_table *mrt;
1280 1280
1281 rtnl_lock(); 1281 ASSERT_RTNL();
1282 ipmr_for_each_table(mrt, net) { 1282 ipmr_for_each_table(mrt, net) {
1283 if (sk == rtnl_dereference(mrt->mroute_sk)) { 1283 if (sk == rtnl_dereference(mrt->mroute_sk)) {
1284 IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; 1284 IPV4_DEVCONF_ALL(net, MC_FORWARDING)--;
@@ -1289,7 +1289,6 @@ static void mrtsock_destruct(struct sock *sk)
1289 mroute_clean_tables(mrt, false); 1289 mroute_clean_tables(mrt, false);
1290 } 1290 }
1291 } 1291 }
1292 rtnl_unlock();
1293} 1292}
1294 1293
1295/* Socket options and virtual interface manipulation. The whole 1294/* Socket options and virtual interface manipulation. The whole
@@ -1353,13 +1352,8 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
1353 if (sk != rcu_access_pointer(mrt->mroute_sk)) { 1352 if (sk != rcu_access_pointer(mrt->mroute_sk)) {
1354 ret = -EACCES; 1353 ret = -EACCES;
1355 } else { 1354 } else {
1356 /* We need to unlock here because mrtsock_destruct takes
1357 * care of rtnl itself and we can't change that due to
1358 * the IP_ROUTER_ALERT setsockopt which runs without it.
1359 */
1360 rtnl_unlock();
1361 ret = ip_ra_control(sk, 0, NULL); 1355 ret = ip_ra_control(sk, 0, NULL);
1362 goto out; 1356 goto out_unlock;
1363 } 1357 }
1364 break; 1358 break;
1365 case MRT_ADD_VIF: 1359 case MRT_ADD_VIF:
@@ -1470,7 +1464,6 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
1470 } 1464 }
1471out_unlock: 1465out_unlock:
1472 rtnl_unlock(); 1466 rtnl_unlock();
1473out:
1474 return ret; 1467 return ret;
1475} 1468}
1476 1469
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 8119e1f66e03..9d943974de2b 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -682,7 +682,9 @@ static void raw_close(struct sock *sk, long timeout)
682 /* 682 /*
683 * Raw sockets may have direct kernel references. Kill them. 683 * Raw sockets may have direct kernel references. Kill them.
684 */ 684 */
685 rtnl_lock();
685 ip_ra_control(sk, 0, NULL); 686 ip_ra_control(sk, 0, NULL);
687 rtnl_unlock();
686 688
687 sk_common_release(sk); 689 sk_common_release(sk);
688} 690}
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index eec27f87efac..e011122ebd43 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -405,9 +405,6 @@ static inline bool ipv6_datagram_support_addr(struct sock_exterr_skb *serr)
405 * At one point, excluding local errors was a quick test to identify icmp/icmp6 405 * At one point, excluding local errors was a quick test to identify icmp/icmp6
406 * errors. This is no longer true, but the test remained, so the v6 stack, 406 * errors. This is no longer true, but the test remained, so the v6 stack,
407 * unlike v4, also honors cmsg requests on all wifi and timestamp errors. 407 * unlike v4, also honors cmsg requests on all wifi and timestamp errors.
408 *
409 * Timestamp code paths do not initialize the fields expected by cmsg:
410 * the PKTINFO fields in skb->cb[]. Fill those in here.
411 */ 408 */
412static bool ip6_datagram_support_cmsg(struct sk_buff *skb, 409static bool ip6_datagram_support_cmsg(struct sk_buff *skb,
413 struct sock_exterr_skb *serr) 410 struct sock_exterr_skb *serr)
@@ -419,14 +416,9 @@ static bool ip6_datagram_support_cmsg(struct sk_buff *skb,
419 if (serr->ee.ee_origin == SO_EE_ORIGIN_LOCAL) 416 if (serr->ee.ee_origin == SO_EE_ORIGIN_LOCAL)
420 return false; 417 return false;
421 418
422 if (!skb->dev) 419 if (!IP6CB(skb)->iif)
423 return false; 420 return false;
424 421
425 if (skb->protocol == htons(ETH_P_IPV6))
426 IP6CB(skb)->iif = skb->dev->ifindex;
427 else
428 PKTINFO_SKB_CB(skb)->ipi_ifindex = skb->dev->ifindex;
429
430 return true; 422 return true;
431} 423}
432 424
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 275cac628a95..25192a3b0cd7 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -388,7 +388,6 @@ looped_back:
388 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, 388 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
389 ((&hdr->segments_left) - 389 ((&hdr->segments_left) -
390 skb_network_header(skb))); 390 skb_network_header(skb)));
391 kfree_skb(skb);
392 return -1; 391 return -1;
393 } 392 }
394 393
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index aacfb4bce153..c45b12b4431c 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -122,11 +122,14 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
122 max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs)); 122 max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs));
123 /* 123 /*
124 * RFC4291 2.5.3 124 * RFC4291 2.5.3
125 * The loopback address must not be used as the source address in IPv6
126 * packets that are sent outside of a single node. [..]
125 * A packet received on an interface with a destination address 127 * A packet received on an interface with a destination address
126 * of loopback must be dropped. 128 * of loopback must be dropped.
127 */ 129 */
128 if (!(dev->flags & IFF_LOOPBACK) && 130 if ((ipv6_addr_loopback(&hdr->saddr) ||
129 ipv6_addr_loopback(&hdr->daddr)) 131 ipv6_addr_loopback(&hdr->daddr)) &&
132 !(dev->flags & IFF_LOOPBACK))
130 goto err; 133 goto err;
131 134
132 /* RFC4291 Errata ID: 3480 135 /* RFC4291 Errata ID: 3480
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 6ba6c900ebcf..bf34d0950752 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -774,7 +774,8 @@ failure:
774 * Delete a VIF entry 774 * Delete a VIF entry
775 */ 775 */
776 776
777static int mif6_delete(struct mr6_table *mrt, int vifi, struct list_head *head) 777static int mif6_delete(struct mr6_table *mrt, int vifi, int notify,
778 struct list_head *head)
778{ 779{
779 struct mif_device *v; 780 struct mif_device *v;
780 struct net_device *dev; 781 struct net_device *dev;
@@ -820,7 +821,7 @@ static int mif6_delete(struct mr6_table *mrt, int vifi, struct list_head *head)
820 dev->ifindex, &in6_dev->cnf); 821 dev->ifindex, &in6_dev->cnf);
821 } 822 }
822 823
823 if (v->flags & MIFF_REGISTER) 824 if ((v->flags & MIFF_REGISTER) && !notify)
824 unregister_netdevice_queue(dev, head); 825 unregister_netdevice_queue(dev, head);
825 826
826 dev_put(dev); 827 dev_put(dev);
@@ -1331,7 +1332,6 @@ static int ip6mr_device_event(struct notifier_block *this,
1331 struct mr6_table *mrt; 1332 struct mr6_table *mrt;
1332 struct mif_device *v; 1333 struct mif_device *v;
1333 int ct; 1334 int ct;
1334 LIST_HEAD(list);
1335 1335
1336 if (event != NETDEV_UNREGISTER) 1336 if (event != NETDEV_UNREGISTER)
1337 return NOTIFY_DONE; 1337 return NOTIFY_DONE;
@@ -1340,10 +1340,9 @@ static int ip6mr_device_event(struct notifier_block *this,
1340 v = &mrt->vif6_table[0]; 1340 v = &mrt->vif6_table[0];
1341 for (ct = 0; ct < mrt->maxvif; ct++, v++) { 1341 for (ct = 0; ct < mrt->maxvif; ct++, v++) {
1342 if (v->dev == dev) 1342 if (v->dev == dev)
1343 mif6_delete(mrt, ct, &list); 1343 mif6_delete(mrt, ct, 1, NULL);
1344 } 1344 }
1345 } 1345 }
1346 unregister_netdevice_many(&list);
1347 1346
1348 return NOTIFY_DONE; 1347 return NOTIFY_DONE;
1349} 1348}
@@ -1552,7 +1551,7 @@ static void mroute_clean_tables(struct mr6_table *mrt, bool all)
1552 for (i = 0; i < mrt->maxvif; i++) { 1551 for (i = 0; i < mrt->maxvif; i++) {
1553 if (!all && (mrt->vif6_table[i].flags & VIFF_STATIC)) 1552 if (!all && (mrt->vif6_table[i].flags & VIFF_STATIC))
1554 continue; 1553 continue;
1555 mif6_delete(mrt, i, &list); 1554 mif6_delete(mrt, i, 0, &list);
1556 } 1555 }
1557 unregister_netdevice_many(&list); 1556 unregister_netdevice_many(&list);
1558 1557
@@ -1707,7 +1706,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, uns
1707 if (copy_from_user(&mifi, optval, sizeof(mifi_t))) 1706 if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
1708 return -EFAULT; 1707 return -EFAULT;
1709 rtnl_lock(); 1708 rtnl_lock();
1710 ret = mif6_delete(mrt, mifi, NULL); 1709 ret = mif6_delete(mrt, mifi, 0, NULL);
1711 rtnl_unlock(); 1710 rtnl_unlock();
1712 return ret; 1711 return ret;
1713 1712
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 9db1418993f2..fb174b590fd3 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1854,6 +1854,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
1854 int addr_type; 1854 int addr_type;
1855 int err = -EINVAL; 1855 int err = -EINVAL;
1856 1856
1857 /* RTF_PCPU is an internal flag; can not be set by userspace */
1858 if (cfg->fc_flags & RTF_PCPU)
1859 goto out;
1860
1857 if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128) 1861 if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
1858 goto out; 1862 goto out;
1859#ifndef CONFIG_IPV6_SUBTREES 1863#ifndef CONFIG_IPV6_SUBTREES
diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
index a855eb325b03..5f44ffed2576 100644
--- a/net/ipv6/seg6.c
+++ b/net/ipv6/seg6.c
@@ -53,6 +53,9 @@ bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len)
53 struct sr6_tlv *tlv; 53 struct sr6_tlv *tlv;
54 unsigned int tlv_len; 54 unsigned int tlv_len;
55 55
56 if (trailing < sizeof(*tlv))
57 return false;
58
56 tlv = (struct sr6_tlv *)((unsigned char *)srh + tlv_offset); 59 tlv = (struct sr6_tlv *)((unsigned char *)srh + tlv_offset);
57 tlv_len = sizeof(*tlv) + tlv->len; 60 tlv_len = sizeof(*tlv) + tlv->len;
58 61
diff --git a/net/key/af_key.c b/net/key/af_key.c
index c6252ed42c1d..be8cecc65002 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -63,8 +63,13 @@ struct pfkey_sock {
63 } u; 63 } u;
64 struct sk_buff *skb; 64 struct sk_buff *skb;
65 } dump; 65 } dump;
66 struct mutex dump_lock;
66}; 67};
67 68
69static int parse_sockaddr_pair(struct sockaddr *sa, int ext_len,
70 xfrm_address_t *saddr, xfrm_address_t *daddr,
71 u16 *family);
72
68static inline struct pfkey_sock *pfkey_sk(struct sock *sk) 73static inline struct pfkey_sock *pfkey_sk(struct sock *sk)
69{ 74{
70 return (struct pfkey_sock *)sk; 75 return (struct pfkey_sock *)sk;
@@ -139,6 +144,7 @@ static int pfkey_create(struct net *net, struct socket *sock, int protocol,
139{ 144{
140 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id); 145 struct netns_pfkey *net_pfkey = net_generic(net, pfkey_net_id);
141 struct sock *sk; 146 struct sock *sk;
147 struct pfkey_sock *pfk;
142 int err; 148 int err;
143 149
144 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 150 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
@@ -153,6 +159,9 @@ static int pfkey_create(struct net *net, struct socket *sock, int protocol,
153 if (sk == NULL) 159 if (sk == NULL)
154 goto out; 160 goto out;
155 161
162 pfk = pfkey_sk(sk);
163 mutex_init(&pfk->dump_lock);
164
156 sock->ops = &pfkey_ops; 165 sock->ops = &pfkey_ops;
157 sock_init_data(sock, sk); 166 sock_init_data(sock, sk);
158 167
@@ -281,13 +290,23 @@ static int pfkey_do_dump(struct pfkey_sock *pfk)
281 struct sadb_msg *hdr; 290 struct sadb_msg *hdr;
282 int rc; 291 int rc;
283 292
293 mutex_lock(&pfk->dump_lock);
294 if (!pfk->dump.dump) {
295 rc = 0;
296 goto out;
297 }
298
284 rc = pfk->dump.dump(pfk); 299 rc = pfk->dump.dump(pfk);
285 if (rc == -ENOBUFS) 300 if (rc == -ENOBUFS) {
286 return 0; 301 rc = 0;
302 goto out;
303 }
287 304
288 if (pfk->dump.skb) { 305 if (pfk->dump.skb) {
289 if (!pfkey_can_dump(&pfk->sk)) 306 if (!pfkey_can_dump(&pfk->sk)) {
290 return 0; 307 rc = 0;
308 goto out;
309 }
291 310
292 hdr = (struct sadb_msg *) pfk->dump.skb->data; 311 hdr = (struct sadb_msg *) pfk->dump.skb->data;
293 hdr->sadb_msg_seq = 0; 312 hdr->sadb_msg_seq = 0;
@@ -298,6 +317,9 @@ static int pfkey_do_dump(struct pfkey_sock *pfk)
298 } 317 }
299 318
300 pfkey_terminate_dump(pfk); 319 pfkey_terminate_dump(pfk);
320
321out:
322 mutex_unlock(&pfk->dump_lock);
301 return rc; 323 return rc;
302} 324}
303 325
@@ -1793,19 +1815,26 @@ static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_ms
1793 struct xfrm_address_filter *filter = NULL; 1815 struct xfrm_address_filter *filter = NULL;
1794 struct pfkey_sock *pfk = pfkey_sk(sk); 1816 struct pfkey_sock *pfk = pfkey_sk(sk);
1795 1817
1796 if (pfk->dump.dump != NULL) 1818 mutex_lock(&pfk->dump_lock);
1819 if (pfk->dump.dump != NULL) {
1820 mutex_unlock(&pfk->dump_lock);
1797 return -EBUSY; 1821 return -EBUSY;
1822 }
1798 1823
1799 proto = pfkey_satype2proto(hdr->sadb_msg_satype); 1824 proto = pfkey_satype2proto(hdr->sadb_msg_satype);
1800 if (proto == 0) 1825 if (proto == 0) {
1826 mutex_unlock(&pfk->dump_lock);
1801 return -EINVAL; 1827 return -EINVAL;
1828 }
1802 1829
1803 if (ext_hdrs[SADB_X_EXT_FILTER - 1]) { 1830 if (ext_hdrs[SADB_X_EXT_FILTER - 1]) {
1804 struct sadb_x_filter *xfilter = ext_hdrs[SADB_X_EXT_FILTER - 1]; 1831 struct sadb_x_filter *xfilter = ext_hdrs[SADB_X_EXT_FILTER - 1];
1805 1832
1806 filter = kmalloc(sizeof(*filter), GFP_KERNEL); 1833 filter = kmalloc(sizeof(*filter), GFP_KERNEL);
1807 if (filter == NULL) 1834 if (filter == NULL) {
1835 mutex_unlock(&pfk->dump_lock);
1808 return -ENOMEM; 1836 return -ENOMEM;
1837 }
1809 1838
1810 memcpy(&filter->saddr, &xfilter->sadb_x_filter_saddr, 1839 memcpy(&filter->saddr, &xfilter->sadb_x_filter_saddr,
1811 sizeof(xfrm_address_t)); 1840 sizeof(xfrm_address_t));
@@ -1821,6 +1850,7 @@ static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_ms
1821 pfk->dump.dump = pfkey_dump_sa; 1850 pfk->dump.dump = pfkey_dump_sa;
1822 pfk->dump.done = pfkey_dump_sa_done; 1851 pfk->dump.done = pfkey_dump_sa_done;
1823 xfrm_state_walk_init(&pfk->dump.u.state, proto, filter); 1852 xfrm_state_walk_init(&pfk->dump.u.state, proto, filter);
1853 mutex_unlock(&pfk->dump_lock);
1824 1854
1825 return pfkey_do_dump(pfk); 1855 return pfkey_do_dump(pfk);
1826} 1856}
@@ -1913,19 +1943,14 @@ parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)
1913 1943
1914 /* addresses present only in tunnel mode */ 1944 /* addresses present only in tunnel mode */
1915 if (t->mode == XFRM_MODE_TUNNEL) { 1945 if (t->mode == XFRM_MODE_TUNNEL) {
1916 u8 *sa = (u8 *) (rq + 1); 1946 int err;
1917 int family, socklen;
1918 1947
1919 family = pfkey_sockaddr_extract((struct sockaddr *)sa, 1948 err = parse_sockaddr_pair(
1920 &t->saddr); 1949 (struct sockaddr *)(rq + 1),
1921 if (!family) 1950 rq->sadb_x_ipsecrequest_len - sizeof(*rq),
1922 return -EINVAL; 1951 &t->saddr, &t->id.daddr, &t->encap_family);
1923 1952 if (err)
1924 socklen = pfkey_sockaddr_len(family); 1953 return err;
1925 if (pfkey_sockaddr_extract((struct sockaddr *)(sa + socklen),
1926 &t->id.daddr) != family)
1927 return -EINVAL;
1928 t->encap_family = family;
1929 } else 1954 } else
1930 t->encap_family = xp->family; 1955 t->encap_family = xp->family;
1931 1956
@@ -1945,7 +1970,11 @@ parse_ipsecrequests(struct xfrm_policy *xp, struct sadb_x_policy *pol)
1945 if (pol->sadb_x_policy_len * 8 < sizeof(struct sadb_x_policy)) 1970 if (pol->sadb_x_policy_len * 8 < sizeof(struct sadb_x_policy))
1946 return -EINVAL; 1971 return -EINVAL;
1947 1972
1948 while (len >= sizeof(struct sadb_x_ipsecrequest)) { 1973 while (len >= sizeof(*rq)) {
1974 if (len < rq->sadb_x_ipsecrequest_len ||
1975 rq->sadb_x_ipsecrequest_len < sizeof(*rq))
1976 return -EINVAL;
1977
1949 if ((err = parse_ipsecrequest(xp, rq)) < 0) 1978 if ((err = parse_ipsecrequest(xp, rq)) < 0)
1950 return err; 1979 return err;
1951 len -= rq->sadb_x_ipsecrequest_len; 1980 len -= rq->sadb_x_ipsecrequest_len;
@@ -2408,7 +2437,6 @@ out:
2408 return err; 2437 return err;
2409} 2438}
2410 2439
2411#ifdef CONFIG_NET_KEY_MIGRATE
2412static int pfkey_sockaddr_pair_size(sa_family_t family) 2440static int pfkey_sockaddr_pair_size(sa_family_t family)
2413{ 2441{
2414 return PFKEY_ALIGN8(pfkey_sockaddr_len(family) * 2); 2442 return PFKEY_ALIGN8(pfkey_sockaddr_len(family) * 2);
@@ -2420,7 +2448,7 @@ static int parse_sockaddr_pair(struct sockaddr *sa, int ext_len,
2420{ 2448{
2421 int af, socklen; 2449 int af, socklen;
2422 2450
2423 if (ext_len < pfkey_sockaddr_pair_size(sa->sa_family)) 2451 if (ext_len < 2 || ext_len < pfkey_sockaddr_pair_size(sa->sa_family))
2424 return -EINVAL; 2452 return -EINVAL;
2425 2453
2426 af = pfkey_sockaddr_extract(sa, saddr); 2454 af = pfkey_sockaddr_extract(sa, saddr);
@@ -2436,6 +2464,7 @@ static int parse_sockaddr_pair(struct sockaddr *sa, int ext_len,
2436 return 0; 2464 return 0;
2437} 2465}
2438 2466
2467#ifdef CONFIG_NET_KEY_MIGRATE
2439static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len, 2468static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len,
2440 struct xfrm_migrate *m) 2469 struct xfrm_migrate *m)
2441{ 2470{
@@ -2443,13 +2472,14 @@ static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len,
2443 struct sadb_x_ipsecrequest *rq2; 2472 struct sadb_x_ipsecrequest *rq2;
2444 int mode; 2473 int mode;
2445 2474
2446 if (len <= sizeof(struct sadb_x_ipsecrequest) || 2475 if (len < sizeof(*rq1) ||
2447 len < rq1->sadb_x_ipsecrequest_len) 2476 len < rq1->sadb_x_ipsecrequest_len ||
2477 rq1->sadb_x_ipsecrequest_len < sizeof(*rq1))
2448 return -EINVAL; 2478 return -EINVAL;
2449 2479
2450 /* old endoints */ 2480 /* old endoints */
2451 err = parse_sockaddr_pair((struct sockaddr *)(rq1 + 1), 2481 err = parse_sockaddr_pair((struct sockaddr *)(rq1 + 1),
2452 rq1->sadb_x_ipsecrequest_len, 2482 rq1->sadb_x_ipsecrequest_len - sizeof(*rq1),
2453 &m->old_saddr, &m->old_daddr, 2483 &m->old_saddr, &m->old_daddr,
2454 &m->old_family); 2484 &m->old_family);
2455 if (err) 2485 if (err)
@@ -2458,13 +2488,14 @@ static int ipsecrequests_to_migrate(struct sadb_x_ipsecrequest *rq1, int len,
2458 rq2 = (struct sadb_x_ipsecrequest *)((u8 *)rq1 + rq1->sadb_x_ipsecrequest_len); 2488 rq2 = (struct sadb_x_ipsecrequest *)((u8 *)rq1 + rq1->sadb_x_ipsecrequest_len);
2459 len -= rq1->sadb_x_ipsecrequest_len; 2489 len -= rq1->sadb_x_ipsecrequest_len;
2460 2490
2461 if (len <= sizeof(struct sadb_x_ipsecrequest) || 2491 if (len <= sizeof(*rq2) ||
2462 len < rq2->sadb_x_ipsecrequest_len) 2492 len < rq2->sadb_x_ipsecrequest_len ||
2493 rq2->sadb_x_ipsecrequest_len < sizeof(*rq2))
2463 return -EINVAL; 2494 return -EINVAL;
2464 2495
2465 /* new endpoints */ 2496 /* new endpoints */
2466 err = parse_sockaddr_pair((struct sockaddr *)(rq2 + 1), 2497 err = parse_sockaddr_pair((struct sockaddr *)(rq2 + 1),
2467 rq2->sadb_x_ipsecrequest_len, 2498 rq2->sadb_x_ipsecrequest_len - sizeof(*rq2),
2468 &m->new_saddr, &m->new_daddr, 2499 &m->new_saddr, &m->new_daddr,
2469 &m->new_family); 2500 &m->new_family);
2470 if (err) 2501 if (err)
@@ -2679,14 +2710,18 @@ static int pfkey_spddump(struct sock *sk, struct sk_buff *skb, const struct sadb
2679{ 2710{
2680 struct pfkey_sock *pfk = pfkey_sk(sk); 2711 struct pfkey_sock *pfk = pfkey_sk(sk);
2681 2712
2682 if (pfk->dump.dump != NULL) 2713 mutex_lock(&pfk->dump_lock);
2714 if (pfk->dump.dump != NULL) {
2715 mutex_unlock(&pfk->dump_lock);
2683 return -EBUSY; 2716 return -EBUSY;
2717 }
2684 2718
2685 pfk->dump.msg_version = hdr->sadb_msg_version; 2719 pfk->dump.msg_version = hdr->sadb_msg_version;
2686 pfk->dump.msg_portid = hdr->sadb_msg_pid; 2720 pfk->dump.msg_portid = hdr->sadb_msg_pid;
2687 pfk->dump.dump = pfkey_dump_sp; 2721 pfk->dump.dump = pfkey_dump_sp;
2688 pfk->dump.done = pfkey_dump_sp_done; 2722 pfk->dump.done = pfkey_dump_sp_done;
2689 xfrm_policy_walk_init(&pfk->dump.u.policy, XFRM_POLICY_TYPE_MAIN); 2723 xfrm_policy_walk_init(&pfk->dump.u.policy, XFRM_POLICY_TYPE_MAIN);
2724 mutex_unlock(&pfk->dump_lock);
2690 2725
2691 return pfkey_do_dump(pfk); 2726 return pfkey_do_dump(pfk);
2692} 2727}
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index e48724a6725e..4d7543d1a62c 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -208,6 +208,51 @@ ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
208 return len; 208 return len;
209} 209}
210 210
211static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
212 struct sk_buff *skb,
213 int rtap_vendor_space)
214{
215 struct {
216 struct ieee80211_hdr_3addr hdr;
217 u8 category;
218 u8 action_code;
219 } __packed action;
220
221 if (!sdata)
222 return;
223
224 BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
225
226 if (skb->len < rtap_vendor_space + sizeof(action) +
227 VHT_MUMIMO_GROUPS_DATA_LEN)
228 return;
229
230 if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
231 return;
232
233 skb_copy_bits(skb, rtap_vendor_space, &action, sizeof(action));
234
235 if (!ieee80211_is_action(action.hdr.frame_control))
236 return;
237
238 if (action.category != WLAN_CATEGORY_VHT)
239 return;
240
241 if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
242 return;
243
244 if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
245 return;
246
247 skb = skb_copy(skb, GFP_ATOMIC);
248 if (!skb)
249 return;
250
251 skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
252 skb_queue_tail(&sdata->skb_queue, skb);
253 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
254}
255
211/* 256/*
212 * ieee80211_add_rx_radiotap_header - add radiotap header 257 * ieee80211_add_rx_radiotap_header - add radiotap header
213 * 258 *
@@ -515,7 +560,6 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
515 struct net_device *prev_dev = NULL; 560 struct net_device *prev_dev = NULL;
516 int present_fcs_len = 0; 561 int present_fcs_len = 0;
517 unsigned int rtap_vendor_space = 0; 562 unsigned int rtap_vendor_space = 0;
518 struct ieee80211_mgmt *mgmt;
519 struct ieee80211_sub_if_data *monitor_sdata = 563 struct ieee80211_sub_if_data *monitor_sdata =
520 rcu_dereference(local->monitor_sdata); 564 rcu_dereference(local->monitor_sdata);
521 565
@@ -553,6 +597,8 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
553 return remove_monitor_info(local, origskb, rtap_vendor_space); 597 return remove_monitor_info(local, origskb, rtap_vendor_space);
554 } 598 }
555 599
600 ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_vendor_space);
601
556 /* room for the radiotap header based on driver features */ 602 /* room for the radiotap header based on driver features */
557 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb); 603 rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
558 needed_headroom = rt_hdrlen - rtap_vendor_space; 604 needed_headroom = rt_hdrlen - rtap_vendor_space;
@@ -618,23 +664,6 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
618 ieee80211_rx_stats(sdata->dev, skb->len); 664 ieee80211_rx_stats(sdata->dev, skb->len);
619 } 665 }
620 666
621 mgmt = (void *)skb->data;
622 if (monitor_sdata &&
623 skb->len >= IEEE80211_MIN_ACTION_SIZE + 1 + VHT_MUMIMO_GROUPS_DATA_LEN &&
624 ieee80211_is_action(mgmt->frame_control) &&
625 mgmt->u.action.category == WLAN_CATEGORY_VHT &&
626 mgmt->u.action.u.vht_group_notif.action_code == WLAN_VHT_ACTION_GROUPID_MGMT &&
627 is_valid_ether_addr(monitor_sdata->u.mntr.mu_follow_addr) &&
628 ether_addr_equal(mgmt->da, monitor_sdata->u.mntr.mu_follow_addr)) {
629 struct sk_buff *mu_skb = skb_copy(skb, GFP_ATOMIC);
630
631 if (mu_skb) {
632 mu_skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
633 skb_queue_tail(&monitor_sdata->skb_queue, mu_skb);
634 ieee80211_queue_work(&local->hw, &monitor_sdata->work);
635 }
636 }
637
638 if (prev_dev) { 667 if (prev_dev) {
639 skb->dev = prev_dev; 668 skb->dev = prev_dev;
640 netif_receive_skb(skb); 669 netif_receive_skb(skb);
@@ -3610,6 +3639,27 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
3610 !ether_addr_equal(bssid, hdr->addr1)) 3639 !ether_addr_equal(bssid, hdr->addr1))
3611 return false; 3640 return false;
3612 } 3641 }
3642
3643 /*
3644 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
3645 * the BSSID - we've checked that already but may have accepted
3646 * the wildcard (ff:ff:ff:ff:ff:ff).
3647 *
3648 * It also says:
3649 * The BSSID of the Data frame is determined as follows:
3650 * a) If the STA is contained within an AP or is associated
3651 * with an AP, the BSSID is the address currently in use
3652 * by the STA contained in the AP.
3653 *
3654 * So we should not accept data frames with an address that's
3655 * multicast.
3656 *
3657 * Accepting it also opens a security problem because stations
3658 * could encrypt it with the GTK and inject traffic that way.
3659 */
3660 if (ieee80211_is_data(hdr->frame_control) && multicast)
3661 return false;
3662
3613 return true; 3663 return true;
3614 case NL80211_IFTYPE_WDS: 3664 case NL80211_IFTYPE_WDS:
3615 if (bssid || !ieee80211_is_data(hdr->frame_control)) 3665 if (bssid || !ieee80211_is_data(hdr->frame_control))
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index ae5ac175b2be..9da7368b0140 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -658,7 +658,9 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
658 } 658 }
659 659
660 if (plen != len) { 660 if (plen != len) {
661 skb_pad(skb, plen - len); 661 rc = skb_pad(skb, plen - len);
662 if (rc)
663 goto out_node;
662 skb_put(skb, plen - len); 664 skb_put(skb, plen - len);
663 } 665 }
664 666
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index b70aa57319ea..e05b924618a0 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -529,20 +529,20 @@ errout:
529 return err; 529 return err;
530} 530}
531 531
532static int nla_memdup_cookie(struct tc_action *a, struct nlattr **tb) 532static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
533{ 533{
534 a->act_cookie = kzalloc(sizeof(*a->act_cookie), GFP_KERNEL); 534 struct tc_cookie *c = kzalloc(sizeof(*c), GFP_KERNEL);
535 if (!a->act_cookie) 535 if (!c)
536 return -ENOMEM; 536 return NULL;
537 537
538 a->act_cookie->data = nla_memdup(tb[TCA_ACT_COOKIE], GFP_KERNEL); 538 c->data = nla_memdup(tb[TCA_ACT_COOKIE], GFP_KERNEL);
539 if (!a->act_cookie->data) { 539 if (!c->data) {
540 kfree(a->act_cookie); 540 kfree(c);
541 return -ENOMEM; 541 return NULL;
542 } 542 }
543 a->act_cookie->len = nla_len(tb[TCA_ACT_COOKIE]); 543 c->len = nla_len(tb[TCA_ACT_COOKIE]);
544 544
545 return 0; 545 return c;
546} 546}
547 547
548struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla, 548struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
@@ -551,6 +551,7 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
551{ 551{
552 struct tc_action *a; 552 struct tc_action *a;
553 struct tc_action_ops *a_o; 553 struct tc_action_ops *a_o;
554 struct tc_cookie *cookie = NULL;
554 char act_name[IFNAMSIZ]; 555 char act_name[IFNAMSIZ];
555 struct nlattr *tb[TCA_ACT_MAX + 1]; 556 struct nlattr *tb[TCA_ACT_MAX + 1];
556 struct nlattr *kind; 557 struct nlattr *kind;
@@ -566,6 +567,18 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
566 goto err_out; 567 goto err_out;
567 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) 568 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
568 goto err_out; 569 goto err_out;
570 if (tb[TCA_ACT_COOKIE]) {
571 int cklen = nla_len(tb[TCA_ACT_COOKIE]);
572
573 if (cklen > TC_COOKIE_MAX_SIZE)
574 goto err_out;
575
576 cookie = nla_memdup_cookie(tb);
577 if (!cookie) {
578 err = -ENOMEM;
579 goto err_out;
580 }
581 }
569 } else { 582 } else {
570 err = -EINVAL; 583 err = -EINVAL;
571 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ) 584 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
@@ -604,20 +617,12 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
604 if (err < 0) 617 if (err < 0)
605 goto err_mod; 618 goto err_mod;
606 619
607 if (tb[TCA_ACT_COOKIE]) { 620 if (name == NULL && tb[TCA_ACT_COOKIE]) {
608 int cklen = nla_len(tb[TCA_ACT_COOKIE]); 621 if (a->act_cookie) {
609 622 kfree(a->act_cookie->data);
610 if (cklen > TC_COOKIE_MAX_SIZE) { 623 kfree(a->act_cookie);
611 err = -EINVAL;
612 tcf_hash_release(a, bind);
613 goto err_mod;
614 }
615
616 if (nla_memdup_cookie(a, tb) < 0) {
617 err = -ENOMEM;
618 tcf_hash_release(a, bind);
619 goto err_mod;
620 } 624 }
625 a->act_cookie = cookie;
621 } 626 }
622 627
623 /* module count goes up only when brand new policy is created 628 /* module count goes up only when brand new policy is created
@@ -632,6 +637,10 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
632err_mod: 637err_mod:
633 module_put(a_o->owner); 638 module_put(a_o->owner);
634err_out: 639err_out:
640 if (cookie) {
641 kfree(cookie->data);
642 kfree(cookie);
643 }
635 return ERR_PTR(err); 644 return ERR_PTR(err);
636} 645}
637 646
diff --git a/security/keys/gc.c b/security/keys/gc.c
index addf060399e0..9cb4fe4478a1 100644
--- a/security/keys/gc.c
+++ b/security/keys/gc.c
@@ -46,7 +46,7 @@ static unsigned long key_gc_flags;
46 * immediately unlinked. 46 * immediately unlinked.
47 */ 47 */
48struct key_type key_type_dead = { 48struct key_type key_type_dead = {
49 .name = "dead", 49 .name = ".dead",
50}; 50};
51 51
52/* 52/*
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index 52c34532c785..4ad3212adebe 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -273,7 +273,8 @@ error:
273 * Create and join an anonymous session keyring or join a named session 273 * Create and join an anonymous session keyring or join a named session
274 * keyring, creating it if necessary. A named session keyring must have Search 274 * keyring, creating it if necessary. A named session keyring must have Search
275 * permission for it to be joined. Session keyrings without this permit will 275 * permission for it to be joined. Session keyrings without this permit will
276 * be skipped over. 276 * be skipped over. It is not permitted for userspace to create or join
277 * keyrings whose name begin with a dot.
277 * 278 *
278 * If successful, the ID of the joined session keyring will be returned. 279 * If successful, the ID of the joined session keyring will be returned.
279 */ 280 */
@@ -290,12 +291,16 @@ long keyctl_join_session_keyring(const char __user *_name)
290 ret = PTR_ERR(name); 291 ret = PTR_ERR(name);
291 goto error; 292 goto error;
292 } 293 }
294
295 ret = -EPERM;
296 if (name[0] == '.')
297 goto error_name;
293 } 298 }
294 299
295 /* join the session */ 300 /* join the session */
296 ret = join_session_keyring(name); 301 ret = join_session_keyring(name);
302error_name:
297 kfree(name); 303 kfree(name);
298
299error: 304error:
300 return ret; 305 return ret;
301} 306}
@@ -1253,8 +1258,8 @@ error:
1253 * Read or set the default keyring in which request_key() will cache keys and 1258 * Read or set the default keyring in which request_key() will cache keys and
1254 * return the old setting. 1259 * return the old setting.
1255 * 1260 *
1256 * If a process keyring is specified then this will be created if it doesn't 1261 * If a thread or process keyring is specified then it will be created if it
1257 * yet exist. The old setting will be returned if successful. 1262 * doesn't yet exist. The old setting will be returned if successful.
1258 */ 1263 */
1259long keyctl_set_reqkey_keyring(int reqkey_defl) 1264long keyctl_set_reqkey_keyring(int reqkey_defl)
1260{ 1265{
@@ -1279,11 +1284,8 @@ long keyctl_set_reqkey_keyring(int reqkey_defl)
1279 1284
1280 case KEY_REQKEY_DEFL_PROCESS_KEYRING: 1285 case KEY_REQKEY_DEFL_PROCESS_KEYRING:
1281 ret = install_process_keyring_to_cred(new); 1286 ret = install_process_keyring_to_cred(new);
1282 if (ret < 0) { 1287 if (ret < 0)
1283 if (ret != -EEXIST) 1288 goto error;
1284 goto error;
1285 ret = 0;
1286 }
1287 goto set; 1289 goto set;
1288 1290
1289 case KEY_REQKEY_DEFL_DEFAULT: 1291 case KEY_REQKEY_DEFL_DEFAULT:
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index b6fdd22205b1..9139b18fc863 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -128,13 +128,18 @@ error:
128} 128}
129 129
130/* 130/*
131 * Install a fresh thread keyring directly to new credentials. This keyring is 131 * Install a thread keyring to the given credentials struct if it didn't have
132 * allowed to overrun the quota. 132 * one already. This is allowed to overrun the quota.
133 *
134 * Return: 0 if a thread keyring is now present; -errno on failure.
133 */ 135 */
134int install_thread_keyring_to_cred(struct cred *new) 136int install_thread_keyring_to_cred(struct cred *new)
135{ 137{
136 struct key *keyring; 138 struct key *keyring;
137 139
140 if (new->thread_keyring)
141 return 0;
142
138 keyring = keyring_alloc("_tid", new->uid, new->gid, new, 143 keyring = keyring_alloc("_tid", new->uid, new->gid, new,
139 KEY_POS_ALL | KEY_USR_VIEW, 144 KEY_POS_ALL | KEY_USR_VIEW,
140 KEY_ALLOC_QUOTA_OVERRUN, 145 KEY_ALLOC_QUOTA_OVERRUN,
@@ -147,7 +152,9 @@ int install_thread_keyring_to_cred(struct cred *new)
147} 152}
148 153
149/* 154/*
150 * Install a fresh thread keyring, discarding the old one. 155 * Install a thread keyring to the current task if it didn't have one already.
156 *
157 * Return: 0 if a thread keyring is now present; -errno on failure.
151 */ 158 */
152static int install_thread_keyring(void) 159static int install_thread_keyring(void)
153{ 160{
@@ -158,8 +165,6 @@ static int install_thread_keyring(void)
158 if (!new) 165 if (!new)
159 return -ENOMEM; 166 return -ENOMEM;
160 167
161 BUG_ON(new->thread_keyring);
162
163 ret = install_thread_keyring_to_cred(new); 168 ret = install_thread_keyring_to_cred(new);
164 if (ret < 0) { 169 if (ret < 0) {
165 abort_creds(new); 170 abort_creds(new);
@@ -170,17 +175,17 @@ static int install_thread_keyring(void)
170} 175}
171 176
172/* 177/*
173 * Install a process keyring directly to a credentials struct. 178 * Install a process keyring to the given credentials struct if it didn't have
179 * one already. This is allowed to overrun the quota.
174 * 180 *
175 * Returns -EEXIST if there was already a process keyring, 0 if one installed, 181 * Return: 0 if a process keyring is now present; -errno on failure.
176 * and other value on any other error
177 */ 182 */
178int install_process_keyring_to_cred(struct cred *new) 183int install_process_keyring_to_cred(struct cred *new)
179{ 184{
180 struct key *keyring; 185 struct key *keyring;
181 186
182 if (new->process_keyring) 187 if (new->process_keyring)
183 return -EEXIST; 188 return 0;
184 189
185 keyring = keyring_alloc("_pid", new->uid, new->gid, new, 190 keyring = keyring_alloc("_pid", new->uid, new->gid, new,
186 KEY_POS_ALL | KEY_USR_VIEW, 191 KEY_POS_ALL | KEY_USR_VIEW,
@@ -194,11 +199,9 @@ int install_process_keyring_to_cred(struct cred *new)
194} 199}
195 200
196/* 201/*
197 * Make sure a process keyring is installed for the current process. The 202 * Install a process keyring to the current task if it didn't have one already.
198 * existing process keyring is not replaced.
199 * 203 *
200 * Returns 0 if there is a process keyring by the end of this function, some 204 * Return: 0 if a process keyring is now present; -errno on failure.
201 * error otherwise.
202 */ 205 */
203static int install_process_keyring(void) 206static int install_process_keyring(void)
204{ 207{
@@ -212,14 +215,18 @@ static int install_process_keyring(void)
212 ret = install_process_keyring_to_cred(new); 215 ret = install_process_keyring_to_cred(new);
213 if (ret < 0) { 216 if (ret < 0) {
214 abort_creds(new); 217 abort_creds(new);
215 return ret != -EEXIST ? ret : 0; 218 return ret;
216 } 219 }
217 220
218 return commit_creds(new); 221 return commit_creds(new);
219} 222}
220 223
221/* 224/*
222 * Install a session keyring directly to a credentials struct. 225 * Install the given keyring as the session keyring of the given credentials
226 * struct, replacing the existing one if any. If the given keyring is NULL,
227 * then install a new anonymous session keyring.
228 *
229 * Return: 0 on success; -errno on failure.
223 */ 230 */
224int install_session_keyring_to_cred(struct cred *cred, struct key *keyring) 231int install_session_keyring_to_cred(struct cred *cred, struct key *keyring)
225{ 232{
@@ -254,8 +261,11 @@ int install_session_keyring_to_cred(struct cred *cred, struct key *keyring)
254} 261}
255 262
256/* 263/*
257 * Install a session keyring, discarding the old one. If a keyring is not 264 * Install the given keyring as the session keyring of the current task,
258 * supplied, an empty one is invented. 265 * replacing the existing one if any. If the given keyring is NULL, then
266 * install a new anonymous session keyring.
267 *
268 * Return: 0 on success; -errno on failure.
259 */ 269 */
260static int install_session_keyring(struct key *keyring) 270static int install_session_keyring(struct key *keyring)
261{ 271{
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index a0aa2009b0e0..20f1871874df 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -282,7 +282,7 @@ static void test_arraymap_percpu(int task, void *data)
282{ 282{
283 unsigned int nr_cpus = bpf_num_possible_cpus(); 283 unsigned int nr_cpus = bpf_num_possible_cpus();
284 int key, next_key, fd, i; 284 int key, next_key, fd, i;
285 long values[nr_cpus]; 285 long long values[nr_cpus];
286 286
287 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), 287 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key),
288 sizeof(values[0]), 2, 0); 288 sizeof(values[0]), 2, 0);
@@ -340,7 +340,7 @@ static void test_arraymap_percpu_many_keys(void)
340 * allocator more than anything else 340 * allocator more than anything else
341 */ 341 */
342 unsigned int nr_keys = 2000; 342 unsigned int nr_keys = 2000;
343 long values[nr_cpus]; 343 long long values[nr_cpus];
344 int key, fd, i; 344 int key, fd, i;
345 345
346 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), 346 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key),
diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
new file mode 100644
index 000000000000..bab5ff7c607e
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-pid.tc
@@ -0,0 +1,117 @@
1#!/bin/sh
2# description: ftrace - function pid filters
3
4# Make sure that function pid matching filter works.
5# Also test it on an instance directory
6
7if ! grep -q function available_tracers; then
8 echo "no function tracer configured"
9 exit_unsupported
10fi
11
12if [ ! -f set_ftrace_pid ]; then
13 echo "set_ftrace_pid not found? Is function tracer not set?"
14 exit_unsupported
15fi
16
17if [ ! -f set_ftrace_filter ]; then
18 echo "set_ftrace_filter not found? Is function tracer not set?"
19 exit_unsupported
20fi
21
22do_function_fork=1
23
24if [ ! -f options/function-fork ]; then
25 do_function_fork=0
26 echo "no option for function-fork found. Option will not be tested."
27fi
28
29read PID _ < /proc/self/stat
30
31if [ $do_function_fork -eq 1 ]; then
32 # default value of function-fork option
33 orig_value=`grep function-fork trace_options`
34fi
35
36do_reset() {
37 reset_tracer
38 clear_trace
39 enable_tracing
40 echo > set_ftrace_filter
41 echo > set_ftrace_pid
42
43 if [ $do_function_fork -eq 0 ]; then
44 return
45 fi
46
47 echo $orig_value > trace_options
48}
49
50fail() { # msg
51 do_reset
52 echo $1
53 exit $FAIL
54}
55
56yield() {
57 ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
58}
59
60do_test() {
61 disable_tracing
62
63 echo do_execve* > set_ftrace_filter
64 echo *do_fork >> set_ftrace_filter
65
66 echo $PID > set_ftrace_pid
67 echo function > current_tracer
68
69 if [ $do_function_fork -eq 1 ]; then
70 # don't allow children to be traced
71 echo nofunction-fork > trace_options
72 fi
73
74 enable_tracing
75 yield
76
77 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
78 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
79
80 # count_other should be 0
81 if [ $count_pid -eq 0 -o $count_other -ne 0 ]; then
82 fail "PID filtering not working?"
83 fi
84
85 disable_tracing
86 clear_trace
87
88 if [ $do_function_fork -eq 0 ]; then
89 return
90 fi
91
92 # allow children to be traced
93 echo function-fork > trace_options
94
95 enable_tracing
96 yield
97
98 count_pid=`cat trace | grep -v ^# | grep $PID | wc -l`
99 count_other=`cat trace | grep -v ^# | grep -v $PID | wc -l`
100
101 # count_other should NOT be 0
102 if [ $count_pid -eq 0 -o $count_other -eq 0 ]; then
103 fail "PID filtering not following fork?"
104 fi
105}
106
107do_test
108
109mkdir instances/foo
110cd instances/foo
111do_test
112cd ../../
113rmdir instances/foo
114
115do_reset
116
117exit 0
diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/selftests/net/psock_fanout.c
index 412459369686..e62bb354820c 100644
--- a/tools/testing/selftests/net/psock_fanout.c
+++ b/tools/testing/selftests/net/psock_fanout.c
@@ -75,7 +75,7 @@ static int sock_fanout_open(uint16_t typeflags, int num_packets)
75{ 75{
76 int fd, val; 76 int fd, val;
77 77
78 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); 78 fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
79 if (fd < 0) { 79 if (fd < 0) {
80 perror("socket packet"); 80 perror("socket packet");
81 exit(1); 81 exit(1);
@@ -95,6 +95,24 @@ static int sock_fanout_open(uint16_t typeflags, int num_packets)
95 return fd; 95 return fd;
96} 96}
97 97
98static void sock_fanout_set_cbpf(int fd)
99{
100 struct sock_filter bpf_filter[] = {
101 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 80), /* ldb [80] */
102 BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
103 };
104 struct sock_fprog bpf_prog;
105
106 bpf_prog.filter = bpf_filter;
107 bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter);
108
109 if (setsockopt(fd, SOL_PACKET, PACKET_FANOUT_DATA, &bpf_prog,
110 sizeof(bpf_prog))) {
111 perror("fanout data cbpf");
112 exit(1);
113 }
114}
115
98static void sock_fanout_set_ebpf(int fd) 116static void sock_fanout_set_ebpf(int fd)
99{ 117{
100 const int len_off = __builtin_offsetof(struct __sk_buff, len); 118 const int len_off = __builtin_offsetof(struct __sk_buff, len);
@@ -270,7 +288,7 @@ static int test_datapath(uint16_t typeflags, int port_off,
270 exit(1); 288 exit(1);
271 } 289 }
272 if (type == PACKET_FANOUT_CBPF) 290 if (type == PACKET_FANOUT_CBPF)
273 sock_setfilter(fds[0], SOL_PACKET, PACKET_FANOUT_DATA); 291 sock_fanout_set_cbpf(fds[0]);
274 else if (type == PACKET_FANOUT_EBPF) 292 else if (type == PACKET_FANOUT_EBPF)
275 sock_fanout_set_ebpf(fds[0]); 293 sock_fanout_set_ebpf(fds[0]);
276 294
diff --git a/tools/testing/selftests/net/psock_lib.h b/tools/testing/selftests/net/psock_lib.h
index a77da88bf946..7d990d6c861b 100644
--- a/tools/testing/selftests/net/psock_lib.h
+++ b/tools/testing/selftests/net/psock_lib.h
@@ -38,7 +38,7 @@
38# define __maybe_unused __attribute__ ((__unused__)) 38# define __maybe_unused __attribute__ ((__unused__))
39#endif 39#endif
40 40
41static __maybe_unused void sock_setfilter(int fd, int lvl, int optnum) 41static __maybe_unused void pair_udp_setfilter(int fd)
42{ 42{
43 /* the filter below checks for all of the following conditions that 43 /* the filter below checks for all of the following conditions that
44 * are based on the contents of create_payload() 44 * are based on the contents of create_payload()
@@ -76,23 +76,16 @@ static __maybe_unused void sock_setfilter(int fd, int lvl, int optnum)
76 }; 76 };
77 struct sock_fprog bpf_prog; 77 struct sock_fprog bpf_prog;
78 78
79 if (lvl == SOL_PACKET && optnum == PACKET_FANOUT_DATA)
80 bpf_filter[5].code = 0x16; /* RET A */
81
82 bpf_prog.filter = bpf_filter; 79 bpf_prog.filter = bpf_filter;
83 bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter); 80 bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter);
84 if (setsockopt(fd, lvl, optnum, &bpf_prog, 81
82 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog,
85 sizeof(bpf_prog))) { 83 sizeof(bpf_prog))) {
86 perror("setsockopt SO_ATTACH_FILTER"); 84 perror("setsockopt SO_ATTACH_FILTER");
87 exit(1); 85 exit(1);
88 } 86 }
89} 87}
90 88
91static __maybe_unused void pair_udp_setfilter(int fd)
92{
93 sock_setfilter(fd, SOL_SOCKET, SO_ATTACH_FILTER);
94}
95
96static __maybe_unused void pair_udp_open(int fds[], uint16_t port) 89static __maybe_unused void pair_udp_open(int fds[], uint16_t port)
97{ 90{
98 struct sockaddr_in saddr, daddr; 91 struct sockaddr_in saddr, daddr;