Compare

afb1ecfeda3fc31d6300a176f4854cc62e289bf3..68ab4a6a84b92f52650508acb60317eb76454250

pinctrl: qcom: nord: fix GPIO interrupt target width

The TARGET_PROC field in the Nord GPIO_INTR_CFG registers occupies bits
11:8. Describe it as four bits wide so the common Qualcomm pinctrl code
clears the complete field before routing an interrupt to the application
processor.

Without intr_target_width, the common code uses its three-bit default
mask. Since GPIO_INTR_CFG resets with TARGET_PROC set to 0xf (NONE), bit
11 remains set when the driver programs HMSS target 3. The resulting
target is 0xb (HPASS_DSP_1), observed as an interrupt configuration value
of 0xb1b instead of 0x31b.

The GPIO interrupt status is consequently latched, but the HMSS TLMM
summary interrupt at GIC SPI 208 is never asserted. This affects all Nord
GPIO interrupts using the TLMM summary path, including the Ethernet PHY
interrupts on GPIO55 and GPIO141.

Fixes: c24dd0826f06 ("pinctrl: qcom: add the TLMM driver for the Nord platforms")
Signed-off-by: Zhangfei Gao <zhangfei.gao@oss.qualcomm.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Reviewed-by: Shawn Guo <shengchao.guo@oss.qualcomm.com>
Link: https://patch.msgid.link/20260916085720.771498-1-zhangfei.gao@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Zhangfei Gao <zhangfei.gao@oss.qualcomm.com> · 2026-09-16 08:57 UTC · committed by Bartosz Golaszewski

Browse files
744 files changed, +7198 −3929
modified .mailmap
@@ -19,7 +19,8 @@ Abhinav Kumar <quic_abhinavk@quicinc.com> <abhinavk@codeaurora.org>
19 19 Ahmad Masri <quic_amasri@quicinc.com> <amasri@codeaurora.org>
20 20 Adam Oldham <oldhamca@gmail.com>
21 21 Adam Radford <aradford@gmail.com>
22 - Aditya Garg <gargaditya08@proton.me> <gargaditya08@live.com>
22 + Aditya Garg <aditya.garg@linux.dev> <gargaditya08@live.com>
23 + Aditya Garg <aditya.garg@linux.dev> <gargaditya08@proton.me>
23 24 Adriana Reus <adi.reus@gmail.com> <adriana.reus@intel.com>
24 25 Adrian Bunk <bunk@stusta.de>
25 26 Ajay Kaher <ajay.kaher@broadcom.com> <akaher@vmware.com>
@@ -699,6 +700,7 @@ Oliver Hartkopp <socketcan@hartkopp.net> <oliver.hartkopp@volkswagen.de>
699 700 Oliver Hartkopp <socketcan@hartkopp.net> <oliver@hartkopp.net>
700 701 Oliver Upton <oupton@kernel.org> <oupton@google.com>
701 702 Oliver Upton <oupton@kernel.org> <oliver.upton@linux.dev>
703 + Ondrej Mosnáček <omosnacek@gmail.com> <omosnace@redhat.com>
702 704 Ondřej Jirman <megi@xff.cz> <megous@megous.com>
703 705 Oza Pawandeep <quic_poza@quicinc.com> <poza@codeaurora.org>
704 706 Pali Rohár <pali@kernel.org> <pali.rohar@gmail.com>
@@ -898,7 +900,8 @@ Thomas Graf <tgraf@suug.ch>
898 900 Thomas Gleixner <tglx@kernel.org> <tglx@linutronix.de>
899 901 Thomas Körper <socketcan@esd.eu> <thomas.koerper@esd.eu>
900 902 Thomas Pedersen <twp@codeaurora.org>
901 - Thorsten Blum <thorsten.blum@linux.dev> <thorsten.blum@toblux.com>
903 + Thorsten Blum <blum@kernel.org> <thorsten.blum@toblux.com>
904 + Thorsten Blum <blum@kernel.org> <thorsten.blum@linux.dev>
902 905 Tiezhu Yang <yangtiezhu@loongson.cn> <kernelpatch@126.com>
903 906 Tingwei Zhang <quic_tingwei@quicinc.com> <tingwei@codeaurora.org>
904 907 Tirupathi Reddy <quic_tirupath@quicinc.com> <tirupath@codeaurora.org>
modified CREDITS
@@ -1512,6 +1512,10 @@ N: Andy Gross
1512 1512 E: agross@kernel.org
1513 1513 D: Qualcomm SoC subsystem and drivers
1514 1514
1515 + N: Mark Gross
1516 + E: markgross@kernel.org
1517 + D: x86/mellanox platform maintenance and various x86 specific drivers
1518 +
1515 1519 N: Grant Grundler
1516 1520 E: grantgrundler@gmail.com
1517 1521 W: http://obmouse.sourceforge.net/
@@ -4305,6 +4309,10 @@ N: Juergen Weigert
4305 4309 E: jnweiger@immd4.informatik.uni-erlangen.de
4306 4310 D: The Linux Support Team Erlangen
4307 4311
4312 + N: Russ Weight
4313 + E: russ.weight@gmail.com
4314 + D: Added support for Firmware Upload to the Firmware Loader
4315 +
4308 4316 N: David Weinehall
4309 4317 E: tao@acc.umu.se
4310 4318 P: 1024D/DC47CA16 7ACE 0FB0 7A74 F994 9B36 E1D1 D14E 8526 DC47 CA16
modified Documentation/ABI/testing/ima_policy
@@ -108,6 +108,9 @@ Description:
108 108 # NSFS_MAGIC
109 109 dont_measure fsmagic=0x6e736673
110 110 dont_appraise fsmagic=0x6e736673
111 + # CONFIGFS_MAGIC
112 + dont_measure fsmagic=0x62656570
113 + dont_appraise fsmagic=0x62656570
111 114
112 115 measure func=BPRM_CHECK
113 116 measure func=FILE_MMAP mask=MAY_EXEC
modified Documentation/ABI/testing/sysfs-class-firmware
@@ -1,7 +1,7 @@
1 1 What: /sys/class/firmware/.../data
2 2 Date: July 2022
3 3 KernelVersion: 5.19
4 - Contact: Russ Weight <russ.weight@linux.dev>
4 + Contact: driver-core@lists.linux.dev
5 5 Description: The data sysfs file is used for firmware-fallback and for
6 6 firmware uploads. Cat a firmware image to this sysfs file
7 7 after you echo 1 to the loading sysfs file. When the firmware
@@ -13,7 +13,7 @@ Description: The data sysfs file is used for firmware-fallback and for
13 13 What: /sys/class/firmware/.../cancel
14 14 Date: July 2022
15 15 KernelVersion: 5.19
16 - Contact: Russ Weight <russ.weight@linux.dev>
16 + Contact: driver-core@lists.linux.dev
17 17 Description: Write-only. For firmware uploads, write a "1" to this file to
18 18 request that the transfer of firmware data to the lower-level
19 19 device be canceled. This request will be rejected (EBUSY) if
@@ -23,7 +23,7 @@ Description: Write-only. For firmware uploads, write a "1" to this file to
23 23 What: /sys/class/firmware/.../error
24 24 Date: July 2022
25 25 KernelVersion: 5.19
26 - Contact: Russ Weight <russ.weight@linux.dev>
26 + Contact: driver-core@lists.linux.dev
27 27 Description: Read-only. Returns a string describing a failed firmware
28 28 upload. This string will be in the form of <STATUS>:<ERROR>,
29 29 where <STATUS> will be one of the status strings described
@@ -37,7 +37,7 @@ Description: Read-only. Returns a string describing a failed firmware
37 37 What: /sys/class/firmware/.../loading
38 38 Date: July 2022
39 39 KernelVersion: 5.19
40 - Contact: Russ Weight <russ.weight@linux.dev>
40 + Contact: driver-core@lists.linux.dev
41 41 Description: The loading sysfs file is used for both firmware-fallback and
42 42 for firmware uploads. Echo 1 onto the loading file to indicate
43 43 you are writing a firmware file to the data sysfs node. Echo
@@ -49,7 +49,7 @@ Description: The loading sysfs file is used for both firmware-fallback and
49 49 What: /sys/class/firmware/.../remaining_size
50 50 Date: July 2022
51 51 KernelVersion: 5.19
52 - Contact: Russ Weight <russ.weight@linux.dev>
52 + Contact: driver-core@lists.linux.dev
53 53 Description: Read-only. For firmware upload, this file contains the size
54 54 of the firmware data that remains to be transferred to the
55 55 lower-level device driver. The size value is initialized to
@@ -62,7 +62,7 @@ Description: Read-only. For firmware upload, this file contains the size
62 62 What: /sys/class/firmware/.../status
63 63 Date: July 2022
64 64 KernelVersion: 5.19
65 - Contact: Russ Weight <russ.weight@linux.dev>
65 + Contact: driver-core@lists.linux.dev
66 66 Description: Read-only. Returns a string describing the current status of
67 67 a firmware upload. The string will be one of the following:
68 68 idle, "receiving", "preparing", "transferring", "programming".
@@ -70,7 +70,7 @@ Description: Read-only. Returns a string describing the current status of
70 70 What: /sys/class/firmware/.../timeout
71 71 Date: July 2022
72 72 KernelVersion: 5.19
73 - Contact: Russ Weight <russ.weight@linux.dev>
73 + Contact: driver-core@lists.linux.dev
74 74 Description: This file supports the timeout mechanism for firmware
75 75 fallback. This file has no affect on firmware uploads. For
76 76 more information on timeouts please see the documentation
modified Documentation/admin-guide/cgroup-v1/memory.rst
@@ -47,7 +47,6 @@ Features:
47 47 - pages are linked to per-memcg LRU exclusively, and there is no global LRU.
48 48 - optionally, memory+swap usage can be accounted and limited.
49 49 - hierarchical accounting
50 - - soft limit
51 50 - moving (recharging) account at moving a task is selectable.
52 51 - usage threshold notifier
53 52 - memory pressure notifier
@@ -76,10 +75,9 @@ Brief summary of control files.
76 75 memory.memsw.failcnt show the number of memory+Swap hits limits
77 76 memory.max_usage_in_bytes show max memory usage recorded
78 77 memory.memsw.max_usage_in_bytes show max memory+Swap usage recorded
79 - memory.soft_limit_in_bytes set/show soft limit of memory usage
80 - This knob is not available on CONFIG_PREEMPT_RT systems.
81 - This knob is deprecated and shouldn't be
82 - used.
78 + memory.soft_limit_in_bytes This knob is deprecated and has no effect.
79 + Writes are ignored and reads always
80 + return the maximum value.
83 81 memory.stat show various statistics
84 82 memory.use_hierarchy set/show hierarchical account enabled
85 83 This knob is deprecated and shouldn't be
@@ -340,9 +338,6 @@ memory.kmem.usage_in_bytes, or in a separate counter when it makes sense.
340 338 The main "kmem" counter is fed into the main counter, so kmem charges will
341 339 also be visible from the user counter.
342 340
343 - Currently no soft limit is implemented for kernel memory. It is future work
344 - to trigger slab reclaim when those limits are reached.
345 -
346 341 2.7.1 Current Kernel Memory resources accounted
347 342 -----------------------------------------------
348 343
@@ -710,42 +705,10 @@ For compatibility reasons writing 1 to memory.use_hierarchy will always pass::
710 705
711 706 THIS IS DEPRECATED!
712 707
713 - Soft limits allow for greater sharing of memory. The idea behind soft limits
714 - is to allow control groups to use as much of the memory as needed, provided
715 -
716 - a. There is no memory contention
717 - b. They do not exceed their hard limit
718 -
719 - When the system detects memory contention or low memory, control groups
720 - are pushed back to their soft limits. If the soft limit of each control
721 - group is very high, they are pushed back as much as possible to make
722 - sure that one control group does not starve the others of memory.
723 -
724 - Please note that soft limits is a best-effort feature; it comes with
725 - no guarantees, but it does its best to make sure that when memory is
726 - heavily contended for, memory is allocated based on the soft limit
727 - hints/setup. Currently soft limit based reclaim is set up such that
728 - it gets invoked from balance_pgdat (kswapd).
729 -
730 - 7.1 Interface
731 - -------------
732 -
733 - Soft limits can be setup by using the following commands (in this example we
734 - assume a soft limit of 256 MiB)::
735 -
736 - # echo 256M > memory.soft_limit_in_bytes
737 -
738 - If we want to change this to 1G, we can at any time use::
708 + Writing to memory.soft_limit_in_bytes has no effect and reading it will
709 + always return the maximum value.
739 710
740 - # echo 1G > memory.soft_limit_in_bytes
741 -
742 - .. note::
743 - Soft limits take effect over a long period of time, since they involve
744 - reclaiming memory for balancing between memory cgroups
745 -
746 - .. note::
747 - It is recommended to set the soft limit always below the hard limit,
748 - otherwise the hard limit will take precedence.
711 + Use memory.low and memory.min in cgroup v2 instead.
749 712
750 713 .. _cgroup-v1-memory-move-charges:
751 714
modified Documentation/admin-guide/cgroup-v2.rst
@@ -1130,9 +1130,9 @@ policy and the underlying scheduler. From the point of view of the cpu controlle
1130 1130 processes can be categorized as follows:
1131 1131
1132 1132 * Processes under the fair-class scheduler
1133 - * Processes under a BPF scheduler with the ``cgroup_set_weight`` callback
1133 + * Processes under a BPF scheduler with the corresponding ``cgroup_set_*`` callback
1134 1134 * Everything else: ``SCHED_{FIFO,RR,DEADLINE}`` and processes under a BPF scheduler
1135 - without the ``cgroup_set_weight`` callback
1135 + without the corresponding ``cgroup_set_*`` callback
1136 1136
1137 1137 For details on when a process is under the fair-class scheduler or a BPF scheduler,
1138 1138 check out :ref:`Documentation/scheduler/sched-ext.rst <sched-ext>`.
@@ -1223,7 +1223,9 @@ will be referred to. All time durations are in microseconds.
1223 1223 $PERIOD duration. "max" for $MAX indicates no limit. If only
1224 1224 one number is written, $MAX is updated.
1225 1225
1226 - This file affects only processes under the fair-class scheduler.
1226 + This file affects only processes under the fair-class scheduler and a BPF
1227 + scheduler with the ``cgroup_set_bandwidth`` callback depending on what
1228 + the callback actually does.
1227 1229
1228 1230 cpu.max.burst
1229 1231 A read-write single value file which exists on non-root
@@ -1231,7 +1233,9 @@ will be referred to. All time durations are in microseconds.
1231 1233
1232 1234 The burst in the range [0, $MAX].
1233 1235
1234 - This file affects only processes under the fair-class scheduler.
1236 + This file affects only processes under the fair-class scheduler and a BPF
1237 + scheduler with the ``cgroup_set_bandwidth`` callback depending on what
1238 + the callback actually does.
1235 1239
1236 1240 cpu.pressure
1237 1241 A read-write nested-keyed file.
@@ -1283,7 +1287,9 @@ will be referred to. All time durations are in microseconds.
1283 1287 own relative priorities, but the cgroup itself will be treated as
1284 1288 very low priority relative to its peers.
1285 1289
1286 - This file affects only processes under the fair-class scheduler.
1290 + This file affects only processes under the fair-class scheduler and a BPF
1291 + scheduler with the ``cgroup_set_idle`` callback depending on what the
1292 + callback actually does.
1287 1293
1288 1294 Memory
1289 1295 ------
@@ -3064,7 +3070,7 @@ resources (res_a and res_b) are registered then:
3064 3070 change in this file generates a file modified event. All fields in
3065 3071 this file are hierarchical.
3066 3072
3067 - max
3073 + <res>.max
3068 3074 The number of times the cgroup's resource usage was
3069 3075 about to go over the max boundary.
3070 3076
modified Documentation/devicetree/bindings/pinctrl/qcom,nord-tlmm.yaml
@@ -67,7 +67,7 @@ $defs:
67 67 Specify the alternative function to be configured for the specified
68 68 pins.
69 69
70 - enum: [ aoss_cti, atest_char, atest_usb20, atest_usb21,
70 + enum: [ gpio, aoss_cti, atest_char, atest_usb20, atest_usb21,
71 71 aud_intfc0_clk, aud_intfc0_data, aud_intfc0_ws,
72 72 aud_intfc10_clk, aud_intfc10_data, aud_intfc10_ws,
73 73 aud_intfc1_clk, aud_intfc1_data, aud_intfc1_ws,
@@ -98,9 +98,10 @@ $defs:
98 98 pcie3_clk_req_n, phase_flag, pll_bist_sync, pll_clk_aux,
99 99 prng_rosc0, prng_rosc1, pwrbrk_i_n, qdss, qdss_cti, qspi,
100 100 qup0_se0, qup0_se1, qup0_se2, qup0_se3, qup0_se4, qup0_se5,
101 - qup1_se0, qup1_se1, qup1_se3, qup1_se2, qup1_se4, qup1_se5,
101 + qup1_se0, qup1_se1, qup1_se2_01, qup1_se2_23, qup1_se3_01,
102 + qup1_se3_23, qup1_se4, qup1_se5,
102 103 qup1_se6, qup2_se0, qup2_se1, qup2_se2, qup2_se3, qup2_se4,
103 - qup2_se5, qup2_se6,
104 + qup2_se5, qup2_se6, qup3_se0_mira, qup3_se0_mirb,
104 105 sailss_ospi, sdc4_clk, sdc4_cmd, sdc4_data, smb_alert,
105 106 smb_alert_n, smb_clk, smb_dat, tb_trig_sdc4, tmess_prng0,
106 107 tmess_prng1, tsc_timer, tsense_pwm, usb0_hs,
modified Documentation/fault-injection/nvme-fault-injection.rst
@@ -176,3 +176,68 @@ Message from dmesg::
176 176 secondary_startup_64+0xa4/0xb0
177 177 nvme nvme0: Could not set queue count (16385)
178 178 nvme nvme0: IO queues not created
179 +
180 + Example 4: Inject an error into the first write command
181 + -------------------------------------------------------
182 +
183 + ::
184 +
185 + echo 0x01 > /sys/kernel/debug/nvme0n1/fault_inject/opcode
186 + echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
187 + echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
188 + dd if=/dev/zero of=/dev/nvme0n1 oflag=direct bs=512 count=1
189 +
190 + Expected Result::
191 +
192 + The first write command sent to nvme0n1 fails
193 +
194 + Message from dmesg::
195 +
196 + FAULT_INJECTION: forcing a failure.
197 + name fault_inject, interval 1, probability 100, space 0, times 1
198 + CPU: 4 UID: 0 PID: 0 Comm: swapper/4 Not tainted 7.1.0+ #5 PREEMPT(full)
199 + Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-20240910_120124-localhost 04/01/2014
200 + Call Trace:
201 + <IRQ>
202 + dump_stack_lvl+0x6e/0xa0
203 + dump_stack+0x10/0x16
204 + should_fail_ex+0x461/0x510
205 + should_fail+0xb/0x20
206 + nvme_should_fail+0x11b/0x240 [nvme_core]
207 + nvme_poll_cq+0x6ad/0xb30 [nvme]
208 + nvme_irq+0x84/0xe0 [nvme]
209 + ? __pfx_nvme_irq+0x10/0x10 [nvme]
210 + ? rcu_core+0xa40/0xa90
211 + ? __pfx_sched_balance_softirq+0x10/0x10
212 + ? debug_smp_processor_id+0x17/0x20
213 + ? rcu_is_watching+0x13/0xa0
214 + __handle_irq_event_percpu+0x396/0x610
215 + handle_irq_event_percpu+0xf/0x90
216 + handle_irq_event+0xab/0x110
217 + handle_edge_irq+0x1a3/0x210
218 + __common_interrupt+0xff/0x170
219 + common_interrupt+0x90/0xc0
220 + </IRQ>
221 + <TASK>
222 + asm_common_interrupt+0x27/0x40
223 + RIP: 0010:pv_native_safe_halt+0x13/0x20
224 + Code: 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 8b 05 0a 2a 58 01 85 c0 7e 07 0f 00 2d ff cc 0d 00 fb f4 <c3> cc 0
225 + RSP: 0018:ffff888100a67e40 EFLAGS: 00000242
226 + RAX: 0000000000000001 RBX: ffff888100a49c40 RCX: ffffed102b6c645b
227 + RDX: ffffed102b6c645b RSI: ffffffff82a0d3c0 RDI: ffffffff81428b9b
228 + RBP: ffff888100a67e48 R08: ffffed102b6c645b R09: 0000000000000004
229 + R10: ffffed102b6c645a R11: 0000000000000001 R12: 0000000000000000
230 + R13: 0000000000000000 R14: ffffed1020149388 R15: dffffc0000000000
231 + ? do_idle+0x19b/0x2c0
232 + ? default_idle+0x9/0x20
233 + arch_cpu_idle+0x9/0x10
234 + default_idle_call+0x6b/0xa0
235 + do_idle+0x19b/0x2c0
236 + ? __pfx_do_idle+0x10/0x10
237 + ? complete_with_flags+0x63/0x70
238 + cpu_startup_entry+0x55/0x60
239 + start_secondary+0x1df/0x1e0
240 + common_startup_64+0x13e/0x158
241 + </TASK>
242 + nvme0n1: Write(0x1) @ LBA 0, 1 blocks, Invalid Command Opcode (sct 0x0 / sc 0x1) DNR
243 + operation not supported error, dev nvme0n1, sector 0 op 0x1:(WRITE) flags 0x8800 phys_seg 1 prio class 2
modified Documentation/netlink/specs/conntrack.yaml
@@ -360,6 +360,17 @@ attribute-sets:
360 360 name: tsoff
361 361 type: u32
362 362 byte-order: big-endian
363 + -
364 + name: filter-attrs
365 + attributes:
366 + -
367 + name: orig-flags
368 + type: u32
369 + doc: bitmask of tuple fields to filter on, original direction
370 + -
371 + name: reply-flags
372 + type: u32
373 + doc: bitmask of tuple fields to filter on, reply direction
363 374 -
364 375 name: conntrack-attrs
365 376 attributes:
@@ -466,7 +477,7 @@ attribute-sets:
466 477 -
467 478 name: filter
468 479 type: nest
469 - nested-attributes: tuple-attrs
480 + nested-attributes: filter-attrs
470 481 -
471 482 name: status-mask
472 483 type: u32
@@ -591,10 +602,14 @@ operations:
591 602 request:
592 603 value: 0x101
593 604 attributes:
594 - - mark
595 - - filter
605 + - tuple-orig
606 + - tuple-reply
596 607 - status
608 + - mark
597 609 - zone
610 + - mark-mask
611 + - filter
612 + - status-mask
598 613 reply:
599 614 value: 0x100
600 615 attributes:
modified Documentation/scheduler/sched-ext.rst
@@ -230,7 +230,7 @@ optional. The following modified excerpt is from
230 230
231 231 void BPF_STRUCT_OPS(simple_exit, struct scx_exit_info *ei)
232 232 {
233 - exit_type = ei->type;
233 + exit_type = ei->kind;
234 234 }
235 235
236 236 SEC(".struct_ops")
@@ -242,6 +242,21 @@ optional. The following modified excerpt is from
242 242 .name = "simple",
243 243 };
244 244
245 + Scheduler-Dependent Knobs
246 + -------------------------
247 +
248 + The fair-class scheduler enforces CPU controller settings such as
249 + ``cpu.max``, ``cpu.weight`` and ``cpu.idle``. For sched_ext tasks, the
250 + scheduler core communicates these settings to the BPF scheduler
251 + through ``ops.cgroup_init()`` and reports subsequent changes through
252 + the corresponding ``ops.cgroup_set_*()`` callbacks. Similarly, per-task
253 + nice changes are converted to weights and reported through
254 + ``ops.set_weight()``.
255 +
256 + Each BPF scheduler is responsible for implementing the scheduling
257 + semantics of these settings and may choose to ignore them. Consult the
258 + loaded scheduler's documentation before relying on these controls.
259 +
245 260 Dispatch Queues
246 261 ---------------
247 262
modified Documentation/translations/zh_CN/core-api/irq/irq-domain.rst
@@ -90,10 +90,6 @@ irq_domain映射的类型
90 90 映射的优点是固定时间查找IRQ号,而且irq_descs只分配给在用的IRQ。 缺点是该表
91 91 必须尽可能大的hwirq号。
92 92
93 - irq_domain_add_linear()和irq_domain_create_linear()在功能上是等价的,
94 - 除了第一个参数不同--前者接受一个Open Firmware特定的 'struct device_node' 而
95 - 后者接受一个更通用的抽象 'struct fwnode_handle' 。
96 -
97 93 大多数驱动应该使用线性映射
98 94
99 95 树状映射
modified MAINTAINERS
@@ -5671,8 +5671,8 @@ W: http://bu3sch.de/btgpio.php
5671 5671 F: drivers/gpio/gpio-bt8xx.c
5672 5672
5673 5673 BTRFS FILE SYSTEM
5674 - M: Chris Mason <clm@fb.com>
5675 5674 M: David Sterba <dsterba@suse.com>
5675 + R: Chris Mason <mason@kernel.org>
5676 5676 L: linux-btrfs@vger.kernel.org
5677 5677 S: Maintained
5678 5678 W: https://btrfs.readthedocs.io
@@ -8039,7 +8039,7 @@ F: drivers/gpu/drm/sun4i/sun8i*
8039 8039
8040 8040 DRM DRIVER FOR APPLE TOUCH BARS
8041 8041 M: Aun-Ali Zaidi <admin@kodeit.net>
8042 - M: Aditya Garg <gargaditya08@proton.me>
8042 + M: Aditya Garg <aditya.garg@linux.dev>
8043 8043 L: dri-devel@lists.freedesktop.org
8044 8044 S: Maintained
8045 8045 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -9387,9 +9387,8 @@ S: Maintained
9387 9387 F: drivers/edac/octeon_edac*
9388 9388
9389 9389 EDAC-CAVIUM THUNDERX
9390 - M: Robert Richter <rric@kernel.org>
9391 9390 L: linux-edac@vger.kernel.org
9392 - S: Odd Fixes
9391 + S: Orphan
9393 9392 F: drivers/edac/thunderx_edac*
9394 9393
9395 9394 EDAC-CORE
@@ -9416,9 +9415,8 @@ S: Supported
9416 9415 F: drivers/edac/dmc520_edac.c
9417 9416
9418 9417 EDAC-E752X
9419 - M: Mark Gross <markgross@kernel.org>
9420 9418 L: linux-edac@vger.kernel.org
9421 - S: Maintained
9419 + S: Orphan
9422 9420 F: drivers/edac/e752x_edac.c
9423 9421
9424 9422 EDAC-E7XXX
@@ -9493,9 +9491,8 @@ S: Maintained
9493 9491 F: drivers/edac/igen6_edac.c
9494 9492
9495 9493 EDAC-MPC85XX
9496 - M: Johannes Thumshirn <morbidrsa@gmail.com>
9497 9494 L: linux-edac@vger.kernel.org
9498 - S: Maintained
9495 + S: Orphan
9499 9496 F: drivers/edac/mpc85xx_edac.[ch]
9500 9497
9501 9498 EDAC-NPCM
@@ -10193,7 +10190,6 @@ F: include/linux/arm_ffa.h
10193 10190
10194 10191 FIRMWARE LOADER (request_firmware)
10195 10192 M: Luis Chamberlain <mcgrof@kernel.org>
10196 - M: Russ Weight <russ.weight@linux.dev>
10197 10193 M: Danilo Krummrich <dakr@kernel.org>
10198 10194 L: driver-core@lists.linux.dev
10199 10195 S: Maintained
@@ -12224,7 +12220,7 @@ F: drivers/tty/hvc/
12224 12220
12225 12221 HUNG TASK DETECTOR
12226 12222 M: Andrew Morton <akpm@linux-foundation.org>
12227 - R: Lance Yang <lance.yang@linux.dev>
12223 + M: Lance Yang <lance.yang@linux.dev>
12228 12224 R: Masami Hiramatsu <mhiramat@kernel.org>
12229 12225 R: Petr Mladek <pmladek@suse.com>
12230 12226 L: linux-kernel@vger.kernel.org
@@ -13283,7 +13279,6 @@ F: drivers/crypto/intel/keembay/ocs-aes.h
13283 13279
13284 13280 INTEL KEEM BAY OCS ECC CRYPTO DRIVER
13285 13281 M: Prabhjot Khurana <prabhjot.khurana@intel.com>
13286 - M: Mark Gross <mgross@linux.intel.com>
13287 13282 S: Maintained
13288 13283 F: Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml
13289 13284 F: drivers/crypto/intel/keembay/Kconfig
@@ -14240,8 +14235,6 @@ F: tools/testing/selftests/
14240 14235 KERNEL SMB3 SERVER (KSMBD)
14241 14236 M: Namjae Jeon <linkinjeon@kernel.org>
14242 14237 M: Namjae Jeon <linkinjeon@samba.org>
14243 - M: Steve French <smfrench@gmail.com>
14244 - M: Steve French <sfrench@samba.org>
14245 14238 R: Sergey Senozhatsky <senozhatsky@chromium.org>
14246 14239 R: Tom Talpey <tom@talpey.com>
14247 14240 R: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
@@ -17416,7 +17409,6 @@ F: mm/swapfile.c
17416 17409 MEMORY MANAGEMENT - THP (TRANSPARENT HUGE PAGE)
17417 17410 M: Andrew Morton <akpm@linux-foundation.org>
17418 17411 M: David Hildenbrand <david@kernel.org>
17419 - M: Lorenzo Stoakes <ljs@kernel.org>
17420 17412 R: Zi Yan <ziy@nvidia.com>
17421 17413 R: Baolin Wang <baolin.wang@linux.alibaba.com>
17422 17414 R: Liam R. Howlett <liam@infradead.org>
@@ -17426,6 +17418,7 @@ R: Dev Jain <dev.jain@arm.com>
17426 17418 R: Barry Song <baohua@kernel.org>
17427 17419 R: Lance Yang <lance.yang@linux.dev>
17428 17420 R: Usama Arif <usama.arif@linux.dev>
17421 + R: Kiryl Shutsemau <kas@kernel.org>
17429 17422 L: linux-mm@kvack.org
17430 17423 S: Maintained
17431 17424 W: http://www.linux-mm.org
@@ -17698,7 +17691,7 @@ F: Documentation/devicetree/bindings/serial/atmel,at91-usart.yaml
17698 17691 F: drivers/spi/spi-at91-usart.c
17699 17692
17700 17693 MICROCHIP ATSHA204A DRIVER
17701 - M: Thorsten Blum <thorsten.blum@linux.dev>
17694 + M: Thorsten Blum <blum@kernel.org>
17702 17695 L: linux-crypto@vger.kernel.org
17703 17696 S: Maintained
17704 17697 F: drivers/crypto/atmel-sha204a.c
@@ -17722,7 +17715,7 @@ F: Documentation/devicetree/bindings/media/microchip,csi2dc.yaml
17722 17715 F: drivers/media/platform/microchip/microchip-csi2dc.c
17723 17716
17724 17717 MICROCHIP ECC DRIVER
17725 - M: Thorsten Blum <thorsten.blum@linux.dev>
17718 + M: Thorsten Blum <blum@kernel.org>
17726 17719 L: linux-crypto@vger.kernel.org
17727 17720 S: Maintained
17728 17721 F: drivers/crypto/atmel-ecc.c
@@ -19569,7 +19562,7 @@ F: include/linux/platform_data/x86/nvidia-wmi-ec-backlight.h
19569 19562
19570 19563 NVM EXPRESS DRIVER
19571 19564 M: Keith Busch <kbusch@kernel.org>
19572 - M: Jens Axboe <axboe@fb.com>
19565 + M: Jens Axboe <axboe@kernel.dk>
19573 19566 M: Christoph Hellwig <hch@lst.de>
19574 19567 M: Sagi Grimberg <sagi@grimberg.me>
19575 19568 L: linux-nvme@lists.infradead.org
@@ -24778,7 +24771,7 @@ K: \bsecurity_[a-z_0-9]\+\b
24778 24771 SELINUX SECURITY MODULE
24779 24772 M: Paul Moore <paul@paul-moore.com>
24780 24773 M: Stephen Smalley <stephen.smalley.work@gmail.com>
24781 - R: Ondrej Mosnacek <omosnace@redhat.com>
24774 + R: Ondrej Mosnáček <omosnacek@gmail.com>
24782 24775 L: selinux@vger.kernel.org
24783 24776 S: Supported
24784 24777 W: https://github.com/SELinuxProject
@@ -25236,10 +25229,9 @@ F: Documentation/admin-guide/LSM/Smack.rst
25236 25229 F: security/smack/
25237 25230
25238 25231 SMBDIRECT (RDMA Stream Transport with Read/Write-Offload, MS-SMBD)
25239 - M: Steve French <smfrench@gmail.com>
25240 - M: Steve French <sfrench@samba.org>
25241 25232 M: Namjae Jeon <linkinjeon@kernel.org>
25242 25233 M: Namjae Jeon <linkinjeon@samba.org>
25234 + M: Paulo Alcantara <pc@manguebit.org>
25243 25235 R: Stefan Metzmacher <metze@samba.org>
25244 25236 R: Tom Talpey <tom@talpey.com>
25245 25237 L: linux-cifs@vger.kernel.org
@@ -25410,7 +25402,7 @@ F: drivers/md/md*
25410 25402 F: drivers/md/raid*
25411 25403 F: include/linux/raid/
25412 25404 F: include/uapi/linux/raid/
25413 - F: lib/raid/raid6/
25405 + F: lib/raid/
25414 25406
25415 25407 SOLIDRUN CLEARFOG SUPPORT
25416 25408 M: Russell King <linux@armlinux.org.uk>
@@ -26954,8 +26946,7 @@ S: Maintained
26954 26946 F: drivers/net/ethernet/tehuti/tn40*
26955 26947
26956 26948 TELECOM CLOCK DRIVER FOR MCPL0010
26957 - M: Mark Gross <markgross@kernel.org>
26958 - S: Supported
26949 + S: Orphan
26959 26950 F: drivers/char/tlclk.c
26960 26951
26961 26952 TEMPO SEMICONDUCTOR DRIVERS
@@ -29937,12 +29928,14 @@ F: include/uapi/linux/xilinx-v4l2-controls.h
29937 29928 XILINX VERSAL EDAC DRIVER
29938 29929 M: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
29939 29930 M: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
29931 + R: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
29940 29932 S: Maintained
29941 29933 F: Documentation/devicetree/bindings/memory-controllers/xlnx,versal-ddrmc-edac.yaml
29942 29934 F: drivers/edac/versal_edac.c
29943 29935
29944 29936 XILINX VERSALNET EDAC DRIVER
29945 29937 M: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
29938 + R: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
29946 29939 S: Maintained
29947 29940 F: Documentation/devicetree/bindings/memory-controllers/xlnx,versal-net-ddrmc5.yaml
29948 29941 F: drivers/edac/versalnet_edac.c
@@ -29988,6 +29981,7 @@ F: include/dt-bindings/dma/xlnx-zynqmp-dpdma.h
29988 29981 XILINX ZYNQMP OCM EDAC DRIVER
29989 29982 M: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
29990 29983 M: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
29984 + R: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
29991 29985 S: Maintained
29992 29986 F: Documentation/devicetree/bindings/memory-controllers/xlnx,zynqmp-ocmc-1.0.yaml
29993 29987 F: drivers/edac/zynqmp_edac.c
modified Makefile
@@ -2,7 +2,7 @@
2 2 VERSION = 7
3 3 PATCHLEVEL = 3
4 4 SUBLEVEL = 0
5 - EXTRAVERSION = -rc1
5 + EXTRAVERSION = -rc2
6 6 NAME = Baby Opossum Posse
7 7
8 8 # *DOCUMENTATION*
modified arch/arm/configs/sama5_defconfig
@@ -69,8 +69,8 @@ CONFIG_BLK_DEV_SD=y
69 69 # CONFIG_BLK_DEV_BSG is not set
70 70 # CONFIG_SCSI_LOWLEVEL is not set
71 71 CONFIG_NETDEVICES=y
72 - CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON=m
73 - CONFIG_NET_DSA_MICROCHIP_KSZ_SPI=m
72 + CONFIG_NET_DSA_MICROCHIP_KSZ9477=m
73 + CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI=m
74 74 # CONFIG_NET_VENDOR_BROADCOM is not set
75 75 CONFIG_MACB=y
76 76 # CONFIG_NET_VENDOR_CIRRUS is not set
modified arch/arm64/crypto/aes-neonbs-glue.c
@@ -66,7 +66,7 @@ static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
66 66 struct crypto_aes_ctx *rk;
67 67 int err;
68 68
69 - rk = kmalloc(sizeof(*rk), GFP_KERNEL);
69 + rk = kmalloc_obj(*rk);
70 70 if (!rk)
71 71 return -ENOMEM;
72 72
@@ -128,7 +128,7 @@ static int aesbs_cbc_ctr_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
128 128 struct crypto_aes_ctx *rk;
129 129 int err;
130 130
131 - rk = kmalloc(sizeof(*rk), GFP_KERNEL);
131 + rk = kmalloc_obj(*rk);
132 132 if (!rk)
133 133 return -ENOMEM;
134 134
modified arch/arm64/include/asm/cpu.h
@@ -78,5 +78,6 @@ void __init cpuinfo_store_boot_cpu(void);
78 78 void __init init_cpu_features(struct cpuinfo_arm64 *info);
79 79 void update_cpu_features(int cpu, struct cpuinfo_arm64 *info,
80 80 struct cpuinfo_arm64 *boot);
81 + bool gmid_el1_accessible(const struct cpuinfo_arm64 *info);
81 82
82 83 #endif /* __ASM_CPU_H */
modified arch/arm64/include/asm/cpufeature.h
@@ -627,13 +627,6 @@ static inline bool id_aa64pfr1_mpamfrac(u64 pfr1)
627 627 return val > 0;
628 628 }
629 629
630 - static inline bool id_aa64pfr1_mte(u64 pfr1)
631 - {
632 - u32 val = cpuid_feature_extract_unsigned_field(pfr1, ID_AA64PFR1_EL1_MTE_SHIFT);
633 -
634 - return val >= ID_AA64PFR1_EL1_MTE_MTE2;
635 - }
636 -
637 630 void __init setup_boot_cpu_features(void);
638 631 void __init setup_system_features(void);
639 632 void __init setup_user_features(void);
modified arch/arm64/kernel/cpu_errata.c
@@ -82,7 +82,7 @@ is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
82 82
83 83 for (i = 0; i < target_impl_cpu_num; i++) {
84 84 if (__is_affected_midr_range(entry, target_impl_cpus[i].midr,
85 - target_impl_cpus[i].midr))
85 + target_impl_cpus[i].revidr))
86 86 return true;
87 87 }
88 88 return false;
modified arch/arm64/kernel/cpufeature.c
@@ -1178,6 +1178,33 @@ static bool detect_ftr_has_mpam(void)
1178 1178 return id_aa64pfr0_mpam(pfr0) || id_aa64pfr1_mpamfrac(pfr1);
1179 1179 }
1180 1180
1181 + bool gmid_el1_accessible(const struct cpuinfo_arm64 *info)
1182 + {
1183 + const struct arm64_ftr_bits *ftrp;
1184 + s64 mte, ovr;
1185 + u64 ftr_mask;
1186 +
1187 + /* No ID register reflects CONFIG_ARM64_MTE. */
1188 + if (!IS_ENABLED(CONFIG_ARM64_MTE))
1189 + return false;
1190 +
1191 + for (ftrp = ftr_id_aa64pfr1; ftrp->width; ftrp++) {
1192 + if (ftrp->shift == ID_AA64PFR1_EL1_MTE_SHIFT)
1193 + break;
1194 + }
1195 +
1196 + ftr_mask = arm64_ftr_mask(ftrp);
1197 + mte = arm64_ftr_value(ftrp, info->reg_id_aa64pfr1);
1198 +
1199 + /* The boot CPU runs before init_cpu_ftr_reg() strips unsafe overrides. */
1200 + if ((id_aa64pfr1_override.mask & ftr_mask) == ftr_mask) {
1201 + ovr = arm64_ftr_value(ftrp, id_aa64pfr1_override.val);
1202 + mte = arm64_ftr_safe_value(ftrp, ovr, mte);
1203 + }
1204 +
1205 + return mte >= ID_AA64PFR1_EL1_MTE_MTE2;
1206 + }
1207 +
1181 1208 void __init init_cpu_features(struct cpuinfo_arm64 *info)
1182 1209 {
1183 1210 /* Before we start using the tables, make sure it is sorted */
@@ -1230,7 +1257,7 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info)
1230 1257 init_cpu_ftr_reg(SYS_MPAMIDR_EL1, info->reg_mpamidr);
1231 1258 }
1232 1259
1233 - if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
1260 + if (gmid_el1_accessible(info))
1234 1261 init_cpu_ftr_reg(SYS_GMID_EL1, info->reg_gmid);
1235 1262 }
1236 1263
@@ -1492,11 +1519,9 @@ void update_cpu_features(int cpu,
1492 1519 * they read/write depends on the GMID_EL1.BS field. Check that the
1493 1520 * value is the same on all CPUs.
1494 1521 */
1495 - if (IS_ENABLED(CONFIG_ARM64_MTE) &&
1496 - id_aa64pfr1_mte(info->reg_id_aa64pfr1)) {
1522 + if (gmid_el1_accessible(info))
1497 1523 taint |= check_update_ftr_reg(SYS_GMID_EL1, cpu,
1498 1524 info->reg_gmid, boot->reg_gmid);
1499 - }
1500 1525
1501 1526 /*
1502 1527 * If we don't have AArch32 at all then skip the checks entirely
modified arch/arm64/kernel/cpuinfo.c
@@ -502,7 +502,7 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
502 502 info->reg_id_aa64smfr0 = read_cpuid(ID_AA64SMFR0_EL1);
503 503 info->reg_id_aa64fpfr0 = read_cpuid(ID_AA64FPFR0_EL1);
504 504
505 - if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
505 + if (gmid_el1_accessible(info))
506 506 info->reg_gmid = read_cpuid(GMID_EL1);
507 507
508 508 if (id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0))
modified arch/arm64/kernel/machine_kexec.c
@@ -129,7 +129,8 @@ int machine_kexec_post_load(struct kimage *kimage)
129 129 }
130 130
131 131 /* Create a copy of the linear map */
132 - rc = trans_pgd_create_copy(&info, &trans_pgd, PAGE_OFFSET, PAGE_END);
132 + rc = trans_pgd_create_copy(&info, &trans_pgd,
133 + _PAGE_OFFSET(vabits_actual), PAGE_END);
133 134 if (rc)
134 135 return rc;
135 136 kimage->arch.ttbr1 = __pa(trans_pgd);
modified arch/arm64/kvm/nested.c
@@ -93,7 +93,7 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
93 93 num_mmus = atomic_read(&kvm->online_vcpus) * S2_MMU_PER_VCPU;
94 94
95 95 if (num_mmus > kvm->arch.nested_mmus_size) {
96 - tmp = kvcalloc(num_mmus, sizeof(*tmp), GFP_KERNEL_ACCOUNT);
96 + tmp = kvzalloc_objs(*tmp, num_mmus, GFP_KERNEL_ACCOUNT);
97 97 if (!tmp)
98 98 return -ENOMEM;
99 99
modified arch/arm64/mm/fault.c
@@ -16,6 +16,7 @@
16 16 #include <linux/mm.h>
17 17 #include <linux/hardirq.h>
18 18 #include <linux/init.h>
19 + #include <linux/irqflags.h>
19 20 #include <linux/kasan.h>
20 21 #include <linux/kprobes.h>
21 22 #include <linux/uaccess.h>
@@ -154,6 +155,9 @@ static void show_pte(unsigned long addr)
154 155 pr_alert("%s pgtable: %luk pages, %llu-bit VAs, pgdp=%016lx\n",
155 156 mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K,
156 157 vabits_actual, mm_to_pgd_phys(mm));
158 +
159 + guard(irqsave)();
160 +
157 161 pgdp = pgd_offset(mm, addr);
158 162 pgd = READ_ONCE(*pgdp);
159 163 pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd));
@@ -167,25 +171,25 @@ static void show_pte(unsigned long addr)
167 171 if (pgd_none(pgd) || pgd_bad(pgd))
168 172 break;
169 173
170 - p4dp = p4d_offset(pgdp, addr);
174 + p4dp = p4d_offset_lockless(pgdp, pgd, addr);
171 175 p4d = READ_ONCE(*p4dp);
172 176 pr_cont(", p4d=%016llx", p4d_val(p4d));
173 177 if (p4d_none(p4d) || p4d_bad(p4d))
174 178 break;
175 179
176 - pudp = pud_offset(p4dp, addr);
180 + pudp = pud_offset_lockless(p4dp, p4d, addr);
177 181 pud = READ_ONCE(*pudp);
178 182 pr_cont(", pud=%016llx", pud_val(pud));
179 183 if (pud_none(pud) || pud_bad(pud))
180 184 break;
181 185
182 - pmdp = pmd_offset(pudp, addr);
186 + pmdp = pmd_offset_lockless(pudp, pud, addr);
183 187 pmd = READ_ONCE(*pmdp);
184 188 pr_cont(", pmd=%016llx", pmd_val(pmd));
185 189 if (pmd_none(pmd) || pmd_bad(pmd))
186 190 break;
187 191
188 - ptep = pte_offset_map(pmdp, addr);
192 + ptep = pte_offset_map(&pmd, addr);
189 193 if (!ptep)
190 194 break;
191 195
modified arch/loongarch/Kconfig
@@ -175,7 +175,7 @@ config LOONGARCH
175 175 select HAVE_RELIABLE_STACKTRACE if UNWINDER_ORC
176 176 select HAVE_RETHOOK
177 177 select HAVE_RSEQ
178 - select HAVE_RUST
178 + select HAVE_RUST if !KASAN
179 179 select HAVE_SAMPLE_FTRACE_DIRECT
180 180 select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
181 181 select HAVE_SETUP_PER_CPU_AREA if NUMA
modified arch/loongarch/include/asm/kvm_dmsintc.h
@@ -20,6 +20,7 @@ struct dmsintc_state {
20 20 };
21 21
22 22 int kvm_loongarch_register_dmsintc_device(void);
23 + void kvm_loongarch_unregister_dmsintc_device(void);
23 24 void dmsintc_inject_irq(struct kvm_vcpu *vcpu);
24 25 int dmsintc_set_irq(struct kvm *kvm, u64 addr, int data, int level);
25 26 int dmsintc_deliver_msi_to_vcpu(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 vector, int level);
modified arch/loongarch/include/asm/kvm_eiointc.h
@@ -79,6 +79,7 @@ struct loongarch_eiointc {
79 79 };
80 80
81 81 int kvm_loongarch_register_eiointc_device(void);
82 + void kvm_loongarch_unregister_eiointc_device(void);
82 83 void eiointc_set_irq(struct loongarch_eiointc *s, int irq, int level);
83 84
84 85 #endif /* __ASM_KVM_EIOINTC_H */
modified arch/loongarch/include/asm/kvm_host.h
@@ -125,6 +125,7 @@ struct kvm_arch {
125 125 unsigned int pte_shifts[MAX_PGTABLE_LEVELS];
126 126 unsigned int root_level;
127 127 spinlock_t phyid_map_lock;
128 + spinlock_t pv_setting_lock;
128 129 struct kvm_phyid_map *phyid_map;
129 130 /* Enabled PV features */
130 131 unsigned long pv_features;
@@ -350,7 +351,6 @@ static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
350 351 static inline void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) {}
351 352 void kvm_check_vpid(struct kvm_vcpu *vcpu);
352 353 enum hrtimer_restart kvm_swtimer_wakeup(struct hrtimer *timer);
353 - void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm, const struct kvm_memory_slot *memslot);
354 354 void kvm_init_vmcs(struct kvm *kvm);
355 355 void kvm_exc_entry(void);
356 356 int kvm_enter_guest(struct kvm_run *run, struct kvm_vcpu *vcpu);
modified arch/loongarch/include/asm/kvm_ipi.h
@@ -41,5 +41,6 @@ struct ipi_state {
41 41 #define IOCSR_ANY_SEND 0x158
42 42
43 43 int kvm_loongarch_register_ipi_device(void);
44 + void kvm_loongarch_unregister_ipi_device(void);
44 45
45 46 #endif
modified arch/loongarch/include/asm/kvm_pch_pic.h
@@ -70,6 +70,7 @@ struct loongarch_pch_pic {
70 70
71 71 struct kvm_kernel_irq_routing_entry;
72 72 int kvm_loongarch_register_pch_pic_device(void);
73 + void kvm_loongarch_unregister_pch_pic_device(void);
73 74 void pch_pic_set_irq(struct loongarch_pch_pic *s, int irq, int level);
74 75 int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, int level);
75 76
modified arch/loongarch/kernel/kprobes.c
@@ -275,6 +275,9 @@ bool kprobe_singlestep_handler(struct pt_regs *regs)
275 275 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
276 276 unsigned long addr = instruction_pointer(regs);
277 277
278 + if (!cur)
279 + return false;
280 +
278 281 if (cur && (kcb->kprobe_status & (KPROBE_HIT_SS | KPROBE_REENTER)) &&
279 282 ((unsigned long)&cur->ainsn.insn[1] == addr)) {
280 283 restore_local_irqflag(kcb, regs);
modified arch/loongarch/kernel/rethook_trampoline.S
@@ -24,7 +24,6 @@
24 24 cfi_st t6, PT_R18
25 25 cfi_st t7, PT_R19
26 26 cfi_st t8, PT_R20
27 - cfi_st u0, PT_R21
28 27 cfi_st fp, PT_R22
29 28 cfi_st s0, PT_R23
30 29 cfi_st s1, PT_R24
@@ -59,7 +58,6 @@
59 58 cfi_ld t6, PT_R18
60 59 cfi_ld t7, PT_R19
61 60 cfi_ld t8, PT_R20
62 - cfi_ld u0, PT_R21
63 61 cfi_ld fp, PT_R22
64 62 cfi_ld s0, PT_R23
65 63 cfi_ld s1, PT_R24
modified arch/loongarch/kernel/smp.c
@@ -14,7 +14,6 @@
14 14 #include <linux/init.h>
15 15 #include <linux/interrupt.h>
16 16 #include <linux/irq_work.h>
17 - #include <linux/profile.h>
18 17 #include <linux/seq_file.h>
19 18 #include <linux/smp.h>
20 19 #include <linux/threads.h>
@@ -716,13 +715,6 @@ void smp_send_stop(void)
716 715 smp_call_function(stop_this_cpu, NULL, 0);
717 716 }
718 717
719 - #ifdef CONFIG_PROFILING
720 - int setup_profiling_timer(unsigned int multiplier)
721 - {
722 - return 0;
723 - }
724 - #endif
725 -
726 718 static void flush_tlb_all_ipi(void *info)
727 719 {
728 720 local_flush_tlb_all();
modified arch/loongarch/kernel/vmlinux.lds.S
@@ -23,7 +23,7 @@
23 23 #include "image-vars.h"
24 24
25 25 /*
26 - * Max avaliable Page Size is 64K, so we set SectionAlignment
26 + * Max available Page Size is 64K, so we set SectionAlignment
27 27 * field of EFI application to 64K.
28 28 */
29 29 PECOFF_FILE_ALIGN = 0x200;
modified arch/loongarch/kvm/intc/dmsintc.c
@@ -149,7 +149,7 @@ static int kvm_dmsintc_create(struct kvm_device *dev, u32 type)
149 149 return -EINVAL;
150 150 }
151 151
152 - s = kzalloc(sizeof(struct loongarch_dmsintc), GFP_KERNEL);
152 + s = kzalloc_obj(struct loongarch_dmsintc);
153 153 if (!s)
154 154 return -ENOMEM;
155 155
@@ -180,3 +180,8 @@ int kvm_loongarch_register_dmsintc_device(void)
180 180 {
181 181 return kvm_register_device_ops(&kvm_dmsintc_dev_ops, KVM_DEV_TYPE_LOONGARCH_DMSINTC);
182 182 }
183 +
184 + void kvm_loongarch_unregister_dmsintc_device(void)
185 + {
186 + kvm_unregister_device_ops(KVM_DEV_TYPE_LOONGARCH_DMSINTC);
187 + }
modified arch/loongarch/kvm/intc/eiointc.c
@@ -695,3 +695,8 @@ int kvm_loongarch_register_eiointc_device(void)
695 695 {
696 696 return kvm_register_device_ops(&kvm_eiointc_dev_ops, KVM_DEV_TYPE_LOONGARCH_EIOINTC);
697 697 }
698 +
699 + void kvm_loongarch_unregister_eiointc_device(void)
700 + {
701 + kvm_unregister_device_ops(KVM_DEV_TYPE_LOONGARCH_EIOINTC);
702 + }
modified arch/loongarch/kvm/intc/ipi.c
@@ -463,3 +463,8 @@ int kvm_loongarch_register_ipi_device(void)
463 463 {
464 464 return kvm_register_device_ops(&kvm_ipi_dev_ops, KVM_DEV_TYPE_LOONGARCH_IPI);
465 465 }
466 +
467 + void kvm_loongarch_unregister_ipi_device(void)
468 + {
469 + kvm_unregister_device_ops(KVM_DEV_TYPE_LOONGARCH_IPI);
470 + }
modified arch/loongarch/kvm/intc/pch_pic.c
@@ -78,6 +78,9 @@ int pch_msi_set_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, int
78 78 return dmsintc_set_irq(kvm, msg_addr, e->msi.data, level);
79 79 }
80 80
81 + if (e->msi.data >= EIOINTC_IRQS)
82 + return -EINVAL;
83 +
81 84 eiointc_set_irq(kvm->arch.eiointc, e->msi.data, level);
82 85
83 86 return 0;
@@ -500,3 +503,8 @@ int kvm_loongarch_register_pch_pic_device(void)
500 503 {
501 504 return kvm_register_device_ops(&kvm_pch_pic_dev_ops, KVM_DEV_TYPE_LOONGARCH_PCHPIC);
502 505 }
506 +
507 + void kvm_loongarch_unregister_pch_pic_device(void)
508 + {
509 + kvm_unregister_device_ops(KVM_DEV_TYPE_LOONGARCH_PCHPIC);
510 + }
modified arch/loongarch/kvm/main.c
@@ -385,27 +385,52 @@ static int kvm_loongarch_env_init(void)
385 385 /* Register LoongArch IPI interrupt controller interface. */
386 386 ret = kvm_loongarch_register_ipi_device();
387 387 if (ret)
388 - return ret;
388 + goto err_env;
389 389
390 390 /* Register LoongArch EIOINTC interrupt controller interface. */
391 391 ret = kvm_loongarch_register_eiointc_device();
392 392 if (ret)
393 - return ret;
393 + goto err_ipi;
394 394
395 395 /* Register LoongArch PCH-PIC interrupt controller interface. */
396 396 ret = kvm_loongarch_register_pch_pic_device();
397 397 if (ret)
398 - return ret;
398 + goto err_eiointc;
399 399
400 400 /* Register LoongArch DMSINTC interrupt contrroller interface */
401 - if (cpu_has_msgint)
401 + if (cpu_has_msgint) {
402 402 ret = kvm_loongarch_register_dmsintc_device();
403 + if (ret)
404 + goto err_pch_pic;
405 + }
406 +
407 + return 0;
408 +
409 + err_pch_pic:
410 + kvm_loongarch_unregister_pch_pic_device();
411 + err_eiointc:
412 + kvm_loongarch_unregister_eiointc_device();
413 + err_ipi:
414 + kvm_loongarch_unregister_ipi_device();
415 + err_env:
416 + kvm_unregister_perf_callbacks();
417 + kfree(kvm_loongarch_ops);
418 + kvm_loongarch_ops = NULL;
419 + free_percpu(vmcs);
420 + vmcs = NULL;
403 421
404 422 return ret;
405 423 }
406 424
407 425 static void kvm_loongarch_env_exit(void)
408 426 {
427 + if (cpu_has_msgint)
428 + kvm_loongarch_unregister_dmsintc_device();
429 +
430 + kvm_loongarch_unregister_pch_pic_device();
431 + kvm_loongarch_unregister_eiointc_device();
432 + kvm_loongarch_unregister_ipi_device();
433 +
409 434 if (vmcs)
410 435 free_percpu(vmcs);
411 436
@@ -428,7 +453,11 @@ static int kvm_loongarch_init(void)
428 453 if (r)
429 454 return r;
430 455
431 - return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
456 + r = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
457 + if (r)
458 + kvm_loongarch_env_exit();
459 +
460 + return r;
432 461 }
433 462
434 463 static void kvm_loongarch_exit(void)
modified arch/loongarch/kvm/mmu.c
@@ -383,6 +383,16 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, const struct kvm_memory_slot
383 383 hva_t hva_start;
384 384 size_t size, gpa_offset, hva_offset;
385 385
386 + /*
387 + * The generic code allocates a fresh, zeroed memslot for every change,
388 + * so the arch flags computed below must be carried over when only the
389 + * userspace flags change, e.g. when dirty logging is toggled.
390 + */
391 + if (change == KVM_MR_FLAGS_ONLY) {
392 + new->arch = old->arch;
393 + return 0;
394 + }
395 +
386 396 if ((change != KVM_MR_MOVE) && (change != KVM_MR_CREATE))
387 397 return 0;
388 398 /*
@@ -939,9 +949,3 @@ int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long gpa, bool write, in
939 949 void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot)
940 950 {
941 951 }
942 -
943 - void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm,
944 - const struct kvm_memory_slot *memslot)
945 - {
946 - kvm_flush_remote_tlbs(kvm);
947 - }
modified arch/loongarch/kvm/vcpu.c
@@ -1165,10 +1165,14 @@ static int kvm_loongarch_cpucfg_set_attr(struct kvm_vcpu *vcpu,
1165 1165 return -EINVAL;
1166 1166
1167 1167 /* All vCPUs need set the same PV features */
1168 + spin_lock(&kvm->arch.pv_setting_lock);
1168 1169 if ((kvm->arch.pv_features & LOONGARCH_PV_FEAT_UPDATED)
1169 - && ((kvm->arch.pv_features & valid) != val))
1170 + && ((kvm->arch.pv_features & valid) != val)) {
1171 + spin_unlock(&kvm->arch.pv_setting_lock);
1170 1172 return -EINVAL;
1173 + }
1171 1174 kvm->arch.pv_features = val | LOONGARCH_PV_FEAT_UPDATED;
1175 + spin_unlock(&kvm->arch.pv_setting_lock);
1172 1176 return 0;
1173 1177 default:
1174 1178 return -ENXIO;
modified arch/loongarch/kvm/vm.c
@@ -76,6 +76,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
76 76 return -ENOMEM;
77 77 }
78 78 spin_lock_init(&kvm->arch.phyid_map_lock);
79 + spin_lock_init(&kvm->arch.pv_setting_lock);
79 80
80 81 kvm_init_vmcs(kvm);
81 82 kvm_vm_init_features(kvm);
modified arch/loongarch/net/bpf_jit.c
@@ -717,7 +717,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
717 717 move_reg(ctx, t1, src);
718 718 emit_zext_32(ctx, t1, true);
719 719 move_imm(ctx, dst, (ctx->user_vm_start >> 32) << 32, false);
720 - emit_insn(ctx, beq, t1, LOONGARCH_GPR_ZERO, 1);
720 + emit_insn(ctx, beq, t1, LOONGARCH_GPR_ZERO, 2);
721 721 emit_insn(ctx, or, t1, dst, t1);
722 722 move_reg(ctx, dst, t1);
723 723 break;
modified arch/mips/bcm47xx/buttons.c
@@ -523,24 +523,24 @@ bcm47xx_buttons_add(const struct bcm47xx_gpio_key *buttons, int nbuttons)
523 523
524 524 /* 1 node for gpio-keys device, 1 node for each button, 1 terminator */
525 525 const struct software_node **node_group __free(kfree) =
526 - kcalloc(1 + nbuttons + 1, sizeof(*node_group), GFP_KERNEL);
526 + kzalloc_objs(*node_group, 1 + nbuttons + 1);
527 527 if (!node_group)
528 528 return -ENOMEM;
529 529
530 530 /* 1 code property, 1 gpio property, 1 terminator */
531 531 struct property_entry *props __free(kfree) =
532 - kcalloc(nbuttons * 3, sizeof(*props), GFP_KERNEL);
532 + kzalloc_objs(*props, nbuttons * 3);
533 533 if (!props)
534 534 return -ENOMEM;
535 535
536 536 /* 1 node for gpio-keys device, 1 node for each button */
537 537 struct software_node *nodes __free(kfree) =
538 - kcalloc(1 + nbuttons, sizeof(*nodes), GFP_KERNEL);
538 + kzalloc_objs(*nodes, 1 + nbuttons);
539 539 if (!nodes)
540 540 return -ENOMEM;
541 541
542 542 struct software_node_ref_args *ref_args __free(kfree) =
543 - kcalloc(nbuttons, sizeof(*ref_args), GFP_KERNEL);
543 + kzalloc_objs(*ref_args, nbuttons);
544 544 if (!ref_args)
545 545 return -ENOMEM;
546 546
modified arch/powerpc/sysdev/xive/common.c
@@ -1134,7 +1134,7 @@ static int __init xive_init_ipis(void)
1134 1134 if (!ipi_domain)
1135 1135 goto out_free_fwnode;
1136 1136
1137 - xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids, GFP_KERNEL);
1137 + xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids);
1138 1138 if (!xive_ipis)
1139 1139 goto out_free_domain;
1140 1140
modified arch/riscv/kvm/vcpu_pmu.c
@@ -503,8 +503,8 @@ int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low
503 503 }
504 504 }
505 505
506 - einfo = kvcalloc(num_events, sizeof(*einfo),
507 - GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
506 + einfo = kvzalloc_objs(*einfo, num_events,
507 + GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
508 508 if (!einfo) {
509 509 ret = SBI_ERR_FAILURE;
510 510 goto out;
modified arch/riscv/net/bpf_jit_comp64.c
@@ -2128,7 +2128,15 @@ bool bpf_jit_supports_ptr_xchg(void)
2128 2128
2129 2129 bool bpf_jit_supports_arena(void)
2130 2130 {
2131 - return true;
2131 + /*
2132 + * The arena range tree uses kmalloc_nolock(), which needs
2133 + * cmpxchg128, provided by ZACAS on riscv.
2134 + */
2135 + #ifdef system_has_cmpxchg128
2136 + return system_has_cmpxchg128();
2137 + #else
2138 + return false;
2139 + #endif
2132 2140 }
2133 2141
2134 2142 bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena)
modified arch/s390/boot/alternative.c
@@ -45,11 +45,12 @@ static void alt_debug_modify(int type, unsigned int nr, bool clear)
45 45
46 46 static char *alt_debug_parse(int type, char *str)
47 47 {
48 - unsigned long val, endval;
48 + unsigned long val, endval, limit;
49 49 char *endp;
50 50 bool clear;
51 51 int i;
52 52
53 + limit = type == ALT_TYPE_FACILITY ? MAX_FACILITY_BIT : MAX_MFEATURE_BIT;
53 54 if (*str == ':') {
54 55 str++;
55 56 } else {
@@ -73,7 +74,7 @@ static char *alt_debug_parse(int type, char *str)
73 74 if (str == endp)
74 75 break;
75 76 str = endp;
76 - while (val <= endval) {
77 + while (val <= endval && val < limit) {
77 78 alt_debug_modify(type, val, clear);
78 79 val++;
79 80 }
modified arch/s390/boot/ipl_parm.c
@@ -23,6 +23,7 @@ struct parmarea parmarea __section(".parmarea") = {
23 23 };
24 24
25 25 char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
26 + static char command_line_buf[COMMAND_LINE_SIZE];
26 27
27 28 unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
28 29 struct ipl_parameter_block __bootdata_preserved(ipl_block);
@@ -135,31 +136,29 @@ out:
135 136
136 137 static void append_ipl_block_parm(void)
137 138 {
138 - char *parm, *delim;
139 - size_t len, rc = 0;
139 + size_t len, extra = 0;
140 + char *delim;
140 141
141 142 len = strlen(early_command_line);
142 -
143 - delim = early_command_line + len; /* '\0' character position */
144 - parm = early_command_line + len + 1; /* append right after '\0' */
143 + delim = early_command_line + len; /* '\0' character position */
145 144
146 145 switch (ipl_block.pb0_hdr.pbt) {
147 146 case IPL_PBT_CCW:
148 - rc = ipl_block_get_ascii_vmparm(
149 - parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
147 + extra = ipl_block_get_ascii_vmparm(command_line_buf, sizeof(command_line_buf), &ipl_block);
150 148 break;
151 149 case IPL_PBT_FCP:
152 150 case IPL_PBT_NVME:
153 151 case IPL_PBT_ECKD:
154 - rc = ipl_block_get_ascii_scpdata(
155 - parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
152 + extra = ipl_block_get_ascii_scpdata(command_line_buf, sizeof(command_line_buf), &ipl_block);
156 153 break;
157 154 }
158 - if (rc) {
159 - if (*parm == '=')
160 - memmove(early_command_line, parm + 1, rc);
161 - else
155 + if (extra) {
156 + if (command_line_buf[0] == '=') {
157 + memmove(early_command_line, command_line_buf + 1, extra);
158 + } else if (len < COMMAND_LINE_SIZE - 2) {
162 159 *delim = ' '; /* replace '\0' with space */
160 + sized_strscpy(delim + 1, command_line_buf, COMMAND_LINE_SIZE - len - 1);
161 + }
163 162 }
164 163 }
165 164
@@ -231,7 +230,7 @@ static void modify_fac_list(char *str)
231 230 if (str == endp)
232 231 break;
233 232 str = endp;
234 - while (val <= endval) {
233 + while (val <= endval && val < MAX_FACILITY_BIT) {
235 234 modify_facility(val, clear);
236 235 val++;
237 236 }
@@ -245,7 +244,6 @@ static void modify_fac_list(char *str)
245 244 check_cleared_facilities();
246 245 }
247 246
248 - static char command_line_buf[COMMAND_LINE_SIZE];
249 247 void parse_boot_command_line(void)
250 248 {
251 249 char *param, *val;
modified arch/s390/boot/physmem_info.c
@@ -141,7 +141,7 @@ static int tprot(unsigned long addr)
141 141
142 142 static unsigned long search_mem_end(void)
143 143 {
144 - unsigned long range = 1 << (MAX_PHYSMEM_BITS - 20); /* in 1MB blocks */
144 + unsigned long range = 1UL << (MAX_PHYSMEM_BITS - 20); /* in 1MB blocks */
145 145 unsigned long offset = 0;
146 146 unsigned long pivot;
147 147
modified arch/s390/include/asm/cpacf.h
@@ -301,6 +301,7 @@ static __always_inline void __cpacf_query(unsigned int opcode,
301 301 cpacf_mask_t *mask)
302 302 {
303 303 __cpacf_query_insn(opcode, mask, CPACF_FC_QUERY);
304 + kmsan_unpoison_memory(mask, sizeof(*mask));
304 305 }
305 306
306 307 static __always_inline int __cpacf_check_opcode(unsigned int opcode)
@@ -370,6 +371,7 @@ static __always_inline int cpacf_query_func(unsigned int opcode,
370 371 static __always_inline void __cpacf_qai(unsigned int opcode, cpacf_qai_t *qai)
371 372 {
372 373 __cpacf_query_insn(opcode, qai, CPACF_FC_QUERY_AUTH_INFO);
374 + kmsan_unpoison_memory(qai, sizeof(*qai));
373 375 }
374 376
375 377 /**
@@ -422,6 +424,7 @@ static inline int cpacf_km(unsigned long func, void *param,
422 424 [opc] "i" (CPACF_KM)
423 425 : "cc", "memory", "0", "1");
424 426
427 + kmsan_unpoison_memory(dest, src_len - s.odd);
425 428 return src_len - s.odd;
426 429 }
427 430
@@ -454,6 +457,7 @@ static inline int cpacf_kmc(unsigned long func, void *param,
454 457 [opc] "i" (CPACF_KMC)
455 458 : "cc", "memory", "0", "1");
456 459
460 + kmsan_unpoison_memory(dest, src_len - s.odd);
457 461 return src_len - s.odd;
458 462 }
459 463
@@ -587,6 +591,7 @@ static inline int cpacf_kmctr(unsigned long func, void *param, u8 *dest,
587 591 [opc] "i" (CPACF_KMCTR)
588 592 : "cc", "memory", "0", "1");
589 593
594 + kmsan_unpoison_memory(dest, src_len - s.odd);
590 595 return src_len - s.odd;
591 596 }
592 597
@@ -619,6 +624,7 @@ static inline void cpacf_prno(unsigned long func, void *param,
619 624 : [fc] "d" (func), [pba] "d" ((unsigned long)param),
620 625 [seed] "d" (s.pair), [opc] "i" (CPACF_PRNO)
621 626 : "cc", "memory", "0", "1");
627 + kmsan_unpoison_memory(dest, dest_len);
622 628 }
623 629
624 630 /**
modified arch/s390/include/asm/processor.h
@@ -46,7 +46,6 @@ struct pcpu {
46 46 unsigned long ec_mask; /* bit mask for ec_xxx functions */
47 47 unsigned long ec_clk; /* sigp timestamp for ec_xxx */
48 48 unsigned long flags; /* per CPU flags */
49 - unsigned long capacity; /* cpu capacity for scheduler */
50 49 signed char state; /* physical cpu state */
51 50 signed char polarization; /* physical polarization */
52 51 u16 address; /* physical cpu address */
modified arch/s390/include/asm/smp.h
@@ -30,7 +30,7 @@ static __always_inline unsigned int raw_smp_processor_id(void)
30 30 return cpu;
31 31 }
32 32
33 - #define arch_scale_cpu_capacity smp_cpu_get_capacity
33 + #define arch_scale_cpu_capacity topology_get_cpu_scale
34 34
35 35 extern struct mutex smp_cpu_state_mutex;
36 36 extern unsigned int smp_cpu_mt_shift;
@@ -53,9 +53,7 @@ extern void smp_save_dump_secondary_cpus(void);
53 53 extern void smp_yield_cpu(int cpu);
54 54 extern void smp_cpu_set_polarization(int cpu, int val);
55 55 extern int smp_cpu_get_polarization(int cpu);
56 - extern void smp_cpu_set_capacity(int cpu, unsigned long val);
57 56 extern void smp_set_core_capacity(int cpu, unsigned long val);
58 - extern unsigned long smp_cpu_get_capacity(int cpu);
59 57 extern int smp_cpu_get_cpu_address(int cpu);
60 58 extern void smp_fill_possible_mask(void);
61 59 extern void smp_detect_cpus(void);
modified arch/s390/kernel/diag/diag324.c
@@ -182,8 +182,7 @@ long diag324_pibbuf(unsigned long arg)
182 182 goto out;
183 183 rc = copy_to_user((void __user *)address, data->pib, data->pib->len);
184 184 rc |= put_user(data->sequence, &udata->sequence);
185 - if (rc)
186 - rc = -EFAULT;
185 + rc = rc ? -EFAULT : data->rc;
187 186 out:
188 187 mutex_unlock(&pibmutex);
189 188 return rc;
modified arch/s390/kernel/ipl.c
@@ -1157,6 +1157,8 @@ static struct attribute_group reipl_nss_attr_group = {
1157 1157
1158 1158 void set_os_info_reipl_block(void)
1159 1159 {
1160 + if (!reipl_block_actual)
1161 + return;
1160 1162 os_info_entry_add_data(OS_INFO_REIPL_BLOCK, reipl_block_actual,
1161 1163 reipl_block_actual->hdr.len);
1162 1164 }
@@ -1927,7 +1929,8 @@ static struct shutdown_action __refdata dump_action = {
1927 1929 static void dump_reipl_run(struct shutdown_trigger *trigger)
1928 1930 {
1929 1931 struct lowcore *abs_lc;
1930 - unsigned int csum;
1932 + unsigned long ipib = 0;
1933 + unsigned int csum = 0;
1931 1934
1932 1935 /*
1933 1936 * Set REIPL_CLEAR flag in os_info flags entry indicating
@@ -1943,9 +1946,12 @@ static void dump_reipl_run(struct shutdown_trigger *trigger)
1943 1946 reipl_type == IPL_TYPE_UNKNOWN)
1944 1947 os_info_flags |= OS_INFO_FLAG_REIPL_CLEAR;
1945 1948 os_info_entry_add_data(OS_INFO_FLAGS_ENTRY, &os_info_flags, sizeof(os_info_flags));
1946 - csum = (__force unsigned int)cksm(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1949 + if (reipl_block_actual) {
1950 + ipib = __pa(reipl_block_actual);
1951 + csum = (__force unsigned int)cksm(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1952 + }
1947 1953 abs_lc = get_abs_lowcore();
1948 - abs_lc->ipib = __pa(reipl_block_actual);
1954 + abs_lc->ipib = ipib;
1949 1955 abs_lc->ipib_checksum = csum;
1950 1956 put_abs_lowcore(abs_lc);
1951 1957 dump_run(trigger);
modified arch/s390/kernel/perf_pai.c
@@ -464,6 +464,7 @@ static void pai_start(struct perf_event *event, int flags,
464 464 cpump->event = event;
465 465 }
466 466 }
467 + event->hw.state &= ~PERF_HES_STOPPED;
467 468 }
468 469
469 470 static void paicrypt_start(struct perf_event *event, int flags)
@@ -510,6 +511,13 @@ static void pai_stop(struct perf_event *event, int flags)
510 511 struct pai_mapptr *mp = this_cpu_ptr(pai_root[idx].mapptr);
511 512 struct pai_map *cpump = mp->mapptr;
512 513
514 + /* Cope with multiple invocations:
515 + * 1. perf_event_throttle() --> PMU->stop()
516 + * 2. task schedules out --> PMU->stop()
517 + * Check for event already stopped.
518 + */
519 + if (event->hw.state & PERF_HES_STOPPED)
520 + return;
513 521 if (!event->attr.sample_period) { /* Counting */
514 522 pai_pmu[idx].pmu->read(event);
515 523 } else { /* Sampling */
@@ -672,9 +680,9 @@ static void pai_have_samples(int idx)
672 680 {
673 681 struct pai_mapptr *mp = this_cpu_ptr(pai_root[idx].mapptr);
674 682 struct pai_map *cpump = mp->mapptr;
675 - struct perf_event *event;
683 + struct perf_event *event, *e2;
676 684
677 - list_for_each_entry(event, &cpump->syswide_list, hw.tp_list)
685 + list_for_each_entry_safe(event, e2, &cpump->syswide_list, hw.tp_list)
678 686 pai_have_sample(event, cpump);
679 687 }
680 688
@@ -691,6 +699,17 @@ static void paicrypt_sched_task(struct perf_event_pmu_context *pmu_ctx,
691 699 pai_have_samples(PAI_PMU_CRYPTO);
692 700 }
693 701
702 + /* Prevent ioctl(fd, PERF_EVENT_IOC_PERIOD, ...) call.
703 + * It sets perf_event::event_limit to a positive value and causes
704 + * perf_event_overflow() to invoke pai_stop() call back function when
705 + * perf_event::event_limit hits zero. This is not supported because the
706 + * sample events CRYPTO_ALL and NNPA_ALL are always taken at schedule out
707 + * of a task.
708 + */
709 + static int pai_check_period(struct perf_event *event, u64 value)
710 + {
711 + return -EINVAL;
712 + }
694 713 /* ============================= paiext ====================================*/
695 714
696 715 static void paiext_event_destroy(struct perf_event *event)
@@ -804,6 +823,7 @@ static struct pmu paicrypt = {
804 823 .stop = paicrypt_stop,
805 824 .read = paicrypt_read,
806 825 .sched_task = paicrypt_sched_task,
826 + .check_period = pai_check_period,
807 827 .attr_groups = paicrypt_attr_groups
808 828 };
809 829
@@ -1015,6 +1035,7 @@ static struct pmu paiext = {
1015 1035 .stop = paiext_stop,
1016 1036 .read = paiext_read,
1017 1037 .sched_task = paiext_sched_task,
1038 + .check_period = pai_check_period,
1018 1039 .attr_groups = paiext_attr_groups,
1019 1040 };
1020 1041
@@ -1221,7 +1242,7 @@ static int __init paipmu_setup(void)
1221 1242 static int __init pai_init(void)
1222 1243 {
1223 1244 /* Setup s390dbf facility */
1224 - paidbg = debug_register("pai", 32, 256, 128);
1245 + paidbg = debug_register("pai", 1, 1, 128);
1225 1246 if (!paidbg) {
1226 1247 pr_err("Registration of s390dbf pai failed\n");
1227 1248 return -ENOMEM;
modified arch/s390/kernel/smp.c
@@ -659,23 +659,13 @@ int smp_cpu_get_polarization(int cpu)
659 659 return per_cpu(pcpu_devices, cpu).polarization;
660 660 }
661 661
662 - void smp_cpu_set_capacity(int cpu, unsigned long val)
663 - {
664 - per_cpu(pcpu_devices, cpu).capacity = val;
665 - }
666 -
667 - unsigned long smp_cpu_get_capacity(int cpu)
668 - {
669 - return per_cpu(pcpu_devices, cpu).capacity;
670 - }
671 -
672 662 void smp_set_core_capacity(int cpu, unsigned long val)
673 663 {
674 664 int i;
675 665
676 666 cpu = smp_get_base_cpu(cpu);
677 667 for (i = cpu; (i <= cpu + smp_cpu_mtid) && (i < nr_cpu_ids); i++)
678 - smp_cpu_set_capacity(i, val);
668 + topology_set_cpu_scale(i, val);
679 669 }
680 670
681 671 int smp_cpu_get_cpu_address(int cpu)
@@ -727,7 +717,7 @@ static int smp_add_core(struct sclp_core_entry *core, cpumask_t *avail,
727 717 else
728 718 pcpu->state = CPU_STATE_STANDBY;
729 719 smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
730 - smp_cpu_set_capacity(cpu, CPU_CAPACITY_HIGH);
720 + topology_set_cpu_scale(cpu, CPU_CAPACITY_HIGH);
731 721 set_cpu_present(cpu, true);
732 722 if (!early && arch_register_cpu(cpu))
733 723 set_cpu_present(cpu, false);
@@ -967,7 +957,7 @@ void __init smp_prepare_boot_cpu(void)
967 957 ipl_pcpu->state = CPU_STATE_CONFIGURED;
968 958 lc->pcpu = (unsigned long)ipl_pcpu;
969 959 smp_cpu_set_polarization(0, POLARIZATION_UNKNOWN);
970 - smp_cpu_set_capacity(0, CPU_CAPACITY_HIGH);
960 + topology_set_cpu_scale(0, CPU_CAPACITY_HIGH);
971 961 }
972 962
973 963 void __init smp_setup_processor_id(void)
modified arch/s390/kernel/topology.c
@@ -147,7 +147,7 @@ static void add_cpus_to_mask(struct topology_core *tl_core,
147 147 cpumask_set_cpu(cpu, &book->mask);
148 148 cpumask_set_cpu(cpu, &socket->mask);
149 149 smp_cpu_set_polarization(cpu, tl_core->pp);
150 - smp_cpu_set_capacity(cpu, CPU_CAPACITY_HIGH);
150 + topology_set_cpu_scale(cpu, CPU_CAPACITY_HIGH);
151 151 }
152 152 }
153 153 }
modified arch/s390/kernel/vtime.c
@@ -32,7 +32,7 @@ static atomic64_t virt_timer_elapsed;
32 32 DEFINE_PER_CPU(u64, mt_cycles[8]);
33 33 static DEFINE_PER_CPU(u64, mt_scaling_mult) = { 1 };
34 34 static DEFINE_PER_CPU(u64, mt_scaling_div) = { 1 };
35 - static DEFINE_PER_CPU(u64, mt_scaling_jiffies);
35 + static DEFINE_PER_CPU(unsigned long, mt_scaling_jiffies);
36 36
37 37 static inline void set_vtimer(u64 expires)
38 38 {
@@ -81,7 +81,7 @@ static void update_mt_scaling(void)
81 81 memcpy(cycles_old, cycles_new,
82 82 sizeof(u64) * (smp_cpu_mtid + 1));
83 83 }
84 - __this_cpu_write(mt_scaling_jiffies, jiffies_64);
84 + __this_cpu_write(mt_scaling_jiffies, jiffies);
85 85 }
86 86
87 87 static inline u64 update_tsk_timer(unsigned long *tsk_vtime, u64 new)
@@ -144,7 +144,7 @@ static int do_account_vtime(struct task_struct *tsk)
144 144 lc->system_timer += timer;
145 145
146 146 /* Update MT utilization calculation */
147 - if (smp_cpu_mtid && time_after64(jiffies_64, __this_cpu_read(mt_scaling_jiffies)))
147 + if (smp_cpu_mtid && time_after(jiffies, __this_cpu_read(mt_scaling_jiffies)))
148 148 update_mt_scaling();
149 149
150 150 /* Calculate cputime delta */
modified arch/s390/kvm/s390/s390.c
@@ -2168,7 +2168,7 @@ static int kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
2168 2168 if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
2169 2169 return -EINVAL;
2170 2170
2171 - keys = kvmalloc_array(args->count, sizeof(*keys), GFP_KERNEL_ACCOUNT);
2171 + keys = kvmalloc_objs(*keys, args->count, GFP_KERNEL_ACCOUNT);
2172 2172 if (!keys)
2173 2173 return -ENOMEM;
2174 2174
@@ -2205,7 +2205,7 @@ static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
2205 2205 if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
2206 2206 return -EINVAL;
2207 2207
2208 - keys = kvmalloc_array(args->count, sizeof(*keys), GFP_KERNEL_ACCOUNT);
2208 + keys = kvmalloc_objs(*keys, args->count, GFP_KERNEL_ACCOUNT);
2209 2209 if (!keys)
2210 2210 return -ENOMEM;
2211 2211
modified arch/s390/mm/pgalloc.c
@@ -55,63 +55,46 @@ static void __crst_table_upgrade(void *arg)
55 55
56 56 int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
57 57 {
58 - unsigned long *pgd = NULL, *p4d = NULL, *__pgd;
59 - unsigned long asce_limit = mm->context.asce_limit;
58 + unsigned long *table, *pgd;
59 + int rc, notify;
60 60
61 61 mmap_assert_write_locked(mm);
62 -
63 62 /* upgrade should only happen from 3 to 4, 3 to 5, or 4 to 5 levels */
64 - VM_BUG_ON(asce_limit < _REGION2_SIZE);
65 -
66 - if (end <= asce_limit)
67 - return 0;
68 -
69 - if (asce_limit == _REGION2_SIZE) {
70 - p4d = crst_table_alloc(mm);
71 - if (unlikely(!p4d))
72 - goto err_p4d;
73 - crst_table_init(p4d, _REGION2_ENTRY_EMPTY);
74 - pagetable_p4d_ctor(virt_to_ptdesc(p4d));
75 - }
76 - if (end > _REGION1_SIZE) {
77 - pgd = crst_table_alloc(mm);
78 - if (unlikely(!pgd))
79 - goto err_pgd;
80 - crst_table_init(pgd, _REGION1_ENTRY_EMPTY);
81 - pagetable_pgd_ctor(virt_to_ptdesc(pgd));
82 - }
83 -
84 - spin_lock_bh(&mm->page_table_lock);
85 -
86 - if (p4d) {
87 - __pgd = (unsigned long *) mm->pgd;
88 - p4d_populate(mm, (p4d_t *) p4d, (pud_t *) __pgd);
89 - mm->pgd = (pgd_t *) p4d;
90 - mm->context.asce_limit = _REGION1_SIZE;
91 - mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
92 - _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
93 - mm_inc_nr_puds(mm);
94 - }
95 - if (pgd) {
96 - __pgd = (unsigned long *) mm->pgd;
97 - pgd_populate(mm, (pgd_t *) pgd, (p4d_t *) __pgd);
98 - mm->pgd = (pgd_t *) pgd;
99 - mm->context.asce_limit = TASK_SIZE_MAX;
100 - mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
101 - _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
63 + VM_BUG_ON(mm->context.asce_limit < _REGION2_SIZE);
64 + rc = 0;
65 + notify = 0;
66 + while (mm->context.asce_limit < end) {
67 + table = crst_table_alloc(mm);
68 + if (!table) {
69 + rc = -ENOMEM;
70 + break;
71 + }
72 + spin_lock_bh(&mm->page_table_lock);
73 + pgd = (unsigned long *)mm->pgd;
74 + if (mm->context.asce_limit == _REGION2_SIZE) {
75 + crst_table_init(table, _REGION2_ENTRY_EMPTY);
76 + p4d_populate(mm, (p4d_t *)table, (pud_t *)pgd);
77 + pagetable_p4d_ctor(virt_to_ptdesc(table));
78 + mm->pgd = (pgd_t *)table;
79 + mm->context.asce_limit = _REGION1_SIZE;
80 + mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
81 + _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
82 + mm_inc_nr_puds(mm);
83 + } else {
84 + crst_table_init(table, _REGION1_ENTRY_EMPTY);
85 + pgd_populate(mm, (pgd_t *)table, (p4d_t *)pgd);
86 + pagetable_pgd_ctor(virt_to_ptdesc(table));
87 + mm->pgd = (pgd_t *)table;
88 + mm->context.asce_limit = TASK_SIZE_MAX;
89 + mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
90 + _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
91 + }
92 + notify = 1;
93 + spin_unlock_bh(&mm->page_table_lock);
102 94 }
103 -
104 - spin_unlock_bh(&mm->page_table_lock);
105 -
106 - on_each_cpu(__crst_table_upgrade, mm, 0);
107 -
108 - return 0;
109 -
110 - err_pgd:
111 - pagetable_dtor(virt_to_ptdesc(p4d));
112 - crst_table_free(mm, p4d);
113 - err_p4d:
114 - return -ENOMEM;
95 + if (notify)
96 + on_each_cpu(__crst_table_upgrade, mm, 0);
97 + return rc;
115 98 }
116 99
117 100 unsigned long *page_table_alloc_noprof(struct mm_struct *mm)
modified arch/s390/pci/pci_sysfs.c
@@ -153,6 +153,9 @@ static ssize_t report_error_write(struct file *filp, struct kobject *kobj,
153 153 if (off || (count < sizeof(*report)))
154 154 return -EINVAL;
155 155
156 + if (count < (report->length + sizeof(*report)))
157 + return -EINVAL;
158 +
156 159 ret = sclp_pci_report(report, zdev->fh, zdev->fid);
157 160
158 161 return ret ? ret : count;
modified arch/x86/kernel/itmt.c
@@ -110,18 +110,14 @@ int sched_set_itmt_support(void)
110 110 arch_debugfs_dir,
111 111 &sysctl_sched_itmt_enabled,
112 112 &dfs_sched_itmt_fops);
113 - if (IS_ERR_OR_NULL(dfs_sched_itmt)) {
113 + if (IS_ERR(dfs_sched_itmt))
114 114 dfs_sched_itmt = NULL;
115 - return -ENOMEM;
116 - }
117 115
118 116 dfs_sched_core_prio = debugfs_create_file("sched_core_priority", 0644,
119 117 arch_debugfs_dir, NULL,
120 118 &sched_core_priority_fops);
121 - if (IS_ERR_OR_NULL(dfs_sched_core_prio)) {
119 + if (IS_ERR(dfs_sched_core_prio))
122 120 dfs_sched_core_prio = NULL;
123 - return -ENOMEM;
124 - }
125 121
126 122 sched_itmt_capable = true;
127 123
modified arch/x86/net/bpf_jit_comp.c
@@ -13,6 +13,7 @@
13 13 #include <linux/bpf_verifier.h>
14 14 #include <linux/memory.h>
15 15 #include <linux/sort.h>
16 + #include <linux/execmem.h>
16 17 #include <asm/extable.h>
17 18 #include <asm/ftrace.h>
18 19 #include <asm/set_memory.h>
@@ -3818,15 +3819,16 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
3818 3819 *
3819 3820 * We cannot use kvmalloc here, because we need image to be in
3820 3821 * module memory range.
3821 - * Since it must be writable use bpf_jit_alloc_exec_rw().
3822 + * Since it must be writable use execmem_alloc(EXECMEM_MODULE_DATA)
3823 + * that returns writable memory in the module address space.
3822 3824 */
3823 - image = bpf_jit_alloc_exec_rw(PAGE_SIZE);
3825 + image = execmem_alloc(EXECMEM_MODULE_DATA, PAGE_SIZE);
3824 3826 if (!image)
3825 3827 return -ENOMEM;
3826 3828
3827 3829 ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, image,
3828 3830 m, flags, tnodes, func_addr);
3829 - bpf_jit_free_exec(image);
3831 + execmem_free(image);
3830 3832 return ret;
3831 3833 }
3832 3834
modified block/bio.c
@@ -859,6 +859,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
859 859 bio->bi_ioprio = bio_src->bi_ioprio;
860 860 bio->bi_write_hint = bio_src->bi_write_hint;
861 861 bio->bi_write_stream = bio_src->bi_write_stream;
862 + bio->bi_bvec_gap_bit = bio_src->bi_bvec_gap_bit;
862 863 bio->bi_iter = bio_src->bi_iter;
863 864 bio->bi_io_vec = bio_src->bi_io_vec;
864 865
@@ -1972,6 +1973,14 @@ struct bio *bio_split(struct bio *bio, int sectors,
1972 1973
1973 1974 bio_advance(bio, split->bi_iter.bi_size);
1974 1975
1976 + /*
1977 + * The gap bit is set when splitting to limits and only applies to the
1978 + * front bio that was split off. The remaining bio will calcualte its
1979 + * gap value when it is subsequently split to limits, so it is safe to
1980 + * re-initialize the value back to 0.
1981 + */
1982 + bio->bi_bvec_gap_bit = 0;
1983 +
1975 1984 if (bio_flagged(bio, BIO_TRACE_COMPLETION))
1976 1985 bio_set_flag(split, BIO_TRACE_COMPLETION);
1977 1986
modified block/genhd.c
@@ -447,6 +447,13 @@ static int __add_disk(struct device *parent, struct gendisk *disk,
447 447 bdev_set_flag(disk->part0, BD_HAS_SUBMIT_BIO);
448 448 }
449 449
450 + /*
451 + * We do not support partitions with zoned block devices, so do not try
452 + * to scan the partitions table.
453 + */
454 + if (blk_queue_is_zoned(disk->queue))
455 + disk->flags |= GENHD_FL_NO_PART;
456 +
450 457 /*
451 458 * If the driver provides an explicit major number it also must provide
452 459 * the number of minors numbers supported, and those will be used to
modified drivers/accel/amdxdna/aie2_message.c
@@ -994,7 +994,7 @@ int aie2_cmdlist_multi_execbuf(struct amdxdna_hwctx *hwctx,
994 994 }
995 995
996 996 ccnt = payload->command_count;
997 - if (payload_len < struct_size(payload, data, ccnt)) {
997 + if (!ccnt || payload_len < struct_size(payload, data, ccnt)) {
998 998 XDNA_DBG(xdna, "Invalid command count %d", ccnt);
999 999 return -EINVAL;
1000 1000 }
modified drivers/accel/amdxdna/amdxdna_ctx.c
@@ -183,8 +183,10 @@ int amdxdna_cmd_set_error(struct amdxdna_gem_obj *abo,
183 183 if (!abo)
184 184 return -EINVAL;
185 185 cmd = amdxdna_gem_vmap(abo);
186 - if (!cmd)
186 + if (!cmd) {
187 + amdxdna_gem_put_obj(abo);
187 188 return -ENOMEM;
189 + }
188 190 }
189 191
190 192 memset(cmd->data, 0xff, abo->mem.size - sizeof(*cmd));
modified drivers/accel/amdxdna/amdxdna_ctx.h
@@ -55,7 +55,7 @@ struct amdxdna_cmd_chain {
55 55 u32 submit_index;
56 56 u32 error_index;
57 57 u32 reserved[3];
58 - u64 data[] __counted_by(command_count);
58 + u64 data[];
59 59 };
60 60
61 61 /*
modified drivers/accel/amdxdna/amdxdna_gem.c
@@ -1246,6 +1246,9 @@ static int amdxdna_flush_bo(struct amdxdna_gem_obj *abo, u64 offset, u64 size)
1246 1246 {
1247 1247 u64 end;
1248 1248
1249 + if (is_import_bo(abo))
1250 + return -EOPNOTSUPP;
1251 +
1249 1252 if (offset >= abo->mem.size)
1250 1253 return -EINVAL;
1251 1254
@@ -1253,9 +1256,10 @@ static int amdxdna_flush_bo(struct amdxdna_gem_obj *abo, u64 offset, u64 size)
1253 1256 return -EINVAL;
1254 1257
1255 1258 size = min(abo->mem.size, end) - offset;
1256 - if (is_import_bo(abo))
1257 - drm_clflush_sg(abo->base.sgt);
1258 - else if (amdxdna_gem_vmap(abo))
1259 + if (!size)
1260 + return 0;
1261 +
1262 + if (amdxdna_gem_vmap(abo))
1259 1263 drm_clflush_virt_range(amdxdna_gem_vmap(abo) + offset, size);
1260 1264 else if (abo->base.pages)
1261 1265 drm_clflush_pages(abo->base.pages, abo->mem.size >> PAGE_SHIFT);
modified drivers/accel/ethosu/ethosu_drv.c
@@ -356,6 +356,8 @@ static int ethosu_probe(struct platform_device *pdev)
356 356 dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
357 357
358 358 ethosudev->regs = devm_platform_ioremap_resource(pdev, 0);
359 + if (IS_ERR(ethosudev->regs))
360 + return PTR_ERR(ethosudev->regs);
359 361 ethosudev->pmu_regs = ethosudev->regs;
360 362
361 363 ethosudev->num_clks = devm_clk_bulk_get_all(&pdev->dev, &ethosudev->clks);
modified drivers/accel/ethosu/ethosu_gem.c
@@ -204,7 +204,7 @@ static u64 feat_matrix_length(struct ethosu_device *edev,
204 204 struct feat_matrix *fm,
205 205 u32 x, u32 y, u32 c, bool ofm)
206 206 {
207 - u32 element_size, storage = fm->precision >> 14;
207 + u32 element_size, storage = ethosu_is_u65(edev) ? 0 : fm->precision >> 14;
208 208 int tile = 0;
209 209 u64 addr;
210 210
modified drivers/accel/ethosu/ethosu_job.c
@@ -154,6 +154,13 @@ static void ethosu_job_err_cleanup(struct ethosu_job *job)
154 154
155 155 drm_gem_object_put(job->cmd_bo);
156 156
157 + if (job->done_fence) {
158 + if (dma_fence_was_initialized(job->done_fence))
159 + dma_fence_put(job->done_fence);
160 + else
161 + dma_fence_free(job->done_fence);
162 + }
163 +
157 164 kfree(job);
158 165 }
159 166
@@ -164,7 +171,6 @@ static void ethosu_job_cleanup(struct kref *ref)
164 171
165 172 pm_runtime_put_autosuspend(job->dev->base.dev);
166 173
167 - dma_fence_put(job->done_fence);
168 174 dma_fence_put(job->inference_done_fence);
169 175
170 176 ethosu_job_err_cleanup(job);
@@ -415,7 +421,7 @@ static int ethosu_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
415 421 ejob->done_fence = kzalloc_obj(*ejob->done_fence);
416 422 if (!ejob->done_fence) {
417 423 ret = -ENOMEM;
418 - goto out_cleanup_job;
424 + goto out_put_job;
419 425 }
420 426
421 427 ret = drm_sched_job_init(&ejob->base,
modified drivers/accel/qaic/qaic_control.c
@@ -963,11 +963,13 @@ static int decode_status(struct qaic_device *qdev, void *trans, struct manage_ms
963 963
964 964 static int decode_message(struct qaic_device *qdev, struct manage_msg *user_msg,
965 965 struct wire_msg *msg, struct ioctl_resources *resources,
966 - struct qaic_user *usr)
966 + struct qaic_user *usr, bool orphaned_deactivate)
967 967 {
968 + u32 msg_hdr_count = le32_to_cpu(msg->hdr.count);
968 969 u32 msg_hdr_len = le32_to_cpu(msg->hdr.len);
969 970 struct wire_trans_hdr *trans_hdr;
970 971 u32 msg_len = 0;
972 + int trans_type;
971 973 int ret;
972 974 int i;
973 975
@@ -975,10 +977,12 @@ static int decode_message(struct qaic_device *qdev, struct manage_msg *user_msg,
975 977 msg_hdr_len > QAIC_MANAGE_MAX_MSG_LENGTH)
976 978 return -EINVAL;
977 979
978 - user_msg->len = 0;
979 - user_msg->count = le32_to_cpu(msg->hdr.count);
980 + if (user_msg) {
981 + user_msg->len = 0;
982 + user_msg->count = msg_hdr_count;
983 + }
980 984
981 - for (i = 0; i < user_msg->count; ++i) {
985 + for (i = 0; i < msg_hdr_count; ++i) {
982 986 u32 hdr_len;
983 987
984 988 if (msg_len > msg_hdr_len - sizeof(*trans_hdr))
@@ -990,7 +994,20 @@ static int decode_message(struct qaic_device *qdev, struct manage_msg *user_msg,
990 994 size_add(msg_len, hdr_len) > msg_hdr_len)
991 995 return -EINVAL;
992 996
993 - switch (le32_to_cpu(trans_hdr->type)) {
997 + trans_type = le32_to_cpu(trans_hdr->type);
998 + /*
999 + * orphaned_deactivate is the case where a deactivate response
1000 + * is received from the device after the user owning the DBC,
1001 + * and the message requesting deactivation, has gone away.
1002 + * In this case, only process QAIC_TRANS_DEACTIVATE_FROM_DEV
1003 + * transaction and skip the others.
1004 + */
1005 + if (orphaned_deactivate && trans_type != QAIC_TRANS_DEACTIVATE_FROM_DEV) {
1006 + msg_len += hdr_len;
1007 + continue;
1008 + }
1009 +
1010 + switch (trans_type) {
994 1011 case QAIC_TRANS_PASSTHROUGH_FROM_DEV:
995 1012 ret = decode_passthrough(qdev, trans_hdr, user_msg, &msg_len);
996 1013 break;
@@ -1281,7 +1298,7 @@ dma_xfer_continue:
1281 1298 goto dma_cont_failed;
1282 1299 }
1283 1300
1284 - ret = decode_message(qdev, user_msg, rsp, &resources, usr);
1301 + ret = decode_message(qdev, user_msg, rsp, &resources, usr, false);
1285 1302
1286 1303 dma_cont_failed:
1287 1304 free_dbc_buf(qdev, &resources);
@@ -1446,22 +1463,7 @@ static void resp_worker(struct work_struct *work)
1446 1463 * response to the QAIC_TRANS_TERMINATE_TO_DEV transaction,
1447 1464 * otherwise, the user can issue an soc_reset to the device.
1448 1465 */
1449 - u32 msg_count = le32_to_cpu(msg->hdr.count);
1450 - u32 msg_len = le32_to_cpu(msg->hdr.len);
1451 - u32 len = 0;
1452 - int j;
1453 -
1454 - for (j = 0; j < msg_count && len < msg_len; ++j) {
1455 - struct wire_trans_hdr *trans_hdr;
1456 -
1457 - trans_hdr = (struct wire_trans_hdr *)(msg->data + len);
1458 - if (le32_to_cpu(trans_hdr->type) == QAIC_TRANS_DEACTIVATE_FROM_DEV) {
1459 - if (decode_deactivate(qdev, trans_hdr, &len, NULL))
1460 - len += le32_to_cpu(trans_hdr->len);
1461 - } else {
1462 - len += le32_to_cpu(trans_hdr->len);
1463 - }
1464 - }
1466 + decode_message(qdev, NULL, msg, NULL, NULL, true);
1465 1467 /* request must have timed out, drop packet */
1466 1468 kfree(msg);
1467 1469 }
modified drivers/accel/rocket/rocket_job.c
@@ -196,7 +196,7 @@ static int rocket_job_push(struct rocket_job *job)
196 196 if (check_add_overflow(job->in_bo_count, job->out_bo_count, &bo_count))
197 197 return -EINVAL;
198 198
199 - bos = kvmalloc_array(bo_count, sizeof(*bos), GFP_KERNEL);
199 + bos = kvmalloc_objs(*bos, bo_count);
200 200 if (!bos)
201 201 return -ENOMEM;
202 202 memcpy(bos, job->in_bos, job->in_bo_count * sizeof(void *));
modified drivers/acpi/irq.c
@@ -486,7 +486,8 @@ static u32 acpi_add_prt_dep(acpi_handle handle)
486 486 if (ACPI_FAILURE(status))
487 487 continue;
488 488 dep_devices.count = 1;
489 - dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL);
489 + dep_devices.handles = kzalloc_objs(*dep_devices.handles,
490 + 1);
490 491 if (!dep_devices.handles) {
491 492 acpi_handle_err(handle, "failed to allocate memory\n");
492 493 continue;
@@ -499,7 +500,8 @@ static u32 acpi_add_prt_dep(acpi_handle handle)
499 500 if (!gsi_handle)
500 501 continue;
501 502 dep_devices.count = 1;
502 - dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL);
503 + dep_devices.handles = kzalloc_objs(*dep_devices.handles,
504 + 1);
503 505 if (!dep_devices.handles) {
504 506 acpi_handle_err(handle, "failed to allocate memory\n");
505 507 continue;
@@ -526,7 +528,7 @@ static u32 acpi_add_irq_dep(acpi_handle handle)
526 528 continue;
527 529
528 530 dep_devices.count = 1;
529 - dep_devices.handles = kcalloc(1, sizeof(*dep_devices.handles), GFP_KERNEL);
531 + dep_devices.handles = kzalloc_objs(*dep_devices.handles, 1);
530 532 if (!dep_devices.handles) {
531 533 acpi_handle_err(handle, "failed to allocate memory\n");
532 534 continue;
modified drivers/acpi/scan.c
@@ -28,9 +28,7 @@
28 28 #include "internal.h"
29 29 #include "sleep.h"
30 30
31 - #define ACPI_BUS_CLASS "system_bus"
32 31 #define ACPI_BUS_HID "LNXSYBUS"
33 - #define ACPI_BUS_DEVICE_NAME "System Bus"
34 32
35 33 #define INVALID_ACPI_HANDLE ((acpi_handle)ZERO_PAGE(0))
36 34
@@ -1450,8 +1448,6 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
1450 1448 acpi_object_is_system_bus(handle)) {
1451 1449 /* \_SB, \_TZ, LNXSYBUS */
1452 1450 acpi_add_id(pnp, ACPI_BUS_HID);
1453 - strscpy(pnp->device_name, ACPI_BUS_DEVICE_NAME);
1454 - strscpy(pnp->device_class, ACPI_BUS_CLASS);
1455 1451 }
1456 1452
1457 1453 break;
modified drivers/ata/ahci.c
@@ -2614,6 +2614,51 @@ static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
2614 2614 }
2615 2615 #endif
2616 2616
2617 + /*
2618 + * The Marvell 88SE6111/6121/6145 ("Thor") family stops reporting interrupts
2619 + * for a port when HOST_IRQ_STAT is cleared while PxIS still holds bits: PxIS
2620 + * keeps its content, HOST_IRQ_STAT reads back as 0, the port is never looked
2621 + * at again and the command in flight only ends in a timeout. On a 88SE6121
2622 + * this makes every SATA-2 or SATA-3 disk fail to IDENTIFY, while SATA-1 disks
2623 + * happen to win the race often enough to work.
2624 + *
2625 + * Clearing the host status before servicing the ports avoids it. Marvell's
2626 + * own driver for these chips does the same and says so ("clear global before
2627 + * channel"), and ahci_xgene handles its broken edge latch the same way. The
2628 + * price is at most one spurious interrupt per valid one, which is why this is
2629 + * not the generic behaviour - see AHCI 1.1 section 10.6.2.
2630 + *
2631 + * Link: https://bugzilla.kernel.org/show_bug.cgi?id=216094
2632 + */
2633 + static irqreturn_t ahci_mv_irq_handler(int irq, void *dev_instance)
2634 + {
2635 + struct ata_host *host = dev_instance;
2636 + struct ahci_host_priv *hpriv = host->private_data;
2637 + void __iomem *mmio = hpriv->mmio;
2638 + unsigned int rc;
2639 + u32 irq_stat, irq_masked;
2640 +
2641 + irq_stat = readl(mmio + HOST_IRQ_STAT);
2642 + if (!irq_stat)
2643 + return IRQ_NONE;
2644 +
2645 + irq_masked = irq_stat & hpriv->port_map;
2646 +
2647 + spin_lock(&host->lock);
2648 +
2649 + /*
2650 + * Use the unmasked value to clear the interrupt, as a spurious pending
2651 + * event on a dummy port might cause a screaming IRQ.
2652 + */
2653 + writel(irq_stat, mmio + HOST_IRQ_STAT);
2654 +
2655 + rc = ahci_handle_port_intr(host, irq_masked);
2656 +
2657 + spin_unlock(&host->lock);
2658 +
2659 + return IRQ_RETVAL(rc);
2660 + }
2661 +
2617 2662 static void ahci_remap_check(struct pci_dev *pdev, int bar,
2618 2663 struct ahci_host_priv *hpriv)
2619 2664 {
@@ -2917,6 +2962,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2917 2962 return -ENOMEM;
2918 2963 hpriv->flags |= (unsigned long)pi.private_data;
2919 2964
2965 + /* the Marvell "Thor" family needs HOST_IRQ_STAT cleared first */
2966 + if (board_id == board_ahci_mv)
2967 + hpriv->irq_handler = ahci_mv_irq_handler;
2968 +
2920 2969 /* MCP65 revision A1 and A2 can't do MSI */
2921 2970 if (board_id == board_ahci_mcp65 &&
2922 2971 (pdev->revision == 0xa1 || pdev->revision == 0xa2))
modified drivers/ata/libata-scsi.c
@@ -4823,28 +4823,6 @@ ata_scsi_get_phys_element_status_xlat(struct ata_queued_cmd *qc)
4823 4823 return 0;
4824 4824 }
4825 4825
4826 - static void ata_scsi_depop_ua_cap_changed_complete(struct ata_queued_cmd *qc)
4827 - {
4828 - struct scsi_cmnd *scmd = qc->scsicmd;
4829 - u8 *cdb = scmd->cmnd;
4830 - bool is_ata_passthru = cdb[0] == ATA_16 || cdb[0] == ATA_12;
4831 - bool is_success = qc->err_mask == 0;
4832 -
4833 - /*
4834 - * For successful non-passthrough commands, raise a UNIT ATTENTION with
4835 - * the additional sense code set to CAPACITY DATA HAS CHANGED to be
4836 - * raised. Note that this should be done only if the capacity has
4837 - * actually changed, which may not be the case if the element that was
4838 - * specified for depopulation was already depopulated, or we did not
4839 - * restore any removed element. But a capacity change unit attention is
4840 - * harmless, so always raise the unit attention.
4841 - */
4842 - if (is_success && !is_ata_passthru)
4843 - ata_scsi_set_sense(qc->dev, scmd, UNIT_ATTENTION,
4844 - UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ);
4845 - ata_scsi_qc_complete(qc);
4846 - }
4847 -
4848 4826 static unsigned int
4849 4827 ata_scsi_remove_element_and_truncate_xlat(struct ata_queued_cmd *qc)
4850 4828 {
@@ -4884,7 +4862,6 @@ ata_scsi_remove_element_and_truncate_xlat(struct ata_queued_cmd *qc)
4884 4862 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4885 4863
4886 4864 qc->flags |= ATA_QCFLAG_RESULT_TF;
4887 - qc->complete_fn = ata_scsi_depop_ua_cap_changed_complete;
4888 4865
4889 4866 return 0;
4890 4867 }
@@ -4937,7 +4914,6 @@ ata_scsi_restore_elements_and_rebuild_xlat(struct ata_queued_cmd *qc)
4937 4914 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
4938 4915
4939 4916 qc->flags |= ATA_QCFLAG_RESULT_TF;
4940 - qc->complete_fn = ata_scsi_depop_ua_cap_changed_complete;
4941 4917
4942 4918 return 0;
4943 4919 }
modified drivers/base/property.c
@@ -526,7 +526,7 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
526 526 if (nval == 0)
527 527 return -ENODATA;
528 528
529 - const char **values __free(kfree) = kcalloc(nval, sizeof(*values), GFP_KERNEL);
529 + const char **values __free(kfree) = kzalloc_objs(*values, nval);
530 530 if (!values)
531 531 return -ENOMEM;
532 532
modified drivers/base/test/Kconfig
@@ -17,7 +17,6 @@ config DM_KUNIT_TEST
17 17 config DRIVER_PE_KUNIT_TEST
18 18 tristate "KUnit Tests for property entry API" if !KUNIT_ALL_TESTS
19 19 depends on KUNIT
20 - select OF
21 20 default KUNIT_ALL_TESTS
22 21
23 22 config DRIVER_SWNODE_KUNIT_TEST
modified drivers/base/test/property-entry-test.c
@@ -523,6 +523,9 @@ static void pe_test_child_iteration(struct kunit *test)
523 523 struct fwnode_handle *child;
524 524 int error, i, num;
525 525
526 + if (!IS_ENABLED(CONFIG_OF))
527 + kunit_skip(test, "requires CONFIG_OF");
528 +
526 529 static const struct software_node node = { .name = "sw" };
527 530 static const struct software_node node1 = { .name = "sw-1", .parent = &node};
528 531 static const struct software_node node2 = { .name = "sw-2", .parent = &node};
modified drivers/block/drbd/drbd_nl_gen.c
@@ -656,7 +656,7 @@ static int __drbd_cfg_context_from_attrs(struct drbd_cfg_context *s,
656 656 *ret_nested_attribute_table = NULL;
657 657 if (!tla)
658 658 return -ENOMSG;
659 - ntb = kcalloc(DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR + 1, sizeof(*ntb), GFP_KERNEL);
659 + ntb = kzalloc_objs(*ntb, DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR + 1);
660 660 if (!ntb)
661 661 return -ENOMEM;
662 662 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_drbd_cfg_context_nl_policy, NULL);
@@ -714,7 +714,7 @@ static int __disk_conf_from_attrs(struct disk_conf *s,
714 714 *ret_nested_attribute_table = NULL;
715 715 if (!tla)
716 716 return -ENOMSG;
717 - ntb = kcalloc(DRBD_A_DISK_CONF_DISABLE_WRITE_SAME + 1, sizeof(*ntb), GFP_KERNEL);
717 + ntb = kzalloc_objs(*ntb, DRBD_A_DISK_CONF_DISABLE_WRITE_SAME + 1);
718 718 if (!ntb)
719 719 return -ENOMEM;
720 720 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_disk_conf_nl_policy, NULL);
@@ -871,7 +871,7 @@ static int __res_opts_from_attrs(struct res_opts *s,
871 871 *ret_nested_attribute_table = NULL;
872 872 if (!tla)
873 873 return -ENOMSG;
874 - ntb = kcalloc(DRBD_A_RES_OPTS_ON_NO_DATA + 1, sizeof(*ntb), GFP_KERNEL);
874 + ntb = kzalloc_objs(*ntb, DRBD_A_RES_OPTS_ON_NO_DATA + 1);
875 875 if (!ntb)
876 876 return -ENOMEM;
877 877 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_res_opts_nl_policy, NULL);
@@ -921,7 +921,7 @@ static int __net_conf_from_attrs(struct net_conf *s,
921 921 *ret_nested_attribute_table = NULL;
922 922 if (!tla)
923 923 return -ENOMSG;
924 - ntb = kcalloc(DRBD_A_NET_CONF_SOCK_CHECK_TIMEO + 1, sizeof(*ntb), GFP_KERNEL);
924 + ntb = kzalloc_objs(*ntb, DRBD_A_NET_CONF_SOCK_CHECK_TIMEO + 1);
925 925 if (!ntb)
926 926 return -ENOMEM;
927 927 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_net_conf_nl_policy, NULL);
@@ -1087,7 +1087,7 @@ static int __set_role_parms_from_attrs(struct set_role_parms *s,
1087 1087 *ret_nested_attribute_table = NULL;
1088 1088 if (!tla)
1089 1089 return -ENOMSG;
1090 - ntb = kcalloc(DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE + 1, sizeof(*ntb), GFP_KERNEL);
1090 + ntb = kzalloc_objs(*ntb, DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE + 1);
1091 1091 if (!ntb)
1092 1092 return -ENOMEM;
1093 1093 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_set_role_parms_nl_policy, NULL);
@@ -1133,7 +1133,7 @@ static int __resize_parms_from_attrs(struct resize_parms *s,
1133 1133 *ret_nested_attribute_table = NULL;
1134 1134 if (!tla)
1135 1135 return -ENOMSG;
1136 - ntb = kcalloc(DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE + 1, sizeof(*ntb), GFP_KERNEL);
1136 + ntb = kzalloc_objs(*ntb, DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE + 1);
1137 1137 if (!ntb)
1138 1138 return -ENOMEM;
1139 1139 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resize_parms_nl_policy, NULL);
@@ -1195,7 +1195,7 @@ static int __start_ov_parms_from_attrs(struct start_ov_parms *s,
1195 1195 *ret_nested_attribute_table = NULL;
1196 1196 if (!tla)
1197 1197 return -ENOMSG;
1198 - ntb = kcalloc(DRBD_A_START_OV_PARMS_OV_STOP_SECTOR + 1, sizeof(*ntb), GFP_KERNEL);
1198 + ntb = kzalloc_objs(*ntb, DRBD_A_START_OV_PARMS_OV_STOP_SECTOR + 1);
1199 1199 if (!ntb)
1200 1200 return -ENOMEM;
1201 1201 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_start_ov_parms_nl_policy, NULL);
@@ -1245,7 +1245,7 @@ static int __new_c_uuid_parms_from_attrs(struct new_c_uuid_parms *s,
1245 1245 *ret_nested_attribute_table = NULL;
1246 1246 if (!tla)
1247 1247 return -ENOMSG;
1248 - ntb = kcalloc(DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM + 1, sizeof(*ntb), GFP_KERNEL);
1248 + ntb = kzalloc_objs(*ntb, DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM + 1);
1249 1249 if (!ntb)
1250 1250 return -ENOMEM;
1251 1251 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_new_c_uuid_parms_nl_policy, NULL);
@@ -1291,7 +1291,7 @@ static int __disconnect_parms_from_attrs(struct disconnect_parms *s,
1291 1291 *ret_nested_attribute_table = NULL;
1292 1292 if (!tla)
1293 1293 return -ENOMSG;
1294 - ntb = kcalloc(DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT + 1, sizeof(*ntb), GFP_KERNEL);
1294 + ntb = kzalloc_objs(*ntb, DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT + 1);
1295 1295 if (!ntb)
1296 1296 return -ENOMEM;
1297 1297 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_disconnect_parms_nl_policy, NULL);
@@ -1337,7 +1337,7 @@ static int __detach_parms_from_attrs(struct detach_parms *s,
1337 1337 *ret_nested_attribute_table = NULL;
1338 1338 if (!tla)
1339 1339 return -ENOMSG;
1340 - ntb = kcalloc(DRBD_A_DETACH_PARMS_FORCE_DETACH + 1, sizeof(*ntb), GFP_KERNEL);
1340 + ntb = kzalloc_objs(*ntb, DRBD_A_DETACH_PARMS_FORCE_DETACH + 1);
1341 1341 if (!ntb)
1342 1342 return -ENOMEM;
1343 1343 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_detach_parms_nl_policy, NULL);
@@ -1383,7 +1383,7 @@ static int __resource_info_from_attrs(struct resource_info *s,
1383 1383 *ret_nested_attribute_table = NULL;
1384 1384 if (!tla)
1385 1385 return -ENOMSG;
1386 - ntb = kcalloc(DRBD_A_RESOURCE_INFO_RES_SUSP_FEN + 1, sizeof(*ntb), GFP_KERNEL);
1386 + ntb = kzalloc_objs(*ntb, DRBD_A_RESOURCE_INFO_RES_SUSP_FEN + 1);
1387 1387 if (!ntb)
1388 1388 return -ENOMEM;
1389 1389 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resource_info_nl_policy, NULL);
@@ -1441,7 +1441,7 @@ static int __device_info_from_attrs(struct device_info *s,
1441 1441 *ret_nested_attribute_table = NULL;
1442 1442 if (!tla)
1443 1443 return -ENOMSG;
1444 - ntb = kcalloc(DRBD_A_DEVICE_INFO_DEV_DISK_STATE + 1, sizeof(*ntb), GFP_KERNEL);
1444 + ntb = kzalloc_objs(*ntb, DRBD_A_DEVICE_INFO_DEV_DISK_STATE + 1);
1445 1445 if (!ntb)
1446 1446 return -ENOMEM;
1447 1447 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_device_info_nl_policy, NULL);
@@ -1487,7 +1487,7 @@ static int __connection_info_from_attrs(struct connection_info *s,
1487 1487 *ret_nested_attribute_table = NULL;
1488 1488 if (!tla)
1489 1489 return -ENOMSG;
1490 - ntb = kcalloc(DRBD_A_CONNECTION_INFO_CONN_ROLE + 1, sizeof(*ntb), GFP_KERNEL);
1490 + ntb = kzalloc_objs(*ntb, DRBD_A_CONNECTION_INFO_CONN_ROLE + 1);
1491 1491 if (!ntb)
1492 1492 return -ENOMEM;
1493 1493 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_connection_info_nl_policy, NULL);
@@ -1537,7 +1537,8 @@ static int __peer_device_info_from_attrs(struct peer_device_info *s,
1537 1537 *ret_nested_attribute_table = NULL;
1538 1538 if (!tla)
1539 1539 return -ENOMSG;
1540 - ntb = kcalloc(DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY + 1, sizeof(*ntb), GFP_KERNEL);
1540 + ntb = kzalloc_objs(*ntb,
1541 + DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY + 1);
1541 1542 if (!ntb)
1542 1543 return -ENOMEM;
1543 1544 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_peer_device_info_nl_policy, NULL);
@@ -1599,7 +1600,8 @@ static int __resource_statistics_from_attrs(struct resource_statistics *s,
1599 1600 *ret_nested_attribute_table = NULL;
1600 1601 if (!tla)
1601 1602 return -ENOMSG;
1602 - ntb = kcalloc(DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING + 1, sizeof(*ntb), GFP_KERNEL);
1603 + ntb = kzalloc_objs(*ntb,
1604 + DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING + 1);
1603 1605 if (!ntb)
1604 1606 return -ENOMEM;
1605 1607 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resource_statistics_nl_policy, NULL);
@@ -1645,7 +1647,7 @@ static int __device_statistics_from_attrs(struct device_statistics *s,
1645 1647 *ret_nested_attribute_table = NULL;
1646 1648 if (!tla)
1647 1649 return -ENOMSG;
1648 - ntb = kcalloc(DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS + 1, sizeof(*ntb), GFP_KERNEL);
1650 + ntb = kzalloc_objs(*ntb, DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS + 1);
1649 1651 if (!ntb)
1650 1652 return -ENOMEM;
1651 1653 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_device_statistics_nl_policy, NULL);
@@ -1743,7 +1745,8 @@ static int __connection_statistics_from_attrs(struct connection_statistics *s,
1743 1745 *ret_nested_attribute_table = NULL;
1744 1746 if (!tla)
1745 1747 return -ENOMSG;
1746 - ntb = kcalloc(DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED + 1, sizeof(*ntb), GFP_KERNEL);
1748 + ntb = kzalloc_objs(*ntb,
1749 + DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED + 1);
1747 1750 if (!ntb)
1748 1751 return -ENOMEM;
1749 1752 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_connection_statistics_nl_policy, NULL);
@@ -1789,7 +1792,8 @@ static int __peer_device_statistics_from_attrs(struct peer_device_statistics *s,
1789 1792 *ret_nested_attribute_table = NULL;
1790 1793 if (!tla)
1791 1794 return -ENOMSG;
1792 - ntb = kcalloc(DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS + 1, sizeof(*ntb), GFP_KERNEL);
1795 + ntb = kzalloc_objs(*ntb,
1796 + DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS + 1);
1793 1797 if (!ntb)
1794 1798 return -ENOMEM;
1795 1799 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_peer_device_statistics_nl_policy, NULL);
modified drivers/block/loop.c
@@ -458,12 +458,14 @@ static void loop_update_dio_alignment(struct loop_device *lo)
458 458 * Use the dio alignment of the file system if provided. The incomoing
459 459 * request's bio_vec is forwarded to the backing file unchanged, so its
460 460 * required memory alignment becomes the device's dma_alignment when
461 - * used for direct-io.
461 + * used for direct-io. The file system reports zeroed alignments if the
462 + * file can't be used for direct-io at all, so fall back to the block
463 + * device limits in that case.
462 464 */
463 465 if (!vfs_getattr(&file->f_path, &st, STATX_DIOALIGN, 0) &&
464 - (st.result_mask & STATX_DIOALIGN)) {
466 + (st.result_mask & STATX_DIOALIGN) && st.dio_mem_align) {
465 467 lo->lo_min_dio_size = st.dio_offset_align;
466 - lo->lo_dio_mem_align = st.dio_mem_align - 1;
468 + lo->lo_dio_mem_align = min(st.dio_mem_align - 1, PAGE_SIZE - 1);
467 469 return;
468 470 }
469 471
modified drivers/block/ublk_drv.c
@@ -2653,6 +2653,12 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
2653 2653 if (vma->vm_flags & VM_WRITE)
2654 2654 return -EPERM;
2655 2655
2656 + /*
2657 + * The per-queue command buffer is kernel-written ABI; prevent
2658 + * the daemon from upgrading to writable via mprotect().
2659 + */
2660 + vm_flags_clear(vma, VM_MAYWRITE);
2661 +
2656 2662 end = UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;
2657 2663 if (phys_off < UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)
2658 2664 return -EINVAL;
@@ -5390,7 +5396,7 @@ static int __ublk_ctrl_reg_buf(struct ublk_device *ub,
5390 5396 page_to_pfn(pages[i + 1]) == pfn + (i - start) + 1)
5391 5397 i++;
5392 5398
5393 - range = kzalloc(sizeof(*range), GFP_KERNEL);
5399 + range = kzalloc_obj(*range);
5394 5400 if (!range) {
5395 5401 ret = -ENOMEM;
5396 5402 goto unwind;
@@ -5453,7 +5459,7 @@ static int ublk_ctrl_reg_buf(struct ublk_device *ub,
5453 5459 nr_pages = buf_reg.len >> PAGE_SHIFT;
5454 5460
5455 5461 /* Pin pages before any locks (may sleep) */
5456 - pages = kvmalloc_array(nr_pages, sizeof(*pages), GFP_KERNEL);
5462 + pages = kvmalloc_objs(*pages, nr_pages);
5457 5463 if (!pages)
5458 5464 return -ENOMEM;
5459 5465
modified drivers/block/zloop.c
@@ -1042,12 +1042,14 @@ static int zloop_get_block_size(struct zloop_device *zlo,
1042 1042 * Use the dio alignment of the file system if provided. The incoming
1043 1043 * request's bio_vec is forwarded to the backing file unchanged, so its
1044 1044 * required memory alignment becomes the device's dma_alignment when
1045 - * used for direct-io.
1045 + * used for direct-io. The file system reports zeroed alignments if the
1046 + * file can't be used for direct-io at all, so fall back to the block
1047 + * device limits in that case.
1046 1048 */
1047 1049 if (!vfs_getattr(&zone->file->f_path, &st, STATX_DIOALIGN, 0) &&
1048 - (st.result_mask & STATX_DIOALIGN)) {
1050 + (st.result_mask & STATX_DIOALIGN) && st.dio_mem_align) {
1049 1051 zlo->block_size = st.dio_offset_align;
1050 - zlo->dio_mem_align = st.dio_mem_align - 1;
1052 + zlo->dio_mem_align = min(st.dio_mem_align - 1, PAGE_SIZE - 1);
1051 1053 } else if (sb_bdev) {
1052 1054 zlo->block_size = bdev_physical_block_size(sb_bdev);
1053 1055 zlo->dio_mem_align = bdev_dma_alignment(sb_bdev);
modified drivers/block/zram/backend_lz4.c
@@ -42,7 +42,7 @@ static int lz4_setup_params(struct zcomp_params *params)
42 42 if (!params->dict || !params->dict_sz)
43 43 return 0;
44 44
45 - dict_stream = kzalloc_obj(*dict_stream, GFP_KERNEL);
45 + dict_stream = kzalloc_obj(*dict_stream);
46 46 if (!dict_stream)
47 47 return -ENOMEM;
48 48
modified drivers/bluetooth/btintel.c
@@ -571,12 +571,44 @@ int btintel_version_info_tlv(struct hci_dev *hdev,
571 571 }
572 572 EXPORT_SYMBOL_GPL(btintel_version_info_tlv);
573 573
574 + static u8 btintel_version_tlv_min_len(u8 type)
575 + {
576 + switch (type) {
577 + case INTEL_TLV_CNVI_TOP:
578 + case INTEL_TLV_CNVR_TOP:
579 + case INTEL_TLV_CNVI_BT:
580 + case INTEL_TLV_CNVR_BT:
581 + case INTEL_TLV_BUILD_NUM:
582 + case INTEL_TLV_GIT_SHA1:
583 + return sizeof(u32);
584 + case INTEL_TLV_DEV_REV_ID:
585 + case INTEL_TLV_TIME_STAMP:
586 + return sizeof(u16);
587 + case INTEL_TLV_IMAGE_TYPE:
588 + case INTEL_TLV_BUILD_TYPE:
589 + case INTEL_TLV_SECURE_BOOT:
590 + case INTEL_TLV_OTP_LOCK:
591 + case INTEL_TLV_API_LOCK:
592 + case INTEL_TLV_DEBUG_LOCK:
593 + case INTEL_TLV_LIMITED_CCE:
594 + case INTEL_TLV_SBE_TYPE:
595 + return sizeof(u8);
596 + case INTEL_TLV_MIN_FW:
597 + return 3;
598 + case INTEL_TLV_OTP_BDADDR:
599 + return sizeof(bdaddr_t);
600 + default:
601 + return 0;
602 + }
603 + }
604 +
574 605 int btintel_parse_version_tlv(struct hci_dev *hdev,
575 606 struct intel_version_tlv *version,
576 607 struct sk_buff *skb)
577 608 {
578 609 /* Consume Command Complete Status field */
579 - skb_pull(skb, 1);
610 + if (!skb_pull(skb, 1))
611 + return -EINVAL;
580 612
581 613 /* Event parameters contain multiple TLVs. Read each of them
582 614 * and only keep the required data. Also, it use existing legacy
@@ -596,6 +628,9 @@ int btintel_parse_version_tlv(struct hci_dev *hdev,
596 628 if (skb->len < tlv->len + sizeof(*tlv))
597 629 return -EINVAL;
598 630
631 + if (tlv->len < btintel_version_tlv_min_len(tlv->type))
632 + return -EINVAL;
633 +
599 634 switch (tlv->type) {
600 635 case INTEL_TLV_CNVI_TOP:
601 636 version->cnvi_top = get_unaligned_le32(tlv->val);
@@ -667,7 +702,7 @@ int btintel_parse_version_tlv(struct hci_dev *hdev,
667 702 break;
668 703 case INTEL_TLV_FW_ID:
669 704 snprintf(version->fw_id, sizeof(version->fw_id),
670 - "%s", tlv->val);
705 + "%.*s", tlv->len, tlv->val);
671 706 break;
672 707 default:
673 708 /* Ignore rest of information */
@@ -686,6 +721,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,
686 721 {
687 722 struct sk_buff *skb;
688 723 const u8 param[1] = { 0xFF };
724 + int err;
689 725
690 726 if (!version)
691 727 return -EINVAL;
@@ -704,10 +740,10 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,
704 740 return -EIO;
705 741 }
706 742
707 - btintel_parse_version_tlv(hdev, version, skb);
743 + err = btintel_parse_version_tlv(hdev, version, skb);
708 744
709 745 kfree_skb(skb);
710 - return 0;
746 + return err;
711 747 }
712 748
713 749 /* ------- REGMAP IBT SUPPORT ------- */
modified drivers/bluetooth/btintel_pcie.c
@@ -1696,6 +1696,9 @@ static irqreturn_t btintel_pcie_irq_msix_handler(int irq, void *dev_id)
1696 1696
1697 1697 if (unlikely(!(intr_fh | intr_hw))) {
1698 1698 /* Ignore interrupt, inta == 0 */
1699 + bt_warn_ratelimited("Bluetooth: btintel_pcie: Received spurious interrupt\n");
1700 + btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_MSIX_AUTOMASK_ST,
1701 + BIT(entry->entry));
1699 1702 return IRQ_NONE;
1700 1703 }
1701 1704
modified drivers/bluetooth/hci_mrvl.c
@@ -307,9 +307,8 @@ static int mrvl_load_firmware(struct hci_dev *hdev, const char *name)
307 307 err = wait_on_bit_timeout(&mrvl->flags, STATE_FW_REQ_PENDING,
308 308 TASK_INTERRUPTIBLE,
309 309 msecs_to_jiffies(2000));
310 - if (err == 1) {
310 + if (err == -EINTR) {
311 311 bt_dev_err(hdev, "Firmware load interrupted");
312 - err = -EINTR;
313 312 break;
314 313 } else if (err) {
315 314 bt_dev_err(hdev, "Firmware request timeout");
modified drivers/char/virtio_console.c
@@ -426,7 +426,7 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size
426 426 * Allocate buffer and the sg list. The sg list array is allocated
427 427 * directly after the port_buffer struct.
428 428 */
429 - buf = kmalloc_flex(*buf, sg, pages);
429 + buf = kmalloc_flex(*buf, sg, pages, gfp);
430 430 if (!buf)
431 431 goto fail;
432 432
modified drivers/clk/ti/composite.c
@@ -248,7 +248,7 @@ int __init ti_clk_add_component(struct device_node *node, struct clk_hw *hw,
248 248 return -EINVAL;
249 249 }
250 250
251 - parent_data = kcalloc(num_parents, sizeof(*parent_data), GFP_KERNEL);
251 + parent_data = kzalloc_objs(*parent_data, num_parents);
252 252 if (!parent_data)
253 253 return -ENOMEM;
254 254
modified drivers/clk/ti/mux.c
@@ -181,7 +181,7 @@ static void of_mux_clk_setup(struct device_node *node)
181 181 pr_err("mux-clock %pOFn must have parents\n", node);
182 182 return;
183 183 }
184 - parent_data = kcalloc(num_parents, sizeof(*parent_data), GFP_KERNEL);
184 + parent_data = kzalloc_objs(*parent_data, num_parents);
185 185 if (!parent_data)
186 186 return;
187 187
modified drivers/cpufreq/amd-pstate.c
@@ -1624,7 +1624,7 @@ static struct freq_attr **get_freq_attrs(void)
1624 1624 /* amd_pstate_{max_freq, lowest_nonlinear_freq, highest_perf} should always be visible */
1625 1625 BUG_ON(!count);
1626 1626
1627 - attrs = kcalloc(count + 1, sizeof(struct freq_attr *), GFP_KERNEL);
1627 + attrs = kzalloc_objs(struct freq_attr *, count + 1);
1628 1628 if (!attrs)
1629 1629 return ERR_PTR(-ENOMEM);
1630 1630
modified drivers/cpuidle/cpuidle-psci.c
@@ -16,7 +16,7 @@
16 16 #include <linux/kernel.h>
17 17 #include <linux/module.h>
18 18 #include <linux/of.h>
19 - #include <linux/device/faux.h>
19 + #include <linux/platform_device.h>
20 20 #include <linux/psci.h>
21 21 #include <linux/pm_domain.h>
22 22 #include <linux/pm_runtime.h>
@@ -428,14 +428,14 @@ deinit:
428 428 * to register cpuidle driver then rollback to cancel all CPUs
429 429 * registration.
430 430 */
431 - static int psci_cpuidle_probe(struct faux_device *fdev)
431 + static int psci_cpuidle_probe(struct platform_device *pdev)
432 432 {
433 433 int cpu, ret;
434 434 struct cpuidle_driver *drv;
435 435 struct cpuidle_device *dev;
436 436
437 437 for_each_present_cpu(cpu) {
438 - ret = psci_idle_init_cpu(&fdev->dev, cpu);
438 + ret = psci_idle_init_cpu(&pdev->dev, cpu);
439 439 if (ret)
440 440 goto out_fail;
441 441 }
@@ -455,36 +455,26 @@ out_fail:
455 455 return ret;
456 456 }
457 457
458 - static struct faux_device_ops psci_cpuidle_ops = {
458 + static struct platform_driver psci_cpuidle_driver = {
459 459 .probe = psci_cpuidle_probe,
460 + .driver = {
461 + .name = "psci-cpuidle",
462 + },
460 463 };
461 464
462 - static bool __init dt_idle_state_present(void)
463 - {
464 - struct device_node *cpu_node __free(device_node) =
465 - of_cpu_device_node_get(cpumask_first(cpu_possible_mask));
466 - if (!cpu_node)
467 - return false;
468 -
469 - struct device_node *state_node __free(device_node) =
470 - of_get_cpu_state_node(cpu_node, 0);
471 - if (!state_node)
472 - return false;
473 -
474 - return !!of_match_node(psci_idle_state_match, state_node);
475 - }
476 -
477 465 static int __init psci_idle_init(void)
478 466 {
479 - struct faux_device *fdev;
467 + struct platform_device *pdev;
468 + int ret;
480 469
481 - if (!dt_idle_state_present())
482 - return 0;
470 + ret = platform_driver_register(&psci_cpuidle_driver);
471 + if (ret)
472 + return ret;
483 473
484 - fdev = faux_device_create("psci-cpuidle", NULL, &psci_cpuidle_ops);
485 - if (!fdev) {
486 - pr_err("Failed to create psci-cpuidle device\n");
487 - return -ENODEV;
474 + pdev = platform_device_register_simple("psci-cpuidle", -1, NULL, 0);
475 + if (IS_ERR(pdev)) {
476 + platform_driver_unregister(&psci_cpuidle_driver);
477 + return PTR_ERR(pdev);
488 478 }
489 479
490 480 return 0;
modified drivers/cpuidle/dt_idle_genpd.c
@@ -99,7 +99,7 @@ struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np,
99 99 if (!pd)
100 100 goto out;
101 101
102 - pd->name = kasprintf(GFP_KERNEL, "%pOF", np);
102 + pd->name = kstrdup(kbasename(of_node_full_name(np)), GFP_KERNEL);
103 103 if (!pd->name)
104 104 goto free_pd;
105 105
@@ -112,7 +112,6 @@ struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np,
112 112 goto free_name;
113 113
114 114 pd->free_states = pd_free_states;
115 - pd->name = kbasename(pd->name);
116 115 pd->states = states;
117 116 pd->state_count = state_count;
118 117
modified drivers/crypto/inside-secure/eip93/eip93-common.c
@@ -533,7 +533,7 @@ int eip93_send_req(struct crypto_async_request *async,
533 533
534 534 memcpy(iv, reqiv, rctx->ivsize);
535 535
536 - rctx->sa_state = kzalloc(sizeof(*rctx->sa_state), GFP_KERNEL);
536 + rctx->sa_state = kzalloc_obj(*rctx->sa_state);
537 537 if (!rctx->sa_state)
538 538 return -ENOMEM;
539 539
@@ -561,8 +561,7 @@ int eip93_send_req(struct crypto_async_request *async,
561 561 iv[3] = 0xffffffff;
562 562 crypto_inc((u8 *)iv, AES_BLOCK_SIZE);
563 563
564 - rctx->sa_state_ctr = kzalloc(sizeof(*rctx->sa_state_ctr),
565 - GFP_KERNEL);
564 + rctx->sa_state_ctr = kzalloc_obj(*rctx->sa_state_ctr);
566 565 if (!rctx->sa_state_ctr) {
567 566 err = -ENOMEM;
568 567 goto free_sa_state;
modified drivers/crypto/intel/qat/qat_common/qat_comp_algs.c
@@ -59,8 +59,7 @@ static void *qat_zstd_alloc_scratch(void)
59 59 if (!scratch->literals)
60 60 goto error;
61 61
62 - scratch->out_seqs = kvcalloc(QAT_MAX_SEQUENCES, sizeof(ZSTD_Sequence),
63 - GFP_KERNEL);
62 + scratch->out_seqs = kvzalloc_objs(ZSTD_Sequence, QAT_MAX_SEQUENCES);
64 63 if (!scratch->out_seqs)
65 64 goto error;
66 65
modified drivers/crypto/ti/dthev2-aes.c
@@ -387,7 +387,7 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
387 387 src_nents++;
388 388 dst_nents++;
389 389
390 - src = kmalloc_array(src_nents, sizeof(*src), GFP_ATOMIC);
390 + src = kmalloc_objs(*src, src_nents, GFP_ATOMIC);
391 391 if (!src) {
392 392 ret = -ENOMEM;
393 393 goto aes_ctr_src_alloc_err;
@@ -399,7 +399,7 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq)
399 399 sg_set_buf(sg, pad_buf, pad_size);
400 400
401 401 if (diff_dst) {
402 - dst = kmalloc_array(dst_nents, sizeof(*dst), GFP_ATOMIC);
402 + dst = kmalloc_objs(*dst, dst_nents, GFP_ATOMIC);
403 403 if (!dst) {
404 404 ret = -ENOMEM;
405 405 goto aes_ctr_dst_alloc_err;
@@ -624,7 +624,7 @@ static struct scatterlist *dthe_aead_prep_aad(struct scatterlist *sg,
624 624 if (assoclen % AES_BLOCK_SIZE)
625 625 aad_nents++;
626 626
627 - aad_sg = kmalloc_array(aad_nents, sizeof(struct scatterlist), GFP_ATOMIC);
627 + aad_sg = kmalloc_objs(struct scatterlist, aad_nents, GFP_ATOMIC);
628 628 if (!aad_sg)
629 629 return ERR_PTR(-ENOMEM);
630 630
@@ -680,7 +680,7 @@ static struct scatterlist *dthe_aead_prep_crypt(struct scatterlist *sg,
680 680 if (cryptlen % AES_BLOCK_SIZE)
681 681 crypt_nents++;
682 682
683 - crypt_sg = kmalloc_array(crypt_nents, sizeof(struct scatterlist), GFP_ATOMIC);
683 + crypt_sg = kmalloc_objs(struct scatterlist, crypt_nents, GFP_ATOMIC);
684 684 if (!crypt_sg) {
685 685 err = -ENOMEM;
686 686 goto dthe_aead_prep_crypt_mem_err;
modified drivers/devfreq/hisi_uncore_freq.c
@@ -474,7 +474,7 @@ static int hisi_uncore_mark_related_cpus(struct hisi_uncore_freq *uncore,
474 474 return -EINVAL;
475 475
476 476 len = rc;
477 - u32 *num __free(kfree) = kcalloc(len, sizeof(*num), GFP_KERNEL);
477 + u32 *num __free(kfree) = kzalloc_objs(*num, len);
478 478 if (!num)
479 479 return -ENOMEM;
480 480
modified drivers/dma-buf/dma-buf.c
@@ -803,6 +803,26 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags)
803 803 }
804 804 EXPORT_SYMBOL_NS_GPL(dma_buf_fd, "DMA_BUF");
805 805
806 + /**
807 + * dma_buf_fd_install - install a reserved fd for a dma-buf
808 + * @dmabuf: [in] pointer to dma_buf
809 + * @fd: [in] fd reserved with get_unused_fd_flags()
810 + *
811 + * Publishes a previously reserved fd into the caller's fd table.
812 + * Must only be called after all fallible work (e.g. copy_to_user)
813 + * has succeeded, as it cannot be undone safely once called.
814 + *
815 + * The caller is responsible for having emitted the trace event
816 + * (via dma_buf_fd() or get_unused_fd_flags() + this function)
817 + * before calling this.
818 + */
819 + void dma_buf_fd_install(struct dma_buf *dmabuf, int fd)
820 + {
821 + DMA_BUF_TRACE(trace_dma_buf_fd, dmabuf, fd);
822 + fd_install(fd, dmabuf->file);
823 + }
824 + EXPORT_SYMBOL_NS_GPL(dma_buf_fd_install, "DMA_BUF");
825 +
806 826 /**
807 827 * dma_buf_get - returns the struct dma_buf related to an fd
808 828 * @fd: [in] fd associated with the struct dma_buf to be returned
modified drivers/dma-buf/dma-heap.c
@@ -56,33 +56,6 @@ MODULE_PARM_DESC(mem_accounting,
56 56 "Enable cgroup-based memory accounting for dma-buf heap allocations (default=false).");
57 57 EXPORT_SYMBOL_NS_GPL(mem_accounting, "DMA_BUF_HEAP");
58 58
59 - static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
60 - u32 fd_flags,
61 - u64 heap_flags)
62 - {
63 - struct dma_buf *dmabuf;
64 - int fd;
65 -
66 - /*
67 - * Allocations from all heaps have to begin
68 - * and end on page boundaries.
69 - */
70 - len = PAGE_ALIGN(len);
71 - if (!len)
72 - return -EINVAL;
73 -
74 - dmabuf = heap->ops->allocate(heap, len, fd_flags, heap_flags);
75 - if (IS_ERR(dmabuf))
76 - return PTR_ERR(dmabuf);
77 -
78 - fd = dma_buf_fd(dmabuf, fd_flags);
79 - if (fd < 0) {
80 - dma_buf_put(dmabuf);
81 - /* just return, as put will call release and that will free */
82 - }
83 - return fd;
84 - }
85 -
86 59 static int dma_heap_open(struct inode *inode, struct file *file)
87 60 {
88 61 struct dma_heap *heap;
@@ -100,30 +73,42 @@ static int dma_heap_open(struct inode *inode, struct file *file)
100 73 return 0;
101 74 }
102 75
103 - static long dma_heap_ioctl_allocate(struct file *file, void *data)
76 + static struct dma_buf *dma_heap_ioctl_allocate(struct file *file, void *data)
104 77 {
105 78 struct dma_heap_allocation_data *heap_allocation = data;
106 79 struct dma_heap *heap = file->private_data;
80 + struct dma_buf *dmabuf;
107 81 int fd;
82 + size_t len;
108 83
109 84 if (heap_allocation->fd)
110 - return -EINVAL;
85 + return ERR_PTR(-EINVAL);
111 86
112 87 if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS)
113 - return -EINVAL;
88 + return ERR_PTR(-EINVAL);
114 89
115 90 if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
116 - return -EINVAL;
91 + return ERR_PTR(-EINVAL);
92 +
93 + len = PAGE_ALIGN(heap_allocation->len);
94 + if (!len)
95 + return ERR_PTR(-EINVAL);
96 +
97 + dmabuf = heap->ops->allocate(heap, len, heap_allocation->fd_flags,
98 + heap_allocation->heap_flags);
117 99
118 - fd = dma_heap_buffer_alloc(heap, heap_allocation->len,
119 - heap_allocation->fd_flags,
120 - heap_allocation->heap_flags);
121 - if (fd < 0)
122 - return fd;
100 + if (IS_ERR(dmabuf))
101 + return dmabuf;
102 +
103 + fd = get_unused_fd_flags(heap_allocation->fd_flags);
104 + if (fd < 0) {
105 + dma_buf_put(dmabuf);
106 + return ERR_PTR(fd);
107 + }
123 108
124 109 heap_allocation->fd = fd;
125 110
126 - return 0;
111 + return dmabuf;
127 112 }
128 113
129 114 static unsigned int dma_heap_ioctl_cmds[] = {
@@ -139,6 +124,8 @@ static long dma_heap_ioctl(struct file *file, unsigned int ucmd,
139 124 unsigned int in_size, out_size, drv_size, ksize;
140 125 int nr = _IOC_NR(ucmd);
141 126 int ret = 0;
127 + int fd;
128 + struct dma_buf *dmabuf;
142 129
143 130 if (nr >= ARRAY_SIZE(dma_heap_ioctl_cmds))
144 131 return -EINVAL;
@@ -175,15 +162,28 @@ static long dma_heap_ioctl(struct file *file, unsigned int ucmd,
175 162
176 163 switch (kcmd) {
177 164 case DMA_HEAP_IOCTL_ALLOC:
178 - ret = dma_heap_ioctl_allocate(file, kdata);
165 + dmabuf = dma_heap_ioctl_allocate(file, kdata);
166 +
167 + if (IS_ERR(dmabuf)) {
168 + ret = PTR_ERR(dmabuf);
169 + break;
170 + }
171 +
172 + fd = ((struct dma_heap_allocation_data *)kdata)->fd;
173 + if (copy_to_user((void __user *)arg, kdata, out_size) != 0) {
174 + put_unused_fd(fd);
175 + dma_buf_put(dmabuf);
176 + ret = -EFAULT;
177 + } else {
178 + dma_buf_fd_install(dmabuf, fd);
179 + }
180 +
179 181 break;
180 182 default:
181 183 ret = -ENOTTY;
182 184 goto err;
183 185 }
184 186
185 - if (copy_to_user((void __user *)arg, kdata, out_size) != 0)
186 - ret = -EFAULT;
187 187 err:
188 188 if (kdata != stack_kdata)
189 189 kfree(kdata);
modified drivers/dma-buf/st-dma-fence.c
@@ -27,7 +27,7 @@ static struct dma_fence *mock_fence(void)
27 27 {
28 28 struct dma_fence *f;
29 29
30 - f = kmalloc(sizeof(*f), GFP_KERNEL);
30 + f = kmalloc_obj(*f);
31 31 if (!f)
32 32 return NULL;
33 33
modified drivers/dma-buf/udmabuf.c
@@ -359,7 +359,7 @@ static long udmabuf_create(struct miscdevice *device,
359 359 long ret = -EINVAL;
360 360 u32 i, flags;
361 361
362 - ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
362 + ubuf = kzalloc_obj(*ubuf);
363 363 if (!ubuf)
364 364 return -ENOMEM;
365 365
@@ -387,7 +387,7 @@ static long udmabuf_create(struct miscdevice *device,
387 387 if (ret)
388 388 goto err;
389 389
390 - folios = kvmalloc_array(max_nr_folios, sizeof(*folios), GFP_KERNEL);
390 + folios = kvmalloc_objs(*folios, max_nr_folios);
391 391 if (!folios) {
392 392 ret = -ENOMEM;
393 393 goto err;
modified drivers/dma/switchtec_dma.c
@@ -1056,7 +1056,7 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev,
1056 1056 int se_buf_len, irq, rc;
1057 1057 struct dma_chan *chan;
1058 1058
1059 - swdma_chan = kzalloc_obj(*swdma_chan, GFP_KERNEL);
1059 + swdma_chan = kzalloc_obj(*swdma_chan);
1060 1060 if (!swdma_chan)
1061 1061 return -ENOMEM;
1062 1062
@@ -1162,8 +1162,7 @@ static int switchtec_dma_chans_enumerate(struct switchtec_dma_dev *swdma_dev,
1162 1162 struct dma_device *dma = &swdma_dev->dma_dev;
1163 1163 int base, cnt, rc, i;
1164 1164
1165 - swdma_dev->swdma_chans = kcalloc(chan_cnt, sizeof(*swdma_dev->swdma_chans),
1166 - GFP_KERNEL);
1165 + swdma_dev->swdma_chans = kzalloc_objs(*swdma_dev->swdma_chans, chan_cnt);
1167 1166
1168 1167 if (!swdma_dev->swdma_chans)
1169 1168 return -ENOMEM;
@@ -1222,7 +1221,7 @@ static int switchtec_dma_create(struct pci_dev *pdev)
1222 1221 /*
1223 1222 * Create the switchtec dma device
1224 1223 */
1225 - swdma_dev = kzalloc_obj(*swdma_dev, GFP_KERNEL);
1224 + swdma_dev = kzalloc_obj(*swdma_dev);
1226 1225 if (!swdma_dev)
1227 1226 return -ENOMEM;
1228 1227
modified drivers/edac/al_mc_edac.c
@@ -302,12 +302,8 @@ static int al_mc_edac_probe(struct platform_device *pdev)
302 302 IRQF_SHARED,
303 303 pdev->name,
304 304 pdev);
305 - if (ret != 0) {
306 - dev_err(&pdev->dev,
307 - "failed to request UE IRQ %d (%d)\n",
308 - al_mc->irq_ue, ret);
305 + if (ret != 0)
309 306 return ret;
310 - }
311 307 }
312 308
313 309 if (al_mc->irq_ce > 0) {
@@ -317,12 +313,8 @@ static int al_mc_edac_probe(struct platform_device *pdev)
317 313 IRQF_SHARED,
318 314 pdev->name,
319 315 pdev);
320 - if (ret != 0) {
321 - dev_err(&pdev->dev,
322 - "failed to request CE IRQ %d (%d)\n",
323 - al_mc->irq_ce, ret);
316 + if (ret != 0)
324 317 return ret;
325 - }
326 318 }
327 319
328 320 return 0;
modified drivers/edac/altera_edac.c
@@ -1507,6 +1507,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1507 1507 int edac_idx, rc;
1508 1508 struct device_node *np;
1509 1509 const struct edac_device_prv_data *prv = &a10_sdmmceccb_data;
1510 + bool is_s10 = device->edac->is_s10;
1510 1511
1511 1512 rc = altr_check_ecc_deps(device);
1512 1513 if (rc)
@@ -1548,15 +1549,14 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1548 1549
1549 1550 /*
1550 1551 * Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly
1551 - *
1552 - * FIXME: Instead of ifdefs with different architectures the driver
1553 - * should properly use compatibles.
1554 1552 */
1555 - #ifdef CONFIG_64BIT
1556 - altdev->sb_irq = irq_of_parse_and_map(np, 1);
1557 - #else
1558 - altdev->sb_irq = irq_of_parse_and_map(np, 2);
1559 - #endif
1553 +
1554 + /* Using compatibles to determine the IRQ Index */
1555 + if (is_s10)
1556 + altdev->sb_irq = irq_of_parse_and_map(np, 1);
1557 + else
1558 + altdev->sb_irq = irq_of_parse_and_map(np, 2);
1559 +
1560 1560 if (!altdev->sb_irq) {
1561 1561 edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB SBIRQ alloc\n");
1562 1562 rc = -ENODEV;
@@ -1570,29 +1570,28 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1570 1570 goto err_release_group_1;
1571 1571 }
1572 1572
1573 - #ifdef CONFIG_64BIT
1574 - /* Use IRQ to determine SError origin instead of assigning IRQ */
1575 - rc = of_property_read_u32_index(np, "interrupts", 1, &altdev->db_irq);
1576 - if (rc) {
1577 - edac_printk(KERN_ERR, EDAC_DEVICE,
1578 - "Error PortB DBIRQ alloc\n");
1579 - goto err_release_group_1;
1580 - }
1581 - #else
1582 - altdev->db_irq = irq_of_parse_and_map(np, 3);
1583 - if (!altdev->db_irq) {
1584 - edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB DBIRQ alloc\n");
1585 - rc = -ENODEV;
1586 - goto err_release_group_1;
1587 - }
1588 - rc = devm_request_irq(&altdev->ddev, altdev->db_irq,
1589 - prv->ecc_irq_handler, IRQF_TRIGGER_HIGH,
1590 - ecc_name, altdev);
1591 - if (rc) {
1592 - edac_printk(KERN_ERR, EDAC_DEVICE, "PortB DBERR IRQ error\n");
1593 - goto err_release_group_1;
1573 + if (is_s10) {
1574 + /* Use IRQ to determine SError origin instead of assigning IRQ */
1575 + rc = of_property_read_u32_index(np, "interrupts", 1, &altdev->db_irq);
1576 + if (rc) {
1577 + edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB DBIRQ alloc\n");
1578 + goto err_release_group_1;
1579 + }
1580 + } else {
1581 + altdev->db_irq = irq_of_parse_and_map(np, 3);
1582 + if (!altdev->db_irq) {
1583 + edac_printk(KERN_ERR, EDAC_DEVICE, "Error PortB DBIRQ alloc\n");
1584 + rc = -ENODEV;
1585 + goto err_release_group_1;
1586 + }
1587 + rc = devm_request_irq(&altdev->ddev, altdev->db_irq,
1588 + prv->ecc_irq_handler, IRQF_TRIGGER_HIGH,
1589 + ecc_name, altdev);
1590 + if (rc) {
1591 + edac_printk(KERN_ERR, EDAC_DEVICE, "PortB DBERR IRQ error\n");
1592 + goto err_release_group_1;
1593 + }
1594 1594 }
1595 - #endif
1596 1595
1597 1596 rc = edac_device_add_device(dci);
1598 1597 if (rc) {
@@ -1974,29 +1973,29 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
1974 1973 goto err_release_group1;
1975 1974 }
1976 1975
1977 - #ifdef CONFIG_64BIT
1978 - /* Use IRQ to determine SError origin instead of assigning IRQ */
1979 - rc = of_property_read_u32_index(np, "interrupts", 0, &altdev->db_irq);
1980 - if (rc) {
1981 - edac_printk(KERN_ERR, EDAC_DEVICE,
1982 - "Unable to parse DB IRQ index\n");
1983 - goto err_release_group1;
1984 - }
1985 - #else
1986 - altdev->db_irq = irq_of_parse_and_map(np, 1);
1987 - if (!altdev->db_irq) {
1988 - edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating DBIRQ\n");
1989 - rc = -ENODEV;
1990 - goto err_release_group1;
1991 - }
1992 - rc = devm_request_irq(edac->dev, altdev->db_irq, prv->ecc_irq_handler,
1993 - IRQF_TRIGGER_HIGH,
1994 - ecc_name, altdev);
1995 - if (rc) {
1996 - edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n");
1997 - goto err_release_group1;
1976 + if (edac->is_s10) {
1977 + /* Use IRQ to determine SError origin instead of assigning IRQ */
1978 + rc = of_property_read_u32_index(np, "interrupts", 0, &altdev->db_irq);
1979 + if (rc) {
1980 + edac_printk(KERN_ERR, EDAC_DEVICE,
1981 + "Unable to parse DB IRQ index\n");
1982 + goto err_release_group1;
1983 + }
1984 + } else {
1985 + altdev->db_irq = irq_of_parse_and_map(np, 1);
1986 + if (!altdev->db_irq) {
1987 + edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating DBIRQ\n");
1988 + rc = -ENODEV;
1989 + goto err_release_group1;
1990 + }
1991 + rc = devm_request_irq(edac->dev, altdev->db_irq, prv->ecc_irq_handler,
1992 + IRQF_TRIGGER_HIGH,
1993 + ecc_name, altdev);
1994 + if (rc) {
1995 + edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n");
1996 + goto err_release_group1;
1997 + }
1998 1998 }
1999 - #endif
2000 1999
2001 2000 rc = edac_device_add_device(dci);
2002 2001 if (rc) {
@@ -2059,7 +2058,6 @@ static const struct irq_domain_ops a10_eccmgr_ic_ops = {
2059 2058 /************** Stratix 10 EDAC Double Bit Error Handler ************/
2060 2059 #define to_a10edac(p, m) container_of(p, struct altr_arria10_edac, m)
2061 2060
2062 - #ifdef CONFIG_64BIT
2063 2061 /* panic routine issues reboot on non-zero panic_timeout */
2064 2062 extern int panic_timeout;
2065 2063
@@ -2106,7 +2104,6 @@ static int s10_edac_dberr_handler(struct notifier_block *this,
2106 2104
2107 2105 return NOTIFY_DONE;
2108 2106 }
2109 - #endif
2110 2107
2111 2108 /****************** Arria 10 EDAC Probe Function *********************/
2112 2109 static int altr_edac_a10_probe(struct platform_device *pdev)
@@ -2122,6 +2119,8 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
2122 2119 platform_set_drvdata(pdev, edac);
2123 2120 INIT_LIST_HEAD(&edac->a10_ecc_devices);
2124 2121
2122 + edac->is_s10 = !!device_get_match_data(&pdev->dev);
2123 +
2125 2124 edac->ecc_mgr_map =
2126 2125 altr_sysmgr_regmap_lookup_by_phandle(pdev->dev.of_node,
2127 2126 "altr,sysmgr-syscon");
@@ -2153,8 +2152,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
2153 2152 irq_set_chained_handler_and_data(edac->sb_irq,
2154 2153 altr_edac_a10_irq_handler,
2155 2154 edac);
2156 -
2157 - #ifdef CONFIG_64BIT
2155 + if (edac->is_s10)
2158 2156 {
2159 2157 int dberror, err_addr;
2160 2158
@@ -2177,15 +2175,14 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
2177 2175 regmap_write(edac->ecc_mgr_map,
2178 2176 S10_SYSMGR_UE_ADDR_OFST, 0);
2179 2177 }
2180 - }
2181 - #else
2182 - edac->db_irq = platform_get_irq(pdev, 1);
2183 - if (edac->db_irq < 0)
2184 - return edac->db_irq;
2178 + } else {
2179 + edac->db_irq = platform_get_irq(pdev, 1);
2180 + if (edac->db_irq < 0)
2181 + return edac->db_irq;
2185 2182
2186 - irq_set_chained_handler_and_data(edac->db_irq,
2187 - altr_edac_a10_irq_handler, edac);
2188 - #endif
2183 + irq_set_chained_handler_and_data(edac->db_irq,
2184 + altr_edac_a10_irq_handler, edac);
2185 + }
2189 2186
2190 2187 for_each_child_of_node(pdev->dev.of_node, child) {
2191 2188 if (!of_device_is_available(child))
@@ -2207,7 +2204,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
2207 2204
2208 2205 static const struct of_device_id altr_edac_a10_of_match[] = {
2209 2206 { .compatible = "altr,socfpga-a10-ecc-manager" },
2210 - { .compatible = "altr,socfpga-s10-ecc-manager" },
2207 + { .compatible = "altr,socfpga-s10-ecc-manager", .data = (void *)1 },
2211 2208 {},
2212 2209 };
2213 2210 MODULE_DEVICE_TABLE(of, altr_edac_a10_of_match);
modified drivers/edac/altera_edac.h
@@ -394,6 +394,7 @@ struct altr_arria10_edac {
394 394 struct irq_chip irq_chip;
395 395 struct list_head a10_ecc_devices;
396 396 struct notifier_block panic_notifier;
397 + bool is_s10;
397 398 };
398 399
399 400 #endif /* #ifndef _ALTERA_EDAC_H */
modified drivers/edac/amd64_edac.c
@@ -4173,6 +4173,8 @@ static int __init amd64_edac_init(void)
4173 4173 goto err_pci;
4174 4174 }
4175 4175
4176 + request_module_nowait("amd_atl");
4177 +
4176 4178 /* register stuff with EDAC MCE */
4177 4179 if (boot_cpu_data.x86 >= 0x17) {
4178 4180 amd_register_ecc_decoder(decode_umc_error);
modified drivers/edac/aspeed_edac.c
@@ -214,10 +214,8 @@ static int config_irq(void *ctx, struct platform_device *pdev)
214 214
215 215 rc = devm_request_irq(&pdev->dev, irq, mcr_isr, IRQF_TRIGGER_HIGH,
216 216 DRV_NAME, ctx);
217 - if (rc) {
218 - dev_err(&pdev->dev, "unable to request irq %d\n", irq);
217 + if (rc)
219 218 return rc;
220 - }
221 219
222 220 /* enable interrupts */
223 221 regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
modified drivers/edac/debugfs.c
@@ -1,50 +1,9 @@
1 1 // SPDX-License-Identifier: GPL-2.0-only
2 2
3 - #include <linux/string_choices.h>
4 -
5 3 #include "edac_module.h"
6 4
7 5 static struct dentry *edac_debugfs;
8 6
9 - static ssize_t edac_fake_inject_write(struct file *file,
10 - const char __user *data,
11 - size_t count, loff_t *ppos)
12 - {
13 - struct device *dev = file->private_data;
14 - struct mem_ctl_info *mci = to_mci(dev);
15 - static enum hw_event_mc_err_type type;
16 - u16 errcount = mci->fake_inject_count;
17 -
18 - if (!errcount)
19 - errcount = 1;
20 -
21 - type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED
22 - : HW_EVENT_ERR_CORRECTED;
23 -
24 - printk(KERN_DEBUG
25 - "Generating %d %s fake error%s to %d.%d.%d to test core handling. NOTE: this won't test the driver-specific decoding logic.\n",
26 - errcount,
27 - (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE",
28 - str_plural(errcount),
29 - mci->fake_inject_layer[0],
30 - mci->fake_inject_layer[1],
31 - mci->fake_inject_layer[2]
32 - );
33 - edac_mc_handle_error(type, mci, errcount, 0, 0, 0,
34 - mci->fake_inject_layer[0],
35 - mci->fake_inject_layer[1],
36 - mci->fake_inject_layer[2],
37 - "FAKE ERROR", "for EDAC testing only");
38 -
39 - return count;
40 - }
41 -
42 - static const struct file_operations debug_fake_inject_fops = {
43 - .open = simple_open,
44 - .write = edac_fake_inject_write,
45 - .llseek = generic_file_llseek,
46 - };
47 -
48 7 void __init edac_debugfs_init(void)
49 8 {
50 9 edac_debugfs = debugfs_create_dir("edac", NULL);
@@ -57,29 +16,7 @@ void edac_debugfs_exit(void)
57 16
58 17 void edac_create_debugfs_nodes(struct mem_ctl_info *mci)
59 18 {
60 - struct dentry *parent;
61 - char name[80];
62 - int i;
63 -
64 - parent = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
65 -
66 - for (i = 0; i < mci->n_layers; i++) {
67 - sprintf(name, "fake_inject_%s",
68 - edac_layer_name[mci->layers[i].type]);
69 - debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent,
70 - &mci->fake_inject_layer[i]);
71 - }
72 -
73 - debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent,
74 - &mci->fake_inject_ue);
75 -
76 - debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent,
77 - &mci->fake_inject_count);
78 -
79 - debugfs_create_file("fake_inject", S_IWUSR, parent, &mci->dev,
80 - &debug_fake_inject_fops);
81 -
82 - mci->debugfs = parent;
19 + mci->debugfs = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
83 20 }
84 21
85 22 /* Create a toplevel dir under EDAC's debugfs hierarchy */
modified drivers/edac/edac_device.c
@@ -342,14 +342,10 @@ static void edac_device_workq_teardown(struct edac_device_ctl_info *edac_dev)
342 342 }
343 343
344 344 /*
345 - * edac_device_reset_delay_period
346 - *
347 - * need to stop any outstanding workq queued up at this time
348 - * because we will be resetting the sleep time.
349 - * Then restart the workq on the new delay
345 + * Stop any outstanding workq queued up at this time because sleep time will
346 + * be reset. Then restart the workq on the new delay.
350 347 */
351 - void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
352 - unsigned long msec)
348 + void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, unsigned int msec)
353 349 {
354 350 edac_dev->poll_msec = msec;
355 351 edac_dev->delay = msecs_to_jiffies(msec);
modified drivers/edac/edac_device_sysfs.c
@@ -84,18 +84,23 @@ static ssize_t edac_device_ctl_poll_msec_show(struct edac_device_ctl_info
84 84 return sprintf(data, "%u\n", ctl_info->poll_msec);
85 85 }
86 86
87 - static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info
88 - *ctl_info, const char *data,
89 - size_t count)
87 + static ssize_t edac_device_ctl_poll_msec_store(struct edac_device_ctl_info *ctl_info,
88 + const char *data, size_t count)
90 89 {
91 - unsigned long value;
90 + unsigned int value;
91 + int ret;
92 92
93 - /* get the value and enforce that it is non-zero, must be at least
94 - * one millisecond for the delay period, between scans
95 - * Then cancel last outstanding delay for the work request
96 - * and set a new one.
93 + /*
94 + * Get the value, make sure it is non-zero, must be at least one millisecond
95 + * for the delay period between scans.
97 96 */
98 - value = simple_strtoul(data, NULL, 0);
97 + ret = kstrtouint(data, 0, &value);
98 + if (ret < 0)
99 + return ret;
100 +
101 + if (value < 1)
102 + return -EINVAL;
103 +
99 104 edac_device_reset_delay_period(ctl_info, value);
100 105
101 106 return count;
modified drivers/edac/edac_mc_sysfs.c
@@ -129,7 +129,7 @@ static ssize_t dimmdev_location_show(struct device *dev,
129 129 ssize_t count;
130 130
131 131 count = edac_dimm_info_location(dimm, data, PAGE_SIZE);
132 - count += scnprintf(data + count, PAGE_SIZE - count, "\n");
132 + count += sysfs_emit_at(data, count, "\n");
133 133
134 134 return count;
135 135 }
modified drivers/edac/edac_module.h
@@ -52,8 +52,7 @@ bool edac_queue_work(struct delayed_work *work, unsigned long delay);
52 52 bool edac_stop_work(struct delayed_work *work);
53 53 bool edac_mod_work(struct delayed_work *work, unsigned long delay);
54 54
55 - extern void edac_device_reset_delay_period(struct edac_device_ctl_info
56 - *edac_dev, unsigned long msec);
55 + extern void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev, unsigned int msec);
57 56 extern void edac_mc_reset_delay_period(unsigned long value);
58 57
59 58 /*
modified drivers/edac/highbank_mc_edac.c
@@ -235,10 +235,8 @@ static int highbank_mc_probe(struct platform_device *pdev)
235 235 irq = platform_get_irq(pdev, 0);
236 236 res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
237 237 0, dev_name(&pdev->dev), mci);
238 - if (res < 0) {
239 - dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
238 + if (res < 0)
240 239 goto err2;
241 - }
242 240
243 241 devres_close_group(&pdev->dev, NULL);
244 242 return 0;
modified drivers/edac/ie31200_edac.c
@@ -416,7 +416,23 @@ static void populate_dimm_info(struct dimm_data *dd, u32 addr_decode, int dimm,
416 416 {
417 417 dd->size = field_get(cfg->reg_mad_dimm_size_mask[dimm], addr_decode) * cfg->reg_mad_dimm_size_granularity;
418 418 dd->ranks = field_get(cfg->reg_mad_dimm_rank_mask[dimm], addr_decode) + 1;
419 - dd->dtype = field_get(cfg->reg_mad_dimm_width_mask[dimm], addr_decode) + DEV_X8;
419 +
420 + switch (field_get(cfg->reg_mad_dimm_width_mask[dimm], addr_decode)) {
421 + case 0:
422 + dd->dtype = DEV_X8;
423 + break;
424 + case 1:
425 + dd->dtype = DEV_X16;
426 + break;
427 + case 2:
428 + dd->dtype = DEV_X32;
429 + break;
430 + case 3:
431 + dd->dtype = DEV_X64;
432 + break;
433 + default:
434 + dd->dtype = DEV_UNKNOWN;
435 + }
420 436 }
421 437
422 438 static void ie31200_get_dimm_config(struct mem_ctl_info *mci, void __iomem *window,
modified drivers/edac/igen6_edac.c
@@ -42,7 +42,8 @@
42 42
43 43 #define GET_BITFIELD(v, lo, hi) (((v) & GENMASK_ULL(hi, lo)) >> (lo))
44 44
45 - #define NUM_IMC 2 /* Max memory controllers */
45 + /* Probing upper bound, not a hardware capability limit. */
46 + #define MAX_IMC_TO_PROBE 8
46 47 #define NUM_CHANNELS 2 /* Max channels */
47 48 #define NUM_DIMMS 2 /* Max DIMMs per channel */
48 49
@@ -122,6 +123,43 @@
122 123 #define MEM_SLICE_HASH_MASK(v) (GET_BITFIELD(v, 6, 19) << 6)
123 124 #define MEM_SLICE_HASH_LSB_MASK_BIT(v) GET_BITFIELD(v, 24, 26)
124 125
126 + /*
127 + * A slice represents a portion of memory space participating in an
128 + * interleave relationship within the memory hierarchy.
129 + *
130 + * It can represent in different levels such as:
131 + *
132 + * - a pair of memory controllers
133 + * - a memory controller
134 + * - a memory channel
135 + * - a memory sub-channel / DIMM
136 + *
137 + * +--------+
138 + * | |
139 + * | Zone 1 |
140 + * | |
141 + * +--------+ +--------+
142 + * | | | |
143 + * | | | |
144 + * | Zone 0 | | Zone 0 |
145 + * | | | |
146 + * | | | |
147 + * +--------+ +--------+
148 + *
149 + * Slice L Slice S
150 + *
151 + * Memory space is divided into:
152 + *
153 + * - Zone 0 : Interleaved region
154 + * - Zone 1 : Non-interleaved region (upper part of the large slice).
155 + */
156 + struct slice {
157 + /* Slice address. */
158 + u64 addr;
159 + /* Slice that @addr belongs to. */
160 + int id;
161 + };
162 +
125 163 struct igen6_imc {
126 164 int mc;
127 165 struct mem_ctl_info *mci;
@@ -175,8 +213,6 @@ static struct res_config {
175 213 /* Set imc->dimm_{l_size,s_size,l_map}[chan]. */
176 214 void (*set_dimm_params)(struct igen6_imc *imc, int chan);
177 215 bool (*ibecc_available)(struct pci_dev *pdev);
178 - /* Extract error address logged in IBECC */
179 - u64 (*err_addr)(u64 ecclog);
180 216 /* Convert error address logged in IBECC to system physical address */
181 217 u64 (*err_addr_to_sys_addr)(u64 eaddr, int mc);
182 218 /* Convert error address logged in IBECC to integrated memory controller address */
@@ -184,11 +220,11 @@ static struct res_config {
184 220 } *res_cfg;
185 221
186 222 static struct igen6_pvt {
187 - struct igen6_imc imc[NUM_IMC];
188 223 void __iomem *memss_pma_cr;
189 224 u64 ms_hash;
190 225 u64 ms_s_size;
191 226 int ms_l_map;
227 + struct igen6_imc imc[];
192 228 } *igen6_pvt;
193 229
194 230 /* The top of low usable DRAM */
@@ -225,7 +261,8 @@ static char ecclog_buf[ECCLOG_POOL_SIZE];
225 261 static struct irq_work ecclog_irq_work;
226 262 static struct work_struct ecclog_work;
227 263
228 - /* Compute die IDs for Elkhart Lake with IBECC */
264 + /* SoC compute die IDs with IBECC capability. */
265 + /* Elkhart Lake */
229 266 #define DID_EHL_SKU5 0x4514
230 267 #define DID_EHL_SKU6 0x4528
231 268 #define DID_EHL_SKU7 0x452a
@@ -238,22 +275,22 @@ static struct work_struct ecclog_work;
238 275 #define DID_EHL_SKU14 0x4534
239 276 #define DID_EHL_SKU15 0x4536
240 277
241 - /* Compute die IDs for ICL-NNPI with IBECC */
278 + /* ICL-NNPI */
242 279 #define DID_ICL_SKU8 0x4581
243 280 #define DID_ICL_SKU10 0x4585
244 281 #define DID_ICL_SKU11 0x4589
245 282 #define DID_ICL_SKU12 0x458d
246 283
247 - /* Compute die IDs for Tiger Lake with IBECC */
284 + /* Tiger Lake */
248 285 #define DID_TGL_SKU 0x9a14
249 286
250 - /* Compute die IDs for Alder Lake with IBECC */
287 + /* Alder Lake */
251 288 #define DID_ADL_SKU1 0x4601
252 289 #define DID_ADL_SKU2 0x4602
253 290 #define DID_ADL_SKU3 0x4621
254 291 #define DID_ADL_SKU4 0x4641
255 292
256 - /* Compute die IDs for Alder Lake-N with IBECC */
293 + /* Alder Lake-N */
257 294 #define DID_ADL_N_SKU1 0x4614
258 295 #define DID_ADL_N_SKU2 0x4617
259 296 #define DID_ADL_N_SKU3 0x461b
@@ -267,38 +304,38 @@ static struct work_struct ecclog_work;
267 304 #define DID_ADL_N_SKU11 0x467c
268 305 #define DID_ADL_N_SKU12 0x4632
269 306
270 - /* Compute die IDs for Arizona Beach with IBECC */
307 + /* Arizona Beach */
271 308 #define DID_AZB_SKU1 0x4676
272 309
273 - /* Compute did IDs for Amston Lake with IBECC */
310 + /* Amston Lake */
274 311 #define DID_ASL_SKU1 0x464a
275 312 #define DID_ASL_SKU2 0x4646
276 313 #define DID_ASL_SKU3 0x4652
277 314
278 - /* Compute die IDs for Raptor Lake-P with IBECC */
315 + /* Raptor Lake-P */
279 316 #define DID_RPL_P_SKU1 0xa706
280 317 #define DID_RPL_P_SKU2 0xa707
281 318 #define DID_RPL_P_SKU3 0xa708
282 319 #define DID_RPL_P_SKU4 0xa716
283 320 #define DID_RPL_P_SKU5 0xa718
284 321
285 - /* Compute die IDs for Meteor Lake-PS with IBECC */
322 + /* Meteor Lake-PS */
286 323 #define DID_MTL_PS_SKU1 0x7d21
287 324 #define DID_MTL_PS_SKU2 0x7d22
288 325 #define DID_MTL_PS_SKU3 0x7d23
289 326 #define DID_MTL_PS_SKU4 0x7d24
290 327
291 - /* Compute die IDs for Meteor Lake-P with IBECC */
328 + /* Meteor Lake-P */
292 329 #define DID_MTL_P_SKU1 0x7d01
293 330 #define DID_MTL_P_SKU2 0x7d02
294 331 #define DID_MTL_P_SKU3 0x7d14
295 332
296 - /* Compute die IDs for Arrow Lake-UH with IBECC */
333 + /* Arrow Lake-UH */
297 334 #define DID_ARL_UH_SKU1 0x7d06
298 335 #define DID_ARL_UH_SKU2 0x7d20
299 336 #define DID_ARL_UH_SKU3 0x7d30
300 337
301 - /* Compute die IDs for Panther Lake-H with IBECC */
338 + /* Panther Lake-H */
302 339 #define DID_PTL_H_SKU1 0xb000
303 340 #define DID_PTL_H_SKU2 0xb001
304 341 #define DID_PTL_H_SKU3 0xb002
@@ -314,15 +351,114 @@ static struct work_struct ecclog_work;
314 351 #define DID_PTL_H_SKU13 0xb02a
315 352 #define DID_PTL_H_SKU14 0xb00a
316 353
317 - /* Compute die IDs for Wildcat Lake with IBECC */
354 + /* Starfire */
355 + #define DID_STF_SKU1 0xb02b
356 +
357 + /* Wildcat Lake */
318 358 #define DID_WCL_SKU1 0xfd00
319 359
320 - /* Compute die IDs for Nova Lake-H/HX with IBECC */
360 + /* Nova Lake-H/HX */
321 361 #define DID_NVL_H_SKU1 0xd701
322 362 #define DID_NVL_H_SKU2 0xd702
323 363 #define DID_NVL_H_SKU3 0xd704
324 364 #define DID_NVL_H_SKU4 0xd705
325 365
366 + /* Remove the interleave bit and shift upper part down to fill gap. */
367 + static u64 squeeze_addr(u64 addr, int intlv_bit)
368 + {
369 + u64 slice_addr;
370 +
371 + slice_addr = GET_BITFIELD(addr, intlv_bit + 1, 63) << intlv_bit;
372 + slice_addr |= GET_BITFIELD(addr, 0, intlv_bit - 1);
373 +
374 + return slice_addr;
375 + }
376 +
377 + /* Shift the upper bits up and insert a zero at the @intlv_bit bit position. */
378 + static u64 inflate_addr(u64 addr, int intlv_bit)
379 + {
380 + u64 inflated_addr;
381 +
382 + /* Insert a zero at @intlv_bit position. */
383 + inflated_addr = GET_BITFIELD(addr, intlv_bit, 63) << (intlv_bit + 1);
384 + inflated_addr |= GET_BITFIELD(addr, 0, intlv_bit - 1);
385 +
386 + return inflated_addr;
387 + }
388 +
389 + static u64 compute_hash(u64 addr, u64 hash_mask, u64 hash_base, int intlv_bit)
390 + {
391 + u64 hash_addr;
392 + int i;
393 +
394 + /*
395 + * In hash mode, @intlv_bit is the lowest selected bit of @addr
396 + * to be XORed. While @mask may or may not include this @intlv_bit,
397 + * we enforce that @mask includes @intlv_bit to ensure @intlv_bit is
398 + * XORed exactly once.
399 + */
400 + hash_mask |= BIT_ULL(intlv_bit);
401 + hash_addr = addr & hash_mask;
402 +
403 + for (i = 6; i < 20; i++)
404 + hash_base ^= (hash_addr >> i) & 1;
405 +
406 + return hash_base;
407 + }
408 +
409 + /*
410 + * Converts a higher-level address (system / IMC / channel) into a lower-level
411 + * slice address and identifier.
412 + */
413 + static void translate_to_lower_level(u64 addr, u64 hash_mask, u64 hash_base,
414 + int intlv_bit, u64 s_size, int l_map,
415 + struct slice *slice)
416 + {
417 + /* In non-interleave zone. */
418 + if (addr >= 2 * s_size) {
419 + slice->addr = addr - s_size;
420 + slice->id = l_map;
421 + return;
422 + }
423 +
424 + /* In interleave zone. */
425 + slice->addr = squeeze_addr(addr, intlv_bit);
426 +
427 + /* Non-hash mode. */
428 + if (!hash_mask) {
429 + slice->id = GET_BITFIELD(addr, intlv_bit, intlv_bit);
430 + return;
431 + }
432 +
433 + /* Hash mode. */
434 + slice->id = compute_hash(addr, hash_mask, hash_base, intlv_bit);
435 + }
436 +
437 + /* Reconstruct address for upper memory hierarchy level. */
438 + static u64 translate_to_upper_level(u64 addr, u64 hash_mask, u64 hash_base,
439 + int intlv_bit, u64 s_size)
440 + {
441 + u64 inflated_addr, hash_val;
442 +
443 + /* In non-interleave zone. */
444 + if (addr >= s_size)
445 + return addr + s_size;
446 +
447 + /*
448 + * In interleave zone.
449 + *
450 + * Insert a zero at @intlv_bit position.
451 + */
452 + inflated_addr = inflate_addr(addr, intlv_bit);
453 +
454 + /*
455 + * Reconstruct the removed interleave bit and use it to replace
456 + * the zero at @intlv_bit position.
457 + */
458 + hash_val = compute_hash(inflated_addr, hash_mask, hash_base, intlv_bit);
459 + return inflated_addr | (hash_val << intlv_bit);
460 + }
461 +
326 462 static int get_mchbar(struct pci_dev *pdev, u64 *mchbar)
327 463 {
328 464 union {
@@ -354,6 +490,46 @@ static int get_mchbar(struct pci_dev *pdev, u64 *mchbar)
354 490 return 0;
355 491 }
356 492
493 + /* Check whether the memory controller is absent. */
494 + static bool imc_absent(void __iomem *window)
495 + {
496 + return readl(window + MAD_INTER_CHANNEL_OFFSET) == ~0;
497 + }
498 +
499 + /* Return MMIO base address of the memory controller if it's present, otherwise return NULL. */
500 + static void __iomem *map_imc_window(u64 mchbar, int pmc)
501 + {
502 + void __iomem *window;
503 +
504 + window = ioremap(mchbar + pmc * MCHBAR_SIZE, MCHBAR_SIZE);
505 + if (!window)
506 + return NULL;
507 +
508 + if (imc_absent(window)) {
509 + iounmap(window);
510 + return NULL;
511 + }
512 +
513 + return window;
514 + }
515 +
516 + /* Return the number of present memory controllers. */
517 + static int get_imc_num(u64 mchbar)
518 + {
519 + void __iomem *window;
520 + int lmc, pmc;
521 +
522 + for (lmc = 0, pmc = 0; pmc < MAX_IMC_TO_PROBE; pmc++) {
523 + window = map_imc_window(mchbar, pmc);
524 + if (window) {
525 + iounmap(window);
526 + lmc++;
527 + }
528 + }
529 +
530 + return lmc;
531 + }
532 +
357 533 static bool ehl_ibecc_available(struct pci_dev *pdev)
358 534 {
359 535 u32 v;
@@ -450,21 +626,9 @@ static u64 mem_addr_to_sys_addr(u64 maddr)
450 626 return maddr;
451 627 }
452 628
453 - static u64 mem_slice_hash(u64 addr, u64 mask, u64 hash_init, int intlv_bit)
454 - {
455 - u64 hash_addr = addr & mask, hash = hash_init;
456 - u64 intlv = (addr >> intlv_bit) & 1;
457 - int i;
458 -
459 - for (i = 6; i < 20; i++)
460 - hash ^= (hash_addr >> i) & 1;
461 -
462 - return hash ^ intlv;
463 - }
464 -
465 629 static u64 tgl_err_addr_to_mem_addr(u64 eaddr, int mc)
466 630 {
467 - u64 maddr, hash, mask, ms_s_size;
631 + u64 mask, ms_s_size;
468 632 int intlv_bit;
469 633 u32 ms_hash;
470 634
@@ -477,12 +641,7 @@ static u64 tgl_err_addr_to_mem_addr(u64 eaddr, int mc)
477 641 mask = MEM_SLICE_HASH_MASK(ms_hash);
478 642 intlv_bit = MEM_SLICE_HASH_LSB_MASK_BIT(ms_hash) + 6;
479 643
480 - maddr = GET_BITFIELD(eaddr, intlv_bit, 63) << (intlv_bit + 1) |
481 - GET_BITFIELD(eaddr, 0, intlv_bit - 1);
482 -
483 - hash = mem_slice_hash(maddr, mask, mc, intlv_bit);
484 -
485 - return maddr | (hash << intlv_bit);
644 + return translate_to_upper_level(eaddr, mask, mc, intlv_bit, ms_s_size);
486 645 }
487 646
488 647 static u64 tgl_err_addr_to_sys_addr(u64 eaddr, int mc)
@@ -504,8 +663,9 @@ static u64 adl_err_addr_to_sys_addr(u64 eaddr, int mc)
504 663
505 664 static u64 adl_err_addr_to_imc_addr(u64 eaddr, int mc)
506 665 {
507 - u64 imc_addr, ms_s_size = igen6_pvt->ms_s_size;
666 + u64 ms_s_size = igen6_pvt->ms_s_size;
508 667 struct igen6_imc *imc = &igen6_pvt->imc[mc];
668 + struct slice slice;
509 669 int intlv_bit;
510 670 u32 mc_hash;
511 671
@@ -516,15 +676,8 @@ static u64 adl_err_addr_to_imc_addr(u64 eaddr, int mc)
516 676
517 677 intlv_bit = MAC_MC_HASH_LSB(mc_hash) + 6;
518 678
519 - imc_addr = GET_BITFIELD(eaddr, intlv_bit + 1, 63) << intlv_bit |
520 - GET_BITFIELD(eaddr, 0, intlv_bit - 1);
521 -
522 - return imc_addr;
523 - }
524 -
525 - static u64 rpl_p_err_addr(u64 ecclog)
526 - {
527 - return field_get(res_cfg->reg_eccerrlog_addr_mask, ecclog);
679 + translate_to_lower_level(eaddr, 0, 0, intlv_bit, ms_s_size, 0, &slice);
680 + return slice.addr;
528 681 }
529 682
530 683 static enum mem_type ptl_h_get_mem_type(struct igen6_imc *imc)
@@ -686,6 +839,7 @@ static struct res_config tgl_cfg = {
686 839 .err_addr_to_imc_addr = tgl_err_addr_to_imc_addr,
687 840 };
688 841
842 + /* Shared by Alder Lake, Alder Lake-N, Arizona Beach, Amston Lake, and Raptor Lake-P */
689 843 static struct res_config adl_cfg = {
690 844 .machine_check = true,
691 845 .num_imc = 2,
@@ -701,37 +855,6 @@ static struct res_config adl_cfg = {
701 855 .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
702 856 };
703 857
704 - static struct res_config adl_n_cfg = {
705 - .machine_check = true,
706 - .num_imc = 1,
707 - .reg_mchbar_mask = GENMASK_ULL(41, 17),
708 - .reg_tom_mask = GENMASK_ULL(41, 20),
709 - .reg_touud_mask = GENMASK_ULL(41, 20),
710 - .reg_eccerrlog_addr_mask = GENMASK_ULL(45, 5),
711 - .imc_base = 0xd800,
712 - .ibecc_base = 0xd400,
713 - .ibecc_error_log_offset = 0x68,
714 - .ibecc_available = tgl_ibecc_available,
715 - .err_addr_to_sys_addr = adl_err_addr_to_sys_addr,
716 - .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
717 - };
718 -
719 - static struct res_config rpl_p_cfg = {
720 - .machine_check = true,
721 - .num_imc = 2,
722 - .reg_mchbar_mask = GENMASK_ULL(41, 17),
723 - .reg_tom_mask = GENMASK_ULL(41, 20),
724 - .reg_touud_mask = GENMASK_ULL(41, 20),
725 - .reg_eccerrlog_addr_mask = GENMASK_ULL(45, 5),
726 - .imc_base = 0xd800,
727 - .ibecc_base = 0xd400,
728 - .ibecc_error_log_offset = 0x68,
729 - .ibecc_available = tgl_ibecc_available,
730 - .err_addr = rpl_p_err_addr,
731 - .err_addr_to_sys_addr = adl_err_addr_to_sys_addr,
732 - .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
733 - };
734 -
735 858 static struct res_config mtl_ps_cfg = {
736 859 .machine_check = true,
737 860 .num_imc = 2,
@@ -749,6 +872,7 @@ static struct res_config mtl_ps_cfg = {
749 872 .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
750 873 };
751 874
875 + /* Shared by Meteor Lake-P, Arrow Lake-UH, and Wildcat Lake */
752 876 static struct res_config mtl_p_cfg = {
753 877 .machine_check = true,
754 878 .num_imc = 2,
@@ -764,6 +888,7 @@ static struct res_config mtl_p_cfg = {
764 888 .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
765 889 };
766 890
891 + /* Shared by Panther Lake-H and Starfire */
767 892 static struct res_config ptl_h_cfg = {
768 893 .machine_check = true,
769 894 .num_imc = 2,
@@ -794,21 +919,6 @@ static struct res_config ptl_h_cfg = {
794 919 .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
795 920 };
796 921
797 - static struct res_config wcl_cfg = {
798 - .machine_check = true,
799 - .num_imc = 1,
800 - .reg_mchbar_mask = GENMASK_ULL(41, 17),
801 - .reg_tom_mask = GENMASK_ULL(41, 20),
802 - .reg_touud_mask = GENMASK_ULL(41, 20),
803 - .reg_eccerrlog_addr_mask = GENMASK_ULL(38, 5),
804 - .imc_base = 0xd800,
805 - .ibecc_base = 0xd400,
806 - .ibecc_error_log_offset = 0x170,
807 - .ibecc_available = mtl_p_ibecc_available,
808 - .err_addr_to_sys_addr = adl_err_addr_to_sys_addr,
809 - .err_addr_to_imc_addr = adl_err_addr_to_imc_addr,
810 - };
811 -
812 922 static struct res_config nvl_h_cfg = {
813 923 .machine_check = true,
814 924 .num_imc = 2,
@@ -861,27 +971,27 @@ static struct pci_device_id igen6_pci_tbl[] = {
861 971 { PCI_VDEVICE(INTEL, DID_ADL_SKU2), .driver_data = (kernel_ulong_t)&adl_cfg },
862 972 { PCI_VDEVICE(INTEL, DID_ADL_SKU3), .driver_data = (kernel_ulong_t)&adl_cfg },
863 973 { PCI_VDEVICE(INTEL, DID_ADL_SKU4), .driver_data = (kernel_ulong_t)&adl_cfg },
864 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU1), .driver_data = (kernel_ulong_t)&adl_n_cfg },
865 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU2), .driver_data = (kernel_ulong_t)&adl_n_cfg },
866 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU3), .driver_data = (kernel_ulong_t)&adl_n_cfg },
867 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU4), .driver_data = (kernel_ulong_t)&adl_n_cfg },
868 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU5), .driver_data = (kernel_ulong_t)&adl_n_cfg },
869 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU6), .driver_data = (kernel_ulong_t)&adl_n_cfg },
870 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU7), .driver_data = (kernel_ulong_t)&adl_n_cfg },
871 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU8), .driver_data = (kernel_ulong_t)&adl_n_cfg },
872 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU9), .driver_data = (kernel_ulong_t)&adl_n_cfg },
873 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU10), .driver_data = (kernel_ulong_t)&adl_n_cfg },
874 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU11), .driver_data = (kernel_ulong_t)&adl_n_cfg },
875 - { PCI_VDEVICE(INTEL, DID_ADL_N_SKU12), .driver_data = (kernel_ulong_t)&adl_n_cfg },
876 - { PCI_VDEVICE(INTEL, DID_AZB_SKU1), .driver_data = (kernel_ulong_t)&adl_n_cfg },
877 - { PCI_VDEVICE(INTEL, DID_ASL_SKU1), .driver_data = (kernel_ulong_t)&adl_n_cfg },
878 - { PCI_VDEVICE(INTEL, DID_ASL_SKU2), .driver_data = (kernel_ulong_t)&adl_n_cfg },
879 - { PCI_VDEVICE(INTEL, DID_ASL_SKU3), .driver_data = (kernel_ulong_t)&adl_n_cfg },
880 - { PCI_VDEVICE(INTEL, DID_RPL_P_SKU1), .driver_data = (kernel_ulong_t)&rpl_p_cfg },
881 - { PCI_VDEVICE(INTEL, DID_RPL_P_SKU2), .driver_data = (kernel_ulong_t)&rpl_p_cfg },
882 - { PCI_VDEVICE(INTEL, DID_RPL_P_SKU3), .driver_data = (kernel_ulong_t)&rpl_p_cfg },
883 - { PCI_VDEVICE(INTEL, DID_RPL_P_SKU4), .driver_data = (kernel_ulong_t)&rpl_p_cfg },
884 - { PCI_VDEVICE(INTEL, DID_RPL_P_SKU5), .driver_data = (kernel_ulong_t)&rpl_p_cfg },
974 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU1), .driver_data = (kernel_ulong_t)&adl_cfg },
975 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU2), .driver_data = (kernel_ulong_t)&adl_cfg },
976 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU3), .driver_data = (kernel_ulong_t)&adl_cfg },
977 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU4), .driver_data = (kernel_ulong_t)&adl_cfg },
978 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU5), .driver_data = (kernel_ulong_t)&adl_cfg },
979 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU6), .driver_data = (kernel_ulong_t)&adl_cfg },
980 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU7), .driver_data = (kernel_ulong_t)&adl_cfg },
981 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU8), .driver_data = (kernel_ulong_t)&adl_cfg },
982 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU9), .driver_data = (kernel_ulong_t)&adl_cfg },
983 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU10), .driver_data = (kernel_ulong_t)&adl_cfg },
984 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU11), .driver_data = (kernel_ulong_t)&adl_cfg },
985 + { PCI_VDEVICE(INTEL, DID_ADL_N_SKU12), .driver_data = (kernel_ulong_t)&adl_cfg },
986 + { PCI_VDEVICE(INTEL, DID_AZB_SKU1), .driver_data = (kernel_ulong_t)&adl_cfg },
987 + { PCI_VDEVICE(INTEL, DID_ASL_SKU1), .driver_data = (kernel_ulong_t)&adl_cfg },
988 + { PCI_VDEVICE(INTEL, DID_ASL_SKU2), .driver_data = (kernel_ulong_t)&adl_cfg },
989 + { PCI_VDEVICE(INTEL, DID_ASL_SKU3), .driver_data = (kernel_ulong_t)&adl_cfg },
990 + { PCI_VDEVICE(INTEL, DID_RPL_P_SKU1), .driver_data = (kernel_ulong_t)&adl_cfg },
991 + { PCI_VDEVICE(INTEL, DID_RPL_P_SKU2), .driver_data = (kernel_ulong_t)&adl_cfg },
992 + { PCI_VDEVICE(INTEL, DID_RPL_P_SKU3), .driver_data = (kernel_ulong_t)&adl_cfg },
993 + { PCI_VDEVICE(INTEL, DID_RPL_P_SKU4), .driver_data = (kernel_ulong_t)&adl_cfg },
994 + { PCI_VDEVICE(INTEL, DID_RPL_P_SKU5), .driver_data = (kernel_ulong_t)&adl_cfg },
885 995 { PCI_VDEVICE(INTEL, DID_MTL_PS_SKU1), .driver_data = (kernel_ulong_t)&mtl_ps_cfg },
886 996 { PCI_VDEVICE(INTEL, DID_MTL_PS_SKU2), .driver_data = (kernel_ulong_t)&mtl_ps_cfg },
887 997 { PCI_VDEVICE(INTEL, DID_MTL_PS_SKU3), .driver_data = (kernel_ulong_t)&mtl_ps_cfg },
@@ -892,6 +1002,7 @@ static struct pci_device_id igen6_pci_tbl[] = {
892 1002 { PCI_VDEVICE(INTEL, DID_ARL_UH_SKU1), .driver_data = (kernel_ulong_t)&mtl_p_cfg },
893 1003 { PCI_VDEVICE(INTEL, DID_ARL_UH_SKU2), .driver_data = (kernel_ulong_t)&mtl_p_cfg },
894 1004 { PCI_VDEVICE(INTEL, DID_ARL_UH_SKU3), .driver_data = (kernel_ulong_t)&mtl_p_cfg },
1005 + { PCI_VDEVICE(INTEL, DID_WCL_SKU1), .driver_data = (kernel_ulong_t)&mtl_p_cfg },
895 1006 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU1), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
896 1007 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU2), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
897 1008 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU3), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
@@ -906,7 +1017,7 @@ static struct pci_device_id igen6_pci_tbl[] = {
906 1017 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU12), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
907 1018 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU13), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
908 1019 { PCI_VDEVICE(INTEL, DID_PTL_H_SKU14), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
909 - { PCI_VDEVICE(INTEL, DID_WCL_SKU1), .driver_data = (kernel_ulong_t)&wcl_cfg },
1020 + { PCI_VDEVICE(INTEL, DID_STF_SKU1), .driver_data = (kernel_ulong_t)&ptl_h_cfg },
910 1021 { PCI_VDEVICE(INTEL, DID_NVL_H_SKU1), .driver_data = (kernel_ulong_t)&nvl_h_cfg },
911 1022 { PCI_VDEVICE(INTEL, DID_NVL_H_SKU2), .driver_data = (kernel_ulong_t)&nvl_h_cfg },
912 1023 { PCI_VDEVICE(INTEL, DID_NVL_H_SKU3), .driver_data = (kernel_ulong_t)&nvl_h_cfg },
@@ -1007,55 +1118,13 @@ static void set_dimm_params(struct igen6_imc *imc, int chan)
1007 1118 imc->dimm_s_size[chan] = MAD_DIMM_CH_DIMM_S_SIZE(val);
1008 1119 }
1009 1120
1010 - static int decode_chan_idx(u64 addr, u64 mask, int intlv_bit)
1011 - {
1012 - u64 hash_addr = addr & mask, hash = 0;
1013 - u64 intlv = (addr >> intlv_bit) & 1;
1014 - int i;
1015 -
1016 - for (i = 6; i < 20; i++)
1017 - hash ^= (hash_addr >> i) & 1;
1018 -
1019 - return (int)hash ^ intlv;
1020 - }
1021 -
1022 - static u64 decode_channel_addr(u64 addr, int intlv_bit)
1023 - {
1024 - u64 channel_addr;
1025 -
1026 - /* Remove the interleave bit and shift upper part down to fill gap */
1027 - channel_addr = GET_BITFIELD(addr, intlv_bit + 1, 63) << intlv_bit;
1028 - channel_addr |= GET_BITFIELD(addr, 0, intlv_bit - 1);
1029 -
1030 - return channel_addr;
1031 - }
1032 -
1033 - static void decode_addr(u64 addr, u32 hash, u64 s_size, int l_map,
1034 - int *idx, u64 *sub_addr)
1035 - {
1036 - int intlv_bit = CHANNEL_HASH_LSB_MASK_BIT(hash) + 6;
1037 -
1038 - if (addr > 2 * s_size) {
1039 - *sub_addr = addr - s_size;
1040 - *idx = l_map;
1041 - return;
1042 - }
1043 -
1044 - if (CHANNEL_HASH_MODE(hash)) {
1045 - *sub_addr = decode_channel_addr(addr, intlv_bit);
1046 - *idx = decode_chan_idx(addr, CHANNEL_HASH_MASK(hash), intlv_bit);
1047 - } else {
1048 - *sub_addr = decode_channel_addr(addr, 6);
1049 - *idx = GET_BITFIELD(addr, 6, 6);
1050 - }
1051 - }
1052 -
1053 1121 static int igen6_decode(struct decoded_addr *res)
1054 1122 {
1055 1123 struct igen6_imc *imc = &igen6_pvt->imc[res->mc];
1056 - u64 addr = res->imc_addr, sub_addr, s_size;
1057 - int idx, l_map;
1058 - u32 hash;
1124 + u64 addr = res->imc_addr, s_size;
1125 + int intlv_bit, l_map;
1126 + u32 hash, hash_mask;
1127 + struct slice slice;
1059 1128
1060 1129 if (addr >= igen6_tom) {
1061 1130 edac_dbg(0, "Address 0x%llx out of range\n", addr);
@@ -1066,17 +1135,25 @@ static int igen6_decode(struct decoded_addr *res)
1066 1135 hash = readl(imc->window + CHANNEL_HASH_OFFSET);
1067 1136 s_size = imc->ch_s_size;
1068 1137 l_map = imc->ch_l_map;
1069 - decode_addr(addr, hash, s_size, l_map, &idx, &sub_addr);
1070 - res->channel_idx = idx;
1071 - res->channel_addr = sub_addr;
1138 + hash_mask = CHANNEL_HASH_MODE(hash) ? CHANNEL_HASH_MASK(hash) : 0;
1139 + intlv_bit = CHANNEL_HASH_LSB_MASK_BIT(hash) + 6;
1140 +
1141 + translate_to_lower_level(addr, hash_mask, 0, intlv_bit, s_size, l_map, &slice);
1142 +
1143 + res->channel_idx = slice.id;
1144 + res->channel_addr = slice.addr;
1072 1145
1073 1146 /* Decode sub-channel/DIMM */
1074 1147 hash = readl(imc->window + CHANNEL_EHASH_OFFSET);
1075 - s_size = imc->dimm_s_size[idx];
1076 - l_map = imc->dimm_l_map[idx];
1077 - decode_addr(res->channel_addr, hash, s_size, l_map, &idx, &sub_addr);
1078 - res->sub_channel_idx = idx;
1079 - res->sub_channel_addr = sub_addr;
1148 + s_size = imc->dimm_s_size[res->channel_idx];
1149 + l_map = imc->dimm_l_map[res->channel_idx];
1150 + hash_mask = CHANNEL_HASH_MODE(hash) ? CHANNEL_HASH_MASK(hash) : 0;
1151 + intlv_bit = CHANNEL_HASH_LSB_MASK_BIT(hash) + 6;
1152 +
1153 + translate_to_lower_level(res->channel_addr, hash_mask, 0, intlv_bit, s_size, l_map, &slice);
1154 +
1155 + res->sub_channel_idx = slice.id;
1156 + res->sub_channel_addr = slice.addr;
1080 1157
1081 1158 return 0;
1082 1159 }
@@ -1230,11 +1307,7 @@ static void ecclog_work_cb(struct work_struct *work)
1230 1307
1231 1308 llist_for_each_entry_safe(node, tmp, head, llnode) {
1232 1309 memset(&res, 0, sizeof(res));
1233 - if (res_cfg->err_addr)
1234 - eaddr = res_cfg->err_addr(node->ecclog);
1235 - else
1236 - eaddr = node->ecclog & res_cfg->reg_eccerrlog_addr_mask;
1237 -
1310 + eaddr = node->ecclog & res_cfg->reg_eccerrlog_addr_mask;
1238 1311 res.mc = node->mc;
1239 1312 res.sys_addr = res_cfg->err_addr_to_sys_addr(eaddr, res.mc);
1240 1313 res.imc_addr = res_cfg->err_addr_to_imc_addr(eaddr, res.mc);
@@ -1476,18 +1549,27 @@ static struct igen6_pvt *igen6_pvt_setup(struct pci_dev *pdev)
1476 1549 {
1477 1550 void __iomem *memss_pma_cr;
1478 1551 struct igen6_pvt *pvt;
1552 + int imc_num, rc;
1479 1553 u64 mchbar;
1480 - int rc;
1481 1554
1482 - pvt = kzalloc_obj(*igen6_pvt);
1483 - if (!pvt)
1555 + rc = get_mchbar(pdev, &mchbar);
1556 + if (rc)
1484 1557 return NULL;
1485 1558
1486 - rc = get_mchbar(pdev, &mchbar);
1487 - if (rc) {
1488 - kfree(pvt);
1559 + imc_num = get_imc_num(mchbar);
1560 + if (!imc_num) {
1561 + igen6_printk(KERN_ERR, "No mc found.\n");
1489 1562 return NULL;
1490 1563 }
1564 + edac_dbg(2, "%d mcs found.\n", imc_num);
1565 +
1566 + /* Use the runtime detected IMC count. */
1567 + if (res_cfg->num_imc != imc_num)
1568 + res_cfg->num_imc = imc_num;
1569 +
1570 + pvt = kzalloc_flex(*pvt, imc, imc_num);
1571 + if (!pvt)
1572 + return NULL;
1491 1573
1492 1574 memss_pma_cr = ioremap(mchbar, MCHBAR_SIZE * 2);
1493 1575 if (!memss_pma_cr) {
@@ -1572,12 +1654,6 @@ static void igen6_check(struct mem_ctl_info *mci)
1572 1654 irq_work_queue(&ecclog_irq_work);
1573 1655 }
1574 1656
1575 - /* Check whether the memory controller is absent. */
1576 - static bool igen6_imc_absent(void __iomem *window)
1577 - {
1578 - return readl(window + MAD_INTER_CHANNEL_OFFSET) == ~0;
1579 - }
1580 -
1581 1657 static void imc_release(struct device *dev)
1582 1658 {
1583 1659 /* Nothing to do, the 'imc' owns the 'dev' and will also release it. */
@@ -1689,26 +1765,15 @@ static int igen6_register_mcis(struct pci_dev *pdev, u64 mchbar)
1689 1765 {
1690 1766 void __iomem *window;
1691 1767 int lmc, pmc, rc;
1692 - u64 base;
1693 -
1694 - for (lmc = 0, pmc = 0; pmc < NUM_IMC; pmc++) {
1695 - base = mchbar + pmc * MCHBAR_SIZE;
1696 - window = ioremap(base, MCHBAR_SIZE);
1697 - if (!window) {
1698 - igen6_printk(KERN_ERR, "Failed to ioremap 0x%llx for mc%d\n", base, pmc);
1699 - rc = -ENOMEM;
1700 - goto out_unregister_mcis;
1701 - }
1702 1768
1703 - if (igen6_imc_absent(window)) {
1704 - iounmap(window);
1705 - edac_dbg(2, "Skip absent mc%d\n", pmc);
1769 + for (lmc = 0, pmc = 0; pmc < MAX_IMC_TO_PROBE; pmc++) {
1770 + window = map_imc_window(mchbar, pmc);
1771 + if (!window)
1706 1772 continue;
1707 - }
1708 1773
1709 1774 rc = igen6_register_mci(lmc, window, pdev);
1710 1775 if (rc)
1711 - goto out_iounmap;
1776 + goto err_unregister;
1712 1777
1713 1778 /* Done, if all present MCs are detected and registered. */
1714 1779 if (++lmc >= res_cfg->num_imc)
@@ -1728,10 +1793,8 @@ static int igen6_register_mcis(struct pci_dev *pdev, u64 mchbar)
1728 1793
1729 1794 return 0;
1730 1795
1731 - out_iounmap:
1796 + err_unregister:
1732 1797 iounmap(window);
1733 -
1734 - out_unregister_mcis:
1735 1798 igen6_unregister_mcis();
1736 1799
1737 1800 return rc;
modified drivers/edac/thunderx_edac.c
@@ -729,10 +729,8 @@ static int thunderx_lmc_probe(struct pci_dev *pdev,
729 729 thunderx_lmc_err_isr,
730 730 thunderx_lmc_threaded_isr, 0,
731 731 "[EDAC] ThunderX LMC", mci);
732 - if (ret) {
733 - dev_err(&pdev->dev, "Cannot set ISR: %d\n", ret);
732 + if (ret)
734 733 goto err_free;
735 - }
736 734
737 735 lmc->node = FIELD_GET(THUNDERX_NODE, pci_resource_start(pdev, 0));
738 736
modified drivers/edac/versalnet_edac.c
@@ -813,7 +813,7 @@ static int init_one_mc(struct mc_priv *priv, struct platform_device *pdev, int i
813 813 layers[1].is_virt_csrow = false;
814 814
815 815 rc = -ENOMEM;
816 - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
816 + dev = kzalloc_obj(*dev);
817 817 if (!dev)
818 818 return rc;
819 819
modified drivers/edac/xgene_edac.c
@@ -1924,11 +1924,8 @@ static int xgene_edac_probe(struct platform_device *pdev)
1924 1924 rc = devm_request_irq(&pdev->dev, irq,
1925 1925 xgene_edac_isr, IRQF_SHARED,
1926 1926 dev_name(&pdev->dev), edac);
1927 - if (rc) {
1928 - dev_err(&pdev->dev,
1929 - "Could not request IRQ %d\n", irq);
1927 + if (rc)
1930 1928 goto out_err;
1931 - }
1932 1929 }
1933 1930 }
1934 1931
modified drivers/firmware/arm_scmi/driver.c
@@ -1792,7 +1792,7 @@ static void *scmi_iterator_init(const struct scmi_protocol_handle *ph,
1792 1792 {
1793 1793 int ret;
1794 1794
1795 - struct scmi_iterator *i __free(kfree) = kzalloc(sizeof(*i), GFP_KERNEL);
1795 + struct scmi_iterator *i __free(kfree) = kzalloc_obj(*i);
1796 1796 if (!i)
1797 1797 return ERR_PTR(-ENOMEM);
1798 1798
modified drivers/firmware/qcom/qcom_tzmem.c
@@ -169,7 +169,7 @@ static int qcom_tzmem_init_area(struct qcom_tzmem_area *area)
169 169 {
170 170 int ret;
171 171
172 - u64 *handle __free(kfree) = kzalloc(sizeof(*handle), GFP_KERNEL);
172 + u64 *handle __free(kfree) = kzalloc_obj(*handle);
173 173 if (!handle)
174 174 return -ENOMEM;
175 175
@@ -197,8 +197,7 @@ static int qcom_tzmem_pool_add_memory(struct qcom_tzmem_pool *pool,
197 197 {
198 198 int ret;
199 199
200 - struct qcom_tzmem_area *area __free(kfree) = kzalloc(sizeof(*area),
201 - gfp);
200 + struct qcom_tzmem_area *area __free(kfree) = kzalloc_obj(*area, gfp);
202 201 if (!area)
203 202 return -ENOMEM;
204 203
@@ -415,8 +414,7 @@ void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp)
415 414
416 415 size = PAGE_ALIGN(size);
417 416
418 - struct qcom_tzmem_chunk *chunk __free(kfree) = kzalloc(sizeof(*chunk),
419 - gfp);
417 + struct qcom_tzmem_chunk *chunk __free(kfree) = kzalloc_obj(*chunk, gfp);
420 418 if (!chunk)
421 419 return NULL;
422 420
modified drivers/firmware/ti_sci.c
@@ -2386,7 +2386,7 @@ static int ti_sci_set_irq(const struct ti_sci_handle *handle, u32 valid_params,
2386 2386 if (ret || !(info->fw_caps & MSG_FLAG_CAPS_LPM_IRQ_CONTEXT_LOST))
2387 2387 goto end;
2388 2388
2389 - irq = kzalloc_obj(*irq, GFP_KERNEL);
2389 + irq = kzalloc_obj(*irq);
2390 2390 if (!irq) {
2391 2391 ti_sci_manage_irq(handle, valid_params, src_id, src_index,
2392 2392 dst_id, dst_host_irq, ia_id, vint,
modified drivers/fpga/dfl-afu-dma-region.c
@@ -316,7 +316,7 @@ int afu_dma_map_region(struct dfl_feature_dev_data *fdata,
316 316 if (user_addr + length < user_addr)
317 317 return -EINVAL;
318 318
319 - region = kzalloc(sizeof(*region), GFP_KERNEL);
319 + region = kzalloc_obj(*region);
320 320 if (!region)
321 321 return -ENOMEM;
322 322
modified drivers/gpio/gpio-aggregator.c
@@ -886,8 +886,8 @@ gpio_aggregator_make_device_sw_node(struct gpio_aggregator *aggr)
886 886 if (num_lines == 0)
887 887 return NULL;
888 888
889 - const char **line_names __free(kfree) = kcalloc(
890 - num_lines, sizeof(*line_names), GFP_KERNEL);
889 + const char **line_names __free(kfree) = kzalloc_objs(*line_names,
890 + num_lines);
891 891 if (!line_names)
892 892 return ERR_PTR(-ENOMEM);
893 893
modified drivers/gpio/gpio-mpsse.c
@@ -518,7 +518,7 @@ static void gpio_mpsse_irq_enable(struct irq_data *irqd)
518 518 * Can't be devm because it uses a non-raw spinlock (illegal in
519 519 * this context, where a raw spinlock is held by our caller)
520 520 */
521 - worker = kzalloc(sizeof(*worker), GFP_NOWAIT);
521 + worker = kzalloc_obj(*worker, GFP_NOWAIT);
522 522 if (!worker)
523 523 return;
524 524
modified drivers/gpio/gpio-sim.c
@@ -790,8 +790,7 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
790 790
791 791 line_names_size = gpio_sim_get_line_names_size(bank);
792 792 if (line_names_size) {
793 - line_names = kcalloc(line_names_size, sizeof(*line_names),
794 - GFP_KERNEL);
793 + line_names = kzalloc_objs(*line_names, line_names_size);
795 794 if (!line_names)
796 795 return ERR_PTR(-ENOMEM);
797 796
modified drivers/gpio/gpio-virtuser.c
@@ -1429,8 +1429,7 @@ gpio_virtuser_make_device_swnode(struct gpio_virtuser_device *dev)
1429 1429 memset(properties, 0, sizeof(properties));
1430 1430
1431 1431 num_ids = list_count_nodes(&dev->lookup_list);
1432 - char **ids __free(kfree) = kcalloc(num_ids + 1, sizeof(*ids),
1433 - GFP_KERNEL);
1432 + char **ids __free(kfree) = kzalloc_objs(*ids, num_ids + 1);
1434 1433 if (!ids)
1435 1434 return ERR_PTR(-ENOMEM);
1436 1435
modified drivers/gpio/gpiolib-cdev.c
@@ -2653,7 +2653,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
2653 2653 struct gpio_chardev_data *cdev;
2654 2654 int ret = -ENOMEM;
2655 2655
2656 - cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
2656 + cdev = kzalloc_obj(*cdev);
2657 2657 if (!cdev)
2658 2658 return -ENOMEM;
2659 2659
modified drivers/gpio/gpiolib.c
@@ -1178,7 +1178,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
1178 1178 int base = 0;
1179 1179 int ret;
1180 1180
1181 - gdev = kzalloc(sizeof(*gdev), GFP_KERNEL);
1181 + gdev = kzalloc_obj(*gdev);
1182 1182 if (!gdev)
1183 1183 return -ENOMEM;
1184 1184 gc->gpiodev = gdev;
@@ -1218,7 +1218,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
1218 1218 goto err_put_device;
1219 1219 gdev->ngpio = gc->ngpio;
1220 1220
1221 - gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL);
1221 + gdev->descs = kzalloc_objs(*gdev->descs, gc->ngpio);
1222 1222 if (!gdev->descs) {
1223 1223 ret = -ENOMEM;
1224 1224 goto err_put_device;
modified drivers/gpu/buddy.c
@@ -411,16 +411,13 @@ int gpu_buddy_init(struct gpu_buddy *mm, u64 size, u64 chunk_size)
411 411 if (!mm->used_scoreboard)
412 412 goto out_free_free_scoreboard;
413 413
414 - mm->free_trees = kmalloc_array(GPU_BUDDY_MAX_FREE_TREES,
415 - sizeof(*mm->free_trees),
416 - GFP_KERNEL);
414 + mm->free_trees = kmalloc_objs(*mm->free_trees, GPU_BUDDY_MAX_FREE_TREES);
417 415 if (!mm->free_trees)
418 416 goto out_free_used_scoreboard;
419 417
420 418 for_each_free_tree(i) {
421 - mm->free_trees[i] = kmalloc_array(mm->max_order + 1,
422 - sizeof(struct rb_root),
423 - GFP_KERNEL);
419 + mm->free_trees[i] = kmalloc_objs(struct rb_root,
420 + mm->max_order + 1);
424 421 if (!mm->free_trees[i])
425 422 goto out_free_tree;
426 423
@@ -430,9 +427,7 @@ int gpu_buddy_init(struct gpu_buddy *mm, u64 size, u64 chunk_size)
430 427
431 428 mm->n_roots = hweight64(size);
432 429
433 - mm->roots = kmalloc_array(mm->n_roots,
434 - sizeof(struct gpu_buddy_block *),
435 - GFP_KERNEL);
430 + mm->roots = kmalloc_objs(struct gpu_buddy_block *, mm->n_roots);
436 431 if (!mm->roots)
437 432 goto out_free_tree;
438 433
modified drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c
@@ -299,10 +299,10 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p,
299 299 amdgpu_res_first(abo->tbo.resource, offset,
300 300 coredump->ibs[i].ib_size_dw * 4, &cursor);
301 301 while (cursor.remaining) {
302 - amdgpu_device_mm_access(adev, cursor.start / 4,
303 - &ib_content[off], cursor.size / 4,
302 + amdgpu_device_mm_access(adev, cursor.start,
303 + &ib_content[off], cursor.size,
304 304 false);
305 - off += cursor.size;
305 + off += cursor.size / 4;
306 306 amdgpu_res_next(&cursor, cursor.size);
307 307 }
308 308 emit_content = true;
@@ -603,9 +603,8 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
603 603 ring_count++;
604 604 }
605 605 if (ring_count)
606 - coredump->rings = kvcalloc(ring_count,
607 - sizeof(struct amdgpu_coredump_ring),
608 - GFP_NOWAIT);
606 + coredump->rings = kvzalloc_objs(struct amdgpu_coredump_ring,
607 + ring_count, GFP_NOWAIT);
609 608 if (coredump->rings) {
610 609 for (i = 0, idx = 0; i < adev->num_rings && idx < ring_count; i++) {
611 610 struct amdgpu_coredump_ring *cdump_ring;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -771,6 +771,9 @@ static int amdgpu_device_read_fb_via_bar0(struct amdgpu_device *adev,
771 771 if (!buf || !size)
772 772 return -EINVAL;
773 773
774 + if (!amdgpu_sriov_vf(adev))
775 + return -EINVAL;
776 +
774 777 flags = pci_resource_flags(adev->pdev, 0);
775 778 if ((flags & IORESOURCE_UNSET) || !(flags & IORESOURCE_MEM))
776 779 return -EINVAL;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -1608,11 +1608,11 @@ int amdgpu_discovery_sysfs_early_init(struct amdgpu_device *adev, struct pci_dev
1608 1608
1609 1609 discovery_bin = adev->discovery.bin;
1610 1610
1611 - early_entry = kzalloc(sizeof(*early_entry), GFP_KERNEL);
1611 + early_entry = kzalloc_obj(*early_entry);
1612 1612 if (!early_entry)
1613 1613 return -ENOMEM;
1614 1614
1615 - ip_top = kzalloc(sizeof(*ip_top), GFP_KERNEL);
1615 + ip_top = kzalloc_obj(*ip_top);
1616 1616 if (!ip_top) {
1617 1617 kfree(early_entry);
1618 1618 return -ENOMEM;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_lockdep.c
@@ -98,7 +98,7 @@ int amdgpu_lockdep_init(void)
98 98 struct amdgpu_lockdep_dummy_locks *locks;
99 99 unsigned long flags;
100 100
101 - locks = kzalloc(sizeof(*locks), GFP_KERNEL);
101 + locks = kzalloc_obj(*locks);
102 102 if (!locks)
103 103 return -ENOMEM;
104 104
modified drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
@@ -879,7 +879,7 @@ bool amdgpu_mes_queue_reset_by_mes_supported(struct amdgpu_device *adev)
879 879
880 880 return (ip_maj == 11 && mes_sched >= 0x8c) ||
881 881 ((ip_maj == 12 && ip_min == 0) && mes_sched >= 0x8d) ||
882 - ((ip_maj == 12 && ip_min == 1) && mes_sched >= 0x73);
882 + ((ip_maj == 12 && ip_min == 1) && mes_sched >= 0x7b);
883 883 }
884 884
885 885 /* Fix me -- node_id is used to identify the correct MES instances in the future */
modified drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -396,6 +396,12 @@ static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,
396 396 bool ret = false;
397 397 int i;
398 398
399 + /*
400 + * Runtime DB is for dGPUs only.
401 + */
402 + if (adev->flags & AMD_IS_APU)
403 + return false;
404 +
399 405 if (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 6) ||
400 406 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 12) ||
401 407 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 14) ||
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c
@@ -1293,7 +1293,7 @@ amdgpu_ras_debugfs_table_read_uniras(struct amdgpu_device *adev,
1293 1293 return -ENOMEM;
1294 1294
1295 1295 if (num_recs) {
1296 - records = kvcalloc(num_recs, sizeof(*records), GFP_KERNEL);
1296 + records = kvzalloc_objs(*records, num_recs);
1297 1297 if (!records) {
1298 1298 res = -ENOMEM;
1299 1299 goto out;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2361,9 +2361,8 @@ void amdgpu_ttm_enable_buffer_funcs(struct amdgpu_device *adev)
2361 2361 num_clear_entities = MIN(adev->mman.num_buffer_funcs_scheds, TTM_NUM_MOVE_FENCES);
2362 2362 num_move_entities = MIN(adev->mman.num_buffer_funcs_scheds, TTM_NUM_MOVE_FENCES);
2363 2363
2364 - adev->mman.clear_entities = kcalloc(num_clear_entities,
2365 - sizeof(struct amdgpu_ttm_buffer_entity),
2366 - GFP_KERNEL);
2364 + adev->mman.clear_entities = kzalloc_objs(struct amdgpu_ttm_buffer_entity,
2365 + num_clear_entities);
2367 2366 atomic_set(&adev->mman.next_clear_entity, 0);
2368 2367 if (!adev->mman.clear_entities)
2369 2368 goto error_free_default_entity;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c
@@ -159,8 +159,8 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,
159 159 adev->umc.ras->ecc_info_query_ras_error_address &&
160 160 adev->umc.max_ras_err_cnt_per_query) {
161 161 err_data->err_addr =
162 - kcalloc(adev->umc.max_ras_err_cnt_per_query,
163 - sizeof(struct eeprom_table_record), GFP_KERNEL);
162 + kzalloc_objs(struct eeprom_table_record,
163 + adev->umc.max_ras_err_cnt_per_query);
164 164
165 165 /* still call query_ras_error_address to clear error status
166 166 * even NOMEM error is encountered
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -1544,7 +1544,7 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
1544 1544 struct amdgpu_usermode_queue *queue;
1545 1545 const struct amdgpu_userq_funcs *userq_funcs;
1546 1546 unsigned long queue_id;
1547 - int r = 0;
1547 + int ret = 0, r;
1548 1548
1549 1549 xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
1550 1550 if (queue->state == AMDGPU_USERQ_STATE_HUNG && !vram_lost) {
@@ -1555,6 +1555,7 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
1555 1555 r = userq_funcs->map(queue);
1556 1556 if (r) {
1557 1557 dev_err(adev->dev, "Failed to remap queue %ld\n", queue_id);
1558 + ret = r;
1558 1559 continue;
1559 1560 }
1560 1561 trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_MAPPED);
@@ -1562,5 +1563,5 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
1562 1563 }
1563 1564 }
1564 1565
1565 - return r;
1566 + return ret;
1566 1567 }
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
@@ -227,7 +227,7 @@ static int amdgpu_userq_fence_alloc(struct amdgpu_usermode_queue *userq,
227 227 struct amdgpu_userq_fence *userq_fence;
228 228 void *entry;
229 229
230 - userq_fence = kmalloc(sizeof(*userq_fence), GFP_KERNEL);
230 + userq_fence = kmalloc_obj(*userq_fence);
231 231 if (!userq_fence)
232 232 return -ENOMEM;
233 233
@@ -244,9 +244,7 @@ static int amdgpu_userq_fence_alloc(struct amdgpu_usermode_queue *userq,
244 244 } while (xas_retry(&xas, entry));
245 245 rcu_read_unlock();
246 246
247 - userq_fence->fence_drv_array = kvmalloc_array(xas.xa_index,
248 - sizeof(fence_drv),
249 - GFP_KERNEL);
247 + userq_fence->fence_drv_array = kvmalloc_objs(fence_drv, xas.xa_index);
250 248 if (!userq_fence->fence_drv_array) {
251 249 mutex_unlock(&userq->fence_drv_lock);
252 250 kfree(userq_fence);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -316,8 +316,8 @@ static int amdgpu_virt_ras_realloc_eh_data_space(struct amdgpu_device *adev,
316 316 if (align_space > AMDGPU_VIRT_RAS_BAD_PAGE_TABLE_MAX_CAPACITY)
317 317 return -ENOMEM;
318 318
319 - new_bps = kmalloc_array(align_space, sizeof(*data->bps), GFP_KERNEL);
320 - new_bo = kcalloc(align_space, sizeof(*data->bps_bo), GFP_KERNEL);
319 + new_bps = kmalloc_objs(*data->bps, align_space);
320 + new_bo = kzalloc_objs(*data->bps_bo, align_space);
321 321 if (!new_bps || !new_bo) {
322 322 kfree(new_bps);
323 323 kfree(new_bo);
@@ -355,7 +355,7 @@ static int amdgpu_virt_init_ras_err_handler_data(struct amdgpu_device *adev)
355 355 if (!bps)
356 356 goto bps_failure;
357 357
358 - bps_bo = kcalloc(align_space, sizeof(*(*data)->bps_bo), GFP_KERNEL);
358 + bps_bo = kzalloc_objs(*(*data)->bps_bo, align_space);
359 359 if (!bps_bo)
360 360 goto bps_bo_failure;
361 361
modified drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2090,7 +2090,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
2090 2090 after->start = eaddr + 1;
2091 2091 after->last = tmp->last;
2092 2092 after->offset = tmp->offset;
2093 - after->offset += (after->start - tmp->start) << PAGE_SHIFT;
2093 + after->offset += (after->start - tmp->start) << AMDGPU_GPU_PAGE_SHIFT;
2094 2094 after->flags = tmp->flags;
2095 2095 after->bo_va = tmp->bo_va;
2096 2096 list_add(&after->list, &tmp->bo_va->invalids);
@@ -3122,7 +3122,7 @@ static void amdgpu_debugfs_vm_bo_status_info(struct seq_file *m,
3122 3122
3123 3123 id = 0;
3124 3124 seq_puts(m, "\tIdle BOs:\n");
3125 - list_for_each_entry(base, &lists->needs_update, vm_status) {
3125 + list_for_each_entry(base, &lists->idle, vm_status) {
3126 3126 if (!base->bo)
3127 3127 continue;
3128 3128
modified drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -1651,10 +1651,10 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
1651 1651 case IP_VERSION(11, 0, 2):
1652 1652 case IP_VERSION(11, 0, 3):
1653 1653 if (!adev->gfx.disable_uq &&
1654 - adev->gfx.me_fw_version >= 2420 &&
1655 - adev->gfx.pfp_fw_version >= 2580 &&
1656 - adev->gfx.mec_fw_version >= 2650 &&
1657 - adev->mes.fw_version[0] >= 120) {
1654 + adev->gfx.me_fw_version >= 3090 &&
1655 + adev->gfx.pfp_fw_version >= 3190 &&
1656 + adev->gfx.mec_fw_version >= 3450 &&
1657 + adev->mes.fw_version[0] >= 147) {
1658 1658 adev->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_mes_funcs;
1659 1659 adev->userq_funcs[AMDGPU_HW_IP_COMPUTE] = &userq_mes_funcs;
1660 1660 }
modified drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -1436,10 +1436,10 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
1436 1436 case IP_VERSION(12, 0, 0):
1437 1437 case IP_VERSION(12, 0, 1):
1438 1438 if (!adev->gfx.disable_uq &&
1439 - adev->gfx.me_fw_version >= 2780 &&
1440 - adev->gfx.pfp_fw_version >= 2840 &&
1441 - adev->gfx.mec_fw_version >= 3050 &&
1442 - adev->mes.fw_version[0] >= 123) {
1439 + adev->gfx.me_fw_version >= 3090 &&
1440 + adev->gfx.pfp_fw_version >= 3190 &&
1441 + adev->gfx.mec_fw_version >= 3450 &&
1442 + adev->mes.fw_version[0] >= 147) {
1443 1443 adev->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_mes_funcs;
1444 1444 adev->userq_funcs[AMDGPU_HW_IP_COMPUTE] = &userq_mes_funcs;
1445 1445 }
modified drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -4546,9 +4546,11 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
4546 4546 /* set static priority for a queue/ring */
4547 4547 gfx_v8_0_mqd_set_priority(ring, mqd);
4548 4548 tmp = RREG32(mmCP_HQD_QUANTUM);
4549 - tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_EN, 1);
4550 - tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
4551 - tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 10);
4549 + if (ring != &adev->gfx.kiq[0].ring) {
4550 + tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_EN, 1);
4551 + tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_SCALE, 1);
4552 + tmp = REG_SET_FIELD(tmp, CP_HQD_QUANTUM, QUANTUM_DURATION, 10);
4553 + }
4552 4554 mqd->cp_hqd_quantum = tmp;
4553 4555
4554 4556 /* map_queues packet doesn't need activate the queue,
modified drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1921,13 +1921,13 @@ static int criu_checkpoint_devices(struct kfd_process *p,
1921 1921 struct kfd_criu_device_bucket *device_buckets = NULL;
1922 1922 int ret = 0, i;
1923 1923
1924 - device_buckets = kvcalloc(num_devices, sizeof(*device_buckets), GFP_KERNEL);
1924 + device_buckets = kvzalloc_objs(*device_buckets, num_devices);
1925 1925 if (!device_buckets) {
1926 1926 ret = -ENOMEM;
1927 1927 goto exit;
1928 1928 }
1929 1929
1930 - device_priv = kvcalloc(num_devices, sizeof(*device_priv), GFP_KERNEL);
1930 + device_priv = kvzalloc_objs(*device_priv, num_devices);
1931 1931 if (!device_priv) {
1932 1932 ret = -ENOMEM;
1933 1933 goto exit;
@@ -2047,17 +2047,17 @@ static int criu_checkpoint_bos(struct kfd_process *p,
2047 2047 int ret = 0, pdd_index, bo_index = 0, id;
2048 2048 void *mem;
2049 2049
2050 - bo_buckets = kvcalloc(num_bos, sizeof(*bo_buckets), GFP_KERNEL);
2050 + bo_buckets = kvzalloc_objs(*bo_buckets, num_bos);
2051 2051 if (!bo_buckets)
2052 2052 return -ENOMEM;
2053 2053
2054 - bo_privs = kvcalloc(num_bos, sizeof(*bo_privs), GFP_KERNEL);
2054 + bo_privs = kvzalloc_objs(*bo_privs, num_bos);
2055 2055 if (!bo_privs) {
2056 2056 ret = -ENOMEM;
2057 2057 goto exit;
2058 2058 }
2059 2059
2060 - files = kvcalloc(num_bos, sizeof(struct file *), GFP_KERNEL);
2060 + files = kvzalloc_objs(struct file *, num_bos);
2061 2061 if (!files) {
2062 2062 ret = -ENOMEM;
2063 2063 goto exit;
@@ -2588,7 +2588,7 @@ static int criu_restore_bos(struct kfd_process *p,
2588 2588 if (!bo_buckets)
2589 2589 return -ENOMEM;
2590 2590
2591 - files = kvcalloc(args->num_bos, sizeof(struct file *), GFP_KERNEL);
2591 + files = kvzalloc_objs(struct file *, args->num_bos);
2592 2592 if (!files) {
2593 2593 ret = -ENOMEM;
2594 2594 goto exit;
modified drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1455,6 +1455,14 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,
1455 1455 dqm_evict_mqd_bo(dqm, q);
1456 1456 }
1457 1457
1458 + /*
1459 + * Heavy-weight TLB flush after MES removes queues to ensure
1460 + * in-flight memory accesses complete before memory is freed/migrated.
1461 + * HWS does this automatically, MES does not.
1462 + */
1463 + if (dqm->dev->kfd->shared_resources.enable_mes)
1464 + kfd_flush_tlb(pdd);
1465 +
1458 1466 if (!dqm->dev->kfd->shared_resources.enable_mes) {
1459 1467 pdd->last_evict_timestamp = get_jiffies_64();
1460 1468 retval = execute_queues_cpsch(dqm,
@@ -3746,8 +3754,11 @@ int suspend_queues(struct kfd_process *p,
3746 3754 if (!per_device_suspended) {
3747 3755 dqm_unlock(dqm);
3748 3756 mutex_unlock(&p->event_mutex);
3749 - if (total_suspended)
3757 + if (total_suspended) {
3750 3758 amdgpu_amdkfd_debug_mem_fence(dqm->dev->adev);
3759 + /* Heavy-weight TLB flush after MES suspends queues */
3760 + kfd_flush_tlb(pdd);
3761 + }
3751 3762 continue;
3752 3763 }
3753 3764
modified drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -1169,13 +1169,13 @@ int pqm_debugfs_mqds(struct seq_file *m, void *data)
1169 1169 mqd_mgr = q->device->dqm->mqd_mgrs[mqd_type];
1170 1170 size = mqd_mgr->mqd_stride(mqd_mgr,
1171 1171 &q->properties);
1172 - }
1173 1172
1174 - for (xcc = 0; xcc < num_xccs; xcc++) {
1175 - mqd = q->mqd + size * xcc;
1176 - r = mqd_mgr->debugfs_show_mqd(m, mqd);
1177 - if (r != 0)
1178 - break;
1173 + for (xcc = 0; xcc < num_xccs; xcc++) {
1174 + mqd = q->mqd + size * xcc;
1175 + r = mqd_mgr->debugfs_show_mqd(m, mqd);
1176 + if (r != 0)
1177 + break;
1178 + }
1179 1179 }
1180 1180 }
1181 1181
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3879,7 +3879,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state,
3879 3879 continue;
3880 3880
3881 3881 bundle->surface_updates[planes_count].surface = dc_plane;
3882 - if (new_pcrtc_state->color_mgmt_changed) {
3882 + if (new_pcrtc_state->color_mgmt_changed || new_plane_state->color_mgmt_changed) {
3883 3883 bundle->surface_updates[planes_count].gamma = &dc_plane->gamma_correction;
3884 3884 bundle->surface_updates[planes_count].in_transfer_func = &dc_plane->in_transfer_func;
3885 3885 bundle->surface_updates[planes_count].gamut_remap_matrix = &dc_plane->gamut_remap_matrix;
@@ -5698,6 +5698,10 @@ static bool should_reset_plane(struct drm_atomic_commit *state,
5698 5698 if (new_crtc_state->color_mgmt_changed)
5699 5699 return true;
5700 5700
5701 + /* Plane color pipeline or its colorop changes. */
5702 + if (new_plane_state->color_mgmt_changed)
5703 + return true;
5704 +
5701 5705 /*
5702 5706 * On zpos change, planes need to be reordered by removing and re-adding
5703 5707 * them one by one to the dc state, in order of descending zpos.
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
@@ -534,8 +534,12 @@ void amdgpu_dm_update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)
534 534 else if (!IS_ERR_OR_NULL(panel_backlight_quirk) &&
535 535 panel_backlight_quirk->force_pwm)
536 536 caps->aux_support = false;
537 - if (caps->aux_support)
538 - aconnector->dc_link->backlight_control_type = BACKLIGHT_CONTROL_AMD_AUX;
537 + if (caps->aux_support) {
538 + if (aconnector->dc_link->dpcd_caps.panel_luminance_control)
539 + aconnector->dc_link->backlight_control_type = BACKLIGHT_CONTROL_VESA_AUX;
540 + else
541 + aconnector->dc_link->backlight_control_type = BACKLIGHT_CONTROL_AMD_AUX;
542 + }
539 543
540 544 luminance_range = &conn_base->display_info.luminance_range;
541 545
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -2208,16 +2208,41 @@ int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
2208 2208 if (res)
2209 2209 return res;
2210 2210
2211 - if (plane->type == DRM_PLANE_TYPE_OVERLAY &&
2212 - plane_cap && plane_cap->per_pixel_alpha) {
2211 + /* Blend mode support varies on DCE generations according to HW caps
2212 + * and number of planes per CRTC. However, as current driver
2213 + * implementation only creates one primary and one cursor plane per
2214 + * CRTC for DCE (overlay is only created if
2215 + * DC_PLANE_TYPE_DCN_UNIVERSAL), the primary plane blend mode is
2216 + * ignored across DCE versions. Keep PREMULTI to avoid uAPI
2217 + * regressions: it was the default/mandatory mode for many years and,
2218 + * with no overlay plane, primary composes on top of a black
2219 + * background, where PREMULTI and PIXEL_NONE are equivalent.
2220 + */
2221 + if (plane_cap && plane_cap->type != DC_PLANE_TYPE_DCN_UNIVERSAL) {
2222 + unsigned int blend_caps = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2223 + BIT(DRM_MODE_BLEND_PREMULTI);
2224 +
2225 + drm_plane_create_blend_mode_property(plane, blend_caps);
2226 + } else if ((plane->type == DRM_PLANE_TYPE_OVERLAY ||
2227 + plane->type == DRM_PLANE_TYPE_PRIMARY) &&
2228 + plane_cap && plane_cap->per_pixel_alpha) {
2213 2229 unsigned int blend_caps = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2214 2230 BIT(DRM_MODE_BLEND_PREMULTI) |
2215 2231 BIT(DRM_MODE_BLEND_COVERAGE);
2216 2232
2217 - drm_plane_create_alpha_property(plane);
2218 2233 drm_plane_create_blend_mode_property(plane, blend_caps);
2234 +
2235 + if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2236 + drm_plane_create_alpha_property(plane);
2219 2237 }
2220 2238
2239 + /* Cursor color format is set to CURSOR_MODE_COLOR_PRE_MULTIPLIED_ALPHA
2240 + * by default, so only advertise DRM_MODE_BLEND_PREMULTI blend mode for
2241 + * this type of plane.
2242 + */
2243 + if (plane->type == DRM_PLANE_TYPE_CURSOR)
2244 + drm_plane_create_blend_mode_property(plane, BIT(DRM_MODE_BLEND_PREMULTI));
2245 +
2221 2246 if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
2222 2247 /*
2223 2248 * Allow OVERLAY planes to be used as underlays by assigning an
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -4180,7 +4180,7 @@ dm_test_destroy_connector(struct kunit *test, struct drm_device *drm)
4180 4180 {
4181 4181 struct amdgpu_dm_connector *aconnector;
4182 4182
4183 - aconnector = kzalloc(sizeof(*aconnector), GFP_KERNEL);
4183 + aconnector = kzalloc_obj(*aconnector);
4184 4184 KUNIT_ASSERT_NOT_NULL(test, aconnector);
4185 4185
4186 4186 KUNIT_ASSERT_EQ(test,
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c
@@ -1445,7 +1445,7 @@ static void dm_test_crtc_destroy_state_no_stream(struct kunit *test)
1445 1445 struct dm_crtc_state *dm_state;
1446 1446
1447 1447 /* destroy_state kfree()s the state, so use a plain (unmanaged) alloc. */
1448 - dm_state = kzalloc_obj(*dm_state, GFP_KERNEL);
1448 + dm_state = kzalloc_obj(*dm_state);
1449 1449 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm_state);
1450 1450
1451 1451 amdgpu_dm_crtc_destroy_state(NULL, &dm_state->base);
@@ -1475,7 +1475,7 @@ static void dm_test_crtc_destroy_state_releases_stream(struct kunit *test)
1475 1475 kref_get(&stream->refcount);
1476 1476
1477 1477 /* destroy_state kfree()s the state, so use a plain (unmanaged) alloc. */
1478 - dm_state = kzalloc_obj(*dm_state, GFP_KERNEL);
1478 + dm_state = kzalloc_obj(*dm_state);
1479 1479 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dm_state);
1480 1480 dm_state->stream = stream;
1481 1481
@@ -1569,7 +1569,7 @@ static void dm_test_crtc_handle_vblank_completes_cursor_only(struct kunit *test)
1569 1569 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, acrtc);
1570 1570
1571 1571 /* drm_crtc_send_vblank_event() consumes (kfree()s) the event. */
1572 - event = kzalloc_obj(*event, GFP_KERNEL);
1572 + event = kzalloc_obj(*event);
1573 1573 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, event);
1574 1574
1575 1575 acrtc->base.dev = &adev->ddev;
@@ -1628,7 +1628,7 @@ dm_test_vblank_control_worker_setup(struct kunit *test, bool enable,
1628 1628 kref_get(&stream->refcount);
1629 1629
1630 1630 /* Worker kfree()s the work item, so it must be a plain allocation. */
1631 - work = kzalloc_obj(*work, GFP_KERNEL);
1631 + work = kzalloc_obj(*work);
1632 1632 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, work);
1633 1633 work->dm = &adev->dm;
1634 1634 work->acrtc = acrtc;
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c
@@ -103,7 +103,7 @@ static enum dc_status dm_test_dp_read_hpd_rx_irq_data_ok(struct dc_link *link,
103 103 */
104 104 static struct dc_sink *dm_test_sink_create(struct dc_link *link)
105 105 {
106 - struct dc_sink *sink = kzalloc(sizeof(*sink), GFP_KERNEL);
106 + struct dc_sink *sink = kzalloc_obj(*sink);
107 107
108 108 if (!sink)
109 109 return NULL;
@@ -2131,7 +2131,7 @@ static void dm_test_hpd_rx_offload_work_no_connector(struct kunit *test)
2131 2131 offload_wq = kunit_kzalloc(test, sizeof(*offload_wq), GFP_KERNEL);
2132 2132 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_wq);
2133 2133
2134 - offload_work = kzalloc(sizeof(*offload_work), GFP_KERNEL);
2134 + offload_work = kzalloc_obj(*offload_work);
2135 2135 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_work);
2136 2136 offload_work->offload_wq = offload_wq;
2137 2137 offload_work->adev = adev;
@@ -2177,7 +2177,7 @@ static void dm_test_hpd_rx_offload_work_no_connection(struct kunit *test)
2177 2177 link->dc = dc;
2178 2178 aconn->dc_link = link;
2179 2179
2180 - offload_work = kzalloc(sizeof(*offload_work), GFP_KERNEL);
2180 + offload_work = kzalloc_obj(*offload_work);
2181 2181 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_work);
2182 2182 offload_work->offload_wq = offload_wq;
2183 2183 offload_work->adev = adev;
@@ -2244,7 +2244,7 @@ static void dm_test_hpd_rx_offload_work_automated_test(struct kunit *test)
2244 2244 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
2245 2245 aconn->dc_link = link;
2246 2246
2247 - offload_work = kzalloc(sizeof(*offload_work), GFP_KERNEL);
2247 + offload_work = kzalloc_obj(*offload_work);
2248 2248 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_work);
2249 2249 offload_work->offload_wq = offload_wq;
2250 2250 offload_work->adev = adev;
@@ -2315,7 +2315,7 @@ static void dm_test_hpd_rx_offload_work_link_loss(struct kunit *test)
2315 2315 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
2316 2316 aconn->dc_link = link;
2317 2317
2318 - offload_work = kzalloc(sizeof(*offload_work), GFP_KERNEL);
2318 + offload_work = kzalloc_obj(*offload_work);
2319 2319 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, offload_work);
2320 2320 offload_work->offload_wq = offload_wq;
2321 2321 offload_work->adev = adev;
@@ -3452,9 +3452,9 @@ static void dm_test_handle_hpd_work_out_of_range(struct kunit *test)
3452 3452 struct amdgpu_device *adev;
3453 3453
3454 3454 adev = dm_kunit_alloc_adev(test);
3455 - hpd_work = kzalloc(sizeof(*hpd_work), GFP_KERNEL);
3455 + hpd_work = kzalloc_obj(*hpd_work);
3456 3456 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hpd_work);
3457 - hpd_work->dmub_notify = kzalloc(sizeof(*hpd_work->dmub_notify), GFP_KERNEL);
3457 + hpd_work->dmub_notify = kzalloc_obj(*hpd_work->dmub_notify);
3458 3458 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hpd_work->dmub_notify);
3459 3459 hpd_work->dmub_notify->type =
3460 3460 (enum dmub_notification_type)ARRAY_SIZE(adev->dm.dmub_callback);
@@ -3899,9 +3899,9 @@ static void dm_test_handle_vmin_vmax_update(struct kunit *test)
3899 3899 kref_get(&stream->refcount);
3900 3900
3901 3901 /* The worker kfree()s both, so they must come from the slab. */
3902 - work = kzalloc(sizeof(*work), GFP_KERNEL);
3902 + work = kzalloc_obj(*work);
3903 3903 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, work);
3904 - adjust = kzalloc(sizeof(*adjust), GFP_KERNEL);
3904 + adjust = kzalloc_obj(*adjust);
3905 3905 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adjust);
3906 3906
3907 3907 work->adev = adev;
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_plane_test.c
@@ -2945,7 +2945,7 @@ static void dm_test_plane_reset_initializes_state(struct kunit *test)
2945 2945 * destroy-existing-state path. The destroy hook frees this state, so it
2946 2946 * must be a plain (non-KUnit-managed) allocation.
2947 2947 */
2948 - old_state = kzalloc(sizeof(*old_state), GFP_KERNEL);
2948 + old_state = kzalloc_obj(*old_state);
2949 2949 KUNIT_ASSERT_NOT_NULL(test, old_state);
2950 2950 plane->funcs = &dm_test_plane_reset_funcs;
2951 2951 plane->state = &old_state->base;
@@ -3018,7 +3018,7 @@ static void dm_test_plane_destroy_state_minimal(struct kunit *test)
3018 3018 KUNIT_ASSERT_NOT_NULL(test, plane);
3019 3019
3020 3020 /* destroy_state frees the state itself, so use a plain allocation. */
3021 - dm_plane_state = kzalloc(sizeof(*dm_plane_state), GFP_KERNEL);
3021 + dm_plane_state = kzalloc_obj(*dm_plane_state);
3022 3022 KUNIT_ASSERT_NOT_NULL(test, dm_plane_state);
3023 3023
3024 3024 amdgpu_dm_plane_drm_plane_destroy_state(plane, &dm_plane_state->base);
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_test.c
@@ -239,7 +239,7 @@ static void dm_test_atomic_destroy_state_no_context(struct kunit *test)
239 239 * Use kzalloc(), not kunit_kzalloc(): dm_atomic_destroy_state() frees
240 240 * the state itself, so KUnit-managed memory would be double-freed.
241 241 */
242 - dm_state = kzalloc(sizeof(*dm_state), GFP_KERNEL);
242 + dm_state = kzalloc_obj(*dm_state);
243 243 KUNIT_ASSERT_NOT_NULL(test, dm_state);
244 244
245 245 /* context == NULL: dc_state_release() is skipped and the state is freed. */
modified drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c
@@ -377,7 +377,7 @@ struct clk_mgr *dc_clk_mgr_create(struct dc_context *ctx, struct pp_smu_funcs *p
377 377 }
378 378 break;
379 379 case AMDGPU_FAMILY_GC_11_5_4: {
380 - struct clk_mgr_dcn42 *clk_mgr = kzalloc(sizeof(*clk_mgr), GFP_KERNEL);
380 + struct clk_mgr_dcn42 *clk_mgr = kzalloc_obj(*clk_mgr);
381 381
382 382 if (clk_mgr == NULL) {
383 383 BREAK_TO_DEBUGGER();
modified drivers/gpu/drm/amd/display/dc/clk_mgr/dcn60/dcn60_clk_mgr.c
@@ -1595,7 +1595,7 @@ struct clk_mgr_internal *dcn60_clk_mgr_construct(
1595 1595 struct dccg *dccg)
1596 1596 {
1597 1597 struct clk_log_info log_info = {0};
1598 - struct dcn60_clk_mgr *clk_mgr60 = kzalloc(sizeof(struct dcn60_clk_mgr), GFP_KERNEL);
1598 + struct dcn60_clk_mgr *clk_mgr60 = kzalloc_obj(struct dcn60_clk_mgr);
1599 1599 struct clk_mgr_internal *clk_mgr;
1600 1600
1601 1601 if (!clk_mgr60)
@@ -1644,7 +1644,7 @@ struct clk_mgr_internal *dcn60_clk_mgr_construct(
1644 1644
1645 1645 clk_mgr->smu_present = false;
1646 1646
1647 - clk_mgr->base.bw_params = kzalloc(sizeof(*clk_mgr->base.bw_params), GFP_KERNEL);
1647 + clk_mgr->base.bw_params = kzalloc_obj(*clk_mgr->base.bw_params);
1648 1648 if (!clk_mgr->base.bw_params)
1649 1649 goto fail;
1650 1650
modified drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -914,8 +914,7 @@ static bool dc_construct_update_scratch_pool(struct dc *dc)
914 914 unsigned int i;
915 915
916 916 for (i = 0; i < ARRAY_SIZE(dc->update_scratch_pool); i++) {
917 - dc->update_scratch_pool[i] = kzalloc(
918 - sizeof(struct dc_update_scratch_space), GFP_KERNEL);
917 + dc->update_scratch_pool[i] = kzalloc_obj(struct dc_update_scratch_space);
919 918 if (!dc->update_scratch_pool[i])
920 919 return false;
921 920 dc->update_scratch_in_use[i] = false;
modified drivers/gpu/drm/amd/display/dc/core/dc_resource.c
@@ -1797,7 +1797,11 @@ bool resource_can_pipe_disable_cursor(struct pipe_ctx *pipe_ctx)
1797 1797 * pipe-split, merge together per same height.
1798 1798 */
1799 1799 for (split_pipe = pipe_ctx->top_pipe; split_pipe;
1800 - split_pipe = split_pipe->top_pipe)
1800 + split_pipe = split_pipe->top_pipe) {
1801 +
1802 + if (split_pipe == test_pipe)
1803 + continue;
1804 +
1801 1805 if (split_pipe->plane_state->layer_index == test_pipe->plane_state->layer_index) {
1802 1806 struct rect r2_half;
1803 1807
@@ -1809,6 +1813,7 @@ bool resource_can_pipe_disable_cursor(struct pipe_ctx *pipe_ctx)
1809 1813 r2_bottom = min(r2_bottom, r2_half.y + r2_half.height);
1810 1814 break;
1811 1815 }
1816 + }
1812 1817
1813 1818 if (r1.x >= r2.x && r1.y >= r2.y && r1_right <= r2_right && r1_bottom <= r2_bottom)
1814 1819 return true;
modified drivers/gpu/drm/amd/display/dc/core/dc_surface.c
@@ -290,7 +290,7 @@ static void dc_plane_cm_free(struct kref *kref)
290 290
291 291 struct dc_plane_cm *dc_plane_cm_create(void)
292 292 {
293 - struct dc_plane_cm *cm = kvzalloc(sizeof(*cm), GFP_KERNEL);
293 + struct dc_plane_cm *cm = kvzalloc_obj(*cm);
294 294
295 295 if (cm == NULL)
296 296 goto alloc_fail;
modified drivers/gpu/drm/amd/display/dc/dccg/dcn42/dcn42_dccg.c
@@ -358,7 +358,7 @@ struct dccg *dccg42_create(
358 358 const struct dccg_shift *dccg_shift,
359 359 const struct dccg_mask *dccg_mask)
360 360 {
361 - struct dcn_dccg *dccg_dcn = kzalloc(sizeof(*dccg_dcn), GFP_KERNEL);
361 + struct dcn_dccg *dccg_dcn = kzalloc_obj(*dccg_dcn);
362 362 struct dccg *base;
363 363
364 364 if (dccg_dcn == NULL) {
modified drivers/gpu/drm/amd/display/dc/dccg/dcn60/dcn60_dccg.c
@@ -167,7 +167,7 @@ struct dccg *dccg60_create(
167 167 const struct dccg_shift *dccg_shift,
168 168 const struct dccg_mask *dccg_mask)
169 169 {
170 - struct dcn_dccg *dccg_dcn = kzalloc(sizeof(*dccg_dcn), GFP_KERNEL);
170 + struct dcn_dccg *dccg_dcn = kzalloc_obj(*dccg_dcn);
171 171 struct dccg *base;
172 172
173 173 if (dccg_dcn == NULL) {
modified drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c
@@ -320,6 +320,8 @@ static struct fixed31_32 interp_tf_pts(const struct fixed31_32 *output_tf_channe
320 320 return value;
321 321 }
322 322
323 + #define NUM_DEGAMMA_REGIONS 9
324 +
323 325 bool cm3_helper_translate_curve_to_degamma_hw_format(
324 326 const struct dc_transfer_func *output_tf,
325 327 struct pwl_params *lut_params)
@@ -343,31 +345,15 @@ bool cm3_helper_translate_curve_to_degamma_hw_format(
343 345 memset(lut_params, 0, sizeof(struct pwl_params));
344 346 memset(seg_distr, 0, sizeof(seg_distr));
345 347
346 - if (output_tf->tf == TRANSFER_FUNCTION_PQ ||
347 - output_tf->tf == TRANSFER_FUNCTION_SRGB) {
348 - /* 9 segments
349 - * segments are from 2^-9 to 0
350 - */
351 - const uint8_t SEG_COUNT = 9;
352 - seg_distr[0] = 0; // Since we only have one point in darkest region
353 - for (k = 1; k < SEG_COUNT; k++)
354 - seg_distr[k] = k - 1; // 2^(k-1) points per region; halves as k decreases
355 -
356 - region_start = -SEG_COUNT;
357 - region_end = 0;
358 - } else {
359 - /* 12 segments
360 - * segments are from 2^-12 to 2^0
361 - * There are less than 256 points, for optimization
362 - */
363 - const uint8_t SEG_COUNT = 12;
364 -
365 - for (i = 0; i < SEG_COUNT; i++)
366 - seg_distr[i] = 4;
348 + /* 9 segments
349 + * segments are from 2^-9 to 2^0
350 + */
351 + seg_distr[0] = 0; // Since we only have one point in darkest region
352 + for (k = 1; k < NUM_DEGAMMA_REGIONS; k++)
353 + seg_distr[k] = k - 1; // 2^(k-1) points per region; halves as k decreases
367 354
368 - region_start = -SEG_COUNT;
369 - region_end = 0;
370 - }
355 + region_start = -NUM_DEGAMMA_REGIONS;
356 + region_end = 0;
371 357
372 358 for (i = region_end - region_start; i < MAX_REGIONS_NUMBER ; i++)
373 359 seg_distr[i] = -1;
modified drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_dcn5_funcs_mode_programming.c
@@ -1128,8 +1128,8 @@ static bool dcn5_mode_programming(struct dml2_core_calcs_mode_programming_ex *in
1128 1128 CalculateWatermarks_params->USRRetrainingSupport = &mode_lib->mp.USRRetrainingSupport;
1129 1129 CalculateWatermarks_params->temp_read_or_ppt_support = mode_lib->mp.temp_read_or_ppt_support;
1130 1130 CalculateWatermarks_params->global_temp_read_or_ppt_supported = &mode_lib->mp.global_temp_read_or_ppt_supported;
1131 - CalculateWatermarks_params->VActiveLatencyHidingMargin = 0;
1132 - CalculateWatermarks_params->VActiveLatencyHidingUs = 0;
1131 + CalculateWatermarks_params->VActiveLatencyHidingMargin = NULL;
1132 + CalculateWatermarks_params->VActiveLatencyHidingUs = NULL;
1133 1133
1134 1134 dcn5_calculate_watermarks_and_dram_speed_change_support(&mode_lib->scratch, CalculateWatermarks_params);
1135 1135
modified drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_core/dml2_core_shared_types.h
@@ -1819,8 +1819,8 @@ struct dml2_core_calcs_CalculateWatermarksMALLUseAndDRAMSpeedChangeSupport_param
1819 1819 bool UnboundedRequestEnabled;
1820 1820 unsigned int CompressedBufferSizeInkByte;
1821 1821 bool max_outstanding_when_urgent_expected;
1822 - const unsigned int max_outstanding_requests;
1823 - const unsigned int max_request_size_bytes;
1822 + unsigned int max_outstanding_requests;
1823 + unsigned int max_request_size_bytes;
1824 1824 const unsigned int *meta_row_height_l;
1825 1825 const unsigned int *meta_row_height_c;
1826 1826 const enum dml2_pstate_method *uclk_pstate_switch_modes;
modified drivers/gpu/drm/amd/display/dc/dml2_0/dml21/src/dml2_pmo/dml2_pmo_dcn6_stage_optimizers.c
@@ -1414,7 +1414,7 @@ static bool find_shift_for_valid_cache_id_assignment(const int *mcache_boundarie
1414 1414 success = true;
1415 1415 for (pipe_index = 0; pipe_index < pipe_count; pipe_index++) {
1416 1416 if (!calculate_first_second_splitting(mcache_boundaries, num_boundaries, *shift,
1417 - pipe_vp_startx[pipe_index], pipe_vp_endx[pipe_index], 0, 0)) {
1417 + pipe_vp_startx[pipe_index], pipe_vp_endx[pipe_index], NULL, NULL)) {
1418 1418 success = false;
1419 1419 break;
1420 1420 }
modified drivers/gpu/drm/amd/display/dc/dml2_0/dml2_translation_helper.c
@@ -301,6 +301,7 @@ void dml2_init_socbb_params(struct dml2_context *dml2, const struct dc *in_dc, s
301 301 out->smn_latency_us = 2;
302 302 out->dispclk_dppclk_vco_speed_mhz = 3600;
303 303 out->pct_ideal_dram_bw_after_urgent_pixel_only = 65.0;
304 + out->gpuvm_min_page_size_kbytes = 4;
304 305 break;
305 306
306 307
modified drivers/gpu/drm/amd/display/dc/gpio/hw_ddc.c
@@ -542,7 +542,7 @@ void dal_hw_ddc_init_i3cpad(
542 542 *hw_ddc = NULL;
543 543 }
544 544
545 - *hw_ddc = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL);
545 + *hw_ddc = kzalloc_obj(struct hw_ddc);
546 546 if (!*hw_ddc) {
547 547 ASSERT_CRITICAL(false);
548 548 return;
modified drivers/gpu/drm/amd/display/dc/irq/dcn42/irq_service_dcn42.c
@@ -405,7 +405,7 @@ static void dcn42_irq_construct(struct irq_service *irq_service,
405 405
406 406 struct irq_service *dal_irq_service_dcn42_create(struct irq_service_init_data *init_data)
407 407 {
408 - struct irq_service *irq_service = kzalloc(sizeof(*irq_service), GFP_KERNEL);
408 + struct irq_service *irq_service = kzalloc_obj(*irq_service);
409 409
410 410 if (!irq_service)
411 411 return NULL;
modified drivers/gpu/drm/amd/display/dc/irq/dcn60/irq_service_dcn60.c
@@ -406,8 +406,7 @@ static void dcn60_irq_construct(
406 406 struct irq_service *dal_irq_service_dcn60_create(
407 407 struct irq_service_init_data *init_data)
408 408 {
409 - struct irq_service *irq_service = kzalloc(sizeof(*irq_service),
410 - GFP_KERNEL);
409 + struct irq_service *irq_service = kzalloc_obj(*irq_service);
411 410
412 411 if (!irq_service)
413 412 return NULL;
modified drivers/gpu/drm/amd/display/dc/pg/dcn42/dcn42_pg_cntl.c
@@ -615,7 +615,7 @@ struct pg_cntl *pg_cntl42_create(
615 615 const struct pg_cntl_shift *pg_cntl_shift,
616 616 const struct pg_cntl_mask *pg_cntl_mask)
617 617 {
618 - struct dcn_pg_cntl *pg_cntl_dcn = kzalloc(sizeof(*pg_cntl_dcn), GFP_KERNEL);
618 + struct dcn_pg_cntl *pg_cntl_dcn = kzalloc_obj(*pg_cntl_dcn);
619 619 struct pg_cntl *base;
620 620
621 621 if (pg_cntl_dcn == NULL) {
modified drivers/gpu/drm/amd/display/dc/resource/dcn30/dcn30_resource.c
@@ -1135,7 +1135,7 @@ static struct hpo_frl_stream_encoder *dcn30_hpo_frl_stream_encoder_create(enum e
1135 1135 }
1136 1136
1137 1137 /* allocate HPO stream encoder and create VPG sub-block */
1138 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1138 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1139 1139 vpg = dcn30_vpg_create(ctx, vpg_inst);
1140 1140 afmt = dcn30_afmt_create(ctx, afmt_inst);
1141 1141
@@ -1166,7 +1166,7 @@ static struct hpo_frl_link_encoder *dcn30_hpo_frl_link_encoder_create(enum engin
1166 1166 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
1167 1167
1168 1168 /* allocate HPO link encoder */
1169 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1169 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1170 1170 if (!hpo_enc3)
1171 1171 return NULL; /* out of memory */
1172 1172
modified drivers/gpu/drm/amd/display/dc/resource/dcn302/dcn302_resource.c
@@ -492,7 +492,7 @@ static struct hpo_frl_stream_encoder *dcn302_hpo_frl_stream_encoder_create(enum
492 492 return NULL;
493 493
494 494 /* allocate HPO stream encoder and create VPG sub-block */
495 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
495 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
496 496 vpg = dcn302_vpg_create(ctx, vpg_inst);
497 497 afmt = dcn302_afmt_create(ctx, afmt_inst);
498 498
@@ -531,7 +531,7 @@ static struct hpo_frl_link_encoder *dcn302_hpo_frl_link_encoder_create(enum engi
531 531 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
532 532
533 533 /* allocate HPO link encoder */
534 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
534 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
535 535 if (!hpo_enc3)
536 536 return NULL; /* out of memory */
537 537
modified drivers/gpu/drm/amd/display/dc/resource/dcn303/dcn303_resource.c
@@ -479,7 +479,7 @@ static struct hpo_frl_stream_encoder *dcn303_hpo_frl_stream_encoder_create(enum
479 479 return NULL;
480 480
481 481 /* allocate HPO stream encoder and create VPG sub-block */
482 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
482 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
483 483 vpg = dcn303_vpg_create(ctx, vpg_inst);
484 484 afmt = dcn303_afmt_create(ctx, afmt_inst);
485 485
@@ -518,7 +518,7 @@ static struct hpo_frl_link_encoder *dcn303_hpo_frl_link_encoder_create(enum engi
518 518 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
519 519
520 520 /* allocate HPO link encoder */
521 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
521 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
522 522 if (!hpo_enc3)
523 523 return NULL; /* out of memory */
524 524
modified drivers/gpu/drm/amd/display/dc/resource/dcn31/dcn31_resource.c
@@ -1346,7 +1346,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(enum e
1346 1346 }
1347 1347
1348 1348 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1349 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1349 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1350 1350 vpg = dcn31_vpg_create(ctx, vpg_inst);
1351 1351 afmt = dcn31_afmt_create(ctx, afmt_inst);
1352 1352
@@ -1377,7 +1377,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(enum engin
1377 1377 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
1378 1378
1379 1379 /* allocate HPO link encoder */
1380 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1380 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1381 1381 if (!hpo_enc3)
1382 1382 return NULL; /* out of memory */
1383 1383
modified drivers/gpu/drm/amd/display/dc/resource/dcn314/dcn314_resource.c
@@ -1404,7 +1404,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(enum e
1404 1404 }
1405 1405
1406 1406 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1407 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1407 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1408 1408 vpg = dcn31_vpg_create(ctx, vpg_inst);
1409 1409 afmt = dcn31_afmt_create(ctx, afmt_inst);
1410 1410
@@ -1436,7 +1436,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(enum engin
1436 1436 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
1437 1437
1438 1438 /* allocate HPO link encoder */
1439 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1439 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1440 1440 if (!hpo_enc3)
1441 1441 return NULL; /* out of memory */
1442 1442
modified drivers/gpu/drm/amd/display/dc/resource/dcn315/dcn315_resource.c
@@ -1347,7 +1347,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(enum e
1347 1347 }
1348 1348
1349 1349 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1350 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1350 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1351 1351 vpg = dcn31_vpg_create(ctx, vpg_inst);
1352 1352 afmt = dcn31_afmt_create(ctx, afmt_inst);
1353 1353
@@ -1379,7 +1379,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(enum engin
1379 1379 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
1380 1380
1381 1381 /* allocate HPO link encoder */
1382 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1382 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1383 1383 if (!hpo_enc3)
1384 1384 return NULL; /* out of memory */
1385 1385
modified drivers/gpu/drm/amd/display/dc/resource/dcn316/dcn316_resource.c
@@ -1340,7 +1340,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(enum e
1340 1340 }
1341 1341
1342 1342 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1343 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1343 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1344 1344 vpg = dcn31_vpg_create(ctx, vpg_inst);
1345 1345 afmt = dcn31_afmt_create(ctx, afmt_inst);
1346 1346
@@ -1372,7 +1372,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(enum engin
1372 1372 ASSERT((eng_id == ENGINE_ID_HPO_0) || (eng_id == ENGINE_ID_HPO_1));
1373 1373
1374 1374 /* allocate HPO link encoder */
1375 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1375 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1376 1376 if (!hpo_enc3)
1377 1377 return NULL; /* out of memory */
1378 1378
modified drivers/gpu/drm/amd/display/dc/resource/dcn32/dcn32_resource.c
@@ -1339,7 +1339,7 @@ static struct hpo_frl_stream_encoder *dcn32_hpo_frl_stream_encoder_create(enum e
1339 1339 }
1340 1340
1341 1341 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1342 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1342 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1343 1343 vpg = dcn32_vpg_create(ctx, vpg_inst);
1344 1344 afmt = dcn32_afmt_create(ctx, afmt_inst);
1345 1345
@@ -1375,7 +1375,7 @@ static struct hpo_frl_link_encoder *dcn32_hpo_frl_link_encoder_create(enum engin
1375 1375 hpo_frl_link_encoder_reg_list(0);
1376 1376
1377 1377 /* allocate HPO link encoder */
1378 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1378 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1379 1379 if (!hpo_enc3)
1380 1380 return NULL; /* out of memory */
1381 1381
modified drivers/gpu/drm/amd/display/dc/resource/dcn321/dcn321_resource.c
@@ -1314,7 +1314,7 @@ static struct hpo_frl_stream_encoder *dcn321_hpo_frl_stream_encoder_create(enum
1314 1314 }
1315 1315
1316 1316 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1317 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1317 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1318 1318 vpg = dcn321_vpg_create(ctx, vpg_inst);
1319 1319 afmt = dcn321_afmt_create(ctx, afmt_inst);
1320 1320
@@ -1350,7 +1350,7 @@ static struct hpo_frl_link_encoder *dcn321_hpo_frl_link_encoder_create(enum engi
1350 1350 hpo_frl_link_encoder_reg_list(0);
1351 1351
1352 1352 /* allocate HPO link encoder */
1353 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1353 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1354 1354 if (!hpo_enc3)
1355 1355 return NULL; /* out of memory */
1356 1356
modified drivers/gpu/drm/amd/display/dc/resource/dcn35/dcn35_resource.c
@@ -1398,7 +1398,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(
1398 1398 return NULL;
1399 1399
1400 1400 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1401 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1401 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1402 1402 vpg = dcn31_vpg_create(ctx, vpg_inst);
1403 1403 afmt = dcn31_afmt_create(ctx, afmt_inst);
1404 1404
@@ -1430,7 +1430,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(
1430 1430 hpo_frl_link_encoder_reg_list(0);
1431 1431
1432 1432 /* allocate HPO link encoder */
1433 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1433 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1434 1434 if (!hpo_enc3)
1435 1435 return NULL; /* out of memory */
1436 1436
modified drivers/gpu/drm/amd/display/dc/resource/dcn351/dcn351_resource.c
@@ -1378,7 +1378,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(
1378 1378 return NULL;
1379 1379
1380 1380 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1381 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1381 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1382 1382 vpg = dcn31_vpg_create(ctx, vpg_inst);
1383 1383 afmt = dcn31_afmt_create(ctx, afmt_inst);
1384 1384
@@ -1410,7 +1410,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(
1410 1410 hpo_frl_link_encoder_reg_list(0);
1411 1411
1412 1412 /* allocate HPO link encoder */
1413 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1413 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1414 1414 if (!hpo_enc3)
1415 1415 return NULL; /* out of memory */
1416 1416
modified drivers/gpu/drm/amd/display/dc/resource/dcn36/dcn36_resource.c
@@ -1385,7 +1385,7 @@ static struct hpo_frl_stream_encoder *dcn31_hpo_frl_stream_encoder_create(
1385 1385 return NULL;
1386 1386
1387 1387 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1388 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_stream_encoder), GFP_KERNEL);
1388 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_stream_encoder);
1389 1389 vpg = dcn31_vpg_create(ctx, vpg_inst);
1390 1390 afmt = dcn31_afmt_create(ctx, afmt_inst);
1391 1391
@@ -1417,7 +1417,7 @@ static struct hpo_frl_link_encoder *dcn31_hpo_frl_link_encoder_create(
1417 1417 hpo_frl_link_encoder_reg_list(0);
1418 1418
1419 1419 /* allocate HPO link encoder */
1420 - hpo_enc3 = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1420 + hpo_enc3 = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1421 1421 if (!hpo_enc3)
1422 1422 return NULL; /* out of memory */
1423 1423
modified drivers/gpu/drm/amd/display/dc/resource/dcn401/dcn401_resource.c
@@ -1322,7 +1322,7 @@ static struct hpo_frl_stream_encoder *dcn401_hpo_frl_stream_encoder_create(
1322 1322 return NULL;
1323 1323
1324 1324 /* allocate HPO stream encoder and create VPG, AFMT sub-blocks */
1325 - hpo_enc401 = kzalloc(sizeof(struct dcn401_hpo_frl_stream_encoder), GFP_KERNEL);
1325 + hpo_enc401 = kzalloc_obj(struct dcn401_hpo_frl_stream_encoder);
1326 1326 vpg = dcn401_vpg_create(ctx, vpg_inst);
1327 1327 afmt = dcn401_afmt_create(ctx, afmt_inst);
1328 1328
@@ -1353,7 +1353,7 @@ static struct hpo_frl_link_encoder *dcn401_hpo_frl_link_encoder_create(
1353 1353 hpo_frl_link_encoder_reg_list(0);
1354 1354
1355 1355 /* allocate HPO link encoder */
1356 - hpo_link_enc = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1356 + hpo_link_enc = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1357 1357 if (!hpo_link_enc)
1358 1358 return NULL; /* out of memory */
1359 1359
modified drivers/gpu/drm/amd/display/dc/resource/dcn42/dcn42_resource.c
@@ -818,7 +818,7 @@ static struct dce_aux *dcn42_aux_engine_create(
818 818 uint32_t inst)
819 819 {
820 820 struct aux_engine_dce110 *aux_engine =
821 - kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
821 + kzalloc_obj(struct aux_engine_dce110);
822 822
823 823 if (!aux_engine)
824 824 return NULL;
@@ -884,7 +884,7 @@ static struct dce_i2c_hw *dcn42_i2c_hw_create(
884 884 uint32_t inst)
885 885 {
886 886 struct dce_i2c_hw *dce_i2c_hw =
887 - kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
887 + kzalloc_obj(struct dce_i2c_hw);
888 888
889 889 if (!dce_i2c_hw)
890 890 return NULL;
@@ -910,7 +910,7 @@ static struct clock_source *dcn42_clock_source_create(
910 910 bool dp_clk_src)
911 911 {
912 912 struct dce110_clk_src *clk_src =
913 - kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
913 + kzalloc_obj(struct dce110_clk_src);
914 914
915 915 if (!clk_src)
916 916 return NULL;
@@ -929,8 +929,7 @@ static struct hubbub *dcn42_hubbub_create(struct dc_context *ctx)
929 929 {
930 930 int i;
931 931
932 - struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub),
933 - GFP_KERNEL);
932 + struct dcn20_hubbub *hubbub3 = kzalloc_obj(struct dcn20_hubbub);
934 933
935 934 if (!hubbub3)
936 935 return NULL;
@@ -983,7 +982,7 @@ static struct hubp *dcn42_hubp_create(
983 982 uint32_t inst)
984 983 {
985 984 struct dcn20_hubp *hubp2 =
986 - kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
985 + kzalloc_obj(struct dcn20_hubp);
987 986
988 987 if (!hubp2)
989 988 return NULL;
@@ -1025,7 +1024,7 @@ static struct dpp *dcn42_dpp_create(
1025 1024 uint32_t inst)
1026 1025 {
1027 1026 struct dcn42_dpp *dpp42 =
1028 - kzalloc(sizeof(struct dcn42_dpp), GFP_KERNEL);
1027 + kzalloc_obj(struct dcn42_dpp);
1029 1028
1030 1029 if (!dpp42)
1031 1030 return NULL;
@@ -1051,8 +1050,7 @@ static struct mpc *dcn42_mpc_create(
1051 1050 int num_mpcc,
1052 1051 int num_rmu)
1053 1052 {
1054 - struct dcn42_mpc *mpc401 = kzalloc(sizeof(struct dcn42_mpc),
1055 - GFP_KERNEL);
1053 + struct dcn42_mpc *mpc401 = kzalloc_obj(struct dcn42_mpc);
1056 1054
1057 1055 if (!mpc401)
1058 1056 return NULL;
@@ -1075,7 +1073,7 @@ static struct output_pixel_processor *dcn42_opp_create(
1075 1073 struct dc_context *ctx, uint32_t inst)
1076 1074 {
1077 1075 struct dcn20_opp *opp4 =
1078 - kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1076 + kzalloc_obj(struct dcn20_opp);
1079 1077
1080 1078 if (!opp4) {
1081 1079 BREAK_TO_DEBUGGER();
@@ -1098,7 +1096,7 @@ static struct timing_generator *dcn42_timing_generator_create(
1098 1096 uint32_t instance)
1099 1097 {
1100 1098 struct optc *tgn10 =
1101 - kzalloc(sizeof(struct optc), GFP_KERNEL);
1099 + kzalloc_obj(struct optc);
1102 1100
1103 1101 if (!tgn10)
1104 1102 return NULL;
@@ -1136,7 +1134,7 @@ static struct link_encoder *dcn42_link_encoder_create(
1136 1134 const struct encoder_init_data *enc_init_data)
1137 1135 {
1138 1136 struct dcn20_link_encoder *enc20 =
1139 - kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1137 + kzalloc_obj(struct dcn20_link_encoder);
1140 1138
1141 1139 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
1142 1140 return NULL;
@@ -1202,7 +1200,7 @@ static struct vpg *dcn42_vpg_create(
1202 1200 struct dc_context *ctx,
1203 1201 uint32_t inst)
1204 1202 {
1205 - struct dcn31_vpg *vpg4 = kzalloc(sizeof(struct dcn31_vpg), GFP_KERNEL);
1203 + struct dcn31_vpg *vpg4 = kzalloc_obj(struct dcn31_vpg);
1206 1204
1207 1205 if (!vpg4)
1208 1206 return NULL;
@@ -1231,7 +1229,7 @@ static struct apg *dcn42_apg_create(
1231 1229 struct dc_context *ctx,
1232 1230 uint32_t inst)
1233 1231 {
1234 - struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1232 + struct dcn31_apg *apg31 = kzalloc_obj(struct dcn31_apg);
1235 1233
1236 1234 if (!apg31)
1237 1235 return NULL;
@@ -1275,7 +1273,7 @@ static struct stream_encoder *dcn42_stream_encoder_create(
1275 1273 } else
1276 1274 return NULL;
1277 1275
1278 - enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1276 + enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1279 1277 vpg = dcn42_vpg_create(ctx, vpg_inst);
1280 1278 apg = dcn42_apg_create(ctx, apg_inst);
1281 1279
@@ -1325,7 +1323,7 @@ static struct hpo_frl_stream_encoder *dcn42_hpo_frl_stream_encoder_create(
1325 1323 return NULL;
1326 1324
1327 1325 /* allocate HPO stream encoder and create VPG sub-block */
1328 - hpo_enc42 = kzalloc(sizeof(struct dcn42_hpo_frl_stream_encoder), GFP_KERNEL);
1326 + hpo_enc42 = kzalloc_obj(struct dcn42_hpo_frl_stream_encoder);
1329 1327 vpg = dcn42_vpg_create(ctx, vpg_inst);
1330 1328 apg = dcn42_apg_create(ctx, apg_inst);
1331 1329
@@ -1357,7 +1355,7 @@ static struct hpo_frl_link_encoder *dcn42_hpo_frl_link_encoder_create(
1357 1355 hpo_frl_link_encoder_reg_list(0);
1358 1356
1359 1357 /* allocate HPO link encoder */
1360 - hpo_link_enc = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1358 + hpo_link_enc = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1361 1359 if (!hpo_link_enc)
1362 1360 return NULL; /* out of memory */
1363 1361
@@ -1399,7 +1397,7 @@ static struct hpo_dp_stream_encoder *dcn42_hpo_dp_stream_encoder_create(
1399 1397 apg_inst = hpo_dp_inst + 5;
1400 1398
1401 1399 /* allocate HPO stream encoder and create VPG sub-block */
1402 - hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1400 + hpo_dp_enc31 = kzalloc_obj(struct dcn31_hpo_dp_stream_encoder);
1403 1401 vpg = dcn42_vpg_create(ctx, vpg_inst);
1404 1402 apg = dcn42_apg_create(ctx, apg_inst);
1405 1403
@@ -1432,7 +1430,7 @@ static struct hpo_dp_link_encoder *dcn42_hpo_dp_link_encoder_create(
1432 1430 struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1433 1431
1434 1432 /* allocate HPO link encoder */
1435 - hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1433 + hpo_dp_enc31 = kzalloc_obj(struct dcn31_hpo_dp_link_encoder);
1436 1434 if (!hpo_dp_enc31)
1437 1435 return NULL; /* out of memory */
1438 1436
@@ -1453,7 +1451,7 @@ static struct hpo_dp_link_encoder *dcn42_hpo_dp_link_encoder_create(
1453 1451 static struct dce_hwseq *dcn42_hwseq_create(
1454 1452 struct dc_context *ctx)
1455 1453 {
1456 - struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1454 + struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1457 1455
1458 1456 #undef REG_STRUCT
1459 1457 #define REG_STRUCT hwseq_reg
@@ -1727,8 +1725,7 @@ static bool dcn42_dwbc_create(struct dc_context *ctx, struct resource_pool *pool
1727 1725 uint32_t dwb_count = pool->res_cap->num_dwb;
1728 1726
1729 1727 for (i = 0; i < dwb_count; i++) {
1730 - struct dcn30_dwbc *dwbc42 = kzalloc(sizeof(struct dcn30_dwbc),
1731 - GFP_KERNEL);
1728 + struct dcn30_dwbc *dwbc42 = kzalloc_obj(struct dcn30_dwbc);
1732 1729
1733 1730 if (!dwbc42) {
1734 1731 dm_error("DC: failed to create dwbc42!\n");
@@ -1764,8 +1761,7 @@ static bool dcn42_mmhubbub_create(struct dc_context *ctx, struct resource_pool *
1764 1761 uint32_t pipe_count = pool->res_cap->num_dwb;
1765 1762
1766 1763 for (i = 0; i < pipe_count; i++) {
1767 - struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1768 - GFP_KERNEL);
1764 + struct dcn30_mmhubbub *mcif_wb30 = kzalloc_obj(struct dcn30_mmhubbub);
1769 1765
1770 1766 if (!mcif_wb30) {
1771 1767 dm_error("DC: failed to create mcif_wb30!\n");
@@ -1793,7 +1789,7 @@ static struct display_stream_compressor *dcn42_dsc_create(
1793 1789 struct dc_context *ctx, uint32_t inst)
1794 1790 {
1795 1791 struct dcn401_dsc *dsc =
1796 - kzalloc(sizeof(struct dcn401_dsc), GFP_KERNEL);
1792 + kzalloc_obj(struct dcn401_dsc);
1797 1793
1798 1794 if (!dsc) {
1799 1795 BREAK_TO_DEBUGGER();
@@ -1890,7 +1886,7 @@ static struct link_encoder *dcn42_link_enc_create_minimal(
1890 1886 if ((unsigned int)(eng_id - ENGINE_ID_DIGA) >= ctx->dc->res_pool->res_cap->num_dig_link_enc)
1891 1887 return NULL;
1892 1888
1893 - enc20 = kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1889 + enc20 = kzalloc_obj(struct dcn20_link_encoder);
1894 1890 if (!enc20)
1895 1891 return NULL;
1896 1892
@@ -2441,7 +2437,7 @@ struct resource_pool *dcn42_create_resource_pool(
2441 2437 struct dc *dc)
2442 2438 {
2443 2439 struct dcn42_resource_pool *pool =
2444 - kzalloc(sizeof(struct dcn401_resource_pool), GFP_KERNEL);
2440 + kzalloc_obj(struct dcn42_resource_pool);
2445 2441
2446 2442 if (!pool)
2447 2443 return NULL;
modified drivers/gpu/drm/amd/display/dc/resource/dcn42b/dcn42b_resource.c
@@ -870,7 +870,7 @@ static struct dce_aux *dcn42b_aux_engine_create(
870 870 uint32_t inst)
871 871 {
872 872 struct aux_engine_dce110 *aux_engine =
873 - kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
873 + kzalloc_obj(struct aux_engine_dce110);
874 874
875 875 if (!aux_engine)
876 876 return NULL;
@@ -940,7 +940,7 @@ static struct dce_i2c_hw *dcn42b_i2c_hw_create(
940 940 uint32_t inst)
941 941 {
942 942 struct dce_i2c_hw *dce_i2c_hw =
943 - kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
943 + kzalloc_obj(struct dce_i2c_hw);
944 944
945 945 if (!dce_i2c_hw)
946 946 return NULL;
@@ -968,7 +968,7 @@ static struct clock_source *dcn42b_clock_source_create(
968 968 bool dp_clk_src)
969 969 {
970 970 struct dce110_clk_src *clk_src =
971 - kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
971 + kzalloc_obj(struct dce110_clk_src);
972 972
973 973 if (!clk_src)
974 974 return NULL;
@@ -988,8 +988,7 @@ static struct hubbub *dcn42b_hubbub_create(struct dc_context *ctx)
988 988 {
989 989 int i;
990 990
991 - struct dcn20_hubbub *hubbub3 = kzalloc(sizeof(struct dcn20_hubbub),
992 - GFP_KERNEL);
991 + struct dcn20_hubbub *hubbub3 = kzalloc_obj(struct dcn20_hubbub);
993 992
994 993 if (!hubbub3)
995 994 return NULL;
@@ -1042,7 +1041,7 @@ static struct hubp *dcn42b_hubp_create(
1042 1041 uint32_t inst)
1043 1042 {
1044 1043 struct dcn20_hubp *hubp2 =
1045 - kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1044 + kzalloc_obj(struct dcn20_hubp);
1046 1045
1047 1046 if (!hubp2)
1048 1047 return NULL;
@@ -1084,7 +1083,7 @@ static struct dpp *dcn42b_dpp_create(
1084 1083 uint32_t inst)
1085 1084 {
1086 1085 struct dcn42_dpp *dpp42b =
1087 - kzalloc(sizeof(struct dcn42_dpp), GFP_KERNEL);
1086 + kzalloc_obj(struct dcn42_dpp);
1088 1087
1089 1088 if (!dpp42b)
1090 1089 return NULL;
@@ -1110,8 +1109,7 @@ static struct mpc *dcn42b_mpc_create(
1110 1109 int num_mpcc,
1111 1110 int num_rmu)
1112 1111 {
1113 - struct dcn42_mpc *mpc42b = kzalloc(sizeof(struct dcn42_mpc),
1114 - GFP_KERNEL);
1112 + struct dcn42_mpc *mpc42b = kzalloc_obj(struct dcn42_mpc);
1115 1113
1116 1114 if (!mpc42b)
1117 1115 return NULL;
@@ -1134,7 +1132,7 @@ static struct output_pixel_processor *dcn42b_opp_create(
1134 1132 struct dc_context *ctx, uint32_t inst)
1135 1133 {
1136 1134 struct dcn20_opp *opp4 =
1137 - kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1135 + kzalloc_obj(struct dcn20_opp);
1138 1136
1139 1137 if (!opp4) {
1140 1138 BREAK_TO_DEBUGGER();
@@ -1158,7 +1156,7 @@ static struct timing_generator *dcn42b_timing_generator_create(
1158 1156 uint32_t instance)
1159 1157 {
1160 1158 struct optc *tgn10 =
1161 - kzalloc(sizeof(struct optc), GFP_KERNEL);
1159 + kzalloc_obj(struct optc);
1162 1160
1163 1161 if (!tgn10)
1164 1162 return NULL;
@@ -1196,7 +1194,7 @@ static struct link_encoder *dcn42b_link_encoder_create(
1196 1194 const struct encoder_init_data *enc_init_data)
1197 1195 {
1198 1196 struct dcn20_link_encoder *enc20 =
1199 - kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1197 + kzalloc_obj(struct dcn20_link_encoder);
1200 1198
1201 1199 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs))
1202 1200 return NULL;
@@ -1271,7 +1269,7 @@ static struct vpg *dcn42b_vpg_create(
1271 1269 struct dc_context *ctx,
1272 1270 uint32_t inst)
1273 1271 {
1274 - struct dcn31_vpg *vpg4 = kzalloc(sizeof(struct dcn31_vpg), GFP_KERNEL);
1272 + struct dcn31_vpg *vpg4 = kzalloc_obj(struct dcn31_vpg);
1275 1273
1276 1274 if (!vpg4)
1277 1275 return NULL;
@@ -1300,7 +1298,7 @@ static struct apg *dcn42b_apg_create(
1300 1298 struct dc_context *ctx,
1301 1299 uint32_t inst)
1302 1300 {
1303 - struct dcn31_apg *apg31 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1301 + struct dcn31_apg *apg31 = kzalloc_obj(struct dcn31_apg);
1304 1302
1305 1303 if (!apg31)
1306 1304 return NULL;
@@ -1344,7 +1342,7 @@ static struct stream_encoder *dcn42b_stream_encoder_create(
1344 1342 } else
1345 1343 return NULL;
1346 1344
1347 - enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1345 + enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1348 1346 vpg = dcn42b_vpg_create(ctx, vpg_inst);
1349 1347 apg = dcn42b_apg_create(ctx, apg_inst);
1350 1348
@@ -1404,7 +1402,7 @@ static struct hpo_dp_stream_encoder *dcn42b_hpo_dp_stream_encoder_create(
1404 1402 apg_inst = hpo_dp_inst + 6;
1405 1403
1406 1404 /* allocate HPO stream encoder and create VPG sub-block */
1407 - hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1405 + hpo_dp_enc31 = kzalloc_obj(struct dcn31_hpo_dp_stream_encoder);
1408 1406 vpg = dcn42b_vpg_create(ctx, vpg_inst);
1409 1407 apg = dcn42b_apg_create(ctx, apg_inst);
1410 1408
@@ -1437,7 +1435,7 @@ static struct hpo_dp_link_encoder *dcn42b_hpo_dp_link_encoder_create(
1437 1435 struct dcn31_hpo_dp_link_encoder *hpo_dp_enc31;
1438 1436
1439 1437 /* allocate HPO link encoder */
1440 - hpo_dp_enc31 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1438 + hpo_dp_enc31 = kzalloc_obj(struct dcn31_hpo_dp_link_encoder);
1441 1439 if (!hpo_dp_enc31)
1442 1440 return NULL; /* out of memory */
1443 1441
@@ -1457,7 +1455,7 @@ static struct hpo_dp_link_encoder *dcn42b_hpo_dp_link_encoder_create(
1457 1455 static struct dce_hwseq *dcn42b_hwseq_create(
1458 1456 struct dc_context *ctx)
1459 1457 {
1460 - struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1458 + struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1461 1459
1462 1460 #undef REG_STRUCT
1463 1461 #define REG_STRUCT hwseq_reg
@@ -1716,8 +1714,7 @@ static bool dcn42b_dwbc_create(struct dc_context *ctx, struct resource_pool *poo
1716 1714 uint32_t dwb_count = pool->res_cap->num_dwb;
1717 1715
1718 1716 for (i = 0; i < dwb_count; i++) {
1719 - struct dcn30_dwbc *dwbc42 = kzalloc(sizeof(struct dcn30_dwbc),
1720 - GFP_KERNEL);
1717 + struct dcn30_dwbc *dwbc42 = kzalloc_obj(struct dcn30_dwbc);
1721 1718
1722 1719 if (!dwbc42) {
1723 1720 dm_error("DC: failed to create dwbc42!\n");
@@ -1753,8 +1750,7 @@ static bool dcn42b_mmhubbub_create(struct dc_context *ctx, struct resource_pool
1753 1750 uint32_t pipe_count = pool->res_cap->num_dwb;
1754 1751
1755 1752 for (i = 0; i < pipe_count; i++) {
1756 - struct dcn30_mmhubbub *mcif_wb30 = kzalloc(sizeof(struct dcn30_mmhubbub),
1757 - GFP_KERNEL);
1753 + struct dcn30_mmhubbub *mcif_wb30 = kzalloc_obj(struct dcn30_mmhubbub);
1758 1754
1759 1755 if (!mcif_wb30) {
1760 1756 dm_error("DC: failed to create mcif_wb30!\n");
@@ -1782,7 +1778,7 @@ static struct display_stream_compressor *dcn42b_dsc_create(
1782 1778 struct dc_context *ctx, uint32_t inst)
1783 1779 {
1784 1780 struct dcn401_dsc *dsc =
1785 - kzalloc(sizeof(struct dcn401_dsc), GFP_KERNEL);
1781 + kzalloc_obj(struct dcn401_dsc);
1786 1782
1787 1783 if (!dsc) {
1788 1784 BREAK_TO_DEBUGGER();
@@ -1875,7 +1871,7 @@ static struct link_encoder *dcn42b_link_enc_create_minimal(
1875 1871 if ((unsigned int)(eng_id - ENGINE_ID_DIGA) >= ctx->dc->res_pool->res_cap->num_dig_link_enc)
1876 1872 return NULL;
1877 1873
1878 - enc20 = kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1874 + enc20 = kzalloc_obj(struct dcn20_link_encoder);
1879 1875 if (!enc20)
1880 1876 return NULL;
1881 1877
@@ -2439,7 +2435,7 @@ struct resource_pool *dcn42b_create_resource_pool(
2439 2435 struct dc *dc)
2440 2436 {
2441 2437 struct dcn42b_resource_pool *pool =
2442 - kzalloc(sizeof(struct dcn42b_resource_pool), GFP_KERNEL);
2438 + kzalloc_obj(struct dcn42b_resource_pool);
2443 2439
2444 2440 if (!pool)
2445 2441 return NULL;
modified drivers/gpu/drm/amd/display/dc/resource/dcn60/dcn60_resource.c
@@ -998,7 +998,7 @@ static struct dce_aux *dcn60_aux_engine_create(
998 998 uint32_t inst)
999 999 {
1000 1000 struct aux_engine_dce110 *aux_engine =
1001 - kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
1001 + kzalloc_obj(struct aux_engine_dce110);
1002 1002
1003 1003 if (!aux_engine)
1004 1004 return NULL;
@@ -1037,7 +1037,7 @@ static struct dce_i2c_hw *dcn60_i2c_hw_create(
1037 1037 uint32_t inst)
1038 1038 {
1039 1039 struct dce_i2c_hw *dce_i2c_hw =
1040 - kzalloc(sizeof(struct dce_i2c_hw), GFP_KERNEL);
1040 + kzalloc_obj(struct dce_i2c_hw);
1041 1041
1042 1042 if (!dce_i2c_hw)
1043 1043 return NULL;
@@ -1061,7 +1061,7 @@ static struct clock_source *dcn60_clock_source_create(
1061 1061 bool dp_clk_src)
1062 1062 {
1063 1063 struct dce110_clk_src *clk_src =
1064 - kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
1064 + kzalloc_obj(struct dce110_clk_src);
1065 1065
1066 1066 if (!clk_src)
1067 1067 return NULL;
@@ -1081,8 +1081,7 @@ static struct hubbub *dcn60_hubbub_create(struct dc_context *ctx)
1081 1081 {
1082 1082 int i;
1083 1083
1084 - struct dcn20_hubbub *hubbub2 = kzalloc(sizeof(struct dcn20_hubbub),
1085 - GFP_KERNEL);
1084 + struct dcn20_hubbub *hubbub2 = kzalloc_obj(struct dcn20_hubbub);
1086 1085
1087 1086 if (!hubbub2)
1088 1087 return NULL;
@@ -1136,7 +1135,7 @@ static struct hubp *dcn60_hubp_create(
1136 1135 uint32_t inst)
1137 1136 {
1138 1137 struct dcn20_hubp *hubp2 =
1139 - kzalloc(sizeof(struct dcn20_hubp), GFP_KERNEL);
1138 + kzalloc_obj(struct dcn20_hubp);
1140 1139
1141 1140 if (!hubp2)
1142 1141 return NULL;
@@ -1168,7 +1167,7 @@ static struct dpp *dcn60_dpp_create(
1168 1167 uint32_t inst)
1169 1168 {
1170 1169 struct dcn60_dpp *dpp60 =
1171 - kzalloc(sizeof(struct dcn60_dpp), GFP_KERNEL);
1170 + kzalloc_obj(struct dcn60_dpp);
1172 1171
1173 1172 if (!dpp60)
1174 1173 return NULL;
@@ -1194,8 +1193,7 @@ static struct mpc *dcn60_mpc_create(
1194 1193 int num_mpcc,
1195 1194 int num_rmu)
1196 1195 {
1197 - struct dcn60_mpc *mpc60 = kzalloc(sizeof(struct dcn60_mpc),
1198 - GFP_KERNEL);
1196 + struct dcn60_mpc *mpc60 = kzalloc_obj(struct dcn60_mpc);
1199 1197
1200 1198 if (!mpc60)
1201 1199 return NULL;
@@ -1218,7 +1216,7 @@ static struct output_pixel_processor *dcn60_opp_create(
1218 1216 struct dc_context *ctx, uint32_t inst)
1219 1217 {
1220 1218 struct dcn20_opp *opp2 =
1221 - kzalloc(sizeof(struct dcn20_opp), GFP_KERNEL);
1219 + kzalloc_obj(struct dcn20_opp);
1222 1220
1223 1221 if (!opp2) {
1224 1222 BREAK_TO_DEBUGGER();
@@ -1242,7 +1240,7 @@ static struct timing_generator *dcn60_timing_generator_create(
1242 1240 uint32_t instance)
1243 1241 {
1244 1242 struct optc *tgn10 =
1245 - kzalloc(sizeof(struct optc), GFP_KERNEL);
1243 + kzalloc_obj(struct optc);
1246 1244
1247 1245 if (!tgn10)
1248 1246 return NULL;
@@ -1282,7 +1280,7 @@ static struct link_encoder *dcn60_link_encoder_create(
1282 1280 const struct encoder_init_data *enc_init_data)
1283 1281 {
1284 1282 struct dcn20_link_encoder *enc20 =
1285 - kzalloc(sizeof(struct dcn20_link_encoder), GFP_KERNEL);
1283 + kzalloc_obj(struct dcn20_link_encoder);
1286 1284
1287 1285 if (!enc20 || enc_init_data->hpd_source >= ARRAY_SIZE(link_enc_hpd_regs)) {
1288 1286 kfree(enc20);
@@ -1349,7 +1347,7 @@ static struct vpg *dcn60_vpg_create(
1349 1347 struct dc_context *ctx,
1350 1348 uint32_t inst)
1351 1349 {
1352 - struct dcn31_vpg *vpg6 = kzalloc(sizeof(struct dcn31_vpg), GFP_KERNEL);
1350 + struct dcn31_vpg *vpg6 = kzalloc_obj(struct dcn31_vpg);
1353 1351
1354 1352 if (!vpg6)
1355 1353 return NULL;
@@ -1378,7 +1376,7 @@ static struct apg *dcn60_apg_create(
1378 1376 struct dc_context *ctx,
1379 1377 uint32_t inst)
1380 1378 {
1381 - struct dcn31_apg *apg60 = kzalloc(sizeof(struct dcn31_apg), GFP_KERNEL);
1379 + struct dcn31_apg *apg60 = kzalloc_obj(struct dcn31_apg);
1382 1380
1383 1381 if (!apg60)
1384 1382 return NULL;
@@ -1415,7 +1413,7 @@ static struct stream_encoder *dcn60_stream_encoder_create(
1415 1413 } else
1416 1414 return NULL;
1417 1415
1418 - enc1 = kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
1416 + enc1 = kzalloc_obj(struct dcn10_stream_encoder);
1419 1417 vpg = dcn60_vpg_create(ctx, vpg_inst);
1420 1418 apg = dcn60_apg_create(ctx, apg_inst);
1421 1419
@@ -1462,7 +1460,7 @@ static struct hpo_frl_stream_encoder *dcn60_hpo_frl_stream_encoder_create(
1462 1460 return NULL;
1463 1461
1464 1462 /* allocate HPO stream encoder and create VPG, APG sub-blocks */
1465 - hpo_enc60 = kzalloc(sizeof(struct dcn401_hpo_frl_stream_encoder), GFP_KERNEL);
1463 + hpo_enc60 = kzalloc_obj(struct dcn401_hpo_frl_stream_encoder);
1466 1464 vpg = dcn60_vpg_create(ctx, vpg_inst);
1467 1465 apg = dcn60_apg_create(ctx, apg_inst);
1468 1466
@@ -1493,7 +1491,7 @@ static struct hpo_frl_link_encoder *dcn60_hpo_frl_link_encoder_create(
1493 1491 hpo_frl_link_encoder_reg_list(0);
1494 1492
1495 1493 /* allocate HPO link encoder */
1496 - hpo_link_enc = kzalloc(sizeof(struct dcn30_hpo_frl_link_encoder), GFP_KERNEL);
1494 + hpo_link_enc = kzalloc_obj(struct dcn30_hpo_frl_link_encoder);
1497 1495 if (!hpo_link_enc)
1498 1496 return NULL; /* out of memory */
1499 1497
@@ -1535,7 +1533,7 @@ static struct hpo_dp_stream_encoder *dcn60_hpo_dp_stream_encoder_create(
1535 1533 apg_inst = hpo_dp_inst;
1536 1534
1537 1535 /* allocate HPO stream encoder and create VPG sub-block */
1538 - hpo_dp_enc60 = kzalloc(sizeof(struct dcn31_hpo_dp_stream_encoder), GFP_KERNEL);
1536 + hpo_dp_enc60 = kzalloc_obj(struct dcn31_hpo_dp_stream_encoder);
1539 1537 vpg = dcn60_vpg_create(ctx, vpg_inst);
1540 1538 apg = dcn60_apg_create(ctx, apg_inst);
1541 1539
@@ -1568,7 +1566,7 @@ static struct hpo_dp_link_encoder *dcn60_hpo_dp_link_encoder_create(
1568 1566 struct dcn31_hpo_dp_link_encoder *hpo_dp_enc60;
1569 1567
1570 1568 /* allocate HPO link encoder */
1571 - hpo_dp_enc60 = kzalloc(sizeof(struct dcn31_hpo_dp_link_encoder), GFP_KERNEL);
1569 + hpo_dp_enc60 = kzalloc_obj(struct dcn31_hpo_dp_link_encoder);
1572 1570 if (!hpo_dp_enc60)
1573 1571 return NULL; /* out of memory */
1574 1572
@@ -1589,7 +1587,7 @@ static struct hpo_dp_link_encoder *dcn60_hpo_dp_link_encoder_create(
1589 1587 static struct dce_hwseq *dcn60_hwseq_create(
1590 1588 struct dc_context *ctx)
1591 1589 {
1592 - struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
1590 + struct dce_hwseq *hws = kzalloc_obj(struct dce_hwseq);
1593 1591
1594 1592 #undef REG_STRUCT
1595 1593 #define REG_STRUCT hwseq_reg
@@ -1784,7 +1782,7 @@ static struct display_stream_compressor *dcn60_dsc_create(
1784 1782 struct dc_context *ctx, uint32_t inst)
1785 1783 {
1786 1784 struct dcn60_dsc *dsc =
1787 - kzalloc(sizeof(struct dcn60_dsc), GFP_KERNEL);
1785 + kzalloc_obj(struct dcn60_dsc);
1788 1786
1789 1787 if (!dsc) {
1790 1788 BREAK_TO_DEBUGGER();
@@ -2363,7 +2361,7 @@ struct resource_pool *dcn60_create_resource_pool(
2363 2361 struct dc *dc)
2364 2362 {
2365 2363 struct dcn60_resource_pool *pool =
2366 - kzalloc(sizeof(struct dcn60_resource_pool), GFP_KERNEL);
2364 + kzalloc_obj(struct dcn60_resource_pool);
2367 2365
2368 2366 if (!pool)
2369 2367 return NULL;
modified drivers/gpu/drm/amd/display/modules/power/power.c
@@ -111,7 +111,7 @@ struct mod_power *mod_power_create(struct dc *dc,
111 111 if (dc == NULL)
112 112 goto fail_dc_null;
113 113
114 - core_power = kzalloc(sizeof(struct core_power), GFP_KERNEL);
114 + core_power = kzalloc_obj(struct core_power);
115 115
116 116 if (core_power == NULL)
117 117 goto fail_alloc_context;
@@ -129,8 +129,7 @@ struct mod_power *mod_power_create(struct dc *dc,
129 129
130 130 for (i = 0; i < MOD_POWER_MAX_CONCURRENT_STREAMS; i++) {
131 131 core_power->map[i].psr_context =
132 - kzalloc(sizeof(struct mod_power_psr_context),
133 - GFP_KERNEL);
132 + kzalloc_obj(struct mod_power_psr_context);
134 133 if (core_power->map[i].psr_context == NULL)
135 134 goto fail_construct;
136 135 }
modified drivers/gpu/drm/amd/display/modules/power/power_abm.c
@@ -705,8 +705,7 @@ void initialize_backlight_caps(struct core_power *core_power, unsigned int inst)
705 705 * (do not want to use 256 bytes on the stack)
706 706 */
707 707 ext_backlight_caps = (struct dm_acpi_atif_backlight_caps *)
708 - (kzalloc(sizeof(struct dm_acpi_atif_backlight_caps),
709 - GFP_KERNEL));
708 + (kzalloc_obj(struct dm_acpi_atif_backlight_caps));
710 709
711 710 if (ext_backlight_caps == NULL)
712 711 return;
modified drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
@@ -2988,7 +2988,7 @@ static int smu7_init_voltage_dependency_on_display_clock_table(struct pp_hwmgr *
2988 2988 if (!amdgpu_device_ip_get_ip_block(hwmgr->adev, AMD_IP_BLOCK_TYPE_DCE))
2989 2989 return 0;
2990 2990
2991 - table = kzalloc(struct_size(table, entries, 4), GFP_KERNEL);
2991 + table = kzalloc_flex(*table, entries, 4);
2992 2992 if (!table)
2993 2993 return -ENOMEM;
2994 2994
modified drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c
@@ -222,7 +222,7 @@ static int smu_v15_0_8_tables_init(struct smu_context *smu)
222 222
223 223 smu_table->metrics_time = 0;
224 224
225 - driver_pptable = kzalloc(sizeof(PPTable_t), GFP_KERNEL);
225 + driver_pptable = kzalloc_obj(PPTable_t);
226 226 if (!driver_pptable)
227 227 return -ENOMEM;
228 228
@@ -1026,7 +1026,7 @@ static int smu_v15_0_8_fru_get_product_info(struct smu_context *smu,
1026 1026 struct amdgpu_device *adev = smu->adev;
1027 1027
1028 1028 if (!adev->fru_info) {
1029 - adev->fru_info = kzalloc(sizeof(*adev->fru_info), GFP_KERNEL);
1029 + adev->fru_info = kzalloc_obj(*adev->fru_info);
1030 1030 if (!adev->fru_info)
1031 1031 return -ENOMEM;
1032 1032 }
modified drivers/gpu/drm/amd/ras/core/cmd.c
@@ -222,7 +222,7 @@ static int ras_cmd_get_cper_records(struct ras_core_context *ras_core,
222 222 if (!buffer)
223 223 return RAS_CMD__ERROR_GENERIC;
224 224
225 - trace = kcalloc(trace_count, sizeof(*trace), GFP_KERNEL);
225 + trace = kzalloc_objs(*trace, trace_count);
226 226 if (!trace) {
227 227 ret = RAS_CMD__ERROR_GENERIC;
228 228 goto out;
@@ -316,7 +316,7 @@ static int ras_cmd_get_batch_trace_records(struct ras_core_context *ras_core,
316 316 (input_data->start_batch_id >= overview.last_batch_id))
317 317 return RAS_CMD__ERROR_INVALID_INPUT_SIZE;
318 318
319 - trace_arry = kcalloc(trace_count, sizeof(*trace_arry), GFP_KERNEL);
319 + trace_arry = kzalloc_objs(*trace_arry, trace_count);
320 320 if (!trace_arry)
321 321 return RAS_CMD__ERROR_GENERIC;
322 322
modified drivers/gpu/drm/drm_atomic_state_helper.c
@@ -278,7 +278,14 @@ void __drm_atomic_helper_plane_state_init(struct drm_plane_state *plane_state,
278 278 plane_state->rotation = DRM_MODE_ROTATE_0;
279 279
280 280 plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE;
281 +
281 282 plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
283 + if (plane->blend_mode_property) {
284 + if (!drm_object_property_get_default_value(&plane->base,
285 + plane->blend_mode_property,
286 + &val))
287 + plane_state->pixel_blend_mode = val;
288 + }
282 289
283 290 if (plane->color_encoding_property) {
284 291 if (!drm_object_property_get_default_value(&plane->base,
modified drivers/gpu/drm/drm_atomic_uapi.c
@@ -1449,9 +1449,6 @@ static int prepare_signaling(struct drm_device *dev,
1449 1449 if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1450 1450 struct drm_pending_vblank_event *e = crtc_state->event;
1451 1451
1452 - if (!file_priv)
1453 - continue;
1454 -
1455 1452 ret = drm_event_reserve_init(dev, file_priv, &e->base,
1456 1453 &e->event.base);
1457 1454 if (ret) {
@@ -1567,6 +1564,8 @@ static void complete_signaling(struct drm_device *dev,
1567 1564 * to prevent a double free in drm_atomic_commit_clear.
1568 1565 */
1569 1566 if (event && (event->base.fence || event->base.file_priv)) {
1567 + if (crtc_state->commit && crtc_state->commit->abort_completion)
1568 + drm_crtc_commit_put(crtc_state->commit);
1570 1569 drm_event_cancel_free(dev, &event->base);
1571 1570 crtc_state->event = NULL;
1572 1571 }
modified drivers/gpu/drm/drm_exec.c
@@ -79,7 +79,7 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr)
79 79 nr = PAGE_SIZE / sizeof(void *);
80 80
81 81 exec->flags = flags;
82 - exec->objects = kvmalloc_objs(*exec->objects, nr, GFP_KERNEL);
82 + exec->objects = kvmalloc_objs(*exec->objects, nr);
83 83
84 84 /* If allocation here fails, just delay that till the first use */
85 85 exec->max_objects = exec->objects ? nr : 0;
modified drivers/gpu/drm/drm_pagemap.c
@@ -383,6 +383,58 @@ next:
383 383 return 0;
384 384 }
385 385
386 + /**
387 + * drm_pagemap_migrate_populate_src_pages() - Populate the source page array
388 + * @pages: Array of source pages to populate
389 + * @src_mpfn: Source array of migrate PFNs
390 + * @dst_mpfn: Destination array of migrate PFNs
391 + * @npages: Number of pages in the arrays
392 + *
393 + * Populate @pages with the device pages the copy callback is to read from.
394 + *
395 + * Entries are normally only populated at the head of each source folio, with
396 + * the copy callback deriving the rest of the folio from the order recorded in
397 + * the corresponding drm_pagemap_addr. That does not work where
398 + * drm_pagemap_migrate_populate_ram_pfn() had to demote a higher-order source
399 + * folio to order-0 destination folios: the drm_pagemap_addr entries are then
400 + * per-page, and the copy callback needs a source page for each of them.
401 + * Populate every entry for those ranges.
402 + *
403 + * Note that the source folio itself is only split later, by
404 + * migrate_vma_pages() / migrate_device_pages(), so its order cannot be used to
405 + * detect the demotion - the destination has to be inspected instead.
406 + */
407 + static void drm_pagemap_migrate_populate_src_pages(struct page **pages,
408 + unsigned long *src_mpfn,
409 + unsigned long *dst_mpfn,
410 + unsigned long npages)
411 + {
412 + unsigned long i;
413 +
414 + for (i = 0; i < npages;) {
415 + struct page *page = migrate_pfn_to_page(src_mpfn[i]);
416 + unsigned int order = 0;
417 + unsigned long j, nr;
418 +
419 + if (!page) {
420 + i++;
421 + continue;
422 + }
423 +
424 + order = folio_order(page_folio(page));
425 + nr = NR_PAGES(order);
426 +
427 + if (order && !(dst_mpfn[i] & MIGRATE_PFN_COMPOUND)) {
428 + for (j = 0; j < nr && i + j < npages; j++)
429 + pages[i + j] = folio_page(page_folio(page), j);
430 + } else {
431 + pages[i] = page;
432 + }
433 +
434 + i += nr;
435 + }
436 + }
437 +
386 438 /**
387 439 * drm_pagemap_migrate_unmap_pages() - Unmap pages previously mapped for GPU SVM migration
388 440 * @dev: The device for which the pages were mapped
@@ -875,6 +927,7 @@ static int drm_pagemap_migrate_populate_ram_pfn(struct vm_area_struct *vas,
875 927 struct page *page = NULL, *src_page;
876 928 struct folio *folio;
877 929 unsigned int order = 0;
930 + gfp_t gfp = GFP_HIGHUSER;
878 931
879 932 if (!(src_mpfn[i] & MIGRATE_PFN_MIGRATE))
880 933 goto next;
@@ -891,11 +944,51 @@ static int drm_pagemap_migrate_populate_ram_pfn(struct vm_area_struct *vas,
891 944
892 945 order = folio_order(page_folio(src_page));
893 946
894 - /* TODO: Support fallback to single pages if THP allocation fails */
947 + /*
948 + * A large source folio is always collected whole, at its head
949 + * page, PMD aligned and flagged MIGRATE_PFN_COMPOUND: anything
950 + * else is split before it reaches us, either by
951 + * migrate_vma_collect_pmd() or, for the eviction path, by
952 + * migrate_device_pfns(). Both the order-0 fallback below and
953 + * drm_pagemap_migrate_populate_src_pages() rely on that, as
954 + * they index the folio from @i.
955 + */
956 + WARN_ON_ONCE(order &&
957 + (src_page != folio_page(page_folio(src_page), 0) ||
958 + !(src_mpfn[i] & MIGRATE_PFN_COMPOUND)));
959 +
960 + if (order)
961 + gfp |= __GFP_NOWARN;
962 +
895 963 if (vas)
896 - folio = vma_alloc_folio(GFP_HIGHUSER, order, vas, addr);
964 + folio = vma_alloc_folio(gfp, order, vas, addr);
897 965 else
898 - folio = folio_alloc(GFP_HIGHUSER, order);
966 + folio = folio_alloc(gfp, order);
967 +
968 + if (!folio && order) {
969 + /*
970 + * Higher-order allocation failed, fall back to
971 + * order-0 allocations for the entire range covered
972 + * by the original higher-order allocation, without
973 + * setting MIGRATE_PFN_COMPOUND, until we move past
974 + * that range.
975 + */
976 + unsigned long nr = NR_PAGES(order);
977 + unsigned long j;
978 +
979 + gfp &= ~__GFP_NOWARN;
980 + for (j = 0; j < nr && i < npages; j++, i++, addr += PAGE_SIZE) {
981 + folio = vas ?
982 + vma_alloc_folio(gfp, 0, vas, addr) :
983 + folio_alloc(gfp, 0);
984 + if (!folio)
985 + goto free_pages;
986 +
987 + page = folio_page(folio, 0);
988 + mpfn[i] = migrate_pfn(page_to_pfn(page));
989 + }
990 + continue;
991 + }
899 992
900 993 if (!folio)
901 994 goto free_pages;
@@ -940,11 +1033,11 @@ free_pages:
940 1033 if (!page)
941 1034 goto next_put;
942 1035
1036 + order = folio_order(page_folio(page));
1037 +
943 1038 put_page(page);
944 1039 mpfn[i] = 0;
945 1040
946 - order = folio_order(page_folio(page));
947 -
948 1041 next_put:
949 1042 i += NR_PAGES(order);
950 1043 }
@@ -1102,12 +1195,117 @@ void drm_pagemap_put(struct drm_pagemap *dpagemap)
1102 1195 }
1103 1196 EXPORT_SYMBOL(drm_pagemap_put);
1104 1197
1198 + /**
1199 + * drm_pagemap_page_get_flags() - Read flags from a device-private folio
1200 + * @page: Pointer to a page of the device-private folio
1201 + *
1202 + * Return: The DRM_PAGEMAP_ZDD_FLAG_* bits encoded in zone_device_data.
1203 + */
1204 + static unsigned long drm_pagemap_page_get_flags(struct page *page)
1205 + {
1206 + struct folio *folio = page_folio(page);
1207 +
1208 + return (unsigned long)folio_zone_device_data(folio) &
1209 + DRM_PAGEMAP_ZDD_FLAG_MASK;
1210 + }
1211 +
1212 + /**
1213 + * drm_pagemap_page_set_flags() - Set flags on a device-private folio
1214 + * @page: Pointer to a page of the device-private folio
1215 + * @flags: DRM_PAGEMAP_ZDD_FLAG_* bits to set
1216 + *
1217 + * Preserve any flags already encoded alongside the ZDD pointer.
1218 + */
1219 + static void drm_pagemap_page_set_flags(struct page *page,
1220 + unsigned long flags)
1221 + {
1222 + struct folio *folio = page_folio(page);
1223 + unsigned long old;
1224 +
1225 + if (WARN_ON_ONCE(flags & ~DRM_PAGEMAP_ZDD_FLAG_MASK))
1226 + return;
1227 +
1228 + old = (unsigned long)folio_zone_device_data(folio);
1229 + folio_set_zone_device_data(folio, (void *)(old | flags));
1230 + }
1231 +
1232 + /**
1233 + * drm_pagemap_retire_migrated_pages() - Record migrated device-private folios
1234 + * @src_pfns: source array after migrate_vma_pages() or migrate_device_pages()
1235 + * @npages: number of entries in @src_pfns
1236 + *
1237 + * Flag device-private folios successfully migrated to RAM before finalize
1238 + * unlocks the sources. The migrated state is stored in the physical folio, so
1239 + * it survives later folio splits and subsequent migrations can skip it.
1240 + */
1241 + static void drm_pagemap_retire_migrated_pages(unsigned long *src_pfns,
1242 + unsigned long npages)
1243 + {
1244 + unsigned long i = 0;
1245 +
1246 + while (i < npages) {
1247 + struct page *page = migrate_pfn_to_page(src_pfns[i]);
1248 + unsigned long nr = 1;
1249 +
1250 + if (!page) {
1251 + i++;
1252 + continue;
1253 + }
1254 +
1255 + if (src_pfns[i] & MIGRATE_PFN_COMPOUND)
1256 + nr = folio_nr_pages(page_folio(page));
1257 +
1258 + if ((src_pfns[i] & MIGRATE_PFN_MIGRATE) &&
1259 + is_device_private_page(page))
1260 + drm_pagemap_page_set_flags(page,
1261 + DRM_PAGEMAP_ZDD_FLAG_MIGRATED);
1262 +
1263 + i += nr;
1264 + }
1265 + }
1266 +
1267 + /**
1268 + * drm_pagemap_skip_retired_pages() - Skip retired device-private folios
1269 + * @src_pfns: MIGRATE_PFN-encoded source array
1270 + * @npages: number of entries in @src_pfns
1271 + *
1272 + * Skip source folios already migrated to RAM, identified by the migrated flag
1273 + * stored in the physical folio's zone_device_data.
1274 + */
1275 + static void drm_pagemap_skip_retired_pages(unsigned long *src_pfns,
1276 + unsigned long npages)
1277 + {
1278 + unsigned long i = 0;
1279 +
1280 + while (i < npages) {
1281 + struct page *page = migrate_pfn_to_page(src_pfns[i]);
1282 + unsigned long nr = 1;
1283 +
1284 + if (!page) {
1285 + i++;
1286 + continue;
1287 + }
1288 +
1289 + if (src_pfns[i] & MIGRATE_PFN_COMPOUND)
1290 + nr = folio_nr_pages(page_folio(page));
1291 +
1292 + if ((src_pfns[i] & MIGRATE_PFN_MIGRATE) &&
1293 + is_device_private_page(page) &&
1294 + (drm_pagemap_page_get_flags(page) &
1295 + DRM_PAGEMAP_ZDD_FLAG_MIGRATED))
1296 + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
1297 +
1298 + i += nr;
1299 + }
1300 + }
1301 +
1105 1302 /**
1106 1303 * drm_pagemap_evict_to_ram() - Evict GPU SVM range to RAM
1107 1304 * @devmem_allocation: Pointer to the device memory allocation
1108 1305 *
1109 - * Similar to __drm_pagemap_migrate_to_ram but does not require mmap lock and
1110 - * migration done via migrate_device_* functions.
1306 + * Similar to __drm_pagemap_migrate_to_ram(), but uses the
1307 + * migrate_device_* helpers and does not require the mmap lock.
1308 + * Device-private PFNs already migrated to RAM by either path are skipped.
1111 1309 *
1112 1310 * Return: 0 on success, negative error code on failure.
1113 1311 */
@@ -1115,17 +1313,18 @@ int drm_pagemap_evict_to_ram(struct drm_pagemap_devmem *devmem_allocation)
1115 1313 {
1116 1314 const struct drm_pagemap_devmem_ops *ops = devmem_allocation->ops;
1117 1315 struct drm_pagemap_iova_state state = {};
1118 - unsigned long npages, mpages = 0;
1316 + unsigned long npages, mpages;
1119 1317 struct page **pages;
1120 1318 unsigned long *src, *dst;
1121 1319 struct drm_pagemap_addr *pagemap_addr;
1122 1320 void *buf;
1123 - int i, err = 0;
1321 + int err = 0;
1124 1322 unsigned int retry_count = 2;
1125 1323
1126 1324 npages = devmem_allocation->size >> PAGE_SHIFT;
1127 1325
1128 1326 retry:
1327 + mpages = 0;
1129 1328 if (!mmget_not_zero(devmem_allocation->mm))
1130 1329 return -EFAULT;
1131 1330
@@ -1148,6 +1347,8 @@ retry:
1148 1347 if (err)
1149 1348 goto err_free;
1150 1349
1350 + drm_pagemap_skip_retired_pages(src, npages);
1351 +
1151 1352 err = drm_pagemap_migrate_populate_ram_pfn(NULL, NULL, npages, &mpages,
1152 1353 src, dst, 0);
1153 1354 if (err || !mpages)
@@ -1160,27 +1361,20 @@ retry:
1160 1361 if (err)
1161 1362 goto err_finalize;
1162 1363
1163 - for (i = 0; i < npages;) {
1164 - unsigned int order = 0;
1165 -
1166 - pages[i] = migrate_pfn_to_page(src[i]);
1167 - if (pages[i])
1168 - order = folio_order(page_folio(pages[i]));
1169 -
1170 - i += NR_PAGES(order);
1171 - }
1364 + drm_pagemap_migrate_populate_src_pages(pages, src, dst, npages);
1172 1365
1173 1366 err = ops->copy_to_ram(pages, pagemap_addr, npages, NULL);
1174 1367 if (err)
1175 1368 goto err_finalize;
1176 1369
1177 1370 err_finalize:
1371 + drm_pagemap_migrate_unmap_pages(devmem_allocation->dev, pagemap_addr, dst, npages,
1372 + DMA_FROM_DEVICE, &state);
1178 1373 if (err)
1179 1374 drm_pagemap_migration_unlock_put_pages(npages, dst);
1180 1375 migrate_device_pages(src, dst, npages);
1376 + drm_pagemap_retire_migrated_pages(src, npages);
1181 1377 migrate_device_finalize(src, dst, npages);
1182 - drm_pagemap_migrate_unmap_pages(devmem_allocation->dev, pagemap_addr, dst, npages,
1183 - DMA_FROM_DEVICE, &state);
1184 1378
1185 1379 err_free:
1186 1380 kvfree(buf);
@@ -1235,7 +1429,7 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
1235 1429 struct drm_pagemap_addr *pagemap_addr;
1236 1430 unsigned long start, end;
1237 1431 void *buf;
1238 - int i, err = 0;
1432 + int err = 0;
1239 1433
1240 1434 zdd = drm_pagemap_page_zone_device_data(page);
1241 1435 if (time_before64(get_jiffies_64(), zdd->devmem_allocation->timeslice_expiration))
@@ -1275,13 +1469,15 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
1275 1469 if (!migrate.cpages)
1276 1470 goto err_free;
1277 1471
1472 + drm_pagemap_skip_retired_pages(migrate.src, npages);
1473 +
1278 1474 ops = zdd->devmem_allocation->ops;
1279 1475 dev = zdd->devmem_allocation->dev;
1280 1476
1281 1477 err = drm_pagemap_migrate_populate_ram_pfn(vas, page, npages, &mpages,
1282 1478 migrate.src, migrate.dst,
1283 1479 start);
1284 - if (err)
1480 + if (err || !mpages)
1285 1481 goto err_finalize;
1286 1482
1287 1483 err = drm_pagemap_migrate_map_system_pages(dev, pagemap_addr,
@@ -1290,29 +1486,23 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
1290 1486 if (err)
1291 1487 goto err_finalize;
1292 1488
1293 - for (i = 0; i < npages;) {
1294 - unsigned int order = 0;
1295 -
1296 - pages[i] = migrate_pfn_to_page(migrate.src[i]);
1297 - if (pages[i])
1298 - order = folio_order(page_folio(pages[i]));
1299 -
1300 - i += NR_PAGES(order);
1301 - }
1489 + drm_pagemap_migrate_populate_src_pages(pages, migrate.src, migrate.dst,
1490 + npages);
1302 1491
1303 1492 err = ops->copy_to_ram(pages, pagemap_addr, npages, NULL);
1304 1493 if (err)
1305 1494 goto err_finalize;
1306 1495
1307 1496 err_finalize:
1308 - if (err)
1309 - drm_pagemap_migration_unlock_put_pages(npages, migrate.dst);
1310 - migrate_vma_pages(&migrate);
1311 - migrate_vma_finalize(&migrate);
1312 1497 if (dev)
1313 1498 drm_pagemap_migrate_unmap_pages(dev, pagemap_addr, migrate.dst,
1314 1499 npages, DMA_FROM_DEVICE,
1315 1500 &state);
1501 + if (err)
1502 + drm_pagemap_migration_unlock_put_pages(npages, migrate.dst);
1503 + migrate_vma_pages(&migrate);
1504 + drm_pagemap_retire_migrated_pages(migrate.src, npages);
1505 + migrate_vma_finalize(&migrate);
1316 1506 err_free:
1317 1507 kvfree(buf);
1318 1508 err_out:
@@ -1360,13 +1550,19 @@ static vm_fault_t drm_pagemap_migrate_to_ram(struct vm_fault *vmf)
1360 1550 static void drm_pagemap_folio_split(struct folio *orig_folio, struct folio *new_folio)
1361 1551 {
1362 1552 struct drm_pagemap_zdd *zdd;
1553 + unsigned long orig_data, new_data;
1363 1554
1364 1555 if (!new_folio)
1365 1556 return;
1366 1557
1367 1558 new_folio->pgmap = orig_folio->pgmap;
1368 - zdd = folio_zone_device_data(orig_folio);
1369 - folio_set_zone_device_data(new_folio, drm_pagemap_zdd_get(zdd));
1559 +
1560 + orig_data = (unsigned long)folio_zone_device_data(orig_folio);
1561 + zdd = (struct drm_pagemap_zdd *)(orig_data & ~DRM_PAGEMAP_ZDD_FLAG_MASK);
1562 +
1563 + new_data = (unsigned long)drm_pagemap_zdd_get(zdd);
1564 + new_data |= orig_data & DRM_PAGEMAP_ZDD_FLAG_MASK;
1565 + folio_set_zone_device_data(new_folio, (void *)new_data);
1370 1566 }
1371 1567
1372 1568 static const struct dev_pagemap_ops drm_pagemap_pagemap_ops = {
modified drivers/gpu/drm/drm_prime.c
@@ -524,7 +524,7 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
524 524 return PTR_ERR(dmabuf);
525 525 }
526 526
527 - fd_install(fd, dmabuf->file);
527 + dma_buf_fd_install(dmabuf, fd);
528 528 *prime_fd = fd;
529 529 return 0;
530 530 }
modified drivers/gpu/drm/drm_syncobj.c
@@ -1619,7 +1619,7 @@ drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data,
1619 1619 goto err_points;
1620 1620 }
1621 1621
1622 - chains = kmalloc_objs(*chains, args->count_handles, GFP_KERNEL);
1622 + chains = kmalloc_objs(*chains, args->count_handles);
1623 1623 if (!chains) {
1624 1624 ret = -ENOMEM;
1625 1625 goto err_points;
modified drivers/gpu/drm/gud/gud_connector.c
@@ -396,8 +396,16 @@ static int gud_connector_add_tv_mode(struct gud_device *gdrm, struct drm_connect
396 396 }
397 397
398 398 num_modes = ret / GUD_CONNECTOR_TV_MODE_NAME_LEN;
399 - for (i = 0; i < num_modes; i++)
400 - modes[i] = &buf[i * GUD_CONNECTOR_TV_MODE_NAME_LEN];
399 + for (i = 0; i < num_modes; i++) {
400 + char *mode = &buf[i * GUD_CONNECTOR_TV_MODE_NAME_LEN];
401 +
402 + if (!memchr(mode, '\0', GUD_CONNECTOR_TV_MODE_NAME_LEN)) {
403 + ret = -EIO;
404 + goto free;
405 + }
406 +
407 + modes[i] = mode;
408 + }
401 409
402 410 ret = drm_mode_create_tv_properties_legacy(connector->dev, num_modes, modes);
403 411 free:
modified drivers/gpu/drm/gud/gud_drv.c
@@ -289,6 +289,8 @@ static int gud_plane_add_properties(struct gud_device *gdrm)
289 289 * but mask out any additions on future devices.
290 290 */
291 291 val &= GUD_ROTATION_MASK;
292 + if (!(val & GUD_ROTATION_0))
293 + continue;
292 294 ret = drm_plane_create_rotation_property(&gdrm->plane,
293 295 DRM_MODE_ROTATE_0, val);
294 296 break;
modified drivers/gpu/drm/i915/display/intel_cdclk.c
@@ -2381,8 +2381,10 @@ static void bxt_sanitize_cdclk(struct intel_display *display)
2381 2381 * dividers both syncing to an active pipe, or asynchronously
2382 2382 * (PIPE_NONE).
2383 2383 */
2384 - cdctl &= ~bxt_cdclk_cd2x_pipe_mask(display);
2385 - cdctl |= bxt_cdclk_cd2x_pipe(display, INVALID_PIPE);
2384 + if (DISPLAY_VER(display) < 30) {
2385 + cdctl &= ~bxt_cdclk_cd2x_pipe_mask(display);
2386 + cdctl |= bxt_cdclk_cd2x_pipe(display, INVALID_PIPE);
2387 + }
2386 2388
2387 2389 if (cdctl != expected) {
2388 2390 if (DISPLAY_VER(display) < 20) {
@@ -2713,8 +2715,8 @@ static void intel_set_cdclk(struct intel_display *display,
2713 2715 }
2714 2716 }
2715 2717
2716 - static bool dg2_power_well_count(struct intel_display *display,
2717 - const struct intel_cdclk_state *cdclk_state)
2718 + static int dg2_power_well_count(struct intel_display *display,
2719 + const struct intel_cdclk_state *cdclk_state)
2718 2720 {
2719 2721 return display->platform.dg2 ? hweight8(cdclk_state->active_pipes) : 0;
2720 2722 }
modified drivers/gpu/drm/i915/display/intel_cursor.c
@@ -530,13 +530,18 @@ static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
530 530 }
531 531
532 532 static void i9xx_cursor_disable_sel_fetch_arm(struct intel_dsb *dsb,
533 - struct intel_plane *plane,
534 - const struct intel_crtc_state *crtc_state)
533 + struct intel_plane *plane)
535 534 {
536 535 struct intel_display *display = to_intel_display(plane);
537 536 enum pipe pipe = plane->pipe;
538 537
539 - if (!crtc_state->enable_psr2_sel_fetch)
538 + /*
539 + * Clear this whenever the hardware has selective fetch, not just when
540 + * the current state uses it. The cursor may have been enabled with
541 + * selective fetch earlier and had its enable bit orphaned when the
542 + * feature was switched off.
543 + */
544 + if (!HAS_PSR2_SEL_FETCH(display))
540 545 return;
541 546
542 547 intel_de_write_dsb(display, dsb, SEL_FETCH_CUR_CTL(pipe), 0);
@@ -586,7 +591,7 @@ static void i9xx_cursor_update_sel_fetch_arm(struct intel_dsb *dsb,
586 591 if (crtc_state->enable_psr2_su_region_et)
587 592 wa_16021440873(dsb, plane, crtc_state, plane_state);
588 593 else
589 - i9xx_cursor_disable_sel_fetch_arm(dsb, plane, crtc_state);
594 + i9xx_cursor_disable_sel_fetch_arm(dsb, plane);
590 595 }
591 596 }
592 597
@@ -695,7 +700,7 @@ static void i9xx_cursor_update_arm(struct intel_dsb *dsb,
695 700 if (plane_state)
696 701 i9xx_cursor_update_sel_fetch_arm(dsb, plane, crtc_state, plane_state);
697 702 else
698 - i9xx_cursor_disable_sel_fetch_arm(dsb, plane, crtc_state);
703 + i9xx_cursor_disable_sel_fetch_arm(dsb, plane);
699 704
700 705 if (plane->cursor.base != base ||
701 706 plane->cursor.size != fbc_ctl ||
modified drivers/gpu/drm/i915/display/intel_cx0_phy.c
@@ -3233,7 +3233,8 @@ static void intel_cx0pll_enable(struct intel_encoder *encoder,
3233 3233 * 8. Program DDI_CLK_VALFREQ to match intended DDI
3234 3234 * clock frequency.
3235 3235 */
3236 - intel_de_write(display, DDI_CLK_VALFREQ(encoder->port), port_clock);
3236 + intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
3237 + intel_ddi_link_symbol_clock(encoder, port_clock));
3237 3238
3238 3239 /*
3239 3240 * 9. Set PORT_CLOCK_CTL register PCLK PLL Request
@@ -3406,7 +3407,7 @@ void intel_mtl_tbt_pll_enable_clock(struct intel_encoder *encoder, int port_cloc
3406 3407 * clock frequency.
3407 3408 */
3408 3409 intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
3409 - port_clock);
3410 + intel_ddi_link_symbol_clock(encoder, port_clock));
3410 3411 }
3411 3412
3412 3413 void intel_mtl_pll_enable(struct intel_encoder *encoder,
modified drivers/gpu/drm/i915/display/intel_ddi.c
@@ -1529,6 +1529,17 @@ int intel_ddi_level(struct intel_encoder *encoder,
1529 1529 return level;
1530 1530 }
1531 1531
1532 + int intel_ddi_link_symbol_clock(struct intel_encoder *encoder, int clock)
1533 + {
1534 + if (intel_encoder_is_dp(encoder))
1535 + return intel_dp_link_symbol_clock(clock);
1536 +
1537 + if (intel_hdmi_is_frl(clock))
1538 + return DIV_ROUND_CLOSEST(clock * 10, 18);
1539 +
1540 + return clock;
1541 + }
1542 +
1532 1543 static void
1533 1544 hsw_set_signal_levels(struct intel_encoder *encoder,
1534 1545 const struct intel_crtc_state *crtc_state)
modified drivers/gpu/drm/i915/display/intel_ddi.h
@@ -81,6 +81,7 @@ void intel_ddi_sanitize_encoder_pll_mapping(struct intel_encoder *encoder);
81 81 int intel_ddi_level(struct intel_encoder *encoder,
82 82 const struct intel_crtc_state *crtc_state,
83 83 int lane);
84 + int intel_ddi_link_symbol_clock(struct intel_encoder *encoder, int clock);
84 85 void intel_ddi_update_active_dpll(struct intel_atomic_state *state,
85 86 struct intel_encoder *encoder,
86 87 struct intel_crtc *crtc);
modified drivers/gpu/drm/i915/display/intel_dp_mst.c
@@ -761,10 +761,6 @@ static int mst_stream_compute_config(struct intel_atomic_state *state,
761 761 pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB;
762 762 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
763 763
764 - ret = intel_pfit_compute_config(pipe_config, conn_state);
765 - if (ret)
766 - return ret;
767 -
768 764 ret = intel_pfit_compute_config(pipe_config, conn_state);
769 765 if (ret)
770 766 return ret;
modified drivers/gpu/drm/i915/display/intel_lt_phy.c
@@ -1976,7 +1976,8 @@ void intel_lt_phy_pll_enable(struct intel_encoder *encoder,
1976 1976 * Change. We handle this step in bxt_set_cdclk().
1977 1977 */
1978 1978 /* 10. Program DDI_CLK_VALFREQ to match intended DDI clock frequency. */
1979 - intel_de_write(display, DDI_CLK_VALFREQ(encoder->port), port_clock);
1979 + intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
1980 + intel_ddi_link_symbol_clock(encoder, port_clock));
1980 1981
1981 1982 /* 11. Program PORT_CLOCK_CTL[PCLK PLL Request LN0] = 1. */
1982 1983 intel_de_rmw(display, XELPDP_PORT_CLOCK_CTL(display, port),
@@ -2023,7 +2024,8 @@ void intel_lt_phy_pll_enable(struct intel_encoder *encoder,
2023 2024 lane_phy_pulse_status,
2024 2025 lane_phy_pulse_status);
2025 2026 } else {
2026 - intel_de_write(display, DDI_CLK_VALFREQ(encoder->port), port_clock);
2027 + intel_de_write(display, DDI_CLK_VALFREQ(encoder->port),
2028 + intel_ddi_link_symbol_clock(encoder, port_clock));
2027 2029 }
2028 2030
2029 2031 /*
modified drivers/gpu/drm/i915/display/skl_universal_plane.c
@@ -879,13 +879,18 @@ skl_plane_disable_arm(struct intel_dsb *dsb,
879 879 }
880 880
881 881 static void icl_plane_disable_sel_fetch_arm(struct intel_dsb *dsb,
882 - struct intel_plane *plane,
883 - const struct intel_crtc_state *crtc_state)
882 + struct intel_plane *plane)
884 883 {
885 884 struct intel_display *display = to_intel_display(plane);
886 885 enum pipe pipe = plane->pipe;
887 886
888 - if (!crtc_state->enable_psr2_sel_fetch)
887 + /*
888 + * Clear this whenever the hardware has selective fetch, not just when
889 + * the current state uses it. The plane may have been enabled with
890 + * selective fetch earlier and had its enable bit orphaned when the
891 + * feature was switched off.
892 + */
893 + if (!HAS_PSR2_SEL_FETCH(display))
889 894 return;
890 895
891 896 intel_de_write_dsb(display, dsb, SEL_FETCH_PLANE_CTL(pipe, plane->id), 0);
@@ -921,7 +926,7 @@ icl_plane_disable_arm(struct intel_dsb *dsb,
921 926
922 927 skl_write_plane_wm(dsb, plane, crtc_state);
923 928
924 - icl_plane_disable_sel_fetch_arm(dsb, plane, crtc_state);
929 + icl_plane_disable_sel_fetch_arm(dsb, plane);
925 930
926 931 if (plane_has_normalizer(plane))
927 932 intel_de_write_dsb(display, dsb,
@@ -1641,7 +1646,7 @@ static void icl_plane_update_sel_fetch_arm(struct intel_dsb *dsb,
1641 1646 intel_de_write_dsb(display, dsb, SEL_FETCH_PLANE_CTL(pipe, plane->id),
1642 1647 SEL_FETCH_PLANE_CTL_ENABLE);
1643 1648 else
1644 - icl_plane_disable_sel_fetch_arm(dsb, plane, crtc_state);
1649 + icl_plane_disable_sel_fetch_arm(dsb, plane);
1645 1650 }
1646 1651
1647 1652 static void
modified drivers/gpu/drm/i915/i915_pci.c
@@ -958,6 +958,9 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
958 958 (struct intel_device_info *) ent->driver_data;
959 959 int err;
960 960
961 + if (!intel_info)
962 + return -ENODEV;
963 +
961 964 if (intel_info->require_force_probe && !id_forced(pdev->device)) {
962 965 dev_info(&pdev->dev,
963 966 "Your graphics device %04x is not properly supported by i915 in this\n"
modified drivers/gpu/drm/nouveau/include/nvkm/engine/disp.h
@@ -87,4 +87,5 @@ int gp102_disp_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct
87 87 int gv100_disp_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_disp **);
88 88 int tu102_disp_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_disp **);
89 89 int ga102_disp_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_disp **);
90 + int gb202_disp_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_disp **);
90 91 #endif
modified drivers/gpu/drm/nouveau/nouveau_chan.c
@@ -90,6 +90,14 @@ nouveau_channel_del(struct nouveau_channel **pchan)
90 90 {
91 91 struct nouveau_channel *chan = *pchan;
92 92 if (chan) {
93 + /*
94 + * Drop the kill-event subscription first. Its handler
95 + * dereferences chan->fence, which the fence context teardown
96 + * below frees, so leaving it armed across the teardown leaves
97 + * a window for a use-after-free.
98 + */
99 + nvif_event_dtor(&chan->kill);
100 +
93 101 if (chan->fence)
94 102 nouveau_fence(chan->cli->drm)->context_del(chan);
95 103
@@ -100,7 +108,6 @@ nouveau_channel_del(struct nouveau_channel **pchan)
100 108 nvif_object_dtor(&chan->nvsw);
101 109 nvif_object_dtor(&chan->gart);
102 110 nvif_object_dtor(&chan->vram);
103 - nvif_event_dtor(&chan->kill);
104 111 nvif_object_dtor(&chan->user);
105 112 nvif_mem_dtor(&chan->mem_userd);
106 113 nouveau_vma_del(&chan->sema.vma);
modified drivers/gpu/drm/nouveau/nouveau_dmem.c
@@ -267,7 +267,7 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf)
267 267 nouveau_fence_new(&fence, dmem->migrate.chan);
268 268 migrate_vma_pages(&args);
269 269 nouveau_dmem_fence_done(&fence);
270 - dma_unmap_page(drm->dev->dev, dma_info.dma_addr, PAGE_SIZE,
270 + dma_unmap_page(drm->dev->dev, dma_info.dma_addr, dma_info.size,
271 271 DMA_BIDIRECTIONAL);
272 272 done:
273 273 migrate_vma_finalize(&args);
@@ -279,11 +279,25 @@ err:
279 279
280 280 static void nouveau_dmem_folio_split(struct folio *head, struct folio *tail)
281 281 {
282 + struct nouveau_dmem_chunk *chunk;
283 + struct nouveau_dmem *dmem;
284 +
282 285 if (tail == NULL)
283 286 return;
284 287 tail->pgmap = head->pgmap;
285 288 tail->mapping = head->mapping;
286 289 folio_set_zone_device_data(tail, folio_zone_device_data(head));
290 +
291 + /*
292 + * The split hands out a new independently-freeable folio that will
293 + * later be released via nouveau_dmem_folio_free(); account for it so
294 + * chunk->callocated stays balanced.
295 + */
296 + chunk = nouveau_page_to_chunk(&head->page);
297 + dmem = chunk->drm->dmem;
298 + spin_lock(&dmem->lock);
299 + chunk->callocated++;
300 + spin_unlock(&dmem->lock);
287 301 }
288 302
289 303 static const struct dev_pagemap_ops nouveau_dmem_pagemap_ops = {
@@ -772,7 +786,7 @@ static unsigned long nouveau_dmem_migrate_copy_one(struct nouveau_drm *drm,
772 786 return mpfn;
773 787
774 788 out_dma_unmap:
775 - dma_unmap_page(dev, dma_info->dma_addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
789 + dma_unmap_page(dev, dma_info->dma_addr, dma_info->size, DMA_BIDIRECTIONAL);
776 790 out_free_page:
777 791 nouveau_dmem_page_free_locked(drm, dpage);
778 792 out:
modified drivers/gpu/drm/nouveau/nouveau_sgdma.c
@@ -72,9 +72,7 @@ nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
72 72 struct nouveau_sgdma_be *nvbe;
73 73 enum ttm_caching caching;
74 74
75 - if (nvbo->force_coherent)
76 - caching = ttm_uncached;
77 - else if (drm->agp.bridge)
75 + if (nvbo->force_coherent || drm->agp.bridge)
78 76 caching = ttm_write_combined;
79 77 else
80 78 caching = ttm_cached;
modified drivers/gpu/drm/nouveau/nouveau_uvmm.c
@@ -1319,6 +1319,7 @@ nouveau_uvmm_bind_job_submit(struct nouveau_job *job,
1319 1319 op->va.range);
1320 1320 if (!op->reg || op->reg->dirty) {
1321 1321 ret = -ENOENT;
1322 + op->reg = NULL;
1322 1323 goto unwind_continue;
1323 1324 }
1324 1325
@@ -1327,6 +1328,7 @@ nouveau_uvmm_bind_job_submit(struct nouveau_job *job,
1327 1328 op->va.range);
1328 1329 if (IS_ERR(op->ops)) {
1329 1330 ret = PTR_ERR(op->ops);
1331 + op->reg = NULL;
1330 1332 goto unwind_continue;
1331 1333 }
1332 1334
@@ -1473,6 +1475,7 @@ unwind:
1473 1475 op->va.range);
1474 1476 break;
1475 1477 case OP_UNMAP_SPARSE:
1478 + op->reg->dirty = false;
1476 1479 __nouveau_uvma_region_insert(uvmm, op->reg);
1477 1480 nouveau_uvmm_sm_unmap_prepare_unwind(uvmm, &op->new,
1478 1481 op->ops);
@@ -1489,7 +1492,8 @@ unwind:
1489 1492 break;
1490 1493 }
1491 1494
1492 - drm_gpuva_ops_free(&uvmm->base, op->ops);
1495 + if (!IS_ERR_OR_NULL(op->ops))
1496 + drm_gpuva_ops_free(&uvmm->base, op->ops);
1493 1497 op->ops = NULL;
1494 1498 op->reg = NULL;
1495 1499 }
modified drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
@@ -2846,7 +2846,7 @@ nv1b2_chipset = {
2846 2846 .pci = { 0x00000001, gh100_pci_new },
2847 2847 .timer = { 0x00000001, gk20a_timer_new },
2848 2848 .vfn = { 0x00000001, ga100_vfn_new },
2849 - .disp = { 0x00000001, ga102_disp_new },
2849 + .disp = { 0x00000001, gb202_disp_new },
2850 2850 .fifo = { 0x00000001, ga102_fifo_new },
2851 2851 };
2852 2852
@@ -2862,7 +2862,7 @@ nv1b3_chipset = {
2862 2862 .pci = { 0x00000001, gh100_pci_new },
2863 2863 .timer = { 0x00000001, gk20a_timer_new },
2864 2864 .vfn = { 0x00000001, ga100_vfn_new },
2865 - .disp = { 0x00000001, ga102_disp_new },
2865 + .disp = { 0x00000001, gb202_disp_new },
2866 2866 .fifo = { 0x00000001, ga102_fifo_new },
2867 2867 };
2868 2868
@@ -2878,7 +2878,7 @@ nv1b5_chipset = {
2878 2878 .pci = { 0x00000001, gh100_pci_new },
2879 2879 .timer = { 0x00000001, gk20a_timer_new },
2880 2880 .vfn = { 0x00000001, ga100_vfn_new },
2881 - .disp = { 0x00000001, ga102_disp_new },
2881 + .disp = { 0x00000001, gb202_disp_new },
2882 2882 .fifo = { 0x00000001, ga102_fifo_new },
2883 2883 };
2884 2884
@@ -2894,7 +2894,7 @@ nv1b6_chipset = {
2894 2894 .pci = { 0x00000001, gh100_pci_new },
2895 2895 .timer = { 0x00000001, gk20a_timer_new },
2896 2896 .vfn = { 0x00000001, ga100_vfn_new },
2897 - .disp = { 0x00000001, ga102_disp_new },
2897 + .disp = { 0x00000001, gb202_disp_new },
2898 2898 .fifo = { 0x00000001, ga102_fifo_new },
2899 2899 };
2900 2900
@@ -2910,7 +2910,7 @@ nv1b7_chipset = {
2910 2910 .pci = { 0x00000001, gh100_pci_new },
2911 2911 .timer = { 0x00000001, gk20a_timer_new },
2912 2912 .vfn = { 0x00000001, ga100_vfn_new },
2913 - .disp = { 0x00000001, ga102_disp_new },
2913 + .disp = { 0x00000001, gb202_disp_new },
2914 2914 .fifo = { 0x00000001, ga102_fifo_new },
2915 2915 };
2916 2916
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/Kbuild
@@ -27,6 +27,7 @@ nvkm-y += nvkm/engine/disp/gp102.o
27 27 nvkm-y += nvkm/engine/disp/gv100.o
28 28 nvkm-y += nvkm/engine/disp/tu102.o
29 29 nvkm-y += nvkm/engine/disp/ga102.o
30 + nvkm-y += nvkm/engine/disp/gb202.o
30 31
31 32 nvkm-y += nvkm/engine/disp/udisp.o
32 33 nvkm-y += nvkm/engine/disp/uconn.o
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/ga102.c
@@ -144,12 +144,23 @@ ga102_disp = {
144 144 },
145 145 };
146 146
147 + static const struct nvkm_disp_func
148 + ga102_gsp_disp = {
149 + .uevent = &gv100_disp_chan_uevent,
150 + .ramht_size = 0x2000,
151 + .gsp.intr = tu102_disp_intr,
152 + .gsp.head = &tu102_gsp_head,
153 + .gsp.hdmi_gcp = tu102_sor_hdmi_gcp,
154 + .gsp.hdmi_infoframe_avi = gv100_sor_hdmi_infoframe_avi,
155 + .gsp.hdmi_infoframe_vsi = gv100_sor_hdmi_infoframe_vsi,
156 + };
157 +
147 158 int
148 159 ga102_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
149 160 struct nvkm_disp **pdisp)
150 161 {
151 162 if (nvkm_gsp_rm(device->gsp))
152 - return r535_disp_new(&ga102_disp, device, type, inst, pdisp);
163 + return r535_disp_new(&ga102_gsp_disp, device, type, inst, pdisp);
153 164
154 165 return nvkm_disp_new_(&ga102_disp, device, type, inst, pdisp);
155 166 }
added drivers/gpu/drm/nouveau/nvkm/engine/disp/gb202.c mode 100644
@@ -0,0 +1,191 @@
1 + // SPDX-License-Identifier: MIT
2 + /*
3 + * Copyright 2026 Valve Corp.
4 + */
5 + #include "priv.h"
6 + #include "head.h"
7 + #include "ior.h"
8 +
9 + #include <subdev/timer.h>
10 +
11 + /* GB20x (NVD5.0) reorganised the SF HDMI packet units. The AVI unit is
12 + * unchanged from GV100, but the legacy VSI unit is gone. Vendor infoframes
13 + * are sent through the shared generic infoframe units instead. Register
14 + * layout per NVIDIA's clc971.h/clca71.h, programming sequence per
15 + * nvhdmipkt_C971.c:programAdvancedInfoframeC971().
16 + */
17 + static void
18 + gb202_sor_hdmi_infoframe_vsi(struct nvkm_ior *ior, int head, void *data, u32 size)
19 + {
20 + struct nvkm_device *device = ior->disp->engine.subdev.device;
21 + const u32 hoff = head * 0x400;
22 + /* Generic infoframe unit 1, the slot NVIDIA's driver uses for the VSI. */
23 + const u32 ctrl = 0x6f0138 + hoff;
24 + u8 buf[36] = {};
25 + int i;
26 +
27 + /* Disable the unit and wait for it to go idle. */
28 + nvkm_mask(device, ctrl, 0x00000001, 0x00000000);
29 + if (nvkm_msec(device, 2000,
30 + if (!(nvkm_rd32(device, ctrl) & 0x00400000))
31 + break;
32 + ) < 0)
33 + return;
34 +
35 + if (!size)
36 + return;
37 +
38 + /* Clear SENT status, and point the data port at unit 1's slot. */
39 + nvkm_mask(device, ctrl, 0x00800000, 0x00800000);
40 + nvkm_wr32(device, 0x6f03f0 + hoff, 0x00000001);
41 +
42 + /* The data port takes the raw packet, except that a zero is inserted
43 + * in HB3 after the three header bytes. A slot is 9 dwords (HB0-3 plus
44 + * up to 32 payload bytes). An HDMI infoframe carries at most PB0-27,
45 + * so the tail stays zero, and we always write the whole slot.
46 + */
47 + size = min_t(u32, size, 31);
48 + memcpy(buf, data, min_t(u32, size, 3));
49 + if (size > 3)
50 + memcpy(&buf[4], (u8 *)data + 3, size - 3);
51 +
52 + for (i = 0; i < 36; i += 4) {
53 + nvkm_wr32(device, 0x6f03f4 + hoff, buf[i + 0] | buf[i + 1] << 8 |
54 + buf[i + 2] << 16 |
55 + (u32)buf[i + 3] << 24);
56 + }
57 +
58 + /* No flip ID or scanline matching. */
59 + nvkm_wr32(device, 0x6f013c + hoff, 0x00000000);
60 +
61 + /* ENABLE | RUN_MODE=ALWAYS | LOC=VBLANK | OFFSET=1 | SIZE=0. */
62 + nvkm_wr32(device, ctrl, 0x00000041);
63 +
64 + /* Audio priority low (the init value). */
65 + nvkm_wr32(device, 0x6f03f8 + hoff, 0x00000002);
66 + }
67 +
68 + /* General Control Packet AVMute bracket. The GCP unit moved to slot 1 on
69 + * NVD5.0. Only SB0 (the AVMute bit) is ours to write so we must not do a
70 + * full write here: SB1 carries the deep-color CD/PP fields, and SB1_CTRL
71 + * (bit 24, new with clc871.h) controls where their generation happens (HW
72 + * or driver) on these chips, with the default being HW.
73 + */
74 + static void
75 + gb202_sor_hdmi_gcp(struct nvkm_ior *sor, int head, bool enable)
76 + {
77 + struct nvkm_device *device = sor->disp->engine.subdev.device;
78 + const u32 hdmi = head * 0x400;
79 +
80 + nvkm_mask(device, 0x6f0040 + hdmi, 0x00000001, 0x00000000);
81 + nvkm_mask(device, 0x6f004c + hdmi, 0x000000ff, !enable ? 0x00000001 :
82 + 0x00000010);
83 + nvkm_mask(device, 0x6f0040 + hdmi, 0x00000001, 0x00000001);
84 + }
85 +
86 + /* Same core-channel state mirror as gv100_head_state() (assembly at 0x680000,
87 + * armed at +0x8000, per-head method offsets unchanged), but NVD5.0 spaces
88 + * heads 0x800 apart (see NVCA7D_HEAD_SET_*(a) in clca7d.h).
89 + */
90 + static void
91 + gb202_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
92 + {
93 + struct nvkm_device *device = head->disp->engine.subdev.device;
94 + const u32 hoff = (state == &head->arm) * 0x8000 + head->id * 0x800;
95 + u32 data;
96 +
97 + data = nvkm_rd32(device, 0x682064 + hoff);
98 + state->vtotal = (data & 0xffff0000) >> 16;
99 + state->htotal = (data & 0x0000ffff);
100 + data = nvkm_rd32(device, 0x682068 + hoff);
101 + state->vsynce = (data & 0xffff0000) >> 16;
102 + state->hsynce = (data & 0x0000ffff);
103 + data = nvkm_rd32(device, 0x68206c + hoff);
104 + state->vblanke = (data & 0xffff0000) >> 16;
105 + state->hblanke = (data & 0x0000ffff);
106 + data = nvkm_rd32(device, 0x682070 + hoff);
107 + state->vblanks = (data & 0xffff0000) >> 16;
108 + state->hblanks = (data & 0x0000ffff);
109 + /* Bit 31 is ADJ1000DIV1001, not a HERTZ bit. We don't have enough bits
110 + * to add the full clock in hz on Blackwell (35 bits), but state->hz
111 + * is unused and obsolete under GSP so this is fine.
112 + */
113 + state->hz = nvkm_rd32(device, 0x68200c + hoff) & 0x7fffffff;
114 +
115 + data = nvkm_rd32(device, 0x682004 + hoff);
116 + switch ((data & 0x000000f0) >> 4) {
117 + case 5: state->or.depth = 30; break;
118 + case 4: state->or.depth = 24; break;
119 + case 1: state->or.depth = 18; break;
120 + default:
121 + state->or.depth = 18;
122 + WARN_ON(1);
123 + break;
124 + }
125 + }
126 +
127 + /* NVD5.0 (GB20x and later) moved the RM head-timing interrupt enable to
128 + * the low-latency vector's EN1 block. The event latch is unchanged.
129 + */
130 + static void
131 + gb202_head_vblank_put(struct nvkm_head *head)
132 + {
133 + struct nvkm_device *device = head->disp->engine.subdev.device;
134 +
135 + nvkm_mask(device, 0x611ef0 + (head->id * 4), 0x00000002, 0x00000000);
136 + }
137 +
138 + static void
139 + gb202_head_vblank_get(struct nvkm_head *head)
140 + {
141 + struct nvkm_device *device = head->disp->engine.subdev.device;
142 +
143 + nvkm_wr32(device, 0x611800 + (head->id * 4), 0x00000002);
144 + nvkm_mask(device, 0x611ef0 + (head->id * 4), 0x00000002, 0x00000002);
145 + }
146 +
147 + static irqreturn_t
148 + gb202_disp_intr(struct nvkm_inth *inth)
149 + {
150 + struct nvkm_disp *disp = container_of(inth, typeof(*disp), engine.subdev.inth);
151 + irqreturn_t ret = tu102_disp_intr(inth);
152 +
153 + /* The FE interrupt vectors are message-based on NVD5.0. Re-arm the
154 + * low-latency vector so it fires again for any event that latched
155 + * while we were servicing.
156 + */
157 + nvkm_wr32(disp->engine.subdev.device, 0x611f34, 0x00000001);
158 + return ret;
159 + }
160 +
161 + static const struct nvkm_head_func
162 + gb202_gsp_head = {
163 + .state = gb202_head_state,
164 + .rgpos = gv100_head_rgpos,
165 + .vblank_get = gb202_head_vblank_get,
166 + .vblank_put = gb202_head_vblank_put,
167 + };
168 +
169 + /* GB20x is GSP-only. This table supplies the register programming the
170 + * GSP-RM display path needs from the chip.
171 + */
172 + static const struct nvkm_disp_func
173 + gb202_gsp_disp = {
174 + .uevent = &gv100_disp_chan_uevent,
175 + .ramht_size = 0x2000,
176 + /* Head timing arrives on the dedicated low-latency vector. */
177 + .gsp.intr = gb202_disp_intr,
178 + .gsp.intr_low_latency = true,
179 + .gsp.head = &gb202_gsp_head,
180 + .gsp.hdmi_gcp = gb202_sor_hdmi_gcp,
181 + /* The legacy AVI unit is unchanged on GB20x. */
182 + .gsp.hdmi_infoframe_avi = gv100_sor_hdmi_infoframe_avi,
183 + .gsp.hdmi_infoframe_vsi = gb202_sor_hdmi_infoframe_vsi,
184 + };
185 +
186 + int
187 + gb202_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
188 + struct nvkm_disp **pdisp)
189 + {
190 + return r535_disp_new(&gb202_gsp_disp, device, type, inst, pdisp);
191 + }
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/head.h
@@ -56,6 +56,8 @@ int gv100_head_new(struct nvkm_disp *, int id);
56 56 void gv100_head_state(struct nvkm_head *head, struct nvkm_head_state *state);
57 57 void gv100_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline);
58 58
59 + extern const struct nvkm_head_func tu102_gsp_head;
60 +
59 61 #define HEAD_MSG(h,l,f,a...) do { \
60 62 struct nvkm_head *_h = (h); \
61 63 nvkm_##l(&_h->disp->engine.subdev, "head-%d: "f"\n", _h->id, ##a); \
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h
@@ -194,6 +194,7 @@ void gv100_sor_dp_audio_sym(struct nvkm_ior *, int, u16, u32);
194 194 void gv100_sor_dp_watermark(struct nvkm_ior *, int, u8);
195 195 extern const struct nvkm_ior_func_hda gv100_sor_hda;
196 196
197 + void tu102_sor_hdmi_gcp(struct nvkm_ior *, int, bool);
197 198 void tu102_sor_dp_vcpi(struct nvkm_ior *, int, u8, u8, u16, u16);
198 199
199 200 int nv50_pior_cnt(struct nvkm_disp *, unsigned long *);
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/priv.h
@@ -5,6 +5,8 @@
5 5 #include <engine/disp.h>
6 6 #include <core/enum.h>
7 7 struct nvkm_head;
8 + struct nvkm_head_func;
9 + struct nvkm_ior;
8 10 struct nvkm_outp;
9 11 struct dcb_output;
10 12
@@ -34,6 +36,20 @@ struct nvkm_disp_func {
34 36 int (*new)(struct nvkm_disp *, int id);
35 37 } wndw, head, dac, sor, pior;
36 38
39 + /* Register programming that the GSP-RM display path (rm/r535) needs from
40 + * the chip, everything else on that path goes through RM. The hooks are
41 + * called unconditionally and the head table is handed to nvkm_head_new_().
42 + */
43 + struct {
44 + irqreturn_t (*intr)(struct nvkm_inth *);
45 + /* Head-timing interrupts arrive on a second DISP vector. */
46 + bool intr_low_latency;
47 + const struct nvkm_head_func *head;
48 + void (*hdmi_gcp)(struct nvkm_ior *, int head, bool enable);
49 + void (*hdmi_infoframe_avi)(struct nvkm_ior *, int head, void *data, u32 size);
50 + void (*hdmi_infoframe_vsi)(struct nvkm_ior *, int head, void *data, u32 size);
51 + } gsp;
52 +
37 53 u16 ramht_size;
38 54
39 55 struct nvkm_sclass root;
@@ -72,6 +88,7 @@ int gv100_disp_wndw_cnt(struct nvkm_disp *, unsigned long *);
72 88 int gv100_disp_caps_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
73 89
74 90 int tu102_disp_init(struct nvkm_disp *);
91 + irqreturn_t tu102_disp_intr(struct nvkm_inth *);
75 92
76 93 void nv50_disp_dptmds_war_2(struct nvkm_disp *, struct dcb_output *);
77 94 void nv50_disp_dptmds_war_3(struct nvkm_disp *, struct dcb_output *);
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/tu102.c
@@ -30,6 +30,21 @@
30 30
31 31 #include <nvif/class.h>
32 32
33 + /* General Control Packet: bracket an audio enable/disable with AVMute
34 + * through the legacy GCP SF unit. Used by the GSP-RM path, which sends the
35 + * equivalent packet via RM as well but keeps the direct write in sync.
36 + */
37 + void
38 + tu102_sor_hdmi_gcp(struct nvkm_ior *sor, int head, bool enable)
39 + {
40 + struct nvkm_device *device = sor->disp->engine.subdev.device;
41 + const u32 hdmi = head * 0x400;
42 +
43 + nvkm_mask(device, 0x6f00c0 + hdmi, 0x00000001, 0x00000000);
44 + nvkm_wr32(device, 0x6f00cc + hdmi, !enable ? 0x00000001 : 0x00000010);
45 + nvkm_mask(device, 0x6f00c0 + hdmi, 0x00000001, 0x00000001);
46 + }
47 +
33 48 void
34 49 tu102_sor_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned)
35 50 {
@@ -104,6 +119,64 @@ tu102_sor_new(struct nvkm_disp *disp, int id)
104 119 return nvkm_ior_new_(&tu102_sor, disp, SOR, id, hda & BIT(id));
105 120 }
106 121
122 + /* The GSP-RM display path leaves head-timing (vblank) interrupts and their
123 + * enables to us. These program the RM head-timing line (bit 1 of the
124 + * per-head enable, not the bit nvkm's own gv100 path uses).
125 + */
126 + static void
127 + tu102_head_vblank_put(struct nvkm_head *head)
128 + {
129 + struct nvkm_device *device = head->disp->engine.subdev.device;
130 +
131 + nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000002, 0x00000000);
132 + }
133 +
134 + static void
135 + tu102_head_vblank_get(struct nvkm_head *head)
136 + {
137 + struct nvkm_device *device = head->disp->engine.subdev.device;
138 +
139 + nvkm_wr32(device, 0x611800 + (head->id * 4), 0x00000002);
140 + nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000002, 0x00000002);
141 + }
142 +
143 + const struct nvkm_head_func
144 + tu102_gsp_head = {
145 + .state = gv100_head_state,
146 + .rgpos = gv100_head_rgpos,
147 + .vblank_get = tu102_head_vblank_get,
148 + .vblank_put = tu102_head_vblank_put,
149 + };
150 +
151 + static void
152 + tu102_disp_intr_head_timing(struct nvkm_disp *disp, int head)
153 + {
154 + struct nvkm_subdev *subdev = &disp->engine.subdev;
155 + struct nvkm_device *device = subdev->device;
156 + u32 stat = nvkm_rd32(device, 0x611c00 + (head * 0x04));
157 +
158 + if (stat & 0x00000002) {
159 + nvkm_disp_vblank(disp, head);
160 +
161 + nvkm_wr32(device, 0x611800 + (head * 0x04), 0x00000002);
162 + }
163 + }
164 +
165 + irqreturn_t
166 + tu102_disp_intr(struct nvkm_inth *inth)
167 + {
168 + struct nvkm_disp *disp = container_of(inth, typeof(*disp), engine.subdev.inth);
169 + struct nvkm_subdev *subdev = &disp->engine.subdev;
170 + struct nvkm_device *device = subdev->device;
171 + unsigned long mask = nvkm_rd32(device, 0x611ec0) & 0x000000ff;
172 + int head;
173 +
174 + for_each_set_bit(head, &mask, 8)
175 + tu102_disp_intr_head_timing(disp, head);
176 +
177 + return IRQ_HANDLED;
178 + }
179 +
107 180 int
108 181 tu102_disp_init(struct nvkm_disp *disp)
109 182 {
@@ -230,12 +303,23 @@ tu102_disp = {
230 303 },
231 304 };
232 305
306 + static const struct nvkm_disp_func
307 + tu102_gsp_disp = {
308 + .uevent = &gv100_disp_chan_uevent,
309 + .ramht_size = 0x2000,
310 + .gsp.intr = tu102_disp_intr,
311 + .gsp.head = &tu102_gsp_head,
312 + .gsp.hdmi_gcp = tu102_sor_hdmi_gcp,
313 + .gsp.hdmi_infoframe_avi = gv100_sor_hdmi_infoframe_avi,
314 + .gsp.hdmi_infoframe_vsi = gv100_sor_hdmi_infoframe_vsi,
315 + };
316 +
233 317 int
234 318 tu102_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
235 319 struct nvkm_disp **pdisp)
236 320 {
237 321 if (nvkm_gsp_rm(device->gsp))
238 - return r535_disp_new(&tu102_disp, device, type, inst, pdisp);
322 + return r535_disp_new(&tu102_gsp_disp, device, type, inst, pdisp);
239 323
240 324 return nvkm_disp_new_(&tu102_disp, device, type, inst, pdisp);
241 325 }
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c
@@ -400,16 +400,16 @@ r535_sor_dp_audio(struct nvkm_ior *sor, int head, bool enable)
400 400 r535_sor_dp_audio_mute(sor, false);
401 401 }
402 402
403 - static void
404 - r535_sor_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned_pbn)
403 + static int
404 + r535_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned_pbn)
405 405 {
406 406 struct nvkm_disp *disp = sor->disp;
407 407 struct NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS *ctrl;
408 408
409 409 ctrl = nvkm_gsp_rm_ctrl_get(&disp->rm.objcom,
410 410 NV0073_CTRL_CMD_DP_CONFIG_STREAM, sizeof(*ctrl));
411 - if (WARN_ON(IS_ERR(ctrl)))
412 - return;
411 + if (IS_ERR(ctrl))
412 + return PTR_ERR(ctrl);
413 413
414 414 ctrl->subDeviceInstance = 0;
415 415 ctrl->head = head;
@@ -429,12 +429,20 @@ r535_sor_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u
429 429 ctrl->MST.sendACT = 0;
430 430 ctrl->MST.singleHeadMSTPipeline = 0;
431 431 ctrl->MST.bEnableAudioOverRightPanel = 0;
432 - WARN_ON(nvkm_gsp_rm_ctrl_wr(&disp->rm.objcom, ctrl));
432 + return nvkm_gsp_rm_ctrl_wr(&disp->rm.objcom, ctrl);
433 + }
434 +
435 + static void
436 + r535_sor_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned_pbn)
437 + {
438 + const struct nvkm_rm_api *rmapi = sor->disp->engine.subdev.device->gsp->rm->api;
439 +
440 + WARN_ON(rmapi->disp->dp.vcpi(sor, head, slot, slot_nr, pbn, aligned_pbn));
433 441 }
434 442
435 443 static int
436 - r535_sor_dp_sst(struct nvkm_ior *sor, int head, bool ef,
437 - u32 watermark, u32 hblanksym, u32 vblanksym)
444 + r535_dp_sst(struct nvkm_ior *sor, int head, bool ef,
445 + u32 watermark, u32 hblanksym, u32 vblanksym)
438 446 {
439 447 struct nvkm_disp *disp = sor->disp;
440 448 struct NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS *ctrl;
@@ -461,6 +469,15 @@ r535_sor_dp_sst(struct nvkm_ior *sor, int head, bool ef,
461 469 return nvkm_gsp_rm_ctrl_wr(&disp->rm.objcom, ctrl);
462 470 }
463 471
472 + static int
473 + r535_sor_dp_sst(struct nvkm_ior *sor, int head, bool ef,
474 + u32 watermark, u32 hblanksym, u32 vblanksym)
475 + {
476 + const struct nvkm_rm_api *rmapi = sor->disp->engine.subdev.device->gsp->rm->api;
477 +
478 + return rmapi->disp->dp.sst(sor, head, ef, watermark, hblanksym, vblanksym);
479 + }
480 +
464 481 static const struct nvkm_ior_func_dp
465 482 r535_sor_dp = {
466 483 .sst = r535_sor_dp_sst,
@@ -545,16 +562,21 @@ r535_sor_hdmi_ctrl_audio(struct nvkm_outp *outp, bool enable)
545 562 static void
546 563 r535_sor_hdmi_audio(struct nvkm_ior *sor, int head, bool enable)
547 564 {
548 - struct nvkm_device *device = sor->disp->engine.subdev.device;
549 - const u32 hdmi = head * 0x400;
550 -
551 565 r535_sor_hdmi_ctrl_audio(sor->asy.outp, enable);
552 566 r535_sor_hdmi_ctrl_audio_mute(sor->asy.outp, !enable);
567 + sor->disp->func->gsp.hdmi_gcp(sor, head, enable);
568 + }
569 +
570 + static void
571 + r535_sor_hdmi_infoframe_avi(struct nvkm_ior *sor, int head, void *data, u32 size)
572 + {
573 + sor->disp->func->gsp.hdmi_infoframe_avi(sor, head, data, size);
574 + }
553 575
554 - /* General Control (GCP). */
555 - nvkm_mask(device, 0x6f00c0 + hdmi, 0x00000001, 0x00000000);
556 - nvkm_wr32(device, 0x6f00cc + hdmi, !enable ? 0x00000001 : 0x00000010);
557 - nvkm_mask(device, 0x6f00c0 + hdmi, 0x00000001, 0x00000001);
576 + static void
577 + r535_sor_hdmi_infoframe_vsi(struct nvkm_ior *sor, int head, void *data, u32 size)
578 + {
579 + sor->disp->func->gsp.hdmi_infoframe_vsi(sor, head, data, size);
558 580 }
559 581
560 582 static void
@@ -582,8 +604,8 @@ r535_sor_hdmi = {
582 604 .ctrl = r535_sor_hdmi_ctrl,
583 605 .scdc = r535_sor_hdmi_scdc,
584 606 /*TODO: SF_USER -> KMS. */
585 - .infoframe_avi = gv100_sor_hdmi_infoframe_avi,
586 - .infoframe_vsi = gv100_sor_hdmi_infoframe_vsi,
607 + .infoframe_avi = r535_sor_hdmi_infoframe_avi,
608 + .infoframe_vsi = r535_sor_hdmi_infoframe_vsi,
587 609 .audio = r535_sor_hdmi_audio,
588 610 };
589 611
@@ -608,31 +630,6 @@ r535_sor_cnt(struct nvkm_disp *disp, unsigned long *pmask)
608 630 return 4;
609 631 }
610 632
611 - static void
612 - r535_head_vblank_put(struct nvkm_head *head)
613 - {
614 - struct nvkm_device *device = head->disp->engine.subdev.device;
615 -
616 - nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000002, 0x00000000);
617 - }
618 -
619 - static void
620 - r535_head_vblank_get(struct nvkm_head *head)
621 - {
622 - struct nvkm_device *device = head->disp->engine.subdev.device;
623 -
624 - nvkm_wr32(device, 0x611800 + (head->id * 4), 0x00000002);
625 - nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000002, 0x00000002);
626 - }
627 -
628 - static const struct nvkm_head_func
629 - r535_head = {
630 - .state = gv100_head_state,
631 - .rgpos = gv100_head_rgpos,
632 - .vblank_get = r535_head_vblank_get,
633 - .vblank_put = r535_head_vblank_put,
634 - };
635 -
636 633 static struct nvkm_conn *
637 634 r535_conn_new(struct nvkm_disp *disp, u32 id)
638 635 {
@@ -1404,35 +1401,6 @@ static const struct nvkm_event_func
1404 1401 r535_disp_event = {
1405 1402 };
1406 1403
1407 - static void
1408 - r535_disp_intr_head_timing(struct nvkm_disp *disp, int head)
1409 - {
1410 - struct nvkm_subdev *subdev = &disp->engine.subdev;
1411 - struct nvkm_device *device = subdev->device;
1412 - u32 stat = nvkm_rd32(device, 0x611c00 + (head * 0x04));
1413 -
1414 - if (stat & 0x00000002) {
1415 - nvkm_disp_vblank(disp, head);
1416 -
1417 - nvkm_wr32(device, 0x611800 + (head * 0x04), 0x00000002);
1418 - }
1419 - }
1420 -
1421 - static irqreturn_t
1422 - r535_disp_intr(struct nvkm_inth *inth)
1423 - {
1424 - struct nvkm_disp *disp = container_of(inth, typeof(*disp), engine.subdev.inth);
1425 - struct nvkm_subdev *subdev = &disp->engine.subdev;
1426 - struct nvkm_device *device = subdev->device;
1427 - unsigned long mask = nvkm_rd32(device, 0x611ec0) & 0x000000ff;
1428 - int head;
1429 -
1430 - for_each_set_bit(head, &mask, 8)
1431 - r535_disp_intr_head_timing(disp, head);
1432 -
1433 - return IRQ_HANDLED;
1434 - }
1435 -
1436 1404 static void
1437 1405 r535_disp_fini(struct nvkm_disp *disp, bool suspend)
1438 1406 {
@@ -1659,7 +1627,7 @@ r535_disp_oneinit(struct nvkm_disp *disp)
1659 1627 nvkm_gsp_rm_ctrl_done(&disp->rm.objcom, ctrl);
1660 1628
1661 1629 for_each_set_bit(i, &disp->head.mask, disp->head.nr) {
1662 - ret = nvkm_head_new_(&r535_head, disp, i);
1630 + ret = nvkm_head_new_(disp->func->gsp.head, disp, i);
1663 1631 if (ret)
1664 1632 return ret;
1665 1633 }
@@ -1703,12 +1671,20 @@ r535_disp_oneinit(struct nvkm_disp *disp)
1703 1671 if (ret)
1704 1672 return ret;
1705 1673
1706 - ret = nvkm_gsp_intr_stall(gsp, disp->engine.subdev.type, disp->engine.subdev.inst);
1674 + /* Chips that raise head-timing interrupts on a separate low-latency
1675 + * vector report it as a second DISP interrupt table entry, exposed
1676 + * as instance 1 by the RM engine-index translation (see
1677 + * r570_gsp_xlat_mc_engine_idx()). Their high-latency vector
1678 + * (instance 0) is left unhandled as no event nouveau enables is
1679 + * routed to it, and without a handler it stays masked.
1680 + */
1681 + ret = nvkm_gsp_intr_stall(gsp, disp->engine.subdev.type,
1682 + disp->func->gsp.intr_low_latency ? 1 : disp->engine.subdev.inst);
1707 1683 if (ret < 0)
1708 1684 return ret;
1709 1685
1710 1686 ret = nvkm_inth_add(&device->vfn->intr, ret, NVKM_INTR_PRIO_NORMAL, &disp->engine.subdev,
1711 - r535_disp_intr, &disp->engine.subdev.inth);
1687 + disp->func->gsp.intr, &disp->engine.subdev.inth);
1712 1688 if (ret)
1713 1689 return ret;
1714 1690
@@ -1741,6 +1717,7 @@ r535_disp_new(const struct nvkm_disp_func *hw, struct nvkm_device *device,
1741 1717 rm->uevent = hw->uevent;
1742 1718 rm->sor.cnt = r535_sor_cnt;
1743 1719 rm->sor.new = r535_sor_new;
1720 + rm->gsp = hw->gsp;
1744 1721 rm->ramht_size = hw->ramht_size;
1745 1722
1746 1723 rm->root.oclass = gpu->disp.class.root;
@@ -1782,6 +1759,8 @@ r535_disp = {
1782 1759 .dp = {
1783 1760 .get_caps = r535_dp_get_caps,
1784 1761 .set_indexed_link_rates = r535_dp_set_indexed_link_rates,
1762 + .sst = r535_dp_sst,
1763 + .vcpi = r535_dp_vcpi,
1785 1764 },
1786 1765 .chan = {
1787 1766 .set_pushbuf = r535_disp_chan_set_pushbuf,
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/disp.c
@@ -5,6 +5,7 @@
5 5 #include <rm/rm.h>
6 6
7 7 #include <engine/disp.h>
8 + #include <engine/disp/ior.h>
8 9 #include <engine/disp/outp.h>
9 10
10 11 #include "nvhw/drf.h"
@@ -74,6 +75,67 @@ r570_disp_chan_set_pushbuf(struct nvkm_disp *disp, s32 oclass, int inst, struct
74 75 return nvkm_gsp_rm_ctrl_wr(&gsp->internal.device.subdevice, ctrl);
75 76 }
76 77
78 + static int
79 + r570_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned_pbn)
80 + {
81 + struct nvkm_disp *disp = sor->disp;
82 + NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS *ctrl;
83 +
84 + ctrl = nvkm_gsp_rm_ctrl_get(&disp->rm.objcom,
85 + NV0073_CTRL_CMD_DP_CONFIG_STREAM, sizeof(*ctrl));
86 + if (IS_ERR(ctrl))
87 + return PTR_ERR(ctrl);
88 +
89 + ctrl->subDeviceInstance = 0;
90 + ctrl->head = head;
91 + ctrl->sorIndex = sor->id;
92 + ctrl->dpLink = sor->asy.link == 2;
93 + ctrl->bEnableOverride = 1;
94 + ctrl->bMST = 1;
95 + ctrl->hBlankSym = 0;
96 + ctrl->vBlankSym = 0;
97 + ctrl->colorFormat = 0;
98 + ctrl->bEnableTwoHeadOneOr = 0;
99 + ctrl->singleHeadMultistreamMode = 0;
100 + ctrl->MST.slotStart = slot;
101 + ctrl->MST.slotEnd = slot + slot_nr - 1;
102 + ctrl->MST.PBN = pbn;
103 + ctrl->MST.Timeslice = aligned_pbn;
104 + ctrl->MST.sendACT = 0;
105 + ctrl->MST.singleHeadMSTPipeline = 0;
106 + ctrl->MST.bEnableAudioOverRightPanel = 0;
107 + return nvkm_gsp_rm_ctrl_wr(&disp->rm.objcom, ctrl);
108 + }
109 +
110 + static int
111 + r570_dp_sst(struct nvkm_ior *sor, int head, bool ef,
112 + u32 watermark, u32 hblanksym, u32 vblanksym)
113 + {
114 + struct nvkm_disp *disp = sor->disp;
115 + NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS *ctrl;
116 +
117 + ctrl = nvkm_gsp_rm_ctrl_get(&disp->rm.objcom,
118 + NV0073_CTRL_CMD_DP_CONFIG_STREAM, sizeof(*ctrl));
119 + if (IS_ERR(ctrl))
120 + return PTR_ERR(ctrl);
121 +
122 + ctrl->subDeviceInstance = 0;
123 + ctrl->head = head;
124 + ctrl->sorIndex = sor->id;
125 + ctrl->dpLink = sor->asy.link == 2;
126 + ctrl->bEnableOverride = 1;
127 + ctrl->bMST = 0;
128 + ctrl->hBlankSym = hblanksym;
129 + ctrl->vBlankSym = vblanksym;
130 + ctrl->colorFormat = 0;
131 + ctrl->bEnableTwoHeadOneOr = 0;
132 + ctrl->SST.bEnhancedFraming = ef;
133 + ctrl->SST.tuSize = 64;
134 + ctrl->SST.waterMark = watermark;
135 + ctrl->SST.bEnableAudioOverRightPanel = 0;
136 + return nvkm_gsp_rm_ctrl_wr(&disp->rm.objcom, ctrl);
137 + }
138 +
77 139 static int
78 140 r570_dp_set_indexed_link_rates(struct nvkm_outp *outp)
79 141 {
@@ -255,6 +317,8 @@ r570_disp = {
255 317 .dp = {
256 318 .get_caps = r570_dp_get_caps,
257 319 .set_indexed_link_rates = r570_dp_set_indexed_link_rates,
320 + .sst = r570_dp_sst,
321 + .vcpi = r570_dp_vcpi,
258 322 },
259 323 .chan = {
260 324 .set_pushbuf = r570_disp_chan_set_pushbuf,
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c
@@ -44,6 +44,15 @@ r570_gsp_xlat_mc_engine_idx(u32 mc_engine_idx, enum nvkm_subdev_type *ptype, int
44 44 *ptype = NVKM_ENGINE_DISP;
45 45 *pinst = 0;
46 46 return true;
47 + case MC_ENGINE_IDX_DISP_LOW:
48 + /* GB20x+ report a separate low-latency display vector, used
49 + * for head-timing interrupts. Expose it as a second DISP
50 + * interrupt instance. r535_disp_oneinit() attaches the
51 + * handler to it when the chip's gsp.intr_low_latency is set.
52 + */
53 + *ptype = NVKM_ENGINE_DISP;
54 + *pinst = 1;
55 + return true;
47 56 case MC_ENGINE_IDX_CE0 ... MC_ENGINE_IDX_CE19:
48 57 *ptype = NVKM_ENGINE_CE;
49 58 *pinst = mc_engine_idx - MC_ENGINE_IDX_CE0;
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/disp.h
@@ -256,6 +256,8 @@ typedef struct NV0073_CTRL_DP_CTRL_PARAMS {
256 256 NvU32 eightLaneDpcdBaseAddr;
257 257 } NV0073_CTRL_DP_CTRL_PARAMS;
258 258
259 + #define NV0073_CTRL_CMD_DP_CONFIG_STREAM (0x731362U) /* finn: Evaluated from "(FINN_NV04_DISPLAY_COMMON_DP_INTERFACE_ID << 8) | NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS_MESSAGE_ID" */
260 +
259 261 typedef struct NV0073_CTRL_CMD_DP_CONFIG_STREAM_PARAMS {
260 262 NvU32 subDeviceInstance;
261 263 NvU32 head;
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h
@@ -6,6 +6,7 @@
6 6 #ifndef __NVKM_RM_H__
7 7 #define __NVKM_RM_H__
8 8 #include "handles.h"
9 + struct nvkm_ior;
9 10 struct nvkm_outp;
10 11 struct r535_gr;
11 12
@@ -93,6 +94,10 @@ struct nvkm_rm_api {
93 94 struct {
94 95 int (*get_caps)(struct nvkm_disp *, int *link_bw, bool *mst, bool *wm);
95 96 int (*set_indexed_link_rates)(struct nvkm_outp *);
97 + int (*sst)(struct nvkm_ior *, int head, bool ef,
98 + u32 watermark, u32 hblanksym, u32 vblanksym);
99 + int (*vcpi)(struct nvkm_ior *, int head,
100 + u8 slot, u8 slot_nr, u16 pbn, u16 aligned_pbn);
96 101 } dp;
97 102
98 103 struct {
modified drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
@@ -195,6 +195,9 @@ check_io_mapping(struct nv50_instmem *imem)
195 195 {
196 196 struct nvkm_device *device = imem->base.subdev.device;
197 197
198 + if (imem->iomap.size)
199 + return true;
200 +
198 201 return io_mapping_init_wc(&imem->iomap,
199 202 device->func->resource_addr(device, NVKM_BAR2_INST),
200 203 device->func->resource_size(device, NVKM_BAR2_INST)) != NULL;
modified drivers/gpu/drm/qxl/qxl_display.c
@@ -981,7 +981,7 @@ static struct drm_plane *qxl_create_plane(struct qxl_device *qdev,
981 981 return ERR_PTR(-EINVAL);
982 982 }
983 983
984 - plane = kzalloc(sizeof(*plane), GFP_KERNEL);
984 + plane = kzalloc_obj(*plane);
985 985 if (!plane)
986 986 return ERR_PTR(-ENOMEM);
987 987
modified drivers/gpu/drm/sysfb/ofdrm.c
@@ -2,6 +2,7 @@
2 2
3 3 #include <linux/aperture.h>
4 4 #include <linux/of_address.h>
5 + #include <linux/overflow.h>
5 6 #include <linux/pci.h>
6 7 #include <linux/platform_device.h>
7 8 #include <linux/pm.h>
@@ -238,7 +239,7 @@ static bool is_avivo(u32 vendor, u32 device)
238 239 /* This will match most R5xx */
239 240 return (vendor == PCI_VENDOR_ID_ATI) &&
240 241 ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
241 - (PCI_VENDOR_ID_ATI_R600 >= 0x9400));
242 + (device >= PCI_VENDOR_ID_ATI_R600));
242 243 }
243 244
244 245 static enum ofdrm_model display_get_model_of(struct drm_device *dev, struct device_node *of_node)
@@ -913,7 +914,10 @@ static struct ofdrm_device *ofdrm_device_create(struct drm_driver *drv,
913 914 return ERR_PTR(-EINVAL);
914 915 }
915 916
916 - fb_size = linebytes * height;
917 + if (check_mul_overflow(linebytes, height, &fb_size)) {
918 + drm_err(dev, "framebuffer size exceeds maximum\n");
919 + return ERR_PTR(-EINVAL);
920 + }
917 921
918 922 /*
919 923 * Try to figure out the address of the framebuffer. Unfortunately, Open
modified drivers/gpu/drm/tegra/dc.c
@@ -904,6 +904,7 @@ static struct drm_plane *tegra_primary_plane_create(struct drm_device *drm,
904 904 struct tegra_dc *dc)
905 905 {
906 906 unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
907 + unsigned int blend_caps = BIT(DRM_MODE_BLEND_COVERAGE);
907 908 enum drm_plane_type type = DRM_PLANE_TYPE_PRIMARY;
908 909 struct tegra_plane *plane;
909 910 unsigned int num_formats;
@@ -939,6 +940,7 @@ static struct drm_plane *tegra_primary_plane_create(struct drm_device *drm,
939 940 }
940 941
941 942 drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs);
943 + drm_plane_create_blend_mode_property(&plane->base, blend_caps);
942 944 drm_plane_create_zpos_property(&plane->base, plane->index, 0, 255);
943 945
944 946 err = drm_plane_create_rotation_property(&plane->base,
@@ -1209,6 +1211,7 @@ static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm,
1209 1211 struct tegra_dc *dc)
1210 1212 {
1211 1213 unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
1214 + unsigned int blend_caps = BIT(DRM_MODE_BLEND_COVERAGE);
1212 1215 struct tegra_plane *plane;
1213 1216 unsigned int num_formats;
1214 1217 const u32 *formats;
@@ -1252,6 +1255,7 @@ static struct drm_plane *tegra_dc_cursor_plane_create(struct drm_device *drm,
1252 1255 }
1253 1256
1254 1257 drm_plane_helper_add(&plane->base, &tegra_cursor_plane_helper_funcs);
1258 + drm_plane_create_blend_mode_property(&plane->base, blend_caps);
1255 1259 drm_plane_create_zpos_immutable_property(&plane->base, 255);
1256 1260
1257 1261 return &plane->base;
@@ -1356,6 +1360,7 @@ static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm,
1356 1360 bool cursor)
1357 1361 {
1358 1362 unsigned long possible_crtcs = tegra_plane_get_possible_crtcs(drm);
1363 + unsigned int blend_caps = BIT(DRM_MODE_BLEND_COVERAGE);
1359 1364 struct tegra_plane *plane;
1360 1365 unsigned int num_formats;
1361 1366 enum drm_plane_type type;
@@ -1394,6 +1399,7 @@ static struct drm_plane *tegra_dc_overlay_plane_create(struct drm_device *drm,
1394 1399 }
1395 1400
1396 1401 drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs);
1402 + drm_plane_create_blend_mode_property(&plane->base, blend_caps);
1397 1403 drm_plane_create_zpos_property(&plane->base, plane->index, 0, 255);
1398 1404
1399 1405 err = drm_plane_create_rotation_property(&plane->base,
modified drivers/gpu/drm/tegra/hub.c
@@ -759,6 +759,7 @@ struct drm_plane *tegra_shared_plane_create(struct drm_device *drm,
759 759 unsigned int index,
760 760 enum drm_plane_type type)
761 761 {
762 + unsigned int blend_caps = BIT(DRM_MODE_BLEND_COVERAGE);
762 763 struct tegra_drm *tegra = drm->dev_private;
763 764 struct tegra_display_hub *hub = tegra->hub;
764 765 struct tegra_shared_plane *plane;
@@ -797,6 +798,7 @@ struct drm_plane *tegra_shared_plane_create(struct drm_device *drm,
797 798 }
798 799
799 800 drm_plane_helper_add(p, &tegra_shared_plane_helper_funcs);
801 + drm_plane_create_blend_mode_property(p, blend_caps);
800 802 drm_plane_create_zpos_property(p, 0, 0, 255);
801 803
802 804 return p;
modified drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c
@@ -22,7 +22,7 @@ tilcdc_panel_update_prop(struct of_changeset *ocs, struct device_node *node,
22 22 {
23 23 struct property *prop;
24 24
25 - prop = kzalloc(sizeof(*prop), GFP_KERNEL);
25 + prop = kzalloc_obj(*prop);
26 26 if (!prop)
27 27 return -ENOMEM;
28 28
modified drivers/gpu/drm/tiny/cirrus-qemu.c
@@ -582,6 +582,9 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
582 582 struct cirrus_device *cirrus;
583 583 int ret;
584 584
585 + if (pci_resource_len(pdev, 0) < CIRRUS_VRAM_SIZE)
586 + return -ENODEV;
587 +
585 588 ret = aperture_remove_conflicting_pci_devices(pdev, cirrus_driver.name);
586 589 if (ret)
587 590 return ret;
modified drivers/gpu/drm/verisilicon/vs_plane.c
@@ -136,7 +136,7 @@ struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane)
136 136
137 137 vs_state_old = to_vs_plane_state(plane->state);
138 138
139 - vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
139 + vs_state = kzalloc_obj(*vs_state);
140 140 if (!vs_state)
141 141 return NULL;
142 142
@@ -166,7 +166,7 @@ void vs_plane_reset(struct drm_plane *plane)
166 166 plane->state = NULL;
167 167 }
168 168
169 - vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
169 + vs_state = kzalloc_obj(*vs_state);
170 170 if (!vs_state)
171 171 return;
172 172
modified drivers/gpu/drm/virtio/virtgpu_display.c
@@ -344,7 +344,7 @@ virtio_gpu_user_framebuffer_create(struct drm_device *dev,
344 344 if (ret) {
345 345 kfree(virtio_gpu_fb);
346 346 drm_gem_object_put(obj);
347 - return NULL;
347 + return ERR_PTR(ret);
348 348 }
349 349
350 350 return &virtio_gpu_fb->base;
@@ -378,8 +378,11 @@ int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
378 378
379 379 vgdev->ddev->mode_config.fb_modifiers_not_supported = true;
380 380
381 - for (i = 0 ; i < vgdev->num_scanouts; ++i)
382 - vgdev_output_init(vgdev, i);
381 + for (i = 0; i < vgdev->num_scanouts; ++i) {
382 + ret = vgdev_output_init(vgdev, i);
383 + if (ret)
384 + return ret;
385 + }
383 386
384 387 ret = drm_vblank_init(vgdev->ddev, vgdev->num_scanouts);
385 388 if (ret)
modified drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -43,6 +43,8 @@
43 43 #include <drm/drm_probe_helper.h>
44 44 #include <drm/virtgpu_drm.h>
45 45
46 + #include <xen/xen.h>
47 +
46 48 #define DRIVER_NAME "virtio_gpu"
47 49 #define DRIVER_DESC "virtio GPU"
48 50
@@ -60,6 +62,24 @@
60 62 /* See virtio_gpu_ctx_create. One additional character for NULL terminator. */
61 63 #define DEBUG_NAME_MAX_LEN 65
62 64
65 + /*
66 + * Whether the host must be told about resource backing pages by DMA address
67 + * rather than guest-physical address.
68 + *
69 + * This mirrors vring_use_map_api() in drivers/virtio/virtio_ring.c, including
70 + * its xen_domain() case.
71 + */
72 + static inline bool virtio_gpu_use_dma_api(const struct virtio_device *vdev)
73 + {
74 + if (!virtio_has_dma_quirk(vdev))
75 + return true;
76 +
77 + if (xen_domain())
78 + return true;
79 +
80 + return false;
81 + }
82 +
63 83 struct virtio_gpu_object_params {
64 84 unsigned long size;
65 85 bool dumb;
@@ -343,6 +363,7 @@ void virtio_gpu_array_put_free_work(struct work_struct *work);
343 363 /* virtgpu_vq.c */
344 364 int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev);
345 365 void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);
366 + void virtio_gpu_reclaim_vbufs(struct virtio_gpu_device *vgdev);
346 367 void virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
347 368 struct virtio_gpu_object *bo,
348 369 struct virtio_gpu_object_params *params,
modified drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -352,6 +352,7 @@ void virtio_gpu_deinit(struct drm_device *dev)
352 352 flush_work(&vgdev->cursorq.dequeue_work);
353 353 flush_work(&vgdev->config_changed_work);
354 354 virtio_reset_device(vgdev->vdev);
355 + virtio_gpu_reclaim_vbufs(vgdev);
355 356 vgdev->vdev->config->del_vqs(vgdev->vdev);
356 357 mutex_destroy(&vgdev->obj_restore_lock);
357 358 }
modified drivers/gpu/drm/virtio/virtgpu_object.c
@@ -173,7 +173,7 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
173 173 struct virtio_gpu_mem_entry **ents,
174 174 unsigned int *nents)
175 175 {
176 - bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
176 + bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
177 177 struct scatterlist *sg;
178 178 struct sg_table *pages;
179 179 int si;
modified drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -293,9 +293,7 @@ int virtgpu_dma_buf_obj_resubmit(struct virtio_gpu_device *vgdev,
293 293 return -ENOMEM;
294 294 }
295 295
296 - ents = kvmalloc_array(bo->sgt->nents,
297 - sizeof(struct virtio_gpu_mem_entry),
298 - GFP_KERNEL);
296 + ents = kvmalloc_objs(struct virtio_gpu_mem_entry, bo->sgt->nents);
299 297 if (!ents) {
300 298 DRM_ERROR("failed to allocate ent list\n");
301 299 return -ENOMEM;
modified drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -208,6 +208,21 @@ static void free_vbuf(struct virtio_gpu_device *vgdev,
208 208 kmem_cache_free(vgdev->vbufs, vbuf);
209 209 }
210 210
211 + void virtio_gpu_reclaim_vbufs(struct virtio_gpu_device *vgdev)
212 + {
213 + struct virtio_gpu_vbuffer *vbuf;
214 +
215 + while ((vbuf = virtqueue_detach_unused_buf(vgdev->ctrlq.vq))) {
216 + if (vbuf->objs)
217 + virtio_gpu_array_put_free(vbuf->objs);
218 + if (vbuf->resp_cb_data)
219 + virtio_gpu_cleanup_object(vbuf->resp_cb_data);
220 + free_vbuf(vgdev, vbuf);
221 + }
222 + while ((vbuf = virtqueue_detach_unused_buf(vgdev->cursorq.vq)))
223 + free_vbuf(vgdev, vbuf);
224 + }
225 +
211 226 static void reclaim_vbufs(struct virtqueue *vq, struct list_head *reclaim_list)
212 227 {
213 228 struct virtio_gpu_vbuffer *vbuf;
@@ -764,7 +779,7 @@ int virtio_gpu_panic_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
764 779 struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(objs->objs[0]);
765 780 struct virtio_gpu_transfer_to_host_2d *cmd_p;
766 781 struct virtio_gpu_vbuffer *vbuf;
767 - bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
782 + bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
768 783
769 784 if (virtio_gpu_is_shmem(bo) && use_dma_api)
770 785 dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
@@ -795,7 +810,7 @@ void virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
795 810 struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(objs->objs[0]);
796 811 struct virtio_gpu_transfer_to_host_2d *cmd_p;
797 812 struct virtio_gpu_vbuffer *vbuf;
798 - bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
813 + bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
799 814
800 815 if (virtio_gpu_is_shmem(bo) && use_dma_api)
801 816 dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
@@ -1228,7 +1243,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
1228 1243 struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(objs->objs[0]);
1229 1244 struct virtio_gpu_transfer_host_3d *cmd_p;
1230 1245 struct virtio_gpu_vbuffer *vbuf;
1231 - bool use_dma_api = !virtio_has_dma_quirk(vgdev->vdev);
1246 + bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
1232 1247
1233 1248 if (virtio_gpu_is_shmem(bo) && use_dma_api)
1234 1249 dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
modified drivers/gpu/drm/vkms/vkms_configfs.c
@@ -212,7 +212,7 @@ static struct config_group *make_crtc_group(struct config_group *group,
212 212 if (dev->enabled)
213 213 return ERR_PTR(-EBUSY);
214 214
215 - crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
215 + crtc = kzalloc_obj(*crtc);
216 216 if (!crtc)
217 217 return ERR_PTR(-ENOMEM);
218 218
@@ -368,7 +368,7 @@ static struct config_group *make_plane_group(struct config_group *group,
368 368 if (dev->enabled)
369 369 return ERR_PTR(-EBUSY);
370 370
371 - plane = kzalloc(sizeof(*plane), GFP_KERNEL);
371 + plane = kzalloc_obj(*plane);
372 372 if (!plane)
373 373 return ERR_PTR(-ENOMEM);
374 374
@@ -484,7 +484,7 @@ static struct config_group *make_encoder_group(struct config_group *group,
484 484 if (dev->enabled)
485 485 return ERR_PTR(-EBUSY);
486 486
487 - encoder = kzalloc(sizeof(*encoder), GFP_KERNEL);
487 + encoder = kzalloc_obj(*encoder);
488 488 if (!encoder)
489 489 return ERR_PTR(-ENOMEM);
490 490
@@ -651,7 +651,7 @@ static struct config_group *make_connector_group(struct config_group *group,
651 651 if (dev->enabled)
652 652 return ERR_PTR(-EBUSY);
653 653
654 - connector = kzalloc(sizeof(*connector), GFP_KERNEL);
654 + connector = kzalloc_obj(*connector);
655 655 if (!connector)
656 656 return ERR_PTR(-ENOMEM);
657 657
modified drivers/gpu/drm/xe/xe_amc.c
@@ -177,7 +177,7 @@ int xe_amc_init(struct xe_i2c *i2c)
177 177 {
178 178 struct xe_amc *amc;
179 179
180 - amc = kzalloc(sizeof(*amc), GFP_KERNEL);
180 + amc = kzalloc_obj(*amc);
181 181 if (!amc)
182 182 return -ENOMEM;
183 183
modified drivers/gpu/drm/xe/xe_oa.c
@@ -2435,9 +2435,9 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
2435 2435
2436 2436 oa_config->id = idr_alloc(&oa->metrics_idr, oa_config, 1, 0, GFP_KERNEL);
2437 2437 if (oa_config->id < 0) {
2438 - drm_dbg(&oa->xe->drm, "Failed to create sysfs entry for OA config\n");
2438 + drm_dbg(&oa->xe->drm, "Failed to allocate id for OA config\n");
2439 2439 err = oa_config->id;
2440 - goto sysfs_err;
2440 + goto id_alloc_err;
2441 2441 }
2442 2442
2443 2443 id = oa_config->id;
@@ -2448,6 +2448,8 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
2448 2448
2449 2449 return id;
2450 2450
2451 + id_alloc_err:
2452 + sysfs_remove_group(oa->metrics_kobj, &oa_config->sysfs_metric);
2451 2453 sysfs_err:
2452 2454 mutex_unlock(&oa->metrics_lock);
2453 2455 reg_err:
modified drivers/gpu/drm/xe/xe_vm.c
@@ -4148,7 +4148,7 @@ static int fill_faults(struct xe_vm *vm,
4148 4148 entry_size = sizeof(struct xe_vm_fault);
4149 4149 count = args->size / entry_size;
4150 4150
4151 - fault_list = kcalloc(count, sizeof(struct xe_vm_fault), GFP_KERNEL);
4151 + fault_list = kzalloc_objs(struct xe_vm_fault, count);
4152 4152 if (!fault_list)
4153 4153 return -ENOMEM;
4154 4154
modified drivers/gpu/drm/xe/xe_vram.c
@@ -90,6 +90,9 @@ static int get_flat_ccs_offset(struct xe_gt *gt, u64 tile_size, u64 *poffset)
90 90 offset |= offset_lo << 6; /* HW view bits 31:6 */
91 91 offset *= num_enabled; /* convert to SW view */
92 92
93 + drm_info(&xe->drm, "FLAT_CCS base:%llx, aligned:%s\n", offset,
94 + str_yes_no(IS_ALIGNED(offset, SZ_128K)));
95 +
93 96 /*
94 97 * Everything below this offset is handed to the VRAM
95 98 * allocator, so it has to be the *first* address the
modified drivers/hid/Kconfig
@@ -1253,7 +1253,7 @@ config HID_HYPERV_MOUSE
1253 1253
1254 1254 config HID_HYPERV_MOUSE_KUNIT_TEST
1255 1255 bool "KUnit tests for Hyper-V mouse driver" if !KUNIT_ALL_TESTS
1256 - depends on KUNIT && HID_HYPERV_MOUSE
1256 + depends on KUNIT && (HID_HYPERV_MOUSE = KUNIT || KUNIT = y)
1257 1257 default KUNIT_ALL_TESTS
1258 1258 help
1259 1259 Builds unit tests for the Hyper-V synthetic HID driver.
modified drivers/hid/bpf/hid_bpf_struct_ops.c
@@ -62,6 +62,10 @@ struct hid_bpf_offset_write_range {
62 62 u32 end;
63 63 };
64 64
65 + struct hid_bpf_ctx__safe_trusted {
66 + struct hid_device *hid;
67 + };
68 +
65 69 static int hid_bpf_ops_btf_struct_access(struct bpf_verifier_log *log,
66 70 const struct bpf_reg_state *reg,
67 71 int off, int size)
@@ -86,6 +90,8 @@ static int hid_bpf_ops_btf_struct_access(struct bpf_verifier_log *log,
86 90 const char *cur = NULL;
87 91 int i;
88 92
93 + BTF_TYPE_EMIT(struct hid_bpf_ctx__safe_trusted);
94 +
89 95 t = btf_type_by_id(reg->btf, reg->btf_id);
90 96
91 97 for (i = 0; i < ARRAY_SIZE(write_ranges); i++) {
@@ -250,6 +256,11 @@ static void hid_bpf_unreg(void *kdata, struct bpf_link *link)
250 256
251 257 mutex_lock(&hdev->bpf.prog_list_lock);
252 258
259 + if (!ops->hdev) {
260 + mutex_unlock(&hdev->bpf.prog_list_lock);
261 + return;
262 + }
263 +
253 264 list_del_rcu(&ops->list);
254 265 synchronize_srcu(&hdev->bpf.srcu);
255 266 ops->hdev = NULL;
@@ -310,13 +321,17 @@ static struct bpf_struct_ops bpf_hid_bpf_ops = {
310 321 void __hid_bpf_ops_destroy_device(struct hid_device *hdev)
311 322 {
312 323 struct hid_bpf_ops *e;
324 + int count = 0;
313 325
314 - rcu_read_lock();
315 - list_for_each_entry_rcu(e, &hdev->bpf.prog_list, list) {
316 - hid_put_device(hdev);
326 + mutex_lock(&hdev->bpf.prog_list_lock);
327 + list_for_each_entry(e, &hdev->bpf.prog_list, list) {
317 328 e->hdev = NULL;
329 + count++;
318 330 }
319 - rcu_read_unlock();
331 + mutex_unlock(&hdev->bpf.prog_list_lock);
332 +
333 + while (count--)
334 + hid_put_device(hdev);
320 335 }
321 336
322 337 static int __init hid_bpf_struct_ops_init(void)
modified drivers/hid/hid-asus.c
@@ -406,7 +406,7 @@ static int asus_kbd_fn_lock_set(struct asus_drvdata *drvdata, bool enabled)
406 406 struct asus_work_action *action;
407 407 unsigned long flags;
408 408
409 - action = kzalloc(sizeof(struct asus_work_action), GFP_ATOMIC);
409 + action = kzalloc_obj(struct asus_work_action, GFP_ATOMIC);
410 410 if (!action)
411 411 return -ENOMEM;
412 412
@@ -433,7 +433,7 @@ static int asus_kbd_wmi_fan_send(struct asus_drvdata *drvdata, u8 *report_data,
433 433 return -EINVAL;
434 434 }
435 435
436 - action = kzalloc(sizeof(struct asus_work_action), GFP_NOWAIT);
436 + action = kzalloc_obj(struct asus_work_action, GFP_NOWAIT);
437 437 if (!action)
438 438 return -ENOMEM;
439 439
@@ -746,7 +746,7 @@ static void asus_kbd_backlight_set(struct asus_hid_listener *listener, int brigh
746 746
747 747 drvdata->kbd_backlight_brightness = brightness;
748 748
749 - action = kzalloc(sizeof(struct asus_work_action), GFP_NOWAIT);
749 + action = kzalloc_obj(struct asus_work_action, GFP_NOWAIT);
750 750 if (!action)
751 751 return;
752 752
modified drivers/hid/hid-hyperv.c
@@ -687,7 +687,7 @@ static void mousevsc_device_info_valid_descriptor(struct kunit *test)
687 687
688 688 info->hid_descriptor.bLength = sizeof(struct hid_descriptor);
689 689 info->hid_descriptor.rpt_desc.wDescriptorLength = cpu_to_le16(4);
690 - report = ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength;
690 + report = (u8 *)(info + 1);
691 691 memset(report, 0x42, 4);
692 692
693 693 mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 4);
@@ -713,7 +713,7 @@ static void mousevsc_device_info_report_desc_oob(struct kunit *test)
713 713
714 714 info->hid_descriptor.bLength = sizeof(struct hid_descriptor);
715 715 info->hid_descriptor.rpt_desc.wDescriptorLength = cpu_to_le16(64);
716 - report = ((u8 *)&info->hid_descriptor) + info->hid_descriptor.bLength;
716 + report = (u8 *)(info + 1);
717 717 memset(report, 0x42, 8);
718 718
719 719 mousevsc_on_receive_device_info(input_dev, info, sizeof(*info) + 8);
modified drivers/hid/hid-ids.h
@@ -338,6 +338,7 @@
338 338
339 339 #define I2C_VENDOR_ID_CIRQUE 0x0488
340 340 #define I2C_PRODUCT_ID_CIRQUE_1063 0x1063
341 + #define I2C_PRODUCT_ID_CIRQUE_D0C1 0xD0C1
341 342
342 343 #define USB_VENDOR_ID_CJTOUCH 0x24b8
343 344 #define USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020 0x0020
modified drivers/hid/hid-multitouch.c
@@ -1321,21 +1321,18 @@ static void mt_touch_report(struct hid_device *hid,
1321 1321 * Includes multi-packet support where subsequent
1322 1322 * packets are sent with zero contactcount.
1323 1323 */
1324 - if (contact_count >= 0) {
1324 + if (contact_count > 0)
1325 + app->num_expected = contact_count;
1326 + else if (app->num_received == 0 && app->prev_scantime != scantime) {
1325 1327 /*
1328 + * New multi-report frame:
1329 + *
1326 1330 * For Win8 PTPs the first packet (td->num_received == 0) may
1327 1331 * have a contactcount of 0 if there only is a button event.
1328 - * We double check that this is not a continuation packet
1329 - * of a possible multi-packet frame be checking that the
1330 - * timestamp has changed.
1332 + *
1333 + * Some other devices use a sentinel frame with 0 to release all contacts
1331 1334 */
1332 - if ((app->quirks & MT_QUIRK_WIN8_PTP_BUTTONS) &&
1333 - app->num_received == 0 &&
1334 - app->prev_scantime != scantime)
1335 - app->num_expected = contact_count;
1336 - /* A non 0 contact count always indicates a first packet */
1337 - else if (contact_count)
1338 - app->num_expected = contact_count;
1335 + app->num_expected = 0;
1339 1336 }
1340 1337 app->prev_scantime = scantime;
1341 1338
modified drivers/hid/hid-rmi.c
@@ -235,7 +235,23 @@ static int rmi_hid_read_block(struct rmi_transport_dev *xport, u16 addr,
235 235 break;
236 236 }
237 237
238 - read_input_count = data->readReport[1];
238 + read_input_count = min_t(int, data->readReport[1],
239 + data->input_report_size - 2);
240 + if (!read_input_count) {
241 + /*
242 + * A zero length reply advances neither
243 + * bytes_read nor bytes_needed, and because a
244 + * reply did arrive the wait above does not
245 + * time out either, so a device answering 0
246 + * forever would spin here indefinitely with
247 + * page_mutex held.
248 + */
249 + hid_warn(hdev, "%s: zero-length read reply\n",
250 + __func__);
251 + clear_bit(RMI_READ_DATA_PENDING, &data->flags);
252 + ret = -EIO;
253 + break;
254 + }
239 255 memcpy(buf + bytes_read, &data->readReport[2],
240 256 min(read_input_count, bytes_needed));
241 257
@@ -271,6 +287,11 @@ static int rmi_hid_write_block(struct rmi_transport_dev *xport, u16 addr,
271 287 goto exit;
272 288 }
273 289
290 + if (len + 4 > data->output_report_size) {
291 + ret = -EINVAL;
292 + goto exit;
293 + }
294 +
274 295 data->writeReport[0] = RMI_WRITE_REPORT_ID;
275 296 data->writeReport[1] = len;
276 297 data->writeReport[2] = addr & 0xFF;
@@ -666,8 +687,16 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
666 687 return ret;
667 688 }
668 689
669 - if (id->driver_data)
670 - data->device_flags = id->driver_data;
690 + /*
691 + * RMI_DEVICE can only mean "this probe validated the RMI reports and
692 + * allocated writeReport": every bail-out to start below skips that
693 + * allocation, and device_flags left carrying RMI_DEVICE from
694 + * driver_data would send rmi_input_configured() into rmi_set_page()
695 + * with writeReport still NULL. A bind through the new_id sysfs
696 + * attribute can supply driver_data with the bit set, so do not let
697 + * driver_data grant it.
698 + */
699 + data->device_flags = id->driver_data & ~RMI_DEVICE;
671 700
672 701 /*
673 702 * Check for the RMI specific report ids. If they are misisng
@@ -696,6 +725,17 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
696 725
697 726 data->output_report_size = hid_report_len(output_report);
698 727
728 + /*
729 + * The write reports built by this driver occupy 6 bytes and the read
730 + * handshake looks at the first 3 bytes of an input report, so refuse
731 + * to drive a device whose reports cannot hold them.
732 + */
733 + if (data->output_report_size < 6 || data->input_report_size < 3) {
734 + hid_err(hdev, "rmi reports too small (out=%u in=%u)\n",
735 + data->output_report_size, data->input_report_size);
736 + goto start;
737 + }
738 +
699 739 data->device_flags |= RMI_DEVICE;
700 740 alloc_size = data->output_report_size + data->input_report_size;
701 741
modified drivers/hid/hid-steam.c
@@ -759,7 +759,7 @@ static inline int steam_haptic_pulse(struct steam_device *steam, u8 pad,
759 759
760 760 if (steam->quirks & STEAM_QUIRK_IBEX) {
761 761 struct steam_ibex_output_report *report =
762 - kzalloc(sizeof(struct steam_ibex_output_report), GFP_KERNEL);
762 + kzalloc_obj(struct steam_ibex_output_report);
763 763
764 764 if (!report)
765 765 return -ENOMEM;
@@ -798,7 +798,7 @@ static inline int steam_haptic_rumble(struct steam_device *steam,
798 798
799 799 if (steam->quirks & STEAM_QUIRK_IBEX) {
800 800 struct steam_ibex_output_report *report =
801 - kzalloc(sizeof(struct steam_ibex_output_report), GFP_KERNEL);
801 + kzalloc_obj(struct steam_ibex_output_report);
802 802
803 803 if (!report)
804 804 return -ENOMEM;
modified drivers/hid/hid-steelseries-arctis.c
@@ -469,7 +469,7 @@ static int steelseries_arctis_probe(struct hid_device *hdev,
469 469 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
470 470
471 471 if (interface_num == info->sync_interface) {
472 - sd = kzalloc_obj(*sd, GFP_KERNEL);
472 + sd = kzalloc_obj(*sd);
473 473 if (!sd)
474 474 return -ENOMEM;
475 475
modified drivers/hid/i2c-hid/i2c-hid-core.c
@@ -136,6 +136,8 @@ static const struct i2c_hid_quirks {
136 136 I2C_HID_QUIRK_BAD_INPUT_SIZE },
137 137 { I2C_VENDOR_ID_CIRQUE, I2C_PRODUCT_ID_CIRQUE_1063,
138 138 I2C_HID_QUIRK_NO_SLEEP_ON_SUSPEND },
139 + { I2C_VENDOR_ID_CIRQUE, I2C_PRODUCT_ID_CIRQUE_D0C1,
140 + I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
139 141 /*
140 142 * Without additional power on command, at least some QTEC devices send garbage
141 143 */
modified drivers/hid/wacom_wac.c
@@ -1550,6 +1550,19 @@ static int wacom_intuos_pro2_bt_irq(struct wacom_wac *wacom, size_t len)
1550 1550 return 0;
1551 1551 }
1552 1552
1553 + if (wacom->features.type == INTUOSP2_BT ||
1554 + wacom->features.type == INTUOSP2S_BT) {
1555 + if (len < 286) {
1556 + dev_warn(wacom->pen_input->dev.parent,
1557 + "Pro2 BT report too short: %zu bytes\n", len);
1558 + return 0;
1559 + }
1560 + } else if (len < 46) {
1561 + dev_warn(wacom->pen_input->dev.parent,
1562 + "Pro2 BT report too short: %zu bytes\n", len);
1563 + return 0;
1564 + }
1565 +
1553 1566 wacom_intuos_pro2_bt_pen(wacom);
1554 1567 if (wacom->features.type == INTUOSP2_BT ||
1555 1568 wacom->features.type == INTUOSP2S_BT) {
modified drivers/hv/channel.c
@@ -694,12 +694,11 @@ void *vmbus_alloc_buffer(struct vmbus_channel *channel,
694 694 return vzalloc(nr_pages << PAGE_SHIFT);
695 695
696 696 /* Worst case: every chunk is a single page. */
697 - chunks = kvmalloc_array(nr_pages, sizeof(*chunks),
698 - GFP_KERNEL | __GFP_ZERO);
697 + chunks = kvmalloc_objs(*chunks, nr_pages, GFP_KERNEL | __GFP_ZERO);
699 698 if (!chunks)
700 699 goto err;
701 700
702 - pages = kvmalloc_array(nr_pages, sizeof(*pages), GFP_KERNEL);
701 + pages = kvmalloc_objs(*pages, nr_pages);
703 702 if (!pages)
704 703 goto err;
705 704
modified drivers/hv/hv_balloon.c
@@ -939,7 +939,7 @@ static unsigned long process_hot_add(unsigned long pg_start,
939 939 */
940 940
941 941 if (rg_size != 0) {
942 - ha_region = kzalloc(sizeof(struct hv_hotadd_state), GFP_KERNEL);
942 + ha_region = kzalloc_obj(struct hv_hotadd_state);
943 943 if (!ha_region)
944 944 return 0;
945 945
modified drivers/hwmon/applesmc.c
@@ -1476,9 +1476,9 @@ static int __init applesmc_init(void)
1476 1476 applesmc_fan_config[smcreg.fan_count] = 0;
1477 1477 applesmc_pwm_config[smcreg.fan_count] = 0;
1478 1478
1479 - applesmc_info_temp = kzalloc_obj(*applesmc_info_temp, GFP_KERNEL);
1480 - applesmc_info_fan = kzalloc_obj(*applesmc_info_fan, GFP_KERNEL);
1481 - applesmc_info_pwm = kzalloc_obj(*applesmc_info_pwm, GFP_KERNEL);
1479 + applesmc_info_temp = kzalloc_obj(*applesmc_info_temp);
1480 + applesmc_info_fan = kzalloc_obj(*applesmc_info_fan);
1481 + applesmc_info_pwm = kzalloc_obj(*applesmc_info_pwm);
1482 1482 if (!applesmc_info_temp || !applesmc_info_fan || !applesmc_info_pwm) {
1483 1483 ret = -ENOMEM;
1484 1484 goto out_info;
@@ -1493,7 +1493,7 @@ static int __init applesmc_init(void)
1493 1493 applesmc_info_pwm->type = hwmon_pwm;
1494 1494 applesmc_info_pwm->config = applesmc_pwm_config;
1495 1495
1496 - applesmc_info_arr = kcalloc(4, sizeof(*applesmc_info_arr), GFP_KERNEL);
1496 + applesmc_info_arr = kzalloc_objs(*applesmc_info_arr, 4);
1497 1497 if (!applesmc_info_arr) {
1498 1498 ret = -ENOMEM;
1499 1499 goto out_info;
@@ -1504,7 +1504,7 @@ static int __init applesmc_init(void)
1504 1504 applesmc_info_arr[2] = applesmc_info_pwm;
1505 1505 applesmc_info_arr[3] = NULL;
1506 1506
1507 - applesmc_chip = kzalloc_obj(*applesmc_chip, GFP_KERNEL);
1507 + applesmc_chip = kzalloc_obj(*applesmc_chip);
1508 1508 if (!applesmc_chip) {
1509 1509 ret = -ENOMEM;
1510 1510 goto out_info;
@@ -1514,10 +1514,9 @@ static int __init applesmc_init(void)
1514 1514 applesmc_chip->info = applesmc_info_arr;
1515 1515
1516 1516 /* Create non-standard fanX_safe attributes group */
1517 - fan_safe_attrs = kcalloc(smcreg.fan_count,
1518 - sizeof(*fan_safe_attrs), GFP_KERNEL);
1519 - fan_safe_attr_list = kcalloc(smcreg.fan_count + 1,
1520 - sizeof(*fan_safe_attr_list), GFP_KERNEL);
1517 + fan_safe_attrs = kzalloc_objs(*fan_safe_attrs, smcreg.fan_count);
1518 + fan_safe_attr_list = kzalloc_objs(*fan_safe_attr_list,
1519 + smcreg.fan_count + 1);
1521 1520 if (!fan_safe_attrs || !fan_safe_attr_list) {
1522 1521 ret = -ENOMEM;
1523 1522 goto out_info;
modified drivers/hwtracing/coresight/coresight-core.c
@@ -1679,7 +1679,7 @@ coresight_allocate_device_list(const char *prefix)
1679 1679 return list;
1680 1680 }
1681 1681
1682 - list = kzalloc(sizeof(*list), GFP_KERNEL);
1682 + list = kzalloc_obj(*list);
1683 1683 if (!list)
1684 1684 return NULL;
1685 1685
modified drivers/i2c/busses/i2c-gpio.c
@@ -418,7 +418,7 @@ static struct i2c_gpio_scl_data *i2c_gpio_create_scl(struct device *dev)
418 418 }
419 419 }
420 420
421 - scl = kzalloc(sizeof(*scl), GFP_KERNEL);
421 + scl = kzalloc_obj(*scl);
422 422 if (!scl) {
423 423 if (sharable)
424 424 fwnode_handle_put(args.fwnode);
modified drivers/i3c/master/amd-i3c-master.c
@@ -376,7 +376,7 @@ static struct xi3c_xfer *xi3c_master_alloc_xfer(unsigned int ncmds)
376 376 {
377 377 struct xi3c_xfer *xfer;
378 378
379 - xfer = kzalloc_flex(*xfer, cmds, ncmds, GFP_KERNEL);
379 + xfer = kzalloc_flex(*xfer, cmds, ncmds);
380 380 if (!xfer)
381 381 return NULL;
382 382
@@ -735,7 +735,7 @@ static int xi3c_master_send_bdcast_ccc_cmd(struct xi3c_master *master,
735 735 if (!xfer)
736 736 return -ENOMEM;
737 737
738 - buf = kmalloc_objs(*buf, xfer_len, GFP_KERNEL);
738 + buf = kmalloc_objs(*buf, xfer_len);
739 739 if (!buf)
740 740 return -ENOMEM;
741 741
modified drivers/iio/adc/ad7280a.c
@@ -796,8 +796,8 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
796 796 struct ad7280_state *st = iio_priv(indio_dev);
797 797 int i, ret;
798 798
799 - unsigned int *channels __free(kfree) = kcalloc(st->scan_cnt, sizeof(*channels),
800 - GFP_KERNEL);
799 + unsigned int *channels __free(kfree) = kzalloc_objs(*channels,
800 + st->scan_cnt);
801 801 if (!channels)
802 802 return IRQ_HANDLED;
803 803
modified drivers/iio/buffer/industrialio-buffer-dmaengine.c
@@ -109,7 +109,7 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue,
109 109 if (nents < 0)
110 110 return nents;
111 111
112 - vecs = kmalloc_array(nents, sizeof(*vecs), GFP_ATOMIC);
112 + vecs = kmalloc_objs(*vecs, nents, GFP_ATOMIC);
113 113 if (!vecs)
114 114 return -ENOMEM;
115 115
modified drivers/iio/inkern.c
@@ -345,7 +345,7 @@ static struct iio_channel *iio_channel_get_sys(const char *name,
345 345 return ERR_PTR(-ENODEV);
346 346
347 347 struct iio_channel *channel __free(kfree) =
348 - kzalloc(sizeof(*channel), GFP_KERNEL);
348 + kzalloc_obj(*channel);
349 349 if (!channel) {
350 350 err = -ENOMEM;
351 351 goto error_no_mem;
modified drivers/infiniband/core/nldev.c
@@ -2943,7 +2943,7 @@ static int nldev_frmr_pools_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
2943 2943 u32 aging_period;
2944 2944 int err;
2945 2945
2946 - tb = kzalloc_objs(*tb, RDMA_NLDEV_ATTR_MAX, GFP_KERNEL);
2946 + tb = kzalloc_objs(*tb, RDMA_NLDEV_ATTR_MAX);
2947 2947 if (!tb)
2948 2948 return -ENOMEM;
2949 2949
modified drivers/infiniband/hw/hns/hns_roce_debugfs.c
@@ -267,8 +267,7 @@ static int hns_roce_alloc_scc_param(struct hns_roce_dev *hr_dev)
267 267 struct hns_roce_scc_param *scc_param;
268 268 int i;
269 269
270 - scc_param = kvcalloc(HNS_ROCE_SCC_ALGO_TOTAL, sizeof(*scc_param),
271 - GFP_KERNEL);
270 + scc_param = kvzalloc_objs(*scc_param, HNS_ROCE_SCC_ALGO_TOTAL);
272 271 if (!scc_param)
273 272 return -ENOMEM;
274 273
modified drivers/input/input.c
@@ -2344,7 +2344,7 @@ static int input_device_tune_vals(struct input_dev *dev)
2344 2344 if (dev->max_vals >= max_vals)
2345 2345 return 0;
2346 2346
2347 - vals = kcalloc(max_vals, sizeof(*vals), GFP_KERNEL);
2347 + vals = kzalloc_objs(*vals, max_vals);
2348 2348 if (!vals)
2349 2349 return -ENOMEM;
2350 2350
modified drivers/input/keyboard/adp5585-keys.c
@@ -115,8 +115,8 @@ static int adp5585_keys_parse_fw(const struct adp5585_dev *adp5585,
115 115 "Too many keypad pins (%d) defined (max=%d)\n",
116 116 n_pins, adp5585->n_pins);
117 117
118 - unsigned int *keypad_pins __free(kfree) = kcalloc(n_pins, sizeof(*keypad_pins),
119 - GFP_KERNEL);
118 + unsigned int *keypad_pins __free(kfree) = kzalloc_objs(*keypad_pins,
119 + n_pins);
120 120 if (!keypad_pins)
121 121 return -ENOMEM;
122 122
modified drivers/input/keyboard/atkbd.c
@@ -1070,7 +1070,7 @@ static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
1070 1070 if (n <= 0 || n > ATKBD_KEYMAP_SIZE)
1071 1071 return -ENXIO;
1072 1072
1073 - u32 *ptr __free(kfree) = kcalloc(n, sizeof(*ptr), GFP_KERNEL);
1073 + u32 *ptr __free(kfree) = kzalloc_objs(*ptr, n);
1074 1074 if (!ptr)
1075 1075 return -ENOMEM;
1076 1076
modified drivers/input/misc/ims-pcu.c
@@ -1844,7 +1844,7 @@ static int ims_pcu_line_setup(struct ims_pcu *pcu)
1844 1844 {
1845 1845 struct usb_host_interface *interface = pcu->ctrl_intf->cur_altsetting;
1846 1846 struct usb_cdc_line_coding *line __free(kfree) =
1847 - kmalloc(sizeof(*line), GFP_KERNEL);
1847 + kmalloc_obj(*line);
1848 1848 int error;
1849 1849
1850 1850 if (!line)
modified drivers/input/mouse/psmouse-smbus.c
@@ -232,7 +232,7 @@ int psmouse_smbus_init(struct psmouse *psmouse,
232 232 struct psmouse_smbus_dev *smbdev;
233 233 int error;
234 234
235 - smbdev = kzalloc(sizeof(*smbdev), GFP_KERNEL);
235 + smbdev = kzalloc_obj(*smbdev);
236 236 if (!smbdev)
237 237 return -ENOMEM;
238 238
modified drivers/input/serio/serio_raw.c
@@ -84,7 +84,7 @@ static int serio_raw_open(struct inode *inode, struct file *file)
84 84 if (serio_raw->dead)
85 85 return -ENODEV;
86 86
87 - client = kzalloc(sizeof(*client), GFP_KERNEL);
87 + client = kzalloc_obj(*client);
88 88 if (!client)
89 89 return -ENOMEM;
90 90
modified drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -796,7 +796,7 @@ static inline struct arm_smmu_invs *arm_smmu_invs_alloc(size_t num_invs)
796 796 {
797 797 struct arm_smmu_invs *new_invs;
798 798
799 - new_invs = kzalloc(struct_size(new_invs, inv, num_invs), GFP_KERNEL);
799 + new_invs = kzalloc_flex(*new_invs, inv, num_invs);
800 800 if (!new_invs)
801 801 return NULL;
802 802 new_invs->max_invs = num_invs;
modified drivers/iommu/iommufd/device.c
@@ -76,7 +76,7 @@ static struct iommufd_group *iommufd_alloc_group(struct iommufd_ctx *ictx,
76 76 {
77 77 struct iommufd_group *new_igroup;
78 78
79 - new_igroup = kzalloc_obj(*new_igroup, GFP_KERNEL);
79 + new_igroup = kzalloc_obj(*new_igroup);
80 80 if (!new_igroup)
81 81 return ERR_PTR(-ENOMEM);
82 82
modified drivers/iommu/iommufd/driver.c
@@ -49,7 +49,7 @@ int _iommufd_alloc_mmap(struct iommufd_ctx *ictx, struct iommufd_object *owner,
49 49 if (!length || !PAGE_ALIGNED(length))
50 50 return -EINVAL;
51 51
52 - immap = kzalloc(sizeof(*immap), GFP_KERNEL);
52 + immap = kzalloc_obj(*immap);
53 53 if (!immap)
54 54 return -ENOMEM;
55 55 immap->owner = owner;
modified drivers/iommu/iommufd/hwpt_noiommu.c
@@ -54,7 +54,7 @@ noiommu_alloc_paging_flags(struct device *dev, u32 flags,
54 54 (BIT(PT_FEAT_DYNAMIC_TOP) | BIT(PT_FEAT_AMDV1_ENCRYPT_TABLES) |
55 55 BIT(PT_FEAT_AMDV1_FORCE_COHERENCE));
56 56
57 - dom = kzalloc(sizeof(*dom), GFP_KERNEL);
57 + dom = kzalloc_obj(*dom);
58 58 if (!dom)
59 59 return ERR_PTR(-ENOMEM);
60 60
modified drivers/iommu/vsi-iommu.c
@@ -231,7 +231,7 @@ static struct iommu_domain *vsi_iommu_domain_alloc_paging(struct device *dev)
231 231 struct vsi_iommu *iommu = dev_iommu_priv_get(dev);
232 232 struct vsi_iommu_domain *vsi_domain;
233 233
234 - vsi_domain = kzalloc(sizeof(*vsi_domain), GFP_KERNEL);
234 + vsi_domain = kzalloc_obj(*vsi_domain);
235 235 if (!vsi_domain)
236 236 return NULL;
237 237
modified drivers/irqchip/irq-gic-v5-irs.c
@@ -618,7 +618,7 @@ static int __init gicv5_irs_of_init_affinity(struct device_node *node,
618 618 if (niaffids != ncpus)
619 619 return -EINVAL;
620 620
621 - u16 *iaffids __free(kfree) = kcalloc(niaffids, sizeof(*iaffids), GFP_KERNEL);
621 + u16 *iaffids __free(kfree) = kzalloc_objs(*iaffids, niaffids);
622 622 if (!iaffids)
623 623 return -ENOMEM;
624 624
modified drivers/irqchip/irq-loongarch-ir.c
@@ -331,7 +331,7 @@ static int redirect_domain_alloc(struct irq_domain *domain, unsigned int virq,
331 331 struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq + i);
332 332 struct redirect_item *item;
333 333
334 - item = kzalloc(sizeof(*item), GFP_KERNEL);
334 + item = kzalloc_obj(*item);
335 335 if (!item) {
336 336 pr_err("Alloc redirect descriptor failed\n");
337 337 goto out_free_resources;
modified drivers/irqchip/irq-mbigen.c
@@ -64,20 +64,6 @@ struct mbigen_device {
64 64 void __iomem *base;
65 65 };
66 66
67 - static inline unsigned int get_mbigen_node_offset(unsigned int nid)
68 - {
69 - unsigned int offset = nid * MBIGEN_NODE_OFFSET;
70 -
71 - /*
72 - * To avoid touched clear register in unexpected way, we need to directly
73 - * skip clear register when access to more than 10 mbigen nodes.
74 - */
75 - if (nid >= (REG_MBIGEN_CLEAR_OFFSET / MBIGEN_NODE_OFFSET))
76 - offset += MBIGEN_NODE_OFFSET;
77 -
78 - return offset;
79 - }
80 -
81 67 static inline unsigned int get_mbigen_vec_reg(irq_hw_number_t hwirq)
82 68 {
83 69 unsigned int nid, pin;
@@ -86,7 +72,8 @@ static inline unsigned int get_mbigen_vec_reg(irq_hw_number_t hwirq)
86 72 nid = hwirq / IRQS_PER_MBIGEN_NODE + 1;
87 73 pin = hwirq % IRQS_PER_MBIGEN_NODE;
88 74
89 - return pin * 4 + get_mbigen_node_offset(nid) + REG_MBIGEN_VEC_OFFSET;
75 + return pin * 4 + nid * MBIGEN_NODE_OFFSET
76 + + REG_MBIGEN_VEC_OFFSET;
90 77 }
91 78
92 79 static inline void get_mbigen_type_reg(irq_hw_number_t hwirq,
@@ -101,7 +88,8 @@ static inline void get_mbigen_type_reg(irq_hw_number_t hwirq,
101 88 *mask = 1 << (irq_ofst % 32);
102 89 ofst = irq_ofst / 32 * 4;
103 90
104 - *addr = ofst + get_mbigen_node_offset(nid) + REG_MBIGEN_TYPE_OFFSET;
91 + *addr = ofst + nid * MBIGEN_NODE_OFFSET
92 + + REG_MBIGEN_TYPE_OFFSET;
105 93 }
106 94
107 95 static inline void get_mbigen_clear_reg(irq_hw_number_t hwirq,
modified drivers/irqchip/irq-realtek-rtl.c
@@ -188,7 +188,7 @@ static int __init realtek_setup_parents(struct device_node *node)
188 188 struct irq_domain *domain;
189 189
190 190 cnt = max(1, num_parents);
191 - output = kcalloc(cnt, sizeof(*output), GFP_KERNEL);
191 + output = kzalloc_objs(*output, cnt);
192 192 if (!output)
193 193 return -ENOMEM;
194 194
modified drivers/irqchip/irq-stm32mp-exti.c
@@ -22,7 +22,7 @@
22 22
23 23 #define IRQS_PER_BANK 32
24 24
25 - #define HWSPNLCK_TIMEOUT 1000 /* usec */
25 + #define HWSPNLCK_TIMEOUT_MS 1
26 26
27 27 #define EXTI_EnCIDCFGR(n) (0x180 + (n) * 4)
28 28 #define EXTI_HWCFGR1 0x3f0
@@ -376,7 +376,7 @@ static int stm32mp_exti_set_type(struct irq_data *d, unsigned int type)
376 376 raw_spin_lock(&chip_data->rlock);
377 377
378 378 if (hwlock) {
379 - err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT);
379 + err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT_MS);
380 380 if (err) {
381 381 pr_err("%s can't get hwspinlock (%d)\n", __func__, err);
382 382 goto unlock;
modified drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -783,7 +783,7 @@ static int mpxy_mbox_populate_channels(struct mpxy_mbox *mbox)
783 783 return dev_err_probe(mbox->dev, -ENODEV, "no MPXY channels available\n");
784 784
785 785 /* Allocate and fetch all channel IDs */
786 - channel_ids = kcalloc(mbox->channel_count, sizeof(*channel_ids), GFP_KERNEL);
786 + channel_ids = kzalloc_objs(*channel_ids, mbox->channel_count);
787 787 if (!channel_ids)
788 788 return -ENOMEM;
789 789 rc = mpxy_get_channel_ids(mbox->channel_count, channel_ids);
modified drivers/md/dm-cache-target.c
@@ -340,8 +340,6 @@ struct cache {
340 340 struct list_head invalidation_requests;
341 341
342 342 sector_t migration_threshold;
343 - wait_queue_head_t migration_wait;
344 - atomic_t nr_allocated_migrations;
345 343
346 344 /*
347 345 * The number of in flight migrations that are performing
@@ -397,7 +395,11 @@ struct cache {
397 395 bool loaded_mappings:1;
398 396 bool loaded_discards:1;
399 397
400 - struct rw_semaphore background_work_lock;
398 + /* background work management */
399 + bool background_work_allowed;
400 + unsigned background_work_nr;
401 + spinlock_t background_work_lock;
402 + wait_queue_head_t background_work_wait;
401 403
402 404 struct batcher committer;
403 405 struct work_struct commit_ws;
@@ -488,19 +490,13 @@ static struct dm_cache_migration *alloc_migration(struct cache *cache)
488 490 memset(mg, 0, sizeof(*mg));
489 491
490 492 mg->cache = cache;
491 - atomic_inc(&cache->nr_allocated_migrations);
492 493
493 494 return mg;
494 495 }
495 496
496 497 static void free_migration(struct dm_cache_migration *mg)
497 498 {
498 - struct cache *cache = mg->cache;
499 -
500 - if (atomic_dec_and_test(&cache->nr_allocated_migrations))
501 - wake_up(&cache->migration_wait);
502 -
503 - mempool_free(mg, &cache->migration_pool);
499 + mempool_free(mg, &mg->cache->migration_pool);
504 500 }
505 501
506 502 /*----------------------------------------------------------------*/
@@ -1030,34 +1026,39 @@ static void calc_discard_block_range(struct cache *cache, struct bio *bio,
1030 1026
1031 1027 static void prevent_background_work(struct cache *cache)
1032 1028 {
1033 - lockdep_off();
1034 - down_write(&cache->background_work_lock);
1035 - lockdep_on();
1029 + spin_lock_irq(&cache->background_work_lock);
1030 + cache->background_work_allowed = false;
1031 + wait_event_lock_irq(cache->background_work_wait,
1032 + cache->background_work_nr == 0,
1033 + cache->background_work_lock);
1034 + spin_unlock_irq(&cache->background_work_lock);
1036 1035 }
1037 1036
1038 1037 static void allow_background_work(struct cache *cache)
1039 1038 {
1040 - lockdep_off();
1041 - up_write(&cache->background_work_lock);
1042 - lockdep_on();
1039 + spin_lock_irq(&cache->background_work_lock);
1040 + cache->background_work_allowed = true;
1041 + spin_unlock_irq(&cache->background_work_lock);
1043 1042 }
1044 1043
1045 1044 static bool background_work_begin(struct cache *cache)
1046 1045 {
1047 1046 bool r;
1048 1047
1049 - lockdep_off();
1050 - r = down_read_trylock(&cache->background_work_lock);
1051 - lockdep_on();
1052 -
1048 + spin_lock_irq(&cache->background_work_lock);
1049 + r = cache->background_work_allowed;
1050 + if (r)
1051 + cache->background_work_nr++;
1052 + spin_unlock_irq(&cache->background_work_lock);
1053 1053 return r;
1054 1054 }
1055 1055
1056 1056 static void background_work_end(struct cache *cache)
1057 1057 {
1058 - lockdep_off();
1059 - up_read(&cache->background_work_lock);
1060 - lockdep_on();
1058 + spin_lock_irq(&cache->background_work_lock);
1059 + if (--cache->background_work_nr == 0)
1060 + wake_up(&cache->background_work_wait);
1061 + spin_unlock_irq(&cache->background_work_lock);
1061 1062 }
1062 1063
1063 1064 /*----------------------------------------------------------------*/
@@ -1462,6 +1463,9 @@ static void invalidate_complete(struct dm_cache_migration *mg, bool success)
1462 1463 struct bio_list bios;
1463 1464 struct cache *cache = mg->cache;
1464 1465
1466 + if (success)
1467 + atomic_inc(&cache->stats.demotion);
1468 +
1465 1469 bio_list_init(&bios);
1466 1470 if (mg->cell) {
1467 1471 if (dm_cell_unlock_v2(cache->prison, mg->cell, &bios))
@@ -1733,7 +1737,6 @@ static int map_bio(struct cache *cache, struct bio *bio, dm_oblock_t block,
1733 1737 if (passthrough_mode(cache)) {
1734 1738 if (bio_data_dir(bio) == WRITE) {
1735 1739 bio_drop_shared_lock(cache, bio);
1736 - atomic_inc(&cache->stats.demotion);
1737 1740 invalidate_start(cache, cblock, block, bio);
1738 1741 return DM_MAPIO_SUBMITTED;
1739 1742 } else
@@ -2507,9 +2510,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2507 2510
2508 2511 spin_lock_init(&cache->lock);
2509 2512 bio_list_init(&cache->deferred_bios);
2510 - atomic_set(&cache->nr_allocated_migrations, 0);
2511 2513 atomic_set(&cache->nr_io_migrations, 0);
2512 - init_waitqueue_head(&cache->migration_wait);
2513 2514
2514 2515 r = -ENOMEM;
2515 2516 atomic_set(&cache->nr_dirty, 0);
@@ -2592,8 +2593,10 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2592 2593 issue_op, cache, cache->wq);
2593 2594 dm_iot_init(&cache->tracker);
2594 2595
2595 - init_rwsem(&cache->background_work_lock);
2596 - prevent_background_work(cache);
2596 + init_waitqueue_head(&cache->background_work_wait);
2597 + spin_lock_init(&cache->background_work_lock);
2598 + cache->background_work_allowed = false;
2599 + cache->background_work_nr = 0;
2597 2600
2598 2601 *result = cache;
2599 2602 return 0;
modified drivers/md/dm-crypt.c
@@ -1745,7 +1745,6 @@ static void crypt_dec_pending(struct dm_crypt_io *io)
1745 1745 {
1746 1746 struct crypt_config *cc = io->cc;
1747 1747 struct bio *base_bio = io->base_bio;
1748 - blk_status_t error = io->error;
1749 1748
1750 1749 if (!atomic_dec_and_test(&io->io_pending))
1751 1750 return;
@@ -1767,7 +1766,7 @@ static void crypt_dec_pending(struct dm_crypt_io *io)
1767 1766 else
1768 1767 kfree(io->integrity_metadata);
1769 1768
1770 - base_bio->bi_status = error;
1769 + base_bio->bi_status = io->error;
1771 1770
1772 1771 bio_endio(base_bio);
1773 1772 }
modified drivers/md/dm-ebs-target.c
@@ -265,8 +265,7 @@ static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv)
265 265
266 266 r = -EINVAL;
267 267 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 ||
268 - tmp != (sector_t)tmp ||
269 - (sector_t)tmp >= ti->len) {
268 + tmp != (sector_t)tmp) {
270 269 ti->error = "Invalid device offset sector";
271 270 goto bad;
272 271 }
modified drivers/md/dm-inlinecrypt.c
@@ -322,7 +322,7 @@ static int inlinecrypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
322 322 return -EINVAL;
323 323 }
324 324
325 - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
325 + ctx = kzalloc_obj(*ctx);
326 326 if (!ctx) {
327 327 ti->error = "Out of memory";
328 328 return -ENOMEM;
modified drivers/md/dm-integrity.c
@@ -1979,8 +1979,8 @@ static void integrity_metadata(struct work_struct *w)
1979 1979
1980 1980 if (unlikely(dio->op == REQ_OP_DISCARD)) {
1981 1981 unsigned int bi_size = dio->bio_details.bi_iter.bi_size;
1982 - unsigned int max_size = likely(checksums != checksums_onstack) ? PAGE_SIZE : HASH_MAX_DIGESTSIZE;
1983 - unsigned int max_blocks = max_size / ic->tag_size;
1982 + unsigned int max_size = likely(checksums != checksums_onstack) ? PAGE_SIZE : sizeof(checksums_onstack);
1983 + unsigned int max_blocks = (max_size - extra_space) / ic->tag_size;
1984 1984 sector_t sector = dio->range.logical_sector;
1985 1985
1986 1986 if (!ic->discard_keyed)
@@ -3875,6 +3875,10 @@ static void dm_integrity_resume(struct dm_target *ti)
3875 3875 r = sync_rw_sb(ic, REQ_OP_READ);
3876 3876 if (r)
3877 3877 dm_integrity_io_error(ic, "reading superblock", r);
3878 +
3879 + if (ic->mode == 'R')
3880 + goto skip_writes;
3881 +
3878 3882 if ((ic->sb->flags & flags) != flags) {
3879 3883 ic->sb->flags |= flags;
3880 3884 r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
@@ -3984,6 +3988,7 @@ static void dm_integrity_resume(struct dm_target *ti)
3984 3988 }
3985 3989 }
3986 3990
3991 + skip_writes:
3987 3992 ic->reboot_notifier.notifier_call = dm_integrity_reboot;
3988 3993 ic->reboot_notifier.next = NULL;
3989 3994 ic->reboot_notifier.priority = INT_MAX - 1; /* be notified after md and before hardware drivers */
@@ -4130,6 +4135,10 @@ static void dm_integrity_io_hints(struct dm_target *ti, struct queue_limits *lim
4130 4135 limits->dma_alignment = limits->logical_block_size - 1;
4131 4136 limits->discard_granularity = ic->sectors_per_block << SECTOR_SHIFT;
4132 4137
4138 + if (ic->internal_hash &&
4139 + (ic->mode == 'D' || ic->mode == 'B' || ic->mode == 'I'))
4140 + limits->features |= BLK_FEAT_STABLE_WRITES;
4141 +
4133 4142 if (!ic->internal_hash) {
4134 4143 struct blk_integrity *bi = &limits->integrity;
4135 4144
modified drivers/md/md-llbitmap.c
@@ -810,7 +810,7 @@ static int llbitmap_expand_pages(struct llbitmap *llbitmap,
810 810 if (nr_pages <= old_nr_pages)
811 811 return 0;
812 812
813 - pctl = kcalloc(nr_pages, sizeof(*pctl), GFP_NOIO);
813 + pctl = kzalloc_objs(*pctl, nr_pages, GFP_NOIO);
814 814 if (!pctl)
815 815 return -ENOMEM;
816 816
@@ -846,7 +846,7 @@ static int llbitmap_alloc_pages(struct llbitmap *llbitmap)
846 846 unsigned int nr_pages = max(used_pages, llbitmap_reserved_pages(llbitmap));
847 847 int i;
848 848
849 - llbitmap->pctl = kcalloc(nr_pages, sizeof(*llbitmap->pctl), GFP_NOIO);
849 + llbitmap->pctl = kzalloc_objs(*llbitmap->pctl, nr_pages, GFP_NOIO);
850 850 if (!llbitmap->pctl)
851 851 return -ENOMEM;
852 852
modified drivers/media/platform/allegro-dvt/allegro-core.c
@@ -3105,7 +3105,7 @@ static int allegro_open(struct file *file)
3105 3105 unsigned int cpb_size_max;
3106 3106 unsigned int cpb_size_def;
3107 3107
3108 - channel = kzalloc(sizeof(*channel), GFP_KERNEL);
3108 + channel = kzalloc_obj(*channel);
3109 3109 if (!channel)
3110 3110 return -ENOMEM;
3111 3111
modified drivers/media/platform/amd/isp4/isp4_interface.c
@@ -127,7 +127,7 @@ isp4if_gpu_mem_alloc(struct isp4_interface *ispif, u32 mem_size)
127 127 struct device *dev = ispif->dev;
128 128 int ret;
129 129
130 - mem_info = kmalloc_obj(*mem_info, GFP_KERNEL);
130 + mem_info = kmalloc_obj(*mem_info);
131 131 if (!mem_info)
132 132 return NULL;
133 133
@@ -368,7 +368,7 @@ static int isp4if_send_fw_cmd(struct isp4_interface *ispif, u32 cmd_id,
368 368
369 369 /* Allocate the sync command object early and outside of the lock */
370 370 if (sync) {
371 - ele = kmalloc_obj(*ele, GFP_KERNEL);
371 + ele = kmalloc_obj(*ele);
372 372 if (!ele)
373 373 return -ENOMEM;
374 374
@@ -738,7 +738,7 @@ isp4if_alloc_buffer_node(struct isp4if_img_buf_info *buf_info)
738 738 {
739 739 struct isp4if_img_buf_node *node;
740 740
741 - node = kmalloc_obj(*node, GFP_KERNEL);
741 + node = kmalloc_obj(*node);
742 742 if (node)
743 743 node->buf_info = *buf_info;
744 744
modified drivers/media/platform/renesas/rcar-isp/core.c
@@ -232,7 +232,7 @@ int risp_core_job_prepare(struct rcar_isp_core *core)
232 232 }
233 233
234 234 /* Memory is released when the job is consumed. */
235 - job = kzalloc(sizeof(*job), GFP_KERNEL);
235 + job = kzalloc_obj(*job);
236 236 if (!job)
237 237 return -ENOMEM;
238 238
modified drivers/media/rc/igorplugusb.c
@@ -164,7 +164,7 @@ static int igorplugusb_probe(struct usb_interface *intf,
164 164 if (!ir)
165 165 return -ENOMEM;
166 166
167 - ir->request = kzalloc_obj(*ir->request, GFP_KERNEL);
167 + ir->request = kzalloc_obj(*ir->request);
168 168 if (!ir->request)
169 169 goto fail;
170 170
modified drivers/mfd/mfd-core.c
@@ -135,7 +135,7 @@ static int mfd_match_of_node_to_dev(struct platform_device *pdev,
135 135 return -EAGAIN;
136 136
137 137 allocate_of_node:
138 - of_entry = kzalloc(sizeof(*of_entry), GFP_KERNEL);
138 + of_entry = kzalloc_obj(*of_entry);
139 139 if (!of_entry)
140 140 return -ENOMEM;
141 141
@@ -174,7 +174,7 @@ static int mfd_add_device(struct device *parent, int id,
174 174 if (!pdev->mfd_cell)
175 175 goto fail_device;
176 176
177 - res = kcalloc(cell->num_resources, sizeof(*res), GFP_KERNEL);
177 + res = kzalloc_objs(*res, cell->num_resources);
178 178 if (!res)
179 179 goto fail_device;
180 180
modified drivers/mfd/ucb1x00-assabet.c
@@ -96,7 +96,7 @@ static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
96 96
97 97 struct ucb1x00_assabet_priv *priv;
98 98
99 - priv = kzalloc_obj(*priv, GFP_KERNEL);
99 + priv = kzalloc_obj(*priv);
100 100 if (!priv)
101 101 return -ENOMEM;
102 102
modified drivers/misc/fastrpc.c
@@ -1822,24 +1822,20 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
1822 1822 return err;
1823 1823 }
1824 1824
1825 - bp.fd = dma_buf_fd(buf->dmabuf, O_ACCMODE);
1825 + bp.fd = get_unused_fd_flags(O_ACCMODE);
1826 1826 if (bp.fd < 0) {
1827 1827 dma_buf_put(buf->dmabuf);
1828 - return -EINVAL;
1828 + return bp.fd;
1829 1829 }
1830 1830
1831 1831 if (copy_to_user(argp, &bp, sizeof(bp))) {
1832 - /*
1833 - * The usercopy failed, but we can't do much about it, as
1834 - * dma_buf_fd() already called fd_install() and made the
1835 - * file descriptor accessible for the current process. It
1836 - * might already be closed and dmabuf no longer valid when
1837 - * we reach this point. Therefore "leak" the fd and rely on
1838 - * the process exit path to do any required cleanup.
1839 - */
1832 + put_unused_fd(bp.fd);
1833 + dma_buf_put(buf->dmabuf);
1840 1834 return -EFAULT;
1841 1835 }
1842 1836
1837 + dma_buf_fd_install(buf->dmabuf, bp.fd);
1838 +
1843 1839 return 0;
1844 1840 }
1845 1841
modified drivers/mtd/mtd_virt_concat.c
@@ -166,7 +166,7 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
166 166 return 0;
167 167 }
168 168
169 - item = kzalloc_flex(*item, nodes, count, GFP_KERNEL);
169 + item = kzalloc_flex(*item, nodes, count);
170 170 if (!item)
171 171 return -ENOMEM;
172 172
@@ -182,7 +182,7 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
182 182 for (i = 1; i < count; i++)
183 183 item->nodes[i] = of_parse_phandle(parts, CONCAT_PROP, (i - 1));
184 184
185 - concat = kzalloc_flex(*concat, subdev, count, GFP_KERNEL);
185 + concat = kzalloc_flex(*concat, subdev, count);
186 186 if (!concat) {
187 187 kfree(item);
188 188 return -ENOMEM;
modified drivers/mtd/mtdconcat.c
@@ -639,7 +639,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
639 639 printk(KERN_NOTICE "into device \"%s\"\n", name);
640 640
641 641 /* allocate the device structure */
642 - concat = kzalloc_flex(*concat, subdev, num_devs, GFP_KERNEL);
642 + concat = kzalloc_flex(*concat, subdev, num_devs);
643 643 if (!concat) {
644 644 printk
645 645 ("memory allocation error while creating concatenated device \"%s\"\n",
modified drivers/net/bonding/bond_alb.c
@@ -875,7 +875,7 @@ static int rlb_initialize(struct bonding *bond)
875 875 spin_unlock_bh(&bond->mode_lock);
876 876
877 877 /* register to receive ARPs */
878 - bond->recv_probe = rlb_arp_recv;
878 + WRITE_ONCE(bond->recv_probe, rlb_arp_recv);
879 879
880 880 return 0;
881 881 }
@@ -1281,10 +1281,10 @@ unwind:
1281 1281 }
1282 1282
1283 1283 /* determine if the packet is NA or NS */
1284 - static bool alb_determine_nd(struct sk_buff *skb, struct bonding *bond)
1284 + static bool alb_determine_nd(struct sk_buff *skb)
1285 1285 {
1286 - struct ipv6hdr *ip6hdr;
1287 - struct icmp6hdr *hdr;
1286 + const struct ipv6hdr *ip6hdr;
1287 + const struct icmp6hdr *hdr;
1288 1288
1289 1289 if (!pskb_network_may_pull(skb, sizeof(*ip6hdr)))
1290 1290 return true;
@@ -1296,7 +1296,8 @@ static bool alb_determine_nd(struct sk_buff *skb, struct bonding *bond)
1296 1296 if (!pskb_network_may_pull(skb, sizeof(*ip6hdr) + sizeof(*hdr)))
1297 1297 return true;
1298 1298
1299 - hdr = icmp6_hdr(skb);
1299 + ip6hdr = ipv6_hdr(skb);
1300 + hdr = (const struct icmp6hdr *)(ip6hdr + 1);
1300 1301 return hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
1301 1302 hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION;
1302 1303 }
@@ -1381,7 +1382,7 @@ struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1381 1382 if (!is_multicast_ether_addr(eth_data->h_dest)) {
1382 1383 switch (skb->protocol) {
1383 1384 case htons(ETH_P_IPV6):
1384 - if (alb_determine_nd(skb, bond))
1385 + if (alb_determine_nd(skb))
1385 1386 break;
1386 1387 fallthrough;
1387 1388 case htons(ETH_P_IP):
@@ -1467,7 +1468,7 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1467 1468 break;
1468 1469 }
1469 1470
1470 - if (alb_determine_nd(skb, bond)) {
1471 + if (alb_determine_nd(skb)) {
1471 1472 do_tx_balance = false;
1472 1473 break;
1473 1474 }
modified drivers/net/bonding/bond_main.c
@@ -1245,7 +1245,7 @@ static void bond_peer_notify_may_events(struct bonding *bond, bool force)
1245 1245 }
1246 1246
1247 1247 if (notified || force)
1248 - bond->send_peer_notif--;
1248 + WRITE_ONCE(bond->send_peer_notif, bond->send_peer_notif - 1);
1249 1249 }
1250 1250
1251 1251 /**
@@ -2284,7 +2284,7 @@ skip_mac_set:
2284 2284 }
2285 2285 }
2286 2286
2287 - bond->slave_cnt++;
2287 + WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
2288 2288 netdev_compute_master_upper_features(bond->dev, true);
2289 2289 bond_set_carrier(bond);
2290 2290
@@ -2517,9 +2517,7 @@ static int __bond_release_one(struct net_device *bond_dev,
2517 2517 bond_alb_deinit_slave(bond, slave);
2518 2518 }
2519 2519
2520 - if (all) {
2521 - RCU_INIT_POINTER(bond->curr_active_slave, NULL);
2522 - } else if (oldcurrent == slave) {
2520 + if (!all && oldcurrent == slave) {
2523 2521 /* Note that we hold RTNL over this sequence, so there
2524 2522 * is no concern that another slave add/remove event
2525 2523 * will interfere.
@@ -2533,7 +2531,7 @@ static int __bond_release_one(struct net_device *bond_dev,
2533 2531
2534 2532 unblock_netpoll_tx();
2535 2533 synchronize_rcu();
2536 - bond->slave_cnt--;
2534 + WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
2537 2535
2538 2536 if (!bond_has_slaves(bond)) {
2539 2537 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
@@ -4385,13 +4383,13 @@ static int bond_open(struct net_device *bond_dev)
4385 4383
4386 4384 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
4387 4385 queue_delayed_work(bond->wq, &bond->arp_work, 0);
4388 - bond->recv_probe = bond_rcv_validate;
4386 + WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
4389 4387 }
4390 4388
4391 4389 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
4392 4390 queue_delayed_work(bond->wq, &bond->ad_work, 0);
4393 4391 /* register to receive LACPDUs */
4394 - bond->recv_probe = bond_3ad_lacpdu_recv;
4392 + WRITE_ONCE(bond->recv_probe, bond_3ad_lacpdu_recv);
4395 4393 bond_3ad_initiate_agg_selection(bond, 1);
4396 4394
4397 4395 bond_for_each_slave(bond, slave, iter)
@@ -4413,7 +4411,7 @@ static int bond_close(struct net_device *bond_dev)
4413 4411 struct slave *slave;
4414 4412
4415 4413 bond_work_cancel_all(bond);
4416 - bond->send_peer_notif = 0;
4414 + WRITE_ONCE(bond->send_peer_notif, 0);
4417 4415 WRITE_ONCE(bond->recv_probe, NULL);
4418 4416
4419 4417 /* Wait for any in-flight RX handlers */
@@ -5118,7 +5116,7 @@ static void bond_skip_slave(struct bond_up_slave *slaves,
5118 5116 if (skipslave == slaves->arr[idx]) {
5119 5117 slaves->arr[idx] =
5120 5118 slaves->arr[slaves->count - 1];
5121 - slaves->count--;
5119 + WRITE_ONCE(slaves->count, slaves->count - 1);
5122 5120 break;
5123 5121 }
5124 5122 }
modified drivers/net/bonding/bond_options.c
@@ -1147,11 +1147,11 @@ static int bond_option_arp_interval_set(struct bonding *bond,
1147 1147 */
1148 1148 if (!newval->value) {
1149 1149 if (bond->params.arp_validate)
1150 - bond->recv_probe = NULL;
1150 + WRITE_ONCE(bond->recv_probe, NULL);
1151 1151 cancel_delayed_work_sync(&bond->arp_work);
1152 1152 } else {
1153 1153 /* arp_validate can be set only in active-backup mode */
1154 - bond->recv_probe = bond_rcv_validate;
1154 + WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
1155 1155 cancel_delayed_work_sync(&bond->mii_work);
1156 1156 queue_delayed_work(bond->wq, &bond->arp_work, 0);
1157 1157 }
modified drivers/net/dsa/mv88e6xxx/tcflower.c
@@ -97,7 +97,7 @@ int mv88e6xxx_cls_flower_add(struct dsa_switch *ds, int port,
97 97 goto err_unlock;
98 98 }
99 99
100 - entry = kzalloc(sizeof(*entry), GFP_KERNEL);
100 + entry = kzalloc_obj(*entry);
101 101 if (!entry) {
102 102 err = -ENOMEM;
103 103 goto err_unlock;
modified drivers/net/ethernet/airoha/airoha_eth.h
@@ -538,7 +538,7 @@ struct airoha_wdma_info {
538 538
539 539 /* RX queue to IRQ mapping: BIT(q) in IRQ(n) */
540 540 #define RX_IRQ0_BANK_PIN_MASK 0x839f
541 - #define RX_IRQ1_BANK_PIN_MASK 0x7fe00000
541 + #define RX_IRQ1_BANK_PIN_MASK 0xffe00000
542 542 #define RX_IRQ2_BANK_PIN_MASK 0x20
543 543 #define RX_IRQ3_BANK_PIN_MASK 0x40
544 544 #define RX_IRQ_BANK_PIN_MASK(_n) \
modified drivers/net/ethernet/alibaba/eea/eea_adminq.c
@@ -439,8 +439,7 @@ int eea_adminq_dev_status(struct eea_net *enet,
439 439 q_num = enet->cfg.rx_ring_num + enet->cfg.tx_ring_num + 1;
440 440 io_num = enet->cfg.rx_ring_num + enet->cfg.tx_ring_num;
441 441
442 - req = kcalloc(q_num, sizeof(struct eea_aq_queue_drv_status),
443 - GFP_KERNEL);
442 + req = kzalloc_objs(struct eea_aq_queue_drv_status, q_num);
444 443 if (!req)
445 444 return -ENOMEM;
446 445
@@ -486,11 +485,11 @@ void eea_adminq_config_host_info(struct eea_net *enet)
486 485 struct eea_aq_host_info_rep *rep;
487 486 int rc = -ENOMEM;
488 487
489 - cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
488 + cfg = kzalloc_obj(*cfg);
490 489 if (!cfg)
491 490 return;
492 491
493 - rep = kzalloc(sizeof(*rep), GFP_KERNEL);
492 + rep = kzalloc_obj(*rep);
494 493 if (!rep)
495 494 goto err_free_cfg;
496 495
modified drivers/net/ethernet/alibaba/eea/eea_net.c
@@ -62,7 +62,7 @@ static int eea_alloc_irq_blks(struct eea_net *enet)
62 62
63 63 num = enet->edev->rx_num;
64 64
65 - irq_blks = kvcalloc(num, sizeof(*blk), GFP_KERNEL);
65 + irq_blks = kvzalloc_objs(*blk, num);
66 66 if (!irq_blks)
67 67 return -ENOMEM;
68 68
@@ -194,11 +194,11 @@ static int eea_alloc_rxtx_q_mem(struct eea_net_init_ctx *ctx)
194 194 struct eea_net_tx *tx;
195 195 int err, i;
196 196
197 - ctx->tx = kvcalloc(ctx->cfg.tx_ring_num, sizeof(*ctx->tx), GFP_KERNEL);
197 + ctx->tx = kvzalloc_objs(*ctx->tx, ctx->cfg.tx_ring_num);
198 198 if (!ctx->tx)
199 199 return -ENOMEM;
200 200
201 - ctx->rx = kvcalloc(ctx->cfg.rx_ring_num, sizeof(*ctx->rx), GFP_KERNEL);
201 + ctx->rx = kvzalloc_objs(*ctx->rx, ctx->cfg.rx_ring_num);
202 202 if (!ctx->rx)
203 203 goto err_free_tx;
204 204
@@ -601,7 +601,7 @@ static int eea_netdev_init_features(struct net_device *netdev,
601 601 int err;
602 602 u32 mtu;
603 603
604 - cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
604 + cfg = kzalloc_obj(*cfg);
605 605 if (!cfg)
606 606 return -ENOMEM;
607 607
modified drivers/net/ethernet/alibaba/eea/eea_pci.c
@@ -651,7 +651,7 @@ static int eea_pci_probe(struct pci_dev *pci_dev,
651 651 struct eea_device *edev;
652 652 int err;
653 653
654 - ep_dev = kzalloc(sizeof(*ep_dev), GFP_KERNEL);
654 + ep_dev = kzalloc_obj(*ep_dev);
655 655 if (!ep_dev)
656 656 return -ENOMEM;
657 657
modified drivers/net/ethernet/alibaba/eea/eea_ring.c
@@ -217,7 +217,7 @@ struct eea_ring *eea_ering_alloc(u32 index, u32 num, struct eea_device *edev,
217 217 if (!cq_desc_size || !is_power_of_2(cq_desc_size))
218 218 return NULL;
219 219
220 - ering = kzalloc(sizeof(*ering), GFP_KERNEL);
220 + ering = kzalloc_obj(*ering);
221 221 if (!ering)
222 222 return NULL;
223 223
modified drivers/net/ethernet/alibaba/eea/eea_rx.c
@@ -764,7 +764,7 @@ struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx)
764 764 struct eea_net_rx *rx;
765 765 int err;
766 766
767 - rx = kzalloc(sizeof(*rx), GFP_KERNEL);
767 + rx = kzalloc_obj(*rx);
768 768 if (!rx)
769 769 return rx;
770 770
@@ -786,8 +786,7 @@ struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx)
786 786 rx->dma_dev = ctx->edev->dma_dev;
787 787
788 788 /* meta */
789 - rx->meta = kvcalloc(ctx->cfg.rx_ring_depth,
790 - sizeof(*rx->meta), GFP_KERNEL);
789 + rx->meta = kvzalloc_objs(*rx->meta, ctx->cfg.rx_ring_depth);
791 790 if (!rx->meta)
792 791 goto err_free_rx;
793 792
modified drivers/net/ethernet/alibaba/eea/eea_tx.c
@@ -480,8 +480,7 @@ int eea_alloc_tx(struct eea_net_init_ctx *ctx, struct eea_net_tx *tx, u32 idx)
480 480 tx->dma_dev = ctx->edev->dma_dev;
481 481
482 482 /* meta */
483 - tx->meta = kvcalloc(ctx->cfg.tx_ring_depth,
484 - sizeof(*tx->meta), GFP_KERNEL);
483 + tx->meta = kvzalloc_objs(*tx->meta, ctx->cfg.tx_ring_depth);
485 484 if (!tx->meta)
486 485 goto err_free_tx;
487 486
modified drivers/net/ethernet/amd/pds_core/core.c
@@ -810,8 +810,7 @@ void pdsc_host_mem_add(struct pdsc *pdsc)
810 810 if (count == 0)
811 811 return;
812 812
813 - pdsc->host_mem_reqs = kzalloc_objs(*pdsc->host_mem_reqs, count,
814 - GFP_KERNEL);
813 + pdsc->host_mem_reqs = kzalloc_objs(*pdsc->host_mem_reqs, count);
815 814 if (!pdsc->host_mem_reqs) {
816 815 dev_err(pdsc->dev, "failed to alloc host_mem_reqs array\n");
817 816 return;
modified drivers/net/ethernet/amd/pds_core/fw.c
@@ -382,7 +382,7 @@ static int pdsc_send_package_data(struct pldmfw *context, const u8 *data,
382 382 if (!length)
383 383 return 0;
384 384
385 - deferred = kmalloc_obj(*deferred, GFP_KERNEL);
385 + deferred = kmalloc_obj(*deferred);
386 386 if (!deferred)
387 387 return -ENOMEM;
388 388
@@ -505,7 +505,7 @@ static int pdsc_send_component_table(struct pldmfw *context,
505 505 component->version_string, component->index,
506 506 component->component_size, transfer_flag);
507 507
508 - component_priv = kzalloc_obj(*component_priv, GFP_KERNEL);
508 + component_priv = kzalloc_obj(*component_priv);
509 509 if (!component_priv)
510 510 return -ENOMEM;
511 511
@@ -710,7 +710,7 @@ static int pdsc_flash_component_chunk(struct pdsc *pdsc, struct device *dev,
710 710 u8 *component_data;
711 711 int err;
712 712
713 - deferred = kmalloc_obj(*deferred, GFP_KERNEL);
713 + deferred = kmalloc_obj(*deferred);
714 714 if (!deferred)
715 715 return -ENOMEM;
716 716
modified drivers/net/ethernet/amd/xgbe/xgbe-dev.c
@@ -3400,7 +3400,7 @@ static void xgbe_enable_rx(struct xgbe_prv_data *pdata)
3400 3400 XGMAC_IOWRITE(pdata, MAC_RQC0R, reg_val);
3401 3401
3402 3402 /* Enable MAC Rx */
3403 - XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 1);
3403 + XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
3404 3404 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 1);
3405 3405 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 1);
3406 3406 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 1);
@@ -3411,7 +3411,6 @@ static void xgbe_disable_rx(struct xgbe_prv_data *pdata)
3411 3411 unsigned int i;
3412 3412
3413 3413 /* Disable MAC Rx */
3414 - XGMAC_IOWRITE_BITS(pdata, MAC_RCR, DCRCC, 0);
3415 3414 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, CST, 0);
3416 3415 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, ACS, 0);
3417 3416 XGMAC_IOWRITE_BITS(pdata, MAC_RCR, RE, 0);
modified drivers/net/ethernet/cadence/macb.h
@@ -968,6 +968,8 @@ struct macb_dma_desc_ptp {
968 968 * of the frame
969 969 * @mapping: DMA address of the skb's fragment buffer
970 970 * @size: size of the DMA mapped buffer
971 + * @fcs_len: FCS bytes appended in software, 0 or ETH_FCS_LEN, only
972 + * set for the last buffer of the frame
971 973 * @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(),
972 974 * false when buffer was mapped with dma_map_single()
973 975 */
@@ -975,6 +977,7 @@ struct macb_tx_skb {
975 977 struct sk_buff *skb;
976 978 dma_addr_t mapping;
977 979 size_t size;
980 + u8 fcs_len;
978 981 bool mapped_as_page;
979 982 };
980 983
modified drivers/net/ethernet/cadence/macb_main.c
@@ -1322,8 +1322,8 @@ static void macb_tx_error_task(struct work_struct *work)
1322 1322 bp->netdev->stats.tx_packets++;
1323 1323 queue->stats.tx_packets++;
1324 1324 packets++;
1325 - bp->netdev->stats.tx_bytes += skb->len;
1326 - queue->stats.tx_bytes += skb->len;
1325 + bp->netdev->stats.tx_bytes += skb->len - tx_skb->fcs_len;
1326 + queue->stats.tx_bytes += skb->len - tx_skb->fcs_len;
1327 1327 bytes += skb->len;
1328 1328 }
1329 1329 } else {
@@ -1450,8 +1450,8 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
1450 1450 skb->data);
1451 1451 bp->netdev->stats.tx_packets++;
1452 1452 queue->stats.tx_packets++;
1453 - bp->netdev->stats.tx_bytes += skb->len;
1454 - queue->stats.tx_bytes += skb->len;
1453 + bp->netdev->stats.tx_bytes += skb->len - tx_skb->fcs_len;
1454 + queue->stats.tx_bytes += skb->len - tx_skb->fcs_len;
1455 1455 packets++;
1456 1456 bytes += skb->len;
1457 1457 }
@@ -2199,7 +2199,8 @@ static void macb_poll_controller(struct net_device *netdev)
2199 2199 static unsigned int macb_tx_map(struct macb *bp,
2200 2200 struct macb_queue *queue,
2201 2201 struct sk_buff *skb,
2202 - unsigned int hdrlen)
2202 + unsigned int hdrlen,
2203 + u8 fcs_len)
2203 2204 {
2204 2205 unsigned int f, nr_frags = skb_shinfo(skb)->nr_frags;
2205 2206 unsigned int len, i, tx_head = queue->tx_head;
@@ -2284,6 +2285,7 @@ static unsigned int macb_tx_map(struct macb *bp,
2284 2285
2285 2286 /* This is the last buffer of the frame: save socket buffer */
2286 2287 tx_skb->skb = skb;
2288 + tx_skb->fcs_len = fcs_len;
2287 2289
2288 2290 /* Update TX ring: update buffer descriptors in reverse order
2289 2291 * to avoid race condition
@@ -2417,6 +2419,7 @@ static inline int macb_clear_csum(struct sk_buff *skb)
2417 2419 return 0;
2418 2420 }
2419 2421
2422 + /* Returns a negative errno, or the FCS bytes appended (0 or ETH_FCS_LEN). */
2420 2423 static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *netdev)
2421 2424 {
2422 2425 bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb) ||
@@ -2465,7 +2468,7 @@ add_fcs:
2465 2468 skb_put_u8(*skb, (fcs >> 16) & 0xff);
2466 2469 skb_put_u8(*skb, (fcs >> 24) & 0xff);
2467 2470
2468 - return 0;
2471 + return ETH_FCS_LEN;
2469 2472 }
2470 2473
2471 2474 static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
@@ -2478,6 +2481,7 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2478 2481 netdev_tx_t ret = NETDEV_TX_OK;
2479 2482 unsigned int hdrlen;
2480 2483 unsigned long flags;
2484 + int fcs_len;
2481 2485 bool is_lso;
2482 2486
2483 2487 if (macb_clear_csum(skb)) {
@@ -2485,7 +2489,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2485 2489 return ret;
2486 2490 }
2487 2491
2488 - if (macb_pad_and_fcs(&skb, netdev)) {
2492 + fcs_len = macb_pad_and_fcs(&skb, netdev);
2493 + if (fcs_len < 0) {
2489 2494 dev_kfree_skb_any(skb);
2490 2495 return ret;
2491 2496 }
@@ -2548,7 +2553,7 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2548 2553 }
2549 2554
2550 2555 /* Map socket buffer for DMA transfer */
2551 - if (macb_tx_map(bp, queue, skb, hdrlen)) {
2556 + if (macb_tx_map(bp, queue, skb, hdrlen, fcs_len)) {
2552 2557 dev_kfree_skb_any(skb);
2553 2558 goto unlock;
2554 2559 }
@@ -4329,7 +4334,7 @@ static int macb_taprio_setup_replace(struct net_device *netdev,
4329 4334 return -EINVAL;
4330 4335 }
4331 4336
4332 - enst_queue = kcalloc(conf->num_entries, sizeof(*enst_queue), GFP_KERNEL);
4337 + enst_queue = kzalloc_objs(*enst_queue, conf->num_entries);
4333 4338 if (unlikely(!enst_queue))
4334 4339 return -ENOMEM;
4335 4340
modified drivers/net/ethernet/cisco/enic/enic_admin.c
@@ -137,7 +137,7 @@ static void enic_admin_msg_enqueue(struct enic *enic, void *buf,
137 137 {
138 138 struct enic_admin_msg *msg;
139 139
140 - msg = kmalloc(struct_size(msg, data, len), GFP_KERNEL);
140 + msg = kmalloc_flex(*msg, data, len);
141 141 if (!msg)
142 142 return;
143 143
modified drivers/net/ethernet/cisco/enic/enic_main.c
@@ -2858,7 +2858,7 @@ enic_sriov_v2_enable(struct enic *enic, int num_vfs)
2858 2858 return -EOPNOTSUPP;
2859 2859 }
2860 2860
2861 - enic->vf_state = kcalloc(num_vfs, sizeof(*enic->vf_state), GFP_KERNEL);
2861 + enic->vf_state = kzalloc_objs(*enic->vf_state, num_vfs);
2862 2862 if (!enic->vf_state)
2863 2863 return -ENOMEM;
2864 2864
@@ -2946,7 +2946,7 @@ enic_sriov_configure(struct pci_dev *pdev, int num_vfs)
2946 2946 if (enic->vf_type == ENIC_VF_TYPE_V2)
2947 2947 return enic_sriov_v2_enable(enic, num_vfs);
2948 2948
2949 - pp = kcalloc(num_vfs, sizeof(*pp), GFP_KERNEL);
2949 + pp = kzalloc_objs(*pp, num_vfs);
2950 2950 if (!pp)
2951 2951 return -ENOMEM;
2952 2952
@@ -2971,7 +2971,7 @@ enic_sriov_configure(struct pci_dev *pdev, int num_vfs)
2971 2971 return 0;
2972 2972 }
2973 2973
2974 - pp = kzalloc_obj(*enic->pp, GFP_KERNEL);
2974 + pp = kzalloc_obj(*enic->pp);
2975 2975 if (!pp)
2976 2976 return -ENOMEM;
2977 2977
modified drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
@@ -616,7 +616,7 @@ static int dpaa2_switch_lag_fdb_add(struct dpaa2_switch_lag *lag,
616 616 goto out;
617 617 }
618 618
619 - a = kzalloc(sizeof(*a), GFP_KERNEL);
619 + a = kzalloc_obj(*a);
620 620 if (!a) {
621 621 err = -ENOMEM;
622 622 goto out;
@@ -4131,8 +4131,7 @@ static int dpaa2_switch_probe(struct fsl_mc_device *sw_dev)
4131 4131 goto err_free_fdbs;
4132 4132 }
4133 4133
4134 - ethsw->lags = kcalloc(ethsw->sw_attr.num_ifs, sizeof(*ethsw->lags),
4135 - GFP_KERNEL);
4134 + ethsw->lags = kzalloc_objs(*ethsw->lags, ethsw->sw_attr.num_ifs);
4136 4135 if (!ethsw->lags) {
4137 4136 err = -ENOMEM;
4138 4137 goto err_free_filter;
modified drivers/net/ethernet/intel/libie/controlq.c
@@ -157,8 +157,7 @@ static void libie_ctlq_free_tx_msgs(struct libie_ctlq_info *ctlq,
157 157 */
158 158 static int libie_ctlq_alloc_tx_msgs(struct libie_ctlq_info *ctlq)
159 159 {
160 - ctlq->tx_msg = kvzalloc_objs(*ctlq->tx_msg, ctlq->ring_len,
161 - GFP_KERNEL);
160 + ctlq->tx_msg = kvzalloc_objs(*ctlq->tx_msg, ctlq->ring_len);
162 161 if (!ctlq->tx_msg)
163 162 return -ENOMEM;
164 163
modified drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c
@@ -3647,7 +3647,7 @@ static int npc_defrag_add_2_show_list(struct rvu *rvu, u16 old_midx,
3647 3647 {
3648 3648 struct npc_defrag_show_node *node;
3649 3649
3650 - node = kcalloc(1, sizeof(*node), GFP_KERNEL);
3650 + node = kzalloc_objs(*node, 1);
3651 3651 if (!node)
3652 3652 return -ENOMEM;
3653 3653
@@ -4082,7 +4082,7 @@ int npc_cn20k_defrag(struct rvu *rvu)
4082 4082 INIT_LIST_HEAD(&x4lh);
4083 4083 INIT_LIST_HEAD(&x2lh);
4084 4084
4085 - node = kcalloc(npc_priv->num_subbanks, sizeof(*node), GFP_KERNEL);
4085 + node = kzalloc_objs(*node, npc_priv->num_subbanks);
4086 4086 if (!node)
4087 4087 return -ENOMEM;
4088 4088
@@ -4711,7 +4711,7 @@ static int npc_priv_init(struct rvu *rvu)
4711 4711 return -EINVAL;
4712 4712 }
4713 4713
4714 - npc_priv = kcalloc(1, sizeof(*npc_priv), GFP_KERNEL);
4714 + npc_priv = kzalloc_objs(*npc_priv, 1);
4715 4715 if (!npc_priv)
4716 4716 return -ENOMEM;
4717 4717
@@ -4729,8 +4729,7 @@ static int npc_priv_init(struct rvu *rvu)
4729 4729 num_banks, bank_depth, num_subbanks, subbank_depth,
4730 4730 npc_kw_name[npc_priv->kw]);
4731 4731
4732 - npc_priv->sb = kcalloc(num_subbanks, sizeof(struct npc_subbank),
4733 - GFP_KERNEL);
4732 + npc_priv->sb = kzalloc_objs(struct npc_subbank, num_subbanks);
4734 4733 if (!npc_priv->sb)
4735 4734 goto fail1;
4736 4735
@@ -4757,9 +4756,7 @@ static int npc_priv_init(struct rvu *rvu)
4757 4756
4758 4757 /* Get number of pcifuncs in the system */
4759 4758 npc_priv->pf_cnt = npc_pcifunc_map_create(rvu);
4760 - npc_priv->xa_pf2idx_map = kcalloc(npc_priv->pf_cnt,
4761 - sizeof(struct xarray),
4762 - GFP_KERNEL);
4759 + npc_priv->xa_pf2idx_map = kzalloc_objs(struct xarray, npc_priv->pf_cnt);
4763 4760 if (!npc_priv->xa_pf2idx_map) {
4764 4761 ret = -ENOMEM;
4765 4762 goto fail3;
modified drivers/net/ethernet/marvell/octeontx2/af/rvu.c
@@ -3468,6 +3468,8 @@ err:
3468 3468 return ret;
3469 3469 }
3470 3470
3471 + #define PCI_DEVID_OCTEONTX2_RVU_AFVF 0xA0F8
3472 +
3471 3473 static int rvu_enable_sriov(struct rvu *rvu)
3472 3474 {
3473 3475 struct pci_dev *pdev = rvu->pdev;
@@ -3486,24 +3488,27 @@ static int rvu_enable_sriov(struct rvu *rvu)
3486 3488 return 0;
3487 3489 pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &rvu->vf_devid);
3488 3490
3489 - chans = rvu_get_num_lbk_chans();
3490 - if (chans < 0)
3491 - return chans;
3492 -
3493 3491 vfs = pci_sriov_get_totalvfs(pdev);
3494 -
3495 - /* Limit VFs in case we have more VFs than LBK channels available. */
3496 - if (vfs > chans)
3497 - vfs = chans;
3498 -
3499 3492 if (!vfs)
3500 3493 return 0;
3501 3494
3502 - /* LBK channel number 63 is used for switching packets between
3503 - * CGX mapped VFs. Hence limit LBK pairs till 62 only.
3504 - */
3505 - if (vfs > 62)
3506 - vfs = 62;
3495 + if (rvu->vf_devid == PCI_DEVID_OCTEONTX2_RVU_AFVF) {
3496 + chans = rvu_get_num_lbk_chans();
3497 + if (chans < 0)
3498 + return chans;
3499 +
3500 + /* The last LBK channel is reserved for switching packets between
3501 + * CGX mapped VFs. Also, since LBK VFs work in pairs, limit VF
3502 + * count to available LBK channels minus 2.
3503 + */
3504 + vfs = min(vfs, chans - 2);
3505 +
3506 + if (vfs <= 0) {
3507 + dev_warn(&pdev->dev,
3508 + "Skipping SRIOV enablement, not enough LBK channels available\n");
3509 + return 0;
3510 + }
3511 + }
3507 3512
3508 3513 /* Save VFs number for reference in VF interrupts handlers.
3509 3514 * Since interrupts might start arriving during SRIOV enablement
modified drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -2957,10 +2957,9 @@ static void npc_mcam_free_all_entries(struct rvu *rvu, struct npc_mcam *mcam,
2957 2957 }
2958 2958 }
2959 2959
2960 - /* Disable the entry */
2961 - npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false);
2962 -
2963 2960 if (!cn20k_dft_rl) {
2961 + /* Disable the entry */
2962 + npc_enable_mcam_entry(rvu, mcam, blkaddr, index, false);
2964 2963 mcam->entry2pfvf_map[index] = NPC_MCAM_INVALID_MAP;
2965 2964 /* Free the entry in bitmap */
2966 2965 npc_mcam_clear_bit(mcam, index);
modified drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c
@@ -3,6 +3,7 @@
3 3
4 4 #include "rx.h"
5 5 #include "en/xdp.h"
6 + #include <linux/bitmap.h>
6 7 #include <net/xdp_sock_drv.h>
7 8 #include <linux/filter.h>
8 9
@@ -156,6 +157,7 @@ err_reuse_batch:
156 157 xsk_buff_free(xsk_buffs[batch]);
157 158
158 159 err:
160 + bitmap_fill(wi->skip_release_bitmap, rq->mpwqe.pages_per_wqe);
159 161 rq->stats->buff_alloc_err++;
160 162 return -ENOMEM;
161 163 }
modified drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -410,8 +410,11 @@ static inline void mlx5e_free_rx_wqe(struct mlx5e_rq *rq,
410 410
411 411 static void mlx5e_xsk_free_rx_wqe(struct mlx5e_wqe_frag_info *wi)
412 412 {
413 - if (!(wi->flags & BIT(MLX5E_WQE_FRAG_SKIP_RELEASE)))
414 - xsk_buff_free(*wi->xskp);
413 + if (wi->flags & BIT(MLX5E_WQE_FRAG_SKIP_RELEASE))
414 + return;
415 +
416 + xsk_buff_free(*wi->xskp);
417 + wi->flags |= BIT(MLX5E_WQE_FRAG_SKIP_RELEASE);
415 418 }
416 419
417 420 static void mlx5e_dealloc_rx_wqe(struct mlx5e_rq *rq, u16 ix)
modified drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -2288,8 +2288,7 @@ static int mlx5_esw_spfs_init(struct mlx5_eswitch *esw)
2288 2288 if (!num_entries)
2289 2289 goto out_free;
2290 2290
2291 - esw_funcs->spfs = kcalloc(num_entries, sizeof(*esw_funcs->spfs),
2292 - GFP_KERNEL);
2291 + esw_funcs->spfs = kzalloc_objs(*esw_funcs->spfs, num_entries);
2293 2292 if (!esw_funcs->spfs) {
2294 2293 err = -ENOMEM;
2295 2294 goto out_free;
modified drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -1524,7 +1524,7 @@ struct mlx5_flow_handle *
1524 1524 mlx5_esw_lag_demux_rule_create(struct mlx5_eswitch *esw, u16 vport_num,
1525 1525 struct mlx5_flow_table *lag_ft)
1526 1526 {
1527 - struct mlx5_flow_spec *spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
1527 + struct mlx5_flow_spec *spec = kvzalloc_obj(*spec);
1528 1528 struct mlx5_flow_destination dest = {};
1529 1529 struct mlx5_flow_act flow_act = {};
1530 1530 struct mlx5_flow_handle *ret;
modified drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -317,7 +317,7 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
317 317
318 318 num_spfs = mlx5_esw_get_num_spfs(dev);
319 319 num_hwc = MLX5_SF_HWC_FIRST_SPF + num_spfs;
320 - table->hwc = kcalloc(num_hwc, sizeof(*table->hwc), GFP_KERNEL);
320 + table->hwc = kzalloc_objs(*table->hwc, num_hwc);
321 321 if (!table->hwc) {
322 322 err = -ENOMEM;
323 323 goto hwc_alloc_err;
modified drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c
@@ -239,7 +239,7 @@ static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy)
239 239 if (!buddy->hw_ste_arr)
240 240 goto free_ste_arr;
241 241
242 - buddy->miss_list = kvmalloc_array(num_of_entries, sizeof(struct list_head), GFP_KERNEL);
242 + buddy->miss_list = kvmalloc_objs(struct list_head, num_of_entries);
243 243 if (!buddy->miss_list)
244 244 goto free_hw_ste_arr;
245 245
modified drivers/net/ethernet/meta/fbnic/fbnic_irq.c
@@ -282,7 +282,7 @@ enum fbnic_msix_self_test_codes fbnic_msix_test(struct fbnic_dev *fbd)
282 282 int i;
283 283
284 284 /* Allocate bitmap and IRQ vector table */
285 - test_data = kzalloc_obj(*test_data, GFP_KERNEL);
285 + test_data = kzalloc_obj(*test_data);
286 286
287 287 /* memory allocation failure */
288 288 if (!test_data)
modified drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -429,11 +429,11 @@ int mana_gd_alloc_memory(struct gdma_context *gc, unsigned int length,
429 429 /* length is a power of 2 above PAGE_SIZE, so this divides exactly. */
430 430 npages = length / PAGE_SIZE;
431 431
432 - gmi->pages_va = kvcalloc(npages, sizeof(*gmi->pages_va), GFP_KERNEL);
432 + gmi->pages_va = kvzalloc_objs(*gmi->pages_va, npages);
433 433 if (!gmi->pages_va)
434 434 return -ENOMEM;
435 435
436 - gmi->pages_dma = kvcalloc(npages, sizeof(*gmi->pages_dma), GFP_KERNEL);
436 + gmi->pages_dma = kvzalloc_objs(*gmi->pages_dma, npages);
437 437 if (!gmi->pages_dma)
438 438 goto free_va;
439 439
@@ -825,7 +825,7 @@ int mana_schedule_serv_work(struct gdma_context *gc, enum gdma_eqe_type type)
825 825 return -ENODEV;
826 826 }
827 827
828 - mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC);
828 + mns_wk = kzalloc_obj(*mns_wk, GFP_ATOMIC);
829 829 if (!mns_wk) {
830 830 module_put(THIS_MODULE);
831 831 clear_bit(GC_IN_SERVICE, &gc->flags);
@@ -1991,7 +1991,7 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
1991 1991 *msi_requested = msi;
1992 1992 }
1993 1993
1994 - gic = kzalloc(sizeof(*gic), GFP_KERNEL);
1994 + gic = kzalloc_obj(*gic);
1995 1995 if (!gic) {
1996 1996 gic = ERR_PTR(-ENOMEM);
1997 1997 if (irq_map.virq)
modified drivers/net/ethernet/oa_tc6.c
@@ -83,7 +83,7 @@ struct oa_tc6 {
83 83 u16 spi_data_tx_buf_offset;
84 84 u16 tx_credits;
85 85 u8 rx_chunks_available;
86 - bool rx_buf_overflow;
86 + bool wait_until_start_valid;
87 87 bool int_flag;
88 88 bool disable_traffic;
89 89 bool prot_ctrl;
@@ -455,7 +455,7 @@ static int oa_tc6_mdiobus_read(struct mii_bus *bus, int addr, int regnum)
455 455 {
456 456 struct oa_tc6 *tc6 = bus->priv;
457 457 u32 regval;
458 - bool ret;
458 + int ret;
459 459
460 460 ret = oa_tc6_read_register(tc6, OA_TC6_PHY_STD_REG_ADDR_BASE |
461 461 (regnum & OA_TC6_PHY_STD_REG_ADDR_MASK),
@@ -693,6 +693,26 @@ static int oa_tc6_enable_data_transfer(struct oa_tc6 *tc6)
693 693 return oa_tc6_write_register(tc6, OA_TC6_REG_CONFIG0, value);
694 694 }
695 695
696 + /* Called when a frame that is meant to be transmitted, is dropped. */
697 + static void oa_tc6_drop_tx_skb(struct oa_tc6 *tc6, struct sk_buff *skb)
698 + {
699 + if (skb) {
700 + tc6->netdev->stats.tx_dropped++;
701 + dev_kfree_skb_any(skb);
702 + }
703 + }
704 +
705 + static struct sk_buff *oa_tc6_detach_waiting_tx_skb(struct oa_tc6 *tc6)
706 + {
707 + struct sk_buff *skb;
708 +
709 + lockdep_assert_held(&tc6->tx_skb_lock);
710 + skb = tc6->waiting_tx_skb;
711 + tc6->waiting_tx_skb = NULL;
712 +
713 + return skb;
714 + }
715 +
696 716 static void oa_tc6_cleanup_ongoing_rx_skb(struct oa_tc6 *tc6)
697 717 {
698 718 if (tc6->rx_skb) {
@@ -704,29 +724,39 @@ static void oa_tc6_cleanup_ongoing_rx_skb(struct oa_tc6 *tc6)
704 724
705 725 static void oa_tc6_cleanup_ongoing_tx_skb(struct oa_tc6 *tc6)
706 726 {
707 - if (tc6->ongoing_tx_skb) {
708 - tc6->netdev->stats.tx_dropped++;
709 - kfree_skb(tc6->ongoing_tx_skb);
710 - tc6->ongoing_tx_skb = NULL;
711 - }
727 + oa_tc6_drop_tx_skb(tc6, tc6->ongoing_tx_skb);
728 + tc6->ongoing_tx_skb = NULL;
712 729 }
713 730
714 731 static void oa_tc6_cleanup_waiting_tx_skb(struct oa_tc6 *tc6)
715 732 {
716 - if (tc6->waiting_tx_skb) {
717 - tc6->netdev->stats.tx_dropped++;
718 - kfree_skb(tc6->waiting_tx_skb);
719 - tc6->waiting_tx_skb = NULL;
720 - }
733 + struct sk_buff *skb;
734 +
735 + spin_lock_bh(&tc6->tx_skb_lock);
736 + skb = oa_tc6_detach_waiting_tx_skb(tc6);
737 + spin_unlock_bh(&tc6->tx_skb_lock);
738 +
739 + oa_tc6_drop_tx_skb(tc6, skb);
721 740 }
722 741
723 - static void oa_tc6_free_pending_skbs(struct oa_tc6 *tc6)
742 + static void oa_tc6_free_ongoing_skbs(struct oa_tc6 *tc6)
724 743 {
725 744 oa_tc6_cleanup_ongoing_tx_skb(tc6);
726 745 oa_tc6_cleanup_ongoing_rx_skb(tc6);
746 + }
747 +
748 + static void oa_tc6_free_pending_skbs(struct oa_tc6 *tc6)
749 + {
750 + oa_tc6_free_ongoing_skbs(tc6);
727 751 oa_tc6_cleanup_waiting_tx_skb(tc6);
728 752 }
729 753
754 + static void oa_tc6_look_for_new_frame(struct oa_tc6 *tc6)
755 + {
756 + tc6->wait_until_start_valid = true;
757 + oa_tc6_cleanup_ongoing_rx_skb(tc6);
758 + }
759 +
730 760 /* If the failure is at SPI interface level, masking and clearing
731 761 * the interrupt of the device won't work. Since SPI interrupt is
732 762 * disabled, it should stop the repeated interrupts.
@@ -734,9 +764,19 @@ static void oa_tc6_free_pending_skbs(struct oa_tc6 *tc6)
734 764 static void oa_tc6_disable_traffic(struct oa_tc6 *tc6)
735 765 {
736 766 u32 regval = OA_TC6_INT_MASK0_ALL_INTERRUPTS;
767 + struct sk_buff *skb;
737 768
769 + spin_lock_bh(&tc6->tx_skb_lock);
738 770 tc6->disable_traffic = true;
739 - oa_tc6_free_pending_skbs(tc6);
771 + skb = oa_tc6_detach_waiting_tx_skb(tc6);
772 + spin_unlock_bh(&tc6->tx_skb_lock);
773 +
774 + /* disable_traffic, when set, is a point of no return to
775 + * working state. Keeping the TX queues disabled.
776 + */
777 + netif_tx_disable(tc6->netdev);
778 + oa_tc6_drop_tx_skb(tc6, skb);
779 + oa_tc6_free_ongoing_skbs(tc6);
740 780 oa_tc6_write_register(tc6, OA_TC6_REG_INT_MASK0, regval);
741 781 oa_tc6_read_register(tc6, OA_TC6_REG_STATUS0, &regval);
742 782 oa_tc6_write_register(tc6, OA_TC6_REG_STATUS0, regval);
@@ -755,6 +795,13 @@ static int oa_tc6_process_extended_status(struct oa_tc6 *tc6)
755 795 return ret;
756 796 }
757 797
798 + /* This function is called for each chunk received in a given SPI
799 + * transaction. In case, extended status bit is set in more than
800 + * one chunk, skip the write, if status0 is already cleared.
801 + */
802 + if (!value)
803 + return 0;
804 +
758 805 /* Clear the error interrupts status */
759 806 ret = oa_tc6_write_register(tc6, OA_TC6_REG_STATUS0, value);
760 807 if (ret) {
@@ -764,8 +811,7 @@ static int oa_tc6_process_extended_status(struct oa_tc6 *tc6)
764 811 }
765 812
766 813 if (FIELD_GET(OA_TC6_STATUS0_RX_BUFFER_OVERFLOW_ERROR, value)) {
767 - tc6->rx_buf_overflow = true;
768 - oa_tc6_cleanup_ongoing_rx_skb(tc6);
814 + oa_tc6_look_for_new_frame(tc6);
769 815 net_err_ratelimited("%s: Receive buffer overflow error\n",
770 816 tc6->netdev->name);
771 817 return -EAGAIN;
@@ -791,6 +837,8 @@ static int oa_tc6_process_extended_status(struct oa_tc6 *tc6)
791 837
792 838 static int oa_tc6_process_rx_chunk_footer(struct oa_tc6 *tc6, u32 footer)
793 839 {
840 + int ret = 0;
841 +
794 842 /* Process rx chunk footer for the following,
795 843 * 1. tx credits
796 844 * 2. errors if any from MAC-PHY
@@ -801,9 +849,11 @@ static int oa_tc6_process_rx_chunk_footer(struct oa_tc6 *tc6, u32 footer)
801 849 footer);
802 850
803 851 if (FIELD_GET(OA_TC6_DATA_FOOTER_EXTENDED_STS, footer)) {
804 - int ret = oa_tc6_process_extended_status(tc6);
805 -
806 - if (ret)
852 + ret = oa_tc6_process_extended_status(tc6);
853 + /* EAGAIN error is recoverable. Move on to check
854 + * HEADER and SYNC errors before returning.
855 + */
856 + if (ret && ret != -EAGAIN)
807 857 return ret;
808 858 }
809 859
@@ -821,7 +871,7 @@ static int oa_tc6_process_rx_chunk_footer(struct oa_tc6 *tc6, u32 footer)
821 871 return -ENODEV;
822 872 }
823 873
824 - return 0;
874 + return ret;
825 875 }
826 876
827 877 static void oa_tc6_submit_rx_skb(struct oa_tc6 *tc6)
@@ -846,13 +896,35 @@ static void oa_tc6_submit_rx_skb(struct oa_tc6 *tc6)
846 896 tc6->rx_skb = NULL;
847 897 }
848 898
849 - static void oa_tc6_update_rx_skb(struct oa_tc6 *tc6, u8 *payload, u8 length)
899 + /* On oversubscribed traffic condition, particularly with overwhelming rx
900 + * buffer overflow errors, there could be data chunk loss. If tail + length
901 + * goes beyond end pointer, that is an indication that the data chunk with
902 + * end_valid bit is lost. Time to look for a data chunk with start_valid bit.
903 + *
904 + * If rx_skb is NULL, it is time to start looking for data chunk with
905 + * start_bit.
906 + */
907 + static int oa_tc6_update_rx_skb(struct oa_tc6 *tc6, u8 *payload, u8 length)
850 908 {
909 + if (!tc6->rx_skb ||
910 + skb_tailroom(tc6->rx_skb) < length) {
911 + oa_tc6_look_for_new_frame(tc6);
912 + return -EAGAIN;
913 + }
914 +
851 915 memcpy(skb_put(tc6->rx_skb, length), payload, length);
916 + return 0;
852 917 }
853 918
919 + /* On overwhelming rx buffer overflow errors, due to data chunk loss, it is
920 + * possible that we get two data chunks with start_valid bit set, without
921 + * end_valid bit set in between. In this case, rx_skb would have a valid
922 + * buffer pointer. We should release, if a valid pointer is found before
923 + * allocating a new one.
924 + */
854 925 static int oa_tc6_allocate_rx_skb(struct oa_tc6 *tc6)
855 926 {
927 + oa_tc6_cleanup_ongoing_rx_skb(tc6);
856 928 tc6->rx_skb = netdev_alloc_skb_ip_align(tc6->netdev, tc6->netdev->mtu +
857 929 ETH_HLEN + ETH_FCS_LEN);
858 930 if (!tc6->rx_skb) {
@@ -872,7 +944,9 @@ static int oa_tc6_prcs_complete_rx_frame(struct oa_tc6 *tc6, u8 *payload,
872 944 if (ret)
873 945 return ret;
874 946
875 - oa_tc6_update_rx_skb(tc6, payload, size);
947 + ret = oa_tc6_update_rx_skb(tc6, payload, size);
948 + if (ret)
949 + return ret;
876 950
877 951 oa_tc6_submit_rx_skb(tc6);
878 952
@@ -887,22 +961,24 @@ static int oa_tc6_prcs_rx_frame_start(struct oa_tc6 *tc6, u8 *payload, u16 size)
887 961 if (ret)
888 962 return ret;
889 963
890 - oa_tc6_update_rx_skb(tc6, payload, size);
891 -
892 - return 0;
964 + return oa_tc6_update_rx_skb(tc6, payload, size);
893 965 }
894 966
895 - static void oa_tc6_prcs_rx_frame_end(struct oa_tc6 *tc6, u8 *payload, u16 size)
967 + static int oa_tc6_prcs_rx_frame_end(struct oa_tc6 *tc6, u8 *payload, u16 size)
896 968 {
897 - oa_tc6_update_rx_skb(tc6, payload, size);
969 + int ret;
898 970
899 - oa_tc6_submit_rx_skb(tc6);
971 + ret = oa_tc6_update_rx_skb(tc6, payload, size);
972 + if (!ret)
973 + oa_tc6_submit_rx_skb(tc6);
974 + return ret;
900 975 }
901 976
902 - static void oa_tc6_prcs_ongoing_rx_frame(struct oa_tc6 *tc6, u8 *payload,
903 - u32 footer)
977 + static int oa_tc6_prcs_ongoing_rx_frame(struct oa_tc6 *tc6, u8 *payload,
978 + u32 footer)
904 979 {
905 - oa_tc6_update_rx_skb(tc6, payload, OA_TC6_CHUNK_PAYLOAD_SIZE);
980 + return oa_tc6_update_rx_skb(tc6, payload,
981 + OA_TC6_CHUNK_PAYLOAD_SIZE);
906 982 }
907 983
908 984 static int oa_tc6_prcs_rx_chunk_payload(struct oa_tc6 *tc6, u8 *data,
@@ -917,10 +993,10 @@ static int oa_tc6_prcs_rx_chunk_payload(struct oa_tc6 *tc6, u8 *data,
917 993 u16 size;
918 994
919 995 /* Restart the new rx frame after receiving rx buffer overflow error */
920 - if (start_valid && tc6->rx_buf_overflow)
921 - tc6->rx_buf_overflow = false;
996 + if (start_valid && tc6->wait_until_start_valid)
997 + tc6->wait_until_start_valid = false;
922 998
923 - if (tc6->rx_buf_overflow)
999 + if (tc6->wait_until_start_valid)
924 1000 return 0;
925 1001
926 1002 /* Process the chunk with complete rx frame */
@@ -942,8 +1018,7 @@ static int oa_tc6_prcs_rx_chunk_payload(struct oa_tc6 *tc6, u8 *data,
942 1018 /* Process the chunk with only rx frame end */
943 1019 if (end_valid && !start_valid) {
944 1020 size = end_byte_offset + 1;
945 - oa_tc6_prcs_rx_frame_end(tc6, data, size);
946 - return 0;
1021 + return oa_tc6_prcs_rx_frame_end(tc6, data, size);
947 1022 }
948 1023
949 1024 /* Process the chunk with previous rx frame end and next rx frame
@@ -957,6 +1032,15 @@ static int oa_tc6_prcs_rx_chunk_payload(struct oa_tc6 *tc6, u8 *data,
957 1032 if (tc6->rx_skb) {
958 1033 size = end_byte_offset + 1;
959 1034 oa_tc6_prcs_rx_frame_end(tc6, data, size);
1035 +
1036 + /* Return value from oa_tc6_prcs_rx_frame_end is not
1037 + * checked. If it returned an error, it is to make
1038 + * the code to look for new frame. At this stage,
1039 + * code below is going to process a new frame. So,
1040 + * error condition is set to false, in case it is
1041 + * set before proceeding.
1042 + */
1043 + tc6->wait_until_start_valid = false;
960 1044 }
961 1045 size = OA_TC6_CHUNK_PAYLOAD_SIZE - start_byte_offset;
962 1046 return oa_tc6_prcs_rx_frame_start(tc6,
@@ -965,9 +1049,7 @@ static int oa_tc6_prcs_rx_chunk_payload(struct oa_tc6 *tc6, u8 *data,
965 1049 }
966 1050
967 1051 /* Process the chunk with ongoing rx frame data */
968 - oa_tc6_prcs_ongoing_rx_frame(tc6, data, footer);
969 -
970 - return 0;
1052 + return oa_tc6_prcs_ongoing_rx_frame(tc6, data, footer);
971 1053 }
972 1054
973 1055 static u32 oa_tc6_get_rx_chunk_footer(struct oa_tc6 *tc6, u16 footer_offset)
@@ -983,8 +1065,9 @@ static u32 oa_tc6_get_rx_chunk_footer(struct oa_tc6 *tc6, u16 footer_offset)
983 1065 static int oa_tc6_process_spi_data_rx_buf(struct oa_tc6 *tc6, u16 length)
984 1066 {
985 1067 u16 no_of_rx_chunks = length / OA_TC6_CHUNK_SIZE;
1068 + bool retry = false;
1069 + int ret = 0;
986 1070 u32 footer;
987 - int ret;
988 1071
989 1072 /* All the rx chunks in the receive SPI data buffer are examined here */
990 1073 for (int i = 0; i < no_of_rx_chunks; i++) {
@@ -993,8 +1076,11 @@ static int oa_tc6_process_spi_data_rx_buf(struct oa_tc6 *tc6, u16 length)
993 1076 OA_TC6_CHUNK_PAYLOAD_SIZE);
994 1077
995 1078 ret = oa_tc6_process_rx_chunk_footer(tc6, footer);
996 - if (ret)
997 - return ret;
1079 + if (ret) {
1080 + if (ret != -EAGAIN)
1081 + return ret;
1082 + retry = true;
1083 + }
998 1084
999 1085 /* If there is a data valid chunks then process it for the
1000 1086 * information needed to determine the validity and the location
@@ -1006,12 +1092,35 @@ static int oa_tc6_process_spi_data_rx_buf(struct oa_tc6 *tc6, u16 length)
1006 1092
1007 1093 ret = oa_tc6_prcs_rx_chunk_payload(tc6, payload,
1008 1094 footer);
1009 - if (ret)
1010 - return ret;
1095 + if (ret) {
1096 + if (ret != -ENOMEM && ret != -EAGAIN)
1097 + return ret;
1098 + retry = true;
1099 + }
1011 1100 }
1012 1101 }
1013 1102
1014 - return 0;
1103 + /* Not bailing out on recoverable error codes, -EAGAIN and
1104 + * -ENOMEM. If subsequent loop iterations, if any, succeeds,
1105 + * error code would be overwritten. retry flag helps to
1106 + * make the caller to continue and retry. Since recovery
1107 + * action for -ENOMEM and -EAGAIN are same, we are returning
1108 + * one of the error codes, that is -EAGAIN.
1109 + *
1110 + * Successful recovery depends on how small the frames are,
1111 + * how many chunks, among the received chunks triggered the
1112 + * error, whether data is intact even with error conditions.
1113 + * As a result, there is no single, best method to recover
1114 + * most data when error conditions hit. We do our best by
1115 + * processing all the chunks with good "footer header" and
1116 + * "data valid" bit set.
1117 + */
1118 + if (retry) {
1119 + ret = -EAGAIN;
1120 + oa_tc6_look_for_new_frame(tc6);
1121 + }
1122 +
1123 + return ret;
1015 1124 }
1016 1125
1017 1126 static __be32 oa_tc6_prepare_data_header(bool data_valid, bool start_valid,
@@ -1173,12 +1282,9 @@ static int oa_tc6_try_spi_transfer(struct oa_tc6 *tc6)
1173 1282 }
1174 1283
1175 1284 ret = oa_tc6_process_spi_data_rx_buf(tc6, spi_len);
1176 - if (ret) {
1177 - if (ret == -EAGAIN)
1178 - continue;
1179 1285
1180 - oa_tc6_cleanup_ongoing_tx_skb(tc6);
1181 - oa_tc6_cleanup_ongoing_rx_skb(tc6);
1286 + if (ret && ret != -EAGAIN) {
1287 + oa_tc6_free_ongoing_skbs(tc6);
1182 1288 netdev_err(tc6->netdev, "Device error: %d\n", ret);
1183 1289 return ret;
1184 1290 }
@@ -1200,15 +1306,20 @@ static irqreturn_t oa_tc6_macphy_threaded_irq(int irq, void *data)
1200 1306 * no need to attempt spi transfer, once it fails. Pending skbs
1201 1307 * are already freed.
1202 1308 */
1203 - if (!tc6->disable_traffic) {
1204 - while (tc6->int_flag ||
1205 - (tc6->waiting_tx_skb && tc6->tx_credits)) {
1206 - ret = oa_tc6_try_spi_transfer(tc6);
1207 - if (ret) {
1208 - disable_irq_nosync(tc6->spi->irq);
1209 - oa_tc6_disable_traffic(tc6);
1210 - break;
1211 - }
1309 + spin_lock_bh(&tc6->tx_skb_lock);
1310 + if (tc6->disable_traffic) {
1311 + spin_unlock_bh(&tc6->tx_skb_lock);
1312 + return IRQ_HANDLED;
1313 + }
1314 + spin_unlock_bh(&tc6->tx_skb_lock);
1315 +
1316 + while (tc6->int_flag ||
1317 + (tc6->waiting_tx_skb && tc6->tx_credits)) {
1318 + ret = oa_tc6_try_spi_transfer(tc6);
1319 + if (ret) {
1320 + disable_irq_nosync(tc6->spi->irq);
1321 + oa_tc6_disable_traffic(tc6);
1322 + break;
1212 1323 }
1213 1324 }
1214 1325
@@ -1287,23 +1398,30 @@ EXPORT_SYMBOL_GPL(oa_tc6_zero_align_receive_frame_enable);
1287 1398 * @tc6: oa_tc6 struct.
1288 1399 * @skb: socket buffer in which the ethernet frame is stored.
1289 1400 *
1290 - * Return: NETDEV_TX_OK if the transmit ethernet frame skb added in the tx_skb_q
1291 - * otherwise returns NETDEV_TX_BUSY.
1401 + * Return: NETDEV_TX_OK either on successful queueing of the packet for
1402 + * transmission, or on packet getting dropped. Packet can be dropped due to
1403 + * failure in linearizing the buffer or disable_traffic is set due to
1404 + * earlier fatal error. Returns NETDEV_TX_BUSY when there is no room
1405 + * to queue the packet.
1292 1406 */
1293 1407 netdev_tx_t oa_tc6_start_xmit(struct oa_tc6 *tc6, struct sk_buff *skb)
1294 1408 {
1295 - if (tc6->disable_traffic || tc6->waiting_tx_skb) {
1296 - netif_stop_queue(tc6->netdev);
1297 - return NETDEV_TX_BUSY;
1298 - }
1299 -
1300 1409 if (skb_linearize(skb)) {
1301 - dev_kfree_skb_any(skb);
1302 - tc6->netdev->stats.tx_dropped++;
1410 + oa_tc6_drop_tx_skb(tc6, skb);
1303 1411 return NETDEV_TX_OK;
1304 1412 }
1305 1413
1306 1414 spin_lock_bh(&tc6->tx_skb_lock);
1415 + if (tc6->waiting_tx_skb) {
1416 + netif_stop_queue(tc6->netdev);
1417 + spin_unlock_bh(&tc6->tx_skb_lock);
1418 + return NETDEV_TX_BUSY;
1419 + }
1420 + if (tc6->disable_traffic) {
1421 + spin_unlock_bh(&tc6->tx_skb_lock);
1422 + oa_tc6_drop_tx_skb(tc6, skb);
1423 + return NETDEV_TX_OK;
1424 + }
1307 1425 tc6->waiting_tx_skb = skb;
1308 1426 spin_unlock_bh(&tc6->tx_skb_lock);
1309 1427
@@ -1462,8 +1580,10 @@ EXPORT_SYMBOL_GPL(oa_tc6_init);
1462 1580 */
1463 1581 void oa_tc6_exit(struct oa_tc6 *tc6)
1464 1582 {
1465 - tc6->disable_traffic = true;
1466 1583 disable_irq(tc6->spi->irq);
1584 + spin_lock_bh(&tc6->tx_skb_lock);
1585 + tc6->disable_traffic = true;
1586 + spin_unlock_bh(&tc6->tx_skb_lock);
1467 1587 oa_tc6_phy_exit(tc6);
1468 1588 oa_tc6_free_pending_skbs(tc6);
1469 1589 }
modified drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3676,6 +3676,14 @@ static int stmmac_hw_setup(struct net_device *dev)
3676 3676 /* Initialize MTL*/
3677 3677 stmmac_mtl_configuration(priv);
3678 3678
3679 + /* Apply the RX packet parser table */
3680 + if (priv->tc_entries) {
3681 + ret = stmmac_rxp_config(priv, priv->hw->pcsr, priv->tc_entries,
3682 + priv->tc_entries_max);
3683 + if (ret)
3684 + return ret;
3685 + }
3686 +
3679 3687 /* Initialize Safety Features */
3680 3688 stmmac_safety_feat_configuration(priv);
3681 3689
@@ -4319,6 +4327,7 @@ static bool stmmac_vlan_insert(struct stmmac_priv *priv, struct sk_buff *skb,
4319 4327 /**
4320 4328 * stmmac_tso_allocator - close entry point of the driver
4321 4329 * @priv: driver private structure
4330 + * @entry: TX queue buffer index
4322 4331 * @des: buffer start address
4323 4332 * @total_len: total length to fill in descriptors
4324 4333 * @last_segment: condition for the last descriptor
@@ -4327,8 +4336,9 @@ static bool stmmac_vlan_insert(struct stmmac_priv *priv, struct sk_buff *skb,
4327 4336 * This function fills descriptor and request new descriptors according to
4328 4337 * buffer length to fill
4329 4338 */
4330 - static void stmmac_tso_allocator(struct stmmac_priv *priv, dma_addr_t des,
4331 - int total_len, bool last_segment, u32 queue)
4339 + static void stmmac_tso_allocator(struct stmmac_priv *priv, u32 *entry,
4340 + dma_addr_t des, int total_len,
4341 + bool last_segment, u32 queue)
4332 4342 {
4333 4343 struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
4334 4344 struct dma_desc *desc;
@@ -4340,14 +4350,13 @@ static void stmmac_tso_allocator(struct stmmac_priv *priv, dma_addr_t des,
4340 4350 while (tmp_len > 0) {
4341 4351 dma_addr_t curr_addr;
4342 4352
4343 - tx_q->cur_tx = STMMAC_NEXT_ENTRY(tx_q->cur_tx,
4344 - priv->dma_conf.dma_tx_size);
4345 - WARN_ON(tx_q->tx_skbuff[tx_q->cur_tx]);
4353 + *entry = STMMAC_NEXT_ENTRY(*entry, priv->dma_conf.dma_tx_size);
4354 + WARN_ON(tx_q->tx_skbuff[*entry]);
4346 4355
4347 4356 if (tx_q->tbs & STMMAC_TBS_AVAIL)
4348 - desc = &tx_q->dma_entx[tx_q->cur_tx].basic;
4357 + desc = &tx_q->dma_entx[*entry].basic;
4349 4358 else
4350 - desc = &tx_q->dma_tx[tx_q->cur_tx];
4359 + desc = &tx_q->dma_tx[*entry];
4351 4360
4352 4361 curr_addr = des + (total_len - tmp_len);
4353 4362 stmmac_set_desc_addr(priv, desc, curr_addr);
@@ -4486,7 +4495,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4486 4495 {
4487 4496 struct dma_desc *desc, *first, *mss_desc = NULL;
4488 4497 struct stmmac_priv *priv = netdev_priv(dev);
4489 - unsigned int first_entry, tx_packets;
4498 + unsigned int first_entry, entry, tx_packets;
4490 4499 struct stmmac_txq_stats *txq_stats;
4491 4500 struct stmmac_tx_queue *tx_q;
4492 4501 bool set_ic, is_last_segment;
@@ -4549,22 +4558,24 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4549 4558 }
4550 4559
4551 4560 first_entry = tx_q->cur_tx;
4552 - WARN_ON(tx_q->tx_skbuff[first_entry]);
4561 + entry = first_entry;
4562 +
4563 + WARN_ON(tx_q->tx_skbuff[entry]);
4553 4564
4554 4565 if (tx_q->tbs & STMMAC_TBS_AVAIL)
4555 - desc = &tx_q->dma_entx[first_entry].basic;
4566 + desc = &tx_q->dma_entx[entry].basic;
4556 4567 else
4557 - desc = &tx_q->dma_tx[first_entry];
4568 + desc = &tx_q->dma_tx[entry];
4558 4569 first = desc;
4559 4570
4560 4571 /* first descriptor: fill Headers on Buf1 */
4561 4572 des = dma_map_single(priv->device, skb->data, skb_headlen(skb),
4562 4573 DMA_TO_DEVICE);
4563 4574 if (dma_mapping_error(priv->device, des))
4564 - goto dma_map_err;
4575 + goto error;
4565 4576
4566 4577 stmmac_set_desc_addr(priv, first, des);
4567 - stmmac_tso_allocator(priv, des + proto_hdr_len, pay_len,
4578 + stmmac_tso_allocator(priv, &entry, des + proto_hdr_len, pay_len,
4568 4579 (nfrags == 0), queue);
4569 4580
4570 4581 /* In case two or more DMA transmit descriptors are allocated for this
@@ -4579,8 +4590,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4579 4590 * this DMA buffer right after the DMA engine completely finishes the
4580 4591 * full buffer transmission.
4581 4592 */
4582 - stmmac_set_tx_skb_dma_entry(tx_q, tx_q->cur_tx, des, skb_headlen(skb),
4583 - false);
4593 + stmmac_set_tx_skb_dma_entry(tx_q, entry, des, skb_headlen(skb), false);
4584 4594
4585 4595 /* Prepare fragments */
4586 4596 for (i = 0; i < nfrags; i++) {
@@ -4590,14 +4600,15 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4590 4600 skb_frag_size(frag),
4591 4601 DMA_TO_DEVICE);
4592 4602 if (dma_mapping_error(priv->device, des))
4593 - goto dma_map_err;
4603 + goto error_dma_unmap;
4594 4604
4595 - stmmac_tso_allocator(priv, des, skb_frag_size(frag),
4605 + stmmac_tso_allocator(priv, &entry, des, skb_frag_size(frag),
4596 4606 (i == nfrags - 1), queue);
4597 4607
4598 - stmmac_set_tx_skb_dma_entry(tx_q, tx_q->cur_tx, des,
4608 + stmmac_set_tx_skb_dma_entry(tx_q, entry, des,
4599 4609 skb_frag_size(frag), true);
4600 4610 }
4611 + tx_q->cur_tx = entry;
4601 4612
4602 4613 stmmac_set_tx_dma_last_segment(tx_q, tx_q->cur_tx);
4603 4614
@@ -4702,7 +4713,19 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4702 4713
4703 4714 return NETDEV_TX_OK;
4704 4715
4705 - dma_map_err:
4716 + error_dma_unmap:
4717 + for (;;) {
4718 + desc = stmmac_get_tx_desc(priv, tx_q, first_entry);
4719 + stmmac_release_tx_desc(priv, desc, priv->descriptor_mode);
4720 + stmmac_free_tx_buffer(priv, &priv->dma_conf, queue,
4721 + first_entry);
4722 + if (first_entry == entry)
4723 + break;
4724 +
4725 + first_entry = STMMAC_NEXT_ENTRY(first_entry,
4726 + priv->dma_conf.dma_tx_size);
4727 + }
4728 + error:
4706 4729 dev_err(priv->device, "Tx dma map failed\n");
4707 4730 dev_kfree_skb(skb);
4708 4731 priv->xstats.tx_dropped++;
modified drivers/net/gtp.c
@@ -318,6 +318,11 @@ static int gtp_inner_proto(struct sk_buff *skb, unsigned int hdrlen,
318 318 static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb,
319 319 unsigned int hdrlen, unsigned int role, __u16 inner_proto)
320 320 {
321 + if (skb_is_gso(skb)) {
322 + netdev_dbg(pctx->dev, "GSO is not supported in GTP\n");
323 + goto err;
324 + }
325 +
321 326 if (!gtp_check_ms(skb, pctx, hdrlen, role, inner_proto)) {
322 327 netdev_dbg(pctx->dev, "No PDP ctx for this MS\n");
323 328 return 1;
modified drivers/net/ipvlan/ipvlan_main.c
@@ -848,7 +848,6 @@ static int ipvlan_device_event(struct notifier_block *unused,
848 848 __ipvlan_link_delete(net, ipvlan->dev, &lst_kill);
849 849 }
850 850
851 - unregister_netdevice_many(&lst_kill);
852 851 break;
853 852 }
854 853 case NETDEV_FEAT_CHANGE:
@@ -899,6 +898,9 @@ static int ipvlan_device_event(struct notifier_block *unused,
899 898
900 899 mutex_unlock(&port->pnodes_lock);
901 900
901 + /* Avoid invoking nested netdevice notifiers under pnodes_lock. */
902 + unregister_netdevice_many(&lst_kill);
903 +
902 904 ipvlan_port_put(port);
903 905
904 906 return ret;
modified drivers/net/ntb_netdev.c
@@ -127,8 +127,10 @@ static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
127 127 {
128 128 struct ntb_netdev_queue *q = qp_data;
129 129 struct ntb_netdev *dev = q->ntdev;
130 + struct pcpu_sw_netstats *tstats;
130 131 struct sk_buff *skb, *new_skb;
131 132 struct net_device *ndev;
133 + unsigned long flags;
132 134 int rc;
133 135
134 136 ndev = dev->ndev;
@@ -139,17 +141,20 @@ static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
139 141 netdev_dbg(ndev, "%s: %d byte payload received\n", __func__, len);
140 142
141 143 if (len < 0) {
142 - ndev->stats.rx_errors++;
143 - ndev->stats.rx_length_errors++;
144 + DEV_STATS_INC(ndev, rx_errors);
145 + DEV_STATS_INC(ndev, rx_length_errors);
144 146 goto enqueue_again;
145 147 }
146 148
147 - ndev->stats.rx_packets++;
148 - ndev->stats.rx_bytes += len;
149 + tstats = this_cpu_ptr(ndev->tstats);
150 + flags = u64_stats_update_begin_irqsave(&tstats->syncp);
151 + u64_stats_inc(&tstats->rx_packets);
152 + u64_stats_add(&tstats->rx_bytes, len);
153 + u64_stats_update_end_irqrestore(&tstats->syncp, flags);
149 154
150 155 new_skb = netdev_alloc_skb(ndev, ndev->mtu + ETH_HLEN);
151 156 if (!new_skb) {
152 - ndev->stats.rx_dropped++;
157 + DEV_STATS_INC(ndev, rx_dropped);
153 158 goto enqueue_again;
154 159 }
155 160
@@ -166,8 +171,8 @@ enqueue_again:
166 171 rc = ntb_transport_rx_enqueue(qp, skb, skb->data, ndev->mtu + ETH_HLEN);
167 172 if (rc) {
168 173 dev_kfree_skb_any(skb);
169 - ndev->stats.rx_errors++;
170 - ndev->stats.rx_fifo_errors++;
174 + DEV_STATS_INC(ndev, rx_errors);
175 + DEV_STATS_INC(ndev, rx_fifo_errors);
171 176 }
172 177 }
173 178
@@ -210,25 +215,39 @@ static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
210 215 {
211 216 struct ntb_netdev_queue *q = qp_data;
212 217 struct ntb_netdev *dev = q->ntdev;
218 + struct pcpu_sw_netstats *tstats;
213 219 struct net_device *ndev;
214 220 struct sk_buff *skb;
221 + unsigned long flags;
222 + bool registered;
215 223
216 224 ndev = dev->ndev;
217 225 skb = data;
218 226 if (!skb || !ndev)
219 227 return;
220 228
229 + rcu_read_lock();
230 + registered = READ_ONCE(ndev->reg_state) == NETREG_REGISTERED;
231 + if (!registered)
232 + goto free_skb;
233 +
221 234 if (len > 0) {
222 - ndev->stats.tx_packets++;
223 - ndev->stats.tx_bytes += skb->len;
235 + /* The memcpy kthread can migrate, so pin the per-CPU update. */
236 + tstats = get_cpu_ptr(ndev->tstats);
237 + flags = u64_stats_update_begin_irqsave(&tstats->syncp);
238 + u64_stats_inc(&tstats->tx_packets);
239 + u64_stats_add(&tstats->tx_bytes, skb->len);
240 + u64_stats_update_end_irqrestore(&tstats->syncp, flags);
241 + put_cpu_ptr(ndev->tstats);
224 242 } else {
225 - ndev->stats.tx_errors++;
226 - ndev->stats.tx_aborted_errors++;
243 + DEV_STATS_INC(ndev, tx_errors);
244 + DEV_STATS_INC(ndev, tx_aborted_errors);
227 245 }
228 246
247 + free_skb:
229 248 dev_kfree_skb_any(skb);
230 249
231 - if (ntb_transport_tx_free_entry(qp) >= tx_start) {
250 + if (registered && ntb_transport_tx_free_entry(qp) >= tx_start) {
232 251 /* Make sure anybody stopping the queue after this sees the new
233 252 * value of ntb_transport_tx_free_entry()
234 253 */
@@ -237,6 +256,7 @@ static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
237 256 ntb_transport_link_query(q->qp))
238 257 netif_wake_subqueue(ndev, q->qid);
239 258 }
259 + rcu_read_unlock();
240 260 }
241 261
242 262 static const struct ntb_queue_handlers ntb_netdev_handlers = {
@@ -277,7 +297,7 @@ static netdev_tx_t ntb_netdev_start_xmit(struct sk_buff *skb,
277 297
278 298 drop:
279 299 dev_kfree_skb_any(skb);
280 - ndev->stats.tx_dropped++;
300 + DEV_STATS_INC(ndev, tx_dropped);
281 301 return NETDEV_TX_OK;
282 302 }
283 303
@@ -639,14 +659,14 @@ static int ntb_netdev_probe(struct device *client_dev)
639 659 dev->client_dev = client_dev;
640 660 dev->num_queues = 0;
641 661
642 - dev->queues = kzalloc_objs(*dev->queues, NTB_NETDEV_MAX_QUEUES,
643 - GFP_KERNEL);
662 + dev->queues = kzalloc_objs(*dev->queues, NTB_NETDEV_MAX_QUEUES);
644 663 if (!dev->queues) {
645 664 rc = -ENOMEM;
646 665 goto err_free_netdev;
647 666 }
648 667
649 668 ndev->features = NETIF_F_HIGHDMA;
669 + ndev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
650 670
651 671 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
652 672
modified drivers/net/ppp/ppp_async.c
@@ -63,8 +63,6 @@ struct asyncppp {
63 63
64 64 struct tasklet_struct tsk;
65 65
66 - refcount_t refcnt;
67 - struct completion dead;
68 66 struct ppp_channel chan; /* interface to generic ppp layer */
69 67 unsigned char obuf[OBUFSIZE];
70 68 };
@@ -114,38 +112,6 @@ static const struct ppp_channel_ops async_ops = {
114 112 * Routines implementing the PPP line discipline.
115 113 */
116 114
117 - /*
118 - * We have a potential race on dereferencing tty->disc_data,
119 - * because the tty layer provides no locking at all - thus one
120 - * cpu could be running ppp_asynctty_receive while another
121 - * calls ppp_asynctty_close, which zeroes tty->disc_data and
122 - * frees the memory that ppp_asynctty_receive is using. The best
123 - * way to fix this is to use a rwlock in the tty struct, but for now
124 - * we use a single global rwlock for all ttys in ppp line discipline.
125 - *
126 - * FIXME: this is no longer true. The _close path for the ldisc is
127 - * now guaranteed to be sane.
128 - */
129 - static DEFINE_RWLOCK(disc_data_lock);
130 -
131 - static struct asyncppp *ap_get(struct tty_struct *tty)
132 - {
133 - struct asyncppp *ap;
134 -
135 - read_lock(&disc_data_lock);
136 - ap = tty->disc_data;
137 - if (ap != NULL)
138 - refcount_inc(&ap->refcnt);
139 - read_unlock(&disc_data_lock);
140 - return ap;
141 - }
142 -
143 - static void ap_put(struct asyncppp *ap)
144 - {
145 - if (refcount_dec_and_test(&ap->refcnt))
146 - complete(&ap->dead);
147 - }
148 -
149 115 /*
150 116 * Called when a tty is put into PPP line discipline. Called in process
151 117 * context.
@@ -180,9 +146,6 @@ ppp_asynctty_open(struct tty_struct *tty)
180 146 skb_queue_head_init(&ap->rqueue);
181 147 tasklet_setup(&ap->tsk, ppp_async_process);
182 148
183 - refcount_set(&ap->refcnt, 1);
184 - init_completion(&ap->dead);
185 -
186 149 ap->chan.private = ap;
187 150 ap->chan.ops = &async_ops;
188 151 ap->chan.mtu = PPP_MRU;
@@ -203,34 +166,18 @@ ppp_asynctty_open(struct tty_struct *tty)
203 166 }
204 167
205 168 /*
206 - * Called when the tty is put into another line discipline
207 - * or it hangs up. We have to wait for any cpu currently
208 - * executing in any of the other ppp_asynctty_* routines to
209 - * finish before we can call ppp_unregister_channel and free
210 - * the asyncppp struct. This routine must be called from
211 - * process context, not interrupt or softirq context.
169 + * Called when the tty is put into another line discipline or it hangs up.
170 + * This call is serialized against other ldisc functions.
212 171 */
213 172 static void
214 173 ppp_asynctty_close(struct tty_struct *tty)
215 174 {
216 - struct asyncppp *ap;
175 + struct asyncppp *ap = tty->disc_data;
217 176
218 - write_lock_irq(&disc_data_lock);
219 - ap = tty->disc_data;
220 - tty->disc_data = NULL;
221 - write_unlock_irq(&disc_data_lock);
222 177 if (!ap)
223 178 return;
224 179
225 - /*
226 - * We have now ensured that nobody can start using ap from now
227 - * on, but we have to wait for all existing users to finish.
228 - * Note that ppp_unregister_channel ensures that no calls to
229 - * our channel ops (i.e. ppp_async_send/ioctl) are in progress
230 - * by the time it returns.
231 - */
232 - if (!refcount_dec_and_test(&ap->refcnt))
233 - wait_for_completion(&ap->dead);
180 + tty->disc_data = NULL;
234 181 tasklet_kill(&ap->tsk);
235 182
236 183 ppp_unregister_channel(&ap->chan);
@@ -240,17 +187,6 @@ ppp_asynctty_close(struct tty_struct *tty)
240 187 kfree(ap);
241 188 }
242 189
243 - /*
244 - * Called on tty hangup in process context.
245 - *
246 - * Wait for I/O to driver to complete and unregister PPP channel.
247 - * This is already done by the close routine, so just call that.
248 - */
249 - static void ppp_asynctty_hangup(struct tty_struct *tty)
250 - {
251 - ppp_asynctty_close(tty);
252 - }
253 -
254 190 /*
255 191 * Read does nothing - no data is ever available this way.
256 192 * Pppd reads and writes packets via /dev/ppp instead.
@@ -281,7 +217,7 @@ ppp_asynctty_write(struct tty_struct *tty, struct file *file, const u8 *buf,
281 217 static int
282 218 ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
283 219 {
284 - struct asyncppp *ap = ap_get(tty);
220 + struct asyncppp *ap = tty->disc_data;
285 221 int err, val;
286 222 int __user *p = (int __user *)arg;
287 223
@@ -322,7 +258,6 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
322 258 err = tty_mode_ioctl(tty, cmd, arg);
323 259 }
324 260
325 - ap_put(ap);
326 261 return err;
327 262 }
328 263
@@ -331,7 +266,7 @@ static void
331 266 ppp_asynctty_receive(struct tty_struct *tty, const u8 *buf, const u8 *cflags,
332 267 size_t count)
333 268 {
334 - struct asyncppp *ap = ap_get(tty);
269 + struct asyncppp *ap = tty->disc_data;
335 270 unsigned long flags;
336 271
337 272 if (!ap)
@@ -341,21 +276,19 @@ ppp_asynctty_receive(struct tty_struct *tty, const u8 *buf, const u8 *cflags,
341 276 spin_unlock_irqrestore(&ap->recv_lock, flags);
342 277 if (!skb_queue_empty(&ap->rqueue))
343 278 tasklet_schedule(&ap->tsk);
344 - ap_put(ap);
345 279 tty_unthrottle(tty);
346 280 }
347 281
348 282 static void
349 283 ppp_asynctty_wakeup(struct tty_struct *tty)
350 284 {
351 - struct asyncppp *ap = ap_get(tty);
285 + struct asyncppp *ap = tty->disc_data;
352 286
353 287 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
354 288 if (!ap)
355 289 return;
356 290 set_bit(XMIT_WAKEUP, &ap->xmit_flags);
357 291 tasklet_schedule(&ap->tsk);
358 - ap_put(ap);
359 292 }
360 293
361 294
@@ -365,7 +298,6 @@ static struct tty_ldisc_ops ppp_ldisc = {
365 298 .name = "ppp",
366 299 .open = ppp_asynctty_open,
367 300 .close = ppp_asynctty_close,
368 - .hangup = ppp_asynctty_hangup,
369 301 .read = ppp_asynctty_read,
370 302 .write = ppp_asynctty_write,
371 303 .ioctl = ppp_asynctty_ioctl,
modified drivers/net/ppp/ppp_synctty.c
@@ -38,11 +38,9 @@
38 38 #include <linux/ppp-ioctl.h>
39 39 #include <linux/ppp_channel.h>
40 40 #include <linux/spinlock.h>
41 - #include <linux/completion.h>
42 41 #include <linux/init.h>
43 42 #include <linux/interrupt.h>
44 43 #include <linux/slab.h>
45 - #include <linux/refcount.h>
46 44 #include <linux/unaligned.h>
47 45 #include <linux/uaccess.h>
48 46
@@ -67,8 +65,6 @@ struct syncppp {
67 65
68 66 struct tasklet_struct tsk;
69 67
70 - refcount_t refcnt;
71 - struct completion dead_cmp;
72 68 struct ppp_channel chan; /* interface to generic ppp layer */
73 69 };
74 70
@@ -116,37 +112,6 @@ ppp_print_buffer (const char *name, const __u8 *buf, int count)
116 112 * Routines implementing the synchronous PPP line discipline.
117 113 */
118 114
119 - /*
120 - * We have a potential race on dereferencing tty->disc_data,
121 - * because the tty layer provides no locking at all - thus one
122 - * cpu could be running ppp_synctty_receive while another
123 - * calls ppp_synctty_close, which zeroes tty->disc_data and
124 - * frees the memory that ppp_synctty_receive is using. The best
125 - * way to fix this is to use a rwlock in the tty struct, but for now
126 - * we use a single global rwlock for all ttys in ppp line discipline.
127 - *
128 - * FIXME: Fixed in tty_io nowadays.
129 - */
130 - static DEFINE_RWLOCK(disc_data_lock);
131 -
132 - static struct syncppp *sp_get(struct tty_struct *tty)
133 - {
134 - struct syncppp *ap;
135 -
136 - read_lock(&disc_data_lock);
137 - ap = tty->disc_data;
138 - if (ap != NULL)
139 - refcount_inc(&ap->refcnt);
140 - read_unlock(&disc_data_lock);
141 - return ap;
142 - }
143 -
144 - static void sp_put(struct syncppp *ap)
145 - {
146 - if (refcount_dec_and_test(&ap->refcnt))
147 - complete(&ap->dead_cmp);
148 - }
149 -
150 115 /*
151 116 * Called when a tty is put into sync-PPP line discipline.
152 117 */
@@ -177,9 +142,6 @@ ppp_sync_open(struct tty_struct *tty)
177 142 skb_queue_head_init(&ap->rqueue);
178 143 tasklet_setup(&ap->tsk, ppp_sync_process);
179 144
180 - refcount_set(&ap->refcnt, 1);
181 - init_completion(&ap->dead_cmp);
182 -
183 145 ap->chan.private = ap;
184 146 ap->chan.ops = &sync_ops;
185 147 ap->chan.mtu = PPP_MRU;
@@ -201,34 +163,18 @@ ppp_sync_open(struct tty_struct *tty)
201 163 }
202 164
203 165 /*
204 - * Called when the tty is put into another line discipline
205 - * or it hangs up. We have to wait for any cpu currently
206 - * executing in any of the other ppp_synctty_* routines to
207 - * finish before we can call ppp_unregister_channel and free
208 - * the syncppp struct. This routine must be called from
209 - * process context, not interrupt or softirq context.
166 + * Called when the tty is put into another line discipline or it hangs up.
167 + * This call is serialized against other ldisc functions.
210 168 */
211 169 static void
212 170 ppp_sync_close(struct tty_struct *tty)
213 171 {
214 - struct syncppp *ap;
172 + struct syncppp *ap = tty->disc_data;
215 173
216 - write_lock_irq(&disc_data_lock);
217 - ap = tty->disc_data;
218 - tty->disc_data = NULL;
219 - write_unlock_irq(&disc_data_lock);
220 174 if (!ap)
221 175 return;
222 176
223 - /*
224 - * We have now ensured that nobody can start using ap from now
225 - * on, but we have to wait for all existing users to finish.
226 - * Note that ppp_unregister_channel ensures that no calls to
227 - * our channel ops (i.e. ppp_sync_send/ioctl) are in progress
228 - * by the time it returns.
229 - */
230 - if (!refcount_dec_and_test(&ap->refcnt))
231 - wait_for_completion(&ap->dead_cmp);
177 + tty->disc_data = NULL;
232 178 tasklet_kill(&ap->tsk);
233 179
234 180 ppp_unregister_channel(&ap->chan);
@@ -237,17 +183,6 @@ ppp_sync_close(struct tty_struct *tty)
237 183 kfree(ap);
238 184 }
239 185
240 - /*
241 - * Called on tty hangup in process context.
242 - *
243 - * Wait for I/O to driver to complete and unregister PPP channel.
244 - * This is already done by the close routine, so just call that.
245 - */
246 - static void ppp_sync_hangup(struct tty_struct *tty)
247 - {
248 - ppp_sync_close(tty);
249 - }
250 -
251 186 /*
252 187 * Read does nothing - no data is ever available this way.
253 188 * Pppd reads and writes packets via /dev/ppp instead.
@@ -273,7 +208,7 @@ ppp_sync_write(struct tty_struct *tty, struct file *file, const u8 *buf,
273 208 static int
274 209 ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
275 210 {
276 - struct syncppp *ap = sp_get(tty);
211 + struct syncppp *ap = tty->disc_data;
277 212 int __user *p = (int __user *)arg;
278 213 int err, val;
279 214
@@ -314,7 +249,6 @@ ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
314 249 break;
315 250 }
316 251
317 - sp_put(ap);
318 252 return err;
319 253 }
320 254
@@ -323,7 +257,7 @@ static void
323 257 ppp_sync_receive(struct tty_struct *tty, const u8 *buf, const u8 *cflags,
324 258 size_t count)
325 259 {
326 - struct syncppp *ap = sp_get(tty);
260 + struct syncppp *ap = tty->disc_data;
327 261 unsigned long flags;
328 262
329 263 if (!ap)
@@ -333,21 +267,19 @@ ppp_sync_receive(struct tty_struct *tty, const u8 *buf, const u8 *cflags,
333 267 spin_unlock_irqrestore(&ap->recv_lock, flags);
334 268 if (!skb_queue_empty(&ap->rqueue))
335 269 tasklet_schedule(&ap->tsk);
336 - sp_put(ap);
337 270 tty_unthrottle(tty);
338 271 }
339 272
340 273 static void
341 274 ppp_sync_wakeup(struct tty_struct *tty)
342 275 {
343 - struct syncppp *ap = sp_get(tty);
276 + struct syncppp *ap = tty->disc_data;
344 277
345 278 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
346 279 if (!ap)
347 280 return;
348 281 set_bit(XMIT_WAKEUP, &ap->xmit_flags);
349 282 tasklet_schedule(&ap->tsk);
350 - sp_put(ap);
351 283 }
352 284
353 285
@@ -357,7 +289,6 @@ static struct tty_ldisc_ops ppp_sync_ldisc = {
357 289 .name = "pppsync",
358 290 .open = ppp_sync_open,
359 291 .close = ppp_sync_close,
360 - .hangup = ppp_sync_hangup,
361 292 .read = ppp_sync_read,
362 293 .write = ppp_sync_write,
363 294 .ioctl = ppp_synctty_ioctl,
modified drivers/net/usb/qmi_wwan.c
@@ -1446,6 +1446,7 @@ static const struct usb_device_id products[] = {
1446 1446 {QMI_QUIRK_SET_DTR(0x2c7c, 0x0316, 3)}, /* Quectel RG255C */
1447 1447 {QMI_QUIRK_SET_DTR(0x2cb7, 0x0104, 4)}, /* Fibocom NL678 series */
1448 1448 {QMI_QUIRK_SET_DTR(0x2cb7, 0x0112, 0)}, /* Fibocom FG132 */
1449 + {QMI_QUIRK_SET_DTR(0x04b7, 0x8217, 8)}, /* Compal EXM-G1x */
1449 1450 {QMI_FIXED_INTF(0x0489, 0xe0b4, 0)}, /* Foxconn T77W968 LTE */
1450 1451 {QMI_FIXED_INTF(0x0489, 0xe0b5, 0)}, /* Foxconn T77W968 LTE with eSIM support*/
1451 1452 {QMI_FIXED_INTF(0x2692, 0x9025, 4)}, /* Cellient MPL200 (rebranded Qualcomm 05c6:9025) */
modified drivers/net/vxlan/vxlan_mdb.c
@@ -354,6 +354,10 @@ static bool vxlan_mdb_is_valid_source(const struct nlattr *attr, __be16 proto,
354 354 NL_SET_ERR_MSG_MOD(extack, "IPv4 multicast source address is not allowed");
355 355 return false;
356 356 }
357 + if (ipv4_is_zeronet(nla_get_in_addr(attr))) {
358 + NL_SET_ERR_MSG_MOD(extack, "IPv4 all-zeros source address is not allowed");
359 + return false;
360 + }
357 361 break;
358 362 #if IS_ENABLED(CONFIG_IPV6)
359 363 case htons(ETH_P_IPV6): {
@@ -368,6 +372,10 @@ static bool vxlan_mdb_is_valid_source(const struct nlattr *attr, __be16 proto,
368 372 NL_SET_ERR_MSG_MOD(extack, "IPv6 multicast source address is not allowed");
369 373 return false;
370 374 }
375 + if (ipv6_addr_any(&src)) {
376 + NL_SET_ERR_MSG_MOD(extack, "IPv6 all-zeros source address is not allowed");
377 + return false;
378 + }
371 379 break;
372 380 }
373 381 #endif
modified drivers/net/wireless/ath/ath12k/ahb.c
@@ -870,7 +870,7 @@ static struct ath12k_ahb_rproc_info *ath12k_ahb_rproc_info_alloc(struct ath12k_b
870 870
871 871 lockdep_assert_held(&ath12k_rproc_info_lock);
872 872
873 - rproc_info = kzalloc_obj(*rproc_info, GFP_KERNEL);
873 + rproc_info = kzalloc_obj(*rproc_info);
874 874 if (!rproc_info)
875 875 return NULL;
876 876
modified drivers/net/wireless/intel/iwlwifi/mld/regulatory.c
@@ -514,8 +514,7 @@ void iwl_mld_init_ap_type_tables(struct iwl_mld *mld)
514 514 return;
515 515
516 516 if (iwl_fw_lookup_cmd_ver(mld->fw, cmd.id, 1) == 1) {
517 - struct iwl_mcc_allowed_ap_type_cmd_v1 *cmd_v1 =
518 - kzalloc(sizeof(*cmd_v1), GFP_KERNEL);
517 + struct iwl_mcc_allowed_ap_type_cmd_v1 *cmd_v1 = kzalloc_obj(*cmd_v1);
519 518
520 519 if (!cmd_v1)
521 520 return;
modified drivers/net/wireless/mediatek/mt76/mt7921/regd.c
@@ -289,7 +289,7 @@ int mt7921_regd_update(struct mt792x_phy *phy, char *alpha2)
289 289 goto err;
290 290 }
291 291
292 - regd = kzalloc(struct_size(regd, reg_rules, num_of_rules), GFP_KERNEL);
292 + regd = kzalloc_flex(*regd, reg_rules, num_of_rules);
293 293 if (!regd) {
294 294 ret = -ENOMEM;
295 295 goto err;
modified drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -1105,7 +1105,7 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
1105 1105 mlink = &msta->deflink;
1106 1106 is_deflink = true;
1107 1107 } else {
1108 - mlink = kzalloc(sizeof(*mlink), GFP_KERNEL);
1108 + mlink = kzalloc_obj(*mlink);
1109 1109 if (!mlink) {
1110 1110 err = -ENOMEM;
1111 1111 break;
modified drivers/net/wireless/mediatek/mt76/mt7925/regd.c
@@ -336,7 +336,7 @@ int mt7925_regd_update(struct mt792x_phy *phy, char *alpha2)
336 336 goto err;
337 337 }
338 338
339 - regd = kzalloc(struct_size(regd, reg_rules, num_of_rules), GFP_KERNEL);
339 + regd = kzalloc_flex(*regd, reg_rules, num_of_rules);
340 340 if (!regd) {
341 341 ret = -ENOMEM;
342 342 goto err;
modified drivers/net/wireless/morsemicro/mm81x/mac.c
@@ -706,8 +706,7 @@ static int mm81x_hw_scan_h_init_chan_list(struct mm81x_hw_scan_params *params,
706 706
707 707 params->num_chans = 0;
708 708 params->allocated_chans = 0;
709 - params->channels = kcalloc(chans_to_allocate, sizeof(*params->channels),
710 - GFP_KERNEL);
709 + params->channels = kzalloc_objs(*params->channels, chans_to_allocate);
711 710 if (!params->channels)
712 711 return -ENOMEM;
713 712
@@ -728,8 +727,8 @@ static int mm81x_hw_scan_h_init_chan_list(struct mm81x_hw_scan_params *params,
728 727 }
729 728 }
730 729
731 - params->powers_qdbm = kmalloc_array(
732 - num_pwrs_coarse, sizeof(*params->powers_qdbm), GFP_KERNEL);
730 + params->powers_qdbm = kmalloc_objs(*params->powers_qdbm,
731 + num_pwrs_coarse);
733 732 if (!params->powers_qdbm)
734 733 return -ENOMEM;
735 734
@@ -822,7 +821,7 @@ __mm81x_hw_scan_h_init_params(struct mm81x *mors)
822 821 struct mm81x_hw_scan_params *params = mors->hw_scan.params;
823 822
824 823 if (!params) {
825 - params = kzalloc_obj(*params, GFP_KERNEL);
824 + params = kzalloc_obj(*params);
826 825 if (params)
827 826 mors->hw_scan.params = params;
828 827 } else {
modified drivers/net/wireless/morsemicro/mm81x/yaps.c
@@ -22,15 +22,13 @@
22 22
23 23 static int mm81x_yaps_alloc_pkt_buffers(struct mm81x_yaps *yaps)
24 24 {
25 - yaps->hw.to_chip_pkts = kcalloc(MAX_PKTS_PER_TX_TXN,
26 - sizeof(*yaps->hw.to_chip_pkts),
27 - GFP_KERNEL);
25 + yaps->hw.to_chip_pkts = kzalloc_objs(*yaps->hw.to_chip_pkts,
26 + MAX_PKTS_PER_TX_TXN);
28 27 if (!yaps->hw.to_chip_pkts)
29 28 return -ENOMEM;
30 29
31 - yaps->hw.from_chip_pkts = kcalloc(MAX_PKTS_PER_RX_TXN,
32 - sizeof(*yaps->hw.from_chip_pkts),
33 - GFP_KERNEL);
30 + yaps->hw.from_chip_pkts = kzalloc_objs(*yaps->hw.from_chip_pkts,
31 + MAX_PKTS_PER_RX_TXN);
34 32 if (!yaps->hw.from_chip_pkts) {
35 33 kfree(yaps->hw.to_chip_pkts);
36 34 yaps->hw.to_chip_pkts = NULL;
modified drivers/net/wireless/nxp/nxpwifi/cfg80211.c
@@ -641,7 +641,7 @@ nxpwifi_cfg80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx, u32 change
641 641
642 642 switch (priv->bss_role) {
643 643 case NXPWIFI_BSS_ROLE_UAP:
644 - bss_cfg = kzalloc_obj(*bss_cfg, GFP_KERNEL);
644 + bss_cfg = kzalloc_obj(*bss_cfg);
645 645 if (!bss_cfg) {
646 646 ret = -ENOMEM;
647 647 break;
@@ -1713,7 +1713,7 @@ static int nxpwifi_cfg80211_start_ap(struct wiphy *wiphy,
1713 1713 if (!nxpwifi_is_channel_setting_allowable(priv, params->chandef.chan))
1714 1714 return -EOPNOTSUPP;
1715 1715
1716 - bss_cfg = kzalloc_obj(*bss_cfg, GFP_KERNEL);
1716 + bss_cfg = kzalloc_obj(*bss_cfg);
1717 1717 if (!bss_cfg)
1718 1718 return -ENOMEM;
1719 1719
@@ -1866,7 +1866,7 @@ nxpwifi_cfg80211_scan(struct wiphy *wiphy,
1866 1866 if (!nxpwifi_stop_bg_scan(priv))
1867 1867 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0);
1868 1868
1869 - user_scan_cfg = kzalloc_obj(*user_scan_cfg, GFP_KERNEL);
1869 + user_scan_cfg = kzalloc_obj(*user_scan_cfg);
1870 1870 if (!user_scan_cfg)
1871 1871 return -ENOMEM;
1872 1872
@@ -1973,7 +1973,7 @@ nxpwifi_cfg80211_sched_scan_start(struct wiphy *wiphy,
1973 1973 request->n_channels, request->scan_plans->interval,
1974 1974 (int)request->ie_len);
1975 1975
1976 - bgscan_cfg = kzalloc_obj(*bgscan_cfg, GFP_KERNEL);
1976 + bgscan_cfg = kzalloc_obj(*bgscan_cfg);
1977 1977 if (!bgscan_cfg)
1978 1978 return -ENOMEM;
1979 1979
@@ -2304,7 +2304,7 @@ nxpwifi_setup_he_caps(struct nxpwifi_private *priv,
2304 2304 if (!hw_he_cap_len)
2305 2305 return;
2306 2306
2307 - iftype_data = kmalloc_obj(*iftype_data, GFP_KERNEL);
2307 + iftype_data = kmalloc_obj(*iftype_data);
2308 2308 if (!iftype_data)
2309 2309 return;
2310 2310 memset(iftype_data, 0, sizeof(*iftype_data));
@@ -2759,7 +2759,7 @@ static int nxpwifi_set_mef_filter(struct nxpwifi_private *priv,
2759 2759 if (wowlan->n_patterns || wowlan->magic_pkt)
2760 2760 num_entries++;
2761 2761
2762 - mef_entry = kzalloc_objs(*mef_entry, num_entries, GFP_KERNEL);
2762 + mef_entry = kzalloc_objs(*mef_entry, num_entries);
2763 2763 if (!mef_entry)
2764 2764 return -ENOMEM;
2765 2765
@@ -3227,7 +3227,7 @@ static int nxpwifi_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
3227 3227 if (!tb[NXPWIFI_TM_ATTR_DATA])
3228 3228 return -EINVAL;
3229 3229
3230 - hostcmd = kzalloc_obj(*hostcmd, GFP_KERNEL);
3230 + hostcmd = kzalloc_obj(*hostcmd);
3231 3231 if (!hostcmd)
3232 3232 return -ENOMEM;
3233 3233
modified drivers/net/wireless/nxp/nxpwifi/cmdevt.c
@@ -302,7 +302,7 @@ int nxpwifi_alloc_cmd_buffer(struct nxpwifi_adapter *adapter)
302 302
303 303 /* Allocate and initialize struct cmd_ctrl_node */
304 304 cmd_array = kzalloc_objs(struct cmd_ctrl_node,
305 - NXPWIFI_NUM_OF_CMD_BUFFER, GFP_KERNEL);
305 + NXPWIFI_NUM_OF_CMD_BUFFER);
306 306 if (!cmd_array)
307 307 return -ENOMEM;
308 308
modified drivers/net/wireless/nxp/nxpwifi/ie.c
@@ -143,7 +143,7 @@ nxpwifi_update_uap_custom_ie(struct nxpwifi_private *priv,
143 143 u16 len;
144 144 int ret;
145 145
146 - ap_custom_ie = kzalloc_obj(*ap_custom_ie, GFP_KERNEL);
146 + ap_custom_ie = kzalloc_obj(*ap_custom_ie);
147 147 if (!ap_custom_ie)
148 148 return -ENOMEM;
149 149
@@ -209,7 +209,7 @@ static int nxpwifi_update_vs_ie(const u8 *ies, int ies_len,
209 209 vendor_ie = cfg80211_find_vendor_ie(oui, oui_type, ies, ies_len);
210 210 if (vendor_ie) {
211 211 if (!*ie_ptr) {
212 - *ie_ptr = kzalloc_obj(struct nxpwifi_ie, GFP_KERNEL);
212 + *ie_ptr = kzalloc_obj(struct nxpwifi_ie);
213 213 if (!*ie_ptr)
214 214 return -ENOMEM;
215 215 ie = *ie_ptr;
@@ -309,7 +309,7 @@ static int nxpwifi_uap_parse_tail_ies(struct nxpwifi_private *priv,
309 309 if (!info->tail || !info->tail_len)
310 310 return 0;
311 311
312 - gen_ie = kzalloc_obj(*gen_ie, GFP_KERNEL);
312 + gen_ie = kzalloc_obj(*gen_ie);
313 313 if (!gen_ie)
314 314 return -ENOMEM;
315 315
@@ -417,7 +417,7 @@ int nxpwifi_del_mgmt_ies(struct nxpwifi_private *priv)
417 417 int ret = 0;
418 418
419 419 if (priv->gen_idx != NXPWIFI_AUTO_IDX_MASK) {
420 - gen_ie = kmalloc_obj(*gen_ie, GFP_KERNEL);
420 + gen_ie = kmalloc_obj(*gen_ie);
421 421 if (!gen_ie)
422 422 return -ENOMEM;
423 423
@@ -434,7 +434,7 @@ int nxpwifi_del_mgmt_ies(struct nxpwifi_private *priv)
434 434 }
435 435
436 436 if (priv->beacon_idx != NXPWIFI_AUTO_IDX_MASK) {
437 - beacon_ie = kmalloc_obj(*beacon_ie, GFP_KERNEL);
437 + beacon_ie = kmalloc_obj(*beacon_ie);
438 438 if (!beacon_ie) {
439 439 ret = -ENOMEM;
440 440 goto done;
@@ -444,7 +444,7 @@ int nxpwifi_del_mgmt_ies(struct nxpwifi_private *priv)
444 444 beacon_ie->ie_length = 0;
445 445 }
446 446 if (priv->proberesp_idx != NXPWIFI_AUTO_IDX_MASK) {
447 - pr_ie = kmalloc_obj(*pr_ie, GFP_KERNEL);
447 + pr_ie = kmalloc_obj(*pr_ie);
448 448 if (!pr_ie) {
449 449 ret = -ENOMEM;
450 450 goto done;
@@ -454,7 +454,7 @@ int nxpwifi_del_mgmt_ies(struct nxpwifi_private *priv)
454 454 pr_ie->ie_length = 0;
455 455 }
456 456 if (priv->assocresp_idx != NXPWIFI_AUTO_IDX_MASK) {
457 - ar_ie = kmalloc_obj(*ar_ie, GFP_KERNEL);
457 + ar_ie = kmalloc_obj(*ar_ie);
458 458 if (!ar_ie) {
459 459 ret = -ENOMEM;
460 460 goto done;
modified drivers/net/wireless/nxp/nxpwifi/init.c
@@ -20,7 +20,7 @@ static int nxpwifi_add_bss_prio_tbl(struct nxpwifi_private *priv)
20 20 struct nxpwifi_bss_prio_node *bss_prio;
21 21 struct nxpwifi_bss_prio_tbl *tbl = adapter->bss_prio_tbl;
22 22
23 - bss_prio = kzalloc_obj(*bss_prio, GFP_KERNEL);
23 + bss_prio = kzalloc_obj(*bss_prio);
24 24 if (!bss_prio)
25 25 return -ENOMEM;
26 26
modified drivers/net/wireless/nxp/nxpwifi/main.c
@@ -32,7 +32,7 @@ static struct nxpwifi_adapter *nxpwifi_register(void *card, struct device *dev,
32 32 int ret = 0;
33 33 int i;
34 34
35 - adapter = kzalloc_obj(*adapter, GFP_KERNEL);
35 + adapter = kzalloc_obj(*adapter);
36 36 if (!adapter)
37 37 return ERR_PTR(-ENOMEM);
38 38
@@ -55,7 +55,7 @@ static struct nxpwifi_adapter *nxpwifi_register(void *card, struct device *dev,
55 55 for (i = 0; i < NXPWIFI_MAX_BSS_NUM; i++) {
56 56 /* Allocate memory for private structure */
57 57 adapter->priv[i] =
58 - kzalloc_obj(struct nxpwifi_private, GFP_KERNEL);
58 + kzalloc_obj(struct nxpwifi_private);
59 59 if (!adapter->priv[i]) {
60 60 ret = -ENOMEM;
61 61 goto error;
@@ -1106,7 +1106,7 @@ void nxpwifi_drv_info_dump(struct nxpwifi_adapter *adapter)
1106 1106 p += adapter->if_ops.reg_dump(adapter, p);
1107 1107 }
1108 1108 p += sprintf(p, "\n=== more debug information\n");
1109 - debug_info = kzalloc_obj(*debug_info, GFP_KERNEL);
1109 + debug_info = kzalloc_obj(*debug_info);
1110 1110 if (debug_info) {
1111 1111 for (i = 0; i < adapter->priv_num; i++) {
1112 1112 if (!adapter->priv[i]->netdev)
@@ -1242,7 +1242,7 @@ void nxpwifi_init_priv_params(struct nxpwifi_private *priv,
1242 1242
1243 1243 if (GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_STA ||
1244 1244 GET_BSS_ROLE(priv) == NXPWIFI_BSS_ROLE_UAP) {
1245 - priv->hist_data = kmalloc_obj(*priv->hist_data, GFP_KERNEL);
1245 + priv->hist_data = kmalloc_obj(*priv->hist_data);
1246 1246 if (priv->hist_data)
1247 1247 nxpwifi_hist_data_reset(priv);
1248 1248 }
modified drivers/net/wireless/nxp/nxpwifi/scan.c
@@ -1341,15 +1341,14 @@ int nxpwifi_scan_networks(struct nxpwifi_private *priv,
1341 1341 adapter->scan_processing = true;
1342 1342 spin_unlock_bh(&adapter->nxpwifi_cmd_lock);
1343 1343
1344 - scan_cfg_out = kzalloc_obj(union nxpwifi_scan_cmd_config_tlv,
1345 - GFP_KERNEL);
1344 + scan_cfg_out = kzalloc_obj(union nxpwifi_scan_cmd_config_tlv);
1346 1345 if (!scan_cfg_out) {
1347 1346 ret = -ENOMEM;
1348 1347 goto done;
1349 1348 }
1350 1349
1351 1350 scan_chan_list = kzalloc_objs(struct nxpwifi_chan_scan_param_set,
1352 - NXPWIFI_USER_SCAN_CHAN_MAX, GFP_KERNEL);
1351 + NXPWIFI_USER_SCAN_CHAN_MAX);
1353 1352 if (!scan_chan_list) {
1354 1353 kfree(scan_cfg_out);
1355 1354 ret = -ENOMEM;
@@ -1471,7 +1470,7 @@ static int nxpwifi_save_hidden_ssid_channels(struct nxpwifi_private *priv,
1471 1470 int chid;
1472 1471
1473 1472 /* Allocate and fill new bss descriptor */
1474 - bss_desc = kzalloc_obj(*bss_desc, GFP_KERNEL);
1473 + bss_desc = kzalloc_obj(*bss_desc);
1475 1474 if (!bss_desc)
1476 1475 return -ENOMEM;
1477 1476
@@ -1512,7 +1511,7 @@ static int nxpwifi_update_curr_bss_params(struct nxpwifi_private *priv,
1512 1511 int ret;
1513 1512
1514 1513 /* Allocate and fill new bss descriptor */
1515 - bss_desc = kzalloc_obj(*bss_desc, GFP_KERNEL);
1514 + bss_desc = kzalloc_obj(*bss_desc);
1516 1515 if (!bss_desc)
1517 1516 return -ENOMEM;
1518 1517
@@ -1751,7 +1750,7 @@ nxpwifi_active_scan_req_for_passive_chan(struct nxpwifi_private *priv)
1751 1750 nxpwifi_dbg(adapter, INFO, "No BSS with hidden SSID found on DFS channels\n");
1752 1751 return 0;
1753 1752 }
1754 - user_scan_cfg = kzalloc_obj(*user_scan_cfg, GFP_KERNEL);
1753 + user_scan_cfg = kzalloc_obj(*user_scan_cfg);
1755 1754
1756 1755 if (!user_scan_cfg)
1757 1756 return -ENOMEM;
@@ -2258,7 +2257,7 @@ int nxpwifi_stop_bg_scan(struct nxpwifi_private *priv)
2258 2257 return 0;
2259 2258 }
2260 2259
2261 - bgscan_cfg = kzalloc_obj(*bgscan_cfg, GFP_KERNEL);
2260 + bgscan_cfg = kzalloc_obj(*bgscan_cfg);
2262 2261 if (!bgscan_cfg)
2263 2262 return -ENOMEM;
2264 2263
modified drivers/net/wireless/nxp/nxpwifi/sta_cfg.c
@@ -245,7 +245,7 @@ int nxpwifi_bss_start(struct nxpwifi_private *priv, struct cfg80211_bss *bss,
245 245 return -EINVAL;
246 246
247 247 /* Allocate and fill new bss descriptor */
248 - bss_desc = kzalloc_obj(*bss_desc, GFP_KERNEL);
248 + bss_desc = kzalloc_obj(*bss_desc);
249 249 if (!bss_desc)
250 250 return -ENOMEM;
251 251
modified drivers/net/wireless/nxp/nxpwifi/sta_cmd.c
@@ -2822,7 +2822,7 @@ nxpwifi_create_custom_regdomain(struct nxpwifi_private *priv,
2822 2822 if (WARN_ON_ONCE(num_chan > NL80211_MAX_SUPP_REG_RULES))
2823 2823 return ERR_PTR(-EINVAL);
2824 2824
2825 - regd = kzalloc_flex(*regd, reg_rules, num_chan, GFP_KERNEL);
2825 + regd = kzalloc_flex(*regd, reg_rules, num_chan);
2826 2826 if (!regd)
2827 2827 return ERR_PTR(-ENOMEM);
2828 2828
modified drivers/net/wireless/nxp/nxpwifi/uap_event.c
@@ -88,7 +88,7 @@ nxpwifi_uap_event_sta_assoc(struct nxpwifi_private *priv)
88 88 struct nxpwifi_sta_node *node;
89 89 int len, i;
90 90
91 - sinfo = kzalloc_obj(*sinfo, GFP_KERNEL);
91 + sinfo = kzalloc_obj(*sinfo);
92 92 if (!sinfo)
93 93 return -ENOMEM;
94 94
modified drivers/nvdimm/region_devs.c
@@ -1002,8 +1002,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
1002 1002 nd_region->num_lanes = ndr_desc->num_lanes;
1003 1003 if (!nd_region->num_lanes)
1004 1004 goto err_percpu;
1005 - nd_region->lane = kcalloc(nd_region->num_lanes,
1006 - sizeof(*nd_region->lane), GFP_KERNEL);
1005 + nd_region->lane = kzalloc_objs(*nd_region->lane, nd_region->num_lanes);
1007 1006 if (!nd_region->lane)
1008 1007 goto err_percpu;
1009 1008
modified drivers/nvme/host/core.c
@@ -155,8 +155,6 @@ static const struct class nvme_ns_chr_class = {
155 155 };
156 156
157 157 static void nvme_put_subsystem(struct nvme_subsystem *subsys);
158 - static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
159 - unsigned nsid);
160 158 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
161 159 struct nvme_command *cmd);
162 160 static int nvme_get_log_lsi(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page,
@@ -1612,7 +1610,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl,
1612 1610 }
1613 1611
1614 1612 if (nvme_multi_css(ctrl) && !csi_seen) {
1615 - dev_warn(ctrl->device, "Command set not reported for nsid:%d\n",
1613 + dev_warn(ctrl->device, "Command set not reported for nsid:%u\n",
1616 1614 info->nsid);
1617 1615 status = -EINVAL;
1618 1616 }
@@ -2341,14 +2339,6 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info)
2341 2339 size_t size;
2342 2340 int i, ret;
2343 2341
2344 - /*
2345 - * The FDP configuration is static for the lifetime of the namespace,
2346 - * so return immediately if we've already registered this namespace's
2347 - * streams.
2348 - */
2349 - if (head->nr_plids)
2350 - return 0;
2351 -
2352 2342 ret = nvme_get_features(ctrl, NVME_FEAT_FDP, info->endgid, NULL, 0,
2353 2343 &fdp);
2354 2344 if (ret) {
@@ -2382,8 +2372,7 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info)
2382 2372 if (!head->nr_plids)
2383 2373 goto free;
2384 2374
2385 - head->plids = kcalloc(head->nr_plids, sizeof(*head->plids),
2386 - GFP_KERNEL);
2375 + head->plids = kzalloc_objs(*head->plids, head->nr_plids);
2387 2376 if (!head->plids) {
2388 2377 dev_warn(ctrl->device,
2389 2378 "failed to allocate %u FDP placement IDs\n",
@@ -2395,6 +2384,7 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info)
2395 2384
2396 2385 for (i = 0; i < head->nr_plids; i++)
2397 2386 head->plids[i] = le16_to_cpu(ruhs->ruhsd[i].pid);
2387 + head->write_stream_granularity = min(info->runs, U32_MAX);
2398 2388 free:
2399 2389 kfree(ruhs);
2400 2390 return ret;
@@ -2442,12 +2432,6 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2442 2432 goto out;
2443 2433 }
2444 2434
2445 - if (ns->ctrl->ctratt & NVME_CTRL_ATTR_FDPS) {
2446 - ret = nvme_query_fdp_info(ns, info);
2447 - if (ret < 0)
2448 - goto out;
2449 - }
2450 -
2451 2435 if (nvme_invalid_lba_sz(le64_to_cpu(id->nsze),
2452 2436 id->lbaf[lbaf].ds - SECTOR_SHIFT, &capacity)) {
2453 2437 dev_warn_once(ns->ctrl->device,
@@ -2468,9 +2452,26 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2468 2452 if (!nvme_update_disk_info(ns, id, nvm, &lim))
2469 2453 capacity = 0;
2470 2454
2455 + /*
2456 + * A failed zone info query leaves zi zero-initialized, so skip the
2457 + * zoned limits update instead of configuring the queue from it.
2458 + * During a revalidation that keeps the zone geometry the queue was
2459 + * last validated with; on a first scan the namespace is registered
2460 + * without zoned limits, so that it is still available as a handle
2461 + * for admin commands.
2462 + */
2471 2463 if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
2472 - ns->head->ids.csi == NVME_CSI_ZNS)
2473 - nvme_update_zone_info(ns, &lim, &zi);
2464 + ns->head->ids.csi == NVME_CSI_ZNS) {
2465 + if (zi.zone_size)
2466 + nvme_update_zone_info(ns, &lim, &zi);
2467 + else
2468 + dev_warn(ns->ctrl->device,
2469 + "zone info query failed for nsid %u, %s\n",
2470 + ns->head->ns_id,
2471 + blk_queue_is_zoned(ns->disk->queue) ?
2472 + "keeping the previous zone limits" :
2473 + "not enabling zoned mode");
2474 + }
2474 2475
2475 2476 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc)
2476 2477 lim.features |= BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA;
@@ -2490,10 +2491,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
2490 2491 capacity = 0;
2491 2492
2492 2493 lim.max_write_streams = ns->head->nr_plids;
2493 - if (lim.max_write_streams)
2494 - lim.write_stream_granularity = min(info->runs, U32_MAX);
2495 - else
2496 - lim.write_stream_granularity = 0;
2494 + lim.write_stream_granularity = ns->head->write_stream_granularity;
2497 2495
2498 2496 /*
2499 2497 * Only set the DEAC bit if the device guarantees that reads from
@@ -4001,10 +3999,11 @@ static void nvme_add_ns_cdev(struct nvme_ns *ns)
4001 3999 set_bit(NVME_NS_CDEV_LIVE, &ns->flags);
4002 4000 }
4003 4001
4004 - static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
4002 + static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ns *ns,
4005 4003 struct nvme_ns_info *info)
4006 - __must_hold(&ctrl->subsys->lock)
4004 + __must_hold(&ns->ctrl->subsys->lock)
4007 4005 {
4006 + struct nvme_ctrl *ctrl = ns->ctrl;
4008 4007 struct nvme_ns_head *head;
4009 4008 size_t size = sizeof(*head);
4010 4009 int ret = -ENOMEM;
@@ -4032,6 +4031,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
4032 4031 ratelimit_state_init(&head->rs_nuse, 5 * HZ, 1);
4033 4032 ratelimit_set_flags(&head->rs_nuse, RATELIMIT_MSG_ON_RELEASE);
4034 4033 kref_init(&head->ref);
4034 + ns->head = head;
4035 4035
4036 4036 if (head->ids.csi) {
4037 4037 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects);
@@ -4040,21 +4040,30 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl,
4040 4040 } else
4041 4041 head->effects = ctrl->effects;
4042 4042
4043 + if (ctrl->ctratt & NVME_CTRL_ATTR_FDPS) {
4044 + ret = nvme_query_fdp_info(ns, info);
4045 + if (ret < 0)
4046 + goto out_cleanup_srcu;
4047 + }
4048 +
4043 4049 ret = nvme_mpath_alloc_disk(ctrl, head);
4044 4050 if (ret)
4045 - goto out_cleanup_srcu;
4051 + goto out_cleanup_fdp;
4046 4052
4047 4053 list_add_tail(&head->entry, &ctrl->subsys->nsheads);
4048 4054
4049 4055 kref_get(&ctrl->subsys->ref);
4050 4056
4051 4057 return head;
4058 + out_cleanup_fdp:
4059 + kfree(head->plids);
4052 4060 out_cleanup_srcu:
4053 4061 cleanup_srcu_struct(&head->srcu);
4054 4062 out_ida_remove:
4055 4063 ida_free(&ctrl->subsys->ns_ida, head->instance);
4056 4064 out_free_head:
4057 4065 kfree(head);
4066 + ns->head = NULL;
4058 4067 out:
4059 4068 if (ret > 0)
4060 4069 ret = blk_status_to_errno(nvme_error_status(ret));
@@ -4116,13 +4125,13 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
4116 4125 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) &&
4117 4126 info->is_shared)) {
4118 4127 dev_err(ctrl->device,
4119 - "ignoring nsid %d because of duplicate IDs\n",
4128 + "ignoring nsid %u because of duplicate IDs\n",
4120 4129 info->nsid);
4121 4130 return ret;
4122 4131 }
4123 4132
4124 4133 dev_err(ctrl->device,
4125 - "clearing duplicate IDs for nsid %d\n", info->nsid);
4134 + "clearing duplicate IDs for nsid %u\n", info->nsid);
4126 4135 dev_err(ctrl->device,
4127 4136 "use of /dev/disk/by-id/ may cause data corruption\n");
4128 4137 memset(&info->ids.nguid, 0, sizeof(info->ids.nguid));
@@ -4137,11 +4146,11 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
4137 4146 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids);
4138 4147 if (ret) {
4139 4148 dev_err(ctrl->device,
4140 - "duplicate IDs in subsystem for nsid %d\n",
4149 + "duplicate IDs in subsystem for nsid %u\n",
4141 4150 info->nsid);
4142 4151 goto out_unlock;
4143 4152 }
4144 - head = nvme_alloc_ns_head(ctrl, info);
4153 + head = nvme_alloc_ns_head(ns, info);
4145 4154 if (IS_ERR(head)) {
4146 4155 ret = PTR_ERR(head);
4147 4156 goto out_unlock;
@@ -4151,20 +4160,20 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
4151 4160 if ((!info->is_shared || !head->shared) &&
4152 4161 !list_empty(&head->list)) {
4153 4162 dev_err(ctrl->device,
4154 - "Duplicate unshared namespace %d\n",
4163 + "Duplicate unshared namespace %u\n",
4155 4164 info->nsid);
4156 4165 goto out_put_ns_head;
4157 4166 }
4158 4167 if (!nvme_ns_ids_equal(&head->ids, &info->ids)) {
4159 4168 dev_err(ctrl->device,
4160 - "IDs don't match for shared namespace %d\n",
4169 + "IDs don't match for shared namespace %u\n",
4161 4170 info->nsid);
4162 4171 goto out_put_ns_head;
4163 4172 }
4164 4173
4165 4174 if (!multipath) {
4166 4175 dev_warn(ctrl->device,
4167 - "Found shared namespace %d, but multipathing not supported.\n",
4176 + "Found shared namespace %u, but multipathing not supported.\n",
4168 4177 info->nsid);
4169 4178 dev_warn_once(ctrl->device,
4170 4179 "Shared namespace support requires core_nvme.multipath=Y.\n");
@@ -4333,6 +4342,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
4333 4342 last_path = true;
4334 4343 }
4335 4344 mutex_unlock(&ctrl->subsys->lock);
4345 +
4346 + /* guarantee not available in head->list */
4347 + synchronize_srcu(&ns->head->srcu);
4336 4348 if (last_path)
4337 4349 nvme_put_ns_head(ns->head);
4338 4350 nvme_put_ns_head(ns->head);
@@ -4410,7 +4422,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)
4410 4422
4411 4423 if (!nvme_ns_ids_equal(&ns->head->ids, &info->ids)) {
4412 4424 dev_err(ns->ctrl->device,
4413 - "identifiers changed for nsid %d\n", ns->head->ns_id);
4425 + "identifiers changed for nsid %u\n", ns->head->ns_id);
4414 4426 goto out;
4415 4427 }
4416 4428
@@ -4437,7 +4449,7 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)
4437 4449
4438 4450 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) {
4439 4451 dev_warn(ctrl->device,
4440 - "command set not reported for nsid: %d\n", nsid);
4452 + "command set not reported for nsid: %u\n", nsid);
4441 4453 return;
4442 4454 }
4443 4455
@@ -4501,15 +4513,16 @@ static void nvme_scan_ns_async(void *data, async_cookie_t cookie)
4501 4513 nvme_scan_ns(scan_info->ctrl, nsid);
4502 4514 }
4503 4515
4504 - static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
4505 - unsigned nsid)
4516 + static void nvme_remove_nsid_range(struct nvme_ctrl *ctrl, u32 start, u32 end)
4506 4517 {
4507 4518 struct nvme_ns *ns, *next;
4508 4519 LIST_HEAD(rm_list);
4509 4520
4510 4521 mutex_lock(&ctrl->namespaces_lock);
4511 4522 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
4512 - if (ns->head->ns_id > nsid) {
4523 + if (ns->head->ns_id >= end)
4524 + break;
4525 + if (ns->head->ns_id > start) {
4513 4526 list_del_rcu(&ns->list);
4514 4527 synchronize_srcu(&ctrl->srcu);
4515 4528 list_add_tail_rcu(&ns->list, &rm_list);
@@ -4559,13 +4572,14 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)
4559 4572 goto out;
4560 4573 async_schedule_domain(nvme_scan_ns_async, &scan_info,
4561 4574 &domain);
4562 - while (++prev < nsid)
4563 - nvme_ns_remove_by_nsid(ctrl, prev);
4575 + if (prev + 1 < nsid)
4576 + nvme_remove_nsid_range(ctrl, prev, nsid);
4577 + prev = max(prev + 1, nsid);
4564 4578 }
4565 4579 async_synchronize_full_domain(&domain);
4566 4580 }
4567 4581 out:
4568 - nvme_remove_invalid_namespaces(ctrl, prev);
4582 + nvme_remove_nsid_range(ctrl, prev, UINT_MAX);
4569 4583 free:
4570 4584 async_synchronize_full_domain(&domain);
4571 4585 kfree(ns_list);
@@ -4585,7 +4599,7 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl)
4585 4599 for (i = 1; i <= nn; i++)
4586 4600 nvme_scan_ns(ctrl, i);
4587 4601
4588 - nvme_remove_invalid_namespaces(ctrl, nn);
4602 + nvme_remove_nsid_range(ctrl, nn, UINT_MAX);
4589 4603 }
4590 4604
4591 4605 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl)
modified drivers/nvme/host/fabrics.c
@@ -1028,6 +1028,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
1028 1028 }
1029 1029 if (strlen(p) < 11 || strncmp(p, "DHHC-1:", 7)) {
1030 1030 pr_err("Invalid DH-CHAP secret %s\n", p);
1031 + kfree_sensitive(p);
1031 1032 ret = -EINVAL;
1032 1033 goto out;
1033 1034 }
@@ -1042,6 +1043,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
1042 1043 }
1043 1044 if (strlen(p) < 11 || strncmp(p, "DHHC-1:", 7)) {
1044 1045 pr_err("Invalid DH-CHAP secret %s\n", p);
1046 + kfree_sensitive(p);
1045 1047 ret = -EINVAL;
1046 1048 goto out;
1047 1049 }
modified drivers/nvme/host/fault_inject.c
@@ -42,9 +42,11 @@ void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
42 42 }
43 43 fault_inj->parent = parent;
44 44
45 - /* create debugfs for status code and dont_retry */
45 + /* create debugfs for opcode, status code, and dont_retry */
46 + fault_inj->opcode = 0xffff;
46 47 fault_inj->status = NVME_SC_INVALID_OPCODE;
47 48 fault_inj->dont_retry = true;
49 + debugfs_create_x16("opcode", 0600, dir, &fault_inj->opcode);
48 50 debugfs_create_x16("status", 0600, dir, &fault_inj->status);
49 51 debugfs_create_bool("dont_retry", 0600, dir, &fault_inj->dont_retry);
50 52 }
@@ -59,6 +61,7 @@ void nvme_should_fail(struct request *req)
59 61 {
60 62 struct gendisk *disk = req->q->disk;
61 63 struct nvme_fault_inject *fault_inject = NULL;
64 + struct nvme_command *cmd = nvme_req(req)->cmd;
62 65 u16 status;
63 66
64 67 if (disk) {
@@ -72,7 +75,14 @@ void nvme_should_fail(struct request *req)
72 75 fault_inject = &nvme_req(req)->ctrl->fault_inject;
73 76 }
74 77
75 - if (fault_inject && should_fail(&fault_inject->attr, 1)) {
78 + if (!fault_inject)
79 + return;
80 +
81 + if (fault_inject->opcode <= 0xff &&
82 + fault_inject->opcode != cmd->common.opcode)
83 + return;
84 +
85 + if (should_fail(&fault_inject->attr, 1)) {
76 86 /* inject status code and DNR bit */
77 87 status = fault_inject->status;
78 88 if (fault_inject->dont_retry)
modified drivers/nvme/host/fc.c
@@ -2364,9 +2364,15 @@ nvme_fc_ctrl_free(struct kref *ref)
2364 2364 struct nvme_fc_ctrl *ctrl =
2365 2365 container_of(ref, struct nvme_fc_ctrl, ref);
2366 2366 unsigned long flags;
2367 + bool owns_opts;
2367 2368
2368 - /* remove from rport list */
2369 + /*
2370 + * Presence on the rport list means nvme_fc_init_ctrl() completed,
2371 + * and with it ownership of the fabrics options passed to it. If it
2372 + * failed instead, the options still belong to nvmf_create_ctrl().
2373 + */
2369 2374 spin_lock_irqsave(&ctrl->rport->lock, flags);
2375 + owns_opts = !list_empty(&ctrl->ctrl_list);
2370 2376 list_del(&ctrl->ctrl_list);
2371 2377 spin_unlock_irqrestore(&ctrl->rport->lock, flags);
2372 2378
@@ -2376,7 +2382,7 @@ nvme_fc_ctrl_free(struct kref *ref)
2376 2382 nvme_fc_rport_put(ctrl->rport);
2377 2383
2378 2384 ida_free(&nvme_fc_ctrl_cnt, ctrl->cnum);
2379 - if (ctrl->ctrl.opts)
2385 + if (owns_opts)
2380 2386 nvmf_free_options(ctrl->ctrl.opts);
2381 2387 kfree(ctrl);
2382 2388 }
@@ -3575,14 +3581,14 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3575 3581 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
3576 3582 dev_err(ctrl->ctrl.device,
3577 3583 "NVME-FC{%d}: failed to init ctrl state\n", ctrl->cnum);
3578 - goto fail_ctrl;
3584 + goto fail_unlist;
3579 3585 }
3580 3586
3581 3587 if (!queue_delayed_work(nvme_wq, &ctrl->connect_work, 0)) {
3582 3588 dev_err(ctrl->ctrl.device,
3583 3589 "NVME-FC{%d}: failed to schedule initial connect\n",
3584 3590 ctrl->cnum);
3585 - goto fail_ctrl;
3591 + goto fail_unlist;
3586 3592 }
3587 3593
3588 3594 flush_delayed_work(&ctrl->connect_work);
@@ -3593,14 +3599,22 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3593 3599
3594 3600 return &ctrl->ctrl;
3595 3601
3602 + fail_unlist:
3603 + /*
3604 + * Leaving the list hands the options back to nvmf_create_ctrl();
3605 + * see nvme_fc_ctrl_free(). Re-init so that list_empty() there
3606 + * reports the controller as unlisted.
3607 + */
3608 + spin_lock_irqsave(&rport->lock, flags);
3609 + list_del_init(&ctrl->ctrl_list);
3610 + spin_unlock_irqrestore(&rport->lock, flags);
3611 +
3596 3612 fail_ctrl:
3597 3613 nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_DELETING);
3598 3614 cancel_work_sync(&ctrl->ioerr_work);
3599 3615 cancel_work_sync(&ctrl->ctrl.reset_work);
3600 3616 cancel_delayed_work_sync(&ctrl->connect_work);
3601 3617
3602 - ctrl->ctrl.opts = NULL;
3603 -
3604 3618 if (ctrl->ctrl.admin_tagset)
3605 3619 nvme_remove_admin_tag_set(&ctrl->ctrl);
3606 3620 /* initiate nvme ctrl ref counting teardown */
modified drivers/nvme/host/nvme.h
@@ -323,6 +323,7 @@ struct nvme_fault_inject {
323 323 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
324 324 struct fault_attr attr;
325 325 struct dentry *parent;
326 + u16 opcode;
326 327 bool dont_retry; /* DNR, do not retry */
327 328 u16 status; /* status code */
328 329 #endif
@@ -571,6 +572,7 @@ struct nvme_ns_head {
571 572
572 573 u16 nr_plids;
573 574 u16 *plids;
575 + u32 write_stream_granularity;
574 576 #ifdef CONFIG_NVME_MULTIPATH
575 577 struct bio_list requeue_list
576 578 __guarded_by(&requeue_lock);
modified drivers/nvme/host/pci.c
@@ -201,7 +201,7 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
201 201 count++;
202 202 }
203 203
204 - qlist = kcalloc(count, sizeof(*qlist), GFP_KERNEL);
204 + qlist = kzalloc_objs(*qlist, count);
205 205 if (!qlist) {
206 206 err = -ENOMEM;
207 207 goto out_free_val;
modified drivers/nvme/host/rdma.c
@@ -2036,7 +2036,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
2036 2036 struct ib_device *dev;
2037 2037 bool queue_ready = test_bit(NVME_RDMA_Q_LIVE, &queue->flags);
2038 2038 blk_status_t ret;
2039 - int err;
2039 + int err = 0;
2040 2040
2041 2041 WARN_ON_ONCE(rq->tag < 0);
2042 2042
@@ -2092,16 +2092,18 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
2092 2092 err_unmap:
2093 2093 nvme_rdma_unmap_data(queue, rq);
2094 2094 err:
2095 - if (err == -EIO)
2096 - ret = nvme_host_path_error(rq);
2097 - else if (err == -ENOMEM || err == -EAGAIN)
2098 - ret = BLK_STS_RESOURCE;
2099 - else
2100 - ret = BLK_STS_IOERR;
2101 - nvme_cleanup_cmd(rq);
2095 + if (err != -EIO) {
2096 + nvme_cleanup_cmd(rq);
2097 + if (err == -ENOMEM || err == -EAGAIN)
2098 + ret = BLK_STS_RESOURCE;
2099 + else
2100 + ret = BLK_STS_IOERR;
2101 + }
2102 2102 unmap_qe:
2103 2103 ib_dma_unmap_single(dev, req->sqe.dma, sizeof(struct nvme_command),
2104 2104 DMA_TO_DEVICE);
2105 + if (err == -EIO)
2106 + return nvme_host_path_error(rq);
2105 2107 return ret;
2106 2108 }
2107 2109
modified drivers/nvme/host/sysfs.c
@@ -166,7 +166,7 @@ static DEVICE_ATTR_RO(eui);
166 166 static ssize_t nsid_show(struct device *dev, struct device_attribute *attr,
167 167 char *buf)
168 168 {
169 - return sysfs_emit(buf, "%d\n", dev_to_ns_head(dev)->ns_id);
169 + return sysfs_emit(buf, "%u\n", dev_to_ns_head(dev)->ns_id);
170 170 }
171 171 static DEVICE_ATTR_RO(nsid);
172 172
modified drivers/nvme/host/tcp.c
@@ -413,8 +413,13 @@ static inline void nvme_tcp_queue_request(struct nvme_tcp_request *req,
413 413 * if we're the first on the send_list and we can try to send
414 414 * directly, otherwise queue io_work. Also, only do that if we
415 415 * are on the same cpu, so we don't introduce contention.
416 + *
417 + * TLS kTLS send takes ctx->tx_lock while blk_mq holds set->srcu.
418 + * lockdep reports circular locking via elevator_lock. Defer TLS
419 + * sends to the io workqueue instead of inline from this path.
416 420 */
417 421 if (queue->io_cpu == raw_smp_processor_id() &&
422 + !nvme_tcp_queue_tls(queue) &&
418 423 empty && mutex_trylock(&queue->send_mutex)) {
419 424 nvme_tcp_send_all(queue);
420 425 mutex_unlock(&queue->send_mutex);
@@ -684,6 +689,13 @@ static int nvme_tcp_handle_c2h_data(struct nvme_tcp_queue *queue,
684 689 return -ENOENT;
685 690 }
686 691
692 + if (rq_data_dir(rq) != READ) {
693 + dev_err(queue->ctrl->ctrl.device,
694 + "queue %d tag %#x unexpected data for a write\n",
695 + nvme_tcp_queue_id(queue), rq->tag);
696 + return -EPROTO;
697 + }
698 +
687 699 req = blk_mq_rq_to_pdu(rq);
688 700 if (!blk_rq_payload_bytes(rq) || !req->curr_bio || !req->data_len) {
689 701 dev_err(queue->ctrl->ctrl.device,
modified drivers/nvme/host/zns.c
@@ -48,12 +48,12 @@ int nvme_query_zone_info(struct nvme_ns *ns, unsigned lbaf,
48 48 NVME_CMD_EFFECTS_CSUPP)) {
49 49 if (test_and_clear_bit(NVME_NS_FORCE_RO, &ns->flags))
50 50 dev_warn(ns->ctrl->device,
51 - "Zone Append supported for zoned namespace:%d. Remove read-only mode\n",
51 + "Zone Append supported for zoned namespace:%u. Remove read-only mode\n",
52 52 ns->head->ns_id);
53 53 } else {
54 54 set_bit(NVME_NS_FORCE_RO, &ns->flags);
55 55 dev_warn(ns->ctrl->device,
56 - "Zone Append not supported for zoned namespace:%d. Forcing to read-only mode\n",
56 + "Zone Append not supported for zoned namespace:%u. Forcing to read-only mode\n",
57 57 ns->head->ns_id);
58 58 }
59 59
modified drivers/nvme/target/auth.c
@@ -238,6 +238,12 @@ void nvmet_auth_sq_free(struct nvmet_sq *sq)
238 238 sq->dhchap_skey = NULL;
239 239 }
240 240
241 + void nvmet_auth_sq_destroy(struct nvmet_sq *sq)
242 + {
243 + cancel_delayed_work_sync(&sq->auth_expired_work);
244 + nvmet_auth_sq_free(sq);
245 + }
246 +
241 247 void nvmet_destroy_auth(struct nvmet_ctrl *ctrl)
242 248 {
243 249 ctrl->shash_id = 0;
modified drivers/nvme/target/configfs.c
@@ -814,7 +814,7 @@ static ssize_t nvmet_ns_resv_enable_store(struct config_item *item,
814 814
815 815 mutex_lock(&ns->subsys->lock);
816 816 if (ns->enabled) {
817 - pr_err("the ns:%d is already enabled.\n", ns->nsid);
817 + pr_err("the ns:%u is already enabled.\n", ns->nsid);
818 818 mutex_unlock(&ns->subsys->lock);
819 819 return -EINVAL;
820 820 }
@@ -880,7 +880,7 @@ static struct config_group *nvmet_ns_make(struct config_group *group,
880 880 goto out;
881 881 config_group_init_type_name(&ns->group, name, &nvmet_ns_type);
882 882
883 - pr_info("adding nsid %d to subsystem %s\n", nsid, subsys->subsysnqn);
883 + pr_info("adding nsid %u to subsystem %s\n", nsid, subsys->subsysnqn);
884 884
885 885 return &ns->group;
886 886 out:
modified drivers/nvme/target/core.c
@@ -558,7 +558,7 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,
558 558 if (ret < 0)
559 559 pci_dev_put(p2p_dev);
560 560
561 - pr_info("using p2pmem on %s for nsid %d\n", pci_name(p2p_dev),
561 + pr_info("using p2pmem on %s for nsid %u\n", pci_name(p2p_dev),
562 562 ns->nsid);
563 563 }
564 564
@@ -591,6 +591,11 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
591 591 if (ns->enabled)
592 592 goto out_unlock;
593 593
594 + if (!ns->device_path) {
595 + ret = -EINVAL;
596 + goto out_unlock;
597 + }
598 +
594 599 ret = nvmet_bdev_ns_enable(ns);
595 600 if (ret == -ENOTBLK)
596 601 ret = nvmet_file_ns_enable(ns);
@@ -980,7 +985,7 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
980 985 wait_for_completion(&sq->confirm_done);
981 986 wait_for_completion(&sq->free_done);
982 987 percpu_ref_exit(&sq->ref);
983 - nvmet_auth_sq_free(sq);
988 + nvmet_auth_sq_destroy(sq);
984 989 nvmet_cq_put(sq->cq);
985 990
986 991 /*
modified drivers/nvme/target/nvmet.h
@@ -924,6 +924,7 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset);
924 924 void nvmet_auth_sq_init(struct nvmet_sq *sq);
925 925 void nvmet_destroy_auth(struct nvmet_ctrl *ctrl);
926 926 void nvmet_auth_sq_free(struct nvmet_sq *sq);
927 + void nvmet_auth_sq_destroy(struct nvmet_sq *sq);
927 928 int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id);
928 929 bool nvmet_check_auth_status(struct nvmet_req *req);
929 930 int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
@@ -950,6 +951,7 @@ static inline void nvmet_auth_sq_init(struct nvmet_sq *sq)
950 951 }
951 952 static inline void nvmet_destroy_auth(struct nvmet_ctrl *ctrl) {};
952 953 static inline void nvmet_auth_sq_free(struct nvmet_sq *sq) {};
954 + static inline void nvmet_auth_sq_destroy(struct nvmet_sq *sq) {};
953 955 static inline bool nvmet_check_auth_status(struct nvmet_req *req)
954 956 {
955 957 return true;
modified drivers/nvme/target/pr.c
@@ -145,7 +145,7 @@ static void nvmet_pr_add_resv_log(struct nvmet_ctrl *ctrl, u8 log_type,
145 145 log.nsid = cpu_to_le32(nsid);
146 146
147 147 if (!kfifo_put(&log_mgr->log_queue, log)) {
148 - pr_info("a reservation log lost, cntlid:%d, log_type:%d, nsid:%d\n",
148 + pr_info("a reservation log lost, cntlid:%d, log_type:%d, nsid:%u\n",
149 149 ctrl->cntlid, log_type, nsid);
150 150 log_mgr->lost_count++;
151 151 }
modified drivers/nvme/target/rdma.c
@@ -1631,19 +1631,13 @@ static int nvmet_rdma_queue_connect(struct rdma_cm_id *cm_id,
1631 1631 mutex_unlock(&nvmet_rdma_queue_mutex);
1632 1632 if (pending > NVMET_RDMA_BACKLOG) {
1633 1633 ret = NVME_SC_CONNECT_CTRL_BUSY;
1634 - goto put_device;
1634 + goto free_queue;
1635 1635 }
1636 1636 }
1637 1637
1638 1638 ret = nvmet_rdma_cm_accept(cm_id, queue, &event->param.conn);
1639 - if (ret) {
1640 - /*
1641 - * Don't destroy the cm_id in free path, as we implicitly
1642 - * destroy the cm_id here with non-zero ret code.
1643 - */
1644 - queue->cm_id = NULL;
1639 + if (ret)
1645 1640 goto free_queue;
1646 - }
1647 1641
1648 1642 mutex_lock(&nvmet_rdma_queue_mutex);
1649 1643 list_add_tail(&queue->queue_list, &nvmet_rdma_queue_list);
@@ -1652,6 +1646,11 @@ static int nvmet_rdma_queue_connect(struct rdma_cm_id *cm_id,
1652 1646 return 0;
1653 1647
1654 1648 free_queue:
1649 + /*
1650 + * Don't destroy the cm_id in free path, as we implicitly
1651 + * destroy the cm_id here with non-zero ret code.
1652 + */
1653 + queue->cm_id = NULL;
1655 1654 nvmet_rdma_free_queue(queue);
1656 1655 put_device:
1657 1656 kref_put(&ndev->ref, nvmet_rdma_free_dev);
modified drivers/nvme/target/tcp.c
@@ -103,6 +103,7 @@ enum nvmet_tcp_recv_state {
103 103
104 104 enum {
105 105 NVMET_TCP_F_INIT_FAILED = (1 << 0),
106 + NVMET_TCP_F_R2T_SENT = (1 << 1),
106 107 };
107 108
108 109 struct nvmet_tcp_cmd {
@@ -776,6 +777,7 @@ static int nvmet_try_send_r2t(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
776 777 return -EAGAIN;
777 778
778 779 cmd->queue->snd_cmd = NULL;
780 + cmd->flags |= NVMET_TCP_F_R2T_SENT;
779 781 return 1;
780 782 }
781 783
@@ -1009,6 +1011,12 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
1009 1011 cmd = &queue->connect;
1010 1012 }
1011 1013
1014 + if (unlikely(!(cmd->flags & NVMET_TCP_F_R2T_SENT))) {
1015 + pr_err("queue %d: unsolicited H2CData (ttag %u)\n",
1016 + queue->idx, data->ttag);
1017 + goto err_proto;
1018 + }
1019 +
1012 1020 if (le32_to_cpu(data->data_offset) != cmd->rbytes_done) {
1013 1021 pr_err("ttag %u unexpected data offset %u (expected %u)\n",
1014 1022 data->ttag, le32_to_cpu(data->data_offset),
@@ -1244,6 +1252,8 @@ recv:
1244 1252 }
1245 1253
1246 1254 queue->left = hdr->hlen - queue->offset + hdgst;
1255 + if (queue->left > sizeof(queue->pdu) - queue->offset)
1256 + return -EPROTO;
1247 1257 goto recv;
1248 1258 }
1249 1259
modified drivers/opp/core.c
@@ -348,7 +348,7 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
348 348
349 349 count = opp_table->regulator_count;
350 350
351 - uV = kmalloc_array(count, sizeof(*uV), GFP_KERNEL);
351 + uV = kmalloc_objs(*uV, count);
352 352 if (!uV)
353 353 return 0;
354 354
@@ -1505,7 +1505,7 @@ struct opp_device *_add_opp_dev(const struct device *dev,
1505 1505 {
1506 1506 struct opp_device *opp_dev;
1507 1507
1508 - opp_dev = kzalloc(sizeof(*opp_dev), GFP_KERNEL);
1508 + opp_dev = kzalloc_obj(*opp_dev);
1509 1509 if (!opp_dev)
1510 1510 return NULL;
1511 1511
modified drivers/pci/endpoint/pci-ep-msi.c
@@ -57,7 +57,7 @@ static int pci_epf_alloc_doorbell_embedded(struct pci_epf *epf, u16 num_db)
57 57 return -ENODEV;
58 58
59 59 struct pci_epc_aux_resource *res __free(kfree) =
60 - kcalloc(count, sizeof(*res), GFP_KERNEL);
60 + kzalloc_objs(*res, count);
61 61 if (!res)
62 62 return -ENOMEM;
63 63
@@ -98,7 +98,7 @@ static int pci_epf_alloc_doorbell_embedded(struct pci_epf *epf, u16 num_db)
98 98 addr = iova_base + off;
99 99 }
100 100
101 - msg = kcalloc(num_db, sizeof(*msg), GFP_KERNEL);
101 + msg = kzalloc_objs(*msg, num_db);
102 102 if (!msg) {
103 103 ret = -ENOMEM;
104 104 goto err_unmap;
modified drivers/pinctrl/qcom/pinctrl-ipq5210.c
@@ -867,6 +867,7 @@ static const struct of_device_id ipq5210_tlmm_of_match[] = {
867 867 { .compatible = "qcom,ipq5210-tlmm", },
868 868 { },
869 869 };
870 + MODULE_DEVICE_TABLE(of, ipq5210_tlmm_of_match);
870 871
871 872 static int ipq5210_tlmm_probe(struct platform_device *pdev)
872 873 {
modified drivers/pinctrl/qcom/pinctrl-nord.c
@@ -32,6 +32,7 @@
32 32 .intr_wakeup_present_bit = 6, \
33 33 .intr_wakeup_enable_bit = 7, \
34 34 .intr_target_bit = 8, \
35 + .intr_target_width = 4, \
35 36 .intr_target_kpss_val = 3, \
36 37 .intr_raw_status_bit = 4, \
37 38 .intr_polarity_bit = 1, \
@@ -570,8 +571,10 @@ enum nord_functions {
570 571 msm_mux_qup0_se5,
571 572 msm_mux_qup1_se0,
572 573 msm_mux_qup1_se1,
573 - msm_mux_qup1_se2,
574 - msm_mux_qup1_se3,
574 + msm_mux_qup1_se2_01,
575 + msm_mux_qup1_se2_23,
576 + msm_mux_qup1_se3_01,
577 + msm_mux_qup1_se3_23,
575 578 msm_mux_qup1_se4,
576 579 msm_mux_qup1_se5,
577 580 msm_mux_qup1_se6,
@@ -1152,11 +1155,19 @@ static const char *const qup1_se1_groups[] = {
1152 1155 "gpio123", "gpio124", "gpio125", "gpio126",
1153 1156 };
1154 1157
1155 - static const char *const qup1_se2_groups[] = {
1156 - "gpio127", "gpio128", "gpio129", "gpio130",
1158 + static const char *const qup1_se2_01_groups[] = {
1159 + "gpio127", "gpio128",
1157 1160 };
1158 1161
1159 - static const char *const qup1_se3_groups[] = {
1162 + static const char *const qup1_se2_23_groups[] = {
1163 + "gpio127", "gpio128",
1164 + };
1165 +
1166 + static const char *const qup1_se3_01_groups[] = {
1167 + "gpio129", "gpio130",
1168 + };
1169 +
1170 + static const char *const qup1_se3_23_groups[] = {
1160 1171 "gpio129", "gpio130",
1161 1172 };
1162 1173
@@ -1428,8 +1439,10 @@ static const struct pinfunction nord_functions[] = {
1428 1439 MSM_PIN_FUNCTION(qup0_se5),
1429 1440 MSM_PIN_FUNCTION(qup1_se0),
1430 1441 MSM_PIN_FUNCTION(qup1_se1),
1431 - MSM_PIN_FUNCTION(qup1_se2),
1432 - MSM_PIN_FUNCTION(qup1_se3),
1442 + MSM_PIN_FUNCTION(qup1_se2_01),
1443 + MSM_PIN_FUNCTION(qup1_se2_23),
1444 + MSM_PIN_FUNCTION(qup1_se3_01),
1445 + MSM_PIN_FUNCTION(qup1_se3_23),
1433 1446 MSM_PIN_FUNCTION(qup1_se4),
1434 1447 MSM_PIN_FUNCTION(qup1_se5),
1435 1448 MSM_PIN_FUNCTION(qup1_se6),
@@ -1633,13 +1646,13 @@ static const struct msm_pingroup nord_groups[] = {
1633 1646 _, _, _, _, _, _, _),
1634 1647 [126] = PINGROUP(126, qup1_se1, qup1_se0, ccu_i2c_scl, mdp1_vsync_out,
1635 1648 _, atest_usb20, ddr_pxi, _, _, _, _),
1636 - [127] = PINGROUP(127, qup1_se2, qup1_se2, _, atest_usb21, ddr_pxi,
1649 + [127] = PINGROUP(127, qup1_se2_23, qup1_se2_01, _, atest_usb21, ddr_pxi,
1637 1650 _, _, _, _, _, _),
1638 - [128] = PINGROUP(128, qup1_se2, qup1_se2, _, atest_usb20, ddr_pxi,
1651 + [128] = PINGROUP(128, qup1_se2_23, qup1_se2_01, _, atest_usb20, ddr_pxi,
1639 1652 _, _, _, _, _, _),
1640 - [129] = PINGROUP(129, qup1_se3, qup1_se3, ccu_i2c_sda, mdp1_vsync_out,
1653 + [129] = PINGROUP(129, qup1_se3_23, qup1_se3_01, ccu_i2c_sda, mdp1_vsync_out,
1641 1654 _, atest_usb21, ddr_pxi, _, _, _, _),
1642 - [130] = PINGROUP(130, qup1_se3, qup1_se3, ccu_i2c_scl, mdp1_vsync_out,
1655 + [130] = PINGROUP(130, qup1_se3_23, qup1_se3_01, ccu_i2c_scl, mdp1_vsync_out,
1643 1656 _, atest_usb20, ddr_pxi, _, _, _, _),
1644 1657 [131] = PINGROUP(131, qup1_se4, qup1_se6, ccu_i2c_sda, mdp1_vsync_out,
1645 1658 _, atest_usb21, ddr_pxi, _, _, _, _),
modified drivers/platform/x86/amd/hsmp/acpi.c
@@ -720,9 +720,8 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
720 720 return -ENODEV;
721 721 }
722 722
723 - hsmp_pdev->sock = kcalloc(hsmp_pdev->num_sockets,
724 - sizeof(*hsmp_pdev->sock),
725 - GFP_KERNEL);
723 + hsmp_pdev->sock = kzalloc_objs(*hsmp_pdev->sock,
724 + hsmp_pdev->num_sockets);
726 725 if (!hsmp_pdev->sock)
727 726 return -ENOMEM;
728 727
modified drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
@@ -96,8 +96,8 @@ int hp_alloc_enumeration_data(void)
96 96
97 97 if (!bioscfg_drv.enumeration_instances_count)
98 98 return -EINVAL;
99 - bioscfg_drv.enumeration_data = kvcalloc(bioscfg_drv.enumeration_instances_count,
100 - sizeof(*bioscfg_drv.enumeration_data), GFP_KERNEL);
99 + bioscfg_drv.enumeration_data = kvzalloc_objs(*bioscfg_drv.enumeration_data,
100 + bioscfg_drv.enumeration_instances_count);
101 101
102 102 if (!bioscfg_drv.enumeration_data) {
103 103 bioscfg_drv.enumeration_instances_count = 0;
modified drivers/platform/x86/intel/pmc/pwrm_telemetry.c
@@ -93,8 +93,7 @@ acpi_disc_t pmc_parse_telem_dsd(union acpi_object *obj,
93 93 if (header->num_entries != num_regions)
94 94 return ERR_PTR(-EINVAL);
95 95
96 - acpi_disc_t disc __free(kfree) = kmalloc_array(num_regions, sizeof(*disc),
97 - GFP_KERNEL);
96 + acpi_disc_t disc __free(kfree) = kmalloc_objs(*disc, num_regions);
98 97 if (!disc)
99 98 return ERR_PTR(-ENOMEM);
100 99
modified drivers/pmdomain/core.c
@@ -2962,7 +2962,7 @@ int of_genpd_add_child_ids(struct device_node *np,
2962 2962 return -EINVAL;
2963 2963
2964 2964 /* Allocate tracking array for error unwind (parent/child pairs) */
2965 - pairs = kmalloc_array(count * 2, sizeof(*pairs), GFP_KERNEL);
2965 + pairs = kmalloc_objs(*pairs, count * 2);
2966 2966 if (!pairs)
2967 2967 return -ENOMEM;
2968 2968
modified drivers/pmdomain/mediatek/Kconfig
@@ -43,9 +43,12 @@ config MTK_MFG_PM_DOMAIN
43 43 This driver is required for the Mali GPU to work at all on MT8196 and
44 44 MT6991.
45 45
46 + endmenu
47 +
46 48 config AIROHA_CPU_PM_DOMAIN
47 49 tristate "Airoha CPU power domain"
48 50 default ARCH_AIROHA
51 + depends on ARCH_AIROHA || COMPILE_TEST
49 52 depends on HAVE_ARM_SMCCC
50 53 depends on PM
51 54 select PM_GENERIC_DOMAINS
@@ -54,5 +57,3 @@ config AIROHA_CPU_PM_DOMAIN
54 57
55 58 CPU frequency and power is controlled by ATF with SMC command to
56 59 set performance states.
57 -
58 - endmenu
modified drivers/pmdomain/qcom/rpmhpd.c
@@ -241,13 +241,9 @@ static struct rpmhpd *eliza_rpmhpds[] = {
241 241 [RPMHPD_GFX] = &gfx,
242 242 [RPMHPD_LCX] = &lcx,
243 243 [RPMHPD_LMX] = &lmx,
244 - [RPMHPD_MMCX] = &mmcx,
245 - [RPMHPD_MMCX_AO] = &mmcx_ao,
246 244 [RPMHPD_MSS] = &mss,
247 245 [RPMHPD_MX] = &mx,
248 246 [RPMHPD_MX_AO] = &mx_ao,
249 - [RPMHPD_MXC] = &mxc,
250 - [RPMHPD_MXC_AO] = &mxc_ao,
251 247 [RPMHPD_NSP] = &nsp,
252 248 };
253 249
modified drivers/power/reset/reboot-mode.c
@@ -122,14 +122,14 @@ static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
122 122 struct mode_info *info;
123 123 int ret;
124 124
125 - priv = kzalloc_obj(*priv, GFP_KERNEL);
125 + priv = kzalloc_obj(*priv);
126 126 if (!priv)
127 127 return -ENOMEM;
128 128
129 129 INIT_LIST_HEAD(&priv->head);
130 130
131 131 list_for_each_entry(info, &reboot->head, list) {
132 - sysfs_info = kzalloc_obj(*sysfs_info, GFP_KERNEL);
132 + sysfs_info = kzalloc_obj(*sysfs_info);
133 133 if (!sysfs_info) {
134 134 ret = -ENOMEM;
135 135 goto error;
@@ -188,7 +188,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
188 188 continue;
189 189 }
190 190
191 - info = kzalloc_obj(*info, GFP_KERNEL);
191 + info = kzalloc_obj(*info);
192 192 if (!info) {
193 193 ret = -ENOMEM;
194 194 goto error;
modified drivers/power/sequencing/core.c
@@ -480,7 +480,7 @@ pwrseq_device_register(const struct pwrseq_config *config)
480 480 !config->targets[0])
481 481 return ERR_PTR(-EINVAL);
482 482
483 - pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL);
483 + pwrseq = kzalloc_obj(*pwrseq);
484 484 if (!pwrseq)
485 485 return ERR_PTR(-ENOMEM);
486 486
modified drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -291,7 +291,7 @@ static int pwrseq_pcie_m2_create_serdev_one(struct pwrseq_pcie_m2_ctx *ctx,
291 291 }
292 292 }
293 293
294 - pci_dev = kzalloc(sizeof(*pci_dev), GFP_KERNEL);
294 + pci_dev = kzalloc_obj(*pci_dev);
295 295 if (!pci_dev) {
296 296 ret = -ENOMEM;
297 297 goto err_put_ctrl;
modified drivers/power/supply/power_supply_core.c
@@ -904,7 +904,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
904 904 goto out_put_node;
905 905 }
906 906
907 - u32 *propdata __free(kfree) = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL);
907 + u32 *propdata __free(kfree) = kzalloc_objs(*propdata, proplen);
908 908 if (!propdata) {
909 909 power_supply_put_battery_info(psy, info);
910 910 err = -EINVAL;
@@ -944,7 +944,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
944 944 goto out_put_node;
945 945 }
946 946
947 - propdata = kcalloc(proplen, sizeof(*propdata), GFP_KERNEL);
947 + propdata = kzalloc_objs(*propdata, proplen);
948 948 if (!propdata) {
949 949 power_supply_put_battery_info(psy, info);
950 950 err = -ENOMEM;
@@ -1726,7 +1726,7 @@ __power_supply_register(struct device *parent,
1726 1726 pr_warn("%s: Expected proper parent device for '%s'\n",
1727 1727 __func__, desc->name);
1728 1728
1729 - psy = kzalloc(sizeof(*psy), GFP_KERNEL);
1729 + psy = kzalloc_obj(*psy);
1730 1730 if (!psy)
1731 1731 return ERR_PTR(-ENOMEM);
1732 1732
modified drivers/ptp/ptp_chardev.c
@@ -136,7 +136,7 @@ int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode)
136 136 struct timestamp_event_queue *queue;
137 137 char debugfsname[32];
138 138
139 - queue = kzalloc(sizeof(*queue), GFP_KERNEL);
139 + queue = kzalloc_obj(*queue);
140 140 if (!queue)
141 141 return -EINVAL;
142 142 queue->mask = bitmap_alloc(PTP_MAX_CHANNELS, GFP_KERNEL);
modified drivers/ras/amd/atl/core.c
@@ -190,7 +190,6 @@ static const struct x86_cpu_id amd_atl_cpuids[] = {
190 190 X86_MATCH_FEATURE(X86_FEATURE_ZEN, NULL),
191 191 { }
192 192 };
193 - MODULE_DEVICE_TABLE(x86cpu, amd_atl_cpuids);
194 193
195 194 static int __init amd_atl_init(void)
196 195 {
modified drivers/ras/amd/atl/map.c
@@ -771,9 +771,5 @@ int get_address_map(struct addr_ctx *ctx)
771 771
772 772 dump_address_map(&ctx->map);
773 773
774 - ret = validate_address_map(ctx);
775 - if (ret)
776 - return ret;
777 -
778 - return ret;
774 + return validate_address_map(ctx);
779 775 }
modified drivers/s390/block/dasd.c
@@ -87,7 +87,7 @@ struct dasd_device *dasd_alloc_device(void)
87 87 {
88 88 struct dasd_device *device;
89 89
90 - device = kzalloc_obj(struct dasd_device, GFP_KERNEL);
90 + device = kzalloc_obj(struct dasd_device);
91 91 if (!device)
92 92 return ERR_PTR(-ENOMEM);
93 93
modified drivers/s390/crypto/zcrypt_cca_key.h
@@ -219,6 +219,7 @@ static inline int zcrypt_type6_crt_key(struct ica_rsa_modexpo_crt *crt, void *p)
219 219 copy_from_user(key->key_parts + 2 * long_len + 2 * short_len,
220 220 crt->u_mult_inv, long_len))
221 221 return -EFAULT;
222 + memset(key->key_parts + 3 * long_len + 2 * short_len, 0, pad_len);
222 223 memset(key->key_parts + 3 * long_len + 2 * short_len + pad_len,
223 224 0xff, crt->inputdatalength);
224 225 pub = (struct cca_public_sec *)(key->key_parts + key_len);
modified drivers/s390/crypto/zcrypt_ccamisc.c
@@ -1158,8 +1158,21 @@ static int _ip_cprb_helper(u16 cardnr, u16 domain,
1158 1158
1159 1159 /* do not check the key here, it may be incomplete */
1160 1160
1161 - /* copy the vlsc key token back */
1161 + /*
1162 + * Copy the vlsc key token back.
1163 + * The available space in the destination (key_token) and the source
1164 + * (t) buffer is always larger as the valid range of prepparm->kb.len.
1165 + * Validate t->len by comparing it with the length information in the
1166 + * param block of the request (prepparm->kb.len)
1167 + * The value range of prepparm->kb.len has been checked above.
1168 + */
1162 1169 t = (struct cipherkeytoken *)prepparm->kb.tlv1.key_token;
1170 + if (t->len != prepparm->kb.len - 3 * sizeof(uint16_t)) {
1171 + ZCRYPT_DBF_ERR("%s reply with invalid key_token length %u\n",
1172 + __func__, t->len);
1173 + rc = -EIO;
1174 + goto out;
1175 + }
1163 1176 memcpy(key_token, t, t->len);
1164 1177 *key_token_size = t->len;
1165 1178
modified drivers/s390/net/ctcm_mpc.c
@@ -826,7 +826,7 @@ static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
826 826
827 827 fsm_deltimer(&grp->timer);
828 828
829 - if (grp->saved_xid2->xid2_flag2 == 0x40) {
829 + if (priv->xid->xid2_flag2 == 0x40) {
830 830 priv->xid->xid2_flag2 = 0x00;
831 831 if (grp->estconnfunc) {
832 832 grp->estconnfunc(grp->port_num, 1,
@@ -1636,7 +1636,6 @@ done:
1636 1636 "The XID used in the MPC protocol is not valid, "
1637 1637 "rc = %d\n", rc);
1638 1638 priv->xid->xid2_flag2 = 0x40;
1639 - grp->saved_xid2->xid2_flag2 = 0x40;
1640 1639 }
1641 1640
1642 1641 return rc;
modified drivers/scsi/fnic/fnic_debugfs.c
@@ -767,7 +767,7 @@ static int fnic_nvmef_debugfs_open(struct inode *inode, struct file *file)
767 767 struct fnic_nvmef_info *info;
768 768 int buf_size = 2 * PAGE_SIZE;
769 769
770 - info = kzalloc_obj(struct fnic_nvmef_info, GFP_KERNEL);
770 + info = kzalloc_obj(struct fnic_nvmef_info);
771 771 if (!info)
772 772 return -ENOMEM;
773 773
modified drivers/scsi/fnic/fnic_nvme.c
@@ -2216,7 +2216,7 @@ int nvfnic_add_tport(struct fnic *fnic, struct fnic_tport_s *tport,
2216 2216
2217 2217 int nvfnic_add_lport(struct fnic *fnic)
2218 2218 {
2219 - struct nvme_fc_port_info pinfo;
2219 + struct nvme_fc_port_info pinfo = {};
2220 2220 struct fnic_iport_s *iport = &fnic->iport;
2221 2221 int ret = 0;
2222 2222
modified drivers/scsi/ibmvscsi/ibmvfc-core.c
@@ -1894,7 +1894,7 @@ static void ibmvfc_log_error(struct ibmvfc_event *evt)
1894 1894 }
1895 1895
1896 1896 /**
1897 - * ibmvfc_relogin - Log back into the specified device
1897 + * ibmvfc_scsi_relogin - Log back into the specified device
1898 1898 * @sdev: scsi device struct
1899 1899 *
1900 1900 **/
@@ -4987,6 +4987,7 @@ static void ibmvfc_tgt_query_target(struct ibmvfc_target *tgt)
4987 4987 * ibmvfc_alloc_target - Allocate and initialize an ibmvfc target
4988 4988 * @vhost: ibmvfc host struct
4989 4989 * @target: Holds SCSI ID to allocate target forand the WWPN
4990 + * @protocol: protocol of the target to allocate
4990 4991 *
4991 4992 * Returns:
4992 4993 * 0 on success / other on failure
modified drivers/scsi/leapraid/leapraid_func.c
@@ -2984,8 +2984,7 @@ static void leapraid_fw_evt_put(struct leapraid_fw_evt_work *fw_work)
2984 2984
2985 2985 static struct leapraid_fw_evt_work *leapraid_alloc_fw_evt_work(void)
2986 2986 {
2987 - struct leapraid_fw_evt_work *fw_evt =
2988 - kzalloc(sizeof(*fw_evt), GFP_ATOMIC);
2987 + struct leapraid_fw_evt_work *fw_evt = kzalloc_obj(*fw_evt, GFP_ATOMIC);
2989 2988
2990 2989 if (fw_evt)
2991 2990 kref_init(&fw_evt->refcnt);
@@ -3644,8 +3643,7 @@ static void leapraid_sas_host_add(struct leapraid_adapter *adapter,
3644 3643 return;
3645 3644
3646 3645 adapter->dev_topo.card.card_phy =
3647 - kcalloc(phys_num,
3648 - sizeof(struct leapraid_card_phy), GFP_KERNEL);
3646 + kzalloc_objs(struct leapraid_card_phy, phys_num);
3649 3647 if (!adapter->dev_topo.card.card_phy)
3650 3648 return;
3651 3649
@@ -3763,8 +3761,7 @@ static int leapraid_internal_exp_add(struct leapraid_adapter *adapter,
3763 3761 }
3764 3762
3765 3763 topo_node_exp->card_phy =
3766 - kcalloc(topo_node_exp->phys_num,
3767 - sizeof(struct leapraid_card_phy), GFP_KERNEL);
3764 + kzalloc_objs(struct leapraid_card_phy, topo_node_exp->phys_num);
3768 3765 if (!topo_node_exp->card_phy) {
3769 3766 dev_err(&adapter->pdev->dev,
3770 3767 "%s: Failed to alloc expander phy array, count=%u\n",
@@ -4352,7 +4349,7 @@ static void leapraid_sas_volume_add(
4352 4349 return;
4353 4350 }
4354 4351
4355 - raid_volume = kzalloc(sizeof(*raid_volume), GFP_KERNEL);
4352 + raid_volume = kzalloc_obj(*raid_volume);
4356 4353 if (!raid_volume)
4357 4354 return;
4358 4355
@@ -6090,17 +6087,15 @@ static void leapraid_update_card_port_after_reset(
6090 6087
6091 6088 if (!adapter->dev_topo.card.card_phy) {
6092 6089 adapter->dev_topo.card.card_phy =
6093 - kcalloc(nr_phys, sizeof(struct leapraid_card_phy),
6094 - GFP_KERNEL);
6090 + kzalloc_objs(struct leapraid_card_phy, nr_phys);
6095 6091 if (!adapter->dev_topo.card.card_phy)
6096 6092 return;
6097 6093 }
6098 6094
6099 6095 adapter->dev_topo.card.phys_num = nr_phys;
6100 6096
6101 - new_card_port_table = kcalloc(adapter->dev_topo.card.phys_num,
6102 - sizeof(struct leapraid_card_port),
6103 - GFP_KERNEL);
6097 + new_card_port_table = kzalloc_objs(struct leapraid_card_port,
6098 + adapter->dev_topo.card.phys_num);
6104 6099 if (!new_card_port_table)
6105 6100 return;
6106 6101
@@ -7224,8 +7219,8 @@ static int leapraid_set_legacy_int(struct leapraid_adapter *adapter)
7224 7219 adapter->notification_desc.iopoll_qdex,
7225 7220 adapter->notification_desc.iopoll_qcnt);
7226 7221 adapter->notification_desc.int_rqs =
7227 - kcalloc(adapter->notification_desc.iopoll_qdex,
7228 - sizeof(struct leapraid_int_rq), GFP_KERNEL);
7222 + kzalloc_objs(struct leapraid_int_rq,
7223 + adapter->notification_desc.iopoll_qdex);
7229 7224 if (!adapter->notification_desc.int_rqs)
7230 7225 return -ENOMEM;
7231 7226
@@ -7268,9 +7263,8 @@ static int leapraid_set_msix(struct leapraid_adapter *adapter)
7268 7263 }
7269 7264 if (iopoll_qcnt) {
7270 7265 adapter->notification_desc.blk_mq_poll_rqs =
7271 - kcalloc(iopoll_qcnt,
7272 - sizeof(struct leapraid_blk_mq_poll_rq),
7273 - GFP_KERNEL);
7266 + kzalloc_objs(struct leapraid_blk_mq_poll_rq,
7267 + iopoll_qcnt);
7274 7268 if (!adapter->notification_desc.blk_mq_poll_rqs)
7275 7269 return -ENOMEM;
7276 7270 adapter->adapter_attr.rq_cnt =
@@ -7289,8 +7283,8 @@ static int leapraid_set_msix(struct leapraid_adapter *adapter)
7289 7283 adapter->notification_desc.iopoll_qcnt);
7290 7284
7291 7285 adapter->notification_desc.int_rqs =
7292 - kcalloc(adapter->notification_desc.iopoll_qdex,
7293 - sizeof(struct leapraid_int_rq), GFP_KERNEL);
7286 + kzalloc_objs(struct leapraid_int_rq,
7287 + adapter->notification_desc.iopoll_qdex);
7294 7288 if (!adapter->notification_desc.int_rqs)
7295 7289 return -ENOMEM;
7296 7290
@@ -7365,9 +7359,8 @@ static int leapraid_set_msi(struct leapraid_adapter *adapter)
7365 7359
7366 7360 if (iopoll_qcnt) {
7367 7361 adapter->notification_desc.blk_mq_poll_rqs =
7368 - kcalloc(iopoll_qcnt,
7369 - sizeof(struct leapraid_blk_mq_poll_rq),
7370 - GFP_KERNEL);
7362 + kzalloc_objs(struct leapraid_blk_mq_poll_rq,
7363 + iopoll_qcnt);
7371 7364 if (!adapter->notification_desc.blk_mq_poll_rqs)
7372 7365 return -ENOMEM;
7373 7366
@@ -7404,9 +7397,8 @@ static int leapraid_set_msi(struct leapraid_adapter *adapter)
7404 7397 adapter->notification_desc.iopoll_qcnt);
7405 7398
7406 7399 adapter->notification_desc.int_rqs =
7407 - kcalloc(adapter->notification_desc.iopoll_qdex,
7408 - sizeof(struct leapraid_int_rq),
7409 - GFP_KERNEL);
7400 + kzalloc_objs(struct leapraid_int_rq,
7401 + adapter->notification_desc.iopoll_qdex);
7410 7402 if (!adapter->notification_desc.int_rqs)
7411 7403 return -ENOMEM;
7412 7404
@@ -7958,18 +7950,16 @@ try_again:
7958 7950 DIV_ROUND_UP(adapter->adapter_attr.rq_cnt,
7959 7951 LEAPRAID_REP_DESC_CHUNK_SIZE);
7960 7952 adapter->mem_desc.rep_desc_seg_maint =
7961 - kcalloc(adapter->adapter_attr.rep_desc_q_seg_cnt,
7962 - sizeof(struct leapraid_rep_desc_seg_maint),
7963 - GFP_KERNEL);
7953 + kzalloc_objs(struct leapraid_rep_desc_seg_maint,
7954 + adapter->adapter_attr.rep_desc_q_seg_cnt);
7964 7955 if (!adapter->mem_desc.rep_desc_seg_maint)
7965 7956 return -ENOMEM;
7966 7957
7967 7958 rep_desc_q_cnt_allocated = 0;
7968 7959 for (i = 0; i < adapter->adapter_attr.rep_desc_q_seg_cnt; i++) {
7969 7960 adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_maint =
7970 - kcalloc(LEAPRAID_REP_DESC_CHUNK_SIZE,
7971 - sizeof(struct leapraid_rep_desc_maint),
7972 - GFP_KERNEL);
7961 + kzalloc_objs(struct leapraid_rep_desc_maint,
7962 + LEAPRAID_REP_DESC_CHUNK_SIZE);
7973 7963 if (!adapter->mem_desc.rep_desc_seg_maint[i].rep_desc_maint)
7974 7964 return -ENOMEM;
7975 7965
modified drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1973,12 +1973,23 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev,
1973 1973 {
1974 1974 struct megasas_instance *instance;
1975 1975 u32 mr_nvme_pg_size;
1976 + u64 max_prp_io;
1976 1977
1977 1978 instance = (struct megasas_instance *)sdev->host->hostdata;
1978 1979 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1979 1980 MR_DEFAULT_NVME_PAGE_SIZE);
1980 1981
1981 - lim->max_hw_sectors = max_io_size / 512;
1982 + /*
1983 + * megasas_make_prp_nvme() builds the PRP list in cmd->sg_frame without
1984 + * bounding it against that buffer, and spends one entry per page of
1985 + * it on the chain pointer. Cap the transfer at what the buffer holds,
1986 + * less one page for lists that start off a page boundary.
1987 + */
1988 + max_prp_io = (u64)((instance->max_chain_frame_sz / sizeof(u64)) -
1989 + (instance->max_chain_frame_sz / mr_nvme_pg_size) - 1) *
1990 + mr_nvme_pg_size;
1991 +
1992 + lim->max_hw_sectors = min_t(u64, max_io_size, max_prp_io) >> SECTOR_SHIFT;
1982 1993 lim->virt_boundary_mask = mr_nvme_pg_size - 1;
1983 1994 }
1984 1995
modified drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -1094,10 +1094,13 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1094 1094 {
1095 1095 struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
1096 1096 struct mpi3mr_stgt_priv_data *tgt_priv;
1097 + struct scsi_target *starget;
1098 + unsigned long flags;
1097 1099
1098 1100 dprint_reset(mrioc, "refresh target devices: check for removals\n");
1099 1101 list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
1100 1102 list) {
1103 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1101 1104 if (((tgtdev->dev_handle == MPI3MR_INVALID_DEV_HANDLE) ||
1102 1105 tgtdev->is_hidden) &&
1103 1106 tgtdev->host_exposed && tgtdev->starget &&
@@ -1106,6 +1109,7 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1106 1109 tgt_priv->dev_removed = 1;
1107 1110 atomic_set(&tgt_priv->block_io, 0);
1108 1111 }
1112 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1109 1113 }
1110 1114
1111 1115 list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
@@ -1127,15 +1131,25 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1127 1131 tgtdev = NULL;
1128 1132 list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) {
1129 1133 if ((tgtdev->dev_handle != MPI3MR_INVALID_DEV_HANDLE) &&
1130 - !tgtdev->is_hidden) {
1131 - if (!tgtdev->host_exposed)
1134 + !tgtdev->is_hidden) {
1135 + if (!tgtdev->host_exposed) {
1132 1136 mpi3mr_report_tgtdev_to_host(mrioc,
1133 - tgtdev->perst_id);
1134 - else if (tgtdev->starget)
1135 - starget_for_each_device(tgtdev->starget,
1136 - (void *)tgtdev, mpi3mr_update_sdev);
1137 - }
1137 + tgtdev->perst_id);
1138 + continue;
1139 + }
1140 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1141 + starget = tgtdev->starget;
1142 + if (starget)
1143 + get_device(&starget->dev);
1144 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1145 + if (starget) {
1146 + starget_for_each_device(starget, (void *)tgtdev,
1147 + mpi3mr_update_sdev);
1148 + put_device(&starget->dev);
1149 + }
1150 + }
1138 1151 }
1152 + dprint_reset(mrioc, "refresh target devices: done\n");
1139 1153 }
1140 1154
1141 1155 /**
@@ -1515,6 +1529,8 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
1515 1529 struct mpi3_device_page0 *dev_pg0)
1516 1530 {
1517 1531 struct mpi3mr_tgt_dev *tgtdev = NULL;
1532 + struct scsi_target *starget;
1533 + unsigned long flags;
1518 1534 u16 dev_handle = 0, perst_id = 0;
1519 1535
1520 1536 perst_id = le16_to_cpu(dev_pg0->persistent_id);
@@ -1535,9 +1551,18 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
1535 1551 mpi3mr_report_tgtdev_to_host(mrioc, perst_id);
1536 1552 if (tgtdev->is_hidden && tgtdev->host_exposed)
1537 1553 mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
1538 - if (!tgtdev->is_hidden && tgtdev->host_exposed && tgtdev->starget)
1539 - starget_for_each_device(tgtdev->starget, (void *)tgtdev,
1540 - mpi3mr_update_sdev);
1554 + if (!tgtdev->is_hidden && tgtdev->host_exposed) {
1555 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1556 + starget = tgtdev->starget;
1557 + if (starget)
1558 + get_device(&starget->dev);
1559 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1560 + if (starget) {
1561 + starget_for_each_device(starget, (void *)tgtdev,
1562 + mpi3mr_update_sdev);
1563 + put_device(&starget->dev);
1564 + }
1565 + }
1541 1566 out:
1542 1567 if (tgtdev)
1543 1568 mpi3mr_tgtdev_put(tgtdev);
modified drivers/scsi/mpi3mr/mpi3mr_transport.c
@@ -1428,9 +1428,15 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
1428 1428 }
1429 1429
1430 1430 port = sas_port_alloc_num(mr_sas_node->parent_dev);
1431 + if (!port) {
1432 + ioc_err(mrioc, "failure at %s:%d/%s()!\n",
1433 + __FILE__, __LINE__, __func__);
1434 + goto out_fail;
1435 + }
1431 1436 if ((sas_port_add(port))) {
1432 1437 ioc_err(mrioc, "failure at %s:%d/%s()!\n",
1433 1438 __FILE__, __LINE__, __func__);
1439 + sas_port_free(port);
1434 1440 goto out_fail;
1435 1441 }
1436 1442
@@ -1501,6 +1507,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
1501 1507 list_for_each_entry_safe(mr_sas_phy, next, &mr_sas_port->phy_list,
1502 1508 port_siblings)
1503 1509 list_del(&mr_sas_phy->port_siblings);
1510 + if (tgtdev)
1511 + mpi3mr_tgtdev_put(tgtdev);
1504 1512 kfree(mr_sas_port);
1505 1513 return NULL;
1506 1514 }
modified drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3238,7 +3238,10 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
3238 3238 * corresponding to high iops queues.
3239 3239 */
3240 3240 if (ioc->high_iops_queues) {
3241 - mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev));
3241 + int node = dev_to_node(&ioc->pdev->dev);
3242 +
3243 + mask = (node == NUMA_NO_NODE) ?
3244 + cpu_online_mask : cpumask_of_node(node);
3242 3245 for (index = 0; index < ioc->high_iops_queues;
3243 3246 index++) {
3244 3247 irq = pci_irq_vector(ioc->pdev, index);
modified drivers/scsi/pm8001/pm8001_init.c
@@ -1029,8 +1029,8 @@ static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
1029 1029 &(pm8001_ha->irq_vector[i]));
1030 1030 if (rc) {
1031 1031 for (j = 0; j < i; j++) {
1032 - free_irq(pci_irq_vector(pm8001_ha->pdev, i),
1033 - &(pm8001_ha->irq_vector[i]));
1032 + free_irq(pci_irq_vector(pm8001_ha->pdev, j),
1033 + &pm8001_ha->irq_vector[j]);
1034 1034 }
1035 1035 pci_free_irq_vectors(pm8001_ha->pdev);
1036 1036 break;
modified drivers/scsi/scsi_bsg.c
@@ -18,6 +18,7 @@ struct scsi_bsg_uring_cmd_pdu {
18 18 struct bio *bio; /* mapped user buffer, unmap in task work */
19 19 struct request *req; /* block request, freed in task work */
20 20 u64 response_addr; /* user space response buffer address */
21 + u32 max_response_len; /* user response buffer size */
21 22 };
22 23 static_assert(sizeof(struct scsi_bsg_uring_cmd_pdu) <= sizeof_field(struct io_uring_cmd, pdu));
23 24
@@ -45,8 +46,8 @@ static void scsi_bsg_uring_task_cb(struct io_tw_req tw_req, io_tw_token_t tw)
45 46 if (scsi_status_is_check_condition(scmd->result)) {
46 47 driver_status = DRIVER_SENSE;
47 48 if (pdu->response_addr)
48 - sense_len_wr = min_t(u8, scmd->sense_len,
49 - SCSI_SENSE_BUFFERSIZE);
49 + sense_len_wr = min_t(unsigned int, pdu->max_response_len,
50 + scmd->sense_len);
50 51 }
51 52
52 53 if (sense_len_wr) {
@@ -76,12 +77,10 @@ static enum rq_end_io_ret scsi_bsg_uring_cmd_done(struct request *req,
76 77
77 78 static int scsi_bsg_map_user_buffer(struct request *req,
78 79 struct io_uring_cmd *ioucmd,
79 - unsigned int issue_flags, gfp_t gfp_mask)
80 + unsigned int issue_flags, gfp_t gfp_mask,
81 + bool is_write, u64 buf_addr,
82 + unsigned long buf_len)
80 83 {
81 - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
82 - bool is_write = cmd->dout_xfer_len > 0;
83 - u64 buf_addr = is_write ? cmd->dout_xferp : cmd->din_xferp;
84 - unsigned long buf_len = is_write ? cmd->dout_xfer_len : cmd->din_xfer_len;
85 84 struct iov_iter iter;
86 85 int ret;
87 86
@@ -104,21 +103,28 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
104 103 unsigned int issue_flags, bool open_for_write)
105 104 {
106 105 struct scsi_bsg_uring_cmd_pdu *pdu = scsi_bsg_uring_cmd_pdu(ioucmd);
107 - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
106 + const struct bsg_uring_cmd *cmd =
107 + io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
108 108 struct scsi_cmnd *scmd;
109 109 struct request *req;
110 110 blk_mq_req_flags_t blk_flags = 0;
111 111 gfp_t gfp_mask = GFP_KERNEL;
112 + u64 request = READ_ONCE(cmd->request);
113 + u32 request_len = READ_ONCE(cmd->request_len);
114 + u64 dout_xferp = READ_ONCE(cmd->dout_xferp);
115 + u32 dout_xfer_len = READ_ONCE(cmd->dout_xfer_len);
116 + u64 din_xferp = READ_ONCE(cmd->din_xferp);
117 + u32 din_xfer_len = READ_ONCE(cmd->din_xfer_len);
112 118 int ret;
113 119
114 120 if (cmd->protocol != BSG_PROTOCOL_SCSI ||
115 121 cmd->subprotocol != BSG_SUB_PROTOCOL_SCSI_CMD)
116 122 return -EINVAL;
117 123
118 - if (!cmd->request || cmd->request_len == 0)
124 + if (!request || request_len == 0)
119 125 return -EINVAL;
120 126
121 - if (cmd->dout_xfer_len && cmd->din_xfer_len) {
127 + if (dout_xfer_len && din_xfer_len) {
122 128 pr_warn_once("BIDI support in bsg has been removed.\n");
123 129 return -EOPNOTSUPP;
124 130 }
@@ -131,20 +137,20 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
131 137 gfp_mask = GFP_NOWAIT;
132 138 }
133 139
134 - req = scsi_alloc_request(q, cmd->dout_xfer_len ?
140 + req = scsi_alloc_request(q, dout_xfer_len ?
135 141 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, blk_flags);
136 142 if (IS_ERR(req))
137 143 return PTR_ERR(req);
138 144
139 145 scmd = blk_mq_rq_to_pdu(req);
140 - if (cmd->request_len > sizeof(scmd->cmnd)) {
146 + if (request_len > sizeof(scmd->cmnd)) {
141 147 ret = -EINVAL;
142 148 goto out_free_req;
143 149 }
144 - scmd->cmd_len = cmd->request_len;
150 + scmd->cmd_len = request_len;
145 151 scmd->allowed = SG_DEFAULT_RETRIES;
146 152
147 - if (copy_from_user(scmd->cmnd, uptr64(cmd->request), cmd->request_len)) {
153 + if (copy_from_user(scmd->cmnd, uptr64(request), request_len)) {
148 154 ret = -EFAULT;
149 155 goto out_free_req;
150 156 }
@@ -155,11 +161,16 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
155 161 }
156 162
157 163 pdu->response_addr = cmd->response;
158 - scmd->sense_len = cmd->max_response_len ?
159 - min(cmd->max_response_len, SCSI_SENSE_BUFFERSIZE) : SCSI_SENSE_BUFFERSIZE;
164 + pdu->max_response_len = cmd->max_response_len;
160 165
161 - if (cmd->dout_xfer_len || cmd->din_xfer_len) {
162 - ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags, gfp_mask);
166 + if (dout_xfer_len || din_xfer_len) {
167 + bool is_write = dout_xfer_len > 0;
168 + u64 buf_addr = is_write ? dout_xferp : din_xferp;
169 + unsigned long buf_len = is_write ? dout_xfer_len : din_xfer_len;
170 +
171 + ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags,
172 + gfp_mask, is_write, buf_addr,
173 + buf_len);
163 174 if (ret)
164 175 goto out_free_req;
165 176 pdu->bio = req->bio;
modified drivers/scsi/scsi_scan.c
@@ -158,7 +158,7 @@ int scsi_complete_async_scans(void)
158 158 * sleep a little. Even if we never get memory, the async
159 159 * scans will finish eventually.
160 160 */
161 - data = kmalloc(sizeof(*data), GFP_KERNEL);
161 + data = kmalloc_obj(*data);
162 162 if (!data)
163 163 msleep(1);
164 164 } while (!data);
modified drivers/soc/bcm/brcmstb/common.c
@@ -65,7 +65,7 @@ static int __init brcmstb_soc_device_init(void)
65 65 goto out_put_node;
66 66 }
67 67
68 - soc_info = kzalloc(sizeof(*soc_info), GFP_KERNEL);
68 + soc_info = kzalloc_obj(*soc_info);
69 69 if (!soc_info) {
70 70 ret = -ENOMEM;
71 71 goto out_unmap;
modified drivers/spi/spi-offload.c
@@ -434,7 +434,7 @@ int devm_spi_offload_trigger_register(struct device *dev,
434 434 if (!info->fwnode || !info->ops || !info->ops->match)
435 435 return -EINVAL;
436 436
437 - trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
437 + trigger = kzalloc_obj(*trigger);
438 438 if (!trigger)
439 439 return -ENOMEM;
440 440
modified drivers/staging/fbtft/fbtft-core.c
@@ -298,14 +298,15 @@ static void fbtft_mkdirty(struct fb_info *info, int y, int height)
298 298 {
299 299 struct fbtft_par *par = info->par;
300 300 struct fb_deferred_io *fbdefio = info->fbdefio;
301 + unsigned long flags;
301 302
302 303 /* Mark display lines/area as dirty */
303 - spin_lock(&par->dirty_lock);
304 + spin_lock_irqsave(&par->dirty_lock, flags);
304 305 if (y < par->dirty_lines_start)
305 306 par->dirty_lines_start = y;
306 307 if (y + height - 1 > par->dirty_lines_end)
307 308 par->dirty_lines_end = y + height - 1;
308 - spin_unlock(&par->dirty_lock);
309 + spin_unlock_irqrestore(&par->dirty_lock, flags);
309 310
310 311 /* Schedule deferred_io to update display (no-op if already on queue)*/
311 312 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
@@ -318,13 +319,13 @@ static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagereflis
318 319 struct fb_deferred_io_pageref *pageref;
319 320 unsigned int y_low = 0, y_high = 0;
320 321
321 - spin_lock(&par->dirty_lock);
322 + spin_lock_irq(&par->dirty_lock);
322 323 dirty_lines_start = par->dirty_lines_start;
323 324 dirty_lines_end = par->dirty_lines_end;
324 325 /* set display line markers as clean */
325 326 par->dirty_lines_start = par->info->var.yres - 1;
326 327 par->dirty_lines_end = 0;
327 - spin_unlock(&par->dirty_lock);
328 + spin_unlock_irq(&par->dirty_lock);
328 329
329 330 /* Mark display lines as dirty */
330 331 list_for_each_entry(pageref, pagereflist, list) {
modified drivers/staging/greybus/raw.c
@@ -178,7 +178,7 @@ static int gb_raw_probe(struct gb_bundle *bundle,
178 178 if (minor < 0)
179 179 return minor;
180 180
181 - raw = kzalloc_obj(*raw, GFP_KERNEL);
181 + raw = kzalloc_obj(*raw);
182 182 if (!raw) {
183 183 ida_free(&minors, minor);
184 184 return -ENOMEM;
modified drivers/staging/media/atomisp/pci/sh_css.c
@@ -5820,36 +5820,31 @@ static int ia_css_pipe_create_cas_scaler_desc_single_output(
5820 5820 }
5821 5821
5822 5822 descr->in_info = kmalloc_objs(*descr->in_info,
5823 - descr->num_stage,
5824 - GFP_KERNEL);
5823 + descr->num_stage);
5825 5824 if (!descr->in_info) {
5826 5825 err = -ENOMEM;
5827 5826 goto ERR;
5828 5827 }
5829 5828 descr->internal_out_info = kmalloc_objs(*descr->internal_out_info,
5830 - descr->num_stage,
5831 - GFP_KERNEL);
5829 + descr->num_stage);
5832 5830 if (!descr->internal_out_info) {
5833 5831 err = -ENOMEM;
5834 5832 goto ERR;
5835 5833 }
5836 5834 descr->out_info = kmalloc_objs(*descr->out_info,
5837 - descr->num_stage,
5838 - GFP_KERNEL);
5835 + descr->num_stage);
5839 5836 if (!descr->out_info) {
5840 5837 err = -ENOMEM;
5841 5838 goto ERR;
5842 5839 }
5843 5840 descr->vf_info = kmalloc_objs(*descr->vf_info,
5844 - descr->num_stage,
5845 - GFP_KERNEL);
5841 + descr->num_stage);
5846 5842 if (!descr->vf_info) {
5847 5843 err = -ENOMEM;
5848 5844 goto ERR;
5849 5845 }
5850 5846 descr->is_output_stage = kmalloc_objs(*descr->is_output_stage,
5851 - descr->num_stage,
5852 - GFP_KERNEL);
5847 + descr->num_stage);
5853 5848 if (!descr->is_output_stage) {
5854 5849 err = -ENOMEM;
5855 5850 goto ERR;
@@ -5970,36 +5965,31 @@ ia_css_pipe_create_cas_scaler_desc(struct ia_css_pipe *pipe,
5970 5965 descr->num_stage = num_stages;
5971 5966
5972 5967 descr->in_info = kmalloc_objs(*descr->in_info,
5973 - descr->num_stage,
5974 - GFP_KERNEL);
5968 + descr->num_stage);
5975 5969 if (!descr->in_info) {
5976 5970 err = -ENOMEM;
5977 5971 goto ERR;
5978 5972 }
5979 5973 descr->internal_out_info = kmalloc_objs(*descr->internal_out_info,
5980 - descr->num_stage,
5981 - GFP_KERNEL);
5974 + descr->num_stage);
5982 5975 if (!descr->internal_out_info) {
5983 5976 err = -ENOMEM;
5984 5977 goto ERR;
5985 5978 }
5986 5979 descr->out_info = kmalloc_objs(*descr->out_info,
5987 - descr->num_stage,
5988 - GFP_KERNEL);
5980 + descr->num_stage);
5989 5981 if (!descr->out_info) {
5990 5982 err = -ENOMEM;
5991 5983 goto ERR;
5992 5984 }
5993 5985 descr->vf_info = kmalloc_objs(*descr->vf_info,
5994 - descr->num_stage,
5995 - GFP_KERNEL);
5986 + descr->num_stage);
5996 5987 if (!descr->vf_info) {
5997 5988 err = -ENOMEM;
5998 5989 goto ERR;
5999 5990 }
6000 5991 descr->is_output_stage = kmalloc_objs(*descr->is_output_stage,
6001 - descr->num_stage,
6002 - GFP_KERNEL);
5992 + descr->num_stage);
6003 5993 if (!descr->is_output_stage) {
6004 5994 err = -ENOMEM;
6005 5995 goto ERR;
modified drivers/staging/media/atomisp/pci/sh_css_firmware.c
@@ -254,8 +254,8 @@ sh_css_load_firmware(struct device *dev, const char *fw_data,
254 254 /* Only allocate memory for ISP blob info */
255 255 if (sh_css_num_binaries > NUM_OF_SPS) {
256 256 sh_css_blob_info =
257 - kmalloc_array(sh_css_num_binaries - NUM_OF_SPS,
258 - sizeof(*sh_css_blob_info), GFP_KERNEL);
257 + kmalloc_objs(*sh_css_blob_info,
258 + sh_css_num_binaries - NUM_OF_SPS);
259 259 if (!sh_css_blob_info)
260 260 return -ENOMEM;
261 261 } else {
modified drivers/staging/rtl8723bs/core/rtw_ieee80211.c
@@ -741,6 +741,10 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att
741 741 u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
742 742 u16 attr_len = attr_data_len + 4;
743 743
744 + /* Reject attributes whose claimed length runs past the IE */
745 + if (attr_ptr + attr_len > wps_ie + wps_ielen)
746 + break;
747 +
744 748 if (attr_id == target_attr_id) {
745 749 target_attr_ptr = attr_ptr;
746 750
@@ -1149,6 +1153,9 @@ int rtw_action_frame_parse(const u8 *frame, u32 frame_len, u8 *category, u8 *act
1149 1153 u8 c;
1150 1154 u8 a = ACT_PUBLIC_MAX;
1151 1155
1156 + if (frame_len < sizeof(struct ieee80211_hdr_3addr) + 2)
1157 + return false;
1158 +
1152 1159 fc = le16_to_cpu(((struct ieee80211_hdr_3addr *)frame)->frame_control);
1153 1160
1154 1161 if ((fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) !=
modified drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -1975,6 +1975,9 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
1975 1975 break;
1976 1976 }
1977 1977
1978 + if (i + 1 >= in_len)
1979 + break;
1980 +
1978 1981 i += (in_ie[i + 1] + 2); /* to the next IE element */
1979 1982 }
1980 1983
modified drivers/staging/sm750fb/sm750.c
@@ -252,7 +252,7 @@ static void lynxfb_ops_imageblit(struct fb_info *info,
252 252 spin_lock(&sm750_dev->slock);
253 253
254 254 sm750_dev->accel.de_imageblit(&sm750_dev->accel,
255 - image->data, image->width >> 3, 0,
255 + image->data, 0,
256 256 base, pitch, bpp,
257 257 image->dx, image->dy,
258 258 image->width, image->height,
modified drivers/staging/sm750fb/sm750.h
@@ -64,7 +64,7 @@ struct lynx_accel {
64 64 u32 rop2);
65 65
66 66 int (*de_imageblit)(struct lynx_accel *accel, const char *p_srcbuf,
67 - u32 src_delta, u32 start_bit, u32 d_base, u32 d_pitch,
67 + u32 start_bit, u32 d_base, u32 d_pitch,
68 68 u32 byte_per_pixel, u32 dx, u32 dy, u32 width,
69 69 u32 height, u32 f_color, u32 b_color, u32 rop2);
70 70
modified drivers/staging/sm750fb/sm750_accel.c
@@ -288,8 +288,6 @@ static unsigned int de_get_transparency(struct lynx_accel *accel)
288 288 * sm750_hw_imageblit
289 289 * @accel: Acceleration device data
290 290 * @src_buf: pointer to start of source buffer in system memory
291 - * @src_delta: Pitch value (in bytes) of the source buffer, +ive means top down
292 - * and -ive mean button up
293 291 * @start_bit: Mono data can start at any bit in a byte, this value should be
294 292 * 0 to 7
295 293 * @dest_base: Address of destination: offset in frame buffer
@@ -304,7 +302,7 @@ static unsigned int de_get_transparency(struct lynx_accel *accel)
304 302 * @rop2: ROP value
305 303 */
306 304 int sm750_hw_imageblit(struct lynx_accel *accel, const char *src_buf,
307 - u32 src_delta, u32 start_bit, u32 dest_base, u32 dest_pitch,
305 + u32 start_bit, u32 dest_base, u32 dest_pitch,
308 306 u32 byte_per_pixel, u32 dx, u32 dy, u32 width,
309 307 u32 height, u32 fg_color, u32 bg_color, u32 rop2)
310 308 {
@@ -395,7 +393,7 @@ int sm750_hw_imageblit(struct lynx_accel *accel, const char *src_buf,
395 393 write_dp_port(accel, *(unsigned int *)remain);
396 394 }
397 395
398 - src_buf += src_delta;
396 + src_buf += bytes_per_scan;
399 397 }
400 398
401 399 return 0;
modified drivers/staging/sm750fb/sm750_accel.h
@@ -220,8 +220,6 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
220 220 /**
221 221 * sm750_hw_imageblit
222 222 * @src_buf: pointer to start of source buffer in system memory
223 - * @src_delta: Pitch value (in bytes) of the source buffer, +ive means top down
224 - *>----- and -ive mean button up
225 223 * @start_bit: Mono data can start at any bit in a byte, this value should be
226 224 *>----- 0 to 7
227 225 * @dest_base: Address of destination: offset in frame buffer
@@ -236,7 +234,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel,
236 234 * @rop2: ROP value
237 235 */
238 236 int sm750_hw_imageblit(struct lynx_accel *accel, const char *src_buf,
239 - u32 src_delta, u32 start_bit, u32 dest_base, u32 dest_pitch,
237 + u32 start_bit, u32 dest_base, u32 dest_pitch,
240 238 u32 byte_per_pixel, u32 dx, u32 dy, u32 width,
241 239 u32 height, u32 fg_color, u32 bg_color, u32 rop2);
242 240
modified drivers/target/iscsi/iscsi_target.c
@@ -1533,8 +1533,10 @@ __iscsit_check_dataout_hdr(struct iscsit_conn *conn, void *buf,
1533 1533 */
1534 1534 if (se_cmd->transport_state & CMD_T_ABORTED) {
1535 1535 if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
1536 - --cmd->outstanding_r2ts < 1)
1536 + --cmd->outstanding_r2ts < 1) {
1537 1537 iscsit_stop_dataout_timer(cmd);
1538 + target_complete_cmd(se_cmd, SAM_STAT_TASK_ABORTED);
1539 + }
1538 1540
1539 1541 return iscsit_dump_data_payload(conn, payload_length, 1);
1540 1542 }
modified drivers/target/iscsi/iscsi_target_login.c
@@ -47,7 +47,7 @@ static struct iscsi_login *iscsi_login_init_conn(struct iscsit_conn *conn)
47 47 login->conn = conn;
48 48 login->first_request = 1;
49 49
50 - login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL);
50 + login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS + 1, GFP_KERNEL);
51 51 if (!login->req_buf) {
52 52 pr_err("Unable to allocate memory for response buffer.\n");
53 53 goto out_login;
modified drivers/tee/qcomtee/user_obj.c
@@ -230,8 +230,7 @@ static int qcomtee_user_object_dispatch(struct qcomtee_object_invoke_ctx *oic,
230 230 struct qcomtee_context_data *ctxdata = uo->ctx->data;
231 231 int errno;
232 232
233 - struct qcomtee_ureq *ureq __free(kfree) = kzalloc(sizeof(*ureq),
234 - GFP_KERNEL);
233 + struct qcomtee_ureq *ureq __free(kfree) = kzalloc_obj(*ureq);
235 234 if (!ureq)
236 235 return -ENOMEM;
237 236
modified drivers/thunderbolt/stream.c
@@ -408,8 +408,7 @@ static int tbstream_dev_alloc_rx_buffers(struct tbstream_dev *sdev)
408 408 size_t ring_size = tb_ring_size(sdev->rx_ring.ring);
409 409 int i;
410 410
411 - sdev->rx_ring.frames = kcalloc(ring_size, sizeof(struct tbstream_frame),
412 - GFP_KERNEL);
411 + sdev->rx_ring.frames = kzalloc_objs(struct tbstream_frame, ring_size);
413 412 if (!sdev->rx_ring.frames)
414 413 return -ENOMEM;
415 414
@@ -463,8 +462,7 @@ static int tbstream_dev_alloc_tx_buffers(struct tbstream_dev *sdev)
463 462 size_t ring_size = tb_ring_size(sdev->tx_ring.ring);
464 463 int i;
465 464
466 - sdev->tx_ring.frames = kcalloc(ring_size, sizeof(struct tbstream_frame),
467 - GFP_KERNEL);
465 + sdev->tx_ring.frames = kzalloc_objs(struct tbstream_frame, ring_size);
468 466 if (!sdev->tx_ring.frames)
469 467 return -ENOMEM;
470 468
@@ -1498,7 +1496,7 @@ tbstream_dev_make_group(struct config_group *group, const char *name)
1498 1496 if (strlen(name) > TB_PROPERTY_KEY_SIZE)
1499 1497 return ERR_PTR(-ENAMETOOLONG);
1500 1498
1501 - sdev = kzalloc_obj(*sdev, GFP_KERNEL);
1499 + sdev = kzalloc_obj(*sdev);
1502 1500 if (!sdev)
1503 1501 return ERR_PTR(-ENOMEM);
1504 1502
@@ -1592,7 +1590,7 @@ tbstream_make_group(struct config_group *group, const char *name)
1592 1590 if (sscanf(name, "%u-%llx.%u", &domain, &route, &index) != 3)
1593 1591 return ERR_PTR(-EINVAL);
1594 1592
1595 - sg = kzalloc_obj(*sg, GFP_KERNEL);
1593 + sg = kzalloc_obj(*sg);
1596 1594 if (!sg)
1597 1595 return ERR_PTR(-ENOMEM);
1598 1596
@@ -1698,7 +1696,7 @@ static int tbstream_probe(struct tb_service *svc)
1698 1696 {
1699 1697 struct tbstream *stream;
1700 1698
1701 - stream = kzalloc_obj(*stream, GFP_KERNEL);
1699 + stream = kzalloc_obj(*stream);
1702 1700 if (!stream)
1703 1701 return -ENOMEM;
1704 1702
modified drivers/tty/moxa.c
@@ -954,8 +954,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
954 954 unsigned int i, first_idx;
955 955 int ret;
956 956
957 - brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
958 - GFP_KERNEL);
957 + brd->ports = kzalloc_objs(*brd->ports, MAX_PORTS_PER_BOARD);
959 958 if (brd->ports == NULL) {
960 959 printk(KERN_ERR "cannot allocate memory for ports\n");
961 960 ret = -ENOMEM;
modified drivers/tty/vt/consolemap.c
@@ -776,7 +776,8 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct,
776 776 struct uni_pagedict *dict;
777 777 unsigned int d, r, g;
778 778
779 - struct unipair *unilist __free(kvfree) = kvmalloc_array(ct, sizeof(*unilist), GFP_KERNEL);
779 + struct unipair *unilist __free(kvfree) = kvmalloc_objs(*unilist, ct,
780 + GFP_KERNEL);
780 781 if (!unilist)
781 782 return -ENOMEM;
782 783
modified drivers/ufs/core/ufs-txeq.c
@@ -1073,7 +1073,7 @@ static int __ufshcd_tx_eqtr(struct ufs_hba *hba,
1073 1073 struct ufs_pa_layer_attr *pwr_mode)
1074 1074 {
1075 1075 struct ufshcd_tx_eqtr_data *eqtr_data __free(kfree) =
1076 - kzalloc(sizeof(*eqtr_data), GFP_KERNEL);
1076 + kzalloc_obj(*eqtr_data);
1077 1077 struct tx_eqtr_iter h_iter = {};
1078 1078 struct tx_eqtr_iter d_iter = {};
1079 1079 u32 gear = pwr_mode->gear_tx;
modified drivers/ufs/host/ufs-qcom.c
@@ -715,6 +715,7 @@ static void ufs_qcom_link_startup_post_change(struct ufs_hba *hba)
715 715 static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
716 716 enum ufs_notify_change_status status)
717 717 {
718 + struct ufs_qcom_host *host = ufshcd_get_variant(hba);
718 719 int err = 0;
719 720
720 721 switch (status) {
@@ -737,6 +738,14 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
737 738 */
738 739 err = ufshcd_disable_host_tx_lcc(hba);
739 740
741 + /*
742 + * Restore HS/LS link startup mode set by bootloader
743 + * after UFS reset clears REG_UFS_DEBUG_SPARE_CFG.
744 + */
745 + if (host->hw_ver.major > 0x6 ||
746 + (host->hw_ver.major == 0x6 && host->hw_ver.minor >= 0x2))
747 + ufshcd_writel(hba, host->boot_spare_cfg,
748 + REG_UFS_DEBUG_SPARE_CFG);
740 749 break;
741 750 case POST_CHANGE:
742 751 ufs_qcom_link_startup_post_change(hba);
@@ -1325,7 +1334,7 @@ static void ufs_qcom_advertise_quirks(struct ufs_hba *hba)
1325 1334 static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host)
1326 1335 {
1327 1336 struct ufs_host_params *host_params = &host->host_params;
1328 - u32 val, dev_major;
1337 + u32 dev_major;
1329 1338
1330 1339 /*
1331 1340 * Default to powering up the PHY to the max gear possible, which is
@@ -1344,8 +1353,8 @@ static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host)
1344 1353 */
1345 1354 host->phy_gear = UFS_HS_G2;
1346 1355 } else if (host->hw_ver.major >= 0x5) {
1347 - val = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG);
1348 - dev_major = FIELD_GET(UFS_DEV_VER_MAJOR_MASK, val);
1356 + host->boot_spare_cfg = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG);
1357 + dev_major = FIELD_GET(UFS_DEV_VER_MAJOR_MASK, host->boot_spare_cfg);
1349 1358
1350 1359 /*
1351 1360 * Since the UFS device version is populated, let's remove the
@@ -2282,7 +2291,7 @@ static void ufs_qcom_config_scaling_param(struct ufs_hba *hba,
2282 2291 p->polling_ms = 60;
2283 2292 p->timer = DEVFREQ_TIMER_DELAYED;
2284 2293 d->upthreshold = 70;
2285 - d->downdifferential = 5;
2294 + d->downdifferential = 65;
2286 2295
2287 2296 hba->clk_scaling.suspend_on_no_request = true;
2288 2297 }
@@ -2761,7 +2770,7 @@ static int ufs_qcom_get_rx_fom(struct ufs_hba *hba,
2761 2770 struct tx_eqtr_iter *d_iter)
2762 2771 {
2763 2772 struct ufshcd_tx_eq_params *params __free(kfree) =
2764 - kzalloc(sizeof(*params), GFP_KERNEL);
2773 + kzalloc_obj(*params);
2765 2774 struct ufs_qcom_host *host = ufshcd_get_variant(hba);
2766 2775 struct ufs_pa_layer_attr old_pwr_info;
2767 2776 u32 fom[PA_MAXDATALANES] = { 0 };
modified drivers/ufs/host/ufs-qcom.h
@@ -361,6 +361,7 @@ struct ufs_qcom_host {
361 361 bool esi_enabled;
362 362
363 363 u32 saved_tx_eq_g1_setting;
364 + u32 boot_spare_cfg;
364 365 };
365 366
366 367 struct ufs_qcom_drvdata {
modified drivers/ufs/host/ufshcd-pci.c
@@ -181,6 +181,25 @@ static int ufs_intel_lkf_pwr_change_notify(struct ufs_hba *hba,
181 181 return err;
182 182 }
183 183
184 + static int ufs_intel_nvl_pwr_change_notify(struct ufs_hba *hba,
185 + enum ufs_notify_change_status stage,
186 + struct ufs_pa_layer_attr *dev_req_params)
187 + {
188 + int adapt_val;
189 +
190 + if (stage != PRE_CHANGE || hba->ufs_version < ufshci_version(4, 0))
191 + return 0;
192 +
193 + if (dev_req_params->pwr_tx == FAST_MODE || dev_req_params->pwr_tx == FASTAUTO_MODE)
194 + adapt_val = PA_INITIAL_ADAPT;
195 + else
196 + adapt_val = PA_NO_ADAPT;
197 +
198 + ufshcd_dme_configure_adapt(hba, dev_req_params->gear_tx, adapt_val);
199 +
200 + return 0;
201 + }
202 +
184 203 static int ufs_intel_lkf_apply_dev_quirks(struct ufs_hba *hba)
185 204 {
186 205 u32 granularity, peer_granularity;
@@ -441,6 +460,43 @@ static int ufs_intel_mtl_init(struct ufs_hba *hba)
441 460 return ufs_intel_common_init(hba);
442 461 }
443 462
463 + static int ufs_intel_mcq_config_resource(struct ufs_hba *hba)
464 + {
465 + hba->mcq_base = hba->mmio_base + ufshcd_mcq_queue_cfg_addr(hba);
466 +
467 + return 0;
468 + }
469 +
470 + /*
471 + * This Intel UFS4.0 controller maps MCQ doorbell and interrupt-status
472 + * registers into the same PCI BAR as the legacy HCI space, at this
473 + * fixed offset/stride.
474 + */
475 + #define UFS_INTEL_SQDAO0 0x2800
476 + #define UFS_INTEL_SQISAO0 0x2814
477 + #define UFS_INTEL_CQDAO0 0x281C
478 + #define UFS_INTEL_CQISAO0 0x2824
479 + #define UFS_INTEL_MCQ_STRIDE 0x30
480 +
481 + static int ufs_intel_op_runtime_config(struct ufs_hba *hba)
482 + {
483 + struct ufshcd_mcq_opr_info_t *opr;
484 + int i;
485 +
486 + hba->mcq_opr[OPR_SQD].offset = UFS_INTEL_SQDAO0;
487 + hba->mcq_opr[OPR_SQIS].offset = UFS_INTEL_SQISAO0;
488 + hba->mcq_opr[OPR_CQD].offset = UFS_INTEL_CQDAO0;
489 + hba->mcq_opr[OPR_CQIS].offset = UFS_INTEL_CQISAO0;
490 +
491 + for (i = 0; i < OPR_MAX; i++) {
492 + opr = &hba->mcq_opr[i];
493 + opr->stride = UFS_INTEL_MCQ_STRIDE;
494 + opr->base = hba->mmio_base + opr->offset;
495 + }
496 +
497 + return 0;
498 + }
499 +
444 500 static int ufs_qemu_get_hba_mac(struct ufs_hba *hba)
445 501 {
446 502 return MAX_SUPP_MAC;
@@ -527,6 +583,9 @@ static struct ufs_hba_variant_ops ufs_intel_mtl_hba_vops = {
527 583 .exit = ufs_intel_common_exit,
528 584 .hce_enable_notify = ufs_intel_hce_enable_notify,
529 585 .link_startup_notify = ufs_intel_link_startup_notify,
586 + .pwr_change_notify = ufs_intel_nvl_pwr_change_notify,
587 + .mcq_config_resource = ufs_intel_mcq_config_resource,
588 + .op_runtime_config = ufs_intel_op_runtime_config,
530 589 .resume = ufs_intel_resume,
531 590 .device_reset = ufs_intel_device_reset,
532 591 };
modified drivers/usb/cdns3/cdnsp-gadget.c
@@ -1338,7 +1338,6 @@ static int cdnsp_run(struct cdnsp_device *pdev,
1338 1338
1339 1339 cdnsp_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
1340 1340
1341 -
1342 1341 ret = cdnsp_start(pdev);
1343 1342 if (ret) {
1344 1343 ret = -ENODEV;
@@ -1837,6 +1836,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev)
1837 1836 readl(&pdev->rev_cap->tx_buff_size));
1838 1837 }
1839 1838
1839 + static void cdnsp_set_event_deq(struct cdnsp_device *pdev)
1840 + {
1841 + dma_addr_t deq;
1842 + u64 temp;
1843 +
1844 + deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg,
1845 + pdev->event_ring->dequeue);
1846 +
1847 + /* Update controller event ring dequeue pointer */
1848 + temp = cdnsp_read_64(&pdev->ir_set->erst_dequeue);
1849 + temp &= ERST_PTR_MASK;
1850 +
1851 + /*
1852 + * Don't clear the EHB bit (which is RW1C) because
1853 + * there might be more events to service.
1854 + */
1855 + temp &= ~ERST_EHB;
1856 +
1857 + cdnsp_write_64(((u64)deq & (u64)~ERST_PTR_MASK) | temp,
1858 + &pdev->ir_set->erst_dequeue);
1859 + }
1860 +
1861 + static void cdnsp_add_interrupter(struct cdnsp_device *pdev)
1862 + {
1863 + u64 erst_base;
1864 + u32 erst_size;
1865 +
1866 + /* Set ERST count with the number of entries in the segment table. */
1867 + erst_size = readl(&pdev->ir_set->erst_size);
1868 + erst_size &= ERST_SIZE_MASK;
1869 + erst_size |= ERST_NUM_SEGS;
1870 + writel(erst_size, &pdev->ir_set->erst_size);
1871 +
1872 + /* Set the segment table base address. */
1873 + erst_base = cdnsp_read_64(&pdev->ir_set->erst_base);
1874 + erst_base &= ERST_PTR_MASK;
1875 + erst_base |= (pdev->erst.erst_dma_addr & (u64)~ERST_PTR_MASK);
1876 + cdnsp_write_64(erst_base, &pdev->ir_set->erst_base);
1877 +
1878 + /* Set the event ring dequeue address. */
1879 + cdnsp_set_event_deq(pdev);
1880 + }
1881 +
1882 + /* Set up basic CDNSP registers */
1883 + static void cdnsp_init(struct cdnsp_device *pdev)
1884 + {
1885 + unsigned int val;
1886 + u64 val_64;
1887 +
1888 + val = readl(&pdev->op_regs->config_reg);
1889 + val |= ((val & ~MAX_DEVS) | CDNSP_DEV_MAX_SLOTS) | CONFIG_U3E;
1890 + writel(val, &pdev->op_regs->config_reg);
1891 +
1892 + /* Initialize the Command ring */
1893 + cdnsp_ring_init(pdev, pdev->cmd_ring);
1894 +
1895 + /* Set the address in the Command Ring Control register */
1896 + val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring);
1897 + val_64 = (val_64 & (u64)CMD_RING_RSVD_BITS) |
1898 + (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) |
1899 + pdev->cmd_ring->cycle_state;
1900 + cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring);
1901 +
1902 + /* Set Device Context Base Address Array pointer */
1903 + cdnsp_write_64(pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr);
1904 +
1905 + /* Set Doorbell array pointer */
1906 + val = readl(&pdev->cap_regs->db_off);
1907 + val &= DBOFF_MASK;
1908 + pdev->dba = (void __iomem *)pdev->cap_regs + val;
1909 +
1910 + /* Initialize the Primary interrupter */
1911 + cdnsp_ring_init(pdev, pdev->event_ring);
1912 + cdnsp_add_interrupter(pdev);
1913 + }
1914 +
1840 1915 static int cdnsp_gen_setup(struct cdnsp_device *pdev)
1841 1916 {
1842 1917 int ret;
@@ -1902,6 +1977,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)
1902 1977 if (ret)
1903 1978 return ret;
1904 1979
1980 + cdnsp_init(pdev);
1981 +
1905 1982 /*
1906 1983 * Software workaround for U1: after transition
1907 1984 * to U1 the controller starts gating clock, and in some cases,
@@ -2031,9 +2108,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)
2031 2108 struct cdnsp_device *pdev = cdns->gadget_dev;
2032 2109 unsigned long flags;
2033 2110
2034 - if (pdev->link_state == XDEV_U3)
2035 - return 0;
2036 -
2037 2111 spin_lock_irqsave(&pdev->lock, flags);
2038 2112 cdnsp_disconnect_gadget(pdev);
2039 2113 cdnsp_stop(pdev);
@@ -2047,12 +2121,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power)
2047 2121 struct cdnsp_device *pdev = cdns->gadget_dev;
2048 2122 enum usb_device_speed max_speed;
2049 2123 unsigned long flags;
2124 + bool context_lost;
2125 + u32 val;
2050 2126 int ret;
2051 2127
2052 2128 if (!pdev->gadget_driver)
2053 2129 return 0;
2054 2130
2055 2131 spin_lock_irqsave(&pdev->lock, flags);
2132 + val = readl(&pdev->port3x_regs->mode_2);
2133 + context_lost = !!(val & CFG_3XPORT_U1_PIPE_CLK_GATE_EN) || lost_power;
2134 +
2135 + if (context_lost) {
2136 + cdnsp_halt(pdev);
2137 + cdnsp_set_apb_timeout_value(pdev);
2138 +
2139 + /* Reset the internal controller memory state and registers. */
2140 + ret = cdnsp_reset(pdev);
2141 + if (ret)
2142 + goto unlock;
2143 +
2144 + val = readl(&pdev->port3x_regs->mode_2);
2145 + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN;
2146 + writel(val, &pdev->port3x_regs->mode_2);
2147 +
2148 + cdnsp_clear_cmd_ring(pdev);
2149 +
2150 + memset(pdev->event_ring->first_seg->trbs, 0,
2151 + sizeof(union cdnsp_trb) * (TRBS_PER_SEGMENT));
2152 +
2153 + cdnsp_init(pdev);
2154 + }
2155 +
2056 2156 max_speed = pdev->gadget_driver->max_speed;
2057 2157
2058 2158 /* Limit speed if necessary. */
@@ -2060,9 +2160,10 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power)
2060 2160
2061 2161 ret = cdnsp_run(pdev, max_speed);
2062 2162
2063 - if (pdev->link_state == XDEV_U3)
2163 + if (!context_lost && pdev->link_state == XDEV_U3)
2064 2164 __cdnsp_gadget_wakeup(pdev);
2065 2165
2166 + unlock:
2066 2167 spin_unlock_irqrestore(&pdev->lock, flags);
2067 2168
2068 2169 return ret;
modified drivers/usb/cdns3/cdnsp-gadget.h
@@ -1510,6 +1510,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,
1510 1510 int cdnsp_ring_expansion(struct cdnsp_device *pdev,
1511 1511 struct cdnsp_ring *ring,
1512 1512 unsigned int num_trbs, gfp_t flags);
1513 + void cdnsp_ring_init(struct cdnsp_device *pdev, struct cdnsp_ring *ring);
1513 1514 struct cdnsp_ring *cdnsp_dma_to_transfer_ring(struct cdnsp_ep *ep, u64 address);
1514 1515 int cdnsp_alloc_stream_info(struct cdnsp_device *pdev,
1515 1516 struct cdnsp_ep *pep,
modified drivers/usb/cdns3/cdnsp-mem.c
@@ -394,13 +394,6 @@ static struct cdnsp_ring *cdnsp_ring_alloc(struct cdnsp_device *pdev,
394 394 if (ret)
395 395 goto fail;
396 396
397 - /* Only event ring does not use link TRB. */
398 - if (type != TYPE_EVENT)
399 - ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |=
400 - cpu_to_le32(LINK_TOGGLE);
401 -
402 - cdnsp_initialize_ring_info(ring);
403 - trace_cdnsp_ring_alloc(ring);
404 397 return ring;
405 398 fail:
406 399 kfree(ring);
@@ -603,6 +596,7 @@ int cdnsp_alloc_stream_info(struct cdnsp_device *pdev,
603 596 if (!cur_ring)
604 597 goto cleanup_rings;
605 598
599 + cdnsp_ring_init(pdev, cur_ring);
606 600 cur_ring->stream_id = cur_stream;
607 601 cur_ring->trb_address_map = &stream_info->trb_address_map;
608 602
@@ -698,6 +692,8 @@ static int cdnsp_alloc_priv_device(struct cdnsp_device *pdev)
698 692 if (!pdev->eps[0].ring)
699 693 goto fail;
700 694
695 + cdnsp_ring_init(pdev, pdev->eps[0].ring);
696 +
701 697 /* Point to output device context in dcbaa. */
702 698 pdev->dcbaa->dev_context_ptrs[1] = cpu_to_le64(pdev->out_ctx.dma);
703 699 pdev->cmd.in_ctx = &pdev->in_ctx;
@@ -991,6 +987,8 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,
991 987 if (!pep->ring)
992 988 return -ENOMEM;
993 989
990 + cdnsp_ring_init(pdev, pep->ring);
991 +
994 992 pep->skip = false;
995 993
996 994 /* Fill the endpoint context */
@@ -1096,28 +1094,6 @@ void cdnsp_mem_cleanup(struct cdnsp_device *pdev)
1096 1094 pdev->active_port = NULL;
1097 1095 }
1098 1096
1099 - static void cdnsp_set_event_deq(struct cdnsp_device *pdev)
1100 - {
1101 - dma_addr_t deq;
1102 - u64 temp;
1103 -
1104 - deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg,
1105 - pdev->event_ring->dequeue);
1106 -
1107 - /* Update controller event ring dequeue pointer */
1108 - temp = cdnsp_read_64(&pdev->ir_set->erst_dequeue);
1109 - temp &= ERST_PTR_MASK;
1110 -
1111 - /*
1112 - * Don't clear the EHB bit (which is RW1C) because
1113 - * there might be more events to service.
1114 - */
1115 - temp &= ~ERST_EHB;
1116 -
1117 - cdnsp_write_64(((u64)deq & (u64)~ERST_PTR_MASK) | temp,
1118 - &pdev->ir_set->erst_dequeue);
1119 - }
1120 -
1121 1097 static void cdnsp_add_in_port(struct cdnsp_device *pdev,
1122 1098 struct cdnsp_port *port,
1123 1099 __le32 __iomem *addr)
@@ -1226,6 +1202,36 @@ static int cdnsp_setup_port_arrays(struct cdnsp_device *pdev)
1226 1202 return 0;
1227 1203 }
1228 1204
1205 + static void cdnsp_initialize_ring_segments(struct cdnsp_device *pdev, struct cdnsp_ring *ring)
1206 + {
1207 + struct cdnsp_segment *seg;
1208 +
1209 + /* Only event ring does not use link TRB. */
1210 + if (ring->type == TYPE_EVENT)
1211 + return;
1212 +
1213 + seg = ring->first_seg;
1214 +
1215 + while (seg) {
1216 + struct cdnsp_segment *next = seg->next;
1217 +
1218 + cdnsp_link_segments(pdev, seg, next, ring->type);
1219 + if (next == ring->first_seg)
1220 + break;
1221 +
1222 + seg = next;
1223 + }
1224 +
1225 + ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= cpu_to_le32(LINK_TOGGLE);
1226 + }
1227 +
1228 + void cdnsp_ring_init(struct cdnsp_device *pdev, struct cdnsp_ring *ring)
1229 + {
1230 + cdnsp_initialize_ring_segments(pdev, ring);
1231 + cdnsp_initialize_ring_info(ring);
1232 + trace_cdnsp_ring_alloc(ring);
1233 + }
1234 +
1229 1235 /*
1230 1236 * Initialize memory for CDNSP (one-time init).
1231 1237 *
@@ -1237,10 +1243,8 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
1237 1243 {
1238 1244 struct device *dev = pdev->dev;
1239 1245 int ret = -ENOMEM;
1240 - unsigned int val;
1241 1246 dma_addr_t dma;
1242 1247 u32 page_size;
1243 - u64 val_64;
1244 1248
1245 1249 /*
1246 1250 * Use 4K pages, since that's common and the minimum the
@@ -1248,10 +1252,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
1248 1252 */
1249 1253 page_size = 1 << 12;
1250 1254
1251 - val = readl(&pdev->op_regs->config_reg);
1252 - val |= ((val & ~MAX_DEVS) | CDNSP_DEV_MAX_SLOTS) | CONFIG_U3E;
1253 - writel(val, &pdev->op_regs->config_reg);
1254 -
1255 1255 /*
1256 1256 * Doorbell array must be physically contiguous
1257 1257 * and 64-byte (cache line) aligned.
@@ -1263,8 +1263,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
1263 1263
1264 1264 pdev->dcbaa->dma = dma;
1265 1265
1266 - cdnsp_write_64(dma, &pdev->op_regs->dcbaa_ptr);
1267 -
1268 1266 /*
1269 1267 * Initialize the ring segment pool. The ring must be a contiguous
1270 1268 * structure comprised of TRBs. The TRBs must be 16 byte aligned,
@@ -1290,17 +1288,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
1290 1288 if (!pdev->cmd_ring)
1291 1289 goto destroy_device_pool;
1292 1290
1293 - /* Set the address in the Command Ring Control register */
1294 - val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring);
1295 - val_64 = (val_64 & (u64)CMD_RING_RSVD_BITS) |
1296 - (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) |
1297 - pdev->cmd_ring->cycle_state;
1298 - cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring);
1299 -
1300 - val = readl(&pdev->cap_regs->db_off);
1301 - val &= DBOFF_MASK;
1302 - pdev->dba = (void __iomem *)pdev->cap_regs + val;
1303 -
1304 1291 /* Set ir_set to interrupt register set 0 */
1305 1292 pdev->ir_set = &pdev->run_regs->ir_set[0];
1306 1293
@@ -1317,21 +1304,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
1317 1304 if (ret)
1318 1305 goto free_event_ring;
1319 1306
1320 - /* Set ERST count with the number of entries in the segment table. */
1321 - val = readl(&pdev->ir_set->erst_size);
1322 - val &= ERST_SIZE_MASK;
1323 - val |= ERST_NUM_SEGS;
1324 - writel(val, &pdev->ir_set->erst_size);
1325 -
1326 - /* Set the segment table base address. */
1327 - val_64 = cdnsp_read_64(&pdev->ir_set->erst_base);
1328 - val_64 &= ERST_PTR_MASK;
1329 - val_64 |= (pdev->erst.erst_dma_addr & (u64)~ERST_PTR_MASK);
1330 - cdnsp_write_64(val_64, &pdev->ir_set->erst_base);
1331 -
1332 - /* Set the event ring dequeue address. */
1333 - cdnsp_set_event_deq(pdev);
1334 -
1335 1307 ret = cdnsp_setup_port_arrays(pdev);
1336 1308 if (ret)
1337 1309 goto free_erst;
modified drivers/usb/dwc3/dwc3-google.c
@@ -442,6 +442,7 @@ static int dwc3_google_probe(struct platform_device *pdev)
442 442 probe_data.dwc = &google->dwc;
443 443 probe_data.res = res;
444 444 probe_data.ignore_clocks_and_resets = true;
445 + probe_data.properties = DWC3_DEFAULT_PROPERTIES;
445 446 ret = dwc3_core_probe(&probe_data);
446 447 if (ret) {
447 448 ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n");
modified drivers/usb/dwc3/ep0.c
@@ -304,7 +304,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
304 304
305 305 dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP;
306 306 if (dwc->connected)
307 - dwc3_stop_active_transfer(dwc3_ep, true, true);
307 + dwc3_stop_active_transfer(dwc3_ep, false, true);
308 308 else
309 309 dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN);
310 310 }
modified drivers/usb/dwc3/gadget.c
@@ -1004,7 +1004,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action)
1004 1004 * controller to generate an ERDY to initiate the
1005 1005 * stream.
1006 1006 */
1007 - dwc3_stop_active_transfer(dep, true, true);
1007 + dwc3_stop_active_transfer(dep, false, true);
1008 1008
1009 1009 /*
1010 1010 * All stream eps will reinitiate stream on NoStream
@@ -1032,7 +1032,7 @@ void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status)
1032 1032 {
1033 1033 struct dwc3_request *req;
1034 1034
1035 - dwc3_stop_active_transfer(dep, true, false);
1035 + dwc3_stop_active_transfer(dep, false, false);
1036 1036
1037 1037 /* If endxfer is delayed, avoid unmapping requests */
1038 1038 if (dep->flags & DWC3_EP_DELAY_STOP)
@@ -1720,7 +1720,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep)
1720 1720 if (ret == -EAGAIN)
1721 1721 return ret;
1722 1722
1723 - dwc3_stop_active_transfer(dep, true, true);
1723 + dwc3_stop_active_transfer(dep, false, true);
1724 1724
1725 1725 list_for_each_entry_safe(req, tmp, &dep->started_list, list)
1726 1726 dwc3_gadget_move_cancelled_request(req, DWC3_REQUEST_STATUS_DEQUEUED);
@@ -1757,6 +1757,11 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)
1757 1757 * the controller won't update the TRB progress on command
1758 1758 * completion. It also won't clear the HWO bit in the TRB.
1759 1759 * The command will also not complete immediately in that case.
1760 + *
1761 + * Older programming guide revisions recommended setting ForceRM to 1
1762 + * when ending a transfer. Newer programming guide revisions now
1763 + * recommend keeping ForceRM cleared, and TRBs are properly updated
1764 + * on command completion.
1760 1765 */
1761 1766 static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool interrupt)
1762 1767 {
@@ -1882,7 +1887,7 @@ static int dwc3_gadget_start_isoc_quirk(struct dwc3_ep *dep)
1882 1887 * to wait for the next XferNotReady to test the command again
1883 1888 */
1884 1889 if (cmd_status == 0) {
1885 - dwc3_stop_active_transfer(dep, true, true);
1890 + dwc3_stop_active_transfer(dep, false, true);
1886 1891 return 0;
1887 1892 }
1888 1893 }
@@ -2165,7 +2170,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
2165 2170 struct dwc3_request *t;
2166 2171
2167 2172 /* wait until it is processed */
2168 - dwc3_stop_active_transfer(dep, true, true);
2173 + dwc3_stop_active_transfer(dep, false, true);
2169 2174
2170 2175 /*
2171 2176 * Remove any started request if the transfer is
@@ -2242,7 +2247,7 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)
2242 2247 return 0;
2243 2248 }
2244 2249
2245 - dwc3_stop_active_transfer(dep, true, true);
2250 + dwc3_stop_active_transfer(dep, false, true);
2246 2251
2247 2252 list_for_each_entry_safe(req, tmp, &dep->started_list, list)
2248 2253 dwc3_gadget_move_cancelled_request(req, DWC3_REQUEST_STATUS_STALLED);
@@ -3368,7 +3373,7 @@ static void dwc3_nostream_work(struct work_struct *work)
3368 3373 dwc3_send_gadget_generic_command(dwc, cmd, dep->number);
3369 3374 } else {
3370 3375 dep->flags |= DWC3_EP_DELAY_START;
3371 - dwc3_stop_active_transfer(dep, true, true);
3376 + dwc3_stop_active_transfer(dep, false, true);
3372 3377 spin_unlock_irqrestore(&dwc->lock, flags);
3373 3378 return;
3374 3379 }
@@ -3726,7 +3731,7 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
3726 3731 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
3727 3732 list_empty(&dep->started_list) &&
3728 3733 (list_empty(&dep->pending_list) || status == -EXDEV))
3729 - dwc3_stop_active_transfer(dep, true, true);
3734 + dwc3_stop_active_transfer(dep, false, true);
3730 3735 else if (dwc3_gadget_ep_should_continue(dep))
3731 3736 if (__dwc3_gadget_kick_transfer(dep) == 0)
3732 3737 no_started_trb = false;
modified drivers/usb/gadget/function/f_mass_storage.c
@@ -2747,6 +2747,9 @@ int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
2747 2747 struct fsg_buffhd *bh, *buffhds;
2748 2748 int i;
2749 2749
2750 + if (n < 2)
2751 + return -EINVAL;
2752 +
2750 2753 buffhds = kzalloc_objs(*buffhds, n);
2751 2754 if (!buffhds)
2752 2755 return -ENOMEM;
@@ -2960,7 +2963,7 @@ EXPORT_SYMBOL_GPL(fsg_common_create_lun);
2960 2963
2961 2964 int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg)
2962 2965 {
2963 - char buf[8]; /* enough for 100000000 different numbers, decimal */
2966 + char buf[14];
2964 2967 int i, rc;
2965 2968
2966 2969 fsg_common_remove_luns(common);
modified drivers/usb/gadget/function/f_midi.c
@@ -879,7 +879,6 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
879 879 int status, n, jack = 1, i = 0, endpoint_descriptor_index = 0;
880 880
881 881 midi->gadget = cdev->gadget;
882 - INIT_WORK(&midi->work, f_midi_in_work);
883 882 status = f_midi_register_card(midi);
884 883 if (status < 0)
885 884 goto fail_register;
@@ -1377,6 +1376,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
1377 1376 status = -ENOMEM;
1378 1377 goto midi_free;
1379 1378 }
1379 + INIT_WORK(&midi->work, f_midi_in_work);
1380 1380 midi->out_ports = opts->out_ports;
1381 1381 midi->index = opts->index;
1382 1382 midi->buflen = opts->buflen;
modified drivers/usb/gadget/function/f_midi2.c
@@ -1145,7 +1145,7 @@ static int f_midi2_alloc_ep_reqs(struct f_midi2_usb_ep *usb_ep)
1145 1145 if (!usb_ep->reqs)
1146 1146 return -EINVAL;
1147 1147
1148 - for (i = 0; i < midi2->info.num_reqs; i++) {
1148 + for (i = 0; i < usb_ep->num_reqs; i++) {
1149 1149 if (usb_ep->reqs[i].req)
1150 1150 continue;
1151 1151 usb_ep->reqs[i].req = alloc_ep_req(usb_ep->usb_ep,
@@ -1160,10 +1160,9 @@ static int f_midi2_alloc_ep_reqs(struct f_midi2_usb_ep *usb_ep)
1160 1160 /* Free allocated requests */
1161 1161 static void f_midi2_free_ep_reqs(struct f_midi2_usb_ep *usb_ep)
1162 1162 {
1163 - struct f_midi2 *midi2 = usb_ep->card;
1164 1163 int i;
1165 1164
1166 - for (i = 0; i < midi2->info.num_reqs; i++) {
1165 + for (i = 0; i < usb_ep->num_reqs; i++) {
1167 1166 if (!usb_ep->reqs[i].req)
1168 1167 continue;
1169 1168 free_ep_req(usb_ep->usb_ep, usb_ep->reqs[i].req);
@@ -2178,13 +2177,13 @@ end:
2178 2177
2179 2178 /* generic show/store for string */
2180 2179 static ssize_t f_midi2_opts_str_show(struct f_midi2_opts *opts,
2181 - const char *str, char *page)
2180 + const char **strp, char *page)
2182 2181 {
2183 2182 int result = 0;
2184 2183
2185 2184 mutex_lock(&opts->lock);
2186 - if (str)
2187 - result = scnprintf(page, PAGE_SIZE, "%s\n", str);
2185 + if (*strp)
2186 + result = scnprintf(page, PAGE_SIZE, "%s\n", *strp);
2188 2187 mutex_unlock(&opts->lock);
2189 2188 return result;
2190 2189 }
@@ -2278,7 +2277,7 @@ static ssize_t f_midi2_block_opts_name_show(struct config_item *item,
2278 2277 {
2279 2278 struct f_midi2_block_opts *opts = to_f_midi2_block_opts(item);
2280 2279
2281 - return f_midi2_opts_str_show(opts->ep->opts, opts->info.name, page);
2280 + return f_midi2_opts_str_show(opts->ep->opts, &opts->info.name, page);
2282 2281 }
2283 2282
2284 2283 static ssize_t f_midi2_block_opts_name_store(struct config_item *item,
@@ -2435,7 +2434,7 @@ static ssize_t f_midi2_ep_opts_##name##_show(struct config_item *item, \
2435 2434 char *page) \
2436 2435 { \
2437 2436 struct f_midi2_ep_opts *opts = to_f_midi2_ep_opts(item); \
2438 - return f_midi2_opts_str_show(opts->opts, opts->info.name, page);\
2437 + return f_midi2_opts_str_show(opts->opts, &opts->info.name, page);\
2439 2438 } \
2440 2439 \
2441 2440 static ssize_t f_midi2_ep_opts_##name##_store(struct config_item *item, \
@@ -2590,7 +2589,7 @@ static ssize_t f_midi2_opts_iface_name_show(struct config_item *item,
2590 2589 {
2591 2590 struct f_midi2_opts *opts = to_f_midi2_opts(item);
2592 2591
2593 - return f_midi2_opts_str_show(opts, opts->info.iface_name, page);
2592 + return f_midi2_opts_str_show(opts, &opts->info.iface_name, page);
2594 2593 }
2595 2594
2596 2595 static ssize_t f_midi2_opts_iface_name_store(struct config_item *item,
modified drivers/usb/gadget/function/f_ncm.c
@@ -1766,7 +1766,7 @@ static struct usb_function *ncm_alloc(struct usb_function_instance *fi)
1766 1766 int status;
1767 1767
1768 1768 /* allocate and initialize one new instance */
1769 - ncm = kzalloc(sizeof(*ncm), GFP_KERNEL);
1769 + ncm = kzalloc_obj(*ncm);
1770 1770 if (!ncm)
1771 1771 return ERR_PTR(-ENOMEM);
1772 1772
modified drivers/usb/gadget/functions.c
@@ -70,7 +70,7 @@ void usb_put_function_instance(struct usb_function_instance *fi)
70 70 {
71 71 struct module *mod;
72 72
73 - if (!fi)
73 + if (!fi || !fi->fd)
74 74 return;
75 75
76 76 mod = fi->fd->mod;
modified drivers/usb/gadget/legacy/inode.c
@@ -1260,10 +1260,11 @@ out:
1260 1260 static long gadget_dev_ioctl (struct file *fd, unsigned code, unsigned long value)
1261 1261 {
1262 1262 struct dev_data *dev = fd->private_data;
1263 - struct usb_gadget *gadget = dev->gadget;
1263 + struct usb_gadget *gadget;
1264 1264 long ret = -ENOTTY;
1265 1265
1266 1266 spin_lock_irq(&dev->lock);
1267 + gadget = dev->gadget;
1267 1268 if (dev->state == STATE_DEV_OPENED ||
1268 1269 dev->state == STATE_DEV_UNBOUND) {
1269 1270 /* Not bound to a UDC */
modified drivers/usb/host/xhci-mem.c
@@ -2301,7 +2301,7 @@ xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags)
2301 2301 if (!segs)
2302 2302 segs = ERST_DEFAULT_SEGS;
2303 2303
2304 - max_segs = FIELD_GET(HCS_ERST_MAX, xhci->hcs_params2) << 2;
2304 + max_segs = BIT(FIELD_GET(HCS_ERST_MAX, xhci->hcs_params2));
2305 2305 segs = min(segs, max_segs);
2306 2306
2307 2307 ir = kzalloc_node(sizeof(*ir), flags, dev_to_node(dev));
modified drivers/usb/host/xhci-ring.c
@@ -824,21 +824,18 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
824 824 usb_hcd_giveback_urb(hcd, urb, status);
825 825 }
826 826
827 - static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci,
828 - struct xhci_ring *ring, struct xhci_td *td)
827 + static void xhci_unmap_one_bounce_buffer(struct xhci_hcd *xhci,
828 + struct xhci_ring *ring, struct xhci_td *td,
829 + struct xhci_segment *seg)
829 830 {
830 831 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
831 - struct xhci_segment *seg = td->bounce_seg;
832 832 struct urb *urb = td->urb;
833 833 size_t len;
834 834
835 - if (!ring || !seg || !urb)
836 - return;
837 -
838 835 if (usb_urb_dir_out(urb)) {
839 836 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len,
840 837 DMA_TO_DEVICE);
841 - return;
838 + goto done;
842 839 }
843 840
844 841 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len,
@@ -854,10 +851,29 @@ static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci,
854 851 memcpy(urb->transfer_buffer + seg->bounce_offs, seg->bounce_buf,
855 852 seg->bounce_len);
856 853 }
854 + done:
857 855 seg->bounce_len = 0;
858 856 seg->bounce_offs = 0;
859 857 }
860 858
859 + static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci,
860 + struct xhci_ring *ring, struct xhci_td *td)
861 + {
862 + struct xhci_segment *seg;
863 + int i = 0;
864 +
865 + if (!td->bounce_seg || !ring || !td->urb)
866 + return;
867 +
868 + /* td->bounce_seg is the last one bounced, unmap them all */
869 + for (seg = td->start_seg; i++ < ring->num_segs; seg = seg->next) {
870 + if (seg->bounce_len)
871 + xhci_unmap_one_bounce_buffer(xhci, ring, td, seg);
872 + if (seg == td->bounce_seg)
873 + break;
874 + }
875 + }
876 +
861 877 static void xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td,
862 878 struct xhci_ring *ep_ring, int status)
863 879 {
@@ -3685,7 +3701,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
3685 3701 &trb_buff_len,
3686 3702 ring->enq_seg)) {
3687 3703 send_addr = ring->enq_seg->bounce_dma;
3688 - /* assuming TD won't span 2 segs */
3704 + /* TD bounced at least, and last on this seg */
3689 3705 td->bounce_seg = ring->enq_seg;
3690 3706 }
3691 3707 }
@@ -4312,11 +4328,16 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
4312 4328 check_interval(urb, ep_ctx);
4313 4329
4314 4330 /*
4315 - * Check if this starts the isoc data flow. Relies on hw setting ep ctx
4316 - * state after doorbell ring. Consider adding list_empty(td_list) check
4331 + * Schedule the URB discontiguously if all previous URBs have completed.
4332 + * XXX core can't tell if completions are pending but not running yet.
4317 4333 */
4318 - if (GET_EP_CTX_STATE(ep_ctx) != EP_STATE_RUNNING)
4334 + if (list_empty(&ep_ring->td_list) &&
4335 + !hcd_periodic_completion_in_progress(xhci_to_hcd(xhci), urb->ep)) {
4336 + if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_RUNNING)
4337 + xhci_dbg(xhci, "Unexpected running ring at isoc stream start, uframe: %d\n",
4338 + xep->next_uframe);
4319 4339 xep->next_uframe = -1;
4340 + }
4320 4341
4321 4342 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index);
4322 4343 }
modified drivers/usb/image/mdc800.c
@@ -1000,13 +1000,13 @@ static int __init usb_mdc800_init (void)
1000 1000 mdc800->downloaded = 0;
1001 1001 mdc800->written = 0;
1002 1002
1003 - mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL);
1003 + mdc800->irq_urb_buffer=kzalloc (8, GFP_KERNEL);
1004 1004 if (!mdc800->irq_urb_buffer)
1005 1005 goto cleanup_on_fail;
1006 1006 mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL);
1007 1007 if (!mdc800->write_urb_buffer)
1008 1008 goto cleanup_on_fail;
1009 - mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL);
1009 + mdc800->download_urb_buffer=kzalloc (64, GFP_KERNEL);
1010 1010 if (!mdc800->download_urb_buffer)
1011 1011 goto cleanup_on_fail;
1012 1012
modified drivers/usb/storage/ene_ub6250.c
@@ -2357,7 +2357,9 @@ static int ene_ub6250_probe(struct usb_interface *intf,
2357 2357 return result;
2358 2358
2359 2359 /* probe card type */
2360 + mutex_lock(&us->dev_mutex);
2360 2361 result = ene_get_card_type(us, REG_CARD_STATUS, info->bbuf);
2362 + mutex_unlock(&us->dev_mutex);
2361 2363 if (result != USB_STOR_XFER_GOOD) {
2362 2364 usb_stor_disconnect(intf);
2363 2365 return USB_STOR_TRANSPORT_ERROR;
modified drivers/usb/storage/realtek_cr.c
@@ -916,7 +916,6 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
916 916 us->proto_handler = rts51x_invoke_transport;
917 917
918 918 chip->timer_expires = 0;
919 - timer_setup(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn, 0);
920 919 fw5895_init(us);
921 920
922 921 /* enable autosuspend function of the usb device */
@@ -934,10 +933,7 @@ static void realtek_cr_destructor(void *extra)
934 933 return;
935 934
936 935 #ifdef CONFIG_REALTEK_AUTOPM
937 - if (ss_en) {
938 - timer_delete(&chip->rts51x_suspend_timer);
939 - chip->timer_expires = 0;
940 - }
936 + timer_shutdown_sync(&chip->rts51x_suspend_timer);
941 937 #endif
942 938 kfree(chip->status);
943 939 }
@@ -982,6 +978,9 @@ static int init_realtek_cr(struct us_data *us)
982 978
983 979 us->extra = chip;
984 980 us->extra_destructor = realtek_cr_destructor;
981 + #ifdef CONFIG_REALTEK_AUTOPM
982 + timer_setup(&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn, 0);
983 + #endif
985 984 us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
986 985 chip->us = us;
987 986
modified drivers/usb/typec/hd3ss3220.c
@@ -62,6 +62,7 @@ struct hd3ss3220 {
62 62 int id_irq;
63 63
64 64 struct regulator *vbus;
65 + bool vbus_enabled;
65 66 };
66 67
67 68 static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
@@ -208,7 +209,7 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
208 209 {
209 210 int ret;
210 211
211 - if (regulator_is_enabled(hd3ss3220->vbus) == on)
212 + if (hd3ss3220->vbus_enabled == on)
212 213 return;
213 214
214 215 if (on)
@@ -216,9 +217,13 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
216 217 else
217 218 ret = regulator_disable(hd3ss3220->vbus);
218 219
219 - if (ret)
220 + if (ret) {
220 221 dev_err(hd3ss3220->dev,
221 222 "vbus regulator %s failed: %d\n", on ? "enable" : "disable", ret);
223 + return;
224 + }
225 +
226 + hd3ss3220->vbus_enabled = on;
222 227 }
223 228
224 229 static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
modified drivers/usb/typec/mux.c
@@ -57,6 +57,8 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
57 57 */
58 58 dev = class_find_device(&typec_mux_class, NULL, fwnode,
59 59 switch_fwnode_match);
60 + if (!dev)
61 + return ERR_PTR(-EPROBE_DEFER);
60 62
61 63 /* Skip duplicates */
62 64 for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
@@ -65,7 +67,7 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
65 67 return NULL;
66 68 }
67 69
68 - return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER);
70 + return to_typec_switch_dev(dev);
69 71 }
70 72
71 73 /**
@@ -275,7 +277,9 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode)
275 277 static void *typec_mux_match(const struct fwnode_handle *fwnode,
276 278 const char *id, void *data)
277 279 {
280 + struct typec_mux_dev **mux_devs = data;
278 281 struct device *dev;
282 + int i;
279 283
280 284 /*
281 285 * Device graph (OF graph) does not give any means to identify the
@@ -290,8 +294,18 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
290 294
291 295 dev = class_find_device(&typec_mux_class, NULL, fwnode,
292 296 mux_fwnode_match);
297 + if (!dev)
298 + return ERR_PTR(-EPROBE_DEFER);
293 299
294 - return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
300 + /* Skip duplicates */
301 + for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
302 + if (to_typec_mux_dev(dev) == mux_devs[i]) {
303 + put_device(dev);
304 + return NULL;
305 + }
306 +
307 +
308 + return to_typec_mux_dev(dev);
295 309 }
296 310
297 311 /**
@@ -316,7 +330,8 @@ struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
316 330 return ERR_PTR(-ENOMEM);
317 331
318 332 count = fwnode_connection_find_matches(fwnode, "mode-switch",
319 - NULL, typec_mux_match,
333 + (void **)mux_devs,
334 + typec_mux_match,
320 335 (void **)mux_devs,
321 336 ARRAY_SIZE(mux_devs));
322 337 if (count <= 0) {
modified drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -543,6 +543,8 @@ static void qcom_pmic_typec_pdphy_stop(struct pmic_typec *tcpm)
543 543 for (i = 0; i < pmic_typec_pdphy->nr_irqs; i++)
544 544 disable_irq(pmic_typec_pdphy->irq_data[i].irq);
545 545
546 + cancel_work_sync(&pmic_typec_pdphy->reset_work);
547 +
546 548 qcom_pmic_typec_pdphy_reset_on(pmic_typec_pdphy);
547 549
548 550 regulator_disable(pmic_typec_pdphy->vdd_pdphy);
modified drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -683,6 +683,9 @@ static int qcom_pmic_typec_port_start(struct pmic_typec *tcpm,
683 683 enable_irq(pmic_typec_port->irq_data[i].irq);
684 684
685 685 done:
686 + if (ret)
687 + disable_delayed_work_sync(&pmic_typec_port->cc_debounce_dwork);
688 +
686 689 return ret;
687 690 }
688 691
@@ -693,6 +696,8 @@ static void qcom_pmic_typec_port_stop(struct pmic_typec *tcpm)
693 696
694 697 for (i = 0; i < pmic_typec_port->nr_irqs; i++)
695 698 disable_irq(pmic_typec_port->irq_data[i].irq);
699 +
700 + disable_delayed_work_sync(&pmic_typec_port->cc_debounce_dwork);
696 701 }
697 702
698 703 int qcom_pmic_typec_port_probe(struct platform_device *pdev,
modified drivers/usb/typec/tcpm/tcpm.c
@@ -7119,16 +7119,32 @@ static void tcpm_pd_event_handler(struct kthread_work *work)
7119 7119 }
7120 7120 }
7121 7121 if (events & TCPM_SOURCING_VBUS) {
7122 - tcpm_log(port, "sourcing vbus");
7123 7122 /*
7124 7123 * In fast role swap case TCPC autonomously sources vbus. Set vbus_source
7125 - * true as TCPM wouldn't have called tcpm_set_vbus.
7124 + * true conditionally as TCPM wouldn't have called tcpm_set_vbus.
7125 + * If TCPM calls tcpm_set_vbus to source vbus, vbus_source would already
7126 + * be true.
7126 7127 *
7127 - * When vbus is sourced on the command on TCPM i.e. TCPM called
7128 - * tcpm_set_vbus to source vbus, vbus_source would already be true.
7128 + * When TCPM_FRS_EVENT and TCPM_SOURCING_VBUS arrive simultaneously,
7129 + * handling TCPM_FRS_EVENT above transitions the state to AMS_START
7130 + * with upcoming_state FR_SWAP_SEND.
7129 7131 */
7130 - port->vbus_source = true;
7131 - _tcpm_pd_vbus_on(port);
7132 +
7133 + if (tcpm_port_is_source(port) ||
7134 + tcpm_port_is_debug_source(port) ||
7135 + (port->state == AMS_START && port->upcoming_state == FR_SWAP_SEND) ||
7136 + port->state == FR_SWAP_SEND ||
7137 + port->state == FR_SWAP_SEND_TIMEOUT ||
7138 + port->state == FR_SWAP_SNK_SRC_TRANSITION_TO_OFF ||
7139 + port->state == FR_SWAP_SNK_SRC_NEW_SINK_READY ||
7140 + port->state == FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED) {
7141 + tcpm_log(port, "sourcing vbus");
7142 + port->vbus_source = true;
7143 + _tcpm_pd_vbus_on(port);
7144 + } else {
7145 + tcpm_log(port, "Discarding sourcing vbus! Invalid state %s",
7146 + tcpm_states[port->state]);
7147 + }
7132 7148 }
7133 7149 if (events & TCPM_PORT_CLEAN) {
7134 7150 tcpm_log(port, "port clean");
modified drivers/usb/typec/tipd/core.c
@@ -114,7 +114,6 @@ struct tps6598x_intel_vid_status_reg {
114 114 __le32 attention_vdo;
115 115 __le16 enter_vdo;
116 116 __le16 device_mode;
117 - __le16 cable_mode;
118 117 } __packed;
119 118
120 119 /* Standard Task return codes */
@@ -731,9 +730,19 @@ static void cd321x_typec_update_mode(struct tps6598x *tps, struct cd321x_status
731 730 cd321x->state.mode == TYPEC_TBT_MODE)
732 731 return;
733 732
734 - tbt_data.cable_mode = le16_to_cpu(st->intel_vid_status.cable_mode);
735 - tbt_data.device_mode = le16_to_cpu(st->intel_vid_status.device_mode);
736 - tbt_data.enter_vdo = le16_to_cpu(st->intel_vid_status.enter_vdo);
733 + tbt_data.cable_mode = TBT_MODE |
734 + TBT_SET_CABLE_SPEED(TPS_DATA_STATUS_TBT_CABLE_SPEED(st->data_status)) |
735 + TBT_SET_CABLE_ROUNDED(TPS_DATA_STATUS_TBT_CABLE_GEN(st->data_status));
736 + if (st->data_status & TPS_DATA_STATUS_OPTICAL_CABLE)
737 + tbt_data.cable_mode |= TBT_CABLE_OPTICAL;
738 + if (st->data_status & TPS_DATA_STATUS_ACTIVE_LINK_TRAIN)
739 + tbt_data.cable_mode |= TBT_CABLE_LINK_TRAINING;
740 + if (st->data_status & TPS_DATA_STATUS_ACTIVE_CABLE)
741 + tbt_data.cable_mode |= TBT_CABLE_ACTIVE_PASSIVE;
742 + tbt_data.device_mode = TBT_MODE |
743 + (u32)le16_to_cpu(st->intel_vid_status.device_mode) << 16;
744 + tbt_data.enter_vdo =
745 + (u32)le16_to_cpu(st->intel_vid_status.enter_vdo) << 16;
737 746 cd321x->state.alt = cd321x->port_altmode_tbt;
738 747 cd321x->state.mode = TYPEC_TBT_MODE;
739 748 cd321x->state.data = &tbt_data;
modified drivers/usb/typec/tipd/tps6598x.h
@@ -210,10 +210,10 @@
210 210 #define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) \
211 211 TPS_FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))
212 212 #define TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK GENMASK(27, 25)
213 - #define TPS_DATA_STATUS_TBT_CABLE_SPEED \
213 + #define TPS_DATA_STATUS_TBT_CABLE_SPEED(x) \
214 214 TPS_FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK, (x))
215 215 #define TPS_DATA_STATUS_TBT_CABLE_GEN_MASK GENMASK(29, 28)
216 - #define TPS_DATA_STATUS_TBT_CABLE_GEN \
216 + #define TPS_DATA_STATUS_TBT_CABLE_GEN(x) \
217 217 TPS_FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_GEN_MASK, (x))
218 218
219 219 /* Map data status to DP spec assignments */
modified drivers/usb/typec/ucsi/displayport.c
@@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)
74 74 cur = 0xff;
75 75 }
76 76
77 - if (cur != 0xff) {
77 + if (cur < UCSI_MAX_ALTMODES) {
78 78 ret = dp->con->port_altmode[cur] == alt ? 0 : -EBUSY;
79 79 goto err_unlock;
80 80 }
modified drivers/usb/usbip/usbip_common.c
@@ -696,7 +696,7 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
696 696
697 697 size = np * sizeof(*iso);
698 698
699 - buff = kcalloc(np, sizeof(*iso), GFP_KERNEL);
699 + buff = kzalloc_objs(*iso, np);
700 700 if (!buff)
701 701 return -ENOMEM;
702 702
modified drivers/xen/grant-table.c
@@ -1478,7 +1478,7 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
1478 1478 /* No need for kzalloc as it is initialized in following hypercall
1479 1479 * GNTTABOP_setup_table.
1480 1480 */
1481 - frames = kmalloc_array(nr_gframes, sizeof(*frames), GFP_ATOMIC);
1481 + frames = kmalloc_objs(*frames, nr_gframes, GFP_ATOMIC);
1482 1482 if (!frames)
1483 1483 return -ENOMEM;
1484 1484
modified fs/9p/vfs_dentry.c
@@ -113,8 +113,7 @@ void v9fs_dentry_fid_remove(struct dentry *dentry)
113 113 */
114 114 static int v9fs_dentry_init(struct dentry *dentry)
115 115 {
116 - struct v9fs_dentry *v9fs_dentry = kzalloc(sizeof(*v9fs_dentry),
117 - GFP_KERNEL);
116 + struct v9fs_dentry *v9fs_dentry = kzalloc_obj(*v9fs_dentry);
118 117
119 118 if (!v9fs_dentry)
120 119 return -ENOMEM;
modified fs/afs/dir.c
@@ -1801,7 +1801,7 @@ static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir,
1801 1801 goto error;
1802 1802
1803 1803 ret = -ENOMEM;
1804 - symlink = kmalloc_flex(struct afs_symlink, content, clen + 1, GFP_KERNEL);
1804 + symlink = kmalloc_flex(struct afs_symlink, content, clen + 1);
1805 1805 if (!symlink)
1806 1806 goto error;
1807 1807 refcount_set(&symlink->ref, 1);
modified fs/afs/symlink.c
@@ -119,8 +119,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
119 119 vnode->directory_size = i_size;
120 120
121 121 /* Copy the symlink. */
122 - symlink = kmalloc_flex(struct afs_symlink, content, i_size + 1,
123 - GFP_KERNEL);
122 + symlink = kmalloc_flex(struct afs_symlink, content, i_size + 1);
124 123 if (!symlink)
125 124 return -ENOMEM;
126 125
modified fs/binfmt_misc.c
@@ -331,8 +331,8 @@ static int entry_attach_interpreter(struct binfmt_misc_entry *e,
331 331 return -ENOSPC;
332 332
333 333 /* One allocation, both strings in it, like the entry's own buffer. */
334 - interp = kmalloc(struct_size(interp, name, nlen + plen + 2),
335 - GFP_KERNEL_ACCOUNT);
334 + interp = kmalloc_flex(*interp, name, nlen + plen + 2,
335 + GFP_KERNEL_ACCOUNT);
336 336 if (!interp) {
337 337 dec_ucount(ucounts, UCOUNT_BINFMT_MISC_INTERPRETERS);
338 338 return -ENOMEM;
@@ -858,8 +858,7 @@ static struct binfmt_misc_entry *create_entry(const char __user *buffer,
858 858 if ((count < 11) || (count > MAX_REGISTER_LENGTH))
859 859 return ERR_PTR(-EINVAL);
860 860
861 - e = kmalloc(struct_size(e, buf, count + MISC_DELIM_PAD),
862 - GFP_KERNEL_ACCOUNT);
861 + e = kmalloc_flex(*e, buf, count + MISC_DELIM_PAD, GFP_KERNEL_ACCOUNT);
863 862 if (!e)
864 863 return ERR_PTR(-ENOMEM);
865 864
modified fs/btrfs/dev-replace.c
@@ -636,7 +636,7 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
636 636
637 637 ret = mark_block_group_to_copy(fs_info, src_device);
638 638 if (ret)
639 - return ret;
639 + goto leave;
640 640
641 641 down_write(&dev_replace->rwsem);
642 642 dev_replace->replace_task = current;
modified fs/btrfs/inode.c
@@ -3436,6 +3436,9 @@ out:
3436 3436 */
3437 3437 btrfs_remove_ordered_extent(ordered_extent);
3438 3438
3439 + /* Cleanup any remaining biocs attached to the OE. */
3440 + btrfs_cleanup_ordered_bioc_list(ordered_extent);
3441 +
3439 3442 /* once for us */
3440 3443 btrfs_put_ordered_extent(ordered_extent);
3441 3444 /* once for the tree */
modified fs/btrfs/ioctl.c
@@ -384,6 +384,7 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
384 384 inode_flags &= ~BTRFS_INODE_COMPRESS;
385 385 inode_flags |= BTRFS_INODE_NOCOMPRESS;
386 386 } else if (fsflags & FS_COMPR_FL) {
387 + enum btrfs_compression_type comp_type;
387 388
388 389 if (IS_SWAPFILE(&inode->vfs_inode))
389 390 return -ETXTBSY;
@@ -391,9 +392,23 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
391 392 inode_flags |= BTRFS_INODE_COMPRESS;
392 393 inode_flags &= ~BTRFS_INODE_NOCOMPRESS;
393 394
394 - comp = btrfs_compress_type2str(fs_info->compress_type);
395 - if (!comp || comp[0] == 0)
396 - comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
395 + /*
396 + * Keep the algorithm recorded in the compression property,
397 + * otherwise changing an unrelated attribute would reset it to
398 + * the mount default, since FS_IOC_SETFLAGS callers write back
399 + * the whole flag set they got from FS_IOC_GETFLAGS and that
400 + * includes FS_COMPR_FL for any inode carrying the property.
401 + *
402 + * Inodes with the compress flag set but no property keep using
403 + * the mount default, so they behave as before.
404 + */
405 + if (inode->prop_compress)
406 + comp_type = inode->prop_compress;
407 + else if (fs_info->compress_type)
408 + comp_type = fs_info->compress_type;
409 + else
410 + comp_type = BTRFS_COMPRESS_ZLIB;
411 + comp = btrfs_compress_type2str(comp_type);
397 412 } else {
398 413 inode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
399 414 }
modified fs/btrfs/raid-stripe-tree.c
@@ -310,8 +310,10 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,
310 310
311 311 ret = btrfs_search_slot(trans, trans->fs_info->stripe_root, key, path,
312 312 0, 1);
313 - if (ret)
314 - return (ret == 1 ? ret : -EINVAL);
313 + if (ret > 0)
314 + ret = -ENOENT;
315 + if (ret < 0)
316 + return ret;
315 317
316 318 leaf = path->nodes[0];
317 319 slot = path->slots[0];
@@ -337,7 +339,6 @@ int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
337 339 stripe_extent = kzalloc(item_size, GFP_NOFS);
338 340 if (unlikely(!stripe_extent)) {
339 341 btrfs_abort_transaction(trans, -ENOMEM);
340 - btrfs_end_transaction(trans);
341 342 return -ENOMEM;
342 343 }
343 344
@@ -374,7 +375,7 @@ int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
374 375 struct btrfs_ordered_extent *ordered_extent)
375 376 {
376 377 struct btrfs_io_context *bioc;
377 - int ret;
378 + int ret = 0;
378 379
379 380 if (!btrfs_fs_incompat(trans->fs_info, RAID_STRIPE_TREE))
380 381 return 0;
@@ -382,17 +383,23 @@ int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
382 383 list_for_each_entry(bioc, &ordered_extent->bioc_list, rst_ordered_entry) {
383 384 ret = btrfs_insert_one_raid_extent(trans, bioc);
384 385 if (ret)
385 - return ret;
386 + break;
386 387 }
387 388
388 - while (!list_empty(&ordered_extent->bioc_list)) {
389 - bioc = list_first_entry(&ordered_extent->bioc_list,
389 + btrfs_cleanup_ordered_bioc_list(ordered_extent);
390 + return ret;
391 + }
392 +
393 + void btrfs_cleanup_ordered_bioc_list(struct btrfs_ordered_extent *ordered)
394 + {
395 + while (!list_empty(&ordered->bioc_list)) {
396 + struct btrfs_io_context *bioc;
397 +
398 + bioc = list_first_entry(&ordered->bioc_list,
390 399 typeof(*bioc), rst_ordered_entry);
391 400 list_del(&bioc->rst_ordered_entry);
392 401 btrfs_put_bioc(bioc);
393 402 }
394 -
395 - return 0;
396 403 }
397 404
398 405 int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
modified fs/btrfs/raid-stripe-tree.h
@@ -28,6 +28,7 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
28 28 u32 stripe_index, struct btrfs_io_stripe *stripe);
29 29 int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
30 30 struct btrfs_ordered_extent *ordered_extent);
31 + void btrfs_cleanup_ordered_bioc_list(struct btrfs_ordered_extent *ordered);
31 32
32 33 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
33 34 int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
modified fs/btrfs/scrub.c
@@ -1023,6 +1023,10 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
1023 1023
1024 1024 skip:
1025 1025 for_each_set_bit(sector_nr, &extent_bitmap, stripe->nr_sectors) {
1026 + const u64 sector_logical = stripe->logical +
1027 + ((u64)sector_nr << fs_info->sectorsize_bits);
1028 + const u64 sector_physical = physical +
1029 + ((u64)sector_nr << fs_info->sectorsize_bits);
1026 1030 bool repaired = false;
1027 1031
1028 1032 if (scrub_bitmap_test_bit_is_metadata(stripe, sector_nr)) {
@@ -1051,12 +1055,12 @@ skip:
1051 1055 if (dev) {
1052 1056 btrfs_err_rl(fs_info,
1053 1057 "scrub: fixed up error at logical %llu on dev %s physical %llu",
1054 - stripe->logical, btrfs_dev_name(dev),
1055 - physical);
1058 + sector_logical, btrfs_dev_name(dev),
1059 + sector_physical);
1056 1060 } else {
1057 1061 btrfs_err_rl(fs_info,
1058 1062 "scrub: fixed up error at logical %llu on mirror %u",
1059 - stripe->logical, stripe->mirror_num);
1063 + sector_logical, stripe->mirror_num);
1060 1064 }
1061 1065 continue;
1062 1066 }
@@ -1065,30 +1069,30 @@ skip:
1065 1069 if (dev) {
1066 1070 btrfs_err_rl(fs_info,
1067 1071 "scrub: unable to fixup (regular) error at logical %llu on dev %s physical %llu",
1068 - stripe->logical, btrfs_dev_name(dev),
1069 - physical);
1072 + sector_logical, btrfs_dev_name(dev),
1073 + sector_physical);
1070 1074 } else {
1071 1075 btrfs_err_rl(fs_info,
1072 1076 "scrub: unable to fixup (regular) error at logical %llu on mirror %u",
1073 - stripe->logical, stripe->mirror_num);
1077 + sector_logical, stripe->mirror_num);
1074 1078 }
1075 1079
1076 1080 if (scrub_bitmap_test_bit_io_error(stripe, sector_nr))
1077 1081 if (__ratelimit(&rs) && dev)
1078 1082 scrub_print_common_warning("i/o error", dev, false,
1079 - stripe->logical, physical);
1083 + sector_logical, sector_physical);
1080 1084 if (scrub_bitmap_test_bit_csum_error(stripe, sector_nr))
1081 1085 if (__ratelimit(&rs) && dev)
1082 1086 scrub_print_common_warning("checksum error", dev, false,
1083 - stripe->logical, physical);
1087 + sector_logical, sector_physical);
1084 1088 if (scrub_bitmap_test_bit_meta_error(stripe, sector_nr))
1085 1089 if (__ratelimit(&rs) && dev)
1086 1090 scrub_print_common_warning("header error", dev, false,
1087 - stripe->logical, physical);
1091 + sector_logical, sector_physical);
1088 1092 if (scrub_bitmap_test_bit_meta_gen_error(stripe, sector_nr))
1089 1093 if (__ratelimit(&rs) && dev)
1090 1094 scrub_print_common_warning("generation error", dev, false,
1091 - stripe->logical, physical);
1095 + sector_logical, sector_physical);
1092 1096 }
1093 1097
1094 1098 /* Update the device stats. */
modified fs/btrfs/send.c
@@ -2065,7 +2065,7 @@ static int will_overwrite_ref(struct send_ctx *sctx, u64 dir, u64 dir_gen,
2065 2065
2066 2066 ret = is_inode_existent(sctx, dir, dir_gen, NULL, &parent_root_dir_gen);
2067 2067 if (ret <= 0)
2068 - return 0;
2068 + return ret;
2069 2069
2070 2070 /*
2071 2071 * If we have a parent root we need to verify that the parent dir was
@@ -6417,6 +6417,13 @@ static int process_extent(struct send_ctx *sctx,
6417 6417
6418 6418 if (S_ISLNK(sctx->cur_inode_mode))
6419 6419 return 0;
6420 + if (unlikely(!S_ISREG(sctx->cur_inode_mode))) {
6421 + btrfs_crit(sctx->send_root->fs_info,
6422 + "send: extent for non-regular inode %llu root %llu mode 0%llo",
6423 + key->objectid, btrfs_root_id(sctx->send_root),
6424 + sctx->cur_inode_mode & S_IFMT);
6425 + return -EUCLEAN;
6426 + }
6420 6427
6421 6428 if (sctx->parent_root && !sctx->cur_inode_new) {
6422 6429 ret = is_extent_unchanged(sctx, path, key);
modified fs/btrfs/tests/extent-io-tests.c
@@ -133,14 +133,14 @@ static int test_find_delalloc(u32 sectorsize, u32 nodesize)
133 133 if (IS_ERR(root)) {
134 134 test_std_err(TEST_ALLOC_ROOT);
135 135 ret = PTR_ERR(root);
136 - goto out;
136 + goto out_root_info;
137 137 }
138 138
139 139 inode = btrfs_new_test_inode();
140 140 if (!inode) {
141 141 test_std_err(TEST_ALLOC_INODE);
142 142 ret = -ENOMEM;
143 - goto out;
143 + goto out_root_info;
144 144 }
145 145 tmp = &BTRFS_I(inode)->io_tree;
146 146 BTRFS_I(inode)->root = root;
@@ -333,6 +333,7 @@ out:
333 333 process_page_range(inode, 0, total_dirty - 1,
334 334 PROCESS_UNLOCK | PROCESS_RELEASE);
335 335 iput(inode);
336 + out_root_info:
336 337 btrfs_free_dummy_root(root);
337 338 btrfs_free_dummy_fs_info(fs_info);
338 339 return ret;
modified fs/btrfs/transaction.c
@@ -458,8 +458,19 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
458 458 * through btrfs_record_root_in_trans without having to take the
459 459 * lock. smp_wmb() makes sure that all the writes above are
460 460 * done before we pop in the zero below
461 + *
462 + * If @force is true, it means the call is from
463 + * qgroup_account_snapshot(), which only requires radix tree
464 + * tracking.
465 + * We should not force reloc root creation here, as the root
466 + * may have already been modified, and in that case
467 + * root->commit_root has already been dropped.
468 + *
469 + * Using that commit root will cause the reloc root to refer
470 + * to a deleted extent, causing extent tree corruption.
461 471 */
462 - ret = btrfs_init_reloc_root(trans, root);
472 + if (!force)
473 + ret = btrfs_init_reloc_root(trans, root);
463 474 smp_mb__before_atomic();
464 475 clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state);
465 476 }
@@ -2583,6 +2594,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
2583 2594 ret = btrfs_write_and_wait_transaction(trans);
2584 2595 if (unlikely(ret)) {
2585 2596 btrfs_err(fs_info, "error while writing out transaction: %pe", ERR_PTR(ret));
2597 + /*
2598 + * Abort before releasing tree_log_mutex, so a log sync waiting
2599 + * on it sees the fs error and skips writing super_for_commit
2600 + * for this failed transaction. See btrfs_sync_log().
2601 + */
2602 + btrfs_abort_transaction(trans, ret);
2586 2603 mutex_unlock(&fs_info->tree_log_mutex);
2587 2604 goto scrub_continue;
2588 2605 }
modified fs/btrfs/volumes.c
@@ -3117,7 +3117,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
3117 3117 error_sysfs:
3118 3118 btrfs_sysfs_remove_device(device);
3119 3119 mutex_lock(&fs_info->fs_devices->device_list_mutex);
3120 + if (seeding_dev)
3121 + btrfs_assign_next_active_device(device, seed_devices->latest_dev);
3120 3122 mutex_lock(&fs_info->chunk_mutex);
3123 + if (!list_empty(&device->post_commit_list))
3124 + list_del_init(&device->post_commit_list);
3121 3125 list_del_rcu(&device->dev_list);
3122 3126 list_del(&device->dev_alloc_list);
3123 3127 fs_info->fs_devices->num_devices--;
modified fs/btrfs/zoned.c
@@ -2626,16 +2626,13 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
2626 2626 down_read(&dev_replace->rwsem);
2627 2627 map = block_group->physical_map;
2628 2628 for (i = 0; i < map->num_stripes; i++) {
2629 -
2630 2629 ret = call_zone_finish(block_group, &map->stripes[i]);
2631 - if (ret) {
2632 - up_read(&dev_replace->rwsem);
2633 - return ret;
2634 - }
2630 + if (ret)
2631 + break;
2635 2632 }
2636 2633 up_read(&dev_replace->rwsem);
2637 2634
2638 - if (!fully_written)
2635 + if (!ret && !fully_written)
2639 2636 btrfs_dec_block_group_ro(block_group);
2640 2637
2641 2638 spin_lock(&fs_info->zone_active_bgs_lock);
@@ -2648,7 +2645,7 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
2648 2645
2649 2646 clear_and_wake_up_bit(BTRFS_FS_NEED_ZONE_FINISH, &fs_info->flags);
2650 2647
2651 - return 0;
2648 + return ret;
2652 2649 }
2653 2650
2654 2651 int btrfs_zone_finish(struct btrfs_block_group *block_group)
@@ -2713,6 +2710,7 @@ int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 leng
2713 2710 {
2714 2711 struct btrfs_block_group *block_group;
2715 2712 u64 min_alloc_bytes;
2713 + int ret = 0;
2716 2714
2717 2715 if (!btrfs_is_zoned(fs_info))
2718 2716 return 0;
@@ -2732,11 +2730,11 @@ int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 leng
2732 2730 block_group->start + block_group->zone_capacity)
2733 2731 goto out;
2734 2732
2735 - do_zone_finish(block_group, true);
2733 + ret = do_zone_finish(block_group, true);
2736 2734
2737 2735 out:
2738 2736 btrfs_put_block_group(block_group);
2739 - return 0;
2737 + return ret;
2740 2738 }
2741 2739
2742 2740 static void btrfs_zone_finish_endio_workfn(struct work_struct *work)
modified fs/btrfs/zstd.c
@@ -307,8 +307,17 @@ again:
307 307 DEFINE_WAIT(wait);
308 308
309 309 prepare_to_wait(&zwsm->wait, &wait, TASK_UNINTERRUPTIBLE);
310 - schedule();
310 + /*
311 + * Re-check after being queued: zstd_put_workspace() only wakes
312 + * a queue that already has a sleeper, so a workspace returned
313 + * since the failed allocation woke nobody.
314 + */
315 + ws = zstd_find_workspace(fs_info, level);
316 + if (!ws)
317 + schedule();
311 318 finish_wait(&zwsm->wait, &wait);
319 + if (ws)
320 + return ws;
312 321
313 322 goto again;
314 323 }
modified fs/ceph/addr.c
@@ -2546,7 +2546,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
2546 2546 }
2547 2547
2548 2548 pool_ns_len = pool_ns ? pool_ns->len : 0;
2549 - perm = kmalloc_flex(*perm, pool_ns, pool_ns_len + 1, GFP_KERNEL);
2549 + perm = kmalloc_flex(*perm, pool_ns, pool_ns_len + 1);
2550 2550 if (!perm) {
2551 2551 err = -ENOMEM;
2552 2552 goto out_unlock;
modified fs/ceph/mds_client.c
@@ -5492,7 +5492,7 @@ static void ceph_mdsc_reset_workfn(struct work_struct *work)
5492 5492 goto out_complete;
5493 5493 }
5494 5494
5495 - sessions = kcalloc(max_sessions, sizeof(*sessions), GFP_KERNEL);
5495 + sessions = kzalloc_objs(*sessions, max_sessions);
5496 5496 if (!sessions) {
5497 5497 mutex_unlock(&mdsc->mutex);
5498 5498 ret = -ENOMEM;
@@ -6600,11 +6600,13 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
6600 6600 doutc(cl, "tpath '%s', mask %d, caller_uid %d, caller_gid %d\n",
6601 6601 tpath, mask, caller_uid, caller_gid);
6602 6602
6603 + mutex_lock(&mdsc->mutex);
6603 6604 for (i = 0; i < mdsc->s_cap_auths_num; i++) {
6604 6605 struct ceph_mds_cap_auth *s = &mdsc->s_cap_auths[i];
6605 6606
6606 6607 err = ceph_mds_auth_match(mdsc, s, cred, tpath);
6607 6608 if (err < 0) {
6609 + mutex_unlock(&mdsc->mutex);
6608 6610 put_cred(cred);
6609 6611 return err;
6610 6612 } else if (err > 0) {
@@ -6626,6 +6628,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
6626 6628 doutc(cl, "root_squash_perms %d, rw_perms_s %p\n", root_squash_perms,
6627 6629 rw_perms_s);
6628 6630 if (root_squash_perms && rw_perms_s == NULL) {
6631 + mutex_unlock(&mdsc->mutex);
6629 6632 doutc(cl, "access allowed\n");
6630 6633 return 0;
6631 6634 }
@@ -6640,6 +6643,7 @@ int ceph_mds_check_access(struct ceph_mds_client *mdsc, char *tpath, int mask)
6640 6643 !!(mask & MAY_READ), !!(mask & MAY_WRITE));
6641 6644 }
6642 6645 doutc(cl, "access denied\n");
6646 + mutex_unlock(&mdsc->mutex);
6643 6647 return -EACCES;
6644 6648 }
6645 6649
modified fs/ceph/mds_client.h
@@ -604,6 +604,7 @@ struct ceph_mds_client {
604 604 struct rw_semaphore pool_perm_rwsem;
605 605 struct rb_root pool_perm_tree;
606 606
607 + /* protected by mutex */
607 608 u32 s_cap_auths_num;
608 609 struct ceph_mds_cap_auth *s_cap_auths;
609 610
modified fs/ceph/subvolume_metrics.c
@@ -245,7 +245,7 @@ int ceph_subvolume_metrics_snapshot(struct ceph_subvolume_metrics_tracker *track
245 245 return 0;
246 246 }
247 247
248 - snap = kcalloc(count, sizeof(*snap), GFP_NOFS);
248 + snap = kzalloc_objs(*snap, count, GFP_NOFS);
249 249 if (!snap) {
250 250 atomic64_inc(&tracker->snapshot_failures);
251 251 return -ENOMEM;
modified fs/ceph/super.c
@@ -1420,6 +1420,11 @@ static int ceph_reconfigure_fc(struct fs_context *fc)
1420 1420 else
1421 1421 ceph_clear_mount_opt(fsc, SPARSEREAD);
1422 1422
1423 + if (fsopt->flags & CEPH_MOUNT_OPT_NEARFULL_SYNC)
1424 + ceph_set_mount_opt(fsc, NEARFULL_SYNC);
1425 + else
1426 + ceph_clear_mount_opt(fsc, NEARFULL_SYNC);
1427 +
1423 1428 if (strcmp_null(fsc->mount_options->mon_addr, fsopt->mon_addr)) {
1424 1429 kfree(fsc->mount_options->mon_addr);
1425 1430 fsc->mount_options->mon_addr = fsopt->mon_addr;
modified fs/configfs/mount.c
@@ -9,6 +9,7 @@
9 9 */
10 10
11 11 #include <linux/fs.h>
12 + #include <linux/magic.h>
12 13 #include <linux/module.h>
13 14 #include <linux/mount.h>
14 15 #include <linux/fs_context.h>
@@ -19,9 +20,6 @@
19 20 #include <linux/configfs.h>
20 21 #include "configfs_internal.h"
21 22
22 - /* Random magic number */
23 - #define CONFIGFS_MAGIC 0x62656570
24 -
25 23 static struct vfsmount *configfs_mount = NULL;
26 24 struct kmem_cache *configfs_dir_cachep;
27 25 static int configfs_mnt_count = 0;
modified fs/coredump.c
@@ -1000,7 +1000,7 @@ static bool coredump_pipe(struct core_name *cn, struct coredump_params *cprm,
1000 1000 return false;
1001 1001 }
1002 1002
1003 - helper_argv = kmalloc_array(argc + 1, sizeof(*helper_argv), GFP_KERNEL);
1003 + helper_argv = kmalloc_objs(*helper_argv, argc + 1);
1004 1004 if (!helper_argv) {
1005 1005 coredump_report_failure("%s failed to allocate memory", __func__);
1006 1006 return false;
modified fs/ext4/fast_commit.c
@@ -1116,7 +1116,7 @@ static int ext4_fc_snapshot_inode(struct inode *inode,
1116 1116 else if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE)
1117 1117 inode_len += ei->i_extra_isize;
1118 1118
1119 - snap = kmalloc(struct_size(snap, inode_buf, inode_len), GFP_NOFS);
1119 + snap = kmalloc_flex(*snap, inode_buf, inode_len, GFP_NOFS);
1120 1120 if (!snap) {
1121 1121 atomic64_inc(&stats->snap_fail_nomem);
1122 1122 ext4_fc_set_snap_err(snap_err, EXT4_FC_SNAP_ERR_NOMEM);
@@ -1522,7 +1522,7 @@ static int ext4_fc_alloc_snapshot_inodes(struct super_block *sb,
1522 1522 if (nr_inodes > EXT4_FC_SNAPSHOT_MAX_INODES)
1523 1523 return -E2BIG;
1524 1524
1525 - inodes = kvcalloc(nr_inodes, sizeof(*inodes), GFP_NOFS);
1525 + inodes = kvzalloc_objs(*inodes, nr_inodes, GFP_NOFS);
1526 1526 if (!inodes)
1527 1527 return -ENOMEM;
1528 1528
modified fs/fuse/file.c
@@ -1597,8 +1597,7 @@ static int fuse_get_user_pages(struct fuse_args_pages *ap, struct iov_iter *ii,
1597 1597 * manually extract pages using iov_iter_extract_pages() and then
1598 1598 * copy that to a folios array.
1599 1599 */
1600 - struct page **pages = kcalloc(max_pages, sizeof(struct page *),
1601 - GFP_KERNEL);
1600 + struct page **pages = kzalloc_objs(struct page *, max_pages);
1602 1601 if (!pages) {
1603 1602 ret = -ENOMEM;
1604 1603 goto out;
modified fs/fuse/readdir.c
@@ -336,7 +336,7 @@ static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
336 336 static struct page **fuse_readdir_alloc_buf(struct fuse_args_pages *ap, size_t *bufsize)
337 337 {
338 338 unsigned int i, nr_alloc, nr_pages = DIV_ROUND_UP(*bufsize, PAGE_SIZE);
339 - struct page **pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
339 + struct page **pages = kzalloc_objs(*pages, nr_pages);
340 340
341 341 if (!pages)
342 342 return NULL;
modified fs/hfs/bnode.c
@@ -312,7 +312,7 @@ static struct hfs_bnode *__hfs_bnode_create(struct hfs_btree *tree, u32 cnid)
312 312 return NULL;
313 313 }
314 314
315 - node = kzalloc_flex(*node, page, tree->pages_per_bnode, GFP_KERNEL);
315 + node = kzalloc_flex(*node, page, tree->pages_per_bnode);
316 316 if (!node)
317 317 return NULL;
318 318 node->tree = tree;
modified fs/kernfs/inode.c
@@ -142,10 +142,8 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
142 142 struct kernfs_iattrs *attrs;
143 143
144 144 attrs = kernfs_iattrs_noalloc(kn);
145 - if (!attrs)
146 - return 0;
147 145
148 - return simple_xattr_list(d_inode(dentry), &attrs->xattrs, buf, size);
146 + return simple_xattr_list(d_inode(dentry), attrs ? &attrs->xattrs : NULL, buf, size);
149 147 }
150 148
151 149 static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
modified fs/namespace.c
@@ -5999,7 +5999,7 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
5999 5999 return -EPERM;
6000 6000 }
6001 6001
6002 - ks = kmalloc(sizeof(*ks), GFP_KERNEL_ACCOUNT);
6002 + ks = kmalloc_obj(*ks, GFP_KERNEL_ACCOUNT);
6003 6003 if (!ks)
6004 6004 return -ENOMEM;
6005 6005
modified fs/nfsd/export.c
@@ -358,7 +358,7 @@ int nfsd_nl_expkey_get_reqs_dumpit(struct sk_buff *skb,
358 358 goto out_unlock;
359 359 }
360 360
361 - items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
361 + items = kzalloc_objs(*items, cnt);
362 362 seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
363 363 if (!items || !seqnos) {
364 364 ret = -ENOMEM;
@@ -685,7 +685,7 @@ int nfsd_nl_svc_export_get_reqs_dumpit(struct sk_buff *skb,
685 685 goto out_unlock;
686 686 }
687 687
688 - items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
688 + items = kzalloc_objs(*items, cnt);
689 689 seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
690 690 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
691 691 if (!items || !seqnos || !pathbuf) {
@@ -786,8 +786,7 @@ static int nfsd_nl_parse_fslocations(struct nlattr *attr,
786 786 if (!count)
787 787 return 0;
788 788
789 - fsloc->locations = kcalloc(count, sizeof(struct nfsd4_fs_location),
790 - GFP_KERNEL);
789 + fsloc->locations = kzalloc_objs(struct nfsd4_fs_location, count);
791 790 if (!fsloc->locations)
792 791 return -ENOMEM;
793 792
modified fs/nfsd/nfs4callback.c
@@ -1981,12 +1981,12 @@ int nfsd_net_cb_init(struct nfsd_net *nn)
1981 1981 {
1982 1982 struct nfsd_net_cb *cb;
1983 1983
1984 - cb = kzalloc(sizeof(*cb), GFP_KERNEL);
1984 + cb = kzalloc_obj(*cb);
1985 1985 if (!cb)
1986 1986 return -ENOMEM;
1987 1987
1988 1988 cb->version4.counts = kzalloc_objs(unsigned int,
1989 - ARRAY_SIZE(nfs4_cb_procedures), GFP_KERNEL);
1989 + ARRAY_SIZE(nfs4_cb_procedures));
1990 1990 if (!cb->version4.counts) {
1991 1991 kfree(cb);
1992 1992 return -ENOMEM;
modified fs/nfsd/nfs4state.c
@@ -1341,7 +1341,7 @@ alloc_init_dir_deleg(struct nfs4_client *clp, struct nfs4_file *fp)
1341 1341 return NULL;
1342 1342 }
1343 1343
1344 - ncn->ncn_nf = kcalloc(NOTIFY4_EVENT_QUEUE_SIZE, sizeof(*ncn->ncn_nf), GFP_KERNEL);
1344 + ncn->ncn_nf = kzalloc_objs(*ncn->ncn_nf, NOTIFY4_EVENT_QUEUE_SIZE);
1345 1345 if (!ncn->ncn_nf) {
1346 1346 nfs4_put_stid(&dp->dl_stid);
1347 1347 return NULL;
@@ -10419,8 +10419,9 @@ alloc_nfsd_notify_event(u32 mask, const struct qstr *q, struct dentry *dentry,
10419 10419 newnamelen = newname.name.len;
10420 10420 }
10421 10421
10422 - ne = kmalloc(struct_size(ne, ne_name, q->len + 1 +
10423 - (newnamelen ? newnamelen + 1 : 0)), GFP_NOFS);
10422 + ne = kmalloc_flex(*ne, ne_name,
10423 + q->len + 1 + (newnamelen ? newnamelen + 1 : 0),
10424 + GFP_NOFS);
10424 10425 if (!ne)
10425 10426 goto out;
10426 10427
modified fs/nfsd/nfsctl.c
@@ -1647,7 +1647,7 @@ static int nfsd_nl_fh_key_set(const struct nlattr *attr, struct nfsd_net *nn)
1647 1647 k1 = get_unaligned_le64(nla_data(attr) + 8);
1648 1648
1649 1649 if (!fh_key) {
1650 - fh_key = kmalloc(sizeof(siphash_key_t), GFP_KERNEL);
1650 + fh_key = kmalloc_obj(siphash_key_t);
1651 1651 if (!fh_key) {
1652 1652 trace_nfsd_ctl_fh_key_set(false, -ENOMEM);
1653 1653 return -ENOMEM;
modified fs/ntfs/attrib.c
@@ -1737,8 +1737,8 @@ static struct attr_def *ntfs_attr_find_in_attrdef(const struct ntfs_volume *vol,
1737 1737 struct attr_def *ad;
1738 1738
1739 1739 WARN_ON(!type);
1740 - for (ad = vol->attrdef; (u8 *)ad - (u8 *)vol->attrdef <
1741 - vol->attrdef_size && ad->type; ++ad) {
1740 + for (ad = vol->attrdef; (u8 *)ad - (u8 *)vol->attrdef <=
1741 + vol->attrdef_size - (s32)sizeof(*ad) && ad->type; ++ad) {
1742 1742 /* We have not found it yet, carry on searching. */
1743 1743 if (likely(le32_to_cpu(ad->type) < le32_to_cpu(type)))
1744 1744 continue;
@@ -2500,7 +2500,7 @@ int ntfs_resident_attr_record_add(struct ntfs_inode *ni, __le32 type,
2500 2500 return offset;
2501 2501 put_err_out:
2502 2502 ntfs_attr_put_search_ctx(ctx);
2503 - return -EIO;
2503 + return err;
2504 2504 }
2505 2505
2506 2506 /*
@@ -2639,7 +2639,7 @@ static int ntfs_non_resident_attr_record_add(struct ntfs_inode *ni, __le32 type,
2639 2639 return offset;
2640 2640 put_err_out:
2641 2641 ntfs_attr_put_search_ctx(ctx);
2642 - return -1;
2642 + return err;
2643 2643 }
2644 2644
2645 2645 /*
@@ -5704,12 +5704,12 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, bo
5704 5704 lcn << vol->cluster_size_bits,
5705 5705 alloc_cnt <<
5706 5706 vol->cluster_size_bits);
5707 - if (err > 0)
5707 + if (err)
5708 5708 goto out;
5709 5709 }
5710 5710
5711 5711 if (signal_pending(current))
5712 - goto out;
5712 + goto signal_out;
5713 5713
5714 5714 vcn += alloc_cnt;
5715 5715 try_alloc_cnt -= alloc_cnt;
@@ -5730,7 +5730,7 @@ int ntfs_attr_fallocate(struct ntfs_inode *ni, loff_t start, loff_t byte_len, bo
5730 5730 up_write(&ni->runlist.lock);
5731 5731 mutex_unlock(&ni->mrec_lock);
5732 5732 if (err || signal_pending(current))
5733 - goto out;
5733 + goto signal_out;
5734 5734
5735 5735 vcn += alloc_cnt;
5736 5736 try_alloc_cnt -= alloc_cnt;
@@ -5756,4 +5756,8 @@ out_unmap:
5756 5756 mutex_unlock(&ni->mrec_lock);
5757 5757 out:
5758 5758 return err >= 0 ? 0 : err;
5759 + signal_out:
5760 + if (!err)
5761 + err = -EINTR;
5762 + goto out;
5759 5763 }
modified fs/ntfs/bdev-io.c
@@ -34,7 +34,7 @@ int ntfs_bdev_read(struct block_device *bdev, char *data, loff_t start, size_t s
34 34 int error;
35 35 struct bio *bio;
36 36 blk_opf_t op;
37 - sector_t sector = start >> SECTOR_SHIFT;
37 + sector_t sector = ntfs_bytes_to_bio_sector(start);
38 38
39 39 if (start & (SECTOR_SIZE - 1))
40 40 return -EINVAL;
modified fs/ntfs/bitmap.c
@@ -40,7 +40,7 @@ int ntfs_trim_fs(struct ntfs_volume *vol, struct fstrim_range *range)
40 40 end_cluster = vol->nr_clusters;
41 41 }
42 42
43 - ra = kzalloc(sizeof(*ra), GFP_NOFS);
43 + ra = kzalloc_obj(*ra, GFP_NOFS);
44 44 if (!ra)
45 45 return -ENOMEM;
46 46
@@ -64,7 +64,7 @@ int ntfs_trim_fs(struct ntfs_volume *vol, struct fstrim_range *range)
64 64
65 65 end = start_buf;
66 66 while (end < end_buf) {
67 - u64 aligned_start, aligned_count;
67 + u64 aligned_start, aligned_end, aligned_count;
68 68 u64 start = find_next_zero_bit(bitmap, end_buf - start_buf,
69 69 end - start_buf) + start_buf;
70 70 if (start >= end_buf)
@@ -74,8 +74,10 @@ int ntfs_trim_fs(struct ntfs_volume *vol, struct fstrim_range *range)
74 74 start - start_buf) + start_buf;
75 75
76 76 aligned_start = ALIGN(ntfs_cluster_to_bytes(vol, start), dq);
77 - aligned_count =
78 - ALIGN_DOWN(ntfs_cluster_to_bytes(vol, end - start), dq);
77 + aligned_end = ALIGN_DOWN(ntfs_cluster_to_bytes(vol, end), dq);
78 + if (aligned_start >= aligned_end)
79 + continue;
80 + aligned_count = aligned_end - aligned_start;
79 81 if (aligned_count >= range->minlen) {
80 82 ret = blkdev_issue_discard(vol->sb->s_bdev, aligned_start >> 9,
81 83 aligned_count >> 9, GFP_NOFS);
modified fs/ntfs/compress.c
@@ -514,8 +514,8 @@ int ntfs_read_compressed_block(struct folio *folio)
514 514 return -EIO;
515 515 }
516 516
517 - pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_NOFS);
518 - completed_pages = kmalloc_array(nr_pages + 1, sizeof(int), GFP_NOFS);
517 + pages = kmalloc_objs(struct page *, nr_pages, GFP_NOFS);
518 + completed_pages = kmalloc_objs(int, nr_pages + 1, GFP_NOFS);
519 519
520 520 if (unlikely(!pages || !completed_pages)) {
521 521 kfree(pages);
@@ -1262,7 +1262,7 @@ static int ntfs_compress_workspace_init(struct ntfs_inode *ni,
1262 1262 size = ni->itype.compressed.block_size + 2 *
1263 1263 (ni->itype.compressed.block_size / NTFS_SB_SIZE) + 2;
1264 1264 ws->nr_pages = DIV_ROUND_UP(size, PAGE_SIZE);
1265 - ws->pages = kcalloc(ws->nr_pages, sizeof(*ws->pages), GFP_NOFS);
1265 + ws->pages = kzalloc_objs(*ws->pages, ws->nr_pages, GFP_NOFS);
1266 1266 if (!ws->pages)
1267 1267 return -ENOMEM;
1268 1268
@@ -1414,7 +1414,7 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,
1414 1414 bio_pos = ntfs_cluster_to_bytes(vol, bio_lcn);
1415 1415 bio = bio_alloc(vol->sb->s_bdev, DIV_ROUND_UP(bio_size, PAGE_SIZE),
1416 1416 REQ_OP_WRITE, GFP_NOIO);
1417 - bio->bi_iter.bi_sector = ntfs_bytes_to_sector(vol, bio_pos);
1417 + bio->bi_iter.bi_sector = ntfs_bytes_to_bio_sector(bio_pos);
1418 1418
1419 1419 for (i = 0; bio_size; i++) {
1420 1420 unsigned int len = min_t(unsigned int, bio_size, PAGE_SIZE);
@@ -1483,7 +1483,7 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
1483 1483 pages_per_cb = DIV_ROUND_UP(offset_in_page(pos & ~(cb_size - 1)) +
1484 1484 cb_size, PAGE_SIZE);
1485 1485
1486 - pages = kmalloc_array(pages_per_cb, sizeof(struct page *), GFP_NOFS);
1486 + pages = kmalloc_objs(struct page *, pages_per_cb, GFP_NOFS);
1487 1487 if (!pages)
1488 1488 return -ENOMEM;
1489 1489 ctx = kvzalloc_obj(*ctx, GFP_NOFS);
modified fs/ntfs/dir.c
@@ -166,8 +166,8 @@ found_it:
166 166 */
167 167 if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
168 168 if (!name) {
169 - name = kmalloc(sizeof(struct ntfs_name),
170 - GFP_NOFS);
169 + name = kmalloc_obj(struct ntfs_name,
170 + GFP_NOFS);
171 171 if (!name) {
172 172 err = -ENOMEM;
173 173 goto err_out;
@@ -401,8 +401,8 @@ found_it2:
401 401 */
402 402 if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
403 403 if (!name) {
404 - name = kmalloc(sizeof(struct ntfs_name),
405 - GFP_NOFS);
404 + name = kmalloc_obj(struct ntfs_name,
405 + GFP_NOFS);
406 406 if (!name) {
407 407 err = -ENOMEM;
408 408 goto unm_err_out;
@@ -700,7 +700,7 @@ static int ntfs_ia_blocks_readahead(struct ntfs_inode *ia_ni, loff_t pos)
700 700 if (dir_start_index >= dir_end_index)
701 701 return 0;
702 702
703 - dir_ra = kzalloc(sizeof(*dir_ra), GFP_NOFS);
703 + dir_ra = kzalloc_obj(*dir_ra, GFP_NOFS);
704 704 if (!dir_ra)
705 705 return -ENOMEM;
706 706
@@ -777,7 +777,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
777 777 return -ENOMEM;
778 778 }
779 779
780 - ra = kzalloc(sizeof(struct file_ra_state), GFP_NOFS);
780 + ra = kzalloc_obj(struct file_ra_state, GFP_NOFS);
781 781 if (!ra) {
782 782 kfree(name);
783 783 ntfs_index_ctx_put(ictx);
@@ -813,7 +813,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
813 813 goto out;
814 814 }
815 815 } else if (!private) {
816 - private = kzalloc(sizeof(struct ntfs_file_private), GFP_KERNEL);
816 + private = kzalloc_obj(struct ntfs_file_private);
817 817 if (!private) {
818 818 err = -ENOMEM;
819 819 goto out;
@@ -949,7 +949,7 @@ nextdir:
949 949 }
950 950
951 951 if (!nir) {
952 - nir = kzalloc(sizeof(struct ntfs_index_ra), GFP_KERNEL);
952 + nir = kzalloc_obj(struct ntfs_index_ra);
953 953 if (nir) {
954 954 nir->start_index = index;
955 955 nir->count = 1;
modified fs/ntfs/ea.c
@@ -235,7 +235,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
235 235 ea_info_qsize = le32_to_cpu(p_ea_info->ea_query_length);
236 236 } else {
237 237 create_ea_info:
238 - p_ea_info = kzalloc(sizeof(struct ea_information), GFP_NOFS);
238 + p_ea_info = kzalloc_obj(struct ea_information, GFP_NOFS);
239 239 if (!p_ea_info)
240 240 return -ENOMEM;
241 241
@@ -404,10 +404,12 @@ alloc_new_ea:
404 404 *packed_ea_size = p_ea_info->ea_length;
405 405 mark_mft_record_dirty(ni);
406 406 out:
407 - if (ea_info_qsize > 0)
408 - NInoSetHasEA(ni);
409 - else
410 - NInoClearHasEA(ni);
407 + if (!err) {
408 + if (ea_info_qsize > 0)
409 + NInoSetHasEA(ni);
410 + else
411 + NInoClearHasEA(ni);
412 + }
411 413
412 414 kvfree(ea_buf);
413 415 kvfree(old_ea_buf);
@@ -615,7 +617,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler,
615 617 if (!buffer) {
616 618 err = sizeof(u8);
617 619 } else if (size < sizeof(u8)) {
618 - err = -ENODATA;
620 + err = -ERANGE;
619 621 } else {
620 622 err = sizeof(u8);
621 623 *(u8 *)buffer = (u8)(le32_to_cpu(ni->flags) & 0x3F);
@@ -628,7 +630,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler,
628 630 if (!buffer) {
629 631 err = sizeof(u32);
630 632 } else if (size < sizeof(u32)) {
631 - err = -ENODATA;
633 + err = -ERANGE;
632 634 } else {
633 635 err = sizeof(u32);
634 636 *(u32 *)buffer = le32_to_cpu(ni->flags);
@@ -753,18 +755,39 @@ static int ntfs_new_attr_flags(struct ntfs_inode *ni, __le32 fattr)
753 755 old_arec_size = le32_to_cpu(a->length);
754 756
755 757 /*
756 - * Move payloads before shrinking the record. Otherwise resizing moves
758 + * Move payloads before shrinking the record. Otherwise resizing moves
757 759 * the following attribute over the old payload before it can be copied.
760 + *
761 + * When offsets increase, move mapping_pairs first to avoid name
762 + * overwriting the start of mapping_pairs.
758 763 */
759 764 if (arec_size < old_arec_size) {
760 - if (a->name_length && name_ofs != old_name_ofs)
761 - memmove((u8 *)a + name_ofs, (u8 *)a + old_name_ofs,
762 - a->name_length * sizeof(__le16));
763 - if (mp_ofs != old_mp_ofs)
764 - memmove((u8 *)a + mp_ofs, (u8 *)a + old_mp_ofs, mp_size);
765 + if (name_ofs > old_name_ofs) {
766 + /* Payload offsets increased: move mapping pairs first. */
767 + if (mp_ofs != old_mp_ofs)
768 + memmove((u8 *)a + mp_ofs,
769 + (u8 *)a + old_mp_ofs,
770 + mp_size);
771 + if (a->name_length && name_ofs != old_name_ofs)
772 + memmove((u8 *)a + name_ofs,
773 + (u8 *)a + old_name_ofs,
774 + a->name_length *
775 + sizeof(__le16));
776 + } else {
777 + /* Payload offsets decreased or unchanged: move name first. */
778 + if (a->name_length && name_ofs != old_name_ofs)
779 + memmove((u8 *)a + name_ofs,
780 + (u8 *)a + old_name_ofs,
781 + a->name_length *
782 + sizeof(__le16));
783 + if (mp_ofs != old_mp_ofs)
784 + memmove((u8 *)a + mp_ofs,
785 + (u8 *)a + old_mp_ofs,
786 + mp_size);
787 + }
765 788 }
766 789
767 - err = ntfs_attr_record_resize(m, a, arec_size);
790 + err = ntfs_attr_record_resize(ctx->mrec, a, arec_size);
768 791 if (unlikely(err))
769 792 goto err_out;
770 793
modified fs/ntfs/file.c
@@ -270,18 +270,25 @@ static int ntfs_setattr_size(struct inode *vi, struct iattr *attr)
270 270 return err;
271 271
272 272 inode_dio_wait(vi);
273 +
274 + /*
275 + * Serialize with page faults and pagecache instantiation so that
276 + * readers cannot observe the size change until the attribute
277 + * updates below have completed.
278 + */
279 + filemap_invalidate_lock(vi->i_mapping);
273 280 if (attr->ia_size > old_size) {
274 281 truncate_pagecache(vi, old_size);
275 282 i_size_write(vi, attr->ia_size);
276 283 pagecache_isize_extended(vi, old_size, attr->ia_size);
277 - } else
284 + } else {
278 285 truncate_setsize(vi, attr->ia_size);
286 + }
279 287
280 288 err = ntfs_truncate_vfs(vi, attr->ia_size, old_size);
281 - if (err) {
289 + if (err)
282 290 i_size_write(vi, old_size);
283 - return err;
284 - }
291 + filemap_invalidate_unlock(vi->i_mapping);
285 292
286 293 return err;
287 294 }
@@ -669,6 +676,7 @@ out_lock:
669 676 static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
670 677 {
671 678 struct inode *inode = file_inode(vmf->vma->vm_file);
679 + struct address_space *mapping = inode->i_mapping;
672 680 vm_fault_t ret;
673 681
674 682 if (NInoWofCompressed(NTFS_I(inode)))
@@ -677,7 +685,14 @@ static vm_fault_t ntfs_filemap_page_mkwrite(struct vm_fault *vmf)
677 685 sb_start_pagefault(inode->i_sb);
678 686 file_update_time(vmf->vma->vm_file);
679 687
688 + /*
689 + * Serialize against truncate/fallocate which hold the lock
690 + * exclusively while invalidating pagecache and changing extents.
691 + */
692 + filemap_invalidate_lock_shared(mapping);
680 693 ret = iomap_page_mkwrite(vmf, &ntfs_page_mkwrite_iomap_ops, NULL);
694 + filemap_invalidate_unlock_shared(mapping);
695 +
681 696 sb_end_pagefault(inode->i_sb);
682 697 return ret;
683 698 }
@@ -1116,7 +1131,6 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t le
1116 1131 struct ntfs_volume *vol = ni->vol;
1117 1132 int err = 0;
1118 1133 loff_t old_size;
1119 - bool map_locked = false;
1120 1134
1121 1135 if (mode & ~(NTFS_FALLOC_FL_SUPPORTED))
1122 1136 return -EOPNOTSUPP;
@@ -1148,16 +1162,13 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t le
1148 1162
1149 1163 inode_lock(vi);
1150 1164 if (NInoCompressed(ni) || NInoEncrypted(ni) || NInoWofCompressed(ni)) {
1151 - err = -EOPNOTSUPP;
1152 - goto out;
1165 + inode_unlock(vi);
1166 + return -EOPNOTSUPP;
1153 1167 }
1154 1168
1155 1169 inode_dio_wait(vi);
1156 - if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
1157 - FALLOC_FL_INSERT_RANGE)) {
1158 - filemap_invalidate_lock(vi->i_mapping);
1159 - map_locked = true;
1160 - }
1170 + /* Take invalidate_lock for all fallocate operations to prevent races */
1171 + filemap_invalidate_lock(vi->i_mapping);
1161 1172
1162 1173 switch (mode & FALLOC_FL_MODE_MASK) {
1163 1174 case FALLOC_FL_ALLOCATE_RANGE:
@@ -1182,14 +1193,15 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t offset, loff_t le
1182 1193
1183 1194 err = file_modified(file);
1184 1195 out:
1185 - if (map_locked)
1186 - filemap_invalidate_unlock(vi->i_mapping);
1196 + if (!err && mode == 0 && NInoNonResident(ni) &&
1197 + offset > old_size) {
1198 + truncate_pagecache(vi, old_size);
1199 + pagecache_isize_extended(vi, old_size, offset);
1200 + }
1201 +
1202 + filemap_invalidate_unlock(vi->i_mapping);
1203 +
1187 1204 if (!err) {
1188 - if (mode == 0 && NInoNonResident(ni) &&
1189 - offset > old_size) {
1190 - truncate_pagecache(vi, old_size);
1191 - pagecache_isize_extended(vi, old_size, offset);
1192 - }
1193 1205 NInoSetFileNameDirty(ni);
1194 1206 inode_set_mtime_to_ts(vi, inode_set_ctime_current(vi));
1195 1207 mark_inode_dirty(vi);
modified fs/ntfs/index.c
@@ -1660,7 +1660,7 @@ resplit:
1660 1660 goto out;
1661 1661 }
1662 1662 } else {
1663 - si = kzalloc(sizeof(struct split_info), GFP_NOFS);
1663 + si = kzalloc_obj(struct split_info, GFP_NOFS);
1664 1664 if (!si) {
1665 1665 ntfs_ibm_clear(icx, new_vcn);
1666 1666 ret = -ENOMEM;
modified fs/ntfs/inode.c
@@ -1852,7 +1852,7 @@ int ntfs_read_inode_mount(struct inode *vi)
1852 1852 struct mft_record *m = NULL;
1853 1853 struct attr_record *a;
1854 1854 struct ntfs_attr_search_ctx *ctx;
1855 - unsigned int i, nr_blocks;
1855 + unsigned int i;
1856 1856 int err;
1857 1857 size_t new_rl_count;
1858 1858
@@ -1896,11 +1896,6 @@ int ntfs_read_inode_mount(struct inode *vi)
1896 1896 goto err_out;
1897 1897 }
1898 1898
1899 - /* Determine the first block of the $MFT/$DATA attribute. */
1900 - nr_blocks = ntfs_bytes_to_sector(vol, vol->mft_record_size);
1901 - if (!nr_blocks)
1902 - nr_blocks = 1;
1903 -
1904 1899 /* Load $MFT/$DATA's first mft record. */
1905 1900 err = ntfs_bdev_read(sb->s_bdev, (char *)m,
1906 1901 ntfs_cluster_to_bytes(vol, vol->mft_lcn), i);
@@ -3780,8 +3775,7 @@ static s64 __ntfs_inode_non_resident_attr_pwrite(struct inode *vi,
3780 3775 bio = bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE,
3781 3776 GFP_NOIO);
3782 3777 bio->bi_iter.bi_sector =
3783 - ntfs_bytes_to_sector(vol,
3784 - ntfs_cluster_to_bytes(vol, lcn) +
3778 + ntfs_bytes_to_bio_sector(ntfs_cluster_to_bytes(vol, lcn) +
3785 3779 lcn_folio_off);
3786 3780
3787 3781 length = min_t(unsigned long,
modified fs/ntfs/lcnalloc.c
@@ -53,10 +53,10 @@ int ntfs_cluster_free_from_rl_nolock(struct ntfs_volume *vol,
53 53 if (rl->lcn < 0)
54 54 continue;
55 55 err = ntfs_bitmap_clear_run(lcnbmp_vi, rl->lcn, rl->length);
56 - if (unlikely(err && (!ret || ret == -ENOMEM) && ret != err))
57 - ret = err;
58 - else
56 + if (likely(!err))
59 57 nr_freed += rl->length;
58 + else if (!ret || ret == -ENOMEM)
59 + ret = err;
60 60 }
61 61 ntfs_inc_free_clusters(vol, nr_freed);
62 62 ntfs_debug("Done.");
@@ -1045,8 +1045,9 @@ err_out:
1045 1045 "Failed to rollback (error %i). Leaving inconsistent metadata! Unmount and run chkdsk.",
1046 1046 (int)delta);
1047 1047 NVolSetErrors(vol);
1048 + } else {
1049 + ntfs_dec_free_clusters(vol, delta);
1048 1050 }
1049 - ntfs_dec_free_clusters(vol, delta);
1050 1051 up_write(&vol->lcnbmp_lock);
1051 1052 memalloc_nofs_restore(memalloc_flags);
1052 1053 ntfs_error(vol->sb, "Aborting (error %i).", err);
modified fs/ntfs/logfile.c
@@ -691,7 +691,7 @@ map_vcn:
691 691
692 692 memset(empty_buf, 0xff, vol->cluster_size);
693 693
694 - ra = kzalloc(sizeof(*ra), GFP_NOFS);
694 + ra = kzalloc_obj(*ra, GFP_NOFS);
695 695 if (!ra)
696 696 goto err;
697 697
modified fs/ntfs/mft.c
@@ -499,8 +499,8 @@ int ntfs_sync_mft_mirror(struct ntfs_volume *vol, const u64 mft_no,
499 499
500 500 bio = bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE, GFP_NOIO);
501 501 bio->bi_iter.bi_sector =
502 - NTFS_B_TO_SECTOR(vol, NTFS_CLU_TO_B(vol, vol->mftmirr_lcn) +
503 - lcn_folio_off + folio_ofs);
502 + ntfs_bytes_to_bio_sector(NTFS_CLU_TO_B(vol, vol->mftmirr_lcn) +
503 + lcn_folio_off + folio_ofs);
504 504
505 505 if (bio_add_folio(bio, folio, vol->mft_record_size, folio_ofs))
506 506 err = submit_bio_wait(bio);
@@ -580,7 +580,7 @@ int write_mft_record_nolock(struct ntfs_inode *ni, struct mft_record *m, int syn
580 580 err = pre_write_mst_fixup((struct ntfs_record *)fixup_m, vol->mft_record_size);
581 581 if (err) {
582 582 ntfs_error(vol->sb, "Failed to apply mst fixups!");
583 - goto err_out;
583 + goto unmap_err_out;
584 584 }
585 585
586 586 folio_size = vol->mft_record_size / ni->mft_lcn_count;
@@ -592,8 +592,8 @@ int write_mft_record_nolock(struct ntfs_inode *ni, struct mft_record *m, int syn
592 592
593 593 bio = bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE, GFP_NOIO);
594 594 bio->bi_iter.bi_sector =
595 - NTFS_B_TO_SECTOR(vol, NTFS_CLU_TO_B(vol, ni->mft_lcn[i]) +
596 - clu_off);
595 + ntfs_bytes_to_bio_sector(NTFS_CLU_TO_B(vol, ni->mft_lcn[i]) +
596 + clu_off);
597 597
598 598 if (!bio_add_folio(bio, folio, folio_size,
599 599 ni->folio_ofs + offset)) {
@@ -645,6 +645,8 @@ done:
645 645 return 0;
646 646 put_bio_out:
647 647 bio_put(bio);
648 + unmap_err_out:
649 + kunmap_local(kaddr);
648 650 err_out:
649 651 /*
650 652 * The caller should mark the base inode as bad so no more I/O
@@ -2633,11 +2635,13 @@ static int ntfs_write_mft_block(struct folio *folio, struct writeback_control *w
2633 2635 struct ntfs_inode *ni = NTFS_I(vi);
2634 2636 struct ntfs_volume *vol = ni->vol;
2635 2637 u8 *kaddr;
2636 - struct ntfs_inode **locked_nis __free(kfree) = kmalloc_array(PAGE_SIZE / NTFS_BLOCK_SIZE,
2637 - sizeof(struct ntfs_inode *), GFP_NOFS);
2638 + struct ntfs_inode **locked_nis __free(kfree) = kmalloc_objs(struct ntfs_inode *,
2639 + PAGE_SIZE / NTFS_BLOCK_SIZE,
2640 + GFP_NOFS);
2638 2641 int nr_locked_nis = 0, err = 0, mft_ofs, prev_mft_ofs;
2639 - struct inode **ref_inos __free(kfree) = kmalloc_array(PAGE_SIZE / NTFS_BLOCK_SIZE,
2640 - sizeof(struct inode *), GFP_NOFS);
2642 + struct inode **ref_inos __free(kfree) = kmalloc_objs(struct inode *,
2643 + PAGE_SIZE / NTFS_BLOCK_SIZE,
2644 + GFP_NOFS);
2641 2645 int nr_ref_inos = 0;
2642 2646 struct bio *bio = NULL;
2643 2647 u64 mft_no;
@@ -2740,8 +2744,8 @@ flush_bio:
2740 2744 bio = bio_alloc(vol->sb->s_bdev, 1, REQ_OP_WRITE,
2741 2745 GFP_NOIO);
2742 2746 bio->bi_iter.bi_sector =
2743 - ntfs_bytes_to_sector(vol,
2744 - ntfs_cluster_to_bytes(vol, lcn) + off);
2747 + ntfs_bytes_to_bio_sector(
2748 + ntfs_cluster_to_bytes(vol, lcn) + off);
2745 2749 }
2746 2750
2747 2751 if (vol->cluster_size == NTFS_BLOCK_SIZE &&
modified fs/ntfs/ntfs.h
@@ -19,6 +19,7 @@
19 19 #include <linux/nls.h>
20 20 #include <linux/smp.h>
21 21 #include <linux/pagemap.h>
22 + #include <linux/blk_types.h>
22 23 #include <linux/uidgid.h>
23 24
24 25 #include "volume.h"
@@ -71,8 +72,6 @@
71 72 #define NTFS_CLU_TO_POFS(vol, clu) (((u64)(clu) << (vol)->cluster_size_bits) & \
72 73 ~PAGE_MASK)
73 74
74 - #define NTFS_B_TO_SECTOR(vol, b) ((b) >> ((vol)->sb)->s_blocksize_bits)
75 -
76 75 enum {
77 76 NTFS_BLOCK_SIZE = 512,
78 77 NTFS_BLOCK_SIZE_BITS = 9,
@@ -154,11 +153,10 @@ static inline u64 ntfs_cluster_to_poff(const struct ntfs_volume *vol,
154 153 return (clu << vol->cluster_size_bits) & ~PAGE_MASK;
155 154 }
156 155
157 - /* Convert byte offset to sector (block) number. */
158 - static inline sector_t ntfs_bytes_to_sector(const struct ntfs_volume *vol,
159 - u64 bytes)
156 + /* Convert a byte offset on the volume to a bio sector number. */
157 + static inline sector_t ntfs_bytes_to_bio_sector(u64 bytes)
160 158 {
161 - return bytes >> vol->sb->s_blocksize_bits;
159 + return bytes >> SECTOR_SHIFT;
162 160 }
163 161
164 162 /* Global variables. */
modified fs/ntfs/reparse.c
@@ -405,7 +405,7 @@ unsigned int ntfs_reparse_tag_dt_types(struct ntfs_volume *vol, unsigned long mr
405 405
406 406 vi = ntfs_iget(vol->sb, mref);
407 407 if (IS_ERR(vi))
408 - return PTR_ERR(vi);
408 + return DT_UNKNOWN;
409 409
410 410 reparse_attr = (struct reparse_point *)ntfs_attr_readall(NTFS_I(vi),
411 411 AT_REPARSE_POINT, NULL, 0, &attr_size);
@@ -694,8 +694,9 @@ static int update_reparse_data(struct ntfs_inode *ni, struct ntfs_index_context
694 694 goto put_rp_inode;
695 695 }
696 696
697 - if (set_reparse_index(ni, xr, ((const struct reparse_point *)value)->reparse_tag) &&
698 - oldsize > 0) {
697 + err = set_reparse_index(ni, xr,
698 + ((const struct reparse_point *)value)->reparse_tag);
699 + if (err && oldsize > 0) {
699 700 /*
700 701 * If cannot index, try to remove the reparse
701 702 * data and log the error. There will be an
modified fs/ntfs/runlist.c
@@ -1804,7 +1804,7 @@ merge_src_rle:
1804 1804 new_2nd_cnt = src_cnt;
1805 1805 new_cnt = new_1st_cnt + new_2nd_cnt + new_3rd_cnt;
1806 1806 new_cnt += dst_rl_split.lcn >= LCN_HOLE ? 1 : 0;
1807 - new_rl = kvcalloc(new_cnt, sizeof(*new_rl), GFP_NOFS);
1807 + new_rl = kvzalloc_objs(*new_rl, new_cnt, GFP_NOFS);
1808 1808 if (!new_rl)
1809 1809 return ERR_PTR(-ENOMEM);
1810 1810
@@ -1888,13 +1888,13 @@ struct runlist_element *ntfs_rl_punch_hole(struct runlist_element *dst_rl, int d
1888 1888
1889 1889 punch_cnt = (int)(e_rl - s_rl) + 1;
1890 1890
1891 - *punch_rl = kvcalloc(punch_cnt + 1, sizeof(struct runlist_element),
1892 - GFP_NOFS);
1891 + *punch_rl = kvzalloc_objs(struct runlist_element, punch_cnt + 1,
1892 + GFP_NOFS);
1893 1893 if (!*punch_rl)
1894 1894 return ERR_PTR(-ENOMEM);
1895 1895
1896 1896 new_cnt = dst_cnt - (int)(e_rl - s_rl + 1) + 3;
1897 - new_rl = kvcalloc(new_cnt, sizeof(struct runlist_element), GFP_NOFS);
1897 + new_rl = kvzalloc_objs(struct runlist_element, new_cnt, GFP_NOFS);
1898 1898 if (!new_rl) {
1899 1899 kvfree(*punch_rl);
1900 1900 *punch_rl = NULL;
@@ -2038,13 +2038,13 @@ struct runlist_element *ntfs_rl_collapse_range(struct runlist_element *dst_rl, i
2038 2038 one_split_3 = e_rl == s_rl && begin_split && end_split;
2039 2039
2040 2040 punch_cnt = (int)(e_rl - s_rl) + 1;
2041 - *punch_rl = kvcalloc(punch_cnt + 1, sizeof(struct runlist_element),
2042 - GFP_NOFS);
2041 + *punch_rl = kvzalloc_objs(struct runlist_element, punch_cnt + 1,
2042 + GFP_NOFS);
2043 2043 if (!*punch_rl)
2044 2044 return ERR_PTR(-ENOMEM);
2045 2045
2046 2046 new_cnt = dst_cnt - (int)(e_rl - s_rl + 1) + 3;
2047 - new_rl = kvcalloc(new_cnt, sizeof(struct runlist_element), GFP_NOFS);
2047 + new_rl = kvzalloc_objs(struct runlist_element, new_cnt, GFP_NOFS);
2048 2048 if (!new_rl) {
2049 2049 kvfree(*punch_rl);
2050 2050 *punch_rl = NULL;
modified fs/ntfs/super.c
@@ -557,8 +557,8 @@ static bool is_boot_sector_ntfs(const struct super_block *sb,
557 557 * Check sectors per cluster value is valid and the cluster size
558 558 * is not above the maximum (2MB).
559 559 */
560 - if (b->bpb.sectors_per_cluster > 0x80 &&
561 - b->bpb.sectors_per_cluster < 0xf4)
560 + if (b->bpb.sectors_per_cluster < 0xf4 &&
561 + !is_power_of_2(b->bpb.sectors_per_cluster))
562 562 goto not_ntfs;
563 563
564 564 /* Check reserved/unused fields are really zero. */
@@ -695,7 +695,7 @@ static bool parse_ntfs_boot_sector(struct ntfs_volume *vol,
695 695 * = -log2(mft_record_size) bytes. mft_record_size normaly is
696 696 * 1024 bytes, which is encoded as 0xF6 (-10 in decimal).
697 697 */
698 - vol->mft_record_size = 1 << -clusters_per_mft_record;
698 + vol->mft_record_size = 1U << -clusters_per_mft_record;
699 699 vol->mft_record_size_mask = vol->mft_record_size - 1;
700 700 vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1;
701 701 ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size,
@@ -732,7 +732,7 @@ static bool parse_ntfs_boot_sector(struct ntfs_volume *vol,
732 732 * index_record_size normaly equals 4096 bytes, which is
733 733 * encoded as 0xF4 (-12 in decimal).
734 734 */
735 - vol->index_record_size = 1 << -clusters_per_index_record;
735 + vol->index_record_size = 1U << -clusters_per_index_record;
736 736 vol->index_record_size_mask = vol->index_record_size - 1;
737 737 vol->index_record_size_bits = ffs(vol->index_record_size) - 1;
738 738 ntfs_debug("vol->index_record_size = %i (0x%x)",
@@ -1241,9 +1241,9 @@ static bool load_and_init_attrdef(struct ntfs_volume *vol)
1241 1241 goto failed;
1242 1242 }
1243 1243 NInoSetSparseDisabled(NTFS_I(ino));
1244 - /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */
1244 + /* FILE_AttrDef must hold at least one entry and fit inside 31 bits. */
1245 1245 i_size = i_size_read(ino);
1246 - if (i_size <= 0 || i_size > 0x7fffffff)
1246 + if (i_size < (s64)sizeof(struct attr_def) || i_size > 0x7fffffff)
1247 1247 goto iput_failed;
1248 1248 vol->attrdef = kvzalloc(i_size, GFP_NOFS);
1249 1249 if (!vol->attrdef)
@@ -1862,7 +1862,8 @@ static int ntfs_sync_fs(struct super_block *sb, int wait)
1862 1862 return 0;
1863 1863
1864 1864 /* If there are some dirty buffers in the bdev inode */
1865 - if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) {
1865 + if (!NVolErrors(vol) &&
1866 + ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) {
1866 1867 ntfs_warning(sb, "Failed to clear dirty bit in volume information flags. Run chkdsk.");
1867 1868 err = -EIO;
1868 1869 }
@@ -2538,7 +2539,7 @@ static int ntfs_init_fs_context(struct fs_context *fc)
2538 2539 struct ntfs_volume *vol;
2539 2540
2540 2541 /* Allocate a new struct ntfs_volume and place it in sb->s_fs_info. */
2541 - vol = kmalloc(sizeof(struct ntfs_volume), GFP_NOFS);
2542 + vol = kmalloc_obj(struct ntfs_volume, GFP_NOFS);
2542 2543 if (!vol)
2543 2544 return -ENOMEM;
2544 2545
modified fs/ntfs/wof.c
@@ -39,8 +39,6 @@ struct ntfs_wof_workspace {
39 39 struct mutex *lock;
40 40 const struct ntfs_codec_ops *codec;
41 41 u32 comp_unit;
42 - void *input;
43 - size_t input_size;
44 42 void *output;
45 43 void *scratch;
46 44 };
@@ -97,30 +95,36 @@ static struct ntfs_wof_workspace *ntfs_wof_workspace(u8 block_size_bits)
97 95 }
98 96 }
99 97
98 + /*
99 + * Size of the buffer a chunk is read into. A chunk is read straight off the
100 + * device, so the buffer has to hold @comp_unit bytes plus the leading partial
101 + * sector.
102 + */
103 + static size_t ntfs_wof_input_size(const struct ntfs_wof_workspace *ws)
104 + {
105 + return round_up((size_t)ws->comp_unit + 511, 512);
106 + }
107 +
100 108 static int ntfs_wof_workspace_prepare(struct ntfs_wof_workspace *ws)
101 109 {
102 - void *input, *output, *scratch;
110 + void *output, *scratch;
103 111 size_t scratch_size;
104 112
105 - if (ws->input)
113 + if (ws->output)
106 114 return 0;
107 115
108 - ws->input_size = round_up((size_t)ws->comp_unit + 511, 512);
109 116 scratch_size = ws->codec->scratch_size(ws->comp_unit);
110 117 if (!scratch_size)
111 118 return -EINVAL;
112 119
113 - input = kvmalloc(ws->input_size, GFP_NOFS);
114 120 output = kvmalloc(ws->comp_unit, GFP_NOFS);
115 121 scratch = kvzalloc(scratch_size, GFP_NOFS);
116 - if (!input || !output || !scratch) {
117 - kvfree(input);
122 + if (!output || !scratch) {
118 123 kvfree(output);
119 124 kvfree(scratch);
120 125 return -ENOMEM;
121 126 }
122 127
123 - ws->input = input;
124 128 ws->output = output;
125 129 ws->scratch = scratch;
126 130 return 0;
@@ -134,10 +138,8 @@ void ntfs_wof_free_workspaces(void)
134 138 struct ntfs_wof_workspace *ws = ntfs_wof_workspaces[i];
135 139
136 140 mutex_lock(ws->lock);
137 - kvfree(ws->input);
138 141 kvfree(ws->output);
139 142 kvfree(ws->scratch);
140 - ws->input = NULL;
141 143 ws->output = NULL;
142 144 ws->scratch = NULL;
143 145 mutex_unlock(ws->lock);
@@ -602,6 +604,51 @@ static int ntfs_wof_try_direct(struct ntfs_wof_workspace *ws,
602 604 chunk_end, src, src_len, dst_len);
603 605 }
604 606
607 + /*
608 + * Decompress one chunk into @folio. Only this step needs the workspace, so it
609 + * is the only step that takes the workspace lock.
610 + */
611 + static int ntfs_wof_decompress_chunk(struct ntfs_wof_workspace *ws,
612 + struct ntfs_volume *vol,
613 + struct address_space *mapping,
614 + struct folio *folio, loff_t folio_start,
615 + loff_t folio_end, u64 chunk_file_offset,
616 + char *chunk_mem, u32 chunk_size,
617 + u32 decomp_size)
618 + {
619 + loff_t chunk_end = chunk_file_offset + decomp_size;
620 + loff_t copy_start, copy_end;
621 + int err;
622 +
623 + mutex_lock(ws->lock);
624 + err = ntfs_wof_workspace_prepare(ws);
625 + if (err)
626 + goto out_unlock;
627 +
628 + err = ntfs_wof_try_direct(ws, mapping, folio, chunk_file_offset,
629 + chunk_end, chunk_mem, chunk_size,
630 + decomp_size);
631 + if (err != -EAGAIN)
632 + goto out_unlock;
633 +
634 + err = ntfs_wof_decode(ws, chunk_mem, chunk_size, ws->output,
635 + decomp_size);
636 + if (err) {
637 + ntfs_error(vol->sb, "Decompression failed: %d", err);
638 + err = -EINVAL;
639 + goto out_unlock;
640 + }
641 +
642 + copy_start = max_t(loff_t, folio_start, chunk_file_offset);
643 + copy_end = min_t(loff_t, folio_end, chunk_file_offset + decomp_size);
644 + memcpy_to_folio(folio, copy_start - folio_start,
645 + ws->output + copy_start - chunk_file_offset,
646 + copy_end - copy_start);
647 + out_unlock:
648 + mutex_unlock(ws->lock);
649 + return err;
650 + }
651 +
605 652 int ntfs_read_wof_compressed_block(struct folio *folio)
606 653 {
607 654 struct address_space *mapping = folio->mapping;
@@ -613,6 +660,8 @@ int ntfs_read_wof_compressed_block(struct folio *folio)
613 660 loff_t folio_start = folio_pos(folio);
614 661 loff_t folio_end = folio_next_pos(folio);
615 662 char *chunk_mem;
663 + void *input;
664 + size_t input_size;
616 665 u32 decomp_size;
617 666 u64 chunk_count, chunk_idx, last_chunk, chunk_offset;
618 667 int err = 0;
@@ -652,10 +701,12 @@ int ntfs_read_wof_compressed_block(struct folio *folio)
652 701 goto out_iput;
653 702 }
654 703
655 - mutex_lock(ws->lock);
656 - err = ntfs_wof_workspace_prepare(ws);
657 - if (err)
658 - goto out_unlock_ws;
704 + input_size = ntfs_wof_input_size(ws);
705 + input = kvmalloc(input_size, GFP_NOFS);
706 + if (!input) {
707 + err = -ENOMEM;
708 + goto out_iput;
709 + }
659 710
660 711 chunk_idx = div_u64(folio_start, ws->comp_unit);
661 712 last_chunk =
@@ -663,55 +714,35 @@ int ntfs_read_wof_compressed_block(struct folio *folio)
663 714 chunk_count = DIV_ROUND_UP_ULL(i_size, ws->comp_unit);
664 715 for (; chunk_idx <= last_chunk; chunk_idx++) {
665 716 u32 chunk_size;
666 - u64 chunk_file_offset;
667 - loff_t chunk_end, copy_start, copy_end;
668 717
669 718 decomp_size = chunk_idx + 1 == chunk_count ?
670 719 i_size - chunk_idx * ws->comp_unit :
671 720 ws->comp_unit;
672 721 err = parse_wof_chunk_table(ni, wof_ni, chunk_idx, chunk_count,
673 722 decomp_size, &chunk_offset,
674 - &chunk_size, ws->input,
675 - ws->input_size);
723 + &chunk_size, input, input_size);
676 724 if (err)
677 - goto out_unlock_ws;
725 + goto out_free_input;
678 726
679 727 err = ntfs_read_wof_chunk(vol, wof_ni, chunk_offset, chunk_size,
680 - ws->input, ws->input_size,
681 - &chunk_mem);
728 + input, input_size, &chunk_mem);
682 729 if (err)
683 - goto out_unlock_ws;
684 -
685 - chunk_file_offset = chunk_idx * ws->comp_unit;
686 - chunk_end = chunk_file_offset + decomp_size;
687 - err = ntfs_wof_try_direct(ws, mapping, folio, chunk_file_offset,
688 - chunk_end, chunk_mem, chunk_size,
689 - decomp_size);
690 - if (!err)
691 - continue;
692 - if (err != -EAGAIN)
693 - goto out_unlock_ws;
730 + goto out_free_input;
694 731
695 - err = ntfs_wof_decode(ws, chunk_mem, chunk_size, ws->output,
696 - decomp_size);
697 - if (err) {
698 - ntfs_error(vol->sb, "Decompression failed: %d", err);
699 - err = -EINVAL;
700 - goto out_unlock_ws;
701 - }
702 - copy_start = max_t(loff_t, folio_start, chunk_file_offset);
703 - copy_end = min_t(loff_t, folio_end,
704 - chunk_file_offset + decomp_size);
705 - memcpy_to_folio(folio, copy_start - folio_start,
706 - ws->output + copy_start - chunk_file_offset,
707 - copy_end - copy_start);
732 + err = ntfs_wof_decompress_chunk(ws, vol, mapping, folio,
733 + folio_start, folio_end,
734 + chunk_idx * ws->comp_unit,
735 + chunk_mem, chunk_size,
736 + decomp_size);
737 + if (err)
738 + goto out_free_input;
708 739 }
709 740
710 741 if (folio_end > i_size)
711 742 folio_zero_segment(folio, i_size - folio_start,
712 743 folio_size(folio));
713 - out_unlock_ws:
714 - mutex_unlock(ws->lock);
744 + out_free_input:
745 + kvfree(input);
715 746 out_iput:
716 747 iput(wof_inode);
717 748 out:
modified fs/overlayfs/readdir.c
@@ -1044,7 +1044,7 @@ static int ovl_dir_open(struct inode *inode, struct file *file)
1044 1044 struct ovl_dir_file *od;
1045 1045 enum ovl_path_type type;
1046 1046
1047 - od = kzalloc(sizeof(struct ovl_dir_file), GFP_KERNEL);
1047 + od = kzalloc_obj(struct ovl_dir_file);
1048 1048 if (!od)
1049 1049 return -ENOMEM;
1050 1050
modified fs/quota/dquot.c
@@ -1240,7 +1240,7 @@ static int ignore_hardlimit(struct dquot *dquot)
1240 1240 {
1241 1241 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
1242 1242
1243 - return capable(CAP_SYS_RESOURCE) &&
1243 + return capable_noaudit(CAP_SYS_RESOURCE) &&
1244 1244 (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD ||
1245 1245 !(info->dqi_flags & DQF_ROOT_SQUASH));
1246 1246 }
modified fs/smb/client/cifs_swn.c
@@ -443,7 +443,7 @@ static struct cifs_swn_reg *cifs_get_swn_reg(struct cifs_tcon *tcon)
443 443 goto unlock;
444 444 }
445 445
446 - reg = kmalloc_obj(struct cifs_swn_reg, GFP_KERNEL);
446 + reg = kmalloc_obj(struct cifs_swn_reg);
447 447 if (reg == NULL) {
448 448 ret = -ENOMEM;
449 449 goto fail_unlock;
modified fs/smb/client/cifssmb.c
@@ -3555,6 +3555,7 @@ int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
3555 3555 int rc = 0;
3556 3556 int bytes_returned = 0;
3557 3557 __u16 params, byte_count, data_count, param_offset, offset;
3558 + size_t cifs_acl_size, bytes_available;
3558 3559
3559 3560 cifs_dbg(FYI, "In SetPosixACL (Unix) for path %s\n", fileName);
3560 3561 setAclRetry:
@@ -3574,8 +3575,7 @@ setAclRetry:
3574 3575 }
3575 3576 params = 6 + name_len;
3576 3577 pSMB->MaxParameterCount = cpu_to_le16(2);
3577 - /* BB find max SMB size from sess */
3578 - pSMB->MaxDataCount = cpu_to_le16(1000);
3578 + pSMB->MaxDataCount = cpu_to_le16(min_t(unsigned int, CIFSMaxBufSize, USHRT_MAX));
3579 3579 pSMB->MaxSetupCount = 0;
3580 3580 pSMB->Reserved = 0;
3581 3581 pSMB->Flags = 0;
@@ -3587,6 +3587,15 @@ setAclRetry:
3587 3587 parm_data = ((char *)pSMB) + offset;
3588 3588 pSMB->ParameterOffset = cpu_to_le16(param_offset);
3589 3589
3590 + /* make sure we can fit the larger cifs_posix_aces in the buffer */
3591 + cifs_acl_size = sizeof(struct cifs_posix_acl) +
3592 + (acl->a_count * sizeof(struct cifs_posix_ace));
3593 + bytes_available = (CIFSMaxBufSize + MAX_HEADER_SIZE(tcon->ses->server)) - offset;
3594 + if (cifs_acl_size > bytes_available || cifs_acl_size > USHRT_MAX) {
3595 + rc = -E2BIG;
3596 + goto setACLerrorExit;
3597 + }
3598 +
3590 3599 /* convert to on the wire format for POSIX ACL */
3591 3600 data_count = posix_acl_to_cifs(parm_data, acl, acl_type);
3592 3601
@@ -6325,8 +6334,10 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,
6325 6334 int name_len;
6326 6335 int rc = 0;
6327 6336 int bytes_returned = 0;
6328 - __u16 params, param_offset, byte_count, offset, count;
6337 + __u16 params, param_offset;
6338 + unsigned int byte_count, offset, count;
6329 6339 int remap = cifs_remap(cifs_sb);
6340 + unsigned int total_len;
6330 6341
6331 6342 cifs_dbg(FYI, "In SetEA\n");
6332 6343 SetEARetry:
@@ -6378,6 +6389,13 @@ SetEARetry:
6378 6389 pSMB->Reserved3 = 0;
6379 6390 pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);
6380 6391 byte_count = 3 /* pad */ + params + count;
6392 + if (check_add_overflow(in_len, byte_count, &total_len) ||
6393 + byte_count > U16_MAX ||
6394 + total_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
6395 + cifs_dbg(VFS, "EA request too large: %u bytes\n", total_len);
6396 + cifs_buf_release(pSMB);
6397 + return -E2BIG;
6398 + }
6381 6399 pSMB->DataCount = cpu_to_le16(count);
6382 6400 parm_data->list_len = cpu_to_le32(count);
6383 6401 parm_data->list.EA_flags = 0;
modified fs/smb/client/connect.c
@@ -4189,14 +4189,25 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
4189 4189 return rc;
4190 4190 }
4191 4191
4192 - static int
4193 - cifs_set_vol_auth(struct smb3_fs_context *ctx, struct cifs_ses *ses)
4192 + static int set_fs_context_auth(struct smb3_fs_context *ctx,
4193 + struct cifs_ses *ses)
4194 4194 {
4195 4195 ctx->sectype = ses->sectype;
4196 4196
4197 - /* krb5 is special, since we don't need username or pw */
4198 - if (ctx->sectype == Kerberos)
4197 + /*
4198 + * krb5 is special as we might need to pass username (passwordless) down
4199 + * to cifs.upcall(8) for keytab.
4200 + */
4201 + if (ctx->sectype == Kerberos) {
4202 + if (ses->user_name && ses->user_name[0]) {
4203 + ctx->username = kstrndup(ses->user_name,
4204 + CIFS_MAX_USERNAME_LEN,
4205 + GFP_KERNEL);
4206 + if (!ctx->username)
4207 + return -ENOMEM;
4208 + }
4199 4209 return 0;
4210 + }
4200 4211
4201 4212 return cifs_set_cifscreds(ctx, ses);
4202 4213 }
@@ -4236,7 +4247,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
4236 4247 ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses;
4237 4248 ctx->unicode = master_tcon->ses->unicode;
4238 4249
4239 - rc = cifs_set_vol_auth(ctx, master_tcon->ses);
4250 + rc = set_fs_context_auth(ctx, master_tcon->ses);
4240 4251 if (rc) {
4241 4252 tcon = ERR_PTR(rc);
4242 4253 goto out;
modified fs/smb/client/dfs_cache.c
@@ -365,7 +365,7 @@ static struct cache_dfs_tgt *alloc_target(const char *name, int path_consumed)
365 365 {
366 366 struct cache_dfs_tgt *t;
367 367
368 - t = kmalloc_obj(*t, GFP_KERNEL);
368 + t = kmalloc_obj(*t);
369 369 if (!t)
370 370 return ERR_PTR(-ENOMEM);
371 371 t->name = kstrdup(name, GFP_KERNEL);
modified fs/smb/client/file.c
@@ -999,26 +999,50 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry)
999 999 struct cifs_tcon *tcon;
1000 1000 int rc;
1001 1001
1002 - rc = filemap_write_and_wait(inode->i_mapping);
1003 - if (is_interrupt_error(rc))
1002 + rc = inode_lock_killable(inode);
1003 + if (rc)
1004 1004 return -ERESTARTSYS;
1005 +
1006 + filemap_invalidate_lock(inode->i_mapping);
1007 +
1008 + rc = filemap_write_and_wait(inode->i_mapping);
1009 + if (is_interrupt_error(rc)) {
1010 + rc = -ERESTARTSYS;
1011 + goto out;
1012 + }
1005 1013 mapping_set_error(inode->i_mapping, rc);
1006 1014
1007 1015 cfile = find_writable_file(cinode, FIND_FSUID_ONLY);
1008 1016 rc = cifs_file_flush(xid, inode, cfile);
1009 1017 if (!rc) {
1010 1018 if (cfile) {
1019 + struct netfs_inode *ictx = netfs_inode(inode);
1020 +
1011 1021 tcon = tlink_tcon(cfile->tlink);
1012 1022 server = tcon->ses->server;
1023 + netfs_wb_begin(ictx, false);
1013 1024 rc = server->ops->set_file_size(xid, tcon,
1014 1025 cfile, 0, false);
1015 - }
1016 - if (!rc) {
1017 - netfs_resize_file(&cinode->netfs, 0, true);
1018 - cifs_setsize(inode, 0);
1026 + if (!rc) {
1027 + netfs_resize_file(&cinode->netfs, 0, true);
1028 + cifs_setsize(inode, 0);
1029 + cifs_invalidate_cache(inode, 0);
1030 + }
1031 + netfs_wb_end(ictx);
1032 + } else {
1033 + /*
1034 + * No cached handle; evict stale pages so they can't
1035 + * be served after the file is later extended; let
1036 + * the server's O_TRUNC open response set the i_size
1037 + */
1038 + truncate_inode_pages(inode->i_mapping, 0);
1019 1039 cifs_invalidate_cache(inode, 0);
1020 1040 }
1021 1041 }
1042 +
1043 + out:
1044 + filemap_invalidate_unlock(inode->i_mapping);
1045 + inode_unlock(inode);
1022 1046 if (cfile)
1023 1047 cifsFileInfo_put(cfile);
1024 1048 return rc;
modified fs/smb/client/smb2inode.c
@@ -237,7 +237,7 @@ replay_again:
237 237 num_rqst = 0;
238 238 server = cifs_pick_channel(ses);
239 239
240 - vars = kzalloc_obj(*vars, GFP_KERNEL);
240 + vars = kzalloc_obj(*vars);
241 241 if (vars == NULL) {
242 242 rc = -ENOMEM;
243 243 goto out;
modified fs/smb/client/smb2ops.c
@@ -1839,31 +1839,31 @@ free_vars:
1839 1839 *
1840 1840 * @tcon: destination file tcon
1841 1841 * @bytes_left: how many bytes are left to copy
1842 + * @chunk_size: maximum size of a single chunk
1842 1843 *
1843 1844 * Return: maximum number of chunks with which Chunks[] can be filled.
1844 1845 */
1845 1846 static inline u32
1846 - calc_chunk_count(struct cifs_tcon *tcon, u64 bytes_left)
1847 + calc_chunk_count(struct cifs_tcon *tcon, u64 bytes_left, u32 chunk_size)
1847 1848 {
1848 1849 u32 max_chunks = READ_ONCE(tcon->max_chunks);
1849 1850 u32 max_bytes_copy = READ_ONCE(tcon->max_bytes_copy);
1850 - u32 max_bytes_chunk = READ_ONCE(tcon->max_bytes_chunk);
1851 1851 u64 need;
1852 1852 u32 allowed;
1853 1853
1854 - if (!max_bytes_chunk || !max_bytes_copy || !max_chunks)
1854 + if (!chunk_size || !max_bytes_copy || !max_chunks)
1855 1855 return 0;
1856 1856
1857 1857 /* chunks needed for the remaining bytes */
1858 - need = DIV_ROUND_UP_ULL(bytes_left, max_bytes_chunk);
1858 + need = DIV_ROUND_UP_ULL(bytes_left, chunk_size);
1859 1859 /* chunks allowed per cc request */
1860 - allowed = DIV_ROUND_UP(max_bytes_copy, max_bytes_chunk);
1860 + allowed = DIV_ROUND_UP(max_bytes_copy, chunk_size);
1861 1861
1862 1862 return (u32)umin(need, umin(max_chunks, allowed));
1863 1863 }
1864 1864
1865 1865 /**
1866 - * smb2_copychunk_range - server-side copy of data range
1866 + * __smb2_copychunk_range - server-side copy of data range
1867 1867 *
1868 1868 * @xid: transaction id
1869 1869 * @src_file: source file
@@ -1875,15 +1875,15 @@ calc_chunk_count(struct cifs_tcon *tcon, u64 bytes_left)
1875 1875 * Obtains a resume key for @src_file and issues FSCTL_SRV_COPYCHUNK_WRITE
1876 1876 * IOCTLs, splitting the request into chunks limited by tcon->max_*.
1877 1877 *
1878 - * Return: @len on success; negative errno on failure.
1878 + * Return: 0 on success; negative errno on failure.
1879 1879 */
1880 - static ssize_t
1881 - smb2_copychunk_range(const unsigned int xid,
1882 - struct cifsFileInfo *src_file,
1883 - struct cifsFileInfo *dst_file,
1884 - u64 src_off,
1885 - u64 len,
1886 - u64 dst_off)
1880 + static int
1881 + __smb2_copychunk_range(const unsigned int xid,
1882 + struct cifsFileInfo *src_file,
1883 + struct cifsFileInfo *dst_file,
1884 + u64 src_off,
1885 + u64 len,
1886 + u64 dst_off)
1887 1887 {
1888 1888 int rc = 0;
1889 1889 unsigned int ret_data_len = 0;
@@ -1891,12 +1891,14 @@ smb2_copychunk_range(const unsigned int xid,
1891 1891 struct copychunk_ioctl_rsp *cc_rsp = NULL;
1892 1892 struct cifs_tcon *tcon;
1893 1893 struct srv_copychunk *chunk;
1894 - u32 chunks, chunk_count, chunk_bytes;
1894 + u32 chunks, chunk_count, chunk_bytes, chunk_size;
1895 1895 u32 copy_bytes, copy_bytes_left;
1896 1896 u32 chunks_written, bytes_written;
1897 1897 u64 total_bytes_left = len;
1898 1898 u64 src_off_prev, dst_off_prev;
1899 + u64 max_chunk = 0;
1899 1900 u32 retries = 0;
1901 + bool reverse = false;
1900 1902
1901 1903 tcon = tlink_tcon(dst_file->tlink);
1902 1904
@@ -1904,8 +1906,50 @@ smb2_copychunk_range(const unsigned int xid,
1904 1906 dst_file->fid.volatile_fid, tcon->tid,
1905 1907 tcon->ses->Suid, src_off, dst_off, len);
1906 1908
1909 + /*
1910 + * Same-file left shifts are safe in forward order. For a right shift,
1911 + * let L be the copy length, delta the distance between the source and
1912 + * destination, and C the normal chunk size:
1913 + *
1914 + * delta >= L: copy forwards using C
1915 + * delta < L:
1916 + * delta >= C: copy backwards using C
1917 + * delta < C: copy backwards with chunks limited to delta
1918 + *
1919 + * Copying backwards prevents one chunk from overwriting data needed by
1920 + * a later chunk. Limiting the chunk size to delta prevents an individual
1921 + * chunk from overlapping itself.
1922 + * This limit can be removed once all supported servers handle overlapping
1923 + * descriptors safely.
1924 + *
1925 + * A small right shift over a large range may therefore require many
1926 + * chunks.
1927 + */
1928 + if (src_file == dst_file && dst_off > src_off) {
1929 + u64 delta = dst_off - src_off;
1930 +
1931 + if (delta < len) {
1932 + reverse = true;
1933 + max_chunk = delta;
1934 + }
1935 + }
1936 +
1937 + /*
1938 + * A backward copy walks the offsets down from the end of the range.
1939 + * Do this once, outside the retry loop, so a retry does not move the
1940 + * offsets again.
1941 + */
1942 + if (reverse) {
1943 + src_off += len;
1944 + dst_off += len;
1945 + }
1946 +
1907 1947 retry:
1908 - chunk_count = calc_chunk_count(tcon, total_bytes_left);
1948 + chunk_size = READ_ONCE(tcon->max_bytes_chunk);
1949 + if (max_chunk && max_chunk < chunk_size)
1950 + chunk_size = (u32)max_chunk;
1951 +
1952 + chunk_count = calc_chunk_count(tcon, total_bytes_left, chunk_size);
1909 1953 if (!chunk_count) {
1910 1954 rc = -EOPNOTSUPP;
1911 1955 goto out;
@@ -1946,16 +1990,21 @@ retry:
1946 1990 while (copy_bytes_left > 0 && chunks < chunk_count) {
1947 1991 chunk = &cc_req->Chunks[chunks++];
1948 1992
1993 + chunk_bytes = umin(copy_bytes_left, chunk_size);
1994 + if (reverse) {
1995 + src_off -= chunk_bytes;
1996 + dst_off -= chunk_bytes;
1997 + }
1998 +
1949 1999 chunk->SourceOffset = cpu_to_le64(src_off);
1950 2000 chunk->TargetOffset = cpu_to_le64(dst_off);
1951 -
1952 - chunk_bytes = umin(copy_bytes_left, tcon->max_bytes_chunk);
1953 -
1954 2001 chunk->Length = cpu_to_le32(chunk_bytes);
1955 2002 /* Buffer is zeroed, no need to set chunk->Reserved = 0 */
1956 2003
1957 - src_off += chunk_bytes;
1958 - dst_off += chunk_bytes;
2004 + if (!reverse) {
2005 + src_off += chunk_bytes;
2006 + dst_off += chunk_bytes;
2007 + }
1959 2008
1960 2009 copy_bytes_left -= chunk_bytes;
1961 2010 copy_bytes += chunk_bytes;
@@ -2003,6 +2052,18 @@ retry:
2003 2052 goto out;
2004 2053 }
2005 2054
2055 + /*
2056 + * A successful COPYCHUNK should copy every descriptor (MS-SMB2
2057 + * 3.3.5.15.6). Reject a short backward copy because the rewind
2058 + * below only supports forward copying.
2059 + */
2060 + if (unlikely(reverse && bytes_written < copy_bytes)) {
2061 + cifs_tcon_dbg(VFS, "Copychunk short write %u/%u (reverse)\n",
2062 + bytes_written, copy_bytes);
2063 + rc = -EIO;
2064 + goto out;
2065 + }
2066 +
2006 2067 /* Partial write: rewind */
2007 2068 if (bytes_written < copy_bytes) {
2008 2069 u32 delta = copy_bytes - bytes_written;
@@ -2064,10 +2125,27 @@ out:
2064 2125 trace_smb3_copychunk_done(xid, src_file->fid.volatile_fid,
2065 2126 dst_file->fid.volatile_fid, tcon->tid,
2066 2127 tcon->ses->Suid, src_off, dst_off, len);
2067 - return len;
2128 + return 0;
2068 2129 }
2069 2130 }
2070 2131
2132 + static ssize_t
2133 + smb2_copychunk_range(const unsigned int xid,
2134 + struct cifsFileInfo *src_file,
2135 + struct cifsFileInfo *dst_file,
2136 + u64 src_off,
2137 + u64 len,
2138 + u64 dst_off)
2139 + {
2140 + int rc;
2141 +
2142 + rc = __smb2_copychunk_range(xid, src_file, dst_file, src_off, len,
2143 + dst_off);
2144 + if (rc)
2145 + return rc;
2146 + return len;
2147 + }
2148 +
2071 2149 static int
2072 2150 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
2073 2151 struct cifs_fid *fid)
@@ -2218,7 +2296,7 @@ smb2_duplicate_extents(const unsigned int xid,
2218 2296 trgtfile->fid.volatile_fid, tcon->tid,
2219 2297 tcon->ses->Suid, src_off, dest_off, len);
2220 2298 inode = d_inode(trgtfile->dentry);
2221 - if (inode->i_size < dest_off + len) {
2299 + if (i_size_read(inode) < dest_off + len) {
2222 2300 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2223 2301 if (rc)
2224 2302 goto duplicate_extents_out;
@@ -2235,7 +2313,10 @@ smb2_duplicate_extents(const unsigned int xid,
2235 2313 if (ret_data_len > 0)
2236 2314 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2237 2315
2238 - if (rc == 0) {
2316 + if (rc) {
2317 + CIFS_I(inode)->time = 0; /* force reval */
2318 + cifs_invalidate_cache(inode, 0);
2319 + } else {
2239 2320 qrc = SMB2_query_info(xid, tcon, trgtfile->fid.persistent_fid,
2240 2321 trgtfile->fid.volatile_fid, &file_inf);
2241 2322 spin_lock(&inode->i_lock);
@@ -3441,6 +3522,13 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3441 3522 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3442 3523 ses->Suid, offset, len);
3443 3524
3525 + new_size = offset + len;
3526 + if (!keep_size && i_size_read(inode) < new_size) {
3527 + rc = inode_newsize_ok(inode, new_size);
3528 + if (rc)
3529 + goto out;
3530 + }
3531 +
3444 3532 filemap_invalidate_lock(inode->i_mapping);
3445 3533
3446 3534 netfs_read_sizes(inode, &i_size, &remote_i_size, &zero_point);
@@ -3464,6 +3552,9 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3464 3552 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3465 3553 goto zero_range_exit;
3466 3554
3555 + fscache_invalidate(cifs_inode_cookie(inode), NULL,
3556 + i_size_read(inode), 0);
3557 +
3467 3558 rc = smb3_zero_data(file, tcon, offset, len, xid);
3468 3559 if (rc < 0)
3469 3560 goto zero_range_exit;
@@ -3471,7 +3562,6 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3471 3562 /*
3472 3563 * do we also need to change the size of the file?
3473 3564 */
3474 - new_size = offset + len;
3475 3565 if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) {
3476 3566 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3477 3567 cfile->fid.volatile_fid, cfile->pid, new_size);
@@ -3488,6 +3578,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3488 3578
3489 3579 zero_range_exit:
3490 3580 filemap_invalidate_unlock(inode->i_mapping);
3581 + out:
3491 3582 free_xid(xid);
3492 3583 if (rc)
3493 3584 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
@@ -3533,6 +3624,8 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3533 3624 */
3534 3625 truncate_pagecache_range(inode, offset, offset + len - 1);
3535 3626 netfs_wait_for_outstanding_io(inode);
3627 + fscache_invalidate(cifs_inode_cookie(inode), NULL,
3628 + i_size_read(inode), 0);
3536 3629
3537 3630 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3538 3631
@@ -3938,18 +4031,26 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3938 4031 }
3939 4032
3940 4033 filemap_invalidate_lock(inode->i_mapping);
3941 - rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
4034 + rc = filemap_write_and_wait_range(inode->i_mapping,
4035 + round_down(off, PAGE_SIZE),
4036 + old_eof - 1);
3942 4037 if (rc < 0)
3943 4038 goto out_2;
3944 4039
3945 - truncate_pagecache_range(inode, off, old_eof);
4040 + netfs_wait_for_outstanding_io(inode);
4041 + /*
4042 + * Invalidate cached folios from the page containing off to EOF before
4043 + * moving data on the server, so subsequent reads do not see stale data.
4044 + */
4045 + truncate_pagecache_range(inode, round_down(off, PAGE_SIZE), -1);
4046 + fscache_invalidate(cifs_inode_cookie(inode), NULL, old_eof, 0);
4047 +
3946 4048 spin_lock(&inode->i_lock);
3947 4049 netfs_write_zero_point(inode, old_eof);
3948 4050 spin_unlock(&inode->i_lock);
3949 - netfs_wait_for_outstanding_io(inode);
3950 4051
3951 - rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3952 - old_eof - off - len, off);
4052 + rc = __smb2_copychunk_range(xid, cfile, cfile, off + len,
4053 + old_eof - off - len, off);
3953 4054 if (rc < 0)
3954 4055 goto out_2;
3955 4056
@@ -3982,7 +4083,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3982 4083 struct cifsFileInfo *cfile = file->private_data;
3983 4084 struct inode *inode = file_inode(file);
3984 4085 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3985 - __u64 count, old_eof, new_eof;
4086 + loff_t old_eof, new_eof;
3986 4087
3987 4088 xid = get_xid();
3988 4089
@@ -3992,15 +4093,32 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3992 4093 goto out;
3993 4094 }
3994 4095
3995 - count = old_eof - off;
3996 - new_eof = old_eof + len;
4096 + if (check_add_overflow(old_eof, len, &new_eof)) {
4097 + rc = -EFBIG;
4098 + goto out;
4099 + }
4100 + rc = inode_newsize_ok(inode, new_eof);
4101 + if (rc)
4102 + goto out;
4103 +
4104 + /* SET_ZERO_DATA creates a hole only in a sparse file. */
4105 + rc = smb2_set_sparse(xid, tcon, cfile, inode, true);
4106 + if (rc)
4107 + goto out;
3997 4108
3998 4109 filemap_invalidate_lock(inode->i_mapping);
3999 - rc = filemap_write_and_wait_range(inode->i_mapping, off, new_eof - 1);
4110 + rc = filemap_write_and_wait_range(inode->i_mapping,
4111 + round_down(off, PAGE_SIZE),
4112 + old_eof - 1);
4000 4113 if (rc < 0)
4001 4114 goto out_2;
4002 - truncate_pagecache_range(inode, off, old_eof);
4003 4115 netfs_wait_for_outstanding_io(inode);
4116 + /*
4117 + * Invalidate cached folios from the page containing off to EOF before
4118 + * moving data on the server, so subsequent reads do not see stale data.
4119 + */
4120 + truncate_pagecache_range(inode, round_down(off, PAGE_SIZE), -1);
4121 + fscache_invalidate(cifs_inode_cookie(inode), NULL, old_eof, 0);
4004 4122
4005 4123 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
4006 4124 cfile->fid.volatile_fid, cfile->pid, new_eof);
@@ -4013,7 +4131,12 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
4013 4131 spin_unlock(&inode->i_lock);
4014 4132 fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode));
4015 4133
4016 - rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
4134 + /*
4135 + * Move [off, old_eof) right by len. The helper copies backwards if the
4136 + * source and destination ranges overlap.
4137 + */
4138 + rc = __smb2_copychunk_range(xid, cfile, cfile, off, old_eof - off,
4139 + off + len);
4017 4140 if (rc < 0)
4018 4141 goto out_2;
4019 4142 spin_lock(&inode->i_lock);
modified fs/smb/client/transport.c
@@ -101,12 +101,11 @@ void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *midEntry)
101 101 trace_smb3_slow_rsp(smb_cmd, midEntry->mid, midEntry->pid,
102 102 midEntry->when_sent, midEntry->when_received);
103 103 if (cifsFYI & CIFS_TIMER) {
104 - pr_debug("slow rsp: cmd %d mid %llu",
105 - midEntry->command, midEntry->mid);
106 - cifs_info("A: 0x%lx S: 0x%lx R: 0x%lx\n",
107 - now - midEntry->when_alloc,
108 - now - midEntry->when_sent,
109 - now - midEntry->when_received);
104 + pr_debug("slow rsp: cmd %d mid %llu A: 0x%lx S: 0x%lx R: 0x%lx\n",
105 + midEntry->command, midEntry->mid,
106 + now - midEntry->when_alloc,
107 + now - midEntry->when_sent,
108 + now - midEntry->when_received);
110 109 }
111 110 }
112 111 #endif
modified fs/smb/server/connection.c
@@ -13,6 +13,7 @@
13 13 #include "mgmt/ksmbd_ida.h"
14 14 #include "mgmt/user_session.h"
15 15 #include "connection.h"
16 + #include "vfs_cache.h"
16 17 #include "compress.h"
17 18 #include "transport_tcp.h"
18 19 #include "transport_rdma.h"
@@ -384,12 +385,12 @@ static void ksmbd_conn_cancel_async_requests(struct ksmbd_conn *conn)
384 385 spin_lock(&conn->request_lock);
385 386 list_for_each_entry_safe(work, tmp, &conn->async_requests,
386 387 async_request_entry) {
387 - if (work->state != KSMBD_WORK_ACTIVE)
388 + if (cmpxchg(&work->state, KSMBD_WORK_ACTIVE,
389 + KSMBD_WORK_CANCELLED) != KSMBD_WORK_ACTIVE)
388 390 continue;
389 391
390 392 ksmbd_debug(CONN, "Cancel async request id %d\n",
391 393 work->async_id);
392 - work->state = KSMBD_WORK_CANCELLED;
393 394 if (work->cancel_fn)
394 395 work->cancel_fn(work->cancel_argv);
395 396 }
@@ -473,6 +474,9 @@ retry_idle:
473 474 if (retry_count >= max_timeout)
474 475 return -EIO;
475 476
477 + /* A blocked byte-range lock cannot drain until teardown wakes it. */
478 + ksmbd_wake_session_blocked_works(sess);
479 +
476 480 down_read(&conn_list_lock);
477 481 hash_for_each(conn_list, bkt, conn, hlist) {
478 482 if (ksmbd_session_is_bound_to_conn(sess, conn)) {
modified fs/smb/server/ksmbd_work.c
@@ -30,7 +30,7 @@ static int ksmbd_reserve_iov(struct ksmbd_work *work, int need_iov_cnt)
30 30 } while (new_alloc_cnt < work->iov_cnt + need_iov_cnt);
31 31
32 32 if (work->iov == work->iov_inline) {
33 - new = kcalloc(new_alloc_cnt, sizeof(*new), KSMBD_DEFAULT_GFP);
33 + new = kzalloc_objs(*new, new_alloc_cnt, KSMBD_DEFAULT_GFP);
34 34 if (!new)
35 35 return -ENOMEM;
36 36
modified fs/smb/server/ksmbd_work.h
@@ -82,7 +82,7 @@ struct ksmbd_work {
82 82 /* Contiguous SMB2 compression transform owned by this work item. */
83 83 void *compress_buf;
84 84
85 - unsigned char state;
85 + unsigned int state;
86 86 /* No response for cancelled request */
87 87 bool send_no_response:1;
88 88 /* Request is encrypted */
modified fs/smb/server/mgmt/share_config.c
@@ -146,9 +146,9 @@ static struct ksmbd_share_config *__share_lookup(const char *name)
146 146
147 147 static int parse_veto_list(struct ksmbd_share_config *share,
148 148 char *veto_list,
149 - int veto_list_sz)
149 + size_t veto_list_sz)
150 150 {
151 - int sz = 0;
151 + size_t sz;
152 152
153 153 if (!veto_list_sz)
154 154 return 0;
@@ -156,7 +156,7 @@ static int parse_veto_list(struct ksmbd_share_config *share,
156 156 while (veto_list_sz > 0) {
157 157 struct ksmbd_veto_pattern *p;
158 158
159 - sz = strlen(veto_list);
159 + sz = strnlen(veto_list, veto_list_sz);
160 160 if (!sz)
161 161 break;
162 162
@@ -164,7 +164,7 @@ static int parse_veto_list(struct ksmbd_share_config *share,
164 164 if (!p)
165 165 return -ENOMEM;
166 166
167 - p->pattern = kstrdup(veto_list, KSMBD_DEFAULT_GFP);
167 + p->pattern = kstrndup(veto_list, sz, KSMBD_DEFAULT_GFP);
168 168 if (!p->pattern) {
169 169 kfree(p);
170 170 return -ENOMEM;
@@ -172,6 +172,9 @@ static int parse_veto_list(struct ksmbd_share_config *share,
172 172
173 173 list_add(&p->list, &share->veto_list);
174 174
175 + if (sz == veto_list_sz)
176 + break;
177 +
175 178 veto_list += sz + 1;
176 179 veto_list_sz -= (sz + 1);
177 180 }
@@ -224,17 +227,28 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work,
224 227 }
225 228
226 229 if (!test_share_config_flag(share, KSMBD_SHARE_FLAG_PIPE)) {
227 - int path_len = PATH_MAX;
228 -
229 - if (resp->payload_sz)
230 - path_len = resp->payload_sz - resp->veto_list_sz;
230 + size_t path_len;
231 231
232 - share->path = kstrndup(ksmbd_share_config_path(resp), path_len,
233 - KSMBD_DEFAULT_GFP);
234 - if (!share->path) {
235 - ret = -ENOMEM;
232 + if (resp->payload_sz <= resp->veto_list_sz) {
233 + ret = -EINVAL;
236 234 } else {
237 - ret = 0;
235 + path_len = resp->payload_sz - resp->veto_list_sz;
236 + if (resp->veto_list_sz)
237 + path_len--;
238 +
239 + if (!path_len) {
240 + ret = -EINVAL;
241 + } else {
242 + share->path = kstrndup(
243 + ksmbd_share_config_path(resp),
244 + path_len, KSMBD_DEFAULT_GFP);
245 + if (!share->path)
246 + ret = -ENOMEM;
247 + else
248 + ret = 0;
249 + }
250 + }
251 + if (share->path) {
238 252 share->path_sz = strlen(share->path);
239 253 while (share->path_sz > 1 &&
240 254 share->path[share->path_sz - 1] == '/')
modified fs/smb/server/mgmt/tree_connect.c
@@ -82,6 +82,8 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name)
82 82 down_write(&sess->tree_conns_lock);
83 83 ret = xa_err(xa_store(&sess->tree_conns, tree_conn->id, tree_conn,
84 84 KSMBD_DEFAULT_GFP));
85 + if (!ret)
86 + atomic_inc(&tree_conn->refcount);
85 87 up_write(&sess->tree_conns_lock);
86 88 if (ret) {
87 89 status.ret = -ENOMEM;
@@ -129,6 +131,12 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
129 131 struct ksmbd_tree_connect *tree_conn)
130 132 {
131 133 down_write(&sess->tree_conns_lock);
134 + if (tree_conn->t_state == TREE_DISCONNECTED ||
135 + xa_load(&sess->tree_conns, tree_conn->id) != tree_conn) {
136 + up_write(&sess->tree_conns_lock);
137 + return -ENOENT;
138 + }
139 + tree_conn->t_state = TREE_DISCONNECTED;
132 140 xa_erase(&sess->tree_conns, tree_conn->id);
133 141 up_write(&sess->tree_conns_lock);
134 142
modified fs/smb/server/mgmt/user_session.c
@@ -666,10 +666,21 @@ void destroy_previous_session(struct ksmbd_conn *conn,
666 666 memcmp(user->passkey, prev_user->passkey, user->passkey_sz))
667 667 goto out;
668 668
669 + down_write(&prev_sess->chann_lock);
670 + if (prev_sess->tearing_down) {
671 + up_write(&prev_sess->chann_lock);
672 + goto out;
673 + }
674 + prev_sess->tearing_down = true;
675 + up_write(&prev_sess->chann_lock);
676 +
669 677 ksmbd_all_conn_set_status(prev_sess, KSMBD_SESS_NEED_RECONNECT);
670 678 err = ksmbd_conn_wait_idle_sess(conn, prev_sess);
671 679 if (err) {
672 - ksmbd_all_conn_set_status(prev_sess, KSMBD_SESS_NEED_SETUP);
680 + down_write(&prev_sess->chann_lock);
681 + prev_sess->tearing_down = false;
682 + up_write(&prev_sess->chann_lock);
683 + ksmbd_all_conn_set_status(prev_sess, KSMBD_SESS_GOOD);
673 684 goto out;
674 685 }
675 686
modified fs/smb/server/mgmt/user_session.h
@@ -42,6 +42,7 @@ struct ksmbd_session {
42 42
43 43 bool sign;
44 44 bool enc;
45 + bool tearing_down;
45 46
46 47 int state;
47 48 __u8 *Preauth_HashValue;
modified fs/smb/server/oplock.c
@@ -924,31 +924,69 @@ out:
924 924 ksmbd_conn_put(conn);
925 925 }
926 926
927 + /*
928 + * Select and pin the connection used for an oplock break before doing any
929 + * allocations which may sleep. The caller of oplock_break() holds a live
930 + * reference on ci (a file being opened, a file being operated on, or an
931 + * explicit ksmbd_inode_lookup_lock() reference in the parent lease break
932 + * paths), so the inode cannot be freed during the call and its lock is
933 + * reachable without dereferencing opinfo->o_fp, which is not pinned by
934 + * the oplock reference and may be freed by a concurrent close.
935 + *
936 + * opinfo->conn is cleared under ci->m_lock by session_fd_check() when the
937 + * durable handle owning the oplock is disconnected, reassigned by
938 + * ksmbd_reopen_durable_fd() under the same lock, and the last
939 + * ksmbd_conn_put() of the old connection frees it. Holding the read lock
940 + * excludes both writers, so the connection cannot be freed while it is
941 + * selected.
942 + */
943 + static struct ksmbd_conn *smb2_oplock_break_conn_get(struct oplock_info *opinfo,
944 + struct ksmbd_inode *ci)
945 + {
946 + struct ksmbd_conn *conn;
947 +
948 + down_read(&ci->m_lock);
949 + conn = READ_ONCE(opinfo->conn);
950 + if (conn && !ksmbd_conn_releasing(conn))
951 + conn = ksmbd_conn_get(conn);
952 + else
953 + conn = NULL;
954 + up_read(&ci->m_lock);
955 +
956 + return conn;
957 + }
958 +
927 959 /**
928 960 * smb2_oplock_break_noti() - send smb2 exclusive/batch to level2 oplock
929 961 * break command from server to client
930 962 * @opinfo: oplock info object
963 + * @ci: inode owning the break target's oplock list, pinned by
964 + * the caller
931 965 *
932 966 * Return: 0 on success, otherwise error
933 967 */
934 - static int smb2_oplock_break_noti(struct oplock_info *opinfo)
968 + static int smb2_oplock_break_noti(struct oplock_info *opinfo,
969 + struct ksmbd_inode *ci)
935 970 {
936 971 struct ksmbd_conn *conn;
937 972 struct oplock_break_info *br_info;
938 973 int ret = 0;
939 974 struct ksmbd_work *work;
940 975
941 - conn = READ_ONCE(opinfo->conn);
976 + conn = smb2_oplock_break_conn_get(opinfo, ci);
942 977 if (!conn)
943 978 return ksmbd_invalidate_durable_fd(opinfo->fid);
944 979
945 980 work = ksmbd_alloc_work_struct();
946 - if (!work)
981 + if (!work) {
982 + ksmbd_conn_put(conn);
947 983 return -ENOMEM;
984 + }
948 985
949 986 br_info = kmalloc_obj(struct oplock_break_info, KSMBD_DEFAULT_GFP);
950 987 if (!br_info) {
951 988 ksmbd_free_work_struct(work);
989 + ksmbd_conn_put(conn);
952 990 return -ENOMEM;
953 991 }
954 992
@@ -957,7 +995,8 @@ static int smb2_oplock_break_noti(struct oplock_info *opinfo)
957 995 br_info->open_trunc = opinfo->open_trunc;
958 996
959 997 work->request_buf = (char *)br_info;
960 - work->conn = ksmbd_conn_get(conn);
998 + /* Transfer the reference acquired by smb2_oplock_break_conn_get(). */
999 + work->conn = conn;
961 1000 work->sess = opinfo->sess;
962 1001
963 1002 ksmbd_conn_r_count_inc(conn);
@@ -1154,9 +1193,9 @@ static void wait_lease_breaking(struct oplock_info *opinfo)
1154 1193 }
1155 1194 }
1156 1195
1157 - static int oplock_break(struct oplock_info *brk_opinfo, int req_op_level,
1158 - struct ksmbd_work *in_work, bool share_break,
1159 - bool sync_lease_break)
1196 + static int oplock_break(struct oplock_info *brk_opinfo, struct ksmbd_inode *ci,
1197 + int req_op_level, struct ksmbd_work *in_work,
1198 + bool share_break, bool sync_lease_break)
1160 1199 {
1161 1200 int err = 0;
1162 1201 bool sent_interim = false;
@@ -1298,7 +1337,7 @@ again:
1298 1337 }
1299 1338 }
1300 1339
1301 - err = smb2_oplock_break_noti(brk_opinfo);
1340 + err = smb2_oplock_break_noti(brk_opinfo, ci);
1302 1341
1303 1342 ksmbd_debug(OPLOCK, "oplock granted = %d\n", brk_opinfo->level);
1304 1343 if (brk_opinfo->op_state == OPLOCK_CLOSING)
@@ -1326,13 +1365,14 @@ static int oplock_break_add(struct list_head *head, struct oplock_info *opinfo)
1326 1365 return 0;
1327 1366 }
1328 1367
1329 - static void oplock_break_drain_none(struct list_head *head)
1368 + static void oplock_break_drain_none(struct list_head *head,
1369 + struct ksmbd_inode *ci)
1330 1370 {
1331 1371 struct oplock_break_entry *ent, *tmp;
1332 1372
1333 1373 list_for_each_entry_safe(ent, tmp, head, list) {
1334 - oplock_break(ent->opinfo, SMB2_OPLOCK_LEVEL_NONE, NULL, false,
1335 - false);
1374 + oplock_break(ent->opinfo, ci, SMB2_OPLOCK_LEVEL_NONE, NULL,
1375 + false, false);
1336 1376 list_del(&ent->list);
1337 1377 opinfo_put(ent->opinfo);
1338 1378 kfree(ent);
@@ -1481,7 +1521,7 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
1481 1521 }
1482 1522 up_read(&p_ci->m_lock);
1483 1523
1484 - oplock_break_drain_none(&brk_list);
1524 + oplock_break_drain_none(&brk_list, p_ci);
1485 1525
1486 1526 ksmbd_inode_put(p_ci);
1487 1527 }
@@ -1525,7 +1565,7 @@ void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
1525 1565 }
1526 1566 up_read(&p_ci->m_lock);
1527 1567
1528 - oplock_break_drain_none(&brk_list);
1568 + oplock_break_drain_none(&brk_list, p_ci);
1529 1569
1530 1570 ksmbd_inode_put(p_ci);
1531 1571 }
@@ -1665,7 +1705,7 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
1665 1705 prev_durable_detached = prev_op_snapshot.durable_detached;
1666 1706 prev_fid = prev_op_snapshot.fid;
1667 1707
1668 - err = oplock_break(prev_opinfo, break_level, work,
1708 + err = oplock_break(prev_opinfo, ci, break_level, work,
1669 1709 share_ret < 0 && prev_opinfo->is_lease, false);
1670 1710 if (prev_durable_detached || (prev_durable_open && err == -ENOENT))
1671 1711 ksmbd_invalidate_durable_fd(prev_fid);
@@ -1771,7 +1811,8 @@ static bool smb_break_all_write_oplock(struct ksmbd_work *work,
1771 1811 }
1772 1812
1773 1813 brk_opinfo->open_trunc = is_trunc;
1774 - oplock_break(brk_opinfo, SMB2_OPLOCK_LEVEL_II, work, false, false);
1814 + oplock_break(brk_opinfo, fp->f_ci, SMB2_OPLOCK_LEVEL_II, work, false,
1815 + false);
1775 1816 sent_break = true;
1776 1817 opinfo_put(brk_opinfo);
1777 1818
@@ -1863,7 +1904,7 @@ next:
1863 1904 brk_op->op_state = OPLOCK_STATE_NONE;
1864 1905 spin_unlock(&brk_op->state_lock);
1865 1906 } else {
1866 - oplock_break(brk_op,
1907 + oplock_break(brk_op, ci,
1867 1908 brk_op->is_lease && !is_trunc ?
1868 1909 SMB2_OPLOCK_LEVEL_II : SMB2_OPLOCK_LEVEL_NONE,
1869 1910 send_interim && !sent_interim ? work : NULL,
modified fs/smb/server/smb2pdu.c
@@ -97,6 +97,11 @@ static int register_session_channel(struct ksmbd_session *sess,
97 97 int rc = 0;
98 98
99 99 down_write(&sess->chann_lock);
100 + if (sess->tearing_down) {
101 + rc = -ESHUTDOWN;
102 + goto out;
103 + }
104 +
100 105 if (xa_load(&sess->ksmbd_chann_list, (long)conn))
101 106 goto out;
102 107
@@ -873,7 +878,8 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work)
873 878 req = smb_get_msg(work->request_buf);
874 879 if ((req->InfoType == SMB2_O_INFO_FILE &&
875 880 (req->FileInfoClass == FILE_FULL_EA_INFORMATION ||
876 - req->FileInfoClass == FILE_ALL_INFORMATION)) ||
881 + req->FileInfoClass == FILE_ALL_INFORMATION ||
882 + req->FileInfoClass == FILE_NORMALIZED_NAME_INFORMATION)) ||
877 883 req->InfoType == SMB2_O_INFO_SECURITY)
878 884 sz = large_sz;
879 885 }
@@ -2784,6 +2790,7 @@ int smb2_tree_connect(struct ksmbd_work *work)
2784 2790 struct ksmbd_session *sess = work->sess;
2785 2791 char *treename = NULL, *name = NULL;
2786 2792 struct ksmbd_tree_conn_status status;
2793 + struct ksmbd_tree_connect *tree_conn = NULL;
2787 2794 struct ksmbd_share_config *share = NULL;
2788 2795 int rc = -EINVAL;
2789 2796
@@ -2811,6 +2818,7 @@ int smb2_tree_connect(struct ksmbd_work *work)
2811 2818
2812 2819 status = ksmbd_tree_conn_connect(work, name);
2813 2820 if (status.ret == KSMBD_TREE_CONN_STATUS_OK) {
2821 + tree_conn = status.tree_conn;
2814 2822 rsp->hdr.Id.SyncId.TreeId = cpu_to_le32(status.tree_conn->id);
2815 2823 share = status.tree_conn->share_conf;
2816 2824
@@ -2854,8 +2862,15 @@ int smb2_tree_connect(struct ksmbd_work *work)
2854 2862 status.tree_conn->posix_extensions = true;
2855 2863
2856 2864 down_write(&sess->tree_conns_lock);
2857 - status.tree_conn->t_state = TREE_CONNECTED;
2865 + if (status.tree_conn->t_state == TREE_DISCONNECTED) {
2866 + status.ret = KSMBD_TREE_CONN_STATUS_ERROR;
2867 + share = NULL;
2868 + } else {
2869 + status.tree_conn->t_state = TREE_CONNECTED;
2870 + }
2858 2871 up_write(&sess->tree_conns_lock);
2872 + if (status.ret != KSMBD_TREE_CONN_STATUS_OK)
2873 + goto out_err1;
2859 2874 rsp->StructureSize = cpu_to_le16(16);
2860 2875 out_err1:
2861 2876 /*
@@ -2882,9 +2897,6 @@ out_err1:
2882 2897 rc = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_tree_connect_rsp));
2883 2898 if (rc) {
2884 2899 if (status.ret == KSMBD_TREE_CONN_STATUS_OK) {
2885 - down_write(&sess->tree_conns_lock);
2886 - status.tree_conn->t_state = TREE_DISCONNECTED;
2887 - up_write(&sess->tree_conns_lock);
2888 2900 ksmbd_tree_conn_disconnect(sess, status.tree_conn);
2889 2901 status.tree_conn = NULL;
2890 2902 }
@@ -2925,6 +2937,9 @@ out_err1:
2925 2937 if (status.ret != KSMBD_TREE_CONN_STATUS_OK)
2926 2938 smb2_set_err_rsp(work);
2927 2939
2940 + if (tree_conn)
2941 + ksmbd_tree_connect_put(tree_conn);
2942 +
2928 2943 return rc;
2929 2944 }
2930 2945
@@ -3028,17 +3043,6 @@ int smb2_tree_disconnect(struct ksmbd_work *work)
3028 3043
3029 3044 ksmbd_close_tree_conn_fds(work);
3030 3045
3031 - down_write(&sess->tree_conns_lock);
3032 - if (tcon->t_state == TREE_DISCONNECTED) {
3033 - up_write(&sess->tree_conns_lock);
3034 - rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
3035 - err = -ENOENT;
3036 - goto err_out;
3037 - }
3038 -
3039 - tcon->t_state = TREE_DISCONNECTED;
3040 - up_write(&sess->tree_conns_lock);
3041 -
3042 3046 err = ksmbd_tree_conn_disconnect(sess, tcon);
3043 3047 if (err) {
3044 3048 rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
@@ -3086,17 +3090,41 @@ int smb2_session_logoff(struct ksmbd_work *work)
3086 3090 smb2_set_err_rsp(work);
3087 3091 return -ENOENT;
3088 3092 }
3093 +
3094 + down_write(&sess->chann_lock);
3095 + if (sess->tearing_down) {
3096 + up_write(&sess->chann_lock);
3097 + ksmbd_conn_unlock(conn);
3098 + rsp->hdr.Status = STATUS_USER_SESSION_DELETED;
3099 + smb2_set_err_rsp(work);
3100 + return -ENOENT;
3101 + }
3102 + sess->tearing_down = true;
3103 + up_write(&sess->chann_lock);
3104 +
3089 3105 ksmbd_all_conn_set_status(sess, KSMBD_SESS_NEED_RECONNECT);
3090 3106 ksmbd_conn_unlock(conn);
3091 3107
3108 + err = ksmbd_conn_wait_idle_sess(conn, sess);
3109 + if (err) {
3110 + down_write(&sess->chann_lock);
3111 + sess->tearing_down = false;
3112 + up_write(&sess->chann_lock);
3113 + ksmbd_all_conn_set_status(sess, KSMBD_SESS_GOOD);
3114 + rsp->hdr.Status = STATUS_UNEXPECTED_IO_ERROR;
3115 + smb2_set_err_rsp(work);
3116 + return err;
3117 + }
3118 +
3092 3119 ksmbd_close_session_fds(work);
3093 - ksmbd_conn_wait_idle(conn);
3094 3120
3095 3121 if (ksmbd_tree_conn_session_logoff(sess)) {
3096 3122 ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);
3097 3123 rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
3098 3124 smb2_set_err_rsp(work);
3099 - return -ENOENT;
3125 + err = -ENOENT;
3126 + } else {
3127 + err = 0;
3100 3128 }
3101 3129
3102 3130 down_write(&conn->session_lock);
@@ -3106,6 +3134,9 @@ int smb2_session_logoff(struct ksmbd_work *work)
3106 3134
3107 3135 ksmbd_all_conn_set_status(sess, KSMBD_SESS_NEED_SETUP);
3108 3136
3137 + if (err)
3138 + return err;
3139 +
3109 3140 rsp->StructureSize = cpu_to_le16(4);
3110 3141 err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
3111 3142 if (err) {
@@ -6757,7 +6788,7 @@ static int get_file_normalized_name_info(struct ksmbd_work *work,
6757 6788 {
6758 6789 struct smb2_file_alt_name_info *file_info;
6759 6790 char *filename, *normalized, *stream_name;
6760 - int conv_len, filename_len;
6791 + int buf_free_len, conv_len, filename_len;
6761 6792
6762 6793 if (work->conn->dialect < SMB311_PROT_ID) {
6763 6794 rsp->hdr.Status = STATUS_NOT_SUPPORTED;
@@ -6781,6 +6812,14 @@ static int get_file_normalized_name_info(struct ksmbd_work *work,
6781 6812 return -ENOMEM;
6782 6813
6783 6814 filename_len = strlen(normalized);
6815 + buf_free_len = smb2_resp_buf_len(work, sizeof(*rsp) +
6816 + sizeof(*file_info));
6817 + if (buf_free_len < 0 ||
6818 + (size_t)buf_free_len < (filename_len + 1) * sizeof(__le16)) {
6819 + kfree(normalized);
6820 + return -EINVAL;
6821 + }
6822 +
6784 6823 file_info = (struct smb2_file_alt_name_info *)rsp->Buffer;
6785 6824 conv_len = smbConvertToUTF16((__le16 *)file_info->FileName,
6786 6825 normalized, filename_len,
@@ -7444,6 +7483,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
7444 7483 struct object_id_info *info;
7445 7484
7446 7485 info = (struct object_id_info *)(rsp->Buffer);
7486 + memset(info, 0, sizeof(*info));
7447 7487
7448 7488 if (path.mnt->mnt_sb->s_uuid_len == 16)
7449 7489 memcpy(info->objid, path.mnt->mnt_sb->s_uuid.b,
@@ -7499,6 +7539,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
7499 7539 info->FreeSpaceStopFiltering = 0;
7500 7540 info->DefaultQuotaThreshold = cpu_to_le64(SMB2_NO_FID);
7501 7541 info->DefaultQuotaLimit = cpu_to_le64(SMB2_NO_FID);
7542 + info->FileSystemControlFlags = 0;
7502 7543 info->Padding = 0;
7503 7544 rsp->OutputBufferLength = cpu_to_le32(48);
7504 7545 fixed_len = 48;
@@ -7521,6 +7562,9 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
7521 7562 info->UserBlocksAvail = cpu_to_le64(stfs.f_bavail);
7522 7563 info->TotalFileNodes = cpu_to_le64(stfs.f_files);
7523 7564 info->FreeFileNodes = cpu_to_le64(stfs.f_ffree);
7565 + info->FileSysIdentifier =
7566 + cpu_to_le64((u64)(u32)stfs.f_fsid.val[1] << 32 |
7567 + (u32)stfs.f_fsid.val[0]);
7524 7568 rsp->OutputBufferLength = cpu_to_le32(56);
7525 7569 fixed_len = 56;
7526 7570 }
@@ -8620,13 +8664,18 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)
8620 8664 }
8621 8665
8622 8666 aux_payload_buf =
8623 - kvmalloc(rpc_resp->payload_sz, KSMBD_DEFAULT_GFP);
8667 + kvmalloc(ALIGN(rpc_resp->payload_sz, 8),
8668 + KSMBD_DEFAULT_GFP);
8624 8669 if (!aux_payload_buf) {
8625 8670 err = -ENOMEM;
8626 8671 goto out;
8627 8672 }
8628 8673
8629 8674 memcpy(aux_payload_buf, rpc_resp->payload, rpc_resp->payload_sz);
8675 + if (rpc_resp->payload_sz & 7)
8676 + memset(aux_payload_buf + rpc_resp->payload_sz, 0,
8677 + ALIGN(rpc_resp->payload_sz, 8) -
8678 + rpc_resp->payload_sz);
8630 8679
8631 8680 nbytes = rpc_resp->payload_sz;
8632 8681 err = ksmbd_iov_pin_rsp_read(work, (void *)rsp,
@@ -9680,14 +9729,14 @@ int smb2_cancel(struct ksmbd_work *work)
9680 9729 * still on conn->async_requests with a live cancel_fn
9681 9730 * pointing at the freed file_lock.
9682 9731 */
9683 - if (iter->state != KSMBD_WORK_ACTIVE)
9732 + if (cmpxchg(&iter->state, KSMBD_WORK_ACTIVE,
9733 + KSMBD_WORK_CANCELLED) != KSMBD_WORK_ACTIVE)
9684 9734 break;
9685 9735
9686 9736 ksmbd_debug(SMB,
9687 9737 "smb2 with AsyncId %llu cancelled command = 0x%x\n",
9688 9738 le64_to_cpu(hdr->Id.AsyncId),
9689 9739 le16_to_cpu(chdr->Command));
9690 - iter->state = KSMBD_WORK_CANCELLED;
9691 9740 if (iter->cancel_fn == smb2_notify_cancel_fn)
9692 9741 cancelled_notify =
9693 9742 smb2_notify_cancel_claim(iter->cancel_argv);
@@ -9716,11 +9765,16 @@ int smb2_cancel(struct ksmbd_work *work)
9716 9765 iter == work)
9717 9766 continue;
9718 9767
9768 + if (cmpxchg(&iter->state, KSMBD_WORK_ACTIVE,
9769 + KSMBD_WORK_CANCELLED) != KSMBD_WORK_ACTIVE)
9770 + break;
9771 +
9719 9772 ksmbd_debug(SMB,
9720 9773 "smb2 with mid %llu cancelled command = 0x%x\n",
9721 9774 le64_to_cpu(hdr->MessageId),
9722 9775 le16_to_cpu(chdr->Command));
9723 - iter->state = KSMBD_WORK_CANCELLED;
9776 + if (iter->cancel_fn)
9777 + iter->cancel_fn(iter->cancel_argv);
9724 9778 break;
9725 9779 }
9726 9780 spin_unlock(&conn->request_lock);
@@ -11766,7 +11820,7 @@ static void smb2_notify_cancel_fn(void **argv)
11766 11820 return;
11767 11821 conn = in_work->conn;
11768 11822
11769 - ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
11823 + ctx = kmalloc_obj(*ctx, GFP_ATOMIC);
11770 11824 if (!ctx) {
11771 11825 /* Can't defer the response -- free without sending one. */
11772 11826 list_del_init(&in_work->async_request_entry);
modified fs/smb/server/smbacl.c
@@ -383,10 +383,10 @@ void free_acl_state(struct posix_acl_state *state)
383 383 kfree(state->groups);
384 384 }
385 385
386 - static void parse_dacl(struct mnt_idmap *idmap,
387 - struct smb_acl *pdacl, char *end_of_acl,
388 - struct smb_sid *pownersid, struct smb_sid *pgrpsid,
389 - struct smb_fattr *fattr)
386 + static int parse_dacl(struct mnt_idmap *idmap,
387 + struct smb_acl *pdacl, char *end_of_acl,
388 + struct smb_sid *pownersid, struct smb_sid *pgrpsid,
389 + struct smb_fattr *fattr)
390 390 {
391 391 int i, ret;
392 392 u16 num_aces = 0;
@@ -400,13 +400,13 @@ static void parse_dacl(struct mnt_idmap *idmap,
400 400 bool owner_found = false, group_found = false, others_found = false;
401 401
402 402 if (!pdacl)
403 - return;
403 + return 0;
404 404
405 405 /* validate that we do not go past end of acl */
406 406 if (end_of_acl < (char *)pdacl + sizeof(struct smb_acl) ||
407 407 end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) {
408 408 pr_err("ACL too small to parse DACL\n");
409 - return;
409 + return -EINVAL;
410 410 }
411 411
412 412 ksmbd_debug(SMB, "DACL revision %d size %d num aces %d\n",
@@ -418,31 +418,31 @@ static void parse_dacl(struct mnt_idmap *idmap,
418 418
419 419 num_aces = le16_to_cpu(pdacl->num_aces);
420 420 if (num_aces <= 0)
421 - return;
421 + return 0;
422 422
423 423 dacl_size = le16_to_cpu(pdacl->size);
424 424 if (dacl_size < sizeof(struct smb_acl))
425 - return;
425 + return -EINVAL;
426 426
427 427 if (num_aces > (dacl_size - sizeof(struct smb_acl)) /
428 428 (offsetof(struct smb_ace, sid) +
429 429 offsetof(struct smb_sid, sub_auth) + sizeof(__le16)))
430 - return;
430 + return -EINVAL;
431 431
432 432 ret = init_acl_state(&acl_state, num_aces);
433 433 if (ret)
434 - return;
434 + return ret;
435 435 ret = init_acl_state(&default_acl_state, num_aces);
436 436 if (ret) {
437 437 free_acl_state(&acl_state);
438 - return;
438 + return ret;
439 439 }
440 440
441 441 ppace = kmalloc_objs(struct smb_ace *, num_aces, KSMBD_DEFAULT_GFP);
442 442 if (!ppace) {
443 443 free_acl_state(&default_acl_state);
444 444 free_acl_state(&acl_state);
445 - return;
445 + return -ENOMEM;
446 446 }
447 447
448 448 /*
@@ -451,8 +451,10 @@ static void parse_dacl(struct mnt_idmap *idmap,
451 451 * user/group/other have no permissions
452 452 */
453 453 for (i = 0; i < num_aces; ++i) {
454 - if (end_of_acl - acl_base < acl_size)
455 - break;
454 + if (end_of_acl - acl_base < acl_size) {
455 + ret = -EINVAL;
456 + goto out;
457 + }
456 458
457 459 ppace[i] = (struct smb_ace *)(acl_base + acl_size);
458 460 acl_base = (char *)ppace[i];
@@ -465,8 +467,10 @@ static void parse_dacl(struct mnt_idmap *idmap,
465 467 (end_of_acl - acl_base <
466 468 acl_size + sizeof(__le32) * ppace[i]->sid.num_subauth) ||
467 469 (le16_to_cpu(ppace[i]->size) <
468 - acl_size + sizeof(__le32) * ppace[i]->sid.num_subauth))
469 - break;
470 + acl_size + sizeof(__le32) * ppace[i]->sid.num_subauth)) {
471 + ret = -EINVAL;
472 + goto out;
473 + }
470 474
471 475 acl_size = le16_to_cpu(ppace[i]->size);
472 476 ppace[i]->access_req =
@@ -524,8 +528,8 @@ static void parse_dacl(struct mnt_idmap *idmap,
524 528 temp_fattr.cf_uid = INVALID_UID;
525 529 ret = sid_to_id(idmap, &ppace[i]->sid, SIDOWNER, &temp_fattr);
526 530 if (ret || uid_eq(temp_fattr.cf_uid, INVALID_UID)) {
527 - pr_err("%s: Error %d mapping Owner SID to uid\n",
528 - __func__, ret);
531 + pr_err_ratelimited("%s: Error %d mapping Owner SID to uid\n",
532 + __func__, ret);
529 533 continue;
530 534 }
531 535
@@ -541,7 +545,6 @@ static void parse_dacl(struct mnt_idmap *idmap,
541 545 ((acl_mode & 0700) >> 6) | 0004;
542 546 }
543 547 }
544 - kfree(ppace);
545 548
546 549 if (owner_found) {
547 550 /* The owner must be set to at least read-only. */
@@ -584,10 +587,12 @@ static void parse_dacl(struct mnt_idmap *idmap,
584 587 fattr->cf_acls =
585 588 posix_acl_alloc(acl_state.users->n +
586 589 acl_state.groups->n + 4, KSMBD_DEFAULT_GFP);
587 - if (fattr->cf_acls) {
588 - cf_pace = fattr->cf_acls->a_entries;
589 - posix_state_to_acl(&acl_state, cf_pace);
590 + if (!fattr->cf_acls) {
591 + ret = -ENOMEM;
592 + goto out;
590 593 }
594 + cf_pace = fattr->cf_acls->a_entries;
595 + posix_state_to_acl(&acl_state, cf_pace);
591 596 }
592 597 }
593 598
@@ -598,14 +603,20 @@ static void parse_dacl(struct mnt_idmap *idmap,
598 603 fattr->cf_dacls =
599 604 posix_acl_alloc(default_acl_state.users->n +
600 605 default_acl_state.groups->n + 4, KSMBD_DEFAULT_GFP);
601 - if (fattr->cf_dacls) {
602 - cf_pdace = fattr->cf_dacls->a_entries;
603 - posix_state_to_acl(&default_acl_state, cf_pdace);
606 + if (!fattr->cf_dacls) {
607 + ret = -ENOMEM;
608 + goto out;
604 609 }
610 + cf_pdace = fattr->cf_dacls->a_entries;
611 + posix_state_to_acl(&default_acl_state, cf_pdace);
605 612 }
606 613 }
614 + ret = 0;
615 + out:
616 + kfree(ppace);
607 617 free_acl_state(&acl_state);
608 618 free_acl_state(&default_acl_state);
619 + return ret;
609 620 }
610 621
611 622 static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
@@ -966,8 +977,10 @@ int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
966 977 if (dacloffset < sizeof(struct smb_ntsd))
967 978 return -EINVAL;
968 979
969 - parse_dacl(idmap, dacl_ptr, end_of_acl,
970 - owner_sid_ptr, group_sid_ptr, fattr);
980 + rc = parse_dacl(idmap, dacl_ptr, end_of_acl,
981 + owner_sid_ptr, group_sid_ptr, fattr);
982 + if (rc)
983 + return rc;
971 984 }
972 985
973 986 return 0;
modified fs/smb/server/transport_ipc.c
@@ -532,14 +532,21 @@ static int ipc_validate_msg(struct ipc_msg_table_entry *entry)
532 532 if (entry->msg_sz < sizeof(struct ksmbd_share_config_response))
533 533 return -EINVAL;
534 534
535 - if (resp->payload_sz) {
536 - if (resp->payload_sz < resp->veto_list_sz)
537 - return -EINVAL;
535 + if (strnlen(resp->share_name, sizeof(resp->share_name)) ==
536 + sizeof(resp->share_name))
537 + return -EINVAL;
538 538
539 - if (check_add_overflow(sizeof(struct ksmbd_share_config_response),
540 - resp->payload_sz, &msg_sz))
541 - return -EINVAL;
542 - }
539 + if (resp->veto_list_sz > resp->payload_sz)
540 + return -EINVAL;
541 +
542 + if (resp->flags != KSMBD_SHARE_FLAG_INVALID &&
543 + !(resp->flags & KSMBD_SHARE_FLAG_PIPE) &&
544 + resp->payload_sz <= resp->veto_list_sz)
545 + return -EINVAL;
546 +
547 + if (check_add_overflow(sizeof(struct ksmbd_share_config_response),
548 + resp->payload_sz, &msg_sz))
549 + return -EINVAL;
543 550 break;
544 551 }
545 552 case KSMBD_EVENT_LOGIN_REQUEST_EXT:
modified fs/smb/server/transport_tcp.c
@@ -39,6 +39,7 @@ struct tcp_transport {
39 39 static const struct ksmbd_transport_ops ksmbd_tcp_transport_ops;
40 40
41 41 static void tcp_stop_kthread(struct task_struct *kthread);
42 + static void ksmbd_tcp_stop_listener(struct interface *iface);
42 43 static struct interface *alloc_iface(char *ifname);
43 44 static void ksmbd_tcp_disconnect(struct ksmbd_transport *t);
44 45
@@ -321,13 +322,20 @@ static int ksmbd_tcp_run_kthread(struct interface *iface)
321 322 int rc;
322 323 struct task_struct *kthread;
323 324
324 - kthread = kthread_run(ksmbd_kthread_fn, (void *)iface, "ksmbd-%s",
325 - iface->name);
325 + kthread = kthread_create(ksmbd_kthread_fn, (void *)iface, "ksmbd-%s",
326 + iface->name);
326 327 if (IS_ERR(kthread)) {
327 328 rc = PTR_ERR(kthread);
328 329 return rc;
329 330 }
331 +
332 + /*
333 + * The listener can exit after its socket is shutdown, so keep the
334 + * task_struct alive until the caller has stopped it.
335 + */
336 + get_task_struct(kthread);
330 337 iface->ksmbd_kthread = kthread;
338 + wake_up_process(kthread);
331 339
332 340 return 0;
333 341 }
@@ -598,12 +606,7 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,
598 606 if (iface && iface->state == IFACE_STATE_CONFIGURED) {
599 607 ksmbd_debug(CONN, "netdev-down event: netdev(%s) is going down\n",
600 608 iface->name);
601 - kernel_sock_shutdown(iface->ksmbd_socket, SHUT_RDWR);
602 - tcp_stop_kthread(iface->ksmbd_kthread);
603 - iface->ksmbd_kthread = NULL;
604 - sock_release(iface->ksmbd_socket);
605 - iface->ksmbd_socket = NULL;
606 -
609 + ksmbd_tcp_stop_listener(iface);
607 610 iface->state = IFACE_STATE_DOWN;
608 611 break;
609 612 }
@@ -631,11 +634,25 @@ static void tcp_stop_kthread(struct task_struct *kthread)
631 634 if (!kthread)
632 635 return;
633 636
634 - ret = kthread_stop(kthread);
637 + ret = kthread_stop_put(kthread);
635 638 if (ret)
636 639 pr_err("failed to stop forker thread\n");
637 640 }
638 641
642 + static void ksmbd_tcp_stop_listener(struct interface *iface)
643 + {
644 + if (iface->ksmbd_socket)
645 + kernel_sock_shutdown(iface->ksmbd_socket, SHUT_RDWR);
646 +
647 + tcp_stop_kthread(iface->ksmbd_kthread);
648 + iface->ksmbd_kthread = NULL;
649 +
650 + if (iface->ksmbd_socket) {
651 + sock_release(iface->ksmbd_socket);
652 + iface->ksmbd_socket = NULL;
653 + }
654 + }
655 +
639 656 void ksmbd_tcp_destroy(void)
640 657 {
641 658 struct interface *iface, *tmp;
@@ -643,6 +660,7 @@ void ksmbd_tcp_destroy(void)
643 660 unregister_netdevice_notifier(&ksmbd_netdev_notifier);
644 661
645 662 list_for_each_entry_safe(iface, tmp, &iface_list, entry) {
663 + ksmbd_tcp_stop_listener(iface);
646 664 list_del(&iface->entry);
647 665 kfree(iface->name);
648 666 kfree(iface);
modified fs/smb/server/vfs.c
@@ -2007,6 +2007,11 @@ out:
2007 2007 return ret;
2008 2008 }
2009 2009
2010 + static bool ksmbd_vfs_copy_range_valid(loff_t offset, size_t len)
2011 + {
2012 + return offset >= 0 && (loff_t)len <= MAX_LFS_FILESIZE - offset;
2013 + }
2014 +
2010 2015 int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
2011 2016 struct ksmbd_file *src_fp,
2012 2017 struct ksmbd_file *dst_fp,
@@ -2042,6 +2047,10 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
2042 2047 dst_off = le64_to_cpu(chunks[i].TargetOffset);
2043 2048 len = le32_to_cpu(chunks[i].Length);
2044 2049
2050 + if (!ksmbd_vfs_copy_range_valid(src_off, len) ||
2051 + !ksmbd_vfs_copy_range_valid(dst_off, len))
2052 + return -E2BIG;
2053 +
2045 2054 if (check_lock_range(src_fp->filp, src_off,
2046 2055 src_off + len - 1, READ))
2047 2056 return -EAGAIN;
@@ -2134,7 +2143,8 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
2134 2143 len = le32_to_cpu(chunks[i].Length);
2135 2144 copy_len = len;
2136 2145
2137 - if (src_off < 0)
2146 + if (!ksmbd_vfs_copy_range_valid(src_off, len) ||
2147 + !ksmbd_vfs_copy_range_valid(dst_off, len))
2138 2148 return -E2BIG;
2139 2149
2140 2150 if (src_off > src_file_size || len > src_file_size - src_off) {
modified fs/smb/server/vfs_cache.c
@@ -846,12 +846,25 @@ static void set_close_state_blocked_works(struct ksmbd_file *fp)
846 846 spin_lock(&fp->f_lock);
847 847 list_for_each_entry(cancel_work, &fp->blocked_works,
848 848 fp_entry) {
849 - cancel_work->state = KSMBD_WORK_CLOSED;
850 - cancel_work->cancel_fn(cancel_work->cancel_argv);
849 + if (xchg(&cancel_work->state, KSMBD_WORK_CLOSED) ==
850 + KSMBD_WORK_ACTIVE)
851 + cancel_work->cancel_fn(cancel_work->cancel_argv);
851 852 }
852 853 spin_unlock(&fp->f_lock);
853 854 }
854 855
856 + void ksmbd_wake_session_blocked_works(struct ksmbd_session *sess)
857 + {
858 + struct ksmbd_file_table *ft = &sess->file_table;
859 + struct ksmbd_file *fp;
860 + unsigned int id;
861 +
862 + read_lock(&ft->lock);
863 + idr_for_each_entry(ft->idr, fp, id)
864 + set_close_state_blocked_works(fp);
865 + read_unlock(&ft->lock);
866 + }
867 +
855 868 int ksmbd_close_fd(struct ksmbd_work *work, u64 id)
856 869 {
857 870 struct ksmbd_file *fp;
modified fs/smb/server/vfs_cache.h
@@ -226,6 +226,7 @@ void ksmbd_stop_durable_scavenger(void);
226 226 bool ksmbd_durable_scavenger_active(void);
227 227 void ksmbd_close_tree_conn_fds(struct ksmbd_work *work);
228 228 void ksmbd_close_session_fds(struct ksmbd_work *work);
229 + void ksmbd_wake_session_blocked_works(struct ksmbd_session *sess);
229 230 int ksmbd_close_inode_fds(struct ksmbd_work *work, struct inode *inode);
230 231 int ksmbd_init_global_file_table(void);
231 232 void ksmbd_free_global_file_table(void);
modified fs/xfs/Makefile
@@ -91,6 +91,7 @@ xfs-y += xfs_aops.o \
91 91 xfs_healthmon.o \
92 92 xfs_icache.o \
93 93 xfs_ioctl.o \
94 + xfs_ioend.o \
94 95 xfs_iomap.o \
95 96 xfs_iops.o \
96 97 xfs_inode.o \
modified fs/xfs/libxfs/xfs_da_btree.c
@@ -2746,8 +2746,8 @@ xfs_dabuf_map(
2746 2746 * larger one that needs to be free by the caller.
2747 2747 */
2748 2748 if (nirecs > 1) {
2749 - map = kcalloc(nirecs, sizeof(struct xfs_buf_map),
2750 - GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
2749 + map = kzalloc_objs(struct xfs_buf_map, nirecs,
2750 + GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
2751 2751 *mapp = map;
2752 2752 }
2753 2753
modified fs/xfs/libxfs/xfs_rtgroup.h
@@ -359,7 +359,11 @@ static inline int xfs_initialize_rtgroups(struct xfs_mount *mp,
359 359 # define xfs_rtgroup_unlock(rtg, gf) ((void)0)
360 360 # define xfs_rtgroup_trans_join(tp, rtg, gf) ((void)0)
361 361 # define xfs_update_rtsb(bp, sb_bp) ((void)0)
362 - # define xfs_log_rtsb(tp, sb_bp) (NULL)
362 + static inline struct xfs_buf *xfs_log_rtsb(struct xfs_trans *tp,
363 + const struct xfs_buf *sb_bp)
364 + {
365 + return NULL;
366 + }
363 367 # define xfs_rtgroup_get_geometry(rtg, rgeo) (-EOPNOTSUPP)
364 368 #endif /* CONFIG_XFS_RT */
365 369
modified fs/xfs/libxfs/xfs_sb.c
@@ -1470,36 +1470,33 @@ xfs_sync_sb_buf(
1470 1470 bool update_rtsb)
1471 1471 {
1472 1472 struct xfs_trans *tp;
1473 - struct xfs_buf *bp;
1474 - struct xfs_buf *rtsb_bp = NULL;
1475 1473 int error;
1476 1474
1477 1475 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
1478 1476 if (error)
1479 1477 return error;
1480 1478
1481 - bp = xfs_trans_getsb(tp);
1482 1479 xfs_log_sb(tp);
1483 - xfs_trans_bhold(tp, bp);
1484 - if (update_rtsb) {
1485 - rtsb_bp = xfs_log_rtsb(tp, bp);
1486 - if (rtsb_bp)
1487 - xfs_trans_bhold(tp, rtsb_bp);
1488 - }
1480 + if (update_rtsb)
1481 + xfs_log_rtsb(tp, xfs_trans_getsb(tp));
1489 1482 xfs_trans_set_sync(tp);
1490 1483 error = xfs_trans_commit(tp);
1491 1484 if (error)
1492 - goto out;
1493 - /*
1494 - * write out the sb buffer to get the changes to disk
1495 - */
1496 - error = xfs_bwrite(bp);
1497 - if (!error && rtsb_bp)
1498 - error = xfs_bwrite(rtsb_bp);
1499 - out:
1500 - if (rtsb_bp)
1501 - xfs_buf_relse(rtsb_bp);
1502 - xfs_buf_relse(bp);
1485 + return error;
1486 +
1487 + /* Re-acquire and write the sb and rtsb to disk. */
1488 + xfs_buf_lock(mp->m_sb_bp);
1489 + error = xfs_bwrite(mp->m_sb_bp);
1490 + xfs_buf_unlock(mp->m_sb_bp);
1491 + if (error)
1492 + return error;
1493 +
1494 + if (update_rtsb && mp->m_rtsb_bp) {
1495 + xfs_buf_lock(mp->m_rtsb_bp);
1496 + error = xfs_bwrite(mp->m_rtsb_bp);
1497 + xfs_buf_unlock(mp->m_rtsb_bp);
1498 + }
1499 +
1503 1500 return error;
1504 1501 }
1505 1502
modified fs/xfs/xfs_aops.c
@@ -20,6 +20,7 @@
20 20 #include "xfs_errortag.h"
21 21 #include "xfs_error.h"
22 22 #include "xfs_icache.h"
23 + #include "xfs_ioend.h"
23 24 #include "xfs_zone_alloc.h"
24 25 #include "xfs_rtgroup.h"
25 26 #include <linux/bio-integrity.h>
@@ -36,15 +37,6 @@ XFS_WPC(struct iomap_writepage_ctx *ctx)
36 37 return container_of(ctx, struct xfs_writepage_ctx, ctx);
37 38 }
38 39
39 - /*
40 - * Fast and loose check if this write could update the on-disk inode size.
41 - */
42 - static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
43 - {
44 - return ioend->io_offset + ioend->io_size >
45 - XFS_I(ioend->io_inode)->i_disk_size;
46 - }
47 -
48 40 /*
49 41 * Update on-disk file size now that data has been written to disk.
50 42 */
@@ -80,175 +72,6 @@ xfs_setfilesize(
80 72 return xfs_trans_commit(tp);
81 73 }
82 74
83 - static void
84 - xfs_ioend_put_open_zones(
85 - struct iomap_ioend *ioend)
86 - {
87 - struct iomap_ioend *tmp;
88 -
89 - /*
90 - * Put the open zone for all ioends merged into this one (if any).
91 - */
92 - list_for_each_entry(tmp, &ioend->io_list, io_list)
93 - xfs_open_zone_put(tmp->io_private);
94 -
95 - /*
96 - * The main ioend might not have an open zone if the submission failed
97 - * before xfs_zone_alloc_and_submit got called.
98 - */
99 - if (ioend->io_private)
100 - xfs_open_zone_put(ioend->io_private);
101 - }
102 -
103 - /*
104 - * IO write completion.
105 - */
106 - STATIC void
107 - xfs_end_ioend_write(
108 - struct iomap_ioend *ioend)
109 - {
110 - struct xfs_inode *ip = XFS_I(ioend->io_inode);
111 - struct xfs_mount *mp = ip->i_mount;
112 - bool is_zoned = xfs_is_zoned_inode(ip);
113 - xfs_off_t offset = ioend->io_offset;
114 - size_t size = ioend->io_size;
115 - unsigned int nofs_flag;
116 - int error;
117 -
118 - /*
119 - * We can allocate memory here while doing writeback on behalf of
120 - * memory reclaim. To avoid memory allocation deadlocks set the
121 - * task-wide nofs context for the following operations.
122 - */
123 - nofs_flag = memalloc_nofs_save();
124 -
125 - /*
126 - * Just clean up the in-memory structures if the fs has been shut down.
127 - */
128 - if (xfs_is_shutdown(mp)) {
129 - error = -EIO;
130 - goto done;
131 - }
132 -
133 - /*
134 - * Clean up all COW blocks and underlying data fork delalloc blocks on
135 - * I/O error. The delalloc punch is required because this ioend was
136 - * mapped to blocks in the COW fork and the associated pages are no
137 - * longer dirty. If we don't remove delalloc blocks here, they become
138 - * stale and can corrupt free space accounting on unmount.
139 - */
140 - error = blk_status_to_errno(ioend->io_bio.bi_status);
141 - if (unlikely(error)) {
142 - /*
143 - * Zoned writes update the in-core open zone accounting before
144 - * I/O submission. A failed write leaves that state
145 - * inconsistent, so shut down the filesystem instead of letting
146 - * later writers wait forever for open zone space to become
147 - * available.
148 - */
149 - if (is_zoned) {
150 - xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
151 - goto done;
152 - }
153 - if (ioend->io_flags & IOMAP_IOEND_SHARED) {
154 - ASSERT(!is_zoned);
155 - xfs_reflink_cancel_cow_range(ip, offset, size, true);
156 - xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, offset,
157 - offset + size, NULL);
158 - }
159 - goto done;
160 - }
161 -
162 - /*
163 - * Success: commit the COW or unwritten blocks if needed.
164 - */
165 - if (is_zoned)
166 - error = xfs_zoned_end_io(ip, offset, size, ioend->io_sector,
167 - ioend->io_private, NULLFSBLOCK);
168 - else if (ioend->io_flags & IOMAP_IOEND_SHARED)
169 - error = xfs_reflink_end_cow(ip, offset, size);
170 - else if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
171 - error = xfs_iomap_write_unwritten(ip, offset, size, false);
172 -
173 - if (!error &&
174 - !(ioend->io_flags & IOMAP_IOEND_DIRECT) &&
175 - xfs_ioend_is_append(ioend))
176 - error = xfs_setfilesize(ip, offset, size);
177 - done:
178 - if (is_zoned)
179 - xfs_ioend_put_open_zones(ioend);
180 - iomap_finish_ioends(ioend, error);
181 - memalloc_nofs_restore(nofs_flag);
182 - }
183 -
184 - /*
185 - * Finish all pending IO completions that require transactional modifications.
186 - *
187 - * We try to merge physical and logically contiguous ioends before completion to
188 - * minimise the number of transactions we need to perform during IO completion.
189 - * Both unwritten extent conversion and COW remapping need to iterate and modify
190 - * one physical extent at a time, so we gain nothing by merging physically
191 - * discontiguous extents here.
192 - *
193 - * The ioend chain length that we can be processing here is largely unbound in
194 - * length and we may have to perform significant amounts of work on each ioend
195 - * to complete it. Hence we have to be careful about holding the CPU for too
196 - * long in this loop.
197 - */
198 - void
199 - xfs_end_io(
200 - struct work_struct *work)
201 - {
202 - struct xfs_inode *ip =
203 - container_of(work, struct xfs_inode, i_ioend_work);
204 - struct iomap_ioend *ioend;
205 - struct list_head tmp;
206 - unsigned long flags;
207 -
208 - spin_lock_irqsave(&ip->i_ioend_lock, flags);
209 - list_replace_init(&ip->i_ioend_list, &tmp);
210 - spin_unlock_irqrestore(&ip->i_ioend_lock, flags);
211 -
212 - iomap_sort_ioends(&tmp);
213 - while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend,
214 - io_list))) {
215 - list_del_init(&ioend->io_list);
216 - iomap_ioend_try_merge(ioend, &tmp);
217 - if (bio_op(&ioend->io_bio) == REQ_OP_READ)
218 - iomap_finish_ioends(ioend,
219 - blk_status_to_errno(ioend->io_bio.bi_status));
220 - else
221 - xfs_end_ioend_write(ioend);
222 - cond_resched();
223 - }
224 - }
225 -
226 - void
227 - xfs_end_bio(
228 - struct bio *bio)
229 - {
230 - struct iomap_ioend *ioend = iomap_ioend_from_bio(bio);
231 - struct xfs_inode *ip = XFS_I(ioend->io_inode);
232 - struct xfs_mount *mp = ip->i_mount;
233 - unsigned long flags;
234 -
235 - /*
236 - * For Appends record the actually written block number and set the
237 - * boundary flag if needed.
238 - */
239 - if (IS_ENABLED(CONFIG_XFS_RT) && bio_is_zone_append(bio)) {
240 - ioend->io_sector = bio->bi_iter.bi_sector;
241 - xfs_mark_rtg_boundary(ioend);
242 - }
243 -
244 - spin_lock_irqsave(&ip->i_ioend_lock, flags);
245 - if (list_empty(&ip->i_ioend_list))
246 - WARN_ON_ONCE(!queue_work(mp->m_unwritten_workqueue,
247 - &ip->i_ioend_work));
248 - list_add_tail(&ioend->io_list, &ip->i_ioend_list);
249 - spin_unlock_irqrestore(&ip->i_ioend_lock, flags);
250 - }
251 -
252 75 /*
253 76 * We cannot cancel the ioend directly on error. We may have already set other
254 77 * pages under writeback and hence we have to run I/O completion to mark the
@@ -631,13 +454,8 @@ xfs_zoned_map_blocks(
631 454 XFS_BMAPI_REMAP);
632 455 xfs_iunlock(ip, XFS_ILOCK_EXCL);
633 456
634 - wpc->iomap.type = IOMAP_MAPPED;
635 - wpc->iomap.flags = IOMAP_F_DIRTY;
636 - wpc->iomap.bdev = mp->m_rtdev_targp->bt_bdev;
637 - wpc->iomap.offset = offset;
638 - wpc->iomap.length = XFS_FSB_TO_B(mp, count_fsb);
639 - wpc->iomap.flags = IOMAP_F_ANON_WRITE;
640 -
457 + xfs_iomap_set_anon_write(ip, &wpc->iomap, offset,
458 + XFS_FSB_TO_B(mp, count_fsb));
641 459 trace_xfs_zoned_map_blocks(ip, offset, wpc->iomap.length);
642 460 return 0;
643 461 }
modified fs/xfs/xfs_aops.h
@@ -10,6 +10,5 @@ extern const struct address_space_operations xfs_address_space_operations;
10 10 extern const struct address_space_operations xfs_dax_aops;
11 11
12 12 int xfs_setfilesize(struct xfs_inode *ip, xfs_off_t offset, size_t size);
13 - void xfs_end_bio(struct bio *bio);
14 13
15 14 #endif /* __XFS_AOPS_H__ */
modified fs/xfs/xfs_file.c
@@ -25,7 +25,7 @@
25 25 #include "xfs_iomap.h"
26 26 #include "xfs_reflink.h"
27 27 #include "xfs_file.h"
28 - #include "xfs_aops.h"
28 + #include "xfs_ioend.h"
29 29 #include "xfs_zone_alloc.h"
30 30 #include "xfs_error.h"
31 31 #include "xfs_errortag.h"
modified fs/xfs/xfs_fsmap.c
@@ -1174,8 +1174,7 @@ xfs_getfsmap(
1174 1174 if (!xfs_getfsmap_check_keys(&head->fmh_keys[0], &head->fmh_keys[1]))
1175 1175 return -EINVAL;
1176 1176
1177 - use_rmap = xfs_has_rmapbt(mp) &&
1178 - has_capability_noaudit(current, CAP_SYS_ADMIN);
1177 + use_rmap = xfs_has_rmapbt(mp) && capable_noaudit(CAP_SYS_ADMIN);
1179 1178 head->fmh_entries = 0;
1180 1179
1181 1180 /* Set up our device handlers. */
modified fs/xfs/xfs_icache.c
@@ -82,24 +82,20 @@ static inline xa_mark_t ici_tag_to_mark(unsigned int tag)
82 82
83 83 /*
84 84 * Allocate and initialise an xfs_inode.
85 + *
86 + * This can happen in context of already dirtied transactions, so the memory
87 + * allocations must not fail.
85 88 */
86 89 struct xfs_inode *
87 90 xfs_inode_alloc(
88 91 struct xfs_mount *mp,
89 92 xfs_ino_t ino)
90 93 {
94 + gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
91 95 struct xfs_inode *ip;
92 96
93 - /*
94 - * XXX: If this didn't occur in transactions, we could drop GFP_NOFAIL
95 - * and return NULL here on ENOMEM.
96 - */
97 - ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, GFP_KERNEL | __GFP_NOFAIL);
98 -
99 - if (inode_init_always(mp->m_super, VFS_I(ip))) {
100 - kmem_cache_free(xfs_inode_cache, ip);
101 - return NULL;
102 - }
97 + ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, gfp);
98 + inode_init_always_gfp(mp->m_super, VFS_I(ip), gfp);
103 99
104 100 VFS_I(ip)->i_ino = ino;
105 101 /* VFS doesn't initialise i_mode! */
modified fs/xfs/xfs_ioctl.c
@@ -647,7 +647,7 @@ xfs_ioctl_setattr_get_trans(
647 647 goto out_error;
648 648
649 649 error = xfs_trans_alloc_ichange(ip, NULL, NULL, pdqp,
650 - has_capability_noaudit(current, CAP_FOWNER), &tp);
650 + capable_noaudit(CAP_FOWNER), &tp);
651 651 if (error)
652 652 goto out_error;
653 653
added fs/xfs/xfs_ioend.c mode 100644
@@ -0,0 +1,184 @@
1 + // SPDX-License-Identifier: GPL-2.0
2 + /*
3 + * Copyright (c) 2016-2025 Christoph Hellwig.
4 + * All Rights Reserved.
5 + */
6 + #include "xfs_platform.h"
7 + #include "xfs_shared.h"
8 + #include "xfs_format.h"
9 + #include "xfs_log_format.h"
10 + #include "xfs_trans_resv.h"
11 + #include "xfs_mount.h"
12 + #include "xfs_inode.h"
13 + #include "xfs_iomap.h"
14 + #include "xfs_trace.h"
15 + #include "xfs_bmap_util.h"
16 + #include "xfs_reflink.h"
17 + #include "xfs_zone_alloc.h"
18 + #include "xfs_ioend.h"
19 +
20 + static void
21 + xfs_ioend_put_open_zones(
22 + struct iomap_ioend *ioend)
23 + {
24 + struct iomap_ioend *tmp;
25 +
26 + /*
27 + * Put the open zone for all ioends merged into this one (if any).
28 + */
29 + list_for_each_entry(tmp, &ioend->io_list, io_list)
30 + xfs_open_zone_put(tmp->io_private);
31 +
32 + /*
33 + * The main ioend might not have an open zone if the submission failed
34 + * before xfs_zone_alloc_and_submit got called.
35 + */
36 + if (ioend->io_private)
37 + xfs_open_zone_put(ioend->io_private);
38 + }
39 +
40 + static void
41 + xfs_end_ioend_write(
42 + struct iomap_ioend *ioend)
43 + {
44 + struct xfs_inode *ip = XFS_I(ioend->io_inode);
45 + struct xfs_mount *mp = ip->i_mount;
46 + bool is_zoned = xfs_is_zoned_inode(ip);
47 + xfs_off_t offset = ioend->io_offset;
48 + size_t size = ioend->io_size;
49 + unsigned int nofs_flag;
50 + int error;
51 +
52 + /*
53 + * We can allocate memory here while doing writeback on behalf of
54 + * memory reclaim. To avoid memory allocation deadlocks set the
55 + * task-wide nofs context for the following operations.
56 + */
57 + nofs_flag = memalloc_nofs_save();
58 +
59 + /*
60 + * Just clean up the in-memory structures if the fs has been shut down.
61 + */
62 + if (xfs_is_shutdown(mp)) {
63 + error = -EIO;
64 + goto done;
65 + }
66 +
67 + /*
68 + * Clean up all COW blocks and underlying data fork delalloc blocks on
69 + * I/O error. The delalloc punch is required because this ioend was
70 + * mapped to blocks in the COW fork and the associated pages are no
71 + * longer dirty. If we don't remove delalloc blocks here, they become
72 + * stale and can corrupt free space accounting on unmount.
73 + */
74 + error = blk_status_to_errno(ioend->io_bio.bi_status);
75 + if (unlikely(error)) {
76 + /*
77 + * Zoned writes update the in-core open zone accounting before
78 + * I/O submission. A failed write leaves that state
79 + * inconsistent, so shut down the filesystem instead of letting
80 + * later writers wait forever for open zone space to become
81 + * available.
82 + */
83 + if (is_zoned) {
84 + xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
85 + goto done;
86 + }
87 + if (ioend->io_flags & IOMAP_IOEND_SHARED) {
88 + ASSERT(!is_zoned);
89 + xfs_reflink_cancel_cow_range(ip, offset, size, true);
90 + xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, offset,
91 + offset + size, NULL);
92 + }
93 + goto done;
94 + }
95 +
96 + /*
97 + * Success: commit the COW or unwritten blocks if needed.
98 + */
99 + if (is_zoned)
100 + error = xfs_zoned_end_io(ip, offset, size, ioend->io_sector,
101 + ioend->io_private, NULLFSBLOCK);
102 + else if (ioend->io_flags & IOMAP_IOEND_SHARED)
103 + error = xfs_reflink_end_cow(ip, offset, size);
104 + else if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
105 + error = xfs_iomap_write_unwritten(ip, offset, size, false);
106 +
107 + if (!error &&
108 + !(ioend->io_flags & IOMAP_IOEND_DIRECT) &&
109 + xfs_ioend_is_append(ioend))
110 + error = xfs_setfilesize(ip, offset, size);
111 + done:
112 + if (is_zoned)
113 + xfs_ioend_put_open_zones(ioend);
114 + iomap_finish_ioends(ioend, error);
115 + memalloc_nofs_restore(nofs_flag);
116 + }
117 +
118 + /*
119 + * Finish all pending IO completions that require transactional modifications.
120 + *
121 + * We try to merge physical and logically contiguous ioends before completion to
122 + * minimise the number of transactions we need to perform during IO completion.
123 + * Both unwritten extent conversion and COW remapping need to iterate and modify
124 + * one physical extent at a time, so we gain nothing by merging physically
125 + * discontiguous extents here.
126 + *
127 + * The ioend chain length that we can be processing here is largely unbound in
128 + * length and we may have to perform significant amounts of work on each ioend
129 + * to complete it. Hence we have to be careful about holding the CPU for too
130 + * long in this loop.
131 + */
132 + void
133 + xfs_end_io(
134 + struct work_struct *work)
135 + {
136 + struct xfs_inode *ip =
137 + container_of(work, struct xfs_inode, i_ioend_work);
138 + struct iomap_ioend *ioend;
139 + struct list_head tmp;
140 + unsigned long flags;
141 +
142 + spin_lock_irqsave(&ip->i_ioend_lock, flags);
143 + list_replace_init(&ip->i_ioend_list, &tmp);
144 + spin_unlock_irqrestore(&ip->i_ioend_lock, flags);
145 +
146 + iomap_sort_ioends(&tmp);
147 + while ((ioend = list_first_entry_or_null(&tmp, struct iomap_ioend,
148 + io_list))) {
149 + list_del_init(&ioend->io_list);
150 + iomap_ioend_try_merge(ioend, &tmp);
151 + if (bio_op(&ioend->io_bio) == REQ_OP_READ)
152 + iomap_finish_ioends(ioend,
153 + blk_status_to_errno(ioend->io_bio.bi_status));
154 + else
155 + xfs_end_ioend_write(ioend);
156 + cond_resched();
157 + }
158 + }
159 +
160 + void
161 + xfs_end_bio(
162 + struct bio *bio)
163 + {
164 + struct iomap_ioend *ioend = iomap_ioend_from_bio(bio);
165 + struct xfs_inode *ip = XFS_I(ioend->io_inode);
166 + struct xfs_mount *mp = ip->i_mount;
167 + unsigned long flags;
168 +
169 + /*
170 + * For Appends record the actually written block number and set the
171 + * boundary flag if needed.
172 + */
173 + if (IS_ENABLED(CONFIG_XFS_RT) && bio_is_zone_append(bio)) {
174 + ioend->io_sector = bio->bi_iter.bi_sector;
175 + xfs_mark_rtg_boundary(ioend);
176 + }
177 +
178 + spin_lock_irqsave(&ip->i_ioend_lock, flags);
179 + if (list_empty(&ip->i_ioend_list))
180 + WARN_ON_ONCE(!queue_work(mp->m_unwritten_workqueue,
181 + &ip->i_ioend_work));
182 + list_add_tail(&ioend->io_list, &ip->i_ioend_list);
183 + spin_unlock_irqrestore(&ip->i_ioend_lock, flags);
184 + }
added fs/xfs/xfs_ioend.h mode 100644
@@ -0,0 +1,16 @@
1 + /* SPDX-License-Identifier: GPL-2.0 */
2 + #ifndef __XFS_IOEND_H
3 + #define __XFS_IOEND_H
4 +
5 + /*
6 + * Fast and loose check if this write could update the on-disk inode size.
7 + */
8 + static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
9 + {
10 + return ioend->io_offset + ioend->io_size >
11 + XFS_I(ioend->io_inode)->i_disk_size;
12 + }
13 +
14 + void xfs_end_bio(struct bio *bio);
15 +
16 + #endif /* __XFS_IOEND_H */
modified fs/xfs/xfs_iomap.c
@@ -1083,12 +1083,7 @@ xfs_zoned_direct_write_iomap_begin(
1083 1083 return error;
1084 1084 }
1085 1085
1086 - iomap->type = IOMAP_MAPPED;
1087 - iomap->flags = IOMAP_F_DIRTY;
1088 - iomap->bdev = ip->i_mount->m_rtdev_targp->bt_bdev;
1089 - iomap->offset = offset;
1090 - iomap->length = length;
1091 - iomap->flags = IOMAP_F_ANON_WRITE;
1086 + xfs_iomap_set_anon_write(ip, iomap, offset, length);
1092 1087 return 0;
1093 1088 }
1094 1089
modified fs/xfs/xfs_iomap.h
@@ -29,6 +29,20 @@ int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,
29 29 int xfs_truncate_page(struct xfs_inode *ip, loff_t pos,
30 30 struct xfs_zone_alloc_ctx *ac, bool *did_zero);
31 31
32 + static inline void
33 + xfs_iomap_set_anon_write(
34 + struct xfs_inode *ip,
35 + struct iomap *iomap,
36 + loff_t offset,
37 + loff_t length)
38 + {
39 + iomap->type = IOMAP_MAPPED;
40 + iomap->bdev = ip->i_mount->m_rtdev_targp->bt_bdev;
41 + iomap->offset = offset;
42 + iomap->length = length;
43 + iomap->flags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
44 + }
45 +
32 46 static inline xfs_filblks_t
33 47 xfs_aligned_fsb_count(
34 48 xfs_fileoff_t offset_fsb,
modified fs/xfs/xfs_iops.c
@@ -834,7 +834,7 @@ xfs_setattr_nonsize(
834 834 }
835 835
836 836 error = xfs_trans_alloc_ichange(ip, udqp, gdqp, NULL,
837 - has_capability_noaudit(current, CAP_FOWNER), &tp);
837 + capable_noaudit(CAP_FOWNER), &tp);
838 838 if (error)
839 839 goto out_dqrele;
840 840
modified fs/xfs/xfs_platform.h
@@ -289,15 +289,4 @@ int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
289 289 # define PTR_FMT "%p"
290 290 #endif
291 291
292 - /*
293 - * Helper for IO routines to grab backing pages from allocated kernel memory.
294 - */
295 - static inline struct page *
296 - kmem_to_page(void *addr)
297 - {
298 - if (is_vmalloc_addr(addr))
299 - return vmalloc_to_page(addr);
300 - return virt_to_page(addr);
301 - }
302 -
303 292 #endif /* _XFS_PLATFORM_H */
modified fs/xfs/xfs_super.c
@@ -445,7 +445,7 @@ xfs_shutdown_devices(
445 445 blkdev_issue_flush(mp->m_logdev_targp->bt_bdev);
446 446 invalidate_bdev(mp->m_logdev_targp->bt_bdev);
447 447 }
448 - if (mp->m_rtdev_targp) {
448 + if (mp->m_rtdev_targp && mp->m_rtdev_targp != mp->m_ddev_targp) {
449 449 blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev);
450 450 invalidate_bdev(mp->m_rtdev_targp->bt_bdev);
451 451 }
modified fs/xfs/xfs_trans_buf.c
@@ -521,7 +521,8 @@ xfs_trans_log_buf(
521 521 {
522 522 struct xfs_buf_log_item *bip = bp->b_log_item;
523 523
524 - ASSERT(first <= last && last < BBTOB(bp->b_length));
524 + ASSERT(first <= last);
525 + ASSERT(last < BBTOB(bp->b_length));
525 526 ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED));
526 527
527 528 xfs_trans_dirty_buf(tp, bp);
modified fs/xfs/xfs_zone_alloc.c
@@ -793,17 +793,35 @@ xfs_get_cached_zone(
793 793
794 794 rcu_read_lock();
795 795 oz = VFS_I(ip)->i_private;
796 - if (oz) {
797 - /*
798 - * GC only steals open zones at mount time, so no GC zones
799 - * should end up in the cache.
800 - */
801 - ASSERT(!oz->oz_is_gc);
802 - if (!atomic_inc_not_zero(&oz->oz_ref))
796 + if (!oz)
797 + goto out_unlock;
798 +
799 + /*
800 + * GC only steals open zones at mount time, so no GC zones should end up
801 + * in the cache.
802 + */
803 + ASSERT(!oz->oz_is_gc);
804 +
805 + /*
806 + * Drop the old cached open zone if it is full.
807 + */
808 + if (oz->oz_allocated == rtg_blocks(oz->oz_rtg)) {
809 + spin_lock(&ip->i_flags_lock);
810 + oz = VFS_I(ip)->i_private;
811 + if (oz && oz->oz_allocated == rtg_blocks(oz->oz_rtg)) {
812 + VFS_I(ip)->i_private = NULL;
813 + spin_unlock(&ip->i_flags_lock);
814 + xfs_open_zone_put(oz);
803 815 oz = NULL;
816 + goto out_unlock;
817 + }
818 + spin_unlock(&ip->i_flags_lock);
804 819 }
805 - rcu_read_unlock();
806 820
821 + if (!atomic_inc_not_zero(&oz->oz_ref))
822 + oz = NULL;
823 + out_unlock:
824 + rcu_read_unlock();
807 825 return oz;
808 826 }
809 827
@@ -818,18 +836,41 @@ xfs_get_cached_zone(
818 836 * that were every written to, but significantly simplifies the cached zone
819 837 * lookup. Because the open_zone is clearly marked as full when all data
820 838 * in the underlying RTG was written, the caching is always safe.
839 + *
840 + * Called with a reference on @oz held. And returns two references on the
841 + * returned zone: one for the caller and one for pinning the zone in
842 + * inode->i_private.
821 843 */
822 - static void
844 + static struct xfs_open_zone *
823 845 xfs_set_cached_zone(
824 846 struct xfs_inode *ip,
825 847 struct xfs_open_zone *oz)
826 848 {
827 849 struct xfs_open_zone *old_oz;
828 850
851 + /*
852 + * If the open zone cached in the inode still has free space, use that
853 + * instead of the new open zone just selected. This can happen when
854 + * multiple threads race to perform zone selection for an inode.
855 + * io_uring worker threads seem to be good way to trigger this.
856 + *
857 + * We need to grab an extra reference to this open zone as the caller
858 + * owns a reference in addition to the i_private pointer.
859 + */
860 + spin_lock(&ip->i_flags_lock);
861 + old_oz = VFS_I(ip)->i_private;
862 + if (old_oz && old_oz->oz_allocated < rtg_blocks(old_oz->oz_rtg) &&
863 + atomic_inc_not_zero(&old_oz->oz_ref)) {
864 + spin_unlock(&ip->i_flags_lock);
865 + xfs_open_zone_put(oz);
866 + return old_oz;
867 + }
868 + VFS_I(ip)->i_private = oz;
829 869 atomic_inc(&oz->oz_ref);
830 - old_oz = xchg(&VFS_I(ip)->i_private, oz);
870 + spin_unlock(&ip->i_flags_lock);
831 871 if (old_oz)
832 872 xfs_open_zone_put(old_oz);
873 + return oz;
833 874 }
834 875
835 876 static void
@@ -873,14 +914,13 @@ xfs_zone_alloc_and_submit(
873 914 * the inode is still associated with a zone and use that if so.
874 915 */
875 916 if (!*oz)
917 + select_zone:
876 918 *oz = xfs_get_cached_zone(ip);
877 -
878 919 if (!*oz) {
879 - select_zone:
880 920 *oz = xfs_select_zone(mp, write_hint, pack_tight);
881 921 if (!*oz)
882 922 goto out_error;
883 - xfs_set_cached_zone(ip, *oz);
923 + *oz = xfs_set_cached_zone(ip, *oz);
884 924 }
885 925
886 926 alloc_len = xfs_zone_alloc_blocks(*oz, XFS_B_TO_FSB(mp, ioend->io_size),
modified fs/xfs/xfs_zone_gc.c
@@ -869,6 +869,11 @@ xfs_zone_gc_write_chunk(
869 869 WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
870 870 list_move_tail(&chunk->entry, &data->writing);
871 871
872 + /*
873 + * If we run on top of stacked block device, the read I/O might have
874 + * reset bi_bdev, restore it to the one we want.
875 + */
876 + bio_set_dev(&chunk->bio, mp->m_rtdev_targp->bt_bdev);
872 877 bio_reuse(&chunk->bio, REQ_OP_WRITE);
873 878 while ((split_chunk = xfs_zone_gc_split_write(data, chunk)))
874 879 xfs_zone_gc_submit_write(data, split_chunk);
modified include/acpi/acpi_bus.h
@@ -202,12 +202,8 @@ struct acpi_device_dir {
202 202
203 203 /* Plug and Play */
204 204
205 - #define MAX_ACPI_DEVICE_NAME_LEN 40
206 - #define MAX_ACPI_CLASS_NAME_LEN 20
207 205 typedef char acpi_bus_id[8];
208 206 typedef u64 acpi_bus_address;
209 - typedef char acpi_device_name[MAX_ACPI_DEVICE_NAME_LEN];
210 - typedef char acpi_device_class[MAX_ACPI_CLASS_NAME_LEN];
211 207
212 208 struct acpi_hardware_id {
213 209 struct list_head list;
@@ -229,16 +225,12 @@ struct acpi_device_pnp {
229 225 acpi_bus_address bus_address; /* _ADR */
230 226 char *unique_id; /* _UID */
231 227 struct list_head ids; /* _HID and _CIDs */
232 - acpi_device_name device_name; /* Driver-determined */
233 - acpi_device_class device_class; /* " */
234 228 };
235 229
236 230 #define acpi_device_bid(d) ((d)->pnp.bus_id)
237 231 #define acpi_device_adr(d) ((d)->pnp.bus_address)
238 232 const char *acpi_device_hid(struct acpi_device *device);
239 233 #define acpi_device_uid(d) ((d)->pnp.unique_id)
240 - #define acpi_device_name(d) ((d)->pnp.device_name)
241 - #define acpi_device_class(d) ((d)->pnp.device_class)
242 234
243 235 /* Power Management */
244 236
@@ -578,6 +570,9 @@ int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
578 570 * ------
579 571 */
580 572
573 + #define MAX_ACPI_CLASS_NAME_LEN 20
574 + typedef char acpi_device_class[MAX_ACPI_CLASS_NAME_LEN];
575 +
581 576 struct acpi_bus_event {
582 577 struct list_head node;
583 578 acpi_device_class device_class;
modified include/drm/drm_pagemap.h
@@ -2,6 +2,7 @@
2 2 #ifndef _DRM_PAGEMAP_H_
3 3 #define _DRM_PAGEMAP_H_
4 4
5 + #include <linux/bits.h>
5 6 #include <linux/dma-direction.h>
6 7 #include <linux/hmm.h>
7 8 #include <linux/memremap.h>
@@ -339,6 +340,9 @@ struct drm_pagemap_migrate_details {
339 340
340 341 #if IS_ENABLED(CONFIG_ZONE_DEVICE)
341 342
343 + #define DRM_PAGEMAP_ZDD_FLAG_MIGRATED BIT(0)
344 + #define DRM_PAGEMAP_ZDD_FLAG_MASK DRM_PAGEMAP_ZDD_FLAG_MIGRATED
345 +
342 346 int drm_pagemap_migrate_to_devmem(struct drm_pagemap_devmem *devmem_allocation,
343 347 struct mm_struct *mm,
344 348 unsigned long start, unsigned long end,
@@ -373,7 +377,9 @@ static inline struct drm_pagemap_zdd *drm_pagemap_page_zone_device_data(struct p
373 377 {
374 378 struct folio *folio = page_folio(page);
375 379
376 - return folio_zone_device_data(folio);
380 + return (struct drm_pagemap_zdd *)
381 + ((unsigned long)folio_zone_device_data(folio) &
382 + ~DRM_PAGEMAP_ZDD_FLAG_MASK);
377 383 }
378 384
379 385 #else
modified include/linux/bpf.h
@@ -894,6 +894,7 @@ enum bpf_arg_type {
894 894
895 895 ARG_PTR_TO_CTX, /* pointer to context */
896 896 ARG_ANYTHING, /* any (initialized) argument is ok */
897 + ARG_SCALAR, /* scalar argument */
897 898 ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */
898 899 ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */
899 900 ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */
@@ -4209,7 +4210,7 @@ static inline int bpf_map_check_op_flags(struct bpf_map *map, u64 flags, u64 all
4209 4210 return -EINVAL;
4210 4211
4211 4212 cpu = flags >> 32;
4212 - if ((flags & BPF_F_CPU) && cpu >= num_possible_cpus())
4213 + if ((flags & BPF_F_CPU) && (cpu >= nr_cpu_ids || !cpu_possible(cpu)))
4213 4214 return -ERANGE;
4214 4215 }
4215 4216
modified include/linux/bpf_verifier.h
@@ -706,6 +706,8 @@ struct bpf_insn_aux_data {
706 706 */
707 707 u32 calls_callback:1;
708 708 u32 indirect_target:1; /* if it is an indirect jump target */
709 + /* true if some jump or call instruction targets this instruction */
710 + u32 jump_target:1;
709 711 /*
710 712 * CFG strongly connected component this instruction belongs to,
711 713 * zero if it is a singleton SCC.
@@ -1142,6 +1144,16 @@ static inline void mark_jmp_point(struct bpf_verifier_env *env, int idx)
1142 1144 env->insn_aux_data[idx].jmp_point = true;
1143 1145 }
1144 1146
1147 + static inline void mark_jump_target(struct bpf_verifier_env *env, int idx)
1148 + {
1149 + env->insn_aux_data[idx].jump_target = true;
1150 + }
1151 +
1152 + static inline bool bpf_is_jump_target(struct bpf_verifier_env *env, int insn_idx)
1153 + {
1154 + return env->insn_aux_data[insn_idx].jump_target;
1155 + }
1156 +
1145 1157 static inline struct bpf_func_state *cur_func(struct bpf_verifier_env *env)
1146 1158 {
1147 1159 struct bpf_verifier_state *cur = env->cur_state;
@@ -1369,7 +1381,9 @@ static inline bool bpf_type_has_unsafe_modifiers(u32 type)
1369 1381
1370 1382 static inline bool type_is_ptr_alloc_obj(u32 type)
1371 1383 {
1372 - return base_type(type) == PTR_TO_BTF_ID && type_flag(type) & MEM_ALLOC;
1384 + return base_type(type) == PTR_TO_BTF_ID &&
1385 + type_flag(type) & MEM_ALLOC &&
1386 + !(type_flag(type) & PTR_UNTRUSTED);
1373 1387 }
1374 1388
1375 1389 static inline bool type_is_non_owning_ref(u32 type)
modified include/linux/capability.h
@@ -145,6 +145,7 @@ extern bool has_capability_noaudit(struct task_struct *t, int cap);
145 145 extern bool has_ns_capability_noaudit(struct task_struct *t,
146 146 struct user_namespace *ns, int cap);
147 147 extern bool capable(int cap);
148 + bool capable_noaudit(int cap);
148 149 extern bool ns_capable(struct user_namespace *ns, int cap);
149 150 extern bool ns_capable_noaudit(struct user_namespace *ns, int cap);
150 151 extern bool ns_capable_setid(struct user_namespace *ns, int cap);
@@ -167,6 +168,10 @@ static inline bool capable(int cap)
167 168 {
168 169 return true;
169 170 }
171 + static inline bool capable_noaudit(int cap)
172 + {
173 + return true;
174 + }
170 175 static inline bool ns_capable(struct user_namespace *ns, int cap)
171 176 {
172 177 return true;
modified include/linux/cgroup-defs.h
@@ -527,7 +527,10 @@ struct cgroup {
527 527
528 528 int nr_threaded_children; /* # of live threaded child cgroups */
529 529
530 - /* sequence number for cgroup.kill, serialized by css_set_lock. */
530 + /*
531 + * Sequence number for cgroup.kill. Incremented with both cgroup_mutex
532 + * and css_set_lock held. Readers hold either one.
533 + */
531 534 unsigned int kill_seq;
532 535
533 536 struct kernfs_node *kn; /* cgroup kernfs entry */
modified include/linux/device-id/ap.h
@@ -4,7 +4,6 @@
4 4
5 5 #ifdef __KERNEL__
6 6 #include <linux/types.h>
7 - typedef unsigned long kernel_ulong_t;
8 7 #endif
9 8
10 9 #define AP_DEVICE_ID_MATCH_CARD_TYPE 0x01
@@ -14,7 +13,6 @@ typedef unsigned long kernel_ulong_t;
14 13 struct ap_device_id {
15 14 __u16 match_flags; /* which fields to match against */
16 15 __u8 dev_type; /* device type */
17 - kernel_ulong_t driver_info;
18 16 };
19 17
20 18 #endif /* ifndef LINUX_DEVICE_ID_AP_H */
modified include/linux/dma-buf.h
@@ -567,6 +567,7 @@ void dma_buf_unpin(struct dma_buf_attachment *attach);
567 567 struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info);
568 568
569 569 int dma_buf_fd(struct dma_buf *dmabuf, int flags);
570 + void dma_buf_fd_install(struct dma_buf *dmabuf, int fd);
570 571 struct dma_buf *dma_buf_get(int fd);
571 572 void dma_buf_put(struct dma_buf *dmabuf);
572 573
modified include/linux/dma-fence-array.h
@@ -28,7 +28,6 @@ struct dma_fence_array_cb {
28 28 /**
29 29 * struct dma_fence_array - fence to represent an array of fences
30 30 * @base: fence base class
31 - * @lock: spinlock for fence handling
32 31 * @num_fences: number of fences in the array
33 32 * @num_pending: fences in the array still pending
34 33 * @fences: array of the fences
modified include/linux/dma-fence-chain.h
@@ -20,7 +20,6 @@
20 20 * @prev: previous fence of the chain
21 21 * @prev_seqno: original previous seqno before garbage collection
22 22 * @fence: encapsulated fence
23 - * @lock: spinlock for fence handling
24 23 */
25 24 struct dma_fence_chain {
26 25 struct dma_fence base;
@@ -81,9 +80,8 @@ dma_fence_chain_contained(struct dma_fence *fence)
81 80 }
82 81
83 82 /**
84 - * dma_fence_chain_alloc
85 - *
86 - * Returns a new struct dma_fence_chain object or NULL on failure.
83 + * dma_fence_chain_alloc - Returns a new &struct dma_fence_chain object or
84 + * %NULL on failure.
87 85 *
88 86 * This specialized allocator has to be a macro for its allocations to be
89 87 * accounted separately (to have a separate alloc_tag). The typecast is
@@ -93,7 +91,8 @@ dma_fence_chain_contained(struct dma_fence *fence)
93 91 kmalloc_obj(struct dma_fence_chain)
94 92
95 93 /**
96 - * dma_fence_chain_free
94 + * dma_fence_chain_free - Frees an allocated but not used
95 + * &struct dma_fence_chain object.
97 96 * @chain: chain node to free
98 97 *
99 98 * Frees up an allocated but not used struct dma_fence_chain object. This
modified include/linux/edac.h
@@ -598,9 +598,6 @@ struct mem_ctl_info {
598 598 int op_state;
599 599
600 600 struct dentry *debugfs;
601 - u8 fake_inject_layer[EDAC_MAX_LAYERS];
602 - bool fake_inject_ue;
603 - u16 fake_inject_count;
604 601
605 602 /*
606 603 * Memory Controller hierarchy
modified include/linux/filter.h
@@ -1376,7 +1376,6 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
1376 1376 void bpf_jit_binary_free(struct bpf_binary_header *hdr);
1377 1377 u64 bpf_jit_alloc_exec_limit(void);
1378 1378 void *bpf_jit_alloc_exec(unsigned long size);
1379 - void *bpf_jit_alloc_exec_rw(unsigned long size);
1380 1379 void bpf_jit_free_exec(void *addr);
1381 1380 void bpf_jit_free(struct bpf_prog *fp);
1382 1381 struct bpf_binary_header *
modified include/linux/ftrace.h
@@ -866,8 +866,9 @@ unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
866 866 unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
867 867
868 868 extern ftrace_func_t ftrace_trace_function;
869 + struct trace_array;
869 870
870 - int ftrace_regex_open(struct ftrace_ops *ops, int flag,
871 + int ftrace_regex_open(struct trace_array *tr, struct ftrace_ops *ops, int flag,
871 872 struct inode *inode, struct file *file);
872 873 ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
873 874 size_t cnt, loff_t *ppos);
@@ -1077,7 +1078,7 @@ static inline unsigned long ftrace_location(unsigned long ip)
1077 1078 * have them defined when ftrace is not enabled, but these
1078 1079 * functions may still be called. Use a macro instead of inline.
1079 1080 */
1080 - #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
1081 + #define ftrace_regex_open(tr, ops, flag, inode, file) ({ -ENODEV; })
1081 1082 #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
1082 1083 #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
1083 1084 #define ftrace_set_filter_ips(ops, ips, cnt, remove, reset) ({ -ENODEV; })
modified include/linux/igmp.h
@@ -57,20 +57,21 @@ struct ip_mc_socklist {
57 57 };
58 58
59 59 struct ip_sf_list {
60 - struct ip_sf_list *sf_next;
60 + struct ip_sf_list __rcu *sf_next;
61 61 unsigned long sf_count[2]; /* include/exclude counts */
62 62 __be32 sf_inaddr;
63 63 unsigned char sf_gsresp; /* include in g & s response? */
64 64 unsigned char sf_oldin; /* change state */
65 65 unsigned char sf_crcount; /* retrans. left to send */
66 + struct rcu_head rcu;
66 67 };
67 68
68 69 struct ip_mc_list {
69 70 struct in_device *interface;
70 71 __be32 multiaddr;
71 72 unsigned int sfmode;
72 - struct ip_sf_list *sources;
73 - struct ip_sf_list *tomb;
73 + struct ip_sf_list __rcu *sources;
74 + struct ip_sf_list __rcu *tomb;
74 75 unsigned long sfcount[2];
75 76 union {
76 77 struct ip_mc_list *next;
modified include/linux/interrupt_rc.h
@@ -20,11 +20,8 @@
20 20 /* Per-CPU interrupt disabling state for local_interrupt_{disable,enable}(). */
21 21 DECLARE_PER_CPU(unsigned long, local_interrupt_disable_state);
22 22
23 - static __always_inline void __local_interrupt_disable(void)
23 + static __always_inline void __local_interrupt_save_state(unsigned long flags)
24 24 {
25 - unsigned long flags;
26 -
27 - local_irq_save(flags);
28 25 raw_cpu_write(local_interrupt_disable_state, flags);
29 26 }
30 27
@@ -36,9 +33,9 @@ static __always_inline void __local_interrupt_enable(void)
36 33 }
37 34
38 35 #ifndef INSTANTIATE_EXPORTED_INTERRUPT_DISABLE
39 - static __always_inline void _local_interrupt_disable(void)
36 + static __always_inline void _local_interrupt_save_state(unsigned long flags)
40 37 {
41 - __local_interrupt_disable();
38 + __local_interrupt_save_state(flags);
42 39 }
43 40
44 41 static __always_inline void _local_interrupt_enable(void)
@@ -46,27 +43,30 @@ static __always_inline void _local_interrupt_enable(void)
46 43 __local_interrupt_enable();
47 44 }
48 45 #else
49 - extern void _local_interrupt_disable(void);
46 + extern void _local_interrupt_save_state(unsigned long flags);
50 47 extern void _local_interrupt_enable(void);
51 48 #endif
52 49
53 50 #else /* !MODULE */
54 - extern void _local_interrupt_disable(void);
51 + extern void _local_interrupt_save_state(unsigned long flags);
55 52 extern void _local_interrupt_enable(void);
56 53 #endif /* !MODULE */
57 54
55 + #define hardirq_disable_enter() __preempt_count_add_return(HARDIRQ_DISABLE_OFFSET)
56 + #define hardirq_disable_exit() __preempt_count_sub_return(HARDIRQ_DISABLE_OFFSET)
57 +
58 58 static inline void local_interrupt_disable(void)
59 59 {
60 60 int new_count;
61 + unsigned long flags;
61 62
62 63 WARN_ON_ONCE(in_nmi());
63 64
65 + local_irq_save(flags);
64 66 new_count = hardirq_disable_enter();
65 67
66 - /* Interrupts can happen here, but it's OK, see __irq_exit_rcu(). */
67 -
68 68 if ((new_count & HARDIRQ_DISABLE_MASK) == HARDIRQ_DISABLE_OFFSET)
69 - _local_interrupt_disable();
69 + _local_interrupt_save_state(flags);
70 70 }
71 71
72 72 static inline void local_interrupt_enable(void)
modified include/linux/irqdomain.h
@@ -752,24 +752,6 @@ static inline void msi_device_domain_free_wired(struct irq_domain *domain, unsig
752 752 }
753 753 #endif
754 754
755 - static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
756 - unsigned int size,
757 - const struct irq_domain_ops *ops,
758 - void *host_data)
759 - {
760 - struct irq_domain_info info = {
761 - .fwnode = of_fwnode_handle(of_node),
762 - .size = size,
763 - .hwirq_max = size,
764 - .ops = ops,
765 - .host_data = host_data,
766 - };
767 - struct irq_domain *d;
768 -
769 - d = irq_domain_instantiate(&info);
770 - return IS_ERR(d) ? NULL : d;
771 - }
772 -
773 755 #else /* CONFIG_IRQ_DOMAIN */
774 756 static inline void irq_dispose_mapping(unsigned int virq) { }
775 757 static inline struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
modified include/linux/kprobes.h
@@ -181,6 +181,7 @@ struct kprobe_blacklist_entry {
181 181 struct list_head list;
182 182 unsigned long start_addr;
183 183 unsigned long end_addr;
184 + struct rcu_head rcu;
184 185 };
185 186
186 187 #ifdef CONFIG_KPROBES
modified include/linux/nvme-tcp.h
@@ -77,7 +77,7 @@ struct nvme_tcp_hdr {
77 77 __le32 plen;
78 78 };
79 79
80 - /**
80 + /*
81 81 * struct nvme_tcp_icreq_pdu - nvme tcp initialize connection request pdu
82 82 *
83 83 * @hdr: pdu generic header
@@ -95,7 +95,7 @@ struct nvme_tcp_icreq_pdu {
95 95 __u8 rsvd2[112];
96 96 };
97 97
98 - /**
98 + /*
99 99 * struct nvme_tcp_icresp_pdu - nvme tcp initialize connection response pdu
100 100 *
101 101 * @hdr: pdu common header
@@ -113,12 +113,13 @@ struct nvme_tcp_icresp_pdu {
113 113 __u8 rsvd[112];
114 114 };
115 115
116 - /**
116 + /*
117 117 * struct nvme_tcp_term_pdu - nvme tcp terminate connection pdu
118 118 *
119 119 * @hdr: pdu common header
120 120 * @fes: fatal error status
121 - * @fei: fatal error information
121 + * @feil: fatal error information (low 16 bits)
122 + * @feih: fatal error information (high 16 bits)
122 123 */
123 124 struct nvme_tcp_term_pdu {
124 125 struct nvme_tcp_hdr hdr;
@@ -128,7 +129,7 @@ struct nvme_tcp_term_pdu {
128 129 __u8 rsvd[10];
129 130 };
130 131
131 - /**
132 + /*
132 133 * struct nvme_tcp_cmd_pdu - nvme tcp command capsule pdu
133 134 *
134 135 * @hdr: pdu common header
@@ -139,10 +140,9 @@ struct nvme_tcp_cmd_pdu {
139 140 struct nvme_command cmd;
140 141 };
141 142
142 - /**
143 + /*
143 144 * struct nvme_tcp_rsp_pdu - nvme tcp response capsule pdu
144 145 *
145 - * @hdr: pdu common header
146 146 * @hdr: nvme-tcp generic header
147 147 * @cqe: nvme completion queue entry
148 148 */
@@ -151,7 +151,7 @@ struct nvme_tcp_rsp_pdu {
151 151 struct nvme_completion cqe;
152 152 };
153 153
154 - /**
154 + /*
155 155 * struct nvme_tcp_r2t_pdu - nvme tcp ready-to-transfer pdu
156 156 *
157 157 * @hdr: pdu common header
@@ -169,7 +169,7 @@ struct nvme_tcp_r2t_pdu {
169 169 __u8 rsvd[4];
170 170 };
171 171
172 - /**
172 + /*
173 173 * struct nvme_tcp_data_pdu - nvme tcp data pdu
174 174 *
175 175 * @hdr: pdu common header
modified include/linux/preempt.h
@@ -168,10 +168,6 @@ static __always_inline unsigned char interrupt_context_level(void)
168 168 #define in_softirq() (softirq_count())
169 169 #define in_interrupt() (irq_count())
170 170
171 - #define hardirq_disable_count() ((preempt_count() & HARDIRQ_DISABLE_MASK) >> HARDIRQ_DISABLE_SHIFT)
172 - #define hardirq_disable_enter() __preempt_count_add_return(HARDIRQ_DISABLE_OFFSET)
173 - #define hardirq_disable_exit() __preempt_count_sub_return(HARDIRQ_DISABLE_OFFSET)
174 -
175 171 /*
176 172 * The preempt_count offset after preempt_disable();
177 173 */
modified include/linux/ring_buffer.h
@@ -218,14 +218,15 @@ bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer);
218 218 size_t ring_buffer_nr_dirty_pages(struct trace_buffer *buffer, int cpu);
219 219
220 220 struct buffer_data_read_page;
221 - struct buffer_data_read_page *
222 - ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu);
221 + int ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu,
222 + struct buffer_data_read_page **rpage);
223 223 void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu,
224 224 struct buffer_data_read_page *page);
225 225 int ring_buffer_read_page(struct trace_buffer *buffer,
226 226 struct buffer_data_read_page *data_page,
227 227 size_t len, int cpu, int full);
228 228 void *ring_buffer_read_page_data(struct buffer_data_read_page *page);
229 + unsigned int ring_buffer_read_page_size(struct buffer_data_read_page *rpage);
229 230
230 231 struct trace_seq;
231 232
modified include/linux/sched/rt.h
@@ -52,8 +52,10 @@ static inline bool rt_or_dl_task_policy(struct task_struct *tsk)
52 52
53 53 #ifdef CONFIG_RT_MUTEXES
54 54 extern void rt_mutex_pre_schedule(void);
55 + extern void rt_mutex_futex_pre_schedule(void);
55 56 extern void rt_mutex_schedule(void);
56 57 extern void rt_mutex_post_schedule(void);
58 + extern void rt_mutex_futex_post_schedule(void);
57 59
58 60 /*
59 61 * Must hold either p->pi_lock or task_rq(p)->lock.
modified include/linux/sched/user.h
@@ -25,7 +25,8 @@ struct user_struct {
25 25
26 26 #if defined(CONFIG_PERF_EVENTS) || defined(CONFIG_BPF_SYSCALL) || \
27 27 defined(CONFIG_NET) || defined(CONFIG_IO_URING) || \
28 - defined(CONFIG_VFIO_PCI_ZDEV_KVM) || IS_ENABLED(CONFIG_IOMMUFD)
28 + defined(CONFIG_VFIO_PCI_ZDEV_KVM) || IS_ENABLED(CONFIG_IOMMUFD) || \
29 + defined(CONFIG_SECRETMEM)
29 30 atomic_long_t locked_vm;
30 31 #endif
31 32 #ifdef CONFIG_WATCH_QUEUE
modified include/linux/skbuff.h
@@ -3082,6 +3082,11 @@ static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
3082 3082 return skb->transport_header != (typeof(skb->transport_header))~0U;
3083 3083 }
3084 3084
3085 + static inline void skb_unset_transport_header(struct sk_buff *skb)
3086 + {
3087 + skb->transport_header = (typeof(skb->transport_header))~0U;
3088 + }
3089 +
3085 3090 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
3086 3091 {
3087 3092 DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb));
modified include/net/af_vsock.h
@@ -229,6 +229,9 @@ struct sock *vsock_find_bound_socket_net(struct sockaddr_vm *addr,
229 229 struct sock *vsock_find_connected_socket_net(struct sockaddr_vm *src,
230 230 struct sockaddr_vm *dst,
231 231 struct net *net);
232 + bool vsock_check_source(const struct vsock_sock *vsk,
233 + const struct vsock_transport *transport,
234 + const struct sockaddr_vm *src);
232 235 void vsock_remove_sock(struct vsock_sock *vsk);
233 236 void vsock_for_each_connected_socket(struct vsock_transport *transport,
234 237 void (*fn)(struct sock *sk));
modified include/net/if_inet6.h
@@ -88,8 +88,6 @@ struct ip6_sf_socklist {
88 88 struct in6_addr sl_addr[] __counted_by(sl_max);
89 89 };
90 90
91 - #define IP6_SFBLOCK 10 /* allocate this many at once */
92 -
93 91 struct ipv6_mc_socklist {
94 92 struct in6_addr addr;
95 93 int ifindex;
modified include/net/ip.h
@@ -704,7 +704,8 @@ static inline void ip_ipgre_mc_map(__be32 naddr, const unsigned char *broadcast,
704 704
705 705 static __inline__ void inet_reset_saddr(struct sock *sk)
706 706 {
707 - inet_sk(sk)->inet_rcv_saddr = inet_sk(sk)->inet_saddr = 0;
707 + inet_sk(sk)->inet_saddr = 0;
708 + WRITE_ONCE(inet_sk(sk)->inet_rcv_saddr, 0);
708 709 #if IS_ENABLED(CONFIG_IPV6)
709 710 if (sk->sk_family == PF_INET6) {
710 711 struct ipv6_pinfo *np = inet6_sk(sk);
modified include/net/tcp.h
@@ -765,8 +765,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue,
765 765 void tcp_send_probe0(struct sock *);
766 766 int tcp_write_wakeup(struct sock *, int mib);
767 767 void tcp_send_fin(struct sock *sk);
768 - void tcp_send_active_reset(struct sock *sk, gfp_t priority,
769 - enum sk_rst_reason reason);
768 + void tcp_send_active_reset(struct sock *sk, enum sk_rst_reason reason);
770 769 int tcp_send_synack(struct sock *);
771 770 void tcp_push_one(struct sock *, unsigned int mss_now);
772 771 void __tcp_send_ack(struct sock *sk, u32 rcv_nxt, u16 flags);
modified include/trace/events/icmp.h
@@ -27,17 +27,20 @@ TRACE_EVENT(icmp_send,
27 27
28 28 TP_fast_assign(
29 29 struct iphdr *iph = ip_hdr(skb);
30 - struct udphdr *uh = udp_hdr(skb);
31 - int proto_4 = iph->protocol;
30 + struct udphdr _uh, *uh = NULL;
32 31 __be32 *p32;
33 32
34 33 __entry->skbaddr = skb;
35 34 __entry->type = type;
36 35 __entry->code = code;
37 36
38 - if (proto_4 != IPPROTO_UDP || (u8 *)uh < skb->head ||
39 - (u8 *)uh + sizeof(struct udphdr)
40 - > skb_tail_pointer(skb)) {
37 + if (iph->protocol == IPPROTO_UDP)
38 + uh = skb_header_pointer(skb,
39 + skb_network_offset(skb) +
40 + (iph->ihl << 2),
41 + sizeof(_uh), &_uh);
42 +
43 + if (!uh) {
41 44 __entry->sport = 0;
42 45 __entry->dport = 0;
43 46 __entry->ulen = 0;
modified include/uapi/drm/amdgpu_drm.h
@@ -1512,6 +1512,7 @@ struct drm_amdgpu_info_device {
1512 1512 __u64 high_va_max;
1513 1513 /* gfx10 pa_sc_tile_steering_override */
1514 1514 __u32 pa_sc_tile_steering_override;
1515 + __u32 pad;
1515 1516 /* disabled TCCs */
1516 1517 __u64 tcc_disabled_mask;
1517 1518 __u64 min_engine_clock;
@@ -1536,7 +1537,6 @@ struct drm_amdgpu_info_device {
1536 1537 __u32 csa_alignment;
1537 1538 /* Userq IP mask (1 << AMDGPU_HW_IP_*) */
1538 1539 __u32 userq_ip_mask;
1539 - __u32 pad;
1540 1540 };
1541 1541
1542 1542 struct drm_amdgpu_info_hw_ip {
modified include/uapi/linux/magic.h
@@ -8,6 +8,7 @@
8 8 #define AUTOFS_SUPER_MAGIC 0x0187
9 9 #define CEPH_SUPER_MAGIC 0x00c36400
10 10 #define CODA_SUPER_MAGIC 0x73757245
11 + #define CONFIGFS_MAGIC 0x62656570 /* some random number */
11 12 #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
12 13 #define CRAMFS_MAGIC_WEND 0x453dcd28 /* magic number with the wrong endianess */
13 14 #define DEBUGFS_MAGIC 0x64626720
modified init/initramfs_test.c
@@ -514,7 +514,7 @@ static void __init initramfs_test_hdr_hex(struct kunit *test)
514 514 char fdata[] = "this file data will not be unpacked";
515 515 struct initramfs_test_bufs {
516 516 char cpio_src[(CPIO_HDRLEN + PATH_MAX + 3 + sizeof(fdata)) * 2];
517 - } *tbufs = kzalloc(sizeof(struct initramfs_test_bufs), GFP_KERNEL);
517 + } *tbufs = kzalloc_obj(struct initramfs_test_bufs);
518 518 struct initramfs_test_cpio c[] = { {
519 519 .magic = "070701",
520 520 .ino = 1,
modified io_uring/napi.c
@@ -58,7 +58,7 @@ int __io_napi_add_id(struct io_ring_ctx *ctx, unsigned int napi_id,
58 58 }
59 59 }
60 60
61 - e = kmalloc(sizeof(*e), GFP_NOWAIT);
61 + e = kmalloc_obj(*e, GFP_NOWAIT);
62 62 if (!e)
63 63 return -ENOMEM;
64 64
modified io_uring/zcrx.c
@@ -483,8 +483,8 @@ static int io_zcrx_append_area(struct io_zcrx_ifq *ifq,
483 483 old_areas = ifq->areas;
484 484 old_nr = ifq->nr_areas;
485 485
486 - areas = kmalloc_array(old_nr + 1, sizeof(areas[0]),
487 - GFP_KERNEL_ACCOUNT | __GFP_ZERO);
486 + areas = kmalloc_objs(areas[0], old_nr + 1,
487 + GFP_KERNEL_ACCOUNT | __GFP_ZERO);
488 488 if (!areas)
489 489 return -ENOMEM;
490 490 if (old_areas)
modified kernel/bpf/arraymap.c
@@ -436,7 +436,7 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
436 436 void __percpu *pptr;
437 437 void *ptr, *val;
438 438 u32 size;
439 - int cpu;
439 + int cpu, off = 0;
440 440
441 441 if (unlikely((map_flags & BPF_F_LOCK) || (u32)map_flags > BPF_F_ALL_CPUS))
442 442 /* unknown flags */
@@ -468,9 +468,10 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
468 468 }
469 469 for_each_possible_cpu(cpu) {
470 470 ptr = per_cpu_ptr(pptr, cpu);
471 - val = (map_flags & BPF_F_ALL_CPUS) ? value : value + size * cpu;
471 + val = (map_flags & BPF_F_ALL_CPUS) ? value : value + off;
472 472 copy_map_value(map, ptr, val);
473 473 bpf_obj_cancel_fields(map, ptr);
474 + off += size;
474 475 }
475 476 unlock:
476 477 rcu_read_unlock();
modified kernel/bpf/backtrack.c
@@ -520,37 +520,34 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
520 520 return -EFAULT;
521 521 }
522 522 } else if (opcode == BPF_EXIT) {
523 - bool r0_precise;
523 + bool from_subprog_call, r0_precise;
524 +
525 + /* BPF_EXIT in subprog or callback always returns
526 + * right after the call instruction, so by checking
527 + * whether the instruction at subseq_idx-1 is subprog
528 + * call or not we can distinguish actual exit from
529 + * *subprog* from exit from *callback*. In the former
530 + * case, we need to propagate r0 precision, if
531 + * necessary. In the former we never do that.
532 + */
533 + from_subprog_call = subseq_idx - 1 >= 0 &&
534 + bpf_pseudo_call(&env->prog->insnsi[subseq_idx - 1]);
535 +
536 + r0_precise = from_subprog_call && bt_is_reg_set(bt, BPF_REG_0);
524 537
525 538 /* Backtracking to a nested function call, 'idx' is a part of
526 539 * the inner frame 'subseq_idx' is a part of the outer frame.
527 540 * In case of a regular function call, instructions giving
528 541 * precision to registers R1-R5 should have been found already.
529 - * In case of a callback, it is ok to have R1-R5 marked for
530 - * backtracking, as these registers are set by the function
531 - * invoking callback.
542 + * In case of a callback from bpf_loop(), R{1,4} in the calling
543 + * frame would be set as precise and that is correct.
532 544 */
533 - if (subseq_idx >= 0 && bpf_calls_callback(env, subseq_idx))
534 - for (i = BPF_REG_1; i <= BPF_REG_5; i++)
535 - bt_clear_reg(bt, i);
536 - if (bt_reg_mask(bt) & BPF_REGMASK_ARGS) {
545 + if (from_subprog_call && (bt_reg_mask(bt) & BPF_REGMASK_ARGS)) {
537 546 verifier_bug(env, "backtracking exit unexpected regs %x",
538 547 bt_reg_mask(bt));
539 548 return -EFAULT;
540 549 }
541 550
542 - /* BPF_EXIT in subprog or callback always returns
543 - * right after the call instruction, so by checking
544 - * whether the instruction at subseq_idx-1 is subprog
545 - * call or not we can distinguish actual exit from
546 - * *subprog* from exit from *callback*. In the former
547 - * case, we need to propagate r0 precision, if
548 - * necessary. In the former we never do that.
549 - */
550 - r0_precise = subseq_idx - 1 >= 0 &&
551 - bpf_pseudo_call(&env->prog->insnsi[subseq_idx - 1]) &&
552 - bt_is_reg_set(bt, BPF_REG_0);
553 -
554 551 bt_clear_reg(bt, BPF_REG_0);
555 552 if (bt_subprog_enter(bt))
556 553 return -EFAULT;
@@ -582,16 +579,29 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,
582 579 */
583 580 }
584 581 } else if (class == BPF_LD) {
585 - if (!bt_is_reg_set(bt, dreg))
586 - return 0;
587 - bt_clear_reg(bt, dreg);
588 582 /* It's ld_imm64 or ld_abs or ld_ind.
589 583 * For ld_imm64 no further tracking of precision
590 584 * into parent is necessary
591 585 */
592 - if (mode == BPF_IND || mode == BPF_ABS)
593 - /* to be analyzed */
594 - return -ENOTSUPP;
586 + if (mode == BPF_IMM) {
587 + bt_clear_reg(bt, dreg);
588 + return 0;
589 + }
590 + /*
591 + * BPF_{IND,ABS} are modelled as two branches:
592 + * - fallthrough;
593 + * - implicit subprogram exit.
594 + * It is necessary to switch current frame if
595 + * implicit subprogram exit branch is backtracked.
596 + */
597 + if (mode == BPF_IND || mode == BPF_ABS) {
598 + if (bt_is_reg_set(bt, dreg))
599 + return -ENOTSUPP;
600 + if (subseq_idx != idx + 1)
601 + if (bt_subprog_enter(bt))
602 + return -EFAULT;
603 + return 0;
604 + }
595 605 }
596 606 /* Propagate precision marks to linked registers, to account for
597 607 * registers marked as precise in this function.
modified kernel/bpf/bpf_iter.c
@@ -754,7 +754,7 @@ const struct bpf_func_proto bpf_loop_proto = {
754 754 .func = bpf_loop,
755 755 .gpl_only = false,
756 756 .ret_type = RET_INTEGER,
757 - .arg1_type = ARG_ANYTHING,
757 + .arg1_type = ARG_SCALAR,
758 758 .arg2_type = ARG_PTR_TO_FUNC,
759 759 .arg3_type = ARG_PTR_TO_STACK_OR_NULL,
760 760 .arg4_type = ARG_ANYTHING,
modified kernel/bpf/btf.c
@@ -2911,14 +2911,29 @@ static void btf_modifier_show(const struct btf *btf,
2911 2911 else
2912 2912 t = btf_type_skip_modifiers(btf, type_id, NULL);
2913 2913
2914 - btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
2914 + /*
2915 + * A modifier can resolve to void, which has no show op; print a
2916 + * placeholder rather than dereferencing NULL.
2917 + */
2918 + if (!btf_type_ops(t))
2919 + btf_df_show(btf, t, type_id, data, bits_offset, show);
2920 + else
2921 + btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
2915 2922 }
2916 2923
2917 2924 static void btf_var_show(const struct btf *btf, const struct btf_type *t,
2918 2925 u32 type_id, void *data, u8 bits_offset,
2919 2926 struct btf_show *show)
2920 2927 {
2921 - t = btf_type_id_resolve(btf, &type_id);
2928 + /*
2929 + * btf_type_id_resolve() dereferences btf->resolved_ids, which is NULL
2930 + * for a base BTF (e.g. the vmlinux BTF that bpf_snprintf_btf() uses).
2931 + * Resolve the var's type directly in that case.
2932 + */
2933 + if (btf->resolved_ids)
2934 + t = btf_type_id_resolve(btf, &type_id);
2935 + else
2936 + t = btf_type_skip_modifiers(btf, t->type, &type_id);
2922 2937
2923 2938 btf_type_ops(t)->show(btf, t, type_id, data, bits_offset, show);
2924 2939 }
@@ -6657,6 +6672,10 @@ struct bpf_raw_tp_null_args {
6657 6672 static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
6658 6673 /* sched */
6659 6674 { "sched_pi_setprio", 0x10 },
6675 + /*
6676 + * do_wait() passes NULL for wait4(-1) and waitid(P_ALL).
6677 + */
6678 + { "sched_process_wait", 0x1 },
6660 6679 /* ... from sched_numa_pair_template event class */
6661 6680 { "sched_stick_numa", 0x100 },
6662 6681 { "sched_swap_numa", 0x100 },
@@ -6717,6 +6736,9 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
6717 6736 { "rxrpc_resend", 0x10 },
6718 6737 { "rxrpc_tq", 0x10 },
6719 6738 { "rxrpc_client", 0x1 },
6739 + /* signal */
6740 + { "signal_generate", 0x20 },
6741 + { "signal_deliver", 0x20 },
6720 6742 /* skb */
6721 6743 {"kfree_skb", 0x1000},
6722 6744 /* sunrpc */
@@ -8727,6 +8749,7 @@ BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int
8727 8749 const struct bpf_func_proto bpf_btf_find_by_name_kind_proto = {
8728 8750 .func = bpf_btf_find_by_name_kind,
8729 8751 .gpl_only = false,
8752 + .might_sleep = true,
8730 8753 .ret_type = RET_INTEGER,
8731 8754 .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
8732 8755 .arg2_type = ARG_MEM_SIZE,
modified kernel/bpf/cfg.c
@@ -125,6 +125,7 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
125 125 /* mark branch target for state pruning */
126 126 mark_prune_point(env, w);
127 127 mark_jmp_point(env, w);
128 + mark_jump_target(env, w);
128 129 }
129 130
130 131 if (insn_state[w] == 0) {
@@ -403,6 +404,7 @@ static int visit_gotox_insn(int t, struct bpf_verifier_env *env)
403 404 }
404 405
405 406 mark_jmp_point(env, w);
407 + mark_jump_target(env, w);
406 408
407 409 /* EXPLORED || DISCOVERED */
408 410 if (insn_state[w])
@@ -564,6 +566,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)
564 566
565 567 mark_prune_point(env, t + off + 1);
566 568 mark_jmp_point(env, t + off + 1);
569 + mark_jump_target(env, t + off + 1);
567 570
568 571 return ret;
569 572
modified kernel/bpf/core.c
@@ -1128,11 +1128,6 @@ void *bpf_jit_alloc_exec(unsigned long size)
1128 1128 return execmem_alloc(EXECMEM_BPF, size);
1129 1129 }
1130 1130
1131 - void *bpf_jit_alloc_exec_rw(unsigned long size)
1132 - {
1133 - return execmem_alloc_rw(EXECMEM_BPF, size);
1134 - }
1135 -
1136 1131 void bpf_jit_free_exec(void *addr)
1137 1132 {
1138 1133 execmem_free(addr);
modified kernel/bpf/diagnostics.c
@@ -266,7 +266,7 @@ static char *diag_fmt_alloc(struct bpf_verifier_env *env, size_t size)
266 266 }
267 267
268 268 capacity = max_t(size_t, BPF_DIAG_FMT_CHUNK_SIZE, size);
269 - chunk = kmalloc(struct_size(chunk, data, capacity), GFP_KERNEL_ACCOUNT);
269 + chunk = kmalloc_flex(*chunk, data, capacity, GFP_KERNEL_ACCOUNT);
270 270 if (!chunk)
271 271 return NULL;
272 272
modified kernel/bpf/disasm.c
@@ -7,6 +7,9 @@
7 7
8 8 #include "disasm.h"
9 9
10 + /* Only defined by the non-UAPI linux/filter.h, which this file cannot use. */
11 + #define BPF_PROBE_ATOMIC 0xe0
12 +
10 13 #define __BPF_FUNC_STR_FN(x) [BPF_FUNC_ ## x] = __stringify(bpf_ ## x)
11 14 static const char * const func_id_str[] = {
12 15 __BPF_FUNC_MAPPER(__BPF_FUNC_STR_FN)
@@ -226,57 +229,57 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
226 229 insn->imm);
227 230 }
228 231 } else if (class == BPF_STX) {
232 + const char *probe_pfx = BPF_MODE(insn->code) == BPF_PROBE_ATOMIC ? "probe " : "";
233 + bool atomic = BPF_MODE(insn->code) == BPF_ATOMIC ||
234 + BPF_MODE(insn->code) == BPF_PROBE_ATOMIC;
235 +
229 236 if (BPF_MODE(insn->code) == BPF_MEM)
230 237 verbose(cbs->private_data, "(%02x) *(%s *)(r%d %+d) = r%d",
231 238 insn->code,
232 239 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
233 240 insn->dst_reg,
234 241 insn->off, insn->src_reg);
235 - else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
242 + else if (atomic &&
236 243 (insn->imm == BPF_ADD || insn->imm == BPF_AND ||
237 244 insn->imm == BPF_OR || insn->imm == BPF_XOR)) {
238 - verbose(cbs->private_data, "(%02x) lock *(%s *)(r%d %+d) %s r%d",
239 - insn->code,
245 + verbose(cbs->private_data, "(%02x) %slock *(%s *)(r%d %+d) %s r%d",
246 + insn->code, probe_pfx,
240 247 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
241 248 insn->dst_reg, insn->off,
242 249 bpf_alu_string[BPF_OP(insn->imm) >> 4],
243 250 insn->src_reg);
244 - } else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
251 + } else if (atomic &&
245 252 (insn->imm == (BPF_ADD | BPF_FETCH) ||
246 253 insn->imm == (BPF_AND | BPF_FETCH) ||
247 254 insn->imm == (BPF_OR | BPF_FETCH) ||
248 255 insn->imm == (BPF_XOR | BPF_FETCH))) {
249 - verbose(cbs->private_data, "(%02x) r%d = atomic%s_fetch_%s((%s *)(r%d %+d), r%d)",
250 - insn->code, insn->src_reg,
256 + verbose(cbs->private_data, "(%02x) %sr%d = atomic%s_fetch_%s((%s *)(r%d %+d), r%d)",
257 + insn->code, probe_pfx, insn->src_reg,
251 258 BPF_SIZE(insn->code) == BPF_DW ? "64" : "",
252 259 bpf_atomic_alu_string[BPF_OP(insn->imm) >> 4],
253 260 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
254 261 insn->dst_reg, insn->off, insn->src_reg);
255 - } else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
256 - insn->imm == BPF_CMPXCHG) {
257 - verbose(cbs->private_data, "(%02x) r0 = atomic%s_cmpxchg((%s *)(r%d %+d), r0, r%d)",
258 - insn->code,
262 + } else if (atomic && insn->imm == BPF_CMPXCHG) {
263 + verbose(cbs->private_data, "(%02x) %sr0 = atomic%s_cmpxchg((%s *)(r%d %+d), r0, r%d)",
264 + insn->code, probe_pfx,
259 265 BPF_SIZE(insn->code) == BPF_DW ? "64" : "",
260 266 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
261 267 insn->dst_reg, insn->off,
262 268 insn->src_reg);
263 - } else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
264 - insn->imm == BPF_XCHG) {
265 - verbose(cbs->private_data, "(%02x) r%d = atomic%s_xchg((%s *)(r%d %+d), r%d)",
266 - insn->code, insn->src_reg,
269 + } else if (atomic && insn->imm == BPF_XCHG) {
270 + verbose(cbs->private_data, "(%02x) %sr%d = atomic%s_xchg((%s *)(r%d %+d), r%d)",
271 + insn->code, probe_pfx, insn->src_reg,
267 272 BPF_SIZE(insn->code) == BPF_DW ? "64" : "",
268 273 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
269 274 insn->dst_reg, insn->off, insn->src_reg);
270 - } else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
271 - insn->imm == BPF_LOAD_ACQ) {
272 - verbose(cbs->private_data, "(%02x) r%d = load_acquire((%s *)(r%d %+d))",
273 - insn->code, insn->dst_reg,
275 + } else if (atomic && insn->imm == BPF_LOAD_ACQ) {
276 + verbose(cbs->private_data, "(%02x) %sr%d = load_acquire((%s *)(r%d %+d))",
277 + insn->code, probe_pfx, insn->dst_reg,
274 278 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
275 279 insn->src_reg, insn->off);
276 - } else if (BPF_MODE(insn->code) == BPF_ATOMIC &&
277 - insn->imm == BPF_STORE_REL) {
278 - verbose(cbs->private_data, "(%02x) store_release((%s *)(r%d %+d), r%d)",
279 - insn->code,
280 + } else if (atomic && insn->imm == BPF_STORE_REL) {
281 + verbose(cbs->private_data, "(%02x) %sstore_release((%s *)(r%d %+d), r%d)",
282 + insn->code, probe_pfx,
280 283 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
281 284 insn->dst_reg, insn->off, insn->src_reg);
282 285 } else {
@@ -295,7 +298,8 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
295 298 verbose(cbs->private_data, "BUG_st_%02x", insn->code);
296 299 }
297 300 } else if (class == BPF_LDX) {
298 - if (BPF_MODE(insn->code) != BPF_MEM && BPF_MODE(insn->code) != BPF_MEMSX) {
301 + if ((BPF_MODE(insn->code) != BPF_MEM && BPF_MODE(insn->code) != BPF_MEMSX) ||
302 + (BPF_MODE(insn->code) == BPF_MEMSX && BPF_SIZE(insn->code) == BPF_DW)) {
299 303 verbose(cbs->private_data, "BUG_ldx_%02x", insn->code);
300 304 return;
301 305 }
modified kernel/bpf/fixups.c
@@ -13,10 +13,15 @@
13 13
14 14 #define verbose(env, fmt, args...) bpf_verifier_log_write(env, fmt, ##args)
15 15
16 + /*
17 + * Matches BPF_PROBE_ATOMIC too: bpf_convert_ctx_accesses() rewrites arena
18 + * atomics before bpf_opt_subreg_zext_lo32_rnd_hi32() runs.
19 + */
16 20 static bool is_cmpxchg_insn(const struct bpf_insn *insn)
17 21 {
18 22 return BPF_CLASS(insn->code) == BPF_STX &&
19 - BPF_MODE(insn->code) == BPF_ATOMIC &&
23 + (BPF_MODE(insn->code) == BPF_ATOMIC ||
24 + BPF_MODE(insn->code) == BPF_PROBE_ATOMIC) &&
20 25 insn->imm == BPF_CMPXCHG;
21 26 }
22 27
modified kernel/bpf/hashtab.c
@@ -511,7 +511,7 @@ static int bpf_ma_set_dtor(struct bpf_map *map, struct bpf_mem_alloc *ma,
511 511 if (IS_ERR_OR_NULL(map->record))
512 512 return 0;
513 513
514 - hrec = kzalloc(sizeof(*hrec), GFP_KERNEL);
514 + hrec = kzalloc_obj(*hrec);
515 515 if (!hrec)
516 516 return -ENOMEM;
517 517 hrec->key_size = map->key_size;
@@ -530,6 +530,9 @@ static int htab_map_check_btf(struct bpf_map *map, const struct btf *btf,
530 530 {
531 531 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
532 532
533 + if (btf_type_is_void(key_type))
534 + return -EINVAL;
535 +
533 536 if (htab_is_prealloc(htab))
534 537 return 0;
535 538 /*
@@ -1025,7 +1028,7 @@ static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,
1025 1028 } else {
1026 1029 u32 size = round_up(htab->map.value_size, 8);
1027 1030 void *val;
1028 - int cpu;
1031 + int cpu, off = 0;
1029 1032
1030 1033 if (map_flags & BPF_F_CPU) {
1031 1034 cpu = map_flags >> 32;
@@ -1037,9 +1040,10 @@ static void pcpu_copy_value(struct bpf_htab *htab, void __percpu *pptr,
1037 1040
1038 1041 for_each_possible_cpu(cpu) {
1039 1042 ptr = per_cpu_ptr(pptr, cpu);
1040 - val = (map_flags & BPF_F_ALL_CPUS) ? value : value + size * cpu;
1043 + val = (map_flags & BPF_F_ALL_CPUS) ? value : value + off;
1041 1044 copy_map_value(&htab->map, ptr, val);
1042 1045 bpf_obj_cancel_fields(&htab->map, ptr);
1046 + off += size;
1043 1047 }
1044 1048 }
1045 1049 }
@@ -2864,16 +2868,6 @@ static int rhtab_map_alloc_check(union bpf_attr *attr)
2864 2868 return htab_map_alloc_check(attr);
2865 2869 }
2866 2870
2867 - static void rhtab_check_and_free_fields(struct bpf_rhtab *rhtab,
2868 - struct rhtab_elem *elem)
2869 - {
2870 - if (IS_ERR_OR_NULL(rhtab->map.record))
2871 - return;
2872 -
2873 - bpf_obj_free_fields(rhtab->map.record,
2874 - rhtab_elem_value(elem, rhtab->map.key_size));
2875 - }
2876 -
2877 2871 static void rhtab_mem_dtor(void *obj, void *ctx)
2878 2872 {
2879 2873 struct htab_btf_record *hrec = ctx;
@@ -2963,8 +2957,8 @@ static int rhtab_delete_elem(struct bpf_rhtab *rhtab, struct rhtab_elem *elem, v
2963 2957 rhtab_read_elem_value(&rhtab->map, copy, elem, flags);
2964 2958 check_and_init_map_value(&rhtab->map, copy);
2965 2959 }
2966 - /* Release internal structs: kptr, bpf_timer, task_work, wq */
2967 - rhtab_check_and_free_fields(rhtab, elem);
2960 + bpf_obj_cancel_fields(&rhtab->map,
2961 + rhtab_elem_value(elem, rhtab->map.key_size));
2968 2962 bpf_mem_cache_free_rcu(&rhtab->ma, elem);
2969 2963 return 0;
2970 2964 }
@@ -3005,7 +2999,6 @@ static int rhtab_map_lookup_and_delete_elem(struct bpf_map *map, void *key, void
3005 2999 static long rhtab_map_update_existing(struct bpf_map *map, struct rhtab_elem *elem, void *value,
3006 3000 u64 map_flags)
3007 3001 {
3008 - struct bpf_rhtab *rhtab = container_of(map, struct bpf_rhtab, map);
3009 3002 void *old_val = rhtab_elem_value(elem, map->key_size);
3010 3003
3011 3004 if (map_flags & BPF_NOEXIST)
@@ -3025,7 +3018,7 @@ static long rhtab_map_update_existing(struct bpf_map *map, struct rhtab_elem *el
3025 3018 * kptrs/etc. still sit in the slot. Cancel them after the copy
3026 3019 * to match arraymap's update semantics.
3027 3020 */
3028 - rhtab_check_and_free_fields(rhtab, elem);
3021 + bpf_obj_cancel_fields(map, old_val);
3029 3022 return 0;
3030 3023 }
3031 3024
@@ -3066,7 +3059,6 @@ static long rhtab_map_update_elem(struct bpf_map *map, void *key, void *value, u
3066 3059
3067 3060 memcpy(elem->data, key, map->key_size);
3068 3061 copy_map_value(map, rhtab_elem_value(elem, map->key_size), value);
3069 - check_and_init_map_value(map, rhtab_elem_value(elem, map->key_size));
3070 3062
3071 3063 /* Prevent deadlock for NMI programs attempting to take bucket lock */
3072 3064 bpf_disable_instrumentation();
@@ -3110,6 +3102,9 @@ static int rhtab_map_check_btf(struct bpf_map *map, const struct btf *btf,
3110 3102 {
3111 3103 struct bpf_rhtab *rhtab = container_of(map, struct bpf_rhtab, map);
3112 3104
3105 + if (btf_type_is_void(key_type))
3106 + return -EINVAL;
3107 +
3113 3108 return bpf_ma_set_dtor(map, &rhtab->ma, rhtab_mem_dtor);
3114 3109 }
3115 3110
modified kernel/bpf/liveness.c
@@ -85,7 +85,7 @@ static struct func_instance *call_instance(struct bpf_verifier_env *env,
85 85 if (f)
86 86 return f;
87 87
88 - f = kvzalloc(sizeof(*f), GFP_KERNEL_ACCOUNT);
88 + f = kvzalloc_obj(*f, GFP_KERNEL_ACCOUNT);
89 89 if (!f)
90 90 return ERR_PTR(-ENOMEM);
91 91 f->callsite = lookup_key;
modified kernel/bpf/local_storage.c
@@ -220,7 +220,7 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *key,
220 220 struct bpf_cgroup_storage *storage;
221 221 void *val;
222 222 u32 size;
223 - int cpu;
223 + int cpu, off = 0;
224 224
225 225 if ((u32)map_flags & ~(BPF_ANY | BPF_EXIST | BPF_F_CPU | BPF_F_ALL_CPUS))
226 226 return -EINVAL;
@@ -245,8 +245,9 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *_map, void *key,
245 245 }
246 246 size = round_up(_map->value_size, 8);
247 247 for_each_possible_cpu(cpu) {
248 - val = (map_flags & BPF_F_ALL_CPUS) ? value : value + size * cpu;
248 + val = (map_flags & BPF_F_ALL_CPUS) ? value : value + off;
249 249 copy_map_value(_map, per_cpu_ptr(storage->percpu_buf, cpu), val);
250 + off += size;
250 251 }
251 252 unlock:
252 253 rcu_read_unlock();
modified kernel/bpf/log.c
@@ -862,7 +862,7 @@ struct bpf_verifier_log *bpf_log_attr_create_vlog(struct bpf_log_attr *attr_log,
862 862 if (!size)
863 863 return NULL;
864 864
865 - log = kzalloc_obj(*log, GFP_KERNEL);
865 + log = kzalloc_obj(*log);
866 866 if (!log)
867 867 return ERR_PTR(-ENOMEM);
868 868
modified kernel/bpf/percpu_freelist.c
@@ -17,6 +17,8 @@ int pcpu_freelist_init(struct pcpu_freelist *s)
17 17 raw_res_spin_lock_init(&head->lock);
18 18 head->first = NULL;
19 19 }
20 + raw_res_spin_lock_init(&s->extralist.lock);
21 + s->extralist.first = NULL;
20 22 return 0;
21 23 }
22 24
@@ -46,22 +48,28 @@ void __pcpu_freelist_push(struct pcpu_freelist *s,
46 48 struct pcpu_freelist_node *node)
47 49 {
48 50 struct pcpu_freelist_head *head;
49 - int cpu;
51 + int cpu, this_cpu;
50 52
51 53 if (___pcpu_freelist_push(this_cpu_ptr(s->freelist), node))
52 54 return;
53 55
56 + this_cpu = raw_smp_processor_id();
54 57 while (true) {
55 - for_each_cpu_wrap(cpu, cpu_possible_mask, raw_smp_processor_id()) {
56 - if (cpu == raw_smp_processor_id())
58 + for_each_cpu_wrap(cpu, cpu_possible_mask, this_cpu) {
59 + if (cpu == this_cpu)
57 60 continue;
61 +
58 62 head = per_cpu_ptr(s->freelist, cpu);
59 - if (raw_res_spin_lock(&head->lock))
60 - continue;
61 - pcpu_freelist_push_node(head, node);
62 - raw_res_spin_unlock(&head->lock);
63 - return;
63 + if (___pcpu_freelist_push(head, node))
64 + return;
64 65 }
66 +
67 + /*
68 + * Push cannot fail. Use the extra list when none of the
69 + * per-CPU freelists can accept the node.
70 + */
71 + if (___pcpu_freelist_push(&s->extralist, node))
72 + return;
65 73 }
66 74 }
67 75
@@ -117,6 +125,17 @@ static struct pcpu_freelist_node *___pcpu_freelist_pop(struct pcpu_freelist *s)
117 125 }
118 126 raw_res_spin_unlock(&head->lock);
119 127 }
128 +
129 + /* Per-CPU lists are empty or unavailable, try the extra list. */
130 + head = &s->extralist;
131 + if (!READ_ONCE(head->first))
132 + return NULL;
133 + if (raw_res_spin_lock(&head->lock))
134 + return NULL;
135 + node = head->first;
136 + if (node)
137 + WRITE_ONCE(head->first, node->next);
138 + raw_res_spin_unlock(&head->lock);
120 139 return node;
121 140 }
122 141
modified kernel/bpf/percpu_freelist.h
@@ -14,6 +14,7 @@ struct pcpu_freelist_head {
14 14
15 15 struct pcpu_freelist {
16 16 struct pcpu_freelist_head __percpu *freelist;
17 + struct pcpu_freelist_head extralist;
17 18 };
18 19
19 20 struct pcpu_freelist_node {
modified kernel/bpf/stackmap.c
@@ -875,6 +875,7 @@ BPF_CALL_4(bpf_get_stack_sleepable, struct pt_regs *, regs, void *, buf, u32, si
875 875 const struct bpf_func_proto bpf_get_stack_sleepable_proto = {
876 876 .func = bpf_get_stack_sleepable,
877 877 .gpl_only = true,
878 + .might_sleep = true,
878 879 .ret_type = RET_INTEGER,
879 880 .arg1_type = ARG_PTR_TO_CTX,
880 881 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
@@ -928,6 +929,7 @@ BPF_CALL_4(bpf_get_task_stack_sleepable, struct task_struct *, task, void *, buf
928 929 const struct bpf_func_proto bpf_get_task_stack_sleepable_proto = {
929 930 .func = bpf_get_task_stack_sleepable,
930 931 .gpl_only = false,
932 + .might_sleep = true,
931 933 .ret_type = RET_INTEGER,
932 934 .arg1_type = ARG_PTR_TO_BTF_ID,
933 935 .arg1_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
modified kernel/bpf/states.c
@@ -445,22 +445,19 @@ static void __clean_func_state(struct bpf_verifier_env *env,
445 445 struct bpf_reg_state *spill = &st->stack[i].spilled_ptr;
446 446
447 447 if (lo_live && stype == STACK_SPILL) {
448 - u8 val = STACK_MISC;
449 -
450 448 if (spill->type != SCALAR_VALUE)
451 449 continue;
452 -
453 450 /*
454 - * 8 byte spill of scalar 0 where half slot is dead
455 - * should become STACK_ZERO in lo 4 bytes.
451 + * Can't replace with STACK_ZERO, because
452 + * that requires bpf_mark_chain_precision().
456 453 */
457 454 if (bpf_register_is_null(spill))
458 - val = STACK_ZERO;
455 + continue;
459 456 for (j = 0; j < 4; j++) {
460 457 u8 *t = &st->stack[i].slot_type[j];
461 458
462 459 if (*t == STACK_SPILL)
463 - *t = val;
460 + *t = STACK_MISC;
464 461 }
465 462 }
466 463 bpf_mark_reg_not_init(env, spill);
modified kernel/bpf/syscall.c
@@ -6568,6 +6568,7 @@ EXPORT_SYMBOL_NS(kern_sys_bpf, "BPF_INTERNAL");
6568 6568 static const struct bpf_func_proto bpf_sys_bpf_proto = {
6569 6569 .func = bpf_sys_bpf,
6570 6570 .gpl_only = false,
6571 + .might_sleep = true,
6571 6572 .ret_type = RET_INTEGER,
6572 6573 .arg1_type = ARG_ANYTHING,
6573 6574 .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY,
@@ -6593,6 +6594,7 @@ BPF_CALL_1(bpf_sys_close, u32, fd)
6593 6594 static const struct bpf_func_proto bpf_sys_close_proto = {
6594 6595 .func = bpf_sys_close,
6595 6596 .gpl_only = false,
6597 + .might_sleep = true,
6596 6598 .ret_type = RET_INTEGER,
6597 6599 .arg1_type = ARG_ANYTHING,
6598 6600 };
modified kernel/bpf/verifier.c
@@ -352,9 +352,18 @@ static bool reg_not_null(struct bpf_verifier_env *env, const struct bpf_reg_stat
352 352 if (type_may_be_null(type))
353 353 return false;
354 354
355 + /*
356 + * The types below guarantee a non-NULL base, an unbounded offset can
357 + * still wrap base + offset to zero.
358 + */
359 + if (reg_smin(reg) <= -BPF_MAX_VAR_OFF || reg_smax(reg) >= BPF_MAX_VAR_OFF)
360 + return false;
361 +
355 362 type = base_type(type);
356 363 return type == PTR_TO_SOCKET ||
357 364 type == PTR_TO_TCP_SOCK ||
365 + type == PTR_TO_XDP_SOCK ||
366 + type == PTR_TO_BUF ||
358 367 type == PTR_TO_MAP_VALUE ||
359 368 type == PTR_TO_MAP_KEY ||
360 369 type == PTR_TO_SOCK_COMMON ||
@@ -4237,6 +4246,15 @@ static int mark_stack_arg_precision(struct bpf_verifier_env *env, int arg_idx)
4237 4246 return mark_chain_precision_batch(env, env->cur_state);
4238 4247 }
4239 4248
4249 + static int mark_arg_precision(struct bpf_verifier_env *env, argno_t argno)
4250 + {
4251 + int regno = reg_from_argno(argno);
4252 +
4253 + if (regno >= 0)
4254 + return mark_chain_precision(env, regno);
4255 + return mark_stack_arg_precision(env, arg_idx_from_argno(argno));
4256 + }
4257 +
4240 4258 static int check_outgoing_stack_args(struct bpf_verifier_env *env, struct bpf_func_state *caller,
4241 4259 int nargs, const char *callee_name, const struct btf *btf,
4242 4260 const struct btf_param *args)
@@ -4486,6 +4504,13 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
4486 4504 if (type_flag(reg->type) & ~perm_flags)
4487 4505 goto bad_type;
4488 4506
4507 + /*
4508 + * A BPF_KPTR_PERCPU field is read back as MEM_PERCPU, so the value
4509 + * stored in it must carry the same flag.
4510 + */
4511 + if ((kptr_field->type == BPF_KPTR_PERCPU) != !!(reg->type & MEM_PERCPU))
4512 + goto bad_type;
4513 +
4489 4514 /* We need to verify reg->type and reg->btf, before accessing reg->btf */
4490 4515 reg_name = btf_type_name(reg->btf, reg->btf_id);
4491 4516
@@ -4692,8 +4717,15 @@ static int check_map_kptr_access(struct bpf_verifier_env *env,
4692 4717 return ret;
4693 4718 } else if (class == BPF_STX) {
4694 4719 val_reg = reg_state(env, value_regno);
4695 - if (!bpf_register_is_null(val_reg) &&
4696 - map_kptr_match_type(env, kptr_field, val_reg, value_regno))
4720 + if (bpf_register_is_null(val_reg)) {
4721 + /*
4722 + * This store is valid only because the scalar is known to be
4723 + * zero. Mark it precise so another scalar cannot be pruned
4724 + * against this state.
4725 + */
4726 + return mark_chain_precision(env, value_regno);
4727 + }
4728 + if (map_kptr_match_type(env, kptr_field, val_reg, value_regno))
4697 4729 return -EACCES;
4698 4730 } else if (class == BPF_ST) {
4699 4731 if (insn->imm) {
@@ -5300,6 +5332,15 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx,
5300 5332 if (!priv_stack_supported)
5301 5333 subprog[idx].priv_stack_mode = NO_PRIV_STACK;
5302 5334 process_func:
5335 + if (subprog[idx].has_ld_abs) {
5336 + for (tmp = idx; tmp >= 0; tmp = dinfo[tmp].caller) {
5337 + if (subprog[tmp].is_cb) {
5338 + verbose(env, "cannot use BPF_LD_[ABS|IND] within callback\n");
5339 + return -EINVAL;
5340 + }
5341 + }
5342 + }
5343 +
5303 5344 /* protect against potential stack overflow that might happen when
5304 5345 * bpf2bpf calls get combined with tailcalls. Limit the caller's stack
5305 5346 * depth for such case down to 256 so that the worst case scenario
@@ -5483,7 +5524,7 @@ static int check_max_stack_depth(struct bpf_verifier_env *env)
5483 5524 bool priv_stack_supported;
5484 5525 int ret;
5485 5526
5486 - dinfo = kvcalloc(env->subprog_cnt, sizeof(*dinfo), GFP_KERNEL_ACCOUNT);
5527 + dinfo = kvzalloc_objs(*dinfo, env->subprog_cnt, GFP_KERNEL_ACCOUNT);
5487 5528 if (!dinfo)
5488 5529 return -ENOMEM;
5489 5530
@@ -6020,7 +6061,13 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
6020 6061 return -EACCES;
6021 6062 }
6022 6063
6023 - if (type_is_alloc(reg->type) && !type_is_non_owning_ref(reg->type) &&
6064 + /*
6065 + * A fault-prone allocated object may still be read through a
6066 + * BPF_PROBE_MEM load after its lifetime protection ends. Writes
6067 + * through such pointers were rejected above.
6068 + */
6069 + if (type_is_alloc(reg->type) && !bpf_may_fault_on_deref(reg->type) &&
6070 + !type_is_non_owning_ref(reg->type) &&
6024 6071 !(reg->type & MEM_RCU) && !reg_is_referenced(env, reg)) {
6025 6072 verifier_bug(env, "allocated object must have a referenced id");
6026 6073 return -EFAULT;
@@ -7113,14 +7160,8 @@ static int check_mem_size_reg(struct bpf_verifier_env *env,
7113 7160 if (err && failure)
7114 7161 *failure = BPF_MEM_SIZE_FAIL_MEMORY;
7115 7162
7116 - if (!err) {
7117 - int regno = reg_from_argno(size_argno);
7118 -
7119 - if (regno >= 0)
7120 - err = mark_chain_precision(env, regno);
7121 - else
7122 - err = mark_stack_arg_precision(env, arg_idx_from_argno(size_argno));
7123 - }
7163 + if (!err)
7164 + err = mark_arg_precision(env, size_argno);
7124 7165
7125 7166 return err;
7126 7167
@@ -7137,7 +7178,7 @@ static int check_mem_reg(struct bpf_verifier_env *env, struct bpf_reg_state *reg
7137 7178 int size, err = 0;
7138 7179
7139 7180 if (bpf_register_is_null(reg))
7140 - return 0;
7181 + return mark_arg_precision(env, argno);
7141 7182 if (known_memory)
7142 7183 *known_memory = true;
7143 7184
@@ -7398,10 +7439,14 @@ static int process_spin_lock(struct bpf_verifier_env *env, struct bpf_reg_state
7398 7439 lock);
7399 7440 return -EINVAL;
7400 7441 }
7442 + /*
7443 + * Invalidate non-owning refs before RCU demotion clears their
7444 + * NON_OWN_REF flag.
7445 + */
7446 + invalidate_non_owning_refs(env);
7447 +
7401 7448 if (!in_rcu_cs(env))
7402 7449 invalidate_rcu_protected_refs(env);
7403 -
7404 - invalidate_non_owning_refs(env);
7405 7450 }
7406 7451 return 0;
7407 7452 }
@@ -8166,6 +8211,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = {
8166 8211 [ARG_MEM_SIZE] = &scalar_types,
8167 8212 [ARG_MEM_SIZE_OR_ZERO] = &scalar_types,
8168 8213 [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types,
8214 + [ARG_SCALAR] = &scalar_types,
8169 8215 [ARG_CONST_MAP_PTR] = &const_map_ptr_types,
8170 8216 [ARG_PTR_TO_CTX] = &context_types,
8171 8217 [ARG_PTR_TO_SOCK_COMMON] = &sock_types,
@@ -8717,11 +8763,15 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
8717 8763 return err;
8718 8764 }
8719 8765
8720 - if (bpf_register_is_null(reg) && type_may_be_null(arg_type))
8766 + if (bpf_register_is_null(reg) && type_may_be_null(arg_type)) {
8721 8767 /* A NULL register has a SCALAR_VALUE type, so skip
8722 8768 * type checking.
8723 8769 */
8770 + err = mark_chain_precision(env, regno);
8771 + if (err)
8772 + return err;
8724 8773 goto skip_type_check;
8774 + }
8725 8775
8726 8776 /* arg_btf_id and arg_size are in a union. */
8727 8777 if (base_type(arg_type) == ARG_PTR_TO_BTF_ID ||
@@ -9501,7 +9551,7 @@ static void invalidate_rcu_protected_refs(struct bpf_verifier_env *env)
9501 9551 bpf_for_each_reg_in_vstate_mask(env->cur_state, state, reg, stack, clear_mask, ({
9502 9552 if (reg->type & MEM_RCU) {
9503 9553 bpf_diag_mod_begin(env, reg, NULL, BPF_DIAG_MOD_WRITE);
9504 - reg->type &= ~(MEM_RCU | PTR_MAYBE_NULL);
9554 + reg->type &= ~(MEM_RCU | PTR_MAYBE_NULL | NON_OWN_REF);
9505 9555 reg->type |= PTR_UNTRUSTED;
9506 9556 bpf_diag_mod_end(env);
9507 9557 }
@@ -9719,8 +9769,12 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,
9719 9769 struct bpf_call_arg_meta meta;
9720 9770 int err;
9721 9771
9722 - if (bpf_register_is_null(reg) && type_may_be_null(arg->arg_type))
9772 + if (bpf_register_is_null(reg) && type_may_be_null(arg->arg_type)) {
9773 + err = mark_arg_precision(env, argno);
9774 + if (err)
9775 + return err;
9723 9776 continue;
9777 + }
9724 9778
9725 9779 memset(&meta, 0, sizeof(meta)); /* leave func_id as zero */
9726 9780 err = check_reg_type(env, reg, argno, arg->arg_type, &arg->btf_id, &meta,
@@ -9976,10 +10030,12 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env,
9976 10030 callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;
9977 10031 __mark_reg_known_zero(&callee->regs[BPF_REG_2]);
9978 10032 callee->regs[BPF_REG_2].map_ptr = caller->regs[BPF_REG_1].map_ptr;
10033 + callee->regs[BPF_REG_2].map_uid = caller->regs[BPF_REG_1].map_uid;
9979 10034
9980 10035 callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;
9981 10036 __mark_reg_known_zero(&callee->regs[BPF_REG_3]);
9982 10037 callee->regs[BPF_REG_3].map_ptr = caller->regs[BPF_REG_1].map_ptr;
10038 + callee->regs[BPF_REG_3].map_uid = caller->regs[BPF_REG_1].map_uid;
9983 10039
9984 10040 /* pointer to stack or null */
9985 10041 callee->regs[BPF_REG_4] = caller->regs[BPF_REG_3];
@@ -10057,6 +10113,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env,
10057 10113 int insn_idx)
10058 10114 {
10059 10115 struct bpf_map *map_ptr = caller->regs[BPF_REG_1].map_ptr;
10116 + u32 map_uid = caller->regs[BPF_REG_1].map_uid;
10060 10117
10061 10118 /* bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn);
10062 10119 * callback_fn(struct bpf_map *map, void *key, void *value);
@@ -10064,14 +10121,17 @@ static int set_timer_callback_state(struct bpf_verifier_env *env,
10064 10121 callee->regs[BPF_REG_1].type = CONST_PTR_TO_MAP;
10065 10122 __mark_reg_known_zero(&callee->regs[BPF_REG_1]);
10066 10123 callee->regs[BPF_REG_1].map_ptr = map_ptr;
10124 + callee->regs[BPF_REG_1].map_uid = map_uid;
10067 10125
10068 10126 callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;
10069 10127 __mark_reg_known_zero(&callee->regs[BPF_REG_2]);
10070 10128 callee->regs[BPF_REG_2].map_ptr = map_ptr;
10129 + callee->regs[BPF_REG_2].map_uid = map_uid;
10071 10130
10072 10131 callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;
10073 10132 __mark_reg_known_zero(&callee->regs[BPF_REG_3]);
10074 10133 callee->regs[BPF_REG_3].map_ptr = map_ptr;
10134 + callee->regs[BPF_REG_3].map_uid = map_uid;
10075 10135
10076 10136 /* unused */
10077 10137 bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10171,6 +10231,7 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
10171 10231 int insn_idx)
10172 10232 {
10173 10233 struct bpf_map *map_ptr = caller->regs[BPF_REG_3].map_ptr;
10234 + u32 map_uid = caller->regs[BPF_REG_3].map_uid;
10174 10235
10175 10236 /*
10176 10237 * callback_fn(struct bpf_map *map, void *key, void *value);
@@ -10178,14 +10239,17 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
10178 10239 callee->regs[BPF_REG_1].type = CONST_PTR_TO_MAP;
10179 10240 __mark_reg_known_zero(&callee->regs[BPF_REG_1]);
10180 10241 callee->regs[BPF_REG_1].map_ptr = map_ptr;
10242 + callee->regs[BPF_REG_1].map_uid = map_uid;
10181 10243
10182 10244 callee->regs[BPF_REG_2].type = PTR_TO_MAP_KEY;
10183 10245 __mark_reg_known_zero(&callee->regs[BPF_REG_2]);
10184 10246 callee->regs[BPF_REG_2].map_ptr = map_ptr;
10247 + callee->regs[BPF_REG_2].map_uid = map_uid;
10185 10248
10186 10249 callee->regs[BPF_REG_3].type = PTR_TO_MAP_VALUE;
10187 10250 __mark_reg_known_zero(&callee->regs[BPF_REG_3]);
10188 10251 callee->regs[BPF_REG_3].map_ptr = map_ptr;
10252 + callee->regs[BPF_REG_3].map_uid = map_uid;
10189 10253
10190 10254 /* unused */
10191 10255 bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10233,9 +10297,10 @@ static void account_current_path(struct bpf_verifier_env *env)
10233 10297 frame ? state->frame[frame - 1] : NULL);
10234 10298 }
10235 10299
10236 - /* Are we currently verifying the callback for a rbtree helper that must
10237 - * be called with lock held? If so, no need to complain about unreleased
10238 - * lock
10300 + /*
10301 + * Are we currently verifying the callback for an rbtree kfunc that must
10302 + * be called with a lock held, or one of that callback's subprogs? If so,
10303 + * no need to complain about an unreleased lock.
10239 10304 */
10240 10305 static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env)
10241 10306 {
@@ -10243,17 +10308,19 @@ static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env)
10243 10308 struct bpf_insn *insn = env->prog->insnsi;
10244 10309 struct bpf_func_state *callee;
10245 10310 int kfunc_btf_id;
10311 + u32 frame;
10246 10312
10247 - if (!state->curframe)
10248 - return false;
10249 -
10250 - callee = state->frame[state->curframe];
10313 + for (frame = state->curframe; frame; frame--) {
10314 + callee = state->frame[frame];
10315 + if (!callee->in_callback_fn)
10316 + continue;
10251 10317
10252 - if (!callee->in_callback_fn)
10253 - return false;
10318 + kfunc_btf_id = insn[callee->callsite].imm;
10319 + if (is_rbtree_lock_required_kfunc(kfunc_btf_id))
10320 + return true;
10321 + }
10254 10322
10255 - kfunc_btf_id = insn[callee->callsite].imm;
10256 - return is_rbtree_lock_required_kfunc(kfunc_btf_id);
10323 + return false;
10257 10324 }
10258 10325
10259 10326 static bool retval_range_within(struct bpf_retval_range range, const struct bpf_reg_state *reg)
@@ -10630,33 +10697,45 @@ static struct bpf_insn_aux_data *cur_aux(const struct bpf_verifier_env *env)
10630 10697 return &env->insn_aux_data[env->insn_idx];
10631 10698 }
10632 10699
10633 - static bool loop_flag_is_zero(struct bpf_verifier_env *env)
10700 + /* Returns 1 if R4 is a known zero, 0 if it is not, a negative errno on error. */
10701 + static int loop_flag_is_zero(struct bpf_verifier_env *env)
10634 10702 {
10635 10703 struct bpf_reg_state *reg = reg_state(env, BPF_REG_4);
10636 - bool reg_is_null = bpf_register_is_null(reg);
10704 + int err;
10637 10705
10638 - if (reg_is_null)
10639 - mark_chain_precision(env, BPF_REG_4);
10706 + if (!bpf_register_is_null(reg))
10707 + return 0;
10640 10708
10641 - return reg_is_null;
10709 + err = mark_chain_precision(env, BPF_REG_4);
10710 + if (err)
10711 + return err;
10712 + return 1;
10642 10713 }
10643 10714
10644 - static void update_loop_inline_state(struct bpf_verifier_env *env, u32 subprogno)
10715 + static int update_loop_inline_state(struct bpf_verifier_env *env, u32 subprogno)
10645 10716 {
10646 10717 struct bpf_loop_inline_state *state = &cur_aux(env)->loop_inline_state;
10718 + int flag_is_zero;
10647 10719
10648 10720 if (!state->initialized) {
10721 + flag_is_zero = loop_flag_is_zero(env);
10722 + if (flag_is_zero < 0)
10723 + return flag_is_zero;
10649 10724 state->initialized = 1;
10650 - state->fit_for_inline = loop_flag_is_zero(env);
10725 + state->fit_for_inline = flag_is_zero;
10651 10726 state->callback_subprogno = subprogno;
10652 - return;
10727 + return 0;
10653 10728 }
10654 10729
10655 10730 if (!state->fit_for_inline)
10656 - return;
10731 + return 0;
10657 10732
10658 - state->fit_for_inline = (loop_flag_is_zero(env) &&
10733 + flag_is_zero = loop_flag_is_zero(env);
10734 + if (flag_is_zero < 0)
10735 + return flag_is_zero;
10736 + state->fit_for_inline = (flag_is_zero &&
10659 10737 state->callback_subprogno == subprogno);
10738 + return 0;
10660 10739 }
10661 10740
10662 10741 /* Returns whether or not the given map can potentially elide
@@ -10868,6 +10947,9 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
10868 10947 verbose(env, "get_local_storage() doesn't support non-zero flags\n");
10869 10948 return -EINVAL;
10870 10949 }
10950 + err = mark_chain_precision(env, BPF_REG_2);
10951 + if (err)
10952 + return err;
10871 10953 break;
10872 10954 case BPF_FUNC_for_each_map_elem:
10873 10955 err = push_callback_call(env, insn, insn_idx, meta.subprogno,
@@ -10885,7 +10967,9 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
10885 10967 err = check_bpf_snprintf_call(env, regs);
10886 10968 break;
10887 10969 case BPF_FUNC_loop:
10888 - update_loop_inline_state(env, meta.subprogno);
10970 + err = update_loop_inline_state(env, meta.subprogno);
10971 + if (err)
10972 + return err;
10889 10973 /* Verifier relies on R1 value to determine if bpf_loop() iteration
10890 10974 * is finished, thus mark it precise.
10891 10975 */
@@ -11226,6 +11310,17 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
11226 11310 if (env->cur_state->curframe) {
11227 11311 struct bpf_verifier_state *branch;
11228 11312
11313 + /*
11314 + * A taken tail call is modeled as a return from the current
11315 + * frame. A callback frame cannot be left that way because
11316 + * prepare_func_exit() would apply its return contract to the
11317 + * unknown R0 synthesized below. Stack-depth validation rejects
11318 + * this construct anyway.
11319 + */
11320 + if (cur_func(env)->in_callback_fn) {
11321 + verbose(env, "cannot tail call within callback\n");
11322 + return -EINVAL;
11323 + }
11229 11324 mark_reg_scratched(env, BPF_REG_0);
11230 11325 branch = push_stack(env, env->insn_idx + 1, env->insn_idx, false);
11231 11326 if (IS_ERR(branch))
@@ -12651,8 +12746,12 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
12651 12746 if (reg_is_referenced(env, reg))
12652 12747 update_ref_obj(&meta->ref_obj, reg);
12653 12748
12654 - if (bpf_register_is_null(reg) && type_may_be_null(kf_arg_type))
12749 + if (bpf_register_is_null(reg) && type_may_be_null(kf_arg_type)) {
12750 + ret = mark_arg_precision(env, argno);
12751 + if (ret)
12752 + return ret;
12655 12753 continue;
12754 + }
12656 12755
12657 12756 if (is_kfunc_arg_map(btf, &args[i])) {
12658 12757 ref_id = *reg2btf_ids[CONST_PTR_TO_MAP];
@@ -13146,7 +13245,7 @@ check_ok:
13146 13245 bpf_diag_reg_type_plain(env, reg->type));
13147 13246 return -EINVAL;
13148 13247 }
13149 - if (!type_is_non_owning_ref(reg->type))
13248 + if (!type_is_non_owning_ref(reg->type) && reg_is_referenced(env, reg))
13150 13249 meta->arg_owning_ref = true;
13151 13250
13152 13251 rec = reg_btf_record(reg);
@@ -13228,6 +13327,11 @@ check_ok:
13228 13327 {
13229 13328 int flags = PROCESS_RES_LOCK;
13230 13329
13330 + if (in_rbtree_lock_required_cb(env)) {
13331 + verbose(env, "can't res_spin_{lock,unlock} in rbtree cb\n");
13332 + return -EACCES;
13333 + }
13334 +
13231 13335 if (reg->type != PTR_TO_MAP_VALUE && reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
13232 13336 verbose(env, "%s doesn't point to map value or allocated object\n",
13233 13337 reg_arg_name(env, argno));
@@ -14560,9 +14664,6 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn
14560 14664 return -EINVAL;
14561 14665 }
14562 14666
14563 - /* pointer types do not carry 32-bit bounds at the moment. */
14564 - __mark_reg32_unbounded(dst_reg);
14565 -
14566 14667 if (sanitize_needed(opcode)) {
14567 14668 ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg,
14568 14669 &info, false);
@@ -14570,6 +14671,14 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn
14570 14671 return sanitize_err(env, insn, ret);
14571 14672 }
14572 14673
14674 + /*
14675 + * Pointer types do not carry 32-bit bounds at the moment. Blank r32
14676 + * only after sanitize_ptr_alu() may have snapshotted dst_reg into a
14677 + * speculative path: otherwise reg_bounds_sanity_check() might hit some
14678 + * constraints violations.
14679 + */
14680 + __mark_reg32_unbounded(dst_reg);
14681 +
14573 14682 switch (opcode) {
14574 14683 case BPF_ADD:
14575 14684 /*
@@ -16295,6 +16404,13 @@ static int is_branch_taken(struct bpf_verifier_env *env, struct bpf_reg_state *r
16295 16404 if (__is_pointer_value(false, reg1) || __is_pointer_value(false, reg2)) {
16296 16405 u64 val;
16297 16406
16407 + /*
16408 + * The low 32 bits of a valid pointer may well be zero, hence
16409 + * nothing below applies to a 32-bit comparison.
16410 + */
16411 + if (is_jmp32)
16412 + return -1;
16413 +
16298 16414 /* arrange that reg2 is a scalar, and reg1 is a pointer */
16299 16415 if (!is_reg_const(reg2, is_jmp32)) {
16300 16416 opcode = flip_opcode(opcode);
@@ -16856,6 +16972,16 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
16856 16972 return err;
16857 16973 }
16858 16974
16975 + /*
16976 + * Collect the linked registers before env->{true,false}_reg{1,2} setup,
16977 + * otherwise ids dropped by collect_linked_regs() would be resurrected
16978 + * when env->{true,false}_reg{1,2} are copied back.
16979 + */
16980 + if (BPF_SRC(insn->code) == BPF_X && src_reg->type == SCALAR_VALUE && src_reg->id)
16981 + collect_linked_regs(env, this_branch, src_reg->id, &linked_regs);
16982 + if (dst_reg->type == SCALAR_VALUE && dst_reg->id)
16983 + collect_linked_regs(env, this_branch, dst_reg->id, &linked_regs);
16984 +
16859 16985 is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32;
16860 16986 env->false_reg1 = *dst_reg;
16861 16987 env->false_reg2 = *src_reg;
@@ -16910,10 +17036,6 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
16910 17036 * 'this_branch' and 'other_branch' share this history
16911 17037 * if parent state is created.
16912 17038 */
16913 - if (BPF_SRC(insn->code) == BPF_X && src_reg->type == SCALAR_VALUE && src_reg->id)
16914 - collect_linked_regs(env, this_branch, src_reg->id, &linked_regs);
16915 - if (dst_reg->type == SCALAR_VALUE && dst_reg->id)
16916 - collect_linked_regs(env, this_branch, dst_reg->id, &linked_regs);
16917 17039 if (linked_regs.cnt > 1) {
16918 17040 err = bpf_push_jmp_history(env, this_branch, 0, 0, 0, linked_regs_pack(&linked_regs));
16919 17041 if (err)
@@ -16963,7 +17085,6 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
16963 17085 */
16964 17086 if (!is_jmp32 && BPF_SRC(insn->code) == BPF_X &&
16965 17087 __is_pointer_value(false, src_reg) && __is_pointer_value(false, dst_reg) &&
16966 - type_may_be_null(src_reg->type) != type_may_be_null(dst_reg->type) &&
16967 17088 base_type(src_reg->type) != PTR_TO_BTF_ID &&
16968 17089 base_type(dst_reg->type) != PTR_TO_BTF_ID) {
16969 17090 eq_branch_regs = NULL;
@@ -16979,9 +17100,11 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
16979 17100 break;
16980 17101 }
16981 17102 if (eq_branch_regs) {
16982 - if (type_may_be_null(src_reg->type))
17103 + /* src == dst && dst != NULL => src != NULL */
17104 + if (reg_not_null(env, dst_reg) && type_may_be_null(src_reg->type))
16983 17105 mark_ptr_not_null_reg(&eq_branch_regs[insn->src_reg]);
16984 - else
17106 + /* src == dst && src != NULL => dst != NULL */
17107 + if (reg_not_null(env, src_reg) && type_may_be_null(dst_reg->type))
16985 17108 mark_ptr_not_null_reg(&eq_branch_regs[insn->dst_reg]);
16986 17109 }
16987 17110 }
@@ -16996,6 +17119,15 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
16996 17119 type_may_be_null(dst_reg->type) &&
16997 17120 ((BPF_SRC(insn->code) == BPF_K && insn->imm == 0) ||
16998 17121 (BPF_SRC(insn->code) == BPF_X && bpf_register_is_null(src_reg)))) {
17122 + /*
17123 + * For BPF_X the zero is a property of this execution path,
17124 + * hence src_reg has to be precise.
17125 + */
17126 + if (BPF_SRC(insn->code) == BPF_X) {
17127 + err = mark_chain_precision(env, insn->src_reg);
17128 + if (err)
17129 + return err;
17130 + }
16999 17131 /* Mark all identical registers in each branch as either
17000 17132 * safe or unknown depending R == 0 or R != 0 conditional.
17001 17133 */
@@ -17081,6 +17213,15 @@ static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)
17081 17213 verbose(env, "callback function not static\n");
17082 17214 return -EINVAL;
17083 17215 }
17216 + /*
17217 + * When env->subprog_cnt == 1 this instruction won't be rewritten
17218 + * to hold a real function address. Assume that no usable program
17219 + * combines e.g. main and timer callback and just reject here.
17220 + */
17221 + if (subprogno == 0) {
17222 + verbose(env, "callback function cannot be the main program\n");
17223 + return -EINVAL;
17224 + }
17084 17225
17085 17226 dst_reg->type = PTR_TO_FUNC;
17086 17227 dst_reg->subprogno = subprogno;
@@ -17146,6 +17287,7 @@ static bool may_access_skb(enum bpf_prog_type type)
17146 17287 */
17147 17288 static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)
17148 17289 {
17290 + struct bpf_verifier_state *state = env->cur_state;
17149 17291 struct bpf_reg_state *regs = cur_regs(env);
17150 17292 static const int ctx_reg = BPF_REG_6;
17151 17293 u8 mode = BPF_MODE(insn->code);
@@ -17156,6 +17298,13 @@ static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)
17156 17298 return -EINVAL;
17157 17299 }
17158 17300
17301 + for (i = state->curframe; i; i--) {
17302 + if (state->frame[i]->in_callback_fn) {
17303 + verbose(env, "cannot use BPF_LD_[ABS|IND] within callback\n");
17304 + return -EINVAL;
17305 + }
17306 + }
17307 +
17159 17308 if (!env->ops->gen_ld_abs) {
17160 17309 verifier_bug(env, "gen_ld_abs is null");
17161 17310 return -EFAULT;
@@ -17623,6 +17772,10 @@ bool bpf_get_call_summary(struct bpf_verifier_env *env, struct bpf_insn *call,
17623 17772 * r0 = *(u64 *)(r10 - 8); r0 += r1;
17624 17773 * r0 += r1; exit;
17625 17774 * exit;
17775 + *
17776 + * Both uses of the marks assume that a pattern is entered at its first
17777 + * spill and thus executes as a unit, hence a pattern is not grown past
17778 + * an instruction targeted by a jump.
17626 17779 */
17627 17780 static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env,
17628 17781 struct bpf_subprog_info *subprog,
@@ -17661,6 +17814,10 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env,
17661 17814 for (i = 1, off = lowest_off; i <= ARRAY_SIZE(caller_saved); ++i, off += BPF_REG_SIZE) {
17662 17815 if (insn_idx - i < 0 || insn_idx + i >= env->prog->len)
17663 17816 break;
17817 + /* stx/ldx/call must not be a jump targets, a jump to the first stx is fine */
17818 + if (bpf_is_jump_target(env, insn_idx - i + 1) ||
17819 + bpf_is_jump_target(env, insn_idx + i))
17820 + break;
17664 17821 stx = &insns[insn_idx - i];
17665 17822 ldx = &insns[insn_idx + i];
17666 17823 /* must be a stack spill/fill pair */
@@ -20536,8 +20693,7 @@ static int process_fd_array_continuous(struct bpf_verifier_env *env,
20536 20693 return -E2BIG;
20537 20694 }
20538 20695
20539 - env->fd_array = kvcalloc(cnt, sizeof(*env->fd_array),
20540 - GFP_KERNEL_ACCOUNT);
20696 + env->fd_array = kvzalloc_objs(*env->fd_array, cnt, GFP_KERNEL_ACCOUNT);
20541 20697 if (!env->fd_array)
20542 20698 return -ENOMEM;
20543 20699 env->fd_array_cnt = cnt;
modified kernel/capability.c
@@ -326,7 +326,6 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
326 326 {
327 327 return has_ns_capability_noaudit(t, &init_user_ns, cap);
328 328 }
329 - EXPORT_SYMBOL(has_capability_noaudit);
330 329
331 330 static bool ns_capable_common(struct user_namespace *ns,
332 331 int cap,
@@ -416,6 +415,24 @@ bool capable(int cap)
416 415 return ns_capable(&init_user_ns, cap);
417 416 }
418 417 EXPORT_SYMBOL(capable);
418 +
419 + /**
420 + * capable_noaudit - Determine if the current task has a superior
421 + * capability in effect by checking the process's effective
422 + * capabilities (unaudited).
423 + * @cap: The capability to be tested for
424 + *
425 + * This is the same as capable(), except it uses CAP_OPT_NOAUDIT as to prevent
426 + * issuing spurious audit messages.
427 + *
428 + * This sets PF_SUPERPRIV on the task if the capability is available on the
429 + * assumption that it's about to be used.
430 + */
431 + bool capable_noaudit(int cap)
432 + {
433 + return ns_capable_noaudit(&init_user_ns, cap);
434 + }
435 + EXPORT_SYMBOL(capable_noaudit);
419 436 #endif /* CONFIG_MULTIUSER */
420 437
421 438 /**
modified kernel/cgroup/cgroup.c
@@ -6873,10 +6873,7 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
6873 6873 spin_lock_irq(&css_set_lock);
6874 6874 cset = task_css_set(current);
6875 6875 get_css_set(cset);
6876 - if (kargs->cgrp)
6877 - kargs->kill_seq = kargs->cgrp->kill_seq;
6878 - else
6879 - kargs->kill_seq = cset->dfl_cgrp->kill_seq;
6876 + kargs->kill_seq = cset->dfl_cgrp->kill_seq;
6880 6877 spin_unlock_irq(&css_set_lock);
6881 6878
6882 6879 if (!(kargs->flags & CLONE_INTO_CGROUP)) {
@@ -6940,6 +6937,7 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
6940 6937
6941 6938 put_css_set(cset);
6942 6939 kargs->cgrp = dst_cgrp;
6940 + kargs->kill_seq = dst_cgrp->kill_seq;
6943 6941 return ret;
6944 6942
6945 6943 err:
modified kernel/cgroup/cpuset.c
@@ -1259,6 +1259,28 @@ static void reset_partition_data(struct cpuset *cs)
1259 1259 cpumask_copy(cs->effective_cpus, parent->effective_cpus);
1260 1260 }
1261 1261
1262 + /* Return true if isolated_cpus changes. */
1263 + static bool isolated_cpu_update(int new_prs, int cpu)
1264 + {
1265 + lockdep_assert_held(&callback_lock);
1266 + lockdep_assert_held(&cpuset_mutex);
1267 +
1268 + if (new_prs == PRS_ISOLATED) {
1269 + if (cpumask_test_cpu(cpu, isolated_cpus))
1270 + return false;
1271 + cpumask_set_cpu(cpu, isolated_cpus);
1272 + return true;
1273 + }
1274 +
1275 + /* CPUs isolated at boot must remain isolated. */
1276 + if (!cpumask_test_cpu(cpu,
1277 + housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT)) ||
1278 + !cpumask_test_cpu(cpu, isolated_cpus))
1279 + return false;
1280 + cpumask_clear_cpu(cpu, isolated_cpus);
1281 + return true;
1282 + }
1283 +
1262 1284 /*
1263 1285 * isolated_cpus_update - Update the isolated_cpus mask
1264 1286 * @old_prs: old partition_root_state
@@ -1267,19 +1289,16 @@ static void reset_partition_data(struct cpuset *cs)
1267 1289 */
1268 1290 static void isolated_cpus_update(int old_prs, int new_prs, struct cpumask *xcpus)
1269 1291 {
1292 + bool updated = false;
1293 + int cpu;
1294 +
1270 1295 WARN_ON_ONCE(old_prs == new_prs);
1271 1296 lockdep_assert_held(&callback_lock);
1272 1297 lockdep_assert_held(&cpuset_mutex);
1273 - if (new_prs == PRS_ISOLATED) {
1274 - if (cpumask_subset(xcpus, isolated_cpus))
1275 - return;
1276 - cpumask_or(isolated_cpus, isolated_cpus, xcpus);
1277 - } else {
1278 - if (!cpumask_intersects(xcpus, isolated_cpus))
1279 - return;
1280 - cpumask_andnot(isolated_cpus, isolated_cpus, xcpus);
1281 - }
1282 - update_housekeeping = true;
1298 + for_each_cpu(cpu, xcpus)
1299 + updated |= isolated_cpu_update(new_prs, cpu);
1300 + if (updated)
1301 + update_housekeeping = true;
1283 1302 }
1284 1303
1285 1304 /*
modified kernel/dma/map_benchmark.c
@@ -51,8 +51,7 @@ struct dma_single_map_param {
51 51
52 52 static void *dma_single_map_benchmark_prepare(struct map_benchmark_data *map)
53 53 {
54 - struct dma_single_map_param *params __free(kfree) = kzalloc(sizeof(*params),
55 - GFP_KERNEL);
54 + struct dma_single_map_param *params __free(kfree) = kzalloc_obj(*params);
56 55 if (!params)
57 56 return NULL;
58 57
modified kernel/events/core.c
@@ -7029,7 +7029,6 @@ static void perf_mmap_close(struct vm_area_struct *vma)
7029 7029 mapped_f unmapped = get_mapped(event, event_unmapped);
7030 7030 struct perf_buffer *rb = ring_buffer_get(event);
7031 7031 struct user_struct *mmap_user = rb->mmap_user;
7032 - bool detach_rest = false;
7033 7032
7034 7033 /* FIXIES vs perf_pmu_unregister() */
7035 7034 if (unmapped)
@@ -7060,17 +7059,18 @@ static void perf_mmap_close(struct vm_area_struct *vma)
7060 7059 mutex_unlock(&rb->aux_mutex);
7061 7060 }
7062 7061
7063 - if (refcount_dec_and_test(&rb->mmap_count))
7064 - detach_rest = true;
7065 -
7066 - if (!refcount_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex))
7067 - goto out_put;
7068 -
7069 - ring_buffer_attach(event, NULL);
7070 - mutex_unlock(&event->mmap_mutex);
7062 + /*
7063 + * Drop references in reverse order of perf_mmap() to prevent
7064 + * rb revival after rb->mmap_count reaches zero.
7065 + */
7066 + if (refcount_dec_and_mutex_lock(&event->mmap_count,
7067 + &event->mmap_mutex)) {
7068 + ring_buffer_attach(event, NULL);
7069 + mutex_unlock(&event->mmap_mutex);
7070 + }
7071 7071
7072 7072 /* If there's still other mmap()s of this buffer, we're done. */
7073 - if (!detach_rest)
7073 + if (!refcount_dec_and_test(&rb->mmap_count))
7074 7074 goto out_put;
7075 7075
7076 7076 /*
@@ -13558,9 +13558,8 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
13558 13558 return ERR_PTR(err);
13559 13559
13560 13560 if (has_addr_filter(event)) {
13561 - event->addr_filter_ranges = kcalloc(pmu->nr_addr_filters,
13562 - sizeof(struct perf_addr_filter_range),
13563 - GFP_KERNEL);
13561 + event->addr_filter_ranges = kzalloc_objs(struct perf_addr_filter_range,
13562 + pmu->nr_addr_filters);
13564 13563 if (!event->addr_filter_ranges)
13565 13564 return ERR_PTR(-ENOMEM);
13566 13565
modified kernel/events/ring_buffer.c
@@ -509,7 +509,10 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
509 509 /*
510 510 * Only send RECORD_AUX if we have something useful to communicate
511 511 *
512 - * Note: the OVERWRITE records by themselves are not considered
512 + * PMU_FORMAT bits identify the PMU type rather than an AUX event
513 + * has occurred, so ignore them for zero-sized records.
514 + *
515 + * The OVERWRITE records by themselves are not considered
513 516 * useful, as they don't communicate any *new* information,
514 517 * aside from the short-lived offset, that becomes history at
515 518 * the next event sched-in and therefore isn't useful.
@@ -518,7 +521,9 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
518 521 * offset. So, from now on we don't output AUX records that
519 522 * have *only* OVERWRITE flag set.
520 523 */
521 - if (size || (handle->aux_flags & ~(u64)PERF_AUX_FLAG_OVERWRITE))
524 + if (size ||
525 + (handle->aux_flags & ~(u64)(PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK |
526 + PERF_AUX_FLAG_OVERWRITE)))
522 527 perf_event_aux_event(handle->event, aux_head, size,
523 528 handle->aux_flags);
524 529
modified kernel/futex/core.c
@@ -1874,8 +1874,8 @@ static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
1874 1874 free_percpu(ref);
1875 1875 }
1876 1876
1877 - fph = kvzalloc(struct_size(fph, queues, hash_slots),
1878 - GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
1877 + fph = kvzalloc_flex(*fph, queues, hash_slots,
1878 + GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
1879 1879 if (!fph)
1880 1880 return -ENOMEM;
1881 1881
@@ -2103,7 +2103,7 @@ static int __init futex_init(void)
2103 2103 size = sizeof(struct futex_hash_bucket) * hashsize;
2104 2104 order = get_order(size);
2105 2105
2106 - __futex_queues = kcalloc(nr_node_ids, sizeof(*__futex_queues), GFP_KERNEL);
2106 + __futex_queues = kzalloc_objs(*__futex_queues, nr_node_ids);
2107 2107 kmemleak_not_leak(__futex_queues);
2108 2108
2109 2109 runtime_const_init(shift, __futex_shift);
modified kernel/futex/pi.c
@@ -1070,17 +1070,11 @@ retry_private:
1070 1070 * Caution; releasing @hb in-scope. The hb->lock is still locked
1071 1071 * while the reference is dropped. The reference can not be dropped
1072 1072 * after the unlock because if a user initiated resize is in progress
1073 - * then we might need to wake him. This can not be done after the
1074 - * rt_mutex_pre_schedule() invocation. The hb will remain valid because
1075 - * the thread, performing resize, will block on hb->lock during
1076 - * the requeue.
1073 + * then we might need to wake him. The hb will remain valid
1074 + * because the thread, performing resize, will block on
1075 + * hb->lock during the requeue.
1077 1076 */
1078 1077 futex_private_hash_put(no_free_ptr(hbr.fph));
1079 - /*
1080 - * Must be done before we enqueue the waiter, here is unfortunately
1081 - * under the hb lock, but that *should* work because it does nothing.
1082 - */
1083 - rt_mutex_pre_schedule();
1084 1078
1085 1079 rt_mutex_init_waiter(&rt_waiter);
1086 1080
@@ -1146,10 +1140,6 @@ cleanup:
1146 1140 * the
1147 1141 */
1148 1142 futex_q_lockptr_lock(&q);
1149 - /*
1150 - * Waiter is unqueued.
1151 - */
1152 - rt_mutex_post_schedule();
1153 1143 no_block:
1154 1144 /*
1155 1145 * Fixup the pi_state owner and possibly acquire the lock if we
modified kernel/futex/requeue.c
@@ -154,8 +154,16 @@ static inline void futex_requeue_pi_complete(struct futex_q *q, int locked)
154 154 } while (!atomic_try_cmpxchg(&q->requeue_state, &old, new));
155 155
156 156 #ifdef CONFIG_PREEMPT_RT
157 - /* If the waiter interleaved with the requeue let it know */
158 - if (unlikely(old == Q_REQUEUE_PI_WAIT))
157 + /*
158 + * The waiter in futex_requeue_pi_wakeup_sync() can interleave with the
159 + * wake below: It will assign Q_REQUEUE_PI_IN_PROGRESS and here it will
160 + * be updated to Q_REQUEUE_PI_LOCKED (locked = 1). The rcuwait_wait_event()
161 + * will already read Q_REQUEUE_PI_LOCKED and skip the schedule() invocation,
162 + * leading to an access of futex_q::requeue_wait after the waiter returned.
163 + * In this case only we skip the wake here and rely on following wake in
164 + * requeue_pi_wake_futex() to perform the wake if needed.
165 + */
166 + if (unlikely(old == Q_REQUEUE_PI_WAIT) && new != Q_REQUEUE_PI_LOCKED)
159 167 rcuwait_wake_up(&q->requeue_wait);
160 168 #endif
161 169 }
modified kernel/irq/manage.c
@@ -2306,7 +2306,7 @@ int request_nmi(unsigned int irq, irq_handler_t handler,
2306 2306 !irq_supports_nmi(desc))
2307 2307 return -EINVAL;
2308 2308
2309 - action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
2309 + action = kzalloc_obj(struct irqaction);
2310 2310 if (!action)
2311 2311 return -ENOMEM;
2312 2312
modified kernel/jump_label.c
@@ -726,12 +726,11 @@ static int jump_label_add_module(struct module *mod)
726 726 if (static_key_sealed(key))
727 727 goto do_poke;
728 728
729 - jlm = kzalloc(sizeof(struct static_key_mod), GFP_KERNEL);
729 + jlm = kzalloc_obj(struct static_key_mod);
730 730 if (!jlm)
731 731 return -ENOMEM;
732 732 if (!static_key_linked(key)) {
733 - jlm2 = kzalloc(sizeof(struct static_key_mod),
734 - GFP_KERNEL);
733 + jlm2 = kzalloc_obj(struct static_key_mod);
735 734 if (!jlm2) {
736 735 kfree(jlm);
737 736 return -ENOMEM;
modified kernel/kprobes.c
@@ -1447,8 +1447,14 @@ static bool __within_kprobe_blacklist(unsigned long addr)
1447 1447 /*
1448 1448 * If 'kprobe_blacklist' is defined, check the address and
1449 1449 * reject any probe registration in the prohibited area.
1450 + * Note: this can return true during transition period where
1451 + * (start_addr, end_addr) in the black list is shrinking
1452 + * but old entry has not been removed yet. This is acceptable
1453 + * because the worst case is that we reject more probes than
1454 + * we should.
1450 1455 */
1451 - list_for_each_entry(ent, &kprobe_blacklist, list) {
1456 + guard(rcu)();
1457 + list_for_each_entry_rcu(ent, &kprobe_blacklist, list) {
1452 1458 if (addr >= ent->start_addr && addr < ent->end_addr)
1453 1459 return true;
1454 1460 }
@@ -2509,7 +2515,7 @@ int kprobe_add_ksym_blacklist(unsigned long entry)
2509 2515 ent->start_addr = entry;
2510 2516 ent->end_addr = entry + size;
2511 2517 INIT_LIST_HEAD(&ent->list);
2512 - list_add_tail(&ent->list, &kprobe_blacklist);
2518 + list_add_tail_rcu(&ent->list, &kprobe_blacklist);
2513 2519
2514 2520 return (int)size;
2515 2521 }
@@ -2603,8 +2609,8 @@ static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)
2603 2609 list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) {
2604 2610 if (ent->start_addr < start || ent->start_addr >= end)
2605 2611 continue;
2606 - list_del(&ent->list);
2607 - kfree(ent);
2612 + list_del_rcu(&ent->list);
2613 + kfree_rcu(ent, rcu);
2608 2614 }
2609 2615 }
2610 2616
modified kernel/kthread.c
@@ -852,7 +852,7 @@ int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
852 852 if (!zalloc_cpumask_var(&affinity, GFP_KERNEL))
853 853 return -ENOMEM;
854 854
855 - kthread->preferred_affinity = kzalloc(sizeof(struct cpumask), GFP_KERNEL);
855 + kthread->preferred_affinity = kzalloc_obj(struct cpumask);
856 856 if (!kthread->preferred_affinity) {
857 857 ret = -ENOMEM;
858 858 goto out;
modified kernel/locking/lockdep.c
@@ -963,6 +963,34 @@ look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
963 963 return NULL;
964 964 }
965 965
966 + static __always_inline bool lock_class_cache_is_valid(const struct lockdep_map *lock,
967 + const struct lock_class *class,
968 + unsigned int subclass)
969 + {
970 + unsigned int class_subclass;
971 +
972 + if (!class)
973 + return false;
974 +
975 + if (unlikely(class < lock_classes || class >= lock_classes + MAX_LOCKDEP_KEYS))
976 + return false;
977 +
978 + if (unlikely(!arch_test_bit(class - lock_classes, lock_classes_in_use)))
979 + return false;
980 +
981 + if (unlikely(!lock->key))
982 + return false;
983 +
984 + class_subclass = subclass ? subclass : class->subclass;
985 + if (unlikely(class_subclass >= MAX_LOCKDEP_SUBCLASSES))
986 + return false;
987 +
988 + if (unlikely(READ_ONCE(class->key) != lock->key->subkeys + class_subclass))
989 + return false;
990 +
991 + return true;
992 + }
993 +
966 994 /*
967 995 * Static locks do not have their class-keys yet - for them the key is
968 996 * the lock object itself. If the lock is in the per cpu area, the
@@ -1395,9 +1423,9 @@ out_unlock_set:
1395 1423
1396 1424 out_set_class_cache:
1397 1425 if (!subclass || force)
1398 - lock->class_cache[0] = class;
1426 + WRITE_ONCE(lock->class_cache[0], class);
1399 1427 else if (subclass < NR_LOCKDEP_CACHING_CLASSES)
1400 - lock->class_cache[subclass] = class;
1428 + WRITE_ONCE(lock->class_cache[subclass], class);
1401 1429
1402 1430 /*
1403 1431 * Hash collision, did we smoke some? We found a class with a matching
@@ -4957,7 +4985,7 @@ void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
4957 4985 int i;
4958 4986
4959 4987 for (i = 0; i < NR_LOCKDEP_CACHING_CLASSES; i++)
4960 - lock->class_cache[i] = NULL;
4988 + WRITE_ONCE(lock->class_cache[i], NULL);
4961 4989
4962 4990 #ifdef CONFIG_LOCK_STAT
4963 4991 lock->cpu = raw_smp_processor_id();
@@ -5022,12 +5050,15 @@ EXPORT_SYMBOL_GPL(__lockdep_no_track__);
5022 5050 void lockdep_set_lock_cmp_fn(struct lockdep_map *lock, lock_cmp_fn cmp_fn,
5023 5051 lock_print_fn print_fn)
5024 5052 {
5025 - struct lock_class *class = lock->class_cache[0];
5053 + struct lock_class *class = READ_ONCE(lock->class_cache[0]);
5026 5054 unsigned long flags;
5027 5055
5028 5056 raw_local_irq_save(flags);
5029 5057 lockdep_recursion_inc();
5030 5058
5059 + if (!lock_class_cache_is_valid(lock, class, 0))
5060 + class = NULL;
5061 +
5031 5062 if (!class)
5032 5063 class = register_lock_class(lock, 0, 0);
5033 5064
@@ -5119,8 +5150,11 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
5119 5150 if (DEBUG_LOCKS_WARN_ON(subclass >= MAX_LOCKDEP_SUBCLASSES))
5120 5151 return 0;
5121 5152
5122 - if (subclass < NR_LOCKDEP_CACHING_CLASSES)
5123 - class = lock->class_cache[subclass];
5153 + if (subclass < NR_LOCKDEP_CACHING_CLASSES) {
5154 + class = READ_ONCE(lock->class_cache[subclass]);
5155 + if (!lock_class_cache_is_valid(lock, class, subclass))
5156 + class = NULL;
5157 + }
5124 5158 /*
5125 5159 * Not cached?
5126 5160 */
@@ -5324,9 +5358,9 @@ static noinstr int match_held_lock(const struct held_lock *hlock,
5324 5358 return 1;
5325 5359
5326 5360 if (hlock->references) {
5327 - const struct lock_class *class = lock->class_cache[0];
5361 + const struct lock_class *class = READ_ONCE(lock->class_cache[0]);
5328 5362
5329 - if (!class)
5363 + if (!lock_class_cache_is_valid(lock, class, 0))
5330 5364 class = look_up_lock_class(lock, 0);
5331 5365
5332 5366 /*
modified kernel/locking/rtmutex_api.c
@@ -423,6 +423,7 @@ int __sched rt_mutex_wait_proxy_lock(struct rt_mutex_base *lock,
423 423 {
424 424 int ret;
425 425
426 + rt_mutex_futex_pre_schedule();
426 427 raw_spin_lock_irq(&lock->wait_lock);
427 428 /* sleep on the mutex */
428 429 set_current_state(TASK_INTERRUPTIBLE);
@@ -433,6 +434,7 @@ int __sched rt_mutex_wait_proxy_lock(struct rt_mutex_base *lock,
433 434 */
434 435 fixup_rt_mutex_waiters(lock, true);
435 436 raw_spin_unlock_irq(&lock->wait_lock);
437 + rt_mutex_futex_post_schedule();
436 438
437 439 return ret;
438 440 }
modified kernel/sched/core.c
@@ -3742,11 +3742,17 @@ static inline void ttwu_do_wakeup(struct task_struct *p)
3742 3742
3743 3743 void update_rq_avg_idle(struct rq *rq)
3744 3744 {
3745 - u64 delta = rq_clock(rq) - rq->idle_stamp;
3746 - u64 max = 2*rq->max_idle_balance_cost;
3745 + u64 idle_stamp = rq->idle_stamp;
3746 + u64 delta, max;
3747 +
3748 + if (!idle_stamp)
3749 + return;
3750 +
3751 + delta = rq_clock(rq) - idle_stamp;
3747 3752
3748 3753 update_avg(&rq->avg_idle, delta);
3749 3754
3755 + max = 2 * rq->max_idle_balance_cost;
3750 3756 if (rq->avg_idle > max)
3751 3757 rq->avg_idle = max;
3752 3758 rq->idle_stamp = 0;
@@ -7637,6 +7643,17 @@ void rt_mutex_pre_schedule(void)
7637 7643 sched_submit_work(current);
7638 7644 }
7639 7645
7646 + /*
7647 + * Used within the futex syscall context, skips sched_submit_work() because none
7648 + * its work will be done. Asserts ensure that it is indeed the case.
7649 + */
7650 + void rt_mutex_futex_pre_schedule(void)
7651 + {
7652 + lockdep_assert(!(current->flags & (PF_WQ_WORKER | PF_IO_WORKER)));
7653 + lockdep_assert(!current->plug);
7654 + lockdep_assert(!fetch_and_set(current->sched_rt_mutex, 1));
7655 + }
7656 +
7640 7657 void rt_mutex_schedule(void)
7641 7658 {
7642 7659 lockdep_assert(current->sched_rt_mutex);
@@ -7649,6 +7666,11 @@ void rt_mutex_post_schedule(void)
7649 7666 lockdep_assert(fetch_and_set(current->sched_rt_mutex, 0));
7650 7667 }
7651 7668
7669 + void rt_mutex_futex_post_schedule(void)
7670 + {
7671 + lockdep_assert(fetch_and_set(current->sched_rt_mutex, 0));
7672 + }
7673 +
7652 7674 /*
7653 7675 * rt_mutex_setprio - set the current priority of a task
7654 7676 * @p: task to boost
modified kernel/sched/deadline.c
@@ -3028,8 +3028,8 @@ static struct task_struct *pick_next_pushable_dl_task(struct rq *rq)
3028 3028 next_node = rb_first_cached(&rq->dl.pushable_dl_tasks_root);
3029 3029 while (next_node) {
3030 3030 i = __node_2_pdl(next_node);
3031 - /* make sure task isn't on_cpu (possible with proxy-exec) */
3032 - if (!task_on_cpu(rq, i)) {
3031 + /* skip tasks that cannot be migrated */
3032 + if (!task_on_cpu(rq, i) && !is_migration_disabled(i)) {
3033 3033 p = i;
3034 3034 break;
3035 3035 }
modified kernel/sched/ext/cid.c
@@ -98,16 +98,16 @@ static struct scx_cid_tables *scx_cid_alloc_tables(void)
98 98 u32 npossible = num_possible_cpus();
99 99 struct scx_cid_tables *tbls;
100 100
101 - tbls = kzalloc_obj(*tbls, GFP_KERNEL);
101 + tbls = kzalloc_obj(*tbls);
102 102 if (!tbls)
103 103 return NULL;
104 104
105 - tbls->cid_to_cpu = kvcalloc(npossible, sizeof(*tbls->cid_to_cpu), GFP_KERNEL);
106 - tbls->cpu_to_cid = kvcalloc(nr_cpu_ids, sizeof(*tbls->cpu_to_cid), GFP_KERNEL);
107 - tbls->cid_to_shard = kvcalloc(npossible, sizeof(*tbls->cid_to_shard), GFP_KERNEL);
108 - tbls->shard_node = kvcalloc(npossible, sizeof(*tbls->shard_node), GFP_KERNEL);
109 - tbls->shard_ranges = kvcalloc(npossible, sizeof(*tbls->shard_ranges), GFP_KERNEL);
110 - tbls->topo = kvcalloc(npossible, sizeof(*tbls->topo), GFP_KERNEL);
105 + tbls->cid_to_cpu = kvzalloc_objs(*tbls->cid_to_cpu, npossible);
106 + tbls->cpu_to_cid = kvzalloc_objs(*tbls->cpu_to_cid, nr_cpu_ids);
107 + tbls->cid_to_shard = kvzalloc_objs(*tbls->cid_to_shard, npossible);
108 + tbls->shard_node = kvzalloc_objs(*tbls->shard_node, npossible);
109 + tbls->shard_ranges = kvzalloc_objs(*tbls->shard_ranges, npossible);
110 + tbls->topo = kvzalloc_objs(*tbls->topo, npossible);
111 111
112 112 if (!tbls->cid_to_cpu || !tbls->cpu_to_cid || !tbls->cid_to_shard ||
113 113 !tbls->shard_node || !tbls->shard_ranges || !tbls->topo) {
@@ -490,7 +490,7 @@ __bpf_kfunc void scx_bpf_cid_override(const s32 *cpu_to_cid__arena, u32 cpu_to_c
490 490 * region that arena fault recovery covers.
491 491 */
492 492 alloced = zalloc_cpumask_var(&seen, GFP_KERNEL);
493 - node_counts = kcalloc(nr_node_ids, sizeof(*node_counts), GFP_KERNEL);
493 + node_counts = kzalloc_objs(*node_counts, nr_node_ids);
494 494 if (cpu_to_cid_cnt == nr_cpu_ids)
495 495 cpu_to_cid = kmemdup(cpu_to_cid__arena, cpu_to_cid_cnt * sizeof(s32),
496 496 GFP_KERNEL);
modified kernel/sched/ext/ext.c
@@ -876,9 +876,9 @@ struct task_struct *scx_task_iter_next_locked(struct scx_task_iter *iter)
876 876 * unloading. The init_tasks ("swappers") should be excluded
877 877 * from the iteration because:
878 878 *
879 - * - It's unsafe to use __setschduler_prio() on an init_task to
880 - * determine the sched_class to use as it won't preserve its
881 - * idle_sched_class.
879 + * - It's unsafe to use __setscheduler_class() on an init_task
880 + * to determine the sched_class to use as it won't preserve
881 + * its idle_sched_class.
882 882 *
883 883 * - ops.init/exit_task() can easily be confused if called with
884 884 * init_tasks as they, e.g., share PID 0.
@@ -2806,6 +2806,8 @@ static void dispatch_to_local_dsq(struct scx_sched *sch, struct rq *rq,
2806 2806 * @p: task to finish dispatching
2807 2807 * @qseq_at_dispatch: qseq when @p started getting dispatched
2808 2808 * @dsq_id: destination DSQ ID
2809 + * @slice: slice carried by the insert verdict, 0 keeps the current value
2810 + * @vtime: vtime carried by the insert verdict, committed on PRIQ inserts
2809 2811 * @enq_flags: %SCX_ENQ_*
2810 2812 *
2811 2813 * Dispatching to local DSQs may need to wait for queueing to complete or
@@ -5447,7 +5449,7 @@ static ssize_t scx_attr_caps_show(struct kobject *kobj,
5447 5449 struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj);
5448 5450 u32 npossible = num_possible_cpus();
5449 5451 struct scx_cmask *agg __free(kfree) =
5450 - kzalloc(struct_size(agg, bits, SCX_CMASK_NR_WORDS(npossible)), GFP_KERNEL);
5452 + kzalloc_flex(*agg, bits, SCX_CMASK_NR_WORDS(npossible));
5451 5453 unsigned long *agg_bm __free(bitmap) = bitmap_zalloc(npossible, GFP_KERNEL);
5452 5454 ssize_t count = 0;
5453 5455 s32 cap, si;
@@ -5514,7 +5516,7 @@ static const struct kset_uevent_ops scx_uevent_ops = {
5514 5516 };
5515 5517
5516 5518 /*
5517 - * Used by sched_fork() and __setscheduler_prio() to pick the matching
5519 + * Used by sched_fork() and __setscheduler_class() to pick the matching
5518 5520 * sched_class. dl/rt are already handled.
5519 5521 */
5520 5522 bool task_should_scx(int policy)
@@ -7694,7 +7696,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)
7694 7696 /*
7695 7697 * Enable ops for every task. Fork is excluded by scx_fork_rwsem
7696 7698 * preventing new tasks from being added. No need to exclude tasks
7697 - * leaving as sched_ext_free() can handle both prepped and enabled
7699 + * leaving as sched_ext_dead() can handle both prepped and enabled
7698 7700 * tasks. Prep all tasks first and then enable them with preemption
7699 7701 * disabled.
7700 7702 *
@@ -7786,7 +7788,7 @@ static void scx_root_enable_workfn(struct kthread_work *work)
7786 7788
7787 7789 /*
7788 7790 * We're fully committed and can't fail. The task READY -> ENABLED
7789 - * transitions here are synchronized against sched_ext_free() through
7791 + * transitions here are synchronized against sched_ext_dead() through
7790 7792 * scx_tasks_lock.
7791 7793 */
7792 7794 percpu_down_write(&scx_fork_rwsem);
@@ -8079,6 +8081,7 @@ static int bpf_scx_check_member(const struct btf_type *t,
8079 8081 case offsetof(struct sched_ext_ops, cgroup_init):
8080 8082 case offsetof(struct sched_ext_ops, cgroup_exit):
8081 8083 case offsetof(struct sched_ext_ops, cgroup_prep_move):
8084 + case offsetof(struct sched_ext_ops, cgroup_set_bandwidth):
8082 8085 #endif
8083 8086 case offsetof(struct sched_ext_ops, cpu_online):
8084 8087 case offsetof(struct sched_ext_ops, cpu_offline):
@@ -9003,12 +9006,6 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
9003 9006 if (unlikely(READ_ONCE(sch->aborting)))
9004 9007 return false;
9005 9008
9006 - if (unlikely(!scx_task_on_sched(sch, p))) {
9007 - scx_error(sch, "scx_bpf_dsq_move[_vtime]() on %s[%d] but the task belongs to a different scheduler",
9008 - p->comm, p->pid);
9009 - return false;
9010 - }
9011 -
9012 9009 /*
9013 9010 * Can be called from either ops.dispatch() holding the dispatched rq's
9014 9011 * lock or any context where no rq lock is held. If latter, lock @p's
@@ -9040,6 +9037,17 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
9040 9037 goto out;
9041 9038 }
9042 9039
9040 + /*
9041 + * @p has been on $src_dsq and can't move anymore. If @p is not on @sch,
9042 + * the caller didn't have authority over @p at the time of the call.
9043 + */
9044 + if (unlikely(!scx_task_on_sched(sch, p))) {
9045 + scx_error(sch, "scx_bpf_dsq_move[_vtime]() on %s[%d] but the task belongs to a different scheduler",
9046 + p->comm, p->pid);
9047 + raw_spin_unlock(&src_dsq->lock);
9048 + goto out;
9049 + }
9050 +
9043 9051 /* @p is still on $src_dsq and stable, determine the destination */
9044 9052 dst_dsq = find_dsq_for_dispatch(sch, locked_rq ?: this_rq(), dsq_id, task_cpu(p));
9045 9053
@@ -9765,7 +9773,7 @@ __bpf_kfunc struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *i
9765 9773 * bpf_iter_scx_dsq_destroy - Destroy a DSQ iterator
9766 9774 * @it: iterator to destroy
9767 9775 *
9768 - * Undo scx_iter_scx_dsq_new().
9776 + * Undo bpf_iter_scx_dsq_new().
9769 9777 */
9770 9778 __bpf_kfunc void bpf_iter_scx_dsq_destroy(struct bpf_iter_scx_dsq *it)
9771 9779 {
@@ -11041,3 +11049,16 @@ static int __init scx_init(void)
11041 11049 return 0;
11042 11050 }
11043 11051 __initcall(scx_init);
11052 +
11053 + /*
11054 + * Compatibility markers for userspace. Existence of a marker function
11055 + * represents that the kernel supports that sched-ext feature.
11056 + */
11057 +
11058 + /*
11059 + * scx_compat_marker_cgroup_set_bandwidth_may_sleep: advertises that
11060 + * ops.cgroup_set_bandwidth() may be implemented as a sleepable callback.
11061 + */
11062 + #ifdef CONFIG_EXT_GROUP_SCHED
11063 + DEFINE_SCX_COMPAT_MARKER(cgroup_set_bandwidth_may_sleep);
11064 + #endif /* CONFIG_EXT_GROUP_SCHED */
modified kernel/sched/ext/internal.h
@@ -442,7 +442,7 @@ struct sched_ext_ops {
442 442 *
443 443 * Note that this callback may be called from a CPU other than the
444 444 * one the task is going to run on. This can happen when a task
445 - * property is changed (i.e., affinity), since scx_next_task_scx(),
445 + * property is changed (i.e., affinity), since set_next_task_scx(),
446 446 * which triggers this callback, may run on a CPU different from
447 447 * the task's assigned CPU.
448 448 *
@@ -753,7 +753,7 @@ struct sched_ext_ops {
753 753 * @burst_us: bandwidth control burst
754 754 *
755 755 * Update @cgrp's bandwidth control parameters. This is from the cpu.max
756 - * cgroup interface.
756 + * cgroup interface. This operation may block.
757 757 *
758 758 * @quota_us / @period_us determines the CPU bandwidth @cgrp is entitled
759 759 * to. For example, if @period_us is 1_000_000 and @quota_us is
@@ -2001,6 +2001,27 @@ struct scx_bstr_buf {
2001 2001 char line[SCX_EXIT_MSG_LEN];
2002 2002 };
2003 2003
2004 + /* Internal helper for DEFINE_SCX_COMPAT_MARKER(). */
2005 + #define DECLARE_SCX_COMPAT_MARKER(func) \
2006 + extern void scx_compat_marker_##func(void)
2007 +
2008 + /**
2009 + * DEFINE_SCX_COMPAT_MARKER() - define a userspace capability marker
2010 + * @func: marker suffix; the defined symbol is scx_compat_marker_@func
2011 + *
2012 + * Emit an empty, callerless function that is retained in the kernel's BTF.
2013 + * Its presence is part of the kernel<->userspace contract: userspace probes
2014 + * scx_compat_marker_@func (e.g. via BTF) to detect that this kernel supports
2015 + * the corresponding feature.
2016 + *
2017 + * The leading declaration suppresses the missing-prototype warning; the
2018 + * trailing declaration consumes the semicolon at the use site.
2019 + */
2020 + #define DEFINE_SCX_COMPAT_MARKER(func) \
2021 + DECLARE_SCX_COMPAT_MARKER(func); \
2022 + __used __retain void scx_compat_marker_##func(void) {} \
2023 + DECLARE_SCX_COMPAT_MARKER(func)
2024 +
2004 2025 extern struct scx_sched __rcu *scx_root;
2005 2026 DECLARE_PER_CPU(struct rq *, scx_locked_rq_state);
2006 2027
modified kernel/sched/ext/sub.c
@@ -194,7 +194,7 @@ s32 scx_alloc_pshards(struct scx_sched *sch)
194 194 shard_node = rcu_dereference_protected(scx_shard_node,
195 195 lockdep_is_held(&scx_enable_mutex));
196 196
197 - pshard = kzalloc_objs(pshard[0], scx_nr_cid_shards, GFP_KERNEL);
197 + pshard = kzalloc_objs(pshard[0], scx_nr_cid_shards);
198 198 if (!pshard)
199 199 return -ENOMEM;
200 200
modified kernel/sched/fair.c
@@ -6978,14 +6978,14 @@ static int tg_throttle_down(struct task_group *tg, void *data)
6978 6978 static bool throttle_cfs_rq(struct cfs_rq *cfs_rq)
6979 6979 {
6980 6980 struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(cfs_rq->tg);
6981 - struct sched_entity *curr = cfs_rq->curr;
6981 + struct sched_entity *curr = cfs_rq->h_curr;
6982 6982 struct rq *rq = rq_of(cfs_rq);
6983 6983
6984 6984 scoped_guard(raw_spinlock, &cfs_b->lock) {
6985 6985 u64 target_runtime = 1;
6986 6986
6987 6987 /*
6988 - * If cfs_rq->curr is still runnable, we are here from an
6988 + * If cfs_rq->h_curr is still runnable, we are here from an
6989 6989 * update_curr(). Request sysctl_sched_cfs_bandwidth_slice
6990 6990 * worth of bandwidth to continue running.
6991 6991 *
@@ -7192,7 +7192,7 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
7192 7192 if (!list_empty(&cfs_rq->throttled_csd_list))
7193 7193 continue;
7194 7194
7195 - if (cfs_rq->curr) {
7195 + if (cfs_rq->h_curr) {
7196 7196 update_rq_clock(rq);
7197 7197 update_curr(cfs_rq);
7198 7198 }
@@ -10057,7 +10057,7 @@ again:
10057 10057
10058 10058 /* Might not have done put_prev_entity() */
10059 10059 if (cfs_rq->curr && cfs_rq->curr->on_rq)
10060 - update_curr(cfs_rq);
10060 + update_curr_eevdf(cfs_rq);
10061 10061
10062 10062 se = pick_next_entity(rq, true);
10063 10063 if (!se)
@@ -10160,7 +10160,7 @@ static void yield_task_fair(struct rq *rq)
10160 10160 /*
10161 10161 * Update run-time statistics of the 'current'.
10162 10162 */
10163 - update_curr(cfs_rq);
10163 + update_curr_eevdf(cfs_rq);
10164 10164 /*
10165 10165 * Tell update_rq_clock() that we've just updated,
10166 10166 * so we don't do microscopic update in schedule()
@@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu,
10691 10691 return mig_llc;
10692 10692 }
10693 10693
10694 + static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p)
10695 + {
10696 + /*
10697 + * On asymmetric CPU capacity domains, do not let cache-aware
10698 + * balancing pull the task onto a destination CPU that cannot
10699 + * accommodate it. Doing so would turn the task into a misfit on
10700 + * the destination, trading a cache-locality gain for a capacity
10701 + * loss. If the task already does not fit its source CPU, the move
10702 + * cannot make things worse, so let the LLC preference decide.
10703 + */
10704 + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p &&
10705 + !task_fits_cpu(p, env->dst_cpu) &&
10706 + task_fits_cpu(p, env->src_cpu))
10707 + return true;
10708 +
10709 + return false;
10710 + }
10711 +
10694 10712 /*
10695 10713 * Check if task p can migrate from source LLC to
10696 10714 * destination LLC in terms of cache aware load balance.
10697 10715 */
10698 - static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
10716 + static enum llc_mig can_migrate_llc_task(struct lb_env *env,
10699 10717 struct task_struct *p)
10700 10718 {
10701 10719 struct mm_struct *mm;
10702 10720 bool to_pref;
10703 - int cpu;
10721 + int cpu, src_cpu, dst_cpu;
10722 +
10723 + if (task_misfits_asym_cpu(env, p))
10724 + return mig_forbid;
10704 10725
10726 + src_cpu = env->src_cpu;
10727 + dst_cpu = env->dst_cpu;
10705 10728 mm = p->mm;
10706 10729 if (!mm)
10707 10730 return mig_unrestricted;
@@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env)
10758 10781 unsigned long util = 0;
10759 10782 struct task_struct *cur;
10760 10783
10784 + /*
10785 + * Migrating misfit tasks from current CPU
10786 + * to CPU with a better fit.
10787 + * Prioritize that over LLC preference.
10788 + */
10789 + if (env->migration_type == migrate_misfit)
10790 + return false;
10791 +
10761 10792 if (env->src_rq->nr_running <= 1)
10762 10793 return true;
10763 10794
@@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env)
10765 10796 if (cur && cur->sched_class == &fair_sched_class)
10766 10797 util = task_util(cur);
10767 10798
10768 - if (can_migrate_llc(env->src_cpu, env->dst_cpu,
10799 + if (task_misfits_asym_cpu(env, cur) ||
10800 + can_migrate_llc(env->src_cpu, env->dst_cpu,
10769 10801 util, false) == mig_forbid)
10770 10802 return true;
10771 10803 }
@@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env)
10805 10837 READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu))
10806 10838 return true;
10807 10839
10808 - if (can_migrate_llc_task(env->src_cpu,
10809 - env->dst_cpu, p) != mig_forbid)
10840 + if (can_migrate_llc_task(env, p) != mig_forbid)
10810 10841 return false;
10811 10842
10812 10843 return true;
@@ -11869,6 +11900,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs,
11869 11900 if (env->sd->flags & SD_SHARE_LLC)
11870 11901 return false;
11871 11902
11903 + /*
11904 + * On asymmetric domains, group_misfit_task_load
11905 + * should be prioritized to move tasks to CPU that fit them
11906 + * over aggregating tasks to their preferred LLC.
11907 + */
11908 + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
11909 + sgs->group_misfit_task_load)
11910 + return false;
11911 +
11872 11912 /*
11873 11913 * Skip cache aware tagging if nr_balanced_failed is sufficiently high.
11874 11914 * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed
modified kernel/sched/rt.c
@@ -1872,8 +1872,8 @@ static struct task_struct *pick_next_pushable_task(struct rq *rq)
1872 1872 return NULL;
1873 1873
1874 1874 plist_for_each_entry(i, head, pushable_tasks) {
1875 - /* make sure task isn't on_cpu (possible with proxy-exec) */
1876 - if (!task_on_cpu(rq, i)) {
1875 + /* skip tasks that cannot be migrated */
1876 + if (!task_on_cpu(rq, i) && !is_migration_disabled(i)) {
1877 1877 p = i;
1878 1878 break;
1879 1879 }
modified kernel/softirq.c
@@ -91,11 +91,11 @@ EXPORT_PER_CPU_SYMBOL_GPL(hardirq_context);
91 91
92 92 DEFINE_PER_CPU(unsigned long, local_interrupt_disable_state);
93 93
94 - void _local_interrupt_disable(void)
94 + void _local_interrupt_save_state(unsigned long flags)
95 95 {
96 - __local_interrupt_disable();
96 + __local_interrupt_save_state(flags);
97 97 }
98 - EXPORT_SYMBOL(_local_interrupt_disable);
98 + EXPORT_SYMBOL(_local_interrupt_save_state);
99 99
100 100 void _local_interrupt_enable(void)
101 101 {
@@ -749,16 +749,7 @@ static inline void __irq_exit_rcu(void)
749 749 #endif
750 750 account_hardirq_exit(current);
751 751 preempt_count_sub(HARDIRQ_OFFSET);
752 - /*
753 - * Interrupts may happen between hardirq_disable_enter() and
754 - * local_irq_save() in local_interrupt_disable(), if irq_exit() invokes
755 - * softirq here, we may have a softirq handler calling
756 - * local_interrupt_disable() but it won't disable the IRQ because
757 - * hardirq disabling count is already 1, hence we need to prevent
758 - * invoking softirq when a local_interrupt_disable() is ongoing.
759 - */
760 - if (!in_interrupt() && !hardirq_disable_count() &&
761 - local_softirq_pending()) {
752 + if (!in_interrupt() && local_softirq_pending()) {
762 753 /*
763 754 * If we left hrtimers unarmed, make sure to arm them now,
764 755 * before enabling interrupts to run softirq.
modified kernel/trace/fprobe.c
@@ -945,7 +945,7 @@ int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter
945 945 if (num < 0)
946 946 return num;
947 947
948 - addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL);
948 + addrs = kzalloc_objs(*addrs, num);
949 949 if (!addrs)
950 950 return -ENOMEM;
951 951
modified kernel/trace/ftrace.c
@@ -75,6 +75,8 @@
75 75 .func_hash = &opsname.local_hash, \
76 76 .local_hash.regex_lock = __MUTEX_INITIALIZER(opsname.local_hash.regex_lock), \
77 77 .subop_list = LIST_HEAD_INIT(opsname.subop_list),
78 + /* Used only to synchronize the initialization of ftrace_ops */
79 + static DEFINE_MUTEX(ops_mutex);
78 80 #else
79 81 #define INIT_OPS_HASH(opsname)
80 82 #endif
@@ -159,11 +161,18 @@ const struct ftrace_ops ftrace_nop_ops = {
159 161 static inline void ftrace_ops_init(struct ftrace_ops *ops)
160 162 {
161 163 #ifdef CONFIG_DYNAMIC_FTRACE
162 - if (!(ops->flags & FTRACE_OPS_FL_INITIALIZED)) {
164 + unsigned long flags = smp_load_acquire(&ops->flags);
165 +
166 + if (!(flags & FTRACE_OPS_FL_INITIALIZED)) {
167 + guard(mutex)(&ops_mutex);
168 + /* Could have been initialized before lock taken */
169 + if (unlikely(ops->flags & FTRACE_OPS_FL_INITIALIZED))
170 + return;
163 171 mutex_init(&ops->local_hash.regex_lock);
164 172 INIT_LIST_HEAD(&ops->subop_list);
165 173 ops->func_hash = &ops->local_hash;
166 - ops->flags |= FTRACE_OPS_FL_INITIALIZED;
174 + flags = ops->flags | FTRACE_OPS_FL_INITIALIZED;
175 + smp_store_release(&ops->flags, flags);
167 176 }
168 177 #endif
169 178 }
@@ -4677,7 +4686,8 @@ ftrace_avail_addrs_open(struct inode *inode, struct file *file)
4677 4686
4678 4687 /**
4679 4688 * ftrace_regex_open - initialize function tracer filter files
4680 - * @ops: The ftrace_ops that hold the hash filters
4689 + * @tr: The trace_array that holds the ftrace_ops [optional]
4690 + * @ops: The ftrace_ops that hold the hash filters [optional]
4681 4691 * @flag: The type of filter to process
4682 4692 * @inode: The inode, usually passed in to your open routine
4683 4693 * @file: The file, usually passed in to your open routine
@@ -4691,26 +4701,45 @@ ftrace_avail_addrs_open(struct inode *inode, struct file *file)
4691 4701 * tracing_lseek() should be used as the lseek routine, and
4692 4702 * release must call ftrace_regex_release().
4693 4703 *
4704 + * Note, If @tr is not NULL, its reference has to be taken before
4705 + * @ops may be referenced.
4706 + * If @ops is NULL and @tr is not, then @tr->ops is used.
4707 + * If @tr is NULL and @ops is not then @ops->private is uesd for @tr.
4708 + * If both @tr and @ops are NULL, then the &global_ops is
4709 + * to be used, and @tr will be the global_ops.private pointer.
4710 + *
4694 4711 * Returns: 0 on success or a negative errno value on failure
4695 4712 */
4696 4713 int
4697 - ftrace_regex_open(struct ftrace_ops *ops, int flag,
4714 + ftrace_regex_open(struct trace_array *tr, struct ftrace_ops *ops, int flag,
4698 4715 struct inode *inode, struct file *file)
4699 4716 {
4700 - struct ftrace_iterator *iter;
4717 + struct ftrace_iterator *iter = NULL;
4701 4718 struct ftrace_hash *hash;
4702 4719 struct list_head *mod_head;
4703 - struct trace_array *tr = ops->private;
4704 - int ret = -ENOMEM;
4705 -
4706 - ftrace_ops_init(ops);
4720 + int ret = -ENODEV;
4707 4721
4708 4722 if (unlikely(ftrace_disabled))
4709 4723 return -ENODEV;
4710 4724
4725 + if (!tr) {
4726 + if (!ops)
4727 + ops = &global_ops;
4728 + tr = ops->private;
4729 + }
4730 +
4711 4731 if (tracing_check_open_get_tr(tr))
4712 4732 return -ENODEV;
4713 4733
4734 + if (!ops)
4735 + ops = tr->ops;
4736 +
4737 + if (WARN_ON_ONCE(!ops))
4738 + goto out;
4739 +
4740 + ftrace_ops_init(ops);
4741 +
4742 + ret = -ENOMEM;
4714 4743 iter = kzalloc_obj(*iter);
4715 4744 if (!iter)
4716 4745 goto out;
@@ -4788,21 +4817,19 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
4788 4817 static int
4789 4818 ftrace_filter_open(struct inode *inode, struct file *file)
4790 4819 {
4791 - struct ftrace_ops *ops = inode->i_private;
4820 + struct trace_array *tr = inode->i_private;
4792 4821
4793 - /* Checks for tracefs lockdown */
4794 - return ftrace_regex_open(ops,
4795 - FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
4796 - inode, file);
4822 + return ftrace_regex_open(tr, NULL,
4823 + FTRACE_ITER_FILTER | FTRACE_ITER_DO_PROBES,
4824 + inode, file);
4797 4825 }
4798 4826
4799 4827 static int
4800 4828 ftrace_notrace_open(struct inode *inode, struct file *file)
4801 4829 {
4802 - struct ftrace_ops *ops = inode->i_private;
4830 + struct trace_array *tr = inode->i_private;
4803 4831
4804 - /* Checks for tracefs lockdown */
4805 - return ftrace_regex_open(ops, FTRACE_ITER_NOTRACE,
4832 + return ftrace_regex_open(tr, NULL, FTRACE_ITER_NOTRACE,
4806 4833 inode, file);
4807 4834 }
4808 4835
@@ -7492,15 +7519,15 @@ static const struct file_operations ftrace_graph_notrace_fops = {
7492 7519 };
7493 7520 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
7494 7521
7495 - void ftrace_create_filter_files(struct ftrace_ops *ops,
7522 + void ftrace_create_filter_files(struct trace_array *tr,
7496 7523 struct dentry *parent)
7497 7524 {
7498 7525
7499 7526 trace_create_file("set_ftrace_filter", TRACE_MODE_WRITE, parent,
7500 - ops, &ftrace_filter_fops);
7527 + tr, &ftrace_filter_fops);
7501 7528
7502 7529 trace_create_file("set_ftrace_notrace", TRACE_MODE_WRITE, parent,
7503 - ops, &ftrace_notrace_fops);
7530 + tr, &ftrace_notrace_fops);
7504 7531 }
7505 7532
7506 7533 /*
@@ -7525,7 +7552,6 @@ void ftrace_destroy_filter_files(struct ftrace_ops *ops)
7525 7552
7526 7553 static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer)
7527 7554 {
7528 -
7529 7555 trace_create_file("available_filter_functions", TRACE_MODE_READ,
7530 7556 d_tracer, NULL, &ftrace_avail_fops);
7531 7557
@@ -7538,7 +7564,7 @@ static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer)
7538 7564 trace_create_file("touched_functions", TRACE_MODE_READ,
7539 7565 d_tracer, NULL, &ftrace_touched_fops);
7540 7566
7541 - ftrace_create_filter_files(&global_ops, d_tracer);
7567 + ftrace_create_filter_files(NULL, d_tracer);
7542 7568
7543 7569 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7544 7570 trace_create_file("set_graph_function", TRACE_MODE_WRITE, d_tracer,
modified kernel/trace/ring_buffer.c
@@ -330,6 +330,14 @@ struct buffer_data_read_page {
330 330 struct buffer_data_page *data; /* actual data, stored in this page */
331 331 };
332 332
333 + static __always_inline unsigned int rb_read_page_capacity(struct buffer_data_read_page *rpage)
334 + {
335 + return (PAGE_SIZE << rpage->order) - BUF_PAGE_HDR_SIZE;
336 + }
337 +
338 + /* The number of bits for static buffer ids */
339 + #define RB_STATIC_BITS 30
340 +
333 341 /*
334 342 * Note, the buffer_page list must be first. The buffer pages
335 343 * are allocated in cache lines, which means that each buffer
@@ -345,7 +353,7 @@ struct buffer_page {
345 353 local_t entries; /* entries on this page */
346 354 unsigned long real_end; /* real end of data */
347 355 unsigned order; /* order of the page */
348 - u32 id:30; /* ID for external mapping */
356 + u32 id:RB_STATIC_BITS; /* ID for external mapping */
349 357 u32 range:1; /* Mapped via a range */
350 358 struct buffer_data_page *page; /* Actual data page */
351 359 };
@@ -652,6 +660,15 @@ static bool rb_is_static(struct ring_buffer_per_cpu *cpu_buffer)
652 660 return cpu_buffer->user_mapped || cpu_buffer->remote || cpu_buffer->ring_meta;
653 661 }
654 662
663 + static unsigned long rb_static_max_pages(void)
664 + {
665 + /*
666 + * Static ring buffers are using bpage::id and must account for the
667 + * reader page.
668 + */
669 + return (1UL << RB_STATIC_BITS) - 1;
670 + }
671 +
655 672 struct ring_buffer_iter {
656 673 struct ring_buffer_per_cpu *cpu_buffer;
657 674 unsigned long head;
@@ -1669,7 +1686,7 @@ out_locked:
1669 1686 * This is used to help find the next per cpu subbuffer within a mapped range.
1670 1687 */
1671 1688 static unsigned long
1672 - rb_range_align_subbuf(unsigned long addr, int subbuf_size, int nr_subbufs)
1689 + rb_range_align_subbuf(unsigned long addr, unsigned int subbuf_size, unsigned long nr_subbufs)
1673 1690 {
1674 1691 addr += sizeof(struct ring_buffer_cpu_meta) +
1675 1692 sizeof(int) * nr_subbufs;
@@ -1679,13 +1696,12 @@ rb_range_align_subbuf(unsigned long addr, int subbuf_size, int nr_subbufs)
1679 1696 /*
1680 1697 * Return the ring_buffer_meta for a given @cpu.
1681 1698 */
1682 - static void *rb_range_meta(struct trace_buffer *buffer, int nr_pages, int cpu)
1699 + static void *rb_range_meta(struct trace_buffer *buffer, unsigned long nr_pages, int cpu)
1683 1700 {
1684 - int subbuf_size = rb_subbuf_size(buffer);
1701 + unsigned int subbuf_size = rb_subbuf_size(buffer);
1685 1702 struct ring_buffer_cpu_meta *meta;
1686 1703 struct ring_buffer_meta *bmeta;
1687 - unsigned long ptr;
1688 - int nr_subbufs;
1704 + unsigned long ptr, nr_subbufs;
1689 1705
1690 1706 bmeta = buffer->meta;
1691 1707 if (!bmeta)
@@ -1731,7 +1747,7 @@ static void *rb_range_meta(struct trace_buffer *buffer, int nr_pages, int cpu)
1731 1747 /* Return the start of subbufs given the meta pointer */
1732 1748 static void *rb_subbufs_from_meta(struct ring_buffer_cpu_meta *meta)
1733 1749 {
1734 - int subbuf_size = meta->subbuf_size;
1750 + unsigned int subbuf_size = meta->subbuf_size;
1735 1751 unsigned long ptr;
1736 1752
1737 1753 ptr = (unsigned long)meta;
@@ -1743,11 +1759,11 @@ static void *rb_subbufs_from_meta(struct ring_buffer_cpu_meta *meta)
1743 1759 /*
1744 1760 * Return a specific sub-buffer for a given @cpu defined by @idx.
1745 1761 */
1746 - static void *rb_range_buffer(struct ring_buffer_per_cpu *cpu_buffer, int idx)
1762 + static void *rb_range_buffer(struct ring_buffer_per_cpu *cpu_buffer, unsigned long idx)
1747 1763 {
1748 1764 struct ring_buffer_cpu_meta *meta;
1765 + unsigned int subbuf_size;
1749 1766 unsigned long ptr;
1750 - int subbuf_size;
1751 1767
1752 1768 meta = rb_range_meta(cpu_buffer->buffer, 0, cpu_buffer->cpu);
1753 1769 if (!meta)
@@ -1763,7 +1779,7 @@ static void *rb_range_buffer(struct ring_buffer_per_cpu *cpu_buffer, int idx)
1763 1779
1764 1780 ptr = (unsigned long)rb_subbufs_from_meta(meta);
1765 1781
1766 - ptr += subbuf_size * idx;
1782 + ptr += (unsigned long)subbuf_size * idx;
1767 1783 if (ptr + subbuf_size > cpu_buffer->buffer->range_addr_end)
1768 1784 return NULL;
1769 1785
@@ -1840,13 +1856,12 @@ static bool rb_meta_init(struct trace_buffer *buffer, int scratch_size)
1840 1856 * must be the same.
1841 1857 */
1842 1858 static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,
1843 - struct trace_buffer *buffer, int nr_pages,
1859 + struct trace_buffer *buffer, unsigned long nr_pages,
1844 1860 unsigned long *subbuf_mask)
1845 1861 {
1846 - int subbuf_size = PAGE_SIZE;
1847 1862 unsigned long buffers_start;
1848 1863 unsigned long buffers_end;
1849 - int i;
1864 + unsigned long i;
1850 1865
1851 1866 if (!subbuf_mask)
1852 1867 return false;
@@ -1856,8 +1871,13 @@ static bool rb_cpu_meta_valid(struct ring_buffer_cpu_meta *meta, int cpu,
1856 1871 return false;
1857 1872 }
1858 1873
1874 + if (meta->nr_subbufs != nr_pages + 1) {
1875 + pr_info("Ring buffer boot meta [%d] invalid nr_subbufs\n", cpu);
1876 + return false;
1877 + }
1878 +
1859 1879 buffers_start = meta->first_buffer;
1860 - buffers_end = meta->first_buffer + (subbuf_size * meta->nr_subbufs);
1880 + buffers_end = meta->first_buffer + (meta->nr_subbufs * PAGE_SIZE);
1861 1881
1862 1882 /* Is the head and commit buffers within the range of buffers? */
1863 1883 if (meta->head_buffer < buffers_start ||
@@ -2095,8 +2115,8 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
2095 2115 struct buffer_page *head_page, *orig_head, *orig_reader;
2096 2116 struct rb_validation_state state = { 0 };
2097 2117 bool skip = false;
2118 + unsigned long i;
2098 2119 int ret;
2099 - int i;
2100 2120
2101 2121 if (!meta || !meta->head_buffer)
2102 2122 return;
@@ -2147,7 +2167,7 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
2147 2167 rb_validate_buffer(head_page, cpu_buffer, meta, &state, 0, state.ts);
2148 2168 }
2149 2169 if (i)
2150 - pr_info("Ring buffer [%d] rewound %d pages\n", cpu_buffer->cpu, i);
2170 + pr_info("Ring buffer [%d] rewound %lu pages\n", cpu_buffer->cpu, i);
2151 2171
2152 2172 /* The last rewound page must be skipped. */
2153 2173 if (head_page != orig_head)
@@ -2231,7 +2251,8 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
2231 2251 }
2232 2252 }
2233 2253
2234 - static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages, int scratch_size)
2254 + static void rb_range_meta_init(struct trace_buffer *buffer, unsigned long nr_pages,
2255 + int scratch_size)
2235 2256 {
2236 2257 struct ring_buffer_cpu_meta *meta;
2237 2258 unsigned long *subbuf_mask;
@@ -2331,8 +2352,8 @@ static int rbm_show(struct seq_file *m, void *v)
2331 2352 rb_meta_subbuf_idx(meta, (void *)meta->head_buffer));
2332 2353 seq_printf(m, "commit_buffer: %d\n",
2333 2354 rb_meta_subbuf_idx(meta, (void *)meta->commit_buffer));
2334 - seq_printf(m, "subbuf_size: %d\n", meta->subbuf_size);
2335 - seq_printf(m, "nr_subbufs: %d\n", meta->nr_subbufs);
2355 + seq_printf(m, "subbuf_size: %u\n", meta->subbuf_size);
2356 + seq_printf(m, "nr_subbufs: %u\n", meta->nr_subbufs);
2336 2357 return 0;
2337 2358 }
2338 2359
@@ -2417,7 +2438,7 @@ static void *ring_buffer_desc_page(struct ring_buffer_desc *desc, unsigned int p
2417 2438 }
2418 2439
2419 2440 static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2420 - long nr_pages, struct list_head *pages)
2441 + unsigned long nr_pages, struct list_head *pages)
2421 2442 {
2422 2443 struct trace_buffer *buffer = cpu_buffer->buffer;
2423 2444 struct ring_buffer_cpu_meta *meta = NULL;
@@ -2545,7 +2566,7 @@ static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2545 2566 }
2546 2567
2547 2568 static struct ring_buffer_per_cpu *
2548 - rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)
2569 + rb_allocate_cpu_buffer(struct trace_buffer *buffer, unsigned long nr_pages, int cpu)
2549 2570 {
2550 2571 struct ring_buffer_per_cpu *cpu_buffer __free(kfree) =
2551 2572 alloc_cpu_buffer(cpu);
@@ -2600,8 +2621,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)
2600 2621 cpu_buffer->remote = buffer->remote;
2601 2622 cpu_buffer->meta_page = (struct trace_buffer_meta *)(void *)desc->meta_va;
2602 2623 cpu_buffer->nr_pages = nr_pages;
2603 - cpu_buffer->subbuf_ids = kcalloc(cpu_buffer->nr_pages + 1,
2604 - sizeof(*cpu_buffer->subbuf_ids), GFP_KERNEL);
2624 + cpu_buffer->subbuf_ids = kzalloc_objs(*cpu_buffer->subbuf_ids,
2625 + cpu_buffer->nr_pages + 1);
2605 2626 if (!cpu_buffer->subbuf_ids)
2606 2627 goto fail_free_reader;
2607 2628
@@ -2702,8 +2723,8 @@ static void rb_test_inject_invalid_pages(struct trace_buffer *buffer)
2702 2723 struct ring_buffer_cpu_meta *meta;
2703 2724 struct buffer_data_page *dpage;
2704 2725 unsigned long entry_bytes = 0;
2726 + unsigned int subbuf_size;
2705 2727 unsigned long ptr;
2706 - int subbuf_size;
2707 2728 int invalid = 0;
2708 2729 int cpu;
2709 2730 int i;
@@ -2773,8 +2794,8 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
2773 2794 struct ring_buffer_remote *remote)
2774 2795 {
2775 2796 struct trace_buffer *buffer __free(kfree) = NULL;
2776 - long nr_pages;
2777 - int subbuf_size;
2797 + unsigned int subbuf_size;
2798 + unsigned long nr_pages;
2778 2799 int bsize;
2779 2800 int cpu;
2780 2801 int ret;
@@ -2828,6 +2849,8 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
2828 2849 size = end - buffers_start;
2829 2850 size = size / nr_cpu_ids;
2830 2851
2852 + if (size < sizeof(struct ring_buffer_cpu_meta))
2853 + goto fail_free_buffers;
2831 2854 /*
2832 2855 * The number of sub-buffers (nr_pages) is determined by the
2833 2856 * total size allocated minus the meta data size.
@@ -2837,6 +2860,10 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
2837 2860 */
2838 2861 nr_pages = (size - sizeof(struct ring_buffer_cpu_meta)) /
2839 2862 (subbuf_size + sizeof(int));
2863 +
2864 + if (nr_pages > rb_static_max_pages())
2865 + goto fail_free_buffers;
2866 +
2840 2867 /* Need at least two pages plus the reader page */
2841 2868 if (nr_pages < 3)
2842 2869 goto fail_free_buffers;
@@ -2869,6 +2896,10 @@ static struct trace_buffer *alloc_buffer(unsigned long size, unsigned flags,
2869 2896 /* The writer is remote. This ring-buffer is read-only */
2870 2897 atomic_inc(&buffer->record_disabled);
2871 2898 nr_pages = desc->nr_page_va - 1;
2899 +
2900 + if (nr_pages > rb_static_max_pages())
2901 + goto fail_free_buffers;
2902 +
2872 2903 if (nr_pages < 2)
2873 2904 goto fail_free_buffers;
2874 2905 } else {
@@ -5853,12 +5884,12 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
5853 5884 static struct buffer_page *
5854 5885 __rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
5855 5886 {
5856 - int max_loops = cpu_buffer->ring_meta ? cpu_buffer->nr_pages : 3;
5887 + unsigned long max_loops = cpu_buffer->ring_meta ? cpu_buffer->nr_pages : 3;
5857 5888 struct buffer_page *reader = NULL;
5889 + unsigned long nr_loops = 0;
5858 5890 unsigned long overwrite;
5859 5891 unsigned long flags;
5860 5892 int missed_events = 0;
5861 - int nr_loops = 0;
5862 5893 bool ret;
5863 5894
5864 5895 local_irq_save(flags);
@@ -6176,8 +6207,8 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
6176 6207 struct trace_buffer *buffer;
6177 6208 struct ring_buffer_per_cpu *cpu_buffer;
6178 6209 struct ring_buffer_event *event;
6179 - int nr_loops = 0;
6180 - int max_loops;
6210 + unsigned long nr_loops = 0;
6211 + unsigned long max_loops;
6181 6212
6182 6213 if (ts)
6183 6214 *ts = 0;
@@ -6993,56 +7024,78 @@ EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu);
6993 7024 * ring_buffer_alloc_read_page - allocate a page to read from buffer
6994 7025 * @buffer: the buffer to allocate for.
6995 7026 * @cpu: the cpu buffer to allocate.
7027 + * @rpage: pointer to pass in an already allocated page (can be NULL)
7028 + * and returns the allocated page.
6996 7029 *
6997 - * This function is used in conjunction with ring_buffer_read_page.
7030 + * This function is used in conjunction with ring_buffer_read_page().
6998 7031 * When reading a full page from the ring buffer, these functions
6999 7032 * can be used to speed up the process. The calling function should
7000 7033 * allocate a few pages first with this function. Then when it
7001 7034 * needs to get pages from the ring buffer, it passes the result
7002 - * of this function into ring_buffer_read_page, which will swap
7035 + * of this function into ring_buffer_read_page(), which will swap
7003 7036 * the page that was allocated, with the read page of the buffer.
7004 7037 *
7038 + * If @rpage is provided, and it has a different order than the current
7039 + * subbuffer order, its payload will be freed and re-allocated. If it
7040 + * already matches the order, it is simply returned.
7041 + *
7005 7042 * Returns:
7006 - * The page allocated, or ERR_PTR
7043 + * 0 on success, < 0 on error
7007 7044 */
7008 - struct buffer_data_read_page *
7009 - ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu)
7045 + int ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu,
7046 + struct buffer_data_read_page **rpage)
7010 7047 {
7011 7048 struct ring_buffer_per_cpu *cpu_buffer;
7012 - struct buffer_data_read_page *bpage = NULL;
7013 7049 unsigned long flags;
7050 + unsigned int order;
7014 7051
7015 7052 if (!cpumask_test_cpu(cpu, buffer->cpumask))
7016 - return ERR_PTR(-ENODEV);
7053 + return -ENODEV;
7017 7054
7018 - bpage = kzalloc_obj(*bpage);
7019 - if (!bpage)
7020 - return ERR_PTR(-ENOMEM);
7055 + if (!rpage)
7056 + return -EINVAL;
7021 7057
7022 - bpage->order = buffer->subbuf_order;
7058 + order = READ_ONCE(buffer->subbuf_order);
7059 +
7060 + if (*rpage) {
7061 + if ((*rpage)->order == order)
7062 + return 0;
7063 +
7064 + /* We can reuse rpage, but we discard the payload */
7065 + free_pages((unsigned long)(*rpage)->data, (*rpage)->order);
7066 + (*rpage)->data = NULL;
7067 + } else {
7068 + *rpage = kzalloc_obj(**rpage);
7069 + if (!*rpage)
7070 + return -ENOMEM;
7071 + }
7072 +
7073 + (*rpage)->order = order;
7023 7074 cpu_buffer = buffer->buffers[cpu];
7075 +
7024 7076 local_irq_save(flags);
7025 7077 arch_spin_lock(&cpu_buffer->lock);
7026 7078
7027 7079 if (cpu_buffer->free_page.data) {
7028 - *bpage = cpu_buffer->free_page;
7080 + **rpage = cpu_buffer->free_page;
7029 7081 cpu_buffer->free_page.data = NULL;
7030 7082 }
7031 7083
7032 7084 arch_spin_unlock(&cpu_buffer->lock);
7033 7085 local_irq_restore(flags);
7034 7086
7035 - if (bpage->data) {
7036 - rb_init_data_page(bpage->data);
7087 + if ((*rpage)->data) {
7088 + rb_init_data_page((*rpage)->data);
7037 7089 } else {
7038 - bpage->data = alloc_cpu_data(cpu, bpage->order);
7039 - if (!bpage->data) {
7040 - kfree(bpage);
7041 - return ERR_PTR(-ENOMEM);
7090 + (*rpage)->data = alloc_cpu_data(cpu, (*rpage)->order);
7091 + if (!(*rpage)->data) {
7092 + kfree(*rpage);
7093 + *rpage = NULL;
7094 + return -ENOMEM;
7042 7095 }
7043 7096 }
7044 7097
7045 - return bpage;
7098 + return 0;
7046 7099 }
7047 7100 EXPORT_SYMBOL_GPL(ring_buffer_alloc_read_page);
7048 7101
@@ -7050,21 +7103,30 @@ EXPORT_SYMBOL_GPL(ring_buffer_alloc_read_page);
7050 7103 * ring_buffer_free_read_page - free an allocated read page
7051 7104 * @buffer: the buffer the page was allocate for
7052 7105 * @cpu: the cpu buffer the page came from
7053 - * @data_page: the page to free
7106 + * @rpage: the buffer_data_read_page to free
7054 7107 *
7055 7108 * Free a page allocated from ring_buffer_alloc_read_page.
7056 7109 */
7057 7110 void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu,
7058 - struct buffer_data_read_page *data_page)
7111 + struct buffer_data_read_page *rpage)
7059 7112 {
7060 7113 struct ring_buffer_per_cpu *cpu_buffer;
7061 - struct buffer_data_page *dpage = data_page->data;
7062 - struct page *page = virt_to_page(dpage);
7114 + struct buffer_data_page *dpage;
7063 7115 unsigned long flags;
7116 + struct page *page;
7064 7117
7065 7118 if (!buffer || !buffer->buffers || !buffer->buffers[cpu])
7066 7119 return;
7067 7120
7121 + if (!rpage)
7122 + return;
7123 +
7124 + dpage = rpage->data;
7125 + if (!dpage)
7126 + goto out;
7127 +
7128 + page = virt_to_page(dpage);
7129 +
7068 7130 cpu_buffer = buffer->buffers[cpu];
7069 7131
7070 7132 /*
@@ -7072,14 +7134,14 @@ void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu,
7072 7134 * is different from the subbuffer order of the buffer -
7073 7135 * we can't reuse it
7074 7136 */
7075 - if (page_ref_count(page) > 1 || data_page->order != buffer->subbuf_order)
7137 + if (page_ref_count(page) > 1 || rpage->order != READ_ONCE(buffer->subbuf_order))
7076 7138 goto out;
7077 7139
7078 7140 local_irq_save(flags);
7079 7141 arch_spin_lock(&cpu_buffer->lock);
7080 7142
7081 7143 if (!cpu_buffer->free_page.data) {
7082 - cpu_buffer->free_page = *data_page;
7144 + cpu_buffer->free_page = *rpage;
7083 7145 dpage = NULL;
7084 7146 }
7085 7147
@@ -7087,8 +7149,8 @@ void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu,
7087 7149 local_irq_restore(flags);
7088 7150
7089 7151 out:
7090 - free_pages((unsigned long)dpage, data_page->order);
7091 - kfree(data_page);
7152 + free_pages((unsigned long)dpage, rpage->order);
7153 + kfree(rpage);
7092 7154 }
7093 7155 EXPORT_SYMBOL_GPL(ring_buffer_free_read_page);
7094 7156
@@ -7159,10 +7221,9 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
7159 7221 if (!dpage)
7160 7222 return -1;
7161 7223
7162 - guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock);
7224 + len = min_t(size_t, len, rb_read_page_capacity(data_page));
7163 7225
7164 - if (data_page->order != cpu_buffer->reader_page->order)
7165 - return -1;
7226 + guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock);
7166 7227
7167 7228 reader = rb_get_reader_page(cpu_buffer);
7168 7229 if (!reader)
@@ -7177,31 +7238,26 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
7177 7238 /* Check if any events were dropped */
7178 7239 missed_events = cpu_buffer->lost_events;
7179 7240
7180 - /*
7181 - * If this page has been partially read or
7182 - * if len is not big enough to read the rest of the page or
7183 - * a writer is still on the page, then
7184 - * we must copy the data from the page to the buffer.
7185 - * Otherwise, we can simply swap the page with the one passed in.
7186 - */
7241 + /*
7242 + * It is not possible to swap the reader page if:
7243 + * - It has been partially read
7244 + * - len is not big enough to read it entirely
7245 + * - A writer is still on it
7246 + * - The ring buffer is static
7247 + * - The order doesn't match
7248 + */
7187 7249 if (read || (len < (size - read)) ||
7188 7250 cpu_buffer->reader_page == cpu_buffer->commit_page ||
7189 - rb_is_static(cpu_buffer)) {
7251 + rb_is_static(cpu_buffer) ||
7252 + data_page->order != reader->order) {
7190 7253 struct buffer_data_page *rpage = cpu_buffer->reader_page->page;
7191 7254 unsigned int rpos = read;
7192 7255 unsigned int pos = 0;
7193 7256 unsigned int event_size;
7194 7257 unsigned int flags = 0;
7195 7258
7196 - /*
7197 - * If a full page is expected, this can still be returned
7198 - * if there's been a previous partial read and the
7199 - * rest of the page can be read and the commit page is off
7200 - * the reader page.
7201 - */
7202 - if (full &&
7203 - (!read || (len < (size - read)) ||
7204 - cpu_buffer->reader_page == cpu_buffer->commit_page))
7259 + /* If a full page is requested, it cannot be the commit page */
7260 + if (full && cpu_buffer->reader_page == cpu_buffer->commit_page)
7205 7261 return -1;
7206 7262
7207 7263 if (len > (size - read))
@@ -7287,7 +7343,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
7287 7343 * missed events, then record it there.
7288 7344 */
7289 7345 if (missed_events > 0 &&
7290 - rb_page_capacity(reader) - size >= sizeof(missed_events)) {
7346 + rb_read_page_capacity(data_page) - size >= sizeof(missed_events)) {
7291 7347 memcpy(&dpage->data[size], &missed_events,
7292 7348 sizeof(missed_events));
7293 7349 local_add(RB_MISSED_STORED, &dpage->commit);
@@ -7307,8 +7363,8 @@ int ring_buffer_read_page(struct trace_buffer *buffer,
7307 7363 /*
7308 7364 * This page may be off to user land. Zero it out here.
7309 7365 */
7310 - if (size < rb_page_capacity(reader))
7311 - memset(&dpage->data[size], 0, rb_page_capacity(reader) - size);
7366 + if (size < rb_read_page_capacity(data_page))
7367 + memset(&dpage->data[size], 0, rb_read_page_capacity(data_page) - size);
7312 7368
7313 7369 return read;
7314 7370 }
@@ -7326,6 +7382,18 @@ void *ring_buffer_read_page_data(struct buffer_data_read_page *page)
7326 7382 }
7327 7383 EXPORT_SYMBOL_GPL(ring_buffer_read_page_data);
7328 7384
7385 + /**
7386 + * ring_buffer_read_page_size - get size of the read page.
7387 + * @page: the page to get the size from
7388 + *
7389 + * Returns size of the page in bytes.
7390 + */
7391 + unsigned int ring_buffer_read_page_size(struct buffer_data_read_page *rpage)
7392 + {
7393 + return rpage ? PAGE_SIZE << rpage->order : 0;
7394 + }
7395 + EXPORT_SYMBOL_GPL(ring_buffer_read_page_size);
7396 +
7329 7397 /**
7330 7398 * ring_buffer_subbuf_size_get - get size of the sub buffer.
7331 7399 * @buffer: the buffer to get the sub buffer size from
@@ -7380,8 +7448,8 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
7380 7448 struct ring_buffer_per_cpu *cpu_buffer;
7381 7449 struct buffer_page *bpage, *tmp;
7382 7450 unsigned int old_capacity;
7451 + unsigned long nr_pages;
7383 7452 int old_order;
7384 - int nr_pages;
7385 7453 int psize;
7386 7454 int err;
7387 7455 int cpu;
@@ -7411,7 +7479,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
7411 7479 /* Make sure all commits have finished */
7412 7480 synchronize_rcu();
7413 7481
7414 - buffer->subbuf_order = order;
7482 + WRITE_ONCE(buffer->subbuf_order, order);
7415 7483
7416 7484 /* Make sure all new buffers are allocated, before deleting the old ones */
7417 7485 for_each_buffer_cpu(buffer, cpu) {
@@ -7515,7 +7583,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
7515 7583 return 0;
7516 7584
7517 7585 error:
7518 - buffer->subbuf_order = old_order;
7586 + WRITE_ONCE(buffer->subbuf_order, old_order);
7519 7587
7520 7588 atomic_dec(&buffer->record_disabled);
7521 7589
@@ -7563,10 +7631,10 @@ static void rb_setup_ids_meta_page(struct ring_buffer_per_cpu *cpu_buffer,
7563 7631 struct buffer_page **subbuf_ids)
7564 7632 {
7565 7633 struct trace_buffer_meta *meta = cpu_buffer->meta_page;
7566 - unsigned int nr_subbufs = cpu_buffer->nr_pages + 1;
7634 + unsigned long nr_subbufs = cpu_buffer->nr_pages + 1;
7567 7635 struct buffer_page *first_subbuf, *subbuf;
7568 - int cnt = 0;
7569 - int id = 0;
7636 + unsigned int cnt = 0;
7637 + unsigned int id = 0;
7570 7638
7571 7639 id = rb_page_id(cpu_buffer, cpu_buffer->reader_page, id);
7572 7640 subbuf_ids[id++] = cpu_buffer->reader_page;
@@ -7794,6 +7862,9 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu,
7794 7862 /* prevent another thread from changing buffer/sub-buffer sizes */
7795 7863 guard(mutex)(&buffer->mutex);
7796 7864
7865 + if (cpu_buffer->nr_pages > rb_static_max_pages())
7866 + return -E2BIG;
7867 +
7797 7868 err = rb_alloc_meta_page(cpu_buffer);
7798 7869 if (err)
7799 7870 return err;
modified kernel/trace/ring_buffer_benchmark.c
@@ -104,7 +104,7 @@ static enum event_status read_event(int cpu)
104 104
105 105 static enum event_status read_page(int cpu)
106 106 {
107 - struct buffer_data_read_page *bpage;
107 + struct buffer_data_read_page *bpage = NULL;
108 108 struct ring_buffer_event *event;
109 109 struct rb_page *rpage;
110 110 unsigned long commit;
@@ -114,8 +114,8 @@ static enum event_status read_page(int cpu)
114 114 int inc;
115 115 int i;
116 116
117 - bpage = ring_buffer_alloc_read_page(buffer, cpu);
118 - if (IS_ERR(bpage))
117 + ret = ring_buffer_alloc_read_page(buffer, cpu, &bpage);
118 + if (ret < 0)
119 119 return EVENT_DROPPED;
120 120
121 121 page_size = ring_buffer_subbuf_size_get(buffer);
modified kernel/trace/trace.c
@@ -7082,8 +7082,8 @@ ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf,
7082 7082 {
7083 7083 struct ftrace_buffer_info *info = filp->private_data;
7084 7084 struct trace_iterator *iter = &info->iter;
7085 + unsigned int spare_size;
7085 7086 void *trace_data;
7086 - int page_size;
7087 7087 ssize_t ret = 0;
7088 7088 ssize_t size;
7089 7089
@@ -7093,36 +7093,22 @@ ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf,
7093 7093 if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace))
7094 7094 return -EBUSY;
7095 7095
7096 - page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer);
7096 + spare_size = ring_buffer_read_page_size(info->spare);
7097 7097
7098 - /* Make sure the spare matches the current sub buffer size */
7099 - if (info->spare) {
7100 - if (page_size != info->spare_size) {
7101 - ring_buffer_free_read_page(iter->array_buffer->buffer,
7102 - info->spare_cpu, info->spare);
7103 - info->spare = NULL;
7104 - }
7105 - }
7098 + again:
7099 + /* Do we have previous read data to read? */
7100 + if (info->read < spare_size)
7101 + goto read;
7106 7102
7107 - if (!info->spare) {
7108 - info->spare = ring_buffer_alloc_read_page(iter->array_buffer->buffer,
7109 - iter->cpu_file);
7110 - if (IS_ERR(info->spare)) {
7111 - ret = PTR_ERR(info->spare);
7112 - info->spare = NULL;
7113 - } else {
7114 - info->spare_cpu = iter->cpu_file;
7115 - info->spare_size = page_size;
7116 - }
7117 - }
7118 - if (!info->spare)
7103 + ret = ring_buffer_alloc_read_page(iter->array_buffer->buffer, iter->cpu_file,
7104 + &info->spare);
7105 + if (ret)
7119 7106 return ret;
7120 7107
7121 - /* Do we have previous read data to read? */
7122 - if (info->read < page_size)
7123 - goto read;
7108 + spare_size = ring_buffer_read_page_size(info->spare);
7109 + info->read = spare_size;
7110 + info->spare_cpu = iter->cpu_file;
7124 7111
7125 - again:
7126 7112 trace_access_lock(iter->cpu_file);
7127 7113 ret = ring_buffer_read_page(iter->array_buffer->buffer,
7128 7114 info->spare,
@@ -7148,8 +7134,9 @@ ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf,
7148 7134 }
7149 7135
7150 7136 info->read = 0;
7137 +
7151 7138 read:
7152 - size = page_size - info->read;
7139 + size = spare_size - info->read;
7153 7140 if (size > count)
7154 7141 size = count;
7155 7142 trace_data = ring_buffer_read_page_data(info->spare);
@@ -7190,26 +7177,24 @@ int tracing_buffers_release(struct inode *inode, struct file *file)
7190 7177
7191 7178 __trace_array_put(iter->tr);
7192 7179
7193 - if (info->spare)
7194 - ring_buffer_free_read_page(iter->array_buffer->buffer,
7195 - info->spare_cpu, info->spare);
7180 + ring_buffer_free_read_page(iter->array_buffer->buffer, info->spare_cpu, info->spare);
7196 7181 kvfree(info);
7197 7182
7198 7183 return 0;
7199 7184 }
7200 7185
7201 7186 struct buffer_ref {
7202 - struct trace_buffer *buffer;
7203 - void *page;
7204 - int cpu;
7205 - refcount_t refcount;
7187 + struct trace_buffer *buffer;
7188 + struct buffer_data_read_page *rpage;
7189 + int cpu;
7190 + refcount_t refcount;
7206 7191 };
7207 7192
7208 7193 static void buffer_ref_release(struct buffer_ref *ref)
7209 7194 {
7210 7195 if (!refcount_dec_and_test(&ref->refcount))
7211 7196 return;
7212 - ring_buffer_free_read_page(ref->buffer, ref->cpu, ref->page);
7197 + ring_buffer_free_read_page(ref->buffer, ref->cpu, ref->rpage);
7213 7198 kfree(ref);
7214 7199 }
7215 7200
@@ -7268,25 +7253,15 @@ ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
7268 7253 .ops = &buffer_pipe_buf_ops,
7269 7254 .spd_release = buffer_spd_release,
7270 7255 };
7256 + unsigned int page_size = 0;
7271 7257 struct buffer_ref *ref;
7272 7258 bool woken = false;
7273 - int page_size;
7274 7259 int entries, i;
7275 7260 ssize_t ret = 0;
7276 7261
7277 7262 if (iter->snapshot && tracer_uses_snapshot(iter->tr->current_trace))
7278 7263 return -EBUSY;
7279 7264
7280 - page_size = ring_buffer_subbuf_size_get(iter->array_buffer->buffer);
7281 - if (*ppos & (page_size - 1))
7282 - return -EINVAL;
7283 -
7284 - if (len & (page_size - 1)) {
7285 - if (len < page_size)
7286 - return -EINVAL;
7287 - len &= (~(page_size - 1));
7288 - }
7289 -
7290 7265 if (splice_grow_spd(pipe, &spd))
7291 7266 return -ENOMEM;
7292 7267
@@ -7306,25 +7281,39 @@ ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
7306 7281
7307 7282 refcount_set(&ref->refcount, 1);
7308 7283 ref->buffer = iter->array_buffer->buffer;
7309 - ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file);
7310 - if (IS_ERR(ref->page)) {
7311 - ret = PTR_ERR(ref->page);
7312 - ref->page = NULL;
7284 +
7285 + ret = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file, &ref->rpage);
7286 + if (ret) {
7313 7287 kfree(ref);
7314 7288 break;
7315 7289 }
7316 7290 ref->cpu = iter->cpu_file;
7317 7291
7318 - r = ring_buffer_read_page(ref->buffer, ref->page,
7319 - len, iter->cpu_file, 1);
7292 + page_size = ring_buffer_read_page_size(ref->rpage);
7293 +
7294 + r = -EINVAL;
7295 + if (IS_ALIGNED(*ppos, page_size) && len >= page_size) {
7296 + r = ring_buffer_read_page(ref->buffer, ref->rpage, len, iter->cpu_file, 1);
7297 + } else if (!i) {
7298 + /*
7299 + * If this fails to read on the first iteration, it
7300 + * means the length was too small and an error should
7301 + * be returned to user space. Otherwise, at least
7302 + * one sub-buffer was successfully read but this failed
7303 + * due to either the length was unaligned or the
7304 + * subbuf order changed. Either case, do not report
7305 + * an error.
7306 + */
7307 + ret = -EINVAL;
7308 + }
7309 +
7320 7310 if (r < 0) {
7321 - ring_buffer_free_read_page(ref->buffer, ref->cpu,
7322 - ref->page);
7311 + ring_buffer_free_read_page(ref->buffer, ref->cpu, ref->rpage);
7323 7312 kfree(ref);
7324 7313 break;
7325 7314 }
7326 7315
7327 - page = virt_to_page(ring_buffer_read_page_data(ref->page));
7316 + page = virt_to_page(ring_buffer_read_page_data(ref->rpage));
7328 7317
7329 7318 spd.pages[i] = page;
7330 7319 spd.partial[i].len = page_size;
@@ -7842,11 +7831,70 @@ trace_options_core_write(struct file *filp, const char __user *ubuf, size_t cnt,
7842 7831 return cnt;
7843 7832 }
7844 7833
7834 + /*
7835 + * The tr_index is the address of a trace_array->trace_flags_index[]
7836 + * element that holds the index of the trace flag. But since the
7837 + * trace_array reference has not been taken yet, it cannot be referenced
7838 + * as it could have been freed by a rmdir of the instance the trace_array
7839 + * represents.
7840 + *
7841 + * Search the list of trace_arrays and compare the tr_index to the
7842 + * address of the entire trace_array trace_flags_index array for each
7843 + * trace_array in the list. If one is matched, then take the reference
7844 + * and return it. If not, the trace_array no longer exits.
7845 + */
7846 + static int trace_array_options_get(void *tr_index)
7847 + {
7848 + struct trace_array *tr;
7849 + int ret;
7850 +
7851 + ret = security_locked_down(LOCKDOWN_TRACEFS);
7852 + if (ret)
7853 + return ret;
7854 +
7855 + if (tracing_disabled)
7856 + return -ENODEV;
7857 +
7858 + guard(mutex)(&trace_types_lock);
7859 + list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7860 + if (tr_index >= (void *)&tr->trace_flags_index[0] &&
7861 + tr_index < (void *)&tr->trace_flags_index[TRACE_FLAGS_MAX_SIZE])
7862 + return __trace_array_get(tr);
7863 + }
7864 + return -ENODEV;
7865 + }
7866 +
7867 + static int trace_options_open(struct inode *inode, struct file *filp)
7868 + {
7869 + void *tr_index = inode->i_private;
7870 +
7871 + if (trace_array_options_get(tr_index) < 0)
7872 + return -ENODEV;
7873 +
7874 + filp->private_data = tr_index;
7875 +
7876 + return 0;
7877 + }
7878 +
7879 + static int trace_options_release(struct inode *inode, struct file *filp)
7880 + {
7881 + void *tr_index = filp->private_data;
7882 + struct trace_array *tr;
7883 + unsigned int index;
7884 +
7885 + get_tr_index(tr_index, &tr, &index);
7886 +
7887 + trace_array_put(tr);
7888 +
7889 + return 0;
7890 + }
7891 +
7845 7892 static const struct file_operations trace_options_core_fops = {
7846 - .open = tracing_open_generic,
7847 - .read = trace_options_core_read,
7848 - .write = trace_options_core_write,
7849 - .llseek = generic_file_llseek,
7893 + .open = trace_options_open,
7894 + .read = trace_options_core_read,
7895 + .write = trace_options_core_write,
7896 + .llseek = generic_file_llseek,
7897 + .release = trace_options_release,
7850 7898 };
7851 7899
7852 7900 struct dentry *trace_create_file(const char *name,
@@ -9651,6 +9699,11 @@ __init static void enable_instances(void)
9651 9699 if (flag_delim)
9652 9700 *flag_delim++ = '\0';
9653 9701
9702 + if (trace_array_find(name)) {
9703 + pr_warn("Tracing: Instance %s already exists\n", name);
9704 + continue;
9705 + }
9706 +
9654 9707 if (backup) {
9655 9708 if (backup_instance_area(backup, &addr, &size) < 0)
9656 9709 continue;
modified kernel/trace/trace.h
@@ -745,11 +745,10 @@ static inline int tracing_get_cpu(struct inode *inode)
745 745 void tracing_reset_cpu(struct array_buffer *buf, int cpu);
746 746
747 747 struct ftrace_buffer_info {
748 - struct trace_iterator iter;
749 - void *spare;
750 - unsigned int spare_cpu;
751 - unsigned int spare_size;
752 - unsigned int read;
748 + struct trace_iterator iter;
749 + struct buffer_data_read_page *spare;
750 + unsigned int spare_cpu;
751 + unsigned int read;
753 752 };
754 753
755 754 /**
@@ -1340,7 +1339,7 @@ extern void clear_ftrace_function_probes(struct trace_array *tr);
1340 1339 int register_ftrace_command(struct ftrace_func_command *cmd);
1341 1340 int unregister_ftrace_command(struct ftrace_func_command *cmd);
1342 1341
1343 - void ftrace_create_filter_files(struct ftrace_ops *ops,
1342 + void ftrace_create_filter_files(struct trace_array *tr,
1344 1343 struct dentry *parent);
1345 1344 void ftrace_destroy_filter_files(struct ftrace_ops *ops);
1346 1345
@@ -1363,11 +1362,12 @@ static inline void clear_ftrace_function_probes(struct trace_array *tr)
1363 1362 {
1364 1363 }
1365 1364
1365 + static inline void ftrace_create_filter_files(struct trace_array *tr,
1366 + struct dentry *parent) { }
1366 1367 /*
1367 1368 * The ops parameter passed in is usually undefined.
1368 1369 * This must be a macro.
1369 1370 */
1370 - #define ftrace_create_filter_files(ops, parent) do { } while (0)
1371 1371 #define ftrace_destroy_filter_files(ops) do { } while (0)
1372 1372 #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
1373 1373
modified kernel/trace/trace_btf.c
@@ -61,47 +61,50 @@ struct btf_anon_stack {
61 61
62 62 /*
63 63 * Find a member of data structure/union by name and return it.
64 - * Return NULL if not found, or -EINVAL if parameter is invalid.
65 - * If the member is an member of anonymous union/structure, the offset
66 - * of that anonymous union/structure is stored into @anon_offset. Caller
67 - * can calculate the correct offset from the root data structure by
68 - * adding anon_offset to the member's offset.
64 + * Return NULL if not found, or ERR_PTR(-EINVAL) if parameter is invalid.
65 + * If the member is a member of an anonymous union/structure, the bit offset
66 + * of that anonymous union/structure is stored into @anon_offset.
67 + * If @member_type is non-NULL, the actual containing structure/union type
68 + * of the found member is stored into @member_type.
69 69 */
70 70 const struct btf_member *btf_find_struct_member(struct btf *btf,
71 71 const struct btf_type *type,
72 72 const char *member_name,
73 - u32 *anon_offset)
73 + u32 *anon_offset,
74 + const struct btf_type **member_type)
74 75 {
75 76 struct btf_anon_stack *anon_stack;
76 77 const struct btf_member *member;
78 + const struct btf_type *mtype;
77 79 u32 tid, cur_offset = 0;
78 80 const char *name;
79 81 int i, top = 0;
80 82
83 + if (!btf_type_is_struct(type))
84 + return ERR_PTR(-EINVAL);
85 +
81 86 anon_stack = kzalloc_objs(*anon_stack, BTF_ANON_STACK_MAX);
82 87 if (!anon_stack)
83 88 return ERR_PTR(-ENOMEM);
84 89
85 90 retry:
86 - if (!btf_type_is_struct(type)) {
87 - member = ERR_PTR(-EINVAL);
88 - goto out;
89 - }
90 -
91 91 for_each_member(i, type, member) {
92 92 if (!member->name_off) {
93 93 /* Anonymous union/struct: push it for later use */
94 - if (btf_type_skip_modifiers(btf, member->type, &tid) &&
94 + mtype = btf_type_skip_modifiers(btf, member->type, &tid);
95 + if (mtype && btf_type_is_struct(mtype) &&
95 96 top < BTF_ANON_STACK_MAX) {
96 97 anon_stack[top].tid = tid;
97 - anon_stack[top++].offset =
98 - cur_offset + member->offset;
98 + anon_stack[top++].offset = cur_offset +
99 + __btf_member_bit_offset(type, member);
99 100 }
100 101 } else {
101 102 name = btf_name_by_offset(btf, member->name_off);
102 103 if (name && !strcmp(member_name, name)) {
103 104 if (anon_offset)
104 105 *anon_offset = cur_offset;
106 + if (member_type)
107 + *member_type = type;
105 108 goto out;
106 109 }
107 110 }
modified kernel/trace/trace_btf.h
@@ -8,4 +8,5 @@ const struct btf_param *btf_get_func_param(const struct btf_type *func_proto,
8 8 const struct btf_member *btf_find_struct_member(struct btf *btf,
9 9 const struct btf_type *type,
10 10 const char *member_name,
11 - u32 *anon_offset);
11 + u32 *anon_offset,
12 + const struct btf_type **member_type);
modified kernel/trace/trace_eprobe.c
@@ -930,7 +930,7 @@ static int __trace_eprobe_create(int argc, const char *argv[])
930 930 } else
931 931 ep->filter_str = NULL;
932 932
933 - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
933 + ctx = kzalloc_obj(*ctx);
934 934 if (!ctx)
935 935 return -ENOMEM;
936 936 ctx->event = ep->event;
modified kernel/trace/trace_events.c
@@ -2736,14 +2736,14 @@ static const struct file_operations ftrace_show_event_filters_fops = {
2736 2736 .open = ftrace_event_show_filters_open,
2737 2737 .read = seq_read,
2738 2738 .llseek = seq_lseek,
2739 - .release = seq_release,
2739 + .release = ftrace_event_release,
2740 2740 };
2741 2741
2742 2742 static const struct file_operations ftrace_show_event_triggers_fops = {
2743 2743 .open = ftrace_event_show_triggers_open,
2744 2744 .read = seq_read,
2745 2745 .llseek = seq_lseek,
2746 - .release = seq_release,
2746 + .release = ftrace_event_release,
2747 2747 };
2748 2748
2749 2749 static const struct file_operations ftrace_set_event_pid_fops = {
@@ -2908,7 +2908,17 @@ ftrace_event_set_open(struct inode *inode, struct file *file)
2908 2908 static int
2909 2909 ftrace_event_show_filters_open(struct inode *inode, struct file *file)
2910 2910 {
2911 - return ftrace_event_open(inode, file, &show_show_event_filters_seq_ops);
2911 + struct trace_array *tr = inode->i_private;
2912 + int ret;
2913 +
2914 + ret = tracing_check_open_get_tr(tr);
2915 + if (ret)
2916 + return ret;
2917 +
2918 + ret = ftrace_event_open(inode, file, &show_show_event_filters_seq_ops);
2919 + if (ret < 0)
2920 + trace_array_put(tr);
2921 + return ret;
2912 2922 }
2913 2923
2914 2924 /**
@@ -2922,7 +2932,17 @@ ftrace_event_show_filters_open(struct inode *inode, struct file *file)
2922 2932 static int
2923 2933 ftrace_event_show_triggers_open(struct inode *inode, struct file *file)
2924 2934 {
2925 - return ftrace_event_open(inode, file, &show_show_event_triggers_seq_ops);
2935 + struct trace_array *tr = inode->i_private;
2936 + int ret;
2937 +
2938 + ret = tracing_check_open_get_tr(tr);
2939 + if (ret)
2940 + return ret;
2941 +
2942 + ret = ftrace_event_open(inode, file, &show_show_event_triggers_seq_ops);
2943 + if (ret < 0)
2944 + trace_array_put(tr);
2945 + return ret;
2926 2946 }
2927 2947
2928 2948 static int
modified kernel/trace/trace_functions.c
@@ -101,7 +101,7 @@ int ftrace_create_function_files(struct trace_array *tr,
101 101 return ret;
102 102 }
103 103
104 - ftrace_create_filter_files(tr->ops, parent);
104 + ftrace_create_filter_files(tr, parent);
105 105
106 106 return 0;
107 107 }
modified kernel/trace/trace_probe.c
@@ -625,6 +625,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
625 625 {
626 626 const struct btf_type *type = *ptype;
627 627 const struct btf_member *field;
628 + const struct btf_type *mtype;
628 629 struct btf *btf = ctx_btf(ctx);
629 630 char *fieldname = *pfieldname;
630 631 int bitoffs = 0;
@@ -640,7 +641,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
640 641
641 642 anon_offs = 0;
642 643 field = btf_find_struct_member(btf, type, fieldname,
643 - &anon_offs);
644 + &anon_offs, &mtype);
644 645 if (IS_ERR(field)) {
645 646 trace_probe_log_err(ctx->offset, BAD_BTF_TID);
646 647 return PTR_ERR(field);
@@ -653,7 +654,7 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
653 654 bitoffs += anon_offs;
654 655
655 656 /* Accumulate the bit-offsets of the dot-connected fields */
656 - if (btf_type_kflag(type)) {
657 + if (btf_type_kflag(mtype)) {
657 658 bitoffs += BTF_MEMBER_BIT_OFFSET(field->offset);
658 659 ctx->last_bitsize = BTF_MEMBER_BITFIELD_SIZE(field->offset);
659 660 } else {
@@ -661,11 +662,11 @@ static int get_bitoffset_of_field(char **pfieldname, const struct btf_type **pty
661 662 ctx->last_bitsize = 0;
662 663 }
663 664
664 - type = btf_type_skip_modifiers(btf, field->type, NULL);
665 - if (!type) {
666 - trace_probe_log_err(ctx->offset, BAD_BTF_TID);
667 - return -EINVAL;
668 - }
665 + type = btf_type_skip_modifiers(btf, field->type, NULL);
666 + if (!type) {
667 + trace_probe_log_err(ctx->offset, BAD_BTF_TID);
668 + return -EINVAL;
669 + }
669 670
670 671 if (next)
671 672 ctx->offset += next - fieldname;
@@ -2552,19 +2553,60 @@ int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype
2552 2553 int traceprobe_define_arg_fields(struct trace_event_call *event_call,
2553 2554 size_t offset, struct trace_probe *tp)
2554 2555 {
2556 + struct trace_probe_event *tpe = trace_probe_event_from_call(event_call);
2555 2557 int ret, i;
2556 2558
2559 + /*
2560 + * A field created by trace_define_field() only stores the name and
2561 + * type pointers, it does not copy the strings. Here they point into
2562 + * the probe_arg of @tp, which is freed when @tp is removed. For an
2563 + * event with multiple probes attached, the field list is defined
2564 + * once by the first probe but kept alive by the surviving siblings,
2565 + * so removing that first probe would leave the fields referencing
2566 + * freed memory. Duplicate the strings and anchor the copies on the
2567 + * trace_probe_event, which lives as long as the field list itself.
2568 + *
2569 + * event_define_fields() ignores the return value of this hook, so
2570 + * if a previous attempt failed before creating any field, it may
2571 + * call here again. Release duplicates left behind by such an
2572 + * attempt before starting over.
2573 + */
2574 + for (i = 0; i < tpe->nr_field_strings; i++)
2575 + kfree(tpe->field_strings[i]);
2576 + kfree(tpe->field_strings);
2577 + tpe->field_strings = NULL;
2578 + tpe->nr_field_strings = 0;
2579 +
2580 + if (tp->nr_args) {
2581 + tpe->field_strings = kcalloc(tp->nr_args * 2, sizeof(char *),
2582 + GFP_KERNEL);
2583 + if (!tpe->field_strings)
2584 + return -ENOMEM;
2585 + }
2586 +
2557 2587 /* Set argument names as fields */
2558 2588 for (i = 0; i < tp->nr_args; i++) {
2559 2589 struct probe_arg *parg = &tp->args[i];
2560 2590 const char *fmt = parg->type->fmttype;
2561 2591 int size = parg->type->size;
2592 + char *name, *type;
2562 2593
2563 2594 if (parg->fmt)
2564 2595 fmt = parg->fmt;
2565 2596 if (parg->count)
2566 2597 size *= parg->count;
2567 - ret = trace_define_field(event_call, fmt, parg->name,
2598 +
2599 + name = kstrdup(parg->name, GFP_KERNEL);
2600 + type = kstrdup(fmt, GFP_KERNEL);
2601 + if (!name || !type) {
2602 + kfree(name);
2603 + kfree(type);
2604 + return -ENOMEM;
2605 + }
2606 + tpe->field_strings[tpe->nr_field_strings++] = name;
2607 + tpe->field_strings[tpe->nr_field_strings++] = type;
2608 +
2609 + ret = trace_define_field(event_call, type, name,
2568 2610 offset + parg->offset, size,
2569 2611 parg->type->is_signed,
2570 2612 FILTER_OTHER);
@@ -2576,6 +2618,11 @@ int traceprobe_define_arg_fields(struct trace_event_call *event_call,
2576 2618
2577 2619 static void trace_probe_event_free(struct trace_probe_event *tpe)
2578 2620 {
2621 + int i;
2622 +
2623 + for (i = 0; i < tpe->nr_field_strings; i++)
2624 + kfree(tpe->field_strings[i]);
2625 + kfree(tpe->field_strings);
2579 2626 kfree(tpe->class.system);
2580 2627 kfree(tpe->call.name);
2581 2628 kfree(tpe->call.print_fmt);
modified kernel/trace/trace_probe.h
@@ -264,6 +264,8 @@ struct trace_probe_event {
264 264 struct trace_event_call call;
265 265 struct list_head files;
266 266 struct list_head probes;
267 + char **field_strings;
268 + int nr_field_strings;
267 269 struct trace_uprobe_filter filter[];
268 270 };
269 271
modified kernel/trace/trace_remote.c
@@ -251,8 +251,8 @@ static int trace_remote_get(struct trace_remote *remote, int cpu)
251 251 if (cpu != RING_BUFFER_ALL_CPUS && !remote->pcpu_reader_locks) {
252 252 int lock_cpu;
253 253
254 - remote->pcpu_reader_locks = kcalloc(nr_cpu_ids, sizeof(*remote->pcpu_reader_locks),
255 - GFP_KERNEL);
254 + remote->pcpu_reader_locks = kzalloc_objs(*remote->pcpu_reader_locks,
255 + nr_cpu_ids);
256 256 if (!remote->pcpu_reader_locks) {
257 257 trace_remote_try_unload(remote);
258 258 return -ENOMEM;
@@ -324,7 +324,7 @@ static int __alloc_ring_buffer_iter(struct trace_remote_iterator *iter, int cpu)
324 324 return iter->rb_iter ? 0 : -ENOMEM;
325 325 }
326 326
327 - iter->rb_iters = kcalloc(nr_cpu_ids, sizeof(*iter->rb_iters), GFP_KERNEL);
327 + iter->rb_iters = kzalloc_objs(*iter->rb_iters, nr_cpu_ids);
328 328 if (!iter->rb_iters)
329 329 return -ENOMEM;
330 330
@@ -1204,7 +1204,7 @@ remote_events_dir_header_page_read(struct file *filp, char __user *ubuf, size_t
1204 1204 struct trace_seq *s;
1205 1205 int ret;
1206 1206
1207 - s = kmalloc(sizeof(*s), GFP_KERNEL);
1207 + s = kmalloc_obj(*s);
1208 1208 if (!s)
1209 1209 return -ENOMEM;
1210 1210
@@ -1227,7 +1227,7 @@ remote_events_dir_header_event_read(struct file *filp, char __user *ubuf, size_t
1227 1227 struct trace_seq *s;
1228 1228 int ret;
1229 1229
1230 - s = kmalloc(sizeof(*s), GFP_KERNEL);
1230 + s = kmalloc_obj(*s);
1231 1231 if (!s)
1232 1232 return -ENOMEM;
1233 1233
modified kernel/trace/trace_stack.c
@@ -499,7 +499,7 @@ stack_trace_filter_open(struct inode *inode, struct file *file)
499 499 struct ftrace_ops *ops = inode->i_private;
500 500
501 501 /* Checks for tracefs lockdown */
502 - return ftrace_regex_open(ops, FTRACE_ITER_FILTER,
502 + return ftrace_regex_open(NULL, ops, FTRACE_ITER_FILTER,
503 503 inode, file);
504 504 }
505 505
modified kernel/trace/trace_uprobe.c
@@ -368,7 +368,7 @@ error:
368 368
369 369 static void free_trace_uprobe(struct trace_uprobe *tu)
370 370 {
371 - if (!tu)
371 + if (IS_ERR_OR_NULL(tu))
372 372 return;
373 373
374 374 path_put(&tu->path);
@@ -533,7 +533,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
533 533 return ret;
534 534 }
535 535
536 - DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, if (_T) free_trace_uprobe(_T))
536 + DEFINE_FREE(free_trace_uprobe, struct trace_uprobe *, free_trace_uprobe(_T))
537 537
538 538 /*
539 539 * Argument syntax:
modified kernel/workqueue.c
@@ -3197,7 +3197,16 @@ restart:
3197 3197 #ifdef CONFIG_PREEMPT_RT
3198 3198 static void worker_lock_callback(struct worker_pool *pool)
3199 3199 {
3200 - spin_lock(&pool->cb_lock);
3200 + /*
3201 + * SINGLE_DEPTH_NESTING is for a dead pool's bh_worker() running from
3202 + * drain_dead_softirq_workfn() inside a live pool's bh_worker(). The
3203 + * unlocked read is stable: the flag is only set while @pool's CPU is
3204 + * dead, inside a serialized hotplug operation. data_race() as the value
3205 + * only affects the lockdep annotation and the read can be elided when
3206 + * lockdep is disabled.
3207 + */
3208 + spin_lock_nested(&pool->cb_lock,
3209 + data_race(pool->flags) & POOL_BH_DRAINING ? SINGLE_DEPTH_NESTING : 0);
3201 3210 }
3202 3211
3203 3212 static void worker_unlock_callback(struct worker_pool *pool)
@@ -5285,12 +5294,6 @@ static void pwq_release_workfn(struct kthread_work *work)
5285 5294 mutex_unlock(&wq->mutex);
5286 5295 }
5287 5296
5288 - if (!is_percpu_pool(pool)) {
5289 - mutex_lock(&wq_pool_mutex);
5290 - put_unbound_pool(pool);
5291 - mutex_unlock(&wq_pool_mutex);
5292 - }
5293 -
5294 5297 if (!list_empty(&pwq->pending_node)) {
5295 5298 struct wq_node_nr_active *nna =
5296 5299 wq_node_nr_active(pwq->wq, pwq->pool->node);
@@ -5300,6 +5303,12 @@ static void pwq_release_workfn(struct kthread_work *work)
5300 5303 raw_spin_unlock_irq(&nna->lock);
5301 5304 }
5302 5305
5306 + if (!is_percpu_pool(pool)) {
5307 + mutex_lock(&wq_pool_mutex);
5308 + put_unbound_pool(pool);
5309 + mutex_unlock(&wq_pool_mutex);
5310 + }
5311 +
5303 5312 kfree_rcu(pwq, rcu);
5304 5313
5305 5314 /*
@@ -8050,6 +8059,9 @@ static int wq_watchdog_param_set_thresh(const char *val,
8050 8059 if (ret)
8051 8060 return ret;
8052 8061
8062 + if (thresh > MAX_JIFFY_OFFSET / HZ)
8063 + return -ERANGE;
8064 +
8053 8065 if (system_percpu_wq)
8054 8066 wq_watchdog_set_thresh(thresh);
8055 8067 else
@@ -8080,12 +8092,12 @@ static inline void wq_watchdog_init(void) { }
8080 8092
8081 8093 static void bh_pool_kick_normal(struct irq_work *irq_work)
8082 8094 {
8083 - raise_softirq_irqoff(TASKLET_SOFTIRQ);
8095 + raise_softirq(TASKLET_SOFTIRQ);
8084 8096 }
8085 8097
8086 8098 static void bh_pool_kick_highpri(struct irq_work *irq_work)
8087 8099 {
8088 - raise_softirq_irqoff(HI_SOFTIRQ);
8100 + raise_softirq(HI_SOFTIRQ);
8089 8101 }
8090 8102
8091 8103 static void __init restrict_unbound_cpumask(const char *name, const struct cpumask *mask)
modified lib/once.c
@@ -93,6 +93,6 @@ void __do_once_sleepable_done(bool *done, struct static_key_true *once_key,
93 93 {
94 94 *done = true;
95 95 mutex_unlock(&once_mutex);
96 - static_branch_disable(once_key);
96 + once_disable_jump(once_key, mod);
97 97 }
98 98 EXPORT_SYMBOL(__do_once_sleepable_done);
modified lib/test_rhashtable.c
@@ -696,7 +696,7 @@ static int __init test_rhashtable_next_key(void)
696 696 if (err)
697 697 return err;
698 698
699 - objs = kcalloc(n, sizeof(*objs), GFP_KERNEL);
699 + objs = kzalloc_objs(*objs, n);
700 700 if (!objs) {
701 701 rhashtable_destroy(&ht);
702 702 return -ENOMEM;
modified lib/test_workqueue.c
@@ -149,11 +149,11 @@ static int __init run_bench(int n_threads, const char *scope, const char *label)
149 149 if (ret)
150 150 return ret;
151 151
152 - ctxs = kcalloc(n_threads, sizeof(*ctxs), GFP_KERNEL);
152 + ctxs = kzalloc_objs(*ctxs, n_threads);
153 153 if (!ctxs)
154 154 return -ENOMEM;
155 155
156 - tasks = kcalloc(n_threads, sizeof(*tasks), GFP_KERNEL);
156 + tasks = kzalloc_objs(*tasks, n_threads);
157 157 if (!tasks) {
158 158 kfree(ctxs);
159 159 return -ENOMEM;
modified lib/tests/kunit_iov_iter.c
@@ -57,7 +57,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test,
57 57 void *buffer;
58 58 unsigned int i;
59 59
60 - pages = kzalloc_objs(struct page *, npages, GFP_KERNEL);
60 + pages = kzalloc_objs(struct page *, npages);
61 61 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
62 62 *ppages = pages;
63 63
modified mm/damon/tests/vaddr-kunit.h
@@ -136,7 +136,7 @@ static void damon_do_test_apply_three_regions(struct kunit *test,
136 136 if (!t)
137 137 kunit_skip(test, "target alloc fail");
138 138
139 - ranges = kmalloc_array(nr_regions / 2, sizeof(*ranges), GFP_KERNEL);
139 + ranges = kmalloc_objs(*ranges, nr_regions / 2);
140 140 if (!ranges) {
141 141 damon_destroy_target(t, NULL);
142 142 kunit_skip(test, "ranges alloc fail");
modified mm/huge_memory.c
@@ -2449,6 +2449,8 @@ static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma,
2449 2449 add_mm_counter(mm, mm_counter_file(folio),
2450 2450 -HPAGE_PMD_NR);
2451 2451
2452 + if (is_present && pmd_dirty(pmdval))
2453 + folio_mark_dirty(folio);
2452 2454 if (is_present && pmd_young(pmdval) &&
2453 2455 likely(vma_has_recency(vma)))
2454 2456 folio_mark_accessed(folio);
modified mm/hugetlb.c
@@ -1992,7 +1992,8 @@ retry:
1992 1992 if (h->surplus_huge_pages_node[folio_nid(folio)])
1993 1993 adjust_surplus = true;
1994 1994 remove_hugetlb_folio(h, folio, adjust_surplus);
1995 - h->max_huge_pages--;
1995 + if (!adjust_surplus)
1996 + h->max_huge_pages--;
1996 1997 spin_unlock_irq(&hugetlb_lock);
1997 1998
1998 1999 /*
@@ -2012,7 +2013,8 @@ retry:
2012 2013 if (rc) {
2013 2014 spin_lock_irq(&hugetlb_lock);
2014 2015 add_hugetlb_folio(h, folio, adjust_surplus);
2015 - h->max_huge_pages++;
2016 + if (!adjust_surplus)
2017 + h->max_huge_pages++;
2016 2018 goto out;
2017 2019 }
2018 2020 } else {
@@ -7330,14 +7332,14 @@ void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio,
7330 7332 * There is no need to transfer the per-node surplus state
7331 7333 * when we do not cross the node.
7332 7334 */
7333 - if (new_nid == old_nid)
7334 - return;
7335 - spin_lock_irq(&hugetlb_lock);
7336 - if (h->surplus_huge_pages_node[old_nid]) {
7337 - h->surplus_huge_pages_node[old_nid]--;
7338 - h->surplus_huge_pages_node[new_nid]++;
7335 + if (new_nid != old_nid) {
7336 + spin_lock_irq(&hugetlb_lock);
7337 + if (h->surplus_huge_pages_node[old_nid]) {
7338 + h->surplus_huge_pages_node[old_nid]--;
7339 + h->surplus_huge_pages_node[new_nid]++;
7340 + }
7341 + spin_unlock_irq(&hugetlb_lock);
7339 7342 }
7340 - spin_unlock_irq(&hugetlb_lock);
7341 7343 }
7342 7344
7343 7345 /*
modified mm/hugetlb_cgroup.c
@@ -97,6 +97,7 @@ static void hugetlb_cgroup_init(struct hugetlb_cgroup *h_cgroup,
97 97 struct page_counter *fault, *fault_parent = NULL;
98 98 struct page_counter *rsvd, *rsvd_parent = NULL;
99 99 unsigned long limit;
100 + int ret;
100 101
101 102 if (parent_h_cgroup) {
102 103 fault_parent = hugetlb_cgroup_counter_from_cgroup(
@@ -118,8 +119,10 @@ static void hugetlb_cgroup_init(struct hugetlb_cgroup *h_cgroup,
118 119 limit = round_down(PAGE_COUNTER_MAX,
119 120 pages_per_huge_page(&hstates[idx]));
120 121
121 - VM_BUG_ON(page_counter_set_max(fault, limit));
122 - VM_BUG_ON(page_counter_set_max(rsvd, limit));
122 + ret = page_counter_set_max(fault, limit);
123 + VM_WARN_ON_ONCE(ret);
124 + ret = page_counter_set_max(rsvd, limit);
125 + VM_WARN_ON_ONCE(ret);
123 126 }
124 127 }
125 128
modified mm/hugetlb_cma.c
@@ -3,6 +3,7 @@
3 3 #include <linux/mm.h>
4 4 #include <linux/cma.h>
5 5 #include <linux/compiler.h>
6 + #include <linux/cpuset.h>
6 7 #include <linux/mm_inline.h>
7 8
8 9 #include <asm/page.h>
@@ -55,15 +56,25 @@ struct folio *hugetlb_cma_alloc_frozen_folio(int order, gfp_t gfp_mask,
55 56 int node;
56 57 struct folio *folio;
57 58 struct page *page = NULL;
59 + const nodemask_t *nmask;
60 + unsigned int cpuset_mems_cookie;
58 61
59 62 if (!hugetlb_cma_size)
60 63 return NULL;
61 64
62 - if (hugetlb_cma[nid])
65 + retry_cpuset:
66 + if (!nodemask) {
67 + cpuset_mems_cookie = read_mems_allowed_begin();
68 + nmask = &cpuset_current_mems_allowed;
69 + } else {
70 + nmask = nodemask;
71 + }
72 +
73 + if (hugetlb_cma[nid] && node_isset(nid, *nmask))
63 74 page = cma_alloc_frozen_compound(hugetlb_cma[nid], order);
64 75
65 76 if (!page && !(gfp_mask & __GFP_THISNODE)) {
66 - for_each_node_mask(node, *nodemask) {
77 + for_each_node_mask(node, *nmask) {
67 78 if (node == nid || !hugetlb_cma[node])
68 79 continue;
69 80
@@ -73,8 +84,12 @@ struct folio *hugetlb_cma_alloc_frozen_folio(int order, gfp_t gfp_mask,
73 84 }
74 85 }
75 86
76 - if (!page)
87 + if (!page) {
88 + if (!nodemask &&
89 + unlikely(read_mems_allowed_retry(cpuset_mems_cookie)))
90 + goto retry_cpuset;
77 91 return NULL;
92 + }
78 93
79 94 folio = page_folio(page);
80 95 folio_set_hugetlb_cma(folio);
modified mm/khugepaged.c
@@ -454,12 +454,6 @@ int hugepage_madvise(struct vm_area_struct *vma,
454 454 case MADV_HUGEPAGE:
455 455 *vm_flags &= ~VM_NOHUGEPAGE;
456 456 *vm_flags |= VM_HUGEPAGE;
457 - /*
458 - * If the vma become good for khugepaged to scan,
459 - * register it here without waiting a page fault that
460 - * may not happen any time soon.
461 - */
462 - khugepaged_enter_vma(vma, *vm_flags);
463 457 break;
464 458 case MADV_NOHUGEPAGE:
465 459 *vm_flags &= ~VM_HUGEPAGE;
modified mm/madvise.c
@@ -178,6 +178,14 @@ static int madvise_update_vma(vm_flags_t new_flags,
178 178 /* vm_flags is protected by the mmap_lock held in write mode. */
179 179 vma_start_write(vma);
180 180 vma->flags = new_vma_flags;
181 + /*
182 + * If the vma become good for khugepaged to scan,
183 + * register it here without waiting a page fault that
184 + * may not happen any time soon.
185 + */
186 + if (vma_flags_test(&new_vma_flags, VMA_HUGEPAGE_BIT))
187 + khugepaged_enter_vma(vma, vma_flags_to_legacy(new_vma_flags));
188 +
181 189 if (set_new_anon_name)
182 190 return replace_anon_vma_name(vma, anon_name);
183 191
modified mm/memcontrol-v1.c
@@ -96,7 +96,6 @@ enum {
96 96 RES_LIMIT,
97 97 RES_MAX_USAGE,
98 98 RES_FAILCNT,
99 - RES_SOFT_LIMIT,
100 99 };
101 100
102 101 #ifdef CONFIG_LOCKDEP
@@ -1888,6 +1887,30 @@ static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
1888 1887 return -EINVAL;
1889 1888 }
1890 1889
1890 + static u64 mem_cgroup_soft_limit_read(struct cgroup_subsys_state *css,
1891 + struct cftype *cft)
1892 + {
1893 + return (u64)PAGE_COUNTER_MAX * PAGE_SIZE;
1894 + }
1895 +
1896 + static ssize_t mem_cgroup_soft_limit_write(struct kernfs_open_file *of,
1897 + char *buf, size_t nbytes, loff_t off)
1898 + {
1899 + unsigned long nr_pages;
1900 + int ret;
1901 +
1902 + ret = page_counter_memparse(strstrip(buf), "-1", &nr_pages);
1903 + if (ret)
1904 + return ret;
1905 +
1906 + pr_warn_once("soft_limit_in_bytes is deprecated and will be removed. "
1907 + "Writing any value to this file has no effect. "
1908 + "Please report your usecase to linux-mm@kvack.org if you "
1909 + "depend on this functionality.\n");
1910 +
1911 + return nbytes;
1912 + }
1913 +
1891 1914 static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
1892 1915 struct cftype *cft)
1893 1916 {
@@ -1924,8 +1947,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
1924 1947 return (u64)counter->watermark * PAGE_SIZE;
1925 1948 case RES_FAILCNT:
1926 1949 return counter->failcnt;
1927 - case RES_SOFT_LIMIT:
1928 - return (u64)READ_ONCE(memcg->soft_limit) * PAGE_SIZE;
1929 1950 default:
1930 1951 BUG();
1931 1952 }
@@ -2020,17 +2041,6 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
2020 2041 break;
2021 2042 }
2022 2043 break;
2023 - case RES_SOFT_LIMIT:
2024 - if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
2025 - ret = -EOPNOTSUPP;
2026 - } else {
2027 - pr_warn_once("soft_limit_in_bytes is deprecated and will be removed. "
2028 - "Please report your usecase to linux-mm@kvack.org if you "
2029 - "depend on this functionality.\n");
2030 - WRITE_ONCE(memcg->soft_limit, nr_pages);
2031 - ret = 0;
2032 - }
2033 - break;
2034 2044 }
2035 2045 return ret ?: nbytes;
2036 2046 }
@@ -2384,9 +2394,8 @@ struct cftype mem_cgroup_legacy_files[] = {
2384 2394 },
2385 2395 {
2386 2396 .name = "soft_limit_in_bytes",
2387 - .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT),
2388 - .write = mem_cgroup_write,
2389 - .read_u64 = mem_cgroup_read_u64,
2397 + .write = mem_cgroup_soft_limit_write,
2398 + .read_u64 = mem_cgroup_soft_limit_read,
2390 2399 },
2391 2400 {
2392 2401 .name = "failcnt",
modified mm/mempolicy.c
@@ -2679,7 +2679,7 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
2679 2679 prev_node = node;
2680 2680
2681 2681 /* create a local copy of node weights to operate on outside rcu */
2682 - weights = kzalloc(nr_node_ids, GFP_KERNEL);
2682 + weights = kmalloc(nr_node_ids, gfp & GFP_RECLAIM_MASK);
2683 2683 if (!weights)
2684 2684 return total_allocated;
2685 2685
modified mm/migrate_device.c
@@ -1423,6 +1423,15 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
1423 1423
1424 1424 src_pfns[i] = migrate_device_pfn_lock(pfn);
1425 1425 nr = folio_nr_pages(folio);
1426 + if (nr > npages - i) {
1427 + if (src_pfns[i] & MIGRATE_PFN_MIGRATE) {
1428 + folio_unlock(folio);
1429 + folio_put(folio);
1430 + }
1431 + memset(&src_pfns[i], 0,
1432 + (npages - i) * sizeof(*src_pfns));
1433 + break;
1434 + }
1426 1435 if (nr > 1) {
1427 1436 src_pfns[i] |= MIGRATE_PFN_COMPOUND;
1428 1437 for (j = 1; j < nr; j++)
@@ -1457,6 +1466,15 @@ int migrate_device_pfns(unsigned long *src_pfns, unsigned long npages)
1457 1466
1458 1467 src_pfns[i] = migrate_device_pfn_lock(src_pfns[i]);
1459 1468 nr = folio_nr_pages(folio);
1469 + if (nr > npages - i) {
1470 + if (src_pfns[i] & MIGRATE_PFN_MIGRATE) {
1471 + folio_unlock(folio);
1472 + folio_put(folio);
1473 + }
1474 + memset(&src_pfns[i], 0,
1475 + (npages - i) * sizeof(*src_pfns));
1476 + break;
1477 + }
1460 1478 if (nr > 1) {
1461 1479 src_pfns[i] |= MIGRATE_PFN_COMPOUND;
1462 1480 for (j = 1; j < nr; j++)
modified mm/mremap.c
@@ -1331,18 +1331,30 @@ static void dontunmap_complete(struct vma_remap_struct *vrm,
1331 1331 {
1332 1332 unsigned long start = vrm->addr;
1333 1333 unsigned long end = vrm->addr + vrm->old_len;
1334 - unsigned long old_start = vrm->vma->vm_start;
1335 - unsigned long old_end = vrm->vma->vm_end;
1334 + struct vm_area_struct *vma = vrm->vma;
1335 + unsigned long old_start = vma->vm_start;
1336 + unsigned long old_end = vma->vm_end;
1336 1337
1337 1338 /* We always clear VMA_LOCKED[ONFAULT]_BIT on the old VMA. */
1338 - vma_clear_flags_mask(vrm->vma, VMA_LOCKED_MASK);
1339 + vma_clear_flags_mask(vma, VMA_LOCKED_MASK);
1339 1340
1340 1341 /*
1341 1342 * anon_vma links of the old vma is no longer needed after its page
1342 1343 * table has been moved.
1343 1344 */
1344 - if (new_vma != vrm->vma && start == old_start && end == old_end)
1345 - unlink_anon_vmas(vrm->vma);
1345 + if (new_vma != vma && start == old_start && end == old_end) {
1346 + const pgoff_t pgoff_unfaulted = vma->vm_start >> PAGE_SHIFT;
1347 +
1348 + unlink_anon_vmas(vma);
1349 + /*
1350 + * The VMA is now unfaulted and it is an invariant that
1351 + * unfaulted anonymous VMAs have page offset equal to
1352 + * vma->vm_start >> PAGE_SHIFT.
1353 + */
1354 + vma_set_anon_pgoff(vma, pgoff_unfaulted);
1355 + if (vma_is_anonymous(vma) && !vma->vm_file)
1356 + vma_set_pgoff(vma, pgoff_unfaulted);
1357 + }
1346 1358
1347 1359 /* Because we won't unmap we don't need to touch locked_vm. */
1348 1360 }
modified mm/secretmem.c
@@ -18,6 +18,8 @@
18 18 #include <linux/secretmem.h>
19 19 #include <linux/set_memory.h>
20 20 #include <linux/sched/signal.h>
21 + #include <linux/sched/user.h>
22 + #include <linux/cred.h>
21 23
22 24 #include <uapi/linux/magic.h>
23 25
@@ -47,10 +49,69 @@ bool secretmem_active(void)
47 49 return !!atomic_read(&secretmem_users);
48 50 }
49 51
52 + struct secretmem_inode_state {
53 + struct user_struct *user;
54 + atomic_long_t nr_pages_accounted;
55 + };
56 +
57 + static bool __secretmem_account_pages(struct user_struct *user,
58 + unsigned long nr_pages)
59 + {
60 + unsigned long page_limit, cur_pages, new_pages;
61 +
62 + if (!nr_pages)
63 + return true;
64 +
65 + page_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
66 +
67 + cur_pages = atomic_long_read(&user->locked_vm);
68 + do {
69 + new_pages = cur_pages + nr_pages;
70 + if (new_pages > page_limit)
71 + return false;
72 + } while (!atomic_long_try_cmpxchg(&user->locked_vm,
73 + &cur_pages, new_pages));
74 + return true;
75 + }
76 +
77 + static bool secretmem_account_folio(struct secretmem_inode_state *state,
78 + const struct folio *folio)
79 + {
80 + const unsigned long nr_pages = folio_nr_pages(folio);
81 +
82 + if (!__secretmem_account_pages(state->user, nr_pages))
83 + return false;
84 +
85 + atomic_long_add(nr_pages, &state->nr_pages_accounted);
86 + return true;
87 + }
88 +
89 + static void __secretmem_unaccount_pages(struct secretmem_inode_state *state,
90 + unsigned long nr_pages)
91 + {
92 + atomic_long_sub(nr_pages, &state->user->locked_vm);
93 + atomic_long_sub(nr_pages, &state->nr_pages_accounted);
94 + }
95 +
96 + static void secretmem_unaccount_folio(struct secretmem_inode_state *state,
97 + struct folio *folio)
98 + {
99 + __secretmem_unaccount_pages(state, folio_nr_pages(folio));
100 + }
101 +
102 + static void secretmem_unaccount_all_folios(struct secretmem_inode_state *state)
103 + {
104 + const unsigned long nr_pages_accounted =
105 + atomic_long_read(&state->nr_pages_accounted);
106 +
107 + __secretmem_unaccount_pages(state, nr_pages_accounted);
108 + }
109 +
50 110 static vm_fault_t secretmem_fault(struct vm_fault *vmf)
51 111 {
52 112 struct address_space *mapping = vmf->vma->vm_file->f_mapping;
53 113 struct inode *inode = file_inode(vmf->vma->vm_file);
114 + struct secretmem_inode_state *state = inode->i_private;
54 115 pgoff_t offset = vmf->pgoff;
55 116 gfp_t gfp = vmf->gfp_mask;
56 117 unsigned long addr;
@@ -72,8 +133,15 @@ retry:
72 133 goto out;
73 134 }
74 135
136 + if (!secretmem_account_folio(state, folio)) {
137 + folio_put(folio);
138 + ret = VM_FAULT_SIGBUS;
139 + goto out;
140 + }
141 +
75 142 err = set_direct_map_invalid_noflush(folio_page(folio, 0));
76 143 if (err) {
144 + secretmem_unaccount_folio(state, folio);
77 145 folio_put(folio);
78 146 ret = vmf_error(err);
79 147 goto out;
@@ -82,6 +150,7 @@ retry:
82 150 __folio_mark_uptodate(folio);
83 151 err = filemap_add_folio(mapping, folio, offset, gfp);
84 152 if (unlikely(err)) {
153 + secretmem_unaccount_folio(state, folio);
85 154 /*
86 155 * If a split of large page was required, it
87 156 * already happened when we marked the page invalid
@@ -112,22 +181,30 @@ static const struct vm_operations_struct secretmem_vm_ops = {
112 181 .fault = secretmem_fault,
113 182 };
114 183
184 + static void secretmem_destroy_inode_priv(struct inode *inode)
185 + {
186 + struct secretmem_inode_state *state = inode->i_private;
187 +
188 + secretmem_unaccount_all_folios(state);
189 + free_uid(state->user);
190 + kfree(state);
191 + inode->i_private = NULL;
192 + }
193 +
115 194 static int secretmem_release(struct inode *inode, struct file *file)
116 195 {
117 196 atomic_dec(&secretmem_users);
197 + secretmem_destroy_inode_priv(inode);
198 +
118 199 return 0;
119 200 }
120 201
121 202 static int secretmem_mmap_prepare(struct vm_area_desc *desc)
122 203 {
123 - const unsigned long len = vma_desc_size(desc);
124 -
125 204 if (!vma_desc_test_any(desc, VMA_SHARED_BIT, VMA_MAYSHARE_BIT))
126 205 return -EINVAL;
127 206
128 - vma_desc_set_flags(desc, VMA_LOCKED_BIT, VMA_DONTDUMP_BIT);
129 - if (!mlock_future_ok(desc->mm, /*is_vma_locked=*/ true, len))
130 - return -EAGAIN;
207 + vma_desc_set_flags(desc, VMA_DONTDUMP_BIT);
131 208 desc->vm_ops = &secretmem_vm_ops;
132 209
133 210 return 0;
@@ -187,20 +264,40 @@ static const struct inode_operations secretmem_iops = {
187 264
188 265 static struct vfsmount *secretmem_mnt;
189 266
267 + static int secretmem_init_inode_priv(struct inode *inode)
268 + {
269 + struct secretmem_inode_state *state;
270 +
271 + state = kzalloc_obj(*state);
272 + if (!state)
273 + return -ENOMEM;
274 +
275 + state->user = get_uid(current_user());
276 + inode->i_private = state;
277 + return 0;
278 + }
279 +
190 280 static struct file *secretmem_file_create(unsigned long flags)
191 281 {
192 282 struct file *file;
193 283 struct inode *inode;
194 284 const char *anon_name = "[secretmem]";
285 + int err;
195 286
196 287 inode = anon_inode_make_secure_inode(secretmem_mnt->mnt_sb, anon_name, NULL);
197 288 if (IS_ERR(inode))
198 289 return ERR_CAST(inode);
199 290
291 + err = secretmem_init_inode_priv(inode);
292 + if (err)
293 + goto err_free_inode;
294 +
200 295 file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
201 296 O_RDWR | O_LARGEFILE, &secretmem_fops);
202 - if (IS_ERR(file))
203 - goto err_free_inode;
297 + if (IS_ERR(file)) {
298 + err = PTR_ERR(file);
299 + goto err_free_priv;
300 + }
204 301
205 302 mapping_set_gfp_mask(inode->i_mapping, GFP_USER);
206 303 mapping_set_unevictable(inode->i_mapping);
@@ -215,10 +312,11 @@ static struct file *secretmem_file_create(unsigned long flags)
215 312 atomic_inc(&secretmem_users);
216 313
217 314 return file;
218 -
315 + err_free_priv:
316 + secretmem_destroy_inode_priv(inode);
219 317 err_free_inode:
220 318 iput(inode);
221 - return file;
319 + return ERR_PTR(err);
222 320 }
223 321
224 322 SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)
modified mm/userfaultfd.c
@@ -2171,8 +2171,10 @@ static ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
2171 2171 }
2172 2172
2173 2173 if (err) {
2174 - if (err == -EAGAIN)
2174 + if (err == -EAGAIN) {
2175 + err = 0;
2175 2176 continue;
2177 + }
2176 2178 break;
2177 2179 }
2178 2180
modified net/batman-adv/hard-interface.c
@@ -981,7 +981,7 @@ batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
981 981
982 982 ASSERT_RTNL();
983 983
984 - device_state = kzalloc_obj(*device_state, GFP_KERNEL);
984 + device_state = kzalloc_obj(*device_state);
985 985 if (!device_state)
986 986 return -ENOMEM;
987 987
modified net/bluetooth/hci_core.c
@@ -2632,11 +2632,11 @@ int hci_register_dev(struct hci_dev *hdev)
2632 2632 if (error)
2633 2633 BT_WARN("register suspend notifier failed error:%d\n", error);
2634 2634
2635 - queue_work(hdev->req_workqueue, &hdev->power_on);
2636 -
2637 2635 idr_init(&hdev->adv_monitors_idr);
2638 2636 msft_register(hdev);
2639 2637
2638 + queue_work(hdev->req_workqueue, &hdev->power_on);
2639 +
2640 2640 return id;
2641 2641
2642 2642 err_wqueue:
modified net/bluetooth/hci_sync.c
@@ -6423,8 +6423,7 @@ static int hci_update_event_filter_sync(struct hci_dev *hdev)
6423 6423 goto update_scan;
6424 6424 }
6425 6425
6426 - accept_list = kmalloc_array(num_entries, sizeof(*accept_list),
6427 - GFP_KERNEL);
6426 + accept_list = kmalloc_objs(*accept_list, num_entries);
6428 6427 if (!accept_list) {
6429 6428 hci_dev_unlock(hdev);
6430 6429 return -ENOMEM;
modified net/bluetooth/l2cap_core.c
@@ -1337,7 +1337,7 @@ static void l2cap_le_connect(struct l2cap_chan *chan)
1337 1337 struct l2cap_ecred_conn_data {
1338 1338 struct {
1339 1339 struct l2cap_ecred_conn_req_hdr req;
1340 - __le16 scid[5];
1340 + __le16 scid[L2CAP_ECRED_CONN_SCID_MAX];
1341 1341 } __packed pdu;
1342 1342 struct l2cap_chan *chan;
1343 1343 struct pid *pid;
@@ -1352,7 +1352,7 @@ static void l2cap_ecred_defer_connect(struct l2cap_chan *chan, void *data)
1352 1352 if (chan == conn->chan)
1353 1353 return;
1354 1354
1355 - if (!test_and_clear_bit(FLAG_DEFER_SETUP, &chan->flags))
1355 + if (!test_bit(FLAG_DEFER_SETUP, &chan->flags))
1356 1356 return;
1357 1357
1358 1358 pid = chan->ops->get_peer_pid(chan);
@@ -1362,9 +1362,16 @@ static void l2cap_ecred_defer_connect(struct l2cap_chan *chan, void *data)
1362 1362 chan->mode != L2CAP_MODE_EXT_FLOWCTL || chan->state != BT_CONNECT)
1363 1363 return;
1364 1364
1365 + if (!test_and_clear_bit(FLAG_DEFER_SETUP, &chan->flags))
1366 + return;
1367 +
1365 1368 if (test_and_set_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags))
1366 1369 return;
1367 1370
1371 + /* Unreachable, checked in l2cap_connect (+timer drops it if reached) */
1372 + if (WARN_ON_ONCE(conn->count >= ARRAY_SIZE(conn->pdu.scid)))
1373 + return;
1374 +
1368 1375 l2cap_ecred_init(chan, 0);
1369 1376
1370 1377 /* Set the same ident so we can match on the rsp */
@@ -3894,6 +3901,9 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data)
3894 3901 struct l2cap_ecred_conn_rsp *rsp_flex =
3895 3902 container_of(&rsp->pdu.rsp, struct l2cap_ecred_conn_rsp, hdr);
3896 3903
3904 + if (chan->mode != L2CAP_MODE_EXT_FLOWCTL)
3905 + return;
3906 +
3897 3907 /* Check if channel for outgoing connection or if it wasn't deferred
3898 3908 * since in those cases it must be skipped.
3899 3909 */
@@ -3904,6 +3914,10 @@ static void l2cap_ecred_rsp_defer(struct l2cap_chan *chan, void *data)
3904 3914 /* Reset ident so only one response is sent */
3905 3915 chan->ident = 0;
3906 3916
3917 + /* Unreachable, check in l2cap_ecred_conn_req. If reached, drop rest */
3918 + if (WARN_ON_ONCE(rsp->count >= ARRAY_SIZE(rsp->pdu.scid)))
3919 + rsp->pdu.rsp.result = cpu_to_le16(L2CAP_CR_LE_NO_MEM);
3920 +
3907 3921 /* Include all channels pending with the same ident */
3908 3922 if (!rsp->pdu.rsp.result)
3909 3923 rsp_flex->dcid[rsp->count++] = cpu_to_le16(chan->scid);
@@ -5063,6 +5077,7 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
5063 5077 __set_chan_timer(chan, chan->ops->get_sndtimeo(chan));
5064 5078
5065 5079 chan->ident = cmd->ident;
5080 + chan->mode = L2CAP_MODE_LE_FLOWCTL;
5066 5081
5067 5082 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
5068 5083 l2cap_state_change(chan, BT_CONNECT2);
@@ -7369,6 +7384,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7369 7384 goto done;
7370 7385 }
7371 7386
7387 + mutex_lock(&conn->lock);
7388 + l2cap_chan_lock(chan);
7389 +
7372 7390 if (chan->mode == L2CAP_MODE_EXT_FLOWCTL) {
7373 7391 struct l2cap_chan_data data;
7374 7392
@@ -7376,19 +7394,20 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7376 7394 data.pid = chan->ops->get_peer_pid(chan);
7377 7395 data.count = 1;
7378 7396
7379 - l2cap_chan_list(conn, l2cap_chan_by_pid, &data);
7397 + __l2cap_chan_list(conn, l2cap_chan_by_pid, &data);
7398 +
7399 + /* Leave room for non-deferred channel that ends the group. */
7400 + if (test_bit(FLAG_DEFER_SETUP, &chan->flags))
7401 + data.count += 1;
7380 7402
7381 7403 /* Check if there isn't too many channels being connected */
7382 7404 if (data.count > L2CAP_ECRED_CONN_SCID_MAX) {
7383 7405 hci_conn_drop(hcon);
7384 7406 err = -EPROTO;
7385 - goto done;
7407 + goto chan_unlock;
7386 7408 }
7387 7409 }
7388 7410
7389 - mutex_lock(&conn->lock);
7390 - l2cap_chan_lock(chan);
7391 -
7392 7411 if (cid && __l2cap_get_chan_by_dcid(conn, cid)) {
7393 7412 hci_conn_drop(hcon);
7394 7413 err = -EBUSY;
modified net/bluetooth/msft.c
@@ -769,8 +769,8 @@ void msft_register(struct hci_dev *hdev)
769 769
770 770 INIT_LIST_HEAD(&msft->handle_map);
771 771 INIT_LIST_HEAD(&msft->address_filters);
772 - hdev->msft_data = msft;
773 772 mutex_init(&msft->filter_lock);
773 + hdev->msft_data = msft;
774 774 }
775 775
776 776 void msft_release(struct hci_dev *hdev)
modified net/bridge/br_multicast.c
@@ -808,7 +808,11 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
808 808 struct hlist_node *tmp;
809 809
810 810 rcu_assign_pointer(*pp, pg->next);
811 - hlist_del_init(&pg->mglist);
811 + /* Keep ->next (held under multicast_lock, freed later by the GC work):
812 + * a port->mglist teardown walk may have latched this node as its next,
813 + * and deleting other groups of the same port must not truncate it.
814 + */
815 + hlist_del_init_rcu(&pg->mglist);
812 816 br_multicast_eht_clean_sets(pg);
813 817 hlist_for_each_entry_safe(ent, tmp, &pg->src_list, node)
814 818 br_multicast_del_group_src(ent, false);
@@ -835,6 +839,13 @@ static void br_multicast_find_del_pg(struct net_bridge *br,
835 839 struct net_bridge_mdb_entry *mp;
836 840 struct net_bridge_port_group *p;
837 841
842 + /* A teardown walk over port->mglist can reach a group that an earlier
843 + * iteration already deleted as a side effect. It is off mp->ports by
844 + * now, so skip it instead of falling through to the WARN_ON() below.
845 + */
846 + if (hlist_unhashed(&pg->mglist))
847 + return;
848 +
838 849 mp = br_mdb_ip_get(br, &pg->key.addr);
839 850 if (WARN_ON(!mp))
840 851 return;
modified net/ceph/messenger.c
@@ -1003,7 +1003,6 @@ static struct page *ceph_msg_data_iter_next(struct ceph_msg_data_cursor *cursor,
1003 1003 * we'll get an iov_iter_get_pages2 variant that doesn't take
1004 1004 * page refs. Until then, just put the page ref.
1005 1005 */
1006 - VM_BUG_ON_PAGE(!PageWriteback(page) && page_count(page) < 2, page);
1007 1006 put_page(page);
1008 1007
1009 1008 *length = min_t(size_t, len, cursor->resid);
modified net/core/dev.c
@@ -12703,7 +12703,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net,
12703 12703 const char *pat, int new_ifindex,
12704 12704 struct netlink_ext_ack *extack)
12705 12705 {
12706 - struct netdev_name_node *name_node;
12706 + struct netdev_name_node *name_node, *tmp;
12707 12707 struct net *net_old = dev_net(dev);
12708 12708 char new_name[IFNAMSIZ] = {};
12709 12709 int err, new_nsid;
@@ -12749,13 +12749,19 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net,
12749 12749 }
12750 12750 /* Check that none of the altnames conflicts. */
12751 12751 err = -EEXIST;
12752 - netdev_for_each_altname(dev, name_node) {
12753 - if (netdev_name_in_use(net, name_node->name)) {
12754 - NL_SET_ERR_MSG_FMT(extack,
12755 - "An interface with the altname %s exists in the target netns",
12756 - name_node->name);
12757 - goto out;
12752 + netdev_for_each_altname_safe(dev, name_node, tmp) {
12753 + if (!netdev_name_in_use(net, name_node->name))
12754 + continue;
12755 +
12756 + if (!check_net(net_old)) {
12757 + __netdev_name_node_alt_destroy(name_node);
12758 + continue;
12758 12759 }
12760 +
12761 + NL_SET_ERR_MSG_FMT(extack,
12762 + "An interface with the altname %s exists in the target netns",
12763 + name_node->name);
12764 + goto out;
12759 12765 }
12760 12766
12761 12767 /* Check that new_ifindex isn't used yet. */
@@ -13210,7 +13216,6 @@ static struct pernet_operations __net_initdata netdev_net_ops = {
13210 13216
13211 13217 static void __net_exit default_device_exit_net(struct net *net)
13212 13218 {
13213 - struct netdev_name_node *name_node, *tmp;
13214 13219 struct net_device *dev, *aux;
13215 13220 /*
13216 13221 * Push all migratable network devices back to the
@@ -13234,10 +13239,6 @@ static void __net_exit default_device_exit_net(struct net *net)
13234 13239 if (netdev_name_in_use(&init_net, fb_name))
13235 13240 snprintf(fb_name, IFNAMSIZ, "dev%%d");
13236 13241
13237 - netdev_for_each_altname_safe(dev, name_node, tmp)
13238 - if (netdev_name_in_use(&init_net, name_node->name))
13239 - __netdev_name_node_alt_destroy(name_node);
13240 -
13241 13242 err = dev_change_net_namespace(dev, &init_net, fb_name);
13242 13243 if (err) {
13243 13244 pr_emerg("%s: failed to move %s to init_net: %d\n",
modified net/core/gro_cells.c
@@ -22,6 +22,8 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)
22 22 if (unlikely(!(dev->flags & IFF_UP)))
23 23 goto drop;
24 24
25 + skb_unset_transport_header(skb);
26 +
25 27 if (!gcells->cells || skb_cloned(skb) || netif_elide_gro(dev)) {
26 28 res = netif_rx(skb);
27 29 goto unlock;
modified net/core/page_pool.c
@@ -1073,7 +1073,8 @@ netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,
1073 1073 if (WARN_ON(size > max_size))
1074 1074 return 0;
1075 1075
1076 - size = ALIGN(size, dma_get_cache_alignment());
1076 + size = ALIGN(size, max_t(unsigned int, dma_get_cache_alignment(),
1077 + __alignof__(struct skb_shared_info)));
1077 1078 *offset = pool->frag_offset;
1078 1079
1079 1080 if (netmem && *offset + size > max_size) {
modified net/core/sock.c
@@ -2494,6 +2494,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
2494 2494 #ifdef CONFIG_BPF_SYSCALL
2495 2495 RCU_INIT_POINTER(newsk->sk_bpf_storage, NULL);
2496 2496 #endif
2497 + #if IS_ENABLED(CONFIG_INET_PSP)
2498 + RCU_INIT_POINTER(newsk->psp_assoc, NULL);
2499 + #endif
2497 2500
2498 2501 /* SANITY */
2499 2502 if (likely(newsk->sk_net_refcnt)) {
modified net/devlink/netlink.c
@@ -251,7 +251,7 @@ devlink_get_parent_from_attrs_lock(struct net *net, struct nlattr **attrs)
251 251 if (!attrs[DEVLINK_ATTR_PARENT_DEV])
252 252 return ERR_PTR(-EINVAL);
253 253
254 - tb = kcalloc(maxtype + 1, sizeof(*tb), GFP_KERNEL);
254 + tb = kzalloc_objs(*tb, maxtype + 1);
255 255 if (!tb)
256 256 return ERR_PTR(-ENOMEM);
257 257
modified net/devlink/param.c
@@ -330,13 +330,12 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
330 330 int err;
331 331 int i;
332 332
333 - default_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
334 - sizeof(*default_value), GFP_KERNEL);
333 + default_value = kzalloc_objs(*default_value,
334 + DEVLINK_PARAM_CMODE_MAX + 1);
335 335 if (!default_value)
336 336 return -ENOMEM;
337 337
338 - param_value = kcalloc(DEVLINK_PARAM_CMODE_MAX + 1,
339 - sizeof(*param_value), GFP_KERNEL);
338 + param_value = kzalloc_objs(*param_value, DEVLINK_PARAM_CMODE_MAX + 1);
340 339 if (!param_value) {
341 340 kfree(default_value);
342 341 return -ENOMEM;
modified net/ipv4/fib_semantics.c
@@ -874,7 +874,7 @@ static void fib_rebalance(struct fib_info *fi)
874 874 change_nexthops(fi) {
875 875 int upper_bound;
876 876
877 - if (nexthop_nh->fib_nh_flags & RTNH_F_DEAD) {
877 + if (!total || nexthop_nh->fib_nh_flags & RTNH_F_DEAD) {
878 878 upper_bound = -1;
879 879 } else if (ip_ignore_linkdown(nexthop_nh->fib_nh_dev) &&
880 880 nexthop_nh->fib_nh_flags & RTNH_F_LINKDOWN) {
modified net/ipv4/igmp.c
@@ -188,6 +188,10 @@ static void ip_ma_put(struct ip_mc_list *im)
188 188 }
189 189 }
190 190
191 + #define pmc_dereference(e, pmc) \
192 + rcu_dereference_protected(e, lockdep_is_held(&(pmc)->lock) || \
193 + lockdep_is_held(&(pmc)->interface->mc_tomb_lock))
194 +
191 195 #define for_each_pmc_rcu(in_dev, pmc) \
192 196 for (pmc = rcu_dereference(in_dev->mc_list); \
193 197 pmc != NULL; \
@@ -198,13 +202,28 @@ static void ip_ma_put(struct ip_mc_list *im)
198 202 pmc != NULL; \
199 203 pmc = rtnl_dereference(pmc->next_rcu))
200 204
205 + #define for_each_psf_mclock(pmc, psf) \
206 + for (psf = pmc_dereference((pmc)->sources, pmc); \
207 + psf; \
208 + psf = pmc_dereference(psf->sf_next, pmc))
209 +
210 + #define for_each_psf_rcu(im, psf) \
211 + for (psf = rcu_dereference((im)->sources); \
212 + psf; \
213 + psf = rcu_dereference(psf->sf_next))
214 +
215 + #define for_each_psf_tomb(pmc, psf) \
216 + for (psf = pmc_dereference((pmc)->tomb, pmc); \
217 + psf; \
218 + psf = pmc_dereference(psf->sf_next, pmc))
219 +
201 220 static void ip_sf_list_clear_all(struct ip_sf_list *psf)
202 221 {
203 222 struct ip_sf_list *next;
204 223
205 224 while (psf) {
206 - next = psf->sf_next;
207 - kfree(psf);
225 + next = rcu_dereference_protected(psf->sf_next, 1);
226 + kfree_rcu(psf, rcu);
208 227 psf = next;
209 228 }
210 229 }
@@ -349,7 +368,7 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
349 368 struct ip_sf_list *psf;
350 369 int scount = 0;
351 370
352 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
371 + for_each_psf_mclock(pmc, psf) {
353 372 if (!is_in(pmc, psf, type, gdeleted, sdeleted))
354 373 continue;
355 374 scount++;
@@ -494,7 +513,8 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
494 513 struct net *net = dev_net(dev);
495 514 struct igmpv3_report *pih;
496 515 struct igmpv3_grec *pgr = NULL;
497 - struct ip_sf_list *psf, *psf_next, *psf_prev, **psf_list;
516 + struct ip_sf_list *psf, *psf_next, *psf_prev;
517 + struct ip_sf_list __rcu **psf_list;
498 518 int scount, stotal, first, isquery, truncate;
499 519 unsigned int mtu;
500 520
@@ -517,7 +537,7 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
517 537
518 538 psf_list = sdeleted ? &pmc->tomb : &pmc->sources;
519 539
520 - if (!*psf_list)
540 + if (!rcu_access_pointer(*psf_list))
521 541 goto empty_source;
522 542
523 543 pih = skb ? igmpv3_report_hdr(skb) : NULL;
@@ -533,10 +553,12 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
533 553 }
534 554 first = 1;
535 555 psf_prev = NULL;
536 - for (psf = *psf_list; psf; psf = psf_next) {
556 + for (psf = pmc_dereference(*psf_list, pmc);
557 + psf;
558 + psf = psf_next) {
537 559 __be32 *psrc;
538 560
539 - psf_next = psf->sf_next;
561 + psf_next = pmc_dereference(psf->sf_next, pmc);
540 562
541 563 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) {
542 564 psf_prev = psf;
@@ -583,10 +605,12 @@ decrease_sf_crcount:
583 605 psf->sf_crcount--;
584 606 if ((sdeleted || gdeleted) && psf->sf_crcount == 0) {
585 607 if (psf_prev)
586 - psf_prev->sf_next = psf->sf_next;
608 + rcu_assign_pointer(psf_prev->sf_next,
609 + psf_next);
587 610 else
588 - *psf_list = psf->sf_next;
589 - kfree(psf);
611 + rcu_assign_pointer(*psf_list,
612 + psf_next);
613 + kfree_rcu(psf, rcu);
590 614 continue;
591 615 }
592 616 }
@@ -655,28 +679,29 @@ static int igmpv3_send_report(struct in_device *in_dev, struct ip_mc_list *pmc)
655 679 /*
656 680 * remove zero-count source records from a source filter list
657 681 */
658 - static void igmpv3_clear_zeros(struct ip_sf_list **ppsf)
682 + static void igmpv3_clear_zeros(struct ip_sf_list __rcu **ppsf)
659 683 {
660 684 struct ip_sf_list *psf_prev, *psf_next, *psf;
661 685
662 686 psf_prev = NULL;
663 - for (psf = *ppsf; psf; psf = psf_next) {
664 - psf_next = psf->sf_next;
687 + for (psf = rcu_dereference_protected(*ppsf, 1); psf; psf = psf_next) {
688 + psf_next = rcu_dereference_protected(psf->sf_next, 1);
665 689 if (psf->sf_crcount == 0) {
666 690 if (psf_prev)
667 - psf_prev->sf_next = psf->sf_next;
691 + rcu_assign_pointer(psf_prev->sf_next, psf_next);
668 692 else
669 - *ppsf = psf->sf_next;
670 - kfree(psf);
671 - } else
693 + rcu_assign_pointer(*ppsf, psf_next);
694 + kfree_rcu(psf, rcu);
695 + } else {
672 696 psf_prev = psf;
697 + }
673 698 }
674 699 }
675 700
676 701 static void kfree_pmc(struct ip_mc_list *pmc)
677 702 {
678 - ip_sf_list_clear_all(pmc->sources);
679 - ip_sf_list_clear_all(pmc->tomb);
703 + ip_sf_list_clear_all(rcu_dereference_protected(pmc->sources, 1));
704 + ip_sf_list_clear_all(rcu_dereference_protected(pmc->tomb, 1));
680 705 kfree(pmc);
681 706 }
682 707
@@ -710,7 +735,8 @@ static void igmpv3_send_cr(struct in_device *in_dev)
710 735 igmpv3_clear_zeros(&pmc->sources);
711 736 }
712 737 }
713 - if (pmc->crcount == 0 && !pmc->tomb && !pmc->sources) {
738 + if (pmc->crcount == 0 && !rcu_access_pointer(pmc->tomb) &&
739 + !rcu_access_pointer(pmc->sources)) {
714 740 if (pmc_prev)
715 741 pmc_prev->next = pmc_next;
716 742 else
@@ -896,7 +922,7 @@ static int igmp_xmarksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs)
896 922 int i, scount;
897 923
898 924 scount = 0;
899 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
925 + for_each_psf_mclock(pmc, psf) {
900 926 if (scount == nsrcs)
901 927 break;
902 928 for (i = 0; i < nsrcs; i++) {
@@ -927,7 +953,7 @@ static int igmp_marksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs)
927 953
928 954 /* mark INCLUDE-mode sources */
929 955 scount = 0;
930 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
956 + for_each_psf_mclock(pmc, psf) {
931 957 if (scount == nsrcs)
932 958 break;
933 959 for (i = 0; i < nsrcs; i++)
@@ -1228,11 +1254,12 @@ static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im,
1228 1254 if (pmc->sfmode == MCAST_INCLUDE) {
1229 1255 struct ip_sf_list *psf;
1230 1256
1257 + for_each_psf_mclock(im, psf)
1258 + psf->sf_crcount = pmc->crcount;
1231 1259 pmc->tomb = im->tomb;
1232 1260 pmc->sources = im->sources;
1233 - im->tomb = im->sources = NULL;
1234 - for (psf = pmc->sources; psf; psf = psf->sf_next)
1235 - psf->sf_crcount = pmc->crcount;
1261 + RCU_INIT_POINTER(im->tomb, NULL);
1262 + RCU_INIT_POINTER(im->sources, NULL);
1236 1263 }
1237 1264 spin_unlock_bh(&im->lock);
1238 1265
@@ -1271,9 +1298,18 @@ static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im)
1271 1298 if (pmc) {
1272 1299 im->interface = pmc->interface;
1273 1300 if (im->sfmode == MCAST_INCLUDE) {
1274 - swap(im->tomb, pmc->tomb);
1275 - swap(im->sources, pmc->sources);
1276 - for (psf = im->sources; psf; psf = psf->sf_next)
1301 + struct ip_sf_list *sources, *tomb;
1302 +
1303 + tomb = rcu_replace_pointer(im->tomb,
1304 + rcu_dereference_protected(pmc->tomb, 1),
1305 + lockdep_is_held(&im->lock));
1306 + rcu_assign_pointer(pmc->tomb, tomb);
1307 +
1308 + sources = rcu_replace_pointer(im->sources,
1309 + rcu_dereference_protected(pmc->sources, 1),
1310 + lockdep_is_held(&im->lock));
1311 + rcu_assign_pointer(pmc->sources, sources);
1312 + for_each_psf_mclock(im, psf)
1277 1313 psf->sf_crcount = in_dev->mr_qrv ?:
1278 1314 READ_ONCE(net->ipv4.sysctl_igmp_qrv);
1279 1315 } else {
@@ -1310,8 +1346,8 @@ static void igmpv3_clear_delrec(struct in_device *in_dev)
1310 1346 struct ip_sf_list *psf;
1311 1347
1312 1348 spin_lock_bh(&pmc->lock);
1313 - psf = pmc->tomb;
1314 - pmc->tomb = NULL;
1349 + psf = pmc_dereference(pmc->tomb, pmc);
1350 + RCU_INIT_POINTER(pmc->tomb, NULL);
1315 1351 spin_unlock_bh(&pmc->lock);
1316 1352 ip_sf_list_clear_all(psf);
1317 1353 }
@@ -1990,7 +2026,7 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
1990 2026 int rv = 0;
1991 2027
1992 2028 psf_prev = NULL;
1993 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
2029 + for_each_psf_mclock(pmc, psf) {
1994 2030 if (psf->sf_inaddr == *psfsrc)
1995 2031 break;
1996 2032 psf_prev = psf;
@@ -1999,7 +2035,7 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
1999 2035 /* source filter not found, or count wrong => bug */
2000 2036 return -ESRCH;
2001 2037 }
2002 - psf->sf_count[sfmode]--;
2038 + WRITE_ONCE(psf->sf_count[sfmode], psf->sf_count[sfmode] - 1);
2003 2039 if (psf->sf_count[sfmode] == 0) {
2004 2040 ip_rt_multicast_event(pmc->interface);
2005 2041 }
@@ -2011,19 +2047,28 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
2011 2047
2012 2048 /* no more filters for this source */
2013 2049 if (psf_prev)
2014 - psf_prev->sf_next = psf->sf_next;
2050 + rcu_assign_pointer(psf_prev->sf_next,
2051 + pmc_dereference(psf->sf_next, pmc));
2015 2052 else
2016 - pmc->sources = psf->sf_next;
2053 + rcu_assign_pointer(pmc->sources,
2054 + pmc_dereference(psf->sf_next, pmc));
2017 2055 #ifdef CONFIG_IP_MULTICAST
2018 2056 if (psf->sf_oldin &&
2019 2057 !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) {
2020 - psf->sf_crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
2021 - psf->sf_next = pmc->tomb;
2022 - pmc->tomb = psf;
2023 - rv = 1;
2024 - } else
2058 + struct ip_sf_list *dpsf = kmalloc_obj(*dpsf, GFP_ATOMIC);
2059 +
2060 + if (dpsf) {
2061 + *dpsf = *psf;
2062 + dpsf->sf_crcount = in_dev->mr_qrv ?:
2063 + READ_ONCE(net->ipv4.sysctl_igmp_qrv);
2064 + rcu_assign_pointer(dpsf->sf_next,
2065 + pmc_dereference(pmc->tomb, pmc));
2066 + rcu_assign_pointer(pmc->tomb, dpsf);
2067 + rv = 1;
2068 + }
2069 + }
2025 2070 #endif
2026 - kfree(psf);
2071 + kfree_rcu(psf, rcu);
2027 2072 }
2028 2073 return rv;
2029 2074 }
@@ -2060,7 +2105,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
2060 2105 err = -EINVAL;
2061 2106 if (!pmc->sfcount[sfmode])
2062 2107 goto out_unlock;
2063 - pmc->sfcount[sfmode]--;
2108 + WRITE_ONCE(pmc->sfcount[sfmode], pmc->sfcount[sfmode] - 1);
2064 2109 }
2065 2110 err = 0;
2066 2111 for (i = 0; i < sfcount; i++) {
@@ -2083,7 +2128,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
2083 2128 #ifdef CONFIG_IP_MULTICAST
2084 2129 pmc->crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
2085 2130 WRITE_ONCE(in_dev->mr_ifc_count, pmc->crcount);
2086 - for (psf = pmc->sources; psf; psf = psf->sf_next)
2131 + for_each_psf_mclock(pmc, psf)
2087 2132 psf->sf_crcount = 0;
2088 2133 igmp_ifc_event(pmc->interface);
2089 2134 } else if (sf_setstate(pmc) || changerec) {
@@ -2104,7 +2149,7 @@ static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode,
2104 2149 struct ip_sf_list *psf, *psf_prev;
2105 2150
2106 2151 psf_prev = NULL;
2107 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
2152 + for_each_psf_mclock(pmc, psf) {
2108 2153 if (psf->sf_inaddr == *psfsrc)
2109 2154 break;
2110 2155 psf_prev = psf;
@@ -2114,12 +2159,12 @@ static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode,
2114 2159 if (!psf)
2115 2160 return -ENOBUFS;
2116 2161 psf->sf_inaddr = *psfsrc;
2117 - if (psf_prev) {
2118 - psf_prev->sf_next = psf;
2119 - } else
2120 - pmc->sources = psf;
2162 + if (psf_prev)
2163 + rcu_assign_pointer(psf_prev->sf_next, psf);
2164 + else
2165 + rcu_assign_pointer(pmc->sources, psf);
2121 2166 }
2122 - psf->sf_count[sfmode]++;
2167 + WRITE_ONCE(psf->sf_count[sfmode], psf->sf_count[sfmode] + 1);
2123 2168 if (psf->sf_count[sfmode] == 1) {
2124 2169 ip_rt_multicast_event(pmc->interface);
2125 2170 }
@@ -2132,13 +2177,15 @@ static void sf_markstate(struct ip_mc_list *pmc)
2132 2177 struct ip_sf_list *psf;
2133 2178 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE];
2134 2179
2135 - for (psf = pmc->sources; psf; psf = psf->sf_next)
2180 + for_each_psf_mclock(pmc, psf) {
2136 2181 if (pmc->sfcount[MCAST_EXCLUDE]) {
2137 2182 psf->sf_oldin = mca_xcount ==
2138 2183 psf->sf_count[MCAST_EXCLUDE] &&
2139 2184 !psf->sf_count[MCAST_INCLUDE];
2140 - } else
2185 + } else {
2141 2186 psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0;
2187 + }
2188 + }
2142 2189 }
2143 2190
2144 2191 static int sf_setstate(struct ip_mc_list *pmc)
@@ -2149,27 +2196,31 @@ static int sf_setstate(struct ip_mc_list *pmc)
2149 2196 int new_in, rv;
2150 2197
2151 2198 rv = 0;
2152 - for (psf = pmc->sources; psf; psf = psf->sf_next) {
2199 + for_each_psf_mclock(pmc, psf) {
2153 2200 if (pmc->sfcount[MCAST_EXCLUDE]) {
2154 2201 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] &&
2155 2202 !psf->sf_count[MCAST_INCLUDE];
2156 - } else
2203 + } else {
2157 2204 new_in = psf->sf_count[MCAST_INCLUDE] != 0;
2205 + }
2158 2206 if (new_in) {
2159 2207 if (!psf->sf_oldin) {
2160 2208 struct ip_sf_list *prev = NULL;
2161 2209
2162 - for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) {
2210 + for_each_psf_tomb(pmc, dpsf) {
2163 2211 if (dpsf->sf_inaddr == psf->sf_inaddr)
2164 2212 break;
2165 2213 prev = dpsf;
2166 2214 }
2167 2215 if (dpsf) {
2216 + struct ip_sf_list *dpsf_next;
2217 +
2218 + dpsf_next = pmc_dereference(dpsf->sf_next, pmc);
2168 2219 if (prev)
2169 - prev->sf_next = dpsf->sf_next;
2220 + rcu_assign_pointer(prev->sf_next, dpsf_next);
2170 2221 else
2171 - pmc->tomb = dpsf->sf_next;
2172 - kfree(dpsf);
2222 + rcu_assign_pointer(pmc->tomb, dpsf_next);
2223 + kfree_rcu(dpsf, rcu);
2173 2224 }
2174 2225 psf->sf_crcount = qrv;
2175 2226 rv++;
@@ -2181,17 +2232,19 @@ static int sf_setstate(struct ip_mc_list *pmc)
2181 2232 * add or update "delete" records if an active filter
2182 2233 * is now inactive
2183 2234 */
2184 - for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next)
2235 + for_each_psf_tomb(pmc, dpsf) {
2185 2236 if (dpsf->sf_inaddr == psf->sf_inaddr)
2186 2237 break;
2238 + }
2187 2239 if (!dpsf) {
2188 2240 dpsf = kmalloc_obj(*dpsf, GFP_ATOMIC);
2189 2241 if (!dpsf)
2190 2242 continue;
2191 2243 *dpsf = *psf;
2192 2244 /* pmc->lock held by callers */
2193 - dpsf->sf_next = pmc->tomb;
2194 - pmc->tomb = dpsf;
2245 + rcu_assign_pointer(dpsf->sf_next,
2246 + pmc_dereference(pmc->tomb, pmc));
2247 + rcu_assign_pointer(pmc->tomb, dpsf);
2195 2248 }
2196 2249 dpsf->sf_crcount = qrv;
2197 2250 rv++;
@@ -2231,7 +2284,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
2231 2284 #endif
2232 2285 isexclude = pmc->sfmode == MCAST_EXCLUDE;
2233 2286 if (!delta)
2234 - pmc->sfcount[sfmode]++;
2287 + WRITE_ONCE(pmc->sfcount[sfmode], pmc->sfcount[sfmode] + 1);
2235 2288 err = 0;
2236 2289 for (i = 0; i < sfcount; i++) {
2237 2290 err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i]);
@@ -2242,7 +2295,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
2242 2295 int j;
2243 2296
2244 2297 if (!delta)
2245 - pmc->sfcount[sfmode]--;
2298 + WRITE_ONCE(pmc->sfcount[sfmode], pmc->sfcount[sfmode] - 1);
2246 2299 for (j = 0; j < i; j++)
2247 2300 (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[j]);
2248 2301 } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) {
@@ -2262,7 +2315,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
2262 2315
2263 2316 pmc->crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv);
2264 2317 WRITE_ONCE(in_dev->mr_ifc_count, pmc->crcount);
2265 - for (psf = pmc->sources; psf; psf = psf->sf_next)
2318 + for_each_psf_mclock(pmc, psf)
2266 2319 psf->sf_crcount = 0;
2267 2320 igmp_ifc_event(in_dev);
2268 2321 } else if (sf_setstate(pmc)) {
@@ -2278,13 +2331,13 @@ static void ip_mc_clear_src(struct ip_mc_list *pmc)
2278 2331 struct ip_sf_list *tomb, *sources;
2279 2332
2280 2333 spin_lock_bh(&pmc->lock);
2281 - tomb = pmc->tomb;
2282 - pmc->tomb = NULL;
2283 - sources = pmc->sources;
2284 - pmc->sources = NULL;
2334 + tomb = pmc_dereference(pmc->tomb, pmc);
2335 + RCU_INIT_POINTER(pmc->tomb, NULL);
2336 + sources = pmc_dereference(pmc->sources, pmc);
2337 + RCU_INIT_POINTER(pmc->sources, NULL);
2285 2338 pmc->sfmode = MCAST_EXCLUDE;
2286 - pmc->sfcount[MCAST_INCLUDE] = 0;
2287 - pmc->sfcount[MCAST_EXCLUDE] = 1;
2339 + WRITE_ONCE(pmc->sfcount[MCAST_INCLUDE], 0);
2340 + WRITE_ONCE(pmc->sfcount[MCAST_EXCLUDE], 1);
2288 2341 spin_unlock_bh(&pmc->lock);
2289 2342
2290 2343 ip_sf_list_clear_all(tomb);
@@ -2866,20 +2919,19 @@ int ip_check_mc_rcu(struct in_device *in_dev, __be32 mc_addr, __be32 src_addr, u
2866 2919 rv = 1;
2867 2920 } else if (im) {
2868 2921 if (src_addr) {
2869 - spin_lock_bh(&im->lock);
2870 - for (psf = im->sources; psf; psf = psf->sf_next) {
2922 + for_each_psf_rcu(im, psf) {
2871 2923 if (psf->sf_inaddr == src_addr)
2872 2924 break;
2873 2925 }
2874 2926 if (psf)
2875 - rv = psf->sf_count[MCAST_INCLUDE] ||
2876 - psf->sf_count[MCAST_EXCLUDE] !=
2877 - im->sfcount[MCAST_EXCLUDE];
2927 + rv = READ_ONCE(psf->sf_count[MCAST_INCLUDE]) ||
2928 + READ_ONCE(psf->sf_count[MCAST_EXCLUDE]) !=
2929 + READ_ONCE(im->sfcount[MCAST_EXCLUDE]);
2878 2930 else
2879 - rv = im->sfcount[MCAST_EXCLUDE] != 0;
2880 - spin_unlock_bh(&im->lock);
2881 - } else
2931 + rv = READ_ONCE(im->sfcount[MCAST_EXCLUDE]) != 0;
2932 + } else {
2882 2933 rv = 1; /* unspecified source; tentatively allow */
2934 + }
2883 2935 }
2884 2936 return rv;
2885 2937 }
@@ -3043,7 +3095,7 @@ static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq)
3043 3095 im = rcu_dereference(idev->mc_list);
3044 3096 if (likely(im)) {
3045 3097 spin_lock_bh(&im->lock);
3046 - psf = im->sources;
3098 + psf = pmc_dereference(im->sources, im);
3047 3099 if (likely(psf)) {
3048 3100 state->im = im;
3049 3101 state->idev = idev;
@@ -3059,7 +3111,7 @@ static struct ip_sf_list *igmp_mcf_get_next(struct seq_file *seq, struct ip_sf_l
3059 3111 {
3060 3112 struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq);
3061 3113
3062 - psf = psf->sf_next;
3114 + psf = pmc_dereference(psf->sf_next, state->im);
3063 3115 while (!psf) {
3064 3116 spin_unlock_bh(&state->im->lock);
3065 3117 state->im = state->im->next;
@@ -3075,7 +3127,7 @@ static struct ip_sf_list *igmp_mcf_get_next(struct seq_file *seq, struct ip_sf_l
3075 3127 state->im = rcu_dereference(state->idev->mc_list);
3076 3128 }
3077 3129 spin_lock_bh(&state->im->lock);
3078 - psf = state->im->sources;
3130 + psf = pmc_dereference(state->im->sources, state->im);
3079 3131 }
3080 3132 out:
3081 3133 return psf;
modified net/ipv4/tcp.c
@@ -3182,8 +3182,7 @@ void __tcp_close(struct sock *sk, long timeout)
3182 3182 /* Unread data was tossed, zap the connection. */
3183 3183 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONCLOSE);
3184 3184 tcp_set_state(sk, TCP_CLOSE);
3185 - tcp_send_active_reset(sk, sk->sk_allocation,
3186 - SK_RST_REASON_TCP_ABORT_ON_CLOSE);
3185 + tcp_send_active_reset(sk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
3187 3186 } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
3188 3187 /* Check zero linger _after_ checking for unread data. */
3189 3188 sk->sk_prot->disconnect(sk, 0);
@@ -3257,7 +3256,7 @@ adjudge_to_death:
3257 3256 struct tcp_sock *tp = tcp_sk(sk);
3258 3257 if (READ_ONCE(tp->linger2) < 0) {
3259 3258 tcp_set_state(sk, TCP_CLOSE);
3260 - tcp_send_active_reset(sk, GFP_ATOMIC,
3259 + tcp_send_active_reset(sk,
3261 3260 SK_RST_REASON_TCP_ABORT_ON_LINGER);
3262 3261 __NET_INC_STATS(sock_net(sk),
3263 3262 LINUX_MIB_TCPABORTONLINGER);
@@ -3276,7 +3275,7 @@ adjudge_to_death:
3276 3275 if (sk->sk_state != TCP_CLOSE) {
3277 3276 if (tcp_check_oom(sk, 0)) {
3278 3277 tcp_set_state(sk, TCP_CLOSE);
3279 - tcp_send_active_reset(sk, GFP_ATOMIC,
3278 + tcp_send_active_reset(sk,
3280 3279 SK_RST_REASON_TCP_ABORT_ON_MEMORY);
3281 3280 __NET_INC_STATS(sock_net(sk),
3282 3281 LINUX_MIB_TCPABORTONMEMORY);
@@ -3377,14 +3376,14 @@ int tcp_disconnect(struct sock *sk, int flags)
3377 3376 } else if (unlikely(tp->repair)) {
3378 3377 WRITE_ONCE(sk->sk_err, ECONNABORTED);
3379 3378 } else if (tcp_need_reset(old_state)) {
3380 - tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_TCP_STATE);
3379 + tcp_send_active_reset(sk, SK_RST_REASON_TCP_STATE);
3381 3380 WRITE_ONCE(sk->sk_err, ECONNRESET);
3382 3381 } else if (tp->snd_nxt != tp->write_seq &&
3383 3382 (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) {
3384 3383 /* The last check adjusts for discrepancy of Linux wrt. RFC
3385 3384 * states
3386 3385 */
3387 - tcp_send_active_reset(sk, gfp_any(),
3386 + tcp_send_active_reset(sk,
3388 3387 SK_RST_REASON_TCP_DISCONNECT_WITH_DATA);
3389 3388 WRITE_ONCE(sk->sk_err, ECONNRESET);
3390 3389 } else if (old_state == TCP_SYN_SENT)
@@ -4562,9 +4561,11 @@ int do_tcp_getsockopt(struct sock *sk, int level,
4562 4561 if (copy_from_sockptr(&len, optlen, sizeof(int)))
4563 4562 return -EFAULT;
4564 4563
4565 - ca_ops = icsk->icsk_ca_ops;
4564 + rcu_read_lock();
4565 + ca_ops = READ_ONCE(icsk->icsk_ca_ops);
4566 4566 if (ca_ops && ca_ops->get_info)
4567 4567 sz = ca_ops->get_info(sk, ~0U, &attr, &info);
4568 + rcu_read_unlock();
4568 4569
4569 4570 len = min_t(unsigned int, len, sz);
4570 4571 if (copy_to_sockptr(optlen, &len, sizeof(int)))
@@ -4577,16 +4578,24 @@ int do_tcp_getsockopt(struct sock *sk, int level,
4577 4578 val = !inet_csk_in_pingpong_mode(sk);
4578 4579 break;
4579 4580
4580 - case TCP_CONGESTION:
4581 + case TCP_CONGESTION: {
4582 + char ca_name[TCP_CA_NAME_MAX] = {};
4583 +
4581 4584 if (copy_from_sockptr(&len, optlen, sizeof(int)))
4582 4585 return -EFAULT;
4583 4586 len = min_t(unsigned int, len, TCP_CA_NAME_MAX);
4584 4587 if (copy_to_sockptr(optlen, &len, sizeof(int)))
4585 4588 return -EFAULT;
4586 - if (copy_to_sockptr(optval, icsk->icsk_ca_ops->name, len))
4589 +
4590 + rcu_read_lock();
4591 + memcpy(ca_name, READ_ONCE(icsk->icsk_ca_ops)->name,
4592 + sizeof(ca_name));
4593 + rcu_read_unlock();
4594 +
4595 + if (copy_to_sockptr(optval, ca_name, len))
4587 4596 return -EFAULT;
4588 4597 return 0;
4589 -
4598 + }
4590 4599 case TCP_ULP:
4591 4600 if (copy_from_sockptr(&len, optlen, sizeof(int)))
4592 4601 return -EFAULT;
@@ -5147,8 +5156,7 @@ int tcp_abort(struct sock *sk, int err)
5147 5156 bh_lock_sock(sk);
5148 5157
5149 5158 if (tcp_need_reset(sk->sk_state))
5150 - tcp_send_active_reset(sk, GFP_ATOMIC,
5151 - SK_RST_REASON_TCP_STATE);
5159 + tcp_send_active_reset(sk, SK_RST_REASON_TCP_STATE);
5152 5160 tcp_done_with_error(sk, err);
5153 5161
5154 5162 bh_unlock_sock(sk);
modified net/ipv4/tcp_cong.c
@@ -223,7 +223,7 @@ void tcp_assign_congestion_control(struct sock *sk)
223 223 ca = rcu_dereference(net->ipv4.tcp_congestion_control);
224 224 if (unlikely(!bpf_try_module_get(ca, ca->owner)))
225 225 ca = &tcp_reno;
226 - icsk->icsk_ca_ops = ca;
226 + WRITE_ONCE(icsk->icsk_ca_ops, ca);
227 227 rcu_read_unlock();
228 228
229 229 memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
@@ -253,7 +253,7 @@ static void tcp_reinit_congestion_control(struct sock *sk,
253 253 struct inet_connection_sock *icsk = inet_csk(sk);
254 254
255 255 tcp_cleanup_congestion_control(sk);
256 - icsk->icsk_ca_ops = ca;
256 + WRITE_ONCE(icsk->icsk_ca_ops, ca);
257 257 icsk->icsk_ca_setsockopt = 1;
258 258 memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
259 259
modified net/ipv4/tcp_dctcp.c
@@ -111,7 +111,7 @@ __bpf_kfunc static void dctcp_init(struct sock *sk)
111 111 /* No ECN support? Fall back to Reno. Also need to clear
112 112 * ECT from sk since it is set during 3WHS for DCTCP.
113 113 */
114 - inet_csk(sk)->icsk_ca_ops = &dctcp_reno;
114 + WRITE_ONCE(inet_csk(sk)->icsk_ca_ops, &dctcp_reno);
115 115 INET_ECN_dontxmit(sk);
116 116 }
117 117
@@ -228,7 +228,7 @@ static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
228 228 if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) ||
229 229 ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
230 230 memset(&info->dctcp, 0, sizeof(info->dctcp));
231 - if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) {
231 + if (READ_ONCE(inet_csk(sk)->icsk_ca_ops) != &dctcp_reno) {
232 232 info->dctcp.dctcp_enabled = 1;
233 233 info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
234 234 info->dctcp.dctcp_alpha = ca->dctcp_alpha;
modified net/ipv4/tcp_ipv4.c
@@ -2931,8 +2931,8 @@ static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
2931 2931 {
2932 2932 union bpf_tcp_iter_batch_item *new_batch;
2933 2933
2934 - new_batch = kvmalloc_array(new_batch_sz, sizeof(*new_batch),
2935 - flags | __GFP_NOWARN);
2934 + new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
2935 + flags | __GFP_NOWARN);
2936 2936 if (!new_batch)
2937 2937 return -ENOMEM;
2938 2938
modified net/ipv4/tcp_minisocks.c
@@ -507,7 +507,7 @@ void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst)
507 507 ca = tcp_ca_find_key(ca_key);
508 508 if (likely(ca && bpf_try_module_get(ca, ca->owner))) {
509 509 icsk->icsk_ca_dst_locked = tcp_ca_dst_locked(dst);
510 - icsk->icsk_ca_ops = ca;
510 + WRITE_ONCE(icsk->icsk_ca_ops, ca);
511 511 ca_got_dst = true;
512 512 }
513 513 rcu_read_unlock();
modified net/ipv4/tcp_offload.c
@@ -332,6 +332,7 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb,
332 332 flush |= skb->ip_summed != p->ip_summed;
333 333 flush |= skb->csum_level != p->csum_level;
334 334 flush |= NAPI_GRO_CB(p)->count >= 64;
335 + flush |= NAPI_GRO_CB(p)->is_flist != NAPI_GRO_CB(skb)->is_flist;
335 336 skb_set_network_header(skb, skb_gro_receive_network_offset(skb));
336 337
337 338 if (flush || skb_gro_receive_list(p, skb))
@@ -395,12 +396,20 @@ static void tcp4_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
395 396 struct net *net;
396 397 int iif, sdif;
397 398
398 - if (likely(!(skb->dev->features & NETIF_F_GRO_FRAGLIST)))
399 - return;
400 -
401 399 p = tcp_gro_lookup(head, th);
402 400 if (p) {
403 - NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
401 + /* flist GRO applies to consecutive non-GSO skbs */
402 + if (!skb_is_gso(skb) || !NAPI_GRO_CB(p)->is_flist) {
403 + NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
404 + return;
405 + }
406 +
407 + /* Fall back to the regular GRO path */
408 + if (NAPI_GRO_CB(p)->count == 1)
409 + NAPI_GRO_CB(p)->is_flist = 0;
410 +
411 + NAPI_GRO_CB(skb)->is_flist = 0;
412 +
404 413 return;
405 414 }
406 415
@@ -410,7 +419,7 @@ static void tcp4_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
410 419 sk = __inet_lookup_established(net, iph->saddr, th->source,
411 420 iph->daddr, ntohs(th->dest),
412 421 iif, sdif);
413 - NAPI_GRO_CB(skb)->is_flist = !sk;
422 + NAPI_GRO_CB(skb)->is_flist = !sk && !skb_is_gso(skb);
414 423 if (sk)
415 424 sock_gen_put(sk);
416 425 }
@@ -430,7 +439,8 @@ struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb)
430 439 if (!th)
431 440 goto flush;
432 441
433 - tcp4_check_fraglist_gro(head, skb, th);
442 + if (unlikely(skb->dev->features & NETIF_F_GRO_FRAGLIST))
443 + tcp4_check_fraglist_gro(head, skb, th);
434 444
435 445 return tcp_gro_receive(head, skb, th);
436 446
modified net/ipv4/tcp_output.c
@@ -3849,9 +3849,9 @@ void tcp_send_fin(struct sock *sk)
3849 3849 * was unread data in the receive queue. This behavior is recommended
3850 3850 * by RFC 2525, section 2.17. -DaveM
3851 3851 */
3852 - void tcp_send_active_reset(struct sock *sk, gfp_t priority,
3853 - enum sk_rst_reason reason)
3852 + void tcp_send_active_reset(struct sock *sk, enum sk_rst_reason reason)
3854 3853 {
3854 + gfp_t priority = sk_gfp_mask(sk, GFP_ATOMIC | __GFP_NOWARN);
3855 3855 struct sk_buff *skb;
3856 3856
3857 3857 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTRSTS);
@@ -4092,7 +4092,7 @@ static void tcp_ca_dst_init(struct sock *sk, const struct dst_entry *dst)
4092 4092 if (likely(ca && bpf_try_module_get(ca, ca->owner))) {
4093 4093 bpf_module_put(icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner);
4094 4094 icsk->icsk_ca_dst_locked = tcp_ca_dst_locked(dst);
4095 - icsk->icsk_ca_ops = ca;
4095 + WRITE_ONCE(icsk->icsk_ca_ops, ca);
4096 4096 }
4097 4097 rcu_read_unlock();
4098 4098 }
modified net/ipv4/tcp_timer.c
@@ -126,7 +126,7 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset)
126 126 (!tp->snd_wnd && !tp->packets_out))
127 127 do_reset = true;
128 128 if (do_reset)
129 - tcp_send_active_reset(sk, GFP_ATOMIC,
129 + tcp_send_active_reset(sk,
130 130 SK_RST_REASON_TCP_ABORT_ON_MEMORY);
131 131 tcp_done(sk);
132 132 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
@@ -809,7 +809,7 @@ static void tcp_keepalive_timer(struct timer_list *t)
809 809 goto out;
810 810 }
811 811 }
812 - tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_TCP_STATE);
812 + tcp_send_active_reset(sk, SK_RST_REASON_TCP_STATE);
813 813 goto death;
814 814 }
815 815
@@ -836,7 +836,7 @@ static void tcp_keepalive_timer(struct timer_list *t)
836 836 icsk->icsk_probes_out > 0) ||
837 837 (user_timeout == 0 &&
838 838 icsk->icsk_probes_out >= keepalive_probes(tp))) {
839 - tcp_send_active_reset(sk, GFP_ATOMIC,
839 + tcp_send_active_reset(sk,
840 840 SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT);
841 841 tcp_write_err(sk);
842 842 goto out;
modified net/ipv4/udp.c
@@ -900,6 +900,15 @@ out:
900 900 return sk;
901 901 }
902 902
903 + static void udp_err_update_exception(struct net *net, struct sk_buff *skb,
904 + int type, int code, u32 info)
905 + {
906 + if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
907 + ipv4_update_pmtu(skb, net, info, 0, IPPROTO_UDP);
908 + else if (type == ICMP_REDIRECT)
909 + ipv4_redirect(skb, net, 0, IPPROTO_UDP);
910 + }
911 +
903 912 /*
904 913 * This routine is called by the ICMP module when it gets some
905 914 * sort of error condition. If err < 0 then the socket should
@@ -923,6 +932,8 @@ int udp_err(struct sk_buff *skb, u32 info)
923 932 int harderr;
924 933 int err;
925 934
935 + udp_err_update_exception(net, skb, type, code, info);
936 +
926 937 uh = (struct udphdr *)(skb->data + (iph->ihl << 2));
927 938 sk = __udp4_lib_lookup(net, iph->daddr, uh->dest,
928 939 iph->saddr, uh->source, skb->dev->ifindex,
@@ -2166,10 +2177,10 @@ int __udp_disconnect(struct sock *sk, int flags)
2166 2177 */
2167 2178
2168 2179 sk->sk_state = TCP_CLOSE;
2169 - inet->inet_daddr = 0;
2180 + WRITE_ONCE(inet->inet_daddr, 0);
2170 2181 inet->inet_dport = 0;
2171 2182 sock_rps_reset_rxhash(sk);
2172 - sk->sk_bound_dev_if = 0;
2183 + WRITE_ONCE(sk->sk_bound_dev_if, 0);
2173 2184 if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) {
2174 2185 inet_reset_saddr(sk);
2175 2186 if (sk->sk_prot->rehash &&
modified net/ipv6/exthdrs.c
@@ -445,7 +445,7 @@ looped_back:
445 445 hdr->segments_left--;
446 446 addr = hdr->segments + hdr->segments_left;
447 447
448 - skb_push(skb, sizeof(struct ipv6hdr));
448 + skb_push(skb, -skb_network_offset(skb));
449 449
450 450 if (skb->ip_summed == CHECKSUM_COMPLETE)
451 451 seg6_update_csum(skb);
@@ -469,7 +469,7 @@ looped_back:
469 469 }
470 470 ipv6_hdr(skb)->hop_limit--;
471 471
472 - skb_pull(skb, sizeof(struct ipv6hdr));
472 + skb_pull(skb, skb_transport_offset(skb));
473 473 goto looped_back;
474 474 }
475 475
modified net/ipv6/ip6_gre.c
@@ -878,6 +878,7 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
878 878 static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
879 879 struct net_device *dev)
880 880 {
881 + struct ip_tunnel_info *tun_info = NULL;
881 882 struct ip6_tnl *t = netdev_priv(dev);
882 883 __be16 payload_protocol;
883 884 int ret;
@@ -888,6 +889,9 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
888 889 if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
889 890 goto tx_err;
890 891
892 + if (t->parms.collect_md)
893 + tun_info = skb_tunnel_info_txcheck(skb);
894 +
891 895 payload_protocol = skb_protocol(skb, true);
892 896 switch (payload_protocol) {
893 897 case htons(ETH_P_IP):
@@ -907,7 +911,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
907 911 return NETDEV_TX_OK;
908 912
909 913 tx_err:
910 - if (!t->parms.collect_md || !IS_ERR(skb_tunnel_info_txcheck(skb)))
914 + if (!IS_ERR(tun_info))
911 915 DEV_STATS_INC(dev, tx_errors);
912 916 DEV_STATS_INC(dev, tx_dropped);
913 917 kfree_skb(skb);
modified net/ipv6/mcast.c
@@ -240,7 +240,8 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,
240 240 return err;
241 241 }
242 242
243 - mc_lst->next = np->ipv6_mc_list;
243 + rcu_assign_pointer(mc_lst->next,
244 + sock_dereference(np->ipv6_mc_list, sk));
244 245 rcu_assign_pointer(np->ipv6_mc_list, mc_lst);
245 246
246 247 return 0;
@@ -300,7 +301,8 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr)
300 301 lnk = &mc_lst->next) {
301 302 if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
302 303 ipv6_addr_equal(&mc_lst->addr, addr)) {
303 - *lnk = mc_lst->next;
304 + rcu_assign_pointer(*lnk,
305 + sock_dereference(mc_lst->next, sk));
304 306 __ipv6_sock_mc_drop(sk, mc_lst);
305 307 return 0;
306 308 }
@@ -333,7 +335,8 @@ void __ipv6_sock_mc_close(struct sock *sk)
333 335 struct ipv6_mc_socklist *mc_lst;
334 336
335 337 while ((mc_lst = sock_dereference(np->ipv6_mc_list, sk)) != NULL) {
336 - np->ipv6_mc_list = mc_lst->next;
338 + rcu_assign_pointer(np->ipv6_mc_list,
339 + sock_dereference(mc_lst->next, sk));
337 340 __ipv6_sock_mc_drop(sk, mc_lst);
338 341 }
339 342 }
@@ -355,12 +358,12 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
355 358 {
356 359 struct ipv6_pinfo *inet6 = inet6_sk(sk);
357 360 struct in6_addr *source, *group;
361 + struct ip6_sf_socklist *newpsl, *psl;
358 362 struct net *net = sock_net(sk);
359 363 struct ipv6_mc_socklist *pmc;
360 - struct ip6_sf_socklist *psl;
361 364 struct inet6_dev *idev;
362 365 int leavegroup = 0;
363 - int i, j, rv;
366 + int i, j;
364 367 int err;
365 368
366 369 source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr;
@@ -409,13 +412,11 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
409 412 if (!add) {
410 413 if (!psl)
411 414 goto done; /* err = -EADDRNOTAVAIL */
412 - rv = !0;
413 415 for (i = 0; i < psl->sl_count; i++) {
414 - rv = !ipv6_addr_equal(&psl->sl_addr[i], source);
415 - if (rv == 0)
416 + if (ipv6_addr_equal(&psl->sl_addr[i], source))
416 417 break;
417 418 }
418 - if (rv) /* source not found */
419 + if (i == psl->sl_count) /* source not found */
419 420 goto done; /* err = -EADDRNOTAVAIL */
420 421
421 422 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
@@ -424,58 +425,74 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
424 425 goto done;
425 426 }
426 427
428 + atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
429 + &sk->sk_omem_alloc);
430 +
431 + if (psl->sl_count == 1) {
432 + newpsl = NULL;
433 + } else {
434 + newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr,
435 + psl->sl_count - 1),
436 + GFP_KERNEL);
437 + if (!newpsl) {
438 + atomic_add(struct_size(psl, sl_addr, psl->sl_max),
439 + &sk->sk_omem_alloc);
440 + err = -ENOBUFS;
441 + goto done;
442 + }
443 + newpsl->sl_max = psl->sl_count - 1;
444 + newpsl->sl_count = psl->sl_count - 1;
445 + for (j = 0; j < i; j++)
446 + newpsl->sl_addr[j] = psl->sl_addr[j];
447 + for (j = i + 1; j < psl->sl_count; j++)
448 + newpsl->sl_addr[j - 1] = psl->sl_addr[j];
449 + }
450 +
427 451 /* update the interface filter */
428 452 ip6_mc_del_src(idev, group, omode, 1, source, 1);
429 453
430 - for (j = i+1; j < psl->sl_count; j++)
431 - psl->sl_addr[j-1] = psl->sl_addr[j];
432 - psl->sl_count--;
454 + rcu_assign_pointer(pmc->sflist, newpsl);
455 + kfree_rcu(psl, rcu);
433 456 err = 0;
434 457 goto done;
435 458 }
436 459 /* else, add a new source to the filter */
437 460
438 - if (psl && psl->sl_count >= sysctl_mld_max_msf) {
461 + if (psl && psl->sl_count >= READ_ONCE(sysctl_mld_max_msf)) {
439 462 err = -ENOBUFS;
440 463 goto done;
441 464 }
442 - if (!psl || psl->sl_count == psl->sl_max) {
443 - struct ip6_sf_socklist *newpsl;
444 - int count = IP6_SFBLOCK;
445 -
446 - if (psl)
447 - count += psl->sl_max;
448 - newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, count),
449 - GFP_KERNEL);
450 - if (!newpsl) {
451 - err = -ENOBUFS;
452 - goto done;
453 - }
454 - newpsl->sl_max = count;
455 - newpsl->sl_count = count - IP6_SFBLOCK;
456 - if (psl) {
457 - for (i = 0; i < psl->sl_count; i++)
458 - newpsl->sl_addr[i] = psl->sl_addr[i];
459 - atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
460 - &sk->sk_omem_alloc);
465 + if (psl) {
466 + for (i = 0; i < psl->sl_count; i++) {
467 + if (ipv6_addr_equal(&psl->sl_addr[i], source))
468 + goto done; /* err = -EADDRNOTAVAIL */
461 469 }
462 - rcu_assign_pointer(pmc->sflist, newpsl);
463 - kfree_rcu(psl, rcu);
464 - psl = newpsl;
465 470 }
466 - rv = 1; /* > 0 for insert logic below if sl_count is 0 */
467 - for (i = 0; i < psl->sl_count; i++) {
468 - rv = !ipv6_addr_equal(&psl->sl_addr[i], source);
469 - if (rv == 0) /* There is an error in the address. */
470 - goto done;
471 +
472 + i = psl ? psl->sl_count + 1 : 1;
473 + newpsl = sock_kmalloc(sk, struct_size(newpsl, sl_addr, i),
474 + GFP_KERNEL);
475 + if (!newpsl) {
476 + err = -ENOBUFS;
477 + goto done;
471 478 }
472 - for (j = psl->sl_count-1; j >= i; j--)
473 - psl->sl_addr[j+1] = psl->sl_addr[j];
474 - psl->sl_addr[i] = *source;
475 - psl->sl_count++;
476 - err = 0;
479 + newpsl->sl_max = i;
480 + newpsl->sl_count = i;
481 + if (psl) {
482 + for (j = 0; j < psl->sl_count; j++)
483 + newpsl->sl_addr[j] = psl->sl_addr[j];
484 + }
485 + newpsl->sl_addr[i - 1] = *source;
486 +
477 487 /* update the interface list */
478 488 ip6_mc_add_src(idev, group, omode, 1, source, 1);
489 +
490 + if (psl)
491 + atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
492 + &sk->sk_omem_alloc);
493 + rcu_assign_pointer(pmc->sflist, newpsl);
494 + kfree_rcu(psl, rcu);
495 + err = 0;
479 496 done:
480 497 mutex_unlock(&idev->mc_lock);
481 498 in6_dev_put(idev);
@@ -784,9 +801,11 @@ static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
784 801 if (!pmc)
785 802 return;
786 803 if (pmc_prev)
787 - rcu_assign_pointer(pmc_prev->next, pmc->next);
804 + rcu_assign_pointer(pmc_prev->next,
805 + mc_dereference(pmc->next, idev));
788 806 else
789 - rcu_assign_pointer(idev->mc_tomb, pmc->next);
807 + rcu_assign_pointer(idev->mc_tomb,
808 + mc_dereference(pmc->next, idev));
790 809
791 810 im->idev = pmc->idev;
792 811 if (im->mca_sfmode == MCAST_INCLUDE) {
@@ -966,7 +985,7 @@ static int __ipv6_dev_mc_inc(struct net_device *dev,
966 985 return -ENOMEM;
967 986 }
968 987
969 - rcu_assign_pointer(mc->next, idev->mc_list);
988 + rcu_assign_pointer(mc->next, mc_dereference(idev->mc_list, idev));
970 989 rcu_assign_pointer(idev->mc_list, mc);
971 990
972 991 mld_del_delrec(idev, mc);
@@ -1000,7 +1019,8 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr)
1000 1019
1001 1020 WRITE_ONCE(ma->mca_users, new_users);
1002 1021 if (new_users == 0) {
1003 - *map = ma->next;
1022 + rcu_assign_pointer(*map,
1023 + mc_dereference(ma->next, idev));
1004 1024
1005 1025 igmp6_group_dropped(ma);
1006 1026 inet6_ifmcaddr_notify(idev->dev, ma,
@@ -2351,14 +2371,18 @@ static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,
2351 2371
2352 2372 if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) &&
2353 2373 !mld_in_v1_mode(idev)) {
2354 - psf->sf_crcount = idev->mc_qrv;
2355 - rcu_assign_pointer(psf->sf_next,
2356 - mc_dereference(pmc->mca_tomb, idev));
2357 - rcu_assign_pointer(pmc->mca_tomb, psf);
2358 - rv = 1;
2359 - } else {
2360 - kfree_rcu(psf, rcu);
2374 + struct ip6_sf_list *dpsf = kmalloc_obj(*dpsf);
2375 +
2376 + if (dpsf) {
2377 + *dpsf = *psf;
2378 + dpsf->sf_crcount = idev->mc_qrv;
2379 + rcu_assign_pointer(dpsf->sf_next,
2380 + mc_dereference(pmc->mca_tomb, idev));
2381 + rcu_assign_pointer(pmc->mca_tomb, dpsf);
2382 + rv = 1;
2383 + }
2361 2384 }
2385 + kfree_rcu(psf, rcu);
2362 2386 }
2363 2387 return rv;
2364 2388 }
@@ -2621,7 +2645,7 @@ static void ip6_mc_clear_src(struct ifmcaddr6 *pmc)
2621 2645
2622 2646 static void igmp6_join_group(struct ifmcaddr6 *ma)
2623 2647 {
2624 - unsigned long delay;
2648 + unsigned long delay, interval;
2625 2649
2626 2650 mc_assert_locked(ma->idev);
2627 2651
@@ -2630,13 +2654,17 @@ static void igmp6_join_group(struct ifmcaddr6 *ma)
2630 2654
2631 2655 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
2632 2656
2633 - delay = get_random_u32_below(unsolicited_report_interval(ma->idev));
2657 + interval = unsolicited_report_interval(ma->idev);
2658 + delay = interval;
2634 2659
2635 2660 if (cancel_delayed_work(&ma->mca_work)) {
2636 2661 refcount_dec(&ma->mca_refcnt);
2637 2662 delay = ma->mca_work.timer.expires - jiffies;
2638 2663 }
2639 2664
2665 + if (delay >= interval)
2666 + delay = get_random_u32_below(interval);
2667 +
2640 2668 if (!mod_delayed_work(mld_wq, &ma->mca_work, delay))
2641 2669 refcount_inc(&ma->mca_refcnt);
2642 2670 WRITE_ONCE(ma->mca_flags, ma->mca_flags |
@@ -3001,7 +3029,7 @@ static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
3001 3029 struct ifmcaddr6 *im = (struct ifmcaddr6 *)v;
3002 3030 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
3003 3031 unsigned int mca_flags = READ_ONCE(im->mca_flags);
3004 - unsigned long expires = READ_ONCE(im->mca_work.timer.expires);
3032 + long delta = READ_ONCE(im->mca_work.timer.expires) - jiffies;
3005 3033
3006 3034 seq_printf(seq,
3007 3035 "%-4d %-15s %pi6 %5d %08X %ld\n",
@@ -3009,7 +3037,7 @@ static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
3009 3037 &im->mca_addr,
3010 3038 READ_ONCE(im->mca_users), mca_flags,
3011 3039 (mca_flags & MAF_TIMER_RUNNING) ?
3012 - jiffies_to_clock_t(expires - jiffies) : 0);
3040 + jiffies_delta_to_clock_t(delta) : 0);
3013 3041 return 0;
3014 3042 }
3015 3043
modified net/ipv6/route.c
@@ -3255,7 +3255,7 @@ void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif)
3255 3255
3256 3256 void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk)
3257 3257 {
3258 - ip6_redirect(skb, sock_net(sk), sk->sk_bound_dev_if,
3258 + ip6_redirect(skb, sock_net(sk), skb->dev->ifindex,
3259 3259 READ_ONCE(sk->sk_mark), sk_uid(sk));
3260 3260 }
3261 3261
modified net/ipv6/tcpv6_offload.c
@@ -26,7 +26,18 @@ static void tcp6_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
26 26
27 27 p = tcp_gro_lookup(head, th);
28 28 if (p) {
29 - NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
29 + /* flist GRO applies to consecutive non-GSO skbs */
30 + if (!skb_is_gso(skb) || !NAPI_GRO_CB(p)->is_flist) {
31 + NAPI_GRO_CB(skb)->is_flist = NAPI_GRO_CB(p)->is_flist;
32 + return;
33 + }
34 +
35 + /* Fall back to the regular GRO path */
36 + if (NAPI_GRO_CB(p)->count == 1)
37 + NAPI_GRO_CB(p)->is_flist = 0;
38 +
39 + NAPI_GRO_CB(skb)->is_flist = 0;
40 +
30 41 return;
31 42 }
32 43
@@ -36,7 +47,7 @@ static void tcp6_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
36 47 sk = __inet6_lookup_established(net, &hdr->saddr, th->source,
37 48 &hdr->daddr, ntohs(th->dest),
38 49 iif, sdif);
39 - NAPI_GRO_CB(skb)->is_flist = !sk;
50 + NAPI_GRO_CB(skb)->is_flist = !sk && !skb_is_gso(skb);
40 51 if (sk)
41 52 sock_gen_put(sk);
42 53 #endif /* IS_ENABLED(CONFIG_IPV6) */
modified net/ipv6/udp.c
@@ -690,6 +690,17 @@ out:
690 690 return sk;
691 691 }
692 692
693 + static void udpv6_err_update_exception(struct net *net, struct sk_buff *skb,
694 + u8 type, __be32 info)
695 + {
696 + if (type == ICMPV6_PKT_TOOBIG)
697 + ip6_update_pmtu(skb, net, info, skb->dev->ifindex, 0,
698 + sock_net_uid(net, NULL));
699 + else if (type == NDISC_REDIRECT)
700 + ip6_redirect(skb, net, skb->dev->ifindex, 0,
701 + sock_net_uid(net, NULL));
702 + }
703 +
693 704 static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
694 705 u8 type, u8 code, int offset, __be32 info)
695 706 {
@@ -703,6 +714,8 @@ static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
703 714 int harderr;
704 715 int err;
705 716
717 + udpv6_err_update_exception(net, skb, type, info);
718 +
706 719 daddr = seg6_get_daddr(skb, opt) ? : &hdr->daddr;
707 720 saddr = &hdr->saddr;
708 721 sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source,
modified net/iucv/af_iucv.c
@@ -210,12 +210,6 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
210 210 phs_hdr->flags = flags;
211 211 if (flags == AF_IUCV_FLAG_SYN)
212 212 phs_hdr->window = iucv->msglimit;
213 - else if ((flags == AF_IUCV_FLAG_WIN) || !flags) {
214 - confirm_recv = atomic_read(&iucv->msg_recv);
215 - phs_hdr->window = confirm_recv;
216 - if (confirm_recv)
217 - phs_hdr->flags = phs_hdr->flags | AF_IUCV_FLAG_WIN;
218 - }
219 213 memcpy(phs_hdr->destUserID, iucv->dst_user_id, 8);
220 214 memcpy(phs_hdr->destAppName, iucv->dst_name, 8);
221 215 memcpy(phs_hdr->srcUserID, iucv->src_user_id, 8);
@@ -250,13 +244,22 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
250 244 }
251 245 skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
252 246
247 + /* Claim the receive credit here, not while building the header: every
248 + * way this frame can be dropped has now been ruled out, so the window
249 + * is zeroed only for as long as the transmit itself takes.
250 + */
251 + if (flags == AF_IUCV_FLAG_WIN || !flags) {
252 + confirm_recv = atomic_xchg(&iucv->msg_recv, 0);
253 + phs_hdr->window = confirm_recv;
254 + if (confirm_recv)
255 + phs_hdr->flags = phs_hdr->flags | AF_IUCV_FLAG_WIN;
256 + }
257 +
253 258 atomic_inc(&iucv->skbs_in_xmit);
254 259 err = dev_queue_xmit(skb);
255 260 if (net_xmit_eval(err)) {
256 261 atomic_dec(&iucv->skbs_in_xmit);
257 - } else {
258 - atomic_sub(confirm_recv, &iucv->msg_recv);
259 - WARN_ON(atomic_read(&iucv->msg_recv) < 0);
262 + atomic_add(confirm_recv, &iucv->msg_recv);
260 263 }
261 264 return net_xmit_eval(err);
262 265
@@ -1241,6 +1244,7 @@ static int iucv_sock_recvmsg(struct socket *sock, struct msghdr *msg,
1241 1244 struct iucv_sock *iucv = iucv_sk(sk);
1242 1245 unsigned int copied, rlen;
1243 1246 struct sk_buff *skb, *rskb, *cskb;
1247 + bool send_win = false;
1244 1248 int err = 0;
1245 1249 u32 offset;
1246 1250
@@ -1331,16 +1335,20 @@ static int iucv_sock_recvmsg(struct socket *sock, struct msghdr *msg,
1331 1335 if (skb_queue_empty(&iucv->backlog_skb_q)) {
1332 1336 if (!list_empty(&iucv->message_q.list))
1333 1337 iucv_process_message_q(sk);
1334 - if (atomic_read(&iucv->msg_recv) >=
1335 - iucv->msglimit / 2) {
1336 - err = iucv_send_ctrl(sk, AF_IUCV_FLAG_WIN);
1337 - if (err) {
1338 - sk->sk_state = IUCV_DISCONN;
1339 - sk->sk_state_change(sk);
1340 - }
1341 - }
1338 + if (iucv->transport == AF_IUCV_TRANS_HIPER &&
1339 + atomic_read(&iucv->msg_recv) >=
1340 + iucv->msglimit / 2)
1341 + send_win = true;
1342 1342 }
1343 1343 spin_unlock_bh(&iucv->message_q.lock);
1344 +
1345 + if (send_win) {
1346 + err = iucv_send_ctrl(sk, AF_IUCV_FLAG_WIN);
1347 + if (err) {
1348 + sk->sk_state = IUCV_DISCONN;
1349 + sk->sk_state_change(sk);
1350 + }
1351 + }
1344 1352 }
1345 1353
1346 1354 done:
modified net/mac80211/nan.c
@@ -659,8 +659,7 @@ int ieee80211_nan_set_peer_sched(struct ieee80211_sub_if_data *sdata,
659 659 if (!sta)
660 660 return -ENOENT;
661 661
662 - new_sched = kzalloc(struct_size(new_sched, channels, sched->n_channels),
663 - GFP_KERNEL);
662 + new_sched = kzalloc_flex(*new_sched, channels, sched->n_channels);
664 663 if (!new_sched)
665 664 return -ENOMEM;
666 665
modified net/mac802154/ieee802154_i.h
@@ -76,7 +76,12 @@ struct ieee802154_local {
76 76 struct work_struct rx_mac_cmd_work;
77 77
78 78 /* Association */
79 - struct ieee802154_pan_device *assoc_dev;
79 + /* assoc_lock protects assoc_dev_extended_addr, assoc_addr,
80 + * assoc_status, the assoc_done reinit/complete pairing and the
81 + * IEEE802154_IS_ASSOCIATING bit in @ongoing.
82 + */
83 + spinlock_t assoc_lock;
84 + __le64 assoc_dev_extended_addr;
80 85 struct completion assoc_done;
81 86 __le16 assoc_addr;
82 87 u8 assoc_status;
modified net/mac802154/main.c
@@ -104,6 +104,7 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
104 104 INIT_WORK(&local->rx_mac_cmd_work, mac802154_rx_mac_cmd_worker);
105 105
106 106 init_completion(&local->assoc_done);
107 + spin_lock_init(&local->assoc_lock);
107 108
108 109 /* init supported flags with 802.15.4 default ranges */
109 110 phy->supported.max_minbe = 8;
modified net/mac802154/scan.c
@@ -536,7 +536,9 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
536 536 struct ieee802154_association_req_frame frame = {};
537 537 struct ieee802154_local *local = sdata->local;
538 538 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
539 + __le16 resp_short_addr;
539 540 struct sk_buff *skb;
541 + u8 resp_status;
540 542 int ret;
541 543
542 544 frame.mhr.fc.type = IEEE802154_FC_TYPE_MAC_CMD;
@@ -578,9 +580,11 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
578 580 return ret;
579 581 }
580 582
581 - local->assoc_dev = coord;
583 + spin_lock(&local->assoc_lock);
582 584 reinit_completion(&local->assoc_done);
585 + local->assoc_dev_extended_addr = coord->extended_addr;
583 586 set_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);
587 + spin_unlock(&local->assoc_lock);
584 588
585 589 ret = ieee802154_mlme_tx_one_locked(local, sdata, skb);
586 590 if (ret) {
@@ -599,25 +603,37 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
599 603 goto clear_assoc;
600 604 }
601 605
602 - if (local->assoc_status != IEEE802154_ASSOCIATION_SUCCESSFUL) {
603 - if (local->assoc_status == IEEE802154_PAN_AT_CAPACITY)
606 + /* The association is complete: mac802154_process_association_resp()
607 + * cleared the associating bit before waking us, so a second (e.g.
608 + * malicious) ASSOC RESP can no longer pass the recheck and overwrite
609 + * the result. Snapshot assoc_status/assoc_addr under the lock.
610 + */
611 + spin_lock(&local->assoc_lock);
612 + resp_status = local->assoc_status;
613 + resp_short_addr = local->assoc_addr;
614 + spin_unlock(&local->assoc_lock);
615 +
616 + if (resp_status != IEEE802154_ASSOCIATION_SUCCESSFUL) {
617 + if (resp_status == IEEE802154_PAN_AT_CAPACITY)
604 618 ret = -ERANGE;
605 619 else
606 620 ret = -EPERM;
607 621
608 622 dev_warn(&sdata->dev->dev,
609 623 "Negative ASSOC RESP received from %8phC: %s\n", &ceaddr,
610 - local->assoc_status == IEEE802154_PAN_AT_CAPACITY ?
624 + resp_status == IEEE802154_PAN_AT_CAPACITY ?
611 625 "PAN at capacity" : "access denied");
612 - goto clear_assoc;
626 + return ret;
613 627 }
614 628
615 - ret = 0;
616 - *short_addr = local->assoc_addr;
629 + *short_addr = resp_short_addr;
630 +
631 + return 0;
617 632
618 633 clear_assoc:
634 + spin_lock(&local->assoc_lock);
619 635 clear_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);
620 - local->assoc_dev = NULL;
636 + spin_unlock(&local->assoc_lock);
621 637
622 638 return ret;
623 639 }
@@ -639,19 +655,28 @@ int mac802154_process_association_resp(struct ieee802154_sub_if_data *sdata,
639 655 dest->mode != IEEE802154_EXTENDED_ADDRESSING))
640 656 return -EINVAL;
641 657
642 - if (unlikely(dest->extended_addr != wpan_dev->extended_addr ||
643 - src->extended_addr != local->assoc_dev->extended_addr))
658 + spin_lock(&local->assoc_lock);
659 + if (unlikely(!test_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing) ||
660 + dest->extended_addr != wpan_dev->extended_addr ||
661 + src->extended_addr != local->assoc_dev_extended_addr)) {
662 + spin_unlock(&local->assoc_lock);
644 663 return -ENODEV;
664 + }
645 665
646 666 memcpy(&resp_pl, skb->data, sizeof(resp_pl));
647 667 local->assoc_addr = resp_pl.short_addr;
648 668 local->assoc_status = resp_pl.status;
669 + /* Clear the associating bit before waking the waiter: once the result
670 + * is saved, any subsequent (e.g. malicious) ASSOC RESP must fail the
671 + * test_bit() recheck above and can no longer overwrite the result.
672 + */
673 + clear_bit(IEEE802154_IS_ASSOCIATING, &local->ongoing);
674 + complete(&local->assoc_done);
675 + spin_unlock(&local->assoc_lock);
649 676
650 677 dev_dbg(&skb->dev->dev,
651 678 "ASSOC RESP 0x%x received from %8phC, getting short address %04x\n",
652 - local->assoc_status, &deaddr, local->assoc_addr);
653 -
654 - complete(&local->assoc_done);
679 + resp_pl.status, &deaddr, resp_pl.short_addr);
655 680
656 681 return 0;
657 682 }
modified net/mctp/test/route-test.c
@@ -193,7 +193,7 @@ static void __mctp_route_test_init(struct kunit *test,
193 193 if (netid != MCTP_NET_ANY)
194 194 WRITE_ONCE(dev->mdev->net, netid);
195 195
196 - dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
196 + dev->mdev->addrs = kmalloc_objs(u8, 1);
197 197 dev->mdev->num_addrs = 1;
198 198 dev->mdev->addrs[0] = 8;
199 199
modified net/mctp/test/utils.c
@@ -88,7 +88,7 @@ struct mctp_test_dev *mctp_test_create_dev_with_addr(mctp_eid_t addr)
88 88 if (!dev)
89 89 return NULL;
90 90
91 - dev->mdev->addrs = kmalloc_objs(u8, 1, GFP_KERNEL);
91 + dev->mdev->addrs = kmalloc_objs(u8, 1);
92 92 if (!dev->mdev->addrs) {
93 93 mctp_test_destroy_dev(dev);
94 94 return NULL;
modified net/mptcp/protocol.c
@@ -3109,8 +3109,7 @@ static void mptcp_do_fastclose(struct sock *sk)
3109 3109 */
3110 3110 inet_csk(ssk)->icsk_ack.rcv_mss = TCP_MIN_MSS;
3111 3111
3112 - tcp_send_active_reset(ssk, ssk->sk_allocation,
3113 - SK_RST_REASON_TCP_ABORT_ON_CLOSE);
3112 + tcp_send_active_reset(ssk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
3114 3113 unlock:
3115 3114 release_sock(ssk);
3116 3115 }
modified net/mptcp/protocol.h
@@ -690,7 +690,7 @@ mptcp_send_active_reset_reason(struct sock *sk)
690 690 enum sk_rst_reason reason;
691 691
692 692 reason = sk_rst_convert_mptcp_reason(subflow->reset_reason);
693 - tcp_send_active_reset(sk, GFP_ATOMIC, reason);
693 + tcp_send_active_reset(sk, reason);
694 694 }
695 695
696 696 /* Made the fwd mem carried by the given skb available to the msk,
modified net/netfilter/nf_tables_api.c
@@ -3215,7 +3215,7 @@ static int nft_trans_delhook(struct nft_hook *hook,
3215 3215 {
3216 3216 struct nft_trans_hook *trans_hook;
3217 3217
3218 - trans_hook = kmalloc_obj(*trans_hook, GFP_KERNEL);
3218 + trans_hook = kmalloc_obj(*trans_hook);
3219 3219 if (!trans_hook)
3220 3220 return -ENOMEM;
3221 3221
modified net/packet/af_packet.c
@@ -2675,7 +2675,8 @@ static int tpacket_parse_header(struct packet_sock *po, void *frame,
2675 2675 int size_max, void **data)
2676 2676 {
2677 2677 union tpacket_uhdr ph;
2678 - int tp_len, off;
2678 + u32 tp_len;
2679 + int off;
2679 2680
2680 2681 ph.raw = frame;
2681 2682
@@ -2695,7 +2696,7 @@ static int tpacket_parse_header(struct packet_sock *po, void *frame,
2695 2696 break;
2696 2697 }
2697 2698 if (unlikely(tp_len > size_max)) {
2698 - pr_err("packet size is too long (%d > %d)\n", tp_len, size_max);
2699 + pr_err("packet size is too long (%u > %d)\n", tp_len, size_max);
2699 2700 return -EMSGSIZE;
2700 2701 }
2701 2702
modified net/qrtr/af_qrtr.c
@@ -9,6 +9,7 @@
9 9 #include <linux/termios.h> /* For TIOCINQ/OUTQ */
10 10 #include <linux/spinlock.h>
11 11 #include <linux/wait.h>
12 + #include <linux/workqueue.h>
12 13
13 14 #include <net/sock.h>
14 15
@@ -120,8 +121,10 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
120 121 * @nid: node id
121 122 * @qrtr_tx_flow: xarray of qrtr_tx_flow, keyed by node << 32 | port
122 123 * @qrtr_tx_lock: lock for qrtr_tx_flow inserts
124 + * @hello_sent: hello packet send successful
123 125 * @rx_queue: receive queue
124 126 * @item: list item for broadcast list
127 + * @say_hello: delayed work for sending hello packet
125 128 */
126 129 struct qrtr_node {
127 130 struct mutex ep_lock;
@@ -132,8 +135,11 @@ struct qrtr_node {
132 135 struct xarray qrtr_tx_flow;
133 136 struct mutex qrtr_tx_lock; /* for qrtr_tx_flow */
134 137
138 + bool hello_sent;
139 +
135 140 struct sk_buff_head rx_queue;
136 141 struct list_head item;
142 + struct delayed_work say_hello;
137 143 };
138 144
139 145 /**
@@ -187,6 +193,8 @@ static void __qrtr_node_release(struct kref *kref)
187 193 list_del(&node->item);
188 194 mutex_unlock(&qrtr_node_lock);
189 195
196 + cancel_delayed_work_sync(&node->say_hello);
197 +
190 198 skb_queue_purge(&node->rx_queue);
191 199
192 200 /* Free tx flow counters */
@@ -341,6 +349,14 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
341 349 size_t len = skb->len;
342 350 int rc, confirm_rx;
343 351
352 + mutex_lock(&node->ep_lock);
353 + if (!node->hello_sent && type != QRTR_TYPE_HELLO) {
354 + mutex_unlock(&node->ep_lock);
355 + kfree_skb(skb);
356 + return -EAGAIN;
357 + }
358 + mutex_unlock(&node->ep_lock);
359 +
344 360 confirm_rx = qrtr_tx_wait(node, to->sq_node, to->sq_port, type);
345 361 if (confirm_rx < 0) {
346 362 kfree_skb(skb);
@@ -353,7 +369,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
353 369 hdr->src_node_id = cpu_to_le32(from->sq_node);
354 370 hdr->src_port_id = cpu_to_le32(from->sq_port);
355 371 if (to->sq_port == QRTR_PORT_CTRL) {
356 - hdr->dst_node_id = cpu_to_le32(node->nid);
372 + hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->nid));
357 373 hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL);
358 374 } else {
359 375 hdr->dst_node_id = cpu_to_le32(to->sq_node);
@@ -372,6 +388,8 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
372 388 rc = node->ep->xmit(node->ep, skb);
373 389 else
374 390 kfree_skb(skb);
391 + if (!rc && type == QRTR_TYPE_HELLO)
392 + node->hello_sent = true;
375 393 mutex_unlock(&node->ep_lock);
376 394 }
377 395 /* Need to ensure that a subsequent message carries the otherwise lost
@@ -379,6 +397,9 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
379 397 if (rc && confirm_rx)
380 398 qrtr_tx_flow_failed(node, to->sq_node, to->sq_port);
381 399
400 + if (rc == -EAGAIN && type == QRTR_TYPE_HELLO)
401 + schedule_delayed_work(&node->say_hello, msecs_to_jiffies(100));
402 +
382 403 return rc;
383 404 }
384 405
@@ -416,7 +437,7 @@ static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
416 437 spin_lock_irqsave(&qrtr_nodes_lock, flags);
417 438 radix_tree_insert(&qrtr_nodes, nid, node);
418 439 if (node->nid == QRTR_EP_NID_AUTO)
419 - node->nid = nid;
440 + WRITE_ONCE(node->nid, nid);
420 441 spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
421 442 }
422 443
@@ -570,6 +591,38 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,
570 591 return skb;
571 592 }
572 593
594 + static void qrtr_hello_work(struct work_struct *work)
595 + {
596 + struct sockaddr_qrtr from = {AF_QIPCRTR, 0, QRTR_PORT_CTRL};
597 + struct sockaddr_qrtr to = {AF_QIPCRTR, 0, QRTR_PORT_CTRL};
598 + struct qrtr_ctrl_pkt *pkt;
599 + struct qrtr_node *node;
600 + struct qrtr_sock *ctrl;
601 + struct sk_buff *skb;
602 +
603 + node = container_of(to_delayed_work(work), struct qrtr_node, say_hello);
604 +
605 + /* NS must be bound before we can send; retry with backoff if not ready */
606 + ctrl = qrtr_port_lookup(QRTR_PORT_CTRL);
607 + if (!ctrl) {
608 + schedule_delayed_work(&node->say_hello, msecs_to_jiffies(100));
609 + return;
610 + }
611 +
612 + skb = qrtr_alloc_ctrl_packet(&pkt, GFP_KERNEL);
613 + if (!skb) {
614 + qrtr_port_put(ctrl);
615 + schedule_delayed_work(&node->say_hello, msecs_to_jiffies(100));
616 + return;
617 + }
618 +
619 + pkt->cmd = cpu_to_le32(QRTR_TYPE_HELLO);
620 + from.sq_node = qrtr_local_nid;
621 + to.sq_node = node->nid;
622 + qrtr_node_enqueue(node, skb, QRTR_TYPE_HELLO, &from, &to);
623 + qrtr_port_put(ctrl);
624 + }
625 +
573 626 /**
574 627 * qrtr_endpoint_register() - register a new endpoint
575 628 * @ep: endpoint to register
@@ -595,6 +648,9 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
595 648 node->nid = QRTR_EP_NID_AUTO;
596 649 node->ep = ep;
597 650
651 + node->hello_sent = false;
652 + INIT_DELAYED_WORK(&node->say_hello, qrtr_hello_work);
653 +
598 654 xa_init(&node->qrtr_tx_flow);
599 655 mutex_init(&node->qrtr_tx_lock);
600 656
@@ -605,6 +661,9 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
605 661 mutex_unlock(&qrtr_node_lock);
606 662 ep->node = node;
607 663
664 + /* Initiate HELLO handshake from the core layer */
665 + schedule_delayed_work(&node->say_hello, 0);
666 +
608 667 return 0;
609 668 }
610 669 EXPORT_SYMBOL_GPL(qrtr_endpoint_register);
@@ -879,6 +938,9 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb,
879 938
880 939 mutex_lock(&qrtr_node_lock);
881 940 list_for_each_entry(node, &qrtr_all_nodes, item) {
941 + /* Skip nodes with no assigned node ID yet. */
942 + if (READ_ONCE(node->nid) == QRTR_EP_NID_AUTO)
943 + continue;
882 944 skbn = pskb_copy(skb, GFP_KERNEL);
883 945 if (!skbn)
884 946 break;
modified net/qrtr/ns.c
@@ -212,6 +212,7 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv,
212 212 pr_err("failed to send lookup notification\n");
213 213 }
214 214
215 + /* Announce the list of servers registered on the local node */
215 216 static int announce_servers(struct sockaddr_qrtr *sq)
216 217 {
217 218 struct qrtr_server *srv;
@@ -326,38 +327,8 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast)
326 327 return 0;
327 328 }
328 329
329 - static int say_hello(struct sockaddr_qrtr *dest)
330 - {
331 - struct qrtr_ctrl_pkt pkt;
332 - struct msghdr msg = { };
333 - struct kvec iv;
334 - int ret;
335 -
336 - iv.iov_base = &pkt;
337 - iv.iov_len = sizeof(pkt);
338 -
339 - memset(&pkt, 0, sizeof(pkt));
340 - pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);
341 -
342 - msg.msg_name = (struct sockaddr *)dest;
343 - msg.msg_namelen = sizeof(*dest);
344 -
345 - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
346 - if (ret < 0)
347 - pr_err("failed to send hello msg\n");
348 -
349 - return ret;
350 - }
351 -
352 - /* Announce the list of servers registered on the local node */
353 330 static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)
354 331 {
355 - int ret;
356 -
357 - ret = say_hello(sq);
358 - if (ret < 0)
359 - return ret;
360 -
361 332 return announce_servers(sq);
362 333 }
363 334
@@ -774,10 +745,6 @@ int qrtr_ns_init(void)
774 745 qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
775 746 qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
776 747
777 - ret = say_hello(&qrtr_ns.bcast_sq);
778 - if (ret < 0)
779 - goto err_wq;
780 -
781 748 /* As the qrtr ns socket owner and creator is the same module, we have
782 749 * to decrease the qrtr module reference count to guarantee that it
783 750 * remains zero after the ns socket is created, otherwise, executing
modified net/rds/connection.c
@@ -106,10 +106,12 @@ static struct rds_connection *rds_conn_lookup(struct net *net,
106 106 }
107 107
108 108 /*
109 - * This is called by transports as they're bringing down a connection.
110 - * It clears partial message state so that the transport can start sending
111 - * and receiving over this connection again in the future. It is up to
112 - * the transport to have serialized this call with its send and recv.
109 + * This is called by rds_conn_shutdown() once the transport has brought
110 + * a path down. It clears partial message state so that the transport
111 + * can start sending and receiving over this path again in the future.
112 + * The caller owns RDS_IN_XMIT and RDS_RECV_REFILL across this call,
113 + * which is what serializes it against the send and receive-refill
114 + * paths.
113 115 */
114 116 static void rds_conn_path_reset(struct rds_conn_path *cp)
115 117 {
@@ -120,7 +122,16 @@ static void rds_conn_path_reset(struct rds_conn_path *cp)
120 122
121 123 rds_stats_inc(s_conn_reset);
122 124 rds_send_path_reset(cp);
123 - cp->cp_flags = 0;
125 +
126 + /* Clear the bits the reset is responsible for individually: a
127 + * blanket cp_flags = 0 is a plain store that can clobber a
128 + * concurrent atomic read-modify-write on the same word.
129 + * RDS_IN_XMIT and RDS_RECV_REFILL are held as locks by the
130 + * caller, rds_conn_shutdown(), which releases them once the
131 + * teardown is complete.
132 + */
133 + clear_bit(RDS_LL_SEND_FULL, &cp->cp_flags);
134 + clear_bit(RDS_RECONNECT_PENDING, &cp->cp_flags);
124 135
125 136 /* Do not clear next_rx_seq here, else we cannot distinguish
126 137 * retransmitted packets from new packets, and will hand all
@@ -406,28 +417,70 @@ void rds_conn_shutdown(struct rds_conn_path *cp)
406 417 }
407 418 mutex_unlock(&cp->cp_cm_lock);
408 419
420 + /* Quiesce the transmit and receive-refill paths by
421 + * acquiring their bit locks, not merely waiting for
422 + * them to be released: with a plain wait, either path
423 + * can re-take its lock the instant after we sample it
424 + * clear and then run concurrently with the transport
425 + * shutdown and the path reset below. Holding both
426 + * locks across the teardown makes that structurally
427 + * impossible.
428 + */
409 429 wait_event(cp->cp_waitq,
410 - !test_bit(RDS_IN_XMIT, &cp->cp_flags));
430 + !test_and_set_bit_lock(RDS_IN_XMIT, &cp->cp_flags));
411 431 wait_event(cp->cp_waitq,
412 - !test_bit(RDS_RECV_REFILL, &cp->cp_flags));
432 + !test_and_set_bit(RDS_RECV_REFILL, &cp->cp_flags));
413 433
414 434 conn->c_trans->conn_path_shutdown(cp);
415 435 rds_conn_path_reset(cp);
416 436
437 + /* Release the two locks and wake any waiter (e.g.
438 + * rds_tcp_reset_callbacks()) that blocked on them while
439 + * we held them. The unlock orders the transport's ring
440 + * re-initialization and the path reset above before
441 + * either bit is seen clear. rds_conn_path_reset() leaves
442 + * both bits alone: ownership ends here, not inside the
443 + * reset.
444 + */
445 + clear_bit_unlock(RDS_IN_XMIT, &cp->cp_flags);
446 + clear_bit_unlock(RDS_RECV_REFILL, &cp->cp_flags);
447 + wake_up_all(&cp->cp_waitq);
448 +
417 449 if (!rds_conn_path_transition(cp, RDS_CONN_DISCONNECTING,
418 - RDS_CONN_DOWN) &&
419 - !rds_conn_path_transition(cp, RDS_CONN_ERROR,
420 450 RDS_CONN_DOWN)) {
421 - /* This can happen - eg when we're in the middle of tearing
422 - * down the connection, and someone unloads the rds module.
423 - * Quite reproducible with loopback connections.
424 - * Mostly harmless.
451 + /* The path was dropped again while we tore it
452 + * down: by a socket state-change callback in
453 + * irq context on receipt of a FIN, or by an
454 + * accept that claimed the path just before a
455 + * drop put it back to RDS_CONN_ERROR and then
456 + * installed a fresh socket on it. Unless a
457 + * pending destroy suppressed it, the drop also
458 + * queued another shutdown pass, and that pass
459 + * must run, because it is what tears down
460 + * whatever attached to the path after the
461 + * transport shutdown above sampled its state.
462 + * Consuming the RDS_CONN_ERROR here would turn
463 + * that pass into a no-op: leave the state
464 + * alone, and let the pass finish the job.
425 465 *
426 - * Note that this also happens with rds-tcp because
427 - * we could have triggered rds_conn_path_drop in irq
428 - * mode from rds_tcp_state change on the receipt of
429 - * a FIN, thus we need to recheck for RDS_CONN_ERROR
430 - * here.
466 + * Quiesce the reconnect timer before bailing
467 + * out, though. When a pending destroy did
468 + * suppress the queue, no later pass runs, and
469 + * rds_conn_path_destroy() is about to flush
470 + * cp_down_w and free the path: it must not
471 + * find cp_conn_w still armed. A successor
472 + * pass, when there is one, re-arms the
473 + * reconnect from its own tail.
474 + */
475 + cancel_delayed_work_sync(&cp->cp_conn_w);
476 + clear_bit(RDS_RECONNECT_PENDING, &cp->cp_flags);
477 +
478 + if (rds_conn_path_state(cp) == RDS_CONN_ERROR)
479 + return;
480 + /* No current cp_state writer leaves a
481 + * DISCONNECTING path in any state but
482 + * RDS_CONN_ERROR; report loudly if one ever
483 + * does.
431 484 */
432 485 rds_conn_path_error(cp, "%s: failed to transition "
433 486 "to state DOWN, current state "
modified net/rds/ib_recv.c
@@ -363,15 +363,14 @@ static int acquire_refill(struct rds_connection *conn)
363 363
364 364 static void release_refill(struct rds_connection *conn)
365 365 {
366 - clear_bit(RDS_RECV_REFILL, &conn->c_flags);
367 - smp_mb__after_atomic();
366 + clear_bit_unlock(RDS_RECV_REFILL, &conn->c_flags);
368 367
369 368 /* We don't use wait_on_bit()/wake_up_bit() because our waking is in a
370 369 * hot path and finding waiters is very rare. We don't want to walk
371 370 * the system-wide hashed waitqueue buckets in the fast path only to
372 371 * almost never find waiters.
373 372 */
374 - if (waitqueue_active(&conn->c_waitq))
373 + if (wq_has_sleeper(&conn->c_waitq))
375 374 wake_up_all(&conn->c_waitq);
376 375 }
377 376
@@ -392,7 +391,9 @@ void rds_ib_recv_refill(struct rds_connection *conn, int prefill, gfp_t gfp)
392 391
393 392 /* the goal here is to just make sure that someone, somewhere
394 393 * is posting buffers. If we can't get the refill lock,
395 - * let them do their thing
394 + * let them do their thing. The holder may also be
395 + * rds_conn_shutdown() tearing the path down, in which case
396 + * there is nothing to post.
396 397 */
397 398 if (!acquire_refill(conn))
398 399 return;
modified net/rds/info.c
@@ -205,7 +205,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, sockopt_t *opt)
205 205 * iterator code to allocate and hand it back.
206 206 */
207 207 npages = iov_iter_npages(&opt->iter_out, INT_MAX);
208 - pages = kvmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
208 + pages = kvmalloc_objs(*pages, npages);
209 209 if (!pages) {
210 210 ret = -ENOMEM;
211 211 goto out;
modified net/rds/send.c
@@ -114,8 +114,13 @@ static void release_in_xmit(struct rds_conn_path *cp)
114 114 * hot path and finding waiters is very rare. We don't want to walk
115 115 * the system-wide hashed waitqueue buckets in the fast path only to
116 116 * almost never find waiters.
117 + *
118 + * wq_has_sleeper() supplies the full barrier that orders the wait
119 + * queue read after the bit clear; clear_bit_unlock() alone is only
120 + * a release and would let this check read a stale empty queue,
121 + * losing the wake-up.
117 122 */
118 - if (waitqueue_active(&cp->cp_waitq))
123 + if (wq_has_sleeper(&cp->cp_waitq))
119 124 wake_up_all(&cp->cp_waitq);
120 125 }
121 126
@@ -239,8 +244,11 @@ restart:
239 244 WRITE_ONCE(cp->cp_send_gen, send_gen);
240 245
241 246 /*
242 - * rds_conn_shutdown() sets the conn state and then tests RDS_IN_XMIT,
243 - * we do the opposite to avoid races.
247 + * rds_conn_shutdown() sets the conn state and then acquires
248 + * RDS_IN_XMIT; we take the lock first and then check the state.
249 + * Ownership is decided by the atomic RMW on the cp_flags word:
250 + * if the teardown won the bit we back off here, and if we won
251 + * it the teardown waits until we release it.
244 252 */
245 253 if (!rds_conn_path_up(cp)) {
246 254 release_in_xmit(cp);
modified net/rds/tcp.c
@@ -115,46 +115,90 @@ void rds_tcp_restore_callbacks(struct socket *sock,
115 115 }
116 116
117 117 /*
118 - * rds_tcp_reset_callbacks() switches the to the new sock and
119 - * returns the existing tc->t_sock.
118 + * rds_tcp_reset_callbacks() switches a path to a new socket and
119 + * releases the old one it finds in tc->t_sock, resolving a duelling
120 + * SYN.
120 121 *
121 - * The only functions that set tc->t_sock are rds_tcp_set_callbacks
122 - * and rds_tcp_reset_callbacks. Send and receive trust that
123 - * it is set. The absence of RDS_CONN_UP bit protects those paths
124 - * from being called while it isn't set.
122 + * tc->t_sock is set by rds_tcp_set_callbacks() and cleared by
123 + * rds_tcp_restore_callbacks(). Four paths write it: the active
124 + * connect in rds_tcp_conn_path_connect(), which sets it and clears it
125 + * again on failure; the accept path in rds_tcp_accept_one(), which
126 + * sets it for a path with no socket yet; the teardown in
127 + * rds_tcp_conn_path_shutdown(), which clears it; and the swap done
128 + * here, which does both. The connect and accept paths are serialized
129 + * against each other by t_conn_path_lock. Send and receive trust
130 + * that it is set: the absence of RDS_CONN_UP protects those paths
131 + * from being called while it isn't, and the swap done here runs under
132 + * RDS_IN_XMIT so that it cannot interleave with a sender already
133 + * inside rds_send_xmit().
125 134 */
126 135 void rds_tcp_reset_callbacks(struct socket *sock,
127 136 struct rds_conn_path *cp)
128 137 {
129 138 struct rds_tcp_connection *tc = cp->cp_transport_data;
130 - struct socket *osock = tc->t_sock;
131 -
132 - if (!osock)
133 - goto newsock;
139 + struct socket *osock;
134 140
135 141 /* Need to resolve a duelling SYN between peers.
136 142 * We have an outstanding SYN to this peer, which may
137 143 * potentially have transitioned to the RDS_CONN_UP state,
138 144 * so we must quiesce any send threads before resetting
139 - * cp_transport_data. We quiesce these threads by setting
140 - * cp_state to something other than RDS_CONN_UP, and then
141 - * waiting for any existing threads in rds_send_xmit to
142 - * complete release_in_xmit(). (Subsequent threads entering
143 - * rds_send_xmit() will bail on !rds_conn_up().
145 + * cp_transport_data. Setting cp_state to something other
146 + * than RDS_CONN_UP stops new senders, and owning RDS_IN_XMIT
147 + * excludes any thread already inside rds_send_xmit() - or a
148 + * teardown in rds_conn_shutdown(), which holds the same lock
149 + * for the duration of the transport shutdown - for the whole
150 + * socket swap and the rds_send_path_reset() below.
144 151 *
145 - * However an incoming syn-ack at this point would end up
146 - * marking the conn as RDS_CONN_UP, and would again permit
147 - * rds_send_xmi() threads through, so ideally we would
148 - * synchronize on RDS_CONN_UP after lock_sock(), but cannot
149 - * do that: waiting on !RDS_IN_XMIT after lock_sock() may
150 - * end up deadlocking with tcp_sendmsg(), and the RDS_IN_XMIT
151 - * would not get set. As a result, we set c_state to
152 - * RDS_CONN_RESETTTING, to ensure that rds_tcp_state_change
153 - * cannot mark rds_conn_path_up() in the window before lock_sock()
152 + * An incoming syn-ack at this point would end up marking the
153 + * conn as RDS_CONN_UP, and would again permit rds_send_xmit()
154 + * threads through, so ideally we would synchronize on
155 + * RDS_CONN_UP after lock_sock(), but cannot do that: acquiring
156 + * RDS_IN_XMIT after lock_sock() may end up deadlocking with
157 + * tcp_sendmsg(), which takes the socket lock while holding
158 + * RDS_IN_XMIT. As a result, we set c_state to
159 + * RDS_CONN_RESETTING, to ensure that rds_tcp_state_change
160 + * cannot mark rds_conn_path_up() in the window before
161 + * lock_sock().
162 + *
163 + * Only make that transition if the path is still connecting
164 + * (or already resetting from an earlier duel). A path in any
165 + * other state - typically RDS_CONN_DISCONNECTING or
166 + * RDS_CONN_ERROR with a shutdown in flight - is dropped
167 + * instead. That still replaces its state, with RDS_CONN_ERROR,
168 + * and, unless a pending destroy is about to reap the whole
169 + * connection anyway, queues one more shutdown pass. A shutdown
170 + * already in flight leaves that RDS_CONN_ERROR alone when it
171 + * finishes; the queued pass then completes the transition to
172 + * RDS_CONN_DOWN and tears down anything that attached to the
173 + * path in the meantime.
174 + */
175 + if (!rds_conn_path_transition(cp, RDS_CONN_CONNECTING,
176 + RDS_CONN_RESETTING) &&
177 + !rds_conn_path_transition(cp, RDS_CONN_RESETTING,
178 + RDS_CONN_RESETTING))
179 + rds_conn_path_drop(cp, 0);
180 + wait_event(cp->cp_waitq,
181 + !test_and_set_bit_lock(RDS_IN_XMIT, &cp->cp_flags));
182 +
183 + /* Read t_sock only while owning RDS_IN_XMIT, never before the
184 + * wait: the teardown in rds_conn_shutdown() releases the old
185 + * socket and clears t_sock, so a pointer sampled earlier can
186 + * be stale by the time we wake up. The teardown holds the
187 + * same lock while it does so, so what we read here cannot
188 + * change under us until we release it.
189 + */
190 + osock = tc->t_sock;
191 + if (!osock)
192 + goto newsock;
193 +
194 + /* reset receive side state for rds_tcp_data_recv() for osock.
195 + *
196 + * The sync cancels while owning RDS_IN_XMIT rely on cp_wq
197 + * being ordered: a teardown blocked on the bit occupies
198 + * cp_wq's only execution slot, so cp_send_w and cp_recv_w are
199 + * pending at most and the cancels never flush. Nothing here
200 + * may flush or wait on cp_wq itself.
154 201 */
155 - atomic_set(&cp->cp_state, RDS_CONN_RESETTING);
156 - wait_event(cp->cp_waitq, !test_bit(RDS_IN_XMIT, &cp->cp_flags));
157 - /* reset receive side state for rds_tcp_data_recv() for osock */
158 202 cancel_delayed_work_sync(&cp->cp_send_w);
159 203 cancel_delayed_work_sync(&cp->cp_recv_w);
160 204 lock_sock(osock->sk);
@@ -172,6 +216,9 @@ newsock:
172 216 lock_sock(sock->sk);
173 217 rds_tcp_set_callbacks(sock, cp);
174 218 release_sock(sock->sk);
219 +
220 + clear_bit_unlock(RDS_IN_XMIT, &cp->cp_flags);
221 + wake_up_all(&cp->cp_waitq);
175 222 }
176 223
177 224 /* Add tc to rds_tcp_tc_list and set tc->t_sock. See comments
modified net/rds/tcp_listen.c
@@ -295,7 +295,11 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn)
295 295 if (rs_tcp->t_sock) {
296 296 /* Duelling SYN has been handled in rds_tcp_accept_one() */
297 297 rds_tcp_reset_callbacks(new_sock, cp);
298 - /* rds_connect_path_complete() marks RDS_CONN_UP */
298 + /* rds_connect_path_complete() marks RDS_CONN_UP, or,
299 + * if a concurrent shutdown won the duel, drops the
300 + * path again and the pass that drop queues reaps the
301 + * socket installed above.
302 + */
299 303 rds_connect_path_complete(cp, RDS_CONN_RESETTING);
300 304 } else {
301 305 rds_tcp_set_callbacks(new_sock, cp);
modified net/rxrpc/key.c
@@ -210,7 +210,7 @@ static int rxrpc_preparse_xdr_yfs_rxgk(struct key_preparsed_payload *prep,
210 210 if (!token)
211 211 goto nomem;
212 212
213 - token->rxgk = kzalloc(struct_size_t(struct rxgk_key, _key, raw_keylen), GFP_KERNEL);
213 + token->rxgk = kzalloc_flex(struct rxgk_key, _key, raw_keylen);
214 214 if (!token->rxgk)
215 215 goto nomem_token;
216 216
modified net/sched/act_api.c
@@ -443,12 +443,21 @@ static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
443 443 + nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
444 444 + cookie_len /* TCA_ACT_COOKIE */
445 445 + nla_total_size(sizeof(struct nla_bitfield32)) /* TCA_ACT_HW_STATS */
446 + /* TCA_ACT_USED_HW_STATS */
447 + + nla_total_size(sizeof(struct nla_bitfield32))
448 + + nla_total_size(sizeof(u32)) /* TCA_ACT_IN_HW_COUNT */
446 449 + nla_total_size(0) /* TCA_ACT_STATS nested */
447 450 + nla_total_size(sizeof(struct nla_bitfield32)) /* TCA_ACT_FLAGS */
448 451 /* TCA_STATS_BASIC */
449 452 + nla_total_size_64bit(sizeof(struct gnet_stats_basic))
450 - /* TCA_STATS_PKT64 */
451 - + nla_total_size_64bit(sizeof(u64))
453 + /* TCA_STATS_BASIC_HW */
454 + + nla_total_size_64bit(sizeof(struct gnet_stats_basic))
455 + /* TCA_STATS_PKT64, emitted by both of the basic copies above */
456 + + 2 * nla_total_size_64bit(sizeof(u64))
457 + /* TCA_STATS_RATE_EST */
458 + + nla_total_size_64bit(sizeof(struct gnet_stats_rate_est))
459 + /* TCA_STATS_RATE_EST64 */
460 + + nla_total_size_64bit(sizeof(struct gnet_stats_rate_est64))
452 461 /* TCA_STATS_QUEUE */
453 462 + nla_total_size_64bit(sizeof(struct gnet_stats_queue))
454 463 + nla_total_size(0) /* TCA_ACT_OPTIONS nested */
@@ -1688,12 +1697,12 @@ out_nlmsg_trim:
1688 1697
1689 1698 static int
1690 1699 tcf_get_notify(struct net *net, u32 portid, struct nlmsghdr *n,
1691 - struct tc_action *actions[], int event,
1700 + struct tc_action *actions[], size_t attr_size, int event,
1692 1701 struct netlink_ext_ack *extack)
1693 1702 {
1694 1703 struct sk_buff *skb;
1695 1704
1696 - skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
1705 + skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL);
1697 1706 if (!skb)
1698 1707 return -ENOBUFS;
1699 1708 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, event,
@@ -1858,11 +1867,13 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[])
1858 1867 static struct sk_buff *tcf_reoffload_del_notify_msg(struct net *net,
1859 1868 struct tc_action *action)
1860 1869 {
1861 - size_t attr_size = tcf_action_fill_size(action);
1862 1870 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {
1863 1871 [0] = action,
1864 1872 };
1865 1873 struct sk_buff *skb;
1874 + size_t attr_size;
1875 +
1876 + attr_size = tcf_action_full_attrs_size(tcf_action_fill_size(action));
1866 1877
1867 1878 skb = alloc_skb(max(attr_size, NLMSG_GOODSIZE), GFP_KERNEL);
1868 1879 if (!skb)
@@ -1879,15 +1890,18 @@ static struct sk_buff *tcf_reoffload_del_notify_msg(struct net *net,
1879 1890 static int tcf_reoffload_del_notify(struct net *net, struct tc_action *action)
1880 1891 {
1881 1892 const struct tc_action_ops *ops = action->ops;
1882 - struct sk_buff *skb;
1893 + struct sk_buff *skb = NULL;
1883 1894 int ret;
1884 1895
1885 - if (!rtnl_notify_needed(net, 0, RTNLGRP_TC)) {
1886 - skb = NULL;
1887 - } else {
1896 + if (rtnl_notify_needed(net, 0, RTNLGRP_TC)) {
1888 1897 skb = tcf_reoffload_del_notify_msg(net, action);
1898 + /* The action has already lost its hardware instance and is
1899 + * skip_sw, so it must be released whether or not the
1900 + * notification can be built. Drop the notification rather
1901 + * than leave an action behind that processes no packets.
1902 + */
1889 1903 if (IS_ERR(skb))
1890 - return PTR_ERR(skb);
1904 + skb = NULL;
1891 1905 }
1892 1906
1893 1907 ret = tcf_idr_release_unsafe(action);
@@ -2044,7 +2058,8 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
2044 2058 attr_size = tcf_action_full_attrs_size(attr_size);
2045 2059
2046 2060 if (event == RTM_GETACTION)
2047 - ret = tcf_get_notify(net, portid, n, actions, event, extack);
2061 + ret = tcf_get_notify(net, portid, n, actions, attr_size, event,
2062 + extack);
2048 2063 else { /* delete */
2049 2064 ret = tcf_del_notify(net, n, actions, portid, attr_size, extack);
2050 2065 if (ret)
modified net/sched/act_gate.c
@@ -240,7 +240,7 @@ static int tcf_gate_copy_entries(struct tcf_gate_params *dst,
240 240 list_for_each_entry(entry, &src->entries, list) {
241 241 struct tcfg_gate_entry *new;
242 242
243 - new = kzalloc(sizeof(*new), GFP_ATOMIC);
243 + new = kzalloc_obj(*new, GFP_ATOMIC);
244 244 if (!new) {
245 245 NL_SET_ERR_MSG(extack, "Not enough memory for entry");
246 246 return -ENOMEM;
@@ -415,7 +415,7 @@ static int tcf_gate_init(struct net *net, struct nlattr *nla,
415 415 if (err < 0)
416 416 goto release_idr;
417 417
418 - p = kzalloc(sizeof(*p), GFP_KERNEL);
418 + p = kzalloc_obj(*p);
419 419 if (!p) {
420 420 err = -ENOMEM;
421 421 goto chain_put;
modified net/sched/act_tunnel_key.c
@@ -526,7 +526,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
526 526 }
527 527 t = to_tunnel_key(*a);
528 528
529 - params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
529 + params_new = kzalloc_obj(*params_new);
530 530 if (unlikely(!params_new)) {
531 531 NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters");
532 532 ret = -ENOMEM;
modified net/sched/cls_flower.c
@@ -1703,6 +1703,11 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
1703 1703 return -EINVAL;
1704 1704 }
1705 1705 nla_opt_msk = nla_next(nla_opt_msk, &msk_depth);
1706 +
1707 + if (msk_depth && !nla_ok(nla_opt_msk, msk_depth)) {
1708 + NL_SET_ERR_MSG(extack, "A mask attribute is invalid");
1709 + return -EINVAL;
1710 + }
1706 1711 }
1707 1712
1708 1713 return 0;
modified net/sched/cls_u32.c
@@ -370,6 +370,10 @@ static int u32_init(struct tcf_proto *tp)
370 370
371 371 refcount_set(&root_ht->refcnt, 1);
372 372 root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : id2handle(0);
373 + if (root_ht->handle == 0) {
374 + kfree(root_ht);
375 + return -ENOMEM;
376 + }
373 377 root_ht->prio = tp->prio;
374 378 root_ht->is_root = true;
375 379 idr_init(&root_ht->handle_idr);
@@ -695,21 +699,33 @@ out:
695 699 return ret;
696 700 }
697 701
698 - static u32 gen_new_kid(struct tc_u_hnode *ht, u32 htid)
702 + static u32 gen_new_kid(struct tc_u_hnode *ht, u32 htid, int *err)
699 703 {
700 704 u32 index = htid | 0x800;
701 705 u32 max = htid | 0xFFF;
702 706
707 + *err = 0;
708 +
703 709 if (idr_alloc_u32(&ht->handle_idr, NULL, &index, max, GFP_KERNEL)) {
704 710 index = htid + 1;
705 - if (idr_alloc_u32(&ht->handle_idr, NULL, &index, max,
706 - GFP_KERNEL))
707 - index = max;
711 + *err = idr_alloc_u32(&ht->handle_idr, NULL, &index, max,
712 + GFP_KERNEL);
713 + if (*err)
714 + return 0;
708 715 }
709 716
710 717 return index;
711 718 }
712 719
720 + static int u32_kid_extack(int err, struct netlink_ext_ack *extack)
721 + {
722 + if (err == -ENOSPC)
723 + NL_SET_ERR_MSG_MOD(extack, "Hash table node ID pool exhausted");
724 + else
725 + NL_SET_ERR_MSG_MOD(extack, "Failed to allocate node ID");
726 + return err;
727 + }
728 +
713 729 static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {
714 730 [TCA_U32_CLASSID] = { .type = NLA_U32 },
715 731 [TCA_U32_HASH] = { .type = NLA_U32 },
@@ -1079,7 +1095,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
1079 1095 * handle which is used to uniquely identify the match entry.
1080 1096 */
1081 1097 if (!TC_U32_NODE(handle)) {
1082 - handle = gen_new_kid(ht, htid);
1098 + handle = gen_new_kid(ht, htid, &err);
1099 + if (err)
1100 + return u32_kid_extack(err, extack);
1083 1101 } else {
1084 1102 handle = htid | TC_U32_NODE(handle);
1085 1103 err = idr_alloc_u32(&ht->handle_idr, NULL, &handle,
@@ -1091,7 +1109,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
1091 1109 /* The user did not give us a handle; lets just generate one
1092 1110 * from the table's pool of nodeids.
1093 1111 */
1094 - handle = gen_new_kid(ht, htid);
1112 + handle = gen_new_kid(ht, htid, &err);
1113 + if (err)
1114 + return u32_kid_extack(err, extack);
1095 1115 }
1096 1116
1097 1117 if (tb[TCA_U32_SEL] == NULL) {
modified net/sctp/inqueue.c
@@ -212,8 +212,10 @@ new_skb:
212 212 chunk->chunk_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
213 213 skb_pull(chunk->skb, sizeof(*ch));
214 214 chunk->subh.v = NULL; /* Subheader is no longer valid. */
215 -
216 - if (chunk->chunk_end + sizeof(*ch) <= skb_tail_pointer(chunk->skb)) {
215 + if (unlikely(ntohs(ch->length) < sizeof(*ch))) {
216 + chunk->pdiscard = 1;
217 + } else if (chunk->chunk_end + sizeof(*ch) <=
218 + skb_tail_pointer(chunk->skb)) {
217 219 /* This is not a singleton */
218 220 chunk->singleton = 0;
219 221 } else if (chunk->chunk_end > skb_tail_pointer(chunk->skb)) {
modified net/sctp/sm_make_chunk.c
@@ -3215,6 +3215,9 @@ bool sctp_verify_asconf(const struct sctp_association *asoc,
3215 3215 *errp = param.p;
3216 3216 switch (param.p->type) {
3217 3217 case SCTP_PARAM_ERR_CAUSE:
3218 + if (length < sizeof(struct sctp_addip_param) +
3219 + sizeof(struct sctp_errhdr))
3220 + return false;
3218 3221 break;
3219 3222 case SCTP_PARAM_IPV4_ADDRESS:
3220 3223 if (length != sizeof(struct sctp_ipv4addr_param))
@@ -3448,20 +3451,15 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
3448 3451 case SCTP_PARAM_ERR_CAUSE:
3449 3452 length = sizeof(*asconf_ack_param);
3450 3453 err_param = (void *)asconf_ack_param + length;
3451 - asconf_ack_len -= length;
3452 - if (asconf_ack_len > 0)
3453 - return err_param->cause;
3454 - else
3455 - return SCTP_ERROR_INV_PARAM;
3456 - break;
3454 + return err_param->cause;
3457 3455 default:
3458 3456 return SCTP_ERROR_INV_PARAM;
3459 3457 }
3460 3458 }
3461 3459
3462 3460 length = ntohs(asconf_ack_param->param_hdr.length);
3463 - asconf_ack_param = (void *)asconf_ack_param + length;
3464 - asconf_ack_len -= length;
3461 + asconf_ack_param = (void *)asconf_ack_param + SCTP_PAD4(length);
3462 + asconf_ack_len -= SCTP_PAD4(length);
3465 3463 }
3466 3464
3467 3465 return err_code;
modified net/sctp/sm_sideeffect.c
@@ -1545,17 +1545,8 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
1545 1545 timeout = asoc->timeouts[cmd->obj.to];
1546 1546 BUG_ON(!timeout);
1547 1547
1548 - /*
1549 - * SCTP has a hard time with timer starts. Because we process
1550 - * timer starts as side effects, it can be hard to tell if we
1551 - * have already started a timer or not, which leads to BUG
1552 - * halts when we call add_timer. So here, instead of just starting
1553 - * a timer, if the timer is already started, and just mod
1554 - * the timer with the shorter of the two expiration times
1555 - */
1556 - if (!timer_pending(timer))
1548 + if (!timer_reduce(timer, jiffies + timeout))
1557 1549 sctp_association_hold(asoc);
1558 - timer_reduce(timer, jiffies + timeout);
1559 1550 break;
1560 1551
1561 1552 case SCTP_CMD_TIMER_RESTART:
modified net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -282,9 +282,8 @@ int gss_krb5_mic_build_sg(const struct xdr_buf *body,
282 282 unsigned int overflow_nents =
283 283 nsg - XDR_BUF_TO_SG_NENTS + 1;
284 284
285 - *sg_overflow = kmalloc_array(overflow_nents,
286 - sizeof(**sg_overflow),
287 - GFP_NOFS);
285 + *sg_overflow = kmalloc_objs(**sg_overflow, overflow_nents,
286 + GFP_NOFS);
288 287 if (!*sg_overflow)
289 288 return -ENOMEM;
290 289
modified net/sunrpc/svcauth_unix.c
@@ -625,7 +625,7 @@ int sunrpc_nl_unix_gid_get_reqs_dumpit(struct sk_buff *skb,
625 625 if (!cnt)
626 626 return 0;
627 627
628 - items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
628 + items = kzalloc_objs(*items, cnt);
629 629 seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
630 630 if (!items || !seqnos) {
631 631 ret = -ENOMEM;
@@ -1326,7 +1326,7 @@ int sunrpc_nl_ip_map_get_reqs_dumpit(struct sk_buff *skb,
1326 1326 if (!cnt)
1327 1327 return 0;
1328 1328
1329 - items = kcalloc(cnt, sizeof(*items), GFP_KERNEL);
1329 + items = kzalloc_objs(*items, cnt);
1330 1330 seqnos = kcalloc(cnt, sizeof(*seqnos), GFP_KERNEL);
1331 1331 if (!items || !seqnos) {
1332 1332 ret = -ENOMEM;
modified net/sunrpc/xdr.c
@@ -371,8 +371,7 @@ int xdr_buf_to_sg_alloc(const struct xdr_buf *buf, unsigned int offset,
371 371 unsigned int overflow_nents = nsg - sg_head_nents + 1;
372 372 struct scatterlist *overflow;
373 373
374 - overflow = kmalloc_array(overflow_nents, sizeof(*overflow),
375 - gfp);
374 + overflow = kmalloc_objs(*overflow, overflow_nents, gfp);
376 375 if (!overflow)
377 376 return -ENOMEM;
378 377
modified net/tipc/link.c
@@ -504,7 +504,7 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
504 504 snprintf(l->name, sizeof(l->name), "%s:%s-%s:unknown",
505 505 self_str, if_name, peer_str);
506 506
507 - strcpy(l->if_name, if_name);
507 + strscpy(l->if_name, if_name);
508 508 l->addr = peer;
509 509 l->peer_caps = peer_caps;
510 510 l->net = net;
@@ -574,7 +574,7 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer, u8 *peer_id,
574 574 snprintf(l->name, sizeof(l->name), "%s:%s", tipc_bclink_name,
575 575 peer_str);
576 576 } else {
577 - strcpy(l->name, tipc_bclink_name);
577 + strscpy(l->name, tipc_bclink_name);
578 578 }
579 579 trace_tipc_link_reset(l, TIPC_DUMP_ALL, "bclink created!");
580 580 tipc_link_reset(l);
@@ -1898,7 +1898,7 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1898 1898 msg_set_dest_session(hdr, l->peer_session);
1899 1899 }
1900 1900 msg_set_max_pkt(hdr, l->advertised_mtu);
1901 - strcpy(data, l->if_name);
1901 + memcpy(data, l->if_name, TIPC_MAX_IF_NAME);
1902 1902 msg_set_size(hdr, INT_H_SIZE + TIPC_MAX_IF_NAME);
1903 1903 skb_trim(skb, INT_H_SIZE + TIPC_MAX_IF_NAME);
1904 1904 }
modified net/tipc/name_table.c
@@ -763,21 +763,40 @@ struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
763 763 struct tipc_socket_addr *sk, u32 key)
764 764 {
765 765 struct name_table *nt = tipc_name_table(net);
766 + u32 max_user_pub = TIPC_MAX_PUBL - 1;
766 767 struct tipc_net *tn = tipc_net(net);
767 768 struct publication *p = NULL;
768 769 struct sk_buff *skb = NULL;
770 + bool protocol_type = false;
769 771 u32 rc_dests;
770 772
773 + if (ua->sr.type == TIPC_NODE_STATE || ua->sr.type == TIPC_LINK_STATE ||
774 + ua->sr.type == TIPC_TOP_SRV)
775 + protocol_type = true;
776 +
771 777 spin_lock_bh(&tn->nametbl_lock);
778 + if (protocol_type)
779 + goto insert;
772 780
773 - if (nt->local_publ_count >= TIPC_MAX_PUBL) {
774 - pr_warn("Bind failed, max limit %u reached\n", TIPC_MAX_PUBL);
781 + /* Reserve one entry for node state service type because it has cluster
782 + * scope and it is distributed in bulk. So, the maximum number of user's
783 + * publications is (TIPC_MAX_PUBL - 1).
784 + */
785 + if (nt->local_publ_count >= max_user_pub) {
786 + pr_warn("Bind failed, max limit %u reached\n", max_user_pub);
775 787 goto exit;
776 788 }
777 789
790 + insert:
778 791 p = tipc_nametbl_insert_publ(net, ua, sk, key);
779 792 if (p) {
780 - nt->local_publ_count++;
793 + /* Not count node state, link state and topology server types
794 + * so that maximum nt->local_publ_count does not prevent
795 + * protocol service types from being inserted into the name
796 + * table.
797 + */
798 + if (!protocol_type)
799 + nt->local_publ_count++;
781 800 skb = tipc_named_publish(net, p);
782 801 }
783 802 rc_dests = nt->rc_dests;
@@ -810,7 +829,10 @@ void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
810 829
811 830 p = tipc_nametbl_remove_publ(net, ua, sk, key);
812 831 if (p) {
813 - nt->local_publ_count--;
832 + if (p->sr.type != TIPC_NODE_STATE &&
833 + p->sr.type != TIPC_LINK_STATE &&
834 + p->sr.type != TIPC_TOP_SRV)
835 + nt->local_publ_count--;
814 836 skb = tipc_named_withdraw(net, p);
815 837 list_del_init(&p->binding_sock);
816 838 kfree_rcu(p, rcu);
modified net/tipc/node.c
@@ -1333,7 +1333,9 @@ static void tipc_node_reset_links(struct tipc_node *n)
1333 1333
1334 1334 pr_warn("Resetting all links to %x\n", n->addr);
1335 1335
1336 + tipc_node_write_lock(n);
1336 1337 trace_tipc_node_reset_links(n, true, " ");
1338 + tipc_node_write_unlock_fast(n);
1337 1339 for (i = 0; i < MAX_BEARERS; i++) {
1338 1340 tipc_node_link_down(n, i, false);
1339 1341 }
modified net/unix/af_unix.c
@@ -3667,8 +3667,8 @@ static int bpf_iter_unix_realloc_batch(struct bpf_unix_iter_state *iter,
3667 3667 {
3668 3668 struct sock **new_batch;
3669 3669
3670 - new_batch = kvmalloc_array(new_batch_sz, sizeof(*new_batch),
3671 - GFP_USER | __GFP_NOWARN);
3670 + new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
3671 + GFP_USER | __GFP_NOWARN);
3672 3672 if (!new_batch)
3673 3673 return -ENOMEM;
3674 3674
modified net/vmw_vsock/af_vsock.c
@@ -438,6 +438,38 @@ struct sock *vsock_find_connected_socket(struct sockaddr_vm *src,
438 438 }
439 439 EXPORT_SYMBOL_GPL(vsock_find_connected_socket);
440 440
441 + /**
442 + * vsock_check_source - validate a packet source against a socket peer
443 + * @vsk: socket receiving the packet
444 + * @transport: transport receiving the packet
445 + * @src: source address from the packet
446 + *
447 + * Return: true if the packet arrived on the socket's assigned transport and
448 + * its source matches the stored peer. Loopback packets are generated
449 + * internally and always use the local CID as their source, including
450 + * connections using a valid CID alias.
451 + *
452 + * The caller must hold the socket lock and must not call this for listening
453 + * sockets, which accept packets from any source and have no assigned
454 + * transport.
455 + */
456 + bool vsock_check_source(const struct vsock_sock *vsk,
457 + const struct vsock_transport *transport,
458 + const struct sockaddr_vm *src)
459 + {
460 + if (vsk->transport != transport)
461 + return false;
462 +
463 + if (src->svm_port != vsk->remote_addr.svm_port)
464 + return false;
465 +
466 + if (src->svm_cid == vsk->remote_addr.svm_cid)
467 + return true;
468 +
469 + return transport->get_local_cid() == VMADDR_CID_LOCAL;
470 + }
471 + EXPORT_SYMBOL_GPL(vsock_check_source);
472 +
441 473 void vsock_remove_sock(struct vsock_sock *vsk)
442 474 {
443 475 /* Transport reassignment must not remove the binding. */
modified net/vmw_vsock/virtio_transport_common.c
@@ -1836,7 +1836,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
1836 1836 * lock_sock (note: listener sockets are not assigned to any transport)
1837 1837 */
1838 1838 if (sock_flag(sk, SOCK_DONE) ||
1839 - (sk->sk_state != TCP_LISTEN && vsk->transport != &t->transport)) {
1839 + (sk->sk_state != TCP_LISTEN &&
1840 + !vsock_check_source(vsk, &t->transport, &src))) {
1840 1841 (void)virtio_transport_reset_no_sock(t, skb, net);
1841 1842 release_sock(sk);
1842 1843 sock_put(sk);
modified net/vmw_vsock/vmci_transport.c
@@ -680,11 +680,13 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)
680 680 struct vmci_transport_packet *pkt;
681 681 struct vsock_sock *vsk;
682 682 bool bh_process_pkt;
683 + bool drop_pkt;
683 684 int err;
684 685
685 686 sk = NULL;
686 687 err = VMCI_SUCCESS;
687 688 bh_process_pkt = false;
689 + drop_pkt = false;
688 690
689 691 /* Ignore incoming packets from resources that aren't vsock
690 692 * implementations.
@@ -765,17 +767,29 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)
765 767 bh_lock_sock(sk);
766 768
767 769 if (!sock_owned_by_user(sk)) {
768 - /* The local context ID may be out of date, update it. */
769 - vsk->local_addr.svm_cid = dst.svm_cid;
770 + if (sk->sk_state != TCP_LISTEN &&
771 + !vsock_check_source(vsk, &vmci_transport, &src)) {
772 + drop_pkt = true;
773 + err = VMCI_ERROR_NO_ACCESS;
774 + } else {
775 + /* The local context ID may be out of date, update it. */
776 + vsk->local_addr.svm_cid = dst.svm_cid;
770 777
771 - if (sk->sk_state == TCP_ESTABLISHED)
772 - vmci_trans(vsk)->notify_ops->handle_notify_pkt(
773 - sk, pkt, true, &dst, &src,
774 - &bh_process_pkt);
778 + if (sk->sk_state == TCP_ESTABLISHED)
779 + vmci_trans(vsk)->notify_ops->handle_notify_pkt(sk, pkt, true,
780 + &dst, &src,
781 + &bh_process_pkt);
782 + }
775 783 }
776 784
777 785 bh_unlock_sock(sk);
778 786
787 + if (drop_pkt) {
788 + if (vmci_transport_send_reset_bh(&dst, &src, pkt) < 0)
789 + pr_err("unable to send reset\n");
790 + goto out;
791 + }
792 +
779 793 if (!bh_process_pkt) {
780 794 struct vmci_transport_recv_pkt_info *recv_pkt_info;
781 795
@@ -900,6 +914,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)
900 914 {
901 915 struct vmci_transport_recv_pkt_info *recv_pkt_info;
902 916 struct vmci_transport_packet *pkt;
917 + struct sockaddr_vm src;
903 918 struct sock *sk;
904 919
905 920 recv_pkt_info =
@@ -908,6 +923,12 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)
908 923 pkt = &recv_pkt_info->pkt;
909 924
910 925 lock_sock(sk);
926 + vsock_addr_init(&src, pkt->dg.src.context, pkt->src_port);
927 + if (sk->sk_state != TCP_LISTEN &&
928 + !vsock_check_source(vsock_sk(sk), &vmci_transport, &src)) {
929 + vmci_transport_reply_reset(pkt);
930 + goto out;
931 + }
911 932
912 933 /* The local context ID may be out of date. */
913 934 vsock_sk(sk)->local_addr.svm_cid = pkt->dg.dst.context;
@@ -937,6 +958,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)
937 958 break;
938 959 }
939 960
961 + out:
940 962 release_sock(sk);
941 963 kfree(recv_pkt_info);
942 964 /* Release reference obtained in the stream callback when we fetched
modified net/wireless/core.c
@@ -311,9 +311,8 @@ int cfg80211_nan_set_local_schedule(struct cfg80211_registered_device *rdev,
311 311 if (!sched->n_channels)
312 312 return 0;
313 313
314 - wdev->u.nan.chandefs = kcalloc(sched->n_channels,
315 - sizeof(*wdev->u.nan.chandefs),
316 - GFP_KERNEL);
314 + wdev->u.nan.chandefs = kzalloc_objs(*wdev->u.nan.chandefs,
315 + sched->n_channels);
317 316 if (!wdev->u.nan.chandefs)
318 317 return -ENOMEM;
319 318
modified net/wireless/nl80211.c
@@ -17330,8 +17330,7 @@ static int nl80211_parse_nan_channel(struct cfg80211_registered_device *rdev,
17330 17330 u8 n_rx_nss;
17331 17331 int ret;
17332 17332
17333 - channel_parsed = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*channel_parsed),
17334 - GFP_KERNEL);
17333 + channel_parsed = kzalloc_objs(*channel_parsed, NL80211_ATTR_MAX + 1);
17335 17334 if (!channel_parsed)
17336 17335 return -ENOMEM;
17337 17336
@@ -17554,8 +17553,7 @@ static int nl80211_nan_set_peer_sched(struct sk_buff *skb,
17554 17553 }
17555 17554
17556 17555 if (n_channels) {
17557 - nan_channels = kcalloc(n_channels, sizeof(*nan_channels),
17558 - GFP_KERNEL);
17556 + nan_channels = kzalloc_objs(*nan_channels, n_channels);
17559 17557 if (!nan_channels)
17560 17558 return -ENOMEM;
17561 17559 }
@@ -17693,8 +17691,7 @@ static int nl80211_nan_set_local_sched(struct sk_buff *skb,
17693 17691 info->nlhdr, GENL_HDRLEN, rem)
17694 17692 n_channels++;
17695 17693
17696 - sched = kzalloc(struct_size(sched, nan_channels, n_channels),
17697 - GFP_KERNEL);
17694 + sched = kzalloc_flex(*sched, nan_channels, n_channels);
17698 17695 if (!sched)
17699 17696 return -ENOMEM;
17700 17697
modified rust/kernel/pci/irq.rs
@@ -151,8 +151,10 @@ impl<'a> IrqVectorRegistration<'a> {
151 151 /// [`Self::len()`].
152 152 #[inline]
153 153 pub fn index(&self, index: usize) -> Result<IrqVector<'_>> {
154 + let index = u32::try_from(index)?;
155 +
154 156 // SAFETY: `self.dev.as_raw()` is a valid pointer to a `struct pci_dev`.
155 - let irq = unsafe { bindings::pci_irq_vector(self.dev.as_raw(), index as u32) };
157 + let irq = unsafe { bindings::pci_irq_vector(self.dev.as_raw(), index) };
156 158 if irq < 0 {
157 159 return Err(Error::from_errno(irq));
158 160 }
modified security/Kconfig.hardening
@@ -278,7 +278,7 @@ config CC_HAS_RANDSTRUCT
278 278
279 279 choice
280 280 prompt "Randomize layout of sensitive kernel structures"
281 - default RANDSTRUCT_FULL if COMPILE_TEST && (GCC_PLUGINS || CC_HAS_RANDSTRUCT)
281 + default RANDSTRUCT_FULL if !(RUST_IS_AVAILABLE && HAVE_RUST) && COMPILE_TEST && (GCC_PLUGINS || CC_HAS_RANDSTRUCT)
282 282 default RANDSTRUCT_NONE
283 283 help
284 284 If you enable this, the layouts of structures that are entirely
modified security/integrity/ima/Kconfig
@@ -46,12 +46,16 @@ config IMA_KEXEC
46 46
47 47 config IMA_MEASURE_PCR_IDX
48 48 int
49 + prompt "PCR Index for Aggregate" if EXPERT
49 50 range 8 14
50 51 default 10
51 52 help
52 53 IMA_MEASURE_PCR_IDX determines the TPM PCR register index
53 54 that IMA uses to maintain the integrity aggregate of the
54 - measurement list. If unsure, use the default 10.
55 + measurement list. Most attestation tooling expects PCR 10.
56 +
57 + The default is almost always what you want. Only change this
58 + if you know what you are doing.
55 59
56 60 config IMA_LSM_RULES
57 61 bool
modified security/integrity/ima/ima_appraise.c
@@ -748,6 +748,8 @@ static int validate_hash_algo(struct dentry *dentry,
748 748 return -EACCES;
749 749
750 750 path = dentry_path(dentry, pathbuf, PATH_MAX);
751 + if (IS_ERR(path))
752 + path = NULL;
751 753
752 754 integrity_audit_msg(AUDIT_INTEGRITY_DATA, d_inode(dentry), path,
753 755 "set_data", errmsg, -EACCES, 0);
modified security/integrity/ima/ima_policy.c
@@ -165,7 +165,10 @@ static struct ima_rule_entry dont_measure_rules[] __ro_after_init = {
165 165 {.action = DONT_MEASURE, .fsmagic = CGROUP2_SUPER_MAGIC,
166 166 .flags = IMA_FSMAGIC},
167 167 {.action = DONT_MEASURE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC},
168 - {.action = DONT_MEASURE, .fsmagic = EFIVARFS_MAGIC, .flags = IMA_FSMAGIC}
168 + {.action = DONT_MEASURE, .fsmagic = EFIVARFS_MAGIC,
169 + .flags = IMA_FSMAGIC},
170 + {.action = DONT_MEASURE, .fsmagic = CONFIGFS_MAGIC,
171 + .flags = IMA_FSMAGIC}
169 172 };
170 173
171 174 static struct ima_rule_entry original_measurement_rules[] __ro_after_init = {
@@ -211,6 +214,8 @@ static struct ima_rule_entry default_appraise_rules[] __ro_after_init = {
211 214 {.action = DONT_APPRAISE, .fsmagic = EFIVARFS_MAGIC, .flags = IMA_FSMAGIC},
212 215 {.action = DONT_APPRAISE, .fsmagic = CGROUP_SUPER_MAGIC, .flags = IMA_FSMAGIC},
213 216 {.action = DONT_APPRAISE, .fsmagic = CGROUP2_SUPER_MAGIC, .flags = IMA_FSMAGIC},
217 + {.action = DONT_APPRAISE, .fsmagic = CONFIGFS_MAGIC,
218 + .flags = IMA_FSMAGIC},
214 219 #ifdef CONFIG_IMA_WRITE_POLICY
215 220 {.action = APPRAISE, .func = POLICY_CHECK,
216 221 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
modified security/integrity/ima/ima_queue.c
@@ -75,8 +75,7 @@ static struct hlist_head *ima_alloc_replace_htable(void)
75 75 struct hlist_head *old_htable, *new_htable;
76 76
77 77 /* Initializing to zeros is equivalent to call HLIST_HEAD_INIT. */
78 - new_htable = kcalloc(IMA_MEASURE_HTABLE_SIZE, sizeof(struct hlist_head),
79 - GFP_KERNEL);
78 + new_htable = kzalloc_objs(struct hlist_head, IMA_MEASURE_HTABLE_SIZE);
80 79 if (!new_htable)
81 80 return ERR_PTR(-ENOMEM);
82 81
modified security/selinux/hooks.c
@@ -7267,24 +7267,6 @@ static int selinux_bpf_prog(struct bpf_prog *prog)
7267 7267 BPF__PROG_RUN, NULL);
7268 7268 }
7269 7269
7270 - static u32 selinux_bpffs_creator_sid(u32 fd)
7271 - {
7272 - struct path path;
7273 - struct super_block *sb;
7274 - struct superblock_security_struct *sbsec;
7275 -
7276 - CLASS(fd, f)(fd);
7277 -
7278 - if (fd_empty(f))
7279 - return SECSID_NULL;
7280 -
7281 - path = fd_file(f)->f_path;
7282 - sb = path.dentry->d_sb;
7283 - sbsec = selinux_superblock(sb);
7284 -
7285 - return sbsec->creator_sid;
7286 - }
7287 -
7288 7270 static int selinux_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
7289 7271 struct bpf_token *token, bool kernel)
7290 7272 {
@@ -7297,7 +7279,7 @@ static int selinux_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
7297 7279 if (!token)
7298 7280 ssid = bpfsec->sid;
7299 7281 else
7300 - ssid = selinux_bpffs_creator_sid(attr->map_token_fd);
7282 + ssid = selinux_bpf_token_security(token)->grantor_sid;
7301 7283
7302 7284 return avc_has_perm(ssid, bpfsec->sid, SECCLASS_BPF, BPF__MAP_CREATE,
7303 7285 NULL);
@@ -7315,7 +7297,7 @@ static int selinux_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
7315 7297 if (!token)
7316 7298 ssid = bpfsec->sid;
7317 7299 else
7318 - ssid = selinux_bpffs_creator_sid(attr->prog_token_fd);
7300 + ssid = selinux_bpf_token_security(token)->grantor_sid;
7319 7301
7320 7302 return avc_has_perm(ssid, bpfsec->sid, SECCLASS_BPF, BPF__PROG_LOAD,
7321 7303 NULL);
@@ -7329,12 +7311,14 @@ static int selinux_bpf_token_create(struct bpf_token *token,
7329 7311 const struct path *path)
7330 7312 {
7331 7313 struct bpf_security_struct *bpfsec;
7332 - u32 sid = selinux_bpffs_creator_sid(attr->token_create.bpffs_fd);
7314 + struct superblock_security_struct *sbsec;
7333 7315 int err;
7334 7316
7317 + sbsec = selinux_superblock(path->dentry->d_sb);
7318 +
7335 7319 bpfsec = selinux_bpf_token_security(token);
7336 7320 bpfsec->sid = current_sid();
7337 - bpfsec->grantor_sid = sid;
7321 + bpfsec->grantor_sid = sbsec->creator_sid;
7338 7322
7339 7323 bpfsec->perms = 0;
7340 7324 /**
@@ -7343,15 +7327,15 @@ static int selinux_bpf_token_create(struct bpf_token *token,
7343 7327 * in the allowed_cmds bitmap.
7344 7328 */
7345 7329 if (bpf_token_cmd(token, BPF_MAP_CREATE)) {
7346 - err = avc_has_perm(bpfsec->sid, sid, SECCLASS_BPF,
7347 - BPF__MAP_CREATE_AS, NULL);
7330 + err = avc_has_perm(bpfsec->sid, bpfsec->grantor_sid,
7331 + SECCLASS_BPF, BPF__MAP_CREATE_AS, NULL);
7348 7332 if (err)
7349 7333 return err;
7350 7334 bpfsec->perms |= BPF__MAP_CREATE;
7351 7335 }
7352 7336 if (bpf_token_cmd(token, BPF_PROG_LOAD)) {
7353 - err = avc_has_perm(bpfsec->sid, sid, SECCLASS_BPF,
7354 - BPF__PROG_LOAD_AS, NULL);
7337 + err = avc_has_perm(bpfsec->sid, bpfsec->grantor_sid,
7338 + SECCLASS_BPF, BPF__PROG_LOAD_AS, NULL);
7355 7339 if (err)
7356 7340 return err;
7357 7341 bpfsec->perms |= BPF__PROG_LOAD;
modified sound/core/compress_offload.c
@@ -107,7 +107,7 @@ static int snd_compr_open(struct inode *inode, struct file *f)
107 107 return -EINVAL;
108 108 }
109 109
110 - data = kzalloc(sizeof(*data), GFP_KERNEL);
110 + data = kzalloc_obj(*data);
111 111 if (!data) {
112 112 snd_card_unref(compr->card);
113 113 return -ENOMEM;
@@ -119,7 +119,7 @@ static int snd_compr_open(struct inode *inode, struct file *f)
119 119 data->stream.direction = dirn;
120 120 data->stream.private_data = compr->private_data;
121 121 data->stream.device = compr;
122 - runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
122 + runtime = kzalloc_obj(*runtime);
123 123 if (!runtime) {
124 124 kfree(data);
125 125 snd_card_unref(compr->card);
modified sound/core/control.c

No content changes.

This diff is too large to show in full - only the first part is shown.