Compare

182d918a68f69b693e59c64af2572bdde07cbed2..f90f8afb61beb268ca8092e7f3a826b520d3e8da

ASoC: SOF: sof-client: Use event-handler mutex consistently

Protect IPC RX and FW state handler list unregister/dispatch paths with
client_event_handler_mutex to match list registration and locking
comments.

Fixes: 5c19da34df02 ("ASoC: SOF: Use guard()/scoped_guard() for mutex locks where it makes sense")
Cc: stable@vger.kernel.org
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://patch.msgid.link/20261008090143.15158-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

Peter Ujfalusi <peter.ujfalusi@linux.intel.com> · 2026-10-08 09:01 UTC · committed by Mark Brown

Browse files
518 files changed, +7082 −2946
modified .mailmap
@@ -286,6 +286,8 @@ Ed L. Cashin <ecashin@coraid.com>
286 286 Elliot Berman <quic_eberman@quicinc.com> <eberman@codeaurora.org>
287 287 Enric Balletbo i Serra <eballetbo@kernel.org> <enric.balletbo@collabora.com>
288 288 Enric Balletbo i Serra <eballetbo@kernel.org> <eballetbo@iseebcn.com>
289 + Eric Dumazet <edumazet@kernel.org> <edumazet@google.com>
290 + Eric Dumazet <edumazet@kernel.org> <eric.dumazet@gmail.com>
289 291 Erik Kaneda <erik.kaneda@intel.com> <erik.schmauss@intel.com>
290 292 Ethan Carter Edwards <ethan@ethancedwards.com> Ethan Edwards <ethancarteredwards@gmail.com>
291 293 Eugen Hristev <ehristev@kernel.org> <eugen.hristev@microchip.com>
@@ -484,7 +486,6 @@ Juha Yrjola <juha.yrjola@nokia.com>
484 486 Juha Yrjola <juha.yrjola@solidboot.com>
485 487 Julien Thierry <julien.thierry.kdev@gmail.com> <julien.thierry@arm.com>
486 488 Justin Iurman <justin.iurman@gmail.com> <justin.iurman@uliege.be>
487 - Imre Kaloz <kaloz@kernel.org> <kaloz@openwrt.org>
488 489 Ira Weiny <iweiny@kernel.org> <ira.weiny@intel.com>
489 490 Iskren Chernev <me@iskren.info> <iskren.chernev@gmail.com>
490 491 Kalle Valo <kvalo@kernel.org> <kvalo@codeaurora.org>
modified Documentation/arch/arm64/silicon-errata.rst
@@ -174,6 +174,8 @@ stable kernels.
174 174 +----------------+-----------------+-----------------+-----------------------------+
175 175 | ARM | Cortex-A725 | #3456106 | ARM64_ERRATUM_3194386 |
176 176 +----------------+-----------------+-----------------+-----------------------------+
177 + | ARM | Cortex-A725 | #3821522 | ARM64_ERRATUM_3821522 |
178 + +----------------+-----------------+-----------------+-----------------------------+
177 179 | ARM | Cortex-X1 | #1502854 | N/A |
178 180 +----------------+-----------------+-----------------+-----------------------------+
179 181 | ARM | Cortex-X1 | #3324344 | ARM64_ERRATUM_3194386 |
modified Documentation/devicetree/bindings/iio/adc/rockchip-saradc.yaml
@@ -12,19 +12,19 @@ maintainers:
12 12 properties:
13 13 compatible:
14 14 oneOf:
15 - - const: rockchip,saradc
16 - - const: rockchip,rk3066-tsadc
17 - - const: rockchip,rk3399-saradc
18 - - const: rockchip,rk3528-saradc
15 + - enum:
16 + - rockchip,saradc
17 + - rockchip,rk3066-tsadc
18 + - rockchip,rk3399-saradc
19 + - rockchip,rk3528-saradc
20 + - rockchip,rk3562-saradc
21 + - rockchip,rk3588-saradc
22 + - rockchip,rv1106-saradc
19 23 - items:
20 24 - const: rockchip,rk3506-saradc
21 25 - const: rockchip,rk3528-saradc
22 - - const: rockchip,rk3562-saradc
23 - - const: rockchip,rk3588-saradc
24 26 - items:
25 - - enum:
26 - - rockchip,rk3576-saradc
27 - - rockchip,rv1106-saradc
27 + - const: rockchip,rk3576-saradc
28 28 - const: rockchip,rk3588-saradc
29 29 - items:
30 30 - enum:
modified Documentation/filesystems/netfs_library.rst
@@ -451,6 +451,32 @@ one.
451 451 The inode should be marked ``NETFS_ICTX_SINGLE_NO_UPLOAD`` if this API is to be
452 452 used. The writeback function requires the buffer to be of ITER_FOLIOQ type.
453 453
454 + Clearing Stale Post-EOF Pagecache
455 + ---------------------------------
456 +
457 + When a file is extended, data left in the pagecache past the old EOF by a write
458 + through an mmap must not be exposed as file content. Netfslib clears this on
459 + its own write paths, and exports a helper so a filesystem can do the same from
460 + a resize path (truncate, setattr, fallocate and the like) that holds the
461 + inode's ``i_rwsem`` exclusively across the whole resize::
462 +
463 + void netfs_clear_stale_post_isize(struct inode *inode, uoff_t from,
464 + uoff_t to);
465 +
466 + This zeroes any such data within the ``[from, to)`` hole to be made, where
467 + @from is the old EOF and @to is the new one, and the caller must have already
468 + updated ``i_size`` to @to before calling it. Only the folio straddling @from
469 + can hold data written past the EOF through an mmap, as pages wholly beyond the
470 + EOF can't be faulted in, so the zeroing is limited to that folio. The folio is
471 + zeroed rather than dropped so that a concurrent extending write can't lose
472 + data.
473 +
474 + This overlaps with ``pagecache_isize_extended()`` but can't reuse it: that
475 + helper is keyed on a sub-page block size and is a no-op when the block size is
476 + ``>= PAGE_SIZE`` (as on network filesystems), and it doesn't wait for
477 + writeback. As both address the same problem, a change to one should probably
478 + be reflected in the other to keep them in sync.
479 +
454 480 High-Level VM API
455 481 ==================
456 482
modified MAINTAINERS
@@ -3012,7 +3012,7 @@ F: arch/arm/boot/dts/ti/omap/omap3-igep*
3012 3012
3013 3013 ARM/INTEL IXP4XX ARM ARCHITECTURE
3014 3014 M: Linus Walleij <linusw@kernel.org>
3015 - M: Imre Kaloz <kaloz@kernel.org>
3015 + M: Imre Kaloz <kaloz@openwrt.org>
3016 3016 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
3017 3017 S: Maintained
3018 3018 F: Documentation/devicetree/bindings/arm/intel-ixp4xx.yaml
@@ -5143,6 +5143,7 @@ L: netdev@vger.kernel.org
5143 5143 L: openwrt-devel@lists.openwrt.org (subscribers-only)
5144 5144 S: Supported
5145 5145 F: Documentation/devicetree/bindings/net/dsa/brcm,b53.yaml
5146 + F: Documentation/networking/dsa/b53.rst
5146 5147 F: drivers/net/dsa/b53/*
5147 5148 F: drivers/net/dsa/bcm_sf2*
5148 5149 F: include/linux/dsa/brcm.h
@@ -17209,31 +17210,6 @@ F: include/trace/events/ksm.h
17209 17210 F: mm/ksm.c
17210 17211 F: mm/mm_slot.h
17211 17212
17212 - MEMORY MANAGEMENT - MEMORY POLICY AND MIGRATION
17213 - M: Andrew Morton <akpm@linux-foundation.org>
17214 - M: David Hildenbrand <david@kernel.org>
17215 - R: Zi Yan <ziy@nvidia.com>
17216 - R: Matthew Brost <matthew.brost@intel.com>
17217 - R: Joshua Hahn <joshua.hahnjy@gmail.com>
17218 - R: Rakie Kim <rakie.kim@sk.com>
17219 - R: Byungchul Park <byungchul@sk.com>
17220 - R: Gregory Price <gourry@gourry.net>
17221 - R: Ying Huang <ying.huang@linux.alibaba.com>
17222 - R: Alistair Popple <apopple@nvidia.com>
17223 - L: linux-mm@kvack.org
17224 - S: Maintained
17225 - W: http://www.linux-mm.org
17226 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
17227 - F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy
17228 - F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy-weighted-interleave
17229 - F: include/linux/mempolicy.h
17230 - F: include/uapi/linux/mempolicy.h
17231 - F: include/linux/migrate.h
17232 - F: include/linux/migrate_mode.h
17233 - F: mm/mempolicy.c
17234 - F: mm/migrate.c
17235 - F: mm/migrate_device.c
17236 -
17237 17213 MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)
17238 17214 M: Andrew Morton <akpm@linux-foundation.org>
17239 17215 R: Kairui Song <kasong@tencent.com>
@@ -17256,6 +17232,25 @@ F: include/linux/mmzone.h
17256 17232 F: mm/vmscan.c
17257 17233 F: mm/workingset.c
17258 17234
17235 + MEMORY MANAGEMENT - MIGRATION
17236 + M: Andrew Morton <akpm@linux-foundation.org>
17237 + M: David Hildenbrand <david@kernel.org>
17238 + R: Zi Yan <ziy@nvidia.com>
17239 + R: Matthew Brost <matthew.brost@intel.com>
17240 + R: Joshua Hahn <joshua.hahnjy@gmail.com>
17241 + R: Byungchul Park <byungchul@sk.com>
17242 + R: Gregory Price <gourry@gourry.net>
17243 + R: Ying Huang <ying.huang@linux.alibaba.com>
17244 + R: Alistair Popple <apopple@nvidia.com>
17245 + L: linux-mm@kvack.org
17246 + S: Maintained
17247 + W: http://www.linux-mm.org
17248 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
17249 + F: include/linux/migrate.h
17250 + F: include/linux/migrate_mode.h
17251 + F: mm/migrate.c
17252 + F: mm/migrate_device.c
17253 +
17259 17254 MEMORY MANAGEMENT - MISC
17260 17255 M: Andrew Morton <akpm@linux-foundation.org>
17261 17256 M: David Hildenbrand <david@kernel.org>
@@ -17271,7 +17266,6 @@ W: http://www.linux-mm.org
17271 17266 T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
17272 17267 F: Documentation/ABI/testing/sysfs-kernel-mm
17273 17268 F: Documentation/ABI/testing/sysfs-kernel-mm-cma
17274 - F: Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
17275 17269 F: Documentation/ABI/testing/sysfs-kernel-mm-numa
17276 17270 F: Documentation/admin-guide/mm/
17277 17271 F: Documentation/mm/
@@ -17279,7 +17273,6 @@ F: drivers/char/mem.c
17279 17273 F: include/linux/cma.h
17280 17274 F: include/linux/dmapool.h
17281 17275 F: include/linux/ioremap.h
17282 - F: include/linux/memory-tiers.h
17283 17276 F: include/linux/page_idle.h
17284 17277 F: mm/backing-dev.c
17285 17278 F: mm/cma.c
@@ -17291,7 +17284,6 @@ F: mm/early_ioremap.c
17291 17284 F: mm/fadvise.c
17292 17285 F: mm/ioremap.c
17293 17286 F: mm/mapping_dirty_helpers.c
17294 - F: mm/memory-tiers.c
17295 17287 F: mm/page_idle.c
17296 17288 F: mm/pgalloc-track.h
17297 17289 F: mm/process_vm_access.c
@@ -17308,6 +17300,27 @@ F: mm/numa.c
17308 17300 F: mm/numa_emulation.c
17309 17301 F: mm/numa_memblks.c
17310 17302
17303 + MEMORY MANAGEMENT - NUMA PLACEMENT
17304 + M: Andrew Morton <akpm@linux-foundation.org>
17305 + M: David Hildenbrand <david@kernel.org>
17306 + M: Gregory Price <gourry@gourry.net>
17307 + R: Zi Yan <ziy@nvidia.com>
17308 + R: Joshua Hahn <joshua.hahnjy@gmail.com>
17309 + R: Rakie Kim <rakie.kim@sk.com>
17310 + R: Ying Huang <ying.huang@linux.alibaba.com>
17311 + L: linux-mm@kvack.org
17312 + S: Maintained
17313 + W: http://www.linux-mm.org
17314 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
17315 + F: Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
17316 + F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy
17317 + F: Documentation/ABI/testing/sysfs-kernel-mm-mempolicy-weighted-interleave
17318 + F: include/linux/memory-tiers.h
17319 + F: include/linux/mempolicy.h
17320 + F: include/uapi/linux/mempolicy.h
17321 + F: mm/memory-tiers.c
17322 + F: mm/mempolicy.c
17323 +
17311 17324 MEMORY MANAGEMENT - OOM KILLER
17312 17325 M: Michal Hocko <mhocko@suse.com>
17313 17326 R: David Rientjes <rientjes@google.com>
@@ -18885,7 +18898,7 @@ F: net/core/drop_monitor.c
18885 18898 NETWORKING DRIVERS
18886 18899 M: Andrew Lunn <andrew+netdev@lunn.ch>
18887 18900 M: "David S. Miller" <davem@davemloft.net>
18888 - M: Eric Dumazet <edumazet@google.com>
18901 + M: Eric Dumazet <edumazet@kernel.org>
18889 18902 M: Jakub Kicinski <kuba@kernel.org>
18890 18903 M: Paolo Abeni <pabeni@redhat.com>
18891 18904 L: netdev@vger.kernel.org
@@ -19002,7 +19015,7 @@ K: struct\s+phy_port|phy_port_
19002 19015
19003 19016 NETWORKING [GENERAL]
19004 19017 M: "David S. Miller" <davem@davemloft.net>
19005 - M: Eric Dumazet <edumazet@google.com>
19018 + M: Eric Dumazet <edumazet@kernel.org>
19006 19019 M: Jakub Kicinski <kuba@kernel.org>
19007 19020 M: Paolo Abeni <pabeni@redhat.com>
19008 19021 R: Simon Horman <horms@kernel.org>
@@ -19228,7 +19241,7 @@ F: net/ipv6/seg6*
19228 19241 F: tools/testing/selftests/net/srv6*
19229 19242
19230 19243 NETWORKING [TCP]
19231 - M: Eric Dumazet <edumazet@google.com>
19244 + M: Eric Dumazet <edumazet@kernel.org>
19232 19245 M: Neal Cardwell <ncardwell@google.com>
19233 19246 R: Kuniyuki Iwashima <kuniyu@google.com>
19234 19247 L: netdev@vger.kernel.org
@@ -19261,7 +19274,7 @@ F: net/tls/
19261 19274 F: tools/testing/selftests/net/tls.c
19262 19275
19263 19276 NETWORKING [SOCKETS]
19264 - M: Eric Dumazet <edumazet@google.com>
19277 + M: Eric Dumazet <edumazet@kernel.org>
19265 19278 M: Kuniyuki Iwashima <kuniyu@google.com>
19266 19279 M: Paolo Abeni <pabeni@redhat.com>
19267 19280 M: Willem de Bruijn <willemb@google.com>
@@ -20557,6 +20570,7 @@ ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
20557 20570 M: Mark Fasheh <mark@fasheh.com>
20558 20571 M: Joel Becker <jlbec@evilplan.org>
20559 20572 M: Joseph Qi <joseph.qi@linux.alibaba.com>
20573 + R: Heming Zhao <heming.zhao@suse.com>
20560 20574 L: ocfs2-devel@lists.linux.dev
20561 20575 S: Supported
20562 20576 W: http://ocfs2.wiki.kernel.org
@@ -24475,6 +24489,11 @@ R: Marc Murphy <marc.murphy@sancloud.com>
24475 24489 S: Supported
24476 24490 F: arch/arm/boot/dts/ti/omap/am335x-sancloud*
24477 24491
24492 + SB1250-DUART BROADCOM SOC SERIAL DRIVER
24493 + M: "Maciej W. Rozycki" <macro@orcam.me.uk>
24494 + S: Maintained
24495 + F: drivers/tty/serial/sb1250-duart.c
24496 +
24478 24497 SBOM
24479 24498 M: Luis Augenstein <luis.augenstein@tngtech.com>
24480 24499 M: Maximilian Huber <maximilian.huber@tngtech.com>
@@ -25185,7 +25204,7 @@ R: David Rientjes <rientjes@google.com>
25185 25204 R: Roman Gushchin <roman.gushchin@linux.dev>
25186 25205 L: linux-mm@kvack.org
25187 25206 S: Maintained
25188 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git
25207 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mm/slab.git
25189 25208 F: Documentation/admin-guide/mm/slab.rst
25190 25209 F: Documentation/mm/slab.rst
25191 25210 F: include/linux/mempool.h
modified Makefile
@@ -2,7 +2,7 @@
2 2 VERSION = 7
3 3 PATCHLEVEL = 3
4 4 SUBLEVEL = 0
5 - EXTRAVERSION = -rc5
5 + EXTRAVERSION = -rc6
6 6 NAME = Baby Opossum Posse
7 7
8 8 # *DOCUMENTATION*
modified arch/arc/Kconfig
@@ -331,13 +331,9 @@ config ARC_FPU_SAVE_RESTORE
331 331 for floating point exceptions and rounding modes. These are
332 332 preserved across task context switch when enabled.
333 333
334 - config ARC_CANT_LLSC
335 - def_bool n
336 -
337 334 config ARC_HAS_LLSC
338 335 bool "Insn: LLOCK/SCOND (efficient atomic ops)"
339 336 default y
340 - depends on !ARC_CANT_LLSC
341 337
342 338 if ISA_ARCV2
343 339
modified arch/arc/include/asm/atomic64-arcv2.h
@@ -156,6 +156,12 @@ static inline u64 __arch_cmpxchg64_relaxed(volatile void *ptr, u64 old, u64 new)
156 156 }
157 157 #define arch_cmpxchg64_relaxed __arch_cmpxchg64_relaxed
158 158
159 + static inline s64 arch_atomic64_cmpxchg_relaxed(atomic64_t *v, s64 old, s64 new)
160 + {
161 + return arch_cmpxchg64_relaxed(&v->counter, old, new);
162 + }
163 + #define arch_atomic64_cmpxchg_relaxed arch_atomic64_cmpxchg_relaxed
164 +
159 165 static inline s64 arch_atomic64_xchg(atomic64_t *ptr, s64 new)
160 166 {
161 167 s64 prev;
modified arch/arc/include/asm/cmpxchg.h
@@ -46,7 +46,7 @@
46 46 __typeof__(*(ptr)) _n_ = (new); \
47 47 __typeof__(*(ptr)) _prev_; \
48 48 \
49 - switch(sizeof((_p_))) { \
49 + switch (sizeof(*(_p_))) { \
50 50 case 1: \
51 51 _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *__force)_p_, (uintptr_t)_o_, (uintptr_t)_n_); \
52 52 break; \
@@ -102,7 +102,7 @@
102 102 __typeof__(ptr) _p_ = (ptr); \
103 103 __typeof__(*(ptr)) _val_ = (val); \
104 104 \
105 - switch(sizeof(*(_p_))) { \
105 + switch (sizeof(*(_p_))) { \
106 106 case 4: \
107 107 _val_ = __arch_xchg(_p_, _val_); \
108 108 break; \
modified arch/arc/kernel/setup.c
@@ -593,6 +593,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
593 593 cpu_id);
594 594 } else {
595 595 freq = clk_get_rate(cpu_clk);
596 + clk_put(cpu_clk);
596 597 }
597 598 if (freq)
598 599 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
modified arch/arc/kernel/smp.c
@@ -12,7 +12,6 @@
12 12 #include <linux/spinlock.h>
13 13 #include <linux/sched/mm.h>
14 14 #include <linux/interrupt.h>
15 - #include <linux/profile.h>
16 15 #include <linux/mm.h>
17 16 #include <linux/cpu.h>
18 17 #include <linux/irq.h>
modified arch/arm/boot/dts/ti/omap/dra7xx-clocks.dtsi
@@ -1376,8 +1376,8 @@
1376 1376 clocks = <&apll_pcie_ck>;
1377 1377 #clock-cells = <0>;
1378 1378 reg = <0x021c>;
1379 - ti,dividers = <2>, <1>;
1380 1379 ti,bit-shift = <8>;
1380 + ti,max-div = <2>;
1381 1381 };
1382 1382
1383 1383 apll_pcie_clkvcoldo: clock-apll-pcie-clkvcoldo {
modified arch/arm64/Kconfig
@@ -1040,9 +1040,17 @@ config ARM64_ERRATUM_1902691
1040 1040
1041 1041 If unsure, say Y.
1042 1042
1043 + config ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
1044 + bool
1045 + # Targeting errata affecting AMEVCNTR01, the AMU constant counter.
1046 + # On affected CPUs the counter may not increment at the expected rate,
1047 + # making it unreliable. As a result, AMU users should treat it as
1048 + # unavailable rather than relying on misleading counter values.
1049 +
1043 1050 config ARM64_ERRATUM_2457168
1044 1051 bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly"
1045 1052 depends on ARM64_AMU_EXTN
1053 + select ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
1046 1054 default y
1047 1055 help
1048 1056 This option adds the workaround for ARM Cortex-A510 erratum 2457168.
@@ -1073,6 +1081,28 @@ config ARM64_ERRATUM_2645198
1073 1081
1074 1082 If unsure, say Y.
1075 1083
1084 + config ARM64_ERRATUM_3821522
1085 + bool "Cortex-A725: 3821522: workaround for possible CNT_CYCLES increment error due to WFE/WFI"
1086 + depends on ARM64_AMU_EXTN
1087 + select ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
1088 + default y
1089 + help
1090 + This option adds the workaround for ARM Cortex-A725 erratum 3821522.
1091 +
1092 + On affected A725 cores, the CNT_CYCLES event may incur a significant
1093 + increment error when entering and subsequently exiting WFx.
1094 + As a result, the CNT_CYCLES may diverge from the system counter
1095 + frequency at which it is expected to increment.
1096 + This renders the AMU counter AMEVCNTR01, that implements CNT_CYCLES,
1097 + being unreliable and unsuitable for use.
1098 +
1099 + Since there is no hardware workaround, reads of the affected CNT_CYCLES
1100 + counter return 0 in the relevant paths. This causes users of the counter
1101 + to treat it as unavailable and is functionally equivalent to firmware
1102 + disabling the affected counter.
1103 +
1104 + If unsure, say Y.
1105 +
1076 1106 config ARM64_WORKAROUND_SPECULATIVE_UNPRIV_LOAD
1077 1107 bool
1078 1108
modified arch/arm64/boot/dts/freescale/fsl-lx216x.dtsi
@@ -1602,7 +1602,7 @@
1602 1602 };
1603 1603
1604 1604 dspi2_miso_mosi_pins: iic5-spi3-pins {
1605 - pinctrl-single,bits = <0x0 (0x3 << 9) (0x7 << 9)>;
1605 + pinctrl-single,bits = <0x3 (0x2 << 9) (0x7 << 9)>;
1606 1606 };
1607 1607
1608 1608 i2c5_pins: iic6-i2c-pins {
@@ -1622,7 +1622,7 @@
1622 1622 };
1623 1623
1624 1624 gpio1_31_28_pins: xspi1-data74-gpio-pins {
1625 - pinctrl-single,bits = <0x0 (0x1 << 15) (0x7 << 15)>;
1625 + pinctrl-single,bits = <0x0 0x1 (0x7 << 15)>;
1626 1626 };
1627 1627
1628 1628 fspi_data30_pins: xspi1-data30-pins {
@@ -1630,7 +1630,7 @@
1630 1630 };
1631 1631
1632 1632 gpio1_27_24_pins: xspi1-data30-gpio-pins {
1633 - pinctrl-single,bits = <0x0 (0x1 << 18) (0x7 << 18)>;
1633 + pinctrl-single,bits = <0x0 0x1 (0x7 << 18)>;
1634 1634 };
1635 1635
1636 1636 fspi_dqs_sck_cs10_pins: xspi1-base-pins {
@@ -1638,7 +1638,7 @@
1638 1638 };
1639 1639
1640 1640 gpio1_23_20_pins: xspi1-base-gpio-pins {
1641 - pinctrl-single,bits = <0x0 (0x1 << 21) (0x7 << 21)>;
1641 + pinctrl-single,bits = <0x0 0x1 (0x7 << 21)>;
1642 1642 };
1643 1643
1644 1644 esdhc0_cmd_data30_clk_vsel_pins: sdhc1-base-sdhc-vsel-pins {
@@ -1687,19 +1687,12 @@
1687 1687 };
1688 1688
1689 1689 /* RCWSR14 */
1690 - /*
1691 - * IIC1_PMUX is a single bit at RCWSR14[10], but bit-per-mux
1692 - * uses the mask for the field to clear before applying the
1693 - * value.
1694 - * So bits 11 and 12, which are reserved, are written as 0
1695 - * on every mux switch, it is harmless.
1696 - */
1697 1690 i2c0_pins: iic1-i2c-pins {
1698 - pinctrl-single,bits = <0x8 0x0 (0x7 << 10)>;
1691 + pinctrl-single,bits = <0x8 0x0 (0x1 << 10)>;
1699 1692 };
1700 1693
1701 1694 gpio0_3_2_pins: iic1-gpio-pins {
1702 - pinctrl-single,bits = <0x8 (0x1 << 10) (0x7 << 10)>;
1695 + pinctrl-single,bits = <0x8 (0x1 << 10) (0x1 << 10)>;
1703 1696 };
1704 1697 };
1705 1698
modified arch/arm64/boot/dts/freescale/imx8mp-var-dart-sonata.dts
@@ -511,7 +511,6 @@
511 511 pinctrl-2 = <&pinctrl_usdhc2_200mhz>, <&pinctrl_usdhc2_gpio>;
512 512 cd-gpios = <&gpio2 12 GPIO_ACTIVE_LOW>;
513 513 vmmc-supply = <&reg_usdhc2_vmmc>;
514 - vqmmc-supply = <&ldo5>;
515 514 bus-width = <4>;
516 515 status = "okay";
517 516 };
modified arch/arm64/boot/dts/qcom/x1-microsoft-denali.dtsi
@@ -863,11 +863,11 @@
863 863 };
864 864
865 865 &lpass_vamacro {
866 - pinctrl-0 = <&dmic01_default>;
866 + pinctrl-0 = <&dmic01_default>, <&dmic23_default>;
867 867 pinctrl-names = "default";
868 868
869 869 vdd-micb-supply = <&vreg_l1b_1p8>;
870 - qcom,dmic-sample-rate = <2400000>;
870 + qcom,dmic-sample-rate = <4800000>;
871 871 };
872 872
873 873 &mdss {
modified arch/arm64/kernel/cpu_errata.c
@@ -384,6 +384,20 @@ static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = {
384 384 };
385 385 #endif
386 386
387 + #ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
388 + static const struct midr_range workaround_amu_constcnt_list[] = {
389 + #ifdef CONFIG_ARM64_ERRATUM_2457168
390 + /* Cortex-A510 r0p0-r1p1 */
391 + MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1),
392 + #endif
393 + #ifdef CONFIG_ARM64_ERRATUM_3821522
394 + /* Cortex-A725 r0p0 - r0p2 */
395 + MIDR_RANGE(MIDR_CORTEX_A725, 0, 0, 0, 2),
396 + #endif
397 + {}
398 + };
399 + #endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT */
400 +
387 401 #ifdef CONFIG_CAVIUM_ERRATUM_23154
388 402 static const struct midr_range cavium_erratum_23154_cpus[] = {
389 403 MIDR_ALL_VERSIONS(MIDR_THUNDERX),
@@ -919,14 +933,12 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
919 933 ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A510, 0, 0, 2)
920 934 },
921 935 #endif
922 - #ifdef CONFIG_ARM64_ERRATUM_2457168
936 + #ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
923 937 {
924 - .desc = "ARM erratum 2457168",
925 - .capability = ARM64_WORKAROUND_2457168,
938 + .desc = "Broken AMU AMEVCNTR01 (const counter)",
939 + .capability = ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT,
926 940 .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
927 -
928 - /* Cortex-A510 r0p0-r1p1 */
929 - CAP_MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1)
941 + CAP_MIDR_RANGE_LIST(workaround_amu_constcnt_list)
930 942 },
931 943 #endif
932 944 #ifdef CONFIG_ARM64_ERRATUM_2038923
modified arch/arm64/kernel/cpufeature.c
@@ -2089,7 +2089,7 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap)
2089 2089 cpumask_set_cpu(smp_processor_id(), &amu_cpus);
2090 2090
2091 2091 /* 0 reference values signal broken/disabled counters */
2092 - if (!this_cpu_has_cap(ARM64_WORKAROUND_2457168))
2092 + if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT))
2093 2093 update_freq_counters_refs();
2094 2094 }
2095 2095 }
modified arch/arm64/kernel/signal.c
@@ -433,6 +433,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
433 433 unsigned int vl, vq;
434 434 struct user_fpsimd_state fpsimd;
435 435 u16 user_vl, flags;
436 + bool fpsimd_only;
436 437 bool sm;
437 438
438 439 if (user->sve_size < sizeof(*user->sve))
@@ -443,19 +444,33 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
443 444 if (err)
444 445 return err;
445 446
447 + fpsimd_only = (user->sve_size == sizeof(*user->sve));
446 448 sm = flags & SVE_SIG_FLAG_SM;
449 +
447 450 if (sm) {
448 451 if (!system_supports_sme())
449 452 return -EINVAL;
450 453
454 + /*
455 + * Streaming SVE state is always preserved with an SVE payload.
456 + * Only accept streaming state which has an SVE payload.
457 + */
458 + if (fpsimd_only)
459 + return -EINVAL;
460 +
451 461 vl = task_get_sme_vl(current);
452 462 } else {
453 463 /*
454 - * A SME only system use SVE for streaming mode so can
455 - * have a SVE formatted context with a zero VL and no
456 - * payload data.
464 + * Non-streaming SVE state may be preserved without an SVE
465 + * payload, in which case all state is saved in the FPSIMD
466 + * context.
467 + *
468 + * On SME-only systems, non-streaming (FPSIMD-only) state is
469 + * always preserved without an SVE payload, and with VL==0. On
470 + * such systems, only accept non-streaming state without an SVE
471 + * payload.
457 472 */
458 - if (!system_supports_sve() && !system_supports_sme())
473 + if (!system_supports_sve() && !fpsimd_only)
459 474 return -EINVAL;
460 475
461 476 vl = task_get_sve_vl(current);
@@ -464,16 +479,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
464 479 if (user_vl != vl)
465 480 return -EINVAL;
466 481
467 - /*
468 - * Non-streaming SVE state may be preserved without an SVE payload, in
469 - * which case the SVE context only has a header with VL==0, and all
470 - * state can be restored from the FPSIMD context.
471 - *
472 - * Streaming SVE state is always preserved with an SVE payload. For
473 - * consistency and robustness, reject restoring streaming SVE state
474 - * without an SVE payload.
475 - */
476 - if (!sm && user->sve_size == sizeof(*user->sve))
482 + if (fpsimd_only)
477 483 return restore_fpsimd_context(user);
478 484
479 485 vq = sve_vq_from_vl(vl);
modified arch/arm64/kernel/topology.c
@@ -186,7 +186,6 @@ int arch_freq_get_on_cpu(int cpu)
186 186 struct amu_cntr_sample *amu_sample;
187 187 unsigned int start_cpu = cpu;
188 188 unsigned long last_update;
189 - unsigned int freq = 0;
190 189 u64 scale;
191 190
192 191 if (!amu_fie_cpu_supported(cpu) || !arch_scale_freq_ref(cpu))
@@ -245,9 +244,8 @@ int arch_freq_get_on_cpu(int cpu)
245 244 * (see amu_scale_freq_tick for details)
246 245 */
247 246 scale = arch_scale_freq_capacity(cpu);
248 - freq = scale * arch_scale_freq_ref(cpu);
249 - freq >>= SCHED_CAPACITY_SHIFT;
250 - return freq;
247 +
248 + return (scale * arch_scale_freq_ref(cpu)) >> SCHED_CAPACITY_SHIFT;
251 249 }
252 250
253 251 static void amu_fie_setup(const struct cpumask *cpus)
@@ -397,12 +395,13 @@ static void cpu_read_corecnt(void *val)
397 395 static void cpu_read_constcnt(void *val)
398 396 {
399 397 /*
400 - * Return 0 if the current CPU is affected by erratum 2457168. A value
401 - * of 0 is also returned if the current CPU does not support AMUs or if
402 - * the counter is disabled. A return value of 0 at counter read is
403 - * properly handled as an error case by the users of the counter.
398 + * Return 0 if the current CPU is affected by a HW erratum.
399 + * A value of 0 is also returned if the current CPU does not
400 + * support AMUs or if the counter is disabled. A return
401 + * value of 0 at counter read is properly handled as an error
402 + * case by the users of the counter.
404 403 */
405 - *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_2457168) ?
404 + *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT) ?
406 405 0UL : read_constcnt();
407 406 }
408 407
@@ -463,8 +462,9 @@ static void amu_read_core_const_ctrs(void *val)
463 462
464 463 /*
465 464 * cpu_read_constcnt() incurs slight latency due to the
466 - * ARM64_WORKAROUND_2457168 check. Read it first to minimize
467 - * the sampling skew between the const and core counters.
465 + * ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT check.
466 + * Read it first to minimize the sampling skew between the const
467 + * and core counters.
468 468 */
469 469 cpu_read_constcnt(&ctrs->constcnt);
470 470 cpu_read_corecnt(&ctrs->corecnt);
modified arch/arm64/kernel/vdso/Makefile
@@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \
41 41 $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \
42 42 -Wmissing-prototypes -Wmissing-declarations
43 43
44 - CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
44 + CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables $(CONFIG_CC_OPT_INLINE_MEMSET)
45 45
46 46 CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO)
47 47 CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO)
modified arch/arm64/kvm/emulate-nested.c
@@ -2386,9 +2386,6 @@ int __init populate_nv_trap_config(void)
2386 2386 print_nv_trap_error(fgt, "FGT bit is reserved", ret);
2387 2387 }
2388 2388
2389 - if (!cpus_have_final_cap(ARM64_HAS_FGT))
2390 - continue;
2391 -
2392 2389 prev = xa_store(&sr_forward_xa, enc,
2393 2390 xa_mk_value(tc.val), GFP_KERNEL);
2394 2391
modified arch/arm64/kvm/hyp/include/nvhe/pkvm.h
@@ -12,6 +12,15 @@
12 12 #include <nvhe/gfp.h>
13 13 #include <nvhe/spinlock.h>
14 14
15 + /*
16 + * HCR_EL2 bits EL2 takes from the host on each entry, per VM type. The rest
17 + * are EL2's own and nothing the host sets there reaches the guest.
18 + */
19 + #define PKVM_HCR_EL2_HOST_PVM (HCR_EL2_TWI | HCR_EL2_TWE | HCR_EL2_VSE)
20 + #define PKVM_HCR_EL2_HOST_NPVM (PKVM_HCR_EL2_HOST_PVM | HCR_EL2_VI | HCR_EL2_VF | \
21 + HCR_EL2_TVM | HCR_EL2_TID2 | HCR_EL2_TID4 | \
22 + HCR_EL2_TID5 | HCR_EL2_TTLBOS)
23 +
15 24 /*
16 25 * Holds the relevant data for maintaining the vcpu state completely at hyp.
17 26 */
modified arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -216,6 +216,7 @@ static void sync_debug_state(struct pkvm_hyp_vcpu *hyp_vcpu)
216 216 static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
217 217 {
218 218 struct kvm_vcpu *host_vcpu = hyp_vcpu->host_vcpu;
219 + u64 host_hcr_mask = PKVM_HCR_EL2_HOST_PVM;
219 220
220 221 fpsimd_sve_flush();
221 222 flush_debug_state(hyp_vcpu);
@@ -228,6 +229,7 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
228 229 if (!pkvm_hyp_vcpu_is_protected(hyp_vcpu)) {
229 230 if (vcpu_get_flag(host_vcpu, PKVM_HOST_STATE_DIRTY))
230 231 flush_hyp_vcpu_state(hyp_vcpu);
232 + host_hcr_mask = PKVM_HCR_EL2_HOST_NPVM;
231 233 } else {
232 234 hyp_vcpu->vcpu.arch.ctxt = host_vcpu->arch.ctxt;
233 235 }
@@ -241,9 +243,8 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
241 243 * trap-control bit, so it must flow to the hyp vCPU alongside TWI/TWE
242 244 * for the vSError to be delivered. sync_hyp_vcpu() reflects it back.
243 245 */
244 - hyp_vcpu->vcpu.arch.hcr_el2 &= ~(HCR_TWI | HCR_TWE | HCR_VSE);
245 - hyp_vcpu->vcpu.arch.hcr_el2 |= READ_ONCE(host_vcpu->arch.hcr_el2) &
246 - (HCR_TWI | HCR_TWE | HCR_VSE);
246 + hyp_vcpu->vcpu.arch.hcr_el2 &= ~host_hcr_mask;
247 + hyp_vcpu->vcpu.arch.hcr_el2 |= READ_ONCE(host_vcpu->arch.hcr_el2) & host_hcr_mask;
247 248
248 249 hyp_vcpu->vcpu.arch.iflags = host_vcpu->arch.iflags;
249 250
modified arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -30,6 +30,7 @@ unsigned int kvm_host_sve_max_vl;
30 30 */
31 31 static DEFINE_PER_CPU(struct pkvm_hyp_vcpu *, loaded_hyp_vcpu);
32 32
33 + /* The PKVM_HCR_EL2_HOST_{PVM,NPVM} bits of this value come from the host on each entry. */
33 34 static void pkvm_vcpu_reset_hcr(struct kvm_vcpu *vcpu)
34 35 {
35 36 vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
@@ -47,18 +48,17 @@ static void pkvm_vcpu_reset_hcr(struct kvm_vcpu *vcpu)
47 48 if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB))
48 49 vcpu->arch.hcr_el2 |= HCR_FWB;
49 50
50 - if (cpus_have_final_cap(ARM64_HAS_EVT) &&
51 - !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE) &&
52 - kvm_read_vm_id_reg(vcpu->kvm, SYS_CTR_EL0) == read_cpuid(CTR_EL0))
53 - vcpu->arch.hcr_el2 |= HCR_TID4;
54 - else
55 - vcpu->arch.hcr_el2 |= HCR_TID2;
51 + /*
52 + * Without AArch32 EL1, leave RW set and let the entry fail with an
53 + * illegal exception return: the *32_EL2 registers EL2 would otherwise
54 + * switch are UNDEFINED there.
55 + */
56 + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT) &&
57 + cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
58 + vcpu->arch.hcr_el2 &= ~HCR_EL2_RW;
56 59
57 60 if (vcpu_has_ptrauth(vcpu))
58 61 vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK);
59 -
60 - if (kvm_has_mte(vcpu->kvm))
61 - vcpu->arch.hcr_el2 |= HCR_ATA;
62 62 }
63 63
64 64 static void pvm_init_traps_hcr(struct kvm_vcpu *vcpu)
@@ -76,6 +76,13 @@ static void pvm_init_traps_hcr(struct kvm_vcpu *vcpu)
76 76 */
77 77 val |= HCR_TACR | HCR_TIDCP | HCR_TID3 | HCR_TID1;
78 78
79 + if (cpus_have_final_cap(ARM64_HAS_EVT) &&
80 + !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE) &&
81 + kvm_read_vm_id_reg(kvm, SYS_CTR_EL0) == read_cpuid(CTR_EL0))
82 + val |= HCR_EL2_TID4;
83 + else
84 + val |= HCR_EL2_TID2;
85 +
79 86 if (!kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, IMP)) {
80 87 val |= HCR_TERR | HCR_TEA;
81 88 val &= ~(HCR_FIEN);
modified arch/arm64/kvm/mmu.c
@@ -1468,32 +1468,11 @@ transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memslot,
1468 1468 return PAGE_SIZE;
1469 1469 }
1470 1470
1471 - static int get_vma_page_shift(struct vm_area_struct *vma, unsigned long hva)
1471 + static int get_vma_page_shift(struct vm_area_struct *vma)
1472 1472 {
1473 - unsigned long pa;
1474 -
1475 - if (is_vm_hugetlb_page(vma) && !(vma->vm_flags & VM_PFNMAP))
1473 + if (is_vm_hugetlb_page(vma))
1476 1474 return huge_page_shift(hstate_vma(vma));
1477 1475
1478 - if (!(vma->vm_flags & VM_PFNMAP))
1479 - return PAGE_SHIFT;
1480 -
1481 - VM_BUG_ON(is_vm_hugetlb_page(vma));
1482 -
1483 - pa = (vma->vm_pgoff << PAGE_SHIFT) + (hva - vma->vm_start);
1484 -
1485 - #ifndef __PAGETABLE_PMD_FOLDED
1486 - if ((hva & (PUD_SIZE - 1)) == (pa & (PUD_SIZE - 1)) &&
1487 - ALIGN_DOWN(hva, PUD_SIZE) >= vma->vm_start &&
1488 - ALIGN(hva, PUD_SIZE) <= vma->vm_end)
1489 - return PUD_SHIFT;
1490 - #endif
1491 -
1492 - if ((hva & (PMD_SIZE - 1)) == (pa & (PMD_SIZE - 1)) &&
1493 - ALIGN_DOWN(hva, PMD_SIZE) >= vma->vm_start &&
1494 - ALIGN(hva, PMD_SIZE) <= vma->vm_end)
1495 - return PMD_SHIFT;
1496 -
1497 1476 return PAGE_SHIFT;
1498 1477 }
1499 1478
@@ -1794,7 +1773,7 @@ static short kvm_s2_resolve_vma_size(const struct kvm_s2_fault_desc *s2fd,
1794 1773 vma_shift = PAGE_SHIFT;
1795 1774 } else {
1796 1775 s2vi->max_map_size = PUD_SIZE;
1797 - vma_shift = get_vma_page_shift(vma, s2fd->hva);
1776 + vma_shift = get_vma_page_shift(vma);
1798 1777 }
1799 1778
1800 1779 switch (vma_shift) {
@@ -1952,16 +1931,6 @@ static int kvm_s2_fault_pin_pfn(const struct kvm_s2_fault_desc *s2fd,
1952 1931 return -EFAULT;
1953 1932 }
1954 1933 } else {
1955 - /*
1956 - * If the page was identified as device early by looking at
1957 - * the VMA flags, vma_pagesize is already representing the
1958 - * largest quantity we can map. If instead it was mapped
1959 - * via __kvm_faultin_pfn(), vma_pagesize is set to PAGE_SIZE
1960 - * and must not be upgraded.
1961 - *
1962 - * In both cases, we don't let transparent_hugepage_adjust()
1963 - * change things at the last minute.
1964 - */
1965 1934 s2vi->map_non_cacheable = true;
1966 1935 }
1967 1936
@@ -2051,10 +2020,10 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,
2051 2020
2052 2021 /*
2053 2022 * If we are not forced to use page mapping, check if we are
2054 - * backed by a THP and thus use block mapping if possible.
2023 + * backed by a huge stage-1 mapping and thus use block mapping if
2024 + * possible.
2055 2025 */
2056 - if (mapping_size == PAGE_SIZE &&
2057 - !(s2vi->max_map_size == PAGE_SIZE || s2vi->map_non_cacheable)) {
2026 + if (mapping_size == PAGE_SIZE && s2vi->max_map_size != PAGE_SIZE) {
2058 2027 if (perm_fault_granule > PAGE_SIZE) {
2059 2028 mapping_size = perm_fault_granule;
2060 2029 } else {
@@ -2135,10 +2104,6 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd)
2135 2104 return ret;
2136 2105 }
2137 2106
2138 - /*
2139 - * Let's check if we will get back a huge page backed by hugetlbfs, or
2140 - * get block mapping for device MMIO region.
2141 - */
2142 2107 ret = kvm_s2_fault_pin_pfn(s2fd, &s2vi);
2143 2108 if (ret != 1)
2144 2109 return ret;
modified arch/arm64/kvm/vgic/vgic-init.c
@@ -97,6 +97,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
97 97 /*
98 98 * - Acquiring the vCPU mutex for every *online* vCPU to prevent
99 99 * concurrent vCPU ioctls for vCPUs already visible to userspace.
100 + * This also ensures KVM isn't in the middle of creating a vCPU,
101 + * i.e. that there are no vCPUs that have been created but aren't
102 + * yet fully online.
100 103 */
101 104 ret = -EBUSY;
102 105 if (kvm_trylock_all_vcpus(kvm))
@@ -105,18 +108,11 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
105 108 /*
106 109 * - Taking the config_lock which protects VGIC data structures such
107 110 * as the per-vCPU arrays of private IRQs (SGIs, PPIs).
108 - */
109 - mutex_lock(&kvm->arch.config_lock);
110 -
111 - /*
112 - * - Bailing on the entire thing if a vCPU is in the middle of creation,
113 - * dropped the kvm->lock, but hasn't reached kvm_arch_vcpu_create().
114 111 *
115 112 * The whole combination of this guarantees that no vCPU can get into
116 113 * KVM with a VGIC configuration inconsistent with the VM's VGIC.
117 114 */
118 - if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
119 - goto out_unlock;
115 + mutex_lock(&kvm->arch.config_lock);
120 116
121 117 if (irqchip_in_kernel(kvm)) {
122 118 ret = -EEXIST;
modified arch/arm64/kvm/vgic/vgic-its.c
@@ -319,12 +319,16 @@ static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq,
319 319 return ret;
320 320 }
321 321
322 - static int update_affinity(struct vgic_irq *irq, struct kvm_vcpu *vcpu)
322 + static int update_affinity(struct vgic_irq *irq,
323 + struct kvm_vcpu *from_vcpu, struct kvm_vcpu *vcpu)
323 324 {
324 325 struct its_vlpi_map map;
325 326 int ret;
326 327
327 328 guard(raw_spinlock_irqsave)(&irq->irq_lock);
329 + if (from_vcpu && irq->target_vcpu != from_vcpu)
330 + return 0;
331 +
328 332 irq->target_vcpu = vcpu;
329 333
330 334 if (!irq->hw)
@@ -362,7 +366,7 @@ static void update_affinity_ite(struct kvm *kvm, struct its_ite *ite)
362 366 return;
363 367
364 368 vcpu = collection_to_vcpu(kvm, ite->collection);
365 - update_affinity(ite->irq, vcpu);
369 + update_affinity(ite->irq, NULL, vcpu);
366 370 }
367 371
368 372 /*
@@ -856,7 +860,7 @@ static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its,
856 860
857 861 vgic_its_invalidate_cache(its);
858 862
859 - return update_affinity(ite->irq, vcpu);
863 + return update_affinity(ite->irq, NULL, vcpu);
860 864 }
861 865
862 866 static bool __is_visible_gfn_locked(struct vgic_its *its, gpa_t gpa)
@@ -1383,7 +1387,7 @@ static int vgic_its_cmd_handle_movall(struct kvm *kvm, struct vgic_its *its,
1383 1387 if (!irq)
1384 1388 continue;
1385 1389
1386 - update_affinity(irq, vcpu2);
1390 + update_affinity(irq, vcpu1, vcpu2);
1387 1391
1388 1392 vgic_put_irq(kvm, irq);
1389 1393 }
modified arch/arm64/kvm/vgic/vgic-v2.c
@@ -122,6 +122,10 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu)
122 122 for (int lr = 0; lr < vgic_cpu->vgic_v2.used_lrs; lr++)
123 123 vgic_v2_fold_lr(vcpu, cpuif->vgic_lr[lr]);
124 124
125 + cpuif->used_lrs = 0;
126 + if (!irq)
127 + return;
128 +
125 129 /* See the GICv3 equivalent for the EOIcount handling rationale */
126 130 list_for_each_entry_continue(irq, &vgic_cpu->ap_list_head, ap_list) {
127 131 u32 lr;
@@ -144,8 +148,6 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu)
144 148 vgic_v2_fold_lr(vcpu, lr);
145 149 eoicount--;
146 150 }
147 -
148 - cpuif->used_lrs = 0;
149 151 }
150 152
151 153 void vgic_v2_deactivate(struct kvm_vcpu *vcpu, u32 val)
modified arch/arm64/kvm/vgic/vgic-v3.c
@@ -155,6 +155,10 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
155 155 for (int lr = 0; lr < cpuif->used_lrs; lr++)
156 156 vgic_v3_fold_lr(vcpu, cpuif->vgic_lr[lr]);
157 157
158 + cpuif->used_lrs = 0;
159 + if (!irq)
160 + return;
161 +
158 162 /*
159 163 * EOIMode=0: use EOIcount to emulate deactivation. We are
160 164 * guaranteed to deactivate in reverse order of the activation, so
@@ -188,8 +192,6 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)
188 192 vgic_v3_fold_lr(vcpu, lr);
189 193 eoicount--;
190 194 }
191 -
192 - cpuif->used_lrs = 0;
193 195 }
194 196
195 197 void vgic_v3_deactivate(struct kvm_vcpu *vcpu, u64 val)
modified arch/arm64/kvm/vgic/vgic.c
@@ -853,6 +853,17 @@ retry:
853 853 goto retry;
854 854 }
855 855
856 + /*
857 + * Fix the last_lr_irq refcount which was obtained while
858 + * populating the LRs. This can also result in the LPI being
859 + * deleted.
860 + */
861 + irq = *host_data_ptr(last_lr_irq);
862 + if (irq) {
863 + deleted_lpis |= vgic_put_irq_norelease(vcpu->kvm, irq);
864 + *host_data_ptr(last_lr_irq) = NULL;
865 + }
866 +
856 867 raw_spin_unlock(&vgic_cpu->ap_list_lock);
857 868
858 869 if (unlikely(deleted_lpis))
@@ -866,9 +877,6 @@ static void vgic_fold_state(struct kvm_vcpu *vcpu)
866 877 return;
867 878 }
868 879
869 - if (!*host_data_ptr(last_lr_irq))
870 - return;
871 -
872 880 if (kvm_vgic_global_state.type == VGIC_V2)
873 881 vgic_v2_fold_lr_state(vcpu);
874 882 else
@@ -1021,11 +1029,14 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)
1021 1029 scoped_guard(raw_spinlock, &irq->irq_lock) {
1022 1030 if (likely(vgic_target_oracle(irq) == vcpu)) {
1023 1031 vgic_populate_lr(vcpu, irq, count++);
1024 - *host_data_ptr(last_lr_irq) = irq;
1032 + if (count == kvm_vgic_global_state.nr_lr) {
1033 + vgic_get_irq_ref(irq);
1034 + *host_data_ptr(last_lr_irq) = irq;
1035 + }
1025 1036 }
1026 1037 }
1027 1038
1028 - if (count == kvm_vgic_global_state.nr_lr)
1039 + if (*host_data_ptr(last_lr_irq))
1029 1040 break;
1030 1041 }
1031 1042
modified arch/arm64/mm/mmu.c
@@ -2295,7 +2295,7 @@ pte_t modify_prot_start_ptes(struct vm_area_struct *vma, unsigned long addr,
2295 2295 * in cases where cpu is affected with errata #2645198.
2296 2296 */
2297 2297 if (pte_accessible(vma->vm_mm, pte) && pte_user_exec(pte))
2298 - __flush_tlb_range(vma, addr, nr * PAGE_SIZE,
2298 + __flush_tlb_range(vma, addr, addr + nr * PAGE_SIZE,
2299 2299 PAGE_SIZE, 3, TLBF_NOWALKCACHE);
2300 2300 }
2301 2301
modified arch/arm64/net/bpf_jit_comp.c
@@ -2418,10 +2418,11 @@ bool bpf_jit_supports_subprog_tailcalls(void)
2418 2418 return true;
2419 2419 }
2420 2420
2421 - static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *node,
2422 - int bargs_off, int retval_off, int run_ctx_off,
2423 - bool save_ret)
2421 + static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2422 + struct bpf_tramp_node *node, int bargs_off,
2423 + int retval_off, int run_ctx_off, bool save_ret)
2424 2424 {
2425 + void *skip;
2425 2426 __le32 *branch;
2426 2427 u64 enter_prog;
2427 2428 u64 exit_prog;
@@ -2431,6 +2432,10 @@ static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *node,
2431 2432 enter_prog = (u64)bpf_trampoline_enter(p);
2432 2433 exit_prog = (u64)bpf_trampoline_exit(p);
2433 2434
2435 + /* nop, patched to skip this prog when it is detached */
2436 + skip = ctx->ro_image + ctx->idx;
2437 + emit(A64_NOP, ctx);
2438 +
2434 2439 if (node->cookie == 0) {
2435 2440 /* if cookie is zero, one instruction is enough to store it */
2436 2441 emit(A64_STR64I(A64_ZR, A64_SP, run_ctx_off + cookie_off), ctx);
@@ -2483,11 +2488,13 @@ static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *node,
2483 2488 emit(A64_ADD_I(1, A64_R(2), A64_SP, run_ctx_off), ctx);
2484 2489
2485 2490 emit_call(exit_prog, ctx);
2491 +
2492 + bpf_tramp_image_add_skip(im, p, skip, ctx->ro_image + ctx->idx);
2486 2493 }
2487 2494
2488 - static void invoke_bpf_mod_ret(struct jit_ctx *ctx, struct bpf_tramp_nodes *tn,
2489 - int bargs_off, int retval_off, int run_ctx_off,
2490 - __le32 **branches)
2495 + static void invoke_bpf_mod_ret(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2496 + struct bpf_tramp_nodes *tn, int bargs_off,
2497 + int retval_off, int run_ctx_off, __le32 **branches)
2491 2498 {
2492 2499 int i;
2493 2500
@@ -2496,7 +2503,7 @@ static void invoke_bpf_mod_ret(struct jit_ctx *ctx, struct bpf_tramp_nodes *tn,
2496 2503 */
2497 2504 emit(A64_STR64I(A64_ZR, A64_SP, retval_off), ctx);
2498 2505 for (i = 0; i < tn->nr_nodes; i++) {
2499 - invoke_bpf_prog(ctx, tn->nodes[i], bargs_off, retval_off,
2506 + invoke_bpf_prog(ctx, im, tn->nodes[i], bargs_off, retval_off,
2500 2507 run_ctx_off, true);
2501 2508 /* if (*(u64 *)(sp + retval_off) != 0)
2502 2509 * goto do_fexit;
@@ -2882,7 +2889,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2882 2889 store_func_meta(ctx, meta, func_meta_off);
2883 2890 cookie_bargs_off--;
2884 2891 }
2885 - invoke_bpf_prog(ctx, fentry->nodes[i], bargs_off,
2892 + invoke_bpf_prog(ctx, im, fentry->nodes[i], bargs_off,
2886 2893 retval_off, run_ctx_off,
2887 2894 flags & BPF_TRAMP_F_RET_FENTRY_RET);
2888 2895 }
@@ -2893,7 +2900,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2893 2900 if (!branches)
2894 2901 return -ENOMEM;
2895 2902
2896 - invoke_bpf_mod_ret(ctx, fmod_ret, bargs_off, retval_off,
2903 + invoke_bpf_mod_ret(ctx, im, fmod_ret, bargs_off, retval_off,
2897 2904 run_ctx_off, branches);
2898 2905 }
2899 2906
@@ -2906,9 +2913,6 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2906 2913 emit(A64_RET(A64_R(10)), ctx);
2907 2914 /* store return value */
2908 2915 emit(A64_STR64I(A64_R(0), A64_SP, retval_off), ctx);
2909 - /* reserve a nop for bpf_tramp_image_put */
2910 - im->ip_after_call = ctx->ro_image + ctx->idx;
2911 - emit(A64_NOP, ctx);
2912 2916 }
2913 2917
2914 2918 /* update the branches saved in invoke_bpf_mod_ret with cbnz */
@@ -2930,12 +2934,11 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
2930 2934 store_func_meta(ctx, meta, func_meta_off);
2931 2935 cookie_bargs_off--;
2932 2936 }
2933 - invoke_bpf_prog(ctx, fexit->nodes[i], bargs_off, retval_off,
2937 + invoke_bpf_prog(ctx, im, fexit->nodes[i], bargs_off, retval_off,
2934 2938 run_ctx_off, false);
2935 2939 }
2936 2940
2937 2941 if (flags & BPF_TRAMP_F_CALL_ORIG) {
2938 - im->ip_epilogue = ctx->ro_image + ctx->idx;
2939 2942 /* for the first pass, assume the worst case */
2940 2943 if (!ctx->image)
2941 2944 ctx->idx += 4;
@@ -2994,7 +2997,7 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
2994 2997 .image = NULL,
2995 2998 .idx = 0,
2996 2999 };
2997 - struct bpf_tramp_image im;
3000 + struct bpf_tramp_image im = {};
2998 3001 struct arg_aux aaux;
2999 3002 int ret;
3000 3003
@@ -3281,6 +3284,10 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
3281 3284 * longer reachable, since bpf_tramp_image_put() function already
3282 3285 * uses percpu_ref and task-based rcu to do the sync, no need to call
3283 3286 * the sync version here, see bpf_tramp_image_put() for details.
3287 + *
3288 + * 3. when a detached prog is patched out of a trampoline, a CPU that
3289 + * still executes the old nop calls the prog before it went through
3290 + * a quiescent state, and the prog is freed after grace periods.
3284 3291 */
3285 3292 ret = aarch64_insn_patch_text_nosync(ip, new_insn);
3286 3293 out:
modified arch/arm64/tools/cpucaps
@@ -105,7 +105,6 @@ WORKAROUND_1902691
105 105 WORKAROUND_2038923
106 106 WORKAROUND_2064142
107 107 WORKAROUND_2077057
108 - WORKAROUND_2457168
109 108 WORKAROUND_2645198
110 109 WORKAROUND_2658417
111 110 WORKAROUND_4193714
@@ -132,3 +131,4 @@ WORKAROUND_REPEAT_TLBI_SYNC
132 131 WORKAROUND_SPECULATIVE_AT
133 132 WORKAROUND_SPECULATIVE_SSBS
134 133 WORKAROUND_SPECULATIVE_UNPRIV_LOAD
134 + WORKAROUND_BROKEN_AMU_CONSTCNT
modified arch/loongarch/net/bpf_jit.c
@@ -1578,6 +1578,24 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
1578 1578 return ret ? ERR_PTR(-EINVAL) : dst;
1579 1579 }
1580 1580
1581 + int arch_bpf_trampoline_skip(void *nop, void *target)
1582 + {
1583 + u32 old_insn = INSN_NOP;
1584 + u32 new_insn = larch_insn_gen_b((unsigned long)nop, (unsigned long)target);
1585 + int ret;
1586 +
1587 + if (memcmp(nop, &old_insn, LOONGARCH_INSN_SIZE))
1588 + return -EFAULT;
1589 +
1590 + cpus_read_lock();
1591 + mutex_lock(&text_mutex);
1592 + ret = larch_insn_text_copy(nop, &new_insn, LOONGARCH_INSN_SIZE);
1593 + mutex_unlock(&text_mutex);
1594 + cpus_read_unlock();
1595 +
1596 + return ret;
1597 + }
1598 +
1581 1599 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
1582 1600 enum bpf_text_poke_type new_t, void *old_addr,
1583 1601 void *new_addr)
@@ -1696,13 +1714,18 @@ static void restore_stk_args(struct jit_ctx *ctx, int nr_stk_args, int args_off,
1696 1714 }
1697 1715 }
1698 1716
1699 - static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *n,
1700 - int args_off, int retval_off, int run_ctx_off, bool save_ret)
1717 + static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_image *im,
1718 + struct bpf_tramp_node *n, int args_off, int retval_off,
1719 + int run_ctx_off, bool save_ret)
1701 1720 {
1702 1721 int ret;
1703 1722 u32 *branch;
1704 1723 struct bpf_prog *p = n->link->prog;
1705 1724 int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
1725 + void *skip = ctx->ro_image + ctx->idx;
1726 +
1727 + /* nop, patched to a b over this prog when it is detached */
1728 + emit_insn(ctx, nop);
1706 1729
1707 1730 if (n->cookie)
1708 1731 emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1,
@@ -1755,13 +1778,17 @@ static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *n,
1755 1778 /* arg3: &run_ctx */
1756 1779 emit_insn(ctx, addid, LOONGARCH_GPR_A2, LOONGARCH_GPR_FP, -run_ctx_off);
1757 1780 ret = emit_call(ctx, (const u64)bpf_trampoline_exit(p));
1781 + if (ret)
1782 + return ret;
1758 1783
1759 - return ret;
1784 + bpf_tramp_image_add_skip(im, p, skip, ctx->ro_image + ctx->idx);
1785 + return 0;
1760 1786 }
1761 1787
1762 - static int invoke_bpf(struct jit_ctx *ctx, struct bpf_tramp_nodes *tn,
1763 - int args_off, int retval_off, int run_ctx_off,
1764 - int func_meta_off, bool save_ret, u64 func_meta, int cookie_off)
1788 + static int invoke_bpf(struct jit_ctx *ctx, struct bpf_tramp_image *im,
1789 + struct bpf_tramp_nodes *tn, int args_off, int retval_off,
1790 + int run_ctx_off, int func_meta_off, bool save_ret,
1791 + u64 func_meta, int cookie_off)
1765 1792 {
1766 1793 int i, cur_cookie = (cookie_off - args_off) / 8;
1767 1794
@@ -1774,7 +1801,8 @@ static int invoke_bpf(struct jit_ctx *ctx, struct bpf_tramp_nodes *tn,
1774 1801 emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -func_meta_off, meta);
1775 1802 cur_cookie--;
1776 1803 }
1777 - err = invoke_bpf_prog(ctx, tn->nodes[i], args_off, retval_off, run_ctx_off, save_ret);
1804 + err = invoke_bpf_prog(ctx, im, tn->nodes[i], args_off, retval_off,
1805 + run_ctx_off, save_ret);
1778 1806 if (err)
1779 1807 return err;
1780 1808 }
@@ -2017,7 +2045,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
2017 2045 }
2018 2046
2019 2047 if (fentry->nr_nodes) {
2020 - ret = invoke_bpf(ctx, fentry, args_off, retval_off, run_ctx_off, func_meta_off,
2048 + ret = invoke_bpf(ctx, im, fentry, args_off, retval_off, run_ctx_off, func_meta_off,
2021 2049 flags & BPF_TRAMP_F_RET_FENTRY_RET, func_meta, cookie_off);
2022 2050 if (ret)
2023 2051 return ret;
@@ -2029,7 +2057,7 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
2029 2057
2030 2058 emit_insn(ctx, std, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_FP, -retval_off);
2031 2059 for (i = 0; i < fmod_ret->nr_nodes; i++) {
2032 - ret = invoke_bpf_prog(ctx, fmod_ret->nodes[i],
2060 + ret = invoke_bpf_prog(ctx, im, fmod_ret->nodes[i],
2033 2061 args_off, retval_off, run_ctx_off, true);
2034 2062 if (ret)
2035 2063 goto out;
@@ -2051,10 +2079,6 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
2051 2079 goto out;
2052 2080 emit_insn(ctx, std, LOONGARCH_GPR_A0, LOONGARCH_GPR_FP, -retval_off);
2053 2081 emit_insn(ctx, std, regmap[BPF_REG_0], LOONGARCH_GPR_FP, -(retval_off - 8));
2054 - im->ip_after_call = ctx->ro_image + ctx->idx;
2055 - /* Reserve space for the move_imm + jirl instruction */
2056 - for (i = 0; i < LOONGARCH_LONG_JUMP_NINSNS; i++)
2057 - emit_insn(ctx, nop);
2058 2082 }
2059 2083
2060 2084 for (i = 0; ctx->image && i < fmod_ret->nr_nodes; i++) {
@@ -2068,14 +2092,13 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
2068 2092 emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -func_meta_off, func_meta);
2069 2093
2070 2094 if (fexit->nr_nodes) {
2071 - ret = invoke_bpf(ctx, fexit, args_off, retval_off, run_ctx_off,
2095 + ret = invoke_bpf(ctx, im, fexit, args_off, retval_off, run_ctx_off,
2072 2096 func_meta_off, false, func_meta, cookie_off);
2073 2097 if (ret)
2074 2098 goto out;
2075 2099 }
2076 2100
2077 2101 if (flags & BPF_TRAMP_F_CALL_ORIG) {
2078 - im->ip_epilogue = ctx->ro_image + ctx->idx;
2079 2102 move_addr(ctx, LOONGARCH_GPR_A0, (const u64)im);
2080 2103 ret = emit_call(ctx, (const u64)__bpf_tramp_exit);
2081 2104 if (ret)
@@ -2177,11 +2200,8 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
2177 2200 struct bpf_tramp_nodes *tnodes, void *func_addr)
2178 2201 {
2179 2202 int ret;
2180 - struct jit_ctx ctx;
2181 - struct bpf_tramp_image im;
2182 -
2183 - ctx.image = NULL;
2184 - ctx.idx = 0;
2203 + struct jit_ctx ctx = {};
2204 + struct bpf_tramp_image im = {};
2185 2205
2186 2206 ret = __arch_prepare_bpf_trampoline(&ctx, &im, m, tnodes, func_addr, flags);
2187 2207
modified arch/loongarch/vdso/Makefile
@@ -16,6 +16,7 @@ ccflags-vdso := \
16 16 $(filter -m64,$(KBUILD_CFLAGS)) \
17 17 $(filter -march=%,$(KBUILD_CFLAGS)) \
18 18 $(filter -m%-float,$(KBUILD_CFLAGS)) \
19 + $(CONFIG_CC_OPT_INLINE_MEMSET) \
19 20 $(CLANG_FLAGS) \
20 21 -D__VDSO__
21 22
modified arch/powerpc/kernel/vdso/Makefile
@@ -43,6 +43,7 @@ ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO
43 43 ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN)
44 44 ccflags-y += $(call cc-option, -fno-stack-protector)
45 45 ccflags-y += -DDISABLE_BRANCH_PROFILING
46 + ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET)
46 47 ccflags-y += -ffreestanding -fasynchronous-unwind-tables
47 48 ccflags-remove-y := $(CC_FLAGS_FTRACE)
48 49 ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS)
modified arch/powerpc/kvm/book3s_hv.c
@@ -3058,7 +3058,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
3058 3058
3059 3059 init_waitqueue_head(&vcpu->arch.cpu_run);
3060 3060
3061 - mutex_lock(&kvm->lock);
3062 3061 vcore = NULL;
3063 3062 err = -EINVAL;
3064 3063 if (cpu_has_feature(CPU_FTR_ARCH_300)) {
@@ -3091,7 +3090,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
3091 3090 mutex_unlock(&kvm->arch.mmu_setup_lock);
3092 3091 }
3093 3092 }
3094 - mutex_unlock(&kvm->lock);
3095 3093
3096 3094 if (!vcore)
3097 3095 return err;
modified arch/powerpc/net/bpf_jit_comp.c
@@ -602,14 +602,18 @@ int arch_protect_bpf_trampoline(void *image, unsigned int size)
602 602 }
603 603
604 604 static int invoke_bpf_prog(u32 *image, u32 *ro_image, struct codegen_context *ctx,
605 - struct bpf_tramp_node *n, int regs_off, int retval_off,
606 - int run_ctx_off, bool save_ret)
605 + struct bpf_tramp_image *im, struct bpf_tramp_node *n,
606 + int regs_off, int retval_off, int run_ctx_off, bool save_ret)
607 607 {
608 608 struct bpf_prog *p = n->link->prog;
609 609 ppc_inst_t branch_insn;
610 - u32 jmp_idx;
610 + u32 jmp_idx, skip_idx;
611 611 int ret = 0;
612 612
613 + /* nop, patched to skip this prog when it is detached */
614 + skip_idx = ctx->idx;
615 + EMIT(PPC_RAW_NOP());
616 +
613 617 /* Save cookie */
614 618 if (IS_ENABLED(CONFIG_PPC64)) {
615 619 PPC_LI64(_R3, n->cookie);
@@ -679,13 +683,17 @@ static int invoke_bpf_prog(u32 *image, u32 *ro_image, struct codegen_context *ct
679 683 EMIT(PPC_RAW_ADDI(_R5, _R1, run_ctx_off));
680 684 ret = bpf_jit_emit_func_call_rel(image, ro_image, ctx,
681 685 (unsigned long)bpf_trampoline_exit(p));
686 + if (ret)
687 + return ret;
682 688
683 - return ret;
689 + if (ro_image) /* image is NULL for dummy pass */
690 + bpf_tramp_image_add_skip(im, p, &ro_image[skip_idx], &ro_image[ctx->idx]);
691 + return 0;
684 692 }
685 693
686 694 static int invoke_bpf_mod_ret(u32 *image, u32 *ro_image, struct codegen_context *ctx,
687 - struct bpf_tramp_nodes *tn, int regs_off, int retval_off,
688 - int run_ctx_off, u32 *branches)
695 + struct bpf_tramp_image *im, struct bpf_tramp_nodes *tn,
696 + int regs_off, int retval_off, int run_ctx_off, u32 *branches)
689 697 {
690 698 int i;
691 699
@@ -696,8 +704,8 @@ static int invoke_bpf_mod_ret(u32 *image, u32 *ro_image, struct codegen_context
696 704 EMIT(PPC_RAW_LI(_R3, 0));
697 705 EMIT(PPC_RAW_STL(_R3, _R1, retval_off));
698 706 for (i = 0; i < tn->nr_nodes; i++) {
699 - if (invoke_bpf_prog(image, ro_image, ctx, tn->nodes[i], regs_off, retval_off,
700 - run_ctx_off, true))
707 + if (invoke_bpf_prog(image, ro_image, ctx, im, tn->nodes[i], regs_off,
708 + retval_off, run_ctx_off, true))
701 709 return -EINVAL;
702 710
703 711 /*
@@ -1043,8 +1051,8 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
1043 1051 cookie_ctx_off--;
1044 1052 }
1045 1053
1046 - if (invoke_bpf_prog(image, ro_image, ctx, fentry->nodes[i], regs_off, retval_off,
1047 - run_ctx_off, flags & BPF_TRAMP_F_RET_FENTRY_RET))
1054 + if (invoke_bpf_prog(image, ro_image, ctx, im, fentry->nodes[i], regs_off,
1055 + retval_off, run_ctx_off, flags & BPF_TRAMP_F_RET_FENTRY_RET))
1048 1056 return -EINVAL;
1049 1057 }
1050 1058
@@ -1053,7 +1061,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
1053 1061 if (!branches)
1054 1062 return -ENOMEM;
1055 1063
1056 - if (invoke_bpf_mod_ret(image, ro_image, ctx, fmod_ret, regs_off, retval_off,
1064 + if (invoke_bpf_mod_ret(image, ro_image, ctx, im, fmod_ret, regs_off, retval_off,
1057 1065 run_ctx_off, branches)) {
1058 1066 ret = -EINVAL;
1059 1067 goto cleanup;
@@ -1090,11 +1098,6 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
1090 1098 /* Restore updated tail_call_cnt */
1091 1099 if (flags & BPF_TRAMP_F_TAIL_CALL_CTX)
1092 1100 bpf_trampoline_restore_tail_call_cnt(image, ctx, bpf_frame_size, r4_off);
1093 -
1094 - /* Reserve space to patch branch instruction to skip fexit progs */
1095 - if (ro_image) /* image is NULL for dummy pass */
1096 - im->ip_after_call = &((u32 *)ro_image)[ctx->idx];
1097 - EMIT(PPC_RAW_NOP());
1098 1101 }
1099 1102
1100 1103 /* Update branches saved in invoke_bpf_mod_ret with address of do_fexit */
@@ -1123,16 +1126,14 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
1123 1126 cookie_ctx_off--;
1124 1127 }
1125 1128
1126 - if (invoke_bpf_prog(image, ro_image, ctx, fexit->nodes[i], regs_off, retval_off,
1127 - run_ctx_off, false)) {
1129 + if (invoke_bpf_prog(image, ro_image, ctx, im, fexit->nodes[i], regs_off,
1130 + retval_off, run_ctx_off, false)) {
1128 1131 ret = -EINVAL;
1129 1132 goto cleanup;
1130 1133 }
1131 1134 }
1132 1135
1133 1136 if (flags & BPF_TRAMP_F_CALL_ORIG) {
1134 - if (ro_image) /* image is NULL for dummy pass */
1135 - im->ip_epilogue = &((u32 *)ro_image)[ctx->idx];
1136 1137 PPC_LI_ADDR(_R3, im);
1137 1138 ret = bpf_jit_emit_func_call_rel(image, ro_image, ctx,
1138 1139 (unsigned long)__bpf_tramp_exit);
@@ -1192,7 +1193,7 @@ cleanup:
1192 1193 int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
1193 1194 struct bpf_tramp_nodes *tnodes, void *func_addr)
1194 1195 {
1195 - struct bpf_tramp_image im;
1196 + struct bpf_tramp_image im = {};
1196 1197 int ret;
1197 1198
1198 1199 ret = __arch_prepare_bpf_trampoline(&im, NULL, NULL, NULL, m, flags, tnodes, func_addr);
@@ -1320,7 +1321,7 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
1320 1321
1321 1322 /*
1322 1323 * If we are not poking at bpf prog entry, then we are simply patching in/out
1323 - * an unconditional branch instruction at im->ip_after_call
1324 + * an unconditional branch instruction in a trampoline image
1324 1325 */
1325 1326 if (offset) {
1326 1327 if (old_t == BPF_MOD_CALL || new_t == BPF_MOD_CALL) {
modified arch/powerpc/perf/imc-pmu.c
@@ -1275,6 +1275,8 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,
1275 1275 struct perf_event_header *header,
1276 1276 struct perf_event *event)
1277 1277 {
1278 + u16 misc = 0;
1279 +
1278 1280 /* Sanity checks for a valid record */
1279 1281 if (be64_to_cpu(READ_ONCE(mem->tb1)) > *prev_tb)
1280 1282 *prev_tb = be64_to_cpu(READ_ONCE(mem->tb1));
@@ -1289,23 +1291,19 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,
1289 1291 data->ip = be64_to_cpu(READ_ONCE(mem->ip));
1290 1292 data->period = event->hw.last_period;
1291 1293
1292 - header->type = PERF_RECORD_SAMPLE;
1293 - header->size = sizeof(*header) + event->header_size;
1294 - header->misc = 0;
1295 -
1296 1294 if (cpu_has_feature(CPU_FTR_ARCH_31)) {
1297 1295 switch (IMC_TRACE_RECORD_VAL_HVPR(be64_to_cpu(READ_ONCE(mem->val)))) {
1298 1296 case 0:/* when MSR HV and PR not set in the trace-record */
1299 - header->misc |= PERF_RECORD_MISC_GUEST_KERNEL;
1297 + misc |= PERF_RECORD_MISC_GUEST_KERNEL;
1300 1298 break;
1301 1299 case 1: /* MSR HV is 0 and PR is 1 */
1302 - header->misc |= PERF_RECORD_MISC_GUEST_USER;
1300 + misc |= PERF_RECORD_MISC_GUEST_USER;
1303 1301 break;
1304 1302 case 2: /* MSR HV is 1 and PR is 0 */
1305 - header->misc |= PERF_RECORD_MISC_KERNEL;
1303 + misc |= PERF_RECORD_MISC_KERNEL;
1306 1304 break;
1307 1305 case 3: /* MSR HV is 1 and PR is 1 */
1308 - header->misc |= PERF_RECORD_MISC_USER;
1306 + misc |= PERF_RECORD_MISC_USER;
1309 1307 break;
1310 1308 default:
1311 1309 pr_info("IMC: Unable to set the flag based on MSR bits\n");
@@ -1313,11 +1311,14 @@ static int trace_imc_prepare_sample(struct trace_imc_data *mem,
1313 1311 }
1314 1312 } else {
1315 1313 if (is_kernel_addr(data->ip))
1316 - header->misc |= PERF_RECORD_MISC_KERNEL;
1314 + misc |= PERF_RECORD_MISC_KERNEL;
1317 1315 else
1318 - header->misc |= PERF_RECORD_MISC_USER;
1316 + misc |= PERF_RECORD_MISC_USER;
1319 1317 }
1320 - perf_event_header__init_id(header, data, event);
1318 + perf_event_header__init(header, data,
1319 + PERF_RECORD_SAMPLE, misc,
1320 + sizeof(*header) + event->header_size,
1321 + event);
1321 1322
1322 1323 return 0;
1323 1324 }
modified arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dts
@@ -90,6 +90,10 @@
90 90 };
91 91
92 92 &gpio0 {
93 + interrupts = <13>, <14>, <15>, <16>,
94 + <17>, <18>, <19>, <20>,
95 + <21>, <22>, <23>, <24>,
96 + <25>, <26>;
93 97 ngpios = <14>;
94 98 gpio-line-names = "", "", "", "", "", "", "",
95 99 "", "", "", "", "", "SD_CARD_CS", "USER_BUTTON";
@@ -97,6 +101,12 @@
97 101 };
98 102
99 103 &gpio1 {
104 + interrupts = <27>, <28>, <29>, <30>,
105 + <31>, <32>, <33>, <34>,
106 + <35>, <36>, <37>, <38>,
107 + <39>, <40>, <41>, <42>,
108 + <43>, <44>, <45>, <46>,
109 + <47>, <48>, <49>, <50>;
100 110 ngpios = <24>;
101 111 gpio-line-names = "", "", "", "", "", "", "", "", "", "",
102 112 "", "", "", "", "", "", "", "", "", "",
@@ -105,6 +115,14 @@
105 115 };
106 116
107 117 &gpio2 {
118 + interrupts = <53>, <53>, <53>, <53>,
119 + <53>, <53>, <53>, <53>,
120 + <53>, <53>, <53>, <53>,
121 + <53>, <53>, <53>, <53>,
122 + <53>, <53>, <53>, <53>,
123 + <53>, <53>, <53>, <53>,
124 + <53>, <53>, <53>, <53>,
125 + <53>, <53>, <53>, <53>;
108 126 ngpios = <32>;
109 127 gpio-line-names = "P8_PIN3_USER_LED_0", "P8_PIN4_USER_LED_1", "P8_PIN5_USER_LED_2",
110 128 "P8_PIN6_USER_LED_3", "P8_PIN7_USER_LED_4", "P8_PIN8_USER_LED_5",
modified arch/riscv/kernel/vdso/Makefile
@@ -36,6 +36,7 @@ endif
36 36 ccflags-y := -fno-stack-protector
37 37 ccflags-y += -DDISABLE_BRANCH_PROFILING
38 38 ccflags-y += -fno-builtin
39 + ccflags-y += $(CONFIG_CC_OPT_INLINE_MEMSET)
39 40 ccflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
40 41 ccflags-y += $(CFI_FULL)
41 42 asflags-y += $(KBUILD_BASE_ISA)$(CFI_MARCH)
modified arch/riscv/kvm/aia_device.c
@@ -237,7 +237,7 @@ static int aia_init(struct kvm *kvm)
237 237 return -EBUSY;
238 238
239 239 /* We might be in the middle of creating a VCPU? */
240 - if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
240 + if (kvm_is_vcpu_creation_in_progress(kvm))
241 241 return -EBUSY;
242 242
243 243 /* Number of sources should be less than or equals number of IDs */
modified arch/riscv/net/bpf_jit_comp64.c
@@ -822,6 +822,24 @@ static int gen_jump_or_nops(void *target, void *ip, u32 *insns, bool is_call)
822 822 return emit_jump_and_link(is_call ? RV_REG_T0 : RV_REG_ZERO, rvoff, false, &ctx);
823 823 }
824 824
825 + int arch_bpf_trampoline_skip(void *nop, void *target)
826 + {
827 + u32 old_insn = rv_nop();
828 + u32 new_insn = rv_jal(RV_REG_ZERO, (target - nop) >> 1);
829 + int ret;
830 +
831 + if (memcmp(nop, &old_insn, sizeof(old_insn)))
832 + return -EFAULT;
833 +
834 + cpus_read_lock();
835 + mutex_lock(&text_mutex);
836 + ret = patch_text(nop, &new_insn, sizeof(new_insn));
837 + mutex_unlock(&text_mutex);
838 + cpus_read_unlock();
839 +
840 + return ret;
841 + }
842 +
825 843 int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
826 844 enum bpf_text_poke_type new_t, void *old_addr,
827 845 void *new_addr)
@@ -904,12 +922,17 @@ static void emit_store_stack_imm64(u8 reg, int stack_off, u64 imm64,
904 922 emit_sd(RV_REG_FP, stack_off, reg, ctx);
905 923 }
906 924
907 - static int invoke_bpf_prog(struct bpf_tramp_node *node, int args_off, int retval_off,
908 - int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
925 + static int invoke_bpf_prog(struct bpf_tramp_image *im, struct bpf_tramp_node *node,
926 + int args_off, int retval_off, int run_ctx_off, bool save_ret,
927 + struct rv_jit_context *ctx)
909 928 {
910 929 int ret, branch_off;
911 930 struct bpf_prog *p = node->link->prog;
912 931 int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
932 + void *skip = ctx->ro_insns + ctx->ninsns;
933 +
934 + /* nop, patched to a jal over this prog when it is detached */
935 + emit(rv_nop(), ctx);
913 936
914 937 if (node->cookie)
915 938 emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, node->cookie, ctx);
@@ -962,13 +985,17 @@ static int invoke_bpf_prog(struct bpf_tramp_node *node, int args_off, int retval
962 985 /* arg3: &run_ctx */
963 986 emit_addi(RV_REG_A2, RV_REG_FP, -run_ctx_off, ctx);
964 987 ret = emit_call((const u64)bpf_trampoline_exit(p), true, ctx);
988 + if (ret)
989 + return ret;
965 990
966 - return ret;
991 + bpf_tramp_image_add_skip(im, p, skip, ctx->ro_insns + ctx->ninsns);
992 + return 0;
967 993 }
968 994
969 - static int invoke_bpf(struct bpf_tramp_nodes *tn, int args_off, int retval_off,
970 - int run_ctx_off, int func_meta_off, bool save_ret, u64 func_meta,
971 - int cookie_off, struct rv_jit_context *ctx)
995 + static int invoke_bpf(struct bpf_tramp_image *im, struct bpf_tramp_nodes *tn,
996 + int args_off, int retval_off, int run_ctx_off, int func_meta_off,
997 + bool save_ret, u64 func_meta, int cookie_off,
998 + struct rv_jit_context *ctx)
972 999 {
973 1000 int i, cur_cookie = (cookie_off - args_off) / 8;
974 1001
@@ -981,8 +1008,8 @@ static int invoke_bpf(struct bpf_tramp_nodes *tn, int args_off, int retval_off,
981 1008 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, meta, ctx);
982 1009 cur_cookie--;
983 1010 }
984 - err = invoke_bpf_prog(tn->nodes[i], args_off, retval_off, run_ctx_off,
985 - save_ret, ctx);
1011 + err = invoke_bpf_prog(im, tn->nodes[i], args_off, retval_off,
1012 + run_ctx_off, save_ret, ctx);
986 1013 if (err)
987 1014 return err;
988 1015 }
@@ -1170,7 +1197,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
1170 1197 }
1171 1198
1172 1199 if (fentry->nr_nodes) {
1173 - ret = invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_off,
1200 + ret = invoke_bpf(im, fentry, args_off, retval_off, run_ctx_off, func_meta_off,
1174 1201 flags & BPF_TRAMP_F_RET_FENTRY_RET, func_meta, cookie_off, ctx);
1175 1202 if (ret)
1176 1203 return ret;
@@ -1184,7 +1211,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
1184 1211 /* cleanup to avoid garbage return value confusion */
1185 1212 emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx);
1186 1213 for (i = 0; i < fmod_ret->nr_nodes; i++) {
1187 - ret = invoke_bpf_prog(fmod_ret->nodes[i], args_off, retval_off,
1214 + ret = invoke_bpf_prog(im, fmod_ret->nodes[i], args_off, retval_off,
1188 1215 run_ctx_off, true, ctx);
1189 1216 if (ret)
1190 1217 goto out;
@@ -1211,10 +1238,6 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
1211 1238 emit_sd(RV_REG_FP, -tcc_off, RV_REG_TCC, ctx);
1212 1239 emit_sd(RV_REG_FP, -retval_off, RV_REG_A0, ctx);
1213 1240 emit_sd(RV_REG_FP, -(retval_off - 8), regmap[BPF_REG_0], ctx);
1214 - im->ip_after_call = ctx->ro_insns + ctx->ninsns;
1215 - /* 2 nops reserved for auipc+jalr pair */
1216 - emit(rv_nop(), ctx);
1217 - emit(rv_nop(), ctx);
1218 1241 }
1219 1242
1220 1243 /* update branches saved in invoke_bpf_mod_ret with bnez */
@@ -1230,14 +1253,13 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
1230 1253 emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx);
1231 1254
1232 1255 if (fexit->nr_nodes) {
1233 - ret = invoke_bpf(fexit, args_off, retval_off, run_ctx_off, func_meta_off,
1256 + ret = invoke_bpf(im, fexit, args_off, retval_off, run_ctx_off, func_meta_off,
1234 1257 false, func_meta, cookie_off, ctx);
1235 1258 if (ret)
1236 1259 goto out;
1237 1260 }
1238 1261
1239 1262 if (flags & BPF_TRAMP_F_CALL_ORIG) {
1240 - im->ip_epilogue = ctx->ro_insns + ctx->ninsns;
1241 1263 emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx);
1242 1264 ret = emit_call((const u64)__bpf_tramp_exit, true, ctx);
1243 1265 if (ret)
@@ -1299,7 +1321,7 @@ out:
1299 1321 int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
1300 1322 struct bpf_tramp_nodes *tnodes, void *func_addr)
1301 1323 {
1302 - struct bpf_tramp_image im;
1324 + struct bpf_tramp_image im = {};
1303 1325 struct rv_jit_context ctx;
1304 1326 int ret;
1305 1327
modified arch/s390/kernel/vdso/Makefile
@@ -29,6 +29,7 @@ KBUILD_CFLAGS_VDSO := $(filter-out -munaligned-symbols,$(KBUILD_CFLAGS_VDSO))
29 29 KBUILD_CFLAGS_VDSO := $(filter-out -fno-asynchronous-unwind-tables,$(KBUILD_CFLAGS_VDSO))
30 30 KBUILD_CFLAGS_VDSO += -fPIC -fno-common -fno-builtin -fasynchronous-unwind-tables
31 31 KBUILD_CFLAGS_VDSO += -fno-stack-protector $(DISABLE_KSTACK_ERASE)
32 + KBUILD_CFLAGS_VDSO += $(CONFIG_CC_OPT_INLINE_MEMSET)
32 33 ldflags-y := -shared -soname=linux-vdso.so.1 \
33 34 --hash-style=both --build-id=sha1 \
34 35 $(call ld-option, --eh-frame-hdr) -T
modified arch/s390/kvm/s390/s390.c
@@ -3579,12 +3579,11 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
3579 3579
3580 3580 void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
3581 3581 {
3582 - mutex_lock(&vcpu->kvm->lock);
3583 3582 preempt_disable();
3584 3583 vcpu->arch.sie_block->epoch = vcpu->kvm->arch.epoch;
3585 3584 vcpu->arch.sie_block->epdx = vcpu->kvm->arch.epdx;
3586 3585 preempt_enable();
3587 - mutex_unlock(&vcpu->kvm->lock);
3586 +
3588 3587 if (!kvm_is_ucontrol(vcpu->kvm)) {
3589 3588 vcpu->arch.gmap = vcpu->kvm->arch.gmap;
3590 3589 sca_add_vcpu(vcpu);
@@ -3757,13 +3756,11 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
3757 3756
3758 3757 kvm_s390_vcpu_pci_setup(vcpu);
3759 3758
3760 - mutex_lock(&vcpu->kvm->lock);
3761 3759 if (kvm_s390_pv_is_protected(vcpu->kvm)) {
3762 3760 rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc);
3763 3761 if (rc)
3764 3762 kvm_s390_vcpu_unsetup_cmma(vcpu);
3765 3763 }
3766 - mutex_unlock(&vcpu->kvm->lock);
3767 3764
3768 3765 return rc;
3769 3766 }
modified arch/s390/net/bpf_jit_comp.c
@@ -2566,6 +2566,8 @@ struct bpf_tramp_jit {
2566 2566 int r14_off; /* Offset of saved %r14, has to be at the
2567 2567 * bottom */
2568 2568 int do_fexit; /* do_fexit: label */
2569 + int skip[BPF_MAX_TRAMP_LINKS]; /* skip: labels after each prog */
2570 + int nr_progs;
2569 2571 };
2570 2572
2571 2573 static void load_imm64(struct bpf_jit *jit, int dst_reg, u64 val)
@@ -2584,6 +2586,7 @@ static void emit_store_stack_imm64(struct bpf_jit *jit, int tmp_reg, int stack_o
2584 2586 }
2585 2587
2586 2588 static int invoke_bpf_prog(struct bpf_tramp_jit *tjit,
2589 + struct bpf_tramp_image *im,
2587 2590 const struct btf_func_model *m,
2588 2591 struct bpf_tramp_node *node, bool save_ret)
2589 2592 {
@@ -2591,8 +2594,20 @@ static int invoke_bpf_prog(struct bpf_tramp_jit *tjit,
2591 2594 int cookie_off = tjit->run_ctx_off +
2592 2595 offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
2593 2596 struct bpf_prog *p = node->link->prog;
2597 + void *skip = jit->prg_buf + jit->prg;
2598 + int idx = tjit->nr_progs++;
2594 2599 int patch;
2595 2600
2601 + if (idx >= ARRAY_SIZE(tjit->skip))
2602 + return -E2BIG;
2603 +
2604 + /*
2605 + * nop, patched to skip this prog when it is detached
2606 + */
2607 +
2608 + /* brcl 0,skip */
2609 + EMIT6_PCREL_RILC(0xc0040000, 0, tjit->skip[idx]);
2610 +
2596 2611 /*
2597 2612 * run_ctx.cookie = node->cookie;
2598 2613 */
@@ -2652,10 +2667,15 @@ static int invoke_bpf_prog(struct bpf_tramp_jit *tjit,
2652 2667 /* brasl %r14,__bpf_prog_exit */
2653 2668 EMIT6_PCREL_RILB_PTR(0xc0050000, REG_14, bpf_trampoline_exit(p));
2654 2669
2670 + /* skip: */
2671 + tjit->skip[idx] = jit->prg;
2672 + bpf_tramp_image_add_skip(im, p, skip, jit->prg_buf + jit->prg);
2673 +
2655 2674 return 0;
2656 2675 }
2657 2676
2658 2677 static int invoke_bpf(struct bpf_tramp_jit *tjit,
2678 + struct bpf_tramp_image *im,
2659 2679 const struct btf_func_model *m,
2660 2680 struct bpf_tramp_nodes *tn, bool save_ret,
2661 2681 u64 func_meta, int cookie_off)
@@ -2670,7 +2690,7 @@ static int invoke_bpf(struct bpf_tramp_jit *tjit,
2670 2690 emit_store_stack_imm64(jit, REG_0, tjit->func_meta_off, meta);
2671 2691 cur_cookie--;
2672 2692 }
2673 - if (invoke_bpf_prog(tjit, m, tn->nodes[i], save_ret))
2693 + if (invoke_bpf_prog(tjit, im, m, tn->nodes[i], save_ret))
2674 2694 return -EINVAL;
2675 2695 }
2676 2696
@@ -2712,6 +2732,11 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2712 2732 u64 func_meta;
2713 2733 int i, j;
2714 2734
2735 + /* The skip labels are taken from the previous pass. */
2736 + tjit->nr_progs = 0;
2737 + if (im)
2738 + im->nr_skips = 0;
2739 +
2715 2740 /* Support as many stack arguments as "mvc" instruction can handle. */
2716 2741 nr_reg_args = min_t(int, m->nr_args, MAX_NR_REG_ARGS);
2717 2742 nr_stack_args = m->nr_args - nr_reg_args;
@@ -2875,7 +2900,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2875 2900 emit_store_stack_imm64(jit, REG_0, tjit->retval_off, 0);
2876 2901 }
2877 2902
2878 - if (invoke_bpf(tjit, m, fentry, flags & BPF_TRAMP_F_RET_FENTRY_RET,
2903 + if (invoke_bpf(tjit, im, m, fentry, flags & BPF_TRAMP_F_RET_FENTRY_RET,
2879 2904 func_meta, cookie_off))
2880 2905 return -EINVAL;
2881 2906
@@ -2889,7 +2914,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2889 2914 0xf000 | tjit->retval_off);
2890 2915
2891 2916 for (i = 0; i < fmod_ret->nr_nodes; i++) {
2892 - if (invoke_bpf_prog(tjit, m, fmod_ret->nodes[i], true))
2917 + if (invoke_bpf_prog(tjit, im, m, fmod_ret->nodes[i], true))
2893 2918 return -EINVAL;
2894 2919
2895 2920 /*
@@ -2943,15 +2968,6 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2943 2968 /* mvc tccnt_off(%r15),tail_call_cnt(4,%r15) */
2944 2969 _EMIT6(0xd203f000 | tjit->tccnt_off,
2945 2970 0xf000 | offsetof(struct prog_frame, tail_call_cnt));
2946 -
2947 - im->ip_after_call = jit->prg_buf + jit->prg;
2948 -
2949 - /*
2950 - * The following nop will be patched by bpf_tramp_image_put().
2951 - */
2952 -
2953 - /* brcl 0,im->ip_epilogue */
2954 - EMIT6_PCREL_RILC(0xc0040000, 0, (u64)im->ip_epilogue);
2955 2971 }
2956 2972
2957 2973 /* Set the "is_return" flag for fsession. */
@@ -2962,12 +2978,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2962 2978
2963 2979 /* do_fexit: */
2964 2980 tjit->do_fexit = jit->prg;
2965 - if (invoke_bpf(tjit, m, fexit, false, func_meta, cookie_off))
2981 + if (invoke_bpf(tjit, im, m, fexit, false, func_meta, cookie_off))
2966 2982 return -EINVAL;
2967 2983
2968 2984 if (flags & BPF_TRAMP_F_CALL_ORIG) {
2969 - im->ip_epilogue = jit->prg_buf + jit->prg;
2970 -
2971 2985 /*
2972 2986 * __bpf_tramp_exit(im);
2973 2987 */
@@ -3016,7 +3030,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
3016 3030 int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
3017 3031 struct bpf_tramp_nodes *tnodes, void *orig_call)
3018 3032 {
3019 - struct bpf_tramp_image im;
3033 + struct bpf_tramp_image im = {};
3020 3034 struct bpf_tramp_jit tjit;
3021 3035 int ret;
3022 3036
modified arch/x86/crypto/aesni-intel_glue.c
@@ -1293,6 +1293,7 @@ static void gcm_process_assoc(const struct aes_gcm_key *key, u8 ghash_acc[16],
1293 1293 unsigned int len;
1294 1294 const u8 *src = walk.addr;
1295 1295
1296 + assoclen -= orig_len_this_step;
1296 1297 if (unlikely(pos)) {
1297 1298 len = min(len_this_step, 16 - pos);
1298 1299 memcpy(&buf[pos], src, len);
@@ -1320,7 +1321,6 @@ next:
1320 1321 kernel_fpu_end();
1321 1322 kernel_fpu_begin();
1322 1323 }
1323 - assoclen -= orig_len_this_step;
1324 1324 }
1325 1325 if (unlikely(pos))
1326 1326 aes_gcm_aad_update(key, ghash_acc, buf, pos, flags);
modified arch/x86/entry/vdso/vdso64/Makefile
@@ -14,7 +14,7 @@ vobjs-$(CONFIG_X86_SGX) += vsgx.o
14 14 vobjs-$(CONFIG_FUTEX_ROBUST_UNLOCK) += vfutex.o
15 15
16 16 # Compilation flags
17 - flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small
17 + flags-y := -DBUILD_VDSO64 -m64 -mcmodel=small $(CONFIG_CC_OPT_INLINE_MEMSET)
18 18
19 19 # The location of this include matters!
20 20 include $(src)/../common/Makefile.include
modified arch/x86/include/uapi/asm/ptrace-abi.h
@@ -2,6 +2,7 @@
2 2 #ifndef _ASM_X86_PTRACE_ABI_H
3 3 #define _ASM_X86_PTRACE_ABI_H
4 4
5 + #if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)
5 6 #ifdef __i386__
6 7
7 8 #define EBX 0
@@ -25,7 +26,6 @@
25 26
26 27 #else /* __i386__ */
27 28
28 - #if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)
29 29 /*
30 30 * C ABI says these regs are callee-preserved. They aren't saved on kernel entry
31 31 * unless syscall needs a complete, fully filled "struct pt_regs".
@@ -57,12 +57,12 @@
57 57 #define EFLAGS 144
58 58 #define RSP 152
59 59 #define SS 160
60 - #endif /* __ASSEMBLER__ */
61 60
62 61 /* top of stack page */
63 62 #define FRAME_SIZE 168
64 63
65 64 #endif /* !__i386__ */
65 + #endif /* defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) */
66 66
67 67 /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */
68 68 #define PTRACE_GETREGS 12
modified arch/x86/kernel/sys_x86_64.c
@@ -50,9 +50,16 @@ static unsigned long get_align_mask(struct file *filp)
50 50 * value before calling vm_unmapped_area() or ORed directly to the
51 51 * address.
52 52 */
53 - static unsigned long get_align_bits(void)
53 + static unsigned long get_align_bits(struct file *filp)
54 54 {
55 - return va_align.bits & get_align_mask(NULL);
55 + /*
56 + * va_align.bits is smaller than the huge page size and will
57 + * lead to misaligned huge pages. Ignore it for huge mappings.
58 + */
59 + if (is_file_hugepages(filp))
60 + return 0;
61 +
62 + return va_align.bits & get_align_mask(filp);
56 63 }
57 64
58 65 static int __init control_va_addr_alignment(char *str)
@@ -157,7 +164,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
157 164 }
158 165 if (filp) {
159 166 info.align_mask = get_align_mask(filp);
160 - info.align_offset += get_align_bits();
167 + info.align_offset += get_align_bits(filp);
161 168 }
162 169
163 170 return vm_unmapped_area(&info);
@@ -222,7 +229,7 @@ get_unmapped_area:
222 229
223 230 if (filp) {
224 231 info.align_mask = get_align_mask(filp);
225 - info.align_offset += get_align_bits();
232 + info.align_offset += get_align_bits(filp);
226 233 }
227 234 addr = vm_unmapped_area(&info);
228 235 if (!(addr & ~PAGE_MASK))
modified arch/x86/kvm/mmu/mmu.c
@@ -2512,6 +2512,12 @@ static void shadow_walk_init_using_root(struct kvm_shadow_walk_iterator *iterato
2512 2512
2513 2513 iterator->addr = addr;
2514 2514 iterator->shadow_addr = root;
2515 +
2516 + if (WARN_ON_ONCE(!VALID_PAGE(root)) || kvm_mmu_is_dummy_root(root)) {
2517 + iterator->level = 0;
2518 + return;
2519 + }
2520 +
2515 2521 iterator->level = vcpu->arch.mmu->root_role.level;
2516 2522
2517 2523 if (iterator->level >= PT64_ROOT_4LEVEL &&
modified arch/x86/kvm/svm/sev.c
@@ -488,6 +488,20 @@ static void snp_guest_req_cleanup(struct kvm *kvm)
488 488 sev->guest_resp_buf = NULL;
489 489 }
490 490
491 + static int sev_alloc_have_run_cpus(struct kvm_sev_info *sev)
492 + {
493 + if (!zalloc_cpumask_var(&sev->have_run_cpus, GFP_KERNEL_ACCOUNT))
494 + return -ENOMEM;
495 +
496 + return 0;
497 + }
498 +
499 + static void sev_free_have_run_cpus(struct kvm_sev_info *sev)
500 + {
501 + free_cpumask_var(sev->have_run_cpus);
502 + memset(&sev->have_run_cpus, 0, sizeof(sev->have_run_cpus));
503 + }
504 +
491 505 static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
492 506 struct kvm_sev_init *data,
493 507 unsigned long vm_type)
@@ -545,10 +559,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
545 559 if (ret)
546 560 goto e_free_asid;
547 561
548 - if (!zalloc_cpumask_var(&sev->have_run_cpus, GFP_KERNEL_ACCOUNT)) {
549 - ret = -ENOMEM;
562 + ret = sev_alloc_have_run_cpus(sev);
563 + if (ret)
550 564 goto e_free_asid;
551 - }
552 565
553 566 /* This needs to happen after SEV/SNP firmware initialization. */
554 567 if (snp_active) {
@@ -566,7 +579,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
566 579 return 0;
567 580
568 581 e_free:
569 - free_cpumask_var(sev->have_run_cpus);
582 + sev_free_have_run_cpus(sev);
570 583 e_free_asid:
571 584 argp->error = init_args.error;
572 585 sev_asid_free(sev);
@@ -1125,9 +1138,6 @@ static int sev_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
1125 1138 if (!sev_es_guest(kvm))
1126 1139 return -ENOTTY;
1127 1140
1128 - if (kvm_is_vcpu_creation_in_progress(kvm))
1129 - return -EBUSY;
1130 -
1131 1141 ret = kvm_lock_all_vcpus(kvm);
1132 1142 if (ret)
1133 1143 return ret;
@@ -2035,6 +2045,13 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
2035 2045 struct kvm_sev_info *mirror;
2036 2046 unsigned long i;
2037 2047
2048 + /*
2049 + * Do cache maintenance on the source VM *before* clearing "SEV active",
2050 + * as memory reclaim flows won't trigger cache maintenance on the VM
2051 + * once it's no longer an SEV VM.
2052 + */
2053 + sev_writeback_caches(src_kvm);
2054 +
2038 2055 dst->active = true;
2039 2056 dst->asid = src->asid;
2040 2057 dst->handle = src->handle;
@@ -2048,12 +2065,6 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
2048 2065 src->pages_locked = 0;
2049 2066 src->es_active = false;
2050 2067
2051 - /*
2052 - * Do cache maintenance on the source VM as it is no longer an SEV VM,
2053 - * i.e. memory reclaim flows won't trigger cache maintenance on the VM.
2054 - */
2055 - sev_writeback_caches(src_kvm);
2056 -
2057 2068 list_cut_before(&dst->regions_list, &src->regions_list, &src->regions_list);
2058 2069
2059 2070 mutex_lock(&sev_mirror_lock);
@@ -2121,10 +2132,6 @@ static int sev_check_source_vcpus(struct kvm *dst, struct kvm *src)
2121 2132 struct kvm_vcpu *src_vcpu;
2122 2133 unsigned long i;
2123 2134
2124 - if (kvm_is_vcpu_creation_in_progress(src) ||
2125 - kvm_is_vcpu_creation_in_progress(dst))
2126 - return -EBUSY;
2127 -
2128 2135 if (!sev_es_guest(src))
2129 2136 return 0;
2130 2137
@@ -2198,10 +2205,9 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
2198 2205 * does not, i.e. KVM could skip flushes if memory is reclaimed from
2199 2206 * the old VM but not the new VM.
2200 2207 */
2201 - if (!zalloc_cpumask_var(&dst_sev->have_run_cpus, GFP_KERNEL_ACCOUNT)) {
2202 - ret = -ENOMEM;
2208 + ret = sev_alloc_have_run_cpus(dst_sev);
2209 + if (ret)
2203 2210 goto out_source_vcpu;
2204 - }
2205 2211
2206 2212 sev_migrate_from(kvm, source_kvm);
2207 2213 kvm_vm_dead(source_kvm);
@@ -2520,9 +2526,6 @@ static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
2520 2526 unsigned long i;
2521 2527 int ret;
2522 2528
2523 - if (kvm_is_vcpu_creation_in_progress(kvm))
2524 - return -EBUSY;
2525 -
2526 2529 ret = kvm_lock_all_vcpus(kvm);
2527 2530 if (ret)
2528 2531 return ret;
@@ -2898,10 +2901,9 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
2898 2901 }
2899 2902
2900 2903 mirror_sev = to_kvm_sev_info(kvm);
2901 - if (!zalloc_cpumask_var(&mirror_sev->have_run_cpus, GFP_KERNEL_ACCOUNT)) {
2902 - ret = -ENOMEM;
2904 + ret = sev_alloc_have_run_cpus(mirror_sev);
2905 + if (ret)
2903 2906 goto e_unlock;
2904 - }
2905 2907
2906 2908 /*
2907 2909 * The mirror kvm holds an enc_context_owner ref so its asid can't
@@ -2994,7 +2996,7 @@ void sev_vm_destroy(struct kvm *kvm)
2994 2996 * Free the mask even if the VM is not *currently* an SEV VM, as it may
2995 2997 * have been an SEV VM prior to intra-host migration.
2996 2998 */
2997 - free_cpumask_var(sev->have_run_cpus);
2999 + sev_free_have_run_cpus(sev);
2998 3000
2999 3001 if (!sev_guest(kvm))
3000 3002 return;
@@ -3630,7 +3632,6 @@ int pre_sev_run(struct vcpu_svm *svm, int cpu)
3630 3632
3631 3633 sd->sev_vmcbs[asid] = svm->vmcb;
3632 3634 svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
3633 - vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
3634 3635 return 0;
3635 3636 }
3636 3637
modified arch/x86/kvm/svm/svm.c
@@ -673,16 +673,7 @@ static void clr_dr_intercepts(struct vcpu_svm *svm)
673 673
674 674 static bool msr_write_intercepted(struct vcpu_svm *svm, u32 msr)
675 675 {
676 - /*
677 - * For non-nested case:
678 - * If the L01 MSR bitmap does not intercept the MSR, then we need to
679 - * save it.
680 - *
681 - * For nested case:
682 - * If the L02 MSR bitmap does not intercept the MSR, then we need to
683 - * save it.
684 - */
685 - void *msrpm = is_guest_mode(&svm->vcpu) ? svm->nested.msrpm : svm->msrpm;
676 + void *msrpm = __va(__sme_clr(svm->vmcb->control.msrpm_base_pa));
686 677
687 678 return svm_test_msr_bitmap_write(msrpm, msr);
688 679 }
@@ -1902,8 +1893,7 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)
1902 1893 if (sd->next_asid > sd->max_asid) {
1903 1894 ++sd->asid_generation;
1904 1895 sd->next_asid = sd->min_asid;
1905 - svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
1906 - vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
1896 + sd->flush_all_asids = true;
1907 1897 }
1908 1898
1909 1899 svm->current_vmcb->asid_generation = sd->asid_generation;
@@ -4528,6 +4518,9 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
4528 4518 svm->vmcb->control.asid = svm->asid;
4529 4519 vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
4530 4520 }
4521 + if (this_cpu_ptr(&svm_data)->flush_all_asids)
4522 + svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
4523 +
4531 4524 svm->vmcb->save.cr2 = vcpu->arch.cr2;
4532 4525
4533 4526 if (guest_cpu_cap_has(vcpu, X86_FEATURE_ERAPS) &&
@@ -4618,16 +4611,23 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
4618 4611 vcpu->arch.nested_run_pending = 0;
4619 4612 }
4620 4613
4621 - svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
4614 + if (!svm_is_vmrun_failure(svm->vmcb->control.exit_code)) {
4615 + this_cpu_ptr(&svm_data)->flush_all_asids = false;
4616 + svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
4622 4617
4623 - /*
4624 - * Unconditionally mask off the CLEAR_RAP bit, the AND is just as cheap
4625 - * as the TEST+Jcc to avoid it.
4626 - */
4627 - if (cpu_feature_enabled(X86_FEATURE_ERAPS))
4628 - svm->vmcb->control.erap_ctl &= ~ERAP_CONTROL_CLEAR_RAP;
4618 + /*
4619 + * Unconditionally mask off the CLEAR_RAP bit, the AND is just
4620 + * as cheap as the TEST+Jcc to avoid it.
4621 + */
4622 + if (cpu_feature_enabled(X86_FEATURE_ERAPS))
4623 + svm->vmcb->control.erap_ctl &= ~ERAP_CONTROL_CLEAR_RAP;
4629 4624
4630 - vmcb_mark_all_clean(svm->vmcb);
4625 + vmcb_mark_all_clean(svm->vmcb);
4626 +
4627 + if (!msr_write_intercepted(svm, MSR_AMD64_PERF_CNTR_GLOBAL_CTL))
4628 + rdmsrq(MSR_AMD64_PERF_CNTR_GLOBAL_CTL,
4629 + vcpu_to_pmu(vcpu)->global_ctrl);
4630 + }
4631 4631
4632 4632 /* if exit due to PF check for async PF */
4633 4633 if (svm->vmcb->control.exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR)
@@ -4636,9 +4636,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
4636 4636
4637 4637 kvm_clear_available_registers(vcpu, SVM_REGS_LAZY_LOAD_SET);
4638 4638
4639 - if (!msr_write_intercepted(svm, MSR_AMD64_PERF_CNTR_GLOBAL_CTL))
4640 - rdmsrq(MSR_AMD64_PERF_CNTR_GLOBAL_CTL, vcpu_to_pmu(vcpu)->global_ctrl);
4641 -
4642 4639 trace_kvm_exit(vcpu, KVM_ISA_SVM);
4643 4640
4644 4641 svm_complete_interrupts(vcpu);
modified arch/x86/kvm/svm/svm.h
@@ -376,6 +376,7 @@ struct svm_cpu_data {
376 376 u32 next_asid;
377 377 u32 min_asid;
378 378
379 + bool flush_all_asids;
379 380 bool bp_spec_reduce_set;
380 381
381 382 struct vmcb *save_area;
modified arch/x86/kvm/vmx/nested.c
@@ -1754,6 +1754,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)
1754 1754 static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields)
1755 1755 {
1756 1756 #ifdef CONFIG_KVM_HYPERV
1757 + const u64 runtime_controls = HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1 |
1758 + HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 |
1759 + HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC;
1757 1760 struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12;
1758 1761 struct hv_enlightened_vmcs *evmcs = nested_vmx_evmcs(vmx);
1759 1762 struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(&vmx->vcpu);
@@ -1762,6 +1765,9 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields
1762 1765 vmcs12->tpr_threshold = evmcs->tpr_threshold;
1763 1766 vmcs12->guest_rip = evmcs->guest_rip;
1764 1767
1768 + if ((hv_clean_fields & runtime_controls) != runtime_controls)
1769 + vmx->nested.force_msr_bitmap_recalc = true;
1770 +
1765 1771 if (unlikely(!(hv_clean_fields &
1766 1772 HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL))) {
1767 1773 hv_vcpu->nested.pa_page_gpa = evmcs->partition_assist_page;
modified arch/x86/kvm/vmx/tdx.c
@@ -2728,11 +2728,6 @@ static tdx_vm_state_guard_t tdx_acquire_vm_state_locks(struct kvm *kvm)
2728 2728
2729 2729 mutex_lock(&kvm->lock);
2730 2730
2731 - if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus)) {
2732 - r = -EBUSY;
2733 - goto out_err;
2734 - }
2735 -
2736 2731 r = kvm_lock_all_vcpus(kvm);
2737 2732 if (r)
2738 2733 goto out_err;
modified arch/x86/mm/pgtable.c
@@ -705,47 +705,37 @@ int pmd_clear_huge(pmd_t *pmd)
705 705 }
706 706
707 707 #ifdef CONFIG_X86_64
708 - /**
709 - * pud_free_pmd_page - Clear PUD entry and free PMD page
710 - * @pud: Pointer to a PUD
711 - * @addr: Virtual address associated with PUD
712 - *
713 - * Context: The PUD range has been unmapped and TLB purged.
714 - * Return: 1 if clearing the entry succeeded. 0 otherwise.
715 - *
716 - * NOTE: Callers must allow a single page allocation.
708 + /*
709 + * Given a PUD poitner, detach and free the pointed-to
710 + * PMD page and any PTE page children. The entire range
711 + * under the PUD must not have any valid translations
712 + * and the TLB must have already been flushed.
717 713 */
718 714 int pud_free_pmd_page(pud_t *pud, unsigned long addr)
719 715 {
720 - pmd_t *pmd, *pmd_sv;
721 716 struct ptdesc *pt;
717 + pmd_t *pmd;
722 718 int i;
723 719
724 720 pmd = pud_pgtable(*pud);
725 - pmd_sv = (pmd_t *)__get_free_page(GFP_KERNEL);
726 - if (!pmd_sv)
727 - return 0;
728 -
729 - for (i = 0; i < PTRS_PER_PMD; i++) {
730 - pmd_sv[i] = pmd[i];
731 - if (!pmd_none(pmd[i]))
732 - pmd_clear(&pmd[i]);
733 - }
734 721
722 + /* Detach the PMD page: */
735 723 pud_clear(pud);
736 724
737 - /* INVLPG to clear all paging-structure caches */
725 + /*
726 + * PMD and all its descendents are unreachable
727 + * via normal page walks. Make them unreachable
728 + * in cached mid-level walks too:
729 + */
738 730 flush_tlb_kernel_range(addr, addr + PAGE_SIZE-1);
739 731
740 732 for (i = 0; i < PTRS_PER_PMD; i++) {
741 - if (!pmd_none(pmd_sv[i])) {
742 - pt = page_ptdesc(pmd_page(pmd_sv[i]));
733 + if (!pmd_none(pmd[i])) {
734 + pt = page_ptdesc(pmd_page(pmd[i]));
743 735 pagetable_dtor_free(pt);
744 736 }
745 737 }
746 738
747 - free_page((unsigned long)pmd_sv);
748 -
749 739 pmd_free(&init_mm, pmd);
750 740
751 741 return 1;
modified arch/x86/net/bpf_jit_comp.c
@@ -3217,16 +3217,21 @@ static void restore_regs(const struct btf_func_model *m, u8 **prog,
3217 3217 }
3218 3218
3219 3219 static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
3220 + struct bpf_tramp_image *im,
3220 3221 struct bpf_tramp_node *node, int stack_size,
3221 3222 int run_ctx_off, bool save_ret,
3222 3223 void *image, void *rw_image)
3223 3224 {
3224 3225 u8 *prog = *pprog;
3225 - u8 *jmp_insn;
3226 + u8 *jmp_insn, *skip;
3226 3227 int ctx_cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
3227 3228 struct bpf_prog *p = node->link->prog;
3228 3229 u64 cookie = node->cookie;
3229 3230
3231 + /* nop, patched to skip this prog when it is detached */
3232 + skip = image + (prog - (u8 *)rw_image);
3233 + emit_nops(&prog, X86_PATCH_SIZE);
3234 +
3230 3235 /* mov rdi, cookie */
3231 3236 emit_mov_imm64(&prog, BPF_REG_1, (long) cookie >> 32, (u32) (long) cookie);
3232 3237
@@ -3301,6 +3306,8 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,
3301 3306 if (emit_rsb_call(&prog, bpf_trampoline_exit(p), image + (prog - (u8 *)rw_image)))
3302 3307 return -EINVAL;
3303 3308
3309 + bpf_tramp_image_add_skip(im, p, skip, image + (prog - (u8 *)rw_image));
3310 +
3304 3311 *pprog = prog;
3305 3312 return 0;
3306 3313 }
@@ -3332,6 +3339,7 @@ static int emit_cond_near_jump(u8 **pprog, void *func, void *ip, u8 jmp_cond)
3332 3339 }
3333 3340
3334 3341 static int invoke_bpf(const struct btf_func_model *m, u8 **pprog,
3342 + struct bpf_tramp_image *im,
3335 3343 struct bpf_tramp_nodes *tl, int stack_size,
3336 3344 int run_ctx_off, int func_meta_off, bool save_ret,
3337 3345 void *image, void *rw_image, u64 func_meta,
@@ -3346,7 +3354,7 @@ static int invoke_bpf(const struct btf_func_model *m, u8 **pprog,
3346 3354 func_meta | (cur_cookie << BPF_TRAMP_COOKIE_INDEX_SHIFT));
3347 3355 cur_cookie--;
3348 3356 }
3349 - if (invoke_bpf_prog(m, &prog, tl->nodes[i], stack_size,
3357 + if (invoke_bpf_prog(m, &prog, im, tl->nodes[i], stack_size,
3350 3358 run_ctx_off, save_ret, image, rw_image))
3351 3359 return -EINVAL;
3352 3360 }
@@ -3355,6 +3363,7 @@ static int invoke_bpf(const struct btf_func_model *m, u8 **pprog,
3355 3363 }
3356 3364
3357 3365 static int invoke_bpf_mod_ret(const struct btf_func_model *m, u8 **pprog,
3366 + struct bpf_tramp_image *im,
3358 3367 struct bpf_tramp_nodes *tl, int stack_size,
3359 3368 int run_ctx_off, u8 **branches,
3360 3369 void *image, void *rw_image)
@@ -3368,7 +3377,7 @@ static int invoke_bpf_mod_ret(const struct btf_func_model *m, u8 **pprog,
3368 3377 emit_mov_imm32(&prog, false, BPF_REG_0, 0);
3369 3378 emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_0, -8);
3370 3379 for (i = 0; i < tl->nr_nodes; i++) {
3371 - if (invoke_bpf_prog(m, &prog, tl->nodes[i], stack_size, run_ctx_off, true,
3380 + if (invoke_bpf_prog(m, &prog, im, tl->nodes[i], stack_size, run_ctx_off, true,
3372 3381 image, rw_image))
3373 3382 return -EINVAL;
3374 3383
@@ -3640,7 +3649,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
3640 3649 }
3641 3650
3642 3651 if (fentry->nr_nodes) {
3643 - if (invoke_bpf(m, &prog, fentry, regs_off, run_ctx_off, func_meta_off,
3652 + if (invoke_bpf(m, &prog, im, fentry, regs_off, run_ctx_off, func_meta_off,
3644 3653 flags & BPF_TRAMP_F_RET_FENTRY_RET, image, rw_image,
3645 3654 func_meta, cookie_off))
3646 3655 return -EINVAL;
@@ -3652,7 +3661,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
3652 3661 if (!branches)
3653 3662 return -ENOMEM;
3654 3663
3655 - if (invoke_bpf_mod_ret(m, &prog, fmod_ret, regs_off,
3664 + if (invoke_bpf_mod_ret(m, &prog, im, fmod_ret, regs_off,
3656 3665 run_ctx_off, branches, image, rw_image)) {
3657 3666 ret = -EINVAL;
3658 3667 goto cleanup;
@@ -3682,8 +3691,6 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
3682 3691 }
3683 3692 /* remember return value in a stack for bpf prog to access */
3684 3693 emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_0, -8);
3685 - im->ip_after_call = image + (prog - (u8 *)rw_image);
3686 - emit_nops(&prog, X86_PATCH_SIZE);
3687 3694 }
3688 3695
3689 3696 if (fmod_ret->nr_nodes) {
@@ -3708,7 +3715,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
3708 3715 emit_store_stack_imm64(&prog, BPF_REG_0, -func_meta_off, func_meta);
3709 3716
3710 3717 if (fexit->nr_nodes) {
3711 - if (invoke_bpf(m, &prog, fexit, regs_off, run_ctx_off, func_meta_off,
3718 + if (invoke_bpf(m, &prog, im, fexit, regs_off, run_ctx_off, func_meta_off,
3712 3719 false, image, rw_image, func_meta, cookie_off)) {
3713 3720 ret = -EINVAL;
3714 3721 goto cleanup;
@@ -3723,7 +3730,6 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
3723 3730 * restored to R0.
3724 3731 */
3725 3732 if (flags & BPF_TRAMP_F_CALL_ORIG) {
3726 - im->ip_epilogue = image + (prog - (u8 *)rw_image);
3727 3733 /* arg1: mov rdi, im */
3728 3734 emit_mov_imm64(&prog, BPF_REG_1, (long) im >> 32, (u32) (long) im);
3729 3735 if (emit_rsb_call(&prog, __bpf_tramp_exit, image + (prog - (u8 *)rw_image))) {
@@ -3811,7 +3817,7 @@ out:
3811 3817 int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
3812 3818 struct bpf_tramp_nodes *tnodes, void *func_addr)
3813 3819 {
3814 - struct bpf_tramp_image im;
3820 + struct bpf_tramp_image im = {};
3815 3821 void *image;
3816 3822 int ret;
3817 3823
modified arch/x86/um/asm/ptrace.h
@@ -13,9 +13,7 @@ enum {
13 13 };
14 14
15 15 #include <linux/compiler.h>
16 - #ifndef CONFIG_X86_32
17 - #define __FRAME_OFFSETS /* Needed to get the R* macros */
18 - #endif
16 + #define __FRAME_OFFSETS /* Needed to get the register macros */
19 17 #include <asm/ptrace-generic.h>
20 18
21 19 #define user_mode(r) UPT_IS_USER(&(r)->regs)
modified arch/x86/um/ptrace_32.c
@@ -7,6 +7,7 @@
7 7 #include <linux/sched.h>
8 8 #include <linux/uaccess.h>
9 9 #include <linux/regset.h>
10 + #define __FRAME_OFFSETS
10 11 #include <asm/ptrace-abi.h>
11 12 #include <registers.h>
12 13 #include <skas.h>
modified block/blk-cgroup.c
@@ -2091,6 +2091,7 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
2091 2091 struct request_queue *q = bio->bi_bdev->bd_queue;
2092 2092 struct blkcg *blkcg = css_to_blkcg(css);
2093 2093 struct blkcg_gq *blkg;
2094 + unsigned long flags;
2094 2095
2095 2096 rcu_read_lock();
2096 2097 blkg = blkg_lookup(blkcg, q);
@@ -2105,11 +2106,11 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
2105 2106 * Fast path failed, we're probably issuing IO in this cgroup the first
2106 2107 * time, hold lock to create new blkg.
2107 2108 */
2108 - spin_lock_irq(&q->queue_lock);
2109 + spin_lock_irqsave(&q->queue_lock, flags);
2109 2110 blkg = blkg_lookup_create(blkcg, bio->bi_bdev->bd_disk);
2110 2111 if (blkg)
2111 2112 blkg = blkg_lookup_tryget(blkg);
2112 - spin_unlock_irq(&q->queue_lock);
2113 + spin_unlock_irqrestore(&q->queue_lock, flags);
2113 2114
2114 2115 return blkg;
2115 2116 }
modified block/blk-mq.c
@@ -447,16 +447,6 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
447 447 WRITE_ONCE(rq->deadline, 0);
448 448 req_ref_set(rq, 1);
449 449
450 - if (rq->rq_flags & RQF_USE_SCHED) {
451 - struct elevator_queue *e = data->q->elevator;
452 -
453 - INIT_HLIST_NODE(&rq->hash);
454 - RB_CLEAR_NODE(&rq->rb_node);
455 -
456 - if (e->type->ops.prepare_request)
457 - e->type->ops.prepare_request(rq);
458 - }
459 -
460 450 return rq;
461 451 }
462 452
@@ -498,6 +488,12 @@ __blk_mq_alloc_requests_batch(struct blk_mq_alloc_data *data)
498 488 return rq_list_pop(data->cached_rqs);
499 489 }
500 490
491 + static bool blk_op_bypass_sched(blk_opf_t opf)
492 + {
493 + return (opf & REQ_OP_MASK) == REQ_OP_FLUSH ||
494 + blk_op_is_passthrough(opf);
495 + }
496 +
501 497 static void blk_mq_limit_depth(struct blk_mq_alloc_data *data)
502 498 {
503 499 struct elevator_mq_ops *ops;
@@ -518,12 +514,10 @@ static void blk_mq_limit_depth(struct blk_mq_alloc_data *data)
518 514 * Flush/passthrough requests are special and go directly to the
519 515 * dispatch list, they are not subject to the async_depth limit.
520 516 */
521 - if ((data->cmd_flags & REQ_OP_MASK) == REQ_OP_FLUSH ||
522 - blk_op_is_passthrough(data->cmd_flags))
517 + if (blk_op_bypass_sched(data->cmd_flags))
523 518 return;
524 519
525 520 WARN_ON_ONCE(data->flags & BLK_MQ_REQ_RESERVED);
526 - data->rq_flags |= RQF_USE_SCHED;
527 521
528 522 /*
529 523 * By default, sync requests have no limit, and async requests are
@@ -534,6 +528,29 @@ static void blk_mq_limit_depth(struct blk_mq_alloc_data *data)
534 528 ops->limit_depth(data->cmd_flags, data);
535 529 }
536 530
531 + /*
532 + * Finish initializing a request once it has been claimed for an operation.
533 + * Cached requests are allocated before that operation is known.
534 + */
535 + static void blk_mq_rq_late_init(struct request *rq, u64 alloc_time_ns)
536 + {
537 + struct elevator_queue *e;
538 +
539 + blk_mq_rq_time_init(rq, alloc_time_ns);
540 +
541 + if (!(rq->rq_flags & RQF_SCHED_TAGS) || (rq->rq_flags & RQF_RESV) ||
542 + blk_op_bypass_sched(rq->cmd_flags))
543 + return;
544 +
545 + rq->rq_flags |= RQF_USE_SCHED;
546 + INIT_HLIST_NODE(&rq->hash);
547 + RB_CLEAR_NODE(&rq->rb_node);
548 +
549 + e = rq->q->elevator;
550 + if (e->type->ops.prepare_request)
551 + e->type->ops.prepare_request(rq);
552 + }
553 +
537 554 static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
538 555 {
539 556 struct request_queue *q = data->q;
@@ -562,7 +579,7 @@ retry:
562 579 if (data->nr_tags > 1) {
563 580 rq = __blk_mq_alloc_requests_batch(data);
564 581 if (rq) {
565 - blk_mq_rq_time_init(rq, alloc_time_ns);
582 + blk_mq_rq_late_init(rq, alloc_time_ns);
566 583 return rq;
567 584 }
568 585 data->nr_tags = 1;
@@ -590,7 +607,7 @@ retry:
590 607 if (!(data->rq_flags & RQF_SCHED_TAGS))
591 608 blk_mq_inc_active_requests(data->hctx);
592 609 rq = blk_mq_rq_ctx_init(data, blk_mq_tags_from_data(data), tag);
593 - blk_mq_rq_time_init(rq, alloc_time_ns);
610 + blk_mq_rq_late_init(rq, alloc_time_ns);
594 611 return rq;
595 612 }
596 613
@@ -637,8 +654,6 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q,
637 654 if (plug->nr_ios == 1)
638 655 return NULL;
639 656 rq = blk_mq_rq_cache_fill(q, plug, opf, flags);
640 - if (!rq)
641 - return NULL;
642 657 } else {
643 658 rq = rq_list_peek(&plug->cached_rqs);
644 659 if (!rq || rq->q != q)
@@ -646,15 +661,13 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q,
646 661
647 662 if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type)
648 663 return NULL;
649 - if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
650 - return NULL;
651 664
652 665 rq_list_pop(&plug->cached_rqs);
653 - blk_mq_rq_time_init(rq, blk_time_get_ns());
666 + rq->cmd_flags = opf;
667 + INIT_LIST_HEAD(&rq->queuelist);
668 + blk_mq_rq_late_init(rq, blk_time_get_ns());
654 669 }
655 670
656 - rq->cmd_flags = opf;
657 - INIT_LIST_HEAD(&rq->queuelist);
658 671 return rq;
659 672 }
660 673
@@ -766,7 +779,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
766 779 if (!(data.rq_flags & RQF_SCHED_TAGS))
767 780 blk_mq_inc_active_requests(data.hctx);
768 781 rq = blk_mq_rq_ctx_init(&data, blk_mq_tags_from_data(&data), tag);
769 - blk_mq_rq_time_init(rq, alloc_time_ns);
782 + blk_mq_rq_late_init(rq, alloc_time_ns);
770 783 rq->__data_len = 0;
771 784 rq->phys_gap_bit = 0;
772 785 rq->__sector = (sector_t) -1;
@@ -3060,8 +3073,6 @@ static struct request *blk_mq_get_cached_request(struct blk_plug *plug,
3060 3073 if (type != rq->mq_hctx->type &&
3061 3074 (type != HCTX_TYPE_READ || rq->mq_hctx->type != HCTX_TYPE_DEFAULT))
3062 3075 return NULL;
3063 - if (op_is_flush(rq->cmd_flags) != op_is_flush(opf))
3064 - return NULL;
3065 3076 rq_list_pop(&plug->cached_rqs);
3066 3077 return rq;
3067 3078 }
@@ -3163,9 +3174,9 @@ void blk_mq_submit_bio(struct bio *bio)
3163 3174 new_request:
3164 3175 if (rq) {
3165 3176 rq_qos_throttle(rq->q, bio);
3166 - blk_mq_rq_time_init(rq, blk_time_get_ns());
3167 3177 rq->cmd_flags = bio->bi_opf;
3168 3178 INIT_LIST_HEAD(&rq->queuelist);
3179 + blk_mq_rq_late_init(rq, blk_time_get_ns());
3169 3180 } else {
3170 3181 rq = blk_mq_get_new_requests(q, plug, bio);
3171 3182 if (unlikely(!rq)) {
modified block/fops.c
@@ -402,6 +402,11 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
402 402 if (blkdev_dio_invalid(bdev, iocb, iter))
403 403 return -EINVAL;
404 404
405 + /* HIPRI needs private as bio; HAS_METADATA keeps it as uio_meta */
406 + if ((iocb->ki_flags & IOCB_HIPRI) &&
407 + (iocb->ki_flags & IOCB_HAS_METADATA))
408 + return -EOPNOTSUPP;
409 +
405 410 if (iov_iter_rw(iter) == WRITE) {
406 411 u16 max_write_streams = bdev_max_write_streams(bdev);
407 412
modified block/mq-deadline.c
@@ -685,7 +685,7 @@ static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
685 685 blk_mq_free_requests(&free);
686 686 }
687 687
688 - /* Callback from inside blk_mq_rq_ctx_init(). */
688 + /* Callback from inside blk_mq_rq_late_init(). */
689 689 static void dd_prepare_request(struct request *rq)
690 690 {
691 691 rq->elv.priv[0] = NULL;
modified crypto/aes.c
@@ -637,7 +637,18 @@ static struct skcipher_alg skcipher_algs[] = {
637 637 .decrypt = crypto_aes_cbc_decrypt,
638 638 },
639 639 #endif
640 - #if IS_ENABLED(CONFIG_CRYPTO_CTS)
640 + /*
641 + * Don't register library-based "cts(cbc(aes))" on architectures where
642 + * it might block a "better" implementation from being instantiated via
643 + * the "cts" template. These exclusions are temporary and will go away
644 + * as the arch-optimized AES code is migrated into the library.
645 + */
646 + #if IS_ENABLED(CONFIG_CRYPTO_CTS) && \
647 + !(IS_ENABLED(CONFIG_ARM) || \
648 + IS_ENABLED(CONFIG_ARM64) || \
649 + IS_ENABLED(CONFIG_PPC) || \
650 + IS_ENABLED(CONFIG_S390) || \
651 + IS_ENABLED(CONFIG_SPARC))
641 652 {
642 653 .base.cra_name = "cts(cbc(aes))",
643 654 .base.cra_driver_name = "cts-cbc-aes-lib",
@@ -687,7 +698,13 @@ static struct skcipher_alg skcipher_algs[] = {
687 698 .decrypt = crypto_aes_xctr_crypt,
688 699 },
689 700 #endif
690 - #if IS_ENABLED(CONFIG_CRYPTO_XTS)
701 + /*
702 + * Don't register library-based "xts(aes)" on architectures where it
703 + * might block a "better" implementation from being instantiated via the
704 + * "xts" template. This exclusion is temporary and will go away when
705 + * the library AES-XTS is optimized for SPARC.
706 + */
707 + #if IS_ENABLED(CONFIG_CRYPTO_XTS) && !IS_ENABLED(CONFIG_SPARC)
691 708 {
692 709 .base.cra_name = "xts(aes)",
693 710 .base.cra_driver_name = "xts-aes-lib",
@@ -980,7 +997,20 @@ static __maybe_unused int crypto_aes_ccm_decrypt(struct aead_request *req)
980 997 }
981 998
982 999 static struct aead_alg aead_algs[] = {
983 - #if IS_ENABLED(CONFIG_CRYPTO_GCM)
1000 + /*
1001 + * Don't register library-based "gcm(aes)" and "rfc4106(gcm(aes))" on
1002 + * architectures where they might block a "better" implementation from
1003 + * being instantiated via the "gcm" and "rfc4106" templates. These
1004 + * exclusions are temporary and will go away as the arch-optimized AES
1005 + * code is migrated into the library.
1006 + */
1007 + #if IS_ENABLED(CONFIG_CRYPTO_GCM) && \
1008 + !(IS_ENABLED(CONFIG_ARM) || \
1009 + IS_ENABLED(CONFIG_ARM64) || \
1010 + IS_ENABLED(CONFIG_PPC) || \
1011 + IS_ENABLED(CONFIG_RISCV) || \
1012 + IS_ENABLED(CONFIG_S390) || \
1013 + IS_ENABLED(CONFIG_SPARC))
984 1014 {
985 1015 .base.cra_name = "gcm(aes)",
986 1016 .base.cra_driver_name = "gcm-aes-lib",
@@ -1012,7 +1042,20 @@ static struct aead_alg aead_algs[] = {
1012 1042 .chunksize = AES_BLOCK_SIZE,
1013 1043 },
1014 1044 #endif /* CONFIG_CRYPTO_GCM */
1015 - #if IS_ENABLED(CONFIG_CRYPTO_CCM)
1045 + /*
1046 + * Don't register library-based "ccm(aes)" on architectures where it
1047 + * might block a "better" implementation from being instantiated via the
1048 + * "ccm" template. These exclusions are temporary and will go away as
1049 + * the arch-optimized AES code is migrated into the library.
1050 + */
1051 + #if IS_ENABLED(CONFIG_CRYPTO_CCM) && \
1052 + !(IS_ENABLED(CONFIG_ARM) || \
1053 + IS_ENABLED(CONFIG_ARM64) || \
1054 + IS_ENABLED(CONFIG_PPC) || \
1055 + IS_ENABLED(CONFIG_RISCV) || \
1056 + IS_ENABLED(CONFIG_S390) || \
1057 + IS_ENABLED(CONFIG_SPARC) || \
1058 + IS_ENABLED(CONFIG_X86))
1016 1059 {
1017 1060 .base.cra_name = "ccm(aes)",
1018 1061 .base.cra_driver_name = "ccm-aes-lib",
modified drivers/android/binder.c
@@ -2930,8 +2930,9 @@ static int binder_proc_transaction(struct binder_transaction *t,
2930 2930 t_outdated->buffer = NULL;
2931 2931 buffer->transaction = NULL;
2932 2932 trace_binder_transaction_update_buffer_release(buffer);
2933 - binder_release_entire_buffer(proc, NULL, buffer, false);
2933 + binder_release_entire_buffer(proc, NULL, buffer, true);
2934 2934 binder_alloc_free_buf(&proc->alloc, buffer);
2935 + binder_free_txn_fixups(t_outdated);
2935 2936 kfree(t_outdated);
2936 2937 binder_stats_deleted(BINDER_STAT_TRANSACTION);
2937 2938 }
modified drivers/android/binder/node.rs
@@ -51,9 +51,9 @@ pub(crate) struct CouldNotDeliverCriticalIncrement;
51 51 /// about to drop the weak reference, then the strong increment could be processed after the
52 52 /// other thread has already exited, which would be too late.
53 53 ///
54 - /// Note that trying to create a `ListArc` to the node can succeed even if `has_normal_push` is
54 + /// Note that trying to create a `ListArc` to the node can succeed even if `has_pushed_node` is
55 55 /// set. This is because another thread might just have popped the node from a todo list, but not
56 - /// yet called `do_work`. However, if `has_normal_push` is false, then creating a `ListArc` should
56 + /// yet called `do_work`. However, if `has_pushed_node` is false, then creating a `ListArc` should
57 57 /// always succeed.
58 58 ///
59 59 /// Like the other fields in `NodeInner`, the delivery state is protected by the process lock.
@@ -738,7 +738,21 @@ impl DeliverToRead for Node {
738 738 self.do_work_locked(writer, owner_inner)
739 739 }
740 740
741 - fn cancel(self: DArc<Self>) {}
741 + fn cancel(self: DArc<Self>) {
742 + let _drop_outside_lock;
743 + let mut owner_inner = self.owner.inner.lock();
744 +
745 + // We only do something on BINDER_THREAD_EXIT, not process exit.
746 + if owner_inner.is_dead {
747 + return;
748 + }
749 +
750 + // If BINDER_THREAD_EXIT is invoked on a thread with a pending node refcount update, we
751 + // should move ourselves to ensure the refcount update is still delivered.
752 + if let Some(node) = ListArc::try_from_arc_borrow(self.as_arc_borrow()) {
753 + _drop_outside_lock = owner_inner.push_work(&self.owner, node);
754 + }
755 + }
742 756
743 757 fn should_sync_wakeup(&self) -> bool {
744 758 false
modified drivers/android/binder/node/wrapper.rs
@@ -57,7 +57,39 @@ impl DeliverToRead for NodeWrapper {
57 57 node.do_work_locked(writer, owner_inner)
58 58 }
59 59
60 - fn cancel(self: DArc<Self>) {}
60 + fn cancel(self: DArc<Self>) {
61 + let _drop_outside_lock;
62 + let node = &self.node;
63 + let mut owner_inner = node.owner.inner.lock();
64 +
65 + // We only do something on BINDER_THREAD_EXIT, not process exit.
66 + if owner_inner.is_dead {
67 + return;
68 + }
69 +
70 + // We transfer the responsibility of the node refcount update to the scheduled Node because
71 + // NodeWrapper has no way to re-create the ListArc.
72 + let inner = node.inner.access_mut(&mut owner_inner);
73 +
74 + let ds = &mut inner.delivery_state;
75 + assert!(ds.has_pushed_wrapper);
76 + assert!(ds.has_strong_zero2one);
77 + ds.has_pushed_wrapper = false;
78 +
79 + // We are changing the state to one where the Node is the strong zero2one update instead of
80 + // the wrapper.
81 + ds.has_weak_zero2one = false;
82 +
83 + if !ds.has_pushed_node {
84 + if let Some(node2) = ListArc::try_from_arc_borrow(node.as_arc_borrow()) {
85 + ds.has_pushed_node = true;
86 + _drop_outside_lock = owner_inner.push_work(&node.owner, node2);
87 + } else {
88 + // This can't actually happen.
89 + ds.has_strong_zero2one = false;
90 + }
91 + }
92 + }
61 93
62 94 fn should_sync_wakeup(&self) -> bool {
63 95 false
modified drivers/android/binder/rust_binderfs.c
@@ -72,6 +72,7 @@ struct binder_features {
72 72 bool oneway_spam_detection;
73 73 bool extended_error;
74 74 bool freeze_notification;
75 + bool transaction_report;
75 76 };
76 77
77 78 static const struct constant_table binderfs_param_stats[] = {
@@ -89,6 +90,7 @@ static struct binder_features binder_features = {
89 90 .oneway_spam_detection = true,
90 91 .extended_error = true,
91 92 .freeze_notification = true,
93 + .transaction_report = true,
92 94 };
93 95
94 96 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
@@ -566,6 +568,12 @@ static int init_binder_features(struct super_block *sb)
566 568 if (IS_ERR(dentry))
567 569 return PTR_ERR(dentry);
568 570
571 + dentry = rust_binderfs_create_file(dir, "transaction_report",
572 + &binder_features_fops,
573 + &binder_features.transaction_report);
574 + if (IS_ERR(dentry))
575 + return PTR_ERR(dentry);
576 +
569 577 return 0;
570 578 }
571 579
modified drivers/android/binder/thread.rs
@@ -686,6 +686,12 @@ impl Thread {
686 686 self.inner.lock().push_return_work(reply);
687 687 }
688 688
689 + pub(crate) fn pop_work_even_if_deferred(&self) -> Option<DLArc<dyn DeliverToRead>> {
690 + let mut thread_inner = self.inner.lock();
691 + thread_inner.process_work_list = true;
692 + thread_inner.pop_work()
693 + }
694 +
689 695 fn translate_object(
690 696 &self,
691 697 obj_index: usize,
@@ -1678,7 +1684,7 @@ impl Thread {
1678 1684 self.unwind_transaction_stack();
1679 1685
1680 1686 // Cancel all pending work items.
1681 - while let Ok(Some(work)) = self.get_work_local(false) {
1687 + while let Some(work) = self.pop_work_even_if_deferred() {
1682 1688 work.into_arc().cancel();
1683 1689 }
1684 1690 }
modified drivers/android/binderfs.c
@@ -189,12 +189,11 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
189 189 goto err;
190 190 }
191 191 inode->i_private = device;
192 + binder_add_device(device);
192 193 d_make_persistent(dentry, inode);
193 194 fsnotify_create(root->d_inode, dentry);
194 195 simple_done_creating(dentry);
195 196
196 - binder_add_device(device);
197 -
198 197 return 0;
199 198
200 199 err:
modified drivers/block/drbd/drbd_nl_gen.c
@@ -638,10 +638,6 @@ const struct genl_split_ops drbd_nl_ops[32] = {
638 638 },
639 639 };
640 640
641 - static const struct genl_multicast_group drbd_nl_mcgrps[] = {
642 - [DRBD_NLGRP_EVENTS] = { "events", },
643 - };
644 -
645 641 static int __drbd_cfg_context_from_attrs(struct drbd_cfg_context *s,
646 642 struct nlattr ***ret_nested_attribute_table,
647 643 struct genl_info *info)
modified drivers/block/virtio_blk.c
@@ -743,6 +743,7 @@ static int virtblk_read_zoned_limits(struct virtio_blk *vblk,
743 743 dev_warn(&vdev->dev, "zero write granularity reported\n");
744 744 return -ENODEV;
745 745 }
746 + lim->zone_write_granularity = wg;
746 747 lim->physical_block_size = wg;
747 748 lim->io_min = wg;
748 749
modified drivers/bluetooth/btintel.c
@@ -289,7 +289,8 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code)
289 289 goto unlock;
290 290 }
291 291
292 - bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
292 + bt_dev_err(hdev, "Exception info %.*s", (int)(skb->len - 1),
293 + (char *)(skb->data + 1));
293 294
294 295 kfree_skb(skb);
295 296
@@ -408,8 +409,16 @@ int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name)
408 409 /* DDC file contains one or more DDC structure which has
409 410 * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
410 411 */
411 - while (fw->size > fw_ptr - fw->data) {
412 - u8 cmd_plen = fw_ptr[0] + sizeof(u8);
412 + while (fw->size > (size_t)(fw_ptr - fw->data)) {
413 + size_t remaining = fw->size - (fw_ptr - fw->data);
414 + unsigned int cmd_plen = fw_ptr[0] + 1U;
415 +
416 + if (cmd_plen < 3 || cmd_plen > U8_MAX || cmd_plen > remaining) {
417 + bt_dev_err(hdev, "Malformed DDC record (plen=%u, remaining=%zu)",
418 + cmd_plen, remaining);
419 + release_firmware(fw);
420 + return -EINVAL;
421 + }
413 422
414 423 skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr,
415 424 HCI_INIT_TIMEOUT);
modified drivers/bluetooth/btintel_pcie.c
@@ -1197,7 +1197,7 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
1197 1197 {
1198 1198 int ret;
1199 1199 u8 pkt_type;
1200 - u16 plen;
1200 + u32 plen;
1201 1201 u32 pcie_pkt_type;
1202 1202 void *pdata;
1203 1203 struct hci_dev *hdev = data->hdev;
@@ -2219,6 +2219,16 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,
2219 2219 if (test_bit(BTINTEL_PCIE_RECOVERY_IN_PROGRESS, &data->flags))
2220 2220 return -ENODEV;
2221 2221
2222 + /* Account for the 4-byte PCIe type header prepended before the
2223 + * DMA copy. Written as a subtraction to avoid wrap-around on
2224 + * attacker-controlled skb->len.
2225 + */
2226 + if (skb->len > BTINTEL_PCIE_BUFFER_SIZE - BTINTEL_PCIE_HCI_TYPE_LEN) {
2227 + bt_dev_err(hdev, "Packet too large: %u > %u", skb->len,
2228 + BTINTEL_PCIE_BUFFER_SIZE - BTINTEL_PCIE_HCI_TYPE_LEN);
2229 + return -EMSGSIZE;
2230 + }
2231 +
2222 2232 /* Due to the fw limitation, the type header of the packet should be
2223 2233 * 4 bytes unlike 1 byte for UART. In UART, the firmware can read
2224 2234 * the first byte to get the packet type and redirect the rest of data
modified drivers/char/tpm/tpm-interface.c
@@ -268,7 +268,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
268 268 int err;
269 269 ssize_t len;
270 270
271 - len = tpm_transmit(chip, buf->data, PAGE_SIZE);
271 + len = tpm_transmit(chip, buf->data, buf->capacity);
272 272 if (len < 0)
273 273 return len;
274 274
modified drivers/char/tpm/tpm2-cmd.c
@@ -281,8 +281,10 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
281 281 }
282 282 tpm_buf_append_u16(buf, num_bytes);
283 283 err = tpm_buf_fill_hmac_session(chip, buf);
284 - if (err)
284 + if (err) {
285 + tpm2_end_auth_session(chip);
285 286 return err;
287 + }
286 288
287 289 err = tpm_transmit_cmd(chip, buf,
288 290 offsetof(struct tpm2_get_random_out,
@@ -305,7 +307,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
305 307 out = (struct tpm2_get_random_out *)&buf->data[offset];
306 308 recd = min_t(u32, be16_to_cpu(out->size), num_bytes);
307 309 if (tpm_buf_length(buf) <
308 - TPM_HEADER_SIZE +
310 + offset +
309 311 offsetof(struct tpm2_get_random_out, buffer) +
310 312 recd) {
311 313 tpm2_end_auth_session(chip);
modified drivers/char/tpm/tpm2-sessions.c
@@ -975,6 +975,7 @@ static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
975 975 /* Deduce from the name change TPM interference: */
976 976 dev_err(&chip->dev, "null key integrity check failed\n");
977 977 tpm2_flush_context(chip, tmp_null_key);
978 + rc = -ENODEV;
978 979
979 980 err:
980 981 if (rc) {
modified drivers/clk/qcom/gcc-eliza.c
@@ -3010,6 +3010,8 @@ static const u32 gcc_eliza_critical_cbcrs[] = {
3010 3010 0x26034, /* GCC_CAMERA_XO_CLK */
3011 3011 0x27004, /* GCC_DISP_AHB_CLK */
3012 3012 0x71004, /* GCC_GPU_CFG_AHB_CLK */
3013 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3014 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3013 3015 0x32004, /* GCC_VIDEO_AHB_CLK */
3014 3016 0x32038, /* GCC_VIDEO_XO_CLK */
3015 3017 };
@@ -3043,10 +3045,6 @@ static const struct regmap_config gcc_eliza_regmap_config = {
3043 3045
3044 3046 static void clk_eliza_regs_configure(struct device *dev, struct regmap *regmap)
3045 3047 {
3046 - /* Keep clocks always enabled */
3047 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3048 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3049 -
3050 3048 /* FORCE_MEM_CORE_ON for ufs phy ice core and gcc ufs phy axi clocks */
3051 3049 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3052 3050 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_axi_clk, true);
modified drivers/clk/qcom/gcc-hawi.c
@@ -3692,6 +3692,8 @@ static const u32 gcc_hawi_critical_cbcrs[] = {
3692 3692 0x67084, /* GCC_PCIE_1_RSC_CORE_CLK */
3693 3693 0x43014, /* GCC_PCIE_LINK_XO_CLK */
3694 3694 0x6b088, /* GCC_PCIE_RSC_CORE_CLK */
3695 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3696 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3695 3697 0x32004, /* GCC_VIDEO_AHB_CLK */
3696 3698 0x32028, /* GCC_VIDEO_XO_CLK */
3697 3699 };
@@ -3761,10 +3763,6 @@ static const struct regmap_config gcc_hawi_regmap_config = {
3761 3763
3762 3764 static void clk_hawi_regs_configure(struct device *dev, struct regmap *regmap)
3763 3765 {
3764 - /* Keep clocks always enabled */
3765 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3766 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3767 -
3768 3766 /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */
3769 3767 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3770 3768 }
modified drivers/clk/qcom/gcc-kaanapali.c
@@ -3464,6 +3464,8 @@ static const u32 gcc_kaanapali_critical_cbcrs[] = {
3464 3464 0x9f004, /* GCC_EVA_AHB_CLK */
3465 3465 0x9f024, /* GCC_EVA_XO_CLK */
3466 3466 0x71004, /* GCC_GPU_CFG_AHB_CLK */
3467 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3468 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3467 3469 0x32004, /* GCC_VIDEO_AHB_CLK */
3468 3470 0x32040, /* GCC_VIDEO_XO_CLK */
3469 3471 };
@@ -3478,10 +3480,6 @@ static const struct regmap_config gcc_kaanapali_regmap_config = {
3478 3480
3479 3481 static void clk_kaanapali_regs_configure(struct device *dev, struct regmap *regmap)
3480 3482 {
3481 - /* Keep clocks always enabled */
3482 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3483 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3484 -
3485 3483 /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */
3486 3484 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3487 3485 }
modified drivers/clk/qcom/gpucc-glymur.c
@@ -510,7 +510,7 @@ static struct gdsc gpu_cc_cx_gdsc = {
510 510 .name = "gpu_cc_cx_gdsc",
511 511 },
512 512 .pwrsts = PWRSTS_OFF_ON,
513 - .flags = RETAIN_FF_ENABLE | VOTABLE,
513 + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
514 514 };
515 515
516 516 static struct clk_regmap *gpu_cc_glymur_clocks[] = {
modified drivers/clk/qcom/gpucc-kaanapali.c
@@ -380,7 +380,7 @@ static struct gdsc gpu_cc_cx_gdsc = {
380 380 .name = "gpu_cc_cx_gdsc",
381 381 },
382 382 .pwrsts = PWRSTS_OFF_ON,
383 - .flags = RETAIN_FF_ENABLE | VOTABLE,
383 + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
384 384 };
385 385
386 386 static struct clk_regmap *gpu_cc_kaanapali_clocks[] = {
modified drivers/clk/spacemit/ccu-k3.c
@@ -30,14 +30,87 @@ static const struct ccu_pll_rate_tbl pll2_rate_tbl[] = {
30 30 };
31 31
32 32 static const struct ccu_pll_rate_tbl pll3_rate_tbl[] = {
33 + CCU_PLLA_RATE(1050000000UL, 0x0b2b3000, 0x00000000, 0xa0458080),
34 + CCU_PLLA_RATE(1100000000UL, 0x0b2d3555, 0x00005500, 0xa0458181),
35 + CCU_PLLA_RATE(1150000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0458181),
36 + CCU_PLLA_RATE(1200000000UL, 0x0b320000, 0x00000000, 0xa0458181),
37 + CCU_PLLA_RATE(1250000000UL, 0x0b340555, 0x00005500, 0xa0458181),
38 + CCU_PLLA_RATE(1300000000UL, 0x0b360aaa, 0x0000ab00, 0xa0458282),
39 + CCU_PLLA_RATE(1350000000UL, 0x0b381000, 0x00000000, 0xa0458282),
40 + CCU_PLLA_RATE(1400000000UL, 0x0b3a1555, 0x00005500, 0xa0458282),
41 + CCU_PLLA_RATE(1450000000UL, 0x0b3c1aaa, 0x0000ab00, 0xa0458383),
42 + CCU_PLLA_RATE(1500000000UL, 0x0b3e2000, 0x00000000, 0xa0458383),
43 + CCU_PLLA_RATE(1550000000UL, 0x0b402555, 0x00005500, 0xa0458383),
44 + CCU_PLLA_RATE(1600000000UL, 0x0b422aaa, 0x0000ab00, 0xa0458484),
45 + CCU_PLLA_RATE(1650000000UL, 0x0b443000, 0x00000000, 0xa0458484),
46 + CCU_PLLA_RATE(1700000000UL, 0x0b463555, 0x00005500, 0xa0458484),
47 + CCU_PLLA_RATE(1750000000UL, 0x0b483aaa, 0x0000ab00, 0xa0458585),
48 + CCU_PLLA_RATE(1800000000UL, 0x0b4b0000, 0x00000000, 0xa0458585),
49 + CCU_PLLA_RATE(1850000000UL, 0x0b4d0555, 0x00005500, 0xa0458585),
50 + CCU_PLLA_RATE(1900000000UL, 0x0b4f0aaa, 0x0000ab00, 0xa0458686),
51 + CCU_PLLA_RATE(1950000000UL, 0x0b511000, 0x00000000, 0xa0458686),
52 + CCU_PLLA_RATE(2000000000UL, 0x0b292aaa, 0x0000ab00, 0xa0558686),
53 + CCU_PLLA_RATE(2050000000UL, 0x0b2a2d55, 0x00005500, 0xa0558686),
54 + CCU_PLLA_RATE(2100000000UL, 0x0b2b3000, 0x00000000, 0xa0558787),
55 + CCU_PLLA_RATE(2150000000UL, 0x0b2c32aa, 0x0000ab00, 0xa0558787),
33 56 CCU_PLLA_RATE(2200000000UL, 0x0b2d3555, 0x00005500, 0xa0558787),
57 + CCU_PLLA_RATE(2250000000UL, 0x0b2e3800, 0x00000000, 0xa0558888),
58 + CCU_PLLA_RATE(2300000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0558888),
59 + CCU_PLLA_RATE(2350000000UL, 0x0b303d55, 0x00005500, 0xa0558888),
60 + CCU_PLLA_RATE(2400000000UL, 0x0b320000, 0x00000000, 0xa0558989),
34 61 };
35 62
36 63 static const struct ccu_pll_rate_tbl pll4_rate_tbl[] = {
64 + CCU_PLLA_RATE(1050000000UL, 0x0b2b3000, 0x00000000, 0xa0458080),
65 + CCU_PLLA_RATE(1100000000UL, 0x0b2d3555, 0x00005500, 0xa0458181),
66 + CCU_PLLA_RATE(1150000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0458181),
67 + CCU_PLLA_RATE(1200000000UL, 0x0b320000, 0x00000000, 0xa0458181),
68 + CCU_PLLA_RATE(1250000000UL, 0x0b340555, 0x00005500, 0xa0458181),
69 + CCU_PLLA_RATE(1300000000UL, 0x0b360aaa, 0x0000ab00, 0xa0458282),
70 + CCU_PLLA_RATE(1350000000UL, 0x0b381000, 0x00000000, 0xa0458282),
71 + CCU_PLLA_RATE(1400000000UL, 0x0b3a1555, 0x00005500, 0xa0458282),
72 + CCU_PLLA_RATE(1450000000UL, 0x0b3c1aaa, 0x0000ab00, 0xa0458383),
73 + CCU_PLLA_RATE(1500000000UL, 0x0b3e2000, 0x00000000, 0xa0458383),
74 + CCU_PLLA_RATE(1550000000UL, 0x0b402555, 0x00005500, 0xa0458383),
75 + CCU_PLLA_RATE(1600000000UL, 0x0b422aaa, 0x0000ab00, 0xa0458484),
76 + CCU_PLLA_RATE(1650000000UL, 0x0b443000, 0x00000000, 0xa0458484),
77 + CCU_PLLA_RATE(1700000000UL, 0x0b463555, 0x00005500, 0xa0458484),
78 + CCU_PLLA_RATE(1750000000UL, 0x0b483aaa, 0x0000ab00, 0xa0458585),
79 + CCU_PLLA_RATE(1800000000UL, 0x0b4b0000, 0x00000000, 0xa0458585),
80 + CCU_PLLA_RATE(1850000000UL, 0x0b4d0555, 0x00005500, 0xa0458585),
81 + CCU_PLLA_RATE(1900000000UL, 0x0b4f0aaa, 0x0000ab00, 0xa0458686),
82 + CCU_PLLA_RATE(1950000000UL, 0x0b511000, 0x00000000, 0xa0458686),
83 + CCU_PLLA_RATE(2000000000UL, 0x0b292aaa, 0x0000ab00, 0xa0558686),
84 + CCU_PLLA_RATE(2050000000UL, 0x0b2a2d55, 0x00005500, 0xa0558686),
85 + CCU_PLLA_RATE(2100000000UL, 0x0b2b3000, 0x00000000, 0xa0558787),
86 + CCU_PLLA_RATE(2150000000UL, 0x0b2c32aa, 0x0000ab00, 0xa0558787),
37 87 CCU_PLLA_RATE(2200000000UL, 0x0b2d3555, 0x00005500, 0xa0558787),
88 + CCU_PLLA_RATE(2250000000UL, 0x0b2e3800, 0x00000000, 0xa0558888),
89 + CCU_PLLA_RATE(2300000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0558888),
90 + CCU_PLLA_RATE(2350000000UL, 0x0b303d55, 0x00005500, 0xa0558888),
91 + CCU_PLLA_RATE(2400000000UL, 0x0b320000, 0x00000000, 0xa0558989),
38 92 };
39 93
40 94 static const struct ccu_pll_rate_tbl pll5_rate_tbl[] = {
95 + CCU_PLLA_RATE(1050000000UL, 0x0b2b3000, 0x00000000, 0xa0458080),
96 + CCU_PLLA_RATE(1100000000UL, 0x0b2d3555, 0x00005500, 0xa0458181),
97 + CCU_PLLA_RATE(1150000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0458181),
98 + CCU_PLLA_RATE(1200000000UL, 0x0b320000, 0x00000000, 0xa0458181),
99 + CCU_PLLA_RATE(1250000000UL, 0x0b340555, 0x00005500, 0xa0458181),
100 + CCU_PLLA_RATE(1300000000UL, 0x0b360aaa, 0x0000ab00, 0xa0458282),
101 + CCU_PLLA_RATE(1350000000UL, 0x0b381000, 0x00000000, 0xa0458282),
102 + CCU_PLLA_RATE(1400000000UL, 0x0b3a1555, 0x00005500, 0xa0458282),
103 + CCU_PLLA_RATE(1450000000UL, 0x0b3c1aaa, 0x0000ab00, 0xa0458383),
104 + CCU_PLLA_RATE(1500000000UL, 0x0b3e2000, 0x00000000, 0xa0458383),
105 + CCU_PLLA_RATE(1550000000UL, 0x0b402555, 0x00005500, 0xa0458383),
106 + CCU_PLLA_RATE(1600000000UL, 0x0b422aaa, 0x0000ab00, 0xa0458484),
107 + CCU_PLLA_RATE(1650000000UL, 0x0b443000, 0x00000000, 0xa0458484),
108 + CCU_PLLA_RATE(1700000000UL, 0x0b463555, 0x00005500, 0xa0458484),
109 + CCU_PLLA_RATE(1750000000UL, 0x0b483aaa, 0x0000ab00, 0xa0458585),
110 + CCU_PLLA_RATE(1800000000UL, 0x0b4b0000, 0x00000000, 0xa0458585),
111 + CCU_PLLA_RATE(1850000000UL, 0x0b4d0555, 0x00005500, 0xa0458585),
112 + CCU_PLLA_RATE(1900000000UL, 0x0b4f0aaa, 0x0000ab00, 0xa0458686),
113 + CCU_PLLA_RATE(1950000000UL, 0x0b511000, 0x00000000, 0xa0458686),
41 114 CCU_PLLA_RATE(2000000000UL, 0x0b292aaa, 0x0000ab00, 0xa0558686),
42 115 };
43 116
@@ -50,6 +123,25 @@ static const struct ccu_pll_rate_tbl pll7_rate_tbl[] = {
50 123 };
51 124
52 125 static const struct ccu_pll_rate_tbl pll8_rate_tbl[] = {
126 + CCU_PLLA_RATE(1050000000UL, 0x0b2b3000, 0x00000000, 0xa0458080),
127 + CCU_PLLA_RATE(1100000000UL, 0x0b2d3555, 0x00005500, 0xa0458181),
128 + CCU_PLLA_RATE(1150000000UL, 0x0b2f3aaa, 0x0000ab00, 0xa0458181),
129 + CCU_PLLA_RATE(1200000000UL, 0x0b320000, 0x00000000, 0xa0458181),
130 + CCU_PLLA_RATE(1250000000UL, 0x0b340555, 0x00005500, 0xa0458181),
131 + CCU_PLLA_RATE(1300000000UL, 0x0b360aaa, 0x0000ab00, 0xa0458282),
132 + CCU_PLLA_RATE(1350000000UL, 0x0b381000, 0x00000000, 0xa0458282),
133 + CCU_PLLA_RATE(1400000000UL, 0x0b3a1555, 0x00005500, 0xa0458282),
134 + CCU_PLLA_RATE(1450000000UL, 0x0b3c1aaa, 0x0000ab00, 0xa0458383),
135 + CCU_PLLA_RATE(1500000000UL, 0x0b3e2000, 0x00000000, 0xa0458383),
136 + CCU_PLLA_RATE(1550000000UL, 0x0b402555, 0x00005500, 0xa0458383),
137 + CCU_PLLA_RATE(1600000000UL, 0x0b422aaa, 0x0000ab00, 0xa0458484),
138 + CCU_PLLA_RATE(1650000000UL, 0x0b443000, 0x00000000, 0xa0458484),
139 + CCU_PLLA_RATE(1700000000UL, 0x0b463555, 0x00005500, 0xa0458484),
140 + CCU_PLLA_RATE(1750000000UL, 0x0b483aaa, 0x0000ab00, 0xa0458585),
141 + CCU_PLLA_RATE(1800000000UL, 0x0b4b0000, 0x00000000, 0xa0458585),
142 + CCU_PLLA_RATE(1850000000UL, 0x0b4d0555, 0x00005500, 0xa0458585),
143 + CCU_PLLA_RATE(1900000000UL, 0x0b4f0aaa, 0x0000ab00, 0xa0458686),
144 + CCU_PLLA_RATE(1950000000UL, 0x0b511000, 0x00000000, 0xa0458686),
53 145 CCU_PLLA_RATE(2000000000UL, 0x0b292aaa, 0x0000ab00, 0xa0558686),
54 146 };
55 147
modified drivers/clk/ti/composite.c
@@ -52,7 +52,7 @@ static const struct clk_ops ti_composite_gate_ops = {
52 52
53 53 struct component_clk {
54 54 int num_parents;
55 - struct clk_parent_data *parent_data;
55 + const char **parent_names;
56 56 struct device_node *node;
57 57 int type;
58 58 struct clk_hw *hw;
@@ -116,7 +116,7 @@ static void __init _register_composite(void *user,
116 116 struct clk_hw_omap_comp *cclk = to_clk_hw_comp(hw);
117 117 struct component_clk *comp;
118 118 int num_parents = 0;
119 - struct clk_parent_data *parent_data = NULL;
119 + const char **parent_names = NULL;
120 120 const char *name;
121 121 int i;
122 122 int ret;
@@ -155,7 +155,7 @@ static void __init _register_composite(void *user,
155 155 continue;
156 156 if (comp->num_parents) {
157 157 num_parents = comp->num_parents;
158 - parent_data = comp->parent_data;
158 + parent_names = comp->parent_names;
159 159 break;
160 160 }
161 161 }
@@ -166,8 +166,8 @@ static void __init _register_composite(void *user,
166 166 }
167 167
168 168 name = ti_dt_clk_name(node);
169 - clk = clk_register_composite_pdata(NULL, name,
170 - parent_data, num_parents,
169 + clk = clk_register_composite(NULL, name,
170 + parent_names, num_parents,
171 171 _get_hw(cclk, CLK_COMPONENT_TYPE_MUX),
172 172 &ti_clk_mux_ops,
173 173 _get_hw(cclk, CLK_COMPONENT_TYPE_DIVIDER),
@@ -190,7 +190,7 @@ cleanup:
190 190 if (!cclk->comp_clks[i])
191 191 continue;
192 192 list_del(&cclk->comp_clks[i]->link);
193 - kfree(cclk->comp_clks[i]->parent_data);
193 + kfree(cclk->comp_clks[i]->parent_names);
194 194 kfree(cclk->comp_clks[i]);
195 195 }
196 196
@@ -237,9 +237,8 @@ int __init ti_clk_add_component(struct device_node *node, struct clk_hw *hw,
237 237 int type)
238 238 {
239 239 unsigned int num_parents;
240 - struct clk_parent_data *parent_data;
240 + const char **parent_names;
241 241 struct component_clk *clk;
242 - unsigned int i;
243 242
244 243 num_parents = of_clk_get_parent_count(node);
245 244
@@ -248,21 +247,20 @@ int __init ti_clk_add_component(struct device_node *node, struct clk_hw *hw,
248 247 return -EINVAL;
249 248 }
250 249
251 - parent_data = kzalloc_objs(*parent_data, num_parents);
252 - if (!parent_data)
250 + parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
251 + if (!parent_names)
253 252 return -ENOMEM;
254 253
255 - for (i = 0; i < num_parents; i++)
256 - parent_data[i].index = i;
254 + of_clk_parent_fill(node, parent_names, num_parents);
257 255
258 256 clk = kzalloc_obj(*clk);
259 257 if (!clk) {
260 - kfree(parent_data);
258 + kfree(parent_names);
261 259 return -ENOMEM;
262 260 }
263 261
264 262 clk->num_parents = num_parents;
265 - clk->parent_data = parent_data;
263 + clk->parent_names = parent_names;
266 264 clk->hw = hw;
267 265 clk->node = node;
268 266 clk->type = type;
modified drivers/cpufreq/cpufreq.c
@@ -2590,8 +2590,8 @@ static void cpufreq_update_pressure(struct cpufreq_policy *policy)
2590 2590
2591 2591 cpu = cpumask_first(policy->related_cpus);
2592 2592 max_freq = arch_scale_freq_ref(cpu);
2593 - if (!max_freq)
2594 - max_freq = policy->cpuinfo.max_freq;
2593 + if (!max_freq && cpufreq_driver->scale_freq_ref)
2594 + max_freq = cpufreq_driver->scale_freq_ref(policy);
2595 2595
2596 2596 capped_freq = policy->max;
2597 2597
modified drivers/cpufreq/intel_pstate.c
@@ -1135,6 +1135,14 @@ static bool hybrid_clear_max_perf_cpu(void)
1135 1135 return ret;
1136 1136 }
1137 1137
1138 + static unsigned int intel_pstate_scale_freq_ref(struct cpufreq_policy *policy)
1139 + {
1140 + if (READ_ONCE(all_cpu_data[policy->cpu]->capacity_perf))
1141 + return policy->cpuinfo.max_freq;
1142 +
1143 + return 0;
1144 + }
1145 +
1138 1146 static void intel_pstate_update_freq_limits(struct cpudata *cpu)
1139 1147 {
1140 1148 int scaling = cpu->pstate.scaling;
@@ -3088,6 +3096,7 @@ static struct cpufreq_driver intel_pstate = {
3088 3096 .offline = intel_pstate_cpu_offline,
3089 3097 .online = intel_pstate_cpu_online,
3090 3098 .update_limits = intel_pstate_update_limits,
3099 + .scale_freq_ref = intel_pstate_scale_freq_ref,
3091 3100 .name = "intel_pstate",
3092 3101 };
3093 3102
@@ -3411,6 +3420,7 @@ static struct cpufreq_driver intel_cpufreq = {
3411 3420 .suspend = intel_cpufreq_suspend,
3412 3421 .resume = intel_pstate_resume,
3413 3422 .update_limits = intel_pstate_update_limits,
3423 + .scale_freq_ref = intel_pstate_scale_freq_ref,
3414 3424 .name = "intel_cpufreq",
3415 3425 };
3416 3426
modified drivers/edac/altera_edac.c
@@ -453,15 +453,6 @@ free:
453 453 return res;
454 454 }
455 455
456 - static void altr_sdram_remove(struct platform_device *pdev)
457 - {
458 - struct mem_ctl_info *mci = platform_get_drvdata(pdev);
459 -
460 - edac_mc_del_mc(&pdev->dev);
461 - edac_mc_free(mci);
462 - platform_set_drvdata(pdev, NULL);
463 - }
464 -
465 456 /*
466 457 * If you want to suspend, need to disable EDAC by removing it
467 458 * from the device tree or defconfig.
@@ -481,13 +472,13 @@ static const struct dev_pm_ops altr_sdram_pm_ops = {
481 472
482 473 static struct platform_driver altr_sdram_edac_driver = {
483 474 .probe = altr_sdram_probe,
484 - .remove = altr_sdram_remove,
485 475 .driver = {
486 476 .name = "altr_sdram_edac",
487 477 #ifdef CONFIG_PM
488 478 .pm = &altr_sdram_pm_ops,
489 479 #endif
490 480 .of_match_table = altr_sdram_ctrl_of_match,
481 + .suppress_bind_attrs = true,
491 482 },
492 483 };
493 484
@@ -517,6 +508,7 @@ static struct platform_driver altr_edac_driver = {
517 508 .driver = {
518 509 .name = "socfpga_ecc_manager",
519 510 .of_match_table = altr_edac_of_match,
511 + .suppress_bind_attrs = true,
520 512 },
521 513 };
522 514 module_platform_driver(altr_edac_driver);
@@ -803,22 +795,12 @@ fail:
803 795 return res;
804 796 }
805 797
806 - static void altr_edac_device_remove(struct platform_device *pdev)
807 - {
808 - struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
809 - struct altr_edac_device_dev *drvdata = dci->pvt_info;
810 -
811 - debugfs_remove_recursive(drvdata->debugfs_dir);
812 - edac_device_del_device(&pdev->dev);
813 - edac_device_free_ctl_info(dci);
814 - }
815 -
816 798 static struct platform_driver altr_edac_device_driver = {
817 799 .probe = altr_edac_device_probe,
818 - .remove = altr_edac_device_remove,
819 800 .driver = {
820 801 .name = "altr_edac_device",
821 802 .of_match_table = altr_edac_device_of_match,
803 + .suppress_bind_attrs = true,
822 804 },
823 805 };
824 806 module_platform_driver(altr_edac_device_driver);
@@ -944,7 +926,7 @@ static int __maybe_unused altr_init_memory_port(void __iomem *ioaddr, int port)
944 926 return ret;
945 927 }
946 928
947 - static __init int __maybe_unused
929 + static int __maybe_unused
948 930 altr_init_a10_ecc_block(struct device_node *np, u32 irq_mask,
949 931 u32 ecc_ctrl_en_mask, bool dual_port)
950 932 {
@@ -1019,7 +1001,7 @@ out:
1019 1001
1020 1002 static int validate_parent_available(struct device_node *np);
1021 1003 static const struct of_device_id altr_edac_a10_device_of_match[];
1022 - static int __init __maybe_unused altr_init_a10_ecc_device_type(char *compat)
1004 + static int __maybe_unused altr_init_a10_ecc_device_type(char *compat)
1023 1005 {
1024 1006 int irq;
1025 1007 struct device_node *child, *np;
@@ -1348,7 +1330,7 @@ static const struct edac_device_prv_data a10_l2ecc_data = {
1348 1330
1349 1331 #ifdef CONFIG_EDAC_ALTERA_ETHERNET
1350 1332
1351 - static int __init socfpga_init_ethernet_ecc(struct altr_edac_device_dev *dev)
1333 + static int socfpga_init_ethernet_ecc(struct altr_edac_device_dev *dev)
1352 1334 {
1353 1335 int ret;
1354 1336
@@ -1378,7 +1360,7 @@ static const struct edac_device_prv_data a10_enetecc_data = {
1378 1360
1379 1361 #ifdef CONFIG_EDAC_ALTERA_NAND
1380 1362
1381 - static int __init socfpga_init_nand_ecc(struct altr_edac_device_dev *device)
1363 + static int socfpga_init_nand_ecc(struct altr_edac_device_dev *device)
1382 1364 {
1383 1365 int ret;
1384 1366
@@ -1408,7 +1390,7 @@ static const struct edac_device_prv_data a10_nandecc_data = {
1408 1390
1409 1391 #ifdef CONFIG_EDAC_ALTERA_DMA
1410 1392
1411 - static int __init socfpga_init_dma_ecc(struct altr_edac_device_dev *device)
1393 + static int socfpga_init_dma_ecc(struct altr_edac_device_dev *device)
1412 1394 {
1413 1395 int ret;
1414 1396
@@ -1438,7 +1420,7 @@ static const struct edac_device_prv_data a10_dmaecc_data = {
1438 1420
1439 1421 #ifdef CONFIG_EDAC_ALTERA_USB
1440 1422
1441 - static int __init socfpga_init_usb_ecc(struct altr_edac_device_dev *device)
1423 + static int socfpga_init_usb_ecc(struct altr_edac_device_dev *device)
1442 1424 {
1443 1425 int ret;
1444 1426
@@ -1468,7 +1450,7 @@ static const struct edac_device_prv_data a10_usbecc_data = {
1468 1450
1469 1451 #ifdef CONFIG_EDAC_ALTERA_QSPI
1470 1452
1471 - static int __init socfpga_init_qspi_ecc(struct altr_edac_device_dev *device)
1453 + static int socfpga_init_qspi_ecc(struct altr_edac_device_dev *device)
1472 1454 {
1473 1455 int ret;
1474 1456
@@ -1524,6 +1506,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1524 1506 dci = edac_device_alloc_ctl_info(sizeof(*altdev), ecc_name, 1,
1525 1507 ecc_name, 1, 0, edac_idx);
1526 1508 if (!dci) {
1509 + of_node_put(np);
1527 1510 edac_printk(KERN_ERR, EDAC_DEVICE,
1528 1511 "%s: Unable to allocate PortB EDAC device\n",
1529 1512 ecc_name);
@@ -1534,8 +1517,11 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1534 1517 altdev = dci->pvt_info;
1535 1518 *altdev = *device;
1536 1519
1537 - if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL))
1520 + if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL)) {
1521 + edac_device_free_ctl_info(dci);
1522 + of_node_put(np);
1538 1523 return -ENOMEM;
1524 + }
1539 1525
1540 1526 /* Update PortB specific values */
1541 1527 altdev->edac_dev_name = ecc_name;
@@ -1600,6 +1586,8 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1600 1586 rc = -ENOMEM;
1601 1587 goto err_release_group_1;
1602 1588 }
1589 + of_node_put(np);
1590 +
1603 1591 altr_create_edacdev_dbgfs(dci, prv);
1604 1592
1605 1593 list_add(&altdev->next, &altdev->edac->a10_ecc_devices);
@@ -1609,14 +1597,20 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1609 1597 return 0;
1610 1598
1611 1599 err_release_group_1:
1612 - edac_device_free_ctl_info(dci);
1600 + /*
1601 + * Release the devres group first so the managed IRQs are
1602 + * unregistered before dci (which contains the IRQ handler's
1603 + * data via dci->pvt_info) is freed, avoiding a use-after-free.
1604 + */
1613 1605 devres_release_group(device->edac->dev, altr_portb_setup);
1606 + edac_device_free_ctl_info(dci);
1607 + of_node_put(np);
1614 1608 edac_printk(KERN_ERR, EDAC_DEVICE,
1615 1609 "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
1616 1610 return rc;
1617 1611 }
1618 1612
1619 - static int __init socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
1613 + static int socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
1620 1614 {
1621 1615 int rc = -ENODEV;
1622 1616 struct device_node *child;
@@ -1638,7 +1632,7 @@ static int __init socfpga_init_sdmmc_ecc(struct altr_edac_device_dev *device)
1638 1632 goto exit;
1639 1633
1640 1634 /* Setup portB */
1641 - return altr_portb_setup(device);
1635 + rc = altr_portb_setup(device);
1642 1636
1643 1637 exit:
1644 1638 of_node_put(child);
@@ -2013,9 +2007,17 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
2013 2007 return 0;
2014 2008
2015 2009 err_release_group1:
2010 + /*
2011 + * Release the devres group first so the managed IRQs are
2012 + * unregistered before dci (which contains the IRQ handler's
2013 + * data via dci->pvt_info) is freed, avoiding a use-after-free.
2014 + */
2015 + devres_release_group(edac->dev, NULL);
2016 2016 edac_device_free_ctl_info(dci);
2017 + goto err_print;
2017 2018 err_release_group:
2018 2019 devres_release_group(edac->dev, NULL);
2020 + err_print:
2019 2021 edac_printk(KERN_ERR, EDAC_DEVICE,
2020 2022 "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
2021 2023
@@ -2214,6 +2216,7 @@ static struct platform_driver altr_edac_a10_driver = {
2214 2216 .driver = {
2215 2217 .name = "socfpga_a10_ecc_manager",
2216 2218 .of_match_table = altr_edac_a10_of_match,
2219 + .suppress_bind_attrs = true,
2217 2220 },
2218 2221 };
2219 2222 module_platform_driver(altr_edac_a10_driver);
modified drivers/edac/versalnet_edac.c
@@ -953,6 +953,7 @@ static void mc_remove(struct platform_device *pdev)
953 953 remove_versalnet(priv);
954 954 rproc_shutdown(priv->mcdi->r5_rproc);
955 955 cdx_mcdi_finish(priv->mcdi);
956 + rproc_put(priv->mcdi->r5_rproc);
956 957 kfree(priv->mcdi);
957 958 }
958 959
modified drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -318,7 +318,7 @@ static int acp_hw_init(struct amdgpu_ip_block *ip_block)
318 318 r = device_for_each_child(adev->acp.parent, &adev->acp.acp_genpd->gpd,
319 319 acp_genpd_add_device);
320 320 if (r)
321 - goto failure;
321 + goto failure_remove_mfd;
322 322 break;
323 323 }
324 324 default:
@@ -443,7 +443,7 @@ static int acp_hw_init(struct amdgpu_ip_block *ip_block)
443 443 r = device_for_each_child(adev->acp.parent, &adev->acp.acp_genpd->gpd,
444 444 acp_genpd_add_device);
445 445 if (r)
446 - goto failure;
446 + goto failure_remove_mfd;
447 447 }
448 448
449 449 /* Assert Soft reset of ACP */
@@ -461,7 +461,7 @@ static int acp_hw_init(struct amdgpu_ip_block *ip_block)
461 461 if (--count == 0) {
462 462 dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
463 463 r = -ETIMEDOUT;
464 - goto failure;
464 + goto failure_remove_mfd;
465 465 }
466 466 udelay(100);
467 467 }
@@ -479,7 +479,7 @@ static int acp_hw_init(struct amdgpu_ip_block *ip_block)
479 479 if (--count == 0) {
480 480 dev_err(&adev->pdev->dev, "Failed to reset ACP\n");
481 481 r = -ETIMEDOUT;
482 - goto failure;
482 + goto failure_remove_mfd;
483 483 }
484 484 udelay(100);
485 485 }
@@ -489,6 +489,11 @@ static int acp_hw_init(struct amdgpu_ip_block *ip_block)
489 489 cgs_write_register(adev->acp.cgs_device, mmACP_SOFT_RESET, val);
490 490 return 0;
491 491
492 + failure_remove_mfd:
493 + device_for_each_child(adev->acp.parent, NULL,
494 + acp_genpd_remove_device);
495 + mfd_remove_devices(adev->acp.parent);
496 +
492 497 failure:
493 498 kfree(adev->acp.i2s_pdata);
494 499 kfree(adev->acp.acp_res);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -1325,6 +1325,8 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
1325 1325 ip_hw_instance->kobj.kset = &ip_hw_id->hw_id_kset;
1326 1326 res = kobject_add(&ip_hw_instance->kobj, NULL,
1327 1327 "%d", ip_hw_instance->num_instance);
1328 + if (res)
1329 + kobject_put(&ip_hw_instance->kobj);
1328 1330 next_ip:
1329 1331 if (reg_base_64)
1330 1332 ip_offset += struct_size(ip, base_address_64,
modified drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2664,6 +2664,14 @@ static int amdgpu_pmops_suspend_noirq(struct device *dev)
2664 2664 struct amdgpu_device *adev = drm_to_adev(drm_dev);
2665 2665 int r;
2666 2666
2667 + /*
2668 + * A GPU parked by vga_switcheroo has no power and no PCIe link, so the
2669 + * ASIC reset below would fail and abort the whole noirq suspend phase.
2670 + * Bail out like amdgpu_device_prepare/suspend/resume() already do.
2671 + */
2672 + if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
2673 + return 0;
2674 +
2667 2675 if (amdgpu_acpi_should_gpu_reset(adev)) {
2668 2676 amdgpu_device_lock_reset_domain(adev->reset_domain);
2669 2677 r = amdgpu_asic_reset(adev);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -724,8 +724,14 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring,
724 724 bool is_guilty_fence;
725 725 bool is_guilty_context;
726 726
727 - last_seq = amdgpu_fence_read(ring) & ring->fence_drv.num_fences_mask;
728 - seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask;
727 + last_seq = amdgpu_fence_read(ring);
728 + seq = ring->fence_drv.sync_seq;
729 +
730 + /* Hardware completion can precede the interrupt which signals fences. */
731 + if (last_seq == seq) {
732 + amdgpu_fence_process(ring);
733 + return;
734 + }
729 735
730 736 /* If there is nothing to reemit, return early and set an error on the fence
731 737 * if applicable. If all of the fences are siganlled, this will be a nop.
@@ -733,7 +739,9 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring,
733 739 * we are skipping it on purpose.
734 740 */
735 741 if (!ring->ring_backup_entries_to_copy) {
736 - amdgpu_fence_driver_force_completion(ring, &guilty_fence->base);
742 + if (guilty_fence)
743 + amdgpu_fence_driver_force_completion(ring,
744 + &guilty_fence->base);
737 745 return;
738 746 }
739 747 ring->reemit = true;
@@ -741,9 +749,8 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring,
741 749 spin_lock_irqsave(&ring->fence_drv.lock, flags);
742 750 do {
743 751 last_seq++;
744 - last_seq &= ring->fence_drv.num_fences_mask;
745 752
746 - ptr = &ring->fence_drv.fences[last_seq];
753 + ptr = &ring->fence_drv.fences[last_seq & ring->fence_drv.num_fences_mask];
747 754 rcu_read_lock();
748 755 unprocessed = rcu_dereference(*ptr);
749 756
@@ -800,26 +807,24 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
800 807 struct amdgpu_fence *fence;
801 808 u32 seq, last_seq;
802 809
803 - last_seq = amdgpu_fence_read(ring) & ring->fence_drv.num_fences_mask;
804 - seq = ring->fence_drv.sync_seq & ring->fence_drv.num_fences_mask;
810 + last_seq = amdgpu_fence_read(ring);
811 + seq = ring->fence_drv.sync_seq;
805 812 ring->ring_backup_entries_to_copy = 0;
806 813
807 - /* if we've already seen this fence, return early.
808 - * ring->ring_backup_entries_to_copy is set to 0 so
809 - * the reemit helper will return early as well to
810 - * avoid getting stuck in a reemit loop.
814 + /*
815 + * Avoid replay loops for a repeated guilty fence. NULL identifies a
816 + * collateral ring, whose pending commands still need backup.
811 817 */
812 - if (ring->guilty_fence == guilty_fence) {
818 + if (guilty_fence && ring->guilty_fence == guilty_fence) {
813 819 ring->guilty_fence = NULL;
814 820 return;
815 821 }
816 822 ring->guilty_fence = guilty_fence;
817 823
818 - do {
824 + while (last_seq != seq) {
819 825 last_seq++;
820 - last_seq &= ring->fence_drv.num_fences_mask;
821 826
822 - ptr = &ring->fence_drv.fences[last_seq];
827 + ptr = &ring->fence_drv.fences[last_seq & ring->fence_drv.num_fences_mask];
823 828 rcu_read_lock();
824 829 unprocessed = rcu_dereference(*ptr);
825 830
@@ -829,7 +834,7 @@ void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
829 834 amdgpu_ring_backup_unprocessed_command(ring, fence);
830 835 }
831 836 rcu_read_unlock();
832 - } while (last_seq != seq);
837 + }
833 838 }
834 839
835 840 struct amdgpu_fence *
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2342,7 +2342,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
2342 2342 void amdgpu_ttm_enable_buffer_funcs(struct amdgpu_device *adev)
2343 2343 {
2344 2344 struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
2345 - u32 num_clear_entities, num_move_entities;
2345 + u32 num_clear_entities, num_move_entities, sdma_ip_version;
2346 2346 int r, i, j;
2347 2347
2348 2348 if (!adev->mman.initialized || amdgpu_in_reset(adev) ||
@@ -2367,6 +2367,12 @@ void amdgpu_ttm_enable_buffer_funcs(struct amdgpu_device *adev)
2367 2367
2368 2368 num_clear_entities = MIN(adev->mman.num_buffer_funcs_scheds, TTM_NUM_MOVE_FENCES);
2369 2369 num_move_entities = MIN(adev->mman.num_buffer_funcs_scheds, TTM_NUM_MOVE_FENCES);
2370 + /* TODO: workaround for DCC corruption when moving BOs from multiple queues at
2371 + * the same time: use a single queue until the root cause is identified and fixed.
2372 + */
2373 + sdma_ip_version = amdgpu_ip_version(adev, SDMA0_HWIP, 0);
2374 + if (sdma_ip_version == IP_VERSION(7, 0, 0) || sdma_ip_version == IP_VERSION(7, 0, 1))
2375 + num_move_entities = 1;
2370 2376
2371 2377 adev->mman.clear_entities = kzalloc_objs(struct amdgpu_ttm_buffer_entity,
2372 2378 num_clear_entities);
modified drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -3808,6 +3808,7 @@ static int gfx_v11_0_cp_gfx_resume(struct amdgpu_device *adev)
3808 3808 rb_bufsz = order_base_2(ring->ring_size / 8);
3809 3809 tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
3810 3810 tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
3811 + tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, KMD_QUEUE, 1);
3811 3812 WREG32_SOC15(GC, 0, regCP_RB0_CNTL, tmp);
3812 3813
3813 3814 /* Initialize the ring buffer's write pointers */
@@ -4216,6 +4217,7 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
4216 4217 tmp = regCP_GFX_HQD_CNTL_DEFAULT;
4217 4218 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BUFSZ, rb_bufsz);
4218 4219 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BLKSZ, rb_bufsz - 2);
4220 + tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, KMD_QUEUE, prop->kernel_queue);
4219 4221 #ifdef __BIG_ENDIAN
4220 4222 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
4221 4223 #endif
modified drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -2767,6 +2767,7 @@ static int gfx_v12_0_cp_gfx_resume(struct amdgpu_device *adev)
2767 2767 rb_bufsz = order_base_2(ring->ring_size / 8);
2768 2768 tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
2769 2769 tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
2770 + tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, KMD_QUEUE, 1);
2770 2771 WREG32_SOC15(GC, 0, regCP_RB0_CNTL, tmp);
2771 2772
2772 2773 /* Initialize the ring buffer's write pointers */
@@ -3059,6 +3060,7 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
3059 3060 tmp = regCP_GFX_HQD_CNTL_DEFAULT;
3060 3061 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BUFSZ, rb_bufsz);
3061 3062 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, RB_BLKSZ, rb_bufsz - 2);
3063 + tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, KMD_QUEUE, prop->kernel_queue);
3062 3064 #ifdef __BIG_ENDIAN
3063 3065 tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
3064 3066 #endif
modified drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c
@@ -322,6 +322,14 @@ static const u32 verde_rlc_save_restore_register_list[] =
322 322 0x00000000
323 323 };
324 324
325 + static void gfx_v6_0_free_microcode(struct amdgpu_device *adev)
326 + {
327 + amdgpu_ucode_release(&adev->gfx.pfp_fw);
328 + amdgpu_ucode_release(&adev->gfx.me_fw);
329 + amdgpu_ucode_release(&adev->gfx.ce_fw);
330 + amdgpu_ucode_release(&adev->gfx.rlc_fw);
331 + }
332 +
325 333 static int gfx_v6_0_init_microcode(struct amdgpu_device *adev)
326 334 {
327 335 const char *chip_name;
@@ -3249,6 +3257,7 @@ static int gfx_v6_0_sw_fini(struct amdgpu_ip_block *ip_block)
3249 3257 amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
3250 3258
3251 3259 amdgpu_gfx_rlc_fini(adev);
3260 + gfx_v6_0_free_microcode(adev);
3252 3261
3253 3262 return 0;
3254 3263 }
modified drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
@@ -327,7 +327,7 @@ static void gmc_v12_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
327 327 return;
328 328 }
329 329
330 - gmc_v12_0_flush_vm_hub(adev, vmid, vmhub, 0);
330 + gmc_v12_0_flush_vm_hub(adev, vmid, vmhub, flush_type);
331 331 return;
332 332 }
333 333
modified drivers/gpu/drm/amd/amdgpu/gmc_v12_1.c
@@ -389,7 +389,7 @@ static void gmc_v12_1_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
389 389 return;
390 390 }
391 391
392 - gmc_v12_1_flush_vm_hub(adev, vmid, vmhub, 0);
392 + gmc_v12_1_flush_vm_hub(adev, vmid, vmhub, flush_type);
393 393 return;
394 394 }
395 395
modified drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c
@@ -1339,10 +1339,6 @@ static int sdma_v7_1_sw_init(struct amdgpu_ip_block *ip_block)
1339 1339 else
1340 1340 DRM_ERROR("Failed to allocated memory for SDMA IP Dump\n");
1341 1341
1342 - #ifdef CONFIG_DRM_AMDGPU_NAVI3X_USERQ
1343 - adev->userq_funcs[AMDGPU_HW_IP_DMA] = &userq_mes_funcs;
1344 - #endif
1345 -
1346 1342 return r;
1347 1343 }
1348 1344
modified drivers/gpu/drm/amd/amdgpu/vi.c
@@ -1397,6 +1397,7 @@ struct vi_reset_quirk {
1397 1397 static const struct vi_reset_quirk vi_reset_quirks[] = {
1398 1398 { 0x67ef, PCI_VENDOR_ID_APPLE, 0x0190, 0xe3 }, /* Radeon Pro 555X */
1399 1399 { 0x67ef, PCI_VENDOR_ID_APPLE, 0x018f, 0xc2 }, /* Radeon Pro 560X */
1400 + { 0x67ef, PCI_VENDOR_ID_APPLE, 0x017a, 0xc7 }, /* Radeon Pro 555 */
1400 1401 };
1401 1402
1402 1403 static bool vi_need_reset_on_init(struct amdgpu_device *adev)
modified drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1752,12 +1752,15 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
1752 1752 }
1753 1753
1754 1754 /*
1755 - * If prange with always mapped flag, update mapping on GPUs with
1756 - * ACCESS attribute
1755 + * If prange with always mapped flag is not mapped or migrated
1756 + * yet, update mapping on GPUs with ACCESS attribute. Don't add
1757 + * them otherwise, ACCESS GPUs may be on different XGMI hives,
1758 + * that would force hmm_range_fault to migrate VRAM back to ram.
1757 1759 */
1758 - if (prange->flags & KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED)
1759 - bitmap_or(ctx->bitmap, ctx->bitmap, prange->bitmap_access,
1760 - MAX_GPU_INSTANCE);
1760 + if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE) &&
1761 + prange->flags & KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED)
1762 + bitmap_copy(ctx->bitmap, prange->bitmap_access,
1763 + MAX_GPU_INSTANCE);
1761 1764 } else {
1762 1765 bitmap_or(ctx->bitmap, prange->bitmap_access,
1763 1766 prange->bitmap_aip, MAX_GPU_INSTANCE);
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -426,6 +426,8 @@ static int amdgpu_dm_init_power_module(struct amdgpu_display_manager *dm)
426 426 init_data[i].use_custom_backlight_caps = false;
427 427 init_data[i].custom_backlight_caps_config_no = 0;
428 428 init_data[i].use_linear_backlight_curve = false;
429 + if (amdgpu_dc_debug_mask & DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE)
430 + init_data[i].use_linear_backlight_curve = true;
429 431 init_data[i].def_varibright_enable = 0;
430 432 init_data[i].varibright_level = 0;
431 433 /*
@@ -1582,9 +1584,14 @@ static int dm_suspend(struct amdgpu_ip_block *ip_block)
1582 1584 dc_allow_idle_optimizations(adev->dm.dc, false);
1583 1585
1584 1586 dm->cached_dc_state = dc_state_create_copy(dm->dc->current_state);
1587 + if (!dm->cached_dc_state) {
1588 + drm_err(adev_to_drm(adev),
1589 + "Failed to allocate cached DC state during suspend\n");
1590 + mutex_unlock(&dm->dc_lock);
1591 + return -ENOMEM;
1592 + }
1585 1593
1586 - if (dm->cached_dc_state)
1587 - dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, false);
1594 + dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, false);
1588 1595
1589 1596 res = amdgpu_dm_commit_zero_streams(dm->dc);
1590 1597 if (res != DC_OK) {
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
@@ -39,6 +39,7 @@
39 39 #include "modules/inc/mod_power.h"
40 40
41 41 #include <linux/backlight.h>
42 + #include <linux/minmax.h>
42 43 #include <linux/power_supply.h>
43 44 #include <drm/drm_edid.h>
44 45 #include <drm/drm_utils.h>
@@ -118,6 +119,68 @@ static inline u32 scale_fw_to_input(int min, int max, u64 input)
118 119 return min + DIV_ROUND_CLOSEST_ULL(input * (max - min), AMDGPU_MAX_BL_LEVEL);
119 120 }
120 121
122 + static u32 backlight_signal_to_luminance(const struct amdgpu_dm_backlight_caps *caps,
123 + u32 signal)
124 + {
125 + u32 lower_signal, upper_signal;
126 + u32 lower_lum, upper_lum;
127 + int i;
128 +
129 + if (!caps->data_points)
130 + return DIV_ROUND_CLOSEST(signal * 100, AMDGPU_MAX_BL_LEVEL);
131 +
132 + if (signal < caps->luminance_data[0].input_signal) {
133 + lower_signal = 0;
134 + lower_lum = 0;
135 + upper_signal = caps->luminance_data[0].input_signal;
136 + upper_lum = caps->luminance_data[0].luminance;
137 + } else if (signal >=
138 + caps->luminance_data[caps->data_points - 1].input_signal) {
139 + lower_signal = caps->luminance_data[caps->data_points - 1].input_signal;
140 + lower_lum = caps->luminance_data[caps->data_points - 1].luminance;
141 + upper_signal = caps->max_input_signal;
142 + upper_lum = 100;
143 + } else {
144 + for (i = 1;
145 + i < caps->data_points &&
146 + signal > caps->luminance_data[i].input_signal;
147 + i++)
148 + ;
149 +
150 + lower_signal = caps->luminance_data[i - 1].input_signal;
151 + upper_signal = caps->luminance_data[i].input_signal;
152 + lower_lum = caps->luminance_data[i - 1].luminance;
153 + upper_lum = caps->luminance_data[i].luminance;
154 + }
155 +
156 + if (upper_signal == lower_signal)
157 + return upper_lum;
158 +
159 + return lower_lum + DIV_ROUND_CLOSEST((upper_lum - lower_lum) *
160 + (signal - lower_signal),
161 + upper_signal - lower_signal);
162 + }
163 +
164 + static u32 convert_brightness_to_millipercent(const struct amdgpu_dm_backlight_caps *caps,
165 + u32 user_brightness)
166 + {
167 + unsigned int min, max;
168 + u32 signal, luminance;
169 +
170 + if (!get_brightness_range(caps, &min, &max))
171 + return DIV_ROUND_CLOSEST_ULL((u64)user_brightness * 100000,
172 + MAX_BACKLIGHT_LEVEL);
173 +
174 + user_brightness = clamp(user_brightness, min, max);
175 + if (amdgpu_dc_debug_mask & DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE)
176 + return DIV_ROUND_CLOSEST_ULL((u64)user_brightness * 100000, max);
177 +
178 + signal = scale_input_to_fw(max, user_brightness);
179 + luminance = backlight_signal_to_luminance(caps, signal);
180 +
181 + return min_t(u32, luminance * 1000, 100000);
182 + }
183 +
121 184 STATIC_IFN_KUNIT
122 185 void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps,
123 186 unsigned int min, unsigned int max,
@@ -260,10 +323,10 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
260 323 struct amdgpu_dm_backlight_caps *caps;
261 324 struct dc_link *link;
262 325 u32 brightness = 0;
326 + u32 millipercent = 0;
263 327 bool rc = false, reallow_idle = false;
264 328 struct drm_connector *connector;
265 329 struct dc_stream_state *stream;
266 - unsigned int min, max;
267 330
268 331 list_for_each_entry(connector, &dm->ddev->mode_config.connector_list, head) {
269 332 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
@@ -286,12 +349,21 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
286 349 /* update scratch register */
287 350 if (bl_idx == 0)
288 351 amdgpu_atombios_scratch_regs_set_backlight_level(dm->adev, dm->brightness[bl_idx]);
289 - brightness = convert_brightness_from_user(caps, dm->brightness[bl_idx]);
352 +
290 353 link = (struct dc_link *)dm->backlight_link[bl_idx];
354 + stream = dm_find_stream_with_link(dm, link);
355 + if (!stream)
356 + return;
291 357
292 - /* Apply brightness quirk */
293 - if (caps->brightness_mask)
294 - brightness |= caps->brightness_mask;
358 + if (caps->aux_support) {
359 + brightness = convert_brightness_from_user(caps, dm->brightness[bl_idx]);
360 + /* Apply brightness quirk */
361 + if (caps->brightness_mask)
362 + brightness |= caps->brightness_mask;
363 + } else {
364 + millipercent = convert_brightness_to_millipercent(caps,
365 + user_brightness);
366 + }
295 367
296 368 if (trace_amdgpu_dm_brightness_enabled()) {
297 369 trace_amdgpu_dm_brightness(__builtin_return_address(0),
@@ -301,10 +373,6 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
301 373 power_supply_is_system_supplied() > 0);
302 374 }
303 375
304 - stream = dm_find_stream_with_link(dm, link);
305 - if (!stream)
306 - return;
307 -
308 376 mutex_lock(&dm->dc_lock);
309 377 if (dm->dc->caps.ips_support && dm->dc->ctx->dmub_srv->idle_allowed) {
310 378 dc_allow_idle_optimizations(dm->dc, false);
@@ -316,10 +384,8 @@ void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
316 384 AUX_BL_DEFAULT_TRANSITION_TIME_MS, false, true);
317 385 } else {
318 386 /* power module uses millipercent */
319 - get_brightness_range(caps, &min, &max);
320 - brightness = DIV_ROUND_CLOSEST(brightness * 100, (max - min)) * 1000;
321 387 rc = mod_power_set_backlight_percent(dm->power_module, stream,
322 - brightness, 0, false);
388 + millipercent, 0, false);
323 389 }
324 390
325 391 /*
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -732,6 +732,24 @@ get_aspect_ratio(const struct drm_display_mode *mode_in)
732 732 }
733 733 EXPORT_IF_KUNIT(get_aspect_ratio);
734 734
735 + /*
736 + * CTA-861 5.1: RGB video formats default to limited range except 640x480 (VIC 1).
737 + * With Broadcast RGB left at Automatic follow that default, as i915 does.
738 + */
739 + static bool rgb_output_is_limited_range(const struct dc_crtc_timing *dc_crtc_timing,
740 + const struct drm_connector_state *connector_state)
741 + {
742 + switch (connector_state->hdmi.broadcast_rgb) {
743 + case DRM_HDMI_BROADCAST_RGB_FULL:
744 + return false;
745 + case DRM_HDMI_BROADCAST_RGB_LIMITED:
746 + return true;
747 + default:
748 + return connector_state->connector->display_info.is_hdmi &&
749 + dc_crtc_timing->vic > 1;
750 + }
751 + }
752 +
735 753 enum dc_color_space
736 754 amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing,
737 755 const struct drm_connector_state *connector_state)
@@ -757,7 +775,7 @@ amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing,
757 775 case DRM_MODE_COLORIMETRY_BT2020_RGB:
758 776 case DRM_MODE_COLORIMETRY_BT2020_YCC:
759 777 if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) {
760 - if (connector_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED)
778 + if (rgb_output_is_limited_range(dc_crtc_timing, connector_state))
761 779 color_space = COLOR_SPACE_2020_RGB_LIMITEDRANGE;
762 780 else
763 781 color_space = COLOR_SPACE_2020_RGB_FULLRANGE;
@@ -769,7 +787,7 @@ amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing,
769 787 default:
770 788 if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) {
771 789 color_space = COLOR_SPACE_SRGB;
772 - if (connector_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED)
790 + if (rgb_output_is_limited_range(dc_crtc_timing, connector_state))
773 791 color_space = COLOR_SPACE_SRGB_LIMITED;
774 792 /*
775 793 * 27030khz is the separation point between HDTV and SDTV
@@ -2256,8 +2274,8 @@ amdgpu_dm_create_validate_stream_for_sink(struct drm_connector *connector,
2256 2274 * below gate which of these entries are actually attempted.
2257 2275 */
2258 2276 static const enum dc_pixel_encoding encoding_order[] = {
2259 - PIXEL_ENCODING_YCBCR444,
2260 2277 PIXEL_ENCODING_RGB,
2278 + PIXEL_ENCODING_YCBCR444,
2261 2279 PIXEL_ENCODING_YCBCR422,
2262 2280 PIXEL_ENCODING_YCBCR420,
2263 2281 };
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -1231,7 +1231,8 @@ static bool get_conv_frl_bw(struct amdgpu_dm_connector *aconnector,
1231 1231 unsigned int max_sink_bw_in_kbps = 0;
1232 1232 unsigned int dsc_max_sink_bw_in_kbps = 0;
1233 1233
1234 - if (aconnector->dc_link->dc->caps.dp_hdmi21_pcon_support &&
1234 + if (aconnector->dc_sink &&
1235 + aconnector->dc_link->dc->caps.dp_hdmi21_pcon_support &&
1235 1236 aconnector->mst_downstream_port_caps.bytes.byte0.bits.DWN_STRM_PORTX_TYPE == DOWN_STREAM_DETAILED_HDMI) {
1236 1237 max_conv_bw_in_kbps = dc_link_bw_kbps_from_raw_frl_link_rate_data(
1237 1238 aconnector->dc_link->dc,
@@ -1996,6 +1997,9 @@ enum dc_status dm_dp_mst_is_port_support_mode(
1996 1997 struct dc_dsc_config_options dsc_options = {0};
1997 1998 uint32_t stream_kbps;
1998 1999
2000 + if (!aconnector->dc_sink)
2001 + return DC_FAIL_BANDWIDTH_VALIDATE;
2002 +
1999 2003 /* DSC unnecessary case
2000 2004 * Check if timing could be supported within end-to-end BW
2001 2005 */
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -409,7 +409,9 @@ static void dm_test_output_color_space_default_rgb_full(struct kunit *test)
409 409 {
410 410 struct dc_crtc_timing timing = {};
411 411 struct drm_connector_state state = {};
412 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
412 413
414 + state.connector = connector;
413 415 timing.pixel_encoding = PIXEL_ENCODING_RGB;
414 416 state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
415 417 state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
@@ -559,7 +561,9 @@ static void dm_test_output_color_space_bt2020_rgb(struct kunit *test)
559 561 {
560 562 struct dc_crtc_timing timing = {};
561 563 struct drm_connector_state state = {};
564 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
562 565
566 + state.connector = connector;
563 567 timing.pixel_encoding = PIXEL_ENCODING_RGB;
564 568 state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
565 569
@@ -584,6 +588,110 @@ static void dm_test_output_color_space_bt2020_rgb_limited(struct kunit *test)
584 588 (int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
585 589 }
586 590
591 + /**
592 + * dm_test_output_color_space_default_rgb_auto_hdmi_cta - Automatic follows the CTA-861 default
593 + * @test: The KUnit test context
594 + */
595 + static void dm_test_output_color_space_default_rgb_auto_hdmi_cta(struct kunit *test)
596 + {
597 + struct dc_crtc_timing timing = {};
598 + struct drm_connector_state state = {};
599 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
600 +
601 + connector->display_info.is_hdmi = true;
602 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
603 + timing.vic = 32;
604 + state.connector = connector;
605 + state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
606 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
607 +
608 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
609 + (int)COLOR_SPACE_SRGB_LIMITED);
610 + }
611 +
612 + /**
613 + * dm_test_output_color_space_default_rgb_auto_hdmi_vga - 640x480 (VIC 1) stays full range
614 + * @test: The KUnit test context
615 + */
616 + static void dm_test_output_color_space_default_rgb_auto_hdmi_vga(struct kunit *test)
617 + {
618 + struct dc_crtc_timing timing = {};
619 + struct drm_connector_state state = {};
620 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
621 +
622 + connector->display_info.is_hdmi = true;
623 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
624 + timing.vic = 1;
625 + state.connector = connector;
626 + state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
627 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
628 +
629 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
630 + (int)COLOR_SPACE_SRGB);
631 + }
632 +
633 + /**
634 + * dm_test_output_color_space_default_rgb_auto_dp_cta - Automatic on a non-HDMI sink is full range
635 + * @test: The KUnit test context
636 + */
637 + static void dm_test_output_color_space_default_rgb_auto_dp_cta(struct kunit *test)
638 + {
639 + struct dc_crtc_timing timing = {};
640 + struct drm_connector_state state = {};
641 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
642 +
643 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
644 + timing.vic = 32;
645 + state.connector = connector;
646 + state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
647 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
648 +
649 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
650 + (int)COLOR_SPACE_SRGB);
651 + }
652 +
653 + /**
654 + * dm_test_output_color_space_default_rgb_full_hdmi_cta - Full overrides the CTA-861 default
655 + * @test: The KUnit test context
656 + */
657 + static void dm_test_output_color_space_default_rgb_full_hdmi_cta(struct kunit *test)
658 + {
659 + struct dc_crtc_timing timing = {};
660 + struct drm_connector_state state = {};
661 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
662 +
663 + connector->display_info.is_hdmi = true;
664 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
665 + timing.vic = 32;
666 + state.connector = connector;
667 + state.colorspace = DRM_MODE_COLORIMETRY_DEFAULT;
668 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_FULL;
669 +
670 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
671 + (int)COLOR_SPACE_SRGB);
672 + }
673 +
674 + /**
675 + * dm_test_output_color_space_bt2020_rgb_auto_hdmi_cta - BT.2020 RGB follows the same default
676 + * @test: The KUnit test context
677 + */
678 + static void dm_test_output_color_space_bt2020_rgb_auto_hdmi_cta(struct kunit *test)
679 + {
680 + struct dc_crtc_timing timing = {};
681 + struct drm_connector_state state = {};
682 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
683 +
684 + connector->display_info.is_hdmi = true;
685 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
686 + timing.vic = 32;
687 + state.connector = connector;
688 + state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
689 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
690 +
691 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
692 + (int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
693 + }
694 +
587 695 /**
588 696 * dm_test_output_color_space_bt2020_ycc - Test Output color space bt2020 ycc
589 697 * @test: The KUnit test context
@@ -647,7 +755,9 @@ static void dm_test_output_color_space_bt2020_ycc_rgb_encoding(struct kunit *tes
647 755 {
648 756 struct dc_crtc_timing timing = {};
649 757 struct drm_connector_state state = {};
758 + struct drm_connector *connector = kunit_kzalloc(test, sizeof(*connector), GFP_KERNEL);
650 759
760 + state.connector = connector;
651 761 timing.pixel_encoding = PIXEL_ENCODING_RGB;
652 762 state.colorspace = DRM_MODE_COLORIMETRY_BT2020_YCC;
653 763
@@ -3425,6 +3535,7 @@ static struct dm_test_fill_ctx *dm_test_fill_ctx_alloc(struct kunit *test)
3425 3535
3426 3536 ctx->conn_state = drmm_kzalloc(ctx->drm, sizeof(*ctx->conn_state), GFP_KERNEL);
3427 3537 KUNIT_ASSERT_NOT_NULL(test, ctx->conn_state);
3538 + ctx->conn_state->connector = &ctx->aconnector->base;
3428 3539 ctx->stream = kunit_kzalloc(test, sizeof(*ctx->stream), GFP_KERNEL);
3429 3540 KUNIT_ASSERT_NOT_NULL(test, ctx->stream);
3430 3541 ctx->mode = kunit_kzalloc(test, sizeof(*ctx->mode), GFP_KERNEL);
@@ -3818,6 +3929,7 @@ static struct dm_test_stream_ctx *dm_test_stream_ctx_alloc(struct kunit *test)
3818 3929
3819 3930 ctx->dm_state = kunit_kzalloc(test, sizeof(*ctx->dm_state), GFP_KERNEL);
3820 3931 KUNIT_ASSERT_NOT_NULL(test, ctx->dm_state);
3932 + ctx->dm_state->base.connector = &ctx->aconnector->base;
3821 3933 ctx->dm_state->scaling = RMX_OFF;
3822 3934
3823 3935 ctx->mode = kunit_kzalloc(test, sizeof(*ctx->mode), GFP_KERNEL);
@@ -5458,6 +5570,11 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
5458 5570 KUNIT_CASE(dm_test_output_color_space_oprgb),
5459 5571 KUNIT_CASE(dm_test_output_color_space_bt2020_rgb),
5460 5572 KUNIT_CASE(dm_test_output_color_space_bt2020_rgb_limited),
5573 + KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_hdmi_cta),
5574 + KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_hdmi_vga),
5575 + KUNIT_CASE(dm_test_output_color_space_default_rgb_auto_dp_cta),
5576 + KUNIT_CASE(dm_test_output_color_space_default_rgb_full_hdmi_cta),
5577 + KUNIT_CASE(dm_test_output_color_space_bt2020_rgb_auto_hdmi_cta),
5461 5578 KUNIT_CASE(dm_test_output_color_space_bt2020_ycc),
5462 5579 KUNIT_CASE(dm_test_output_color_space_default_ycbcr709_y_only),
5463 5580 KUNIT_CASE(dm_test_output_color_space_default_ycbcr601),
modified drivers/gpu/drm/amd/display/dc/dc.h
@@ -1905,6 +1905,7 @@ struct dc_scratch_space {
1905 1905 struct ddc_service *ddc;
1906 1906
1907 1907 enum dp_panel_mode panel_mode;
1908 + bool panel_mode_initialized;
1908 1909 bool aux_mode;
1909 1910
1910 1911 /* Private to DC core */
modified drivers/gpu/drm/amd/display/dc/dml/Makefile
@@ -29,7 +29,7 @@ dml_ccflags := $(CC_FLAGS_FPU)
29 29 dml_rcflags := $(CC_FLAGS_NO_FPU)
30 30
31 31 ifneq ($(CONFIG_FRAME_WARN),0)
32 - ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)$(CONFIG_UBSAN)),y)
32 + ifneq ($(filter y,$(CONFIG_KASAN) $(CONFIG_KCSAN) $(CONFIG_UBSAN)),)
33 33 ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_COMPILE_TEST),yy)
34 34 frame_warn_limit := 4096
35 35 else
modified drivers/gpu/drm/amd/display/dc/dml2_0/Makefile
@@ -28,7 +28,7 @@ dml2_ccflags := $(CC_FLAGS_FPU)
28 28 dml2_rcflags := $(CC_FLAGS_NO_FPU)
29 29
30 30 ifneq ($(CONFIG_FRAME_WARN),0)
31 - ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)$(CONFIG_UBSAN)),y)
31 + ifneq ($(filter y,$(CONFIG_KASAN) $(CONFIG_KCSAN) $(CONFIG_UBSAN)),)
32 32 ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_COMPILE_TEST),yy)
33 33 frame_warn_limit := 4096
34 34 else
modified drivers/gpu/drm/amd/display/dc/resource/dce60/dce60_resource.c
@@ -448,6 +448,12 @@ static const struct dce_abm_mask abm_mask = {
448 448 ABM_MASK_SH_LIST_DCE110(_MASK)
449 449 };
450 450
451 + static const struct dc_debug_options debug_defaults = { 0 };
452 +
453 + static const struct dc_check_config config_defaults = {
454 + .enable_legacy_fast_update = true,
455 + };
456 +
451 457 #define CTX ctx
452 458 #define REG(reg) mm ## reg
453 459
@@ -937,6 +943,8 @@ static bool dce60_construct(
937 943 dc->caps.max_cursor_size = 64;
938 944 dc->caps.dual_link_dvi = true;
939 945 dc->caps.extended_aux_timeout_support = false;
946 + dc->debug = debug_defaults;
947 + dc->check_config = config_defaults;
940 948
941 949 /*************************************************
942 950 * Create resources *
@@ -1134,6 +1142,8 @@ static bool dce61_construct(
1134 1142 dc->caps.i2c_speed_in_khz = 40;
1135 1143 dc->caps.max_cursor_size = 64;
1136 1144 dc->caps.is_apu = true;
1145 + dc->debug = debug_defaults;
1146 + dc->check_config = config_defaults;
1137 1147
1138 1148 /*************************************************
1139 1149 * Create resources *
@@ -1331,7 +1341,8 @@ static bool dce64_construct(
1331 1341 dc->caps.max_downscale_ratio = 200;
1332 1342 dc->caps.i2c_speed_in_khz = 40;
1333 1343 dc->caps.max_cursor_size = 64;
1334 - dc->caps.is_apu = true;
1344 + dc->debug = debug_defaults;
1345 + dc->check_config = config_defaults;
1335 1346
1336 1347 /*************************************************
1337 1348 * Create resources *
modified drivers/gpu/drm/amd/display/dc/resource/dce80/dce80_resource.c
@@ -1148,6 +1148,8 @@ static bool dce81_construct(
1148 1148 dc->caps.max_cursor_size = 128;
1149 1149 dc->caps.min_horizontal_blanking_period = 80;
1150 1150 dc->caps.is_apu = true;
1151 + dc->debug = debug_defaults;
1152 + dc->check_config = config_defaults;
1151 1153
1152 1154 /*************************************************
1153 1155 * Create resources *
modified drivers/gpu/drm/amd/display/modules/power/power.c
@@ -328,6 +328,7 @@ bool mod_power_add_stream(struct mod_power *mod_power,
328 328 core_power->map[core_power->num_entities].psr_enabled = 0;
329 329 core_power->map[core_power->num_entities].psr_events = psr_event_vsync;
330 330 core_power->map[core_power->num_entities].psr_power_opt = 0;
331 + core_power->map[core_power->num_entities].replay_events = replay_event_vsync;
331 332 core_power->num_entities++;
332 333 return true;
333 334 }
@@ -387,6 +388,7 @@ bool mod_power_remove_stream(struct mod_power *mod_power,
387 388 core_power->map[i].psr_enabled = core_power->map[i + 1].psr_enabled;
388 389 core_power->map[i].psr_events = core_power->map[i + 1].psr_events;
389 390 core_power->map[i].psr_power_opt = core_power->map[i + 1].psr_power_opt;
391 + core_power->map[i].replay_events = core_power->map[i + 1].replay_events;
390 392
391 393 memcpy(core_power->map[i].psr_context, core_power->map[i + 1].psr_context, sizeof(struct mod_power_psr_context));
392 394 memset(core_power->map[i + 1].psr_context, 0, sizeof(struct mod_power_psr_context));
modified drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
@@ -5263,7 +5263,8 @@ static int si_init_smc_table(struct amdgpu_device *adev)
5263 5263 break;
5264 5264 }
5265 5265
5266 - if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
5266 + if ((adev->flags & AMD_IS_MOBILITY) &&
5267 + (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC))
5267 5268 table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
5268 5269
5269 5270 if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT) {
@@ -7237,6 +7238,19 @@ static void si_parse_pplib_non_clock_info(struct amdgpu_device *adev,
7237 7238 adev->pm.dpm.uvd_ps = rps;
7238 7239 }
7239 7240
7241 + static void si_update_limits(struct amdgpu_clock_and_voltage_limits *limits,
7242 + struct rv7xx_pl *pl)
7243 + {
7244 + if (pl->sclk > limits->sclk)
7245 + limits->sclk = pl->sclk;
7246 + if (pl->mclk > limits->mclk)
7247 + limits->mclk = pl->mclk;
7248 + if (pl->vddc > limits->vddc)
7249 + limits->vddc = pl->vddc;
7250 + if (pl->vddci > limits->vddci)
7251 + limits->vddci = pl->vddci;
7252 + }
7253 +
7240 7254 static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
7241 7255 struct amdgpu_ps *rps, int index,
7242 7256 union pplib_clock_info *clock_info)
@@ -7245,7 +7259,6 @@ static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
7245 7259 struct evergreen_power_info *eg_pi = evergreen_get_pi(adev);
7246 7260 struct si_power_info *si_pi = si_get_pi(adev);
7247 7261 struct si_ps *ps = si_get_ps(rps);
7248 - struct amdgpu_clock_and_voltage_limits *limits;
7249 7262 u16 leakage_voltage;
7250 7263 struct rv7xx_pl *pl = &ps->performance_levels[index];
7251 7264 int ret;
@@ -7310,26 +7323,14 @@ static void si_parse_pplib_clock_info(struct amdgpu_device *adev,
7310 7323 * VBIOS can contain conflicting values between:
7311 7324 * - the maximum allowed clocks and voltages on AC or DC
7312 7325 * - the clocks and voltages in power states on AC or DC
7326 + *
7327 + * Assume that the AC limits are the maximum of all power states,
7328 + * and the DC limits are the maximum of battery power states.
7313 7329 */
7330 + si_update_limits(&adev->pm.dpm.dyn_state.max_clock_voltage_on_ac, pl);
7314 7331 if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
7315 - ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE)
7316 - limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
7317 - else if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
7318 7332 ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
7319 - limits = &adev->pm.dpm.dyn_state.max_clock_voltage_on_dc;
7320 - else
7321 - limits = NULL;
7322 -
7323 - if (limits) {
7324 - if (pl->sclk > limits->sclk)
7325 - limits->sclk = pl->sclk;
7326 - if (pl->mclk > limits->mclk)
7327 - limits->mclk = pl->mclk;
7328 - if (pl->vddc > limits->vddc)
7329 - limits->vddc = pl->vddc;
7330 - if (pl->vddci > limits->vddci)
7331 - limits->vddci = pl->vddci;
7332 - }
7333 + si_update_limits(&adev->pm.dpm.dyn_state.max_clock_voltage_on_dc, pl);
7333 7334 }
7334 7335
7335 7336 union pplib_power_state {
modified drivers/gpu/drm/i915/display/intel_display_params.c
@@ -120,6 +120,10 @@ intel_display_param_named_unsafe(enable_psr, int, 0400,
120 120 "(0=disabled, 1=enable up to PSR1, 2=enable up to PSR2) "
121 121 "Default: -1 (use per-chip default)");
122 122
123 + intel_display_param_named_unsafe(enable_dc_balance, bool, 0400,
124 + "Enable VRR DC balance (0=disabled, 1=enabled). "
125 + "Default: 0 (disabled)");
126 +
123 127 intel_display_param_named_unsafe(enable_panel_replay, int, 0400,
124 128 "Enable Panel Replay (0=disabled, 1=enabled). Default: -1 (use per-chip default)");
125 129
modified drivers/gpu/drm/i915/display/intel_display_params.h
@@ -46,6 +46,7 @@ struct drm_printer;
46 46 param(bool, enable_dp_mst, true, 0600) \
47 47 param(int, enable_fbc, -1, 0600) \
48 48 param(int, enable_psr, -1, 0600) \
49 + param(bool, enable_dc_balance, false, 0600) \
49 50 param(int, enable_panel_replay, -1, 0600) \
50 51 param(bool, psr_safest_params, false, 0400) \
51 52 param(bool, enable_psr2_sel_fetch, true, 0400) \
modified drivers/gpu/drm/i915/display/intel_vrr.c
@@ -386,10 +386,12 @@ static bool intel_vrr_dc_balance_possible(const struct intel_crtc_state *crtc_st
386 386 static void
387 387 intel_vrr_dc_balance_compute_config(struct intel_crtc_state *crtc_state)
388 388 {
389 + struct intel_display *display = to_intel_display(crtc_state);
389 390 int guardband_usec, adjustment_usec;
390 391 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
391 392
392 - if (!intel_vrr_dc_balance_possible(crtc_state) || !crtc_state->vrr.enable)
393 + if (!intel_vrr_dc_balance_possible(crtc_state) ||
394 + !crtc_state->vrr.enable || !display->params.enable_dc_balance)
393 395 return;
394 396
395 397 crtc_state->vrr.dc_balance.vmax = crtc_state->vrr.vmax;
modified drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -638,8 +638,10 @@ static int mtk_drm_bind(struct device *dev)
638 638 private->mtk_drm_bound = true;
639 639 private->dev = dev;
640 640
641 - if (!mtk_drm_get_all_drm_priv(dev))
641 + if (!mtk_drm_get_all_drm_priv(dev)) {
642 + put_device(private->mutex_dev);
642 643 return 0;
644 + }
643 645
644 646 drm = drm_dev_alloc(&mtk_drm_driver, dev);
645 647 if (IS_ERR(drm)) {
@@ -1060,7 +1062,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
1060 1062 struct mtk_mmsys_driver_data *mtk_drm_data;
1061 1063 struct device_node *node;
1062 1064 struct component_match *match = NULL;
1063 - struct platform_device *ovl_adaptor;
1065 + struct platform_device *ovl_adaptor = NULL;
1064 1066 int ret;
1065 1067 int i;
1066 1068
@@ -1112,6 +1114,9 @@ static int mtk_drm_probe(struct platform_device *pdev)
1112 1114 PLATFORM_DEVID_AUTO,
1113 1115 (void *)private->mmsys_dev,
1114 1116 sizeof(*private->mmsys_dev));
1117 + if (IS_ERR(ovl_adaptor))
1118 + return PTR_ERR(ovl_adaptor);
1119 +
1115 1120 private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
1116 1121 mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
1117 1122 DDP_COMPONENT_DRM_OVL_ADAPTOR);
@@ -1205,6 +1210,8 @@ static int mtk_drm_probe(struct platform_device *pdev)
1205 1210 err_pm:
1206 1211 pm_runtime_disable(dev);
1207 1212 err_node:
1213 + if (ovl_adaptor)
1214 + platform_device_unregister(ovl_adaptor);
1208 1215 of_node_put(private->mutex_node);
1209 1216 for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++)
1210 1217 of_node_put(private->comp_node[i]);
@@ -1214,9 +1221,15 @@ err_node:
1214 1221 static void mtk_drm_remove(struct platform_device *pdev)
1215 1222 {
1216 1223 struct mtk_drm_private *private = platform_get_drvdata(pdev);
1224 + struct device *ovl_adaptor_dev;
1217 1225 int i;
1218 1226
1227 + ovl_adaptor_dev =
1228 + private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev;
1229 +
1219 1230 component_master_del(&pdev->dev, &mtk_drm_ops);
1231 + if (ovl_adaptor_dev)
1232 + platform_device_unregister(to_platform_device(ovl_adaptor_dev));
1220 1233 pm_runtime_disable(&pdev->dev);
1221 1234 of_node_put(private->mutex_node);
1222 1235 for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++)
modified drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c
@@ -376,8 +376,10 @@ static int mtk_hdmi_ddc_v2_probe(struct platform_device *pdev)
376 376 pm_runtime_get_sync(dev);
377 377
378 378 ret = devm_i2c_add_adapter(dev, &ddc->adap);
379 - if (ret < 0)
379 + if (ret < 0) {
380 + pm_runtime_put_noidle(dev);
380 381 return dev_err_probe(dev, ret, "Cannot add DDC I2C adapter\n");
382 + }
381 383
382 384 platform_set_drvdata(pdev, ddc);
383 385 return 0;
modified drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h
@@ -173,7 +173,7 @@
173 173 #define TPI_AUDIO_LOOKUP_EN BIT(2)
174 174
175 175 /* Video downsampling configuration */
176 - #define VID_DOWNSAMPLE_CONFIG 0x8d0
176 + #define VID_DOWNSAMPLE_CONFIG 0x8f0
177 177 #define C444_C422_CONFIG_ENABLE BIT(0)
178 178 #define C422_C420_CONFIG_ENABLE BIT(4)
179 179 #define C422_C420_CONFIG_BYPASS BIT(5)
modified drivers/gpu/drm/radeon/radeon_bios.c
@@ -49,6 +49,7 @@
49 49 static bool igp_read_bios_from_vram(struct radeon_device *rdev)
50 50 {
51 51 uint8_t __iomem *bios;
52 + uint8_t val1, val2;
52 53 resource_size_t vram_base;
53 54 resource_size_t size = 256 * 1024; /* ??? */
54 55
@@ -63,7 +64,10 @@ static bool igp_read_bios_from_vram(struct radeon_device *rdev)
63 64 return false;
64 65 }
65 66
66 - if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
67 + val1 = readb(&bios[0]);
68 + val2 = readb(&bios[1]);
69 +
70 + if (size == 0 || val1 != 0x55 || val2 != 0xaa) {
67 71 iounmap(bios);
68 72 return false;
69 73 }
modified drivers/gpu/drm/xe/xe_pci_sriov.c
@@ -82,16 +82,33 @@ static void pf_engine_activity_stats(struct xe_device *xe, unsigned int num_vfs,
82 82 }
83 83 }
84 84
85 - static int resize_vf_vram_bar(struct xe_device *xe, int num_vfs)
85 + static int pf_resize_vf_vram_bar(struct xe_device *xe, int num_vfs)
86 86 {
87 87 struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
88 + char buf[10];
88 89 u32 sizes;
90 + int size;
91 + int err;
92 +
93 + if (!IS_DGFX(xe))
94 + return 0;
89 95
90 96 sizes = pci_iov_vf_bar_get_sizes(pdev, VF_LMEM_BAR, num_vfs);
91 97 if (!sizes)
92 98 return 0;
93 99
94 - return pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, __fls(sizes));
100 + size = __fls(sizes);
101 + string_get_size(pci_rebar_size_to_bytes(size), 1, STRING_UNITS_2, buf, sizeof(buf));
102 +
103 + err = pci_iov_vf_bar_set_size(pdev, VF_LMEM_BAR, size);
104 + if (err) {
105 + xe_sriov_notice(xe, "Failed to resize VF BAR %u to %s (%pe)\n",
106 + VF_LMEM_BAR, buf, ERR_PTR(err));
107 + return err;
108 + }
109 +
110 + xe_sriov_dbg(xe, "VF LMEM BAR resized to %s\n", buf);
111 + return 0;
95 112 }
96 113
97 114 static int pf_prepare_vfs_enabling(struct xe_device *xe)
@@ -142,11 +159,7 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
142 159 if (err < 0)
143 160 goto failed;
144 161
145 - if (IS_DGFX(xe)) {
146 - err = resize_vf_vram_bar(xe, num_vfs);
147 - if (err)
148 - xe_sriov_info(xe, "Failed to set VF LMEM BAR size: %d\n", err);
149 - }
162 + pf_resize_vf_vram_bar(xe, num_vfs);
150 163
151 164 err = pci_enable_sriov(pdev, num_vfs);
152 165 if (err < 0)
@@ -164,6 +177,7 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
164 177 return num_vfs;
165 178
166 179 failed:
180 + pf_resize_vf_vram_bar(xe, xe->sriov.pf.device_total_vfs);
167 181 xe_sriov_pf_unprovision_vfs(xe, num_vfs);
168 182 xe_pm_runtime_put(xe);
169 183 pf_finish_vfs_enabling(xe);
@@ -191,6 +205,8 @@ static int pf_disable_vfs(struct xe_device *xe)
191 205
192 206 pci_disable_sriov(pdev);
193 207
208 + pf_resize_vf_vram_bar(xe, xe->sriov.pf.device_total_vfs);
209 +
194 210 xe_sriov_pf_reprovision_default(xe);
195 211
196 212 pf_reset_vfs(xe, num_vfs);
modified drivers/hid/bpf/hid_bpf_dispatch.c
@@ -453,7 +453,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
453 453 (u64)(long)ctx,
454 454 true); /* prevent infinite recursions */
455 455
456 - if (ret > size)
456 + if (ret > (ssize_t)size)
457 457 ret = size;
458 458 if (ret > 0)
459 459 memcpy(buf, dma_data, ret);
modified drivers/hid/hid-ids.h
@@ -1510,6 +1510,9 @@
1510 1510 #define USB_DEVICE_ID_ASUS_MD_5110 0x5110
1511 1511 #define USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART 0x7100
1512 1512
1513 + #define USB_VENDOR_ID_TURTLE_BEACH 0x10f5
1514 + #define USB_DEVICE_ID_TB_VELOCITYONE_RACE 0x7077
1515 +
1513 1516 #define USB_VENDOR_ID_TWINHAN 0x6253
1514 1517 #define USB_DEVICE_ID_TWINHAN_IR_REMOTE 0x0100
1515 1518
modified drivers/hid/hid-logitech-dj.c
@@ -121,7 +121,6 @@ enum recvr_type {
121 121 recvr_type_27mhz,
122 122 recvr_type_bluetooth,
123 123 recvr_type_dinovo,
124 - recvr_type_bolt,
125 124 };
126 125
127 126 struct dj_report {
@@ -1157,10 +1156,6 @@ static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
1157 1156 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1158 1157 workitem.reports_supported |= STD_KEYBOARD;
1159 1158 break;
1160 - case 0x10:
1161 - device_type = "Bolt";
1162 - logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1163 - break;
1164 1159 }
1165 1160
1166 1161 /* custom receiver device (eg. powerplay) */
@@ -1750,24 +1745,6 @@ static int logi_dj_hidpp_event(struct hid_device *hdev,
1750 1745
1751 1746 dj_dev = djrcv_dev->paired_dj_devices[device_index];
1752 1747
1753 - /*
1754 - * Bolt receivers send explicit unpair notifications as HID++ events;
1755 - * queue device removal when we receive one.
1756 - */
1757 - if (djrcv_dev->type == recvr_type_bolt &&
1758 - hidpp_report->report_id == REPORT_ID_HIDPP_SHORT &&
1759 - hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED) {
1760 - struct dj_workitem workitem = {
1761 - .device_index = device_index,
1762 - .type = WORKITEM_TYPE_UNPAIRED,
1763 - };
1764 -
1765 - kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1766 - schedule_work(&djrcv_dev->work);
1767 - spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1768 - return false;
1769 - }
1770 -
1771 1748 /*
1772 1749 * With 27 MHz receivers, we do not get an explicit unpair event,
1773 1750 * remove the old device if the user has paired a *different* device.
@@ -1907,9 +1884,6 @@ static int logi_dj_probe(struct hid_device *hdev,
1907 1884 * treat these as logitech-dj interfaces then this causes input events
1908 1885 * reported through this extra interface to not be reported correctly.
1909 1886 * To avoid this, we treat these as generic-hid devices.
1910 - *
1911 - * Bolt receivers only use LOGITECH_DJ_INTERFACE_NUMBER for receiver
1912 - * reporting. Treat all other Bolt interfaces as generic-hid devices.
1913 1887 */
1914 1888 switch (id->driver_data) {
1915 1889 case recvr_type_dj: no_dj_interfaces = 3; break;
@@ -1923,20 +1897,10 @@ static int logi_dj_probe(struct hid_device *hdev,
1923 1897 }
1924 1898 if (hid_is_usb(hdev)) {
1925 1899 intf = to_usb_interface(hdev->dev.parent);
1926 - if (intf) {
1927 - bool generic_hid_interface;
1928 -
1929 - if (id->driver_data == recvr_type_bolt)
1930 - generic_hid_interface =
1931 - intf->altsetting->desc.bInterfaceNumber !=
1932 - LOGITECH_DJ_INTERFACE_NUMBER;
1933 - else
1934 - generic_hid_interface =
1935 - intf->altsetting->desc.bInterfaceNumber >= no_dj_interfaces;
1936 - if (generic_hid_interface) {
1937 - hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1938 - return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1939 - }
1900 + if (intf && intf->altsetting->desc.bInterfaceNumber >=
1901 + no_dj_interfaces) {
1902 + hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1903 + return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1940 1904 }
1941 1905 }
1942 1906
@@ -2139,10 +2103,6 @@ static const struct hid_device_id logi_dj_receivers[] = {
2139 2103 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2140 2104 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_3),
2141 2105 .driver_data = recvr_type_gaming_hidpp_ls_1_3},
2142 - { /* Logitech Bolt receiver (0xc548) */
2143 - HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2144 - USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER),
2145 - .driver_data = recvr_type_bolt},
2146 2106 { /* Logitech lightspeed receiver (0xc54d) */
2147 2107 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2148 2108 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_4),
modified drivers/hid/hid-logitech-hidpp.c
@@ -988,8 +988,7 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
988 988 }
989 989
990 990 /* the device might not be connected */
991 - if (ret == HIDPP_ERROR_CONNECT_FAIL ||
992 - ret == HIDPP_ERROR_RESOURCE_ERROR ||
991 + if (ret == HIDPP_ERROR_RESOURCE_ERROR ||
993 992 ret == HIDPP_ERROR_UNKNOWN_DEVICE)
994 993 return -EIO;
995 994
@@ -4405,50 +4404,8 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp)
4405 4404 return ret;
4406 4405 }
4407 4406
4408 - static bool hidpp_is_bolt_child(struct hid_device *hdev)
4409 - {
4410 - struct device *parent = hdev->dev.parent;
4411 - struct hid_device *receiver_hdev;
4412 -
4413 - if (!parent)
4414 - return false;
4415 -
4416 - receiver_hdev = to_hid_device(parent);
4417 - return receiver_hdev->vendor == USB_VENDOR_ID_LOGITECH &&
4418 - receiver_hdev->product == USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER;
4419 - }
4420 -
4421 - static int hidpp_bolt_init(struct hidpp_device *hidpp)
4422 - {
4423 - struct hid_device *hdev = hidpp->hid_dev;
4424 - char *name;
4425 - int ret;
4426 -
4427 - ret = hidpp_serial_init(hidpp);
4428 - if (ret)
4429 - return ret;
4430 -
4431 - name = hidpp_get_device_name(hidpp);
4432 - if (!name)
4433 - return -EIO;
4434 -
4435 - snprintf(hdev->name, sizeof(hdev->name), "%s", name);
4436 - dbg_hid("HID++ Bolt: Got name: %s\n", name);
4437 -
4438 - kfree(name);
4439 - return 0;
4440 - }
4441 -
4442 - static int hidpp_receiver_init(struct hidpp_device *hidpp)
4443 - {
4444 - if (hidpp_is_bolt_child(hidpp->hid_dev))
4445 - return hidpp_bolt_init(hidpp);
4446 -
4447 - return hidpp_unifying_init(hidpp);
4448 - }
4449 -
4450 4407 /* Get name + serial for USB and Bluetooth HID++ devices */
4451 - static void hidpp_non_receiver_init(struct hidpp_device *hidpp)
4408 + static void hidpp_non_unifying_init(struct hidpp_device *hidpp)
4452 4409 {
4453 4410 struct hid_device *hdev = hidpp->hid_dev;
4454 4411 char *name;
@@ -4800,9 +4757,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
4800 4757
4801 4758 /* Get name + serial, store in hdev->name + hdev->uniq */
4802 4759 if (id->group == HID_GROUP_LOGITECH_DJ_DEVICE)
4803 - hidpp_receiver_init(hidpp);
4760 + hidpp_unifying_init(hidpp);
4804 4761 else
4805 - hidpp_non_receiver_init(hidpp);
4762 + hidpp_non_unifying_init(hidpp);
4806 4763
4807 4764 if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT)
4808 4765 connect_mask &= ~HID_CONNECT_HIDINPUT;
modified drivers/hid/hid-multitouch.c
@@ -2249,7 +2249,7 @@ static void mt_remove(struct hid_device *hdev)
2249 2249 {
2250 2250 struct mt_device *td = hid_get_drvdata(hdev);
2251 2251
2252 - timer_delete_sync(&td->release_timer);
2252 + timer_shutdown_sync(&td->release_timer);
2253 2253
2254 2254 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
2255 2255 hid_hw_stop(hdev);
modified drivers/hid/hid-universal-pidff.c
@@ -187,6 +187,7 @@ static const struct hid_device_id universal_pidff_devices[] = {
187 187 { HID_USB_DEVICE(USB_VENDOR_ID_ASETEK, USB_DEVICE_ID_ASETEK_FORTE) },
188 188 { HID_USB_DEVICE(USB_VENDOR_ID_ASETEK, USB_DEVICE_ID_ASETEK_LA_PRIMA) },
189 189 { HID_USB_DEVICE(USB_VENDOR_ID_ASETEK, USB_DEVICE_ID_ASETEK_TONY_KANAAN) },
190 + { HID_USB_DEVICE(USB_VENDOR_ID_TURTLE_BEACH, USB_DEVICE_ID_TB_VELOCITYONE_RACE)},
190 191 {}
191 192 };
192 193 MODULE_DEVICE_TABLE(hid, universal_pidff_devices);
modified drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
@@ -606,7 +606,8 @@ static int quicki2c_alloc_report_buf(struct quicki2c_device *qcdev)
606 606 */
607 607 max_report_len = max(le16_to_cpu(qcdev->dev_desc.max_input_len), SZ_4K);
608 608
609 - qcdev->input_buf = devm_kzalloc(qcdev->dev, max_report_len, GFP_KERNEL);
609 + qcdev->input_buf = devm_kzalloc(qcdev->dev,
610 + HIDI2C_PACKET_LEN(max_report_len), GFP_KERNEL);
610 611 if (!qcdev->input_buf)
611 612 return -ENOMEM;
612 613
@@ -616,7 +617,8 @@ static int quicki2c_alloc_report_buf(struct quicki2c_device *qcdev)
616 617 max_report_len = max(le16_to_cpu(qcdev->dev_desc.max_output_len),
617 618 max_report_len);
618 619
619 - qcdev->report_buf = devm_kzalloc(qcdev->dev, max_report_len, GFP_KERNEL);
620 + qcdev->report_buf = devm_kzalloc(qcdev->dev,
621 + HIDI2C_PACKET_LEN(max_report_len), GFP_KERNEL);
620 622 if (!qcdev->report_buf)
621 623 return -ENOMEM;
622 624
modified drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
@@ -552,7 +552,8 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
552 552 max_input_len = max(le16_to_cpu(qsdev->dev_desc.rep_desc_len),
553 553 le16_to_cpu(qsdev->dev_desc.max_input_len));
554 554
555 - qsdev->input_buf = devm_kzalloc(qsdev->dev, max_input_len, GFP_KERNEL);
555 + qsdev->input_buf = devm_kzalloc(qsdev->dev,
556 + HIDSPI_INPUT_BODY_SIZE(max_input_len), GFP_KERNEL);
556 557 if (!qsdev->input_buf)
557 558 return -ENOMEM;
558 559
modified drivers/i2c/busses/i2c-at91-master.c
@@ -921,8 +921,14 @@ int at91_twi_probe_master(struct platform_device *pdev,
921 921 at91_calc_twi_clock(dev);
922 922
923 923 rc = at91_init_twi_recovery_info(pdev, dev);
924 - if (rc == -EPROBE_DEFER)
924 + if (rc == -EPROBE_DEFER) {
925 + /*
926 + * The DMA channels were already set up above, release them
927 + * before deferring the probe so they are not leaked.
928 + */
929 + at91_twi_dma_release(dev);
925 930 return rc;
931 + }
926 932
927 933 dev->adapter.algo = &at91_twi_algorithm;
928 934 dev->adapter.quirks = &at91_twi_quirks;
modified drivers/i2c/busses/i2c-xiic.c
@@ -73,6 +73,9 @@ enum i2c_scl_freq {
73 73 * @prev_msg_tx: Previous message is Tx
74 74 * @quirks: To hold platform specific bug info
75 75 * @smbus_block_read: Flag to handle block read
76 + * @smbus_actual_len: Valid byte count (length + payload + optional PEC) of a
77 + * padded SMBus block read. msg->len is trimmed to this on completion.
78 + * Zero when no trimming is needed.
76 79 * @input_clk: Input clock to I2C controller
77 80 * @i2c_clk: I2C SCL frequency
78 81 * @atomic: Mode of transfer
@@ -98,6 +101,7 @@ struct xiic_i2c {
98 101 bool prev_msg_tx;
99 102 u32 quirks;
100 103 bool smbus_block_read;
104 + unsigned int smbus_actual_len;
101 105 unsigned long input_clk;
102 106 unsigned int i2c_clk;
103 107 bool atomic;
@@ -539,30 +543,38 @@ static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c)
539 543
540 544 /* Check if received length is valid */
541 545 if (rxmsg_len <= I2C_SMBUS_BLOCK_MAX) {
546 + unsigned int pec_len = i2c->rx_msg->len - 1;
547 +
542 548 /* Set Receive fifo depth */
543 - if (rxmsg_len > IIC_RX_FIFO_DEPTH) {
549 + if (rxmsg_len + pec_len > IIC_RX_FIFO_DEPTH) {
544 550 /*
545 - * When Rx msg len greater than or equal to Rx fifo capacity
546 - * Receive fifo depth should set to Rx fifo capacity minus 1
551 + * Trailing bytes (payload plus any PEC) exceed Rx FIFO
552 + * capacity, so drain in chunks. This also keeps the
553 + * else branch below from pushing rfd_set past the
554 + * 4-bit XIIC_RFD_REG_OFFSET field.
547 555 */
548 556 rfd_set = IIC_RX_FIFO_DEPTH - 1;
549 - i2c->rx_msg->len = rxmsg_len + 1;
550 - } else if ((rxmsg_len == 1) ||
551 - (rxmsg_len == 0)) {
557 + i2c->rx_msg->len = rxmsg_len + 1 + pec_len;
558 + } else if (1 + rxmsg_len + pec_len < SMBUS_BLOCK_READ_MIN_LEN) {
552 559 /*
553 - * Minimum of 3 bytes required to exit cleanly. 1 byte
554 - * already received, Second byte is being received. Have
555 - * to set NACK in read_rx before receiving the last byte
560 + * The HW needs SMBUS_BLOCK_READ_MIN_LEN bytes on the
561 + * bus to exit cleanly: by the time the ISR reads the
562 + * length byte the second byte is already being clocked
563 + * in, too late to NACK. Pad the drain target and record
564 + * the real length, trimmed back on completion so the
565 + * PEC check sees the right byte.
556 566 */
557 567 rfd_set = 0;
558 568 i2c->rx_msg->len = SMBUS_BLOCK_READ_MIN_LEN;
569 + i2c->smbus_actual_len = 1 + rxmsg_len + pec_len;
559 570 } else {
560 571 /*
561 - * When Rx msg len less than Rx fifo capacity
562 - * Receive fifo depth should set to Rx msg len minus 2
572 + * All trailing bytes fit in the Rx FIFO. Defer RX_FULL
573 + * until every one of them is buffered, so the drain
574 + * takes xiic_read_rx()'s bytes_rem == 0 path.
563 575 */
564 - rfd_set = rxmsg_len - 2;
565 - i2c->rx_msg->len = rxmsg_len + 1;
576 + rfd_set = rxmsg_len + pec_len - 1;
577 + i2c->rx_msg->len = rxmsg_len + 1 + pec_len;
566 578 }
567 579 xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set);
568 580
@@ -575,6 +587,16 @@ static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c)
575 587 dev_err(i2c->adap.dev.parent, "smbus_block_read Invalid msg length\n");
576 588 }
577 589
590 + /*
591 + * Undo the setup-time padding of a short SMBus block read before rx_msg is
592 + * cleared, so the PEC check sees the right byte.
593 + */
594 + static void xiic_smbus_trim_len(struct xiic_i2c *i2c)
595 + {
596 + if (i2c->rx_msg && i2c->smbus_actual_len)
597 + i2c->rx_msg->len = i2c->smbus_actual_len;
598 + }
599 +
578 600 static void xiic_read_rx(struct xiic_i2c *i2c)
579 601 {
580 602 u8 bytes_in_fifo, cr = 0, bytes_to_read = 0;
@@ -797,6 +819,8 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
797 819
798 820 xiic_read_rx(i2c);
799 821 if (xiic_rx_space(i2c) == 0) {
822 + xiic_smbus_trim_len(i2c);
823 +
800 824 /* this is the last part of the message */
801 825 i2c->rx_msg = NULL;
802 826
@@ -865,8 +889,11 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
865 889
866 890 if (i2c->tx_msg && i2c->smbus_block_read) {
867 891 i2c->smbus_block_read = false;
868 - /* Set requested message len=1 to indicate STATE_DONE */
869 - i2c->tx_msg->len = 1;
892 + /*
893 + * Drive xiic_tx_space() to 0 to signal STATE_DONE
894 + * without truncating the rx_msg length.
895 + */
896 + i2c->tx_pos = i2c->tx_msg->len;
870 897 }
871 898
872 899 if (!i2c->tx_msg)
@@ -938,6 +965,7 @@ static void xiic_recv_atomic(struct xiic_i2c *i2c)
938 965 return;
939 966 }
940 967
968 + xiic_smbus_trim_len(i2c);
941 969 i2c->rx_msg = NULL;
942 970 xiic_irq_clr_en(i2c, XIIC_INTR_TX_ERROR_MASK);
943 971
@@ -955,6 +983,9 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
955 983 u8 cr = 0, rfd_set = 0;
956 984 struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg;
957 985
986 + /* A stale value from an aborted block read would truncate this msg. */
987 + i2c->smbus_actual_len = 0;
988 +
958 989 if (!i2c->atomic)
959 990 dev_dbg(i2c->adap.dev.parent, "%s entry, ISR: 0x%x, CR: 0x%x\n",
960 991 __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET),
modified drivers/iio/accel/kionix-kx022a.c
@@ -649,7 +649,7 @@ static int kx022a_read_raw(struct iio_dev *idev,
649 649 if (ret)
650 650 return ret;
651 651
652 - if ((regval & KX022A_MASK_ODR) >
652 + if ((regval & KX022A_MASK_ODR) >=
653 653 ARRAY_SIZE(kx022a_accel_samp_freq_table)) {
654 654 dev_err(data->dev, "Invalid ODR\n");
655 655 return -EINVAL;
@@ -980,26 +980,44 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
980 980 guard(mutex)(&data->mutex);
981 981 ret = __kx022a_turn_on_off(data, false);
982 982 if (ret)
983 - return ret;
983 + goto err_free_out;
984 984
985 985 /* Update watermark to HW */
986 986 ret = kx022a_fifo_set_wmi(data);
987 987 if (ret)
988 - return ret;
988 + goto err_turn_on_out;
989 989
990 990 /* Enable buffer */
991 991 ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
992 992 KX022A_MASK_BUF_EN);
993 993 if (ret)
994 - return ret;
994 + goto err_turn_on_out;
995 995
996 996 data->state |= KX022A_STATE_FIFO;
997 997 ret = regmap_set_bits(data->regmap, data->ien_reg,
998 998 KX022A_MASK_WMI);
999 999 if (ret)
1000 - return ret;
1000 + goto err_buf_disable_out;
1001 1001
1002 - return __kx022a_turn_on_off(data, true);
1002 + ret = __kx022a_turn_on_off(data, true);
1003 + if (ret)
1004 + goto err_wmi_clear_out;
1005 +
1006 + return ret;
1007 +
1008 + err_wmi_clear_out:
1009 + regmap_clear_bits(data->regmap, data->ien_reg,
1010 + KX022A_MASK_WMI);
1011 + err_buf_disable_out:
1012 + regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
1013 + KX022A_MASK_BUF_EN);
1014 + data->state &= ~KX022A_STATE_FIFO;
1015 + err_turn_on_out:
1016 + __kx022a_turn_on_off(data, true);
1017 + err_free_out:
1018 + kfree(data->fifo_buffer);
1019 +
1020 + return ret;
1003 1021 }
1004 1022
1005 1023 static int kx022a_buffer_postenable(struct iio_dev *idev)
modified drivers/iio/accel/kxcjk-1013.c
@@ -1030,7 +1030,7 @@ static int kxcjk1013_write_event_config(struct iio_dev *indio_dev,
1030 1030 struct kxcjk1013_data *data = iio_priv(indio_dev);
1031 1031 int ret;
1032 1032
1033 - if (state && data->ev_enable_state)
1033 + if (state == data->ev_enable_state)
1034 1034 return 0;
1035 1035
1036 1036 mutex_lock(&data->mutex);
modified drivers/iio/accel/sca3000.c
@@ -638,7 +638,7 @@ static int sca3000_write_raw_samp_freq(struct sca3000_state *st, int val)
638 638
639 639 if (val == base_freq / 2)
640 640 ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_2;
641 - if (val == base_freq / 4)
641 + else if (val == base_freq / 4)
642 642 ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_4;
643 643 else if (val != base_freq)
644 644 return -EINVAL;
modified drivers/iio/adc/ad4030.c
@@ -746,14 +746,21 @@ static int ad4030_set_chan_calibbias(struct iio_dev *indio_dev,
746 746 static int ad4030_set_avg_frame_len(struct iio_dev *dev, int avg_val)
747 747 {
748 748 struct ad4030_state *st = iio_priv(dev);
749 - unsigned int avg_log2 = ilog2(avg_val);
750 749 unsigned int last_avg_idx = ARRAY_SIZE(ad4030_average_modes) - 1;
750 + unsigned int avg_log2;
751 751 int freq_hz;
752 752 int ret;
753 753
754 - if (avg_val < 0 || avg_val > ad4030_average_modes[last_avg_idx])
754 + /* Reject unsupported modes */
755 + if (avg_val > ad4030_average_modes[last_avg_idx])
756 + return -EINVAL;
757 +
758 + /* Avoid invalid values for logarithm since it's undefined */
759 + if (avg_val < 1)
755 760 return -EINVAL;
756 761
762 + avg_log2 = ilog2(avg_val);
763 +
757 764 if (st->offload_trigger) {
758 765 /*
759 766 * The sample averaging and sampling frequency configurations
modified drivers/iio/adc/ad7173.c
@@ -775,9 +775,9 @@ static int ad7173_load_config(struct ad7173_state *st,
775 775
776 776 return ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(free_cfg_slot), 2,
777 777 FIELD_PREP(AD7173_FILTER_SINC3_MAP, 0) |
778 - FIELD_PREP(AD7173_FILTER_ENHFILT_MASK,
779 - post_filter_enable) |
780 778 FIELD_PREP(AD7173_FILTER_ENHFILTEN,
779 + post_filter_enable) |
780 + FIELD_PREP(AD7173_FILTER_ENHFILT_MASK,
781 781 post_filter_select) |
782 782 FIELD_PREP(AD7173_FILTER_ORDER, 0) |
783 783 FIELD_PREP(AD7173_FILTER_ODR_MASK,
modified drivers/iio/adc/ad_sigma_delta.c
@@ -498,7 +498,6 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
498 498 const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
499 499 struct spi_transfer *xfer = sigma_delta->sample_xfer;
500 500 unsigned int i, slot, channel;
501 - u8 *samples_buf;
502 501 int ret;
503 502
504 503 if (sigma_delta->num_slots == 1) {
@@ -530,7 +529,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
530 529 xfer[1].bits_per_word = scan_type->realbits;
531 530 xfer[1].len = spi_bpw_to_bytes(scan_type->realbits);
532 531 } else {
533 - unsigned int samples_buf_size, scan_size;
532 + unsigned int scan_size;
534 533
535 534 if (sigma_delta->active_slots > 1) {
536 535 ret = ad_sigma_delta_append_status(sigma_delta, true);
@@ -538,17 +537,6 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
538 537 return ret;
539 538 }
540 539
541 - samples_buf_size =
542 - ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits),
543 - sizeof(s64));
544 - samples_buf_size += sizeof(s64);
545 - samples_buf = devm_krealloc(&sigma_delta->spi->dev,
546 - sigma_delta->samples_buf,
547 - samples_buf_size, GFP_KERNEL);
548 - if (!samples_buf)
549 - return -ENOMEM;
550 -
551 - sigma_delta->samples_buf = samples_buf;
552 540 scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
553 541 /* For 24-bit data, there is an extra byte of padding. */
554 542 xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
@@ -855,6 +843,23 @@ int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indi
855 843
856 844 indio_dev->setup_ops = &ad_sd_buffer_setup_ops;
857 845 } else {
846 + const struct iio_scan_type *scan_type =
847 + &indio_dev->channels[0].scan_type;
848 + unsigned int samples_buf_size;
849 +
850 + /*
851 + * Worst-case size: all sequencer slots can be active, capped
852 + * at num_slots by ad_sd_validate_scan_mask().
853 + */
854 + samples_buf_size =
855 + ALIGN(sigma_delta->num_slots *
856 + BITS_TO_BYTES(scan_type->storagebits),
857 + sizeof(s64));
858 + samples_buf_size += sizeof(s64);
859 + sigma_delta->samples_buf = devm_kzalloc(dev, samples_buf_size, GFP_KERNEL);
860 + if (!sigma_delta->samples_buf)
861 + return -ENOMEM;
862 +
858 863 ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
859 864 &iio_pollfunc_store_time,
860 865 &ad_sd_trigger_handler,
modified drivers/iio/adc/ade9000.c
@@ -219,7 +219,7 @@
219 219 #define ADE9000_ST1_ERROR2_BIT BIT(30)
220 220 #define ADE9000_ST1_ERROR3_BIT BIT(31)
221 221 #define ADE9000_ST1_CROSSING_FIRST 6
222 - #define ADE9000_ST1_CROSSING_DEPTH 25
222 + #define ADE9000_ST1_CROSSING_DEPTH 26
223 223
224 224 #define ADE9000_WFB_TRG_DIP_BIT BIT(0)
225 225 #define ADE9000_WFB_TRG_SWELL_BIT BIT(1)
@@ -444,7 +444,7 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
444 444 BIT(IIO_CHAN_INFO_CALIBSCALE), \
445 445 .event_spec = ade9000_current_events, \
446 446 .num_event_specs = ARRAY_SIZE(ade9000_current_events), \
447 - .scan_index = num, \
447 + .scan_index = num * 2, \
448 448 .indexed = 1, \
449 449 .scan_type = { \
450 450 .sign = 's', \
@@ -464,7 +464,7 @@ static const struct iio_chan_spec_ext_info ade9000_ext_info[] = {
464 464 BIT(IIO_CHAN_INFO_FREQUENCY), \
465 465 .event_spec = ade9000_voltage_events, \
466 466 .num_event_specs = ARRAY_SIZE(ade9000_voltage_events), \
467 - .scan_index = num + 1, /* interleave with current channels */ \
467 + .scan_index = num * 2 + 1, /* interleave with current channels */ \
468 468 .indexed = 1, \
469 469 .scan_type = { \
470 470 .sign = 's', \
@@ -1647,8 +1647,9 @@ static int ade9000_setup_clkout(struct device *dev, struct ade9000_state *st)
1647 1647 return 0;
1648 1648
1649 1649 /* CLKOUT passes through CLKIN with divider of 1 */
1650 - clkout_hw = devm_clk_hw_register_divider(dev, "clkout", __clk_get_name(st->clkin),
1651 - CLK_SET_RATE_PARENT, NULL, 0, 1, 0, NULL);
1650 + clkout_hw = devm_clk_hw_register_fixed_factor(dev, "clkout",
1651 + __clk_get_name(st->clkin),
1652 + CLK_SET_RATE_PARENT, 1, 1);
1652 1653 if (IS_ERR(clkout_hw))
1653 1654 return dev_err_probe(dev, PTR_ERR(clkout_hw), "Failed to register clkout");
1654 1655
@@ -1705,18 +1706,6 @@ static int ade9000_probe(struct spi_device *spi)
1705 1706 if (ret)
1706 1707 return ret;
1707 1708
1708 - ret = ade9000_request_irq(dev, "irq0", ade9000_irq0_thread, indio_dev);
1709 - if (ret)
1710 - return ret;
1711 -
1712 - ret = ade9000_request_irq(dev, "irq1", ade9000_irq1_thread, indio_dev);
1713 - if (ret)
1714 - return ret;
1715 -
1716 - ret = ade9000_request_irq(dev, "dready", ade9000_dready_thread, indio_dev);
1717 - if (ret)
1718 - return ret;
1719 -
1720 1709 /* External CMOS clock input (optional - crystal can be used instead) */
1721 1710 st->clkin = devm_clk_get_optional_enabled(dev, NULL);
1722 1711 if (IS_ERR(st->clkin))
@@ -1736,6 +1725,19 @@ static int ade9000_probe(struct spi_device *spi)
1736 1725 return dev_err_probe(&spi->dev, ret,
1737 1726 "Failed to get and enable vdd regulator\n");
1738 1727
1728 + /* Request IRQs only after powering the chip; the handlers do SPI access. */
1729 + ret = ade9000_request_irq(dev, "irq0", ade9000_irq0_thread, indio_dev);
1730 + if (ret)
1731 + return ret;
1732 +
1733 + ret = ade9000_request_irq(dev, "irq1", ade9000_irq1_thread, indio_dev);
1734 + if (ret)
1735 + return ret;
1736 +
1737 + ret = ade9000_request_irq(dev, "dready", ade9000_dready_thread, indio_dev);
1738 + if (ret)
1739 + return ret;
1740 +
1739 1741 indio_dev->channels = ade9000_channels;
1740 1742 indio_dev->num_channels = ARRAY_SIZE(ade9000_channels);
1741 1743
modified drivers/iio/adc/adi-axi-adc.c
@@ -714,6 +714,10 @@ static int adi_axi_adc_probe(struct platform_device *pdev)
714 714 if (!st)
715 715 return -ENOMEM;
716 716
717 + ret = devm_mutex_init(dev, &st->lock);
718 + if (ret)
719 + return ret;
720 +
717 721 base = devm_platform_ioremap_resource(pdev, 0);
718 722 if (IS_ERR(base))
719 723 return PTR_ERR(base);
modified drivers/iio/adc/aspeed_adc.c
@@ -585,7 +585,9 @@ static int aspeed_adc_probe(struct platform_device *pdev)
585 585 return dev_err_probe(dev, PTR_ERR(data->rst),
586 586 "invalid or missing reset controller device tree entry");
587 587
588 - reset_control_deassert(data->rst);
588 + ret = reset_control_deassert(data->rst);
589 + if (ret)
590 + return ret;
589 591
590 592 ret = devm_add_action_or_reset(dev, aspeed_adc_reset_assert, data->rst);
591 593 if (ret)
modified drivers/iio/adc/axp288_adc.c
@@ -207,6 +207,14 @@ static const struct dmi_system_id axp288_adc_ts_bias_override[] = {
207 207 },
208 208 .driver_data = (void *)(uintptr_t)AXP288_ADC_TS_BIAS_80UA,
209 209 },
210 + {
211 + /* Haier HV103H */
212 + .matches = {
213 + DMI_MATCH(DMI_SYS_VENDOR, "Haier"),
214 + DMI_MATCH(DMI_PRODUCT_NAME, "HV103H"),
215 + },
216 + .driver_data = (void *)(uintptr_t)AXP288_ADC_TS_BIAS_80UA,
217 + },
210 218 { }
211 219 };
212 220
modified drivers/iio/adc/max1363.c
@@ -404,6 +404,14 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
404 404
405 405 data = rxbuf[0];
406 406 }
407 +
408 + /*
409 + * Differential channels are bipolar and the device returns the sample
410 + * in two's complement, so sign-extend it from the resolution bit.
411 + */
412 + if (chan->differential)
413 + data = sign_extend32(data, st->chip_info->bits - 1);
414 +
407 415 *val = data;
408 416
409 417 return 0;
modified drivers/iio/adc/pac1934.c
@@ -1108,6 +1108,10 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
1108 1108 devm_kmemdup(dev, rez->package.elements[i].string.pointer,
1109 1109 (size_t)rez->package.elements[i].string.length + 1,
1110 1110 GFP_KERNEL);
1111 + if (!info->labels[idx]) {
1112 + ACPI_FREE(rez);
1113 + return -ENOMEM;
1114 + }
1111 1115 info->labels[idx][rez->package.elements[i].string.length] = '\0';
1112 1116 info->shunts[idx] = rez->package.elements[i + 1].integer.value * 1000;
1113 1117 info->active_channels[idx] = (info->shunts[idx] != 0);
modified drivers/iio/adc/rohm-bd79124.c
@@ -200,7 +200,7 @@ static int bd79124gpo_set_multiple(struct gpio_chip *gc, unsigned long *mask,
200 200 if (ret)
201 201 return ret;
202 202
203 - if (all_gpos ^ *mask) {
203 + if (*mask & ~all_gpos) {
204 204 dev_dbg(data->dev, "Invalid mux config. Can't set value.\n");
205 205
206 206 return -EINVAL;
@@ -381,6 +381,9 @@ static int bd79124_start_measurement(struct bd79124_data *data, int chan)
381 381
382 382 /* See if already started */
383 383 ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &val);
384 + if (ret)
385 + return ret;
386 +
384 387 if (val & BIT(chan))
385 388 return 0;
386 389
@@ -420,11 +423,16 @@ static int bd79124_stop_measurement(struct bd79124_data *data, int chan)
420 423
421 424 /* See if already stopped */
422 425 ret = regmap_read(data->map, BD79124_REG_AUTO_CHANNELS, &enabled_chans);
426 + if (ret)
427 + return ret;
428 +
423 429 if (!(enabled_chans & BIT(chan)))
424 430 return 0;
425 431
426 432 ret = regmap_clear_bits(data->map, BD79124_REG_SEQ_CFG,
427 433 BD79124_MSK_SEQ_START);
434 + if (ret)
435 + return ret;
428 436
429 437 /* Clear the channel from the measured channels */
430 438 enabled_chans &= ~BIT(chan);
@@ -524,7 +532,7 @@ static int bd79124_enable_event(struct bd79124_data *data,
524 532 return ret;
525 533
526 534 if (dir == IIO_EV_DIR_RISING) {
527 - limit = &data->alarm_f_limit[channel];
535 + limit = &data->alarm_r_limit[channel];
528 536 reg = BD79124_GET_HIGH_LIMIT_REG(channel);
529 537 } else {
530 538 limit = &data->alarm_f_limit[channel];
@@ -919,13 +927,13 @@ static int bd79124_chan_init(struct bd79124_data *data, int channel)
919 927 {
920 928 int ret;
921 929
922 - ret = regmap_write(data->map, BD79124_GET_HIGH_LIMIT_REG(channel),
923 - BD79124_HIGH_LIMIT_MAX);
930 + ret = bd79124_write_int_to_reg(data, BD79124_GET_HIGH_LIMIT_REG(channel),
931 + BD79124_HIGH_LIMIT_MAX);
924 932 if (ret)
925 933 return ret;
926 934
927 - return regmap_write(data->map, BD79124_GET_LOW_LIMIT_REG(channel),
928 - BD79124_LOW_LIMIT_MIN);
935 + return bd79124_write_int_to_reg(data, BD79124_GET_LOW_LIMIT_REG(channel),
936 + BD79124_LOW_LIMIT_MIN);
929 937 }
930 938
931 939 static int bd79124_get_gpio_pins(const struct iio_chan_spec *cs, int num_channels)
modified drivers/iio/adc/stm32-adc.c
@@ -1608,11 +1608,16 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
1608 1608 ret = stm32_adc_single_conv(indio_dev, chan, val);
1609 1609 else
1610 1610 ret = -EINVAL;
1611 + iio_device_release_direct(indio_dev);
1612 + if (ret < 0)
1613 + return ret;
1611 1614
1612 - if (mask == IIO_CHAN_INFO_PROCESSED)
1615 + if (mask == IIO_CHAN_INFO_PROCESSED) {
1616 + if (*val == 0)
1617 + return -EINVAL;
1613 1618 *val = STM32_ADC_VREFINT_VOLTAGE * adc->vrefint.vrefint_cal / *val;
1619 + }
1614 1620
1615 - iio_device_release_direct(indio_dev);
1616 1621 return ret;
1617 1622
1618 1623 case IIO_CHAN_INFO_SCALE:
@@ -2263,33 +2268,37 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
2263 2268
2264 2269 for (i = 0; i < STM32_ADC_INT_CH_NB; i++) {
2265 2270 if (!strncmp(stm32_adc_ic[i].name, ch_name, STM32_ADC_CH_SZ)) {
2271 + bool na;
2272 +
2266 2273 /* Check internal channel availability */
2267 2274 switch (i) {
2268 2275 case STM32_ADC_INT_CH_VDDCORE:
2269 - if (!adc->cfg->regs->or_vddcore.reg)
2270 - dev_warn(&indio_dev->dev,
2271 - "%s channel not available\n", ch_name);
2276 + na = !adc->cfg->regs->or_vddcore.reg;
2272 2277 break;
2273 2278 case STM32_ADC_INT_CH_VDDCPU:
2274 - if (!adc->cfg->regs->or_vddcpu.reg)
2275 - dev_warn(&indio_dev->dev,
2276 - "%s channel not available\n", ch_name);
2279 + na = !adc->cfg->regs->or_vddcpu.reg;
2277 2280 break;
2278 2281 case STM32_ADC_INT_CH_VDDQ_DDR:
2279 - if (!adc->cfg->regs->or_vddq_ddr.reg)
2280 - dev_warn(&indio_dev->dev,
2281 - "%s channel not available\n", ch_name);
2282 + na = !adc->cfg->regs->or_vddq_ddr.reg;
2282 2283 break;
2283 2284 case STM32_ADC_INT_CH_VREFINT:
2284 - if (!adc->cfg->regs->ccr_vref.reg)
2285 - dev_warn(&indio_dev->dev,
2286 - "%s channel not available\n", ch_name);
2285 + na = !adc->cfg->regs->ccr_vref.reg;
2287 2286 break;
2288 2287 case STM32_ADC_INT_CH_VBAT:
2289 - if (!adc->cfg->regs->ccr_vbat.reg)
2290 - dev_warn(&indio_dev->dev,
2291 - "%s channel not available\n", ch_name);
2288 + na = !adc->cfg->regs->ccr_vbat.reg;
2292 2289 break;
2290 + default:
2291 + return -EINVAL;
2292 + }
2293 +
2294 + if (na) {
2295 + /*
2296 + * Channel label matches an internal STM32 ADC channel.
2297 + * Warn about it, as there's normally no restriction on the
2298 + * name but that's not among available internal channels.
2299 + */
2300 + dev_warn(&indio_dev->dev, "no %s internal channel\n", ch_name);
2301 + return 0;
2293 2302 }
2294 2303
2295 2304 if (stm32_adc_ic[i].idx != STM32_ADC_INT_CH_VREFINT) {
modified drivers/iio/adc/sun4i-gpadc-iio.c
@@ -638,10 +638,10 @@ static int sun4i_gpadc_probe(struct platform_device *pdev)
638 638 * thermal because no thermal DT node is found.
639 639 */
640 640 if (IS_ERR(info->tzd) && PTR_ERR(info->tzd) != -ENODEV) {
641 - dev_err(&pdev->dev,
642 - "could not register thermal sensor: %ld\n",
643 - PTR_ERR(info->tzd));
644 - return PTR_ERR(info->tzd);
641 + ret = dev_err_probe(&pdev->dev,
642 + PTR_ERR(info->tzd),
643 + "could not register thermal sensor\n");
644 + goto err_map;
645 645 }
646 646 }
647 647
@@ -657,7 +657,6 @@ err_map:
657 657 if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF))
658 658 iio_map_array_unregister(indio_dev);
659 659
660 - pm_runtime_put(&pdev->dev);
661 660 pm_runtime_disable(&pdev->dev);
662 661
663 662 return ret;
@@ -668,7 +667,6 @@ static void sun4i_gpadc_remove(struct platform_device *pdev)
668 667 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
669 668 struct sun4i_gpadc_iio *info = iio_priv(indio_dev);
670 669
671 - pm_runtime_put(&pdev->dev);
672 670 pm_runtime_disable(&pdev->dev);
673 671
674 672 if (!IS_ENABLED(CONFIG_THERMAL_OF))
modified drivers/iio/adc/xilinx-xadc-core.c
@@ -1401,13 +1401,14 @@ static int xadc_probe(struct platform_device *pdev)
1401 1401 }
1402 1402
1403 1403 if (irq > 0) {
1404 - ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler,
1405 - 0, dev_name(dev), indio_dev);
1404 + /* Clear out any work queued by the interrupt */
1405 + ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work,
1406 + &xadc->zynq_unmask_work);
1406 1407 if (ret)
1407 1408 return ret;
1408 1409
1409 - ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work,
1410 - &xadc->zynq_unmask_work);
1410 + ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler,
1411 + 0, dev_name(dev), indio_dev);
1411 1412 if (ret)
1412 1413 return ret;
1413 1414 }
modified drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -104,10 +104,13 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
104 104 if (block->sg_table) {
105 105 unsigned long flags;
106 106
107 - sgl = block->sg_table->sgl;
108 - nents = sg_nents_for_len(sgl, block->bytes_used);
109 - if (nents < 0)
110 - return nents;
107 + /*
108 + * Only the first sgt->nents entries carry a valid
109 + * sg_dma_address()/sg_dma_len() pair as mapping the table may
110 + * have coalesced entries, in which case nents is smaller than
111 + * orig_nents.
112 + */
113 + nents = block->sg_table->nents;
111 114
112 115 vecs = kmalloc_objs(*vecs, nents, GFP_ATOMIC);
113 116 if (!vecs)
@@ -115,7 +118,8 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
115 118
116 119 len_total = block->bytes_used;
117 120
118 - for (i = 0; i < nents; i++) {
121 + sgl = block->sg_table->sgl;
122 + for (i = 0; i < nents && len_total; i++) {
119 123 vecs[i].addr = sg_dma_address(sgl);
120 124 vecs[i].len = min(sg_dma_len(sgl), len_total);
121 125 len_total -= vecs[i].len;
@@ -123,6 +127,8 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
123 127 sgl = sg_next(sgl);
124 128 }
125 129
130 + nents = i;
131 +
126 132 if (block->cyclic)
127 133 flags = DMA_PREP_REPEAT;
128 134 else
modified drivers/iio/cdc/ad7150.c
@@ -636,11 +636,13 @@ static const struct i2c_device_id ad7150_id[] = {
636 636 MODULE_DEVICE_TABLE(i2c, ad7150_id);
637 637
638 638 static const struct of_device_id ad7150_of_match[] = {
639 - { "adi,ad7150" },
640 - { "adi,ad7151" },
641 - { "adi,ad7156" },
639 + { .compatible = "adi,ad7150" },
640 + { .compatible = "adi,ad7151" },
641 + { .compatible = "adi,ad7156" },
642 642 { }
643 643 };
644 + MODULE_DEVICE_TABLE(of, ad7150_of_match);
645 +
644 646 static struct i2c_driver ad7150_driver = {
645 647 .driver = {
646 648 .name = "ad7150",
modified drivers/iio/common/inv_sensors/inv_sensors_timestamp.c
@@ -167,11 +167,16 @@ void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts,
167 167 valid = inv_validate_period(ts, period);
168 168 }
169 169
170 - /* if interrupt interval is valid, sync with interrupt timestamp */
170 + /*
171 + * If interrupt interval is valid, sync with interrupt timestamp.
172 + * Otherwise, use estimated value while ensuring interrupt timestamp
173 + * remains the maximum possible value.
174 + */
175 + period = inv_align_timestamp_it(ts, sample_nb);
171 176 if (valid)
172 - ts->period = inv_align_timestamp_it(ts, sample_nb);
177 + ts->period = period;
173 178 else
174 - ts->period = ts->mult * ts->chip_period.val;
179 + ts->period = min(ts->mult * ts->chip_period.val, period);
175 180 }
176 181 EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_interrupt, "IIO_INV_SENSORS_TIMESTAMP");
177 182
modified drivers/iio/dac/mcp47a1.c
@@ -26,7 +26,7 @@ struct mcp47a1_data {
26 26 int vref_mV;
27 27 };
28 28
29 - static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS - 1 };
29 + static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS };
30 30
31 31 static const struct iio_chan_spec mcp47a1_channel = {
32 32 .type = IIO_VOLTAGE,
@@ -46,7 +46,7 @@ static int mcp47a1_write(struct iio_dev *indio_dev,
46 46
47 47 switch (mask) {
48 48 case IIO_CHAN_INFO_RAW:
49 - if (!in_range(val, 0, MCP47A1_MAX_STEPS))
49 + if (!in_range(val, 0, MCP47A1_MAX_STEPS + 1))
50 50 return -EINVAL;
51 51
52 52 return i2c_smbus_write_byte_data(data->client, MCP47A1_CMD_CODE,
modified drivers/iio/dac/rohm-bd79703.c
@@ -73,6 +73,9 @@ static int bd79703_write_raw(struct iio_dev *idev,
73 73 {
74 74 struct bd79703_data *data = iio_priv(idev);
75 75
76 + if (mask != IIO_CHAN_INFO_RAW)
77 + return -EINVAL;
78 +
76 79 if (val < 0 || val >= 1 << BD79703_DAC_BITS)
77 80 return -EINVAL;
78 81
modified drivers/iio/frequency/adf4377.c
@@ -988,10 +988,10 @@ static const struct clk_ops adf4377_clk_ops = {
988 988
989 989 static int adf4377_clk_register(struct adf4377_state *st)
990 990 {
991 + struct clk_parent_data parent_data = { };
991 992 struct spi_device *spi = st->spi;
992 993 struct device *dev = &spi->dev;
993 - struct clk_init_data init;
994 - struct clk_parent_data parent_data;
994 + struct clk_init_data init = { };
995 995 int ret;
996 996
997 997 if (!device_property_present(dev, "#clock-cells"))
modified drivers/iio/frequency/admv1013.c
@@ -195,7 +195,7 @@ static int admv1013_read_raw(struct iio_dev *indio_dev,
195 195
196 196 switch (info) {
197 197 case IIO_CHAN_INFO_CALIBBIAS:
198 - switch (chan->channel) {
198 + switch (chan->channel2) {
199 199 case IIO_MOD_I:
200 200 addr = ADMV1013_REG_OFFSET_ADJUST_I;
201 201 break;
@@ -601,11 +601,14 @@ static int admv1013_probe(struct spi_device *spi)
601 601 "failed to get the LO input clock\n");
602 602
603 603 st->nb.notifier_call = admv1013_freq_change;
604 - ret = devm_clk_notifier_register(dev, st->clkin, &st->nb);
604 +
605 + ret = devm_mutex_init(dev, &st->lock);
605 606 if (ret)
606 607 return ret;
607 608
608 - mutex_init(&st->lock);
609 + ret = devm_clk_notifier_register(dev, st->clkin, &st->nb);
610 + if (ret)
611 + return ret;
609 612
610 613 ret = admv1013_init(st, vcm_uv);
611 614 if (ret)
modified drivers/iio/gyro/adis16136.c
@@ -145,7 +145,7 @@ static int adis16136_debugfs_init(struct iio_dev *indio_dev)
145 145 struct adis16136 *adis16136 = iio_priv(indio_dev);
146 146 struct dentry *d = iio_get_debugfs_dentry(indio_dev);
147 147
148 - debugfs_create_file_unsafe("serial_number", 0400,
148 + debugfs_create_file("serial_number", 0400,
149 149 d, adis16136, &adis16136_serial_fops);
150 150 debugfs_create_file_unsafe("product_id", 0400,
151 151 d, adis16136, &adis16136_product_id_fops);
modified drivers/iio/health/max30102.c
@@ -290,9 +290,15 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private)
290 290 {
291 291 struct iio_dev *indio_dev = private;
292 292 struct max30102_data *data = iio_priv(indio_dev);
293 - unsigned int measurements = bitmap_weight(indio_dev->active_scan_mask,
294 - iio_get_masklength(indio_dev));
295 - int ret, cnt = 0;
293 + unsigned int measurements;
294 + int ret, cnt;
295 +
296 + cnt = max30102_fifo_count(data);
297 + if (cnt <= 0)
298 + return IRQ_HANDLED;
299 +
300 + measurements = bitmap_weight(indio_dev->active_scan_mask,
301 + iio_get_masklength(indio_dev));
296 302
297 303 mutex_lock(&data->lock);
298 304
modified drivers/iio/imu/adis16400.c
@@ -280,7 +280,7 @@ static void adis16400_debugfs_init(struct iio_dev *indio_dev)
280 280 return;
281 281
282 282 if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
283 - debugfs_create_file_unsafe("serial_number", 0400,
283 + debugfs_create_file("serial_number", 0400,
284 284 d, st, &adis16400_serial_number_fops);
285 285 if (st->variant->flags & ADIS16400_HAS_PROD_ID)
286 286 debugfs_create_file_unsafe("product_id", 0400,
modified drivers/iio/imu/adis16480.c
@@ -309,9 +309,9 @@ static void adis16480_debugfs_init(struct iio_dev *indio_dev)
309 309 if (!IS_ENABLED(CONFIG_DEBUG_FS))
310 310 return;
311 311
312 - debugfs_create_file_unsafe("firmware_revision", 0400,
312 + debugfs_create_file("firmware_revision", 0400,
313 313 d, adis16480, &adis16480_firmware_revision_fops);
314 - debugfs_create_file_unsafe("firmware_date", 0400,
314 + debugfs_create_file("firmware_date", 0400,
315 315 d, adis16480, &adis16480_firmware_date_fops);
316 316 debugfs_create_file_unsafe("serial_number", 0400,
317 317 d, adis16480, &adis16480_serial_number_fops);
modified drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
@@ -537,9 +537,8 @@ static int inv_icm42607_enable_vddio_reg(struct inv_icm42607_state *st)
537 537 return 0;
538 538 }
539 539
540 - static void inv_icm42607_sensors_off(void *_data)
540 + static int inv_icm42607_sensors_off(struct inv_icm42607_state *st)
541 541 {
542 - struct inv_icm42607_state *st = _data;
543 542 const struct device *dev = regmap_get_device(st->map);
544 543 int ret;
545 544
@@ -552,6 +551,13 @@ static void inv_icm42607_sensors_off(void *_data)
552 551 st->conf.accel.mode);
553 552 if (ret)
554 553 dev_err(dev, "Unable to turn off sensors\n");
554 +
555 + return ret;
556 + }
557 +
558 + static void inv_icm42607_sensors_off_action(void *data)
559 + {
560 + inv_icm42607_sensors_off(data);
555 561 }
556 562
557 563 static void inv_icm42607_disable_vddio_reg(void *_data)
@@ -619,7 +625,7 @@ int inv_icm42607_core_probe(struct regmap *regmap,
619 625 * Ensure if sensors get turned on at some point, they're turned off
620 626 * as part of teardown.
621 627 */
622 - ret = devm_add_action_or_reset(dev, inv_icm42607_sensors_off, st);
628 + ret = devm_add_action_or_reset(dev, inv_icm42607_sensors_off_action, st);
623 629 if (ret)
624 630 return ret;
625 631
@@ -658,9 +664,8 @@ static int inv_icm42607_suspend(struct device *dev)
658 664 return 0;
659 665 }
660 666
661 - static int inv_icm42607_resume(struct device *dev)
667 + static int inv_icm42607_resume_core(struct inv_icm42607_state *st)
662 668 {
663 - struct inv_icm42607_state *st = dev_get_drvdata(dev);
664 669 int ret;
665 670
666 671 ret = inv_icm42607_enable_vddio_reg(st);
@@ -669,9 +674,25 @@ static int inv_icm42607_resume(struct device *dev)
669 674
670 675 /* Sync the regcache again after regulator shutdown. */
671 676 regcache_mark_dirty(st->map);
672 - ret = regcache_sync(st->map);
673 - if (ret)
677 +
678 + return regcache_sync(st->map);
679 + }
680 +
681 + static int inv_icm42607_resume(struct device *dev)
682 + {
683 + struct inv_icm42607_state *st = dev_get_drvdata(dev);
684 + int ret;
685 +
686 + ret = inv_icm42607_resume_core(st);
687 + if (ret) {
688 + int rc;
689 +
690 + rc = pm_runtime_force_resume(dev);
691 + if (rc)
692 + dev_warn(dev, "Failed to restore runtime PM state: %d\n", rc);
693 +
674 694 return ret;
695 + }
675 696
676 697 return pm_runtime_force_resume(dev);
677 698 }
@@ -688,8 +709,7 @@ static int inv_icm42607_runtime_suspend(struct device *dev)
688 709 * however the tradeoff is that an unused sensor won't be
689 710 * turned off until the entire chip is no longer in use.
690 711 */
691 - inv_icm42607_sensors_off(st);
692 - return 0;
712 + return inv_icm42607_sensors_off(st);
693 713 }
694 714
695 715 EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42607_pm_ops, IIO_ICM42607) = {
modified drivers/iio/industrialio-buffer.c
@@ -1377,6 +1377,10 @@ EXPORT_SYMBOL_GPL(iio_update_buffers);
1377 1377
1378 1378 void iio_disable_all_buffers(struct iio_dev *indio_dev)
1379 1379 {
1380 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
1381 +
1382 + guard(mutex)(&iio_dev_opaque->mlock);
1383 +
1380 1384 iio_disable_buffers(indio_dev);
1381 1385 iio_buffer_deactivate_all(indio_dev);
1382 1386 }
@@ -2462,7 +2466,8 @@ int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
2462 2466
2463 2467 bb = devm_krealloc(&indio_dev->dev,
2464 2468 iio_dev_opaque->bounce_buffer,
2465 - indio_dev->scan_bytes, GFP_KERNEL);
2469 + indio_dev->scan_bytes,
2470 + GFP_KERNEL | __GFP_ZERO);
2466 2471 if (!bb)
2467 2472 return -ENOMEM;
2468 2473 iio_dev_opaque->bounce_buffer = bb;
modified drivers/iio/industrialio-trigger.c
@@ -509,6 +509,8 @@ static void iio_trig_release(struct device *device)
509 509 struct iio_trigger *trig = to_iio_trigger(device);
510 510 int i;
511 511
512 + cancel_work_sync(&trig->reenable_work);
513 +
512 514 if (trig->subirq_base) {
513 515 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
514 516 irq_modify_status(trig->subirq_base + i,
modified drivers/iio/light/gp2ap020a00f.c
@@ -1497,6 +1497,7 @@ error_trigger_unregister:
1497 1497 iio_trigger_unregister(data->trig);
1498 1498 error_free_irq:
1499 1499 free_irq(client->irq, indio_dev);
1500 + irq_work_sync(&data->work);
1500 1501 error_uninit_buffer:
1501 1502 iio_triggered_buffer_cleanup(indio_dev);
1502 1503 error_regulator_disable:
@@ -1519,6 +1520,7 @@ static void gp2ap020a00f_remove(struct i2c_client *client)
1519 1520 iio_device_unregister(indio_dev);
1520 1521 iio_trigger_unregister(data->trig);
1521 1522 free_irq(client->irq, indio_dev);
1523 + irq_work_sync(&data->work);
1522 1524 iio_triggered_buffer_cleanup(indio_dev);
1523 1525 regulator_disable(data->vled_reg);
1524 1526 }
modified drivers/iio/light/rohm-bu27034.c
@@ -137,6 +137,7 @@ static const struct iio_gain_sel_pair bu27034_gains[] = {
137 137 #define BU27034_MEAS_MODE_200MS 2
138 138 #define BU27034_MEAS_MODE_400MS 4
139 139
140 + #define BU27034_INT_TIME_US_MIN (55 * USEC_PER_MSEC)
140 141 static const struct iio_itime_sel_mul bu27034_itimes[] = {
141 142 GAIN_SCALE_ITIME_US(400000, BU27034_MEAS_MODE_400MS, 8),
142 143 GAIN_SCALE_ITIME_US(200000, BU27034_MEAS_MODE_200MS, 4),
@@ -296,7 +297,7 @@ static int bu27034_get_gain(struct bu27034_data *data, int chan, int *gain)
296 297 return 0;
297 298 }
298 299
299 - static int bu27034_get_int_time(struct bu27034_data *data)
300 + static int bu27034_get_int_time(struct bu27034_data *data, int *itime)
300 301 {
301 302 int ret, sel;
302 303
@@ -304,24 +305,30 @@ static int bu27034_get_int_time(struct bu27034_data *data)
304 305 if (ret)
305 306 return ret;
306 307
307 - return iio_gts_find_int_time_by_sel(&data->gts,
308 - sel & BU27034_MASK_MEAS_MODE);
308 + ret = iio_gts_find_int_time_by_sel(&data->gts,
309 + sel & BU27034_MASK_MEAS_MODE);
310 + if (ret < 0)
311 + return ret;
312 +
313 + *itime = ret;
314 +
315 + return 0;
309 316 }
310 317
311 318 static int _bu27034_get_scale(struct bu27034_data *data, int channel, int *val,
312 319 int *val2)
313 320 {
314 - int gain, ret;
321 + int gain, itime, ret;
315 322
316 323 ret = bu27034_get_gain(data, channel, &gain);
317 324 if (ret)
318 325 return ret;
319 326
320 - ret = bu27034_get_int_time(data);
321 - if (ret < 0)
327 + ret = bu27034_get_int_time(data, &itime);
328 + if (ret)
322 329 return ret;
323 330
324 - return iio_gts_get_scale(&data->gts, gain, ret, val, val2);
331 + return iio_gts_get_scale(&data->gts, gain, itime, val, val2);
325 332 }
326 333
327 334 static int bu27034_get_scale(struct bu27034_data *data, int channel, int *val,
@@ -397,12 +404,10 @@ static int bu27034_try_set_int_time(struct bu27034_data *data, int time_us)
397 404 int ret, int_time_old, i;
398 405
399 406 guard(mutex)(&data->mutex);
400 - ret = bu27034_get_int_time(data);
401 - if (ret < 0)
407 + ret = bu27034_get_int_time(data, &int_time_old);
408 + if (ret)
402 409 return ret;
403 410
404 - int_time_old = ret;
405 -
406 411 if (!iio_gts_valid_time(&data->gts, time_us)) {
407 412 dev_err(data->dev, "Unsupported integration time %u\n",
408 413 time_us);
@@ -415,7 +420,7 @@ static int bu27034_try_set_int_time(struct bu27034_data *data, int time_us)
415 420 for (i = 0; i < numg; i++) {
416 421 ret = bu27034_get_gain(data, gains[i].chan, &gains[i].old_gain);
417 422 if (ret)
418 - return 0;
423 + return ret;
419 424
420 425 ret = iio_gts_find_new_gain_by_old_gain_time(&data->gts,
421 426 gains[i].old_gain,
@@ -841,7 +846,7 @@ static int bu27034_meas_set(struct bu27034_data *data, bool en)
841 846 static int bu27034_get_single_result(struct bu27034_data *data, int chan,
842 847 int *val)
843 848 {
844 - int ret;
849 + int ret, itime;
845 850
846 851 if (chan < BU27034_CHAN_DATA0 || chan > BU27034_CHAN_DATA1)
847 852 return -EINVAL;
@@ -850,11 +855,11 @@ static int bu27034_get_single_result(struct bu27034_data *data, int chan,
850 855 if (ret)
851 856 return ret;
852 857
853 - ret = bu27034_get_int_time(data);
854 - if (ret < 0)
858 + ret = bu27034_get_int_time(data, &itime);
859 + if (ret)
855 860 return ret;
856 861
857 - msleep(ret / 1000);
862 + msleep(itime / 1000);
858 863
859 864 return bu27034_read_result(data, chan, val);
860 865 }
@@ -904,12 +909,10 @@ static int bu27034_calc_mlux(struct bu27034_data *data, __le16 *res, int *val)
904 909 if (ret)
905 910 return ret;
906 911
907 - ret = bu27034_get_int_time(data);
908 - if (ret < 0)
912 + ret = bu27034_get_int_time(data, &meastime);
913 + if (ret)
909 914 return ret;
910 915
911 - meastime = ret;
912 -
913 916 d1_d0_ratio_scaled = (unsigned int)ch1 * (unsigned int)gain0 * 100;
914 917 helper64 = (u64)ch1 * (u64)gain0 * 100LLU;
915 918
@@ -970,9 +973,9 @@ static int bu27034_read_raw(struct iio_dev *idev,
970 973 switch (mask) {
971 974 case IIO_CHAN_INFO_INT_TIME:
972 975 *val = 0;
973 - *val2 = bu27034_get_int_time(data);
974 - if (*val2 < 0)
975 - return *val2;
976 + ret = bu27034_get_int_time(data, val2);
977 + if (ret)
978 + return ret;
976 979
977 980 return IIO_VAL_INT_PLUS_MICRO;
978 981
@@ -1157,11 +1160,20 @@ static int bu27034_buffer_thread(void *arg)
1157 1160 {
1158 1161 struct iio_dev *idev = arg;
1159 1162 struct bu27034_data *data;
1160 - int wait_ms;
1163 + int wait_ms, ret;
1161 1164
1162 1165 data = iio_priv(idev);
1163 1166
1164 - wait_ms = bu27034_get_int_time(data);
1167 + /*
1168 + * If reading the integration time fails, default to the minimum so we
1169 + * don't lose samples. This may waste CPU cycles, but as a hardening
1170 + * against theoretical, once-in-a-blue-moon error, this should be Ok.
1171 + */
1172 + wait_ms = BU27034_INT_TIME_US_MIN;
1173 + ret = bu27034_get_int_time(data, &wait_ms);
1174 + if (ret)
1175 + dev_warn(data->dev, "Failed to get integration time\n");
1176 +
1165 1177 wait_ms /= 1000;
1166 1178
1167 1179 wait_ms -= BU27034_MEAS_WAIT_PREMATURE_MS;
modified drivers/iio/pressure/bmp280-core.c
@@ -839,7 +839,7 @@ static int bmp280_write_sampling_frequency(struct bmp280_data *data,
839 839 int val, int val2)
840 840 {
841 841 const int (*avail)[2] = data->chip_info->sampling_freq_avail;
842 - const int n = data->chip_info->num_sampling_freq_avail;
842 + const int n = data->chip_info->num_sampling_freq_avail / 2;
843 843 int ret, prev;
844 844 int i;
845 845
modified drivers/iio/pressure/rohm-bm1390.c
@@ -289,7 +289,7 @@ static int bm1390_read_data(struct bm1390_data *data,
289 289 if (warn)
290 290 dev_warn(data->dev, "Failed to stop measurement (%d)\n", warn);
291 291
292 - return 0;
292 + return ret;
293 293 }
294 294
295 295 static int bm1390_read_raw(struct iio_dev *idev,
modified drivers/iio/proximity/aw96103.c
@@ -24,6 +24,7 @@
24 24 #define AW96103_BIN_VALID_DATA_OFFSET 64
25 25 #define AW96103_BIN_DATA_LEN_OFFSET 16
26 26 #define AW96103_BIN_DATA_REG_NUM_SIZE 4
27 + #define AW96103_BIN_REG_SIZE 6
27 28 #define AW96103_BIN_CHIP_TYPE_SIZE 8
28 29 #define AW96103_BIN_CHIP_TYPE_OFFSET 24
29 30
@@ -229,14 +230,27 @@ static const struct aw_chip_info aw_chip_info_tbl[] = {
229 230 },
230 231 };
231 232
232 - static void aw96103_parsing_bin_file(struct aw_bin *bin)
233 + static int aw96103_parsing_bin_file(struct aw_bin *bin)
233 234 {
235 + u32 data_len;
236 +
237 + if (bin->len < AW96103_BIN_VALID_DATA_OFFSET)
238 + return -EINVAL;
239 +
240 + data_len = get_unaligned_le32(bin->data + AW96103_BIN_DATA_LEN_OFFSET);
241 + if (data_len < AW96103_BIN_DATA_REG_NUM_SIZE)
242 + return -EINVAL;
243 +
244 + bin->valid_data_len = data_len - AW96103_BIN_DATA_REG_NUM_SIZE;
245 + if (bin->valid_data_len > bin->len - AW96103_BIN_VALID_DATA_OFFSET ||
246 + bin->valid_data_len % AW96103_BIN_REG_SIZE)
247 + return -EINVAL;
248 +
234 249 bin->valid_data_addr = AW96103_BIN_VALID_DATA_OFFSET;
235 - bin->valid_data_len =
236 - *(unsigned int *)(bin->data + AW96103_BIN_DATA_LEN_OFFSET) -
237 - AW96103_BIN_DATA_REG_NUM_SIZE;
238 250 memcpy(bin->chip_type, bin->data + AW96103_BIN_CHIP_TYPE_OFFSET,
239 251 AW96103_BIN_CHIP_TYPE_SIZE);
252 +
253 + return 0;
240 254 }
241 255
242 256 static const struct regmap_config aw96103_regmap_confg = {
@@ -500,7 +514,7 @@ static int aw96103_bin_valid_loaded(struct aw96103 *aw96103,
500 514 int ret;
501 515
502 516 for (i = 0; i < aw_bin_data_s->valid_data_len;
503 - i += 6, start_addr += 6) {
517 + i += AW96103_BIN_REG_SIZE, start_addr += AW96103_BIN_REG_SIZE) {
504 518 reg_addr = get_unaligned_le16(aw_bin_data_s->data + start_addr);
505 519 reg_data = get_unaligned_le32(aw_bin_data_s->data +
506 520 start_addr + 2);
@@ -550,6 +564,8 @@ static int aw96103_para_loaded(struct aw96103 *aw96103)
550 564 static int aw96103_cfg_all_loaded(const struct firmware *cont,
551 565 struct aw96103 *aw96103)
552 566 {
567 + int ret;
568 +
553 569 if (!cont)
554 570 return -EINVAL;
555 571
@@ -561,7 +577,9 @@ static int aw96103_cfg_all_loaded(const struct firmware *cont,
561 577 aw_bin->len = cont->size;
562 578 memcpy(aw_bin->data, cont->data, cont->size);
563 579 release_firmware(cont);
564 - aw96103_parsing_bin_file(aw_bin);
580 + ret = aw96103_parsing_bin_file(aw_bin);
581 + if (ret)
582 + return ret;
565 583
566 584 return aw96103_bin_valid_loaded(aw96103, aw_bin);
567 585 }
modified drivers/iio/proximity/isl29501.c
@@ -226,7 +226,7 @@ err:
226 226 return ret;
227 227 }
228 228
229 - static u32 isl29501_register_write(struct isl29501_private *isl29501,
229 + static int isl29501_register_write(struct isl29501_private *isl29501,
230 230 enum isl29501_register_name name,
231 231 u32 value)
232 232 {
modified drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -294,12 +294,14 @@ static int lidar_probe(struct i2c_client *client)
294 294
295 295 ret = pm_runtime_set_active(&client->dev);
296 296 if (ret)
297 - goto error_unreg_buffer;
297 + goto error_unreg_dev;
298 298 pm_runtime_enable(&client->dev);
299 299 pm_runtime_idle(&client->dev);
300 300
301 301 return 0;
302 302
303 + error_unreg_dev:
304 + iio_device_unregister(indio_dev);
303 305 error_unreg_buffer:
304 306 iio_triggered_buffer_cleanup(indio_dev);
305 307
modified drivers/iio/proximity/sx9324.c
@@ -222,7 +222,7 @@ static const struct iio_chan_spec_ext_info sx9324_channel_ext_info[] = {
222 222 .scan_index = idx, \
223 223 .scan_type = { \
224 224 .sign = 's', \
225 - .realbits = 12, \
225 + .realbits = 16, \
226 226 .storagebits = 16, \
227 227 .endianness = IIO_BE, \
228 228 }, \
modified drivers/iio/proximity/vcnl3020.c
@@ -584,16 +584,26 @@ static irqreturn_t vcnl3020_handle_irq_thread(int irq, void *p)
584 584 return IRQ_HANDLED;
585 585 }
586 586
587 - if (!(isr & VCNL_ICR_THRES_EN))
587 + if (!(isr & (VCNL_INT_TH_HI | VCNL_INT_TH_LOW)))
588 588 return IRQ_NONE;
589 589
590 - iio_push_event(indio_dev,
591 - IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 1,
592 - IIO_EV_TYPE_THRESH,
593 - IIO_EV_DIR_RISING),
594 - iio_get_time_ns(indio_dev));
590 + if (isr & VCNL_INT_TH_HI) {
591 + iio_push_event(indio_dev,
592 + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
593 + IIO_EV_TYPE_THRESH,
594 + IIO_EV_DIR_RISING),
595 + iio_get_time_ns(indio_dev));
596 + }
597 +
598 + if (isr & VCNL_INT_TH_LOW) {
599 + iio_push_event(indio_dev,
600 + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
601 + IIO_EV_TYPE_THRESH,
602 + IIO_EV_DIR_FALLING),
603 + iio_get_time_ns(indio_dev));
604 + }
595 605
596 - rc = regmap_write(data->regmap, VCNL_ISR, isr & VCNL_ICR_THRES_EN);
606 + rc = regmap_write(data->regmap, VCNL_ISR, isr & (VCNL_INT_TH_HI | VCNL_INT_TH_LOW));
597 607 if (rc)
598 608 dev_err(data->dev, "Error (%d) writing in reg (0x%x)\n",
599 609 rc, VCNL_ISR);
modified drivers/iio/proximity/vl53l0x-i2c.c
@@ -219,7 +219,10 @@ static int vl53l0x_read_raw(struct iio_dev *indio_dev,
219 219
220 220 switch (mask) {
221 221 case IIO_CHAN_INFO_RAW:
222 + if (!iio_device_claim_direct(indio_dev))
223 + return -EBUSY;
222 224 ret = vl53l0x_read_proximity(data, chan, val);
225 + iio_device_release_direct(indio_dev);
223 226 if (ret < 0)
224 227 return ret;
225 228
modified drivers/input/keyboard/atkbd.c
@@ -1938,6 +1938,14 @@ static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
1938 1938 },
1939 1939 .callback = atkbd_deactivate_fixup,
1940 1940 },
1941 + {
1942 + /* Lenovo IdeaPad Slim 3 15IWC11 (83RR) */
1943 + .matches = {
1944 + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1945 + DMI_MATCH(DMI_PRODUCT_NAME, "83RR"),
1946 + },
1947 + .callback = atkbd_deactivate_fixup,
1948 + },
1941 1949 {
1942 1950 /* Xiaomi Book Pro 14 (TM2424) */
1943 1951 .matches = {
modified drivers/input/mouse/synaptics.c
@@ -192,6 +192,7 @@ static const char * const smbus_pnp_ids[] = {
192 192 "LEN2054", /* E480 */
193 193 "LEN2055", /* E580 */
194 194 "LEN2058", /* E490 */
195 + "LEN205b", /* T490 */
195 196 "LEN2068", /* T14 Gen 1 */
196 197 "SYN1221", /* TUXEDO InfinityBook Pro 14 v5 */
197 198 "SYN3003", /* HP EliteBook 850 G1 */
@@ -1839,8 +1840,10 @@ static int synaptics_setup_intertouch(struct psmouse *psmouse,
1839 1840 return -ENXIO;
1840 1841 }
1841 1842
1842 - /* Disable intertouch on known-broken board revisions */
1843 - if (info->board_id == 2722) {
1843 + /* Disable intertouch on known-broken T440p board revisions */
1844 + if (info->board_id == 2722 &&
1845 + psmouse_matches_pnp_id(psmouse,
1846 + (const char * const []){"LEN0036", NULL})) {
1844 1847 psmouse_info(psmouse,
1845 1848 "Disabling intertouch for board id %u\n",
1846 1849 info->board_id);
modified drivers/input/serio/i8042-acpipnpio.h
@@ -671,6 +671,15 @@ static const struct dmi_system_id i8042_dmi_quirk_table[] __initconst = {
671 671 },
672 672 .driver_data = (void *)(SERIO_QUIRK_NOAUX)
673 673 },
674 + {
675 + /* Fujitsu LIFEBOOK U7410 */
676 + /* Mux mode also disturbs the EC keyboard, causing spurious ACKs */
677 + .matches = {
678 + DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU CLIENT COMPUTING LIMITED"),
679 + DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK U7410"),
680 + },
681 + .driver_data = (void *)(SERIO_QUIRK_NOMUX)
682 + },
674 683 {
675 684 /* Gigabyte M912 */
676 685 .matches = {
modified drivers/input/touchscreen/s6sy761.c
@@ -500,10 +500,22 @@ static int s6sy761_suspend(struct device *dev)
500 500 static int s6sy761_resume(struct device *dev)
501 501 {
502 502 struct s6sy761_data *sdata = dev_get_drvdata(dev);
503 + int err;
504 +
505 + err = s6sy761_power_on(sdata);
506 + if (err)
507 + return err;
503 508
504 509 enable_irq(sdata->client->irq);
505 510
506 - return s6sy761_power_on(sdata);
511 + guard(mutex)(&sdata->input->mutex);
512 +
513 + if (!input_device_enabled(sdata->input))
514 + return 0;
515 +
516 + err = i2c_smbus_write_byte(sdata->client, S6SY761_SENSE_ON);
517 +
518 + return err;
507 519 }
508 520
509 521 static const struct dev_pm_ops s6sy761_pm_ops = {
modified drivers/interconnect/qcom/x1e80100.c
@@ -173,13 +173,6 @@ static struct qcom_icc_node qhm_qspi = {
173 173 .name = "qhm_qspi",
174 174 .channels = 1,
175 175 .buswidth = 4,
176 - .qosbox = &(const struct qcom_icc_qosbox) {
177 - .num_ports = 1,
178 - .port_offsets = { 0xb000 },
179 - .prio = 2,
180 - .urg_fwd = 0,
181 - .prio_fwd_disable = 1,
182 - },
183 176 .num_links = 1,
184 177 .link_nodes = { &qns_a1noc_snoc },
185 178 };
@@ -188,13 +181,6 @@ static struct qcom_icc_node qhm_qup1 = {
188 181 .name = "qhm_qup1",
189 182 .channels = 1,
190 183 .buswidth = 4,
191 - .qosbox = &(const struct qcom_icc_qosbox) {
192 - .num_ports = 1,
193 - .port_offsets = { 0xc000 },
194 - .prio = 2,
195 - .urg_fwd = 0,
196 - .prio_fwd_disable = 1,
197 - },
198 184 .num_links = 1,
199 185 .link_nodes = { &qns_a1noc_snoc },
200 186 };
@@ -203,13 +189,6 @@ static struct qcom_icc_node xm_sdc4 = {
203 189 .name = "xm_sdc4",
204 190 .channels = 1,
205 191 .buswidth = 8,
206 - .qosbox = &(const struct qcom_icc_qosbox) {
207 - .num_ports = 1,
208 - .port_offsets = { 0xd000 },
209 - .prio = 2,
210 - .urg_fwd = 0,
211 - .prio_fwd_disable = 1,
212 - },
213 192 .num_links = 1,
214 193 .link_nodes = { &qns_a1noc_snoc },
215 194 };
@@ -218,13 +197,6 @@ static struct qcom_icc_node xm_ufs_mem = {
218 197 .name = "xm_ufs_mem",
219 198 .channels = 1,
220 199 .buswidth = 16,
221 - .qosbox = &(const struct qcom_icc_qosbox) {
222 - .num_ports = 1,
223 - .port_offsets = { 0xe000 },
224 - .prio = 2,
225 - .urg_fwd = 0,
226 - .prio_fwd_disable = 1,
227 - },
228 200 .num_links = 1,
229 201 .link_nodes = { &qns_a1noc_snoc },
230 202 };
@@ -233,13 +205,6 @@ static struct qcom_icc_node qhm_qup0 = {
233 205 .name = "qhm_qup0",
234 206 .channels = 1,
235 207 .buswidth = 4,
236 - .qosbox = &(const struct qcom_icc_qosbox) {
237 - .num_ports = 1,
238 - .port_offsets = { 0x16000 },
239 - .prio = 2,
240 - .urg_fwd = 0,
241 - .prio_fwd_disable = 1,
242 - },
243 208 .num_links = 1,
244 209 .link_nodes = { &qns_a2noc_snoc },
245 210 };
@@ -248,13 +213,6 @@ static struct qcom_icc_node qhm_qup2 = {
248 213 .name = "qhm_qup2",
249 214 .channels = 1,
250 215 .buswidth = 4,
251 - .qosbox = &(const struct qcom_icc_qosbox) {
252 - .num_ports = 1,
253 - .port_offsets = { 0x11000 },
254 - .prio = 2,
255 - .urg_fwd = 0,
256 - .prio_fwd_disable = 1,
257 - },
258 216 .num_links = 1,
259 217 .link_nodes = { &qns_a2noc_snoc },
260 218 };
@@ -263,13 +221,6 @@ static struct qcom_icc_node qxm_crypto = {
263 221 .name = "qxm_crypto",
264 222 .channels = 1,
265 223 .buswidth = 8,
266 - .qosbox = &(const struct qcom_icc_qosbox) {
267 - .num_ports = 1,
268 - .port_offsets = { 0x12000 },
269 - .prio = 2,
270 - .urg_fwd = 0,
271 - .prio_fwd_disable = 1,
272 - },
273 224 .num_links = 1,
274 225 .link_nodes = { &qns_a2noc_snoc },
275 226 };
@@ -286,13 +237,6 @@ static struct qcom_icc_node xm_qdss_etr_0 = {
286 237 .name = "xm_qdss_etr_0",
287 238 .channels = 1,
288 239 .buswidth = 8,
289 - .qosbox = &(const struct qcom_icc_qosbox) {
290 - .num_ports = 1,
291 - .port_offsets = { 0x13000 },
292 - .prio = 2,
293 - .urg_fwd = 0,
294 - .prio_fwd_disable = 1,
295 - },
296 240 .num_links = 1,
297 241 .link_nodes = { &qns_a2noc_snoc },
298 242 };
@@ -301,13 +245,6 @@ static struct qcom_icc_node xm_qdss_etr_1 = {
301 245 .name = "xm_qdss_etr_1",
302 246 .channels = 1,
303 247 .buswidth = 8,
304 - .qosbox = &(const struct qcom_icc_qosbox) {
305 - .num_ports = 1,
306 - .port_offsets = { 0x14000 },
307 - .prio = 2,
308 - .urg_fwd = 0,
309 - .prio_fwd_disable = 1,
310 - },
311 248 .num_links = 1,
312 249 .link_nodes = { &qns_a2noc_snoc },
313 250 };
@@ -316,13 +253,6 @@ static struct qcom_icc_node xm_sdc2 = {
316 253 .name = "xm_sdc2",
317 254 .channels = 1,
318 255 .buswidth = 8,
319 - .qosbox = &(const struct qcom_icc_qosbox) {
320 - .num_ports = 1,
321 - .port_offsets = { 0x15000 },
322 - .prio = 2,
323 - .urg_fwd = 0,
324 - .prio_fwd_disable = 1,
325 - },
326 256 .num_links = 1,
327 257 .link_nodes = { &qns_a2noc_snoc },
328 258 };
@@ -407,13 +337,6 @@ static struct qcom_icc_node alm_gpu_tcu = {
407 337 .name = "alm_gpu_tcu",
408 338 .channels = 1,
409 339 .buswidth = 8,
410 - .qosbox = &(const struct qcom_icc_qosbox) {
411 - .num_ports = 1,
412 - .port_offsets = { 0x271000 },
413 - .prio = 1,
414 - .urg_fwd = 0,
415 - .prio_fwd_disable = 1,
416 - },
417 340 .num_links = 2,
418 341 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
419 342 };
@@ -422,13 +345,6 @@ static struct qcom_icc_node alm_pcie_tcu = {
422 345 .name = "alm_pcie_tcu",
423 346 .channels = 1,
424 347 .buswidth = 8,
425 - .qosbox = &(const struct qcom_icc_qosbox) {
426 - .num_ports = 1,
427 - .port_offsets = { 0x27d000 },
428 - .prio = 3,
429 - .urg_fwd = 0,
430 - .prio_fwd_disable = 1,
431 - },
432 348 .num_links = 2,
433 349 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
434 350 };
@@ -437,13 +353,6 @@ static struct qcom_icc_node alm_sys_tcu = {
437 353 .name = "alm_sys_tcu",
438 354 .channels = 1,
439 355 .buswidth = 8,
440 - .qosbox = &(const struct qcom_icc_qosbox) {
441 - .num_ports = 1,
442 - .port_offsets = { 0x273000 },
443 - .prio = 6,
444 - .urg_fwd = 0,
445 - .prio_fwd_disable = 1,
446 - },
447 356 .num_links = 2,
448 357 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
449 358 };
@@ -461,13 +370,6 @@ static struct qcom_icc_node qnm_gpu = {
461 370 .name = "qnm_gpu",
462 371 .channels = 4,
463 372 .buswidth = 32,
464 - .qosbox = &(const struct qcom_icc_qosbox) {
465 - .num_ports = 4,
466 - .port_offsets = { 0x51000, 0x58000, 0xd1000, 0xd8000 },
467 - .prio = 0,
468 - .urg_fwd = 0,
469 - .prio_fwd_disable = 1,
470 - },
471 373 .num_links = 2,
472 374 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
473 375 };
@@ -476,13 +378,6 @@ static struct qcom_icc_node qnm_lpass = {
476 378 .name = "qnm_lpass",
477 379 .channels = 1,
478 380 .buswidth = 16,
479 - .qosbox = &(const struct qcom_icc_qosbox) {
480 - .num_ports = 1,
481 - .port_offsets = { 0x275000 },
482 - .prio = 0,
483 - .urg_fwd = 1,
484 - .prio_fwd_disable = 0,
485 - },
486 381 .num_links = 3,
487 382 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc,
488 383 &qns_pcie },
@@ -492,13 +387,6 @@ static struct qcom_icc_node qnm_mnoc_hf = {
492 387 .name = "qnm_mnoc_hf",
493 388 .channels = 2,
494 389 .buswidth = 32,
495 - .qosbox = &(const struct qcom_icc_qosbox) {
496 - .num_ports = 2,
497 - .port_offsets = { 0x53000, 0xd3000 },
498 - .prio = 0,
499 - .urg_fwd = 1,
500 - .prio_fwd_disable = 0,
501 - },
502 390 .num_links = 2,
503 391 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
504 392 };
@@ -507,13 +395,6 @@ static struct qcom_icc_node qnm_mnoc_sf = {
507 395 .name = "qnm_mnoc_sf",
508 396 .channels = 2,
509 397 .buswidth = 32,
510 - .qosbox = &(const struct qcom_icc_qosbox) {
511 - .num_ports = 2,
512 - .port_offsets = { 0x55000, 0xd5000 },
513 - .prio = 0,
514 - .urg_fwd = 1,
515 - .prio_fwd_disable = 0,
516 - },
517 398 .num_links = 2,
518 399 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
519 400 };
@@ -522,13 +403,6 @@ static struct qcom_icc_node qnm_nsp_noc = {
522 403 .name = "qnm_nsp_noc",
523 404 .channels = 2,
524 405 .buswidth = 32,
525 - .qosbox = &(const struct qcom_icc_qosbox) {
526 - .num_ports = 2,
527 - .port_offsets = { 0x57000, 0xd7000 },
528 - .prio = 0,
529 - .urg_fwd = 0,
530 - .prio_fwd_disable = 1,
531 - },
532 406 .num_links = 3,
533 407 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc,
534 408 &qns_pcie },
@@ -538,13 +412,6 @@ static struct qcom_icc_node qnm_pcie = {
538 412 .name = "qnm_pcie",
539 413 .channels = 1,
540 414 .buswidth = 64,
541 - .qosbox = &(const struct qcom_icc_qosbox) {
542 - .num_ports = 1,
543 - .port_offsets = { 0x277000 },
544 - .prio = 0,
545 - .urg_fwd = 1,
546 - .prio_fwd_disable = 0,
547 - },
548 415 .num_links = 2,
549 416 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc },
550 417 };
@@ -553,13 +420,6 @@ static struct qcom_icc_node qnm_snoc_sf = {
553 420 .name = "qnm_snoc_sf",
554 421 .channels = 1,
555 422 .buswidth = 64,
556 - .qosbox = &(const struct qcom_icc_qosbox) {
557 - .num_ports = 1,
558 - .port_offsets = { 0x27b000 },
559 - .prio = 2,
560 - .urg_fwd = 1,
561 - .prio_fwd_disable = 0,
562 - },
563 423 .num_links = 3,
564 424 .link_nodes = { &qns_gem_noc_cnoc, &qns_llcc,
565 425 &qns_pcie },
@@ -569,13 +429,6 @@ static struct qcom_icc_node xm_gic = {
569 429 .name = "xm_gic",
570 430 .channels = 1,
571 431 .buswidth = 8,
572 - .qosbox = &(const struct qcom_icc_qosbox) {
573 - .num_ports = 1,
574 - .port_offsets = { 0x27f000 },
575 - .prio = 2,
576 - .urg_fwd = 0,
577 - .prio_fwd_disable = 1,
578 - },
579 432 .num_links = 1,
580 433 .link_nodes = { &qns_llcc },
581 434 };
@@ -616,13 +469,6 @@ static struct qcom_icc_node qnm_av1_enc = {
616 469 .name = "qnm_av1_enc",
617 470 .channels = 1,
618 471 .buswidth = 32,
619 - .qosbox = &(const struct qcom_icc_qosbox) {
620 - .num_ports = 1,
621 - .port_offsets = { 0x2f000 },
622 - .prio = 4,
623 - .urg_fwd = 0,
624 - .prio_fwd_disable = 1,
625 - },
626 472 .num_links = 1,
627 473 .link_nodes = { &qns_mem_noc_sf },
628 474 };
@@ -631,13 +477,6 @@ static struct qcom_icc_node qnm_camnoc_hf = {
631 477 .name = "qnm_camnoc_hf",
632 478 .channels = 2,
633 479 .buswidth = 32,
634 - .qosbox = &(const struct qcom_icc_qosbox) {
635 - .num_ports = 2,
636 - .port_offsets = { 0x28000, 0x29000 },
637 - .prio = 0,
638 - .urg_fwd = 1,
639 - .prio_fwd_disable = 0,
640 - },
641 480 .num_links = 1,
642 481 .link_nodes = { &qns_mem_noc_hf },
643 482 };
@@ -646,13 +485,6 @@ static struct qcom_icc_node qnm_camnoc_icp = {
646 485 .name = "qnm_camnoc_icp",
647 486 .channels = 1,
648 487 .buswidth = 8,
649 - .qosbox = &(const struct qcom_icc_qosbox) {
650 - .num_ports = 1,
651 - .port_offsets = { 0x2a000 },
652 - .prio = 4,
653 - .urg_fwd = 0,
654 - .prio_fwd_disable = 1,
655 - },
656 488 .num_links = 1,
657 489 .link_nodes = { &qns_mem_noc_sf },
658 490 };
@@ -661,13 +493,6 @@ static struct qcom_icc_node qnm_camnoc_sf = {
661 493 .name = "qnm_camnoc_sf",
662 494 .channels = 2,
663 495 .buswidth = 32,
664 - .qosbox = &(const struct qcom_icc_qosbox) {
665 - .num_ports = 2,
666 - .port_offsets = { 0x2b000, 0x2c000 },
667 - .prio = 0,
668 - .urg_fwd = 1,
669 - .prio_fwd_disable = 0,
670 - },
671 496 .num_links = 1,
672 497 .link_nodes = { &qns_mem_noc_sf },
673 498 };
@@ -676,13 +501,6 @@ static struct qcom_icc_node qnm_eva = {
676 501 .name = "qnm_eva",
677 502 .channels = 1,
678 503 .buswidth = 32,
679 - .qosbox = &(const struct qcom_icc_qosbox) {
680 - .num_ports = 1,
681 - .port_offsets = { 0x33000 },
682 - .prio = 0,
683 - .urg_fwd = 1,
684 - .prio_fwd_disable = 0,
685 - },
686 504 .num_links = 1,
687 505 .link_nodes = { &qns_mem_noc_sf },
688 506 };
@@ -691,13 +509,6 @@ static struct qcom_icc_node qnm_mdp = {
691 509 .name = "qnm_mdp",
692 510 .channels = 2,
693 511 .buswidth = 32,
694 - .qosbox = &(const struct qcom_icc_qosbox) {
695 - .num_ports = 2,
696 - .port_offsets = { 0x2d000, 0x2e000 },
697 - .prio = 0,
698 - .urg_fwd = 1,
699 - .prio_fwd_disable = 0,
700 - },
701 512 .num_links = 1,
702 513 .link_nodes = { &qns_mem_noc_hf },
703 514 };
@@ -706,13 +517,6 @@ static struct qcom_icc_node qnm_video = {
706 517 .name = "qnm_video",
707 518 .channels = 2,
708 519 .buswidth = 32,
709 - .qosbox = &(const struct qcom_icc_qosbox) {
710 - .num_ports = 2,
711 - .port_offsets = { 0x30000, 0x31000 },
712 - .prio = 0,
713 - .urg_fwd = 1,
714 - .prio_fwd_disable = 0,
715 - },
716 520 .num_links = 1,
717 521 .link_nodes = { &qns_mem_noc_sf },
718 522 };
@@ -721,13 +525,6 @@ static struct qcom_icc_node qnm_video_cv_cpu = {
721 525 .name = "qnm_video_cv_cpu",
722 526 .channels = 1,
723 527 .buswidth = 8,
724 - .qosbox = &(const struct qcom_icc_qosbox) {
725 - .num_ports = 1,
726 - .port_offsets = { 0x32000 },
727 - .prio = 4,
728 - .urg_fwd = 0,
729 - .prio_fwd_disable = 1,
730 - },
731 528 .num_links = 1,
732 529 .link_nodes = { &qns_mem_noc_sf },
733 530 };
@@ -736,13 +533,6 @@ static struct qcom_icc_node qnm_video_v_cpu = {
736 533 .name = "qnm_video_v_cpu",
737 534 .channels = 1,
738 535 .buswidth = 8,
739 - .qosbox = &(const struct qcom_icc_qosbox) {
740 - .num_ports = 1,
741 - .port_offsets = { 0x34000 },
742 - .prio = 4,
743 - .urg_fwd = 0,
744 - .prio_fwd_disable = 1,
745 - },
746 536 .num_links = 1,
747 537 .link_nodes = { &qns_mem_noc_sf },
748 538 };
@@ -783,13 +573,6 @@ static struct qcom_icc_node xm_pcie_3 = {
783 573 .name = "xm_pcie_3",
784 574 .channels = 1,
785 575 .buswidth = 64,
786 - .qosbox = &(const struct qcom_icc_qosbox) {
787 - .num_ports = 1,
788 - .port_offsets = { 0x7000 },
789 - .prio = 2,
790 - .urg_fwd = 0,
791 - .prio_fwd_disable = 1,
792 - },
793 576 .num_links = 1,
794 577 .link_nodes = { &qns_pcie_north_gem_noc },
795 578 };
@@ -798,13 +581,6 @@ static struct qcom_icc_node xm_pcie_4 = {
798 581 .name = "xm_pcie_4",
799 582 .channels = 1,
800 583 .buswidth = 8,
801 - .qosbox = &(const struct qcom_icc_qosbox) {
802 - .num_ports = 1,
803 - .port_offsets = { 0x8000 },
804 - .prio = 2,
805 - .urg_fwd = 0,
806 - .prio_fwd_disable = 1,
807 - },
808 584 .num_links = 1,
809 585 .link_nodes = { &qns_pcie_north_gem_noc },
810 586 };
@@ -813,13 +589,6 @@ static struct qcom_icc_node xm_pcie_5 = {
813 589 .name = "xm_pcie_5",
814 590 .channels = 1,
815 591 .buswidth = 8,
816 - .qosbox = &(const struct qcom_icc_qosbox) {
817 - .num_ports = 1,
818 - .port_offsets = { 0x9000 },
819 - .prio = 3,
820 - .urg_fwd = 0,
821 - .prio_fwd_disable = 1,
822 - },
823 592 .num_links = 1,
824 593 .link_nodes = { &qns_pcie_north_gem_noc },
825 594 };
@@ -828,13 +597,6 @@ static struct qcom_icc_node xm_pcie_0 = {
828 597 .name = "xm_pcie_0",
829 598 .channels = 1,
830 599 .buswidth = 16,
831 - .qosbox = &(const struct qcom_icc_qosbox) {
832 - .num_ports = 1,
833 - .port_offsets = { 0x9000 },
834 - .prio = 2,
835 - .urg_fwd = 0,
836 - .prio_fwd_disable = 1,
837 - },
838 600 .num_links = 1,
839 601 .link_nodes = { &qns_pcie_south_gem_noc },
840 602 };
@@ -843,13 +605,6 @@ static struct qcom_icc_node xm_pcie_1 = {
843 605 .name = "xm_pcie_1",
844 606 .channels = 1,
845 607 .buswidth = 16,
846 - .qosbox = &(const struct qcom_icc_qosbox) {
847 - .num_ports = 1,
848 - .port_offsets = { 0xa000 },
849 - .prio = 2,
850 - .urg_fwd = 0,
851 - .prio_fwd_disable = 1,
852 - },
853 608 .num_links = 1,
854 609 .link_nodes = { &qns_pcie_south_gem_noc },
855 610 };
@@ -858,13 +613,6 @@ static struct qcom_icc_node xm_pcie_2 = {
858 613 .name = "xm_pcie_2",
859 614 .channels = 1,
860 615 .buswidth = 16,
861 - .qosbox = &(const struct qcom_icc_qosbox) {
862 - .num_ports = 1,
863 - .port_offsets = { 0xb000 },
864 - .prio = 2,
865 - .urg_fwd = 0,
866 - .prio_fwd_disable = 1,
867 - },
868 616 .num_links = 1,
869 617 .link_nodes = { &qns_pcie_south_gem_noc },
870 618 };
@@ -873,13 +621,6 @@ static struct qcom_icc_node xm_pcie_6a = {
873 621 .name = "xm_pcie_6a",
874 622 .channels = 1,
875 623 .buswidth = 32,
876 - .qosbox = &(const struct qcom_icc_qosbox) {
877 - .num_ports = 1,
878 - .port_offsets = { 0xc000 },
879 - .prio = 2,
880 - .urg_fwd = 0,
881 - .prio_fwd_disable = 1,
882 - },
883 624 .num_links = 1,
884 625 .link_nodes = { &qns_pcie_south_gem_noc },
885 626 };
@@ -888,13 +629,6 @@ static struct qcom_icc_node xm_pcie_6b = {
888 629 .name = "xm_pcie_6b",
889 630 .channels = 1,
890 631 .buswidth = 16,
891 - .qosbox = &(const struct qcom_icc_qosbox) {
892 - .num_ports = 1,
893 - .port_offsets = { 0xd000 },
894 - .prio = 2,
895 - .urg_fwd = 0,
896 - .prio_fwd_disable = 1,
897 - },
898 632 .num_links = 1,
899 633 .link_nodes = { &qns_pcie_south_gem_noc },
900 634 };
@@ -919,13 +653,6 @@ static struct qcom_icc_node qnm_gic = {
919 653 .name = "qnm_gic",
920 654 .channels = 1,
921 655 .buswidth = 8,
922 - .qosbox = &(const struct qcom_icc_qosbox) {
923 - .num_ports = 1,
924 - .port_offsets = { 0x1c000 },
925 - .prio = 2,
926 - .urg_fwd = 0,
927 - .prio_fwd_disable = 1,
928 - },
929 656 .num_links = 1,
930 657 .link_nodes = { &qns_gemnoc_sf },
931 658 };
@@ -958,13 +685,6 @@ static struct qcom_icc_node xm_usb2_0 = {
958 685 .name = "xm_usb2_0",
959 686 .channels = 1,
960 687 .buswidth = 8,
961 - .qosbox = &(const struct qcom_icc_qosbox) {
962 - .num_ports = 1,
963 - .port_offsets = { 0x6000 },
964 - .prio = 2,
965 - .urg_fwd = 0,
966 - .prio_fwd_disable = 1,
967 - },
968 688 .num_links = 1,
969 689 .link_nodes = { &qns_aggre_usb_north_snoc },
970 690 };
@@ -973,13 +693,6 @@ static struct qcom_icc_node xm_usb3_mp = {
973 693 .name = "xm_usb3_mp",
974 694 .channels = 1,
975 695 .buswidth = 16,
976 - .qosbox = &(const struct qcom_icc_qosbox) {
977 - .num_ports = 1,
978 - .port_offsets = { 0x7000 },
979 - .prio = 2,
980 - .urg_fwd = 0,
981 - .prio_fwd_disable = 1,
982 - },
983 696 .num_links = 1,
984 697 .link_nodes = { &qns_aggre_usb_north_snoc },
985 698 };
@@ -988,13 +701,6 @@ static struct qcom_icc_node xm_usb3_0 = {
988 701 .name = "xm_usb3_0",
989 702 .channels = 1,
990 703 .buswidth = 8,
991 - .qosbox = &(const struct qcom_icc_qosbox) {
992 - .num_ports = 1,
993 - .port_offsets = { 0xa000 },
994 - .prio = 2,
995 - .urg_fwd = 0,
996 - .prio_fwd_disable = 1,
997 - },
998 704 .num_links = 1,
999 705 .link_nodes = { &qns_aggre_usb_south_snoc },
1000 706 };
@@ -1003,13 +709,6 @@ static struct qcom_icc_node xm_usb3_1 = {
1003 709 .name = "xm_usb3_1",
1004 710 .channels = 1,
1005 711 .buswidth = 8,
1006 - .qosbox = &(const struct qcom_icc_qosbox) {
1007 - .num_ports = 1,
1008 - .port_offsets = { 0xb000 },
1009 - .prio = 2,
1010 - .urg_fwd = 0,
1011 - .prio_fwd_disable = 1,
1012 - },
1013 712 .num_links = 1,
1014 713 .link_nodes = { &qns_aggre_usb_south_snoc },
1015 714 };
@@ -1018,13 +717,6 @@ static struct qcom_icc_node xm_usb3_2 = {
1018 717 .name = "xm_usb3_2",
1019 718 .channels = 1,
1020 719 .buswidth = 8,
1021 - .qosbox = &(const struct qcom_icc_qosbox) {
1022 - .num_ports = 1,
1023 - .port_offsets = { 0xc000 },
1024 - .prio = 2,
1025 - .urg_fwd = 0,
1026 - .prio_fwd_disable = 1,
1027 - },
1028 720 .num_links = 1,
1029 721 .link_nodes = { &qns_aggre_usb_south_snoc },
1030 722 };
@@ -1033,13 +725,6 @@ static struct qcom_icc_node xm_usb4_0 = {
1033 725 .name = "xm_usb4_0",
1034 726 .channels = 1,
1035 727 .buswidth = 16,
1036 - .qosbox = &(const struct qcom_icc_qosbox) {
1037 - .num_ports = 1,
1038 - .port_offsets = { 0xd000 },
1039 - .prio = 2,
1040 - .urg_fwd = 0,
1041 - .prio_fwd_disable = 1,
1042 - },
1043 728 .num_links = 1,
1044 729 .link_nodes = { &qns_aggre_usb_south_snoc },
1045 730 };
@@ -1048,13 +733,6 @@ static struct qcom_icc_node xm_usb4_1 = {
1048 733 .name = "xm_usb4_1",
1049 734 .channels = 1,
1050 735 .buswidth = 16,
1051 - .qosbox = &(const struct qcom_icc_qosbox) {
1052 - .num_ports = 1,
1053 - .port_offsets = { 0xe000 },
1054 - .prio = 2,
1055 - .urg_fwd = 0,
1056 - .prio_fwd_disable = 1,
1057 - },
1058 736 .num_links = 1,
1059 737 .link_nodes = { &qns_aggre_usb_south_snoc },
1060 738 };
@@ -1063,13 +741,6 @@ static struct qcom_icc_node xm_usb4_2 = {
1063 741 .name = "xm_usb4_2",
1064 742 .channels = 1,
1065 743 .buswidth = 16,
1066 - .qosbox = &(const struct qcom_icc_qosbox) {
1067 - .num_ports = 1,
1068 - .port_offsets = { 0xf000 },
1069 - .prio = 2,
1070 - .urg_fwd = 0,
1071 - .prio_fwd_disable = 1,
1072 - },
1073 744 .num_links = 1,
1074 745 .link_nodes = { &qns_aggre_usb_south_snoc },
1075 746 };
@@ -1795,21 +1466,11 @@ static struct qcom_icc_node * const aggre1_noc_nodes[] = {
1795 1466 [SLAVE_A1NOC_SNOC] = &qns_a1noc_snoc,
1796 1467 };
1797 1468
1798 - static const struct regmap_config x1e80100_aggre1_noc_regmap_config = {
1799 - .reg_bits = 32,
1800 - .reg_stride = 4,
1801 - .val_bits = 32,
1802 - .max_register = 0x14400,
1803 - .fast_io = true,
1804 - };
1805 -
1806 1469 static const struct qcom_icc_desc x1e80100_aggre1_noc = {
1807 - .config = &x1e80100_aggre1_noc_regmap_config,
1808 1470 .nodes = aggre1_noc_nodes,
1809 1471 .num_nodes = ARRAY_SIZE(aggre1_noc_nodes),
1810 1472 .bcms = aggre1_noc_bcms,
1811 1473 .num_bcms = ARRAY_SIZE(aggre1_noc_bcms),
1812 - .qos_requires_clocks = true,
1813 1474 };
1814 1475
1815 1476 static struct qcom_icc_bcm * const aggre2_noc_bcms[] = {
@@ -1827,16 +1488,7 @@ static struct qcom_icc_node * const aggre2_noc_nodes[] = {
1827 1488 [SLAVE_A2NOC_SNOC] = &qns_a2noc_snoc,
1828 1489 };
1829 1490
1830 - static const struct regmap_config x1e80100_aggre2_noc_regmap_config = {
1831 - .reg_bits = 32,
1832 - .reg_stride = 4,
1833 - .val_bits = 32,
1834 - .max_register = 0x1c400,
1835 - .fast_io = true,
1836 - };
1837 -
1838 1491 static const struct qcom_icc_desc x1e80100_aggre2_noc = {
1839 - .config = &x1e80100_aggre2_noc_regmap_config,
1840 1492 .nodes = aggre2_noc_nodes,
1841 1493 .num_nodes = ARRAY_SIZE(aggre2_noc_nodes),
1842 1494 .bcms = aggre2_noc_bcms,
@@ -1921,16 +1573,7 @@ static struct qcom_icc_node * const cnoc_cfg_nodes[] = {
1921 1573 [SLAVE_TCU] = &xs_sys_tcu_cfg,
1922 1574 };
1923 1575
1924 - static const struct regmap_config x1e80100_cnoc_cfg_regmap_config = {
1925 - .reg_bits = 32,
1926 - .reg_stride = 4,
1927 - .val_bits = 32,
1928 - .max_register = 0x6600,
1929 - .fast_io = true,
1930 - };
1931 -
1932 1576 static const struct qcom_icc_desc x1e80100_cnoc_cfg = {
1933 - .config = &x1e80100_cnoc_cfg_regmap_config,
1934 1577 .nodes = cnoc_cfg_nodes,
1935 1578 .num_nodes = ARRAY_SIZE(cnoc_cfg_nodes),
1936 1579 .bcms = cnoc_cfg_bcms,
@@ -1960,16 +1603,7 @@ static struct qcom_icc_node * const cnoc_main_nodes[] = {
1960 1603 [SLAVE_PCIE_6B] = &xs_pcie_6b,
1961 1604 };
1962 1605
1963 - static const struct regmap_config x1e80100_cnoc_main_regmap_config = {
1964 - .reg_bits = 32,
1965 - .reg_stride = 4,
1966 - .val_bits = 32,
1967 - .max_register = 0x14400,
1968 - .fast_io = true,
1969 - };
1970 -
1971 1606 static const struct qcom_icc_desc x1e80100_cnoc_main = {
1972 - .config = &x1e80100_cnoc_main_regmap_config,
1973 1607 .nodes = cnoc_main_nodes,
1974 1608 .num_nodes = ARRAY_SIZE(cnoc_main_nodes),
1975 1609 .bcms = cnoc_main_bcms,
@@ -1999,16 +1633,7 @@ static struct qcom_icc_node * const gem_noc_nodes[] = {
1999 1633 [SLAVE_MEM_NOC_PCIE_SNOC] = &qns_pcie,
2000 1634 };
2001 1635
2002 - static const struct regmap_config x1e80100_gem_noc_regmap_config = {
2003 - .reg_bits = 32,
2004 - .reg_stride = 4,
2005 - .val_bits = 32,
2006 - .max_register = 0x311200,
2007 - .fast_io = true,
2008 - };
2009 -
2010 1636 static const struct qcom_icc_desc x1e80100_gem_noc = {
2011 - .config = &x1e80100_gem_noc_regmap_config,
2012 1637 .nodes = gem_noc_nodes,
2013 1638 .num_nodes = ARRAY_SIZE(gem_noc_nodes),
2014 1639 .bcms = gem_noc_bcms,
@@ -2023,16 +1648,7 @@ static struct qcom_icc_node * const lpass_ag_noc_nodes[] = {
2023 1648 [SLAVE_LPASS_GEM_NOC] = &qns_lpass_ag_noc_gemnoc,
2024 1649 };
2025 1650
2026 - static const struct regmap_config x1e80100_lpass_ag_noc_regmap_config = {
2027 - .reg_bits = 32,
2028 - .reg_stride = 4,
2029 - .val_bits = 32,
2030 - .max_register = 0xe080,
2031 - .fast_io = true,
2032 - };
2033 -
2034 1651 static const struct qcom_icc_desc x1e80100_lpass_ag_noc = {
2035 - .config = &x1e80100_lpass_ag_noc_regmap_config,
2036 1652 .nodes = lpass_ag_noc_nodes,
2037 1653 .num_nodes = ARRAY_SIZE(lpass_ag_noc_nodes),
2038 1654 .bcms = lpass_ag_noc_bcms,
@@ -2048,16 +1664,7 @@ static struct qcom_icc_node * const lpass_lpiaon_noc_nodes[] = {
2048 1664 [SLAVE_LPIAON_NOC_LPASS_AG_NOC] = &qns_lpass_aggnoc,
2049 1665 };
2050 1666
2051 - static const struct regmap_config x1e80100_lpass_lpiaon_noc_regmap_config = {
2052 - .reg_bits = 32,
2053 - .reg_stride = 4,
2054 - .val_bits = 32,
2055 - .max_register = 0x19080,
2056 - .fast_io = true,
2057 - };
2058 -
2059 1667 static const struct qcom_icc_desc x1e80100_lpass_lpiaon_noc = {
2060 - .config = &x1e80100_lpass_lpiaon_noc_regmap_config,
2061 1668 .nodes = lpass_lpiaon_noc_nodes,
2062 1669 .num_nodes = ARRAY_SIZE(lpass_lpiaon_noc_nodes),
2063 1670 .bcms = lpass_lpiaon_noc_bcms,
@@ -2072,16 +1679,7 @@ static struct qcom_icc_node * const lpass_lpicx_noc_nodes[] = {
2072 1679 [SLAVE_LPICX_NOC_LPIAON_NOC] = &qns_lpi_aon_noc,
2073 1680 };
2074 1681
2075 - static const struct regmap_config x1e80100_lpass_lpicx_noc_regmap_config = {
2076 - .reg_bits = 32,
2077 - .reg_stride = 4,
2078 - .val_bits = 32,
2079 - .max_register = 0x3a200,
2080 - .fast_io = true,
2081 - };
2082 -
2083 1682 static const struct qcom_icc_desc x1e80100_lpass_lpicx_noc = {
2084 - .config = &x1e80100_lpass_lpicx_noc_regmap_config,
2085 1683 .nodes = lpass_lpicx_noc_nodes,
2086 1684 .num_nodes = ARRAY_SIZE(lpass_lpicx_noc_nodes),
2087 1685 .bcms = lpass_lpicx_noc_bcms,
@@ -2126,16 +1724,7 @@ static struct qcom_icc_node * const mmss_noc_nodes[] = {
2126 1724 [SLAVE_SERVICE_MNOC] = &srvc_mnoc,
2127 1725 };
2128 1726
2129 - static const struct regmap_config x1e80100_mmss_noc_regmap_config = {
2130 - .reg_bits = 32,
2131 - .reg_stride = 4,
2132 - .val_bits = 32,
2133 - .max_register = 0x5b800,
2134 - .fast_io = true,
2135 - };
2136 -
2137 1727 static const struct qcom_icc_desc x1e80100_mmss_noc = {
2138 - .config = &x1e80100_mmss_noc_regmap_config,
2139 1728 .nodes = mmss_noc_nodes,
2140 1729 .num_nodes = ARRAY_SIZE(mmss_noc_nodes),
2141 1730 .bcms = mmss_noc_bcms,
@@ -2151,16 +1740,7 @@ static struct qcom_icc_node * const nsp_noc_nodes[] = {
2151 1740 [SLAVE_CDSP_MEM_NOC] = &qns_nsp_gemnoc,
2152 1741 };
2153 1742
2154 - static const struct regmap_config x1e80100_nsp_noc_regmap_config = {
2155 - .reg_bits = 32,
2156 - .reg_stride = 4,
2157 - .val_bits = 32,
2158 - .max_register = 0xe080,
2159 - .fast_io = true,
2160 - };
2161 -
2162 1743 static const struct qcom_icc_desc x1e80100_nsp_noc = {
2163 - .config = &x1e80100_nsp_noc_regmap_config,
2164 1744 .nodes = nsp_noc_nodes,
2165 1745 .num_nodes = ARRAY_SIZE(nsp_noc_nodes),
2166 1746 .bcms = nsp_noc_bcms,
@@ -2177,16 +1757,7 @@ static struct qcom_icc_node * const pcie_center_anoc_nodes[] = {
2177 1757 [SLAVE_ANOC_PCIE_GEM_NOC] = &qns_pcie_mem_noc,
2178 1758 };
2179 1759
2180 - static const struct regmap_config x1e80100_pcie_center_anoc_regmap_config = {
2181 - .reg_bits = 32,
2182 - .reg_stride = 4,
2183 - .val_bits = 32,
2184 - .max_register = 0x7000,
2185 - .fast_io = true,
2186 - };
2187 -
2188 1760 static const struct qcom_icc_desc x1e80100_pcie_center_anoc = {
2189 - .config = &x1e80100_pcie_center_anoc_regmap_config,
2190 1761 .nodes = pcie_center_anoc_nodes,
2191 1762 .num_nodes = ARRAY_SIZE(pcie_center_anoc_nodes),
2192 1763 .bcms = pcie_center_anoc_bcms,
@@ -2203,16 +1774,7 @@ static struct qcom_icc_node * const pcie_north_anoc_nodes[] = {
2203 1774 [SLAVE_PCIE_NORTH] = &qns_pcie_north_gem_noc,
2204 1775 };
2205 1776
2206 - static const struct regmap_config x1e80100_pcie_north_anoc_regmap_config = {
2207 - .reg_bits = 32,
2208 - .reg_stride = 4,
2209 - .val_bits = 32,
2210 - .max_register = 0x9080,
2211 - .fast_io = true,
2212 - };
2213 -
2214 1777 static const struct qcom_icc_desc x1e80100_pcie_north_anoc = {
2215 - .config = &x1e80100_pcie_north_anoc_regmap_config,
2216 1778 .nodes = pcie_north_anoc_nodes,
2217 1779 .num_nodes = ARRAY_SIZE(pcie_north_anoc_nodes),
2218 1780 .bcms = pcie_north_anoc_bcms,
@@ -2231,16 +1793,7 @@ static struct qcom_icc_node * const pcie_south_anoc_nodes[] = {
2231 1793 [SLAVE_PCIE_SOUTH] = &qns_pcie_south_gem_noc,
2232 1794 };
2233 1795
2234 - static const struct regmap_config x1e80100_pcie_south_anoc_regmap_config = {
2235 - .reg_bits = 32,
2236 - .reg_stride = 4,
2237 - .val_bits = 32,
2238 - .max_register = 0xd080,
2239 - .fast_io = true,
2240 - };
2241 -
2242 1796 static const struct qcom_icc_desc x1e80100_pcie_south_anoc = {
2243 - .config = &x1e80100_pcie_south_anoc_regmap_config,
2244 1797 .nodes = pcie_south_anoc_nodes,
2245 1798 .num_nodes = ARRAY_SIZE(pcie_south_anoc_nodes),
2246 1799 .bcms = pcie_south_anoc_bcms,
@@ -2262,16 +1815,7 @@ static struct qcom_icc_node * const system_noc_nodes[] = {
2262 1815 [SLAVE_SNOC_GEM_NOC_SF] = &qns_gemnoc_sf,
2263 1816 };
2264 1817
2265 - static const struct regmap_config x1e80100_system_noc_regmap_config = {
2266 - .reg_bits = 32,
2267 - .reg_stride = 4,
2268 - .val_bits = 32,
2269 - .max_register = 0x1c080,
2270 - .fast_io = true,
2271 - };
2272 -
2273 1818 static const struct qcom_icc_desc x1e80100_system_noc = {
2274 - .config = &x1e80100_system_noc_regmap_config,
2275 1819 .nodes = system_noc_nodes,
2276 1820 .num_nodes = ARRAY_SIZE(system_noc_nodes),
2277 1821 .bcms = system_noc_bcms,
@@ -2287,16 +1831,7 @@ static struct qcom_icc_node * const usb_center_anoc_nodes[] = {
2287 1831 [SLAVE_USB_NOC_SNOC] = &qns_aggre_usb_snoc,
2288 1832 };
2289 1833
2290 - static const struct regmap_config x1e80100_usb_center_anoc_regmap_config = {
2291 - .reg_bits = 32,
2292 - .reg_stride = 4,
2293 - .val_bits = 32,
2294 - .max_register = 0x8800,
2295 - .fast_io = true,
2296 - };
2297 -
2298 1834 static const struct qcom_icc_desc x1e80100_usb_center_anoc = {
2299 - .config = &x1e80100_usb_center_anoc_regmap_config,
2300 1835 .nodes = usb_center_anoc_nodes,
2301 1836 .num_nodes = ARRAY_SIZE(usb_center_anoc_nodes),
2302 1837 .bcms = usb_center_anoc_bcms,
@@ -2312,21 +1847,11 @@ static struct qcom_icc_node * const usb_north_anoc_nodes[] = {
2312 1847 [SLAVE_AGGRE_USB_NORTH] = &qns_aggre_usb_north_snoc,
2313 1848 };
2314 1849
2315 - static const struct regmap_config x1e80100_usb_north_anoc_regmap_config = {
2316 - .reg_bits = 32,
2317 - .reg_stride = 4,
2318 - .val_bits = 32,
2319 - .max_register = 0x7080,
2320 - .fast_io = true,
2321 - };
2322 -
2323 1850 static const struct qcom_icc_desc x1e80100_usb_north_anoc = {
2324 - .config = &x1e80100_usb_north_anoc_regmap_config,
2325 1851 .nodes = usb_north_anoc_nodes,
2326 1852 .num_nodes = ARRAY_SIZE(usb_north_anoc_nodes),
2327 1853 .bcms = usb_north_anoc_bcms,
2328 1854 .num_bcms = ARRAY_SIZE(usb_north_anoc_bcms),
2329 - .qos_requires_clocks = true,
2330 1855 };
2331 1856
2332 1857 static struct qcom_icc_bcm * const usb_south_anoc_bcms[] = {
@@ -2342,21 +1867,11 @@ static struct qcom_icc_node * const usb_south_anoc_nodes[] = {
2342 1867 [SLAVE_AGGRE_USB_SOUTH] = &qns_aggre_usb_south_snoc,
2343 1868 };
2344 1869
2345 - static const struct regmap_config x1e80100_usb_south_anoc_regmap_config = {
2346 - .reg_bits = 32,
2347 - .reg_stride = 4,
2348 - .val_bits = 32,
2349 - .max_register = 0xf080,
2350 - .fast_io = true,
2351 - };
2352 -
2353 1870 static const struct qcom_icc_desc x1e80100_usb_south_anoc = {
2354 - .config = &x1e80100_usb_south_anoc_regmap_config,
2355 1871 .nodes = usb_south_anoc_nodes,
2356 1872 .num_nodes = ARRAY_SIZE(usb_south_anoc_nodes),
2357 1873 .bcms = usb_south_anoc_bcms,
2358 1874 .num_bcms = ARRAY_SIZE(usb_south_anoc_bcms),
2359 - .qos_requires_clocks = true,
2360 1875 };
2361 1876
2362 1877 static const struct of_device_id qnoc_of_match[] = {
modified drivers/mtd/chips/cfi_cmdset_0001.c
@@ -1716,12 +1716,24 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
1716 1716 }
1717 1717
1718 1718
1719 + /*
1720 + * Keep noinline: inlined, the map_word temporaries put do_write_buffer() over
1721 + * the frame-size limit with MTD_MAP_BANK_WIDTH_32 and KASAN_STACK.
1722 + */
1723 + static noinline void __xipram cfi_write_cmd(struct map_info *map,
1724 + unsigned long cmd, unsigned long adr)
1725 + {
1726 + struct cfi_private *cfi = map->fldrv_priv;
1727 +
1728 + map_write(map, CMD(cmd), adr);
1729 + }
1730 +
1719 1731 static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1720 1732 unsigned long adr, const struct kvec **pvec,
1721 1733 unsigned long *pvec_seek, int len)
1722 1734 {
1723 1735 struct cfi_private *cfi = map->fldrv_priv;
1724 - map_word status, write_cmd, datum;
1736 + map_word status, datum;
1725 1737 unsigned long cmd_adr;
1726 1738 int ret, wbufsize, word_gap, words;
1727 1739 const struct kvec *vec;
@@ -1740,9 +1752,6 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1740 1752 if (is_LH28F640BF(cfi))
1741 1753 cmd_adr = adr;
1742 1754
1743 - /* Let's determine this according to the interleave only once */
1744 - write_cmd = (cfi->cfiq->P_ID != P_ID_INTEL_PERFORMANCE) ? CMD(0xe8) : CMD(0xe9);
1745 -
1746 1755 mutex_lock(&chip->mutex);
1747 1756 ret = get_chip(map, chip, cmd_adr, FL_WRITING);
1748 1757 if (ret) {
@@ -1759,7 +1768,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1759 1768 So we must check here and reset those bits if they're set. Otherwise
1760 1769 we're just pissing in the wind */
1761 1770 if (chip->state != FL_STATUS) {
1762 - map_write(map, CMD(0x70), cmd_adr);
1771 + cfi_write_cmd(map, 0x70, cmd_adr);
1763 1772 chip->state = FL_STATUS;
1764 1773 }
1765 1774 status = map_read(map, cmd_adr);
@@ -1767,21 +1776,22 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1767 1776 xip_enable(map, chip, cmd_adr);
1768 1777 printk(KERN_WARNING "SR.4 or SR.5 bits set in buffer write (status %lx). Clearing.\n", status.x[0]);
1769 1778 xip_disable(map, chip, cmd_adr);
1770 - map_write(map, CMD(0x50), cmd_adr);
1771 - map_write(map, CMD(0x70), cmd_adr);
1779 + cfi_write_cmd(map, 0x50, cmd_adr);
1780 + cfi_write_cmd(map, 0x70, cmd_adr);
1772 1781 }
1773 1782
1774 1783 chip->state = FL_WRITING_TO_BUFFER;
1775 - map_write(map, write_cmd, cmd_adr);
1784 + cfi_write_cmd(map, (cfi->cfiq->P_ID != P_ID_INTEL_PERFORMANCE) ? 0xe8 : 0xe9,
1785 + cmd_adr);
1776 1786 ret = WAIT_TIMEOUT(map, chip, cmd_adr, 0, 0);
1777 1787 if (ret) {
1778 1788 /* Argh. Not ready for write to buffer */
1779 1789 map_word Xstatus = map_read(map, cmd_adr);
1780 - map_write(map, CMD(0x70), cmd_adr);
1790 + cfi_write_cmd(map, 0x70, cmd_adr);
1781 1791 chip->state = FL_STATUS;
1782 1792 status = map_read(map, cmd_adr);
1783 - map_write(map, CMD(0x50), cmd_adr);
1784 - map_write(map, CMD(0x70), cmd_adr);
1793 + cfi_write_cmd(map, 0x50, cmd_adr);
1794 + cfi_write_cmd(map, 0x70, cmd_adr);
1785 1795 xip_enable(map, chip, cmd_adr);
1786 1796 printk(KERN_ERR "%s: Chip not ready for buffer write. Xstatus = %lx, status = %lx\n",
1787 1797 map->name, Xstatus.x[0], status.x[0]);
@@ -1800,7 +1810,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1800 1810 }
1801 1811
1802 1812 /* Write length of data to come */
1803 - map_write(map, CMD(words), cmd_adr );
1813 + cfi_write_cmd(map, words, cmd_adr);
1804 1814
1805 1815 /* Write data */
1806 1816 vec = *pvec;
@@ -1837,7 +1847,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1837 1847 *pvec_seek = vec_seek;
1838 1848
1839 1849 /* GO GO GO */
1840 - map_write(map, CMD(0xd0), cmd_adr);
1850 + cfi_write_cmd(map, 0xd0, cmd_adr);
1841 1851 chip->state = FL_WRITING;
1842 1852
1843 1853 ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr,
@@ -1845,7 +1855,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1845 1855 chip->buffer_write_time,
1846 1856 chip->buffer_write_time_max);
1847 1857 if (ret) {
1848 - map_write(map, CMD(0x70), cmd_adr);
1858 + cfi_write_cmd(map, 0x70, cmd_adr);
1849 1859 chip->state = FL_STATUS;
1850 1860 xip_enable(map, chip, cmd_adr);
1851 1861 printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name);
@@ -1858,8 +1868,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1858 1868 unsigned long chipstatus = MERGESTATUS(status);
1859 1869
1860 1870 /* reset status */
1861 - map_write(map, CMD(0x50), cmd_adr);
1862 - map_write(map, CMD(0x70), cmd_adr);
1871 + cfi_write_cmd(map, 0x50, cmd_adr);
1872 + cfi_write_cmd(map, 0x70, cmd_adr);
1863 1873 xip_enable(map, chip, cmd_adr);
1864 1874
1865 1875 if (chipstatus & 0x02) {
modified drivers/mtd/devices/block2mtd.c
@@ -293,7 +293,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,
293 293 }
294 294
295 295 size = bdev_nr_bytes(bdev);
296 - if ((long)size % erase_size) {
296 + if (!erase_size || (long)size % erase_size) {
297 297 pr_err("erasesize must be a divisor of device size\n");
298 298 goto err_free_block2mtd;
299 299 }
modified drivers/mtd/devices/mtd_intel_dg.c
@@ -387,7 +387,7 @@ idg_erase(struct intel_dg_nvm *nvm, u8 region, loff_t from, u64 len, u64 *fail_a
387 387 void __iomem *base2 = nvm->base2;
388 388 void __iomem *base = nvm->base;
389 389 const u32 block = 0x10;
390 - u32 iter = 0;
390 + u32 iter;
391 391 u32 reg;
392 392 u64 i;
393 393
@@ -396,6 +396,7 @@ idg_erase(struct intel_dg_nvm *nvm, u8 region, loff_t from, u64 len, u64 *fail_a
396 396 iowrite32(region << 24 | block, base + NVM_ERASE_REG);
397 397 if (nvm->non_posted_erase) {
398 398 /* Wait for Erase Done */
399 + iter = 0;
399 400 reg = ioread32(base2 + NVM_DEBUG_REG);
400 401 while (!(reg & NVM_NON_POSTED_ERASE_DONE) &&
401 402 ++iter < NVM_NON_POSTED_ERASE_DONE_ITER) {
modified drivers/mtd/mtdcore.c
@@ -1083,6 +1083,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
1083 1083
1084 1084 err:
1085 1085 nvmem_unregister(mtd->otp_user_nvmem);
1086 + mtd->otp_user_nvmem = NULL;
1086 1087 /* Don't report error if OTP is not supported. */
1087 1088 if (err == -EOPNOTSUPP)
1088 1089 return 0;
@@ -1332,7 +1333,7 @@ int __get_mtd_device(struct mtd_info *mtd)
1332 1333 int err;
1333 1334
1334 1335 if (master->_get_device) {
1335 - err = master->_get_device(mtd);
1336 + err = master->_get_device(master);
1336 1337 if (err)
1337 1338 return err;
1338 1339 }
modified drivers/mtd/nand/ecc.c
@@ -159,6 +159,13 @@ int nand_ecc_finish_io_req(struct nand_device *nand,
159 159 }
160 160 EXPORT_SYMBOL(nand_ecc_finish_io_req);
161 161
162 + bool nand_ecc_is_pipelined(const struct nand_device *nand)
163 + {
164 + return nand->ecc.engine &&
165 + nand->ecc.engine->integration == NAND_ECC_ENGINE_INTEGRATION_PIPELINED;
166 + }
167 + EXPORT_SYMBOL(nand_ecc_is_pipelined);
168 +
162 169 /* Define default OOB placement schemes for large and small page devices */
163 170 static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
164 171 struct mtd_oob_region *oobregion)
modified drivers/mtd/nand/raw/cadence-nand-controller.c
@@ -3143,6 +3143,9 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
3143 3143 goto free_buf_desc;
3144 3144 }
3145 3145
3146 + spin_lock_init(&cdns_ctrl->irq_lock);
3147 + init_completion(&cdns_ctrl->complete);
3148 +
3146 3149 if (devm_request_irq(cdns_ctrl->dev, cdns_ctrl->irq, cadence_nand_isr,
3147 3150 IRQF_SHARED, "cadence-nand-controller",
3148 3151 cdns_ctrl)) {
@@ -3151,9 +3154,6 @@ static int cadence_nand_init(struct cdns_nand_ctrl *cdns_ctrl)
3151 3154 goto free_buf;
3152 3155 }
3153 3156
3154 - spin_lock_init(&cdns_ctrl->irq_lock);
3155 - init_completion(&cdns_ctrl->complete);
3156 -
3157 3157 ret = cadence_nand_hw_init(cdns_ctrl);
3158 3158 if (ret)
3159 3159 goto disable_irq;
modified drivers/mtd/nand/raw/vf610_nfc.c
@@ -505,6 +505,11 @@ static int vf610_nfc_exec_op(struct nand_chip *chip,
505 505 check_only);
506 506 }
507 507
508 + static unsigned int vf610_nfc_spare_size(struct mtd_info *mtd)
509 + {
510 + return min_t(unsigned int, mtd->oobsize, 64);
511 + }
512 +
508 513 static inline int vf610_nfc_correct_data(struct nand_chip *chip, uint8_t *dat,
509 514 uint8_t *oob, int page)
510 515 {
@@ -514,6 +519,7 @@ static inline int vf610_nfc_correct_data(struct nand_chip *chip, uint8_t *dat,
514 519 u8 ecc_status;
515 520 u8 ecc_count;
516 521 int flips_threshold = nfc->chip.ecc.strength / 2;
522 + int ret;
517 523
518 524 ecc_status = vf610_nfc_read(nfc, ecc_status_off) & 0xff;
519 525 ecc_count = ecc_status & ECC_STATUS_ERR_COUNT;
@@ -521,16 +527,22 @@ static inline int vf610_nfc_correct_data(struct nand_chip *chip, uint8_t *dat,
521 527 if (!(ecc_status & ECC_STATUS_MASK))
522 528 return ecc_count;
523 529
530 + /* The failed decode leaves a bogus correction in SRAM; re-read without ECC */
524 531 nfc->data_access = true;
525 - nand_read_oob_op(&nfc->chip, page, 0, oob, mtd->oobsize);
532 + ret = nand_read_page_op(&nfc->chip, page, 0, dat, mtd->writesize);
533 + if (!ret)
534 + ret = nand_read_oob_op(&nfc->chip, page, 0, oob,
535 + vf610_nfc_spare_size(mtd));
526 536 nfc->data_access = false;
537 + if (ret)
538 + return ret;
527 539
528 540 /*
529 - * On an erased page, bit count (including OOB) should be zero or
530 - * at least less then half of the ECC strength.
541 + * Run the erased-page check with the driver's historic threshold
542 + * of half the ECC strength.
531 543 */
532 - return nand_check_erased_ecc_chunk(dat, nfc->chip.ecc.size, oob,
533 - mtd->oobsize, NULL, 0,
544 + return nand_check_erased_ecc_chunk(dat, mtd->writesize, oob,
545 + vf610_nfc_spare_size(mtd), NULL, 0,
534 546 flips_threshold);
535 547 }
536 548
@@ -551,7 +563,7 @@ static int vf610_nfc_read_page(struct nand_chip *chip, uint8_t *buf,
551 563 {
552 564 struct vf610_nfc *nfc = chip_to_nfc(chip);
553 565 struct mtd_info *mtd = nand_to_mtd(chip);
554 - int trfr_sz = mtd->writesize + mtd->oobsize;
566 + int trfr_sz = mtd->writesize + vf610_nfc_spare_size(mtd);
555 567 u32 row = 0, cmd1 = 0, cmd2 = 0, code = 0;
556 568 int stat;
557 569
@@ -577,11 +589,16 @@ static int vf610_nfc_read_page(struct nand_chip *chip, uint8_t *buf,
577 589 */
578 590 vf610_nfc_rd_from_sram(buf, nfc->regs + NFC_MAIN_AREA(0),
579 591 mtd->writesize, false);
580 - if (oob_required)
592 + if (oob_required) {
593 + unsigned int spare = vf610_nfc_spare_size(mtd);
594 +
581 595 vf610_nfc_rd_from_sram(chip->oob_poi,
582 596 nfc->regs + NFC_MAIN_AREA(0) +
583 597 mtd->writesize,
584 - mtd->oobsize, false);
598 + spare, false);
599 + /* Not transferred, and never written: reads back erased */
600 + memset(chip->oob_poi + spare, 0xff, mtd->oobsize - spare);
601 + }
585 602
586 603 stat = vf610_nfc_correct_data(chip, buf, chip->oob_poi, page);
587 604
@@ -599,7 +616,7 @@ static int vf610_nfc_write_page(struct nand_chip *chip, const uint8_t *buf,
599 616 {
600 617 struct vf610_nfc *nfc = chip_to_nfc(chip);
601 618 struct mtd_info *mtd = nand_to_mtd(chip);
602 - int trfr_sz = mtd->writesize + mtd->oobsize;
619 + int trfr_sz = mtd->writesize + vf610_nfc_spare_size(mtd);
603 620 u32 row = 0, cmd1 = 0, cmd2 = 0, code = 0;
604 621 u8 status;
605 622 int ret;
@@ -740,6 +757,49 @@ static void vf610_nfc_init_controller(struct vf610_nfc *nfc)
740 757 }
741 758 }
742 759
760 + /*
761 + * With 64 byte OOB chips the core's large page layout matches what
762 + * U-Boot uses, and on chips with more, U-Boot and older kernels clamped
763 + * mtd->oobsize to 64. Modifying the OOB size is no longer possible, the
764 + * actual chip geometry must be respected, so to avoid breaking those
765 + * existing setups use our own layout: the core's large page one,
766 + * computed over the first 64 spare bytes only.
767 + */
768 + static int vf610_nfc_ooblayout_ecc(struct mtd_info *mtd, int section,
769 + struct mtd_oob_region *oobregion)
770 + {
771 + struct nand_device *nand = mtd_to_nanddev(mtd);
772 + unsigned int total_ecc_bytes = nand->ecc.ctx.total;
773 +
774 + if (section || !total_ecc_bytes)
775 + return -ERANGE;
776 +
777 + oobregion->length = total_ecc_bytes;
778 + oobregion->offset = vf610_nfc_spare_size(mtd) - oobregion->length;
779 +
780 + return 0;
781 + }
782 +
783 + static int vf610_nfc_ooblayout_free(struct mtd_info *mtd, int section,
784 + struct mtd_oob_region *oobregion)
785 + {
786 + struct nand_device *nand = mtd_to_nanddev(mtd);
787 + unsigned int total_ecc_bytes = nand->ecc.ctx.total;
788 +
789 + if (section)
790 + return -ERANGE;
791 +
792 + oobregion->length = vf610_nfc_spare_size(mtd) - total_ecc_bytes - 2;
793 + oobregion->offset = 2;
794 +
795 + return 0;
796 + }
797 +
798 + static const struct mtd_ooblayout_ops vf610_nfc_ooblayout_ops = {
799 + .ecc = vf610_nfc_ooblayout_ecc,
800 + .free = vf610_nfc_ooblayout_free,
801 + };
802 +
743 803 static int vf610_nfc_attach_chip(struct nand_chip *chip)
744 804 {
745 805 struct mtd_info *mtd = nand_to_mtd(chip);
@@ -770,12 +830,7 @@ static int vf610_nfc_attach_chip(struct nand_chip *chip)
770 830 return -ENXIO;
771 831 }
772 832
773 - /* Only 64 byte ECC layouts known */
774 - if (mtd->oobsize > 64)
775 - mtd->oobsize = 64;
776 -
777 - /* Use default large page ECC layout defined in NAND core */
778 - mtd_set_ooblayout(mtd, nand_get_large_page_ooblayout());
833 + mtd_set_ooblayout(mtd, &vf610_nfc_ooblayout_ops);
779 834 if (chip->ecc.strength == 32) {
780 835 nfc->ecc_mode = ECC_60_BYTE;
781 836 chip->ecc.bytes = 60;
modified drivers/mtd/nand/spi/core.c
@@ -281,8 +281,26 @@ static int spinand_init_cfg_cache(struct spinand_device *spinand)
281 281 static int spinand_init_quad_enable(struct spinand_device *spinand,
282 282 bool enable)
283 283 {
284 - return spinand_upd_cfg(spinand, CFG_QUAD_ENABLE,
285 - enable ? CFG_QUAD_ENABLE : 0);
284 + struct nand_device *nand = spinand_to_nand(spinand);
285 + unsigned int target;
286 + int ret;
287 +
288 + /*
289 + * QE is a per-die setting on some devices. Program each target
290 + * individually when enabling or disabling quad I/O mode.
291 + */
292 + for (target = 0; target < nand->memorg.ntargets; target++) {
293 + ret = spinand_select_target(spinand, target);
294 + if (ret)
295 + return ret;
296 +
297 + ret = spinand_upd_cfg(spinand, CFG_QUAD_ENABLE,
298 + enable ? CFG_QUAD_ENABLE : 0);
299 + if (ret)
300 + return ret;
301 + }
302 +
303 + return 0;
286 304 }
287 305
288 306 static int spinand_ecc_enable(struct spinand_device *spinand,
@@ -508,8 +526,7 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
508 526 else
509 527 rdesc->info.op_tmpl = &rdesc->info.primary_op_tmpl;
510 528
511 - if (nand->ecc.engine->integration == NAND_ECC_ENGINE_INTEGRATION_PIPELINED &&
512 - req->mode != MTD_OPS_RAW)
529 + if (nand_ecc_is_pipelined(nand) && req->mode != MTD_OPS_RAW)
513 530 rdesc->info.op_tmpl->data.ecc = true;
514 531 else
515 532 rdesc->info.op_tmpl->data.ecc = false;
@@ -603,8 +620,7 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
603 620
604 621 wdesc = spinand->dirmaps[req->pos.plane].wdesc;
605 622
606 - if (nand->ecc.engine->integration == NAND_ECC_ENGINE_INTEGRATION_PIPELINED &&
607 - req->mode != MTD_OPS_RAW)
623 + if (nand_ecc_is_pipelined(nand) && req->mode != MTD_OPS_RAW)
608 624 wdesc->info.op_tmpl->data.ecc = true;
609 625 else
610 626 wdesc->info.op_tmpl->data.ecc = false;
@@ -1261,7 +1277,7 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
1261 1277 struct spi_mem_dirmap_desc *desc;
1262 1278 bool enable_ecc = false, secondary_op = false;
1263 1279
1264 - if (nand->ecc.engine->integration == NAND_ECC_ENGINE_INTEGRATION_PIPELINED)
1280 + if (nand_ecc_is_pipelined(nand))
1265 1281 enable_ecc = true;
1266 1282
1267 1283 if (spinand->cont_read_possible && spinand->op_templates->cont_read_cache)
@@ -1797,11 +1813,11 @@ try_ssdr:
1797 1813 spinand->ssdr_op_templates.write_cache->data.buswidth == 4 ||
1798 1814 spinand->ssdr_op_templates.update_cache->data.buswidth == 4)
1799 1815 quad_enable = true;
1800 - }
1801 1816
1802 - ret = spinand_init_quad_enable(spinand, quad_enable);
1803 - if (ret)
1804 - return ret;
1817 + ret = spinand_init_quad_enable(spinand, quad_enable);
1818 + if (ret)
1819 + return ret;
1820 + }
1805 1821
1806 1822 if (spinand->configure_chip) {
1807 1823 ret = spinand->configure_chip(spinand, SSDR);
@@ -1809,7 +1825,7 @@ try_ssdr:
1809 1825 return ret;
1810 1826 }
1811 1827
1812 - return ret;
1828 + return 0;
1813 1829 }
1814 1830
1815 1831 static int spinand_init_flash(struct spinand_device *spinand)
@@ -1980,12 +1996,17 @@ static int spinand_init(struct spinand_device *spinand)
1980 1996 goto err_cleanup_ecc_engine;
1981 1997 }
1982 1998
1983 - if (nand->ecc.engine) {
1984 - ret = mtd_ooblayout_count_freebytes(mtd);
1985 - if (ret < 0)
1986 - goto err_cleanup_ecc_engine;
1999 + if (!nand->ecc.engine) {
2000 + if (spinand->eccinfo.ooblayout)
2001 + mtd_set_ooblayout(mtd, spinand->eccinfo.ooblayout);
2002 + else
2003 + mtd_set_ooblayout(mtd, &spinand_noecc_ooblayout);
1987 2004 }
1988 2005
2006 + ret = mtd_ooblayout_count_freebytes(mtd);
2007 + if (ret < 0)
2008 + goto err_cleanup_ecc_engine;
2009 +
1989 2010 mtd->oobavail = ret;
1990 2011
1991 2012 /* Propagate ECC information to mtd_info */
modified drivers/mtd/spi-nor/core.c
@@ -1310,7 +1310,7 @@ static bool spi_nor_rww_start_exclusive(struct spi_nor *nor)
1310 1310 {
1311 1311 struct spi_nor_rww *rww = &nor->rww;
1312 1312
1313 - mutex_lock(&nor->lock);
1313 + guard(mutex)(&nor->lock);
1314 1314
1315 1315 if (rww->ongoing_io || rww->ongoing_rd || rww->ongoing_pe)
1316 1316 return false;
modified drivers/net/ethernet/broadcom/bcmsysport.c
@@ -391,8 +391,10 @@ static void bcm_sysport_update_mib_counters(struct bcm_sysport_priv *priv)
391 391 if (priv->is_lite)
392 392 continue;
393 393
394 - if (s->type != BCM_SYSPORT_STAT_MIB_RX)
394 + if (s->type == BCM_SYSPORT_STAT_MIB_TX)
395 395 offset = UMAC_MIB_STAT_OFFSET;
396 + else if (s->type == BCM_SYSPORT_STAT_RUNT)
397 + offset = 2 * UMAC_MIB_STAT_OFFSET;
396 398 val = umac_readl(priv, UMAC_MIB_START + j + offset);
397 399 break;
398 400 case BCM_SYSPORT_STAT_RXCHK:
@@ -482,10 +484,10 @@ static void bcm_sysport_get_stats(struct net_device *dev,
482 484 s->type == BCM_SYSPORT_STAT_NETDEV64) {
483 485 do {
484 486 start = u64_stats_fetch_begin(syncp);
485 - data[i] = *(u64 *)p;
487 + data[j] = *(u64 *)p;
486 488 } while (u64_stats_fetch_retry(syncp, start));
487 489 } else
488 - data[i] = *(u32 *)p;
490 + data[j] = *(u32 *)p;
489 491 j++;
490 492 }
491 493
modified drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -57,6 +57,9 @@
57 57 */
58 58 #define GENET_RSB_PAD (sizeof(struct status_64) + 2)
59 59
60 + /* RX buffer plus the skb_shared_info napi_build_skb() places behind it */
61 + #define GENET_RX_BUF_SIZE SKB_HEAD_ALIGN(RX_BUF_LENGTH)
62 +
60 63 /* Tx/Rx DMA register offset, skip 256 descriptors */
61 64 #define WORDS_PER_BD(p) (p->hw_params->words_per_bd)
62 65 #define DMA_DESC_SIZE (WORDS_PER_BD(priv) * sizeof(u32))
@@ -2254,11 +2257,12 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
2254 2257 struct enet_cb *cb)
2255 2258 {
2256 2259 struct bcmgenet_priv *priv = ring->priv;
2260 + unsigned int size = GENET_RX_BUF_SIZE;
2261 + unsigned int offset;
2257 2262 dma_addr_t mapping;
2258 2263 struct page *page;
2259 2264
2260 - page = page_pool_alloc_pages(ring->page_pool,
2261 - GFP_ATOMIC);
2265 + page = page_pool_dev_alloc(ring->page_pool, &offset, &size);
2262 2266 if (!page) {
2263 2267 priv->mib.alloc_rx_buff_failed++;
2264 2268 netif_err(priv, rx_err, priv->dev,
@@ -2267,9 +2271,13 @@ static int bcmgenet_rx_refill(struct bcmgenet_rx_ring *ring,
2267 2271 }
2268 2272
2269 2273 /* page_pool handles DMA mapping via PP_FLAG_DMA_MAP */
2270 - mapping = page_pool_get_dma_addr(page);
2274 + mapping = page_pool_get_dma_addr(page) + offset;
2275 + dma_sync_single_for_device(&priv->pdev->dev, mapping, RX_BUF_LENGTH,
2276 + DMA_FROM_DEVICE);
2271 2277
2272 2278 cb->rx_page = page;
2279 + cb->rx_offset = offset;
2280 + cb->rx_size = size;
2273 2281 dmadesc_set_addr(priv, cb->bd_addr, mapping);
2274 2282
2275 2283 return 0;
@@ -2323,6 +2331,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
2323 2331
2324 2332 while ((rxpktprocessed < rxpkttoprocess) &&
2325 2333 (rxpktprocessed < budget)) {
2334 + unsigned int rx_offset, rx_size;
2326 2335 struct status_64 *status;
2327 2336 struct page *rx_page;
2328 2337 void *hard_start;
@@ -2332,6 +2341,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
2332 2341
2333 2342 /* Save the received page before refilling */
2334 2343 rx_page = cb->rx_page;
2344 + rx_offset = cb->rx_offset;
2345 + rx_size = cb->rx_size;
2335 2346
2336 2347 if (bcmgenet_rx_refill(ring, cb)) {
2337 2348 BCMGENET_STATS64_INC(stats, dropped);
@@ -2341,10 +2352,10 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
2341 2352 /* Sync the full buffer; the HW may have written anywhere
2342 2353 * up to RX_BUF_LENGTH.
2343 2354 */
2344 - page_pool_dma_sync_for_cpu(ring->page_pool, rx_page, 0,
2355 + page_pool_dma_sync_for_cpu(ring->page_pool, rx_page, rx_offset,
2345 2356 RX_BUF_LENGTH);
2346 2357
2347 - hard_start = page_address(rx_page);
2358 + hard_start = page_address(rx_page) + rx_offset;
2348 2359 status = (struct status_64 *)hard_start;
2349 2360 dma_length_status = status->length_status;
2350 2361
@@ -2410,7 +2421,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
2410 2421 /* Build SKB from the page - data starts at hard_start,
2411 2422 * frame begins after RSB(64) + pad(2) = 66 bytes.
2412 2423 */
2413 - skb = napi_build_skb(hard_start, PAGE_SIZE);
2424 + skb = napi_build_skb(hard_start, rx_size);
2414 2425 if (unlikely(!skb)) {
2415 2426 BCMGENET_STATS64_INC(stats, dropped);
2416 2427 page_pool_put_full_page(ring->page_pool, rx_page,
@@ -2762,14 +2773,16 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,
2762 2773 static int bcmgenet_rx_ring_create_pool(struct bcmgenet_priv *priv,
2763 2774 struct bcmgenet_rx_ring *ring)
2764 2775 {
2776 + /* Buffers share a page. bcmgenet_rx_refill() syncs each one for the
2777 + * device, PP_FLAG_DMA_SYNC_DEV would sync the whole page.
2778 + */
2765 2779 struct page_pool_params pp_params = {
2766 2780 .order = 0,
2767 - .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
2781 + .flags = PP_FLAG_DMA_MAP,
2768 2782 .pool_size = ring->size,
2769 2783 .nid = NUMA_NO_NODE,
2770 2784 .dev = &priv->pdev->dev,
2771 2785 .dma_dir = DMA_FROM_DEVICE,
2772 - .max_len = RX_BUF_LENGTH,
2773 2786 };
2774 2787 int err;
2775 2788
@@ -4138,8 +4151,11 @@ static int bcmgenet_probe(struct platform_device *pdev)
4138 4151 netif_set_real_num_rx_queues(priv->dev, priv->hw_params->rx_queues + 1);
4139 4152
4140 4153 /* Set default coalescing parameters */
4141 - for (i = 0; i <= priv->hw_params->rx_queues; i++)
4154 + for (i = 0; i <= priv->hw_params->rx_queues; i++) {
4155 + priv->rx_rings[i].priv = priv;
4156 + priv->rx_rings[i].index = i;
4142 4157 priv->rx_rings[i].rx_max_coalesced_frames = 1;
4158 + }
4143 4159
4144 4160 /* Initialize u64 stats seq counter for 32bit machines */
4145 4161 for (i = 0; i <= GENET_MAX_MQ_CNT; i++) {
modified drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -470,6 +470,8 @@ struct bcmgenet_rx_stats64 {
470 470 struct enet_cb {
471 471 struct sk_buff *skb;
472 472 struct page *rx_page;
473 + unsigned int rx_offset;
474 + unsigned int rx_size;
473 475 void __iomem *bd_addr;
474 476 DEFINE_DMA_UNMAP_ADDR(dma_addr);
475 477 DEFINE_DMA_UNMAP_LEN(dma_len);
modified drivers/net/ethernet/google/gve/gve_tx_dqo.c
@@ -595,25 +595,25 @@ static int gve_prep_tso(struct sk_buff *skb)
595 595 err = skb_cow_head(skb, 0);
596 596 if (err < 0)
597 597 return err;
598 + shinfo = skb_shinfo(skb);
598 599
599 600 l4_start = skb_transport_offset(skb);
600 601 paylen = skb->len - l4_start;
601 602
602 - switch (shinfo->gso_type) {
603 - case SKB_GSO_TCPV4:
604 - case SKB_GSO_TCPV6:
603 + /* gso_type is a bitmask: SKB_GSO_DODGY, SKB_GSO_TCP_ECN and
604 + * SKB_GSO_TCP_FIXEDID may be set alongside the protocol bit.
605 + */
606 + if (shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
605 607 tcp = tcp_hdr(skb);
606 608 csum_replace_by_diff(&tcp->check,
607 609 (__force __wsum)htonl(paylen));
608 610 header_len = skb_tcp_all_headers(skb);
609 - break;
610 - case SKB_GSO_UDP_L4:
611 + } else if (shinfo->gso_type & SKB_GSO_UDP_L4) {
611 612 udp = udp_hdr(skb);
612 613 csum_replace_by_diff(&udp->check,
613 614 (__force __wsum)htonl(paylen));
614 615 header_len = sizeof(struct udphdr) + l4_start;
615 - break;
616 - default:
616 + } else {
617 617 return -EINVAL;
618 618 }
619 619
modified drivers/net/ethernet/marvell/mvneta.c
@@ -2340,7 +2340,7 @@ mvneta_swbm_rx_frame(struct mvneta_port *pp,
2340 2340
2341 2341 /* Prefetch header */
2342 2342 prefetch(data);
2343 - xdp_buff_clear_frags_flag(xdp);
2343 + xdp_reinit_buff(xdp);
2344 2344 xdp_prepare_buff(xdp, data, pp->rx_offset_correction + MVNETA_MH_SIZE,
2345 2345 data_len, true);
2346 2346 }
modified drivers/net/ethernet/marvell/octeontx2/af/mcs.c
@@ -314,7 +314,7 @@ int mcs_clear_all_stats(struct mcs *mcs, u16 pcifunc, int dir)
314 314 }
315 315
316 316 /* Clear SC stats */
317 - for (id = 0; id < map->secy.max; id++) {
317 + for (id = 0; id < map->sc.max; id++) {
318 318 if (map->sc2pf_map[id] != pcifunc)
319 319 continue;
320 320 mcs_clear_stats(mcs, MCS_SC_STATS, id, dir);
@@ -738,7 +738,7 @@ int mcs_free_all_rsrc(struct mcs *mcs, int dir, u16 pcifunc)
738 738 }
739 739
740 740 /* free sc entries */
741 - for (id = 0; id < map->secy.max; id++) {
741 + for (id = 0; id < map->sc.max; id++) {
742 742 if (map->sc2pf_map[id] != pcifunc)
743 743 continue;
744 744 mcs_free_rsrc(&map->sc, map->sc2pf_map, id, pcifunc);
modified drivers/net/ethernet/marvell/octeontx2/nic/cn20k.c
@@ -242,15 +242,6 @@ int cn20k_register_pfvf_mbox_intr(struct otx2_nic *pf, int numvfs)
242 242
243 243 #define RQ_BP_LVL_AURA (255 - ((85 * 256) / 100)) /* BP when 85% is full */
244 244
245 - static u8 cn20k_aura_bpid_idx(struct otx2_nic *pfvf, int aura_id)
246 - {
247 - #ifdef CONFIG_DCB
248 - return pfvf->queue_to_pfc_map[aura_id];
249 - #else
250 - return 0;
251 - #endif
252 - }
253 -
254 245 static int cn20k_tc_get_entry_index(struct otx2_flow_config *flow_cfg,
255 246 struct otx2_tc_flow *node)
256 247 {
@@ -580,7 +571,7 @@ static int cn20k_aura_aq_init(struct otx2_nic *pfvf, int aura_id,
580 571 if (pfvf->nix_blkaddr == BLKADDR_NIX1)
581 572 aq->aura.bp_ena = 1;
582 573
583 - bpid_idx = cn20k_aura_bpid_idx(pfvf, aura_id);
574 + bpid_idx = otx2_get_bpid_idx(pfvf, aura_id);
584 575 aq->aura.bpid = pfvf->bpid[bpid_idx];
585 576
586 577 /* Set backpressure level for RQ's Aura */
modified drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -394,7 +394,7 @@ int otx2_rss_init(struct otx2_nic *pfvf)
394 394 struct otx2_rss_info *rss = &pfvf->hw.rss_info;
395 395 int idx, ret = 0;
396 396
397 - rss->rss_size = sizeof(*rss->ind_tbl);
397 + rss->rss_size = ARRAY_SIZE(rss->ind_tbl);
398 398
399 399 /* Init RSS key if it is not setup already */
400 400 if (!rss->enable)
@@ -1055,6 +1055,7 @@ int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
1055 1055 struct nix_aq_enq_req *aq;
1056 1056 struct otx2_cq_queue *cq;
1057 1057 struct otx2_pool *pool;
1058 + u8 bpid_idx;
1058 1059
1059 1060 cq = &qset->cq[qidx];
1060 1061 cq->cq_idx = qidx;
@@ -1132,11 +1133,8 @@ int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
1132 1133 if (!is_otx2_lbkvf(pfvf->pdev)) {
1133 1134 /* Enable receive CQ backpressure */
1134 1135 aq->cq.bp_ena = 1;
1135 - #ifdef CONFIG_DCB
1136 - aq->cq.bpid = pfvf->bpid[pfvf->queue_to_pfc_map[qidx]];
1137 - #else
1138 - aq->cq.bpid = pfvf->bpid[0];
1139 - #endif
1136 + bpid_idx = otx2_get_bpid_idx(pfvf, qidx);
1137 + aq->cq.bpid = pfvf->bpid[bpid_idx];
1140 1138
1141 1139 /* Set backpressure level is same as cq pass level */
1142 1140 aq->cq.bp = RQ_PASS_LVL_CQ(pfvf->hw.rq_skid, qset->rqe_cnt);
@@ -1378,6 +1376,7 @@ int otx2_aura_aq_init(struct otx2_nic *pfvf, int aura_id,
1378 1376 {
1379 1377 struct npa_aq_enq_req *aq;
1380 1378 struct otx2_pool *pool;
1379 + u8 bpid_idx;
1381 1380 int err;
1382 1381
1383 1382 pool = &pfvf->qset.pool[pool_id];
@@ -1433,11 +1432,8 @@ int otx2_aura_aq_init(struct otx2_nic *pfvf, int aura_id,
1433 1432 */
1434 1433 if (pfvf->nix_blkaddr == BLKADDR_NIX1)
1435 1434 aq->aura.bp_ena = 1;
1436 - #ifdef CONFIG_DCB
1437 - aq->aura.nix0_bpid = pfvf->bpid[pfvf->queue_to_pfc_map[aura_id]];
1438 - #else
1439 - aq->aura.nix0_bpid = pfvf->bpid[0];
1440 - #endif
1435 + bpid_idx = otx2_get_bpid_idx(pfvf, aura_id);
1436 + aq->aura.nix0_bpid = pfvf->bpid[bpid_idx];
1441 1437
1442 1438 /* Set backpressure level for RQ's Aura */
1443 1439 aq->aura.bp = RQ_BP_LVL_AURA;
modified drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
@@ -1029,6 +1029,15 @@ static inline int otx2_tc_flower_rule_cnt(struct otx2_nic *pfvf)
1029 1029 return pfvf->flow_cfg->nr_flows;
1030 1030 }
1031 1031
1032 + static inline u8 otx2_get_bpid_idx(struct otx2_nic *pfvf, int qidx)
1033 + {
1034 + #ifdef CONFIG_DCB
1035 + if (pfvf->queue_to_pfc_map)
1036 + return pfvf->queue_to_pfc_map[qidx];
1037 + #endif
1038 + return 0;
1039 + }
1040 +
1032 1041 /* MSI-X APIs */
1033 1042 void otx2_free_cints(struct otx2_nic *pfvf, int n);
1034 1043 void otx2_set_cints_affinity(struct otx2_nic *pfvf);
modified drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -5341,6 +5341,22 @@ static int mtk_probe(struct platform_device *pdev)
5341 5341 }
5342 5342 }
5343 5343
5344 + /* we run 2 devices on the same DMA ring so we need a dummy device
5345 + * for NAPI to work. Allocate it before registering the netdevs so a
5346 + * concurrent ndo_open (e.g. netifd bringing the first netdev up the
5347 + * instant it is registered) never observes eth->dummy_dev == NULL in
5348 + * mtk_dma_init() -> mtk_rx_alloc() -> __xdp_rxq_info_reg() (net/core/xdp.c
5349 + * "Missing net_device from driver") and fails the first open.
5350 + */
5351 + eth->dummy_dev = alloc_netdev_dummy(0);
5352 + if (!eth->dummy_dev) {
5353 + err = -ENOMEM;
5354 + dev_err(eth->dev, "failed to allocated dummy device\n");
5355 + goto err_unreg_netdev;
5356 + }
5357 + netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
5358 + netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
5359 +
5344 5360 for (i = 0; i < MTK_MAX_DEVS; i++) {
5345 5361 if (!eth->netdev[i])
5346 5362 continue;
@@ -5355,18 +5371,6 @@ static int mtk_probe(struct platform_device *pdev)
5355 5371 eth->netdev[i]->base_addr, eth->irq[MTK_FE_IRQ_SHARED]);
5356 5372 }
5357 5373
5358 - /* we run 2 devices on the same DMA ring so we need a dummy device
5359 - * for NAPI to work
5360 - */
5361 - eth->dummy_dev = alloc_netdev_dummy(0);
5362 - if (!eth->dummy_dev) {
5363 - err = -ENOMEM;
5364 - dev_err(eth->dev, "failed to allocated dummy device\n");
5365 - goto err_unreg_netdev;
5366 - }
5367 - netif_napi_add(eth->dummy_dev, &eth->tx_napi, mtk_napi_tx);
5368 - netif_napi_add(eth->dummy_dev, &eth->rx_napi, mtk_napi_rx);
5369 -
5370 5374 platform_set_drvdata(pdev, eth);
5371 5375 schedule_delayed_work(&eth->reset.monitor_work,
5372 5376 MTK_DMA_MONITOR_TIMEOUT);
@@ -5376,6 +5380,16 @@ static int mtk_probe(struct platform_device *pdev)
5376 5380 err_unreg_netdev:
5377 5381 mtk_unreg_dev(eth);
5378 5382 err_deinit_ppe:
5383 + /* A netdev opened while probe was still registering can have queued
5384 + * the frame-engine reset worker, which takes rtnl and drives the
5385 + * hardware; cancel it before anything below is torn down.
5386 + */
5387 + cancel_work_sync(&eth->pending_work);
5388 + if (eth->dummy_dev) {
5389 + netif_napi_del(&eth->tx_napi);
5390 + netif_napi_del(&eth->rx_napi);
5391 + free_netdev(eth->dummy_dev);
5392 + }
5379 5393 mtk_ppe_deinit(eth);
5380 5394 mtk_mdio_cleanup(eth);
5381 5395 err_free_dev:
modified drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
@@ -293,6 +293,9 @@ static u64 mlx5e_xsk_fill_timestamp(void *_priv)
293 293 struct mlx5e_xsk_tx_complete *priv = _priv;
294 294 u64 ts;
295 295
296 + if (!priv->cqe)
297 + return 0;
298 +
296 299 ts = get_cqe_ts(priv->cqe);
297 300
298 301 if (mlx5_is_real_time_rq(priv->cq->mdev) || mlx5_is_real_time_sq(priv->cq->mdev))
modified drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -1943,9 +1943,11 @@ static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
1943 1943 }
1944 1944 }
1945 1945 if (i < MLX5_MAX_PORTS) {
1946 - slave = bond_slave_get_rcu(ndev_tmp);
1947 - if (slave)
1948 - has_inactive |= bond_is_slave_inactive(slave);
1946 + if (netif_is_bond_master(upper)) {
1947 + slave = bond_slave_get_rcu(ndev_tmp);
1948 + if (slave)
1949 + has_inactive |= bond_is_slave_inactive(slave);
1950 + }
1949 1951 bond_status |= (1 << idx);
1950 1952 }
1951 1953
@@ -2029,7 +2031,7 @@ static int mlx5_handle_changeinfodata_event(struct mlx5_lag *ldev,
2029 2031 bool has_inactive = 0;
2030 2032 int idx;
2031 2033
2032 - if (!netif_is_lag_master(ndev))
2034 + if (!netif_is_bond_master(ndev))
2033 2035 return 0;
2034 2036
2035 2037 rcu_read_lock();
modified drivers/net/ethernet/microchip/sparx5/sparx5_main.c
@@ -898,6 +898,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
898 898 dev_info(sparx5->dev, "MAC addr was not set, use random MAC\n");
899 899 eth_random_addr(sparx5->base_mac);
900 900 sparx5->base_mac[5] = 0;
901 + sparx5->base_mac_assign_type = NET_ADDR_RANDOM;
901 902 }
902 903
903 904 sparx5->fdma_irq = platform_get_irq_byname(sparx5->pdev, "fdma");
modified drivers/net/ethernet/microchip/sparx5/sparx5_main.h
@@ -392,6 +392,7 @@ struct sparx5 {
392 392 struct notifier_block switchdev_blocking_nb;
393 393 /* Switch state */
394 394 u8 base_mac[ETH_ALEN];
395 + u8 base_mac_assign_type;
395 396 /* Associated bridge device (when bridged) */
396 397 struct net_device *hw_bridge_dev;
397 398 /* Bridged interfaces */
modified drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c
@@ -294,6 +294,7 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno)
294 294 ndev->ethtool_ops = &sparx5_ethtool_ops;
295 295
296 296 eth_hw_addr_gen(ndev, sparx5->base_mac, portno + 1);
297 + ndev->addr_assign_type = sparx5->base_mac_assign_type;
297 298
298 299 return ndev;
299 300 }
modified drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
@@ -673,6 +673,9 @@ void sparx5_ptp_deinit(struct sparx5 *sparx5)
673 673 struct sparx5_port *port;
674 674 int i;
675 675
676 + if (!sparx5->ptp)
677 + return;
678 +
676 679 if (sparx5->ptp_irq >= 0) {
677 680 disable_irq(sparx5->ptp_irq);
678 681 sparx5->ptp_irq = -ENXIO;
modified drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -3527,8 +3527,8 @@ int vcap_filter_rule_keys(struct vcap_rule *rule,
3527 3527 if (key == keylist[idx]) {
3528 3528 list_del(&ckf->ctrl.list);
3529 3529 kfree(ckf);
3530 - idx++;
3531 3530 err = 0;
3531 + break;
3532 3532 }
3533 3533 }
3534 3534 }
modified drivers/net/ethernet/realtek/r8169_main.c
@@ -5484,6 +5484,12 @@ static int r8169_mdio_register(struct rtl8169_private *tp)
5484 5484 phy_disable_eee_mode(tp->phydev,
5485 5485 ETHTOOL_LINK_MODE_2500baseT_Full_BIT);
5486 5486
5487 + /* Keep EEE off but the version stays EEE-capable so that link-up
5488 + * still clears the MAC TX-LPI bits.
5489 + */
5490 + if (tp->mac_version == RTL_GIGA_MAC_VER_46)
5491 + phy_disable_eee(tp->phydev);
5492 +
5487 5493 /* PHY will be woken up in rtl_open() */
5488 5494 phy_suspend(tp->phydev);
5489 5495
modified drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -1629,6 +1629,16 @@ static void stmmac_clear_descriptors(struct stmmac_priv *priv,
1629 1629 stmmac_clear_tx_descriptors(priv, dma_conf, queue);
1630 1630 }
1631 1631
1632 + static bool stmmac_rx_check_buf2_cap(struct stmmac_priv *priv)
1633 + {
1634 + /* Only cores that can program an independent secondary RX buffer
1635 + * (used for scatter-gather overflow or split-header payload) back
1636 + * buffer2. Legacy cores have no set_sec_addr op, so buffer2 is
1637 + * never handed to the hardware there.
1638 + */
1639 + return priv->hw->desc && priv->hw->desc->set_sec_addr;
1640 + }
1641 +
1632 1642 /**
1633 1643 * stmmac_init_rx_buffers - init the RX descriptor buffer.
1634 1644 * @priv: driver private structure
@@ -1659,16 +1669,13 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv,
1659 1669 buf->page_offset = stmmac_rx_offset(priv);
1660 1670 }
1661 1671
1662 - if (priv->sph_active && !buf->sec_page) {
1672 + if (stmmac_rx_check_buf2_cap(priv) && !buf->sec_page) {
1663 1673 buf->sec_page = page_pool_alloc_pages(rx_q->page_pool, gfp);
1664 1674 if (!buf->sec_page)
1665 1675 return -ENOMEM;
1666 1676
1667 1677 buf->sec_addr = page_pool_get_dma_addr(buf->sec_page);
1668 1678 stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, true);
1669 - } else {
1670 - buf->sec_page = NULL;
1671 - stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, false);
1672 1679 }
1673 1680
1674 1681 buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
@@ -2256,13 +2263,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
2256 2263 pp_params.nid = dev_to_node(priv->device);
2257 2264 pp_params.dev = priv->device;
2258 2265 pp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
2259 - pp_params.offset = stmmac_rx_offset(priv);
2260 - pp_params.max_len = dma_conf->dma_buf_sz;
2261 -
2262 - if (priv->sph_active) {
2263 - pp_params.offset = 0;
2264 - pp_params.max_len += stmmac_rx_offset(priv);
2265 - }
2266 + pp_params.offset = 0;
2267 + pp_params.max_len = dma_conf->dma_buf_sz + stmmac_rx_offset(priv);
2266 2268
2267 2269 rx_q->page_pool = page_pool_create(&pp_params);
2268 2270 if (IS_ERR(rx_q->page_pool)) {
@@ -5099,7 +5101,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
5099 5101 break;
5100 5102 }
5101 5103
5102 - if (priv->sph_active && !buf->sec_page) {
5104 + if (stmmac_rx_check_buf2_cap(priv) && !buf->sec_page) {
5103 5105 buf->sec_page = page_pool_alloc_pages(rx_q->page_pool, gfp);
5104 5106 if (!buf->sec_page)
5105 5107 break;
@@ -5110,10 +5112,8 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue)
5110 5112 buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
5111 5113
5112 5114 stmmac_set_desc_addr(priv, p, buf->addr);
5113 - if (priv->sph_active)
5114 - stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, true);
5115 - else
5116 - stmmac_set_desc_sec_addr(priv, p, buf->sec_addr, false);
5115 + stmmac_set_desc_sec_addr(priv, p, buf->sec_addr,
5116 + stmmac_rx_check_buf2_cap(priv));
5117 5117 stmmac_refill_desc3(priv, rx_q, p);
5118 5118
5119 5119 rx_q->rx_count_frames++;
@@ -5144,7 +5144,9 @@ static unsigned int stmmac_rx_buf1_len(struct stmmac_priv *priv,
5144 5144 unsigned int plen = 0, hlen = 0;
5145 5145 int coe = priv->hw->rx_csum;
5146 5146
5147 - /* Not first descriptor, buffer is always zero */
5147 + /* Not first descriptor, SPH enabled: buffer1 only carries the
5148 + * split header of the first descriptor, so it is zero here.
5149 + */
5148 5150 if (priv->sph_active && len)
5149 5151 return 0;
5150 5152
@@ -5155,14 +5157,16 @@ static unsigned int stmmac_rx_buf1_len(struct stmmac_priv *priv,
5155 5157 return hlen;
5156 5158 }
5157 5159
5158 - /* First descriptor, not last descriptor and not split header */
5160 + /* Not last descriptor and not split header: buffer1 is fully filled */
5159 5161 if (status & rx_not_ls)
5160 5162 return priv->dma_conf.dma_buf_sz;
5161 5163
5162 5164 plen = stmmac_get_rx_frame_len(priv, p, coe);
5163 5165
5164 - /* First descriptor and last descriptor and not split header */
5165 - return min_t(unsigned int, priv->dma_conf.dma_buf_sz, plen);
5166 + /* Last descriptor and not split header: buffer1 holds the remaining
5167 + * bytes of the frame, up to dma_buf_sz
5168 + */
5169 + return min_t(unsigned int, priv->dma_conf.dma_buf_sz, plen - len);
5166 5170 }
5167 5171
5168 5172 static unsigned int stmmac_rx_buf2_len(struct stmmac_priv *priv,
@@ -5172,8 +5176,7 @@ static unsigned int stmmac_rx_buf2_len(struct stmmac_priv *priv,
5172 5176 int coe = priv->hw->rx_csum;
5173 5177 unsigned int plen = 0;
5174 5178
5175 - /* Not split header, buffer is not available */
5176 - if (!priv->sph_active)
5179 + if (!stmmac_rx_check_buf2_cap(priv))
5177 5180 return 0;
5178 5181
5179 5182 /* For GMAC4, when split header is enabled, in some rare cases, the
@@ -5190,14 +5193,15 @@ static unsigned int stmmac_rx_buf2_len(struct stmmac_priv *priv,
5190 5193 * Thus 'plen - len' always gives the correct length of buf2.
5191 5194 */
5192 5195
5193 - /* Not GMAC4 and not last descriptor */
5194 - if (priv->plat->core_type != DWMAC_CORE_GMAC4 && (status & rx_not_ls))
5196 + /* Not GMAC4, or non-SPH and not last descriptor */
5197 + if ((priv->plat->core_type != DWMAC_CORE_GMAC4 || !priv->sph_active) &&
5198 + (status & rx_not_ls))
5195 5199 return priv->dma_conf.dma_buf_sz;
5196 5200
5197 5201 /* GMAC4 or last descriptor */
5198 5202 plen = stmmac_get_rx_frame_len(priv, p, coe);
5199 5203
5200 - return plen - len;
5204 + return plen > len ? plen - len : 0;
5201 5205 }
5202 5206
5203 5207 static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
@@ -5720,6 +5724,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
5720 5724 unsigned int desc_size;
5721 5725 struct sk_buff *skb = NULL;
5722 5726 struct stmmac_xdp_buff ctx;
5727 + bool fcs_stripped = false;
5723 5728 int xdp_status = 0;
5724 5729 int bufsz;
5725 5730
@@ -5809,24 +5814,25 @@ read_again:
5809 5814 len += buf2_len;
5810 5815
5811 5816 /* ACS is disabled; strip manually. */
5812 - if (likely(!(status & rx_not_ls))) {
5813 - if (buf2_len) {
5814 - buf2_len -= ETH_FCS_LEN;
5815 - len -= ETH_FCS_LEN;
5816 - } else if (buf1_len) {
5817 - buf1_len -= ETH_FCS_LEN;
5818 - len -= ETH_FCS_LEN;
5819 - }
5820 - }
5817 + if (likely(!(status & rx_not_ls)))
5818 + len -= ETH_FCS_LEN;
5821 5819
5822 5820 if (!skb) {
5823 5821 unsigned int pre_len, sync_len;
5824 5822
5823 + /* Each frame starts here: reset the FCS handling */
5824 + fcs_stripped = false;
5825 +
5825 5826 dma_sync_single_for_cpu(priv->device, buf->addr,
5826 5827 buf1_len, dma_dir);
5827 5828 net_prefetch(page_address(buf->page) +
5828 5829 buf->page_offset);
5829 5830
5831 + if (stmmac_xdp_is_enabled(priv) && !buf2_len) {
5832 + buf1_len -= ETH_FCS_LEN;
5833 + fcs_stripped = true;
5834 + }
5835 +
5830 5836 xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq);
5831 5837 xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
5832 5838 buf->page_offset, buf1_len, true);
@@ -5927,6 +5933,15 @@ drain_data:
5927 5933
5928 5934 /* Got entire packet into SKB. Finish it. */
5929 5935
5936 + /* Remove FCS if needed */
5937 + if (!fcs_stripped && pskb_trim(skb, len)) {
5938 + dev_kfree_skb_any(skb);
5939 + skb = NULL;
5940 + rx_dropped++;
5941 + count++;
5942 + continue;
5943 + }
5944 +
5930 5945 stmmac_get_rx_hwtstamp(priv, p, np, skb);
5931 5946
5932 5947 if (priv->hw->hw_vlan_en)
modified drivers/net/pcs/pcs-rzn1-miic.c
@@ -270,6 +270,9 @@ static struct miic_port *phylink_pcs_to_miic_port(struct phylink_pcs *pcs)
270 270
271 271 static void miic_unlock_regs(struct miic *miic)
272 272 {
273 + /* Clear protection state */
274 + writel(0x0000, miic->base + MIIC_PRCMD);
275 +
273 276 /* Unprotect register writes */
274 277 writel(0x00A5, miic->base + MIIC_PRCMD);
275 278 writel(0x0001, miic->base + MIIC_PRCMD);
modified drivers/net/pfcp.c
@@ -105,6 +105,9 @@ drop:
105 105
106 106 static void pfcp_del_sock(struct pfcp_dev *pfcp)
107 107 {
108 + if (!pfcp->sk)
109 + return;
110 +
108 111 udp_tunnel_sock_release(pfcp->sk);
109 112 pfcp->sk = NULL;
110 113 }
modified drivers/net/phy/aquantia/aquantia_main.c
@@ -544,7 +544,7 @@ static int aqr_gen1_read_status(struct phy_device *phydev)
544 544 if (ret)
545 545 return ret;
546 546
547 - if (!phydev->link || phydev->autoneg == AUTONEG_DISABLE)
547 + if (!phydev->link)
548 548 return 0;
549 549
550 550 /* The status register is not immediately correct on line side link up.
@@ -594,6 +594,9 @@ static int aqr_gen1_read_status(struct phy_device *phydev)
594 594
595 595 phydev->interface = aqr_translate_interface(phydev, interface);
596 596
597 + if (phydev->autoneg == AUTONEG_DISABLE)
598 + return 0;
599 +
597 600 /* Read rate from vendor register */
598 601 return aqr_gen1_read_rate(phydev);
599 602 }
modified drivers/net/phy/qcom/at803x.c
@@ -1051,11 +1051,15 @@ static int ipq5018_config_init(struct phy_device *phydev)
1051 1051 if (priv->set_short_cable_dac) {
1052 1052 /* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */
1053 1053 phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, IPQ5018_PHY_MMD1_MDAC,
1054 - IPQ5018_PHY_DAC_MASK, IPQ5018_PHY_MMD1_MDAC_VAL);
1054 + IPQ5018_PHY_DAC_MASK,
1055 + FIELD_PREP(IPQ5018_PHY_DAC_MASK,
1056 + IPQ5018_PHY_MMD1_MDAC_VAL));
1055 1057
1056 1058 /* setting EDAC (Error-detection and Correction) in debug register */
1057 1059 at803x_debug_reg_mask(phydev, IPQ5018_PHY_DEBUG_EDAC,
1058 - IPQ5018_PHY_DAC_MASK, IPQ5018_PHY_DEBUG_EDAC_VAL);
1060 + IPQ5018_PHY_DAC_MASK,
1061 + FIELD_PREP(IPQ5018_PHY_DAC_MASK,
1062 + IPQ5018_PHY_DEBUG_EDAC_VAL));
1059 1063 }
1060 1064
1061 1065 return 0;
modified drivers/net/usb/qmi_wwan.c
@@ -1455,6 +1455,7 @@ static const struct usb_device_id products[] = {
1455 1455 {QMI_QUIRK_SET_DTR(0x1546, 0x1312, 4)}, /* u-blox LARA-R6 01B */
1456 1456 {QMI_QUIRK_SET_DTR(0x1546, 0x1342, 4)}, /* u-blox LARA-L6 */
1457 1457 {QMI_QUIRK_SET_DTR(0x33f8, 0x0104, 4)}, /* Rolling RW101 RMNET */
1458 + {QMI_QUIRK_SET_DTR(0x33f8, 0x9300, 8)}, /* Rolling RN947R RMNET */
1458 1459 {QMI_FIXED_INTF(0x2dee, 0x4d22, 5)}, /* MeiG Smart SRM825L */
1459 1460 {QMI_QUIRK_SET_DTR(0x2dee, 0x4d63, 0)}, /* MeiG SRM813Q w/ Modem(PPP) */
1460 1461 {QMI_QUIRK_SET_DTR(0x2dee, 0x4d64, 0)}, /* MeiG SRM813Q w/ NMEA */
modified drivers/net/wireless/ath/ath11k/mac.c
@@ -6716,6 +6716,7 @@ static int ath11k_mac_op_start(struct ieee80211_hw *hw)
6716 6716 ar->num_started_vdevs = 0;
6717 6717 ar->num_created_vdevs = 0;
6718 6718 ar->num_peers = 0;
6719 + ar->num_stations = 0;
6719 6720 ar->allocated_vdev_map = 0;
6720 6721
6721 6722 /* Configure monitor status ring with default rx_filter to get rx status
modified drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -14,6 +14,7 @@
14 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 15 */
16 16
17 + #include <linux/math.h>
17 18 #include <linux/unaligned.h>
18 19 #include "htc.h"
19 20
@@ -328,11 +329,14 @@ static int __hif_usb_tx(struct hif_device_usb *hif_dev)
328 329 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM);
329 330
330 331 for (i = 0; i < tx_skb_cnt; i++) {
331 - nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
332 + nskb = skb_peek(&hif_dev->tx.tx_skb_queue);
333 + if (!nskb)
334 + break;
332 335
333 - /* Should never be NULL */
334 - BUG_ON(!nskb);
336 + if (tx_buf->offset + nskb->len + 4 > MAX_TX_BUF_SIZE)
337 + break;
335 338
339 + nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue);
336 340 hif_dev->tx.tx_skb_cnt--;
337 341
338 342 buf = tx_buf->buf;
@@ -342,13 +346,8 @@ static int __hif_usb_tx(struct hif_device_usb *hif_dev)
342 346 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG);
343 347 buf += 4;
344 348 memcpy(buf, nskb->data, nskb->len);
345 - tx_buf->len = nskb->len + 4;
346 -
347 - if (i < (tx_skb_cnt - 1))
348 - tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4;
349 -
350 - if (i == (tx_skb_cnt - 1))
351 - tx_buf->len += tx_buf->offset;
349 + tx_buf->len = tx_buf->offset + nskb->len + 4;
350 + tx_buf->offset += round_up(nskb->len + 4, 4);
352 351
353 352 __skb_queue_tail(&tx_buf->skb_queue, nskb);
354 353 TX_STAT_INC(hif_dev, skb_queued);
modified drivers/net/wireless/ath/ath9k/htc.h
@@ -281,7 +281,6 @@ struct ath9k_htc_rxbuf {
281 281 struct ath9k_htc_rx {
282 282 struct list_head rxbuf;
283 283 spinlock_t rxbuflock;
284 - bool initialized;
285 284 };
286 285
287 286 #define ATH9K_HTC_TX_CLEANUP_INTERVAL 50 /* ms */
modified drivers/net/wireless/ath/ath9k/htc_drv_init.c
@@ -910,6 +910,9 @@ static int ath9k_init_device(struct ath9k_htc_priv *priv,
910 910 ath9k_init_leds(priv);
911 911 ath9k_start_rfkill_poll(priv);
912 912
913 + /* signal completion to ath9k_htc_rxep() and ath9k_wmi_event_tasklet() */
914 + smp_store_release(&priv->initialized, true);
915 +
913 916 return 0;
914 917
915 918 err_world:
@@ -966,10 +969,6 @@ int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev,
966 969
967 970 htc_handle->drv_priv = priv;
968 971
969 - /* Allow ath9k_wmi_event_tasklet() to operate. */
970 - smp_wmb();
971 - priv->initialized = true;
972 -
973 972 return 0;
974 973
975 974 err_init:
modified drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
@@ -1141,8 +1141,8 @@ void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
1141 1141 struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
1142 1142 unsigned long flags;
1143 1143
1144 - /* Check if ath9k_rx_init() completed. */
1145 - if (!data_race(priv->rx.initialized))
1144 + /* Check if ath9k_init_device() completed. */
1145 + if (!smp_load_acquire(&priv->initialized))
1146 1146 goto err;
1147 1147
1148 1148 spin_lock_irqsave(&priv->rx.rxbuflock, flags);
@@ -1200,10 +1200,6 @@ int ath9k_rx_init(struct ath9k_htc_priv *priv)
1200 1200 list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
1201 1201 }
1202 1202
1203 - /* Allow ath9k_htc_rxep() to operate. */
1204 - smp_wmb();
1205 - priv->rx.initialized = true;
1206 -
1207 1203 return 0;
1208 1204
1209 1205 err:
modified drivers/net/wireless/ath/ath9k/wmi.c
@@ -146,6 +146,12 @@ void ath9k_wmi_event_tasklet(struct tasklet_struct *t)
146 146 unsigned long flags;
147 147 u16 cmd_id;
148 148
149 + /* Check if ath9k_init_device() completed. */
150 + if (!smp_load_acquire(&priv->initialized)) {
151 + tasklet_schedule(t);
152 + return;
153 + }
154 +
149 155 do {
150 156 spin_lock_irqsave(&wmi->wmi_lock, flags);
151 157 skb = __skb_dequeue(&wmi->wmi_event_queue);
@@ -155,12 +161,6 @@ void ath9k_wmi_event_tasklet(struct tasklet_struct *t)
155 161 }
156 162 spin_unlock_irqrestore(&wmi->wmi_lock, flags);
157 163
158 - /* Check if ath9k_htc_probe_device() completed. */
159 - if (!data_race(priv->initialized)) {
160 - kfree_skb(skb);
161 - continue;
162 - }
163 -
164 164 hdr = (struct wmi_cmd_hdr *) skb->data;
165 165 cmd_id = be16_to_cpu(hdr->command_id);
166 166 wmi_event = skb_pull(skb, sizeof(struct wmi_cmd_hdr));
@@ -206,9 +206,16 @@ static void ath9k_wmi_rsp_callback(struct wmi *wmi, struct sk_buff *skb)
206 206 {
207 207 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
208 208
209 - if (wmi->cmd_rsp_buf != NULL && wmi->cmd_rsp_len != 0)
209 + if (wmi->cmd_rsp_buf && wmi->cmd_rsp_len) {
210 + if (skb->len < wmi->cmd_rsp_len) {
211 + wmi->cmd_rsp_status = -EMSGSIZE;
212 + goto complete;
213 + }
210 214 memcpy(wmi->cmd_rsp_buf, skb->data, wmi->cmd_rsp_len);
215 + }
216 + wmi->cmd_rsp_status = 0;
211 217
218 + complete:
212 219 complete(&wmi->cmd_wait);
213 220 }
214 221
@@ -300,6 +307,7 @@ static int ath9k_wmi_cmd_issue(struct wmi *wmi,
300 307 /* record the rsp buffer and length */
301 308 wmi->cmd_rsp_buf = rsp_buf;
302 309 wmi->cmd_rsp_len = rsp_len;
310 + wmi->cmd_rsp_status = 0;
303 311
304 312 wmi->last_seq_id = wmi->tx_seq_id;
305 313 spin_unlock_irqrestore(&wmi->wmi_lock, flags);
@@ -356,9 +364,13 @@ int ath9k_wmi_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id,
356 364 return -ETIMEDOUT;
357 365 }
358 366
367 + spin_lock_irqsave(&wmi->wmi_lock, flags);
368 + ret = wmi->cmd_rsp_status;
369 + spin_unlock_irqrestore(&wmi->wmi_lock, flags);
370 +
359 371 mutex_unlock(&wmi->op_mutex);
360 372
361 - return 0;
373 + return ret;
362 374
363 375 out:
364 376 ath_dbg(common, WMI, "WMI failure for: %s\n", wmi_cmd_to_name(cmd_id));
modified drivers/net/wireless/ath/ath9k/wmi.h
@@ -157,6 +157,7 @@ struct wmi {
157 157 u16 tx_seq_id;
158 158 u8 *cmd_rsp_buf;
159 159 u32 cmd_rsp_len;
160 + int cmd_rsp_status;
160 161 bool stopped;
161 162
162 163 struct list_head pending_tx_events;
modified drivers/net/wireless/intel/iwlegacy/3945-mac.c
@@ -3807,6 +3807,7 @@ il3945_pci_remove(struct pci_dev *pdev)
3807 3807
3808 3808 il_free_channel_map(il);
3809 3809 il_free_geos(il);
3810 + il_eeprom_free(il);
3810 3811 kfree(il->scan_cmd);
3811 3812 dev_kfree_skb(il->beacon_skb);
3812 3813 ieee80211_free_hw(il->hw);
modified drivers/net/wireless/intersil/p54/fwio.c
@@ -52,6 +52,13 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
52 52 u32 code = le32_to_cpu(bootrec->code);
53 53 switch (code) {
54 54 case BR_CODE_COMPONENT_ID:
55 + if (len < sizeof(struct bootrec_comp_id) /
56 + sizeof(*bootrec->data)) {
57 + wiphy_err(priv->hw->wiphy,
58 + "firmware component ID is too short\n");
59 + return -EINVAL;
60 + }
61 +
55 62 priv->fw_interface = be32_to_cpup((__be32 *)
56 63 bootrec->data);
57 64 switch (priv->fw_interface) {
@@ -72,16 +79,41 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
72 79 }
73 80 break;
74 81 case BR_CODE_COMPONENT_VERSION:
82 + if (len < DIV_ROUND_UP(sizeof(struct bootrec_comp_ver),
83 + sizeof(*bootrec->data))) {
84 + wiphy_err(priv->hw->wiphy,
85 + "firmware component version is too short\n");
86 + return -EINVAL;
87 + }
88 +
75 89 /* 24 bytes should be enough for all firmwares */
76 - if (strnlen((unsigned char *) bootrec->data, 24) < 24)
77 - fw_version = (unsigned char *) bootrec->data;
90 + if (strnlen((unsigned char *)bootrec->data,
91 + sizeof(struct bootrec_comp_ver)) <
92 + sizeof(struct bootrec_comp_ver))
93 + fw_version = (unsigned char *)bootrec->data;
78 94 break;
79 95 case BR_CODE_DESCR: {
80 96 struct bootrec_desc *desc =
81 97 (struct bootrec_desc *)bootrec->data;
82 - priv->rx_start = le32_to_cpu(desc->rx_start);
83 - /* FIXME add sanity checking */
84 - priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
98 + u32 rx_start, rx_end;
99 +
100 + /* 0xa is the shortest descriptor in supported firmware. */
101 + if (len < 0xa) {
102 + wiphy_err(priv->hw->wiphy,
103 + "firmware descriptor is too short\n");
104 + return -EINVAL;
105 + }
106 +
107 + rx_start = le32_to_cpu(desc->rx_start);
108 + rx_end = le32_to_cpu(desc->rx_end);
109 + if (rx_end < 0x3500 || rx_end - 0x3500 <= rx_start) {
110 + wiphy_err(priv->hw->wiphy,
111 + "firmware descriptor has invalid RX range\n");
112 + return -EINVAL;
113 + }
114 +
115 + priv->rx_start = rx_start;
116 + priv->rx_end = rx_end - 0x3500;
85 117 priv->headroom = desc->headroom;
86 118 priv->tailroom = desc->tailroom;
87 119 priv->privacy_caps = desc->privacy_caps;
modified drivers/net/wireless/silabs/wfx/hif_tx.c
@@ -207,9 +207,11 @@ int wfx_hif_read_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id, void *val, si
207 207 dev_warn(wdev->dev, "%s: confirmation mismatch request\n", __func__);
208 208 ret = -EIO;
209 209 }
210 - if (ret == -ENOMEM)
210 + if (!ret && le16_to_cpu(reply->length) > val_len) {
211 211 dev_err(wdev->dev, "buffer is too small to receive %s (%zu < %d)\n",
212 212 wfx_get_mib_name(mib_id), val_len, le16_to_cpu(reply->length));
213 + ret = -EIO;
214 + }
213 215 if (!ret)
214 216 memcpy(val, &reply->mib_data, le16_to_cpu(reply->length));
215 217 else
modified drivers/net/wireless/st/cw1200/bh.c
@@ -344,6 +344,7 @@ static int cw1200_bh_tx_helper(struct cw1200_common *priv,
344 344 int *tx_burst)
345 345 {
346 346 size_t tx_len;
347 + size_t aligned_len;
347 348 u8 *data;
348 349 int ret;
349 350 struct wsm_hdr *wsm;
@@ -376,9 +377,14 @@ static int cw1200_bh_tx_helper(struct cw1200_common *priv,
376 377
377 378 atomic_inc(&priv->bh_tx);
378 379
379 - tx_len = priv->hwbus_ops->align_size(
380 + aligned_len = priv->hwbus_ops->align_size(
380 381 priv->hwbus_priv, tx_len);
381 382
383 + /* Zero the bus alignment padding so no stale data is sent. */
384 + if (aligned_len > tx_len)
385 + memset(data + tx_len, 0, aligned_len - tx_len);
386 + tx_len = aligned_len;
387 +
382 388 /* Check if not exceeding CW1200 capabilities */
383 389 if (WARN_ON_ONCE(tx_len > EFFECTIVE_BUF_SIZE))
384 390 pr_debug("Write aligned len: %zu\n", tx_len);
modified drivers/net/wireless/st/cw1200/txrx.c
@@ -14,6 +14,7 @@
14 14 #include "wsm.h"
15 15 #include "bh.h"
16 16 #include "sta.h"
17 + #include "hwbus.h"
17 18 #include "debug.h"
18 19
19 20 #define CW1200_INVALID_RATE_ID (0xFF)
@@ -716,6 +717,7 @@ void cw1200_tx(struct ieee80211_hw *dev,
716 717 struct ieee80211_sta *sta;
717 718 struct wsm_tx *wsm;
718 719 bool tid_update = false;
720 + size_t pad_len;
719 721 u8 flags = 0;
720 722 int ret;
721 723
@@ -764,6 +766,18 @@ void cw1200_tx(struct ieee80211_hw *dev,
764 766
765 767 sta = t.sta;
766 768
769 + /*
770 + * The bus transfer is padded up to the bus alignment and the
771 + * padding is transferred from the frame buffer. Make sure the
772 + * buffer has room for the padding so the device never receives
773 + * data past the end of the frame.
774 + */
775 + pad_len = priv->hwbus_ops->align_size(priv->hwbus_priv, skb->len) -
776 + skb->len;
777 + if (skb_tailroom(skb) < pad_len &&
778 + pskb_expand_head(skb, 0, pad_len, GFP_ATOMIC))
779 + goto drop;
780 +
767 781 spin_lock_bh(&priv->ps_state_lock);
768 782 {
769 783 tid_update = cw1200_tx_h_pm_state(priv, &t);
modified drivers/net/wireless/ti/wlcore/main.c
@@ -6809,8 +6809,10 @@ void wlcore_remove(struct platform_device *pdev)
6809 6809
6810 6810 if (pdev_data->family && pdev_data->family->nvs_name)
6811 6811 wait_for_completion(&wl->nvs_loading_complete);
6812 - if (!wl->initialized)
6812 + if (!wl->initialized) {
6813 + pm_runtime_put_noidle(wl->dev);
6813 6814 return;
6815 + }
6814 6816
6815 6817 if (wl->wakeirq >= 0) {
6816 6818 dev_pm_clear_wake_irq(wl->dev);
modified drivers/nvme/host/core.c
@@ -598,7 +598,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
598 598 break;
599 599 case NVME_CTRL_RESETTING:
600 600 switch (old_state) {
601 - case NVME_CTRL_NEW:
602 601 case NVME_CTRL_LIVE:
603 602 changed = true;
604 603 atomic_long_inc(&ctrl->nr_reset);
@@ -3195,9 +3194,16 @@ static void nvme_release_subsystem(struct device *dev)
3195 3194 {
3196 3195 struct nvme_subsystem *subsys =
3197 3196 container_of(dev, struct nvme_subsystem, dev);
3197 + struct nvme_effects_log *cel;
3198 + unsigned long i;
3198 3199
3199 3200 if (subsys->instance >= 0)
3200 3201 ida_free(&nvme_instance_ida, subsys->instance);
3202 + xa_for_each(&subsys->cels, i, cel) {
3203 + xa_erase(&subsys->cels, i);
3204 + kfree(cel);
3205 + }
3206 + xa_destroy(&subsys->cels);
3201 3207 kfree(subsys);
3202 3208 }
3203 3209
@@ -3311,6 +3317,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
3311 3317 kref_init(&subsys->ref);
3312 3318 INIT_LIST_HEAD(&subsys->ctrls);
3313 3319 INIT_LIST_HEAD(&subsys->nsheads);
3320 + xa_init(&subsys->cels);
3314 3321 nvme_init_subnqn(subsys, ctrl, id);
3315 3322 memcpy(subsys->serial, id->sn, sizeof(subsys->serial));
3316 3323 memcpy(subsys->model, id->mn, sizeof(subsys->model));
@@ -3413,7 +3420,7 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
3413 3420 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
3414 3421 struct nvme_effects_log **log)
3415 3422 {
3416 - struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi);
3423 + struct nvme_effects_log *old, *cel = xa_load(&ctrl->subsys->cels, csi);
3417 3424 int ret;
3418 3425
3419 3426 if (cel)
@@ -3430,7 +3437,7 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
3430 3437 return ret;
3431 3438 }
3432 3439
3433 - old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
3440 + old = xa_store(&ctrl->subsys->cels, csi, cel, GFP_KERNEL);
3434 3441 if (xa_is_err(old)) {
3435 3442 kfree(cel);
3436 3443 return xa_err(old);
@@ -3505,7 +3512,7 @@ static int nvme_init_effects_log(struct nvme_ctrl *ctrl,
3505 3512 if (!effects)
3506 3513 return -ENOMEM;
3507 3514
3508 - old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL);
3515 + old = xa_store(&ctrl->subsys->cels, csi, effects, GFP_KERNEL);
3509 3516 if (xa_is_err(old)) {
3510 3517 kfree(effects);
3511 3518 return xa_err(old);
@@ -3551,23 +3558,27 @@ static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
3551 3558 {
3552 3559 int ret = 0;
3553 3560
3561 + mutex_lock(&ctrl->subsys->lock);
3562 + ctrl->effects = xa_load(&ctrl->subsys->cels, NVME_CSI_NVM);
3554 3563 if (ctrl->effects)
3555 - return 0;
3564 + goto out_unlock;
3556 3565
3557 3566 if (id->lpa & NVME_CTRL_LPA_CMD_EFFECTS_LOG) {
3558 3567 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects);
3559 3568 if (ret < 0)
3560 - return ret;
3569 + goto out_unlock;
3561 3570 }
3562 3571
3563 3572 if (!ctrl->effects) {
3564 3573 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects);
3565 3574 if (ret < 0)
3566 - return ret;
3575 + goto out_unlock;
3567 3576 }
3568 3577
3569 3578 nvme_init_known_nvm_effects(ctrl);
3570 - return 0;
3579 + out_unlock:
3580 + mutex_unlock(&ctrl->subsys->lock);
3581 + return ret;
3571 3582 }
3572 3583
3573 3584 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
@@ -3931,9 +3942,9 @@ void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device)
3931 3942 put_device(cdev_device);
3932 3943 }
3933 3944
3934 - int nvme_cdev_add(const char *name, struct cdev *cdev,
3935 - struct device *cdev_device,
3936 - const struct file_operations *fops, struct module *owner)
3945 + int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
3946 + const struct file_operations *fops, struct module *owner,
3947 + int ctrl, int head)
3937 3948 {
3938 3949 int minor, ret;
3939 3950
@@ -3941,7 +3952,7 @@ int nvme_cdev_add(const char *name, struct cdev *cdev,
3941 3952 if (minor < 0)
3942 3953 return minor;
3943 3954
3944 - ret = dev_set_name(cdev_device, name);
3955 + ret = dev_set_name(cdev_device, "ng%dn%d", ctrl, head);
3945 3956 if (ret) {
3946 3957 ida_free(&nvme_ns_chr_minor_ida, minor);
3947 3958 return ret;
@@ -3982,17 +3993,14 @@ static const struct file_operations nvme_ns_chr_fops = {
3982 3993
3983 3994 static void nvme_add_ns_cdev(struct nvme_ns *ns)
3984 3995 {
3985 - char name[32];
3986 -
3987 3996 ns->cdev_device.parent = ns->ctrl->device;
3988 - snprintf(name, sizeof(name), "ng%dn%d", ns->ctrl->instance,
3989 - ns->head->instance);
3990 3997
3991 3998 nvme_get_ns(ns); /* Undone in nvme_cdev_rel() */
3992 - if (nvme_cdev_add(name, &ns->cdev, &ns->cdev_device,
3993 - &nvme_ns_chr_fops, ns->ctrl->ops->module)) {
3994 - dev_err(ns->ctrl->device, "Unable to create the %s device\n",
3995 - name);
3999 + if (nvme_cdev_add(&ns->cdev, &ns->cdev_device,
4000 + &nvme_ns_chr_fops, ns->ctrl->ops->module,
4001 + ns->ctrl->instance, ns->head->instance)) {
4002 + dev_err(ns->ctrl->device, "Unable to create the ng%dn%d device\n",
4003 + ns->ctrl->instance, ns->head->instance);
3996 4004 nvme_put_ns(ns);
3997 4005 return;
3998 4006 }
@@ -5155,19 +5163,6 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
5155 5163 }
5156 5164 EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
5157 5165
5158 - static void nvme_free_cels(struct nvme_ctrl *ctrl)
5159 - {
5160 - struct nvme_effects_log *cel;
5161 - unsigned long i;
5162 -
5163 - xa_for_each(&ctrl->cels, i, cel) {
5164 - xa_erase(&ctrl->cels, i);
5165 - kfree(cel);
5166 - }
5167 -
5168 - xa_destroy(&ctrl->cels);
5169 - }
5170 -
5171 5166 static void nvme_free_ctrl(struct device *dev)
5172 5167 {
5173 5168 struct nvme_ctrl *ctrl =
@@ -5180,7 +5175,6 @@ static void nvme_free_ctrl(struct device *dev)
5180 5175 blk_put_queue(ctrl->fabrics_q);
5181 5176 if (!subsys || ctrl->instance != subsys->instance)
5182 5177 ida_free(&nvme_instance_ida, ctrl->instance);
5183 - nvme_free_cels(ctrl);
5184 5178 nvme_mpath_uninit(ctrl);
5185 5179 cleanup_srcu_struct(&ctrl->srcu);
5186 5180 nvme_auth_stop(ctrl);
@@ -5226,7 +5220,6 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
5226 5220
5227 5221 mutex_init(&ctrl->scan_lock);
5228 5222 INIT_LIST_HEAD(&ctrl->namespaces);
5229 - xa_init(&ctrl->cels);
5230 5223 ctrl->dev = dev;
5231 5224 ctrl->ops = ops;
5232 5225 ctrl->quirks = quirks;
modified drivers/nvme/host/fc.c
@@ -3338,7 +3338,7 @@ nvme_fc_reconnect_or_delete(struct nvme_fc_ctrl *ctrl, int status)
3338 3338 ctrl->cnum, min_t(int, portptr->dev_loss_tmo,
3339 3339 (ctrl->ctrl.opts->max_reconnects *
3340 3340 ctrl->ctrl.opts->reconnect_delay)));
3341 - WARN_ON(nvme_delete_ctrl(&ctrl->ctrl));
3341 + nvme_delete_ctrl(&ctrl->ctrl);
3342 3342 }
3343 3343 }
3344 3344
modified drivers/nvme/host/multipath.c
@@ -646,17 +646,15 @@ static const struct file_operations nvme_ns_head_chr_fops = {
646 646
647 647 static void nvme_add_ns_head_cdev(struct nvme_ns_head *head)
648 648 {
649 - char name[32];
650 -
651 649 head->cdev_device.parent = &head->subsys->dev;
652 - snprintf(name, sizeof(name), "ng%dn%d", head->subsys->instance,
653 - head->instance);
654 650
655 651 nvme_get_ns_head(head); /* Undone in nvme_cdev_rel() */
656 - if (nvme_cdev_add(name, &head->cdev, &head->cdev_device,
657 - &nvme_ns_head_chr_fops, THIS_MODULE)) {
652 + if (nvme_cdev_add(&head->cdev, &head->cdev_device,
653 + &nvme_ns_head_chr_fops, THIS_MODULE,
654 + head->subsys->instance, head->instance)) {
658 655 dev_err(disk_to_dev(head->disk),
659 - "Unable to create the %s device\n", name);
656 + "Unable to create the ng%dn%d device\n",
657 + head->subsys->instance, head->instance);
660 658 nvme_put_ns_head(head);
661 659 return;
662 660 }
@@ -763,8 +761,6 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
763 761 lim.dma_alignment = 3;
764 762 lim.features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT |
765 763 BLK_FEAT_POLL | BLK_FEAT_ATOMIC_WRITES | BLK_FEAT_PCI_P2PDMA;
766 - if (head->ids.csi == NVME_CSI_ZNS)
767 - lim.features |= BLK_FEAT_ZONED;
768 764
769 765 head->disk = blk_alloc_disk(&lim, ctrl->numa_node);
770 766 if (IS_ERR(head->disk))
@@ -845,7 +841,8 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
845 841 u32 nr_nsids;
846 842 size_t nsid_buf_size;
847 843
848 - if (WARN_ON_ONCE(offset > ctrl->ana_log_size - sizeof(*desc)))
844 + if (WARN_ON_ONCE(offset > ctrl->ana_log_size ||
845 + sizeof(*desc) > ctrl->ana_log_size - offset))
849 846 return -EINVAL;
850 847
851 848 nr_nsids = le32_to_cpu(desc->nnsids);
@@ -861,7 +858,7 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
861 858 return -EINVAL;
862 859
863 860 offset += sizeof(*desc);
864 - if (WARN_ON_ONCE(offset > ctrl->ana_log_size - nsid_buf_size))
861 + if (WARN_ON_ONCE(nsid_buf_size > ctrl->ana_log_size - offset))
865 862 return -EINVAL;
866 863
867 864 error = cb(ctrl, desc, data);
modified drivers/nvme/host/nvme.h
@@ -415,7 +415,6 @@ struct nvme_ctrl {
415 415 unsigned long quirks;
416 416 struct nvme_id_power_state psd[32];
417 417 struct nvme_effects_log *effects;
418 - struct xarray cels;
419 418 struct work_struct scan_work;
420 419 struct work_struct async_event_work;
421 420 struct delayed_work ka_work;
@@ -509,6 +508,8 @@ struct nvme_subsystem {
509 508 __guarded_by(&nvme_subsystems_lock);
510 509 struct list_head nsheads
511 510 __guarded_by(&lock);
511 + /* Command effects logs, indexed by CSI and protected by lock. */
512 + struct xarray cels;
512 513 char subnqn[NVMF_NQN_SIZE];
513 514 char serial[20];
514 515 char model[40];
@@ -1013,9 +1014,9 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
1013 1014 void nvme_get_ns_head(struct nvme_ns_head *head);
1014 1015 bool nvme_tryget_ns_head(struct nvme_ns_head *head);
1015 1016 void nvme_put_ns_head(struct nvme_ns_head *head);
1016 - int nvme_cdev_add(const char *name, struct cdev *cdev,
1017 - struct device *cdev_device,
1018 - const struct file_operations *fops, struct module *owner);
1017 + int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
1018 + const struct file_operations *fops, struct module *owner,
1019 + int ctrl, int head);
1019 1020 void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device);
1020 1021 int nvme_ioctl(struct block_device *bdev, blk_mode_t mode,
1021 1022 unsigned int cmd, unsigned long arg);
modified drivers/nvme/host/pci.c
@@ -4196,6 +4196,8 @@ static const struct pci_device_id nvme_id_table[] = {
4196 4196 .driver_data = NVME_QUIRK_IGNORE_DEV_SUBNQN },
4197 4197 { PCI_DEVICE(0x1344, 0x6001), /* Micron Nitro NVMe */
4198 4198 .driver_data = NVME_QUIRK_BOGUS_NID, },
4199 + { PCI_DEVICE(0x1344, 0x6004), /* Micron 4100AT */
4200 + .driver_data = NVME_QUIRK_DMAPOOL_ALIGN_512, },
4199 4201 { PCI_DEVICE(0x1c5c, 0x1504), /* SK Hynix PC400 */
4200 4202 .driver_data = NVME_QUIRK_DISABLE_WRITE_ZEROES, },
4201 4203 { PCI_DEVICE(0x1c5c, 0x174a), /* SK Hynix P31 SSD */
modified drivers/nvme/host/sysfs.c
@@ -679,7 +679,7 @@ static ssize_t cntrltype_show(struct device *dev,
679 679 if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype])
680 680 return sysfs_emit(buf, "reserved\n");
681 681
682 - return sysfs_emit(buf, type[ctrl->cntrltype]);
682 + return sysfs_emit(buf, "%s", type[ctrl->cntrltype]);
683 683 }
684 684 static DEVICE_ATTR_RO(cntrltype);
685 685
@@ -696,7 +696,7 @@ static ssize_t dctype_show(struct device *dev,
696 696 if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype])
697 697 return sysfs_emit(buf, "reserved\n");
698 698
699 - return sysfs_emit(buf, type[ctrl->dctype]);
699 + return sysfs_emit(buf, "%s", type[ctrl->dctype]);
700 700 }
701 701 static DEVICE_ATTR_RO(dctype);
702 702
modified drivers/nvme/host/tcp.c
@@ -144,11 +144,6 @@ struct nvme_tcp_queue {
144 144 void (*state_change)(struct sock *);
145 145 void (*data_ready)(struct sock *);
146 146 void (*write_space)(struct sock *);
147 -
148 - #ifdef CONFIG_DEBUG_LOCK_ALLOC
149 - struct lock_class_key nvme_tcp_sk_key;
150 - struct lock_class_key nvme_tcp_slock_key;
151 - #endif
152 147 };
153 148
154 149 static DEFINE_MUTEX(nvme_tcp_ctrl_mutex);
@@ -185,9 +180,12 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
185 180 * a separate class prevents lockdep from conflating nvme-tcp socket use with
186 181 * user-space socket API use.
187 182 */
188 - static void nvme_tcp_reclassify_socket(struct nvme_tcp_queue *queue)
183 + static struct lock_class_key nvme_tcp_sk_key[2];
184 + static struct lock_class_key nvme_tcp_slock_key[2];
185 +
186 + static void nvme_tcp_reclassify_socket(struct socket *sock)
189 187 {
190 - struct sock *sk = queue->sock->sk;
188 + struct sock *sk = sock->sk;
191 189
192 190 if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
193 191 return;
@@ -195,20 +193,22 @@ static void nvme_tcp_reclassify_socket(struct nvme_tcp_queue *queue)
195 193 switch (sk->sk_family) {
196 194 case AF_INET:
197 195 sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME",
198 - &queue->nvme_tcp_slock_key,
196 + &nvme_tcp_slock_key[0],
199 197 "sk_lock-AF_INET-NVME",
200 - &queue->nvme_tcp_sk_key);
198 + &nvme_tcp_sk_key[0]);
201 199 break;
202 200 case AF_INET6:
203 201 sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME",
204 - &queue->nvme_tcp_slock_key,
202 + &nvme_tcp_slock_key[1],
205 203 "sk_lock-AF_INET6-NVME",
206 - &queue->nvme_tcp_sk_key);
204 + &nvme_tcp_sk_key[1]);
207 205 break;
208 206 default:
209 207 WARN_ON_ONCE(1);
210 208 }
211 209 }
210 + #else
211 + static void nvme_tcp_reclassify_socket(struct socket *sock) { }
212 212 #endif
213 213
214 214 static inline struct nvme_tcp_ctrl *to_tcp_ctrl(struct nvme_ctrl *ctrl)
@@ -1523,11 +1523,6 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid)
1523 1523 mutex_destroy(&queue->send_mutex);
1524 1524 mutex_destroy(&queue->queue_lock);
1525 1525 mutex_destroy(&queue->pf_cache_lock);
1526 -
1527 - #ifdef CONFIG_DEBUG_LOCK_ALLOC
1528 - lockdep_unregister_key(&queue->nvme_tcp_sk_key);
1529 - lockdep_unregister_key(&queue->nvme_tcp_slock_key);
1530 - #endif
1531 1526 }
1532 1527
1533 1528 static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
@@ -1875,12 +1870,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
1875 1870
1876 1871 sk_net_refcnt_upgrade(queue->sock->sk);
1877 1872
1878 - #ifdef CONFIG_DEBUG_LOCK_ALLOC
1879 - lockdep_register_key(&queue->nvme_tcp_sk_key);
1880 - lockdep_register_key(&queue->nvme_tcp_slock_key);
1881 - nvme_tcp_reclassify_socket(queue);
1882 - #endif
1883 -
1884 1873 /* Single syn retry */
1885 1874 tcp_sock_set_syncnt(queue->sock->sk, 1);
1886 1875
@@ -1968,6 +1957,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
1968 1957 goto err_init_connect;
1969 1958 }
1970 1959
1960 + nvme_tcp_reclassify_socket(queue->sock);
1961 +
1971 1962 ret = nvme_tcp_init_connection(queue);
1972 1963 if (ret)
1973 1964 goto err_init_connect;
@@ -1984,10 +1975,6 @@ err_sock:
1984 1975 /* Use sync variant - see nvme_tcp_free_queue() for explanation */
1985 1976 __fput_sync(queue->sock->file);
1986 1977 queue->sock = NULL;
1987 - #ifdef CONFIG_DEBUG_LOCK_ALLOC
1988 - lockdep_unregister_key(&queue->nvme_tcp_sk_key);
1989 - lockdep_unregister_key(&queue->nvme_tcp_slock_key);
1990 - #endif
1991 1978 err_destroy_mutex:
1992 1979 mutex_destroy(&queue->send_mutex);
1993 1980 mutex_destroy(&queue->queue_lock);
modified drivers/nvme/target/configfs.c
@@ -534,6 +534,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
534 534 struct nvmet_subsys *subsys = ns->subsys;
535 535 size_t len;
536 536 int ret;
537 + char *new_path = NULL;
537 538
538 539 mutex_lock(&subsys->lock);
539 540 ret = -EBUSY;
@@ -545,12 +546,14 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
545 546 if (!len)
546 547 goto out_unlock;
547 548
548 - kfree(ns->device_path);
549 549 ret = -ENOMEM;
550 - ns->device_path = kmemdup_nul(page, len, GFP_KERNEL);
551 - if (!ns->device_path)
550 + new_path = kmemdup_nul(page, len, GFP_KERNEL);
551 + if (!new_path)
552 552 goto out_unlock;
553 553
554 + kfree(ns->device_path);
555 + ns->device_path = new_path;
556 +
554 557 mutex_unlock(&subsys->lock);
555 558 return count;
556 559
modified drivers/nvme/target/core.c
@@ -446,20 +446,27 @@ u16 nvmet_req_find_ns(struct nvmet_req *req)
446 446 {
447 447 u32 nsid = le32_to_cpu(req->cmd->common.nsid);
448 448 struct nvmet_subsys *subsys = nvmet_req_subsys(req);
449 + u16 status = NVME_SC_SUCCESS;
449 450
451 + rcu_read_lock();
450 452 req->ns = xa_load(&subsys->namespaces, nsid);
451 - if (unlikely(!req->ns || !req->ns->enabled)) {
453 + if (unlikely(!req->ns) ||
454 + !test_bit(NVMET_NS_IO_LIVE, &req->ns->flags) ||
455 + !percpu_ref_tryget_live_rcu(&req->ns->ref)) {
452 456 req->error_loc = offsetof(struct nvme_common_command, nsid);
453 - if (!req->ns) /* ns doesn't exist! */
454 - return NVME_SC_INVALID_NS | NVME_STATUS_DNR;
457 + if (!req->ns) { /* ns doesn't exist! */
458 + status = NVME_SC_INVALID_NS | NVME_STATUS_DNR;
459 + goto unlock;
460 + }
455 461
456 462 /* ns exists but it's disabled */
457 463 req->ns = NULL;
458 - return NVME_SC_INTERNAL_PATH_ERROR;
464 + status = NVME_SC_INTERNAL_PATH_ERROR;
459 465 }
466 + unlock:
467 + rcu_read_unlock();
460 468
461 - percpu_ref_get(&req->ns->ref);
462 - return NVME_SC_SUCCESS;
469 + return status;
463 470 }
464 471
465 472 static void nvmet_destroy_namespace(struct percpu_ref *ref)
@@ -623,6 +630,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
623 630 ns->enabled = true;
624 631 xa_set_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED);
625 632 nvmet_debugfs_ns_setup(ns);
633 + set_bit(NVMET_NS_IO_LIVE, &ns->flags);
626 634 ret = 0;
627 635 out_unlock:
628 636 mutex_unlock(&subsys->lock);
@@ -643,11 +651,11 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
643 651 struct nvmet_subsys *subsys = ns->subsys;
644 652 struct nvmet_ctrl *ctrl;
645 653
654 + if (!test_and_clear_bit(NVMET_NS_IO_LIVE, &ns->flags))
655 + return;
656 +
646 657 mutex_lock(&subsys->lock);
647 - if (!ns->enabled)
648 - goto out_unlock;
649 658
650 - ns->enabled = false;
651 659 xa_clear_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED);
652 660 nvmet_debugfs_ns_free(ns);
653 661
@@ -675,7 +683,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
675 683 mutex_lock(&subsys->lock);
676 684 nvmet_ns_changed(subsys, ns->nsid);
677 685 nvmet_ns_dev_disable(ns);
678 - out_unlock:
686 + ns->enabled = false;
679 687 mutex_unlock(&subsys->lock);
680 688 }
681 689
@@ -1648,6 +1656,8 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args)
1648 1656 INIT_DELAYED_WORK(&ctrl->ka_work, nvmet_keep_alive_timer);
1649 1657
1650 1658 memcpy(ctrl->hostnqn, args->hostnqn, NVMF_NQN_SIZE);
1659 + if (args->hostid)
1660 + uuid_copy(&ctrl->hostid, args->hostid);
1651 1661
1652 1662 kref_init(&ctrl->ref);
1653 1663 ctrl->subsys = subsys;
@@ -1706,9 +1716,6 @@ struct nvmet_ctrl *nvmet_alloc_ctrl(struct nvmet_alloc_ctrl_args *args)
1706 1716
1707 1717 nvmet_start_keep_alive_timer(ctrl);
1708 1718
1709 - if (args->hostid)
1710 - uuid_copy(&ctrl->hostid, args->hostid);
1711 -
1712 1719 dhchap_status = nvmet_setup_auth(ctrl, args->sq, false);
1713 1720 if (dhchap_status) {
1714 1721 pr_err("Failed to setup authentication, dhchap status %u\n",
modified drivers/nvme/target/fabrics-cmd-auth.c
@@ -427,7 +427,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
427 427 struct nvmet_ctrl *ctrl = req->sq->ctrl;
428 428 int ret = 0;
429 429 int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
430 - int data_size = sizeof(*d) + hash_len;
430 + int data_size = sizeof(*data) + hash_len;
431 431
432 432 if (ctrl->dh_tfm)
433 433 data_size += ctrl->dh_keysize;
modified drivers/nvme/target/nvmet.h
@@ -112,6 +112,8 @@ struct nvmet_ns {
112 112
113 113 bool buffered_io;
114 114 bool enabled;
115 + #define NVMET_NS_IO_LIVE 0
116 + unsigned long flags;
115 117 struct nvmet_subsys *subsys;
116 118 const char *device_path;
117 119
modified drivers/nvme/target/pci-epf.c
@@ -978,6 +978,9 @@ nvmet_pci_epf_get_sgl_segment(struct nvmet_pci_epf_ctrl *ctrl,
978 978 int nr_descs, ret;
979 979 void *buf;
980 980
981 + if (length < sizeof(struct nvme_sgl_desc))
982 + return NULL;
983 +
981 984 buf = kmalloc(length, GFP_KERNEL);
982 985 if (!buf)
983 986 return NULL;
modified drivers/of/base.c
@@ -96,9 +96,17 @@ static bool __of_node_is_type(const struct device_node *np, const char *type)
96 96 return !strcmp(match, type);
97 97 }
98 98
99 + static bool of_coreboot_present(void)
100 + {
101 + struct device_node *np __free(device_node) =
102 + of_find_compatible_node(NULL, NULL, "coreboot");
103 +
104 + return np;
105 + }
106 +
99 107 #define EXCLUDED_DEFAULT_CELLS_PLATFORMS ( \
100 108 IS_ENABLED(CONFIG_SPARC) || \
101 - of_find_compatible_node(NULL, NULL, "coreboot") \
109 + of_coreboot_present() \
102 110 )
103 111
104 112 int of_bus_n_addr_cells(struct device_node *np)
modified drivers/of/irq.c
@@ -754,6 +754,8 @@ void __init of_irq_init(const struct of_device_id *matches)
754 754
755 755 list_for_each_entry_safe(desc, temp_desc, &intc_parent_list, list) {
756 756 list_del(&desc->list);
757 + of_node_put(desc->interrupt_parent);
758 + of_node_put(desc->dev);
757 759 kfree(desc);
758 760 }
759 761 err:
modified drivers/of/overlay.c
@@ -256,6 +256,9 @@ static struct property *dup_and_fixup_symbol_prop(
256 256 if (!target_path)
257 257 return NULL;
258 258 target_path_len = strlen(target_path);
259 + /* a root target renders as "/"; drop it to avoid "//" results */
260 + if (target_path_len == 1 && target_path[0] == '/' && path_tail_len)
261 + target_path_len = 0;
259 262
260 263 new_prop = kzalloc_obj(*new_prop);
261 264 if (!new_prop)
@@ -358,12 +361,13 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
358 361 return -ENOMEM;
359 362
360 363 if (!prop) {
361 - if (!target->in_livetree) {
364 + ret = of_changeset_add_property(&ovcs->cset, target->np,
365 + new_prop);
366 + /* the detached node owns the property until the apply */
367 + if (!ret && !target->in_livetree) {
362 368 new_prop->next = target->np->deadprops;
363 369 target->np->deadprops = new_prop;
364 370 }
365 - ret = of_changeset_add_property(&ovcs->cset, target->np,
366 - new_prop);
367 371 } else {
368 372 ret = of_changeset_update_property(&ovcs->cset, target->np,
369 373 new_prop);
@@ -853,6 +857,10 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
853 857 err_out:
854 858 pr_err("%s() failed, ret = %d\n", __func__, ret);
855 859
860 + /* let free_overlay_changeset() put the fragments set up so far */
861 + if (ovcs->fragments)
862 + ovcs->count = cnt;
863 +
856 864 return ret;
857 865 }
858 866
@@ -863,7 +871,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs)
863 871 if (ovcs->cset.entries.next)
864 872 of_changeset_destroy(&ovcs->cset);
865 873
866 - if (ovcs->id) {
874 + /* a failed idr_alloc() leaves its negative error in ovcs->id */
875 + if (ovcs->id > 0) {
867 876 idr_remove(&ovcs_idr, ovcs->id);
868 877 list_del(&ovcs->ovcs_list);
869 878 ovcs->id = 0;
modified drivers/pci/pci.c
@@ -3769,8 +3769,21 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
3769 3769 }
3770 3770
3771 3771 root = pcie_find_root_port(dev);
3772 - if (!root)
3772 + if (!root) {
3773 +
3774 + /*
3775 + * A hypervisor may expose a topology with the root port
3776 + * not visible to the guest. If the hypervisor has already
3777 + * set AtomicOp Requester Enable in the endpoint, we assume
3778 + * it has verified support in the root port, so it is safe
3779 + * for the driver to use AtomicOps.
3780 + */
3781 + pcie_capability_read_dword(dev, PCI_EXP_DEVCTL2, &ctl2);
3782 + if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_REQ)
3783 + return 0;
3784 +
3773 3785 return -EINVAL;
3786 + }
3774 3787
3775 3788 pcie_capability_read_dword(root, PCI_EXP_DEVCAP2, &cap);
3776 3789 if ((cap & cap_mask) != cap_mask)
modified drivers/rtc/dev.c
@@ -216,7 +216,7 @@ static long rtc_dev_ioctl(struct file *file,
216 216 struct rtc_device *rtc = file->private_data;
217 217 const struct rtc_class_ops *ops = rtc->ops;
218 218 struct rtc_time tm;
219 - struct rtc_wkalrm alarm;
219 + struct rtc_wkalrm alarm = { 0 };
220 220 struct rtc_param param;
221 221 void __user *uarg = (void __user *)arg;
222 222
modified drivers/rtc/rtc-ac100.c
@@ -317,10 +317,12 @@ static int ac100_rtc_register_clks(struct ac100_rtc_dev *chip)
317 317 if (!chip->clk_data)
318 318 return -ENOMEM;
319 319
320 - chip->rtc_32k_clk = clk_hw_register_fixed_rate(chip->dev,
321 - AC100_RTC_32K_NAME,
322 - NULL, 0,
323 - AC100_RTC_32K_RATE);
320 + chip->clk_data->num = AC100_CLKOUT_NUM;
321 +
322 + chip->rtc_32k_clk = devm_clk_hw_register_fixed_rate(chip->dev,
323 + AC100_RTC_32K_NAME,
324 + NULL, 0,
325 + AC100_RTC_32K_RATE);
324 326 if (IS_ERR(chip->rtc_32k_clk)) {
325 327 ret = PTR_ERR(chip->rtc_32k_clk);
326 328 dev_err(chip->dev, "Failed to register RTC-32k clock: %d\n",
@@ -354,29 +356,14 @@ static int ac100_rtc_register_clks(struct ac100_rtc_dev *chip)
354 356 if (ret) {
355 357 dev_err(chip->dev, "Failed to register clk '%s': %d\n",
356 358 init.name, ret);
357 - goto err_unregister_rtc_32k;
359 + return ret;
358 360 }
359 361
360 362 chip->clk_data->hws[i] = &clk->hw;
361 363 }
362 364
363 - chip->clk_data->num = i;
364 - ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, chip->clk_data);
365 - if (ret)
366 - goto err_unregister_rtc_32k;
367 -
368 - return 0;
369 -
370 - err_unregister_rtc_32k:
371 - clk_unregister_fixed_rate(chip->rtc_32k_clk->clk);
372 -
373 - return ret;
374 - }
375 -
376 - static void ac100_rtc_unregister_clks(struct ac100_rtc_dev *chip)
377 - {
378 - of_clk_del_provider(chip->dev->of_node);
379 - clk_unregister_fixed_rate(chip->rtc_32k_clk->clk);
365 + return devm_of_clk_add_hw_provider(chip->dev, of_clk_hw_onecell_get,
366 + chip->clk_data);
380 367 }
381 368
382 369 /*
@@ -614,13 +601,6 @@ static int ac100_rtc_probe(struct platform_device *pdev)
614 601 return devm_rtc_register_device(chip->rtc);
615 602 }
616 603
617 - static void ac100_rtc_remove(struct platform_device *pdev)
618 - {
619 - struct ac100_rtc_dev *chip = platform_get_drvdata(pdev);
620 -
621 - ac100_rtc_unregister_clks(chip);
622 - }
623 -
624 604 static const struct of_device_id ac100_rtc_match[] = {
625 605 { .compatible = "x-powers,ac100-rtc" },
626 606 { },
@@ -629,7 +609,6 @@ MODULE_DEVICE_TABLE(of, ac100_rtc_match);
629 609
630 610 static struct platform_driver ac100_rtc_driver = {
631 611 .probe = ac100_rtc_probe,
632 - .remove = ac100_rtc_remove,
633 612 .driver = {
634 613 .name = "ac100-rtc",
635 614 .of_match_table = of_match_ptr(ac100_rtc_match),
modified drivers/rtc/rtc-efi.c
@@ -52,6 +52,7 @@ compute_wday(efi_time_t *eft, int yday)
52 52 static void
53 53 convert_to_efi_time(struct rtc_time *wtime, efi_time_t *eft)
54 54 {
55 + memset(eft, 0, sizeof(*eft));
55 56 eft->year = wtime->tm_year + 1900;
56 57 eft->month = wtime->tm_mon + 1;
57 58 eft->day = wtime->tm_mday;
@@ -112,6 +113,35 @@ convert_from_efi_time(efi_time_t *eft, struct rtc_time *wtime)
112 113 return true;
113 114 }
114 115
116 + static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
117 + {
118 + efi_time_t eft;
119 + efi_status_t status;
120 +
121 + memset(&eft, 0, sizeof(eft));
122 + status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled,
123 + (efi_bool_t *)&wkalrm->pending, &eft);
124 + if (status != EFI_SUCCESS)
125 + return -EINVAL;
126 +
127 + if (!convert_from_efi_time(&eft, &wkalrm->time))
128 + return -EIO;
129 +
130 + return rtc_valid_tm(&wkalrm->time);
131 + }
132 +
133 + static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
134 + {
135 + efi_time_t eft;
136 + efi_status_t status;
137 +
138 + convert_to_efi_time(&wkalrm->time, &eft);
139 +
140 + status = efi.set_wakeup_time((efi_bool_t)!!wkalrm->enabled, &eft);
141 +
142 + return status == EFI_SUCCESS ? 0 : -EINVAL;
143 + }
144 +
115 145 static int efi_read_time(struct device *dev, struct rtc_time *tm)
116 146 {
117 147 efi_status_t status;
@@ -146,13 +176,21 @@ static int efi_set_time(struct device *dev, struct rtc_time *tm)
146 176
147 177 static int efi_procfs(struct device *dev, struct seq_file *seq)
148 178 {
149 - efi_time_t eft;
179 + efi_time_t eft, alm;
150 180 efi_time_cap_t cap;
181 + efi_bool_t enabled, pending;
182 + struct rtc_device *rtc = dev_get_drvdata(dev);
151 183
152 184 memset(&eft, 0, sizeof(eft));
185 + memset(&alm, 0, sizeof(alm));
153 186 memset(&cap, 0, sizeof(cap));
154 187
155 188 efi.get_time(&eft, &cap);
189 + if (test_bit(RTC_FEATURE_ALARM, rtc->features) &&
190 + efi.get_wakeup_time(&enabled, &pending, &alm) != EFI_SUCCESS) {
191 + enabled = 0;
192 + pending = 0;
193 + }
156 194
157 195 seq_printf(seq,
158 196 "Time\t\t: %u:%u:%u.%09u\n"
@@ -168,6 +206,25 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
168 206 /* XXX fixme: convert to string? */
169 207 seq_printf(seq, "Timezone\t: %u\n", eft.timezone);
170 208
209 + if (test_bit(RTC_FEATURE_ALARM, rtc->features)) {
210 + seq_printf(seq,
211 + "Alarm Time\t: %u:%u:%u.%09u\n"
212 + "Alarm Date\t: %u-%u-%u\n"
213 + "Alarm Daylight\t: %u\n"
214 + "Enabled\t\t: %s\n"
215 + "Pending\t\t: %s\n",
216 + alm.hour, alm.minute, alm.second, alm.nanosecond,
217 + alm.year, alm.month, alm.day,
218 + alm.daylight,
219 + enabled == 1 ? "yes" : "no",
220 + pending == 1 ? "yes" : "no");
221 +
222 + if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE)
223 + seq_puts(seq, "Alarm Timezone\t: unspecified\n");
224 + else
225 + seq_printf(seq, "Alarm Timezone\t: %d\n", alm.timezone);
226 + }
227 +
171 228 /*
172 229 * now prints the capabilities
173 230 */
@@ -183,6 +240,8 @@ static int efi_procfs(struct device *dev, struct seq_file *seq)
183 240 static const struct rtc_class_ops efi_rtc_ops = {
184 241 .read_time = efi_read_time,
185 242 .set_time = efi_set_time,
243 + .read_alarm = efi_read_alarm,
244 + .set_alarm = efi_set_alarm,
186 245 .proc = efi_procfs,
187 246 };
188 247
@@ -191,6 +250,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
191 250 struct rtc_device *rtc;
192 251 efi_time_t eft;
193 252 efi_time_cap_t cap;
253 + efi_bool_t enabled, pending;
194 254
195 255 /* First check if the RTC is usable */
196 256 if (efi.get_time(&eft, &cap) != EFI_SUCCESS)
@@ -203,7 +263,23 @@ static int __init efi_rtc_probe(struct platform_device *dev)
203 263 platform_set_drvdata(dev, rtc);
204 264
205 265 rtc->ops = &efi_rtc_ops;
206 - clear_bit(RTC_FEATURE_ALARM, rtc->features);
266 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
267 +
268 + /*
269 + * The EFI_RT_SUPPORTED_WAKEUP_SERVICES bit defaults to enabled
270 + * and only gets cleared when the RT_PROP table explicitly says
271 + * wakeup is unsupported. Many platforms lack an RT_PROP table
272 + * even though they don't implement the wakeup runtime service,
273 + * so probe by actually calling GetWakeupTime() to avoid exposing
274 + * a broken alarm to userspace.
275 + */
276 + if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES) &&
277 + efi.get_wakeup_time(&enabled, &pending, &eft) == EFI_SUCCESS) {
278 + set_bit(RTC_FEATURE_ALARM, rtc->features);
279 + set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features);
280 + } else {
281 + clear_bit(RTC_FEATURE_ALARM, rtc->features);
282 + }
207 283
208 284 device_init_wakeup(&dev->dev, true);
209 285
modified drivers/rtc/rtc-mpfs.c
@@ -256,8 +256,12 @@ static int mpfs_rtc_probe(struct platform_device *pdev)
256 256 return ret;
257 257 }
258 258
259 + clk = devm_clk_get(&pdev->dev, "rtcref");
260 + if (IS_ERR(clk))
261 + return PTR_ERR(clk);
262 +
259 263 /* prescaler hardware adds 1 to reg value */
260 - prescaler = clk_get_rate(devm_clk_get(&pdev->dev, "rtcref")) - 1;
264 + prescaler = clk_get_rate(clk) - 1;
261 265 if (prescaler > MAX_PRESCALER_COUNT) {
262 266 dev_dbg(&pdev->dev, "invalid prescaler %lu\n", prescaler);
263 267 return -EINVAL;
modified drivers/rtc/rtc-spear.c
@@ -363,6 +363,12 @@ static int spear_rtc_probe(struct platform_device *pdev)
363 363 if (irq < 0)
364 364 return irq;
365 365
366 + config->ioaddr = devm_platform_ioremap_resource(pdev, 0);
367 + if (IS_ERR(config->ioaddr))
368 + return PTR_ERR(config->ioaddr);
369 +
370 + spin_lock_init(&config->lock);
371 +
366 372 status = devm_request_irq(&pdev->dev, irq, spear_rtc_irq, 0, pdev->name,
367 373 config);
368 374 if (status) {
@@ -371,10 +377,6 @@ static int spear_rtc_probe(struct platform_device *pdev)
371 377 return status;
372 378 }
373 379
374 - config->ioaddr = devm_platform_ioremap_resource(pdev, 0);
375 - if (IS_ERR(config->ioaddr))
376 - return PTR_ERR(config->ioaddr);
377 -
378 380 config->clk = devm_clk_get(&pdev->dev, NULL);
379 381 if (IS_ERR(config->clk))
380 382 return PTR_ERR(config->clk);
@@ -383,7 +385,6 @@ static int spear_rtc_probe(struct platform_device *pdev)
383 385 if (status < 0)
384 386 return status;
385 387
386 - spin_lock_init(&config->lock);
387 388 platform_set_drvdata(pdev, config);
388 389
389 390 config->rtc->ops = &spear_rtc_ops;
modified drivers/soc/tegra/fuse/tegra-apbmisc.c
@@ -309,7 +309,7 @@ void tegra_acpi_init_apbmisc(void)
309 309
310 310 ret = acpi_dev_get_memory_resources(adev, &resource_list);
311 311 if (ret < 0) {
312 - pr_err("failed to get APBMISC memory resources\n");
312 + pr_err("failed to get APBMISC memory resources");
313 313 goto out_put_acpi_dev;
314 314 }
315 315
modified drivers/soc/tegra/pmc.c
@@ -3151,7 +3151,6 @@ static int tegra_pmc_probe(struct platform_device *pdev)
3151 3151
3152 3152 #if defined(CONFIG_ARM)
3153 3153 mutex_lock(&early_pmc->powergates_lock);
3154 - early_pmc->rate = pmc->rate;
3155 3154 iounmap(early_pmc->base);
3156 3155 early_pmc->base = pmc->base;
3157 3156 mutex_unlock(&early_pmc->powergates_lock);
modified drivers/spi/spi-cs42l43.c
@@ -11,6 +11,7 @@
11 11 #include <linux/bitfield.h>
12 12 #include <linux/cleanup.h>
13 13 #include <linux/device.h>
14 + #include <linux/dmi.h>
14 15 #include <linux/errno.h>
15 16 #include <linux/gpio/consumer.h>
16 17 #include <linux/gpio/machine.h>
@@ -215,12 +216,108 @@ static size_t cs42l43_spi_max_length(struct spi_device *spi)
215 216 return CS42L43_SPI_MAX_LENGTH;
216 217 }
217 218
219 + /*
220 + * Workaround needed for two speaker ID pins in one ACPI GpioIo() but
221 + * the Linux-specific _DSD property only contains one pin.
222 + * Create a temporary acpi_gpio_mapping pointing at both pins.
223 + */
224 + static const struct acpi_gpio_params cs42l43_2bit_speaker_id_from_one_gpioio_params[] = {
225 + [0] = {
226 + .crs_entry_index = 0,
227 + .line_index = 0,
228 + },
229 + [1] = {
230 + .crs_entry_index = 0,
231 + .line_index = 1,
232 + },
233 + };
234 +
235 + static const struct acpi_gpio_mapping cs42l43_2bit_speaker_id_from_one_gpioio_mapping[] = {
236 + {
237 + .name = "spk-id-quirk-gpios",
238 + .data = cs42l43_2bit_speaker_id_from_one_gpioio_params,
239 + .size = ARRAY_SIZE(cs42l43_2bit_speaker_id_from_one_gpioio_params),
240 + },
241 + { }
242 + };
243 +
244 + static int cs42l43_get_2bit_speaker_id_from_one_gpioio(struct cs42l43_spi *priv, int *result)
245 + {
246 + struct fwnode_reference_args args;
247 + struct acpi_device *adev;
248 + struct gpio_desc *desc;
249 + u32 spkid = 0;
250 + int i, ret;
251 +
252 + /* Use the _DSD property to get the node containing the GpioIo() */
253 + ret = fwnode_property_get_reference_args(dev_fwnode(priv->dev), "spk-id-gpios",
254 + NULL, 3, 0, &args);
255 + if (ret)
256 + return ret;
257 +
258 + struct fwnode_handle *fwnode __free(fwnode_handle) = args.fwnode;
259 +
260 + /* An acpi_gpio_mapping must be added to the node that contains the GpioIo() */
261 + adev = to_acpi_device_node(fwnode);
262 + if (!adev)
263 + return -EINVAL;
264 +
265 + ret = acpi_dev_add_driver_gpios(adev, cs42l43_2bit_speaker_id_from_one_gpioio_mapping);
266 + if (ret)
267 + return ret;
268 +
269 + /* gpiod_get_array() can't read from a mapping in a child node */
270 + for (i = 0; i < ARRAY_SIZE(cs42l43_2bit_speaker_id_from_one_gpioio_params); i++) {
271 + desc = fwnode_gpiod_get_index(fwnode, "spk-id-quirk", i, GPIOD_IN,
272 + dev_name(priv->dev));
273 + if (IS_ERR(desc)) {
274 + ret = PTR_ERR(desc);
275 + goto out;
276 + }
277 +
278 + ret = gpiod_get_value_cansleep(desc);
279 + gpiod_put(desc);
280 + if (ret < 0)
281 + goto out;
282 +
283 + spkid |= (u32)ret << i;
284 + }
285 +
286 + dev_dbg(priv->dev, "spk-id-gpios = %u\n", spkid);
287 + *result = spkid;
288 + ret = 0;
289 + out:
290 + acpi_dev_remove_driver_gpios(adev);
291 +
292 + return ret;
293 + }
294 +
295 + static const struct dmi_system_id cs42l43_spk_id_quirks[] = {
296 + {
297 + .ident = "Dell XPS 13 DX13260",
298 + .matches = {
299 + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
300 + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0E53"),
301 + },
302 + .driver_data = cs42l43_get_2bit_speaker_id_from_one_gpioio,
303 + },
304 + { }
305 + };
306 +
218 307 static int cs42l43_get_speaker_id_gpios(struct cs42l43_spi *priv, int *result)
219 308 {
309 + const struct dmi_system_id *dmi_id;
220 310 struct gpio_descs *descs;
221 311 u32 spkid;
222 312 int i, ret;
223 313
314 + dmi_id = dmi_first_match(cs42l43_spk_id_quirks);
315 + if (dmi_id) {
316 + int (*get_speaker_id)(struct cs42l43_spi *priv, int *result) = dmi_id->driver_data;
317 +
318 + return get_speaker_id(priv, result);
319 + }
320 +
224 321 descs = gpiod_get_array_optional(priv->dev, "spk-id", GPIOD_IN);
225 322 if (!descs)
226 323 return 0;
modified drivers/staging/greybus/uart.c
@@ -948,7 +948,8 @@ static int gb_tty_init(void)
948 948 int retval = 0;
949 949
950 950 gb_tty_driver = tty_alloc_driver(GB_NUM_MINORS, TTY_DRIVER_REAL_RAW |
951 - TTY_DRIVER_DYNAMIC_DEV);
951 + TTY_DRIVER_DYNAMIC_DEV |
952 + TTY_DRIVER_RESET_SAVED_TERMIOS);
952 953 if (IS_ERR(gb_tty_driver)) {
953 954 pr_err("Can not allocate tty driver\n");
954 955 retval = PTR_ERR(gb_tty_driver);
modified drivers/tee/optee/ffa_abi.c
@@ -198,8 +198,7 @@ static int to_msg_param_ffa_mem(struct optee_msg_param *mp,
198 198 if (shm) {
199 199 u64 shm_offs = p->u.memref.shm_offs;
200 200
201 - mp->u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
202 - (FFA_PAGE_SIZE - 1);
201 + mp->u.fmem.internal_offs = shm->offset;
203 202
204 203 mp->u.fmem.offs_low = shm_offs;
205 204 mp->u.fmem.offs_high = shm_offs >> 32;
@@ -285,26 +284,14 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm,
285 284 .nattrs = 1,
286 285 };
287 286 struct sg_table sgt;
288 - size_t ffa_offs;
289 287 int rc;
290 288
291 - if (!num_pages)
292 - return -EINVAL;
293 -
294 289 rc = optee_check_mem_type(start, num_pages);
295 290 if (rc)
296 291 return rc;
297 292
298 - /*
299 - * Start the FF-A descriptor at the 4 KiB page containing the shared
300 - * buffer, skipping unused leading 4 KiB pages when PAGE_SIZE is
301 - * larger. Same approach as optee_fill_pages_list() in the SMC ABI.
302 - * This leaves only the offset into that 4 KiB page for internal_offs.
303 - */
304 - ffa_offs = round_down(tee_shm_get_page_offset(shm), FFA_PAGE_SIZE);
305 - rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, ffa_offs,
306 - num_pages * PAGE_SIZE - ffa_offs,
307 - GFP_KERNEL);
293 + rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, 0,
294 + num_pages * PAGE_SIZE, GFP_KERNEL);
308 295 if (rc)
309 296 return rc;
310 297 args.sg = sgt.sgl;
@@ -471,8 +458,7 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
471 458 .attr = OPTEE_MSG_ATTR_TYPE_FMEM_OUTPUT,
472 459 .u.fmem.size = tee_shm_get_size(shm),
473 460 .u.fmem.global_id = shm->sec_world_id,
474 - .u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
475 - (FFA_PAGE_SIZE - 1),
461 + .u.fmem.internal_offs = shm->offset,
476 462 };
477 463
478 464 arg->ret = TEEC_SUCCESS;
@@ -1137,6 +1123,14 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
1137 1123
1138 1124 optee_set_dev_group(optee);
1139 1125
1126 + rc = tee_device_register(optee->teedev);
1127 + if (rc)
1128 + goto err_unreg_supp_teedev;
1129 +
1130 + rc = tee_device_register(optee->supp_teedev);
1131 + if (rc)
1132 + goto err_unreg_supp_teedev;
1133 +
1140 1134 rc = rhashtable_init(&optee->ffa.global_ids, &shm_rhash_params);
1141 1135 if (rc)
1142 1136 goto err_unreg_supp_teedev;
@@ -1165,14 +1159,6 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
1165 1159 if (optee_ffa_protmem_pool_init(optee, sec_caps))
1166 1160 pr_info("Protected memory service not available\n");
1167 1161
1168 - rc = tee_device_register(optee->teedev);
1169 - if (rc)
1170 - goto err_unregister_devices;
1171 -
1172 - rc = tee_device_register(optee->supp_teedev);
1173 - if (rc)
1174 - goto err_unregister_devices;
1175 -
1176 1162 rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
1177 1163 if (rc)
1178 1164 goto err_unregister_devices;
modified drivers/tee/optee/optee_msg.h
@@ -136,8 +136,8 @@ struct optee_msg_param_rmem {
136 136 * struct optee_msg_param_fmem - FF-A memory reference parameter
137 137 * @offs_low: lower bits of offset into shared memory reference
138 138 * @offs_high: higher bits of offset into shared memory reference
139 - * @internal_offs: offset into the first 4 KiB page of the FF-A shared
140 - * memory region
139 + * @internal_offs: internal offset into the first page of shared memory
140 + * reference
141 141 * @size: size of the buffer
142 142 * @global_id: global identifier of the shared memory
143 143 */
modified drivers/tee/optee/smc_abi.c
@@ -1849,6 +1849,14 @@ static int optee_probe(struct platform_device *pdev)
1849 1849
1850 1850 optee_set_dev_group(optee);
1851 1851
1852 + rc = tee_device_register(optee->teedev);
1853 + if (rc)
1854 + goto err_unreg_supp_teedev;
1855 +
1856 + rc = tee_device_register(optee->supp_teedev);
1857 + if (rc)
1858 + goto err_unreg_supp_teedev;
1859 +
1852 1860 optee_cq_init(&optee->call_queue, thread_count);
1853 1861 optee_supp_init(&optee->supp);
1854 1862 optee->smc.memremaped_shm = memremaped_shm;
@@ -1908,14 +1916,6 @@ static int optee_probe(struct platform_device *pdev)
1908 1916 if (optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
1909 1917 pr_info("dynamic shared memory is enabled\n");
1910 1918
1911 - rc = tee_device_register(optee->teedev);
1912 - if (rc)
1913 - goto err_disable_shm_cache;
1914 -
1915 - rc = tee_device_register(optee->supp_teedev);
1916 - if (rc)
1917 - goto err_disable_shm_cache;
1918 -
1919 1919 rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
1920 1920 if (rc)
1921 1921 goto err_disable_shm_cache;
@@ -1942,6 +1942,7 @@ err_supp_uninit:
1942 1942 optee_shm_arg_cache_uninit(optee);
1943 1943 optee_supp_uninit(&optee->supp);
1944 1944 mutex_destroy(&optee->call_queue.mutex);
1945 + err_unreg_supp_teedev:
1945 1946 tee_device_unregister(optee->supp_teedev);
1946 1947 err_unreg_teedev:
1947 1948 tee_device_unregister(optee->teedev);
modified drivers/tee/qcomtee/async.c
@@ -97,10 +97,10 @@ static void qcomtee_get_async_buffer(struct qcomtee_object_invoke_ctx *oic,
97 97 /**
98 98 * async_release() - Process QTEE async release requests.
99 99 * @oic: context used for the current invocation.
100 - * @async_msg: async message for object release.
100 + * @msg: async message for object release.
101 101 * @size: size of the async buffer available.
102 102 *
103 - * Return: Size of the outbound buffer used when processing @async_msg.
103 + * Return: Size of the outbound buffer used when processing @msg.
104 104 */
105 105 static size_t async_release(struct qcomtee_object_invoke_ctx *oic,
106 106 struct qcomtee_async_msg_hdr *async_msg,
modified drivers/tee/qcomtee/qcomtee_msg.h
@@ -112,7 +112,7 @@ union qcomtee_msg_arg {
112 112
113 113 /**
114 114 * struct qcomtee_msg_object_invoke - Direct object invocation message.
115 - * @cxt: object ID hosted in QTEE.
115 + * @ctx: object ID hosted in QTEE.
116 116 * @op: operation for the object.
117 117 * @counts: number of different types of arguments in @args.
118 118 * @args: array of arguments.
modified drivers/tee/qcomtee/qcomtee_object.h
@@ -74,7 +74,6 @@ enum qcomtee_object_type {
74 74 * @QCOMTEE_ARG_TYPE_OO: output object (OO).
75 75 * @QCOMTEE_ARG_TYPE_IB: input buffer (IB).
76 76 * @QCOMTEE_ARG_TYPE_IO: input object (IO).
77 - * @QCOMTEE_ARG_TYPE_NR: number of argument types.
78 77 *
79 78 * Use the invalid type to specify the end of the argument array.
80 79 */
modified drivers/tee/tee_shm.c
@@ -343,10 +343,6 @@ int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align,
343 343 unsigned int i;
344 344 int rc = 0;
345 345
346 - /* get_order(0) is undefined and exceeds MAX_PAGE_ORDER. */
347 - if (!nr_pages)
348 - return -EINVAL;
349 -
350 346 /*
351 347 * Ignore alignment since this is already going to be page aligned
352 348 * and there's no need for any larger alignment.
modified drivers/thunderbolt/ctl.c
@@ -73,7 +73,6 @@ struct tb_ctl {
73 73 #define tb_ctl_dbg_once(ctl, format, arg...) \
74 74 dev_dbg_once((ctl)->nhi->dev, format, ## arg)
75 75
76 - static DECLARE_WAIT_QUEUE_HEAD(tb_cfg_request_cancel_queue);
77 76 /* Serializes access to request kref_get/put */
78 77 static DEFINE_MUTEX(tb_cfg_request_lock);
79 78
@@ -133,41 +132,42 @@ void tb_cfg_request_put(struct tb_cfg_request *req)
133 132 static int tb_cfg_request_enqueue(struct tb_ctl *ctl,
134 133 struct tb_cfg_request *req)
135 134 {
135 + tb_cfg_request_get(req);
136 +
136 137 WARN_ON(test_bit(TB_CFG_REQUEST_ACTIVE, &req->flags));
137 138 WARN_ON(req->ctl);
138 139
139 - mutex_lock(&ctl->request_queue_lock);
140 + guard(mutex)(&ctl->request_queue_lock);
140 141 if (!ctl->running) {
141 - mutex_unlock(&ctl->request_queue_lock);
142 + tb_cfg_request_put(req);
142 143 return -ENOTCONN;
143 144 }
144 145 req->ctl = ctl;
145 146 list_add_tail(&req->list, &ctl->request_queue);
146 147 set_bit(TB_CFG_REQUEST_ACTIVE, &req->flags);
147 - mutex_unlock(&ctl->request_queue_lock);
148 148 return 0;
149 149 }
150 150
151 - static void tb_cfg_request_dequeue(struct tb_cfg_request *req)
151 + static bool tb_cfg_request_is_active(struct tb_cfg_request *req)
152 152 {
153 - struct tb_ctl *ctl = req->ctl;
154 -
155 - mutex_lock(&ctl->request_queue_lock);
156 - if (!test_bit(TB_CFG_REQUEST_ACTIVE, &req->flags)) {
157 - mutex_unlock(&ctl->request_queue_lock);
158 - return;
159 - }
153 + return test_bit(TB_CFG_REQUEST_ACTIVE, &req->flags);
154 + }
160 155
161 - list_del(&req->list);
162 - clear_bit(TB_CFG_REQUEST_ACTIVE, &req->flags);
163 - if (test_bit(TB_CFG_REQUEST_CANCELED, &req->flags))
164 - wake_up(&tb_cfg_request_cancel_queue);
165 - mutex_unlock(&ctl->request_queue_lock);
156 + static bool tb_cfg_request_is_canceled(struct tb_cfg_request *req)
157 + {
158 + return test_bit(TB_CFG_REQUEST_CANCELED, &req->flags);
166 159 }
167 160
168 - static bool tb_cfg_request_is_active(struct tb_cfg_request *req)
161 + static void tb_cfg_request_dequeue(struct tb_cfg_request *req)
169 162 {
170 - return test_bit(TB_CFG_REQUEST_ACTIVE, &req->flags);
163 + struct tb_ctl *ctl = req->ctl;
164 +
165 + guard(mutex)(&ctl->request_queue_lock);
166 + if (tb_cfg_request_is_active(req)) {
167 + list_del(&req->list);
168 + clear_bit(TB_CFG_REQUEST_ACTIVE, &req->flags);
169 + tb_cfg_request_put(req);
170 + }
171 171 }
172 172
173 173 static struct tb_cfg_request *
@@ -178,7 +178,7 @@ tb_cfg_request_find(struct tb_ctl *ctl, struct ctl_pkg *pkg)
178 178 mutex_lock(&pkg->ctl->request_queue_lock);
179 179 list_for_each_entry(iter, &pkg->ctl->request_queue, list) {
180 180 tb_cfg_request_get(iter);
181 - if (iter->match(iter, pkg)) {
181 + if (!tb_cfg_request_is_canceled(iter) && iter->match(iter, pkg)) {
182 182 req = iter;
183 183 break;
184 184 }
@@ -512,8 +512,11 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,
512 512 trace_tb_rx(pkg->ctl->index, frame->eof, pkg->buffer, frame->size, !req);
513 513
514 514 if (req) {
515 - if (req->copy(req, pkg))
516 - schedule_work(&req->work);
515 + scoped_guard(mutex, &pkg->ctl->request_queue_lock) {
516 + if (!tb_cfg_request_is_canceled(req) &&
517 + req->copy(req, pkg))
518 + schedule_work(&req->work);
519 + }
517 520 tb_cfg_request_put(req);
518 521 }
519 522
@@ -525,11 +528,10 @@ static void tb_cfg_request_work(struct work_struct *work)
525 528 {
526 529 struct tb_cfg_request *req = container_of(work, typeof(*req), work);
527 530
528 - if (!test_bit(TB_CFG_REQUEST_CANCELED, &req->flags))
531 + if (!tb_cfg_request_is_canceled(req))
529 532 req->callback(req->callback_data);
530 533
531 534 tb_cfg_request_dequeue(req);
532 - tb_cfg_request_put(req);
533 535 }
534 536
535 537 /**
@@ -555,10 +557,9 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,
555 557 INIT_WORK(&req->work, tb_cfg_request_work);
556 558 INIT_LIST_HEAD(&req->list);
557 559
558 - tb_cfg_request_get(req);
559 560 ret = tb_cfg_request_enqueue(ctl, req);
560 561 if (ret)
561 - goto err_put;
562 + return ret;
562 563
563 564 ret = tb_ctl_tx(ctl, req->request, req->request_size,
564 565 req->request_type);
@@ -572,9 +573,6 @@ int tb_cfg_request(struct tb_ctl *ctl, struct tb_cfg_request *req,
572 573
573 574 err_dequeue:
574 575 tb_cfg_request_dequeue(req);
575 - err_put:
576 - tb_cfg_request_put(req);
577 -
578 576 return ret;
579 577 }
580 578
@@ -588,9 +586,10 @@ err_put:
588 586 */
589 587 void tb_cfg_request_cancel(struct tb_cfg_request *req, int err)
590 588 {
591 - set_bit(TB_CFG_REQUEST_CANCELED, &req->flags);
592 - schedule_work(&req->work);
593 - wait_event(tb_cfg_request_cancel_queue, !tb_cfg_request_is_active(req));
589 + scoped_guard(mutex, &req->ctl->request_queue_lock)
590 + set_bit(TB_CFG_REQUEST_CANCELED, &req->flags);
591 + cancel_work_sync(&req->work);
592 + tb_cfg_request_dequeue(req);
594 593 req->result.err = err;
595 594 }
596 595
modified drivers/thunderbolt/domain.c
@@ -788,21 +788,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
788 788 transmit_ring, receive_path, receive_ring);
789 789 }
790 790
791 - static void tb_domain_reset_interface(struct tb *tb)
792 - {
793 - struct tb_nhi *nhi = tb->nhi;
794 -
795 - if (!nhi->ops->reset_interface)
796 - return;
797 -
798 - guard(mutex)(&tb->lock);
799 -
800 - /* The reset clears the ring state so stop the control channel */
801 - tb_ctl_stop(tb->ctl);
802 - nhi->ops->reset_interface(nhi);
803 - tb_ctl_start(tb->ctl);
804 - }
805 -
806 791 /**
807 792 * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain
808 793 * @tb: Domain disabling the DMA paths
@@ -825,20 +810,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
825 810 int transmit_path, int transmit_ring,
826 811 int receive_path, int receive_ring)
827 812 {
828 - int ret;
829 -
830 813 if (!tb->cm_ops->disconnect_xdomain_paths)
831 814 return -ENOTSUPP;
832 815
833 - ret = tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path,
816 + return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path,
834 817 transmit_ring, receive_path, receive_ring);
835 - if (ret)
836 - return ret;
837 -
838 - if (tb->nhi->quirks & QUIRK_RESET_DMA_ON_TEARDOWN)
839 - tb_domain_reset_interface(tb);
840 -
841 - return 0;
842 818 }
843 819
844 820 static int disconnect_xdomain(struct device *dev, void *data)
modified drivers/thunderbolt/nhi.c
@@ -15,6 +15,7 @@
15 15 #include <linux/dma-mapping.h>
16 16 #include <linux/interrupt.h>
17 17 #include <linux/iommu.h>
18 + #include <linux/lockdep.h>
18 19 #include <linux/module.h>
19 20 #include <linux/delay.h>
20 21 #include <linux/property.h>
@@ -560,6 +561,8 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
560 561 INIT_LIST_HEAD(&ring->in_flight);
561 562 INIT_WORK(&ring->work, ring_work);
562 563 init_waitqueue_head(&ring->wait);
564 + lockdep_register_key(&ring->lock_key);
565 + lockdep_init_map(&ring->work.lockdep_map, "ring.work", &ring->lock_key, 0);
563 566
564 567 ring->nhi = nhi;
565 568 ring->hop = hop;
@@ -599,6 +602,7 @@ err_free_descs:
599 602 ring->size * sizeof(*ring->descriptors),
600 603 ring->descriptors, ring->descriptors_dma);
601 604 err_free_ring:
605 + lockdep_unregister_key(&ring->lock_key);
602 606 kfree(ring);
603 607
604 608 return NULL;
@@ -848,6 +852,7 @@ void tb_ring_free(struct tb_ring *ring)
848 852 * to finish before freeing the ring.
849 853 */
850 854 flush_work(&ring->work);
855 + lockdep_unregister_key(&ring->lock_key);
851 856 kfree(ring);
852 857 }
853 858 EXPORT_SYMBOL_GPL(tb_ring_free);
@@ -1175,32 +1180,6 @@ static void nhi_reset(struct tb_nhi *nhi)
1175 1180 dev_warn(nhi->dev, "timeout resetting host router\n");
1176 1181 }
1177 1182
1178 - /**
1179 - * nhi_reset_interface() - Reset the host interface
1180 - * @nhi: Host interface to reset
1181 - *
1182 - * Brings the registers in the memory BAR back to their default state and
1183 - * clears the End-to-End Flow Control state. The caller is responsible for
1184 - * stopping the control channel over the reset because it clears the ring
1185 - * state as well.
1186 - */
1187 - void nhi_reset_interface(struct tb_nhi *nhi)
1188 - {
1189 - u32 val;
1190 -
1191 - val = ioread32(nhi->iobase + REG_CAPS);
1192 - /* Only v1 host interfaces implement the reset */
1193 - if (FIELD_GET(REG_CAPS_VERSION_MASK, val) >= REG_CAPS_VERSION_2)
1194 - return;
1195 -
1196 - dev_dbg(nhi->dev, "issuing host interface reset\n");
1197 -
1198 - iowrite32(REG_HOST_INTERFACE_RESET_RST,
1199 - nhi->iobase + REG_HOST_INTERFACE_RESET);
1200 - /* Wait for tHIReset (10 ms) to complete */
1201 - usleep_range(10000, 20000);
1202 - }
1203 -
1204 1183 static struct tb *nhi_select_cm(struct tb_nhi *nhi)
1205 1184 {
1206 1185 struct tb *tb;
modified drivers/thunderbolt/nhi.h
@@ -36,8 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);
36 36 irqreturn_t ring_msix(int irq, void *data);
37 37 int nhi_probe(struct tb_nhi *nhi);
38 38 void nhi_shutdown(struct tb_nhi *nhi);
39 - void nhi_reset_interface(struct tb_nhi *nhi);
40 -
41 39 extern const struct dev_pm_ops nhi_pm_ops;
42 40
43 41 /**
@@ -54,7 +52,6 @@ extern const struct dev_pm_ops nhi_pm_ops;
54 52 * @release_ring_irq: NHI specific interrupt release hook
55 53 * @is_present: Whether the device is currently present on the parent bus
56 54 * @init_interrupts: NHI specific interrupt initialization hook
57 - * @reset_interface: Resets the host interface
58 55 */
59 56 struct tb_nhi_ops {
60 57 int (*init)(struct tb_nhi *nhi);
@@ -69,7 +66,6 @@ struct tb_nhi_ops {
69 66 void (*release_ring_irq)(struct tb_ring *ring);
70 67 bool (*is_present)(struct tb_nhi *nhi);
71 68 int (*init_interrupts)(struct tb_nhi *nhi);
72 - void (*reset_interface)(struct tb_nhi *nhi);
73 69 };
74 70
75 71 /*
@@ -120,24 +116,11 @@ struct tb_nhi_ops {
120 116 #define PCI_DEVICE_ID_INTEL_PTL_P_NHI0 0xe433
121 117 #define PCI_DEVICE_ID_INTEL_PTL_P_NHI1 0xe434
122 118
123 - #define PCI_DEVICE_ID_AMD_1AH_M60H_NHI0 0x1120
124 - #define PCI_DEVICE_ID_AMD_1AH_M60H_NHI1 0x1121
125 - #define PCI_DEVICE_ID_AMD_1AH_M68H_NHI0 0x113b
126 - #define PCI_DEVICE_ID_AMD_1AH_M68H_NHI1 0x113c
127 - #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI0 0x1155
128 - #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI1 0x1158
129 - #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI2 0x1159
130 - #define PCI_DEVICE_ID_AMD_1AH_M24H_NHI0 0x151c
131 - #define PCI_DEVICE_ID_AMD_1AH_M24H_NHI1 0x151d
132 - #define PCI_DEVICE_ID_AMD_1AH_M70H_NHI0 0x158d
133 - #define PCI_DEVICE_ID_AMD_1AH_M70H_NHI1 0x158e
134 -
135 119 #define PCI_CLASS_SERIAL_USB_USB4 0x0c0340
136 120
137 121 /* Host interface quirks */
138 - #define QUIRK_AUTO_CLEAR_INT BIT(0)
139 - #define QUIRK_E2E BIT(1)
140 - #define QUIRK_RESET_DMA_ON_TEARDOWN BIT(2)
122 + #define QUIRK_AUTO_CLEAR_INT BIT(0)
123 + #define QUIRK_E2E BIT(1)
141 124
142 125 /*
143 126 * Minimal number of vectors when we use MSI-X. Two for control channel
modified drivers/thunderbolt/nhi_regs.h
@@ -115,10 +115,6 @@ struct ring_desc {
115 115 #define REG_CAPS_VERSION_MASK GENMASK(23, 16)
116 116 #define REG_CAPS_VERSION_2 0x40
117 117
118 - /* Host Interface Reset - resets TX/RX rings and E2E flow control counters */
119 - #define REG_HOST_INTERFACE_RESET 0x39858
120 - #define REG_HOST_INTERFACE_RESET_RST BIT(0)
121 -
122 118 #define REG_DMA_MISC 0x39864
123 119 #define REG_DMA_MISC_INT_AUTO_CLEAR BIT(2)
124 120 #define REG_DMA_MISC_DISABLE_AUTO_CLEAR BIT(17)
modified drivers/thunderbolt/pci.c
@@ -62,27 +62,6 @@ static void nhi_pci_check_quirks(struct tb_nhi_pci *nhi_pci)
62 62 nhi->quirks |= QUIRK_E2E;
63 63 break;
64 64 }
65 - } else if (pdev->vendor == PCI_VENDOR_ID_AMD) {
66 - switch (pdev->device) {
67 - case PCI_DEVICE_ID_AMD_1AH_M60H_NHI0:
68 - case PCI_DEVICE_ID_AMD_1AH_M60H_NHI1:
69 - case PCI_DEVICE_ID_AMD_1AH_M68H_NHI0:
70 - case PCI_DEVICE_ID_AMD_1AH_M68H_NHI1:
71 - case PCI_DEVICE_ID_AMD_1AH_M80H_NHI0:
72 - case PCI_DEVICE_ID_AMD_1AH_M80H_NHI1:
73 - case PCI_DEVICE_ID_AMD_1AH_M80H_NHI2:
74 - case PCI_DEVICE_ID_AMD_1AH_M24H_NHI0:
75 - case PCI_DEVICE_ID_AMD_1AH_M24H_NHI1:
76 - case PCI_DEVICE_ID_AMD_1AH_M70H_NHI0:
77 - case PCI_DEVICE_ID_AMD_1AH_M70H_NHI1:
78 - /*
79 - * These AMD hosts may hang the Tx ring when the
80 - * DMA paths are torn down so they need the host
81 - * interface reset after each teardown.
82 - */
83 - nhi->quirks |= QUIRK_RESET_DMA_ON_TEARDOWN;
84 - break;
85 - }
86 65 }
87 66 }
88 67
@@ -279,7 +258,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = {
279 258 .shutdown = nhi_pci_release_irq,
280 259 .is_present = nhi_pci_is_present,
281 260 .init_interrupts = nhi_pci_init_msi,
282 - .reset_interface = nhi_reset_interface,
283 261 };
284 262
285 263 /* Ice Lake specific NHI operations */
@@ -463,7 +441,6 @@ static const struct tb_nhi_ops icl_nhi_ops = {
463 441 .release_ring_irq = nhi_pci_ring_release_msix,
464 442 .is_present = nhi_pci_is_present,
465 443 .init_interrupts = nhi_pci_init_msi,
466 - .reset_interface = nhi_reset_interface,
467 444 };
468 445
469 446 static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
modified drivers/thunderbolt/quirks.c
@@ -99,6 +99,9 @@ static const struct tb_quirk tb_quirks[] = {
99 99 quirk_usb3_maximum_bandwidth },
100 100 { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_40G_BRIDGE, 0x0000, 0x0000,
101 101 quirk_usb3_maximum_bandwidth },
102 + /* CLx is unstable on the Anker Prime TB5 dock (DROM 01ea:83b5) */
103 + { 0x8087, PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_80G_BRIDGE, 0x01ea, 0x83b5,
104 + quirk_clx_disable },
102 105 /*
103 106 * Block Runtime PM in DP redrive mode for Intel Barlow Ridge host
104 107 * controllers.
modified drivers/thunderbolt/stream.c
@@ -978,6 +978,9 @@ static int tbstream_dev_fops_open(struct inode *inode, struct file *file)
978 978 }
979 979
980 980 mutex_unlock(&sdev->lock);
981 +
982 + /* Stream handles IOCB_NOWAIT just fine */
983 + file->f_mode |= FMODE_NOWAIT;
981 984 return 0;
982 985
983 986 err_unlock:
modified drivers/thunderbolt/switch.c
@@ -774,6 +774,7 @@ static int tb_port_alloc_hopid(struct tb_port *port, bool in, int min_hopid,
774 774 {
775 775 int port_max_hopid;
776 776 struct ida *ida;
777 + int ret;
777 778
778 779 if (in) {
779 780 port_max_hopid = port->config.max_in_hop_id;
@@ -793,7 +794,11 @@ static int tb_port_alloc_hopid(struct tb_port *port, bool in, int min_hopid,
793 794 if (max_hopid < 0 || max_hopid > port_max_hopid)
794 795 max_hopid = port_max_hopid;
795 796
796 - return ida_alloc_range(ida, min_hopid, max_hopid, GFP_KERNEL);
797 + ret = ida_alloc_range(ida, min_hopid, max_hopid, GFP_KERNEL);
798 + if (ret >= 0)
799 + tb_switch_get(port->sw);
800 +
801 + return ret;
797 802 }
798 803
799 804 /**
@@ -832,6 +837,7 @@ int tb_port_alloc_out_hopid(struct tb_port *port, int min_hopid, int max_hopid)
832 837 void tb_port_release_in_hopid(struct tb_port *port, int hopid)
833 838 {
834 839 ida_free(&port->in_hopids, hopid);
840 + tb_switch_put(port->sw);
835 841 }
836 842
837 843 /**
@@ -842,6 +848,7 @@ void tb_port_release_in_hopid(struct tb_port *port, int hopid)
842 848 void tb_port_release_out_hopid(struct tb_port *port, int hopid)
843 849 {
844 850 ida_free(&port->out_hopids, hopid);
851 + tb_switch_put(port->sw);
845 852 }
846 853
847 854 static inline bool tb_switch_is_reachable(const struct tb_switch *parent,
modified drivers/thunderbolt/tb.c
@@ -89,6 +89,7 @@ static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port,
89 89 const char *reason);
90 90 static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port,
91 91 int retry, unsigned long delay);
92 + static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data);
92 93
93 94 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
94 95 {
@@ -385,7 +386,8 @@ static void tb_switch_discover_tunnels(struct tb_switch *sw,
385 386
386 387 switch (port->config.type) {
387 388 case TB_TYPE_DP_HDMI_IN:
388 - tunnel = tb_tunnel_discover_dp(tb, port, alloc_hopids);
389 + tunnel = tb_tunnel_discover_dp(tb, port, alloc_hopids,
390 + tb_dp_tunnel_active, tb);
389 391 tb_increase_tmu_accuracy(tunnel);
390 392 break;
391 393
@@ -1910,6 +1912,18 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)
1910 1912 struct tb *tb = data;
1911 1913
1912 1914 mutex_lock(&tb->lock);
1915 +
1916 + /*
1917 + * If the DPRX read was canceled the tunnel is already being torn
1918 + * down by whoever canceled it. Do not touch the adapters here
1919 + * because the routers may be gone by now.
1920 + */
1921 + if (tunnel->dprx_canceled) {
1922 + tb_tunnel_dbg(tunnel, "DPRX read canceled, not activating\n");
1923 + mutex_unlock(&tb->lock);
1924 + return;
1925 + }
1926 +
1913 1927 if (tb_tunnel_is_active(tunnel)) {
1914 1928 int consumed_up, consumed_down, ret;
1915 1929
@@ -1964,8 +1978,6 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)
1964 1978 tb_dp_resource_unavailable(tb, in, "DPRX negotiation failed");
1965 1979 }
1966 1980 mutex_unlock(&tb->lock);
1967 -
1968 - tb_domain_put(tb);
1969 1981 }
1970 1982
1971 1983 static void tb_tunnel_one_dp(struct tb *tb, struct tb_port *in,
@@ -2026,8 +2038,7 @@ static void tb_tunnel_one_dp(struct tb *tb, struct tb_port *in,
2026 2038 available_up, available_down);
2027 2039
2028 2040 tunnel = tb_tunnel_alloc_dp(tb, in, out, link_nr, available_up,
2029 - available_down, tb_dp_tunnel_active,
2030 - tb_domain_get(tb));
2041 + available_down, tb_dp_tunnel_active, tb);
2031 2042 if (!tunnel) {
2032 2043 tb_port_dbg(out, "could not allocate DP tunnel\n");
2033 2044 goto err_reclaim_usb;
@@ -2048,7 +2059,6 @@ err_free:
2048 2059 tb_tunnel_put(tunnel);
2049 2060 err_reclaim_usb:
2050 2061 tb_reclaim_usb3_bandwidth(tb, in, out);
2051 - tb_domain_put(tb);
2052 2062 err_detach_group:
2053 2063 tb_detach_bandwidth_group(in);
2054 2064 err_dealloc_dp:
@@ -2950,11 +2960,12 @@ static void tb_stop(struct tb *tb)
2950 2960 /* tunnels are only present after everything has been initialized */
2951 2961 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
2952 2962 /*
2953 - * DMA tunnels require the driver to be functional so we
2954 - * tear them down. Other protocol tunnels can be left
2955 - * intact.
2963 + * DMA tunnels and DP tunnels which are not yet active require
2964 + * the driver to be functional so we tear them down.
2965 + * Other protocol tunnels can be left intact.
2956 2966 */
2957 - if (tb_tunnel_is_dma(tunnel))
2967 + if (tb_tunnel_is_dma(tunnel) ||
2968 + (tb_tunnel_is_dp(tunnel) && !tb_tunnel_is_active(tunnel)))
2958 2969 tb_tunnel_deactivate(tunnel);
2959 2970 tb_tunnel_put(tunnel);
2960 2971 }
@@ -3274,11 +3285,11 @@ static void tb_remove_work(struct work_struct *work)
3274 3285 struct tb *tb = tcm_to_tb(tcm);
3275 3286
3276 3287 mutex_lock(&tb->lock);
3277 - if (tb->root_switch)
3288 + if (tb->root_switch) {
3278 3289 tb_free_unplugged_children(tb->root_switch);
3290 + tb_free_unplugged_xdomains(tb->root_switch);
3291 + }
3279 3292 mutex_unlock(&tb->lock);
3280 -
3281 - tb_free_unplugged_xdomains(tb->root_switch);
3282 3293 }
3283 3294
3284 3295 static int tb_runtime_resume(struct tb *tb)
modified drivers/thunderbolt/test.c
@@ -33,6 +33,18 @@ static void kunit_ida_init(struct kunit *test, struct ida *ida)
33 33 kunit_alloc_resource(test, __ida_init, __ida_destroy, GFP_KERNEL, ida);
34 34 }
35 35
36 + static void tb_test_switch_release(struct device *dev)
37 + {
38 + /* The memory is owned by KUnit, nothing to do here */
39 + }
40 +
41 + static void tb_test_switch_put(void *data)
42 + {
43 + struct tb_switch *sw = data;
44 +
45 + put_device(&sw->dev);
46 + }
47 +
36 48 static struct tb_switch *alloc_switch(struct kunit *test, u64 route,
37 49 u8 upstream_port, u8 max_port_number)
38 50 {
@@ -44,6 +56,15 @@ static struct tb_switch *alloc_switch(struct kunit *test, u64 route,
44 56 if (!sw)
45 57 return NULL;
46 58
59 + /*
60 + * HopID allocations take a reference to their routers and those devices
61 + * have to be initialized for that to work.
62 + */
63 + sw->dev.release = tb_test_switch_release;
64 + device_initialize(&sw->dev);
65 + if (kunit_add_action_or_reset(test, tb_test_switch_put, sw))
66 + return NULL;
67 +
47 68 sw->config.upstream_port_number = upstream_port;
48 69 sw->config.depth = tb_route_length(route);
49 70 sw->config.route_hi = upper_32_bits(route);
@@ -1386,6 +1407,10 @@ static void tb_test_tunnel_pcie(struct kunit *test)
1386 1407 tb_tunnel_put(tunnel1);
1387 1408 }
1388 1409
1410 + static void tb_test_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)
1411 + {
1412 + }
1413 +
1389 1414 static void tb_test_tunnel_dp(struct kunit *test)
1390 1415 {
1391 1416 struct tb_switch *host, *dev;
@@ -1406,7 +1431,8 @@ static void tb_test_tunnel_dp(struct kunit *test)
1406 1431 in = &host->ports[5];
1407 1432 out = &dev->ports[13];
1408 1433
1409 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
1434 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
1435 + tb_test_dp_tunnel_active, NULL);
1410 1436 KUNIT_ASSERT_NOT_NULL(test, tunnel);
1411 1437 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP);
1412 1438 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in);
@@ -1452,7 +1478,8 @@ static void tb_test_tunnel_dp_chain(struct kunit *test)
1452 1478 in = &host->ports[5];
1453 1479 out = &dev4->ports[14];
1454 1480
1455 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
1481 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
1482 + tb_test_dp_tunnel_active, NULL);
1456 1483 KUNIT_ASSERT_NOT_NULL(test, tunnel);
1457 1484 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP);
1458 1485 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in);
@@ -1502,7 +1529,8 @@ static void tb_test_tunnel_dp_tree(struct kunit *test)
1502 1529 in = &dev2->ports[13];
1503 1530 out = &dev5->ports[13];
1504 1531
1505 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
1532 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
1533 + tb_test_dp_tunnel_active, NULL);
1506 1534 KUNIT_ASSERT_NOT_NULL(test, tunnel);
1507 1535 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP);
1508 1536 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in);
@@ -1567,7 +1595,8 @@ static void tb_test_tunnel_dp_max_length(struct kunit *test)
1567 1595 in = &dev6->ports[13];
1568 1596 out = &dev12->ports[13];
1569 1597
1570 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
1598 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
1599 + tb_test_dp_tunnel_active, NULL);
1571 1600 KUNIT_ASSERT_NOT_NULL(test, tunnel);
1572 1601 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP);
1573 1602 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in);
@@ -1637,7 +1666,8 @@ static void tb_test_tunnel_3dp(struct kunit *test)
1637 1666 out2 = &dev5->ports[13];
1638 1667 out3 = &dev4->ports[14];
1639 1668
1640 - tunnel1 = tb_tunnel_alloc_dp(NULL, in1, out1, 1, 0, 0, NULL, NULL);
1669 + tunnel1 = tb_tunnel_alloc_dp(NULL, in1, out1, 1, 0, 0,
1670 + tb_test_dp_tunnel_active, NULL);
1641 1671 KUNIT_ASSERT_TRUE(test, tunnel1 != NULL);
1642 1672 KUNIT_EXPECT_EQ(test, tunnel1->type, TB_TUNNEL_DP);
1643 1673 KUNIT_EXPECT_PTR_EQ(test, tunnel1->src_port, in1);
@@ -1645,7 +1675,8 @@ static void tb_test_tunnel_3dp(struct kunit *test)
1645 1675 KUNIT_ASSERT_EQ(test, tunnel1->npaths, 3);
1646 1676 KUNIT_ASSERT_EQ(test, tunnel1->paths[0]->path_length, 3);
1647 1677
1648 - tunnel2 = tb_tunnel_alloc_dp(NULL, in2, out2, 1, 0, 0, NULL, NULL);
1678 + tunnel2 = tb_tunnel_alloc_dp(NULL, in2, out2, 1, 0, 0,
1679 + tb_test_dp_tunnel_active, NULL);
1649 1680 KUNIT_ASSERT_TRUE(test, tunnel2 != NULL);
1650 1681 KUNIT_EXPECT_EQ(test, tunnel2->type, TB_TUNNEL_DP);
1651 1682 KUNIT_EXPECT_PTR_EQ(test, tunnel2->src_port, in2);
@@ -1653,7 +1684,8 @@ static void tb_test_tunnel_3dp(struct kunit *test)
1653 1684 KUNIT_ASSERT_EQ(test, tunnel2->npaths, 3);
1654 1685 KUNIT_ASSERT_EQ(test, tunnel2->paths[0]->path_length, 4);
1655 1686
1656 - tunnel3 = tb_tunnel_alloc_dp(NULL, in3, out3, 1, 0, 0, NULL, NULL);
1687 + tunnel3 = tb_tunnel_alloc_dp(NULL, in3, out3, 1, 0, 0,
1688 + tb_test_dp_tunnel_active, NULL);
1657 1689 KUNIT_ASSERT_TRUE(test, tunnel3 != NULL);
1658 1690 KUNIT_EXPECT_EQ(test, tunnel3->type, TB_TUNNEL_DP);
1659 1691 KUNIT_EXPECT_PTR_EQ(test, tunnel3->src_port, in3);
@@ -1751,7 +1783,8 @@ static void tb_test_tunnel_port_on_path(struct kunit *test)
1751 1783 in = &dev2->ports[13];
1752 1784 out = &dev5->ports[13];
1753 1785
1754 - dp_tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
1786 + dp_tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
1787 + tb_test_dp_tunnel_active, NULL);
1755 1788 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel);
1756 1789
1757 1790 KUNIT_EXPECT_TRUE(test, tb_tunnel_port_on_path(dp_tunnel, in));
@@ -2183,7 +2216,8 @@ static void tb_test_credit_alloc_dp(struct kunit *test)
2183 2216 in = &host->ports[5];
2184 2217 out = &dev->ports[14];
2185 2218
2186 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
2219 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
2220 + tb_test_dp_tunnel_active, NULL);
2187 2221 KUNIT_ASSERT_NOT_NULL(test, tunnel);
2188 2222 KUNIT_ASSERT_EQ(test, tunnel->npaths, (size_t)3);
2189 2223
@@ -2419,7 +2453,8 @@ static struct tb_tunnel *TB_TEST_DP_TUNNEL1(struct kunit *test,
2419 2453
2420 2454 in = &host->ports[5];
2421 2455 out = &dev->ports[13];
2422 - dp_tunnel1 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
2456 + dp_tunnel1 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
2457 + tb_test_dp_tunnel_active, NULL);
2423 2458 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel1);
2424 2459 KUNIT_ASSERT_EQ(test, dp_tunnel1->npaths, (size_t)3);
2425 2460
@@ -2456,7 +2491,8 @@ static struct tb_tunnel *TB_TEST_DP_TUNNEL2(struct kunit *test,
2456 2491
2457 2492 in = &host->ports[6];
2458 2493 out = &dev->ports[14];
2459 - dp_tunnel2 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL);
2494 + dp_tunnel2 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0,
2495 + tb_test_dp_tunnel_active, NULL);
2460 2496 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel2);
2461 2497 KUNIT_ASSERT_EQ(test, dp_tunnel2->npaths, (size_t)3);
2462 2498
modified drivers/thunderbolt/tunnel.c
@@ -510,6 +510,7 @@ struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,
510 510 goto err_deactivate;
511 511 }
512 512
513 + tb_tunnel_set_active(tunnel, true);
513 514 tb_tunnel_dbg(tunnel, "discovered\n");
514 515 return tunnel;
515 516
@@ -1093,8 +1094,14 @@ static void tb_dp_dprx_work(struct work_struct *work)
1093 1094 struct tb_tunnel *tunnel = container_of(work, typeof(*tunnel), dprx_work.work);
1094 1095 struct tb *tb = tunnel->tb;
1095 1096
1097 + /*
1098 + * The DPRX read can be canceled while this work is waiting for
1099 + * tb->lock. Check the flag only once it is held: while the lock is
1100 + * held the tunnel cannot be torn down under us and the adapters are
1101 + * safe to access.
1102 + */
1103 + mutex_lock(&tb->lock);
1096 1104 if (!tunnel->dprx_canceled) {
1097 - mutex_lock(&tb->lock);
1098 1105 if (tb_dp_is_usb4(tunnel->src_port->sw) &&
1099 1106 tb_dp_wait_dprx(tunnel, TB_DPRX_WAIT_TIMEOUT)) {
1100 1107 if (ktime_before(ktime_get(), tunnel->dprx_timeout)) {
@@ -1106,41 +1113,42 @@ static void tb_dp_dprx_work(struct work_struct *work)
1106 1113 } else {
1107 1114 tb_tunnel_set_active(tunnel, true);
1108 1115 }
1109 - mutex_unlock(&tb->lock);
1110 1116 }
1117 + mutex_unlock(&tb->lock);
1111 1118
1112 - if (tunnel->callback)
1113 - tunnel->callback(tunnel, tunnel->callback_data);
1119 + tunnel->callback(tunnel, tunnel->callback_data);
1114 1120 tb_tunnel_put(tunnel);
1121 + tb_domain_put(tb);
1115 1122 }
1116 1123
1117 1124 static int tb_dp_dprx_start(struct tb_tunnel *tunnel)
1118 1125 {
1119 1126 /*
1120 - * Bump up the reference to keep the tunnel around. It will be
1121 - * dropped in tb_dp_dprx_stop() once the tunnel is deactivated.
1127 + * Bump up the references to keep the tunnel and the domain around
1128 + * until the work has run or has been canceled.
1122 1129 */
1123 1130 tb_tunnel_get(tunnel);
1131 + tb_domain_get(tunnel->tb);
1124 1132
1125 1133 tunnel->dprx_started = true;
1134 + tunnel->dprx_canceled = false;
1135 + tunnel->dprx_timeout = dprx_timeout_to_ktime(dprx_timeout);
1136 + queue_delayed_work(tunnel->tb->wq, &tunnel->dprx_work, 0);
1126 1137
1127 - if (tunnel->callback) {
1128 - tunnel->dprx_timeout = dprx_timeout_to_ktime(dprx_timeout);
1129 - queue_delayed_work(tunnel->tb->wq, &tunnel->dprx_work, 0);
1130 - return -EINPROGRESS;
1131 - }
1132 -
1133 - return tb_dp_is_usb4(tunnel->src_port->sw) ?
1134 - tb_dp_wait_dprx(tunnel, dprx_timeout) : 0;
1138 + return -EINPROGRESS;
1135 1139 }
1136 1140
1137 1141 static void tb_dp_dprx_stop(struct tb_tunnel *tunnel)
1138 1142 {
1143 + struct tb *tb = tunnel->tb;
1144 +
1139 1145 if (tunnel->dprx_started) {
1140 1146 tunnel->dprx_started = false;
1141 1147 tunnel->dprx_canceled = true;
1142 - if (cancel_delayed_work(&tunnel->dprx_work))
1148 + if (cancel_delayed_work(&tunnel->dprx_work)) {
1143 1149 tb_tunnel_put(tunnel);
1150 + tb_domain_put(tb);
1151 + }
1144 1152 }
1145 1153 }
1146 1154
@@ -1582,20 +1590,28 @@ static void tb_dp_dump(struct tb_tunnel *tunnel)
1582 1590 * @tb: Pointer to the domain structure
1583 1591 * @in: DP in adapter
1584 1592 * @alloc_hopid: Allocate HopIDs from visited ports
1593 + * @callback: Callback that is called when the DP tunnel is fully
1594 + * activated (or there is an error)
1595 + * @callback_data: Data for @callback
1585 1596 *
1586 1597 * If @in adapter is active, follows the tunnel to the DP out adapter
1587 1598 * and back. Returns the discovered tunnel or %NULL if there was no
1588 - * tunnel.
1599 + * tunnel. See tb_tunnel_alloc_dp() for @callback.
1589 1600 *
1590 1601 * Return: Pointer to &struct tb_tunnel or %NULL if no tunnel found.
1591 1602 */
1592 1603 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
1593 - bool alloc_hopid)
1604 + bool alloc_hopid,
1605 + void (*callback)(struct tb_tunnel *, void *),
1606 + void *callback_data)
1594 1607 {
1595 1608 struct tb_tunnel *tunnel;
1596 1609 struct tb_port *port;
1597 1610 struct tb_path *path;
1598 1611
1612 + if (WARN_ON(!callback))
1613 + return NULL;
1614 +
1599 1615 if (!tb_dp_port_is_enabled(in))
1600 1616 return NULL;
1601 1617
@@ -1611,6 +1627,9 @@ struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
1611 1627 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth;
1612 1628 tunnel->consumed_bandwidth = tb_dp_consumed_bandwidth;
1613 1629 tunnel->src_port = in;
1630 + tunnel->callback = callback;
1631 + tunnel->callback_data = callback_data;
1632 + INIT_DELAYED_WORK(&tunnel->dprx_work, tb_dp_dprx_work);
1614 1633
1615 1634 path = tb_path_discover(in, TB_DP_VIDEO_HOPID, NULL, -1,
1616 1635 &tunnel->dst_port, "Video", alloc_hopid);
@@ -1656,6 +1675,7 @@ struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
1656 1675
1657 1676 tb_dp_dump(tunnel);
1658 1677
1678 + tb_tunnel_set_active(tunnel, true);
1659 1679 tb_tunnel_dbg(tunnel, "discovered\n");
1660 1680 return tunnel;
1661 1681
@@ -1677,16 +1697,16 @@ err_free:
1677 1697 * %0 if no available bandwidth.
1678 1698 * @max_down: Maximum available downstream bandwidth for the DP tunnel.
1679 1699 * %0 if no available bandwidth.
1680 - * @callback: Optional callback that is called when the DP tunnel is
1681 - * fully activated (or there is an error)
1682 - * @callback_data: Optional data for @callback
1700 + * @callback: Callback that is called when the DP tunnel is fully
1701 + * activated (or there is an error)
1702 + * @callback_data: Data for @callback
1683 1703 *
1684 1704 * Allocates a tunnel between @in and @out that is capable of tunneling
1685 - * Display Port traffic. If @callback is not %NULL it will be called
1686 - * after tb_tunnel_activate() once the tunnel has been fully activated.
1687 - * It can call tb_tunnel_is_active() to check if activation was
1688 - * successful (or if it returns %false there was some sort of issue).
1689 - * The @callback is called without @tb->lock held.
1705 + * Display Port traffic. The @callback is called after tb_tunnel_activate()
1706 + * once the tunnel has been fully activated. It can call
1707 + * tb_tunnel_is_active() to check if activation was successful (or if it
1708 + * returns %false there was some sort of issue). The @callback is called
1709 + * without @tb->lock held.
1690 1710 *
1691 1711 * Return: Pointer to @struct tb_tunnel or %NULL in case of failure.
1692 1712 */
@@ -1701,7 +1721,7 @@ struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
1701 1721 struct tb_path *path;
1702 1722 bool pm_support;
1703 1723
1704 - if (WARN_ON(!in->cap_adap || !out->cap_adap))
1724 + if (WARN_ON(!in->cap_adap || !out->cap_adap || !callback))
1705 1725 return NULL;
1706 1726
1707 1727 tunnel = tb_tunnel_alloc(tb, 3, TB_TUNNEL_DP);
@@ -2288,6 +2308,7 @@ struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
2288 2308 tb_usb3_reclaim_available_bandwidth;
2289 2309 }
2290 2310
2311 + tb_tunnel_set_active(tunnel, true);
2291 2312 tb_tunnel_dbg(tunnel, "discovered\n");
2292 2313 return tunnel;
2293 2314
modified drivers/thunderbolt/tunnel.h
@@ -66,8 +66,8 @@ enum tb_tunnel_state {
66 66 * @dprx_canceled: Was DPRX capabilities read poll canceled
67 67 * @dprx_timeout: If set DPRX capabilities read poll work will timeout after this passes
68 68 * @dprx_work: Worker that is scheduled to poll completion of DPRX capabilities read
69 - * @callback: Optional callback called when DP tunnel is fully activated
70 - * @callback_data: Optional data for @callback
69 + * @callback: Callback called when DP tunnel is fully activated
70 + * @callback_data: Data for @callback
71 71 * @paths: All paths required by the tunnel
72 72 */
73 73 struct tb_tunnel {
@@ -117,7 +117,9 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
117 117 bool tb_tunnel_reserved_pci(struct tb_port *port, int *reserved_up,
118 118 int *reserved_down);
119 119 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
120 - bool alloc_hopid);
120 + bool alloc_hopid,
121 + void (*callback)(struct tb_tunnel *, void *),
122 + void *callback_data);
121 123 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
122 124 struct tb_port *out, int link_nr,
123 125 int max_up, int max_down,
modified drivers/thunderbolt/xdomain.c
@@ -377,6 +377,10 @@ static int tb_xdp_properties_request(struct tb_ctl *ctl, u64 route,
377 377
378 378 len += sizeof(res->hdr.xd_hdr) / 4;
379 379 len -= sizeof(*res) / 4;
380 + if (len > TB_XDP_PROPERTIES_MAX_DATA_LENGTH) {
381 + ret = -EINVAL;
382 + goto err;
383 + }
380 384
381 385 if (res->offset != req.offset) {
382 386 ret = -EINVAL;
@@ -1814,7 +1818,6 @@ static void tb_xdomain_state_work(struct work_struct *work)
1814 1818 tb_xdomain_failed(xd);
1815 1819 } else {
1816 1820 xd->state = XDOMAIN_STATE_ENUMERATED;
1817 - tb_xdomain_queue_properties_changed(xd);
1818 1821 }
1819 1822 break;
1820 1823
modified drivers/tty/amiserial.c
@@ -1138,11 +1138,6 @@ static int rs_ioctl(struct tty_struct *tty,
1138 1138 local_irq_save(flags);
1139 1139 cnow = info->icount; /* atomic copy */
1140 1140 local_irq_restore(flags);
1141 - if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1142 - cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
1143 - ret = -EIO; /* no change => error */
1144 - break;
1145 - }
1146 1141 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1147 1142 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1148 1143 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
@@ -1150,6 +1145,10 @@ static int rs_ioctl(struct tty_struct *tty,
1150 1145 ret = 0;
1151 1146 break;
1152 1147 }
1148 + if (tty_io_error(tty)) {
1149 + ret = -EIO;
1150 + break;
1151 + }
1153 1152 schedule();
1154 1153 /* see if a signal did it */
1155 1154 if (signal_pending(current)) {
modified drivers/tty/n_gsm.c
@@ -454,14 +454,13 @@ static const u8 gsm_fcs8[256] = {
454 454
455 455 static void gsm_dlci_close(struct gsm_dlci *dlci);
456 456 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len);
457 - static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk);
457 + static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk, bool wait);
458 458 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
459 459 u8 ctrl);
460 460 static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg);
461 461 static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr);
462 462 static void gsmld_write_trigger(struct gsm_mux *gsm);
463 463 static void gsmld_write_task(struct work_struct *work);
464 - static int gsm_modem_send_initial_msc(struct gsm_dlci *dlci);
465 464
466 465 /**
467 466 * gsm_fcs_add - update FCS
@@ -2174,7 +2173,7 @@ static void gsm_dlci_open(struct gsm_dlci *dlci)
2174 2173 pr_debug("DLCI %d goes open.\n", dlci->addr);
2175 2174 /* Send current modem state */
2176 2175 if (dlci->addr) {
2177 - gsm_modem_send_initial_msc(dlci);
2176 + gsm_modem_update(dlci, 0, false);
2178 2177 } else {
2179 2178 /* Start keep-alive control */
2180 2179 gsm->ka_num = 0;
@@ -4136,9 +4135,10 @@ static void gsm_modem_upd_via_data(struct gsm_dlci *dlci, u8 brk)
4136 4135 * gsm_modem_upd_via_msc - send modem bits via control frame
4137 4136 * @dlci: channel
4138 4137 * @brk: break signal
4138 + * @wait: wait for the MSC command
4139 4139 */
4140 4140
4141 - static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
4141 + static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk, bool wait)
4142 4142 {
4143 4143 u8 modembits[3];
4144 4144 struct gsm_control *ctrl;
@@ -4155,41 +4155,22 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk)
4155 4155 modembits[2] = (brk << 4) | 2 | EA; /* Length, Break, EA */
4156 4156 len++;
4157 4157 }
4158 + if (!wait)
4159 + return gsm_control_command(dlci->gsm, CMD_MSC, modembits, len);
4158 4160 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len);
4159 4161 if (ctrl == NULL)
4160 4162 return -ENOMEM;
4161 4163 return gsm_control_wait(dlci->gsm, ctrl);
4162 4164 }
4163 4165
4164 - /**
4165 - * gsm_modem_send_initial_msc - Send initial modem status message
4166 - *
4167 - * @dlci: channel
4168 - *
4169 - * Send an initial MSC message after DLCI open to set the initial
4170 - * modem status lines. This is only done for basic mode.
4171 - * Does not wait for a response as we cannot block the input queue
4172 - * processing.
4173 - */
4174 - static int gsm_modem_send_initial_msc(struct gsm_dlci *dlci)
4175 - {
4176 - u8 modembits[2];
4177 -
4178 - if (dlci->adaption != 1 || dlci->gsm->encoding != GSM_BASIC_OPT)
4179 - return 0;
4180 -
4181 - modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */
4182 - modembits[1] = (gsm_encode_modem(dlci) << 1) | EA;
4183 - return gsm_control_command(dlci->gsm, CMD_MSC, (const u8 *)&modembits, 2);
4184 - }
4185 -
4186 4166 /**
4187 4167 * gsm_modem_update - send modem status line state
4188 4168 * @dlci: channel
4189 4169 * @brk: break signal
4170 + * @wait: wait for the MSC command
4190 4171 */
4191 4172
4192 - static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
4173 + static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk, bool wait)
4193 4174 {
4194 4175 if (dlci->gsm->dead)
4195 4176 return -EL2HLT;
@@ -4199,7 +4180,7 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
4199 4180 return 0;
4200 4181 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) {
4201 4182 /* Send as MSC control message. */
4202 - return gsm_modem_upd_via_msc(dlci, brk);
4183 + return gsm_modem_upd_via_msc(dlci, brk, wait);
4203 4184 }
4204 4185
4205 4186 /* Modem status lines are not supported. */
@@ -4265,7 +4246,7 @@ static void gsm_dtr_rts(struct tty_port *port, bool active)
4265 4246 modem_tx &= ~(TIOCM_DTR | TIOCM_RTS);
4266 4247 if (modem_tx != dlci->modem_tx) {
4267 4248 dlci->modem_tx = modem_tx;
4268 - gsm_modem_update(dlci, 0);
4249 + gsm_modem_update(dlci, 0, true);
4269 4250 }
4270 4251 }
4271 4252
@@ -4471,7 +4452,7 @@ static int gsmtty_tiocmset(struct tty_struct *tty,
4471 4452
4472 4453 if (modem_tx != dlci->modem_tx) {
4473 4454 dlci->modem_tx = modem_tx;
4474 - return gsm_modem_update(dlci, 0);
4455 + return gsm_modem_update(dlci, 0, true);
4475 4456 }
4476 4457 return 0;
4477 4458 }
@@ -4553,7 +4534,7 @@ static void gsmtty_throttle(struct tty_struct *tty)
4553 4534 dlci->modem_tx &= ~TIOCM_RTS;
4554 4535 dlci->throttled = true;
4555 4536 /* Send an MSC with RTS cleared */
4556 - gsm_modem_update(dlci, 0);
4537 + gsm_modem_update(dlci, 0, true);
4557 4538 }
4558 4539
4559 4540 static void gsmtty_unthrottle(struct tty_struct *tty)
@@ -4565,7 +4546,7 @@ static void gsmtty_unthrottle(struct tty_struct *tty)
4565 4546 dlci->modem_tx |= TIOCM_RTS;
4566 4547 dlci->throttled = false;
4567 4548 /* Send an MSC with RTS set */
4568 - gsm_modem_update(dlci, 0);
4549 + gsm_modem_update(dlci, 0, true);
4569 4550 }
4570 4551
4571 4552 static int gsmtty_break_ctl(struct tty_struct *tty, int state)
@@ -4583,7 +4564,7 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)
4583 4564 if (encode > 0x0F)
4584 4565 encode = 0x0F; /* Best effort */
4585 4566 }
4586 - return gsm_modem_update(dlci, encode);
4567 + return gsm_modem_update(dlci, encode, true);
4587 4568 }
4588 4569
4589 4570 static void gsmtty_cleanup(struct tty_struct *tty)
modified drivers/tty/serial/8250/8250_bcm7271.c
@@ -1121,8 +1121,8 @@ static void brcmuart_remove(struct platform_device *pdev)
1121 1121 struct brcmuart_priv *priv = platform_get_drvdata(pdev);
1122 1122
1123 1123 debugfs_remove_recursive(priv->debugfs_dir);
1124 - hrtimer_cancel(&priv->hrt);
1125 1124 serial8250_unregister_port(priv->line);
1125 + hrtimer_cancel(&priv->hrt);
1126 1126 brcmuart_free_bufs(&pdev->dev, priv);
1127 1127 if (priv->dma_enabled)
1128 1128 brcmuart_arbitration(priv, 0);
modified drivers/tty/serial/8250/8250_omap.c
@@ -711,12 +711,6 @@ static int omap_8250_startup(struct uart_port *port)
711 711 struct uart_8250_dma *dma = &priv->omap8250_dma;
712 712 int ret;
713 713
714 - if (priv->wakeirq) {
715 - ret = dev_pm_set_dedicated_wake_irq(port->dev, priv->wakeirq);
716 - if (ret)
717 - return ret;
718 - }
719 -
720 714 #ifdef CONFIG_PM
721 715 up->capabilities |= UART_CAP_RPM;
722 716 #endif
@@ -787,7 +781,6 @@ static void omap_8250_shutdown(struct uart_port *port)
787 781 }
788 782
789 783 disable_irq_nosync(port->irq);
790 - dev_pm_clear_wake_irq(port->dev);
791 784
792 785 serial8250_release_dma(up);
793 786 up->dma = NULL;
@@ -1588,6 +1581,12 @@ static int omap8250_probe(struct platform_device *pdev)
1588 1581
1589 1582 priv->wakeirq = irq_of_parse_and_map(np, 1);
1590 1583
1584 + if (priv->wakeirq) {
1585 + ret = dev_pm_set_dedicated_wake_irq(&pdev->dev, priv->wakeirq);
1586 + if (ret)
1587 + goto err;
1588 + }
1589 +
1591 1590 ret = serial8250_register_8250_port(&up);
1592 1591 if (ret < 0) {
1593 1592 dev_err(&pdev->dev, "unable to register 8250 port\n");
@@ -1603,6 +1602,7 @@ static int omap8250_probe(struct platform_device *pdev)
1603 1602
1604 1603 return 0;
1605 1604 err:
1605 + dev_pm_clear_wake_irq(&pdev->dev);
1606 1606 pm_runtime_dont_use_autosuspend(&pdev->dev);
1607 1607 pm_runtime_put_sync(&pdev->dev);
1608 1608 flush_work(&priv->qos_work);
@@ -1625,6 +1625,7 @@ static void omap8250_remove(struct platform_device *pdev)
1625 1625 omap_8250_shutdown(&up->port);
1626 1626 serial8250_unregister_port(priv->line);
1627 1627 priv->line = -ENODEV;
1628 + dev_pm_clear_wake_irq(&pdev->dev);
1628 1629 pm_runtime_dont_use_autosuspend(&pdev->dev);
1629 1630 pm_runtime_put_sync(&pdev->dev);
1630 1631 flush_work(&priv->qos_work);
modified drivers/tty/serial/8250/8250_port.c
@@ -3597,7 +3597,7 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
3597 3597
3598 3598 up->console_line_ended = true;
3599 3599 up->console_msr_work_allow = true;
3600 - init_irq_work(&up->console_msr_work, console_msr_handler);
3600 + up->console_msr_work = IRQ_WORK_INIT_LAZY(console_msr_handler);
3601 3601
3602 3602 if (options)
3603 3603 uart_parse_options(options, &baud, &parity, &bits, &flow);
modified drivers/tty/serial/kgdboc.c
@@ -188,6 +188,11 @@ static void cleanup_kgdboc(void)
188 188
189 189 kgdboc_unregister_kbd();
190 190 kgdb_unregister_io_module(&kgdboc_io_ops);
191 +
192 + if (kgdb_tty_driver) {
193 + tty_driver_kref_put(kgdb_tty_driver);
194 + kgdb_tty_driver = NULL;
195 + }
191 196 }
192 197
193 198 static int configure_kgdboc(void)
@@ -254,6 +259,10 @@ do_register:
254 259
255 260 noconfig:
256 261 kgdboc_unregister_kbd();
262 + if (kgdb_tty_driver) {
263 + tty_driver_kref_put(kgdb_tty_driver);
264 + kgdb_tty_driver = NULL;
265 + }
257 266 configured = 0;
258 267
259 268 return err;
modified drivers/tty/serial/ma35d1_serial.c
@@ -728,7 +728,7 @@ static int ma35d1serial_probe(struct platform_device *pdev)
728 728
729 729 ret = clk_prepare_enable(up->clk);
730 730 if (ret)
731 - goto err_iounmap;
731 + goto err_put_clk;
732 732
733 733 if (up->port.line != 0)
734 734 up->port.uartclk = clk_get_rate(up->clk);
@@ -755,6 +755,9 @@ err_free_irq:
755 755 err_clk_disable:
756 756 clk_disable_unprepare(up->clk);
757 757
758 + err_put_clk:
759 + clk_put(up->clk);
760 +
758 761 err_iounmap:
759 762 iounmap(up->port.membase);
760 763 return ret;
@@ -770,6 +773,7 @@ static void ma35d1serial_remove(struct platform_device *dev)
770 773
771 774 uart_remove_one_port(&ma35d1serial_reg, port);
772 775 clk_disable_unprepare(up->clk);
776 + clk_put(up->clk);
773 777 }
774 778
775 779 static int ma35d1serial_suspend(struct platform_device *dev, pm_message_t state)
modified drivers/tty/serial/max3100.c
@@ -535,11 +535,11 @@ static void max3100_shutdown(struct uart_port *port)
535 535 timer_delete_sync(&s->timer);
536 536
537 537 if (s->workqueue) {
538 + free_irq(port->irq, s);
539 + cancel_work_sync(&s->work);
538 540 destroy_workqueue(s->workqueue);
539 541 s->workqueue = NULL;
540 542 }
541 - if (port->irq)
542 - free_irq(port->irq, s);
543 543
544 544 /* set shutdown mode to save power */
545 545 max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx);
@@ -753,6 +753,15 @@ static void max3100_remove(struct spi_device *spi)
753 753 if (max3100s[i] == s) {
754 754 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i);
755 755 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port);
756 +
757 + s->force_end_work = 1;
758 + timer_shutdown_sync(&s->timer);
759 + if (s->workqueue) {
760 + free_irq(s->port.irq, s);
761 + cancel_work_sync(&s->work);
762 + destroy_workqueue(s->workqueue);
763 + s->workqueue = NULL;
764 + }
756 765 kfree(max3100s[i]);
757 766 max3100s[i] = NULL;
758 767 break;
modified drivers/tty/serial/mpc52xx_uart.c
@@ -634,6 +634,9 @@ static void __exit mpc512x_psc_fifoc_uninit(void)
634 634 }
635 635 }
636 636
637 + static struct clk *psc_mclk_clk[MPC52xx_PSC_MAXNUM];
638 + static struct clk *psc_ipg_clk[MPC52xx_PSC_MAXNUM];
639 +
637 640 /* 512x specific interrupt handler. The caller holds the port lock */
638 641 static irqreturn_t mpc512x_psc_handle_irq(struct uart_port *port)
639 642 {
@@ -654,9 +657,6 @@ static irqreturn_t mpc512x_psc_handle_irq(struct uart_port *port)
654 657 return IRQ_NONE;
655 658 }
656 659
657 - static struct clk *psc_mclk_clk[MPC52xx_PSC_MAXNUM];
658 - static struct clk *psc_ipg_clk[MPC52xx_PSC_MAXNUM];
659 -
660 660 /* called from within the .request_port() callback (allocation) */
661 661 static int mpc512x_psc_alloc_clock(struct uart_port *port)
662 662 {
modified drivers/tty/serial/qcom_geni_serial.c
@@ -171,7 +171,6 @@ static void qcom_geni_serial_cancel_tx_cmd(struct uart_port *uport);
171 171 static int qcom_geni_serial_port_setup(struct uart_port *uport);
172 172 static void qcom_geni_serial_start_tx_fifo(struct uart_port *uport);
173 173 static void qcom_geni_serial_resume_tx(struct uart_port *uport);
174 - static void qcom_geni_serial_poll_rx_fifo_locked(struct uart_port *uport);
175 174
176 175 static inline struct qcom_geni_serial_port *to_dev_port(struct uart_port *uport)
177 176 {
@@ -467,6 +466,102 @@ static int qcom_geni_serial_poll_init(struct uart_port *uport)
467 466 #endif
468 467
469 468 #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
469 + static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
470 + {
471 + u32 i;
472 + unsigned char buf[sizeof(u32)];
473 + struct tty_port *tport;
474 + struct qcom_geni_serial_port *port = to_dev_port(uport);
475 +
476 + tport = &uport->state->port;
477 + for (i = 0; i < bytes; ) {
478 + int c;
479 + int chunk = min_t(int, bytes - i, BYTES_PER_FIFO_WORD);
480 +
481 + ioread32_rep(uport->membase + SE_GENI_RX_FIFOn, buf, 1);
482 + i += chunk;
483 + if (drop)
484 + continue;
485 +
486 + for (c = 0; c < chunk; c++) {
487 + int sysrq;
488 +
489 + uport->icount.rx++;
490 + if (port->brk && buf[c] == 0) {
491 + port->brk = false;
492 + if (uart_handle_break(uport))
493 + continue;
494 + }
495 +
496 + sysrq = uart_prepare_sysrq_char(uport, buf[c]);
497 +
498 + if (!sysrq)
499 + tty_insert_flip_char(tport, buf[c], TTY_NORMAL);
500 + }
501 + }
502 + if (!drop)
503 + tty_flip_buffer_push(tport);
504 + }
505 + #else
506 + static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
507 + {
508 +
509 + }
510 + #endif
511 +
512 + static void qcom_geni_serial_handle_rx_fifo(struct uart_port *uport, bool drop)
513 + {
514 + u32 status;
515 + u32 word_cnt;
516 + u32 last_word_byte_cnt;
517 + u32 last_word_partial;
518 + u32 total_bytes;
519 +
520 + status = readl(uport->membase + SE_GENI_RX_FIFO_STATUS);
521 + word_cnt = status & RX_FIFO_WC_MSK;
522 + last_word_partial = status & RX_LAST;
523 + last_word_byte_cnt = (status & RX_LAST_BYTE_VALID_MSK) >>
524 + RX_LAST_BYTE_VALID_SHFT;
525 +
526 + if (!word_cnt)
527 + return;
528 + total_bytes = BYTES_PER_FIFO_WORD * (word_cnt - 1);
529 + if (last_word_partial && last_word_byte_cnt)
530 + total_bytes += last_word_byte_cnt;
531 + else
532 + total_bytes += BYTES_PER_FIFO_WORD;
533 + handle_rx_console(uport, total_bytes, drop);
534 + }
535 +
536 + #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
537 + /* Caller holds the UART port lock. */
538 + static void qcom_geni_serial_poll_rx_fifo_locked(struct uart_port *uport)
539 + {
540 + struct qcom_geni_serial_port *port = to_dev_port(uport);
541 + struct tty_port *tport = &uport->state->port;
542 + u32 s_irq_status;
543 + bool drop_rx = false;
544 +
545 + s_irq_status = readl(uport->membase + SE_GENI_S_IRQ_STATUS);
546 + writel(s_irq_status, uport->membase + SE_GENI_S_IRQ_CLEAR);
547 +
548 + if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
549 + uport->icount.overrun++;
550 + tty_insert_flip_char(tport, 0, TTY_OVERRUN);
551 + }
552 +
553 + if (s_irq_status & (S_GP_IRQ_0_EN | S_GP_IRQ_1_EN)) {
554 + if (s_irq_status & S_GP_IRQ_0_EN)
555 + uport->icount.parity++;
556 + drop_rx = true;
557 + } else if (s_irq_status & (S_GP_IRQ_2_EN | S_GP_IRQ_3_EN)) {
558 + uport->icount.brk++;
559 + port->brk = true;
560 + }
561 +
562 + qcom_geni_serial_handle_rx_fifo(uport, drop_rx);
563 + }
564 +
470 565 static void qcom_geni_serial_drain_fifo(struct uart_port *uport)
471 566 {
472 567 struct qcom_geni_serial_port *port = to_dev_port(uport);
@@ -676,47 +771,6 @@ static void qcom_geni_serial_console_device_unlock(struct console *co,
676 771 #endif
677 772 }
678 773
679 - static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
680 - {
681 - u32 i;
682 - unsigned char buf[sizeof(u32)];
683 - struct tty_port *tport;
684 - struct qcom_geni_serial_port *port = to_dev_port(uport);
685 -
686 - tport = &uport->state->port;
687 - for (i = 0; i < bytes; ) {
688 - int c;
689 - int chunk = min_t(int, bytes - i, BYTES_PER_FIFO_WORD);
690 -
691 - ioread32_rep(uport->membase + SE_GENI_RX_FIFOn, buf, 1);
692 - i += chunk;
693 - if (drop)
694 - continue;
695 -
696 - for (c = 0; c < chunk; c++) {
697 - int sysrq;
698 -
699 - uport->icount.rx++;
700 - if (port->brk && buf[c] == 0) {
701 - port->brk = false;
702 - if (uart_handle_break(uport))
703 - continue;
704 - }
705 -
706 - sysrq = uart_prepare_sysrq_char(uport, buf[c]);
707 -
708 - if (!sysrq)
709 - tty_insert_flip_char(tport, buf[c], TTY_NORMAL);
710 - }
711 - }
712 - if (!drop)
713 - tty_flip_buffer_push(tport);
714 - }
715 - #else
716 - static void handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
717 - {
718 -
719 - }
720 774 #endif /* CONFIG_SERIAL_QCOM_GENI_CONSOLE */
721 775
722 776 static void handle_rx_uart(struct uart_port *uport, u32 bytes)
@@ -890,58 +944,6 @@ static void qcom_geni_serial_cancel_tx_cmd(struct uart_port *uport)
890 944 port->tx_queued = 0;
891 945 }
892 946
893 - static void qcom_geni_serial_handle_rx_fifo(struct uart_port *uport, bool drop)
894 - {
895 - u32 status;
896 - u32 word_cnt;
897 - u32 last_word_byte_cnt;
898 - u32 last_word_partial;
899 - u32 total_bytes;
900 -
901 - status = readl(uport->membase + SE_GENI_RX_FIFO_STATUS);
902 - word_cnt = status & RX_FIFO_WC_MSK;
903 - last_word_partial = status & RX_LAST;
904 - last_word_byte_cnt = (status & RX_LAST_BYTE_VALID_MSK) >>
905 - RX_LAST_BYTE_VALID_SHFT;
906 -
907 - if (!word_cnt)
908 - return;
909 - total_bytes = BYTES_PER_FIFO_WORD * (word_cnt - 1);
910 - if (last_word_partial && last_word_byte_cnt)
911 - total_bytes += last_word_byte_cnt;
912 - else
913 - total_bytes += BYTES_PER_FIFO_WORD;
914 - handle_rx_console(uport, total_bytes, drop);
915 - }
916 -
917 - /* Caller holds the UART port lock. */
918 - static void qcom_geni_serial_poll_rx_fifo_locked(struct uart_port *uport)
919 - {
920 - struct qcom_geni_serial_port *port = to_dev_port(uport);
921 - struct tty_port *tport = &uport->state->port;
922 - u32 s_irq_status;
923 - bool drop_rx = false;
924 -
925 - s_irq_status = readl(uport->membase + SE_GENI_S_IRQ_STATUS);
926 - writel(s_irq_status, uport->membase + SE_GENI_S_IRQ_CLEAR);
927 -
928 - if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
929 - uport->icount.overrun++;
930 - tty_insert_flip_char(tport, 0, TTY_OVERRUN);
931 - }
932 -
933 - if (s_irq_status & (S_GP_IRQ_0_EN | S_GP_IRQ_1_EN)) {
934 - if (s_irq_status & S_GP_IRQ_0_EN)
935 - uport->icount.parity++;
936 - drop_rx = true;
937 - } else if (s_irq_status & (S_GP_IRQ_2_EN | S_GP_IRQ_3_EN)) {
938 - uport->icount.brk++;
939 - port->brk = true;
940 - }
941 -
942 - qcom_geni_serial_handle_rx_fifo(uport, drop_rx);
943 - }
944 -
945 947 static void qcom_geni_serial_stop_rx_fifo(struct uart_port *uport)
946 948 {
947 949 u32 irq_en;
@@ -1482,9 +1484,8 @@ static int geni_serial_set_rate(struct geni_se *se, unsigned long baud)
1482 1484 * Bump up BW vote on CPU and CORE path as driver supports FIFO mode
1483 1485 * only.
1484 1486 */
1485 - avg_bw_core = (baud > 115200) ? Bps_to_icc(CORE_2X_50_MHZ)
1486 - : GENI_DEFAULT_BW;
1487 - port->se.icc_paths[GENI_TO_CORE].avg_bw = avg_bw_core;
1487 + avg_bw_core = baud > 115200 ? CORE_2X_50_MHZ : CORE_2X_19_2_MHZ;
1488 + port->se.icc_paths[GENI_TO_CORE].avg_bw = Bps_to_icc(avg_bw_core);
1488 1489 port->se.icc_paths[CPU_TO_GENI].avg_bw = Bps_to_icc(baud);
1489 1490 geni_icc_set_bw(&port->se);
1490 1491
@@ -1625,16 +1626,37 @@ static int qcom_geni_console_setup(struct console *co, char *options)
1625 1626 if (unlikely(!uport->membase))
1626 1627 return -ENXIO;
1627 1628
1629 + ret = pm_runtime_resume_and_get(uport->dev);
1630 + if (ret < 0)
1631 + return ret;
1632 +
1628 1633 if (!port->setup) {
1629 1634 ret = qcom_geni_serial_port_setup(uport);
1630 - if (ret)
1635 + if (ret) {
1636 + pm_runtime_put_sync(uport->dev);
1631 1637 return ret;
1638 + }
1632 1639 }
1633 1640
1634 1641 if (options)
1635 1642 uart_parse_options(options, &baud, &parity, &bits, &flow);
1636 1643
1637 - return uart_set_options(uport, co, baud, parity, bits, flow);
1644 + ret = uart_set_options(uport, co, baud, parity, bits, flow);
1645 + if (ret)
1646 + pm_runtime_put_sync(uport->dev);
1647 +
1648 + return ret;
1649 + }
1650 +
1651 + static int qcom_geni_console_exit(struct console *co)
1652 + {
1653 + struct qcom_geni_serial_port *port;
1654 +
1655 + port = get_port_from_line(co->index, true, NULL);
1656 + if (IS_ERR(port))
1657 + return PTR_ERR(port);
1658 +
1659 + return pm_runtime_put_sync(port->uport.dev);
1638 1660 }
1639 1661
1640 1662 static void qcom_geni_serial_earlycon_write(struct console *con,
@@ -1751,6 +1773,7 @@ static struct console cons_ops = {
1751 1773 .device_unlock = qcom_geni_serial_console_device_unlock,
1752 1774 .device = uart_console_device,
1753 1775 .setup = qcom_geni_console_setup,
1776 + .exit = qcom_geni_console_exit,
1754 1777 .flags = CON_PRINTBUFFER | CON_NBCON,
1755 1778 .index = -1,
1756 1779 .data = &qcom_geni_console_driver,
@@ -2099,9 +2122,11 @@ static int qcom_geni_serial_resume(struct device *dev)
2099 2122 struct uart_port *uport = &port->uport;
2100 2123 struct qcom_geni_private_data *private_data = uport->private_data;
2101 2124
2102 - ret = pm_runtime_force_resume(dev);
2103 - if (ret)
2104 - return ret;
2125 + if (console_suspend_enabled || !uart_console(uport)) {
2126 + ret = pm_runtime_force_resume(dev);
2127 + if (ret)
2128 + return ret;
2129 + }
2105 2130
2106 2131 ret = uart_resume_port(private_data->drv, uport);
2107 2132 if (uart_console(uport)) {
modified drivers/tty/serial/sc16is7xx.c
@@ -216,6 +216,8 @@
216 216 #define SC16IS7XX_TLR_TX_TRIGGER(words) ((((words) / 4) & 0x0f) << 0)
217 217 #define SC16IS7XX_TLR_RX_TRIGGER(words) ((((words) / 4) & 0x0f) << 4)
218 218
219 + #define SC16IS7XX_TX_TRIGGER_LEVEL 32
220 +
219 221 /* IOControl register bits (Only 75x/76x) */
220 222 #define SC16IS7XX_IOCONTROL_LATCH_BIT BIT(0) /* Enable input latching */
221 223 #define SC16IS7XX_IOCONTROL_MODEM_A_BIT BIT(1) /* Enable GPIO[7:4] as modem A pins */
@@ -647,12 +649,26 @@ static void sc16is7xx_handle_rx(struct uart_port *port, unsigned int rxlen,
647 649 tty_flip_buffer_push(&port->state->port);
648 650 }
649 651
652 + static unsigned int sc16is7xx_txlvl(struct uart_port *port)
653 + {
654 + unsigned int txlvl;
655 +
656 + txlvl = sc16is7xx_port_read(port, SC16IS7XX_TXLVL_REG);
657 + if (txlvl > SC16IS7XX_FIFO_SIZE) {
658 + dev_err_ratelimited(port->dev,
659 + "chip reports %u free bytes in TX FIFO, but it only has %u\n",
660 + txlvl, SC16IS7XX_FIFO_SIZE);
661 + return 0;
662 + }
663 +
664 + return txlvl;
665 + }
666 +
650 667 static void sc16is7xx_handle_tx(struct uart_port *port)
651 668 {
652 669 struct tty_port *tport = &port->state->port;
653 670 unsigned long flags;
654 671 unsigned int txlen;
655 - unsigned char *tail;
656 672
657 673 if (unlikely(port->x_char)) {
658 674 sc16is7xx_port_write(port, SC16IS7XX_THR_REG, port->x_char);
@@ -669,17 +685,28 @@ static void sc16is7xx_handle_tx(struct uart_port *port)
669 685 }
670 686
671 687 /* Limit to space available in TX FIFO */
672 - txlen = sc16is7xx_port_read(port, SC16IS7XX_TXLVL_REG);
673 - if (txlen > SC16IS7XX_FIFO_SIZE) {
674 - dev_err_ratelimited(port->dev,
675 - "chip reports %d free bytes in TX fifo, but it only has %d",
676 - txlen, SC16IS7XX_FIFO_SIZE);
677 - txlen = 0;
678 - }
688 + txlen = sc16is7xx_txlvl(port);
689 +
690 + /* Handle circular buffer wrap-around by sending multiple segments */
691 + while (txlen > 0 && !kfifo_is_empty(&tport->xmit_fifo)) {
692 + unsigned char *tail;
693 + unsigned int to_send;
694 +
695 + to_send = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen);
696 + if (!to_send)
697 + break;
679 698
680 - txlen = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen);
681 - sc16is7xx_fifo_write(port, tail, txlen);
682 - uart_xmit_advance(port, txlen);
699 + sc16is7xx_fifo_write(port, tail, to_send);
700 + uart_xmit_advance(port, to_send);
701 +
702 + if (kfifo_is_empty(&tport->xmit_fifo))
703 + break;
704 +
705 + /* Refill below the trigger to enable the next THRI crossing. */
706 + txlen = sc16is7xx_txlvl(port);
707 + if (txlen < SC16IS7XX_TX_TRIGGER_LEVEL)
708 + break;
709 + }
683 710
684 711 uart_port_lock_irqsave(port, &flags);
685 712 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
@@ -1130,6 +1157,10 @@ static int sc16is7xx_startup(struct uart_port *port)
1130 1157 SC16IS7XX_TCR_RX_RESUME(24) |
1131 1158 SC16IS7XX_TCR_RX_HALT(48));
1132 1159
1160 + /* Sync hardware and software TX trigger levels */
1161 + sc16is7xx_port_write(port, SC16IS7XX_TLR_REG,
1162 + SC16IS7XX_TLR_TX_TRIGGER(SC16IS7XX_TX_TRIGGER_LEVEL));
1163 +
1133 1164 /* Disable TCR/TLR access */
1134 1165 sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, SC16IS7XX_MCR_TCRTLR_BIT, 0);
1135 1166
modified drivers/tty/serial/serial-tegra.c
@@ -306,11 +306,19 @@ static void tegra_uart_fifo_reset(struct tegra_uart_port *tup, u8 fcr_bits)
306 306 {
307 307 unsigned long fcr = tup->fcr_shadow;
308 308 unsigned int lsr, tmout = 10000;
309 + bool clear_tx = !!(fcr_bits & UART_FCR_CLEAR_XMIT);
309 310
310 311 if (tup->rts_active)
311 312 set_rts(tup, false);
312 313
313 - if (tup->cdata->allow_txfifo_reset_fifo_mode) {
314 + /*
315 + * Leaving FIFO mode below is a workaround for a Tegra30
316 + * restriction on clearing the Tx FIFO while FIFO mode is
317 + * enabled. It empties both FIFOs, so applying it to an
318 + * Rx-only reset would destroy an in-flight transmission.
319 + * Only take that path when the caller asked for CLEAR_XMIT.
320 + */
321 + if (tup->cdata->allow_txfifo_reset_fifo_mode || !clear_tx) {
314 322 fcr |= fcr_bits & (UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
315 323 tegra_uart_write(tup, fcr, UART_FCR);
316 324 } else {
@@ -335,9 +343,15 @@ static void tegra_uart_fifo_reset(struct tegra_uart_port *tup, u8 fcr_bits)
335 343 */
336 344 tegra_uart_wait_cycle_time(tup, 32);
337 345
346 + /*
347 + * Only wait for the transmitter to drain when the Tx FIFO was
348 + * part of the reset. For an Rx-only reset it is left intact,
349 + * and waiting for TEMT here would spin for a full frame time.
350 + */
338 351 do {
339 352 lsr = tegra_uart_read(tup, UART_LSR);
340 - if ((lsr & UART_LSR_TEMT) && !(lsr & UART_LSR_DR))
353 + if ((!clear_tx || (lsr & UART_LSR_TEMT)) &&
354 + !(lsr & UART_LSR_DR))
341 355 break;
342 356 udelay(1);
343 357 } while (--tmout);
modified drivers/tty/serial/serial_core.c
@@ -896,7 +896,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
896 896 upf_t old_flags, new_flags;
897 897 int retval;
898 898
899 - if (!uport)
899 + if (!uport || tty_io_error(tty))
900 900 return -EIO;
901 901
902 902 new_port = new_info->port;
@@ -1119,7 +1119,7 @@ static int uart_break_ctl(struct tty_struct *tty, int break_state)
1119 1119 guard(mutex)(&port->mutex);
1120 1120
1121 1121 uport = uart_port_check(state);
1122 - if (!uport)
1122 + if (!uport || tty_io_error(tty))
1123 1123 return -EIO;
1124 1124
1125 1125 if (uport->type != PORT_UNKNOWN && uport->ops->break_ctl)
@@ -1144,7 +1144,7 @@ static int uart_do_autoconfig(struct tty_struct *tty, struct uart_state *state)
1144 1144 */
1145 1145 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &port->mutex) {
1146 1146 uport = uart_port_check(state);
1147 - if (!uport)
1147 + if (!uport || tty_io_error(tty))
1148 1148 return -EIO;
1149 1149
1150 1150 if (tty_port_users(port) != 1)
@@ -1199,7 +1199,7 @@ static void uart_enable_ms(struct uart_port *uport)
1199 1199 * FIXME: This wants extracting into a common all driver implementation
1200 1200 * of TIOCMWAIT using tty_port.
1201 1201 */
1202 - static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1202 + static int uart_wait_modem_status(struct tty_struct *tty, struct uart_state *state, unsigned long arg)
1203 1203 {
1204 1204 struct uart_port *uport;
1205 1205 struct tty_port *port = &state->port;
@@ -1213,18 +1213,29 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1213 1213 uport = uart_port_ref(state);
1214 1214 if (!uport)
1215 1215 return -EIO;
1216 - scoped_guard(uart_port_lock_irq, uport) {
1217 - memcpy(&cprev, &uport->icount, sizeof(struct uart_icount));
1218 - uart_enable_ms(uport);
1216 +
1217 + mutex_lock(&port->mutex);
1218 + if (tty_io_error(tty)) {
1219 + mutex_unlock(&port->mutex);
1220 + ret = -EIO;
1221 + goto out_deref;
1219 1222 }
1220 1223
1224 + uart_port_lock_irq(uport);
1225 + memcpy(&cprev, &uport->icount, sizeof(struct uart_icount));
1226 + uart_enable_ms(uport);
1227 + uart_port_unlock_irq(uport);
1228 +
1229 + mutex_unlock(&port->mutex);
1230 +
1221 1231 add_wait_queue(&port->delta_msr_wait, &wait);
1222 1232 for (;;) {
1223 - scoped_guard(uart_port_lock_irq, uport)
1224 - memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
1225 -
1226 1233 set_current_state(TASK_INTERRUPTIBLE);
1227 1234
1235 + uart_port_lock_irq(uport);
1236 + memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
1237 + uart_port_unlock_irq(uport);
1238 +
1228 1239 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1229 1240 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1230 1241 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
@@ -1233,6 +1244,11 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1233 1244 break;
1234 1245 }
1235 1246
1247 + if (tty_io_error(tty)) {
1248 + ret = -EIO;
1249 + break;
1250 + }
1251 +
1236 1252 schedule();
1237 1253
1238 1254 /* see if a signal did it */
@@ -1245,6 +1261,7 @@ static int uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1245 1261 }
1246 1262 __set_current_state(TASK_RUNNING);
1247 1263 remove_wait_queue(&port->delta_msr_wait, &wait);
1264 + out_deref:
1248 1265 uart_port_deref(uport);
1249 1266
1250 1267 return ret;
@@ -1567,7 +1584,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
1567 1584
1568 1585 /* This should only be used when the hardware is present. */
1569 1586 if (cmd == TIOCMIWAIT)
1570 - return uart_wait_modem_status(state, arg);
1587 + return uart_wait_modem_status(tty, state, arg);
1571 1588
1572 1589 /* rs485_config requires more locking than others */
1573 1590 if (cmd == TIOCSRS485)
@@ -1623,14 +1640,13 @@ static void uart_set_ldisc(struct tty_struct *tty)
1623 1640 {
1624 1641 struct uart_state *state = tty->driver_data;
1625 1642 struct uart_port *uport;
1626 - struct tty_port *port = &state->port;
1627 -
1628 - if (!tty_port_initialized(port))
1629 - return;
1630 1643
1631 1644 guard(mutex)(&state->port.mutex);
1632 1645 uport = uart_port_check(state);
1633 - if (uport && uport->ops->set_ldisc)
1646 + if (!uport || tty_io_error(tty))
1647 + return;
1648 +
1649 + if (uport->ops->set_ldisc)
1634 1650 uport->ops->set_ldisc(uport, &tty->termios);
1635 1651 }
1636 1652
@@ -1646,7 +1662,7 @@ static void uart_set_termios(struct tty_struct *tty,
1646 1662 guard(mutex)(&state->port.mutex);
1647 1663
1648 1664 uport = uart_port_check(state);
1649 - if (!uport)
1665 + if (!uport || tty_io_error(tty))
1650 1666 return;
1651 1667
1652 1668 /*
@@ -1798,7 +1814,14 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1798 1814 * 'timeout' / 'expire' give us the maximum amount of time
1799 1815 * we wait.
1800 1816 */
1801 - while (!port->ops->tx_empty(port)) {
1817 + for (;;) {
1818 + mutex_lock(&state->port.mutex);
1819 + if (tty_io_error(tty) || port->ops->tx_empty(port)) {
1820 + mutex_unlock(&state->port.mutex);
1821 + break;
1822 + }
1823 + mutex_unlock(&state->port.mutex);
1824 +
1802 1825 msleep_interruptible(jiffies_to_msecs(char_time));
1803 1826 if (signal_pending(current))
1804 1827 break;
@@ -3358,6 +3381,7 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
3358 3381
3359 3382 err_unregister_port_dev:
3360 3383 serial_base_port_device_remove(port->port_dev);
3384 + port->port_dev = NULL;
3361 3385
3362 3386 err_unregister_ctrl_dev:
3363 3387 serial_base_ctrl_device_remove(new_ctrl_dev);
@@ -3372,12 +3396,24 @@ err_unregister_ctrl_dev:
3372 3396 void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port)
3373 3397 {
3374 3398 struct device *phys_dev = port->dev;
3375 - struct serial_port_device *port_dev = port->port_dev;
3376 - struct serial_ctrl_device *ctrl_dev = serial_core_get_ctrl_dev(port_dev);
3399 + struct serial_port_device *port_dev;
3400 + struct serial_ctrl_device *ctrl_dev;
3377 3401 int ctrl_id = port->ctrl_id;
3378 3402
3379 3403 guard(mutex)(&port_mutex);
3380 3404
3405 + /*
3406 + * A NULL port device means there is no registered port device to
3407 + * remove: serial_core_remove_one_port() clears port_dev on
3408 + * teardown, and it is never set if registration failed before
3409 + * serial_core_port_device_add().
3410 + */
3411 + port_dev = port->port_dev;
3412 + if (!port_dev)
3413 + return;
3414 +
3415 + ctrl_dev = serial_core_get_ctrl_dev(port_dev);
3416 +
3381 3417 port->flags |= UPF_DEAD;
3382 3418
3383 3419 serial_core_remove_one_port(drv, port);
modified drivers/tty/serial/vt8500_serial.c
@@ -656,6 +656,7 @@ static int vt8500_serial_probe(struct platform_device *pdev)
656 656 ret = clk_prepare_enable(vt8500_port->clk);
657 657 if (ret) {
658 658 dev_err(&pdev->dev, "failed to enable clock\n");
659 + clk_put(vt8500_port->clk);
659 660 return ret;
660 661 }
661 662
modified drivers/tty/tty_io.c
@@ -620,6 +620,8 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
620 620
621 621 tty_ldisc_hangup(tty, cons_filp != NULL);
622 622
623 + wake_up_interruptible(&tty->break_wait);
624 +
623 625 spin_lock_irq(&tty->ctrl.lock);
624 626 clear_bit(TTY_THROTTLED, &tty->flags);
625 627 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
@@ -2431,6 +2433,7 @@ static int tiocgetd(struct tty_struct *tty, int __user *p)
2431 2433 * send_break - performed time break
2432 2434 * @tty: device to break on
2433 2435 * @duration: timeout in mS
2436 + * @file: file object
2434 2437 *
2435 2438 * Perform a timed break on hardware that lacks its own driver level timed
2436 2439 * break functionality.
@@ -2438,8 +2441,9 @@ static int tiocgetd(struct tty_struct *tty, int __user *p)
2438 2441 * Locking:
2439 2442 * @tty->atomic_write_lock serializes
2440 2443 */
2441 - static int send_break(struct tty_struct *tty, unsigned int duration)
2444 + static int send_break(struct file *file, struct tty_struct *tty, unsigned int duration)
2442 2445 {
2446 + long timeout;
2443 2447 int retval;
2444 2448
2445 2449 if (tty->ops->break_ctl == NULL)
@@ -2453,13 +2457,26 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
2453 2457 return -EINTR;
2454 2458
2455 2459 retval = tty->ops->break_ctl(tty, -1);
2456 - if (!retval) {
2457 - msleep_interruptible(duration);
2458 - retval = tty->ops->break_ctl(tty, 0);
2459 - } else if (retval == -EOPNOTSUPP) {
2460 - /* some drivers can tell only dynamically */
2461 - retval = 0;
2460 + if (retval) {
2461 + if (retval == -EOPNOTSUPP) {
2462 + /* some drivers can tell only dynamically */
2463 + retval = 0;
2464 + }
2465 + goto out_unlock;
2466 + }
2467 +
2468 + timeout = msecs_to_jiffies(duration);
2469 + timeout = wait_event_interruptible_timeout(tty->break_wait,
2470 + tty_hung_up_p(file),
2471 + timeout);
2472 + /* return early on hangup only */
2473 + if (timeout > 0) {
2474 + retval = -EIO;
2475 + goto out_unlock;
2462 2476 }
2477 +
2478 + retval = tty->ops->break_ctl(tty, 0);
2479 + out_unlock:
2463 2480 tty_write_unlock(tty);
2464 2481
2465 2482 if (signal_pending(current))
@@ -2727,10 +2744,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2727 2744 * This is used by the tcdrain() termios function.
2728 2745 */
2729 2746 if (!arg)
2730 - return send_break(tty, 250);
2747 + return send_break(file, tty, 250);
2731 2748 return 0;
2732 2749 case TCSBRKP: /* support for POSIX tcsendbreak() */
2733 - return send_break(tty, arg ? arg*100 : 250);
2750 + return send_break(file, tty, arg ? arg * 100 : 250);
2734 2751
2735 2752 case TIOCMGET:
2736 2753 return tty_tiocmget(tty, p);
@@ -3090,6 +3107,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
3090 3107 init_ldsem(&tty->ldisc_sem);
3091 3108 init_waitqueue_head(&tty->write_wait);
3092 3109 init_waitqueue_head(&tty->read_wait);
3110 + init_waitqueue_head(&tty->break_wait);
3093 3111 INIT_WORK(&tty->hangup_work, do_tty_hangup);
3094 3112 mutex_init(&tty->atomic_write_lock);
3095 3113 spin_lock_init(&tty->ctrl.lock);
@@ -3238,14 +3256,16 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
3238 3256 goto err_put;
3239 3257
3240 3258 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
3241 - /*
3242 - * Free any saved termios data so that the termios state is
3243 - * reset when reusing a minor number.
3244 - */
3245 - tp = driver->termios[index];
3246 - if (tp) {
3247 - driver->termios[index] = NULL;
3248 - kfree(tp);
3259 + if (driver->flags & TTY_DRIVER_RESET_SAVED_TERMIOS) {
3260 + /*
3261 + * Free any saved termios data so that the termios
3262 + * state is reset when reusing a minor number.
3263 + */
3264 + tp = driver->termios[index];
3265 + if (tp) {
3266 + driver->termios[index] = NULL;
3267 + kfree(tp);
3268 + }
3249 3269 }
3250 3270
3251 3271 retval = tty_cdev_add(driver, devt, index, 1);
modified drivers/tty/tty_port.c
@@ -340,19 +340,9 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
340 340 }
341 341 EXPORT_SYMBOL(tty_port_tty_set);
342 342
343 - /**
344 - * tty_port_shutdown - internal helper to shutdown the device
345 - * @port: tty port to be shut down
346 - * @tty: the associated tty
347 - *
348 - * It is used by tty_port_hangup() and tty_port_close(). Its task is to
349 - * shutdown the device if it was initialized (note consoles remain
350 - * functioning). It lowers DTR/RTS (if @tty has HUPCL set) and invokes
351 - * @port->ops->shutdown().
352 - */
353 - static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
343 + static void tty_port_shutdown_locked(struct tty_port *port, struct tty_struct *tty)
354 344 {
355 - guard(mutex)(&port->mutex);
345 + lockdep_assert_held(&port->mutex);
356 346
357 347 if (port->console)
358 348 return;
@@ -372,6 +362,23 @@ static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
372 362 port->ops->shutdown(port);
373 363 }
374 364
365 + /**
366 + * tty_port_shutdown - internal helper to shutdown the device
367 + * @port: tty port to be shut down
368 + * @tty: the associated tty
369 + *
370 + * It is used by tty_port_hangup() and tty_port_close(). Its task is to
371 + * shutdown the device if it was initialized (note consoles remain
372 + * functioning). It lowers DTR/RTS (if @tty has HUPCL set) and invokes
373 + * @port->ops->shutdown().
374 + */
375 + static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
376 + {
377 + guard(mutex)(&port->mutex);
378 +
379 + tty_port_shutdown_locked(port, tty);
380 + }
381 +
375 382 /**
376 383 * tty_port_hangup - hangup helper
377 384 * @port: tty port
@@ -385,36 +392,58 @@ void tty_port_hangup(struct tty_port *port)
385 392 {
386 393 struct tty_struct *tty;
387 394
388 - scoped_guard(spinlock_irqsave, &port->lock) {
389 - port->count = 0;
390 - tty = port->tty;
391 - if (tty)
392 - set_bit(TTY_IO_ERROR, &tty->flags);
393 - port->tty = NULL;
394 - }
395 + scoped_guard(mutex, &port->mutex) {
396 + scoped_guard(spinlock_irqsave, &port->lock) {
397 + port->count = 0;
398 + tty = port->tty;
399 + if (tty)
400 + set_bit(TTY_IO_ERROR, &tty->flags);
401 + port->tty = NULL;
402 + }
395 403
396 - tty_port_set_active(port, false);
397 - tty_port_shutdown(port, tty);
404 + tty_port_set_active(port, false);
405 + tty_port_shutdown_locked(port, tty);
406 + }
398 407 tty_kref_put(tty);
399 408 wake_up_interruptible(&port->open_wait);
400 409 wake_up_interruptible(&port->delta_msr_wait);
401 410 }
402 411 EXPORT_SYMBOL(tty_port_hangup);
403 412
404 - void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async)
413 + /**
414 + * tty_port_tty_hangup - helper to hang up a tty asynchronously
415 + * @port: tty port
416 + * @check_clocal: hang only ttys with %CLOCAL unset?
417 + */
418 + void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
405 419 {
406 420 scoped_guard(tty_port_tty, port) {
407 421 struct tty_struct *tty = scoped_tty();
408 422
409 - if (!check_clocal || !C_CLOCAL(tty)) {
410 - if (async)
411 - tty_hangup(tty);
412 - else
413 - tty_vhangup(tty);
414 - }
423 + if (!check_clocal || !C_CLOCAL(tty))
424 + tty_hangup(tty);
425 + }
426 + }
427 + EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
428 +
429 + /**
430 + * tty_port_tty_vhangup - helper to hang up a tty synchronously
431 + * @port: tty port
432 + */
433 + void tty_port_tty_vhangup(struct tty_port *port)
434 + {
435 + struct tty_struct *tty;
436 +
437 + mutex_lock(&port->mutex);
438 + tty = tty_port_tty_get(port);
439 + mutex_unlock(&port->mutex);
440 +
441 + if (tty) {
442 + tty_vhangup(tty);
443 + tty_kref_put(tty);
415 444 }
416 445 }
417 - EXPORT_SYMBOL_GPL(__tty_port_tty_hangup);
446 + EXPORT_SYMBOL_GPL(tty_port_tty_vhangup);
418 447
419 448 /**
420 449 * tty_port_tty_wakeup - helper to wake up a tty
@@ -767,8 +796,10 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
767 796 clear_bit(TTY_IO_ERROR, &tty->flags);
768 797 if (port->ops->activate) {
769 798 int retval = port->ops->activate(port, tty);
770 - if (retval)
799 + if (retval) {
800 + set_bit(TTY_IO_ERROR, &tty->flags);
771 801 return retval;
802 + }
772 803 }
773 804 tty_port_set_initialized(port, true);
774 805 }
modified drivers/tty/vcc.c
@@ -492,7 +492,7 @@ static ssize_t domain_show(struct device *dev,
492 492
493 493 static int vcc_send_ctl(struct vcc_port *port, int ctl)
494 494 {
495 - struct vio_vcc pkt;
495 + struct vio_vcc pkt = {};
496 496 int rv;
497 497
498 498 pkt.tag.type = VIO_TYPE_CTRL;
@@ -986,7 +986,8 @@ static void vcc_cleanup(struct tty_struct *tty)
986 986
987 987 port = vcc_get(tty->index, true);
988 988 if (port) {
989 - port->tty = NULL;
989 + scoped_guard(spinlock_irqsave, &port->lock)
990 + port->tty = NULL;
990 991
991 992 if (port->removed) {
992 993 vcc_table_remove(tty->index);
modified drivers/tty/vt/selection.c
@@ -434,8 +434,8 @@ int paste_selection(struct tty_struct *tty)
434 434 bps = NULL;
435 435 }
436 436
437 - count = vc_sel.buf_len - pasted;
438 - if (count) {
437 + if (vc_sel.buf_len > pasted) {
438 + count = vc_sel.buf_len - pasted;
439 439 pasted += tty_ldisc_receive_buf(ld, vc_sel.buffer + pasted,
440 440 NULL, count);
441 441 if (vc_sel.buf_len > pasted)
modified drivers/tty/vt/vc_screen.c
@@ -631,6 +631,18 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
631 631 ret = copy_from_user(con_buf, buf, this_round);
632 632 console_lock();
633 633
634 + /* The vc might have been freed or vcs_size might have changed
635 + * while we slept to grab the user buffer; recheck here, before
636 + * if (ret), so every break path below passes a fresh vc to the
637 + * post-loop vcs_scr_updated(). Return data written so far.
638 + */
639 + vc = vcs_vc(inode, &viewed);
640 + if (!vc) {
641 + if (written)
642 + break;
643 + return -ENXIO;
644 + }
645 +
634 646 if (ret) {
635 647 this_round -= ret;
636 648 if (!this_round) {
@@ -642,17 +654,6 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
642 654 return -EFAULT;
643 655 }
644 656 }
645 -
646 - /* The vc might have been freed or vcs_size might have changed
647 - * while we slept to grab the user buffer, so recheck.
648 - * Return data written up to now on failure.
649 - */
650 - vc = vcs_vc(inode, &viewed);
651 - if (!vc) {
652 - if (written)
653 - break;
654 - return -ENXIO;
655 - }
656 657 size = vcs_size(vc, attr, false);
657 658 if (size < 0) {
658 659 if (written)
modified drivers/tty/vt/vt.c
@@ -1134,6 +1134,8 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
1134 1134 return 0;
1135 1135 err_free:
1136 1136 visual_deinit(vc);
1137 + if (*vc->uni_pagedict_loc)
1138 + con_free_unimap(vc);
1137 1139 kfree(vc);
1138 1140 vc_cons[currcons].d = NULL;
1139 1141 return err;
@@ -2860,7 +2862,8 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
2860 2862 csi_J(vc, CSI_J_VISIBLE);
2861 2863 vc->vc_video_erase_char =
2862 2864 (vc->vc_video_erase_char & 0xff00) | ' ';
2863 - do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
2865 + if (con_should_update(vc))
2866 + do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
2864 2867 }
2865 2868 return;
2866 2869 case ESsetG0: /* ESC ( */
modified drivers/usb/cdns3/cdns3-gadget.c
@@ -3269,6 +3269,10 @@ static void cdns3_gadget_exit(struct cdns *cdns)
3269 3269 usb_del_gadget(&priv_dev->gadget);
3270 3270 devm_free_irq(cdns->dev, cdns->dev_irq, priv_dev);
3271 3271
3272 + /* The works can still be queued until the IRQ is freed. */
3273 + cancel_work_sync(&priv_dev->pending_status_wq);
3274 + cancel_work_sync(&priv_dev->aligned_buf_wq);
3275 +
3272 3276 cdns3_free_all_eps(priv_dev);
3273 3277
3274 3278 while (!list_empty(&priv_dev->aligned_buf_list)) {
modified drivers/usb/cdns3/cdns3-pci-wrap.c
@@ -96,6 +96,11 @@ static int cdns3_pci_probe(struct pci_dev *pdev,
96 96
97 97 if (pci_is_enabled(func)) {
98 98 wrap = pci_get_drvdata(func);
99 + if (!wrap) {
100 + dev_err(&pdev->dev,
101 + "second function not initialized, retrying\n");
102 + return -EPROBE_DEFER;
103 + }
99 104 } else {
100 105 wrap = kzalloc_obj(*wrap);
101 106 if (!wrap)
modified drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -306,8 +306,10 @@ static int tegra_usb_probe(struct platform_device *pdev)
306 306
307 307 pm_runtime_enable(&pdev->dev);
308 308 err = pm_runtime_resume_and_get(&pdev->dev);
309 - if (err)
309 + if (err) {
310 + pm_runtime_disable(&pdev->dev);
310 311 return err;
312 + }
311 313
312 314 if (device_property_present(&pdev->dev, "nvidia,needs-double-reset"))
313 315 usb->needs_double_reset = true;
modified drivers/usb/class/cdc-acm.c
@@ -331,7 +331,6 @@ static void acm_process_notification(struct acm *acm, unsigned char *buf)
331 331
332 332 spin_lock_irqsave(&acm->read_lock, flags);
333 333 acm->ctrlin = newctrl;
334 - acm->oldcount = acm->iocount;
335 334
336 335 if (difference & USB_CDC_SERIAL_STATE_DSR)
337 336 acm->iocount.dsr++;
@@ -788,6 +787,9 @@ static void acm_port_shutdown(struct tty_port *port)
788 787 usb_autopm_put_interface_async(acm->control);
789 788 }
790 789
790 + if (acm->disconnected)
791 + return;
792 +
791 793 acm_unpoison_urbs(acm);
792 794
793 795 if (acm->quirks & ALWAYS_POLL_CTRL) {
@@ -1027,11 +1029,16 @@ static int wait_serial_change(struct acm *acm, unsigned long arg)
1027 1029 DECLARE_WAITQUEUE(wait, current);
1028 1030 struct async_icount old, new;
1029 1031
1030 - do {
1032 + spin_lock_irq(&acm->read_lock);
1033 + old = acm->iocount;
1034 + spin_unlock_irq(&acm->read_lock);
1035 +
1036 + add_wait_queue(&acm->wioctl, &wait);
1037 + for (;;) {
1038 + set_current_state(TASK_INTERRUPTIBLE);
1039 +
1031 1040 spin_lock_irq(&acm->read_lock);
1032 - old = acm->oldcount;
1033 1041 new = acm->iocount;
1034 - acm->oldcount = new;
1035 1042 spin_unlock_irq(&acm->read_lock);
1036 1043
1037 1044 if ((arg & TIOCM_DSR) &&
@@ -1044,22 +1051,20 @@ static int wait_serial_change(struct acm *acm, unsigned long arg)
1044 1051 old.rng != new.rng)
1045 1052 break;
1046 1053
1047 - add_wait_queue(&acm->wioctl, &wait);
1048 - set_current_state(TASK_INTERRUPTIBLE);
1049 - schedule();
1050 - remove_wait_queue(&acm->wioctl, &wait);
1051 1054 if (acm->disconnected) {
1052 - if (arg & TIOCM_CD)
1053 - break;
1054 - else
1055 - rv = -ENODEV;
1056 - } else {
1057 - if (signal_pending(current))
1058 - rv = -ERESTARTSYS;
1055 + rv = -ENODEV;
1056 + break;
1059 1057 }
1060 - } while (!rv);
1061 1058
1062 -
1059 + schedule();
1060 +
1061 + if (signal_pending(current)) {
1062 + rv = -ERESTARTSYS;
1063 + break;
1064 + }
1065 + }
1066 + __set_current_state(TASK_RUNNING);
1067 + remove_wait_queue(&acm->wioctl, &wait);
1063 1068
1064 1069 return rv;
1065 1070 }
@@ -2140,7 +2145,7 @@ static int __init acm_init(void)
2140 2145 {
2141 2146 int retval;
2142 2147 acm_tty_driver = tty_alloc_driver(ACM_TTY_MINORS, TTY_DRIVER_REAL_RAW |
2143 - TTY_DRIVER_DYNAMIC_DEV);
2148 + TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_RESET_SAVED_TERMIOS);
2144 2149 if (IS_ERR(acm_tty_driver))
2145 2150 return PTR_ERR(acm_tty_driver);
2146 2151 acm_tty_driver->driver_name = "acm",
modified drivers/usb/class/cdc-acm.h
@@ -90,7 +90,6 @@ struct acm {
90 90 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */
91 91 unsigned int ctrlout; /* output control lines (DTR, RTS) */
92 92 struct async_icount iocount; /* counters for control line changes */
93 - struct async_icount oldcount; /* for comparison of counter */
94 93 wait_queue_head_t wioctl; /* for ioctl */
95 94 unsigned int writesize; /* max packet size for the output bulk endpoint */
96 95 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */
modified drivers/usb/core/hub.c
@@ -73,8 +73,11 @@
73 73 /*
74 74 * Give SS hubs 200ms time after wake to train downstream links before
75 75 * assuming no port activity and allowing hub to runtime suspend back.
76 + * Root hubs have no upstream hub whose wake propagation needs to be
77 + * accounted for, so they need less time, use 120ms for them.
76 78 */
77 79 #define USB_SS_PORT_U0_WAKE_TIME 200 /* ms */
80 + #define USB_SS_RH_PORT_U0_WAKE_TIME 120 /* ms */
78 81
79 82 /* Protect struct usb_device->state and ->children members
80 83 * Note: Both are also protected by ->dev.sem, except that ->state can
@@ -1358,7 +1361,9 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1358 1361
1359 1362 queue_delayed_work(system_power_efficient_wq,
1360 1363 &hub->post_resume_work,
1361 - msecs_to_jiffies(USB_SS_PORT_U0_WAKE_TIME));
1364 + msecs_to_jiffies(hdev->parent ?
1365 + USB_SS_PORT_U0_WAKE_TIME :
1366 + USB_SS_RH_PORT_U0_WAKE_TIME));
1362 1367 return;
1363 1368 }
1364 1369
modified drivers/usb/core/message.c
@@ -1337,7 +1337,8 @@ static void remove_intf_ep_devs(struct usb_interface *intf)
1337 1337 *
1338 1338 * Disables the endpoint for URB submission and nukes all pending URBs.
1339 1339 * If @reset_hardware is set then also deallocates hcd/hardware state
1340 - * for the endpoint.
1340 + * for the endpoint (clearing both ep_in and ep_out pointers for
1341 + * bidirectional non-ep0 control endpoints).
1341 1342 */
1342 1343 void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
1343 1344 bool reset_hardware)
@@ -1358,6 +1359,11 @@ void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
1358 1359 dev->ep_in[epnum] = NULL;
1359 1360 }
1360 1361 if (ep) {
1362 + if (reset_hardware && epnum != 0 &&
1363 + usb_endpoint_xfer_control(&ep->desc)) {
1364 + dev->ep_out[epnum] = NULL;
1365 + dev->ep_in[epnum] = NULL;
1366 + }
1361 1367 ep->enabled = 0;
1362 1368 usb_hcd_flush_endpoint(dev, ep);
1363 1369 if (reset_hardware)
modified drivers/usb/dwc2/hcd.c
@@ -5082,14 +5082,13 @@ static void dwc2_hcd_free(struct dwc2_hsotg *hsotg)
5082 5082 }
5083 5083
5084 5084 cancel_work_sync(&hsotg->phy_reset_work);
5085 -
5086 - timer_delete(&hsotg->wkp_timer);
5087 5085 }
5088 5086
5089 5087 static void dwc2_hcd_release(struct dwc2_hsotg *hsotg)
5090 5088 {
5091 5089 /* Turn off all host-specific interrupts */
5092 5090 dwc2_disable_host_interrupts(hsotg);
5091 + timer_shutdown_sync(&hsotg->wkp_timer);
5093 5092
5094 5093 dwc2_hcd_free(hsotg);
5095 5094 }
modified drivers/usb/dwc3/core.h
@@ -49,6 +49,7 @@
49 49 #define DWC3_ENDPOINTS_NUM 32
50 50 #define DWC3_XHCI_RESOURCES_NUM 2
51 51 #define DWC3_ISOC_MAX_RETRIES 5
52 + #define DWC3_ERR_RECOVERY_MAX 3
52 53
53 54 #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */
54 55 #define DWC3_EVENT_BUFFERS_SIZE 4096
@@ -841,6 +842,12 @@ enum dwc3_link_state {
841 842 DWC3_LINK_STATE_MASK = 0x0f,
842 843 };
843 844
845 + enum dwc3_err_state {
846 + DWC3_ERR_NONE = 0,
847 + DWC3_ERR_RECOVERY,
848 + DWC3_ERR_UNRECOVERABLE,
849 + };
850 +
844 851 /* TRB Length, PCM and Status */
845 852 #define DWC3_TRB_SIZE_MASK (0x00ffffff)
846 853 #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
@@ -1004,6 +1011,7 @@ struct dwc3_glue_ops {
1004 1011 /**
1005 1012 * struct dwc3 - representation of our controller
1006 1013 * @drd_work: workqueue used for role swapping
1014 + * @err_recovery_work: workqueue used for controller error recovery
1007 1015 * @ep0_trb: trb which is used for the ctrl_req
1008 1016 * @bounce: address of bounce buffer
1009 1017 * @setup_buf: used while precessing STD USB requests
@@ -1013,6 +1021,7 @@ struct dwc3_glue_ops {
1013 1021 * @ep0_in_setup: one control transfer is completed and enter setup phase
1014 1022 * @lock: for synchronizing
1015 1023 * @mutex: for mode switching
1024 + * @connect_mutex: for the pull-up and err_recovery_work
1016 1025 * @dev: pointer to our struct device
1017 1026 * @sysdev: pointer to the DMA-capable device
1018 1027 * @xhci: pointer to our xHCI child
@@ -1079,6 +1088,9 @@ struct dwc3_glue_ops {
1079 1088 * @ep0_next_event: hold the next expected event
1080 1089 * @ep0state: state of endpoint zero
1081 1090 * @link_state: link state
1091 + * @err_state: current error recovery state.
1092 + * @err_recovery_count: number of consecutive error recovery attempts until
1093 + * confirmed healthy and reset to 0 on reset event.
1082 1094 * @speed: device speed (super, high, full, low)
1083 1095 * @hwparams: copy of hwparams registers
1084 1096 * @regset: debugfs pointer to regdump file
@@ -1189,6 +1201,7 @@ struct dwc3_glue_ops {
1189 1201 */
1190 1202 struct dwc3 {
1191 1203 struct work_struct drd_work;
1204 + struct work_struct err_recovery_work;
1192 1205 struct dwc3_trb *ep0_trb;
1193 1206 void *bounce;
1194 1207 u8 *setup_buf;
@@ -1203,6 +1216,9 @@ struct dwc3 {
1203 1216 /* mode switching lock */
1204 1217 struct mutex mutex;
1205 1218
1219 + /* serializes pull-up run/stop vs error recovery */
1220 + struct mutex connect_mutex;
1221 +
1206 1222 struct device *dev;
1207 1223 struct device *sysdev;
1208 1224
@@ -1332,6 +1348,9 @@ struct dwc3 {
1332 1348 enum dwc3_ep0_next ep0_next_event;
1333 1349 enum dwc3_ep0_state ep0state;
1334 1350 enum dwc3_link_state link_state;
1351 + enum dwc3_err_state err_state;
1352 +
1353 + u32 err_recovery_count;
1335 1354
1336 1355 u16 u2sel;
1337 1356 u16 u2pel;
modified drivers/usb/dwc3/dwc3-am62.c
@@ -299,6 +299,7 @@ static int dwc3_ti_probe(struct platform_device *pdev)
299 299
300 300 err_pm_disable:
301 301 clk_disable_unprepare(am62->usb2_refclk);
302 + pm_runtime_put_noidle(dev);
302 303 pm_runtime_disable(dev);
303 304 pm_runtime_set_suspended(dev);
304 305 return ret;
modified drivers/usb/dwc3/ep0.c
@@ -200,6 +200,11 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
200 200 int ret;
201 201
202 202 spin_lock_irqsave(&dwc->lock, flags);
203 + if (dwc->err_state != DWC3_ERR_NONE) {
204 + ret = -ESHUTDOWN;
205 + goto out;
206 + }
207 +
203 208 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) {
204 209 dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n",
205 210 dep->name);
@@ -271,6 +276,10 @@ int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
271 276 int ret;
272 277
273 278 spin_lock_irqsave(&dwc->lock, flags);
279 + if (dwc->err_state != DWC3_ERR_NONE) {
280 + spin_unlock_irqrestore(&dwc->lock, flags);
281 + return -ESHUTDOWN;
282 + }
274 283 ret = __dwc3_gadget_ep0_set_halt(ep, value);
275 284 spin_unlock_irqrestore(&dwc->lock, flags);
276 285
modified drivers/usb/dwc3/gadget.c
@@ -1149,6 +1149,10 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
1149 1149 return 0;
1150 1150
1151 1151 spin_lock_irqsave(&dwc->lock, flags);
1152 + if (dwc->err_state != DWC3_ERR_NONE) {
1153 + spin_unlock_irqrestore(&dwc->lock, flags);
1154 + return -ESHUTDOWN;
1155 + }
1152 1156 ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT);
1153 1157 spin_unlock_irqrestore(&dwc->lock, flags);
1154 1158
@@ -2060,6 +2064,10 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
2060 2064 int ret;
2061 2065
2062 2066 spin_lock_irqsave(&dwc->lock, flags);
2067 + if (dwc->err_state != DWC3_ERR_NONE) {
2068 + spin_unlock_irqrestore(&dwc->lock, flags);
2069 + return -ESHUTDOWN;
2070 + }
2063 2071 ret = __dwc3_gadget_ep_queue(dep, req);
2064 2072 spin_unlock_irqrestore(&dwc->lock, flags);
2065 2073
@@ -2292,6 +2300,10 @@ static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value)
2292 2300 int ret;
2293 2301
2294 2302 spin_lock_irqsave(&dwc->lock, flags);
2303 + if (dwc->err_state != DWC3_ERR_NONE) {
2304 + spin_unlock_irqrestore(&dwc->lock, flags);
2305 + return -ESHUTDOWN;
2306 + }
2295 2307 ret = __dwc3_gadget_ep_set_halt(dep, value, false);
2296 2308 spin_unlock_irqrestore(&dwc->lock, flags);
2297 2309
@@ -2306,6 +2318,10 @@ static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep)
2306 2318 int ret;
2307 2319
2308 2320 spin_lock_irqsave(&dwc->lock, flags);
2321 + if (dwc->err_state != DWC3_ERR_NONE) {
2322 + spin_unlock_irqrestore(&dwc->lock, flags);
2323 + return -ESHUTDOWN;
2324 + }
2309 2325 dep->flags |= DWC3_EP_WEDGE;
2310 2326
2311 2327 if (dep->number == 0 || dep->number == 1)
@@ -2437,6 +2453,10 @@ static int dwc3_gadget_wakeup(struct usb_gadget *g)
2437 2453 }
2438 2454
2439 2455 spin_lock_irqsave(&dwc->lock, flags);
2456 + if (dwc->err_state != DWC3_ERR_NONE) {
2457 + spin_unlock_irqrestore(&dwc->lock, flags);
2458 + return -ESHUTDOWN;
2459 + }
2440 2460 if (!dwc->gadget->wakeup_armed) {
2441 2461 dev_err(dwc->dev, "not armed for remote wakeup\n");
2442 2462 spin_unlock_irqrestore(&dwc->lock, flags);
@@ -2464,6 +2484,10 @@ static int dwc3_gadget_func_wakeup(struct usb_gadget *g, int intf_id)
2464 2484 }
2465 2485
2466 2486 spin_lock_irqsave(&dwc->lock, flags);
2487 + if (dwc->err_state != DWC3_ERR_NONE) {
2488 + spin_unlock_irqrestore(&dwc->lock, flags);
2489 + return -ESHUTDOWN;
2490 + }
2467 2491 /*
2468 2492 * If the link is in U3, signal for remote wakeup and wait for the
2469 2493 * link to transition to U0 before sending device notification.
@@ -2833,10 +2857,13 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
2833 2857
2834 2858 synchronize_irq(dwc->irq_gadget);
2835 2859
2860 + /* Serialize against dwc3_err_recovery_work() */
2861 + mutex_lock(&dwc->connect_mutex);
2836 2862 if (!is_on)
2837 2863 ret = dwc3_gadget_soft_disconnect(dwc);
2838 2864 else
2839 2865 ret = dwc3_gadget_soft_connect(dwc);
2866 + mutex_unlock(&dwc->connect_mutex);
2840 2867
2841 2868 pm_runtime_put(dwc->dev);
2842 2869
@@ -4153,6 +4180,10 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
4153 4180
4154 4181 dwc->suspended = false;
4155 4182
4183 + /* The controller is recovered. */
4184 + if (dwc->err_state == DWC3_ERR_NONE)
4185 + dwc->err_recovery_count = 0;
4186 +
4156 4187 /*
4157 4188 * Ideally, dwc3_reset_gadget() would trigger the function
4158 4189 * drivers to stop any active transfers through ep disable.
@@ -4640,6 +4671,12 @@ static irqreturn_t dwc3_thread_interrupt(int irq, void *_evt)
4640 4671 return ret;
4641 4672 }
4642 4673
4674 + static void dwc3_schedule_err_recovery(struct dwc3 *dwc)
4675 + {
4676 + dwc->err_state = DWC3_ERR_RECOVERY;
4677 + schedule_work(&dwc->err_recovery_work);
4678 + }
4679 +
4643 4680 static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)
4644 4681 {
4645 4682 struct dwc3 *dwc = evt->dwc;
@@ -4673,9 +4710,21 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt)
4673 4710 return IRQ_NONE;
4674 4711
4675 4712 if (count > evt->length) {
4676 - dev_err_ratelimited(dwc->dev, "invalid count(%u) > evt->length(%u)\n",
4713 + dev_err(dwc->dev, "invalid count(%u) > evt->length(%u)\n",
4677 4714 count, evt->length);
4678 - return IRQ_NONE;
4715 + /*
4716 + * This is a fatal error - the driver and controller are out of
4717 + * sync on which event has been consumed. Reinitializing the
4718 + * controller is required to recover. Write the bogus count back
4719 + * to GEVNTCOUNT to clear the IRQ source, consistent with the
4720 + * stale event clearing in dwc3_event_buffers_setup(), then
4721 + * schedule error recovery.
4722 + */
4723 + spin_lock(&dwc->lock);
4724 + dwc3_schedule_err_recovery(dwc);
4725 + spin_unlock(&dwc->lock);
4726 + dwc3_writel(dwc, DWC3_GEVNTCOUNT(0), count);
4727 + return IRQ_HANDLED;
4679 4728 }
4680 4729
4681 4730 evt->count = count;
@@ -4735,6 +4784,57 @@ static void dwc_gadget_release(struct device *dev)
4735 4784 kfree(gadget);
4736 4785 }
4737 4786
4787 + static void dwc3_err_recovery_work(struct work_struct *work)
4788 + {
4789 + struct dwc3 *dwc = container_of(work, struct dwc3, err_recovery_work);
4790 + unsigned long flags;
4791 + int ret;
4792 +
4793 + /* serializes against dwc3_gadget_pullup() */
4794 + mutex_lock(&dwc->connect_mutex);
4795 +
4796 + ret = dwc3_gadget_soft_disconnect(dwc);
4797 +
4798 + dwc3_disconnect_gadget_sleepable(dwc);
4799 +
4800 + if (ret)
4801 + goto err_unrecoverable;
4802 +
4803 + if (dwc->softconnect) {
4804 + u32 count;
4805 + /*
4806 + * Wait irq to finish before soft_connect resets evt->lpos and
4807 + * the event buffer registers to avoid racing with
4808 + * dwc3_process_event_buf().
4809 + */
4810 + synchronize_irq(dwc->irq_gadget);
4811 +
4812 + spin_lock_irqsave(&dwc->lock, flags);
4813 + count = ++dwc->err_recovery_count;
4814 + spin_unlock_irqrestore(&dwc->lock, flags);
4815 +
4816 + if (count > DWC3_ERR_RECOVERY_MAX)
4817 + goto err_unrecoverable;
4818 +
4819 + ret = dwc3_gadget_soft_connect(dwc);
4820 + if (ret)
4821 + goto err_unrecoverable;
4822 + }
4823 + mutex_unlock(&dwc->connect_mutex);
4824 +
4825 + spin_lock_irqsave(&dwc->lock, flags);
4826 + dwc->err_state = DWC3_ERR_NONE;
4827 + spin_unlock_irqrestore(&dwc->lock, flags);
4828 + return;
4829 +
4830 + err_unrecoverable:
4831 + dev_err(dwc->dev, "Unable to recover the controller\n");
4832 + mutex_unlock(&dwc->connect_mutex);
4833 + spin_lock_irqsave(&dwc->lock, flags);
4834 + dwc->err_state = DWC3_ERR_UNRECOVERABLE;
4835 + spin_unlock_irqrestore(&dwc->lock, flags);
4836 + }
4837 +
4738 4838 /**
4739 4839 * dwc3_gadget_init - initializes gadget related registers
4740 4840 * @dwc: pointer to our controller context structure
@@ -4778,6 +4878,8 @@ int dwc3_gadget_init(struct dwc3 *dwc)
4778 4878 }
4779 4879
4780 4880 init_completion(&dwc->ep0_in_setup);
4881 + INIT_WORK(&dwc->err_recovery_work, dwc3_err_recovery_work);
4882 + mutex_init(&dwc->connect_mutex);
4781 4883 dwc->gadget = kzalloc_obj(struct usb_gadget);
4782 4884 if (!dwc->gadget) {
4783 4885 ret = -ENOMEM;
@@ -4874,6 +4976,8 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
4874 4976 if (!dwc->gadget)
4875 4977 return;
4876 4978
4979 + cancel_work_sync(&dwc->err_recovery_work);
4980 + mutex_destroy(&dwc->connect_mutex);
4877 4981 dwc3_enable_susphy(dwc, true);
4878 4982 usb_del_gadget(dwc->gadget);
4879 4983 dwc3_gadget_free_endpoints(dwc);
modified drivers/usb/gadget/function/f_fs.c
@@ -1877,8 +1877,9 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
1877 1877 break;
1878 1878 case FUNCTIONFS_ENDPOINT_DESC:
1879 1879 {
1880 + const struct usb_endpoint_descriptor *desc;
1881 + struct usb_endpoint_descriptor desc1;
1880 1882 int desc_idx;
1881 - struct usb_endpoint_descriptor desc1, *desc;
1882 1883
1883 1884 switch (epfile->ffs->gadget->speed) {
1884 1885 case USB_SPEED_SUPER:
@@ -1892,7 +1893,17 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
1892 1893 desc_idx = 0;
1893 1894 }
1894 1895
1895 - desc = epfile->ep->descs[desc_idx];
1896 + do {
1897 + desc = epfile->ep->descs[desc_idx];
1898 + } while (!desc && --desc_idx >= 0);
1899 +
1900 + if (!desc)
1901 + desc = epfile->ep->ep->desc;
1902 + if (!desc) {
1903 + ret = -EINVAL;
1904 + break;
1905 + }
1906 +
1896 1907 memcpy(&desc1, desc, desc->bLength);
1897 1908
1898 1909 spin_unlock_irq(&epfile->ffs->eps_lock);
modified drivers/usb/gadget/function/f_midi2.c
@@ -1633,8 +1633,8 @@ struct f_midi2_usb_config {
1633 1633
1634 1634 /* MIDI 1.0 jacks */
1635 1635 unsigned char jack_in, jack_out, jack_id;
1636 - struct usb_midi_in_jack_descriptor jack_ins[MAX_CABLES];
1637 - struct usb_midi_out_jack_descriptor_1 jack_outs[MAX_CABLES];
1636 + struct usb_midi_in_jack_descriptor jack_ins[MAX_CABLES * 2];
1637 + struct usb_midi_out_jack_descriptor_1 jack_outs[MAX_CABLES * 2];
1638 1638 };
1639 1639
1640 1640 static int append_config(struct f_midi2_usb_config *config, void *d)
modified drivers/usb/gadget/function/f_uac1_legacy.c
@@ -797,6 +797,9 @@ fail:
797 797
798 798 static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
799 799 {
800 + if (cmd >= ARRAY_SIZE(con->data))
801 + return -EINVAL;
802 +
800 803 con->data[cmd] = value;
801 804
802 805 return 0;
@@ -804,6 +807,9 @@ static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
804 807
805 808 static int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
806 809 {
810 + if (cmd >= ARRAY_SIZE(con->data))
811 + return -EINVAL;
812 +
807 813 return con->data[cmd];
808 814 }
809 815
modified drivers/usb/gadget/udc/aspeed-vhub/core.c
@@ -267,6 +267,9 @@ static void ast_vhub_remove(struct platform_device *pdev)
267 267 for (i = 0; i < vhub->max_ports; i++)
268 268 ast_vhub_del_dev(&vhub->ports[i].dev);
269 269
270 + /* Final drain; the worker takes vhub->lock, so stay outside of it */
271 + cancel_work_sync(&vhub->wake_work);
272 +
270 273 spin_lock_irqsave(&vhub->lock, flags);
271 274
272 275 /* Mask & ack all interrupts */
@@ -328,6 +331,7 @@ static int ast_vhub_probe(struct platform_device *pdev)
328 331 return -ENOMEM;
329 332
330 333 spin_lock_init(&vhub->lock);
334 + INIT_WORK(&vhub->wake_work, ast_vhub_wake_work);
331 335 vhub->pdev = pdev;
332 336 vhub->port_irq_mask = GENMASK(VHUB_IRQ_DEV1_BIT + vhub->max_ports - 1,
333 337 VHUB_IRQ_DEV1_BIT);
modified drivers/usb/gadget/udc/aspeed-vhub/dev.c
@@ -280,7 +280,7 @@ static int ast_vhub_udc_wakeup(struct usb_gadget* gadget)
280 280 int rc = -EINVAL;
281 281
282 282 spin_lock_irqsave(&d->vhub->lock, flags);
283 - if (!d->wakeup_en)
283 + if (!d->wakeup_en || !d->registered)
284 284 goto err;
285 285
286 286 DDBG(d, "Device initiated wakeup\n");
modified drivers/usb/gadget/udc/aspeed-vhub/hub.c
@@ -558,7 +558,7 @@ void ast_vhub_device_connect(struct ast_vhub *vhub,
558 558 ast_vhub_send_host_wakeup(vhub);
559 559 }
560 560
561 - static void ast_vhub_wake_work(struct work_struct *work)
561 + void ast_vhub_wake_work(struct work_struct *work)
562 562 {
563 563 struct ast_vhub *vhub = container_of(work,
564 564 struct ast_vhub,
@@ -588,6 +588,8 @@ static void ast_vhub_wake_work(struct work_struct *work)
588 588
589 589 void ast_vhub_hub_wake_all(struct ast_vhub *vhub)
590 590 {
591 + lockdep_assert_held(&vhub->lock);
592 +
591 593 /*
592 594 * A device is trying to wake the world, because this
593 595 * can recurse into the device, we break the call chain
@@ -1076,7 +1078,6 @@ static int ast_vhub_init_desc(struct ast_vhub *vhub)
1076 1078 int ast_vhub_init_hub(struct ast_vhub *vhub)
1077 1079 {
1078 1080 vhub->speed = USB_SPEED_UNKNOWN;
1079 - INIT_WORK(&vhub->wake_work, ast_vhub_wake_work);
1080 1081
1081 1082 return ast_vhub_init_desc(vhub);
1082 1083 }
modified drivers/usb/gadget/udc/aspeed-vhub/vhub.h
@@ -547,6 +547,7 @@ void ast_vhub_hub_suspend(struct ast_vhub *vhub);
547 547 void ast_vhub_hub_resume(struct ast_vhub *vhub);
548 548 void ast_vhub_hub_reset(struct ast_vhub *vhub);
549 549 void ast_vhub_hub_wake_all(struct ast_vhub *vhub);
550 + void ast_vhub_wake_work(struct work_struct *work);
550 551
551 552 /* dev.c */
552 553 int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int idx);
modified drivers/usb/gadget/udc/dummy_hcd.c
@@ -343,9 +343,11 @@ static void dummy_giveback(struct dummy *dum, struct usb_ep *_ep,
343 343 {
344 344 bool fifo = req == &dum->fifo_req;
345 345
346 + ++dum->callback_usage;
346 347 spin_unlock(&dum->lock);
347 348 usb_gadget_giveback_request(_ep, &req->req);
348 349 spin_lock(&dum->lock);
350 + --dum->callback_usage;
349 351 if (fifo)
350 352 dum->fifo_req_busy = 0;
351 353 }
@@ -759,11 +761,13 @@ static int dummy_queue(struct usb_ep *_ep, struct usb_request *_req,
759 761 req->req.complete = fifo_complete;
760 762
761 763 list_add_tail(&req->queue, &ep->queue);
764 + ++dum->callback_usage;
762 765 spin_unlock(&dum->lock);
763 766 _req->actual = _req->length;
764 767 _req->status = 0;
765 768 usb_gadget_giveback_request(_ep, _req);
766 769 spin_lock(&dum->lock);
770 + --dum->callback_usage;
767 771 } else
768 772 list_add_tail(&req->queue, &ep->queue);
769 773 spin_unlock_irqrestore(&dum->lock, flags);
modified drivers/usb/host/octeon-hcd.c
@@ -378,8 +378,22 @@ struct octeon_hcd {
378 378 struct cvmx_usb_transaction *active_split;
379 379 struct cvmx_usb_tx_fifo periodic;
380 380 struct cvmx_usb_tx_fifo nonperiodic;
381 + struct hrtimer sof_timer;
381 382 };
382 383
384 + static int cvmx_usb_poll(struct octeon_hcd *usb);
385 +
386 + static enum hrtimer_restart octeon_usb_sof_timer(struct hrtimer *t)
387 + {
388 + struct octeon_hcd *usb = container_of(t, struct octeon_hcd, sof_timer);
389 + unsigned long flags;
390 +
391 + spin_lock_irqsave(&usb->lock, flags);
392 + cvmx_usb_poll(usb);
393 + spin_unlock_irqrestore(&usb->lock, flags);
394 + return HRTIMER_NORESTART;
395 + }
396 +
383 397 /*
384 398 * This macro logically sets a single field in a CSR. It does the sequence
385 399 * read, modify, and write
@@ -578,7 +592,7 @@ static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type)
578 592 int result;
579 593 u64 address = CVMX_USBCX_GRSTCTL(usb->index);
580 594 u64 done = cvmx_get_cycle() + 100 *
581 - (u64)octeon_get_clock_rate / 1000000;
595 + (u64)octeon_get_clock_rate() / 1000000;
582 596 union cvmx_usbcx_grstctl c;
583 597
584 598 while (1) {
@@ -853,6 +867,14 @@ retry:
853 867 * USBC_GAHBCFG[PTXFEMPLVL]
854 868 * Global interrupt mask, USBC_GAHBCFG[GLBLINTRMSK] = 1
855 869 */
870 + usbcx_gahbcfg.u32 = cvmx_usb_read_csr32(usb,
871 + CVMX_USBCX_GHWCFG3(usb->index));
872 + if (usbcx_gahbcfg.u32 == 0xffffffff || usbcx_gahbcfg.u32 == 0) {
873 + dev_err(dev, "USB core is not responding (GHWCFG3=0x%08x)\n",
874 + usbcx_gahbcfg.u32);
875 + return -ENODEV;
876 + }
877 +
856 878 usbcx_gahbcfg.u32 = 0;
857 879 usbcx_gahbcfg.s.dmaen = !(usb->init_flags &
858 880 CVMX_USB_INITIALIZE_FLAGS_NO_DMA);
@@ -1900,6 +1922,7 @@ static void cvmx_usb_schedule(struct octeon_hcd *usb, int is_sof)
1900 1922 int channel;
1901 1923 struct cvmx_usb_pipe *pipe;
1902 1924 int need_sof;
1925 + u64 min_due;
1903 1926 enum cvmx_usb_transfer ttype;
1904 1927
1905 1928 if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) {
@@ -1940,15 +1963,33 @@ done:
1940 1963 * future that might need to be scheduled
1941 1964 */
1942 1965 need_sof = 0;
1966 + min_due = ~0ull;
1943 1967 for (ttype = CVMX_USB_TRANSFER_CONTROL;
1944 1968 ttype <= CVMX_USB_TRANSFER_INTERRUPT; ttype++) {
1945 1969 list_for_each_entry(pipe, &usb->active_pipes[ttype], node) {
1946 - if (pipe->next_tx_frame > usb->frame_number) {
1947 - need_sof = 1;
1948 - break;
1949 - }
1970 + if (pipe->next_tx_frame > usb->frame_number &&
1971 + pipe->next_tx_frame < min_due)
1972 + min_due = pipe->next_tx_frame;
1950 1973 }
1951 1974 }
1975 + if (min_due != ~0ull) {
1976 + u64 delta = min_due - usb->frame_number;
1977 +
1978 + /*
1979 + * frame_number is resynced from HFNUM on every poll, so a
1980 + * deadline that is many frames away does not need an
1981 + * interrupt on every SOF to count them down - sleep on the
1982 + * timer instead and keep SOF interrupts for deadlines within
1983 + * a few frames. Stay well below the 16383-frame wrap of
1984 + * HFNUM. One (micro)frame is 125us in high-speed mode.
1985 + */
1986 + if (delta <= 4 || delta > 8000)
1987 + need_sof = 1;
1988 + else
1989 + hrtimer_start(&usb->sof_timer,
1990 + ns_to_ktime((delta - 2) * 125000),
1991 + HRTIMER_MODE_REL);
1992 + }
1952 1993 USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index),
1953 1994 cvmx_usbcx_gintmsk, sofmsk, need_sof);
1954 1995 }
@@ -3638,6 +3679,8 @@ static int octeon_usb_probe(struct platform_device *pdev)
3638 3679 usb = (struct octeon_hcd *)hcd->hcd_priv;
3639 3680
3640 3681 spin_lock_init(&usb->lock);
3682 + hrtimer_setup(&usb->sof_timer, octeon_usb_sof_timer, CLOCK_MONOTONIC,
3683 + HRTIMER_MODE_REL);
3641 3684
3642 3685 usb->init_flags = initialize_flags;
3643 3686
@@ -3688,6 +3731,7 @@ static void octeon_usb_remove(struct platform_device *pdev)
3688 3731 unsigned long flags;
3689 3732
3690 3733 usb_remove_hcd(hcd);
3734 + hrtimer_cancel(&usb->sof_timer);
3691 3735 spin_lock_irqsave(&usb->lock, flags);
3692 3736 status = cvmx_usb_shutdown(usb);
3693 3737 spin_unlock_irqrestore(&usb->lock, flags);
modified drivers/usb/host/ohci-da8xx.c
@@ -447,6 +447,7 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
447 447
448 448 err_remove_hcd:
449 449 usb_remove_hcd(hcd);
450 + device_wakeup_disable(hcd->self.controller);
450 451 err:
451 452 usb_put_hcd(hcd);
452 453 return error;
@@ -457,6 +458,7 @@ static void ohci_da8xx_remove(struct platform_device *pdev)
457 458 struct usb_hcd *hcd = platform_get_drvdata(pdev);
458 459
459 460 usb_remove_hcd(hcd);
461 + device_wakeup_disable(hcd->self.controller);
460 462 usb_put_hcd(hcd);
461 463 }
462 464
modified drivers/usb/host/ohci-s3c2410.c
@@ -335,6 +335,7 @@ ohci_hcd_s3c2410_remove(struct platform_device *dev)
335 335 struct usb_hcd *hcd = platform_get_drvdata(dev);
336 336
337 337 usb_remove_hcd(hcd);
338 + device_wakeup_disable(hcd->self.controller);
338 339 s3c2410_stop_hc(dev);
339 340 usb_put_hcd(hcd);
340 341 }
modified drivers/usb/host/ohci-spear.c
@@ -103,6 +103,7 @@ static void spear_ohci_hcd_drv_remove(struct platform_device *pdev)
103 103 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
104 104
105 105 usb_remove_hcd(hcd);
106 + device_wakeup_disable(hcd->self.controller);
106 107 clk_disable_unprepare(sohci_p->clk);
107 108
108 109 usb_put_hcd(hcd);
modified drivers/usb/host/ohci-st.c
@@ -235,6 +235,7 @@ static void st_ohci_platform_remove(struct platform_device *dev)
235 235 int clk;
236 236
237 237 usb_remove_hcd(hcd);
238 + device_wakeup_disable(hcd->self.controller);
238 239
239 240 if (pdata->power_off)
240 241 pdata->power_off(dev);
modified drivers/usb/serial/bus.c
@@ -165,7 +165,11 @@ int usb_serial_bus_register(struct usb_serial_driver *driver)
165 165
166 166 void usb_serial_bus_deregister(struct usb_serial_driver *driver)
167 167 {
168 - free_dynids(driver);
169 168 driver_unregister(&driver->driver);
169 + free_dynids(driver);
170 170 }
171 171
172 + void usb_serial_bus_remove_new_id(struct usb_serial_driver *driver)
173 + {
174 + driver_remove_file(&driver->driver, &driver_attr_new_id);
175 + }
modified drivers/usb/serial/cp210x.c
@@ -223,6 +223,7 @@ static const struct usb_device_id id_table[] = {
223 223 { USB_DEVICE(0x19CF, 0x3000) }, /* Parrot NMEA GPS Flight Recorder */
224 224 { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */
225 225 { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */
226 + { USB_DEVICE(0x1B1C, 0x1C02) }, /* Corsair AX1500i Power Supply */
226 227 { USB_DEVICE(0x1B93, 0x1013) }, /* Phoenix Contact UPS Device */
227 228 { USB_DEVICE(0x1BA4, 0x0002) }, /* Silicon Labs 358x factory default */
228 229 { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */
modified drivers/usb/serial/generic.c
@@ -266,6 +266,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);
266 266 void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
267 267 {
268 268 struct usb_serial_port *port = tty->driver_data;
269 + struct tty_port *tport = &port->port;
269 270 unsigned int bps;
270 271 unsigned long period;
271 272 unsigned long expire;
@@ -285,7 +286,14 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
285 286 __func__, jiffies_to_msecs(timeout),
286 287 jiffies_to_msecs(period));
287 288 expire = jiffies + timeout;
288 - while (!port->serial->type->tx_empty(port)) {
289 + for (;;) {
290 + mutex_lock(&tport->mutex);
291 + if (tty_io_error(tty) || port->serial->type->tx_empty(port)) {
292 + mutex_unlock(&tport->mutex);
293 + break;
294 + }
295 + mutex_unlock(&tport->mutex);
296 +
289 297 schedule_timeout_interruptible(period);
290 298 if (signal_pending(current))
291 299 break;
modified drivers/usb/serial/option.c
@@ -260,6 +260,7 @@ static void option_instat_callback(struct urb *urb);
260 260 #define QUECTEL_PRODUCT_EM060K_12a 0x012a
261 261 #define QUECTEL_PRODUCT_EM060K_12b 0x012b
262 262 #define QUECTEL_PRODUCT_EM060K_12c 0x012c
263 + #define QUECTEL_PRODUCT_RG660QB 0x013d
263 264 #define QUECTEL_PRODUCT_EG91 0x0191
264 265 #define QUECTEL_PRODUCT_EG95 0x0195
265 266 #define QUECTEL_PRODUCT_BG96 0x0296
@@ -280,6 +281,7 @@ static void option_instat_callback(struct urb *urb);
280 281 #define QUECTEL_PRODUCT_EC200U 0x0901
281 282 #define QUECTEL_PRODUCT_EG912Y 0x6001
282 283 #define QUECTEL_PRODUCT_EC200S_CN 0x6002
284 + #define QUECTEL_PRODUCT_EG060W 0x6004
283 285 #define QUECTEL_PRODUCT_EC200A 0x6005
284 286 #define QUECTEL_PRODUCT_EG916Q 0x6007
285 287 #define QUECTEL_PRODUCT_EM061K_LWW 0x6008
@@ -1268,12 +1270,15 @@ static const struct usb_device_id option_ids[] = {
1268 1270 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200A, 0xff, 0, 0) },
1269 1271 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200U, 0xff, 0, 0) },
1270 1272 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200S_CN, 0xff, 0, 0) },
1273 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EG060W, 0xff, 0, 0) },
1271 1274 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200T, 0xff, 0, 0) },
1272 1275 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EG912Y, 0xff, 0, 0) },
1273 1276 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EG916Q, 0xff, 0x00, 0x00) },
1274 1277 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500K, 0xff, 0x00, 0x00) },
1275 1278 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG650V, 0xff, 0xff, 0x30) },
1276 1279 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG650V, 0xff, 0, 0) },
1280 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG660QB, 0xff, 0xff, 0x30) },
1281 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG660QB, 0xff, 0, 0) },
1277 1282 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG255C, 0xff, 0xff, 0x30) },
1278 1283 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG255C, 0xff, 0, 0) },
1279 1284 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RG255C, 0xff, 0xff, 0x40) },
@@ -2168,6 +2173,8 @@ static const struct usb_device_id option_ids[] = {
2168 2173 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9003, 0xff) }, /* Simcom SIM7500/SIM7600 MBIM mode */
2169 2174 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9011, 0xff), /* Simcom SIM7500/SIM7600 RNDIS mode */
2170 2175 .driver_info = RSVD(7) },
2176 + { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x902b, 0xff),
2177 + .driver_info = RSVD(4) },
2171 2178 { USB_DEVICE(0x1e0e, 0x9071), /* Simcom SIM8230 RMNET mode */
2172 2179 .driver_info = RSVD(3) | RSVD(4) },
2173 2180 { USB_DEVICE_INTERFACE_CLASS(0x1e0e, 0x9078, 0xff), /* Simcom SIM8230 ECM mode */
@@ -2429,6 +2436,13 @@ static const struct usb_device_id option_ids[] = {
2429 2436 .driver_info = RSVD(5) },
2430 2437 { USB_DEVICE_INTERFACE_CLASS(0x0489, 0xe167, 0xff), /* Foxconn T99W640 MBIM */
2431 2438 .driver_info = RSVD(3) },
2439 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x4d22, 0xff, 0x10, 0x01) }, /* Compal EXC-T1 */
2440 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x4d22, 0xff, 0x10, 0x02) },
2441 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x4d22, 0xff, 0x10, 0x03) },
2442 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x4d22, 0xff, 0x10, 0x04) },
2443 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x8217, 0xff, 0xff, 0x30) }, /* Compal EXM-G1x */
2444 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x8217, 0xff, 0xff, 0x40) },
2445 + { USB_DEVICE_AND_INTERFACE_INFO(0x04b7, 0x8217, 0xff, 0xff, 0x60) },
2432 2446 { USB_DEVICE(0x1508, 0x1001), /* Fibocom NL668 (IOT version) */
2433 2447 .driver_info = RSVD(4) | RSVD(5) | RSVD(6) },
2434 2448 { USB_DEVICE(0x1782, 0x4d10) }, /* Fibocom L610 (AT mode) */
modified drivers/usb/serial/quatech2.c
@@ -52,6 +52,7 @@
52 52 #define QT2_XMIT_FLUSH 0x05 /* no following info */
53 53 #define QT2_CONTROL_ESCAPE 0xff /* pass through previous 2 control bytes */
54 54
55 + #define MIN_BAUD_RATE 50
55 56 #define MAX_BAUD_RATE 921600
56 57 #define DEFAULT_BAUD_RATE 9600
57 58
@@ -156,7 +157,7 @@ static inline int calc_baud_divisor(int baudrate)
156 157
157 158 static inline int qt2_set_port_config(struct usb_device *dev,
158 159 unsigned char port_number,
159 - u16 baudrate, u16 lcr)
160 + speed_t baudrate, u16 lcr)
160 161 {
161 162 int divisor = calc_baud_divisor(baudrate);
162 163 u16 index = ((u16) (lcr << 8) | (u16) (port_number));
@@ -257,9 +258,9 @@ static void qt2_set_termios(struct tty_struct *tty,
257 258 struct usb_device *dev = port->serial->dev;
258 259 struct qt2_port_private *port_priv;
259 260 struct ktermios *termios = &tty->termios;
260 - u16 baud;
261 261 unsigned int cflag = termios->c_cflag;
262 262 u16 new_lcr = 0;
263 + speed_t baud;
263 264 int status;
264 265
265 266 port_priv = usb_get_serial_port_data(port);
@@ -277,6 +278,18 @@ static void qt2_set_termios(struct tty_struct *tty,
277 278 if (!baud)
278 279 baud = 9600;
279 280
281 + if (baud < MIN_BAUD_RATE || baud > MAX_BAUD_RATE) {
282 + if (old_termios)
283 + baud = tty_termios_baud_rate(old_termios);
284 + else
285 + baud = clamp(baud, MIN_BAUD_RATE, MAX_BAUD_RATE);
286 +
287 + tty_encode_baud_rate(tty, baud, baud);
288 +
289 + if (!baud)
290 + baud = 9600;
291 + }
292 +
280 293 status = qt2_set_port_config(dev, port_priv->device_port, baud,
281 294 new_lcr);
282 295 if (status < 0)
@@ -373,7 +386,7 @@ static int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
373 386 port_priv->device_port = (u8) device_port;
374 387
375 388 if (tty)
376 - qt2_set_termios(tty, port, &tty->termios);
389 + qt2_set_termios(tty, port, NULL);
377 390
378 391 return 0;
379 392
modified drivers/usb/serial/ssu100.c
@@ -32,6 +32,7 @@
32 32
33 33 #define SERIAL_EVEN_PARITY (UART_LCR_PARITY | UART_LCR_EPAR)
34 34
35 + #define MIN_BAUD_RATE 50
35 36 #define MAX_BAUD_RATE 460800
36 37
37 38 #define ATC_DISABLED 0x00
@@ -217,9 +218,10 @@ static void ssu100_set_termios(struct tty_struct *tty,
217 218 {
218 219 struct usb_device *dev = port->serial->dev;
219 220 struct ktermios *termios = &tty->termios;
220 - u16 baud, divisor, remainder;
221 + speed_t baud, remainder;
221 222 unsigned int cflag = termios->c_cflag;
222 223 u16 urb_value = 0; /* will hold the new flags */
224 + u16 divisor;
223 225 int result;
224 226
225 227 if (cflag & PARENB) {
@@ -235,6 +237,18 @@ static void ssu100_set_termios(struct tty_struct *tty,
235 237 if (!baud)
236 238 baud = 9600;
237 239
240 + if (baud < MIN_BAUD_RATE || baud > MAX_BAUD_RATE) {
241 + if (old_termios)
242 + baud = tty_termios_baud_rate(old_termios);
243 + else
244 + baud = clamp(baud, MIN_BAUD_RATE, MAX_BAUD_RATE);
245 +
246 + tty_encode_baud_rate(tty, baud, baud);
247 +
248 + if (!baud)
249 + baud = 9600;
250 + }
251 +
238 252 dev_dbg(&port->dev, "%s - got baud = %d\n", __func__, baud);
239 253
240 254
@@ -310,7 +324,7 @@ static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
310 324 dev_dbg(&port->dev, "%s - set uart failed\n", __func__);
311 325
312 326 if (tty)
313 - ssu100_set_termios(tty, port, &tty->termios);
327 + ssu100_set_termios(tty, port, NULL);
314 328
315 329 return usb_serial_generic_open(tty, port);
316 330 }
modified drivers/usb/serial/usb-serial.c
@@ -400,17 +400,13 @@ static unsigned int serial_chars_in_buffer(struct tty_struct *tty)
400 400 static void serial_wait_until_sent(struct tty_struct *tty, int timeout)
401 401 {
402 402 struct usb_serial_port *port = tty->driver_data;
403 - struct usb_serial *serial = port->serial;
404 403
405 404 dev_dbg(&port->dev, "%s\n", __func__);
406 405
407 406 if (!port->serial->type->wait_until_sent)
408 407 return;
409 408
410 - mutex_lock(&serial->disc_mutex);
411 - if (!serial->disconnected)
412 - port->serial->type->wait_until_sent(tty, timeout);
413 - mutex_unlock(&serial->disc_mutex);
409 + port->serial->type->wait_until_sent(tty, timeout);
414 410 }
415 411
416 412 static void serial_throttle(struct tty_struct *tty)
@@ -438,8 +434,13 @@ static int serial_get_serial(struct tty_struct *tty, struct serial_struct *ss)
438 434 struct usb_serial_port *port = tty->driver_data;
439 435 struct tty_port *tport = &port->port;
440 436 unsigned int close_delay, closing_wait;
437 + int ret = 0;
441 438
442 439 mutex_lock(&tport->mutex);
440 + if (tty_io_error(tty)) {
441 + ret = -EIO;
442 + goto out_unlock;
443 + }
443 444
444 445 close_delay = jiffies_to_msecs(tport->close_delay) / 10;
445 446 closing_wait = tport->closing_wait;
@@ -452,10 +453,10 @@ static int serial_get_serial(struct tty_struct *tty, struct serial_struct *ss)
452 453
453 454 if (port->serial->type->get_serial)
454 455 port->serial->type->get_serial(tty, ss);
455 -
456 + out_unlock:
456 457 mutex_unlock(&tport->mutex);
457 458
458 - return 0;
459 + return ret;
459 460 }
460 461
461 462 static int serial_set_serial(struct tty_struct *tty, struct serial_struct *ss)
@@ -471,6 +472,10 @@ static int serial_set_serial(struct tty_struct *tty, struct serial_struct *ss)
471 472 closing_wait = msecs_to_jiffies(closing_wait * 10);
472 473
473 474 mutex_lock(&tport->mutex);
475 + if (tty_io_error(tty)) {
476 + ret = -EIO;
477 + goto out_unlock;
478 + }
474 479
475 480 if (!capable(CAP_SYS_ADMIN)) {
476 481 if (close_delay != tport->close_delay ||
@@ -498,6 +503,7 @@ static int serial_ioctl(struct tty_struct *tty,
498 503 unsigned int cmd, unsigned long arg)
499 504 {
500 505 struct usb_serial_port *port = tty->driver_data;
506 + struct tty_port *tport = &port->port;
501 507 int retval = -ENOIOCTLCMD;
502 508
503 509 dev_dbg(&port->dev, "%s - cmd 0x%04x\n", __func__, cmd);
@@ -508,8 +514,21 @@ static int serial_ioctl(struct tty_struct *tty,
508 514 retval = port->serial->type->tiocmiwait(tty, arg);
509 515 break;
510 516 default:
511 - if (port->serial->type->ioctl)
517 + if (!port->serial->type->ioctl)
518 + break;
519 +
520 + if (cmd == TIOCSRS485)
521 + down_write(&tty->termios_rwsem);
522 +
523 + mutex_lock(&tport->mutex);
524 + if (tty_io_error(tty))
525 + retval = -EIO;
526 + else
512 527 retval = port->serial->type->ioctl(tty, cmd, arg);
528 + mutex_unlock(&tport->mutex);
529 +
530 + if (cmd == TIOCSRS485)
531 + up_write(&tty->termios_rwsem);
513 532 }
514 533
515 534 return retval;
@@ -519,25 +538,40 @@ static void serial_set_termios(struct tty_struct *tty,
519 538 const struct ktermios *old)
520 539 {
521 540 struct usb_serial_port *port = tty->driver_data;
541 + struct tty_port *tport = &port->port;
522 542
523 543 dev_dbg(&port->dev, "%s\n", __func__);
524 544
525 - if (port->serial->type->set_termios)
526 - port->serial->type->set_termios(tty, port, old);
527 - else
545 + if (!port->serial->type->set_termios) {
528 546 tty_termios_copy_hw(&tty->termios, old);
547 + return;
548 + }
549 +
550 + mutex_lock(&tport->mutex);
551 + if (!tty_io_error(tty))
552 + port->serial->type->set_termios(tty, port, old);
553 + mutex_unlock(&tport->mutex);
529 554 }
530 555
531 556 static int serial_break(struct tty_struct *tty, int break_state)
532 557 {
533 558 struct usb_serial_port *port = tty->driver_data;
559 + struct tty_port *tport = &port->port;
560 + int ret;
534 561
535 562 dev_dbg(&port->dev, "%s\n", __func__);
536 563
537 - if (port->serial->type->break_ctl)
538 - return port->serial->type->break_ctl(tty, break_state);
564 + if (!port->serial->type->break_ctl)
565 + return -ENOTTY;
539 566
540 - return -ENOTTY;
567 + mutex_lock(&tport->mutex);
568 + if (tty_io_error(tty))
569 + ret = -EIO;
570 + else
571 + ret = port->serial->type->break_ctl(tty, break_state);
572 + mutex_unlock(&tport->mutex);
573 +
574 + return ret;
541 575 }
542 576
543 577 static int serial_proc_show(struct seq_file *m, void *v)
@@ -578,24 +612,44 @@ static int serial_proc_show(struct seq_file *m, void *v)
578 612 static int serial_tiocmget(struct tty_struct *tty)
579 613 {
580 614 struct usb_serial_port *port = tty->driver_data;
615 + struct tty_port *tport = &port->port;
616 + int ret;
581 617
582 618 dev_dbg(&port->dev, "%s\n", __func__);
583 619
584 - if (port->serial->type->tiocmget)
585 - return port->serial->type->tiocmget(tty);
586 - return -ENOTTY;
620 + if (!port->serial->type->tiocmget)
621 + return -ENOTTY;
622 +
623 + mutex_lock(&tport->mutex);
624 + if (tty_io_error(tty))
625 + ret = -EIO;
626 + else
627 + ret = port->serial->type->tiocmget(tty);
628 + mutex_unlock(&tport->mutex);
629 +
630 + return ret;
587 631 }
588 632
589 633 static int serial_tiocmset(struct tty_struct *tty,
590 634 unsigned int set, unsigned int clear)
591 635 {
592 636 struct usb_serial_port *port = tty->driver_data;
637 + struct tty_port *tport = &port->port;
638 + int ret;
593 639
594 640 dev_dbg(&port->dev, "%s\n", __func__);
595 641
596 - if (port->serial->type->tiocmset)
597 - return port->serial->type->tiocmset(tty, set, clear);
598 - return -ENOTTY;
642 + if (!port->serial->type->tiocmset)
643 + return -ENOTTY;
644 +
645 + mutex_lock(&tport->mutex);
646 + if (tty_io_error(tty))
647 + ret = -EIO;
648 + else
649 + ret = port->serial->type->tiocmset(tty, set, clear);
650 + mutex_unlock(&tport->mutex);
651 +
652 + return ret;
599 653 }
600 654
601 655 static int serial_get_icount(struct tty_struct *tty,
@@ -1191,12 +1245,17 @@ static void usb_serial_disconnect(struct usb_interface *interface)
1191 1245 usb_serial_port_poison_urbs(port);
1192 1246 wake_up_interruptible(&port->port.delta_msr_wait);
1193 1247 cancel_work_sync(&port->work);
1194 - if (device_is_registered(&port->dev))
1195 - device_del(&port->dev);
1196 1248 }
1249 +
1197 1250 if (serial->type->disconnect)
1198 1251 serial->type->disconnect(serial);
1199 1252
1253 + for (i = 0; i < serial->num_ports; ++i) {
1254 + port = serial->port[i];
1255 + if (device_is_registered(&port->dev))
1256 + device_del(&port->dev);
1257 + }
1258 +
1200 1259 release_sibling(serial, interface);
1201 1260
1202 1261 /* let the last holder of this object cause it to be cleaned up */
@@ -1313,7 +1372,8 @@ static int __init usb_serial_init(void)
1313 1372 int result;
1314 1373
1315 1374 usb_serial_tty_driver = tty_alloc_driver(USB_SERIAL_TTY_MINORS,
1316 - TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
1375 + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV |
1376 + TTY_DRIVER_RESET_SAVED_TERMIOS);
1317 1377 if (IS_ERR(usb_serial_tty_driver))
1318 1378 return PTR_ERR(usb_serial_tty_driver);
1319 1379
@@ -1464,7 +1524,7 @@ int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers
1464 1524 {
1465 1525 int rc;
1466 1526 struct usb_driver *udriver;
1467 - struct usb_serial_driver * const *sd;
1527 + struct usb_serial_driver * const *sd, * const *s;
1468 1528
1469 1529 /*
1470 1530 * udriver must be registered before any of the serial drivers,
@@ -1517,9 +1577,11 @@ int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers
1517 1577 return 0;
1518 1578
1519 1579 err_deregister_drivers:
1580 + for (s = serial_drivers; s < sd; ++s)
1581 + usb_serial_bus_remove_new_id(*s);
1582 + usb_deregister(udriver);
1520 1583 while (sd-- > serial_drivers)
1521 1584 usb_serial_deregister(*sd);
1522 - usb_deregister(udriver);
1523 1585 err_free_driver:
1524 1586 kfree(udriver);
1525 1587 return rc;
@@ -1537,10 +1599,23 @@ EXPORT_SYMBOL_GPL(__usb_serial_register_drivers);
1537 1599 void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[])
1538 1600 {
1539 1601 struct usb_driver *udriver = (*serial_drivers)->usb_driver;
1602 + struct usb_serial_driver * const *sd;
1603 +
1604 + /*
1605 + * udriver must be deregistered before the serial drivers so that
1606 + * I/O is stopped before unbinding the ports.
1607 + *
1608 + * Remove the new_id attributes to prevent ids from being added and
1609 + * triggering a probe of udriver after it has been deregistered.
1610 + */
1611 + for (sd = serial_drivers; *sd; ++sd)
1612 + usb_serial_bus_remove_new_id(*sd);
1540 1613
1541 - for (; *serial_drivers; ++serial_drivers)
1542 - usb_serial_deregister(*serial_drivers);
1543 1614 usb_deregister(udriver);
1615 +
1616 + for (sd = serial_drivers; *sd; ++sd)
1617 + usb_serial_deregister(*sd);
1618 +
1544 1619 kfree(udriver);
1545 1620 }
1546 1621 EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers);
modified drivers/usb/serial/xr_serial.c
@@ -850,12 +850,9 @@ static int xr_get_rs485_config(struct tty_struct *tty,
850 850 struct usb_serial_port *port = tty->driver_data;
851 851 struct xr_data *data = usb_get_serial_port_data(port);
852 852
853 - down_read(&tty->termios_rwsem);
854 - if (copy_to_user(argp, &data->rs485, sizeof(data->rs485))) {
855 - up_read(&tty->termios_rwsem);
853 + /* core holds port mutex */
854 + if (copy_to_user(argp, &data->rs485, sizeof(data->rs485)))
856 855 return -EFAULT;
857 - }
858 - up_read(&tty->termios_rwsem);
859 856
860 857 return 0;
861 858 }
@@ -871,10 +868,9 @@ static int xr_set_rs485_config(struct tty_struct *tty,
871 868 return -EFAULT;
872 869 xr_sanitize_serial_rs485(&rs485);
873 870
874 - down_write(&tty->termios_rwsem);
871 + /* core holds termios rwsem and port mutex */
875 872 data->rs485 = rs485;
876 873 xr_set_flow_mode(tty, port, NULL);
877 - up_write(&tty->termios_rwsem);
878 874
879 875 if (copy_to_user(argp, &rs485, sizeof(rs485)))
880 876 return -EFAULT;
modified drivers/usb/storage/sierra_ms.c
@@ -77,6 +77,13 @@ static int sierra_get_swoc_info(struct usb_device *udev,
77 77 sizeof(struct swoc_info), /* __u16 size */
78 78 USB_CTRL_SET_TIMEOUT); /* int timeout */
79 79
80 + /*
81 + * A short IN transfer leaves the tail of swocInfo uninitialized;
82 + * only a full transfer is valid.
83 + */
84 + if (result != sizeof(struct swoc_info))
85 + return -EIO;
86 +
80 87 swocInfo->LinuxSKU = le16_to_cpu(swocInfo->LinuxSKU);
81 88 swocInfo->LinuxVer = le16_to_cpu(swocInfo->LinuxVer);
82 89 return result;
modified drivers/usb/typec/anx7411.c
@@ -1566,8 +1566,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
1566 1566 anx7411_partner_unregister_altmode(plat);
1567 1567 anx7411_unregister_partner(plat);
1568 1568
1569 - if (plat->workqueue)
1569 + if (plat->workqueue) {
1570 + disable_irq(plat->intp_irq);
1571 + cancel_work_sync(&plat->work);
1570 1572 destroy_workqueue(plat->workqueue);
1573 + }
1571 1574
1572 1575 i2c_unregister_device(plat->spi_client);
1573 1576
modified drivers/usb/typec/port-mapper.c
@@ -42,6 +42,23 @@ static int usb4_port_compare(struct device *dev, void *fwnode)
42 42 return usb4_usb3_port_match(dev, fwnode);
43 43 }
44 44
45 + static bool typec_has_usb4_host_interface(const struct fwnode_handle *fwnode)
46 + {
47 + if (!IS_REACHABLE(CONFIG_USB4))
48 + return false;
49 +
50 + struct fwnode_handle *nhi_fwnode __free(fwnode_handle) =
51 + fwnode_find_reference(fwnode, "usb4-host-interface", 0);
52 +
53 + /*
54 + * The USB4 port can only appear if the host interface is enabled in
55 + * the firmware and has been enumerated as a device. The latter is
56 + * the same check as in usb_acpi_add_usb4_devlink().
57 + */
58 + return !IS_ERR(nhi_fwnode) && fwnode_device_is_available(nhi_fwnode) &&
59 + nhi_fwnode->dev;
60 + }
61 +
45 62 static int typec_port_compare(struct device *dev, void *fwnode)
46 63 {
47 64 return device_match_fwnode(dev, fwnode);
@@ -64,11 +81,11 @@ static int typec_port_match(struct device *dev, void *data)
64 81 adev_fwnode);
65 82
66 83 /*
67 - * If dev is USB 3.x port, it may have reference to the
84 + * If dev is USB 3.x port, it may have reference to an available
68 85 * USB4 host interface in which case we can also link the
69 86 * Type-C port with the USB4 port.
70 87 */
71 - if (fwnode_property_present(adev_fwnode, "usb4-host-interface"))
88 + if (typec_has_usb4_host_interface(adev_fwnode))
72 89 component_match_add(&arg->port->dev, &arg->match,
73 90 usb4_port_compare, adev_fwnode);
74 91 }
modified drivers/usb/typec/tcpm/tcpm.c
@@ -1756,7 +1756,8 @@ static void mod_enable_frs_delayed_work(struct tcpm_port *port, unsigned int del
1756 1756 static void mod_vdm_discovery_cancel_delayed_work(struct tcpm_port *port)
1757 1757 {
1758 1758 hrtimer_cancel(&port->vdm_discovery_timer);
1759 - kthread_cancel_work_sync(&port->vdm_discovery_work);
1759 + if (port->wq)
1760 + kthread_cancel_work_sync(&port->vdm_discovery_work);
1760 1761 }
1761 1762
1762 1763 static void mod_vdm_discovery_delayed_work(struct tcpm_port *port, unsigned int delay_ms)
@@ -7113,7 +7114,7 @@ static void tcpm_pd_event_handler(struct kthread_work *work)
7113 7114 port->upcoming_state = FR_SWAP_SEND;
7114 7115 ret = tcpm_ams_start(port, FAST_ROLE_SWAP);
7115 7116 if (ret == -EAGAIN)
7116 - port->upcoming_state = INVALID_STATE;
7117 + tcpm_set_state(port, ERROR_RECOVERY, 0);
7117 7118 } else {
7118 7119 tcpm_log(port, "Discarding FRS_SIGNAL! Not in sink ready");
7119 7120 }
@@ -8977,6 +8978,7 @@ void tcpm_unregister_port(struct tcpm_port *port)
8977 8978
8978 8979 port->registered = false;
8979 8980 kthread_destroy_worker(port->wq);
8981 + port->wq = NULL;
8980 8982
8981 8983 hrtimer_cancel(&port->vdm_discovery_timer);
8982 8984 hrtimer_cancel(&port->enable_frs_timer);
modified drivers/usb/typec/tipd/core.c
@@ -343,7 +343,7 @@ static void tps6598x_set_data_role(struct tps6598x *tps,
343 343
344 344 static int tps6598x_connect(struct tps6598x *tps, u32 status)
345 345 {
346 - struct typec_partner_desc desc;
346 + struct typec_partner_desc desc = { };
347 347 enum typec_pwr_opmode mode;
348 348 int ret;
349 349
@@ -354,7 +354,6 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)
354 354
355 355 desc.usb_pd = mode == TYPEC_PWR_MODE_PD;
356 356 desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
357 - desc.identity = NULL;
358 357
359 358 if (desc.usb_pd) {
360 359 ret = tps6598x_read_partner_identity(tps);
@@ -850,11 +849,10 @@ static void cd321x_update_work(struct work_struct *work)
850 849
851 850 /* Set up partner if we were previously disconnected (or changed). */
852 851 if (!tps->partner) {
853 - struct typec_partner_desc desc;
852 + struct typec_partner_desc desc = { };
854 853
855 854 desc.usb_pd = is_pd;
856 855 desc.accessory = TYPEC_ACCESSORY_NONE; /* XXX: handle accessories */
857 - desc.identity = NULL;
858 856
859 857 if (desc.usb_pd)
860 858 desc.identity = &st.partner_identity;
@@ -1792,6 +1790,7 @@ static int tps6598x_probe(struct i2c_client *client)
1792 1790 const struct tipd_data *data;
1793 1791 struct tps6598x *tps;
1794 1792 struct fwnode_handle *fwnode;
1793 + bool patch_loaded = false;
1795 1794 u32 status;
1796 1795 u32 vid = 0;
1797 1796 int ret;
@@ -1847,6 +1846,7 @@ static int tps6598x_probe(struct i2c_client *client)
1847 1846 return ret;
1848 1847
1849 1848 if (ret == TPS_MODE_PTCH) {
1849 + patch_loaded = true;
1850 1850 ret = tps->data->init(tps);
1851 1851 if (ret)
1852 1852 return ret;
@@ -1937,7 +1937,8 @@ err_clear_mask:
1937 1937 tps6598x_write64(tps, TPS_REG_INT_MASK1, 0);
1938 1938 err_reset_controller:
1939 1939 /* Reset PD controller to remove any applied patch */
1940 - tps->data->reset(tps);
1940 + if (patch_loaded)
1941 + tps->data->reset(tps);
1941 1942
1942 1943 return ret;
1943 1944 }
modified drivers/usb/typec/ucsi/displayport.c
@@ -71,11 +71,14 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
71 71 if (ret < 0) {
72 72 if (ucsi->version > 0x0100)
73 73 goto err_unlock;
74 - cur = 0xff;
75 74 }
76 75
77 - if (cur < UCSI_MAX_ALTMODES) {
78 - ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
76 + if (cur != 0xff) {
77 + if (cur < UCSI_MAX_ALTMODES)
78 + ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
79 + else
80 + ret = -EINVAL;
81 +
79 82 goto err_unlock;
80 83 }
81 84
modified drivers/usb/typec/ucsi/ucsi.c
@@ -1801,10 +1801,21 @@ static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con)
1801 1801 {
1802 1802 struct fwnode_handle *fwnode;
1803 1803 int i = 1;
1804 + int ret;
1805 + u32 port;
1804 1806
1805 - device_for_each_child_node(con->ucsi->dev, fwnode)
1806 - if (i++ == con->num)
1807 - return fwnode;
1807 + device_for_each_child_node(con->ucsi->dev, fwnode) {
1808 + ret = fwnode_property_read_u32(fwnode, "reg", &port);
1809 + if (ret < 0) {
1810 + if (i == con->num)
1811 + return fwnode;
1812 + } else {
1813 + if (port == con->num - 1)
1814 + return fwnode;
1815 + }
1816 +
1817 + i++;
1818 + }
1808 1819 return NULL;
1809 1820 }
1810 1821
modified drivers/usb/typec/ucsi/ucsi_acpi.c
@@ -121,6 +121,33 @@ static const struct ucsi_operations ucsi_acpi_ops = {
121 121 .async_control = ucsi_acpi_async_control
122 122 };
123 123
124 + static int ucsi_acer_read_version(struct ucsi *ucsi, u16 *version)
125 + {
126 + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
127 + int ret;
128 +
129 + ret = ucsi_acpi_read_version(ucsi, version);
130 + if (ret)
131 + return ret;
132 +
133 + if (!*version) {
134 + dev_warn(ua->dev, "UCSI version is zero, assuming 1.2\n");
135 + *version = UCSI_VERSION_1_2;
136 + }
137 +
138 + return 0;
139 + }
140 +
141 + static const struct ucsi_operations ucsi_acer_ops = {
142 + .read_version = ucsi_acer_read_version,
143 + .read_cci = ucsi_acpi_read_cci,
144 + .poll_cci = ucsi_acpi_poll_cci,
145 + .read_message_in = ucsi_acpi_read_message_in,
146 + .write_message_out = ucsi_acpi_write_message_out,
147 + .sync_control = ucsi_sync_control_common,
148 + .async_control = ucsi_acpi_async_control
149 + };
150 +
124 151 static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci,
125 152 void *val, size_t len, void *msg_out,
126 153 size_t msg_out_size)
@@ -162,6 +189,13 @@ static const struct ucsi_operations ucsi_gram_ops = {
162 189 };
163 190
164 191 static const struct dmi_system_id ucsi_acpi_quirks[] = {
192 + {
193 + .matches = {
194 + DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
195 + DMI_MATCH(DMI_PRODUCT_NAME, "Nitro ANV15-41"),
196 + },
197 + .driver_data = (void *)&ucsi_acer_ops,
198 + },
165 199 {
166 200 .matches = {
167 201 DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
modified drivers/usb/typec/ucsi/ucsi_glink.c
@@ -362,6 +362,10 @@ static void pmic_glink_ucsi_destroy(void *data)
362 362 {
363 363 struct pmic_glink_ucsi *ucsi = data;
364 364
365 + /* Drain the work items before ucsi_destroy() frees the ucsi instance */
366 + cancel_work_sync(&ucsi->notify_work);
367 + cancel_work_sync(&ucsi->register_work);
368 +
365 369 /* Protect to make sure we're not in a middle of a transaction from a glink callback */
366 370 mutex_lock(&ucsi->lock);
367 371 ucsi_destroy(ucsi->ucsi);
@@ -467,8 +471,15 @@ static void pmic_glink_ucsi_remove(struct auxiliary_device *adev)
467 471 {
468 472 struct pmic_glink_ucsi *ucsi = dev_get_drvdata(&adev->dev);
469 473
470 - /* Unregister first to stop having read & writes */
471 - ucsi_unregister(ucsi->ucsi);
474 + /* Callbacks can queue work until devres releases the client */
475 + disable_work_sync(&ucsi->notify_work);
476 + disable_work_sync(&ucsi->register_work);
477 +
478 + /* register_work may have unregistered the instance already */
479 + if (ucsi->ucsi_registered) {
480 + ucsi->ucsi_registered = false;
481 + ucsi_unregister(ucsi->ucsi);
482 + }
472 483 }
473 484
474 485 static const struct auxiliary_device_id pmic_glink_ucsi_id_table[] = {
modified drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -1706,6 +1706,7 @@ static int ne_create_vm_ioctl(struct ne_pci_dev *ne_pci_dev, u64 __user *slot_ui
1706 1706 return enclave_fd;
1707 1707
1708 1708 put_file:
1709 + enclave_file->private_data = NULL;
1709 1710 fput(enclave_file);
1710 1711 put_fd:
1711 1712 put_unused_fd(enclave_fd);
modified drivers/virt/vmgenid.c
@@ -25,7 +25,7 @@ struct vmgenid_state {
25 25
26 26 static void vmgenid_notify(struct device *device)
27 27 {
28 - struct vmgenid_state *state = device->driver_data;
28 + struct vmgenid_state *state = dev_get_drvdata(device);
29 29 u8 old_id[VMGENID_SIZE];
30 30
31 31 memcpy(old_id, state->this_id, sizeof(old_id));
@@ -75,13 +75,16 @@ static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
75 75 phys_addr = (obj->package.elements[0].integer.value << 0) |
76 76 (obj->package.elements[1].integer.value << 32);
77 77
78 - virt_addr = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB);
78 + virt_addr = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE,
79 + MEMREMAP_WB | MEMREMAP_DEC);
79 80 if (IS_ERR(virt_addr)) {
80 81 ret = PTR_ERR(virt_addr);
81 82 goto out;
82 83 }
83 84 setup_vmgenid_state(state, virt_addr);
84 85
86 + dev_set_drvdata(dev, state);
87 +
85 88 status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
86 89 vmgenid_acpi_handler, dev);
87 90 if (ACPI_FAILURE(status)) {
@@ -89,7 +92,6 @@ static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
89 92 goto out;
90 93 }
91 94
92 - dev->driver_data = state;
93 95 out:
94 96 ACPI_FREE(parsed.pointer);
95 97 return ret;
@@ -123,12 +125,13 @@ static int vmgenid_add_of(struct platform_device *pdev,
123 125 if (ret < 0)
124 126 return ret;
125 127
128 + dev_set_drvdata(&pdev->dev, state);
129 +
126 130 ret = devm_request_irq(&pdev->dev, ret, vmgenid_of_irq_handler,
127 131 IRQF_SHARED, "vmgenid", &pdev->dev);
128 132 if (ret < 0)
129 133 return ret;
130 134
131 - pdev->dev.driver_data = state;
132 135 return 0;
133 136 }
134 137
modified fs/netfs/buffered_read.c
@@ -541,6 +541,13 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
541 541
542 542 ret = netfs_wait_for_read(rreq);
543 543 if (ret >= 0) {
544 + if (ret < flen) {
545 + struct iov_iter iter;
546 +
547 + iov_iter_bvec(&iter, ITER_DEST, bvec, i, flen);
548 + iov_iter_advance(&iter, ret);
549 + iov_iter_zero(flen - ret, &iter);
550 + }
544 551 if (group)
545 552 folio_change_private(folio, group);
546 553 else
modified fs/netfs/buffered_write.c
@@ -469,6 +469,7 @@ ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *fr
469 469 struct netfs_group *netfs_group)
470 470 {
471 471 struct file *file = iocb->ki_filp;
472 + struct inode *inode = file_inode(file);
472 473 ssize_t ret;
473 474
474 475 trace_netfs_write_iter(iocb, from);
@@ -481,6 +482,14 @@ ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *fr
481 482 if (ret)
482 483 return ret;
483 484
485 + if (iocb->ki_pos > i_size_read(inode)) {
486 + ret = netfs_clear_stale_pre_isize(inode, i_size_read(inode),
487 + iocb->ki_pos,
488 + iocb->ki_flags & IOCB_NOWAIT);
489 + if (ret)
490 + return ret;
491 + }
492 +
484 493 return netfs_perform_write(iocb, from, netfs_group);
485 494 }
486 495 EXPORT_SYMBOL(netfs_buffered_write_iter_locked);
modified fs/netfs/direct_write.c
@@ -359,6 +359,15 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)
359 359 ret = file_update_time(file);
360 360 if (ret < 0)
361 361 goto out;
362 +
363 + if (iocb->ki_pos > i_size_read(inode)) {
364 + ret = netfs_clear_stale_pre_isize(inode, i_size_read(inode),
365 + iocb->ki_pos,
366 + iocb->ki_flags & IOCB_NOWAIT);
367 + if (ret < 0)
368 + goto out;
369 + }
370 +
362 371 if (iocb->ki_flags & IOCB_NOWAIT) {
363 372 /* We could block if there are any pages in the range. */
364 373 ret = -EAGAIN;
modified fs/netfs/internal.h
@@ -80,6 +80,8 @@ ssize_t netfs_wait_for_write(struct netfs_io_request *rreq);
80 80 void netfs_wait_for_paused_read(struct netfs_io_request *rreq);
81 81 void netfs_wait_for_paused_write(struct netfs_io_request *rreq);
82 82 void netfs_wait_for_put_ra_refs(struct netfs_io_request *rreq);
83 + int netfs_clear_stale_pre_isize(struct inode *inode, uoff_t from,
84 + uoff_t to, bool nowait);
83 85
84 86 /*
85 87 * objects.c
modified fs/netfs/misc.c
@@ -6,6 +6,7 @@
6 6 */
7 7
8 8 #include <linux/swap.h>
9 + #include <linux/rmap.h>
9 10 #include "internal.h"
10 11
11 12 /**
@@ -582,3 +583,101 @@ void netfs_wait_for_put_ra_refs(struct netfs_io_request *rreq)
582 583 trace_netfs_rreq(rreq, netfs_rreq_trace_waited_put_ra_refs);
583 584 finish_wait(&rreq->waitq, &myself);
584 585 }
586 +
587 + /**
588 + * netfs_clear_stale_isize - Clear stale pagecache in a to-be-created hole
589 + * @inode: The inode to act upon.
590 + * @from: The base of the hole to be made.
591 + * @to: The top of the hole to be made.
592 + * @nowait: True to return -EAGAIN rather than block.
593 + * @exclusive: True if the caller holds i_rwsem exclusively for the resize.
594 + *
595 + * Zero any data left in the pagecache within the [@from, @to) hole by a
596 + * write through an mmap so that it isn't exposed as file content once the
597 + * file is extended. Only the uptodate folio straddling @from can hold such
598 + * data as pages wholly beyond the EOF can't be faulted in, so the zeroing
599 + * is limited to that folio. The folio is zeroed rather than dropped so
600 + * that a concurrent extending write can't lose data.
601 + *
602 + * If @exclusive is false, @from is re-read from i_size and used to clamp
603 + * the zeroed range, for callers that may race with another writer also
604 + * extending the file (eg. multiple buffered writes extending the same file
605 + * under a shared i_rwsem). If @exclusive is true, for callers that hold
606 + * i_rwsem exclusively across the whole resize and have already updated
607 + * i_size to @to, staleness is decided from the folio's dirty state instead:
608 + * since no genuine concurrent buffered writer can be racing, a lockless
609 + * stat() adopting a server-confirmed size mid-resize has no data behind it
610 + * and never dirties the folio, so it can't fool this check into skipping
611 + * the zeroing the way it could fool the @exclusive false clamp.
612 + *
613 + * pagecache_isize_extended() can't be reused here: it is keyed on a
614 + * sub-page block size (a no-op when the block size is >= PAGE_SIZE, as on
615 + * network filesystems), runs after i_size is updated, can't honour
616 + * @nowait, and doesn't wait for writeback. Keep the two in sync if either
617 + * is changed.
618 + *
619 + * Return: 0 on success, or -EAGAIN if @nowait is set and the folio is
620 + * mapped or under writeback and so can't be cleaned without blocking.
621 + */
622 + static int netfs_clear_stale_isize(struct inode *inode, uoff_t from,
623 + uoff_t to, bool nowait, bool exclusive)
624 + {
625 + struct address_space *mapping = inode->i_mapping;
626 + fgf_t fgp = FGP_LOCK;
627 + struct folio *folio;
628 + int ret;
629 +
630 + if (from >= to)
631 + return 0;
632 +
633 + if (nowait)
634 + fgp |= FGP_NOWAIT;
635 +
636 + folio = __filemap_get_folio(mapping, from >> PAGE_SHIFT, fgp, 0);
637 + if (IS_ERR(folio))
638 + return PTR_ERR(folio) == -EAGAIN ? -EAGAIN : 0;
639 +
640 + ret = 0;
641 + if (nowait && (folio_mapped(folio) || folio_test_writeback(folio))) {
642 + ret = -EAGAIN;
643 + goto out;
644 + }
645 +
646 + folio_wait_writeback(folio);
647 +
648 + if (folio_mkclean(folio))
649 + folio_mark_dirty(folio);
650 +
651 + if (folio_test_uptodate(folio) &&
652 + (!exclusive || folio_test_dirty(folio))) {
653 + uoff_t fpos = folio_pos(folio);
654 +
655 + if (!exclusive)
656 + from = umax(from, i_size_read(inode));
657 + if (from < to && from < fpos + folio_size(folio)) {
658 + size_t end = umin(to - fpos, folio_size(folio));
659 + size_t offset = from - fpos;
660 +
661 + folio_zero_segment(folio, offset, end);
662 + }
663 + }
664 + out:
665 + folio_unlock(folio);
666 + folio_put(folio);
667 + return ret;
668 + }
669 +
670 + /* Clear stale pagecache before an extending buffered/DIO write. */
671 + int netfs_clear_stale_pre_isize(struct inode *inode, uoff_t from,
672 + uoff_t to, bool nowait)
673 + {
674 + return netfs_clear_stale_isize(inode, from, to, nowait, false);
675 + }
676 +
677 + /* Clear stale pagecache when extending a file under an exclusive resize. */
678 + void netfs_clear_stale_post_isize(struct inode *inode, uoff_t from,
679 + uoff_t to)
680 + {
681 + netfs_clear_stale_isize(inode, from, to, false, true);
682 + }
683 + EXPORT_SYMBOL(netfs_clear_stale_post_isize);
modified fs/netfs/read_collect.c
@@ -33,6 +33,22 @@ static void netfs_clear_unread(struct netfs_io_subrequest *subreq)
33 33 __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
34 34 }
35 35
36 + static void netfs_clear_unread_dio(struct netfs_io_subrequest *subreq)
37 + {
38 + uoff_t pos = subreq->start + subreq->transferred;
39 + struct netfs_io_request *rreq = subreq->rreq;
40 + size_t fill;
41 +
42 + if (pos >= rreq->i_size)
43 + return;
44 +
45 + fill = min_t(uoff_t, rreq->i_size - pos,
46 + subreq->len - subreq->transferred);
47 +
48 + netfs_reset_iter(subreq);
49 + subreq->transferred += iov_iter_zero(fill, &subreq->io_iter);
50 + }
51 +
36 52 /*
37 53 * Cancel the copy-to-cache mark on a folio.
38 54 */
@@ -311,6 +327,14 @@ reassess:
311 327 test_bit(NETFS_SREQ_HIT_EOF, &front->flags))
312 328 netfs_read_unlock_folios(rreq, &notes);
313 329 } else {
330 + if (!(notes & HIT_PENDING) &&
331 + front->error == 0 &&
332 + transferred < front->len &&
333 + test_bit(NETFS_SREQ_CLEAR_TAIL, &front->flags)) {
334 + netfs_clear_unread_dio(front);
335 + transferred = front->transferred;
336 + trace_netfs_sreq(front, netfs_sreq_trace_clear);
337 + }
314 338 stream->collected_to = front->start + transferred;
315 339 rreq->collected_to = stream->collected_to;
316 340 }
modified fs/smb/client/cifsfs.c
@@ -1412,6 +1412,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1412 1412 * server could even support copy of range where source = target
1413 1413 */
1414 1414 lock_two_nondirectories(target_inode, src_inode);
1415 + filemap_invalidate_lock(target_inode->i_mapping);
1415 1416
1416 1417 if (len == 0) {
1417 1418 loff_t src_size = i_size_read(src_inode);
@@ -1467,9 +1468,15 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1467 1468 i_size = target_inode->i_size;
1468 1469 spin_unlock(&target_inode->i_lock);
1469 1470
1470 - /* Discard all the folios that overlap the destination region. */
1471 + /*
1472 + * Discard all the folios that overlap the destination region. Start at
1473 + * the old EOF when extending so the folio straddling it, which may hold
1474 + * data written past EOF through an mmap, is dropped too.
1475 + */
1471 1476 cifs_dbg(FYI, "about to discard pages %llx-%llx\n", fstart, fend);
1472 - truncate_inode_pages_range(&target_inode->i_data, fstart, fend);
1477 + truncate_inode_pages_range(&target_inode->i_data,
1478 + min(fstart, i_size), fend);
1479 + netfs_wait_for_outstanding_io(target_inode);
1473 1480
1474 1481 fscache_invalidate(cifs_inode_cookie(target_inode), NULL, i_size, 0);
1475 1482
@@ -1508,6 +1515,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
1508 1515 if (rc)
1509 1516 CIFS_I(target_inode)->time = 0;
1510 1517 unlock:
1518 + filemap_invalidate_unlock(target_inode->i_mapping);
1511 1519 /* although unlocking in the reverse order from locking is not
1512 1520 strictly necessary here it is a little cleaner to be consistent */
1513 1521 unlock_two_nondirectories(src_inode, target_inode);
@@ -1531,6 +1539,9 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
1531 1539 struct cifs_tcon *target_tcon;
1532 1540 ssize_t rc;
1533 1541
1542 + if (len == 0)
1543 + return 0;
1544 +
1534 1545 cifs_dbg(FYI, "copychunk range\n");
1535 1546
1536 1547 if (!src_file->private_data || !dst_file->private_data) {
@@ -1560,6 +1571,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
1560 1571 * server could even support copy of range where source = target
1561 1572 */
1562 1573 lock_two_nondirectories(target_inode, src_inode);
1574 + filemap_invalidate_lock(target_inode->i_mapping);
1563 1575
1564 1576 cifs_dbg(FYI, "about to flush pages\n");
1565 1577
@@ -1581,10 +1593,28 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
1581 1593 /* Flush and invalidate all the folios in the destination region. If
1582 1594 * the copy was successful, then some of the flush is extra overhead,
1583 1595 * but we need to allow for the copy failing in some way (eg. ENOSPC).
1596 + *
1597 + * Start at the old EOF when extending so the folio straddling it, which
1598 + * may hold data written past EOF through an mmap, is dropped too.
1584 1599 */
1585 - rc = filemap_invalidate_inode(target_inode, true, destoff, destoff + len - 1);
1586 - if (rc)
1587 - goto unlock;
1600 + if (target_inode->i_mapping->nrpages) {
1601 + loff_t fstart = min(destoff, i_size_read(target_inode));
1602 + loff_t fend = destoff + len - 1;
1603 +
1604 + unmap_mapping_pages(target_inode->i_mapping,
1605 + fstart >> PAGE_SHIFT,
1606 + (fend >> PAGE_SHIFT) -
1607 + (fstart >> PAGE_SHIFT) + 1,
1608 + false);
1609 + rc = filemap_write_and_wait_range(target_inode->i_mapping,
1610 + fstart, fend);
1611 + if (rc)
1612 + goto unlock;
1613 + invalidate_inode_pages2_range(target_inode->i_mapping,
1614 + fstart >> PAGE_SHIFT,
1615 + fend >> PAGE_SHIFT);
1616 + }
1617 + netfs_wait_for_outstanding_io(target_inode);
1588 1618
1589 1619 fscache_invalidate(cifs_inode_cookie(target_inode), NULL,
1590 1620 i_size_read(target_inode), 0);
@@ -1616,6 +1646,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
1616 1646 CIFS_I(target_inode)->time = 0;
1617 1647
1618 1648 unlock:
1649 + filemap_invalidate_unlock(target_inode->i_mapping);
1619 1650 /* although unlocking in the reverse order from locking is not
1620 1651 * strictly necessary here it is a little cleaner to be consistent
1621 1652 */
modified fs/smb/client/cifsfs.h
@@ -146,8 +146,9 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct file *src_file,
146 146 unsigned int flags);
147 147
148 148 long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg);
149 - void cifs_setsize(struct inode *inode, loff_t offset);
150 - void cifs_resize_file_locked(struct inode *inode, loff_t offset);
149 + void cifs_setsize(struct inode *inode, loff_t old_size, loff_t offset);
150 + void cifs_resize_file_locked(struct inode *inode, loff_t old_size,
151 + loff_t offset);
151 152
152 153 struct fs_context;
153 154 struct smb3_fs_context;
modified fs/smb/client/cifsglob.h
@@ -1450,11 +1450,11 @@ struct cifsFileInfo {
1450 1450 struct dentry *dentry;
1451 1451 struct tcon_link *tlink;
1452 1452 unsigned int f_flags;
1453 - bool invalidHandle:1; /* file closed via session abend */
1454 - bool swapfile:1;
1455 - bool oplock_break_cancelled:1;
1456 - bool status_file_deleted:1; /* file has been deleted */
1457 - bool offload:1; /* offload final part of _put to a wq */
1453 + bool invalidHandle; /* file closed via session abend */
1454 + bool swapfile;
1455 + bool oplock_break_cancelled;
1456 + bool status_file_deleted; /* file has been deleted */
1457 + bool offload; /* offload final part of _put to a wq */
1458 1458 __u16 oplock_epoch; /* epoch from the lease break */
1459 1459 __u32 oplock_level; /* oplock/lease level from the lease break */
1460 1460 int count;
modified fs/smb/client/file.c
@@ -1012,11 +1012,14 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
1012 1012 }
1013 1013 mapping_set_error(inode->i_mapping, rc);
1014 1014
1015 + netfs_wait_for_outstanding_io(inode);
1016 +
1015 1017 cfile = find_writable_file(cinode, FIND_FSUID_ONLY);
1016 1018 rc = cifs_file_flush(xid, inode, cfile);
1017 1019 if (!rc) {
1018 1020 if (cfile) {
1019 1021 struct netfs_inode *ictx = netfs_inode(inode);
1022 + loff_t old_size = i_size_read(inode);
1020 1023
1021 1024 tcon = tlink_tcon(cfile->tlink);
1022 1025 server = tcon->ses->server;
@@ -1025,7 +1028,7 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
1025 1028 cfile, 0, false);
1026 1029 if (!rc) {
1027 1030 netfs_resize_file(&cinode->netfs, 0, true);
1028 - cifs_setsize(inode, 0);
1031 + cifs_setsize(inode, old_size, 0);
1029 1032 cifs_invalidate_cache(inode, 0);
1030 1033 }
1031 1034 netfs_wb_end(ictx);
modified fs/smb/client/inode.c
@@ -88,6 +88,8 @@ static void cifs_set_ops(struct inode *inode)
88 88 else
89 89 inode->i_data.a_ops = &cifs_addr_ops;
90 90 mapping_set_large_folios(inode->i_mapping);
91 + if (tcon->ses->server->sign)
92 + mapping_set_stable_writes(inode->i_mapping);
91 93 break;
92 94 case S_IFDIR:
93 95 if (IS_AUTOMOUNT(inode)) {
@@ -3053,15 +3055,12 @@ int cifs_fiemap(struct inode *inode, struct fiemap_extent_info *fei, u64 start,
3053 3055 return -EOPNOTSUPP;
3054 3056 }
3055 3057
3056 - void cifs_setsize(struct inode *inode, loff_t offset)
3058 + void cifs_setsize(struct inode *inode, loff_t old_size, loff_t offset)
3057 3059 {
3058 - loff_t old_size;
3059 3060 u64 blocks = CIFS_INO_BLOCKS(offset);
3060 3061
3061 3062 spin_lock(&inode->i_lock);
3062 - old_size = i_size_read(inode);
3063 3063 i_size_write(inode, offset);
3064 -
3065 3064 /*
3066 3065 * Extending EOF does not allocate the intervening range. Only clamp
3067 3066 * i_blocks on shrink; allocation growth comes from writes or from the
@@ -3071,20 +3070,28 @@ void cifs_setsize(struct inode *inode, loff_t offset)
3071 3070 inode->i_blocks = blocks;
3072 3071 spin_unlock(&inode->i_lock);
3073 3072 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
3073 +
3074 + /*
3075 + * Zero the tail of the folio straddling the old EOF so data dirtied
3076 + * past EOF through an mmap isn't exposed. truncate_pagecache() then
3077 + * drops any pagecache beyond the new EOF, as in truncate_setsize().
3078 + */
3074 3079 if (offset > old_size)
3075 - pagecache_isize_extended(inode, old_size, offset);
3080 + netfs_clear_stale_post_isize(inode, old_size, offset);
3081 +
3076 3082 truncate_pagecache(inode, offset);
3077 3083 netfs_wait_for_outstanding_io(inode);
3078 3084 }
3079 3085
3080 - void cifs_resize_file_locked(struct inode *inode, loff_t offset)
3086 + void cifs_resize_file_locked(struct inode *inode, loff_t old_size,
3087 + loff_t offset)
3081 3088 {
3082 3089 struct fscache_cookie *cookie = cifs_inode_cookie(inode);
3083 3090
3084 3091 lockdep_assert_held_write(&inode->i_rwsem);
3085 3092
3086 3093 netfs_resize_file(netfs_inode(inode), offset, true);
3087 - cifs_setsize(inode, offset);
3094 + cifs_setsize(inode, old_size, offset);
3088 3095
3089 3096 if (!cookie)
3090 3097 return;
@@ -3101,6 +3108,7 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,
3101 3108 struct inode *inode = d_inode(dentry);
3102 3109 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3103 3110 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
3111 + loff_t old_size = i_size_read(inode);
3104 3112 struct tcon_link *tlink = NULL;
3105 3113 struct cifs_tcon *tcon = NULL;
3106 3114 struct TCP_Server_Info *server;
@@ -3159,7 +3167,7 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,
3159 3167
3160 3168 set_size_out:
3161 3169 if (rc == 0)
3162 - cifs_resize_file_locked(inode, size);
3170 + cifs_resize_file_locked(inode, old_size, size);
3163 3171
3164 3172 return rc;
3165 3173 }
modified fs/smb/client/smb2ops.c
@@ -2287,6 +2287,7 @@ smb2_duplicate_extents(const unsigned int xid,
2287 2287 struct duplicate_extents_to_file dup_ext_buf;
2288 2288 struct timespec64 ts;
2289 2289 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2290 + loff_t old_size;
2290 2291 u64 asize;
2291 2292
2292 2293 /* server fileays advertise duplicate extent support with this flag */
@@ -2305,11 +2306,12 @@ smb2_duplicate_extents(const unsigned int xid,
2305 2306 trgtfile->fid.volatile_fid, tcon->tid,
2306 2307 tcon->ses->Suid, src_off, dest_off, len);
2307 2308 inode = d_inode(trgtfile->dentry);
2308 - if (i_size_read(inode) < dest_off + len) {
2309 + old_size = i_size_read(inode);
2310 + if (old_size < dest_off + len) {
2309 2311 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2310 2312 if (rc)
2311 2313 goto duplicate_extents_out;
2312 - cifs_resize_file_locked(inode, dest_off + len);
2314 + cifs_resize_file_locked(inode, old_size, dest_off + len);
2313 2315 }
2314 2316 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2315 2317 trgtfile->fid.volatile_fid,
@@ -3520,6 +3522,21 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3520 3522 0, NULL, NULL);
3521 3523 }
3522 3524
3525 + static long query_server_eof(const unsigned int xid,
3526 + struct cifs_tcon *tcon,
3527 + struct cifsFileInfo *cfile,
3528 + unsigned long long *eof)
3529 + {
3530 + struct smb2_file_all_info file_inf = {};
3531 + long rc;
3532 +
3533 + rc = SMB2_query_info(xid, tcon, cfile->fid.persistent_fid,
3534 + cfile->fid.volatile_fid, &file_inf);
3535 + if (!rc)
3536 + *eof = le64_to_cpu(file_inf.EndOfFile);
3537 + return rc;
3538 + }
3539 +
3523 3540 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3524 3541 unsigned long long offset, unsigned long long len,
3525 3542 bool keep_size)
@@ -3547,25 +3564,32 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3547 3564 filemap_invalidate_lock(inode->i_mapping);
3548 3565
3549 3566 netfs_read_sizes(inode, &i_size, &remote_i_size, &zero_point);
3550 - if (offset + len >= remote_i_size && offset < i_size) {
3551 - unsigned long long top = umin(offset + len, i_size);
3552 3567
3553 - rc = filemap_write_and_wait_range(inode->i_mapping, offset, top - 1);
3554 - if (rc < 0)
3555 - goto zero_range_exit;
3556 - }
3568 + rc = filemap_write_and_wait_range(inode->i_mapping, offset,
3569 + offset + len - 1);
3570 + if (rc < 0)
3571 + goto zero_range_exit;
3557 3572
3558 3573 /*
3559 3574 * We zero the range through ioctl, so we need remove the page caches
3560 3575 * first, otherwise the data may be inconsistent with the server.
3576 + *
3577 + * Start at the old EOF when extending so the folio straddling it, which
3578 + * may hold data written past EOF through an mmap, is dropped too.
3561 3579 */
3562 - truncate_pagecache_range(inode, offset, offset + len - 1);
3580 + truncate_pagecache_range(inode, min(offset, i_size), offset + len - 1);
3563 3581 netfs_wait_for_outstanding_io(inode);
3564 3582
3565 - /* if file not oplocked can't be sure whether asking to extend size */
3566 - rc = -EOPNOTSUPP;
3567 - if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3568 - goto zero_range_exit;
3583 + if (!keep_size && !CIFS_CACHE_READ(cifsi)) {
3584 + rc = query_server_eof(xid, tcon, cfile, &remote_i_size);
3585 + if (rc)
3586 + goto zero_range_exit;
3587 + i_size = max(i_size, remote_i_size);
3588 + if (i_size < new_size) {
3589 + rc = -EOPNOTSUPP;
3590 + goto zero_range_exit;
3591 + }
3592 + }
3569 3593
3570 3594 fscache_invalidate(cifs_inode_cookie(inode), NULL,
3571 3595 i_size_read(inode), 0);
@@ -3577,7 +3601,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3577 3601 /*
3578 3602 * do we also need to change the size of the file?
3579 3603 */
3580 - if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) {
3604 + if (!keep_size && umax(i_size, i_size_read(inode)) < new_size) {
3581 3605 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3582 3606 cfile->fid.volatile_fid, cfile->pid, new_size);
3583 3607 if (rc >= 0) {
@@ -3723,7 +3747,8 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
3723 3747 static int smb3_simple_fallocate_range(unsigned int xid,
3724 3748 struct cifs_tcon *tcon,
3725 3749 struct cifsFileInfo *cfile,
3726 - loff_t off, loff_t len)
3750 + loff_t off, loff_t len,
3751 + loff_t old_eof)
3727 3752 {
3728 3753 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3729 3754 struct inode *inode = d_inode(cfile->dentry);
@@ -3739,12 +3764,30 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3739 3764 goto out;
3740 3765 }
3741 3766
3742 - if (off >= i_size_read(inode)) {
3767 + if (off >= old_eof) {
3743 3768 rc = smb3_simple_fallocate_write_range(xid, tcon, cfile,
3744 3769 off, len, buf);
3745 3770 goto out;
3746 3771 }
3747 3772
3773 + filemap_invalidate_lock(inode->i_mapping);
3774 +
3775 + /*
3776 + * Flush and commit the data to the server, otherwise
3777 + * FSCTL_QUERY_ALLOCATED_RANGES might report recently written data as
3778 + * unallocated holes on Windows Servers, and the loop below would
3779 + * then zero-fill them and corrupt the file.
3780 + */
3781 + rc = filemap_write_and_wait_range(inode->i_mapping, off,
3782 + off + len - 1);
3783 + if (rc)
3784 + goto out_unlock;
3785 + netfs_wait_for_outstanding_io(inode);
3786 + rc = SMB2_flush(xid, tcon, cfile->fid.persistent_fid,
3787 + cfile->fid.volatile_fid);
3788 + if (rc)
3789 + goto out_unlock;
3790 +
3748 3791 in_data.file_offset = cpu_to_le64(off);
3749 3792 in_data.length = cpu_to_le64(len);
3750 3793 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
@@ -3754,7 +3797,7 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3754 3797 1024 * sizeof(struct file_allocated_range_buffer),
3755 3798 (char **)&out_data, &out_data_len);
3756 3799 if (rc)
3757 - goto out;
3800 + goto out_unlock;
3758 3801
3759 3802 tmp_data = out_data;
3760 3803 while (len) {
@@ -3764,12 +3807,12 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3764 3807 if (out_data_len == 0) {
3765 3808 rc = smb3_simple_fallocate_write_range(xid, tcon,
3766 3809 cfile, off, len, buf);
3767 - goto out;
3810 + goto out_unlock;
3768 3811 }
3769 3812
3770 3813 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3771 3814 rc = -EINVAL;
3772 - goto out;
3815 + goto out_unlock;
3773 3816 }
3774 3817
3775 3818 range_start = le64_to_cpu(tmp_data->file_offset);
@@ -3777,7 +3820,7 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3777 3820 if (check_add_overflow(range_start, range_len, &range_end) ||
3778 3821 range_end > S64_MAX) {
3779 3822 rc = -EINVAL;
3780 - goto out;
3823 + goto out_unlock;
3781 3824 }
3782 3825
3783 3826 if (off < range_start) {
@@ -3792,11 +3835,11 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3792 3835 rc = smb3_simple_fallocate_write_range(xid, tcon,
3793 3836 cfile, off, l, buf);
3794 3837 if (rc)
3795 - goto out;
3838 + goto out_unlock;
3796 3839 off = off + l;
3797 3840 len = len - l;
3798 3841 if (len == 0)
3799 - goto out;
3842 + goto out_unlock;
3800 3843 }
3801 3844 /*
3802 3845 * We are at a section of allocated data, just skip forward
@@ -3815,6 +3858,8 @@ static int smb3_simple_fallocate_range(unsigned int xid,
3815 3858 out_data_len -= sizeof(struct file_allocated_range_buffer);
3816 3859 }
3817 3860
3861 + out_unlock:
3862 + filemap_invalidate_unlock(inode->i_mapping);
3818 3863 out:
3819 3864 kfree(out_data);
3820 3865 kvfree(buf);
@@ -3830,7 +3875,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3830 3875 struct cifsFileInfo *cfile = file->private_data;
3831 3876 long rc = -EOPNOTSUPP;
3832 3877 unsigned int xid;
3833 - loff_t old_eof, new_eof;
3878 + loff_t old_eof, new_eof, local_eof;
3834 3879 struct smb2_file_all_info file_inf;
3835 3880 u64 asize;
3836 3881 int qrc;
@@ -3839,18 +3884,37 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3839 3884
3840 3885 inode = d_inode(cfile->dentry);
3841 3886 cifsi = CIFS_I(inode);
3842 - old_eof = i_size_read(inode);
3887 + old_eof = local_eof = i_size_read(inode);
3843 3888
3844 3889 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3845 3890 tcon->ses->Suid, off, len);
3846 - /* if file not oplocked can't be sure whether asking to extend size */
3847 - if (!CIFS_CACHE_READ(cifsi))
3848 - if (!keep_size) {
3891 +
3892 + if (!keep_size && !CIFS_CACHE_READ(cifsi)) {
3893 + unsigned long long server_eof;
3894 +
3895 + rc = filemap_write_and_wait(inode->i_mapping);
3896 + if (rc) {
3849 3897 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3850 3898 tcon->tid, tcon->ses->Suid, off, len, rc);
3851 3899 free_xid(xid);
3852 3900 return rc;
3853 3901 }
3902 + netfs_wait_for_outstanding_io(inode);
3903 +
3904 + rc = query_server_eof(xid, tcon, cfile, &server_eof);
3905 + if (rc) {
3906 + trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3907 + tcon->tid, tcon->ses->Suid, off, len, rc);
3908 + free_xid(xid);
3909 + return rc;
3910 + }
3911 + /*
3912 + * Only use the larger EOF to decide whether we're extending.
3913 + * The pagecache zeroing below must still key off the local
3914 + * i_size, so keep local_eof for that.
3915 + */
3916 + old_eof = max_t(loff_t, old_eof, server_eof);
3917 + }
3854 3918
3855 3919 /*
3856 3920 * Extending the file
@@ -3874,7 +3938,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3874 3938 }
3875 3939
3876 3940 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3877 - off, len);
3941 + off, len, old_eof);
3878 3942 if (rc) {
3879 3943 spin_lock(&inode->i_lock);
3880 3944 cifsi->time = 0;
@@ -3883,7 +3947,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3883 3947 }
3884 3948
3885 3949 new_eof = off + len;
3886 - cifs_resize_file_locked(inode, new_eof);
3950 + cifs_resize_file_locked(inode, local_eof, new_eof);
3887 3951
3888 3952 qrc = SMB2_query_info(xid, tcon,
3889 3953 cfile->fid.persistent_fid,
@@ -3931,7 +3995,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3931 3995 if (rc)
3932 3996 goto out;
3933 3997
3934 - cifs_resize_file_locked(inode, new_eof);
3998 + cifs_resize_file_locked(inode, local_eof, new_eof);
3935 3999
3936 4000 qrc = SMB2_query_info(xid, tcon,
3937 4001 cfile->fid.persistent_fid,
@@ -3976,7 +4040,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3976 4040 }
3977 4041 }
3978 4042
3979 - if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
4043 + if (keep_size || old_eof >= off + len) {
3980 4044 /*
3981 4045 * At this point, we are trying to fallocate an internal
3982 4046 * regions of a sparse file. Since smb2 does not have a
@@ -3993,7 +4057,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3993 4057 */
3994 4058 if (len <= 1024 * 1024) {
3995 4059 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3996 - off, len);
4060 + off, len, old_eof);
3997 4061 goto out;
3998 4062 }
3999 4063
@@ -4005,7 +4069,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
4005 4069 * ie potentially making a few extra pages at the beginning
4006 4070 * or end of the file non-sparse via set_sparse is harmless.
4007 4071 */
4008 - if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
4072 + if (off > 8192 || off + len + 8192 < old_eof) {
4009 4073 rc = -EOPNOTSUPP;
4010 4074 goto out;
4011 4075 }
modified fs/smb/client/smb2pdu.c
@@ -4796,14 +4796,20 @@ do_retry:
4796 4796 rdata->got_bytes);
4797 4797
4798 4798 if (rdata->result == -ENODATA) {
4799 - __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
4800 4799 rdata->result = 0;
4800 + if (rdata->subreq.start + rdata->subreq.transferred >= i_size_read(inode))
4801 + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
4802 + else
4803 + __set_bit(NETFS_SREQ_CLEAR_TAIL, &rdata->subreq.flags);
4801 4804 } else {
4802 4805 size_t trans = rdata->subreq.transferred + rdata->got_bytes;
4803 4806 if (trans < rdata->subreq.len &&
4804 4807 rdata->subreq.start + trans >= netfs_read_remote_i_size(inode)) {
4805 - __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
4806 4808 rdata->result = 0;
4809 + if (rdata->subreq.start + trans >= i_size_read(inode))
4810 + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags);
4811 + else
4812 + __set_bit(NETFS_SREQ_CLEAR_TAIL, &rdata->subreq.flags);
4807 4813 }
4808 4814 if (rdata->got_bytes)
4809 4815 __set_bit(NETFS_SREQ_MADE_PROGRESS, &rdata->subreq.flags);
modified include/linux/bpf.h
@@ -1258,11 +1258,15 @@ struct btf_func_model {
1258 1258 #define BPF_TRAMP_F_INDIRECT BIT(8)
1259 1259
1260 1260 /* Each call __bpf_prog_enter + call bpf_func + call __bpf_prog_exit is ~50
1261 - * bytes on x86.
1261 + * bytes on x86. The trampoline image has to fit in PAGE_SIZE.
1262 1262 */
1263 1263 enum {
1264 - #if defined(__s390x__)
1264 + #if defined(__s390x__) || defined(__powerpc64__)
1265 1265 BPF_MAX_TRAMP_LINKS = 27,
1266 + #elif defined(__x86_64__)
1267 + BPF_MAX_TRAMP_LINKS = 36,
1268 + #elif defined(__aarch64__)
1269 + BPF_MAX_TRAMP_LINKS = 37,
1266 1270 #else
1267 1271 BPF_MAX_TRAMP_LINKS = 38,
1268 1272 #endif
@@ -1315,6 +1319,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image, void *i
1315 1319 void *arch_alloc_bpf_trampoline(unsigned int size);
1316 1320 void arch_free_bpf_trampoline(void *image, unsigned int size);
1317 1321 int __must_check arch_protect_bpf_trampoline(void *image, unsigned int size);
1322 + int arch_bpf_trampoline_skip(void *nop, void *target);
1318 1323 int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
1319 1324 struct bpf_tramp_nodes *tnodes, void *func_addr);
1320 1325
@@ -1363,19 +1368,48 @@ enum bpf_tramp_prog_type {
1363 1368 BPF_TRAMP_FSESSION,
1364 1369 };
1365 1370
1371 + /*
1372 + * Each prog call in a trampoline image is preceded by a nop. When the prog is
1373 + * detached, the nop is patched to a jump to target, right after the call, so
1374 + * that tasks still running in the image skip the prog.
1375 + */
1376 + struct bpf_tramp_skip {
1377 + struct bpf_prog *prog;
1378 + void *nop;
1379 + void *target;
1380 + };
1381 +
1366 1382 struct bpf_tramp_image {
1367 1383 void *image;
1368 1384 int size;
1369 1385 struct bpf_ksym ksym;
1370 1386 struct percpu_ref pcref;
1371 - void *ip_after_call;
1372 - void *ip_epilogue;
1387 + bool call_orig;
1388 + /* entry in tr->images, the image holds a reference on tr */
1389 + struct bpf_trampoline *tr;
1390 + struct list_head list;
1391 + int nr_skips;
1392 + struct bpf_tramp_skip *skips;
1373 1393 union {
1374 1394 struct rcu_head rcu;
1375 1395 struct work_struct work;
1376 1396 };
1377 1397 };
1378 1398
1399 + static inline void bpf_tramp_image_add_skip(struct bpf_tramp_image *im, struct bpf_prog *prog,
1400 + void *nop, void *target)
1401 + {
1402 + struct bpf_tramp_skip *skip;
1403 +
1404 + /* struct_ops trampolines and arch_bpf_trampoline_size() have no image */
1405 + if (!im || !im->skips)
1406 + return;
1407 + skip = &im->skips[im->nr_skips++];
1408 + skip->prog = prog;
1409 + skip->nop = nop;
1410 + skip->target = target;
1411 + }
1412 +
1379 1413 struct bpf_trampoline {
1380 1414 /* hlist for trampoline_key_table */
1381 1415 struct hlist_node hlist_key;
@@ -1402,6 +1436,8 @@ struct bpf_trampoline {
1402 1436 int progs_cnt[BPF_TRAMP_MAX];
1403 1437 /* Executable image of trampoline */
1404 1438 struct bpf_tramp_image *cur_image;
1439 + /* Images not freed yet, cur_image and older ones still in use */
1440 + struct list_head images;
1405 1441 /* Used as temporary old image storage for multi_attach */
1406 1442 struct {
1407 1443 struct bpf_tramp_image *old_image;
@@ -1770,6 +1806,7 @@ struct bpf_prog_aux {
1770 1806 bool offload_requested; /* Program is bound and offloaded to the netdev. */
1771 1807 bool attach_btf_trace; /* true if attaching to BTF-enabled raw tp */
1772 1808 bool attach_tracing_prog; /* true if tracing another tracing program */
1809 + bool tramp_linked; /* true if it was ever linked to a trampoline */
1773 1810 bool func_proto_unreliable;
1774 1811 bool tail_call_reachable;
1775 1812 bool xdp_has_frags;
modified include/linux/cpufreq.h
@@ -420,6 +420,9 @@ struct cpufreq_driver {
420 420 /* Will be called after the driver is fully initialized */
421 421 void (*ready)(struct cpufreq_policy *policy);
422 422
423 + /* Return the capacity reference frequency for policy. */
424 + unsigned int (*scale_freq_ref)(struct cpufreq_policy *policy);
425 +
423 426 struct freq_attr **attr;
424 427
425 428 /* platform specific boost support code */
modified include/linux/hrtimer_rearm.h
@@ -45,7 +45,7 @@ hrtimer_rearm_deferred_user_irq(unsigned long *tif_work, const unsigned long tif
45 45 clear_thread_flag(TIF_HRTIMER_REARM);
46 46 __hrtimer_rearm_deferred();
47 47 /* Don't go into the loop if HRTIMER_REARM was the only flag */
48 - *tif_work &= ~TIF_HRTIMER_REARM;
48 + *tif_work &= ~_TIF_HRTIMER_REARM;
49 49 return !*tif_work;
50 50 }
51 51 return false;
modified include/linux/kvm_host.h
@@ -791,7 +791,6 @@ struct kvm {
791 791 /* The current active memslot set for each address space */
792 792 struct kvm_memslots __rcu *memslots[KVM_MAX_NR_ADDRESS_SPACES];
793 793 struct xarray vcpu_array;
794 - DECLARE_BITMAP(vcpu_ids, KVM_MAX_VCPU_IDS);
795 794 /*
796 795 * Protected by slots_lock, but can be read outside if an
797 796 * incorrect answer is acceptable.
modified include/linux/mtd/nand.h
@@ -305,6 +305,8 @@ int nand_ecc_prepare_io_req(struct nand_device *nand,
305 305 struct nand_page_io_req *req);
306 306 int nand_ecc_finish_io_req(struct nand_device *nand,
307 307 struct nand_page_io_req *req);
308 + bool nand_ecc_is_pipelined(const struct nand_device *nand);
309 +
308 310 bool nand_ecc_is_strong_enough(struct nand_device *nand);
309 311
310 312 #if IS_REACHABLE(CONFIG_MTD_NAND_CORE)
modified include/linux/netdevice.h
@@ -887,6 +887,7 @@ enum net_device_path_type {
887 887 DEV_PATH_DSA,
888 888 DEV_PATH_MTK_WDMA,
889 889 DEV_PATH_TUN,
890 + DEV_PATH_IEEE80211,
890 891 };
891 892
892 893 struct net_device_path {
@@ -953,6 +954,8 @@ struct net_device_path_ctx {
953 954 u16 id;
954 955 __be16 proto;
955 956 } vlan[NET_DEVICE_PATH_VLAN_MAX];
957 +
958 + bool ieee80211;
956 959 };
957 960
958 961 enum tc_setup_type {
modified include/linux/netfilter_netdev.h
@@ -133,7 +133,7 @@ static inline struct sk_buff *nf_hook_egress(struct sk_buff *skb, int *rc,
133 133
134 134 static inline void nf_skip_egress(struct sk_buff *skb, bool skip)
135 135 {
136 - #ifdef CONFIG_NETFILTER_SKIP_EGRESS
136 + #ifdef CONFIG_NET_EGRESS
137 137 skb->nf_skip_egress = skip;
138 138 #endif
139 139 }
modified include/linux/netfs.h
@@ -397,6 +397,8 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from);
397 397 ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
398 398 struct netfs_group *netfs_group);
399 399 ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from);
400 + void netfs_clear_stale_post_isize(struct inode *inode, uoff_t from,
401 + uoff_t to);
400 402
401 403 /* Single, monolithic object read/write API. */
402 404 void netfs_single_mark_inode_dirty(struct inode *inode);
modified include/linux/perf_event.h
@@ -1506,9 +1506,10 @@ is_default_overflow_handler(struct perf_event *event)
1506 1506 }
1507 1507
1508 1508 extern void
1509 - perf_event_header__init_id(struct perf_event_header *header,
1510 - struct perf_sample_data *data,
1511 - struct perf_event *event);
1509 + perf_event_header__init(struct perf_event_header *header,
1510 + struct perf_sample_data *data,
1511 + u32 type, u16 misc, u16 size,
1512 + struct perf_event *event);
1512 1513 extern void
1513 1514 perf_event__output_id_sample(struct perf_event *event,
1514 1515 struct perf_output_handle *handle,
modified include/linux/rtnetlink.h
@@ -186,7 +186,12 @@ void net_dec_ingress_queue(void);
186 186 #ifdef CONFIG_NET_EGRESS
187 187 void net_inc_egress_queue(void);
188 188 void net_dec_egress_queue(void);
189 - void netdev_xmit_skip_txqueue(bool skip);
189 + bool netdev_xmit_skip_txqueue(bool skip);
190 + #else
191 + static inline bool netdev_xmit_skip_txqueue(bool skip)
192 + {
193 + return false;
194 + }
190 195 #endif
191 196
192 197 void rtnetlink_init(void);
modified include/linux/siphash.h
@@ -75,8 +75,10 @@ static inline u64 ___siphash_aligned(const __le64 *data, size_t len,
75 75 /**
76 76 * siphash - compute 64-bit siphash PRF value
77 77 * @data: buffer to hash
78 - * @size: size of @data
78 + * @len: size of @data
79 79 * @key: the siphash key
80 + *
81 + * Returns: siphash PRF value
80 82 */
81 83 static inline u64 siphash(const void *data, size_t len,
82 84 const siphash_key_t *key)
@@ -125,8 +127,10 @@ static inline u32 ___hsiphash_aligned(const __le32 *data, size_t len,
125 127 /**
126 128 * hsiphash - compute 32-bit hsiphash PRF value
127 129 * @data: buffer to hash
128 - * @size: size of @data
130 + * @len: size of @data
129 131 * @key: the hsiphash key
132 + *
133 + * Returns: hsiphash PRF value
130 134 */
131 135 static inline u32 hsiphash(const void *data, size_t len,
132 136 const hsiphash_key_t *key)
modified include/linux/skbuff.h
@@ -1020,7 +1020,7 @@ struct sk_buff {
1020 1020 #ifdef CONFIG_NET_REDIRECT
1021 1021 __u8 from_ingress:1;
1022 1022 #endif
1023 - #ifdef CONFIG_NETFILTER_SKIP_EGRESS
1023 + #ifdef CONFIG_NET_EGRESS
1024 1024 __u8 nf_skip_egress:1;
1025 1025 #endif
1026 1026 #ifdef CONFIG_SKB_DECRYPTED
modified include/linux/soc/qcom/geni-se.h
@@ -347,17 +347,12 @@ struct geni_se {
347 347 #define QUP_SE_VERSION_2_5 0x20050000
348 348
349 349 /*
350 - * Define bandwidth thresholds that cause the underlying Core 2X interconnect
351 - * clock to run at the named frequency. These baseline values are recommended
352 - * by the hardware team, and are not dynamically scaled with GENI bandwidth
353 - * beyond basic on/off.
350 + * QUP Core 2X clock votes used by GENI clients through the "qup-core" ICC
351 + * path. Values are in Bps and must be converted with Bps_to_icc() before
352 + * setting avg_bw.
354 353 */
355 - #define CORE_2X_19_2_MHZ 960
356 - #define CORE_2X_50_MHZ 2500
357 - #define CORE_2X_100_MHZ 5000
358 - #define CORE_2X_150_MHZ 7500
359 - #define CORE_2X_200_MHZ 10000
360 - #define CORE_2X_236_MHZ 16383
354 + #define CORE_2X_19_2_MHZ 9600000
355 + #define CORE_2X_50_MHZ 25000000
361 356
362 357 #define GENI_DEFAULT_BW Bps_to_icc(1000)
363 358
modified include/linux/thunderbolt.h
@@ -22,6 +22,7 @@ struct device;
22 22 #include <linux/device.h>
23 23 #include <linux/idr.h>
24 24 #include <linux/list.h>
25 + #include <linux/lockdep.h>
25 26 #include <linux/mutex.h>
26 27 #include <linux/device-id/tb.h>
27 28 #include <linux/pci.h>
@@ -565,6 +566,7 @@ struct tb_nhi {
565 566 * @interval_nsec: Interval counter if interrupt throttling is to be
566 567 * used with this ring (in ns)
567 568 * @wait: Used to signal that the ring may be empty now
569 + * @lock_key: Lock validator class key per-ring
568 570 */
569 571 struct tb_ring {
570 572 spinlock_t lock;
@@ -590,6 +592,7 @@ struct tb_ring {
590 592 void *poll_data;
591 593 unsigned int interval_nsec;
592 594 wait_queue_head_t wait;
595 + struct lock_class_key lock_key;
593 596 };
594 597
595 598 /* Leave ring interrupt enabled on suspend */
modified include/linux/tty.h
@@ -168,6 +168,7 @@ struct tty_operations;
168 168 * @write_wait: concurrent writers are waiting in this queue until they are
169 169 * allowed to write
170 170 * @read_wait: readers wait for data in this queue
171 + * @break_wait: wait queue for timed breaks
171 172 * @hangup_work: normally a work to perform a hangup (do_tty_hangup()); while
172 173 * freeing the tty, (re)used to release_one_tty()
173 174 * @disc_data: pointer to @ldisc's private data (e.g. to &struct n_tty_data)
@@ -230,6 +231,7 @@ struct tty_struct {
230 231 struct fasync_struct *fasync;
231 232 wait_queue_head_t write_wait;
232 233 wait_queue_head_t read_wait;
234 + wait_queue_head_t break_wait;
233 235 struct work_struct hangup_work;
234 236 void *disc_data;
235 237 void *driver_data;
modified include/linux/tty_driver.h
@@ -73,6 +73,11 @@ struct serial_struct;
73 73 * @TTY_DRIVER_NO_WORKQUEUE:
74 74 * Do not create workqueue when tty_register_driver(). Whenever set, flip
75 75 * buffer workqueue can be set by tty_port_link_wq() for every port.
76 + *
77 + * @TTY_DRIVER_RESET_SAVED_TERMIOS:
78 + * Reset any saved termios settings on device registration when reusing a
79 + * minor number. Must only be set by drivers that guarantee that the minor
80 + * number is no longer in use.
76 81 */
77 82 enum tty_driver_flag {
78 83 TTY_DRIVER_INSTALLED = BIT(0),
@@ -84,6 +89,7 @@ enum tty_driver_flag {
84 89 TTY_DRIVER_DYNAMIC_ALLOC = BIT(6),
85 90 TTY_DRIVER_UNNUMBERED_NODE = BIT(7),
86 91 TTY_DRIVER_NO_WORKQUEUE = BIT(8),
92 + TTY_DRIVER_RESET_SAVED_TERMIOS = BIT(9),
87 93 };
88 94
89 95 enum tty_driver_type {
modified include/linux/tty_port.h
@@ -245,7 +245,8 @@ bool tty_port_carrier_raised(struct tty_port *port);
245 245 void tty_port_raise_dtr_rts(struct tty_port *port);
246 246 void tty_port_lower_dtr_rts(struct tty_port *port);
247 247 void tty_port_hangup(struct tty_port *port);
248 - void __tty_port_tty_hangup(struct tty_port *port, bool check_clocal, bool async);
248 + void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
249 + void tty_port_tty_vhangup(struct tty_port *port);
249 250 void tty_port_tty_wakeup(struct tty_port *port);
250 251 int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty,
251 252 struct file *filp);
@@ -264,25 +265,6 @@ static inline int tty_port_users(struct tty_port *port)
264 265 return port->count + port->blocked_open;
265 266 }
266 267
267 - /**
268 - * tty_port_tty_hangup - helper to hang up a tty asynchronously
269 - * @port: tty port
270 - * @check_clocal: hang only ttys with %CLOCAL unset?
271 - */
272 - static inline void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
273 - {
274 - __tty_port_tty_hangup(port, check_clocal, true);
275 - }
276 -
277 - /**
278 - * tty_port_tty_vhangup - helper to hang up a tty synchronously
279 - * @port: tty port
280 - */
281 - static inline void tty_port_tty_vhangup(struct tty_port *port)
282 - {
283 - __tty_port_tty_hangup(port, false, false);
284 - }
285 -
286 268 #ifdef CONFIG_TTY
287 269 void tty_kref_put(struct tty_struct *tty);
288 270 __DEFINE_CLASS_IS_CONDITIONAL(tty_port_tty, true);
modified include/linux/usb/serial.h
@@ -381,6 +381,7 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
381 381
382 382 int usb_serial_bus_register(struct usb_serial_driver *device);
383 383 void usb_serial_bus_deregister(struct usb_serial_driver *device);
384 + void usb_serial_bus_remove_new_id(struct usb_serial_driver *driver);
384 385
385 386 extern const struct bus_type usb_serial_bus_type;
386 387 extern struct tty_driver *usb_serial_tty_driver;
modified include/net/bluetooth/hci_core.h
@@ -62,7 +62,7 @@ struct inquiry_entry {
62 62 NAME_PENDING,
63 63 NAME_KNOWN,
64 64 } name_state;
65 - __u32 timestamp;
65 + unsigned long timestamp;
66 66 struct inquiry_data data;
67 67 };
68 68
@@ -78,7 +78,7 @@ struct discovery_state {
78 78 struct list_head all; /* All devices found during inquiry */
79 79 struct list_head unknown; /* Name state not known */
80 80 struct list_head resolve; /* Name needs to be resolved */
81 - __u32 timestamp;
81 + unsigned long timestamp;
82 82 bdaddr_t last_adv_addr;
83 83 u8 last_adv_addr_type;
84 84 s8 last_adv_rssi;
@@ -562,6 +562,7 @@ struct hci_dev {
562 562 struct list_head link_keys;
563 563 struct list_head long_term_keys;
564 564 struct list_head identity_resolving_keys;
565 + struct mutex remote_oob_lock;
565 566 struct list_head remote_oob_data;
566 567 struct list_head le_accept_list;
567 568 struct list_head le_resolv_list;
modified include/net/gso.h
@@ -19,10 +19,18 @@ struct skb_gso_cb {
19 19 int encap_level;
20 20 __wsum csum;
21 21 __u16 csum_start;
22 + /* Number of IPv4/IPv6 GSO handler entries for this packet. */
23 + u8 recursion_counter;
22 24 };
23 25 #define SKB_GSO_CB_OFFSET 32
24 26 #define SKB_GSO_CB(skb) ((struct skb_gso_cb *)((skb)->cb + SKB_GSO_CB_OFFSET))
25 27
28 + static inline bool gso_recursion_inc_test(struct sk_buff *skb,
29 + unsigned int limit)
30 + {
31 + return ++SKB_GSO_CB(skb)->recursion_counter > limit;
32 + }
33 +
26 34 static inline int skb_tnl_header_len(const struct sk_buff *inner_skb)
27 35 {
28 36 return (skb_mac_header(inner_skb) - inner_skb->head) -
modified include/net/netfilter/nf_flow_table.h
@@ -183,10 +183,10 @@ enum nf_flow_flags {
183 183 NF_FLOW_DNAT,
184 184 NF_FLOW_CLOSING,
185 185 NF_FLOW_TEARDOWN,
186 + NF_FLOW_PENDING,
186 187 NF_FLOW_HW,
187 188 NF_FLOW_HW_DYING,
188 189 NF_FLOW_HW_DEAD,
189 - NF_FLOW_HW_PENDING,
190 190 NF_FLOW_HW_BIDIRECTIONAL,
191 191 NF_FLOW_HW_ESTABLISHED,
192 192 };
modified include/net/sch_generic.h
@@ -810,6 +810,15 @@ static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
810 810 #endif
811 811 }
812 812
813 + static inline bool skb_at_tc_egress(const struct sk_buff *skb)
814 + {
815 + #ifdef CONFIG_NET_EGRESS
816 + return skb->nf_skip_egress && !skb_at_tc_ingress(skb);
817 + #else
818 + return false;
819 + #endif
820 + }
821 +
813 822 static inline bool skb_skip_tc_classify(struct sk_buff *skb)
814 823 {
815 824 #ifdef CONFIG_NET_CLS_ACT
modified include/net/xdp.h
@@ -106,6 +106,11 @@ struct xdp_buff {
106 106 };
107 107 };
108 108
109 + static __always_inline void xdp_reinit_buff(struct xdp_buff *xdp)
110 + {
111 + xdp->flags = 0;
112 + }
113 +
109 114 static __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp)
110 115 {
111 116 return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
modified include/sound/core.h
@@ -340,6 +340,15 @@ static inline void snd_card_unref(struct snd_card *card)
340 340
341 341 DEFINE_FREE(snd_card_unref, struct snd_card *, if (_T) snd_card_unref(_T))
342 342
343 + /*
344 + * For automatic error handling at probe time, assign the card like:
345 + * struct snd_card *card __free(snd_card_free) = NULL;
346 + * then create and process as usual.
347 + * But, don't forget to clear to NULL at successful return for avoiding
348 + * the unexpected cleanup!
349 + */
350 + DEFINE_FREE(snd_card_free, struct snd_card *, if (_T) snd_card_free(_T))
351 +
343 352 #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
344 353
345 354 /* device.c */
modified include/sound/cs35l56.h
@@ -312,6 +312,7 @@ struct snd_ctl_elem_value;
312 312
313 313 #define CS35L56_SDW1_PLAYBACK_PORT 1
314 314 #define CS35L56_SDW1_CAPTURE_PORT 3
315 + #define CS35L56_OT25_CAPTURE_PORT 4
315 316
316 317 #define CS35L56_NUM_BULK_SUPPLIES 3
317 318 #define CS35L56_NUM_DSP_REGIONS 5
modified include/uapi/linux/alloc_tag.h
@@ -38,6 +38,7 @@ struct allocinfo_counter {
38 38 __u64 bytes;
39 39 __u64 calls;
40 40 __u8 accurate;
41 + __u8 pad[7];
41 42 } __attribute__((aligned(8)));
42 43
43 44 struct allocinfo_tag_data {
modified include/uapi/linux/random.h
@@ -58,7 +58,7 @@ struct rand_pool_info {
58 58 /**
59 59 * struct vgetrandom_opaque_params - arguments for allocating memory for vgetrandom
60 60 *
61 - * @size_per_opaque_state: Size of each state that is to be passed to vgetrandom().
61 + * @size_of_opaque_state: Size of each state passed to vgetrandom().
62 62 * @mmap_prot: Value of the prot argument in mmap(2).
63 63 * @mmap_flags: Value of the flags argument in mmap(2).
64 64 * @reserved: Reserved for future use.
modified include/vdso/getrandom.h
@@ -64,7 +64,7 @@ extern void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key, u32 *c
64 64 * @opaque_state: Passed to __cvdso_getrandom().
65 65 * @opaque_len: Passed to __cvdso_getrandom();
66 66 *
67 - * This function is implemented by making a single call to to __cvdso_getrandom(), whose
67 + * This function is implemented by making a single call to __cvdso_getrandom(), whose
68 68 * documentation may be consulted for more information.
69 69 *
70 70 * Returns: The return value of __cvdso_getrandom().
modified init/Kconfig
@@ -173,6 +173,11 @@ config CC_HAS_ALLOC_TOKEN
173 173 config CC_HAS_MULTIDIMENSIONAL_NONSTRING
174 174 def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)
175 175
176 + config CC_OPT_INLINE_MEMSET
177 + string
178 + default "-finline-stringops=memset" if $(cc-option,-finline-stringops=memset)
179 + default "-mllvm -max-store-memset=4294967294" if $(cc-option,-mllvm -max-store-memset=4294967294)
180 +
176 181 config LD_CAN_USE_KEEP_IN_OVERLAY
177 182 # ld.lld prior to 21.0.0 did not support KEEP within an overlay description
178 183 # https://github.com/llvm/llvm-project/pull/130661
modified io_uring/bpf_filter.c
@@ -253,6 +253,7 @@ void io_bpf_filter_clone(struct io_restriction *dst, struct io_restriction *src)
253 253 * If the src filter is going away, just ignore it.
254 254 */
255 255 if (refcount_inc_not_zero(&src->bpf_filters->refs)) {
256 + src->bpf_filters_cow = true;
256 257 dst->bpf_filters = src->bpf_filters;
257 258 dst->bpf_filters_cow = true;
258 259 }
modified io_uring/cmd_net.c
@@ -69,8 +69,8 @@ static inline int io_uring_cmd_setsockopt(struct socket *sock,
69 69 optlen);
70 70 }
71 71
72 - static bool io_process_timestamp_skb(struct io_uring_cmd *cmd, struct sock *sk,
73 - struct sk_buff *skb, unsigned issue_flags)
72 + static int io_process_timestamp_skb(struct io_uring_cmd *cmd, struct sock *sk,
73 + struct sk_buff *skb, unsigned int issue_flags)
74 74 {
75 75 struct sock_exterr_skb *serr = SKB_EXT_ERR(skb);
76 76 struct io_uring_cqe cqe[2];
@@ -83,7 +83,7 @@ static bool io_process_timestamp_skb(struct io_uring_cmd *cmd, struct sock *sk,
83 83
84 84 ret = skb_get_tx_timestamp(skb, sk, &ts);
85 85 if (ret < 0)
86 - return false;
86 + return ret;
87 87
88 88 tskey = serr->ee.ee_data;
89 89 tstype = serr->ee.ee_info;
@@ -98,7 +98,9 @@ static bool io_process_timestamp_skb(struct io_uring_cmd *cmd, struct sock *sk,
98 98 iots = (struct io_timespec *)&cqe[1];
99 99 iots->tv_sec = ts.tv_sec;
100 100 iots->tv_nsec = ts.tv_nsec;
101 - return io_uring_cmd_post_mshot_cqe32(cmd, issue_flags, cqe);
101 + if (!io_uring_cmd_post_mshot_cqe32(cmd, issue_flags, cqe))
102 + return -ENOBUFS;
103 + return 0;
102 104 }
103 105
104 106 static int io_uring_cmd_timestamp(struct socket *sock,
@@ -135,7 +137,8 @@ static int io_uring_cmd_timestamp(struct socket *sock,
135 137 skb = skb_peek(&list);
136 138 if (!skb)
137 139 break;
138 - if (!io_process_timestamp_skb(cmd, sk, skb, issue_flags))
140 + ret = io_process_timestamp_skb(cmd, sk, skb, issue_flags);
141 + if (ret)
139 142 break;
140 143 __skb_dequeue(&list);
141 144 consume_skb(skb);
@@ -145,6 +148,12 @@ static int io_uring_cmd_timestamp(struct socket *sock,
145 148 scoped_guard(spinlock_irqsave, &q->lock)
146 149 skb_queue_splice(&list, q);
147 150 }
151 + /*
152 + * Aux CQEs cannot overflow and the poll is edge triggered, so nothing
153 + * re-runs the command once the CQ drains. End the multishot instead.
154 + */
155 + if (ret == -ENOBUFS)
156 + return -ENOBUFS;
148 157 return -EAGAIN;
149 158 }
150 159
modified io_uring/io_uring.c
@@ -733,7 +733,8 @@ bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32)
733 733 * Post dummy CQE if a 32b CQE is needed and there's only room for a
734 734 * 16b CQE before the ring wraps.
735 735 */
736 - if (cqe32 && off + 1 == ctx->cq_entries) {
736 + if (cqe32 && (ctx->flags & IORING_SETUP_CQE_MIXED) &&
737 + off + 1 == ctx->cq_entries) {
737 738 if (!io_fill_nop_cqe(ctx, off))
738 739 return false;
739 740 off = 0;
@@ -742,12 +743,13 @@ bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32)
742 743 free = ctx->cq_entries - io_cqring_queued(ctx);
743 744 /* we need a contiguous range, limit based on the current array offset */
744 745 len = min(free, ctx->cq_entries - off);
745 - if (len < (cqe32 + 1))
746 - return false;
747 -
748 746 if (ctx->flags & IORING_SETUP_CQE32) {
747 + if (!len)
748 + return false;
749 749 off <<= 1;
750 750 len <<= 1;
751 + } else if (len < (cqe32 + 1)) {
752 + return false;
751 753 }
752 754
753 755 ctx->cqe_cached = &rings->cqes[off];
@@ -781,7 +783,7 @@ static bool io_fill_cqe_aux(struct io_ring_ctx *ctx, u64 user_data, s32 res,
781 783 WRITE_ONCE(cqe->res, res);
782 784 WRITE_ONCE(cqe->flags, cflags);
783 785
784 - if (cqe32) {
786 + if (cqe32 || (ctx->flags & IORING_SETUP_CQE32)) {
785 787 WRITE_ONCE(cqe->big_cqe[0], 0);
786 788 WRITE_ONCE(cqe->big_cqe[1], 0);
787 789 }
@@ -2403,8 +2405,8 @@ static __cold void io_ring_exit_work(struct work_struct *work)
2403 2405 spin_lock(&ctx->completion_lock);
2404 2406 spin_unlock(&ctx->completion_lock);
2405 2407
2406 - /* pairs with RCU read section in io_req_local_work_add() */
2407 - if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
2408 + /* pairs with the RCU read sections in the task_work add paths */
2409 + if (ctx->flags & (IORING_SETUP_DEFER_TASKRUN | IORING_SETUP_SQPOLL))
2408 2410 synchronize_rcu();
2409 2411
2410 2412 io_ring_ctx_free(ctx);
modified io_uring/loop.c
@@ -2,6 +2,7 @@
2 2 #include "io_uring.h"
3 3 #include "wait.h"
4 4 #include "loop.h"
5 + #include "tctx.h"
5 6
6 7 static inline int io_loop_nr_cqes(const struct io_ring_ctx *ctx,
7 8 const struct iou_loop_params *lp)
@@ -81,6 +82,10 @@ int io_run_loop(struct io_ring_ctx *ctx)
81 82 {
82 83 int ret;
83 84
85 + ret = io_uring_add_tctx_node(ctx);
86 + if (unlikely(ret))
87 + return ret;
88 +
84 89 if (!io_allowed_run_tw(ctx))
85 90 return -EEXIST;
86 91
modified io_uring/tw.c
@@ -210,6 +210,9 @@ void io_req_normal_work_add(struct io_kiocb *req)
210 210 struct io_uring_task *tctx = req->tctx;
211 211 struct io_ring_ctx *ctx = req->ctx;
212 212
213 + /* SQPOLL can retire the request on push, see io_ring_exit_work() */
214 + guard(rcu)();
215 +
213 216 /* tw run already pending, nothing else to do */
214 217 if (!mpscq_push(&tctx->task_list, &req->io_task_work.node))
215 218 return;
modified io_uring/zcrx.c
@@ -374,6 +374,7 @@ struct io_zcrx_args {
374 374 struct io_kiocb *req;
375 375 struct io_zcrx_ifq *ifq;
376 376 unsigned nr_skbs;
377 + bool stopped_early;
377 378 };
378 379
379 380 static const struct memory_provider_ops io_uring_pp_zc_ops;
@@ -1899,6 +1900,9 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
1899 1900 }
1900 1901
1901 1902 out:
1903 + /* Bytes left in len mean an error stopped the walk early. */
1904 + if (len)
1905 + args->stopped_early = true;
1902 1906 if (offset == start_off)
1903 1907 return ret;
1904 1908 desc->count -= (offset - start_off);
@@ -1935,8 +1939,9 @@ static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
1935 1939 ret = -ENOTCONN;
1936 1940 else
1937 1941 ret = -EAGAIN;
1938 - } else if (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) &&
1939 - (issue_flags & IO_URING_F_MULTISHOT)) {
1942 + } else if ((issue_flags & IO_URING_F_MULTISHOT) &&
1943 + (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) ||
1944 + args.stopped_early)) {
1940 1945 ret = IOU_REQUEUE;
1941 1946 } else if (sock_flag(sk, SOCK_DONE)) {
1942 1947 /* Make it to retry until it finally gets 0. */
modified kernel/audit_tree.c
@@ -545,22 +545,38 @@ static void kill_rules(struct audit_context *context, struct audit_tree *tree)
545 545 {
546 546 struct audit_krule *rule, *next;
547 547 struct audit_entry *entry;
548 + bool need_sync = false;
548 549
549 550 list_for_each_entry_safe(rule, next, &tree->rules, rlist) {
550 551 entry = container_of(rule, struct audit_entry, rule);
551 552
552 - list_del_init(&rule->rlist);
553 553 if (rule->tree) {
554 554 /* not a half-baked one */
555 555 audit_tree_log_remove_rule(context, rule);
556 - if (entry->rule.exe)
557 - audit_remove_mark(entry->rule.exe);
558 556 rule->tree = NULL;
559 557 list_del_rcu(&entry->list);
560 558 list_del(&entry->rule.list);
561 - call_rcu(&entry->rcu, audit_free_rule_rcu);
559 + if (entry->rule.exe)
560 + need_sync = true;
561 + } else {
562 + list_del_init(&rule->rlist);
562 563 }
563 564 }
565 +
566 + if (list_empty(&tree->rules))
567 + return;
568 +
569 + if (need_sync)
570 + synchronize_rcu();
571 +
572 + list_for_each_entry_safe(rule, next, &tree->rules, rlist) {
573 + entry = container_of(rule, struct audit_entry, rule);
574 +
575 + list_del_init(&rule->rlist);
576 + if (entry->rule.exe)
577 + audit_remove_mark(entry->rule.exe);
578 + call_rcu(&entry->rcu, audit_free_rule_rcu);
579 + }
564 580 }
565 581
566 582 /*
modified kernel/bpf/core.c
@@ -1362,7 +1362,7 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
1362 1362 {
1363 1363 struct bpf_insn *to = to_buff;
1364 1364 u32 imm_rnd = get_random_u32();
1365 - s16 off;
1365 + int off;
1366 1366
1367 1367 BUILD_BUG_ON(BPF_REG_PARAMS + 2 != MAX_BPF_JIT_REG);
1368 1368 BUILD_BUG_ON(BPF_REG_AX + 1 != MAX_BPF_JIT_REG);
@@ -1438,6 +1438,8 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
1438 1438 off = from->off;
1439 1439 if (off < 0)
1440 1440 off -= 2;
1441 + if (off < S16_MIN)
1442 + return -ERANGE;
1441 1443 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
1442 1444 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
1443 1445 *to++ = BPF_JMP_REG(from->code, from->dst_reg, BPF_REG_AX, off);
@@ -1458,6 +1460,8 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
1458 1460 off = from->off;
1459 1461 if (off < 0)
1460 1462 off -= 2;
1463 + if (off < S16_MIN)
1464 + return -ERANGE;
1461 1465 *to++ = BPF_ALU32_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
1462 1466 *to++ = BPF_ALU32_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
1463 1467 *to++ = BPF_JMP32_REG(from->code, from->dst_reg, BPF_REG_AX,
@@ -1606,7 +1610,9 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bp
1606 1610 if (!rewritten)
1607 1611 continue;
1608 1612
1609 - if (env)
1613 + if (rewritten < 0)
1614 + tmp = ERR_PTR(rewritten);
1615 + else if (env)
1610 1616 tmp = bpf_patch_insn_data(env, i, insn_buff, rewritten);
1611 1617 else
1612 1618 tmp = bpf_patch_insn_single(clone, i, insn_buff, rewritten);
modified kernel/bpf/hashtab.c
@@ -128,6 +128,7 @@ struct htab_elem {
128 128
129 129 struct htab_btf_record {
130 130 struct btf_record *record;
131 + struct btf *btf;
131 132 u32 key_size;
132 133 };
133 134
@@ -497,8 +498,13 @@ static void htab_dtor_ctx_free(void *ctx)
497 498 {
498 499 struct htab_btf_record *hrec = ctx;
499 500
501 + /*
502 + * The duplicated record still points into the map BTF, so free it
503 + * before dropping the reference that keeps that BTF alive.
504 + */
500 505 btf_record_free(hrec->record);
501 - kfree(ctx);
506 + btf_put(hrec->btf);
507 + kfree(hrec);
502 508 }
503 509
504 510 static int bpf_ma_set_dtor(struct bpf_map *map, struct bpf_mem_alloc *ma,
@@ -521,6 +527,15 @@ static int bpf_ma_set_dtor(struct bpf_map *map, struct bpf_mem_alloc *ma,
521 527 kfree(hrec);
522 528 return err;
523 529 }
530 + /*
531 + * btf_record_dup() only acquires kernel and module BTF. Fields whose
532 + * types live in the map BTF keep pointing into it: kptrs to local
533 + * types refer to map->btf, and graph roots carry a value record owned
534 + * by its struct meta table. The context can outlive the map when the
535 + * allocator defers its teardown, so hold a reference of our own.
536 + */
537 + hrec->btf = map->btf;
538 + btf_get(hrec->btf);
524 539 bpf_mem_alloc_set_dtor(ma, dtor, htab_dtor_ctx_free, hrec);
525 540 return 0;
526 541 }
@@ -3359,8 +3374,10 @@ static int __rhtab_map_lookup_and_delete_batch(struct bpf_map *map,
3359 3374 }
3360 3375
3361 3376 if (do_delete) {
3377 + migrate_disable();
3362 3378 for (i = 0; i < total; i++)
3363 3379 rhtab_delete_elem(rhtab, del_elems[i], NULL, 0);
3380 + migrate_enable();
3364 3381 }
3365 3382
3366 3383 rcu_read_unlock();
modified kernel/bpf/memalloc.c
@@ -118,6 +118,11 @@ struct bpf_mem_cache {
118 118 struct llist_head free_by_rcu_ttrace;
119 119 struct llist_head waiting_for_gp_ttrace;
120 120 struct rcu_head rcu_ttrace;
121 + /*
122 + * 0 - idle
123 + * 1 - __free_rcu() is queued
124 + * 2 - __free_rcu() is queued and free_by_rcu_ttrace got more objects since
125 + */
121 126 atomic_t call_rcu_ttrace_in_progress;
122 127 raw_spinlock_t lock;
123 128 };
@@ -276,6 +281,8 @@ static int free_all(struct bpf_mem_cache *c, struct llist_node *llnode, bool per
276 281 return cnt;
277 282 }
278 283
284 + static void __do_call_rcu_ttrace(struct bpf_mem_cache *c);
285 +
279 286 static void __free_rcu(struct rcu_head *head)
280 287 {
281 288 struct bpf_mem_cache *c = container_of(head, struct bpf_mem_cache, rcu_ttrace);
@@ -285,7 +292,19 @@ static void __free_rcu(struct rcu_head *head)
285 292 llnode = llist_del_all(&c->waiting_for_gp_ttrace);
286 293
287 294 free_all(c, llnode, !!c->percpu_size);
288 - atomic_set(&c->call_rcu_ttrace_in_progress, 0);
295 +
296 + /*
297 + * do_call_rcu_ttrace() that ran while GP was in flight left its objects
298 + * in free_by_rcu_ttrace. This cache may never free or alloc in bulk
299 + * again, so start the next GP from here.
300 + * 'c' can be freed as soon as call_rcu_ttrace_in_progress is zero.
301 + */
302 + if (atomic_cmpxchg(&c->call_rcu_ttrace_in_progress, 1, 0) == 1)
303 + return;
304 +
305 + /* Pairs with synchronize_rcu() in free_mem_alloc() */
306 + guard(rcu)();
307 + __do_call_rcu_ttrace(c);
289 308 }
290 309
291 310 static void enque_to_free(struct bpf_mem_cache *c, void *obj)
@@ -298,18 +317,15 @@ static void enque_to_free(struct bpf_mem_cache *c, void *obj)
298 317 llist_add(llnode, &c->free_by_rcu_ttrace);
299 318 }
300 319
301 - static void do_call_rcu_ttrace(struct bpf_mem_cache *c)
320 + static void __do_call_rcu_ttrace(struct bpf_mem_cache *c)
302 321 {
303 322 struct llist_node *llnode, *t;
304 323
305 - if (atomic_xchg(&c->call_rcu_ttrace_in_progress, 1)) {
306 - if (unlikely(READ_ONCE(c->draining))) {
307 - scoped_guard(raw_spinlock_irqsave, &c->lock)
308 - llnode = llist_del_all(&c->free_by_rcu_ttrace);
309 - free_all(c, llnode, !!c->percpu_size);
310 - }
311 - return;
312 - }
324 + /*
325 + * Must be done before llist_del_all(). Objects that it misses were
326 + * added by do_call_rcu_ttrace() that will set 2 after this store.
327 + */
328 + atomic_set(&c->call_rcu_ttrace_in_progress, 1);
313 329
314 330 WARN_ON_ONCE(!llist_empty(&c->waiting_for_gp_ttrace));
315 331 llist_for_each_safe(llnode, t, llist_del_all(&c->free_by_rcu_ttrace))
@@ -328,6 +344,22 @@ static void do_call_rcu_ttrace(struct bpf_mem_cache *c)
328 344 call_rcu_tasks_trace(&c->rcu_ttrace, __free_rcu);
329 345 }
330 346
347 + static void do_call_rcu_ttrace(struct bpf_mem_cache *c)
348 + {
349 + struct llist_node *llnode;
350 +
351 + if (atomic_xchg(&c->call_rcu_ttrace_in_progress, 2)) {
352 + if (unlikely(READ_ONCE(c->draining))) {
353 + scoped_guard(raw_spinlock_irqsave, &c->lock)
354 + llnode = llist_del_all(&c->free_by_rcu_ttrace);
355 + free_all(c, llnode, !!c->percpu_size);
356 + }
357 + return;
358 + }
359 +
360 + __do_call_rcu_ttrace(c);
361 + }
362 +
331 363 static void free_bulk(struct bpf_mem_cache *c)
332 364 {
333 365 struct bpf_mem_cache *tgt = c->tgt;
@@ -700,7 +732,12 @@ static void free_mem_alloc(struct bpf_mem_alloc *ma)
700 732 * to wait for the pending __free_by_rcu(), and __free_rcu(). RCU Tasks
701 733 * Trace grace period implies RCU grace period, so all __free_rcu don't
702 734 * need extra call_rcu() (and thus extra rcu_barrier() here).
735 + *
736 + * __free_rcu() queues itself again unless it sees 'draining'. After
737 + * synchronize_rcu() it either did that already or will not do it, so
738 + * rcu_barrier_tasks_trace() cannot miss it.
703 739 */
740 + synchronize_rcu();
704 741 rcu_barrier(); /* wait for __free_by_rcu */
705 742 rcu_barrier_tasks_trace(); /* wait for __free_rcu */
706 743 free_mem_alloc_no_barrier(ma);
modified kernel/bpf/syscall.c
@@ -2448,6 +2448,21 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu)
2448 2448 bpf_prog_free(aux->prog);
2449 2449 }
2450 2450
2451 + /*
2452 + * Progs called from a trampoline can also be reached by a task that was
2453 + * preempted in the trampoline before the prog's enter helper took its RCU
2454 + * read lock, wait for those first.
2455 + */
2456 + static void __bpf_prog_put_rcu_tasks(struct rcu_head *rcu)
2457 + {
2458 + struct bpf_prog *prog = container_of(rcu, struct bpf_prog_aux, rcu)->prog;
2459 +
2460 + if (prog->sleepable)
2461 + call_rcu_tasks_trace(rcu, __bpf_prog_put_rcu);
2462 + else
2463 + call_rcu(rcu, __bpf_prog_put_rcu);
2464 + }
2465 +
2451 2466 static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
2452 2467 {
2453 2468 bpf_prog_kallsyms_del_all(prog);
@@ -2461,7 +2476,9 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
2461 2476 btf_put(prog->aux->attach_btf);
2462 2477
2463 2478 if (deferred) {
2464 - if (prog->sleepable)
2479 + if (IS_ENABLED(CONFIG_TASKS_RCU) && prog->aux->tramp_linked)
2480 + call_rcu_tasks(&prog->aux->rcu, __bpf_prog_put_rcu_tasks);
2481 + else if (prog->sleepable)
2465 2482 call_rcu_tasks_trace(&prog->aux->rcu, __bpf_prog_put_rcu);
2466 2483 else
2467 2484 call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
modified kernel/bpf/trampoline.c
@@ -401,6 +401,7 @@ static struct bpf_trampoline *bpf_trampoline_lookup(u64 key, unsigned long ip)
401 401 head = &trampoline_ip_table[hash_64(tr->ip, TRAMPOLINE_HASH_BITS)];
402 402 hlist_add_head(&tr->hlist_ip, head);
403 403 refcount_set(&tr->refcnt, 1);
404 + INIT_LIST_HEAD(&tr->images);
404 405 for (i = 0; i < BPF_TRAMP_MAX; i++)
405 406 INIT_HLIST_HEAD(&tr->progs_hlist[i]);
406 407 out:
@@ -565,15 +566,22 @@ static void bpf_tramp_image_free(struct bpf_tramp_image *im)
565 566 arch_free_bpf_trampoline(im->image, im->size);
566 567 bpf_jit_uncharge_modmem(im->size);
567 568 percpu_ref_exit(&im->pcref);
569 + kfree(im->skips);
568 570 kfree_rcu(im, rcu);
569 571 }
570 572
571 573 static void __bpf_tramp_image_put_deferred(struct work_struct *work)
572 574 {
573 575 struct bpf_tramp_image *im;
576 + struct bpf_trampoline *tr;
574 577
575 578 im = container_of(work, struct bpf_tramp_image, work);
579 + tr = im->tr;
580 + trampoline_lock(tr);
581 + list_del(&im->list);
582 + trampoline_unlock(tr);
576 583 bpf_tramp_image_free(im);
584 + bpf_trampoline_put(tr);
577 585 }
578 586
579 587 /* callback, fexit step 3 or fentry step 2 */
@@ -601,7 +609,7 @@ static void __bpf_tramp_image_put_rcu_tasks(struct rcu_head *rcu)
601 609 struct bpf_tramp_image *im;
602 610
603 611 im = container_of(rcu, struct bpf_tramp_image, rcu);
604 - if (im->ip_after_call)
612 + if (im->call_orig)
605 613 /* the case of fmod_ret/fexit trampoline and CONFIG_PREEMPTION=y */
606 614 percpu_ref_kill(&im->pcref);
607 615 else
@@ -621,9 +629,9 @@ static void bpf_tramp_image_put(struct bpf_tramp_image *im)
621 629 *
622 630 * The trampoline is unreachable before bpf_tramp_image_put().
623 631 *
624 - * First, patch the trampoline to avoid calling into fexit progs.
625 - * The progs will be freed even if the original function is still
626 - * executing or sleeping.
632 + * Progs are patched out of the image when they are detached, see
633 + * bpf_trampoline_skip_prog(), so they can be freed even if a task is
634 + * still in the image.
627 635 * In case of CONFIG_PREEMPT=y use call_rcu_tasks() to wait on
628 636 * first few asm instructions to execute and call into
629 637 * __bpf_tramp_enter->percpu_ref_get.
@@ -637,11 +645,7 @@ static void bpf_tramp_image_put(struct bpf_tramp_image *im)
637 645 * percpu_ref_kill will be waiting for. Hence the first
638 646 * call_rcu_tasks() is not necessary.
639 647 */
640 - if (im->ip_after_call) {
641 - int err = bpf_arch_text_poke(im->ip_after_call, BPF_MOD_NOP,
642 - BPF_MOD_JUMP, NULL,
643 - im->ip_epilogue);
644 - WARN_ON(err);
648 + if (im->call_orig) {
645 649 if (IS_ENABLED(CONFIG_TASKS_RCU))
646 650 call_rcu_tasks(&im->rcu, __bpf_tramp_image_put_rcu_tasks);
647 651 else
@@ -658,7 +662,7 @@ static void bpf_tramp_image_put(struct bpf_tramp_image *im)
658 662 call_rcu_tasks_trace(&im->rcu, __bpf_tramp_image_put_rcu_tasks);
659 663 }
660 664
661 - static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, int size)
665 + static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, int size, int nr_progs)
662 666 {
663 667 struct bpf_tramp_image *im;
664 668 struct bpf_ksym *ksym;
@@ -669,6 +673,10 @@ static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key, int size)
669 673 if (!im)
670 674 goto out;
671 675
676 + im->skips = kzalloc_objs(*im->skips, nr_progs);
677 + if (!im->skips)
678 + goto out_free_im;
679 +
672 680 err = bpf_jit_charge_modmem(size);
673 681 if (err)
674 682 goto out_free_im;
@@ -695,6 +703,7 @@ out_free_image:
695 703 out_uncharge:
696 704 bpf_jit_uncharge_modmem(size);
697 705 out_free_im:
706 + kfree(im->skips);
698 707 kfree(im);
699 708 out:
700 709 return ERR_PTR(err);
@@ -771,11 +780,12 @@ again:
771 780 goto out;
772 781 }
773 782
774 - im = bpf_tramp_image_alloc(tr->key, size);
783 + im = bpf_tramp_image_alloc(tr->key, size, total);
775 784 if (IS_ERR(im)) {
776 785 err = PTR_ERR(im);
777 786 goto out;
778 787 }
788 + im->call_orig = tr->flags & BPF_TRAMP_F_CALL_ORIG;
779 789
780 790 err = arch_prepare_bpf_trampoline(im, im->image, im->image + size,
781 791 &tr->func.model, tr->flags, tnodes,
@@ -806,8 +816,14 @@ again:
806 816 #endif
807 817
808 818 out_free:
809 - if (err)
819 + if (err) {
810 820 bpf_tramp_image_free(im);
821 + } else {
822 + /* track the image until it is freed, for bpf_trampoline_skip_prog() */
823 + refcount_inc(&tr->refcnt);
824 + im->tr = tr;
825 + list_add(&im->list, &tr->images);
826 + }
811 827 out:
812 828 /* If any error happens, restore previous flags */
813 829 if (err)
@@ -907,6 +923,7 @@ static int bpf_trampoline_add_prog(struct bpf_trampoline *tr,
907 923 }
908 924
909 925 hlist_add_head(&node->tramp_hlist, prog_list);
926 + node->link->prog->aux->tramp_linked = true;
910 927 if (kind == BPF_TRAMP_FSESSION) {
911 928 tr->progs_cnt[BPF_TRAMP_FENTRY]++;
912 929 fexit = fsession_exit(node);
@@ -920,6 +937,41 @@ static int bpf_trampoline_add_prog(struct bpf_trampoline *tr,
920 937 return 0;
921 938 }
922 939
940 + /*
941 + * Patch the nop in front of a prog call to a jump over it. A task can be
942 + * preempted anywhere in the image, so archs that need several instructions for
943 + * a jump of any range patch a single near branch here instead.
944 + */
945 + int __weak arch_bpf_trampoline_skip(void *nop, void *target)
946 + {
947 + return bpf_arch_text_poke(nop, BPF_MOD_NOP, BPF_MOD_JUMP, NULL, target);
948 + }
949 +
950 + /*
951 + * prog was detached and can be freed, but tasks may still be running in images
952 + * that call it, sleeping in an earlier prog for example. They can be in any
953 + * image that is not freed yet, not only in cur_image, so patch all of them to
954 + * jump over prog.
955 + */
956 + static void bpf_trampoline_skip_prog(struct bpf_trampoline *tr, struct bpf_prog *prog)
957 + {
958 + struct bpf_tramp_image *im;
959 + int i, err;
960 +
961 + list_for_each_entry(im, &tr->images, list) {
962 + for (i = 0; i < im->nr_skips; i++) {
963 + struct bpf_tramp_skip *skip = &im->skips[i];
964 +
965 + if (skip->prog != prog)
966 + continue;
967 + err = arch_bpf_trampoline_skip(skip->nop, skip->target);
968 + WARN_ON_ONCE(err);
969 + /* not a nop anymore, and prog's address can be reused */
970 + skip->prog = NULL;
971 + }
972 + }
973 + }
974 +
923 975 static void bpf_trampoline_remove_prog(struct bpf_trampoline *tr,
924 976 struct bpf_tramp_node *node)
925 977 {
@@ -937,6 +989,7 @@ static void bpf_trampoline_remove_prog(struct bpf_trampoline *tr,
937 989 }
938 990 hlist_del_init(&node->tramp_hlist);
939 991 tr->progs_cnt[kind]--;
992 + bpf_trampoline_skip_prog(tr, node->link->prog);
940 993 }
941 994
942 995 static int __bpf_trampoline_link_prog(struct bpf_tramp_node *node,
@@ -1245,11 +1298,9 @@ void bpf_trampoline_put(struct bpf_trampoline *tr)
1245 1298 if (WARN_ON_ONCE(!hlist_empty(&tr->progs_hlist[i])))
1246 1299 goto out;
1247 1300
1248 - /* This code will be executed even when the last bpf_tramp_image
1249 - * is alive. All progs are detached from the trampoline and the
1250 - * trampoline image is patched with jmp into epilogue to skip
1251 - * fexit progs. The fentry-only trampoline will be freed via
1252 - * multiple rcu callbacks.
1301 + /*
1302 + * All progs are detached and the last image has been freed, images
1303 + * hold a reference on the trampoline until then.
1253 1304 */
1254 1305 hlist_del(&tr->hlist_key);
1255 1306 hlist_del(&tr->hlist_ip);
modified kernel/bpf/verifier.c
@@ -14826,7 +14826,15 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn
14826 14826 "Tighten the scalar bounds before the arithmetic so the resulting pointer remains within the allowed range.");
14827 14827 return -EINVAL;
14828 14828 }
14829 - reg_bounds_sync(dst_reg);
14829 + /*
14830 + * A packet pointer that keeps its id or range is checked against a
14831 + * range set from the checked pointer's umax, so var_off must not tighten
14832 + * its umax. r32 must still match var_off for reg_bounds_sanity_check().
14833 + */
14834 + if (reg_is_pkt_pointer(dst_reg) && (known || dst_reg->range > 0))
14835 + __update_reg32_bounds(dst_reg);
14836 + else
14837 + reg_bounds_sync(dst_reg);
14830 14838 bounds_ret = sanitize_check_bounds(env, insn, dst_reg);
14831 14839 if (bounds_ret == -EACCES)
14832 14840 return bounds_ret;
modified kernel/events/core.c
@@ -7626,9 +7626,11 @@ static void perf_sigtrap(struct perf_event *event)
7626 7626 {
7627 7627 /*
7628 7628 * Both perf_pending_task() and perf_pending_irq() can race with the
7629 - * task exiting.
7629 + * task exiting or exec-ing. We can determine if such a race has
7630 + * occurred by checking if perf_event_exit_task(), which will set
7631 + * ctx->task to TASK_TOMBSTONE, has already been called.
7630 7632 */
7631 - if (current->flags & PF_EXITING)
7633 + if (event->ctx->task == TASK_TOMBSTONE)
7632 7634 return;
7633 7635
7634 7636 /*
@@ -8129,10 +8131,15 @@ static void __perf_event_header__init_id(struct perf_sample_data *data,
8129 8131 }
8130 8132 }
8131 8133
8132 - void perf_event_header__init_id(struct perf_event_header *header,
8133 - struct perf_sample_data *data,
8134 - struct perf_event *event)
8134 + void perf_event_header__init(struct perf_event_header *header,
8135 + struct perf_sample_data *data,
8136 + u32 type, u16 misc, u16 size,
8137 + struct perf_event *event)
8135 8138 {
8139 + header->type = type;
8140 + header->misc = misc;
8141 + header->size = size;
8142 +
8136 8143 if (event->attr.sample_id_all) {
8137 8144 header->size += event->id_header_size;
8138 8145 __perf_event_header__init_id(data, event, event->attr.sample_type);
@@ -8969,17 +8976,16 @@ perf_event_read_event(struct perf_event *event,
8969 8976 struct perf_output_handle handle;
8970 8977 struct perf_sample_data sample;
8971 8978 struct perf_read_event read_event = {
8972 - .header = {
8973 - .type = PERF_RECORD_READ,
8974 - .misc = 0,
8975 - .size = sizeof(read_event) + event->read_size,
8976 - },
8977 8979 .pid = perf_event_pid(event, task),
8978 8980 .tid = perf_event_tid(event, task),
8979 8981 };
8980 8982 int ret;
8981 8983
8982 - perf_event_header__init_id(&read_event.header, &sample, event);
8984 + perf_event_header__init(&read_event.header, &sample,
8985 + PERF_RECORD_READ,
8986 + /* misc= */ 0,
8987 + sizeof(read_event) + event->read_size,
8988 + event);
8983 8989 ret = perf_output_begin(&handle, &sample, event, read_event.header.size);
8984 8990 if (ret)
8985 8991 return;
@@ -9220,6 +9226,7 @@ struct perf_task_event {
9220 9226 u32 ptid;
9221 9227 u64 time;
9222 9228 } event_id;
9229 + int new;
9223 9230 };
9224 9231
9225 9232 static int perf_event_task_match(struct perf_event *event)
@@ -9236,17 +9243,21 @@ static void perf_event_task_output(struct perf_event *event,
9236 9243 struct perf_output_handle handle;
9237 9244 struct perf_sample_data sample;
9238 9245 struct task_struct *task = task_event->task;
9239 - int ret, size = task_event->event_id.header.size;
9246 + int ret;
9240 9247
9241 9248 if (!perf_event_task_match(event))
9242 9249 return;
9243 9250
9244 - perf_event_header__init_id(&task_event->event_id.header, &sample, event);
9251 + perf_event_header__init(&task_event->event_id.header, &sample,
9252 + task_event->new ? PERF_RECORD_FORK : PERF_RECORD_EXIT,
9253 + /* misc= */ 0,
9254 + sizeof(task_event->event_id),
9255 + event);
9245 9256
9246 9257 ret = perf_output_begin(&handle, &sample, event,
9247 9258 task_event->event_id.header.size);
9248 9259 if (ret)
9249 - goto out;
9260 + return;
9250 9261
9251 9262 task_event->event_id.pid = perf_event_pid(event, task);
9252 9263 task_event->event_id.tid = perf_event_tid(event, task);
@@ -9268,8 +9279,6 @@ static void perf_event_task_output(struct perf_event *event,
9268 9279 perf_event__output_id_sample(event, &handle, &sample);
9269 9280
9270 9281 perf_output_end(&handle);
9271 - out:
9272 - task_event->event_id.header.size = size;
9273 9282 }
9274 9283
9275 9284 static void perf_event_task(struct task_struct *task,
@@ -9286,18 +9295,7 @@ static void perf_event_task(struct task_struct *task,
9286 9295 task_event = (struct perf_task_event){
9287 9296 .task = task,
9288 9297 .task_ctx = task_ctx,
9289 - .event_id = {
9290 - .header = {
9291 - .type = new ? PERF_RECORD_FORK : PERF_RECORD_EXIT,
9292 - .misc = 0,
9293 - .size = sizeof(task_event.event_id),
9294 - },
9295 - /* .pid */
9296 - /* .ppid */
9297 - /* .tid */
9298 - /* .ptid */
9299 - /* .time */
9300 - },
9298 + .new = new,
9301 9299 };
9302 9300
9303 9301 perf_iterate_sb(perf_event_task_output,
@@ -9374,6 +9372,7 @@ struct perf_comm_event {
9374 9372 u32 pid;
9375 9373 u32 tid;
9376 9374 } event_id;
9375 + bool exec;
9377 9376 };
9378 9377
9379 9378 static int perf_event_comm_match(struct perf_event *event)
@@ -9387,18 +9386,21 @@ static void perf_event_comm_output(struct perf_event *event,
9387 9386 struct perf_comm_event *comm_event = data;
9388 9387 struct perf_output_handle handle;
9389 9388 struct perf_sample_data sample;
9390 - int size = comm_event->event_id.header.size;
9391 9389 int ret;
9392 9390
9393 9391 if (!perf_event_comm_match(event))
9394 9392 return;
9395 9393
9396 - perf_event_header__init_id(&comm_event->event_id.header, &sample, event);
9394 + perf_event_header__init(&comm_event->event_id.header, &sample,
9395 + PERF_RECORD_COMM,
9396 + comm_event->exec ? PERF_RECORD_MISC_COMM_EXEC : 0,
9397 + sizeof(comm_event->event_id) + comm_event->comm_size,
9398 + event);
9397 9399 ret = perf_output_begin(&handle, &sample, event,
9398 9400 comm_event->event_id.header.size);
9399 9401
9400 9402 if (ret)
9401 - goto out;
9403 + return;
9402 9404
9403 9405 comm_event->event_id.pid = perf_event_pid(event, comm_event->task);
9404 9406 comm_event->event_id.tid = perf_event_tid(event, comm_event->task);
@@ -9410,8 +9412,6 @@ static void perf_event_comm_output(struct perf_event *event,
9410 9412 perf_event__output_id_sample(event, &handle, &sample);
9411 9413
9412 9414 perf_output_end(&handle);
9413 - out:
9414 - comm_event->event_id.header.size = size;
9415 9415 }
9416 9416
9417 9417 static void perf_event_comm_event(struct perf_comm_event *comm_event)
@@ -9426,8 +9426,6 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
9426 9426 comm_event->comm = comm;
9427 9427 comm_event->comm_size = size;
9428 9428
9429 - comm_event->event_id.header.size = sizeof(comm_event->event_id) + size;
9430 -
9431 9429 perf_iterate_sb(perf_event_comm_output,
9432 9430 comm_event,
9433 9431 NULL);
@@ -9444,15 +9442,8 @@ void perf_event_comm(struct task_struct *task, bool exec)
9444 9442 .task = task,
9445 9443 /* .comm */
9446 9444 /* .comm_size */
9447 - .event_id = {
9448 - .header = {
9449 - .type = PERF_RECORD_COMM,
9450 - .misc = exec ? PERF_RECORD_MISC_COMM_EXEC : 0,
9451 - /* .size */
9452 - },
9453 - /* .pid */
9454 - /* .tid */
9455 - },
9445 + /* .event_id */
9446 + .exec = exec,
9456 9447 };
9457 9448
9458 9449 perf_event_comm_event(&comm_event);
@@ -9486,18 +9477,20 @@ static void perf_event_namespaces_output(struct perf_event *event,
9486 9477 struct perf_namespaces_event *namespaces_event = data;
9487 9478 struct perf_output_handle handle;
9488 9479 struct perf_sample_data sample;
9489 - u16 header_size = namespaces_event->event_id.header.size;
9490 9480 int ret;
9491 9481
9492 9482 if (!perf_event_namespaces_match(event))
9493 9483 return;
9494 9484
9495 - perf_event_header__init_id(&namespaces_event->event_id.header,
9496 - &sample, event);
9485 + perf_event_header__init(&namespaces_event->event_id.header, &sample,
9486 + PERF_RECORD_NAMESPACES,
9487 + /* misc= */ 0,
9488 + sizeof(namespaces_event->event_id),
9489 + event);
9497 9490 ret = perf_output_begin(&handle, &sample, event,
9498 9491 namespaces_event->event_id.header.size);
9499 9492 if (ret)
9500 - goto out;
9493 + return;
9501 9494
9502 9495 namespaces_event->event_id.pid = perf_event_pid(event,
9503 9496 namespaces_event->task);
@@ -9509,8 +9502,6 @@ static void perf_event_namespaces_output(struct perf_event *event,
9509 9502 perf_event__output_id_sample(event, &handle, &sample);
9510 9503
9511 9504 perf_output_end(&handle);
9512 - out:
9513 - namespaces_event->event_id.header.size = header_size;
9514 9505 }
9515 9506
9516 9507 static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info,
@@ -9541,11 +9532,7 @@ void perf_event_namespaces(struct task_struct *task)
9541 9532 namespaces_event = (struct perf_namespaces_event){
9542 9533 .task = task,
9543 9534 .event_id = {
9544 - .header = {
9545 - .type = PERF_RECORD_NAMESPACES,
9546 - .misc = 0,
9547 - .size = sizeof(namespaces_event.event_id),
9548 - },
9535 + /* .header */
9549 9536 /* .pid */
9550 9537 /* .tid */
9551 9538 .nr_namespaces = NR_NAMESPACES,
@@ -9613,18 +9600,19 @@ static void perf_event_cgroup_output(struct perf_event *event, void *data)
9613 9600 struct perf_cgroup_event *cgroup_event = data;
9614 9601 struct perf_output_handle handle;
9615 9602 struct perf_sample_data sample;
9616 - u16 header_size = cgroup_event->event_id.header.size;
9617 9603 int ret;
9604 + u16 size = sizeof(cgroup_event->event_id) + cgroup_event->path_size;
9618 9605
9619 9606 if (!perf_event_cgroup_match(event))
9620 9607 return;
9621 9608
9622 - perf_event_header__init_id(&cgroup_event->event_id.header,
9623 - &sample, event);
9609 + perf_event_header__init(&cgroup_event->event_id.header, &sample,
9610 + PERF_RECORD_CGROUP, /* misc= */ 0, size,
9611 + event);
9624 9612 ret = perf_output_begin(&handle, &sample, event,
9625 9613 cgroup_event->event_id.header.size);
9626 9614 if (ret)
9627 - goto out;
9615 + return;
9628 9616
9629 9617 perf_output_put(&handle, cgroup_event->event_id);
9630 9618 __output_copy(&handle, cgroup_event->path, cgroup_event->path_size);
@@ -9632,8 +9620,6 @@ static void perf_event_cgroup_output(struct perf_event *event, void *data)
9632 9620 perf_event__output_id_sample(event, &handle, &sample);
9633 9621
9634 9622 perf_output_end(&handle);
9635 - out:
9636 - cgroup_event->event_id.header.size = header_size;
9637 9623 }
9638 9624
9639 9625 static void perf_event_cgroup(struct cgroup *cgrp)
@@ -9648,11 +9634,6 @@ static void perf_event_cgroup(struct cgroup *cgrp)
9648 9634
9649 9635 cgroup_event = (struct perf_cgroup_event){
9650 9636 .event_id = {
9651 - .header = {
9652 - .type = PERF_RECORD_CGROUP,
9653 - .misc = 0,
9654 - .size = sizeof(cgroup_event.event_id),
9655 - },
9656 9637 .id = cgroup_id(cgrp),
9657 9638 },
9658 9639 };
@@ -9675,7 +9656,6 @@ static void perf_event_cgroup(struct cgroup *cgrp)
9675 9656 while (!IS_ALIGNED(size, sizeof(u64)))
9676 9657 cgroup_event.path[size++] = '\0';
9677 9658
9678 - cgroup_event.event_id.header.size += size;
9679 9659 cgroup_event.path_size = size;
9680 9660
9681 9661 perf_iterate_sb(perf_event_cgroup_output,
@@ -9731,38 +9711,40 @@ static void perf_event_mmap_output(struct perf_event *event,
9731 9711 struct perf_mmap_event *mmap_event = data;
9732 9712 struct perf_output_handle handle;
9733 9713 struct perf_sample_data sample;
9734 - int size = mmap_event->event_id.header.size;
9735 - u32 type = mmap_event->event_id.header.type;
9736 - bool use_build_id;
9714 + int size = sizeof(mmap_event->event_id) + mmap_event->file_size;
9715 + u32 type = PERF_RECORD_MMAP;
9716 + u16 misc = PERF_RECORD_MISC_USER;
9717 + bool use_build_id = false;
9737 9718 int ret;
9738 9719
9739 9720 if (!perf_event_mmap_match(event, data))
9740 9721 return;
9741 9722
9742 9723 if (event->attr.mmap2) {
9743 - mmap_event->event_id.header.type = PERF_RECORD_MMAP2;
9744 - mmap_event->event_id.header.size += sizeof(mmap_event->maj);
9745 - mmap_event->event_id.header.size += sizeof(mmap_event->min);
9746 - mmap_event->event_id.header.size += sizeof(mmap_event->ino);
9747 - mmap_event->event_id.header.size += sizeof(mmap_event->ino_generation);
9748 - mmap_event->event_id.header.size += sizeof(mmap_event->prot);
9749 - mmap_event->event_id.header.size += sizeof(mmap_event->flags);
9750 - }
9751 -
9752 - perf_event_header__init_id(&mmap_event->event_id.header, &sample, event);
9724 + type = PERF_RECORD_MMAP2;
9725 + size += sizeof(mmap_event->maj);
9726 + size += sizeof(mmap_event->min);
9727 + size += sizeof(mmap_event->ino);
9728 + size += sizeof(mmap_event->ino_generation);
9729 + size += sizeof(mmap_event->prot);
9730 + size += sizeof(mmap_event->flags);
9731 + use_build_id = event->attr.build_id && mmap_event->build_id_size;
9732 + if (use_build_id)
9733 + misc |= PERF_RECORD_MISC_MMAP_BUILD_ID;
9734 + }
9735 + if (!(mmap_event->vma->vm_flags & VM_EXEC))
9736 + misc |= PERF_RECORD_MISC_MMAP_DATA;
9737 +
9738 + perf_event_header__init(&mmap_event->event_id.header, &sample,
9739 + type, misc, size, event);
9753 9740 ret = perf_output_begin(&handle, &sample, event,
9754 9741 mmap_event->event_id.header.size);
9755 9742 if (ret)
9756 - goto out;
9743 + return;
9757 9744
9758 9745 mmap_event->event_id.pid = perf_event_pid(event, current);
9759 9746 mmap_event->event_id.tid = perf_event_tid(event, current);
9760 9747
9761 - use_build_id = event->attr.build_id && mmap_event->build_id_size;
9762 -
9763 - if (event->attr.mmap2 && use_build_id)
9764 - mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID;
9765 -
9766 9748 perf_output_put(&handle, mmap_event->event_id);
9767 9749
9768 9750 if (event->attr.mmap2) {
@@ -9787,9 +9769,6 @@ static void perf_event_mmap_output(struct perf_event *event,
9787 9769 perf_event__output_id_sample(event, &handle, &sample);
9788 9770
9789 9771 perf_output_end(&handle);
9790 - out:
9791 - mmap_event->event_id.header.size = size;
9792 - mmap_event->event_id.header.type = type;
9793 9772 }
9794 9773
9795 9774 static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
@@ -9885,11 +9864,6 @@ got_name:
9885 9864 mmap_event->prot = prot;
9886 9865 mmap_event->flags = flags;
9887 9866
9888 - if (!(vma->vm_flags & VM_EXEC))
9889 - mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA;
9890 -
9891 - mmap_event->event_id.header.size = sizeof(mmap_event->event_id) + size;
9892 -
9893 9867 if (atomic_read(&nr_build_id_events))
9894 9868 build_id_parse_nofault(vma, mmap_event->build_id, &mmap_event->build_id_size);
9895 9869
@@ -10009,11 +9983,7 @@ void perf_event_mmap(struct vm_area_struct *vma)
10009 9983 /* .file_name */
10010 9984 /* .file_size */
10011 9985 .event_id = {
10012 - .header = {
10013 - .type = PERF_RECORD_MMAP,
10014 - .misc = PERF_RECORD_MISC_USER,
10015 - /* .size */
10016 - },
9986 + /* .header */
10017 9987 /* .pid */
10018 9988 /* .tid */
10019 9989 .start = vma->vm_start,
@@ -10043,18 +10013,15 @@ void perf_event_aux_event(struct perf_event *event, unsigned long head,
10043 10013 u64 size;
10044 10014 u64 flags;
10045 10015 } rec = {
10046 - .header = {
10047 - .type = PERF_RECORD_AUX,
10048 - .misc = 0,
10049 - .size = sizeof(rec),
10050 - },
10051 10016 .offset = head,
10052 10017 .size = size,
10053 10018 .flags = flags,
10054 10019 };
10055 10020 int ret;
10056 10021
10057 - perf_event_header__init_id(&rec.header, &sample, event);
10022 + perf_event_header__init(&rec.header, &sample,
10023 + PERF_RECORD_AUX, /* misc= */ 0, sizeof(rec),
10024 + event);
10058 10025 ret = perf_output_begin(&handle, &sample, event, rec.header.size);
10059 10026
10060 10027 if (ret)
@@ -10079,15 +10046,14 @@ void perf_log_lost_samples(struct perf_event *event, u64 lost)
10079 10046 struct perf_event_header header;
10080 10047 u64 lost;
10081 10048 } lost_samples_event = {
10082 - .header = {
10083 - .type = PERF_RECORD_LOST_SAMPLES,
10084 - .misc = 0,
10085 - .size = sizeof(lost_samples_event),
10086 - },
10087 10049 .lost = lost,
10088 10050 };
10089 10051
10090 - perf_event_header__init_id(&lost_samples_event.header, &sample, event);
10052 + perf_event_header__init(&lost_samples_event.header, &sample,
10053 + PERF_RECORD_LOST_SAMPLES,
10054 + /* misc= */ 0,
10055 + sizeof(lost_samples_event),
10056 + event);
10091 10057
10092 10058 ret = perf_output_begin(&handle, &sample, event,
10093 10059 lost_samples_event.header.size);
@@ -10112,6 +10078,8 @@ struct perf_switch_event {
10112 10078 u32 next_prev_pid;
10113 10079 u32 next_prev_tid;
10114 10080 } event_id;
10081 + bool sched_in;
10082 + bool preempt;
10115 10083 };
10116 10084
10117 10085 static int perf_event_switch_match(struct perf_event *event)
@@ -10124,6 +10092,9 @@ static void perf_event_switch_output(struct perf_event *event, void *data)
10124 10092 struct perf_switch_event *se = data;
10125 10093 struct perf_output_handle handle;
10126 10094 struct perf_sample_data sample;
10095 + u32 type;
10096 + u16 misc;
10097 + u16 size;
10127 10098 int ret;
10128 10099
10129 10100 if (!perf_event_switch_match(event))
@@ -10131,18 +10102,22 @@ static void perf_event_switch_output(struct perf_event *event, void *data)
10131 10102
10132 10103 /* Only CPU-wide events are allowed to see next/prev pid/tid */
10133 10104 if (event->ctx->task) {
10134 - se->event_id.header.type = PERF_RECORD_SWITCH;
10135 - se->event_id.header.size = sizeof(se->event_id.header);
10105 + type = PERF_RECORD_SWITCH;
10106 + size = sizeof(se->event_id.header);
10136 10107 } else {
10137 - se->event_id.header.type = PERF_RECORD_SWITCH_CPU_WIDE;
10138 - se->event_id.header.size = sizeof(se->event_id);
10108 + type = PERF_RECORD_SWITCH_CPU_WIDE;
10109 + size = sizeof(se->event_id);
10139 10110 se->event_id.next_prev_pid =
10140 10111 perf_event_pid(event, se->next_prev);
10141 10112 se->event_id.next_prev_tid =
10142 10113 perf_event_tid(event, se->next_prev);
10143 10114 }
10115 + misc = se->sched_in ? 0 : PERF_RECORD_MISC_SWITCH_OUT;
10116 + if (se->preempt)
10117 + misc |= PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
10144 10118
10145 - perf_event_header__init_id(&se->event_id.header, &sample, event);
10119 + perf_event_header__init(&se->event_id.header, &sample,
10120 + type, misc, size, event);
10146 10121
10147 10122 ret = perf_output_begin(&handle, &sample, event, se->event_id.header.size);
10148 10123 if (ret)
@@ -10168,22 +10143,11 @@ static void perf_event_switch(struct task_struct *task,
10168 10143 switch_event = (struct perf_switch_event){
10169 10144 .task = task,
10170 10145 .next_prev = next_prev,
10171 - .event_id = {
10172 - .header = {
10173 - /* .type */
10174 - .misc = sched_in ? 0 : PERF_RECORD_MISC_SWITCH_OUT,
10175 - /* .size */
10176 - },
10177 - /* .next_prev_pid */
10178 - /* .next_prev_tid */
10179 - },
10146 + /* .event_id */
10147 + .sched_in = sched_in,
10148 + .preempt = !sched_in && task_is_runnable(task),
10180 10149 };
10181 10150
10182 - if (!sched_in && task_is_runnable(task)) {
10183 - switch_event.event_id.header.misc |=
10184 - PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
10185 - }
10186 -
10187 10151 perf_iterate_sb(perf_event_switch_output, &switch_event, NULL);
10188 10152 }
10189 10153
@@ -10203,20 +10167,17 @@ static void perf_log_throttle(struct perf_event *event, int enable)
10203 10167 u64 id;
10204 10168 u64 stream_id;
10205 10169 } throttle_event = {
10206 - .header = {
10207 - .type = PERF_RECORD_THROTTLE,
10208 - .misc = 0,
10209 - .size = sizeof(throttle_event),
10210 - },
10211 10170 .time = perf_event_clock(event),
10212 10171 .id = primary_event_id(event),
10213 10172 .stream_id = event->id,
10214 10173 };
10215 10174
10216 - if (enable)
10217 - throttle_event.header.type = PERF_RECORD_UNTHROTTLE;
10218 -
10219 - perf_event_header__init_id(&throttle_event.header, &sample, event);
10175 + perf_event_header__init(&throttle_event.header, &sample,
10176 + enable ? PERF_RECORD_UNTHROTTLE
10177 + : PERF_RECORD_THROTTLE,
10178 + /* misc= */ 0,
10179 + sizeof(throttle_event),
10180 + event);
10220 10181
10221 10182 ret = perf_output_begin(&handle, &sample, event,
10222 10183 throttle_event.header.size);
@@ -10255,12 +10216,14 @@ static void perf_event_ksymbol_output(struct perf_event *event, void *data)
10255 10216 struct perf_output_handle handle;
10256 10217 struct perf_sample_data sample;
10257 10218 int ret;
10219 + u16 size = sizeof(ksymbol_event->event_id) + ksymbol_event->name_len;
10258 10220
10259 10221 if (!perf_event_ksymbol_match(event))
10260 10222 return;
10261 10223
10262 - perf_event_header__init_id(&ksymbol_event->event_id.header,
10263 - &sample, event);
10224 + perf_event_header__init(&ksymbol_event->event_id.header, &sample,
10225 + PERF_RECORD_KSYMBOL, /* misc= */ 0, size,
10226 + event);
10264 10227 ret = perf_output_begin(&handle, &sample, event,
10265 10228 ksymbol_event->event_id.header.size);
10266 10229 if (ret)
@@ -10301,11 +10264,6 @@ void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, bool unregister,
10301 10264 .name = name,
10302 10265 .name_len = name_len,
10303 10266 .event_id = {
10304 - .header = {
10305 - .type = PERF_RECORD_KSYMBOL,
10306 - .size = sizeof(ksymbol_event.event_id) +
10307 - name_len,
10308 - },
10309 10267 .addr = addr,
10310 10268 .len = len,
10311 10269 .ksym_type = ksym_type,
@@ -10349,8 +10307,11 @@ static void perf_event_bpf_output(struct perf_event *event, void *data)
10349 10307 if (!perf_event_bpf_match(event))
10350 10308 return;
10351 10309
10352 - perf_event_header__init_id(&bpf_event->event_id.header,
10353 - &sample, event);
10310 + perf_event_header__init(&bpf_event->event_id.header, &sample,
10311 + PERF_RECORD_BPF_EVENT,
10312 + /* misc= */ 0,
10313 + sizeof(bpf_event->event_id),
10314 + event);
10354 10315 ret = perf_output_begin(&handle, &sample, event,
10355 10316 bpf_event->event_id.header.size);
10356 10317 if (ret)
@@ -10406,10 +10367,6 @@ void perf_event_bpf_event(struct bpf_prog *prog,
10406 10367 bpf_event = (struct perf_bpf_event){
10407 10368 .prog = prog,
10408 10369 .event_id = {
10409 - .header = {
10410 - .type = PERF_RECORD_BPF_EVENT,
10411 - .size = sizeof(bpf_event.event_id),
10412 - },
10413 10370 .type = type,
10414 10371 .flags = flags,
10415 10372 .id = prog->aux->id,
@@ -10437,18 +10394,23 @@ static void perf_callchain_deferred_output(struct perf_event *event, void *data)
10437 10394 struct perf_callchain_deferred_event *deferred_event = data;
10438 10395 struct perf_output_handle handle;
10439 10396 struct perf_sample_data sample;
10440 - int ret, size = deferred_event->event.header.size;
10397 + int ret;
10398 + u16 size = sizeof(deferred_event->event) + (deferred_event->trace->nr * sizeof(u64));
10441 10399
10442 10400 if (!event->attr.defer_output)
10443 10401 return;
10444 10402
10445 10403 /* XXX do we really need sample_id_all for this ??? */
10446 - perf_event_header__init_id(&deferred_event->event.header, &sample, event);
10404 + perf_event_header__init(&deferred_event->event.header, &sample,
10405 + PERF_RECORD_CALLCHAIN_DEFERRED,
10406 + PERF_RECORD_MISC_USER,
10407 + size,
10408 + event);
10447 10409
10448 10410 ret = perf_output_begin(&handle, &sample, event,
10449 10411 deferred_event->event.header.size);
10450 10412 if (ret)
10451 - goto out;
10413 + return;
10452 10414
10453 10415 perf_output_put(&handle, deferred_event->event);
10454 10416 for (int i = 0; i < deferred_event->trace->nr; i++) {
@@ -10458,8 +10420,6 @@ static void perf_callchain_deferred_output(struct perf_event *event, void *data)
10458 10420 perf_event__output_id_sample(event, &handle, &sample);
10459 10421
10460 10422 perf_output_end(&handle);
10461 - out:
10462 - deferred_event->event.header.size = size;
10463 10423 }
10464 10424
10465 10425 static void perf_unwind_deferred_callback(struct unwind_work *work,
@@ -10468,12 +10428,6 @@ static void perf_unwind_deferred_callback(struct unwind_work *work,
10468 10428 struct perf_callchain_deferred_event deferred_event = {
10469 10429 .trace = trace,
10470 10430 .event = {
10471 - .header = {
10472 - .type = PERF_RECORD_CALLCHAIN_DEFERRED,
10473 - .misc = PERF_RECORD_MISC_USER,
10474 - .size = sizeof(deferred_event.event) +
10475 - (trace->nr * sizeof(u64)),
10476 - },
10477 10431 .cookie = cookie,
10478 10432 .nr = trace->nr,
10479 10433 },
@@ -10485,7 +10439,8 @@ static void perf_unwind_deferred_callback(struct unwind_work *work,
10485 10439 struct perf_text_poke_event {
10486 10440 const void *old_bytes;
10487 10441 const void *new_bytes;
10488 - size_t pad;
10442 + u16 tot;
10443 + u16 pad;
10489 10444 u16 old_len;
10490 10445 u16 new_len;
10491 10446
@@ -10506,13 +10461,18 @@ static void perf_event_text_poke_output(struct perf_event *event, void *data)
10506 10461 struct perf_text_poke_event *text_poke_event = data;
10507 10462 struct perf_output_handle handle;
10508 10463 struct perf_sample_data sample;
10464 + u16 size = sizeof(text_poke_event->event_id) + text_poke_event->tot + text_poke_event->pad;
10509 10465 u64 padding = 0;
10510 10466 int ret;
10511 10467
10512 10468 if (!perf_event_text_poke_match(event))
10513 10469 return;
10514 10470
10515 - perf_event_header__init_id(&text_poke_event->event_id.header, &sample, event);
10471 + perf_event_header__init(&text_poke_event->event_id.header, &sample,
10472 + PERF_RECORD_TEXT_POKE,
10473 + PERF_RECORD_MISC_KERNEL,
10474 + size,
10475 + event);
10516 10476
10517 10477 ret = perf_output_begin(&handle, &sample, event,
10518 10478 text_poke_event->event_id.header.size);
@@ -10550,15 +10510,11 @@ void perf_event_text_poke(const void *addr, const void *old_bytes,
10550 10510 text_poke_event = (struct perf_text_poke_event){
10551 10511 .old_bytes = old_bytes,
10552 10512 .new_bytes = new_bytes,
10513 + .tot = tot,
10553 10514 .pad = pad,
10554 10515 .old_len = old_len,
10555 10516 .new_len = new_len,
10556 10517 .event_id = {
10557 - .header = {
10558 - .type = PERF_RECORD_TEXT_POKE,
10559 - .misc = PERF_RECORD_MISC_KERNEL,
10560 - .size = sizeof(text_poke_event.event_id) + tot + pad,
10561 - },
10562 10518 .addr = (unsigned long)addr,
10563 10519 },
10564 10520 };
@@ -10589,13 +10545,12 @@ static void perf_log_itrace_start(struct perf_event *event)
10589 10545 event->attach_state & PERF_ATTACH_ITRACE)
10590 10546 return;
10591 10547
10592 - rec.header.type = PERF_RECORD_ITRACE_START;
10593 - rec.header.misc = 0;
10594 - rec.header.size = sizeof(rec);
10595 10548 rec.pid = perf_event_pid(event, current);
10596 10549 rec.tid = perf_event_tid(event, current);
10597 10550
10598 - perf_event_header__init_id(&rec.header, &sample, event);
10551 + perf_event_header__init(&rec.header, &sample,
10552 + PERF_RECORD_ITRACE_START, /* misc= */ 0, sizeof(rec),
10553 + event);
10599 10554 ret = perf_output_begin(&handle, &sample, event, rec.header.size);
10600 10555
10601 10556 if (ret)
@@ -10620,12 +10575,10 @@ void perf_report_aux_output_id(struct perf_event *event, u64 hw_id)
10620 10575 if (event->parent)
10621 10576 event = event->parent;
10622 10577
10623 - rec.header.type = PERF_RECORD_AUX_OUTPUT_HW_ID;
10624 - rec.header.misc = 0;
10625 - rec.header.size = sizeof(rec);
10626 - rec.hw_id = hw_id;
10627 -
10628 - perf_event_header__init_id(&rec.header, &sample, event);
10578 + rec.hw_id = hw_id;
10579 + perf_event_header__init(&rec.header, &sample,
10580 + PERF_RECORD_AUX_OUTPUT_HW_ID, /* misc= */ 0,
10581 + sizeof(rec), event);
10629 10582 ret = perf_output_begin(&handle, &sample, event, rec.header.size);
10630 10583
10631 10584 if (ret)
@@ -13953,7 +13906,7 @@ SYSCALL_DEFINE5(perf_event_open,
13953 13906 if (err)
13954 13907 return err;
13955 13908
13956 - if (!attr.exclude_kernel ||
13909 + if (!attr.exclude_kernel || attr.text_poke ||
13957 13910 ((attr.sample_type & PERF_SAMPLE_CALLCHAIN) &&
13958 13911 !attr.exclude_callchain_kernel)) {
13959 13912 err = perf_allow_kernel();
modified kernel/events/ring_buffer.c
@@ -246,14 +246,13 @@ __perf_output_begin(struct perf_output_handle *handle,
246 246 handle->size = (1UL << page_shift) - offset;
247 247
248 248 if (unlikely(have_lost)) {
249 - lost_event.header.size = sizeof(lost_event);
250 - lost_event.header.type = PERF_RECORD_LOST;
251 - lost_event.header.misc = 0;
252 249 lost_event.id = event->id;
253 250 lost_event.lost = local_xchg(&rb->lost, 0);
254 251
255 252 /* XXX mostly redundant; @data is already fully initializes */
256 - perf_event_header__init_id(&lost_event.header, data, event);
253 + perf_event_header__init(&lost_event.header, data,
254 + PERF_RECORD_LOST, /* misc= */ 0,
255 + sizeof(lost_event), event);
257 256 perf_output_put(handle, lost_event);
258 257 perf_event__output_id_sample(event, handle, data);
259 258 }
modified kernel/futex/core.c
@@ -213,10 +213,12 @@ static bool __futex_pivot_hash(struct mm_struct *mm, struct futex_private_hash *
213 213 futex_rehash_private(fph, new);
214 214 }
215 215 new->state = FR_PERCPU;
216 - scoped_guard(rcu) {
217 - mmph->batches = get_state_synchronize_rcu();
218 - rcu_assign_pointer(mmph->hash, new);
219 - }
216 + rcu_assign_pointer(mmph->hash, new);
217 + /*
218 + * mmph->batches must reference a grace period which started after
219 + * mmph->hash was assigned. See futex_ref_drop().
220 + */
221 + mmph->batches = get_state_synchronize_rcu();
220 222 kvfree_rcu(fph, rcu);
221 223 return true;
222 224 }
modified kernel/irq/Kconfig
@@ -150,6 +150,18 @@ config IRQ_KUNIT_TEST
150 150
151 151 If unsure, say N.
152 152
153 + config REFCOUNT_INTERRUPT_KUNIT_TEST
154 + tristate "Test refcounted interrupt enable/disable" if !KUNIT_ALL_TESTS
155 + depends on KUNIT
156 + default KUNIT_ALL_TESTS
157 + help
158 + This builds the kunit tests for the refcounted interrupt
159 + infrastructure. It verifies the correctness of single, nested,
160 + and multiple interrupt enable/disable state changes and ensures
161 + that the underlying reference counting mechanisms work as expected.
162 +
163 + If unsure, say N.
164 +
153 165 endmenu
154 166
155 167 config GENERIC_IRQ_MULTI_HANDLER
modified kernel/irq/Makefile
@@ -16,4 +16,4 @@ obj-$(CONFIG_SMP) += affinity.o
16 16 obj-$(CONFIG_GENERIC_IRQ_DEBUGFS) += debugfs.o
17 17 obj-$(CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR) += matrix.o
18 18 obj-$(CONFIG_IRQ_KUNIT_TEST) += irq_test.o
19 - obj-$(CONFIG_KUNIT) += refcount_interrupt_test.o
19 + obj-$(CONFIG_REFCOUNT_INTERRUPT_KUNIT_TEST) += refcount_interrupt_test.o
modified kernel/kprobes.c
@@ -496,14 +496,16 @@ static bool kprobe_queued(struct kprobe *p)
496 496 static struct kprobe *get_optimized_kprobe(kprobe_opcode_t *addr)
497 497 {
498 498 int i;
499 - struct kprobe *p = NULL;
499 + struct kprobe *p;
500 500 struct optimized_kprobe *op;
501 501
502 502 /* Don't check i == 0, since that is a breakpoint case. */
503 - for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++)
503 + for (i = 1; i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++) {
504 504 p = get_kprobe(addr - i);
505 + /* A disabled probe can have prepared, but inactive, optinsns. */
506 + if (!p || !kprobe_optready(p) || kprobe_disarmed(p))
507 + continue;
505 508
506 - if (p && kprobe_optready(p)) {
507 509 op = container_of(p, struct optimized_kprobe, kp);
508 510 if (arch_within_optimized_kprobe(op, addr))
509 511 return p;
modified kernel/module/main.c
@@ -3581,8 +3581,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3581 3581 goto sysfs_cleanup;
3582 3582 }
3583 3583
3584 - if (codetag_load_module(mod))
3585 - goto sysfs_cleanup;
3584 + err = codetag_load_module(mod);
3585 + if (err)
3586 + goto livepatch_cleanup;
3586 3587
3587 3588 /* Get rid of temporary copy. */
3588 3589 free_copy(info, flags);
@@ -3592,6 +3593,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
3592 3593
3593 3594 return do_init_module(mod);
3594 3595
3596 + livepatch_cleanup:
3597 + if (is_livepatch_module(mod))
3598 + free_module_elf(mod);
3595 3599 sysfs_cleanup:
3596 3600 mod_sysfs_teardown(mod);
3597 3601 coming_cleanup:
modified kernel/sysctl.c
@@ -483,7 +483,7 @@ int proc_int_k2u_conv_kop(ulong *u_ptr, const int *k_ptr, bool *negp,
483 483
484 484 if (val < 0) {
485 485 *negp = true;
486 - *u_ptr = k_ptr_op ? -k_ptr_op((ulong)val) : -(ulong)val;
486 + *u_ptr = k_ptr_op ? k_ptr_op(-(ulong)val) : -(ulong)val;
487 487 } else {
488 488 *negp = false;
489 489 *u_ptr = k_ptr_op ? k_ptr_op((ulong)val) : (ulong) val;
modified kernel/time/jiffies.c
@@ -101,6 +101,8 @@ void __init register_refined_jiffies(long cycles_per_second)
101 101 #ifdef CONFIG_SYSCTL
102 102 static ulong mult_hz(const ulong val)
103 103 {
104 + if (val >= ULONG_MAX / HZ)
105 + return ULONG_MAX;
104 106 return val * HZ;
105 107 }
106 108
modified kernel/trace/fprobe.c
@@ -47,6 +47,10 @@ static struct rhltable fprobe_ip_table;
47 47 static DEFINE_MUTEX(fprobe_mutex);
48 48 static struct fgraph_ops fprobe_graph_ops;
49 49
50 + DEFINE_LOCK_GUARD_0(rcu_sched_notrace,
51 + rcu_read_lock_sched_notrace(),
52 + rcu_read_unlock_sched_notrace())
53 +
50 54 static u32 fprobe_node_hashfn(const void *data, u32 len, u32 seed)
51 55 {
52 56 return hash_ptr(*(unsigned long **)data, 32);
@@ -329,16 +333,14 @@ static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
329 333 struct fprobe *fp;
330 334 int bit;
331 335
336 + if (!rcu_is_watching())
337 + return;
338 +
332 339 bit = ftrace_test_recursion_trylock(ip, parent_ip);
333 340 if (bit < 0)
334 341 return;
335 342
336 - /*
337 - * ftrace_test_recursion_trylock() disables preemption, but
338 - * rhltable_lookup() checks whether rcu_read_lcok is held.
339 - * So we take rcu_read_lock() here.
340 - */
341 - rcu_read_lock();
343 + guard(rcu_sched_notrace)();
342 344 head = rhltable_lookup(&fprobe_ip_table, &ip, fprobe_rht_params);
343 345
344 346 rhl_for_each_entry_rcu(node, pos, head, hlist) {
@@ -353,7 +355,6 @@ static void fprobe_ftrace_entry(unsigned long ip, unsigned long parent_ip,
353 355 else
354 356 __fprobe_handler(ip, parent_ip, fp, fregs, NULL);
355 357 }
356 - rcu_read_unlock();
357 358 ftrace_test_recursion_unlock(bit);
358 359 }
359 360 NOKPROBE_SYMBOL(fprobe_ftrace_entry);
@@ -567,10 +568,13 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
567 568 struct fprobe *fp;
568 569 int used, ret;
569 570
571 + if (!rcu_is_watching())
572 + return 0;
573 +
570 574 if (WARN_ON_ONCE(!fregs))
571 575 return 0;
572 576
573 - guard(rcu)();
577 + guard(rcu_sched_notrace)();
574 578 head = rhltable_lookup(&fprobe_ip_table, &func, fprobe_rht_params);
575 579 reserved_words = 0;
576 580 rhl_for_each_entry_rcu(node, pos, head, hlist) {
@@ -665,13 +669,16 @@ static void fprobe_return(struct ftrace_graph_ret *trace,
665 669 int size, curr;
666 670 int size_words;
667 671
672 + if (!rcu_is_watching())
673 + return;
674 +
668 675 fgraph_data = (unsigned long *)fgraph_retrieve_data(gops->idx, &size);
669 676 if (WARN_ON_ONCE(!fgraph_data))
670 677 return;
671 678 size_words = SIZE_IN_LONG(size);
672 679 ret_ip = ftrace_regs_get_instruction_pointer(fregs);
673 680
674 - preempt_disable_notrace();
681 + guard(rcu_sched_notrace)();
675 682
676 683 curr = 0;
677 684 while (size_words > curr) {
@@ -687,7 +694,6 @@ static void fprobe_return(struct ftrace_graph_ret *trace,
687 694 }
688 695 curr += size;
689 696 }
690 - preempt_enable_notrace();
691 697 }
692 698 NOKPROBE_SYMBOL(fprobe_return);
693 699
modified mm/damon/core.c
@@ -3147,7 +3147,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
3147 3147 unsigned long cumulated_sz, cached_esz;
3148 3148 unsigned int score, max_score = 0;
3149 3149
3150 - if (!quota->ms && !quota->sz && list_empty(&quota->goals))
3150 + if (!damos_quota_is_set(quota))
3151 3151 return;
3152 3152
3153 3153 /* First charge window */
modified mm/kasan/common.c
@@ -114,12 +114,23 @@ void kasan_unpoison_task_stack(struct task_struct *task)
114 114 /* Unpoison the stack for the current task beyond a watermark sp value. */
115 115 asmlinkage void kasan_unpoison_task_stack_below(const void *watermark)
116 116 {
117 + void *base;
118 +
119 + /*
120 + * Only the generic mode needs this. In the tag-based mode the
121 + * compiler fully initializes the shadow of stack variables on
122 + * function entry, so stale tags left below the watermark are
123 + * harmless.
124 + */
125 + if (!IS_ENABLED(CONFIG_KASAN_GENERIC))
126 + return;
127 +
117 128 /*
118 129 * Calculate the task stack base address. Avoid using 'current'
119 130 * because this function is called by early resume code which hasn't
120 131 * yet set up the percpu register (%gs).
121 132 */
122 - void *base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1));
133 + base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1));
123 134
124 135 kasan_unpoison(base, watermark - base, false);
125 136 }
modified mm/shmem.c
@@ -1847,8 +1847,11 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
1847 1847
1848 1848 global_orders = shmem_huge_global_enabled(inode, index, write_end,
1849 1849 shmem_huge_force, vma, vm_flags);
1850 - /* Tmpfs huge pages allocation */
1851 - if (!vma || !vma_is_anon_shmem(vma))
1850 + /*
1851 + * Tmpfs huge pages allocation or forced collapse ignores
1852 + * sysfs configs.
1853 + */
1854 + if (!vma || !vma_is_anon_shmem(vma) || shmem_huge_force)
1852 1855 return global_orders;
1853 1856
1854 1857 /*
modified mm/slub.c
@@ -5969,7 +5969,8 @@ alloc_empty:
5969 5969 if (!allow_spin)
5970 5970 return NULL;
5971 5971
5972 - empty = alloc_empty_sheaf(s, GFP_NOWAIT, SLAB_ALLOC_DEFAULT);
5972 + /* Don't wake up kswapd, it will cause deadlock under pi_lock */
5973 + empty = alloc_empty_sheaf(s, __GFP_NOWARN, SLAB_ALLOC_DEFAULT);
5973 5974 if (empty)
5974 5975 goto got_empty;
5975 5976
@@ -6128,7 +6129,6 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
6128 6129 struct slab_sheaf *empty;
6129 6130 struct node_barn *barn;
6130 6131 unsigned int alloc_flags = to_alloc_flags(free_flags);
6131 - gfp_t gfp = allow_spin ? GFP_NOWAIT : __GFP_NOWARN;
6132 6132
6133 6133 /* Bootstrap or debug cache, fall back */
6134 6134 if (unlikely(!cache_has_sheaves(s))) {
@@ -6157,7 +6157,8 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
6157 6157
6158 6158 local_unlock(&s->cpu_sheaves->lock);
6159 6159
6160 - empty = alloc_empty_sheaf(s, gfp, alloc_flags);
6160 + /* Don't wake up kswapd, it will cause deadlock under pi_lock */
6161 + empty = alloc_empty_sheaf(s, __GFP_NOWARN, alloc_flags);
6161 6162
6162 6163 if (!empty)
6163 6164 goto fail;
modified mm/vma.c
@@ -2849,7 +2849,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
2849 2849 {
2850 2850 struct mm_struct *mm = current->mm;
2851 2851 struct vm_area_struct *vma = NULL;
2852 - bool have_mmap_prepare = file && file->f_op->mmap_prepare;
2852 + const bool have_mmap_prepare = file && file->f_op->mmap_prepare;
2853 2853 VMA_ITERATOR(vmi, mm, addr);
2854 2854 const pgoff_t anon_pgoff = addr >> PAGE_SHIFT;
2855 2855 MMAP_STATE(map, mm, &vmi, addr, len, pgoff, anon_pgoff, vma_flags, file);
@@ -2892,7 +2892,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
2892 2892 allocated_new = true;
2893 2893 }
2894 2894
2895 - if (have_mmap_prepare)
2895 + if (have_mmap_prepare && allocated_new)
2896 2896 set_vma_user_defined_fields(vma, &map);
2897 2897
2898 2898 __mmap_complete(&map, vma);
modified net/bluetooth/hci_conn.c
@@ -302,11 +302,13 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
302 302 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
303 303 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
304 304
305 + hci_dev_lock(hdev);
306 +
305 307 switch (conn->codec.id) {
306 308 case BT_CODEC_MSBC:
307 309 if (!find_next_esco_param(conn, esco_param_msbc,
308 310 ARRAY_SIZE(esco_param_msbc)))
309 - return -EINVAL;
311 + goto unlock;
310 312
311 313 param = &esco_param_msbc[conn->attempt - 1];
312 314 cp.tx_coding_format.id = 0x05;
@@ -332,7 +334,7 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
332 334 case BT_CODEC_TRANSPARENT:
333 335 if (!find_next_esco_param(conn, esco_param_msbc,
334 336 ARRAY_SIZE(esco_param_msbc)))
335 - return -EINVAL;
337 + goto unlock;
336 338
337 339 param = &esco_param_msbc[conn->attempt - 1];
338 340 cp.tx_coding_format.id = 0x03;
@@ -359,11 +361,11 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
359 361 if (conn->parent && lmp_esco_capable(conn->parent)) {
360 362 if (!find_next_esco_param(conn, esco_param_cvsd,
361 363 ARRAY_SIZE(esco_param_cvsd)))
362 - return -EINVAL;
364 + goto unlock;
363 365 param = &esco_param_cvsd[conn->attempt - 1];
364 366 } else {
365 367 if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
366 - return -EINVAL;
368 + goto unlock;
367 369 param = &sco_param_cvsd[conn->attempt - 1];
368 370 }
369 371 cp.tx_coding_format.id = 2;
@@ -386,9 +388,11 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
386 388 cp.out_transport_unit_size = 16;
387 389 break;
388 390 default:
389 - return -EINVAL;
391 + goto unlock;
390 392 }
391 393
394 + hci_dev_unlock(hdev);
395 +
392 396 cp.retrans_effort = param->retrans_effort;
393 397 cp.pkt_type = __cpu_to_le16(param->pkt_type);
394 398 cp.max_latency = __cpu_to_le16(param->max_latency);
@@ -397,6 +401,10 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
397 401 return -EIO;
398 402
399 403 return 0;
404 +
405 + unlock:
406 + hci_dev_unlock(hdev);
407 + return -EINVAL;
400 408 }
401 409
402 410 static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
modified net/bluetooth/hci_core.c
@@ -1489,8 +1489,10 @@ int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1489 1489
1490 1490 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type);
1491 1491
1492 + mutex_lock(&hdev->remote_oob_lock);
1492 1493 list_del(&data->list);
1493 1494 kfree(data);
1495 + mutex_unlock(&hdev->remote_oob_lock);
1494 1496
1495 1497 return 0;
1496 1498 }
@@ -1499,10 +1501,12 @@ void hci_remote_oob_data_clear(struct hci_dev *hdev)
1499 1501 {
1500 1502 struct oob_data *data, *n;
1501 1503
1504 + mutex_lock(&hdev->remote_oob_lock);
1502 1505 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) {
1503 1506 list_del(&data->list);
1504 1507 kfree(data);
1505 1508 }
1509 + mutex_unlock(&hdev->remote_oob_lock);
1506 1510 }
1507 1511
1508 1512 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
@@ -1511,11 +1515,14 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1511 1515 {
1512 1516 struct oob_data *data;
1513 1517
1518 + mutex_lock(&hdev->remote_oob_lock);
1514 1519 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type);
1515 1520 if (!data) {
1516 1521 data = kmalloc_obj(*data);
1517 - if (!data)
1522 + if (!data) {
1523 + mutex_unlock(&hdev->remote_oob_lock);
1518 1524 return -ENOMEM;
1525 + }
1519 1526
1520 1527 bacpy(&data->bdaddr, bdaddr);
1521 1528 data->bdaddr_type = bdaddr_type;
@@ -1548,6 +1555,8 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1548 1555
1549 1556 BT_DBG("%s for %pMR", hdev->name, bdaddr);
1550 1557
1558 + mutex_unlock(&hdev->remote_oob_lock);
1559 +
1551 1560 return 0;
1552 1561 }
1553 1562
@@ -2485,6 +2494,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
2485 2494 mutex_init(&hdev->lock);
2486 2495 mutex_init(&hdev->req_lock);
2487 2496 mutex_init(&hdev->mgmt_pending_lock);
2497 + mutex_init(&hdev->remote_oob_lock);
2488 2498
2489 2499 ida_init(&hdev->unset_handle_ida);
2490 2500
@@ -2557,8 +2567,10 @@ int hci_register_dev(struct hci_dev *hdev)
2557 2567 return id;
2558 2568
2559 2569 error = dev_set_name(&hdev->dev, "hci%u", id);
2560 - if (error)
2570 + if (error) {
2571 + ida_free(&hci_index_ida, id);
2561 2572 return error;
2573 + }
2562 2574
2563 2575 hdev->name = dev_name(&hdev->dev);
2564 2576 hdev->id = id;
@@ -3325,6 +3337,8 @@ static void hci_queue_iso(struct hci_conn *conn, struct sk_buff_head *queue,
3325 3337
3326 3338 skb_shinfo(skb)->frag_list = NULL;
3327 3339
3340 + spin_lock_bh(&queue->lock);
3341 +
3328 3342 __skb_queue_tail(queue, skb);
3329 3343
3330 3344 do {
@@ -3339,6 +3353,8 @@ static void hci_queue_iso(struct hci_conn *conn, struct sk_buff_head *queue,
3339 3353
3340 3354 __skb_queue_tail(queue, skb);
3341 3355 } while (list);
3356 +
3357 + spin_unlock_bh(&queue->lock);
3342 3358 }
3343 3359
3344 3360 bt_dev_dbg(hdev, "hcon %p queued %d", conn, skb_queue_len(queue));
@@ -3402,9 +3418,6 @@ static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
3402 3418 struct hci_conn *conn = NULL, *c;
3403 3419 unsigned int num = 0, min = ~0;
3404 3420
3405 - /* We don't have to lock device here. Connections are always
3406 - * added and removed with TX task disabled. */
3407 -
3408 3421 rcu_read_lock();
3409 3422
3410 3423 list_for_each_entry_rcu(c, &h->list, list) {
@@ -3609,13 +3622,15 @@ static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type)
3609 3622 }
3610 3623
3611 3624 /* Schedule SCO */
3612 - static void hci_sched_sco(struct hci_dev *hdev, __u8 type)
3625 + static void __hci_sched_sco(struct hci_dev *hdev, __u8 type)
3613 3626 {
3614 3627 struct hci_conn *conn;
3615 3628 struct sk_buff *skb;
3616 3629 int quote, *cnt;
3617 3630 unsigned int pkts = hdev->sco_pkts;
3618 3631
3632 + lockdep_assert_held(&hdev->lock);
3633 +
3619 3634 bt_dev_dbg(hdev, "type %u", type);
3620 3635
3621 3636 if (!hci_conn_num(hdev, type) || !pkts)
@@ -3650,6 +3665,13 @@ static void hci_sched_sco(struct hci_dev *hdev, __u8 type)
3650 3665 queue_work(hdev->workqueue, &hdev->tx_work);
3651 3666 }
3652 3667
3668 + static void hci_sched_sco(struct hci_dev *hdev, __u8 type)
3669 + {
3670 + hci_dev_lock(hdev);
3671 + __hci_sched_sco(hdev, type);
3672 + hci_dev_unlock(hdev);
3673 + }
3674 +
3653 3675 static void hci_sched_acl_pkt(struct hci_dev *hdev)
3654 3676 {
3655 3677 unsigned int cnt = hdev->acl_cnt;
@@ -3659,6 +3681,8 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev)
3659 3681
3660 3682 __check_timeout(hdev, cnt, ACL_LINK);
3661 3683
3684 + hci_dev_lock(hdev);
3685 +
3662 3686 while (hdev->acl_cnt &&
3663 3687 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
3664 3688 u32 priority = (skb_peek(&chan->data_q))->priority;
@@ -3683,13 +3707,15 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev)
3683 3707 chan->conn->sent++;
3684 3708
3685 3709 /* Send pending SCO packets right away */
3686 - hci_sched_sco(hdev, SCO_LINK);
3687 - hci_sched_sco(hdev, ESCO_LINK);
3710 + __hci_sched_sco(hdev, SCO_LINK);
3711 + __hci_sched_sco(hdev, ESCO_LINK);
3688 3712 }
3689 3713 }
3690 3714
3691 3715 if (cnt != hdev->acl_cnt)
3692 3716 hci_prio_recalculate(hdev, ACL_LINK);
3717 +
3718 + hci_dev_unlock(hdev);
3693 3719 }
3694 3720
3695 3721 static void hci_sched_acl(struct hci_dev *hdev)
@@ -3718,6 +3744,8 @@ static void hci_sched_le(struct hci_dev *hdev)
3718 3744
3719 3745 __check_timeout(hdev, *cnt, LE_LINK);
3720 3746
3747 + hci_dev_lock(hdev);
3748 +
3721 3749 tmp = *cnt;
3722 3750 while (*cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) {
3723 3751 u32 priority = (skb_peek(&chan->data_q))->priority;
@@ -3739,13 +3767,15 @@ static void hci_sched_le(struct hci_dev *hdev)
3739 3767 chan->conn->sent++;
3740 3768
3741 3769 /* Send pending SCO packets right away */
3742 - hci_sched_sco(hdev, SCO_LINK);
3743 - hci_sched_sco(hdev, ESCO_LINK);
3770 + __hci_sched_sco(hdev, SCO_LINK);
3771 + __hci_sched_sco(hdev, ESCO_LINK);
3744 3772 }
3745 3773 }
3746 3774
3747 3775 if (*cnt != tmp)
3748 3776 hci_prio_recalculate(hdev, LE_LINK);
3777 +
3778 + hci_dev_unlock(hdev);
3749 3779 }
3750 3780
3751 3781 /* Schedule iso */
@@ -3764,6 +3794,8 @@ static void hci_sched_iso(struct hci_dev *hdev, __u8 type)
3764 3794
3765 3795 __check_timeout(hdev, *cnt, type);
3766 3796
3797 + hci_dev_lock(hdev);
3798 +
3767 3799 while (*cnt && (conn = hci_low_sent(hdev, type, &quote))) {
3768 3800 while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
3769 3801 BT_DBG("skb %p len %d", skb, skb->len);
@@ -3777,6 +3809,8 @@ static void hci_sched_iso(struct hci_dev *hdev, __u8 type)
3777 3809 (*cnt)--;
3778 3810 }
3779 3811 }
3812 +
3813 + hci_dev_unlock(hdev);
3780 3814 }
3781 3815
3782 3816 static void hci_tx_work(struct work_struct *work)
modified net/bluetooth/hci_debugfs.c
@@ -364,7 +364,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
364 364
365 365 list_for_each_entry(e, &cache->all, all) {
366 366 struct inquiry_data *data = &e->data;
367 - seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
367 + seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %lu\n",
368 368 &data->bdaddr,
369 369 data->pscan_rep_mode, data->pscan_period_mode,
370 370 data->pscan_mode, data->dev_class[2],
modified net/bluetooth/hci_sync.c
@@ -312,6 +312,10 @@ static void hci_cmd_sync_work(struct work_struct *work)
312 312 while (1) {
313 313 struct hci_cmd_sync_work_entry *entry;
314 314
315 + /* Leave the backlog to hci_cmd_sync_clear() */
316 + if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
317 + break;
318 +
315 319 mutex_lock(&hdev->cmd_sync_work_lock);
316 320 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list,
317 321 struct hci_cmd_sync_work_entry,
@@ -658,6 +662,8 @@ void hci_cmd_sync_clear(struct hci_dev *hdev)
658 662 {
659 663 struct hci_cmd_sync_work_entry *entry, *tmp;
660 664
665 + /* cmd_work is disabled, the pending request can only time out */
666 + hci_cmd_sync_cancel_sync(hdev, ENODEV);
661 667 cancel_work_sync(&hdev->cmd_sync_work);
662 668 cancel_work_sync(&hdev->reenable_adv_work);
663 669
@@ -5764,6 +5770,7 @@ int hci_stop_discovery_sync(struct hci_dev *hdev)
5764 5770 {
5765 5771 struct discovery_state *d = &hdev->discovery;
5766 5772 struct inquiry_entry *e;
5773 + bdaddr_t addr;
5767 5774 int err;
5768 5775
5769 5776 bt_dev_dbg(hdev, "state %u", hdev->discovery.state);
@@ -5799,15 +5806,21 @@ int hci_stop_discovery_sync(struct hci_dev *hdev)
5799 5806 return 0;
5800 5807
5801 5808 if (d->state == DISCOVERY_RESOLVING || d->state == DISCOVERY_STOPPING) {
5809 + hci_dev_lock(hdev);
5802 5810 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY,
5803 5811 NAME_PENDING);
5804 - if (!e)
5812 + if (!e) {
5813 + hci_dev_unlock(hdev);
5805 5814 return 0;
5815 + }
5816 +
5817 + bacpy(&addr, &e->data.bdaddr);
5818 + hci_dev_unlock(hdev);
5806 5819
5807 5820 /* Ignore cancel errors since it should interfere with stopping
5808 5821 * of the discovery.
5809 5822 */
5810 - hci_remote_name_cancel_sync(hdev, &e->data.bdaddr);
5823 + hci_remote_name_cancel_sync(hdev, &addr);
5811 5824 }
5812 5825
5813 5826 return 0;
@@ -7236,6 +7249,7 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
7236 7249 bacpy(&cp.bdaddr, &conn->dst);
7237 7250 cp.pscan_rep_mode = 0x02;
7238 7251
7252 + hci_dev_lock(hdev);
7239 7253 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
7240 7254 if (ie) {
7241 7255 if (inquiry_entry_age(ie) <= INQUIRY_ENTRY_AGE_MAX) {
@@ -7247,6 +7261,7 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
7247 7261
7248 7262 memcpy(conn->dev_class, ie->data.dev_class, 3);
7249 7263 }
7264 + hci_dev_unlock(hdev);
7250 7265
7251 7266 cp.pkt_type = cpu_to_le16(conn->pkt_type);
7252 7267 if (lmp_rswitch_capable(hdev) && !(hdev->link_mode & HCI_LM_MASTER))
modified net/bluetooth/rfcomm/tty.c
@@ -462,7 +462,7 @@ static int __rfcomm_release_dev(void __user *arg)
462 462 /* Shut down TTY synchronously before freeing rfcomm_dev */
463 463 tty_port_tty_vhangup(&dev->port);
464 464
465 - if (!test_bit(RFCOMM_TTY_OWNED, &dev->status))
465 + if (!test_and_set_bit(RFCOMM_TTY_OWNED, &dev->status))
466 466 tty_port_put(&dev->port);
467 467
468 468 tty_port_put(&dev->port);
@@ -724,10 +724,9 @@ static int rfcomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
724 724 * when the last process closes the tty. The behaviour is expected by
725 725 * userspace.
726 726 */
727 - if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) {
728 - set_bit(RFCOMM_TTY_OWNED, &dev->status);
727 + if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags) &&
728 + !test_and_set_bit(RFCOMM_TTY_OWNED, &dev->status))
729 729 tty_port_put(&dev->port);
730 - }
731 730
732 731 return 0;
733 732 }
modified net/bluetooth/smp.c
@@ -662,6 +662,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
662 662 else
663 663 bdaddr_type = BDADDR_LE_RANDOM;
664 664
665 + mutex_lock(&hdev->remote_oob_lock);
665 666 oob_data = hci_find_remote_oob_data(hdev, &hcon->dst,
666 667 bdaddr_type);
667 668 if (oob_data && oob_data->present) {
@@ -672,6 +673,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
672 673 SMP_DBG("OOB Remote Confirmation: %16phN", smp->pcnf);
673 674 SMP_DBG("OOB Remote Random: %16phN", smp->rr);
674 675 }
676 + mutex_unlock(&hdev->remote_oob_lock);
675 677
676 678 } else {
677 679 authreq &= ~SMP_AUTH_SC;
modified net/core/dev.c
@@ -3818,20 +3818,36 @@ static netdev_features_t dflt_features_check(struct sk_buff *skb,
3818 3818 return vlan_features_check(skb, features);
3819 3819 }
3820 3820
3821 - static bool skb_gso_has_extension_hdr(const struct sk_buff *skb)
3822 - {
3823 - if (!skb->encapsulation)
3824 - return ((skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6 ||
3825 - (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
3826 - vlan_get_protocol(skb) == htons(ETH_P_IPV6))) &&
3827 - skb_transport_header_was_set(skb) &&
3828 - skb_network_header_len(skb) != sizeof(struct ipv6hdr));
3829 - else
3830 - return (!skb_inner_network_header_was_set(skb) ||
3831 - ((skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6 ||
3832 - (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
3833 - inner_ip_hdr(skb)->version == 6)) &&
3834 - skb_inner_network_header_len(skb) != sizeof(struct ipv6hdr)));
3821 + static bool __skb_has_ipv6_ext_hdr(const struct sk_buff *skb, int nhoff)
3822 + {
3823 + const struct ipv6hdr *ip6h;
3824 + struct ipv6hdr _ip6h;
3825 +
3826 + ip6h = skb_header_pointer(skb, nhoff, sizeof(_ip6h), &_ip6h);
3827 + return ip6h && ip6h->version == 6 && ipv6_ext_hdr(ip6h->nexthdr);
3828 + }
3829 +
3830 + static bool skb_has_ipv6_extension_hdr(const struct sk_buff *skb)
3831 + {
3832 + if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
3833 + if (__skb_has_ipv6_ext_hdr(skb, skb_network_offset(skb)))
3834 + return true;
3835 +
3836 + /* Catch tunnels without skb->encapsulation (e.g., virtio). */
3837 + if (!skb->encapsulation &&
3838 + skb_transport_header_was_set(skb) &&
3839 + skb_network_header_len(skb) != sizeof(struct ipv6hdr))
3840 + return true;
3841 + }
3842 +
3843 + /* Tunnels without an inner network header, such as SCTP-in-UDP or
3844 + * PSP, have no inner IP header and thus no inner extension header.
3845 + */
3846 + if (skb->encapsulation && skb_inner_network_header_was_set(skb) &&
3847 + __skb_has_ipv6_ext_hdr(skb, skb_inner_network_offset(skb)))
3848 + return true;
3849 +
3850 + return false;
3835 3851 }
3836 3852
3837 3853 static netdev_features_t gso_features_check(const struct sk_buff *skb,
@@ -3886,7 +3902,7 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,
3886 3902 * so neither does TSO that depends on it.
3887 3903 */
3888 3904 if (features & NETIF_F_IPV6_CSUM &&
3889 - skb_gso_has_extension_hdr(skb))
3905 + skb_has_ipv6_extension_hdr(skb))
3890 3906 features &= ~(NETIF_F_IPV6_CSUM | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4);
3891 3907
3892 3908 return features;
@@ -3988,8 +4004,7 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,
3988 4004 return 0;
3989 4005
3990 4006 if (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
3991 - if (vlan_get_protocol(skb) == htons(ETH_P_IPV6) &&
3992 - skb_network_header_len(skb) != sizeof(struct ipv6hdr))
4007 + if (skb_has_ipv6_extension_hdr(skb))
3993 4008 goto sw_checksum;
3994 4009
3995 4010 switch (skb->csum_offset) {
@@ -4404,9 +4419,14 @@ EXPORT_SYMBOL(dev_loopback_xmit);
4404 4419 static struct netdev_queue *
4405 4420 netdev_tx_queue_mapping(struct net_device *dev, struct sk_buff *skb)
4406 4421 {
4407 - int qm = skb_get_queue_mapping(skb);
4422 + int queue = skb_get_queue_mapping(skb);
4423 + int capped;
4424 +
4425 + capped = netdev_cap_txqueue(dev, queue);
4426 + if (unlikely(capped != queue))
4427 + skb_set_queue_mapping(skb, capped);
4408 4428
4409 - return netdev_get_tx_queue(dev, netdev_cap_txqueue(dev, qm));
4429 + return netdev_get_tx_queue(dev, capped);
4410 4430 }
4411 4431
4412 4432 #ifndef CONFIG_PREEMPT_RT
@@ -4415,9 +4435,13 @@ static bool netdev_xmit_txqueue_skipped(void)
4415 4435 return __this_cpu_read(softnet_data.xmit.skip_txqueue);
4416 4436 }
4417 4437
4418 - void netdev_xmit_skip_txqueue(bool skip)
4438 + bool netdev_xmit_skip_txqueue(bool skip)
4419 4439 {
4440 + bool prev = netdev_xmit_txqueue_skipped();
4441 +
4420 4442 __this_cpu_write(softnet_data.xmit.skip_txqueue, skip);
4443 +
4444 + return prev;
4421 4445 }
4422 4446 EXPORT_SYMBOL_GPL(netdev_xmit_skip_txqueue);
4423 4447
@@ -4427,9 +4451,13 @@ static bool netdev_xmit_txqueue_skipped(void)
4427 4451 return current->net_xmit.skip_txqueue;
4428 4452 }
4429 4453
4430 - void netdev_xmit_skip_txqueue(bool skip)
4454 + bool netdev_xmit_skip_txqueue(bool skip)
4431 4455 {
4456 + bool prev = netdev_xmit_txqueue_skipped();
4457 +
4432 4458 current->net_xmit.skip_txqueue = skip;
4459 +
4460 + return prev;
4433 4461 }
4434 4462 EXPORT_SYMBOL_GPL(netdev_xmit_skip_txqueue);
4435 4463 #endif
@@ -4848,21 +4876,25 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
4848 4876 tcx_set_ingress(skb, false);
4849 4877 #ifdef CONFIG_NET_EGRESS
4850 4878 if (static_branch_unlikely(&egress_needed_key)) {
4879 + bool skip_txq;
4880 +
4851 4881 if (nf_hook_egress_active()) {
4852 4882 skb = nf_hook_egress(skb, &rc, dev);
4853 4883 if (!skb)
4854 4884 goto out;
4855 4885 }
4856 4886
4857 - netdev_xmit_skip_txqueue(false);
4887 + skip_txq = netdev_xmit_skip_txqueue(false);
4858 4888
4859 4889 nf_skip_egress(skb, true);
4860 4890 skb = sch_handle_egress(skb, &rc, dev);
4861 - if (!skb)
4891 + if (!skb) {
4892 + netdev_xmit_skip_txqueue(skip_txq);
4862 4893 goto out;
4894 + }
4863 4895 nf_skip_egress(skb, false);
4864 4896
4865 - if (netdev_xmit_txqueue_skipped())
4897 + if (netdev_xmit_skip_txqueue(skip_txq))
4866 4898 txq = netdev_tx_queue_mapping(dev, skb);
4867 4899 }
4868 4900 #endif
modified net/core/dev_ioctl.c
@@ -267,7 +267,8 @@ int dev_get_hwtstamp_phylib(struct net_device *dev,
267 267 hwprov->phydev)
268 268 return phy_hwtstamp_get(hwprov->phydev, cfg);
269 269
270 - if (hwprov->source == HWTSTAMP_SOURCE_NETDEV)
270 + if (hwprov->source == HWTSTAMP_SOURCE_NETDEV &&
271 + dev->netdev_ops->ndo_hwtstamp_get)
271 272 return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg);
272 273
273 274 return -EOPNOTSUPP;
modified net/core/gso.c
@@ -117,6 +117,7 @@ struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
117 117
118 118 SKB_GSO_CB(skb)->mac_offset = skb_headroom(skb);
119 119 SKB_GSO_CB(skb)->encap_level = 0;
120 + SKB_GSO_CB(skb)->recursion_counter = 0;
120 121
121 122 skb_reset_mac_header(skb);
122 123 skb_reset_mac_len(skb);
modified net/core/page_pool.c
@@ -951,8 +951,8 @@ static void page_pool_recycle_ring_bulk(struct page_pool *pool,
951 951 }
952 952 }
953 953
954 - page_pool_producer_unlock(pool, in_softirq);
955 954 recycle_stat_add(pool, ring, i);
955 + page_pool_producer_unlock(pool, in_softirq);
956 956
957 957 /* Hopefully all pages were returned into ptr_ring */
958 958 if (likely(i == bulk_len))
modified net/core/skbuff.c
@@ -7409,7 +7409,8 @@ nodefer: kfree_skb_napi_cache(skb);
7409 7409 }
7410 7410
7411 7411 static void skb_splice_csum_page(struct sk_buff *skb, struct page *page,
7412 - size_t offset, size_t len)
7412 + size_t offset, size_t len,
7413 + unsigned int csum_offset)
7413 7414 {
7414 7415 const char *kaddr;
7415 7416 __wsum csum;
@@ -7417,7 +7418,7 @@ static void skb_splice_csum_page(struct sk_buff *skb, struct page *page,
7417 7418 kaddr = kmap_local_page(page);
7418 7419 csum = csum_partial(kaddr + offset, len, 0);
7419 7420 kunmap_local(kaddr);
7420 - skb->csum = csum_block_add(skb->csum, csum, skb->len);
7421 + skb->csum = csum_block_add(skb->csum, csum, csum_offset);
7421 7422 }
7422 7423
7423 7424 /**
@@ -7477,7 +7478,8 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter,
7477 7478 }
7478 7479
7479 7480 if (skb->ip_summed == CHECKSUM_NONE)
7480 - skb_splice_csum_page(skb, page, off, part);
7481 + skb_splice_csum_page(skb, page, off, part,
7482 + skb->len + spliced);
7481 7483
7482 7484 off = 0;
7483 7485 spliced += part;
modified net/core/sock.c
@@ -1034,7 +1034,7 @@ static int sock_reserve_memory(struct sock *sk, int bytes)
1034 1034 bool charged;
1035 1035 int pages;
1036 1036
1037 - if (!mem_cgroup_sk_enabled(sk) || !sk_has_account(sk))
1037 + if (!mem_cgroup_sk_enabled(sk) || !sk_is_tcp(sk))
1038 1038 return -EOPNOTSUPP;
1039 1039
1040 1040 if (!bytes)
@@ -1661,7 +1661,7 @@ set_sndbuf:
1661 1661 {
1662 1662 int delta;
1663 1663
1664 - if (val < 0) {
1664 + if (val < 0 || val > SZ_1G) {
1665 1665 ret = -EINVAL;
1666 1666 break;
1667 1667 }
modified net/ethtool/tsconfig.c
@@ -1,6 +1,7 @@
1 1 // SPDX-License-Identifier: GPL-2.0-only
2 2
3 3 #include <linux/net_tstamp.h>
4 + #include <linux/phy.h>
4 5 #include <linux/ptp_clock_kernel.h>
5 6 #include <net/netdev_lock.h>
6 7
@@ -42,7 +43,9 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
42 43 struct kernel_hwtstamp_config cfg = {};
43 44 int ret;
44 45
45 - if (!dev->netdev_ops->ndo_hwtstamp_get)
46 + if (!dev->netdev_ops->ndo_hwtstamp_get &&
47 + !phy_is_default_hwtstamp(dev->phydev) &&
48 + !netdev_ops_lock_dereference(dev->hwprov, dev))
46 49 return -EOPNOTSUPP;
47 50
48 51 ret = ethnl_ops_begin(dev);
@@ -248,17 +251,6 @@ err_cleanup:
248 251 return ret;
249 252 }
250 253
251 - static int ethnl_set_tsconfig_validate(struct ethnl_req_info *req_base,
252 - struct genl_info *info)
253 - {
254 - const struct net_device_ops *ops = req_base->dev->netdev_ops;
255 -
256 - if (!ops->ndo_hwtstamp_set || !ops->ndo_hwtstamp_get)
257 - return -EOPNOTSUPP;
258 -
259 - return 1;
260 - }
261 -
262 254 static struct hwtstamp_provider *
263 255 tsconfig_set_hwprov_from_desc(struct net_device *dev,
264 256 struct genl_info *info,
@@ -272,7 +264,7 @@ tsconfig_set_hwprov_from_desc(struct net_device *dev,
272 264 int ret;
273 265
274 266 ret = ethtool_net_get_ts_info_by_phc(dev, &ts_info, hwprov_desc);
275 - if (!ret) {
267 + if (!ret && dev->netdev_ops->ndo_hwtstamp_set) {
276 268 /* Found */
277 269 source = HWTSTAMP_SOURCE_NETDEV;
278 270 } else {
@@ -313,6 +305,11 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
313 305 if (!netif_device_present(dev))
314 306 return -ENODEV;
315 307
308 + if (!dev->netdev_ops->ndo_hwtstamp_set &&
309 + !phy_is_default_hwtstamp(dev->phydev) &&
310 + !netdev_ops_lock_dereference(dev->hwprov, dev))
311 + return -EOPNOTSUPP;
312 +
316 313 if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER]) {
317 314 struct hwtstamp_provider_desc __hwprov_desc = {.index = -1};
318 315 struct hwtstamp_provider *__hwprov;
@@ -459,6 +456,5 @@ const struct ethnl_request_ops ethnl_tsconfig_request_ops = {
459 456 .reply_size = tsconfig_reply_size,
460 457 .fill_reply = tsconfig_fill_reply,
461 458
462 - .set_validate = ethnl_set_tsconfig_validate,
463 459 .set = ethnl_set_tsconfig,
464 460 };
modified net/ipv4/af_inet.c
@@ -1375,6 +1375,9 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb,
1375 1375 int id;
1376 1376
1377 1377 skb_reset_network_header(skb);
1378 + if (unlikely(gso_recursion_inc_test(skb,
1379 + IP_TUNNEL_RECURSION_LIMIT)))
1380 + goto out;
1378 1381 nhoff = skb_network_header(skb) - skb_mac_header(skb);
1379 1382 if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
1380 1383 goto out;
modified net/ipv4/tcp_input.c
@@ -4465,6 +4465,12 @@ no_queue:
4465 4465 return 1;
4466 4466
4467 4467 old_ack:
4468 + /* An old ACK can carry new data. Update TS.Recent before SACK
4469 + * processing can trigger a retransmission.
4470 + */
4471 + if (flag & FLAG_UPDATE_TS_RECENT)
4472 + tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
4473 +
4468 4474 /* If data was SACKed, tag it and see if we should send more data.
4469 4475 * If data was DSACKed, see if we can undo a cwnd reduction.
4470 4476 */
modified net/ipv6/addrconf.c
@@ -4874,7 +4874,7 @@ static int modify_prefix_route(struct net *net, struct inet6_ifaddr *ifp,
4874 4874 fib6_clean_expires(f6i);
4875 4875 fib6_may_remove_gc_list(net, f6i);
4876 4876 } else {
4877 - fib6_set_expires(f6i, expires);
4877 + fib6_set_expires(f6i, jiffies + clock_t_to_jiffies(expires));
4878 4878 fib6_add_gc_list(f6i);
4879 4879 }
4880 4880
modified net/ipv6/ip6_offload.c
@@ -17,6 +17,7 @@
17 17 #include <net/udp.h>
18 18 #include <net/gro.h>
19 19 #include <net/gso.h>
20 + #include <net/ip_tunnels.h>
20 21
21 22 #include "ip6_offload.h"
22 23 #include "tcpv6_offload.c"
@@ -104,6 +105,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
104 105 bool gso_partial;
105 106
106 107 skb_reset_network_header(skb);
108 + if (unlikely(gso_recursion_inc_test(skb,
109 + IP_TUNNEL_RECURSION_LIMIT)))
110 + goto out;
107 111 nhoff = skb_network_header(skb) - skb_mac_header(skb);
108 112 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
109 113 goto out;
modified net/ipv6/seg6_iptunnel.c
@@ -129,7 +129,7 @@ static __be32 seg6_make_flowlabel(struct net *net, struct sk_buff *skb,
129 129 u32 hash;
130 130
131 131 if (do_flowlabel > 0) {
132 - hash = skb_get_hash(skb);
132 + hash = skb_get_hash_net(net, skb);
133 133 hash = rol32(hash, 16);
134 134 flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
135 135 } else if (!do_flowlabel && skb->protocol == htons(ETH_P_IPV6)) {
modified net/ipv6/seg6_local.c
@@ -278,13 +278,43 @@ static bool decap_and_validate(struct sk_buff *skb, int proto)
278 278 return true;
279 279 }
280 280
281 - static void advance_nextseg(struct ipv6_sr_hdr *srh, struct in6_addr *daddr)
281 + /* advance the SRH to the next segment and set the IPv6 DA accordingly.
282 + * skb pointers may change: after this call, the caller must evaluate again
283 + * any pointer into the packet data.
284 + *
285 + * This function returns:
286 + * - the SRH on success;
287 + * - NULL when the skb cannot be made writable. In this case, the function
288 + * sets the drop reason to SKB_DROP_REASON_NOMEM.
289 + */
290 + static struct ipv6_sr_hdr *advance_nextseg(struct sk_buff *skb,
291 + struct ipv6_sr_hdr *srh,
292 + enum skb_drop_reason *reason)
282 293 {
283 294 struct in6_addr *addr;
295 + int srhoff;
296 + int wlen;
297 +
298 + srhoff = (unsigned char *)srh - skb->data;
299 + /* we write only the Segment Left field and the IPv6 DA. The segment
300 + * list is only read, and seg6_get_srh() already pulled it into the
301 + * linear area.
302 + */
303 + wlen = srhoff + sizeof(*srh);
304 +
305 + if (unlikely(skb_ensure_writable(skb, wlen))) {
306 + *reason = SKB_DROP_REASON_NOMEM;
307 + return NULL;
308 + }
309 +
310 + /* skb_ensure_writable() may change skb pointers; evaluate srh again */
311 + srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
284 312
285 313 srh->segments_left--;
286 314 addr = srh->segments + srh->segments_left;
287 - *daddr = *addr;
315 + ipv6_hdr(skb)->daddr = *addr;
316 +
317 + return srh;
288 318 }
289 319
290 320 static int
@@ -382,12 +412,26 @@ static bool seg6_next_csid_is_arg_zero(const struct in6_addr *addr,
382 412 return true;
383 413 }
384 414
385 - /* assume that DA.Argument length > 0 */
386 - static void seg6_next_csid_advance_arg(struct in6_addr *addr,
387 - const struct seg6_flavors_info *finfo)
415 + /* assume that DA.Argument length > 0.
416 + * skb pointers may change: after this call, the caller must evaluate again
417 + * any pointer into the packet data.
418 + *
419 + * This function returns:
420 + * - SKB_NOT_DROPPED_YET on success;
421 + * - SKB_DROP_REASON_NOMEM when the skb cannot be made writable.
422 + */
423 + static enum skb_drop_reason
424 + seg6_next_csid_advance_arg(struct sk_buff *skb,
425 + const struct seg6_flavors_info *finfo)
388 426 {
389 427 __u8 fnc_octects = seg6_flv_lcnode_func_octects(finfo);
390 428 __u8 blk_octects = seg6_flv_lcblock_octects(finfo);
429 + struct in6_addr *addr;
430 +
431 + if (unlikely(skb_ensure_writable(skb, sizeof(struct ipv6hdr))))
432 + return SKB_DROP_REASON_NOMEM;
433 +
434 + addr = &ipv6_hdr(skb)->daddr;
391 435
392 436 /* advance DA.Argument */
393 437 memmove(&addr->s6_addr[blk_octects],
@@ -395,6 +439,8 @@ static void seg6_next_csid_advance_arg(struct in6_addr *addr,
395 439 16 - blk_octects - fnc_octects);
396 440
397 441 memset(&addr->s6_addr[16 - fnc_octects], 0x00, fnc_octects);
442 +
443 + return SKB_NOT_DROPPED_YET;
398 444 }
399 445
400 446 static int input_action_end_finish(struct sk_buff *skb,
@@ -408,31 +454,42 @@ static int input_action_end_finish(struct sk_buff *skb,
408 454 static int input_action_end_core(struct sk_buff *skb,
409 455 struct seg6_local_lwt *slwt)
410 456 {
457 + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
411 458 struct ipv6_sr_hdr *srh;
459 + int err = -EINVAL;
412 460
413 461 srh = get_and_validate_srh(skb);
414 462 if (!srh)
415 463 goto drop;
416 464
417 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
465 + srh = advance_nextseg(skb, srh, &reason);
466 + if (!srh) {
467 + err = -ENOMEM;
468 + goto drop;
469 + }
418 470
419 471 return input_action_end_finish(skb, slwt);
420 472
421 473 drop:
422 - kfree_skb(skb);
423 - return -EINVAL;
474 + kfree_skb_reason(skb, reason);
475 + return err;
424 476 }
425 477
426 478 static int end_next_csid_core(struct sk_buff *skb, struct seg6_local_lwt *slwt)
427 479 {
428 480 const struct seg6_flavors_info *finfo = &slwt->flv_info;
429 481 struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
482 + enum skb_drop_reason reason;
430 483
431 484 if (seg6_next_csid_is_arg_zero(daddr, finfo))
432 485 return input_action_end_core(skb, slwt);
433 486
434 487 /* update DA */
435 - seg6_next_csid_advance_arg(daddr, finfo);
488 + reason = seg6_next_csid_advance_arg(skb, finfo);
489 + if (reason) {
490 + kfree_skb_reason(skb, reason);
491 + return -ENOMEM;
492 + }
436 493
437 494 return input_action_end_finish(skb, slwt);
438 495 }
@@ -448,19 +505,25 @@ static int input_action_end_x_finish(struct sk_buff *skb,
448 505 static int input_action_end_x_core(struct sk_buff *skb,
449 506 struct seg6_local_lwt *slwt)
450 507 {
508 + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
451 509 struct ipv6_sr_hdr *srh;
510 + int err = -EINVAL;
452 511
453 512 srh = get_and_validate_srh(skb);
454 513 if (!srh)
455 514 goto drop;
456 515
457 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
516 + srh = advance_nextseg(skb, srh, &reason);
517 + if (!srh) {
518 + err = -ENOMEM;
519 + goto drop;
520 + }
458 521
459 522 return input_action_end_x_finish(skb, slwt);
460 523
461 524 drop:
462 - kfree_skb(skb);
463 - return -EINVAL;
525 + kfree_skb_reason(skb, reason);
526 + return err;
464 527 }
465 528
466 529 static int end_x_next_csid_core(struct sk_buff *skb,
@@ -468,12 +531,17 @@ static int end_x_next_csid_core(struct sk_buff *skb,
468 531 {
469 532 const struct seg6_flavors_info *finfo = &slwt->flv_info;
470 533 struct in6_addr *daddr = &ipv6_hdr(skb)->daddr;
534 + enum skb_drop_reason reason;
471 535
472 536 if (seg6_next_csid_is_arg_zero(daddr, finfo))
473 537 return input_action_end_x_core(skb, slwt);
474 538
475 539 /* update DA */
476 - seg6_next_csid_advance_arg(daddr, finfo);
540 + reason = seg6_next_csid_advance_arg(skb, finfo);
541 + if (reason) {
542 + kfree_skb_reason(skb, reason);
543 + return -ENOMEM;
544 + }
477 545
478 546 return input_action_end_x_finish(skb, slwt);
479 547 }
@@ -760,10 +828,12 @@ pull:
760 828 */
761 829 static int end_flv8986_core(struct sk_buff *skb, struct seg6_local_lwt *slwt)
762 830 {
831 + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
763 832 const struct seg6_flavors_info *finfo = &slwt->flv_info;
764 833 enum seg6_local_flv_action action;
765 834 enum seg6_local_pktinfo pinfo;
766 835 struct ipv6_sr_hdr *srh;
836 + int err = -EINVAL;
767 837 __u32 flvmask;
768 838 int srhoff;
769 839
@@ -787,10 +857,18 @@ static int end_flv8986_core(struct sk_buff *skb, struct seg6_local_lwt *slwt)
787 857 switch (action) {
788 858 case SEG6_LOCAL_FLV_ACT_END:
789 859 /* process the packet as the "standard" End behavior */
790 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
860 + srh = advance_nextseg(skb, srh, &reason);
861 + if (!srh) {
862 + err = -ENOMEM;
863 + goto drop;
864 + }
791 865 break;
792 866 case SEG6_LOCAL_FLV_ACT_PSP:
793 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
867 + srh = advance_nextseg(skb, srh, &reason);
868 + if (!srh) {
869 + err = -ENOMEM;
870 + goto drop;
871 + }
794 872
795 873 if (unlikely(!seg6_pop_srh(skb, srhoff)))
796 874 goto drop;
@@ -807,8 +885,8 @@ static int end_flv8986_core(struct sk_buff *skb, struct seg6_local_lwt *slwt)
807 885 return input_action_end_finish(skb, slwt);
808 886
809 887 drop:
810 - kfree_skb(skb);
811 - return -EINVAL;
888 + kfree_skb_reason(skb, reason);
889 + return err;
812 890 }
813 891
814 892 /* regular endpoint function */
@@ -847,21 +925,27 @@ static int input_action_end_x(struct sk_buff *skb, struct seg6_local_lwt *slwt)
847 925
848 926 static int input_action_end_t(struct sk_buff *skb, struct seg6_local_lwt *slwt)
849 927 {
928 + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
850 929 struct ipv6_sr_hdr *srh;
930 + int err = -EINVAL;
851 931
852 932 srh = get_and_validate_srh(skb);
853 933 if (!srh)
854 934 goto drop;
855 935
856 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
936 + srh = advance_nextseg(skb, srh, &reason);
937 + if (!srh) {
938 + err = -ENOMEM;
939 + goto drop;
940 + }
857 941
858 942 seg6_lookup_nexthop(skb, NULL, slwt->table);
859 943
860 944 return dst_input(skb);
861 945
862 946 drop:
863 - kfree_skb(skb);
864 - return -EINVAL;
947 + kfree_skb_reason(skb, reason);
948 + return err;
865 949 }
866 950
867 951 /* decapsulate and forward inner L2 frame on specified interface */
@@ -1375,6 +1459,7 @@ drop:
1375 1459 static int input_action_end_b6_encap(struct sk_buff *skb,
1376 1460 struct seg6_local_lwt *slwt)
1377 1461 {
1462 + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
1378 1463 struct ipv6_sr_hdr *srh;
1379 1464 int err = -EINVAL;
1380 1465
@@ -1382,7 +1467,11 @@ static int input_action_end_b6_encap(struct sk_buff *skb,
1382 1467 if (!srh)
1383 1468 goto drop;
1384 1469
1385 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
1470 + srh = advance_nextseg(skb, srh, &reason);
1471 + if (!srh) {
1472 + err = -ENOMEM;
1473 + goto drop;
1474 + }
1386 1475
1387 1476 skb_reset_inner_headers(skb);
1388 1477 skb->encapsulation = 1;
@@ -1398,7 +1487,7 @@ static int input_action_end_b6_encap(struct sk_buff *skb,
1398 1487 return dst_input(skb);
1399 1488
1400 1489 drop:
1401 - kfree_skb(skb);
1490 + kfree_skb_reason(skb, reason);
1402 1491 return err;
1403 1492 }
1404 1493
@@ -1434,6 +1523,7 @@ static int input_action_end_bpf(struct sk_buff *skb,
1434 1523 struct seg6_local_lwt *slwt)
1435 1524 {
1436 1525 struct seg6_bpf_srh_state *srh_state;
1526 + enum skb_drop_reason reason;
1437 1527 struct ipv6_sr_hdr *srh;
1438 1528 int ret;
1439 1529
@@ -1442,7 +1532,11 @@ static int input_action_end_bpf(struct sk_buff *skb,
1442 1532 kfree_skb(skb);
1443 1533 return -EINVAL;
1444 1534 }
1445 - advance_nextseg(srh, &ipv6_hdr(skb)->daddr);
1535 + srh = advance_nextseg(skb, srh, &reason);
1536 + if (!srh) {
1537 + kfree_skb_reason(skb, reason);
1538 + return -ENOMEM;
1539 + }
1446 1540
1447 1541 /* The access to the per-CPU buffer srh_state is protected by running
1448 1542 * always in softirq context (with disabled BH). On PREEMPT_RT the
modified net/mac80211/agg-rx.c
@@ -102,7 +102,7 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
102 102 if (!tid_rx)
103 103 return;
104 104
105 - timer_delete_sync(&tid_rx->session_timer);
105 + timer_shutdown_sync(&tid_rx->session_timer);
106 106
107 107 /* make sure ieee80211_sta_reorder_release() doesn't re-arm the timer */
108 108 spin_lock_bh(&tid_rx->reorder_lock);
modified net/mac80211/chan.c
@@ -231,6 +231,13 @@ int ieee80211_chanctx_refcount(struct ieee80211_local *local,
231 231 return num;
232 232 }
233 233
234 + static bool
235 + ieee80211_chanctx_has_replace_partner(struct ieee80211_chanctx *ctx)
236 + {
237 + return ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED &&
238 + ctx->replace_ctx;
239 + }
240 +
234 241 static int ieee80211_num_chanctx(struct ieee80211_local *local, int radio_idx)
235 242 {
236 243 struct ieee80211_chanctx *ctx;
@@ -1405,6 +1412,7 @@ void ieee80211_link_unreserve_chanctx(struct ieee80211_link_data *link)
1405 1412 {
1406 1413 struct ieee80211_sub_if_data *sdata = link->sdata;
1407 1414 struct ieee80211_chanctx *ctx = link->reserved_chanctx;
1415 + struct ieee80211_chanctx *old_ctx = NULL;
1408 1416
1409 1417 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1410 1418
@@ -1418,6 +1426,7 @@ void ieee80211_link_unreserve_chanctx(struct ieee80211_link_data *link)
1418 1426 if (WARN_ON(!ctx->replace_ctx))
1419 1427 return;
1420 1428
1429 + old_ctx = ctx->replace_ctx;
1421 1430 WARN_ON(ctx->replace_ctx->replace_state !=
1422 1431 IEEE80211_CHANCTX_WILL_BE_REPLACED);
1423 1432 WARN_ON(ctx->replace_ctx->replace_ctx != ctx);
@@ -1428,6 +1437,11 @@ void ieee80211_link_unreserve_chanctx(struct ieee80211_link_data *link)
1428 1437
1429 1438 list_del_rcu(&ctx->list);
1430 1439 kfree_rcu(ctx, rcu_head);
1440 +
1441 + if (ieee80211_chanctx_refcount(sdata->local,
1442 + old_ctx) == 0)
1443 + ieee80211_free_chanctx(sdata->local, old_ctx,
1444 + false);
1431 1445 } else {
1432 1446 ieee80211_free_chanctx(sdata->local, ctx, false);
1433 1447 }
@@ -1707,7 +1721,8 @@ ieee80211_link_use_reserved_reassign(struct ieee80211_link_data *link)
1707 1721
1708 1722 ieee80211_check_fast_xmit_iface(sdata);
1709 1723
1710 - if (ieee80211_chanctx_refcount(local, old_ctx) == 0)
1724 + if (ieee80211_chanctx_refcount(local, old_ctx) == 0 &&
1725 + !ieee80211_chanctx_has_replace_partner(old_ctx))
1711 1726 ieee80211_free_chanctx(local, old_ctx, false);
1712 1727
1713 1728 ieee80211_recalc_chanctx_min_def(local, new_ctx);
@@ -1772,7 +1787,8 @@ out:
1772 1787 }
1773 1788
1774 1789 static bool
1775 - ieee80211_link_has_in_place_reservation(struct ieee80211_link_data *link)
1790 + ieee80211_link_has_in_place_reservation(struct ieee80211_link_data *link,
1791 + struct ieee80211_chanctx *ctx)
1776 1792 {
1777 1793 struct ieee80211_sub_if_data *sdata = link->sdata;
1778 1794 struct ieee80211_chanctx *old_ctx, *new_ctx;
@@ -1782,6 +1798,9 @@ ieee80211_link_has_in_place_reservation(struct ieee80211_link_data *link)
1782 1798 new_ctx = link->reserved_chanctx;
1783 1799 old_ctx = ieee80211_link_get_chanctx(link);
1784 1800
1801 + if (new_ctx != ctx)
1802 + return false;
1803 +
1785 1804 if (!old_ctx)
1786 1805 return false;
1787 1806
@@ -1794,6 +1813,12 @@ ieee80211_link_has_in_place_reservation(struct ieee80211_link_data *link)
1794 1813 if (new_ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1795 1814 return false;
1796 1815
1816 + if (new_ctx->replace_ctx != old_ctx)
1817 + return false;
1818 +
1819 + if (old_ctx->replace_ctx != new_ctx)
1820 + return false;
1821 +
1797 1822 return true;
1798 1823 }
1799 1824
@@ -1823,7 +1848,8 @@ static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local,
1823 1848 }
1824 1849
1825 1850 for_each_chanctx_user_reserved(local, ctx, &iter) {
1826 - if (!ieee80211_link_has_in_place_reservation(iter.link))
1851 + if (!ieee80211_link_has_in_place_reservation(iter.link,
1852 + ctx))
1827 1853 continue;
1828 1854
1829 1855 old_ctx = ieee80211_link_get_chanctx(iter.link);
@@ -1925,7 +1951,9 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)
1925 1951
1926 1952 for_each_chanctx_user_assigned(local, ctx->replace_ctx, &iter) {
1927 1953 n_assigned++;
1928 - if (iter.link && iter.link->reserved_chanctx) {
1954 + if (iter.link &&
1955 + ieee80211_link_has_in_place_reservation(iter.link,
1956 + ctx)) {
1929 1957 n_reserved++;
1930 1958 if (iter.link->reserved_ready)
1931 1959 n_ready++;
@@ -1950,7 +1978,8 @@ static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)
1950 1978 use_reserved:
1951 1979 ctx->conf.radar_enabled = false;
1952 1980 for_each_chanctx_user_reserved(local, ctx, &iter) {
1953 - if (ieee80211_link_has_in_place_reservation(iter.link) &&
1981 + if (ieee80211_link_has_in_place_reservation(iter.link,
1982 + ctx) &&
1954 1983 !iter.link->reserved_ready)
1955 1984 return -EAGAIN;
1956 1985
@@ -1991,7 +2020,8 @@ use_reserved:
1991 2020 }
1992 2021
1993 2022 for_each_chanctx_user_reserved(local, ctx, &iter) {
1994 - if (!ieee80211_link_has_in_place_reservation(iter.link))
2023 + if (!ieee80211_link_has_in_place_reservation(iter.link,
2024 + ctx))
1995 2025 continue;
1996 2026
1997 2027 ieee80211_chan_bw_change(local,
@@ -2040,7 +2070,7 @@ use_reserved:
2040 2070 struct ieee80211_bss_conf *link_conf = link->conf;
2041 2071 u64 changed = 0;
2042 2072
2043 - if (!ieee80211_link_has_in_place_reservation(link))
2073 + if (!ieee80211_link_has_in_place_reservation(link, ctx))
2044 2074 continue;
2045 2075
2046 2076 rcu_assign_pointer(link_conf->chanctx_conf,
@@ -2091,7 +2121,8 @@ use_reserved:
2091 2121 for_each_chanctx_user_reserved(local, ctx, &iter) {
2092 2122 struct ieee80211_link_data *link = iter.link;
2093 2123
2094 - if (WARN_ON(ieee80211_link_has_in_place_reservation(link)))
2124 + if (WARN_ON(ieee80211_link_has_in_place_reservation(link,
2125 + ctx)))
2095 2126 continue;
2096 2127
2097 2128 if (!link->reserved_ready)
@@ -2176,7 +2207,8 @@ void __ieee80211_link_release_channel(struct ieee80211_link_data *link,
2176 2207 }
2177 2208
2178 2209 ieee80211_assign_link_chanctx(link, NULL, false);
2179 - if (ieee80211_chanctx_refcount(local, ctx) == 0)
2210 + if (ieee80211_chanctx_refcount(local, ctx) == 0 &&
2211 + !ieee80211_chanctx_has_replace_partner(ctx))
2180 2212 ieee80211_free_chanctx(local, ctx, skip_idle_recalc);
2181 2213
2182 2214 link->radar_required = false;
modified net/mac80211/drop.h
@@ -108,6 +108,7 @@ typedef unsigned int __bitwise ieee80211_rx_result;
108 108 R(RX_DROP_U_UNHANDLED_PREQ) \
109 109 R(RX_DROP_U_UNHANDLED_MGMT_STYPE) \
110 110 R(RX_DROP_U_NO_LINK) \
111 + R(RX_DROP_U_DEFRAG_OVERFLOW) \
111 112 /* this line for the trailing \ - add before this */
112 113
113 114 /* having two enums allows for checking ieee80211_rx_result use with sparse */
modified net/mac80211/fils_aead.c
@@ -89,6 +89,14 @@ static int aes_siv_encrypt(const u8 *key, size_t key_len,
89 89 if (res)
90 90 return res;
91 91
92 + /* With an empty plaintext there is no ciphertext to produce and
93 + * the S2V result is the complete output.
94 + */
95 + if (!plain_len) {
96 + memcpy(out, v, AES_BLOCK_SIZE);
97 + return 0;
98 + }
99 +
92 100 /* Use a temporary buffer of the plaintext to handle need for
93 101 * overwriting this during AES-CTR.
94 102 */
modified net/mac80211/ieee80211_i.h
@@ -2475,7 +2475,7 @@ static inline bool ieee80211_require_encrypted_assoc(__le16 fc,
2475 2475 /* sta_out needs to be checked for ERR_PTR() before using */
2476 2476 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2477 2477 struct sk_buff *skb,
2478 - struct sta_info **sta_out);
2478 + struct sta_info **sta_out, bool bss);
2479 2479
2480 2480 static inline void
2481 2481 ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
modified net/mac80211/iface.c
@@ -998,8 +998,8 @@ static u16 ieee80211_monitor_select_queue(struct net_device *dev,
998 998
999 999 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1000 1000 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
1001 - if (skb->len < len_rthdr + 2 ||
1002 - skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
1001 + if (skb_headlen(skb) < len_rthdr + 2 ||
1002 + skb_headlen(skb) < len_rthdr + ieee80211_hdrlen(hdr->frame_control))
1003 1003 return 0; /* doesn't matter, frame will be dropped */
1004 1004
1005 1005 return ieee80211_select_queue_80211(sdata, skb, hdr);
@@ -1023,6 +1023,13 @@ static int ieee80211_netdev_fill_forward_path(struct net_device_path_ctx *ctx,
1023 1023 struct sta_info *sta;
1024 1024 int ret = -ENOENT;
1025 1025
1026 + if (ctx->ieee80211) {
1027 + path->type = DEV_PATH_IEEE80211;
1028 + path->dev = ctx->dev;
1029 + ctx->dev = NULL;
1030 + return 0;
1031 + }
1032 +
1026 1033 sdata = IEEE80211_DEV_TO_SUB_IF(ctx->dev);
1027 1034 local = sdata->local;
1028 1035
modified net/mac80211/mesh_pathtbl.c
@@ -577,6 +577,12 @@ void mesh_fast_tx_cache(struct ieee80211_sub_if_data *sdata,
577 577 goto unlock_sta;
578 578
579 579 spin_lock(&cache->walk_lock);
580 + if ((READ_ONCE(mpath->flags) & MESH_PATH_DELETED) ||
581 + (mppath && (READ_ONCE(mppath->flags) & MESH_PATH_DELETED))) {
582 + kfree(entry);
583 + goto unlock_cache;
584 + }
585 +
580 586 prev = rhashtable_lookup_get_insert_fast(&cache->rht,
581 587 &entry->rhash,
582 588 fast_tx_rht_params);
@@ -694,8 +700,10 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
694 700 return ERR_PTR(-ENOSPC);
695 701
696 702 new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
697 - if (!new_mpath)
703 + if (!new_mpath) {
704 + atomic_dec(&sdata->u.mesh.mpaths);
698 705 return ERR_PTR(-ENOMEM);
706 + }
699 707
700 708 tbl = &sdata->u.mesh.mesh_paths;
701 709 spin_lock_bh(&tbl->walk_lock);
@@ -708,6 +716,7 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
708 716
709 717 if (mpath) {
710 718 kfree(new_mpath);
719 + atomic_dec(&sdata->u.mesh.mpaths);
711 720
712 721 if (IS_ERR(mpath))
713 722 return mpath;
@@ -733,10 +742,15 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
733 742 if (is_multicast_ether_addr(dst))
734 743 return -EOPNOTSUPP;
735 744
745 + if (!atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS))
746 + return -ENOSPC;
747 +
736 748 new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
737 749
738 - if (!new_mpath)
750 + if (!new_mpath) {
751 + atomic_dec(&sdata->u.mesh.mpaths);
739 752 return -ENOMEM;
753 + }
740 754
741 755 memcpy(new_mpath->mpp, mpp, ETH_ALEN);
742 756 tbl = &sdata->u.mesh.mpp_paths;
@@ -749,10 +763,12 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
749 763 hlist_add_head_rcu(&new_mpath->walk_list, &tbl->walk_head);
750 764 spin_unlock_bh(&tbl->walk_lock);
751 765
752 - if (ret)
766 + if (ret) {
753 767 kfree(new_mpath);
754 - else
768 + atomic_dec(&sdata->u.mesh.mpaths);
769 + } else {
755 770 mesh_fast_tx_flush_addr(sdata, dst);
771 + }
756 772
757 773 sdata->u.mesh.mpp_paths_generation++;
758 774 return ret;
@@ -798,7 +814,8 @@ static void mesh_path_free_rcu(struct mesh_table *tbl,
798 814 struct ieee80211_sub_if_data *sdata = mpath->sdata;
799 815
800 816 spin_lock_bh(&mpath->state_lock);
801 - mpath->flags |= MESH_PATH_RESOLVING | MESH_PATH_DELETED;
817 + WRITE_ONCE(mpath->flags,
818 + mpath->flags | MESH_PATH_RESOLVING | MESH_PATH_DELETED);
802 819 mesh_gate_del(tbl, mpath);
803 820 spin_unlock_bh(&mpath->state_lock);
804 821 timer_shutdown_sync(&mpath->timer);
@@ -812,6 +829,9 @@ static void __mesh_path_del(struct mesh_table *tbl, struct mesh_path *mpath)
812 829 {
813 830 hlist_del_rcu(&mpath->walk_list);
814 831 rhashtable_remove_fast(&tbl->rhead, &mpath->rhash, mesh_rht_params);
832 + spin_lock_bh(&mpath->state_lock);
833 + WRITE_ONCE(mpath->flags, mpath->flags | MESH_PATH_DELETED);
834 + spin_unlock_bh(&mpath->state_lock);
815 835 if (tbl == &mpath->sdata->u.mesh.mpp_paths)
816 836 mesh_fast_tx_flush_addr(mpath->sdata, mpath->dst);
817 837 else
modified net/mac80211/mlme.c
@@ -5877,6 +5877,7 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
5877 5877 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5878 5878 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
5879 5879 const struct cfg80211_bss_ies *bss_ies = NULL;
5880 + struct ieee802_11_elems *bss_elems = NULL;
5880 5881 struct ieee80211_supported_band *sband;
5881 5882 struct ieee802_11_elems *elems;
5882 5883 u16 capab_info;
@@ -6007,7 +6008,6 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
6007 6008 (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT &&
6008 6009 (!elems->vht_cap_elem || !elems->vht_operation)))) {
6009 6010 const struct cfg80211_bss_ies *ies;
6010 - struct ieee802_11_elems *bss_elems;
6011 6011
6012 6012 rcu_read_lock();
6013 6013 ies = rcu_dereference(cbss->ies);
@@ -6069,7 +6069,6 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
6069 6069 "AP bug: VHT operation missing from AssocResp\n");
6070 6070 }
6071 6071 }
6072 - kfree(bss_elems);
6073 6072 }
6074 6073
6075 6074 /*
@@ -6342,6 +6341,7 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
6342 6341 ret = true;
6343 6342 out:
6344 6343 kfree(elems);
6344 + kfree(bss_elems);
6345 6345 kfree(bss_ies);
6346 6346 return ret;
6347 6347 }
modified net/mac80211/rc80211_minstrel_ht.c
@@ -7,6 +7,7 @@
7 7 #include <linux/types.h>
8 8 #include <linux/skbuff.h>
9 9 #include <linux/debugfs.h>
10 + #include <linux/limits.h>
10 11 #include <linux/random.h>
11 12 #include <linux/moduleparam.h>
12 13 #include <linux/ieee80211.h>
@@ -1193,6 +1194,54 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
1193 1194 mi->sample_time = jiffies;
1194 1195 }
1195 1196
1197 + /*
1198 + * Check whether an HT/VHT rate from a TX status entry maps to an entry
1199 + * in the minstrel_ht rate tables. Values that cannot be represented
1200 + * there must not be used for indexing mi->groups[] and the MCS groups.
1201 + */
1202 + static bool
1203 + minstrel_ht_txstat_rate_valid(struct ieee80211_tx_rate *rate)
1204 + {
1205 + unsigned int bw;
1206 +
1207 + if (!(rate->flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)))
1208 + return true;
1209 +
1210 + if (rate->flags & IEEE80211_TX_RC_MCS) {
1211 + /* minstrel_ht supports up to MINSTREL_MAX_STREAMS streams */
1212 + return rate->idx < MINSTREL_MAX_STREAMS * 8;
1213 + }
1214 +
1215 + /* minstrel_ht has no VHT groups for 160 MHz and wider */
1216 + bw = !!(rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) +
1217 + 2 * !!(rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH);
1218 + if ((rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) || bw > BW_80)
1219 + return false;
1220 +
1221 + return ieee80211_rate_get_vht_nss(rate) <= MINSTREL_MAX_STREAMS &&
1222 + ieee80211_rate_get_vht_mcs(rate) < MCS_GROUP_RATES;
1223 + }
1224 +
1225 + static bool
1226 + minstrel_ht_ri_txstat_rate_valid(struct rate_info *rate)
1227 + {
1228 + if (!(rate->flags & (RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_VHT_MCS)))
1229 + return true;
1230 +
1231 + if (rate->flags & RATE_INFO_FLAGS_MCS) {
1232 + /* minstrel_ht supports up to MINSTREL_MAX_STREAMS streams */
1233 + return rate->mcs < MINSTREL_MAX_STREAMS * 8;
1234 + }
1235 +
1236 + /* minstrel_ht has VHT groups only for 20/40/80 MHz */
1237 + if (rate->bw != RATE_INFO_BW_20 && rate->bw != RATE_INFO_BW_40 &&
1238 + rate->bw != RATE_INFO_BW_80)
1239 + return false;
1240 +
1241 + return rate->nss <= MINSTREL_MAX_STREAMS &&
1242 + rate->mcs < MCS_GROUP_RATES;
1243 + }
1244 +
1196 1245 static bool
1197 1246 minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
1198 1247 struct ieee80211_tx_rate *rate)
@@ -1205,9 +1254,8 @@ minstrel_ht_txstat_valid(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
1205 1254 if (!rate->count)
1206 1255 return false;
1207 1256
1208 - if (rate->flags & IEEE80211_TX_RC_MCS ||
1209 - rate->flags & IEEE80211_TX_RC_VHT_MCS)
1210 - return true;
1257 + if (rate->flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
1258 + return minstrel_ht_txstat_rate_valid(rate);
1211 1259
1212 1260 for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++)
1213 1261 if (rate->idx == mp->cck_rates[i])
@@ -1235,9 +1283,9 @@ minstrel_ht_ri_txstat_valid(struct minstrel_priv *mp,
1235 1283 if (!rate_status->try_count)
1236 1284 return false;
1237 1285
1238 - if (rate_status->rate_idx.flags & RATE_INFO_FLAGS_MCS ||
1239 - rate_status->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
1240 - return true;
1286 + if (rate_status->rate_idx.flags &
1287 + (RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_VHT_MCS))
1288 + return minstrel_ht_ri_txstat_rate_valid(&rate_status->rate_idx);
1241 1289
1242 1290 for (i = 0; i < ARRAY_SIZE(mp->cck_rates); i++) {
1243 1291 if (rate_status->rate_idx.legacy ==
@@ -1947,14 +1995,39 @@ minstrel_ht_alloc(struct ieee80211_hw *hw)
1947 1995 }
1948 1996
1949 1997 #ifdef CONFIG_MAC80211_DEBUGFS
1998 + static int minstrel_ht_fixed_rate_idx_get(void *data, u64 *val)
1999 + {
2000 + *val = *(u32 *)data;
2001 + return 0;
2002 + }
2003 +
2004 + static int minstrel_ht_fixed_rate_idx_set(void *data, u64 val)
2005 + {
2006 + u32 idx = val;
2007 +
2008 + /* U32_MAX is the default and keeps fixed rate processing disabled */
2009 + if (val != U32_MAX &&
2010 + (val > U16_MAX ||
2011 + MI_RATE_GROUP(idx) >= ARRAY_SIZE(minstrel_mcs_groups) ||
2012 + MI_RATE_IDX(idx) >= MCS_GROUP_RATES))
2013 + return -EINVAL;
2014 +
2015 + *(u32 *)data = idx;
2016 + return 0;
2017 + }
2018 +
2019 + DEFINE_DEBUGFS_ATTRIBUTE(minstrel_ht_fixed_rate_idx_fops,
2020 + minstrel_ht_fixed_rate_idx_get,
2021 + minstrel_ht_fixed_rate_idx_set, "%llu\n");
2022 +
1950 2023 static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
1951 2024 struct dentry *debugfsdir)
1952 2025 {
1953 2026 struct minstrel_priv *mp = priv;
1954 2027
1955 2028 mp->fixed_rate_idx = (u32) -1;
1956 - debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
1957 - &mp->fixed_rate_idx);
2029 + debugfs_create_file("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
2030 + &mp->fixed_rate_idx, &minstrel_ht_fixed_rate_idx_fops);
1958 2031 }
1959 2032 #endif
1960 2033
modified net/mac80211/rx.c
@@ -2499,6 +2499,12 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2499 2499 }
2500 2500
2501 2501 skb_pull(rx->skb, ieee80211_hdrlen(fc));
2502 + if (unlikely((u32)entry->extra_len + rx->skb->len > U16_MAX)) {
2503 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2504 + __skb_queue_purge(&entry->skb_list);
2505 + return RX_DROP_U_DEFRAG_OVERFLOW;
2506 + }
2507 +
2502 2508 __skb_queue_tail(&entry->skb_list, rx->skb);
2503 2509 entry->last_frag = frag;
2504 2510 entry->extra_len += rx->skb->len;
modified net/mac80211/spectmgmt.c
@@ -111,8 +111,8 @@ validate_chandef_by_ht_vht_oper(struct ieee80211_sub_if_data *sdata,
111 111
112 112 switch (chan_width) {
113 113 case NL80211_CHAN_WIDTH_320:
114 - WARN_ON(1);
115 - break;
114 + chandef->chan = NULL;
115 + return;
116 116 case NL80211_CHAN_WIDTH_160:
117 117 vht_oper.chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
118 118 vht_oper.center_freq_seg1_idx = vht_oper.center_freq_seg0_idx;
modified net/mac80211/sta_info.c
@@ -137,6 +137,8 @@ static void __cleanup_single_sta(struct sta_info *sta)
137 137 struct ieee80211_local *local = sdata->local;
138 138 struct ps_data *ps;
139 139
140 + cancel_work_sync(&sta->drv_deliver_wk);
141 +
140 142 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
141 143 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
142 144 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
@@ -166,8 +168,6 @@ static void __cleanup_single_sta(struct sta_info *sta)
166 168 if (ieee80211_vif_is_mesh(&sdata->vif))
167 169 mesh_sta_cleanup(sta);
168 170
169 - cancel_work_sync(&sta->drv_deliver_wk);
170 -
171 171 /*
172 172 * Destroy aggregation state here. It would be nice to wait for the
173 173 * driver to finish aggregation stop and then clean up, but for now
@@ -1582,6 +1582,8 @@ static void __sta_info_destroy_part2(struct sta_info *sta, bool recalc)
1582 1582
1583 1583 sta->dead = true;
1584 1584
1585 + cancel_work_sync(&sta->drv_deliver_wk);
1586 +
1585 1587 local->num_sta--;
1586 1588 local->sta_generation++;
1587 1589
modified net/mac80211/status.c
@@ -1164,6 +1164,73 @@ void ieee80211_tx_status_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1164 1164 }
1165 1165 EXPORT_SYMBOL(ieee80211_tx_status_skb);
1166 1166
1167 + /*
1168 + * Check whether the HT/VHT rate information in a TX status entry is
1169 + * valid for its encoding. This is not specific to any rate control
1170 + * algorithm; all status consumers rely on the values being sane.
1171 + */
1172 + static bool ieee80211_tx_status_rate_info_valid(const struct rate_info *rate)
1173 + {
1174 + if (rate->flags & RATE_INFO_FLAGS_MCS)
1175 + return rate->mcs < 32;
1176 +
1177 + if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
1178 + return rate->nss >= 1 && rate->nss <= 8 && rate->mcs <= 11;
1179 +
1180 + return true;
1181 + }
1182 +
1183 + static bool
1184 + ieee80211_tx_status_tx_rate_valid(const struct ieee80211_tx_rate *rate)
1185 + {
1186 + if (rate->flags & IEEE80211_TX_RC_MCS)
1187 + return rate->idx < 32;
1188 +
1189 + if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
1190 + return ieee80211_rate_get_vht_mcs(rate) <= 11;
1191 +
1192 + return true;
1193 + }
1194 +
1195 + /*
1196 + * Drop TX status rate entries that don't describe a valid rate. The
1197 + * status information is used by rate control and by other mac80211
1198 + * code, and a malformed entry must not be able to corrupt state beyond
1199 + * the driver that reported it.
1200 + */
1201 + static void
1202 + ieee80211_tx_status_drop_invalid_rates(struct ieee80211_tx_status *status)
1203 + {
1204 + int i;
1205 +
1206 + for (i = 0; i < status->n_rates; i++) {
1207 + struct ieee80211_rate_status *rs = &status->rates[i];
1208 +
1209 + if (ieee80211_tx_status_rate_info_valid(&rs->rate_idx))
1210 + continue;
1211 +
1212 + rs->try_count = 0;
1213 + memset(&rs->rate_idx, 0, sizeof(rs->rate_idx));
1214 + }
1215 +
1216 + if (!status->info)
1217 + return;
1218 +
1219 + for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
1220 + struct ieee80211_tx_rate *rate;
1221 +
1222 + rate = &status->info->status.rates[i];
1223 + if (rate->idx < 0)
1224 + break;
1225 +
1226 + if (ieee80211_tx_status_tx_rate_valid(rate))
1227 + continue;
1228 +
1229 + rate->idx = -1;
1230 + rate->count = 0;
1231 + }
1232 + }
1233 +
1167 1234 void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
1168 1235 struct ieee80211_tx_status *status)
1169 1236 {
@@ -1176,6 +1243,8 @@ void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
1176 1243 bool acked, noack_success, ack_signal_valid;
1177 1244 u16 tx_time_est;
1178 1245
1246 + ieee80211_tx_status_drop_invalid_rates(status);
1247 +
1179 1248 if (pubsta) {
1180 1249 sta = container_of(pubsta, struct sta_info, sta);
1181 1250
@@ -1300,6 +1369,7 @@ void ieee80211_tx_rate_update(struct ieee80211_hw *hw,
1300 1369 .sta = pubsta,
1301 1370 };
1302 1371
1372 + ieee80211_tx_status_drop_invalid_rates(&status);
1303 1373 rate_control_tx_status(local, &status);
1304 1374
1305 1375 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
modified net/mac80211/tx.c
@@ -2091,7 +2091,7 @@ static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2091 2091 (struct ieee80211_radiotap_header *)skb->data;
2092 2092
2093 2093 /* check for not even having the fixed radiotap header part */
2094 - if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2094 + if (unlikely(skb_headlen(skb) < sizeof(struct ieee80211_radiotap_header)))
2095 2095 return false; /* too short to be possibly valid */
2096 2096
2097 2097 /* is it a header version we can trust to find length from? */
@@ -2099,7 +2099,7 @@ static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2099 2099 return false; /* only version 0 is supported */
2100 2100
2101 2101 /* does the skb contain enough to deliver on the alleged length? */
2102 - if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2102 + if (unlikely(skb_headlen(skb) < ieee80211_get_radiotap_len(skb->data)))
2103 2103 return false; /* skb too short for claimed rt header extent */
2104 2104
2105 2105 return true;
@@ -2388,13 +2388,13 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2388 2388 skb_set_network_header(skb, len_rthdr);
2389 2389 skb_set_transport_header(skb, len_rthdr);
2390 2390
2391 - if (skb->len < len_rthdr + 2)
2391 + if (skb_headlen(skb) < len_rthdr + 2)
2392 2392 goto fail;
2393 2393
2394 2394 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2395 2395 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2396 2396
2397 - if (skb->len < len_rthdr + hdrlen)
2397 + if (skb_headlen(skb) < len_rthdr + hdrlen)
2398 2398 goto fail;
2399 2399
2400 2400 /*
@@ -2402,7 +2402,7 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2402 2402 * carrying a rfc1042 header
2403 2403 */
2404 2404 if (ieee80211_is_data(hdr->frame_control) &&
2405 - skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2405 + skb_headlen(skb) >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2406 2406 u8 *payload = (u8 *)hdr + hdrlen;
2407 2407
2408 2408 if (ether_addr_equal(payload, rfc1042_header))
@@ -2532,7 +2532,7 @@ static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2532 2532
2533 2533 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2534 2534 struct sk_buff *skb,
2535 - struct sta_info **sta_out)
2535 + struct sta_info **sta_out, bool bss)
2536 2536 {
2537 2537 struct sta_info *sta;
2538 2538
@@ -2553,7 +2553,10 @@ int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2553 2553 *sta_out = ERR_PTR(-ENOENT);
2554 2554 return 0;
2555 2555 }
2556 - sta = sta_info_get_bss(sdata, skb->data);
2556 + if (bss)
2557 + sta = sta_info_get_bss(sdata, skb->data);
2558 + else
2559 + sta = sta_info_get(sdata, skb->data);
2557 2560 break;
2558 2561 #ifdef CONFIG_MAC80211_MESH
2559 2562 case NL80211_IFTYPE_MESH_POINT:
@@ -4419,7 +4422,8 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
4419 4422 ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
4420 4423 goto out;
4421 4424
4422 - if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
4425 + if (ieee80211_lookup_ra_sta(sdata, skb, &sta,
4426 + skb->protocol == sdata->control_port_protocol))
4423 4427 goto out_free;
4424 4428
4425 4429 if (IS_ERR(sta))
@@ -4731,6 +4735,7 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4731 4735 {
4732 4736 struct ieee80211_tx_info *info;
4733 4737 struct ieee80211_local *local = sdata->local;
4738 + struct ieee80211_chanctx_conf *chanctx_conf;
4734 4739 struct tid_ampdu_tx *tid_tx = NULL;
4735 4740 struct sk_buff *seg, *next;
4736 4741 unsigned int skbs = 0, len = 0;
@@ -4780,6 +4785,16 @@ static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4780 4785 sdata = container_of(sdata->bss,
4781 4786 struct ieee80211_sub_if_data, u.ap);
4782 4787
4788 + /* MLD transmissions must not rely on the band */
4789 + if (!ieee80211_vif_is_mld(&sdata->vif)) {
4790 + chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4791 + if (unlikely(!chanctx_conf)) {
4792 + kfree_skb_list(skb);
4793 + return;
4794 + }
4795 + info->band = chanctx_conf->def.chan->band;
4796 + }
4797 +
4783 4798 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4784 4799 info->control.vif = &sdata->vif;
4785 4800
@@ -4848,7 +4863,10 @@ static void __ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4848 4863
4849 4864 rcu_read_lock();
4850 4865
4851 - if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4866 + if (unlikely(sdata->control_port_protocol == ehdr->h_proto))
4867 + goto skip_offload;
4868 +
4869 + if (ieee80211_lookup_ra_sta(sdata, skb, &sta, false)) {
4852 4870 kfree_skb(skb);
4853 4871 goto out;
4854 4872 }
@@ -4869,8 +4887,7 @@ static void __ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4869 4887 link = &sdata->deflink;
4870 4888 key = rcu_dereference(link->default_multicast_key);
4871 4889 } else if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4872 - !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4873 - sdata->control_port_protocol == ehdr->h_proto)) {
4890 + !test_sta_flag(sta, WLAN_STA_AUTHORIZED))) {
4874 4891 goto skip_offload;
4875 4892 } else {
4876 4893 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
@@ -4931,7 +4948,7 @@ ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4931 4948
4932 4949 rcu_read_lock();
4933 4950
4934 - if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4951 + if (ieee80211_lookup_ra_sta(sdata, skb, &sta, false)) {
4935 4952 kfree_skb(skb);
4936 4953 skb = ERR_PTR(-EINVAL);
4937 4954 goto out;
@@ -5002,7 +5019,7 @@ static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
5002 5019 }
5003 5020 result = ieee80211_tx(sdata, NULL, skb, true);
5004 5021 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
5005 - if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
5022 + if (ieee80211_lookup_ra_sta(sdata, skb, &sta, true)) {
5006 5023 dev_kfree_skb(skb);
5007 5024 return true;
5008 5025 }
@@ -6639,7 +6656,7 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
6639 6656 * AF_PACKET
6640 6657 */
6641 6658 rcu_read_lock();
6642 - err = ieee80211_lookup_ra_sta(sdata, skb, &sta);
6659 + err = ieee80211_lookup_ra_sta(sdata, skb, &sta, true);
6643 6660 if (err) {
6644 6661 dev_kfree_skb(skb);
6645 6662 rcu_read_unlock();
modified net/mctp/device.c
@@ -344,13 +344,13 @@ static struct mctp_dev *mctp_add_dev(struct net_device *dev)
344 344
345 345 mdev->net = mctp_default_net(dev_net(dev));
346 346
347 - /* associate to net_device */
348 347 refcount_set(&mdev->refs, 1);
349 - rcu_assign_pointer(dev->mctp_ptr, mdev);
350 -
351 348 dev_hold(dev);
352 349 mdev->dev = dev;
353 350
351 + /* Associate to net_device, publish the mdev. */
352 + rcu_assign_pointer(dev->mctp_ptr, mdev);
353 +
354 354 return mdev;
355 355 }
356 356
modified net/netfilter/ipset/ip_set_bitmap_gen.h
@@ -159,7 +159,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
159 159
160 160 if (SET_WITH_COUNTER(set))
161 161 ip_set_init_counter(ext_counter(x, set), ext);
162 - if (SET_WITH_COMMENT(set))
162 + if (SET_WITH_COMMENT(set) && !ext->target)
163 163 ip_set_init_comment(set, ext_comment(x, set), ext);
164 164 if (SET_WITH_SKBINFO(set))
165 165 ip_set_init_skbinfo(ext_skbinfo(x, set), ext);
modified net/netfilter/ipvs/ip_vs_conn.c
@@ -1102,6 +1102,9 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
1102 1102 if (cp->protocol != IPPROTO_UDP)
1103 1103 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
1104 1104 flags = cp->flags;
1105 + /* Only visible templates can control multiple connections */
1106 + if (flags & IP_VS_CONN_F_TEMPLATE)
1107 + conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
1105 1108 /* Bind with the destination and its corresponding transmitter */
1106 1109 if (flags & IP_VS_CONN_F_SYNC) {
1107 1110 /* Synced conns are hashed, so they can not get this flag */
modified net/netfilter/ipvs/ip_vs_lblc.c
@@ -203,7 +203,11 @@ ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr,
203 203 if (en->dest == dest)
204 204 return en;
205 205 ip_vs_lblc_del(en);
206 + atomic_dec(&tbl->entries);
206 207 }
208 + if (atomic_read(&tbl->entries) >= tbl->max_size * 3 / 2)
209 + return NULL;
210 +
207 211 en = kmalloc_obj(*en, GFP_ATOMIC);
208 212 if (!en)
209 213 return NULL;
modified net/netfilter/ipvs/ip_vs_lblcr.c
@@ -363,6 +363,9 @@ ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
363 363
364 364 en = ip_vs_lblcr_get(af, tbl, daddr);
365 365 if (!en) {
366 + if (atomic_read(&tbl->entries) >= tbl->max_size * 3 / 2)
367 + return NULL;
368 +
366 369 en = kmalloc_obj(*en, GFP_ATOMIC);
367 370 if (!en)
368 371 return NULL;
modified net/netfilter/ipvs/ip_vs_sync.c
@@ -949,6 +949,21 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
949 949 ip_vs_conn_put(cp);
950 950 }
951 951
952 + /* Check for incompatible flags */
953 + static bool ip_vs_sync_validate_flags(u32 flags)
954 + {
955 + /* We do not expect NO_CPORT, especially to allow lookups
956 + * to hit templates
957 + */
958 + if (flags & IP_VS_CONN_F_NO_CPORT) {
959 + if (flags & IP_VS_CONN_F_TEMPLATE)
960 + return false;
961 + }
962 + if (flags & IP_VS_CONN_F_ONE_PACKET)
963 + return false;
964 + return true;
965 + }
966 +
952 967 /*
953 968 * Process received multicast message for Version 0
954 969 */
@@ -972,8 +987,7 @@ static void ip_vs_process_message_v0(struct netns_ipvs *ipvs, const char *buffer
972 987 return;
973 988 }
974 989 s = (struct ip_vs_sync_conn_v0 *) p;
975 - flags = ntohs(s->flags) | IP_VS_CONN_F_SYNC;
976 - flags &= ~IP_VS_CONN_F_HASHED;
990 + flags = ntohs(s->flags);
977 991 if (flags & IP_VS_CONN_F_SEQ_MASK) {
978 992 opt = (struct ip_vs_sync_conn_options *)&s[1];
979 993 p += FULL_CONN_SIZE;
@@ -986,6 +1000,13 @@ static void ip_vs_process_message_v0(struct netns_ipvs *ipvs, const char *buffer
986 1000 p += SIMPLE_CONN_SIZE;
987 1001 }
988 1002
1003 + if (!ip_vs_sync_validate_flags(flags)) {
1004 + IP_VS_DBG(2, "BACKUP v0, Invalid flags 0x%X\n", flags);
1005 + continue;
1006 + }
1007 + flags &= IP_VS_CONN_F_BACKUP_MASK;
1008 + flags |= IP_VS_CONN_F_SYNC;
1009 +
989 1010 state = ntohs(s->state);
990 1011 if (!(flags & IP_VS_CONN_F_TEMPLATE)) {
991 1012 pp = ip_vs_proto_get(s->protocol);
@@ -1141,7 +1162,13 @@ static inline int ip_vs_proc_sync_conn(struct netns_ipvs *ipvs, __u8 *p, __u8 *m
1141 1162 }
1142 1163
1143 1164 /* Get flags and Mask off unsupported */
1144 - flags = ntohl(s->v4.flags) & IP_VS_CONN_F_BACKUP_MASK;
1165 + flags = ntohl(s->v4.flags);
1166 + if (!ip_vs_sync_validate_flags(flags)) {
1167 + IP_VS_DBG(3, "BACKUP, Invalid flags 0x%X\n", flags);
1168 + retc = 25;
1169 + goto out;
1170 + }
1171 + flags &= IP_VS_CONN_F_BACKUP_MASK;
1145 1172 flags |= IP_VS_CONN_F_SYNC;
1146 1173 state = ntohs(s->v4.state);
1147 1174
modified net/netfilter/nf_flow_table_core.c
@@ -575,7 +575,12 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)
575 575 static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
576 576 struct flow_offload *flow, void *data)
577 577 {
578 - bool teardown = test_bit(NF_FLOW_TEARDOWN, &flow->flags);
578 + bool teardown;
579 +
580 + if (test_bit(NF_FLOW_PENDING, &flow->flags))
581 + return;
582 +
583 + teardown = test_bit(NF_FLOW_TEARDOWN, &flow->flags);
579 584
580 585 if (nf_flow_has_expired(flow) ||
581 586 nf_ct_is_dying(flow->ct) ||
modified net/netfilter/nf_flow_table_offload.c
@@ -995,6 +995,7 @@ static void flow_offload_work_del(struct flow_offload_work *offload)
995 995 flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL);
996 996 if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags))
997 997 flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY);
998 + set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags);
998 999 }
999 1000
1000 1001 static void flow_offload_tuple_stats(struct flow_offload_work *offload,
@@ -1056,13 +1057,8 @@ static void flow_offload_work_handler(struct work_struct *work)
1056 1057 default:
1057 1058 WARN_ON_ONCE(1);
1058 1059 }
1059 -
1060 - clear_bit(NF_FLOW_HW_PENDING, &offload->flow->flags);
1061 - if (offload->cmd == FLOW_CLS_DESTROY) {
1062 - /* Publish after the worker's last flow access. */
1063 - smp_mb__before_atomic();
1064 - set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags);
1065 - }
1060 + smp_mb__before_atomic();
1061 + clear_bit(NF_FLOW_PENDING, &offload->flow->flags);
1066 1062
1067 1063 kfree(offload);
1068 1064 }
@@ -1089,12 +1085,12 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
1089 1085 {
1090 1086 struct flow_offload_work *offload;
1091 1087
1092 - if (test_and_set_bit(NF_FLOW_HW_PENDING, &flow->flags))
1088 + if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
1093 1089 return NULL;
1094 1090
1095 1091 offload = kmalloc_obj(struct flow_offload_work, GFP_ATOMIC);
1096 1092 if (!offload) {
1097 - clear_bit(NF_FLOW_HW_PENDING, &flow->flags);
1093 + clear_bit(NF_FLOW_PENDING, &flow->flags);
1098 1094 return NULL;
1099 1095 }
1100 1096
modified net/netfilter/nf_flow_table_path.c
@@ -53,6 +53,7 @@ static int nft_dev_fill_forward_path(const struct dst_entry *dst_cache,
53 53 struct net_device_path_ctx ctx = {
54 54 .dev = dev,
55 55 .ether_type = ether_type,
56 + .ieee80211 = true,
56 57 };
57 58 struct neighbour *n;
58 59 u8 nud_state;
@@ -114,6 +115,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
114 115 path = &stack->path[i];
115 116 switch (path->type) {
116 117 case DEV_PATH_ETHERNET:
118 + case DEV_PATH_IEEE80211:
117 119 case DEV_PATH_DSA:
118 120 case DEV_PATH_VLAN:
119 121 case DEV_PATH_PPPOE:
@@ -123,6 +125,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
123 125 memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
124 126
125 127 if (path->type == DEV_PATH_ETHERNET ||
128 + path->type == DEV_PATH_IEEE80211 ||
126 129 path->type == DEV_PATH_DSA)
127 130 break;
128 131
modified net/netfilter/nf_nat_bpf.c
@@ -39,6 +39,9 @@ __bpf_kfunc int bpf_ct_set_nat_info(struct nf_conn___init *nfct,
39 39 if (proto != NFPROTO_IPV4 && proto != NFPROTO_IPV6)
40 40 return -EINVAL;
41 41
42 + if (manip != NF_NAT_MANIP_SRC && manip != NF_NAT_MANIP_DST)
43 + return -EINVAL;
44 +
42 45 memset(&range, 0, sizeof(struct nf_nat_range2));
43 46 range.flags = NF_NAT_RANGE_MAP_IPS;
44 47 range.min_addr = *addr;
modified net/netfilter/nf_nat_core.c
@@ -767,8 +767,9 @@ nf_nat_setup_info(struct nf_conn *ct,
767 767 if (nf_ct_is_confirmed(ct))
768 768 return NF_ACCEPT;
769 769
770 - WARN_ON(maniptype != NF_NAT_MANIP_SRC &&
771 - maniptype != NF_NAT_MANIP_DST);
770 + if (WARN_ON(maniptype != NF_NAT_MANIP_SRC &&
771 + maniptype != NF_NAT_MANIP_DST))
772 + return NF_DROP;
772 773
773 774 if (WARN_ON(nf_nat_initialized(ct, maniptype)))
774 775 return NF_DROP;
modified net/netfilter/nft_flow_offload.c
@@ -160,6 +160,7 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx,
160 160 struct nft_flow_offload *priv = nft_expr_priv(expr);
161 161 u8 genmask = nft_genmask_next(ctx->net);
162 162 struct nft_flowtable *flowtable;
163 + int err;
163 164
164 165 if (!tb[NFTA_FLOW_TABLE_NAME])
165 166 return -EINVAL;
@@ -174,7 +175,11 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx,
174 175
175 176 priv->flowtable = flowtable;
176 177
177 - return nf_ct_netns_get(ctx->net, ctx->family);
178 + err = nf_ct_netns_get(ctx->net, ctx->family);
179 + if (err < 0)
180 + nft_use_dec(&flowtable->use);
181 +
182 + return err;
178 183 }
179 184
180 185 static void nft_flow_offload_deactivate(const struct nft_ctx *ctx,
modified net/netfilter/nft_set_rbtree.c
@@ -900,6 +900,8 @@ static void nft_rbtree_gc_scan(struct nft_set *set)
900 900 next = rb_next(node);
901 901
902 902 rbe = rb_entry(node, struct nft_rbtree_elem, node);
903 + if (!nft_set_elem_active(&rbe->ext, NFT_GENMASK_ANY))
904 + continue;
903 905
904 906 /* elements are reversed in the rbtree for historical reasons,
905 907 * from highest to lowest value, that is why end element is
modified net/packet/af_packet.c
@@ -2874,6 +2874,9 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2874 2874 vnet_hdr.hdr_len);
2875 2875 has_vnet_hdr = true;
2876 2876 }
2877 + /* Prevent the byte count from wrapping into a negative errno */
2878 + if (unlikely(tp_len > INT_MAX - len_sum))
2879 + break;
2877 2880 copylen = max_t(int, copylen, hard_header_len);
2878 2881 skb = sock_alloc_send_skb(&po->sk,
2879 2882 hlen + tlen + sizeof(struct sockaddr_ll) +
modified net/sched/act_ct.c
@@ -289,7 +289,7 @@ static bool tcf_ct_flow_is_outdated(const struct flow_offload *flow)
289 289 {
290 290 return test_bit(IPS_SEEN_REPLY_BIT, &flow->ct->status) &&
291 291 test_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status) &&
292 - !test_bit(NF_FLOW_HW_PENDING, &flow->flags) &&
292 + !test_bit(NF_FLOW_PENDING, &flow->flags) &&
293 293 !test_bit(NF_FLOW_HW_ESTABLISHED, &flow->flags);
294 294 }
295 295
modified net/sched/act_skbedit.c
@@ -72,9 +72,8 @@ TC_INDIRECT_SCOPE int tcf_skbedit_act(struct sk_buff *skb,
72 72 }
73 73 if (params->flags & SKBEDIT_F_QUEUE_MAPPING &&
74 74 skb->dev->real_num_tx_queues > params->queue_mapping) {
75 - #ifdef CONFIG_NET_EGRESS
76 - netdev_xmit_skip_txqueue(true);
77 - #endif
75 + if (skb_at_tc_egress(skb))
76 + netdev_xmit_skip_txqueue(true);
78 77 skb_set_queue_mapping(skb, tcf_skbedit_hash(params, skb));
79 78 }
80 79 if (params->flags & SKBEDIT_F_MARK) {
modified net/sched/cls_api.c
@@ -2463,7 +2463,20 @@ replay:
2463 2463 }
2464 2464
2465 2465 errout:
2466 - if (err && tp_state == TP_CREATED)
2466 + if (err && !IS_ERR_OR_NULL(tp) &&
2467 + (tp_state == TP_CREATED || tp->ops->delete_empty))
2468 + /*
2469 + * The request is dropping its reference to tp. If it was
2470 + * the last user (the idr is empty now), reclaim the proto.
2471 + * A tp this request created is reclaimed unconditionally:
2472 + * it is the only owner, so marking it for deletion is
2473 + * safe. Otherwise only classifiers with a delete_empty
2474 + * callback are reclaimed -- the callback admits an empty
2475 + * proto only, so a live shared proto is never unlinked.
2476 + * Classifiers without one (deleting is set
2477 + * unconditionally) are rtnl-serialized, so the raced
2478 + * window this guard closes cannot arise for them.
2479 + */
2467 2480 tcf_chain_tp_delete_empty(chain, tp, rtnl_held, NULL);
2468 2481 errout_tp:
2469 2482 if (chain) {
modified net/sched/sch_codel.c
@@ -205,7 +205,7 @@ static int codel_init(struct Qdisc *sch, struct nlattr *opt,
205 205 codel_params_init(&q->params);
206 206 codel_vars_init(&q->vars);
207 207 codel_stats_init(&q->stats);
208 - q->params.mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 256, 1 << 20);
208 + q->params.mtu = min_t(u32, psched_mtu(qdisc_dev(sch)), 1 << 20);
209 209
210 210 if (opt) {
211 211 int err = codel_change(sch, opt, extack);
modified net/sched/sch_fq_codel.c
@@ -517,8 +517,8 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
517 517 q->flows_cnt = 1024;
518 518 q->memory_limit = 32 << 20; /* 32 MBytes */
519 519 q->drop_batch_size = 64;
520 - mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 256, FQ_CODEL_QUANTUM_MAX);
521 - q->quantum = mtu;
520 + mtu = min_t(u32, psched_mtu(qdisc_dev(sch)), FQ_CODEL_QUANTUM_MAX);
521 + q->quantum = clamp_t(u32, mtu, 256, FQ_CODEL_QUANTUM_MAX);
522 522 INIT_LIST_HEAD(&q->new_flows);
523 523 INIT_LIST_HEAD(&q->old_flows);
524 524 codel_params_init(&q->cparams);
modified net/sctp/socket.c
@@ -1844,7 +1844,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1844 1844 if (asoc->ep->intl_enable) {
1845 1845 timeo = sock_sndtimeo(sk, 0);
1846 1846 err = sctp_wait_for_connect(asoc, &timeo);
1847 - if (err) {
1847 + if (err || sk->sk_shutdown & RCV_SHUTDOWN) {
1848 1848 err = -ESRCH;
1849 1849 goto err;
1850 1850 }
modified net/tipc/crypto.c
@@ -144,7 +144,7 @@ struct tipc_tfm {
144 144 * @rcu: struct rcu_head
145 145 * @key: the aead key
146 146 * @gen: the key's generation
147 - * @seqno: the key seqno (cluster scope)
147 + * @seqno: the per-key TX nonce counter
148 148 * @refcnt: the key reference counter
149 149 */
150 150 struct tipc_aead {
@@ -190,7 +190,6 @@ struct tipc_crypto_stats {
190 190 * @rekeying_intv: rekeying interval (in minutes)
191 191 * @stats: the crypto statistics
192 192 * @name: the crypto name
193 - * @sndnxt: the per-peer sndnxt (TX)
194 193 * @timer1: general timer 1 (jiffies)
195 194 * @timer2: general timer 2 (jiffies)
196 195 * @working: the crypto is working or not
@@ -219,7 +218,6 @@ struct tipc_crypto {
219 218 struct tipc_crypto_stats __percpu *stats;
220 219 char name[48];
221 220
222 - atomic64_t sndnxt ____cacheline_aligned;
223 221 unsigned long timer1;
224 222 unsigned long timer2;
225 223 union {
@@ -1051,14 +1049,11 @@ static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
1051 1049 WARN_ON(skb_headroom(skb) < ehsz);
1052 1050 ehdr = (struct tipc_ehdr *)skb_push(skb, ehsz);
1053 1051
1054 - /* Obtain a seqno first:
1055 - * Use the key seqno (= cluster wise) if dest is unknown or we're in
1056 - * cluster key mode, otherwise it's better for a per-peer seqno!
1052 + /*
1053 + * Keep the nonce unique for the lifetime of the TX key,
1054 + * including key state changes and peer reconnection.
1057 1055 */
1058 - if (!__rx || aead->mode == CLUSTER_KEY)
1059 - seqno = atomic64_inc_return(&aead->seqno);
1060 - else
1061 - seqno = atomic64_inc_return(&__rx->sndnxt);
1056 + seqno = atomic64_inc_return(&aead->seqno);
1062 1057
1063 1058 /* Revoke the key if seqno is wrapped around */
1064 1059 if (unlikely(!seqno))
@@ -1237,7 +1232,6 @@ void tipc_crypto_key_flush(struct tipc_crypto *c)
1237 1232 tipc_crypto_key_set_state(c, 0, 0, 0);
1238 1233 for (k = KEY_MIN; k <= KEY_MAX; k++)
1239 1234 tipc_crypto_key_detach(c->aead[k], &c->lock);
1240 - atomic64_set(&c->sndnxt, 0);
1241 1235 spin_unlock_bh(&c->lock);
1242 1236 }
1243 1237
@@ -1384,8 +1378,6 @@ done:
1384 1378 * It also considers if peer has no key, then we need to make own master key
1385 1379 * (if any) taking over i.e. starting grace period and also trigger key
1386 1380 * distributing process.
1387 - *
1388 - * The "per-peer" sndnxt is also reset when the peer key has switched.
1389 1381 */
1390 1382 static void tipc_crypto_key_synch(struct tipc_crypto *rx, struct sk_buff *skb)
1391 1383 {
@@ -1436,7 +1428,6 @@ static void tipc_crypto_key_synch(struct tipc_crypto *rx, struct sk_buff *skb)
1436 1428 if (cur)
1437 1429 tipc_aead_users_dec(tx->aead[cur], 0);
1438 1430
1439 - atomic64_set(&rx->sndnxt, 0);
1440 1431 /* Mark the point TX key users changed */
1441 1432 tx->timer1 = jiffies;
1442 1433
@@ -1501,7 +1492,6 @@ int tipc_crypto_start(struct tipc_crypto **crypto, struct net *net,
1501 1492 tipc_crypto_key_set_state(c, 0, 0, 0);
1502 1493 atomic_set(&c->key_distr, 0);
1503 1494 atomic_set(&c->peer_rx_active, 0);
1504 - atomic64_set(&c->sndnxt, 0);
1505 1495 c->timer1 = jiffies;
1506 1496 c->timer2 = jiffies;
1507 1497 c->rekeying_intv = TIPC_REKEYING_INTV_DEF;
modified net/wireless/nl80211.c
@@ -4563,12 +4563,13 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
4563 4563 rdev->wiphy.retry_long = retry_long;
4564 4564 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
4565 4565 rdev->wiphy.frag_threshold = frag_threshold;
4566 - if ((changed & WIPHY_PARAM_RTS_THRESHOLD) &&
4567 - old_radio_rts_threshold) {
4566 + if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
4568 4567 rdev->wiphy.rts_threshold = rts_threshold;
4569 - for (i = 0 ; i < rdev->wiphy.n_radio; i++)
4570 - rdev->wiphy.radio_cfg[i].rts_threshold =
4571 - rdev->wiphy.rts_threshold;
4568 + if (old_radio_rts_threshold) {
4569 + for (i = 0; i < rdev->wiphy.n_radio; i++)
4570 + rdev->wiphy.radio_cfg[i].rts_threshold =
4571 + rdev->wiphy.rts_threshold;
4572 + }
4572 4573 }
4573 4574 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
4574 4575 rdev->wiphy.coverage_class = coverage_class;
modified net/wireless/scan.c
@@ -1992,20 +1992,22 @@ cfg80211_update_known_bss(struct cfg80211_registered_device *rdev,
1992 1992 return false;
1993 1993 }
1994 1994
1995 - old = rcu_access_pointer(known->pub.beacon_ies);
1995 + if (!new->pub.hidden_beacon_bss) {
1996 + old = rcu_access_pointer(known->pub.beacon_ies);
1996 1997
1997 - rcu_assign_pointer(known->pub.beacon_ies, new->pub.beacon_ies);
1998 + rcu_assign_pointer(known->pub.beacon_ies, new->pub.beacon_ies);
1998 1999
1999 - /* Override IEs if they were from a beacon before */
2000 - if (old == rcu_access_pointer(known->pub.ies))
2001 - rcu_assign_pointer(known->pub.ies, new->pub.beacon_ies);
2000 + /* Override IEs if they were from a beacon before */
2001 + if (old == rcu_access_pointer(known->pub.ies))
2002 + rcu_assign_pointer(known->pub.ies, new->pub.beacon_ies);
2002 2003
2003 - cfg80211_update_hidden_bsses(known,
2004 - rcu_access_pointer(new->pub.beacon_ies),
2005 - old);
2004 + cfg80211_update_hidden_bsses(known,
2005 + rcu_access_pointer(new->pub.beacon_ies),
2006 + old);
2006 2007
2007 - if (old)
2008 - kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
2008 + if (old)
2009 + kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
2010 + }
2009 2011 }
2010 2012
2011 2013 known->pub.beacon_interval = new->pub.beacon_interval;
modified rust/kernel/net/netlink.rs
@@ -11,6 +11,7 @@
11 11 use kernel::{
12 12 alloc::{self, AllocError},
13 13 error::to_result,
14 + num::casts::u16_as_usize,
14 15 prelude::*,
15 16 transmute::AsBytes,
16 17 types::Opaque,
@@ -86,9 +87,17 @@ impl GenlMsg {
86 87 where
87 88 T: ?Sized + AsBytes,
88 89 {
90 + // `nla_len` is a 16-bit field that encodes the total attribute length
91 + // (header + payload). Subtracting the header size from `u16::MAX` gives
92 + // the largest payload that still fits within that field.
93 + const MAX_PAYLOAD_LEN: usize = u16_as_usize(u16::MAX) - size_of::<bindings::nlattr>();
94 +
89 95 let skb = self.skb.skb.as_ptr();
90 96 let len = size_of_val(value);
91 97 let ptr = core::ptr::from_ref(value).cast::<c_void>();
98 + if len > MAX_PAYLOAD_LEN {
99 + return Err(EMSGSIZE);
100 + }
92 101 // SAFETY: `skb` is valid by `NetlinkSkBuff` type invariants, and the provided value is
93 102 // readable and initialized for its `size_of` bytes.
94 103 to_result(unsafe { bindings::nla_put(skb, attrtype, len as c_int, ptr) })
modified sound/core/seq/seq_compat.c
@@ -44,7 +44,9 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned
44 44 return -EFAULT;
45 45 data->kernel = NULL;
46 46
47 - err = snd_seq_kernel_client_ctl(client->number, cmd, data);
47 + scoped_guard(mutex, &client->ioctl_mutex) {
48 + err = snd_seq_kernel_client_ctl(client->number, cmd, data);
49 + }
48 50 if (err < 0)
49 51 return err;
50 52
modified sound/hda/codecs/realtek/alc269.c
@@ -4025,6 +4025,7 @@ enum {
4025 4025 ALC269_FIXUP_SONY_VAIO,
4026 4026 ALC275_FIXUP_SONY_VAIO_GPIO2,
4027 4027 ALC269_FIXUP_DELL_M101Z,
4028 + ALC256_FIXUP_ASUS_PM3406CHA,
4028 4029 ALC269_FIXUP_SKU_IGNORE,
4029 4030 ALC269_FIXUP_ASUS_G73JW,
4030 4031 ALC269_FIXUP_ASUS_N7601ZM_PINS,
@@ -4124,6 +4125,7 @@ enum {
4124 4125 ALC285_FIXUP_HP_SPECTRE_X360_EB1,
4125 4126 ALC285_FIXUP_HP_SPECTRE_X360_DF1,
4126 4127 ALC285_FIXUP_HP_ENVY_X360,
4128 + ALC285_FIXUP_HP_ENVY_13AQ,
4127 4129 ALC288_FIXUP_DELL_HEADSET_MODE,
4128 4130 ALC288_FIXUP_DELL1_MIC_NO_PRESENCE,
4129 4131 ALC288_FIXUP_DELL_XPS_13,
@@ -4199,6 +4201,7 @@ enum {
4199 4201 ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE,
4200 4202 ALC225_FIXUP_WYSE_AUTO_MUTE,
4201 4203 ALC225_FIXUP_WYSE_DISABLE_MIC_VREF,
4204 + ALC225_FIXUP_HP_AIO_SPK,
4202 4205 ALC286_FIXUP_ACER_AIO_HEADSET_MIC,
4203 4206 ALC256_FIXUP_ASUS_HEADSET_MIC,
4204 4207 ALC256_FIXUP_ASUS_MIC_NO_PRESENCE,
@@ -4384,6 +4387,7 @@ enum {
4384 4387 ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN_HEADSET,
4385 4388 ALC285_LENOVO_DAC_RENAME,
4386 4389 ALC287_FIXUP_YOGA9_SPEAKER2_TO_DAC1,
4390 + ALC256_FIXUP_IPASON_SMARTBOOK_S1,
4387 4391 };
4388 4392
4389 4393 /* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -4481,6 +4485,14 @@ static const struct hda_fixup alc269_fixups[] = {
4481 4485 {}
4482 4486 }
4483 4487 },
4488 + [ALC256_FIXUP_ASUS_PM3406CHA] = {
4489 + .type = HDA_FIXUP_VERBS,
4490 + .v.verbs = (const struct hda_verb[]) {
4491 + { 0x20, AC_VERB_SET_COEF_INDEX, 0x10 },
4492 + { 0x20, AC_VERB_SET_PROC_COEF, 0x7f20 },
4493 + {}
4494 + }
4495 + },
4484 4496 [ALC269_FIXUP_SKU_IGNORE] = {
4485 4497 .type = HDA_FIXUP_FUNC,
4486 4498 .v.func = alc_fixup_sku_ignore,
@@ -5719,6 +5731,14 @@ static const struct hda_fixup alc269_fixups[] = {
5719 5731 .chained = true,
5720 5732 .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
5721 5733 },
5734 + [ALC225_FIXUP_HP_AIO_SPK] = {
5735 + .type = HDA_FIXUP_VERBS,
5736 + .v.verbs = (const struct hda_verb[]) {
5737 + { 0x20, AC_VERB_SET_COEF_INDEX, 0x10 },
5738 + { 0x20, AC_VERB_SET_PROC_COEF, 0x0220 },
5739 + { }
5740 + },
5741 + },
5722 5742 [ALC286_FIXUP_ACER_AIO_HEADSET_MIC] = {
5723 5743 .type = HDA_FIXUP_VERBS,
5724 5744 .v.verbs = (const struct hda_verb[]) {
@@ -6400,6 +6420,15 @@ static const struct hda_fixup alc269_fixups[] = {
6400 6420 .chained = true,
6401 6421 .chain_id = ALC285_FIXUP_HP_GPIO_AMP_INIT,
6402 6422 },
6423 + [ALC285_FIXUP_HP_ENVY_13AQ] = {
6424 + .type = HDA_FIXUP_PINS,
6425 + .v.pins = (const struct hda_pintbl[]) {
6426 + { 0x14, 0x90170150 }, /* front speakers */
6427 + { }
6428 + },
6429 + .chained = true,
6430 + .chain_id = ALC285_FIXUP_HP_GPIO_AMP_INIT,
6431 + },
6403 6432 [ALC287_FIXUP_IDEAPAD_BASS_SPK_AMP] = {
6404 6433 .type = HDA_FIXUP_FUNC,
6405 6434 .v.func = alc285_fixup_ideapad_s740_coef,
@@ -7087,6 +7116,8 @@ static const struct hda_fixup alc269_fixups[] = {
7087 7116 [ALC236_FIXUP_DELL_HP_POP_NOISE] = {
7088 7117 .type = HDA_FIXUP_FUNC,
7089 7118 .v.func = alc285_fixup_invalidate_dacs,
7119 + .chained = true,
7120 + .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
7090 7121 },
7091 7122 [ALC274_FIXUP_HP_89E9_GPIO] = {
7092 7123 .type = HDA_FIXUP_FUNC,
@@ -7136,6 +7167,13 @@ static const struct hda_fixup alc269_fixups[] = {
7136 7167 .chained = true,
7137 7168 .chain_id = ALC287_FIXUP_TXNW2781_I2C,
7138 7169 },
7170 + [ALC256_FIXUP_IPASON_SMARTBOOK_S1] = {
7171 + .type = HDA_FIXUP_PINS,
7172 + .v.pins = (const struct hda_pintbl[]) {
7173 + { 0x1b, 0x90170110 }, /* the real internal speaker */
7174 + { }
7175 + },
7176 + },
7139 7177 };
7140 7178
7141 7179 static const struct hda_quirk alc269_fixup_tbl[] = {
@@ -7183,6 +7221,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7183 7221 SND_PCI_QUIRK(0x1025, 0x142b, "Acer Swift SF314-42", ALC255_FIXUP_ACER_MIC_NO_PRESENCE),
7184 7222 SND_PCI_QUIRK(0x1025, 0x1430, "Acer TravelMate B311R-31", ALC256_FIXUP_ACER_MIC_NO_PRESENCE),
7185 7223 SND_PCI_QUIRK(0x1025, 0x1466, "Acer Aspire A515-56", ALC255_FIXUP_ACER_HEADPHONE_AND_MIC),
7224 + SND_PCI_QUIRK(0x1025, 0x151e, "Acer Nitro AN515-45", ALC2XX_FIXUP_HEADSET_MIC),
7186 7225 SND_PCI_QUIRK(0x1025, 0x1534, "Acer Predator PH315-54", ALC255_FIXUP_ACER_MIC_NO_PRESENCE),
7187 7226 SND_PCI_QUIRK(0x1025, 0x1539, "Acer Nitro 5 AN515-57", ALC2XX_FIXUP_HEADSET_MIC),
7188 7227 SND_PCI_QUIRK(0x1025, 0x159c, "Acer Nitro 5 AN515-58", ALC287_FIXUP_ACER_MICMUTE_LED),
@@ -7196,8 +7235,10 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7196 7235 SND_PCI_QUIRK(0x1025, 0x1679, "Acer Nitro 16 AN16-41", ALC2XX_FIXUP_HEADSET_MIC),
7197 7236 SND_PCI_QUIRK(0x1025, 0x169a, "Acer Swift SFG16", ALC256_FIXUP_ACER_SFG16_MICMUTE_LED),
7198 7237 SND_PCI_QUIRK(0x1025, 0x171e, "Acer Nitro ANV15-51", ALC245_FIXUP_ACER_MICMUTE_LED),
7238 + SND_PCI_QUIRK(0x1025, 0x172c, "Acer Nitro ANV16-41", ALC2XX_FIXUP_HEADSET_MIC),
7199 7239 SND_PCI_QUIRK(0x1025, 0x1731, "Acer Predator PHN16-72", ALC2XX_FIXUP_HEADSET_MIC),
7200 7240 SND_PCI_QUIRK(0x1025, 0x173a, "Acer Swift SFG14-73", ALC245_FIXUP_ACER_MICMUTE_LED),
7241 + SND_PCI_QUIRK(0x1025, 0x173b, "Acer Swift SFG16-72", ALC245_FIXUP_ACER_MICMUTE_LED),
7201 7242 SND_PCI_QUIRK(0x1025, 0x1758, "Acer Nitro ANV15-41", ALC245_FIXUP_ACER_MICMUTE_LED),
7202 7243 SND_PCI_QUIRK(0x1025, 0x1826, "Acer Helios ZPC", ALC287_FIXUP_PREDATOR_SPK_CS35L41_I2C_2),
7203 7244 SND_PCI_QUIRK(0x1025, 0x182c, "Acer Helios ZPD", ALC287_FIXUP_PREDATOR_SPK_CS35L41_I2C_2),
@@ -7303,6 +7344,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7303 7344 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
7304 7345 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
7305 7346 SND_PCI_QUIRK(0x103c, 0x18e6, "HP", ALC269_FIXUP_HP_GPIO_LED),
7347 + SND_PCI_QUIRK(0x103c, 0x2164, "HP Pavilion 15 Notebook PC", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
7306 7348 SND_PCI_QUIRK(0x103c, 0x218b, "HP", ALC269_FIXUP_LIMIT_INT_MIC_BOOST_MUTE_LED),
7307 7349 SND_PCI_QUIRK(0x103c, 0x21f9, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
7308 7350 SND_PCI_QUIRK(0x103c, 0x2210, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
@@ -7385,9 +7427,11 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7385 7427 SND_PCI_QUIRK(0x103c, 0x854a, "HP EliteBook 830 G6", ALC285_FIXUP_HP_GPIO_LED),
7386 7428 SND_PCI_QUIRK(0x103c, 0x854d, "HP EliteBook 840 G6", ALC285_FIXUP_HP_GPIO_LED),
7387 7429 SND_PCI_QUIRK(0x103c, 0x856a, "HP Pavilion 15-cs1xxx", ALC295_FIXUP_HP_PAVILION_MUTE_LED_1B),
7430 + HDA_CODEC_QUIRK(0x103c, 0x85ba, "HP Pavilion AiO 24", ALC225_FIXUP_HP_AIO_SPK),
7388 7431 SND_PCI_QUIRK(0x103c, 0x85c6, "HP Pavilion x360 Convertible 14-dy1xxx", ALC295_FIXUP_HP_MUTE_LED_COEFBIT11),
7389 7432 SND_PCI_QUIRK(0x103c, 0x85de, "HP Envy x360 13-ar0xxx", ALC285_FIXUP_HP_ENVY_X360),
7390 7433 SND_PCI_QUIRK(0x103c, 0x85f0, "HP Laptop 15-dw0xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7434 + SND_PCI_QUIRK(0x103c, 0x85f1, "HP Laptop 15-dw1xxx", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_GPIO),
7391 7435 SND_PCI_QUIRK(0x103c, 0x85f3, "HP 250 G8 Notebook PC", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7392 7436 SND_PCI_QUIRK(0x103c, 0x8603, "HP Omen 17-cb0xxx", ALC285_FIXUP_HP_MUTE_LED),
7393 7437 SND_PCI_QUIRK(0x103c, 0x860c, "HP ZBook 17 G6", ALC285_FIXUP_HP_GPIO_AMP_INIT),
@@ -7395,6 +7439,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7395 7439 SND_PCI_QUIRK(0x103c, 0x861f, "HP Elite Dragonfly G1", ALC285_FIXUP_HP_GPIO_AMP_INIT),
7396 7440 SND_PCI_QUIRK(0x103c, 0x864f, "HP Laptop 15-dy0xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7397 7441 SND_PCI_QUIRK(0x103c, 0x869d, "HP", ALC236_FIXUP_HP_MUTE_LED),
7442 + SND_PCI_QUIRK(0x103c, 0x86ad, "HP ENVY 13-aq1xxx", ALC285_FIXUP_HP_ENVY_13AQ),
7398 7443 SND_PCI_QUIRK(0x103c, 0x86c1, "HP Laptop 15-da3001TU", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7399 7444 SND_PCI_QUIRK(0x103c, 0x86c7, "HP Envy AiO 32", ALC274_FIXUP_HP_ENVY_GPIO),
7400 7445 SND_PCI_QUIRK(0x103c, 0x86c8, "HP Laptop 14s-dr1xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
@@ -7423,6 +7468,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7423 7468 SND_PCI_QUIRK(0x103c, 0x8786, "HP OMEN 15", ALC285_FIXUP_HP_MUTE_LED),
7424 7469 SND_PCI_QUIRK(0x103c, 0x8787, "HP OMEN 15", ALC285_FIXUP_HP_MUTE_LED),
7425 7470 SND_PCI_QUIRK(0x103c, 0x8788, "HP OMEN 15", ALC285_FIXUP_HP_MUTE_LED),
7471 + SND_PCI_QUIRK(0x103c, 0x87b2, "HP Pavilion Gaming Laptop 15-ec1xxx", ALC285_FIXUP_HP_MUTE_LED),
7426 7472 SND_PCI_QUIRK(0x103c, 0x87b7, "HP Laptop 14-fq0xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7427 7473 SND_PCI_QUIRK(0x103c, 0x87c8, "HP", ALC287_FIXUP_HP_GPIO_LED),
7428 7474 SND_PCI_QUIRK(0x103c, 0x87cb, "HP Pavilion 15-eg0xxx", ALC287_FIXUP_HP_GPIO_LED),
@@ -7483,6 +7529,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7483 7529 SND_PCI_QUIRK(0x103c, 0x8975, "HP EliteBook x360 840 Aero G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
7484 7530 SND_PCI_QUIRK(0x103c, 0x897d, "HP mt440 Mobile Thin Client U74", ALC236_FIXUP_HP_GPIO_LED),
7485 7531 SND_PCI_QUIRK(0x103c, 0x8981, "HP Elite Dragonfly G3", ALC245_FIXUP_CS35L41_SPI_4),
7532 + SND_PCI_QUIRK(0x103c, 0x8987, "HP Pavilion 14-dv1001TU", ALC287_FIXUP_HP_GPIO_LED),
7486 7533 SND_PCI_QUIRK(0x103c, 0x898a, "HP Pavilion 15-eg100", ALC287_FIXUP_HP_GPIO_LED),
7487 7534 SND_PCI_QUIRK(0x103c, 0x898e, "HP EliteBook 835 G9", ALC287_FIXUP_CS35L41_I2C_2),
7488 7535 SND_PCI_QUIRK(0x103c, 0x898f, "HP EliteBook 835 G9", ALC287_FIXUP_CS35L41_I2C_2),
@@ -7520,7 +7567,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7520 7567 SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2),
7521 7568 SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2),
7522 7569 SND_PCI_QUIRK(0x103c, 0x8a30, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2),
7523 - SND_PCI_QUIRK(0x103c, 0x8a31, "HP Envy 15", ALC287_FIXUP_CS35L41_I2C_2),
7570 + SND_PCI_QUIRK(0x103c, 0x8a31, "HP ENVY x360 2-in-1 Laptop 15-ey0xxx", ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS),
7524 7571 SND_PCI_QUIRK(0x103c, 0x8a34, "HP Pavilion x360 2-in-1 Laptop 14-ek0xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7525 7572 SND_PCI_QUIRK(0x103c, 0x8a36, "HP Pavilion Plus 14-eh0xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7526 7573 SND_PCI_QUIRK(0x103c, 0x8a3d, "HP Victus 15-fb0xxx (MB 8A3D)", ALC245_FIXUP_HP_MUTE_LED_V2_COEFBIT),
@@ -7581,6 +7628,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7581 7628 SND_PCI_QUIRK(0x103c, 0x8bb4, "HP Slim OMEN", ALC287_FIXUP_CS35L41_I2C_2),
7582 7629 SND_PCI_QUIRK(0x103c, 0x8bb6, "HP Laptop 15-fd0039nt", ALC236_FIXUP_HP_15_FD0XXX),
7583 7630 SND_PCI_QUIRK(0x103c, 0x8bbe, "HP Victus 16-r0xxx (MB 8BBE)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7631 + SND_PCI_QUIRK(0x103c, 0x8bc7, "HP Pavilion 15-eh3174nw", ALC287_FIXUP_HP_GPIO_LED),
7584 7632 SND_PCI_QUIRK(0x103c, 0x8bc8, "HP Victus 15-fa1xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7585 7633 SND_PCI_QUIRK(0x103c, 0x8bcd, "HP Omen 16-xd0xxx", ALC245_FIXUP_HP_MUTE_LED_V1_COEFBIT),
7586 7634 SND_PCI_QUIRK(0x103c, 0x8bd4, "HP Victus 16-s0xxx (MB 8BD4)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
@@ -7603,6 +7651,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7603 7651 SND_PCI_QUIRK(0x103c, 0x8c17, "HP Spectre x360 2-in-1 Laptop 16-aa0xxx", ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX),
7604 7652 SND_PCI_QUIRK(0x103c, 0x8c21, "HP Pavilion Plus Laptop 14-ey0XXX", ALC245_FIXUP_HP_X360_MUTE_LEDS),
7605 7653 SND_PCI_QUIRK(0x103c, 0x8c2d, "HP Victus 15-fa1xxx (MB 8C2D)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7654 + SND_PCI_QUIRK(0x103c, 0x8c2f, "HP Victus 15-fb2xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7606 7655 SND_PCI_QUIRK(0x103c, 0x8c30, "HP Victus 15-fb1xxx", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7607 7656 SND_PCI_QUIRK(0x103c, 0x8c3f, "HP Victus 15-fa1xxx (MB 8C3F)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
7608 7657 SND_PCI_QUIRK(0x103c, 0x8c46, "HP EliteBook 830 G11", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
@@ -7712,6 +7761,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7712 7761 SND_PCI_QUIRK(0x103c, 0x8e37, "HP 16 Piston OmniBook X", ALC287_FIXUP_CS35L41_I2C_2),
7713 7762 SND_PCI_QUIRK(0x103c, 0x8e3a, "HP Agusta", ALC287_FIXUP_CS35L41_I2C_2),
7714 7763 SND_PCI_QUIRK(0x103c, 0x8e3b, "HP Agusta", ALC287_FIXUP_CS35L41_I2C_2),
7764 + SND_PCI_QUIRK(0x103c, 0x8e43, "HP Laptop 15-fd2xxx", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_GPIO),
7715 7765 SND_PCI_QUIRK(0x103c, 0x8e60, "HP OmniBook 7 Laptop 16-bh0xxx", ALC245_FIXUP_CS35L41_I2C_2_MUTE_LED),
7716 7766 SND_PCI_QUIRK(0x103c, 0x8e61, "HP Trekker ", ALC287_FIXUP_CS35L41_I2C_2),
7717 7767 SND_PCI_QUIRK(0x103c, 0x8e62, "HP Trekker ", ALC287_FIXUP_CS35L41_I2C_2),
@@ -7814,6 +7864,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7814 7864 SND_PCI_QUIRK(0x1043, 0x1652, "ASUS ROG Zephyrus Do 15 SE", ALC289_FIXUP_ASUS_ZEPHYRUS_DUAL_SPK),
7815 7865 SND_PCI_QUIRK(0x1043, 0x1662, "ASUS GV301QH", ALC294_FIXUP_ASUS_DUAL_SPK),
7816 7866 SND_PCI_QUIRK(0x1043, 0x1663, "ASUS GU603ZI/ZJ/ZQ/ZU/ZV", ALC285_FIXUP_ASUS_HEADSET_MIC),
7867 + SND_PCI_QUIRK(0x1043, 0x1664, "ASUS ExpertBook PM3406CHA", ALC256_FIXUP_ASUS_PM3406CHA),
7817 7868 SND_PCI_QUIRK(0x1043, 0x1683, "ASUS UM3402YAR", ALC287_FIXUP_CS35L41_I2C_2),
7818 7869 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS UX3402VA", ALC245_FIXUP_CS35L41_SPI_2),
7819 7870 SND_PCI_QUIRK(0x1043, 0x16b2, "ASUS GU603", ALC289_FIXUP_ASUS_GA401),
@@ -7916,7 +7967,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7916 7967 SND_PCI_QUIRK(0x1043, 0x3ef0, "ASUS Strix G635LR_LW_LX", ALC287_FIXUP_TXNW2781_I2C),
7917 7968 SND_PCI_QUIRK(0x1043, 0x3f00, "ASUS Strix G815LH_LM_LP", ALC287_FIXUP_TXNW2781_I2C),
7918 7969 SND_PCI_QUIRK(0x1043, 0x3f10, "ASUS Strix G835LR_LW_LX", ALC287_FIXUP_TXNW2781_I2C),
7919 - SND_PCI_QUIRK(0x1043, 0x3f20, "ASUS Strix G615LR_LW", ALC287_FIXUP_TXNW2781_I2C),
7970 + SND_PCI_QUIRK(0x1043, 0x3f20, "ASUS Strix G615LR_LW", ALC287_FIXUP_TXNW2781_I2C_ASUS),
7920 7971 SND_PCI_QUIRK(0x1043, 0x3f30, "ASUS Strix G815LR_LW", ALC287_FIXUP_TXNW2781_I2C),
7921 7972 SND_PCI_QUIRK(0x1043, 0x3fd0, "ASUS B3605CVA", ALC245_FIXUP_CS35L41_SPI_2),
7922 7973 SND_PCI_QUIRK(0x1043, 0x3ff0, "ASUS B5405CVA", ALC245_FIXUP_CS35L41_SPI_2),
@@ -7939,6 +7990,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7939 7990 SND_PCI_QUIRK(0x10cf, 0x1757, "Lifebook E752", ALC269_FIXUP_LIFEBOOK_HP_PIN),
7940 7991 SND_PCI_QUIRK(0x10cf, 0x1845, "Lifebook U904", ALC269_FIXUP_LIFEBOOK_EXTMIC),
7941 7992 SND_PCI_QUIRK(0x10ec, 0x10f2, "Intel Reference board", ALC700_FIXUP_INTEL_REFERENCE),
7993 + SND_PCI_QUIRK(0x10ec, 0x111e, "Higole F9B", ALC290_FIXUP_MONO_SPEAKERS),
7942 7994 SND_PCI_QUIRK(0x10ec, 0x118c, "Medion EE4254 MD62100", ALC256_FIXUP_MEDION_HEADSET_NO_PRESENCE),
7943 7995 SND_PCI_QUIRK(0x10ec, 0x119e, "Positivo SU C1400", ALC269_FIXUP_ASPIRE_HEADSET_MIC),
7944 7996 SND_PCI_QUIRK(0x10ec, 0x11bc, "VAIO VJFE-IL", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -8164,7 +8216,6 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8164 8216 SND_PCI_QUIRK(0x17aa, 0x3834, "Lenovo IdeaPad Slim 9i 14ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
8165 8217 SND_PCI_QUIRK(0x17aa, 0x383d, "Legion Y9000X 2019", ALC285_FIXUP_LEGION_Y9000X_SPEAKERS),
8166 8218 SND_PCI_QUIRK(0x17aa, 0x3843, "Lenovo Yoga 9i / Yoga Book 9i", ALC287_FIXUP_LENOVO_YOGA_BOOK_9I),
8167 - SND_PCI_QUIRK(0x17aa, 0x3846, "Lenovo Yoga Pro 9 16IAH10", ALC287_FIXUP_YOGA9_SPEAKER2_TO_DAC1),
8168 8219 /* Yoga Pro 7 14IMH9 shares PCI SSID 17aa:3847 with Legion 7 16ACHG6;
8169 8220 * use codec SSID to distinguish them
8170 8221 */
@@ -8189,6 +8240,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8189 8240 HDA_CODEC_QUIRK(0x17aa, 0x38a8, "Legion Pro 7 16ARX8H", ALC287_FIXUP_TAS2781_I2C), /* this must match before PCI SSID 17aa:386f below */
8190 8241 SND_PCI_QUIRK(0x17aa, 0x386f, "Legion Pro 7i 16IAX7", ALC287_FIXUP_CS35L41_I2C_2),
8191 8242 SND_PCI_QUIRK(0x17aa, 0x3870, "Lenovo Yoga 7 14ARB7", ALC287_FIXUP_YOGA7_14ARB7_I2C),
8243 + SND_PCI_QUIRK(0x17aa, 0x3871, "Lenovo ThinkBook 16p Gen 3 ARH", ALC287_FIXUP_YOGA7_14ARB7_I2C),
8192 8244 SND_PCI_QUIRK(0x17aa, 0x3874, "Legion 7i 16IAX7", ALC287_FIXUP_CS35L41_I2C_2),
8193 8245 SND_PCI_QUIRK(0x17aa, 0x3877, "Lenovo Legion 7 Slim 16ARHA7", ALC287_FIXUP_CS35L41_I2C_2),
8194 8246 SND_PCI_QUIRK(0x17aa, 0x3878, "Lenovo Legion 7 Slim 16ARHA7", ALC287_FIXUP_CS35L41_I2C_2),
@@ -8239,6 +8291,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8239 8291 SND_PCI_QUIRK(0x17aa, 0x38d5, "Yoga S990-16 Pro IMH YC Quad", ALC287_FIXUP_TAS2781_I2C),
8240 8292 SND_PCI_QUIRK(0x17aa, 0x38d6, "Yoga S990-16 Pro IMH VECO Quad", ALC287_FIXUP_TAS2781_I2C),
8241 8293 SND_PCI_QUIRK(0x17aa, 0x38d7, "Lenovo Yoga 9 14IMH9", ALC287_FIXUP_YOGA9_14IMH9_BASS_SPK_PIN),
8294 + SND_PCI_QUIRK(0x17aa, 0x38dc, "Lenovo ThinkBook G8", ALC285_FIXUP_SPEAKER2_TO_DAC1),
8242 8295 SND_PCI_QUIRK(0x17aa, 0x38df, "Yoga Y990 Intel YC Dual", ALC287_FIXUP_TAS2781_I2C),
8243 8296 SND_PCI_QUIRK(0x17aa, 0x38e0, "Yoga Y990 Intel VECO Dual", ALC287_FIXUP_TAS2781_I2C),
8244 8297 SND_PCI_QUIRK(0x17aa, 0x38f8, "Yoga Book 9i", ALC287_FIXUP_TAS2781_I2C),
@@ -8258,7 +8311,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8258 8311 SND_PCI_QUIRK(0x17aa, 0x3912, "Lenovo Xiaoxin 14 GT", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN),
8259 8312 SND_PCI_QUIRK(0x17aa, 0x3913, "Lenovo 145", ALC236_FIXUP_LENOVO_INV_DMIC),
8260 8313 SND_PCI_QUIRK(0x17aa, 0x391f, "Yoga S990-16 pro Quad YC Quad", ALC287_FIXUP_TXNW2781_I2C),
8261 - SND_PCI_QUIRK(0x17aa, 0x3920, "Yoga S990-16 pro Quad VECO Quad", ALC287_FIXUP_TXNW2781_I2C),
8314 + SND_PCI_QUIRK(0x17aa, 0x3920, "Yoga S990-16 pro Quad VECO Quad", ALC287_FIXUP_YOGA9_SPEAKER2_TO_DAC1),
8262 8315 SND_PCI_QUIRK(0x17aa, 0x3929, "Thinkbook 13x Gen 5", ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD),
8263 8316 SND_PCI_QUIRK(0x17aa, 0x392b, "Thinkbook 13x Gen 5", ALC287_FIXUP_MG_RTKC_CSAMP_CS35L41_I2C_THINKPAD),
8264 8317 HDA_CODEC_QUIRK(0x17aa, 0x3936, "Legion R9000P ADR10H", ALC287_FIXUP_LENOVO_LEGION_AW88399),
@@ -8354,6 +8407,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8354 8407 SND_PCI_QUIRK(0x2014, 0x800a, "Positivo ARN50", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
8355 8408 SND_PCI_QUIRK(0x2039, 0x0001, "Inspur S14-G1", ALC295_FIXUP_CHROME_BOOK),
8356 8409 SND_PCI_QUIRK(0x2145, 0x0001, "Star Labs StarFighter", ALC233_FIXUP_STARLABS_STARFIGHTER),
8410 + SND_PCI_QUIRK(0x2782, 0x0206, "IPASON SmartBook S1", ALC256_FIXUP_IPASON_SMARTBOOK_S1),
8357 8411 SND_PCI_QUIRK(0x2782, 0x0214, "VAIO VJFE-CL", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
8358 8412 SND_PCI_QUIRK(0x2782, 0x0228, "Infinix ZERO BOOK 13", ALC269VB_FIXUP_INFINIX_ZERO_BOOK_13),
8359 8413 SND_PCI_QUIRK(0x2782, 0x0232, "CHUWI CoreBook XPro", ALC269VB_FIXUP_CHUWI_COREBOOK_XPRO),
modified sound/hda/codecs/realtek/realtek.c
@@ -1292,6 +1292,7 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
1292 1292 }
1293 1293
1294 1294 switch (codec->core.vendor_id) {
1295 + case 0x10ec0235:
1295 1296 case 0x10ec0255:
1296 1297 alc_process_coef_fw(codec, coef0255);
1297 1298 break;
@@ -1407,6 +1408,7 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
1407 1408 };
1408 1409
1409 1410 switch (codec->core.vendor_id) {
1411 + case 0x10ec0235:
1410 1412 case 0x10ec0255:
1411 1413 alc_write_coef_idx(codec, 0x45, 0xc489);
1412 1414 snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
@@ -1562,6 +1564,7 @@ static void alc_headset_mode_default(struct hda_codec *codec)
1562 1564 alc_process_coef_fw(codec, coef0225);
1563 1565 alc_hp_enable_unmute(codec, 75);
1564 1566 break;
1567 + case 0x10ec0235:
1565 1568 case 0x10ec0255:
1566 1569 alc_process_coef_fw(codec, coef0255);
1567 1570 break;
@@ -1663,6 +1666,7 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
1663 1666 };
1664 1667
1665 1668 switch (codec->core.vendor_id) {
1669 + case 0x10ec0235:
1666 1670 case 0x10ec0255:
1667 1671 alc_process_coef_fw(codec, coef0255);
1668 1672 break;
@@ -1780,6 +1784,7 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
1780 1784 };
1781 1785
1782 1786 switch (codec->core.vendor_id) {
1787 + case 0x10ec0235:
1783 1788 case 0x10ec0255:
1784 1789 alc_process_coef_fw(codec, coef0255);
1785 1790 break;
@@ -1881,6 +1886,7 @@ static void alc_determine_headset_type(struct hda_codec *codec)
1881 1886 }
1882 1887
1883 1888 switch (codec->core.vendor_id) {
1889 + case 0x10ec0235:
1884 1890 case 0x10ec0255:
1885 1891 alc_process_coef_fw(codec, coef0255);
1886 1892 msleep(300);
modified sound/hda/controllers/tegra.c
@@ -374,7 +374,8 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
374 374 * in powers of 2, next available ratio is 16 which can be
375 375 * used as a limiting factor here.
376 376 */
377 - if (of_device_is_compatible(np, "nvidia,tegra30-hda"))
377 + if (of_device_is_compatible(np, "nvidia,tegra30-hda") ||
378 + of_device_is_compatible(np, "nvidia,tegra194-hda"))
378 379 chip->bus.core.sdo_limit = 16;
379 380
380 381 /* codec detection */
modified sound/pci/ctxfi/cthw20k2.c
@@ -1895,6 +1895,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
1895 1895
1896 1896 if (hw->model == CTSB1270) {
1897 1897 /* Set up the PCM4220 ADC on Titanium HD */
1898 + data = hw_read_20kx(hw, GPIO_DATA);
1898 1899 data &= ~0x0C;
1899 1900 if (1 == info->msr)
1900 1901 data |= 0x00; /* Single Speed Mode 32-50kHz */
@@ -1903,6 +1904,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
1903 1904 else
1904 1905 data |= 0x04; /* Quad Speed Mode 108kHz-216kHz */
1905 1906 hw_write_20kx(hw, GPIO_DATA, data);
1907 + usleep_range(10000, 11000);
1906 1908 }
1907 1909
1908 1910 hw_adc_start(hw);
modified sound/pci/ice1712/ice1712.c
@@ -2523,7 +2523,7 @@ static int snd_ice1712_probe(struct pci_dev *pci,
2523 2523 const struct pci_device_id *pci_id)
2524 2524 {
2525 2525 static int dev;
2526 - struct snd_card *card __free(snd_card_unref) = NULL;
2526 + struct snd_card *card __free(snd_card_free) = NULL;
2527 2527 struct snd_ice1712 *ice;
2528 2528 int pcm_dev = 0, err;
2529 2529 const struct snd_ice1712_card_info * const *tbl, *c;
modified sound/soc/amd/acp-config.c
@@ -30,6 +30,13 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = {
30 30 DMI_MATCH(DMI_PRODUCT_NAME, "HN7306EA"),
31 31 },
32 32 },
33 + {
34 + /* ASUS EXPERTBOOK AM7406CKA (Kraken Point, ACP 7.0) */
35 + .matches = {
36 + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
37 + DMI_MATCH(DMI_PRODUCT_NAME, "ASUS EXPERTBOOK AM7406CKA"),
38 + },
39 + },
33 40 {
34 41 /* ASUS Zenbook S16 UM5606GA (Strix Point, ACP 7.0) */
35 42 .matches = {
@@ -51,6 +58,13 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = {
51 58 DMI_MATCH(DMI_PRODUCT_NAME, "83V9"),
52 59 },
53 60 },
61 + {
62 + /* Lenovo Yoga Pro 7 14ASP9 (Strix Point, ACP 7.0) */
63 + .matches = {
64 + DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
65 + DMI_MATCH(DMI_PRODUCT_NAME, "83HN"),
66 + },
67 + },
54 68 {
55 69 .matches = {
56 70 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC"),
@@ -63,6 +77,13 @@ static const struct dmi_system_id acp70_acpi_flag_override_table[] = {
63 77 DMI_MATCH(DMI_PRODUCT_NAME, "Vivobook 18 M1807GA"),
64 78 },
65 79 },
80 + {
81 + /* ASUS Zenbook S14 UM5406GA (Strix Point, ACP 7.0) */
82 + .matches = {
83 + DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
84 + DMI_MATCH(DMI_PRODUCT_NAME, "Zenbook S14 UM5406GA"),
85 + },
86 + },
66 87 {
67 88 /* HP OmniBook X Flip 14-kc0xxx (Strix Point, ACP 7.2) */
68 89 .matches = {
modified sound/soc/amd/acp/Kconfig
@@ -181,6 +181,7 @@ config SND_SOC_AMD_LEGACY_SDW_MACH
181 181 select SND_SOC_RT715_SDW
182 182 select SND_SOC_RT715_SDCA_SDW
183 183 select SND_SOC_RT722_SDCA_SDW
184 + select SND_SOC_TAS2783_SDW
184 185 help
185 186 This option enables Legacy(No DSP) sound card support for SoundWire
186 187 enabled AMD platforms along with ACP PDM controller.
modified sound/soc/amd/acp/amd-acp70-acpi-match.c
@@ -335,6 +335,27 @@ static const struct snd_soc_acpi_adr_device cs42l43b_l0u1_adr[] = {
335 335 }
336 336 };
337 337
338 + static const struct snd_soc_acpi_adr_device cs42l43b_l0u1_cs35l57x2_l0u01_adr[] = {
339 + {
340 + .adr = 0x00003101FA2A3B01ull,
341 + .num_endpoints = ARRAY_SIZE(cs42l43_endpoints),
342 + .endpoints = cs42l43_endpoints,
343 + .name_prefix = "cs42l43"
344 + },
345 + {
346 + .adr = 0x00003001FA355701ull,
347 + .num_endpoints = 1,
348 + .endpoints = &spk_l_endpoint,
349 + .name_prefix = "AMP1"
350 + },
351 + {
352 + .adr = 0x00003101FA355701ull,
353 + .num_endpoints = 1,
354 + .endpoints = &spk_r_endpoint,
355 + .name_prefix = "AMP2"
356 + },
357 + };
358 +
338 359 static const struct snd_soc_acpi_adr_device cs42l43_l1u0_cs35l56x4_l1u0123_adr[] = {
339 360 {
340 361 .adr = 0x00013001FA424301ull,
@@ -438,6 +459,15 @@ static const struct snd_soc_acpi_link_adr acp70_cs42l43_l0u0_cs35l56x4_l1u3210[]
438 459 {}
439 460 };
440 461
462 + static const struct snd_soc_acpi_link_adr acp70_cs42l43b_l0u1_cs35l57x2_l0u01[] = {
463 + {
464 + .mask = BIT(0),
465 + .num_adr = ARRAY_SIZE(cs42l43b_l0u1_cs35l57x2_l0u01_adr),
466 + .adr_d = cs42l43b_l0u1_cs35l57x2_l0u01_adr,
467 + },
468 + {}
469 + };
470 +
441 471 static const struct snd_soc_acpi_link_adr acp70_cs42l43_l1u0_cs35l56x4_l1u0123[] = {
442 472 {
443 473 .mask = BIT(1),
@@ -748,7 +778,27 @@ static const struct snd_soc_acpi_link_adr acp70_rt721_only[] = {
748 778 {}
749 779 };
750 780
781 + static const struct snd_soc_acpi_link_adr acp70_tas2783a_l0_rt712_vb_l1[] = {
782 + {
783 + .mask = BIT(0),
784 + .num_adr = ARRAY_SIZE(tas2783_2_adr),
785 + .adr_d = tas2783_2_adr,
786 + },
787 + {
788 + .mask = BIT(1),
789 + .num_adr = ARRAY_SIZE(rt712_vb_1_group1_adr),
790 + .adr_d = rt712_vb_1_group1_adr,
791 + },
792 + {}
793 + };
794 +
751 795 struct snd_soc_acpi_mach snd_soc_acpi_amd_acp70_sdw_machines[] = {
796 + {
797 + .link_mask = BIT(0) | BIT(1),
798 + .links = acp70_tas2783a_l0_rt712_vb_l1,
799 + .machine_check = snd_soc_acpi_amd_sdca_is_device_rt712_vb,
800 + .drv_name = "amd_sdw",
801 + },
752 802 {
753 803 .link_mask = BIT(0),
754 804 .links = acp70_tas2783_2,
@@ -800,6 +850,11 @@ struct snd_soc_acpi_mach snd_soc_acpi_amd_acp70_sdw_machines[] = {
800 850 .links = acp70_cs42l45_l1u0_cs35l63x2_l0u01,
801 851 .drv_name = "amd_sdw",
802 852 },
853 + {
854 + .link_mask = BIT(0),
855 + .links = acp70_cs42l43b_l0u1_cs35l57x2_l0u01,
856 + .drv_name = "amd_sdw",
857 + },
803 858 {
804 859 .link_mask = BIT(1),
805 860 .links = acp70_cs42l43_l1u0_cs35l56x4_l1u0123,
modified sound/soc/amd/yc/acp6x-mach.c
@@ -248,6 +248,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
248 248 DMI_MATCH(DMI_PRODUCT_NAME, "21J6"),
249 249 }
250 250 },
251 + {
252 + .driver_data = &acp6x_card,
253 + .matches = {
254 + DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
255 + DMI_MATCH(DMI_PRODUCT_NAME, "21JN"),
256 + }
257 + },
251 258 {
252 259 .driver_data = &acp6x_card,
253 260 .matches = {
@@ -381,6 +388,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
381 388 DMI_MATCH(DMI_PRODUCT_NAME, "83Q3"),
382 389 }
383 390 },
391 + {
392 + .driver_data = &acp6x_card,
393 + .matches = {
394 + DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
395 + DMI_MATCH(DMI_PRODUCT_NAME, "83UU"),
396 + }
397 + },
384 398 {
385 399 .driver_data = &acp6x_card,
386 400 .matches = {
@@ -773,6 +787,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
773 787 DMI_MATCH(DMI_BOARD_NAME, "Herbag_MDU"),
774 788 }
775 789 },
790 + {
791 + .driver_data = &acp6x_card,
792 + .matches = {
793 + DMI_MATCH(DMI_BOARD_VENDOR, "MDC"),
794 + DMI_MATCH(DMI_BOARD_NAME, "Herbag2_MDU"),
795 + }
796 + },
776 797 {
777 798 .driver_data = &acp6x_card,
778 799 .matches = {
modified sound/soc/codecs/Kconfig
@@ -1989,9 +1989,7 @@ config SND_SOC_RT715_SDCA_SDW
1989 1989 config SND_SOC_RT766_SDCA_SDW
1990 1990 tristate "Realtek RT766 SDCA Codec - SDW"
1991 1991 depends on SOUNDWIRE
1992 - depends on SND_SOC_SDCA
1993 - select SND_SOC_SDCA_HID
1994 - select SND_SOC_SDCA_IRQ
1992 + depends on SND_SOC_SDCA_CLASS
1995 1993 select REGMAP_SOUNDWIRE
1996 1994 select REGMAP_SOUNDWIRE_MBQ
1997 1995
modified sound/soc/codecs/adau1372.c
@@ -798,7 +798,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)
798 798 if (ret)
799 799 return ret;
800 800 if (adau1372->pd_gpio)
801 - gpiod_set_value(adau1372->pd_gpio, 0);
801 + gpiod_set_value_cansleep(adau1372->pd_gpio, 0);
802 802
803 803 if (adau1372->switch_mode)
804 804 adau1372->switch_mode(adau1372->dev);
@@ -818,8 +818,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)
818 818 ADAU1372_CLK_CTRL_PLL_EN,
819 819 0);
820 820 regcache_cache_only(adau1372->regmap, true);
821 - if (adau1372->pd_gpio)
822 - gpiod_set_value(adau1372->pd_gpio, 1);
821 + gpiod_set_value_cansleep(adau1372->pd_gpio, 1);
823 822 clk_disable_unprepare(adau1372->mclk);
824 823 return ret;
825 824 }
@@ -836,7 +835,7 @@ static int adau1372_set_power(struct adau1372 *adau1372, bool enable)
836 835 * map. No need to do any register writes to manually
837 836 * turn things off.
838 837 */
839 - gpiod_set_value(adau1372->pd_gpio, 1);
838 + gpiod_set_value_cansleep(adau1372->pd_gpio, 1);
840 839 regcache_mark_dirty(adau1372->regmap);
841 840 } else {
842 841 regmap_update_bits(adau1372->regmap, ADAU1372_REG_CLK_CTRL,
@@ -1003,6 +1002,17 @@ int adau1372_probe(struct device *dev, struct regmap *regmap,
1003 1002
1004 1003 regmap_write(regmap, ADAU1372_REG_OP_STAGE_MUTE, 0x0);
1005 1004
1005 + /*
1006 + * Set sane default values for the Output ASRC and DAC input muxes,
1007 + * since the power-on reset defaults are invalid "Reserved" states.
1008 + */
1009 + regmap_write(regmap, ADAU1372_REG_ASRCO_SOURCE_0_1,
1010 + 0x54); /* Decimator0, Decimator1 */
1011 + regmap_write(regmap, ADAU1372_REG_ASRCO_SOURCE_2_3,
1012 + 0x76); /* Decimator2, Decimator3 */
1013 + regmap_write(regmap, ADAU1372_REG_DAC_SOURCE,
1014 + 0xdc); /* Input ASRC0, Input ASRC1 */
1015 +
1006 1016 regmap_write(regmap, 0x7, 0x01); /* CLOCK OUT */
1007 1017
1008 1018 return devm_snd_soc_register_component(dev, &adau1372_driver, &adau1372_dai_driver, 1);
modified sound/soc/codecs/cs35l56-sdw.c
@@ -265,11 +265,11 @@ static int cs35l56_sdw_read_prop(struct sdw_slave *peripheral)
265 265 if (ret == 0)
266 266 prop->clk_stop_mode1 = !!clock_stop_1;
267 267
268 - ports = devm_kcalloc(cs35l56->base.dev, 2, sizeof(*ports), GFP_KERNEL);
268 + ports = devm_kcalloc(cs35l56->base.dev, 3, sizeof(*ports), GFP_KERNEL);
269 269 if (!ports)
270 270 return -ENOMEM;
271 271
272 - prop->source_ports = BIT(CS35L56_SDW1_CAPTURE_PORT);
272 + prop->source_ports = BIT(CS35L56_SDW1_CAPTURE_PORT) | BIT(CS35L56_OT25_CAPTURE_PORT);
273 273 prop->sink_ports = BIT(CS35L56_SDW1_PLAYBACK_PORT);
274 274 prop->paging_support = true;
275 275 prop->use_domain_irq = true;
@@ -286,6 +286,11 @@ static int cs35l56_sdw_read_prop(struct sdw_slave *peripheral)
286 286 ports[1].num = CS35L56_SDW1_CAPTURE_PORT;
287 287 ports[1].type = SDW_DPN_FULL;
288 288 ports[1].ch_prep_timeout = 10;
289 +
290 + /* DP4 - capture */
291 + ports[2].num = CS35L56_OT25_CAPTURE_PORT;
292 + ports[2].type = SDW_DPN_FULL;
293 + ports[2].ch_prep_timeout = 10;
289 294 prop->src_dpn_prop = &ports[1];
290 295
291 296 dev_dbg(&peripheral->dev, "clock stop mode 1 supported: %s\n",
modified sound/soc/codecs/cs35l56.c
@@ -32,6 +32,7 @@
32 32 #include <sound/cs-amp-lib.h>
33 33 #include <sound/pcm.h>
34 34 #include <sound/pcm_params.h>
35 + #include <sound/sdw.h>
35 36 #include <sound/soc.h>
36 37 #include <sound/soc-dapm.h>
37 38 #include <sound/tlv.h>
@@ -324,6 +325,7 @@ static const struct snd_soc_dapm_widget cs35l56_dapm_widgets[] = {
324 325 SND_SOC_DAPM_SIGGEN("VDDBMON ADC"),
325 326 SND_SOC_DAPM_SIGGEN("VBSTMON ADC"),
326 327 SND_SOC_DAPM_SIGGEN("TEMPMON ADC"),
328 + SND_SOC_DAPM_SIGGEN("OT25 Reference"),
327 329
328 330 SND_SOC_DAPM_INPUT("Calibrate"),
329 331 };
@@ -388,6 +390,8 @@ static const struct snd_soc_dapm_route cs35l56_audio_map[] = {
388 390 { "SDW1 Capture", NULL, "SDW1 TX2 Source" },
389 391 { "SDW1 Capture", NULL, "SDW1 TX3 Source" },
390 392 { "SDW1 Capture", NULL, "SDW1 TX4 Source" },
393 +
394 + { "OT25", NULL, "OT25 Reference" },
391 395 };
392 396
393 397 static int cs35l56_dsp_event(struct snd_soc_dapm_widget *w,
@@ -712,6 +716,37 @@ static int cs35l56_sdw_dai_set_stream(struct snd_soc_dai *dai,
712 716 return 0;
713 717 }
714 718
719 + static int cs35l56_ot25_dai_hw_params(struct snd_pcm_substream *substream,
720 + struct snd_pcm_hw_params *params,
721 + struct snd_soc_dai *dai)
722 + {
723 + struct cs35l56_private *cs35l56 = snd_soc_component_get_drvdata(dai->component);
724 + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
725 + struct sdw_stream_config sconfig = { };
726 + struct sdw_port_config pconfig = { };
727 + int ret;
728 +
729 + dev_dbg(cs35l56->base.dev, "%s: rate %d\n", __func__, params_rate(params));
730 +
731 + if (!cs35l56->base.init_done)
732 + return -ENODEV;
733 +
734 + if (!sdw_stream)
735 + return -EINVAL;
736 +
737 + snd_sdw_params_to_config(substream, params, &sconfig, &pconfig);
738 + pconfig.num = CS35L56_OT25_CAPTURE_PORT;
739 +
740 + ret = sdw_stream_add_slave(cs35l56->sdw_peripheral, &sconfig, &pconfig,
741 + 1, sdw_stream);
742 + if (ret) {
743 + dev_err(dai->dev, "Failed to add OT25 stream: %d\n", ret);
744 + return ret;
745 + }
746 +
747 + return 0;
748 + }
749 +
715 750 static const struct snd_soc_dai_ops cs35l56_sdw_dai_ops = {
716 751 .set_tdm_slot = cs35l56_sdw_dai_set_tdm_slot,
717 752 .shutdown = cs35l56_sdw_dai_shutdown,
@@ -720,6 +755,13 @@ static const struct snd_soc_dai_ops cs35l56_sdw_dai_ops = {
720 755 .set_stream = cs35l56_sdw_dai_set_stream,
721 756 };
722 757
758 + static const struct snd_soc_dai_ops cs35l56_ot25_dai_ops = {
759 + .shutdown = cs35l56_sdw_dai_shutdown,
760 + .hw_params = cs35l56_ot25_dai_hw_params,
761 + .hw_free = cs35l56_sdw_dai_hw_free,
762 + .set_stream = cs35l56_sdw_dai_set_stream,
763 + };
764 +
723 765 static struct snd_soc_dai_driver cs35l56_dai[] = {
724 766 {
725 767 .name = "cs35l56-asp1",
@@ -768,6 +810,18 @@ static struct snd_soc_dai_driver cs35l56_dai[] = {
768 810 .symmetric_rate = 1,
769 811 .ops = &cs35l56_sdw_dai_ops,
770 812 },
813 + {
814 + .name = "cs35l56-ot25",
815 + .id = 3,
816 + .capture = {
817 + .stream_name = "OT25",
818 + .channels_min = 1,
819 + .channels_max = 2,
820 + .rates = CS35L56_RATES,
821 + .formats = CS35L56_TX_FORMATS,
822 + },
823 + .ops = &cs35l56_ot25_dai_ops,
824 + },
771 825 };
772 826
773 827 static int cs35l56_write_cal(struct cs35l56_private *cs35l56)
modified sound/soc/codecs/lpass-wsa-macro.c
@@ -1841,6 +1841,7 @@ static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
1841 1841 int event)
1842 1842 {
1843 1843 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1844 + unsigned int gain;
1844 1845 u16 gain_reg;
1845 1846 u16 reg;
1846 1847 struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
@@ -1882,6 +1883,8 @@ static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
1882 1883 CDC_WSA_RX_PGA_HALF_DB_MASK,
1883 1884 CDC_WSA_RX_PGA_HALF_DB_ENABLE);
1884 1885 }
1886 + gain = snd_soc_component_read(component, gain_reg);
1887 + snd_soc_component_write(component, gain_reg, gain);
1885 1888 wsa_macro_config_ear_spkr_gain(component, wsa,
1886 1889 event, gain_reg);
1887 1890 break;
modified sound/soc/codecs/max98363.c
@@ -200,7 +200,7 @@ static int max98363_sdw_dai_hw_params(struct snd_pcm_substream *substream,
200 200 struct max98363_priv *max98363 =
201 201 snd_soc_component_get_drvdata(component);
202 202
203 - struct sdw_stream_config stream_config;
203 + struct sdw_stream_config stream_config = {0};
204 204 struct sdw_port_config port_config;
205 205 enum sdw_data_direction direction;
206 206 struct sdw_stream_runtime *stream;
modified sound/soc/codecs/rt1017-sdca-sdw.c
@@ -15,6 +15,7 @@
15 15 #include <sound/pcm_params.h>
16 16 #include <sound/soc.h>
17 17 #include <sound/soc-dapm.h>
18 + #include <sound/sdw.h>
18 19 #include <sound/initval.h>
19 20 #include <sound/tlv.h>
20 21
@@ -573,11 +574,10 @@ static int rt1017_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
573 574 {
574 575 struct snd_soc_component *component = dai->component;
575 576 struct rt1017_sdca_priv *rt1017 = snd_soc_component_get_drvdata(component);
576 - struct sdw_stream_config stream_config;
577 + struct sdw_stream_config stream_config = {0};
577 578 struct sdw_port_config port_config;
578 - enum sdw_data_direction direction;
579 579 struct sdw_stream_runtime *sdw_stream;
580 - int retval, port, num_channels, ch_mask;
580 + int retval, port;
581 581 unsigned int sampling_rate;
582 582
583 583 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
@@ -591,28 +591,17 @@ static int rt1017_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
591 591
592 592 /* SoundWire specific configuration */
593 593 /* port 1 for playback */
594 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
595 - direction = SDW_DATA_DIR_RX;
594 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
596 595 port = 1;
597 - } else {
598 - direction = SDW_DATA_DIR_TX;
596 + else
599 597 port = 2;
600 - }
601 -
602 - num_channels = params_channels(params);
603 - ch_mask = (1 << num_channels) - 1;
604 -
605 - stream_config.frame_rate = params_rate(params);
606 - stream_config.ch_count = num_channels;
607 - stream_config.bps = snd_pcm_format_width(params_format(params));
608 - stream_config.direction = direction;
609 598
610 - port_config.ch_mask = ch_mask;
599 + snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
611 600 port_config.num = port;
612 601
613 602 dev_dbg(dai->dev, "frame_rate %d, ch_count %d, bps %d, direction %d, ch_mask %d, port: %d\n",
614 - params_rate(params), num_channels, snd_pcm_format_width(params_format(params)),
615 - direction, ch_mask, port);
603 + stream_config.frame_rate, stream_config.ch_count, stream_config.bps,
604 + stream_config.direction, port_config.ch_mask, port);
616 605
617 606 retval = sdw_stream_add_slave(rt1017->sdw_slave, &stream_config,
618 607 &port_config, 1, sdw_stream);
modified sound/soc/codecs/rt274.c
@@ -619,9 +619,11 @@ static int rt274_hw_params(struct snd_pcm_substream *substream,
619 619 unsigned int val = 0;
620 620 int d_len_code = 0, c_len_code = 0;
621 621
622 + /* bit 14 Sample Rate Base, 0: 48kHz 1: 44.1kHz */
622 623 switch (params_rate(params)) {
623 - /* bit 14 0:48K 1:44.1K */
624 624 case 44100:
625 + val |= BIT(14);
626 + break;
625 627 case 48000:
626 628 break;
627 629 default:
modified sound/soc/codecs/rt286.c
@@ -953,7 +953,7 @@ static int rt286_probe(struct snd_soc_component *component)
953 953
954 954 if (rt286->i2c->irq)
955 955 schedule_delayed_work(&rt286->jack_detect_work,
956 - msecs_to_jiffies(50));
956 + msecs_to_jiffies(1250));
957 957 return 0;
958 958 }
959 959
modified sound/soc/codecs/wm8903.c
@@ -676,7 +676,7 @@ SOC_ENUM("DRC Decay Rate", drc_decay),
676 676 SOC_ENUM("DRC FF Delay", drc_ff_delay),
677 677 SOC_SINGLE("DRC Anticlip Switch", WM8903_DRC_0, 1, 1, 0),
678 678 SOC_SINGLE("DRC QR Switch", WM8903_DRC_0, 2, 1, 0),
679 - SOC_SINGLE_TLV("DRC QR Threshold Volume", WM8903_DRC_0, 6, 3, 0, drc_tlv_max),
679 + SOC_SINGLE_TLV("DRC QR Threshold Volume", WM8903_DRC_1, 6, 3, 0, drc_tlv_max),
680 680 SOC_ENUM("DRC QR Decay Rate", drc_qr_decay),
681 681 SOC_SINGLE("DRC Smoothing Switch", WM8903_DRC_0, 3, 1, 0),
682 682 SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8903_DRC_0, 0, 1, 0),
modified sound/soc/intel/boards/bytcr_rt5651.c
@@ -410,6 +410,23 @@ static const struct dmi_system_id byt_rt5651_quirk_table[] = {
410 410 BYT_RT5651_HP_LR_SWAPPED |
411 411 BYT_RT5651_MONO_SPEAKER),
412 412 },
413 + {
414 + /* Chuwi Hi8 (CWI513) with a BIOS using generic DMI strings */
415 + .callback = byt_rt5651_quirk_cb,
416 + .matches = {
417 + DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
418 + DMI_MATCH(DMI_BOARD_NAME, "Cherry Trail CR"),
419 + /* Above matches are too generic, add bios-date match */
420 + DMI_MATCH(DMI_BIOS_DATE, "05/21/2016"),
421 + },
422 + .driver_data = (void *)(BYT_RT5651_MCLK_EN |
423 + BYT_RT5651_JD1_1 |
424 + BYT_RT5651_OVCD_TH_2000UA |
425 + BYT_RT5651_OVCD_SF_1P0 |
426 + BYT_RT5651_IN2_MAP |
427 + BYT_RT5651_HP_LR_SWAPPED |
428 + BYT_RT5651_MONO_SPEAKER),
429 + },
413 430 {
414 431 /* Chuwi Vi8 Plus (CWI519) */
415 432 .callback = byt_rt5651_quirk_cb,
modified sound/soc/intel/common/soc-acpi-intel-lnl-match.c
@@ -745,6 +745,7 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_lnl_sdw_machines[] = {
745 745 .links = lnl_cs42l43_l0,
746 746 .drv_name = "sof_sdw",
747 747 .sof_tplg_filename = "sof-lnl-cs42l43-l0.tplg",
748 + .machine_check = snd_soc_acpi_intel_force_function_topology,
748 749 .get_function_tplg_files = sof_sdw_get_tplg_files,
749 750 },
750 751 {
modified sound/soc/intel/common/soc-acpi-intel-sdca-quirks.c
@@ -53,6 +53,22 @@ bool snd_soc_acpi_intel_no_function_topology(void *arg)
53 53 }
54 54 EXPORT_SYMBOL_NS(snd_soc_acpi_intel_no_function_topology, "SND_SOC_ACPI_INTEL_SDCA_QUIRKS");
55 55
56 + static const struct dmi_system_id force_function_topology_quirk_table[] = {
57 + {
58 + .matches = {
59 + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
60 + DMI_MATCH(DMI_PRODUCT_NAME, "83R0"),
61 + },
62 + },
63 + {}
64 + };
65 +
66 + bool snd_soc_acpi_intel_force_function_topology(void *arg)
67 + {
68 + return !dmi_check_system(force_function_topology_quirk_table);
69 + }
70 + EXPORT_SYMBOL_NS(snd_soc_acpi_intel_force_function_topology, "SND_SOC_ACPI_INTEL_SDCA_QUIRKS");
71 +
56 72 bool snd_soc_acpi_intel_rt712_vb_no_function_topology(void *arg)
57 73 {
58 74 return snd_soc_acpi_intel_sdca_is_device_rt712_vb(arg) &&
modified sound/soc/intel/common/soc-acpi-intel-sdca-quirks.h
@@ -11,6 +11,7 @@
11 11
12 12 bool snd_soc_acpi_intel_sdca_is_device_rt712_vb(void *arg);
13 13 bool snd_soc_acpi_intel_no_function_topology(void *arg);
14 + bool snd_soc_acpi_intel_force_function_topology(void *arg);
14 15 bool snd_soc_acpi_intel_rt712_vb_no_function_topology(void *arg);
15 16
16 17 #endif
modified sound/soc/qcom/lpass-cpu.c
@@ -1234,8 +1234,8 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
1234 1234 }
1235 1235 if (drvdata->mi2s_playback_sd_mode[dai_id] ==
1236 1236 LPAIF_I2SCTL_MODE_QUAD01) {
1237 - variant->dai_driver[dai_id].playback.channels_min = 4;
1238 - variant->dai_driver[dai_id].playback.channels_max = 4;
1237 + variant->dai_driver[i].playback.channels_min = 4;
1238 + variant->dai_driver[i].playback.channels_max = 4;
1239 1239 }
1240 1240 }
1241 1241
modified sound/soc/samsung/i2s.c
@@ -1534,9 +1534,16 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1534 1534 goto err_disable_pm;
1535 1535
1536 1536 priv->op_clk = clk_get_parent(priv->clk_table[CLK_I2S_RCLK_SRC]);
1537 + ret = clk_prepare_enable(priv->op_clk);
1538 + if (ret < 0) {
1539 + priv->op_clk = NULL;
1540 + goto err_unregister_clk;
1541 + }
1537 1542
1538 1543 return 0;
1539 1544
1545 + err_unregister_clk:
1546 + i2s_unregister_clock_provider(priv);
1540 1547 err_disable_pm:
1541 1548 pm_runtime_disable(&pdev->dev);
1542 1549 err_del_sec:
@@ -1559,6 +1566,7 @@ static void samsung_i2s_remove(struct platform_device *pdev)
1559 1566
1560 1567 i2s_unregister_clock_provider(priv);
1561 1568 i2s_delete_secondary_device(priv);
1569 + clk_disable_unprepare(priv->op_clk);
1562 1570 clk_disable_unprepare(priv->clk);
1563 1571
1564 1572 pm_runtime_put_noidle(&pdev->dev);
modified sound/soc/sdca/sdca_class_function.c
@@ -388,20 +388,27 @@ static int class_function_probe(struct auxiliary_device *auxdev,
388 388
389 389 ret = devm_pm_runtime_enable(dev);
390 390 if (ret)
391 - return ret;
391 + goto err_pm;
392 392
393 393 ret = class_function_boot(drv);
394 394 if (ret)
395 - return ret;
395 + goto err_pm;
396 396
397 397 ret = devm_snd_soc_register_component(dev, cmp_drv, dais, num_dais);
398 - if (ret)
399 - return dev_err_probe(dev, ret, "failed to register component\n");
398 + if (ret) {
399 + dev_err_probe(dev, ret, "failed to register component\n");
400 + goto err_pm;
401 + }
400 402
401 403 pm_runtime_mark_last_busy(dev);
402 404 pm_runtime_put_autosuspend(dev);
403 405
404 406 return 0;
407 +
408 + err_pm:
409 + pm_runtime_put_sync(dev);
410 +
411 + return ret;
405 412 }
406 413
407 414 static void class_function_remove(struct auxiliary_device *auxdev)
@@ -490,8 +497,6 @@ static int class_function_suspend(struct device *dev)
490 497 struct class_function_drv *drv = auxiliary_get_drvdata(auxdev);
491 498 int ret;
492 499
493 - drv->suspended = true;
494 -
495 500 /* Ensure runtime resume runs on resume */
496 501 ret = pm_runtime_resume_and_get(dev);
497 502 if (ret) {
@@ -499,6 +504,8 @@ static int class_function_suspend(struct device *dev)
499 504 return ret;
500 505 }
501 506
507 + drv->suspended = true;
508 +
502 509 sdca_irq_disable(drv->function, drv->core->irq_info);
503 510
504 511 ret = pm_runtime_force_suspend(dev);
modified sound/soc/sdw_utils/soc_sdw_utils.c
@@ -808,7 +808,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
808 808 },
809 809 {
810 810 .direction = {false, true},
811 - .dai_name = "cs35l56-sdw1c",
811 + .dai_name = "cs35l56-ot25",
812 812 .dai_type = SOC_SDW_DAI_TYPE_AMP,
813 813 .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
814 814 },
@@ -836,7 +836,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
836 836 },
837 837 {
838 838 .direction = {false, true},
839 - .dai_name = "cs35l56-sdw1c",
839 + .dai_name = "cs35l56-ot25",
840 840 .dai_type = SOC_SDW_DAI_TYPE_AMP,
841 841 .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
842 842 },
@@ -864,7 +864,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
864 864 },
865 865 {
866 866 .direction = {false, true},
867 - .dai_name = "cs35l56-sdw1c",
867 + .dai_name = "cs35l56-ot25",
868 868 .dai_type = SOC_SDW_DAI_TYPE_AMP,
869 869 .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
870 870 },
@@ -892,7 +892,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
892 892 },
893 893 {
894 894 .direction = {false, true},
895 - .dai_name = "cs35l56-sdw1c",
895 + .dai_name = "cs35l56-ot25",
896 896 .dai_type = SOC_SDW_DAI_TYPE_AMP,
897 897 .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_AMP_IN_DAI_ID},
898 898 },
modified sound/soc/sof/ipc4-topology.c
@@ -2458,11 +2458,14 @@ _sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
2458 2458 ch_map >>= 4;
2459 2459 }
2460 2460
2461 - if (swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) {
2461 + if ((swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) ||
2462 + ch_count < blob->alh_cfg.device_count) {
2462 2463 /*
2463 2464 * For playback DAI widgets where the channel number is equal to
2464 - * the output reference channels, set the step = 0 to ensure all
2465 - * the ch_mask is applied to all alh mappings.
2465 + * the output reference channels, or when there are fewer
2466 + * channels than aggregated devices (e.g. a mono capture
2467 + * stream split across multiple links), set step = 0 to
2468 + * ensure all the ch_mask is applied to all alh mappings.
2466 2469 */
2467 2470 mask = ch_mask;
2468 2471 step = 0;
modified sound/soc/sof/sof-client.c
@@ -576,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
576 576 struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
577 577 struct sof_ipc_event_entry *event;
578 578
579 - guard(mutex)(&sdev->ipc_client_mutex);
579 + guard(mutex)(&sdev->client_event_handler_mutex);
580 580
581 581 list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
582 582 if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) {
@@ -593,7 +593,7 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
593 593 {
594 594 struct sof_state_event_entry *event;
595 595
596 - guard(mutex)(&sdev->ipc_client_mutex);
596 + guard(mutex)(&sdev->client_event_handler_mutex);
597 597
598 598 list_for_each_entry(event, &sdev->fw_state_handler_list, list)
599 599 event->callback(event->cdev, sdev->fw_state);
@@ -628,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
628 628 struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
629 629 struct sof_state_event_entry *event;
630 630
631 - guard(mutex)(&sdev->ipc_client_mutex);
631 + guard(mutex)(&sdev->client_event_handler_mutex);
632 632
633 633 list_for_each_entry(event, &sdev->fw_state_handler_list, list) {
634 634 if (event->cdev == cdev) {
modified sound/soc/tegra/tegra186_asrc.c
@@ -828,7 +828,7 @@ static const struct snd_kcontrol_new tegra186_asrc_controls[] = {
828 828 tegra186_asrc_put_input_threshold),
829 829
830 830 SOC_SINGLE_EXT("Stream6 Input Threshold",
831 - ASRC_STREAM_REG(TEGRA186_ASRC_RX_THRESHOLD, 4), 0, 3, 0,
831 + ASRC_STREAM_REG(TEGRA186_ASRC_RX_THRESHOLD, 5), 0, 3, 0,
832 832 tegra186_asrc_get_input_threshold,
833 833 tegra186_asrc_put_input_threshold),
834 834
modified sound/usb/caiaq/device.c
@@ -562,6 +562,9 @@ static int snd_probe(struct usb_interface *intf,
562 562 ret = init_card(caiaqdev(card));
563 563 if (ret < 0) {
564 564 dev_err(&usb_dev->dev, "unable to init card! (ret=%d)\n", ret);
565 + #ifdef CONFIG_SND_USB_CAIAQ_INPUT
566 + snd_usb_caiaq_input_disconnect(caiaqdev(card));
567 + #endif
565 568 snd_card_free(card);
566 569 return ret;
567 570 }
modified sound/usb/line6/playback.c
@@ -182,6 +182,13 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
182 182
183 183 fsize *= bytes_per_frame;
184 184
185 + if (fsize > line6pcm->max_packet_size_out) {
186 + dev_err(line6pcm->line6->ifcdev,
187 + "playback packet too large: %d > %d\n",
188 + fsize, line6pcm->max_packet_size_out);
189 + return -EMSGSIZE;
190 + }
191 +
185 192 fout->offset = urb_size;
186 193 fout->length = fsize;
187 194 urb_size += fsize;
modified sound/usb/misc/ua101.c
@@ -1007,6 +1007,15 @@ static int detect_usb_format(struct ua101 *ua)
1007 1007 }
1008 1008 ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, usb_endpoint_num(epd));
1009 1009 ua->playback.max_packet_bytes = usb_endpoint_maxp(epd);
1010 +
1011 + if (ua->capture.max_packet_bytes / ua->capture.frame_bytes *
1012 + ua->playback.frame_bytes > ua->playback.max_packet_bytes) {
1013 + dev_err(&ua->dev->dev,
1014 + "playback packet size %u too small for %u capture frames\n",
1015 + ua->playback.max_packet_bytes,
1016 + ua->capture.max_packet_bytes / ua->capture.frame_bytes);
1017 + return -ENXIO;
1018 + }
1010 1019 return 0;
1011 1020 }
1012 1021
modified sound/usb/mixer_maps.c
@@ -749,6 +749,10 @@ static const struct usbmix_ctl_map usbmix_ctl_maps[] = {
749 749 .id = USB_ID(0x0db0, 0xa073),
750 750 .map = msi_mpg_x570s_carbon_max_wifi_alc4080_map,
751 751 },
752 + { /* MSI MAG B850M MORTAR WIFI */
753 + .id = USB_ID(0x0db0, 0xcc78),
754 + .map = msi_mpg_x570s_carbon_max_wifi_alc4080_map,
755 + },
752 756 { /* MSI TRX40 */
753 757 .id = USB_ID(0x0db0, 0x543d),
754 758 .map = trx40_mobo_map,
modified sound/usb/quirks.c
@@ -1702,10 +1702,12 @@ int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
1702 1702 switch (id) {
1703 1703 case USB_ID(0x07fd, 0x0008): /* MOTU M Series, 1st hardware version */
1704 1704 return snd_usb_motu_m_series_boot_quirk(dev);
1705 - case USB_ID(0x1397, 0x1234): /* Behringer CM1A */
1706 - return snd_usb_cm1a_boot_quirk(dev);
1707 1705 }
1708 1706
1707 + /* Behringer devices may need explicit device descriptor read at boot */
1708 + if (USB_ID_VENDOR(id) == 0x1397)
1709 + return snd_usb_cm1a_boot_quirk(dev);
1710 +
1709 1711 return 0;
1710 1712 }
1711 1713
@@ -2366,6 +2368,10 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2366 2368 QUIRK_FLAG_CTL_MSG_DELAY_1M),
2367 2369 DEVICE_FLG(0x0a73, 0x003a, /* Mackie DLZ Creator XS */
2368 2370 QUIRK_FLAG_ALWAYS_SET_RATE),
2371 + DEVICE_FLG(0x0b05, 0x1826, /* ASUS SupremeFX Hi-Fi */
2372 + QUIRK_FLAG_DISABLE_AUTOSUSPEND),
2373 + DEVICE_FLG(0x0b05, 0x1827, /* ASUS SupremeFX Hi-Fi */
2374 + QUIRK_FLAG_DISABLE_AUTOSUSPEND),
2369 2375 DEVICE_FLG(0x0b05, 0x18a6, /* ASUSTek Computer, Inc. */
2370 2376 QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE),
2371 2377 DEVICE_FLG(0x0b0e, 0x0349, /* Jabra 550a */
@@ -2510,8 +2516,6 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2510 2516 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2511 2517 DEVICE_FLG(0x262a, 0x9302, /* ddHiFi TC44C */
2512 2518 QUIRK_FLAG_DSD_RAW),
2513 - DEVICE_FLG(0x2708, 0x0002, /* Audient iD14 */
2514 - QUIRK_FLAG_IGNORE_CTL_ERROR),
2515 2519 DEVICE_FLG(0x2772, 0x0502, /* Musical Fidelity M6s DAC */
2516 2520 0), /* for avoiding QUIRK_FLAG_DSD_RAW with vendor match */
2517 2521 DEVICE_FLG(0x2912, 0x30c8, /* Audioengine D1 */
@@ -2542,6 +2546,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2542 2546 QUIRK_FLAG_IGNORE_CTL_ERROR),
2543 2547 DEVICE_FLG(0x3255, 0x0000, /* Luxman D-10X */
2544 2548 QUIRK_FLAG_ITF_USB_DSD_DAC | QUIRK_FLAG_CTL_MSG_DELAY),
2549 + DEVICE_FLG(0x32bb, 0x0004, /* HiBy FC4 */
2550 + QUIRK_FLAG_DSD_RAW),
2545 2551 DEVICE_FLG(0x3302, 0x17c2, /* TTGK Technology USB-C Audio */
2546 2552 QUIRK_FLAG_FORCE_IFACE_RESET | QUIRK_FLAG_IFACE_DELAY),
2547 2553 DEVICE_FLG(0x339b, 0x3a07, /* Synaptics HONOR USB-C HEADSET */
@@ -2608,6 +2614,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2608 2614 QUIRK_FLAG_DSD_RAW),
2609 2615 VENDOR_FLG(0x2622, /* IAG Limited devices */
2610 2616 QUIRK_FLAG_DSD_RAW),
2617 + VENDOR_FLG(0x2708, /* Audient devices */
2618 + QUIRK_FLAG_IGNORE_CTL_ERROR),
2611 2619 VENDOR_FLG(0x2772, /* Musical Fidelity devices */
2612 2620 QUIRK_FLAG_DSD_RAW),
2613 2621 VENDOR_FLG(0x278b, /* Rotel? */
added tools/testing/selftests/bpf/prog_tests/bpf_ma_ttrace.c mode 100644
@@ -0,0 +1,60 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + #include <test_progs.h>
3 + #include "bpf_ma_ttrace.skel.h"
4 +
5 + #define NR_ELEMS 4096
6 +
7 + /*
8 + * The first free_bulk() starts RCU tasks trace GP. The rest of the elements are
9 + * deleted while it's in flight. They should be freed without further alloc or
10 + * free from this map.
11 + */
12 + void test_bpf_ma_ttrace(void)
13 + {
14 + LIBBPF_OPTS(bpf_test_run_opts, opts);
15 + struct bpf_ma_ttrace *skel;
16 + __u32 cnt = NR_ELEMS;
17 + long *vals = NULL;
18 + int *keys = NULL;
19 + int i, err, fd, nr_cpus;
20 +
21 + skel = bpf_ma_ttrace__open_and_load();
22 + if (!ASSERT_OK_PTR(skel, "open_and_load"))
23 + return;
24 + nr_cpus = libbpf_num_possible_cpus();
25 + if (!ASSERT_GT(nr_cpus, 0, "nr_cpus"))
26 + goto out;
27 + skel->bss->nr_cpus = nr_cpus;
28 +
29 + keys = calloc(NR_ELEMS, sizeof(*keys));
30 + vals = calloc(NR_ELEMS, sizeof(*vals));
31 + if (!ASSERT_OK_PTR(keys, "keys") || !ASSERT_OK_PTR(vals, "vals"))
32 + goto out;
33 + for (i = 0; i < NR_ELEMS; i++)
34 + keys[i] = i;
35 +
36 + fd = bpf_map__fd(skel->maps.htab);
37 + err = bpf_map_update_batch(fd, keys, vals, &cnt, NULL);
38 + if (!ASSERT_OK(err, "update_batch") || !ASSERT_EQ(cnt, NR_ELEMS, "update_cnt"))
39 + goto out;
40 + err = bpf_map_delete_batch(fd, keys, &cnt, NULL);
41 + if (!ASSERT_OK(err, "delete_batch") || !ASSERT_EQ(cnt, NR_ELEMS, "delete_cnt"))
42 + goto out;
43 +
44 + /* Wait for all __free_rcu() callbacks to finish */
45 + for (i = 0; i < 300; i++) {
46 + err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.check_ttrace), &opts);
47 + if (!ASSERT_OK(err, "test_run") || !ASSERT_OK(opts.retval, "retval"))
48 + goto out;
49 + if (!skel->bss->in_progress)
50 + break;
51 + usleep(100000);
52 + }
53 + ASSERT_EQ(skel->bss->nr_caches, nr_cpus, "nr_caches");
54 + ASSERT_EQ(skel->bss->in_progress, 0, "in_progress");
55 + ASSERT_EQ(skel->bss->not_freed, 0, "not_freed");
56 + out:
57 + free(keys);
58 + free(vals);
59 + bpf_ma_ttrace__destroy(skel);
60 + }
modified tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c
@@ -55,38 +55,6 @@ static void *load_module_thread(void *p)
55 55 return p;
56 56 }
57 57
58 - static int sys_userfaultfd(int flags)
59 - {
60 - return syscall(__NR_userfaultfd, flags);
61 - }
62 -
63 - static int test_setup_uffd(void *fault_addr)
64 - {
65 - struct uffdio_register uffd_register = {};
66 - struct uffdio_api uffd_api = {};
67 - int uffd;
68 -
69 - uffd = sys_userfaultfd(O_CLOEXEC);
70 - if (uffd < 0)
71 - return -errno;
72 -
73 - uffd_api.api = UFFD_API;
74 - uffd_api.features = 0;
75 - if (ioctl(uffd, UFFDIO_API, &uffd_api)) {
76 - close(uffd);
77 - return -1;
78 - }
79 -
80 - uffd_register.range.start = (unsigned long)fault_addr;
81 - uffd_register.range.len = getpagesize();
82 - uffd_register.mode = UFFDIO_REGISTER_MODE_MISSING;
83 - if (ioctl(uffd, UFFDIO_REGISTER, &uffd_register)) {
84 - close(uffd);
85 - return -1;
86 - }
87 - return uffd;
88 - }
89 -
90 58 static void test_bpf_mod_race_config(const struct test_config *config)
91 59 {
92 60 void *fault_addr, *skel_fail;
@@ -117,7 +85,7 @@ static void test_bpf_mod_race_config(const struct test_config *config)
117 85 if (!ASSERT_OK(bpf_mod_race__attach(skel), "bpf_mod_kfunc_race__attach"))
118 86 goto end_destroy;
119 87
120 - uffd = test_setup_uffd(fault_addr);
88 + uffd = uffd_block_page(fault_addr);
121 89 if (!ASSERT_GE(uffd, 0, "userfaultfd open + register address"))
122 90 goto end_destroy;
123 91
added tools/testing/selftests/bpf/prog_tests/tramp_prog_detach.c mode 100644
@@ -0,0 +1,188 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + #include <test_progs.h>
3 + #include <pthread.h>
4 + #include <poll.h>
5 + #include <sys/mman.h>
6 + #include <linux/userfaultfd.h>
7 + #include "tramp_prog_detach.skel.h"
8 + #include "testing_helpers.h"
9 +
10 + /*
11 + * Detach and free progs while a task sleeps in the prog that runs before them
12 + * in the same trampoline image, then let that task continue through the
13 + * image. It must not call into the freed progs.
14 + *
15 + * The task is held in a sleepable prog with userfaultfd, like bpf_mod_race
16 + * does.
17 + */
18 +
19 + static struct bpf_program *pick_prog(struct tramp_prog_detach *skel,
20 + bool fexit, bool sleepable)
21 + {
22 + if (fexit)
23 + return sleepable ? skel->progs.fexit_sleepable :
24 + skel->progs.fexit_victim;
25 + return sleepable ? skel->progs.fentry_sleepable :
26 + skel->progs.fentry_victim;
27 + }
28 +
29 + static struct bpf_program *sleepable_prog;
30 +
31 + static void *run_sleepable(void *arg)
32 + {
33 + LIBBPF_OPTS(bpf_test_run_opts, topts);
34 +
35 + /* calls bpf_fentry_test1() */
36 + return (void *)(long)bpf_prog_test_run_opts(bpf_program__fd(sleepable_prog),
37 + &topts);
38 + }
39 +
40 + static struct tramp_prog_detach *load_one(bool fexit, bool sleepable)
41 + {
42 + struct tramp_prog_detach *skel;
43 + int err;
44 +
45 + skel = tramp_prog_detach__open();
46 + if (!ASSERT_OK_PTR(skel, "open"))
47 + return NULL;
48 +
49 + bpf_program__set_autoload(pick_prog(skel, fexit, sleepable), true);
50 + err = tramp_prog_detach__load(skel);
51 + if (!ASSERT_OK(err, "load"))
52 + goto err;
53 + skel->bss->pid = getpid();
54 + err = tramp_prog_detach__attach(skel);
55 + if (!ASSERT_OK(err, "attach"))
56 + goto err;
57 + return skel;
58 + err:
59 + tramp_prog_detach__destroy(skel);
60 + return NULL;
61 + }
62 +
63 + /* The .bss map of a destroyed skeleton goes away when its prog is freed */
64 + static bool wait_for_map_free(__u32 map_id)
65 + {
66 + int i, fd;
67 +
68 + for (i = 0; i < 100; i++) {
69 + fd = bpf_map_get_fd_by_id(map_id);
70 + if (fd < 0)
71 + return true;
72 + close(fd);
73 + usleep(100 * 1000);
74 + }
75 + return false;
76 + }
77 +
78 + static void test_detach(bool sleepable_fexit, bool victim_fexit)
79 + {
80 + struct tramp_prog_detach *sleepable = NULL, *victims[2] = {};
81 + struct pollfd pfd = { .events = POLLIN };
82 + struct uffdio_copy uffd_copy = {};
83 + struct bpf_map_info map_info = {};
84 + __u32 map_info_len = sizeof(map_info);
85 + struct uffd_msg uffd_msg;
86 + void *fault_page, *src_page = MAP_FAILED;
87 + long page_size = getpagesize();
88 + bool started = false;
89 + void *thread_ret;
90 + pthread_t thread;
91 + int i, uffd = -1;
92 +
93 + fault_page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
94 + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
95 + if (!ASSERT_NEQ(fault_page, MAP_FAILED, "mmap fault_page"))
96 + return;
97 + src_page = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
98 + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
99 + if (!ASSERT_NEQ(src_page, MAP_FAILED, "mmap src_page"))
100 + goto out;
101 +
102 + /* The most recently attached prog runs first */
103 + for (i = 0; i < ARRAY_SIZE(victims); i++) {
104 + victims[i] = load_one(victim_fexit, false);
105 + if (!victims[i])
106 + goto out;
107 + }
108 + sleepable = load_one(sleepable_fexit, true);
109 + if (!sleepable)
110 + goto out;
111 + sleepable_prog = pick_prog(sleepable, sleepable_fexit, true);
112 +
113 + /* Not armed yet so this doesn't block, make sure sleepable runs first */
114 + if (!ASSERT_OK((long)run_sleepable(NULL), "dry run"))
115 + goto out;
116 + for (i = 0; i < ARRAY_SIZE(victims); i++)
117 + if (!ASSERT_LT(sleepable->bss->ts, victims[i]->bss->ts, "prog order"))
118 + goto out;
119 +
120 + uffd = uffd_block_page(fault_page);
121 + if (!ASSERT_GE(uffd, 0, "userfaultfd open + register address"))
122 + goto out;
123 + sleepable->bss->fault_addr = fault_page;
124 +
125 + if (!ASSERT_OK(pthread_create(&thread, NULL, run_sleepable, NULL),
126 + "pthread_create"))
127 + goto out;
128 + started = true;
129 +
130 + /* Wait for the thread to sleep in bpf_copy_from_user() */
131 + pfd.fd = uffd;
132 + if (!ASSERT_EQ(poll(&pfd, 1, 10000), 1, "poll uffd"))
133 + goto out;
134 + if (!ASSERT_EQ(read(uffd, &uffd_msg, sizeof(uffd_msg)), sizeof(uffd_msg),
135 + "read uffd"))
136 + goto out;
137 + if (!ASSERT_EQ(uffd_msg.event, UFFD_EVENT_PAGEFAULT, "uffd pagefault"))
138 + goto out;
139 +
140 + /*
141 + * Detach and unload the victim progs and wait for them to be freed.
142 + * After the first one, the task is in an image that isn't the
143 + * trampoline's current one anymore.
144 + */
145 + for (i = 0; i < ARRAY_SIZE(victims); i++) {
146 + if (!ASSERT_OK(bpf_map_get_info_by_fd(bpf_map__fd(victims[i]->maps.bss),
147 + &map_info, &map_info_len),
148 + "victim bss info"))
149 + goto out;
150 + tramp_prog_detach__destroy(victims[i]);
151 + victims[i] = NULL;
152 + if (!ASSERT_TRUE(wait_for_map_free(map_info.id), "victim freed"))
153 + goto out;
154 + }
155 +
156 + out:
157 + /* Let the thread proceed with the rest of the trampoline */
158 + if (uffd >= 0) {
159 + uffd_copy.dst = (unsigned long)fault_page;
160 + uffd_copy.src = (unsigned long)src_page;
161 + uffd_copy.len = page_size;
162 + ASSERT_OK(ioctl(uffd, UFFDIO_COPY, &uffd_copy), "uffd copy");
163 + close(uffd);
164 + }
165 + if (started &&
166 + ASSERT_OK(pthread_join(thread, &thread_ret), "pthread_join"))
167 + ASSERT_NULL(thread_ret, "blocking run");
168 +
169 + for (i = 0; i < ARRAY_SIZE(victims); i++)
170 + tramp_prog_detach__destroy(victims[i]);
171 + tramp_prog_detach__destroy(sleepable);
172 + if (src_page != MAP_FAILED)
173 + munmap(src_page, page_size);
174 + munmap(fault_page, page_size);
175 + }
176 +
177 + void serial_test_tramp_prog_detach(void)
178 + {
179 + /* a task sleeping before the original function is called */
180 + if (test__start_subtest("fentry"))
181 + test_detach(false, false);
182 + /* a task sleeping after the original function returned */
183 + if (test__start_subtest("fexit"))
184 + test_detach(true, true);
185 + /* the original function runs in between and must still be called */
186 + if (test__start_subtest("fentry_fexit"))
187 + test_detach(false, true);
188 + }
added tools/testing/selftests/bpf/progs/bpf_ma_ttrace.c mode 100644
@@ -0,0 +1,50 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + #include <vmlinux.h>
3 + #include <bpf/bpf_helpers.h>
4 + #include <bpf/bpf_core_read.h>
5 + #include "bpf_kfuncs.h"
6 +
7 + struct {
8 + __uint(type, BPF_MAP_TYPE_HASH);
9 + __uint(map_flags, BPF_F_NO_PREALLOC);
10 + __uint(max_entries, 4096);
11 + __type(key, int);
12 + __type(value, long);
13 + } htab SEC(".maps");
14 +
15 + extern const void __per_cpu_offset __ksym;
16 +
17 + int nr_cpus;
18 + int nr_caches;
19 + int in_progress;
20 + int not_freed;
21 +
22 + /* Look at bpf_mem_cache of every cpu that htab allocates its elements from */
23 + SEC("syscall")
24 + int check_ttrace(void *ctx)
25 + {
26 + struct bpf_htab *h = bpf_core_cast(&htab, struct bpf_htab);
27 + unsigned long cache = (unsigned long)BPF_CORE_READ(h, ma.cache);
28 + const unsigned long *offsets = &__per_cpu_offset;
29 + struct bpf_mem_cache *c;
30 + unsigned long off;
31 + int cpu;
32 +
33 + nr_caches = 0;
34 + in_progress = 0;
35 + not_freed = 0;
36 + bpf_for(cpu, 0, nr_cpus) {
37 + if (bpf_probe_read_kernel(&off, sizeof(off), offsets + cpu))
38 + return -1;
39 + c = bpf_core_cast((void *)(cache + off), struct bpf_mem_cache);
40 + if (c->unit_size)
41 + nr_caches++;
42 + if (c->call_rcu_ttrace_in_progress.counter)
43 + in_progress++;
44 + if (c->free_by_rcu_ttrace.first || c->waiting_for_gp_ttrace.first)
45 + not_freed++;
46 + }
47 + return 0;
48 + }
49 +
50 + char _license[] SEC("license") = "GPL";
added tools/testing/selftests/bpf/progs/tramp_prog_detach.c mode 100644
@@ -0,0 +1,56 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + #include "vmlinux.h"
3 + #include <bpf/bpf_helpers.h>
4 + #include <bpf/bpf_tracing.h>
5 +
6 + char _license[] SEC("license") = "GPL";
7 +
8 + int pid;
9 + void *fault_addr;
10 + __u64 ts;
11 +
12 + static int do_sleepable(void)
13 + {
14 + char dst;
15 +
16 + if (bpf_get_current_pid_tgid() >> 32 != pid)
17 + return 0;
18 +
19 + ts = bpf_ktime_get_ns();
20 + /* blocks for as long as user space wants when fault_addr is armed */
21 + bpf_copy_from_user(&dst, sizeof(dst), fault_addr);
22 + return 0;
23 + }
24 +
25 + static int do_victim(void)
26 + {
27 + if (bpf_get_current_pid_tgid() >> 32 != pid)
28 + return 0;
29 +
30 + ts = bpf_ktime_get_ns();
31 + return 0;
32 + }
33 +
34 + SEC("?fentry.s/bpf_fentry_test1")
35 + int BPF_PROG(fentry_sleepable, int a)
36 + {
37 + return do_sleepable();
38 + }
39 +
40 + SEC("?fentry/bpf_fentry_test1")
41 + int BPF_PROG(fentry_victim, int a)
42 + {
43 + return do_victim();
44 + }
45 +
46 + SEC("?fexit.s/bpf_fentry_test1")
47 + int BPF_PROG(fexit_sleepable, int a, int ret)
48 + {
49 + return do_sleepable();
50 + }
51 +
52 + SEC("?fexit/bpf_fentry_test1")
53 + int BPF_PROG(fexit_victim, int a, int ret)
54 + {
55 + return do_victim();
56 + }
modified tools/testing/selftests/bpf/progs/verifier_align.c
@@ -284,7 +284,7 @@ __msg("26: {{.*}} R5=pkt(r=8,imm=14)")
284 284 */
285 285 __msg("28: {{.*}} R4={{[^)]*}}var_off=(0x2; 0x7fc){{.*}} R5={{[^)]*}}var_off=(0x2; 0x7fc)")
286 286 /* Constant is added to R5 again, setting reg->off to 18. */
287 - __msg("29: {{.*}} R5=pkt(id=3,{{[^)]*}}var_off=(0x2; 0x7fc)")
287 + __msg("29: {{.*}} R5=pkt(id=3,{{[^)]*}}var_off=(0x2; 0xffc)")
288 288 /* And once more we add a variable; resulting {{[^)]*}}var_off
289 289 * is still (4n), fixed offset is not changed.
290 290 * Also, we create a new reg->id.
@@ -359,7 +359,7 @@ __msg("7: {{.*}} R6={{[^)]*}}var_off=(0x0; 0x3fc)")
359 359 __msg("8: {{.*}} R6={{[^)]*}}var_off=(0x2; 0x7fc)")
360 360 /* Packet pointer has (4n+2) offset */
361 361 __msg("11: {{.*}} R5={{[^)]*}}var_off=(0x2; 0x7fc)")
362 - __msg("12: {{.*}} R4={{[^)]*}}var_off=(0x2; 0x7fc)")
362 + __msg("12: {{.*}} R4={{[^)]*}}var_off=(0x2; 0xffc)")
363 363 /* At the time the word size load is performed from R5,
364 364 * its total fixed offset is NET_IP_ALIGN + reg->off (0)
365 365 * which is 2. Then the variable offset is (4n+2), so
@@ -375,7 +375,7 @@ __msg("17: {{.*}} R6={{[^)]*}}var_off=(0x0; 0x3fc)")
375 375 * another (4n+2).
376 376 */
377 377 __msg("19: {{.*}} R5={{[^)]*}}var_off=(0x2; 0xffc)")
378 - __msg("20: {{.*}} R4={{[^)]*}}var_off=(0x2; 0xffc)")
378 + __msg("20: {{.*}} R4={{[^)]*}}var_off=(0x2; 0x1ffc)")
379 379 /* At the time the word size load is performed from R5,
380 380 * its total fixed offset is NET_IP_ALIGN + reg->off (0)
381 381 * which is 2. Then the variable offset is (4n+2), so
modified tools/testing/selftests/bpf/progs/verifier_direct_packet_access.c
@@ -920,4 +920,182 @@ l1_%=: r0 = *(u8*)(r9 + 0); \
920 920 : __clobber_all);
921 921 }
922 922
923 + SEC("tc")
924 + __description("direct packet access: 8-aligned offset, check p + 8, load 8 bytes at p")
925 + __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
926 + __naked void pkt_same_id_check_copy_load_base(void)
927 + {
928 + asm volatile (" \
929 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
930 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
931 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
932 + r4 &= 0x38; \
933 + if r4 > 50 goto l0_%=; \
934 + /* r4 is a multiple of 8, at most 48 */ \
935 + r5 = r2; \
936 + r5 += r4; \
937 + r6 = r5; \
938 + r6 += 8; \
939 + if r6 > r3 goto l0_%=; \
940 + /* [r5, r5 + 8) is in the packet */ \
941 + r0 = *(u64*)(r5 + 0); \
942 + l0_%=: r0 = 0; \
943 + exit; \
944 + " :
945 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
946 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
947 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
948 + : __clobber_all);
949 + }
950 +
951 + SEC("tc")
952 + __description("direct packet access: 8-aligned offset, check p, load past it via p + 8")
953 + __failure __msg("invalid access to packet, off=51 size=1")
954 + __naked void pkt_same_id_check_base_load_via_copy(void)
955 + {
956 + asm volatile (" \
957 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
958 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
959 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
960 + r4 &= 0x38; \
961 + if r4 > 50 goto l0_%=; \
962 + /* r4 is a multiple of 8, at most 48 */ \
963 + r5 = r2; \
964 + r5 += r4; \
965 + r6 = r5; \
966 + r6 += 8; \
967 + if r5 > r3 goto l0_%=; \
968 + /* r6 - 7 is r5 + 1 */ \
969 + r0 = *(u8*)(r6 - 7); \
970 + l0_%=: r0 = 0; \
971 + exit; \
972 + " :
973 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
974 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
975 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
976 + : __clobber_all);
977 + }
978 +
979 + SEC("tc")
980 + __description("direct packet access: 8-aligned offset, check p + 4, 4-byte load at p + 2")
981 + __failure __msg("invalid access to packet, off=52 size=4")
982 + __naked void pkt_same_id_check_base_4_load_via_copy(void)
983 + {
984 + asm volatile (" \
985 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
986 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
987 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
988 + r4 &= 0x38; \
989 + if r4 > 50 goto l0_%=; \
990 + /* r4 is a multiple of 8, at most 48 */ \
991 + r5 = r2; \
992 + r5 += r4; \
993 + r6 = r5; \
994 + r6 += 8; \
995 + r7 = r5; \
996 + r7 += 4; \
997 + if r7 > r3 goto l0_%=; \
998 + /* [r5, r5 + 4) is in the packet, [r5 + 2, r5 + 6) may not be */ \
999 + r0 = *(u32*)(r6 - 6); \
1000 + l0_%=: r0 = 0; \
1001 + exit; \
1002 + " :
1003 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
1004 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
1005 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
1006 + : __clobber_all);
1007 + }
1008 +
1009 + SEC("tc")
1010 + __description("direct packet access: checked pointer minus non-negative unknown keeps range")
1011 + __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
1012 + __naked void pkt_sub_unknown_keeps_range(void)
1013 + {
1014 + asm volatile (" \
1015 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
1016 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
1017 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
1018 + r4 &= 0x1f; \
1019 + r4 += 8; \
1020 + r5 = r2; \
1021 + r5 += 40; \
1022 + if r5 > r3 goto l0_%=; \
1023 + /* r5 is 8 to 39 bytes below the checked pointer */ \
1024 + r5 -= r4; \
1025 + r0 = *(u64*)(r5 + 0); \
1026 + l0_%=: r0 = 0; \
1027 + exit; \
1028 + " :
1029 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
1030 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
1031 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
1032 + : __clobber_all);
1033 + }
1034 +
1035 + SEC("tc")
1036 + __description("direct packet access: no pruning of a path whose checks prove fewer bytes")
1037 + __failure __msg("invalid access to packet, off=255 size=8")
1038 + __flag(BPF_F_ANY_ALIGNMENT) __flag(BPF_F_TEST_STATE_FREQ)
1039 + __naked void pkt_same_id_pruning(void)
1040 + {
1041 + asm volatile (" \
1042 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
1043 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
1044 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
1045 + r0 = *(u32*)(r1 + %[__sk_buff_priority]); \
1046 + r4 &= 0xff; \
1047 + r5 = r2; \
1048 + r5 += r4; \
1049 + if r0 != 0 goto l1_%=; \
1050 + /* this path proves [r5, r5 + 8) */ \
1051 + r6 = r5; \
1052 + r6 += 8; \
1053 + if r6 > r3 goto l0_%=; \
1054 + goto l2_%=; \
1055 + l1_%=: /* this path proves [r5, r5 + 7) */ \
1056 + if r5 > r3 goto l0_%=; \
1057 + r6 = r5; \
1058 + r6 += 7; \
1059 + if r6 > r3 goto l0_%=; \
1060 + l2_%=: r0 = *(u64*)(r5 + 0); \
1061 + l0_%=: r0 = 0; \
1062 + exit; \
1063 + " :
1064 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
1065 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
1066 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark)),
1067 + __imm_const(__sk_buff_priority, offsetof(struct __sk_buff, priority))
1068 + : __clobber_all);
1069 + }
1070 +
1071 + SEC("tc")
1072 + __description("direct packet access: spilled copy of checked pointer, load past range")
1073 + __failure __msg("invalid access to packet, off=262 size=1, R7(id={{[0-9]+}},off=262,r=262)")
1074 + __naked void pkt_spilled_copy_gets_range(void)
1075 + {
1076 + asm volatile (" \
1077 + r2 = *(u32*)(r1 + %[__sk_buff_data]); \
1078 + r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
1079 + r4 = *(u32*)(r1 + %[__sk_buff_mark]); \
1080 + r4 &= 0xff; \
1081 + r5 = r2; \
1082 + r5 += r4; \
1083 + *(u64*)(r10 - 8) = r5; \
1084 + /* proves only bytes before r5 */ \
1085 + if r5 > r3 goto l0_%=; \
1086 + r6 = r5; \
1087 + r6 += 7; \
1088 + if r6 > r3 goto l0_%=; \
1089 + /* [r5, r5 + 7) is in the packet */ \
1090 + r7 = *(u64*)(r10 - 8); \
1091 + r0 = *(u8*)(r7 + 7); \
1092 + l0_%=: r0 = 0; \
1093 + exit; \
1094 + " :
1095 + : __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
1096 + __imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end)),
1097 + __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
1098 + : __clobber_all);
1099 + }
1100 +
923 1101 char _license[] SEC("license") = "GPL";
modified tools/testing/selftests/bpf/progs/verifier_meta_access.c
@@ -281,4 +281,34 @@ l0_%=: r0 = 0; \
281 281 : __clobber_all);
282 282 }
283 283
284 + SEC("xdp")
285 + __description("meta access, 8-aligned offset, check p, load a byte at p + 1 via p + 8")
286 + __failure __msg("invalid access to packet, off=51 size=1")
287 + __naked void meta_access_check_base_load_via_copy(void)
288 + {
289 + asm volatile (" \
290 + r9 = r1; \
291 + call %[bpf_get_prandom_u32]; \
292 + r4 = r0; \
293 + r4 &= 0x38; \
294 + if r4 > 50 goto l0_%=; \
295 + /* r4 is a multiple of 8, at most 48 */ \
296 + r2 = *(u32*)(r9 + %[xdp_md_data_meta]); \
297 + r3 = *(u32*)(r9 + %[xdp_md_data]); \
298 + r5 = r2; \
299 + r5 += r4; \
300 + r6 = r5; \
301 + r6 += 8; \
302 + if r5 > r3 goto l0_%=; \
303 + /* r6 - 7 is r5 + 1 */ \
304 + r0 = *(u8*)(r6 - 7); \
305 + l0_%=: r0 = 0; \
306 + exit; \
307 + " :
308 + : __imm(bpf_get_prandom_u32),
309 + __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
310 + __imm_const(xdp_md_data_meta, offsetof(struct xdp_md, data_meta))
311 + : __clobber_all);
312 + }
313 +
284 314 char _license[] SEC("license") = "GPL";
modified tools/testing/selftests/bpf/testing_helpers.c
@@ -13,6 +13,7 @@
13 13 #include "test_progs.h"
14 14 #include "testing_helpers.h"
15 15 #include <linux/membarrier.h>
16 + #include <linux/userfaultfd.h>
16 17
17 18 int parse_num_list(const char *s, bool **num_set, int *num_set_len)
18 19 {
@@ -459,6 +460,33 @@ int kern_sync_rcu(void)
459 460 return syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0, 0);
460 461 }
461 462
463 + int uffd_block_page(void *fault_addr)
464 + {
465 + struct uffdio_register uffd_register = {};
466 + struct uffdio_api uffd_api = {};
467 + int uffd;
468 +
469 + uffd = syscall(__NR_userfaultfd, O_CLOEXEC);
470 + if (uffd < 0)
471 + return -errno;
472 +
473 + uffd_api.api = UFFD_API;
474 + uffd_api.features = 0;
475 + if (ioctl(uffd, UFFDIO_API, &uffd_api)) {
476 + close(uffd);
477 + return -1;
478 + }
479 +
480 + uffd_register.range.start = (unsigned long)fault_addr;
481 + uffd_register.range.len = getpagesize();
482 + uffd_register.mode = UFFDIO_REGISTER_MODE_MISSING;
483 + if (ioctl(uffd, UFFDIO_REGISTER, &uffd_register)) {
484 + close(uffd);
485 + return -1;
486 + }
487 + return uffd;
488 + }
489 +
462 490 int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt)
463 491 {
464 492 __u32 buf_element_size = sizeof(struct bpf_insn);
modified tools/testing/selftests/bpf/testing_helpers.h
@@ -36,6 +36,8 @@ __u64 read_perf_max_sample_freq(void);
36 36 int load_bpf_testmod(bool verbose);
37 37 int unload_bpf_testmod(bool verbose);
38 38 int kern_sync_rcu(void);
39 + /* returns a userfaultfd that makes accesses to fault_addr's page block */
40 + int uffd_block_page(void *fault_addr);
39 41 int finit_module(int fd, const char *param_values, int flags);
40 42 int delete_module(const char *name, int flags);
41 43 int load_module(const char *path, bool verbose);
modified tools/testing/selftests/hid/hid_bpf.c
@@ -546,6 +546,37 @@ TEST_F(hid_bpf, test_hid_user_raw_request_call)
546 546 ASSERT_EQ(args.data[1], 2);
547 547 }
548 548
549 + /*
550 + * Call hid_hw_raw_request against the given uhid device,
551 + * check that the program is called and does the expected.
552 + */
553 + TEST_F(hid_bpf, test_hid_user_raw_request_call_eio)
554 + {
555 + struct hid_hw_request_syscall_args args = {
556 + .retval = -1,
557 + .type = HID_FEATURE_REPORT,
558 + .request_type = HID_REQ_GET_PROTOCOL,
559 + .size = MAX_BUF_SIZE,
560 + };
561 + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattrs,
562 + .ctx_in = &args,
563 + .ctx_size_in = sizeof(args),
564 + );
565 + int err, prog_fd;
566 +
567 + LOAD_BPF;
568 +
569 + args.hid = self->hid.hid_id;
570 + args.data[0] = 1; /* report ID */
571 +
572 + prog_fd = bpf_program__fd(self->skel->progs.hid_user_raw_request);
573 +
574 + err = bpf_prog_test_run_opts(prog_fd, &tattrs);
575 + ASSERT_OK(err) TH_LOG("error while calling bpf_prog_test_run_opts");
576 +
577 + ASSERT_EQ(args.retval, -EIO);
578 + }
579 +
549 580 /*
550 581 * Call hid_hw_raw_request against the given uhid device,
551 582 * check that the program is called and prevents the
modified tools/testing/selftests/kvm/Makefile.kvm
@@ -103,6 +103,7 @@ TEST_GEN_PROGS_x86 += x86/nested_tdp_fault_test
103 103 TEST_GEN_PROGS_x86 += x86/nested_tsc_adjust_test
104 104 TEST_GEN_PROGS_x86 += x86/nested_tsc_scaling_test
105 105 TEST_GEN_PROGS_x86 += x86/nested_vmsave_vmload_test
106 + TEST_GEN_PROGS_x86 += x86/nested_x2apic_test
106 107 TEST_GEN_PROGS_x86 += x86/platform_info_test
107 108 TEST_GEN_PROGS_x86 += x86/pmu_counters_test
108 109 TEST_GEN_PROGS_x86 += x86/pmu_event_filter_test
@@ -195,6 +196,7 @@ TEST_GEN_PROGS_arm64 += arm64/vgic_v5
195 196 TEST_GEN_PROGS_arm64 += arm64/vpmu_counter_access
196 197 TEST_GEN_PROGS_arm64 += arm64/no-vgic
197 198 TEST_GEN_PROGS_arm64 += arm64/idreg-idst
199 + TEST_GEN_PROGS_arm64 += arm64/hidden_features
198 200 TEST_GEN_PROGS_arm64 += arm64/kvm-uuid
199 201 TEST_GEN_PROGS_arm64 += access_tracking_perf_test
200 202 TEST_GEN_PROGS_arm64 += arch_timer
added tools/testing/selftests/kvm/arm64/hidden_features.c mode 100644
@@ -0,0 +1,184 @@
1 + // SPDX-License-Identifier: GPL-2.0-only
2 + /*
3 + * hidden_features - Check that a feature's instruction runs in the guest when
4 + * its ID register field is advertised, and is UNDEFINED when userspace clears
5 + * the field.
6 + *
7 + * Copyright (c) 2026 Google LLC
8 + * Author: Fuad Tabba <fuad.tabba@linux.dev>
9 + */
10 + #include "kvm_util.h"
11 + #include "processor.h"
12 + #include "test_util.h"
13 +
14 + static volatile bool undef;
15 +
16 + static void guest_tlbi_os(void)
17 + {
18 + /* tlbi vmalle1os */
19 + asm volatile("sys #0, c8, c1, #0\n\tdsb ish\n\tisb" ::: "memory");
20 + }
21 +
22 + static void guest_mops(void)
23 + {
24 + register u64 *d asm("x0");
25 + register u64 n asm("x1");
26 + register u64 s asm("x2");
27 + u64 buf[8];
28 +
29 + d = buf;
30 + n = sizeof(buf);
31 + s = 0;
32 + /* setp [x0]!, x1!, x2; setm; sete */
33 + asm volatile(".inst 0x19c20420\n\t.inst 0x19c24420\n\t.inst 0x19c28420"
34 + : "+r"(d), "+r"(n) : "r"(s) : "cc", "memory");
35 + }
36 +
37 + static void guest_tcr2(void)
38 + {
39 + read_sysreg_s(SYS_TCR2_EL1);
40 + }
41 +
42 + static void guest_fpmr(void)
43 + {
44 + read_sysreg_s(SYS_FPMR);
45 + }
46 +
47 + struct feature {
48 + const char *name;
49 + u64 id_reg;
50 + u64 mask;
51 + u8 shift;
52 + u64 min;
53 + void (*insn)(void);
54 + bool (*trappable)(struct kvm_vcpu *vcpu);
55 + };
56 +
57 + /* Without FGT, KVM traps a hidden TLBI OS only through HCR_EL2.TTLBOS (FEAT_EVT2). */
58 + static bool tlbi_os_trappable(struct kvm_vcpu *vcpu)
59 + {
60 + u64 mmfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR0_EL1));
61 + u64 mmfr2 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR2_EL1));
62 +
63 + return SYS_FIELD_GET(ID_AA64MMFR0_EL1, FGT, mmfr0) >= ID_AA64MMFR0_EL1_FGT_IMP ||
64 + SYS_FIELD_GET(ID_AA64MMFR2_EL1, EVT, mmfr2) >= ID_AA64MMFR2_EL1_EVT_TTLBxS;
65 + }
66 +
67 + #define FEATURE(n, reg, field, min_val, fn, trap) \
68 + { \
69 + .name = n, \
70 + .id_reg = SYS_##reg, \
71 + .mask = reg##_##field##_MASK, \
72 + .shift = reg##_##field##_SHIFT, \
73 + .min = reg##_##field##_##min_val, \
74 + .insn = fn, \
75 + .trappable = trap, \
76 + }
77 +
78 + static const struct feature features[] = {
79 + FEATURE("TLBI OS", ID_AA64ISAR0_EL1, TLB, OS, guest_tlbi_os, tlbi_os_trappable),
80 + FEATURE("MOPS", ID_AA64ISAR2_EL1, MOPS, IMP, guest_mops, NULL),
81 + FEATURE("TCR2_EL1", ID_AA64MMFR3_EL1, TCRX, IMP, guest_tcr2, NULL),
82 + FEATURE("FPMR", ID_AA64PFR2_EL1, FPMR, IMP, guest_fpmr, NULL),
83 + };
84 +
85 + static void guest_code(const struct feature *feat)
86 + {
87 + undef = false;
88 + feat->insn();
89 + GUEST_SYNC(undef);
90 + GUEST_DONE();
91 + }
92 +
93 + static void guest_undef_handler(struct ex_regs *regs)
94 + {
95 + undef = true;
96 + regs->pc += 4;
97 + }
98 +
99 + static bool run(const struct feature *feat, bool hide)
100 + {
101 + struct kvm_vcpu *vcpu;
102 + struct kvm_vm *vm;
103 + struct ucall uc;
104 + bool got = false;
105 + u64 val;
106 +
107 + vm = vm_create_with_one_vcpu(&vcpu, (void *)guest_code);
108 + vm_init_descriptor_tables(vm);
109 + vcpu_init_descriptor_tables(vcpu);
110 + vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_ELx_EC_UNKNOWN, guest_undef_handler);
111 + vcpu_args_set(vcpu, 1, feat);
112 +
113 + if (hide) {
114 + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(feat->id_reg));
115 + vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(feat->id_reg), val & ~feat->mask);
116 + }
117 +
118 + for (;;) {
119 + vcpu_run(vcpu);
120 + switch (get_ucall(vcpu, &uc)) {
121 + case UCALL_SYNC:
122 + got = uc.args[1];
123 + break;
124 + case UCALL_ABORT:
125 + REPORT_GUEST_ASSERT(uc);
126 + break;
127 + case UCALL_DONE:
128 + kvm_vm_free(vm);
129 + return got;
130 + default:
131 + TEST_FAIL("Unknown ucall %lu", uc.cmd);
132 + }
133 + }
134 + }
135 +
136 + static void probe_feature(const struct feature *feat, bool *present, bool *trappable)
137 + {
138 + struct kvm_vcpu *vcpu;
139 + struct kvm_vm *vm;
140 + u64 val;
141 +
142 + vm = vm_create_with_one_vcpu(&vcpu, NULL);
143 + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(feat->id_reg));
144 + *present = ((val & feat->mask) >> feat->shift) >= feat->min;
145 + *trappable = !feat->trappable || feat->trappable(vcpu);
146 + kvm_vm_free(vm);
147 + }
148 +
149 + int main(void)
150 + {
151 + const struct feature *feat;
152 + bool present, trappable;
153 + int i;
154 +
155 + test_disable_default_vgic();
156 +
157 + ksft_print_header();
158 + ksft_set_plan(ARRAY_SIZE(features) * 2);
159 +
160 + for (i = 0; i < ARRAY_SIZE(features); i++) {
161 + feat = &features[i];
162 +
163 + probe_feature(feat, &present, &trappable);
164 + if (!present) {
165 + ksft_test_result_skip("%s advertised, not supported\n", feat->name);
166 + ksft_test_result_skip("%s hidden, not supported\n", feat->name);
167 + continue;
168 + }
169 +
170 + if (run(feat, false))
171 + ksft_test_result_fail("%s advertised, UNDEF\n", feat->name);
172 + else
173 + ksft_test_result_pass("%s advertised\n", feat->name);
174 +
175 + if (!trappable)
176 + ksft_test_result_skip("%s hidden, not trappable\n", feat->name);
177 + else if (run(feat, true))
178 + ksft_test_result_pass("%s hidden\n", feat->name);
179 + else
180 + ksft_test_result_fail("%s hidden, no UNDEF\n", feat->name);
181 + }
182 +
183 + ksft_finished();
184 + }
added tools/testing/selftests/kvm/x86/nested_x2apic_test.c mode 100644
@@ -0,0 +1,222 @@
1 + // SPDX-License-Identifier: GPL-2.0-only
2 + #include "test_util.h"
3 + #include "kvm_util.h"
4 + #include "processor.h"
5 + #include "vmx.h"
6 + #include "svm_util.h"
7 +
8 + /*
9 + * Use the kernel's posted interrupt vectors to minimize the risk of crashing
10 + * the host if KVM is buggy. Note, the vectors aren't set in stone, ideally
11 + * these will be kept up-to-date if the kernel vectors change, but it's "fine"
12 + * if they are stale.
13 + */
14 + #define POSTED_INTR_VECTOR 0xf2
15 + #define POSTED_INTR_WAKEUP_VECTOR 0xf1
16 + #define POSTED_INTR_NESTED_VECTOR 0xf0
17 +
18 + static bool inhibit_apicv;
19 + static volatile unsigned int nr_irqs;
20 +
21 + static void guest_irq_handler(struct ex_regs *regs)
22 + {
23 + nr_irqs++;
24 + x2apic_write_reg(APIC_EOI, 0);
25 + }
26 +
27 + static void l2_guest_code(void)
28 + {
29 + if (inhibit_apicv)
30 + wrmsr(MSR_IA32_APICBASE, rdmsr(MSR_IA32_APICBASE) & GENMASK_ULL(11, 0));
31 +
32 + for (;;) {
33 + x2apic_write_reg(APIC_TASKPRI, 0xf0);
34 + GUEST_ASSERT_EQ(x2apic_read_reg(APIC_TASKPRI), 0xf0);
35 +
36 + asm volatile("cpuid" ::: "eax", "ebx", "ecx", "edx");
37 + }
38 + }
39 +
40 + static void l1_svm_code(struct svm_test_data *svm)
41 + {
42 + struct vmcb_control_area *ctrl = &svm->vmcb->control;
43 +
44 + generic_svm_setup(svm, l2_guest_code);
45 + ctrl->intercept |= BIT_ULL(INTERCEPT_CPUID) | BIT_ULL(INTERCEPT_MSR_PROT);
46 +
47 + run_guest(svm->vmcb, svm->vmcb_gpa);
48 + GUEST_ASSERT_EQ(ctrl->exit_code, SVM_EXIT_CPUID);
49 +
50 + stgi();
51 + x2apic_write_reg(APIC_TASKPRI, 0);
52 + }
53 +
54 + static void l1_vmx_code(struct vmx_pages *vmx, struct hyperv_test_pages *hv_pages)
55 + {
56 + u64 control;
57 +
58 + if (hv_pages) {
59 + wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_LINUX_OS_ID);
60 + enable_vp_assist(hv_pages->vp_assist_gpa, hv_pages->vp_assist);
61 + evmcs_enable();
62 + }
63 +
64 + GUEST_ASSERT_EQ(prepare_for_vmx_operation(vmx), true);
65 +
66 + if (hv_pages) {
67 + GUEST_ASSERT(load_evmcs(hv_pages));
68 + current_evmcs->hv_enlightenments_control.msr_bitmap = 1;
69 + } else {
70 + GUEST_ASSERT(load_vmcs(vmx));
71 + }
72 +
73 + prepare_vmcs(vmx, NULL);
74 + GUEST_ASSERT_EQ(vmwrite(GUEST_RIP, (unsigned long)l2_guest_code), 0);
75 +
76 + control = vmreadz(PIN_BASED_VM_EXEC_CONTROL);
77 + control |= PIN_BASED_EXT_INTR_MASK;
78 + vmwrite(PIN_BASED_VM_EXEC_CONTROL, control);
79 +
80 + control = vmreadz(CPU_BASED_VM_EXEC_CONTROL);
81 + control |= CPU_BASED_USE_MSR_BITMAPS | CPU_BASED_TPR_SHADOW;
82 + GUEST_ASSERT_EQ(vmwrite(CPU_BASED_VM_EXEC_CONTROL, control), 0);
83 +
84 + control = vmreadz(SECONDARY_VM_EXEC_CONTROL);
85 + control |= SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
86 + SECONDARY_EXEC_APIC_REGISTER_VIRT |
87 + SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY;
88 + control &= (rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32);
89 + GUEST_ASSERT_EQ(vmwrite(SECONDARY_VM_EXEC_CONTROL, control), 0);
90 +
91 + GUEST_ASSERT(!vmlaunch());
92 + GUEST_ASSERT_EQ(vmreadz(VM_EXIT_REASON), EXIT_REASON_CPUID);
93 + GUEST_ASSERT_EQ(vmwrite(GUEST_RIP,
94 + vmreadz(GUEST_RIP) + vmreadz(VM_EXIT_INSTRUCTION_LEN)), 0);
95 + }
96 +
97 + static void l1_vmx_code_part2(void)
98 + {
99 + u64 control;
100 +
101 + control = vmreadz(CPU_BASED_VM_EXEC_CONTROL);
102 + control &= ~CPU_BASED_TPR_SHADOW;
103 + GUEST_ASSERT_EQ(vmwrite(CPU_BASED_VM_EXEC_CONTROL, control), 0);
104 +
105 + control = vmreadz(SECONDARY_VM_EXEC_CONTROL);
106 + control &= ~(SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
107 + SECONDARY_EXEC_APIC_REGISTER_VIRT |
108 + SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY);
109 + GUEST_ASSERT_EQ(vmwrite(SECONDARY_VM_EXEC_CONTROL, control), 0);
110 +
111 + GUEST_ASSERT(!vmresume());
112 + GUEST_ASSERT_EQ(vmreadz(VM_EXIT_REASON), EXIT_REASON_CPUID);
113 + GUEST_ASSERT_EQ(vmwrite(GUEST_RIP,
114 + vmreadz(GUEST_RIP) + vmreadz(VM_EXIT_INSTRUCTION_LEN)), 0);
115 + }
116 +
117 + static void l1_test_x2apic_intercepts(void)
118 + {
119 + GUEST_ASSERT_EQ(nr_irqs, 0);
120 +
121 + sti_nop();
122 +
123 + GUEST_ASSERT_EQ(x2apic_read_reg(APIC_TASKPRI), 0xf0);
124 +
125 + x2apic_write_reg(APIC_ICR, APIC_DEST_SELF | APIC_INT_ASSERT | POSTED_INTR_VECTOR);
126 + GUEST_ASSERT_EQ(nr_irqs, 0);
127 +
128 + x2apic_write_reg(APIC_TASKPRI, 0xff);
129 + GUEST_ASSERT_EQ(x2apic_read_reg(APIC_TASKPRI), 0xff);
130 + x2apic_write_reg(APIC_ICR, APIC_DEST_SELF | APIC_INT_ASSERT | POSTED_INTR_WAKEUP_VECTOR);
131 + GUEST_ASSERT_EQ(nr_irqs, 0);
132 +
133 + x2apic_write_reg(APIC_TASKPRI, 0);
134 + GUEST_ASSERT_EQ(x2apic_read_reg(APIC_TASKPRI), 0);
135 +
136 + x2apic_write_reg(APIC_ICR, APIC_DEST_SELF | APIC_INT_ASSERT | POSTED_INTR_NESTED_VECTOR);
137 + GUEST_ASSERT_EQ(nr_irqs, 3);
138 +
139 + nr_irqs = 0;
140 + }
141 +
142 + static void l1_guest_code(void *test_data, void *hv_pages)
143 + {
144 + x2apic_enable();
145 +
146 + if (this_cpu_has(X86_FEATURE_SVM))
147 + l1_svm_code(test_data);
148 + else
149 + l1_vmx_code(test_data, hv_pages);
150 +
151 + GUEST_ASSERT_EQ(x2apic_read_reg(APIC_TASKPRI), 0);
152 + x2apic_write_reg(APIC_TASKPRI, 0xf0);
153 +
154 + l1_test_x2apic_intercepts();
155 +
156 + if (this_cpu_has(X86_FEATURE_VMX)) {
157 + l1_vmx_code_part2();
158 + l1_test_x2apic_intercepts();
159 + }
160 +
161 + GUEST_DONE();
162 + }
163 +
164 + static void test_x2apic_intercepts(bool with_inhibit_apicv, bool use_evmcs)
165 + {
166 + gva_t nested_test_data_gva, hv_pages_gva = 0;
167 + struct kvm_vcpu *vcpu;
168 + struct kvm_vm *vm;
169 + struct ucall uc;
170 +
171 + inhibit_apicv = with_inhibit_apicv;
172 +
173 + vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
174 + vm_install_exception_handler(vm, POSTED_INTR_VECTOR, guest_irq_handler);
175 + vm_install_exception_handler(vm, POSTED_INTR_WAKEUP_VECTOR, guest_irq_handler);
176 + vm_install_exception_handler(vm, POSTED_INTR_NESTED_VECTOR, guest_irq_handler);
177 +
178 + sync_global_to_guest(vm, inhibit_apicv);
179 +
180 + if (kvm_cpu_has(X86_FEATURE_SVM))
181 + vcpu_alloc_svm(vm, &nested_test_data_gva);
182 + else
183 + vcpu_alloc_vmx(vm, &nested_test_data_gva);
184 +
185 + if (use_evmcs) {
186 + vcpu_set_hv_cpuid(vcpu);
187 + vcpu_enable_evmcs(vcpu);
188 +
189 + vcpu_alloc_hyperv_test_pages(vm, &hv_pages_gva);
190 + }
191 +
192 + vcpu_args_set(vcpu, 2, nested_test_data_gva, hv_pages_gva);
193 +
194 + vcpu_run(vcpu);
195 +
196 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
197 +
198 + switch (get_ucall(vcpu, &uc)) {
199 + case UCALL_DONE:
200 + break;
201 + case UCALL_ABORT:
202 + REPORT_GUEST_ASSERT(uc);
203 + break;
204 + default:
205 + TEST_FAIL("Expected DONE, got unexpected ucall %lu", uc.cmd);
206 + }
207 +
208 + kvm_vm_free(vm);
209 + }
210 +
211 + int main(int argc, char *argv[])
212 + {
213 + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM) || kvm_cpu_has(X86_FEATURE_VMX));
214 +
215 + test_x2apic_intercepts(true, false);
216 + test_x2apic_intercepts(false, false);
217 +
218 + if (kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) {
219 + test_x2apic_intercepts(true, true);
220 + test_x2apic_intercepts(false, true);
221 + }
222 + }
modified tools/testing/selftests/net/.gitignore
@@ -55,6 +55,7 @@ tools
55 55 tun
56 56 txring_overwrite
57 57 txtimestamp
58 + udp_splice_checksum
58 59 udpgso
59 60 udpgso_bench_rx
60 61 udpgso_bench_tx
modified tools/testing/selftests/net/Makefile
@@ -199,6 +199,7 @@ TEST_GEN_PROGS := \
199 199 tap \
200 200 tcp_port_share \
201 201 tls \
202 + udp_splice_checksum \
202 203 # end of TEST_GEN_PROGS
203 204
204 205 TEST_FILES := \
added tools/testing/selftests/net/packetdrill/tcp_old_ack_ts.pkt mode 100644
@@ -0,0 +1,22 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + // An out-of-order segment advances SND.UNA. The gap filler still carries
3 + // its original, older ACK. The reply must echo the gap filler's timestamp.
4 + --tcp_ts_tick_usecs=1000
5 +
6 + `./defaults.sh`
7 +
8 + 0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
9 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
10 + +0 bind(3, ..., ...) = 0
11 + +0 listen(3, 1) = 0
12 + 0.100 < S 0:0(0) win 20000 <mss 1000,sackOK,TS val 900 ecr 0>
13 + +0 > S. 0:0(0) ack 1 <mss 1460,sackOK,TS val 100 ecr 900>
14 + 0.200 < . 1:1(0) ack 1 win 20000 <nop,nop,TS val 1000 ecr 100>
15 + +0 accept(3, ..., ...) = 4
16 + 0.300 write(4, ..., 17) = 17
17 + +0 > P. 1:18(17) ack 1 <nop,nop,TS val 300 ecr 1000>
18 + 0.310 < P. 18:35(17) ack 18 win 20000 <nop,nop,TS val 301001 ecr 300>
19 + +0 > . 18:18(0) ack 1 <nop,nop,TS val 310 ecr 1000,nop,nop,sack 18:35>
20 + 0.320 < P. 1:18(17) ack 1 win 20000 <nop,nop,TS val 301000 ecr 100>
21 + +0 > . 18:18(0) ack 35 <nop,nop,TS val 320 ecr 301000>
22 + +0 read(4, ..., 34) = 34
added tools/testing/selftests/net/udp_splice_checksum.c mode 100644
@@ -0,0 +1,378 @@
1 + // SPDX-License-Identifier: GPL-2.0-only
2 + /*
3 + * Exercise UDP software checksums over multiple spliced pipe fragments.
4 + * All traffic stays on loopback; no privileges or external services are needed.
5 + * Exit status: 0 = pass, 1 = failure, 4 = all cases skipped.
6 + */
7 + #define _GNU_SOURCE
8 +
9 + #include <arpa/inet.h>
10 + #include <errno.h>
11 + #include <fcntl.h>
12 + #include <poll.h>
13 + #include <stdbool.h>
14 + #include <stdio.h>
15 + #include <stdlib.h>
16 + #include <string.h>
17 + #include <sys/socket.h>
18 + #include <time.h>
19 + #include <unistd.h>
20 +
21 + #include "kselftest.h"
22 +
23 + #define TIMEOUT_MS 200
24 +
25 + struct test_case {
26 + const char *name;
27 + const char *body;
28 + const char *prefix;
29 + size_t fragments[3];
30 + bool ordinary;
31 + bool page_tail;
32 + };
33 +
34 + static const struct test_case cases[] = {
35 + { "ordinary-control", "abcDEFGH", "", { 3, 5 }, true, false },
36 + { "uniform-odd-fragments", "BBBBBBBB", "", { 3, 5 }, false, false },
37 + { "even-fragments", "abcdEFGH", "", { 4, 4 }, false, false },
38 + { "odd-fragments", "abcDEFGH", "", { 3, 5 }, false, false },
39 + { "odd-prefix-odd-fragments", "abcDEFGH", "P", { 3, 5 }, false, false },
40 + { "even-prefix-odd-fragments", "abcDEFGH", "PQ", { 3, 5 }, false, false },
41 + { "page-tail-odd-fragments", "abcDEFGH", "", { 3, 5 }, false, true },
42 + { "three-fragments", "abcDEFGhijkl", "", { 3, 4, 5 }, false, false },
43 + { "odd-prefix-three-fragments",
44 + "abcDEFGhijkl",
45 + "P",
46 + { 3, 4, 5 },
47 + false,
48 + false },
49 + };
50 +
51 + static const char *const families[] = { "IPv4", "IPv6", "IPv4-mapped" };
52 +
53 + static int error(const char *what)
54 + {
55 + ksft_perror(what);
56 + return 1;
57 + }
58 +
59 + static bool unavailable(void)
60 + {
61 + return errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT ||
62 + errno == EADDRNOTAVAIL;
63 + }
64 +
65 + static long long now_ms(void)
66 + {
67 + struct timespec ts;
68 +
69 + if (clock_gettime(CLOCK_MONOTONIC, &ts))
70 + ksft_exit_fail_perror("clock_gettime");
71 + return (long long)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
72 + }
73 +
74 + static int receive_one(int fd, const char *expected, size_t length)
75 + {
76 + struct pollfd pfd = { .fd = fd, .events = POLLIN };
77 + long long deadline = now_ms() + TIMEOUT_MS;
78 + int remaining, ret;
79 + char received[64];
80 + ssize_t count;
81 +
82 + for (;;) {
83 + remaining = deadline - now_ms();
84 + if (remaining < 0)
85 + remaining = 0;
86 + ret = poll(&pfd, 1, remaining);
87 + if (ret < 0) {
88 + if (errno == EINTR)
89 + continue;
90 + return error("poll");
91 + }
92 + if (!ret) {
93 + ksft_print_msg("no datagram within %d ms after send\n",
94 + TIMEOUT_MS);
95 + return 1;
96 + }
97 + count = recv(fd, received, sizeof(received),
98 + MSG_DONTWAIT | MSG_TRUNC);
99 + if (count < 0) {
100 + if (errno == EINTR || errno == EAGAIN)
101 + continue;
102 + return error("recv");
103 + }
104 + break;
105 + }
106 + if (count != (ssize_t)length || memcmp(received, expected, length)) {
107 + ksft_print_msg("received %zd bytes; expected %zu matching\n",
108 + count, length);
109 + return 1;
110 + }
111 + count = recv(fd, received, sizeof(received), MSG_DONTWAIT | MSG_TRUNC);
112 + if (count >= 0) {
113 + ksft_print_msg("unexpected extra datagram (%zd bytes)\n",
114 + count);
115 + return 1;
116 + }
117 + if (errno != EAGAIN)
118 + return error("extra-datagram check");
119 + return 0;
120 + }
121 +
122 + /* Separate source pipes prevent adjacent small writes merging into one buffer. */
123 + static int append_fragment(int dest, const char *data, size_t length)
124 + {
125 + int source[2], ret = 1;
126 +
127 + if (pipe2(source, O_NONBLOCK | O_CLOEXEC))
128 + return error("source pipe");
129 + if (write(source[1], data, length) != (ssize_t)length) {
130 + error("source write");
131 + goto out;
132 + }
133 + if (splice(source[0], NULL, dest, NULL, length, SPLICE_F_NONBLOCK) !=
134 + (ssize_t)length) {
135 + error("pipe-to-pipe splice");
136 + goto out;
137 + }
138 + ret = 0;
139 + out:
140 + close(source[0]);
141 + close(source[1]);
142 + return ret;
143 + }
144 +
145 + static int pipe_capacity(int fd, unsigned int slots, const char **skip_reason)
146 + {
147 + long required = slots * sysconf(_SC_PAGESIZE);
148 + int capacity = fcntl(fd, F_GETPIPE_SZ);
149 +
150 + if (capacity < 0)
151 + return error("query pipe capacity");
152 + if (capacity >= required ||
153 + fcntl(fd, F_SETPIPE_SZ, required) >= required)
154 + return 0;
155 + ksft_print_msg("cannot reserve %u pipe slots: %s\n", slots,
156 + strerror(errno));
157 + *skip_reason = "required pipe capacity unavailable";
158 + return KSFT_SKIP;
159 + }
160 +
161 + /* Leave three bytes at a page's end, followed by five bytes on the next page. */
162 + static int append_page_tail(int dest, const char *body,
163 + const char **skip_reason)
164 + {
165 + long page = sysconf(_SC_PAGESIZE);
166 + int source[2], ret = 1;
167 + char *data;
168 +
169 + if (page < 8) {
170 + ksft_print_msg("invalid page size %ld\n", page);
171 + return 1;
172 + }
173 + data = malloc(page + 5);
174 + if (!data)
175 + return error("malloc");
176 + memset(data, 'x', page - 3);
177 + memcpy(data + page - 3, body, 8);
178 + if (pipe2(source, O_NONBLOCK | O_CLOEXEC)) {
179 + error("page-tail source pipe");
180 + goto free_data;
181 + }
182 + ret = pipe_capacity(source[1], 2, skip_reason);
183 + if (ret)
184 + goto out;
185 + ret = 1;
186 + if (write(source[1], data, page + 5) != page + 5) {
187 + error("page-tail write");
188 + goto out;
189 + }
190 + if (read(source[0], data, page - 3) != page - 3) {
191 + error("page-tail discard");
192 + goto out;
193 + }
194 + if (splice(source[0], NULL, dest, NULL, 8, SPLICE_F_NONBLOCK) != 8) {
195 + error("page-tail pipe-to-pipe splice");
196 + goto out;
197 + }
198 + ret = 0;
199 + out:
200 + close(source[0]);
201 + close(source[1]);
202 + free_data:
203 + free(data);
204 + return ret;
205 + }
206 +
207 + static int run_case(unsigned int family, bool connected,
208 + const struct test_case *test, const char **skip_reason)
209 + {
210 + size_t body_length = strlen(test->body), offset = 0;
211 + int tx_family = family == 0 ? AF_INET : AF_INET6;
212 + int rx_family = family == 1 ? AF_INET6 : AF_INET;
213 + int rx = -1, tx = -1, pipefd[2] = { -1, -1 };
214 + size_t prefix_length = strlen(test->prefix);
215 + struct sockaddr_storage address = { 0 };
216 + socklen_t address_length;
217 + struct sockaddr_in6 *v6;
218 + struct sockaddr_in *v4;
219 + int ret = 1, zero = 0;
220 + char expected[64];
221 + unsigned int i;
222 + ssize_t count;
223 +
224 + v4 = (struct sockaddr_in *)&address;
225 + v6 = (struct sockaddr_in6 *)&address;
226 + *skip_reason = "address family unavailable";
227 + memcpy(expected, test->prefix, prefix_length);
228 + memcpy(expected + prefix_length, test->body, body_length);
229 + rx = socket(rx_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
230 + if (rx < 0) {
231 + ret = unavailable() ? KSFT_SKIP : error("receive socket");
232 + goto out;
233 + }
234 + if (rx_family == AF_INET) {
235 + v4->sin_family = AF_INET;
236 + v4->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
237 + address_length = sizeof(*v4);
238 + } else {
239 + v6->sin6_family = AF_INET6;
240 + v6->sin6_addr = in6addr_loopback;
241 + address_length = sizeof(*v6);
242 + }
243 + if (bind(rx, (struct sockaddr *)&address, address_length)) {
244 + ret = unavailable() ? KSFT_SKIP : error("bind loopback");
245 + goto out;
246 + }
247 + if (getsockname(rx, (struct sockaddr *)&address, &address_length)) {
248 + error("getsockname");
249 + goto out;
250 + }
251 + if (family == 2) {
252 + unsigned short port = v4->sin_port;
253 +
254 + memset(&address, 0, sizeof(address));
255 + v6->sin6_family = AF_INET6;
256 + v6->sin6_port = port;
257 + inet_pton(AF_INET6, "::ffff:127.0.0.1", &v6->sin6_addr);
258 + address_length = sizeof(*v6);
259 + }
260 + tx = socket(tx_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
261 + if (tx < 0) {
262 + ret = unavailable() ? KSFT_SKIP : error("send socket");
263 + goto out;
264 + }
265 + if (family == 2 &&
266 + setsockopt(tx, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero))) {
267 + error("disable IPV6_V6ONLY");
268 + goto out;
269 + }
270 + if (connected &&
271 + connect(tx, (struct sockaddr *)&address, address_length)) {
272 + error("connect");
273 + goto out;
274 + }
275 + if (test->ordinary) {
276 + count = sendto(tx, expected, prefix_length + body_length, 0,
277 + (struct sockaddr *)&address, address_length);
278 + if (count != (ssize_t)(prefix_length + body_length)) {
279 + error("ordinary sendto");
280 + goto out;
281 + }
282 + } else {
283 + if (pipe2(pipefd, O_NONBLOCK | O_CLOEXEC)) {
284 + error("assembled pipe");
285 + goto out;
286 + }
287 + ret = pipe_capacity(pipefd[1], test->fragments[2] ? 3 : 2,
288 + skip_reason);
289 + if (ret)
290 + goto out;
291 + ret = 1;
292 + if (test->page_tail) {
293 + ret = append_page_tail(pipefd[1], test->body,
294 + skip_reason);
295 + if (ret)
296 + goto out;
297 + ret = 1;
298 + } else {
299 + for (i = 0; i < ARRAY_SIZE(test->fragments); i++) {
300 + if (!test->fragments[i])
301 + break;
302 + if (append_fragment(pipefd[1],
303 + test->body + offset,
304 + test->fragments[i]))
305 + goto out;
306 + offset += test->fragments[i];
307 + }
308 + }
309 + /* Even an empty prefix establishes the destination and UDP cork. */
310 + count = sendto(tx, test->prefix, prefix_length, MSG_MORE,
311 + (struct sockaddr *)&address, address_length);
312 + if (count != (ssize_t)prefix_length) {
313 + error("prime sendto(MSG_MORE)");
314 + goto out;
315 + }
316 + count = splice(pipefd[0], NULL, tx, NULL, body_length,
317 + SPLICE_F_NONBLOCK | SPLICE_F_MORE);
318 + if (count != (ssize_t)body_length) {
319 + ksft_print_msg("socket splice: %zd, expected %zu: %s\n",
320 + count, body_length,
321 + count < 0 ? strerror(errno) :
322 + "short transfer");
323 + goto out;
324 + }
325 + if (sendto(tx, "", 0, 0, (struct sockaddr *)&address,
326 + address_length)) {
327 + error("commit sendto");
328 + goto out;
329 + }
330 + }
331 + ret = receive_one(rx, expected, prefix_length + body_length);
332 + out:
333 + if (pipefd[0] >= 0) {
334 + close(pipefd[0]);
335 + close(pipefd[1]);
336 + }
337 + if (tx >= 0)
338 + close(tx);
339 + if (rx >= 0)
340 + close(rx);
341 + return ret;
342 + }
343 +
344 + int main(void)
345 + {
346 + unsigned int family, connected, i;
347 + const char *connection, *skip;
348 + int ret;
349 +
350 + ksft_print_header();
351 + ksft_set_plan(ARRAY_SIZE(families) * 2 * ARRAY_SIZE(cases));
352 + for (family = 0; family < ARRAY_SIZE(families); family++) {
353 + for (connected = 0; connected < 2; connected++) {
354 + connection = connected ? "connected" : "unconnected";
355 + for (i = 0; i < ARRAY_SIZE(cases); i++) {
356 + ret = run_case(family, connected, &cases[i],
357 + &skip);
358 + if (ret == KSFT_SKIP)
359 + ksft_test_result_skip("%s %s %s: %s\n",
360 + families[family],
361 + connection,
362 + cases[i].name,
363 + skip);
364 + else
365 + ksft_test_result(!ret, "%s %s %s\n",
366 + families[family],
367 + connection,
368 + cases[i].name);
369 + }
370 + }
371 + }
372 + if (!ksft_get_pass_cnt() && !ksft_get_fail_cnt()) {
373 + /* ksft_exit_skip() would add a result beyond the plan. */
374 + ksft_print_cnts();
375 + return KSFT_SKIP;
376 + }
377 + ksft_finished();
378 + }
modified tools/testing/selftests/ublk/kublk.c
@@ -1589,7 +1589,7 @@ fail_start:
1589 1589
1590 1590 /* Signal listener thread to stop and wait for it */
1591 1591 if (linfo.stop_efd >= 0) {
1592 - write(linfo.stop_efd, &stop_val, sizeof(stop_val));
1592 + (void)!write(linfo.stop_efd, &stop_val, sizeof(stop_val));
1593 1593 pthread_join(listener, NULL);
1594 1594 close(linfo.stop_efd);
1595 1595 ublk_shmem_sock_destroy(dinfo->dev_id, linfo.sock_fd);
modified virt/kvm/kvm_main.c
@@ -1363,6 +1363,9 @@ int kvm_trylock_all_vcpus(struct kvm *kvm)
1363 1363
1364 1364 lockdep_assert_held(&kvm->lock);
1365 1365
1366 + if (WARN_ON_ONCE(kvm_is_vcpu_creation_in_progress(kvm)))
1367 + return -EBUSY;
1368 +
1366 1369 kvm_for_each_vcpu(i, vcpu, kvm)
1367 1370 if (!mutex_trylock_nest_lock(&vcpu->mutex, &kvm->lock))
1368 1371 goto out_unlock;
@@ -1386,6 +1389,9 @@ int kvm_lock_all_vcpus(struct kvm *kvm)
1386 1389
1387 1390 lockdep_assert_held(&kvm->lock);
1388 1391
1392 + if (WARN_ON_ONCE(kvm_is_vcpu_creation_in_progress(kvm)))
1393 + return -EBUSY;
1394 +
1389 1395 kvm_for_each_vcpu(i, vcpu, kvm) {
1390 1396 r = mutex_lock_killable_nest_lock(&vcpu->mutex, &kvm->lock);
1391 1397 if (r)
@@ -4182,6 +4188,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
4182 4188 struct kvm_vcpu *vcpu;
4183 4189 struct page *page;
4184 4190
4191 + guard(mutex)(&kvm->lock);
4192 +
4185 4193 /*
4186 4194 * KVM tracks vCPU IDs as 'int', be kind to userspace and reject
4187 4195 * too-large values instead of silently truncating.
@@ -4194,26 +4202,17 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
4194 4202 if (id >= KVM_MAX_VCPU_IDS)
4195 4203 return -EINVAL;
4196 4204
4197 - mutex_lock(&kvm->lock);
4198 - if (kvm->created_vcpus >= kvm->max_vcpus) {
4199 - mutex_unlock(&kvm->lock);
4205 + if (kvm->created_vcpus >= kvm->max_vcpus)
4200 4206 return -EINVAL;
4201 - }
4202 4207
4203 - if (test_bit(id, kvm->vcpu_ids)) {
4204 - mutex_unlock(&kvm->lock);
4208 + if (kvm_get_vcpu_by_id(kvm, id))
4205 4209 return -EEXIST;
4206 - }
4207 4210
4208 4211 r = kvm_arch_vcpu_precreate(kvm, id);
4209 - if (r) {
4210 - mutex_unlock(&kvm->lock);
4212 + if (r)
4211 4213 return r;
4212 - }
4213 4214
4214 4215 kvm->created_vcpus++;
4215 - __set_bit(id, kvm->vcpu_ids);
4216 - mutex_unlock(&kvm->lock);
4217 4216
4218 4217 vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL_ACCOUNT);
4219 4218 if (!vcpu) {
@@ -4244,13 +4243,6 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
4244 4243 goto arch_vcpu_destroy;
4245 4244 }
4246 4245
4247 - mutex_lock(&kvm->lock);
4248 -
4249 - if (WARN_ON_ONCE(kvm_get_vcpu_by_id(kvm, id))) {
4250 - r = -EEXIST;
4251 - goto unlock_vcpu_destroy;
4252 - }
4253 -
4254 4246 /*
4255 4247 * Set the vCPU's index *before* the vCPU is reachable by other tasks.
4256 4248 * Unwind the index back to -1 on failure so that KVM can use the index
@@ -4284,7 +4276,6 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
4284 4276 atomic_inc(&kvm->online_vcpus);
4285 4277 mutex_unlock(&vcpu->mutex);
4286 4278
4287 - mutex_unlock(&kvm->lock);
4288 4279 kvm_arch_vcpu_postcreate(vcpu);
4289 4280 kvm_create_vcpu_debugfs(vcpu);
4290 4281 return r;
@@ -4295,7 +4286,6 @@ kvm_put_xa_erase:
4295 4286 xa_erase(&kvm->vcpu_array, vcpu->vcpu_idx);
4296 4287 unlock_vcpu_destroy:
4297 4288 vcpu->vcpu_idx = -1;
4298 - mutex_unlock(&kvm->lock);
4299 4289 kvm_dirty_ring_free(&vcpu->dirty_ring);
4300 4290 arch_vcpu_destroy:
4301 4291 kvm_arch_vcpu_destroy(vcpu);
@@ -4304,10 +4294,7 @@ vcpu_free_run_page:
4304 4294 vcpu_free:
4305 4295 kmem_cache_free(kvm_vcpu_cache, vcpu);
4306 4296 vcpu_decrement:
4307 - mutex_lock(&kvm->lock);
4308 4297 kvm->created_vcpus--;
4309 - __clear_bit(id, kvm->vcpu_ids);
4310 - mutex_unlock(&kvm->lock);
4311 4298 return r;
4312 4299 }
4313 4300