Compare

19ed235c1adcaf40f05997dfe8b96eb209effd35..5e0ed1108504dae408e8cfaabf7ee5f7bb180bca

Revert "dma-buf: Make DMABUF_DEBUG default to y on DEBUG_KERNEL kernels"

This reverts commit 143755bdabaa96776c24f878014608e9cb44f930.

That commit fixed a dangling reference in the DMABUF_DEBUG default
and thereby enabled the option - and with it the page-stripping
sg_table wrapper that dma_buf_map_attachment() hands to importers -
on every kernel with DEBUG_KERNEL=y, i.e. virtually every distro
kernel.

drm/msm is broken by the wrapper.  Both of msm's map paths consume
sg->length and sg_phys() of the attachment sg_table:
msm_iommu_pagetable_map() for the per-process GPU pagetables, and
iommu_map_sg() (via iommu_map_sgtable()) for scanout.  The wrapper
zeroes sg->length and strips the page pointers, so mappings of
imported dma-bufs silently map nothing, and userspace observes
arm-smmu translation faults from UCHE, e.g. during hardware video
decode (clapper, chromium) on Adreno systems:

  gpu fault: ttbr0=000000088a889000 iova=000000010741c000 dir=READ
  type=TRANSLATION source=UCHE

Bisected on a Snapdragon X1E78100 laptop as v7.3-rc3 good,
v7.3-rc4 bad, culprit 143755bdabaa9.

Switching msm to sg_dma_address()/sg_dma_len() is not a trivial fix
either: those fields are only valid for sg_tables that msm has
dma-mapped itself, which native non-MSM_BO_WC objects' sg_tables
are not, so the conversion needs more work.  The msm maintainer has
therefore requested restoring the previous default for v7.3, to be
revisited once msm no longer consumes struct page and sg->length of
imported sg_tables.

Link: https://lore.kernel.org/linux-arm-msm/20260923074256.9357-1-liujianfeng1994@gmail.com/
Suggested-by: Rob Clark <robin.clark@oss.qualcomm.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>

Signed-off-by: Jianfeng Liu <liujianfeng1994@gmail.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
 [sumits: as discussed on
  https://lore.kernel.org/all/CAO_48GEh1p52pA_-NE=rN=_NQ=oAXpeHgHGVZCH6uPnFq7G1gQ@mail.gmail.com/
  applying this revert for 7.3 unblock]
Link: https://patch.msgid.link/20260926022026.10539-1-liujianfeng1994@gmail.com

Jianfeng Liu <liujianfeng1994@gmail.com> · 2026-09-26 02:20 UTC · committed by Sumit Semwal

Browse files
635 files changed, +8407 −4377
modified .mailmap
@@ -421,6 +421,7 @@ Jens Axboe <axboe@kernel.dk> <axboe@suse.de>
421 421 Jens Axboe <axboe@kernel.dk> <jens.axboe@oracle.com>
422 422 Jens Axboe <axboe@kernel.dk> <axboe@fb.com>
423 423 Jens Axboe <axboe@kernel.dk> <axboe@meta.com>
424 + Jens Axboe <axboe@kernel.dk> <axboe@anthropic.com>
424 425 Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
425 426 Jens Wiklander <jenswi@kernel.org> <jens.wiklander@linaro.org>
426 427 Jernej Skrabec <jernej.skrabec@gmail.com> <jernej.skrabec@siol.net>
@@ -551,6 +552,9 @@ Li Yang <leoyang.li@nxp.com> <leo@zh-kernel.org>
551 552 Lior David <quic_liord@quicinc.com> <liord@codeaurora.org>
552 553 Loic Poulain <loic.poulain@oss.qualcomm.com> <loic.poulain@linaro.org>
553 554 Loic Poulain <loic.poulain@oss.qualcomm.com> <loic.poulain@intel.com>
555 + Lorenzo Bianconi <lorenzo@kernel.org> <lorenzo.bianconi@redhat.com>
556 + Lorenzo Bianconi <lorenzo@kernel.org> <lorenzo.bianconi@st.com>
557 + Lorenzo Bianconi <lorenzo@kernel.org> <lorenzo.bianconi83@gmail.com>
554 558 Lorenzo Pieralisi <lpieralisi@kernel.org> <lorenzo.pieralisi@arm.com>
555 559 Lorenzo Stoakes <ljs@kernel.org> <lstoakes@gmail.com>
556 560 Lorenzo Stoakes <ljs@kernel.org> <lorenzo.stoakes@oracle.com>
modified Documentation/ABI/testing/sysfs-fs-erofs
@@ -5,7 +5,7 @@ Description: Shows all enabled kernel features.
5 5 Supported features:
6 6 compr_cfgs, big_pcluster, chunked_file, device_table,
7 7 compr_head2, sb_chksum, ztailpacking, dedupe, fragments,
8 - 48bit, metabox.
8 + xattr_prefixes, 48bit, metabox.
9 9
10 10 What: /sys/fs/erofs/<disk>/sync_decompress
11 11 Date: November 2021
modified Documentation/admin-guide/kernel-parameters.txt
@@ -4987,18 +4987,6 @@ Kernel parameters
4987 4987 Set to non-zero if a chip is present that snoops speed
4988 4988 changes. Disabled by default.
4989 4989
4990 - pata_legacy.ht6560a= [HW,LIBATA]
4991 - Format: <int>
4992 - Set to 1, 2, or 3 for HT 6560A on the primary channel,
4993 - the secondary channel, or both channels respectively.
4994 - Disabled by default.
4995 -
4996 - pata_legacy.ht6560b= [HW,LIBATA]
4997 - Format: <int>
4998 - Set to 1, 2, or 3 for HT 6560B on the primary channel,
4999 - the secondary channel, or both channels respectively.
5000 - Disabled by default.
5001 -
5002 4990 pata_legacy.iordy_mask= [HW,LIBATA]
5003 4991 Format: <int>
5004 4992 IORDY enable mask. Set individual bits to allow IORDY
@@ -5011,18 +4999,6 @@ Kernel parameters
5011 4999 with the sequence. By default IORDY is allowed across
5012 5000 all channels.
5013 5001
5014 - pata_legacy.opti82c46x= [HW,LIBATA]
5015 - Format: <int>
5016 - Set to 1, 2, or 3 for Opti 82c611A on the primary
5017 - channel, the secondary channel, or both channels
5018 - respectively. Disabled by default.
5019 -
5020 - pata_legacy.opti82c611a= [HW,LIBATA]
5021 - Format: <int>
5022 - Set to 1, 2, or 3 for Opti 82c465MV on the primary
5023 - channel, the secondary channel, or both channels
5024 - respectively. Disabled by default.
5025 -
5026 5002 pata_legacy.pio_mask= [HW,LIBATA]
5027 5003 Format: <int>
5028 5004 PIO mode mask for autospeed devices. Set individual
@@ -5046,19 +5022,6 @@ Kernel parameters
5046 5022 the first port in the list above (0x1f0), and so on.
5047 5023 By default all supported ports are probed.
5048 5024
5049 - pata_legacy.qdi= [HW,LIBATA]
5050 - Format: <int>
5051 - Set to non-zero to probe QDI controllers. By default
5052 - set to 1 if CONFIG_PATA_QDI_MODULE, 0 otherwise.
5053 -
5054 - pata_legacy.winbond= [HW,LIBATA]
5055 - Format: <int>
5056 - Set to non-zero to probe Winbond controllers. Use
5057 - the standard I/O port (0x130) if 1, otherwise the
5058 - value given is the I/O port to use (typically 0x1b0).
5059 - By default set to 1 if CONFIG_PATA_WINBOND_VLB_MODULE,
5060 - 0 otherwise.
5061 -
5062 5025 pata_platform.pio_mask= [HW,LIBATA]
5063 5026 Format: <int>
5064 5027 Supported PIO mode mask. Set individual bits to allow
modified Documentation/admin-guide/sysctl/kernel.rst
@@ -1416,7 +1416,7 @@ Controls whether userspace may arm Syscall User Dispatch via
1416 1416 == ===================================================================
1417 1417
1418 1418 Only present when the kernel is built with ``CONFIG_SYSCALL_USER_DISPATCH``
1419 - and ``CONFIG_PROC_SYSCTL``.
1419 + and ``CONFIG_SYSCTL``.
1420 1420
1421 1421
1422 1422 sysctl_writes_strict
modified Documentation/arch/riscv/hwprobe.rst
@@ -155,7 +155,8 @@ The following keys are defined:
155 155 defined in version 1.0 of the RISC-V Cryptography Extensions Volume II.
156 156
157 157 * :c:macro:`RISCV_HWPROBE_EXT_ZFH`: The Zfh extension version 1.0 is supported
158 - as defined in the RISC-V ISA manual.
158 + as defined in the RISC-V ISA manual. Zfh is a superset of Zfhmin, so
159 + RISCV_HWPROBE_EXT_ZFHMIN is reported whenever RISCV_HWPROBE_EXT_ZFH is.
159 160
160 161 * :c:macro:`RISCV_HWPROBE_EXT_ZFHMIN`: The Zfhmin extension version 1.0 is
161 162 supported as defined in the RISC-V ISA manual.
@@ -164,8 +165,9 @@ The following keys are defined:
164 165 is supported as defined in the RISC-V ISA manual.
165 166
166 167 * :c:macro:`RISCV_HWPROBE_EXT_ZVFH`: The Zvfh extension is supported as
167 - defined in the RISC-V Vector manual starting from commit e2ccd0548d6c
168 - ("Remove draft warnings from Zvfh[min]").
168 + defined in the RISC-V Vector manual starting from commit e2ccd0548d6c
169 + ("Remove draft warnings from Zvfh[min]"). Zvfh is a superset of Zvfhmin,
170 + so RISCV_HWPROBE_EXT_ZVFHMIN is reported whenever RISCV_HWPROBE_EXT_ZVFH is.
169 171
170 172 * :c:macro:`RISCV_HWPROBE_EXT_ZVFHMIN`: The Zvfhmin extension is supported as
171 173 defined in the RISC-V Vector manual starting from commit e2ccd0548d6c
modified Documentation/devicetree/bindings/regulator/fcs,fan53555.yaml
@@ -23,6 +23,7 @@ properties:
23 23 - silergy,syr827
24 24 - silergy,syr828
25 25 - tcs,tcs4525
26 + - tcs,tcs4526
26 27 - items:
27 28 - const: rockchip,rk8601
28 29 - const: rockchip,rk8600
modified Documentation/devicetree/bindings/riscv/cpus.yaml
@@ -117,8 +117,8 @@ properties:
117 117 $ref: /schemas/types.yaml#/definitions/uint32
118 118 description:
119 119 VLEN/8, the vector register length in bytes. This property is required on
120 - thead systems where the vector register length is not identical on all harts, or
121 - the vlenb CSR is not available.
120 + thead systems where the vector register length is not identical on all
121 + harts, or the vlenb CSR is not available.
122 122
123 123 # RISC-V has multiple properties for cache op block sizes as the sizes
124 124 # differ between individual CBO extensions
@@ -151,8 +151,8 @@ anyOf:
151 151 - riscv,isa-base
152 152
153 153 dependencies:
154 - riscv,isa-base: [ "riscv,isa-extensions" ]
155 - riscv,isa-extensions: [ "riscv,isa-base" ]
154 + riscv,isa-base: ["riscv,isa-extensions"]
155 + riscv,isa-extensions: ["riscv,isa-base"]
156 156
157 157 required:
158 158 - interrupt-controller
modified Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
@@ -44,6 +44,21 @@ allOf:
44 44 else:
45 45 properties:
46 46 starfive,sfc-filter-syscon: false
47 + - if:
48 + properties:
49 + compatible:
50 + contains:
51 + const: ultrarisc,dp1000-spi
52 + then:
53 + properties:
54 + reg:
55 + maxItems: 1
56 + clocks:
57 + minItems: 2
58 + clock-names:
59 + minItems: 2
60 + required:
61 + - clock-names
47 62
48 63 properties:
49 64 compatible:
@@ -63,6 +78,7 @@ properties:
63 78 - mscc,jaguar2-spi
64 79 - sophgo,sg2042-spi
65 80 - thead,th1520-spi
81 + - ultrarisc,dp1000-spi
66 82 - const: snps,dw-apb-ssi
67 83 - description: Vendor controllers compatible with v1.01a
68 84 items:
modified Documentation/hwmon/gpd-fan.rst
@@ -67,7 +67,7 @@ pwm1_enable
67 67 at full speed. Write "1" to set to manual, write "2" to let the EC control
68 68 decide fan speed. Read this attribute to see current status.
69 69
70 - NB:In consideration of the safety of the device, when setting to manual mode,
70 + NB: In consideration of the safety of the device, when setting to manual mode,
71 71 the pwm speed will be set to the maximum value (255) by default. You can set
72 72 a different value by writing pwm1 later.
73 73
modified Documentation/hwmon/hwmon-kernel-api.rst
@@ -42,6 +42,9 @@ register/unregister functions::
42 42
43 43 char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
44 44
45 + int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
46 + u32 attr, int channel);
47 +
45 48 void hwmon_lock(struct device *dev);
46 49 void hwmon_unlock(struct device *dev);
47 50
@@ -90,6 +93,18 @@ implemented in the driver, or debugfs functions, hwmon_lock() and hwmon_unlock()
90 93 can be used to ensure that calls to those functions are serialized. Those
91 94 functions also support guard() and scoped_guard() variants.
92 95
96 + Drivers can call hwmon_notify_event() to notify userspace and the thermal
97 + subsystem when a hardware monitoring event (such as an alarm or a fault
98 + condition) occurs or clears. The parameters are the hwmon device, the sensor
99 + type, the attribute identifier associated with the event (such as
100 + hwmon_temp_max_alarm or hwmon_fan_fault), and the sensor channel number.
101 + hwmon_notify_event() generates a sysfs event (calling sysfs_notify()) and a
102 + udev event with the attribute name passed in the NAME environment property
103 + (e.g., "NAME=temp1_max_alarm"). If the event is for a temperature sensor and
104 + the sensor is attached to a thermal zone, it also notifies the thermal
105 + subsystem to update the thermal zone. hwmon_notify_event() returns 0 on
106 + success or a negative error code on failure.
107 +
93 108 Using devm_hwmon_device_register_with_info()
94 109 --------------------------------------------
95 110
modified Documentation/netlink/specs/rt-link.yaml
@@ -898,6 +898,8 @@ attribute-sets:
898 898 -
899 899 name: txqlen
900 900 type: u32
901 + checks:
902 + max: 32767
901 903 -
902 904 name: map
903 905 type: binary
modified Documentation/translations/zh_CN/arch/riscv/patch-acceptance.rst
@@ -15,19 +15,41 @@ arch/riscv 开发者维护指南
15 15
16 16 概述
17 17 ----
18 - RISC-V指令集体系结构是公开开发的:
18 + RISC-V 指令集体系结构是公开开发的:
19 19 正在进行的草案可供所有人查看和测试实现。新模块或者扩展草案可能会在开发过程中发
20 - 生更改---有时以不兼容的方式对以前的草案进行更改。这种灵活性可能会给RISC-V Linux
21 - 维护者带来挑战。Linux开发过程更喜欢经过良好检查和测试的代码,而不是试验代码。我
22 - 们希望推广同样的规则到即将被内核合并的RISC-V相关代码。
20 + 生更改 --- 有时以不兼容的方式对以前的草案进行更改。这种灵活性可能会给 RISC-V
21 + Linux 维护者带来挑战。Linux 维护者不赞成频繁的变更,且 Linux 开发过程更喜欢经过
22 + 良好检查和测试的代码,而不是试验代码。我们希望推广同样的规则到即将被内核合并的
23 + RISC-V 相关代码。
24 +
25 + Patchwork
26 + ---------
27 +
28 + RISC-V 有一个 patchwork 实例,可以在那里查看补丁的状态:
29 +
30 + https://patchwork.kernel.org/project/linux-riscv/list/
31 +
32 + 如果你的补丁不在默认视图中出现,那么 RISC-V 维护者很有可能已要求修改,或者希望
33 + 将其应用到另一个代码树上。
34 +
35 + 自动化流程会在该 patchwork 实例上运行,在每个补丁到达时立刻对其进行构建/测试。
36 + 自动化流程会根据补丁是否被识别为修复,选用 RISC-V `for-next` 或 `fixes` 分支
37 + 当前的 HEAD;若上述均应用失败,则使用 RISC-V `master` 分支。补丁系列被应用到的具
38 + 体提交将标注在 patchwork 上。任何检查未通过的补丁通常不会被应用,并且在大多数情
39 + 况下将需要重新提交。
23 40
24 41 附加的提交检查单
25 42 ----------------
26 - 我们仅接受相关标准已经被RISC-V基金会标准为“已批准”或“已冻结”的扩展或模块的补丁。
27 - (开发者当然可以维护自己的Linux内核树,其中包含所需代码扩展草案的代码。)
28 -
29 - 此外,RISC-V规范允许爱好者创建自己的自定义扩展。这些自定义拓展不需要通过RISC-V
30 - 基金会的任何审核或批准。为了避免将爱好者一些特别的RISC-V拓展添加进内核代码带来
31 - 的维护复杂性和对性能的潜在影响,我们将只接受RISC-V基金会正式冻结或批准的的扩展
32 - 补丁。(开发者当然可以维护自己的Linux内核树,其中包含他们想要的任何自定义扩展
33 - 的代码。)
43 + 我们仅接受针对新模块或扩展的补丁,前提是这些模块或扩展的规范被列为未来不太可能发
44 + 生不兼容的变更。对于来自 RISC-V 基金会的规范,这意味着“已冻结”或“已批准”,对于
45 + UEFI 论坛的规范,这意味着已发布的 ECR。(开发者当然可以维护自己的 Linux 内核树,
46 + 其中包含他们所需的任何扩展草案的代码。)
47 +
48 + 此外,RISC-V 规范允许实现者创建自己的自定义扩展。这些自定义扩展不需要通过 RISC-V
49 + 基金会的任何审核或批准流程。为了避免因添加实现者特定的 RISC-V 扩展带来的维护复杂
50 + 性和对性能的潜在影响,我们将只考虑符合以下任一条件的扩展补丁:
51 +
52 + - 已由 RISC-V 基金会正式冻结或批准
53 + - 已按照标准 Linux 惯例,在广泛可用的硬件中实现
54 +
55 + (实现者当然可以维护自己的 Linux 内核树,其中包含他们所需的任何自定义扩展的代码。)
modified MAINTAINERS
@@ -4512,7 +4512,7 @@ AYANEO PLATFORM EC DRIVER
4512 4512 M: Antheas Kapenekakis <lkml@antheas.dev>
4513 4513 L: platform-driver-x86@vger.kernel.org
4514 4514 S: Maintained
4515 - F: Documentation/ABI/testing/sysfs-platform-ayaneo
4515 + F: Documentation/ABI/testing/sysfs-platform-ayaneo-ec
4516 4516 F: drivers/platform/x86/ayaneo-ec.c
4517 4517
4518 4518 AZ6007 DVB DRIVER
@@ -8011,6 +8011,7 @@ F: include/uapi/drm/ivpu_accel.h
8011 8011
8012 8012 DRM ACCEL DRIVER FOR ROCKCHIP NPU
8013 8013 M: Tomeu Vizoso <tomeu@tomeuvizoso.net>
8014 + R: Heiko Stuebner <heiko@sntech.de>
8014 8015 L: dri-devel@lists.freedesktop.org
8015 8016 S: Supported
8016 8017 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -8573,7 +8574,7 @@ F: Documentation/devicetree/bindings/display/panel/synaptics,r63353.yaml
8573 8574 F: drivers/gpu/drm/panel/panel-synaptics-r63353.c
8574 8575
8575 8576 DRM DRIVER FOR SYNOPSYS DESIGNWARE DISPLAYPORT BRIDGE
8576 - M: Andy Yan <andy.yan@rock-chips.com>
8577 + M: Andy Yan <andyshrk@163.com>
8577 8578 S: Maintained
8578 8579 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
8579 8580 F: Documentation/devicetree/bindings/display/rockchip/rockchip,dw-dp.yaml
@@ -8926,7 +8927,7 @@ F: include/linux/platform_data/shmob_drm.h
8926 8927 DRM DRIVERS FOR ROCKCHIP
8927 8928 M: Sandy Huang <hjc@rock-chips.com>
8928 8929 M: Heiko Stübner <heiko@sntech.de>
8929 - M: Andy Yan <andy.yan@rock-chips.com>
8930 + M: Andy Yan <andyshrk@163.com>
8930 8931 L: dri-devel@lists.freedesktop.org
8931 8932 L: linux-rockchip@lists.infradead.org
8932 8933 S: Maintained
@@ -12880,7 +12881,7 @@ S: Maintained
12880 12881 F: drivers/power/supply/ip5xxx_power.c
12881 12882
12882 12883 INNOSILICON HDMI BRIDGE DRIVER
12883 - M: Andy Yan <andy.yan@rock-chips.com>
12884 + M: Andy Yan <andyshrk@163.com>
12884 12885 L: dri-devel@lists.freedesktop.org
12885 12886 S: Maintained
12886 12887 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -25336,8 +25337,8 @@ F: Documentation/networking/timestamping.rst
25336 25337 F: include/linux/net_tstamp.h
25337 25338 F: include/uapi/linux/net_tstamp.h
25338 25339 F: tools/testing/selftests/bpf/*/net_timestamping*
25340 + F: tools/testing/selftests/drivers/net/so_txtime.*
25339 25341 F: tools/testing/selftests/net/*timestamp*
25340 - F: tools/testing/selftests/net/so_txtime.c
25341 25342
25342 25343 SOEKRIS NET48XX LED SUPPORT
25343 25344 M: Chris Boot <bootc@bootc.net>
@@ -28609,7 +28610,6 @@ L: iommu@lists.linux.dev
28609 28610 S: Maintained
28610 28611 F: Documentation/devicetree/bindings/iommu/verisilicon,iommu.yaml
28611 28612 F: drivers/iommu/vsi-iommu.c
28612 - F: include/linux/vsi-iommu.h
28613 28613
28614 28614 VF610 NAND DRIVER
28615 28615 M: Stefan Agner <stefan@agner.ch>
@@ -28869,8 +28869,8 @@ F: include/uapi/linux/virtio_console.h
28869 28869 VIRTIO CORE
28870 28870 M: "Michael S. Tsirkin" <mst@redhat.com>
28871 28871 M: Jason Wang <jasowangio@gmail.com>
28872 + M: Eugenio Pérez <eperezma@redhat.com>
28872 28873 R: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
28873 - R: Eugenio Pérez <eperezma@redhat.com>
28874 28874 L: virtualization@lists.linux.dev
28875 28875 S: Maintained
28876 28876 F: Documentation/ABI/testing/sysfs-bus-vdpa
@@ -28947,7 +28947,7 @@ F: include/uapi/linux/virtio_gpu.h
28947 28947 VIRTIO HOST (VHOST)
28948 28948 M: "Michael S. Tsirkin" <mst@redhat.com>
28949 28949 M: Jason Wang <jasowangio@gmail.com>
28950 - R: Eugenio Pérez <eperezma@redhat.com>
28950 + M: Eugenio Pérez <eperezma@redhat.com>
28951 28951 L: kvm@vger.kernel.org
28952 28952 L: virtualization@lists.linux.dev
28953 28953 L: netdev@vger.kernel.org
@@ -29002,8 +29002,8 @@ F: include/uapi/linux/virtio_mem.h
29002 29002 VIRTIO NET DRIVER
29003 29003 M: "Michael S. Tsirkin" <mst@redhat.com>
29004 29004 M: Jason Wang <jasowangio@gmail.com>
29005 + M: Eugenio Pérez <eperezma@redhat.com>
29005 29006 R: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
29006 - R: Eugenio Pérez <eperezma@redhat.com>
29007 29007 L: netdev@vger.kernel.org
29008 29008 L: virtualization@lists.linux.dev
29009 29009 S: Maintained
@@ -29019,6 +29019,13 @@ S: Maintained
29019 29019 F: drivers/nvdimm/nd_virtio.c
29020 29020 F: drivers/nvdimm/virtio_pmem.c
29021 29021
29022 + VIRTIO RNG DRIVER
29023 + M: Laurent Vivier <lvivier@redhat.com>
29024 + L: virtualization@lists.linux.dev
29025 + S: Maintained
29026 + F: drivers/char/hw_random/virtio-rng.c
29027 + F: include/uapi/linux/virtio_rng.h
29028 +
29022 29029 VIRTIO RTC DRIVER
29023 29030 M: Peter Hilber <peter.hilber@oss.qualcomm.com>
29024 29031 L: virtualization@lists.linux.dev
@@ -29350,7 +29357,7 @@ M: Guenter Roeck <linux@roeck-us.net>
29350 29357 L: linux-watchdog@vger.kernel.org
29351 29358 S: Maintained
29352 29359 W: http://www.linux-watchdog.org/
29353 - T: git git://www.linux-watchdog.org/linux-watchdog.git
29360 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
29354 29361 F: Documentation/devicetree/bindings/watchdog/
29355 29362 F: Documentation/watchdog/
29356 29363 F: drivers/watchdog/
modified Makefile
@@ -2,7 +2,7 @@
2 2 VERSION = 7
3 3 PATCHLEVEL = 3
4 4 SUBLEVEL = 0
5 - EXTRAVERSION = -rc2
5 + EXTRAVERSION = -rc3
6 6 NAME = Baby Opossum Posse
7 7
8 8 # *DOCUMENTATION*
modified arch/arm64/tools/sysreg
@@ -3761,7 +3761,9 @@ Sysreg ICC_CR0_EL1 3 1 12 0 1
3761 3761 Res0 63:39
3762 3762 Field 38 PID
3763 3763 Field 37:32 IPPT
3764 - Res0 31:1
3764 + Res0 31:3
3765 + Field 2 LINK_IDLE
3766 + Field 1 LINK
3765 3767 Field 0 EN
3766 3768 EndSysreg
3767 3769
modified arch/powerpc/include/asm/entry-common.h
@@ -222,8 +222,6 @@ static inline void arch_interrupt_enter_prepare(struct pt_regs *regs)
222 222
223 223 if (user_mode(regs)) {
224 224 kuap_lock();
225 - account_cpu_user_entry();
226 - account_stolen_time();
227 225 } else {
228 226 kuap_save_and_lock(regs);
229 227 /*
modified arch/powerpc/kernel/prom.c
@@ -824,7 +824,6 @@ void __init early_init_devtree(void *params)
824 824 fadump_append_bootargs();
825 825
826 826 /* Scan memory nodes and rebuild MEMBLOCKs */
827 - early_init_dt_scan_root();
828 827 early_init_dt_scan_memory_ppc();
829 828
830 829 /*
modified arch/powerpc/kexec/elf_64.c
@@ -94,6 +94,8 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
94 94 cmdline = modified_cmdline;
95 95 }
96 96
97 + kexec_dprintk("Command line: %s", cmdline ? cmdline : "");
98 +
97 99 if (initrd != NULL) {
98 100 kbuf.buffer = initrd;
99 101 kbuf.bufsz = kbuf.memsz = initrd_len;
modified arch/powerpc/kvm/book3s_hv.c
@@ -6140,12 +6140,12 @@ static int kvmppc_irq_bypass_add_producer_hv(struct irq_bypass_consumer *cons,
6140 6140 struct kvm_kernel_irqfd *irqfd =
6141 6141 container_of(cons, struct kvm_kernel_irqfd, consumer);
6142 6142
6143 - irqfd->producer = prod;
6144 -
6145 6143 ret = kvmppc_set_passthru_irq(irqfd->kvm, prod->irq, irqfd->gsi);
6146 6144 if (ret)
6147 6145 pr_info("kvmppc_set_passthru_irq (irq %d, gsi %d) fails: %d\n",
6148 6146 prod->irq, irqfd->gsi, ret);
6147 + else
6148 + irqfd->producer = prod;
6149 6149
6150 6150 return ret;
6151 6151 }
modified arch/powerpc/platforms/pasemi/setup.c
@@ -165,6 +165,8 @@ static int __init pas_setup_mce_regs(void)
165 165 while (dev && reg < MAX_MCE_REGS) {
166 166 mce_regs[reg].name = kasprintf(GFP_KERNEL,
167 167 "mc%d_mcdebug_errsta", reg);
168 + if (!mce_regs[reg].name)
169 + return -ENOMEM;
168 170 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
169 171 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
170 172 reg++;
modified arch/powerpc/platforms/pseries/htmdump.c
@@ -527,28 +527,28 @@ static int htmdump_init_debugfs(void)
527 527 htm_status_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
528 528 if (!htm_status_buf) {
529 529 pr_err("Failed to allocate htmstatus buf\n");
530 - return -ENOMEM;
530 + goto htm_status_buf_err;
531 531 }
532 532
533 533 /* Debugfs interface file to present System Processor Configuration */
534 534 htm_info_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
535 535 if (!htm_info_buf) {
536 536 pr_err("Failed to allocate htm info buf\n");
537 - return -ENOMEM;
537 + goto htm_info_buf_err;
538 538 }
539 539
540 540 /* Debugfs interface file to present HTM capabilities */
541 541 htm_caps_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
542 542 if (!htm_caps_buf) {
543 543 pr_err("Failed to allocate htm caps buf\n");
544 - return -ENOMEM;
544 + goto htm_caps_buf_err;
545 545 }
546 546
547 547 /* Memory to present HTM system memory configuration */
548 548 htm_mem_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
549 549 if (!htm_mem_buf) {
550 550 pr_err("Failed to allocate htm mem buf\n");
551 - return -ENOMEM;
551 + goto htm_mem_buf_err;
552 552 }
553 553
554 554 debugfs_create_file("htmstatus", 0400, htmdump_debugfs_dir, htm_status_buf, &htmstatus_fops);
@@ -557,6 +557,17 @@ static int htmdump_init_debugfs(void)
557 557 debugfs_create_file("htmsystem_mem", 0400, htmdump_debugfs_dir, htm_mem_buf, &htmsystem_mem_fops);
558 558
559 559 return 0;
560 +
561 + htm_mem_buf_err:
562 + kfree(htm_caps_buf);
563 + htm_caps_buf_err:
564 + kfree(htm_info_buf);
565 + htm_info_buf_err:
566 + kfree(htm_status_buf);
567 + htm_status_buf_err:
568 + debugfs_remove_recursive(htmdump_debugfs_dir);
569 + kfree(htm_buf);
570 + return -ENOMEM;
560 571 }
561 572
562 573 static int __init htmdump_init(void)
modified arch/riscv/Kconfig
@@ -326,7 +326,7 @@ config STACKTRACE_SUPPORT
326 326 config GENERIC_BUG
327 327 def_bool y
328 328 depends on BUG
329 - select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
329 + select GENERIC_BUG_RELATIVE_POINTERS
330 330
331 331 config GENERIC_BUG_RELATIVE_POINTERS
332 332 bool
modified arch/riscv/include/asm/bug.h
@@ -29,13 +29,8 @@
29 29
30 30 typedef u32 bug_insn_t;
31 31
32 - #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
33 32 #define __BUG_ENTRY_ADDR RISCV_INT " 1b - ."
34 33 #define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ."
35 - #else
36 - #define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
37 - #define __BUG_ENTRY_FILE(file) RISCV_PTR " " file
38 - #endif
39 34
40 35 #ifdef CONFIG_DEBUG_BUGVERBOSE
41 36 #define __BUG_ENTRY(file, line, flags) \
modified arch/riscv/include/asm/switch_to.h
@@ -61,8 +61,8 @@ static inline void __switch_to_fpu(struct task_struct *prev,
61 61
62 62 static __always_inline bool has_fpu(void)
63 63 {
64 - return riscv_has_extension_likely(RISCV_ISA_EXT_F) ||
65 - riscv_has_extension_likely(RISCV_ISA_EXT_D);
64 + /* D extension depends on F, so checking D alone is sufficient. */
65 + return riscv_has_extension_likely(RISCV_ISA_EXT_D);
66 66 }
67 67 #else
68 68 static __always_inline bool has_fpu(void) { return false; }
modified arch/riscv/kernel/cpufeature.c
@@ -412,6 +412,19 @@ static const unsigned int riscv_zvbb_exts[] = {
412 412 RISCV_ISA_EXT_ZVKB
413 413 };
414 414
415 + /*
416 + * The RISC-V ISA manual specifies that Zfh implies Zfhmin and Zvfh implies
417 + * Zvfhmin. Report the implied subset extensions whenever the supersets are
418 + * detected (see https://github.com/riscv/riscv-isa-manual/pull/3070).
419 + */
420 + static const unsigned int riscv_zfh_exts[] = {
421 + RISCV_ISA_EXT_ZFHMIN
422 + };
423 +
424 + static const unsigned int riscv_zvfh_exts[] = {
425 + RISCV_ISA_EXT_ZVFHMIN
426 + };
427 +
415 428 #define RISCV_ISA_EXT_ZVE64F_IMPLY_LIST \
416 429 RISCV_ISA_EXT_ZVE64X, \
417 430 RISCV_ISA_EXT_ZVE32F, \
@@ -550,7 +563,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
550 563 __RISCV_ISA_EXT_DATA(zawrs, RISCV_ISA_EXT_ZAWRS),
551 564 __RISCV_ISA_EXT_DATA_VALIDATE(zfa, RISCV_ISA_EXT_ZFA, riscv_ext_f_depends),
552 565 __RISCV_ISA_EXT_DATA_VALIDATE(zfbfmin, RISCV_ISA_EXT_ZFBFMIN, riscv_ext_f_depends),
553 - __RISCV_ISA_EXT_DATA_VALIDATE(zfh, RISCV_ISA_EXT_ZFH, riscv_ext_f_depends),
566 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zfh, RISCV_ISA_EXT_ZFH,
567 + riscv_zfh_exts, riscv_ext_f_depends),
554 568 __RISCV_ISA_EXT_DATA_VALIDATE(zfhmin, RISCV_ISA_EXT_ZFHMIN, riscv_ext_f_depends),
555 569 __RISCV_ISA_EXT_DATA(zca, RISCV_ISA_EXT_ZCA),
556 570 __RISCV_ISA_EXT_DATA_VALIDATE(zcb, RISCV_ISA_EXT_ZCB, riscv_ext_zca_depends),
@@ -586,7 +600,9 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
586 600 __RISCV_ISA_EXT_SUPERSET_VALIDATE(zve64x, RISCV_ISA_EXT_ZVE64X, riscv_zve64x_exts, riscv_ext_vector_x_validate),
587 601 __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfmin, RISCV_ISA_EXT_ZVFBFMIN, riscv_vector_f_validate),
588 602 __RISCV_ISA_EXT_DATA_VALIDATE(zvfbfwma, RISCV_ISA_EXT_ZVFBFWMA, riscv_ext_zvfbfwma_validate),
589 - __RISCV_ISA_EXT_DATA(zvfh, RISCV_ISA_EXT_ZVFH),
603 + __RISCV_ISA_EXT_SUPERSET_VALIDATE(zvfh, RISCV_ISA_EXT_ZVFH,
604 + riscv_zvfh_exts,
605 + riscv_ext_vector_float_validate),
590 606 __RISCV_ISA_EXT_DATA(zvfhmin, RISCV_ISA_EXT_ZVFHMIN),
591 607 __RISCV_ISA_EXT_DATA_VALIDATE(zvkb, RISCV_ISA_EXT_ZVKB, riscv_ext_vector_crypto_validate),
592 608 __RISCV_ISA_EXT_DATA_VALIDATE(zvkg, RISCV_ISA_EXT_ZVKG, riscv_ext_vector_crypto_validate),
modified arch/riscv/kernel/patch.c
@@ -45,6 +45,8 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
45 45 phys_addr_t phys;
46 46
47 47 if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) {
48 + if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
49 + return addr;
48 50 phys = __pa_symbol(addr);
49 51 } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) {
50 52 struct page *page = vmalloc_to_page(addr);
modified arch/riscv/kernel/process.c
@@ -349,10 +349,8 @@ long set_tagged_addr_ctrl(struct task_struct *task, unsigned long arg)
349 349 if (arg & PR_TAGGED_ADDR_ENABLE && (tagged_addr_disabled || !pmlen))
350 350 return -EINVAL;
351 351
352 - if (!(arg & PR_TAGGED_ADDR_ENABLE)) {
352 + if (!(arg & PR_TAGGED_ADDR_ENABLE))
353 353 pmlen = PMLEN_0;
354 - pmm = ENVCFG_PMM_PMLEN_0;
355 - }
356 354
357 355 if (mmap_write_lock_killable(mm))
358 356 return -EINTR;
modified arch/riscv/kernel/sys_hwprobe.c
@@ -297,6 +297,8 @@ static u64 hwprobe_vec_misaligned(const struct cpumask *cpus)
297 297 static void hwprobe_one_pair(struct riscv_hwprobe *pair,
298 298 const struct cpumask *cpus)
299 299 {
300 + pair->value = 0;
301 +
300 302 switch (pair->key) {
301 303 case RISCV_HWPROBE_KEY_MVENDORID:
302 304 case RISCV_HWPROBE_KEY_MARCHID:
@@ -331,17 +333,14 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
331 333 break;
332 334
333 335 case RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE:
334 - pair->value = 0;
335 336 if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ))
336 337 pair->value = riscv_cboz_block_size;
337 338 break;
338 339 case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE:
339 - pair->value = 0;
340 340 if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM))
341 341 pair->value = riscv_cbom_block_size;
342 342 break;
343 343 case RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE:
344 - pair->value = 0;
345 344 if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOP))
346 345 pair->value = riscv_cbop_block_size;
347 346 break;
modified arch/riscv/kernel/usercfi.c
@@ -525,9 +525,8 @@ static int __init setup_global_riscv_enable(char *str)
525 525
526 526 if (riscv_nousercfi)
527 527 pr_info("RISC-V user CFI disabled via cmdline - shadow stack status : %s, landing pad status : %s\n",
528 - (riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_BCFI) ? "disabled" :
529 - "enabled", (riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_FCFI) ?
530 - "disabled" : "enabled");
528 + str_disabled_enabled(riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_BCFI),
529 + str_disabled_enabled(riscv_nousercfi & CMDLINE_DISABLE_RISCV_USERCFI_FCFI));
531 530
532 531 return 1;
533 532 }
modified arch/riscv/lib/uaccess.S
@@ -76,6 +76,7 @@ SYM_FUNC_START(fallback_scalar_usercopy_sum_enabled)
76 76 li a3, 9*SZREG-1 /* size must >= (word_copy stride + SZREG-1) */
77 77 bltu a2, a3, .Lbyte_copy_tail
78 78
79 + #if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
79 80 /*
80 81 * Copy first bytes until dst is aligned to word boundary.
81 82 * a0 - start of dst
@@ -103,7 +104,7 @@ SYM_FUNC_START(fallback_scalar_usercopy_sum_enabled)
103 104 /* a1 - start of src */
104 105 andi a3, a1, SZREG-1
105 106 bnez a3, .Lshift_copy
106 -
107 + #endif
107 108 .Lword_copy:
108 109 /*
109 110 * Both src and dst are aligned, unrolled word copy
@@ -137,6 +138,7 @@ SYM_FUNC_START(fallback_scalar_usercopy_sum_enabled)
137 138 addi t0, t0, 8*SZREG /* revert to original value */
138 139 j .Lbyte_copy_tail
139 140
141 + #if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
140 142 .Lshift_copy:
141 143
142 144 /*
@@ -189,6 +191,7 @@ SYM_FUNC_START(fallback_scalar_usercopy_sum_enabled)
189 191
190 192 /* Revert src to original unaligned value */
191 193 add a1, a1, a3
194 + #endif
192 195
193 196 .Lbyte_copy_tail:
194 197 /*
modified arch/riscv/mm/init.c
@@ -1465,7 +1465,9 @@ struct execmem_info __init *execmem_arch_setup(void)
1465 1465 [EXECMEM_KPROBES] = {
1466 1466 .start = VMALLOC_START,
1467 1467 .end = VMALLOC_END,
1468 - .pgprot = PAGE_KERNEL_READ_EXEC,
1468 + .pgprot = IS_ENABLED(CONFIG_STRICT_MODULE_RWX) ?
1469 + PAGE_KERNEL_READ_EXEC :
1470 + PAGE_KERNEL_EXEC,
1469 1471 .alignment = 1,
1470 1472 },
1471 1473 [EXECMEM_BPF] = {
modified arch/s390/crypto/Makefile
@@ -3,6 +3,8 @@
3 3 # Cryptographic API
4 4 #
5 5
6 + CONTEXT_ANALYSIS := y
7 +
6 8 obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o
7 9 obj-$(CONFIG_CRYPTO_PAES_S390) += paes_s390.o
8 10 obj-$(CONFIG_S390_PRNG) += prng.o
modified arch/s390/crypto/aes_s390.c
@@ -26,14 +26,14 @@
26 26 #include <linux/module.h>
27 27 #include <linux/cpufeature.h>
28 28 #include <linux/init.h>
29 - #include <linux/mutex.h>
30 29 #include <linux/fips.h>
30 + #include <linux/semaphore.h>
31 31 #include <linux/string.h>
32 32 #include <crypto/xts.h>
33 33 #include <asm/cpacf.h>
34 34
35 35 static u8 *ctrblk;
36 - static DEFINE_MUTEX(ctrblk_lock);
36 + static DEFINE_SEMAPHORE(ctrblk_sem, 1);
37 37
38 38 static cpacf_mask_t km_functions, kmc_functions, kmctr_functions,
39 39 kma_functions;
@@ -129,7 +129,7 @@ static int ecb_aes_crypt(struct skcipher_request *req, unsigned long modifier)
129 129 return fallback_skcipher_crypt(sctx, req, modifier);
130 130
131 131 ret = skcipher_walk_virt(&walk, req, false);
132 - while ((nbytes = walk.nbytes) != 0) {
132 + while (!ret && ((nbytes = walk.nbytes) != 0)) {
133 133 /* only use complete blocks */
134 134 n = nbytes & ~(AES_BLOCK_SIZE - 1);
135 135 cpacf_km(sctx->fc | modifier, sctx->key,
@@ -233,7 +233,7 @@ static int cbc_aes_crypt(struct skcipher_request *req, unsigned long modifier)
233 233 return ret;
234 234 memcpy(param.iv, walk.iv, AES_BLOCK_SIZE);
235 235 memcpy(param.key, sctx->key, sctx->key_len);
236 - while ((nbytes = walk.nbytes) != 0) {
236 + while (!ret && ((nbytes = walk.nbytes) != 0)) {
237 237 /* only use complete blocks */
238 238 n = nbytes & ~(AES_BLOCK_SIZE - 1);
239 239 cpacf_kmc(sctx->fc | modifier, &param,
@@ -359,7 +359,7 @@ static int xts_aes_crypt(struct skcipher_request *req, unsigned long modifier)
359 359 memcpy(xts_param.key + offset, xts_ctx->key, xts_ctx->key_len);
360 360 memcpy(xts_param.init, pcc_param.xts, 16);
361 361
362 - while ((nbytes = walk.nbytes) != 0) {
362 + while (!ret && ((nbytes = walk.nbytes) != 0)) {
363 363 /* only use complete blocks */
364 364 n = nbytes & ~(AES_BLOCK_SIZE - 1);
365 365 cpacf_km(xts_ctx->fc | modifier, xts_param.key + offset,
@@ -487,7 +487,7 @@ static int fullxts_aes_crypt(struct skcipher_request *req, unsigned long modifi
487 487 memcpy(fxts_param.tweak, req->iv, AES_BLOCK_SIZE);
488 488 fxts_param.nap[0] = 0x01; /* initial alpha power (1, little-endian) */
489 489
490 - while ((nbytes = walk.nbytes) != 0) {
490 + while (!ret && ((nbytes = walk.nbytes) != 0)) {
491 491 /* only use complete blocks */
492 492 n = nbytes & ~(AES_BLOCK_SIZE - 1);
493 493 cpacf_km(xts_ctx->fc | modifier, fxts_param.key + offset,
@@ -562,48 +562,64 @@ static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)
562 562 return n;
563 563 }
564 564
565 + static int __ctr_aes_crypt(struct s390_aes_ctx *sctx,
566 + struct skcipher_walk *walk, bool locked)
567 + {
568 + unsigned int n, nbytes;
569 + int ret = 0;
570 + u8 *ctrptr;
571 +
572 + while (!ret && ((nbytes = walk->nbytes) >= AES_BLOCK_SIZE)) {
573 + n = AES_BLOCK_SIZE;
574 + if (nbytes >= 2 * AES_BLOCK_SIZE && locked)
575 + n = __ctrblk_init(ctrblk, walk->iv, nbytes);
576 + ctrptr = (n > AES_BLOCK_SIZE) ? ctrblk : walk->iv;
577 + cpacf_kmctr(sctx->fc, sctx->key, walk->dst.virt.addr,
578 + walk->src.virt.addr, n, ctrptr);
579 + if (ctrptr == ctrblk)
580 + memcpy(walk->iv, ctrptr + n - AES_BLOCK_SIZE,
581 + AES_BLOCK_SIZE);
582 + crypto_inc(walk->iv, AES_BLOCK_SIZE);
583 + ret = skcipher_walk_done(walk, nbytes - n);
584 + }
585 +
586 + return ret;
587 + }
588 +
565 589 static int ctr_aes_crypt(struct skcipher_request *req)
566 590 {
567 591 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
568 592 struct s390_aes_ctx *sctx = crypto_skcipher_ctx(tfm);
569 - u8 buf[AES_BLOCK_SIZE], *ctrptr;
570 593 struct skcipher_walk walk;
571 - unsigned int n, nbytes;
572 - int ret, locked;
594 + u8 buf[AES_BLOCK_SIZE];
595 + int ret;
573 596
574 597 if (unlikely(!sctx->fc))
575 598 return fallback_skcipher_crypt(sctx, req, 0);
576 599
577 - locked = mutex_trylock(&ctrblk_lock);
578 -
579 600 ret = skcipher_walk_virt(&walk, req, false);
580 - while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
581 - n = AES_BLOCK_SIZE;
601 + if (ret)
602 + return ret;
582 603
583 - if (nbytes >= 2*AES_BLOCK_SIZE && locked)
584 - n = __ctrblk_init(ctrblk, walk.iv, nbytes);
585 - ctrptr = (n > AES_BLOCK_SIZE) ? ctrblk : walk.iv;
586 - cpacf_kmctr(sctx->fc, sctx->key, walk.dst.virt.addr,
587 - walk.src.virt.addr, n, ctrptr);
588 - if (ctrptr == ctrblk)
589 - memcpy(walk.iv, ctrptr + n - AES_BLOCK_SIZE,
590 - AES_BLOCK_SIZE);
591 - crypto_inc(walk.iv, AES_BLOCK_SIZE);
592 - ret = skcipher_walk_done(&walk, nbytes - n);
604 + if (down_trylock(&ctrblk_sem) == 0) {
605 + ret = __ctr_aes_crypt(sctx, &walk, true);
606 + up(&ctrblk_sem);
607 + } else {
608 + ret = __ctr_aes_crypt(sctx, &walk, false);
593 609 }
594 - if (locked)
595 - mutex_unlock(&ctrblk_lock);
610 +
596 611 /*
597 612 * final block may be < AES_BLOCK_SIZE, copy only nbytes
598 613 */
599 - if (nbytes) {
614 + if (!ret && walk.nbytes > 0) {
600 615 memset(buf, 0, AES_BLOCK_SIZE);
601 - memcpy(buf, walk.src.virt.addr, nbytes);
616 + memcpy(buf, walk.src.virt.addr, walk.nbytes);
602 617 cpacf_kmctr(sctx->fc, sctx->key, buf, buf,
603 618 AES_BLOCK_SIZE, walk.iv);
604 - memcpy(walk.dst.virt.addr, buf, nbytes);
619 + memcpy(walk.dst.virt.addr, buf, walk.nbytes);
605 620 crypto_inc(walk.iv, AES_BLOCK_SIZE);
606 621 ret = skcipher_walk_done(&walk, 0);
622 + memzero_explicit(buf, sizeof(buf));
607 623 }
608 624
609 625 return ret;
@@ -895,10 +911,14 @@ static int gcm_aes_crypt(struct aead_request *req, unsigned int flags)
895 911 gw_in.ptr, aad_bytes);
896 912
897 913 n = aad_bytes + pc_bytes;
898 - if (gcm_in_walk_done(&gw_in, n) != n)
899 - return -ENOMEM;
900 - if (gcm_out_walk_done(&gw_out, n) != n)
901 - return -ENOMEM;
914 + if (gcm_in_walk_done(&gw_in, n) != n) {
915 + ret = -ENOMEM;
916 + goto out;
917 + }
918 + if (gcm_out_walk_done(&gw_out, n) != n) {
919 + ret = -ENOMEM;
920 + goto out;
921 + }
902 922 aadlen -= aad_bytes;
903 923 pclen -= pc_bytes;
904 924 } while (aadlen + pclen > 0);
@@ -910,7 +930,10 @@ static int gcm_aes_crypt(struct aead_request *req, unsigned int flags)
910 930 } else
911 931 scatterwalk_map_and_copy(param.t, req->dst, len, taglen, 1);
912 932
933 + out:
913 934 memzero_explicit(&param, sizeof(param));
935 + memzero_explicit(gw_in.buf, sizeof(gw_in.buf));
936 + memzero_explicit(gw_out.buf, sizeof(gw_out.buf));
914 937 return ret;
915 938 }
916 939
modified arch/s390/crypto/paes_s390.c
@@ -19,7 +19,7 @@
19 19 #include <linux/init.h>
20 20 #include <linux/miscdevice.h>
21 21 #include <linux/module.h>
22 - #include <linux/mutex.h>
22 + #include <linux/semaphore.h>
23 23 #include <linux/spinlock.h>
24 24 #include <crypto/aes.h>
25 25 #include <crypto/algapi.h>
@@ -45,7 +45,7 @@ module_param_named(clrkey, pkey_clrkey_allowed, bool, 0444);
45 45 MODULE_PARM_DESC(clrkey, "Allow clear key material (default N)");
46 46
47 47 static u8 *ctrblk;
48 - static DEFINE_MUTEX(ctrblk_lock);
48 + static DEFINE_SEMAPHORE(ctrblk_sem, 1);
49 49
50 50 static cpacf_mask_t km_functions, kmc_functions, kmctr_functions;
51 51
@@ -220,6 +220,10 @@ static inline int convert_key(const u8 *key, unsigned int keylen,
220 220 xflags);
221 221 }
222 222
223 + /* But finally map -EBUSY to -EIO to indicate an IO failure */
224 + if (rc == -EBUSY)
225 + rc = -EIO;
226 +
223 227 out:
224 228 pr_debug("rc=%d\n", rc);
225 229 return rc;
@@ -432,8 +436,11 @@ static int ecb_paes_do_crypt(struct s390_paes_ctx *ctx,
432 436 n = nbytes & ~(AES_BLOCK_SIZE - 1);
433 437 k = cpacf_km(ctx->fc | req_ctx->modifier, param,
434 438 walk->dst.virt.addr, walk->src.virt.addr, n);
435 - if (k)
439 + if (k) {
436 440 rc = skcipher_walk_done(walk, nbytes - k);
441 + if (rc)
442 + goto out;
443 + }
437 444 if (k < n) {
438 445 if (!maysleep) {
439 446 rc = -EKEYEXPIRED;
@@ -460,6 +467,7 @@ static int ecb_paes_crypt(struct skcipher_request *req, unsigned long modifier)
460 467 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
461 468 struct skcipher_walk *walk = &req_ctx->walk;
462 469 bool tested = crypto_skcipher_tested(tfm);
470 + bool cleanup = true;
463 471 int rc;
464 472
465 473 /*
@@ -491,15 +499,17 @@ static int ecb_paes_crypt(struct skcipher_request *req, unsigned long modifier)
491 499 if (rc == 0 || rc == -EKEYEXPIRED) {
492 500 atomic_inc(&ctx->via_engine_ctr);
493 501 rc = crypto_transfer_skcipher_request_to_engine(paes_crypto_engine, req);
494 - if (rc != -EINPROGRESS)
502 + if (rc == -EINPROGRESS || rc == -EBUSY)
503 + cleanup = false;
504 + else
495 505 atomic_dec(&ctx->via_engine_ctr);
496 506 }
497 507
498 - if (rc != -EINPROGRESS)
508 + if (cleanup && walk->nbytes)
499 509 skcipher_walk_done(walk, rc);
500 510
501 511 out:
502 - if (rc != -EINPROGRESS)
512 + if (cleanup)
503 513 memzero_explicit(&req_ctx->param, sizeof(req_ctx->param));
504 514 pr_debug("rc=%d\n", rc);
505 515 return rc;
@@ -549,7 +559,7 @@ static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq)
549 559 rc = ecb_paes_do_crypt(ctx, req_ctx, tested, true);
550 560 if (rc == -EKEYEXPIRED) {
551 561 return pkey_handle_expired();
552 - } else if (rc) {
562 + } else if (rc && walk->nbytes) {
553 563 skcipher_walk_done(walk, rc);
554 564 }
555 565
@@ -559,7 +569,7 @@ static int ecb_paes_do_one_request(struct crypto_engine *engine, void *areq)
559 569 atomic_dec(&ctx->via_engine_ctr);
560 570 crypto_finalize_skcipher_request(engine, req, rc);
561 571 local_bh_enable();
562 - return rc;
572 + return 0;
563 573 }
564 574
565 575 static struct skcipher_engine_alg ecb_paes_alg = {
@@ -567,6 +577,7 @@ static struct skcipher_engine_alg ecb_paes_alg = {
567 577 .base.cra_name = "ecb(paes)",
568 578 .base.cra_driver_name = "ecb-paes-s390",
569 579 .base.cra_priority = 401, /* combo: aes + ecb + 1 */
580 + .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NO_FALLBACK,
570 581 .base.cra_blocksize = AES_BLOCK_SIZE,
571 582 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
572 583 .base.cra_module = THIS_MODULE,
@@ -690,6 +701,8 @@ static int cbc_paes_do_crypt(struct s390_paes_ctx *ctx,
690 701 if (k) {
691 702 memcpy(walk->iv, param->iv, AES_BLOCK_SIZE);
692 703 rc = skcipher_walk_done(walk, nbytes - k);
704 + if (rc)
705 + goto out;
693 706 }
694 707 if (k < n) {
695 708 if (!maysleep) {
@@ -717,6 +730,7 @@ static int cbc_paes_crypt(struct skcipher_request *req, unsigned long modifier)
717 730 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
718 731 struct skcipher_walk *walk = &req_ctx->walk;
719 732 bool tested = crypto_skcipher_tested(tfm);
733 + bool cleanup = true;
720 734 int rc;
721 735
722 736 /*
@@ -748,15 +762,17 @@ static int cbc_paes_crypt(struct skcipher_request *req, unsigned long modifier)
748 762 if (rc == 0 || rc == -EKEYEXPIRED) {
749 763 atomic_inc(&ctx->via_engine_ctr);
750 764 rc = crypto_transfer_skcipher_request_to_engine(paes_crypto_engine, req);
751 - if (rc != -EINPROGRESS)
765 + if (rc == -EINPROGRESS || rc == -EBUSY)
766 + cleanup = false;
767 + else
752 768 atomic_dec(&ctx->via_engine_ctr);
753 769 }
754 770
755 - if (rc != -EINPROGRESS)
771 + if (cleanup && walk->nbytes)
756 772 skcipher_walk_done(walk, rc);
757 773
758 774 out:
759 - if (rc != -EINPROGRESS)
775 + if (cleanup)
760 776 memzero_explicit(&req_ctx->param, sizeof(req_ctx->param));
761 777 pr_debug("rc=%d\n", rc);
762 778 return rc;
@@ -806,7 +822,7 @@ static int cbc_paes_do_one_request(struct crypto_engine *engine, void *areq)
806 822 rc = cbc_paes_do_crypt(ctx, req_ctx, tested, true);
807 823 if (rc == -EKEYEXPIRED) {
808 824 return pkey_handle_expired();
809 - } else if (rc) {
825 + } else if (rc && walk->nbytes) {
810 826 skcipher_walk_done(walk, rc);
811 827 }
812 828
@@ -816,7 +832,7 @@ static int cbc_paes_do_one_request(struct crypto_engine *engine, void *areq)
816 832 atomic_dec(&ctx->via_engine_ctr);
817 833 crypto_finalize_skcipher_request(engine, req, rc);
818 834 local_bh_enable();
819 - return rc;
835 + return 0;
820 836 }
821 837
822 838 static struct skcipher_engine_alg cbc_paes_alg = {
@@ -824,6 +840,7 @@ static struct skcipher_engine_alg cbc_paes_alg = {
824 840 .base.cra_name = "cbc(paes)",
825 841 .base.cra_driver_name = "cbc-paes-s390",
826 842 .base.cra_priority = 402, /* cbc-paes-s390 + 1 */
843 + .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NO_FALLBACK,
827 844 .base.cra_blocksize = AES_BLOCK_SIZE,
828 845 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
829 846 .base.cra_module = THIS_MODULE,
@@ -914,41 +931,14 @@ static inline unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes
914 931 return n;
915 932 }
916 933
917 - static int ctr_paes_do_crypt(struct s390_paes_ctx *ctx,
918 - struct s390_pctr_req_ctx *req_ctx,
919 - bool tested, bool maysleep)
934 + static int __ctr_paes_do_crypt(struct s390_paes_ctx *ctx,
935 + struct ctr_param *param,
936 + struct skcipher_walk *walk,
937 + bool tested, bool maysleep, bool locked)
920 938 {
921 - struct ctr_param *param = &req_ctx->param;
922 - struct skcipher_walk *walk = &req_ctx->walk;
923 - u8 buf[AES_BLOCK_SIZE], *ctrptr;
924 939 unsigned int nbytes, n, k;
925 - int pk_state, locked, rc = 0;
926 -
927 - if (!req_ctx->param_init_done) {
928 - /* fetch and check protected key state */
929 - spin_lock_bh(&ctx->pk_lock);
930 - pk_state = ctx->pk_state;
931 - switch (pk_state) {
932 - case PK_STATE_NO_KEY:
933 - rc = -ENOKEY;
934 - break;
935 - case PK_STATE_CONVERT_IN_PROGRESS:
936 - rc = -EKEYEXPIRED;
937 - break;
938 - case PK_STATE_VALID:
939 - memcpy(param->key, ctx->pk.protkey, sizeof(param->key));
940 - req_ctx->param_init_done = true;
941 - break;
942 - default:
943 - rc = pk_state < 0 ? pk_state : -EIO;
944 - break;
945 - }
946 - spin_unlock_bh(&ctx->pk_lock);
947 - }
948 - if (rc)
949 - goto out;
950 -
951 - locked = mutex_trylock(&ctrblk_lock);
940 + u8 *ctrptr;
941 + int rc = 0;
952 942
953 943 /*
954 944 * Note that in case of partial processing or failure the walk
@@ -968,32 +958,71 @@ static int ctr_paes_do_crypt(struct s390_paes_ctx *ctx,
968 958 AES_BLOCK_SIZE);
969 959 crypto_inc(walk->iv, AES_BLOCK_SIZE);
970 960 rc = skcipher_walk_done(walk, nbytes - k);
961 + if (rc)
962 + goto out;
971 963 }
972 964 if (k < n) {
973 965 if (!maysleep) {
974 - if (locked)
975 - mutex_unlock(&ctrblk_lock);
976 966 rc = -EKEYEXPIRED;
977 967 goto out;
978 968 }
979 969 rc = paes_convert_key(ctx, tested);
980 - if (rc) {
981 - if (locked)
982 - mutex_unlock(&ctrblk_lock);
970 + if (rc)
983 971 goto out;
984 - }
985 972 spin_lock_bh(&ctx->pk_lock);
986 973 memcpy(param->key, ctx->pk.protkey, sizeof(param->key));
987 974 spin_unlock_bh(&ctx->pk_lock);
988 975 }
989 976 }
990 - if (locked)
991 - mutex_unlock(&ctrblk_lock);
977 +
978 + out:
979 + return rc;
980 + }
981 +
982 + static int ctr_paes_do_crypt(struct s390_paes_ctx *ctx,
983 + struct s390_pctr_req_ctx *req_ctx,
984 + bool tested, bool maysleep)
985 + {
986 + struct ctr_param *param = &req_ctx->param;
987 + struct skcipher_walk *walk = &req_ctx->walk;
988 + u8 buf[AES_BLOCK_SIZE];
989 + int pk_state, rc = 0;
990 +
991 + if (!req_ctx->param_init_done) {
992 + /* fetch and check protected key state */
993 + spin_lock_bh(&ctx->pk_lock);
994 + pk_state = ctx->pk_state;
995 + switch (pk_state) {
996 + case PK_STATE_NO_KEY:
997 + rc = -ENOKEY;
998 + break;
999 + case PK_STATE_CONVERT_IN_PROGRESS:
1000 + rc = -EKEYEXPIRED;
1001 + break;
1002 + case PK_STATE_VALID:
1003 + memcpy(param->key, ctx->pk.protkey, sizeof(param->key));
1004 + req_ctx->param_init_done = true;
1005 + break;
1006 + default:
1007 + rc = pk_state < 0 ? pk_state : -EIO;
1008 + break;
1009 + }
1010 + spin_unlock_bh(&ctx->pk_lock);
1011 + }
1012 + if (rc)
1013 + goto out;
1014 +
1015 + if (down_trylock(&ctrblk_sem) == 0) {
1016 + rc = __ctr_paes_do_crypt(ctx, param, walk, tested, maysleep, true);
1017 + up(&ctrblk_sem);
1018 + } else {
1019 + rc = __ctr_paes_do_crypt(ctx, param, walk, tested, maysleep, false);
1020 + }
992 1021
993 1022 /* final block may be < AES_BLOCK_SIZE, copy only nbytes */
994 - if (nbytes) {
1023 + if (!rc && walk->nbytes > 0) {
995 1024 memset(buf, 0, AES_BLOCK_SIZE);
996 - memcpy(buf, walk->src.virt.addr, nbytes);
1025 + memcpy(buf, walk->src.virt.addr, walk->nbytes);
997 1026 while (1) {
998 1027 if (cpacf_kmctr(ctx->fc, param, buf,
999 1028 buf, AES_BLOCK_SIZE,
@@ -1010,12 +1039,13 @@ static int ctr_paes_do_crypt(struct s390_paes_ctx *ctx,
1010 1039 memcpy(param->key, ctx->pk.protkey, sizeof(param->key));
1011 1040 spin_unlock_bh(&ctx->pk_lock);
1012 1041 }
1013 - memcpy(walk->dst.virt.addr, buf, nbytes);
1042 + memcpy(walk->dst.virt.addr, buf, walk->nbytes);
1014 1043 crypto_inc(walk->iv, AES_BLOCK_SIZE);
1015 1044 rc = skcipher_walk_done(walk, 0);
1016 1045 }
1017 1046
1018 1047 out:
1048 + memzero_explicit(buf, sizeof(buf));
1019 1049 pr_debug("rc=%d\n", rc);
1020 1050 return rc;
1021 1051 }
@@ -1027,6 +1057,7 @@ static int ctr_paes_crypt(struct skcipher_request *req)
1027 1057 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
1028 1058 struct skcipher_walk *walk = &req_ctx->walk;
1029 1059 bool tested = crypto_skcipher_tested(tfm);
1060 + bool cleanup = true;
1030 1061 int rc;
1031 1062
1032 1063 /*
@@ -1057,15 +1088,17 @@ static int ctr_paes_crypt(struct skcipher_request *req)
1057 1088 if (rc == 0 || rc == -EKEYEXPIRED) {
1058 1089 atomic_inc(&ctx->via_engine_ctr);
1059 1090 rc = crypto_transfer_skcipher_request_to_engine(paes_crypto_engine, req);
1060 - if (rc != -EINPROGRESS)
1091 + if (rc == -EINPROGRESS || rc == -EBUSY)
1092 + cleanup = false;
1093 + else
1061 1094 atomic_dec(&ctx->via_engine_ctr);
1062 1095 }
1063 1096
1064 - if (rc != -EINPROGRESS)
1097 + if (cleanup && walk->nbytes)
1065 1098 skcipher_walk_done(walk, rc);
1066 1099
1067 1100 out:
1068 - if (rc != -EINPROGRESS)
1101 + if (cleanup)
1069 1102 memzero_explicit(&req_ctx->param, sizeof(req_ctx->param));
1070 1103 pr_debug("rc=%d\n", rc);
1071 1104 return rc;
@@ -1105,7 +1138,7 @@ static int ctr_paes_do_one_request(struct crypto_engine *engine, void *areq)
1105 1138 rc = ctr_paes_do_crypt(ctx, req_ctx, tested, true);
1106 1139 if (rc == -EKEYEXPIRED) {
1107 1140 return pkey_handle_expired();
1108 - } else if (rc) {
1141 + } else if (rc && walk->nbytes) {
1109 1142 skcipher_walk_done(walk, rc);
1110 1143 }
1111 1144
@@ -1115,7 +1148,7 @@ static int ctr_paes_do_one_request(struct crypto_engine *engine, void *areq)
1115 1148 atomic_dec(&ctx->via_engine_ctr);
1116 1149 crypto_finalize_skcipher_request(engine, req, rc);
1117 1150 local_bh_enable();
1118 - return rc;
1151 + return 0;
1119 1152 }
1120 1153
1121 1154 static struct skcipher_engine_alg ctr_paes_alg = {
@@ -1123,6 +1156,7 @@ static struct skcipher_engine_alg ctr_paes_alg = {
1123 1156 .base.cra_name = "ctr(paes)",
1124 1157 .base.cra_driver_name = "ctr-paes-s390",
1125 1158 .base.cra_priority = 402, /* ecb-paes-s390 + 1 */
1159 + .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NO_FALLBACK,
1126 1160 .base.cra_blocksize = 1,
1127 1161 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
1128 1162 .base.cra_module = THIS_MODULE,
@@ -1283,8 +1317,11 @@ static int xts_paes_do_crypt_fullkey(struct s390_pxts_ctx *ctx,
1283 1317 n = nbytes & ~(AES_BLOCK_SIZE - 1);
1284 1318 k = cpacf_km(ctx->fc | req_ctx->modifier, param->key + offset,
1285 1319 walk->dst.virt.addr, walk->src.virt.addr, n);
1286 - if (k)
1320 + if (k) {
1287 1321 rc = skcipher_walk_done(walk, nbytes - k);
1322 + if (rc)
1323 + goto out;
1324 + }
1288 1325 if (k < n) {
1289 1326 if (!maysleep) {
1290 1327 rc = -EKEYEXPIRED;
@@ -1337,7 +1374,7 @@ static inline int __xts_2keys_prep_param(struct s390_pxts_ctx *ctx,
1337 1374 memcpy(param->init, pcc_param.xts, 16);
1338 1375 }
1339 1376
1340 - memzero_explicit(pcc_param.key, sizeof(pcc_param.key));
1377 + memzero_explicit(&pcc_param, sizeof(pcc_param));
1341 1378 return rc;
1342 1379 }
1343 1380
@@ -1377,8 +1414,11 @@ static int xts_paes_do_crypt_2keys(struct s390_pxts_ctx *ctx,
1377 1414 n = nbytes & ~(AES_BLOCK_SIZE - 1);
1378 1415 k = cpacf_km(ctx->fc | req_ctx->modifier, param->key + offset,
1379 1416 walk->dst.virt.addr, walk->src.virt.addr, n);
1380 - if (k)
1417 + if (k) {
1381 1418 rc = skcipher_walk_done(walk, nbytes - k);
1419 + if (rc)
1420 + goto out;
1421 + }
1382 1422 if (k < n) {
1383 1423 if (!maysleep) {
1384 1424 rc = -EKEYEXPIRED;
@@ -1450,6 +1490,7 @@ static inline int xts_paes_crypt(struct skcipher_request *req, unsigned long mod
1450 1490 struct s390_pxts_ctx *ctx = crypto_skcipher_ctx(tfm);
1451 1491 struct skcipher_walk *walk = &req_ctx->walk;
1452 1492 bool tested = crypto_skcipher_tested(tfm);
1493 + bool cleanup = true;
1453 1494 int rc;
1454 1495
1455 1496 /*
@@ -1481,15 +1522,17 @@ static inline int xts_paes_crypt(struct skcipher_request *req, unsigned long mod
1481 1522 if (rc == 0 || rc == -EKEYEXPIRED) {
1482 1523 atomic_inc(&ctx->via_engine_ctr);
1483 1524 rc = crypto_transfer_skcipher_request_to_engine(paes_crypto_engine, req);
1484 - if (rc != -EINPROGRESS)
1525 + if (rc == -EINPROGRESS || rc == -EBUSY)
1526 + cleanup = false;
1527 + else
1485 1528 atomic_dec(&ctx->via_engine_ctr);
1486 1529 }
1487 1530
1488 - if (rc != -EINPROGRESS)
1531 + if (cleanup && walk->nbytes)
1489 1532 skcipher_walk_done(walk, rc);
1490 1533
1491 1534 out:
1492 - if (rc != -EINPROGRESS)
1535 + if (cleanup)
1493 1536 memzero_explicit(&req_ctx->param, sizeof(req_ctx->param));
1494 1537 pr_debug("rc=%d\n", rc);
1495 1538 return rc;
@@ -1539,7 +1582,7 @@ static int xts_paes_do_one_request(struct crypto_engine *engine, void *areq)
1539 1582 rc = xts_paes_do_crypt(ctx, req_ctx, tested, true);
1540 1583 if (rc == -EKEYEXPIRED) {
1541 1584 return pkey_handle_expired();
1542 - } else if (rc) {
1585 + } else if (rc && walk->nbytes) {
1543 1586 skcipher_walk_done(walk, rc);
1544 1587 }
1545 1588
@@ -1549,7 +1592,7 @@ static int xts_paes_do_one_request(struct crypto_engine *engine, void *areq)
1549 1592 atomic_dec(&ctx->via_engine_ctr);
1550 1593 crypto_finalize_skcipher_request(engine, req, rc);
1551 1594 local_bh_enable();
1552 - return rc;
1595 + return 0;
1553 1596 }
1554 1597
1555 1598 static struct skcipher_engine_alg xts_paes_alg = {
@@ -1557,6 +1600,7 @@ static struct skcipher_engine_alg xts_paes_alg = {
1557 1600 .base.cra_name = "xts(paes)",
1558 1601 .base.cra_driver_name = "xts-paes-s390",
1559 1602 .base.cra_priority = 402, /* ecb-paes-s390 + 1 */
1603 + .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NO_FALLBACK,
1560 1604 .base.cra_blocksize = AES_BLOCK_SIZE,
1561 1605 .base.cra_ctxsize = sizeof(struct s390_pxts_ctx),
1562 1606 .base.cra_module = THIS_MODULE,
modified arch/s390/crypto/phmac_s390.c
@@ -62,8 +62,10 @@ static inline int hwh_prepare(struct ahash_request *req,
62 62 */
63 63 static inline int hwh_advance(struct hash_walk_helper *hwh, int n)
64 64 {
65 - if (n < 0)
65 + if (n < 0) {
66 + hwh->walkbytes = n;
66 67 return crypto_hash_walk_done(&hwh->walk, n);
68 + }
67 69
68 70 hwh->walkbytes -= n;
69 71 hwh->walkaddr += n;
@@ -339,6 +341,10 @@ static inline int convert_key(const u8 *key, unsigned int keylen,
339 341 xflags);
340 342 }
341 343
344 + /* But finally map -EBUSY to -EIO to indicate an IO failure */
345 + if (rc == -EBUSY)
346 + rc = -EIO;
347 +
342 348 out:
343 349 pr_debug("rc=%d\n", rc);
344 350 return rc;
@@ -606,6 +612,7 @@ static int phmac_update(struct ahash_request *req)
606 612 struct phmac_tfm_ctx *tfm_ctx = crypto_ahash_ctx(tfm);
607 613 struct kmac_sha2_ctx *kmac_ctx = &req_ctx->kmac_ctx;
608 614 struct hash_walk_helper *hwh = &req_ctx->hwh;
615 + bool cleanup = true;
609 616 int rc;
610 617
611 618 /* prep the walk in the request context */
@@ -629,12 +636,15 @@ static int phmac_update(struct ahash_request *req)
629 636 req_ctx->async_op = OP_UPDATE;
630 637 atomic_inc(&tfm_ctx->via_engine_ctr);
631 638 rc = crypto_transfer_hash_request_to_engine(phmac_crypto_engine, req);
632 - if (rc != -EINPROGRESS)
639 + if (rc == -EINPROGRESS || rc == -EBUSY)
640 + cleanup = false;
641 + else
633 642 atomic_dec(&tfm_ctx->via_engine_ctr);
634 643 }
635 644
636 - if (rc != -EINPROGRESS) {
637 - hwh_advance(hwh, rc);
645 + if (cleanup) {
646 + if (hwh->walkbytes > 0)
647 + hwh_advance(hwh, rc);
638 648 memzero_explicit(kmac_ctx, sizeof(*kmac_ctx));
639 649 }
640 650
@@ -649,6 +659,7 @@ static int phmac_final(struct ahash_request *req)
649 659 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
650 660 struct phmac_tfm_ctx *tfm_ctx = crypto_ahash_ctx(tfm);
651 661 struct kmac_sha2_ctx *kmac_ctx = &req_ctx->kmac_ctx;
662 + bool cleanup = true;
652 663 int rc = 0;
653 664
654 665 /* Try synchronous operation if no active engine usage */
@@ -667,12 +678,14 @@ static int phmac_final(struct ahash_request *req)
667 678 req_ctx->async_op = OP_FINAL;
668 679 atomic_inc(&tfm_ctx->via_engine_ctr);
669 680 rc = crypto_transfer_hash_request_to_engine(phmac_crypto_engine, req);
670 - if (rc != -EINPROGRESS)
681 + if (rc == -EINPROGRESS || rc == -EBUSY)
682 + cleanup = false;
683 + else
671 684 atomic_dec(&tfm_ctx->via_engine_ctr);
672 685 }
673 686
674 687 out:
675 - if (rc != -EINPROGRESS)
688 + if (cleanup)
676 689 memzero_explicit(kmac_ctx, sizeof(*kmac_ctx));
677 690 pr_debug("rc=%d\n", rc);
678 691 return rc;
@@ -685,6 +698,7 @@ static int phmac_finup(struct ahash_request *req)
685 698 struct phmac_tfm_ctx *tfm_ctx = crypto_ahash_ctx(tfm);
686 699 struct kmac_sha2_ctx *kmac_ctx = &req_ctx->kmac_ctx;
687 700 struct hash_walk_helper *hwh = &req_ctx->hwh;
701 + bool cleanup = true;
688 702 int rc;
689 703
690 704 /* prep the walk in the request context */
@@ -716,15 +730,17 @@ static int phmac_finup(struct ahash_request *req)
716 730 /* req->async_op has been set to either OP_FINUP or OP_FINAL */
717 731 atomic_inc(&tfm_ctx->via_engine_ctr);
718 732 rc = crypto_transfer_hash_request_to_engine(phmac_crypto_engine, req);
719 - if (rc != -EINPROGRESS)
733 + if (rc == -EINPROGRESS || rc == -EBUSY)
734 + cleanup = false;
735 + else
720 736 atomic_dec(&tfm_ctx->via_engine_ctr);
721 737 }
722 738
723 - if (rc != -EINPROGRESS)
739 + if (cleanup && hwh->walkbytes > 0)
724 740 hwh_advance(hwh, rc);
725 741
726 742 out:
727 - if (rc != -EINPROGRESS)
743 + if (cleanup)
728 744 memzero_explicit(kmac_ctx, sizeof(*kmac_ctx));
729 745 pr_debug("rc=%d\n", rc);
730 746 return rc;
@@ -914,7 +930,7 @@ out:
914 930 atomic_dec(&tfm_ctx->via_engine_ctr);
915 931 crypto_finalize_hash_request(engine, req, rc);
916 932 local_bh_enable();
917 - return rc;
933 + return 0;
918 934 }
919 935
920 936 #define S390_ASYNC_PHMAC_ALG(x) \
modified arch/s390/include/asm/pai.h
@@ -76,7 +76,6 @@ static __always_inline void pai_kernel_exit(struct pt_regs *regs)
76 76 }
77 77
78 78 #define PAI_SAVE_AREA(x) ((x)->hw.event_base)
79 - #define PAI_CPU_MASK(x) ((x)->hw.addr_filters)
80 79 #define PAI_PMU_IDX(x) ((x)->hw.last_tag)
81 80 #define PAI_SWLIST(x) (&(x)->hw.tp_list)
82 81
modified arch/s390/kernel/debug.c
@@ -182,7 +182,7 @@ static struct debug_param_t {
182 182 static int debug_param_num;
183 183
184 184 /* functions */
185 - static void debug_get_param(const char *name, int *level, int *pages)
185 + static void debug_get_param(const char *name, int *level, int *pages, bool quiet)
186 186 {
187 187 struct debug_param_t *p;
188 188 int i;
@@ -192,11 +192,13 @@ static void debug_get_param(const char *name, int *level, int *pages)
192 192 if (!glob_match(p->name, name))
193 193 continue;
194 194 if (level && p->level != PARAM_UNSET) {
195 - pr_info("%s: override level to %d\n", name, p->level);
195 + if (!quiet)
196 + pr_info("%s: override level to %d\n", name, p->level);
196 197 *level = p->level;
197 198 }
198 199 if (pages && p->pages != PARAM_UNSET) {
199 - pr_info("%s: override pages to %d\n", name, p->pages);
200 + if (!quiet)
201 + pr_info("%s: override pages to %d\n", name, p->pages);
200 202 *pages = p->pages;
201 203 }
202 204 }
@@ -251,7 +253,7 @@ static int __init s390dbf_parse(char *arg)
251 253 * regular memory allocations are possible.
252 254 */
253 255 for (i = 0, id = __s390dbf_info; &id[i] < __s390dbf_info_end; i++)
254 - debug_get_param(id[i]->name, &id[i]->level, NULL);
256 + debug_get_param(id[i]->name, &id[i]->level, NULL, false);
255 257
256 258 return rc;
257 259 }
@@ -395,7 +397,7 @@ static debug_info_t *debug_info_create(const char *name, int pages_per_area,
395 397 int level = DEBUG_DEFAULT_LEVEL;
396 398 debug_info_t *rc;
397 399
398 - debug_get_param(name, &level, &pages_per_area);
400 + debug_get_param(name, &level, &pages_per_area, false);
399 401 rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size, level, ALL_AREAS);
400 402 if (!rc)
401 403 goto out;
@@ -960,7 +962,7 @@ void debug_register_static(debug_info_t *id, int pages_per_area, int nr_areas)
960 962 return;
961 963 }
962 964
963 - debug_get_param(id->name, &id->level, &pages_per_area);
965 + debug_get_param(id->name, &id->level, &pages_per_area, false);
964 966 copy = debug_info_alloc("", pages_per_area, nr_areas, id->buf_size,
965 967 id->level, ALL_AREAS);
966 968 if (!copy) {
@@ -1074,9 +1076,6 @@ static void _debug_set_level(debug_info_t *id, int new_level)
1074 1076 {
1075 1077 unsigned long flags;
1076 1078
1077 - if (!id)
1078 - return;
1079 -
1080 1079 if (new_level == DEBUG_OFF_LEVEL) {
1081 1080 pr_info("%s: switched off\n", id->name);
1082 1081 } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
@@ -1101,8 +1100,14 @@ static void _debug_set_level(debug_info_t *id, int new_level)
1101 1100 */
1102 1101 void debug_set_level(debug_info_t *id, int new_level)
1103 1102 {
1104 - /* Level specified via kernel parameter takes precedence */
1105 - debug_get_param(id->name, &new_level, NULL);
1103 + if (!id)
1104 + return;
1105 +
1106 + /*
1107 + * Level specified via kernel parameter takes precedence. The override
1108 + * was already announced during registration, so stay quiet here.
1109 + */
1110 + debug_get_param(id->name, &new_level, NULL, true);
1106 1111
1107 1112 _debug_set_level(id, new_level);
1108 1113 }
@@ -1278,7 +1283,7 @@ void debug_set_critical(void)
1278 1283 debug_entry_t *debug_event_common(debug_info_t *id, int level, const void *buf,
1279 1284 int len)
1280 1285 {
1281 - debug_entry_t *active;
1286 + debug_entry_t *active = NULL;
1282 1287 unsigned long flags;
1283 1288
1284 1289 if (!debug_active || !id->areas)
@@ -1289,6 +1294,8 @@ debug_entry_t *debug_event_common(debug_info_t *id, int level, const void *buf,
1289 1294 } else {
1290 1295 raw_spin_lock_irqsave(&id->lock, flags);
1291 1296 }
1297 + if (!id->areas)
1298 + goto out;
1292 1299 do {
1293 1300 active = get_active_entry(id);
1294 1301 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
@@ -1298,7 +1305,7 @@ debug_entry_t *debug_event_common(debug_info_t *id, int level, const void *buf,
1298 1305 len -= id->buf_size;
1299 1306 buf += id->buf_size;
1300 1307 } while (len > 0);
1301 -
1308 + out:
1302 1309 raw_spin_unlock_irqrestore(&id->lock, flags);
1303 1310 return active;
1304 1311 }
@@ -1311,7 +1318,7 @@ EXPORT_SYMBOL(debug_event_common);
1311 1318 debug_entry_t *debug_exception_common(debug_info_t *id, int level,
1312 1319 const void *buf, int len)
1313 1320 {
1314 - debug_entry_t *active;
1321 + debug_entry_t *active = NULL;
1315 1322 unsigned long flags;
1316 1323
1317 1324 if (!debug_active || !id->areas)
@@ -1322,6 +1329,8 @@ debug_entry_t *debug_exception_common(debug_info_t *id, int level,
1322 1329 } else {
1323 1330 raw_spin_lock_irqsave(&id->lock, flags);
1324 1331 }
1332 + if (!id->areas)
1333 + goto out;
1325 1334 do {
1326 1335 active = get_active_entry(id);
1327 1336 memcpy(DEBUG_DATA(active), buf, min(len, id->buf_size));
@@ -1331,7 +1340,7 @@ debug_entry_t *debug_exception_common(debug_info_t *id, int level,
1331 1340 len -= id->buf_size;
1332 1341 buf += id->buf_size;
1333 1342 } while (len > 0);
1334 -
1343 + out:
1335 1344 raw_spin_unlock_irqrestore(&id->lock, flags);
1336 1345 return active;
1337 1346 }
@@ -1357,7 +1366,7 @@ static inline int debug_count_numargs(char *string)
1357 1366 debug_entry_t *__debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
1358 1367 {
1359 1368 debug_sprintf_entry_t *curr_event;
1360 - debug_entry_t *active;
1369 + debug_entry_t *active = NULL;
1361 1370 unsigned long flags;
1362 1371 int numargs, idx;
1363 1372 va_list ap;
@@ -1372,6 +1381,8 @@ debug_entry_t *__debug_sprintf_event(debug_info_t *id, int level, char *string,
1372 1381 } else {
1373 1382 raw_spin_lock_irqsave(&id->lock, flags);
1374 1383 }
1384 + if (!id->areas)
1385 + goto out;
1375 1386 active = get_active_entry(id);
1376 1387 curr_event = (debug_sprintf_entry_t *) DEBUG_DATA(active);
1377 1388 va_start(ap, string);
@@ -1380,6 +1391,7 @@ debug_entry_t *__debug_sprintf_event(debug_info_t *id, int level, char *string,
1380 1391 curr_event->args[idx] = va_arg(ap, long);
1381 1392 va_end(ap);
1382 1393 debug_finish_entry(id, active, level, 0);
1394 + out:
1383 1395 raw_spin_unlock_irqrestore(&id->lock, flags);
1384 1396
1385 1397 return active;
@@ -1392,7 +1404,7 @@ EXPORT_SYMBOL(__debug_sprintf_event);
1392 1404 debug_entry_t *__debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
1393 1405 {
1394 1406 debug_sprintf_entry_t *curr_event;
1395 - debug_entry_t *active;
1407 + debug_entry_t *active = NULL;
1396 1408 unsigned long flags;
1397 1409 int numargs, idx;
1398 1410 va_list ap;
@@ -1408,6 +1420,8 @@ debug_entry_t *__debug_sprintf_exception(debug_info_t *id, int level, char *stri
1408 1420 } else {
1409 1421 raw_spin_lock_irqsave(&id->lock, flags);
1410 1422 }
1423 + if (!id->areas)
1424 + goto out;
1411 1425 active = get_active_entry(id);
1412 1426 curr_event = (debug_sprintf_entry_t *)DEBUG_DATA(active);
1413 1427 va_start(ap, string);
@@ -1416,6 +1430,7 @@ debug_entry_t *__debug_sprintf_exception(debug_info_t *id, int level, char *stri
1416 1430 curr_event->args[idx] = va_arg(ap, long);
1417 1431 va_end(ap);
1418 1432 debug_finish_entry(id, active, level, 1);
1433 + out:
1419 1434 raw_spin_unlock_irqrestore(&id->lock, flags);
1420 1435
1421 1436 return active;
@@ -1658,9 +1673,11 @@ static void debug_flush(debug_info_t *id, int area)
1658 1673 unsigned long flags;
1659 1674 int i, j;
1660 1675
1661 - if (!id || !id->areas)
1676 + if (!id)
1662 1677 return;
1663 1678 raw_spin_lock_irqsave(&id->lock, flags);
1679 + if (!id->areas)
1680 + goto out;
1664 1681 if (area == DEBUG_FLUSH_ALL) {
1665 1682 id->active_area = 0;
1666 1683 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
@@ -1675,6 +1692,7 @@ static void debug_flush(debug_info_t *id, int area)
1675 1692 for (i = 0; i < id->pages_per_area; i++)
1676 1693 memset(id->areas[area][i], 0, PAGE_SIZE);
1677 1694 }
1695 + out:
1678 1696 raw_spin_unlock_irqrestore(&id->lock, flags);
1679 1697 }
1680 1698
modified arch/s390/kernel/perf_pai.c
@@ -67,6 +67,7 @@ struct pai_mapptr {
67 67
68 68 static struct pai_root { /* Anchor to per CPU data */
69 69 refcount_t refcnt; /* Overall active events */
70 + atomic_t tskctx; /* Overall per-task events */
70 71 struct pai_mapptr __percpu *mapptr;
71 72 } pai_root[PAI_PMU_MAX];
72 73
@@ -93,14 +94,15 @@ struct pai_pmu { /* Define PAI PMU characteristics */
93 94 static struct pai_pmu pai_pmu[]; /* Forward declaration */
94 95
95 96 /* Free per CPU data when the last event is removed. */
96 - static void pai_root_free(int idx)
97 + static void pai_root_free(int idx, int tasks)
97 98 {
98 - if (refcount_dec_and_test(&pai_root[idx].refcnt)) {
99 + if (refcount_sub_and_test(tasks, &pai_root[idx].refcnt)) {
99 100 free_percpu(pai_root[idx].mapptr);
100 101 pai_root[idx].mapptr = NULL;
101 102 }
102 - debug_sprintf_event(paidbg, 5, "%s root[%d].refcount %d\n", __func__,
103 - idx, refcount_read(&pai_root[idx].refcnt));
103 + debug_sprintf_event(paidbg, 5, "%s root[%d].refcount %d tskctx %d\n",
104 + __func__, idx, refcount_read(&pai_root[idx].refcnt),
105 + atomic_read(&pai_root[idx].tskctx));
104 106 }
105 107
106 108 /*
@@ -137,40 +139,54 @@ static void pai_free(struct pai_mapptr *mp)
137 139 mp->mapptr = NULL;
138 140 }
139 141
140 - /* Adjust usage counters and remove allocated memory when all users are
141 - * gone.
142 - */
143 - static void pai_event_destroy_cpu(struct perf_event *event, int cpu)
142 + /* Called under mutex_lock */
143 + static void pai_event_destroy_cpu(int idx, int cpu, bool hotplug)
144 144 {
145 - int idx = PAI_PMU_IDX(event);
146 - struct pai_mapptr *mp = per_cpu_ptr(pai_root[idx].mapptr, cpu);
147 - struct pai_map *cpump = mp->mapptr;
145 + struct pai_mapptr *mp;
146 + struct pai_map *cpump;
147 + int tasks = 1;
148 148
149 - mutex_lock(&pai_reserve_mutex);
150 - debug_sprintf_event(paidbg, 5, "%s event %#llx idx %d cpu %d users %d "
151 - "refcnt %u\n", __func__, event->attr.config, idx,
152 - event->cpu, cpump->active_events,
153 - refcount_read(&cpump->refcnt));
154 - if (refcount_dec_and_test(&cpump->refcnt))
149 + /* Check reference count and return when all gone.
150 + * 1. An event is installed on online CPU X.
151 + * 2. CPU x is offlined and the per-CPU data is removed.
152 + * 3. Event is destroyed via close system call.
153 + */
154 + if (!refcount_read(&pai_root[idx].refcnt))
155 + return; /* No events at all */
156 + mp = per_cpu_ptr(pai_root[idx].mapptr, cpu);
157 + if (!mp || !mp->mapptr) /* No events on that CPU */
158 + return;
159 +
160 + /* When hotplug is true, invocation is from CPU hotplug callback.
161 + * Delete per-CPU resource and adjust refcnt when per-task events
162 + * are currently active. This can be more than one.
163 + * In this case adjust counters.
164 + */
165 + if (hotplug)
166 + tasks = atomic_read(&pai_root[idx].tskctx);
167 +
168 + cpump = mp->mapptr;
169 + if (refcount_sub_and_test(tasks, &cpump->refcnt))
155 170 pai_free(mp);
156 - pai_root_free(idx);
157 - mutex_unlock(&pai_reserve_mutex);
171 + pai_root_free(idx, tasks);
158 172 }
159 173
160 174 static void pai_event_destroy(struct perf_event *event)
161 175 {
162 - int cpu;
176 + int cpu = 0, idx = PAI_PMU_IDX(event);
163 177
164 178 free_page(PAI_SAVE_AREA(event));
179 + cpus_read_lock();
180 + mutex_lock(&pai_reserve_mutex);
165 181 if (event->cpu == -1) {
166 - struct cpumask *mask = PAI_CPU_MASK(event);
167 -
168 - for_each_cpu(cpu, mask)
169 - pai_event_destroy_cpu(event, cpu);
170 - kfree(mask);
182 + atomic_dec(&pai_root[idx].tskctx);
183 + for_each_online_cpu(cpu)
184 + pai_event_destroy_cpu(idx, cpu, false);
171 185 } else {
172 - pai_event_destroy_cpu(event, event->cpu);
186 + pai_event_destroy_cpu(idx, event->cpu, false);
173 187 }
188 + mutex_unlock(&pai_reserve_mutex);
189 + cpus_read_unlock();
174 190 }
175 191
176 192 static void paicrypt_event_destroy(struct perf_event *event)
@@ -234,25 +250,30 @@ static u64 paicrypt_getall(struct perf_event *event)
234 250 return sum;
235 251 }
236 252
237 - /* Check concurrent access of counting and sampling for crypto events.
238 - * This function is called in process context and it is save to block.
239 - * When the event initialization functions fails, no other call back will
240 - * be invoked.
241 - *
242 - * Allocate the memory for the event.
243 - */
244 - static int pai_alloc_cpu(struct perf_event *event, int cpu)
253 + /* Called under mutex_lock */
254 + static int pai_alloc_cpu(int idx, int cpu, bool hotplug)
245 255 {
246 - int rc, idx = PAI_PMU_IDX(event);
247 256 struct pai_map *cpump = NULL;
248 257 bool need_paiext_cb = false;
249 258 struct pai_mapptr *mp;
259 + int tasks = 1, rc = 0;
260 +
261 + /* When hotplug is true, invocation is from CPU hotplug callback.
262 + * Allocate per-CPU resource when per-task events are currently active.
263 + * This can be more than one. In this case adjust all reference
264 + * counters. Otherwise return, this ensures memory is only allocated
265 + * when needed.
266 + */
267 + if (hotplug) {
268 + tasks = atomic_read(&pai_root[idx].tskctx);
269 + if (!tasks)
270 + goto out;
271 + }
250 272
251 - mutex_lock(&pai_reserve_mutex);
252 273 /* Allocate root node */
253 274 rc = pai_root_alloc(idx);
254 275 if (rc)
255 - goto unlock;
276 + goto out;
256 277
257 278 /* Allocate node for this event */
258 279 mp = per_cpu_ptr(pai_root[idx].mapptr, cpu);
@@ -296,28 +317,45 @@ static int pai_alloc_cpu(struct perf_event *event, int cpu)
296 317 goto undo;
297 318 }
298 319 INIT_LIST_HEAD(&cpump->syswide_list);
299 - refcount_set(&cpump->refcnt, 1);
320 + refcount_set(&cpump->refcnt, tasks);
300 321 rc = 0;
301 322 } else {
302 - refcount_inc(&cpump->refcnt);
323 + refcount_add(tasks, &cpump->refcnt);
303 324 }
325 + /* If tasks is greater than 1, we are called from CPU hotplug path
326 + * and need to adjust the pai_root[idx].refcnt by the number of
327 + * per-process events. Function pai_root_alloc(idx) already
328 + * incremented by one. Adjust for the rest.
329 + */
330 + if (tasks > 1)
331 + refcount_add(tasks - 1, &pai_root[idx].refcnt);
304 332
305 333 undo:
306 334 if (rc) {
307 335 /* Error in allocation of event, decrement anchor. Since
308 336 * the event in not created, its destroy() function is never
309 337 * invoked. Adjust the reference counter for the anchor.
338 + * The failure happened in the case of variable
339 + * cpump == NULL branch above. The pai_root[XXX].refcnt has
340 + * been incremented by one. Then the per-CPU allocation
341 + * failed, so decrement it by one, regardless of tasks.
310 342 */
311 - pai_root_free(idx);
343 + pai_root_free(idx, 1);
312 344 }
313 - unlock:
314 - mutex_unlock(&pai_reserve_mutex);
345 + out:
315 346 /* If rc is non-zero, no increment of counter/sampler was done. */
316 347 return rc;
317 348 }
318 349
350 + /* Check concurrent access of counting and sampling for PAI events.
351 + * This function is called in process context and it is safe to block.
352 + * When the event initialization functions fails, no other call back will
353 + * be invoked.
354 + * Called under mutex_lock.
355 + */
319 356 static int pai_alloc(struct perf_event *event)
320 357 {
358 + int idx = PAI_PMU_IDX(event);
321 359 struct cpumask *maskptr;
322 360 int cpu, rc = -ENOMEM;
323 361
@@ -326,24 +364,20 @@ static int pai_alloc(struct perf_event *event)
326 364 goto out;
327 365
328 366 for_each_online_cpu(cpu) {
329 - rc = pai_alloc_cpu(event, cpu);
367 + rc = pai_alloc_cpu(idx, cpu, false);
330 368 if (rc) {
331 369 for_each_cpu(cpu, maskptr)
332 - pai_event_destroy_cpu(event, cpu);
333 - kfree(maskptr);
334 - goto out;
370 + pai_event_destroy_cpu(idx, cpu, false);
371 + goto undo;
335 372 }
336 373 cpumask_set_cpu(cpu, maskptr);
337 374 }
338 375
339 - /*
340 - * On error all cpumask are freed and all events have been destroyed.
341 - * Save of which CPUs data structures have been allocated for.
342 - * Release them in pai_event_destroy call back function
343 - * for this event.
344 - */
345 - PAI_CPU_MASK(event) = maskptr;
346 376 rc = 0;
377 + /* Trace per-task events for CPU hotplug. */
378 + atomic_inc(&pai_root[idx].tskctx);
379 + undo:
380 + kfree(maskptr);
347 381 out:
348 382 return rc;
349 383 }
@@ -391,10 +425,14 @@ static int pai_event_init(struct perf_event *event, int idx)
391 425 }
392 426 }
393 427
428 + cpus_read_lock();
429 + mutex_lock(&pai_reserve_mutex);
394 430 if (event->cpu >= 0)
395 - rc = pai_alloc_cpu(event, event->cpu);
431 + rc = pai_alloc_cpu(idx, event->cpu, false);
396 432 else
397 433 rc = pai_alloc(event);
434 + mutex_unlock(&pai_reserve_mutex);
435 + cpus_read_unlock();
398 436 if (rc) {
399 437 free_page(PAI_SAVE_AREA(event));
400 438 goto out;
@@ -1239,8 +1277,35 @@ static int __init paipmu_setup(void)
1239 1277 return install_ok;
1240 1278 }
1241 1279
1280 + static int pai_online_cpu(unsigned int cpu)
1281 + {
1282 + int rc;
1283 +
1284 + mutex_lock(&pai_reserve_mutex);
1285 + rc = pai_alloc_cpu(PAI_PMU_CRYPTO, cpu, true);
1286 + if (rc)
1287 + goto out;
1288 + rc = pai_alloc_cpu(PAI_PMU_EXT, cpu, true);
1289 + if (rc)
1290 + pai_event_destroy_cpu(PAI_PMU_CRYPTO, cpu, true);
1291 + out:
1292 + mutex_unlock(&pai_reserve_mutex);
1293 + return rc;
1294 + }
1295 +
1296 + static int pai_offline_cpu(unsigned int cpu)
1297 + {
1298 + mutex_lock(&pai_reserve_mutex);
1299 + pai_event_destroy_cpu(PAI_PMU_CRYPTO, cpu, true);
1300 + pai_event_destroy_cpu(PAI_PMU_EXT, cpu, true);
1301 + mutex_unlock(&pai_reserve_mutex);
1302 + return 0;
1303 + }
1304 +
1242 1305 static int __init pai_init(void)
1243 1306 {
1307 + int state, rc;
1308 +
1244 1309 /* Setup s390dbf facility */
1245 1310 paidbg = debug_register("pai", 1, 1, 128);
1246 1311 if (!paidbg) {
@@ -1249,13 +1314,24 @@ static int __init pai_init(void)
1249 1314 }
1250 1315 debug_register_view(paidbg, &debug_sprintf_view);
1251 1316
1252 - if (!paipmu_setup()) {
1253 - /* No PMU registration, no need for debug buffer */
1254 - debug_unregister_view(paidbg, &debug_sprintf_view);
1255 - debug_unregister(paidbg);
1256 - return -ENODEV;
1257 - }
1317 + /* CPUHP_BP_PREPARE_DYN --> before CPU is brought online */
1318 + state = cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "perf/pai:prepare",
1319 + pai_online_cpu, pai_offline_cpu);
1320 + rc = state < 0 ? state : 0;
1321 + if (rc < 0)
1322 + goto out_debug;
1323 +
1324 + rc = -ENODEV;
1325 + if (!paipmu_setup())
1326 + goto out_cpuhp;
1258 1327 return 0;
1328 +
1329 + out_cpuhp:
1330 + cpuhp_remove_state(state);
1331 + out_debug:
1332 + debug_unregister_view(paidbg, &debug_sprintf_view);
1333 + debug_unregister(paidbg);
1334 + return rc;
1259 1335 }
1260 1336
1261 1337 device_initcall(pai_init);
modified arch/x86/events/intel/core.c
@@ -3125,6 +3125,27 @@ static void intel_pmu_del_event(struct perf_event *event)
3125 3125 this_cpu_ptr(&cpu_hw_events)->n_late_setup--;
3126 3126 }
3127 3127
3128 + int __intel_pmu_quiesce(void)
3129 + {
3130 + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
3131 + int pmu_enabled = cpuc->enabled;
3132 +
3133 + cpuc->enabled = 0;
3134 + if (pmu_enabled)
3135 + intel_pmu_disable_all();
3136 +
3137 + return pmu_enabled;
3138 + }
3139 +
3140 + void __intel_pmu_resume(int pmu_enabled)
3141 + {
3142 + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
3143 +
3144 + cpuc->enabled = pmu_enabled;
3145 + if (pmu_enabled)
3146 + intel_pmu_enable_all(0);
3147 + }
3148 +
3128 3149 static int icl_set_topdown_event_period(struct perf_event *event)
3129 3150 {
3130 3151 struct hw_perf_event *hwc = &event->hw;
@@ -3316,16 +3337,13 @@ static void intel_pmu_read_event(struct perf_event *event)
3316 3337 if (event->hw.flags & (PERF_X86_EVENT_AUTO_RELOAD | PERF_X86_EVENT_TOPDOWN) ||
3317 3338 is_pebs_counter_event_group(event)) {
3318 3339 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
3319 - bool pmu_enabled = cpuc->enabled;
3340 + int pmu_enabled;
3320 3341
3321 3342 /* Only need to call update_topdown_event() once for group read. */
3322 3343 if (is_metric_event(event) && (cpuc->txn_flags & PERF_PMU_TXN_READ))
3323 3344 return;
3324 3345
3325 - cpuc->enabled = 0;
3326 - if (pmu_enabled)
3327 - intel_pmu_disable_all();
3328 -
3346 + pmu_enabled = __intel_pmu_quiesce();
3329 3347 /*
3330 3348 * If the PEBS counters snapshotting is enabled,
3331 3349 * the topdown event is available in PEBS records.
@@ -3334,10 +3352,7 @@ static void intel_pmu_read_event(struct perf_event *event)
3334 3352 static_call(intel_pmu_update_topdown_event)(event, NULL);
3335 3353 else
3336 3354 intel_pmu_drain_pebs_buffer();
3337 -
3338 - cpuc->enabled = pmu_enabled;
3339 - if (pmu_enabled)
3340 - intel_pmu_enable_all(0);
3355 + __intel_pmu_resume(pmu_enabled);
3341 3356
3342 3357 return;
3343 3358 }
modified arch/x86/events/intel/ds.c
@@ -1242,8 +1242,11 @@ unlock:
1242 1242
1243 1243 void intel_pmu_drain_pebs_buffer(void)
1244 1244 {
1245 + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
1245 1246 struct perf_sample_data data;
1246 1247
1248 + WARN_ON_ONCE(cpuc->enabled);
1249 +
1247 1250 static_call(x86_pmu_drain_pebs)(NULL, &data);
1248 1251 }
1249 1252
@@ -1864,8 +1867,11 @@ static void intel_pmu_pebs_via_pt_enable(struct perf_event *event)
1864 1867 static inline void intel_pmu_drain_large_pebs(struct cpu_hw_events *cpuc)
1865 1868 {
1866 1869 if (cpuc->n_pebs == cpuc->n_large_pebs &&
1867 - cpuc->n_pebs != cpuc->n_pebs_via_pt)
1870 + cpuc->n_pebs != cpuc->n_pebs_via_pt) {
1871 + int enabled = __intel_pmu_quiesce();
1868 1872 intel_pmu_drain_pebs_buffer();
1873 + __intel_pmu_resume(enabled);
1874 + }
1869 1875 }
1870 1876
1871 1877 static void __intel_pmu_pebs_enable(struct perf_event *event)
@@ -2432,7 +2438,7 @@ static inline void __setup_pebs_basic_group(struct perf_event *event,
2432 2438 {
2433 2439 /* The ip in basic is EventingIP */
2434 2440 set_linear_ip(regs, ip);
2435 - regs->flags = PERF_EFLAGS_EXACT;
2441 + regs->flags |= PERF_EFLAGS_EXACT;
2436 2442 setup_pebs_time(event, data, tsc);
2437 2443
2438 2444 if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT)
@@ -2444,9 +2450,17 @@ static inline void __setup_pebs_gpr_group(struct perf_event *event,
2444 2450 struct pebs_gprs *gprs,
2445 2451 u64 sample_type)
2446 2452 {
2453 + /*
2454 + * Update flags with PEBS data. PERF_EFLAGS_EXACT must be set
2455 + * in previous basic group handling.
2456 + */
2457 + regs->flags = gprs->flags | PERF_EFLAGS_EXACT;
2458 +
2447 2459 if (event->attr.precise_ip < 2) {
2448 2460 set_linear_ip(regs, gprs->ip);
2449 2461 regs->flags &= ~PERF_EFLAGS_EXACT;
2462 + } else if (regs->flags & X86_VM_MASK) {
2463 + regs->flags ^= (PERF_EFLAGS_VM | X86_VM_MASK);
2450 2464 }
2451 2465
2452 2466 if (sample_type & (PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER))
modified arch/x86/events/perf_event.h
@@ -1638,6 +1638,9 @@ static __always_inline void __intel_pmu_lbr_disable(void)
1638 1638 wrmsrq(MSR_IA32_DEBUGCTLMSR, debugctl);
1639 1639 }
1640 1640
1641 + extern int __intel_pmu_quiesce(void);
1642 + extern void __intel_pmu_resume(int pmu_enabled);
1643 +
1641 1644 int intel_pmu_save_and_restart(struct perf_event *event);
1642 1645
1643 1646 struct event_constraint *
modified drivers/accel/amdxdna/Kconfig
@@ -6,6 +6,7 @@ config DRM_ACCEL_AMDXDNA
6 6 depends on DRM_ACCEL
7 7 depends on PCI && HAS_IOMEM
8 8 depends on X86_64
9 + depends on AMD_PMF || !AMD_PMF
9 10 select DRM_SCHED
10 11 select DRM_GEM_SHMEM_HELPER
11 12 select FW_LOADER
modified drivers/accel/ethosu/ethosu_device.h
@@ -87,6 +87,7 @@ struct gen_pool;
87 87 #define PMU_EV_TYPE_IDLE 0x20
88 88
89 89 enum ethosu_cmds {
90 + NPU_OP_STOP = 0x0,
90 91 NPU_OP_CONV = 0x2,
91 92 NPU_OP_DEPTHWISE = 0x3,
92 93 NPU_OP_POOL = 0x5,
modified drivers/accel/ethosu/ethosu_drv.c
@@ -281,8 +281,6 @@ static int ethosu_device_suspend(struct device *dev)
281 281
282 282 static int ethosu_sram_init(struct ethosu_device *ethosudev)
283 283 {
284 - ethosudev->npu_info.sram_size = 0;
285 -
286 284 ethosudev->srampool = of_gen_pool_get(ethosudev->base.dev->of_node, "sram", 0);
287 285 if (!ethosudev->srampool)
288 286 return 0;
@@ -293,6 +291,7 @@ static int ethosu_sram_init(struct ethosu_device *ethosudev)
293 291 ethosudev->npu_info.sram_size,
294 292 &ethosudev->sramphys);
295 293 if (!ethosudev->sram) {
294 + ethosudev->npu_info.sram_size = 0;
296 295 dev_err(ethosudev->base.dev, "failed to allocate from SRAM pool\n");
297 296 return -ENOMEM;
298 297 }
modified drivers/accel/ethosu/ethosu_gem.c
@@ -390,6 +390,7 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
390 390 struct ethosu_validated_cmdstream_info __free(kfree) *info = kzalloc_obj(*info);
391 391 struct ethosu_device *edev = to_ethosu_device(ddev);
392 392 u32 *bocmds = bo->base.vaddr;
393 + bool ends_with_stop = false;
393 394 struct cmd_state st;
394 395 int i, ret;
395 396
@@ -426,6 +427,11 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
426 427 }
427 428
428 429 switch (cmd) {
430 + case NPU_OP_STOP:
431 + if (i != size / 4 - 1)
432 + return -EINVAL;
433 + ends_with_stop = true;
434 + break;
429 435 case NPU_OP_DMA_START:
430 436 srclen = dma_length(info, &st.dma, &st.dma.src);
431 437 dstlen = dma_length(info, &st.dma, &st.dma.dst);
@@ -688,6 +694,9 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
688 694 }
689 695 }
690 696
697 + if (!ends_with_stop)
698 + return -EINVAL;
699 +
691 700 for (i = 0; i < NPU_BASEP_REGION_MAX; i++) {
692 701 if (!info->region_size[i])
693 702 continue;
modified drivers/accel/ethosu/ethosu_job.c
@@ -343,7 +343,7 @@ int ethosu_job_init(struct ethosu_device *edev)
343 343 ret = devm_request_threaded_irq(dev, edev->irq,
344 344 ethosu_job_irq_handler,
345 345 ethosu_job_irq_handler_thread,
346 - IRQF_SHARED, KBUILD_MODNAME,
346 + 0, KBUILD_MODNAME,
347 347 edev);
348 348 if (ret) {
349 349 dev_err(dev, "failed to request irq\n");
@@ -374,12 +374,10 @@ int ethosu_job_open(struct ethosu_file_priv *ethosu_priv)
374 374 {
375 375 struct ethosu_device *dev = ethosu_priv->edev;
376 376 struct drm_gpu_scheduler *sched = &dev->sched;
377 - int ret;
378 377
379 - ret = drm_sched_entity_init(&ethosu_priv->sched_entity,
380 - DRM_SCHED_PRIORITY_NORMAL,
381 - &sched, 1, NULL);
382 - return WARN_ON(ret);
378 + return drm_sched_entity_init(&ethosu_priv->sched_entity,
379 + DRM_SCHED_PRIORITY_NORMAL,
380 + &sched, 1, NULL);
383 381 }
384 382
385 383 void ethosu_job_close(struct ethosu_file_priv *ethosu_priv)
@@ -449,13 +447,13 @@ static int ethosu_ioctl_submit_job(struct drm_device *dev, struct drm_file *file
449 447 if (!cmd_info->region_size[i])
450 448 continue;
451 449 if (i == ETHOSU_SRAM_REGION) {
452 - if (cmd_info->region_size[i] <= edev->npu_info.sram_size)
450 + if (cmd_info->region_size[i] <= ejob->sram_size)
453 451 continue;
454 452
455 453 dev_err(dev->dev,
456 - "cmd stream region %d size greater than SRAM size (%llu > %u)\n",
454 + "cmd stream region %d size greater than job SRAM size (%llu > %u)\n",
457 455 i, cmd_info->region_size[i],
458 - edev->npu_info.sram_size);
456 + ejob->sram_size);
459 457 ret = -EINVAL;
460 458 goto out_cleanup_job;
461 459 }
modified drivers/accel/ivpu/ivpu_drv.c
@@ -515,6 +515,7 @@ void ivpu_prepare_for_reset(struct ivpu_device *vdev)
515 515 {
516 516 ivpu_hw_irq_disable(vdev);
517 517 disable_irq(vdev->irq);
518 + atomic_set(&vdev->job_timeout_detected, 0);
518 519 flush_work(&vdev->irq_dct_work);
519 520 flush_work(&vdev->context_abort_work);
520 521 flush_work(&vdev->job_destroy_work);
@@ -710,7 +711,7 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
710 711 vdev->context_xa_limit.max = IVPU_USER_CONTEXT_MAX_SSID;
711 712 atomic64_set(&vdev->unique_id_counter, 0);
712 713 atomic_set(&vdev->job_timeout_counter, 0);
713 - atomic_set(&vdev->faults_detected, 0);
714 + atomic_set(&vdev->job_timeout_detected, 0);
714 715 xa_init_flags(&vdev->context_xa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
715 716 xa_init_flags(&vdev->submitted_jobs_xa, XA_FLAGS_ALLOC1);
716 717 xa_init_flags(&vdev->db_xa, XA_FLAGS_ALLOC1);
modified drivers/accel/ivpu/ivpu_drv.h
@@ -171,7 +171,7 @@ struct ivpu_device {
171 171 struct xarray submitted_jobs_xa;
172 172 struct ivpu_ipc_consumer job_done_consumer;
173 173 atomic_t job_timeout_counter;
174 - atomic_t faults_detected;
174 + atomic_t job_timeout_detected;
175 175
176 176 atomic64_t unique_id_counter;
177 177
modified drivers/accel/ivpu/ivpu_fw_log.c
@@ -26,10 +26,17 @@ MODULE_PARM_DESC(fw_log_level,
26 26 " error=" __stringify(IVPU_FW_LOG_ERROR)
27 27 " fatal=" __stringify(IVPU_FW_LOG_FATAL));
28 28
29 + struct ivpu_fw_log_desc {
30 + struct vpu_tracing_buffer_header *log;
31 + u32 header_size;
32 + u32 size;
33 + };
34 +
29 35 static int fw_log_from_bo(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *offset,
30 - struct vpu_tracing_buffer_header **out_log)
36 + struct ivpu_fw_log_desc *desc)
31 37 {
32 38 struct vpu_tracing_buffer_header *log;
39 + u32 header_size, size;
33 40
34 41 if ((*offset + sizeof(*log)) > ivpu_bo_size(bo))
35 42 return -EINVAL;
@@ -39,26 +46,32 @@ static int fw_log_from_bo(struct ivpu_device *vdev, struct ivpu_bo *bo, u32 *off
39 46 if (log->vpu_canary_start != VPU_TRACING_BUFFER_CANARY)
40 47 return -EINVAL;
41 48
42 - if (log->header_size < sizeof(*log) || log->header_size > 1024) {
43 - ivpu_dbg(vdev, FW_BOOT, "Invalid header size 0x%x\n", log->header_size);
49 + header_size = READ_ONCE(log->header_size);
50 + size = READ_ONCE(log->size);
51 +
52 + if (header_size < sizeof(*log) || header_size > 1024) {
53 + ivpu_dbg(vdev, FW_BOOT, "Invalid header size 0x%x\n", header_size);
44 54 return -EINVAL;
45 55 }
46 - if (log->size < log->header_size) {
47 - ivpu_dbg(vdev, FW_BOOT, "Invalid log size 0x%x\n", log->size);
56 + if ((char *)log + size > (char *)ivpu_bo_vaddr(bo) + ivpu_bo_size(bo)) {
57 + ivpu_dbg(vdev, FW_BOOT, "Invalid log size 0x%x\n", size);
48 58 return -EINVAL;
49 59 }
50 - if ((char *)log + log->size > (char *)ivpu_bo_vaddr(bo) + ivpu_bo_size(bo)) {
51 - ivpu_dbg(vdev, FW_BOOT, "Invalid log size 0x%x\n", log->size);
60 + if (size < header_size) {
61 + ivpu_dbg(vdev, FW_BOOT, "Invalid log size 0x%x < header size 0x%x\n",
62 + size, header_size);
52 63 return -EINVAL;
53 64 }
54 65
55 - *out_log = log;
56 - *offset += log->size;
66 + desc->log = log;
67 + desc->header_size = header_size;
68 + desc->size = size;
69 + *offset += size;
57 70
58 71 ivpu_dbg(vdev, FW_BOOT,
59 - "FW log name \"%s\", write offset 0x%x size 0x%x, wrap count %d, hdr version %d size %d format %d, alignment %d",
60 - log->name, log->write_index, log->size, log->wrap_count, log->header_version,
61 - log->header_size, log->format, log->alignment);
72 + "FW log name \"%.*s\", write offset 0x%x size 0x%x, wrap count %d, hdr version %d size %d format %d, alignment %d",
73 + (int)ARRAY_SIZE(log->name), log->name, log->write_index, size, log->wrap_count,
74 + log->header_version, header_size, log->format, log->alignment);
62 75
63 76 return 0;
64 77 }
@@ -94,11 +107,12 @@ static void fw_log_print_lines(char *buffer, u32 size, struct drm_printer *p)
94 107 drm_printf(p, "%s", line);
95 108 }
96 109
97 - static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const char *prefix,
110 + static void fw_log_print_buffer(struct ivpu_fw_log_desc *desc, const char *prefix,
98 111 bool only_new_msgs, struct drm_printer *p)
99 112 {
100 - char *log_data = (void *)log + log->header_size;
101 - u32 data_size = log->size - log->header_size;
113 + struct vpu_tracing_buffer_header *log = desc->log;
114 + char *log_data = (void *)log + desc->header_size;
115 + u32 data_size = desc->size - desc->header_size;
102 116 u32 log_start = only_new_msgs ? READ_ONCE(log->read_index) : 0;
103 117 u32 log_end = READ_ONCE(log->write_index);
104 118
@@ -109,7 +123,8 @@ static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const cha
109 123
110 124 if (log->wrap_count == log->read_wrap_count) {
111 125 if (log_end <= log_start) {
112 - drm_printf(p, "==== %s \"%s\" log empty ====\n", prefix, log->name);
126 + drm_printf(p, "==== %s \"%.*s\" log empty ====\n", prefix,
127 + (int)ARRAY_SIZE(log->name), log->name);
113 128 return;
114 129 }
115 130 } else if (log->wrap_count == log->read_wrap_count + 1) {
@@ -119,7 +134,8 @@ static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const cha
119 134 log_start = log_end;
120 135 }
121 136
122 - drm_printf(p, "==== %s \"%s\" log start ====\n", prefix, log->name);
137 + drm_printf(p, "==== %s \"%.*s\" log start ====\n", prefix, (int)ARRAY_SIZE(log->name),
138 + log->name);
123 139 if (log_end > log_start) {
124 140 fw_log_print_lines(log_data + log_start, log_end - log_start, p);
125 141 } else {
@@ -127,18 +143,19 @@ static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const cha
127 143 fw_log_print_lines(log_data, log_end, p);
128 144 }
129 145 drm_printf(p, "\n\x1b[0m"); /* add new line and clear formatting */
130 - drm_printf(p, "==== %s \"%s\" log end ====\n", prefix, log->name);
146 + drm_printf(p, "==== %s \"%.*s\" log end ====\n", prefix, (int)ARRAY_SIZE(log->name),
147 + log->name);
131 148 }
132 149
133 150 static void
134 151 fw_log_print_all_in_bo(struct ivpu_device *vdev, const char *name,
135 152 struct ivpu_bo *bo, bool only_new_msgs, struct drm_printer *p)
136 153 {
137 - struct vpu_tracing_buffer_header *log;
154 + struct ivpu_fw_log_desc desc;
138 155 u32 next = 0;
139 156
140 - while (fw_log_from_bo(vdev, bo, &next, &log) == 0)
141 - fw_log_print_buffer(log, name, only_new_msgs, p);
157 + while (fw_log_from_bo(vdev, bo, &next, &desc) == 0)
158 + fw_log_print_buffer(&desc, name, only_new_msgs, p);
142 159 }
143 160
144 161 void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p)
@@ -149,36 +166,36 @@ void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_
149 166
150 167 void ivpu_fw_log_mark_read(struct ivpu_device *vdev)
151 168 {
152 - struct vpu_tracing_buffer_header *log;
169 + struct ivpu_fw_log_desc desc;
153 170 u32 next;
154 171
155 172 next = 0;
156 - while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0) {
157 - log->read_index = READ_ONCE(log->write_index);
158 - log->read_wrap_count = READ_ONCE(log->wrap_count);
173 + while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &desc) == 0) {
174 + desc.log->read_index = READ_ONCE(desc.log->write_index);
175 + desc.log->read_wrap_count = READ_ONCE(desc.log->wrap_count);
159 176 }
160 177
161 178 next = 0;
162 - while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0) {
163 - log->read_index = READ_ONCE(log->write_index);
164 - log->read_wrap_count = READ_ONCE(log->wrap_count);
179 + while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &desc) == 0) {
180 + desc.log->read_index = READ_ONCE(desc.log->write_index);
181 + desc.log->read_wrap_count = READ_ONCE(desc.log->wrap_count);
165 182 }
166 183 }
167 184
168 185 void ivpu_fw_log_reset(struct ivpu_device *vdev)
169 186 {
170 - struct vpu_tracing_buffer_header *log;
187 + struct ivpu_fw_log_desc desc;
171 188 u32 next;
172 189
173 190 next = 0;
174 - while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0) {
175 - log->read_index = 0;
176 - log->read_wrap_count = 0;
191 + while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &desc) == 0) {
192 + desc.log->read_index = 0;
193 + desc.log->read_wrap_count = 0;
177 194 }
178 195
179 196 next = 0;
180 - while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0) {
181 - log->read_index = 0;
182 - log->read_wrap_count = 0;
197 + while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &desc) == 0) {
198 + desc.log->read_index = 0;
199 + desc.log->read_wrap_count = 0;
183 200 }
184 201 }
modified drivers/accel/ivpu/ivpu_gem.h
@@ -87,15 +87,23 @@ static inline bool ivpu_bo_is_resident(struct ivpu_bo *bo)
87 87 return !!bo->base.pages;
88 88 }
89 89
90 - static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
90 + static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u64 vpu_addr, u64 size)
91 91 {
92 + u64 bo_size = ivpu_bo_size(bo);
93 + u64 offset;
94 +
92 95 if (vpu_addr < bo->vpu_addr)
93 96 return NULL;
94 97
95 - if (vpu_addr >= (bo->vpu_addr + ivpu_bo_size(bo)))
98 + if (size > bo_size)
99 + return NULL;
100 +
101 + offset = vpu_addr - bo->vpu_addr;
102 +
103 + if (offset > bo_size - size)
96 104 return NULL;
97 105
98 - return ivpu_bo_vaddr(bo) + (vpu_addr - bo->vpu_addr);
106 + return ivpu_bo_vaddr(bo) + offset;
99 107 }
100 108
101 109 static inline u32 cpu_to_vpu_addr(struct ivpu_bo *bo, void *cpu_addr)
modified drivers/accel/ivpu/ivpu_ipc.c
@@ -79,7 +79,7 @@ ivpu_ipc_tx_prepare(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
79 79 return -ENOMEM;
80 80 }
81 81
82 - tx_buf = ivpu_to_cpu_addr(ipc->mem_tx, tx_buf_vpu_addr);
82 + tx_buf = ivpu_to_cpu_addr(ipc->mem_tx, tx_buf_vpu_addr, sizeof(*tx_buf));
83 83 if (drm_WARN_ON(&vdev->drm, !tx_buf)) {
84 84 gen_pool_free(ipc->mm_tx, tx_buf_vpu_addr, sizeof(*tx_buf));
85 85 return -EIO;
@@ -420,7 +420,7 @@ void ivpu_ipc_irq_handler(struct ivpu_device *vdev)
420 420 return;
421 421 }
422 422
423 - ipc_hdr = ivpu_to_cpu_addr(ipc->mem_rx, vpu_addr);
423 + ipc_hdr = ivpu_to_cpu_addr(ipc->mem_rx, vpu_addr, sizeof(*ipc_hdr));
424 424 if (!ipc_hdr) {
425 425 ivpu_warn_ratelimited(vdev, "IPC msg 0x%x out of range\n", vpu_addr);
426 426 continue;
@@ -429,7 +429,8 @@ void ivpu_ipc_irq_handler(struct ivpu_device *vdev)
429 429
430 430 jsm_msg = NULL;
431 431 if (ipc_hdr->channel != IVPU_IPC_CHAN_BOOT_MSG) {
432 - jsm_msg = ivpu_to_cpu_addr(ipc->mem_rx, ipc_hdr->data_addr);
432 + jsm_msg = ivpu_to_cpu_addr(ipc->mem_rx, ipc_hdr->data_addr,
433 + sizeof(*jsm_msg));
433 434 if (!jsm_msg) {
434 435 ivpu_warn_ratelimited(vdev, "JSM msg 0x%x out of range\n",
435 436 ipc_hdr->data_addr);
modified drivers/accel/ivpu/ivpu_job.c
@@ -621,7 +621,6 @@ bool ivpu_job_handle_engine_error(struct ivpu_device *vdev, u32 job_id, u32 job_
621 621 * status and ensure both are handled in the same way
622 622 */
623 623 job->file_priv->has_mmu_faults = true;
624 - atomic_set(&vdev->faults_detected, 1);
625 624 queue_work(system_percpu_wq, &vdev->context_abort_work);
626 625 return true;
627 626 }
@@ -1175,10 +1174,10 @@ static int reset_engine_and_mark_faulty_contexts(struct ivpu_device *vdev)
1175 1174 return ret;
1176 1175
1177 1176 /*
1178 - * If faults are detected, ignore guilty contexts from engine reset as NPU may not be stuck
1179 - * and could return currently running good context and faulty contexts are already marked
1177 + * If job timeout is detected, read guilty context from engine reset, for other reasons
1178 + * faulty context is already known
1180 1179 */
1181 - if (atomic_cmpxchg(&vdev->faults_detected, 1, 0) == 1)
1180 + if (atomic_cmpxchg(&vdev->job_timeout_detected, 1, 0) == 0)
1182 1181 return 0;
1183 1182
1184 1183 num_impacted_contexts = resp.payload.engine_reset_done.num_impacted_contexts;
modified drivers/accel/ivpu/ivpu_mmu.c
@@ -964,7 +964,6 @@ void ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev)
964 964 file_priv = xa_load(&vdev->context_xa, ssid);
965 965 if (file_priv) {
966 966 if (!READ_ONCE(file_priv->has_mmu_faults)) {
967 - atomic_set(&vdev->faults_detected, 1);
968 967 ivpu_mmu_dump_event(vdev, event);
969 968 WRITE_ONCE(file_priv->has_mmu_faults, true);
970 969 }
modified drivers/accel/ivpu/ivpu_pm.c
@@ -229,6 +229,7 @@ abort:
229 229
230 230 ivpu_jsm_state_dump(vdev);
231 231 ivpu_dev_coredump(vdev);
232 + atomic_set(&vdev->job_timeout_detected, 1);
232 233 queue_work(system_percpu_wq, &vdev->context_abort_work);
233 234 }
234 235
modified drivers/accel/rocket/rocket_device.c
@@ -31,6 +31,8 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
31 31 if (of_device_is_available(core_node))
32 32 num_cores++;
33 33
34 + rdev->max_cores = num_cores;
35 +
34 36 rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
35 37 if (!rdev->cores)
36 38 return ERR_PTR(-ENOMEM);
modified drivers/accel/rocket/rocket_device.h
@@ -19,6 +19,7 @@ struct rocket_device {
19 19
20 20 struct rocket_core *cores;
21 21 unsigned int num_cores;
22 + unsigned int max_cores;
22 23 };
23 24
24 25 struct rocket_device *rocket_device_init(struct platform_device *pdev,
modified drivers/accel/rocket/rocket_drv.c
@@ -165,8 +165,11 @@ static int rocket_probe(struct platform_device *pdev)
165 165 /* First core probing, initialize DRM device. */
166 166 rdev = rocket_device_init(drm_dev, &rocket_drm_driver);
167 167 if (IS_ERR(rdev)) {
168 + int err = PTR_ERR(rdev);
169 +
168 170 dev_err(&pdev->dev, "failed to initialize rocket device\n");
169 - return PTR_ERR(rdev);
171 + rdev = NULL;
172 + return err;
170 173 }
171 174 }
172 175
@@ -223,7 +226,7 @@ static int find_core_for_dev(struct device *dev)
223 226 {
224 227 struct rocket_device *rdev = dev_get_drvdata(dev);
225 228
226 - for (unsigned int core = 0; core < rdev->num_cores; core++) {
229 + for (unsigned int core = 0; core < rdev->max_cores; core++) {
227 230 if (dev == rdev->cores[core].dev)
228 231 return core;
229 232 }
modified drivers/accel/rocket/rocket_job.c
@@ -283,7 +283,7 @@ static struct rocket_core *sched_to_core(struct rocket_device *rdev,
283 283 {
284 284 unsigned int core;
285 285
286 - for (core = 0; core < rdev->num_cores; core++) {
286 + for (core = 0; core < rdev->max_cores; core++) {
287 287 if (&rdev->cores[core].sched == sched)
288 288 return &rdev->cores[core];
289 289 }
modified drivers/accessibility/braille/braille_console.c
@@ -62,50 +62,14 @@ static void braille_write(u16 *buf)
62 62 {
63 63 static u16 lastwrite[WIDTH];
64 64 unsigned char data[1 + 1 + 2*WIDTH + 2 + 1], csum = 0, *c;
65 - struct nbcon_write_context wctxt = { };
66 - unsigned long flags;
67 65 u16 out;
68 66 int i;
69 67
70 68 if (!braille_co)
71 69 return;
72 70
73 - /*
74 - * Braille console is not registered in console_list. Instead, it
75 - * is integrated with VT and shows what appears on the graphical
76 - * console under console_lock(). From this POV it is a legacy
77 - * console. But it calls serial console driver which might be
78 - * converted to the NBCON API. It is similar to
79 - * nbcon_legacy_emit_next_record() except that we should try
80 - * harder to get the lock. Otherwise, the Braille device won't show
81 - * everything what is displayed on the terminal.
82 - *
83 - * In short, simulate the original locking using NBCON API.
84 - */
85 - if (braille_co->flags & CON_NBCON) {
86 - if (panic_on_this_cpu()) {
87 - /*
88 - * This should be good enough in practice. Most/all
89 - * serial console drivers have the atomic callback.
90 - */
91 - if (!braille_co->write_atomic)
92 - return;
93 -
94 - local_irq_save(flags);
95 - /* NBCON API strictly requires the ownership. */
96 - if (!nbcon_braille_try_acquire(braille_co, &wctxt)) {
97 - local_irq_restore(flags);
98 - return;
99 - }
100 - } else {
101 - braille_co->device_lock(braille_co, &flags);
102 - while (!nbcon_braille_try_acquire(braille_co, &wctxt))
103 - cpu_relax();
104 - }
105 - }
106 -
107 71 if (!memcmp(lastwrite, buf, WIDTH * sizeof(*buf)))
108 - goto unlock_nbcon;
72 + return;
109 73 memcpy(lastwrite, buf, WIDTH * sizeof(*buf));
110 74
111 75 #define SOH 1
@@ -138,24 +102,7 @@ static void braille_write(u16 *buf)
138 102 *c++ = csum;
139 103 *c++ = ETX;
140 104
141 - if (braille_co->flags & CON_NBCON) {
142 - nbcon_write_context_set_buf(&wctxt, (char *)data, c - data);
143 - if (panic_on_this_cpu())
144 - braille_co->write_atomic(braille_co, &wctxt);
145 - else
146 - braille_co->write_thread(braille_co, &wctxt);
147 - } else {
148 - braille_co->write(braille_co, data, c - data);
149 - }
150 -
151 - unlock_nbcon:
152 - if (braille_co->flags & CON_NBCON) {
153 - nbcon_braille_release(&wctxt);
154 - if (panic_on_this_cpu())
155 - local_irq_restore(flags);
156 - else
157 - braille_co->device_unlock(braille_co, flags);
158 - }
105 + braille_co->write(braille_co, data, c - data);
159 106 }
160 107
161 108 /* Follow the VC cursor*/
modified drivers/block/sunvdc.c
@@ -525,6 +525,23 @@ static int __send_request(struct request *req)
525 525 err = __vdc_tx_trigger(port);
526 526 if (err < 0) {
527 527 printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err);
528 + /*
529 + * If the port was reset (-ENOTCONN), the dring and the
530 + * LDC channel including all of its mappings are already
531 + * torn down and reallocated - there is nothing to undo
532 + * and @desc must not be touched.
533 + *
534 + * For any other failure the descriptor was never handed
535 + * to the peer: unmap the cookies and free the descriptor
536 + * again, so that a later retry of the request does not
537 + * leak LDC map table entries.
538 + */
539 + if (err != -ENOTCONN) {
540 + ldc_unmap(port->vio.lp, desc->cookies,
541 + desc->ncookies);
542 + desc->hdr.state = VIO_DESC_FREE;
543 + rqe->req = NULL;
544 + }
528 545 } else {
529 546 port->req_id++;
530 547 dr->prod = vio_dring_next(dr, dr->prod);
@@ -539,6 +556,7 @@ static blk_status_t vdc_queue_rq(struct blk_mq_hw_ctx *hctx,
539 556 struct vdc_port *port = hctx->queue->queuedata;
540 557 struct vio_dring_state *dr;
541 558 unsigned long flags;
559 + int ret;
542 560
543 561 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
544 562
@@ -560,7 +578,13 @@ static blk_status_t vdc_queue_rq(struct blk_mq_hw_ctx *hctx,
560 578 return BLK_STS_DEV_RESOURCE;
561 579 }
562 580
563 - if (__send_request(bd->rq) < 0) {
581 + ret = __send_request(bd->rq);
582 + if (ret == -EAGAIN) {
583 + spin_unlock_irqrestore(&port->vio.lock, flags);
584 + /* already spun for 10msec, defer 10msec and retry */
585 + blk_mq_delay_kick_requeue_list(hctx->queue, 10);
586 + return BLK_STS_DEV_RESOURCE;
587 + } else if (ret < 0) {
564 588 spin_unlock_irqrestore(&port->vio.lock, flags);
565 589 return BLK_STS_IOERR;
566 590 }
modified drivers/block/ublk_drv.c
@@ -3030,6 +3030,7 @@ static void ublk_queue_reset_io_flags(struct ublk_queue *ubq)
3030 3030 ubq->canceling = false;
3031 3031 spin_unlock(&ubq->cancel_lock);
3032 3032 ubq->fail_io = false;
3033 + ubq->force_abort = false;
3033 3034 }
3034 3035
3035 3036 /* device can only be started after all IOs are ready */
modified drivers/bluetooth/btintel_pcie.c
@@ -1099,7 +1099,7 @@ static void btintel_pcie_msix_tx_handle(struct btintel_pcie_data *data)
1099 1099
1100 1100 urbd0 = &txq->urbd0s[cr_tia];
1101 1101
1102 - if (urbd0->tfd_index > txq->count)
1102 + if (urbd0->tfd_index >= txq->count)
1103 1103 return;
1104 1104
1105 1105 cr_tia = (cr_tia + 1) % txq->count;
@@ -1599,7 +1599,9 @@ static int btintel_pcie_submit_rx_work(struct btintel_pcie_data *data, u8 status
1599 1599 rfh_hdr = buf;
1600 1600
1601 1601 len = rfh_hdr->packet_len;
1602 - if (len <= 0) {
1602 + if (len == 0 || len > BTINTEL_PCIE_BUFFER_SIZE - sizeof(*rfh_hdr)) {
1603 + bt_dev_err(data->hdev, "Invalid packet_len %d (max %zu)", len,
1604 + BTINTEL_PCIE_BUFFER_SIZE - sizeof(*rfh_hdr));
1603 1605 ret = -EINVAL;
1604 1606 goto resubmit;
1605 1607 }
modified drivers/bluetooth/btmtk.c
@@ -1374,16 +1374,6 @@ int btmtk_usb_setup(struct hci_dev *hdev)
1374 1374 break;
1375 1375 case 0x7922:
1376 1376 case 0x7925:
1377 - /*
1378 - * A remote wakeup could cause the device completely unresponsive, and
1379 - * recovering from such a state needs a power cycle.
1380 - *
1381 - * Since the remote wakeup capability is super broken, just disable it
1382 - * to get rid of the troubles. The device can still be autosuspended
1383 - * when the bluetooth interface is closed.
1384 - */
1385 - device_set_wakeup_capable(&btmtk_data->udev->dev, false);
1386 - fallthrough;
1387 1377 case 0x7961:
1388 1378 case 0x7902:
1389 1379 case 0x6639:
@@ -1587,5 +1577,6 @@ MODULE_FIRMWARE(FIRMWARE_MT7663);
1587 1577 MODULE_FIRMWARE(FIRMWARE_MT7668);
1588 1578 MODULE_FIRMWARE(FIRMWARE_MT7922);
1589 1579 MODULE_FIRMWARE(FIRMWARE_MT7961);
1580 + MODULE_FIRMWARE(FIRMWARE_MT7920);
1590 1581 MODULE_FIRMWARE(FIRMWARE_MT7925);
1591 1582 MODULE_FIRMWARE(FIRMWARE_MT7927);
modified drivers/bluetooth/btmtk.h
@@ -7,6 +7,7 @@
7 7 #define FIRMWARE_MT7922 "mediatek/BT_RAM_CODE_MT7922_1_1_hdr.bin"
8 8 #define FIRMWARE_MT7902 "mediatek/BT_RAM_CODE_MT7902_1_1_hdr.bin"
9 9 #define FIRMWARE_MT7961 "mediatek/BT_RAM_CODE_MT7961_1_2_hdr.bin"
10 + #define FIRMWARE_MT7920 "mediatek/BT_RAM_CODE_MT7961_1a_2_hdr.bin"
10 11 #define FIRMWARE_MT7925 "mediatek/mt7925/BT_RAM_CODE_MT7925_1_1_hdr.bin"
11 12 #define FIRMWARE_MT7927 "mediatek/mt7927/BT_RAM_CODE_MT6639_2_1_hdr.bin"
12 13
modified drivers/bluetooth/btqcomsmd.c
@@ -188,7 +188,10 @@ static int btqcomsmd_probe(struct platform_device *pdev)
188 188 return 0;
189 189
190 190 hci_free_dev:
191 + rpmsg_destroy_ept(btq->cmd_channel);
192 + rpmsg_destroy_ept(btq->acl_channel);
191 193 hci_free_dev(hdev);
194 + return ret;
192 195 destroy_cmd_channel:
193 196 rpmsg_destroy_ept(btq->cmd_channel);
194 197 destroy_acl_channel:
@@ -202,10 +205,11 @@ static void btqcomsmd_remove(struct platform_device *pdev)
202 205 struct btqcomsmd *btq = platform_get_drvdata(pdev);
203 206
204 207 hci_unregister_dev(btq->hdev);
205 - hci_free_dev(btq->hdev);
206 208
207 209 rpmsg_destroy_ept(btq->cmd_channel);
208 210 rpmsg_destroy_ept(btq->acl_channel);
211 +
212 + hci_free_dev(btq->hdev);
209 213 }
210 214
211 215 static const struct of_device_id btqcomsmd_of_match[] = {
modified drivers/bluetooth/btrtl.c
@@ -591,7 +591,7 @@ static int rtlbt_parse_firmware_v2(struct hci_dev *hdev,
591 591 * headers.
592 592 */
593 593 if (!key_id)
594 - break;
594 + continue;
595 595 rc = btrtl_parse_section(hdev, btrtl_dev, opcode,
596 596 ptr, section_len);
597 597 break;
@@ -600,8 +600,7 @@ static int rtlbt_parse_firmware_v2(struct hci_dev *hdev,
600 600 ptr, section_len);
601 601 break;
602 602 default:
603 - rc = 0;
604 - break;
603 + continue;
605 604 }
606 605 if (rc < 0) {
607 606 rtl_dev_err(hdev, "RTL: Parse section (%u) err %d",
modified drivers/bluetooth/btusb.c
@@ -6,6 +6,7 @@
6 6 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
7 7 */
8 8
9 + #include <linux/cpufeature.h>
9 10 #include <linux/dmi.h>
10 11 #include <linux/module.h>
11 12 #include <linux/usb.h>
@@ -980,6 +981,8 @@ struct btqca_data {
980 981 #define BTUSB_USE_ALT3_FOR_WBS 15
981 982 #define BTUSB_ALT6_CONTINUOUS_TX 16
982 983 #define BTUSB_HW_SSR_ACTIVE 17
984 + #define BTUSB_WAKEUP_BROKEN 18
985 + #define BTUSB_RESET 19
983 986
984 987 struct btusb_data {
985 988 struct hci_dev *hdev;
@@ -1054,13 +1057,15 @@ static void btusb_reset(struct hci_dev *hdev)
1054 1057 int err;
1055 1058
1056 1059 data = hci_get_drvdata(hdev);
1057 - /* This is not an unbalanced PM reference since the device will reset */
1058 1060 err = usb_autopm_get_interface(data->intf);
1059 1061 if (err) {
1060 1062 bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
1061 1063 return;
1062 1064 }
1063 1065
1066 + if (test_and_set_bit(BTUSB_RESET, &data->flags))
1067 + usb_autopm_put_interface_no_suspend(data->intf);
1068 +
1064 1069 bt_dev_err(hdev, "Resetting usb device.");
1065 1070 usb_queue_reset_device(data->intf);
1066 1071 }
@@ -2092,18 +2097,24 @@ static int btusb_close(struct hci_dev *hdev)
2092 2097
2093 2098 BT_DBG("%s", hdev->name);
2094 2099
2095 - cancel_delayed_work(&data->rx_work);
2096 2100 cancel_work_sync(&data->work);
2097 2101 cancel_work_sync(&data->waker);
2098 2102
2099 - skb_queue_purge(&data->acl_q);
2100 -
2101 2103 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
2102 2104 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
2103 2105 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
2104 2106 clear_bit(BTUSB_DIAG_RUNNING, &data->flags);
2105 2107
2106 2108 btusb_stop_traffic(data);
2109 +
2110 + /* rx_work must only be canceled once the URBs that can rearm it are
2111 + * gone, and it must be canceled synchronously since btusb_disconnect()
2112 + * frees the btusb_data it dereferences right after hci_unregister_dev().
2113 + */
2114 + cancel_delayed_work_sync(&data->rx_work);
2115 +
2116 + skb_queue_purge(&data->acl_q);
2117 +
2107 2118 btusb_free_frags(data);
2108 2119
2109 2120 err = usb_autopm_get_interface(data->intf);
@@ -2129,7 +2140,7 @@ static int btusb_flush(struct hci_dev *hdev)
2129 2140
2130 2141 BT_DBG("%s", hdev->name);
2131 2142
2132 - cancel_delayed_work(&data->rx_work);
2143 + cancel_delayed_work_sync(&data->rx_work);
2133 2144
2134 2145 skb_queue_purge(&data->acl_q);
2135 2146
@@ -2923,8 +2934,11 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
2923 2934 }
2924 2935
2925 2936 err = usb_autopm_get_interface(data->intf);
2926 - if (err < 0)
2937 + if (err < 0) {
2938 + bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
2939 + clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags);
2927 2940 return err;
2941 + }
2928 2942
2929 2943 /* Release MediaTek ISO data interface */
2930 2944 btusb_mtk_release_iso_intf(hdev);
@@ -2946,6 +2960,11 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
2946 2960
2947 2961 err = btmtk_usb_subsys_reset(hdev, btmtk_data->dev_id);
2948 2962
2963 + if (test_and_set_bit(BTUSB_RESET, &data->flags)) {
2964 + bt_dev_err(hdev, "last usb reset failed? Resetting again");
2965 + usb_autopm_put_interface_no_suspend(data->intf);
2966 + }
2967 +
2949 2968 usb_queue_reset_device(data->intf);
2950 2969 clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags);
2951 2970
@@ -2969,10 +2988,25 @@ static int btusb_send_frame_mtk(struct hci_dev *hdev, struct sk_buff *skb)
2969 2988 }
2970 2989 }
2971 2990
2991 + static inline bool platform_is_ryzen(void)
2992 + {
2993 + #ifdef CONFIG_X86
2994 + return boot_cpu_has(X86_FEATURE_ZEN);
2995 + #else
2996 + return false;
2997 + #endif
2998 + }
2999 +
3000 + static inline bool is_direct_child_of_root_hub(struct usb_device *udev)
3001 + {
3002 + return udev->parent == udev->bus->root_hub;
3003 + }
3004 +
2972 3005 static int btusb_mtk_setup(struct hci_dev *hdev)
2973 3006 {
2974 3007 struct btusb_data *data = hci_get_drvdata(hdev);
2975 3008 struct btmtk_data *btmtk_data = hci_get_priv(hdev);
3009 + int err;
2976 3010
2977 3011 /* MediaTek WMT vendor cmd requiring below USB resources to
2978 3012 * complete the handshake.
@@ -2989,7 +3023,40 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
2989 3023 btusb_mtk_claim_iso_intf(data);
2990 3024 }
2991 3025
2992 - return btmtk_usb_setup(hdev);
3026 + err = btmtk_usb_setup(hdev);
3027 + if (err)
3028 + return err;
3029 +
3030 + switch (btmtk_data->dev_id) {
3031 + case 0x7922:
3032 + case 0x7925:
3033 + /*
3034 + * All reports seen to be relevant to Ryzen-based laptops. These
3035 + * NICs are usually used as OEM components thanks to some sort
3036 + * of reference designs.
3037 + *
3038 + * Their popularity on other platforms is unclear. While there
3039 + * is still a chance that the quirk may exist on other
3040 + * platforms, be cautious and only apply the quirk to direct
3041 + * children of Ryzen platforms's root hubs for the time being.
3042 + *
3043 + * In most cases the root hub is on the SoC or PCH, which needs
3044 + * the quirk. Unfortunately, this can't distinguish root hubs on
3045 + * PCIe add-in cards. Such roughness should be acceptable, as
3046 + * PCIe USB controller add-in cards are less commonly used
3047 + * nowadays. On the other hand, applying the quirk doesn't hurt
3048 + * any functionalities either, as the device can still be used
3049 + * as a wakeup source if desired.
3050 + *
3051 + * Theoretically, we could retrieve the root hub's PCI vendor ID
3052 + * with some hierarchy magic, but that's too intrusive...
3053 + */
3054 + if (platform_is_ryzen() && is_direct_child_of_root_hub(data->udev))
3055 + set_bit(BTUSB_WAKEUP_BROKEN, &data->flags);
3056 + break;
3057 + }
3058 +
3059 + return 0;
2993 3060 }
2994 3061
2995 3062 static int btusb_mtk_shutdown(struct hci_dev *hdev)
@@ -4540,6 +4607,9 @@ static void btusb_disconnect(struct usb_interface *intf)
4540 4607 if (data->reset_gpio)
4541 4608 gpiod_put(data->reset_gpio);
4542 4609
4610 + if (test_and_clear_bit(BTUSB_RESET, &data->flags))
4611 + usb_autopm_put_interface_no_suspend(data->intf);
4612 +
4543 4613 if (intf == data->intf) {
4544 4614 if (data->isoc)
4545 4615 usb_driver_release_interface(&btusb_driver, data->isoc);
@@ -4565,11 +4635,26 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
4565 4635
4566 4636 BT_DBG("intf %p", intf);
4567 4637
4568 - /* Don't auto-suspend if there are connections or discovery in
4569 - * progress; external suspend calls shall never fail.
4638 + /*
4639 + * It is reported that remote wakeup events could sometimes cause some
4640 + * adapters completely unresponsive. Resetting the xHCI root hub doesn't
4641 + * help at all, and recovering from such a state needs a power cycle.
4642 + * Since disabling remote wakeup simply causes the USB core to gate
4643 + * runtime autosuspend as well due to needs_remote_wakeup == 1, let's do
4644 + * this ourselves to make our life easier. The interface can be safely
4645 + * autosuspended as long as remote wakeup is disabled, i.e., after
4646 + * closing the HCI device.
4647 + *
4648 + * Don't auto-suspend if there are connections or discovery in progress.
4649 + *
4650 + * External suspend calls shall never fail. Specifically, a device with
4651 + * broken remote wakeup may still take the advantage of remote wakeup in
4652 + * order to wake up the system from sleep if userspace has enabled it as
4653 + * a wakeup source.
4570 4654 */
4571 4655 if (PMSG_IS_AUTO(message) &&
4572 - (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
4656 + ((test_bit(BTUSB_WAKEUP_BROKEN, &data->flags) && data->intf->needs_remote_wakeup) ||
4657 + hci_conn_count(data->hdev) || hci_discovery_active(data->hdev)))
4573 4658 return -EBUSY;
4574 4659
4575 4660 if (data->suspend_count++)
modified drivers/char/virtio_console.c
@@ -1964,13 +1964,28 @@ static const struct file_operations portdev_fops = {
1964 1964 static void remove_vqs(struct ports_device *portdev)
1965 1965 {
1966 1966 struct virtqueue *vq;
1967 + bool multiport = use_multiport(portdev);
1967 1968
1968 1969 virtio_device_for_each_vq(portdev->vdev, vq) {
1969 1970 struct port_buffer *buf;
1971 + unsigned int len;
1970 1972
1971 - flush_bufs(vq, true);
1972 - while ((buf = virtqueue_detach_unused_buf(vq)))
1973 - free_buf(buf, true);
1973 + /*
1974 + * c_ovq cookies are &portdev->cpkt, not port_buffer.
1975 + * Detach them but do not free_buf().
1976 + */
1977 + if (multiport && vq == portdev->c_ovq) {
1978 + spin_lock(&portdev->c_ovq_lock);
1979 + while (virtqueue_get_buf(vq, &len))
1980 + ;
1981 + while (virtqueue_detach_unused_buf(vq))
1982 + ;
1983 + spin_unlock(&portdev->c_ovq_lock);
1984 + } else {
1985 + flush_bufs(vq, true);
1986 + while ((buf = virtqueue_detach_unused_buf(vq)))
1987 + free_buf(buf, true);
1988 + }
1974 1989 cond_resched();
1975 1990 }
1976 1991 portdev->vdev->config->del_vqs(portdev->vdev);
modified drivers/cpufreq/cpufreq.c
@@ -1249,7 +1249,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1249 1249 if (!policy)
1250 1250 return NULL;
1251 1251
1252 - if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1252 + if (!zalloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1253 1253 goto err_free_policy;
1254 1254
1255 1255 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
@@ -1258,6 +1258,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1258 1258 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1259 1259 goto err_free_rcpumask;
1260 1260
1261 + init_rwsem(&policy->rwsem);
1262 +
1261 1263 init_completion(&policy->kobj_unregister);
1262 1264 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
1263 1265 cpufreq_global_kobject, "policy%u", cpu);
@@ -1272,8 +1274,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1272 1274 goto err_free_real_cpus;
1273 1275 }
1274 1276
1275 - init_rwsem(&policy->rwsem);
1276 -
1277 1277 freq_constraints_init(&policy->constraints);
1278 1278
1279 1279 policy->nb_min.notifier_call = cpufreq_notifier_min;
modified drivers/dibs/dibs_main.c
@@ -251,13 +251,19 @@ static int __init dibs_init(void)
251 251
252 252 rc = class_register(&dibs_class);
253 253 if (rc)
254 - return rc;
254 + goto err;
255 255
256 256 rc = dibs_loopback_init();
257 257 if (rc)
258 - pr_err("%s fails with %d\n", __func__, rc);
258 + goto err_unregister;
259 259
260 260 return rc;
261 +
262 + err_unregister:
263 + class_unregister(&dibs_class);
264 + err:
265 + pr_err("%s fails with %d\n", __func__, rc);
266 + return rc;
261 267 }
262 268
263 269 static void __exit dibs_exit(void)
modified drivers/dma-buf/dma-buf-mapping.c
@@ -5,16 +5,18 @@
5 5 */
6 6 #include <linux/dma-buf-mapping.h>
7 7 #include <linux/dma-resv.h>
8 + #include <linux/overflow.h>
9 + #include <linux/align.h>
10 +
11 + #define MAX_SG_ENT_SZ ALIGN_DOWN(UINT_MAX, PAGE_SIZE)
8 12
9 13 static struct scatterlist *fill_sg_entry(struct scatterlist *sgl, size_t length,
10 14 dma_addr_t addr)
11 15 {
12 - unsigned int len, nents;
13 - int i;
16 + size_t len;
14 17
15 - nents = DIV_ROUND_UP(length, UINT_MAX);
16 - for (i = 0; i < nents; i++) {
17 - len = min_t(size_t, length, UINT_MAX);
18 + while (length) {
19 + len = min(length, MAX_SG_ENT_SZ);
18 20 length -= len;
19 21 /*
20 22 * DMABUF abuses scatterlist to create a scatterlist
@@ -24,8 +26,10 @@ static struct scatterlist *fill_sg_entry(struct scatterlist *sgl, size_t length,
24 26 * does not require the CPU list for mapping or unmapping.
25 27 */
26 28 sg_set_page(sgl, NULL, 0, 0);
27 - sg_dma_address(sgl) = addr + (dma_addr_t)i * UINT_MAX;
29 + sg_dma_address(sgl) = addr;
28 30 sg_dma_len(sgl) = len;
31 + addr += len;
32 + /* Unconditionally advance. On last segment, this becomes NULL */
29 33 sgl = sg_next(sgl);
30 34 }
31 35
@@ -40,15 +44,19 @@ static unsigned int calc_sg_nents(struct dma_iova_state *state,
40 44 size_t i;
41 45
42 46 if (!state || !dma_use_iova(state)) {
43 - for (i = 0; i < nr_ranges; i++)
44 - nents += DIV_ROUND_UP(phys_vec[i].len, UINT_MAX);
47 + for (i = 0; i < nr_ranges; i++) {
48 + unsigned int added = DIV_ROUND_UP(phys_vec[i].len, MAX_SG_ENT_SZ);
49 +
50 + if (check_add_overflow(nents, added, &nents))
51 + return 0;
52 + }
45 53 } else {
46 54 /*
47 55 * In IOVA case, there is only one SG entry which spans
48 56 * for whole IOVA address space, but we need to make sure
49 57 * that it fits sg->length, maybe we need more.
50 58 */
51 - nents = DIV_ROUND_UP(size, UINT_MAX);
59 + nents = DIV_ROUND_UP(size, MAX_SG_ENT_SZ);
52 60 }
53 61
54 62 return nents;
@@ -95,9 +103,10 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
95 103 size_t nr_ranges, size_t size,
96 104 enum dma_data_direction dir)
97 105 {
98 - unsigned int nents, mapped_len = 0;
99 106 struct dma_buf_dma *dma;
100 107 struct scatterlist *sgl;
108 + size_t mapped_len = 0;
109 + unsigned int nents;
101 110 dma_addr_t addr;
102 111 size_t i;
103 112 int ret;
@@ -133,6 +142,8 @@ struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
133 142 }
134 143
135 144 nents = calc_sg_nents(dma->state, phys_vec, nr_ranges, size);
145 +
146 + /* sg_alloc_table will cleanly fail and return -EINVAL if nents == 0 */
136 147 ret = sg_alloc_table(&dma->sgt, nents, GFP_KERNEL | __GFP_ZERO);
137 148 if (ret)
138 149 goto err_free_state;
modified drivers/dma-buf/dma-fence.c
@@ -1170,7 +1170,12 @@ const char __rcu *dma_fence_driver_name(struct dma_fence *fence)
1170 1170
1171 1171 /* RCU protection is required for safe access to returned string */
1172 1172 ops = rcu_dereference(fence->ops);
1173 - if (ops)
1173 +
1174 + /*
1175 + * Make load ordering irrelevant by checking both signaled state and ops
1176 + * pointer and ops pointer is only set to NULL on newer implementations.
1177 + */
1178 + if (!dma_fence_test_signaled_flag(fence) && ops)
1174 1179 return (const char __rcu *)ops->get_driver_name(fence);
1175 1180 else
1176 1181 return (const char __rcu *)"detached-driver";
@@ -1203,7 +1208,12 @@ const char __rcu *dma_fence_timeline_name(struct dma_fence *fence)
1203 1208
1204 1209 /* RCU protection is required for safe access to returned string */
1205 1210 ops = rcu_dereference(fence->ops);
1206 - if (ops)
1211 +
1212 + /*
1213 + * Make load ordering irrelevant by checking both signaled state and ops
1214 + * pointer and ops pointer is only set to NULL on newer implementations.
1215 + */
1216 + if (!dma_fence_test_signaled_flag(fence) && ops)
1207 1217 return (const char __rcu *)ops->get_timeline_name(fence);
1208 1218 else
1209 1219 return (const char __rcu *)"signaled-timeline";
modified drivers/edac/altera_edac.c
@@ -1534,7 +1534,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1534 1534 altdev = dci->pvt_info;
1535 1535 *altdev = *device;
1536 1536
1537 - if (!devres_open_group(&altdev->ddev, altr_portb_setup, GFP_KERNEL))
1537 + if (!devres_open_group(device->edac->dev, altr_portb_setup, GFP_KERNEL))
1538 1538 return -ENOMEM;
1539 1539
1540 1540 /* Update PortB specific values */
@@ -1562,7 +1562,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1562 1562 rc = -ENODEV;
1563 1563 goto err_release_group_1;
1564 1564 }
1565 - rc = devm_request_irq(&altdev->ddev, altdev->sb_irq,
1565 + rc = devm_request_irq(device->edac->dev, altdev->sb_irq,
1566 1566 prv->ecc_irq_handler, IRQF_TRIGGER_HIGH,
1567 1567 ecc_name, altdev);
1568 1568 if (rc) {
@@ -1584,7 +1584,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1584 1584 rc = -ENODEV;
1585 1585 goto err_release_group_1;
1586 1586 }
1587 - rc = devm_request_irq(&altdev->ddev, altdev->db_irq,
1587 + rc = devm_request_irq(device->edac->dev, altdev->db_irq,
1588 1588 prv->ecc_irq_handler, IRQF_TRIGGER_HIGH,
1589 1589 ecc_name, altdev);
1590 1590 if (rc) {
@@ -1604,13 +1604,13 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)
1604 1604
1605 1605 list_add(&altdev->next, &altdev->edac->a10_ecc_devices);
1606 1606
1607 - devres_remove_group(&altdev->ddev, altr_portb_setup);
1607 + devres_remove_group(device->edac->dev, altr_portb_setup);
1608 1608
1609 1609 return 0;
1610 1610
1611 1611 err_release_group_1:
1612 1612 edac_device_free_ctl_info(dci);
1613 - devres_release_group(&altdev->ddev, altr_portb_setup);
1613 + devres_release_group(device->edac->dev, altr_portb_setup);
1614 1614 edac_printk(KERN_ERR, EDAC_DEVICE,
1615 1615 "%s:Error setting up EDAC device: %d\n", ecc_name, rc);
1616 1616 return rc;
modified drivers/gpu/drm/adp/Kconfig
@@ -6,7 +6,6 @@ config DRM_ADP
6 6 select DRM_KMS_HELPER
7 7 select DRM_BRIDGE_CONNECTOR
8 8 select DRM_DISPLAY_HELPER
9 - select DRM_KMS_DMA_HELPER
10 9 select DRM_GEM_DMA_HELPER
11 10 select DRM_PANEL_BRIDGE
12 11 select VIDEOMODE_HELPERS
modified drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -1701,9 +1701,8 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
1701 1701 if (dma_resv_trylock(bo->tbo.base.resv)) {
1702 1702 dma_resv_describe(bo->tbo.base.resv, m);
1703 1703 dma_resv_unlock(bo->tbo.base.resv);
1704 - } else {
1705 - seq_puts(m, "\n");
1706 1704 }
1705 + seq_puts(m, "\n");
1707 1706
1708 1707 return size;
1709 1708 }
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -191,6 +191,8 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_ttm_buffer_entit
191 191 * @tmz: if we should setup a TMZ enabled mapping
192 192 * @size: in number of bytes to map, out number of bytes mapped
193 193 * @addr: resulting address inside the MC address space
194 + * @vm_needs_flush: out, set true if a GART window was programmed (VMID 0 flush
195 + * needed) or false for a direct address
194 196 *
195 197 * Setup one of the GART windows to access a specific piece of memory or return
196 198 * the physical address for local memory.
@@ -200,7 +202,8 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,
200 202 struct ttm_resource *mem,
201 203 struct amdgpu_res_cursor *mm_cur,
202 204 unsigned int window,
203 - bool tmz, uint64_t *size, uint64_t *addr)
205 + bool tmz, uint64_t *size, uint64_t *addr,
206 + bool *vm_needs_flush)
204 207 {
205 208 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
206 209 unsigned int offset, num_pages, num_dw, num_bytes;
@@ -221,9 +224,12 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,
221 224 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
222 225 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
223 226 mm_cur->start;
227 + *vm_needs_flush = false;
224 228 return 0;
225 229 }
226 230
231 + /* A GART window is programmed below, so its VMID 0 TLB needs a flush */
232 + *vm_needs_flush = true;
227 233
228 234 /*
229 235 * If start begins at an offset inside the page, then adjust the size
@@ -324,6 +330,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
324 330 while (src_mm.remaining) {
325 331 uint64_t from, to, cur_size, tiling_flags;
326 332 uint32_t num_type, data_format, max_com, write_compress_disable;
333 + bool src_vm_flush, dst_vm_flush;
327 334 struct dma_fence *next;
328 335
329 336 /* Never copy more than 256MiB at once to avoid a timeout */
@@ -331,12 +338,12 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
331 338
332 339 /* Map src to window 0 and dst to window 1. */
333 340 r = amdgpu_ttm_map_buffer(entity, src->bo, src->mem, &src_mm,
334 - 0, tmz, &cur_size, &from);
341 + 0, tmz, &cur_size, &from, &src_vm_flush);
335 342 if (r)
336 343 goto error;
337 344
338 345 r = amdgpu_ttm_map_buffer(entity, dst->bo, dst->mem, &dst_mm,
339 - 1, tmz, &cur_size, &to);
346 + 1, tmz, &cur_size, &to, &dst_vm_flush);
340 347 if (r)
341 348 goto error;
342 349
@@ -364,7 +371,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
364 371 }
365 372
366 373 r = amdgpu_copy_buffer(adev, entity, from, to, cur_size, resv,
367 - &next, true, copy_flags);
374 + &next, src_vm_flush || dst_vm_flush, copy_flags);
368 375 if (r)
369 376 goto error;
370 377
@@ -2624,6 +2631,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,
2624 2631 struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
2625 2632 struct dma_fence *fence = NULL;
2626 2633 struct amdgpu_res_cursor dst;
2634 + bool vm_needs_flush = false;
2627 2635 int r;
2628 2636
2629 2637 if (!entity)
@@ -2645,13 +2653,13 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_ttm_buffer_entity *entity,
2645 2653 cur_size = min(dst.size, 256ULL << 20);
2646 2654
2647 2655 r = amdgpu_ttm_map_buffer(entity, &bo->tbo, bo->tbo.resource, &dst,
2648 - 0, false, &cur_size, &to);
2656 + 0, false, &cur_size, &to, &vm_needs_flush);
2649 2657 if (r)
2650 2658 goto error;
2651 2659
2652 2660 r = amdgpu_ttm_fill_mem(adev, entity,
2653 2661 0, to, cur_size, resv,
2654 - &next, true, k_job_id);
2662 + &next, vm_needs_flush, k_job_id);
2655 2663 if (r)
2656 2664 goto error;
2657 2665
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -747,9 +747,9 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
747 747 }
748 748 if (adev->dm.dc->caps.max_links > 0) {
749 749 adev->dm.hdmi_frl_status_polling_wq =
750 - create_singlethread_workqueue("hdmi_frl_status_polling_workqueue");
750 + create_singlethread_workqueue("hdmi_frl_status_polling_wq");
751 751 if (!adev->dm.hdmi_frl_status_polling_wq)
752 - drm_err(adev_to_drm(adev), "failed to initialize hdmi_frl_status_polling_workqueue\n");
752 + drm_err(adev_to_drm(adev), "failed to initialize hdmi_frl_status_polling_wq\n");
753 753 }
754 754 if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
755 755 init_completion(&adev->dm.dmub_aux_transfer_done);
@@ -1972,6 +1972,10 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
1972 1972 /* On resume we need to rewrite the MSTM control bits to enable MST*/
1973 1973 s3_handle_mst(ddev, false);
1974 1974
1975 + /* Exit IPS before the detection loop's first AUX/DDC access. */
1976 + scoped_guard(mutex, &dm->dc_lock)
1977 + dc_exit_ips_for_hw_access(dm->dc);
1978 +
1975 1979 /* Do detection*/
1976 1980 drm_connector_list_iter_begin(ddev, &iter);
1977 1981 drm_for_each_connector_iter(connector, &iter) {
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -756,10 +756,14 @@ amdgpu_dm_get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing,
756 756 break;
757 757 case DRM_MODE_COLORIMETRY_BT2020_RGB:
758 758 case DRM_MODE_COLORIMETRY_BT2020_YCC:
759 - if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB)
760 - color_space = COLOR_SPACE_2020_RGB_FULLRANGE;
761 - else
759 + if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) {
760 + if (connector_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED)
761 + color_space = COLOR_SPACE_2020_RGB_LIMITEDRANGE;
762 + else
763 + color_space = COLOR_SPACE_2020_RGB_FULLRANGE;
764 + } else {
762 765 color_space = COLOR_SPACE_2020_YCBCR_LIMITED;
766 + }
763 767 break;
764 768 case DRM_MODE_COLORIMETRY_DEFAULT: /* ITU601 */
765 769 default:
@@ -3937,17 +3941,15 @@ void amdgpu_dm_update_freesync_caps(struct drm_connector *connector,
3937 3941 }
3938 3942
3939 3943 /* Handle MCCS */
3940 - if (do_mccs)
3944 + if (do_mccs) {
3941 3945 dm_helpers_read_mccs_caps(adev->dm.dc->ctx, amdgpu_dm_connector->dc_link, sink);
3942 3946
3943 - if ((sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A ||
3944 - as_type == FREESYNC_TYPE_PCON_IN_WHITELIST) &&
3945 - (!sink->edid_caps.freesync_vcp_code ||
3946 - (sink->edid_caps.freesync_vcp_code && !sink->mccs_caps.freesync_supported)))
3947 - freesync_capable = false;
3947 + if (sink->edid_caps.freesync_vcp_code && !sink->mccs_caps.freesync_supported)
3948 + freesync_capable = false;
3948 3949
3949 - if (do_mccs && sink->mccs_caps.freesync_supported && freesync_capable)
3950 - dm_helpers_mccs_vcp_set(adev->dm.dc->ctx, amdgpu_dm_connector->dc_link, sink);
3950 + if (sink->mccs_caps.freesync_supported && freesync_capable)
3951 + dm_helpers_mccs_vcp_set(adev->dm.dc->ctx, amdgpu_dm_connector->dc_link, sink);
3952 + }
3951 3953
3952 3954 update:
3953 3955 if (dm_con_state)
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c
@@ -196,7 +196,6 @@ static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
196 196 char *rd_buf_ptr = NULL;
197 197 const uint32_t rd_buf_size = 100;
198 198 uint32_t result = 0;
199 - uint8_t str_len = 0;
200 199 int r;
201 200
202 201 if (*pos & 3 || size & 3)
@@ -208,29 +207,26 @@ static ssize_t dp_link_settings_read(struct file *f, char __user *buf,
208 207
209 208 rd_buf_ptr = rd_buf;
210 209
211 - str_len = strlen("Current: %d 0x%x %d ");
212 - snprintf(rd_buf_ptr, str_len, "Current: %d 0x%x %d ",
210 + rd_buf_ptr += scnprintf(rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf),
211 + "Current: %d 0x%x %d ",
213 212 link->cur_link_settings.lane_count,
214 213 link->cur_link_settings.link_rate,
215 214 link->cur_link_settings.link_spread);
216 - rd_buf_ptr += str_len;
217 215
218 - str_len = strlen("Verified: %d 0x%x %d ");
219 - snprintf(rd_buf_ptr, str_len, "Verified: %d 0x%x %d ",
216 + rd_buf_ptr += scnprintf(rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf),
217 + "Verified: %d 0x%x %d ",
220 218 link->verified_link_cap.lane_count,
221 219 link->verified_link_cap.link_rate,
222 220 link->verified_link_cap.link_spread);
223 - rd_buf_ptr += str_len;
224 221
225 - str_len = strlen("Reported: %d 0x%x %d ");
226 - snprintf(rd_buf_ptr, str_len, "Reported: %d 0x%x %d ",
222 + rd_buf_ptr += scnprintf(rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf),
223 + "Reported: %d 0x%x %d ",
227 224 link->reported_link_cap.lane_count,
228 225 link->reported_link_cap.link_rate,
229 226 link->reported_link_cap.link_spread);
230 - rd_buf_ptr += str_len;
231 227
232 - str_len = strlen("Preferred: %d 0x%x %d ");
233 - snprintf(rd_buf_ptr, str_len, "Preferred: %d 0x%x %d\n",
228 + rd_buf_ptr += scnprintf(rd_buf_ptr, rd_buf_size - (rd_buf_ptr - rd_buf),
229 + "Preferred: %d 0x%x %d\n",
234 230 link->preferred_link_setting.lane_count,
235 231 link->preferred_link_setting.link_rate,
236 232 link->preferred_link_setting.link_spread);
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -200,6 +200,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(
200 200 edid_caps->edid_hdmi = connector->display_info.is_hdmi;
201 201
202 202 if (edid_caps->edid_hdmi) {
203 + edid_caps->qs_bit = connector->display_info.rgb_quant_range_selectable;
203 204 populate_hdmi_info_from_connector(link->dc->config.enable_frl, &connector->display_info.hdmi, edid_caps);
204 205 drm_dbg_driver(connector->dev, "%s: HDMI_FRL [%s] max_frl_rate %d\n", __func__, connector->name, edid_caps->max_frl_rate);
205 206 if (edid_caps->frl_dsc_support)
@@ -1202,9 +1203,10 @@ void populate_hdmi_info_from_connector(bool enable_frl, struct drm_hdmi_info *hd
1202 1203 edid_caps->max_frl_rate = get_max_frl_rate(hdmi->max_lanes, hdmi->max_frl_rate_per_lane);
1203 1204 edid_caps->frl_dsc_support = hdmi->dsc_cap.v_1p2;
1204 1205 if (edid_caps->frl_dsc_support) {
1205 - if (hdmi->dsc_cap.bpc_supported == 10)
1206 + /* HF-VSDB DSC max bpc is cumulative: >=12 implies 10 and 8. */
1207 + if (hdmi->dsc_cap.bpc_supported >= 10)
1206 1208 edid_caps->frl_dsc_10bpc = true;
1207 - else if (hdmi->dsc_cap.bpc_supported == 12)
1209 + if (hdmi->dsc_cap.bpc_supported >= 12)
1208 1210 edid_caps->frl_dsc_12bpc = true;
1209 1211 edid_caps->frl_dsc_all_bpp = hdmi->dsc_cap.all_bpp;
1210 1212 edid_caps->frl_dsc_native_420 = hdmi->dsc_cap.native_420;
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -567,6 +567,23 @@ static void dm_test_output_color_space_bt2020_rgb(struct kunit *test)
567 567 (int)COLOR_SPACE_2020_RGB_FULLRANGE);
568 568 }
569 569
570 + /**
571 + * dm_test_output_color_space_bt2020_rgb_limited - Test limited BT.2020 RGB
572 + * @test: The KUnit test context
573 + */
574 + static void dm_test_output_color_space_bt2020_rgb_limited(struct kunit *test)
575 + {
576 + struct dc_crtc_timing timing = {};
577 + struct drm_connector_state state = {};
578 +
579 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
580 + state.colorspace = DRM_MODE_COLORIMETRY_BT2020_RGB;
581 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_LIMITED;
582 +
583 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
584 + (int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
585 + }
586 +
570 587 /**
571 588 * dm_test_output_color_space_bt2020_ycc - Test Output color space bt2020 ycc
572 589 * @test: The KUnit test context
@@ -638,6 +655,24 @@ static void dm_test_output_color_space_bt2020_ycc_rgb_encoding(struct kunit *tes
638 655 (int)COLOR_SPACE_2020_RGB_FULLRANGE);
639 656 }
640 657
658 + /**
659 + * dm_test_output_color_space_bt2020_ycc_rgb_encoding_limited - Test limited
660 + * BT.2020 RGB output selected through the BT.2020 YCC connector colorspace
661 + * @test: The KUnit test context
662 + */
663 + static void dm_test_output_color_space_bt2020_ycc_rgb_encoding_limited(struct kunit *test)
664 + {
665 + struct dc_crtc_timing timing = {};
666 + struct drm_connector_state state = {};
667 +
668 + timing.pixel_encoding = PIXEL_ENCODING_RGB;
669 + state.colorspace = DRM_MODE_COLORIMETRY_BT2020_YCC;
670 + state.hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_LIMITED;
671 +
672 + KUNIT_EXPECT_EQ(test, (int)amdgpu_dm_get_output_color_space(&timing, &state),
673 + (int)COLOR_SPACE_2020_RGB_LIMITEDRANGE);
674 + }
675 +
641 676 /**
642 677 * dm_test_output_color_space_bt2020_rgb_ycc_encoding - Test Output color space
643 678 * bt2020 rgb with non-rgb pixel encoding falls back to limited ycbcr
@@ -5422,10 +5457,12 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
5422 5457 KUNIT_CASE(dm_test_output_color_space_bt709_y_only),
5423 5458 KUNIT_CASE(dm_test_output_color_space_oprgb),
5424 5459 KUNIT_CASE(dm_test_output_color_space_bt2020_rgb),
5460 + KUNIT_CASE(dm_test_output_color_space_bt2020_rgb_limited),
5425 5461 KUNIT_CASE(dm_test_output_color_space_bt2020_ycc),
5426 5462 KUNIT_CASE(dm_test_output_color_space_default_ycbcr709_y_only),
5427 5463 KUNIT_CASE(dm_test_output_color_space_default_ycbcr601),
5428 5464 KUNIT_CASE(dm_test_output_color_space_bt2020_ycc_rgb_encoding),
5465 + KUNIT_CASE(dm_test_output_color_space_bt2020_ycc_rgb_encoding_limited),
5429 5466 KUNIT_CASE(dm_test_output_color_space_bt2020_rgb_ycc_encoding),
5430 5467 /* Tests for amdgpu_dm_convert_dc_color_depth_into_bpc */
5431 5468 KUNIT_CASE(dm_test_convert_color_depth_bpc_mappings),
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_helpers_test.c
@@ -358,12 +358,14 @@ static void dm_test_parse_edid_caps_hdmi_frl(struct kunit *test)
358 358
359 359 /* Drive the HDMI/FRL branch */
360 360 connector->display_info.is_hdmi = true;
361 + connector->display_info.rgb_quant_range_selectable = true;
361 362 connector->display_info.hdmi.scdc.supported = true;
362 363 connector->display_info.hdmi.max_lanes = 4;
363 364 connector->display_info.hdmi.max_frl_rate_per_lane = 12;
364 365
365 366 KUNIT_EXPECT_EQ(test, dm_helpers_parse_edid_caps(link, dc_edid, edid_caps), EDID_OK);
366 367 KUNIT_EXPECT_TRUE(test, edid_caps->edid_hdmi);
368 + KUNIT_EXPECT_EQ(test, edid_caps->qs_bit, 1);
367 369 KUNIT_EXPECT_TRUE(test, edid_caps->scdc_present);
368 370 /* max_lanes 4 + max_frl_rate_per_lane 12 -> rate index 6 */
369 371 KUNIT_EXPECT_EQ(test, edid_caps->max_frl_rate, 6);
@@ -909,7 +911,7 @@ static void dm_test_populate_hdmi_frl_dsc_12bpc(struct kunit *test)
909 911
910 912 KUNIT_EXPECT_EQ(test, caps->max_frl_rate, 2);
911 913 KUNIT_EXPECT_TRUE(test, caps->frl_dsc_support);
912 - KUNIT_EXPECT_FALSE(test, caps->frl_dsc_10bpc);
914 + KUNIT_EXPECT_TRUE(test, caps->frl_dsc_10bpc);
913 915 KUNIT_EXPECT_TRUE(test, caps->frl_dsc_12bpc);
914 916 KUNIT_EXPECT_EQ(test, caps->frl_dsc_max_slices, 7);
915 917 KUNIT_EXPECT_EQ(test, caps->frl_dsc_max_frl_rate, 1);
modified drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -3198,6 +3198,7 @@ static struct dc_update_descriptor check_update_surfaces_for_stream(
3198 3198 }
3199 3199
3200 3200 if ((stream_update->hdr_static_metadata && !stream_update->stream->use_dynamic_meta) ||
3201 + stream_update->output_color_space ||
3201 3202 stream_update->vrr_infopacket ||
3202 3203 stream_update->vsc_infopacket ||
3203 3204 stream_update->vsp_infopacket ||
@@ -4188,6 +4189,7 @@ static void commit_planes_do_stream_update_sequence(struct dc *dc,
4188 4189 hwss_add_setup_periodic_interrupt(&seq_state, dc, pipe_ctx);
4189 4190
4190 4191 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
4192 + stream_update->output_color_space ||
4191 4193 stream_update->vrr_infopacket ||
4192 4194 stream_update->vsc_infopacket ||
4193 4195 stream_update->vsp_infopacket ||
@@ -4370,6 +4372,7 @@ static void commit_planes_do_stream_update(struct dc *dc,
4370 4372 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx);
4371 4373
4372 4374 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
4375 + stream_update->output_color_space ||
4373 4376 stream_update->vrr_infopacket ||
4374 4377 stream_update->vsc_infopacket ||
4375 4378 stream_update->vsp_infopacket ||
modified drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -348,7 +348,8 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,
348 348 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
349 349 int ret = 0;
350 350
351 - if (amdgpu_sriov_vf(adev))
351 + if (amdgpu_sriov_vf(adev) ||
352 + amdgpu_in_reset(adev))
352 353 return 0;
353 354
354 355 if (pp_funcs && pp_funcs->switch_power_profile) {
@@ -367,7 +368,8 @@ int amdgpu_dpm_pause_power_profile(struct amdgpu_device *adev,
367 368 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
368 369 int ret = 0;
369 370
370 - if (amdgpu_sriov_vf(adev))
371 + if (amdgpu_sriov_vf(adev) ||
372 + amdgpu_in_reset(adev))
371 373 return 0;
372 374
373 375 if (pp_funcs && pp_funcs->pause_power_profile) {
modified drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
@@ -2092,11 +2092,11 @@ static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
2092 2092
2093 2093 gpu_metrics->average_socket_power = metrics->AverageSocketPower;
2094 2094
2095 - if ((mp1_ver == IP_VERSION(13, 0, 0) && smu->smc_fw_version <= 0x004e1e00) ||
2096 - (mp1_ver == IP_VERSION(13, 0, 10) && smu->smc_fw_version <= 0x00500800))
2095 + if ((mp1_ver == IP_VERSION(13, 0, 0) &&
2096 + (smu->smc_fw_version <= 0x004e1e00 || smu->smc_fw_version >= 0x004e8600)) ||
2097 + (mp1_ver == IP_VERSION(13, 0, 10) &&
2098 + smu->smc_fw_version <= 0x00500800))
2097 2099 gpu_metrics->energy_accumulator = metrics->EnergyAccumulator;
2098 - else
2099 - gpu_metrics->energy_accumulator = UINT_MAX;
2100 2100
2101 2101 if (metrics->AverageGfxActivity <= SMU_13_0_0_BUSY_THRESHOLD)
2102 2102 gpu_metrics->average_gfxclk_frequency = metrics->AverageGfxclkFrequencyPostDs;
modified drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
@@ -2097,8 +2097,8 @@ static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
2097 2097 metrics->Vcn1ActivityPercentage);
2098 2098
2099 2099 gpu_metrics->average_socket_power = metrics->AverageSocketPower;
2100 - gpu_metrics->energy_accumulator = smu->smc_fw_version <= 0x00521400 ?
2101 - metrics->EnergyAccumulator : UINT_MAX;
2100 + if (smu->smc_fw_version <= 0x00521400)
2101 + gpu_metrics->energy_accumulator = metrics->EnergyAccumulator;
2102 2102
2103 2103 if (metrics->AverageGfxActivity <= SMU_13_0_7_BUSY_THRESHOLD)
2104 2104 gpu_metrics->average_gfxclk_frequency = metrics->AverageGfxclkFrequencyPostDs;
modified drivers/gpu/drm/aspeed/aspeed_gfx_drv.c
@@ -189,13 +189,12 @@ static int aspeed_gfx_load(struct drm_device *drm)
189 189 }
190 190 reset_control_deassert(priv->rst);
191 191
192 - priv->clk = devm_clk_get(drm->dev, NULL);
192 + priv->clk = devm_clk_get_enabled(drm->dev, NULL);
193 193 if (IS_ERR(priv->clk)) {
194 194 dev_err(&pdev->dev,
195 - "missing or invalid clk device tree entry");
195 + "failed to get and enable clock\n");
196 196 return PTR_ERR(priv->clk);
197 197 }
198 - clk_prepare_enable(priv->clk);
199 198
200 199 /* Sanitize control registers */
201 200 writel(0, priv->base + CRT_CTRL1);
modified drivers/gpu/drm/ast/ast_cursor.c
@@ -25,6 +25,7 @@
25 25 #include <linux/sizes.h>
26 26
27 27 #include <drm/drm_atomic.h>
28 + #include <drm/drm_blend.h>
28 29 #include <drm/drm_damage_helper.h>
29 30 #include <drm/drm_format_helper.h>
30 31 #include <drm/drm_gem_atomic_helper.h>
@@ -355,6 +356,8 @@ int ast_cursor_plane_init(struct ast_device *ast)
355 356 }
356 357 drm_plane_helper_add(cursor_plane, &ast_cursor_plane_helper_funcs);
357 358 drm_plane_enable_fb_damage_clips(cursor_plane);
359 + drm_plane_create_blend_mode_property(cursor_plane,
360 + BIT(DRM_MODE_BLEND_COVERAGE));
358 361
359 362 return 0;
360 363 }
modified drivers/gpu/drm/bridge/samsung-dsim.c
@@ -1862,7 +1862,7 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct device
1862 1862 int te_gpio_irq;
1863 1863 int ret;
1864 1864
1865 - dsi->te_gpio = devm_gpiod_get_optional(dev, "te", GPIOD_IN);
1865 + dsi->te_gpio = gpiod_get_optional(dev, "te", GPIOD_IN);
1866 1866 if (!dsi->te_gpio)
1867 1867 return 0;
1868 1868 else if (IS_ERR(dsi->te_gpio))
modified drivers/gpu/drm/bridge/tc358768.c
@@ -1263,10 +1263,13 @@ tc358768_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
1263 1263 return input_fmts;
1264 1264 }
1265 1265
1266 - static bool tc358768_mode_fixup(struct drm_bridge *bridge,
1267 - const struct drm_display_mode *mode,
1268 - struct drm_display_mode *adjusted_mode)
1266 + static int tc358768_bridge_atomic_check(struct drm_bridge *bridge,
1267 + struct drm_bridge_state *bridge_state,
1268 + struct drm_crtc_state *crtc_state,
1269 + struct drm_connector_state *conn_state)
1269 1270 {
1271 + struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
1272 +
1270 1273 /* Default to positive sync */
1271 1274
1272 1275 if (!(adjusted_mode->flags &
@@ -1277,13 +1280,15 @@ static bool tc358768_mode_fixup(struct drm_bridge *bridge,
1277 1280 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
1278 1281 adjusted_mode->flags |= DRM_MODE_FLAG_PVSYNC;
1279 1282
1280 - return true;
1283 + bridge_state->input_bus_cfg.flags = bridge->timings->input_bus_flags;
1284 +
1285 + return 0;
1281 1286 }
1282 1287
1283 1288 static const struct drm_bridge_funcs tc358768_bridge_funcs = {
1284 1289 .attach = tc358768_bridge_attach,
1285 1290 .mode_valid = tc358768_bridge_mode_valid,
1286 - .mode_fixup = tc358768_mode_fixup,
1291 + .atomic_check = tc358768_bridge_atomic_check,
1287 1292 .atomic_pre_enable = tc358768_bridge_atomic_pre_enable,
1288 1293 .atomic_enable = tc358768_bridge_atomic_enable,
1289 1294 .atomic_disable = tc358768_bridge_atomic_disable,
modified drivers/gpu/drm/bridge/th1520-dw-hdmi.c
@@ -135,8 +135,8 @@ static int th1520_dw_hdmi_probe(struct platform_device *pdev)
135 135 plat_data->priv_data = hdmi;
136 136
137 137 hdmi->dw_hdmi = dw_hdmi_probe(pdev, plat_data);
138 - if (IS_ERR(hdmi))
139 - return PTR_ERR(hdmi);
138 + if (IS_ERR(hdmi->dw_hdmi))
139 + return PTR_ERR(hdmi->dw_hdmi);
140 140
141 141 platform_set_drvdata(pdev, hdmi);
142 142
@@ -145,9 +145,9 @@ static int th1520_dw_hdmi_probe(struct platform_device *pdev)
145 145
146 146 static void th1520_dw_hdmi_remove(struct platform_device *pdev)
147 147 {
148 - struct dw_hdmi *hdmi = platform_get_drvdata(pdev);
148 + struct th1520_hdmi *hdmi = platform_get_drvdata(pdev);
149 149
150 - dw_hdmi_remove(hdmi);
150 + dw_hdmi_remove(hdmi->dw_hdmi);
151 151 }
152 152
153 153 static const struct of_device_id th1520_dw_hdmi_of_table[] = {
modified drivers/gpu/drm/bridge/ti-sn65dsi83.c
@@ -403,7 +403,7 @@ retry:
403 403 drm_modeset_drop_locks(&ctx);
404 404 drm_modeset_acquire_fini(&ctx);
405 405
406 - return 0;
406 + return err;
407 407 }
408 408
409 409 static void sn65dsi83_reset_work(struct work_struct *ws)
@@ -419,11 +419,13 @@ static void sn65dsi83_reset_work(struct work_struct *ws)
419 419 ret = sn65dsi83_reset_pipe(ctx);
420 420 if (ret) {
421 421 dev_err(ctx->dev, "reset pipe failed %pe\n", ERR_PTR(ret));
422 - return;
422 + goto bridge_exit;
423 423 }
424 +
424 425 if (ctx->irq)
425 426 enable_irq(ctx->irq);
426 427
428 + bridge_exit:
427 429 drm_bridge_exit(idx);
428 430 }
429 431
modified drivers/gpu/drm/clients/drm_fbdev_client.c
@@ -42,6 +42,14 @@ static int drm_fbdev_client_restore(struct drm_client_dev *client, bool force)
42 42 {
43 43 struct drm_fb_helper *fb_helper = drm_fb_helper_from_client(client);
44 44
45 + /*
46 + * The client is registered before the initial fbdev probe.
47 + * If probing failed, the client remains registered but there
48 + * is no valid fbdev framebuffer to restore.
49 + */
50 + if (!fb_helper->info || !fb_helper->fb)
51 + return 0;
52 +
45 53 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper, force);
46 54
47 55 return 0;
modified drivers/gpu/drm/display/drm_dp_helper.c
@@ -4634,7 +4634,9 @@ static int dp_aux_backlight_update_status(struct backlight_device *bd)
4634 4634
4635 4635 if (!backlight_is_blank(bd)) {
4636 4636 if (!bl->enabled) {
4637 - drm_edp_backlight_enable(bl->aux, &bl->info, brightness);
4637 + ret = drm_edp_backlight_enable(bl->aux, &bl->info, brightness);
4638 + if (ret)
4639 + return ret;
4638 4640 bl->enabled = true;
4639 4641 return 0;
4640 4642 }
modified drivers/gpu/drm/drm_atomic_uapi.c
@@ -1462,10 +1462,12 @@ static int prepare_signaling(struct drm_device *dev,
1462 1462 struct dma_fence *fence;
1463 1463 struct drm_out_fence_state *f;
1464 1464
1465 + ret = -ENOMEM;
1466 +
1465 1467 f = krealloc(*fence_state, sizeof(**fence_state) *
1466 1468 (*num_fences + 1), GFP_KERNEL);
1467 1469 if (!f)
1468 - return -ENOMEM;
1470 + goto err_free_event;
1469 1471
1470 1472 memset(&f[*num_fences], 0, sizeof(*f));
1471 1473
@@ -1474,12 +1476,12 @@ static int prepare_signaling(struct drm_device *dev,
1474 1476
1475 1477 fence = drm_crtc_create_fence(crtc);
1476 1478 if (!fence)
1477 - return -ENOMEM;
1479 + goto err_free_event;
1478 1480
1479 1481 ret = setup_out_fence(&f[(*num_fences)++], fence);
1480 1482 if (ret) {
1481 1483 dma_fence_put(fence);
1482 - return ret;
1484 + goto err_free_event;
1483 1485 }
1484 1486
1485 1487 crtc_state->event->base.fence = fence;
@@ -1535,6 +1537,11 @@ static int prepare_signaling(struct drm_device *dev,
1535 1537 }
1536 1538
1537 1539 return 0;
1540 +
1541 + err_free_event:
1542 + drm_event_cancel_free(dev, &crtc_state->event->base);
1543 + crtc_state->event = NULL;
1544 + return ret;
1538 1545 }
1539 1546
1540 1547 static void complete_signaling(struct drm_device *dev,
modified drivers/gpu/drm/drm_bridge.c
@@ -454,8 +454,10 @@ void drm_bridge_add(struct drm_bridge *bridge)
454 454 * in bridge_lingering_list. Remove it or bridge_lingering_list will be
455 455 * corrupted when adding this bridge to bridge_list below.
456 456 */
457 + mutex_lock(&bridge_lock);
457 458 if (!list_empty(&bridge->list))
458 459 list_del_init(&bridge->list);
460 + mutex_unlock(&bridge_lock);
459 461
460 462 mutex_init(&bridge->hpd_state_mutex);
461 463 mutex_init(&bridge->hpd_mutex);
@@ -593,8 +595,10 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
593 595 if (!bridge->container)
594 596 DRM_WARN("DRM bridge corrupted or not allocated by devm_drm_bridge_alloc()\n");
595 597
596 - if (list_empty(&bridge->list))
597 - DRM_WARN("Missing drm_bridge_add() before attach\n");
598 + scoped_guard(mutex, &bridge_lock) {
599 + if (list_empty(&bridge->list))
600 + DRM_WARN("Missing drm_bridge_add() before attach\n");
601 + }
598 602
599 603 drm_bridge_get(bridge);
600 604
modified drivers/gpu/drm/drm_exec.c
@@ -322,6 +322,19 @@ int drm_exec_prepare_array(struct drm_exec *exec,
322 322 {
323 323 int ret;
324 324
325 + /*
326 + * Make sure to lock a contended object even when no objects are
327 + * given, otherwise drm_exec_retry_on_contention() would loop
328 + * forever on patterns like:
329 + *
330 + * ret = drm_exec_prepare_array(exec, objs, num_objects, ...);
331 + * drm_exec_retry_on_contention(exec);
332 + *
333 + * with num_objects == 0.
334 + */
335 + if (!num_objects)
336 + return drm_exec_lock_contended(exec);
337 +
325 338 for (unsigned int i = 0; i < num_objects; ++i) {
326 339 ret = drm_exec_prepare_obj(exec, objects[i], num_fences);
327 340 if (unlikely(ret))
modified drivers/gpu/drm/drm_fb_helper.c
@@ -1724,10 +1724,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper)
1724 1724
1725 1725 ret = drm_fb_helper_single_fb_probe(fb_helper);
1726 1726 if (ret < 0) {
1727 - if (ret == -EAGAIN) {
1728 - fb_helper->deferred_setup = true;
1727 + /* modesets are probed but fb_helper->fb isn't; defer restore too */
1728 + fb_helper->deferred_setup = true;
1729 + if (ret == -EAGAIN)
1729 1730 ret = 0;
1730 - }
1731 1731 mutex_unlock(&fb_helper->lock);
1732 1732
1733 1733 goto err_drm_fb_helper_release_info;
modified drivers/gpu/drm/drm_panic_qr.rs
@@ -407,8 +407,8 @@ impl DecFifo {
407 407 for i in (0..self.len).rev() {
408 408 self.decimals[i + len] = self.decimals[i];
409 409 }
410 - for i in 0..len {
411 - self.decimals[i] = (chunk % 10) as u8;
410 + for decimal in &mut self.decimals[..len] {
411 + *decimal = (chunk % 10) as u8;
412 412 chunk = div10(chunk);
413 413 }
414 414 self.len += len;
modified drivers/gpu/drm/gud/gud_pipe.c
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,
482 482 if (!new_plane_state->visible)
483 483 return 0;
484 484
485 + if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE)
486 + new_plane_state->ignore_damage_clips = true;
487 +
485 488 if (old_plane_state->rotation != new_plane_state->rotation)
486 489 crtc_state->mode_changed = true;
487 490
@@ -504,6 +507,7 @@ int gud_plane_atomic_check(struct drm_plane *plane,
504 507 for_each_new_connector_in_state(state, connector, connector_state, i) {
505 508 if (connector_state->crtc)
506 509 break;
510 + connector_state = NULL;
507 511 }
508 512
509 513 /*
@@ -562,8 +566,8 @@ int gud_plane_atomic_check(struct drm_plane *plane,
562 566 goto out;
563 567 }
564 568
565 - req->properties[num_properties + i].prop = cpu_to_le16(prop);
566 - req->properties[num_properties + i].val = cpu_to_le64(val);
569 + req->properties[num_properties].prop = cpu_to_le16(prop);
570 + req->properties[num_properties].val = cpu_to_le64(val);
567 571 num_properties++;
568 572 }
569 573
modified drivers/gpu/drm/i915/display/intel_display_types.h
@@ -1946,6 +1946,8 @@ struct intel_dp {
1946 1946
1947 1947 bool colorimetry_support;
1948 1948
1949 + bool sst_split_sdp_support;
1950 +
1949 1951 struct {
1950 1952 enum transcoder transcoder;
1951 1953 struct mutex lock;
modified drivers/gpu/drm/i915/display/intel_dp.c
@@ -3409,12 +3409,22 @@ intel_dp_audio_compute_config(struct intel_encoder *encoder,
3409 3409 struct intel_crtc_state *pipe_config,
3410 3410 struct drm_connector_state *conn_state)
3411 3411 {
3412 + struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3413 +
3412 3414 pipe_config->has_audio =
3413 3415 intel_dp_has_audio(encoder, conn_state) &&
3414 3416 intel_audio_compute_config(encoder, pipe_config, conn_state);
3415 3417
3416 3418 pipe_config->sdp_split_enable = pipe_config->has_audio &&
3417 3419 intel_dp_is_uhbr(pipe_config);
3420 +
3421 + /*
3422 + * SDP splitting for UHBR audio requires explicit sink capability in
3423 + * SST mode, whereas in MST mode it is inherently supported.
3424 + */
3425 + if (pipe_config->sdp_split_enable &&
3426 + !intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
3427 + pipe_config->sdp_split_enable = intel_dp->sst_split_sdp_support;
3418 3428 }
3419 3429
3420 3430 void
@@ -4462,16 +4472,25 @@ void intel_dp_configure_protocol_converter(struct intel_dp *intel_dp,
4462 4472 str_enable_disable(tmp));
4463 4473 }
4464 4474
4465 - static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
4475 + static u8 intel_dp_read_dprx_feature_enum(struct intel_dp *intel_dp)
4466 4476 {
4467 4477 u8 dprx = 0;
4468 4478
4469 - if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
4470 - &dprx) != 1)
4471 - return false;
4479 + drm_dp_dpcd_read_data(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
4480 + &dprx, sizeof(dprx));
4481 + return dprx;
4482 + }
4483 +
4484 + static bool intel_dp_get_colorimetry_status(u8 dprx)
4485 + {
4472 4486 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
4473 4487 }
4474 4488
4489 + static bool intel_dp_get_sst_split_sdp_status(u8 dprx)
4490 + {
4491 + return dprx & DP_SST_SPLIT_SDP_CAP;
4492 + }
4493 +
4475 4494 static int intel_dp_read_dsc_dpcd(struct drm_dp_aux *aux,
4476 4495 u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
4477 4496 {
@@ -4771,6 +4790,7 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp, struct intel_connector *connector
4771 4790 {
4772 4791 struct intel_display *display = to_intel_display(intel_dp);
4773 4792 int ret;
4793 + u8 dprx;
4774 4794
4775 4795 /* this function is meant to be called only once */
4776 4796 drm_WARN_ON(display->drm, intel_dp->dpcd[DP_DPCD_REV] != 0);
@@ -4782,8 +4802,13 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp, struct intel_connector *connector
4782 4802 drm_dp_is_branch(intel_dp->dpcd));
4783 4803 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident);
4784 4804
4805 + dprx = intel_dp_read_dprx_feature_enum(intel_dp);
4806 +
4785 4807 intel_dp->colorimetry_support =
4786 - intel_dp_get_colorimetry_status(intel_dp);
4808 + intel_dp_get_colorimetry_status(dprx);
4809 +
4810 + intel_dp->sst_split_sdp_support =
4811 + intel_dp_get_sst_split_sdp_status(dprx);
4787 4812
4788 4813 /*
4789 4814 * Read the eDP display control registers.
@@ -4874,13 +4899,20 @@ intel_dp_get_dpcd(struct intel_dp *intel_dp)
4874 4899 * the OUI/ID since we know it won't change.
4875 4900 */
4876 4901 if (!intel_dp_is_edp(intel_dp)) {
4902 + u8 dprx;
4903 +
4877 4904 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4878 4905 drm_dp_is_branch(intel_dp->dpcd));
4879 4906
4880 4907 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident);
4881 4908
4909 + dprx = intel_dp_read_dprx_feature_enum(intel_dp);
4910 +
4882 4911 intel_dp->colorimetry_support =
4883 - intel_dp_get_colorimetry_status(intel_dp);
4912 + intel_dp_get_colorimetry_status(dprx);
4913 +
4914 + intel_dp->sst_split_sdp_support =
4915 + intel_dp_get_sst_split_sdp_status(dprx);
4884 4916
4885 4917 intel_dp_update_sink_caps(intel_dp);
4886 4918 }
modified drivers/gpu/drm/i915/i915_query.c
@@ -403,8 +403,10 @@ static int query_perf_config_list(struct drm_i915_private *i915,
403 403 ids = krealloc(oa_config_ids,
404 404 n_configs * sizeof(*oa_config_ids),
405 405 GFP_KERNEL);
406 - if (!ids)
406 + if (!ids) {
407 + kfree(oa_config_ids);
407 408 return -ENOMEM;
409 + }
408 410
409 411 alloc = fetch_and_zero(&n_configs);
410 412
modified drivers/gpu/drm/imagination/pvr_free_list.c
@@ -8,6 +8,7 @@
8 8 #include "pvr_vm.h"
9 9
10 10 #include <drm/drm_gem.h>
11 + #include <drm/drm_print.h>
11 12 #include <linux/slab.h>
12 13 #include <linux/xarray.h>
13 14 #include <uapi/drm/pvr_drm.h>
@@ -612,13 +613,21 @@ pvr_free_list_process_reconstruct_req(struct pvr_device *pvr_dev,
612 613 };
613 614 struct rogue_fwif_freelists_reconstruction_data *resp =
614 615 &resp_cmd.cmd_data.free_lists_reconstruction_data;
616 + u32 count = min_t(u32, req->freelist_count,
617 + ARRAY_SIZE(req->freelist_ids));
615 618
616 - for (u32 i = 0; i < req->freelist_count; i++)
619 + if (count != req->freelist_count) {
620 + drm_warn_once(from_pvr_device(pvr_dev),
621 + "Requested reconstruction of %u freelists, limiting to %u\n",
622 + req->freelist_count, count);
623 + }
624 +
625 + for (u32 i = 0; i < count; i++)
617 626 pvr_free_list_reconstruct(pvr_dev, req->freelist_ids[i]);
618 627
619 - resp->freelist_count = req->freelist_count;
628 + resp->freelist_count = count;
620 629 memcpy(resp->freelist_ids, req->freelist_ids,
621 - req->freelist_count * sizeof(resp->freelist_ids[0]));
630 + count * sizeof(resp->freelist_ids[0]));
622 631
623 632 WARN_ON(pvr_kccb_send_cmd(pvr_dev, &resp_cmd, NULL));
624 633 }
modified drivers/gpu/drm/imagination/pvr_mmu.c
@@ -12,6 +12,7 @@
12 12 #include "pvr_rogue_mmu_defs.h"
13 13
14 14 #include <drm/drm_drv.h>
15 + #include <drm/drm_print.h>
15 16 #include <linux/atomic.h>
16 17 #include <linux/bitops.h>
17 18 #include <linux/dma-mapping.h>
@@ -2335,7 +2336,8 @@ void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx)
2335 2336 * pvr_mmu_op_context_create() - Create an MMU op context.
2336 2337 * @ctx: MMU context associated with owning VM context.
2337 2338 * @sgt: Scatter gather table containing pages pinned for use by this context.
2338 - * @sgt_offset: Start offset of the requested device-virtual memory mapping.
2339 + * @device_addr: Virtual device address at the start of the requested mapping.
2340 + * @sgt_offset: Offset into @sgt of the start of the requested mapping.
2339 2341 * @size: Size in bytes of the requested device-virtual memory mapping. For an
2340 2342 * unmapping, this should be zero so that no page tables are allocated.
2341 2343 *
@@ -2346,7 +2348,7 @@ void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx)
2346 2348 */
2347 2349 struct pvr_mmu_op_context *
2348 2350 pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
2349 - u64 sgt_offset, u64 size)
2351 + u64 device_addr, u64 sgt_offset, u64 size)
2350 2352 {
2351 2353 int err;
2352 2354
@@ -2362,18 +2364,18 @@ pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
2362 2364
2363 2365 if (size) {
2364 2366 /*
2365 - * The number of page table objects we need to prealloc is
2366 - * indicated by the mapping size, start offset and the sizes
2367 - * of the areas mapped per PT or PD. The range calculation is
2368 - * identical to that for the index into a table for a device
2369 - * address, so we reuse those functions here.
2367 + * The page tables needed are set by the device-virtual range
2368 + * being mapped: one level 1 table per 1GiB region and one
2369 + * level 0 table per 2MiB region the range touches. Tables that
2370 + * already exist are not consumed, so this is an upper bound.
2370 2371 */
2371 - const u32 l1_start_idx = pvr_page_table_l2_idx(sgt_offset);
2372 - const u32 l1_end_idx = pvr_page_table_l2_idx(sgt_offset + size);
2373 - const u32 l1_count = l1_end_idx - l1_start_idx + 1;
2374 - const u32 l0_start_idx = pvr_page_table_l1_idx(sgt_offset);
2375 - const u32 l0_end_idx = pvr_page_table_l1_idx(sgt_offset + size);
2376 - const u32 l0_count = l0_end_idx - l0_start_idx + 1;
2372 + const u64 last_addr = device_addr + size - 1;
2373 + const u64 l1_count =
2374 + (last_addr >> ROGUE_MMUCTRL_VADDR_PC_INDEX_SHIFT) -
2375 + (device_addr >> ROGUE_MMUCTRL_VADDR_PC_INDEX_SHIFT) + 1;
2376 + const u64 l0_count =
2377 + (last_addr >> ROGUE_MMUCTRL_VADDR_PD_INDEX_SHIFT) -
2378 + (device_addr >> ROGUE_MMUCTRL_VADDR_PD_INDEX_SHIFT) + 1;
2377 2379
2378 2380 /*
2379 2381 * Alloc and push page table entries until we have enough of
@@ -2553,7 +2555,9 @@ pvr_mmu_map_sgl(struct pvr_mmu_op_context *op_ctx, struct scatterlist *sgl,
2553 2555
2554 2556 err_destroy_pages:
2555 2557 memcpy(&op_ctx->curr_page, &ptr_copy, sizeof(op_ctx->curr_page));
2556 - err = pvr_mmu_op_context_unmap_curr_page(op_ctx, page);
2558 + if (pvr_mmu_op_context_unmap_curr_page(op_ctx, page))
2559 + drm_err(from_pvr_device(op_ctx->mmu_ctx->pvr_dev),
2560 + "%s : Failure in unmapping pages\n", __func__);
2557 2561
2558 2562 return err;
2559 2563 }
modified drivers/gpu/drm/imagination/pvr_mmu.h
@@ -99,7 +99,7 @@ dma_addr_t pvr_mmu_get_root_table_dma_addr(struct pvr_mmu_context *ctx);
99 99 void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx);
100 100 struct pvr_mmu_op_context *
101 101 pvr_mmu_op_context_create(struct pvr_mmu_context *ctx,
102 - struct sg_table *sgt, u64 sgt_offset, u64 size);
102 + struct sg_table *sgt, u64 device_addr, u64 sgt_offset, u64 size);
103 103
104 104 int pvr_mmu_map(struct pvr_mmu_op_context *op_ctx, u64 size, u64 flags,
105 105 u64 device_addr);
modified drivers/gpu/drm/imagination/pvr_vm.c
@@ -276,7 +276,7 @@ pvr_vm_bind_op_map_init(struct pvr_vm_bind_op *bind_op,
276 276 goto err_bind_op_fini;
277 277
278 278 bind_op->mmu_op_ctx =
279 - pvr_mmu_op_context_create(vm_ctx->mmu_ctx, sgt, offset, size);
279 + pvr_mmu_op_context_create(vm_ctx->mmu_ctx, sgt, device_addr, offset, size);
280 280 err = PTR_ERR_OR_ZERO(bind_op->mmu_op_ctx);
281 281 if (err) {
282 282 bind_op->mmu_op_ctx = NULL;
@@ -318,7 +318,7 @@ pvr_vm_bind_op_unmap_init(struct pvr_vm_bind_op *bind_op,
318 318 }
319 319
320 320 bind_op->mmu_op_ctx =
321 - pvr_mmu_op_context_create(vm_ctx->mmu_ctx, NULL, 0, 0);
321 + pvr_mmu_op_context_create(vm_ctx->mmu_ctx, NULL, device_addr, 0, 0);
322 322 err = PTR_ERR_OR_ZERO(bind_op->mmu_op_ctx);
323 323 if (err) {
324 324 bind_op->mmu_op_ctx = NULL;
@@ -418,6 +418,8 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void *op_ctx)
418 418 static int
419 419 pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
420 420 {
421 + /* The split parts belong to the object of the mapping being split. */
422 + struct drm_gpuvm_bo *vm_bo = op->remap.unmap->va->vm_bo;
421 423 struct pvr_vm_bind_op *ctx = op_ctx;
422 424 u64 va_start = 0, va_range = 0;
423 425 int err;
@@ -433,14 +435,12 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
433 435 drm_gpuva_remap(&ctx->prev_va->base, &ctx->next_va->base, &op->remap);
434 436
435 437 if (op->remap.prev) {
436 - pvr_gem_object_get(gem_to_pvr_gem(ctx->prev_va->base.gem.obj));
437 - drm_gpuva_link(&ctx->prev_va->base, ctx->gpuvm_bo);
438 + drm_gpuva_link(&ctx->prev_va->base, vm_bo);
438 439 ctx->prev_va = NULL;
439 440 }
440 441
441 442 if (op->remap.next) {
442 - pvr_gem_object_get(gem_to_pvr_gem(ctx->next_va->base.gem.obj));
443 - drm_gpuva_link(&ctx->next_va->base, ctx->gpuvm_bo);
443 + drm_gpuva_link(&ctx->next_va->base, vm_bo);
444 444 ctx->next_va = NULL;
445 445 }
446 446
modified drivers/gpu/drm/logicvc/Kconfig
@@ -4,7 +4,6 @@ config DRM_LOGICVC
4 4 depends on OF || COMPILE_TEST
5 5 select DRM_CLIENT_SELECTION
6 6 select DRM_KMS_HELPER
7 - select DRM_KMS_DMA_HELPER
8 7 select DRM_GEM_DMA_HELPER
9 8 select REGMAP
10 9 select REGMAP_MMIO
modified drivers/gpu/drm/loongson/lsdc_plane.c
@@ -7,6 +7,7 @@
7 7
8 8 #include <drm/drm_atomic.h>
9 9 #include <drm/drm_atomic_helper.h>
10 + #include <drm/drm_blend.h>
10 11 #include <drm/drm_framebuffer.h>
11 12 #include <drm/drm_gem_atomic_helper.h>
12 13 #include <drm/drm_print.h>
@@ -765,7 +766,7 @@ int ls7a1000_cursor_plane_init(struct drm_device *ddev,
765 766
766 767 drm_plane_helper_add(plane, &ls7a1000_cursor_plane_helper_funcs);
767 768
768 - return 0;
769 + return drm_plane_create_blend_mode_property(plane, BIT(DRM_MODE_BLEND_COVERAGE));
769 770 }
770 771
771 772 int ls7a2000_cursor_plane_init(struct drm_device *ddev,
@@ -790,5 +791,5 @@ int ls7a2000_cursor_plane_init(struct drm_device *ddev,
790 791
791 792 drm_plane_helper_add(plane, &ls7a2000_cursor_plane_helper_funcs);
792 793
793 - return 0;
794 + return drm_plane_create_blend_mode_property(plane, BIT(DRM_MODE_BLEND_COVERAGE));
794 795 }
modified drivers/gpu/drm/nouveau/include/nvif/cl0080.h
@@ -4,6 +4,7 @@
4 4
5 5 #define NV_DEVICE_V0_INFO 0x00
6 6 #define NV_DEVICE_V0_TIME 0x01
7 + #define NV_DEVICE_V0_GCX_READY 0x02
7 8
8 9 struct nv_device_info_v0 {
9 10 __u8 version;
@@ -55,6 +56,15 @@ struct nv_device_time_v0 {
55 56 __u64 time;
56 57 };
57 58
59 + #define NV_DEVICE_GC6_READY BIT(0)
60 + #define NV_DEVICE_GCOFF_READY BIT(1)
61 +
62 + struct nv_device_gcx_ready_v0 {
63 + __u8 version;
64 + __u8 pad01[6];
65 + __u8 ready;
66 + };
67 +
58 68 #define NV_DEVICE_INFO_UNIT (0xffffffffULL << 32)
59 69 #define NV_DEVICE_INFO(n) ((n) | (0x00000000ULL << 32))
60 70 #define NV_DEVICE_HOST(n) ((n) | (0x00000001ULL << 32))
modified drivers/gpu/drm/nouveau/include/nvif/device.h
@@ -22,4 +22,5 @@ int nvif_device_ctor(struct nvif_client *, const char *name, struct nvif_device
22 22 void nvif_device_dtor(struct nvif_device *);
23 23 int nvif_device_map(struct nvif_device *);
24 24 u64 nvif_device_time(struct nvif_device *);
25 + int nvif_device_gcx_ready(struct nvif_device *);
25 26 #endif
modified drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
@@ -156,6 +156,10 @@ struct nvkm_gsp {
156 156 struct sg_table fbsr;
157 157 } sr;
158 158
159 + struct {
160 + bool use_raw_mode_comptagline_alloc;
161 + } memsys;
162 +
159 163 struct {
160 164 struct nvkm_gsp_mem mem;
161 165
@@ -495,6 +499,8 @@ nvkm_gsp_event_dtor(struct nvkm_gsp_event *event)
495 499 int nvkm_gsp_intr_stall(struct nvkm_gsp *, enum nvkm_subdev_type, int);
496 500 int nvkm_gsp_intr_nonstall(struct nvkm_gsp *, enum nvkm_subdev_type, int);
497 501
502 + int nvkm_gsp_gcx_ready(struct nvkm_gsp *gsp);
503 +
498 504 int gv100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
499 505 int tu102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
500 506 int tu116_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
modified drivers/gpu/drm/nouveau/nouveau_abi16.c
@@ -488,7 +488,7 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
488 488 goto done;
489 489 break;
490 490 case NV_DEVICE_INFO_V0_TURING:
491 - if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_NVDEC) {
491 + if (engine == NV_DEVICE_HOST_RUNLIST_ENGINES_GR) {
492 492 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar",
493 493 0, TURING_DMA_COPY_A, NULL, 0,
494 494 &chan->ce);
modified drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -578,8 +578,9 @@ int nouveau_bo_pin_locked(struct nouveau_bo *nvbo, uint32_t domain, bool contig)
578 578 "0x%08x vs 0x%08x\n", bo,
579 579 bo->resource->mem_type, domain);
580 580 ret = -EBUSY;
581 + } else {
582 + ttm_bo_pin(&nvbo->bo);
581 583 }
582 - ttm_bo_pin(&nvbo->bo);
583 584 goto out;
584 585 }
585 586
modified drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -600,8 +600,11 @@ nouveau_connector_detect(struct drm_connector *connector, bool force)
600 600 new_edid = drm_get_edid(connector, nv_encoder->i2c);
601 601 } else {
602 602 ret = nvif_outp_edid_get(&nv_encoder->outp, (u8 **)&new_edid);
603 - if (ret < 0)
603 + if (ret < 0) {
604 + pm_runtime_mark_last_busy(dev->dev);
605 + pm_runtime_put_autosuspend(dev->dev);
604 606 return connector_status_disconnected;
607 + }
605 608 }
606 609
607 610 nouveau_connector_set_edid(nv_connector, new_edid);
modified drivers/gpu/drm/nouveau/nouveau_dmem.c
@@ -339,8 +339,8 @@ nouveau_dmem_chunk_alloc(struct nouveau_drm *drm, struct page **ppage,
339 339 chunk->pagemap.ops = &nouveau_dmem_pagemap_ops;
340 340 chunk->pagemap.owner = drm->dev;
341 341
342 - ret = nouveau_bo_new_pin(&drm->client, NOUVEAU_GEM_DOMAIN_VRAM, DMEM_CHUNK_SIZE,
343 - &chunk->bo);
342 + ret = nouveau_bo_new_pin(&drm->client, NOUVEAU_GEM_DOMAIN_VRAM,
343 + DMEM_CHUNK_SIZE * NR_CHUNKS, &chunk->bo);
344 344 if (ret)
345 345 goto out_release;
346 346
modified drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -585,6 +585,7 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)
585 585 if (nouveau_pmops_runtime()) {
586 586 pm_runtime_get_sync(dev->dev);
587 587 pm_runtime_forbid(dev->dev);
588 + pm_runtime_dont_use_autosuspend(dev->dev);
588 589 }
589 590
590 591 nouveau_led_fini(dev);
@@ -1148,6 +1149,7 @@ nouveau_pmops_runtime_suspend(struct device *dev)
1148 1149 {
1149 1150 struct pci_dev *pdev = to_pci_dev(dev);
1150 1151 struct nouveau_drm *drm = pci_get_drvdata(pdev);
1152 + struct nvif_device *nvif = &drm->client.device;
1151 1153 int ret;
1152 1154
1153 1155 if (!nouveau_pmops_runtime()) {
@@ -1155,6 +1157,18 @@ nouveau_pmops_runtime_suspend(struct device *dev)
1155 1157 return -EBUSY;
1156 1158 }
1157 1159
1160 + // Check if the GPU itself is ready for runtime suspend, otherwise mark as busy and check
1161 + // again in a bit.
1162 + ret = nvif_device_gcx_ready(nvif);
1163 + if (ret < 0) {
1164 + NV_ERROR(drm, "Failed to query GCX readiness (returned %d)\n", ret);
1165 + return -EBUSY;
1166 + } else if (!(ret & NV_DEVICE_GCOFF_READY)) {
1167 + NV_DEBUG(drm, "GPU isn't ready for suspend yet, delaying...\n");
1168 + pm_runtime_mark_last_busy(dev);
1169 + return -EBUSY;
1170 + }
1171 +
1158 1172 nouveau_switcheroo_optimus_dsm();
1159 1173 ret = nouveau_do_suspend(drm, true);
1160 1174 pci_save_state(pdev);
@@ -1250,10 +1264,8 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
1250 1264 mutex_unlock(&drm->clients_lock);
1251 1265
1252 1266 done:
1253 - if (ret && cli) {
1254 - nouveau_cli_fini(cli);
1267 + if (ret && cli)
1255 1268 kfree(cli);
1256 - }
1257 1269
1258 1270 pm_runtime_mark_last_busy(dev->dev);
1259 1271 pm_runtime_put_autosuspend(dev->dev);
modified drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -522,6 +522,7 @@ retry:
522 522 if (unlikely(ret)) {
523 523 if (ret != -ERESTARTSYS)
524 524 NV_PRINTK(err, cli, "fail reserve\n");
525 + drm_gem_object_put(gem);
525 526 break;
526 527 }
527 528 }
@@ -531,6 +532,7 @@ retry:
531 532 struct nouveau_vma *vma = nouveau_vma_find(nvbo, vmm);
532 533 if (!vma) {
533 534 NV_PRINTK(err, cli, "vma not found!\n");
535 + drm_gem_object_put(gem);
534 536 ret = -EINVAL;
535 537 break;
536 538 }
modified drivers/gpu/drm/nouveau/nouveau_sched.c
@@ -517,7 +517,7 @@ nouveau_sched_destroy(struct nouveau_sched **psched)
517 517 struct nouveau_sched *sched = *psched;
518 518
519 519 nouveau_sched_fini(sched);
520 - kfree(sched);
520 + kfree_rcu(sched, rcu);
521 521
522 522 *psched = NULL;
523 523 }
modified drivers/gpu/drm/nouveau/nouveau_sched.h
@@ -98,6 +98,7 @@ void nouveau_job_free(struct nouveau_job *job);
98 98
99 99 struct nouveau_sched {
100 100 struct drm_gpu_scheduler base;
101 + struct rcu_head rcu;
101 102 struct drm_sched_entity entity;
102 103 struct workqueue_struct *wq;
103 104 struct mutex mutex;
modified drivers/gpu/drm/nouveau/nouveau_uvmm.c
@@ -846,6 +846,9 @@ op_map(struct nouveau_uvma *uvma)
846 846 {
847 847 struct nouveau_bo *nvbo = nouveau_gem_object(uvma->va.gem.obj);
848 848
849 + if (drm_gpuva_invalidated(&uvma->va))
850 + return;
851 +
849 852 nouveau_uvma_map(uvma, nouveau_mem(nvbo->bo.resource));
850 853 }
851 854
@@ -1232,6 +1235,7 @@ bind_lock_validate(struct nouveau_job *job, struct drm_exec *exec,
1232 1235
1233 1236 drm_gpuva_for_each_op(va_op, op->ops) {
1234 1237 struct drm_gem_object *obj = op_gem_obj(va_op);
1238 + struct nouveau_bo *nvbo;
1235 1239
1236 1240 if (unlikely(!obj))
1237 1241 continue;
@@ -1246,8 +1250,13 @@ bind_lock_validate(struct nouveau_job *job, struct drm_exec *exec,
1246 1250 if (va_op->op == DRM_GPUVA_OP_UNMAP)
1247 1251 continue;
1248 1252
1249 - ret = nouveau_bo_validate(nouveau_gem_object(obj),
1250 - true, false);
1253 + nvbo = nouveau_gem_object(obj);
1254 + if (!(nvbo->valid_domains &
1255 + (NOUVEAU_GEM_DOMAIN_VRAM | NOUVEAU_GEM_DOMAIN_GART)))
1256 + return -EINVAL;
1257 +
1258 + nouveau_bo_placement_set(nvbo, nvbo->valid_domains, 0);
1259 + ret = nouveau_bo_validate(nvbo, true, false);
1251 1260 if (ret)
1252 1261 return ret;
1253 1262 }
modified drivers/gpu/drm/nouveau/nvif/device.c
@@ -38,6 +38,19 @@ nvif_device_time(struct nvif_device *device)
38 38 return device->user.func->time(&device->user);
39 39 }
40 40
41 + int
42 + nvif_device_gcx_ready(struct nvif_device *device)
43 + {
44 + struct nv_device_gcx_ready_v0 args = {};
45 + int ret;
46 +
47 + ret = nvif_object_mthd(&device->object, NV_DEVICE_V0_GCX_READY, &args, sizeof(args));
48 + if (ret)
49 + return ret;
50 +
51 + return args.ready;
52 + }
53 +
41 54 int
42 55 nvif_device_map(struct nvif_device *device)
43 56 {
modified drivers/gpu/drm/nouveau/nvif/vmm.c
@@ -192,6 +192,7 @@ void
192 192 nvif_vmm_dtor(struct nvif_vmm *vmm)
193 193 {
194 194 kfree(vmm->page);
195 + vmm->page = NULL;
195 196 nvif_object_dtor(&vmm->object);
196 197 }
197 198
modified drivers/gpu/drm/nouveau/nvkm/engine/device/ctrl.c
@@ -74,6 +74,7 @@ nvkm_control_mthd_pstate_attr(struct nvkm_control *ctrl, void *data, u32 size)
74 74 const struct nvkm_domain *domain;
75 75 struct nvkm_pstate *pstate;
76 76 struct nvkm_cstate *cstate;
77 + bool found = false;
77 78 int i = 0, j = -1;
78 79 u32 lo, hi;
79 80 int ret = -ENOSYS;
@@ -104,10 +105,15 @@ nvkm_control_mthd_pstate_attr(struct nvkm_control *ctrl, void *data, u32 size)
104 105
105 106 if (args->v0.state != NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT) {
106 107 list_for_each_entry(pstate, &clk->states, head) {
107 - if (i++ == args->v0.state)
108 + if (i++ == args->v0.state) {
109 + found = true;
108 110 break;
111 + }
109 112 }
110 113
114 + if (!found)
115 + return -EINVAL;
116 +
111 117 lo = pstate->base.domain[domain->name];
112 118 hi = lo;
113 119 list_for_each_entry(cstate, &pstate->list, head) {
modified drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
@@ -27,6 +27,7 @@
27 27
28 28 #include <core/client.h>
29 29 #include <subdev/fb.h>
30 + #include <subdev/gsp.h>
30 31 #include <subdev/instmem.h>
31 32 #include <subdev/timer.h>
32 33
@@ -189,6 +190,38 @@ nvkm_udevice_time(struct nvkm_udevice *udev, void *data, u32 size)
189 190 return ret;
190 191 }
191 192
193 + static int
194 + nvkm_udevice_gcx_ready(struct nvkm_udevice *udev, void *data, u32 size)
195 + {
196 + struct nvkm_object *object = &udev->object;
197 + struct nvkm_device *device = udev->device;
198 + struct nvkm_gsp *gsp = device->gsp;
199 + union {
200 + struct nv_device_gcx_ready_v0 v0;
201 + } *args = data;
202 + int ret = -ENOSYS;
203 +
204 + if (!gsp || !gsp->rm) {
205 + args->v0.ready = NV_DEVICE_GC6_READY | NV_DEVICE_GCOFF_READY;
206 + return 0;
207 + }
208 +
209 + nvif_ioctl(object, "device gcx ready size %d\n", size);
210 + ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false);
211 + if (!ret) {
212 + nvif_ioctl(object, "device gcx ready vers %d\n", args->v0.version);
213 +
214 + ret = nvkm_gsp_gcx_ready(gsp);
215 + if (ret < 0)
216 + return ret;
217 +
218 + args->v0.ready = ret;
219 + ret = 0;
220 + }
221 +
222 + return ret;
223 + }
224 +
192 225 static int
193 226 nvkm_udevice_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
194 227 {
@@ -199,6 +232,8 @@ nvkm_udevice_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
199 232 return nvkm_udevice_info(udev, data, size);
200 233 case NV_DEVICE_V0_TIME:
201 234 return nvkm_udevice_time(udev, data, size);
235 + case NV_DEVICE_V0_GCX_READY:
236 + return nvkm_udevice_gcx_ready(udev, data, size);
202 237 default:
203 238 break;
204 239 }
modified drivers/gpu/drm/nouveau/nvkm/engine/disp/uoutp.c
@@ -253,8 +253,7 @@ nvkm_uoutp_mthd_hdmi(struct nvkm_outp *outp, void *argv, u32 argc)
253 253
254 254 if (!ior->func->hdmi ||
255 255 args->v0.max_ac_packet > 0x1f ||
256 - args->v0.rekey > 0x7f ||
257 - (args->v0.scdc && !ior->func->hdmi->scdc))
256 + args->v0.rekey > 0x7f)
258 257 return -EINVAL;
259 258
260 259 if (!args->v0.enable) {
modified drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
@@ -199,16 +199,18 @@ nvkm_cstate_prog(struct nvkm_clk *clk, struct nvkm_pstate *pstate, int cstatei)
199 199 }
200 200
201 201 if (volt) {
202 - ret = nvkm_volt_set_id(volt, cstate->voltage,
203 - pstate->base.voltage, clk->temp, -1);
204 - if (ret && ret != -ENODEV)
205 - nvkm_error(subdev, "failed to lower voltage: %d\n", ret);
202 + int err = nvkm_volt_set_id(volt, cstate->voltage,
203 + pstate->base.voltage, clk->temp, -1);
204 +
205 + if (err && err != -ENODEV)
206 + nvkm_error(subdev, "failed to lower voltage: %d\n", err);
206 207 }
207 208
208 209 if (therm) {
209 - ret = nvkm_therm_cstate(therm, pstate->fanspeed, -1);
210 - if (ret && ret != -ENODEV)
211 - nvkm_error(subdev, "failed to lower fan speed: %d\n", ret);
210 + int err = nvkm_therm_cstate(therm, pstate->fanspeed, -1);
211 +
212 + if (err && err != -ENODEV)
213 + nvkm_error(subdev, "failed to lower fan speed: %d\n", err);
212 214 }
213 215
214 216 return ret;
@@ -270,13 +272,19 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
270 272 struct nvkm_fb *fb = subdev->device->fb;
271 273 struct nvkm_pci *pci = subdev->device->pci;
272 274 struct nvkm_pstate *pstate;
275 + bool found = false;
273 276 int ret, idx = 0;
274 277
275 278 list_for_each_entry(pstate, &clk->states, head) {
276 - if (idx++ == pstatei)
279 + if (idx++ == pstatei) {
280 + found = true;
277 281 break;
282 + }
278 283 }
279 284
285 + if (!found)
286 + return -EINVAL;
287 +
280 288 nvkm_debug(subdev, "setting performance state %d\n", pstatei);
281 289 clk->pstate = pstatei;
282 290
@@ -473,6 +481,7 @@ static int
473 481 nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)
474 482 {
475 483 struct nvkm_pstate *pstate;
484 + bool found = false;
476 485 int i = 0;
477 486
478 487 if (!clk->allow_reclock)
@@ -480,12 +489,14 @@ nvkm_clk_ustate_update(struct nvkm_clk *clk, int req)
480 489
481 490 if (req != -1 && req != -2) {
482 491 list_for_each_entry(pstate, &clk->states, head) {
483 - if (pstate->pstate == req)
492 + if (pstate->pstate == req) {
493 + found = true;
484 494 break;
495 + }
485 496 i++;
486 497 }
487 498
488 - if (pstate->pstate != req)
499 + if (!found)
489 500 return -EINVAL;
490 501 req = i;
491 502 }
modified drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramnv1a.c
@@ -51,6 +51,8 @@ nv1a_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram)
51 51 mib = ((mem >> 4) & 127) + 1;
52 52 }
53 53
54 + pci_dev_put(bridge);
55 +
54 56 return nvkm_ram_new_(&nv04_ram_func, fb, NVKM_RAM_TYPE_STOLEN,
55 57 mib * 1024 * 1024, pram);
56 58 }
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/base.c
@@ -20,6 +20,7 @@
20 20 * OTHER DEALINGS IN THE SOFTWARE.
21 21 */
22 22 #include "priv.h"
23 + #include <nvif/cl0080.h>
23 24
24 25 int
25 26 nvkm_gsp_intr_nonstall(struct nvkm_gsp *gsp, enum nvkm_subdev_type type, int inst)
@@ -47,6 +48,15 @@ nvkm_gsp_intr_stall(struct nvkm_gsp *gsp, enum nvkm_subdev_type type, int inst)
47 48 return -ENOENT;
48 49 }
49 50
51 + int
52 + nvkm_gsp_gcx_ready(struct nvkm_gsp *gsp)
53 + {
54 + if (!gsp->rm->api->gsp->gcx_ready)
55 + return NV_DEVICE_GC6_READY | NV_DEVICE_GCOFF_READY;
56 +
57 + return gsp->rm->api->gsp->gcx_ready(gsp);
58 + }
59 +
50 60 static int
51 61 nvkm_gsp_fini(struct nvkm_subdev *subdev, enum nvkm_suspend_state suspend)
52 62 {
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h
@@ -93,6 +93,7 @@ void r535_gsp_dtor(struct nvkm_gsp *);
93 93 int r535_gsp_oneinit(struct nvkm_gsp *);
94 94 int r535_gsp_init(struct nvkm_gsp *);
95 95 int r535_gsp_fini(struct nvkm_gsp *, enum nvkm_suspend_state suspend);
96 + int r535_gsp_gcx_ready(struct nvkm_gsp *gsp);
96 97
97 98 int nvkm_gsp_new_(const struct nvkm_gsp_fwif *, struct nvkm_device *, enum nvkm_subdev_type, int,
98 99 struct nvkm_gsp **);
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/fbsr.c
@@ -208,7 +208,7 @@ r535_fbsr_resume(struct nvkm_gsp *gsp)
208 208 }
209 209
210 210 static int
211 - r535_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)
211 + r535_fbsr_suspend(struct nvkm_gsp *gsp)
212 212 {
213 213 struct nvkm_subdev *subdev = &gsp->subdev;
214 214 struct nvkm_device *device = subdev->device;
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c
@@ -1749,7 +1749,7 @@ r535_gsp_fini(struct nvkm_gsp *gsp, enum nvkm_suspend_state suspend)
1749 1749 sr->sysmemAddrOfSuspendResumeData = gsp->sr.radix3.lvl0.addr;
1750 1750 sr->sizeOfSuspendResumeData = len;
1751 1751
1752 - ret = rm->api->fbsr->suspend(gsp, suspend == NVKM_RUNTIME_SUSPEND);
1752 + ret = rm->api->fbsr->suspend(gsp);
1753 1753 if (ret) {
1754 1754 nvkm_gsp_mem_dtor(&gsp->sr.meta);
1755 1755 nvkm_gsp_radix3_dtor(gsp, &gsp->sr.radix3);
@@ -1761,8 +1761,12 @@ r535_gsp_fini(struct nvkm_gsp *gsp, enum nvkm_suspend_state suspend)
1761 1761 * TODO: Debug the GSP firmware / RPC handling to find out why
1762 1762 * without this Turing (but none of the other architectures)
1763 1763 * ends up resetting all channels after resume.
1764 + * Additionally, runtime suspend on other architectures quickly
1765 + * becomes unreliable without this sleep. If you're experiencing
1766 + * issues with runtime suspend, try bumping this delay up and
1767 + * sending a patch if it fixes your GPU.
1764 1768 */
1765 - msleep(50);
1769 + msleep(200);
1766 1770 }
1767 1771
1768 1772 ret = r535_gsp_rpc_unloading_guest_driver(gsp, suspend);
@@ -1778,6 +1782,23 @@ r535_gsp_fini(struct nvkm_gsp *gsp, enum nvkm_suspend_state suspend)
1778 1782 return 0;
1779 1783 }
1780 1784
1785 + int
1786 + r535_gsp_get_static_memsys_info(struct nvkm_gsp *gsp)
1787 + {
1788 + NV2080_CTRL_INTERNAL_MEMSYS_GET_STATIC_CONFIG_PARAMS *ctrl;
1789 +
1790 + ctrl = nvkm_gsp_rm_ctrl_rd(&gsp->internal.device.subdevice,
1791 + NV2080_CTRL_CMD_INTERNAL_MEMSYS_GET_STATIC_CONFIG,
1792 + sizeof(*ctrl));
1793 + if (IS_ERR(ctrl))
1794 + return PTR_ERR(ctrl);
1795 +
1796 + gsp->memsys.use_raw_mode_comptagline_alloc = ctrl->bUseRawModeComptaglineAllocation;
1797 +
1798 + nvkm_gsp_rm_ctrl_done(&gsp->internal.device.subdevice, ctrl);
1799 + return 0;
1800 + }
1801 +
1781 1802 int
1782 1803 r535_gsp_init(struct nvkm_gsp *gsp)
1783 1804 {
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/nvrm/gsp.h
@@ -782,6 +782,51 @@ typedef struct NV2080_CTRL_INTERNAL_INTR_GET_KERNEL_TABLE_PARAMS {
782 782
783 783 #define GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE ((48 << 10) * 2048) // Support 2048 channels
784 784
785 + typedef struct NV2080_CTRL_INTERNAL_MEMSYS_GET_STATIC_CONFIG_PARAMS {
786 + /*! Determines if RM should use 1 to 1 Comptagline allocation policy */
787 + NvBool bOneToOneComptagLineAllocation;
788 +
789 + /*! Determines if RM should use 1 to 4 Comptagline allocation policy */
790 + NvBool bUseOneToFourComptagLineAllocation;
791 +
792 + /*! Determines if RM should use raw Comptagline allocation policy */
793 + NvBool bUseRawModeComptaglineAllocation;
794 +
795 + /*! Has COMPBIT_BACKING_SIZE been overridden to zero (i.e. disabled)? */
796 + NvBool bDisableCompbitBacking;
797 +
798 + /*! Determine if we need to disable post L2 compression */
799 + NvBool bDisablePostL2Compression;
800 +
801 + /*! Is ECC DRAM feature supported? */
802 + NvBool bEnabledEccFBPA;
803 +
804 + NvBool bL2PreFill;
805 +
806 + /*! L2 cache size */
807 + NV_DECLARE_ALIGNED(NvU64 l2CacheSize, 8);
808 +
809 + /*! Indicate whether fpba is present or not */
810 + NvBool bFbpaPresent;
811 +
812 + /*! Size covered by one comptag */
813 + NvU32 comprPageSize;
814 +
815 + /*! log32(comprPageSize) */
816 + NvU32 comprPageShift;
817 +
818 + /*! RAM type */
819 + NvU32 ramType;
820 +
821 + /*! LTC count */
822 + NvU32 ltcCount;
823 +
824 + /*! LTS per LTC count */
825 + NvU32 ltsPerLtcCount;
826 + } NV2080_CTRL_INTERNAL_MEMSYS_GET_STATIC_CONFIG_PARAMS;
827 +
828 + #define NV2080_CTRL_CMD_INTERNAL_MEMSYS_GET_STATIC_CONFIG (0x20800a1c) /* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_INTERNAL_INTERFACE_ID << 8) | NV2080_CTRL_INTERNAL_MEMSYS_GET_STATIC_CONFIG_PARAMS_MESSAGE_ID" */
829 +
785 830 typedef union rpc_message_rpc_union_field_v03_00
786 831 {
787 832 NvU32 spare;
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/fbsr.c
@@ -26,6 +26,52 @@ r570_fbsr_suspend_channels(struct nvkm_gsp *gsp, bool suspend)
26 26 return nvkm_gsp_rm_ctrl_wr(&gsp->internal.device.subdevice, ctrl);
27 27 }
28 28
29 + static int
30 + r570_fb_get_compbit_store_size(struct nvkm_gsp *gsp, u64 *size)
31 + {
32 + NV0080_CTRL_FB_GET_COMPBIT_STORE_INFO_PARAMS *ctrl;
33 +
34 + ctrl = nvkm_gsp_rm_ctrl_rd(&gsp->internal.device.object,
35 + NV0080_CTRL_CMD_FB_GET_COMPBIT_STORE_INFO,
36 + sizeof(*ctrl));
37 + if (IS_ERR(ctrl))
38 + return PTR_ERR(ctrl);
39 +
40 + *size = ctrl->Size;
41 +
42 + nvkm_gsp_rm_ctrl_done(&gsp->internal.device.object, ctrl);
43 + return 0;
44 + }
45 +
46 + static int
47 + r570_memsys_enable_raw_comp_mode(struct nvkm_gsp *gsp, bool enable)
48 + {
49 + NV2080_CTRL_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE_PARAMS *ctrl;
50 + int ret;
51 +
52 + ctrl = nvkm_gsp_rm_ctrl_get(&gsp->internal.device.subdevice,
53 + NV2080_CTRL_CMD_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE,
54 + sizeof(*ctrl));
55 + if (IS_ERR(ctrl))
56 + return PTR_ERR(ctrl);
57 +
58 + ctrl->bRawMode = enable;
59 +
60 + ret = nvkm_gsp_rm_ctrl_wr(&gsp->internal.device.subdevice, ctrl);
61 + if (!ret)
62 + nvkm_debug(&gsp->subdev, "memsys: Raw compression mode %s\n",
63 + str_enabled_disabled(enable));
64 +
65 + return ret;
66 + }
67 +
68 + static bool
69 + r570_need_raw_comp_war(struct nvkm_gsp *gsp, struct nvkm_device *device)
70 + {
71 + return (device->card_type == GA100 || device->card_type == AD100) &&
72 + gsp->memsys.use_raw_mode_comptagline_alloc;
73 + }
74 +
29 75 static void
30 76 r570_fbsr_resume(struct nvkm_gsp *gsp)
31 77 {
@@ -33,6 +79,7 @@ r570_fbsr_resume(struct nvkm_gsp *gsp)
33 79 struct nvkm_instmem *imem = device->imem;
34 80 struct nvkm_instobj *iobj;
35 81 struct nvkm_vmm *vmm;
82 + int ret;
36 83
37 84 /* Restore BAR2 page tables via BAR0 window, and re-enable BAR2. */
38 85 list_for_each_entry(iobj, &imem->boot, head) {
@@ -54,6 +101,13 @@ r570_fbsr_resume(struct nvkm_gsp *gsp)
54 101 vmm = nvkm_bar_bar1_vmm(device);
55 102 vmm->func->flush(vmm, 0);
56 103
104 + /* Re-enable raw mode if it was previously disabled */
105 + if (r570_need_raw_comp_war(gsp, device)) {
106 + ret = r570_memsys_enable_raw_comp_mode(gsp, true);
107 + if (ret)
108 + nvkm_error(&gsp->subdev, "Failed to re-enable raw comp mode\n");
109 + }
110 +
57 111 /* Resume channel scheduling. */
58 112 r570_fbsr_suspend_channels(device->gsp, false);
59 113
@@ -62,7 +116,7 @@ r570_fbsr_resume(struct nvkm_gsp *gsp)
62 116 }
63 117
64 118 static int
65 - r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtime)
119 + r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size)
66 120 {
67 121 NV2080_CTRL_INTERNAL_FBSR_INIT_PARAMS *ctrl;
68 122 struct nvkm_gsp_object memlist;
@@ -81,7 +135,7 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtim
81 135 ctrl->hClient = gsp->internal.client.object.handle;
82 136 ctrl->hSysMem = memlist.handle;
83 137 ctrl->sysmemAddrOfSuspendResumeData = gsp->sr.meta.addr;
84 - ctrl->bEnteringGcoffState = runtime ? 1 : 0;
138 + ctrl->bEnteringGcoffState = 1;
85 139
86 140 ret = nvkm_gsp_rm_ctrl_wr(&gsp->internal.device.subdevice, ctrl);
87 141 if (ret)
@@ -92,18 +146,35 @@ r570_fbsr_init(struct nvkm_gsp *gsp, struct sg_table *sgt, u64 size, bool runtim
92 146 }
93 147
94 148 static int
95 - r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)
149 + r570_fbsr_suspend(struct nvkm_gsp *gsp)
96 150 {
97 151 struct nvkm_subdev *subdev = &gsp->subdev;
98 152 struct nvkm_device *device = subdev->device;
99 153 struct nvkm_instmem *imem = device->imem;
100 154 struct nvkm_instobj *iobj;
101 - u64 size;
155 + u64 size, compbit_store_size;
102 156 int ret;
103 157
104 158 /* Stop channel scheduling. */
105 159 r570_fbsr_suspend_channels(gsp, true);
106 160
161 + /* Temporarily disable raw mode to prevent FBSR restore operations from corrupting
162 + * compressed surfaces. Required for ampere and ada.
163 + *
164 + * Nvidia bug #3172217
165 + */
166 + if (r570_need_raw_comp_war(gsp, device)) {
167 + ret = r570_memsys_enable_raw_comp_mode(gsp, false);
168 + if (ret)
169 + return ret;
170 + }
171 +
172 + ret = r570_fb_get_compbit_store_size(gsp, &compbit_store_size);
173 + if (ret < 0)
174 + return ret;
175 + nvkm_debug(&gsp->subdev, "fbsr: Compbit backing store size: 0x%llx bytes\n",
176 + compbit_store_size);
177 +
107 178 /* Save BAR2 allocations to system memory. */
108 179 list_for_each_entry(iobj, &imem->list, head) {
109 180 if (iobj->preserve) {
@@ -126,6 +197,8 @@ r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)
126 197 size = gsp->fb.heap.size;
127 198 size += gsp->fb.rsvd_size;
128 199 size += gsp->fb.bios.vga_workspace.size;
200 + size += compbit_store_size;
201 +
129 202 nvkm_debug(subdev, "fbsr: size: 0x%llx bytes\n", size);
130 203
131 204 ret = nvkm_gsp_sg(device, size, &gsp->sr.fbsr);
@@ -133,7 +206,7 @@ r570_fbsr_suspend(struct nvkm_gsp *gsp, bool runtime)
133 206 return ret;
134 207
135 208 /* Initialise FBSR on RM. */
136 - ret = r570_fbsr_init(gsp, &gsp->sr.fbsr, size, runtime);
209 + ret = r570_fbsr_init(gsp, &gsp->sr.fbsr, size);
137 210 if (ret) {
138 211 nvkm_gsp_sg_free(device, &gsp->sr.fbsr);
139 212 return ret;
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c
@@ -10,6 +10,7 @@
10 10 #include "nvrm/gsp.h"
11 11 #include "nvrm/rpcfn.h"
12 12 #include "nvrm/msgfn.h"
13 + #include "nvif/cl0080.h"
13 14
14 15 #include <core/pci.h>
15 16 #include <subdev/pci/priv.h>
@@ -137,6 +138,14 @@ r570_gsp_get_static_info(struct nvkm_gsp *gsp)
137 138 }
138 139 }
139 140
141 + ret = r535_gsp_get_static_memsys_info(gsp);
142 + if (ret) {
143 + nvkm_error(&gsp->subdev, "Retrieving static memsys info failed\n");
144 + return ret;
145 + }
146 + nvkm_debug(&gsp->subdev, "memsys: Use raw mode for comptag allocations? %s\n",
147 + str_yes_no(gsp->memsys.use_raw_mode_comptagline_alloc));
148 +
140 149 return 0;
141 150 }
142 151
@@ -207,13 +216,40 @@ r570_gsp_set_rmargs(struct nvkm_gsp *gsp, bool resume)
207 216 args->srInitArguments.bInPMTransition = 0;
208 217 } else {
209 218 args->srInitArguments.oldLevel = NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_3;
210 - args->srInitArguments.flags = 0;
219 + args->srInitArguments.flags =
220 + GPU_STATE_FLAGS_PRESERVING | GPU_STATE_FLAGS_PM_TRANSITION;
211 221 args->srInitArguments.bInPMTransition = 1;
212 222 }
213 223
214 224 args->bDmemStack = 1;
215 225 }
216 226
227 + int
228 + r570_gsp_gcx_ready(struct nvkm_gsp *gsp)
229 + {
230 + NV2080_CTRL_INTERNAL_GCX_ENTRY_PREREQUISITE_PARAMS *ctrl;
231 + int ret = 0;
232 +
233 + ctrl = nvkm_gsp_rm_ctrl_rd(&gsp->internal.device.subdevice,
234 + NV2080_CTRL_CMD_INTERNAL_GCX_ENTRY_PREREQUISITE,
235 + sizeof(*ctrl));
236 + if (IS_ERR(ctrl))
237 + return PTR_ERR(ctrl);
238 +
239 + if (ctrl->bIsGC6Satisfied)
240 + ret |= NV_DEVICE_GC6_READY;
241 + if (ctrl->bIsGCOFFSatisfied)
242 + ret |= NV_DEVICE_GCOFF_READY;
243 +
244 + nvkm_debug(&gsp->subdev,
245 + "GCX ready status: GC6=%s GCOFF=%s\n",
246 + str_yes_no(ctrl->bIsGC6Satisfied), str_yes_no(ctrl->bIsGCOFFSatisfied));
247 +
248 + nvkm_gsp_rm_ctrl_done(&gsp->internal.device.subdevice, ctrl);
249 + return ret;
250 + }
251 +
252 +
217 253 const struct nvkm_rm_api_gsp
218 254 r570_gsp = {
219 255 .set_rmargs = r570_gsp_set_rmargs,
@@ -222,4 +258,5 @@ r570_gsp = {
222 258 .xlat_mc_engine_idx = r570_gsp_xlat_mc_engine_idx,
223 259 .drop_post_nocat_record = r570_gsp_drop_post_nocat_record,
224 260 .sr_data_size = r570_gsp_sr_data_size,
261 + .gcx_ready = r570_gsp_gcx_ready,
225 262 };
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/fbsr.h
@@ -16,4 +16,33 @@ typedef struct NV2080_CTRL_INTERNAL_FBSR_INIT_PARAMS {
16 16 NV_DECLARE_ALIGNED(NvU64 sysmemAddrOfSuspendResumeData, 8);
17 17 } NV2080_CTRL_INTERNAL_FBSR_INIT_PARAMS;
18 18
19 + #define NV0080_CTRL_CMD_FB_GET_COMPBIT_STORE_INFO (0x801306) /* finn: Evaluated from "(FINN_NV01_DEVICE_0_FB_INTERFACE_ID << 8) | NV0080_CTRL_FB_GET_COMPBIT_STORE_INFO_PARAMS_MESSAGE_ID" */
20 +
21 + typedef struct NV0080_CTRL_FB_GET_COMPBIT_STORE_INFO_PARAMS {
22 + NV_DECLARE_ALIGNED(NvU64 Size, 8);
23 + NV_DECLARE_ALIGNED(NvU64 Address, 8);
24 + NvU32 AddressSpace;
25 + NvU32 MaxCompbitLine;
26 + NvU32 comptagsPerCacheLine;
27 + NvU32 cacheLineSize;
28 + NvU32 cacheLineSizePerSlice;
29 + NvU32 cacheLineFetchAlignment;
30 + NV_DECLARE_ALIGNED(NvU64 backingStoreBase, 8);
31 + NvU32 gobsPerComptagPerSlice;
32 + NvU32 backingStoreCbcBase;
33 + NvU32 comptaglineAllocationPolicy;
34 + NV_DECLARE_ALIGNED(NvU64 privRegionStartOffset, 8);
35 + NvU32 cbcCoveragePerSlice;
36 + } NV0080_CTRL_FB_GET_COMPBIT_STORE_INFO_PARAMS;
37 +
38 + #define NV0080_CTRL_CMD_FB_GET_COMPBIT_STORE_INFO_ADDRESS_SPACE_UNKNOWN 0 // ADDR_UNKNOWN
39 + #define NV0080_CTRL_CMD_FB_GET_COMPBIT_STORE_INFO_ADDRESS_SPACE_SYSMEM 1 // ADDR_SYSMEM
40 + #define NV0080_CTRL_CMD_FB_GET_COMPBIT_STORE_INFO_ADDRESS_SPACE_FBMEM 2 // ADDR_FBMEM
41 +
42 + #define NV2080_CTRL_CMD_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE (0x20800a6f) /* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_INTERNAL_INTERFACE_ID << 8) | NV2080_CTRL_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE_PARAMS_MESSAGE_ID" */
43 +
44 + typedef struct NV2080_CTRL_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE_PARAMS {
45 + NvBool bRawMode;
46 + } NV2080_CTRL_INTERNAL_MEMSYS_PROGRAM_RAW_COMPRESSION_MODE_PARAMS;
47 +
19 48 #endif
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/gsp.h
@@ -523,6 +523,14 @@ typedef struct
523 523
524 524 #define NV2080_CTRL_GPU_SET_POWER_STATE_GPU_LEVEL_3 (0x00000003U)
525 525
526 + #define GPU_STATE_FLAGS_PRESERVING BIT(0) // GPU state is preserved
527 + #define GPU_STATE_FLAGS_VGA_TRANSITION BIT(1) // To be used with GPU_STATE_FLAGS_PRESERVING.
528 + #define GPU_STATE_FLAGS_PM_TRANSITION BIT(2) // To be used with GPU_STATE_FLAGS_PRESERVING.
529 + #define GPU_STATE_FLAGS_PM_SUSPEND BIT(3)
530 + #define GPU_STATE_FLAGS_PM_HIBERNATE BIT(4)
531 + #define GPU_STATE_FLAGS_GC6_TRANSITION BIT(5) // To be used with GPU_STATE_FLAGS_PRESERVING.
532 + #define GPU_STATE_FLAGS_FAST_UNLOAD BIT(6) // Used during windows restart, skips stateDestroy steps
533 +
526 534 typedef struct
527 535 {
528 536 // Magic for verification by secure ucode
@@ -631,4 +639,11 @@ typedef struct GSP_FMC_BOOT_PARAMS
631 639 } GSP_FMC_BOOT_PARAMS;
632 640
633 641 #define GSP_FW_HEAP_PARAM_BASE_RM_SIZE_GH100 (14 << 20) // Hopper+
642 +
643 + #define NV2080_CTRL_CMD_INTERNAL_GCX_ENTRY_PREREQUISITE (0x2080a7d7)
644 +
645 + typedef struct NV2080_CTRL_INTERNAL_GCX_ENTRY_PREREQUISITE_PARAMS {
646 + NvBool bIsGC6Satisfied;
647 + NvBool bIsGCOFFSatisfied;
648 + } NV2080_CTRL_INTERNAL_GCX_ENTRY_PREREQUISITE_PARAMS;
634 649 #endif
modified drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h
@@ -40,6 +40,7 @@ struct nvkm_rm_api {
40 40 void (*drop_send_user_shared_data)(struct nvkm_gsp *);
41 41 void (*drop_post_nocat_record)(struct nvkm_gsp *);
42 42 u32 (*sr_data_size)(struct nvkm_gsp *);
43 + int (*gcx_ready)(struct nvkm_gsp *gsp);
43 44 } *gsp;
44 45
45 46 const struct nvkm_rm_api_rpc {
@@ -79,7 +80,7 @@ struct nvkm_rm_api {
79 80 } *device;
80 81
81 82 const struct nvkm_rm_api_fbsr {
82 - int (*suspend)(struct nvkm_gsp *, bool runtime);
83 + int (*suspend)(struct nvkm_gsp *);
83 84 void (*resume)(struct nvkm_gsp *);
84 85 } *fbsr;
85 86
@@ -174,6 +175,8 @@ int r535_gr_chan_new(struct nvkm_gr *, struct nvkm_chan *, const struct nvkm_ocl
174 175 int r535_gr_promote_ctx(struct r535_gr *, bool golden, struct nvkm_vmm *,
175 176 struct nvkm_memory **pctxbuf_mem, struct nvkm_vma **pctxbuf_vma,
176 177 struct nvkm_gsp_object *chan);
178 + int r570_gsp_gcx_ready(struct nvkm_gsp *gsp);
179 + int r535_gsp_get_static_memsys_info(struct nvkm_gsp *gsp);
177 180 extern const struct nvkm_rm_api_engine r535_nvdec;
178 181 extern const struct nvkm_rm_api_engine r535_nvenc;
179 182 extern const struct nvkm_rm_api_engine r535_nvjpg;
modified drivers/gpu/drm/panthor/panthor_sched.c
@@ -3674,6 +3674,9 @@ int panthor_group_create(struct panthor_file *pfile,
3674 3674 hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
3675 3675 return -EINVAL;
3676 3676
3677 + if (group_args->queues.count > sched->cs_slot_count)
3678 + return -EINVAL;
3679 +
3677 3680 group = kzalloc_obj(*group);
3678 3681 if (!group)
3679 3682 return -ENOMEM;
modified drivers/gpu/drm/qxl/qxl_display.c
@@ -30,6 +30,7 @@
30 30 #include <drm/drm_drv.h>
31 31 #include <drm/drm_atomic.h>
32 32 #include <drm/drm_atomic_helper.h>
33 + #include <drm/drm_blend.h>
33 34 #include <drm/drm_edid.h>
34 35 #include <drm/drm_encoder.h>
35 36 #include <drm/drm_framebuffer.h>
@@ -993,6 +994,9 @@ static struct drm_plane *qxl_create_plane(struct qxl_device *qdev,
993 994
994 995 drm_plane_helper_add(plane, helper_funcs);
995 996
997 + drm_plane_create_blend_mode_property(plane,
998 + BIT(DRM_MODE_BLEND_PREMULTI));
999 +
996 1000 return plane;
997 1001
998 1002 free_plane:
modified drivers/gpu/drm/rockchip/Kconfig
@@ -68,6 +68,7 @@ config ROCKCHIP_CDN_DP
68 68
69 69 config ROCKCHIP_DW_DP
70 70 bool "Rockchip specific extensions for Synopsys DW DP"
71 + select DRM_BRIDGE_CONNECTOR
71 72 help
72 73 This selects support for Rockchip SoC specific extensions
73 74 to enable Synopsys DesignWare Cores based DisplayPort transmit
@@ -145,6 +146,8 @@ config ROCKCHIP_RGB
145 146 config ROCKCHIP_RK3066_HDMI
146 147 bool "Rockchip specific extensions for RK3066 HDMI"
147 148 depends on DRM_ROCKCHIP
149 + select DRM_DISPLAY_HELPER
150 + select DRM_BRIDGE_CONNECTOR
148 151 help
149 152 This selects support for Rockchip SoC specific extensions
150 153 for the RK3066 HDMI driver. If you want to enable
modified drivers/gpu/drm/rockchip/analogix_dp-rockchip.c
@@ -241,10 +241,11 @@ static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder,
241 241 of_graph_get_remote_port(endpoint.local_node);
242 242
243 243 of_property_read_u32(remote_port, "reg", &port_id);
244 - sprintf(name, "%s vp%d", remote_port_parent->full_name, port_id);
244 + snprintf(name, sizeof(name), "%s vp%d",
245 + remote_port_parent->full_name, port_id);
245 246 } else {
246 - sprintf(name, "%s %s",
247 - remote_port_parent->full_name, endpoint.id ? "vopl" : "vopb");
247 + snprintf(name, sizeof(name), "%s %s",
248 + remote_port_parent->full_name, endpoint.id ? "vopl" : "vopb");
248 249 }
249 250
250 251 DRM_DEV_DEBUG(dp->dev, "vop %s output to dp\n", (ret) ? "LIT" : "BIG");
modified drivers/gpu/drm/scheduler/sched_entity.c
@@ -559,9 +559,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
559 559 */
560 560 smp_wmb();
561 561
562 + spin_lock(&entity->lock);
562 563 spsc_queue_pop(&entity->job_queue);
563 -
564 564 drm_sched_rq_pop_entity(entity);
565 + spin_unlock(&entity->lock);
565 566
566 567 /* Jobs and entities might have different lifecycles. Since we're
567 568 * removing the job from the entities queue, set the jobs entity pointer
@@ -647,6 +648,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
647 648 * Make sure to set the submit_ts first, to avoid a race.
648 649 */
649 650 sched_job->submit_ts = submit_ts = ktime_get();
651 +
652 + spin_lock(&entity->lock);
653 +
650 654 first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
651 655
652 656 /* first job wakes up scheduler */
@@ -657,5 +661,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
657 661 if (sched)
658 662 drm_sched_wakeup(sched);
659 663 }
664 +
665 + spin_unlock(&entity->lock);
660 666 }
661 667 EXPORT_SYMBOL(drm_sched_entity_push_job);
modified drivers/gpu/drm/scheduler/sched_rq.c
@@ -257,19 +257,17 @@ static ktime_t drm_sched_entity_get_job_ts(struct drm_sched_entity *entity)
257 257 struct drm_gpu_scheduler *
258 258 drm_sched_rq_add_entity(struct drm_sched_entity *entity, ktime_t ts)
259 259 {
260 + struct drm_sched_rq *rq = entity->rq;
260 261 struct drm_gpu_scheduler *sched;
261 - struct drm_sched_rq *rq;
262 262
263 263 /* Add the entity to the run queue */
264 - spin_lock(&entity->lock);
265 - if (entity->stopped) {
266 - spin_unlock(&entity->lock);
264 + lockdep_assert_held(&entity->lock);
267 265
266 + if (entity->stopped) {
268 267 DRM_ERROR("Trying to push to a killed entity\n");
269 268 return NULL;
270 269 }
271 270
272 - rq = entity->rq;
273 271 spin_lock(&rq->lock);
274 272 sched = rq->sched;
275 273
@@ -289,7 +287,6 @@ drm_sched_rq_add_entity(struct drm_sched_entity *entity, ktime_t ts)
289 287 drm_sched_rq_update_fifo_locked(entity, rq, ts);
290 288
291 289 spin_unlock(&rq->lock);
292 - spin_unlock(&entity->lock);
293 290
294 291 return sched;
295 292 }
@@ -343,16 +340,17 @@ drm_sched_rq_next_rr_ts(struct drm_sched_rq *rq,
343 340 */
344 341 void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)
345 342 {
343 + struct drm_sched_rq *rq = entity->rq;
346 344 struct drm_sched_job *next_job;
347 - struct drm_sched_rq *rq;
345 +
346 + lockdep_assert_held(&entity->lock);
347 +
348 + spin_lock(&rq->lock);
348 349
349 350 /*
350 351 * Update the entity's location in the min heap according to
351 352 * the timestamp of the next job, if any.
352 353 */
353 - spin_lock(&entity->lock);
354 - rq = entity->rq;
355 - spin_lock(&rq->lock);
356 354 next_job = drm_sched_entity_queue_peek(entity);
357 355 if (next_job) {
358 356 ktime_t ts;
@@ -375,8 +373,8 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)
375 373 drm_sched_entity_save_vruntime(entity, min_vruntime);
376 374 }
377 375 }
376 +
378 377 spin_unlock(&rq->lock);
379 - spin_unlock(&entity->lock);
380 378 }
381 379
382 380 /**
modified drivers/gpu/drm/scheduler/tests/mock_scheduler.c
@@ -1,6 +1,8 @@
1 1 // SPDX-License-Identifier: GPL-2.0
2 2 /* Copyright (c) 2025 Valve Corporation */
3 3
4 + #include <kunit/device.h>
5 +
4 6 #include "sched_tests.h"
5 7
6 8 /*
@@ -288,6 +290,7 @@ static const struct drm_sched_backend_ops drm_mock_scheduler_ops = {
288 290 */
289 291 struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout)
290 292 {
293 + static unsigned int instance;
291 294 struct drm_sched_init_args args = {
292 295 .ops = &drm_mock_scheduler_ops,
293 296 .num_rqs = DRM_SCHED_PRIORITY_COUNT,
@@ -297,11 +300,19 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout)
297 300 .name = "drm-mock-scheduler",
298 301 };
299 302 struct drm_mock_scheduler *sched;
303 + struct device *dev;
304 + char name[64];
300 305 int ret;
301 306
302 307 sched = kunit_kzalloc(test, sizeof(*sched), GFP_KERNEL);
303 308 KUNIT_ASSERT_NOT_NULL(test, sched);
304 309
310 + snprintf(name, sizeof(name), "%s-%u", args.name, instance++);
311 + dev = kunit_device_register(test, name);
312 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
313 +
314 + args.dev = dev;
315 +
305 316 ret = drm_sched_init(&sched->base, &args);
306 317 KUNIT_ASSERT_EQ(test, ret, 0);
307 318
modified drivers/gpu/drm/ttm/ttm_bo.c
@@ -1434,7 +1434,7 @@ ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct ttm_buffer_object *bo)
1434 1434
1435 1435 if (ttm_tt_is_populated(tt)) {
1436 1436 ret = ttm_tt_swapout(bdev, tt, swapout_walk->gfp_flags);
1437 - if (!ret) {
1437 + if (ret > 0) {
1438 1438 spin_lock(&bdev->lru_lock);
1439 1439 ttm_resource_del_bulk_move_unevictable(bo->resource, bo);
1440 1440 ttm_resource_move_to_lru_tail(bo->resource);
modified drivers/gpu/drm/vboxvideo/vbox_mode.c
@@ -15,6 +15,7 @@
15 15
16 16 #include <drm/drm_atomic.h>
17 17 #include <drm/drm_atomic_helper.h>
18 + #include <drm/drm_blend.h>
18 19 #include <drm/drm_edid.h>
19 20 #include <drm/drm_fb_helper.h>
20 21 #include <drm/drm_fourcc.h>
@@ -540,6 +541,9 @@ static struct drm_plane *vbox_create_plane(struct vbox_private *vbox,
540 541
541 542 drm_plane_helper_add(plane, helper_funcs);
542 543
544 + drm_plane_create_blend_mode_property(plane,
545 + BIT(DRM_MODE_BLEND_COVERAGE));
546 +
543 547 return plane;
544 548
545 549 free_plane:
modified drivers/gpu/drm/vc4/vc4_bo.c
@@ -204,7 +204,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
204 204 struct list_head *new_list;
205 205 uint32_t i;
206 206
207 - new_list = kmalloc_objs(struct list_head, new_size);
207 + new_list = kvmalloc_objs(struct list_head, new_size);
208 208 if (!new_list)
209 209 return NULL;
210 210
@@ -224,7 +224,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
224 224 for (i = vc4->bo_cache.size_list_size; i < new_size; i++)
225 225 INIT_LIST_HEAD(&new_list[i]);
226 226
227 - kfree(vc4->bo_cache.size_list);
227 + kvfree(vc4->bo_cache.size_list);
228 228 vc4->bo_cache.size_list = new_list;
229 229 vc4->bo_cache.size_list_size = new_size;
230 230 }
@@ -1052,6 +1052,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)
1052 1052 cancel_work_sync(&vc4->bo_cache.time_work);
1053 1053
1054 1054 vc4_bo_cache_purge(dev);
1055 + kvfree(vc4->bo_cache.size_list);
1055 1056
1056 1057 for (i = 0; i < vc4->num_labels; i++) {
1057 1058 if (vc4->bo_labels[i].num_allocated) {
modified drivers/gpu/drm/vc4/vc4_drv.c
@@ -360,8 +360,11 @@ static int vc4_drm_bind(struct device *dev)
360 360 }
361 361
362 362 ret = aperture_remove_all_conflicting_devices(driver->name);
363 - if (ret)
363 + if (ret) {
364 + if (firmware)
365 + rpi_firmware_put(firmware);
364 366 goto err;
367 + }
365 368
366 369 if (firmware) {
367 370 ret = rpi_firmware_property(firmware,
modified drivers/gpu/drm/vc4/vc4_drv.h
@@ -1051,7 +1051,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
1051 1051 /* vc4_v3d.c */
1052 1052 extern struct platform_driver vc4_v3d_driver;
1053 1053 extern const struct of_device_id vc4_v3d_dt_match[];
1054 - int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
1054 + int vc4_v3d_get_bin_slot(struct vc4_dev *vc4, long timeout);
1055 1055 int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
1056 1056 void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
1057 1057 int vc4_v3d_pm_get(struct vc4_dev *vc4);
modified drivers/gpu/drm/vc4/vc4_gem.c
@@ -877,11 +877,17 @@ vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
877 877 drm_gem_object_put(&bo->base.base);
878 878 }
879 879
880 - /* Free up the allocation of any bin slots we used. */
880 + /* Free up the allocation of any bin slots we used. Jobs that ran to
881 + * completion had their slots released in vc4_irq_finish_render_job().
882 + * Only jobs that never completed still have slots to be released here.
883 + */
881 884 spin_lock_irqsave(&vc4->job_lock, irqflags);
882 885 vc4->bin_alloc_used &= ~exec->bin_slots;
883 886 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
884 887
888 + /* Let anyone waiting on the binner pool retry. */
889 + wake_up_all(&vc4->job_wait_queue);
890 +
885 891 /* Release the reference on the binner BO if needed. */
886 892 if (exec->bin_bo_used)
887 893 vc4_v3d_bin_bo_put(vc4);
modified drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -894,7 +894,7 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
894 894
895 895 spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
896 896
897 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, 0);
897 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, VC4_HDMI_RAM_PACKET_ENABLE);
898 898
899 899 HDMI_WRITE(HDMI_VID_CTL, HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_CLRRGB);
900 900
@@ -1663,9 +1663,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
1663 1663 WARN_ONCE(ret, "Timeout waiting for "
1664 1664 "VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE\n");
1665 1665 } else {
1666 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG,
1667 - HDMI_READ(HDMI_RAM_PACKET_CONFIG) &
1668 - ~(VC4_HDMI_RAM_PACKET_ENABLE));
1669 1666 HDMI_WRITE(HDMI_SCHEDULER_CONTROL,
1670 1667 HDMI_READ(HDMI_SCHEDULER_CONTROL) &
1671 1668 ~VC4_HDMI_SCHEDULER_CONTROL_MODE_HDMI);
@@ -1684,9 +1681,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
1684 1681 WARN_ON(!(HDMI_READ(HDMI_SCHEDULER_CONTROL) &
1685 1682 VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE));
1686 1683
1687 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG,
1688 - VC4_HDMI_RAM_PACKET_ENABLE);
1689 -
1690 1684 spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
1691 1685 vc4_hdmi->packet_ram_enabled = true;
1692 1686
@@ -3143,6 +3137,11 @@ static int vc5_hdmi_init_resources(struct drm_device *drm,
3143 3137 static int vc4_hdmi_runtime_suspend(struct device *dev)
3144 3138 {
3145 3139 struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
3140 + unsigned long flags;
3141 +
3142 + spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
3143 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, 0);
3144 + spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
3146 3145
3147 3146 clk_disable_unprepare(vc4_hdmi->audio_clock);
3148 3147 clk_disable_unprepare(vc4_hdmi->hsm_clock);
@@ -3153,9 +3152,8 @@ static int vc4_hdmi_runtime_suspend(struct device *dev)
3153 3152 static int vc4_hdmi_runtime_resume(struct device *dev)
3154 3153 {
3155 3154 struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
3156 - unsigned long __maybe_unused flags;
3155 + unsigned long rate, flags;
3157 3156 u32 __maybe_unused value;
3158 - unsigned long rate;
3159 3157 int ret;
3160 3158
3161 3159 ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
@@ -3201,6 +3199,10 @@ static int vc4_hdmi_runtime_resume(struct device *dev)
3201 3199 }
3202 3200 #endif
3203 3201
3202 + spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
3203 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, VC4_HDMI_RAM_PACKET_ENABLE);
3204 + spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
3205 +
3204 3206 return 0;
3205 3207
3206 3208 err_disable_clk:
modified drivers/gpu/drm/vc4/vc4_irq.c
@@ -74,7 +74,7 @@ vc4_overflow_mem_work(struct work_struct *work)
74 74
75 75 bo = vc4->bin_bo;
76 76
77 - bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
77 + bin_bo_slot = vc4_v3d_get_bin_slot(vc4, msecs_to_jiffies(500));
78 78 if (bin_bo_slot < 0) {
79 79 drm_err(&vc4->base, "Couldn't allocate binner overflow mem\n");
80 80 goto complete;
@@ -165,6 +165,10 @@ vc4_irq_finish_render_job(struct drm_device *dev)
165 165 trace_vc4_rcl_end_irq(dev, exec->seqno);
166 166
167 167 vc4->finished_seqno++;
168 +
169 + vc4->bin_alloc_used &= ~exec->bin_slots;
170 + exec->bin_slots = 0;
171 +
168 172 list_move_tail(&exec->head, &vc4->job_done_list);
169 173
170 174 nextbin = vc4_first_bin_job(vc4);
@@ -276,7 +280,7 @@ vc4_irq_disable(struct drm_device *dev)
276 280 V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
277 281
278 282 /* Finish any interrupt handler still in flight. */
279 - synchronize_irq(vc4->irq);
283 + disable_irq(vc4->irq);
280 284
281 285 cancel_work_sync(&vc4->overflow_mem_work);
282 286 }
@@ -284,7 +288,6 @@ vc4_irq_disable(struct drm_device *dev)
284 288 int vc4_irq_install(struct drm_device *dev, int irq)
285 289 {
286 290 struct vc4_dev *vc4 = to_vc4_dev(dev);
287 - int ret;
288 291
289 292 if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
290 293 return -ENODEV;
@@ -298,19 +301,8 @@ int vc4_irq_install(struct drm_device *dev, int irq)
298 301 init_waitqueue_head(&vc4->job_wait_queue);
299 302 INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
300 303
301 - /* Clear any pending interrupts someone might have left around
302 - * for us.
303 - */
304 - V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
305 -
306 - ret = devm_request_irq(dev->dev, irq, vc4_irq, 0,
307 - dev_name(dev->dev), dev);
308 - if (ret)
309 - return ret;
310 -
311 - vc4_irq_enable(dev);
312 -
313 - return 0;
304 + return devm_request_irq(dev->dev, irq, vc4_irq, IRQF_NO_AUTOEN,
305 + dev_name(dev->dev), dev);
314 306 }
315 307
316 308 void vc4_irq_uninstall(struct drm_device *dev)
modified drivers/gpu/drm/vc4/vc4_kms.c
@@ -1188,7 +1188,7 @@ int vc4_kms_load(struct drm_device *dev)
1188 1188
1189 1189 drm_mode_config_reset(dev);
1190 1190
1191 - drm_kms_helper_poll_init(dev);
1191 + drmm_kms_helper_poll_init(dev);
1192 1192
1193 1193 return 0;
1194 1194 }
modified drivers/gpu/drm/vc4/vc4_v3d.c
@@ -9,6 +9,7 @@
9 9 #include <linux/component.h>
10 10 #include <linux/platform_device.h>
11 11 #include <linux/pm_runtime.h>
12 + #include <linux/timer.h>
12 13
13 14 #include <drm/drm_print.h>
14 15
@@ -172,46 +173,42 @@ static void vc4_v3d_init_hw(struct drm_device *dev)
172 173 V3D_WRITE(V3D_VPMBASE, 0);
173 174 }
174 175
175 - int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
176 + static int bin_slot_try_alloc(struct vc4_dev *vc4)
176 177 {
177 - struct drm_device *dev = &vc4->base;
178 - unsigned long irqflags;
179 178 int slot;
180 - uint64_t seqno = 0;
181 - struct vc4_exec_info *exec;
182 179
183 - if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
184 - return -ENODEV;
180 + guard(spinlock_irqsave)(&vc4->job_lock);
185 181
186 - try_again:
187 - spin_lock_irqsave(&vc4->job_lock, irqflags);
188 182 slot = ffs(~vc4->bin_alloc_used);
189 183 if (slot != 0) {
190 184 /* Switch from ffs() bit index to a 0-based index. */
191 185 slot--;
192 186 vc4->bin_alloc_used |= BIT(slot);
193 - spin_unlock_irqrestore(&vc4->job_lock, irqflags);
194 - return slot;
187 + } else {
188 + slot = -ENOMEM;
195 189 }
196 190
197 - /* Couldn't find an open slot. Wait for render to complete
198 - * and try again.
199 - */
200 - exec = vc4_last_render_job(vc4);
201 - if (exec)
202 - seqno = exec->seqno;
203 - spin_unlock_irqrestore(&vc4->job_lock, irqflags);
191 + return slot;
192 + }
204 193
205 - if (seqno) {
206 - int ret = vc4_wait_for_seqno(dev, seqno, ~0ull, true);
194 + int vc4_v3d_get_bin_slot(struct vc4_dev *vc4, long timeout)
195 + {
196 + int slot;
197 + long ret;
207 198
208 - if (ret == 0)
209 - goto try_again;
199 + if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
200 + return -ENODEV;
210 201
202 + /* If the pool is full, wait for a job to release its slots. */
203 + ret = wait_event_interruptible_timeout(vc4->job_wait_queue,
204 + (slot = bin_slot_try_alloc(vc4)) >= 0,
205 + timeout);
206 + if (ret < 0)
211 207 return ret;
212 - }
208 + if (ret == 0)
209 + return -ENOMEM;
213 210
214 - return -ENOMEM;
211 + return slot;
215 212 }
216 213
217 214 /*
@@ -396,6 +393,7 @@ static int vc4_v3d_runtime_resume(struct device *dev)
396 393 vc4_v3d_init_hw(&vc4->base);
397 394
398 395 vc4_irq_enable(&vc4->base);
396 + enable_irq(vc4->irq);
399 397
400 398 return 0;
401 399 }
@@ -452,6 +450,12 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
452 450 return ret;
453 451 vc4->irq = ret;
454 452
453 + ret = vc4_irq_install(drm, vc4->irq);
454 + if (ret) {
455 + drm_err(drm, "Failed to install IRQ handler\n");
456 + return ret;
457 + }
458 +
455 459 ret = devm_pm_runtime_enable(dev);
456 460 if (ret)
457 461 return ret;
@@ -473,12 +477,6 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
473 477 V3D_WRITE(V3D_BPOA, 0);
474 478 V3D_WRITE(V3D_BPOS, 0);
475 479
476 - ret = vc4_irq_install(drm, vc4->irq);
477 - if (ret) {
478 - drm_err(drm, "Failed to install IRQ handler\n");
479 - goto err_put_runtime_pm;
480 - }
481 -
482 480 pm_runtime_use_autosuspend(dev);
483 481 pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
484 482 pm_runtime_put_autosuspend(dev);
@@ -497,8 +495,15 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master,
497 495 struct drm_device *drm = data;
498 496 struct vc4_dev *vc4 = to_vc4_dev(drm);
499 497
498 + /* A straggler vc4_reset() re-enables the interrupt. */
499 + timer_shutdown_sync(&vc4->hangcheck.timer);
500 + cancel_work_sync(&vc4->hangcheck.reset_work);
501 +
500 502 vc4_irq_uninstall(drm);
501 503
504 + /* Flush rather than cancel, so queued completions release their jobs. */
505 + flush_work(&vc4->job_done_work);
506 +
502 507 /* Disable the binner's overflow memory address, so the next
503 508 * driver probe (if any) doesn't try to reuse our old
504 509 * allocation.
modified drivers/gpu/drm/vc4/vc4_validate.c
@@ -402,7 +402,7 @@ validate_tile_binning_config(VALIDATE_ARGS)
402 402 return -EINVAL;
403 403 }
404 404
405 - bin_slot = vc4_v3d_get_bin_slot(vc4);
405 + bin_slot = vc4_v3d_get_bin_slot(vc4, MAX_SCHEDULE_TIMEOUT);
406 406 if (bin_slot < 0) {
407 407 if (bin_slot != -EINTR && bin_slot != -ERESTARTSYS) {
408 408 drm_err(dev, "Failed to allocate binner memory: %d\n",
modified drivers/gpu/drm/verisilicon/vs_cursor_plane.c
@@ -11,6 +11,7 @@
11 11
12 12 #include <drm/drm_atomic.h>
13 13 #include <drm/drm_atomic_helper.h>
14 + #include <drm/drm_blend.h>
14 15 #include <drm/drm_crtc.h>
15 16 #include <drm/drm_fourcc.h>
16 17 #include <drm/drm_framebuffer.h>
@@ -267,6 +268,7 @@ struct drm_plane *vs_cursor_plane_init(struct drm_device *drm_dev,
267 268 return plane;
268 269
269 270 drm_plane_helper_add(plane, &vs_cursor_plane_helper_funcs);
271 + drm_plane_create_blend_mode_property(plane, BIT(DRM_MODE_BLEND_COVERAGE));
270 272
271 273 return plane;
272 274 }
modified drivers/gpu/drm/verisilicon/vs_hwdb.c
@@ -10,82 +10,50 @@
10 10 #include "vs_dc_top_regs.h"
11 11 #include "vs_hwdb.h"
12 12
13 - static const u32 vs_formats_array_no_yuv444[] = {
13 + static const u32 vs_primary_formats_array_no_yuv444[] = {
14 14 DRM_FORMAT_XRGB4444,
15 15 DRM_FORMAT_XBGR4444,
16 16 DRM_FORMAT_RGBX4444,
17 17 DRM_FORMAT_BGRX4444,
18 - DRM_FORMAT_ARGB4444,
19 - DRM_FORMAT_ABGR4444,
20 - DRM_FORMAT_RGBA4444,
21 - DRM_FORMAT_BGRA4444,
22 18 DRM_FORMAT_XRGB1555,
23 19 DRM_FORMAT_XBGR1555,
24 20 DRM_FORMAT_RGBX5551,
25 21 DRM_FORMAT_BGRX5551,
26 - DRM_FORMAT_ARGB1555,
27 - DRM_FORMAT_ABGR1555,
28 - DRM_FORMAT_RGBA5551,
29 - DRM_FORMAT_BGRA5551,
30 22 DRM_FORMAT_RGB565,
31 23 DRM_FORMAT_BGR565,
32 24 DRM_FORMAT_XRGB8888,
33 25 DRM_FORMAT_XBGR8888,
34 26 DRM_FORMAT_RGBX8888,
35 27 DRM_FORMAT_BGRX8888,
36 - DRM_FORMAT_ARGB8888,
37 - DRM_FORMAT_ABGR8888,
38 - DRM_FORMAT_RGBA8888,
39 - DRM_FORMAT_BGRA8888,
40 - DRM_FORMAT_ARGB2101010,
41 - DRM_FORMAT_ABGR2101010,
42 - DRM_FORMAT_RGBA1010102,
43 - DRM_FORMAT_BGRA1010102,
44 28 /* TODO: non-RGB formats */
45 29 };
46 30
47 - static const u32 vs_formats_array_with_yuv444[] = {
31 + static const u32 vs_primary_formats_array_with_yuv444[] = {
48 32 DRM_FORMAT_XRGB4444,
49 33 DRM_FORMAT_XBGR4444,
50 34 DRM_FORMAT_RGBX4444,
51 35 DRM_FORMAT_BGRX4444,
52 - DRM_FORMAT_ARGB4444,
53 - DRM_FORMAT_ABGR4444,
54 - DRM_FORMAT_RGBA4444,
55 - DRM_FORMAT_BGRA4444,
56 36 DRM_FORMAT_XRGB1555,
57 37 DRM_FORMAT_XBGR1555,
58 38 DRM_FORMAT_RGBX5551,
59 39 DRM_FORMAT_BGRX5551,
60 - DRM_FORMAT_ARGB1555,
61 - DRM_FORMAT_ABGR1555,
62 - DRM_FORMAT_RGBA5551,
63 - DRM_FORMAT_BGRA5551,
64 40 DRM_FORMAT_RGB565,
65 41 DRM_FORMAT_BGR565,
66 42 DRM_FORMAT_XRGB8888,
67 43 DRM_FORMAT_XBGR8888,
68 44 DRM_FORMAT_RGBX8888,
69 45 DRM_FORMAT_BGRX8888,
70 - DRM_FORMAT_ARGB8888,
71 - DRM_FORMAT_ABGR8888,
72 - DRM_FORMAT_RGBA8888,
73 - DRM_FORMAT_BGRA8888,
74 - DRM_FORMAT_ARGB2101010,
75 - DRM_FORMAT_ABGR2101010,
76 - DRM_FORMAT_RGBA1010102,
77 - DRM_FORMAT_BGRA1010102,
78 46 /* TODO: non-RGB formats */
79 47 };
80 48
81 49 static const struct vs_formats vs_formats_no_yuv444 = {
82 - .array = vs_formats_array_no_yuv444,
83 - .num = ARRAY_SIZE(vs_formats_array_no_yuv444)
50 + .primary_array = vs_primary_formats_array_no_yuv444,
51 + .primary_num = ARRAY_SIZE(vs_primary_formats_array_no_yuv444)
84 52 };
85 53
86 54 static const struct vs_formats vs_formats_with_yuv444 = {
87 - .array = vs_formats_array_with_yuv444,
88 - .num = ARRAY_SIZE(vs_formats_array_with_yuv444)
55 + .primary_array = vs_primary_formats_array_with_yuv444,
56 + .primary_num = ARRAY_SIZE(vs_primary_formats_array_with_yuv444)
89 57 };
90 58
91 59 static struct vs_chip_identity vs_chip_identities[] = {
modified drivers/gpu/drm/verisilicon/vs_hwdb.h
@@ -10,8 +10,8 @@
10 10 #include <linux/types.h>
11 11
12 12 struct vs_formats {
13 - const u32 *array;
14 - unsigned int num;
13 + const u32 *primary_array;
14 + unsigned int primary_num;
15 15 };
16 16
17 17 struct vs_chip_identity {
modified drivers/gpu/drm/verisilicon/vs_primary_plane.c
@@ -168,8 +168,8 @@ struct drm_plane *vs_primary_plane_init(struct drm_device *drm_dev, struct vs_dc
168 168
169 169 plane = drmm_universal_plane_alloc(drm_dev, struct drm_plane, dev, 0,
170 170 &vs_primary_plane_funcs,
171 - dc->identity.formats->array,
172 - dc->identity.formats->num,
171 + dc->identity.formats->primary_array,
172 + dc->identity.formats->primary_num,
173 173 NULL,
174 174 DRM_PLANE_TYPE_PRIMARY,
175 175 NULL);
modified drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -114,6 +114,8 @@ struct virtio_gpu_object {
114 114 bool dumb;
115 115 bool created;
116 116 bool attached;
117 + /* a guest-bound transfer is queued and its mapping not yet synced */
118 + bool from_host_pending;
117 119 bool host3d_blob, guest_blob;
118 120 uint32_t blob_mem, blob_flags;
119 121
@@ -196,6 +198,9 @@ struct virtio_gpu_vbuffer {
196 198 struct list_head list;
197 199
198 200 uint32_t seqno;
201 +
202 + /* guest-bound transfer whose shmem backing needs a CPU sync */
203 + bool sync_for_cpu;
199 204 };
200 205
201 206 struct virtio_gpu_output {
modified drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -45,7 +45,7 @@ static int virtio_gpu_gem_create(struct drm_file *file,
45 45
46 46 ret = drm_gem_handle_create(file, &obj->base.base, &handle);
47 47 if (ret) {
48 - drm_gem_object_release(&obj->base.base);
48 + drm_gem_object_put(&obj->base.base);
49 49 return ret;
50 50 }
51 51
modified drivers/gpu/drm/virtio/virtgpu_ioctl.c
@@ -185,7 +185,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
185 185
186 186 ret = drm_gem_handle_create(file, obj, &handle);
187 187 if (ret) {
188 - drm_gem_object_release(obj);
188 + drm_gem_object_put(obj);
189 189 return ret;
190 190 }
191 191
@@ -261,6 +261,27 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,
261 261 if (ret != 0)
262 262 goto err_put_free;
263 263
264 + if (virtio_gpu_is_shmem(bo) && virtio_gpu_use_dma_api(vgdev->vdev)) {
265 + /*
266 + * The sync on completion restores the whole mapping, so an
267 + * earlier transfer has to be done before this one snapshots it.
268 + * Otherwise the snapshot predates anything the CPU wrote once
269 + * that transfer's fence signalled, and the later sync would
270 + * discard it. Nothing can add a fence behind our back here,
271 + * since doing so takes the reservation we already hold.
272 + * This writes the pages, so it waits as a writer does. READ
273 + * usage covers existing readers.
274 + */
275 + long wait = dma_resv_wait_timeout(objs->objs[0]->resv,
276 + DMA_RESV_USAGE_READ, true,
277 + MAX_SCHEDULE_TIMEOUT);
278 +
279 + if (wait < 0) {
280 + ret = wait;
281 + goto err_unlock;
282 + }
283 + }
284 +
264 285 fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context, 0);
265 286 if (!fence) {
266 287 ret = -ENOMEM;
@@ -320,6 +341,28 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,
320 341 if (ret != 0)
321 342 goto err_put_free;
322 343
344 + /*
345 + * A transfer the other way may have queued without yet syncing
346 + * its mapping. Pushing the guest pages into it now would
347 + * discard what the device wrote there, so wait for that sync:
348 + * it runs before the fence it belongs to is signalled. The
349 + * flag is only set under this reservation, so it cannot appear
350 + * behind our back, and the acquire pairs with the release in
351 + * that sync, so finding it clear means the pages it wrote are
352 + * visible here too.
353 + */
354 + if (smp_load_acquire(&bo->from_host_pending)) {
355 + long wait = dma_resv_wait_timeout(objs->objs[0]->resv,
356 + DMA_RESV_USAGE_WRITE,
357 + true,
358 + MAX_SCHEDULE_TIMEOUT);
359 +
360 + if (wait < 0) {
361 + ret = wait;
362 + goto err_unlock;
363 + }
364 + }
365 +
323 366 ret = -ENOMEM;
324 367 fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context,
325 368 0);
@@ -557,14 +600,14 @@ static int virtio_gpu_resource_create_blob_ioctl(struct drm_device *dev,
557 600 if (params.blob_flags & VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE) {
558 601 ret = virtio_gpu_resource_assign_uuid(vgdev, bo);
559 602 if (ret) {
560 - drm_gem_object_release(obj);
603 + drm_gem_object_put(obj);
561 604 return ret;
562 605 }
563 606 }
564 607
565 608 ret = drm_gem_handle_create(file, obj, &handle);
566 609 if (ret) {
567 - drm_gem_object_release(obj);
610 + drm_gem_object_put(obj);
568 611 return ret;
569 612 }
570 613
modified drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -24,6 +24,7 @@
24 24 */
25 25
26 26 #include <drm/drm_atomic_helper.h>
27 + #include <drm/drm_blend.h>
27 28 #include <drm/drm_damage_helper.h>
28 29 #include <drm/drm_fourcc.h>
29 30 #include <drm/drm_gem_atomic_helper.h>
@@ -609,6 +610,9 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
609 610
610 611 if (type == DRM_PLANE_TYPE_PRIMARY)
611 612 drm_plane_enable_fb_damage_clips(plane);
613 + else if (type == DRM_PLANE_TYPE_CURSOR)
614 + drm_plane_create_blend_mode_property(plane,
615 + BIT(DRM_MODE_BLEND_PREMULTI));
612 616
613 617 return plane;
614 618 }
modified drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -349,7 +349,7 @@ struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
349 349 }
350 350 }
351 351
352 - if (!vgdev->has_resource_blob)
352 + if (!vgdev->has_resource_blob || vgdev->has_virgl_3d)
353 353 return drm_gem_prime_import(dev, buf);
354 354
355 355 bo = kzalloc_obj(*bo);
modified drivers/gpu/drm/virtio/virtgpu_submit.c
@@ -389,10 +389,13 @@ static int virtio_gpu_init_submit(struct virtio_gpu_submit *submit,
389 389 if ((exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_OUT) ||
390 390 exbuf->num_out_syncobjs ||
391 391 exbuf->num_bo_handles ||
392 - drm_fence_event)
392 + drm_fence_event) {
393 393 out_fence = virtio_gpu_fence_alloc(vgdev, fence_ctx, ring_idx);
394 - else
394 + if (!out_fence)
395 + return -ENOMEM;
396 + } else {
395 397 out_fence = NULL;
398 + }
396 399
397 400 if (drm_fence_event) {
398 401 err = virtio_gpu_fence_event_create(dev, file, out_fence, ring_idx);
@@ -538,6 +541,10 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
538 541 virtio_gpu_process_post_deps(&submit);
539 542 virtio_gpu_complete_submit(&submit);
540 543 cleanup:
544 + if (ret && submit.out_fence && submit.out_fence->e) {
545 + drm_event_cancel_free(dev, &submit.out_fence->e->base);
546 + submit.out_fence->e = NULL;
547 + }
541 548 virtio_gpu_cleanup_submit(&submit);
542 549
543 550 return ret;
modified drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -256,6 +256,33 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work)
256 256 } while (!virtqueue_enable_cb(vgdev->ctrlq.vq));
257 257 spin_unlock(&vgdev->ctrlq.qlock);
258 258
259 + /*
260 + * Sync guest-bound transfers before signalling anything, so that a
261 + * waiter cannot read the backing pages while what the device wrote is
262 + * still in a bounce buffer. This cannot be folded into the loop below:
263 + * virtio_gpu_fence_event_process() also signals every earlier fence in
264 + * the same context, so any entry there may signal this entry's fence.
265 + */
266 + list_for_each_entry(entry, &reclaim_list, list) {
267 + if (entry->sync_for_cpu) {
268 + struct virtio_gpu_object *bo =
269 + gem_to_virtio_gpu_obj(entry->objs->objs[0]);
270 +
271 + dma_sync_sgtable_for_cpu(vgdev->vdev->dev.parent,
272 + bo->base.sgt, DMA_FROM_DEVICE);
273 + /*
274 + * Release, so a transfer the other way that skips its
275 + * wait on the strength of this cannot go on to read
276 + * the backing pages before the sync above is visible.
277 + * Nothing orders the two otherwise: where the mapping
278 + * bounces on a coherent device the sync is a plain
279 + * copy, and dma_direct_sync_sg_for_cpu() emits its
280 + * barrier only for the non-coherent case.
281 + */
282 + smp_store_release(&bo->from_host_pending, false);
283 + }
284 + }
285 +
259 286 list_for_each_entry(entry, &reclaim_list, list) {
260 287 resp = (struct virtio_gpu_ctrl_hdr *)entry->resp_buf;
261 288
@@ -1278,12 +1305,31 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,
1278 1305 struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(objs->objs[0]);
1279 1306 struct virtio_gpu_transfer_host_3d *cmd_p;
1280 1307 struct virtio_gpu_vbuffer *vbuf;
1308 + bool use_dma_api = virtio_gpu_use_dma_api(vgdev->vdev);
1281 1309
1282 1310 cmd_p = virtio_gpu_alloc_cmd(vgdev, &vbuf, sizeof(*cmd_p));
1283 1311 memset(cmd_p, 0, sizeof(*cmd_p));
1284 1312
1285 1313 vbuf->objs = objs;
1286 1314
1315 + if (virtio_gpu_is_shmem(bo) && use_dma_api) {
1316 + /*
1317 + * The device writes only the requested box, so prime the
1318 + * mapping with the current contents: otherwise the sync on
1319 + * completion would hand back whatever a bounce buffer held for
1320 + * the regions the device does not touch.
1321 + */
1322 + dma_sync_sgtable_for_device(vgdev->vdev->dev.parent,
1323 + bo->base.sgt, DMA_TO_DEVICE);
1324 + vbuf->sync_for_cpu = true;
1325 + /*
1326 + * Set under the reservation the caller holds, so a transfer
1327 + * the other way cannot miss it and push the guest pages into
1328 + * the mapping while the device still owns it.
1329 + */
1330 + WRITE_ONCE(bo->from_host_pending, true);
1331 + }
1332 +
1287 1333 cmd_p->hdr.type = cpu_to_le32(VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D);
1288 1334 cmd_p->hdr.ctx_id = cpu_to_le32(ctx_id);
1289 1335 cmd_p->resource_id = cpu_to_le32(bo->hw_res_handle);
modified drivers/gpu/drm/virtio/virtgpu_vram.c
@@ -215,16 +215,12 @@ int virtio_gpu_vram_create(struct virtio_gpu_device *vgdev,
215 215
216 216 /* Create fake offset */
217 217 ret = drm_gem_create_mmap_offset(obj);
218 - if (ret) {
219 - kfree(vram);
220 - return ret;
221 - }
218 + if (ret)
219 + goto err_release_obj;
222 220
223 221 ret = virtio_gpu_resource_id_get(vgdev, &vram->base.hw_res_handle);
224 - if (ret) {
225 - kfree(vram);
226 - return ret;
227 - }
222 + if (ret)
223 + goto err_release_obj;
228 224
229 225 virtio_gpu_cmd_resource_create_blob(vgdev, &vram->base, params, NULL,
230 226 0);
@@ -240,6 +236,11 @@ int virtio_gpu_vram_create(struct virtio_gpu_device *vgdev,
240 236
241 237 *bo_ptr = &vram->base;
242 238 return 0;
239 +
240 + err_release_obj:
241 + drm_gem_object_release(obj);
242 + kfree(vram);
243 + return ret;
243 244 }
244 245
245 246 void virtio_gpu_vram_map_deferred(struct virtio_gpu_object_vram *vram)
modified drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
@@ -324,6 +324,7 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
324 324 unsigned long kmap_num;
325 325 SVGA3dCopyBox *box;
326 326 u32 box_count;
327 + u64 src_extent;
327 328 void *virtual;
328 329 bool is_iomem;
329 330 struct vmw_dma_cmd {
@@ -335,6 +336,8 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
335 336 vmw_surface_get_desc(VMW_CURSOR_SNOOP_FORMAT);
336 337 const u32 image_pitch = VMW_CURSOR_SNOOP_WIDTH * desc->pitchBytesPerBlock;
337 338
339 + BUILD_BUG_ON(sizeof(*srf->snooper.image) != desc->pitchBytesPerBlock);
340 +
338 341 cmd = container_of(header, struct vmw_dma_cmd, header);
339 342
340 343 /* No snooper installed, nothing to copy */
@@ -372,8 +375,19 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
372 375 return;
373 376 }
374 377
378 + if (box->w == 0 || box->h == 0)
379 + return;
380 +
381 + src_extent = (u64)(box->h - 1) * cmd->dma.guest.pitch +
382 + (u64)box->w * desc->pitchBytesPerBlock;
383 + if (src_extent > bo->base.size) {
384 + DRM_ERROR("Cursor snoop source of %llu bytes exceeds the %zu byte buffer\n",
385 + src_extent, bo->base.size);
386 + return;
387 + }
388 +
375 389 kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT;
376 - kmap_num = (VMW_CURSOR_SNOOP_HEIGHT * image_pitch) >> PAGE_SHIFT;
390 + kmap_num = PFN_UP(src_extent);
377 391
378 392 ret = ttm_bo_reserve(bo, true, false, NULL);
379 393 if (unlikely(ret != 0)) {
@@ -387,14 +401,16 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
387 401
388 402 virtual = ttm_kmap_obj_virtual(&map, &is_iomem);
389 403
390 - if (box->w == VMW_CURSOR_SNOOP_WIDTH && cmd->dma.guest.pitch == image_pitch) {
404 + if (box->w == VMW_CURSOR_SNOOP_WIDTH &&
405 + box->h == VMW_CURSOR_SNOOP_HEIGHT &&
406 + cmd->dma.guest.pitch == image_pitch) {
391 407 memcpy(srf->snooper.image, virtual,
392 408 VMW_CURSOR_SNOOP_HEIGHT * image_pitch);
393 409 } else {
394 - /* Image is unsigned pointer. */
410 + /* The destination stride is in pixels. */
395 411 for (i = 0; i < box->h; i++)
396 - memcpy(srf->snooper.image + i * image_pitch,
397 - virtual + i * cmd->dma.guest.pitch,
412 + memcpy(srf->snooper.image + i * VMW_CURSOR_SNOOP_WIDTH,
413 + virtual + (size_t)i * cmd->dma.guest.pitch,
398 414 box->w * desc->pitchBytesPerBlock);
399 415 }
400 416 srf->snooper.id++;
modified drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -20,10 +20,18 @@
20 20 #include <drm/drm_rect.h>
21 21 #include <drm/drm_sysfs.h>
22 22 #include <drm/drm_edid.h>
23 + #include <drm/drm_blend.h>
23 24
24 25 void vmw_du_init(struct vmw_display_unit *du)
25 26 {
26 27 vmw_vkms_crtc_init(&du->crtc);
28 + drm_plane_create_blend_mode_property(&du->primary,
29 + BIT(DRM_MODE_BLEND_PIXEL_NONE) |
30 + BIT(DRM_MODE_BLEND_PREMULTI));
31 + // Check that the cursor plane was actually initialized
32 + if (du->crtc.cursor == &du->cursor.base)
33 + drm_plane_create_blend_mode_property(&du->cursor.base,
34 + BIT(DRM_MODE_BLEND_PREMULTI));
27 35 }
28 36
29 37 void vmw_du_cleanup(struct vmw_display_unit *du)
modified drivers/gpu/drm/xe/instructions/xe_gpu_commands.h
@@ -46,6 +46,7 @@
46 46 #define GFX_OP_PIPE_CONTROL(len) ((0x3<<29)|(0x3<<27)|(0x2<<24)|((len)-2))
47 47
48 48 #define PIPE_CONTROL0_QUEUE_DRAIN_MODE BIT(12)
49 + #define PIPE_CONTROL0_UNTYPED_DATAPORT_CACHE_FLUSH BIT(11) /* gen12 */
49 50 #define PIPE_CONTROL0_L3_READ_ONLY_CACHE_INVALIDATE BIT(10) /* gen12 */
50 51 #define PIPE_CONTROL0_HDC_PIPELINE_FLUSH BIT(9) /* gen12 */
51 52
modified drivers/gpu/drm/xe/xe_pagefault.c
@@ -16,6 +16,7 @@
16 16 #include "xe_hw_engine.h"
17 17 #include "xe_pagefault.h"
18 18 #include "xe_pagefault_types.h"
19 + #include "xe_pm.h"
19 20 #include "xe_svm.h"
20 21 #include "xe_trace_bo.h"
21 22 #include "xe_vm.h"
@@ -292,9 +293,17 @@ static void xe_pagefault_queue_work(struct work_struct *w)
292 293 {
293 294 struct xe_pagefault_queue *pf_queue =
294 295 container_of(w, typeof(*pf_queue), worker);
296 + struct xe_device *xe = pf_queue->xe;
295 297 struct xe_pagefault pf;
296 298 unsigned long threshold;
297 299
300 + /*
301 + * A live VM holds a PM reference, but a torn-down VM does not.
302 + * Guard the entire worker loop to safely drain stale faults and
303 + * prevent autosuspends from desyncing batched CT flushes.
304 + */
305 + guard(xe_pm_runtime)(xe);
306 +
298 307 #define USM_QUEUE_MAX_RUNTIME_MS 20
299 308 threshold = jiffies + msecs_to_jiffies(USM_QUEUE_MAX_RUNTIME_MS);
300 309
@@ -365,6 +374,7 @@ static int xe_pagefault_queue_init(struct xe_device *xe,
365 374 drm_dbg(&xe->drm, "xe_pagefault_entry_size=%d, total_num_eus=%d, pf_queue->size=%u",
366 375 xe_pagefault_entry_size(), total_num_eus, pf_queue->size);
367 376
377 + pf_queue->xe = xe;
368 378 spin_lock_init(&pf_queue->lock);
369 379 INIT_WORK(&pf_queue->worker, xe_pagefault_queue_work);
370 380
modified drivers/gpu/drm/xe/xe_pagefault_types.h
@@ -8,6 +8,7 @@
8 8
9 9 #include <linux/workqueue.h>
10 10
11 + struct xe_device;
11 12 struct xe_gt;
12 13 struct xe_pagefault;
13 14
@@ -118,6 +119,8 @@ struct xe_pagefault {
118 119 * queue to absorb the device’s worst-case number of outstanding faults.
119 120 */
120 121 struct xe_pagefault_queue {
122 + /** @xe: Back-pointer to the Xe device */
123 + struct xe_device *xe;
121 124 /**
122 125 * @data: Data in queue containing struct xe_pagefault, protected by
123 126 * @lock
modified drivers/gpu/drm/xe/xe_ring_ops.c
@@ -212,6 +212,7 @@ static int emit_render_cache_flush(struct xe_sched_job *job, u32 *dw, int i)
212 212 {
213 213 struct xe_exec_queue *q = job->q;
214 214 struct xe_gt *gt = q->gt;
215 + struct xe_device *xe = gt_to_xe(gt);
215 216 bool lacks_render = !(gt->info.engine_mask & XE_HW_ENGINE_RCS_MASK);
216 217 u32 flags0, flags1;
217 218
@@ -220,6 +221,16 @@ static int emit_render_cache_flush(struct xe_sched_job *job, u32 *dw, int i)
220 221 LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR, 0);
221 222
222 223 flags0 = PIPE_CONTROL0_HDC_PIPELINE_FLUSH;
224 + /*
225 + * Prior to MTL, HDC Pipeline Flush reliably also flushes the LSC
226 + * untyped L1 dataport cache, provided HDC_CHICKEN0 is programmed
227 + * correctly. Starting with MTL that coupling no longer holds
228 + * regardless of how HDC_CHICKEN0 is programmed, but explicitly
229 + * requesting the flush via PIPE_CONTROL is itself only reliable
230 + * from Xe2 onward, so only gate it in on Xe2+.
231 + */
232 + if (GRAPHICS_VERx100(xe) >= 2000)
233 + flags0 |= PIPE_CONTROL0_UNTYPED_DATAPORT_CACHE_FLUSH;
223 234 flags1 = (PIPE_CONTROL_TILE_CACHE_FLUSH |
224 235 PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH |
225 236 PIPE_CONTROL_DEPTH_CACHE_FLUSH |
modified drivers/hwmon/applesmc.c
@@ -1128,12 +1128,17 @@ static void applesmc_release_light_sensor(void)
1128 1128
1129 1129 static int applesmc_create_key_backlight(void)
1130 1130 {
1131 + int ret;
1132 +
1131 1133 if (!smcreg.has_key_backlight)
1132 1134 return 0;
1133 1135 applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
1134 1136 if (!applesmc_led_wq)
1135 1137 return -ENOMEM;
1136 - return led_classdev_register(&pdev->dev, &applesmc_backlight);
1138 + ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
1139 + if (ret)
1140 + destroy_workqueue(applesmc_led_wq);
1141 + return ret;
1137 1142 }
1138 1143
1139 1144 static void applesmc_release_key_backlight(void)
modified drivers/hwmon/aspeed-pwm-tacho.c
@@ -934,7 +934,9 @@ static int aspeed_pwm_tacho_probe(struct platform_device *pdev)
934 934 "missing or invalid reset controller device tree entry");
935 935 return PTR_ERR(priv->rst);
936 936 }
937 - reset_control_deassert(priv->rst);
937 + ret = reset_control_deassert(priv->rst);
938 + if (ret)
939 + return ret;
938 940
939 941 ret = devm_add_action_or_reset(dev, aspeed_pwm_tacho_remove, priv);
940 942 if (ret)
modified drivers/hwmon/asus_rog_ryujin.c
@@ -184,6 +184,7 @@ static int rog_ryujin_write_expanded(struct rog_ryujin_data *priv, const u8 *cmd
184 184 static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, int cmd_length,
185 185 struct completion *status_completion)
186 186 {
187 + unsigned long flags;
187 188 int ret;
188 189
189 190 /*
@@ -191,9 +192,9 @@ static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, i
191 192 * completion. Reinit is done because hidraw could have triggered
192 193 * the raw event parsing and marked the passed in completion as done.
193 194 */
194 - spin_lock_bh(&priv->status_report_request_lock);
195 + spin_lock_irqsave(&priv->status_report_request_lock, flags);
195 196 reinit_completion(status_completion);
196 - spin_unlock_bh(&priv->status_report_request_lock);
197 + spin_unlock_irqrestore(&priv->status_report_request_lock, flags);
197 198
198 199 /* Send command for getting data */
199 200 ret = rog_ryujin_write_expanded(priv, cmd, cmd_length);
@@ -421,11 +422,19 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo
421 422 int size)
422 423 {
423 424 struct rog_ryujin_data *priv = hid_get_drvdata(hdev);
425 + unsigned long flags;
424 426
425 - if (data[0] != RYUJIN_CMD_PREFIX)
427 + if (size < 2 || data[0] != RYUJIN_CMD_PREFIX)
426 428 return 0;
427 429
430 + spin_lock_irqsave(&priv->status_report_request_lock, flags);
431 +
428 432 if (data[1] == RYUJIN_GET_COOLER_STATUS_CMD_RESPONSE) {
433 + if (size <= priv->info->temp_offset + 1 ||
434 + size <= priv->info->pump_speed_offset + 1 ||
435 + size <= priv->info->fan_speed_offset + 1)
436 + goto unlock;
437 +
429 438 /* Received coolant temp and speeds of pump and internal fan */
430 439 priv->temp_input[0] = data[priv->info->temp_offset] * 1000 +
431 440 data[priv->info->temp_offset + 1] * 100;
@@ -437,6 +446,9 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo
437 446 if (!completion_done(&priv->cooler_status_received))
438 447 complete_all(&priv->cooler_status_received);
439 448 } else if (data[1] == RYUJIN_GET_CONTROLLER_SPEED_CMD_RESPONSE) {
449 + if (size <= RYUJIN_CONTROLLER_SPEED_3 + 1)
450 + goto unlock;
451 +
440 452 /* Received speeds of four fans attached to the controller */
441 453 priv->speed_input[2] = get_unaligned_le16(data + RYUJIN_CONTROLLER_SPEED_1);
442 454 priv->speed_input[3] = get_unaligned_le16(data + RYUJIN_CONTROLLER_SPEED_2);
@@ -446,6 +458,9 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo
446 458 if (!completion_done(&priv->controller_status_received))
447 459 complete_all(&priv->controller_status_received);
448 460 } else if (data[1] == RYUJIN_GET_COOLER_DUTY_CMD_RESPONSE) {
461 + if (size <= RYUJIN_INTERNAL_FAN_DUTY)
462 + goto unlock;
463 +
449 464 /* Received report for pump and internal fan duties (in %) */
450 465 if (data[RYUJIN_PUMP_DUTY] == 0 && data[RYUJIN_INTERNAL_FAN_DUTY] == 0) {
451 466 /*
@@ -463,7 +478,7 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo
463 478 * We're expecting a report, so parse it.
464 479 */
465 480 goto read_cooler_duty;
466 - return 0;
481 + goto unlock;
467 482 }
468 483 read_cooler_duty:
469 484 priv->duty_input[0] = rog_ryujin_percent_to_pwm(data[RYUJIN_PUMP_DUTY]);
@@ -472,6 +487,9 @@ read_cooler_duty:
472 487 if (!completion_done(&priv->cooler_duty_received))
473 488 complete_all(&priv->cooler_duty_received);
474 489 } else if (data[1] == RYUJIN_GET_CONTROLLER_DUTY_CMD_RESPONSE) {
490 + if (size <= RYUJIN_CONTROLLER_DUTY)
491 + goto unlock;
492 +
475 493 /* Received report for controller duty for fans (in PWM) */
476 494 if (data[RYUJIN_CONTROLLER_DUTY] == 0) {
477 495 /*
@@ -489,7 +507,7 @@ read_cooler_duty:
489 507 * We're expecting a report, so parse it.
490 508 */
491 509 goto read_controller_duty;
492 - return 0;
510 + goto unlock;
493 511 }
494 512 read_controller_duty:
495 513 priv->duty_input[2] = data[RYUJIN_CONTROLLER_DUTY];
@@ -498,6 +516,8 @@ read_controller_duty:
498 516 complete_all(&priv->controller_duty_received);
499 517 }
500 518
519 + unlock:
520 + spin_unlock_irqrestore(&priv->status_report_request_lock, flags);
501 521 return 0;
502 522 }
503 523
modified drivers/hwmon/chipcap2.c
@@ -92,11 +92,6 @@ struct cc2_data {
92 92 bool process_irqs;
93 93 };
94 94
95 - enum cc2_chan_addr {
96 - CC2_CHAN_TEMP = 0,
97 - CC2_CHAN_HUMIDITY,
98 - };
99 -
100 95 /* %RH as a per cent mille from a register value */
101 96 static long cc2_rh_convert(u16 data)
102 97 {
@@ -499,7 +494,7 @@ static irqreturn_t cc2_low_interrupt(int irq, void *data)
499 494
500 495 if (cc2->process_irqs) {
501 496 hwmon_notify_event(cc2->hwmon, hwmon_humidity,
502 - hwmon_humidity_min_alarm, CC2_CHAN_HUMIDITY);
497 + hwmon_humidity_min_alarm, 0);
503 498 cc2->rh_alarm.low_alarm = true;
504 499 }
505 500
@@ -512,7 +507,7 @@ static irqreturn_t cc2_high_interrupt(int irq, void *data)
512 507
513 508 if (cc2->process_irqs) {
514 509 hwmon_notify_event(cc2->hwmon, hwmon_humidity,
515 - hwmon_humidity_max_alarm, CC2_CHAN_HUMIDITY);
510 + hwmon_humidity_max_alarm, 0);
516 511 cc2->rh_alarm.high_alarm = true;
517 512 }
518 513
modified drivers/hwmon/corsair-cpro.c
@@ -566,21 +566,18 @@ static int bootloader_show(struct seq_file *seqf, void *unused)
566 566 }
567 567 DEFINE_SHOW_ATTRIBUTE(bootloader);
568 568
569 - static void ccp_debugfs_init(struct ccp_device *ccp)
569 + static void ccp_debugfs_init(struct ccp_device *ccp, bool fw_valid, bool bl_valid)
570 570 {
571 571 char name[32];
572 - int ret;
573 572
574 573 scnprintf(name, sizeof(name), "corsaircpro-%s", dev_name(&ccp->hdev->dev));
575 574 ccp->debugfs = debugfs_create_dir(name, NULL);
576 575
577 - ret = get_fw_version(ccp);
578 - if (!ret)
576 + if (fw_valid)
579 577 debugfs_create_file("firmware_version", 0444,
580 578 ccp->debugfs, ccp, &firmware_fops);
581 579
582 - ret = get_bl_version(ccp);
583 - if (!ret)
580 + if (bl_valid)
584 581 debugfs_create_file("bootloader_version", 0444,
585 582 ccp->debugfs, ccp, &bootloader_fops);
586 583 }
@@ -588,6 +585,7 @@ static void ccp_debugfs_init(struct ccp_device *ccp)
588 585 static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id)
589 586 {
590 587 struct ccp_device *ccp;
588 + bool fw_valid, bl_valid;
591 589 int ret;
592 590
593 591 ccp = devm_kzalloc(&hdev->dev, sizeof(*ccp), GFP_KERNEL);
@@ -632,17 +630,27 @@ static int ccp_probe(struct hid_device *hdev, const struct hid_device_id *id)
632 630 if (ret)
633 631 goto out_hw_close;
634 632
635 - ccp_debugfs_init(ccp);
633 + /*
634 + * Query the versions before registering the hwmon device: they send
635 + * USB commands without holding ccp->mutex, which is only safe while
636 + * nothing else can call send_usb_cmd().
637 + */
638 + fw_valid = !get_fw_version(ccp);
639 + bl_valid = !get_bl_version(ccp);
636 640
637 641 ccp->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsaircpro",
638 642 ccp, &ccp_chip_info, NULL);
639 643 if (IS_ERR(ccp->hwmon_dev)) {
640 644 ret = PTR_ERR(ccp->hwmon_dev);
641 - goto out_hw_close;
645 + goto out_debugfs_remove;
642 646 }
643 647
648 + ccp_debugfs_init(ccp, fw_valid, bl_valid);
649 +
644 650 return 0;
645 651
652 + out_debugfs_remove:
653 + debugfs_remove_recursive(ccp->debugfs);
646 654 out_hw_close:
647 655 hid_hw_close(hdev);
648 656 hid_device_io_stop(hdev);
modified drivers/hwmon/gpio-fan.c
@@ -12,6 +12,7 @@
12 12 #include <linux/slab.h>
13 13 #include <linux/interrupt.h>
14 14 #include <linux/irq.h>
15 + #include <linux/devm-helpers.h>
15 16 #include <linux/platform_device.h>
16 17 #include <linux/err.h>
17 18 #include <linux/kstrtox.h>
@@ -84,6 +85,7 @@ static DEVICE_ATTR_RO(fan1_alarm);
84 85 static int fan_alarm_init(struct gpio_fan_data *fan_data)
85 86 {
86 87 int alarm_irq;
88 + int err;
87 89 struct device *dev = fan_data->dev;
88 90
89 91 /*
@@ -94,7 +96,11 @@ static int fan_alarm_init(struct gpio_fan_data *fan_data)
94 96 if (alarm_irq <= 0)
95 97 return 0;
96 98
97 - INIT_WORK(&fan_data->alarm_work, fan_alarm_notify);
99 + err = devm_work_autocancel(dev, &fan_data->alarm_work,
100 + fan_alarm_notify);
101 + if (err)
102 + return err;
103 +
98 104 irq_set_irq_type(alarm_irq, IRQ_TYPE_EDGE_BOTH);
99 105 return devm_request_irq(dev, alarm_irq, fan_alarm_irq_handler,
100 106 IRQF_SHARED, "GPIO fan alarm", fan_data);
@@ -606,8 +612,11 @@ static void gpio_fan_shutdown(struct platform_device *pdev)
606 612 {
607 613 struct gpio_fan_data *fan_data = platform_get_drvdata(pdev);
608 614
609 - if (fan_data->gpios)
615 + if (fan_data->gpios) {
616 + mutex_lock(&fan_data->lock);
610 617 set_fan_speed(fan_data, 0);
618 + mutex_unlock(&fan_data->lock);
619 + }
611 620 }
612 621
613 622 static int gpio_fan_runtime_suspend(struct device *dev)
modified drivers/hwmon/hwmon.c
@@ -318,6 +318,11 @@ static int hwmon_attr_base(enum hwmon_sensor_types type)
318 318 return 1;
319 319 }
320 320
321 + static bool is_hwmon_device(struct device *dev)
322 + {
323 + return dev->class == &hwmon_class;
324 + }
325 +
321 326 #if IS_REACHABLE(CONFIG_I2C)
322 327
323 328 /*
@@ -338,7 +343,7 @@ static int hwmon_attr_base(enum hwmon_sensor_types type)
338 343
339 344 static int hwmon_match_device(struct device *dev, const void *data)
340 345 {
341 - return dev->class == &hwmon_class;
346 + return is_hwmon_device(dev);
342 347 }
343 348
344 349 static ssize_t pec_show(struct device *dev, const struct device_attribute *dummy,
@@ -371,18 +376,17 @@ static ssize_t pec_store(struct device *dev, const struct device_attribute *deva
371 376 * handling is not required.
372 377 */
373 378 hwdev = to_hwmon_device(hdev);
374 - guard(mutex)(&hwdev->lock);
375 - if (hwdev->chip->ops->write) {
376 - err = hwdev->chip->ops->write(hdev, hwmon_chip, hwmon_chip_pec, 0, val);
377 - if (err && err != -EOPNOTSUPP)
378 - goto put;
379 + scoped_guard(mutex, &hwdev->lock) {
380 + if (hwdev->chip->ops->write) {
381 + err = hwdev->chip->ops->write(hdev, hwmon_chip, hwmon_chip_pec, 0, val);
382 + if (err && err != -EOPNOTSUPP)
383 + goto put;
384 + }
385 + if (!val)
386 + client->flags &= ~I2C_CLIENT_PEC;
387 + else
388 + client->flags |= I2C_CLIENT_PEC;
379 389 }
380 -
381 - if (!val)
382 - client->flags &= ~I2C_CLIENT_PEC;
383 - else
384 - client->flags |= I2C_CLIENT_PEC;
385 -
386 390 err = count;
387 391 put:
388 392 put_device(hdev);
@@ -782,6 +786,9 @@ int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
782 786 const char *template;
783 787 int base;
784 788
789 + if (WARN(!is_hwmon_device(dev), "%s is not a hardware monitoring device\n",
790 + dev_name(dev)))
791 + return -EINVAL;
785 792 if (type >= ARRAY_SIZE(__templates))
786 793 return -EINVAL;
787 794 if (attr >= __templates_size[type])
modified drivers/hwmon/ina2xx.c
@@ -8,6 +8,7 @@
8 8 */
9 9
10 10 #include <linux/bitfield.h>
11 + #include <linux/bitops.h>
11 12 #include <linux/bits.h>
12 13 #include <linux/delay.h>
13 14 #include <linux/device.h>
@@ -129,6 +130,17 @@ enum ina2xx_ids {
129 130 sy24655
130 131 };
131 132
133 + enum ina2xx_alert_type {
134 + INA2XX_ALERT_NONE,
135 + INA2XX_ALERT_CURRENT_LOW,
136 + INA2XX_ALERT_CURRENT_HIGH,
137 + INA2XX_ALERT_POWER_HIGH,
138 + INA2XX_ALERT_BUS_VOLTAGE_LOW,
139 + INA2XX_ALERT_BUS_VOLTAGE_HIGH,
140 + INA2XX_ALERT_SHUNT_VOLTAGE_LOW,
141 + INA2XX_ALERT_SHUNT_VOLTAGE_HIGH,
142 + };
143 +
132 144 struct ina2xx_config {
133 145 u16 config_default;
134 146 bool has_alerts; /* chip supports alerts and limits */
@@ -148,6 +160,7 @@ struct ina2xx_data {
148 160 const struct ina2xx_config *config;
149 161 enum ina2xx_ids chip;
150 162
163 + enum ina2xx_alert_type active_alert;
151 164 long rshunt;
152 165 long current_lsb_uA;
153 166 long power_lsb_uW;
@@ -428,16 +441,78 @@ static u16 ina226_alert_to_reg(struct ina2xx_data *data, int reg, long val)
428 441 }
429 442 }
430 443
431 - static int ina226_alert_limit_read(struct ina2xx_data *data, u32 mask, int reg, long *val)
444 + static u32 ina2xx_alert_type_to_mask(enum ina2xx_alert_type alert)
445 + {
446 + switch (alert) {
447 + case INA2XX_ALERT_CURRENT_LOW:
448 + case INA2XX_ALERT_SHUNT_VOLTAGE_LOW:
449 + return INA226_SHUNT_UNDER_VOLTAGE_MASK;
450 + case INA2XX_ALERT_CURRENT_HIGH:
451 + case INA2XX_ALERT_SHUNT_VOLTAGE_HIGH:
452 + return INA226_SHUNT_OVER_VOLTAGE_MASK;
453 + case INA2XX_ALERT_BUS_VOLTAGE_LOW:
454 + return INA226_BUS_UNDER_VOLTAGE_MASK;
455 + case INA2XX_ALERT_BUS_VOLTAGE_HIGH:
456 + return INA226_BUS_OVER_VOLTAGE_MASK;
457 + case INA2XX_ALERT_POWER_HIGH:
458 + return INA226_POWER_OVER_LIMIT_MASK;
459 + case INA2XX_ALERT_NONE:
460 + return 0;
461 + default:
462 + /* programmer error */
463 + WARN_ON_ONCE(1);
464 + return 0;
465 + }
466 + }
467 +
468 + static enum ina2xx_alert_type ina2xx_mask_to_alert_type(u32 mask)
469 + {
470 + int top_bit = fls(mask & INA226_ALERT_CONFIG_MASK);
471 +
472 + if (!top_bit)
473 + return INA2XX_ALERT_NONE;
474 +
475 + /*
476 + * Multiple bits may be set, with the highest-set function taking
477 + * precedence according to the datasheet. Shunt voltage masks are
478 + * assumed to map to voltage monitoring rather than current monitoring,
479 + * since the latter isn't directly implemented in the hardware.
480 + */
481 + switch (BIT(top_bit - 1)) {
482 + case INA226_SHUNT_OVER_VOLTAGE_MASK:
483 + return INA2XX_ALERT_SHUNT_VOLTAGE_HIGH;
484 + case INA226_SHUNT_UNDER_VOLTAGE_MASK:
485 + return INA2XX_ALERT_SHUNT_VOLTAGE_LOW;
486 + case INA226_BUS_OVER_VOLTAGE_MASK:
487 + return INA2XX_ALERT_BUS_VOLTAGE_HIGH;
488 + case INA226_BUS_UNDER_VOLTAGE_MASK:
489 + return INA2XX_ALERT_BUS_VOLTAGE_LOW;
490 + case INA226_POWER_OVER_LIMIT_MASK:
491 + return INA2XX_ALERT_POWER_HIGH;
492 + default:
493 + return INA2XX_ALERT_NONE;
494 + }
495 + }
496 +
497 + static int ina226_alert_limit_read(struct ina2xx_data *data, enum ina2xx_alert_type alert,
498 + int reg, long *val)
432 499 {
433 500 struct regmap *regmap = data->regmap;
434 501 int regval;
502 + u32 mask;
435 503 int ret;
436 504
505 + /* Avoid nonzero reads from inactive alerts caused by shared limit register */
506 + if (data->active_alert != alert) {
507 + *val = 0;
508 + return 0;
509 + }
510 +
437 511 ret = regmap_read(regmap, INA226_MASK_ENABLE, &regval);
438 512 if (ret)
439 513 return ret;
440 514
515 + mask = ina2xx_alert_type_to_mask(alert);
441 516 if (regval & mask) {
442 517 ret = regmap_read(regmap, INA226_ALERT_LIMIT, &regval);
443 518 if (ret)
@@ -449,9 +524,11 @@ static int ina226_alert_limit_read(struct ina2xx_data *data, u32 mask, int reg,
449 524 return 0;
450 525 }
451 526
452 - static int ina226_alert_limit_write(struct ina2xx_data *data, u32 mask, int reg, long val)
527 + static int ina226_alert_limit_write(struct ina2xx_data *data, enum ina2xx_alert_type alert,
528 + int reg, long val)
453 529 {
454 530 struct regmap *regmap = data->regmap;
531 + u32 mask;
455 532 int ret;
456 533
457 534 if (val < 0)
@@ -466,15 +543,22 @@ static int ina226_alert_limit_write(struct ina2xx_data *data, u32 mask, int reg,
466 543 INA226_ALERT_CONFIG_MASK, 0);
467 544 if (ret < 0)
468 545 return ret;
546 + data->active_alert = INA2XX_ALERT_NONE;
469 547
470 548 ret = regmap_write(regmap, INA226_ALERT_LIMIT,
471 549 ina226_alert_to_reg(data, reg, val));
472 550 if (ret < 0)
473 551 return ret;
474 552
475 - if (val)
476 - return regmap_update_bits(regmap, INA226_MASK_ENABLE,
477 - INA226_ALERT_CONFIG_MASK, mask);
553 + if (val) {
554 + mask = ina2xx_alert_type_to_mask(alert);
555 + ret = regmap_update_bits(regmap, INA226_MASK_ENABLE,
556 + INA226_ALERT_CONFIG_MASK, mask);
557 + if (ret < 0)
558 + return ret;
559 + data->active_alert = alert;
560 + }
561 +
478 562 return 0;
479 563 }
480 564
@@ -498,15 +582,26 @@ static int ina2xx_chip_read(struct device *dev, u32 attr, long *val)
498 582 return 0;
499 583 }
500 584
501 - static int ina226_alert_read(struct regmap *regmap, u32 mask, long *val)
585 + static int ina226_alert_read(struct ina2xx_data *data, enum ina2xx_alert_type alert, long *val)
502 586 {
503 587 unsigned int regval;
588 + u32 mask;
504 589 int ret;
505 590
506 - ret = regmap_read_bypassed(regmap, INA226_MASK_ENABLE, &regval);
591 + /*
592 + * With alert latching, reading alerts from hardware also clears the
593 + * alert, so return early if the alert is inactive.
594 + */
595 + if (data->active_alert != alert) {
596 + *val = 0;
597 + return 0;
598 + }
599 +
600 + ret = regmap_read_bypassed(data->regmap, INA226_MASK_ENABLE, &regval);
507 601 if (ret)
508 602 return ret;
509 603
604 + mask = ina2xx_alert_type_to_mask(alert);
510 605 *val = (regval & mask) && (regval & INA226_ALERT_FUNCTION_FLAG);
511 606
512 607 return 0;
@@ -515,10 +610,10 @@ static int ina226_alert_read(struct regmap *regmap, u32 mask, long *val)
515 610 static int ina2xx_in_read(struct device *dev, u32 attr, int channel, long *val)
516 611 {
517 612 int voltage_reg = channel ? INA2XX_BUS_VOLTAGE : INA2XX_SHUNT_VOLTAGE;
518 - u32 under_voltage_mask = channel ? INA226_BUS_UNDER_VOLTAGE_MASK
519 - : INA226_SHUNT_UNDER_VOLTAGE_MASK;
520 - u32 over_voltage_mask = channel ? INA226_BUS_OVER_VOLTAGE_MASK
521 - : INA226_SHUNT_OVER_VOLTAGE_MASK;
613 + enum ina2xx_alert_type under_voltage_alert = channel ? INA2XX_ALERT_BUS_VOLTAGE_LOW
614 + : INA2XX_ALERT_SHUNT_VOLTAGE_LOW;
615 + enum ina2xx_alert_type over_voltage_alert = channel ? INA2XX_ALERT_BUS_VOLTAGE_HIGH
616 + : INA2XX_ALERT_SHUNT_VOLTAGE_HIGH;
522 617 struct ina2xx_data *data = dev_get_drvdata(dev);
523 618 struct regmap *regmap = data->regmap;
524 619 unsigned int regval;
@@ -532,15 +627,15 @@ static int ina2xx_in_read(struct device *dev, u32 attr, int channel, long *val)
532 627 *val = ina2xx_get_value(data, voltage_reg, regval);
533 628 break;
534 629 case hwmon_in_lcrit:
535 - return ina226_alert_limit_read(data, under_voltage_mask,
630 + return ina226_alert_limit_read(data, under_voltage_alert,
536 631 voltage_reg, val);
537 632 case hwmon_in_crit:
538 - return ina226_alert_limit_read(data, over_voltage_mask,
633 + return ina226_alert_limit_read(data, over_voltage_alert,
539 634 voltage_reg, val);
540 635 case hwmon_in_lcrit_alarm:
541 - return ina226_alert_read(regmap, under_voltage_mask, val);
636 + return ina226_alert_read(data, under_voltage_alert, val);
542 637 case hwmon_in_crit_alarm:
543 - return ina226_alert_read(regmap, over_voltage_mask, val);
638 + return ina226_alert_read(data, over_voltage_alert, val);
544 639 default:
545 640 return -EOPNOTSUPP;
546 641 }
@@ -594,10 +689,10 @@ static int ina2xx_power_read(struct device *dev, u32 attr, long *val)
594 689 case hwmon_power_average:
595 690 return sy24655_average_power_read(data, SY24655_EIN, val);
596 691 case hwmon_power_crit:
597 - return ina226_alert_limit_read(data, INA226_POWER_OVER_LIMIT_MASK,
692 + return ina226_alert_limit_read(data, INA2XX_ALERT_POWER_HIGH,
598 693 INA2XX_POWER, val);
599 694 case hwmon_power_crit_alarm:
600 - return ina226_alert_read(data->regmap, INA226_POWER_OVER_LIMIT_MASK, val);
695 + return ina226_alert_read(data, INA2XX_ALERT_POWER_HIGH, val);
601 696 default:
602 697 return -EOPNOTSUPP;
603 698 }
@@ -633,15 +728,15 @@ static int ina2xx_curr_read(struct device *dev, u32 attr, long *val)
633 728 *val = ina2xx_get_value(data, INA2XX_CURRENT, regval);
634 729 return 0;
635 730 case hwmon_curr_lcrit:
636 - return ina226_alert_limit_read(data, INA226_SHUNT_UNDER_VOLTAGE_MASK,
731 + return ina226_alert_limit_read(data, INA2XX_ALERT_CURRENT_LOW,
637 732 INA2XX_CURRENT, val);
638 733 case hwmon_curr_crit:
639 - return ina226_alert_limit_read(data, INA226_SHUNT_OVER_VOLTAGE_MASK,
734 + return ina226_alert_limit_read(data, INA2XX_ALERT_CURRENT_HIGH,
640 735 INA2XX_CURRENT, val);
641 736 case hwmon_curr_lcrit_alarm:
642 - return ina226_alert_read(regmap, INA226_SHUNT_UNDER_VOLTAGE_MASK, val);
737 + return ina226_alert_read(data, INA2XX_ALERT_CURRENT_LOW, val);
643 738 case hwmon_curr_crit_alarm:
644 - return ina226_alert_read(regmap, INA226_SHUNT_OVER_VOLTAGE_MASK, val);
739 + return ina226_alert_read(data, INA2XX_ALERT_CURRENT_HIGH, val);
645 740 default:
646 741 return -EOPNOTSUPP;
647 742 }
@@ -685,12 +780,12 @@ static int ina2xx_in_write(struct device *dev, u32 attr, int channel, long val)
685 780 switch (attr) {
686 781 case hwmon_in_lcrit:
687 782 return ina226_alert_limit_write(data,
688 - channel ? INA226_BUS_UNDER_VOLTAGE_MASK : INA226_SHUNT_UNDER_VOLTAGE_MASK,
783 + channel ? INA2XX_ALERT_BUS_VOLTAGE_LOW : INA2XX_ALERT_SHUNT_VOLTAGE_LOW,
689 784 channel ? INA2XX_BUS_VOLTAGE : INA2XX_SHUNT_VOLTAGE,
690 785 val);
691 786 case hwmon_in_crit:
692 787 return ina226_alert_limit_write(data,
693 - channel ? INA226_BUS_OVER_VOLTAGE_MASK : INA226_SHUNT_OVER_VOLTAGE_MASK,
788 + channel ? INA2XX_ALERT_BUS_VOLTAGE_HIGH : INA2XX_ALERT_SHUNT_VOLTAGE_HIGH,
694 789 channel ? INA2XX_BUS_VOLTAGE : INA2XX_SHUNT_VOLTAGE,
695 790 val);
696 791 default:
@@ -705,7 +800,7 @@ static int ina2xx_power_write(struct device *dev, u32 attr, long val)
705 800
706 801 switch (attr) {
707 802 case hwmon_power_crit:
708 - return ina226_alert_limit_write(data, INA226_POWER_OVER_LIMIT_MASK,
803 + return ina226_alert_limit_write(data, INA2XX_ALERT_POWER_HIGH,
709 804 INA2XX_POWER, val);
710 805 default:
711 806 return -EOPNOTSUPP;
@@ -719,10 +814,10 @@ static int ina2xx_curr_write(struct device *dev, u32 attr, long val)
719 814
720 815 switch (attr) {
721 816 case hwmon_curr_lcrit:
722 - return ina226_alert_limit_write(data, INA226_SHUNT_UNDER_VOLTAGE_MASK,
817 + return ina226_alert_limit_write(data, INA2XX_ALERT_CURRENT_LOW,
723 818 INA2XX_CURRENT, val);
724 819 case hwmon_curr_crit:
725 - return ina226_alert_limit_write(data, INA226_SHUNT_OVER_VOLTAGE_MASK,
820 + return ina226_alert_limit_write(data, INA2XX_ALERT_CURRENT_HIGH,
726 821 INA2XX_CURRENT, val);
727 822 default:
728 823 return -EOPNOTSUPP;
@@ -883,8 +978,12 @@ static ssize_t shunt_resistor_show(struct device *dev,
883 978 struct device_attribute *da, char *buf)
884 979 {
885 980 struct ina2xx_data *data = dev_get_drvdata(dev);
981 + long rshunt;
886 982
887 - return sysfs_emit(buf, "%li\n", data->rshunt);
983 + scoped_guard(hwmon_lock, dev) {
984 + rshunt = data->rshunt;
985 + }
986 + return sysfs_emit(buf, "%li\n", rshunt);
888 987 }
889 988
890 989 static ssize_t shunt_resistor_store(struct device *dev,
@@ -940,6 +1039,16 @@ static int ina2xx_init(struct device *dev, struct ina2xx_data *data)
940 1039
941 1040 if (data->config->has_alerts) {
942 1041 bool active_high = device_property_read_bool(dev, "ti,alert-polarity-active-high");
1042 + unsigned int mask_enable;
1043 +
1044 + /*
1045 + * Infer active alert from MASK_ENABLE in case it's already
1046 + * configured (e.g., by a past probe or firmware)
1047 + */
1048 + ret = regmap_read(regmap, INA226_MASK_ENABLE, &mask_enable);
1049 + if (ret < 0)
1050 + return ret;
1051 + data->active_alert = ina2xx_mask_to_alert_type(mask_enable);
943 1052
944 1053 regmap_update_bits(regmap, INA226_MASK_ENABLE,
945 1054 INA226_ALERT_LATCH_ENABLE | INA226_ALERT_POLARITY,
modified drivers/hwmon/ltc4282.c
@@ -1106,7 +1106,7 @@ static const struct clk_ops ltc4282_ops = {
1106 1106 static int ltc428_clk_provider_setup(struct ltc4282_state *st,
1107 1107 struct device *dev)
1108 1108 {
1109 - struct clk_init_data init;
1109 + struct clk_init_data init = {};
1110 1110 int ret;
1111 1111
1112 1112 if (!IS_ENABLED(CONFIG_COMMON_CLK))
modified drivers/hwmon/mcp9982.c
@@ -395,6 +395,8 @@ static int mcp9982_read(struct device *dev, enum hwmon_sensor_types type, u32 at
395 395 reg_status, !(reg_status & MCP9982_STATUS_BUSY),
396 396 MCP9982_WAKE_UP_TIME_US,
397 397 MCP9982_WAKE_UP_TIME_US * 10);
398 + if (ret)
399 + return ret;
398 400 break;
399 401 }
400 402 break;
modified drivers/hwmon/nct6694-hwmon.c
@@ -159,6 +159,9 @@ static inline s8 temp_to_reg(long val)
159 159 #define NCT6694_HWMON_TEMP_CONFIG (HWMON_T_INPUT | HWMON_T_ENABLE | \
160 160 HWMON_T_MAX | HWMON_T_MAX_HYST | \
161 161 HWMON_T_MAX_ALARM)
162 + #define NCT6694_HWMON_DTIN_CONFIG (HWMON_T_INPUT | \
163 + HWMON_T_MAX | HWMON_T_MAX_HYST | \
164 + HWMON_T_MAX_ALARM)
162 165 #define NCT6694_HWMON_FAN_CONFIG (HWMON_F_INPUT | HWMON_F_ENABLE | \
163 166 HWMON_F_MIN | HWMON_F_MIN_ALARM)
164 167 #define NCT6694_HWMON_PWM_CONFIG (HWMON_PWM_INPUT | HWMON_PWM_ENABLE | \
@@ -193,22 +196,22 @@ static const struct hwmon_channel_info *nct6694_info[] = {
193 196 NCT6694_HWMON_TEMP_CONFIG, /* TDP2 */
194 197 NCT6694_HWMON_TEMP_CONFIG, /* TDP3 */
195 198 NCT6694_HWMON_TEMP_CONFIG, /* TDP4 */
196 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN0 */
197 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN1 */
198 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN2 */
199 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN3 */
200 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN4 */
201 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN5 */
202 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN6 */
203 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN7 */
204 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN8 */
205 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN9 */
206 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN10 */
207 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN11 */
208 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN12 */
209 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN13 */
210 - NCT6694_HWMON_TEMP_CONFIG, /* DTIN14 */
211 - NCT6694_HWMON_TEMP_CONFIG), /* DTIN15 */
199 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN0 */
200 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN1 */
201 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN2 */
202 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN3 */
203 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN4 */
204 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN5 */
205 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN6 */
206 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN7 */
207 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN8 */
208 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN9 */
209 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN10 */
210 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN11 */
211 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN12 */
212 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN13 */
213 + NCT6694_HWMON_DTIN_CONFIG, /* DTIN14 */
214 + NCT6694_HWMON_DTIN_CONFIG), /* DTIN15 */
212 215
213 216 HWMON_CHANNEL_INFO(fan,
214 217 NCT6694_HWMON_FAN_CONFIG, /* FIN0 */
modified drivers/hwmon/pmbus/pmbus_core.c
@@ -1275,7 +1275,9 @@ static int pmbus_get_boolean(struct i2c_client *client, struct pmbus_boolean *b,
1275 1275
1276 1276 regval = status & mask;
1277 1277 if (regval) {
1278 - if (data->revision >= PMBUS_REV_12) {
1278 + /* Generic STATUS_WORD alarms are not individually clearable. */
1279 + if (data->revision >= PMBUS_REV_12 &&
1280 + reg != PMBUS_STATUS_WORD) {
1279 1281 ret = _pmbus_write_byte_data(client, page, reg, regval);
1280 1282 if (ret)
1281 1283 return ret;
modified drivers/hwmon/sht4x.c
@@ -277,6 +277,8 @@ static ssize_t heater_enable_store(struct device *dev,
277 277 heating_time_bound = 1100;
278 278 }
279 279
280 + guard(hwmon_lock)(dev);
281 +
280 282 if (time_before(jiffies, data->heating_complete))
281 283 return -EBUSY;
282 284
@@ -286,7 +288,7 @@ static ssize_t heater_enable_store(struct device *dev,
286 288
287 289 data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound);
288 290 data->data_pending = true;
289 - return 0;
291 + return count;
290 292 }
291 293
292 294 static ssize_t heater_power_show(struct device *dev,
@@ -314,6 +316,8 @@ static ssize_t heater_power_store(struct device *dev,
314 316 if (power != 20 && power != 110 && power != 200)
315 317 return -EINVAL;
316 318
319 + guard(hwmon_lock)(dev);
320 +
317 321 data->heater_power = power;
318 322
319 323 return count;
@@ -344,6 +348,8 @@ static ssize_t heater_time_store(struct device *dev,
344 348 if (time != 100 && time != 1000)
345 349 return -EINVAL;
346 350
351 + guard(hwmon_lock)(dev);
352 +
347 353 data->heater_time = time;
348 354
349 355 return count;
modified drivers/hwmon/yogafan.c
@@ -1,5 +1,5 @@
1 1 // SPDX-License-Identifier: GPL-2.0-only
2 - /**
2 + /*
3 3 * yoga_fan.c - Lenovo Yoga/Legion Fan Hardware Monitoring Driver
4 4 *
5 5 * Provides fan speed monitoring for Lenovo Yoga, Legion, and IdeaPad
modified drivers/iommu/amd/amd_iommu.h
@@ -54,9 +54,6 @@ struct protection_domain *protection_domain_alloc(void);
54 54 struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
55 55 struct mm_struct *mm);
56 56 void amd_iommu_domain_free(struct iommu_domain *dom);
57 - int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
58 - struct device *dev, ioasid_t pasid,
59 - struct iommu_domain *old);
60 57 void amd_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
61 58 struct iommu_domain *domain);
62 59
modified drivers/iommu/amd/amd_iommu_types.h
@@ -39,18 +39,6 @@
39 39 #define MMIO_RANGE_OFFSET 0x0c
40 40 #define MMIO_MISC_OFFSET 0x10
41 41
42 - /* Masks, shifts and macros to parse the device range capability */
43 - #define MMIO_RANGE_LD_MASK 0xff000000
44 - #define MMIO_RANGE_FD_MASK 0x00ff0000
45 - #define MMIO_RANGE_BUS_MASK 0x0000ff00
46 - #define MMIO_RANGE_LD_SHIFT 24
47 - #define MMIO_RANGE_FD_SHIFT 16
48 - #define MMIO_RANGE_BUS_SHIFT 8
49 - #define MMIO_GET_LD(x) (((x) & MMIO_RANGE_LD_MASK) >> MMIO_RANGE_LD_SHIFT)
50 - #define MMIO_GET_FD(x) (((x) & MMIO_RANGE_FD_MASK) >> MMIO_RANGE_FD_SHIFT)
51 - #define MMIO_GET_BUS(x) (((x) & MMIO_RANGE_BUS_MASK) >> MMIO_RANGE_BUS_SHIFT)
52 - #define MMIO_MSI_NUM(x) ((x) & 0x1f)
53 -
54 42 /* Used offsets into the MMIO space */
55 43 #define MMIO_DEV_TABLE_OFFSET 0x0000
56 44 #define MMIO_CMD_BUF_OFFSET 0x0008
@@ -247,7 +235,6 @@
247 235
248 236 /* constants to configure the command buffer */
249 237 #define CMD_BUFFER_SIZE 8192
250 - #define CMD_BUFFER_UNINITIALIZED 1
251 238 #define CMD_BUFFER_ENTRIES 512
252 239 #define MMIO_CMD_SIZE_SHIFT 56
253 240 #define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT)
@@ -434,9 +421,6 @@ struct irq_remap_table {
434 421 u32 *table;
435 422 };
436 423
437 - /* Interrupt remapping feature used? */
438 - extern bool amd_iommu_irq_remap;
439 -
440 424 extern const struct iommu_ops amd_iommu_ops;
441 425
442 426 /* IVRS indicates that pre-boot remapping was enabled */
modified drivers/iommu/amd/init.c
@@ -152,7 +152,7 @@ struct ivmd_header {
152 152 } __attribute__((packed));
153 153
154 154 bool amd_iommu_dump;
155 - bool amd_iommu_irq_remap __read_mostly;
155 + static bool amd_iommu_irq_remap __read_mostly;
156 156
157 157 enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
158 158 /* Virtual address size */
@@ -909,7 +909,9 @@ static void free_ga_log(struct amd_iommu *iommu)
909 909 {
910 910 #ifdef CONFIG_IRQ_REMAP
911 911 iommu_free_pages(iommu->ga_log);
912 + iommu->ga_log = NULL;
912 913 iommu_free_pages(iommu->ga_log_tail);
914 + iommu->ga_log_tail = NULL;
913 915 #endif
914 916 }
915 917
@@ -956,6 +958,9 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
956 958 if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
957 959 return -EINVAL;
958 960
961 + if (iommu->ga_log && iommu->ga_log_tail)
962 + return 0;
963 +
959 964 iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE);
960 965 if (!iommu->ga_log)
961 966 goto err_out;
@@ -1917,19 +1922,20 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
1917 1922 else
1918 1923 iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET;
1919 1924
1925 + if (h->efr_attr & BIT(IOMMU_IVHD_ATTR_HATDIS_SHIFT)) {
1926 + pr_warn_once("Host Address Translation is not supported.\n");
1927 + amd_iommu_hatdis = true;
1928 + }
1929 +
1920 1930 /* XT and GAM require GA mode. */
1921 1931 if ((h->efr_reg & (0x1 << IOMMU_EFR_GASUP_SHIFT)) == 0) {
1922 1932 amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY;
1933 + break;
1923 1934 } else {
1924 1935 if (h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT))
1925 1936 amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
1926 1937 }
1927 1938
1928 - if (h->efr_attr & BIT(IOMMU_IVHD_ATTR_HATDIS_SHIFT)) {
1929 - pr_warn_once("Host Address Translation is not supported.\n");
1930 - amd_iommu_hatdis = true;
1931 - }
1932 -
1933 1939 early_iommu_features_init(iommu, h);
1934 1940
1935 1941 break;
modified drivers/iommu/amd/iommu.c
@@ -1076,9 +1076,6 @@ static void iommu_poll_ga_log(struct amd_iommu *iommu)
1076 1076 {
1077 1077 u32 head, tail;
1078 1078
1079 - if (iommu->ga_log == NULL)
1080 - return;
1081 -
1082 1079 head = readl(iommu->mmio_base + MMIO_GA_HEAD_OFFSET);
1083 1080 tail = readl(iommu->mmio_base + MMIO_GA_TAIL_OFFSET);
1084 1081
@@ -3976,9 +3973,6 @@ static int irq_remapping_select(struct irq_domain *d, struct irq_fwspec *fwspec,
3976 3973 struct amd_iommu *iommu;
3977 3974 int devid = -1;
3978 3975
3979 - if (!amd_iommu_irq_remap)
3980 - return 0;
3981 -
3982 3976 if (x86_fwspec_is_ioapic(fwspec))
3983 3977 devid = get_ioapic_devid(fwspec->param[0]);
3984 3978 else if (x86_fwspec_is_hpet(fwspec))
modified drivers/iommu/amd/nested.c
@@ -96,7 +96,7 @@ struct iommu_domain *
96 96 amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
97 97 const struct iommu_user_data *user_data)
98 98 {
99 - int ret;
99 + int ret, hdom_id;
100 100 unsigned long irqflags;
101 101 struct nested_domain *ndom;
102 102 struct guest_domain_mapping_info *gdom_info;
@@ -161,8 +161,8 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
161 161 }
162 162
163 163 /* The gDomID does not exist. We allocate new hdom_id */
164 - gdom_info->hdom_id = amd_iommu_pdom_id_alloc();
165 - if (gdom_info->hdom_id <= 0) {
164 + hdom_id = amd_iommu_pdom_id_alloc();
165 + if (hdom_id <= 0) {
166 166 __xa_cmpxchg(&aviommu->gdomid_array,
167 167 ndom->gdom_id, gdom_info, NULL, GFP_ATOMIC);
168 168 xa_unlock_irqrestore(&aviommu->gdomid_array, irqflags);
@@ -170,6 +170,7 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
170 170 goto out_err_gdom_info;
171 171 }
172 172
173 + gdom_info->hdom_id = hdom_id;
173 174 ndom->gdom_info = gdom_info;
174 175 refcount_set(&gdom_info->users, 1);
175 176
modified drivers/iommu/amd/pasid.c
@@ -99,9 +99,9 @@ static const struct mmu_notifier_ops sva_mn = {
99 99 .release = sva_mn_release,
100 100 };
101 101
102 - int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
103 - struct device *dev, ioasid_t pasid,
104 - struct iommu_domain *old)
102 + static int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
103 + struct device *dev, ioasid_t pasid,
104 + struct iommu_domain *old)
105 105 {
106 106 struct pdom_dev_data *pdom_dev_data;
107 107 struct protection_domain *sva_pdom = to_pdomain(domain);
modified drivers/iommu/amd/ppr.c
@@ -165,9 +165,6 @@ void amd_iommu_poll_ppr_log(struct amd_iommu *iommu)
165 165 {
166 166 u32 head, tail;
167 167
168 - if (iommu->ppr_log == NULL)
169 - return;
170 -
171 168 head = readl(iommu->mmio_base + MMIO_PPR_HEAD_OFFSET);
172 169 tail = readl(iommu->mmio_base + MMIO_PPR_TAIL_OFFSET);
173 170
modified drivers/iommu/riscv/iommu.c
@@ -382,78 +382,97 @@ static int riscv_iommu_queue_wait(struct riscv_iommu_queue *queue,
382 382 (int)(cons - index) > 0, 0, timeout_us);
383 383 }
384 384
385 - /* Enqueue an entry and wait to be processed if timeout_us > 0
386 - *
387 - * Error handling for IOMMU hardware not responding in reasonable time
388 - * will be added as separate patch series along with other RAS features.
389 - * For now, only report hardware failure and continue.
390 - */
391 - static unsigned int riscv_iommu_queue_send(struct riscv_iommu_queue *queue,
392 - void *entry, size_t entry_size)
385 + static int riscv_iommu_queue_wait_for_space(struct riscv_iommu_queue *queue,
386 + unsigned int last)
393 387 {
394 - unsigned int prod;
395 388 unsigned int head;
396 389 unsigned int tail;
390 + unsigned int hw_head;
397 391 unsigned long flags;
392 + int ret;
398 393
399 - /* Do not preempt submission flow. */
400 - local_irq_save(flags);
394 + ret = riscv_iommu_readl_timeout(queue->iommu, Q_HEAD(queue), hw_head,
395 + !(hw_head & ~queue->mask) && hw_head != last,
396 + 0, RISCV_IOMMU_QUEUE_TIMEOUT);
397 + if (ret)
398 + return ret;
401 399
402 - /* 1. Allocate some space in the queue */
403 - prod = atomic_inc_return(&queue->prod) - 1;
400 + raw_spin_lock_irqsave(&queue->lock, flags);
404 401 head = atomic_read(&queue->head);
402 + tail = atomic_read(&queue->tail);
403 + if ((tail - head) >= queue->mask) {
404 + last = Q_ITEM(queue, head);
405 + /*
406 + * Re-read hw_head under the lock so that it is consistent with
407 + * the freshly computed 'last'. Using the pre-lock snapshot
408 + * could produce a stale value that wraps around relative to the
409 + * new 'last', advancing the shadow head past entries that have
410 + * not yet been consumed by the hardware.
411 + */
412 + hw_head = riscv_iommu_readl(queue->iommu, Q_HEAD(queue));
413 + if (!(hw_head & ~queue->mask) && hw_head != last)
414 + atomic_add((hw_head - last) & queue->mask, &queue->head);
415 + }
416 + raw_spin_unlock_irqrestore(&queue->lock, flags);
405 417
406 - /* 2. Wait for space availability. */
407 - if ((prod - head) > queue->mask) {
408 - if (readx_poll_timeout(atomic_read, &queue->head,
409 - head, (prod - head) < queue->mask,
410 - 0, RISCV_IOMMU_QUEUE_TIMEOUT))
411 - goto err_busy;
412 - } else if ((prod - head) == queue->mask) {
413 - const unsigned int last = Q_ITEM(queue, head);
418 + return 0;
419 + }
420 +
421 + /* Enqueue an entry and publish it to the hardware queue. */
422 + static int riscv_iommu_queue_send(struct riscv_iommu_queue *queue,
423 + void *entry, size_t entry_size,
424 + unsigned int *out_prod)
425 + {
426 + unsigned int prod;
427 + unsigned int head;
428 + unsigned long flags;
429 + int ret;
430 +
431 + /* 1. Wait for space availability and reserve the next slot. */
432 + for (;;) {
433 + raw_spin_lock_irqsave(&queue->lock, flags);
434 +
435 + prod = atomic_read(&queue->tail);
436 + head = atomic_read(&queue->head);
437 +
438 + if ((prod - head) < queue->mask)
439 + break;
440 +
441 + head = Q_ITEM(queue, head);
442 + raw_spin_unlock_irqrestore(&queue->lock, flags);
414 443
415 - if (riscv_iommu_readl_timeout(queue->iommu, Q_HEAD(queue), head,
416 - !(head & ~queue->mask) && head != last,
417 - 0, RISCV_IOMMU_QUEUE_TIMEOUT))
444 + ret = riscv_iommu_queue_wait_for_space(queue, head);
445 + if (ret)
418 446 goto err_busy;
419 - atomic_add((head - last) & queue->mask, &queue->head);
420 447 }
421 448
422 - /* 3. Store entry in the ring buffer */
449 + /* 2. Store entry in the ring buffer. */
423 450 memcpy(queue->base + Q_ITEM(queue, prod) * entry_size, entry, entry_size);
424 451
425 - /* 4. Wait for all previous entries to be ready */
426 - if (readx_poll_timeout(atomic_read, &queue->tail, tail, prod == tail,
427 - 0, RISCV_IOMMU_QUEUE_TIMEOUT))
428 - goto err_busy;
429 -
430 - /*
431 - * 5. Make sure the ring buffer update (whether in normal or I/O memory) is
432 - * completed and visible before signaling the tail doorbell to fetch
433 - * the next command. 'fence ow, ow'
434 - */
452 + /* 3. Make sure the entry is visible before updating the queue tail. */
435 453 dma_wmb();
436 454 riscv_iommu_writel(queue->iommu, Q_TAIL(queue), Q_ITEM(queue, prod + 1));
437 455
438 456 /*
439 - * 6. Make sure the doorbell write to the device has finished before updating
440 - * the shadow tail index in normal memory. 'fence o, w'
457 + * 4. Make sure the doorbell write to the device has finished before
458 + * updating the shadow tail index in normal memory. 'fence o, w'
441 459 */
442 460 #ifdef CONFIG_MMIOWB
443 461 mmiowb();
444 462 #endif
445 - atomic_inc(&queue->tail);
463 + atomic_set(&queue->tail, prod + 1);
464 + atomic_set(&queue->prod, prod + 1);
446 465
447 - /* 7. Complete submission and restore local interrupts */
448 - local_irq_restore(flags);
466 + if (out_prod)
467 + *out_prod = prod;
449 468
450 - return prod;
469 + raw_spin_unlock_irqrestore(&queue->lock, flags);
470 + return 0;
451 471
452 472 err_busy:
453 - local_irq_restore(flags);
473 + /* Report the failure and continue; full RAS recovery is not implemented. */
454 474 dev_err_once(queue->iommu->dev, "Hardware error: command enqueue failed\n");
455 -
456 - return prod;
475 + return ret;
457 476 }
458 477
459 478 /*
@@ -492,7 +511,7 @@ static irqreturn_t riscv_iommu_cmdq_process(int irq, void *data)
492 511 static void riscv_iommu_cmd_send(struct riscv_iommu_device *iommu,
493 512 struct riscv_iommu_command *cmd)
494 513 {
495 - riscv_iommu_queue_send(&iommu->cmdq, cmd, sizeof(*cmd));
514 + riscv_iommu_queue_send(&iommu->cmdq, cmd, sizeof(*cmd), NULL);
496 515 }
497 516
498 517 /* Send IOFENCE.C command and wait for all scheduled commands to complete. */
@@ -501,9 +520,12 @@ static void riscv_iommu_cmd_sync(struct riscv_iommu_device *iommu,
501 520 {
502 521 struct riscv_iommu_command cmd;
503 522 unsigned int prod;
523 + int ret;
504 524
505 525 riscv_iommu_cmd_iofence(&cmd);
506 - prod = riscv_iommu_queue_send(&iommu->cmdq, &cmd, sizeof(cmd));
526 + ret = riscv_iommu_queue_send(&iommu->cmdq, &cmd, sizeof(cmd), &prod);
527 + if (ret)
528 + return;
507 529
508 530 if (!timeout_us)
509 531 return;
@@ -1560,6 +1582,7 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu)
1560 1582 int rc;
1561 1583
1562 1584 RISCV_IOMMU_QUEUE_INIT(&iommu->cmdq, CQ);
1585 + raw_spin_lock_init(&iommu->cmdq.lock);
1563 1586 RISCV_IOMMU_QUEUE_INIT(&iommu->fltq, FQ);
1564 1587
1565 1588 rc = riscv_iommu_init_check(iommu);
modified drivers/iommu/riscv/iommu.h
@@ -12,6 +12,7 @@
12 12 #define _RISCV_IOMMU_H_
13 13
14 14 #include <linux/iommu.h>
15 + #include <linux/spinlock.h>
15 16 #include <linux/types.h>
16 17 #include <linux/iopoll.h>
17 18
@@ -23,6 +24,7 @@ struct riscv_iommu_queue {
23 24 atomic_t prod; /* unbounded producer allocation index */
24 25 atomic_t head; /* unbounded shadow ring buffer consumer index */
25 26 atomic_t tail; /* unbounded shadow ring buffer producer index */
27 + raw_spinlock_t lock; /* serialize queue publishing */
26 28 unsigned int mask; /* index mask, queue length - 1 */
27 29 unsigned int irq; /* allocated interrupt number */
28 30 struct riscv_iommu_device *iommu; /* iommu device handling the queue when active */
modified drivers/iommu/s390-iommu.c
@@ -974,6 +974,8 @@ static unsigned long *get_rto_from_iova(struct s390_domain *domain,
974 974 case ZPCI_TABLE_TYPE_RFX:
975 975 case ZPCI_TABLE_TYPE_RSX:
976 976 rso = get_rso_from_iova(domain, iova);
977 + if (!rso)
978 + return NULL;
977 979 rsx = calc_rsx(iova);
978 980 rse = READ_ONCE(rso[rsx]);
979 981 if (!reg_entry_isvalid(rse))
modified drivers/irqchip/irq-gic-v5.c
@@ -974,7 +974,8 @@ static void gicv5_cpu_disable_interrupts(void)
974 974 {
975 975 u64 cr0;
976 976
977 - cr0 = FIELD_PREP(ICC_CR0_EL1_EN, 0);
977 + cr0 = read_sysreg_s(SYS_ICC_CR0_EL1);
978 + cr0 &= ~ICC_CR0_EL1_EN_MASK;
978 979 write_sysreg_s(cr0, SYS_ICC_CR0_EL1);
979 980 isb();
980 981 }
@@ -991,7 +992,8 @@ static void gicv5_cpu_enable_interrupts(void)
991 992 pcr = FIELD_PREP(ICC_PCR_EL1_PRIORITY, GICV5_IRQ_PRI_MI);
992 993 write_sysreg_s(pcr, SYS_ICC_PCR_EL1);
993 994
994 - cr0 = FIELD_PREP(ICC_CR0_EL1_EN, 1);
995 + cr0 = read_sysreg_s(SYS_ICC_CR0_EL1);
996 + cr0 |= ICC_CR0_EL1_EN_MASK;
995 997 write_sysreg_s(cr0, SYS_ICC_CR0_EL1);
996 998 }
997 999
modified drivers/media/pci/intel/ipu-bridge.c
@@ -232,6 +232,19 @@ static const struct acpi_device_id ivsc_acpi_ids[] = {
232 232 { "INTC10FA" }, /* NVL */
233 233 };
234 234
235 + /*
236 + * The subset of ivsc_acpi_ids[] which are IVSC, rather than CVS, devices. The
237 + * CVS IDs are deliberately not listed here: new ones keep being added, whereas
238 + * this list is complete.
239 + */
240 + static const struct acpi_device_id ivsc_only_acpi_ids[] = {
241 + { "INTC1059" },
242 + { "INTC1095" },
243 + { "INTC100A" },
244 + { "INTC10CF" },
245 + { }
246 + };
247 +
235 248 static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev)
236 249 {
237 250 unsigned int i;
@@ -283,6 +296,17 @@ static struct device *ipu_bridge_get_ivsc_csi_dev(struct acpi_device *adev)
283 296 return csi_dev;
284 297 }
285 298
299 + /*
300 + * The lookups below match on the ACPI companion alone. That is fine for
301 + * CVS, which binds a driver to that very device, but not for IVSC: there
302 + * the ACPI device also has a driverless platform device, which would be
303 + * returned instead of the mei-csi client. Return NULL for IVSC so that
304 + * the caller fails and the probe is retried once the IVSC device shows
305 + * up.
306 + */
307 + if (!acpi_match_device_ids(adev, ivsc_only_acpi_ids))
308 + return NULL;
309 +
286 310 /* Try to locate CVS device on the I2C bus */
287 311 csi_dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
288 312 if (csi_dev)
modified drivers/media/platform/dreamchip/rppx1/rpp_params.c
@@ -25,6 +25,7 @@ rppx1_ext_params_blocks_info[] = {
25 25 RPPX1_PARAMS_BLOCK_INFO(LSC_PRE2, lsc),
26 26 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE1, awbg),
27 27 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE2, awbg),
28 + RPPX1_PARAMS_BLOCK_INFO(AWBG_POST, awbg),
28 29 RPPX1_PARAMS_BLOCK_INFO(CCOR_POST, ccor),
29 30 RPPX1_PARAMS_BLOCK_INFO(HIST_PRE1, hist),
30 31 RPPX1_PARAMS_BLOCK_INFO(HIST_PRE2, hist),
modified drivers/media/platform/dreamchip/rppx1/rppx1_bls.c
@@ -70,7 +70,7 @@ rppx1_bls_swap_regs(struct rpp_module *mod, const u32 input[4], u32 output[4])
70 70
71 71 /* Swap to pattern used in our path, PRE1 or PRE2. */
72 72 struct rpp_module *acq = mod == &mod->rpp->pre1.bls ?
73 - &mod->rpp->pre1.acq : &mod->rpp->pre2.bls;
73 + &mod->rpp->pre1.acq : &mod->rpp->pre2.acq;
74 74 enum rpp_raw_pattern pattern = acq->info.acq.raw_pattern;
75 75
76 76 for (unsigned int i = 0; i < 4; ++i)
modified drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
@@ -1299,11 +1299,12 @@ static void vdec_av1_slice_setup_tile(struct vdec_av1_slice_frame *frame,
1299 1299 tile->uniform_tile_spacing_flag =
1300 1300 BIT_FLAG(ctrl_tile, V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING);
1301 1301
1302 - for (i = 0; i < tile->tile_cols + 1; i++)
1302 + /* Bound the copy to the mi_col_starts[]/mi_row_starts[] capacity. */
1303 + for (i = 0; i < tile->tile_cols + 1 && i < V4L2_AV1_MAX_TILE_COLS + 1; i++)
1303 1304 tile->mi_col_starts[i] =
1304 1305 ALIGN(ctrl_tile->mi_col_starts[i], BIT(mib_size_log2)) >> mib_size_log2;
1305 1306
1306 - for (i = 0; i < tile->tile_rows + 1; i++)
1307 + for (i = 0; i < tile->tile_rows + 1 && i < V4L2_AV1_MAX_TILE_ROWS + 1; i++)
1307 1308 tile->mi_row_starts[i] =
1308 1309 ALIGN(ctrl_tile->mi_row_starts[i], BIT(mib_size_log2)) >> mib_size_log2;
1309 1310 }
modified drivers/media/platform/rockchip/rkvdec/rkvdec-hevc-common.c
@@ -16,6 +16,7 @@
16 16 */
17 17
18 18 #include <linux/v4l2-common.h>
19 + #include <media/v4l2-hevc.h>
19 20 #include <media/v4l2-mem2mem.h>
20 21
21 22 #include "rkvdec.h"
@@ -37,15 +38,17 @@ void compute_tiles_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size,
37 38 s32 pic_in_cts_height, u16 *column_width, u16 *row_height)
38 39 {
39 40 const struct v4l2_ctrl_hevc_pps *pps = run->pps;
41 + unsigned int num_cols = v4l2_hevc_pps_num_tile_columns(pps);
42 + unsigned int num_rows = v4l2_hevc_pps_num_tile_rows(pps);
40 43 int i;
41 44
42 - for (i = 0; i < pps->num_tile_columns_minus1 + 1; i++)
45 + for (i = 0; i < num_cols; i++)
43 46 column_width[i] = ((i + 1) * pic_in_cts_width) /
44 47 (pps->num_tile_columns_minus1 + 1) -
45 48 (i * pic_in_cts_width) /
46 49 (pps->num_tile_columns_minus1 + 1);
47 50
48 - for (i = 0; i < pps->num_tile_rows_minus1 + 1; i++)
51 + for (i = 0; i < num_rows; i++)
49 52 row_height[i] = ((i + 1) * pic_in_cts_height) /
50 53 (pps->num_tile_rows_minus1 + 1) -
51 54 (i * pic_in_cts_height) /
@@ -57,17 +60,20 @@ void compute_tiles_non_uniform(struct rkvdec_hevc_run *run, u16 log2_min_cb_size
57 60 s32 pic_in_cts_height, u16 *column_width, u16 *row_height)
58 61 {
59 62 const struct v4l2_ctrl_hevc_pps *pps = run->pps;
63 + unsigned int num_cols = v4l2_hevc_pps_num_tile_columns(pps);
64 + unsigned int num_rows = v4l2_hevc_pps_num_tile_rows(pps);
60 65 s32 sum = 0;
61 66 int i;
62 67
63 - for (i = 0; i < pps->num_tile_columns_minus1; i++) {
68 + /* The last tile entry is written after the loop, so iterate one less. */
69 + for (i = 0; i < num_cols - 1; i++) {
64 70 column_width[i] = pps->column_width_minus1[i] + 1;
65 71 sum += column_width[i];
66 72 }
67 73 column_width[i] = pic_in_cts_width - sum;
68 74
69 75 sum = 0;
70 - for (i = 0; i < pps->num_tile_rows_minus1; i++) {
76 + for (i = 0; i < num_rows - 1; i++) {
71 77 row_height[i] = pps->row_height_minus1[i] + 1;
72 78 sum += row_height[i];
73 79 }
modified drivers/media/platform/rockchip/rkvdec/rkvdec-hevc.c
@@ -12,6 +12,7 @@
12 12 * Jeffy Chen <jeffy.chen@rock-chips.com>
13 13 */
14 14
15 + #include <media/v4l2-hevc.h>
15 16 #include <media/v4l2-mem2mem.h>
16 17
17 18 #include "rkvdec.h"
@@ -135,6 +136,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
135 136 * packet unit). so the driver copy SPS/PPS information to the exact PPS
136 137 * packet unit for HW accessing.
137 138 */
139 + if (pps->pic_parameter_set_id >= ARRAY_SIZE(priv_tbl->param_set))
140 + return;
138 141 hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id];
139 142 memset(hw_ps, 0, sizeof(*hw_ps));
140 143
@@ -253,9 +256,9 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
253 256
254 257 if (pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED) {
255 258 /* Userspace also provide column width and row height for uniform spacing */
256 - for (i = 0; i <= pps->num_tile_columns_minus1; i++)
259 + for (i = 0; i < v4l2_hevc_pps_num_tile_columns(pps); i++)
257 260 WRITE_PPS(pps->column_width_minus1[i], COLUMN_WIDTH(i));
258 - for (i = 0; i <= pps->num_tile_rows_minus1; i++)
261 + for (i = 0; i < v4l2_hevc_pps_num_tile_rows(pps); i++)
259 262 WRITE_PPS(pps->row_height_minus1[i], ROW_HEIGHT(i));
260 263 } else {
261 264 WRITE_PPS(DIV_ROUND_UP(sps->pic_width_in_luma_samples, ctb_size_y) - 1,
modified drivers/media/platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c
@@ -145,6 +145,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
145 145 * packet unit). so the driver copy SPS/PPS information to the exact PPS
146 146 * packet unit for HW accessing.
147 147 */
148 + if (pps->pic_parameter_set_id >= ARRAY_SIZE(priv_tbl->param_set))
149 + return;
148 150 hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id];
149 151 memset(hw_ps, 0, sizeof(*hw_ps));
150 152
modified drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c
@@ -5,6 +5,8 @@
5 5 * Copyright (C) 2020 Safran Passenger Innovations LLC
6 6 */
7 7
8 + #include <media/v4l2-hevc.h>
9 +
8 10 #include "hantro_hw.h"
9 11 #include "hantro_g2_regs.h"
10 12
@@ -15,8 +17,8 @@ static void prepare_tile_info_buffer(struct hantro_ctx *ctx)
15 17 const struct v4l2_ctrl_hevc_pps *pps = ctrls->pps;
16 18 const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
17 19 u16 *p = (u16 *)((u8 *)ctx->hevc_dec.tile_sizes.cpu);
18 - unsigned int num_tile_rows = pps->num_tile_rows_minus1 + 1;
19 - unsigned int num_tile_cols = pps->num_tile_columns_minus1 + 1;
20 + unsigned int num_tile_rows = v4l2_hevc_pps_num_tile_rows(pps);
21 + unsigned int num_tile_cols = v4l2_hevc_pps_num_tile_columns(pps);
20 22 unsigned int pic_width_in_ctbs, pic_height_in_ctbs;
21 23 unsigned int max_log2_ctb_size, ctb_size;
22 24 bool tiles_enabled, uniform_spacing;
modified drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -431,20 +431,39 @@ static int rockchip_vpu981_av1_dec_prepare_run(struct hantro_ctx *ctx)
431 431 {
432 432 struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
433 433 struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls;
434 + const struct v4l2_av1_tile_info *tile_info;
435 + struct v4l2_ctrl *tge;
436 + u32 num_tiles;
434 437
435 438 ctrls->sequence = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_AV1_SEQUENCE);
436 439 if (WARN_ON(!ctrls->sequence))
437 440 return -EINVAL;
438 441
439 - ctrls->tile_group_entry =
440 - hantro_get_ctrl(ctx, V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY);
441 - if (WARN_ON(!ctrls->tile_group_entry))
442 + tge = v4l2_ctrl_find(&ctx->ctrl_handler,
443 + V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY);
444 + if (WARN_ON(!tge))
442 445 return -EINVAL;
446 + ctrls->tile_group_entry = tge->p_cur.p;
443 447
444 448 ctrls->frame = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_AV1_FRAME);
445 449 if (WARN_ON(!ctrls->frame))
446 450 return -EINVAL;
447 451
452 + /*
453 + * rockchip_vpu981_av1_dec_set_tile_info() indexes the tile group
454 + * entry array by tile1 * tile_cols + tile0, so it reads up to
455 + * tile_cols * tile_rows entries, and lays out one descriptor per tile
456 + * in the AV1_MAX_TILES tile_info buffer while programming the real
457 + * tile geometry into the hardware. Reject a frame that claims more
458 + * tiles than userspace submitted, or more than the hardware tile
459 + * buffer holds, so the read stays in bounds and the programmed
460 + * geometry matches the descriptors written.
461 + */
462 + tile_info = &ctrls->frame->tile_info;
463 + num_tiles = (u32)tile_info->tile_cols * tile_info->tile_rows;
464 + if (num_tiles > tge->elems || num_tiles > AV1_MAX_TILES)
465 + return -EINVAL;
466 +
448 467 ctrls->film_grain =
449 468 hantro_get_ctrl(ctx, V4L2_CID_STATELESS_AV1_FILM_GRAIN);
450 469
@@ -578,16 +597,30 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx)
578 597 const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;
579 598 const struct v4l2_ctrl_av1_tile_group_entry *group_entry =
580 599 ctrls->tile_group_entry;
581 - int context_update_y =
582 - tile_info->context_update_tile_id / tile_info->tile_cols;
583 - int context_update_x =
584 - tile_info->context_update_tile_id % tile_info->tile_cols;
585 - int context_update_tile_id =
586 - context_update_x * tile_info->tile_rows + context_update_y;
600 + int context_update_y = 0;
601 + int context_update_x = 0;
602 + int context_update_tile_id = 0;
587 603 u8 *dst = av1_dec->tile_info.cpu;
604 + u8 *dst_end = dst + av1_dec->tile_info.size;
588 605 struct hantro_dev *vpu = ctx->dev;
589 606 int tile0, tile1;
590 607
608 + /*
609 + * tile_cols and tile_rows are bounded by the V4L2 control validation
610 + * (V4L2_AV1_MAX_TILE_{COLS,ROWS} and V4L2_AV1_MAX_TILE_COUNT). Guard
611 + * the divisor here, and keep the descriptor writes within the
612 + * AV1_MAX_TILES tile_info buffer below; the register values use the
613 + * unmodified tile geometry.
614 + */
615 + if (tile_info->tile_cols) {
616 + context_update_y =
617 + tile_info->context_update_tile_id / tile_info->tile_cols;
618 + context_update_x =
619 + tile_info->context_update_tile_id % tile_info->tile_cols;
620 + context_update_tile_id =
621 + context_update_x * tile_info->tile_rows + context_update_y;
622 + }
623 +
591 624 memset(dst, 0, av1_dec->tile_info.size);
592 625
593 626 for (tile0 = 0; tile0 < tile_info->tile_cols; tile0++) {
@@ -598,6 +631,10 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx)
598 631 tile_info->height_in_sbs_minus_1[tile1] + 1;
599 632 u32 x0 = tile_info->width_in_sbs_minus_1[tile0] + 1;
600 633
634 + /* Stop once the tile_info descriptor buffer is full. */
635 + if (dst + 16 > dst_end)
636 + break;
637 +
601 638 /* tile size in SB units (width,height) */
602 639 *dst++ = x0;
603 640 *dst++ = 0;
@@ -622,6 +659,8 @@ static void rockchip_vpu981_av1_dec_set_tile_info(struct hantro_ctx *ctx)
622 659 *dst++ = (end >> 16) & 255;
623 660 *dst++ = (end >> 24) & 255;
624 661 }
662 + if (dst + 16 > dst_end)
663 + break;
625 664 }
626 665
627 666 hantro_reg_write(vpu, &av1_multicore_expect_context_update, !!(context_update_x == 0));
modified drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -793,10 +793,30 @@ static int validate_av1_film_grain(struct v4l2_ctrl_av1_film_grain *fg)
793 793 return 0;
794 794 }
795 795
796 + static int validate_av1_tile_info(struct v4l2_av1_tile_info *t)
797 + {
798 + /*
799 + * tile_cols and tile_rows index the per-tile descriptor arrays and
800 + * bound the tile loops in the stateless AV1 drivers; the product
801 + * bounds the total tile descriptor count.
802 + */
803 + if (t->tile_cols > V4L2_AV1_MAX_TILE_COLS ||
804 + t->tile_rows > V4L2_AV1_MAX_TILE_ROWS)
805 + return -EINVAL;
806 +
807 + if ((u32)t->tile_cols * t->tile_rows > V4L2_AV1_MAX_TILE_COUNT)
808 + return -EINVAL;
809 +
810 + return 0;
811 + }
812 +
796 813 static int validate_av1_frame(struct v4l2_ctrl_av1_frame *f)
797 814 {
798 815 int ret = 0;
799 816
817 + ret = validate_av1_tile_info(&f->tile_info);
818 + if (ret)
819 + return ret;
800 820 ret = validate_av1_quantization(&f->quantization);
801 821 if (ret)
802 822 return ret;
@@ -1253,6 +1273,18 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
1253 1273
1254 1274 p_hevc_pps->flags &=
1255 1275 ~V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED;
1276 + } else {
1277 + /*
1278 + * These count the entries the stateless HEVC drivers
1279 + * read from column_width_minus1[] / row_height_minus1[]
1280 + * and use as tile-loop bounds.
1281 + */
1282 + if (p_hevc_pps->num_tile_columns_minus1 >=
1283 + ARRAY_SIZE(p_hevc_pps->column_width_minus1))
1284 + return -EINVAL;
1285 + if (p_hevc_pps->num_tile_rows_minus1 >=
1286 + ARRAY_SIZE(p_hevc_pps->row_height_minus1))
1287 + return -EINVAL;
1256 1288 }
1257 1289
1258 1290 if (p_hevc_pps->flags &
modified drivers/media/v4l2-core/v4l2-h264.c
@@ -440,7 +440,8 @@ v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
440 440 }
441 441
442 442 if (builder->num_valid > 1 &&
443 - !memcmp(b1_reflist, b0_reflist, builder->num_valid))
443 + !memcmp(b1_reflist, b0_reflist,
444 + sizeof(b1_reflist[0]) * builder->num_valid))
444 445 swap(b1_reflist[0], b1_reflist[1]);
445 446
446 447 print_ref_list_b(builder, b0_reflist, 0);
modified drivers/net/bonding/bond_alb.c
@@ -678,9 +678,15 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
678 678 if (arp->op_code == htons(ARPOP_REPLY)) {
679 679 /* the arp must be sent on the selected rx channel */
680 680 tx_slave = rlb_choose_channel(skb, bond, arp);
681 - if (tx_slave)
681 + if (tx_slave &&
682 + !ether_addr_equal_64bits(arp->mac_src,
683 + tx_slave->dev->dev_addr)) {
684 + if (unlikely(skb_cow_head(skb, 0)))
685 + return NULL;
686 + arp = (struct arp_pkt *)skb_network_header(skb);
682 687 bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr,
683 688 tx_slave->dev->addr_len);
689 + }
684 690 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n",
685 691 tx_slave ? tx_slave->dev->name : "NULL");
686 692 } else if (arp->op_code == htons(ARPOP_REQUEST)) {
@@ -1340,7 +1346,6 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
1340 1346 struct slave *tx_slave)
1341 1347 {
1342 1348 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1343 - struct ethhdr *eth_data = eth_hdr(skb);
1344 1349
1345 1350 if (!tx_slave) {
1346 1351 /* unbalanced or unassigned, send through primary */
@@ -1351,7 +1356,9 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
1351 1356
1352 1357 if (tx_slave && bond_slave_can_tx(tx_slave)) {
1353 1358 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) {
1354 - ether_addr_copy(eth_data->h_source,
1359 + if (unlikely(skb_cow_head(skb, 0)))
1360 + return bond_tx_drop(bond->dev, skb);
1361 + ether_addr_copy(skb_eth_hdr(skb)->h_source,
1355 1362 tx_slave->dev->dev_addr);
1356 1363 }
1357 1364
@@ -1375,8 +1382,7 @@ struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1375 1382 struct ethhdr *eth_data;
1376 1383 u32 hash_index;
1377 1384
1378 - skb_reset_mac_header(skb);
1379 - eth_data = eth_hdr(skb);
1385 + eth_data = skb_eth_hdr(skb);
1380 1386
1381 1387 /* Do not TX balance any multicast or broadcast */
1382 1388 if (!is_multicast_ether_addr(eth_data->h_dest)) {
@@ -1428,8 +1434,7 @@ struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1428 1434 u32 hash_index = 0;
1429 1435 int hash_size = 0;
1430 1436
1431 - skb_reset_mac_header(skb);
1432 - eth_data = eth_hdr(skb);
1437 + eth_data = skb_eth_hdr(skb);
1433 1438
1434 1439 switch (ntohs(skb->protocol)) {
1435 1440 case ETH_P_IP: {
modified drivers/net/dsa/bcm_sf2_cfp.c
@@ -1088,6 +1088,8 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv,
1088 1088 unsigned int index = 1, rules_cnt = 0;
1089 1089
1090 1090 for_each_set_bit_from(index, priv->cfp.unique, priv->num_cfp_rules) {
1091 + if (rules_cnt == nfc->rule_cnt)
1092 + return -EMSGSIZE;
1091 1093 rule_locs[rules_cnt] = index;
1092 1094 rules_cnt++;
1093 1095 }
modified drivers/net/dsa/lantiq/lantiq_gswip.h
@@ -42,7 +42,7 @@
42 42 #define GSWIP_MDIO_PHY_FDUP_DIS 0x0600
43 43 #define GSWIP_MDIO_PHY_FCONTX_MASK 0x0180
44 44 #define GSWIP_MDIO_PHY_FCONTX_AUTO 0x0000
45 - #define GSWIP_MDIO_PHY_FCONTX_EN 0x0100
45 + #define GSWIP_MDIO_PHY_FCONTX_EN 0x0080
46 46 #define GSWIP_MDIO_PHY_FCONTX_DIS 0x0180
47 47 #define GSWIP_MDIO_PHY_FCONRX_MASK 0x0060
48 48 #define GSWIP_MDIO_PHY_FCONRX_AUTO 0x0000
modified drivers/net/dsa/mt7530.c
@@ -3172,23 +3172,31 @@ static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
3172 3172
3173 3173 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
3174 3174
3175 + priv->info->mac_port_get_caps(ds, port, config);
3176 +
3175 3177 /* The EN7528 GPHYs report EEE capability, but negotiating EEE with
3176 3178 * common link partners (e.g. Realtek GbE NICs) results in an unstable
3177 3179 * link with dropped frames. Leave the LPI capabilities empty so that
3178 3180 * phylink disables EEE on these PHYs and refuses to enable it from
3179 3181 * userspace.
3180 3182 */
3181 - if (priv->id != ID_EN7528) {
3183 + if (priv->id != ID_EN7528 &&
3184 + config->mac_capabilities & (MAC_100FD | MAC_1000FD)) {
3182 3185 u32 eeecr = mt7530_read(priv, MT753X_PMEEECR_P(port));
3183 3186
3184 - config->lpi_capabilities = MAC_100FD | MAC_1000FD | MAC_2500FD;
3187 + /* LPI above 1 Gbps is not supported */
3188 + config->lpi_capabilities = config->mac_capabilities &
3189 + (MAC_100FD | MAC_1000FD);
3190 + phy_interface_copy(config->lpi_interfaces,
3191 + config->supported_interfaces);
3192 + __clear_bit(PHY_INTERFACE_MODE_2500BASEX,
3193 + config->lpi_interfaces);
3194 +
3185 3195 /* tx_lpi_timer should be in microseconds. The time units for
3186 3196 * LPI threshold are unspecified.
3187 3197 */
3188 3198 config->lpi_timer_default = FIELD_GET(LPI_THRESH_MASK, eeecr);
3189 3199 }
3190 -
3191 - priv->info->mac_port_get_caps(ds, port, config);
3192 3200 }
3193 3201
3194 3202 static int mt753x_pcs_validate(struct phylink_pcs *pcs,
modified drivers/net/dsa/mv88e6xxx/chip.c
@@ -2438,6 +2438,7 @@ static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
2438 2438 struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
2439 2439 struct mv88e6xxx_chip *chip = ds->priv;
2440 2440 struct mv88e6xxx_policy *policy;
2441 + u32 cnt = 0;
2441 2442 int err;
2442 2443 int id;
2443 2444
@@ -2463,11 +2464,18 @@ static int mv88e6xxx_get_rxnfc(struct dsa_switch *ds, int port,
2463 2464 break;
2464 2465 case ETHTOOL_GRXCLSRLALL:
2465 2466 rxnfc->data = 0;
2466 - rxnfc->rule_cnt = 0;
2467 - idr_for_each_entry(&chip->policies, policy, id)
2468 - if (policy->port == port)
2469 - rule_locs[rxnfc->rule_cnt++] = id;
2470 2467 err = 0;
2468 + idr_for_each_entry(&chip->policies, policy, id) {
2469 + if (policy->port != port)
2470 + continue;
2471 + if (cnt == rxnfc->rule_cnt) {
2472 + err = -EMSGSIZE;
2473 + break;
2474 + }
2475 + rule_locs[cnt++] = id;
2476 + }
2477 + if (!err)
2478 + rxnfc->rule_cnt = cnt;
2471 2479 break;
2472 2480 default:
2473 2481 err = -EOPNOTSUPP;
modified drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -1067,6 +1067,7 @@ static int emac_probe(struct platform_device *pdev)
1067 1067 return 0;
1068 1068
1069 1069 out_release_sram:
1070 + of_node_put(db->phy_node);
1070 1071 sunxi_sram_release(&pdev->dev);
1071 1072 out_clk_disable_unprepare:
1072 1073 clk_disable_unprepare(db->clk);
@@ -1094,6 +1095,7 @@ static void emac_remove(struct platform_device *pdev)
1094 1095 }
1095 1096
1096 1097 unregister_netdev(ndev);
1098 + of_node_put(db->phy_node);
1097 1099 sunxi_sram_release(&pdev->dev);
1098 1100 clk_disable_unprepare(db->clk);
1099 1101 irq_dispose_mapping(ndev->irq);
modified drivers/net/ethernet/amd/pds_core/fw.c
@@ -171,8 +171,10 @@ pdsc_legacy_firmware_update(struct pdsc *pdsc,
171 171
172 172 dev_info(pdsc->dev, "Installing firmware\n");
173 173
174 - if (!pdsc->cmd_regs)
174 + if (!pdsc->cmd_regs) {
175 + NL_SET_ERR_MSG_MOD(extack, "BARs not mapped");
175 176 return -ENXIO;
177 + }
176 178
177 179 dl = priv_to_devlink(pdsc);
178 180 devlink_flash_update_status_notify(dl, "Preparing to flash",
@@ -198,6 +200,12 @@ pdsc_legacy_firmware_update(struct pdsc *pdsc,
198 200
199 201 copy_sz = min_t(unsigned int, buf_sz, fw->size - offset);
200 202 mutex_lock(&pdsc->devcmd_lock);
203 + if (!pdsc->cmd_regs) {
204 + mutex_unlock(&pdsc->devcmd_lock);
205 + err = -ENXIO;
206 + NL_SET_ERR_MSG_MOD(extack, "Device reset during flash");
207 + goto err_out;
208 + }
201 209 memcpy_toio(&pdsc->cmd_regs->data, fw->data + offset, copy_sz);
202 210 err = pdsc_devcmd_fw_download_locked(pdsc, data_addr,
203 211 offset, copy_sz);
modified drivers/net/ethernet/amd/pds_core/main.c
@@ -513,8 +513,12 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)
513 513 pdsc_auxbus_dev_del(pdsc, pdsc, &pdsc->padev);
514 514 }
515 515
516 - pdsc_unmap_bars(pdsc);
517 - pci_release_regions(pdev);
516 + if (!pdev->is_virtfn) {
517 + mutex_lock(&pdsc->devcmd_lock);
518 + pdsc_unmap_bars(pdsc);
519 + mutex_unlock(&pdsc->devcmd_lock);
520 + pci_release_regions(pdev);
521 + }
518 522 if (pci_is_enabled(pdev))
519 523 pci_disable_device(pdev);
520 524 pdsc_deferred_dma_free(pdsc);
@@ -543,7 +547,9 @@ static void pdsc_reset_done(struct pci_dev *pdev)
543 547 return;
544 548 }
545 549
550 + mutex_lock(&pdsc->devcmd_lock);
546 551 err = pdsc_map_bars(pdsc);
552 + mutex_unlock(&pdsc->devcmd_lock);
547 553 if (err)
548 554 return;
549 555 }
modified drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -148,8 +148,9 @@ static int tx_spb_ring_full(struct bcmasp_intf *intf, int cnt)
148 148 int next_index, i;
149 149
150 150 /* Check if we have enough room for cnt descriptors */
151 + next_index = intf->tx_spb_index;
151 152 for (i = 0; i < cnt; i++) {
152 - next_index = incr_ring(intf->tx_spb_index, DESC_RING_COUNT);
153 + next_index = incr_ring(next_index, DESC_RING_COUNT);
153 154 if (next_index == intf->tx_spb_clean_index)
154 155 return 1;
155 156 }
@@ -301,6 +302,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
301 302 txcb->bytes_sent = total_bytes;
302 303 dma_unmap_addr_set(txcb, dma_addr, mapping);
303 304 dma_unmap_len_set(txcb, dma_len, size);
305 + txcb->last = false;
304 306 if (!i) {
305 307 desc->flags |= DESC_SOF;
306 308 if (csum_hw)
modified drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -462,6 +462,16 @@ u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
462 462 static void bnxt_txr_db_kick(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
463 463 u16 prod)
464 464 {
465 + /* If the most recent BD has its completion suppressed, unset the bit
466 + * so that a completion is generated, otherwise nothing is left to
467 + * clean the ring and wake the queue.
468 + */
469 + if (txr->kick_txbd0) {
470 + txr->kick_txbd0->tx_bd_len_flags_type &=
471 + cpu_to_le32(~TX_BD_FLAGS_NO_CMPL);
472 + txr->kick_txbd0 = NULL;
473 + }
474 +
465 475 /* Sync BD data before updating doorbell */
466 476 wmb();
467 477 bnxt_db_write(bp, &txr->tx_db, prod);
@@ -485,7 +495,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
485 495 struct bnxt_sw_tx_bd *tx_buf;
486 496 __le32 lflags = 0;
487 497 skb_frag_t *frag;
488 - netdev_tx_t ret;
489 498
490 499 i = skb_get_queue_mapping(skb);
491 500 if (unlikely(i >= bp->tx_nr_rings)) {
@@ -509,11 +518,22 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
509 518 if (skb_is_gso(skb) &&
510 519 (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) &&
511 520 !(bp->flags & BNXT_FLAG_UDP_GSO_CAP)) {
512 - ret = bnxt_sw_udp_gso_xmit(bp, txr, txq, skb);
513 - if (txr->kick_pending)
521 + int rc = bnxt_sw_udp_gso_xmit(bp, txr, txq, skb);
522 +
523 + /* if SW USO queued a packet, the doorbell will be written
524 + * below and there is no reason to track the last BD with
525 + * suppressed completions
526 + */
527 + if (rc > 0)
528 + txr->kick_txbd0 = NULL;
529 +
530 + /* if a packet was queued by SW USO or a doorbell was pending
531 + * from a previous xmit that was deferred, write the doorbell.
532 + */
533 + if (rc > 0 || txr->kick_pending)
514 534 bnxt_txr_db_kick(bp, txr, txr->tx_prod);
515 535
516 - return ret;
536 + return rc < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK;
517 537 }
518 538
519 539 free_size = bnxt_tx_avail(bp, txr);
@@ -751,23 +771,23 @@ normal_tx:
751 771 prod = NEXT_TX(prod);
752 772 WRITE_ONCE(txr->tx_prod, prod);
753 773
774 + txr->kick_txbd0 = NULL;
754 775 if (!netdev_xmit_more() || netif_xmit_stopped(txq)) {
755 776 bnxt_txr_db_kick(bp, txr, prod);
756 777 } else {
757 - if (free_size >= bp->tx_wake_thresh)
778 + if (free_size >= bp->tx_wake_thresh) {
758 779 txbd0->tx_bd_len_flags_type |=
759 780 cpu_to_le32(TX_BD_FLAGS_NO_CMPL);
781 + txr->kick_txbd0 = txbd0;
782 + }
760 783 txr->kick_pending = 1;
761 784 }
762 785
763 786 tx_done:
764 787
765 788 if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
766 - if (netdev_xmit_more() && !tx_buf->is_push) {
767 - txbd0->tx_bd_len_flags_type &=
768 - cpu_to_le32(~TX_BD_FLAGS_NO_CMPL);
789 + if (txr->kick_pending)
769 790 bnxt_txr_db_kick(bp, txr, prod);
770 - }
771 791
772 792 netif_txq_try_stop(txq, bnxt_tx_avail(bp, txr),
773 793 bp->tx_wake_thresh);
@@ -1514,14 +1534,16 @@ static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1514 1534 return 0;
1515 1535 }
1516 1536
1517 - static u16 bnxt_alloc_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
1537 + static u16 bnxt_alloc_agg_idx(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1538 + u16 agg_id)
1518 1539 {
1519 1540 struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
1520 - u16 idx = agg_id & MAX_TPA_P5_MASK;
1541 + u16 idx = agg_id & (bp->max_tpa_roundup_size - 1);
1521 1542
1522 1543 if (test_bit(idx, map->agg_idx_bmap)) {
1523 - idx = find_first_zero_bit(map->agg_idx_bmap, MAX_TPA_P5);
1524 - if (idx >= MAX_TPA_P5)
1544 + idx = find_first_zero_bit(map->agg_idx_bmap,
1545 + bp->max_tpa_roundup_size);
1546 + if (idx >= bp->max_tpa_roundup_size)
1525 1547 return INVALID_HW_RING_ID;
1526 1548 }
1527 1549 __set_bit(idx, map->agg_idx_bmap);
@@ -1586,7 +1608,7 @@ static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
1586 1608
1587 1609 if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
1588 1610 agg_id = TPA_START_AGG_ID_P5(tpa_start);
1589 - agg_id = bnxt_alloc_agg_idx(rxr, agg_id);
1611 + agg_id = bnxt_alloc_agg_idx(bp, rxr, agg_id);
1590 1612 if (unlikely(agg_id == INVALID_HW_RING_ID)) {
1591 1613 netdev_warn(bp->dev, "Unable to allocate agg ID for ring %d, agg 0x%x\n",
1592 1614 rxr->bnapi->index,
@@ -3584,7 +3606,7 @@ static void bnxt_free_one_tpa_info_data(struct bnxt *bp,
3584 3606 {
3585 3607 int i;
3586 3608
3587 - for (i = 0; i < bp->max_tpa; i++) {
3609 + for (i = 0; i < bp->max_tpa_roundup_size; i++) {
3588 3610 struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[i];
3589 3611 u8 *data = tpa_info->data;
3590 3612
@@ -3781,7 +3803,7 @@ static void bnxt_free_one_tpa_info(struct bnxt *bp,
3781 3803 kfree(rxr->rx_tpa_idx_map);
3782 3804 rxr->rx_tpa_idx_map = NULL;
3783 3805 if (rxr->rx_tpa) {
3784 - for (i = 0; i < bp->max_tpa; i++) {
3806 + for (i = 0; i < bp->max_tpa_roundup_size; i++) {
3785 3807 kfree(rxr->rx_tpa[i].agg_arr);
3786 3808 rxr->rx_tpa[i].agg_arr = NULL;
3787 3809 }
@@ -3807,13 +3829,14 @@ static int bnxt_alloc_one_tpa_info(struct bnxt *bp,
3807 3829 struct rx_agg_cmp *agg;
3808 3830 int i;
3809 3831
3810 - rxr->rx_tpa = kzalloc_objs(struct bnxt_tpa_info, bp->max_tpa);
3832 + rxr->rx_tpa = kzalloc_objs(struct bnxt_tpa_info,
3833 + bp->max_tpa_roundup_size);
3811 3834 if (!rxr->rx_tpa)
3812 3835 return -ENOMEM;
3813 3836
3814 3837 if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
3815 3838 return 0;
3816 - for (i = 0; i < bp->max_tpa; i++) {
3839 + for (i = 0; i < bp->max_tpa_roundup_size; i++) {
3817 3840 agg = kzalloc_objs(*agg, MAX_SKB_FRAGS);
3818 3841 if (!agg)
3819 3842 return -ENOMEM;
@@ -3832,6 +3855,9 @@ static int bnxt_alloc_tpa_info(struct bnxt *bp)
3832 3855
3833 3856 bp->max_tpa = MAX_TPA;
3834 3857 if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
3858 + /* TPA is not supported at all, so there is nothing to
3859 + * allocate.
3860 + */
3835 3861 if (!bp->max_tpa_v2)
3836 3862 return 0;
3837 3863 bp->max_tpa = min_t(u16, bp->max_tpa_v2, MAX_TPA_P5);
@@ -3839,6 +3865,7 @@ static int bnxt_alloc_tpa_info(struct bnxt *bp)
3839 3865 if (bp->max_tpa <= 32 && BNXT_CHIP_P5(bp) && !BNXT_NPAR(bp))
3840 3866 bp->max_tpa = MAX_TPA_P5;
3841 3867 }
3868 + bp->max_tpa_roundup_size = roundup_pow_of_two(bp->max_tpa);
3842 3869
3843 3870 for (i = 0; i < bp->rx_nr_rings; i++) {
3844 3871 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
@@ -4551,7 +4578,7 @@ static int bnxt_alloc_one_tpa_info_data(struct bnxt *bp,
4551 4578 u8 *data;
4552 4579 int i;
4553 4580
4554 - for (i = 0; i < bp->max_tpa; i++) {
4581 + for (i = 0; i < bp->max_tpa_roundup_size; i++) {
4555 4582 data = __bnxt_alloc_rx_frag(bp, &mapping, rxr,
4556 4583 GFP_KERNEL);
4557 4584 if (!data)
@@ -5006,7 +5033,8 @@ void bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
5006 5033 bnxt_get_max_rings(bp, &rx, &tx, true);
5007 5034 if (rx > 1) {
5008 5035 bp->flags &= ~BNXT_FLAG_NO_AGG_RINGS;
5009 - bp->dev->hw_features |= NETIF_F_LRO;
5036 + if (BNXT_SUPPORTS_TPA(bp))
5037 + bp->dev->hw_features |= NETIF_F_LRO;
5010 5038 }
5011 5039 }
5012 5040
@@ -5427,6 +5455,8 @@ static void bnxt_clear_ring_indices(struct bnxt *bp)
5427 5455 txr->tx_prod = 0;
5428 5456 txr->tx_cons = 0;
5429 5457 txr->tx_hw_cons = 0;
5458 + txr->kick_pending = 0;
5459 + txr->kick_txbd0 = NULL;
5430 5460 }
5431 5461
5432 5462 rxr = bnapi->rx_ring;
@@ -11340,8 +11370,13 @@ static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
11340 11370
11341 11371 static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
11342 11372 {
11373 + int rc;
11374 +
11343 11375 bnxt_init_cp_rings(bp);
11344 - bnxt_init_rx_rings(bp);
11376 + rc = bnxt_init_rx_rings(bp);
11377 + if (rc)
11378 + return rc;
11379 +
11345 11380 bnxt_init_tx_rings(bp);
11346 11381 bnxt_init_ring_grps(bp, irq_re_init);
11347 11382 bnxt_init_vnics(bp);
@@ -11772,6 +11807,8 @@ static int bnxt_tx_queue_start(struct bnxt *bp, int idx)
11772 11807 txr->tx_prod = 0;
11773 11808 txr->tx_cons = 0;
11774 11809 txr->tx_hw_cons = 0;
11810 + txr->kick_pending = 0;
11811 + txr->kick_txbd0 = NULL;
11775 11812 start_tx:
11776 11813 WRITE_ONCE(txr->dev_state, 0);
11777 11814 synchronize_net();
@@ -14603,7 +14640,14 @@ static void bnxt_rx_ring_reset(struct bnxt *bp)
14603 14640 rxr->rx_sw_agg_prod = 0;
14604 14641 rxr->rx_next_cons = 0;
14605 14642 rxr->bnapi->in_reset = false;
14606 - bnxt_alloc_one_rx_ring(bp, i);
14643 + rc = bnxt_alloc_one_rx_ring(bp, i);
14644 + if (rc) {
14645 + netdev_warn(bp->dev, "RX ring reset failed to allocate buffers, rc = %d, falling back to global reset\n",
14646 + rc);
14647 + bnxt_reset_task(bp, true);
14648 + bnxt_rtnl_unlock_sp(bp);
14649 + return;
14650 + }
14607 14651 cpr = &rxr->bnapi->cp_ring;
14608 14652 cpr->sw_stats->rx.rx_resets++;
14609 14653 if (bp->flags & BNXT_FLAG_AGG_RINGS)
@@ -16332,6 +16376,8 @@ static int bnxt_queue_mem_alloc(struct net_device *dev,
16332 16376 clone->need_head_pool = false;
16333 16377 clone->rx_page_size = qcfg->rx_page_size;
16334 16378 clone->rx_agg_bmap = NULL;
16379 + clone->rx_tpa = NULL;
16380 + clone->rx_tpa_idx_map = NULL;
16335 16381
16336 16382 rc = bnxt_alloc_rx_page_pool(bp, clone, rxr->page_pool->p.nid);
16337 16383 if (rc)
@@ -16375,11 +16421,16 @@ static int bnxt_queue_mem_alloc(struct net_device *dev,
16375 16421 bnxt_alloc_one_rx_ring_skb(bp, clone, idx);
16376 16422 if (bp->flags & BNXT_FLAG_AGG_RINGS)
16377 16423 bnxt_alloc_one_rx_ring_netmem(bp, clone, idx);
16378 - if (bp->flags & BNXT_FLAG_TPA)
16379 - bnxt_alloc_one_tpa_info_data(bp, clone);
16424 + if (bp->flags & BNXT_FLAG_TPA) {
16425 + rc = bnxt_alloc_one_tpa_info_data(bp, clone);
16426 + if (rc)
16427 + goto err_free_rx_ring_skbs;
16428 + }
16380 16429
16381 16430 return 0;
16382 16431
16432 + err_free_rx_ring_skbs:
16433 + bnxt_free_one_rx_ring_skbs(bp, clone);
16383 16434 err_free_tpa_info:
16384 16435 bnxt_free_one_tpa_info(bp, clone);
16385 16436 err_free_rx_agg_ring:
modified drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -789,7 +789,6 @@ struct nqe_cn {
789 789
790 790 #define MAX_TPA 64
791 791 #define MAX_TPA_P5 256
792 - #define MAX_TPA_P5_MASK (MAX_TPA_P5 - 1)
793 792 #define MAX_TPA_SEGS_P5 0x3f
794 793
795 794 #if (BNXT_PAGE_SHIFT == 16)
@@ -993,6 +992,7 @@ struct bnxt_tx_ring_info {
993 992 u16 txq_index;
994 993 u8 tx_napi_idx;
995 994 u8 kick_pending;
995 + struct tx_bd *kick_txbd0;
996 996 struct bnxt_db_info tx_db;
997 997
998 998 struct tx_bd *tx_desc_ring[MAX_TX_PAGES];
@@ -2380,6 +2380,7 @@ struct bnxt {
2380 2380
2381 2381 u16 max_tpa_v2;
2382 2382 u16 max_tpa;
2383 + u16 max_tpa_roundup_size;
2383 2384 u32 rx_buf_size;
2384 2385 u32 rx_buf_use_size; /* useable size */
2385 2386 u16 rx_offset;
modified drivers/net/ethernet/broadcom/bnxt/bnxt_gso.c
@@ -31,10 +31,14 @@ static u32 bnxt_sw_gso_lhint(unsigned int len)
31 31 return TX_BD_FLAGS_LHINT_2048_AND_LARGER;
32 32 }
33 33
34 - netdev_tx_t bnxt_sw_udp_gso_xmit(struct bnxt *bp,
35 - struct bnxt_tx_ring_info *txr,
36 - struct netdev_queue *txq,
37 - struct sk_buff *skb)
34 + /* Transmit an skb requiring software UDP segmentation.
35 + *
36 + * Returns 1 if the skb was queued and new BDs were produced, 0 if the skb
37 + * was dropped, or -1 if the ring is full and the skb should be retried.
38 + * The caller owns the doorbell for all three cases.
39 + */
40 + int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
41 + struct netdev_queue *txq, struct sk_buff *skb)
38 42 {
39 43 unsigned int last_unmap_len __maybe_unused = 0;
40 44 dma_addr_t last_unmap_addr __maybe_unused = 0;
@@ -69,7 +73,7 @@ netdev_tx_t bnxt_sw_udp_gso_xmit(struct bnxt *bp,
69 73 if (unlikely(bnxt_tx_avail(bp, txr) < bds_needed)) {
70 74 netif_txq_try_stop(txq, bnxt_tx_avail(bp, txr),
71 75 bp->tx_wake_thresh);
72 - return NETDEV_TX_BUSY;
76 + return -1;
73 77 }
74 78
75 79 /* BD backpressure alone cannot prevent overwriting in-flight
@@ -77,7 +81,7 @@ netdev_tx_t bnxt_sw_udp_gso_xmit(struct bnxt *bp,
77 81 */
78 82 if (!netif_txq_maybe_stop(txq, bnxt_inline_avail(txr),
79 83 num_segs, num_segs))
80 - return NETDEV_TX_BUSY;
84 + return -1;
81 85
82 86 if (unlikely(tso_dma_map_init(&map, &pdev->dev, skb, hdr_len)))
83 87 goto drop;
@@ -223,16 +227,15 @@ netdev_tx_t bnxt_sw_udp_gso_xmit(struct bnxt *bp,
223 227 netdev_tx_sent_queue(txq, skb->len);
224 228
225 229 WRITE_ONCE(txr->tx_prod, prod);
226 - txr->kick_pending = 1;
227 230
228 231 if (unlikely(bnxt_tx_avail(bp, txr) <= bp->tx_wake_thresh))
229 232 netif_txq_try_stop(txq, bnxt_tx_avail(bp, txr),
230 233 bp->tx_wake_thresh);
231 234
232 - return NETDEV_TX_OK;
235 + return 1;
233 236
234 237 drop:
235 238 dev_kfree_skb_any(skb);
236 239 dev_core_stats_tx_dropped_inc(bp->dev);
237 - return NETDEV_TX_OK;
240 + return 0;
238 241 }
modified drivers/net/ethernet/broadcom/bnxt/bnxt_gso.h
@@ -38,9 +38,7 @@ static inline int bnxt_min_tx_desc_cnt(struct bnxt *bp,
38 38 return BNXT_MIN_TX_DESC_CNT;
39 39 }
40 40
41 - netdev_tx_t bnxt_sw_udp_gso_xmit(struct bnxt *bp,
42 - struct bnxt_tx_ring_info *txr,
43 - struct netdev_queue *txq,
44 - struct sk_buff *skb);
41 + int bnxt_sw_udp_gso_xmit(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
42 + struct netdev_queue *txq, struct sk_buff *skb);
45 43
46 44 #endif
modified drivers/net/ethernet/cadence/macb_main.c
@@ -1164,6 +1164,8 @@ static int macb_mii_init(struct macb *bp)
1164 1164 if (err)
1165 1165 goto err_out_unregister_bus;
1166 1166
1167 + of_node_put(mdio_np);
1168 +
1167 1169 return 0;
1168 1170
1169 1171 err_out_unregister_bus:
@@ -4300,9 +4302,9 @@ static int macb_taprio_setup_replace(struct net_device *netdev,
4300 4302 u64 total_on_time = 0, start_time_sec = 0, start_time = conf->base_time;
4301 4303 u32 configured_queues = 0, speed = 0, start_time_nsec;
4302 4304 struct macb_queue_enst_config *enst_queue;
4303 - struct tc_taprio_sched_entry *entry;
4305 + struct ethtool_link_ksettings kset = {};
4304 4306 struct macb *bp = netdev_priv(netdev);
4305 - struct ethtool_link_ksettings kset;
4307 + struct tc_taprio_sched_entry *entry;
4306 4308 struct macb_queue *queue;
4307 4309 u32 queue_mask;
4308 4310 u8 queue_id;
@@ -4329,8 +4331,8 @@ static int macb_taprio_setup_replace(struct net_device *netdev,
4329 4331 }
4330 4332
4331 4333 speed = kset.base.speed;
4332 - if (unlikely(speed <= 0)) {
4333 - netdev_err(netdev, "Invalid speed: %d\n", speed);
4334 + if (unlikely(speed == SPEED_UNKNOWN || !speed)) {
4335 + netdev_err(netdev, "Invalid speed %d, link-down?\n", speed);
4334 4336 return -EINVAL;
4335 4337 }
4336 4338
@@ -5881,6 +5883,7 @@ static int macb_probe(struct platform_device *pdev)
5881 5883 }
5882 5884 spin_lock_init(&bp->lock);
5883 5885 spin_lock_init(&bp->stats_lock);
5886 + spin_lock_init(&bp->tsu_clk_lock);
5884 5887
5885 5888 /* setup capabilities */
5886 5889 macb_configure_caps(bp, macb_config);
@@ -5976,8 +5979,11 @@ err_out_free_tieoff:
5976 5979 macb_free_tieoff(bp);
5977 5980
5978 5981 err_out_unregister_mdio:
5979 - mdiobus_unregister(bp->mii_bus);
5980 - mdiobus_free(bp->mii_bus);
5982 + if (bp->mii_bus) {
5983 + mdiobus_unregister(bp->mii_bus);
5984 + mdiobus_free(bp->mii_bus);
5985 + }
5986 + phylink_destroy(bp->phylink);
5981 5987
5982 5988 err_out_phy_exit:
5983 5989 phy_exit(bp->phy);
@@ -6006,8 +6012,10 @@ static void macb_remove(struct platform_device *pdev)
6006 6012 unregister_netdev(netdev);
6007 6013 macb_free_tieoff(bp);
6008 6014 phy_exit(bp->phy);
6009 - mdiobus_unregister(bp->mii_bus);
6010 - mdiobus_free(bp->mii_bus);
6015 + if (bp->mii_bus) {
6016 + mdiobus_unregister(bp->mii_bus);
6017 + mdiobus_free(bp->mii_bus);
6018 + }
6011 6019
6012 6020 device_set_wakeup_enable(&bp->pdev->dev, 0);
6013 6021 cancel_delayed_work_sync(&bp->tx_lpi_work);
modified drivers/net/ethernet/cadence/macb_ptp.c
@@ -334,6 +334,7 @@ void gem_ptp_init(struct net_device *netdev)
334 334 bp->tsu_rate = bp->ptp_info->get_tsu_rate(bp);
335 335 bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj();
336 336 gem_ptp_init_timer(bp);
337 + gem_ptp_init_tsu(bp);
337 338 bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &netdev->dev);
338 339 if (IS_ERR(bp->ptp_clock)) {
339 340 pr_err("ptp clock register failed: %ld\n",
@@ -345,10 +346,6 @@ void gem_ptp_init(struct net_device *netdev)
345 346 return;
346 347 }
347 348
348 - spin_lock_init(&bp->tsu_clk_lock);
349 -
350 - gem_ptp_init_tsu(bp);
351 -
352 349 dev_info(&bp->pdev->dev, "%s ptp clock registered.\n",
353 350 GEM_PTP_TIMER_NAME);
354 351 }
modified drivers/net/ethernet/cisco/enic/enic.h
@@ -137,6 +137,12 @@ struct enic_port_profile {
137 137 u8 mac_addr[ETH_ALEN];
138 138 };
139 139
140 + enum enic_vf_link_state {
141 + ENIC_VF_LINK_STATE_UNKNOWN,
142 + ENIC_VF_LINK_STATE_DOWN,
143 + ENIC_VF_LINK_STATE_UP,
144 + };
145 +
140 146 /* enic_rfs_fltr_node - rfs filter node in hash table
141 147 * @@keys: IPv4 5 tuple
142 148 * @flow_id: flow_id of clsf filter provided by kernel
@@ -312,19 +318,25 @@ struct enic {
312 318 unsigned int admin_msg_count; /* current depth of admin_msg_list */
313 319 void (*admin_rq_handler)(struct enic *enic, void *buf,
314 320 unsigned int len);
321 + /* The PF is authoritative for a V2 VF's carrier. Keep the last
322 + * notification across an ordinary netdev close/open and serialize it
323 + * against the open/stop carrier transition.
324 + */
325 + spinlock_t vf_link_state_lock;
326 + enum enic_vf_link_state vf_link_state;
327 + bool vf_link_running;
315 328
316 329 /* MBOX protocol state — mbox_lock serializes admin WQ sends */
317 330 struct mutex mbox_lock;
318 331 u64 mbox_msg_num;
319 - /* MBOX request-reply state. mbox_expected_reply is written and
320 - * cleared by the process-context request helpers (capability/register/
321 - * unregister) and only read by the admin_msg_work receive handlers, so
322 - * it is annotated with READ_ONCE()/WRITE_ONCE() rather than locked:
323 - * only one request is in flight at a time (requesters run under RTNL or
324 - * single-threaded probe/remove), so each request is serialized and its
325 - * reply completes mbox_comp before the next request is issued.
332 + /* MBOX request-reply state. Existing request callers allow only one
333 + * request in flight. The state lock arbitrates reply acceptance against
334 + * timeout invalidation, while mbox_comp publishes the accepted result to
335 + * the requester.
326 336 */
327 337 struct completion mbox_comp;
338 + spinlock_t mbox_state_lock; /* protects expected reply state */
339 + u64 mbox_expected_msg_num;
328 340 u8 mbox_expected_reply;
329 341 bool mbox_initialized;
330 342
modified drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1800,6 +1800,8 @@ static int enic_open(struct net_device *netdev)
1800 1800
1801 1801 enic_notify_timer_start(enic);
1802 1802 enic_rfs_timer_start(enic);
1803 + if (enic_is_sriov_vf_v2(enic))
1804 + enic_mbox_vf_link_state_set_running(enic, true);
1803 1805
1804 1806 return 0;
1805 1807
@@ -1853,7 +1855,10 @@ static int enic_stop(struct net_device *netdev)
1853 1855 for (i = 0; i < enic->rq_count; i++)
1854 1856 napi_disable(&enic->napi[i]);
1855 1857
1856 - netif_carrier_off(netdev);
1858 + if (enic_is_sriov_vf_v2(enic))
1859 + enic_mbox_vf_link_state_set_running(enic, false);
1860 + else
1861 + netif_carrier_off(netdev);
1857 1862 if (vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
1858 1863 for (i = 0; i < enic->wq_count; i++)
1859 1864 napi_disable(&enic->napi[enic_cq_wq(enic, i)]);
@@ -2201,9 +2206,10 @@ static void enic_admin_chan_reopen(struct enic *enic)
2201 2206 {
2202 2207 int err;
2203 2208
2204 - /* Install the MBOX receive handler and reset the sequence number
2205 - * before opening the channel, so the handler is in place before the
2206 - * admin interrupt is unmasked and no early completion is dropped.
2209 + /* Install the MBOX receive handler and clear pending reply state before
2210 + * opening the channel, so the handler is in place before the admin
2211 + * interrupt is unmasked and no early completion is dropped. Keep the
2212 + * sequence number monotonic across channel generations.
2207 2213 */
2208 2214 enic_mbox_init(enic);
2209 2215
@@ -2215,7 +2221,7 @@ static void enic_admin_chan_reopen(struct enic *enic)
2215 2221 * registration over a dead channel.
2216 2222 */
2217 2223 if (enic_is_sriov_vf_v2(enic))
2218 - enic->vf_registered = false;
2224 + WRITE_ONCE(enic->vf_registered, false);
2219 2225
2220 2226 err = enic_admin_channel_open(enic);
2221 2227 if (err) {
@@ -2271,6 +2277,8 @@ static void enic_reset(struct work_struct *work)
2271 2277 enic_admin_channel_close(enic);
2272 2278
2273 2279 enic_stop(enic->netdev);
2280 + if (enic_is_sriov_vf_v2(enic))
2281 + enic_mbox_vf_link_state_reset(enic);
2274 2282
2275 2283 enic_dev_soft_reset(enic);
2276 2284 enic_reset_addr_lists(enic);
@@ -2315,6 +2323,8 @@ static void enic_tx_hang_reset(struct work_struct *work)
2315 2323
2316 2324 enic_dev_hang_notify(enic);
2317 2325 enic_stop(enic->netdev);
2326 + if (enic_is_sriov_vf_v2(enic))
2327 + enic_mbox_vf_link_state_reset(enic);
2318 2328
2319 2329 enic_dev_hang_reset(enic);
2320 2330 enic_reset_addr_lists(enic);
@@ -3015,6 +3025,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3015 3025 enic = netdev_priv(netdev);
3016 3026 enic->netdev = netdev;
3017 3027 enic->pdev = pdev;
3028 + spin_lock_init(&enic->vf_link_state_lock);
3018 3029
3019 3030 /* Setup PCI resources
3020 3031 */
@@ -3339,7 +3350,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3339 3350
3340 3351 err_out_admin_close:
3341 3352 if (enic_is_sriov_vf_v2(enic)) {
3342 - if (enic->vf_registered) {
3353 + if (READ_ONCE(enic->vf_registered)) {
3343 3354 int unreg_err = enic_mbox_vf_unregister(enic);
3344 3355
3345 3356 if (unreg_err)
@@ -3392,7 +3403,7 @@ static void enic_remove(struct pci_dev *pdev)
3392 3403 * touching a netdev that is being torn down.
3393 3404 */
3394 3405 if (enic_is_sriov_vf_v2(enic)) {
3395 - if (enic->vf_registered) {
3406 + if (READ_ONCE(enic->vf_registered)) {
3396 3407 int unreg_err = enic_mbox_vf_unregister(enic);
3397 3408
3398 3409 if (unreg_err)
modified drivers/net/ethernet/cisco/enic/enic_mbox.c
@@ -18,22 +18,25 @@
18 18 #define ENIC_MBOX_POLL_TIMEOUT_US 5000000
19 19 #define ENIC_MBOX_POLL_INTERVAL_US 100
20 20
21 - static void enic_mbox_fill_hdr(struct enic *enic, struct enic_mbox_hdr *hdr,
22 - u8 msg_type, u16 dst_vnic_id, u16 msg_len)
21 + static void enic_mbox_fill_hdr(struct enic_mbox_hdr *hdr, u8 msg_type,
22 + u16 dst_vnic_id, u16 msg_len, u64 msg_num)
23 23 {
24 24 memset(hdr, 0, sizeof(*hdr));
25 25 hdr->dst_vnic_id = cpu_to_le16(dst_vnic_id);
26 26 hdr->msg_type = msg_type;
27 27 hdr->msg_len = cpu_to_le16(msg_len);
28 - hdr->msg_num = cpu_to_le64(++enic->mbox_msg_num);
28 + hdr->msg_num = cpu_to_le64(msg_num);
29 29 }
30 30
31 - int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
32 - void *payload, u16 payload_len)
31 + static int enic_mbox_send_msg_id(struct enic *enic, u8 msg_type,
32 + u16 dst_vnic_id, void *payload,
33 + u16 payload_len, u64 msg_num, bool reuse_msg_num,
34 + u8 expected_reply)
33 35 {
34 36 size_t total_len = sizeof(struct enic_mbox_hdr) + payload_len;
35 37 struct vnic_wq *wq = &enic->admin_wq;
36 38 struct wq_enet_desc *desc;
39 + bool reply_expected = false;
37 40 unsigned long timeout;
38 41 dma_addr_t dma_addr;
39 42 u16 vlan_tag;
@@ -68,7 +71,21 @@ int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
68 71 goto unlock;
69 72 }
70 73
71 - enic_mbox_fill_hdr(enic, buf, msg_type, dst_vnic_id, total_len);
74 + /* Replies reuse the initiating message number. Requests and
75 + * notifications allocate a new one.
76 + */
77 + if (!reuse_msg_num)
78 + msg_num = ++enic->mbox_msg_num;
79 + if (expected_reply) {
80 + reinit_completion(&enic->mbox_comp);
81 + spin_lock_bh(&enic->mbox_state_lock);
82 + enic->mbox_expected_reply = expected_reply;
83 + enic->mbox_expected_msg_num = msg_num;
84 + spin_unlock_bh(&enic->mbox_state_lock);
85 + reply_expected = true;
86 + }
87 +
88 + enic_mbox_fill_hdr(buf, msg_type, dst_vnic_id, total_len, msg_num);
72 89 if (payload_len) {
73 90 void *dst = buf + sizeof(struct enic_mbox_hdr);
74 91
@@ -139,18 +156,66 @@ int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
139 156 "MBOX send msg_type %u dst %u vlan %u err %d\n",
140 157 msg_type, dst_vnic_id, vlan_tag, err);
141 158 unlock:
159 + if (err && reply_expected) {
160 + spin_lock_bh(&enic->mbox_state_lock);
161 + if (enic->mbox_expected_reply == expected_reply &&
162 + enic->mbox_expected_msg_num == msg_num) {
163 + enic->mbox_expected_reply = 0;
164 + enic->mbox_expected_msg_num = 0;
165 + }
166 + spin_unlock_bh(&enic->mbox_state_lock);
167 + }
142 168 mutex_unlock(&enic->mbox_lock);
143 169 return err;
144 170 }
145 171
172 + int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
173 + void *payload, u16 payload_len)
174 + {
175 + return enic_mbox_send_msg_id(enic, msg_type, dst_vnic_id, payload,
176 + payload_len, 0, false, 0);
177 + }
178 +
179 + static int enic_mbox_send_reply(struct enic *enic, u8 msg_type,
180 + u16 dst_vnic_id, void *payload, u16 payload_len,
181 + u64 msg_num)
182 + {
183 + return enic_mbox_send_msg_id(enic, msg_type, dst_vnic_id, payload,
184 + payload_len, msg_num, true, 0);
185 + }
186 +
187 + static int enic_mbox_vf_send_request(struct enic *enic, u8 request_type,
188 + u8 expected_reply, void *payload,
189 + u16 payload_len)
190 + {
191 + return enic_mbox_send_msg_id(enic, request_type, ENIC_MBOX_DST_PF,
192 + payload, payload_len, 0, false,
193 + expected_reply);
194 + }
195 +
146 196 static int enic_mbox_wait_reply(struct enic *enic, unsigned long timeout_ms)
147 197 {
148 198 unsigned long left;
199 + int err = 0;
149 200
150 201 left = wait_for_completion_timeout(&enic->mbox_comp,
151 202 msecs_to_jiffies(timeout_ms));
203 + if (left)
204 + return 0;
205 +
206 + /* Invalidate a request that the handler has not already accepted. A
207 + * delayed reply cannot match a later request because message numbers are
208 + * monotonic across channel reopen.
209 + */
210 + spin_lock_bh(&enic->mbox_state_lock);
211 + if (enic->mbox_expected_reply) {
212 + enic->mbox_expected_reply = 0;
213 + enic->mbox_expected_msg_num = 0;
214 + err = -ETIMEDOUT;
215 + }
216 + spin_unlock_bh(&enic->mbox_state_lock);
152 217
153 - return left ? 0 : -ETIMEDOUT;
218 + return err;
154 219 }
155 220
156 221 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state)
@@ -178,8 +243,8 @@ static int enic_mbox_pf_handle_capability(struct enic *enic, void *msg,
178 243 reply.reply.ret_major = cpu_to_le16(0);
179 244 reply.version = cpu_to_le32(ENIC_MBOX_CAP_VERSION_1);
180 245
181 - return enic_mbox_send_msg(enic, ENIC_MBOX_VF_CAPABILITY_REPLY, vf_id,
182 - &reply, sizeof(reply));
246 + return enic_mbox_send_reply(enic, ENIC_MBOX_VF_CAPABILITY_REPLY, vf_id,
247 + &reply, sizeof(reply), msg_num);
183 248 }
184 249
185 250 static int enic_mbox_pf_handle_register(struct enic *enic, void *msg,
@@ -208,8 +273,8 @@ static int enic_mbox_pf_handle_register(struct enic *enic, void *msg,
208 273 }
209 274
210 275 reply.reply.ret_major = cpu_to_le16(0);
211 - err = enic_mbox_send_msg(enic, ENIC_MBOX_VF_REGISTER_REPLY, vf_id,
212 - &reply, sizeof(reply));
276 + err = enic_mbox_send_reply(enic, ENIC_MBOX_VF_REGISTER_REPLY, vf_id,
277 + &reply, sizeof(reply), msg_num);
213 278 if (err)
214 279 return err;
215 280
@@ -253,8 +318,8 @@ static int enic_mbox_pf_handle_unregister(struct enic *enic, void *msg,
253 318 enic->vf_state[vf_id].registered = false;
254 319
255 320 reply.reply.ret_major = cpu_to_le16(0);
256 - err = enic_mbox_send_msg(enic, ENIC_MBOX_VF_UNREGISTER_REPLY, vf_id,
257 - &reply, sizeof(reply));
321 + err = enic_mbox_send_reply(enic, ENIC_MBOX_VF_UNREGISTER_REPLY, vf_id,
322 + &reply, sizeof(reply), msg_num);
258 323
259 324 if (net_ratelimit())
260 325 netdev_info(enic->netdev,
@@ -324,105 +389,116 @@ static void enic_mbox_pf_process_msg(struct enic *enic,
324 389 hdr->msg_type, vf_id, err);
325 390 }
326 391
327 - static void enic_mbox_vf_handle_capability_reply(struct enic *enic,
328 - void *payload)
392 + static void enic_mbox_vf_handle_reply(struct enic *enic, u8 reply_type,
393 + void *payload, u64 msg_num)
329 394 {
330 - struct enic_mbox_vf_capability_reply_msg *reply = payload;
331 -
332 - if (READ_ONCE(enic->mbox_expected_reply) != ENIC_MBOX_VF_CAPABILITY_REPLY) {
395 + struct enic_mbox_generic_reply *reply = payload;
396 + u16 ret_major = le16_to_cpu(reply->ret_major);
397 + u64 expected_msg_num;
398 + u8 expected_type;
399 +
400 + spin_lock_bh(&enic->mbox_state_lock);
401 + expected_type = enic->mbox_expected_reply;
402 + expected_msg_num = enic->mbox_expected_msg_num;
403 + if (expected_type != reply_type || expected_msg_num != msg_num) {
404 + spin_unlock_bh(&enic->mbox_state_lock);
333 405 netdev_warn(enic->netdev,
334 - "MBOX: stale capability reply (expected %u), drop\n",
335 - READ_ONCE(enic->mbox_expected_reply));
406 + "MBOX: stale reply %u/%llu (expected %u/%llu), drop\n",
407 + reply_type, (unsigned long long)msg_num,
408 + expected_type, (unsigned long long)expected_msg_num);
336 409 return;
337 410 }
338 411
339 - if (le16_to_cpu(reply->reply.ret_major) == 0)
340 - enic->pf_cap_version = le32_to_cpu(reply->version);
341 - else
342 - netdev_warn(enic->netdev,
343 - "MBOX: PF rejected capability request: %u/%u\n",
344 - le16_to_cpu(reply->reply.ret_major),
345 - le16_to_cpu(reply->reply.ret_minor));
346 - complete(&enic->mbox_comp);
347 - }
412 + if (!ret_major) {
413 + switch (reply_type) {
414 + case ENIC_MBOX_VF_CAPABILITY_REPLY: {
415 + struct enic_mbox_vf_capability_reply_msg *cap = payload;
348 416
349 - static void enic_mbox_vf_handle_register_reply(struct enic *enic,
350 - void *payload)
351 - {
352 - struct enic_mbox_vf_register_reply_msg *reply = payload;
353 -
354 - if (READ_ONCE(enic->mbox_expected_reply) != ENIC_MBOX_VF_REGISTER_REPLY) {
355 - netdev_warn(enic->netdev,
356 - "MBOX: stale register reply (expected %u), drop\n",
357 - READ_ONCE(enic->mbox_expected_reply));
358 - return;
359 - }
360 -
361 - if (le16_to_cpu(reply->reply.ret_major)) {
362 - netdev_warn(enic->netdev,
363 - "MBOX: VF register rejected by PF: %u/%u\n",
364 - le16_to_cpu(reply->reply.ret_major),
365 - le16_to_cpu(reply->reply.ret_minor));
366 - } else {
367 - enic->vf_registered = true;
417 + WRITE_ONCE(enic->pf_cap_version,
418 + le32_to_cpu(cap->version));
419 + break;
420 + }
421 + case ENIC_MBOX_VF_REGISTER_REPLY:
422 + WRITE_ONCE(enic->vf_registered, true);
423 + break;
424 + case ENIC_MBOX_VF_UNREGISTER_REPLY:
425 + WRITE_ONCE(enic->vf_registered, false);
426 + break;
427 + }
368 428 }
429 + enic->mbox_expected_reply = 0;
430 + enic->mbox_expected_msg_num = 0;
369 431 complete(&enic->mbox_comp);
370 - }
432 + spin_unlock_bh(&enic->mbox_state_lock);
371 433
372 - static void enic_mbox_vf_handle_unregister_reply(struct enic *enic,
373 - void *payload)
374 - {
375 - struct enic_mbox_vf_register_reply_msg *reply = payload;
376 -
377 - if (READ_ONCE(enic->mbox_expected_reply) != ENIC_MBOX_VF_UNREGISTER_REPLY) {
434 + if (ret_major)
378 435 netdev_warn(enic->netdev,
379 - "MBOX: stale unregister reply (expected %u), drop\n",
380 - READ_ONCE(enic->mbox_expected_reply));
381 - return;
382 - }
383 -
384 - if (le16_to_cpu(reply->reply.ret_major)) {
385 - netdev_warn(enic->netdev,
386 - "MBOX: VF unregister rejected by PF: %u/%u\n",
387 - le16_to_cpu(reply->reply.ret_major),
388 - le16_to_cpu(reply->reply.ret_minor));
389 - } else {
390 - enic->vf_registered = false;
391 - }
392 - complete(&enic->mbox_comp);
436 + "MBOX: PF rejected reply type %u: %u/%u\n",
437 + reply_type, ret_major,
438 + le16_to_cpu(reply->ret_minor));
393 439 }
394 440
395 - static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload)
441 + static void enic_mbox_vf_handle_link_state(struct enic *enic, void *payload,
442 + u64 msg_num)
396 443 {
397 444 struct enic_mbox_pf_link_state_notif_msg *notif = payload;
398 445 struct enic_mbox_pf_link_state_ack_msg ack = {};
446 + u32 link_state = le32_to_cpu(notif->link_state);
399 447 int err;
400 448
401 - switch (le32_to_cpu(notif->link_state)) {
449 + spin_lock_bh(&enic->vf_link_state_lock);
450 + switch (link_state) {
402 451 case ENIC_MBOX_LINK_STATE_ENABLE:
403 - if (!netif_carrier_ok(enic->netdev))
452 + enic->vf_link_state = ENIC_VF_LINK_STATE_UP;
453 + if (enic->vf_link_running &&
454 + !netif_carrier_ok(enic->netdev))
404 455 netif_carrier_on(enic->netdev);
405 456 netdev_dbg(enic->netdev, "MBOX: link state -> UP\n");
406 457 break;
407 458 case ENIC_MBOX_LINK_STATE_DISABLE:
408 - if (netif_carrier_ok(enic->netdev))
459 + enic->vf_link_state = ENIC_VF_LINK_STATE_DOWN;
460 + if (enic->vf_link_running &&
461 + netif_carrier_ok(enic->netdev))
409 462 netif_carrier_off(enic->netdev);
410 463 netdev_dbg(enic->netdev, "MBOX: link state -> DOWN\n");
411 464 break;
412 465 default:
413 466 netdev_warn(enic->netdev, "MBOX: unknown link state %u\n",
414 - le32_to_cpu(notif->link_state));
467 + link_state);
415 468 ack.ack.ret_major = cpu_to_le16(ENIC_MBOX_ERR_GENERIC);
416 469 break;
417 470 }
471 + spin_unlock_bh(&enic->vf_link_state_lock);
418 472
419 - err = enic_mbox_send_msg(enic, ENIC_MBOX_PF_LINK_STATE_ACK,
420 - ENIC_MBOX_DST_PF, &ack, sizeof(ack));
473 + err = enic_mbox_send_reply(enic, ENIC_MBOX_PF_LINK_STATE_ACK,
474 + ENIC_MBOX_DST_PF, &ack, sizeof(ack), msg_num);
421 475 if (err && net_ratelimit())
422 476 netdev_warn(enic->netdev,
423 477 "MBOX: failed to send link state ACK: %d\n", err);
424 478 }
425 479
480 + void enic_mbox_vf_link_state_reset(struct enic *enic)
481 + {
482 + spin_lock_bh(&enic->vf_link_state_lock);
483 + enic->vf_link_state = ENIC_VF_LINK_STATE_UNKNOWN;
484 + if (enic->vf_link_running && netif_carrier_ok(enic->netdev))
485 + netif_carrier_off(enic->netdev);
486 + spin_unlock_bh(&enic->vf_link_state_lock);
487 + }
488 +
489 + void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running)
490 + {
491 + spin_lock_bh(&enic->vf_link_state_lock);
492 + enic->vf_link_running = running;
493 + if (running && enic->vf_link_state == ENIC_VF_LINK_STATE_UP) {
494 + if (!netif_carrier_ok(enic->netdev))
495 + netif_carrier_on(enic->netdev);
496 + } else if (netif_carrier_ok(enic->netdev)) {
497 + netif_carrier_off(enic->netdev);
498 + }
499 + spin_unlock_bh(&enic->vf_link_state_lock);
500 + }
501 +
426 502 static bool enic_mbox_vf_payload_ok(struct enic *enic, u8 msg_type,
427 503 u16 payload_len, size_t min_len)
428 504 {
@@ -439,6 +515,8 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
439 515 struct enic_mbox_hdr *hdr, void *payload,
440 516 u16 payload_len)
441 517 {
518 + u64 msg_num = le64_to_cpu(hdr->msg_num);
519 +
442 520 switch (hdr->msg_type) {
443 521 case ENIC_MBOX_VF_CAPABILITY_REPLY: {
444 522 size_t exp = sizeof(struct enic_mbox_vf_capability_reply_msg);
@@ -446,7 +524,7 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
446 524 if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
447 525 payload_len, exp))
448 526 return;
449 - enic_mbox_vf_handle_capability_reply(enic, payload);
527 + enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
450 528 break;
451 529 }
452 530 case ENIC_MBOX_VF_REGISTER_REPLY: {
@@ -455,7 +533,7 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
455 533 if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
456 534 payload_len, exp))
457 535 return;
458 - enic_mbox_vf_handle_register_reply(enic, payload);
536 + enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
459 537 break;
460 538 }
461 539 case ENIC_MBOX_VF_UNREGISTER_REPLY: {
@@ -464,7 +542,7 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
464 542 if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
465 543 payload_len, exp))
466 544 return;
467 - enic_mbox_vf_handle_unregister_reply(enic, payload);
545 + enic_mbox_vf_handle_reply(enic, hdr->msg_type, payload, msg_num);
468 546 break;
469 547 }
470 548 case ENIC_MBOX_PF_LINK_STATE_NOTIF: {
@@ -473,7 +551,7 @@ static void enic_mbox_vf_process_msg(struct enic *enic,
473 551 if (!enic_mbox_vf_payload_ok(enic, hdr->msg_type,
474 552 payload_len, exp))
475 553 return;
476 - enic_mbox_vf_handle_link_state(enic, payload);
554 + enic_mbox_vf_handle_link_state(enic, payload, msg_num);
477 555 break;
478 556 }
479 557 default:
@@ -542,32 +620,31 @@ static void enic_mbox_recv_handler(struct enic *enic, void *buf,
542 620 int enic_mbox_vf_capability_check(struct enic *enic)
543 621 {
544 622 struct enic_mbox_vf_capability_msg req = {};
623 + u32 version;
545 624 int err;
546 625
547 - enic->pf_cap_version = 0;
548 - reinit_completion(&enic->mbox_comp);
549 - WRITE_ONCE(enic->mbox_expected_reply, ENIC_MBOX_VF_CAPABILITY_REPLY);
626 + WRITE_ONCE(enic->pf_cap_version, 0);
550 627 req.version = cpu_to_le32(ENIC_MBOX_CAP_VERSION_1);
551 628
552 - err = enic_mbox_send_msg(enic, ENIC_MBOX_VF_CAPABILITY_REQUEST,
553 - ENIC_MBOX_DST_PF, &req, sizeof(req));
554 - if (err) {
555 - WRITE_ONCE(enic->mbox_expected_reply, 0);
629 + err = enic_mbox_vf_send_request(enic,
630 + ENIC_MBOX_VF_CAPABILITY_REQUEST,
631 + ENIC_MBOX_VF_CAPABILITY_REPLY,
632 + &req, sizeof(req));
633 + if (err)
556 634 return err;
557 - }
558 635
559 636 err = enic_mbox_wait_reply(enic, 3000);
560 - WRITE_ONCE(enic->mbox_expected_reply, 0);
637 + version = READ_ONCE(enic->pf_cap_version);
561 638 if (err) {
562 639 netdev_warn(enic->netdev,
563 640 "MBOX: no capability reply from PF\n");
564 641 return err;
565 642 }
566 643
567 - if (enic->pf_cap_version < ENIC_MBOX_CAP_VERSION_1) {
644 + if (version < ENIC_MBOX_CAP_VERSION_1) {
568 645 netdev_warn(enic->netdev,
569 646 "MBOX: PF rejected capability request or reported unsupported version %u\n",
570 - enic->pf_cap_version);
647 + version);
571 648 return -EOPNOTSUPP;
572 649 }
573 650
@@ -576,28 +653,25 @@ int enic_mbox_vf_capability_check(struct enic *enic)
576 653
577 654 int enic_mbox_vf_register(struct enic *enic)
578 655 {
656 + bool registered;
579 657 int err;
580 658
581 - enic->vf_registered = false;
582 - reinit_completion(&enic->mbox_comp);
583 - WRITE_ONCE(enic->mbox_expected_reply, ENIC_MBOX_VF_REGISTER_REPLY);
659 + WRITE_ONCE(enic->vf_registered, false);
584 660
585 - err = enic_mbox_send_msg(enic, ENIC_MBOX_VF_REGISTER_REQUEST,
586 - ENIC_MBOX_DST_PF, NULL, 0);
587 - if (err) {
588 - WRITE_ONCE(enic->mbox_expected_reply, 0);
661 + err = enic_mbox_vf_send_request(enic, ENIC_MBOX_VF_REGISTER_REQUEST,
662 + ENIC_MBOX_VF_REGISTER_REPLY, NULL, 0);
663 + if (err)
589 664 return err;
590 - }
591 665
592 666 err = enic_mbox_wait_reply(enic, 3000);
593 - WRITE_ONCE(enic->mbox_expected_reply, 0);
667 + registered = READ_ONCE(enic->vf_registered);
594 668 if (err) {
595 669 netdev_warn(enic->netdev,
596 670 "MBOX: VF registration with PF timed out\n");
597 671 return err;
598 672 }
599 673
600 - if (!enic->vf_registered)
674 + if (!registered)
601 675 return -ENODEV;
602 676
603 677 return 0;
@@ -605,43 +679,48 @@ int enic_mbox_vf_register(struct enic *enic)
605 679
606 680 int enic_mbox_vf_unregister(struct enic *enic)
607 681 {
682 + bool registered;
608 683 int err;
609 684
610 - if (!enic->vf_registered)
685 + if (!READ_ONCE(enic->vf_registered))
611 686 return 0;
612 687
613 - reinit_completion(&enic->mbox_comp);
614 - WRITE_ONCE(enic->mbox_expected_reply, ENIC_MBOX_VF_UNREGISTER_REPLY);
615 -
616 - err = enic_mbox_send_msg(enic, ENIC_MBOX_VF_UNREGISTER_REQUEST,
617 - ENIC_MBOX_DST_PF, NULL, 0);
618 - if (err) {
619 - WRITE_ONCE(enic->mbox_expected_reply, 0);
688 + err = enic_mbox_vf_send_request(enic,
689 + ENIC_MBOX_VF_UNREGISTER_REQUEST,
690 + ENIC_MBOX_VF_UNREGISTER_REPLY,
691 + NULL, 0);
692 + if (err)
620 693 return err;
621 - }
622 694
623 695 err = enic_mbox_wait_reply(enic, 3000);
624 - WRITE_ONCE(enic->mbox_expected_reply, 0);
696 + registered = READ_ONCE(enic->vf_registered);
625 697 if (err)
626 698 return err;
627 - if (enic->vf_registered)
699 + if (registered)
628 700 return -EACCES;
629 701 return 0;
630 702 }
631 703
632 704 void enic_mbox_init(struct enic *enic)
633 705 {
634 - /* mbox_lock and mbox_comp must be initialized exactly once per
706 + bool reinit = enic->mbox_initialized;
707 +
708 + /* MBOX locks and mbox_comp must be initialized exactly once per
635 709 * device lifetime; the PF sriov_configure path can re-enter this
636 710 * on each enable cycle where these primitives are already set up.
637 711 */
638 - if (!enic->mbox_initialized) {
712 + if (!reinit) {
639 713 mutex_init(&enic->mbox_lock);
640 714 init_completion(&enic->mbox_comp);
715 + spin_lock_init(&enic->mbox_state_lock);
716 + enic->mbox_msg_num = 0;
641 717 enic->mbox_initialized = true;
642 718 } else {
643 719 reinit_completion(&enic->mbox_comp);
644 720 }
645 - enic->mbox_msg_num = 0;
721 + spin_lock_bh(&enic->mbox_state_lock);
722 + enic->mbox_expected_reply = 0;
723 + enic->mbox_expected_msg_num = 0;
724 + spin_unlock_bh(&enic->mbox_state_lock);
646 725 enic->admin_rq_handler = enic_mbox_recv_handler;
647 726 }
modified drivers/net/ethernet/cisco/enic/enic_mbox.h
@@ -88,6 +88,8 @@ void enic_mbox_init(struct enic *enic);
88 88 int enic_mbox_send_msg(struct enic *enic, u8 msg_type, u16 dst_vnic_id,
89 89 void *payload, u16 payload_len);
90 90 int enic_mbox_send_link_state(struct enic *enic, u16 vf_id, u32 link_state);
91 + void enic_mbox_vf_link_state_reset(struct enic *enic);
92 + void enic_mbox_vf_link_state_set_running(struct enic *enic, bool running);
91 93 int enic_mbox_vf_capability_check(struct enic *enic);
92 94 int enic_mbox_vf_register(struct enic *enic);
93 95 int enic_mbox_vf_unregister(struct enic *enic);
modified drivers/net/ethernet/cortina/gemini.c
@@ -124,6 +124,7 @@ struct gemini_ethernet_port {
124 124 unsigned int rx_coalesce_nsecs;
125 125 struct sk_buff *rx_skb;
126 126 unsigned int rx_frag_nr;
127 + bool rx_dropping;
127 128
128 129 unsigned int freeq_refill;
129 130 struct gmac_txq txq[TX_QUEUE_NUM];
@@ -1439,7 +1440,8 @@ update_exit:
1439 1440 return skb;
1440 1441 }
1441 1442
1442 - static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1443 + static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,
1444 + unsigned int *freeq_consumed)
1443 1445 {
1444 1446 struct gemini_ethernet_port *port = netdev_priv(netdev);
1445 1447 unsigned short m = (1 << port->rxq_order) - 1;
@@ -1447,9 +1449,12 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1447 1449 void __iomem *ptr_reg = port->rxq_rwptr;
1448 1450 unsigned int frag_nr = port->rx_frag_nr;
1449 1451 struct sk_buff *skb = port->rx_skb;
1452 + unsigned int consumed = 0;
1450 1453 unsigned int frame_len, frag_len;
1451 1454 struct gmac_rxdesc *rx = NULL;
1452 1455 struct gmac_queue_page *gpage;
1456 + unsigned int received = 0;
1457 + bool dropping = port->rx_dropping;
1453 1458 union gmac_rxdesc_0 word0;
1454 1459 union gmac_rxdesc_1 word1;
1455 1460 union gmac_rxdesc_3 word3;
@@ -1471,6 +1476,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1471 1476 w = rw.bits.wptr;
1472 1477
1473 1478 while (budget && w != r) {
1479 + page = NULL;
1474 1480 rx = port->rxq_ring + r;
1475 1481 word0 = rx->word0;
1476 1482 word1 = rx->word1;
@@ -1479,11 +1485,22 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1479 1485
1480 1486 r++;
1481 1487 r &= m;
1488 + consumed++;
1482 1489
1483 1490 frag_len = word0.bits.buffer_size;
1484 1491 frame_len = word1.bits.byte_count;
1485 1492 page_offs = mapping & ~PAGE_MASK;
1486 1493
1494 + if (word3.bits32 & SOF_BIT) {
1495 + if (skb) {
1496 + napi_free_frags(&port->napi);
1497 + port->stats.rx_dropped++;
1498 + skb = NULL;
1499 + frag_nr = 0;
1500 + }
1501 + dropping = false;
1502 + }
1503 +
1487 1504 if (!mapping) {
1488 1505 netdev_err(netdev,
1489 1506 "rxq[%u]: HW BUG: zero DMA desc\n", r);
@@ -1494,24 +1511,11 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1494 1511 gpage = gmac_get_queue_page(geth, port, mapping + PAGE_SIZE);
1495 1512 if (!gpage) {
1496 1513 dev_err(geth->dev, "could not find mapping\n");
1497 - port->stats.rx_dropped++;
1498 - if (skb) {
1499 - napi_free_frags(&port->napi);
1500 - skb = NULL;
1501 - frag_nr = 0;
1502 - }
1503 - continue;
1514 + goto err_drop;
1504 1515 }
1505 1516 page = gpage->page;
1506 1517
1507 1518 if (word3.bits32 & SOF_BIT) {
1508 - if (skb) {
1509 - napi_free_frags(&port->napi);
1510 - port->stats.rx_dropped++;
1511 - skb = NULL;
1512 - frag_nr = 0;
1513 - }
1514 -
1515 1519 skb = gmac_skb_if_good_frame(port, word0, frame_len);
1516 1520 if (!skb)
1517 1521 goto err_drop;
@@ -1521,8 +1525,7 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1521 1525 frag_nr = 0;
1522 1526
1523 1527 } else if (!skb) {
1524 - put_page(page);
1525 - continue;
1528 + goto err_drop;
1526 1529 }
1527 1530
1528 1531 if (word3.bits32 & EOF_BIT)
@@ -1545,9 +1548,8 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget)
1545 1548 napi_gro_frags(&port->napi);
1546 1549 skb = NULL;
1547 1550 frag_nr = 0;
1548 - --budget;
1549 1551 }
1550 - continue;
1552 + goto next_desc;
1551 1553
1552 1554 err_drop:
1553 1555 if (skb) {
@@ -1556,16 +1558,29 @@ err_drop:
1556 1558 frag_nr = 0;
1557 1559 }
1558 1560
1559 - if (mapping)
1561 + if (page)
1560 1562 put_page(page);
1561 1563
1562 - port->stats.rx_dropped++;
1564 + if (!dropping) {
1565 + port->stats.rx_dropped++;
1566 + dropping = true;
1567 + }
1568 +
1569 + next_desc:
1570 + /* Final or single-descriptor fragment, advance things */
1571 + if (word3.bits32 & EOF_BIT) {
1572 + budget--;
1573 + received++;
1574 + dropping = false;
1575 + }
1563 1576 }
1564 1577
1565 1578 port->rx_skb = skb;
1566 1579 port->rx_frag_nr = frag_nr;
1580 + port->rx_dropping = dropping;
1581 + *freeq_consumed = consumed;
1567 1582 writew(r, ptr_reg);
1568 - return budget;
1583 + return received;
1569 1584 }
1570 1585
1571 1586 static int gmac_napi_poll(struct napi_struct *napi, int budget)
@@ -1573,26 +1588,27 @@ static int gmac_napi_poll(struct napi_struct *napi, int budget)
1573 1588 struct gemini_ethernet_port *port = netdev_priv(napi->dev);
1574 1589 struct gemini_ethernet *geth = port->geth;
1575 1590 unsigned int freeq_threshold;
1591 + unsigned int freeq_consumed;
1576 1592 unsigned int received;
1577 1593
1578 1594 freeq_threshold = 1 << (geth->freeq_order - 1);
1579 1595 u64_stats_update_begin(&port->rx_stats_syncp);
1580 1596
1581 - received = gmac_rx(napi->dev, budget);
1582 - if (received < budget) {
1583 - napi_gro_flush(napi, false);
1584 - napi_complete_done(napi, received);
1585 - gmac_enable_rx_irq(napi->dev, 1);
1597 + received = gmac_rx(napi->dev, budget, &freeq_consumed);
1598 + if (received < budget)
1586 1599 ++port->rx_napi_exits;
1587 - }
1588 1600
1589 - port->freeq_refill += (budget - received);
1601 + u64_stats_update_end(&port->rx_stats_syncp);
1602 +
1603 + port->freeq_refill += freeq_consumed;
1590 1604 if (port->freeq_refill > freeq_threshold) {
1591 1605 port->freeq_refill -= freeq_threshold;
1592 1606 geth_fill_freeq(geth, true);
1593 1607 }
1594 1608
1595 - u64_stats_update_end(&port->rx_stats_syncp);
1609 + if (received < budget && napi_complete_done(napi, received))
1610 + gmac_enable_rx_irq(napi->dev, 1);
1611 +
1596 1612 return received;
1597 1613 }
1598 1614
@@ -1893,6 +1909,7 @@ static int gmac_stop(struct net_device *netdev)
1893 1909 napi_disable(&port->napi);
1894 1910 port->rx_skb = NULL;
1895 1911 port->rx_frag_nr = 0;
1912 + port->rx_dropping = false;
1896 1913
1897 1914 gmac_enable_irq(netdev, 0);
1898 1915 gmac_cleanup_rxq(netdev);
modified drivers/net/ethernet/huawei/hinic/hinic_hw_mbox.c
@@ -128,6 +128,7 @@ enum hinic_mbox_tx_status {
128 128
129 129 #define SEQ_ID_START_VAL 0
130 130 #define SEQ_ID_MAX_VAL 42
131 + #define MBOX_LAST_SEG_MAX_LEN (MBOX_MAX_BUF_SZ - SEQ_ID_MAX_VAL * MBOX_SEG_LEN)
131 132
132 133 #define NO_DMA_ATTRIBUTE_VAL 0
133 134
@@ -372,7 +373,8 @@ recv_pf_from_vf_mbox_handler(struct hinic_mbox_func_to_func *func_to_func,
372 373 static bool check_mbox_seq_id_and_seg_len(struct hinic_recv_mbox *recv_mbox,
373 374 u8 seq_id, u8 seg_len)
374 375 {
375 - if (seq_id > SEQ_ID_MAX_VAL || seg_len > MBOX_SEG_LEN)
376 + if (seq_id > SEQ_ID_MAX_VAL || seg_len > MBOX_SEG_LEN ||
377 + (seq_id == SEQ_ID_MAX_VAL && seg_len > MBOX_LAST_SEG_MAX_LEN))
376 378 return false;
377 379
378 380 if (seq_id == 0) {
modified drivers/net/ethernet/intel/ice/ice_common.c
@@ -1051,14 +1051,13 @@ int ice_init_hw(struct ice_hw *hw)
1051 1051
1052 1052 hw->evb_veb = true;
1053 1053
1054 - /* init xarray for identifying scheduling nodes uniquely */
1055 - xa_init_flags(&hw->port_info->sched_node_ids, XA_FLAGS_ALLOC);
1054 + xa_init_flags(&hw->sched_node_ids, XA_FLAGS_ALLOC);
1056 1055
1057 1056 /* Query the allocated resources for Tx scheduler */
1058 1057 status = ice_sched_query_res_alloc(hw);
1059 1058 if (status) {
1060 1059 ice_debug(hw, ICE_DBG_SCHED, "Failed to get scheduler allocated resources\n");
1061 - goto err_unroll_alloc;
1060 + goto err_unroll_xarray;
1062 1061 }
1063 1062 ice_sched_get_psm_clk_freq(hw);
1064 1063
@@ -1146,6 +1145,8 @@ err_unroll_fltr_mgmt_struct:
1146 1145 ice_cleanup_fltr_mgmt_struct(hw);
1147 1146 err_unroll_sched:
1148 1147 ice_sched_cleanup_all(hw);
1148 + err_unroll_xarray:
1149 + xa_destroy(&hw->sched_node_ids);
1149 1150 err_unroll_alloc:
1150 1151 devm_kfree(ice_hw_to_dev(hw), hw->port_info);
1151 1152 err_unroll_cqinit:
@@ -1186,6 +1187,8 @@ void ice_deinit_hw(struct ice_hw *hw)
1186 1187
1187 1188 /* Clear VSI contexts if not already cleared */
1188 1189 ice_clear_all_vsi_ctx(hw);
1190 +
1191 + xa_destroy(&hw->sched_node_ids);
1189 1192 }
1190 1193
1191 1194 /**
modified drivers/net/ethernet/intel/ice/ice_sched.c
@@ -371,7 +371,7 @@ void ice_free_sched_node(struct ice_port_info *pi, struct ice_sched_node *node)
371 371
372 372 devm_kfree(ice_hw_to_dev(hw), node->children);
373 373 kfree(node->name);
374 - xa_erase(&pi->sched_node_ids, node->id);
374 + xa_erase(&hw->sched_node_ids, node->id);
375 375 devm_kfree(ice_hw_to_dev(hw), node);
376 376 }
377 377
@@ -977,7 +977,7 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node,
977 977 if (!new_node->name)
978 978 return -ENOMEM;
979 979
980 - status = xa_alloc(&pi->sched_node_ids, &new_node->id, NULL, XA_LIMIT(0, UINT_MAX),
980 + status = xa_alloc(&hw->sched_node_ids, &new_node->id, NULL, XA_LIMIT(0, UINT_MAX),
981 981 GFP_KERNEL);
982 982 if (status) {
983 983 ice_debug(hw, ICE_DBG_SCHED, "xa_alloc failed for sched node status =%d\n",
modified drivers/net/ethernet/intel/ice/ice_trace.h
@@ -63,23 +63,33 @@
63 63 DECLARE_EVENT_CLASS(ice_rx_dim_template,
64 64 TP_PROTO(struct ice_q_vector *q_vector, struct dim *dim),
65 65 TP_ARGS(q_vector, dim),
66 - TP_STRUCT__entry(__field(struct ice_q_vector *, q_vector)
67 - __field(struct dim *, dim)
66 + TP_STRUCT__entry(__field(u16, q_index)
67 + __field(u8, state)
68 + __field(u8, profile_ix)
69 + __field(u8, tune_state)
70 + __field(u8, steps_right)
71 + __field(u8, steps_left)
72 + __field(u8, tired)
68 73 __string(devname, q_vector->rx.rx_ring->netdev->name)),
69 74
70 - TP_fast_assign(__entry->q_vector = q_vector;
71 - __entry->dim = dim;
75 + TP_fast_assign(__entry->q_index = q_vector->rx.rx_ring->q_index;
76 + __entry->state = dim->state;
77 + __entry->profile_ix = dim->profile_ix;
78 + __entry->tune_state = dim->tune_state;
79 + __entry->steps_right = dim->steps_right;
80 + __entry->steps_left = dim->steps_left;
81 + __entry->tired = dim->tired;
72 82 __assign_str(devname);),
73 83
74 84 TP_printk("netdev: %s Rx-Q: %d dim-state: %d dim-profile: %d dim-tune: %d dim-st-right: %d dim-st-left: %d dim-tired: %d",
75 85 __get_str(devname),
76 - __entry->q_vector->rx.rx_ring->q_index,
77 - __entry->dim->state,
78 - __entry->dim->profile_ix,
79 - __entry->dim->tune_state,
80 - __entry->dim->steps_right,
81 - __entry->dim->steps_left,
82 - __entry->dim->tired)
86 + __entry->q_index,
87 + __entry->state,
88 + __entry->profile_ix,
89 + __entry->tune_state,
90 + __entry->steps_right,
91 + __entry->steps_left,
92 + __entry->tired)
83 93 );
84 94
85 95 DEFINE_EVENT(ice_rx_dim_template, ice_rx_dim_work,
@@ -90,23 +100,33 @@ DEFINE_EVENT(ice_rx_dim_template, ice_rx_dim_work,
90 100 DECLARE_EVENT_CLASS(ice_tx_dim_template,
91 101 TP_PROTO(struct ice_q_vector *q_vector, struct dim *dim),
92 102 TP_ARGS(q_vector, dim),
93 - TP_STRUCT__entry(__field(struct ice_q_vector *, q_vector)
94 - __field(struct dim *, dim)
103 + TP_STRUCT__entry(__field(u16, q_index)
104 + __field(u8, state)
105 + __field(u8, profile_ix)
106 + __field(u8, tune_state)
107 + __field(u8, steps_right)
108 + __field(u8, steps_left)
109 + __field(u8, tired)
95 110 __string(devname, q_vector->tx.tx_ring->netdev->name)),
96 111
97 - TP_fast_assign(__entry->q_vector = q_vector;
98 - __entry->dim = dim;
112 + TP_fast_assign(__entry->q_index = q_vector->tx.tx_ring->q_index;
113 + __entry->state = dim->state;
114 + __entry->profile_ix = dim->profile_ix;
115 + __entry->tune_state = dim->tune_state;
116 + __entry->steps_right = dim->steps_right;
117 + __entry->steps_left = dim->steps_left;
118 + __entry->tired = dim->tired;
99 119 __assign_str(devname);),
100 120
101 121 TP_printk("netdev: %s Tx-Q: %d dim-state: %d dim-profile: %d dim-tune: %d dim-st-right: %d dim-st-left: %d dim-tired: %d",
102 122 __get_str(devname),
103 - __entry->q_vector->tx.tx_ring->q_index,
104 - __entry->dim->state,
105 - __entry->dim->profile_ix,
106 - __entry->dim->tune_state,
107 - __entry->dim->steps_right,
108 - __entry->dim->steps_left,
109 - __entry->dim->tired)
123 + __entry->q_index,
124 + __entry->state,
125 + __entry->profile_ix,
126 + __entry->tune_state,
127 + __entry->steps_right,
128 + __entry->steps_left,
129 + __entry->tired)
110 130 );
111 131
112 132 DEFINE_EVENT(ice_tx_dim_template, ice_tx_dim_work,
modified drivers/net/ethernet/intel/ice/ice_type.h
@@ -765,7 +765,6 @@ struct ice_port_info {
765 765 /* List contain profile ID(s) and other params per layer */
766 766 struct list_head rl_prof_list[ICE_AQC_TOPO_MAX_LEVEL_NUM];
767 767 struct ice_qos_cfg qos_cfg;
768 - struct xarray sched_node_ids;
769 768 u8 is_vf:1;
770 769 u8 is_custom_tx_enabled:1;
771 770 };
@@ -930,6 +929,7 @@ struct ice_hw {
930 929 u8 sw_entry_point_layer;
931 930 u16 max_children[ICE_AQC_TOPO_MAX_LEVEL_NUM];
932 931 struct list_head agg_list; /* lists all aggregator */
932 + struct xarray sched_node_ids;
933 933
934 934 struct ice_vsi_ctx *vsi_ctx[ICE_MAX_VSI];
935 935 u8 evb_veb; /* true for VEB, false for VEPA */
modified drivers/net/ethernet/intel/idpf/idpf_main.c
@@ -106,6 +106,11 @@ static int idpf_dev_init(struct idpf_adapter *adapter,
106 106 */
107 107 static void idpf_decfg_device(struct idpf_adapter *adapter)
108 108 {
109 + struct pci_dev *pdev = adapter->pdev;
110 +
111 + if (pcie_ptm_enabled(pdev))
112 + pci_disable_ptm(pdev);
113 +
109 114 libie_pci_unmap_all_mmio_regions(&adapter->ctlq_ctx.mmio_info);
110 115 }
111 116
modified drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -3299,6 +3299,7 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
3299 3299 struct libeth_rx_pt decoded)
3300 3300 {
3301 3301 u16 rsc_segments, rsc_seg_len;
3302 + u16 l3_start = 0;
3302 3303 bool ipv4, ipv6;
3303 3304 int len;
3304 3305
@@ -3321,7 +3322,10 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
3321 3322 NAPI_GRO_CB(skb)->count = rsc_segments;
3322 3323 skb_shinfo(skb)->gso_size = rsc_seg_len;
3323 3324
3324 - skb_reset_network_header(skb);
3325 + if (unlikely(eth_type_vlan(skb->protocol)))
3326 + l3_start = VLAN_HLEN;
3327 +
3328 + skb_set_network_header(skb, l3_start);
3325 3329
3326 3330 if (ipv4) {
3327 3331 struct iphdr *ipv4h = ip_hdr(skb);
@@ -3329,7 +3333,7 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
3329 3333 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
3330 3334
3331 3335 /* Reset and set transport header offset in skb */
3332 - skb_set_transport_header(skb, sizeof(struct iphdr));
3336 + skb_set_transport_header(skb, l3_start + sizeof(struct iphdr));
3333 3337 len = skb->len - skb_transport_offset(skb);
3334 3338
3335 3339 /* Compute the TCP pseudo header checksum*/
@@ -3339,7 +3343,7 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,
3339 3343 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
3340 3344
3341 3345 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
3342 - skb_set_transport_header(skb, sizeof(struct ipv6hdr));
3346 + skb_set_transport_header(skb, l3_start + sizeof(struct ipv6hdr));
3343 3347 len = skb->len - skb_transport_offset(skb);
3344 3348 tcp_hdr(skb)->check =
3345 3349 ~tcp_v6_check(len, &ipv6h->saddr, &ipv6h->daddr, 0);
@@ -4145,6 +4149,26 @@ static void idpf_vport_intr_ena_irq_all(struct idpf_vport *vport,
4145 4149 writel(rsrc->noirq_dyn_ctl_ena, rsrc->noirq_dyn_ctl);
4146 4150 }
4147 4151
4152 + /**
4153 + * idpf_vport_intr_dis_dim_all - Disable DIM work for all q_vectors
4154 + * @rsrc: pointer to queue and vector resources
4155 + *
4156 + * The DIM works are embedded in the q_vector array that
4157 + * idpf_vport_intr_rel() frees, and the poll arms them after
4158 + * napi_complete_done() has already cleared NAPI_STATE_SCHED. Disable
4159 + * rather than just cancel, so that a poll tail still running past
4160 + * napi_disable() cannot queue them again behind the drain.
4161 + */
4162 + static void idpf_vport_intr_dis_dim_all(struct idpf_q_vec_rsrc *rsrc)
4163 + {
4164 + for (u16 v_idx = 0; v_idx < rsrc->num_q_vectors; v_idx++) {
4165 + struct idpf_q_vector *q_vector = &rsrc->q_vectors[v_idx];
4166 +
4167 + disable_work_sync(&q_vector->tx_dim.work);
4168 + disable_work_sync(&q_vector->rx_dim.work);
4169 + }
4170 + }
4171 +
4148 4172 /**
4149 4173 * idpf_vport_intr_deinit - Release all vector associations for the vport
4150 4174 * @vport: main vport structure
@@ -4155,6 +4179,7 @@ void idpf_vport_intr_deinit(struct idpf_vport *vport,
4155 4179 {
4156 4180 idpf_vport_intr_dis_irq_all(rsrc);
4157 4181 idpf_vport_intr_napi_dis_all(rsrc);
4182 + idpf_vport_intr_dis_dim_all(rsrc);
4158 4183 idpf_vport_intr_napi_del_all(rsrc);
4159 4184 idpf_vport_intr_rel_irq(vport, rsrc);
4160 4185 }
@@ -4235,7 +4260,6 @@ static void idpf_vport_intr_napi_ena_all(struct idpf_q_vec_rsrc *rsrc)
4235 4260 for (u16 q_idx = 0; q_idx < rsrc->num_q_vectors; q_idx++) {
4236 4261 struct idpf_q_vector *q_vector = &rsrc->q_vectors[q_idx];
4237 4262
4238 - idpf_init_dim(q_vector);
4239 4263 napi_enable(&q_vector->napi);
4240 4264 }
4241 4265 }
@@ -4578,6 +4602,8 @@ int idpf_vport_intr_alloc(struct idpf_vport *vport,
4578 4602 q_coal = &user_config->q_coalesce[v_idx];
4579 4603 q_vector->vport = vport;
4580 4604
4605 + idpf_init_dim(q_vector);
4606 +
4581 4607 q_vector->tx_itr_value = q_coal->tx_coalesce_usecs;
4582 4608 q_vector->tx_intr_mode = q_coal->tx_intr_mode;
4583 4609 q_vector->tx_itr_idx = VIRTCHNL2_ITR_IDX_1;
modified drivers/net/ethernet/marvell/octeontx2/af/mcs.c
@@ -1417,6 +1417,16 @@ static int mcs_x2p_calibration(struct mcs *mcs)
1417 1417 int i, err = 0;
1418 1418 u64 val;
1419 1419
1420 + /* Clear any stale calibration state left by firmware/bootloader.
1421 + * Some firmware versions may leave MCSX_MIL_GLOBAL bit 5 set,
1422 + * preventing the hardware from detecting the rising edge needed to
1423 + * trigger X2P calibration.
1424 + */
1425 + val = mcs_reg_read(mcs, MCSX_MIL_GLOBAL);
1426 + val &= ~BIT_ULL(5);
1427 + mcs_reg_write(mcs, MCSX_MIL_GLOBAL, val);
1428 + usleep_range(100, 200);
1429 +
1420 1430 /* set X2P calibration */
1421 1431 val = mcs_reg_read(mcs, MCSX_MIL_GLOBAL);
1422 1432 val |= BIT_ULL(5);
modified drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -829,19 +829,25 @@ static int rvu_dbg_rvu_pf_cgx_map_display(struct seq_file *filp, void *unused)
829 829 int pf, domain, blkid;
830 830 u8 cgx_id, lmac_id;
831 831 u16 pcifunc;
832 + u8 start;
832 833
833 - domain = 2;
834 + domain = pci_domain_nr(rvu->pdev->bus);
834 835 mac_ops = get_mac_ops(rvu_first_cgx_pdata(rvu));
835 836 /* There can be no CGX devices at all */
836 837 if (!mac_ops)
837 838 return 0;
838 839 seq_printf(filp, "PCI dev\t\tRVU PF Func\tNIX block\t%s\tLMAC\tCHAN\n",
839 840 mac_ops->name);
841 +
842 + /* All the PF devices are on contiguous PCI bus numbers, but the PF0(AF)
843 + * may not start from 1 always. Hence get domain and bus from PCI device.
844 + */
845 + start = rvu->pdev->bus->number;
840 846 for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
841 847 if (!is_pf_cgxmapped(rvu, pf))
842 848 continue;
843 849
844 - pdev = pci_get_domain_bus_and_slot(domain, pf + 1, 0);
850 + pdev = pci_get_domain_bus_and_slot(domain, pf + start, 0);
845 851 if (!pdev)
846 852 continue;
847 853
modified drivers/net/ethernet/marvell/octeontx2/nic/qos.c
@@ -235,13 +235,63 @@ static int otx2_qos_txschq_set_parent_topology(struct otx2_nic *pfvf,
235 235 return rc;
236 236 }
237 237
238 + static int otx2_qos_reset_schq_topology(struct otx2_nic *pfvf, u16 lvl,
239 + u16 schq)
240 + {
241 + struct mbox *mbox = &pfvf->mbox;
242 + struct nix_txschq_config *cfg;
243 + int rc;
244 +
245 + if (lvl < NIX_TXSCH_LVL_TL4 || lvl >= NIX_TXSCH_LVL_TL1)
246 + return 0;
247 +
248 + mutex_lock(&mbox->lock);
249 +
250 + cfg = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
251 + if (!cfg) {
252 + mutex_unlock(&mbox->lock);
253 + return -ENOMEM;
254 + }
255 +
256 + cfg->lvl = lvl;
257 + cfg->num_regs = 1;
258 +
259 + if (lvl == NIX_TXSCH_LVL_TL4)
260 + cfg->reg[0] = NIX_AF_TL4X_TOPOLOGY(schq);
261 + else if (lvl == NIX_TXSCH_LVL_TL3)
262 + cfg->reg[0] = NIX_AF_TL3X_TOPOLOGY(schq);
263 + else if (lvl == NIX_TXSCH_LVL_TL2)
264 + cfg->reg[0] = NIX_AF_TL2X_TOPOLOGY(schq);
265 +
266 + cfg->regval[0] = 0;
267 +
268 + rc = otx2_sync_mbox_msg(mbox);
269 +
270 + mutex_unlock(&mbox->lock);
271 +
272 + return rc;
273 + }
274 +
275 + static void otx2_qos_free_hw_schq(struct otx2_nic *pfvf, u16 lvl, u16 schq)
276 + {
277 + int err;
278 +
279 + err = otx2_qos_reset_schq_topology(pfvf, lvl, schq);
280 + if (err)
281 + netdev_warn(pfvf->netdev,
282 + "QoS: failed to reset topology for schq %u at level %u: %d\n",
283 + schq, lvl, err);
284 +
285 + otx2_txschq_free_one(pfvf, lvl, schq);
286 + }
287 +
238 288 static void otx2_qos_free_hw_node_schq(struct otx2_nic *pfvf,
239 289 struct otx2_qos_node *parent)
240 290 {
241 291 struct otx2_qos_node *node;
242 292
243 293 list_for_each_entry_reverse(node, &parent->child_schq_list, list)
244 - otx2_txschq_free_one(pfvf, node->level, node->schq);
294 + otx2_qos_free_hw_schq(pfvf, node->level, node->schq);
245 295 }
246 296
247 297 static void otx2_qos_free_hw_node(struct otx2_nic *pfvf,
@@ -252,7 +302,7 @@ static void otx2_qos_free_hw_node(struct otx2_nic *pfvf,
252 302 list_for_each_entry_safe(node, tmp, &parent->child_list, list) {
253 303 otx2_qos_free_hw_node(pfvf, node);
254 304 otx2_qos_free_hw_node_schq(pfvf, node);
255 - otx2_txschq_free_one(pfvf, node->level, node->schq);
305 + otx2_qos_free_hw_schq(pfvf, node->level, node->schq);
256 306 }
257 307 }
258 308
@@ -266,7 +316,7 @@ static void otx2_qos_free_hw_cfg(struct otx2_nic *pfvf,
266 316 otx2_qos_free_hw_node_schq(pfvf, node);
267 317
268 318 /* free node hw mappings */
269 - otx2_txschq_free_one(pfvf, node->level, node->schq);
319 + otx2_qos_free_hw_schq(pfvf, node->level, node->schq);
270 320
271 321 mutex_unlock(&pfvf->qos.qos_lock);
272 322 }
@@ -913,7 +963,7 @@ static void otx2_qos_free_cfg(struct otx2_nic *pfvf, struct otx2_qos_cfg *cfg)
913 963 for (lvl = 0; lvl < NIX_TXSCH_LVL_CNT; lvl++) {
914 964 for (idx = 0; idx < cfg->schq[lvl]; idx++) {
915 965 schq = cfg->schq_list[lvl][idx];
916 - otx2_txschq_free_one(pfvf, lvl, schq);
966 + otx2_qos_free_hw_schq(pfvf, lvl, schq);
917 967 }
918 968 }
919 969
@@ -921,7 +971,7 @@ static void otx2_qos_free_cfg(struct otx2_nic *pfvf, struct otx2_qos_cfg *cfg)
921 971 for (idx = 0; idx < cfg->schq_contig[lvl]; idx++) {
922 972 if (cfg->schq_index_used[lvl][idx]) {
923 973 schq = cfg->schq_contig_list[lvl][idx];
924 - otx2_txschq_free_one(pfvf, lvl, schq);
974 + otx2_qos_free_hw_schq(pfvf, lvl, schq);
925 975 }
926 976 }
927 977 }
modified drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4828,7 +4828,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
4828 4828 phy_interface_t phy_mode;
4829 4829 struct phylink *phylink;
4830 4830 struct mtk_mac *mac;
4831 - int id, err;
4831 + int id, err, i;
4832 4832 int txqs = 1;
4833 4833 u32 val;
4834 4834
@@ -4907,8 +4907,8 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
4907 4907 mac->phylink_config.type = PHYLINK_NETDEV;
4908 4908 mac->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
4909 4909 MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD;
4910 - mac->phylink_config.lpi_capabilities = MAC_100FD | MAC_1000FD |
4911 - MAC_2500FD;
4910 + /* LPI above 1 Gbps is not supported */
4911 + mac->phylink_config.lpi_capabilities = MAC_100FD | MAC_1000FD;
4912 4912 mac->phylink_config.lpi_timer_default = 1000;
4913 4913
4914 4914 /* MT7623 gmac0 is now missing its speed-specific PLL configuration
@@ -4966,6 +4966,18 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
4966 4966 __set_bit(PHY_INTERFACE_MODE_INTERNAL,
4967 4967 mac->phylink_config.supported_interfaces);
4968 4968
4969 + /* LPI wake-up timing is only verified on MTK_GMAC_EEE SoCs */
4970 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_GMAC_EEE)) {
4971 + phy_interface_copy(mac->phylink_config.lpi_interfaces,
4972 + mac->phylink_config.supported_interfaces);
4973 + __clear_bit(PHY_INTERFACE_MODE_2500BASEX,
4974 + mac->phylink_config.lpi_interfaces);
4975 + for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++)
4976 + if (mtk_interface_mode_is_xgmii(eth, i))
4977 + __clear_bit(i,
4978 + mac->phylink_config.lpi_interfaces);
4979 + }
4980 +
4969 4981 phylink = phylink_create(&mac->phylink_config,
4970 4982 of_fwnode_handle(mac->of_node),
4971 4983 phy_mode, mac_ops);
modified drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -994,6 +994,7 @@ enum mkt_eth_capabilities {
994 994 MTK_U3_COPHY_V2_BIT,
995 995 MTK_SRAM_BIT,
996 996 MTK_36BIT_DMA_BIT,
997 + MTK_GMAC_EEE_BIT,
997 998
998 999 /* MUX BITS*/
999 1000 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
@@ -1034,6 +1035,7 @@ enum mkt_eth_capabilities {
1034 1035 #define MTK_U3_COPHY_V2 BIT_ULL(MTK_U3_COPHY_V2_BIT)
1035 1036 #define MTK_SRAM BIT_ULL(MTK_SRAM_BIT)
1036 1037 #define MTK_36BIT_DMA BIT_ULL(MTK_36BIT_DMA_BIT)
1038 + #define MTK_GMAC_EEE BIT_ULL(MTK_GMAC_EEE_BIT)
1037 1039
1038 1040 #define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
1039 1041 BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
@@ -1117,7 +1119,7 @@ enum mkt_eth_capabilities {
1117 1119 #define MT7981_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1118 1120 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1119 1121 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
1120 - MTK_RSTCTRL_PPE1 | MTK_SRAM)
1122 + MTK_RSTCTRL_PPE1 | MTK_SRAM | MTK_GMAC_EEE)
1121 1123
1122 1124 #define MT7986_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1123 1125 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
modified drivers/net/ethernet/mellanox/mlx5/core/en/port.c
@@ -557,6 +557,7 @@ int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u16 fec_policy)
557 557 u32 in[MLX5_ST_SZ_DW(pplm_reg)] = {};
558 558 int sz = MLX5_ST_SZ_BYTES(pplm_reg);
559 559 u16 fec_policy_auto = 0;
560 + bool fec_set = false;
560 561 int err;
561 562 int i;
562 563
@@ -569,9 +570,6 @@ int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u16 fec_policy)
569 570 if (fec_policy >= (1 << MLX5E_FEC_LLRS_272_257_1) && !fec_50g_per_lane)
570 571 return -EOPNOTSUPP;
571 572
572 - if (fec_policy && !mlx5e_fec_in_caps(dev, fec_policy))
573 - return -EOPNOTSUPP;
574 -
575 573 MLX5_SET(pplm_reg, in, local_port, 1);
576 574 err = mlx5_core_access_reg(dev, in, sz, out, sz, MLX5_REG_PPLM, 0, 0);
577 575 if (err)
@@ -591,12 +589,17 @@ int mlx5e_set_fec_mode(struct mlx5_core_dev *dev, u16 fec_policy)
591 589 mlx5e_get_fec_cap_field(out, &fec_caps, i);
592 590
593 591 /* policy supported for link speed */
594 - if (fec_caps & conf_fec)
592 + if (fec_caps & conf_fec) {
595 593 mlx5e_fec_admin_field(out, &conf_fec, 1, i);
596 - else
597 - /* set FEC to auto*/
594 + fec_set = true;
595 + } else {
596 + /* set FEC to auto */
598 597 mlx5e_fec_admin_field(out, &fec_policy_auto, 1, i);
598 + }
599 599 }
600 600
601 + if (fec_policy && !fec_set)
602 + return -EOPNOTSUPP;
603 +
601 604 return mlx5_core_access_reg(dev, out, sz, out, sz, MLX5_REG_PPLM, 0, 1);
602 605 }
modified drivers/net/ethernet/mellanox/mlx5/core/en/port.h
@@ -66,4 +66,8 @@ enum {
66 66 MLX5E_FEC_LLRS_272_257_1 = 9,
67 67 };
68 68
69 + #define MLX5E_FEC_RS_MASK (BIT(MLX5E_FEC_RS_528_514) | \
70 + BIT(MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD) | \
71 + BIT(MLX5E_FEC_RS_544_514))
72 +
69 73 #endif
modified drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
@@ -311,12 +311,15 @@ err_alloc:
311 311 static void
312 312 sample_restore_put(struct mlx5e_tc_psample *tc_psample, struct mlx5e_sample_restore *restore)
313 313 {
314 + bool last;
315 +
314 316 mutex_lock(&tc_psample->restore_lock);
315 - if (--restore->count == 0)
317 + last = --restore->count == 0;
318 + if (last)
316 319 hash_del(&restore->hlist);
317 320 mutex_unlock(&tc_psample->restore_lock);
318 321
319 - if (!restore->count) {
322 + if (last) {
320 323 mlx5_del_flow_rules(restore->rule);
321 324 mlx5_modify_header_dealloc(tc_psample->esw->dev, restore->modify_hdr);
322 325 kfree(restore);
modified drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
@@ -148,7 +148,7 @@ static int mlx5e_dcbnl_ieee_getets(struct net_device *netdev,
148 148 if (err)
149 149 return err;
150 150
151 - if (ets->tc_tx_bw[i] < MLX5E_MAX_BW_ALLOC &&
151 + if (priv->dcbx.tc_tsa[i] == IEEE_8021QAZ_TSA_ETS &&
152 152 tc_group[i] == (MLX5E_LOWEST_PRIO_GROUP + 1))
153 153 is_zero_bw_ets_tc = true;
154 154
modified drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -1002,9 +1002,9 @@ static u32 pplm2ethtool_fec(u_long fec_mode, unsigned long size)
1002 1002 return 0;
1003 1003 }
1004 1004
1005 - #define MLX5E_ADVERTISE_SUPPORTED_FEC(mlx5_fec, ethtool_fec) \
1005 + #define MLX5E_ADVERTISE_SUPPORTED_FEC(fec_mask, ethtool_fec) \
1006 1006 do { \
1007 - if (mlx5e_fec_in_caps(dev, 1 << (mlx5_fec))) \
1007 + if (mlx5e_fec_in_caps(dev, fec_mask)) \
1008 1008 __set_bit(ethtool_fec, \
1009 1009 link_ksettings->link_modes.supported);\
1010 1010 } while (0)
@@ -1013,6 +1013,7 @@ static const u32 pplm_fec_2_ethtool_linkmodes[] = {
1013 1013 [MLX5E_FEC_NOFEC] = ETHTOOL_LINK_MODE_FEC_NONE_BIT,
1014 1014 [MLX5E_FEC_FIRECODE] = ETHTOOL_LINK_MODE_FEC_BASER_BIT,
1015 1015 [MLX5E_FEC_RS_528_514] = ETHTOOL_LINK_MODE_FEC_RS_BIT,
1016 + [MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD] = ETHTOOL_LINK_MODE_FEC_RS_BIT,
1016 1017 [MLX5E_FEC_RS_544_514] = ETHTOOL_LINK_MODE_FEC_RS_BIT,
1017 1018 [MLX5E_FEC_LLRS_272_257_1] = ETHTOOL_LINK_MODE_FEC_LLRS_BIT,
1018 1019 };
@@ -1029,13 +1030,13 @@ static int get_fec_supported_advertised(struct mlx5_core_dev *dev,
1029 1030 if (err)
1030 1031 return (err == -EOPNOTSUPP) ? 0 : err;
1031 1032
1032 - MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_NOFEC,
1033 + MLX5E_ADVERTISE_SUPPORTED_FEC(BIT(MLX5E_FEC_NOFEC),
1033 1034 ETHTOOL_LINK_MODE_FEC_NONE_BIT);
1034 - MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_FIRECODE,
1035 + MLX5E_ADVERTISE_SUPPORTED_FEC(BIT(MLX5E_FEC_FIRECODE),
1035 1036 ETHTOOL_LINK_MODE_FEC_BASER_BIT);
1036 - MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_RS_528_514,
1037 + MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_RS_MASK,
1037 1038 ETHTOOL_LINK_MODE_FEC_RS_BIT);
1038 - MLX5E_ADVERTISE_SUPPORTED_FEC(MLX5E_FEC_LLRS_272_257_1,
1039 + MLX5E_ADVERTISE_SUPPORTED_FEC(BIT(MLX5E_FEC_LLRS_272_257_1),
1039 1040 ETHTOOL_LINK_MODE_FEC_LLRS_BIT);
1040 1041
1041 1042 active_fec_long = active_fec;
modified drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -56,7 +56,6 @@
56 56 #include "lib/vxlan.h"
57 57 #define CREATE_TRACE_POINTS
58 58 #include "diag/en_rep_tracepoint.h"
59 - #include "diag/reporter_vnic.h"
60 59 #include "en_accel/ipsec.h"
61 60 #include "en/tc/int_port.h"
62 61 #include "en/ptp.h"
@@ -1439,51 +1438,6 @@ static unsigned int mlx5e_ul_rep_stats_grps_num(struct mlx5e_priv *priv)
1439 1438 return ARRAY_SIZE(mlx5e_ul_rep_stats_grps);
1440 1439 }
1441 1440
1442 - static int
1443 - mlx5e_rep_vnic_reporter_diagnose(struct devlink_health_reporter *reporter,
1444 - struct devlink_fmsg *fmsg,
1445 - struct netlink_ext_ack *extack)
1446 - {
1447 - struct mlx5e_rep_priv *rpriv = devlink_health_reporter_priv(reporter);
1448 - struct mlx5_eswitch_rep *rep = rpriv->rep;
1449 -
1450 - mlx5_reporter_vnic_diagnose_counters(rep->esw->dev, fmsg, rep->vport,
1451 - true);
1452 - return 0;
1453 - }
1454 -
1455 - static const struct devlink_health_reporter_ops mlx5_rep_vnic_reporter_ops = {
1456 - .name = "vnic",
1457 - .diagnose = mlx5e_rep_vnic_reporter_diagnose,
1458 - };
1459 -
1460 - static void mlx5e_rep_vnic_reporter_create(struct mlx5e_priv *priv,
1461 - struct devlink_port *dl_port)
1462 - {
1463 - struct mlx5e_rep_priv *rpriv = priv->ppriv;
1464 - struct devlink_health_reporter *reporter;
1465 -
1466 - reporter = devl_port_health_reporter_create(dl_port,
1467 - &mlx5_rep_vnic_reporter_ops,
1468 - rpriv);
1469 - if (IS_ERR(reporter)) {
1470 - mlx5_core_err(priv->mdev,
1471 - "Failed to create representor vnic reporter, err = %pe\n",
1472 - reporter);
1473 - return;
1474 - }
1475 -
1476 - rpriv->rep_vnic_reporter = reporter;
1477 - }
1478 -
1479 - static void mlx5e_rep_vnic_reporter_destroy(struct mlx5e_priv *priv)
1480 - {
1481 - struct mlx5e_rep_priv *rpriv = priv->ppriv;
1482 -
1483 - if (!IS_ERR_OR_NULL(rpriv->rep_vnic_reporter))
1484 - devl_health_reporter_destroy(rpriv->rep_vnic_reporter);
1485 - }
1486 -
1487 1441 static const struct mlx5e_profile mlx5e_rep_profile = {
1488 1442 .init = mlx5e_init_rep,
1489 1443 .cleanup = mlx5e_cleanup_rep,
@@ -1607,10 +1561,8 @@ mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1607 1561
1608 1562 dl_port = mlx5_esw_offloads_devlink_port(dev->priv.eswitch,
1609 1563 rpriv->rep->vport);
1610 - if (!IS_ERR(dl_port)) {
1564 + if (!IS_ERR(dl_port))
1611 1565 SET_NETDEV_DEVLINK_PORT(netdev, dl_port);
1612 - mlx5e_rep_vnic_reporter_create(priv, dl_port);
1613 - }
1614 1566
1615 1567 err = register_netdev(netdev);
1616 1568 if (err) {
@@ -1623,7 +1575,6 @@ mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
1623 1575 return 0;
1624 1576
1625 1577 err_detach_netdev:
1626 - mlx5e_rep_vnic_reporter_destroy(priv);
1627 1578 mlx5e_detach_netdev(netdev_priv(netdev));
1628 1579 err_cleanup_profile:
1629 1580 priv->profile->cleanup(priv);
@@ -1681,7 +1632,6 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
1681 1632 }
1682 1633
1683 1634 unregister_netdev(netdev);
1684 - mlx5e_rep_vnic_reporter_destroy(priv);
1685 1635 mlx5e_detach_netdev(priv);
1686 1636 priv->profile->cleanup(priv);
1687 1637 mlx5e_destroy_netdev(netdev);
modified drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -118,7 +118,6 @@ struct mlx5e_rep_priv {
118 118 struct rtnl_link_stats64 prev_vf_vport_stats;
119 119 struct mlx5_flow_handle *send_to_vport_meta_rule;
120 120 struct rhashtable tc_ht;
121 - struct devlink_health_reporter *rep_vnic_reporter;
122 121 };
123 122
124 123 static inline
modified drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
@@ -1199,50 +1199,39 @@ void mlx5e_stats_rmon_get(struct mlx5e_priv *priv,
1199 1199 void mlx5e_stats_ts_get(struct mlx5e_priv *priv,
1200 1200 struct ethtool_ts_stats *ts_stats)
1201 1201 {
1202 - int i, j;
1202 + u16 nch = mlx5e_stats_nch_read(priv);
1203 + int i, tc;
1203 1204
1204 - mutex_lock(&priv->state_lock);
1205 + ts_stats->pkts = 0;
1205 1206
1206 - if (priv->tx_ptp_opened) {
1207 - struct mlx5e_ptp *ptp = priv->channels.ptp;
1207 + for (i = 0; i < nch; i++) {
1208 + struct mlx5e_channel_stats *channel_stats =
1209 + priv->channel_stats[i];
1208 1210
1209 - ts_stats->pkts = 0;
1211 + for (tc = 0; tc < priv->max_opened_tc; tc++)
1212 + ts_stats->pkts += channel_stats->sq[tc].timestamps;
1213 + }
1214 +
1215 + /* Accumulate DMA and port timestamp counters so values stay monotonic
1216 + * across channel teardown and mode switches.
1217 + */
1218 + if (priv->tx_ptp_opened) {
1219 + /* Err and Lost stats are only relevant for port timestamping,
1220 + * as the DMA layer will always successfully timestamp packets.
1221 + */
1210 1222 ts_stats->err = 0;
1211 1223 ts_stats->lost = 0;
1212 1224
1213 - if (!ptp)
1214 - goto out;
1215 -
1216 - /* Aggregate stats across all TCs */
1217 - for (i = 0; i < ptp->num_tc; i++) {
1225 + for (tc = 0; tc < priv->max_opened_tc; tc++) {
1218 1226 struct mlx5e_ptp_cq_stats *stats =
1219 - ptp->ptpsq[i].cq_stats;
1227 + &priv->ptp_stats.cq[tc];
1220 1228
1221 1229 ts_stats->pkts += stats->cqe;
1222 1230 ts_stats->err += stats->abort + stats->err_cqe +
1223 - stats->late_cqe;
1231 + stats->late_cqe;
1224 1232 ts_stats->lost += stats->lost_cqe;
1225 1233 }
1226 - } else {
1227 - /* DMA layer will always successfully timestamp packets. Other
1228 - * counters do not make sense for this layer.
1229 - */
1230 - ts_stats->pkts = 0;
1231 -
1232 - /* Aggregate stats across all SQs */
1233 - for (j = 0; j < priv->channels.num; j++) {
1234 - struct mlx5e_channel *c = priv->channels.c[j];
1235 -
1236 - for (i = 0; i < c->num_tc; i++) {
1237 - struct mlx5e_sq_stats *stats = c->sq[i].stats;
1238 -
1239 - ts_stats->pkts += stats->timestamps;
1240 - }
1241 - }
1242 1234 }
1243 -
1244 - out:
1245 - mutex_unlock(&priv->state_lock);
1246 1235 }
1247 1236
1248 1237 #define PPORT_PHY_LAYER_OFF(c) \
modified drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1040,13 +1040,19 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
1040 1040 (vport->info.ipsec_crypto_enabled || vport->info.ipsec_packet_enabled))
1041 1041 esw->enabled_ipsec_vf_count--;
1042 1042
1043 + /* Clear rx-mode before esw_vport_change_handle_locked(): on
1044 + * MLX5_VPORT_PROMISC_CHANGE it calls esw_update_vport_mc_promisc()
1045 + * when vport->allmulti_rule is set, repopulating mc_list with FDB
1046 + * rules that dangle once the FDB is destroyed. NULL allmulti_rule
1047 + * here skips that path.
1048 + */
1049 + esw_apply_vport_rx_mode(esw, vport, false, false);
1043 1050 /* We don't assume VFs will cleanup after themselves.
1044 1051 * Calling vport change handler while vport is disabled will cleanup
1045 1052 * the vport resources.
1046 1053 */
1047 1054 esw_vport_change_handle_locked(vport);
1048 1055 vport->enabled_events = 0;
1049 - esw_apply_vport_rx_mode(esw, vport, false, false);
1050 1056 esw_vport_cleanup(esw, vport);
1051 1057 esw->enabled_vports--;
1052 1058
modified drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -189,6 +189,7 @@ struct mlx5_vport;
189 189 struct mlx5_devlink_port {
190 190 struct devlink_port dl_port;
191 191 struct mlx5_vport *vport;
192 + struct devlink_health_reporter *vnic_reporter;
192 193 };
193 194
194 195 static inline void mlx5_devlink_port_init(struct mlx5_devlink_port *dl_port,
modified drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
@@ -163,12 +163,15 @@ void
163 163 mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw,
164 164 struct mlx5_termtbl_handle *tt)
165 165 {
166 + bool last;
167 +
166 168 mutex_lock(&esw->offloads.termtbl_mutex);
167 - if (--tt->ref_count == 0)
169 + last = (--tt->ref_count == 0);
170 + if (last)
168 171 hash_del(&tt->termtbl_hlist);
169 172 mutex_unlock(&esw->offloads.termtbl_mutex);
170 173
171 - if (!tt->ref_count) {
174 + if (last) {
172 175 mlx5_del_flow_rules(tt->rule);
173 176 mlx5_destroy_flow_table(tt->termtbl);
174 177 kfree(tt);
modified drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -63,14 +63,15 @@ static int get_port_sel_mode(enum mlx5_lag_mode mode, unsigned long flags)
63 63 return MLX5_LAG_PORT_SELECT_MODE_QUEUE_AFFINITY;
64 64 }
65 65
66 - static u8 lag_active_port_bits(struct mlx5_lag *ldev)
66 + static u8 lag_active_port_bits(struct mlx5_lag *ldev,
67 + struct lag_tracker *tracker)
67 68 {
68 69 u8 enabled_ports[MLX5_MAX_PORTS] = {};
69 70 u8 active_port = 0;
70 71 int num_enabled;
71 72 int idx;
72 73
73 - mlx5_infer_tx_enabled(&ldev->tracker, ldev, enabled_ports,
74 + mlx5_infer_tx_enabled(tracker, ldev, enabled_ports,
74 75 &num_enabled);
75 76 for (idx = 0; idx < num_enabled; idx++)
76 77 active_port |= BIT_MASK(enabled_ports[idx]);
@@ -79,7 +80,8 @@ static u8 lag_active_port_bits(struct mlx5_lag *ldev)
79 80 }
80 81
81 82 static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, struct mlx5_lag *ldev,
82 - int mode, unsigned long flags)
83 + struct lag_tracker *tracker, int mode,
84 + unsigned long flags)
83 85 {
84 86 bool fdb_sel_mode = test_bit(MLX5_LAG_MODE_FLAG_FDB_SEL_MODE_NATIVE,
85 87 &flags);
@@ -108,7 +110,7 @@ static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, struct mlx5_lag *ldev,
108 110 break;
109 111
110 112 MLX5_SET(lagc, lag_ctx, active_port,
111 - lag_active_port_bits(mlx5_lag_dev(dev)));
113 + lag_active_port_bits(ldev, tracker));
112 114 break;
113 115 default:
114 116 break;
@@ -787,7 +789,8 @@ static int mlx5_cmd_modify_active_port(struct mlx5_core_dev *dev, u8 ports)
787 789 return mlx5_cmd_exec_in(dev, modify_lag, in);
788 790 }
789 791
790 - static int _mlx5_modify_lag(struct mlx5_lag *ldev, u8 *ports)
792 + static int _mlx5_modify_lag(struct mlx5_lag *ldev,
793 + struct lag_tracker *tracker, u8 *ports)
791 794 {
792 795 int idx = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1);
793 796 struct mlx5_core_dev *dev0;
@@ -804,7 +807,7 @@ static int _mlx5_modify_lag(struct mlx5_lag *ldev, u8 *ports)
804 807 !MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table_bypass))
805 808 return ret;
806 809
807 - active_ports = lag_active_port_bits(ldev);
810 + active_ports = lag_active_port_bits(ldev, tracker);
808 811
809 812 return mlx5_cmd_modify_active_port(dev0, active_ports);
810 813 }
@@ -868,7 +871,7 @@ void mlx5_modify_lag(struct mlx5_lag *ldev,
868 871 idx = i * ldev->buckets + j;
869 872 if (ports[idx] == ldev->v2p_map[idx])
870 873 continue;
871 - err = _mlx5_modify_lag(ldev, ports);
874 + err = _mlx5_modify_lag(ldev, tracker, ports);
872 875 if (err) {
873 876 mlx5_core_err(dev0,
874 877 "Failed to modify LAG (%d)\n",
@@ -976,7 +979,7 @@ static int mlx5_create_lag(struct mlx5_lag *ldev,
976 979 mlx5_core_info(dev0, "shared_fdb:%d mode:%s\n",
977 980 shared_fdb, mlx5_get_str_port_sel_mode(mode, flags));
978 981
979 - err = mlx5_cmd_create_lag(dev0, ldev, mode, flags);
982 + err = mlx5_cmd_create_lag(dev0, ldev, tracker, mode, flags);
980 983 if (err) {
981 984 mlx5_core_err(dev0,
982 985 "Failed to create LAG (%d)\n",
modified drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.c
@@ -572,6 +572,38 @@ mlxsw_sp1_ptp_unmatched_remove(struct mlxsw_sp *mlxsw_sp,
572 572 mlxsw_sp1_ptp_unmatched_ht_params);
573 573 }
574 574
575 + /* mlxsw_sp1_ptp_packet_finish() is reached both from the NAPI poll context
576 + * (mlxsw_sp1_ptp_got_packet(), mlxsw_sp1_ptp_got_piece() and
577 + * mlxsw_sp1_packet_timestamp()) and from process context, by way of the GC
578 + * workqueue (mlxsw_sp1_ptp_ht_gc_collect() ->
579 + * mlxsw_sp1_ptp_unmatched_finish()).
580 + *
581 + * mlxsw_sp_rx_listener_no_mark_func() ends in napi_gro_receive(), using the
582 + * NAPI pointer that was placed in the SKB control block when the trapped
583 + * packet was received in the NAPI context. That pointer may only be used
584 + * from its own poll context, which this call site cannot guarantee.
585 + *
586 + * netif_receive_skb(), unlike napi_gro_receive(), can be called from outside
587 + * of the NAPI instance's poll context. RX stats accounting and the skb->dev
588 + * assignment are still preserved; the only change is the delivery call.
589 + */
590 + static void mlxsw_sp1_ptp_rx_finish(struct mlxsw_sp_port *mlxsw_sp_port,
591 + struct sk_buff *skb)
592 + {
593 + struct mlxsw_sp_port_pcpu_stats *pcpu_stats;
594 +
595 + skb->dev = mlxsw_sp_port->dev;
596 +
597 + pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
598 + u64_stats_update_begin(&pcpu_stats->syncp);
599 + pcpu_stats->rx_packets++;
600 + pcpu_stats->rx_bytes += skb->len;
601 + u64_stats_update_end(&pcpu_stats->syncp);
602 +
603 + skb->protocol = eth_type_trans(skb, skb->dev);
604 + netif_receive_skb(skb);
605 + }
606 +
575 607 /* This function is called in the following scenarios:
576 608 *
577 609 * 1) When a packet is matched with its timestamp.
@@ -600,7 +632,7 @@ static void mlxsw_sp1_ptp_packet_finish(struct mlxsw_sp *mlxsw_sp,
600 632 if (ingress) {
601 633 if (hwtstamps)
602 634 *skb_hwtstamps(skb) = *hwtstamps;
603 - mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
635 + mlxsw_sp1_ptp_rx_finish(mlxsw_sp_port, skb);
604 636 } else {
605 637 /* skb_tstamp_tx() allows hwtstamps to be NULL. */
606 638 skb_tstamp_tx(skb, hwtstamps);
modified drivers/net/ethernet/micrel/ks8851_common.c
@@ -143,9 +143,6 @@ static int ks8851_write_mac_addr(struct net_device *dev)
143 143 ks8851_wrreg16(ks, KS_MAR(i), val);
144 144 }
145 145
146 - if (!netif_running(dev))
147 - ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN);
148 -
149 146 ks8851_unlock(ks);
150 147
151 148 return 0;
@@ -478,8 +475,7 @@ static int ks8851_net_open(struct net_device *dev)
478 475 * @dev: The device being closed.
479 476 *
480 477 * Called to close down a network device which has been active. Cancel any
481 - * work, shutdown the RX and TX process and then place the chip into a low
482 - * power state whilst it is not being used.
478 + * work and shutdown the RX and TX process.
483 479 */
484 480 static int ks8851_net_stop(struct net_device *dev)
485 481 {
@@ -506,8 +502,6 @@ static int ks8851_net_stop(struct net_device *dev)
506 502 /* shutdown TX process */
507 503 ks8851_wrreg16(ks, KS_TXCR, 0x0000);
508 504
509 - /* set powermode to soft power down to save power */
510 - ks8851_set_powermode(ks, PMECR_PM_SOFTDOWN);
511 505 ks8851_unlock(ks);
512 506
513 507 /* ensure any queued tx buffers are dumped */
modified drivers/net/ethernet/microsoft/mana/mana_bpf.c
@@ -208,6 +208,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
208 208 if (err) {
209 209 NL_SET_ERR_MSG_MOD(extack,
210 210 "XDP: Insufficient memory for tx/rx re-config");
211 + apc->bpf_prog = old_prog;
211 212 return err;
212 213 }
213 214
modified drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -2986,6 +2986,10 @@ static int mana_alloc_rx_wqe(struct mana_port_context *apc,
2986 2986 *cq_size += COMP_ENTRY_SIZE;
2987 2987 }
2988 2988
2989 + /* Reserve an extra slot for Fence completion
2990 + * event (CQE_RX_OBJECT_FENCE) in case RX CQ is full.
2991 + */
2992 + *cq_size += COMP_ENTRY_SIZE;
2989 2993 return 0;
2990 2994 }
2991 2995
@@ -3080,7 +3084,7 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
3080 3084 goto out;
3081 3085
3082 3086 rq_size = MANA_PAGE_ALIGN(rq_size);
3083 - cq_size = MANA_PAGE_ALIGN(cq_size);
3087 + cq_size = MANA_PAGE_ALIGN(roundup_pow_of_two(cq_size));
3084 3088
3085 3089 /* Create RQ */
3086 3090 memset(&spec, 0, sizeof(spec));
@@ -3983,7 +3987,8 @@ static void mana_rdma_service_handle(struct work_struct *work)
3983 3987 struct device *dev = gd->gdma_context->dev;
3984 3988 int ret;
3985 3989
3986 - if (READ_ONCE(gd->rdma_teardown))
3990 + /* Pairs with the smp_store_release() in mana_rdma_probe(). */
3991 + if (smp_load_acquire(&gd->rdma_teardown))
3987 3992 goto out;
3988 3993
3989 3994 switch (serv_work->event) {
@@ -4279,6 +4284,21 @@ int mana_rdma_probe(struct gdma_dev *gd)
4279 4284 if (err)
4280 4285 return err;
4281 4286
4287 + /* Clear the state left by a previous mana_rdma_remove() so servicing
4288 + * events are handled again after a reset cycle.
4289 + */
4290 + gd->is_suspended = false;
4291 +
4292 + /* Publish is_suspended before re-opening the gate, so the handler
4293 + * cannot observe an open gate with a stale is_suspended. Pairs
4294 + * with the smp_load_acquire() in mana_rdma_service_handle(). This
4295 + * matters on the reset path, where mana_rdma_remove() closed the
4296 + * gate and drained the workqueue; on the initial probe path the
4297 + * gate was never closed and both flags are already clear. It does
4298 + * not order gd->adev, which add_adev() publishes below.
4299 + */
4300 + smp_store_release(&gd->rdma_teardown, false);
4301 +
4282 4302 err = add_adev(gd, "rdma");
4283 4303 if (err)
4284 4304 mana_gd_deregister_device(gd);
modified drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
@@ -1421,7 +1421,8 @@ static int nfp_net_get_fs_rule(struct nfp_net *nn, struct ethtool_rxnfc *cmd)
1421 1421 return -ENOENT;
1422 1422 }
1423 1423
1424 - static int nfp_net_get_fs_loc(struct nfp_net *nn, u32 *rule_locs)
1424 + static int nfp_net_get_fs_loc(struct nfp_net *nn, struct ethtool_rxnfc *cmd,
1425 + u32 *rule_locs)
1425 1426 {
1426 1427 struct nfp_fs_entry *entry;
1427 1428 u32 count = 0;
@@ -1429,8 +1430,12 @@ static int nfp_net_get_fs_loc(struct nfp_net *nn, u32 *rule_locs)
1429 1430 if (!(nn->cap_w1 & NFP_NET_CFG_CTRL_FLOW_STEER))
1430 1431 return -EOPNOTSUPP;
1431 1432
1432 - list_for_each_entry(entry, &nn->fs.list, node)
1433 + list_for_each_entry(entry, &nn->fs.list, node) {
1434 + if (count == cmd->rule_cnt)
1435 + return -EMSGSIZE;
1433 1436 rule_locs[count++] = entry->loc;
1437 + }
1438 + cmd->rule_cnt = count;
1434 1439
1435 1440 return 0;
1436 1441 }
@@ -1455,7 +1460,7 @@ static int nfp_net_get_rxnfc(struct net_device *netdev,
1455 1460 return nfp_net_get_fs_rule(nn, cmd);
1456 1461 case ETHTOOL_GRXCLSRLALL:
1457 1462 cmd->data = NFP_FS_MAX_ENTRY;
1458 - return nfp_net_get_fs_loc(nn, rule_locs);
1463 + return nfp_net_get_fs_loc(nn, cmd, rule_locs);
1459 1464 default:
1460 1465 return -EOPNOTSUPP;
1461 1466 }
@@ -1698,8 +1703,14 @@ static int nfp_net_fs_add(struct nfp_net *nn, struct ethtool_rxnfc *cmd)
1698 1703
1699 1704 nn->fs.count--;
1700 1705 err = nfp_net_fs_add_hw(nn, new);
1701 - if (err)
1706 + if (err) {
1707 + /* mbox broken, adding the old rule back will
1708 + * likely also fail.
1709 + */
1710 + list_del(&entry->node);
1711 + kfree(entry);
1702 1712 goto err;
1713 + }
1703 1714
1704 1715 nn->fs.count++;
1705 1716 list_replace(&entry->node, &new->node);
modified drivers/net/ethernet/pensando/ionic/ionic_txrx.c
@@ -1672,15 +1672,22 @@ static int ionic_tx(struct net_device *netdev, struct ionic_queue *q,
1672 1672 stats->pkts++;
1673 1673 stats->bytes += skb->len;
1674 1674
1675 + ionic_txq_post(q, false);
1676 +
1675 1677 if (likely(!ionic_txq_hwstamp_enabled(q))) {
1676 1678 struct netdev_queue *ndq = q_to_ndq(netdev, q);
1677 1679
1678 - if (unlikely(!ionic_q_has_space(q, MAX_SKB_FRAGS + 1)))
1679 - netif_tx_stop_queue(ndq);
1680 + netif_txq_maybe_stop(ndq, ionic_q_space_avail(q),
1681 + MAX_SKB_FRAGS + 1, MAX_SKB_FRAGS + 1);
1680 1682 ring_dbell = __netdev_tx_sent_queue(ndq, skb->len,
1681 1683 netdev_xmit_more());
1682 1684 }
1683 - ionic_txq_post(q, ring_dbell);
1685 +
1686 + if (ring_dbell) {
1687 + ionic_dbell_ring(q->lif->kern_dbpage, q->hw_type,
1688 + q->dbval | q->head_idx);
1689 + q->dbell_jiffies = jiffies;
1690 + }
1684 1691
1685 1692 return 0;
1686 1693 }
modified drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4454,6 +4454,26 @@ static bool stmmac_tso_valid_packet(struct sk_buff *skb)
4454 4454 header_len + gso_size < 16383;
4455 4455 }
4456 4456
4457 + static int stmmac_tso_get_num_desc(struct stmmac_tx_queue *tx_q,
4458 + struct sk_buff *skb, u32 pay_len)
4459 + {
4460 + int i, ndesc = 1;
4461 +
4462 + /* head payload */
4463 + ndesc += DIV_ROUND_UP(pay_len, TSO_MAX_BUFF_SIZE);
4464 + /* frag payload */
4465 + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
4466 + const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
4467 +
4468 + ndesc += DIV_ROUND_UP(skb_frag_size(frag),
4469 + TSO_MAX_BUFF_SIZE);
4470 + }
4471 + /* MSS update requires a new descriptor */
4472 + ndesc += !!(skb_shinfo(skb)->gso_size != tx_q->mss);
4473 +
4474 + return ndesc;
4475 + }
4476 +
4457 4477 /**
4458 4478 * stmmac_tso_xmit - Tx entry point of the driver for oversized frames (TSO)
4459 4479 * @skb : the socket buffer
@@ -4497,10 +4517,10 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4497 4517 struct stmmac_priv *priv = netdev_priv(dev);
4498 4518 unsigned int first_entry, entry, tx_packets;
4499 4519 struct stmmac_txq_stats *txq_stats;
4520 + int i, first_tx, nfrags, ndesc;
4500 4521 struct stmmac_tx_queue *tx_q;
4501 4522 bool set_ic, is_last_segment;
4502 4523 u32 pay_len, mss, queue;
4503 - int i, first_tx, nfrags;
4504 4524 u8 proto_hdr_len, hdr;
4505 4525 dma_addr_t des;
4506 4526
@@ -4513,14 +4533,15 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4513 4533
4514 4534 /* Compute header lengths */
4515 4535 proto_hdr_len = stmmac_tso_header_size(skb);
4536 + pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */
4537 +
4516 4538 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
4517 4539 hdr = sizeof(struct udphdr);
4518 4540 else
4519 4541 hdr = tcp_hdrlen(skb);
4520 4542
4521 - /* Desc availability based on threshold should be enough safe */
4522 - if (unlikely(stmmac_tx_avail(priv, queue) <
4523 - (((skb->len - proto_hdr_len) / TSO_MAX_BUFF_SIZE + 1)))) {
4543 + ndesc = stmmac_tso_get_num_desc(tx_q, skb, pay_len);
4544 + if (unlikely(stmmac_tx_avail(priv, queue) < ndesc)) {
4524 4545 if (!netif_tx_queue_stopped(netdev_get_tx_queue(dev, queue))) {
4525 4546 netif_tx_stop_queue(netdev_get_tx_queue(priv->dev,
4526 4547 queue));
@@ -4532,8 +4553,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
4532 4553 return NETDEV_TX_BUSY;
4533 4554 }
4534 4555
4535 - pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */
4536 -
4537 4556 mss = skb_shinfo(skb)->gso_size;
4538 4557
4539 4558 /* set new MSS value if needed */
@@ -8025,6 +8044,7 @@ static int __stmmac_dvr_probe(struct device *device,
8025 8044 stmmac_napi_add(ndev);
8026 8045
8027 8046 mutex_init(&priv->lock);
8047 + rwlock_init(&priv->ptp_lock);
8028 8048
8029 8049 stmmac_fpe_init(priv);
8030 8050
modified drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -365,7 +365,6 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
365 365 if (priv->plat->crosststamp)
366 366 priv->ptp_clock_ops.getcrosststamp = stmmac_getcrosststamp;
367 367
368 - rwlock_init(&priv->ptp_lock);
369 368 mutex_init(&priv->aux_ts_lock);
370 369
371 370 priv->ptp_clock = ptp_clock_register(&priv->ptp_clock_ops,
modified drivers/net/ieee802154/cc2520.c
@@ -1156,11 +1156,10 @@ static void cc2520_remove(struct spi_device *spi)
1156 1156 {
1157 1157 struct cc2520_private *priv = spi_get_drvdata(spi);
1158 1158
1159 - mutex_destroy(&priv->buffer_mutex);
1160 - flush_work(&priv->fifop_irqwork);
1161 -
1159 + disable_work_sync(&priv->fifop_irqwork);
1162 1160 ieee802154_unregister_hw(priv->hw);
1163 1161 ieee802154_free_hw(priv->hw);
1162 + mutex_destroy(&priv->buffer_mutex);
1164 1163 }
1165 1164
1166 1165 static const struct spi_device_id cc2520_ids[] = {
modified drivers/net/ieee802154/mac802154_hwsim.c
@@ -72,6 +72,8 @@ struct hwsim_phy {
72 72 struct ieee802154_hw *hw;
73 73 u32 idx;
74 74
75 + /* Serializes phy->pib_updates. */
76 + spinlock_t pib_lock;
75 77 struct hwsim_pib __rcu *pib;
76 78
77 79 bool suspended;
@@ -102,8 +104,6 @@ static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel,
102 104 if (!pib)
103 105 return -ENOMEM;
104 106
105 - pib_old = rtnl_dereference(phy->pib);
106 -
107 107 pib->page = page;
108 108 pib->channel = channel;
109 109 pib->filt.short_addr = filt->short_addr;
@@ -112,7 +112,10 @@ static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel,
112 112 pib->filt.pan_coord = filt->pan_coord;
113 113 pib->filt_level = filt_level;
114 114
115 - rcu_assign_pointer(phy->pib, pib);
115 + spin_lock_bh(&phy->pib_lock);
116 + pib_old = rcu_replace_pointer(phy->pib, pib,
117 + lockdep_is_held(&phy->pib_lock));
118 + spin_unlock_bh(&phy->pib_lock);
116 119 kfree_rcu(pib_old, rcu);
117 120 return 0;
118 121 }
@@ -952,6 +955,7 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev,
952 955 goto err_pib;
953 956 }
954 957
958 + spin_lock_init(&phy->pib_lock);
955 959 pib->channel = 13;
956 960 pib->filt.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
957 961 pib->filt.pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
modified drivers/net/mctp/mctp-i3c.c
@@ -288,6 +288,7 @@ err:
288 288 static int mctp_i3c_probe(struct i3c_device *i3c)
289 289 {
290 290 struct mctp_i3c_bus *b = NULL, *mbus = NULL;
291 + int rc;
291 292
292 293 /* Look for a known bus */
293 294 mutex_lock(&busdevs_lock);
@@ -296,14 +297,16 @@ static int mctp_i3c_probe(struct i3c_device *i3c)
296 297 mbus = b;
297 298 break;
298 299 }
299 - mutex_unlock(&busdevs_lock);
300 300
301 301 if (!mbus) {
302 302 /* probably no "mctp-controller" property on the i3c bus */
303 - return -ENODEV;
303 + rc = -ENODEV;
304 + } else {
305 + rc = mctp_i3c_add_device(mbus, i3c);
304 306 }
307 + mutex_unlock(&busdevs_lock);
305 308
306 - return mctp_i3c_add_device(mbus, i3c);
309 + return rc;
307 310 }
308 311
309 312 static void mctp_i3c_remove_device(struct mctp_i3c_device *mi)
modified drivers/net/net_failover.c
@@ -675,7 +675,7 @@ static int net_failover_slave_name_change(struct net_device *slave_dev,
675 675 /* We need to bring up the slave after the rename by udev in case
676 676 * open failed with EBUSY when it was registered.
677 677 */
678 - dev_open(slave_dev, NULL);
678 + netif_open(slave_dev, NULL);
679 679
680 680 return 0;
681 681 }
modified drivers/net/phy/dp83867.c
@@ -1150,6 +1150,9 @@ static int dp83867_led_polarity_set(struct phy_device *phydev, int index,
1150 1150 case PHY_LED_ACTIVE_LOW:
1151 1151 polarity = 0;
1152 1152 break;
1153 + case PHY_LED_ACTIVE_HIGH:
1154 + polarity = DP83867_LED_POLARITY(index);
1155 + break;
1153 1156 default:
1154 1157 return -EINVAL;
1155 1158 }
modified drivers/net/phy/dp83td510.c
@@ -439,6 +439,9 @@ static int dp83td510_led_polarity_set(struct phy_device *phydev, int index,
439 439 case PHY_LED_ACTIVE_LOW:
440 440 polarity = 0;
441 441 break;
442 + case PHY_LED_ACTIVE_HIGH:
443 + polarity = DP83TD510E_LED_POLARITY(index);
444 + break;
442 445 default:
443 446 return -EINVAL;
444 447 }
modified drivers/net/phy/mediatek/mtk-ge.c
@@ -62,10 +62,38 @@ static void mtk_gephy_config_init(struct phy_device *phydev)
62 62 FIELD_PREP(MTK_MCC_NEARECHO_OFFSET_MASK, 0x3));
63 63 }
64 64
65 + static int mt7530_phy_probe(struct phy_device *phydev)
66 + {
67 + /* The MT7530 internal GE PHY has broken EEE: with EEE advertised,
68 + * some link partners fail to establish a stable link (on a 2-pair
69 + * cable, 1000BASE-T training fails and the port loops instead of
70 + * falling back). MediaTek recommends disabling EEE on this PHY.
71 + * Clear the advertisement as early as possible, before anything
72 + * can negotiate EEE with the link partner.
73 + */
74 + return phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
75 + }
76 +
65 77 static int mt7530_phy_config_init(struct phy_device *phydev)
66 78 {
79 + int ret;
80 +
67 81 mtk_gephy_config_init(phydev);
68 82
83 + /* The probe() clear alone is not durable: phy_init_hw() replays only
84 + * ->config_init after a PHY reset, with the register back at its
85 + * EEE-advertising hardware default, and phy_probe() zeroes
86 + * eee_disabled_modes (of_set_phy_eee_broken()) after ->probe already
87 + * ran. Clear the advertisement again and mark EEE disabled, so that
88 + * neither phylib nor userspace can re-enable it; dp83867 disables
89 + * broken EEE from config_init() the same way.
90 + */
91 + ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
92 + if (ret)
93 + return ret;
94 +
95 + phy_disable_eee(phydev);
96 +
69 97 /* Increase post_update_timer */
70 98 phy_write_paged(phydev, MTK_PHY_PAGE_EXTENDED_3,
71 99 MTK_PHY_RG_LPI_PCS_DSP_CTRL_REG11, 0x4b);
@@ -100,6 +128,7 @@ static struct phy_driver mtk_gephy_driver[] = {
100 128 {
101 129 PHY_ID_MATCH_EXACT(MTK_GPHY_ID_MT7530),
102 130 .name = "MediaTek MT7530 PHY",
131 + .probe = mt7530_phy_probe,
103 132 .config_init = mt7530_phy_config_init,
104 133 /* Interrupts are handled by the switch, not the PHY
105 134 * itself.
modified drivers/net/phy/phylink.c
@@ -1630,8 +1630,10 @@ static void phylink_resolve(struct work_struct *w)
1630 1630
1631 1631 if (pl->phylink_disable_state) {
1632 1632 pl->link_failed = false;
1633 + link_state = pl->link_config;
1633 1634 link_state.link = false;
1634 1635 } else if (pl->link_failed) {
1636 + link_state = pl->link_config;
1635 1637 link_state.link = false;
1636 1638 retrigger = true;
1637 1639 } else if (pl->act_link_an_mode == MLO_AN_FIXED) {
modified drivers/net/ppp/ppp_async.c
@@ -742,11 +742,8 @@ process_input_packet(struct asyncppp *ap)
742 742 err:
743 743 /* frame had an error, remember that, reset SC_TOSS & SC_ESCAPE */
744 744 ap->state = SC_PREV_ERROR;
745 - if (skb) {
746 - /* make skb appear as freshly allocated */
747 - skb_trim(skb, 0);
748 - skb_reserve(skb, - skb_headroom(skb));
749 - }
745 + kfree_skb(skb);
746 + ap->rpkt = NULL;
750 747 }
751 748
752 749 /* Called when the tty driver has data for us. Runs parallel with the
modified drivers/net/ppp/ppp_synctty.c
@@ -455,17 +455,9 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
455 455
456 456 /* prepend address/control fields if necessary */
457 457 if ((ap->flags & SC_COMP_AC) == 0 || islcp) {
458 - if (skb_headroom(skb) < 2) {
459 - struct sk_buff *npkt = dev_alloc_skb(skb->len + 2);
460 - if (npkt == NULL) {
461 - kfree_skb(skb);
462 - return NULL;
463 - }
464 - skb_reserve(npkt,2);
465 - skb_copy_from_linear_data(skb,
466 - skb_put(npkt, skb->len), skb->len);
467 - consume_skb(skb);
468 - skb = npkt;
458 + if (skb_cow_head(skb, 2)) {
459 + kfree_skb(skb);
460 + return NULL;
469 461 }
470 462 skb_push(skb,2);
471 463 skb->data[0] = PPP_ALLSTATIONS;
modified drivers/net/usb/cx82310_eth.c
@@ -282,6 +282,7 @@ static int cx82310_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
282 282 if (len == 0xffff) {
283 283 netdev_info(dev->net, "router was rebooted, re-enabling ethernet mode");
284 284 schedule_work(&priv->reenable_work);
285 + return 0;
285 286 } else if (len > CX82310_MTU) {
286 287 netdev_err(dev->net, "RX packet too long: %d B\n", len);
287 288 return 0;
modified drivers/net/usb/hso.c
@@ -1547,10 +1547,10 @@ hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
1547 1547 spin_unlock_irq(&serial->serial_lock);
1548 1548 add_wait_queue(&tiocmget->waitq, &wait);
1549 1549 for (;;) {
1550 + set_current_state(TASK_INTERRUPTIBLE);
1550 1551 spin_lock_irq(&serial->serial_lock);
1551 1552 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
1552 1553 spin_unlock_irq(&serial->serial_lock);
1553 - set_current_state(TASK_INTERRUPTIBLE);
1554 1554 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1555 1555 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1556 1556 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd))) {
modified drivers/net/usb/qmi_wwan.c
@@ -1084,6 +1084,7 @@ static const struct usb_device_id products[] = {
1084 1084 },
1085 1085 {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0122)}, /* Quectel RG650V */
1086 1086 {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0125)}, /* Quectel EC25, EC20 R2.0 Mini PCIe */
1087 + {QMI_MATCH_FF_FF_FF(0x2c7c, 0x013d)}, /* Quectel RG660QB */
1087 1088 {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0306)}, /* Quectel EP06/EG06/EM06 */
1088 1089 {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0512)}, /* Quectel EG12/EM12 */
1089 1090 {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0620)}, /* Quectel EM160R-GL */
modified drivers/net/vxlan/vxlan_core.c
@@ -996,6 +996,12 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
996 996 return -EOPNOTSUPP;
997 997 }
998 998
999 + if (rcu_access_pointer(f->nh) &&
1000 + !(state & (NUD_PERMANENT | NUD_NOARP))) {
1001 + NL_SET_ERR_MSG(extack, "Cannot make a nexthop fdb dynamic");
1002 + return -EOPNOTSUPP;
1003 + }
1004 +
999 1005 /* Do not allow an externally learned entry to take over an entry added
1000 1006 * by the user.
1001 1007 */
@@ -1257,6 +1263,11 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
1257 1263 if (err)
1258 1264 return err;
1259 1265
1266 + if (nhid && !(ndm->ndm_state & (NUD_PERMANENT | NUD_NOARP))) {
1267 + NL_SET_ERR_MSG(extack, "A nexthop fdb cannot be dynamic");
1268 + return -EINVAL;
1269 + }
1270 +
1260 1271 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family)
1261 1272 return -EAFNOSUPPORT;
1262 1273
@@ -2362,7 +2373,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2362 2373 struct ip_tunnel_key key;
2363 2374 struct vxlan_dev *vxlan = netdev_priv(dev);
2364 2375 const struct iphdr *old_iph;
2365 - struct vxlan_metadata _md;
2376 + struct vxlan_metadata _md = {};
2366 2377 struct vxlan_metadata *md = &_md;
2367 2378 unsigned int pkt_len = skb->len;
2368 2379 __be16 src_port = 0, dst_port;
modified drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
@@ -477,18 +477,23 @@ static int mt7921_load_clc(struct mt792x_dev *dev, const char *fw_name)
477 477
478 478 for (offset = 0; offset < len; offset += clc_len) {
479 479 if (len - offset < sizeof(*clc)) {
480 + dev_err(mdev->dev, "Invalid CLC record\n");
480 481 ret = -EINVAL;
481 482 goto out;
482 483 }
483 484
484 485 clc = (const struct mt7921_clc *)(clc_base + offset);
485 486 clc_len = le32_to_cpu(clc->len);
486 - if (clc_len < sizeof(*clc) || clc_len > len - offset ||
487 - clc->idx >= ARRAY_SIZE(phy->clc)) {
487 + if (clc_len < sizeof(*clc) || clc_len > len - offset) {
488 + dev_err(mdev->dev, "Invalid CLC record\n");
488 489 ret = -EINVAL;
489 490 goto out;
490 491 }
491 492
493 + /* Newer firmware may add records this driver does not use yet */
494 + if (clc->idx >= ARRAY_SIZE(phy->clc))
495 + continue;
496 +
492 497 /* do not init buf again if chip reset triggered */
493 498 if (phy->clc[clc->idx])
494 499 continue;
modified drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
@@ -323,7 +323,8 @@ int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default)
323 323 const struct cfg80211_sar_capa *capa = phy->mt76->hw->wiphy->sar_capa;
324 324 int i;
325 325
326 - if (!phy->acpisar || !((struct mt792x_acpi_sar *)phy->acpisar)->dyn)
326 + if (!capa || !phy->acpisar ||
327 + !((struct mt792x_acpi_sar *)phy->acpisar)->dyn)
327 328 return 0;
328 329
329 330 /* When ACPI SAR enabled in HW, we should apply rules for .frp
modified drivers/opp/core.c
@@ -453,8 +453,8 @@ int dev_pm_opp_get_opp_count(struct device *dev)
453 453 _find_opp_table(dev);
454 454
455 455 if (IS_ERR(opp_table)) {
456 - dev_dbg(dev, "%s: OPP table not found (%ld)\n",
457 - __func__, PTR_ERR(opp_table));
456 + dev_dbg(dev, "%s: OPP table not found (%pe)\n",
457 + __func__, opp_table);
458 458 return PTR_ERR(opp_table);
459 459 }
460 460
@@ -611,8 +611,8 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
611 611 _find_opp_table(dev);
612 612
613 613 if (IS_ERR(opp_table)) {
614 - dev_err(dev, "%s: OPP table not found (%ld)\n", __func__,
615 - PTR_ERR(opp_table));
614 + dev_err(dev, "%s: OPP table not found (%pe)\n", __func__,
615 + opp_table);
616 616 return ERR_CAST(opp_table);
617 617 }
618 618
@@ -722,8 +722,8 @@ struct dev_pm_opp *dev_pm_opp_find_key_exact(struct device *dev,
722 722 struct opp_table *opp_table __free(put_opp_table) = _find_opp_table(dev);
723 723
724 724 if (IS_ERR(opp_table)) {
725 - dev_err(dev, "%s: OPP table not found (%ld)\n", __func__,
726 - PTR_ERR(opp_table));
725 + dev_err(dev, "%s: OPP table not found (%pe)\n", __func__,
726 + opp_table);
727 727 return ERR_CAST(opp_table);
728 728 }
729 729
@@ -1036,8 +1036,8 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg,
1036 1036
1037 1037 /* Regulator not available for device */
1038 1038 if (IS_ERR(reg)) {
1039 - dev_dbg(dev, "%s: regulator not available: %ld\n", __func__,
1040 - PTR_ERR(reg));
1039 + dev_dbg(dev, "%s: regulator not available: %pe\n", __func__,
1040 + reg);
1041 1041 return 0;
1042 1042 }
1043 1043
@@ -1448,8 +1448,8 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
1448 1448 temp_freq = freq;
1449 1449 opp = _find_freq_ceil(opp_table, &temp_freq);
1450 1450 if (IS_ERR(opp)) {
1451 - dev_err(dev, "%s: failed to find OPP for freq %lu (%ld)\n",
1452 - __func__, freq, PTR_ERR(opp));
1451 + dev_err(dev, "%s: failed to find OPP for freq %lu (%pe)\n",
1452 + __func__, freq, opp);
1453 1453 return PTR_ERR(opp);
1454 1454 }
1455 1455
@@ -1581,6 +1581,8 @@ static struct opp_table *_update_opp_table_clk(struct device *dev,
1581 1581 struct opp_table *opp_table,
1582 1582 bool getclk)
1583 1583 {
1584 + int ret;
1585 +
1584 1586 /*
1585 1587 * Return early if we don't need to get clk or we have already done it
1586 1588 * earlier.
@@ -1607,9 +1609,9 @@ static struct opp_table *_update_opp_table_clk(struct device *dev,
1607 1609 opp_table->clk = clk_get_optional(dev, NULL);
1608 1610
1609 1611 if (IS_ERR(opp_table->clk)) {
1612 + ret = dev_err_probe(dev, PTR_ERR(opp_table->clk), "Couldn't find clock\n");
1610 1613 dev_pm_opp_put_opp_table(opp_table);
1611 - dev_err_probe(dev, PTR_ERR(opp_table->clk), "Couldn't find clock\n");
1612 - return ERR_CAST(opp_table->clk);
1614 + return ERR_PTR(ret);
1613 1615 }
1614 1616
1615 1617 if (opp_table->clk)
@@ -2869,8 +2871,8 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
2869 2871 struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp;
2870 2872
2871 2873 if (IS_ERR(opp_table)) {
2872 - dev_warn(dev, "%s: Device OPP not found (%ld)\n", __func__,
2873 - PTR_ERR(opp_table));
2874 + dev_warn(dev, "%s: Device OPP not found (%pe)\n", __func__,
2875 + opp_table);
2874 2876 return PTR_ERR(opp_table);
2875 2877 }
2876 2878
modified drivers/opp/of.c
@@ -1039,7 +1039,7 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
1039 1039
1040 1040 val = prop->value;
1041 1041 while (nr) {
1042 - unsigned long freq = be32_to_cpup(val++) * 1000;
1042 + unsigned long freq = (unsigned long)be32_to_cpup(val++) * 1000;
1043 1043 unsigned long volt = be32_to_cpup(val++);
1044 1044 struct dev_pm_opp_data data = {
1045 1045 .freq = freq,
@@ -1345,8 +1345,8 @@ int of_get_required_opp_performance_state(struct device_node *np, int index)
1345 1345 _find_table_of_opp_np(required_np);
1346 1346
1347 1347 if (IS_ERR(opp_table)) {
1348 - pr_err("%s: Failed to find required OPP table %pOF: %ld\n",
1349 - __func__, np, PTR_ERR(opp_table));
1348 + pr_err("%s: Failed to find required OPP table %pOF: %pe\n",
1349 + __func__, np, opp_table);
1350 1350 return PTR_ERR(opp_table);
1351 1351 }
1352 1352
modified drivers/perf/riscv_pmu_legacy.c
@@ -110,8 +110,9 @@ static void pmu_legacy_init(struct riscv_pmu *pmu)
110 110 {
111 111 pr_info("Legacy PMU implementation is available\n");
112 112
113 - pmu->cmask = BIT(RISCV_PMU_LEGACY_CYCLE) |
114 - BIT(RISCV_PMU_LEGACY_INSTRET);
113 + bitmap_zero(pmu->cmask, RISCV_MAX_COUNTERS);
114 + set_bit(RISCV_PMU_LEGACY_CYCLE, pmu->cmask);
115 + set_bit(RISCV_PMU_LEGACY_INSTRET, pmu->cmask);
115 116 pmu->ctr_start = pmu_legacy_ctr_start;
116 117 pmu->ctr_stop = NULL;
117 118 pmu->event_map = pmu_legacy_event_map;
modified drivers/perf/riscv_pmu_sbi.c
@@ -97,7 +97,7 @@ static unsigned int riscv_pmu_irq_mask;
97 97 static unsigned int riscv_pmu_irq;
98 98
99 99 /* Cache the available counters in a bitmask */
100 - static unsigned long cmask;
100 + static DECLARE_BITMAP(cmask, RISCV_MAX_COUNTERS);
101 101
102 102 static int pmu_event_find_cache(u64 config);
103 103 struct sbi_pmu_event_data {
@@ -359,16 +359,38 @@ free_mem:
359 359 return result;
360 360 }
361 361
362 + static struct sbiret pmu_sbi_ctr_cfg_match(unsigned long cbase,
363 + unsigned long ctr_mask,
364 + unsigned long cflags,
365 + unsigned long event_idx,
366 + u64 config)
367 + {
368 + #if defined(CONFIG_32BIT)
369 + return sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase,
370 + ctr_mask, cflags, event_idx, config, config >> 32);
371 + #else
372 + return sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase,
373 + ctr_mask, cflags, event_idx, config, 0);
374 + #endif
375 + }
376 +
362 377 static void pmu_sbi_check_event(struct sbi_pmu_event_data *edata)
363 378 {
364 - struct sbiret ret;
379 + struct sbiret ret = { .error = SBI_ERR_NOT_SUPPORTED };
380 + int i;
365 381
366 - ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH,
367 - 0, cmask, 0, edata->event_idx, 0, 0);
368 - if (!ret.error) {
369 - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP,
370 - ret.value, 0x1, SBI_PMU_STOP_FLAG_RESET, 0, 0, 0);
371 - } else if (ret.error == SBI_ERR_NOT_SUPPORTED) {
382 + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) {
383 + if (!cmask[i])
384 + continue;
385 + ret = pmu_sbi_ctr_cfg_match(i * BITS_PER_LONG, cmask[i], 0,
386 + edata->event_idx, 0);
387 + if (!ret.error) {
388 + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP,
389 + ret.value, 0x1, SBI_PMU_STOP_FLAG_RESET, 0, 0, 0);
390 + return;
391 + }
392 + }
393 + if (ret.error == SBI_ERR_NOT_SUPPORTED) {
372 394 /* This event cannot be monitored by any counter */
373 395 edata->event_idx = -ENOENT;
374 396 }
@@ -488,10 +510,10 @@ int riscv_pmu_get_hpm_info(u32 *hw_ctr_width, u32 *num_hw_ctr)
488 510 union sbi_pmu_ctr_info *info;
489 511 u32 hpm_width = 0, hpm_count = 0;
490 512
491 - if (!cmask)
513 + if (bitmap_empty(cmask, RISCV_MAX_COUNTERS))
492 514 return -EINVAL;
493 515
494 - for_each_set_bit(i, &cmask, RISCV_MAX_COUNTERS) {
516 + for_each_set_bit(i, cmask, RISCV_MAX_COUNTERS) {
495 517 info = &pmu_ctr_list[i];
496 518 if (!info)
497 519 continue;
@@ -540,8 +562,8 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
540 562 struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu);
541 563 struct cpu_hw_events *cpuc = this_cpu_ptr(rvpmu->hw_events);
542 564 struct sbiret ret;
543 - int idx;
544 - uint64_t cbase = 0, cmask = rvpmu->cmask;
565 + int idx, i;
566 + u64 cbase = 0, cmask = 0;
545 567 unsigned long cflags = 0;
546 568
547 569 cflags = pmu_sbi_get_filter_flags(event);
@@ -562,14 +584,21 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
562 584 }
563 585
564 586 /* retrieve the available counter index */
565 - #if defined(CONFIG_32BIT)
566 - ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase,
567 - cmask, cflags, hwc->event_base, hwc->config,
568 - hwc->config >> 32);
569 - #else
570 - ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase,
571 - cmask, cflags, hwc->event_base, hwc->config, 0);
572 - #endif
587 + if (cmask) {
588 + ret = pmu_sbi_ctr_cfg_match(cbase, cmask, cflags, hwc->event_base,
589 + hwc->config);
590 + } else {
591 + ret.error = SBI_ERR_NOT_SUPPORTED;
592 + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) {
593 + if (!rvpmu->cmask[i])
594 + continue;
595 + cbase = i * BITS_PER_LONG;
596 + ret = pmu_sbi_ctr_cfg_match(cbase, rvpmu->cmask[i], cflags,
597 + hwc->event_base, hwc->config);
598 + if (!ret.error)
599 + break;
600 + }
601 + }
573 602 if (ret.error) {
574 603 pr_debug("Not able to find a counter for event %lx config %llx\n",
575 604 hwc->event_base, hwc->config);
@@ -577,7 +606,7 @@ static int pmu_sbi_ctr_get_idx(struct perf_event *event)
577 606 }
578 607
579 608 idx = ret.value;
580 - if (!test_bit(idx, &rvpmu->cmask) || !pmu_ctr_list[idx].value)
609 + if (!test_bit(idx, rvpmu->cmask) || !pmu_ctr_list[idx].value)
581 610 return -ENOENT;
582 611
583 612 /* Additional sanity check for the counter id */
@@ -881,7 +910,7 @@ static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask)
881 910 /* The logical counter ids are not expected to be contiguous */
882 911 continue;
883 912
884 - *mask |= BIT(i);
913 + set_bit(i, mask);
885 914
886 915 cinfo.value = ret.value;
887 916 if (cinfo.type == SBI_PMU_CTR_TYPE_FW)
@@ -898,12 +927,19 @@ static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask)
898 927
899 928 static inline void pmu_sbi_stop_all(struct riscv_pmu *pmu)
900 929 {
930 + int i;
931 +
901 932 /*
902 933 * No need to check the error because we are disabling all the counters
903 934 * which may include counters that are not enabled yet.
904 935 */
905 - sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP,
906 - 0, pmu->cmask, SBI_PMU_STOP_FLAG_RESET, 0, 0, 0);
936 + for (i = 0; i < BITS_TO_LONGS(RISCV_MAX_COUNTERS); i++) {
937 + if (!pmu->cmask[i])
938 + continue;
939 + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP,
940 + i * BITS_PER_LONG, pmu->cmask[i],
941 + SBI_PMU_STOP_FLAG_RESET, 0, 0, 0);
942 + }
907 943 }
908 944
909 945 static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu)
@@ -1002,7 +1038,7 @@ static inline void pmu_sbi_start_ovf_ctrs_snapshot(struct cpu_hw_events *cpu_hw_
1002 1038 struct riscv_pmu_snapshot_data *sdata = cpu_hw_evt->snapshot_addr;
1003 1039
1004 1040 for_each_set_bit(idx, cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS) {
1005 - if (ctr_ovf_mask & BIT(idx)) {
1041 + if (ctr_ovf_mask & BIT_ULL(idx)) {
1006 1042 event = cpu_hw_evt->events[idx];
1007 1043 hwc = &event->hw;
1008 1044 max_period = riscv_pmu_ctr_get_width_mask(event);
@@ -1050,11 +1086,13 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)
1050 1086 u64 overflowed_ctrs = 0;
1051 1087 struct cpu_hw_events *cpu_hw_evt = dev;
1052 1088 u64 start_clock = sched_clock();
1053 - struct riscv_pmu_snapshot_data *sdata = cpu_hw_evt->snapshot_addr;
1089 + struct riscv_pmu_snapshot_data *sdata;
1054 1090
1055 1091 if (WARN_ON_ONCE(!cpu_hw_evt))
1056 1092 return IRQ_NONE;
1057 1093
1094 + sdata = cpu_hw_evt->snapshot_addr;
1095 +
1058 1096 /* Firmware counter don't support overflow yet */
1059 1097 fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS);
1060 1098 if (fidx == RISCV_MAX_COUNTERS) {
@@ -1109,14 +1147,14 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)
1109 1147 hidx = info->csr - CSR_CYCLE;
1110 1148
1111 1149 /* check if the corresponding bit is set in scountovf or overflow mask in shmem */
1112 - if (!(overflow & BIT(hidx)))
1150 + if (!(overflow & BIT_ULL(hidx)))
1113 1151 continue;
1114 1152
1115 1153 /*
1116 1154 * Keep a track of overflowed counters so that they can be started
1117 1155 * with updated initial value.
1118 1156 */
1119 - overflowed_ctrs |= BIT(lidx);
1157 + overflowed_ctrs |= BIT_ULL(lidx);
1120 1158 hw_evt = &event->hw;
1121 1159 /* Update the event states here so that we know the state while reading */
1122 1160 hw_evt->state |= PERF_HES_STOPPED;
@@ -1451,7 +1489,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
1451 1489 }
1452 1490
1453 1491 /* cache all the information about counters now */
1454 - if (pmu_sbi_get_ctrinfo(num_counters, &cmask))
1492 + if (pmu_sbi_get_ctrinfo(num_counters, cmask))
1455 1493 goto out_free;
1456 1494
1457 1495 ret = pmu_sbi_setup_irqs(pmu, pdev);
@@ -1464,7 +1502,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev)
1464 1502
1465 1503 pmu->pmu.attr_groups = riscv_pmu_attr_groups;
1466 1504 pmu->pmu.parent = &pdev->dev;
1467 - pmu->cmask = cmask;
1505 + bitmap_copy(pmu->cmask, cmask, RISCV_MAX_COUNTERS);
1468 1506 pmu->ctr_start = pmu_sbi_ctr_start;
1469 1507 pmu->ctr_stop = pmu_sbi_ctr_stop;
1470 1508 pmu->event_map = pmu_sbi_event_map;
modified drivers/platform/x86/amd/pmf/spc.c
@@ -17,7 +17,6 @@
17 17 #include <linux/units.h>
18 18 #include "pmf.h"
19 19
20 - #ifdef CONFIG_AMD_PMF_DEBUG
21 20 u32 amd_pmf_get_ta_custom_bios_inputs(struct ta_pmf_enact_table *in, int index)
22 21 {
23 22 switch (index) {
@@ -31,6 +30,7 @@ u32 amd_pmf_get_ta_custom_bios_inputs(struct ta_pmf_enact_table *in, int index)
31 30 }
32 31 EXPORT_SYMBOL(amd_pmf_get_ta_custom_bios_inputs);
33 32
33 + #ifdef CONFIG_AMD_PMF_DEBUG
34 34 void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in)
35 35 {
36 36 int i;
modified drivers/platform/x86/asus-laptop.c
@@ -1882,7 +1882,7 @@ static int asus_acpi_probe(struct platform_device *pdev)
1882 1882 if (result && result != -ENODEV)
1883 1883 goto fail_pega_rfkill;
1884 1884
1885 - result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
1885 + result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
1886 1886 asus_acpi_notify, asus);
1887 1887 if (result)
1888 1888 goto fail_pega_rfkill;
@@ -1912,7 +1912,7 @@ static void asus_acpi_remove(struct platform_device *pdev)
1912 1912 {
1913 1913 struct asus_laptop *asus = platform_get_drvdata(pdev);
1914 1914
1915 - acpi_dev_remove_notify_handler(asus->device, ACPI_DEVICE_NOTIFY,
1915 + acpi_dev_remove_notify_handler(asus->device, ACPI_ALL_NOTIFY,
1916 1916 asus_acpi_notify);
1917 1917 asus_backlight_exit(asus);
1918 1918 asus_rfkill_exit(asus);
modified drivers/platform/x86/hp/hp-wmi.c
@@ -337,7 +337,7 @@ static const struct dmi_system_id hp_wmi_feature_boards[] __initconst = {
337 337 },
338 338 {
339 339 .matches = { DMI_MATCH(DMI_BOARD_NAME, "8DD6") },
340 - .driver_data = (void *)&omen_v1_no_ec_thermal_params,
340 + .driver_data = (void *)&omen_v1_no_ec_board_params,
341 341 },
342 342 {
343 343 .matches = { DMI_MATCH(DMI_BOARD_NAME, "8E35") },
modified drivers/platform/x86/x86-android-tablets/core.c
@@ -156,7 +156,6 @@ static struct platform_device **pdevs;
156 156 static struct serdev_device **serdevs;
157 157 static const struct software_node **gpio_button_swnodes;
158 158 static const struct software_node **swnode_group;
159 - static const struct software_node **gpiochip_node_group;
160 159 static void (*exit_handler)(void);
161 160
162 161 static __init struct i2c_adapter *
@@ -362,11 +361,21 @@ static const struct software_node *cherryview_gpiochip_node_group[] = {
362 361 NULL
363 362 };
364 363
364 + const struct software_node crystalcove_gpiochip_node = {
365 + .name = "INT33FD:00",
366 + };
367 +
368 + static const struct software_node *crystalcove_gpiochip_node_group[] = {
369 + &crystalcove_gpiochip_node,
370 + NULL
371 + };
372 +
365 373 static void gpio_secondary_unset(void *data)
366 374 {
367 375 struct device *dev = data;
368 376
369 377 set_secondary_fwnode(dev, NULL);
378 + put_device(dev);
370 379 }
371 380
372 381 static void gpio_secondary_unregister_node_group(void *data)
@@ -376,26 +385,28 @@ static void gpio_secondary_unregister_node_group(void *data)
376 385 software_node_unregister_node_group(nodes);
377 386 }
378 387
379 - static int gpio_secondary_fwnode_init(struct device *parent)
388 + static int gpio_secondary_fwnode_init(struct device *parent,
389 + const struct software_node * const *node_group)
380 390 {
381 391 const struct software_node *const *swnode;
382 392 struct fwnode_handle *fwnode;
393 + struct device *phys_dev;
383 394 int ret;
384 395
385 - if (!gpiochip_node_group)
396 + if (!node_group)
386 397 return 0;
387 398
388 - ret = software_node_register_node_group(gpiochip_node_group);
399 + ret = software_node_register_node_group(node_group);
389 400 if (ret)
390 401 return ret;
391 402
392 403 ret = devm_add_action_or_reset(parent,
393 404 gpio_secondary_unregister_node_group,
394 - gpiochip_node_group);
405 + (void *)node_group);
395 406 if (ret)
396 407 return ret;
397 408
398 - for (swnode = gpiochip_node_group; *swnode; swnode++) {
409 + for (swnode = node_group; *swnode; swnode++) {
399 410 struct device *dev __free(put_device) =
400 411 acpi_bus_find_device_by_name((*swnode)->name);
401 412 if (!dev)
@@ -407,9 +418,15 @@ static int gpio_secondary_fwnode_init(struct device *parent)
407 418 if (WARN_ON(!fwnode))
408 419 return -ENOENT;
409 420
410 - set_secondary_fwnode(dev, fwnode);
421 + phys_dev = acpi_get_first_physical_node(to_acpi_device(dev));
422 + if (!phys_dev)
423 + return dev_err_probe(parent, -ENODEV,
424 + "No physical device for ACPI GPIO dev: %pfwP\n",
425 + fwnode);
426 +
427 + set_secondary_fwnode(phys_dev, fwnode);
411 428
412 - ret = devm_add_action_or_reset(parent, gpio_secondary_unset, dev);
429 + ret = devm_add_action_or_reset(parent, gpio_secondary_unset, get_device(phys_dev));
413 430 if (ret)
414 431 return ret;
415 432 }
@@ -452,6 +469,7 @@ static void x86_android_tablet_remove(struct platform_device *pdev)
452 469
453 470 static __init int x86_android_tablet_probe(struct platform_device *pdev)
454 471 {
472 + const struct software_node * const *gpiochip_node_group;
455 473 const struct x86_dev_info *dev_info;
456 474 const struct dmi_system_id *id;
457 475 int i, ret = 0;
@@ -483,12 +501,20 @@ static __init int x86_android_tablet_probe(struct platform_device *pdev)
483 501 break;
484 502 }
485 503
486 - ret = gpio_secondary_fwnode_init(&pdev->dev);
504 + ret = gpio_secondary_fwnode_init(&pdev->dev, gpiochip_node_group);
487 505 if (ret) {
488 506 x86_android_tablet_remove(pdev);
489 507 return ret;
490 508 }
491 509
510 + if (dev_info->has_crystalcove) {
511 + ret = gpio_secondary_fwnode_init(&pdev->dev, crystalcove_gpiochip_node_group);
512 + if (ret) {
513 + x86_android_tablet_remove(pdev);
514 + return ret;
515 + }
516 + }
517 +
492 518 ret = software_node_register_node_group(dev_info->swnode_group);
493 519 if (ret) {
494 520 x86_android_tablet_remove(pdev);
modified drivers/platform/x86/x86-android-tablets/lenovo.c
@@ -61,13 +61,6 @@ static struct lp855x_platform_data lenovo_lp8557_reg_only_pdata = {
61 61 .initial_brightness = 128,
62 62 };
63 63
64 - static const struct software_node arizona_gpiochip_node = {
65 - .name = "arizona",
66 - };
67 -
68 - static const struct software_node crystalcove_gpiochip_node = {
69 - .name = "gpio_crystalcove",
70 - };
71 64
72 65 /* Lenovo Yoga Book X90F / X90L's Android factory image has everything hardcoded */
73 66
@@ -416,15 +409,17 @@ static const struct platform_device_info lenovo_yoga_tab2_830_1050_pdevs[] __ini
416 409
417 410 #define LENOVO_YOGA_TAB2_830_1050_CODEC_NAME "spi-10WM5102:00"
418 411
412 + static const struct software_node lenovo_yoga_tab2_830_1050_wm5102;
413 +
419 414 static const struct property_entry lenovo_yoga_tab2_830_1050_wm1502_props[] = {
420 415 PROPERTY_ENTRY_GPIO("reset-gpios",
421 416 &crystalcove_gpiochip_node, 3, GPIO_ACTIVE_HIGH),
422 417 PROPERTY_ENTRY_GPIO("wlf,ldoena-gpios",
423 418 &baytrail_gpiochip_nodes[1], 23, GPIO_ACTIVE_HIGH),
424 419 PROPERTY_ENTRY_GPIO("wlf,spkvdd-ena-gpios",
425 - &arizona_gpiochip_node, 2, GPIO_ACTIVE_HIGH),
420 + &lenovo_yoga_tab2_830_1050_wm5102, 2, GPIO_ACTIVE_HIGH),
426 421 PROPERTY_ENTRY_GPIO("wlf,micd-pol-gpios",
427 - &arizona_gpiochip_node, 4, GPIO_ACTIVE_LOW),
422 + &lenovo_yoga_tab2_830_1050_wm5102, 4, GPIO_ACTIVE_LOW),
428 423 { }
429 424 };
430 425
@@ -432,14 +427,6 @@ static const struct software_node lenovo_yoga_tab2_830_1050_wm5102 = {
432 427 .properties = lenovo_yoga_tab2_830_1050_wm1502_props,
433 428 };
434 429
435 - static const struct software_node *lenovo_yoga_tab2_830_1050_swnodes[] = {
436 - &crystalcove_gpiochip_node,
437 - &arizona_gpiochip_node,
438 - &lenovo_yoga_tab2_830_1050_wm5102,
439 - &generic_lipo_hv_4v35_battery_node,
440 - NULL
441 - };
442 -
443 430 static int __init lenovo_yoga_tab2_830_1050_init(struct device *dev);
444 431 static void lenovo_yoga_tab2_830_1050_exit(void);
445 432
@@ -455,8 +442,9 @@ const struct x86_dev_info lenovo_yoga_tab2_830_1050_info __initconst = {
455 442 .pdev_info = lenovo_yoga_tab2_830_1050_pdevs,
456 443 .pdev_count = ARRAY_SIZE(lenovo_yoga_tab2_830_1050_pdevs),
457 444 .gpio_button_swnodes = lenovo_yoga_tab2_830_1050_lid_swnodes,
458 - .swnode_group = lenovo_yoga_tab2_830_1050_swnodes,
445 + .swnode_group = generic_lipo_hv_4v35_battery_swnodes,
459 446 .modules = lenovo_yoga_tab2_modules,
447 + .has_crystalcove = true,
460 448 .gpiochip_type = X86_GPIOCHIP_BAYTRAIL,
461 449 .init = lenovo_yoga_tab2_830_1050_init,
462 450 .exit = lenovo_yoga_tab2_830_1050_exit,
@@ -800,8 +788,9 @@ const struct x86_dev_info lenovo_yoga_tab2_1380_info __initconst = {
800 788 .pdev_info = lenovo_yoga_tab2_1380_pdevs,
801 789 .pdev_count = ARRAY_SIZE(lenovo_yoga_tab2_1380_pdevs),
802 790 .gpio_button_swnodes = lenovo_yoga_tab2_830_1050_lid_swnodes,
803 - .swnode_group = lenovo_yoga_tab2_830_1050_swnodes,
791 + .swnode_group = generic_lipo_hv_4v35_battery_swnodes,
804 792 .modules = lenovo_yoga_tab2_modules,
793 + .has_crystalcove = true,
805 794 .gpiochip_type = X86_GPIOCHIP_BAYTRAIL,
806 795 .init = lenovo_yoga_tab2_1380_init,
807 796 .exit = lenovo_yoga_tab2_830_1050_exit,
@@ -985,13 +974,15 @@ static struct arizona_pdata lenovo_yt3_wm5102_pdata = {
985 974 },
986 975 };
987 976
977 + static const struct software_node lenovo_yt3_wm5102;
978 +
988 979 static const struct property_entry lenovo_yt3_wm1502_props[] = {
989 980 PROPERTY_ENTRY_GPIO("wlf,spkvdd-ena-gpios",
990 981 &cherryview_gpiochip_nodes[0], 75, GPIO_ACTIVE_HIGH),
991 982 PROPERTY_ENTRY_GPIO("wlf,ldoena-gpios",
992 983 &cherryview_gpiochip_nodes[0], 81, GPIO_ACTIVE_HIGH),
993 984 PROPERTY_ENTRY_GPIO("reset-gpios", &cherryview_gpiochip_nodes[0], 82, GPIO_ACTIVE_HIGH),
994 - PROPERTY_ENTRY_GPIO("wlf,micd-pol-gpios", &arizona_gpiochip_node, 2, GPIO_ACTIVE_HIGH),
985 + PROPERTY_ENTRY_GPIO("wlf,micd-pol-gpios", &lenovo_yt3_wm5102, 2, GPIO_ACTIVE_HIGH),
995 986 { }
996 987 };
997 988
@@ -1000,11 +991,6 @@ static const struct software_node lenovo_yt3_wm5102 = {
1000 991 .name = "wm5102",
1001 992 };
1002 993
1003 - static const struct software_node *lenovo_yt3_swnodes[] = {
1004 - &arizona_gpiochip_node,
1005 - &lenovo_yt3_wm5102,
1006 - NULL
1007 - };
1008 994
1009 995 static const struct x86_spi_dev_info lenovo_yt3_spi_devs[] __initconst = {
1010 996 {
@@ -1072,7 +1058,6 @@ const struct x86_dev_info lenovo_yt3_info __initconst = {
1072 1058 .i2c_client_count = ARRAY_SIZE(lenovo_yt3_i2c_clients),
1073 1059 .spi_dev_info = lenovo_yt3_spi_devs,
1074 1060 .spi_dev_count = ARRAY_SIZE(lenovo_yt3_spi_devs),
1075 - .swnode_group = lenovo_yt3_swnodes,
1076 1061 .modules = lenovo_yt3_modules,
1077 1062 .gpiochip_type = X86_GPIOCHIP_CHERRYVIEW,
1078 1063 .init = lenovo_yt3_init,
modified drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
@@ -96,6 +96,7 @@ struct x86_dev_info {
96 96 int (*init)(struct device *dev);
97 97 void (*exit)(void);
98 98 bool use_pci;
99 + bool has_crystalcove;
99 100 enum x86_gpiochip_type gpiochip_type;
100 101 };
101 102
@@ -107,6 +108,7 @@ int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data);
107 108 /* Software nodes representing GPIO chips used by various tablets */
108 109 extern const struct software_node baytrail_gpiochip_nodes[];
109 110 extern const struct software_node cherryview_gpiochip_nodes[];
111 + extern const struct software_node crystalcove_gpiochip_node;
110 112
111 113 /*
112 114 * Extern declarations of x86_dev_info structs so there can be a single
modified drivers/regulator/pf1550-regulator.c
@@ -283,63 +283,61 @@ static struct pf1550_desc pf1550_regulators[] = {
283 283 PF_LDO1(PF1550, "ldo3", LDO3, 0x1f, pf1550_ldo13_volts),
284 284 };
285 285
286 + /*
287 + * The _LS interrupts indicate an over-current event. The _HS
288 + * interrupts, which are more accurate and can detect catastrophic
289 + * faults, issue an error event. The current limit FAULT interrupt is
290 + * similar to the _HS.
291 + */
292 + static const struct pf1550_regulator_irq {
293 + unsigned int event;
294 + u8 id;
295 + } pf1550_regulator_irqs[] = {
296 + [PF1550_PMIC_IRQ_SW1_LS] = { REGULATOR_EVENT_OVER_CURRENT_WARN, PF1550_SW1 },
297 + [PF1550_PMIC_IRQ_SW2_LS] = { REGULATOR_EVENT_OVER_CURRENT_WARN, PF1550_SW2 },
298 + [PF1550_PMIC_IRQ_SW3_LS] = { REGULATOR_EVENT_OVER_CURRENT_WARN, PF1550_SW3 },
299 + [PF1550_PMIC_IRQ_SW1_HS] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_SW1 },
300 + [PF1550_PMIC_IRQ_SW2_HS] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_SW2 },
301 + [PF1550_PMIC_IRQ_SW3_HS] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_SW3 },
302 + [PF1550_PMIC_IRQ_LDO1_FAULT] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_LDO1 },
303 + [PF1550_PMIC_IRQ_LDO2_FAULT] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_LDO2 },
304 + [PF1550_PMIC_IRQ_LDO3_FAULT] = { REGULATOR_EVENT_OVER_CURRENT, PF1550_LDO3 },
305 + };
306 +
286 307 static irqreturn_t pf1550_regulator_irq_handler(int irq, void *data)
287 308 {
309 + const struct pf1550_regulator_irq *map;
288 310 struct pf1550_regulator_info *info = data;
289 311 struct device *dev = info->dev;
290 312 struct platform_device *pdev = to_platform_device(dev);
291 313 int i, irq_type = -1;
292 - unsigned int event;
293 314
294 315 for (i = 0; i < PF1550_REGULATOR_IRQ_NR; i++)
295 316 if (irq == platform_get_irq(pdev, i))
296 317 irq_type = i;
297 318
298 - switch (irq_type) {
299 - /* The _LS interrupts indicate over-current event. The _HS interrupts
300 - * which are more accurate and can detect catastrophic faults, issue
301 - * an error event. The current limit FAULT interrupt is similar to the
302 - * _HS'
303 - */
304 - case PF1550_PMIC_IRQ_SW1_LS:
305 - case PF1550_PMIC_IRQ_SW2_LS:
306 - case PF1550_PMIC_IRQ_SW3_LS:
307 - event = REGULATOR_EVENT_OVER_CURRENT_WARN;
308 - for (i = 0; i < PF1550_MAX_REGULATOR; i++)
309 - if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3"))
310 - regulator_notifier_call_chain(info->rdevs[i],
311 - event, NULL);
312 - break;
313 - case PF1550_PMIC_IRQ_SW1_HS:
314 - case PF1550_PMIC_IRQ_SW2_HS:
315 - case PF1550_PMIC_IRQ_SW3_HS:
316 - event = REGULATOR_EVENT_OVER_CURRENT;
317 - for (i = 0; i < PF1550_MAX_REGULATOR; i++)
318 - if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3"))
319 - regulator_notifier_call_chain(info->rdevs[i],
320 - event, NULL);
321 - break;
322 - case PF1550_PMIC_IRQ_LDO1_FAULT:
323 - case PF1550_PMIC_IRQ_LDO2_FAULT:
324 - case PF1550_PMIC_IRQ_LDO3_FAULT:
325 - event = REGULATOR_EVENT_OVER_CURRENT;
326 - for (i = 0; i < PF1550_MAX_REGULATOR; i++)
327 - if (!strcmp(rdev_get_name(info->rdevs[i]), "LDO3"))
328 - regulator_notifier_call_chain(info->rdevs[i],
329 - event, NULL);
330 - break;
331 - case PF1550_PMIC_IRQ_TEMP_110:
332 - case PF1550_PMIC_IRQ_TEMP_125:
333 - event = REGULATOR_EVENT_OVER_TEMP;
319 + /* The die temperature concerns every rail. */
320 + if (irq_type == PF1550_PMIC_IRQ_TEMP_110 ||
321 + irq_type == PF1550_PMIC_IRQ_TEMP_125) {
334 322 for (i = 0; i < PF1550_MAX_REGULATOR; i++)
335 323 regulator_notifier_call_chain(info->rdevs[i],
336 - event, NULL);
337 - break;
338 - default:
339 - dev_err(dev, "regulator interrupt: irq %d occurred\n",
340 - irq_type);
324 + REGULATOR_EVENT_OVER_TEMP,
325 + NULL);
326 + return IRQ_HANDLED;
327 + }
328 +
329 + if (irq_type < 0 || irq_type >= (int)ARRAY_SIZE(pf1550_regulator_irqs)) {
330 + dev_err(dev, "regulator interrupt: irq %d occurred\n", irq_type);
331 + return IRQ_HANDLED;
341 332 }
342 333
334 + map = &pf1550_regulator_irqs[irq_type];
335 +
336 + for (i = 0; i < PF1550_MAX_REGULATOR; i++)
337 + if (rdev_get_id(info->rdevs[i]) == map->id)
338 + regulator_notifier_call_chain(info->rdevs[i],
339 + map->event, NULL);
340 +
343 341 return IRQ_HANDLED;
344 342 }
345 343
modified drivers/s390/net/ism_drv.c
@@ -231,6 +231,7 @@ static void ism_free_dmb(struct ism_dev *ism, struct dibs_dmb *dmb)
231 231 dma_unmap_page(&ism->pdev->dev, dmb->dma_addr, dmb->dmb_len,
232 232 DMA_FROM_DEVICE);
233 233 folio_put(virt_to_folio(dmb->cpu_addr));
234 + dmb->cpu_addr = NULL;
234 235 }
235 236
236 237 static int ism_alloc_dmb(struct ism_dev *ism, struct dibs_dmb *dmb)
@@ -274,7 +275,8 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct dibs_dmb *dmb)
274 275 return 0;
275 276
276 277 out_free:
277 - kfree(dmb->cpu_addr);
278 + folio_put(folio);
279 + dmb->cpu_addr = NULL;
278 280 out_bit:
279 281 clear_bit(dmb->idx, ism->sba_bitmap);
280 282 return rc;
modified drivers/s390/net/qeth_l2.h
@@ -13,7 +13,8 @@ extern const struct attribute_group *qeth_l2_attr_groups[];
13 13
14 14 int qeth_bridgeport_query_ports(struct qeth_card *card,
15 15 enum qeth_sbp_roles *role,
16 - enum qeth_sbp_states *state);
16 + enum qeth_sbp_states *state,
17 + bool *os_mismatch);
17 18 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role);
18 19 int qeth_bridgeport_an_set(struct qeth_card *card, int enable);
19 20
modified drivers/s390/net/qeth_l2_main.c
@@ -1158,7 +1158,7 @@ static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
1158 1158 qeth_bridgeport_setrole(card, card->options.sbp.role);
1159 1159 /* Let the callback function refresh the stored role value. */
1160 1160 qeth_bridgeport_query_ports(card, &card->options.sbp.role,
1161 - NULL);
1161 + NULL, NULL);
1162 1162 }
1163 1163 if (card->options.sbp.hostnotification) {
1164 1164 if (qeth_bridgeport_an_set(card, 1))
@@ -1545,6 +1545,7 @@ struct _qeth_sbp_cbctl {
1545 1545 struct {
1546 1546 enum qeth_sbp_roles *role;
1547 1547 enum qeth_sbp_states *state;
1548 + bool *os_mismatch;
1548 1549 } qports;
1549 1550 } data;
1550 1551 };
@@ -1721,10 +1722,19 @@ static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1721 1722 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1722 1723 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1723 1724 struct qeth_sbp_port_data *qports;
1725 + u16 sbp_rc;
1724 1726 int rc;
1725 1727
1726 1728 QETH_CARD_TEXT(card, 2, "brqprtcb");
1727 - rc = qeth_bridgeport_makerc(card, cmd);
1729 + sbp_rc = cmd->data.sbp.hdr.return_code;
1730 +
1731 + /* on OS family mismatch, query still returns valid port data;
1732 + * treat as success
1733 + */
1734 + if (sbp_rc == IPA_RC_SBP_IQD_OS_MISMATCH && !cmd->hdr.return_code)
1735 + rc = 0;
1736 + else
1737 + rc = qeth_bridgeport_makerc(card, cmd);
1728 1738 if (rc)
1729 1739 return rc;
1730 1740
@@ -1740,6 +1750,9 @@ static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1740 1750 if (cbctl->data.qports.state)
1741 1751 *cbctl->data.qports.state = qports->entry[0].state;
1742 1752 }
1753 + if (cbctl->data.qports.os_mismatch)
1754 + *cbctl->data.qports.os_mismatch =
1755 + (sbp_rc == IPA_RC_SBP_IQD_OS_MISMATCH);
1743 1756 return 0;
1744 1757 }
1745 1758
@@ -1748,13 +1761,17 @@ static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1748 1761 * @card: qeth_card structure pointer.
1749 1762 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1750 1763 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1764 + * @os_mismatch: if non-NULL, set to true when firmware reports
1765 + * OS family mismatch.
1751 1766 *
1752 1767 * Returns negative errno-compatible error indication or 0 on success.
1753 1768 *
1754 - * 'role' and 'state' are not updated in case of hardware operation failure.
1769 + * 'role', 'state' and 'os_mismatch' are not updated in case of
1770 + * hardware operation failure.
1755 1771 */
1756 1772 int qeth_bridgeport_query_ports(struct qeth_card *card,
1757 - enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1773 + enum qeth_sbp_roles *role, enum qeth_sbp_states *state,
1774 + bool *os_mismatch)
1758 1775 {
1759 1776 struct qeth_cmd_buffer *iob;
1760 1777 struct _qeth_sbp_cbctl cbctl = {
@@ -1762,6 +1779,7 @@ int qeth_bridgeport_query_ports(struct qeth_card *card,
1762 1779 .qports = {
1763 1780 .role = role,
1764 1781 .state = state,
1782 + .os_mismatch = os_mismatch,
1765 1783 },
1766 1784 },
1767 1785 };
modified drivers/s390/net/qeth_l2_sys.c
@@ -15,6 +15,7 @@ static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
15 15 {
16 16 struct qeth_card *card = dev_get_drvdata(dev);
17 17 enum qeth_sbp_states state = QETH_SBP_STATE_INACTIVE;
18 + bool os_mismatch = false;
18 19 int rc = 0;
19 20 char *word;
20 21
@@ -25,7 +26,7 @@ static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
25 26 if (qeth_card_hw_is_reachable(card) &&
26 27 card->options.sbp.supported_funcs)
27 28 rc = qeth_bridgeport_query_ports(card,
28 - &card->options.sbp.role, &state);
29 + &card->options.sbp.role, &state, &os_mismatch);
29 30 if (!rc) {
30 31 if (show_state)
31 32 switch (state) {
@@ -52,6 +53,10 @@ static ssize_t qeth_bridge_port_role_state_show(struct device *dev,
52 53 if (rc)
53 54 QETH_CARD_TEXT_(card, 2, "SBP%02x:%02x",
54 55 card->options.sbp.role, state);
56 + else if (!show_state &&
57 + card->options.sbp.role == QETH_SBP_ROLE_NONE &&
58 + os_mismatch)
59 + rc = sysfs_emit(buf, "%s (OS family mismatch)\n", word);
55 60 else
56 61 rc = sysfs_emit(buf, "%s\n", word);
57 62 }
modified drivers/thermal/thermal_sysfs.c
@@ -400,8 +400,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
400 400 struct thermal_trip_attrs *trip_attrs = &td->trip_attrs;
401 401
402 402 /* create trip type attribute */
403 - snprintf(trip_attrs->type.name, THERMAL_NAME_LENGTH,
404 - "trip_point_%d_type", i);
403 + scnprintf(trip_attrs->type.name, sizeof(trip_attrs->type.name),
404 + "trip_point_%d_type", i);
405 405
406 406 sysfs_attr_init(&trip_attrs->type.attr.attr);
407 407 trip_attrs->type.attr.attr.name = trip_attrs->type.name;
@@ -410,8 +410,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
410 410 attrs[i] = &trip_attrs->type.attr.attr;
411 411
412 412 /* create trip temp attribute */
413 - snprintf(trip_attrs->temp.name, THERMAL_NAME_LENGTH,
414 - "trip_point_%d_temp", i);
413 + scnprintf(trip_attrs->temp.name, sizeof(trip_attrs->temp.name),
414 + "trip_point_%d_temp", i);
415 415
416 416 sysfs_attr_init(&trip_attrs->temp.attr.attr);
417 417 trip_attrs->temp.attr.attr.name = trip_attrs->temp.name;
@@ -423,8 +423,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz)
423 423 }
424 424 attrs[i + tz->num_trips] = &trip_attrs->temp.attr.attr;
425 425
426 - snprintf(trip_attrs->hyst.name, THERMAL_NAME_LENGTH,
427 - "trip_point_%d_hyst", i);
426 + scnprintf(trip_attrs->hyst.name, sizeof(trip_attrs->hyst.name),
427 + "trip_point_%d_hyst", i);
428 428
429 429 sysfs_attr_init(&trip_attrs->hyst.attr.attr);
430 430 trip_attrs->hyst.attr.attr.name = trip_attrs->hyst.name;
modified drivers/tty/serial/8250/8250_port.c
@@ -3417,11 +3417,8 @@ static void __serial8250_console_write(struct uart_8250_port *up,
3417 3417 * If the console printer did not fully output the previous line, it
3418 3418 * must have been handed or taken over. Insert a newline in order to
3419 3419 * maintain clean output.
3420 - *
3421 - * Braille consoles are an exception. The serial port is not used
3422 - * for printk(). The driver is supposed to write exactly what it gets.
3423 3420 */
3424 - if (unlikely(!up->console_line_ended && !nbcon_write_context_is_braille(wctxt))) {
3421 + if (!up->console_line_ended) {
3425 3422 if (use_fifo)
3426 3423 __serial8250_console_fifo_write(up, wctxt, "\n", 1);
3427 3424 else
modified drivers/tty/serial/amba-pl011.c
@@ -2656,7 +2656,7 @@ pl011_console_write_atomic(struct console *co, struct nbcon_write_context *wctxt
2656 2656 uap, REG_CR);
2657 2657 }
2658 2658
2659 - if (unlikely(!uap->console_line_ended && !nbcon_is_braille(co)))
2659 + if (!uap->console_line_ended)
2660 2660 uart_console_write(&uap->port, "\n", 1, pl011_console_putchar);
2661 2661 uart_console_write(&uap->port, wctxt->outbuf, wctxt->len, pl011_console_putchar);
2662 2662
modified drivers/tty/serial/imx.c
@@ -2136,7 +2136,7 @@ static void imx_uart_console_write_atomic(struct console *co,
2136 2136 imx_uart_writel(sport, ucr1, UCR1);
2137 2137 imx_uart_writel(sport, old_ucr.ucr2 | UCR2_TXEN, UCR2);
2138 2138
2139 - if (unlikely(!sport->last_putchar_was_newline && !nbcon_is_braille(co)))
2139 + if (!sport->last_putchar_was_newline)
2140 2140 uart_console_write(port, "\n", 1, imx_uart_console_putchar);
2141 2141 uart_console_write(port, wctxt->outbuf, wctxt->len,
2142 2142 imx_uart_console_putchar);
modified drivers/tty/serial/sifive.c
@@ -821,7 +821,7 @@ static void sifive_serial_console_write_atomic(struct console *co,
821 821 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS);
822 822 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp);
823 823
824 - if (unlikely(!ssp->console_line_ended && !nbcon_is_braille(co)))
824 + if (!ssp->console_line_ended)
825 825 uart_console_write(port, "\n", 1, sifive_serial_console_putchar);
826 826 uart_console_write(port, wctxt->outbuf, wctxt->len,
827 827 sifive_serial_console_putchar);
modified drivers/tty/vt/vt.c
@@ -4986,8 +4986,8 @@ static int con_font_set(struct vc_data *vc, const struct console_font_op *op)
4986 4986 if (!vc->vc_sw->con_font_set)
4987 4987 return -ENOSYS;
4988 4988
4989 - if (vc_is_sel(vc))
4990 - clear_selection();
4989 + /* hide selection and cursor prior font changes */
4990 + hide_cursor(vc);
4991 4991
4992 4992 return vc->vc_sw->con_font_set(vc, &font, vpitch, op->flags);
4993 4993 }
@@ -5011,8 +5011,9 @@ static int con_font_default(struct vc_data *vc, struct console_font_op *op)
5011 5011 if (!vc->vc_sw->con_font_default)
5012 5012 return -ENOSYS;
5013 5013
5014 - if (vc_is_sel(vc))
5015 - clear_selection();
5014 + /* hide selection and cursor prior font changes */
5015 + hide_cursor(vc);
5016 +
5016 5017 int ret = vc->vc_sw->con_font_default(vc, &font, s);
5017 5018 if (ret)
5018 5019 return ret;
modified drivers/vdpa/alibaba/eni_vdpa.c
@@ -216,7 +216,10 @@ static void eni_vdpa_set_status(struct vdpa_device *vdpa, u8 status)
216 216
217 217 if (status & VIRTIO_CONFIG_S_DRIVER_OK &&
218 218 !(s & VIRTIO_CONFIG_S_DRIVER_OK)) {
219 - eni_vdpa_request_irq(eni_vdpa);
219 + if (eni_vdpa_request_irq(eni_vdpa)) {
220 + WARN_ON(1);
221 + return;
222 + }
220 223 }
221 224
222 225 vp_legacy_set_status(ldev, status);
modified drivers/vdpa/ifcvf/ifcvf_main.c
@@ -724,7 +724,8 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
724 724 if (config->device_features & ~device_features) {
725 725 IFCVF_ERR(pdev, "The provisioned features 0x%llx are not supported by this device with features 0x%llx\n",
726 726 config->device_features, device_features);
727 - return -EINVAL;
727 + ret = -EINVAL;
728 + goto err;
728 729 }
729 730 device_features &= config->device_features;
730 731 }
modified drivers/vdpa/octeon_ep/octep_vdpa_main.c
@@ -600,6 +600,8 @@ static int octep_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
600 600 ret = dev_set_name(&vdpa_dev->dev, "%s", name);
601 601 else
602 602 ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
603 + if (ret)
604 + goto vdpa_dev_put;
603 605
604 606 ret = _vdpa_register_device(&oct_vdpa->vdpa, oct_hw->nr_vring);
605 607 if (ret) {
modified drivers/vdpa/pds/vdpa_dev.c
@@ -731,6 +731,12 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
731 731
732 732 notify = vp_modern_map_vq_notify(&pdsv->vdpa_aux->vd_mdev,
733 733 i, &pdsv->vqs[i].notify_pa);
734 + if (!notify) {
735 + err = -EINVAL;
736 + dev_err(dev, "Fail to map vq notify %d\n", i);
737 + goto err_unmap;
738 + }
739 +
734 740 pds_vdpa_init_vqs_entry(pdsv, i, notify);
735 741 }
736 742
modified drivers/vdpa/solidrun/snet_main.c
@@ -418,11 +418,15 @@ static int snet_request_irqs(struct pci_dev *pdev, struct snet *snet)
418 418 snet->vqs[i]->irq_name, snet->vqs[i]);
419 419 if (ret) {
420 420 SNET_ERR(pdev, "Failed to request IRQ\n");
421 - return ret;
421 + goto err_free_irqs;
422 422 }
423 423 snet->vqs[i]->irq = irq;
424 424 }
425 425 return 0;
426 +
427 + err_free_irqs:
428 + snet_free_irqs(snet);
429 + return ret;
426 430 }
427 431
428 432 static void snet_set_status(struct vdpa_device *vdev, u8 status)
modified drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
@@ -79,10 +79,11 @@ static void vdpasim_blk_buffer_unlock(struct vdpasim_blk *blk)
79 79 static bool vdpasim_blk_check_range(struct vdpasim *vdpasim, u64 start_sector,
80 80 u64 num_sectors, u64 max_sectors)
81 81 {
82 - if (start_sector > VDPASIM_BLK_CAPACITY) {
82 + if (start_sector >= VDPASIM_BLK_CAPACITY) {
83 83 dev_dbg(&vdpasim->vdpa.dev,
84 84 "starting sector exceeds the capacity - start: 0x%llx capacity: 0x%x\n",
85 85 start_sector, VDPASIM_BLK_CAPACITY);
86 + return false;
86 87 }
87 88
88 89 if (num_sectors > max_sectors) {
modified drivers/vdpa/vdpa_sim/vdpa_sim_net.c
@@ -225,10 +225,15 @@ static void vdpasim_net_work(struct vdpasim *vdpasim)
225 225 break;
226 226 }
227 227
228 - ++tx_pkts;
229 228 read = vringh_iov_pull_iotlb(&txq->vring, &txq->out_iov,
230 229 net->buffer, PAGE_SIZE);
230 + if (read <= 0) {
231 + ++tx_errors;
232 + vdpasim_net_complete(txq, 0);
233 + continue;
234 + }
231 235
236 + ++tx_pkts;
232 237 tx_bytes += read;
233 238
234 239 if (!receive_filter(vdpasim, read)) {
modified drivers/vdpa/vdpa_user/vduse_dev.c
@@ -506,7 +506,7 @@ static void vduse_dev_reset(struct vduse_dev *dev)
506 506 }
507 507
508 508 scoped_guard(rwsem_write, &dev->rwsem) {
509 - dev->suspended = false;
509 + WRITE_ONCE(dev->suspended, false);
510 510 dev->status = 0;
511 511 dev->driver_features = 0;
512 512 dev->generation++;
@@ -567,11 +567,17 @@ static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
567 567
568 568 static void vduse_vq_kick(struct vduse_virtqueue *vq)
569 569 {
570 - guard(rwsem_read)(&vq->dev->rwsem);
571 - if (vq->dev->suspended)
570 + /*
571 + * This runs in the context of the vdpa kick_vq op, which may be
572 + * atomic (e.g. virtio-blk kicks from blk-mq dispatch under
573 + * rcu_read_lock()), so dev->rwsem must not be taken here.
574 + * dev->suspended is checked under kick_lock instead and
575 + * vduse_vdpa_suspend() cycles every kick_lock after setting it.
576 + */
577 + guard(spinlock)(&vq->kick_lock);
578 + if (READ_ONCE(vq->dev->suspended))
572 579 return;
573 580
574 - guard(spinlock)(&vq->kick_lock);
575 581 scoped_guard(spinlock_bh, &vq->ready_lock)
576 582 if (!vq->ready)
577 583 return;
@@ -946,7 +952,17 @@ static int vduse_vdpa_suspend(struct vdpa_device *vdpa)
946 952 ret = vduse_dev_msg_sync(dev, &msg);
947 953 if (ret == 0) {
948 954 scoped_guard(rwsem_write, &dev->rwsem)
949 - dev->suspended = true;
955 + WRITE_ONCE(dev->suspended, true);
956 +
957 + /*
958 + * Kicks check dev->suspended under kick_lock without taking
959 + * the rwsem: cycle each kick_lock so that no kick that has
960 + * already passed the check is still in flight after this.
961 + */
962 + for (u32 i = 0; i < dev->vq_num; i++) {
963 + spin_lock(&dev->vqs[i]->kick_lock);
964 + spin_unlock(&dev->vqs[i]->kick_lock);
965 + }
950 966
951 967 cancel_work_sync(&dev->inject);
952 968 for (u32 i = 0; i < dev->vq_num; i++)
@@ -1866,11 +1882,11 @@ static long vduse_dev_compat_ioctl(struct file *file, unsigned int cmd,
1866 1882 break;
1867 1883 }
1868 1884 default:
1869 - ret = -ENOIOCTLCMD;
1870 - break;
1885 + return vduse_dev_ioctl(file, cmd,
1886 + (unsigned long)compat_ptr(arg));
1871 1887 }
1872 1888
1873 - return vduse_dev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
1889 + return ret;
1874 1890 }
1875 1891 #else
1876 1892 #define vduse_dev_compat_ioctl compat_ptr_ioctl
@@ -2211,7 +2227,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config,
2211 2227 return false;
2212 2228 }
2213 2229
2214 - if (config->vq_align > PAGE_SIZE)
2230 + if (config->vq_align < VRING_USED_ALIGN_SIZE ||
2231 + !is_power_of_2(config->vq_align) ||
2232 + config->vq_align > PAGE_SIZE)
2215 2233 return false;
2216 2234
2217 2235 if (config->config_size > PAGE_SIZE)
modified drivers/vhost/net.c
@@ -1705,6 +1705,8 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features)
1705 1705 if (virtio_features_test_bit(features, VIRTIO_F_ACCESS_PLATFORM)) {
1706 1706 if (vhost_init_device_iotlb(&n->dev))
1707 1707 goto out_unlock;
1708 + } else {
1709 + vhost_clear_device_iotlb(&n->dev);
1708 1710 }
1709 1711
1710 1712 for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
modified drivers/vhost/scsi.c
@@ -210,7 +210,37 @@ static const int vhost_scsi_bits[] = {
210 210 #define VHOST_SCSI_MAX_EVENT 128
211 211
212 212 static unsigned vhost_scsi_max_io_vqs = 128;
213 - module_param_named(max_io_vqs, vhost_scsi_max_io_vqs, uint, 0644);
213 +
214 + static int vhost_scsi_set_max_io_vqs(const char *val,
215 + const struct kernel_param *kp)
216 + {
217 + unsigned int max_io_vqs;
218 + int ret;
219 +
220 + ret = kstrtouint(val, 0, &max_io_vqs);
221 + if (ret)
222 + return ret;
223 +
224 + if (max_io_vqs > VHOST_SCSI_MAX_IO_VQ) {
225 + pr_err("Invalid max_io_vqs of %u. Using %u.\n",
226 + max_io_vqs, VHOST_SCSI_MAX_IO_VQ);
227 + max_io_vqs = VHOST_SCSI_MAX_IO_VQ;
228 + } else if (!max_io_vqs) {
229 + pr_err("Invalid max_io_vqs of 0. Using 1.\n");
230 + max_io_vqs = 1;
231 + }
232 +
233 + WRITE_ONCE(vhost_scsi_max_io_vqs, max_io_vqs);
234 + return 0;
235 + }
236 +
237 + static const struct kernel_param_ops vhost_scsi_max_io_vqs_op = {
238 + .set = vhost_scsi_set_max_io_vqs,
239 + .get = param_get_uint,
240 + };
241 +
242 + module_param_cb(max_io_vqs, &vhost_scsi_max_io_vqs_op,
243 + &vhost_scsi_max_io_vqs, 0644);
214 244 MODULE_PARM_DESC(max_io_vqs, "Set the max number of IO virtqueues a vhost scsi device can support. The default is 128. The max is 1024.");
215 245
216 246 struct vhost_scsi_virtqueue {
@@ -2290,21 +2320,14 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
2290 2320 struct vhost_scsi_virtqueue *svq;
2291 2321 struct vhost_scsi *vs;
2292 2322 struct vhost_virtqueue **vqs;
2293 - int r = -ENOMEM, i, nvqs = vhost_scsi_max_io_vqs;
2323 + int r = -ENOMEM, i, nvqs;
2294 2324
2295 2325 vs = kvzalloc_obj(*vs);
2296 2326 if (!vs)
2297 2327 goto err_vs;
2298 2328 vs->inline_sg_cnt = vhost_scsi_inline_sg_cnt;
2299 2329
2300 - if (nvqs > VHOST_SCSI_MAX_IO_VQ) {
2301 - pr_err("Invalid max_io_vqs of %d. Using %d.\n", nvqs,
2302 - VHOST_SCSI_MAX_IO_VQ);
2303 - nvqs = VHOST_SCSI_MAX_IO_VQ;
2304 - } else if (nvqs == 0) {
2305 - pr_err("Invalid max_io_vqs of %d. Using 1.\n", nvqs);
2306 - nvqs = 1;
2307 - }
2330 + nvqs = READ_ONCE(vhost_scsi_max_io_vqs);
2308 2331 nvqs += VHOST_SCSI_VQ_IO;
2309 2332
2310 2333 vs->old_inflight = kmalloc_objs(*vs->old_inflight, nvqs,
@@ -2312,7 +2335,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
2312 2335 if (!vs->old_inflight)
2313 2336 goto err_inflight;
2314 2337
2315 - vs->vqs = kmalloc_objs(*vs->vqs, nvqs, GFP_KERNEL | __GFP_ZERO);
2338 + vs->vqs = kvzalloc_objs(*vs->vqs, nvqs);
2316 2339 if (!vs->vqs)
2317 2340 goto err_vqs;
2318 2341
@@ -2348,7 +2371,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
2348 2371 return 0;
2349 2372
2350 2373 err_local_vqs:
2351 - kfree(vs->vqs);
2374 + kvfree(vs->vqs);
2352 2375 err_vqs:
2353 2376 kfree(vs->old_inflight);
2354 2377 err_inflight:
@@ -2369,7 +2392,7 @@ static int vhost_scsi_release(struct inode *inode, struct file *f)
2369 2392 vhost_dev_stop(&vs->dev);
2370 2393 vhost_dev_cleanup(&vs->dev);
2371 2394 kfree(vs->dev.vqs);
2372 - kfree(vs->vqs);
2395 + kvfree(vs->vqs);
2373 2396 kfree(vs->old_inflight);
2374 2397 kvfree(vs);
2375 2398 return 0;
modified drivers/vhost/vdpa.c
@@ -58,9 +58,12 @@ struct vhost_vdpa {
58 58 struct cdev cdev;
59 59 atomic_t opened;
60 60 u32 nvqs;
61 + u16 vq_num_max;
61 62 int virtio_id;
62 63 int minor;
63 64 struct eventfd_ctx *config_ctx;
65 + /* Serialises vhost_vdpa_config_cb() against config_ctx being replaced. */
66 + spinlock_t config_lock;
64 67 int in_batch;
65 68 struct vdpa_iova_range range;
66 69 u32 batch_asid;
@@ -194,10 +197,12 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private)
194 197 static irqreturn_t vhost_vdpa_config_cb(void *private)
195 198 {
196 199 struct vhost_vdpa *v = private;
197 - struct eventfd_ctx *config_ctx = v->config_ctx;
200 + unsigned long flags;
198 201
199 - if (config_ctx)
200 - eventfd_signal(config_ctx);
202 + spin_lock_irqsave(&v->config_lock, flags);
203 + if (v->config_ctx)
204 + eventfd_signal(v->config_ctx);
205 + spin_unlock_irqrestore(&v->config_lock, flags);
201 206
202 207 return IRQ_HANDLED;
203 208 }
@@ -236,7 +241,9 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)
236 241 static int _compat_vdpa_reset(struct vhost_vdpa *v)
237 242 {
238 243 struct vdpa_device *vdpa = v->vdpa;
244 + const struct vdpa_config_ops *ops = vdpa->config;
239 245 u32 flags = 0;
246 + int ret;
240 247
241 248 v->suspended = false;
242 249
@@ -246,7 +253,14 @@ static int _compat_vdpa_reset(struct vhost_vdpa *v)
246 253 VDPA_RESET_F_CLEAN_MAP : 0;
247 254 }
248 255
249 - return vdpa_reset(vdpa, flags);
256 + v->vq_num_max = 0;
257 + ret = vdpa_reset(vdpa, flags);
258 + if (!ret) {
259 + /* Some backends derive the max from mutable queue state. */
260 + v->vq_num_max = ops->get_vq_num_max(vdpa);
261 + }
262 +
263 + return ret;
250 264 }
251 265
252 266 static int vhost_vdpa_reset(struct vhost_vdpa *v)
@@ -518,15 +532,22 @@ static long vhost_vdpa_get_vring_num(struct vhost_vdpa *v, u16 __user *argp)
518 532
519 533 static void vhost_vdpa_config_put(struct vhost_vdpa *v)
520 534 {
521 - if (v->config_ctx) {
522 - eventfd_ctx_put(v->config_ctx);
523 - v->config_ctx = NULL;
524 - }
535 + struct eventfd_ctx *ctx;
536 + unsigned long flags;
537 +
538 + spin_lock_irqsave(&v->config_lock, flags);
539 + ctx = v->config_ctx;
540 + v->config_ctx = NULL;
541 + spin_unlock_irqrestore(&v->config_lock, flags);
542 +
543 + if (ctx)
544 + eventfd_ctx_put(ctx);
525 545 }
526 546
527 547 static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
528 548 {
529 549 struct vdpa_callback cb;
550 + unsigned long flags;
530 551 int fd;
531 552 struct eventfd_ctx *ctx;
532 553
@@ -536,18 +557,20 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
536 557 return -EFAULT;
537 558
538 559 ctx = fd == VHOST_FILE_UNBIND ? NULL : eventfd_ctx_fdget(fd);
560 + if (IS_ERR(ctx))
561 + return PTR_ERR(ctx);
562 +
563 + spin_lock_irqsave(&v->config_lock, flags);
539 564 swap(ctx, v->config_ctx);
565 + spin_unlock_irqrestore(&v->config_lock, flags);
540 566
541 - if (!IS_ERR_OR_NULL(ctx))
567 + /*
568 + * The callback can no longer reach the old context, so this is the
569 + * last reference to it.
570 + */
571 + if (ctx)
542 572 eventfd_ctx_put(ctx);
543 573
544 - if (IS_ERR(v->config_ctx)) {
545 - long ret = PTR_ERR(v->config_ctx);
546 -
547 - v->config_ctx = NULL;
548 - return ret;
549 - }
550 -
551 574 v->vdpa->config->set_config_cb(v->vdpa, &cb);
552 575
553 576 return 0;
@@ -648,9 +671,15 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
648 671 u32 idx;
649 672 long r;
650 673
651 - r = get_user(idx, (u32 __user *)argp);
652 - if (r < 0)
653 - return r;
674 + if (cmd == VHOST_SET_VRING_NUM) {
675 + if (copy_from_user(&s, argp, sizeof(s)))
676 + return -EFAULT;
677 + idx = s.index;
678 + } else {
679 + r = get_user(idx, (u32 __user *)argp);
680 + if (r < 0)
681 + return r;
682 + }
654 683
655 684 if (idx >= v->nvqs)
656 685 return -ENOBUFS;
@@ -659,6 +688,23 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
659 688 vq = &v->vqs[idx];
660 689
661 690 switch (cmd) {
691 + case VHOST_SET_VRING_NUM:
692 + mutex_lock(&vq->mutex);
693 + if (vq->private_data) {
694 + r = -EBUSY;
695 + } else if (!s.num || s.num > 0xffff ||
696 + s.num > v->vq_num_max ||
697 + (s.num & (s.num - 1))) {
698 + r = -EINVAL;
699 + } else {
700 + vq->num = s.num;
701 + r = 0;
702 + }
703 + mutex_unlock(&vq->mutex);
704 + if (r)
705 + return r;
706 + ops->set_vq_num(vdpa, idx, s.num);
707 + return 0;
662 708 case VHOST_VDPA_SET_VRING_ENABLE:
663 709 if (copy_from_user(&s, argp, sizeof(s)))
664 710 return -EFAULT;
@@ -772,9 +818,6 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
772 818 ops->set_vq_cb(vdpa, idx, &cb);
773 819 break;
774 820
775 - case VHOST_SET_VRING_NUM:
776 - ops->set_vq_num(vdpa, idx, vq->num);
777 - break;
778 821 }
779 822
780 823 return r;
@@ -1613,6 +1656,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
1613 1656 }
1614 1657
1615 1658 atomic_set(&v->opened, 0);
1659 + spin_lock_init(&v->config_lock);
1616 1660 v->minor = minor;
1617 1661 v->vdpa = vdpa;
1618 1662 v->nvqs = vdpa->nvqs;
modified drivers/vhost/vhost.c
@@ -344,6 +344,17 @@ static void __vhost_vq_meta_reset(struct vhost_virtqueue *vq)
344 344 vq->meta_iotlb[j] = NULL;
345 345 }
346 346
347 + /* Caller must hold the virtqueue mutex. */
348 + static void vhost_vq_invalidate_access(struct vhost_virtqueue *vq)
349 + {
350 + vq->desc = NULL;
351 + vq->avail = NULL;
352 + vq->used = NULL;
353 + vq->log_used = false;
354 + vq->log_addr = -1ull;
355 + __vhost_vq_meta_reset(vq);
356 + }
357 +
347 358 static void vhost_vq_meta_reset(struct vhost_dev *d)
348 359 {
349 360 int i;
@@ -392,6 +403,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
392 403 vq->busyloop_timeout = 0;
393 404 vq->umem = NULL;
394 405 vq->iotlb = NULL;
406 + vq->iotlb_miss = NULL;
395 407 rcu_assign_pointer(vq->worker, NULL);
396 408 vhost_vring_call_reset(&vq->call_ctx);
397 409 __vhost_vq_meta_reset(vq);
@@ -1180,6 +1192,21 @@ void vhost_dev_stop(struct vhost_dev *dev)
1180 1192 }
1181 1193 EXPORT_SYMBOL_GPL(vhost_dev_stop);
1182 1194
1195 + static void vhost_free_msg_locked(struct vhost_msg_node *node)
1196 + {
1197 + if (node->vq->iotlb_miss == node)
1198 + node->vq->iotlb_miss = NULL;
1199 + kfree(node);
1200 + }
1201 +
1202 + static void vhost_free_msg(struct vhost_dev *dev,
1203 + struct vhost_msg_node *node)
1204 + {
1205 + spin_lock(&dev->iotlb_lock);
1206 + vhost_free_msg_locked(node);
1207 + spin_unlock(&dev->iotlb_lock);
1208 + }
1209 +
1183 1210 void vhost_clear_msg(struct vhost_dev *dev)
1184 1211 {
1185 1212 struct vhost_msg_node *node, *n;
@@ -1188,12 +1215,12 @@ void vhost_clear_msg(struct vhost_dev *dev)
1188 1215
1189 1216 list_for_each_entry_safe(node, n, &dev->read_list, node) {
1190 1217 list_del(&node->node);
1191 - kfree(node);
1218 + vhost_free_msg_locked(node);
1192 1219 }
1193 1220
1194 1221 list_for_each_entry_safe(node, n, &dev->pending_list, node) {
1195 1222 list_del(&node->node);
1196 - kfree(node);
1223 + vhost_free_msg_locked(node);
1197 1224 }
1198 1225
1199 1226 spin_unlock(&dev->iotlb_lock);
@@ -1602,7 +1629,7 @@ static void vhost_iotlb_notify_vq(struct vhost_dev *d,
1602 1629 vq_msg->type == VHOST_IOTLB_MISS) {
1603 1630 vhost_poll_queue(&node->vq->poll);
1604 1631 list_del(&node->node);
1605 - kfree(node);
1632 + vhost_free_msg_locked(node);
1606 1633 }
1607 1634 }
1608 1635
@@ -1816,7 +1843,7 @@ ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
1816 1843
1817 1844 ret = copy_to_iter(start, size, to);
1818 1845 if (ret != size || msg->type != VHOST_IOTLB_MISS) {
1819 - kfree(node);
1846 + vhost_free_msg(dev, node);
1820 1847 return ret;
1821 1848 }
1822 1849 vhost_enqueue_msg(dev, &dev->pending_list, node);
@@ -1848,7 +1875,19 @@ static int vhost_iotlb_miss(struct vhost_virtqueue *vq, u64 iova, int access)
1848 1875 msg->iova = iova;
1849 1876 msg->perm = access;
1850 1877
1851 - vhost_enqueue_msg(dev, &dev->read_list, node);
1878 + spin_lock(&dev->iotlb_lock);
1879 + /* VQ processing stops at the first miss until userspace resolves it. */
1880 + if (vq->iotlb_miss) {
1881 + spin_unlock(&dev->iotlb_lock);
1882 + kfree(node);
1883 + return 0;
1884 + }
1885 +
1886 + vq->iotlb_miss = node;
1887 + list_add_tail(&node->node, &dev->read_list);
1888 + spin_unlock(&dev->iotlb_lock);
1889 +
1890 + wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM);
1852 1891
1853 1892 return 0;
1854 1893 }
@@ -1918,6 +1957,13 @@ int vq_meta_prefetch(struct vhost_virtqueue *vq)
1918 1957 {
1919 1958 unsigned int num = vq->num;
1920 1959
1960 + /*
1961 + * vhost_vq_invalidate_access() clears all three addresses together.
1962 + * A single zero address may be a valid GIOVA in IOTLB mode.
1963 + */
1964 + if (!vq->desc && !vq->avail && !vq->used)
1965 + return 0;
1966 +
1921 1967 if (!vq->iotlb)
1922 1968 return 1;
1923 1969
@@ -2287,6 +2333,40 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
2287 2333 }
2288 2334 EXPORT_SYMBOL_GPL(vhost_vring_ioctl);
2289 2335
2336 + /* Caller must hold the device mutex. */
2337 + void vhost_clear_device_iotlb(struct vhost_dev *d)
2338 + {
2339 + struct vhost_iotlb *iotlb;
2340 + int i;
2341 +
2342 + iotlb = d->iotlb;
2343 + if (!iotlb)
2344 + return;
2345 +
2346 + vhost_dev_lock_vqs(d);
2347 +
2348 + /*
2349 + * vhost_dev_lock_vqs() takes all VQ mutexes in index order. Drop the
2350 + * device-wide view while they are held, then clear each per-VQ view
2351 + * and its cached ring access before releasing the locks. Workers
2352 + * cannot observe a mixed address-space state during this handoff.
2353 + */
2354 + d->iotlb = NULL;
2355 +
2356 + for (i = 0; i < d->nvqs; ++i) {
2357 + struct vhost_virtqueue *vq = d->vqs[i];
2358 +
2359 + vq->iotlb = NULL;
2360 + vhost_vq_invalidate_access(vq);
2361 + }
2362 +
2363 + vhost_dev_unlock_vqs(d);
2364 + vhost_clear_msg(d);
2365 + vhost_iotlb_free(iotlb);
2366 + wake_up_interruptible_poll(&d->wait, EPOLLIN | EPOLLRDNORM);
2367 + }
2368 + EXPORT_SYMBOL_GPL(vhost_clear_device_iotlb);
2369 +
2290 2370 int vhost_init_device_iotlb(struct vhost_dev *d)
2291 2371 {
2292 2372 struct vhost_iotlb *niotlb, *oiotlb;
@@ -2307,7 +2387,10 @@ int vhost_init_device_iotlb(struct vhost_dev *d)
2307 2387
2308 2388 mutex_lock(&vq->mutex);
2309 2389 vq->iotlb = niotlb;
2310 - __vhost_vq_meta_reset(vq);
2390 + if (oiotlb)
2391 + __vhost_vq_meta_reset(vq);
2392 + else
2393 + vhost_vq_invalidate_access(vq);
2311 2394 mutex_unlock(&vq->mutex);
2312 2395 }
2313 2396
modified drivers/vhost/vhost.h
@@ -29,6 +29,7 @@ struct vhost_work {
29 29
30 30 struct vhost_worker;
31 31 struct vhost_dev;
32 + struct vhost_msg_node;
32 33
33 34 struct vhost_worker_ops {
34 35 int (*create)(struct vhost_worker *worker, struct vhost_dev *dev,
@@ -148,6 +149,8 @@ struct vhost_virtqueue {
148 149 /* Protected by virtqueue mutex. */
149 150 struct vhost_iotlb *umem;
150 151 struct vhost_iotlb *iotlb;
152 + /* Protected by dev->iotlb_lock. */
153 + struct vhost_msg_node *iotlb_miss;
151 154 void *private_data;
152 155 VIRTIO_DECLARE_FEATURES(acked_features);
153 156 u64 acked_backend_features;
@@ -277,6 +280,7 @@ ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
277 280 int noblock);
278 281 ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
279 282 struct iov_iter *from);
283 + void vhost_clear_device_iotlb(struct vhost_dev *d);
280 284 int vhost_init_device_iotlb(struct vhost_dev *d);
281 285
282 286 void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
modified drivers/vhost/vsock.c
@@ -868,6 +868,8 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
868 868 if ((features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) {
869 869 if (vhost_init_device_iotlb(&vsock->dev))
870 870 goto err;
871 + } else {
872 + vhost_clear_device_iotlb(&vsock->dev);
871 873 }
872 874
873 875 vsock->seqpacket_allow = features & (1ULL << VIRTIO_VSOCK_F_SEQPACKET);
modified drivers/video/fbdev/atafb.c
@@ -3360,7 +3360,11 @@ static int __init atafb_probe(struct platform_device *pdev)
3360 3360 memset (screen_base, 0, external_len);
3361 3361
3362 3362 /* framebuffer in SV RAM: enable the SuperBlitter */
3363 - if (external_addr >= 0xa0000000) {
3363 + if (external_addr >= 0xa0000000 &&
3364 + ((external_pmode == FB_TYPE_PACKED_PIXELS &&
3365 + external_depth == 8) ||
3366 + (external_pmode == -1 &&
3367 + (external_depth == 16 || external_depth == 32)))) {
3364 3368 svblit_regs = ioremap(SVBLIT_REGS_PHYS, 0x100);
3365 3369 if (svblit_regs) {
3366 3370 svblit_fw = svblit_rd(SVBLIT_VERSION) & 0x1ff;
modified drivers/video/fbdev/core/fbcon.c
@@ -660,6 +660,13 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
660 660 erase &= ~0x400;
661 661 logo_height = fb_prepare_logo(info, par->rotate);
662 662 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
663 + logo_lines = min(logo_lines, rows);
664 + logo_lines = min(logo_lines, new_rows - 1);
665 + if (logo_lines <= 0) {
666 + logo_lines = 0;
667 + logo_shown = FBCON_LOGO_DONTSHOW;
668 + return;
669 + }
663 670 q = (unsigned short *) (vc->vc_origin +
664 671 vc->vc_size_row * rows);
665 672 step = logo_lines * cols;
modified drivers/video/fbdev/omap2/omapfb/displays/panel-sony-acx565akm.c
@@ -210,12 +210,13 @@ static void set_display_state(struct panel_drv_data *ddata, int enabled)
210 210
211 211 static int panel_enabled(struct panel_drv_data *ddata)
212 212 {
213 + __be32 disp_status_be;
213 214 u32 disp_status;
214 215 int enabled;
215 216
216 217 acx565akm_read(ddata, MIPID_CMD_READ_DISP_STATUS,
217 - (u8 *)&disp_status, 4);
218 - disp_status = __be32_to_cpu(disp_status);
218 + (u8 *)&disp_status_be, 4);
219 + disp_status = __be32_to_cpu(disp_status_be);
219 220 enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
220 221 dev_dbg(&ddata->spi->dev,
221 222 "LCD panel %senabled by bootloader (status 0x%04x)\n",
modified drivers/video/fbdev/ssd1307fb.c
@@ -665,6 +665,10 @@ static int ssd1307fb_probe(struct i2c_client *client)
665 665 spin_lock_init(&par->damage_lock);
666 666
667 667 par->device_info = device_get_match_data(dev);
668 + if (!par->device_info) {
669 + ret = -ENODEV;
670 + goto fb_alloc_error;
671 + }
668 672
669 673 par->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
670 674 if (IS_ERR(par->reset)) {
modified drivers/video/fbdev/vfb.c
@@ -78,6 +78,13 @@ static int vfb_pan_display(struct fb_var_screeninfo *var,
78 78 static int vfb_mmap(struct fb_info *info,
79 79 struct vm_area_struct *vma);
80 80
81 + static void vfb_destroy(struct fb_info *info)
82 + {
83 + vfree(info->screen_buffer);
84 + fb_dealloc_cmap(&info->cmap);
85 + framebuffer_release(info);
86 + }
87 +
81 88 static const struct fb_ops vfb_ops = {
82 89 .owner = THIS_MODULE,
83 90 __FB_DEFAULT_SYSMEM_OPS_RDWR,
@@ -87,6 +94,7 @@ static const struct fb_ops vfb_ops = {
87 94 .fb_pan_display = vfb_pan_display,
88 95 __FB_DEFAULT_SYSMEM_OPS_DRAW,
89 96 .fb_mmap = vfb_mmap,
97 + .fb_destroy = vfb_destroy,
90 98 };
91 99
92 100 /*
@@ -485,9 +493,6 @@ static void vfb_remove(struct platform_device *dev)
485 493
486 494 if (info) {
487 495 unregister_framebuffer(info);
488 - vfree(videomemory);
489 - fb_dealloc_cmap(&info->cmap);
490 - framebuffer_release(info);
491 496 }
492 497 }
493 498
modified drivers/virtio/virtio.c
@@ -604,8 +604,8 @@ void unregister_virtio_device(struct virtio_device *dev)
604 604 {
605 605 int index = dev->index; /* save for after device release */
606 606
607 - device_unregister(&dev->dev);
608 607 virtio_debug_device_exit(dev);
608 + device_unregister(&dev->dev);
609 609 ida_free(&virtio_index_ida, index);
610 610 }
611 611 EXPORT_SYMBOL_GPL(unregister_virtio_device);
modified drivers/virtio/virtio_input.c
@@ -49,9 +49,12 @@ static void virtinput_recv_events(struct virtqueue *vq)
49 49 le16_to_cpu(event->code),
50 50 le32_to_cpu(event->value));
51 51 spin_lock_irqsave(&vi->lock, flags);
52 + if (!vi->ready)
53 + continue;
52 54 virtinput_queue_evtbuf(vi, event);
53 55 }
54 - virtqueue_kick(vq);
56 + if (vi->ready)
57 + virtqueue_kick(vq);
55 58 }
56 59 spin_unlock_irqrestore(&vi->lock, flags);
57 60 }
@@ -331,6 +334,7 @@ err_input_register:
331 334 spin_lock_irqsave(&vi->lock, flags);
332 335 vi->ready = false;
333 336 spin_unlock_irqrestore(&vi->lock, flags);
337 + virtio_reset_device(vdev);
334 338 err_mt_init_slots:
335 339 input_free_device(vi->idev);
336 340 err_input_alloc:
@@ -350,8 +354,9 @@ static void virtinput_remove(struct virtio_device *vdev)
350 354 vi->ready = false;
351 355 spin_unlock_irqrestore(&vi->lock, flags);
352 356
353 - input_unregister_device(vi->idev);
357 + /* Callbacks use vi->idev. */
354 358 virtio_reset_device(vdev);
359 + input_unregister_device(vi->idev);
355 360 while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
356 361 kfree(buf);
357 362 vdev->config->del_vqs(vdev);
modified drivers/virtio/virtio_mmio.c
@@ -88,6 +88,9 @@ struct virtio_mmio_device {
88 88
89 89 void __iomem *base;
90 90 unsigned long version;
91 +
92 + /* True if enable_irq_wake() succeeded for the shared IRQ. */
93 + bool wake_irq_enabled;
91 94 };
92 95
93 96 /* Configuration interface */
@@ -336,11 +339,17 @@ static void vm_del_vqs(struct virtio_device *vdev)
336 339 {
337 340 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
338 341 struct virtqueue *vq, *n;
342 + int irq = platform_get_irq(vm_dev->pdev, 0);
339 343
340 344 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
341 345 vm_del_vq(vq);
342 346
343 - free_irq(platform_get_irq(vm_dev->pdev, 0), vm_dev);
347 + if (vm_dev->wake_irq_enabled) {
348 + disable_irq_wake(irq);
349 + vm_dev->wake_irq_enabled = false;
350 + }
351 +
352 + free_irq(irq, vm_dev);
344 353 }
345 354
346 355 static void vm_synchronize_cbs(struct virtio_device *vdev)
@@ -467,8 +476,9 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
467 476 if (err)
468 477 return err;
469 478
470 - if (of_property_read_bool(vm_dev->pdev->dev.of_node, "wakeup-source"))
471 - enable_irq_wake(irq);
479 + if (of_property_read_bool(vm_dev->pdev->dev.of_node, "wakeup-source") &&
480 + !enable_irq_wake(irq))
481 + vm_dev->wake_irq_enabled = true;
472 482
473 483 for (i = 0; i < nvqs; ++i) {
474 484 struct virtqueue_info *vqi = &vqs_info[i];
modified drivers/virtio/virtio_pci_common.c
@@ -120,7 +120,9 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)
120 120 if (isr & VIRTIO_PCI_ISR_CONFIG)
121 121 vp_config_changed(irq, opaque);
122 122
123 - return vp_vring_interrupt(irq, opaque);
123 + vp_vring_interrupt(irq, opaque);
124 +
125 + return IRQ_HANDLED;
124 126 }
125 127
126 128 static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
modified drivers/virtio/virtio_ring.c
@@ -1670,7 +1670,7 @@ static inline int virtqueue_add_packed(struct vring_virtqueue *vq,
1670 1670 struct scatterlist *sg;
1671 1671 unsigned int i, n, c, descs_used, err_idx, len;
1672 1672 __le16 head_flags, flags;
1673 - u16 head, id, prev, curr, avail_used_flags;
1673 + u16 head, id, prev, curr, avail_used_flags, unpub_flags;
1674 1674 int err;
1675 1675
1676 1676 START_USE(vq);
@@ -1798,15 +1798,30 @@ unmap_release:
1798 1798 curr = vq->free_head;
1799 1799
1800 1800 vq->packed.avail_used_flags = avail_used_flags;
1801 + unpub_flags = avail_used_flags ^ (1 << VRING_PACKED_DESC_F_AVAIL |
1802 + 1 << VRING_PACKED_DESC_F_USED);
1801 1803
1802 1804 for (n = 0; n < total_sg; n++) {
1803 1805 if (i == err_idx)
1804 1806 break;
1807 + /*
1808 + * The mapping loop made every descriptor but the head
1809 + * available. Stamp the previous wrap counter's AVAIL and USED
1810 + * bits on those, so that a later and shorter chain at this head
1811 + * does not leave one of them available beyond its own last
1812 + * descriptor. Marking them used instead would hand
1813 + * is_used_desc_packed() a completion we never made.
1814 + */
1815 + if (i != head)
1816 + desc[i].flags = cpu_to_le16(unpub_flags);
1805 1817 vring_unmap_extra_packed(vq, &vq->packed.desc_extra[curr]);
1806 1818 curr = vq->packed.desc_extra[curr].next;
1807 1819 i++;
1808 - if (i >= vq->packed.vring.num)
1820 + if (i >= vq->packed.vring.num) {
1809 1821 i = 0;
1822 + unpub_flags ^= 1 << VRING_PACKED_DESC_F_AVAIL |
1823 + 1 << VRING_PACKED_DESC_F_USED;
1824 + }
1810 1825 }
1811 1826
1812 1827 END_USE(vq);
@@ -1828,7 +1843,7 @@ static inline int virtqueue_add_packed_in_order(struct vring_virtqueue *vq,
1828 1843 struct scatterlist *sg;
1829 1844 unsigned int i, n, sg_count, err_idx, total_in_len = 0;
1830 1845 __le16 head_flags, flags;
1831 - u16 head, avail_used_flags;
1846 + u16 head, avail_used_flags, unpub_flags;
1832 1847 bool avail_wrap_counter;
1833 1848 int err;
1834 1849
@@ -1955,14 +1970,29 @@ unmap_release:
1955 1970 i = head;
1956 1971 vq->packed.avail_used_flags = avail_used_flags;
1957 1972 vq->packed.avail_wrap_counter = avail_wrap_counter;
1973 + unpub_flags = avail_used_flags ^ (1 << VRING_PACKED_DESC_F_AVAIL |
1974 + 1 << VRING_PACKED_DESC_F_USED);
1958 1975
1959 1976 for (n = 0; n < total_sg; n++) {
1960 1977 if (i == err_idx)
1961 1978 break;
1979 + /*
1980 + * The mapping loop made every descriptor but the head
1981 + * available. Stamp the previous wrap counter's AVAIL and USED
1982 + * bits on those, so that a later and shorter chain at this head
1983 + * does not leave one of them available beyond its own last
1984 + * descriptor. Marking them used instead would hand
1985 + * is_used_desc_packed() a completion we never made.
1986 + */
1987 + if (i != head)
1988 + desc[i].flags = cpu_to_le16(unpub_flags);
1962 1989 vring_unmap_extra_packed(vq, &vq->packed.desc_extra[i]);
1963 1990 i++;
1964 - if (i >= vq->packed.vring.num)
1991 + if (i >= vq->packed.vring.num) {
1965 1992 i = 0;
1993 + unpub_flags ^= 1 << VRING_PACKED_DESC_F_AVAIL |
1994 + 1 << VRING_PACKED_DESC_F_USED;
1995 + }
1966 1996 }
1967 1997
1968 1998 END_USE(vq);
modified drivers/virtio/virtio_vdpa.c
@@ -352,7 +352,7 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
352 352 continue;
353 353 }
354 354
355 - vqs[i] = virtio_vdpa_setup_vq(vdev, queue_idx++, vqi->callback,
355 + vqs[i] = virtio_vdpa_setup_vq(vdev, queue_idx, vqi->callback,
356 356 vqi->name, vqi->ctx);
357 357 if (IS_ERR(vqs[i])) {
358 358 err = PTR_ERR(vqs[i]);
@@ -360,7 +360,8 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
360 360 }
361 361
362 362 if (has_affinity)
363 - ops->set_vq_affinity(vdpa, i, &masks[i]);
363 + ops->set_vq_affinity(vdpa, queue_idx, &masks[i]);
364 + queue_idx++;
364 365 }
365 366
366 367 cb.callback = virtio_vdpa_config_cb;
modified drivers/watchdog/msc313e_wdt.c
@@ -31,20 +31,36 @@ struct msc313e_wdt_priv {
31 31 struct clk *clk;
32 32 };
33 33
34 + static u32 msc313e_wdt_get_hw_timeout(struct msc313e_wdt_priv *priv)
35 + {
36 + u16 low, high;
37 +
38 + low = readw(priv->base + REG_WDT_MAX_PRD_L);
39 + high = readw(priv->base + REG_WDT_MAX_PRD_H);
40 +
41 + return ((u32)high << 16) | low;
42 + }
43 +
44 + static void msc313e_wdt_set_hw_timeout(struct msc313e_wdt_priv *priv,
45 + unsigned int timeout)
46 + {
47 + u32 t = timeout * clk_get_rate(priv->clk);
48 +
49 + writew(t & 0xffff, priv->base + REG_WDT_MAX_PRD_L);
50 + writew((t >> 16) & 0xffff, priv->base + REG_WDT_MAX_PRD_H);
51 + writew(1, priv->base + REG_WDT_CLR);
52 + }
53 +
34 54 static int msc313e_wdt_start(struct watchdog_device *wdev)
35 55 {
36 56 struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
37 - u32 timeout;
38 57 int err;
39 58
40 59 err = clk_prepare_enable(priv->clk);
41 60 if (err)
42 61 return err;
43 62
44 - timeout = wdev->timeout * clk_get_rate(priv->clk);
45 - writew(timeout & 0xffff, priv->base + REG_WDT_MAX_PRD_L);
46 - writew((timeout >> 16) & 0xffff, priv->base + REG_WDT_MAX_PRD_H);
47 - writew(1, priv->base + REG_WDT_CLR);
63 + msc313e_wdt_set_hw_timeout(priv, wdev->timeout);
48 64 return 0;
49 65 }
50 66
@@ -69,9 +85,13 @@ static int msc313e_wdt_stop(struct watchdog_device *wdev)
69 85
70 86 static int msc313e_wdt_settimeout(struct watchdog_device *wdev, unsigned int new_time)
71 87 {
88 + struct msc313e_wdt_priv *priv = watchdog_get_drvdata(wdev);
89 +
72 90 wdev->timeout = new_time;
73 91
74 - return msc313e_wdt_start(wdev);
92 + if (watchdog_hw_running(wdev) || watchdog_active(wdev))
93 + msc313e_wdt_set_hw_timeout(priv, wdev->timeout);
94 + return 0;
75 95 }
76 96
77 97 static const struct watchdog_info msc313e_wdt_ident = {
@@ -97,6 +117,8 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
97 117 {
98 118 struct device *dev = &pdev->dev;
99 119 struct msc313e_wdt_priv *priv;
120 + unsigned long rate;
121 + int ret;
100 122
101 123 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
102 124 if (!priv)
@@ -116,27 +138,51 @@ static int msc313e_wdt_probe(struct platform_device *pdev)
116 138 priv->wdev.ops = &msc313e_wdt_ops,
117 139 priv->wdev.parent = dev;
118 140 priv->wdev.min_timeout = MSC313E_WDT_MIN_TIMEOUT;
119 - priv->wdev.max_timeout = U32_MAX / clk_get_rate(priv->clk);
141 + rate = clk_get_rate(priv->clk);
142 + if (!rate)
143 + return -EINVAL;
144 + priv->wdev.max_timeout = U32_MAX / rate;
120 145 priv->wdev.timeout = MSC313E_WDT_DEFAULT_TIMEOUT;
121 146
122 - /* If the period is non-zero the WDT is running */
123 - if (readw(priv->base + REG_WDT_MAX_PRD_L) | (readw(priv->base + REG_WDT_MAX_PRD_H) << 16))
124 - set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
125 -
126 147 watchdog_set_drvdata(&priv->wdev, priv);
148 + platform_set_drvdata(pdev, priv);
127 149
128 150 watchdog_init_timeout(&priv->wdev, timeout, dev);
129 151 watchdog_stop_on_reboot(&priv->wdev);
130 152 watchdog_stop_on_unregister(&priv->wdev);
153 + watchdog_stop_ping_on_suspend(&priv->wdev);
154 +
155 + ret = clk_prepare_enable(priv->clk);
156 + if (ret)
157 + return ret;
158 +
159 + /* If the period is non-zero the WDT is running */
160 + if (msc313e_wdt_get_hw_timeout(priv)) {
161 + msc313e_wdt_set_hw_timeout(priv, priv->wdev.timeout);
162 + set_bit(WDOG_HW_RUNNING, &priv->wdev.status);
163 + /*
164 + * Keep the clock enabled. The watchdog core will skip the next
165 + * start() and a future stop() will balance the CCF reference
166 + * count.
167 + */
168 + } else {
169 + clk_disable_unprepare(priv->clk);
170 + }
171 +
172 + ret = devm_watchdog_register_device(dev, &priv->wdev);
173 +
174 + /* If the WDT is running and anything goes wrong, disable the clock. */
175 + if (ret && test_bit(WDOG_HW_RUNNING, &priv->wdev.status))
176 + clk_disable_unprepare(priv->clk);
131 177
132 - return devm_watchdog_register_device(dev, &priv->wdev);
178 + return ret;
133 179 }
134 180
135 181 static int __maybe_unused msc313e_wdt_suspend(struct device *dev)
136 182 {
137 183 struct msc313e_wdt_priv *priv = dev_get_drvdata(dev);
138 184
139 - if (watchdog_active(&priv->wdev))
185 + if (watchdog_active(&priv->wdev) || watchdog_hw_running(&priv->wdev))
140 186 msc313e_wdt_stop(&priv->wdev);
141 187
142 188 return 0;
@@ -146,7 +192,7 @@ static int __maybe_unused msc313e_wdt_resume(struct device *dev)
146 192 {
147 193 struct msc313e_wdt_priv *priv = dev_get_drvdata(dev);
148 194
149 - if (watchdog_active(&priv->wdev))
195 + if (watchdog_active(&priv->wdev) || watchdog_hw_running(&priv->wdev))
150 196 msc313e_wdt_start(&priv->wdev);
151 197
152 198 return 0;
modified drivers/watchdog/sunxi_wdt.c
@@ -128,6 +128,38 @@ static int sunxi_wdt_ping(struct watchdog_device *wdt_dev)
128 128 return 0;
129 129 }
130 130
131 + static bool sunxi_wdt_is_running(struct watchdog_device *wdt_dev)
132 + {
133 + struct sunxi_wdt_dev *sunxi_wdt = watchdog_get_drvdata(wdt_dev);
134 + const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs;
135 +
136 + return readl(sunxi_wdt->wdt_base + regs->wdt_mode) & WDT_MODE_EN;
137 + }
138 +
139 + static unsigned int sunxi_wdt_get_timeout(struct watchdog_device *wdt_dev)
140 + {
141 + struct sunxi_wdt_dev *sunxi_wdt = watchdog_get_drvdata(wdt_dev);
142 + const struct sunxi_wdt_reg *regs = sunxi_wdt->wdt_regs;
143 + unsigned int timeout;
144 + u32 interval;
145 +
146 + interval = readl(sunxi_wdt->wdt_base + regs->wdt_mode);
147 + interval >>= regs->wdt_timeout_shift;
148 + interval &= WDT_TIMEOUT_MASK;
149 + /* Round the 0.5-second interval up to the minimum representable timeout. */
150 + if (!interval)
151 + return WDT_MIN_TIMEOUT;
152 +
153 + for (timeout = WDT_MIN_TIMEOUT;
154 + timeout < ARRAY_SIZE(wdt_timeout_map); timeout++) {
155 + if (wdt_timeout_map[timeout] == interval)
156 + return timeout;
157 + }
158 +
159 + /* Reserved interval encoding. */
160 + return 0;
161 + }
162 +
131 163 static int sunxi_wdt_set_timeout(struct watchdog_device *wdt_dev,
132 164 unsigned int timeout)
133 165 {
@@ -259,6 +291,7 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
259 291 {
260 292 struct device *dev = &pdev->dev;
261 293 struct sunxi_wdt_dev *sunxi_wdt;
294 + unsigned int running_timeout;
262 295 int err;
263 296
264 297 sunxi_wdt = devm_kzalloc(dev, sizeof(*sunxi_wdt), GFP_KERNEL);
@@ -286,7 +319,17 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
286 319
287 320 watchdog_set_drvdata(&sunxi_wdt->wdt_dev, sunxi_wdt);
288 321
289 - sunxi_wdt_stop(&sunxi_wdt->wdt_dev);
322 + if (sunxi_wdt_is_running(&sunxi_wdt->wdt_dev)) {
323 + running_timeout = sunxi_wdt_get_timeout(&sunxi_wdt->wdt_dev);
324 + if (running_timeout)
325 + sunxi_wdt->wdt_dev.timeout = running_timeout;
326 +
327 + err = sunxi_wdt_start(&sunxi_wdt->wdt_dev);
328 + if (err)
329 + return err;
330 +
331 + set_bit(WDOG_HW_RUNNING, &sunxi_wdt->wdt_dev.status);
332 + }
290 333
291 334 watchdog_stop_on_reboot(&sunxi_wdt->wdt_dev);
292 335 err = devm_watchdog_register_device(dev, &sunxi_wdt->wdt_dev);
modified drivers/watchdog/watchdog_hrtimer_pretimeout.c
@@ -30,6 +30,7 @@ void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)
30 30 void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
31 31 {
32 32 if (!(wdd->info->options & WDIOF_PRETIMEOUT) &&
33 + wdd->pretimeout &&
33 34 !watchdog_pretimeout_invalid(wdd, wdd->pretimeout))
34 35 hrtimer_start(&wdd->wd_data->pretimeout_timer,
35 36 ktime_set(wdd->timeout - wdd->pretimeout, 0),
modified fs/adfs/super.c
@@ -92,10 +92,7 @@ static int adfs_checkdiscrecord(struct adfs_discrecord *dr)
92 92
93 93 static void adfs_put_super(struct super_block *sb)
94 94 {
95 - struct adfs_sb_info *asb = ADFS_SB(sb);
96 -
97 95 adfs_free_map(sb);
98 - kfree_rcu(asb, rcu);
99 96 }
100 97
101 98 static int adfs_show_options(struct seq_file *seq, struct dentry *root)
@@ -365,7 +362,7 @@ static int adfs_fill_super(struct super_block *sb, struct fs_context *fc)
365 362 ret = -EINVAL;
366 363 }
367 364 if (ret)
368 - goto error;
365 + return ret;
369 366
370 367 /* set up enough so that we can read an inode */
371 368 sb->s_op = &adfs_sops;
@@ -406,15 +403,9 @@ static int adfs_fill_super(struct super_block *sb, struct fs_context *fc)
406 403 if (!sb->s_root) {
407 404 adfs_free_map(sb);
408 405 adfs_error(sb, "get root inode failed\n");
409 - ret = -EIO;
410 - goto error;
406 + return -EIO;
411 407 }
412 408 return 0;
413 -
414 - error:
415 - sb->s_fs_info = NULL;
416 - kfree(asb);
417 - return ret;
418 409 }
419 410
420 411 static int adfs_get_tree(struct fs_context *fc)
@@ -465,10 +456,19 @@ static int adfs_init_fs_context(struct fs_context *fc)
465 456 return 0;
466 457 }
467 458
459 + static void adfs_kill_sb(struct super_block *sb)
460 + {
461 + struct adfs_sb_info *asb = ADFS_SB(sb);
462 +
463 + kill_block_super(sb);
464 +
465 + kfree_rcu(asb, rcu);
466 + }
467 +
468 468 static struct file_system_type adfs_fs_type = {
469 469 .owner = THIS_MODULE,
470 470 .name = "adfs",
471 - .kill_sb = kill_block_super,
471 + .kill_sb = adfs_kill_sb,
472 472 .fs_flags = FS_REQUIRES_DEV,
473 473 .init_fs_context = adfs_init_fs_context,
474 474 .parameters = adfs_param_spec,
modified fs/afs/addr_list.c
@@ -394,8 +394,11 @@ void afs_set_peer_appdata(struct afs_server *server,
394 394 struct rxrpc_peer *pn = new_alist->addrs[n].peer;
395 395 struct rxrpc_peer *po = old_alist->addrs[o].peer;
396 396
397 - if (pn == po)
397 + if (pn == po) {
398 + n++;
399 + o++;
398 400 continue;
401 + }
399 402 if (pn < po) {
400 403 rxrpc_kernel_set_peer_data(pn, data);
401 404 n++;
modified fs/afs/dir_edit.c
@@ -442,7 +442,7 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
442 442 /* Check and clear the entry. */
443 443 de = &block->dirents[slot];
444 444 if (de->u.valid != 1)
445 - goto error_unmap;
445 + goto error;
446 446
447 447 trace_afs_edit_dir(vnode, why, afs_edit_dir_delete, b, slot,
448 448 ntohl(de->u.vnode), ntohl(de->u.unique),
@@ -458,7 +458,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
458 458 /* Clear the constituent entries. */
459 459 next = de->u.hash_next;
460 460 memset(de, 0, sizeof(*de) * iter.nr_slots);
461 - kunmap_local(block);
462 461
463 462 /* Adjust the hash chain: if iter->prev_entry is 0, the hashtable head
464 463 * index is previous; otherwise it's slot number of the previous entry.
@@ -485,7 +484,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
485 484 pde = &pblock->dirents[ps];
486 485 prev_next = pde->u.hash_next;
487 486 if (prev_next != htons(entry)) {
488 - kunmap_local(pblock);
489 487 pr_warn("%llx:%llx:%x: not prev in chain b=%x p=%x,%x e=%x %*s",
490 488 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique,
491 489 iter.bucket, iter.prev_entry, prev_next, entry,
@@ -493,7 +491,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
493 491 goto error;
494 492 }
495 493 pde->u.hash_next = next;
496 - kunmap_local(pblock);
497 494 }
498 495
499 496 netfs_single_mark_inode_dirty(&vnode->netfs.inode);
@@ -503,18 +500,16 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
503 500 _debug("Remove %s from %u[%u]", name->name, b, slot);
504 501
505 502 out_unmap:
503 + afs_dir_end_iter(&iter);
506 504 kunmap_local(meta);
507 505 _leave("");
508 506 return;
509 507
510 508 already_invalidated:
511 - kunmap_local(block);
512 509 trace_afs_edit_dir(vnode, why, afs_edit_dir_delete_inval,
513 510 0, 0, 0, 0, name->name);
514 511 goto out_unmap;
515 512
516 - error_unmap:
517 - kunmap_local(block);
518 513 error:
519 514 trace_afs_edit_dir(vnode, why, afs_edit_dir_delete_error,
520 515 0, 0, 0, 0, name->name);
modified fs/afs/dir_search.c
@@ -75,10 +75,7 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t bl
75 75
76 76 _enter("%zx,%d", block, slot);
77 77
78 - if (iter->block) {
79 - kunmap_local(iter->block);
80 - iter->block = NULL;
81 - }
78 + afs_dir_end_iter(iter);
82 79
83 80 if (dvnode->directory_size < blend)
84 81 goto fail;
@@ -173,12 +170,8 @@ int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name,
173 170
174 171 ret = -ENOENT;
175 172 found:
176 - if (iter->block) {
177 - kunmap_local(iter->block);
178 - iter->block = NULL;
179 - }
180 -
181 173 bad:
174 + afs_dir_end_iter(iter);
182 175 if (ret == -ESTALE)
183 176 afs_invalidate_dir(iter->dvnode, afs_dir_invalid_iter_stale);
184 177 _leave(" = %d", ret);
modified fs/afs/fs_probe.c
@@ -258,6 +258,7 @@ int afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
258 258 lockdep_is_held(&server->fs_lock));
259 259 if (old) {
260 260 estate->responsive_set = old->responsive_set;
261 + old_alist = old->addresses;
261 262 if (!new_alist)
262 263 new_alist = old->addresses;
263 264 }
modified fs/afs/internal.h
@@ -1133,6 +1133,14 @@ int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name,
1133 1133 int afs_dir_search(struct afs_vnode *dvnode, const struct qstr *name,
1134 1134 struct afs_fid *_fid, afs_dataversion_t *_dir_version);
1135 1135
1136 + static inline void afs_dir_end_iter(struct afs_dir_iter *iter)
1137 + {
1138 + if (iter->block) {
1139 + kunmap_local(iter->block);
1140 + iter->block = NULL;
1141 + }
1142 + }
1143 +
1136 1144 /*
1137 1145 * dir_silly.c
1138 1146 */
modified fs/afs/server.c
@@ -242,7 +242,6 @@ struct afs_server *afs_lookup_server(struct afs_cell *cell, struct key *key,
242 242 out:
243 243 afs_put_addrlist(alist, afs_alist_trace_put_server_create);
244 244 if (candidate) {
245 - kfree(rcu_access_pointer(server->endpoint_state));
246 245 kfree(candidate);
247 246 afs_dec_servers_outstanding(cell->net);
248 247 }
modified fs/autofs/inode.c
@@ -323,8 +323,10 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
323 323 return -ENOMEM;
324 324
325 325 root_inode = autofs_get_inode(s, S_IFDIR | 0755);
326 - if (!root_inode)
326 + if (!root_inode) {
327 + autofs_free_ino(ino);
327 328 return -ENOMEM;
329 + }
328 330
329 331 root_inode->i_uid = ctx->uid;
330 332 root_inode->i_gid = ctx->gid;
modified fs/btrfs/block-group.c
@@ -3074,21 +3074,25 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
3074 3074 return ERR_PTR(ret);
3075 3075 }
3076 3076
3077 - ret = btrfs_add_new_free_space(cache, chunk_offset, chunk_offset + size, NULL);
3078 - btrfs_free_excluded_extents(cache);
3079 - if (ret) {
3080 - btrfs_put_block_group(cache);
3081 - return ERR_PTR(ret);
3082 - }
3083 -
3084 3077 /*
3085 3078 * Ensure the corresponding space_info object is created and
3086 3079 * assigned to our block group. We want our bg to be added to the rbtree
3087 3080 * with its ->space_info set.
3081 + *
3082 + * On a zoned filesystem btrfs_add_new_free_space() ends up in
3083 + * __btrfs_add_free_space_zoned(), which dereferences
3084 + * block_group->space_info, so it has to be set beforehand.
3088 3085 */
3089 3086 cache->space_info = space_info;
3090 3087 ASSERT(cache->space_info);
3091 3088
3089 + ret = btrfs_add_new_free_space(cache, chunk_offset, chunk_offset + size, NULL);
3090 + btrfs_free_excluded_extents(cache);
3091 + if (ret) {
3092 + btrfs_put_block_group(cache);
3093 + return ERR_PTR(ret);
3094 + }
3095 +
3092 3096 ret = btrfs_add_block_group_cache(cache);
3093 3097 if (ret) {
3094 3098 btrfs_remove_free_space_cache(cache);
modified fs/btrfs/tree-checker.c
@@ -1909,6 +1909,16 @@ static int check_inode_ref(struct extent_buffer *leaf,
1909 1909 return -EUCLEAN;
1910 1910 }
1911 1911
1912 + if (unlikely(btrfs_is_fstree(btrfs_header_owner(leaf)) &&
1913 + (key->offset < BTRFS_FIRST_FREE_OBJECTID ||
1914 + key->offset > BTRFS_LAST_FREE_OBJECTID))) {
1915 + inode_ref_err(leaf, slot,
1916 + "invalid offset for ref key, have %llu expect [%llu, %lld]",
1917 + key->offset, BTRFS_FIRST_FREE_OBJECTID,
1918 + BTRFS_LAST_FREE_OBJECTID);
1919 + return -EUCLEAN;
1920 + }
1921 +
1912 1922 ptr = btrfs_item_ptr_offset(leaf, slot);
1913 1923 end = ptr + btrfs_item_size(leaf, slot);
1914 1924 while (ptr < end) {
@@ -1952,12 +1962,14 @@ static int check_inode_extref(struct extent_buffer *leaf,
1952 1962 {
1953 1963 unsigned long ptr = btrfs_item_ptr_offset(leaf, slot);
1954 1964 unsigned long end = ptr + btrfs_item_size(leaf, slot);
1965 + const bool is_fstree = btrfs_is_fstree(btrfs_header_owner(leaf));
1955 1966
1956 1967 if (unlikely(!check_prev_ino(leaf, key, slot, prev_key)))
1957 1968 return -EUCLEAN;
1958 1969
1959 1970 while (ptr < end) {
1960 1971 struct btrfs_inode_extref *extref = (struct btrfs_inode_extref *)ptr;
1972 + u64 parent;
1961 1973 u16 namelen;
1962 1974
1963 1975 if (unlikely(ptr + sizeof(*extref) > end)) {
@@ -1967,7 +1979,24 @@ static int check_inode_extref(struct extent_buffer *leaf,
1967 1979 return -EUCLEAN;
1968 1980 }
1969 1981
1982 + parent = btrfs_inode_extref_parent(leaf, extref);
1983 + if (unlikely(is_fstree && (parent < BTRFS_FIRST_FREE_OBJECTID ||
1984 + parent > BTRFS_LAST_FREE_OBJECTID))) {
1985 + inode_ref_err(leaf, slot,
1986 + "invalid parent for extref key, have %llu expect [%llu, %lld]",
1987 + parent, BTRFS_FIRST_FREE_OBJECTID,
1988 + BTRFS_LAST_FREE_OBJECTID);
1989 + return -EUCLEAN;
1990 + }
1991 +
1970 1992 namelen = btrfs_inode_extref_name_len(leaf, extref);
1993 + if (unlikely(namelen == 0 || namelen > BTRFS_NAME_LEN)) {
1994 + inode_ref_err(leaf, slot,
1995 + "invalid inode extref name length, has %u expect [1, %u]",
1996 + namelen, BTRFS_NAME_LEN);
1997 + return -EUCLEAN;
1998 + }
1999 +
1971 2000 if (unlikely(ptr + sizeof(*extref) + namelen > end)) {
1972 2001 inode_ref_err(leaf, slot,
1973 2002 "inode extref overflow, ptr %lu end %lu namelen %u",
modified fs/btrfs/tree-log.c
@@ -7286,6 +7286,22 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
7286 7286 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
7287 7287 if (ret < 0)
7288 7288 goto out;
7289 + /*
7290 + * There can't be an inode ref key with offset 0 because inode numbers
7291 + * start at BTRFS_FIRST_FREE_OBJECTID.
7292 + */
7293 + if (WARN_ON_ONCE(ret == 0)) {
7294 + btrfs_err(trans->fs_info,
7295 + "found inode ref key with offset 0 for root %llu inode %llu",
7296 + btrfs_root_id(root), ino);
7297 + ret = BTRFS_LOG_FORCE_COMMIT;
7298 + goto out;
7299 + }
7300 + /*
7301 + * Set to 0 so that in case we don't do any work below, we won't return
7302 + * 1 and trigger an unnecessary transaction commit.
7303 + */
7304 + ret = 0;
7289 7305
7290 7306 while (true) {
7291 7307 struct extent_buffer *leaf = path->nodes[0];
modified fs/cachefiles/xattr.c
@@ -13,6 +13,7 @@
13 13 #include <linux/quotaops.h>
14 14 #include <linux/xattr.h>
15 15 #include <linux/slab.h>
16 + #include <linux/unaligned.h>
16 17 #include "internal.h"
17 18
18 19 #define CACHEFILES_COOKIE_TYPE_DATA 1
@@ -50,7 +51,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
50 51
51 52 _enter("%x,#%d", object->debug_id, len);
52 53
53 - buf = kmalloc(sizeof(struct cachefiles_xattr) + len, GFP_KERNEL);
54 + buf = kmalloc(sizeof(struct cachefiles_xattr) + max(len, sizeof(__be64)), GFP_KERNEL);
54 55 if (!buf)
55 56 return -ENOMEM;
56 57
@@ -60,6 +61,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
60 61 buf->content = object->content_info;
61 62 if (test_bit(FSCACHE_COOKIE_LOCAL_WRITE, &object->cookie->flags))
62 63 buf->content = CACHEFILES_CONTENT_DIRTY;
64 + put_unaligned_be64(0, (__be64 *)buf->data);
63 65 if (len > 0)
64 66 memcpy(buf->data, fscache_get_aux(object->cookie), len);
65 67
@@ -77,8 +79,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
77 79 trace_cachefiles_vfs_error(object, file_inode(file), ret,
78 80 cachefiles_trace_setxattr_error);
79 81 trace_cachefiles_coherency(object, file_inode(file)->i_ino,
80 - be64_to_cpup((__be64 *)buf->data),
81 - buf->content,
82 + buf->data, buf->content,
82 83 cachefiles_coherency_set_fail);
83 84 if (ret != -ENOMEM)
84 85 cachefiles_io_error_obj(
@@ -86,8 +87,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
86 87 "Failed to set xattr with error %d", ret);
87 88 } else {
88 89 trace_cachefiles_coherency(object, file_inode(file)->i_ino,
89 - be64_to_cpup((__be64 *)buf->data),
90 - buf->content,
90 + buf->data, buf->content,
91 91 cachefiles_coherency_set_ok);
92 92 }
93 93
@@ -110,9 +110,10 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
110 110 int ret = -ESTALE;
111 111
112 112 tlen = sizeof(struct cachefiles_xattr) + len;
113 - buf = kmalloc(tlen, GFP_KERNEL);
113 + buf = kmalloc(sizeof(struct cachefiles_xattr) + max(len, sizeof(__be64)), GFP_KERNEL);
114 114 if (!buf)
115 115 return -ENOMEM;
116 + put_unaligned_be64(0, (__be64 *)buf->data);
116 117
117 118 xlen = cachefiles_inject_read_error();
118 119 if (xlen == 0)
@@ -148,8 +149,7 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
148 149
149 150 out:
150 151 trace_cachefiles_coherency(object, file_inode(file)->i_ino,
151 - be64_to_cpup((__be64 *)buf->data),
152 - buf->content, why);
152 + buf->data, buf->content, why);
153 153 kfree(buf);
154 154 return ret;
155 155 }
modified fs/erofs/data.c
@@ -48,7 +48,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
48 48 return NULL;
49 49 if (!buf->base)
50 50 buf->base = kmap_local_page(buf->page);
51 - return buf->base + (offset & ~PAGE_MASK);
51 + return buf->base + ((buf->off + offset) & ~PAGE_MASK);
52 52 }
53 53
54 54 int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb,
modified fs/erofs/decompressor.c
@@ -7,8 +7,6 @@
7 7 #include "compress.h"
8 8 #include <linux/lz4.h>
9 9
10 - #define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1)
11 -
12 10 static int z_erofs_load_lz4_config(struct super_block *sb,
13 11 struct erofs_super_block *dsb, void *data, int size)
14 12 {
@@ -21,8 +19,6 @@ static int z_erofs_load_lz4_config(struct super_block *sb,
21 19 erofs_err(sb, "invalid lz4 cfgs, size=%u", size);
22 20 return -EINVAL;
23 21 }
24 - distance = le16_to_cpu(lz4->max_distance);
25 -
26 22 sbi->lz4.max_pclusterblks = le16_to_cpu(lz4->max_pclusterblks);
27 23 if (!sbi->lz4.max_pclusterblks) {
28 24 sbi->lz4.max_pclusterblks = 1; /* reserved case */
@@ -39,45 +35,25 @@ static int z_erofs_load_lz4_config(struct super_block *sb,
39 35 sbi->lz4.max_pclusterblks = 1;
40 36 sbi->available_compr_algs = 1 << Z_EROFS_COMPRESSION_LZ4;
41 37 }
42 -
43 - sbi->lz4.max_distance_pages = distance ?
44 - DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
45 - LZ4_MAX_DISTANCE_PAGES;
46 38 return z_erofs_gbuf_growsize(sbi->lz4.max_pclusterblks);
47 39 }
48 40
49 41 /*
50 - * Fill all gaps with bounce pages if it's a sparse page list. Also check if
51 - * all physical pages are consecutive, which can be seen for moderate CR.
42 + * Fill all gaps with bounce pages if it's a sparse page list (for example some
43 + * folios are already uptodate and thus can be mapped into userspace). Also
44 + * check if pages are physically consecutive, which can be seen for moderate CR.
52 45 */
53 - static int z_erofs_lz4_prepare_dstpages(struct z_erofs_decompress_req *rq,
54 - struct page **pagepool)
46 + static int z_erofs_oneshot_prepare_dstpages(struct z_erofs_decompress_req *rq,
47 + struct page **pagepool)
55 48 {
56 - struct page *availables[LZ4_MAX_DISTANCE_PAGES] = { NULL };
57 - unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES,
58 - BITS_PER_LONG)] = { 0 };
59 - unsigned int lz4_max_distance_pages =
60 - EROFS_SB(rq->sb)->lz4.max_distance_pages;
61 49 void *kaddr = NULL;
62 - unsigned int i, j, top;
50 + unsigned int i;
63 51
64 - top = 0;
65 - for (i = j = 0; i < rq->outpages; ++i, ++j) {
66 - struct page *const page = rq->out[i];
67 - struct page *victim;
68 -
69 - if (j >= lz4_max_distance_pages)
70 - j = 0;
71 -
72 - /* 'valid' bounced can only be tested after a complete round */
73 - if (!rq->fillgaps && test_bit(j, bounced)) {
74 - DBG_BUGON(i < lz4_max_distance_pages);
75 - DBG_BUGON(top >= lz4_max_distance_pages);
76 - availables[top++] = rq->out[i - lz4_max_distance_pages];
77 - }
52 + for (i = 0; i < rq->outpages; ++i) {
53 + struct page *page, *victim;
78 54
55 + page = rq->out[i];
79 56 if (page) {
80 - __clear_bit(j, bounced);
81 57 if (!PageHighMem(page)) {
82 58 if (!i) {
83 59 kaddr = page_address(page);
@@ -89,21 +65,14 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erofs_decompress_req *rq,
89 65 continue;
90 66 }
91 67 }
92 - kaddr = NULL;
93 - continue;
94 - }
95 - kaddr = NULL;
96 - __set_bit(j, bounced);
97 -
98 - if (top) {
99 - victim = availables[--top];
100 68 } else {
101 69 victim = __erofs_allocpage(pagepool, rq->gfp, true);
102 70 if (!victim)
103 71 return -ENOMEM;
104 72 set_page_private(victim, Z_EROFS_SHORTLIVED_PAGE);
73 + rq->out[i] = victim;
105 74 }
106 - rq->out[i] = victim;
75 + kaddr = NULL;
107 76 }
108 77 return kaddr ? 1 : 0;
109 78 }
@@ -266,7 +235,7 @@ static const char *z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
266 235 dst_maptype = 0;
267 236 } else {
268 237 /* general decoding path which can be used for all cases */
269 - ret = z_erofs_lz4_prepare_dstpages(rq, pagepool);
238 + ret = z_erofs_oneshot_prepare_dstpages(rq, pagepool);
270 239 if (ret < 0)
271 240 return ERR_PTR(ret);
272 241 if (ret > 0) {
modified fs/erofs/decompressor_lzma.c
@@ -5,6 +5,7 @@
5 5 struct z_erofs_lzma {
6 6 struct z_erofs_lzma *next;
7 7 struct xz_dec_microlzma *state;
8 + unsigned int dict_size;
8 9 u8 bounce[PAGE_SIZE];
9 10 };
10 11
@@ -128,11 +129,19 @@ again:
128 129 err = 0;
129 130 /* 2. walk each isolated stream and grow max dict_size if needed */
130 131 for (strm = head; strm; strm = strm->next) {
132 + struct xz_dec_microlzma *state;
133 +
134 + if (strm->dict_size >= dict_size)
135 + continue;
136 + state = xz_dec_microlzma_alloc(XZ_PREALLOC, dict_size);
137 + if (!state) {
138 + err = -ENOMEM;
139 + break;
140 + }
131 141 if (strm->state)
132 142 xz_dec_microlzma_end(strm->state);
133 - strm->state = xz_dec_microlzma_alloc(XZ_PREALLOC, dict_size);
134 - if (!strm->state)
135 - err = -ENOMEM;
143 + strm->state = state;
144 + strm->dict_size = dict_size;
136 145 }
137 146
138 147 /* 3. push back all to the global list and update max dict_size */
@@ -142,7 +151,8 @@ again:
142 151 spin_unlock(&z_erofs_lzma_lock);
143 152 wake_up_all(&z_erofs_lzma_wq);
144 153
145 - z_erofs_lzma_max_dictsize = dict_size;
154 + if (!err)
155 + z_erofs_lzma_max_dictsize = dict_size;
146 156 mutex_unlock(&lzma_resize_mutex);
147 157 return err;
148 158 }
modified fs/erofs/internal.h
@@ -71,12 +71,8 @@ struct erofs_dev_context {
71 71 bool flatdev;
72 72 };
73 73
74 - /* all filesystem-wide lz4 configurations */
75 74 struct erofs_sb_lz4_info {
76 - /* # of pages needed for EROFS lz4 rolling decompression */
77 - u16 max_distance_pages;
78 - /* maximum possible blocks for pclusters in the filesystem */
79 - u16 max_pclusterblks;
75 + u16 max_pclusterblks; /* maximum physical blocks for LZ4 pclusters */
80 76 };
81 77
82 78 struct erofs_xattr_prefix_item {
modified fs/erofs/sysfs.c
@@ -95,6 +95,7 @@ EROFS_ATTR_FEATURE(sb_chksum);
95 95 EROFS_ATTR_FEATURE(ztailpacking);
96 96 EROFS_ATTR_FEATURE(fragments);
97 97 EROFS_ATTR_FEATURE(dedupe);
98 + EROFS_ATTR_FEATURE(xattr_prefixes);
98 99 EROFS_ATTR_FEATURE(48bit);
99 100 EROFS_ATTR_FEATURE(metabox);
100 101
@@ -108,6 +109,7 @@ static struct attribute *erofs_feat_attrs[] = {
108 109 ATTR_LIST(ztailpacking),
109 110 ATTR_LIST(fragments),
110 111 ATTR_LIST(dedupe),
112 + ATTR_LIST(xattr_prefixes),
111 113 ATTR_LIST(48bit),
112 114 ATTR_LIST(metabox),
113 115 NULL,
modified fs/erofs/xattr.c
@@ -620,8 +620,8 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp,
620 620 {
621 621 struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
622 622 struct erofs_xattr_prefix_item *prefix;
623 + int domainlen, valuelen, base_index;
623 624 const char *infix;
624 - int valuelen, base_index;
625 625
626 626 if (!test_opt(&sbi->opt, INODE_SHARE))
627 627 return -EOPNOTSUPP;
@@ -633,17 +633,18 @@ int erofs_xattr_fill_inode_fingerprint(struct erofs_inode_fingerprint *fp,
633 633 valuelen = erofs_getxattr(inode, base_index, infix, NULL, 0);
634 634 if (valuelen <= 0 || valuelen > (1 << sbi->blkszbits))
635 635 return -EFSCORRUPTED;
636 - fp->size = valuelen + (domain_id ? strlen(domain_id) : 0);
636 + domainlen = strlen(domain_id);
637 + fp->size = domainlen + 1 + valuelen;
637 638 fp->opaque = kmalloc(fp->size, GFP_KERNEL);
638 639 if (!fp->opaque)
639 640 return -ENOMEM;
641 + memcpy(fp->opaque, domain_id, domainlen + 1);
640 642 if (valuelen != erofs_getxattr(inode, base_index, infix,
641 - fp->opaque, valuelen)) {
643 + fp->opaque + domainlen + 1, valuelen)) {
642 644 kfree(fp->opaque);
643 645 fp->opaque = NULL;
644 646 return -EFSCORRUPTED;
645 647 }
646 - memcpy(fp->opaque + valuelen, domain_id, fp->size - valuelen);
647 648 return 0;
648 649 }
649 650 #endif
modified fs/erofs/zdata.c
@@ -1259,7 +1259,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio)
1259 1259 const struct z_erofs_decompressor *alg =
1260 1260 z_erofs_decomp[pcl->algorithmformat];
1261 1261 bool try_free = true;
1262 - int i, j, jtop, err2, err = eio ? -EIO : 0;
1262 + int i, err2, err = eio ? -EIO : 0;
1263 1263 struct page *page;
1264 1264 bool overlapped;
1265 1265 const char *reason;
@@ -1348,7 +1348,6 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio)
1348 1348 be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)
1349 1349 kvfree(be->compressed_pages);
1350 1350
1351 - jtop = 0;
1352 1351 z_erofs_fill_other_copies(be, err);
1353 1352 for (i = 0; i < be->nr_pages; ++i) {
1354 1353 page = be->decompressed_pages[i];
@@ -1356,22 +1355,11 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio)
1356 1355 continue;
1357 1356
1358 1357 DBG_BUGON(z_erofs_page_is_invalidated(page));
1359 - if (!z_erofs_is_shortlived_page(page)) {
1358 + if (!z_erofs_is_shortlived_page(page))
1360 1359 erofs_onlinefolio_end(page_folio(page), err, true);
1361 - continue;
1362 - }
1363 - if (pcl->algorithmformat != Z_EROFS_COMPRESSION_LZ4) {
1360 + else
1364 1361 erofs_pagepool_add(be->pagepool, page);
1365 - continue;
1366 - }
1367 - for (j = 0; j < jtop && be->decompressed_pages[j] != page; ++j)
1368 - ;
1369 - if (j >= jtop) /* this bounce page is newly detected */
1370 - be->decompressed_pages[jtop++] = page;
1371 1362 }
1372 - while (jtop)
1373 - erofs_pagepool_add(be->pagepool,
1374 - be->decompressed_pages[--jtop]);
1375 1363 if (be->decompressed_pages != be->onstack_pages)
1376 1364 kvfree(be->decompressed_pages);
1377 1365
modified fs/exec.c
@@ -1164,6 +1164,20 @@ int begin_new_exec(struct linux_binprm * bprm)
1164 1164 if (retval)
1165 1165 goto out;
1166 1166
1167 + /*
1168 + * We have to apply CLOEXEC before we change whether the process is
1169 + * dumpable (in setup_new_exec) to avoid a race with a process in userspace
1170 + * trying to access the should-be-closed file descriptors of a process
1171 + * undergoing exec(2).
1172 + *
1173 + * This can block on filesystem ->flush() handlers, including waiting
1174 + * for FUSE daemons, so do it before exec_mmap takes the
1175 + * exec_update_lock.
1176 + * This must happen after the point of no return, and after unsharing
1177 + * the FD table.
1178 + */
1179 + do_close_on_exec(me->files);
1180 +
1167 1181 /*
1168 1182 * Must be called _before_ exec_mmap() as bprm->mm is
1169 1183 * not visible until then. Doing it here also ensures
@@ -1214,14 +1228,6 @@ int begin_new_exec(struct linux_binprm * bprm)
1214 1228
1215 1229 clear_syscall_work_syscall_user_dispatch(me);
1216 1230
1217 - /*
1218 - * We have to apply CLOEXEC before we change whether the process is
1219 - * dumpable (in setup_new_exec) to avoid a race with a process in userspace
1220 - * trying to access the should-be-closed file descriptors of a process
1221 - * undergoing exec(2).
1222 - */
1223 - do_close_on_exec(me->files);
1224 -
1225 1231 if (bprm->secureexec) {
1226 1232 /* Make sure parent cannot signal privileged process. */
1227 1233 me->pdeath_signal = 0;
@@ -1472,9 +1478,9 @@ static void free_bprm(struct linux_binprm *bprm)
1472 1478 /* exec swapped the mm but failed before setup_new_exec() freed it */
1473 1479 if (bprm->old_mm)
1474 1480 exec_mm_put_old(bprm->old_mm);
1475 - do_close_execat(bprm->file);
1476 1481 /* An unconsumed PT_INTERP substitute from a binfmt_misc loader entry. */
1477 1482 bprm_drop_loader(bprm);
1483 + do_close_execat(bprm->file);
1478 1484 do_close_execat(bprm->executable);
1479 1485 /* If a binfmt changed the interp, free it. */
1480 1486 if (bprm->interp != bprm->filename)
modified fs/ext4/inode.c
@@ -6456,9 +6456,10 @@ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks)
6456 6456 int ext4_mark_iloc_dirty(handle_t *handle,
6457 6457 struct inode *inode, struct ext4_iloc *iloc)
6458 6458 {
6459 + struct super_block *sb = inode->i_sb;
6459 6460 int err = 0;
6460 6461
6461 - err = ext4_emergency_state(inode->i_sb);
6462 + err = ext4_emergency_state(sb);
6462 6463 if (unlikely(err)) {
6463 6464 put_bh(iloc->bh);
6464 6465 return err;
@@ -6473,9 +6474,13 @@ int ext4_mark_iloc_dirty(handle_t *handle,
6473 6474 put_bh(iloc->bh);
6474 6475 /*
6475 6476 * Mark that there's metadata writeout pending for the inode so that it
6476 - * gets properly flushed on fsync(2) and similar.
6477 + * gets properly flushed on fsync(2) and similar. We don't bother for
6478 + * fastcommit replay as that flushes the whole bdev afterwards anyway.
6479 + * It is faster this way and we avoid entering fs writeback paths which
6480 + * aren't fully initialized yet.
6477 6481 */
6478 - if (!EXT4_SB(inode->i_sb)->s_journal) {
6482 + if (!ext4_handle_valid(handle) &&
6483 + !(EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) {
6479 6484 /*
6480 6485 * Inode didn't need to go through dirtying, make sure it is
6481 6486 * attached to wb so that writeback can handle it.
modified fs/netfs/buffered_read.c
@@ -54,6 +54,42 @@ static void netfs_rreq_expand(struct netfs_io_request *rreq,
54 54 }
55 55 }
56 56
57 + /*
58 + * Drop the folio refs acquired from the readahead API.
59 + */
60 + static void netfs_bulk_drop_ra_refs(struct netfs_io_request *rreq)
61 + {
62 + struct folio_batch fbatch;
63 + struct folio *folio;
64 + pgoff_t nr_pages = DIV_ROUND_UP(rreq->len, PAGE_SIZE);
65 + pgoff_t first = rreq->start / PAGE_SIZE;
66 + XA_STATE(xas, &rreq->mapping->i_pages, first);
67 +
68 + folio_batch_init(&fbatch);
69 +
70 + rcu_read_lock();
71 +
72 + xas_for_each(&xas, folio, first + nr_pages - 1) {
73 + if (xas_retry(&xas, folio))
74 + continue;
75 +
76 + if (!folio_batch_add(&fbatch, folio))
77 + folio_batch_release(&fbatch);
78 + }
79 +
80 + rcu_read_unlock();
81 + folio_batch_release(&fbatch);
82 + trace_netfs_rreq(rreq, netfs_rreq_trace_ra_put_ref);
83 + clear_bit_unlock(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags);
84 + wake_up(&rreq->waitq);
85 + }
86 +
87 + static void netfs_maybe_bulk_drop_ra_refs(struct netfs_io_request *rreq)
88 + {
89 + if (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
90 + netfs_bulk_drop_ra_refs(rreq);
91 + }
92 +
57 93 /*
58 94 * Begin an operation, and fetch the stored zero point value from the cookie if
59 95 * available.
@@ -74,12 +110,8 @@ static int netfs_begin_cache_read(struct netfs_io_request *rreq, struct netfs_in
74 110 *
75 111 * Returns the limited size if successful and -ENOMEM if insufficient memory
76 112 * available.
77 - *
78 - * [!] NOTE: This must be run in the same thread as ->issue_read() was called
79 - * in as we access the readahead_control struct.
80 113 */
81 - static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq,
82 - struct readahead_control *ractl)
114 + static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)
83 115 {
84 116 struct netfs_io_request *rreq = subreq->rreq;
85 117 size_t rsize = subreq->len;
@@ -87,30 +119,6 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq,
87 119 if (subreq->source == NETFS_DOWNLOAD_FROM_SERVER)
88 120 rsize = umin(rsize, rreq->io_streams[0].sreq_max_len);
89 121
90 - if (ractl) {
91 - /* If we don't have sufficient folios in the rolling buffer,
92 - * extract a folioq's worth from the readahead region at a time
93 - * into the buffer. Note that this acquires a ref on each page
94 - * that we will need to release later - but we don't want to do
95 - * that until after we've started the I/O.
96 - */
97 - struct folio_batch put_batch;
98 -
99 - folio_batch_init(&put_batch);
100 - while (rreq->submitted < subreq->start + rsize) {
101 - ssize_t added;
102 -
103 - added = rolling_buffer_load_from_ra(&rreq->buffer, ractl,
104 - &put_batch);
105 - if (added < 0) {
106 - folio_batch_release(&put_batch);
107 - return added;
108 - }
109 - rreq->submitted += added;
110 - }
111 - folio_batch_release(&put_batch);
112 - }
113 -
114 122 subreq->len = rsize;
115 123 if (unlikely(rreq->io_streams[0].sreq_max_segs)) {
116 124 size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
@@ -203,17 +211,68 @@ static void netfs_issue_read(struct netfs_io_request *rreq,
203 211 }
204 212 }
205 213
214 + /*
215 + * Mark folios that we want to copy to the cache. For filesystems that use
216 + * netfslib fully, we set folio->private to NETFS_FOLIO_COPY_TO_CACHE;
217 + * otherwise we set the deprecated PG_private_2.
218 + */
219 + static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,
220 + struct folio_queue **fq,
221 + unsigned int *offset,
222 + int *slot,
223 + size_t len,
224 + bool copy)
225 + {
226 + while (len > 0) {
227 + struct folio *folio;
228 + size_t fsize, overlap;
229 +
230 + if (!*fq)
231 + break;
232 + if (*slot >= folioq_count(*fq)) {
233 + *fq = (*fq)->next;
234 + *slot = 0;
235 + *offset = 0;
236 + continue;
237 + }
238 +
239 + /* Determine how much the subreq overlaps the folio, if at all. */
240 + fsize = folioq_folio_size(*fq, *slot);
241 + overlap = min(len, fsize - *offset);
242 +
243 + if (overlap > 0 && copy) {
244 + folio = folioq_folio(*fq, *slot);
245 + if (unlikely(test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags))) {
246 + if (!folio_test_private_2(folio))
247 + folio_start_private_2(folio);
248 + } else {
249 + if (!folio_get_private(folio))
250 + folio_attach_private(folio, NETFS_FOLIO_COPY_TO_CACHE);
251 + }
252 + trace_netfs_folio(folio, netfs_folio_trace_mark_copy);
253 + }
254 +
255 + len -= overlap;
256 + *offset += overlap;
257 + if (*offset >= fsize) {
258 + *slot += 1;
259 + *offset = 0;
260 + }
261 + }
262 + }
263 +
206 264 /*
207 265 * Perform a read to the pagecache from a series of sources of different types,
208 266 * slicing up the region to be read according to available cache blocks and
209 267 * network rsize.
210 268 */
211 - static void netfs_read_to_pagecache(struct netfs_io_request *rreq,
212 - struct readahead_control *ractl)
269 + static void netfs_read_to_pagecache(struct netfs_io_request *rreq)
213 270 {
271 + struct folio_queue *fq = rreq->buffer.tail;
214 272 unsigned long long start = rreq->start;
273 + unsigned int offset = 0;
215 274 ssize_t size = rreq->len;
216 - int ret = 0;
275 + int ret = 0, slot = 0;
217 276
218 277 do {
219 278 struct netfs_io_subrequest *subreq;
@@ -288,7 +347,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq,
288 347 break;
289 348
290 349 issue:
291 - slice = netfs_prepare_read_iterator(subreq, ractl);
350 + slice = netfs_prepare_read_iterator(subreq);
292 351 if (slice < 0) {
293 352 ret = slice;
294 353 netfs_cancel_read(subreq, ret);
@@ -301,7 +360,15 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq,
301 360 set_bit(NETFS_RREQ_ALL_QUEUED, &rreq->flags);
302 361 }
303 362
363 + if (fq) {
364 + /* See if the cache indicated this should be cached. */
365 + bool copy = test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags);
366 +
367 + netfs_mark_copy_to_cache(rreq, &fq, &slot, &offset, slice, copy);
368 + }
369 +
304 370 netfs_issue_read(rreq, subreq);
371 + netfs_maybe_bulk_drop_ra_refs(rreq);
305 372
306 373 if (test_bit(NETFS_RREQ_PAUSE, &rreq->flags))
307 374 netfs_wait_for_paused_read(rreq);
@@ -339,7 +406,8 @@ void netfs_readahead(struct readahead_control *ractl)
339 406 {
340 407 struct netfs_io_request *rreq;
341 408 struct netfs_inode *ictx = netfs_inode(ractl->mapping->host);
342 - unsigned long long start = readahead_pos(ractl);
409 + ssize_t added;
410 + uoff_t start = readahead_pos(ractl);
343 411 size_t size = readahead_length(ractl);
344 412 int ret;
345 413
@@ -360,11 +428,24 @@ void netfs_readahead(struct readahead_control *ractl)
360 428
361 429 netfs_rreq_expand(rreq, ractl);
362 430
363 - rreq->submitted = rreq->start;
364 - if (rolling_buffer_init(&rreq->buffer, rreq->debug_id, ITER_DEST, rreq->gfp) < 0)
431 + /* Load the folios to be read into a bvecq chain. Note that this
432 + * acquires a ref on each folio that we will need to release later -
433 + * but we don't want to do that until after we've started the I/O.
434 + */
435 + added = rolling_buffer_bulk_load_from_ra(&rreq->buffer, ractl,
436 + rreq->debug_id, rreq->gfp);
437 + if (added < 0) {
438 + ret = added;
365 439 goto cleanup_free;
366 - netfs_read_to_pagecache(rreq, ractl);
440 + }
441 + __set_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags);
442 +
443 + rreq->submitted = rreq->start + added;
444 + rreq->cleaned_to = rreq->start;
445 + netfs_read_set_unlock_at(rreq);
367 446
447 + netfs_read_to_pagecache(rreq);
448 + netfs_maybe_bulk_drop_ra_refs(rreq);
368 449 return netfs_put_request(rreq, netfs_rreq_trace_put_return);
369 450
370 451 cleanup_free:
@@ -387,6 +468,7 @@ static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct fo
387 468 if (added < 0)
388 469 return added;
389 470 rreq->submitted = rreq->start + added;
471 + rreq->progress_at = added;
390 472 return 0;
391 473 }
392 474
@@ -457,7 +539,7 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)
457 539 iov_iter_bvec(&rreq->buffer.iter, ITER_DEST, bvec, i, rreq->len);
458 540 rreq->submitted = rreq->start + flen;
459 541
460 - netfs_read_to_pagecache(rreq, NULL);
542 + netfs_read_to_pagecache(rreq);
461 543
462 544 ret = netfs_wait_for_read(rreq);
463 545 if (ret >= 0) {
@@ -532,7 +614,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)
532 614 if (ret < 0)
533 615 goto discard;
534 616
535 - netfs_read_to_pagecache(rreq, NULL);
617 + netfs_read_to_pagecache(rreq);
536 618 ret = netfs_wait_for_read(rreq);
537 619 netfs_put_request(rreq, netfs_rreq_trace_put_return);
538 620 return ret < 0 ? ret : 0;
@@ -689,7 +771,7 @@ retry:
689 771 if (ret < 0)
690 772 goto error_put;
691 773
692 - netfs_read_to_pagecache(rreq, NULL);
774 + netfs_read_to_pagecache(rreq);
693 775 ret = netfs_wait_for_read(rreq);
694 776 netfs_put_request(rreq, netfs_rreq_trace_put_return);
695 777 if (ret < 0)
@@ -754,7 +836,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,
754 836 if (ret < 0)
755 837 goto error_put;
756 838
757 - netfs_read_to_pagecache(rreq, NULL);
839 + netfs_read_to_pagecache(rreq);
758 840 ret = netfs_wait_for_read(rreq);
759 841 netfs_put_request(rreq, netfs_rreq_trace_put_return);
760 842 return ret < 0 ? ret : 0;
modified fs/netfs/direct_write.c
@@ -21,7 +21,7 @@ static void netfs_unbuffered_write_done(struct netfs_io_request *wreq)
21 21 /* Okay, declare that all I/O is complete. */
22 22 trace_netfs_rreq(wreq, netfs_rreq_trace_write_done);
23 23
24 - if (!wreq->error)
24 + if (wreq->transferred)
25 25 netfs_update_i_size(ictx, &ictx->inode, wreq->start, wreq->transferred);
26 26
27 27 if (wreq->origin == NETFS_DIO_WRITE &&
@@ -51,7 +51,7 @@ static void netfs_unbuffered_write_done(struct netfs_io_request *wreq)
51 51 wreq->iocb->ki_pos += written;
52 52 if (wreq->iocb->ki_complete) {
53 53 trace_netfs_rreq(wreq, netfs_rreq_trace_ki_complete);
54 - wreq->iocb->ki_complete(wreq->iocb, wreq->error ?: written);
54 + wreq->iocb->ki_complete(wreq->iocb, written ?: wreq->error);
55 55 }
56 56 wreq->iocb = VFS_PTR_POISON;
57 57 }
@@ -95,7 +95,7 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
95 95 {
96 96 struct netfs_io_subrequest *subreq = NULL;
97 97 struct netfs_io_stream *stream = &wreq->io_streams[0];
98 - int ret;
98 + int ret = 0;
99 99
100 100 _enter("%llx", wreq->len);
101 101
@@ -110,6 +110,11 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
110 110 if (!subreq) {
111 111 netfs_prepare_write(wreq, stream, wreq->start + wreq->transferred);
112 112 subreq = stream->construct;
113 + if (!subreq) {
114 + wreq->error = -ENOMEM;
115 + ret = -ENOMEM;
116 + break;
117 + }
113 118 stream->construct = NULL;
114 119 }
115 120
@@ -121,8 +126,14 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
121 126 }
122 127
123 128 iov_iter_truncate(&subreq->io_iter, wreq->len - wreq->transferred);
124 - if (!iov_iter_count(&subreq->io_iter))
129 + if (!iov_iter_count(&subreq->io_iter)) {
130 + pr_warn("netfs: Unexpected zero-length iterator R=%08x\n",
131 + wreq->debug_id);
132 + __set_bit(NETFS_SREQ_FAILED, &subreq->flags);
133 + netfs_write_subrequest_terminated(subreq, -EIO);
134 + wreq->error = -EIO;
125 135 break;
136 + }
126 137
127 138 subreq->len = netfs_limit_iter(&subreq->io_iter, 0,
128 139 stream->sreq_max_len,
@@ -139,13 +150,11 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
139 150 if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
140 151 retry = true;
141 152 } else if (test_bit(NETFS_SREQ_FAILED, &subreq->flags)) {
142 - ret = subreq->error;
143 - wreq->error = ret;
153 + wreq->error = subreq->error;
144 154 netfs_see_subrequest(subreq, netfs_sreq_trace_see_failed);
145 155 subreq = NULL;
146 156 break;
147 157 }
148 - ret = 0;
149 158
150 159 if (!retry) {
151 160 netfs_unbuffered_write_collect(wreq, stream, subreq);
@@ -288,11 +297,11 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *
288 297 ret = -EIOCBQUEUED;
289 298 } else {
290 299 ret = netfs_unbuffered_write(wreq);
291 - if (ret < 0) {
292 - _debug("begin = %zd", ret);
293 - } else {
300 + if (wreq->transferred) {
294 301 iocb->ki_pos += wreq->transferred;
295 - ret = wreq->transferred ?: wreq->error;
302 + ret = wreq->transferred;
303 + } else if (wreq->error) {
304 + ret = wreq->error;
296 305 }
297 306
298 307 netfs_put_request(wreq, netfs_rreq_trace_put_complete);
modified fs/netfs/internal.h
@@ -79,6 +79,7 @@ ssize_t netfs_wait_for_read(struct netfs_io_request *rreq);
79 79 ssize_t netfs_wait_for_write(struct netfs_io_request *rreq);
80 80 void netfs_wait_for_paused_read(struct netfs_io_request *rreq);
81 81 void netfs_wait_for_paused_write(struct netfs_io_request *rreq);
82 + void netfs_wait_for_put_ra_refs(struct netfs_io_request *rreq);
82 83
83 84 /*
84 85 * objects.c
@@ -109,6 +110,8 @@ static inline void netfs_see_subrequest(struct netfs_io_subrequest *subreq,
109 110 /*
110 111 * read_collect.c
111 112 */
113 + void netfs_cancel_copy_to_cache(struct netfs_io_request *rreq, struct folio *folio);
114 + void netfs_read_set_unlock_at(struct netfs_io_request *rreq);
112 115 bool netfs_read_collection(struct netfs_io_request *rreq);
113 116 void netfs_read_collection_worker(struct work_struct *work);
114 117 void netfs_cancel_read(struct netfs_io_subrequest *subreq, int error);
modified fs/netfs/misc.c
@@ -563,3 +563,22 @@ void netfs_wait_for_paused_write(struct netfs_io_request *rreq)
563 563 {
564 564 return netfs_wait_for_pause(rreq, netfs_write_collection);
565 565 }
566 +
567 + /*
568 + * Wait for the readahead-acquired refs to be put.
569 + */
570 + void netfs_wait_for_put_ra_refs(struct netfs_io_request *rreq)
571 + {
572 + DEFINE_WAIT(myself);
573 +
574 + for (;;) {
575 + trace_netfs_rreq(rreq, netfs_rreq_trace_wait_put_ra_refs);
576 + prepare_to_wait(&rreq->waitq, &myself, TASK_UNINTERRUPTIBLE);
577 + if (!test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
578 + break;
579 + schedule();
580 + }
581 +
582 + trace_netfs_rreq(rreq, netfs_rreq_trace_waited_put_ra_refs);
583 + finish_wait(&rreq->waitq, &myself);
584 + }
modified fs/netfs/objects.c
@@ -41,24 +41,32 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
41 41
42 42 memset(rreq, 0, kmem_cache_size(cache));
43 43 INIT_WORK(&rreq->cleanup_work, netfs_free_request);
44 - rreq->gfp = gfp;
45 - rreq->start = start;
46 - rreq->len = len;
47 - rreq->origin = origin;
48 - rreq->netfs_ops = ctx->ops;
49 - rreq->mapping = mapping;
50 - rreq->inode = inode;
51 - rreq->i_size = i_size_read(inode);
52 - rreq->debug_id = atomic_inc_return(&debug_ids);
53 - rreq->wsize = INT_MAX;
44 + rreq->gfp = gfp;
45 + rreq->start = start;
46 + rreq->collected_to = start;
47 + rreq->cleaned_to = start;
48 + rreq->len = len;
49 + rreq->progress_at = 0;
50 + rreq->origin = origin;
51 + rreq->netfs_ops = ctx->ops;
52 + rreq->mapping = mapping;
53 + rreq->inode = inode;
54 + rreq->i_size = i_size_read(inode);
55 + rreq->debug_id = atomic_inc_return(&debug_ids);
56 + rreq->wsize = INT_MAX;
54 57 rreq->io_streams[0].sreq_max_len = ULONG_MAX;
55 58 rreq->io_streams[0].sreq_max_segs = 0;
56 59 spin_lock_init(&rreq->lock);
57 - INIT_LIST_HEAD(&rreq->io_streams[0].subrequests);
58 - INIT_LIST_HEAD(&rreq->io_streams[1].subrequests);
59 60 init_waitqueue_head(&rreq->waitq);
60 61 refcount_set(&rreq->ref, 2);
61 62
63 + for (int s = 0; s < NR_IO_STREAMS; s++) {
64 + struct netfs_io_stream *stream = &rreq->io_streams[s];
65 +
66 + INIT_LIST_HEAD(&stream->subrequests);
67 + stream->collected_to = rreq->start;
68 + }
69 +
62 70 if (origin == NETFS_READAHEAD ||
63 71 origin == NETFS_READPAGE ||
64 72 origin == NETFS_READ_GAPS ||
modified fs/netfs/read_collect.c
@@ -19,7 +19,6 @@
19 19 #define MADE_PROGRESS 0x04 /* Made progress cleaning up a stream or the folio set */
20 20 #define BUFFERED 0x08 /* The pagecache needs cleaning up */
21 21 #define NEED_RETRY 0x10 /* A front op requests retrying */
22 - #define COPY_TO_CACHE 0x40 /* Need to copy subrequest to cache */
23 22 #define ABANDON_SREQ 0x80 /* Need to abandon untransferred part of subrequest */
24 23
25 24 /*
@@ -34,6 +33,30 @@ static void netfs_clear_unread(struct netfs_io_subrequest *subreq)
34 33 __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
35 34 }
36 35
36 + /*
37 + * Cancel the copy-to-cache mark on a folio.
38 + */
39 + void netfs_cancel_copy_to_cache(struct netfs_io_request *rreq, struct folio *folio)
40 + {
41 + if (!test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags)) {
42 + if (folio_get_private(folio) == NETFS_FOLIO_COPY_TO_CACHE) {
43 + folio_detach_private(folio);
44 + trace_netfs_folio(folio, netfs_folio_trace_cancel_copy);
45 + } else if (netfs_folio_group(folio) == NETFS_FOLIO_COPY_TO_CACHE) {
46 + struct netfs_folio *finfo = netfs_folio_info(folio);
47 +
48 + finfo->netfs_group = NULL;
49 + trace_netfs_folio(folio, netfs_folio_trace_cancel_copy);
50 + }
51 + } else {
52 + // TODO: Use of PG_private_2 is deprecated.
53 + if (folio_test_private_2(folio)) {
54 + folio_end_private_2(folio);
55 + trace_netfs_folio(folio, netfs_folio_trace_cancel_copy);
56 + }
57 + }
58 + }
59 +
37 60 /*
38 61 * Flush, mark and unlock a folio that's now completely read. If we want to
39 62 * cache the folio, we set the group to NETFS_FOLIO_COPY_TO_CACHE, mark it
@@ -48,37 +71,37 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,
48 71
49 72 if (unlikely(folio_pos(folio) < rreq->abandon_to)) {
50 73 trace_netfs_folio(folio, netfs_folio_trace_abandon);
74 + netfs_cancel_copy_to_cache(rreq, folio);
51 75 goto just_unlock;
52 76 }
53 77
54 78 flush_dcache_folio(folio);
55 79 folio_mark_uptodate(folio);
56 80
57 - if (!test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags)) {
58 - finfo = netfs_folio_info(folio);
59 - if (finfo) {
60 - trace_netfs_folio(folio, netfs_folio_trace_filled_gaps);
61 - if (finfo->netfs_group)
62 - folio_change_private(folio, finfo->netfs_group);
63 - else
64 - folio_detach_private(folio);
65 - kfree(finfo);
66 - }
81 + if (unlikely(test_bit(NETFS_RREQ_CANCEL_CACHING, &rreq->flags)))
82 + netfs_cancel_copy_to_cache(rreq, folio);
67 83
68 - if (test_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &rreq->flags)) {
69 - if (!WARN_ON_ONCE(folio_get_private(folio) != NULL)) {
70 - trace_netfs_folio(folio, netfs_folio_trace_copy_to_cache);
71 - folio_attach_private(folio, NETFS_FOLIO_COPY_TO_CACHE);
72 - folio_mark_dirty(folio);
73 - }
84 + if (!test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags)) {
85 + if (netfs_folio_group(folio) == NETFS_FOLIO_COPY_TO_CACHE) {
86 + trace_netfs_folio(folio, netfs_folio_trace_sched_copy);
87 + folio_mark_dirty(folio);
74 88 } else {
89 + finfo = netfs_folio_info(folio);
90 + if (finfo) {
91 + trace_netfs_folio(folio, netfs_folio_trace_filled_gaps);
92 + if (finfo->netfs_group)
93 + folio_change_private(folio, finfo->netfs_group);
94 + else
95 + folio_detach_private(folio);
96 + kfree(finfo);
97 + }
75 98 trace_netfs_folio(folio, netfs_folio_trace_read_done);
76 99 }
77 100
78 101 folioq_clear(folioq, slot);
79 102 } else {
80 103 // TODO: Use of PG_private_2 is deprecated.
81 - if (test_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &rreq->flags))
104 + if (folio_test_private_2(folio))
82 105 netfs_pgpriv2_copy_to_cache(rreq, folio);
83 106 }
84 107
@@ -94,6 +117,35 @@ just_unlock:
94 117 folioq_clear(folioq, slot);
95 118 }
96 119
120 + /*
121 + * Determine how much to gather before unlocking more folios.
122 + */
123 + void netfs_read_set_unlock_at(struct netfs_io_request *rreq)
124 + {
125 + struct folio_queue *folioq = rreq->buffer.tail;
126 + unsigned int slot = rreq->buffer.first_tail_slot;
127 + size_t cleaned_to = rreq->cleaned_to - rreq->start;
128 + size_t progress_at = cleaned_to;
129 + size_t minimum = 256 * 1024;
130 +
131 + while (progress_at < rreq->len) {
132 + if (slot >= folioq_count(folioq)) {
133 + folioq = folioq->next;
134 + if (!folioq)
135 + break;
136 + slot = 0;
137 + }
138 +
139 + progress_at += folioq_folio_size(folioq, slot);
140 + if (progress_at - cleaned_to >= minimum)
141 + break;
142 + slot++;
143 + }
144 +
145 + WRITE_ONCE(rreq->progress_at, progress_at);
146 + trace_netfs_read_progress_at(rreq);
147 + }
148 +
97 149 /*
98 150 * Unlock any folios we've finished with.
99 151 */
@@ -112,30 +164,31 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
112 164 if (slot >= folioq_nr_slots(folioq)) {
113 165 folioq = rolling_buffer_delete_spent(&rreq->buffer);
114 166 if (!folioq) {
115 - rreq->front_folio_order = 0;
167 + WRITE_ONCE(rreq->progress_at, rreq->len);
116 168 return;
117 169 }
118 170 slot = 0;
119 171 }
120 172
173 + /* We have to wait for readahead refs to have been released before we
174 + * can unlock any folios as the ref-dropper walks i_pages and the only
175 + * thing preventing these folios from being removed is the folio lock.
176 + */
177 + if (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
178 + netfs_wait_for_put_ra_refs(rreq);
179 +
121 180 for (;;) {
122 181 struct folio *folio;
123 182 unsigned long long fpos, fend;
124 - unsigned int order;
125 183 size_t fsize;
126 184
127 - if (*notes & COPY_TO_CACHE)
128 - set_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &rreq->flags);
129 -
130 185 folio = folioq_folio(folioq, slot);
131 186 if (WARN_ONCE(!folio_test_locked(folio),
132 187 "R=%08x: folio %lx is not locked\n",
133 188 rreq->debug_id, folio->index))
134 189 trace_netfs_folio(folio, netfs_folio_trace_not_locked);
135 190
136 - order = folioq_folio_order(folioq, slot);
137 - rreq->front_folio_order = order;
138 - fsize = PAGE_SIZE << order;
191 + fsize = folioq_folio_size(folioq, slot);
139 192 fpos = folio_pos(folio);
140 193 fend = fpos + fsize;
141 194
@@ -149,8 +202,6 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
149 202 WRITE_ONCE(rreq->cleaned_to, fpos + fsize);
150 203 *notes |= MADE_PROGRESS;
151 204
152 - clear_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &rreq->flags);
153 -
154 205 /* Clean up the head folioq. If we clear an entire folioq, then
155 206 * we can get rid of it provided it's not also the tail folioq
156 207 * being filled by the issuer.
@@ -172,6 +223,8 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,
172 223 rreq->buffer.tail = folioq;
173 224 done:
174 225 rreq->buffer.first_tail_slot = slot;
226 +
227 + netfs_read_set_unlock_at(rreq);
175 228 }
176 229
177 230 /*
@@ -232,7 +285,7 @@ reassess:
232 285 * subreqs.
233 286 */
234 287 if (notes & BUFFERED) {
235 - size_t fsize = PAGE_SIZE << rreq->front_folio_order;
288 + uoff_t unlock_at = rreq->start + rreq->progress_at;
236 289
237 290 /* Clear the tail of a short read. */
238 291 if (!(notes & HIT_PENDING) &&
@@ -248,16 +301,13 @@ reassess:
248 301 stream->collected_to = front->start + transferred;
249 302 rreq->collected_to = stream->collected_to;
250 303
251 - if (test_bit(NETFS_SREQ_COPY_TO_CACHE, &front->flags))
252 - notes |= COPY_TO_CACHE;
253 -
254 304 if (test_bit(NETFS_SREQ_FAILED, &front->flags)) {
255 305 rreq->abandon_to = front->start + front->len;
256 306 front->transferred = front->len;
257 307 transferred = front->len;
258 308 trace_netfs_rreq(rreq, netfs_rreq_trace_set_abandon);
259 309 }
260 - if (front->start + transferred >= rreq->cleaned_to + fsize ||
310 + if (front->start + transferred >= unlock_at ||
261 311 test_bit(NETFS_SREQ_HIT_EOF, &front->flags))
262 312 netfs_read_unlock_folios(rreq, &notes);
263 313 } else {
@@ -477,20 +527,22 @@ void netfs_read_collection_worker(struct work_struct *work)
477 527 void netfs_read_subreq_progress(struct netfs_io_subrequest *subreq)
478 528 {
479 529 struct netfs_io_request *rreq = subreq->rreq;
480 - struct netfs_io_stream *stream = &rreq->io_streams[0];
481 - size_t fsize = PAGE_SIZE << rreq->front_folio_order;
482 -
483 - trace_netfs_sreq(subreq, netfs_sreq_trace_progress);
530 + struct netfs_io_stream *stream = &rreq->io_streams[subreq->stream_nr];
531 + size_t progress_at = READ_ONCE(rreq->progress_at);
532 + uoff_t update_at = rreq->start + progress_at;
533 + uoff_t transferred_to = subreq->start + subreq->transferred;
484 534
485 535 /* If we are at the head of the queue, wake up the collector,
486 536 * getting a ref to it if we were the ones to do so.
487 537 */
488 - if (subreq->start + subreq->transferred > rreq->cleaned_to + fsize &&
538 + if (progress_at < rreq->len &&
539 + transferred_to >= update_at &&
489 540 (rreq->origin == NETFS_READAHEAD ||
490 541 rreq->origin == NETFS_READPAGE ||
491 542 rreq->origin == NETFS_READ_FOR_WRITE) &&
492 543 list_is_first(&subreq->rreq_link, &stream->subrequests)
493 544 ) {
545 + trace_netfs_sreq(subreq, netfs_sreq_trace_progress);
494 546 __set_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
495 547 netfs_wake_collector(rreq);
496 548 }
modified fs/netfs/read_pgpriv2.c
@@ -54,8 +54,8 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio
54 54
55 55 /* Attach the folio to the rolling buffer. */
56 56 if (rolling_buffer_append(&creq->buffer, folio, 0, creq->gfp) < 0) {
57 + set_bit(NETFS_RREQ_CANCEL_CACHING, &creq->flags);
57 58 folio_end_private_2(folio);
58 - clear_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &creq->flags);
59 59 return;
60 60 }
61 61
@@ -122,13 +122,14 @@ cancel_put:
122 122 netfs_put_failed_request(creq);
123 123 cancel:
124 124 rreq->copy_to_cache = ERR_PTR(-ENOBUFS);
125 - clear_bit(NETFS_RREQ_FOLIO_COPY_TO_CACHE, &rreq->flags);
125 + set_bit(NETFS_RREQ_CANCEL_CACHING, &rreq->flags);
126 126 return ERR_PTR(-ENOBUFS);
127 127 }
128 128
129 129 /*
130 130 * [DEPRECATED] Mark page as requiring copy-to-cache using PG_private_2 and add
131 - * it to the copy write request.
131 + * it to the copy write request. PG_private_2 should already be set on the
132 + * folio.
132 133 */
133 134 void netfs_pgpriv2_copy_to_cache(struct netfs_io_request *rreq, struct folio *folio)
134 135 {
@@ -136,11 +137,13 @@ void netfs_pgpriv2_copy_to_cache(struct netfs_io_request *rreq, struct folio *fo
136 137
137 138 if (!creq)
138 139 creq = netfs_pgpriv2_begin_copy_to_cache(rreq, folio);
139 - if (IS_ERR(creq))
140 + if (IS_ERR(creq)) {
141 + set_bit(NETFS_RREQ_CANCEL_CACHING, &rreq->flags);
142 + netfs_cancel_copy_to_cache(rreq, folio);
140 143 return;
144 + }
141 145
142 - trace_netfs_folio(folio, netfs_folio_trace_copy_to_cache);
143 - folio_start_private_2(folio);
146 + trace_netfs_folio(folio, netfs_folio_trace_pgpriv2_copy);
144 147 netfs_pgpriv2_copy_folio(creq, folio);
145 148 }
146 149
modified fs/netfs/read_retry.c
@@ -292,11 +292,22 @@ void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
292 292 {
293 293 struct folio_queue *p;
294 294
295 + /* We have to wait for readahead refs to have been released before we
296 + * can unlock any folios as the ref-dropper walks i_pages and the only
297 + * thing preventing these folios from being removed is the folio lock.
298 + */
299 + if (test_bit(NETFS_RREQ_NEED_PUT_RA_REFS, &rreq->flags))
300 + netfs_wait_for_put_ra_refs(rreq);
301 +
295 302 for (p = rreq->buffer.tail; p; p = p->next) {
296 303 for (int slot = 0; slot < folioq_count(p); slot++) {
297 304 struct folio *folio = folioq_folio(p, slot);
298 305
299 - if (folio && !folioq_is_marked2(p, slot)) {
306 + if (!folio)
307 + continue;
308 + netfs_cancel_copy_to_cache(rreq, folio);
309 +
310 + if (!folioq_is_marked2(p, slot)) {
300 311 if (folio == rreq->no_unlock_folio &&
301 312 test_bit(NETFS_RREQ_NO_UNLOCK_FOLIO,
302 313 &rreq->flags)) {
modified fs/netfs/read_single.c
@@ -170,6 +170,8 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_ite
170 170 if (IS_ERR(rreq))
171 171 return PTR_ERR(rreq);
172 172
173 + rreq->progress_at = rreq->len;
174 +
173 175 ret = netfs_single_begin_cache_read(rreq, ictx);
174 176 if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS)
175 177 goto cleanup_free;
modified fs/netfs/rolling_buffer.c
@@ -115,42 +115,65 @@ int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp)
115 115 }
116 116
117 117 /*
118 - * Decant the list of folios to read into a rolling buffer.
118 + * Decant the entire list of folios to read into a rolling buffer.
119 119 */
120 - ssize_t rolling_buffer_load_from_ra(struct rolling_buffer *roll,
121 - struct readahead_control *ractl,
122 - struct folio_batch *put_batch)
120 + ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
121 + struct readahead_control *ractl,
122 + unsigned int rreq_id, gfp_t gfp)
123 123 {
124 124 struct folio_queue *fq;
125 - struct page **vec;
126 - int nr, ix, to;
127 - ssize_t size = 0;
125 + ssize_t loaded = 0;
128 126
129 - if (rolling_buffer_make_space(roll, GFP_KERNEL) < 0)
130 - return -ENOMEM;
127 + while (ractl->_nr_pages - ractl->_batch_count > 0) {
128 + unsigned int nr;
131 129
132 - fq = roll->head;
133 - vec = (struct page **)fq->vec.folios;
134 - nr = __readahead_batch(ractl, vec + folio_batch_count(&fq->vec),
135 - folio_batch_space(&fq->vec));
136 - ix = fq->vec.nr;
137 - to = ix + nr;
138 - fq->vec.nr = to;
139 - for (; ix < to; ix++) {
140 - struct folio *folio = folioq_folio(fq, ix);
141 - unsigned int order = folio_order(folio);
142 -
143 - fq->orders[ix] = order;
144 - size += PAGE_SIZE << order;
145 - trace_netfs_folio(folio, netfs_folio_trace_read);
146 - if (!folio_batch_add(put_batch, folio))
147 - folio_batch_release(put_batch);
130 + /* Allocate a folioq to put some folios into and attach it to
131 + * the rolling buffer.
132 + */
133 + fq = netfs_folioq_alloc(rreq_id, gfp,
134 + netfs_trace_folioq_make_space);
135 + if (!fq)
136 + goto nomem_unlock;
137 + fq->prev = roll->head;
138 + if (!roll->tail)
139 + roll->tail = fq;
140 + else
141 + roll->head->next = fq;
142 + roll->head = fq;
143 +
144 + /* Get a batch of folios and note their orders. */
145 + nr = __readahead_batch(ractl, (struct page **)fq->vec.folios,
146 + folioq_nr_slots(fq));
147 + if (WARN_ON_ONCE(!nr))
148 + break;
149 + fq->vec.nr = nr;
150 +
151 + for (int slot = 0; slot < nr; slot++) {
152 + struct folio *folio = folioq_folio(fq, slot);
153 + unsigned int order;
154 +
155 + order = folio_order(folio);
156 + fq->orders[slot] = order;
157 + loaded += PAGE_SIZE << order;
158 + trace_netfs_folio(folio, netfs_folio_trace_read);
159 + }
148 160 }
149 - WRITE_ONCE(roll->iter.count, roll->iter.count + size);
150 161
151 - /* Store the counter after setting the slot. */
152 - smp_store_release(&roll->next_head_slot, to);
153 - return size;
162 + WRITE_ONCE(roll->iter.count, loaded);
163 + iov_iter_folio_queue(&roll->iter, ITER_DEST, roll->tail, 0, 0, loaded);
164 + return loaded;
165 +
166 + nomem_unlock:
167 + for (fq = roll->tail; fq; fq = fq->next) {
168 + for (int slot = 0; slot < folioq_count(fq); slot++) {
169 + folio_unlock(fq->vec.folios[slot]);
170 + folioq_mark(fq, slot);
171 + }
172 + }
173 + rolling_buffer_clear(roll);
174 + roll->head = NULL;
175 + roll->tail = NULL;
176 + return -ENOMEM;
154 177 }
155 178
156 179 /*
modified fs/netfs/write_issue.c
@@ -170,6 +170,8 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
170 170 rolling_buffer_make_space(&wreq->buffer, wreq->gfp);
171 171
172 172 subreq = netfs_alloc_subrequest(wreq);
173 + if (!subreq)
174 + return;
173 175 subreq->source = stream->source;
174 176 subreq->start = start;
175 177 subreq->stream_nr = stream->stream_nr;
modified fs/overlayfs/super.c
@@ -1543,7 +1543,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
1543 1543 struct ovl_fs *ofs = sb->s_fs_info;
1544 1544 int err;
1545 1545
1546 - err = -EIO;
1546 + err = -EINVAL;
1547 1547 /* The fscontext fd may have been passed to another user namespace. */
1548 1548 if (fc->user_ns != current_user_ns())
1549 1549 goto out_err;
modified fs/smb/client/cifsacl.c
@@ -100,8 +100,23 @@ cifs_idmap_key_destroy(struct key *key)
100 100 kfree(key->payload.data[0]);
101 101 }
102 102
103 + static int
104 + cifs_idmap_key_vet_description(const char *description)
105 + {
106 + /*
107 + * cifs.idmap descriptions are authority-bearing inputs to the
108 + * cifs.idmap upcall helper. Only allow the kernel to create this
109 + * type of key using the private root_cred installed in
110 + * init_cifs_idmap; reject userspace request_key(2)/add_key(2).
111 + */
112 + if (current_cred() != root_cred)
113 + return -EPERM;
114 + return 0;
115 + }
116 +
103 117 static struct key_type cifs_idmap_key_type = {
104 118 .name = "cifs.idmap",
119 + .vet_description = cifs_idmap_key_vet_description,
105 120 .instantiate = cifs_idmap_key_instantiate,
106 121 .destroy = cifs_idmap_key_destroy,
107 122 .describe = user_describe,
@@ -1081,13 +1096,13 @@ unsigned int setup_special_user_owner_ACE(struct smb_ace *pntace)
1081 1096 static void populate_new_aces(char *nacl_base,
1082 1097 struct smb_sid *pownersid,
1083 1098 struct smb_sid *pgrpsid,
1084 - __u64 *pnmode, u16 *pnum_aces, u16 *pnsize,
1099 + __u64 *pnmode, u16 *pnum_aces, u32 *pnsize,
1085 1100 bool modefromsid,
1086 1101 bool posix)
1087 1102 {
1088 1103 __u64 nmode;
1089 1104 u16 num_aces = 0;
1090 - u16 nsize = 0;
1105 + u32 nsize = 0;
1091 1106 __u64 user_mode;
1092 1107 __u64 group_mode;
1093 1108 __u64 other_mode;
@@ -1186,17 +1201,17 @@ set_size:
1186 1201 *pnsize = nsize;
1187 1202 }
1188 1203
1189 - static __u16 replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *pndacl,
1190 - struct smb_sid *pownersid, struct smb_sid *pgrpsid,
1191 - struct smb_sid *pnownersid, struct smb_sid *pngrpsid,
1192 - int *aclflag)
1204 + static int replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *pndacl,
1205 + struct smb_sid *pownersid, struct smb_sid *pgrpsid,
1206 + struct smb_sid *pnownersid, struct smb_sid *pngrpsid,
1207 + int *aclflag, u16 *pnsize)
1193 1208 {
1194 1209 int i;
1195 1210 u16 size = 0;
1196 1211 struct smb_ace *pntace = NULL;
1197 1212 char *acl_base = NULL;
1198 1213 u16 src_num_aces = 0;
1199 - u16 nsize = 0;
1214 + u32 nsize = 0;
1200 1215 struct smb_ace *pnntace = NULL;
1201 1216 char *nacl_base = NULL;
1202 1217 u16 ace_size = 0;
@@ -1225,9 +1240,12 @@ static __u16 replace_sids_and_copy_aces(struct smb_acl *pdacl, struct smb_acl *p
1225 1240
1226 1241 size += le16_to_cpu(pntace->size);
1227 1242 nsize += ace_size;
1243 + if (nsize > U16_MAX)
1244 + return -EOVERFLOW;
1228 1245 }
1229 1246
1230 - return nsize;
1247 + *pnsize = nsize;
1248 + return 0;
1231 1249 }
1232 1250
1233 1251 static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
@@ -1239,7 +1257,7 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
1239 1257 struct smb_ace *pntace = NULL;
1240 1258 char *acl_base = NULL;
1241 1259 u16 src_num_aces = 0;
1242 - u16 nsize = 0;
1260 + u32 nsize = 0;
1243 1261 struct smb_ace *pnntace = NULL;
1244 1262 char *nacl_base = NULL;
1245 1263 u16 num_aces = 0;
@@ -1290,6 +1308,8 @@ static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
1290 1308
1291 1309 nsize += cifs_copy_ace(pnntace, pntace, NULL);
1292 1310 num_aces++;
1311 + if (nsize > U16_MAX)
1312 + return -EOVERFLOW;
1293 1313
1294 1314 next_ace:
1295 1315 size += le16_to_cpu(pntace->size);
@@ -1306,6 +1326,10 @@ next_ace:
1306 1326 }
1307 1327
1308 1328 finalize_dacl:
1329 + /* The DACL size field is 16-bit on the wire, see MS-DTYP 2.4.5 */
1330 + if (nsize > U16_MAX)
1331 + return -EOVERFLOW;
1332 +
1309 1333 pndacl->num_aces = cpu_to_le16(num_aces);
1310 1334 pndacl->size = cpu_to_le16(nsize);
1311 1335
@@ -1331,6 +1355,7 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
1331 1355 {
1332 1356 int rc = 0;
1333 1357 struct smb_sid *owner_sid_ptr, *group_sid_ptr;
1358 + unsigned int sbflags = cifs_sb_flags(cifs_sb);
1334 1359 struct smb_acl *dacl_ptr; /* no need for SACL ptr */
1335 1360 char *end_of_acl;
1336 1361 __u32 dacloffset, osidoffset, gsidoffset;
@@ -1349,17 +1374,21 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
1349 1374 cifs_dbg(NOISY, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n",
1350 1375 pntsd->revision, pntsd->type, osidoffset, gsidoffset,
1351 1376 le32_to_cpu(pntsd->sacloffset), dacloffset);
1352 - /* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */
1377 + fattr->cf_uid = cifs_sb->ctx->linux_uid;
1378 + fattr->cf_gid = cifs_sb->ctx->linux_gid;
1379 +
1353 1380 rc = sid_from_sd(pntsd, acl_len, osidoffset, &owner_sid_ptr);
1354 1381 if (rc) {
1355 1382 cifs_dbg(FYI, "%s: Error %d parsing Owner SID\n", __func__, rc);
1356 1383 return rc;
1357 1384 }
1358 - rc = sid_to_id(cifs_sb, owner_sid_ptr, fattr, SIDOWNER);
1359 - if (rc) {
1360 - cifs_dbg(FYI, "%s: Error %d mapping Owner SID to uid\n",
1361 - __func__, rc);
1362 - return rc;
1385 + if (!(sbflags & CIFS_MOUNT_OVERR_UID)) {
1386 + rc = sid_to_id(cifs_sb, owner_sid_ptr, fattr, SIDOWNER);
1387 + if (rc) {
1388 + cifs_dbg(FYI, "%s: Error %d mapping Owner SID to uid\n",
1389 + __func__, rc);
1390 + return rc;
1391 + }
1363 1392 }
1364 1393
1365 1394 rc = sid_from_sd(pntsd, acl_len, gsidoffset, &group_sid_ptr);
@@ -1368,11 +1397,13 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
1368 1397 __func__, rc);
1369 1398 return rc;
1370 1399 }
1371 - rc = sid_to_id(cifs_sb, group_sid_ptr, fattr, SIDGROUP);
1372 - if (rc) {
1373 - cifs_dbg(FYI, "%s: Error %d mapping Group SID to gid\n",
1374 - __func__, rc);
1375 - return rc;
1400 + if (!(sbflags & CIFS_MOUNT_OVERR_GID)) {
1401 + rc = sid_to_id(cifs_sb, group_sid_ptr, fattr, SIDGROUP);
1402 + if (rc) {
1403 + cifs_dbg(FYI, "%s: Error %d mapping Group SID to gid\n",
1404 + __func__, rc);
1405 + return rc;
1406 + }
1376 1407 }
1377 1408
1378 1409 if (dacloffset) {
@@ -1451,6 +1482,8 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,
1451 1482
1452 1483 rc = set_chmod_dacl(dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr,
1453 1484 pnmode, mode_from_sid, posix);
1485 + if (rc)
1486 + return rc;
1454 1487
1455 1488 sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size);
1456 1489 /* copy the non-dacl portion of secdesc */
@@ -1526,10 +1559,12 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,
1526 1559
1527 1560 if (dacloffset) {
1528 1561 /* Replace ACEs for old owner with new one */
1529 - size = replace_sids_and_copy_aces(dacl_ptr, ndacl_ptr,
1530 - owner_sid_ptr, group_sid_ptr,
1531 - nowner_sid_ptr, ngroup_sid_ptr,
1532 - aclflag);
1562 + rc = replace_sids_and_copy_aces(dacl_ptr, ndacl_ptr,
1563 + owner_sid_ptr, group_sid_ptr,
1564 + nowner_sid_ptr, ngroup_sid_ptr,
1565 + aclflag, &size);
1566 + if (rc)
1567 + goto chown_chgrp_exit;
1533 1568 ndacl_ptr->size = cpu_to_le16(size);
1534 1569 }
1535 1570
@@ -1815,11 +1850,13 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,
1815 1850 cifs_put_tlink(tlink);
1816 1851 return rc;
1817 1852 }
1818 - if (mode_from_sid)
1819 - nsecdesclen +=
1820 - le16_to_cpu(dacl_ptr->num_aces) * sizeof(struct smb_ace);
1821 - else /* cifsacl */
1822 - nsecdesclen += le16_to_cpu(dacl_ptr->size);
1853 + /*
1854 + * Worst case: every ACE is rewritten with a new SID of
1855 + * SID_MAX_SUB_AUTHORITIES sub-auths -> sizeof(smb_ace) each,
1856 + * plus the smb_acl header replace_sids_and_copy_aces() emits.
1857 + */
1858 + nsecdesclen += sizeof(struct smb_acl) +
1859 + le16_to_cpu(dacl_ptr->num_aces) * sizeof(struct smb_ace);
1823 1860 }
1824 1861 }
1825 1862
modified fs/smb/client/cifssmb.c
@@ -1719,8 +1719,17 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
1719 1719 pSMBr = (READ_RSP *)rsp_iov.iov_base;
1720 1720 if (rc) {
1721 1721 cifs_dbg(VFS, "Send error in read = %d\n", rc);
1722 + } else if (rsp_iov.iov_len < tcon->ses->server->vals->read_rsp_size) {
1723 + /* check that the received response can hold a whole READ_RSP */
1724 + cifs_dbg(FYI, "%s: server returned short header. got=%zu expected=%zu\n",
1725 + __func__, rsp_iov.iov_len,
1726 + tcon->ses->server->vals->read_rsp_size);
1727 + rc = smb_EIO2(smb_eio_trace_read_rsp_short,
1728 + rsp_iov.iov_len, tcon->ses->server->vals->read_rsp_size);
1729 + *nbytes = 0;
1722 1730 } else {
1723 - int data_length = le16_to_cpu(pSMBr->DataLengthHigh);
1731 + unsigned int data_length = le16_to_cpu(pSMBr->DataLengthHigh);
1732 + __u16 data_offset = le16_to_cpu(pSMBr->DataOffset);
1724 1733 data_length = data_length << 16;
1725 1734 data_length += le16_to_cpu(pSMBr->DataLength);
1726 1735 *nbytes = data_length;
@@ -1728,14 +1737,21 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
1728 1737 /*check that DataLength would not go beyond end of SMB */
1729 1738 if ((data_length > CIFSMaxBufSize)
1730 1739 || (data_length > count)) {
1731 - cifs_dbg(FYI, "bad length %d for count %d\n",
1732 - data_length, count);
1740 + cifs_dbg(FYI, "%s: bad length %u for count %u\n",
1741 + __func__, data_length, count);
1733 1742 rc = smb_EIO2(smb_eio_trace_read_overlarge,
1734 1743 data_length, count);
1735 1744 *nbytes = 0;
1745 + } else if (data_offset < sizeof(*pSMBr) ||
1746 + (size_t)data_offset + data_length > rsp_iov.iov_len) {
1747 + /* check that the data lies within the received response */
1748 + cifs_dbg(FYI, "%s: bad data offset %u length %u for response of %zu\n",
1749 + __func__, data_offset, data_length, rsp_iov.iov_len);
1750 + rc = smb_EIO2(smb_eio_trace_read_bad_offset,
1751 + data_offset, data_length);
1752 + *nbytes = 0;
1736 1753 } else {
1737 - pReadData = (char *) (&pSMBr->hdr.Protocol) +
1738 - le16_to_cpu(pSMBr->DataOffset);
1754 + pReadData = (char *) (&pSMBr->hdr.Protocol) + data_offset;
1739 1755 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1740 1756 cifs_dbg(VFS, "Faulting on read rc = %d\n",rc);
1741 1757 rc = -EFAULT;
modified fs/smb/client/dfs_cache.c
@@ -123,6 +123,7 @@ static inline void free_tgts(struct cache_entry *ce)
123 123 kfree(t);
124 124 }
125 125
126 + ce->numtgts = 0;
126 127 WRITE_ONCE(ce->tgthint, NULL);
127 128 }
128 129
@@ -388,13 +389,6 @@ static int copy_ref_data(const struct dfs_info3_param *refs, int numrefs,
388 389 struct cache_dfs_tgt *target;
389 390 int i;
390 391
391 - ce->ttl = max_t(int, refs[0].ttl, CACHE_MIN_TTL);
392 - ce->etime = get_expire_time(ce->ttl);
393 - ce->srvtype = refs[0].server_type;
394 - ce->hdr_flags = refs[0].flags;
395 - ce->ref_flags = refs[0].ref_flag;
396 - ce->path_consumed = refs[0].path_consumed;
397 -
398 392 for (i = 0; i < numrefs; i++) {
399 393 struct cache_dfs_tgt *t;
400 394
@@ -409,12 +403,19 @@ static int copy_ref_data(const struct dfs_info3_param *refs, int numrefs,
409 403 } else {
410 404 list_add_tail(&t->list, &ce->tlist);
411 405 }
412 - ce->numtgts++;
413 406 }
414 407
415 408 target = list_first_entry_or_null(&ce->tlist, struct cache_dfs_tgt,
416 409 list);
410 +
417 411 WRITE_ONCE(ce->tgthint, target);
412 + ce->ttl = max_t(int, refs[0].ttl, CACHE_MIN_TTL);
413 + ce->etime = get_expire_time(ce->ttl);
414 + ce->srvtype = refs[0].server_type;
415 + ce->hdr_flags = refs[0].flags;
416 + ce->ref_flags = refs[0].ref_flag;
417 + ce->path_consumed = refs[0].path_consumed;
418 + ce->numtgts = numrefs;
418 419
419 420 return 0;
420 421 }
@@ -634,7 +635,6 @@ static int update_cache_entry_locked(struct cache_entry *ce, const struct dfs_in
634 635 }
635 636
636 637 free_tgts(ce);
637 - ce->numtgts = 0;
638 638
639 639 rc = copy_ref_data(refs, numrefs, ce, th);
640 640
modified fs/smb/client/file.c
@@ -1515,11 +1515,18 @@ int cifs_close(struct inode *inode, struct file *file)
1515 1515 trace_smb3_close_cached(tcon->tid, tcon->ses->Suid,
1516 1516 cfile->fid.persistent_fid,
1517 1517 cifs_sb->ctx->closetimeo);
1518 - queue_delayed_work(deferredclose_wq,
1519 - &cfile->deferred, cifs_sb->ctx->closetimeo);
1520 - cfile->deferred_close_scheduled = true;
1521 - spin_unlock(&cinode->deferred_lock);
1522 - return 0;
1518 + /*
1519 + * Each queued execution owns one reference.
1520 + * If nothing was queued, the reference of
1521 + * the closing file is dropped below.
1522 + */
1523 + if (queue_delayed_work(deferredclose_wq,
1524 + &cfile->deferred,
1525 + cifs_sb->ctx->closetimeo)) {
1526 + cfile->deferred_close_scheduled = true;
1527 + spin_unlock(&cinode->deferred_lock);
1528 + return 0;
1529 + }
1523 1530 }
1524 1531 spin_unlock(&cinode->deferred_lock);
1525 1532 _cifsFileInfo_put(cfile, true, false);
@@ -3348,8 +3355,11 @@ void cifs_oplock_break(struct work_struct *work)
3348 3355 TASK_UNINTERRUPTIBLE);
3349 3356
3350 3357 tlink = cifs_sb_tlink(cifs_sb);
3351 - if (IS_ERR(tlink))
3358 + if (IS_ERR(tlink)) {
3359 + /* drop the reference taken when the break was queued */
3360 + _cifsFileInfo_put(cfile, false /* do not wait for ourself */, false);
3352 3361 goto out;
3362 + }
3353 3363 tcon = tlink_tcon(tlink);
3354 3364 server = tcon->ses->server;
3355 3365
modified fs/smb/client/inode.c
@@ -851,6 +851,7 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr,
851 851 struct smb311_posix_qinfo *info = &data->posix_fi;
852 852 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
853 853 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
854 + unsigned int sbflags = cifs_sb_flags(cifs_sb);
854 855
855 856 memset(fattr, 0, sizeof(*fattr));
856 857
@@ -895,8 +896,12 @@ out_reparse:
895 896 fattr->cf_symlink_target = data->symlink_target;
896 897 data->symlink_target = NULL;
897 898 }
898 - sid_to_id(cifs_sb, &data->posix_owner, fattr, SIDOWNER);
899 - sid_to_id(cifs_sb, &data->posix_group, fattr, SIDGROUP);
899 + fattr->cf_uid = cifs_sb->ctx->linux_uid;
900 + fattr->cf_gid = cifs_sb->ctx->linux_gid;
901 + if (!(sbflags & CIFS_MOUNT_OVERR_UID))
902 + sid_to_id(cifs_sb, &data->posix_owner, fattr, SIDOWNER);
903 + if (!(sbflags & CIFS_MOUNT_OVERR_GID))
904 + sid_to_id(cifs_sb, &data->posix_group, fattr, SIDGROUP);
900 905
901 906 cifs_dbg(FYI, "POSIX query info: mode 0x%x uniqueid 0x%llx nlink %d\n",
902 907 fattr->cf_mode, fattr->cf_uniqueid, fattr->cf_nlink);
@@ -2992,14 +2997,14 @@ int cifs_getattr(struct mnt_idmap *idmap, const struct path *path,
2992 2997 stat->attributes |= STATX_ATTR_ENCRYPTED;
2993 2998
2994 2999 /*
2995 - * If on a multiuser mount without unix extensions or cifsacl being
2996 - * enabled, and the admin hasn't overridden them, set the ownership
2997 - * to the fsuid/fsgid of the current process.
3000 + * If on a multiuser mount without unix extensions, posix extensions
3001 + * or cifsacl being enabled, and the admin hasn't overridden them,
3002 + * set the ownership to the fsuid/fsgid of the current process.
2998 3003 */
2999 3004 sbflags = cifs_sb_flags(cifs_sb);
3000 3005 if ((sbflags & CIFS_MOUNT_MULTIUSER) &&
3001 3006 !(sbflags & CIFS_MOUNT_CIFS_ACL) &&
3002 - !tcon->unix_ext) {
3007 + !tcon->unix_ext && !tcon->posix_extensions) {
3003 3008 if (!(sbflags & CIFS_MOUNT_OVERR_UID))
3004 3009 stat->uid = current_fsuid();
3005 3010 if (!(sbflags & CIFS_MOUNT_OVERR_GID))
modified fs/smb/client/misc.c
@@ -378,10 +378,11 @@ void cifs_queue_oplock_break(struct cifsFileInfo *cfile)
378 378 * open_file_lock to enforce the validity of it for the oplock
379 379 * break handler. The matching put is done at the end of the
380 380 * handler.
381 + *
382 + * Only take a reference if the work is actually queued.
381 383 */
382 - cifsFileInfo_get(cfile);
383 -
384 - queue_work(cifsoplockd_wq, &cfile->oplock_break);
384 + if (queue_work(cifsoplockd_wq, &cfile->oplock_break))
385 + cifsFileInfo_get(cfile);
385 386 }
386 387
387 388 void cifs_done_oplock_break(struct cifsInodeInfo *cinode)
@@ -891,8 +892,14 @@ static void tcon_super_cb(struct super_block *sb, void *arg)
891 892 t1->ses->dfs_root_ses == t2->ses->dfs_root_ses) &&
892 893 t1->ses->server == t2->ses->server &&
893 894 t2->origin_fullpath &&
894 - dfs_src_pathname_equal(t2->origin_fullpath, t1->origin_fullpath))
895 + dfs_src_pathname_equal(t2->origin_fullpath, t1->origin_fullpath)) {
896 + /*
897 + * Take the active reference while iterate_supers_type() still
898 + * holds s_umount shared.
899 + */
900 + cifs_sb_active(sb);
895 901 sd->sb = sb;
902 + }
896 903 spin_unlock(&t2->tc_lock);
897 904 }
898 905
@@ -909,15 +916,8 @@ static struct super_block *__cifs_get_super(void (*f)(struct super_block *, void
909 916
910 917 for (; *fs_type; fs_type++) {
911 918 iterate_supers_type(*fs_type, f, &sd);
912 - if (sd.sb) {
913 - /*
914 - * Grab an active reference in order to prevent automounts (DFS links)
915 - * of expiring and then freeing up our cifs superblock pointer while
916 - * we're doing failover.
917 - */
918 - cifs_sb_active(sd.sb);
919 + if (sd.sb)
919 920 return sd.sb;
920 - }
921 921 }
922 922 pr_warn_once("%s: could not find dfs superblock\n", __func__);
923 923 return ERR_PTR(-EINVAL);
modified fs/smb/client/readdir.c
@@ -242,9 +242,11 @@ static void
242 242 cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
243 243 struct cifs_sb_info *cifs_sb)
244 244 {
245 + unsigned int sbflags = cifs_sb_flags(cifs_sb);
245 246 struct smb2_posix_info_parsed parsed;
247 + int rc;
246 248
247 - posix_info_parse(info, NULL, &parsed);
249 + rc = posix_info_parse(info, NULL, &parsed);
248 250
249 251 memset(fattr, 0, sizeof(*fattr));
250 252 fattr->cf_uniqueid = le64_to_cpu(info->Inode);
@@ -281,8 +283,17 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
281 283 le32_to_cpu(info->ReparseTag),
282 284 le32_to_cpu(info->Mode));
283 285
284 - sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER);
285 - sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP);
286 + fattr->cf_uid = cifs_sb->ctx->linux_uid;
287 + fattr->cf_gid = cifs_sb->ctx->linux_gid;
288 + if (rc < 0) {
289 + cifs_dbg(VFS, "%s: failed to parse SIDs: %d\n",
290 + __func__, rc);
291 + } else {
292 + if (!(sbflags & CIFS_MOUNT_OVERR_UID))
293 + sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER);
294 + if (!(sbflags & CIFS_MOUNT_OVERR_GID))
295 + sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP);
296 + }
286 297 }
287 298
288 299 static void __dir_info_to_fattr(struct cifs_fattr *fattr, const void *info)
modified fs/smb/client/reparse.c
@@ -971,7 +971,8 @@ globalroot:
971 971 linux_target[i*3 + 1] = '.';
972 972 linux_target[i*3 + 2] = sep;
973 973 }
974 - memcpy(linux_target + levels*3, smb_target+1, smb_target_len); /* +1 to skip leading sep */
974 + /* +1 to skip leading sep */
975 + memcpy(linux_target + levels*3, smb_target+1, smb_target_len-1);
975 976 } else {
976 977 /*
977 978 * This is either an absolute symlink in POSIX-style format
@@ -1137,10 +1138,15 @@ static bool wsl_to_fattr(struct cifs_open_info_data *data,
1137 1138 struct cifs_sb_info *cifs_sb,
1138 1139 u32 tag, struct cifs_fattr *fattr)
1139 1140 {
1141 + unsigned int sbflags = cifs_sb_flags(cifs_sb);
1140 1142 struct smb2_file_full_ea_info *ea;
1141 1143 bool have_xattr_dev = false;
1142 1144 u32 next = 0;
1143 1145
1146 + fattr->cf_uid = cifs_sb->ctx->linux_uid;
1147 + fattr->cf_gid = cifs_sb->ctx->linux_gid;
1148 +
1149 + fattr->cf_mode &= ~S_IFMT;
1144 1150 switch (tag) {
1145 1151 case IO_REPARSE_TAG_LX_SYMLINK:
1146 1152 fattr->cf_mode |= S_IFLNK;
@@ -1177,11 +1183,13 @@ static bool wsl_to_fattr(struct cifs_open_info_data *data,
1177 1183 nlen = ea->ea_name_length;
1178 1184 v = (void *)((u8 *)ea->ea_data + ea->ea_name_length + 1);
1179 1185
1180 - if (!strncmp(name, SMB2_WSL_XATTR_UID, nlen))
1181 - fattr->cf_uid = wsl_make_kuid(cifs_sb, v);
1182 - else if (!strncmp(name, SMB2_WSL_XATTR_GID, nlen))
1183 - fattr->cf_gid = wsl_make_kgid(cifs_sb, v);
1184 - else if (!strncmp(name, SMB2_WSL_XATTR_MODE, nlen)) {
1186 + if (!strncmp(name, SMB2_WSL_XATTR_UID, nlen)) {
1187 + if (!(sbflags & CIFS_MOUNT_OVERR_UID))
1188 + fattr->cf_uid = wsl_make_kuid(cifs_sb, v);
1189 + } else if (!strncmp(name, SMB2_WSL_XATTR_GID, nlen)) {
1190 + if (!(sbflags & CIFS_MOUNT_OVERR_GID))
1191 + fattr->cf_gid = wsl_make_kgid(cifs_sb, v);
1192 + } else if (!strncmp(name, SMB2_WSL_XATTR_MODE, nlen)) {
1185 1193 /* File type in reparse point tag and in xattr mode must match. */
1186 1194 if (S_DT(fattr->cf_mode) != S_DT(le32_to_cpu(*(__le32 *)v)))
1187 1195 return false;
@@ -1205,6 +1213,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,
1205 1213 struct cifs_open_info_data *data)
1206 1214 {
1207 1215 struct reparse_nfs_data_buffer *buf = (struct reparse_nfs_data_buffer *)data->reparse.buf;
1216 + umode_t ftype;
1208 1217
1209 1218 if (buf == NULL)
1210 1219 return true;
@@ -1220,7 +1229,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,
1220 1229 WARN_ON_ONCE(1);
1221 1230 return false;
1222 1231 }
1223 - fattr->cf_mode |= S_IFCHR;
1232 + ftype = S_IFCHR;
1224 1233 fattr->cf_rdev = reparse_mkdev(buf->DataBuffer);
1225 1234 break;
1226 1235 case NFS_SPECFILE_BLK:
@@ -1228,22 +1237,23 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,
1228 1237 WARN_ON_ONCE(1);
1229 1238 return false;
1230 1239 }
1231 - fattr->cf_mode |= S_IFBLK;
1240 + ftype = S_IFBLK;
1232 1241 fattr->cf_rdev = reparse_mkdev(buf->DataBuffer);
1233 1242 break;
1234 1243 case NFS_SPECFILE_FIFO:
1235 - fattr->cf_mode |= S_IFIFO;
1244 + ftype = S_IFIFO;
1236 1245 break;
1237 1246 case NFS_SPECFILE_SOCK:
1238 - fattr->cf_mode |= S_IFSOCK;
1247 + ftype = S_IFSOCK;
1239 1248 break;
1240 1249 case NFS_SPECFILE_LNK:
1241 - fattr->cf_mode |= S_IFLNK;
1250 + ftype = S_IFLNK;
1242 1251 break;
1243 1252 default:
1244 1253 WARN_ON_ONCE(1);
1245 1254 return false;
1246 1255 }
1256 + fattr->cf_mode = (fattr->cf_mode & ~S_IFMT) | ftype;
1247 1257 return true;
1248 1258 }
1249 1259
@@ -1271,6 +1281,7 @@ bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb,
1271 1281 break;
1272 1282 case 0: /* SMB1 symlink */
1273 1283 case IO_REPARSE_TAG_SYMLINK:
1284 + fattr->cf_mode &= ~S_IFMT;
1274 1285 fattr->cf_mode |= S_IFLNK;
1275 1286 break;
1276 1287 default:
modified fs/smb/client/trace.h
@@ -79,6 +79,7 @@
79 79 EM(smb_eio_trace_qreparse_setup_count, "qreparse_setup_count") \
80 80 EM(smb_eio_trace_qreparse_sizes_wrong, "qreparse_sizes_wrong") \
81 81 EM(smb_eio_trace_qsym_bcc_too_small, "qsym_bcc_too_small") \
82 + EM(smb_eio_trace_read_bad_offset, "read_bad_offset") \
82 83 EM(smb_eio_trace_read_mid_state_unknown, "read_mid_state_unknown") \
83 84 EM(smb_eio_trace_read_overlarge, "read_overlarge") \
84 85 EM(smb_eio_trace_read_rsp_malformed, "read_rsp_malformed") \
modified fs/super.c
@@ -2369,11 +2369,14 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
2369 2369 goto out_unlock;
2370 2370
2371 2371 /*
2372 - * All freezers share a single active reference.
2373 - * So just unlock in case there are any left.
2372 + * All freezers share a single active reference. If other freezers
2373 + * remain, drop our hold and report success; the superblock stays
2374 + * frozen until the last holder thaws it.
2374 2375 */
2375 - if (freeze_dec(sb, who))
2376 + if (freeze_dec(sb, who)) {
2377 + error = 0;
2376 2378 goto out_unlock;
2379 + }
2377 2380
2378 2381 if (sb_rdonly(sb)) {
2379 2382 sb->s_writers.frozen = SB_UNFROZEN;
modified fs/ufs/cylinder.c
@@ -68,6 +68,16 @@ static bool ufs_read_cylinder(struct super_block *sb,
68 68 ucpi->c_clustersumoff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clustersumoff);
69 69 ucpi->c_clusteroff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clusteroff);
70 70 ucpi->c_nclusterblks = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_nclusterblks);
71 +
72 + /* these on-disk values become array and bitmap indices */
73 + if (ucpi->c_cgx != cgno ||
74 + ucpi->c_rotor >= uspi->s_fpg ||
75 + ucpi->c_frotor >= uspi->s_fpg ||
76 + ucpi->c_irotor >= uspi->s_ipg) {
77 + ufs_error(sb, __func__,
78 + "inconsistent metadata in cylinder group %u\n", cgno);
79 + goto failed;
80 + }
71 81 UFSD("EXIT\n");
72 82 return true;
73 83
modified fs/ufs/dir.c
@@ -590,7 +590,7 @@ int ufs_empty_dir(struct inode * inode)
590 590
591 591 kaddr = ufs_get_folio(inode, i, &folio);
592 592 if (IS_ERR(kaddr))
593 - continue;
593 + return 0;
594 594
595 595 de = (struct ufs_dir_entry *)kaddr;
596 596 kaddr += ufs_last_byte(inode, i) - UFS_DIR_REC_LEN(1);
modified fs/ufs/super.c
@@ -1199,6 +1199,15 @@ magic_found:
1199 1199 sb->s_maxbytes = ufs_max_bytes(sb);
1200 1200 sb->s_max_links = UFS_LINK_MAX;
1201 1201
1202 + ufs_setup_cstotal(sb);
1203 + /*
1204 + * Read cylinder group structures
1205 + */
1206 + if (!sb_rdonly(sb))
1207 + if (!ufs_read_cylinder_structures(sb))
1208 + goto failed;
1209 +
1210 + /* create the root dentry last, once UFS_SB(sb) is fully set up */
1202 1211 inode = ufs_iget(sb, UFS_ROOTINO);
1203 1212 if (IS_ERR(inode)) {
1204 1213 ret = PTR_ERR(inode);
@@ -1210,14 +1219,6 @@ magic_found:
1210 1219 goto failed;
1211 1220 }
1212 1221
1213 - ufs_setup_cstotal(sb);
1214 - /*
1215 - * Read cylinder group structures
1216 - */
1217 - if (!sb_rdonly(sb))
1218 - if (!ufs_read_cylinder_structures(sb))
1219 - goto failed;
1220 -
1221 1222 UFSD("EXIT\n");
1222 1223 return 0;
1223 1224
modified fs/xfs/libxfs/xfs_btree_mem.c
@@ -117,6 +117,7 @@ xfbtree_init(
117 117 struct xfs_buftarg *btp,
118 118 const struct xfs_btree_ops *ops)
119 119 {
120 + unsigned long long owner = xfbt->owner;
120 121 unsigned int blocklen = xfbtree_rec_bytes(mp, ops);
121 122 unsigned int keyptr_len;
122 123 int error;
@@ -133,6 +134,7 @@ xfbtree_init(
133 134
134 135 memset(xfbt, 0, sizeof(*xfbt));
135 136 xfbt->target = btp;
137 + xfbt->owner = owner;
136 138
137 139 /* Set up min/maxrecs for this btree. */
138 140 keyptr_len = ops->key_len + sizeof(__be64);
modified fs/xfs/libxfs/xfs_btree_staging.c
@@ -336,8 +336,10 @@ xfs_btree_bload_prep_block(
336 336 xfs_btree_set_sibling(cur, *blockp, &new_ptr, XFS_BB_RIGHTSIB);
337 337
338 338 ret = xfs_btree_bload_drop_buf(bbl, buffers_list, bpp);
339 - if (ret)
339 + if (ret) {
340 + xfs_buf_relse(new_bp);
340 341 return ret;
342 + }
341 343
342 344 /* Initialize the new btree block. */
343 345 xfs_btree_init_block_cur(cur, new_bp, level, nr_this_block);
modified fs/xfs/libxfs/xfs_da_btree.c
@@ -130,7 +130,7 @@ xfs_da_state_reset(
130 130 state->mp = state->args->dp->i_mount;
131 131 }
132 132
133 - static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
133 + inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
134 134 {
135 135 if (whichfork == XFS_DATA_FORK)
136 136 return mp->m_dir_geo->fsbcount;
@@ -2384,6 +2384,7 @@ xfs_da_grow_inode_int(
2384 2384 }
2385 2385
2386 2386 /* account for newly allocated blocks in reserved blocks total */
2387 + ASSERT(args->total >= dp->i_nblocks - nblks);
2387 2388 args->total -= dp->i_nblocks - nblks;
2388 2389
2389 2390 out_free_map:
modified fs/xfs/libxfs/xfs_da_btree.h
@@ -244,4 +244,6 @@ xfs_failaddr_t xfs_da3_node_header_check(struct xfs_buf *bp, xfs_ino_t owner);
244 244
245 245 extern struct kmem_cache *xfs_da_state_cache;
246 246
247 + int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork);
248 +
247 249 #endif /* __XFS_DA_BTREE_H__ */
modified fs/xfs/libxfs/xfs_defer.c
@@ -229,6 +229,7 @@ xfs_defer_barrier_cancel_item(
229 229 }
230 230
231 231 static const struct xfs_defer_op_type xfs_barrier_defer_type = {
232 + .name = "barrier",
232 233 .max_items = 1,
233 234 .create_intent = xfs_defer_barrier_create_intent,
234 235 .abort_intent = xfs_defer_barrier_abort_intent,
@@ -583,7 +584,7 @@ xfs_defer_finish_one(
583 584 const struct xfs_defer_op_type *ops = dfp->dfp_ops;
584 585 struct xfs_btree_cur *state = NULL;
585 586 struct list_head *li, *n;
586 - int error;
587 + int error = 0;
587 588
588 589 trace_xfs_defer_pending_finish(tp->t_mountp, dfp);
589 590
@@ -655,6 +656,7 @@ xfs_defer_finish_noroll(
655 656 struct xfs_trans **tp)
656 657 {
657 658 struct xfs_defer_pending *dfp = NULL;
659 + const char *what = "chain";
658 660 int error = 0;
659 661 LIST_HEAD(dop_pending);
660 662 LIST_HEAD(dop_paused);
@@ -704,9 +706,17 @@ xfs_defer_finish_noroll(
704 706 struct xfs_defer_pending, dfp_list);
705 707 if (!dfp)
706 708 break;
709 + what = dfp->dfp_ops->name;
707 710 error = xfs_defer_finish_one(*tp, dfp);
708 711 if (error && error != -EAGAIN)
709 712 goto out_shutdown;
713 + /*
714 + * A finished item is no longer a candidate for a later
715 + * failure. An -EAGAIN one is not finished, so it keeps the
716 + * attribution across the roll that completes it.
717 + */
718 + if (!error)
719 + what = "chain";
710 720 }
711 721
712 722 /* Requeue the paused items in the outgoing transaction. */
@@ -718,8 +728,12 @@ xfs_defer_finish_noroll(
718 728 out_shutdown:
719 729 list_splice_tail_init(&dop_paused, &dop_pending);
720 730 xfs_defer_trans_abort(*tp, &dop_pending);
721 - xfs_force_shutdown((*tp)->t_mountp, SHUTDOWN_CORRUPT_INCORE);
722 731 trace_xfs_defer_finish_error(*tp, error);
732 + if (!xfs_is_shutdown((*tp)->t_mountp))
733 + xfs_alert((*tp)->t_mountp,
734 + "deferred %s work failed, error %d, %u blocks reserved",
735 + what, error, (*tp)->t_blk_res);
736 + xfs_force_shutdown((*tp)->t_mountp, SHUTDOWN_CORRUPT_INCORE);
723 737 xfs_defer_cancel_list((*tp)->t_mountp, &dop_pending);
724 738 xfs_defer_cancel(*tp);
725 739 return error;
modified fs/xfs/libxfs/xfs_exchmaps.c
@@ -959,6 +959,16 @@ xmi_can_exchange_reflink_flags(
959 959 {
960 960 struct xfs_mount *mp = req->ip1->i_mount;
961 961
962 + /*
963 + * The INO1_WRITTEN optimization can skip exchanging hole and
964 + * unwritten mappings, which means we cannot guarantee that all
965 + * shared extents actually moved to the other file. Clearing the
966 + * reflink flag of an inode that still holds shared extents breaks
967 + * the CoW write path, so refuse to exchange the flags in that case.
968 + */
969 + if (req->flags & XFS_EXCHMAPS_INO1_WRITTEN)
970 + return false;
971 +
962 972 /*
963 973 * The INO1_WRITTEN optimization can skip exchanging hole and
964 974 * unwritten mappings, which means we cannot guarantee that all
modified fs/xfs/libxfs/xfs_parent.c
@@ -193,7 +193,7 @@ xfs_parent_addname(
193 193 const struct xfs_name *parent_name,
194 194 struct xfs_inode *child)
195 195 {
196 - int error;
196 + int error, local;
197 197
198 198 error = xfs_parent_iread_extents(tp, child);
199 199 if (error)
@@ -203,6 +203,10 @@ xfs_parent_addname(
203 203 xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child,
204 204 I_INO(child), parent_name);
205 205
206 + /* Growing the attr fork needs a real reservation in args->total. */
207 + ppargs->args.total = xfs_attr_calc_size(&ppargs->args, &local);
208 + ASSERT(local);
209 +
206 210 return xfs_attr_setname(&ppargs->args, 0);
207 211 }
208 212
@@ -239,7 +243,7 @@ xfs_parent_replacename(
239 243 const struct xfs_name *new_name,
240 244 struct xfs_inode *child)
241 245 {
242 - int error;
246 + int error, local;
243 247
244 248 error = xfs_parent_iread_extents(tp, child);
245 249 if (error)
@@ -249,6 +253,10 @@ xfs_parent_replacename(
249 253 xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child,
250 254 I_INO(child), old_name);
251 255
256 + /* Growing the attr fork needs a real reservation in args->total. */
257 + ppargs->args.total = xfs_attr_calc_size(&ppargs->args, &local);
258 + ASSERT(local);
259 +
252 260 xfs_inode_to_parent_rec(&ppargs->new_rec, new_dp);
253 261
254 262 ppargs->args.new_name = new_name->name;
modified fs/xfs/libxfs/xfs_rtrefcount_btree.c
@@ -489,8 +489,11 @@ xfs_rtrefcountbt_maxlevels_ondisk(void)
489 489 minrecs[0] = xfs_rtrefcountbt_block_maxrecs(blocklen, true) / 2;
490 490 minrecs[1] = xfs_rtrefcountbt_block_maxrecs(blocklen, false) / 2;
491 491
492 - /* We need at most one record for every block in an rt group. */
493 - return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_RGBLOCKS);
492 + /*
493 + * We need at most one record for every block in an rt group, and
494 + * one extra level for the inode root.
495 + */
496 + return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_RGBLOCKS) + 1;
494 497 }
495 498
496 499 int __init
modified fs/xfs/libxfs/xfs_rtrmap_btree.c
@@ -618,7 +618,7 @@ xfs_rtrmapbt_mem_cursor(
618 618 struct xfs_btree_cur *cur;
619 619
620 620 cur = xfs_btree_alloc_cursor(mp, tp, &xfs_rtrmapbt_mem_ops,
621 - mp->m_rtrmap_maxlevels, xfs_rtrmapbt_cur_cache);
621 + xfs_rtrmapbt_maxlevels_ondisk(), xfs_rtrmapbt_cur_cache);
622 622 cur->bc_mem.xfbtree = xfbt;
623 623 cur->bc_nlevels = xfbt->nlevels;
624 624 cur->bc_group = xfs_group_hold(rtg_group(rtg));
@@ -716,10 +716,12 @@ xfs_rtrmapbt_maxlevels_ondisk(void)
716 716 * happens, which means that we must compute the max height based on
717 717 * what the btree will look like if it consumes almost all the blocks
718 718 * in the data device due to maximal sharing factor.
719 + *
720 + * Add one extra level for the inode root.
719 721 */
720 722 max_dblocks = -1U; /* max ag count */
721 723 max_dblocks *= XFS_MAX_CRC_AG_BLOCKS;
722 - return xfs_btree_space_to_height(minrecs, max_dblocks);
724 + return xfs_btree_space_to_height(minrecs, max_dblocks) + 1;
723 725 }
724 726
725 727 int __init
modified fs/xfs/libxfs/xfs_trans_space.c
@@ -22,8 +22,23 @@ xfs_parent_calc_space_res(
22 22 unsigned int namelen)
23 23 {
24 24 /*
25 - * Parent pointers are always the first attr in an attr tree, and never
26 - * larger than a block
25 + * A parent pointer is recorded per dirent, so an inode with N links
26 + * carries N of them and the attr fork can already be in leaf or node
27 + * format when one is added. That does not affect the reservation:
28 + * XFS_DAENTER_SPACE_RES covers a split at every level of a
29 + * maximum-depth attr dabtree, whatever format the fork is in now.
30 + *
31 + * The name is a dirent name and the value is a struct xfs_parent_rec,
32 + * so the leaf entry is always local and never exceeds 272 bytes.
33 + * Parent pointers require V5, hence a 1k minimum block size, so the
34 + * entry always stays under half a block and this needs none of the
35 + * double split allowance that xfs_attr_calc_size() makes.
36 + *
37 + * The second term hands a byte count to a macro whose parameter counts
38 + * mappings, so it asks for more extent-add allowance than the single
39 + * mapping a parent pointer adds - how much more depends on the block
40 + * size. It over-reserves either way, which is why it is left alone:
41 + * correcting the unit would shrink a reservation that is only generous.
27 42 */
28 43 return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) +
29 44 XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK);
modified fs/xfs/scrub/agheader.c
@@ -418,6 +418,13 @@ xchk_superblock(
418 418 xchk_block_set_corrupt(sc, bp);
419 419 }
420 420
421 + if (xfs_has_zoned(mp)) {
422 + if (sb->sb_rtstart != cpu_to_be64(mp->m_sb.sb_rtstart))
423 + xchk_block_set_corrupt(sc, bp);
424 + if (sb->sb_rtreserved != cpu_to_be64(mp->m_sb.sb_rtreserved))
425 + xchk_block_set_corrupt(sc, bp);
426 + }
427 +
421 428 /* Everything else must be zero. */
422 429 sblen = xchk_superblock_ondisk_size(mp);
423 430 if (memchr_inv((char *)sb + sblen, 0, BBTOB(bp->b_length) - sblen))
modified fs/xfs/scrub/agheader_repair.c
@@ -668,14 +668,16 @@ xrep_agfl_init_header(
668 668 struct xfs_scrub *sc,
669 669 struct xfs_buf *agfl_bp,
670 670 struct xagb_bitmap *agfl_extents,
671 - xfs_agblock_t flcount)
671 + xfs_agblock_t flcount,
672 + struct xfs_agfl *old_agfl)
672 673 {
673 674 struct xrep_agfl_fill af = {
674 675 .sc = sc,
675 676 .flcount = flcount,
676 677 };
677 678 struct xfs_mount *mp = sc->mp;
678 - struct xfs_agfl *agfl;
679 + struct xfs_agfl *agfl = XFS_BUF_TO_AGFL(agfl_bp);
680 + const size_t agfl_sz = BBTOB(agfl_bp->b_length);
679 681 int error;
680 682
681 683 ASSERT(flcount <= xfs_agfl_size(mp));
@@ -684,8 +686,8 @@ xrep_agfl_init_header(
684 686 * Start rewriting the header by setting the bno[] array to
685 687 * NULLAGBLOCK, then setting AGFL header fields.
686 688 */
687 - agfl = XFS_BUF_TO_AGFL(agfl_bp);
688 - memset(agfl, 0xFF, BBTOB(agfl_bp->b_length));
689 + memcpy(old_agfl, agfl, agfl_sz);
690 + memset(agfl, 0xFF, agfl_sz);
689 691 agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
690 692 agfl->agfl_seqno = cpu_to_be32(pag_agno(sc->sa.pag));
691 693 uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
@@ -697,16 +699,23 @@ xrep_agfl_init_header(
697 699 */
698 700 xagb_bitmap_init(&af.used_extents);
699 701 af.agfl_bno = xfs_buf_to_agfl_bno(agfl_bp);
700 - xagb_bitmap_walk(agfl_extents, xrep_agfl_fill, &af);
702 + error = xagb_bitmap_walk(agfl_extents, xrep_agfl_fill, &af);
703 + if (error && error != -ECANCELED)
704 + goto err_undo;
701 705 error = xagb_bitmap_disunion(agfl_extents, &af.used_extents);
702 706 if (error)
703 - return error;
707 + goto err_undo;
704 708
705 709 /* Write new AGFL to disk. */
706 710 xfs_trans_buf_set_type(sc->tp, agfl_bp, XFS_BLFT_AGFL_BUF);
707 - xfs_trans_log_buf(sc->tp, agfl_bp, 0, BBTOB(agfl_bp->b_length) - 1);
711 + xfs_trans_log_buf(sc->tp, agfl_bp, 0, agfl_sz - 1);
708 712 xagb_bitmap_destroy(&af.used_extents);
709 713 return 0;
714 +
715 + err_undo:
716 + xagb_bitmap_destroy(&af.used_extents);
717 + memcpy(agfl, old_agfl, agfl_sz);
718 + return error;
710 719 }
711 720
712 721 /* Repair the AGFL. */
@@ -718,6 +727,7 @@ xrep_agfl(
718 727 struct xfs_mount *mp = sc->mp;
719 728 struct xfs_buf *agf_bp;
720 729 struct xfs_buf *agfl_bp;
730 + struct xfs_agfl *old_agfl;
721 731 xfs_agblock_t flcount;
722 732 int error;
723 733
@@ -725,6 +735,10 @@ xrep_agfl(
725 735 if (!xfs_has_rmapbt(mp))
726 736 return -EOPNOTSUPP;
727 737
738 + old_agfl = kzalloc(BBTOB(XFS_FSS_TO_BB(mp, 1)), XCHK_GFP_FLAGS);
739 + if (!old_agfl)
740 + return -ENOMEM;
741 +
728 742 xagb_bitmap_init(&agfl_extents);
729 743
730 744 /*
@@ -734,7 +748,7 @@ xrep_agfl(
734 748 */
735 749 error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp);
736 750 if (error)
737 - return error;
751 + goto err_old_agfl;
738 752
739 753 /*
740 754 * Make sure we have the AGFL buffer, as scrub might have decided it
@@ -745,7 +759,7 @@ xrep_agfl(
745 759 XFS_AGFL_DADDR(mp)),
746 760 XFS_FSS_TO_BB(mp, 1), 0, &agfl_bp, NULL);
747 761 if (error)
748 - return error;
762 + goto err_old_agfl;
749 763 agfl_bp->b_ops = &xfs_agfl_buf_ops;
750 764
751 765 /* Gather all the extents we're going to put on the new AGFL. */
@@ -762,10 +776,11 @@ xrep_agfl(
762 776 * we adjust the AGF flcount (which can fail) so avoid updating any
763 777 * buffers until we know that part works.
764 778 */
765 - xrep_agfl_update_agf(sc, agf_bp, flcount);
766 - error = xrep_agfl_init_header(sc, agfl_bp, &agfl_extents, flcount);
779 + error = xrep_agfl_init_header(sc, agfl_bp, &agfl_extents, flcount,
780 + old_agfl);
767 781 if (error)
768 782 goto err;
783 + xrep_agfl_update_agf(sc, agf_bp, flcount);
769 784
770 785 /*
771 786 * Ok, the AGFL should be ready to go now. Roll the transaction to
@@ -785,6 +800,8 @@ xrep_agfl(
785 800
786 801 err:
787 802 xagb_bitmap_destroy(&agfl_extents);
803 + err_old_agfl:
804 + kfree(old_agfl);
788 805 return error;
789 806 }
790 807
modified fs/xfs/scrub/alloc_repair.c
@@ -571,7 +571,7 @@ xrep_abt_dispose_one(
571 571 * allocation, and blocks that didn't get used can be freed via the usual
572 572 * (deferred) means.
573 573 */
574 - STATIC void
574 + STATIC int
575 575 xrep_abt_dispose_reservations(
576 576 struct xrep_abt *ra,
577 577 int error)
@@ -582,9 +582,13 @@ xrep_abt_dispose_reservations(
582 582 goto junkit;
583 583
584 584 list_for_each_entry_safe(resv, n, &ra->new_bnobt.resv_list, list) {
585 - error = xrep_abt_dispose_one(ra, resv);
586 - if (error)
585 + int error2 = xrep_abt_dispose_one(ra, resv);
586 +
587 + if (error2) {
588 + if (!error)
589 + error = error2;
587 590 goto junkit;
591 + }
588 592 }
589 593
590 594 junkit:
@@ -596,6 +600,7 @@ junkit:
596 600
597 601 xrep_newbt_cancel(&ra->new_bnobt);
598 602 xrep_newbt_cancel(&ra->new_cntbt);
603 + return error;
599 604 }
600 605
601 606 /* Retrieve free space data for bulk load. */
@@ -801,7 +806,9 @@ xrep_abt_build_new_trees(
801 806 goto err_newbt;
802 807
803 808 /* Dispose of any unused blocks and the accounting information. */
804 - xrep_abt_dispose_reservations(ra, error);
809 + error = xrep_abt_dispose_reservations(ra, error);
810 + if (error)
811 + return error;
805 812
806 813 return xrep_roll_ag_trans(sc);
807 814
@@ -812,8 +819,7 @@ err_cur:
812 819 xfs_btree_del_cursor(cnt_cur, error);
813 820 xfs_btree_del_cursor(bno_cur, error);
814 821 err_newbt:
815 - xrep_abt_dispose_reservations(ra, error);
816 - return error;
822 + return xrep_abt_dispose_reservations(ra, error);
817 823 }
818 824
819 825 /*
modified fs/xfs/scrub/attr_repair.c
@@ -1294,7 +1294,7 @@ xrep_xattr_swap_prep(
1294 1294 .geo = sc->mp->m_attr_geo,
1295 1295 .whichfork = XFS_ATTR_FORK,
1296 1296 .trans = sc->tp,
1297 - .total = 1,
1297 + .total = xfs_dabuf_nfsb(sc->mp, XFS_ATTR_FORK),
1298 1298 .owner = I_INO(sc->ip),
1299 1299 };
1300 1300
modified fs/xfs/scrub/bmap.c
@@ -274,7 +274,7 @@ xchk_bmap_xref_rmap_cow(
274 274 unsigned long long rmap_end;
275 275 uint64_t owner = XFS_RMAP_OWN_COW;
276 276
277 - if (!info->sc->sa.rmap_cur || xchk_skip_xref(info->sc->sm))
277 + if (xchk_skip_xref(info->sc->sm))
278 278 return;
279 279
280 280 /* Find the rmap record for this irec. */
@@ -1103,8 +1103,9 @@ xchk_bmap(
1103 1103 * the rmap must match the combined mapping exactly.
1104 1104 */
1105 1105 while (xchk_bmap_iext_iter(&info, &irec)) {
1106 - if (xchk_should_terminate(sc, &error) ||
1107 - (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
1106 + if (xchk_should_terminate(sc, &error))
1107 + return error;
1108 + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
1108 1109 return 0;
1109 1110
1110 1111 if (irec.br_startoff >= endoff) {
modified fs/xfs/scrub/common.h
@@ -74,7 +74,6 @@ int xchk_setup_ag_rmapbt(struct xfs_scrub *sc);
74 74 int xchk_setup_ag_refcountbt(struct xfs_scrub *sc);
75 75 int xchk_setup_inode(struct xfs_scrub *sc);
76 76 int xchk_setup_inode_bmap(struct xfs_scrub *sc);
77 - int xchk_setup_inode_bmap_data(struct xfs_scrub *sc);
78 77 int xchk_setup_directory(struct xfs_scrub *sc);
79 78 int xchk_setup_xattr(struct xfs_scrub *sc);
80 79 int xchk_setup_symlink(struct xfs_scrub *sc);
modified fs/xfs/scrub/dabtree.h
@@ -37,8 +37,6 @@ bool xchk_da_process_error(struct xchk_da_btree *ds, int level, int *error);
37 37 void xchk_da_set_corrupt(struct xchk_da_btree *ds, int level);
38 38 void xchk_da_set_preen(struct xchk_da_btree *ds, int level);
39 39
40 - void xchk_da_set_preen(struct xchk_da_btree *ds, int level);
41 -
42 40 int xchk_da_btree_hash(struct xchk_da_btree *ds, int level, __be32 *hashp);
43 41 int xchk_da_btree(struct xfs_scrub *sc, int whichfork,
44 42 xchk_da_btree_rec_fn scrub_fn, void *private);
modified fs/xfs/scrub/dir_repair.c
@@ -484,18 +484,24 @@ xrep_dir_recover_data(
484 484 while (offset < end) {
485 485 struct xfs_dir2_data_unused *dup = bp->b_addr + offset;
486 486 struct xfs_dir2_data_entry *dep = bp->b_addr + offset;
487 + unsigned int advance;
487 488
488 489 if (xchk_should_terminate(rd->sc, &error))
489 490 return error;
490 491
491 492 /* Skip unused entries. */
492 493 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
494 + if (!dup->length)
495 + break;
493 496 offset += be16_to_cpu(dup->length);
494 497 continue;
495 498 }
496 499
497 500 /* Don't walk off the end of the block. */
498 - offset += xfs_dir2_data_entsize(rd->sc->mp, dep->namelen);
501 + advance = xfs_dir2_data_entsize(rd->sc->mp, dep->namelen);
502 + if (!advance)
503 + break;
504 + offset += advance;
499 505 if (offset > end)
500 506 break;
501 507
@@ -721,7 +727,7 @@ xrep_dir_replay_removename(
721 727 const struct xfs_name *name,
722 728 xfs_extlen_t total)
723 729 {
724 - struct xfs_inode *dp = rd->args.dp;
730 + struct xfs_inode *dp = rd->sc->tempip;
725 731
726 732 ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
727 733
@@ -1375,9 +1381,24 @@ xrep_dir_live_update(
1375 1381 if (p->delta > 0)
1376 1382 error = xrep_dir_stash_createname(rd, p->name,
1377 1383 I_INO(p->ip));
1378 - else
1379 - error = xrep_dir_stash_removename(rd, p->name,
1384 + else {
1385 + /*
1386 + * xfs_dentry_to_name in unlink or rename-exchange can
1387 + * pass us names with ftype FT_UNKNOWN, but we really
1388 + * must know the ftype of the child that is being
1389 + * removed so that we can do nlink updates correctly
1390 + * without holding inode references.
1391 + */
1392 + struct xfs_name name = {
1393 + .name = p->name->name,
1394 + .len = p->name->len,
1395 + .type = xfs_mode_to_ftype(
1396 + VFS_IC(p->ip)->i_mode),
1397 + };
1398 +
1399 + error = xrep_dir_stash_removename(rd, &name,
1380 1400 I_INO(p->ip));
1401 + }
1381 1402 mutex_unlock(&rd->pscan.lock);
1382 1403 if (error)
1383 1404 goto out_abort;
@@ -1467,7 +1488,7 @@ xrep_dir_swap_prep(
1467 1488 .geo = sc->mp->m_dir_geo,
1468 1489 .whichfork = XFS_DATA_FORK,
1469 1490 .trans = sc->tp,
1470 - .total = 1,
1491 + .total = xfs_dabuf_nfsb(sc->mp, XFS_DATA_FORK),
1471 1492 .owner = I_INO(sc->ip),
1472 1493 };
1473 1494
modified fs/xfs/scrub/dirtree.c
@@ -259,6 +259,7 @@ xchk_dirtree_create_path(
259 259 dl->nr_paths++;
260 260 return 0;
261 261 out_path:
262 + xino_bitmap_destroy(&path->seen_inodes);
262 263 kfree(path);
263 264 return error;
264 265 }
@@ -368,12 +369,38 @@ xchk_dirpath_step_up(
368 369 struct xfs_inode *dp;
369 370 xfs_ino_t parent_ino = be64_to_cpu(dl->pptr_rec.p_ino);
370 371 unsigned int lock_mode;
371 - int error;
372 + int error = 0;
373 +
374 + if (xchk_should_terminate(sc, &error))
375 + return error;
372 376
373 377 /* Grab and lock the parent directory. */
374 378 error = xchk_iget(sc, parent_ino, &dp);
375 - if (error)
379 + switch (error) {
380 + case -EINVAL:
381 + case -ENOENT:
382 + mutex_lock(&dl->lock);
383 +
384 + if (dl->stale) {
385 + /* live update detected a change in this path */
386 + error = -ESTALE;
387 + } else {
388 + /* inode doesn't exist, path invalid */
389 + error = -EFSCORRUPTED;
390 +
391 + trace_xchk_dirpath_badino(dl->sc, path->path_nr,
392 + path->nr_steps, &dl->xname,
393 + &dl->pptr_rec);
394 + }
395 +
396 + mutex_unlock(&dl->lock);
397 + return error;
398 + case 0:
399 + /* keep going */
400 + break;
401 + default:
376 402 return error;
403 + }
377 404
378 405 lock_mode = xfs_ilock_attr_map_shared(dp);
379 406 mutex_lock(&dl->lock);
modified fs/xfs/scrub/dirtree_repair.c
@@ -479,6 +479,7 @@ again:
479 479 }
480 480
481 481 if (xfs_has_parent(sc->mp)) {
482 + memset(&dl->ppargs, 0, sizeof(dl->ppargs));
482 483 error = xfs_parent_removename(sc->tp, &dl->ppargs, dp,
483 484 &dl->xname, sc->ip);
484 485 if (error)
@@ -618,6 +619,7 @@ xrep_dirtree_create_adoption_path(
618 619 return 0;
619 620
620 621 out_path:
622 + xino_bitmap_destroy(&path->seen_inodes);
621 623 kfree(path);
622 624 return error;
623 625 }
modified fs/xfs/scrub/findparent.c
@@ -139,32 +139,52 @@ xrep_findparent_dirent(
139 139 return 0;
140 140 }
141 141
142 - /*
143 - * If this is a directory, walk the dirents looking for any that point to the
144 - * scrub target inode.
145 - */
146 - STATIC int
147 - xrep_findparent_walk_directory(
148 - struct xrep_findparent_info *fpi)
142 + static inline bool
143 + xrep_findparent_want_scan_file(
144 + const struct xrep_findparent_info *fpi)
149 145 {
150 - struct xfs_scrub *sc = fpi->sc;
151 - struct xfs_inode *dp = fpi->dp;
152 - unsigned int lock_mode;
153 - int error = 0;
146 + const struct xfs_scrub *sc = fpi->sc;
147 + const struct xfs_inode *dp = fpi->dp;
148 +
149 + /* Only directories can be parents */
150 + if (!S_ISDIR(VFS_IC(dp)->i_mode))
151 + return false;
154 152
155 153 /*
156 154 * The inode being scanned cannot be its own parent, nor can any
157 155 * temporary directory we created to stage this repair.
158 156 */
159 157 if (dp == sc->ip || dp == sc->tempip)
160 - return 0;
158 + return false;
161 159
162 160 /*
163 161 * Similarly, temporary files created to stage a repair cannot be the
164 162 * parent of this inode.
165 163 */
166 164 if (xrep_is_tempfile(dp))
165 + return false;
166 +
167 + return true;
168 + }
169 +
170 + /*
171 + * If this is a directory, walk the dirents looking for any that point to the
172 + * scrub target inode.
173 + */
174 + STATIC int
175 + xrep_findparent_walk_file(
176 + struct xrep_findparent_info *fpi)
177 + {
178 + struct xfs_scrub *sc = fpi->sc;
179 + struct xfs_inode *dp = fpi->dp;
180 + unsigned int lock_mode;
181 + int error = 0;
182 +
183 + if (!xrep_findparent_want_scan_file(fpi)) {
184 + if (fpi->parent_scan)
185 + xchk_iscan_mark_visited(&fpi->parent_scan->iscan, dp);
167 186 return 0;
187 + }
168 188
169 189 /*
170 190 * Scan the directory to see if there it contains an entry pointing to
@@ -201,6 +221,8 @@ xrep_findparent_walk_directory(
201 221 goto out_unlock;
202 222
203 223 out_unlock:
224 + if (fpi->parent_scan)
225 + xchk_iscan_mark_visited(&fpi->parent_scan->iscan, dp);
204 226 xfs_iunlock(dp, lock_mode);
205 227 return error;
206 228 }
@@ -308,11 +330,7 @@ xrep_findparent_scan(
308 330 ASSERT(S_ISDIR(VFS_IC(sc->ip)->i_mode));
309 331
310 332 while ((ret = xchk_iscan_iter(&pscan->iscan, &fpi.dp)) == 1) {
311 - if (S_ISDIR(VFS_I(fpi.dp)->i_mode))
312 - ret = xrep_findparent_walk_directory(&fpi);
313 - else
314 - ret = 0;
315 - xchk_iscan_mark_visited(&pscan->iscan, fpi.dp);
333 + ret = xrep_findparent_walk_file(&fpi);
316 334 xchk_irele(sc, fpi.dp);
317 335 if (ret)
318 336 break;
@@ -401,7 +419,7 @@ xrep_findparent_confirm(
401 419 goto out_rele;
402 420 }
403 421
404 - error = xrep_findparent_walk_directory(&fpi);
422 + error = xrep_findparent_walk_file(&fpi);
405 423 if (error)
406 424 goto out_rele;
407 425
modified fs/xfs/scrub/ialloc.c
@@ -85,6 +85,8 @@ xchk_inobt_xref_finobt(
85 85 goto no_record;
86 86
87 87 error = xfs_inobt_get_rec(cur, &frec, &has_record);
88 + if (error)
89 + return error;
88 90 if (!has_record)
89 91 return -EFSCORRUPTED;
90 92
@@ -188,6 +190,8 @@ xchk_finobt_xref_inobt(
188 190 goto no_record;
189 191
190 192 error = xfs_inobt_get_rec(cur, &irec, &has_record);
193 + if (error)
194 + return error;
191 195 if (!has_record)
192 196 return -EFSCORRUPTED;
193 197
modified fs/xfs/scrub/metapath.c
@@ -23,6 +23,7 @@
23 23 #include "xfs_rtgroup.h"
24 24 #include "xfs_rtrmap_btree.h"
25 25 #include "xfs_rtrefcount_btree.h"
26 + #include "xfs_ag.h"
26 27 #include "scrub/scrub.h"
27 28 #include "scrub/common.h"
28 29 #include "scrub/trace.h"
@@ -348,12 +349,78 @@ out_cancel:
348 349 }
349 350
350 351 #ifdef CONFIG_XFS_ONLINE_REPAIR
352 + /*
353 + * Given a directory @dp, an existing inode @ip, and a @name, link @ip into @dp
354 + * under the given @name.
355 + */
356 + static int
357 + xrep_metadir_add_child(
358 + struct xchk_metapath *mpath,
359 + xfs_ino_t old_dotdot)
360 + {
361 + struct xfs_trans *tp = mpath->sc->tp;
362 + struct xfs_dir_update *du = &mpath->du;
363 + struct xfs_inode *dp = du->dp;
364 + const struct xfs_name *name = du->name;
365 + struct xfs_inode *ip = du->ip;
366 + struct xfs_mount *mp = tp->t_mountp;
367 + const unsigned int resblks = mpath->link_resblks;
368 + int error;
369 +
370 + /*
371 + * The metadata file shouldn't be on the unlinked list, but we'll fix
372 + * it if that is the case.
373 + */
374 + if (VFS_I(ip)->i_nlink == 0) {
375 + struct xfs_perag *pag;
376 +
377 + pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, I_INO(ip)));
378 + error = xfs_iunlink_remove(tp, pag, ip);
379 + xfs_perag_put(pag);
380 + if (error)
381 + return error;
382 + }
383 +
384 + error = xfs_dir_createname(tp, dp, name, I_INO(ip), resblks);
385 + if (error)
386 + return error;
387 +
388 + xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
389 +
390 + xfs_bumplink(tp, ip);
391 +
392 + /* update dotdot entry in child */
393 + if (S_ISDIR(VFS_I(ip)->i_mode)) {
394 + xfs_bumplink(tp, dp);
395 +
396 + /* Replace the dotdot entry in the child */
397 + if (old_dotdot != I_INO(dp)) {
398 + error = xfs_dir_replace(tp, ip, &xfs_name_dotdot,
399 + I_INO(dp), resblks);
400 + if (error)
401 + return error;
402 + }
403 + }
404 +
405 + /* Update the child's parent pointer */
406 + if (du->ppargs) {
407 + error = xfs_parent_addname(tp, du->ppargs, dp, name, ip);
408 + if (error)
409 + return error;
410 + }
411 +
412 + xfs_dir_update_hook(dp, ip, 1, name);
413 + return 0;
414 + }
415 +
351 416 /* Create the dirent represented by the final component of the path. */
352 417 STATIC int
353 418 xrep_metapath_link(
354 419 struct xchk_metapath *mpath)
355 420 {
356 421 struct xfs_scrub *sc = mpath->sc;
422 + xfs_ino_t old_dotdot = NULLFSINO;
423 + int error;
357 424
358 425 mpath->du.dp = mpath->dp;
359 426 mpath->du.name = &mpath->xname;
@@ -366,7 +433,21 @@ xrep_metapath_link(
366 433
367 434 trace_xrep_metapath_link(sc, mpath->path, mpath->dp, I_INO(sc->ip));
368 435
369 - return xfs_dir_add_child(sc->tp, mpath->link_resblks, &mpath->du);
436 + if (S_ISDIR(VFS_I(sc->ip)->i_mode)) {
437 + error = xchk_dir_lookup(sc, sc->ip, &xfs_name_dotdot,
438 + &old_dotdot);
439 + if (error && error != -ENOENT)
440 + return error;
441 +
442 + /*
443 + * subdir didn't give us a dotdot entry, so we just give up
444 + * and let the repair get marked as failed.
445 + */
446 + if (old_dotdot == NULLFSINO)
447 + return 0;
448 + }
449 +
450 + return xrep_metadir_add_child(mpath, old_dotdot);
370 451 }
371 452
372 453 /* Remove the dirent at the final component of the path. */
@@ -397,7 +478,7 @@ xrep_metapath_unlink(
397 478
398 479 /* Figure out if we're removing a parent pointer too. */
399 480 if (xfs_has_parent(mp)) {
400 - xfs_inode_to_parent_rec(&rec, ip);
481 + xfs_inode_to_parent_rec(&rec, mpath->dp);
401 482 error = xfs_parent_lookup(sc->tp, ip, &mpath->xname, &rec,
402 483 &mpath->pptr_args);
403 484 switch (error) {
@@ -556,6 +637,8 @@ xrep_metapath_try_unlink(
556 637 error = xchk_metapath_ilock_parent_and_child(mpath, ip);
557 638 if (error) {
558 639 xchk_trans_cancel(sc);
640 + if (ip)
641 + xchk_irele(sc, ip);
559 642 return error;
560 643 }
561 644 xfs_trans_ijoin(sc->tp, mpath->dp, 0);
modified fs/xfs/scrub/quota_repair.c
@@ -325,7 +325,7 @@ xrep_quota_block(
325 325 * If there's nothing that would impede a dqiterate, we're
326 326 * done.
327 327 */
328 - if ((ddq->d_type & XFS_DQTYPE_REC_MASK) != dqtype ||
328 + if ((ddq->d_type & XFS_DQTYPE_REC_MASK) == dqtype &&
329 329 id == be32_to_cpu(ddq->d_id)) {
330 330 xfs_trans_brelse(sc->tp, bp);
331 331 return 0;
@@ -363,11 +363,18 @@ xrep_quota_block(
363 363 ddq->d_rtbcount, &ddq->d_rtbtimer,
364 364 defq->rtb.time);
365 365
366 + /*
367 + * This transaction operates on raw disk buffers, so we don't
368 + * have a dquot log item to assign the LSN for us. Instead,
369 + * set it to zero so that log recovery will always replay any
370 + * logged dquot item atop this buffer.
371 + */
372 + dqblk->dd_lsn = 0;
373 +
366 374 /* We only support v5 filesystems so always set these. */
367 375 uuid_copy(&dqblk->dd_uuid, &sc->mp->m_sb.sb_meta_uuid);
368 376 xfs_update_cksum((char *)dqblk, sizeof(struct xfs_dqblk),
369 377 XFS_DQUOT_CRC_OFF);
370 - dqblk->dd_lsn = 0;
371 378 }
372 379 switch (dqtype) {
373 380 case XFS_DQTYPE_USER:
@@ -455,8 +462,7 @@ xrep_quota_data_fork(
455 462
456 463 if (truncate) {
457 464 /* Erase everything after the block containing the max dquot */
458 - error = xfs_bunmapi_range(&sc->tp, sc->ip, 0,
459 - max_dqid_off * sc->mp->m_sb.sb_blocksize,
465 + error = xfs_bunmapi_range(&sc->tp, sc->ip, 0, max_dqid_off + 1,
460 466 XFS_MAX_FILEOFF);
461 467 if (error)
462 468 goto out;
modified fs/xfs/scrub/quotacheck.c
@@ -263,8 +263,10 @@ xqcheck_mod_live_ino_dqtrx(
263 263 dqa->tx_id = p->tx_id;
264 264 error = rhashtable_insert_fast(&xqc->shadow_dquot_acct,
265 265 &dqa->hash, xqcheck_dqacct_hash_params);
266 - if (error)
266 + if (error) {
267 + kfree(dqa);
267 268 goto out_abort;
269 + }
268 270 }
269 271
270 272 /* Find the shadow dqtrx (or an empty slot) here. */
modified fs/xfs/scrub/reap.c
@@ -601,7 +601,7 @@ xreap_configure_agextent_limits(
601 601
602 602 /* Maximum overhead of invalidating one buffer. */
603 603 const unsigned int per_binval =
604 - xfs_buf_inval_log_space(1, XFS_B_TO_FSBT(mp, max_binval));
604 + xfs_buf_inval_log_space(1, XFS_FSB_TO_B(mp, max_binval));
605 605
606 606 /*
607 607 * For each transaction in a reap chain, we can delete some number of
@@ -680,7 +680,7 @@ xreap_configure_agcow_limits(
680 680
681 681 /* Overhead of invalidating one buffer */
682 682 const unsigned int per_binval =
683 - xfs_buf_inval_log_space(1, XFS_B_TO_FSBT(mp, max_binval));
683 + xfs_buf_inval_log_space(1, XFS_FSB_TO_B(mp, max_binval));
684 684
685 685 /*
686 686 * For each transaction in a reap chain, we can delete some number of
@@ -1399,7 +1399,7 @@ xreap_bmapi_binval(
1399 1399 * far we've gotten.
1400 1400 */
1401 1401 if (!xreap_inc_binval(rs)) {
1402 - imap->br_blockcount = agbno_next - bno;
1402 + imap->br_blockcount = bno - agbno;
1403 1403 goto out;
1404 1404 }
1405 1405 }
modified fs/xfs/scrub/refcount.c
@@ -410,7 +410,7 @@ xchk_refcount_mergeable(
410 410 const struct xfs_refcount_irec *r1 = &rrc->prev_rec;
411 411
412 412 /* Ignore if prev_rec is not yet initialized. */
413 - if (r1->rc_blockcount > 0)
413 + if (r1->rc_blockcount == 0)
414 414 return false;
415 415
416 416 if (r1->rc_domain != r2->rc_domain)
@@ -581,8 +581,12 @@ xchk_xref_is_cow_staging(
581 581 if (rc.rc_domain != XFS_REFC_DOMAIN_COW)
582 582 xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
583 583
584 + /* Can't start after bno */
585 + if (rc.rc_startblock > agbno)
586 + xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
587 +
584 588 /* Must be at least as long as what was passed in */
585 - if (rc.rc_blockcount < len)
589 + if (rc.rc_startblock + rc.rc_blockcount < agbno + len)
586 590 xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
587 591 }
588 592
modified fs/xfs/scrub/rgsuper.c
@@ -36,8 +36,10 @@ xchk_rgsuperblock_xref(
36 36 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
37 37 return;
38 38
39 - xchk_xref_is_used_rt_space(sc, xfs_rgbno_to_rtb(sc->sr.rtg, 0), 1);
40 - xchk_xref_is_only_rt_owned_by(sc, 0, 1, &XFS_RMAP_OINFO_FS);
39 + xchk_xref_is_used_rt_space(sc, xfs_rgbno_to_rtb(sc->sr.rtg, 0),
40 + sc->mp->m_sb.sb_rextsize);
41 + xchk_xref_is_only_rt_owned_by(sc, 0, sc->mp->m_sb.sb_rextsize,
42 + &XFS_RMAP_OINFO_FS);
41 43 }
42 44
43 45 int
modified fs/xfs/scrub/rtrefcount.c
@@ -20,6 +20,7 @@
20 20 #include "xfs_metafile.h"
21 21 #include "xfs_rtrefcount_btree.h"
22 22 #include "xfs_rtalloc.h"
23 + #include "xfs_ag.h"
23 24 #include "scrub/scrub.h"
24 25 #include "scrub/common.h"
25 26 #include "scrub/btree.h"
@@ -375,7 +376,7 @@ xchk_rtrefcount_mergeable(
375 376 const struct xfs_refcount_irec *r1 = &rrc->prev_rec;
376 377
377 378 /* Ignore if prev_rec is not yet initialized. */
378 - if (r1->rc_blockcount > 0)
379 + if (r1->rc_blockcount == 0)
379 380 return false;
380 381
381 382 if (r1->rc_startblock + r1->rc_blockcount != r2->rc_startblock)
@@ -428,7 +429,7 @@ static inline void
428 429 xchk_rtrefcountbt_xref_gaps(
429 430 struct xfs_scrub *sc,
430 431 struct xchk_rtrefcbt_records *rrc,
431 - xfs_rtblock_t bno)
432 + xfs_rgblock_t bno)
432 433 {
433 434 struct xfs_rmap_irec low;
434 435 struct xfs_rmap_irec high;
@@ -504,30 +505,75 @@ xchk_rtrefcountbt_rec(
504 505 return 0;
505 506 }
506 507
508 + /* Count the number of blocks used by the rtrefcount btree file in this AG. */
509 + static int
510 + xchk_rtrefcount_count_agblocks(
511 + struct xfs_scrub *sc,
512 + xfs_agnumber_t agno,
513 + const struct xfs_owner_info *btree_oinfo,
514 + xfs_filblks_t *blocks)
515 + {
516 + xfs_filblks_t agblocks = 0;
517 + int error;
518 +
519 + error = xchk_ag_init_existing(sc, agno, &sc->sa);
520 + if (error)
521 + goto out_free;
522 +
523 + /*
524 + * If we don't have an rmap cursor, we can't complete the cross
525 + * referencing, so return EFSCORRUPTED to end the loop and trigger the
526 + * XFAIL flag.
527 + */
528 + if (!sc->sa.rmap_cur) {
529 + error = -EFSCORRUPTED;
530 + goto out_free;
531 + }
532 +
533 + error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, btree_oinfo,
534 + &agblocks);
535 + if (error)
536 + goto out_free;
537 +
538 + *blocks += agblocks;
539 + out_free:
540 + xchk_ag_free(sc, &sc->sa);
541 + return error;
542 + }
543 +
507 544 /* Make sure we have as many refc blocks as the rmap says. */
508 545 STATIC void
509 - xchk_refcount_xref_rmap(
546 + xchk_rtrefcount_xref_rmap(
510 547 struct xfs_scrub *sc,
511 548 const struct xfs_owner_info *btree_oinfo,
512 549 xfs_extlen_t cow_blocks)
513 550 {
514 551 xfs_filblks_t refcbt_blocks = 0;
515 - xfs_filblks_t blocks;
516 - int error;
552 + xfs_filblks_t blocks = 1; /* one for the iroot */
553 + xfs_agnumber_t agno;
554 + int error = 0;
517 555
518 - if (!sc->sr.rmap_cur || !sc->sa.rmap_cur || xchk_skip_xref(sc->sm))
556 + if (!xfs_has_rmapbt(sc->mp) || xchk_skip_xref(sc->sm))
519 557 return;
520 558
521 559 /* Check that we saw as many refcbt blocks as the rmap knows about. */
522 560 error = xfs_btree_count_blocks(sc->sr.refc_cur, &refcbt_blocks);
523 561 if (!xchk_btree_process_error(sc, sc->sr.refc_cur, 0, &error))
524 562 return;
525 - error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, btree_oinfo,
526 - &blocks);
527 - if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
563 +
564 + for (agno = 0; agno < sc->mp->m_sb.sb_agcount; agno++) {
565 + error = xchk_rtrefcount_count_agblocks(sc, agno, btree_oinfo,
566 + &blocks);
567 + if (error)
568 + break;
569 + }
570 + if (!xchk_fblock_xref_process_error(sc, XFS_DATA_FORK, 0, &error))
528 571 return;
529 572 if (blocks != refcbt_blocks)
530 - xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
573 + xchk_fblock_xref_set_corrupt(sc, XFS_DATA_FORK, 0);
574 +
575 + if (!sc->sr.rmap_cur || xchk_skip_xref(sc->sm))
576 + return;
531 577
532 578 /* Check that we saw as many cow blocks as the rmap knows about. */
533 579 error = xchk_count_rmap_ownedby_ag(sc, sc->sr.rmap_cur,
@@ -538,7 +584,7 @@ xchk_refcount_xref_rmap(
538 584 xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
539 585 }
540 586
541 - /* Scrub the refcount btree for some AG. */
587 + /* Scrub the refcount btree for some rtgroup. */
542 588 int
543 589 xchk_rtrefcountbt(
544 590 struct xfs_scrub *sc)
@@ -564,11 +610,11 @@ xchk_rtrefcountbt(
564 610
565 611 /*
566 612 * Check that all blocks between the last refcount > 1 record and the
567 - * end of the rt volume have at most one reverse mapping.
613 + * end of the rtgroup have at most one reverse mapping.
568 614 */
569 - xchk_rtrefcountbt_xref_gaps(sc, &rrc, sc->mp->m_sb.sb_rblocks);
570 -
571 - xchk_refcount_xref_rmap(sc, &btree_oinfo, rrc.cow_blocks);
615 + xchk_rtrefcountbt_xref_gaps(sc, &rrc,
616 + xfs_rtx_to_rgbno(sc->sr.rtg, sc->mp->m_sb.sb_rgextents));
617 + xchk_rtrefcount_xref_rmap(sc, &btree_oinfo, rrc.cow_blocks);
572 618
573 619 return 0;
574 620 }
@@ -609,8 +655,12 @@ xchk_xref_is_rt_cow_staging(
609 655 if (rc.rc_domain != XFS_REFC_DOMAIN_COW)
610 656 xchk_btree_xref_set_corrupt(sc, sc->sr.refc_cur, 0);
611 657
658 + /* Can't start after bno */
659 + if (rc.rc_startblock > bno)
660 + xchk_btree_xref_set_corrupt(sc, sc->sr.refc_cur, 0);
661 +
612 662 /* Must be at least as long as what was passed in */
613 - if (rc.rc_blockcount < len)
663 + if (rc.rc_startblock + rc.rc_blockcount < bno + len)
614 664 xchk_btree_xref_set_corrupt(sc, sc->sr.refc_cur, 0);
615 665 }
616 666
modified fs/xfs/scrub/rtsummary_repair.c
@@ -164,9 +164,10 @@ xrep_rtsummary(
164 164 /*
165 165 * Now exchange the contents. Nothing in repair uses the temporary
166 166 * buffer, so we can reuse it for the tempfile exchrange information.
167 + * Use XFS_MAX_FILEOFF here so that we correct the rtsummary file size.
167 168 */
168 169 error = xrep_tempexch_trans_reserve(sc, XFS_DATA_FORK, 0,
169 - rts->rsumblocks, &rts->tempexch);
170 + XFS_MAX_FILEOFF, &rts->tempexch);
170 171 if (error)
171 172 return error;
172 173
modified fs/xfs/scrub/scrub.c
@@ -765,8 +765,7 @@ out_nofix:
765 765 out_teardown:
766 766 error = xchk_teardown(sc, error);
767 767 out_sc:
768 - if (error != -ENOENT)
769 - xchk_stats_merge(mp, sm, &run);
768 + xchk_stats_merge(mp, sm, error, &run);
770 769 kfree(sc);
771 770 out:
772 771 trace_xchk_done(XFS_I(file_inode(file)), sm, error);
modified fs/xfs/scrub/scrub.h
@@ -261,7 +261,6 @@ static inline int xchk_nothing(struct xfs_scrub *sc)
261 261 }
262 262
263 263 /* Metadata scrubbers */
264 - int xchk_tester(struct xfs_scrub *sc);
265 264 int xchk_superblock(struct xfs_scrub *sc);
266 265 int xchk_agf(struct xfs_scrub *sc);
267 266 int xchk_agfl(struct xfs_scrub *sc);
modified fs/xfs/scrub/stats.c
@@ -29,6 +29,7 @@ struct xchk_scrub_stats {
29 29 uint32_t incomplete;
30 30 uint32_t warning;
31 31 uint32_t retries;
32 + uint32_t runtime_errors;
32 33
33 34 /* repair stats */
34 35 uint32_t repair_invocations;
@@ -84,6 +85,7 @@ static const char *name_map[XFS_SCRUB_TYPE_NR] = {
84 85 [XFS_SCRUB_TYPE_RGSUPER] = "rgsuper",
85 86 [XFS_SCRUB_TYPE_RTRMAPBT] = "rtrmapbt",
86 87 [XFS_SCRUB_TYPE_RTREFCBT] = "rtrefcountbt",
88 + [XFS_SCRUB_TYPE_HEALTHY] = "healthy",
87 89 };
88 90
89 91 /* Format the scrub stats into a text buffer, similar to pcp style. */
@@ -99,25 +101,32 @@ xchk_stats_format(
99 101 int ret = 0;
100 102
101 103 for (i = 0; i < XFS_SCRUB_TYPE_NR; i++, css++) {
104 + struct xchk_scrub_stats fss;
105 +
102 106 if (!name_map[i])
103 107 continue;
104 108
109 + spin_lock(&css->css_lock);
110 + memcpy(&fss, css, offsetof(struct xchk_scrub_stats, css_lock));
111 + spin_unlock(&css->css_lock);
112 +
105 113 ret = scnprintf(buf, remaining,
106 - "%s %u %u %u %u %u %u %u %u %u %llu %u %u %llu\n",
114 + "%s %u %u %u %u %u %u %u %u %u %llu %u %u %llu %u\n",
107 115 name_map[i],
108 - (unsigned int)css->invocations,
109 - (unsigned int)css->clean,
110 - (unsigned int)css->corrupt,
111 - (unsigned int)css->preen,
112 - (unsigned int)css->xfail,
113 - (unsigned int)css->xcorrupt,
114 - (unsigned int)css->incomplete,
115 - (unsigned int)css->warning,
116 - (unsigned int)css->retries,
117 - (unsigned long long)css->checktime_us,
118 - (unsigned int)css->repair_invocations,
119 - (unsigned int)css->repair_success,
120 - (unsigned long long)css->repairtime_us);
116 + (unsigned int)fss.invocations,
117 + (unsigned int)fss.clean,
118 + (unsigned int)fss.corrupt,
119 + (unsigned int)fss.preen,
120 + (unsigned int)fss.xfail,
121 + (unsigned int)fss.xcorrupt,
122 + (unsigned int)fss.incomplete,
123 + (unsigned int)fss.warning,
124 + (unsigned int)fss.retries,
125 + (unsigned long long)fss.checktime_us,
126 + (unsigned int)fss.repair_invocations,
127 + (unsigned int)fss.repair_success,
128 + (unsigned long long)fss.repairtime_us,
129 + (unsigned int)fss.runtime_errors);
121 130 if (ret <= 0)
122 131 break;
123 132
@@ -188,31 +197,41 @@ STATIC void
188 197 xchk_stats_merge_one(
189 198 struct xchk_stats *cs,
190 199 const struct xfs_scrub_metadata *sm,
200 + int error,
191 201 const struct xchk_stats_run *run)
192 202 {
193 203 struct xchk_scrub_stats *css;
204 + unsigned int sm_flags = sm->sm_flags;
194 205
195 206 if (sm->sm_type >= XFS_SCRUB_TYPE_NR) {
196 207 ASSERT(sm->sm_type < XFS_SCRUB_TYPE_NR);
197 208 return;
198 209 }
199 210
211 + /* caller applies this same transformation after we return */
212 + if (error == -EFSCORRUPTED || error == -EFSBADCRC) {
213 + sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
214 + error = 0;
215 + }
216 +
200 217 css = &cs->cs_stats[sm->sm_type];
201 218 spin_lock(&css->css_lock);
202 219 css->invocations++;
203 - if (!(sm->sm_flags & XFS_SCRUB_OFLAG_UNCLEAN))
220 + if (error)
221 + css->runtime_errors++;
222 + else if (!(sm_flags & XFS_SCRUB_OFLAG_UNCLEAN))
204 223 css->clean++;
205 - if (sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
224 + if (sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
206 225 css->corrupt++;
207 - if (sm->sm_flags & XFS_SCRUB_OFLAG_PREEN)
226 + if (sm_flags & XFS_SCRUB_OFLAG_PREEN)
208 227 css->preen++;
209 - if (sm->sm_flags & XFS_SCRUB_OFLAG_XFAIL)
228 + if (sm_flags & XFS_SCRUB_OFLAG_XFAIL)
210 229 css->xfail++;
211 - if (sm->sm_flags & XFS_SCRUB_OFLAG_XCORRUPT)
230 + if (sm_flags & XFS_SCRUB_OFLAG_XCORRUPT)
212 231 css->xcorrupt++;
213 - if (sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
232 + if (sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE)
214 233 css->incomplete++;
215 - if (sm->sm_flags & XFS_SCRUB_OFLAG_WARNING)
234 + if (sm_flags & XFS_SCRUB_OFLAG_WARNING)
216 235 css->warning++;
217 236 css->retries += run->retries;
218 237 css->checktime_us += howmany_64(run->scrub_ns, NSEC_PER_USEC);
@@ -230,10 +249,14 @@ void
230 249 xchk_stats_merge(
231 250 struct xfs_mount *mp,
232 251 const struct xfs_scrub_metadata *sm,
252 + int error,
233 253 const struct xchk_stats_run *run)
234 254 {
235 - xchk_stats_merge_one(&global_stats, sm, run);
236 - xchk_stats_merge_one(mp->m_scrub_stats, sm, run);
255 + if (error == -ENOENT)
256 + return;
257 +
258 + xchk_stats_merge_one(&global_stats, sm, error, run);
259 + xchk_stats_merge_one(mp->m_scrub_stats, sm, error, run);
237 260 }
238 261
239 262 /* debugfs boilerplate */
modified fs/xfs/scrub/stats.h
@@ -27,7 +27,7 @@ void xchk_stats_register(struct xchk_stats *cs, struct dentry *parent);
27 27 void xchk_stats_unregister(struct xchk_stats *cs);
28 28
29 29 void xchk_stats_merge(struct xfs_mount *mp, const struct xfs_scrub_metadata *sm,
30 - const struct xchk_stats_run *run);
30 + int error, const struct xchk_stats_run *run);
31 31
32 32 static inline u64 xchk_stats_now(void) { return ktime_get_ns(); }
33 33 static inline u64 xchk_stats_elapsed_ns(u64 since)
@@ -53,7 +53,7 @@ static inline u64 xchk_stats_elapsed_ns(u64 since)
53 53 # define xchk_stats_unregister(cs) ((void)0)
54 54 # define xchk_stats_now() (0)
55 55 # define xchk_stats_elapsed_ns(x) (0 * (x))
56 - # define xchk_stats_merge(mp, sm, run) ((void)0)
56 + # define xchk_stats_merge(mp, sm, error, run) ((void)0)
57 57 #endif /* CONFIG_XFS_ONLINE_SCRUB_STATS */
58 58
59 59 #endif /* __XFS_SCRUB_STATS_H__ */
modified fs/xfs/scrub/tempfile.c
@@ -649,6 +649,19 @@ xrep_tempexch_prep_request(
649 649 return 0;
650 650 }
651 651
652 + static inline unsigned int
653 + xrep_tempexch_estimate_sf_resblks(
654 + struct xfs_scrub *sc,
655 + int whichfork)
656 + {
657 + /* repairing a symlink target */
658 + if (S_ISLNK(VFS_I(sc->ip)->i_mode) && whichfork == XFS_DATA_FORK)
659 + return 1;
660 +
661 + /* everything else is a directory or an xattr structure */
662 + return xfs_dabuf_nfsb(sc->mp, whichfork);
663 + }
664 +
652 665 /*
653 666 * Fill out the mapping exchange resource estimation structures in preparation
654 667 * for exchanging the contents of a metadata file that we've rebuilt in the
@@ -663,6 +676,8 @@ xrep_tempexch_estimate(
663 676 struct xfs_ifork *ifp;
664 677 struct xfs_ifork *tifp;
665 678 int whichfork = xfs_exchmaps_reqfork(req);
679 + unsigned int sf_resblks =
680 + xrep_tempexch_estimate_sf_resblks(sc, whichfork);
666 681 int state = 0;
667 682
668 683 /*
@@ -693,9 +708,9 @@ xrep_tempexch_estimate(
693 708 * plus the block we converted.
694 709 */
695 710 req->ip1_bcount = sc->tempip->i_nblocks;
696 - req->ip2_bcount = 1;
711 + req->ip2_bcount = sf_resblks;
697 712 req->nr_exchanges = 1 + tifp->if_nextents;
698 - req->resblks = 1;
713 + req->resblks = sf_resblks;
699 714 break;
700 715 case 2:
701 716 /*
@@ -707,10 +722,10 @@ xrep_tempexch_estimate(
707 722 * is (worst case) the extent count of the file being repaired
708 723 * plus the block we converted.
709 724 */
710 - req->ip1_bcount = 1;
725 + req->ip1_bcount = sf_resblks;
711 726 req->ip2_bcount = sc->ip->i_nblocks;
712 727 req->nr_exchanges = 1 + ifp->if_nextents;
713 - req->resblks = 1;
728 + req->resblks = sf_resblks;
714 729 break;
715 730 case 3:
716 731 /*
@@ -722,10 +737,10 @@ xrep_tempexch_estimate(
722 737 * fileoff 0. Presumably, the caller could not exchange the
723 738 * two inode fork areas directly.
724 739 */
725 - req->ip1_bcount = 1;
726 - req->ip2_bcount = 1;
740 + req->ip1_bcount = sf_resblks;
741 + req->ip2_bcount = sf_resblks;
727 742 req->nr_exchanges = 1;
728 - req->resblks = 2;
743 + req->resblks = 2 * sf_resblks;
729 744 break;
730 745 }
731 746
modified fs/xfs/scrub/tempfile.h
@@ -39,10 +39,6 @@ int xrep_tempfile_roll_trans(struct xfs_scrub *sc);
39 39 void xrep_tempfile_copyout_local(struct xfs_scrub *sc, int whichfork);
40 40 bool xrep_is_tempfile(const struct xfs_inode *ip);
41 41 #else
42 - static inline void xrep_tempfile_iolock_both(struct xfs_scrub *sc)
43 - {
44 - xchk_ilock(sc, XFS_IOLOCK_EXCL);
45 - }
46 42 # define xrep_is_tempfile(ip) (false)
47 43 # define xrep_tempfile_adjust_directory_tree(sc) (0)
48 44 # define xrep_tempfile_rele(sc)
modified fs/xfs/scrub/trace.h
@@ -1640,7 +1640,7 @@ DECLARE_EVENT_CLASS(xchk_pptr_class,
1640 1640 __entry->dev = ip->i_mount->m_super->s_dev;
1641 1641 __entry->ino = I_INO(ip);
1642 1642 __entry->namelen = name->len;
1643 - memcpy(__get_str(name), name, name->len);
1643 + memcpy(__get_str(name), name->name, name->len);
1644 1644 __entry->far_ino = far_ino;
1645 1645 ),
1646 1646 TP_printk("dev %d:%d ino 0x%llx name '%.*s' far_ino 0x%llx",
@@ -1706,6 +1706,39 @@ DEFINE_EVENT(xchk_dirtree_class, name, \
1706 1706 DEFINE_XCHK_DIRTREE_EVENT(xchk_dirtree_create_path);
1707 1707 DEFINE_XCHK_DIRTREE_EVENT(xchk_dirpath_walk_upwards);
1708 1708
1709 + TRACE_EVENT(xchk_dirpath_badino,
1710 + TP_PROTO(struct xfs_scrub *sc, unsigned int path_nr,
1711 + unsigned int step_nr, const struct xfs_name *name,
1712 + const struct xfs_parent_rec *pptr),
1713 + TP_ARGS(sc, path_nr, step_nr, name, pptr),
1714 + TP_STRUCT__entry(
1715 + __field(dev_t, dev)
1716 + __field(unsigned int, path_nr)
1717 + __field(unsigned int, step_nr)
1718 + __field(xfs_ino_t, parent_ino)
1719 + __field(unsigned int, parent_gen)
1720 + __field(unsigned int, namelen)
1721 + __dynamic_array(char, name, name->len)
1722 + ),
1723 + TP_fast_assign(
1724 + __entry->dev = sc->mp->m_super->s_dev;
1725 + __entry->path_nr = path_nr;
1726 + __entry->step_nr = step_nr;
1727 + __entry->parent_ino = be64_to_cpu(pptr->p_ino);
1728 + __entry->parent_gen = be32_to_cpu(pptr->p_gen);
1729 + __entry->namelen = name->len;
1730 + memcpy(__get_str(name), name->name, name->len);
1731 + ),
1732 + TP_printk("dev %d:%d path %u step %u parent_ino 0x%llx parent_gen 0x%x name '%.*s'",
1733 + MAJOR(__entry->dev), MINOR(__entry->dev),
1734 + __entry->path_nr,
1735 + __entry->step_nr,
1736 + __entry->parent_ino,
1737 + __entry->parent_gen,
1738 + __entry->namelen,
1739 + __get_str(name))
1740 + );
1741 +
1709 1742 DECLARE_EVENT_CLASS(xchk_dirpath_class,
1710 1743 TP_PROTO(struct xfs_scrub *sc, struct xfs_inode *ip,
1711 1744 unsigned int path_nr, unsigned int step_nr,
modified fs/xfs/xfs_buf.c
@@ -139,7 +139,7 @@ xfs_buf_free(
139 139 ASSERT(list_empty(&bp->b_lru));
140 140
141 141 if (!xfs_buftarg_is_mem(bp->b_target) && size >= PAGE_SIZE)
142 - mm_account_reclaimed_pages(howmany(size, PAGE_SHIFT));
142 + mm_account_reclaimed_pages(howmany(size, PAGE_SIZE));
143 143
144 144 if (is_vmalloc_addr(bp->b_addr))
145 145 vfree(bp->b_addr);
@@ -176,7 +176,7 @@ xfs_buf_alloc_kmem(
176 176 ASSERT(is_power_of_2(size));
177 177 ASSERT(size < PAGE_SIZE);
178 178
179 - bp->b_addr = kmalloc(size, gfp_mask);
179 + bp->b_addr = kmalloc(size, gfp_mask | __GFP_RECLAIMABLE);
180 180 if (!bp->b_addr)
181 181 return -ENOMEM;
182 182
modified fs/xfs/xfs_buf_item.h
@@ -60,7 +60,6 @@ static inline void xfs_buf_dquot_iodone(struct xfs_buf *bp)
60 60 {
61 61 }
62 62 #endif /* CONFIG_XFS_QUOTA */
63 - void xfs_buf_iodone(struct xfs_buf *);
64 63 bool xfs_buf_log_check_iovec(struct kvec *iovec);
65 64
66 65 unsigned int xfs_buf_inval_log_space(unsigned int map_count,
modified fs/xfs/xfs_exchmaps_item.c
@@ -344,7 +344,17 @@ xfs_xmi_validate(
344 344 if (!xfs_verify_fileext(mp, xlf->xmi_startoff1, xlf->xmi_blockcount))
345 345 return false;
346 346
347 - return xfs_verify_fileext(mp, xlf->xmi_startoff2, xlf->xmi_blockcount);
347 + if (!xfs_verify_fileext(mp, xlf->xmi_startoff2, xlf->xmi_blockcount))
348 + return false;
349 +
350 + if (xlf->xmi_flags & XFS_EXCHMAPS_SET_SIZES) {
351 + if ((int64_t)xlf->xmi_isize1 < 0)
352 + return false;
353 + if ((int64_t)xlf->xmi_isize2 < 0)
354 + return false;
355 + }
356 +
357 + return true;
348 358 }
349 359
350 360 /*
@@ -403,6 +413,13 @@ xfs_xmi_item_recover_intent(
403 413 *ipp1 = ip1;
404 414 *ipp2 = ip2;
405 415 xmi = xfs_exchmaps_init_intent(req);
416 +
417 + /* Restore intended file sizes from recovered logged item */
418 + if (req->flags & XFS_EXCHMAPS_SET_SIZES) {
419 + xmi->xmi_isize1 = xlf->xmi_isize1;
420 + xmi->xmi_isize2 = xlf->xmi_isize2;
421 + }
422 +
406 423 xfs_defer_add_item(dfp, &xmi->xmi_list);
407 424 return xmi;
408 425
modified fs/xfs/xfs_exchrange.c
@@ -504,6 +504,9 @@ xfs_exchange_range_finish(
504 504 {
505 505 int error;
506 506
507 + if (fxr->flags & XFS_EXCHANGE_RANGE_DRY_RUN)
508 + return 0;
509 +
507 510 error = file_remove_privs(fxr->file1);
508 511 if (error)
509 512 return error;
@@ -783,9 +786,12 @@ xfs_exchange_range(
783 786 if (ret)
784 787 return ret;
785 788
786 - fsnotify_modify(fxr->file1);
787 - if (fxr->file2 != fxr->file1)
788 - fsnotify_modify(fxr->file2);
789 + if (!(fxr->flags & XFS_EXCHANGE_RANGE_DRY_RUN)) {
790 + fsnotify_modify(fxr->file1);
791 + if (fxr->file2 != fxr->file1)
792 + fsnotify_modify(fxr->file2);
793 + }
794 +
789 795 return 0;
790 796 }
791 797
modified fs/xfs/xfs_extent_busy.c
@@ -161,8 +161,8 @@ xfs_extent_busy_update_extent(
161 161 xfs_agblock_t fbno,
162 162 xfs_extlen_t flen,
163 163 bool userdata)
164 - __releases(&eb->eb_lock)
165 - __acquires(&eb->eb_lock)
164 + __releases(&xg->xg_busy_extents->eb_lock)
165 + __acquires(&xg->xg_busy_extents->eb_lock)
166 166 {
167 167 struct xfs_extent_busy_tree *eb = xg->xg_busy_extents;
168 168 xfs_agblock_t fend = fbno + flen;
modified fs/xfs/xfs_file.c
@@ -129,9 +129,8 @@ xfs_file_fsync(
129 129 int datasync)
130 130 {
131 131 struct xfs_inode *ip = XFS_I(file->f_mapping->host);
132 - struct xfs_mount *mp = ip->i_mount;
133 - int error, err2;
134 132 int log_flushed = 0;
133 + int error;
135 134
136 135 trace_xfs_file_fsync(ip);
137 136
@@ -139,30 +138,22 @@ xfs_file_fsync(
139 138 if (error)
140 139 return error;
141 140
142 - if (xfs_is_shutdown(mp))
141 + if (xfs_is_shutdown(ip->i_mount))
143 142 return -EIO;
144 143
145 144 xfs_iflags_clear(ip, XFS_ITRUNCATED);
146 145
147 146 /*
148 - * If we have an RT and/or log subvolume we need to make sure to flush
149 - * the write cache the device used for file data first. This is to
150 - * ensure newly written file data make it to disk before logging the new
151 - * inode size in case of an extending write.
152 - */
153 - if (XFS_IS_REALTIME_INODE(ip) && mp->m_rtdev_targp != mp->m_ddev_targp)
154 - error = blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev);
155 - else if (mp->m_logdev_targp != mp->m_ddev_targp)
156 - error = blkdev_issue_flush(mp->m_ddev_targp->bt_bdev);
157 -
158 - /*
159 - * If the inode has a inode log item attached, it may need the journal
160 - * flushed to persist any changes the log item might be tracking.
147 + * If the inode has a log item attached, we must force the log up to the
148 + * last LSN in which the inode was modified to ensure all metadata is
149 + * persisted. The log force will flush the caches for all devices
150 + * before writing the log records unless it is a no-op because there are
151 + * no modifications to this inode that need to be pushed out.
161 152 */
162 153 if (ip->i_itemp) {
163 - err2 = xfs_fsync_flush_log(ip, datasync, &log_flushed);
164 - if (err2 && !error)
165 - error = err2;
154 + error = xfs_fsync_flush_log(ip, datasync, &log_flushed);
155 + if (error)
156 + return error;
166 157 }
167 158
168 159 /*
@@ -171,21 +162,11 @@ xfs_file_fsync(
171 162 * when no metadata needed to be committed.
172 163 *
173 164 * Use the inode's actual file data target rather than assuming the
174 - * main data device. Realtime inodes with a separate realtime device
175 - * are flushed before the log force, so this fallback only applies
176 - * when the file data target is the same as the log target.
165 + * main data device.
177 166 */
178 - if (!log_flushed) {
179 - struct xfs_buftarg *file_targp = xfs_inode_buftarg(ip);
180 -
181 - if (mp->m_logdev_targp == file_targp) {
182 - err2 = blkdev_issue_flush(file_targp->bt_bdev);
183 - if (err2 && !error)
184 - error = err2;
185 - }
186 - }
187 -
188 - return error;
167 + if (!log_flushed)
168 + return blkdev_issue_flush(xfs_inode_buftarg(ip)->bt_bdev);
169 + return 0;
189 170 }
190 171
191 172 static int
modified fs/xfs/xfs_healthmon.c
@@ -87,12 +87,10 @@ xfs_healthmon_put(
87 87 struct xfs_healthmon *hm)
88 88 {
89 89 if (refcount_dec_and_test(&hm->ref)) {
90 - struct xfs_healthmon_event *event;
91 - struct xfs_healthmon_event *next = hm->first_event;
90 + struct xfs_healthmon_event *event, *s;
92 91
93 - while ((event = next) != NULL) {
92 + list_for_each_entry_safe(event, s, &hm->event_list, entry) {
94 93 trace_xfs_healthmon_drop(hm, event);
95 - next = event->next;
96 94 kfree(event);
97 95 }
98 96
@@ -173,9 +171,13 @@ static inline void xfs_healthmon_bump_lost(struct xfs_healthmon *hm)
173 171 */
174 172 static bool
175 173 xfs_healthmon_merge_events(
176 - struct xfs_healthmon_event *existing,
174 + struct xfs_healthmon *hm,
177 175 const struct xfs_healthmon_event *new)
178 176 {
177 + struct xfs_healthmon_event *existing =
178 + list_last_entry_or_null(&hm->event_list, struct
179 + xfs_healthmon_event, entry);
180 +
179 181 if (!existing)
180 182 return false;
181 183
@@ -192,7 +194,7 @@ xfs_healthmon_merge_events(
192 194
193 195 case XFS_HEALTHMON_LOST:
194 196 existing->lostcount += new->lostcount;
195 - return true;
197 + goto out_merge;
196 198
197 199 case XFS_HEALTHMON_SICK:
198 200 case XFS_HEALTHMON_CORRUPT:
@@ -200,19 +202,19 @@ xfs_healthmon_merge_events(
200 202 switch (existing->domain) {
201 203 case XFS_HEALTHMON_FS:
202 204 existing->fsmask |= new->fsmask;
203 - return true;
205 + goto out_merge;
204 206 case XFS_HEALTHMON_AG:
205 207 case XFS_HEALTHMON_RTGROUP:
206 208 if (existing->group == new->group){
207 209 existing->grpmask |= new->grpmask;
208 - return true;
210 + goto out_merge;
209 211 }
210 212 return false;
211 213 case XFS_HEALTHMON_INODE:
212 214 if (existing->ino == new->ino &&
213 215 existing->gen == new->gen) {
214 216 existing->imask |= new->imask;
215 - return true;
217 + goto out_merge;
216 218 }
217 219 return false;
218 220 default:
@@ -224,18 +226,18 @@ xfs_healthmon_merge_events(
224 226 case XFS_HEALTHMON_SHUTDOWN:
225 227 /* yes, we can race to shutdown */
226 228 existing->flags |= new->flags;
227 - return true;
229 + goto out_merge;
228 230
229 231 case XFS_HEALTHMON_MEDIA_ERROR:
230 232 /* physically adjacent errors can merge */
231 233 if (existing->daddr + existing->bbcount == new->daddr) {
232 234 existing->bbcount += new->bbcount;
233 - return true;
235 + goto out_merge;
234 236 }
235 237 if (new->daddr + new->bbcount == existing->daddr) {
236 238 existing->daddr = new->daddr;
237 239 existing->bbcount += new->bbcount;
238 - return true;
240 + goto out_merge;
239 241 }
240 242 return false;
241 243
@@ -250,63 +252,58 @@ xfs_healthmon_merge_events(
250 252
251 253 if (existing->fpos + existing->flen == new->fpos) {
252 254 existing->flen += new->flen;
253 - return true;
255 + goto out_merge;
254 256 }
255 257
256 258 if (new->fpos + new->flen == existing->fpos) {
257 259 existing->fpos = new->fpos;
258 260 existing->flen += new->flen;
259 - return true;
261 + goto out_merge;
260 262 }
261 263 return false;
262 264 }
263 265
264 266 return false;
267 +
268 + out_merge:
269 + trace_xfs_healthmon_merge(hm, existing);
270 + return true;
265 271 }
266 272
267 - /* Insert an event onto the start of the queue. */
273 + enum insert_where {
274 + INSERT_HEAD,
275 + INSERT_TAIL,
276 + };
277 +
278 + /* Add an event onto the start or the end of the queue. */
268 279 static inline void
269 280 __xfs_healthmon_insert(
270 281 struct xfs_healthmon *hm,
282 + enum insert_where where,
271 283 struct xfs_healthmon_event *event)
272 284 {
273 285 struct timespec64 now;
274 286
287 + lockdep_assert_held(&hm->lock);
288 +
275 289 ktime_get_coarse_real_ts64(&now);
276 290 event->time_ns = (now.tv_sec * NSEC_PER_SEC) + now.tv_nsec;
277 291
278 - event->next = hm->first_event;
279 - if (!hm->first_event)
280 - hm->first_event = event;
281 - if (!hm->last_event)
282 - hm->last_event = event;
283 - xfs_healthmon_bump_events(hm);
284 - wake_up(&hm->wait);
285 -
286 - trace_xfs_healthmon_insert(hm, event);
287 - }
292 + switch (where) {
293 + case INSERT_HEAD:
294 + trace_xfs_healthmon_insert_head(hm, event);
288 295
289 - /* Push an event onto the end of the queue. */
290 - static inline void
291 - __xfs_healthmon_push(
292 - struct xfs_healthmon *hm,
293 - struct xfs_healthmon_event *event)
294 - {
295 - struct timespec64 now;
296 + list_add(&event->entry, &hm->event_list);
297 + break;
298 + case INSERT_TAIL:
299 + trace_xfs_healthmon_insert_tail(hm, event);
296 300
297 - ktime_get_coarse_real_ts64(&now);
298 - event->time_ns = (now.tv_sec * NSEC_PER_SEC) + now.tv_nsec;
301 + list_add_tail(&event->entry, &hm->event_list);
302 + break;
303 + }
299 304
300 - if (!hm->first_event)
301 - hm->first_event = event;
302 - if (hm->last_event)
303 - hm->last_event->next = event;
304 - hm->last_event = event;
305 - event->next = NULL;
306 305 xfs_healthmon_bump_events(hm);
307 306 wake_up(&hm->wait);
308 -
309 - trace_xfs_healthmon_push(hm, event);
310 307 }
311 308
312 309 /* Deal with any previously lost events */
@@ -321,8 +318,7 @@ xfs_healthmon_clear_lost_prev(
321 318 };
322 319 struct xfs_healthmon_event *event = NULL;
323 320
324 - if (xfs_healthmon_merge_events(hm->last_event, &lost_event)) {
325 - trace_xfs_healthmon_merge(hm, hm->last_event);
321 + if (xfs_healthmon_merge_events(hm, &lost_event)) {
326 322 wake_up(&hm->wait);
327 323 goto cleared;
328 324 }
@@ -330,10 +326,12 @@ xfs_healthmon_clear_lost_prev(
330 326 if (hm->events < XFS_HEALTHMON_MAX_EVENTS)
331 327 event = kmemdup(&lost_event, sizeof(struct xfs_healthmon_event),
332 328 GFP_NOFS);
333 - if (!event)
329 + if (!event) {
330 + xfs_healthmon_bump_lost(hm);
334 331 return -ENOMEM;
332 + }
335 333
336 - __xfs_healthmon_push(hm, event);
334 + __xfs_healthmon_insert(hm, INSERT_TAIL, event);
337 335 cleared:
338 336 hm->lost_prev_event = 0;
339 337 return 0;
@@ -369,8 +367,7 @@ xfs_healthmon_push(
369 367 }
370 368
371 369 /* Try to merge with the newest event */
372 - if (xfs_healthmon_merge_events(hm->last_event, template)) {
373 - trace_xfs_healthmon_merge(hm, hm->last_event);
370 + if (xfs_healthmon_merge_events(hm, template)) {
374 371 wake_up(&hm->wait);
375 372 goto out_unlock;
376 373 }
@@ -387,7 +384,7 @@ xfs_healthmon_push(
387 384 goto out_unlock;
388 385 }
389 386
390 - __xfs_healthmon_push(hm, event);
387 + __xfs_healthmon_insert(hm, INSERT_TAIL, event);
391 388
392 389 out_unlock:
393 390 mutex_unlock(&hm->lock);
@@ -415,8 +412,10 @@ xfs_healthmon_unmount(
415 412 * There's nothing actionable for userspace after an unmount. Once
416 413 * we've inserted the unmount event, hm no longer owns that event.
417 414 */
418 - __xfs_healthmon_insert(hm, hm->unmount_event);
415 + mutex_lock(&hm->lock);
416 + __xfs_healthmon_insert(hm, INSERT_HEAD, hm->unmount_event);
419 417 hm->unmount_event = NULL;
418 + mutex_unlock(&hm->lock);
420 419
421 420 xfs_healthmon_detach(hm);
422 421 xfs_healthmon_put(hm);
@@ -738,6 +737,13 @@ static const unsigned int type_map[] = {
738 737 [XFS_HEALTHMON_DATALOST] = XFS_HEALTH_MONITOR_TYPE_DATALOST,
739 738 };
740 739
740 + static inline bool
741 + xfs_healthmon_check_outbuffer_space(const struct xfs_healthmon *hm)
742 + {
743 + return hm->bufhead + sizeof(struct xfs_health_monitor_event) <=
744 + hm->bufsize;
745 + }
746 +
741 747 /* Render event as a V0 structure */
742 748 STATIC int
743 749 xfs_healthmon_format_v0(
@@ -804,10 +810,10 @@ xfs_healthmon_format_v0(
804 810 break;
805 811 }
806 812
807 - ASSERT(hm->bufhead + sizeof(hme) <= hm->bufsize);
813 + ASSERT(xfs_healthmon_check_outbuffer_space(hm));
808 814
809 815 /* copy formatted object to the outbuf */
810 - if (hm->bufhead + sizeof(hme) <= hm->bufsize) {
816 + if (xfs_healthmon_check_outbuffer_space(hm)) {
811 817 memcpy(hm->buffer + hm->bufhead, &hme, sizeof(hme));
812 818 hm->bufhead += sizeof(hme);
813 819 }
@@ -890,15 +896,18 @@ xfs_healthmon_format_pop(
890 896 {
891 897 struct xfs_healthmon_event *event;
892 898
893 - if (hm->bufhead + sizeof(*event) > hm->bufsize)
899 + /*
900 + * Don't bother if there's not enough space to format even one event in
901 + * the outbuffer.
902 + */
903 + if (!xfs_healthmon_check_outbuffer_space(hm))
894 904 return NULL;
895 905
896 906 mutex_lock(&hm->lock);
897 - event = hm->first_event;
907 + event = list_first_entry_or_null(&hm->event_list,
908 + struct xfs_healthmon_event, entry);
898 909 if (event) {
899 - if (hm->last_event == event)
900 - hm->last_event = NULL;
901 - hm->first_event = event->next;
910 + list_del_init(&event->entry);
902 911 hm->events--;
903 912
904 913 trace_xfs_healthmon_pop(hm, event);
@@ -1198,6 +1207,7 @@ xfs_ioc_health_monitor(
1198 1207 return -ENOMEM;
1199 1208 hm->dev = mp->m_super->s_dev;
1200 1209 refcount_set(&hm->ref, 1);
1210 + INIT_LIST_HEAD(&hm->event_list);
1201 1211
1202 1212 mutex_init(&hm->lock);
1203 1213 init_waitqueue_head(&hm->wait);
@@ -1213,7 +1223,9 @@ xfs_ioc_health_monitor(
1213 1223 }
1214 1224 running_event->type = XFS_HEALTHMON_RUNNING;
1215 1225 running_event->domain = XFS_HEALTHMON_MOUNT;
1216 - __xfs_healthmon_insert(hm, running_event);
1226 + mutex_lock(&hm->lock);
1227 + __xfs_healthmon_insert(hm, INSERT_HEAD, running_event);
1228 + mutex_unlock(&hm->lock);
1217 1229
1218 1230 /*
1219 1231 * Preallocate the unmount event so that we can't fail to notify the
modified fs/xfs/xfs_healthmon.h
@@ -31,8 +31,7 @@ struct xfs_healthmon {
31 31 struct mutex lock;
32 32
33 33 /* list of event objects */
34 - struct xfs_healthmon_event *first_event;
35 - struct xfs_healthmon_event *last_event;
34 + struct list_head event_list;
36 35
37 36 /* preallocated event for unmount */
38 37 struct xfs_healthmon_event *unmount_event;
@@ -110,7 +109,7 @@ enum xfs_healthmon_domain {
110 109 };
111 110
112 111 struct xfs_healthmon_event {
113 - struct xfs_healthmon_event *next;
112 + struct list_head entry;
114 113
115 114 enum xfs_healthmon_type type;
116 115 enum xfs_healthmon_domain domain;
modified fs/xfs/xfs_icache.c
@@ -497,7 +497,8 @@ xfs_iget_cache_hit(
497 497 struct xfs_inode *ip,
498 498 xfs_ino_t ino,
499 499 int flags,
500 - int lock_flags) __releases(RCU)
500 + int lock_flags)
501 + __releases_shared(RCU)
501 502 {
502 503 struct inode *inode = VFS_I(ip);
503 504 struct xfs_mount *mp = ip->i_mount;
modified fs/xfs/xfs_inode.h
@@ -585,7 +585,6 @@ uint xfs_ilock_attr_map_shared(struct xfs_inode *);
585 585 int xfs_ifree(struct xfs_trans *, struct xfs_inode *);
586 586 int xfs_itruncate_extents_flags(struct xfs_trans **,
587 587 struct xfs_inode *, int, xfs_fsize_t, int);
588 - void xfs_iext_realloc(xfs_inode_t *, int, int);
589 588
590 589 int xfs_log_force_inode(struct xfs_inode *ip);
591 590 void xfs_iunpin_wait(xfs_inode_t *);
modified fs/xfs/xfs_iomap.h
@@ -41,6 +41,8 @@ xfs_iomap_set_anon_write(
41 41 iomap->offset = offset;
42 42 iomap->length = length;
43 43 iomap->flags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
44 + if (bdev_has_integrity_csum(iomap->bdev))
45 + iomap->flags |= IOMAP_F_INTEGRITY;
44 46 }
45 47
46 48 static inline xfs_filblks_t
modified fs/xfs/xfs_log.c
@@ -422,6 +422,8 @@ out_error:
422 422 static void
423 423 xlog_state_shutdown_callbacks(
424 424 struct xlog *log)
425 + __releases(&log->l_icloglock)
426 + __acquires(&log->l_icloglock)
425 427 {
426 428 struct xlog_in_core *iclog;
427 429 LIST_HEAD(cb_list);
@@ -470,6 +472,8 @@ xlog_state_release_iclog(
470 472 struct xlog *log,
471 473 struct xlog_in_core *iclog,
472 474 struct xlog_ticket *ticket)
475 + __releases(&log->l_icloglock)
476 + __acquires(&log->l_icloglock)
473 477 {
474 478 bool last_ref;
475 479
@@ -744,13 +748,16 @@ xfs_log_mount_cancel(
744 748 */
745 749 static inline int
746 750 xlog_force_iclog(
751 + struct xlog *log,
747 752 struct xlog_in_core *iclog)
753 + __releases(&log->l_icloglock)
754 + __acquires(&log->l_icloglock)
748 755 {
749 756 atomic_inc(&iclog->ic_refcnt);
750 757 iclog->ic_flags |= XLOG_ICL_NEED_FLUSH | XLOG_ICL_NEED_FUA;
751 758 if (iclog->ic_state == XLOG_STATE_ACTIVE)
752 - xlog_state_switch_iclogs(iclog->ic_log, iclog, 0);
753 - return xlog_state_release_iclog(iclog->ic_log, iclog, NULL);
759 + xlog_state_switch_iclogs(log, iclog, 0);
760 + return xlog_state_release_iclog(log, iclog, NULL);
754 761 }
755 762
756 763 /*
@@ -778,11 +785,10 @@ xlog_wait_iclog_completion(struct xlog *log)
778 785 */
779 786 int
780 787 xlog_wait_on_iclog(
788 + struct xlog *log,
781 789 struct xlog_in_core *iclog)
782 - __releases(iclog->ic_log->l_icloglock)
790 + __releases(log->l_icloglock)
783 791 {
784 - struct xlog *log = iclog->ic_log;
785 -
786 792 trace_xlog_iclog_wait_on(iclog, _RET_IP_);
787 793 if (!xlog_is_shutdown(log) &&
788 794 iclog->ic_state != XLOG_STATE_ACTIVE &&
@@ -879,8 +885,8 @@ out_err:
879 885
880 886 spin_lock(&log->l_icloglock);
881 887 iclog = log->l_iclog;
882 - error = xlog_force_iclog(iclog);
883 - xlog_wait_on_iclog(iclog);
888 + error = xlog_force_iclog(log, iclog);
889 + xlog_wait_on_iclog(log, iclog);
884 890
885 891 if (tic) {
886 892 trace_xfs_log_umount_write(log, tic);
@@ -1538,6 +1544,35 @@ xlog_bio_end_io(
1538 1544 &iclog->ic_end_io_work);
1539 1545 }
1540 1546
1547 + /*
1548 + * When using multiple devices, we also need to flush the data and RT device
1549 + * caches first to ensure that all metadata writeback covered by the LSN in
1550 + * this iclog is on stable storage. This is slow, but it *must* complete
1551 + * before we issue the external log IO.
1552 + *
1553 + * If the flush fails, we cannot conclude that past metadata writeback from
1554 + * the log succeeded. Repeating the flush is not possible, hence we must
1555 + * shut down with log IO error to avoid shutdown re-entering this path and
1556 + * erroring out again.
1557 + */
1558 + static int
1559 + xlog_flush_data_caches(
1560 + struct xlog *log)
1561 + {
1562 + struct xfs_mount *mp = log->l_mp;
1563 +
1564 + if (log->l_targ != mp->m_ddev_targp) {
1565 + if (blkdev_issue_flush(mp->m_ddev_targp->bt_bdev))
1566 + return -EIO;
1567 + }
1568 + if (mp->m_rtdev_targp && mp->m_rtdev_targp != mp->m_ddev_targp) {
1569 + if (blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev))
1570 + return -EIO;
1571 + }
1572 +
1573 + return 0;
1574 + }
1575 +
1541 1576 STATIC void
1542 1577 xlog_write_iclog(
1543 1578 struct xlog *log,
@@ -1582,21 +1617,9 @@ xlog_write_iclog(
1582 1617 iclog->ic_bio.bi_private = iclog;
1583 1618
1584 1619 if (iclog->ic_flags & XLOG_ICL_NEED_FLUSH) {
1585 - iclog->ic_bio.bi_opf |= REQ_PREFLUSH;
1586 - /*
1587 - * For external log devices, we also need to flush the data
1588 - * device cache first to ensure all metadata writeback covered
1589 - * by the LSN in this iclog is on stable storage. This is slow,
1590 - * but it *must* complete before we issue the external log IO.
1591 - *
1592 - * If the flush fails, we cannot conclude that past metadata
1593 - * writeback from the log succeeded. Repeating the flush is
1594 - * not possible, hence we must shut down with log IO error to
1595 - * avoid shutdown re-entering this path and erroring out again.
1596 - */
1597 - if (log->l_targ != log->l_mp->m_ddev_targp &&
1598 - blkdev_issue_flush(log->l_mp->m_ddev_targp->bt_bdev))
1620 + if (xlog_flush_data_caches(log))
1599 1621 goto shutdown;
1622 + iclog->ic_bio.bi_opf |= REQ_PREFLUSH;
1600 1623 }
1601 1624 if (iclog->ic_flags & XLOG_ICL_NEED_FUA)
1602 1625 iclog->ic_bio.bi_opf |= REQ_FUA;
@@ -2741,14 +2764,17 @@ xlog_state_switch_iclogs(
2741 2764 */
2742 2765 static int
2743 2766 xlog_force_and_check_iclog(
2767 + struct xlog *log,
2744 2768 struct xlog_in_core *iclog,
2745 2769 bool *completed)
2770 + __releases(&log->l_icloglock)
2771 + __acquires(&log->l_icloglock)
2746 2772 {
2747 2773 xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header->h_lsn);
2748 2774 int error;
2749 2775
2750 2776 *completed = false;
2751 - error = xlog_force_iclog(iclog);
2777 + error = xlog_force_iclog(log, iclog);
2752 2778 if (error)
2753 2779 return error;
2754 2780
@@ -2825,7 +2851,7 @@ xfs_log_force(
2825 2851 /* We have exclusive access to this iclog. */
2826 2852 bool completed;
2827 2853
2828 - if (xlog_force_and_check_iclog(iclog, &completed))
2854 + if (xlog_force_and_check_iclog(log, iclog, &completed))
2829 2855 goto out_error;
2830 2856
2831 2857 if (completed)
@@ -2850,7 +2876,7 @@ xfs_log_force(
2850 2876 iclog->ic_flags |= XLOG_ICL_NEED_FLUSH | XLOG_ICL_NEED_FUA;
2851 2877
2852 2878 if (flags & XFS_LOG_SYNC)
2853 - return xlog_wait_on_iclog(iclog);
2879 + return xlog_wait_on_iclog(log, iclog);
2854 2880 out_unlock:
2855 2881 spin_unlock(&log->l_icloglock);
2856 2882 return 0;
@@ -2920,7 +2946,7 @@ xlog_force_lsn(
2920 2946 &log->l_icloglock);
2921 2947 return -EAGAIN;
2922 2948 }
2923 - if (xlog_force_and_check_iclog(iclog, &completed))
2949 + if (xlog_force_and_check_iclog(log, iclog, &completed))
2924 2950 goto out_error;
2925 2951 if (log_flushed)
2926 2952 *log_flushed = 1;
@@ -2948,7 +2974,7 @@ xlog_force_lsn(
2948 2974 }
2949 2975
2950 2976 if (flags & XFS_LOG_SYNC)
2951 - return xlog_wait_on_iclog(iclog);
2977 + return xlog_wait_on_iclog(log, iclog);
2952 2978 out_unlock:
2953 2979 spin_unlock(&log->l_icloglock);
2954 2980 return 0;
modified fs/xfs/xfs_log.h
@@ -105,8 +105,6 @@ int xfs_log_mount(struct xfs_mount *mp,
105 105 int num_bblocks);
106 106 int xfs_log_mount_finish(struct xfs_mount *mp);
107 107 void xfs_log_mount_cancel(struct xfs_mount *);
108 - xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
109 - xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
110 108 void xfs_log_space_wake(struct xfs_mount *mp);
111 109 int xfs_log_reserve(struct xfs_mount *mp, int length, int count,
112 110 struct xlog_ticket **ticket, bool permanent);
modified fs/xfs/xfs_log_cil.c
@@ -1055,9 +1055,10 @@ xlog_cil_set_ctx_write_state(
1055 1055 spin_unlock(&cil->xc_push_lock);
1056 1056
1057 1057 /*
1058 - * Make sure the metadata we are about to overwrite in the log
1059 - * has been flushed to stable storage before this iclog is
1060 - * issued.
1058 + * Flush the write cache before writing the start record so that
1059 + * the metadata we are about to overwrite in the log and the
1060 + * data that new allocations in this context refer to are
1061 + * persisted to stable storage before this iclog is written.
1061 1062 */
1062 1063 spin_lock(&cil->xc_log->l_icloglock);
1063 1064 iclog->ic_flags |= XLOG_ICL_NEED_FLUSH;
@@ -1556,7 +1557,7 @@ xlog_cil_push_work(
1556 1557 * iclogs older than ic_prev. Hence we only need to wait
1557 1558 * on the most recent older iclog here.
1558 1559 */
1559 - xlog_wait_on_iclog(ctx->commit_iclog->ic_prev);
1560 + xlog_wait_on_iclog(log, ctx->commit_iclog->ic_prev);
1560 1561 spin_lock(&log->l_icloglock);
1561 1562 }
1562 1563
@@ -1627,6 +1628,7 @@ out_abort_free_ticket:
1627 1628 static void
1628 1629 xlog_cil_push_background(
1629 1630 struct xlog *log)
1631 + __releases_shared(&log->l_cilp->xc_ctx_lock)
1630 1632 {
1631 1633 struct xfs_cil *cil = log->l_cilp;
1632 1634 int space_used = atomic_read(&cil->xc_ctx->space_used);
modified fs/xfs/xfs_log_priv.h
@@ -605,8 +605,8 @@ xlog_wait(
605 605 remove_wait_queue(wq, &wait);
606 606 }
607 607
608 - int xlog_wait_on_iclog(struct xlog_in_core *iclog)
609 - __releases(iclog->ic_log->l_icloglock);
608 + int xlog_wait_on_iclog(struct xlog *log, struct xlog_in_core *iclog)
609 + __releases(log->l_icloglock);
610 610
611 611 /* Calculate the distance between two LSNs in bytes */
612 612 static inline uint64_t
modified fs/xfs/xfs_mru_cache.c
@@ -520,7 +520,7 @@ xfs_mru_cache_lookup(
520 520 if (elem) {
521 521 list_del(&elem->list_node);
522 522 _xfs_mru_cache_list_insert(mru, elem);
523 - __release(mru_lock); /* help sparse not be stupid */
523 + __release(&mru->lock);
524 524 } else
525 525 spin_unlock(&mru->lock);
526 526
modified fs/xfs/xfs_trace.h
@@ -6139,8 +6139,8 @@ DEFINE_EVENT(xfs_healthmon_event_class, name, \
6139 6139 TP_PROTO(const struct xfs_healthmon *hm, \
6140 6140 const struct xfs_healthmon_event *event), \
6141 6141 TP_ARGS(hm, event))
6142 - DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_insert);
6143 - DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_push);
6142 + DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_insert_head);
6143 + DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_insert_tail);
6144 6144 DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_pop);
6145 6145 DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_format);
6146 6146 DEFINE_HEALTHMONEVENT_EVENT(xfs_healthmon_format_overflow);
modified fs/xfs/xfs_trans_ail.c
@@ -33,7 +33,7 @@ STATIC void
33 33 xfs_ail_check(
34 34 struct xfs_ail *ailp,
35 35 struct xfs_log_item *lip)
36 - __must_hold(&ailp->ail_lock)
36 + __must_hold(&ailp->ail_lock)
37 37 {
38 38 struct xfs_log_item *prev_lip;
39 39 struct xfs_log_item *next_lip;
@@ -321,6 +321,7 @@ static void
321 321 xfs_ail_delete(
322 322 struct xfs_ail *ailp,
323 323 struct xfs_log_item *lip)
324 + __must_hold(&ailp->ail_lock)
324 325 {
325 326 xfs_ail_check(ailp, lip);
326 327 list_del(&lip->li_ail);
@@ -899,6 +900,7 @@ xfs_lsn_t
899 900 xfs_ail_delete_one(
900 901 struct xfs_ail *ailp,
901 902 struct xfs_log_item *lip)
903 + __must_hold(&ailp->ail_lock)
902 904 {
903 905 struct xfs_log_item *mlip = xfs_ail_min(ailp);
904 906 xfs_lsn_t lsn = lip->li_lsn;
modified fs/xfs/xfs_verify_media.c
@@ -268,6 +268,8 @@ xfs_verify_media(
268 268 struct xfs_buftarg *btp = NULL;
269 269 struct bio *bio;
270 270 struct folio *folio;
271 + xfs_daddr_t dev_start = 0;
272 + xfs_daddr_t dev_end = 0;
271 273 xfs_daddr_t daddr;
272 274 uint64_t bbcount;
273 275 int error = 0;
@@ -277,24 +279,33 @@ xfs_verify_media(
277 279 switch (me->me_dev) {
278 280 case XFS_DEV_DATA:
279 281 btp = mp->m_ddev_targp;
282 + dev_end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
280 283 break;
281 284 case XFS_DEV_LOG:
282 - if (mp->m_logdev_targp != mp->m_ddev_targp)
285 + if (mp->m_logdev_targp != mp->m_ddev_targp) {
283 286 btp = mp->m_logdev_targp;
287 + dev_end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
288 + }
284 289 break;
285 290 case XFS_DEV_RT:
286 291 btp = mp->m_rtdev_targp;
292 + dev_start = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart);
293 + dev_end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart +
294 + mp->m_sb.sb_rblocks);
287 295 break;
288 296 }
289 297 if (!btp)
290 298 return -ENODEV;
291 299
292 300 /*
293 - * If the caller told us to verify beyond the end of the disk, tell the
294 - * user exactly where that was.
301 + * If the caller told us to verify before the start or beyond the end
302 + * of the disk volume, tell the user exactly where the volume starts
303 + * and ends.
295 304 */
296 - if (me->me_end_daddr > btp->bt_nr_sectors)
297 - me->me_end_daddr = btp->bt_nr_sectors;
305 + if (me->me_end_daddr > dev_end)
306 + me->me_end_daddr = dev_end;
307 + if (me->me_start_daddr < dev_start)
308 + me->me_start_daddr = dev_start;
298 309
299 310 /* start and end have to be aligned to the lba size */
300 311 if (!IS_ALIGNED(BBTOB(me->me_start_daddr | me->me_end_daddr),
@@ -323,8 +334,7 @@ xfs_verify_media(
323 334 * verifying.
324 335 */
325 336 daddr = me->me_start_daddr;
326 - bbcount = min_t(sector_t, me->me_end_daddr, btp->bt_nr_sectors) -
327 - me->me_start_daddr;
337 + bbcount = me->me_end_daddr - me->me_start_daddr;
328 338
329 339 folio = xfs_verify_alloc_folio(xfs_verify_iosize(me, btp, bbcount));
330 340 if (!folio)
modified fs/xfs/xfs_zone_alloc.c
@@ -475,6 +475,8 @@ static struct xfs_open_zone *
475 475 xfs_try_open_zone(
476 476 struct xfs_mount *mp,
477 477 enum rw_hint write_hint)
478 + __releases(&mp->m_zone_info->zi_open_zones_lock)
479 + __acquires(&mp->m_zone_info->zi_open_zones_lock)
478 480 {
479 481 struct xfs_zone_info *zi = mp->m_zone_info;
480 482 struct xfs_open_zone *oz;
modified fs/xfs/xfs_zone_space_resv.c
@@ -85,13 +85,13 @@ xfs_zoned_add_available(
85 85 struct xfs_zone_info *zi = mp->m_zone_info;
86 86 struct xfs_zone_reservation *reservation;
87 87
88 - if (list_empty_careful(&zi->zi_reclaim_reservations)) {
89 - xfs_add_freecounter(mp, XC_FREE_RTAVAILABLE, count_fsb);
88 + spin_lock(&zi->zi_reservation_lock);
89 + xfs_add_freecounter(mp, XC_FREE_RTAVAILABLE, count_fsb);
90 + if (list_empty(&zi->zi_reclaim_reservations)) {
91 + spin_unlock(&zi->zi_reservation_lock);
90 92 return;
91 93 }
92 94
93 - spin_lock(&zi->zi_reservation_lock);
94 - xfs_add_freecounter(mp, XC_FREE_RTAVAILABLE, count_fsb);
95 95 count_fsb = xfs_sum_freecounter(mp, XC_FREE_RTAVAILABLE);
96 96 list_for_each_entry(reservation, &zi->zi_reclaim_reservations, entry) {
97 97 if (reservation->count_fsb > count_fsb)
modified include/linux/console.h
@@ -615,15 +615,6 @@ extern bool nbcon_allow_unsafe_takeover(void);
615 615 extern bool nbcon_kdb_try_acquire(struct console *con,
616 616 struct nbcon_write_context *wctxt);
617 617 extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
618 - extern bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt);
619 - extern bool nbcon_braille_try_acquire(struct console *con,
620 - struct nbcon_write_context *wctxt);
621 - extern void nbcon_braille_release(struct nbcon_write_context *wctxt);
622 -
623 - static inline bool nbcon_is_braille(struct console *con)
624 - {
625 - return con && (con->flags & CON_BRL);
626 - }
627 618
628 619 /*
629 620 * Check if the given console is currently capable and allowed to print
@@ -687,14 +678,8 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }
687 678 static inline bool nbcon_kdb_try_acquire(struct console *con,
688 679 struct nbcon_write_context *wctxt) { return false; }
689 680 static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
690 - static inline
691 - bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt) { return false; }
692 681 static inline bool console_is_usable(struct console *con, short flags,
693 682 bool use_atomic) { return false; }
694 - static inline bool nbcon_braille_try_acquire(struct console *con,
695 - struct nbcon_write_context *wctxt) { return false; }
696 - static inline void nbcon_braille_release(struct nbcon_write_context *wctxt) { }
697 - static inline bool nbcon_is_braille(struct console *con) { return false; }
698 683 #endif
699 684
700 685 extern int console_set_on_cmdline;
modified include/linux/dma-fence.h
@@ -141,6 +141,9 @@ struct dma_fence_ops {
141 141 * compute the name at runtime, without having it to store permanently
142 142 * for each fence, or build a cache of some sort.
143 143 *
144 + * The returned string is RCU protected and can be freed after the fence
145 + * signaled and a RCU grace period passed.
146 + *
144 147 * This callback is mandatory.
145 148 */
146 149 const char * (*get_driver_name)(struct dma_fence *fence);
@@ -153,6 +156,9 @@ struct dma_fence_ops {
153 156 * having it to store permanently for each fence, or build a cache of
154 157 * some sort.
155 158 *
159 + * The returned string is RCU protected and can be freed after the fence
160 + * signaled and a RCU grace period passed.
161 + *
156 162 * This callback is mandatory.
157 163 */
158 164 const char * (*get_timeline_name)(struct dma_fence *fence);
modified include/linux/entry-common.h
@@ -102,7 +102,14 @@ static __always_inline long syscall_trace_enter(struct pt_regs *regs, unsigned l
102 102 if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
103 103 trace_syscall_enter(regs);
104 104
105 - if (unlikely(audit_context()))
105 + /*
106 + * The config check works around broken compilers which fail to
107 + * eliminate the dead code in case of CONFIG_AUDITSYSCALL=n as they
108 + * insist on creating a always false runtime condition based on
109 + * audit_context() which returns NULL in that case. The explicit
110 + * IS_ENABLED() check makes that madness go away.
111 + */
112 + if (IS_ENABLED(CONFIG_AUDITSYSCALL) && unlikely(audit_context()))
106 113 syscall_enter_audit(regs);
107 114
108 115 return true;
modified include/linux/ethtool.h
@@ -1057,6 +1057,12 @@ struct kernel_ethtool_ts_info {
1057 1057 * @get_sset_count: Get number of strings that @get_strings will write.
1058 1058 * @get_rxnfc: Get RX flow classification rules. Returns a negative
1059 1059 * error code or zero.
1060 + * Note that for %ETHTOOL_GRXCLSRLALL rule_cnt and size of the arrays
1061 + * is user-provided, and not guaranteed to match what driver would
1062 + * have reported via %ETHTOOL_GRXCLSRLCNT. Drivers must return -%EMSGSIZE
1063 + * when rule_cnt is too small. rule_locs is %NULL when rule_cnt is zero.
1064 + * On success drivers must set rule_cnt to the number of locations they
1065 + * filled in, the core copies out exactly that many.
1060 1066 * @set_rxnfc: Set RX flow classification rules. Returns a negative
1061 1067 * error code or zero.
1062 1068 * @flash_device: Write a firmware image to device's flash memory.
modified include/linux/netfilter_arp/arp_tables.h
@@ -56,23 +56,4 @@ void arpt_unregister_table(struct net *net, const char *name);
56 56 extern unsigned int arpt_do_table(void *priv, struct sk_buff *skb,
57 57 const struct nf_hook_state *state);
58 58
59 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
60 - #include <net/compat.h>
61 -
62 - struct compat_arpt_entry {
63 - struct arpt_arp arp;
64 - __u16 target_offset;
65 - __u16 next_offset;
66 - compat_uint_t comefrom;
67 - struct compat_xt_counters counters;
68 - unsigned char elems[];
69 - };
70 -
71 - static inline struct xt_entry_target *
72 - compat_arpt_get_target(struct compat_arpt_entry *e)
73 - {
74 - return (void *)e + e->target_offset;
75 - }
76 -
77 - #endif /* CONFIG_COMPAT */
78 59 #endif /* _ARPTABLES_H */
modified include/linux/netfs.h
@@ -246,6 +246,7 @@ struct netfs_io_request {
246 246 unsigned long long submitted; /* Amount submitted for I/O so far */
247 247 unsigned long long len; /* Length of the request */
248 248 size_t transferred; /* Amount to be indicated as transferred */
249 + size_t progress_at; /* Report read progress when hit this much read */
249 250 long error; /* 0 or error that occurred */
250 251 unsigned long long i_size; /* Size of the file */
251 252 unsigned long long start; /* Start position */
@@ -262,7 +263,6 @@ struct netfs_io_request {
262 263 atomic_t subreq_counter; /* Next subreq->debug_index */
263 264 unsigned int nr_group_rel; /* Number of refs to release on ->group */
264 265 spinlock_t lock; /* Lock for queuing subreqs */
265 - unsigned char front_folio_order; /* Order (size) of front folio */
266 266 enum netfs_io_origin origin; /* Origin of the request */
267 267 bool direct_bv_unpin; /* T if direct_bv[] must be unpinned */
268 268 refcount_t ref;
@@ -275,9 +275,10 @@ struct netfs_io_request {
275 275 #define NETFS_RREQ_SHORT_TRANSFER 5 /* Set if we have a short transfer */
276 276 #define NETFS_RREQ_OFFLOAD_COLLECTION 8 /* Offload collection to workqueue */
277 277 #define NETFS_RREQ_NO_UNLOCK_FOLIO 9 /* Don't unlock no_unlock_folio on completion */
278 - #define NETFS_RREQ_FOLIO_COPY_TO_CACHE 10 /* Copy current folio to cache from read */
278 + #define NETFS_RREQ_CANCEL_CACHING 10 /* Set to cancel caching */
279 279 #define NETFS_RREQ_UPLOAD_TO_SERVER 11 /* Need to write to the server */
280 280 #define NETFS_RREQ_USE_IO_ITER 12 /* Use ->io_iter rather than ->i_pages */
281 + #define NETFS_RREQ_NEED_PUT_RA_REFS 17 /* Need to put the folio refs RA gave us */
281 282 #define NETFS_RREQ_USE_PGPRIV2 31 /* [DEPRECATED] Use PG_private_2 to mark
282 283 * write to cache on read */
283 284 const struct netfs_request_ops *netfs_ops;
modified include/linux/ns/ns_common_types.h
@@ -116,10 +116,8 @@ struct ns_common {
116 116 struct dentry *stashed;
117 117 const struct proc_ns_operations *ops;
118 118 unsigned int inum;
119 - union {
120 - struct ns_tree;
121 - struct rcu_head ns_rcu;
122 - };
119 + struct ns_tree;
120 + struct rcu_head ns_rcu;
123 121 };
124 122
125 123 #define to_ns_common(__ns) \
modified include/linux/perf/riscv_pmu.h
@@ -55,7 +55,7 @@ struct riscv_pmu {
55 55
56 56 irqreturn_t (*handle_irq)(int irq_num, void *dev);
57 57
58 - unsigned long cmask;
58 + DECLARE_BITMAP(cmask, RISCV_MAX_COUNTERS);
59 59 u64 (*ctr_read)(struct perf_event *event);
60 60 int (*ctr_get_idx)(struct perf_event *event);
61 61 int (*ctr_get_width)(int idx);
modified include/linux/rbtree_augmented.h
@@ -87,18 +87,18 @@ rb_add_augmented_cached(struct rb_node *node, struct rb_root_cached *tree,
87 87 }
88 88
89 89 /*
90 - * Template for declaring augmented rbtree callbacks (generic case)
90 + * Template for declaring augmented rbtree callbacks (generic multi fields)
91 91 *
92 92 * RBSTATIC: 'static' or empty
93 93 * RBNAME: name of the rb_augment_callbacks structure
94 94 * RBSTRUCT: struct type of the tree nodes
95 95 * RBFIELD: name of struct rb_node field within RBSTRUCT
96 - * RBAUGMENTED: name of field within RBSTRUCT holding data for subtree
97 - * RBCOMPUTE: name of function that recomputes the RBAUGMENTED data
96 + * RBCOPY: name of function that copies the RBAUGMENTED datas
97 + * RBCOMPUTE: name of function that recomputes the RBAUGMENTED datas
98 98 */
99 99
100 - #define RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \
101 - RBSTRUCT, RBFIELD, RBAUGMENTED, RBCOMPUTE) \
100 + #define RB_DECLARE_CALLBACKS_MULTI(RBSTATIC, RBNAME, \
101 + RBSTRUCT, RBFIELD, RBCOPY, RBCOMPUTE) \
102 102 static inline void \
103 103 RBNAME ## _propagate(struct rb_node *rb, struct rb_node *stop) \
104 104 { \
@@ -114,14 +114,14 @@ RBNAME ## _copy(struct rb_node *rb_old, struct rb_node *rb_new) \
114 114 { \
115 115 RBSTRUCT *old = rb_entry(rb_old, RBSTRUCT, RBFIELD); \
116 116 RBSTRUCT *new = rb_entry(rb_new, RBSTRUCT, RBFIELD); \
117 - new->RBAUGMENTED = old->RBAUGMENTED; \
117 + RBCOPY(new, old); \
118 118 } \
119 119 static void \
120 120 RBNAME ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
121 121 { \
122 122 RBSTRUCT *old = rb_entry(rb_old, RBSTRUCT, RBFIELD); \
123 123 RBSTRUCT *new = rb_entry(rb_new, RBSTRUCT, RBFIELD); \
124 - new->RBAUGMENTED = old->RBAUGMENTED; \
124 + RBCOPY(new, old); \
125 125 RBCOMPUTE(old, false); \
126 126 } \
127 127 RBSTATIC const struct rb_augment_callbacks RBNAME = { \
@@ -130,6 +130,27 @@ RBSTATIC const struct rb_augment_callbacks RBNAME = { \
130 130 .rotate = RBNAME ## _rotate \
131 131 };
132 132
133 + /*
134 + * Template for declaring augmented rbtree callbacks (generic single field)
135 + *
136 + * RBSTATIC: 'static' or empty
137 + * RBNAME: name of the rb_augment_callbacks structure
138 + * RBSTRUCT: struct type of the tree nodes
139 + * RBFIELD: name of struct rb_node field within RBSTRUCT
140 + * RBAUGMENTED: name of field within RBSTRUCT holding data for subtree
141 + * RBCOMPUTE: name of function that recomputes the RBAUGMENTED data
142 + */
143 +
144 + #define RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \
145 + RBSTRUCT, RBFIELD, RBAUGMENTED, RBCOMPUTE) \
146 + static inline void \
147 + RBNAME ## _copy_single(RBSTRUCT *new, RBSTRUCT *old) \
148 + { \
149 + new->RBAUGMENTED = old->RBAUGMENTED; \
150 + } \
151 + RB_DECLARE_CALLBACKS_MULTI(RBSTATIC, RBNAME, \
152 + RBSTRUCT, RBFIELD, RBNAME ## _copy_single, RBCOMPUTE)
153 +
133 154 /*
134 155 * Template for declaring augmented rbtree callbacks,
135 156 * computing RBAUGMENTED scalar as max(RBCOMPUTE(node)) for all subtree nodes.
modified include/linux/ring_buffer.h
@@ -3,8 +3,9 @@
3 3 #define _LINUX_RING_BUFFER_H
4 4
5 5 #include <linux/mm.h>
6 - #include <linux/seq_file.h>
7 6 #include <linux/poll.h>
7 + #include <linux/ring_buffer_types.h>
8 + #include <linux/seq_file.h>
8 9
9 10 #include <uapi/linux/trace_mmap.h>
10 11
@@ -279,11 +280,25 @@ static inline struct ring_buffer_desc *__first_ring_buffer_desc(struct trace_buf
279 280 return (struct ring_buffer_desc *)(&desc->__data[0]);
280 281 }
281 282
283 + /*
284 + * Returns the number of pages for a ring_buffer_desc. The caller must ensure it
285 + * does not overflow ring_buffer_desc::nr_page_va.
286 + */
287 + static inline unsigned long __calc_nr_pages_ring_buffer_desc(size_t size)
288 + {
289 + /* Takes into account the reader page */
290 + return max(DIV_ROUND_UP(size, PAGE_SIZE - BUF_PAGE_HDR_SIZE), 2UL) + 1;
291 + }
292 +
282 293 static inline size_t trace_buffer_desc_size(size_t buffer_size, unsigned int nr_cpus)
283 294 {
284 - unsigned int nr_pages = max(DIV_ROUND_UP(buffer_size, PAGE_SIZE), 2UL) + 1;
295 + unsigned long nr_pages = __calc_nr_pages_ring_buffer_desc(buffer_size);
285 296 struct ring_buffer_desc *rbdesc;
286 297
298 + /* Capped by ring_buffer_desc::nr_page_va */
299 + if (nr_pages > UINT_MAX)
300 + return SIZE_MAX;
301 +
287 302 return size_add(offsetof(struct trace_buffer_desc, __data),
288 303 size_mul(nr_cpus, struct_size(rbdesc, page_va, nr_pages)));
289 304 }
modified include/linux/rolling_buffer.h
@@ -45,9 +45,9 @@ struct rolling_buffer_snapshot {
45 45 int rolling_buffer_init(struct rolling_buffer *roll, unsigned int rreq_id,
46 46 unsigned int direction, gfp_t gfp);
47 47 int rolling_buffer_make_space(struct rolling_buffer *roll, gfp_t gfp);
48 - ssize_t rolling_buffer_load_from_ra(struct rolling_buffer *roll,
49 - struct readahead_control *ractl,
50 - struct folio_batch *put_batch);
48 + ssize_t rolling_buffer_bulk_load_from_ra(struct rolling_buffer *roll,
49 + struct readahead_control *ractl,
50 + unsigned int rreq_id, gfp_t gfp);
51 51 ssize_t rolling_buffer_append(struct rolling_buffer *roll, struct folio *folio,
52 52 unsigned int flags, gfp_t gfp);
53 53 struct folio_queue *rolling_buffer_delete_spent(struct rolling_buffer *roll);
modified include/linux/sched.h
@@ -1787,7 +1787,7 @@ static inline bool is_lazy_mmu_mode_active(void)
1787 1787 }
1788 1788 #endif
1789 1789
1790 - extern struct pid *cad_pid;
1790 + extern struct pid __rcu *cad_pid;
1791 1791
1792 1792 /*
1793 1793 * Per process flags
modified include/linux/sched/signal.h
@@ -562,10 +562,7 @@ static inline sigset_t *sigmask_to_save(void)
562 562 return res;
563 563 }
564 564
565 - static inline int kill_cad_pid(int sig, int priv)
566 - {
567 - return kill_pid(cad_pid, sig, priv);
568 - }
565 + int kill_cad_pid(int sig, int priv);
569 566
570 567 /* These can be the second arg to send_sig_info/send_group_sig_info. */
571 568 #define SEND_SIG_NOINFO ((struct kernel_siginfo *) 0)
added include/media/v4l2-hevc.h mode 100644
@@ -0,0 +1,41 @@
1 + /* SPDX-License-Identifier: GPL-2.0-or-later */
2 + /*
3 + * Helper functions for HEVC stateless codecs.
4 + */
5 +
6 + #ifndef _MEDIA_V4L2_HEVC_H
7 + #define _MEDIA_V4L2_HEVC_H
8 +
9 + #include <linux/minmax.h>
10 + #include <media/v4l2-ctrls.h>
11 +
12 + /**
13 + * v4l2_hevc_pps_num_tile_columns - number of HEVC tile columns, bounded
14 + * @pps: the V4L2 HEVC PPS control
15 + *
16 + * Return the number of tile columns (num_tile_columns_minus1 + 1) clamped to
17 + * the capacity of column_width_minus1[]. The control validation already
18 + * rejects out-of-range counts; this keeps the consuming drivers bounded too.
19 + */
20 + static inline unsigned int
21 + v4l2_hevc_pps_num_tile_columns(const struct v4l2_ctrl_hevc_pps *pps)
22 + {
23 + return min_t(unsigned int, pps->num_tile_columns_minus1 + 1,
24 + ARRAY_SIZE(pps->column_width_minus1));
25 + }
26 +
27 + /**
28 + * v4l2_hevc_pps_num_tile_rows - number of HEVC tile rows, bounded
29 + * @pps: the V4L2 HEVC PPS control
30 + *
31 + * Return the number of tile rows (num_tile_rows_minus1 + 1) clamped to the
32 + * capacity of row_height_minus1[].
33 + */
34 + static inline unsigned int
35 + v4l2_hevc_pps_num_tile_rows(const struct v4l2_ctrl_hevc_pps *pps)
36 + {
37 + return min_t(unsigned int, pps->num_tile_rows_minus1 + 1,
38 + ARRAY_SIZE(pps->row_height_minus1));
39 + }
40 +
41 + #endif /* _MEDIA_V4L2_HEVC_H */
modified include/net/cfg802154.h
@@ -376,6 +376,7 @@ struct cfg802154_mac_pkt {
376 376 struct list_head node;
377 377 struct sk_buff *skb;
378 378 struct ieee802154_sub_if_data *sdata;
379 + netdevice_tracker dev_tracker;
379 380 u8 page;
380 381 u8 channel;
381 382 };
modified include/net/ip6_route.h
@@ -384,6 +384,8 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst
384 384 rcu_read_unlock();
385 385
386 386 out:
387 + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
388 +
387 389 return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
388 390 }
389 391
modified include/net/sch_generic.h
@@ -793,7 +793,7 @@ void qdisc_offload_query_caps(struct net_device *dev,
793 793 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
794 794 const struct Qdisc_ops *ops,
795 795 struct netlink_ext_ack *extack);
796 - void qdisc_free(struct Qdisc *qdisc);
796 + void qdisc_free_rcu(struct Qdisc *qdisc);
797 797 struct Qdisc *qdisc_create_dflt(struct netdev_queue *dev_queue,
798 798 const struct Qdisc_ops *ops, u32 parentid,
799 799 struct netlink_ext_ack *extack);
modified include/trace/events/cachefiles.h
@@ -372,7 +372,7 @@ TRACE_EVENT(cachefiles_rename,
372 372 TRACE_EVENT(cachefiles_coherency,
373 373 TP_PROTO(struct cachefiles_object *obj,
374 374 ino_t ino,
375 - u64 disk_aux,
375 + const void *disk_aux,
376 376 enum cachefiles_content content,
377 377 enum cachefiles_coherency_trace why),
378 378
@@ -389,12 +389,27 @@ TRACE_EVENT(cachefiles_coherency,
389 389 ),
390 390
391 391 TP_fast_assign(
392 + union {
393 + __be16 s[4];
394 + __be64 ll;
395 + } x;
396 +
392 397 __entry->obj = obj->debug_id;
393 398 __entry->why = why;
394 399 __entry->content = content;
395 400 __entry->ino = ino;
396 401 __entry->aux = be64_to_cpup((__be64 *)obj->cookie->inline_aux);
397 - __entry->disk_aux = disk_aux;
402 +
403 + /* cachefiles_xattr::data is 2-byte aligned but not 8-byte aligned. */
404 + if (disk_aux) {
405 + x.s[0] = ((__be16 *)disk_aux)[0];
406 + x.s[1] = ((__be16 *)disk_aux)[1];
407 + x.s[2] = ((__be16 *)disk_aux)[2];
408 + x.s[3] = ((__be16 *)disk_aux)[3];
409 + __entry->disk_aux = be64_to_cpu(x.ll);
410 + } else {
411 + __entry->disk_aux = 0;
412 + }
398 413 ),
399 414
400 415 TP_printk("o=%08x %s B=%llx c=%u aux=%llx dsk=%llx",
modified include/trace/events/landlock.h
@@ -28,6 +28,16 @@ struct task_struct;
28 28
29 29 #ifdef CREATE_TRACE_POINTS
30 30
31 + /* About 6 KiB, leaving about 2 KiB for sibling helpers and fixed fields. */
32 + #define TRACE_UNTRUSTED_STR_OUTPUT_SIZE \
33 + (TRACE_SEQ_BUFFER_SIZE - TRACE_SEQ_BUFFER_SIZE / 4)
34 +
35 + /*
36 + * A raw UTF-8 ellipsis (…) marks truncation and cannot collide with escaped
37 + * input: ESCAPE_NAP renders every non-ASCII input byte in octal.
38 + */
39 + #define TRACE_TRUNCATION_MARKER "\xe2\x80\xa6"
40 +
31 41 /*
32 42 * Escapes @len bytes of an untrusted string into the trace sequence @p so it
33 43 * cannot inject field separators or control characters into the ftrace text
@@ -37,33 +47,59 @@ struct task_struct;
37 47 * NUL-terminated or carries embedded NUL bytes (an abstract socket name) is
38 48 * escaped in full instead of being truncated at the first NUL.
39 49 *
40 - * Return: a pointer into @p's buffer, or NULL if @src is NULL or the buffer is
41 - * exhausted (normal when the trace buffer is full).
50 + * Strings that exceed the output limit retain the largest complete escaped
51 + * prefix followed by the truncation marker.
52 + *
53 + * Return: a pointer into @p's buffer, or NULL if @src is NULL or the fixed
54 + * output reservation is unavailable.
42 55 */
43 56 static inline const char *
44 57 __trace_print_untrusted_str(struct trace_seq *p, const char *src, size_t len)
45 58 {
59 + const unsigned int escape_flags = ESCAPE_SPACE | ESCAPE_SPECIAL |
60 + ESCAPE_NAP | ESCAPE_APPEND |
61 + ESCAPE_OCTAL;
62 + const size_t marker_len = sizeof(TRACE_TRUNCATION_MARKER) - 1;
63 + size_t buf_size, prefix_len, prefix_size;
46 64 int escaped_size;
47 65 char *buf;
48 - size_t buf_size = seq_buf_get_buf(&p->seq, &buf);
49 - const char *ret = trace_seq_buffer_ptr(p);
66 + const char *ret;
50 67
51 - /* Buffer exhaustion is normal when the trace buffer is full. */
52 - if (!src || buf_size == 0)
68 + buf_size = seq_buf_get_buf(&p->seq, &buf);
69 + if (!src || buf_size < TRACE_UNTRUSTED_STR_OUTPUT_SIZE)
53 70 return NULL;
54 71
55 - escaped_size =
56 - string_escape_mem(src, len, buf, buf_size,
57 - ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_NAP |
58 - ESCAPE_APPEND | ESCAPE_OCTAL,
59 - " ='\"\\");
60 - if (unlikely(escaped_size >= buf_size)) {
61 - /* We need some room for the final '\0'. */
62 - seq_buf_set_overflow(&p->seq);
63 - p->full = 1;
64 - return NULL;
72 + ret = trace_seq_buffer_ptr(p);
73 + escaped_size = string_escape_mem(src, len, buf,
74 + TRACE_UNTRUSTED_STR_OUTPUT_SIZE,
75 + escape_flags, " ='\"\\");
76 + if (likely(escaped_size < TRACE_UNTRUSTED_STR_OUTPUT_SIZE)) {
77 + seq_buf_commit(&p->seq, escaped_size);
78 + trace_seq_putc(p, 0);
79 + return ret;
80 + }
81 +
82 + prefix_len = 0;
83 + prefix_size = 0;
84 + while (prefix_len < len) {
85 + const char *const src_char = src + prefix_len;
86 + int char_size;
87 +
88 + char_size = string_escape_mem(src_char, 1, NULL, 0,
89 + escape_flags, " ='\"\\");
90 + if (char_size > TRACE_UNTRUSTED_STR_OUTPUT_SIZE - marker_len -
91 + 1 - prefix_size)
92 + break;
93 + prefix_size += char_size;
94 + prefix_len++;
65 95 }
66 - seq_buf_commit(&p->seq, escaped_size);
96 +
97 + escaped_size = string_escape_mem(src, prefix_len, buf, prefix_size,
98 + escape_flags, " ='\"\\");
99 + if (WARN_ON_ONCE(escaped_size != prefix_size))
100 + return NULL;
101 + memcpy(buf + prefix_size, TRACE_TRUNCATION_MARKER, marker_len);
102 + seq_buf_commit(&p->seq, prefix_size + marker_len);
67 103 trace_seq_putc(p, 0);
68 104 return ret;
69 105 }
modified include/trace/events/netfs.h
@@ -59,6 +59,7 @@
59 59 EM(netfs_rreq_trace_free, "FREE ") \
60 60 EM(netfs_rreq_trace_intr, "INTR ") \
61 61 EM(netfs_rreq_trace_ki_complete, "KI-CMPL") \
62 + EM(netfs_rreq_trace_ra_put_ref, "RA-PUT ") \
62 63 EM(netfs_rreq_trace_recollect, "RECLLCT") \
63 64 EM(netfs_rreq_trace_redirty, "REDIRTY") \
64 65 EM(netfs_rreq_trace_resubmit, "RESUBMT") \
@@ -70,9 +71,11 @@
70 71 EM(netfs_rreq_trace_unpause, "UNPAUSE") \
71 72 EM(netfs_rreq_trace_wait_ip, "WAIT-IP") \
72 73 EM(netfs_rreq_trace_wait_pause, "--PAUSED--") \
74 + EM(netfs_rreq_trace_wait_put_ra_refs, "WAIT-P-RA") \
73 75 EM(netfs_rreq_trace_wait_quiesce, "WAIT-QUIESCE") \
74 76 EM(netfs_rreq_trace_waited_ip, "DONE-IP") \
75 77 EM(netfs_rreq_trace_waited_pause, "--UNPAUSED--") \
78 + EM(netfs_rreq_trace_waited_put_ra_refs, "DONE-P-RA") \
76 79 EM(netfs_rreq_trace_waited_quiesce, "DONE-QUIESCE") \
77 80 EM(netfs_rreq_trace_wake_ip, "WAKE-IP") \
78 81 EM(netfs_rreq_trace_wake_queue, "WAKE-Q ") \
@@ -195,7 +198,6 @@
195 198 EM(netfs_folio_trace_clear_cc, "clear-cc") \
196 199 EM(netfs_folio_trace_clear_g, "clear-g") \
197 200 EM(netfs_folio_trace_clear_s, "clear-s") \
198 - EM(netfs_folio_trace_copy_to_cache, "mark-copy") \
199 201 EM(netfs_folio_trace_end_copy, "end-copy") \
200 202 EM(netfs_folio_trace_filled_gaps, "filled-gaps") \
201 203 EM(netfs_folio_trace_invalidate_all, "inval-all") \
@@ -206,16 +208,19 @@
206 208 EM(netfs_folio_trace_kill_cc, "kill-cc") \
207 209 EM(netfs_folio_trace_kill_g, "kill-g") \
208 210 EM(netfs_folio_trace_kill_s, "kill-s") \
211 + EM(netfs_folio_trace_mark_copy, "mark-copy") \
209 212 EM(netfs_folio_trace_mkwrite, "mkwrite") \
210 213 EM(netfs_folio_trace_mkwrite_plus, "mkwrite+") \
211 - EM(netfs_folio_trace_not_under_wback, "!wback") \
212 214 EM(netfs_folio_trace_not_locked, "!locked") \
215 + EM(netfs_folio_trace_not_under_wback, "!wback") \
216 + EM(netfs_folio_trace_pgpriv2_copy, "pgpriv2-copy") \
213 217 EM(netfs_folio_trace_put, "put") \
214 218 EM(netfs_folio_trace_read, "read") \
215 219 EM(netfs_folio_trace_read_done, "read-done") \
216 220 EM(netfs_folio_trace_read_gaps, "read-gaps") \
217 221 EM(netfs_folio_trace_read_unlock, "read-unlock") \
218 222 EM(netfs_folio_trace_redirtied, "redirtied") \
223 + EM(netfs_folio_trace_sched_copy, "sched-copy") \
219 224 EM(netfs_folio_trace_store, "store") \
220 225 EM(netfs_folio_trace_store_copy, "store-copy") \
221 226 EM(netfs_folio_trace_store_plus, "store+") \
@@ -786,6 +791,27 @@ TRACE_EVENT(netfs_folioq,
786 791 __print_symbolic(__entry->trace, netfs_folioq_traces))
787 792 );
788 793
794 + TRACE_EVENT(netfs_read_progress_at,
795 + TP_PROTO(const struct netfs_io_request *rreq),
796 +
797 + TP_ARGS(rreq),
798 +
799 + TP_STRUCT__entry(
800 + __field(unsigned int, rreq)
801 + __field(size_t, progress_at)
802 + __field(size_t, cleaned_to)
803 + ),
804 +
805 + TP_fast_assign(
806 + __entry->rreq = rreq->debug_id;
807 + __entry->cleaned_to = rreq->cleaned_to - rreq->start;
808 + __entry->progress_at = rreq->progress_at;
809 + ),
810 +
811 + TP_printk("R=%08x cln=%zx prg=%zx",
812 + __entry->rreq, __entry->cleaned_to, __entry->progress_at)
813 + );
814 +
789 815 #undef EM
790 816 #undef E_
791 817 #endif /* _TRACE_NETFS_H */
modified include/trace/events/timer.h
@@ -302,7 +302,7 @@ DECLARE_EVENT_CLASS(hrtimer_class,
302 302 * hrtimer_start_expired - Invoked when a expired timer was started
303 303 * @hrtimer: pointer to struct hrtimer
304 304 *
305 - * Preceeded by a hrtimer_start tracepoint.
305 + * Preceded by a hrtimer_start tracepoint.
306 306 */
307 307 DEFINE_EVENT(hrtimer_class, hrtimer_start_expired,
308 308
modified init/main.c
@@ -277,7 +277,8 @@ static void * __init get_boot_config_from_initrd(size_t *_size)
277 277 u8 *hdr;
278 278 int i;
279 279
280 - if (!initrd_end)
280 + if (!initrd_end || initrd_end < initrd_start ||
281 + initrd_end - initrd_start < BOOTCONFIG_MAGIC_LEN + 8)
281 282 return NULL;
282 283
283 284 data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
@@ -294,16 +295,26 @@ static void * __init get_boot_config_from_initrd(size_t *_size)
294 295
295 296 found:
296 297 hdr = (u8 *)(data - 8);
298 + if ((unsigned long)hdr < initrd_start)
299 + return NULL;
300 +
297 301 size = get_unaligned_le32(hdr);
298 302 csum = get_unaligned_le32(hdr + 4);
299 303
300 - data = ((void *)hdr) - size;
301 - if ((unsigned long)data < initrd_start) {
302 - pr_err("bootconfig size %d is greater than initrd size %ld\n",
304 + if (size > XBC_DATA_MAX) {
305 + pr_err("bootconfig size %u is greater than max size %d\n",
306 + size, XBC_DATA_MAX);
307 + return NULL;
308 + }
309 +
310 + if (size > ((unsigned long)hdr - initrd_start)) {
311 + pr_err("bootconfig size %u is greater than initrd size %lu\n",
303 312 size, initrd_end - initrd_start);
304 313 return NULL;
305 314 }
306 315
316 + data = ((void *)hdr) - size;
317 +
307 318 if (xbc_calc_checksum(data, size) != csum) {
308 319 pr_err("bootconfig checksum failed\n");
309 320 return NULL;
@@ -394,12 +405,6 @@ static void __init setup_boot_config(void)
394 405 return;
395 406 }
396 407
397 - if (size >= XBC_DATA_MAX) {
398 - pr_err("bootconfig size %ld greater than max size %d\n",
399 - (long)size, XBC_DATA_MAX);
400 - return;
401 - }
402 -
403 408 ret = xbc_init(data, size, &msg, &pos);
404 409 if (ret < 0) {
405 410 if (pos < 0)
@@ -1648,7 +1653,7 @@ static noinline void __init kernel_init_freeable(void)
1648 1653 */
1649 1654 set_mems_allowed(node_states[N_MEMORY]);
1650 1655
1651 - cad_pid = get_pid(task_pid(current));
1656 + rcu_assign_pointer(cad_pid, get_pid(task_pid(current)));
1652 1657
1653 1658 smp_prepare_cpus(setup_max_cpus);
1654 1659
modified io_uring/net.c
@@ -853,7 +853,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
853 853 static inline bool io_recv_finish(struct io_kiocb *req,
854 854 struct io_async_msghdr *kmsg,
855 855 struct io_br_sel *sel, bool mshot_finished,
856 - unsigned issue_flags)
856 + unsigned issue_flags, int consumed)
857 857 {
858 858 struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
859 859 unsigned int cflags = 0;
@@ -877,7 +877,7 @@ static inline bool io_recv_finish(struct io_kiocb *req,
877 877 if (sr->flags & IORING_RECVSEND_BUNDLE) {
878 878 size_t this_ret = sel->val - sr->done_io;
879 879
880 - cflags |= io_put_kbufs(req, this_ret, sel->buf_list, io_bundle_nbufs(kmsg, this_ret));
880 + cflags |= io_put_kbufs(req, consumed, sel->buf_list, io_bundle_nbufs(kmsg, consumed));
881 881 if (sr->flags & IORING_RECV_RETRY)
882 882 cflags = req->cqe.flags | (cflags & CQE_F_MASK);
883 883 if (sr->mshot_len && sel->val >= sr->mshot_len)
@@ -899,7 +899,7 @@ static inline bool io_recv_finish(struct io_kiocb *req,
899 899 return false;
900 900 }
901 901 } else {
902 - cflags |= io_put_kbuf(req, sel->val, sel->buf_list);
902 + cflags |= io_put_kbuf(req, consumed, sel->buf_list);
903 903 }
904 904
905 905 /*
@@ -1027,6 +1027,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
1027 1027 int ret, min_ret = 0;
1028 1028 bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
1029 1029 bool mshot_finished = true;
1030 + int consumed = 0;
1031 + size_t len;
1030 1032
1031 1033 sock = sock_from_file(req->file);
1032 1034 if (unlikely(!sock))
@@ -1042,9 +1044,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
1042 1044
1043 1045 retry_multishot:
1044 1046 sel.buf_list = NULL;
1047 + len = sr->len;
1045 1048 if (io_do_buffer_select(req)) {
1046 - size_t len = sr->len;
1047 -
1048 1049 sel = io_buffer_select(req, &len, sr->buf_group, issue_flags);
1049 1050 if (!sel.addr)
1050 1051 return -ENOBUFS;
@@ -1065,6 +1066,7 @@ retry_multishot:
1065 1066 if (req->flags & REQ_F_APOLL_MULTISHOT) {
1066 1067 ret = io_recvmsg_multishot(sock, sr, kmsg, flags,
1067 1068 &mshot_finished);
1069 + consumed = ret;
1068 1070 } else {
1069 1071 /* disable partial retry for recvmsg with cmsg attached */
1070 1072 if (flags & MSG_WAITALL && !kmsg->msg.msg_controllen)
@@ -1072,6 +1074,15 @@ retry_multishot:
1072 1074
1073 1075 ret = __sys_recvmsg_sock(sock, &kmsg->msg, sr->umsg,
1074 1076 kmsg->uaddr, flags);
1077 + /*
1078 + * With MSG_TRUNC, the net layer will return the full size of
1079 + * the packet, even if we only filled part of it in the buffers.
1080 + * Adjust the returned size to consume only the real part of the
1081 + * buffer.
1082 + */
1083 + consumed = ret;
1084 + if (ret > 0)
1085 + consumed = min_t(size_t, ret, len);
1075 1086 }
1076 1087
1077 1088 if (ret < min_ret) {
@@ -1098,7 +1109,7 @@ retry_multishot:
1098 1109 io_kbuf_recycle(req, sel.buf_list, issue_flags);
1099 1110
1100 1111 sel.val = ret;
1101 - if (!io_recv_finish(req, kmsg, &sel, mshot_finished, issue_flags))
1112 + if (!io_recv_finish(req, kmsg, &sel, mshot_finished, issue_flags, consumed))
1102 1113 goto retry_multishot;
1103 1114
1104 1115 return sel.val;
@@ -1108,6 +1119,7 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
1108 1119 struct io_br_sel *sel, unsigned int issue_flags)
1109 1120 {
1110 1121 struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
1122 + size_t len;
1111 1123 int ret;
1112 1124
1113 1125 /*
@@ -1153,13 +1165,14 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
1153 1165 /* special case 1 vec, can be a fast path */
1154 1166 if (ret == 1) {
1155 1167 sr->buf = arg.iovs[0].iov_base;
1156 - sr->len = arg.iovs[0].iov_len;
1168 + len = sr->len = arg.iovs[0].iov_len;
1157 1169 goto map_ubuf;
1158 1170 }
1159 1171 iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret,
1160 - arg.out_len);
1172 + arg.out_len);
1173 + len = arg.out_len;
1161 1174 } else {
1162 - size_t len = sel->val;
1175 + len = sel->val;
1163 1176
1164 1177 *sel = io_buffer_select(req, &len, sr->buf_group, issue_flags);
1165 1178 if (!sel->addr)
@@ -1173,7 +1186,7 @@ map_ubuf:
1173 1186 return ret;
1174 1187 }
1175 1188
1176 - return 0;
1189 + return len;
1177 1190 }
1178 1191
1179 1192 int io_recv(struct io_kiocb *req, unsigned int issue_flags)
@@ -1183,9 +1196,10 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
1183 1196 struct io_br_sel sel;
1184 1197 struct socket *sock;
1185 1198 unsigned flags;
1186 - int ret, min_ret = 0;
1199 + int ret, min_ret = 0, consumed = 0;
1187 1200 bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
1188 1201 bool mshot_finished;
1202 + size_t len = 0;
1189 1203
1190 1204 sock = sock_from_file(req->file);
1191 1205 if (unlikely(!sock))
@@ -1213,6 +1227,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags)
1213 1227
1214 1228 retry_multishot:
1215 1229 sel.buf_list = NULL;
1230 + len = sr->len;
1216 1231 if (io_do_buffer_select(req)) {
1217 1232 sel.val = sr->len;
1218 1233 ret = io_recv_buf_select(req, kmsg, &sel, issue_flags);
@@ -1220,6 +1235,7 @@ retry_multishot:
1220 1235 kmsg->msg.msg_inq = -1;
1221 1236 goto out_free;
1222 1237 }
1238 + len = ret;
1223 1239 sr->buf = NULL;
1224 1240 }
1225 1241
@@ -1250,6 +1266,17 @@ out_free:
1250 1266 }
1251 1267
1252 1268 mshot_finished = ret <= 0;
1269 +
1270 + /*
1271 + * With MSG_TRUNC, the net layer will return the full size of
1272 + * the packet, even if we only filled part of it in the buffers.
1273 + * Adjust the returned size to consume only the real part of the
1274 + * buffer.
1275 + */
1276 + consumed = ret;
1277 + if (ret > 0)
1278 + consumed = min_t(size_t, ret, len);
1279 +
1253 1280 if (ret > 0)
1254 1281 ret += sr->done_io;
1255 1282 else if (sr->done_io)
@@ -1258,7 +1285,7 @@ out_free:
1258 1285 io_kbuf_recycle(req, sel.buf_list, issue_flags);
1259 1286
1260 1287 sel.val = ret;
1261 - if (!io_recv_finish(req, kmsg, &sel, mshot_finished, issue_flags))
1288 + if (!io_recv_finish(req, kmsg, &sel, mshot_finished, issue_flags, consumed))
1262 1289 goto retry_multishot;
1263 1290
1264 1291 return sel.val;
modified io_uring/rw.c
@@ -517,20 +517,25 @@ static void io_req_end_write(struct io_kiocb *req)
517 517 }
518 518 }
519 519
520 - /*
521 - * Trigger the notifications after having done some IO, and finish the write
522 - * accounting, if any.
523 - */
524 - static void io_req_io_end(struct io_kiocb *req)
520 + /* Trigger the notifications after having done some IO. */
521 + static void io_req_io_notify(struct io_kiocb *req)
525 522 {
526 523 struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
527 524
528 - if (rw->kiocb.ki_flags & IOCB_WRITE) {
529 - io_req_end_write(req);
525 + if (rw->kiocb.ki_flags & IOCB_WRITE)
530 526 fsnotify_modify(req->file);
531 - } else {
527 + else
532 528 fsnotify_access(req->file);
533 - }
529 + }
530 +
531 + /* Finish write accounting and notify, for inline completions only. */
532 + static void io_req_io_end(struct io_kiocb *req)
533 + {
534 + struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
535 +
536 + if (rw->kiocb.ki_flags & IOCB_WRITE)
537 + io_req_end_write(req);
538 + io_req_io_notify(req);
534 539 }
535 540
536 541 static void __io_complete_rw_common(struct io_kiocb *req, long res)
@@ -563,7 +568,7 @@ void io_req_rw_complete(struct io_tw_req tw_req, io_tw_token_t tw)
563 568 {
564 569 struct io_kiocb *req = tw_req.req;
565 570
566 - io_req_io_end(req);
571 + io_req_io_notify(req);
567 572
568 573 if (req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING))
569 574 req->cqe.flags |= io_put_kbuf(req, max(req->cqe.res, 0), NULL);
@@ -577,6 +582,10 @@ static void io_complete_rw(struct kiocb *kiocb, long res)
577 582 struct io_rw *rw = container_of(kiocb, struct io_rw, kiocb);
578 583 struct io_kiocb *req = cmd_to_io_kiocb(rw);
579 584
585 + /* ring owner may block in freeze_super() before task_work runs */
586 + if (kiocb->ki_flags & IOCB_WRITE)
587 + io_req_end_write(req);
588 +
580 589 __io_complete_rw_common(req, res);
581 590 io_req_set_res(req, io_fixup_rw_res(req, res), 0);
582 591 req->io_task_work.func = io_req_rw_complete;
@@ -871,6 +880,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
871 880 kiocb->private = NULL;
872 881 kiocb->ki_flags |= IOCB_HIPRI;
873 882 req->iopoll_completed = 0;
883 + req->cqe.flags = 0;
874 884 if (ctx->flags & IORING_SETUP_HYBRID_IOPOLL) {
875 885 /* make sure every req only blocks once*/
876 886 req->flags &= ~REQ_F_IOPOLL_STATE;
@@ -1373,7 +1383,7 @@ int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
1373 1383 list_del(&req->iopoll_node);
1374 1384 wq_list_add_tail(&req->comp_list, &ctx->submit_state.compl_reqs);
1375 1385 nr_events++;
1376 - req->cqe.flags = io_put_kbuf(req, max(req->cqe.res, 0), NULL);
1386 + req->cqe.flags |= io_put_kbuf(req, max(req->cqe.res, 0), NULL);
1377 1387 if (!io_is_uring_cmd(req))
1378 1388 io_req_rw_cleanup(req, 0);
1379 1389 }
modified kernel/entry/syscall_user_dispatch.c
@@ -178,7 +178,7 @@ int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long siz
178 178 (char __user *)(uintptr_t)cfg.selector);
179 179 }
180 180
181 - #ifdef CONFIG_PROC_SYSCTL
181 + #ifdef CONFIG_SYSCTL
182 182 static const struct ctl_table syscall_user_dispatch_sysctls[] = {
183 183 {
184 184 .procname = "syscall_user_dispatch",
@@ -195,4 +195,4 @@ static int __init syscall_user_dispatch_sysctl_init(void)
195 195 return 0;
196 196 }
197 197 late_initcall(syscall_user_dispatch_sysctl_init);
198 - #endif /* CONFIG_PROC_SYSCTL */
198 + #endif /* CONFIG_SYSCTL */
modified kernel/events/core.c
@@ -3925,13 +3925,13 @@ static void perf_pmu_sched_task(struct task_struct *prev,
3925 3925 bool sched_in)
3926 3926 {
3927 3927 struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
3928 - struct perf_cpu_pmu_context *cpc;
3928 + struct perf_cpu_pmu_context *cpc, *cpc2;
3929 3929
3930 3930 /* cpuctx->task_ctx will be handled in perf_event_context_sched_in/out */
3931 3931 if (prev == next || cpuctx->task_ctx)
3932 3932 return;
3933 3933
3934 - list_for_each_entry(cpc, this_cpu_ptr(&sched_cb_list), sched_cb_entry)
3934 + list_for_each_entry_safe(cpc, cpc2, this_cpu_ptr(&sched_cb_list), sched_cb_entry)
3935 3935 __perf_pmu_sched_task(cpc, sched_in ? next : prev, sched_in);
3936 3936 }
3937 3937
modified kernel/exit.c
@@ -261,8 +261,11 @@ repeat:
261 261 pidfs_exit(p);
262 262 cgroup_task_release(p);
263 263
264 - /* Retrieve @thread_pid before __unhash_process() may set it to NULL. */
265 - thread_pid = task_pid(p);
264 + /*
265 + * Pin @thread_pid before __unhash_process() clears it. The last
266 + * PIDTYPE detach can otherwise free it before proc_flush_pid().
267 + */
268 + thread_pid = get_pid(task_pid(p));
266 269
267 270 write_lock_irq(&tasklist_lock);
268 271 ptrace_release_task(p);
@@ -291,8 +294,8 @@ repeat:
291 294 }
292 295
293 296 write_unlock_irq(&tasklist_lock);
294 - /* @thread_pid can't go away until free_pids() below */
295 297 proc_flush_pid(thread_pid);
298 + put_pid(thread_pid);
296 299 exit_cred_namespaces(p);
297 300 add_device_randomness(&p->se.sum_exec_runtime,
298 301 sizeof(p->se.sum_exec_runtime));
modified kernel/fork.c
@@ -2133,6 +2133,11 @@ __latent_entropy struct task_struct *copy_process(
2133 2133 p = dup_task_struct(current, node);
2134 2134 if (!p)
2135 2135 goto fork_out;
2136 + /*
2137 + * Must run before the first fallible op, so error paths never
2138 + * free the parent's ret_stack.
2139 + */
2140 + ftrace_graph_init_task(p);
2136 2141 retval = copy_exec_state(clone_flags, p);
2137 2142 if (retval)
2138 2143 goto bad_fork_free;
@@ -2159,8 +2164,6 @@ __latent_entropy struct task_struct *copy_process(
2159 2164 */
2160 2165 p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? args->child_tid : NULL;
2161 2166
2162 - ftrace_graph_init_task(p);
2163 -
2164 2167 rt_mutex_init_task(p);
2165 2168 raw_spin_lock_init(&p->blocked_lock);
2166 2169
modified kernel/nstree.c
@@ -533,19 +533,13 @@ DEFINE_FREE(ns_put, struct ns_common *, if (!IS_ERR_OR_NULL(_T)) ns_put(_T))
533 533 static inline struct ns_common *__must_check legitimize_ns(const struct klistns *kls,
534 534 struct ns_common *candidate)
535 535 {
536 - struct ns_common *ns __free(ns_put) = NULL;
537 -
538 536 if (!ns_requested(kls, candidate))
539 537 return NULL;
540 538
541 - ns = ns_get_unless_inactive(candidate);
542 - if (!ns)
543 - return NULL;
544 -
545 - if (!may_list_ns(kls, ns))
539 + if (!may_list_ns(kls, candidate))
546 540 return NULL;
547 541
548 - return no_free_ptr(ns);
542 + return ns_get_unless_inactive(candidate);
549 543 }
550 544
551 545 static ssize_t do_listns_userns(struct klistns *kls)
modified kernel/printk/nbcon.c
@@ -1887,7 +1887,6 @@ bool nbcon_device_try_acquire(struct console *con)
1887 1887
1888 1888 memset(ctxt, 0, sizeof(*ctxt));
1889 1889 ctxt->console = con;
1890 - /* Keep in sync with nbcon_braille_try_acquire(). */
1891 1890 ctxt->prio = NBCON_PRIO_NORMAL;
1892 1891
1893 1892 if (!nbcon_context_try_acquire(ctxt, false))
@@ -2003,82 +2002,3 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt)
2003 2002 */
2004 2003 __nbcon_atomic_flush_pending_con(ctxt->console, prb_next_reserve_seq(prb));
2005 2004 }
2006 -
2007 - /**
2008 - * nbcon_write_context_is_braille - Checks whether the nbcon write context
2009 - * is using Braille console
2010 - *
2011 - * @wctxt: checked nbcon write context
2012 - *
2013 - * Return: True when the write context is associated with a Braille console.
2014 - * Otherwise, return false.
2015 - *
2016 - * Context: Can be called in any context but only when Braille console is
2017 - * registered and the struct console could not disappear.
2018 - */
2019 - bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt)
2020 - {
2021 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2022 - struct console *con = ctxt->console;
2023 -
2024 - return con && con->flags & CON_BRL;
2025 - }
2026 - EXPORT_SYMBOL_GPL(nbcon_write_context_is_braille);
2027 -
2028 - /**
2029 - * nbcon_braille_try_acquire - Try to acquire nbcon console for braille_write()
2030 - *
2031 - * @con: The nbcon console to acquire
2032 - * @wctxt: The nbcon write context to be used on success
2033 - *
2034 - * Context: braille_write() for emitting a single buffer on Braille console.
2035 - *
2036 - * Return: True if the console was acquired. False otherwise.
2037 - *
2038 - * Braille console is not registered as a proper printk consoles. Instead,
2039 - * it is integrated with the graphical virtual terminal.
2040 - *
2041 - * This function is going to synchronize the Braille write against other
2042 - * operations on the used serial port. The port can be used also for a user
2043 - * input but printk() won't emit the messages there directly. It means
2044 - * the other operations will get synchronized using nbcon_device_try_acquire().
2045 - */
2046 - bool nbcon_braille_try_acquire(struct console *con,
2047 - struct nbcon_write_context *wctxt)
2048 - {
2049 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2050 - bool success;
2051 -
2052 - memset(ctxt, 0, sizeof(*ctxt));
2053 - ctxt->console = con;
2054 - /* Keep in sync with nbcon_device_try_acquire(). */
2055 - if (panic_on_this_cpu())
2056 - ctxt->prio = NBCON_PRIO_PANIC;
2057 - else
2058 - ctxt->prio = NBCON_PRIO_NORMAL;
2059 -
2060 - success = nbcon_context_try_acquire(ctxt, false);
2061 - /*
2062 - * Try hard in panic, otherwise the Braille console would
2063 - * miss a text on the related VT.
2064 - */
2065 - if (panic_on_this_cpu() && !success) {
2066 - ctxt->allow_unsafe_takeover = true;
2067 - success = nbcon_context_try_acquire(ctxt, false);
2068 - }
2069 -
2070 - return success;
2071 - }
2072 -
2073 - /**
2074 - * nbcon_braille_release - Release the nbcon console
2075 - *
2076 - * @wctxt: The nbcon write context initialized by a successful
2077 - * nbcon_braille_try_acquire()
2078 - */
2079 - void nbcon_braille_release(struct nbcon_write_context *wctxt)
2080 - {
2081 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2082 -
2083 - nbcon_context_release(ctxt);
2084 - }
modified kernel/reboot.c
@@ -8,13 +8,14 @@
8 8 #define pr_fmt(fmt) "reboot: " fmt
9 9
10 10 #include <linux/atomic.h>
11 - #include <linux/console.h>
12 11 #include <linux/ctype.h>
13 12 #include <linux/export.h>
14 13 #include <linux/kexec.h>
15 14 #include <linux/kmod.h>
16 15 #include <linux/kmsg_dump.h>
16 + #include <linux/rcupdate.h>
17 17 #include <linux/reboot.h>
18 + #include <linux/sched/signal.h>
18 19 #include <linux/suspend.h>
19 20 #include <linux/syscalls.h>
20 21 #include <linux/syscore_ops.h>
@@ -25,8 +26,7 @@
25 26 */
26 27
27 28 static int C_A_D = 1;
28 - struct pid *cad_pid;
29 - EXPORT_SYMBOL(cad_pid);
29 + struct pid __rcu *cad_pid;
30 30
31 31 #if defined(CONFIG_ARM)
32 32 #define DEFAULT_REBOOT_MODE = REBOOT_HARD
@@ -94,14 +94,6 @@ void emergency_restart(void)
94 94 {
95 95 kmsg_dump(KMSG_DUMP_EMERG);
96 96 system_state = SYSTEM_RESTART;
97 -
98 - /*
99 - * NBCON kthreads won't be flushed and stopped properly in
100 - * the emergency restart. Move them to the atomic mode.
101 - */
102 - nbcon_cpu_emergency_enter();
103 - printk_trigger_flush();
104 -
105 97 machine_emergency_restart();
106 98 }
107 99 EXPORT_SYMBOL_GPL(emergency_restart);
@@ -1380,10 +1372,14 @@ static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffe
1380 1372 {
1381 1373 struct ctl_table tmp_table = *table;
1382 1374 struct pid *new_pid;
1375 + struct pid *old_pid;
1383 1376 pid_t tmp_pid;
1384 1377 int r;
1385 1378
1386 - tmp_pid = pid_vnr(cad_pid);
1379 + rcu_read_lock();
1380 + tmp_pid = pid_vnr(rcu_dereference(cad_pid));
1381 + rcu_read_unlock();
1382 +
1387 1383 tmp_table.data = &tmp_pid;
1388 1384
1389 1385 r = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);
@@ -1394,7 +1390,13 @@ static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffe
1394 1390 if (!new_pid)
1395 1391 return -ESRCH;
1396 1392
1397 - put_pid(xchg(&cad_pid, new_pid));
1393 + old_pid = unrcu_pointer(xchg(&cad_pid, RCU_INITIALIZER(new_pid)));
1394 + /*
1395 + * Wait for cad_pid readers before put_pid(). We cannot use
1396 + * call_rcu() here because free_pid() already owns pid->rcu.
1397 + */
1398 + synchronize_rcu();
1399 + put_pid(old_pid);
1398 1400 return 0;
1399 1401 }
1400 1402
modified kernel/sched/core.c
@@ -5776,8 +5776,8 @@ void sched_tick(void)
5776 5776 {
5777 5777 int cpu = smp_processor_id();
5778 5778 struct rq *rq = cpu_rq(cpu);
5779 - /* accounting goes to the donor task */
5780 - struct task_struct *donor;
5779 + /* scheduler accounting goes to the donor task */
5780 + struct task_struct *curr, *donor;
5781 5781 struct rq_flags rf;
5782 5782 unsigned long hw_pressure;
5783 5783 u64 resched_latency;
@@ -5788,6 +5788,7 @@ void sched_tick(void)
5788 5788 sched_clock_tick();
5789 5789
5790 5790 rq_lock(rq, &rf);
5791 + curr = rq->curr;
5791 5792 donor = rq->donor;
5792 5793
5793 5794 psi_account_irqtime(rq, donor, NULL);
@@ -5813,8 +5814,8 @@ void sched_tick(void)
5813 5814
5814 5815 perf_event_task_tick();
5815 5816
5816 - if (donor->flags & PF_WQ_WORKER)
5817 - wq_worker_tick(donor);
5817 + if (curr->flags & PF_WQ_WORKER)
5818 + wq_worker_tick(curr);
5818 5819
5819 5820 if (!scx_switched_all()) {
5820 5821 rq->idle_balance = idle_cpu(cpu);
modified kernel/sched/fair.c
@@ -1032,6 +1032,13 @@ static inline void __max_slice_update(struct sched_entity *se, struct rb_node *n
1032 1032 }
1033 1033 }
1034 1034
1035 + static inline void min_vruntime_copy(struct sched_entity *new, struct sched_entity *old)
1036 + {
1037 + new->min_vruntime = old->min_vruntime;
1038 + new->min_slice = old->min_slice;
1039 + new->max_slice = old->max_slice;
1040 + }
1041 +
1035 1042 /*
1036 1043 * se->min_vruntime = min(se->vruntime, {left,right}->min_vruntime)
1037 1044 */
@@ -1059,8 +1066,9 @@ static inline bool min_vruntime_update(struct sched_entity *se, bool exit)
1059 1066 se->max_slice == old_max_slice;
1060 1067 }
1061 1068
1062 - RB_DECLARE_CALLBACKS(static, min_vruntime_cb, struct sched_entity,
1063 - run_node, min_vruntime, min_vruntime_update);
1069 +
1070 + RB_DECLARE_CALLBACKS_MULTI(static, min_vruntime_cb, struct sched_entity,
1071 + run_node, min_vruntime_copy, min_vruntime_update);
1064 1072
1065 1073 /*
1066 1074 * Enqueue an entity into the rb-tree:
@@ -1073,6 +1081,8 @@ static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
1073 1081 sum_w_vruntime_add(cfs_rq, se);
1074 1082 se->min_vruntime = se->vruntime;
1075 1083 se->min_slice = se->slice;
1084 + se->max_slice = se->slice;
1085 +
1076 1086 rb_add_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline,
1077 1087 __entity_less, &min_vruntime_cb);
1078 1088 }
@@ -1404,7 +1414,6 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
1404 1414
1405 1415 se->exec_start = now;
1406 1416 if (entity_is_task(se)) {
1407 - struct task_struct *donor = task_of(se);
1408 1417 struct task_struct *running = rq->curr;
1409 1418 /*
1410 1419 * If se is a task, we account the time against the running
@@ -1417,8 +1426,7 @@ static s64 update_se(struct rq *rq, struct sched_entity *se)
1417 1426 account_group_exec_runtime(running, delta_exec);
1418 1427 account_mm_sched(rq, running, delta_exec);
1419 1428
1420 - /* cgroup time is always accounted against the donor */
1421 - cgroup_account_cputime(donor, delta_exec);
1429 + cgroup_account_cputime(running, delta_exec);
1422 1430 } else {
1423 1431 /* If not task, account the time against donor se */
1424 1432 se->sum_exec_runtime += delta_exec;
modified kernel/signal.c
@@ -1892,6 +1892,18 @@ int kill_pid(struct pid *pid, int sig, int priv)
1892 1892 }
1893 1893 EXPORT_SYMBOL(kill_pid);
1894 1894
1895 + int kill_cad_pid(int sig, int priv)
1896 + {
1897 + int ret;
1898 +
1899 + rcu_read_lock();
1900 + ret = kill_pid(rcu_dereference(cad_pid), sig, priv);
1901 + rcu_read_unlock();
1902 +
1903 + return ret;
1904 + }
1905 + EXPORT_SYMBOL(kill_cad_pid);
1906 +
1895 1907 #ifdef CONFIG_POSIX_TIMERS
1896 1908 /*
1897 1909 * These functions handle POSIX timer signals. POSIX timers use
modified kernel/time/clockevents.c
@@ -615,33 +615,40 @@ void clockevents_handle_noop(struct clock_event_device *dev)
615 615 {
616 616 }
617 617
618 - /**
619 - * clockevents_exchange_device - release and request clock devices
620 - * @old: device to release (can be NULL)
621 - * @new: device to request (can be NULL)
622 - *
623 - * Called from various tick functions with clockevents_lock held and
624 - * interrupts disabled.
625 - */
626 - void clockevents_exchange_device(struct clock_event_device *old,
627 - struct clock_event_device *new)
618 + void __clockevents_exchange_device(struct clock_event_device *old,
619 + struct clock_event_device *new)
628 620 {
629 621 /*
630 622 * Caller releases a clock event device. We queue it into the
631 623 * released list and do a notify add later.
632 624 */
633 625 if (old) {
634 - module_put(old->owner);
635 626 clockevents_switch_state(old, CLOCK_EVT_STATE_DETACHED);
636 627 list_move(&old->list, &clockevents_released);
637 628 }
638 629
639 630 if (new) {
640 - BUG_ON(!clockevent_state_detached(new));
631 + WARN_ON(!clockevent_state_detached(new));
641 632 clockevents_shutdown(new);
642 633 }
643 634 }
644 635
636 + /**
637 + * clockevents_exchange_device - release and request clock devices
638 + * @old: device to release (can be NULL)
639 + * @new: device to request (can be NULL)
640 + *
641 + * Called from various tick functions with clockevents_lock held and
642 + * interrupts disabled.
643 + */
644 + void clockevents_exchange_device(struct clock_event_device *old,
645 + struct clock_event_device *new)
646 + {
647 + __clockevents_exchange_device(old, new);
648 + if (old)
649 + module_put(old->owner);
650 + }
651 +
645 652 /**
646 653 * clockevents_suspend - suspend clock devices
647 654 */
@@ -699,7 +706,7 @@ void tick_offline_cpu(unsigned int cpu)
699 706 if (cpumask_test_cpu(cpu, dev->cpumask) &&
700 707 cpumask_weight(dev->cpumask) == 1 &&
701 708 !tick_is_broadcast_device(dev)) {
702 - BUG_ON(!clockevent_state_detached(dev));
709 + WARN_ON(!clockevent_state_detached(dev));
703 710 list_del(&dev->list);
704 711 }
705 712 }
modified kernel/time/hrtimer.c
@@ -1263,13 +1263,23 @@ remove_and_enqueue_same_base(struct hrtimer *timer, struct hrtimer_clock_base *b
1263 1263 {
1264 1264 bool was_first = false;
1265 1265
1266 + /*
1267 + * Updating the sort key while @timer is queued can temporarily
1268 + * make the tree inconsistent. This is safe under cpu_base->lock:
1269 + * no other queue operation can observe that state.
1270 + * hrtimer_can_update_in_place() either confirms that the new expiry
1271 + * fits between the neighbours or timerqueue_linked_del() removes the
1272 + * timer without consulting the expiry.
1273 + */
1274 + hrtimer_set_expires_range_ns(timer, expires, delta_ns);
1275 + expires = hrtimer_get_expires(timer);
1276 +
1266 1277 /* Remove it from the timer queue if active */
1267 1278 if (timer->is_queued) {
1268 1279 was_first = !timerqueue_linked_prev(&timer->node);
1269 1280
1270 1281 /* Try to update in place to avoid the de/enqueue dance */
1271 1282 if (hrtimer_can_update_in_place(timer, base, expires)) {
1272 - hrtimer_set_expires_range_ns(timer, expires, delta_ns);
1273 1283 trace_hrtimer_start(timer, mode, true);
1274 1284 if (was_first)
1275 1285 base->expires_next = expires;
@@ -1280,9 +1290,6 @@ remove_and_enqueue_same_base(struct hrtimer *timer, struct hrtimer_clock_base *b
1280 1290 timerqueue_linked_del(&base->active, &timer->node);
1281 1291 }
1282 1292
1283 - /* Set the new expiry time */
1284 - hrtimer_set_expires_range_ns(timer, expires, delta_ns);
1285 -
1286 1293 debug_activate(timer, mode, timer->is_queued);
1287 1294 base->cpu_base->active_bases |= 1 << base->index;
1288 1295
modified kernel/time/tick-broadcast.c
@@ -165,23 +165,31 @@ static bool tick_set_oneshot_wakeup_device(struct clock_event_device *newdev,
165 165 */
166 166 void tick_install_broadcast_device(struct clock_event_device *dev, int cpu)
167 167 {
168 - struct clock_event_device *cur = tick_broadcast_device.evtdev;
168 + struct clock_event_device *cur;
169 169
170 - if (tick_set_oneshot_wakeup_device(dev, cpu))
171 - return;
170 + scoped_guard(raw_spinlock_irqsave, &tick_broadcast_lock) {
172 171
173 - if (!tick_check_broadcast_device(cur, dev))
174 - return;
172 + if (tick_set_oneshot_wakeup_device(dev, cpu))
173 + return;
175 174
176 - if (!try_module_get(dev->owner))
177 - return;
175 + cur = tick_broadcast_device.evtdev;
176 + if (!tick_check_broadcast_device(cur, dev))
177 + return;
178 178
179 - clockevents_exchange_device(cur, dev);
179 + if (!try_module_get(dev->owner))
180 + return;
181 +
182 + __clockevents_exchange_device(cur, dev);
183 + if (cur)
184 + cur->event_handler = clockevents_handle_noop;
185 + WRITE_ONCE(tick_broadcast_device.evtdev, dev);
186 + if (!cpumask_empty(tick_broadcast_mask))
187 + tick_broadcast_start_periodic(dev);
188 + }
189 +
190 + /* Module release must be outside of the lock */
180 191 if (cur)
181 - cur->event_handler = clockevents_handle_noop;
182 - tick_broadcast_device.evtdev = dev;
183 - if (!cpumask_empty(tick_broadcast_mask))
184 - tick_broadcast_start_periodic(dev);
192 + module_put(cur->owner);
185 193
186 194 if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
187 195 return;
@@ -1218,7 +1226,7 @@ int tick_broadcast_oneshot_active(void)
1218 1226 */
1219 1227 bool tick_broadcast_oneshot_available(void)
1220 1228 {
1221 - struct clock_event_device *bc = tick_broadcast_device.evtdev;
1229 + struct clock_event_device *bc = READ_ONCE(tick_broadcast_device.evtdev);
1222 1230
1223 1231 return bc ? bc->features & CLOCK_EVT_FEAT_ONESHOT : false;
1224 1232 }
@@ -1226,7 +1234,7 @@ bool tick_broadcast_oneshot_available(void)
1226 1234 #else
1227 1235 int __tick_broadcast_oneshot_control(enum tick_broadcast_state state)
1228 1236 {
1229 - struct clock_event_device *bc = tick_broadcast_device.evtdev;
1237 + struct clock_event_device *bc = READ_ONCE(tick_broadcast_device.evtdev);
1230 1238
1231 1239 if (!bc || (bc->features & CLOCK_EVT_FEAT_HRTIMER))
1232 1240 return -EBUSY;
modified kernel/time/tick-internal.h
@@ -55,6 +55,8 @@ static inline void clockevent_set_state(struct clock_event_device *dev,
55 55 }
56 56
57 57 extern void clockevents_shutdown(struct clock_event_device *dev);
58 + extern void __clockevents_exchange_device(struct clock_event_device *old,
59 + struct clock_event_device *new);
58 60 extern void clockevents_exchange_device(struct clock_event_device *old,
59 61 struct clock_event_device *new);
60 62 extern void clockevents_switch_state(struct clock_event_device *dev,
modified kernel/trace/fgraph.c
@@ -143,9 +143,6 @@ enum {
143 143 #define FGRAPH_DATA_INDEX_MASK GENMASK(FGRAPH_DATA_INDEX_BITS - 1, 0)
144 144 #define FGRAPH_DATA_INDEX_SHIFT (FGRAPH_DATA_SHIFT + FGRAPH_DATA_BITS)
145 145
146 - #define FGRAPH_MAX_INDEX \
147 - ((FGRAPH_INDEX_SIZE << FGRAPH_DATA_BITS) + FGRAPH_RET_INDEX)
148 -
149 146 #define FGRAPH_ARRAY_SIZE FGRAPH_INDEX_BITS
150 147
151 148 /*
modified kernel/trace/ftrace.c
@@ -6675,7 +6675,7 @@ int update_ftrace_direct_mod(struct ftrace_ops *ops, struct ftrace_hash *hash, b
6675 6675
6676 6676 /* Enable the tmp_ops to have the same functions as the hash object. */
6677 6677 ftrace_ops_init(&tmp_ops);
6678 - tmp_ops.func_hash->filter_hash = hash;
6678 + rcu_assign_pointer(tmp_ops.func_hash->filter_hash, hash);
6679 6679
6680 6680 err = register_ftrace_function_nolock(&tmp_ops);
6681 6681 if (err)
modified kernel/trace/rethook.c
@@ -171,7 +171,7 @@ struct rethook_node *rethook_try_get(struct rethook *rh)
171 171 * This expects the caller will set up a rethook on a function entry.
172 172 * When the function returns, the rethook will eventually be reclaimed
173 173 * or released in the rethook_recycle() with call_rcu().
174 - * This means the caller must be run in the RCU-availabe context.
174 + * This means the caller must be run in the RCU-available context.
175 175 */
176 176 if (unlikely(!rcu_is_watching()))
177 177 return NULL;
modified kernel/trace/ring_buffer.c
@@ -904,14 +904,13 @@ static void rb_wake_up_waiters(struct irq_work *work)
904 904 struct ring_buffer_per_cpu *cpu_buffer =
905 905 container_of(rbwork, struct ring_buffer_per_cpu, irq_work);
906 906
907 - /* Called from interrupt context */
908 - raw_spin_lock(&cpu_buffer->reader_lock);
909 - rbwork->wakeup_full = false;
910 - rbwork->full_waiters_pending = false;
907 + scoped_guard(raw_spinlock_irqsave, &cpu_buffer->reader_lock) {
908 + rbwork->wakeup_full = false;
909 + rbwork->full_waiters_pending = false;
911 910
912 - /* Waking up all waiters, they will reset the shortest full */
913 - cpu_buffer->shortest_full = 0;
914 - raw_spin_unlock(&cpu_buffer->reader_lock);
911 + /* Waking up all waiters, they will reset the shortest full */
912 + cpu_buffer->shortest_full = 0;
913 + }
915 914
916 915 wake_up_all(&rbwork->full_waiters);
917 916 }
@@ -7384,7 +7383,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_read_page_data);
7384 7383
7385 7384 /**
7386 7385 * ring_buffer_read_page_size - get size of the read page.
7387 - * @page: the page to get the size from
7386 + * @rpage: the page to get the size from
7388 7387 *
7389 7388 * Returns size of the page in bytes.
7390 7389 */
@@ -7474,6 +7473,14 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
7474 7473
7475 7474 old_capacity = rb_subbuf_capacity(buffer);
7476 7475
7476 + /* The mmap fast path reads subbuf_order without buffer->mutex. */
7477 + for_each_buffer_cpu(buffer, cpu) {
7478 + if (!cpumask_test_cpu(cpu, buffer->cpumask))
7479 + continue;
7480 + if (atomic_read(&buffer->buffers[cpu]->resize_disabled))
7481 + return -EBUSY;
7482 + }
7483 +
7477 7484 atomic_inc(&buffer->record_disabled);
7478 7485
7479 7486 /* Make sure all commits have finished */
modified kernel/trace/trace.c
@@ -7717,12 +7717,55 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
7717 7717 return cnt;
7718 7718 }
7719 7719
7720 + static bool tr_option_match(struct trace_array *tr, void *topt)
7721 + {
7722 + for (int i = 0; i < tr->nr_topts; i++) {
7723 + struct trace_options *tr_topts = &tr->topts[i];
7724 +
7725 + if (topt >= (void *)&tr_topts->topts[0] &&
7726 + topt < (void *)&tr_topts->topts[tr_topts->nr_topts])
7727 + return true;
7728 + }
7729 + return false;
7730 + }
7731 +
7732 + /*
7733 + * The topt is the address of a trace_array->topts[] element that holds the
7734 + * the tracer options descriptor. But since the trace_array reference has not
7735 + * been taken yet, it cannot be dereferenced as it could have been freed by
7736 + * a rmdir of the instance the trace_array represents.
7737 + *
7738 + * Search the list of trace_arrays and compare the topt to the address of
7739 + * the entire trace_array topts array for each trace_array in the list.
7740 + * If one is matched, then take the reference and return it. If not, the
7741 + * trace_array no longer exits.
7742 + */
7743 + static int trace_array_tracer_options_get(void *topt)
7744 + {
7745 + struct trace_array *tr;
7746 + int ret;
7747 +
7748 + ret = security_locked_down(LOCKDOWN_TRACEFS);
7749 + if (ret)
7750 + return ret;
7751 +
7752 + if (tracing_disabled)
7753 + return -ENODEV;
7754 +
7755 + guard(mutex)(&trace_types_lock);
7756 + list_for_each_entry(tr, &ftrace_trace_arrays, list) {
7757 + if (tr_option_match(tr, topt))
7758 + return __trace_array_get(tr);
7759 + }
7760 + return -ENODEV;
7761 + }
7762 +
7720 7763 static int tracing_open_options(struct inode *inode, struct file *filp)
7721 7764 {
7722 7765 struct trace_option_dentry *topt = inode->i_private;
7723 7766 int ret;
7724 7767
7725 - ret = tracing_check_open_get_tr(topt->tr);
7768 + ret = trace_array_tracer_options_get(topt);
7726 7769 if (ret)
7727 7770 return ret;
7728 7771
@@ -7984,6 +8027,7 @@ create_trace_option_files(struct trace_array *tr, struct tracer *tracer,
7984 8027 tr->topts = tr_topts;
7985 8028 tr->topts[tr->nr_topts].tracer = tracer;
7986 8029 tr->topts[tr->nr_topts].topts = topts;
8030 + tr->topts[tr->nr_topts].nr_topts = cnt;
7987 8031 tr->nr_topts++;
7988 8032
7989 8033 for (cnt = 0; opts[cnt].name; cnt++) {
modified kernel/trace/trace.h
@@ -227,6 +227,7 @@ struct array_buffer {
227 227 struct trace_options {
228 228 struct tracer *tracer;
229 229 struct trace_option_dentry *topts;
230 + int nr_topts;
230 231 };
231 232
232 233 struct trace_pid_list *trace_pid_list_alloc(void);
@@ -1952,6 +1953,7 @@ struct event_trigger_data {
1952 1953
1953 1954 struct enable_trigger_data {
1954 1955 struct trace_event_file *file;
1956 + struct trace_event_call *call;
1955 1957 bool enable;
1956 1958 bool hist;
1957 1959 };
modified kernel/trace/trace_events.c
@@ -1489,6 +1489,8 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
1489 1489 /* Put back the colon to allow this to be called again */
1490 1490 if (buf)
1491 1491 *(buf - 1) = ':';
1492 + if (mod)
1493 + *(mod - 5) = ':';
1492 1494
1493 1495 return ret;
1494 1496 }
modified kernel/trace/trace_events_hist.c
@@ -169,7 +169,6 @@ struct hist_field {
169 169 struct hist_field *operands[HIST_FIELD_OPERANDS_MAX];
170 170 struct hist_trigger_data *hist_data;
171 171 enum hist_field_fn fn_num;
172 - unsigned int ref;
173 172 unsigned int size;
174 173 unsigned int offset;
175 174 unsigned int is_signed;
@@ -1913,16 +1912,8 @@ out:
1913 1912 return field_op;
1914 1913 }
1915 1914
1916 - static void get_hist_field(struct hist_field *hist_field)
1917 - {
1918 - hist_field->ref++;
1919 - }
1920 -
1921 1915 static void __destroy_hist_field(struct hist_field *hist_field)
1922 1916 {
1923 - if (--hist_field->ref > 1)
1924 - return;
1925 -
1926 1917 kfree(hist_field->var.name);
1927 1918 kfree(hist_field->name);
1928 1919
@@ -1969,8 +1960,6 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
1969 1960 if (!hist_field)
1970 1961 return NULL;
1971 1962
1972 - hist_field->ref = 1;
1973 -
1974 1963 hist_field->hist_data = hist_data;
1975 1964
1976 1965 if (flags & HIST_FIELD_FL_EXPR || flags & HIST_FIELD_FL_ALIAS)
@@ -2223,10 +2212,8 @@ static struct hist_field *create_var_ref(struct hist_trigger_data *hist_data,
2223 2212 for (i = 0; i < hist_data->n_var_refs; i++) {
2224 2213 ref_field = hist_data->var_refs[i];
2225 2214 if (ref_field->var.idx == var_field->var.idx &&
2226 - ref_field->var.hist_data == var_field->hist_data) {
2227 - get_hist_field(ref_field);
2215 + ref_field->var.hist_data == var_field->hist_data)
2228 2216 return ref_field;
2229 - }
2230 2217 }
2231 2218 /* Sanity check to avoid out-of-bound write on 'hist_data->var_refs' */
2232 2219 if (hist_data->n_var_refs >= TRACING_MAP_VARS_MAX)
@@ -2234,7 +2221,7 @@ static struct hist_field *create_var_ref(struct hist_trigger_data *hist_data,
2234 2221 ref_field = create_hist_field(var_field->hist_data, NULL, flags, NULL);
2235 2222 if (ref_field) {
2236 2223 if (init_var_ref(ref_field, var_field, system, event_name)) {
2237 - destroy_hist_field(ref_field, 0);
2224 + __destroy_hist_field(ref_field);
2238 2225 return NULL;
2239 2226 }
2240 2227
@@ -2330,6 +2317,7 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
2330 2317 struct ftrace_event_field *field = NULL;
2331 2318 char *field_name, *modifier, *str;
2332 2319 struct trace_array *tr = file->tr;
2320 + bool stack_modifier = false;
2333 2321
2334 2322 modifier = str = kstrdup(field_str, GFP_KERNEL);
2335 2323 if (!modifier)
@@ -2352,9 +2340,10 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
2352 2340 *flags |= HIST_FIELD_FL_EXECNAME;
2353 2341 else if (strcmp(modifier, "syscall") == 0)
2354 2342 *flags |= HIST_FIELD_FL_SYSCALL;
2355 - else if (strcmp(modifier, "stacktrace") == 0)
2343 + else if (strcmp(modifier, "stacktrace") == 0) {
2356 2344 *flags |= HIST_FIELD_FL_STACKTRACE;
2357 - else if (strcmp(modifier, "log2") == 0)
2345 + stack_modifier = true;
2346 + } else if (strcmp(modifier, "log2") == 0)
2358 2347 *flags |= HIST_FIELD_FL_LOG2;
2359 2348 else if (strcmp(modifier, "usecs") == 0)
2360 2349 *flags |= HIST_FIELD_FL_TIMESTAMP_USECS;
@@ -2415,6 +2404,7 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
2415 2404 *flags |= HIST_FIELD_FL_CPU;
2416 2405 } else if (field && field->filter_type == FILTER_STACKTRACE) {
2417 2406 *flags |= HIST_FIELD_FL_STACKTRACE;
2407 + field = NULL;
2418 2408 } else if (field && field->filter_type == FILTER_COMM) {
2419 2409 *flags |= HIST_FIELD_FL_COMM | HIST_FIELD_FL_STRING;
2420 2410 } else {
@@ -2425,6 +2415,12 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
2425 2415 }
2426 2416 }
2427 2417 }
2418 +
2419 + if (stack_modifier &&
2420 + (!field || field->filter_type != FILTER_STACKTRACE)) {
2421 + hist_err(tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));
2422 + field = ERR_PTR(-EINVAL);
2423 + }
2428 2424 out:
2429 2425 kfree(str);
2430 2426
@@ -3276,7 +3272,6 @@ static struct hist_field *create_var(struct hist_trigger_data *hist_data,
3276 3272 goto out;
3277 3273 }
3278 3274
3279 - var->ref = 1;
3280 3275 var->flags = HIST_FIELD_FL_VAR;
3281 3276 var->var.idx = idx;
3282 3277 var->var.hist_data = var->hist_data = hist_data;
@@ -4313,8 +4308,7 @@ static int __create_val_field(struct hist_trigger_data *hist_data,
4313 4308 goto err;
4314 4309 } else {
4315 4310 /* Value */
4316 - if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT |
4317 - HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 |
4311 + if (hist_field->flags & (HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 |
4318 4312 HIST_FIELD_FL_SYM | HIST_FIELD_FL_SYM_OFFSET |
4319 4313 HIST_FIELD_FL_SYSCALL | HIST_FIELD_FL_STACKTRACE))
4320 4314 goto err;
@@ -4331,6 +4325,7 @@ static int __create_val_field(struct hist_trigger_data *hist_data,
4331 4325 return ret;
4332 4326 err:
4333 4327 hist_err(file->tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));
4328 + destroy_hist_field(hist_field, 0);
4334 4329 return -EINVAL;
4335 4330 }
4336 4331
@@ -5690,7 +5685,7 @@ static int print_entries(struct seq_file *m,
5690 5685 {
5691 5686 struct tracing_map_sort_entry **sort_entries = NULL;
5692 5687 struct tracing_map *map = hist_data->map;
5693 - int i, j, n_entries;
5688 + int i, j, n_entries, ret;
5694 5689 struct hist_val_stat *stats = NULL;
5695 5690 u64 val;
5696 5691
@@ -5700,6 +5695,8 @@ static int print_entries(struct seq_file *m,
5700 5695 if (n_entries < 0)
5701 5696 return n_entries;
5702 5697
5698 + ret = n_entries;
5699 +
5703 5700 /* Calculate the max and the total for each field if needed. */
5704 5701 for (j = 0; j < hist_data->n_vals; j++) {
5705 5702 if (!(hist_data->fields[j]->flags &
@@ -5708,7 +5705,7 @@ static int print_entries(struct seq_file *m,
5708 5705 if (!stats) {
5709 5706 stats = kzalloc_objs(*stats, hist_data->n_vals);
5710 5707 if (!stats) {
5711 - n_entries = -ENOMEM;
5708 + ret = -ENOMEM;
5712 5709 goto out;
5713 5710 }
5714 5711 }
@@ -5729,7 +5726,7 @@ static int print_entries(struct seq_file *m,
5729 5726 out:
5730 5727 tracing_map_destroy_sort_entries(sort_entries, n_entries);
5731 5728
5732 - return n_entries;
5729 + return ret;
5733 5730 }
5734 5731
5735 5732 static void hist_trigger_show(struct seq_file *m,
@@ -6383,17 +6380,18 @@ static int event_hist_trigger_named_init(struct event_trigger_data *data)
6383 6380 {
6384 6381 int ret;
6385 6382
6386 - data->ref++;
6387 -
6388 - save_named_trigger(data->named_data->name, data);
6389 -
6390 6383 ret = event_hist_trigger_init(data->named_data);
6391 6384 if (ret < 0) {
6392 6385 kfree(data->cmd_ops);
6393 6386 data->cmd_ops = &trigger_hist_cmd;
6387 + return ret;
6394 6388 }
6395 6389
6396 - return ret;
6390 + data->ref++;
6391 +
6392 + save_named_trigger(data->named_data->name, data);
6393 +
6394 + return 0;
6397 6395 }
6398 6396
6399 6397 static void event_hist_trigger_named_free(struct event_trigger_data *data)
@@ -6643,12 +6641,6 @@ static int hist_register_trigger(char *glob,
6643 6641 data->cmd_ops = cmd_ops;
6644 6642 }
6645 6643
6646 - if (data->cmd_ops->init) {
6647 - ret = data->cmd_ops->init(data);
6648 - if (ret < 0)
6649 - goto out;
6650 - }
6651 -
6652 6644 if (hist_data->enable_timestamps) {
6653 6645 char *clock = hist_data->attrs->clock;
6654 6646
@@ -6661,6 +6653,15 @@ static int hist_register_trigger(char *glob,
6661 6653 tracing_set_filter_buffering(file->tr, true);
6662 6654 }
6663 6655
6656 + if (data->cmd_ops->init) {
6657 + ret = data->cmd_ops->init(data);
6658 + if (ret < 0) {
6659 + if (hist_data->enable_timestamps)
6660 + tracing_set_filter_buffering(file->tr, false);
6661 + goto out;
6662 + }
6663 + }
6664 +
6664 6665 if (named_data) {
6665 6666 remove_hist_vars(hist_data);
6666 6667 destroy_hist_data(hist_data);
@@ -6678,11 +6679,12 @@ static int hist_trigger_enable(struct event_trigger_data *data,
6678 6679
6679 6680 update_cond_flag(file);
6680 6681
6681 - if (trace_event_trigger_enable_disable(file, 1) < 0) {
6682 - list_del_rcu(&data->list);
6683 - update_cond_flag(file);
6682 + /*
6683 + * On failure the caller undoes the registration, and
6684 + * hist_unregister_trigger() can only find the trigger here.
6685 + */
6686 + if (trace_event_trigger_enable_disable(file, 1) < 0)
6684 6687 ret--;
6685 - }
6686 6688
6687 6689 return ret;
6688 6690 }
@@ -6760,13 +6762,13 @@ static void hist_unregister_trigger(char *glob,
6760 6762 }
6761 6763 }
6762 6764
6763 - if (test && test->cmd_ops->free)
6764 - test->cmd_ops->free(test);
6765 -
6766 6765 if (hist_data->enable_timestamps) {
6767 6766 if (!hist_data->remove || test)
6768 6767 tracing_set_filter_buffering(file->tr, false);
6769 6768 }
6769 +
6770 + if (test && test->cmd_ops->free)
6771 + test->cmd_ops->free(test);
6770 6772 }
6771 6773
6772 6774 static bool hist_file_check_refs(struct trace_event_file *file)
@@ -6971,6 +6973,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
6971 6973 return ret;
6972 6974 out_unreg:
6973 6975 event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
6976 + /* The unregister frees trigger_data, skip out_free */
6977 + goto out;
6974 6978 out_free:
6975 6979 remove_hist_vars(hist_data);
6976 6980
modified kernel/trace/trace_events_trigger.c
@@ -1728,7 +1728,8 @@ static void enable_trigger_private_data_free(struct event_trigger_data *data)
1728 1728 {
1729 1729 struct enable_trigger_data *enable_data = data->private_data;
1730 1730
1731 - trace_event_put_ref(enable_data->file->event_call);
1731 + /* The file may already be freed here, only the call is kept alive */
1732 + trace_event_put_ref(enable_data->call);
1732 1733 kfree(enable_data);
1733 1734 }
1734 1735
@@ -1801,6 +1802,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops,
1801 1802 enable_data->hist = hist;
1802 1803 enable_data->enable = enable;
1803 1804 enable_data->file = event_enable_file;
1805 + enable_data->call = event_enable_file->event_call;
1804 1806
1805 1807 trigger_data = trigger_data_alloc(cmd_ops, cmd, param, enable_data);
1806 1808 if (!trigger_data)
modified kernel/trace/trace_events_user.c
@@ -1122,10 +1122,9 @@ static void user_event_destroy_validators(struct user_event *user)
1122 1122 }
1123 1123 }
1124 1124
1125 - static void user_event_destroy_fields(struct user_event *user)
1125 + static void user_event_destroy_fields(struct list_head *head)
1126 1126 {
1127 1127 struct ftrace_event_field *field, *next;
1128 - struct list_head *head = &user->fields;
1129 1128
1130 1129 list_for_each_entry_safe(field, next, head, link) {
1131 1130 list_del(&field->link);
@@ -1502,17 +1501,32 @@ static int user_event_set_call_visible(struct user_event *user, bool visible)
1502 1501
1503 1502 static int destroy_user_event(struct user_event *user)
1504 1503 {
1504 + LIST_HEAD(fields);
1505 1505 int ret = 0;
1506 1506
1507 1507 lockdep_assert_held(&event_mutex);
1508 1508
1509 - /* Must destroy fields before call removal */
1510 - user_event_destroy_fields(user);
1509 + /*
1510 + * Detach the fields before removing the call. Removing the event
1511 + * frees the field list memory (trace_destroy_fields() is run on
1512 + * successful removal and kmem_cache_free()s the fields), but the
1513 + * fields here are allocated and owned by user_events. Destroy
1514 + * them separately once removal has succeeded.
1515 + */
1516 + list_splice_init(&user->fields, &fields);
1511 1517
1512 1518 ret = user_event_set_call_visible(user, false);
1513 1519
1514 - if (ret)
1520 + if (ret) {
1521 + /*
1522 + * Removal failed and the event stays registered, recover
1523 + * the fields so it is left in a consistent state.
1524 + */
1525 + list_splice(&fields, &user->fields);
1515 1526 return ret;
1527 + }
1528 +
1529 + user_event_destroy_fields(&fields);
1516 1530
1517 1531 dyn_event_remove(&user->devent);
1518 1532 hash_del(&user->node);
@@ -2212,7 +2226,7 @@ static int user_event_parse(struct user_event_group *group, char *name,
2212 2226 put_user_lock:
2213 2227 mutex_unlock(&event_mutex);
2214 2228 put_user:
2215 - user_event_destroy_fields(user);
2229 + user_event_destroy_fields(&user->fields);
2216 2230 user_event_destroy_validators(user);
2217 2231 kfree(user->call.print_fmt);
2218 2232
modified kernel/trace/trace_functions_graph.c
@@ -52,6 +52,7 @@ struct fgraph_data {
52 52 };
53 53 struct ftrace_graph_ret_entry ret;
54 54 int failed;
55 + int ent_size;
55 56 int cpu;
56 57 };
57 58
@@ -1274,6 +1275,7 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
1274 1275 if (s->full) {
1275 1276 data->failed = 1;
1276 1277 data->cpu = cpu;
1278 + data->ent_size = iter->ent_size;
1277 1279 } else
1278 1280 data->failed = 0;
1279 1281 }
@@ -1457,6 +1459,7 @@ print_graph_function_flags(struct trace_iterator *iter, u32 flags)
1457 1459 if (data && data->failed) {
1458 1460 field = &data->ent.ent;
1459 1461 iter->cpu = data->cpu;
1462 + iter->ent_size = data->ent_size;
1460 1463 ret = print_graph_entry(field, s, iter, flags);
1461 1464 if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) {
1462 1465 per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1;
modified kernel/trace/trace_remote.c
@@ -980,9 +980,12 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size,
980 980 const struct cpumask *cpumask)
981 981 {
982 982 size_t min_desc_size = trace_buffer_desc_size(buffer_size, cpumask_weight(cpumask));
983 - unsigned int nr_pages = max(DIV_ROUND_UP(buffer_size, PAGE_SIZE), 2UL) + 1;
984 983 struct ring_buffer_desc *rb_desc;
985 984 int cpu, ret = -ENOMEM;
985 + unsigned int nr_pages;
986 +
987 + if (min_desc_size == SIZE_MAX)
988 + return -E2BIG;
986 989
987 990 if (desc_size < min_desc_size)
988 991 return -EINVAL;
@@ -991,6 +994,7 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size,
991 994 desc->struct_len = min_desc_size;
992 995
993 996 rb_desc = __first_ring_buffer_desc(desc);
997 + nr_pages = __calc_nr_pages_ring_buffer_desc(buffer_size);
994 998
995 999 for_each_cpu(cpu, cpumask) {
996 1000 unsigned int id;
modified lib/iov_iter.c
@@ -1921,15 +1921,29 @@ ssize_t iov_iter_extract_bvecs(struct iov_iter *iter, struct bio_vec *bv,
1921 1921 unsigned short max_vecs, unsigned mem_align_mask,
1922 1922 iov_iter_extraction_t extraction_flags)
1923 1923 {
1924 - unsigned long start = (unsigned long)iter_iov_addr(iter);
1925 1924 unsigned short entries_left = max_vecs - *nr_vecs;
1926 1925 unsigned short nr_pages, i = 0;
1927 1926 size_t left, offset, len;
1928 1927 struct page **pages;
1929 1928 ssize_t size;
1930 1929
1931 - if ((start | iter_iov_len(iter)) & mem_align_mask)
1930 + /*
1931 + * DMA engines typically have both memory address and length alignment
1932 + * requirements, so check these against the alignment mask. For UBUF,
1933 + * IOVEC and KVEC, only the current segment will be extracted from; for
1934 + * everything else we might extract from multiple segments, so we need
1935 + * to check those too.
1936 + */
1937 + if (likely(iter_is_ubuf(iter) ||
1938 + iter_is_iovec(iter) ||
1939 + iov_iter_is_kvec(iter))) {
1940 + unsigned long start = (unsigned long)iter_iov_addr(iter);
1941 +
1942 + if ((start | iter_iov_len(iter)) & mem_align_mask)
1943 + return -EINVAL;
1944 + } else if (iov_iter_alignment(iter) & mem_align_mask) {
1932 1945 return -EINVAL;
1946 + }
1933 1947
1934 1948 /*
1935 1949 * Move page array up in the allocated memory for the bio vecs as far as
modified mm/slab_common.c
@@ -1667,14 +1667,6 @@ static bool kfree_rcu_sheaf(void *obj)
1667 1667 {
1668 1668 struct kmem_cache *s;
1669 1669 struct slab *slab;
1670 - unsigned int free_flags = SLAB_FREE_DEFAULT;
1671 -
1672 - /*
1673 - * It is not safe to spin on PREEMPT_RT because the kernel might be
1674 - * holding a raw spinlock and slab acquires sleeping locks.
1675 - */
1676 - if (IS_ENABLED(CONFIG_PREEMPT_RT))
1677 - free_flags = SLAB_FREE_NOLOCK;
1678 1670
1679 1671 if (is_vmalloc_addr(obj))
1680 1672 return false;
@@ -1685,7 +1677,7 @@ static bool kfree_rcu_sheaf(void *obj)
1685 1677
1686 1678 s = slab->slab_cache;
1687 1679 if (likely(!IS_ENABLED(CONFIG_NUMA) || slab_nid(slab) == numa_mem_id()))
1688 - return __kfree_rcu_sheaf(s, obj, free_flags);
1680 + return __kfree_rcu_sheaf(s, obj, SLAB_FREE_DEFAULT);
1689 1681
1690 1682 return false;
1691 1683 }
@@ -2034,7 +2026,13 @@ void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr)
2034 2026 if (!head)
2035 2027 might_sleep();
2036 2028
2037 - if (kfree_rcu_sheaf(ptr))
2029 + /*
2030 + * kvfree_rcu() is called by set_cpus_allowed_force() with
2031 + * task_struct::pi_lock acquired. On PREEMPT_RT the local_trylock()
2032 + * usage below will acquire the waitlock which must be avoided.
2033 + * Therefore avoid it on PREEMPT_RT.
2034 + */
2035 + if (!IS_ENABLED(CONFIG_PREEMPT_RT) && kfree_rcu_sheaf(ptr))
2038 2036 return;
2039 2037
2040 2038 // Queue the object but don't yet schedule the batch.
modified mm/slub.c
@@ -5680,10 +5680,12 @@ static noinline void free_to_partial_list(
5680 5680 *
5681 5681 * Fail if the slab isn't full anymore due to a concurrent free.
5682 5682 */
5683 - static bool __slab_try_return_freelist(struct kmem_cache *s, struct slab *slab,
5684 - void *head, int cnt)
5683 + static bool __slab_try_return_freelist(struct kmem_cache *s,
5684 + struct kmem_cache_node *n,
5685 + struct slab *slab, void *head, int cnt)
5685 5686 {
5686 5687 struct freelist_counters old, new;
5688 + unsigned long flags;
5687 5689
5688 5690 old.freelist = slab->freelist;
5689 5691 old.counters = slab->counters;
@@ -5695,9 +5697,15 @@ static bool __slab_try_return_freelist(struct kmem_cache *s, struct slab *slab,
5695 5697 new.counters = old.counters;
5696 5698 new.inuse -= cnt;
5697 5699
5698 - if (!slab_update_freelist(s, slab, &old, &new, "__slab_try_return_freelist"))
5700 + spin_lock_irqsave(&n->list_lock, flags);
5701 +
5702 + if (!slab_update_freelist(s, slab, &old, &new, "__slab_try_return_freelist")) {
5703 + spin_unlock_irqrestore(&n->list_lock, flags);
5699 5704 return false;
5705 + }
5700 5706
5707 + add_partial(n, slab, ADD_TO_TAIL);
5708 + spin_unlock_irqrestore(&n->list_lock, flags);
5701 5709 return true;
5702 5710 }
5703 5711
@@ -6088,8 +6096,9 @@ empty:
6088 6096 /*
6089 6097 * kvfree_call_rcu() can be called while holding a raw_spinlock_t. Since
6090 6098 * __kfree_rcu_sheaf() may acquire a spinlock_t (sleeping lock on PREEMPT_RT),
6091 - * this would violate lock nesting rules. Therefore, kvfree_call_rcu() avoids
6092 - * this problem by passing SLAB_FREE_NOLOCK on PREEMPT_RT.
6099 + * this would violate lock nesting rules. Therefore, kfree_call_rcu_nolock()
6100 + * avoids this problem by passing SLAB_FREE_NOLOCK. kvfree_call_rcu() is
6101 + * bypassing the sheaves layer completely on PREEMPT_RT.
6093 6102 *
6094 6103 * However, lockdep still complains that it is invalid to acquire spinlock_t
6095 6104 * while holding raw_spinlock_t, even on !PREEMPT_RT where spinlock_t is a
@@ -7296,10 +7305,8 @@ __refill_objects_node(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int mi
7296 7305 void *head = object;
7297 7306 void *tail;
7298 7307
7299 - if (__slab_try_return_freelist(s, slab, head, count)) {
7300 - list_add(&slab->slab_list, &pc.slabs);
7308 + if (__slab_try_return_freelist(s, n, slab, head, count))
7301 7309 break;
7302 - }
7303 7310
7304 7311 do {
7305 7312 tail = object;
@@ -7312,7 +7319,7 @@ __refill_objects_node(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int mi
7312 7319 break;
7313 7320 }
7314 7321
7315 - if (!list_empty(&pc.slabs)) {
7322 + if (unlikely(!list_empty(&pc.slabs))) {
7316 7323 spin_lock_irqsave(&n->list_lock, flags);
7317 7324
7318 7325 list_for_each_entry(slab, &pc.slabs, slab_list)
modified net/6lowpan/nhc.h
@@ -15,7 +15,7 @@
15 15 * @__nhc: variable name of the lowpan_nhc struct.
16 16 * @_name: const char * of common header compression name.
17 17 * @_nexthdr: ipv6 nexthdr field for the header compression.
18 - * @_nexthdrlen: ipv6 nexthdr len for the reserved space.
18 + * @_hdrlen: ipv6 nexthdr len for the reserved space.
19 19 * @_id: one byte nhc id value.
20 20 * @_idmask: one byte nhc id mask value.
21 21 * @_uncompress: callback for uncompression call.
@@ -102,7 +102,6 @@ int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr,
102 102 /**
103 103 * lowpan_nhc_do_uncompression - calling uncompress callback for nhc
104 104 *
105 - * @nhc: 6LoWPAN nhc context, get by lowpan_nhc_by_ functions.
106 105 * @skb: skb of 6LoWPAN header, skb->data should be pointed to nhc id value.
107 106 * @dev: netdevice for print logging information.
108 107 * @hdr: ipv6hdr for setting nexthdr value.
modified net/bluetooth/hci_sync.c
@@ -4797,6 +4797,24 @@ static int hci_le_set_def_rate_sync(struct hci_dev *hdev)
4797 4797 cp.cont_num = cpu_to_le16(0x0001);
4798 4798 cp.supv_timeout = cpu_to_le16(0x000c); /* 120 ms */
4799 4799
4800 + /* The connection event length recommended in requests by a Peripheral
4801 + * uses units of 125 us with a valid range of 0x0001 to 0x7CFF
4802 + * (0.125 ms to 3.999875 s), so 0x0000 cannot be used. Also note that
4803 + * the Controller is not required to use these values:
4804 + *
4805 + * BLUETOOTH CORE SPECIFICATION Version 6.2 | Vol 4, Part E
4806 + * 7.8.158. LE Set Default Rate Parameters command
4807 + *
4808 + * The Min_CE_Length and Max_CE_Length parameters provide the
4809 + * Controller with the expected minimum and maximum length of the
4810 + * connection events. The Controller is not required to use these
4811 + * values.
4812 + *
4813 + * So it is safe to just use the minimum.
4814 + */
4815 + cp.min_ce_len = cpu_to_le16(0x0001);
4816 + cp.max_ce_len = cpu_to_le16(0x0001);
4817 +
4800 4818 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEF_RATE,
4801 4819 sizeof(cp), &cp, HCI_CMD_TIMEOUT);
4802 4820 }
@@ -7466,8 +7484,24 @@ static int hci_le_conn_rate_request_sync(struct hci_dev *hdev, void *data)
7466 7484 cp.max_latency = cpu_to_le16(params->max_latency);
7467 7485 cp.cont_num = cpu_to_le16(params->cont_num);
7468 7486 cp.supv_timeout = cpu_to_le16(params->rate_supv_timeout);
7469 - cp.min_ce_len = cpu_to_le16(0x0000);
7470 - cp.max_ce_len = cpu_to_le16(0x0000);
7487 +
7488 + /* The connection event length recommended in requests by a Peripheral
7489 + * uses units of 125 us with a valid range of 0x0001 to 0x7CFF
7490 + * (0.125 ms to 3.999875 s), so 0x0000 cannot be used. Also note that
7491 + * the Controller is not required to use these values:
7492 + *
7493 + * BLUETOOTH CORE SPECIFICATION Version 6.2 | Vol 4, Part E
7494 + * 7.8.157. LE Connection Rate Request command
7495 + *
7496 + * The Min_CE_Length and Max_CE_Length parameters provide the
7497 + * Controller with the expected minimum and maximum length of the
7498 + * connection events. The Controller is not required to use these
7499 + * values.
7500 + *
7501 + * So it is safe to just use the minimum.
7502 + */
7503 + cp.min_ce_len = cpu_to_le16(0x0001);
7504 + cp.max_ce_len = cpu_to_le16(0x0001);
7471 7505
7472 7506 hci_dev_unlock(hdev);
7473 7507
modified net/bluetooth/hci_sysfs.c
@@ -13,7 +13,10 @@ static const struct class bt_class = {
13 13 static void bt_link_release(struct device *dev)
14 14 {
15 15 struct hci_conn *conn = to_hci_conn(dev);
16 + struct device *parent = dev->parent;
17 +
16 18 kfree(conn);
19 + put_device(parent);
17 20 }
18 21
19 22 static const struct device_type bt_link = {
@@ -21,6 +24,16 @@ static const struct device_type bt_link = {
21 24 .release = bt_link_release,
22 25 };
23 26
27 + /*
28 + * The rfcomm tty device will possibly retain even when conn
29 + * is down, and sysfs doesn't support move zombie device,
30 + * so we should move the device before conn device is destroyed.
31 + */
32 + static int __match_tty(struct device *dev, const void *data)
33 + {
34 + return !strncmp(dev_name(dev), "rfcomm", 6);
35 + }
36 +
24 37 void hci_conn_init_sysfs(struct hci_conn *conn)
25 38 {
26 39 struct hci_dev *hdev = conn->hdev;
@@ -29,7 +42,7 @@ void hci_conn_init_sysfs(struct hci_conn *conn)
29 42
30 43 conn->dev.type = &bt_link;
31 44 conn->dev.class = &bt_class;
32 - conn->dev.parent = &hdev->dev;
45 + conn->dev.parent = get_device(&hdev->dev);
33 46
34 47 device_initialize(&conn->dev);
35 48 }
@@ -69,7 +82,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn)
69 82 while (1) {
70 83 struct device *dev;
71 84
72 - dev = device_find_any_child(&conn->dev);
85 + dev = device_find_child(&conn->dev, NULL, __match_tty);
73 86 if (!dev)
74 87 break;
75 88 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
modified net/bridge/br_cfm.c
@@ -367,7 +367,7 @@ static u32 ccm_tlv_extract(struct sk_buff *skb, u32 index,
367 367 }
368 368
369 369 /* note: already called with rcu_read_lock */
370 - static int br_cfm_frame_rx(struct net_bridge_port *port, struct sk_buff *skb)
370 + int br_cfm_frame_rx(struct net_bridge_port *port, struct sk_buff *skb)
371 371 {
372 372 u32 mdlevel, interval, size, index, max;
373 373 const struct br_cfm_common_hdr *hdr;
@@ -489,11 +489,6 @@ static int br_cfm_frame_rx(struct net_bridge_port *port, struct sk_buff *skb)
489 489 return 1;
490 490 }
491 491
492 - static struct br_frame_type cfm_frame_type __read_mostly = {
493 - .type = cpu_to_be16(ETH_P_CFM),
494 - .frame_handler = br_cfm_frame_rx,
495 - };
496 -
497 492 int br_cfm_mep_create(struct net_bridge *br,
498 493 const u32 instance,
499 494 struct br_cfm_mep_create *const create,
@@ -559,7 +554,7 @@ int br_cfm_mep_create(struct net_bridge *br,
559 554 INIT_DELAYED_WORK(&mep->ccm_tx_dwork, ccm_tx_work_expired);
560 555
561 556 if (hlist_empty(&br->mep_list))
562 - br_add_frame(br, &cfm_frame_type);
557 + br_opt_toggle(br, BROPT_CFM_ENABLED, true);
563 558
564 559 hlist_add_tail_rcu(&mep->head, &br->mep_list);
565 560
@@ -588,7 +583,7 @@ static void mep_delete_implementation(struct net_bridge *br,
588 583 kfree_rcu(mep, rcu);
589 584
590 585 if (hlist_empty(&br->mep_list))
591 - br_del_frame(br, &cfm_frame_type);
586 + br_opt_toggle(br, BROPT_CFM_ENABLED, false);
592 587 }
593 588
594 589 int br_cfm_mep_delete(struct net_bridge *br,
modified net/bridge/br_device.c
@@ -503,7 +503,6 @@ void br_dev_setup(struct net_device *dev)
503 503 spin_lock_init(&br->lock);
504 504 INIT_LIST_HEAD(&br->port_list);
505 505 INIT_HLIST_HEAD(&br->fdb_list);
506 - INIT_HLIST_HEAD(&br->frame_type_list);
507 506 #if IS_ENABLED(CONFIG_BRIDGE_MRP)
508 507 INIT_HLIST_HEAD(&br->mrp_list);
509 508 #endif
modified net/bridge/br_input.c
@@ -317,17 +317,25 @@ frame_finish:
317 317 return RX_HANDLER_CONSUMED;
318 318 }
319 319
320 + #define BR_CFM_MRP_OPTS \
321 + ((IS_ENABLED(CONFIG_BRIDGE_CFM) ? BIT(BROPT_CFM_ENABLED) : 0UL) | \
322 + (IS_ENABLED(CONFIG_BRIDGE_MRP) ? BIT(BROPT_MRP_ENABLED) : 0UL))
323 +
320 324 /* Return 0 if the frame was not processed otherwise 1
321 325 * note: already called with rcu_read_lock
322 326 */
323 327 static int br_process_frame_type(struct net_bridge_port *p,
324 328 struct sk_buff *skb)
325 329 {
326 - struct br_frame_type *tmp;
330 + struct net_bridge *br = p->br;
331 +
332 + if (skb->protocol == htons(ETH_P_CFM) &&
333 + br_opt_get(br, BROPT_CFM_ENABLED))
334 + return br_cfm_frame_rx(p, skb);
327 335
328 - hlist_for_each_entry_rcu(tmp, &p->br->frame_type_list, list)
329 - if (unlikely(tmp->type == skb->protocol))
330 - return tmp->frame_handler(p, skb);
336 + if (skb->protocol == htons(ETH_P_MRP) &&
337 + br_opt_get(br, BROPT_MRP_ENABLED))
338 + return br_mrp_process(p, skb);
331 339
332 340 return 0;
333 341 }
@@ -425,7 +433,8 @@ static rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
425 433 }
426 434 }
427 435
428 - if (unlikely(br_process_frame_type(p, skb)))
436 + if (unlikely((READ_ONCE(p->br->options) & BR_CFM_MRP_OPTS) &&
437 + br_process_frame_type(p, skb)))
429 438 return RX_HANDLER_PASS;
430 439
431 440 forward:
@@ -467,19 +476,3 @@ rx_handler_func_t *br_get_rx_handler(const struct net_device *dev)
467 476
468 477 return br_handle_frame;
469 478 }
470 -
471 - void br_add_frame(struct net_bridge *br, struct br_frame_type *ft)
472 - {
473 - hlist_add_head_rcu(&ft->list, &br->frame_type_list);
474 - }
475 -
476 - void br_del_frame(struct net_bridge *br, struct br_frame_type *ft)
477 - {
478 - struct br_frame_type *tmp;
479 -
480 - hlist_for_each_entry(tmp, &br->frame_type_list, list)
481 - if (ft == tmp) {
482 - hlist_del_rcu(&ft->list);
483 - return;
484 - }
485 - }
modified net/bridge/br_mrp.c
@@ -6,13 +6,6 @@
6 6 static const u8 mrp_test_dmac[ETH_ALEN] = { 0x1, 0x15, 0x4e, 0x0, 0x0, 0x1 };
7 7 static const u8 mrp_in_test_dmac[ETH_ALEN] = { 0x1, 0x15, 0x4e, 0x0, 0x0, 0x3 };
8 8
9 - static int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb);
10 -
11 - static struct br_frame_type mrp_frame_type __read_mostly = {
12 - .type = cpu_to_be16(ETH_P_MRP),
13 - .frame_handler = br_mrp_process,
14 - };
15 -
16 9 static bool br_mrp_is_ring_port(struct net_bridge_port *p_port,
17 10 struct net_bridge_port *s_port,
18 11 struct net_bridge_port *port)
@@ -486,7 +479,7 @@ static void br_mrp_del_impl(struct net_bridge *br, struct br_mrp *mrp)
486 479 kfree_rcu(mrp, rcu);
487 480
488 481 if (hlist_empty(&br->mrp_list))
489 - br_del_frame(br, &mrp_frame_type);
482 + br_opt_toggle(br, BROPT_MRP_ENABLED, false);
490 483 }
491 484
492 485 /* Adds a new MRP instance.
@@ -536,7 +529,7 @@ int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance)
536 529 rcu_assign_pointer(mrp->s_port, p);
537 530
538 531 if (hlist_empty(&br->mrp_list))
539 - br_add_frame(br, &mrp_frame_type);
532 + br_opt_toggle(br, BROPT_MRP_ENABLED, true);
540 533
541 534 INIT_DELAYED_WORK(&mrp->test_work, br_mrp_test_work_expired);
542 535 INIT_DELAYED_WORK(&mrp->in_test_work, br_mrp_in_test_work_expired);
@@ -1241,7 +1234,7 @@ no_forward:
1241 1234 * normal forwarding.
1242 1235 * note: already called with rcu_read_lock
1243 1236 */
1244 - static int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
1237 + int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
1245 1238 {
1246 1239 /* If there is no MRP instance do normal forwarding */
1247 1240 if (likely(!test_bit(BR_MRP_AWARE_BIT, &p->flags)))
modified net/bridge/br_multicast.c
@@ -1441,16 +1441,17 @@ struct net_bridge_port_group *br_multicast_new_port_group(
1441 1441 goto free_out;
1442 1442 }
1443 1443
1444 - rcu_assign_pointer(p->next, next);
1445 1444 timer_setup(&p->timer, br_multicast_port_group_expired, 0);
1446 1445 timer_setup(&p->rexmit_timer, br_multicast_port_group_rexmit, 0);
1447 - hlist_add_head(&p->mglist, &port->mglist);
1448 1446
1449 1447 if (src)
1450 1448 memcpy(p->eth_addr, src, ETH_ALEN);
1451 1449 else
1452 1450 eth_broadcast_addr(p->eth_addr);
1453 1451
1452 + RCU_INIT_POINTER(p->next, next);
1453 + hlist_add_head_rcu(&p->mglist, &port->mglist);
1454 +
1454 1455 return p;
1455 1456
1456 1457 free_out:
@@ -1465,11 +1466,11 @@ void br_multicast_del_port_group(struct net_bridge_port_group *p)
1465 1466 struct net_bridge_port *port = p->key.port;
1466 1467 __u16 vid = p->key.addr.vid;
1467 1468
1468 - hlist_del_init(&p->mglist);
1469 + hlist_del_init_rcu(&p->mglist);
1469 1470 if (!br_multicast_is_star_g(&p->key.addr))
1470 1471 rhashtable_remove_fast(&port->br->sg_port_tbl, &p->rhnode,
1471 1472 br_sg_port_rht_params);
1472 - kfree(p);
1473 + kfree_rcu(p, rcu);
1473 1474 br_multicast_port_ngroups_dec(port, vid);
1474 1475 }
1475 1476
modified net/bridge/br_private.h
@@ -495,12 +495,13 @@ enum net_bridge_opts {
495 495 BROPT_MST_ENABLED,
496 496 BROPT_MDB_OFFLOAD_FAIL_NOTIFICATION,
497 497 BROPT_FDB_LOCAL_VLAN_0,
498 + BROPT_CFM_ENABLED,
499 + BROPT_MRP_ENABLED,
498 500 };
499 501
500 502 struct net_bridge {
501 503 spinlock_t lock;
502 504 spinlock_t hash_lock;
503 - struct hlist_head frame_type_list;
504 505 struct net_device *dev;
505 506 unsigned long options;
506 507 /* These fields are accessed on each packet */
@@ -932,16 +933,6 @@ int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev);
932 933 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
933 934 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
934 935
935 - struct br_frame_type {
936 - __be16 type;
937 - int (*frame_handler)(struct net_bridge_port *port,
938 - struct sk_buff *skb);
939 - struct hlist_node list;
940 - };
941 -
942 - void br_add_frame(struct net_bridge *br, struct br_frame_type *ft);
943 - void br_del_frame(struct net_bridge *br, struct br_frame_type *ft);
944 -
945 936 static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
946 937 {
947 938 return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
@@ -2080,6 +2071,7 @@ int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
2080 2071 bool br_mrp_enabled(struct net_bridge *br);
2081 2072 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
2082 2073 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
2074 + int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb);
2083 2075 #else
2084 2076 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
2085 2077 struct nlattr *attr, int cmd,
@@ -2103,6 +2095,11 @@ static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
2103 2095 return 0;
2104 2096 }
2105 2097
2098 + static inline int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
2099 + {
2100 + return 0;
2101 + }
2102 +
2106 2103 #endif
2107 2104
2108 2105 /* br_cfm.c */
@@ -2111,6 +2108,7 @@ int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p,
2111 2108 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
2112 2109 bool br_cfm_created(struct net_bridge *br);
2113 2110 void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p);
2111 + int br_cfm_frame_rx(struct net_bridge_port *port, struct sk_buff *skb);
2114 2112 int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br);
2115 2113 int br_cfm_status_fill_info(struct sk_buff *skb,
2116 2114 struct net_bridge *br,
@@ -2135,6 +2133,12 @@ static inline void br_cfm_port_del(struct net_bridge *br,
2135 2133 {
2136 2134 }
2137 2135
2136 + static inline int br_cfm_frame_rx(struct net_bridge_port *port,
2137 + struct sk_buff *skb)
2138 + {
2139 + return 0;
2140 + }
2141 +
2138 2142 static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br)
2139 2143 {
2140 2144 return -EOPNOTSUPP;
modified net/core/dev.c
@@ -9982,7 +9982,7 @@ int netif_change_tx_queue_len(struct net_device *dev, unsigned long new_len)
9982 9982 unsigned int orig_len = dev->tx_queue_len;
9983 9983 int res;
9984 9984
9985 - if (new_len != (unsigned int)new_len)
9985 + if (new_len > S16_MAX)
9986 9986 return -ERANGE;
9987 9987
9988 9988 if (new_len != orig_len) {
modified net/core/rtnetlink.c
@@ -2287,6 +2287,11 @@ nla_put_failure:
2287 2287 return -EMSGSIZE;
2288 2288 }
2289 2289
2290 + static const struct netlink_range_validation txqlen_range = {
2291 + .min = 0,
2292 + .max = S16_MAX,
2293 + };
2294 +
2290 2295 static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
2291 2296 [IFLA_UNSPEC] = { .strict_start_type = IFLA_DPLL_PIN },
2292 2297 [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
@@ -2297,7 +2302,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
2297 2302 [IFLA_LINK] = { .type = NLA_U32 },
2298 2303 [IFLA_MASTER] = { .type = NLA_U32 },
2299 2304 [IFLA_CARRIER] = { .type = NLA_U8 },
2300 - [IFLA_TXQLEN] = { .type = NLA_U32 },
2305 + [IFLA_TXQLEN] = NLA_POLICY_FULL_RANGE(NLA_U32, &txqlen_range),
2301 2306 [IFLA_WEIGHT] = { .type = NLA_U32 },
2302 2307 [IFLA_OPERSTATE] = { .type = NLA_U8 },
2303 2308 [IFLA_LINKMODE] = { .type = NLA_U8 },
modified net/core/skbuff.c
@@ -6690,6 +6690,13 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
6690 6690 }
6691 6691 skb->protocol = next_proto;
6692 6692
6693 + /* The last label is gone, so the inner header recorded by
6694 + * skb_mpls_push() no longer describes this packet. Drop it, or a
6695 + * later push keeps the stale offset.
6696 + */
6697 + if (!eth_p_mpls(next_proto))
6698 + skb->inner_protocol = 0;
6699 +
6693 6700 return 0;
6694 6701 }
6695 6702 EXPORT_SYMBOL_GPL(skb_mpls_pop);
modified net/dsa/tag_brcm.c
@@ -373,6 +373,7 @@ static const struct dsa_device_ops brcm_legacy_fcs_netdev_ops = {
373 373 .xmit = brcm_leg_fcs_tag_xmit,
374 374 .rcv = brcm_leg_tag_rcv,
375 375 .needed_headroom = BRCM_LEG_TAG_LEN,
376 + .needed_tailroom = ETH_FCS_LEN,
376 377 };
377 378
378 379 DSA_TAG_DRIVER(brcm_legacy_fcs_netdev_ops);
modified net/hsr/hsr_slave.c
@@ -149,9 +149,12 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
149 149 int res;
150 150
151 151 /* Don't use promiscuous mode for offload since L2 frame forward
152 - * happens at the offloaded hardware.
152 + * happens at the offloaded hardware. The interlink port never
153 + * gets forwarding offload (RedBox forwarding to/from it is done
154 + * by this driver), so it still needs promiscuous mode to receive
155 + * frames addressed to hsr_dev's MAC rather than its own.
153 156 */
154 - if (!port->hsr->fwd_offloaded) {
157 + if (!port->hsr->fwd_offloaded || port->type == HSR_PT_INTERLINK) {
155 158 res = dev_set_promiscuity(dev, 1);
156 159 if (res)
157 160 return res;
@@ -176,7 +179,7 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
176 179 fail_rx_handler:
177 180 netdev_upper_dev_unlink(dev, hsr_dev);
178 181 fail_upper_dev_link:
179 - if (!port->hsr->fwd_offloaded)
182 + if (!port->hsr->fwd_offloaded || port->type == HSR_PT_INTERLINK)
180 183 dev_set_promiscuity(dev, -1);
181 184
182 185 return res;
@@ -240,7 +243,7 @@ void hsr_del_port(struct hsr_port *port)
240 243 netdev_update_features(master->dev);
241 244 dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
242 245 netdev_rx_handler_unregister(port->dev);
243 - if (!port->hsr->fwd_offloaded)
246 + if (!port->hsr->fwd_offloaded || port->type == HSR_PT_INTERLINK)
244 247 dev_set_promiscuity(port->dev, -1);
245 248 if (port->type == HSR_PT_SLAVE_A || port->type == HSR_PT_SLAVE_B)
246 249 vlan_vids_del_by_dev(port->dev, master->dev);
modified net/ieee802154/6lowpan/core.c
@@ -150,7 +150,7 @@ static int lowpan_newlink(struct net_device *ldev,
150 150 wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
151 151 if (!wdev)
152 152 return -ENODEV;
153 - if (wdev->type != ARPHRD_IEEE802154) {
153 + if (wdev->type != ARPHRD_IEEE802154 || !wdev->ieee802154_ptr) {
154 154 dev_put(wdev);
155 155 return -EINVAL;
156 156 }
modified net/ipv4/fib_rules.c
@@ -214,6 +214,8 @@ INDIRECT_CALLABLE_SCOPE int fib4_rule_match(struct fib_rule *rule,
214 214 return 1;
215 215 }
216 216
217 + #define FIB_MAX_AUTO_TABLE_ID 4096
218 +
217 219 static struct fib_table *fib_empty_table(struct net *net)
218 220 {
219 221 u32 id = 1;
@@ -222,7 +224,7 @@ static struct fib_table *fib_empty_table(struct net *net)
222 224 if (!fib_get_table(net, id))
223 225 return fib_new_table(net, id);
224 226
225 - if (id++ == RT_TABLE_MAX)
227 + if (id++ == FIB_MAX_AUTO_TABLE_ID)
226 228 break;
227 229 }
228 230 return NULL;
modified net/ipv4/inet_fragment.c
@@ -235,6 +235,8 @@ void fqdir_pre_exit(struct fqdir *fqdir)
235 235 rhashtable_walk_start(&hti);
236 236
237 237 while ((fq = rhashtable_walk_next(&hti))) {
238 + int refs = 0;
239 +
238 240 if (IS_ERR(fq)) {
239 241 if (PTR_ERR(fq) != -EAGAIN)
240 242 break;
@@ -242,8 +244,12 @@ void fqdir_pre_exit(struct fqdir *fqdir)
242 244 }
243 245 spin_lock_bh(&fq->lock);
244 246 if (!(fq->flags & INET_FRAG_COMPLETE))
247 + inet_frag_kill(fq, &refs);
248 +
249 + if (fq->flags & INET_FRAG_HASH_DEAD)
245 250 inet_frag_queue_flush(fq, 0);
246 251 spin_unlock_bh(&fq->lock);
252 + inet_frag_putn(fq, refs);
247 253 }
248 254
249 255 rhashtable_walk_stop(&hti);
modified net/ipv4/ip_output.c
@@ -1303,6 +1303,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
1303 1303
1304 1304 cork->fragsize = ip_sk_use_pmtu(sk) ?
1305 1305 dst4_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
1306 + cork->fragsize = min(cork->fragsize, IP_MAX_MTU);
1306 1307
1307 1308 if (!inetdev_valid_mtu(cork->fragsize))
1308 1309 return -ENETUNREACH;
modified net/ipv4/ip_tunnel_core.c
@@ -268,6 +268,9 @@ static int iptunnel_pmtud_build_icmp(struct sk_buff *skb, int mtu)
268 268 eth_header(skb, skb->dev, ntohs(eh.h_proto), eh.h_source, eh.h_dest, 0);
269 269 skb_reset_mac_header(skb);
270 270
271 + if (skb_valid_dst(skb))
272 + skb_dst_drop(skb);
273 +
271 274 return skb->len;
272 275 }
273 276
@@ -371,6 +374,9 @@ static int iptunnel_pmtud_build_icmpv6(struct sk_buff *skb, int mtu)
371 374 eth_header(skb, skb->dev, ntohs(eh.h_proto), eh.h_source, eh.h_dest, 0);
372 375 skb_reset_mac_header(skb);
373 376
377 + if (skb_valid_dst(skb))
378 + skb_dst_drop(skb);
379 +
374 380 return skb->len;
375 381 }
376 382
modified net/ipv4/ipmr.c
@@ -3376,7 +3376,8 @@ int __init ip_mr_init(void)
3376 3376 {
3377 3377 int err;
3378 3378
3379 - mrt_cachep = KMEM_CACHE(mfc_cache, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
3379 + mrt_cachep = KMEM_CACHE(mfc_cache,
3380 + SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);
3380 3381
3381 3382 err = register_pernet_subsys(&ipmr_net_ops);
3382 3383 if (err)
modified net/ipv4/ipmr_base.c
@@ -52,7 +52,7 @@ mr_table_alloc(struct net *net, u32 id,
52 52 struct mr_table *mrt;
53 53 int err;
54 54
55 - mrt = kzalloc_obj(*mrt);
55 + mrt = kzalloc_obj(*mrt, GFP_KERNEL_ACCOUNT);
56 56 if (!mrt)
57 57 return ERR_PTR(-ENOMEM);
58 58 mrt->id = id;
modified net/ipv4/netfilter/arp_tables.c
@@ -23,7 +23,6 @@
23 23 #include <linux/init.h>
24 24 #include <linux/mutex.h>
25 25 #include <linux/err.h>
26 - #include <net/compat.h>
27 26 #include <net/sock.h>
28 27 #include <linux/uaccess.h>
29 28
@@ -724,80 +723,6 @@ static int copy_entries_to_user(unsigned int total_size,
724 723 return ret;
725 724 }
726 725
727 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
728 - static void compat_standard_from_user(void *dst, const void *src)
729 - {
730 - int v = *(compat_int_t *)src;
731 -
732 - if (v > 0)
733 - v += xt_compat_calc_jump(NFPROTO_ARP, v);
734 - memcpy(dst, &v, sizeof(v));
735 - }
736 -
737 - static int compat_standard_to_user(void __user *dst, const void *src)
738 - {
739 - compat_int_t cv = *(int *)src;
740 -
741 - if (cv > 0)
742 - cv -= xt_compat_calc_jump(NFPROTO_ARP, cv);
743 - return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
744 - }
745 -
746 - static int compat_calc_entry(const struct arpt_entry *e,
747 - const struct xt_table_info *info,
748 - const void *base, struct xt_table_info *newinfo)
749 - {
750 - const struct xt_entry_target *t;
751 - unsigned int entry_offset;
752 - int off, i, ret;
753 -
754 - off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
755 - entry_offset = (void *)e - base;
756 -
757 - t = arpt_get_target_c(e);
758 - off += xt_compat_target_offset(t->u.kernel.target);
759 - newinfo->size -= off;
760 - ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
761 - if (ret)
762 - return ret;
763 -
764 - for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
765 - if (info->hook_entry[i] &&
766 - (e < (struct arpt_entry *)(base + info->hook_entry[i])))
767 - newinfo->hook_entry[i] -= off;
768 - if (info->underflow[i] &&
769 - (e < (struct arpt_entry *)(base + info->underflow[i])))
770 - newinfo->underflow[i] -= off;
771 - }
772 - return 0;
773 - }
774 -
775 - static int compat_table_info(const struct xt_table_info *info,
776 - struct xt_table_info *newinfo)
777 - {
778 - struct arpt_entry *iter;
779 - const void *loc_cpu_entry;
780 - int ret;
781 -
782 - if (!newinfo || !info)
783 - return -EINVAL;
784 -
785 - /* we dont care about newinfo->entries */
786 - memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
787 - newinfo->initial_entries = 0;
788 - loc_cpu_entry = info->entries;
789 - ret = xt_compat_init_offsets(NFPROTO_ARP, info->number);
790 - if (ret)
791 - return ret;
792 - xt_entry_foreach(iter, loc_cpu_entry, info->size) {
793 - ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
794 - if (ret != 0)
795 - return ret;
796 - }
797 - return 0;
798 - }
799 - #endif
800 -
801 726 static int get_info(struct net *net, void __user *user, const int *len)
802 727 {
803 728 char name[XT_TABLE_MAXNAMELEN];
@@ -811,23 +736,11 @@ static int get_info(struct net *net, void __user *user, const int *len)
811 736 return -EFAULT;
812 737
813 738 name[XT_TABLE_MAXNAMELEN-1] = '\0';
814 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
815 - if (in_compat_syscall())
816 - xt_compat_lock(NFPROTO_ARP);
817 - #endif
818 739 t = xt_request_find_table_lock(net, NFPROTO_ARP, name);
819 740 if (!IS_ERR(t)) {
820 741 struct arpt_getinfo info;
821 742 const struct xt_table_info *private = t->private;
822 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
823 - struct xt_table_info tmp;
824 743
825 - if (in_compat_syscall()) {
826 - ret = compat_table_info(private, &tmp);
827 - xt_compat_flush_offsets(NFPROTO_ARP);
828 - private = &tmp;
829 - }
830 - #endif
831 744 memset(&info, 0, sizeof(info));
832 745 info.valid_hooks = t->valid_hooks;
833 746 memcpy(info.hook_entry, private->hook_entry,
@@ -846,10 +759,7 @@ static int get_info(struct net *net, void __user *user, const int *len)
846 759 module_put(t->me);
847 760 } else
848 761 ret = PTR_ERR(t);
849 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
850 - if (in_compat_syscall())
851 - xt_compat_unlock(NFPROTO_ARP);
852 - #endif
762 +
853 763 return ret;
854 764 }
855 765
@@ -1059,367 +969,6 @@ static int do_add_counters(struct net *net, sockptr_t arg, unsigned int len)
1059 969 return ret;
1060 970 }
1061 971
1062 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
1063 - struct compat_arpt_replace {
1064 - char name[XT_TABLE_MAXNAMELEN];
1065 - u32 valid_hooks;
1066 - u32 num_entries;
1067 - u32 size;
1068 - u32 hook_entry[NF_ARP_NUMHOOKS];
1069 - u32 underflow[NF_ARP_NUMHOOKS];
1070 - u32 num_counters;
1071 - compat_uptr_t counters;
1072 - struct compat_arpt_entry entries[];
1073 - };
1074 -
1075 - static inline void compat_release_entry(struct compat_arpt_entry *e)
1076 - {
1077 - struct xt_entry_target *t;
1078 -
1079 - t = compat_arpt_get_target(e);
1080 - module_put(t->u.kernel.target->me);
1081 - }
1082 -
1083 - static int
1084 - check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
1085 - struct xt_table_info *newinfo,
1086 - unsigned int *size,
1087 - const unsigned char *base,
1088 - const unsigned char *limit)
1089 - {
1090 - struct xt_entry_target *t;
1091 - struct xt_target *target;
1092 - unsigned int entry_offset;
1093 - int ret, off;
1094 -
1095 - if ((unsigned long)e % __alignof__(struct compat_arpt_entry) != 0 ||
1096 - (unsigned char *)e + sizeof(struct compat_arpt_entry) >= limit ||
1097 - (unsigned char *)e + e->next_offset > limit)
1098 - return -EINVAL;
1099 -
1100 - if (e->next_offset < sizeof(struct compat_arpt_entry) +
1101 - sizeof(struct compat_xt_entry_target))
1102 - return -EINVAL;
1103 -
1104 - if (!arp_checkentry(&e->arp))
1105 - return -EINVAL;
1106 -
1107 - ret = xt_compat_check_entry_offsets(e, e->elems, e->target_offset,
1108 - e->next_offset);
1109 - if (ret)
1110 - return ret;
1111 -
1112 - off = sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1113 - entry_offset = (void *)e - (void *)base;
1114 -
1115 - t = compat_arpt_get_target(e);
1116 - target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
1117 - t->u.user.revision);
1118 - if (IS_ERR(target)) {
1119 - ret = PTR_ERR(target);
1120 - goto out;
1121 - }
1122 - t->u.kernel.target = target;
1123 -
1124 - off += xt_compat_target_offset(target);
1125 - *size += off;
1126 - ret = xt_compat_add_offset(NFPROTO_ARP, entry_offset, off);
1127 - if (ret)
1128 - goto release_target;
1129 -
1130 - return 0;
1131 -
1132 - release_target:
1133 - module_put(t->u.kernel.target->me);
1134 - out:
1135 - return ret;
1136 - }
1137 -
1138 - static void
1139 - compat_copy_entry_from_user(struct compat_arpt_entry *e, void **dstptr,
1140 - unsigned int *size,
1141 - struct xt_table_info *newinfo, unsigned char *base)
1142 - {
1143 - struct xt_entry_target *t;
1144 - struct arpt_entry *de;
1145 - unsigned int origsize;
1146 - int h;
1147 -
1148 - origsize = *size;
1149 - de = *dstptr;
1150 - memcpy(de, e, sizeof(struct arpt_entry));
1151 - memcpy(&de->counters, &e->counters, sizeof(e->counters));
1152 -
1153 - *dstptr += sizeof(struct arpt_entry);
1154 - *size += sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1155 -
1156 - de->target_offset = e->target_offset - (origsize - *size);
1157 - t = compat_arpt_get_target(e);
1158 - xt_compat_target_from_user(t, dstptr, size);
1159 -
1160 - de->next_offset = e->next_offset - (origsize - *size);
1161 - for (h = 0; h < NF_ARP_NUMHOOKS; h++) {
1162 - if ((unsigned char *)de - base < newinfo->hook_entry[h])
1163 - newinfo->hook_entry[h] -= origsize - *size;
1164 - if ((unsigned char *)de - base < newinfo->underflow[h])
1165 - newinfo->underflow[h] -= origsize - *size;
1166 - }
1167 - }
1168 -
1169 - static int translate_compat_table(struct net *net,
1170 - struct xt_table_info **pinfo,
1171 - void **pentry0,
1172 - const struct compat_arpt_replace *compatr)
1173 - {
1174 - unsigned int i, j;
1175 - struct xt_table_info *newinfo, *info;
1176 - void *pos, *entry0, *entry1;
1177 - struct compat_arpt_entry *iter0;
1178 - struct arpt_replace repl;
1179 - unsigned int size;
1180 - int ret;
1181 -
1182 - info = *pinfo;
1183 - entry0 = *pentry0;
1184 - size = compatr->size;
1185 - info->number = compatr->num_entries;
1186 -
1187 - j = 0;
1188 - xt_compat_lock(NFPROTO_ARP);
1189 - ret = xt_compat_init_offsets(NFPROTO_ARP, compatr->num_entries);
1190 - if (ret)
1191 - goto out_unlock;
1192 - /* Walk through entries, checking offsets. */
1193 - xt_entry_foreach(iter0, entry0, compatr->size) {
1194 - ret = check_compat_entry_size_and_hooks(iter0, info, &size,
1195 - entry0,
1196 - entry0 + compatr->size);
1197 - if (ret != 0)
1198 - goto out_unlock;
1199 - ++j;
1200 - }
1201 -
1202 - ret = -EINVAL;
1203 - if (j != compatr->num_entries)
1204 - goto out_unlock;
1205 -
1206 - ret = -ENOMEM;
1207 - newinfo = xt_alloc_table_info(size);
1208 - if (!newinfo)
1209 - goto out_unlock;
1210 -
1211 - memset(newinfo->entries, 0, size);
1212 -
1213 - newinfo->number = compatr->num_entries;
1214 - for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1215 - newinfo->hook_entry[i] = compatr->hook_entry[i];
1216 - newinfo->underflow[i] = compatr->underflow[i];
1217 - }
1218 - entry1 = newinfo->entries;
1219 - pos = entry1;
1220 - size = compatr->size;
1221 - xt_entry_foreach(iter0, entry0, compatr->size)
1222 - compat_copy_entry_from_user(iter0, &pos, &size,
1223 - newinfo, entry1);
1224 -
1225 - /* all module references in entry0 are now gone */
1226 -
1227 - xt_compat_flush_offsets(NFPROTO_ARP);
1228 - xt_compat_unlock(NFPROTO_ARP);
1229 -
1230 - memcpy(&repl, compatr, sizeof(*compatr));
1231 -
1232 - for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
1233 - repl.hook_entry[i] = newinfo->hook_entry[i];
1234 - repl.underflow[i] = newinfo->underflow[i];
1235 - }
1236 -
1237 - repl.num_counters = 0;
1238 - repl.counters = NULL;
1239 - repl.size = newinfo->size;
1240 - ret = translate_table(net, newinfo, entry1, &repl);
1241 - if (ret)
1242 - goto free_newinfo;
1243 -
1244 - *pinfo = newinfo;
1245 - *pentry0 = entry1;
1246 - xt_free_table_info(info);
1247 - return 0;
1248 -
1249 - free_newinfo:
1250 - xt_free_table_info(newinfo);
1251 - return ret;
1252 - out_unlock:
1253 - xt_compat_flush_offsets(NFPROTO_ARP);
1254 - xt_compat_unlock(NFPROTO_ARP);
1255 - xt_entry_foreach(iter0, entry0, compatr->size) {
1256 - if (j-- == 0)
1257 - break;
1258 - compat_release_entry(iter0);
1259 - }
1260 - return ret;
1261 - }
1262 -
1263 - static int compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
1264 - {
1265 - int ret;
1266 - struct compat_arpt_replace tmp;
1267 - struct xt_table_info *newinfo;
1268 - void *loc_cpu_entry;
1269 - struct arpt_entry *iter;
1270 -
1271 - if (len < sizeof(tmp))
1272 - return -EINVAL;
1273 - if (copy_from_sockptr(&tmp, arg, sizeof(tmp)) != 0)
1274 - return -EFAULT;
1275 -
1276 - /* overflow check */
1277 - if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters))
1278 - return -ENOMEM;
1279 - if (tmp.num_counters == 0)
1280 - return -EINVAL;
1281 - if ((u64)len < (u64)tmp.size + sizeof(tmp))
1282 - return -EINVAL;
1283 -
1284 - tmp.name[sizeof(tmp.name)-1] = 0;
1285 -
1286 - newinfo = xt_alloc_table_info(tmp.size);
1287 - if (!newinfo)
1288 - return -ENOMEM;
1289 -
1290 - loc_cpu_entry = newinfo->entries;
1291 - if (copy_from_sockptr_offset(loc_cpu_entry, arg, sizeof(tmp),
1292 - tmp.size) != 0) {
1293 - ret = -EFAULT;
1294 - goto free_newinfo;
1295 - }
1296 -
1297 - ret = translate_compat_table(net, &newinfo, &loc_cpu_entry, &tmp);
1298 - if (ret != 0)
1299 - goto free_newinfo;
1300 -
1301 - ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
1302 - tmp.num_counters, compat_ptr(tmp.counters));
1303 - if (ret)
1304 - goto free_newinfo_untrans;
1305 - return 0;
1306 -
1307 - free_newinfo_untrans:
1308 - xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
1309 - cleanup_entry(iter, net);
1310 - free_newinfo:
1311 - xt_free_table_info(newinfo);
1312 - return ret;
1313 - }
1314 -
1315 - static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr,
1316 - compat_uint_t *size,
1317 - struct xt_counters *counters,
1318 - unsigned int i)
1319 - {
1320 - struct xt_entry_target *t;
1321 - struct compat_arpt_entry __user *ce;
1322 - u_int16_t target_offset, next_offset;
1323 - compat_uint_t origsize;
1324 - int ret;
1325 -
1326 - origsize = *size;
1327 - ce = *dstptr;
1328 - if (copy_to_user(ce, e, offsetof(struct compat_arpt_entry, counters)) ||
1329 - copy_to_user(&ce->counters, &counters[i], sizeof(counters[i])))
1330 - return -EFAULT;
1331 -
1332 - *dstptr += sizeof(struct compat_arpt_entry);
1333 - *size -= sizeof(struct arpt_entry) - sizeof(struct compat_arpt_entry);
1334 -
1335 - target_offset = e->target_offset - (origsize - *size);
1336 -
1337 - t = arpt_get_target(e);
1338 - ret = xt_compat_target_to_user(t, dstptr, size);
1339 - if (ret)
1340 - return ret;
1341 - next_offset = e->next_offset - (origsize - *size);
1342 - if (put_user(target_offset, &ce->target_offset) != 0 ||
1343 - put_user(next_offset, &ce->next_offset) != 0)
1344 - return -EFAULT;
1345 - return 0;
1346 - }
1347 -
1348 - static int compat_copy_entries_to_user(unsigned int total_size,
1349 - struct xt_table *table,
1350 - void __user *userptr)
1351 - {
1352 - struct xt_counters *counters;
1353 - const struct xt_table_info *private = table->private;
1354 - void __user *pos;
1355 - unsigned int size;
1356 - int ret = 0;
1357 - unsigned int i = 0;
1358 - struct arpt_entry *iter;
1359 -
1360 - counters = alloc_counters(table);
1361 - if (IS_ERR(counters))
1362 - return PTR_ERR(counters);
1363 -
1364 - pos = userptr;
1365 - size = total_size;
1366 - xt_entry_foreach(iter, private->entries, total_size) {
1367 - ret = compat_copy_entry_to_user(iter, &pos,
1368 - &size, counters, i++);
1369 - if (ret != 0)
1370 - break;
1371 - }
1372 - vfree(counters);
1373 - return ret;
1374 - }
1375 -
1376 - struct compat_arpt_get_entries {
1377 - char name[XT_TABLE_MAXNAMELEN];
1378 - compat_uint_t size;
1379 - struct compat_arpt_entry entrytable[];
1380 - };
1381 -
1382 - static int compat_get_entries(struct net *net,
1383 - struct compat_arpt_get_entries __user *uptr,
1384 - int *len)
1385 - {
1386 - int ret;
1387 - struct compat_arpt_get_entries get;
1388 - struct xt_table *t;
1389 -
1390 - if (*len < sizeof(get))
1391 - return -EINVAL;
1392 - if (copy_from_user(&get, uptr, sizeof(get)) != 0)
1393 - return -EFAULT;
1394 - if (*len != sizeof(struct compat_arpt_get_entries) + get.size)
1395 - return -EINVAL;
1396 -
1397 - get.name[sizeof(get.name) - 1] = '\0';
1398 -
1399 - xt_compat_lock(NFPROTO_ARP);
1400 - t = xt_find_table_lock(net, NFPROTO_ARP, get.name);
1401 - if (!IS_ERR(t)) {
1402 - const struct xt_table_info *private = t->private;
1403 - struct xt_table_info info;
1404 -
1405 - ret = compat_table_info(private, &info);
1406 - if (!ret && get.size == info.size) {
1407 - ret = compat_copy_entries_to_user(private->size,
1408 - t, uptr->entrytable);
1409 - } else if (!ret)
1410 - ret = -EAGAIN;
1411 -
1412 - xt_compat_flush_offsets(NFPROTO_ARP);
1413 - module_put(t->me);
1414 - xt_table_unlock(t);
1415 - } else
1416 - ret = PTR_ERR(t);
1417 -
1418 - xt_compat_unlock(NFPROTO_ARP);
1419 - return ret;
1420 - }
1421 - #endif
1422 -
1423 972 static int do_arpt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
1424 973 unsigned int len)
1425 974 {
@@ -1432,12 +981,7 @@ static int do_arpt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
1432 981
1433 982 switch (cmd) {
1434 983 case ARPT_SO_SET_REPLACE:
1435 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
1436 - if (in_compat_syscall())
1437 - ret = compat_do_replace(sock_net(sk), arg, len);
1438 - else
1439 - #endif
1440 - ret = do_replace(sock_net(sk), arg, len);
984 + ret = do_replace(sock_net(sk), arg, len);
1441 985 break;
1442 986
1443 987 case ARPT_SO_SET_ADD_COUNTERS:
@@ -1466,12 +1010,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
1466 1010 break;
1467 1011
1468 1012 case ARPT_SO_GET_ENTRIES:
1469 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
1470 - if (in_compat_syscall())
1471 - ret = compat_get_entries(sock_net(sk), user, len);
1472 - else
1473 - #endif
1474 - ret = get_entries(sock_net(sk), user, len);
1013 + ret = get_entries(sock_net(sk), user, len);
1475 1014 break;
1476 1015
1477 1016 case ARPT_SO_GET_REVISION_TARGET: {
@@ -1568,11 +1107,6 @@ static struct xt_target arpt_builtin_tg[] __read_mostly = {
1568 1107 .name = XT_STANDARD_TARGET,
1569 1108 .targetsize = sizeof(int),
1570 1109 .family = NFPROTO_ARP,
1571 - #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
1572 - .compatsize = sizeof(compat_int_t),
1573 - .compat_from_user = compat_standard_from_user,
1574 - .compat_to_user = compat_standard_to_user,
1575 - #endif
1576 1110 },
1577 1111 {
1578 1112 .name = XT_ERROR_TARGET,
modified net/ipv4/nexthop.c
@@ -2036,7 +2036,7 @@ remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge,
2036 2036 {
2037 2037 struct nh_grp_entry *nhges, *new_nhges;
2038 2038 struct nexthop *nhp = nhge->nh_parent;
2039 - struct netlink_ext_ack extack;
2039 + struct netlink_ext_ack extack = {};
2040 2040 struct nexthop *nh = nhge->nh;
2041 2041 struct nh_group *nhg, *newg;
2042 2042 int i, j, err;
modified net/ipv4/tcp.c
@@ -1169,8 +1169,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
1169 1169 zc = MSG_SPLICE_PAGES;
1170 1170 }
1171 1171
1172 - if (!sockc_err && sockc.dmabuf_id &&
1173 - (!(flags & MSG_ZEROCOPY) || !sock_flag(sk, SOCK_ZEROCOPY))) {
1172 + if (!sockc_err && sockc.dmabuf_id && (zc != MSG_ZEROCOPY || !binding)) {
1174 1173 err = -EINVAL;
1175 1174 goto out_err;
1176 1175 }
modified net/ipv6/ip6_fib.c
@@ -85,7 +85,7 @@ static void fib6_walker_link(struct net *net, struct fib6_walker *w)
85 85 static void fib6_walker_unlink(struct net *net, struct fib6_walker *w)
86 86 {
87 87 write_lock_bh(&net->ipv6.fib6_walker_lock);
88 - list_del(&w->lh);
88 + list_del_init(&w->lh);
89 89 write_unlock_bh(&net->ipv6.fib6_walker_lock);
90 90 }
91 91
@@ -2760,7 +2760,7 @@ static void *ipv6_route_seq_start(struct seq_file *seq, loff_t *pos)
2760 2760 static bool ipv6_route_iter_active(struct ipv6_route_iter *iter)
2761 2761 {
2762 2762 struct fib6_walker *w = &iter->w;
2763 - return w->node && !(w->state == FWS_U && w->node == w->root);
2763 + return w->node && !list_empty(&w->lh);
2764 2764 }
2765 2765
2766 2766 static void ipv6_route_native_seq_stop(struct seq_file *seq, void *v)
modified net/ipv6/ip6_flowlabel.c
@@ -461,6 +461,21 @@ done:
461 461 return NULL;
462 462 }
463 463
464 + static bool fl_sock_at_lease_limit(const struct sock *sk)
465 + {
466 + const struct ipv6_fl_socklist *sfl;
467 + int count = 0;
468 +
469 + rcu_read_lock();
470 + for_each_sk_fl_rcu(sk, sfl) {
471 + if (++count >= FL_MAX_PER_SOCK)
472 + break;
473 + }
474 + rcu_read_unlock();
475 +
476 + return count >= FL_MAX_PER_SOCK;
477 + }
478 +
464 479 static int mem_check(struct sock *sk)
465 480 {
466 481 const int unpriv_total_limit = FL_MAX_SIZE - (FL_MAX_SIZE / 4);
@@ -679,6 +694,10 @@ recheck:
679 694 err = -ENOMEM;
680 695 if (!sfl1)
681 696 goto release;
697 + err = -ENOBUFS;
698 + if (fl_sock_at_lease_limit(sk) &&
699 + !capable(CAP_NET_ADMIN))
700 + goto release;
682 701 if (fl->linger > fl1->linger)
683 702 fl1->linger = fl->linger;
684 703 if ((long)(fl->expires - fl1->expires) > 0)
modified net/ipv6/ip6_output.c
@@ -1432,6 +1432,8 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
1432 1432 if (frag_size && frag_size < mtu)
1433 1433 mtu = frag_size;
1434 1434
1435 + if (sk_is_udp(sk))
1436 + mtu = min(mtu, IP6_MAX_MTU);
1435 1437 cork->base.fragsize = mtu;
1436 1438 cork->base.gso_size = ipc6->gso_size;
1437 1439 cork->base.tx_flags = 0;
modified net/ipv6/ip6mr.c
@@ -1427,7 +1427,7 @@ int __init ip6_mr_init(void)
1427 1427 {
1428 1428 int err;
1429 1429
1430 - mrt_cachep = KMEM_CACHE(mfc6_cache, SLAB_HWCACHE_ALIGN);
1430 + mrt_cachep = KMEM_CACHE(mfc6_cache, SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT);
1431 1431 if (!mrt_cachep)
1432 1432 return -ENOMEM;
1433 1433
modified net/ipv6/netfilter/ip6_tables.c
@@ -647,6 +647,11 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
647 647 /* Clear counters and comefrom */
648 648 e->counters = ((struct xt_counters) { 0, 0 });
649 649 e->comefrom = 0;
650 +
651 + /* set F_PROTO, else ip6_packet_match won't do the right thing. */
652 + if (e->ipv6.proto)
653 + e->ipv6.flags |= IP6T_F_PROTO;
654 +
650 655 return 0;
651 656 }
652 657
modified net/ipv6/route.c
@@ -4019,6 +4019,7 @@ static int __ip6_del_rt_siblings(struct fib6_info *rt, struct fib6_config *cfg)
4019 4019 struct net *net = info->nl_net;
4020 4020 struct sk_buff *skb = NULL;
4021 4021 struct fib6_table *table;
4022 + struct fib6_node *fn;
4022 4023 int err = -ENOENT;
4023 4024
4024 4025 if (rt == net->ipv6.fib6_null_entry)
@@ -4026,9 +4027,13 @@ static int __ip6_del_rt_siblings(struct fib6_info *rt, struct fib6_config *cfg)
4026 4027 table = rt->fib6_table;
4027 4028 spin_lock_bh(&table->tb6_lock);
4028 4029
4030 + fn = rcu_dereference_protected(rt->fib6_node,
4031 + lockdep_is_held(&table->tb6_lock));
4032 + if (!fn)
4033 + goto out_unlock;
4034 +
4029 4035 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) {
4030 4036 struct fib6_info *sibling, *next_sibling;
4031 - struct fib6_node *fn;
4032 4037
4033 4038 /* prefer to send a single notification with all hops */
4034 4039 skb = nlmsg_new(rt6_nlmsg_size(rt), GFP_ATOMIC);
@@ -4051,8 +4056,6 @@ static int __ip6_del_rt_siblings(struct fib6_info *rt, struct fib6_config *cfg)
4051 4056 * and emit a replace or delete notification, respectively.
4052 4057 */
4053 4058 info->skip_notify_kernel = 1;
4054 - fn = rcu_dereference_protected(rt->fib6_node,
4055 - lockdep_is_held(&table->tb6_lock));
4056 4059 if (rcu_access_pointer(fn->leaf) == rt) {
4057 4060 struct fib6_info *last_sibling, *replace_rt;
4058 4061
modified net/mac802154/ieee802154_i.h
@@ -74,6 +74,10 @@ struct ieee802154_local {
74 74 struct work_struct rx_beacon_work;
75 75 struct list_head rx_mac_cmd_list;
76 76 struct work_struct rx_mac_cmd_work;
77 + /* Serializes rx_beacon_list and rx_mac_cmd_list against the RX
78 + * softirq producer, the mac_wq workers and the teardown flush.
79 + */
80 + spinlock_t rx_lock;
77 81
78 82 /* Association */
79 83 /* assoc_lock protects assoc_dev_extended_addr, assoc_addr,
@@ -305,6 +309,10 @@ static inline bool mac802154_is_beaconing(struct ieee802154_local *local)
305 309 }
306 310
307 311 void mac802154_rx_mac_cmd_worker(struct work_struct *work);
312 + void mac802154_flush_list(struct list_head *list,
313 + struct ieee802154_sub_if_data *sdata);
314 + void mac802154_flush_queued_pkts(struct ieee802154_local *local,
315 + struct ieee802154_sub_if_data *sdata);
308 316
309 317 int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,
310 318 struct ieee802154_pan_device *coord,
modified net/mac802154/iface.c
@@ -694,6 +694,7 @@ void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata)
694 694 mutex_unlock(&sdata->local->iflist_mtx);
695 695
696 696 synchronize_rcu();
697 + mac802154_flush_queued_pkts(sdata->local, sdata);
697 698 unregister_netdevice(sdata->dev);
698 699 }
699 700
@@ -705,6 +706,11 @@ void ieee802154_remove_interfaces(struct ieee802154_local *local)
705 706 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
706 707 list_del_rcu(&sdata->list);
707 708
709 + /* Best-effort: a frame the RX softirq queues for this sdata
710 + * after the flush still pins the netdev, so the
711 + * unregister_netdevice() below waits it out.
712 + */
713 + mac802154_flush_queued_pkts(local, sdata);
708 714 unregister_netdevice(sdata->dev);
709 715 }
710 716 mutex_unlock(&local->iflist_mtx);
modified net/mac802154/main.c
@@ -91,6 +91,7 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
91 91 INIT_LIST_HEAD(&local->interfaces);
92 92 INIT_LIST_HEAD(&local->rx_beacon_list);
93 93 INIT_LIST_HEAD(&local->rx_mac_cmd_list);
94 + spin_lock_init(&local->rx_lock);
94 95 mutex_init(&local->iflist_mtx);
95 96
96 97 tasklet_setup(&local->tasklet, ieee802154_tasklet_handler);
modified net/mac802154/rx.c
@@ -35,16 +35,23 @@ void mac802154_rx_beacon_worker(struct work_struct *work)
35 35 container_of(work, struct ieee802154_local, rx_beacon_work);
36 36 struct cfg802154_mac_pkt *mac_pkt;
37 37
38 - mac_pkt = list_first_entry_or_null(&local->rx_beacon_list,
39 - struct cfg802154_mac_pkt, node);
40 - if (!mac_pkt)
41 - return;
38 + for (;;) {
39 + spin_lock_bh(&local->rx_lock);
40 + mac_pkt = list_first_entry_or_null(&local->rx_beacon_list,
41 + struct cfg802154_mac_pkt, node);
42 + if (mac_pkt)
43 + list_del(&mac_pkt->node);
44 + spin_unlock_bh(&local->rx_lock);
45 + if (!mac_pkt)
46 + break;
42 47
43 - mac802154_process_beacon(local, mac_pkt->skb, mac_pkt->page, mac_pkt->channel);
48 + mac802154_process_beacon(local, mac_pkt->skb,
49 + mac_pkt->page, mac_pkt->channel);
44 50
45 - list_del(&mac_pkt->node);
46 - kfree_skb(mac_pkt->skb);
47 - kfree(mac_pkt);
51 + netdev_put(mac_pkt->sdata->dev, &mac_pkt->dev_tracker);
52 + kfree_skb(mac_pkt->skb);
53 + kfree(mac_pkt);
54 + }
48 55 }
49 56
50 57 static bool mac802154_should_answer_beacon_req(struct ieee802154_local *local)
@@ -68,22 +75,15 @@ static bool mac802154_should_answer_beacon_req(struct ieee802154_local *local)
68 75 return interval == IEEE802154_ACTIVE_SCAN_DURATION;
69 76 }
70 77
71 - void mac802154_rx_mac_cmd_worker(struct work_struct *work)
78 + static void mac802154_rx_mac_cmd(struct ieee802154_local *local,
79 + struct cfg802154_mac_pkt *mac_pkt)
72 80 {
73 - struct ieee802154_local *local =
74 - container_of(work, struct ieee802154_local, rx_mac_cmd_work);
75 - struct cfg802154_mac_pkt *mac_pkt;
76 81 u8 mac_cmd;
77 82 int rc;
78 83
79 - mac_pkt = list_first_entry_or_null(&local->rx_mac_cmd_list,
80 - struct cfg802154_mac_pkt, node);
81 - if (!mac_pkt)
82 - return;
83 -
84 84 rc = ieee802154_get_mac_cmd(mac_pkt->skb, &mac_cmd);
85 85 if (rc)
86 - goto out;
86 + return;
87 87
88 88 switch (mac_cmd) {
89 89 case IEEE802154_CMD_BEACON_REQ:
@@ -121,11 +121,81 @@ void mac802154_rx_mac_cmd_worker(struct work_struct *work)
121 121 default:
122 122 break;
123 123 }
124 + }
124 125
125 - out:
126 - list_del(&mac_pkt->node);
127 - kfree_skb(mac_pkt->skb);
128 - kfree(mac_pkt);
126 + void mac802154_rx_mac_cmd_worker(struct work_struct *work)
127 + {
128 + struct ieee802154_local *local =
129 + container_of(work, struct ieee802154_local, rx_mac_cmd_work);
130 + struct cfg802154_mac_pkt *mac_pkt;
131 +
132 + for (;;) {
133 + spin_lock_bh(&local->rx_lock);
134 + mac_pkt = list_first_entry_or_null(&local->rx_mac_cmd_list,
135 + struct cfg802154_mac_pkt, node);
136 + if (mac_pkt)
137 + list_del(&mac_pkt->node);
138 + spin_unlock_bh(&local->rx_lock);
139 + if (!mac_pkt)
140 + break;
141 +
142 + /* A stopped interface cannot transmit; skipping avoids a
143 + * needless association response (and the !netif_running()
144 + * warning it would trip) during teardown. The beacon worker
145 + * needs no such check as it never transmits.
146 + */
147 + if (ieee802154_sdata_running(mac_pkt->sdata))
148 + mac802154_rx_mac_cmd(local, mac_pkt);
149 +
150 + netdev_put(mac_pkt->sdata->dev, &mac_pkt->dev_tracker);
151 + kfree_skb(mac_pkt->skb);
152 + kfree(mac_pkt);
153 + }
154 + }
155 +
156 + /**
157 + * mac802154_flush_list - free queued RX frames on @list
158 + * @list: rx_beacon_list or rx_mac_cmd_list
159 + * @sdata: only free frames received on this interface, or %NULL for all
160 + *
161 + * Each frame pins the net_device it was received on (via netdev_hold()),
162 + * so release that reference as the frame is dropped. Caller must hold
163 + * local->rx_lock.
164 + */
165 + void mac802154_flush_list(struct list_head *list,
166 + struct ieee802154_sub_if_data *sdata)
167 + {
168 + struct cfg802154_mac_pkt *mac_pkt, *tmp;
169 +
170 + list_for_each_entry_safe(mac_pkt, tmp, list, node) {
171 + if (sdata && mac_pkt->sdata != sdata)
172 + continue;
173 + list_del(&mac_pkt->node);
174 + netdev_put(mac_pkt->sdata->dev, &mac_pkt->dev_tracker);
175 + kfree_skb(mac_pkt->skb);
176 + kfree(mac_pkt);
177 + }
178 + }
179 +
180 + /**
181 + * mac802154_flush_queued_pkts - drop queued RX work referencing @sdata
182 + * @local: the mac802154 device
183 + * @sdata: interface being removed
184 + *
185 + * The workers dereference the queued frame's interface directly
186 + * (mac_pkt->sdata) or through skb->dev in mac802154_process_beacon(). Drop
187 + * the not-yet-started entries belonging to @sdata before it is unregistered
188 + * so their netdev reference is released; an entry already dequeued by a
189 + * running worker keeps its own reference until the worker completes, which
190 + * unregister_netdevice() then waits out.
191 + */
192 + void mac802154_flush_queued_pkts(struct ieee802154_local *local,
193 + struct ieee802154_sub_if_data *sdata)
194 + {
195 + spin_lock_bh(&local->rx_lock);
196 + mac802154_flush_list(&local->rx_beacon_list, sdata);
197 + mac802154_flush_list(&local->rx_mac_cmd_list, sdata);
198 + spin_unlock_bh(&local->rx_lock);
129 199 }
130 200
131 201 static int
@@ -221,7 +291,10 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
221 291 mac_pkt->sdata = sdata;
222 292 mac_pkt->page = sdata->local->scan_page;
223 293 mac_pkt->channel = sdata->local->scan_channel;
294 + netdev_hold(sdata->dev, &mac_pkt->dev_tracker, GFP_ATOMIC);
295 + spin_lock(&sdata->local->rx_lock);
224 296 list_add_tail(&mac_pkt->node, &sdata->local->rx_beacon_list);
297 + spin_unlock(&sdata->local->rx_lock);
225 298 queue_work(sdata->local->mac_wq, &sdata->local->rx_beacon_work);
226 299 return NET_RX_SUCCESS;
227 300
@@ -233,7 +306,10 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
233 306
234 307 mac_pkt->skb = skb_get(skb);
235 308 mac_pkt->sdata = sdata;
309 + netdev_hold(sdata->dev, &mac_pkt->dev_tracker, GFP_ATOMIC);
310 + spin_lock(&sdata->local->rx_lock);
236 311 list_add_tail(&mac_pkt->node, &sdata->local->rx_mac_cmd_list);
312 + spin_unlock(&sdata->local->rx_lock);
237 313 queue_work(sdata->local->mac_wq, &sdata->local->rx_mac_cmd_work);
238 314 return NET_RX_SUCCESS;
239 315
modified net/mac802154/scan.c
@@ -104,13 +104,9 @@ static unsigned int mac802154_scan_get_channel_time(u8 duration_order,
104 104
105 105 static void mac802154_flush_queued_beacons(struct ieee802154_local *local)
106 106 {
107 - struct cfg802154_mac_pkt *mac_pkt, *tmp;
108 -
109 - list_for_each_entry_safe(mac_pkt, tmp, &local->rx_beacon_list, node) {
110 - list_del(&mac_pkt->node);
111 - kfree_skb(mac_pkt->skb);
112 - kfree(mac_pkt);
113 - }
107 + spin_lock_bh(&local->rx_lock);
108 + mac802154_flush_list(&local->rx_beacon_list, NULL);
109 + spin_unlock_bh(&local->rx_lock);
114 110 }
115 111
116 112 static void
modified net/mptcp/options.c
@@ -93,7 +93,8 @@ static void mptcp_parse_option(const struct sk_buff *skb,
93 93 * In other words, the only way for checksums not to be used
94 94 * is if both hosts in their SYNs set A=0."
95 95 */
96 - if (flags & MPTCP_CAP_CHECKSUM_REQD)
96 + if ((flags & MPTCP_CAP_CHECKSUM_REQD) &&
97 + opsize < TCPOLEN_MPTCP_MPC_ACK_DATA)
97 98 mp_opt->suboptions |= OPTION_MPTCP_CSUMREQD;
98 99
99 100 mp_opt->deny_join_id0 = !!(flags & MPTCP_CAP_DENY_JOIN_ID0);
@@ -529,7 +530,7 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb,
529 530 return false;
530 531
531 532 /* MPC/MPJ needed only on 3rd ack packet, DATA_FIN and TCP shutdown take precedence */
532 - if (READ_ONCE(subflow->fully_established) || snd_data_fin_enable ||
533 + if (subflow->fully_established || snd_data_fin_enable ||
533 534 subflow->snd_isn != TCP_SKB_CB(skb)->seq ||
534 535 sk->sk_state != TCP_ESTABLISHED)
535 536 return false;
@@ -611,6 +612,7 @@ static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
611 612 ext->data_seq = data_fin_tx_seq;
612 613 ext->subflow_seq = 0;
613 614 ext->data_len = 1;
615 + ext->csum = 0;
614 616 } else if (ext->data_seq + ext->data_len == data_fin_tx_seq) {
615 617 /* If there's an existing DSS mapping and it is the
616 618 * final mapping, DATA_FIN consumes 1 additional byte of
@@ -980,7 +982,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
980 982 /* here we can process OoO, in-window pkts, only in-sequence 4th ack
981 983 * will make the subflow fully established
982 984 */
983 - if (likely(READ_ONCE(subflow->fully_established))) {
985 + if (likely(subflow->fully_established)) {
984 986 /* on passive sockets, check for 3rd ack retransmission
985 987 * note that msk is always set by subflow_syn_recv_sock()
986 988 * for mp_join subflows
modified net/mptcp/pm.c
@@ -462,10 +462,10 @@ bool mptcp_pm_announced_alloc(struct mptcp_sock *msk,
462 462
463 463 add_entry->addr = *addr;
464 464 add_entry->sock = msk;
465 - add_entry->retrans_times = 0;
466 465
467 466 timer_setup(&add_entry->timer, mptcp_pm_add_addr_timer, 0);
468 467 reset_timer:
468 + add_entry->retrans_times = 0;
469 469 add_entry->timer_done = false;
470 470 timeout = mptcp_adjust_add_addr_timeout(msk);
471 471 if (timeout)
modified net/mptcp/pm_kernel.c
@@ -1137,6 +1137,8 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
1137 1137 while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
1138 1138 struct sock *sk = (struct sock *)msk;
1139 1139 struct mptcp_addr_info msk_local;
1140 + struct mptcp_addr_info anno_addr;
1141 + bool announced;
1140 1142
1141 1143 if (list_empty(&msk->conn_list) || mptcp_pm_is_userspace(msk))
1142 1144 goto next;
@@ -1146,7 +1148,13 @@ static int mptcp_nl_remove_id_zero_address(struct net *net,
1146 1148 goto next;
1147 1149
1148 1150 lock_sock(sk);
1151 + /* Drop a possibly pending ADD_ADDR for this address. */
1152 + anno_addr = msk_local;
1153 + anno_addr.port = 0;
1154 + announced = mptcp_pm_announced_remove(msk, &anno_addr);
1149 1155 spin_lock_bh(&msk->pm.lock);
1156 + if (announced)
1157 + msk->pm.add_addr_signaled--;
1150 1158 mptcp_pm_remove_addr(msk, &list);
1151 1159 mptcp_pm_rm_subflow(msk, &list);
1152 1160 __mark_subflow_endp_available(msk, 0);
modified net/mptcp/pm_userspace.c
@@ -69,6 +69,19 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
69 69 }
70 70
71 71 if (!addr_match && !id_match) {
72 + unsigned int id;
73 +
74 + if (!entry->addr.id && needs_id) {
75 + id = find_next_zero_bit(id_bitmap,
76 + MPTCP_PM_MAX_ADDR_ID + 1, 1);
77 + if (id > MPTCP_PM_MAX_ADDR_ID) {
78 + ret = -ENOSPC;
79 + goto append_err;
80 + }
81 + } else {
82 + id = entry->addr.id;
83 + }
84 +
72 85 /* Memory for the entry is allocated from the
73 86 * sock option buffer.
74 87 */
@@ -78,10 +91,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
78 91 goto append_err;
79 92 }
80 93
81 - if (!e->addr.id && needs_id)
82 - e->addr.id = find_next_zero_bit(id_bitmap,
83 - MPTCP_PM_MAX_ADDR_ID + 1,
84 - 1);
94 + e->addr.id = id;
85 95 list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
86 96 msk->pm.local_addr_used++;
87 97 ret = e->addr.id;
modified net/mptcp/protocol.c
@@ -95,6 +95,7 @@ bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
95 95
96 96 msk->allow_subflows = false;
97 97 set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
98 + clear_bit(MPTCP_RTX_ENABLED, &msk->flags);
98 99 __MPTCP_INC_STATS(net, fb_mib);
99 100 spin_unlock_bh(&msk->fallback_lock);
100 101 return true;
@@ -288,8 +289,8 @@ static void mptcp_prune_ofo_queue(struct sock *sk,
288 289 */
289 290 static bool mptcp_can_ingest(const struct sock *sk)
290 291 {
291 - return unlikely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
292 - __mptcp_check_fallback(mptcp_sk(sk));
292 + return likely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
293 + __mptcp_check_fallback(mptcp_sk(sk));
293 294 }
294 295
295 296 static bool mptcp_try_rmem_schedule(struct sock *sk, const struct sk_buff *skb)
@@ -312,12 +313,6 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
312 313 u64 seq, end_seq, max_seq;
313 314 struct sk_buff *skb1;
314 315
315 - if (!mptcp_try_rmem_schedule(sk, skb)) {
316 - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
317 - mptcp_drop(sk, skb);
318 - return;
319 - }
320 -
321 316 seq = MPTCP_SKB_CB(skb)->map_seq;
322 317 end_seq = MPTCP_SKB_CB(skb)->end_seq;
323 318 max_seq = atomic64_read(&msk->rcv_wnd_sent);
@@ -334,6 +329,12 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
334 329 return;
335 330 }
336 331
332 + if (!mptcp_try_rmem_schedule(sk, skb)) {
333 + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
334 + mptcp_drop(sk, skb);
335 + return;
336 + }
337 +
337 338 p = &msk->out_of_order_queue.rb_node;
338 339 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
339 340 if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
@@ -1084,13 +1085,14 @@ static bool mptcp_rtx_timer_pending(struct sock *sk)
1084 1085
1085 1086 static void mptcp_reset_rtx_timer(struct sock *sk)
1086 1087 {
1088 + struct mptcp_sock *msk = mptcp_sk(sk);
1087 1089 unsigned long tout;
1088 1090
1089 - /* prevent rescheduling on close */
1090 - if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
1091 + /* Prevent rescheduling on close and in case of fallback. */
1092 + if (!test_bit(MPTCP_RTX_ENABLED, &msk->flags))
1091 1093 return;
1092 1094
1093 - tout = mptcp_sk(sk)->timer_ival;
1095 + tout = msk->timer_ival;
1094 1096 sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
1095 1097 }
1096 1098
@@ -3323,6 +3325,9 @@ void mptcp_set_state(struct sock *sk, int state)
3323 3325 * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
3324 3326 */
3325 3327 break;
3328 + case TCP_CLOSE:
3329 + clear_bit(MPTCP_RTX_ENABLED, &mptcp_sk(sk)->flags);
3330 + fallthrough;
3326 3331 default:
3327 3332 if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
3328 3333 MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
@@ -3583,6 +3588,7 @@ static void mptcp_destroy_common(struct mptcp_sock *msk)
3583 3588
3584 3589 static int mptcp_disconnect(struct sock *sk, int flags)
3585 3590 {
3591 + struct inet_connection_sock *icsk = inet_csk(sk);
3586 3592 struct mptcp_sock *msk = mptcp_sk(sk);
3587 3593
3588 3594 /* We are on the fastopen error path. We can't call straight into the
@@ -3595,8 +3601,13 @@ static int mptcp_disconnect(struct sock *sk, int flags)
3595 3601 mptcp_check_listen_stop(sk);
3596 3602 mptcp_set_state(sk, TCP_CLOSE);
3597 3603
3598 - mptcp_stop_rtx_timer(sk);
3599 - mptcp_stop_tout_timer(sk);
3604 + /* The later subflow close can not kick again the tout timer,
3605 + * as the msk is already in closed status.
3606 + */
3607 + msk->timer_ival = icsk->icsk_rto_min;
3608 + sk_stop_timer_sync(sk, &sk->mptcp_retransmit_timer);
3609 + icsk->icsk_mtup.probe_timestamp = 0;
3610 + sk_stop_timer_sync(sk, &icsk->mptcp_tout_timer);
3600 3611
3601 3612 mptcp_pm_connection_closed(msk);
3602 3613
@@ -3875,7 +3886,7 @@ static void schedule_3rdack_retransmission(struct sock *ssk)
3875 3886 struct tcp_sock *tp = tcp_sk(ssk);
3876 3887 unsigned long timeout;
3877 3888
3878 - if (READ_ONCE(mptcp_subflow_ctx(ssk)->fully_established))
3889 + if (mptcp_subflow_ctx(ssk)->fully_established)
3879 3890 return;
3880 3891
3881 3892 /* reschedule with a timeout above RTT, as we must look only for drop */
@@ -4141,6 +4152,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
4141 4152 if (IS_ERR(ssk))
4142 4153 return PTR_ERR(ssk);
4143 4154
4155 + set_bit(MPTCP_RTX_ENABLED, &msk->flags);
4144 4156 mptcp_set_state(sk, TCP_SYN_SENT);
4145 4157 subflow = mptcp_subflow_ctx(ssk);
4146 4158 #ifdef CONFIG_TCP_MD5SIG
@@ -4288,6 +4300,7 @@ static int mptcp_listen(struct socket *sock, int backlog)
4288 4300 goto unlock;
4289 4301 }
4290 4302
4303 + set_bit(MPTCP_RTX_ENABLED, &msk->flags);
4291 4304 mptcp_set_state(sk, TCP_LISTEN);
4292 4305 sock_set_flag(sk, SOCK_RCU_FREE);
4293 4306
modified net/mptcp/protocol.h
@@ -116,6 +116,7 @@
116 116 #define MPTCP_WORK_RTX 1
117 117 #define MPTCP_FALLBACK_DONE 2
118 118 #define MPTCP_WORK_CLOSE_SUBFLOW 3
119 + #define MPTCP_RTX_ENABLED 4
119 120
120 121 /* MPTCP socket release cb flags */
121 122 #define MPTCP_PUSH_PENDING 1
modified net/mptcp/subflow.c
@@ -2084,7 +2084,6 @@ static void subflow_ulp_clone(const struct request_sock *req,
2084 2084 new_ctx->request_bkup = subflow_req->request_bkup;
2085 2085 WRITE_ONCE(new_ctx->remote_id, subflow_req->remote_id);
2086 2086 new_ctx->token = subflow_req->token;
2087 - new_ctx->thmac = subflow_req->thmac;
2088 2087
2089 2088 /* the subflow req id is valid, fetched via subflow_check_req()
2090 2089 * and subflow_token_join_request()
modified net/mptcp/syncookies.c
@@ -26,7 +26,8 @@ struct join_entry {
26 26 u32 local_nonce;
27 27 u8 join_id;
28 28 u8 local_id;
29 - u8 backup;
29 + u8 backup:1,
30 + request_bkup:1;
30 31 u8 valid;
31 32 };
32 33
@@ -63,6 +64,7 @@ static void mptcp_join_store_state(struct join_entry *entry,
63 64 entry->remote_nonce = subflow_req->remote_nonce;
64 65 entry->local_nonce = subflow_req->local_nonce;
65 66 entry->backup = subflow_req->backup;
67 + entry->request_bkup = subflow_req->request_bkup;
66 68 entry->join_id = subflow_req->remote_id;
67 69 entry->local_id = subflow_req->local_id;
68 70 entry->valid = 1;
@@ -117,6 +119,7 @@ bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subfl
117 119 subflow_req->remote_nonce = e->remote_nonce;
118 120 subflow_req->local_nonce = e->local_nonce;
119 121 subflow_req->backup = e->backup;
122 + subflow_req->request_bkup = e->request_bkup;
120 123 subflow_req->remote_id = e->join_id;
121 124 subflow_req->local_id = e->local_id;
122 125 subflow_req->token = e->token;
modified net/netfilter/Kconfig
@@ -739,7 +739,7 @@ config NETFILTER_XTABLES_COMPAT
739 739 bool "Netfilter Xtables 32bit support"
740 740 depends on COMPAT
741 741 help
742 - This option provides a translation layer to run 32bit arp,ip(6),ebtables
742 + This option provides a translation layer to run 32bit ip(6),ebtables
743 743 binaries on 64bit kernels.
744 744
745 745 If unsure, say N.
modified net/netfilter/ipvs/ip_vs_sync.c
@@ -747,9 +747,9 @@ sloop:
747 747 if (cp->flags & IP_VS_CONN_F_SEQ_MASK) {
748 748 *(p++) = IPVS_OPT_SEQ_DATA;
749 749 *(p++) = sizeof(struct ip_vs_sync_conn_options);
750 - hton_seq((struct ip_vs_seq *)p, &cp->in_seq);
750 + hton_seq(&cp->in_seq, (struct ip_vs_seq *)p);
751 751 p += sizeof(struct ip_vs_seq);
752 - hton_seq((struct ip_vs_seq *)p, &cp->out_seq);
752 + hton_seq(&cp->out_seq, (struct ip_vs_seq *)p);
753 753 p += sizeof(struct ip_vs_seq);
754 754 }
755 755 /* Handle pe data */
@@ -999,10 +999,10 @@ static void ip_vs_process_message_v0(struct netns_ipvs *ipvs, const char *buffer
999 999 pp->name, state);
1000 1000 continue;
1001 1001 }
1002 - } else {
1003 - if (state >= IP_VS_CTPL_S_LAST)
1004 - IP_VS_DBG(7, "BACKUP v0, Invalid tpl state %u\n",
1005 - state);
1002 + } else if (state >= IP_VS_CTPL_S_LAST) {
1003 + IP_VS_DBG(7, "BACKUP v0, Invalid tpl state %u\n",
1004 + state);
1005 + continue;
1006 1006 }
1007 1007
1008 1008 ip_vs_conn_fill_param(ipvs, AF_INET, s->protocol,
@@ -1159,10 +1159,10 @@ static inline int ip_vs_proc_sync_conn(struct netns_ipvs *ipvs, __u8 *p, __u8 *m
1159 1159 retc = 40;
1160 1160 goto out;
1161 1161 }
1162 - } else {
1163 - if (state >= IP_VS_CTPL_S_LAST)
1164 - IP_VS_DBG(7, "BACKUP, Invalid tpl state %u\n",
1165 - state);
1162 + } else if (state >= IP_VS_CTPL_S_LAST) {
1163 + IP_VS_DBG(7, "BACKUP, Invalid tpl state %u\n", state);
1164 + retc = 40;
1165 + goto out;
1166 1166 }
1167 1167 if (ip_vs_conn_fill_param_sync(ipvs, af, s, &param, pe_data,
1168 1168 pe_data_len, pe_name, pe_name_len)) {
modified net/netfilter/nf_conntrack_netlink.c
@@ -1077,6 +1077,8 @@ static int ctnetlink_start(struct netlink_callback *cb)
1077 1077 }
1078 1078
1079 1079 cb->data = filter;
1080 + if (filter)
1081 + cb->answer_flags = NLM_F_DUMP_FILTERED;
1080 1082 return 0;
1081 1083 }
1082 1084
modified net/netfilter/nf_conntrack_sip.c
@@ -423,7 +423,7 @@ static const char *sip_skip_whitespace(const char *dptr, const char *limit)
423 423 dptr = sip_follow_continuation(dptr, limit);
424 424 break;
425 425 }
426 - return dptr;
426 + return dptr < limit ? dptr : NULL;
427 427 }
428 428
429 429 /* Search within a SIP header value, dealing with continuation lines */
modified net/netfilter/nf_log_syslog.c
@@ -1073,12 +1073,12 @@ err1:
1073 1073
1074 1074 static void __exit nf_log_syslog_exit(void)
1075 1075 {
1076 - unregister_pernet_subsys(&nf_log_syslog_net_ops);
1077 1076 nf_log_unregister(&nf_ip_logger);
1078 1077 nf_log_unregister(&nf_arp_logger);
1079 1078 nf_log_unregister(&nf_ip6_logger);
1080 1079 nf_log_unregister(&nf_netdev_logger);
1081 1080 nf_log_unregister(&nf_bridge_logger);
1081 + unregister_pernet_subsys(&nf_log_syslog_net_ops);
1082 1082 }
1083 1083
1084 1084 module_init(nf_log_syslog_init);
modified net/netlink/genetlink.c
@@ -1513,6 +1513,7 @@ struct ctrl_dump_policy_ctx {
1513 1513 struct netlink_policy_dump_state *state;
1514 1514 const struct genl_family *rt;
1515 1515 struct genl_op_iter *op_iter;
1516 + struct module *owner;
1516 1517 u32 op;
1517 1518 u16 fam_id;
1518 1519 u8 dump_map:1,
@@ -1555,6 +1556,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
1555 1556 return -ENOENT;
1556 1557
1557 1558 ctx->rt = rt;
1559 + ctx->owner = rt->module;
1560 + if (!try_module_get(ctx->owner))
1561 + return -ENOENT;
1558 1562
1559 1563 if (tb[CTRL_ATTR_OP]) {
1560 1564 struct genl_split_ops doit, dump;
@@ -1565,7 +1569,7 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
1565 1569 err = genl_get_cmd_both(ctx->op, rt, &doit, &dump);
1566 1570 if (err) {
1567 1571 NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]);
1568 - return err;
1572 + goto err_put_owner;
1569 1573 }
1570 1574
1571 1575 if (doit.policy) {
@@ -1583,16 +1587,20 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
1583 1587 goto err_free_state;
1584 1588 }
1585 1589
1586 - if (!ctx->state)
1587 - return -ENODATA;
1590 + if (!ctx->state) {
1591 + err = -ENODATA;
1592 + goto err_put_owner;
1593 + }
1588 1594
1589 1595 ctx->dump_map = 1;
1590 1596 return 0;
1591 1597 }
1592 1598
1593 1599 ctx->op_iter = kmalloc_obj(*ctx->op_iter);
1594 - if (!ctx->op_iter)
1595 - return -ENOMEM;
1600 + if (!ctx->op_iter) {
1601 + err = -ENOMEM;
1602 + goto err_put_owner;
1603 + }
1596 1604
1597 1605 genl_op_iter_init(rt, ctx->op_iter);
1598 1606 ctx->dump_map = genl_op_iter_next(ctx->op_iter);
@@ -1624,6 +1632,8 @@ err_free_state:
1624 1632 netlink_policy_dump_free(ctx->state);
1625 1633 err_free_op_iter:
1626 1634 kfree(ctx->op_iter);
1635 + err_put_owner:
1636 + module_put(ctx->owner);
1627 1637 return err;
1628 1638 }
1629 1639
@@ -1760,6 +1770,7 @@ static int ctrl_dumppolicy_done(struct netlink_callback *cb)
1760 1770
1761 1771 kfree(ctx->op_iter);
1762 1772 netlink_policy_dump_free(ctx->state);
1773 + module_put(ctx->owner);
1763 1774 return 0;
1764 1775 }
1765 1776
modified net/openvswitch/flow.c
@@ -288,7 +288,7 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh,
288 288 if (*ext_hdrs & OFPIEH12_ESP)
289 289 *ext_hdrs |= OFPIEH12_UNREP;
290 290 if ((*ext_hdrs & ~(OFPIEH12_HOP | OFPIEH12_DEST |
291 - OFPIEH12_ROUTER | IPPROTO_FRAGMENT |
291 + OFPIEH12_ROUTER | OFPIEH12_FRAG |
292 292 OFPIEH12_AUTH | OFPIEH12_UNREP)) ||
293 293 dest_options_header_count >= 2) {
294 294 *ext_hdrs |= OFPIEH12_UNSEQ;
@@ -301,7 +301,7 @@ static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh,
301 301 *ext_hdrs |= OFPIEH12_UNREP;
302 302 if ((*ext_hdrs &
303 303 ~(OFPIEH12_HOP | OFPIEH12_DEST | OFPIEH12_ROUTER |
304 - IPPROTO_FRAGMENT | OFPIEH12_UNREP)) ||
304 + OFPIEH12_FRAG | OFPIEH12_UNREP)) ||
305 305 dest_options_header_count >= 2) {
306 306 *ext_hdrs |= OFPIEH12_UNSEQ;
307 307 }
modified net/openvswitch/flow_table.c
@@ -257,11 +257,13 @@ static int tbl_mask_array_realloc(struct flow_table *tbl, int size)
257 257 if (ovsl_dereference(old->masks[i]))
258 258 new->masks[new->count++] = old->masks[i];
259 259 }
260 - call_rcu(&old->rcu, mask_array_rcu_cb);
261 260 }
262 261
263 262 rcu_assign_pointer(tbl->mask_array, new);
264 263
264 + if (old)
265 + call_rcu(&old->rcu, mask_array_rcu_cb);
266 +
265 267 return 0;
266 268 }
267 269
modified net/rds/message.c
@@ -431,7 +431,9 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
431 431 for (i = 0; i < rm->data.op_nents; ++i) {
432 432 sg_set_page(&rm->data.op_sg[i],
433 433 virt_to_page((void *)page_addrs[i]),
434 - PAGE_SIZE, 0);
434 + i == rm->data.op_nents - 1
435 + ? total_len - (i * PAGE_SIZE)
436 + : PAGE_SIZE, 0);
435 437 }
436 438
437 439 return rm;
modified net/sched/act_api.c
@@ -1200,18 +1200,13 @@ EXPORT_SYMBOL(tcf_action_exec);
1200 1200
1201 1201 int tcf_action_destroy(struct tc_action *actions[], int bind)
1202 1202 {
1203 - const struct tc_action_ops *ops;
1204 1203 struct tc_action *a;
1205 1204 int ret = 0, i;
1206 1205
1207 1206 tcf_act_for_each_action(i, a, actions) {
1208 1207 actions[i] = NULL;
1209 - ops = a->ops;
1210 - ret = __tcf_idr_release(a, bind, true);
1211 - if (ret == ACT_P_DELETED)
1212 - module_put(ops->owner);
1213 - else if (ret < 0)
1214 - return ret;
1208 + /* Drop our reference even if the action is still bound to a filter. */
1209 + ret = tcf_idr_release(a, bind);
1215 1210 }
1216 1211 return ret;
1217 1212 }
modified net/sched/cls_api.c
@@ -3254,7 +3254,7 @@ errout:
3254 3254 tcf_chain_put(chain);
3255 3255 errout_block:
3256 3256 tcf_block_release(q, block, true);
3257 - if (err == -EAGAIN)
3257 + if (err == -EAGAIN && n->nlmsg_type == RTM_NEWCHAIN)
3258 3258 /* Replay the request. */
3259 3259 goto replay;
3260 3260 return err;
modified net/sched/cls_route.c
@@ -11,6 +11,7 @@
11 11 #include <linux/kernel.h>
12 12 #include <linux/string.h>
13 13 #include <linux/errno.h>
14 + #include <linux/refcount.h>
14 15 #include <linux/skbuff.h>
15 16 #include <net/dst.h>
16 17 #include <net/route.h>
@@ -41,6 +42,7 @@ struct route4_head {
41 42 struct route4_bucket {
42 43 /* 16 FROM buckets + 16 IIF buckets + 1 wildcard bucket */
43 44 struct route4_filter __rcu *ht[16 + 16 + 1];
45 + refcount_t filters_ref;
44 46 struct rcu_head rcu;
45 47 };
46 48
@@ -336,7 +338,7 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,
336 338 struct route4_filter *nf;
337 339 struct route4_bucket *b;
338 340 unsigned int h = 0;
339 - int i, h1;
341 + int h1;
340 342
341 343 if (!head || !f)
342 344 return -EINVAL;
@@ -362,23 +364,14 @@ static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,
362 364 tcf_exts_get_net(&f->exts);
363 365 tcf_queue_work(&f->rwork, route4_delete_filter_work);
364 366
365 - /* Strip RTNL protected tree */
366 - for (i = 0; i <= 32; i++) {
367 - struct route4_filter *rt;
368 -
369 - rt = rtnl_dereference(b->ht[i]);
370 - if (rt)
371 - goto out;
367 + if (refcount_dec_and_test(&b->filters_ref)) {
368 + RCU_INIT_POINTER(head->table[to_hash(h)], NULL);
369 + kfree_rcu(b, rcu);
372 370 }
373 -
374 - /* OK, session has no flows */
375 - RCU_INIT_POINTER(head->table[to_hash(h)], NULL);
376 - kfree_rcu(b, rcu);
377 371 break;
378 372 }
379 373 }
380 374
381 - out:
382 375 *last = true;
383 376 for (h1 = 0; h1 <= 256; h1++) {
384 377 if (rcu_access_pointer(head->table[h1])) {
@@ -400,8 +393,9 @@ static const struct nla_policy route4_policy[TCA_ROUTE4_MAX + 1] = {
400 393 static int route4_set_parms(struct net *net, struct tcf_proto *tp,
401 394 unsigned long base, struct route4_filter *f,
402 395 u32 handle, struct route4_head *head,
403 - struct nlattr **tb, struct nlattr *est, int new,
404 - u32 flags, struct netlink_ext_ack *extack)
396 + struct nlattr **tb, struct nlattr *est,
397 + struct route4_filter *fold, u32 flags,
398 + struct netlink_ext_ack *extack)
405 399 {
406 400 u32 id = 0, to = 0, nhandle = 0x8000;
407 401 struct route4_filter *fp;
@@ -414,7 +408,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
414 408 return err;
415 409
416 410 if (tb[TCA_ROUTE4_TO]) {
417 - if (new && handle & 0x8000) {
411 + if (!fold && handle & 0x8000) {
418 412 NL_SET_ERR_MSG(extack, "Invalid handle");
419 413 return -EINVAL;
420 414 }
@@ -437,14 +431,14 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
437 431 } else
438 432 nhandle |= 0xFFFF << 16;
439 433
440 - if (handle && new) {
434 + if (handle && (!fold || nhandle == (handle & ~0x7F00)))
441 435 nhandle |= handle & 0x7F00;
442 - if (nhandle != handle) {
443 - NL_SET_ERR_MSG_FMT(extack,
444 - "Handle mismatch constructed: %x (expected: %x)",
445 - handle, nhandle);
446 - return -EINVAL;
447 - }
436 +
437 + if (handle && !fold && nhandle != handle) {
438 + NL_SET_ERR_MSG_FMT(extack,
439 + "Handle mismatch constructed: %x (expected: %x)",
440 + handle, nhandle);
441 + return -EINVAL;
448 442 }
449 443
450 444 if (!nhandle) {
@@ -459,6 +453,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
459 453 if (b == NULL)
460 454 return -ENOBUFS;
461 455
456 + refcount_set(&b->filters_ref, 1);
462 457 rcu_assign_pointer(head->table[h1], b);
463 458 } else {
464 459 unsigned int h2 = from_hash(nhandle >> 16);
@@ -466,8 +461,14 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
466 461 for (fp = rtnl_dereference(b->ht[h2]);
467 462 fp;
468 463 fp = rtnl_dereference(fp->next))
469 - if (fp->handle == f->handle)
464 + if (fp != fold && fp->handle == nhandle) {
465 + NL_SET_ERR_MSG_FMT(extack,
466 + "Handle %x is already in use",
467 + nhandle);
470 468 return -EEXIST;
469 + }
470 +
471 + refcount_inc(&b->filters_ref);
471 472 }
472 473
473 474 if (tb[TCA_ROUTE4_TO])
@@ -500,9 +501,8 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
500 501 struct route4_filter *fold, *f1, *pfp, *f = NULL;
501 502 struct route4_bucket *b;
502 503 struct nlattr *tb[TCA_ROUTE4_MAX + 1];
503 - unsigned int h, th;
504 + unsigned int h;
504 505 int err;
505 - bool new = true;
506 506
507 507 if (!handle) {
508 508 NL_SET_ERR_MSG(extack, "Creating with handle of 0 is invalid");
@@ -539,11 +539,10 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
539 539
540 540 f->tp = fold->tp;
541 541 f->bkt = fold->bkt;
542 - new = false;
543 542 }
544 543
545 544 err = route4_set_parms(net, tp, base, f, handle, head, tb,
546 - tca[TCA_RATE], new, flags, extack);
545 + tca[TCA_RATE], fold, flags, extack);
547 546 if (err < 0)
548 547 goto errout;
549 548
@@ -560,17 +559,20 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
560 559 rcu_assign_pointer(*fp, f);
561 560
562 561 if (fold) {
563 - th = to_hash(fold->handle);
562 + b = fold->bkt;
564 563 h = from_hash(fold->handle >> 16);
565 - b = rtnl_dereference(head->table[th]);
566 - if (b) {
567 - fp = &b->ht[h];
568 - for (pfp = rtnl_dereference(*fp); pfp;
569 - fp = &pfp->next, pfp = rtnl_dereference(*fp)) {
570 - if (pfp == fold) {
571 - rcu_assign_pointer(*fp, fold->next);
572 - break;
564 + fp = &b->ht[h];
565 + for (pfp = rtnl_dereference(*fp); pfp;
566 + fp = &pfp->next, pfp = rtnl_dereference(*fp)) {
567 + if (pfp == fold) {
568 + rcu_assign_pointer(*fp, fold->next);
569 + if (refcount_dec_and_test(&b->filters_ref)) {
570 + unsigned int th = to_hash(fold->handle);
571 +
572 + RCU_INIT_POINTER(head->table[th], NULL);
573 + kfree_rcu(b, rcu);
573 574 }
575 + break;
574 576 }
575 577 }
576 578 }
modified net/sched/sch_api.c
@@ -1385,7 +1385,7 @@ err_out4:
1385 1385 err_out3:
1386 1386 qdisc_lock_uninit(sch, ops);
1387 1387 netdev_put(dev, &sch->dev_tracker);
1388 - qdisc_free(sch);
1388 + qdisc_free_rcu(sch);
1389 1389 err_out2:
1390 1390 bpf_module_put(ops, ops->owner);
1391 1391 err_out:
modified net/sched/sch_drr.c
@@ -82,8 +82,9 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
82 82 NL_SET_ERR_MSG(extack, "Specified DRR quantum cannot be zero");
83 83 return -EINVAL;
84 84 }
85 + quantum = clamp_t(u32, quantum, 256, 1 << 20);
85 86 } else
86 - quantum = psched_mtu(qdisc_dev(sch));
87 + quantum = clamp_t(u32, (u32)psched_mtu(qdisc_dev(sch)), 256, 1 << 20);
87 88
88 89 if (cl != NULL) {
89 90 if (tca[TCA_RATE]) {
modified net/sched/sch_dualpi2.c
@@ -208,9 +208,11 @@ static void dualpi2_reset_c_protection(struct dualpi2_sched_data *q)
208 208 static void dualpi2_calculate_c_protection(struct Qdisc *sch,
209 209 struct dualpi2_sched_data *q, u32 wc)
210 210 {
211 + u32 mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 1, 1 << 20);
212 +
211 213 q->c_protection_wc = wc;
212 214 q->c_protection_wl = MAX_WC - wc;
213 - q->c_protection_init = (s32)psched_mtu(qdisc_dev(sch)) *
215 + q->c_protection_init = (s32)mtu *
214 216 ((int)q->c_protection_wc - (int)q->c_protection_wl);
215 217 dualpi2_reset_c_protection(q);
216 218 }
@@ -285,8 +287,9 @@ static bool must_drop(struct Qdisc *sch, struct dualpi2_sched_data *q,
285 287 u64 local_l_prob;
286 288 bool overload;
287 289 u32 prob;
290 + u32 mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 1, 1 << 20);
288 291
289 - if (sch->qstats.backlog < 2 * psched_mtu(qdisc_dev(sch)))
292 + if (sch->qstats.backlog < 2 * mtu)
290 293 return false;
291 294
292 295 prob = READ_ONCE(q->pi2_prob);
@@ -712,7 +715,8 @@ static u32 get_memory_limit(struct Qdisc *sch, u32 limit)
712 715 /* Apply rule of thumb, i.e., doubling the packet length,
713 716 * to further include per packet overhead in memory_limit.
714 717 */
715 - u64 memlim = mul_u32_u32(limit, 2 * psched_mtu(qdisc_dev(sch)));
718 + u64 memlim = mul_u32_u32(limit, 2 * clamp_t(u32, psched_mtu(qdisc_dev(sch)),
719 + 1, 1 << 20));
716 720
717 721 if (upper_32_bits(memlim))
718 722 return U32_MAX;
modified net/sched/sch_ets.c
@@ -83,11 +83,7 @@ static int ets_quantum_parse(struct Qdisc *sch, const struct nlattr *attr,
83 83 unsigned int *quantum,
84 84 struct netlink_ext_ack *extack)
85 85 {
86 - *quantum = nla_get_u32(attr);
87 - if (!*quantum) {
88 - NL_SET_ERR_MSG(extack, "ETS quantum cannot be zero");
89 - return -EINVAL;
90 - }
86 + *quantum = clamp_t(u32, nla_get_u32(attr), 256, 1 << 20);
91 87 return 0;
92 88 }
93 89
@@ -632,11 +628,13 @@ static int ets_qdisc_change(struct Qdisc *sch, struct nlattr *opt,
632 628 return err;
633 629 }
634 630 /* If there are more bands than strict + quanta provided, the remaining
635 - * ones are ETS with quantum of MTU. Initialize the missing values here.
631 + * ones are ETS with quantum of max(MTU, 256). Initialize the missing
632 + * values here.
636 633 */
637 634 for (i = nstrict; i < nbands; i++) {
638 635 if (!quanta[i])
639 - quanta[i] = psched_mtu(qdisc_dev(sch));
636 + quanta[i] = clamp_t(u32, (u32)psched_mtu(qdisc_dev(sch)),
637 + 256, 1 << 20);
640 638 }
641 639
642 640 /* Before commit, make sure we can allocate all new qdiscs */
modified net/sched/sch_fq.c
@@ -980,7 +980,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
980 980 }
981 981
982 982 static const struct netlink_range_validation iq_range = {
983 - .max = INT_MAX,
983 + .max = 1 << 20,
984 984 };
985 985
986 986 static const struct nla_policy fq_policy[TCA_FQ_MAX + 1] = {
@@ -1106,14 +1106,10 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt,
1106 1106 nla_get_u32(tb[TCA_FQ_FLOW_PLIMIT]));
1107 1107
1108 1108 if (tb[TCA_FQ_QUANTUM]) {
1109 - u32 quantum = nla_get_u32(tb[TCA_FQ_QUANTUM]);
1109 + u32 quantum = clamp_t(u32, nla_get_u32(tb[TCA_FQ_QUANTUM]),
1110 + 256, 1 << 20);
1110 1111
1111 - if (quantum > 0 && quantum <= (1 << 20)) {
1112 - WRITE_ONCE(q->quantum, quantum);
1113 - } else {
1114 - NL_SET_ERR_MSG_MOD(extack, "invalid quantum");
1115 - err = -EINVAL;
1116 - }
1112 + WRITE_ONCE(q->quantum, quantum);
1117 1113 }
1118 1114
1119 1115 if (tb[TCA_FQ_INITIAL_QUANTUM])
@@ -1232,7 +1228,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt,
1232 1228 sch->limit = 10000;
1233 1229 q->flow_plimit = 100;
1234 1230 mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 1, 1 << 20);
1235 - q->quantum = min_t(u32, 2 * mtu, 1 << 20);
1231 + q->quantum = clamp_t(u32, 2 * mtu, 256, 1 << 20);
1236 1232 q->initial_quantum = min_t(u32, 10 * mtu, 1 << 20);
1237 1233 q->flow_refill_delay = msecs_to_jiffies(40);
1238 1234 q->flow_max_rate = ~0UL;
modified net/sched/sch_fq_pie.c
@@ -341,7 +341,8 @@ static int fq_pie_change(struct Qdisc *sch, struct nlattr *opt,
341 341 nla_get_u32(tb[TCA_FQ_PIE_BETA]));
342 342
343 343 if (tb[TCA_FQ_PIE_QUANTUM])
344 - WRITE_ONCE(q->quantum, nla_get_u32(tb[TCA_FQ_PIE_QUANTUM]));
344 + WRITE_ONCE(q->quantum,
345 + max(256U, nla_get_u32(tb[TCA_FQ_PIE_QUANTUM])));
345 346
346 347 if (tb[TCA_FQ_PIE_MEMORY_LIMIT])
347 348 WRITE_ONCE(q->memory_limit,
modified net/sched/sch_generic.c
@@ -1086,21 +1086,21 @@ void qdisc_reset(struct Qdisc *qdisc)
1086 1086 }
1087 1087 EXPORT_SYMBOL(qdisc_reset);
1088 1088
1089 - void qdisc_free(struct Qdisc *qdisc)
1089 + static void qdisc_free_cb(struct rcu_head *head)
1090 1090 {
1091 - if (qdisc_is_percpu_stats(qdisc)) {
1092 - free_percpu(qdisc->cpu_bstats);
1093 - free_percpu(qdisc->cpu_qstats);
1091 + struct Qdisc *q = container_of(head, struct Qdisc, rcu);
1092 +
1093 + if (qdisc_is_percpu_stats(q)) {
1094 + free_percpu(q->cpu_bstats);
1095 + free_percpu(q->cpu_qstats);
1094 1096 }
1095 1097
1096 - kfree(qdisc);
1098 + kfree(q);
1097 1099 }
1098 1100
1099 - static void qdisc_free_cb(struct rcu_head *head)
1101 + void qdisc_free_rcu(struct Qdisc *qdisc)
1100 1102 {
1101 - struct Qdisc *q = container_of(head, struct Qdisc, rcu);
1102 -
1103 - qdisc_free(q);
1103 + call_rcu(&qdisc->rcu, qdisc_free_cb);
1104 1104 }
1105 1105
1106 1106 static void __qdisc_destroy(struct Qdisc *qdisc)
@@ -1127,7 +1127,7 @@ static void __qdisc_destroy(struct Qdisc *qdisc)
1127 1127
1128 1128 trace_qdisc_destroy(qdisc);
1129 1129
1130 - call_rcu(&qdisc->rcu, qdisc_free_cb);
1130 + qdisc_free_rcu(qdisc);
1131 1131 }
1132 1132
1133 1133 void qdisc_destroy(struct Qdisc *qdisc)
modified net/sched/sch_hhf.c
@@ -551,7 +551,7 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt,
551 551 return err;
552 552
553 553 if (tb[TCA_HHF_QUANTUM])
554 - new_quantum = nla_get_u32(tb[TCA_HHF_QUANTUM]);
554 + new_quantum = max(256U, nla_get_u32(tb[TCA_HHF_QUANTUM]));
555 555
556 556 if (tb[TCA_HHF_NON_HH_WEIGHT])
557 557 new_hhf_non_hh_weight = nla_get_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
@@ -613,7 +613,7 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt,
613 613 int i;
614 614
615 615 sch->limit = 1000;
616 - q->quantum = psched_mtu(qdisc_dev(sch));
616 + q->quantum = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 256, 1 << 20);
617 617 get_random_bytes(&q->perturbation, sizeof(q->perturbation));
618 618 INIT_LIST_HEAD(&q->new_buckets);
619 619 INIT_LIST_HEAD(&q->old_buckets);
@@ -624,10 +624,6 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt,
624 624 q->hhf_evict_timeout = HZ; /* 1 sec */
625 625 q->hhf_non_hh_weight = 2;
626 626
627 - if ((int)q->quantum <= 0 ||
628 - (u64)q->quantum * q->hhf_non_hh_weight > INT_MAX)
629 - q->quantum = 256;
630 -
631 627 if (opt) {
632 628 int err = hhf_change(sch, opt, extack);
633 629
modified net/sched/sch_pie.c
@@ -35,7 +35,7 @@ bool pie_drop_early(struct Qdisc *sch, struct pie_params *params,
35 35 {
36 36 u64 rnd;
37 37 u64 local_prob = vars->prob;
38 - u32 mtu = psched_mtu(qdisc_dev(sch));
38 + u32 mtu = clamp_t(u32, psched_mtu(qdisc_dev(sch)), 1, 1 << 20);
39 39
40 40 /* If there is still burst allowance left skip random early drop */
41 41 if (vars->burst_time > 0)
modified net/sched/sch_sfq.c
@@ -660,6 +660,11 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
660 660 return -EINVAL;
661 661 }
662 662
663 + if (ctl->quantum > 1 << 20) {
664 + NL_SET_ERR_MSG_MOD(extack, "quantum too large");
665 + return -EINVAL;
666 + }
667 +
663 668 if (ctl->perturb_period < 0 ||
664 669 ctl->perturb_period > INT_MAX / HZ) {
665 670 NL_SET_ERR_MSG_MOD(extack, "invalid perturb period");
@@ -688,7 +693,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
688 693
689 694 /* update and validate configuration */
690 695 if (ctl->quantum)
691 - quantum = ctl->quantum;
696 + quantum = max(256U, ctl->quantum);
692 697 if (ctl->flows)
693 698 maxflows = min_t(u32, ctl->flows, SFQ_MAX_FLOWS);
694 699 if (ctl->divisor) {
modified net/unix/af_unix.c
@@ -2812,8 +2812,8 @@ static int unix_stream_recv_urg(struct unix_stream_read_state *state)
2812 2812 return 1;
2813 2813 }
2814 2814
2815 - static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
2816 - int flags, int copied)
2815 + static struct sk_buff *manage_oob(struct sk_buff *skb, struct sk_buff **last,
2816 + struct sock *sk, int flags, int copied)
2817 2817 {
2818 2818 struct sk_buff *read_skb = NULL, *unread_skb = NULL;
2819 2819 struct unix_sock *u = unix_sk(sk);
@@ -2827,11 +2827,13 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
2827 2827 if (copied && (!u->oob_skb || skb == u->oob_skb)) {
2828 2828 skb = NULL;
2829 2829 } else if (flags & MSG_PEEK) {
2830 + *last = skb;
2830 2831 skb = skb_peek_next(skb, &sk->sk_receive_queue);
2831 2832 } else {
2832 2833 read_skb = skb;
2833 2834 skb = skb_peek_next(skb, &sk->sk_receive_queue);
2834 2835 __skb_unlink(read_skb, &sk->sk_receive_queue);
2836 + *last = skb;
2835 2837 }
2836 2838
2837 2839 if (!skb)
@@ -2850,8 +2852,10 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
2850 2852 __skb_unlink(skb, &sk->sk_receive_queue);
2851 2853 unread_skb = skb;
2852 2854 skb = skb_peek(&sk->sk_receive_queue);
2855 + *last = skb;
2853 2856 }
2854 2857 } else if (!sock_flag(sk, SOCK_URGINLINE)) {
2858 + *last = skb;
2855 2859 skb = skb_peek_next(skb, &sk->sk_receive_queue);
2856 2860 }
2857 2861
@@ -2971,8 +2975,8 @@ redo:
2971 2975 again:
2972 2976 #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
2973 2977 if (skb) {
2974 - skb = manage_oob(skb, sk, flags, copied);
2975 - if (!skb && copied) {
2978 + skb = manage_oob(skb, &last, sk, flags, copied);
2979 + if (!skb && (copied || !state->size)) {
2976 2980 unix_state_unlock(sk);
2977 2981 break;
2978 2982 }
modified rust/bindings/lib.rs
@@ -22,11 +22,13 @@
22 22 #![feature(cfi_encoding)]
23 23
24 24 #[allow(dead_code)]
25 + #[allow(clippy::as_underscore)]
25 26 #[allow(clippy::cast_lossless)]
26 27 #[allow(clippy::ptr_as_ptr)]
27 28 #[allow(clippy::ref_as_ptr)]
28 29 #[allow(clippy::undocumented_unsafe_blocks)]
29 - #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
30 + #[cfg_attr(not(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES), allow(unknown_lints))]
31 + #[allow(unnecessary_transmutes)]
30 32 #[cfg_attr(
31 33 CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
32 34 allow(suspicious_runtime_symbol_definitions)
modified rust/kernel/num.rs
@@ -15,9 +15,14 @@ pub enum Unsigned {}
15 15 /// Designates signed primitive types.
16 16 pub enum Signed {}
17 17
18 + mod private {
19 + pub trait Sealed {}
20 + }
21 +
18 22 /// Describes core properties of integer types.
19 23 pub trait Integer:
20 - Sized
24 + private::Sealed
25 + + Sized
21 26 + Copy
22 27 + Clone
23 28 + PartialEq
@@ -56,6 +61,8 @@ pub trait Integer:
56 61 macro_rules! impl_integer {
57 62 ($($type:ty: $signedness:ty), *) => {
58 63 $(
64 + impl private::Sealed for $type {}
65 +
59 66 impl Integer for $type {
60 67 type Signedness = $signedness;
61 68
modified rust/pin-init/src/lib.rs
@@ -490,13 +490,7 @@ macro_rules! stack_pin_init {
490 490 (let $var:ident $(: $t:ty)? = $val:expr) => {
491 491 let val = $val;
492 492 let mut $var = ::core::pin::pin!($crate::__internal::StackInit$(::<$t>)?::uninit());
493 - let mut $var = match $crate::__internal::StackInit::init($var, val) {
494 - Ok(res) => res,
495 - Err(x) => {
496 - let x: ::core::convert::Infallible = x;
497 - match x {}
498 - }
499 - };
493 + let Ok(mut $var) = $crate::__internal::StackInit::init($var, val);
500 494 };
501 495 }
502 496
modified rust/uapi/lib.rs
@@ -10,6 +10,7 @@
10 10 #![no_std]
11 11 #![allow(
12 12 clippy::all,
13 + clippy::as_underscore,
13 14 clippy::cast_lossless,
14 15 clippy::ptr_as_ptr,
15 16 clippy::ref_as_ptr,
@@ -23,7 +24,8 @@
23 24 unreachable_pub,
24 25 unsafe_op_in_unsafe_fn
25 26 )]
26 - #![cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
27 + #![cfg_attr(not(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES), allow(unknown_lints))]
28 + #![allow(unnecessary_transmutes)]
27 29 #![cfg_attr(
28 30 CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
29 31 allow(suspicious_runtime_symbol_definitions)
modified samples/rust/rust_print_main.rs
@@ -23,10 +23,10 @@ fn arc_print() -> Result {
23 23 let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
24 24
25 25 // Prints the value of data in `a`.
26 - pr_info!("{}", a);
26 + pr_info!("{}\n", a);
27 27
28 28 // Uses ":?" to print debug fmt of `b`.
29 - pr_info!("{:?}", b);
29 + pr_info!("{:?}\n", b);
30 30
31 31 let a: Arc<&str> = b.into();
32 32 let c = a.clone();
@@ -42,7 +42,7 @@ fn arc_print() -> Result {
42 42
43 43 use kernel::fmt::Display;
44 44 fn arc_dyn_print(arc: &Arc<dyn Display>) {
45 - pr_info!("Arc<dyn Display> says {arc}");
45 + pr_info!("Arc<dyn Display> says {arc}\n");
46 46 }
47 47
48 48 let a_i32_display: Arc<dyn Display> = Arc::new(42i32, GFP_KERNEL)?;
@@ -53,7 +53,7 @@ fn arc_print() -> Result {
53 53 }
54 54
55 55 // Pretty-prints the debug formatting with lower-case hexadecimal integers.
56 - pr_info!("{:#x?}", a);
56 + pr_info!("{:#x?}\n", a);
57 57
58 58 Ok(())
59 59 }
modified scripts/Makefile.asm-headers
@@ -48,7 +48,7 @@ syscall-y := $(addprefix $(obj)/, $(syscall-y))
48 48 generated-y := $(addprefix $(obj)/, $(generated-y))
49 49
50 50 # Remove stale wrappers when the corresponding files are removed from generic-y
51 - old-headers := $(shell test -d $(obj) && find $(obj) -name *.h)
51 + old-headers := $(shell test -d $(obj) && find $(obj) -name '*.h' ! -name '.*')
52 52 unwanted := $(filter-out $(generic-y) $(generated-y) $(syscall-y),$(old-headers))
53 53
54 54 filechk_wrap = echo "\#include <asm-generic/$*.h>"
modified scripts/livepatch/init.c
@@ -51,7 +51,7 @@ static int __init livepatch_mod_init(void)
51 51 if (!funcs) {
52 52 ret = -ENOMEM;
53 53 for (int j = 0; j < i; j++)
54 - kfree(objs[i].funcs);
54 + kfree(objs[j].funcs);
55 55 goto err_free_objs;
56 56 }
57 57
modified scripts/mksysmap
@@ -35,7 +35,7 @@
35 35 / __efistub_/d
36 36
37 37 # arm64 local symbols in PIE namespace
38 - / __pi_\\$/d
38 + / __pi_\$/d
39 39 / __pi_\.L/d
40 40
41 41 # arm64 local symbols in non-VHE KVM namespace
@@ -83,7 +83,7 @@
83 83 / _SDA2_BASE_$/d
84 84
85 85 # MODULE_INFO()
86 - / __UNIQUE_ID_modinfo[0-9]*$/d
86 + / __UNIQUE_ID_modinfo_[0-9]*$/d
87 87
88 88 # ---------------------------------------------------------------------------
89 89 # Ignored patterns
modified scripts/sorttable.c
@@ -116,7 +116,7 @@ static inline void *get_index(void *start, int entsize, int index)
116 116 }
117 117
118 118 static int extable_ent_size;
119 - static int long_size;
119 + static int long_size __maybe_unused;
120 120
121 121 #define ERRSTR_MAXSZ 256
122 122
modified security/landlock/.kunitconfig
@@ -1,6 +1,8 @@
1 1 CONFIG_AUDIT=y
2 + CONFIG_FTRACE=y
2 3 CONFIG_KUNIT=y
3 4 CONFIG_NET=y
5 + CONFIG_SCHED_TRACER=y
4 6 CONFIG_SECURITY=y
5 7 CONFIG_SECURITY_LANDLOCK=y
6 8 CONFIG_SECURITY_LANDLOCK_KUNIT_TEST=y
modified security/landlock/domain.c
@@ -439,10 +439,11 @@ landlock_merge_ruleset(struct landlock_domain *const parent,
439 439 int err;
440 440
441 441 might_sleep();
442 - lockdep_assert_held(&ruleset->lock);
443 442 if (WARN_ON_ONCE(!ruleset))
444 443 return ERR_PTR(-EINVAL);
445 444
445 + lockdep_assert_held(&ruleset->lock);
446 +
446 447 if (parent) {
447 448 if (parent->num_layers >= LANDLOCK_MAX_NUM_LAYERS)
448 449 return ERR_PTR(-E2BIG);
modified security/landlock/fs.c
@@ -1298,11 +1298,12 @@ static int current_check_refer_path(struct dentry *const old_dentry,
1298 1298 /*
1299 1299 * old_dentry may be the root of the common mount point and
1300 1300 * !IS_ROOT(old_dentry) at the same time (e.g. with open_tree() and
1301 - * OPEN_TREE_CLONE). We do not need to call dget(old_parent) because
1302 - * we keep a reference to old_dentry.
1301 + * OPEN_TREE_CLONE). Pin the dentry used as old_parent in either case.
1302 + * Otherwise, dget_parent() safely fetches and pins the current parent
1303 + * against a concurrent rename(2).
1303 1304 */
1304 - old_parent = (old_dentry == mnt_dir.dentry) ? old_dentry :
1305 - old_dentry->d_parent;
1305 + old_parent = (old_dentry == mnt_dir.dentry) ? dget(old_dentry) :
1306 + dget_parent(old_dentry);
1306 1307
1307 1308 /* new_dir->dentry is equal to new_dentry->d_parent */
1308 1309 allow_parent1 = collect_domain_accesses(subject->domain, mnt_dir.dentry,
@@ -1311,8 +1312,10 @@ static int current_check_refer_path(struct dentry *const old_dentry,
1311 1312 allow_parent2 = collect_domain_accesses(subject->domain, mnt_dir.dentry,
1312 1313 new_dir->dentry,
1313 1314 &layer_masks_parent2);
1314 - if (allow_parent1 && allow_parent2)
1315 + if (allow_parent1 && allow_parent2) {
1316 + dput(old_parent);
1315 1317 return 0;
1318 + }
1316 1319
1317 1320 /*
1318 1321 * To be able to compare source and destination domain access rights,
@@ -1324,8 +1327,10 @@ static int current_check_refer_path(struct dentry *const old_dentry,
1324 1327 subject->domain, &mnt_dir, access_request_parent1,
1325 1328 &layer_masks_parent1, &request1, old_dentry,
1326 1329 access_request_parent2, &layer_masks_parent2, &request2,
1327 - exchange ? new_dentry : NULL))
1330 + exchange ? new_dentry : NULL)) {
1331 + dput(old_parent);
1328 1332 return 0;
1333 + }
1329 1334
1330 1335 if (request1.access) {
1331 1336 request1.audit.u.path.dentry = old_parent;
@@ -1335,6 +1340,7 @@ static int current_check_refer_path(struct dentry *const old_dentry,
1335 1340 request2.audit.u.path.dentry = new_dir->dentry;
1336 1341 landlock_log_denial(subject, &request2);
1337 1342 }
1343 + dput(old_parent);
1338 1344
1339 1345 /*
1340 1346 * This prioritizes EACCES over EXDEV for all actions, including
modified security/landlock/ruleset.c
@@ -58,7 +58,7 @@ landlock_create_ruleset(const access_mask_t fs_access_mask,
58 58 new_ruleset->id = landlock_get_id_range(1);
59 59 #endif /* CONFIG_TRACEPOINTS */
60 60
61 - /* Should already be checked in landlock_create_ruleset(). */
61 + /* The caller must only pass supported access rights and scopes. */
62 62 if (fs_access_mask) {
63 63 const access_mask_t mask = fs_access_mask &
64 64 LANDLOCK_MASK_ACCESS_FS;
modified security/landlock/trace.c
@@ -6,6 +6,7 @@
6 6 * Copyright © 2026 Cloudflare, Inc.
7 7 */
8 8
9 + #include <kunit/test.h>
9 10 #include <linux/cleanup.h>
10 11 #include <linux/dcache.h>
11 12 #include <linux/err.h>
@@ -183,3 +184,184 @@ void landlock_trace_denial(
183 184 break;
184 185 }
185 186 }
187 +
188 + #ifdef CONFIG_SECURITY_LANDLOCK_KUNIT_TEST
189 +
190 + static void test_trace_seq_init(struct trace_seq *const seq, const size_t size)
191 + {
192 + memset(seq, 0, sizeof(*seq));
193 + seq_buf_init(&seq->seq, seq->buffer, size);
194 + }
195 +
196 + static void test_untrusted_str_data(struct kunit *const test)
197 + {
198 + const char binary[] = { 'a', '\0', '<' };
199 + static const char ellipsis[] = "\xe2\x80\xa6";
200 + struct trace_seq *const seq =
201 + kunit_kzalloc(test, sizeof(*seq), GFP_KERNEL);
202 + const char *output;
203 +
204 + KUNIT_ASSERT_NOT_NULL(test, seq);
205 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
206 + output = __trace_print_untrusted_str(seq, "<too_long>", 10);
207 + KUNIT_ASSERT_NOT_NULL(test, output);
208 + KUNIT_EXPECT_STREQ(test, output, "<too_long>");
209 +
210 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
211 + output = __trace_print_untrusted_str(seq, binary, sizeof(binary));
212 + KUNIT_ASSERT_NOT_NULL(test, output);
213 + KUNIT_EXPECT_STREQ(test, output, "a\\000<");
214 +
215 + /* Input ellipsis bytes are escaped and cannot mimic the raw marker. */
216 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
217 + output = __trace_print_untrusted_str(seq, ellipsis,
218 + sizeof(ellipsis) - 1);
219 + KUNIT_ASSERT_NOT_NULL(test, output);
220 + KUNIT_EXPECT_STREQ(test, output, "\\342\\200\\246");
221 + }
222 +
223 + static void test_untrusted_str_boundaries(struct kunit *const test)
224 + {
225 + static const char escaped_space[] = "\\040";
226 + const size_t output_size = TRACE_UNTRUSTED_STR_OUTPUT_SIZE;
227 + const size_t marker_len = sizeof(TRACE_TRUNCATION_MARKER) - 1;
228 + const size_t escape_len = sizeof(escaped_space) - 1;
229 + const size_t exact_prefix_len =
230 + output_size - marker_len - 1 - escape_len;
231 + const size_t short_prefix_len = exact_prefix_len + 1;
232 + struct trace_seq *const seq =
233 + kunit_kzalloc(test, sizeof(*seq), GFP_KERNEL);
234 + char *const input = kunit_kmalloc(test, output_size + 1, GFP_KERNEL);
235 + char *const expected = kunit_kmalloc(test, output_size, GFP_KERNEL);
236 + const char *output;
237 +
238 + KUNIT_ASSERT_NOT_NULL(test, seq);
239 + KUNIT_ASSERT_NOT_NULL(test, input);
240 + KUNIT_ASSERT_NOT_NULL(test, expected);
241 +
242 + /* The escaped string and its trailing NUL exactly fit the limit. */
243 + memset(input, 'a', output_size - 1);
244 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
245 + output = __trace_print_untrusted_str(seq, input, output_size - 1);
246 + KUNIT_ASSERT_NOT_NULL(test, output);
247 + KUNIT_EXPECT_EQ(test, seq->seq.len, output_size);
248 + KUNIT_EXPECT_EQ(test, memcmp(output, input, output_size - 1), 0);
249 +
250 + /* Stop before a four-byte escape when only three bytes remain. */
251 + memset(input, 'a', short_prefix_len);
252 + input[short_prefix_len] = ' ';
253 + memset(input + short_prefix_len + 1, 'b', 5);
254 + memset(expected, 'a', short_prefix_len);
255 + memcpy(expected + short_prefix_len, TRACE_TRUNCATION_MARKER,
256 + marker_len + 1);
257 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
258 + output = __trace_print_untrusted_str(seq, input, short_prefix_len + 6);
259 + KUNIT_ASSERT_NOT_NULL(test, output);
260 + KUNIT_EXPECT_STREQ(test, output, expected);
261 +
262 + /* Include a four-byte escape that exactly fills the prefix capacity. */
263 + memset(input, 'a', exact_prefix_len);
264 + input[exact_prefix_len] = ' ';
265 + memset(input + exact_prefix_len + 1, 'b', marker_len + 1);
266 + memset(expected, 'a', exact_prefix_len);
267 + memcpy(expected + exact_prefix_len, escaped_space, escape_len);
268 + memcpy(expected + exact_prefix_len + escape_len,
269 + TRACE_TRUNCATION_MARKER, marker_len + 1);
270 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
271 + output = __trace_print_untrusted_str(seq, input,
272 + exact_prefix_len + marker_len + 2);
273 + KUNIT_ASSERT_NOT_NULL(test, output);
274 + KUNIT_EXPECT_STREQ(test, output, expected);
275 +
276 + /* Literal backslashes remain escaped in complete output. */
277 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
278 + output = __trace_print_untrusted_str(seq, "/\\000", 5);
279 + KUNIT_ASSERT_NOT_NULL(test, output);
280 + KUNIT_EXPECT_STREQ(test, output, "/\\\\000");
281 + }
282 +
283 + static void test_untrusted_str_cursor(struct kunit *const test)
284 + {
285 + const size_t padding_len =
286 + TRACE_SEQ_BUFFER_SIZE - TRACE_UNTRUSTED_STR_OUTPUT_SIZE + 1;
287 + struct trace_seq *const seq =
288 + kunit_kzalloc(test, sizeof(*seq), GFP_KERNEL);
289 + char *const padding = kunit_kzalloc(test, padding_len, GFP_KERNEL);
290 + const char *output;
291 +
292 + KUNIT_ASSERT_NOT_NULL(test, seq);
293 + KUNIT_ASSERT_NOT_NULL(test, padding);
294 +
295 + /* Accept available space exactly equal to the fixed reservation. */
296 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
297 + trace_seq_putmem(seq, padding, padding_len - 1);
298 + output = __trace_print_untrusted_str(seq, "/a", 2);
299 + KUNIT_ASSERT_NOT_NULL(test, output);
300 + KUNIT_EXPECT_STREQ(test, output, "/a");
301 + KUNIT_EXPECT_EQ(test, seq->seq.len, padding_len - 1 + sizeof("/a"));
302 +
303 + /* Reject one byte less without changing the scratch cursor. */
304 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
305 + trace_seq_putmem(seq, padding, padding_len);
306 + output = __trace_print_untrusted_str(seq, "/a", 2);
307 + KUNIT_EXPECT_NULL(test, output);
308 + KUNIT_EXPECT_EQ(test, seq->seq.len, padding_len);
309 + }
310 +
311 + static void test_untrusted_str_composition(struct kunit *const test)
312 + {
313 + static const struct trace_print_flags flags[] = {
314 + { .mask = 1, .name = "read" },
315 + };
316 + const size_t output_size = TRACE_UNTRUSTED_STR_OUTPUT_SIZE;
317 + const size_t prefix_len = output_size - sizeof(TRACE_TRUNCATION_MARKER);
318 + struct trace_seq *const seq =
319 + kunit_kzalloc(test, sizeof(*seq), GFP_KERNEL);
320 + char *const expected = kunit_kmalloc(test, output_size, GFP_KERNEL);
321 + char *const path = kunit_kmalloc(test, output_size, GFP_KERNEL);
322 + const char *flags_output, *path_output;
323 +
324 + KUNIT_ASSERT_NOT_NULL(test, seq);
325 + KUNIT_ASSERT_NOT_NULL(test, expected);
326 + KUNIT_ASSERT_NOT_NULL(test, path);
327 + memset(path, 'a', output_size);
328 + memset(expected, 'a', prefix_len);
329 + memcpy(expected + prefix_len, TRACE_TRUNCATION_MARKER,
330 + sizeof(TRACE_TRUNCATION_MARKER));
331 +
332 + /* Exercise both legal TP_printk() sibling evaluation orders. */
333 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
334 + path_output = __trace_print_untrusted_str(seq, path, output_size);
335 + flags_output =
336 + trace_print_flags_seq(seq, "|", 1, flags, ARRAY_SIZE(flags));
337 + KUNIT_ASSERT_NOT_NULL(test, path_output);
338 + KUNIT_EXPECT_STREQ(test, path_output, expected);
339 + KUNIT_EXPECT_STREQ(test, flags_output, "read");
340 +
341 + test_trace_seq_init(seq, TRACE_SEQ_BUFFER_SIZE);
342 + flags_output =
343 + trace_print_flags_seq(seq, "|", 1, flags, ARRAY_SIZE(flags));
344 + path_output = __trace_print_untrusted_str(seq, path, output_size);
345 + KUNIT_ASSERT_NOT_NULL(test, path_output);
346 + KUNIT_EXPECT_STREQ(test, path_output, expected);
347 + KUNIT_EXPECT_STREQ(test, flags_output, "read");
348 + }
349 +
350 + static struct kunit_case test_cases[] = {
351 + /* clang-format off */
352 + KUNIT_CASE(test_untrusted_str_data),
353 + KUNIT_CASE(test_untrusted_str_boundaries),
354 + KUNIT_CASE(test_untrusted_str_cursor),
355 + KUNIT_CASE(test_untrusted_str_composition),
356 + {}
357 + /* clang-format on */
358 + };
359 +
360 + static struct kunit_suite test_suite = {
361 + .name = "landlock_trace",
362 + .test_cases = test_cases,
363 + };
364 +
365 + kunit_test_suite(test_suite);
366 +
367 + #endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */
modified sound/hda/codecs/realtek/alc269.c
@@ -7451,6 +7451,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7451 7451 SND_PCI_QUIRK(0x103c, 0x887c, "HP Laptop 14s-fq1xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
7452 7452 SND_PCI_QUIRK(0x103c, 0x888a, "HP ENVY x360 Convertible 15-eu0xxx", ALC245_FIXUP_HP_X360_MUTE_LEDS),
7453 7453 SND_PCI_QUIRK(0x103c, 0x888d, "HP ZBook Power 15.6 inch G8 Mobile Workstation PC", ALC236_FIXUP_HP_GPIO_LED),
7454 + SND_PCI_QUIRK(0x103c, 0x8890, "HP Elite Dragonfly Max G2 Notebook PC", ALC285_FIXUP_HP_GPIO_AMP_INIT),
7454 7455 SND_PCI_QUIRK(0x103c, 0x8895, "HP EliteBook 855 G8 Notebook PC", ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED),
7455 7456 SND_PCI_QUIRK(0x103c, 0x8896, "HP EliteBook 855 G8 Notebook PC", ALC285_FIXUP_HP_MUTE_LED),
7456 7457 SND_PCI_QUIRK(0x103c, 0x8898, "HP EliteBook 845 G8 Notebook PC", ALC285_FIXUP_HP_LIMIT_INT_MIC_BOOST),
@@ -7566,6 +7567,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7566 7567 SND_PCI_QUIRK(0x103c, 0x8b92, "HP", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
7567 7568 SND_PCI_QUIRK(0x103c, 0x8b96, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
7568 7569 SND_PCI_QUIRK(0x103c, 0x8b97, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
7570 + SND_PCI_QUIRK(0x103c, 0x8ba9, "HP Omen 16-wd0xxx", ALC245_FIXUP_HP_MUTE_LED_V1_COEFBIT),
7569 7571 SND_PCI_QUIRK(0x103c, 0x8bb3, "HP Slim OMEN", ALC287_FIXUP_CS35L41_I2C_2),
7570 7572 SND_PCI_QUIRK(0x103c, 0x8bb4, "HP Slim OMEN", ALC287_FIXUP_CS35L41_I2C_2),
7571 7573 SND_PCI_QUIRK(0x103c, 0x8bb6, "HP Laptop 15-fd0039nt", ALC236_FIXUP_HP_15_FD0XXX),
modified sound/hda/common/codec.c
@@ -2277,6 +2277,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2277 2277 int idx = kcontrol->private_value;
2278 2278 struct hda_spdif_out *spdif;
2279 2279 hda_nid_t nid;
2280 + unsigned int old_status;
2280 2281 unsigned short val;
2281 2282 int change;
2282 2283
@@ -2285,6 +2286,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2285 2286 guard(mutex)(&codec->spdif_mutex);
2286 2287 spdif = snd_array_elem(&codec->spdif_out, idx);
2287 2288 nid = spdif->nid;
2289 + old_status = spdif->status;
2288 2290 spdif->status = ucontrol->value.iec958.status[0] |
2289 2291 ((unsigned int)ucontrol->value.iec958.status[1] << 8) |
2290 2292 ((unsigned int)ucontrol->value.iec958.status[2] << 16) |
@@ -2295,7 +2297,7 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
2295 2297 spdif->ctls = val;
2296 2298 if (change && nid != (u16)-1)
2297 2299 set_dig_out_convert(codec, nid, val & 0xff, (val >> 8) & 0xff);
2298 - return change;
2300 + return change || spdif->status != old_status;
2299 2301 }
2300 2302
2301 2303 #define snd_hda_spdif_out_switch_info snd_ctl_boolean_mono_info
modified sound/hda/core/ext/controller.c
@@ -90,8 +90,10 @@ int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_bus *bus)
90 90
91 91 for (idx = 0; idx < link_count; idx++) {
92 92 hlink = kzalloc_obj(*hlink);
93 - if (!hlink)
93 + if (!hlink) {
94 + snd_hdac_ext_link_free_all(bus);
94 95 return -ENOMEM;
96 + }
95 97 hlink->index = idx;
96 98 hlink->bus = bus;
97 99 hlink->ml_addr = bus->mlcap + AZX_ML_BASE +
modified sound/hda/core/ext/stream.c
@@ -102,8 +102,10 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
102 102
103 103 for (i = 0; i < num_stream; i++) {
104 104 struct hdac_ext_stream *hext_stream = kzalloc_obj(*hext_stream);
105 - if (!hext_stream)
105 + if (!hext_stream) {
106 + snd_hdac_ext_stream_free_all(bus);
106 107 return -ENOMEM;
108 + }
107 109 tag = ++stream_tag;
108 110 snd_hdac_ext_stream_init(bus, hext_stream, idx, dir, tag);
109 111 idx++;
@@ -111,7 +113,6 @@ int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
111 113 }
112 114
113 115 return 0;
114 -
115 116 }
116 117 EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_init_all);
117 118
modified sound/pci/ctxfi/cthw20k2.c
@@ -994,6 +994,7 @@ static int daio_mgr_dao_init(struct hw *hw, void *blk, unsigned int idx, unsigne
994 994 /* S/PDIF output */
995 995 switch ((conf & 0xf)) {
996 996 case 1:
997 + case 9:
997 998 set_field(&ctl->txctl[idx], ATXCTL_NUC, 0);
998 999 break;
999 1000 case 2:
modified sound/pci/rme9652/hdspm.c
@@ -1071,14 +1071,8 @@ struct hdspm {
1071 1071
1072 1072
1073 1073 static const struct pci_device_id snd_hdspm_ids[] = {
1074 - {
1075 - .vendor = PCI_VENDOR_ID_XILINX,
1076 - .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
1077 - .subvendor = PCI_ANY_ID,
1078 - .subdevice = PCI_ANY_ID,
1079 - .class = 0,
1080 - .class_mask = 0,
1081 - .driver_data = 0},
1074 + { PCI_DEVICE(PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI) },
1075 + { PCI_DEVICE(0x1d18, 0x3fc6) }, /* RME HDSPe AIO PCI express audio */
1082 1076 {0,}
1083 1077 };
1084 1078
modified sound/soc/amd/acp-da7219-max98357a.c
@@ -17,6 +17,7 @@
17 17 #include <linux/i2c.h>
18 18 #include <linux/input.h>
19 19 #include <linux/acpi.h>
20 + #include <linux/pci.h>
20 21
21 22 #include "acp.h"
22 23 #include "../codecs/da7219.h"
@@ -742,6 +743,18 @@ static const struct regulator_desc acp_da7219_desc = {
742 743 .n_voltages = 1,
743 744 };
744 745
746 + /*
747 + * The ACP3.x+ (Raven/Picasso and later) audio coprocessor is a dedicated PCI
748 + * function. Carrizo/Stoney - the only platforms handled by this driver - reach
749 + * the ACP through the GPU driver and have no such device.
750 + */
751 + #define ACP3X_PCI_DEV_ID 0x15e2
752 +
753 + static const struct pci_device_id acp3x_pci_ids[] = {
754 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, ACP3X_PCI_DEV_ID) },
755 + { 0, },
756 + };
757 +
745 758 static int cz_probe(struct platform_device *pdev)
746 759 {
747 760 int ret;
@@ -750,6 +763,16 @@ static int cz_probe(struct platform_device *pdev)
750 763 struct regulator_dev *rdev;
751 764 struct device *dev = &pdev->dev;
752 765
766 + /*
767 + * AMDI5682 is also matched by acp3x-alc5682-max98357 (Raven/Picasso).
768 + * If the ACP3.x PCI function is present this is such a board; return
769 + * -ENODEV so that driver binds instead.
770 + */
771 + if (pci_dev_present(acp3x_pci_ids)) {
772 + dev_info(dev, "ACP3.x PCI device present, deferring to acp3x-alc5682-max98357\n");
773 + return -ENODEV;
774 + }
775 +
753 776 card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev);
754 777 if (!card)
755 778 return -ENODEV;
modified sound/soc/amd/renoir/acp3x-pdm-dma.c
@@ -104,7 +104,7 @@ static void disable_pdm_interrupts(void __iomem *acp_base)
104 104 u32 ext_int_ctrl;
105 105
106 106 ext_int_ctrl = rn_readl(acp_base + ACP_EXTERNAL_INTR_CNTL);
107 - ext_int_ctrl |= ~PDM_DMA_INTR_MASK;
107 + ext_int_ctrl &= ~PDM_DMA_INTR_MASK;
108 108 rn_writel(ext_int_ctrl, acp_base + ACP_EXTERNAL_INTR_CNTL);
109 109 }
110 110
modified sound/soc/amd/yc/acp6x-mach.c
@@ -388,6 +388,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
388 388 DMI_MATCH(DMI_PRODUCT_NAME, "Nitro ANV15-41"),
389 389 }
390 390 },
391 + {
392 + .driver_data = &acp6x_card,
393 + .matches = {
394 + DMI_MATCH(DMI_BOARD_VENDOR, "RB"),
395 + DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN17-41"),
396 + }
397 + },
391 398 {
392 399 .driver_data = &acp6x_card,
393 400 .matches = {
@@ -892,6 +899,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
892 899 DMI_MATCH(DMI_BOARD_NAME, "TM2423"),
893 900 }
894 901 },
902 + {
903 + .driver_data = &acp6x_card,
904 + .matches = {
905 + DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
906 + DMI_MATCH(DMI_PRODUCT_NAME, "HP 255R 15.6 inch G10 Notebook PC"),
907 + }
908 + },
895 909 {}
896 910 };
897 911
modified sound/soc/amd/yc/acp6x-pdm-dma.c
@@ -275,9 +275,11 @@ static int acp6x_pdm_dma_close(struct snd_soc_component *component,
275 275 struct snd_pcm_substream *substream)
276 276 {
277 277 struct pdm_dev_data *adata = dev_get_drvdata(component->dev);
278 + struct snd_pcm_runtime *runtime = substream->runtime;
278 279
279 280 acp6x_disable_pdm_interrupts(adata->acp6x_base);
280 281 adata->capture_stream = NULL;
282 + kfree(runtime->private_data);
281 283 return 0;
282 284 }
283 285
modified sound/soc/bcm/bcm63xx-i2s-whistler.c
@@ -285,6 +285,7 @@ static const struct of_device_id snd_soc_bcm_audio_match[] = {
285 285 {.compatible = "brcm,bcm63xx-i2s"},
286 286 { }
287 287 };
288 + MODULE_DEVICE_TABLE(of, snd_soc_bcm_audio_match);
288 289 #endif
289 290
290 291 static struct platform_driver bcm63xx_i2s_driver = {
modified sound/soc/codecs/ab8500-codec.c
@@ -14,17 +14,14 @@
14 14 * for ST-Ericsson.
15 15 */
16 16
17 - #include <linux/cleanup.h>
18 17 #include <linux/kernel.h>
19 18 #include <linux/module.h>
20 19 #include <linux/device.h>
21 20 #include <linux/slab.h>
22 21 #include <linux/moduleparam.h>
23 22 #include <linux/init.h>
24 - #include <linux/delay.h>
25 23 #include <linux/pm.h>
26 24 #include <linux/platform_device.h>
27 - #include <linux/mutex.h>
28 25 #include <linux/mfd/abx500/ab8500.h>
29 26 #include <linux/mfd/abx500.h>
30 27 #include <linux/mfd/abx500/ab8500-sysctrl.h>
@@ -54,32 +51,9 @@
54 51 /* Macrocell register definitions */
55 52 #define AB8500_GPIO_DIR4_REG 0x13 /* Bank AB8500_MISC */
56 53
57 - /* Nr of FIR/IIR-coeff banks in ANC-block */
58 - #define AB8500_NR_OF_ANC_COEFF_BANKS 2
59 -
60 - /* Minimum duration to keep ANC IIR Init bit high or
61 - low before proceeding with the configuration sequence */
62 - #define AB8500_ANC_SM_DELAY 2000
63 -
64 - /* Sidetone states */
65 - static const char * const enum_sid_state[] = {
66 - "Unconfigured",
67 - "Apply FIR",
68 - "FIR is configured",
69 - };
70 - enum sid_state {
71 - SID_UNCONFIGURED = 0,
72 - SID_APPLY_FIR = 1,
73 - SID_FIR_CONFIGURED = 2,
74 - };
75 -
76 54 /* Private data for AB8500 device-driver */
77 55 struct ab8500_codec_drvdata {
78 56 struct regmap *regmap;
79 - struct mutex ctrl_lock;
80 -
81 - /* Sidetone */
82 - enum sid_state sid_status;
83 57 };
84 58
85 59 static inline const char *amic_micbias_str(enum amic_micbias micbias)
@@ -259,7 +233,7 @@ static const struct snd_kcontrol_new dapm_anc_in_select[] = {
259 233 /* ANC - Enable/Disable */
260 234 static const struct snd_kcontrol_new dapm_anc_enable[] = {
261 235 SOC_DAPM_SINGLE("Switch", AB8500_ANCCONF1,
262 - AB8500_ANCCONF1_ENANC, 0, 0),
236 + AB8500_ANCCONF1_ENANC, 1, 0),
263 237 };
264 238
265 239 /* ANC to Earpiece - Mute */
@@ -341,12 +315,6 @@ static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
341 315
342 316 /* DA/AD */
343 317
344 - SND_SOC_DAPM_INPUT("ADC Input"),
345 - SND_SOC_DAPM_ADC("ADC", "ab8500_0c", SND_SOC_NOPM, 0, 0),
346 -
347 - SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
348 - SND_SOC_DAPM_OUTPUT("DAC Output"),
349 -
350 318 SND_SOC_DAPM_AIF_IN("DA_IN1", NULL, 0, SND_SOC_NOPM, 0, 0),
351 319 SND_SOC_DAPM_AIF_IN("DA_IN2", NULL, 0, SND_SOC_NOPM, 0, 0),
352 320 SND_SOC_DAPM_AIF_IN("DA_IN3", NULL, 0, SND_SOC_NOPM, 0, 0),
@@ -538,9 +506,8 @@ static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
538 506 SND_SOC_DAPM_MIXER("AD3 Channel Volume",
539 507 SND_SOC_NOPM, 0, 0,
540 508 NULL, 0),
541 - SND_SOC_DAPM_MIXER("AD3 Enable",
542 - AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34, 0,
543 - NULL, 0),
509 + SND_SOC_DAPM_SUPPLY("AD34 Enable", AB8500_ADPATHENA,
510 + AB8500_ADPATHENA_ENAD34, 0, NULL, 0),
544 511
545 512 /* Mic 2 */
546 513
@@ -599,9 +566,8 @@ static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
599 566 SND_SOC_NOPM, 0, 0,
600 567 NULL, 0),
601 568
602 - SND_SOC_DAPM_MIXER("AD12 Enable",
603 - AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD12, 0,
604 - NULL, 0),
569 + SND_SOC_DAPM_SUPPLY("AD12 Enable", AB8500_ADPATHENA,
570 + AB8500_ADPATHENA_ENAD12, 0, NULL, 0),
605 571
606 572 /* HD Capture path */
607 573
@@ -615,12 +581,8 @@ static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
615 581 SND_SOC_DAPM_MIXER("AD6 Channel Volume",
616 582 SND_SOC_NOPM, 0, 0,
617 583 NULL, 0),
618 - SND_SOC_DAPM_MIXER("AD57 Enable",
619 - AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
620 - NULL, 0),
621 - SND_SOC_DAPM_MIXER("AD68 Enable",
622 - AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD5768, 0,
623 - NULL, 0),
584 + SND_SOC_DAPM_SUPPLY("AD5768 Enable", AB8500_ADPATHENA,
585 + AB8500_ADPATHENA_ENAD5768, 0, NULL, 0),
624 586
625 587 /* Digital Microphone path */
626 588
@@ -652,15 +614,8 @@ static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = {
652 614 SND_SOC_DAPM_MIXER("AD4 Channel Volume",
653 615 SND_SOC_NOPM, 0, 0,
654 616 NULL, 0),
655 - SND_SOC_DAPM_MIXER("AD4 Enable",
656 - AB8500_ADPATHENA, AB8500_ADPATHENA_ENAD34,
657 - 0, NULL, 0),
658 -
659 617 /* Acoustical Noise Cancellation path */
660 618
661 - SND_SOC_DAPM_INPUT("ANC Configure Input"),
662 - SND_SOC_DAPM_OUTPUT("ANC Configure Output"),
663 -
664 619 SND_SOC_DAPM_MUX("ANC Source",
665 620 SND_SOC_NOPM, 0, 0,
666 621 dapm_anc_in_select),
@@ -703,24 +658,13 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
703 658 {"Main Supply", NULL, "Audio Power"},
704 659 {"Main Supply", NULL, "Audio Analog Power"},
705 660
706 - {"DAC", NULL, "ab8500_0p"},
707 - {"DAC", NULL, "Main Supply"},
708 - {"ADC", NULL, "ab8500_0c"},
709 - {"ADC", NULL, "Main Supply"},
710 -
711 - /* ANC Configure */
712 - {"ANC Configure Input", NULL, "Main Supply"},
713 - {"ANC Configure Output", NULL, "ANC Configure Input"},
714 -
715 - /* AD/DA */
716 - {"ADC", NULL, "ADC Input"},
717 - {"DAC Output", NULL, "DAC"},
718 -
719 661 /* Powerup charge pump if DA1/2 is in use */
720 662
721 663 {"DA_IN1", NULL, "ab8500_0p"},
664 + {"DA_IN1", NULL, "Main Supply"},
722 665 {"DA_IN1", NULL, "Charge Pump"},
723 666 {"DA_IN2", NULL, "ab8500_0p"},
667 + {"DA_IN2", NULL, "Main Supply"},
724 668 {"DA_IN2", NULL, "Charge Pump"},
725 669
726 670 /* Headset path */
@@ -755,8 +699,10 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
755 699 /* HF or LineOut path */
756 700
757 701 {"DA_IN3", NULL, "ab8500_0p"},
702 + {"DA_IN3", NULL, "Main Supply"},
758 703 {"DA3 Channel Volume", NULL, "DA_IN3"},
759 704 {"DA_IN4", NULL, "ab8500_0p"},
705 + {"DA_IN4", NULL, "Main Supply"},
760 706 {"DA4 Channel Volume", NULL, "DA_IN4"},
761 707
762 708 {"Speaker Left Source", "Audio Path", "DA3 Channel Volume"},
@@ -814,8 +760,10 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
814 760 /* Vibrator path */
815 761
816 762 {"DA_IN5", NULL, "ab8500_0p"},
763 + {"DA_IN5", NULL, "Main Supply"},
817 764 {"DA5 Channel Volume", NULL, "DA_IN5"},
818 765 {"DA_IN6", NULL, "ab8500_0p"},
766 + {"DA_IN6", NULL, "Main Supply"},
819 767 {"DA6 Channel Volume", NULL, "DA_IN6"},
820 768
821 769 {"VIB1 DAC", NULL, "DA5 Channel Volume"},
@@ -857,13 +805,15 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
857 805 {"AD1 Channel Volume", NULL, "AD1 Source Select"},
858 806 {"AD2 Channel Volume", NULL, "AD2 Source Select"},
859 807
860 - {"AD12 Enable", NULL, "AD1 Channel Volume"},
861 - {"AD12 Enable", NULL, "AD2 Channel Volume"},
808 + {"AD1 Channel Volume", NULL, "AD12 Enable"},
809 + {"AD2 Channel Volume", NULL, "AD12 Enable"},
862 810
863 - {"AD_OUT1", NULL, "ab8500_0c"},
864 - {"AD_OUT1", NULL, "AD12 Enable"},
865 - {"AD_OUT2", NULL, "ab8500_0c"},
866 - {"AD_OUT2", NULL, "AD12 Enable"},
811 + {"ab8500_0c", NULL, "AD_OUT1"},
812 + {"AD_OUT1", NULL, "Main Supply"},
813 + {"AD_OUT1", NULL, "AD1 Channel Volume"},
814 + {"ab8500_0c", NULL, "AD_OUT2"},
815 + {"AD_OUT2", NULL, "Main Supply"},
816 + {"AD_OUT2", NULL, "AD2 Channel Volume"},
867 817
868 818 /* Mic 1 */
869 819
@@ -880,11 +830,11 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
880 830 {"AD3 Source Select", "Mic 1", "MIC1 ADC"},
881 831
882 832 {"AD3 Channel Volume", NULL, "AD3 Source Select"},
833 + {"AD3 Channel Volume", NULL, "AD34 Enable"},
883 834
884 - {"AD3 Enable", NULL, "AD3 Channel Volume"},
885 -
886 - {"AD_OUT3", NULL, "ab8500_0c"},
887 - {"AD_OUT3", NULL, "AD3 Enable"},
835 + {"ab8500_0c", NULL, "AD_OUT3"},
836 + {"AD_OUT3", NULL, "Main Supply"},
837 + {"AD_OUT3", NULL, "AD3 Channel Volume"},
888 838
889 839 /* HD Capture path */
890 840
@@ -893,14 +843,15 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
893 843
894 844 {"AD5 Channel Volume", NULL, "AD5 Source Select"},
895 845 {"AD6 Channel Volume", NULL, "AD6 Source Select"},
846 + {"AD5 Channel Volume", NULL, "AD5768 Enable"},
847 + {"AD6 Channel Volume", NULL, "AD5768 Enable"},
896 848
897 - {"AD57 Enable", NULL, "AD5 Channel Volume"},
898 - {"AD68 Enable", NULL, "AD6 Channel Volume"},
899 -
900 - {"AD_OUT57", NULL, "ab8500_0c"},
901 - {"AD_OUT57", NULL, "AD57 Enable"},
902 - {"AD_OUT68", NULL, "ab8500_0c"},
903 - {"AD_OUT68", NULL, "AD68 Enable"},
849 + {"ab8500_0c", NULL, "AD_OUT57"},
850 + {"AD_OUT57", NULL, "Main Supply"},
851 + {"AD_OUT57", NULL, "AD5 Channel Volume"},
852 + {"ab8500_0c", NULL, "AD_OUT68"},
853 + {"AD_OUT68", NULL, "Main Supply"},
854 + {"AD_OUT68", NULL, "AD6 Channel Volume"},
904 855
905 856 /* Digital Microphone path */
906 857
@@ -911,17 +862,25 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
911 862 {"DMic 5", NULL, "V-DMIC"},
912 863 {"DMic 6", NULL, "V-DMIC"},
913 864
914 - {"AD1 Source Select", NULL, "DMic 1"},
915 - {"AD2 Source Select", NULL, "DMic 2"},
916 - {"AD3 Source Select", NULL, "DMic 3"},
917 - {"AD5 Source Select", NULL, "DMic 5"},
918 - {"AD6 Source Select", NULL, "DMic 6"},
865 + {"DMIC1", NULL, "DMic 1"},
866 + {"DMIC2", NULL, "DMic 2"},
867 + {"DMIC3", NULL, "DMic 3"},
868 + {"DMIC4", NULL, "DMic 4"},
869 + {"DMIC5", NULL, "DMic 5"},
870 + {"DMIC6", NULL, "DMic 6"},
919 871
920 - {"AD4 Channel Volume", NULL, "DMic 4"},
921 - {"AD4 Enable", NULL, "AD4 Channel Volume"},
872 + {"AD1 Source Select", "DMic 1", "DMIC1"},
873 + {"AD2 Source Select", "DMic 2", "DMIC2"},
874 + {"AD3 Source Select", "DMic 3", "DMIC3"},
875 + {"AD5 Source Select", "DMic 5", "DMIC5"},
876 + {"AD6 Source Select", "DMic 6", "DMIC6"},
922 877
923 - {"AD_OUT4", NULL, "ab8500_0c"},
924 - {"AD_OUT4", NULL, "AD4 Enable"},
878 + {"AD4 Channel Volume", NULL, "DMIC4"},
879 + {"AD4 Channel Volume", NULL, "AD34 Enable"},
880 +
881 + {"ab8500_0c", NULL, "AD_OUT4"},
882 + {"AD_OUT4", NULL, "Main Supply"},
883 + {"AD_OUT4", NULL, "AD4 Channel Volume"},
925 884
926 885 /* LineIn Bypass path */
927 886
@@ -946,13 +905,13 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes[] = {
946 905
947 906 /* Sidetone Filter path */
948 907
949 - {"Sidetone Left Source", "LineIn Left", "AD12 Enable"},
950 - {"Sidetone Left Source", "LineIn Right", "AD12 Enable"},
951 - {"Sidetone Left Source", "Mic 1", "AD3 Enable"},
908 + {"Sidetone Left Source", "LineIn Left", "AD1 Channel Volume"},
909 + {"Sidetone Left Source", "LineIn Right", "AD2 Channel Volume"},
910 + {"Sidetone Left Source", "Mic 1", "AD3 Channel Volume"},
952 911 {"Sidetone Left Source", "Headset Left", "DA_IN1"},
953 - {"Sidetone Right Source", "LineIn Right", "AD12 Enable"},
954 - {"Sidetone Right Source", "Mic 1", "AD3 Enable"},
955 - {"Sidetone Right Source", "DMic 4", "AD4 Enable"},
912 + {"Sidetone Right Source", "LineIn Right", "AD2 Channel Volume"},
913 + {"Sidetone Right Source", "Mic 1", "AD3 Channel Volume"},
914 + {"Sidetone Right Source", "DMic 4", "AD4 Channel Volume"},
956 915 {"Sidetone Right Source", "Headset Right", "DA_IN2"},
957 916
958 917 {"STFIR1 Control", NULL, "Sidetone Left Source"},
@@ -980,75 +939,6 @@ static const struct snd_soc_dapm_route ab8500_dapm_routes_mic2_vamicx[] = {
980 939 {"MIC2 V-AMICx Enable", NULL, "V-AMIC2"},
981 940 };
982 941
983 - /*
984 - * Control-events
985 - */
986 -
987 - static int sid_status_control_get(struct snd_kcontrol *kcontrol,
988 - struct snd_ctl_elem_value *ucontrol)
989 - {
990 - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
991 - struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
992 -
993 - guard(mutex)(&drvdata->ctrl_lock);
994 - ucontrol->value.enumerated.item[0] = drvdata->sid_status;
995 -
996 - return 0;
997 - }
998 -
999 - /* Write sidetone FIR-coefficients configuration sequence */
1000 - static int sid_status_control_put(struct snd_kcontrol *kcontrol,
1001 - struct snd_ctl_elem_value *ucontrol)
1002 - {
1003 - struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1004 - struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(component->dev);
1005 - unsigned int param, sidconf;
1006 - int status = 1;
1007 -
1008 - dev_dbg(component->dev, "%s: Enter\n", __func__);
1009 -
1010 - if (ucontrol->value.enumerated.item[0] != SID_APPLY_FIR) {
1011 - dev_err(component->dev,
1012 - "%s: ERROR: This control supports '%s' only!\n",
1013 - __func__, enum_sid_state[SID_APPLY_FIR]);
1014 - return -EIO;
1015 - }
1016 -
1017 - guard(mutex)(&drvdata->ctrl_lock);
1018 -
1019 - sidconf = snd_soc_component_read(component, AB8500_SIDFIRCONF);
1020 - if (((sidconf & BIT(AB8500_SIDFIRCONF_FIRSIDBUSY)) != 0)) {
1021 - if ((sidconf & BIT(AB8500_SIDFIRCONF_ENFIRSIDS)) == 0) {
1022 - dev_err(component->dev, "%s: Sidetone busy while off!\n",
1023 - __func__);
1024 - status = -EPERM;
1025 - } else {
1026 - status = -EBUSY;
1027 - }
1028 - dev_dbg(component->dev, "%s: Exit\n", __func__);
1029 - return status;
1030 - }
1031 -
1032 - snd_soc_component_write(component, AB8500_SIDFIRADR, 0);
1033 -
1034 - for (param = 0; param < AB8500_SID_FIR_COEFFS; param++) {
1035 - snd_soc_component_write(component, AB8500_SIDFIRCOEF1, 0);
1036 - snd_soc_component_write(component, AB8500_SIDFIRCOEF2, 0);
1037 - }
1038 -
1039 - snd_soc_component_update_bits(component, AB8500_SIDFIRADR,
1040 - BIT(AB8500_SIDFIRADR_FIRSIDSET),
1041 - BIT(AB8500_SIDFIRADR_FIRSIDSET));
1042 - snd_soc_component_update_bits(component, AB8500_SIDFIRADR,
1043 - BIT(AB8500_SIDFIRADR_FIRSIDSET), 0);
1044 -
1045 - drvdata->sid_status = SID_FIR_CONFIGURED;
1046 -
1047 - dev_dbg(component->dev, "%s: Exit\n", __func__);
1048 -
1049 - return status;
1050 - }
1051 -
1052 942 /*
1053 943 * Controls - Non-DAPM ASoC
1054 944 */
@@ -1332,9 +1222,6 @@ static SOC_ENUM_SINGLE_DECL(soc_enum_bfifomast,
1332 1222 AB8500_FIFOCONF3, AB8500_FIFOCONF3_BFIFOMAST_SHIFT,
1333 1223 enum_slavemaster);
1334 1224
1335 - /* Sidetone */
1336 - static SOC_ENUM_SINGLE_EXT_DECL(soc_enum_sidstate, enum_sid_state);
1337 -
1338 1225 /* ANC */
1339 1226
1340 1227 static struct snd_kcontrol_new ab8500_ctrls[] = {
@@ -1625,8 +1512,6 @@ static struct snd_kcontrol_new ab8500_ctrls[] = {
1625 1512 AB8500_ANC_WARP_DELAY_MIN, AB8500_ANC_WARP_DELAY_MAX, 0),
1626 1513
1627 1514 /* Sidetone */
1628 - SOC_ENUM_EXT("Sidetone Status", soc_enum_sidstate,
1629 - sid_status_control_get, sid_status_control_put),
1630 1515 SOC_SINGLE_STROBE("Sidetone Reset",
1631 1516 AB8500_SIDFIRADR, AB8500_SIDFIRADR_FIRSIDSET, 0),
1632 1517 };
@@ -1638,23 +1523,25 @@ static struct snd_kcontrol_new ab8500_ctrls[] = {
1638 1523 static int ab8500_audio_init_audioblock(struct snd_soc_component *component)
1639 1524 {
1640 1525 int status;
1526 + u8 mask = AB8500_STW4500CTRL3_CLK32KOUT2DIS |
1527 + AB8500_STW4500CTRL3_RESETAUDN;
1641 1528
1642 1529 dev_dbg(component->dev, "%s: Enter.\n", __func__);
1643 1530
1644 - /* Reset audio-registers and disable 32kHz-clock output 2 */
1645 - status = ab8500_sysctrl_write(AB8500_STW4500CTRL3,
1646 - AB8500_STW4500CTRL3_CLK32KOUT2DIS |
1647 - AB8500_STW4500CTRL3_RESETAUDN,
1648 - AB8500_STW4500CTRL3_RESETAUDN);
1531 + /* Reset the audio registers and disable the unused 32 kHz output. */
1532 + status = ab8500_sysctrl_write(AB8500_STW4500CTRL3, mask,
1533 + AB8500_STW4500CTRL3_CLK32KOUT2DIS);
1649 1534 if (status < 0)
1650 1535 return status;
1651 1536
1652 - return 0;
1537 + return ab8500_sysctrl_write(AB8500_STW4500CTRL3, mask, mask);
1653 1538 }
1654 1539
1655 1540 static int ab8500_audio_setup_mics(struct snd_soc_component *component,
1656 1541 struct amic_settings *amics)
1657 1542 {
1543 + struct device *dev = component->dev;
1544 + struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
1658 1545 struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
1659 1546 u8 value8;
1660 1547 unsigned int value;
@@ -1663,20 +1550,21 @@ static int ab8500_audio_setup_mics(struct snd_soc_component *component,
1663 1550
1664 1551 dev_dbg(component->dev, "%s: Enter.\n", __func__);
1665 1552
1666 - /* Set DMic-clocks to outputs */
1667 - status = abx500_get_register_interruptible(component->dev, AB8500_MISC,
1668 - AB8500_GPIO_DIR4_REG,
1669 - &value8);
1670 - if (status < 0)
1671 - return status;
1672 - value = value8 | GPIO27_DIR_OUTPUT | GPIO29_DIR_OUTPUT |
1673 - GPIO31_DIR_OUTPUT;
1674 - status = abx500_set_register_interruptible(component->dev,
1675 - AB8500_MISC,
1676 - AB8500_GPIO_DIR4_REG,
1677 - value);
1678 - if (status < 0)
1679 - return status;
1553 + /* Set DMic-clocks to outputs; these GPIOs do not exist on AB8505. */
1554 + if (!is_ab8505(ab8500)) {
1555 + status = abx500_get_register_interruptible(dev, AB8500_MISC,
1556 + AB8500_GPIO_DIR4_REG,
1557 + &value8);
1558 + if (status < 0)
1559 + return status;
1560 + value = value8 | GPIO27_DIR_OUTPUT | GPIO29_DIR_OUTPUT |
1561 + GPIO31_DIR_OUTPUT;
1562 + status = abx500_set_register_interruptible(dev, AB8500_MISC,
1563 + AB8500_GPIO_DIR4_REG,
1564 + value);
1565 + if (status < 0)
1566 + return status;
1567 + }
1680 1568
1681 1569 /* Attach regulators to AMic DAPM-paths */
1682 1570 dev_dbg(component->dev, "%s: Mic 1a regulator: %s\n", __func__,
@@ -1745,149 +1633,91 @@ static int ab8500_audio_set_ear_cmv(struct snd_soc_component *component,
1745 1633 return 0;
1746 1634 }
1747 1635
1748 - static int ab8500_audio_set_bit_delay(struct snd_soc_dai *dai,
1749 - unsigned int delay)
1750 - {
1751 - unsigned int mask, val;
1752 - struct snd_soc_component *component = dai->component;
1753 -
1754 - mask = BIT(AB8500_DIGIFCONF2_IF0DEL);
1755 - val = 0;
1756 -
1757 - switch (delay) {
1758 - case 0:
1759 - break;
1760 - case 1:
1761 - val |= BIT(AB8500_DIGIFCONF2_IF0DEL);
1762 - break;
1763 - default:
1764 - dev_err(dai->component->dev,
1765 - "%s: ERROR: Unsupported bit-delay (0x%x)!\n",
1766 - __func__, delay);
1767 - return -EINVAL;
1768 - }
1769 -
1770 - dev_dbg(dai->component->dev, "%s: IF0 Bit-delay: %d bits.\n",
1771 - __func__, delay);
1772 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF2, mask, val);
1773 -
1774 - return 0;
1775 - }
1776 -
1777 - /* Gates clocking according format mask */
1778 - static int ab8500_codec_set_dai_clock_gate(struct snd_soc_component *component,
1779 - unsigned int fmt)
1780 - {
1781 - unsigned int mask;
1782 - unsigned int val;
1783 -
1784 - mask = BIT(AB8500_DIGIFCONF1_ENMASTGEN) |
1785 - BIT(AB8500_DIGIFCONF1_ENFSBITCLK0);
1786 -
1787 - val = BIT(AB8500_DIGIFCONF1_ENMASTGEN);
1788 -
1789 - switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
1790 - case SND_SOC_DAIFMT_CONT: /* continuous clock */
1791 - dev_dbg(component->dev, "%s: IF0 Clock is continuous.\n",
1792 - __func__);
1793 - val |= BIT(AB8500_DIGIFCONF1_ENFSBITCLK0);
1794 - break;
1795 - case SND_SOC_DAIFMT_GATED: /* clock is gated */
1796 - dev_dbg(component->dev, "%s: IF0 Clock is gated.\n",
1797 - __func__);
1798 - break;
1799 - default:
1800 - dev_err(component->dev,
1801 - "%s: ERROR: Unsupported clock mask (0x%x)!\n",
1802 - __func__, fmt & SND_SOC_DAIFMT_CLOCK_MASK);
1803 - return -EINVAL;
1804 - }
1805 -
1806 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF1, mask, val);
1807 -
1808 - return 0;
1809 - }
1810 -
1811 1636 static int ab8500_codec_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1812 1637 {
1813 - unsigned int mask;
1814 - unsigned int val;
1815 1638 struct snd_soc_component *component = dai->component;
1816 - int status;
1639 + unsigned int conf1_mask, conf1_val = 0;
1640 + unsigned int conf2_mask, conf2_val = 0;
1641 + unsigned int conf3_mask, conf3_val = 0;
1642 + bool provider = false;
1643 + int ret;
1817 1644
1818 1645 dev_dbg(component->dev, "%s: Enter (fmt = 0x%x)\n", __func__, fmt);
1819 1646
1820 - mask = BIT(AB8500_DIGIFCONF3_IF1DATOIF0AD) |
1647 + conf3_mask = BIT(AB8500_DIGIFCONF3_IF1DATOIF0AD) |
1821 1648 BIT(AB8500_DIGIFCONF3_IF1CLKTOIF0CLK) |
1822 1649 BIT(AB8500_DIGIFCONF3_IF0BFIFOEN) |
1823 1650 BIT(AB8500_DIGIFCONF3_IF0MASTER);
1824 - val = 0;
1825 1651
1826 1652 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
1827 1653 case SND_SOC_DAIFMT_CBP_CFP:
1828 - dev_dbg(dai->component->dev,
1654 + dev_dbg(component->dev,
1829 1655 "%s: IF0 Master-mode: AB8500 provider.\n", __func__);
1830 - val |= BIT(AB8500_DIGIFCONF3_IF0MASTER);
1656 + conf3_val |= BIT(AB8500_DIGIFCONF3_IF0MASTER);
1657 + provider = true;
1831 1658 break;
1832 1659 case SND_SOC_DAIFMT_CBC_CFC:
1833 - dev_dbg(dai->component->dev,
1660 + dev_dbg(component->dev,
1834 1661 "%s: IF0 Master-mode: AB8500 consumer.\n", __func__);
1835 1662 break;
1836 1663 case SND_SOC_DAIFMT_CBC_CFP:
1837 1664 case SND_SOC_DAIFMT_CBP_CFC:
1838 - dev_err(dai->component->dev,
1665 + dev_err(component->dev,
1839 1666 "%s: ERROR: The device is either a provider or a consumer.\n",
1840 1667 __func__);
1841 1668 fallthrough;
1842 1669 default:
1843 - dev_err(dai->component->dev,
1844 - "%s: ERROR: Unsupporter clocking mask 0x%x\n",
1670 + dev_err(component->dev,
1671 + "%s: ERROR: Unsupported clocking mask 0x%x\n",
1845 1672 __func__, fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK);
1846 1673 return -EINVAL;
1847 1674 }
1848 1675
1849 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF3, mask, val);
1850 -
1851 - /* Set clock gating */
1852 - status = ab8500_codec_set_dai_clock_gate(component, fmt);
1853 - if (status) {
1854 - dev_err(dai->component->dev,
1855 - "%s: ERROR: Failed to set clock gate (%d).\n",
1856 - __func__, status);
1857 - return status;
1676 + conf1_mask = BIT(AB8500_DIGIFCONF1_ENMASTGEN) |
1677 + BIT(AB8500_DIGIFCONF1_ENFSBITCLK0);
1678 + switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
1679 + case SND_SOC_DAIFMT_CONT:
1680 + if (provider)
1681 + conf1_val = conf1_mask;
1682 + break;
1683 + case SND_SOC_DAIFMT_GATED:
1684 + if (provider)
1685 + conf1_val = BIT(AB8500_DIGIFCONF1_ENMASTGEN);
1686 + break;
1687 + default:
1688 + dev_err(component->dev, "%s: Unsupported clock mask 0x%x\n",
1689 + __func__, fmt & SND_SOC_DAIFMT_CLOCK_MASK);
1690 + return -EINVAL;
1858 1691 }
1859 1692
1860 - /* Setting data transfer format */
1861 -
1862 - mask = BIT(AB8500_DIGIFCONF2_IF0FORMAT0) |
1863 - BIT(AB8500_DIGIFCONF2_IF0FORMAT1) |
1864 - BIT(AB8500_DIGIFCONF2_FSYNC0P) |
1865 - BIT(AB8500_DIGIFCONF2_BITCLK0P);
1866 - val = 0;
1693 + conf2_mask = BIT(AB8500_DIGIFCONF2_IF0FORMAT0) |
1694 + BIT(AB8500_DIGIFCONF2_IF0FORMAT1) |
1695 + BIT(AB8500_DIGIFCONF2_IF0DEL) |
1696 + BIT(AB8500_DIGIFCONF2_FSYNC0P) |
1697 + BIT(AB8500_DIGIFCONF2_BITCLK0P);
1867 1698
1868 1699 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1869 1700 case SND_SOC_DAIFMT_I2S: /* I2S mode */
1870 - dev_dbg(dai->component->dev, "%s: IF0 Protocol: I2S\n", __func__);
1871 - val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT1);
1872 - ab8500_audio_set_bit_delay(dai, 0);
1701 + dev_dbg(component->dev, "%s: IF0 Protocol: I2S\n", __func__);
1702 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT1) |
1703 + BIT(AB8500_DIGIFCONF2_IF0DEL);
1873 1704 break;
1874 1705
1875 1706 case SND_SOC_DAIFMT_DSP_A: /* L data MSB after FRM LRC */
1876 - dev_dbg(dai->component->dev,
1707 + dev_dbg(component->dev,
1877 1708 "%s: IF0 Protocol: DSP A (TDM)\n", __func__);
1878 - val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0);
1879 - ab8500_audio_set_bit_delay(dai, 1);
1709 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0) |
1710 + BIT(AB8500_DIGIFCONF2_IF0DEL);
1880 1711 break;
1881 1712
1882 1713 case SND_SOC_DAIFMT_DSP_B: /* L data MSB during FRM LRC */
1883 - dev_dbg(dai->component->dev,
1714 + dev_dbg(component->dev,
1884 1715 "%s: IF0 Protocol: DSP B (TDM)\n", __func__);
1885 - val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0);
1886 - ab8500_audio_set_bit_delay(dai, 0);
1716 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0FORMAT0);
1887 1717 break;
1888 1718
1889 1719 default:
1890 - dev_err(dai->component->dev,
1720 + dev_err(component->dev,
1891 1721 "%s: ERROR: Unsupported format (0x%x)!\n",
1892 1722 __func__, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
1893 1723 return -EINVAL;
@@ -1895,39 +1725,50 @@ static int ab8500_codec_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1895 1725
1896 1726 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1897 1727 case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
1898 - dev_dbg(dai->component->dev,
1728 + dev_dbg(component->dev,
1899 1729 "%s: IF0: Normal bit clock, normal frame\n",
1900 1730 __func__);
1901 1731 break;
1902 1732 case SND_SOC_DAIFMT_NB_IF: /* normal BCLK + inv FRM */
1903 - dev_dbg(dai->component->dev,
1733 + dev_dbg(component->dev,
1904 1734 "%s: IF0: Normal bit clock, inverted frame\n",
1905 1735 __func__);
1906 - val |= BIT(AB8500_DIGIFCONF2_FSYNC0P);
1736 + conf2_val |= BIT(AB8500_DIGIFCONF2_FSYNC0P);
1907 1737 break;
1908 1738 case SND_SOC_DAIFMT_IB_NF: /* invert BCLK + nor FRM */
1909 - dev_dbg(dai->component->dev,
1739 + dev_dbg(component->dev,
1910 1740 "%s: IF0: Inverted bit clock, normal frame\n",
1911 1741 __func__);
1912 - val |= BIT(AB8500_DIGIFCONF2_BITCLK0P);
1742 + conf2_val |= BIT(AB8500_DIGIFCONF2_BITCLK0P);
1913 1743 break;
1914 1744 case SND_SOC_DAIFMT_IB_IF: /* invert BCLK + FRM */
1915 - dev_dbg(dai->component->dev,
1745 + dev_dbg(component->dev,
1916 1746 "%s: IF0: Inverted bit clock, inverted frame\n",
1917 1747 __func__);
1918 - val |= BIT(AB8500_DIGIFCONF2_FSYNC0P);
1919 - val |= BIT(AB8500_DIGIFCONF2_BITCLK0P);
1748 + conf2_val |= BIT(AB8500_DIGIFCONF2_FSYNC0P) |
1749 + BIT(AB8500_DIGIFCONF2_BITCLK0P);
1920 1750 break;
1921 1751 default:
1922 - dev_err(dai->component->dev,
1752 + dev_err(component->dev,
1923 1753 "%s: ERROR: Unsupported INV mask 0x%x\n",
1924 1754 __func__, fmt & SND_SOC_DAIFMT_INV_MASK);
1925 1755 return -EINVAL;
1926 1756 }
1927 1757
1928 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF2, mask, val);
1758 + ret = snd_soc_component_update_bits(component, AB8500_DIGIFCONF3,
1759 + conf3_mask, conf3_val);
1760 + if (ret < 0)
1761 + return ret;
1929 1762
1930 - return 0;
1763 + ret = snd_soc_component_update_bits(component, AB8500_DIGIFCONF1,
1764 + conf1_mask, conf1_val);
1765 + if (ret < 0)
1766 + return ret;
1767 +
1768 + ret = snd_soc_component_update_bits(component, AB8500_DIGIFCONF2,
1769 + conf2_mask, conf2_val);
1770 +
1771 + return ret < 0 ? ret : 0;
1931 1772 }
1932 1773
1933 1774 static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
@@ -1935,23 +1776,27 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
1935 1776 int slots, int slot_width)
1936 1777 {
1937 1778 struct snd_soc_component *component = dai->component;
1938 - unsigned int val, mask, slot, slots_active;
1779 + unsigned int active_mask, clock_ratio, slot, value, ad_out, reg;
1780 + unsigned int tx_active, rx_active;
1781 + unsigned int conf1_val, conf2_val;
1782 + unsigned int mask;
1783 + int channel, ret;
1939 1784
1940 1785 mask = BIT(AB8500_DIGIFCONF2_IF0WL0) |
1941 1786 BIT(AB8500_DIGIFCONF2_IF0WL1);
1942 - val = 0;
1787 + conf2_val = 0;
1943 1788
1944 1789 switch (slot_width) {
1945 1790 case 16:
1946 1791 break;
1947 1792 case 20:
1948 - val |= BIT(AB8500_DIGIFCONF2_IF0WL0);
1793 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0WL0);
1949 1794 break;
1950 1795 case 24:
1951 - val |= BIT(AB8500_DIGIFCONF2_IF0WL1);
1796 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0WL1);
1952 1797 break;
1953 1798 case 32:
1954 - val |= BIT(AB8500_DIGIFCONF2_IF0WL1) |
1799 + conf2_val |= BIT(AB8500_DIGIFCONF2_IF0WL1) |
1955 1800 BIT(AB8500_DIGIFCONF2_IF0WL0);
1956 1801 break;
1957 1802 default:
@@ -1960,27 +1805,11 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
1960 1805 return -EINVAL;
1961 1806 }
1962 1807
1963 - dev_dbg(dai->component->dev, "%s: IF0 slot-width: %d bits.\n",
1964 - __func__, slot_width);
1965 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF2, mask, val);
1966 -
1967 - /* Setup TDM clocking according to slot count */
1968 - dev_dbg(dai->component->dev, "%s: Slots, total: %d\n", __func__, slots);
1969 - mask = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
1970 - BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
1971 1808 switch (slots) {
1972 1809 case 2:
1973 - val = AB8500_MASK_NONE;
1974 - break;
1975 1810 case 4:
1976 - val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0);
1977 - break;
1978 1811 case 8:
1979 - val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
1980 - break;
1981 1812 case 16:
1982 - val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
1983 - BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
1984 1813 break;
1985 1814 default:
1986 1815 dev_err(dai->component->dev,
@@ -1988,92 +1817,134 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
1988 1817 __func__, slots);
1989 1818 return -EINVAL;
1990 1819 }
1991 - snd_soc_component_update_bits(component, AB8500_DIGIFCONF1, mask, val);
1992 -
1993 - /* Setup TDM DA according to active tx slots */
1994 1820
1995 - if (tx_mask & ~0xff)
1996 - return -EINVAL;
1997 -
1998 - mask = AB8500_DASLOTCONFX_SLTODAX_MASK;
1999 - tx_mask = tx_mask << AB8500_DA_DATA0_OFFSET;
2000 - slots_active = hweight32(tx_mask);
2001 -
2002 - dev_dbg(dai->component->dev, "%s: Slots, active, TX: %d\n", __func__,
2003 - slots_active);
2004 -
2005 - switch (slots_active) {
2006 - case 0:
1821 + clock_ratio = slots * slot_width;
1822 + switch (clock_ratio) {
1823 + case 32:
1824 + conf1_val = 0;
2007 1825 break;
2008 - case 1:
2009 - slot = ffs(tx_mask);
2010 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF1, mask, slot);
2011 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF3, mask, slot);
2012 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF2, mask, slot);
2013 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF4, mask, slot);
1826 + case 64:
1827 + conf1_val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0);
2014 1828 break;
2015 - case 2:
2016 - slot = ffs(tx_mask);
2017 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF1, mask, slot);
2018 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF3, mask, slot);
2019 - slot = fls(tx_mask);
2020 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF2, mask, slot);
2021 - snd_soc_component_update_bits(component, AB8500_DASLOTCONF4, mask, slot);
1829 + case 128:
1830 + conf1_val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
2022 1831 break;
2023 - case 8:
2024 - dev_dbg(dai->component->dev,
2025 - "%s: In 8-channel mode DA-from-slot mapping is set manually.",
2026 - __func__);
1832 + case 256:
1833 + conf1_val = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
1834 + BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
2027 1835 break;
2028 1836 default:
2029 - dev_err(dai->component->dev,
2030 - "%s: Unsupported number of active TX-slots (%d)!\n",
2031 - __func__, slots_active);
1837 + dev_err(component->dev, "%s: Unsupported BCLK ratio (%u)!\n",
1838 + __func__, clock_ratio);
2032 1839 return -EINVAL;
2033 1840 }
2034 1841
2035 - /* Setup TDM AD according to active RX-slots */
1842 + active_mask = GENMASK(min(slots, 8) - 1, 0);
1843 + if ((tx_mask | rx_mask) & ~active_mask) {
1844 + dev_err(component->dev, "%s: Slot mask exceeds slot count\n",
1845 + __func__);
1846 + return -EINVAL;
1847 + }
2036 1848
2037 - if (rx_mask & ~0xff)
1849 + tx_active = hweight32(tx_mask);
1850 + rx_active = hweight32(rx_mask);
1851 + if (tx_active != 0 && tx_active != 1 && tx_active != 2 &&
1852 + tx_active != 8) {
1853 + dev_err(component->dev, "%s: Unsupported active TX slots (%u)!\n",
1854 + __func__, tx_active);
2038 1855 return -EINVAL;
1856 + }
1857 + if (rx_active != 0 && rx_active != 1 && rx_active != 2 &&
1858 + rx_active != 8) {
1859 + dev_err(component->dev, "%s: Unsupported active RX slots (%u)!\n",
1860 + __func__, rx_active);
1861 + return -EINVAL;
1862 + }
2039 1863
2040 - rx_mask = rx_mask << AB8500_AD_DATA0_OFFSET;
2041 - slots_active = hweight32(rx_mask);
1864 + dev_dbg(component->dev,
1865 + "%s: %d slots of %d bits, TX active: %u, RX active: %u\n",
1866 + __func__, slots, slot_width, tx_active, rx_active);
2042 1867
2043 - dev_dbg(dai->component->dev, "%s: Slots, active, RX: %d\n", __func__,
2044 - slots_active);
1868 + ret = snd_soc_component_update_bits(component, AB8500_DIGIFCONF2,
1869 + mask, conf2_val);
1870 + if (ret < 0)
1871 + return ret;
2045 1872
2046 - switch (slots_active) {
2047 - case 0:
2048 - break;
2049 - case 1:
2050 - slot = ffs(rx_mask);
2051 - snd_soc_component_update_bits(component, AB8500_ADSLOTSEL(slot),
2052 - AB8500_MASK_SLOT(slot),
2053 - AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
2054 - break;
2055 - case 2:
2056 - slot = ffs(rx_mask);
2057 - snd_soc_component_update_bits(component,
2058 - AB8500_ADSLOTSEL(slot),
2059 - AB8500_MASK_SLOT(slot),
2060 - AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
2061 - slot = fls(rx_mask);
2062 - snd_soc_component_update_bits(component,
2063 - AB8500_ADSLOTSEL(slot),
2064 - AB8500_MASK_SLOT(slot),
2065 - AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT2, slot));
2066 - break;
2067 - case 8:
2068 - dev_dbg(dai->component->dev,
2069 - "%s: In 8-channel mode AD-to-slot mapping is set manually.",
2070 - __func__);
2071 - break;
2072 - default:
2073 - dev_err(dai->component->dev,
2074 - "%s: Unsupported number of active RX-slots (%d)!\n",
2075 - __func__, slots_active);
2076 - return -EINVAL;
1873 + mask = BIT(AB8500_DIGIFCONF1_IF0BITCLKOS0) |
1874 + BIT(AB8500_DIGIFCONF1_IF0BITCLKOS1);
1875 + ret = snd_soc_component_update_bits(component, AB8500_DIGIFCONF1,
1876 + mask, conf1_val);
1877 + if (ret < 0)
1878 + return ret;
1879 +
1880 + mask = AB8500_DASLOTCONFX_SLTODAX_MASK;
1881 + if (tx_active == 1 || tx_active == 2) {
1882 + slot = __ffs(tx_mask) + AB8500_DA_DATA0_OFFSET;
1883 + reg = AB8500_DASLOTCONF1;
1884 + ret = snd_soc_component_update_bits(component, reg, mask, slot);
1885 + if (ret < 0)
1886 + return ret;
1887 + reg = AB8500_DASLOTCONF3;
1888 + ret = snd_soc_component_update_bits(component, reg, mask, slot);
1889 + if (ret < 0)
1890 + return ret;
1891 +
1892 + if (tx_active == 2)
1893 + slot = __fls(tx_mask) + AB8500_DA_DATA0_OFFSET;
1894 + reg = AB8500_DASLOTCONF2;
1895 + ret = snd_soc_component_update_bits(component, reg, mask, slot);
1896 + if (ret < 0)
1897 + return ret;
1898 + reg = AB8500_DASLOTCONF4;
1899 + ret = snd_soc_component_update_bits(component, reg, mask, slot);
1900 + if (ret < 0)
1901 + return ret;
1902 + } else if (tx_active == 8) {
1903 + channel = 0;
1904 + for (slot = 0; slot < 8; slot++) {
1905 + if (!(tx_mask & BIT(slot)))
1906 + continue;
1907 + reg = AB8500_DASLOTCONF1 + channel++;
1908 + value = slot + AB8500_DA_DATA0_OFFSET;
1909 + ret = snd_soc_component_update_bits(component, reg, mask, value);
1910 + if (ret < 0)
1911 + return ret;
1912 + }
1913 + }
1914 +
1915 + if (rx_active == 1 || rx_active == 2) {
1916 + slot = __ffs(rx_mask) + AB8500_AD_DATA0_OFFSET;
1917 + value = AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3,
1918 + slot);
1919 + reg = AB8500_ADSLOTSEL(slot);
1920 + mask = AB8500_MASK_SLOT(slot);
1921 + ret = snd_soc_component_update_bits(component, reg, mask, value);
1922 + if (ret < 0)
1923 + return ret;
1924 +
1925 + if (rx_active == 2) {
1926 + slot = __fls(rx_mask) + AB8500_AD_DATA0_OFFSET;
1927 + value = AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT2,
1928 + slot);
1929 + reg = AB8500_ADSLOTSEL(slot);
1930 + mask = AB8500_MASK_SLOT(slot);
1931 + ret = snd_soc_component_update_bits(component, reg, mask, value);
1932 + if (ret < 0)
1933 + return ret;
1934 + }
1935 + } else if (rx_active == 8) {
1936 + channel = 0;
1937 + for (slot = 0; slot < 8; slot++) {
1938 + if (!(rx_mask & BIT(slot)))
1939 + continue;
1940 + ad_out = AB8500_AD_OUT1 + channel++;
1941 + value = AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(ad_out, slot);
1942 + reg = AB8500_ADSLOTSEL(slot);
1943 + mask = AB8500_MASK_SLOT(slot);
1944 + ret = snd_soc_component_update_bits(component, reg, mask, value);
1945 + if (ret < 0)
1946 + return ret;
1947 + }
2077 1948 }
2078 1949
2079 1950 return 0;
@@ -2170,10 +2041,8 @@ static void ab8500_codec_of_probe(struct device *dev, struct device_node *np,
2170 2041
2171 2042 static int ab8500_codec_probe(struct snd_soc_component *component)
2172 2043 {
2173 - struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
2174 2044 struct device *dev = component->dev;
2175 2045 struct device_node *np = dev->of_node;
2176 - struct ab8500_codec_drvdata *drvdata = dev_get_drvdata(dev);
2177 2046 struct ab8500_codec_platform_data codec_pdata;
2178 2047 int status;
2179 2048
@@ -2181,6 +2050,13 @@ static int ab8500_codec_probe(struct snd_soc_component *component)
2181 2050
2182 2051 ab8500_codec_of_probe(dev, np, &codec_pdata);
2183 2052
2053 + status = ab8500_audio_init_audioblock(component);
2054 + if (status < 0) {
2055 + dev_err(dev, "%s: failed to init audio-block (%d)!\n",
2056 + __func__, status);
2057 + return status;
2058 + }
2059 +
2184 2060 status = ab8500_audio_setup_mics(component, &codec_pdata.amics);
2185 2061 if (status < 0) {
2186 2062 pr_err("%s: Failed to setup mics (%d)!\n", __func__, status);
@@ -2193,23 +2069,12 @@ static int ab8500_codec_probe(struct snd_soc_component *component)
2193 2069 return status;
2194 2070 }
2195 2071
2196 - status = ab8500_audio_init_audioblock(component);
2197 - if (status < 0) {
2198 - dev_err(dev, "%s: failed to init audio-block (%d)!\n",
2199 - __func__, status);
2200 - return status;
2201 - }
2202 -
2203 2072 /* Override HW-defaults */
2204 2073 snd_soc_component_write(component, AB8500_ANACONF5,
2205 2074 BIT(AB8500_ANACONF5_HSAUTOEN));
2206 2075 snd_soc_component_write(component, AB8500_SHORTCIRCONF,
2207 2076 BIT(AB8500_SHORTCIRCONF_HSZCDDIS));
2208 2077
2209 - snd_soc_dapm_disable_pin(dapm, "ANC Configure Input");
2210 -
2211 - mutex_init(&drvdata->ctrl_lock);
2212 -
2213 2078 return status;
2214 2079 }
2215 2080
@@ -2238,7 +2103,6 @@ static int ab8500_codec_driver_probe(struct platform_device *pdev)
2238 2103 GFP_KERNEL);
2239 2104 if (!drvdata)
2240 2105 return -ENOMEM;
2241 - drvdata->sid_status = SID_UNCONFIGURED;
2242 2106 dev_set_drvdata(&pdev->dev, drvdata);
2243 2107
2244 2108 drvdata->regmap = devm_regmap_init(&pdev->dev, NULL, &pdev->dev,
modified sound/soc/codecs/cs35l56-sdw.c
@@ -386,11 +386,8 @@ static int __maybe_unused cs35l56_sdw_system_suspend(struct device *dev)
386 386 {
387 387 struct cs35l56_private *cs35l56 = dev_get_drvdata(dev);
388 388
389 - if (!cs35l56->base.init_done)
390 - return 0;
391 -
392 - /* runtime_resume unmasks the interrupt */
393 - cs35l56_mask_soundwire_interrupts(cs35l56);
389 + if (cs35l56->sdw_attached)
390 + cs35l56_mask_soundwire_interrupts(cs35l56);
394 391
395 392 return cs35l56_system_suspend(dev);
396 393 }
modified sound/soc/codecs/cs35l56.c
@@ -18,9 +18,11 @@
18 18 #include <linux/interrupt.h>
19 19 #include <linux/math.h>
20 20 #include <linux/module.h>
21 + #include <linux/mutex.h>
21 22 #include <linux/pm.h>
22 23 #include <linux/pm_runtime.h>
23 24 #include <linux/property.h>
25 + #include <linux/reboot.h>
24 26 #include <linux/regmap.h>
25 27 #include <linux/regulator/consumer.h>
26 28 #include <linux/slab.h>
@@ -37,6 +39,13 @@
37 39 #include "wm_adsp.h"
38 40 #include "cs35l56.h"
39 41
42 + /*
43 + * snd_soc_register_component() can call component_probe() on all instances
44 + * in a card, so deferred registration must be protected across all instances.
45 + */
46 + static DEFINE_MUTEX(cs35l56_component_register_lock);
47 + static bool cs35l56_shutting_down;
48 +
40 49 void cs35l56_mask_soundwire_interrupts(struct cs35l56_private *cs35l56)
41 50 {
42 51 /*
@@ -1365,12 +1374,6 @@ static int _cs35l56_component_probe(struct snd_soc_component *component)
1365 1374
1366 1375 BUILD_BUG_ON(ARRAY_SIZE(cs35l56_tx_input_texts) != ARRAY_SIZE(cs35l56_tx_input_values));
1367 1376
1368 - if (!wait_for_completion_timeout(&cs35l56->init_completion,
1369 - msecs_to_jiffies(5000))) {
1370 - dev_err(cs35l56->base.dev, "%s: init_completion timed out\n", __func__);
1371 - return -ENODEV;
1372 - }
1373 -
1374 1377 cs35l56->dsp.part = kasprintf(GFP_KERNEL, "cs35l%02x", cs35l56->base.type);
1375 1378 if (!cs35l56->dsp.part)
1376 1379 return -ENOMEM;
@@ -1939,6 +1942,45 @@ static int cs35l56_try_get_broken_sdca_spkid_gpio(struct cs35l56_private *cs35l5
1939 1942 return ret;
1940 1943 }
1941 1944
1945 + static int cs35l56_component_register(struct cs35l56_private *cs35l56)
1946 + {
1947 + int ret;
1948 +
1949 + ret = snd_soc_register_component(cs35l56->base.dev,
1950 + &soc_component_dev_cs35l56,
1951 + cs35l56_dai, ARRAY_SIZE(cs35l56_dai));
1952 + if (ret < 0) {
1953 + dev_err(cs35l56->base.dev, "Register codec failed: %d\n", ret);
1954 + return ret;
1955 + }
1956 +
1957 + cs35l56->component_registered = true;
1958 +
1959 + return 0;
1960 + }
1961 +
1962 + static void cs35l56_component_register_work(struct work_struct *work)
1963 + {
1964 + struct cs35l56_private *cs35l56 = container_of(work,
1965 + struct cs35l56_private,
1966 + component_register_work);
1967 + int ret;
1968 +
1969 + guard(mutex)(&cs35l56_component_register_lock);
1970 +
1971 + if (cs35l56_shutting_down)
1972 + return;
1973 +
1974 + PM_RUNTIME_ACQUIRE_AUTOSUSPEND(cs35l56->base.dev, pm_err);
1975 + ret = PM_RUNTIME_ACQUIRE_ERR(&pm_err);
1976 + if (ret) {
1977 + dev_err(cs35l56->base.dev, "register_work failed to get pm_runtime: %d\n", ret);
1978 + return;
1979 + }
1980 +
1981 + cs35l56_component_register(cs35l56);
1982 + }
1983 +
1942 1984 int cs35l56_common_probe(struct cs35l56_private *cs35l56, int irq)
1943 1985 {
1944 1986 int ret;
@@ -1947,6 +1989,7 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56, int irq)
1947 1989 mutex_init(&cs35l56->base.irq_lock);
1948 1990 cs35l56->base.cal_index = -1;
1949 1991 cs35l56->speaker_id = -ENOENT;
1992 + INIT_WORK(&cs35l56->component_register_work, cs35l56_component_register_work);
1950 1993
1951 1994 dev_set_drvdata(cs35l56->base.dev, cs35l56);
1952 1995
@@ -2020,12 +2063,17 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56, int irq)
2020 2063 if (ret)
2021 2064 goto err_remove_wm_adsp;
2022 2065
2023 - ret = snd_soc_register_component(cs35l56->base.dev,
2024 - &soc_component_dev_cs35l56,
2025 - cs35l56_dai, ARRAY_SIZE(cs35l56_dai));
2026 - if (ret < 0) {
2027 - dev_err_probe(cs35l56->base.dev, ret, "Register codec failed\n");
2028 - goto err_free_irq;
2066 + /*
2067 + * Defer calling snd_soc_register_component() on SoundWire to prevent
2068 + * a deadlock where it calls our component_probe(), which requires the
2069 + * SoundWire enumeration to complete, but because we are still in probe()
2070 + * the SoundWire core will not call the update_status() callback. At time
2071 + * of writing snd_soc_register_component() never returns EPROBE_DEFER.
2072 + */
2073 + if (!cs35l56->sdw_peripheral) {
2074 + ret = cs35l56_component_register(cs35l56);
2075 + if (ret < 0)
2076 + goto err_free_irq;
2029 2077 }
2030 2078
2031 2079 return 0;
@@ -2055,6 +2103,7 @@ EXPORT_SYMBOL_NS_GPL(cs35l56_common_probe, "SND_SOC_CS35L56_CORE");
2055 2103
2056 2104 int cs35l56_init(struct cs35l56_private *cs35l56)
2057 2105 {
2106 + bool first_time_init = !cs35l56->base.init_done;
2058 2107 int ret;
2059 2108
2060 2109 /*
@@ -2131,13 +2180,23 @@ post_soft_reset:
2131 2180 cs35l56->base.init_done = true;
2132 2181 complete_all(&cs35l56->init_completion);
2133 2182
2183 + if (cs35l56->sdw_peripheral && first_time_init) {
2184 + /*
2185 + * Hardware now accessible, queue work to call
2186 + * snd_soc_register_component().
2187 + */
2188 + queue_work(system_freezable_wq, &cs35l56->component_register_work);
2189 + }
2190 +
2134 2191 return 0;
2135 2192 }
2136 2193 EXPORT_SYMBOL_NS_GPL(cs35l56_init, "SND_SOC_CS35L56_CORE");
2137 2194
2138 2195 void cs35l56_remove(struct cs35l56_private *cs35l56)
2139 2196 {
2140 - snd_soc_unregister_component(cs35l56->base.dev);
2197 + cancel_work_sync(&cs35l56->component_register_work);
2198 + if (cs35l56->component_registered)
2199 + snd_soc_unregister_component(cs35l56->base.dev);
2141 2200
2142 2201 cs35l56->base.init_done = false;
2143 2202
@@ -2172,6 +2231,37 @@ EXPORT_NS_GPL_DEV_PM_OPS(cs35l56_pm_ops_i2c_spi, SND_SOC_CS35L56_CORE) = {
2172 2231 };
2173 2232 #endif
2174 2233
2234 + static int cs35l56_reboot_notify(struct notifier_block *nb,
2235 + unsigned long action, void *data)
2236 + {
2237 + guard(mutex)(&cs35l56_component_register_lock);
2238 + cs35l56_shutting_down = true;
2239 +
2240 + return NOTIFY_DONE;
2241 + }
2242 +
2243 + static struct notifier_block cs35l56_reboot_notifier = {
2244 + .notifier_call = cs35l56_reboot_notify,
2245 + };
2246 +
2247 + static int __init cs35l56_modinit(void)
2248 + {
2249 + /*
2250 + * Use reboot notifier to prevent race between shutdown and
2251 + * snd_soc_register_component(). Driver shutdown() callback would
2252 + * run too late, after device_shutdown() is already walking the
2253 + * device list that component registration can modify.
2254 + */
2255 + return register_reboot_notifier(&cs35l56_reboot_notifier);
2256 + }
2257 + module_init(cs35l56_modinit);
2258 +
2259 + static void __exit cs35l56_modexit(void)
2260 + {
2261 + unregister_reboot_notifier(&cs35l56_reboot_notifier);
2262 + }
2263 + module_exit(cs35l56_modexit);
2264 +
2175 2265 MODULE_DESCRIPTION("ASoC CS35L56 driver");
2176 2266 MODULE_IMPORT_NS("SND_SOC_CS35L56_SHARED");
2177 2267 MODULE_IMPORT_NS("SND_SOC_CS_AMP_LIB");
modified sound/soc/codecs/cs35l56.h
@@ -32,6 +32,7 @@ struct sdw_slave;
32 32 struct cs35l56_private {
33 33 struct wm_adsp dsp; /* must be first member */
34 34 struct cs35l56_base base;
35 + struct work_struct component_register_work;
35 36 struct work_struct dsp_work;
36 37 struct workqueue_struct *dsp_wq;
37 38 struct snd_soc_component *component;
@@ -41,6 +42,7 @@ struct cs35l56_private {
41 42 const char *fallback_fw_suffix;
42 43 bool soft_resetting;
43 44 bool sdw_attached;
45 + bool component_registered;
44 46 struct completion init_completion;
45 47
46 48 int speaker_id;
modified sound/soc/codecs/es8326.c
@@ -26,6 +26,7 @@ struct es8326_priv {
26 26 struct snd_soc_component *component;
27 27 struct delayed_work jack_detect_work;
28 28 struct delayed_work button_press_work;
29 + struct delayed_work capture_pop_work;
29 30 struct snd_soc_jack *jack;
30 31 int irq;
31 32 /* The lock protects the situation that an irq is generated
@@ -628,6 +629,7 @@ static int es8326_mute(struct snd_soc_dai *dai, int mute, int direction)
628 629 regmap_update_bits(es8326->regmap, ES8326_HP_DRIVER_REF,
629 630 0x30, 0x00);
630 631 } else {
632 + cancel_delayed_work_sync(&es8326->capture_pop_work);
631 633 regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE,
632 634 0x0F, 0x0F);
633 635 if (es8326->version > ES8326_VERSION_B) {
@@ -666,8 +668,9 @@ static int es8326_mute(struct snd_soc_dai *dai, int mute, int direction)
666 668 regmap_update_bits(es8326->regmap, ES8326_ANA_MICBIAS, 0x70, 0x70);
667 669 regmap_update_bits(es8326->regmap, ES8326_VMIDSEL, 0x40, 0x00);
668 670 }
669 - regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE,
670 - 0x0F, 0x00);
671 +
672 + queue_delayed_work(system_dfl_wq, &es8326->capture_pop_work,
673 + msecs_to_jiffies(40));
671 674 }
672 675 }
673 676 return 0;
@@ -773,6 +776,15 @@ static void es8326_disable_micbias(struct snd_soc_component *component)
773 776 snd_soc_dapm_mutex_unlock(dapm);
774 777 }
775 778
779 + static void es8326_capture_pop_handler(struct work_struct *work)
780 + {
781 + struct es8326_priv *es8326 =
782 + container_of(work, struct es8326_priv, capture_pop_work.work);
783 +
784 + regmap_update_bits(es8326->regmap, ES8326_ADC_MUTE,
785 + 0x0F, 0x00);
786 + }
787 +
776 788 /*
777 789 * For button detection, set the following in soundcard
778 790 * snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
@@ -1140,6 +1152,7 @@ static int es8326_suspend(struct snd_soc_component *component)
1140 1152 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
1141 1153
1142 1154 cancel_delayed_work_sync(&es8326->jack_detect_work);
1155 + cancel_delayed_work_sync(&es8326->capture_pop_work);
1143 1156 es8326_disable_micbias(component);
1144 1157 es8326->calibrated = false;
1145 1158 regmap_write(es8326->regmap, ES8326_CLK_MUX, 0x2d);
@@ -1291,6 +1304,8 @@ static int es8326_i2c_probe(struct i2c_client *i2c)
1291 1304 es8326_jack_detect_handler);
1292 1305 INIT_DELAYED_WORK(&es8326->button_press_work,
1293 1306 es8326_jack_button_handler);
1307 + INIT_DELAYED_WORK(&es8326->capture_pop_work,
1308 + es8326_capture_pop_handler);
1294 1309 /* ES8316 is level-based while ES8326 is edge-based */
1295 1310 ret = devm_request_threaded_irq(&i2c->dev, es8326->irq, NULL, es8326_irq,
1296 1311 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
modified sound/soc/codecs/es8389.c
@@ -812,6 +812,23 @@ static int es8389_pcm_hw_free(struct snd_pcm_substream *substream,
812 812 return 0;
813 813 }
814 814
815 + static void es8389_standby(struct snd_soc_component *component)
816 + {
817 + struct es8389_private *es8389 = snd_soc_component_get_drvdata(component);
818 +
819 + regmap_update_bits(es8389->regmap, ES8389_ADC_HPF1, 0x0f, 0x04);
820 + regmap_update_bits(es8389->regmap, ES8389_ADC_HPF2, 0x0f, 0x04);
821 + regmap_write(es8389->regmap, ES8389_CSM_JUMP, 0xD4);
822 + usleep_range(70000, 72000);
823 + regmap_write(es8389->regmap, ES8389_ANA_CTL1, 0x59);
824 + regmap_write(es8389->regmap, ES8389_ADC_EN, 0x00);
825 + regmap_write(es8389->regmap, ES8389_CLK_OFF1, 0x00);
826 + regmap_write(es8389->regmap, ES8389_RESET, 0x3E);
827 + regmap_update_bits(es8389->regmap, ES8389_DAC_INV, 0x80, 0x80);
828 + usleep_range(8000, 8500);
829 + regmap_update_bits(es8389->regmap, ES8389_DAC_INV, 0x80, 0x00);
830 + }
831 +
815 832 static int es8389_set_bias_level(struct snd_soc_component *component,
816 833 enum snd_soc_bias_level level)
817 834 {
@@ -834,18 +851,7 @@ static int es8389_set_bias_level(struct snd_soc_component *component,
834 851 case SND_SOC_BIAS_PREPARE:
835 852 break;
836 853 case SND_SOC_BIAS_STANDBY:
837 - regmap_update_bits(es8389->regmap, ES8389_ADC_HPF1, 0x0f, 0x04);
838 - regmap_update_bits(es8389->regmap, ES8389_ADC_HPF2, 0x0f, 0x04);
839 - regmap_write(es8389->regmap, ES8389_CSM_JUMP, 0xD4);
840 - usleep_range(70000, 72000);
841 - regmap_write(es8389->regmap, ES8389_ANA_CTL1, 0x59);
842 - regmap_write(es8389->regmap, ES8389_ADC_EN, 0x00);
843 - regmap_write(es8389->regmap, ES8389_CLK_OFF1, 0x00);
844 - regmap_write(es8389->regmap, ES8389_RESET, 0x3E);
845 - regmap_update_bits(es8389->regmap, ES8389_DAC_INV, 0x80, 0x80);
846 - usleep_range(8000, 8500);
847 - regmap_update_bits(es8389->regmap, ES8389_DAC_INV, 0x80, 0x00);
848 -
854 + es8389_standby(component);
849 855 clk_disable_unprepare(es8389->mclk);
850 856 break;
851 857 case SND_SOC_BIAS_OFF:
@@ -1015,7 +1021,7 @@ static int es8389_suspend(struct snd_soc_component *component)
1015 1021 {
1016 1022 struct es8389_private *es8389 = snd_soc_component_get_drvdata(component);
1017 1023
1018 - es8389_set_bias_level(component, SND_SOC_BIAS_STANDBY);
1024 + es8389_standby(component);
1019 1025 regcache_cache_only(es8389->regmap, true);
1020 1026 regcache_mark_dirty(es8389->regmap);
1021 1027
@@ -1084,7 +1090,7 @@ static int es8389_probe(struct snd_soc_component *component)
1084 1090
1085 1091 es8389->hpf_freq = ES8389_HPF_DEFAULT;
1086 1092 es8389_init(component);
1087 - es8389_set_bias_level(component, SND_SOC_BIAS_STANDBY);
1093 + es8389_standby(component);
1088 1094
1089 1095 return 0;
1090 1096 }
modified sound/soc/codecs/mt6351.c
@@ -1478,6 +1478,7 @@ static const struct of_device_id mt6351_of_match[] = {
1478 1478 {.compatible = "mediatek,mt6351-sound",},
1479 1479 {}
1480 1480 };
1481 + MODULE_DEVICE_TABLE(of, mt6351_of_match);
1481 1482
1482 1483 static struct platform_driver mt6351_codec_driver = {
1483 1484 .driver = {
modified sound/soc/codecs/rt1318-sdw.c
@@ -16,6 +16,7 @@
16 16 #include <sound/pcm.h>
17 17 #include <sound/pcm_params.h>
18 18 #include <sound/soc-dapm.h>
19 + #include <sound/sdw.h>
19 20 #include <sound/initval.h>
20 21 #include "rt1318-sdw.h"
21 22
@@ -564,11 +565,10 @@ static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream,
564 565 struct snd_soc_component *component = dai->component;
565 566 struct rt1318_sdw_priv *rt1318 =
566 567 snd_soc_component_get_drvdata(component);
567 - struct sdw_stream_config stream_config;
568 + struct sdw_stream_config stream_config = {0};
568 569 struct sdw_port_config port_config;
569 - enum sdw_data_direction direction;
570 570 struct sdw_stream_runtime *sdw_stream;
571 - int retval, port, num_channels, ch_mask;
571 + int retval, port;
572 572 unsigned int sampling_rate;
573 573
574 574 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
@@ -582,23 +582,13 @@ static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream,
582 582
583 583 /* SoundWire specific configuration */
584 584 /* port 1 for playback */
585 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
586 - direction = SDW_DATA_DIR_RX;
585 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
587 586 port = 1;
588 - } else {
589 - direction = SDW_DATA_DIR_TX;
587 + else
590 588 port = 2;
591 - }
592 -
593 - num_channels = params_channels(params);
594 - ch_mask = (1 << num_channels) - 1;
595 589
596 - stream_config.frame_rate = params_rate(params);
597 - stream_config.ch_count = num_channels;
598 - stream_config.bps = snd_pcm_format_width(params_format(params));
599 - stream_config.direction = direction;
600 -
601 - port_config.ch_mask = ch_mask;
590 + /* SoundWire specific configuration */
591 + snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
602 592 port_config.num = port;
603 593
604 594 retval = sdw_stream_add_slave(rt1318->sdw_slave, &stream_config,
modified sound/soc/codecs/rt1320-sdw.c
@@ -3246,7 +3246,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream,
3246 3246 struct snd_soc_component *component = dai->component;
3247 3247 struct rt1320_sdw_priv *rt1320 =
3248 3248 snd_soc_component_get_drvdata(component);
3249 - struct sdw_stream_config stream_config;
3249 + struct sdw_stream_config stream_config = {0};
3250 3250 struct sdw_port_config port_config;
3251 3251 struct sdw_port_config dmic_port_config[2];
3252 3252 struct sdw_stream_runtime *sdw_stream;
modified sound/soc/codecs/rt712-sdca.c
@@ -23,6 +23,7 @@
23 23 #include <linux/soundwire/sdw_registers.h>
24 24 #include <linux/slab.h>
25 25 #include <sound/soc-dapm.h>
26 + #include <sound/sdw.h>
26 27 #include <sound/tlv.h>
27 28 #include "rt712-sdca.h"
28 29
@@ -1449,11 +1450,10 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1449 1450 {
1450 1451 struct snd_soc_component *component = dai->component;
1451 1452 struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component);
1452 - struct sdw_stream_config stream_config;
1453 + struct sdw_stream_config stream_config = {0};
1453 1454 struct sdw_port_config port_config;
1454 - enum sdw_data_direction direction;
1455 1455 struct sdw_stream_runtime *sdw_stream;
1456 - int retval, port, num_channels;
1456 + int retval, port;
1457 1457 unsigned int sampling_rate;
1458 1458
1459 1459 dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id);
@@ -1471,7 +1471,6 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1471 1471
1472 1472 /* SoundWire specific configuration */
1473 1473 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1474 - direction = SDW_DATA_DIR_RX;
1475 1474 if (dai->id == RT712_AIF1)
1476 1475 port = 1;
1477 1476 else if (dai->id == RT712_AIF2)
@@ -1479,7 +1478,6 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1479 1478 else
1480 1479 return -EINVAL;
1481 1480 } else {
1482 - direction = SDW_DATA_DIR_TX;
1483 1481 if (dai->id == RT712_AIF1)
1484 1482 port = 4;
1485 1483 else if (dai->id == RT712_AIF3)
@@ -1488,13 +1486,8 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1488 1486 return -EINVAL;
1489 1487 }
1490 1488
1491 - stream_config.frame_rate = params_rate(params);
1492 - stream_config.ch_count = params_channels(params);
1493 - stream_config.bps = snd_pcm_format_width(params_format(params));
1494 - stream_config.direction = direction;
1495 -
1496 - num_channels = params_channels(params);
1497 - port_config.ch_mask = GENMASK(num_channels - 1, 0);
1489 + /* SoundWire specific configuration */
1490 + snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
1498 1491 port_config.num = port;
1499 1492
1500 1493 retval = sdw_stream_add_slave(rt712->slave, &stream_config,
modified sound/soc/codecs/rt721-sdca.c
@@ -21,6 +21,7 @@
21 21 #include <linux/soundwire/sdw_registers.h>
22 22 #include <linux/slab.h>
23 23 #include <sound/soc-dapm.h>
24 + #include <sound/sdw.h>
24 25 #include <sound/tlv.h>
25 26
26 27 #include "rt721-sdca.h"
@@ -206,6 +207,7 @@ static void rt721_sdca_amp_preset(struct rt721_sdca_priv *rt721)
206 207 regmap_write(rt721->regmap,
207 208 SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_FU55,
208 209 RT721_SDCA_CTL_FU_MUTE, CH_02), 0x00);
210 + regmap_write(rt721->regmap, 0x2f5d, 0x1);
209 211 }
210 212
211 213 static void rt721_sdca_jack_preset(struct rt721_sdca_priv *rt721)
@@ -1268,11 +1270,10 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1268 1270 {
1269 1271 struct snd_soc_component *component = dai->component;
1270 1272 struct rt721_sdca_priv *rt721 = snd_soc_component_get_drvdata(component);
1271 - struct sdw_stream_config stream_config;
1273 + struct sdw_stream_config stream_config = {0};
1272 1274 struct sdw_port_config port_config;
1273 - enum sdw_data_direction direction;
1274 1275 struct sdw_stream_runtime *sdw_stream;
1275 - int retval, port, num_channels;
1276 + int retval, port;
1276 1277 unsigned int sampling_rate;
1277 1278
1278 1279 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
@@ -1291,7 +1292,6 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1291 1292 * RT721_AIF3 with port = 6 for digital-mic capture
1292 1293 */
1293 1294 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1294 - direction = SDW_DATA_DIR_RX;
1295 1295 if (dai->id == RT721_AIF1)
1296 1296 port = 1;
1297 1297 else if (dai->id == RT721_AIF2)
@@ -1299,7 +1299,6 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1299 1299 else
1300 1300 return -EINVAL;
1301 1301 } else {
1302 - direction = SDW_DATA_DIR_TX;
1303 1302 if (dai->id == RT721_AIF1)
1304 1303 port = 2;
1305 1304 else if (dai->id == RT721_AIF3)
@@ -1307,13 +1306,9 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1307 1306 else
1308 1307 return -EINVAL;
1309 1308 }
1310 - stream_config.frame_rate = params_rate(params);
1311 - stream_config.ch_count = params_channels(params);
1312 - stream_config.bps = snd_pcm_format_width(params_format(params));
1313 - stream_config.direction = direction;
1314 1309
1315 - num_channels = params_channels(params);
1316 - port_config.ch_mask = GENMASK(num_channels - 1, 0);
1310 + /* SoundWire specific configuration */
1311 + snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
1317 1312 port_config.num = port;
1318 1313
1319 1314 retval = sdw_stream_add_slave(rt721->slave, &stream_config,
modified sound/soc/codecs/rt722-sdca.c
@@ -24,6 +24,7 @@
24 24 #include <sound/pcm.h>
25 25 #include <sound/pcm_params.h>
26 26 #include <sound/soc-dapm.h>
27 + #include <sound/sdw.h>
27 28 #include <sound/tlv.h>
28 29
29 30 #include "rt722-sdca.h"
@@ -1442,11 +1443,10 @@ static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1442 1443 {
1443 1444 struct snd_soc_component *component = dai->component;
1444 1445 struct rt722_sdca_priv *rt722 = snd_soc_component_get_drvdata(component);
1445 - struct sdw_stream_config stream_config;
1446 + struct sdw_stream_config stream_config = {0};
1446 1447 struct sdw_port_config port_config;
1447 - enum sdw_data_direction direction;
1448 1448 struct sdw_stream_runtime *sdw_stream;
1449 - int retval, port, num_channels;
1449 + int retval, port;
1450 1450 unsigned int sampling_rate;
1451 1451
1452 1452 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
@@ -1465,7 +1465,6 @@ static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1465 1465 * RT722_AIF3 with port = 6 for digital-mic capture
1466 1466 */
1467 1467 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1468 - direction = SDW_DATA_DIR_RX;
1469 1468 if (dai->id == RT722_AIF1)
1470 1469 port = 1;
1471 1470 else if (dai->id == RT722_AIF2)
@@ -1473,7 +1472,6 @@ static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1473 1472 else
1474 1473 return -EINVAL;
1475 1474 } else {
1476 - direction = SDW_DATA_DIR_TX;
1477 1475 if (dai->id == RT722_AIF1)
1478 1476 port = 2;
1479 1477 else if (dai->id == RT722_AIF3)
@@ -1481,13 +1479,9 @@ static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
1481 1479 else
1482 1480 return -EINVAL;
1483 1481 }
1484 - stream_config.frame_rate = params_rate(params);
1485 - stream_config.ch_count = params_channels(params);
1486 - stream_config.bps = snd_pcm_format_width(params_format(params));
1487 - stream_config.direction = direction;
1488 1482
1489 - num_channels = params_channels(params);
1490 - port_config.ch_mask = GENMASK(num_channels - 1, 0);
1483 + /* SoundWire specific configuration */
1484 + snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
1491 1485 port_config.num = port;
1492 1486
1493 1487 retval = sdw_stream_add_slave(rt722->slave, &stream_config,
modified sound/soc/codecs/rt766-sdca.c
@@ -936,9 +936,8 @@ static int rt766_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
936 936 {
937 937 struct snd_soc_component *component = dai->component;
938 938 struct rt766_sdca_priv *rt766 = snd_soc_component_get_drvdata(component);
939 - struct sdw_stream_config stream_config;
939 + struct sdw_stream_config stream_config = {0};
940 940 struct sdw_port_config port_config;
941 - enum sdw_data_direction direction;
942 941 struct sdw_stream_runtime *sdw_stream;
943 942 unsigned int sampling_rate;
944 943 int retval, port;
@@ -957,7 +956,6 @@ static int rt766_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
957 956
958 957 /* SoundWire specific configuration */
959 958 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
960 - direction = SDW_DATA_DIR_RX;
961 959 if (dai->id == RT766_AIF1)
962 960 port = 3;
963 961 else if (dai->id == RT766_AIF2)
@@ -965,7 +963,6 @@ static int rt766_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
965 963 else
966 964 return -EINVAL;
967 965 } else {
968 - direction = SDW_DATA_DIR_TX;
969 966 if (dai->id == RT766_AIF1)
970 967 port = 12;
971 968 else if (dai->id == RT766_AIF3)
modified sound/soc/codecs/tas2783-sdw.c
@@ -1001,6 +1001,31 @@ static s32 tas_sdw_hw_params(struct snd_pcm_substream *substream,
1001 1001 /* SoundWire specific configuration */
1002 1002 snd_sdw_params_to_config(substream, params,
1003 1003 &stream_config, &port_config);
1004 +
1005 + /*
1006 + * The two mono amps each render one channel of the stereo stream:
1007 + * snd_sdw_params_to_config() hands every codec the full mask for
1008 + * playback, which leaves the pair in mirror mode and one channel
1009 + * unreproduced. Claim a single channel instead, keyed off the
1010 + * machine-assigned component prefix rather than the SoundWire
1011 + * address, which is board-specific: soc_sdw_ti_amp.c names the amps
1012 + * tas2783-1..4.
1013 + *
1014 + * Which side an amp then renders does not follow from the bit that
1015 + * is set - sdw_compute_slave_ports() advances the payload offset by
1016 + * the popcount of ch_mask and never looks at which bit it is - but
1017 + * from the amp's position in the codec order of the DAI link, which
1018 + * on these boards matches the prefix numbering.
1019 + */
1020 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
1021 + params_channels(params) == 2 && component->name_prefix) {
1022 + const char *idx_str = strrchr(component->name_prefix, '-');
1023 + unsigned long idx;
1024 +
1025 + if (idx_str && !kstrtoul(idx_str + 1, 10, &idx) && idx)
1026 + port_config.ch_mask = (idx & 1) ? BIT(0) : BIT(1);
1027 + }
1028 +
1004 1029 /* port 1 for playback */
1005 1030 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1006 1031 port_config.num = 1;
modified sound/soc/fsl/fsl_micfil.c
@@ -953,12 +953,17 @@ static int fsl_micfil_reparent_rootclk(struct fsl_micfil *micfil, unsigned int s
953 953 /* Get root clock */
954 954 clk = micfil->mclk;
955 955
956 - /* Disable clock first, for it was enabled by pm_runtime */
956 + /* Reparent root clock to the PLL matching this sample rate */
957 957 fsl_asoc_reparent_pll_clocks(dev, clk, micfil->pll8k_clk,
958 958 micfil->pll11k_clk, ratio);
959 - ret = clk_prepare_enable(clk);
960 - if (ret)
961 - return ret;
959 +
960 + /* Enable only once; hw_params can be called multiple times */
961 + if (!micfil->mclk_flag) {
962 + ret = clk_prepare_enable(clk);
963 + if (ret)
964 + return ret;
965 + micfil->mclk_flag = true;
966 + }
962 967
963 968 return 0;
964 969 }
@@ -991,8 +996,6 @@ static int fsl_micfil_hw_params(struct snd_pcm_substream *substream,
991 996 if (ret)
992 997 return ret;
993 998
994 - micfil->mclk_flag = true;
995 -
996 999 /* floor(K * CLKDIV) */
997 1000 switch (micfil->quality) {
998 1001 case QUALITY_HIGH:
@@ -1068,8 +1071,10 @@ static int fsl_micfil_hw_free(struct snd_pcm_substream *substream,
1068 1071 {
1069 1072 struct fsl_micfil *micfil = snd_soc_dai_get_drvdata(dai);
1070 1073
1071 - clk_disable_unprepare(micfil->mclk);
1072 - micfil->mclk_flag = false;
1074 + if (micfil->mclk_flag) {
1075 + clk_disable_unprepare(micfil->mclk);
1076 + micfil->mclk_flag = false;
1077 + }
1073 1078
1074 1079 return 0;
1075 1080 }
modified sound/soc/intel/atom/sst/sst_pci.c
@@ -167,6 +167,7 @@ static const struct pci_device_id intel_sst_ids[] = {
167 167 { PCI_DEVICE_DATA(INTEL, SST_TNG, 0) },
168 168 { 0, }
169 169 };
170 + MODULE_DEVICE_TABLE(pci, intel_sst_ids);
170 171
171 172 static struct pci_driver sst_driver = {
172 173 .name = SST_DRV_NAME,
modified sound/soc/intel/avs/boards/hdaudio.c
@@ -15,6 +15,22 @@
15 15 #include "../../../codecs/hda.h"
16 16 #include "../utils.h"
17 17
18 + static int avs_link_startup(struct snd_pcm_substream *substream)
19 + {
20 + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
21 + const struct snd_soc_pcm_stream *stream_info;
22 + struct snd_soc_dai *codec_dai;
23 +
24 + codec_dai = snd_soc_rtd_to_codec(rtd, 0);
25 + stream_info = snd_soc_dai_get_pcm_stream(codec_dai, substream->stream);
26 +
27 + return snd_pcm_hw_constraint_msbits(substream->runtime, 0, 0, stream_info->sig_bits);
28 + }
29 +
30 + static const struct snd_soc_ops avs_link_ops = {
31 + .startup = avs_link_startup,
32 + };
33 +
18 34 static int avs_create_dai_links(struct device *dev, struct hda_codec *codec, int pcm_count,
19 35 struct snd_soc_dai_link **links)
20 36 {
@@ -43,6 +59,7 @@ static int avs_create_dai_links(struct device *dev, struct hda_codec *codec, int
43 59 dl[i].platforms = platform;
44 60 dl[i].num_platforms = 1;
45 61 dl[i].ignore_pmdown_time = 1;
62 + dl[i].ops = &avs_link_ops;
46 63
47 64 dl[i].codecs = devm_kzalloc(dev, sizeof(*dl->codecs), GFP_KERNEL);
48 65 dl[i].cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
modified sound/soc/intel/avs/core.c
@@ -92,16 +92,28 @@ static int avs_hdac_bus_init_streams(struct hdac_bus *bus)
92 92 {
93 93 unsigned int cp_streams, pb_streams;
94 94 unsigned int gcap;
95 + int ret;
95 96
96 97 gcap = snd_hdac_chip_readw(bus, GCAP);
97 98 cp_streams = (gcap >> 8) & 0x0F;
98 99 pb_streams = (gcap >> 12) & 0x0F;
99 100 bus->num_streams = cp_streams + pb_streams;
100 101
101 - snd_hdac_ext_stream_init_all(bus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
102 - snd_hdac_ext_stream_init_all(bus, cp_streams, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
102 + ret = snd_hdac_ext_stream_init_all(bus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
103 + if (ret)
104 + return ret;
105 + ret = snd_hdac_ext_stream_init_all(bus, cp_streams, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
106 + if (ret)
107 + goto err;
108 +
109 + ret = snd_hdac_bus_alloc_stream_pages(bus);
110 + if (ret)
111 + goto err;
103 112
104 - return snd_hdac_bus_alloc_stream_pages(bus);
113 + return 0;
114 + err:
115 + snd_hdac_ext_stream_free_all(bus);
116 + return ret;
105 117 }
106 118
107 119 static bool avs_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset)
@@ -383,6 +395,18 @@ static int avs_bus_init(struct avs_dev *adev, struct pci_dev *pci, const struct
383 395 struct device *dev = &pci->dev;
384 396 int ret;
385 397
398 + ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL);
399 + if (!ipc)
400 + return -ENOMEM;
401 +
402 + adev->modcfg_buf = devm_kzalloc(dev, AVS_MAILBOX_SIZE, GFP_KERNEL);
403 + if (!adev->modcfg_buf)
404 + return -ENOMEM;
405 +
406 + ret = avs_ipc_init(ipc, dev);
407 + if (ret < 0)
408 + return ret;
409 +
386 410 ret = snd_hdac_ext_bus_init(&bus->core, dev, NULL, &soc_hda_ext_bus_ops);
387 411 if (ret < 0)
388 412 return ret;
@@ -394,17 +418,6 @@ static int avs_bus_init(struct avs_dev *adev, struct pci_dev *pci, const struct
394 418 bus->mixer_assigned = -1;
395 419 mutex_init(&bus->prepare_mutex);
396 420
397 - ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL);
398 - if (!ipc)
399 - return -ENOMEM;
400 - ret = avs_ipc_init(ipc, dev);
401 - if (ret < 0)
402 - return ret;
403 -
404 - adev->modcfg_buf = devm_kzalloc(dev, AVS_MAILBOX_SIZE, GFP_KERNEL);
405 - if (!adev->modcfg_buf)
406 - return -ENOMEM;
407 -
408 421 adev->dev = dev;
409 422 adev->spec = (const struct avs_spec *)id->driver_data;
410 423 adev->ipc = ipc;
@@ -456,13 +469,14 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
456 469
457 470 ret = pcim_request_all_regions(pci, "AVS HDAudio");
458 471 if (ret < 0)
459 - return ret;
472 + goto err_request_regions;
460 473
461 474 bus->addr = pci_resource_start(pci, 0);
462 475 bus->remap_addr = pci_ioremap_bar(pci, 0);
463 476 if (!bus->remap_addr) {
464 477 dev_err(bus->dev, "ioremap error\n");
465 - return -ENXIO;
478 + ret = -ENXIO;
479 + goto err_request_regions;
466 480 }
467 481
468 482 adev->dsp_ba = pci_ioremap_bar(pci, 4);
@@ -473,8 +487,13 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
473 487 }
474 488
475 489 snd_hdac_bus_parse_capabilities(bus);
476 - if (bus->mlcap)
477 - snd_hdac_ext_bus_get_ml_capabilities(bus);
490 + if (bus->mlcap) {
491 + ret = snd_hdac_ext_bus_get_ml_capabilities(bus);
492 + if (ret < 0) {
493 + dev_err(dev, "failed to get ml capabilities: %d\n", ret);
494 + goto err_ml_cap;
495 + }
496 + }
478 497
479 498 if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
480 499 dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
@@ -516,9 +535,13 @@ err_acquire_irq:
516 535 snd_hdac_bus_free_stream_pages(bus);
517 536 snd_hdac_ext_stream_free_all(bus);
518 537 err_init_streams:
538 + snd_hdac_ext_link_free_all(bus);
539 + err_ml_cap:
519 540 iounmap(adev->dsp_ba);
520 541 err_remap_bar4:
521 542 iounmap(bus->remap_addr);
543 + err_request_regions:
544 + snd_hdac_ext_bus_exit(bus);
522 545 return ret;
523 546 }
524 547
modified sound/soc/intel/avs/debugfs.c
@@ -9,6 +9,7 @@
9 9 #include <linux/cleanup.h>
10 10 #include <linux/debugfs.h>
11 11 #include <linux/kfifo.h>
12 + #include <linux/module.h>
12 13 #include <linux/wait.h>
13 14 #include <linux/sched/signal.h>
14 15 #include <linux/string_helpers.h>
@@ -236,15 +237,20 @@ static int strace_open(struct inode *inode, struct file *file)
236 237 if (!try_module_get(adev->dev->driver->owner))
237 238 return -ENODEV;
238 239
239 - if (kfifo_initialized(&adev->trace_fifo))
240 - return -EBUSY;
240 + if (kfifo_initialized(&adev->trace_fifo)) {
241 + ret = -EBUSY;
242 + goto err;
243 + }
241 244
242 245 ret = kfifo_alloc(&adev->trace_fifo, PAGE_SIZE, GFP_KERNEL);
243 246 if (ret < 0)
244 - return ret;
247 + goto err;
245 248
246 249 file->private_data = adev;
247 250 return 0;
251 + err:
252 + module_put(adev->dev->driver->owner);
253 + return ret;
248 254 }
249 255
250 256 static int strace_release(struct inode *inode, struct file *file)
modified sound/soc/intel/avs/ipc.c
@@ -172,7 +172,7 @@ static void avs_dsp_exception_caught(struct avs_dev *adev, union avs_notify_msg
172 172
173 173 /* Avoid deadlock as the exception may be the response to SET_D0IX. */
174 174 if (current_work() != &ipc->d0ix_work.work)
175 - cancel_delayed_work_sync(&ipc->d0ix_work);
175 + cancel_delayed_work(&ipc->d0ix_work);
176 176 ipc->in_d0ix = false;
177 177 /* Re-enabled on recovery completion. */
178 178 pm_runtime_disable(adev->dev);
@@ -395,11 +395,11 @@ static int avs_dsp_do_send_msg(struct avs_dev *adev, struct avs_ipc_msg *request
395 395 struct avs_ipc *ipc = adev->ipc;
396 396 int ret;
397 397
398 + guard(mutex)(&ipc->msg_mutex);
399 +
398 400 if (!ipc->ready)
399 401 return -EPERM;
400 402
401 - guard(mutex)(&ipc->msg_mutex);
402 -
403 403 spin_lock(&ipc->rx_lock);
404 404 avs_ipc_msg_init(ipc, reply);
405 405 avs_dsp_send_tx(adev, request, true);
modified sound/soc/intel/avs/path.c
@@ -836,15 +836,10 @@ static int avs_path_module_type_create(struct avs_dev *adev, struct avs_path_mod
836 836
837 837 static int avs_path_module_send_init_configs(struct avs_dev *adev, struct avs_path_module *mod)
838 838 {
839 - struct avs_soc_component *acomp;
840 -
841 - acomp = to_avs_soc_component(mod->template->owner->owner->owner->owner->comp);
842 -
843 - u32 num_ids = mod->template->num_config_ids;
844 - u32 *ids = mod->template->config_ids;
839 + struct avs_tplg_module *template = mod->template;
845 840
846 - for (int i = 0; i < num_ids; i++) {
847 - struct avs_tplg_init_config *config = &acomp->tplg->init_configs[ids[i]];
841 + for (int i = 0; i < template->num_init_configs; i++) {
842 + struct avs_tplg_init_config *config = template->init_configs[i];
848 843 size_t len = config->length;
849 844 void *data = config->data;
850 845 u32 param = config->param;
modified sound/soc/intel/avs/pcm.c
@@ -6,6 +6,7 @@
6 6 // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7 7 //
8 8
9 + #include <linux/cleanup.h>
9 10 #include <linux/debugfs.h>
10 11 #include <linux/device.h>
11 12 #include <sound/hda_register.h>
@@ -987,13 +988,25 @@ static int avs_component_load_libraries(struct avs_soc_component *acomp)
987 988 return ret;
988 989 }
989 990
991 + static int avs_request_topology(struct snd_soc_component *component, const char *name,
992 + const struct firmware **fw)
993 + {
994 + char *fullname __free(kfree) = NULL;
995 +
996 + fullname = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix, name);
997 + if (!fullname)
998 + return -ENOMEM;
999 +
1000 + return request_firmware(fw, fullname, component->dev);
1001 + }
1002 +
990 1003 static int avs_component_probe(struct snd_soc_component *component)
991 1004 {
992 1005 struct snd_soc_card *card = component->card;
993 1006 struct snd_soc_acpi_mach *mach;
994 1007 struct avs_soc_component *acomp;
1008 + const struct firmware *fw;
995 1009 struct avs_dev *adev;
996 - char *filename;
997 1010 int ret;
998 1011
999 1012 dev_dbg(card->dev, "probing %s card %s\n", component->name, card->name);
@@ -1009,13 +1022,7 @@ static int avs_component_probe(struct snd_soc_component *component)
1009 1022 goto finalize;
1010 1023
1011 1024 /* Load specified topology and create debugfs for it. */
1012 - filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
1013 - mach->tplg_filename);
1014 - if (!filename)
1015 - return -ENOMEM;
1016 -
1017 - ret = avs_load_topology(component, filename);
1018 - kfree(filename);
1025 + ret = avs_request_topology(component, mach->tplg_filename, &fw);
1019 1026 if (ret == -ENOENT && !strncmp(mach->tplg_filename, "hda-", 4)) {
1020 1027 unsigned int vendor_id;
1021 1028
@@ -1030,18 +1037,17 @@ static int avs_component_probe(struct snd_soc_component *component)
1030 1037 "hda-generic-tplg.bin");
1031 1038 if (!mach->tplg_filename)
1032 1039 return -ENOMEM;
1033 - filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
1034 - mach->tplg_filename);
1035 - if (!filename)
1036 - return -ENOMEM;
1037 1040
1038 1041 dev_info(card->dev, "trying to load fallback topology %s\n", mach->tplg_filename);
1039 - ret = avs_load_topology(component, filename);
1040 - kfree(filename);
1042 + ret = avs_request_topology(component, mach->tplg_filename, &fw);
1041 1043 }
1042 1044 if (ret < 0)
1043 1045 return ret;
1044 1046
1047 + ret = snd_soc_tplg_component_load(component, &avs_tplg_ops, fw);
1048 + if (ret)
1049 + return ret;
1050 +
1045 1051 ret = avs_component_load_libraries(acomp);
1046 1052 if (ret < 0) {
1047 1053 dev_err(card->dev, "libraries loading failed: %d\n", ret);
modified sound/soc/intel/avs/topology.c
@@ -350,6 +350,7 @@ AVS_DEFINE_PTR_PARSER(modcfg_base, struct avs_tplg_modcfg_base, modcfgs_base);
350 350 AVS_DEFINE_PTR_PARSER(modcfg_ext, struct avs_tplg_modcfg_ext, modcfgs_ext);
351 351 AVS_DEFINE_PTR_PARSER(pplcfg, struct avs_tplg_pplcfg, pplcfgs);
352 352 AVS_DEFINE_PTR_PARSER(binding, struct avs_tplg_binding, bindings);
353 + AVS_DEFINE_PTR_PARSER(init_config, struct avs_tplg_init_config, init_configs);
353 354 AVS_DEFINE_PTR_PARSER(nhlt_config, struct avs_tplg_nhlt_config, nhlt_configs);
354 355
355 356 static int
@@ -1198,7 +1199,7 @@ static const struct avs_tplg_token_parser module_parsers[] = {
1198 1199 {
1199 1200 .token = AVS_TKN_MOD_INIT_CONFIG_NUM_IDS_U32,
1200 1201 .type = SND_SOC_TPLG_TUPLE_TYPE_WORD,
1201 - .offset = offsetof(struct avs_tplg_module, num_config_ids),
1202 + .offset = offsetof(struct avs_tplg_module, num_init_configs),
1202 1203 .parse = avs_parse_byte_token,
1203 1204 },
1204 1205 {
@@ -1214,10 +1215,32 @@ static const struct avs_tplg_token_parser init_config_parsers[] = {
1214 1215 .token = AVS_TKN_MOD_INIT_CONFIG_ID_U32,
1215 1216 .type = SND_SOC_TPLG_TUPLE_TYPE_WORD,
1216 1217 .offset = 0,
1217 - .parse = avs_parse_word_token,
1218 + .parse = avs_parse_init_config_ptr,
1218 1219 },
1219 1220 };
1220 1221
1222 + static int avs_tplg_module_init_configs(struct snd_soc_component *comp,
1223 + struct avs_tplg_module *module,
1224 + struct snd_soc_tplg_vendor_array *tuples, u32 block_size)
1225 + {
1226 + struct avs_tplg_init_config **cfgs;
1227 + int ret;
1228 +
1229 + if (!module->num_init_configs)
1230 + return -EINVAL;
1231 +
1232 + cfgs = devm_kcalloc(comp->card->dev, module->num_init_configs, sizeof(*cfgs), GFP_KERNEL);
1233 + if (!cfgs)
1234 + return -ENOMEM;
1235 +
1236 + ret = parse_dictionary_entries(comp, tuples, block_size, cfgs, module->num_init_configs,
1237 + sizeof(*cfgs), AVS_TKN_MOD_INIT_CONFIG_ID_U32,
1238 + init_config_parsers, ARRAY_SIZE(init_config_parsers));
1239 + if (!ret)
1240 + module->init_configs = cfgs;
1241 + return ret;
1242 + }
1243 +
1221 1244 static struct avs_tplg_module *
1222 1245 avs_tplg_module_create(struct snd_soc_component *comp, struct avs_tplg_pipeline *owner,
1223 1246 struct snd_soc_tplg_vendor_array *tuples, u32 block_size)
@@ -1244,27 +1267,11 @@ avs_tplg_module_create(struct snd_soc_component *comp, struct avs_tplg_pipeline
1244 1267 block_size -= esize;
1245 1268 /* Parse trailing config ids if any. */
1246 1269 if (block_size) {
1247 - u32 num_config_ids = module->num_config_ids;
1248 - u32 *config_ids;
1249 -
1250 - if (!num_config_ids)
1251 - return ERR_PTR(-EINVAL);
1252 -
1253 - config_ids = devm_kcalloc(comp->card->dev, num_config_ids, sizeof(*config_ids),
1254 - GFP_KERNEL);
1255 - if (!config_ids)
1256 - return ERR_PTR(-ENOMEM);
1257 -
1258 1270 tuples = avs_tplg_vendor_array_at(tuples, esize);
1259 - ret = parse_dictionary_entries(comp, tuples, block_size,
1260 - config_ids, num_config_ids, sizeof(*config_ids),
1261 - AVS_TKN_MOD_INIT_CONFIG_ID_U32,
1262 - init_config_parsers,
1263 - ARRAY_SIZE(init_config_parsers));
1271 +
1272 + ret = avs_tplg_module_init_configs(comp, module, tuples, block_size);
1264 1273 if (ret)
1265 1274 return ERR_PTR(ret);
1266 -
1267 - module->config_ids = config_ids;
1268 1275 }
1269 1276
1270 1277 module->owner = owner;
@@ -2194,7 +2201,7 @@ avs_control_load(struct snd_soc_component *comp, int index, struct snd_kcontrol_
2194 2201 return 0;
2195 2202 }
2196 2203
2197 - static const struct snd_soc_tplg_ops avs_tplg_ops = {
2204 + const struct snd_soc_tplg_ops avs_tplg_ops = {
2198 2205 .io_ops = avs_control_ops,
2199 2206 .io_ops_count = ARRAY_SIZE(avs_control_ops),
2200 2207 .control_load = avs_control_load,
modified sound/soc/intel/avs/topology.h
@@ -221,8 +221,8 @@ struct avs_tplg_module {
221 221 u8 domain;
222 222 struct avs_tplg_modcfg_ext *cfg_ext;
223 223 u32 ctl_id;
224 - u32 num_config_ids;
225 - u32 *config_ids;
224 + u32 num_init_configs;
225 + struct avs_tplg_init_config **init_configs;
226 226 struct avs_tplg_nhlt_config *nhlt_config;
227 227
228 228 struct avs_tplg_pipeline *owner;
@@ -230,6 +230,7 @@ struct avs_tplg_module {
230 230 struct list_head node;
231 231 };
232 232
233 + extern const struct snd_soc_tplg_ops avs_tplg_ops;
233 234 struct avs_tplg *avs_tplg_new(struct snd_soc_component *comp);
234 235
235 236 int avs_load_topology(struct snd_soc_component *comp, const char *filename);
modified sound/soc/intel/boards/Kconfig
@@ -533,12 +533,14 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
533 533 select SND_SOC_CS35L56_SPI
534 534 select SND_SOC_CS35L56_SDW
535 535 select SND_SOC_ES9356
536 + imply SND_SOC_TAC5XX2_SDW
536 537 select SND_SOC_DMIC
537 538 select SND_SOC_INTEL_HDA_DSP_COMMON
538 539 imply SND_SOC_SDW_MOCKUP
539 540 help
540 541 Add support for Intel SoundWire-based platforms connected to
541 - MAX98373, RT700, RT711, RT1308 and RT715
542 + MAX98373, RT700, RT711, RT1308, RT715, TAC5XX2_SDW family (including
543 + TAC5572, TAC5682).
542 544 If unsure select "N".
543 545
544 546 endif
modified sound/soc/intel/boards/sof_rt5682.c
@@ -908,6 +908,14 @@ static const struct platform_device_id board_ids[] = {
908 908 SOF_SSP_PORT_BT_OFFLOAD(2) |
909 909 SOF_BT_OFFLOAD_PRESENT),
910 910 },
911 + {
912 + .name = "nvl_rt5682_def",
913 + .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
914 + SOF_SSP_PORT_CODEC(0) |
915 + SOF_SSP_PORT_AMP(1) |
916 + SOF_SSP_PORT_BT_OFFLOAD(2) |
917 + SOF_BT_OFFLOAD_PRESENT),
918 + },
911 919 {
912 920 .name = "ptl_rt5682_c1_h02",
913 921 .driver_data = (kernel_ulong_t)(SOF_RT5682_MCLK_EN |
modified sound/soc/intel/common/soc-acpi-intel-nvl-match.c
@@ -51,10 +51,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_nvl_machines[] = {
51 51 },
52 52 {
53 53 .comp_ids = &nvl_rt5682_rt5682s_hp,
54 - .drv_name = "sof_rt5682",
55 - .sof_tplg_filename = "sof-nvl-rt5682", /* the tplg suffix is added at run time */
56 - .tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
57 - SND_SOC_ACPI_TPLG_INTEL_SSP_MSB,
54 + .drv_name = "nvl_rt5682_def",
55 + .sof_tplg_filename = "sof-nvl", /* the tplg suffix is added at run time */
56 + .tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_AMP_NAME |
57 + SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME,
58 58 },
59 59 /* place amp/hdmi-in only boards in the end of table */
60 60 {
modified sound/soc/sprd/sprd-pcm-compress.c
@@ -17,7 +17,7 @@
17 17
18 18 /* Default values if userspace does not set */
19 19 #define SPRD_COMPR_MIN_FRAGMENT_SIZE SZ_8K
20 - #define SPRD_COMPR_MAX_FRAGMENT_SIZE SZ_128K
20 + #define SPRD_COMPR_MAX_FRAGMENT_SIZE SZ_32K
21 21 #define SPRD_COMPR_MIN_NUM_FRAGMENTS 4
22 22 #define SPRD_COMPR_MAX_NUM_FRAGMENTS 64
23 23
@@ -271,6 +271,19 @@ static int sprd_platform_compr_set_params(struct snd_soc_component *component,
271 271 struct sprd_compr_params compr_params = { };
272 272 int ret;
273 273
274 + /*
275 + * The stage 0 IRAM buffer and the stage 1 DDR buffer are allocated
276 + * with fixed sizes at open time, so the requested fragment size and
277 + * fragments must fit into them, otherwise sprd_platform_compr_copy()
278 + * would overflow the buffers. Note the compress core only checks the
279 + * fragment size and fragments against an u32 overflow, not against
280 + * the buffer sizes advertised by get_caps.
281 + */
282 + if (params->buffer.fragment_size > SPRD_COMPR_IRAM_BUF_SIZE ||
283 + (u64)params->buffer.fragment_size * params->buffer.fragments >
284 + SPRD_COMPR_AREA_BUF_SIZE)
285 + return -EINVAL;
286 +
274 287 /*
275 288 * Configure the DMA engine 2-stage transfer mode. Channel 1 set as the
276 289 * destination channel, and channel 0 set as the source channel, that
modified sound/soc/sti/uniperif_reader.c
@@ -416,6 +416,8 @@ int uni_reader_init(struct platform_device *pdev,
416 416 else
417 417 reader->hw = &uni_reader_pcm_hw;
418 418
419 + spin_lock_init(&reader->irq_lock);
420 +
419 421 ret = devm_request_irq(&pdev->dev, reader->irq,
420 422 uni_reader_irq_handler, IRQF_SHARED,
421 423 dev_name(&pdev->dev), reader);
@@ -424,8 +426,6 @@ int uni_reader_init(struct platform_device *pdev,
424 426 return -EBUSY;
425 427 }
426 428
427 - spin_lock_init(&reader->irq_lock);
428 -
429 429 return 0;
430 430 }
431 431 EXPORT_SYMBOL_GPL(uni_reader_init);
modified sound/soc/ux500/ux500_msp_dai.c
@@ -14,7 +14,7 @@
14 14 #include <linux/clk.h>
15 15 #include <linux/of.h>
16 16 #include <linux/regulator/consumer.h>
17 - #include <linux/mfd/db8500-prcmu.h>
17 + #include <linux/reset.h>
18 18
19 19 #include <sound/soc.h>
20 20 #include <sound/soc-dai.h>
@@ -34,8 +34,10 @@ static int setup_pcm_multichan(struct snd_soc_dai *dai,
34 34 if (drvdata->slots > 1) {
35 35 msp_config->multichannel_configured = 1;
36 36
37 - multi->tx_multichannel_enable = true;
38 - multi->rx_multichannel_enable = true;
37 + multi->tx_multichannel_enable =
38 + msp_config->direction & MSP_DIR_TX;
39 + multi->rx_multichannel_enable =
40 + msp_config->direction & MSP_DIR_RX;
39 41 multi->rx_comparison_enable_mode = MSP_COMPARISON_DISABLED;
40 42
41 43 multi->tx_channel_0_enable = drvdata->tx_mask;
@@ -57,72 +59,21 @@ static int setup_pcm_multichan(struct snd_soc_dai *dai,
57 59 return 0;
58 60 }
59 61
60 - static int setup_frameper(struct snd_soc_dai *dai, unsigned int rate,
61 - struct msp_protdesc *prot_desc)
62 + static void setup_frameper(struct snd_soc_dai *dai,
63 + struct msp_protdesc *prot_desc)
62 64 {
63 65 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
64 66
65 - switch (drvdata->slots) {
66 - case 1:
67 - switch (rate) {
68 - case 8000:
69 - prot_desc->frame_period =
70 - FRAME_PER_SINGLE_SLOT_8_KHZ;
71 - break;
72 -
73 - case 16000:
74 - prot_desc->frame_period =
75 - FRAME_PER_SINGLE_SLOT_16_KHZ;
76 - break;
77 -
78 - case 44100:
79 - prot_desc->frame_period =
80 - FRAME_PER_SINGLE_SLOT_44_1_KHZ;
81 - break;
82 -
83 - case 48000:
84 - prot_desc->frame_period =
85 - FRAME_PER_SINGLE_SLOT_48_KHZ;
86 - break;
87 -
88 - default:
89 - dev_err(dai->dev,
90 - "%s: Error: Unsupported sample-rate (freq = %d)!\n",
91 - __func__, rate);
92 - return -EINVAL;
93 - }
94 - break;
95 -
96 - case 2:
97 - prot_desc->frame_period = FRAME_PER_2_SLOTS;
98 - break;
99 -
100 - case 8:
101 - prot_desc->frame_period = FRAME_PER_8_SLOTS;
102 - break;
103 -
104 - case 16:
105 - prot_desc->frame_period = FRAME_PER_16_SLOTS;
106 - break;
107 - default:
108 - dev_err(dai->dev,
109 - "%s: Error: Unsupported slot-count (slots = %d)!\n",
110 - __func__, drvdata->slots);
111 - return -EINVAL;
112 - }
113 -
114 - prot_desc->clocks_per_frame =
115 - prot_desc->frame_period+1;
67 + prot_desc->clocks_per_frame = drvdata->slots * drvdata->slot_width;
68 + prot_desc->frame_period = prot_desc->clocks_per_frame - 1;
116 69
117 70 dev_dbg(dai->dev, "%s: Clocks per frame: %u\n",
118 71 __func__,
119 72 prot_desc->clocks_per_frame);
120 -
121 - return 0;
122 73 }
123 74
124 - static int setup_pcm_framing(struct snd_soc_dai *dai, unsigned int rate,
125 - struct msp_protdesc *prot_desc)
75 + static int setup_pcm_framing(struct snd_soc_dai *dai,
76 + struct msp_protdesc *prot_desc)
126 77 {
127 78 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
128 79
@@ -163,7 +114,9 @@ static int setup_pcm_framing(struct snd_soc_dai *dai, unsigned int rate,
163 114 prot_desc->tx_elem_len_2 = MSP_ELEM_LEN_16;
164 115 prot_desc->rx_elem_len_2 = MSP_ELEM_LEN_16;
165 116
166 - return setup_frameper(dai, rate, prot_desc);
117 + setup_frameper(dai, prot_desc);
118 +
119 + return 0;
167 120 }
168 121
169 122 static int setup_clocking(struct snd_soc_dai *dai,
@@ -177,7 +130,16 @@ static int setup_clocking(struct snd_soc_dai *dai,
177 130 case SND_SOC_DAIFMT_NB_IF:
178 131 msp_config->tx_fsync_pol ^= 1 << TFSPOL_SHIFT;
179 132 msp_config->rx_fsync_pol ^= 1 << RFSPOL_SHIFT;
133 + break;
134 +
135 + case SND_SOC_DAIFMT_IB_NF:
136 + msp_config->bclk_inverted = true;
137 + break;
180 138
139 + case SND_SOC_DAIFMT_IB_IF:
140 + msp_config->bclk_inverted = true;
141 + msp_config->tx_fsync_pol ^= 1 << TFSPOL_SHIFT;
142 + msp_config->rx_fsync_pol ^= 1 << RFSPOL_SHIFT;
181 143 break;
182 144
183 145 default:
@@ -192,6 +154,7 @@ static int setup_clocking(struct snd_soc_dai *dai,
192 154 case SND_SOC_DAIFMT_BC_FC:
193 155 dev_dbg(dai->dev, "%s: Codec is master.\n", __func__);
194 156
157 + msp_config->clock_provider = false;
195 158 msp_config->iodelay = 0x20;
196 159 msp_config->rx_fsync_sel = 0;
197 160 msp_config->tx_fsync_sel = 1 << TFSSEL_SHIFT;
@@ -204,6 +167,7 @@ static int setup_clocking(struct snd_soc_dai *dai,
204 167 case SND_SOC_DAIFMT_BP_FP:
205 168 dev_dbg(dai->dev, "%s: Codec is slave.\n", __func__);
206 169
170 + msp_config->clock_provider = true;
207 171 msp_config->tx_clk_sel = TX_CLK_SEL_SRG;
208 172 msp_config->tx_fsync_sel = TX_SYNC_SRG_PROG;
209 173 msp_config->rx_clk_sel = RX_CLK_SEL_SRG;
@@ -362,7 +326,7 @@ static int setup_msp_config(struct snd_pcm_substream *substream,
362 326 if (ret < 0)
363 327 return ret;
364 328
365 - ret = setup_pcm_framing(dai, runtime->rate, prot_desc);
329 + ret = setup_pcm_framing(dai, prot_desc);
366 330 if (ret < 0)
367 331 return ret;
368 332
@@ -424,21 +388,21 @@ static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream,
424 388 int ret;
425 389 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
426 390 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
391 + unsigned int configured = is_playback ? PLAYBACK_CONFIGURED :
392 + CAPTURE_CONFIGURED;
393 + unsigned int dir = is_playback ? MSP_DIR_TX : MSP_DIR_RX;
427 394
428 395 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id,
429 396 snd_pcm_stream_str(substream));
430 397
431 - if (drvdata->vape_opp_constraint == 1) {
432 - prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
433 - "ux500_msp_i2s", 50);
434 - drvdata->vape_opp_constraint = 0;
435 - }
436 -
437 - if (ux500_msp_i2s_close(drvdata->msp,
438 - is_playback ? MSP_DIR_TX : MSP_DIR_RX)) {
439 - dev_err(dai->dev,
440 - "%s: Error: MSP %d (%s): Unable to close i2s.\n",
441 - __func__, dai->id, snd_pcm_stream_str(substream));
398 + if (drvdata->configured & configured) {
399 + if (ux500_msp_i2s_close(drvdata->msp, dir)) {
400 + dev_err(dai->dev,
401 + "%s: Error: MSP %d (%s): Unable to close i2s.\n",
402 + __func__, dai->id,
403 + snd_pcm_stream_str(substream));
404 + }
405 + drvdata->configured &= ~configured;
442 406 }
443 407
444 408 /* Disable and unprepare clocks */
@@ -456,15 +420,23 @@ static void ux500_msp_dai_shutdown(struct snd_pcm_substream *substream,
456 420 static int ux500_msp_dai_prepare(struct snd_pcm_substream *substream,
457 421 struct snd_soc_dai *dai)
458 422 {
459 - int ret = 0;
460 423 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
461 424 struct snd_pcm_runtime *runtime = substream->runtime;
462 425 struct ux500_msp_config msp_config;
426 + bool is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
427 + unsigned int configured = is_playback ? PLAYBACK_CONFIGURED :
428 + CAPTURE_CONFIGURED;
429 + int ret;
463 430
464 431 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter (rate = %d).\n", __func__,
465 432 dai->id, snd_pcm_stream_str(substream), runtime->rate);
466 433
467 - setup_msp_config(substream, dai, &msp_config);
434 + if (drvdata->configured & configured)
435 + return 0;
436 +
437 + ret = setup_msp_config(substream, dai, &msp_config);
438 + if (ret)
439 + return ret;
468 440
469 441 ret = ux500_msp_i2s_open(drvdata->msp, &msp_config);
470 442 if (ret < 0) {
@@ -473,22 +445,9 @@ static int ux500_msp_dai_prepare(struct snd_pcm_substream *substream,
473 445 return ret;
474 446 }
475 447
476 - /* Set OPP-level */
477 - if ((drvdata->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) &&
478 - (drvdata->msp->f_bitclk > 19200000)) {
479 - /* If the bit-clock is higher than 19.2MHz, Vape should be
480 - * run in 100% OPP. Only when bit-clock is used (MSP master)
481 - */
482 - prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
483 - "ux500-msp-i2s", 100);
484 - drvdata->vape_opp_constraint = 1;
485 - } else {
486 - prcmu_qos_update_requirement(PRCMU_QOS_APE_OPP,
487 - "ux500-msp-i2s", 50);
488 - drvdata->vape_opp_constraint = 0;
489 - }
448 + drvdata->configured |= configured;
490 449
491 - return ret;
450 + return 0;
492 451 }
493 452
494 453 static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream,
@@ -496,7 +455,6 @@ static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream,
496 455 struct snd_soc_dai *dai)
497 456 {
498 457 unsigned int mask, slots_active;
499 - struct snd_pcm_runtime *runtime = substream->runtime;
500 458 struct ux500_msp_i2s_drvdata *drvdata = dev_get_drvdata(dai->dev);
501 459
502 460 dev_dbg(dai->dev, "%s: MSP %d (%s): Enter.\n",
@@ -504,9 +462,8 @@ static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream,
504 462
505 463 switch (drvdata->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
506 464 case SND_SOC_DAIFMT_I2S:
507 - snd_pcm_hw_constraint_minmax(runtime,
508 - SNDRV_PCM_HW_PARAM_CHANNELS,
509 - 1, 2);
465 + if (params_channels(params) < 1 || params_channels(params) > 2)
466 + return -EINVAL;
510 467 break;
511 468
512 469 case SND_SOC_DAIFMT_DSP_B:
@@ -518,9 +475,8 @@ static int ux500_msp_dai_hw_params(struct snd_pcm_substream *substream,
518 475 slots_active = hweight32(mask);
519 476 dev_dbg(dai->dev, "TDM-slots active: %d", slots_active);
520 477
521 - snd_pcm_hw_constraint_single(runtime,
522 - SNDRV_PCM_HW_PARAM_CHANNELS,
523 - slots_active);
478 + if (!slots_active || params_channels(params) != slots_active)
479 + return -EINVAL;
524 480 break;
525 481
526 482 default:
@@ -553,20 +509,21 @@ static int ux500_msp_dai_set_dai_fmt(struct snd_soc_dai *dai,
553 509 default:
554 510 dev_err(dai->dev,
555 511 "%s: Error: Unsupported protocol/master (fmt = 0x%x)!\n",
556 - __func__, drvdata->fmt);
512 + __func__, fmt);
557 513 return -EINVAL;
558 514 }
559 515
560 516 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
561 517 case SND_SOC_DAIFMT_NB_NF:
562 518 case SND_SOC_DAIFMT_NB_IF:
519 + case SND_SOC_DAIFMT_IB_NF:
563 520 case SND_SOC_DAIFMT_IB_IF:
564 521 break;
565 522
566 523 default:
567 524 dev_err(dai->dev,
568 525 "%s: Error: Unsupported inversion (fmt = 0x%x)!\n",
569 - __func__, drvdata->fmt);
526 + __func__, fmt);
570 527 return -EINVAL;
571 528 }
572 529
@@ -600,17 +557,23 @@ static int ux500_msp_dai_set_tdm_slot(struct snd_soc_dai *dai,
600 557 __func__, slots);
601 558 return -EINVAL;
602 559 }
603 - drvdata->slots = slots;
604 560
605 - if (!(slot_width == 16)) {
561 + if (slot_width != 16) {
606 562 dev_err(dai->dev, "%s: Error: Unsupported slot-width (%d)!\n",
607 563 __func__, slot_width);
608 564 return -EINVAL;
609 565 }
610 - drvdata->slot_width = slot_width;
611 566
612 - drvdata->tx_mask = tx_mask & cap;
613 - drvdata->rx_mask = rx_mask & cap;
567 + if ((tx_mask | rx_mask) & ~cap) {
568 + dev_err(dai->dev, "%s: Slot mask exceeds %d slots\n",
569 + __func__, slots);
570 + return -EINVAL;
571 + }
572 +
573 + drvdata->slots = slots;
574 + drvdata->slot_width = slot_width;
575 + drvdata->tx_mask = tx_mask;
576 + drvdata->rx_mask = rx_mask;
614 577
615 578 return 0;
616 579 }
@@ -716,6 +679,7 @@ static const struct snd_soc_component_driver ux500_msp_component = {
716 679 static int ux500_msp_drv_probe(struct platform_device *pdev)
717 680 {
718 681 struct ux500_msp_i2s_drvdata *drvdata;
682 + struct reset_control *reset;
719 683 int ret = 0;
720 684
721 685 drvdata = devm_kzalloc(&pdev->dev,
@@ -729,7 +693,6 @@ static int ux500_msp_drv_probe(struct platform_device *pdev)
729 693 drvdata->tx_mask = 0x01;
730 694 drvdata->rx_mask = 0x01;
731 695 drvdata->slot_width = 16;
732 - drvdata->master_clk = MSP_INPUT_FREQ_APB;
733 696
734 697 drvdata->reg_vape = devm_regulator_get(&pdev->dev, "v-ape");
735 698 if (IS_ERR(drvdata->reg_vape)) {
@@ -739,8 +702,6 @@ static int ux500_msp_drv_probe(struct platform_device *pdev)
739 702 __func__, ret);
740 703 return ret;
741 704 }
742 - prcmu_qos_add_requirement(PRCMU_QOS_APE_OPP, (char *)pdev->name, 50);
743 -
744 705 drvdata->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
745 706 if (IS_ERR(drvdata->pclk)) {
746 707 ret = PTR_ERR(drvdata->pclk);
@@ -758,9 +719,19 @@ static int ux500_msp_drv_probe(struct platform_device *pdev)
758 719 __func__, ret);
759 720 return ret;
760 721 }
722 + drvdata->master_clk = clk_get_rate(drvdata->clk);
723 + if (!drvdata->master_clk) {
724 + dev_err(&pdev->dev, "MSP clock has no rate\n");
725 + return -EINVAL;
726 + }
727 +
728 + reset = devm_reset_control_get_exclusive_deasserted(&pdev->dev, NULL);
729 + if (IS_ERR(reset))
730 + return dev_err_probe(&pdev->dev, PTR_ERR(reset),
731 + "Failed to deassert MSP reset\n");
761 732
762 733 ret = ux500_msp_i2s_init_msp(pdev, &drvdata->msp);
763 - if (!drvdata->msp) {
734 + if (ret) {
764 735 dev_err(&pdev->dev,
765 736 "%s: ERROR: Failed to init MSP-struct (%d)!",
766 737 __func__, ret);
@@ -799,8 +770,6 @@ static void ux500_msp_drv_remove(struct platform_device *pdev)
799 770
800 771 snd_soc_unregister_component(&pdev->dev);
801 772
802 - prcmu_qos_remove_requirement(PRCMU_QOS_APE_OPP, "ux500_msp_i2s");
803 -
804 773 ux500_msp_i2s_cleanup_msp(pdev, drvdata->msp);
805 774 }
806 775
modified sound/soc/ux500/ux500_msp_dai.h
@@ -22,17 +22,6 @@
22 22
23 23 #define UX500_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
24 24
25 - #define FRAME_PER_SINGLE_SLOT_8_KHZ 31
26 - #define FRAME_PER_SINGLE_SLOT_16_KHZ 124
27 - #define FRAME_PER_SINGLE_SLOT_44_1_KHZ 63
28 - #define FRAME_PER_SINGLE_SLOT_48_KHZ 49
29 - #define FRAME_PER_2_SLOTS 31
30 - #define FRAME_PER_8_SLOTS 138
31 - #define FRAME_PER_16_SLOTS 277
32 -
33 - #define UX500_MSP_INTERNAL_CLOCK_FREQ 40000000
34 - #define UX500_MSP1_INTERNAL_CLOCK_FREQ UX500_MSP_INTERNAL_CLOCK_FREQ
35 -
36 25 #define UX500_MSP_MIN_CHANNELS 1
37 26 #define UX500_MSP_MAX_CHANNELS 8
38 27
@@ -47,6 +36,7 @@ struct ux500_msp_i2s_drvdata {
47 36 struct ux500_msp *msp;
48 37 struct regulator *reg_vape;
49 38 unsigned int fmt;
39 + unsigned int configured;
50 40 unsigned int tx_mask;
51 41 unsigned int rx_mask;
52 42 int slots;
@@ -57,8 +47,6 @@ struct ux500_msp_i2s_drvdata {
57 47 struct clk *clk;
58 48 struct clk *pclk;
59 49
60 - /* Regulators */
61 - int vape_opp_constraint;
62 50 };
63 51
64 52 int ux500_msp_dai_set_data_delay(struct snd_soc_dai *dai, int delay);
modified sound/soc/ux500/ux500_msp_i2s.c
@@ -201,10 +201,12 @@ static int configure_protocol(struct ux500_msp *msp,
201 201
202 202 /* The code below should not be separated. */
203 203 temp_reg = readl(msp->registers + MSP_GCR) & ~TX_CLK_POL_RISING;
204 - temp_reg |= MSP_TX_CLKPOL_BIT(~protdesc->tx_clk_pol);
204 + temp_reg |= MSP_TX_CLKPOL_BIT(!protdesc->tx_clk_pol ^
205 + config->bclk_inverted);
205 206 writel(temp_reg, msp->registers + MSP_GCR);
206 207 temp_reg = readl(msp->registers + MSP_GCR) & ~RX_CLK_POL_RISING;
207 - temp_reg |= MSP_RX_CLKPOL_BIT(protdesc->rx_clk_pol);
208 + temp_reg |= MSP_RX_CLKPOL_BIT(protdesc->rx_clk_pol ^
209 + config->bclk_inverted);
208 210 writel(temp_reg, msp->registers + MSP_GCR);
209 211
210 212 return 0;
@@ -212,35 +214,20 @@ static int configure_protocol(struct ux500_msp *msp,
212 214
213 215 static int setup_bitclk(struct ux500_msp *msp, struct ux500_msp_config *config)
214 216 {
217 + struct msp_protdesc *protdesc;
218 + u64 desired_bitclk;
219 + unsigned int bitclk;
215 220 u32 reg_val_GCR;
216 - u32 frame_per = 0;
217 - u32 sck_div = 0;
218 - u32 frame_width = 0;
219 - u32 temp_reg = 0;
220 - struct msp_protdesc *protdesc = NULL;
221 + u32 sck_div;
222 + u32 temp_reg;
221 223
222 224 reg_val_GCR = readl(msp->registers + MSP_GCR);
223 225 writel(reg_val_GCR & ~SRG_ENABLE, msp->registers + MSP_GCR);
224 226
225 - if (config->default_protdesc)
226 - protdesc =
227 - (struct msp_protdesc *)&prot_descs[config->protocol];
228 - else
229 - protdesc = (struct msp_protdesc *)&config->protdesc;
230 -
231 227 switch (config->protocol) {
232 228 case MSP_PCM_PROTOCOL:
233 229 case MSP_PCM_COMPAND_PROTOCOL:
234 - frame_width = protdesc->frame_width;
235 - sck_div = config->f_inputclk / (config->frame_freq *
236 - (protdesc->clocks_per_frame));
237 - frame_per = protdesc->frame_period;
238 - break;
239 230 case MSP_I2S_PROTOCOL:
240 - frame_width = protdesc->frame_width;
241 - sck_div = config->f_inputclk / (config->frame_freq *
242 - (protdesc->clocks_per_frame));
243 - frame_per = protdesc->frame_period;
244 231 break;
245 232 default:
246 233 dev_err(msp->dev, "%s: ERROR: Unknown protocol (%d)!\n",
@@ -249,12 +236,35 @@ static int setup_bitclk(struct ux500_msp *msp, struct ux500_msp_config *config)
249 236 return -EINVAL;
250 237 }
251 238
239 + if (config->default_protdesc)
240 + protdesc = (struct msp_protdesc *)&prot_descs[config->protocol];
241 + else
242 + protdesc = &config->protdesc;
243 +
244 + if (!config->frame_freq || !protdesc->clocks_per_frame)
245 + return -EINVAL;
246 +
247 + desired_bitclk = (u64)config->frame_freq * protdesc->clocks_per_frame;
248 + if (desired_bitclk > config->f_inputclk)
249 + return -EINVAL;
250 + bitclk = desired_bitclk;
251 + if (config->f_inputclk % bitclk) {
252 + dev_err(msp->dev,
253 + "Input clock %u cannot generate bit clock %u\n",
254 + config->f_inputclk, bitclk);
255 + return -EINVAL;
256 + }
257 +
258 + sck_div = config->f_inputclk / bitclk;
259 + if (!sck_div || sck_div > SCK_DIV_MASK + 1)
260 + return -EINVAL;
261 +
252 262 temp_reg = (sck_div - 1) & SCK_DIV_MASK;
253 - temp_reg |= FRAME_WIDTH_BITS(frame_width);
254 - temp_reg |= FRAME_PERIOD_BITS(frame_per);
263 + temp_reg |= FRAME_WIDTH_BITS(protdesc->frame_width);
264 + temp_reg |= FRAME_PERIOD_BITS(protdesc->frame_period);
255 265 writel(temp_reg, msp->registers + MSP_SRG);
256 266
257 - msp->f_bitclk = (config->f_inputclk)/(sck_div + 1);
267 + msp->f_bitclk = config->f_inputclk / sck_div;
258 268
259 269 /* Enable bit-clock */
260 270 udelay(100);
@@ -344,20 +354,27 @@ static int configure_multichannel(struct ux500_msp *msp,
344 354 return 0;
345 355 }
346 356
347 - static int enable_msp(struct ux500_msp *msp, struct ux500_msp_config *config)
357 + static int enable_msp(struct ux500_msp *msp, struct ux500_msp_config *config,
358 + bool first)
348 359 {
349 - int status = 0;
350 - u32 reg_val_DMACR, reg_val_GCR;
360 + int status;
361 + u32 reg_val_DMACR;
351 362
352 363 /* Configure msp with protocol dependent settings */
353 - configure_protocol(msp, config);
354 - setup_bitclk(msp, config);
364 + status = configure_protocol(msp, config);
365 + if (status)
366 + return status;
367 +
368 + if (first && config->clock_provider) {
369 + status = setup_bitclk(msp, config);
370 + if (status)
371 + return status;
372 + }
373 +
355 374 if (config->multichannel_configured == 1) {
356 375 status = configure_multichannel(msp, config);
357 376 if (status)
358 - dev_warn(msp->dev,
359 - "%s: WARN: configure_multichannel failed (%d)!\n",
360 - __func__, status);
377 + return status;
361 378 }
362 379
363 380 reg_val_DMACR = readl(msp->registers + MSP_DMACR);
@@ -369,11 +386,7 @@ static int enable_msp(struct ux500_msp *msp, struct ux500_msp_config *config)
369 386
370 387 writel(config->iodelay, msp->registers + MSP_IODLY);
371 388
372 - /* Enable frame generation logic */
373 - reg_val_GCR = readl(msp->registers + MSP_GCR);
374 - writel(reg_val_GCR | FRAME_GEN_ENABLE, msp->registers + MSP_GCR);
375 -
376 - return status;
389 + return 0;
377 390 }
378 391
379 392 static void flush_fifo_rx(struct ux500_msp *msp)
@@ -411,12 +424,37 @@ static void flush_fifo_tx(struct ux500_msp *msp)
411 424 writel(reg_val_GCR, msp->registers + MSP_GCR);
412 425 }
413 426
427 + static bool ux500_msp_config_compatible(struct ux500_msp *msp,
428 + struct ux500_msp_config *config)
429 + {
430 + struct ux500_msp_config *active = &msp->config;
431 +
432 + return active->f_inputclk == config->f_inputclk &&
433 + active->tx_clk_sel == config->tx_clk_sel &&
434 + active->rx_clk_sel == config->rx_clk_sel &&
435 + active->srg_clk_sel == config->srg_clk_sel &&
436 + active->rx_fsync_pol == config->rx_fsync_pol &&
437 + active->tx_fsync_pol == config->tx_fsync_pol &&
438 + active->rx_fsync_sel == config->rx_fsync_sel &&
439 + active->tx_fsync_sel == config->tx_fsync_sel &&
440 + active->default_protdesc == config->default_protdesc &&
441 + active->protocol == config->protocol &&
442 + active->frame_freq == config->frame_freq &&
443 + active->data_size == config->data_size &&
444 + active->def_elem_len == config->def_elem_len &&
445 + active->clock_provider == config->clock_provider &&
446 + active->bclk_inverted == config->bclk_inverted &&
447 + !memcmp(&active->protdesc, &config->protdesc,
448 + sizeof(active->protdesc));
449 + }
450 +
414 451 int ux500_msp_i2s_open(struct ux500_msp *msp,
415 452 struct ux500_msp_config *config)
416 453 {
417 454 u32 old_reg, new_reg, mask;
418 455 int res;
419 456 unsigned int tx_sel, rx_sel, tx_busy, rx_busy;
457 + bool first;
420 458
421 459 if (in_interrupt()) {
422 460 dev_err(msp->dev,
@@ -444,40 +482,68 @@ int ux500_msp_i2s_open(struct ux500_msp *msp,
444 482 return -EBUSY;
445 483 }
446 484
447 - msp->dir_busy |= (tx_sel ? MSP_DIR_TX : 0) | (rx_sel ? MSP_DIR_RX : 0);
448 -
449 - /* First do the global config register */
450 - mask = RX_CLK_SEL_MASK | TX_CLK_SEL_MASK | RX_FSYNC_MASK |
451 - TX_FSYNC_MASK | RX_SYNC_SEL_MASK | TX_SYNC_SEL_MASK |
452 - RX_FIFO_ENABLE_MASK | TX_FIFO_ENABLE_MASK | SRG_CLK_SEL_MASK |
453 - LOOPBACK_MASK | TX_EXTRA_DELAY_MASK;
454 -
455 - new_reg = (config->tx_clk_sel | config->rx_clk_sel |
456 - config->rx_fsync_pol | config->tx_fsync_pol |
457 - config->rx_fsync_sel | config->tx_fsync_sel |
458 - config->rx_fifo_config | config->tx_fifo_config |
459 - config->srg_clk_sel | config->loopback_enable |
460 - config->tx_data_enable);
485 + first = !msp->dir_busy;
486 + if (!first && !ux500_msp_config_compatible(msp, config)) {
487 + dev_err(msp->dev, "%s: Incompatible duplex configuration\n",
488 + __func__);
489 + return -EBUSY;
490 + }
461 491
462 - old_reg = readl(msp->registers + MSP_GCR);
463 - old_reg &= ~mask;
464 - new_reg |= old_reg;
465 - writel(new_reg, msp->registers + MSP_GCR);
492 + if (first) {
493 + /* First do the global config register */
494 + mask = RX_CLK_SEL_MASK | TX_CLK_SEL_MASK | RX_FSYNC_MASK |
495 + TX_FSYNC_MASK | RX_SYNC_SEL_MASK | TX_SYNC_SEL_MASK |
496 + RX_FIFO_ENABLE_MASK | TX_FIFO_ENABLE_MASK |
497 + SRG_CLK_SEL_MASK | LOOPBACK_MASK | TX_EXTRA_DELAY_MASK;
498 +
499 + new_reg = config->tx_clk_sel | config->rx_clk_sel |
500 + config->rx_fsync_pol | config->tx_fsync_pol |
501 + config->rx_fsync_sel | config->tx_fsync_sel |
502 + config->rx_fifo_config | config->tx_fifo_config |
503 + config->srg_clk_sel | config->loopback_enable |
504 + config->tx_data_enable;
505 +
506 + old_reg = readl(msp->registers + MSP_GCR);
507 + old_reg &= ~mask;
508 + new_reg |= old_reg;
509 + writel(new_reg, msp->registers + MSP_GCR);
510 + writel(MSP_WMRK_TX_4_ELEMENTS | MSP_WMRK_RX_4_ELEMENTS,
511 + msp->registers + MSP_WMRK);
512 + }
466 513
467 - res = enable_msp(msp, config);
514 + res = enable_msp(msp, config, first);
468 515 if (res < 0) {
469 516 dev_err(msp->dev, "%s: ERROR: enable_msp failed (%d)!\n",
470 517 __func__, res);
471 - return -EBUSY;
518 + if (tx_sel)
519 + writel(0, msp->registers + MSP_TCF);
520 + if (rx_sel)
521 + writel(0, msp->registers + MSP_RCF);
522 + if (first) {
523 + writel(0, msp->registers + MSP_GCR);
524 + writel(0, msp->registers + MSP_DMACR);
525 + writel(0, msp->registers + MSP_SRG);
526 + writel(0, msp->registers + MSP_MCR);
527 + }
528 + return res;
529 + }
530 +
531 + msp->dir_busy |= config->direction;
532 + if (first) {
533 + msp->config = *config;
534 + msp->clock_provider = config->clock_provider;
472 535 }
473 536 if (config->loopback_enable & 0x80)
474 537 msp->loopback_enable = 1;
475 538
476 539 /* Flush FIFOs */
477 - flush_fifo_tx(msp);
478 - flush_fifo_rx(msp);
540 + if (tx_sel)
541 + flush_fifo_tx(msp);
542 + if (rx_sel)
543 + flush_fifo_rx(msp);
479 544
480 - msp->msp_state = MSP_STATE_CONFIGURED;
545 + if (!msp->dir_running)
546 + msp->msp_state = MSP_STATE_CONFIGURED;
481 547 return 0;
482 548 }
483 549
@@ -494,7 +560,6 @@ static void disable_msp_rx(struct ux500_msp *msp)
494 560 ~(RX_SERVICE_INT | RX_OVERRUN_ERROR_INT),
495 561 msp->registers + MSP_IMSC);
496 562
497 - msp->dir_busy &= ~MSP_DIR_RX;
498 563 }
499 564
500 565 static void disable_msp_tx(struct ux500_msp *msp)
@@ -510,7 +575,6 @@ static void disable_msp_tx(struct ux500_msp *msp)
510 575 ~(TX_SERVICE_INT | TX_UNDERRUN_ERR_INT),
511 576 msp->registers + MSP_IMSC);
512 577
513 - msp->dir_busy &= ~MSP_DIR_TX;
514 578 }
515 579
516 580 static int disable_msp(struct ux500_msp *msp, unsigned int dir)
@@ -520,7 +584,7 @@ static int disable_msp(struct ux500_msp *msp, unsigned int dir)
520 584
521 585 reg_val_GCR = readl(msp->registers + MSP_GCR);
522 586 disable_tx = dir & MSP_DIR_TX;
523 - disable_rx = dir & MSP_DIR_TX;
587 + disable_rx = dir & MSP_DIR_RX;
524 588 if (disable_tx && disable_rx) {
525 589 reg_val_GCR = readl(msp->registers + MSP_GCR);
526 590 writel(reg_val_GCR | LOOPBACK_MASK,
@@ -553,7 +617,15 @@ static int disable_msp(struct ux500_msp *msp, unsigned int dir)
553 617
554 618 int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd, int direction)
555 619 {
556 - u32 reg_val_GCR, enable_bit;
620 + u32 reg_val_DMACR, reg_val_GCR, dma_enable_bit, enable_bit;
621 + unsigned int dir;
622 +
623 + if (direction == SNDRV_PCM_STREAM_PLAYBACK)
624 + dir = MSP_DIR_TX;
625 + else if (direction == SNDRV_PCM_STREAM_CAPTURE)
626 + dir = MSP_DIR_RX;
627 + else
628 + return -EINVAL;
557 629
558 630 if (msp->msp_state == MSP_STATE_IDLE) {
559 631 dev_err(msp->dev, "%s: ERROR: MSP is not configured!\n",
@@ -565,21 +637,44 @@ int ux500_msp_i2s_trigger(struct ux500_msp *msp, int cmd, int direction)
565 637 case SNDRV_PCM_TRIGGER_START:
566 638 case SNDRV_PCM_TRIGGER_RESUME:
567 639 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
568 - if (direction == SNDRV_PCM_STREAM_PLAYBACK)
640 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
569 641 enable_bit = TX_ENABLE;
570 - else
642 + dma_enable_bit = TX_DMA_ENABLE;
643 + } else {
571 644 enable_bit = RX_ENABLE;
645 + dma_enable_bit = RX_DMA_ENABLE;
646 + }
647 + if (!(msp->dir_busy & dir))
648 + return -EINVAL;
649 + reg_val_DMACR = readl(msp->registers + MSP_DMACR);
650 + writel(reg_val_DMACR | dma_enable_bit,
651 + msp->registers + MSP_DMACR);
572 652 reg_val_GCR = readl(msp->registers + MSP_GCR);
653 + if (msp->clock_provider)
654 + enable_bit |= FRAME_GEN_ENABLE;
573 655 writel(reg_val_GCR | enable_bit, msp->registers + MSP_GCR);
656 + msp->dir_running |= dir;
657 + msp->msp_state = MSP_STATE_RUNNING;
574 658 break;
575 659
576 660 case SNDRV_PCM_TRIGGER_STOP:
577 661 case SNDRV_PCM_TRIGGER_SUSPEND:
578 662 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
579 - if (direction == SNDRV_PCM_STREAM_PLAYBACK)
663 + if (!(msp->dir_busy & dir))
664 + return -EINVAL;
665 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
580 666 disable_msp_tx(msp);
581 - else
667 + msp->dir_running &= ~MSP_DIR_TX;
668 + } else {
582 669 disable_msp_rx(msp);
670 + msp->dir_running &= ~MSP_DIR_RX;
671 + }
672 + if (!msp->dir_running) {
673 + reg_val_GCR = readl(msp->registers + MSP_GCR);
674 + writel(reg_val_GCR & ~FRAME_GEN_ENABLE,
675 + msp->registers + MSP_GCR);
676 + msp->msp_state = MSP_STATE_CONFIGURED;
677 + }
583 678 break;
584 679 default:
585 680 return -EINVAL;
@@ -594,7 +689,18 @@ int ux500_msp_i2s_close(struct ux500_msp *msp, unsigned int dir)
594 689
595 690 dev_dbg(msp->dev, "%s: Enter (dir = 0x%01x).\n", __func__, dir);
596 691
692 + if (!dir || dir & ~(MSP_DIR_TX | MSP_DIR_RX) ||
693 + (msp->dir_busy & dir) != dir)
694 + return -EINVAL;
695 +
597 696 status = disable_msp(msp, dir);
697 + msp->dir_busy &= ~dir;
698 + msp->dir_running &= ~dir;
699 + if (msp->dir_busy && !msp->dir_running) {
700 + writel(readl(msp->registers + MSP_GCR) & ~FRAME_GEN_ENABLE,
701 + msp->registers + MSP_GCR);
702 + msp->msp_state = MSP_STATE_CONFIGURED;
703 + }
598 704 if (msp->dir_busy == 0) {
599 705 /* disable sample rate and frame generators */
600 706 msp->msp_state = MSP_STATE_IDLE;
@@ -618,6 +724,8 @@ int ux500_msp_i2s_close(struct ux500_msp *msp, unsigned int dir)
618 724 writel(0, msp->registers + MSP_RCE1);
619 725 writel(0, msp->registers + MSP_RCE2);
620 726 writel(0, msp->registers + MSP_RCE3);
727 + memset(&msp->config, 0, sizeof(msp->config));
728 + msp->clock_provider = false;
621 729 }
622 730
623 731 return status;
@@ -627,7 +735,7 @@ int ux500_msp_i2s_close(struct ux500_msp *msp, unsigned int dir)
627 735 int ux500_msp_i2s_init_msp(struct platform_device *pdev,
628 736 struct ux500_msp **msp_p)
629 737 {
630 - struct resource *res = NULL;
738 + struct resource *res;
631 739 struct ux500_msp *msp;
632 740
633 741 *msp_p = devm_kzalloc(&pdev->dev, sizeof(struct ux500_msp), GFP_KERNEL);
@@ -637,20 +745,10 @@ int ux500_msp_i2s_init_msp(struct platform_device *pdev,
637 745
638 746 msp->dev = &pdev->dev;
639 747
640 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
641 - if (res == NULL) {
642 - dev_err(&pdev->dev, "%s: ERROR: Unable to get resource!\n",
643 - __func__);
644 - return -ENOMEM;
645 - }
646 -
748 + msp->registers = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
749 + if (IS_ERR(msp->registers))
750 + return PTR_ERR(msp->registers);
647 751 msp->tx_rx_addr = res->start + MSP_DR;
648 - msp->registers = devm_ioremap(&pdev->dev, res->start,
649 - resource_size(res));
650 - if (msp->registers == NULL) {
651 - dev_err(&pdev->dev, "%s: ERROR: ioremap failed!\n", __func__);
652 - return -ENOMEM;
653 - }
654 752
655 753 msp->msp_state = MSP_STATE_IDLE;
656 754 msp->loopback_enable = 0;
modified sound/soc/ux500/ux500_msp_i2s.h
@@ -12,8 +12,6 @@
12 12
13 13 #include <linux/platform_device.h>
14 14
15 - #define MSP_INPUT_FREQ_APB 48000000
16 -
17 15 /*** Stereo mode. Used for APB data accesses as 16 bits accesses (mono),
18 16 * 32 bits accesses (stereo).
19 17 ***/
@@ -64,6 +62,7 @@ enum msp_direction {
64 62 #define MSP_SRG 0x10
65 63 #define MSP_FLR 0x14
66 64 #define MSP_DMACR 0x18
65 + #define MSP_WMRK 0x1c
67 66
68 67 #define MSP_IMSC 0x20
69 68 #define MSP_RIS 0x24
@@ -230,6 +229,10 @@ enum msp_direction {
230 229 #define RDMAE_SHIFT 0
231 230 #define TDMAE_SHIFT 1
232 231
232 + /* FIFO watermark register */
233 + #define MSP_WMRK_RX_4_ELEMENTS BIT(0)
234 + #define MSP_WMRK_TX_4_ELEMENTS BIT(3)
235 +
233 236 /* Interrupt Register */
234 237 #define RX_SERVICE_INT BIT(0)
235 238 #define RX_OVERRUN_ERROR_INT BIT(1)
@@ -460,6 +463,8 @@ struct ux500_msp_config {
460 463 enum msp_data_size data_size;
461 464 unsigned int def_elem_len;
462 465 unsigned int iodelay;
466 + bool clock_provider;
467 + bool bclk_inverted;
463 468 };
464 469
465 470 struct ux500_msp {
@@ -470,8 +475,11 @@ struct ux500_msp {
470 475 enum msp_state msp_state;
471 476 int def_elem_len;
472 477 unsigned int dir_busy;
478 + unsigned int dir_running;
473 479 int loopback_enable;
474 480 unsigned int f_bitclk;
481 + bool clock_provider;
482 + struct ux500_msp_config config;
475 483 };
476 484
477 485 int ux500_msp_i2s_init_msp(struct platform_device *pdev,
modified sound/usb/6fire/comm.c
@@ -21,7 +21,6 @@ enum {
21 21 static void usb6fire_comm_init_urb(struct comm_runtime *rt, struct urb *urb,
22 22 u8 *buffer, void *context, void(*handler)(struct urb *urb))
23 23 {
24 - usb_init_urb(urb);
25 24 urb->transfer_buffer = buffer;
26 25 urb->pipe = usb_sndintpipe(rt->chip->dev, COMM_EP);
27 26 urb->complete = handler;
@@ -142,6 +141,19 @@ static int usb6fire_comm_write16(struct comm_runtime *rt, u8 request,
142 141 return ret;
143 142 }
144 143
144 + static void usb6fire_comm_free(struct comm_runtime *rt)
145 + {
146 + if (!rt)
147 + return;
148 +
149 + if (rt->chip)
150 + rt->chip->comm = NULL;
151 +
152 + usb_free_urb(rt->receiver);
153 + kfree(rt->receiver_buffer);
154 + kfree(rt);
155 + }
156 +
145 157 int usb6fire_comm_init(struct sfire_chip *chip)
146 158 {
147 159 struct comm_runtime *rt = kzalloc_obj(struct comm_runtime);
@@ -153,14 +165,18 @@ int usb6fire_comm_init(struct sfire_chip *chip)
153 165
154 166 rt->receiver_buffer = kzalloc(COMM_RECEIVER_BUFSIZE, GFP_KERNEL);
155 167 if (!rt->receiver_buffer) {
156 - kfree(rt);
157 - return -ENOMEM;
168 + ret = -ENOMEM;
169 + goto error;
158 170 }
159 171
160 - urb = &rt->receiver;
172 + urb = usb_alloc_urb(0, GFP_KERNEL);
173 + if (!urb) {
174 + ret = -ENOMEM;
175 + goto error;
176 + }
177 + rt->receiver = urb;
161 178 rt->serial = 1;
162 179 rt->chip = chip;
163 - usb_init_urb(urb);
164 180 rt->init_urb = usb6fire_comm_init_urb;
165 181 rt->write8 = usb6fire_comm_write8;
166 182 rt->write16 = usb6fire_comm_write16;
@@ -175,13 +191,15 @@ int usb6fire_comm_init(struct sfire_chip *chip)
175 191 urb->interval = 1;
176 192 ret = usb_submit_urb(urb, GFP_KERNEL);
177 193 if (ret < 0) {
178 - kfree(rt->receiver_buffer);
179 - kfree(rt);
180 194 dev_err(&chip->dev->dev, "cannot create comm data receiver.");
181 - return ret;
195 + goto error;
182 196 }
183 197 chip->comm = rt;
184 198 return 0;
199 +
200 + error:
201 + usb6fire_comm_free(rt);
202 + return ret;
185 203 }
186 204
187 205 void usb6fire_comm_abort(struct sfire_chip *chip)
@@ -189,14 +207,10 @@ void usb6fire_comm_abort(struct sfire_chip *chip)
189 207 struct comm_runtime *rt = chip->comm;
190 208
191 209 if (rt)
192 - usb_poison_urb(&rt->receiver);
210 + usb_poison_urb(rt->receiver);
193 211 }
194 212
195 213 void usb6fire_comm_destroy(struct sfire_chip *chip)
196 214 {
197 - struct comm_runtime *rt = chip->comm;
198 -
199 - kfree(rt->receiver_buffer);
200 - kfree(rt);
201 - chip->comm = NULL;
215 + usb6fire_comm_free(chip->comm);
202 216 }
modified sound/usb/6fire/comm.h
@@ -19,7 +19,7 @@ enum /* settings for comm */
19 19 struct comm_runtime {
20 20 struct sfire_chip *chip;
21 21
22 - struct urb receiver;
22 + struct urb *receiver;
23 23 u8 *receiver_buffer;
24 24
25 25 u8 serial; /* urb serial */
modified sound/usb/6fire/midi.c
@@ -66,7 +66,7 @@ static void usb6fire_midi_out_trigger(
66 66 struct snd_rawmidi_substream *alsa_sub, int up)
67 67 {
68 68 struct midi_runtime *rt = alsa_sub->rmidi->private_data;
69 - struct urb *urb = &rt->out_urb;
69 + struct urb *urb = rt->out_urb;
70 70 __s8 ret;
71 71
72 72 guard(spinlock_irqsave)(&rt->out_lock);
@@ -137,6 +137,19 @@ static const struct snd_rawmidi_ops in_ops = {
137 137 .trigger = usb6fire_midi_in_trigger
138 138 };
139 139
140 + static void usb6fire_midi_free(struct midi_runtime *rt)
141 + {
142 + if (!rt)
143 + return;
144 +
145 + if (rt->chip)
146 + rt->chip->midi = NULL;
147 +
148 + usb_free_urb(rt->out_urb);
149 + kfree(rt->out_buffer);
150 + kfree(rt);
151 + }
152 +
140 153 int usb6fire_midi_init(struct sfire_chip *chip)
141 154 {
142 155 int ret;
@@ -148,8 +161,14 @@ int usb6fire_midi_init(struct sfire_chip *chip)
148 161
149 162 rt->out_buffer = kzalloc(MIDI_BUFSIZE, GFP_KERNEL);
150 163 if (!rt->out_buffer) {
151 - kfree(rt);
152 - return -ENOMEM;
164 + ret = -ENOMEM;
165 + goto error;
166 + }
167 +
168 + rt->out_urb = usb_alloc_urb(0, GFP_KERNEL);
169 + if (!rt->out_urb) {
170 + ret = -ENOMEM;
171 + goto error;
153 172 }
154 173
155 174 rt->chip = chip;
@@ -160,15 +179,13 @@ int usb6fire_midi_init(struct sfire_chip *chip)
160 179 spin_lock_init(&rt->in_lock);
161 180 spin_lock_init(&rt->out_lock);
162 181
163 - comm_rt->init_urb(comm_rt, &rt->out_urb, rt->out_buffer, rt,
182 + comm_rt->init_urb(comm_rt, rt->out_urb, rt->out_buffer, rt,
164 183 usb6fire_midi_out_handler);
165 184
166 185 ret = snd_rawmidi_new(chip->card, "6FireUSB", 0, 1, 1, &rt->instance);
167 186 if (ret < 0) {
168 - kfree(rt->out_buffer);
169 - kfree(rt);
170 187 dev_err(&chip->dev->dev, "unable to create midi.\n");
171 - return ret;
188 + goto error;
172 189 }
173 190 rt->instance->private_data = rt;
174 191 strscpy(rt->instance->name, "DMX6FireUSB MIDI");
@@ -182,6 +199,10 @@ int usb6fire_midi_init(struct sfire_chip *chip)
182 199
183 200 chip->midi = rt;
184 201 return 0;
202 +
203 + error:
204 + usb6fire_midi_free(rt);
205 + return ret;
185 206 }
186 207
187 208 void usb6fire_midi_abort(struct sfire_chip *chip)
@@ -189,14 +210,10 @@ void usb6fire_midi_abort(struct sfire_chip *chip)
189 210 struct midi_runtime *rt = chip->midi;
190 211
191 212 if (rt)
192 - usb_poison_urb(&rt->out_urb);
213 + usb_poison_urb(rt->out_urb);
193 214 }
194 215
195 216 void usb6fire_midi_destroy(struct sfire_chip *chip)
196 217 {
197 - struct midi_runtime *rt = chip->midi;
198 -
199 - kfree(rt->out_buffer);
200 - kfree(rt);
201 - chip->midi = NULL;
218 + usb6fire_midi_free(chip->midi);
202 219 }
modified sound/usb/6fire/midi.h
@@ -22,7 +22,7 @@ struct midi_runtime {
22 22 spinlock_t in_lock;
23 23 spinlock_t out_lock;
24 24 struct snd_rawmidi_substream *out;
25 - struct urb out_urb;
25 + struct urb *out_urb;
26 26 u8 out_serial; /* serial number of out packet */
27 27 u8 *out_buffer;
28 28 int buffer_offset;
modified sound/usb/6fire/pcm.c
@@ -138,8 +138,8 @@ static void usb6fire_pcm_stream_stop(struct pcm_runtime *rt)
138 138 rt->stream_state = STREAM_STOPPING;
139 139
140 140 for (i = 0; i < PCM_N_URBS; i++) {
141 - usb_kill_urb(&rt->in_urbs[i].instance);
142 - usb_kill_urb(&rt->out_urbs[i].instance);
141 + usb_kill_urb(rt->in_urbs[i].instance);
142 + usb_kill_urb(rt->out_urbs[i].instance);
143 143 }
144 144 ctrl_rt->usb_streaming = false;
145 145 ctrl_rt->update_streaming(ctrl_rt);
@@ -161,13 +161,13 @@ static int usb6fire_pcm_stream_start(struct pcm_runtime *rt)
161 161 rt->stream_state = STREAM_STARTING;
162 162 for (i = 0; i < PCM_N_URBS; i++) {
163 163 for (k = 0; k < PCM_N_PACKETS_PER_URB; k++) {
164 - packet = &rt->in_urbs[i].packets[k];
164 + packet = &rt->in_urbs[i].instance->iso_frame_desc[k];
165 165 packet->offset = k * rt->in_packet_size;
166 166 packet->length = rt->in_packet_size;
167 167 packet->actual_length = 0;
168 168 packet->status = 0;
169 169 }
170 - ret = usb_submit_urb(&rt->in_urbs[i].instance,
170 + ret = usb_submit_urb(rt->in_urbs[i].instance,
171 171 GFP_ATOMIC);
172 172 if (ret) {
173 173 usb6fire_pcm_stream_stop(rt);
@@ -197,6 +197,7 @@ static void usb6fire_pcm_capture(struct pcm_substream *sub, struct pcm_urb *urb)
197 197 unsigned int total_length = 0;
198 198 struct pcm_runtime *rt = snd_pcm_substream_chip(sub->instance);
199 199 struct snd_pcm_runtime *alsa_rt = sub->instance->runtime;
200 + struct usb_iso_packet_descriptor *isoc;
200 201 u32 *src = NULL;
201 202 u32 *dest = (u32 *) (alsa_rt->dma_area + sub->dma_off
202 203 * (alsa_rt->frame_bits >> 3));
@@ -207,8 +208,9 @@ static void usb6fire_pcm_capture(struct pcm_substream *sub, struct pcm_urb *urb)
207 208 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
208 209 /* at least 4 header bytes for valid packet.
209 210 * after that: 32 bits per sample for analog channels */
210 - if (urb->packets[i].actual_length > 4)
211 - frame_count = (urb->packets[i].actual_length - 4)
211 + isoc = &urb->instance->iso_frame_desc[i];
212 + if (isoc->actual_length > 4)
213 + frame_count = (isoc->actual_length - 4)
212 214 / (rt->in_n_analog << 2);
213 215 else
214 216 frame_count = 0;
@@ -220,7 +222,7 @@ static void usb6fire_pcm_capture(struct pcm_substream *sub, struct pcm_urb *urb)
220 222 else
221 223 return;
222 224 src++; /* skip leading 4 bytes of every packet */
223 - total_length += urb->packets[i].length;
225 + total_length += isoc->length;
224 226 for (frame = 0; frame < frame_count; frame++) {
225 227 memcpy(dest, src, bytes_per_frame);
226 228 dest += alsa_rt->channels;
@@ -244,6 +246,7 @@ static void usb6fire_pcm_playback(struct pcm_substream *sub,
244 246 int frame_count;
245 247 struct pcm_runtime *rt = snd_pcm_substream_chip(sub->instance);
246 248 struct snd_pcm_runtime *alsa_rt = sub->instance->runtime;
249 + struct usb_iso_packet_descriptor *isoc;
247 250 u32 *src = (u32 *) (alsa_rt->dma_area + sub->dma_off
248 251 * (alsa_rt->frame_bits >> 3));
249 252 u32 *src_end = (u32 *) (alsa_rt->dma_area + alsa_rt->buffer_size
@@ -263,8 +266,9 @@ static void usb6fire_pcm_playback(struct pcm_substream *sub,
263 266 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
264 267 /* at least 4 header bytes for valid packet.
265 268 * after that: 32 bits per sample for analog channels */
266 - if (urb->packets[i].length > 4)
267 - frame_count = (urb->packets[i].length - 4)
269 + isoc = &urb->instance->iso_frame_desc[i];
270 + if (isoc->length > 4)
271 + frame_count = (isoc->length - 4)
268 272 / (rt->out_n_analog << 2);
269 273 else
270 274 frame_count = 0;
@@ -289,6 +293,7 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
289 293 struct pcm_urb *out_urb = in_urb->peer;
290 294 struct pcm_runtime *rt = in_urb->chip->pcm;
291 295 struct pcm_substream *sub;
296 + struct usb_iso_packet_descriptor *isoc_out, *isoc_in;
292 297 bool period_elapsed;
293 298 int total_length = 0;
294 299 int frame_count;
@@ -299,11 +304,13 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
299 304
300 305 if (usb_urb->status || rt->panic || rt->stream_state == STREAM_STOPPING)
301 306 return;
302 - for (i = 0; i < PCM_N_PACKETS_PER_URB; i++)
303 - if (in_urb->packets[i].status) {
307 + for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
308 + isoc_in = &in_urb->instance->iso_frame_desc[i];
309 + if (isoc_in->status) {
304 310 rt->panic = true;
305 311 return;
306 312 }
313 + }
307 314
308 315 if (rt->stream_state == STREAM_DISABLED) {
309 316 dev_err(&rt->chip->dev->dev,
@@ -328,12 +335,13 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
328 335
329 336 /* setup out urb structure */
330 337 for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
331 - out_urb->packets[i].offset = total_length;
332 - out_urb->packets[i].length = (in_urb->packets[i].actual_length
333 - - 4) / (rt->in_n_analog << 2)
338 + isoc_out = &out_urb->instance->iso_frame_desc[i];
339 + isoc_in = &in_urb->instance->iso_frame_desc[i];
340 + isoc_out->offset = total_length;
341 + isoc_out->length = (isoc_in->actual_length - 4) / (rt->in_n_analog << 2)
334 342 * (rt->out_n_analog << 2) + 4;
335 - out_urb->packets[i].status = 0;
336 - total_length += out_urb->packets[i].length;
343 + isoc_out->status = 0;
344 + total_length += isoc_out->length;
337 345 }
338 346 memset(out_urb->buffer, 0, total_length);
339 347
@@ -354,9 +362,10 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
354 362
355 363 /* setup the 4th byte of each sample (0x40 for analog channels) */
356 364 dest = out_urb->buffer;
357 - for (i = 0; i < PCM_N_PACKETS_PER_URB; i++)
358 - if (out_urb->packets[i].length >= 4) {
359 - frame_count = (out_urb->packets[i].length - 4)
365 + for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
366 + isoc_out = &out_urb->instance->iso_frame_desc[i];
367 + if (isoc_out->length >= 4) {
368 + frame_count = (isoc_out->length - 4)
360 369 / (rt->out_n_analog << 2);
361 370 *(dest++) = 0xaa;
362 371 *(dest++) = 0xaa;
@@ -370,8 +379,10 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
370 379 *(dest++) = 0x40;
371 380 }
372 381 }
373 - usb_submit_urb(&out_urb->instance, GFP_ATOMIC);
374 - usb_submit_urb(&in_urb->instance, GFP_ATOMIC);
382 + }
383 +
384 + usb_submit_urb(out_urb->instance, GFP_ATOMIC);
385 + usb_submit_urb(in_urb->instance, GFP_ATOMIC);
375 386 }
376 387
377 388 static void usb6fire_pcm_out_urb_handler(struct urb *usb_urb)
@@ -534,22 +545,25 @@ static const struct snd_pcm_ops pcm_ops = {
534 545 .pointer = usb6fire_pcm_pointer,
535 546 };
536 547
537 - static void usb6fire_pcm_init_urb(struct pcm_urb *urb,
538 - struct sfire_chip *chip, bool in, int ep,
539 - void (*handler)(struct urb *))
548 + static int usb6fire_pcm_init_urb(struct pcm_urb *urb,
549 + struct sfire_chip *chip, bool in, int ep,
550 + void (*handler)(struct urb *))
540 551 {
541 552 urb->chip = chip;
542 - usb_init_urb(&urb->instance);
543 - urb->instance.transfer_buffer = urb->buffer;
544 - urb->instance.transfer_buffer_length =
553 + urb->instance = usb_alloc_urb(PCM_N_PACKETS_PER_URB, GFP_KERNEL);
554 + if (!urb->instance)
555 + return -ENOMEM;
556 + urb->instance->transfer_buffer = urb->buffer;
557 + urb->instance->transfer_buffer_length =
545 558 PCM_N_PACKETS_PER_URB * PCM_MAX_PACKET_SIZE;
546 - urb->instance.dev = chip->dev;
547 - urb->instance.pipe = in ? usb_rcvisocpipe(chip->dev, ep)
559 + urb->instance->dev = chip->dev;
560 + urb->instance->pipe = in ? usb_rcvisocpipe(chip->dev, ep)
548 561 : usb_sndisocpipe(chip->dev, ep);
549 - urb->instance.interval = 1;
550 - urb->instance.complete = handler;
551 - urb->instance.context = urb;
552 - urb->instance.number_of_packets = PCM_N_PACKETS_PER_URB;
562 + urb->instance->interval = 1;
563 + urb->instance->complete = handler;
564 + urb->instance->context = urb;
565 + urb->instance->number_of_packets = PCM_N_PACKETS_PER_URB;
566 + return 0;
553 567 }
554 568
555 569 static int usb6fire_pcm_buffers_init(struct pcm_runtime *rt)
@@ -571,14 +585,23 @@ static int usb6fire_pcm_buffers_init(struct pcm_runtime *rt)
571 585 return 0;
572 586 }
573 587
574 - static void usb6fire_pcm_buffers_destroy(struct pcm_runtime *rt)
588 + static void usb6fire_pcm_free(struct pcm_runtime *rt)
575 589 {
576 590 int i;
577 591
592 + if (!rt)
593 + return;
594 +
595 + if (rt->chip)
596 + rt->chip->pcm = NULL;
597 +
578 598 for (i = 0; i < PCM_N_URBS; i++) {
599 + usb_free_urb(rt->out_urbs[i].instance);
579 600 kfree(rt->out_urbs[i].buffer);
601 + usb_free_urb(rt->in_urbs[i].instance);
580 602 kfree(rt->in_urbs[i].buffer);
581 603 }
604 + kfree(rt);
582 605 }
583 606
584 607 int usb6fire_pcm_init(struct sfire_chip *chip)
@@ -593,11 +616,8 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
593 616 return -ENOMEM;
594 617
595 618 ret = usb6fire_pcm_buffers_init(rt);
596 - if (ret) {
597 - usb6fire_pcm_buffers_destroy(rt);
598 - kfree(rt);
599 - return ret;
600 - }
619 + if (ret)
620 + goto error;
601 621
602 622 rt->chip = chip;
603 623 rt->stream_state = STREAM_DISABLED;
@@ -609,10 +629,14 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
609 629 spin_lock_init(&rt->capture.lock);
610 630
611 631 for (i = 0; i < PCM_N_URBS; i++) {
612 - usb6fire_pcm_init_urb(&rt->in_urbs[i], chip, true, IN_EP,
613 - usb6fire_pcm_in_urb_handler);
614 - usb6fire_pcm_init_urb(&rt->out_urbs[i], chip, false, OUT_EP,
615 - usb6fire_pcm_out_urb_handler);
632 + ret = usb6fire_pcm_init_urb(&rt->in_urbs[i], chip, true, IN_EP,
633 + usb6fire_pcm_in_urb_handler);
634 + if (ret < 0)
635 + goto error;
636 + ret = usb6fire_pcm_init_urb(&rt->out_urbs[i], chip, false, OUT_EP,
637 + usb6fire_pcm_out_urb_handler);
638 + if (ret < 0)
639 + goto error;
616 640
617 641 rt->in_urbs[i].peer = &rt->out_urbs[i];
618 642 rt->out_urbs[i].peer = &rt->in_urbs[i];
@@ -620,10 +644,8 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
620 644
621 645 ret = snd_pcm_new(chip->card, "DMX6FireUSB", 0, 1, 1, &pcm);
622 646 if (ret < 0) {
623 - usb6fire_pcm_buffers_destroy(rt);
624 - kfree(rt);
625 647 dev_err(&chip->dev->dev, "cannot create pcm instance.\n");
626 - return ret;
648 + goto error;
627 649 }
628 650
629 651 pcm->private_data = rt;
@@ -636,6 +658,10 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
636 658
637 659 chip->pcm = rt;
638 660 return 0;
661 +
662 + error:
663 + usb6fire_pcm_free(rt);
664 + return ret;
639 665 }
640 666
641 667 void usb6fire_pcm_abort(struct sfire_chip *chip)
@@ -653,8 +679,8 @@ void usb6fire_pcm_abort(struct sfire_chip *chip)
653 679 snd_pcm_stop_xrun(rt->capture.instance);
654 680
655 681 for (i = 0; i < PCM_N_URBS; i++) {
656 - usb_poison_urb(&rt->in_urbs[i].instance);
657 - usb_poison_urb(&rt->out_urbs[i].instance);
682 + usb_poison_urb(rt->in_urbs[i].instance);
683 + usb_poison_urb(rt->out_urbs[i].instance);
658 684 }
659 685
660 686 }
@@ -662,9 +688,5 @@ void usb6fire_pcm_abort(struct sfire_chip *chip)
662 688
663 689 void usb6fire_pcm_destroy(struct sfire_chip *chip)
664 690 {
665 - struct pcm_runtime *rt = chip->pcm;
666 -
667 - usb6fire_pcm_buffers_destroy(rt);
668 - kfree(rt);
669 - chip->pcm = NULL;
691 + usb6fire_pcm_free(chip->pcm);
670 692 }
modified sound/usb/6fire/pcm.h
@@ -24,10 +24,7 @@ enum /* settings for pcm */
24 24 struct pcm_urb {
25 25 struct sfire_chip *chip;
26 26
27 - /* BEGIN DO NOT SEPARATE */
28 - struct urb instance;
29 - struct usb_iso_packet_descriptor packets[PCM_N_PACKETS_PER_URB];
30 - /* END DO NOT SEPARATE */
27 + struct urb *instance;
31 28 u8 *buffer;
32 29
33 30 struct pcm_urb *peer;
modified sound/usb/caiaq/device.c
@@ -192,8 +192,8 @@ static void usb_ep1_command_reply_dispatch (struct urb* urb)
192 192 break;
193 193 }
194 194
195 - cdev->ep1_in_urb.actual_length = 0;
196 - ret = usb_submit_urb(&cdev->ep1_in_urb, GFP_ATOMIC);
195 + cdev->ep1_in_urb->actual_length = 0;
196 + ret = usb_submit_urb(cdev->ep1_in_urb, GFP_ATOMIC);
197 197 if (ret < 0)
198 198 dev_err(dev, "unable to submit urb. OOM!?\n");
199 199 }
@@ -408,6 +408,10 @@ static void card_free(struct snd_card *card)
408 408 #endif
409 409 snd_usb_caiaq_audio_free(cdev);
410 410 usb_put_dev(cdev->chip.dev);
411 + usb_free_urb(cdev->ep1_in_urb);
412 + cdev->ep1_in_urb = NULL;
413 + usb_free_urb(cdev->midi_out_urb);
414 + cdev->midi_out_urb = NULL;
411 415 }
412 416
413 417 static int create_card(struct usb_device *usb_dev,
@@ -457,22 +461,30 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
457 461 return -EIO;
458 462 }
459 463
460 - usb_init_urb(&cdev->ep1_in_urb);
461 - usb_init_urb(&cdev->midi_out_urb);
464 + cdev->ep1_in_urb = usb_alloc_urb(0, GFP_KERNEL);
465 + if (!cdev->ep1_in_urb)
466 + return -ENOMEM;
462 467
463 - usb_fill_bulk_urb(&cdev->ep1_in_urb, usb_dev,
468 + cdev->midi_out_urb = usb_alloc_urb(0, GFP_KERNEL);
469 + if (!cdev->midi_out_urb) {
470 + usb_free_urb(cdev->ep1_in_urb);
471 + cdev->ep1_in_urb = NULL;
472 + return -ENOMEM;
473 + }
474 +
475 + usb_fill_bulk_urb(cdev->ep1_in_urb, usb_dev,
464 476 usb_rcvbulkpipe(usb_dev, 0x1),
465 477 cdev->ep1_in_buf, EP1_BUFSIZE,
466 478 usb_ep1_command_reply_dispatch, cdev);
467 479
468 - usb_fill_bulk_urb(&cdev->midi_out_urb, usb_dev,
480 + usb_fill_bulk_urb(cdev->midi_out_urb, usb_dev,
469 481 usb_sndbulkpipe(usb_dev, 0x1),
470 482 cdev->midi_out_buf, EP1_BUFSIZE,
471 483 snd_usb_caiaq_midi_output_done, cdev);
472 484
473 485 /* sanity checks of EPs before actually submitting */
474 - if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
475 - usb_urb_ep_type_check(&cdev->midi_out_urb)) {
486 + if (usb_urb_ep_type_check(cdev->ep1_in_urb) ||
487 + usb_urb_ep_type_check(cdev->midi_out_urb)) {
476 488 dev_err(dev, "invalid EPs\n");
477 489 return -EINVAL;
478 490 }
@@ -480,7 +492,7 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
480 492 init_waitqueue_head(&cdev->ep1_wait_queue);
481 493 init_waitqueue_head(&cdev->prepare_wait_queue);
482 494
483 - if (usb_submit_urb(&cdev->ep1_in_urb, GFP_KERNEL) != 0)
495 + if (usb_submit_urb(cdev->ep1_in_urb, GFP_KERNEL) != 0)
484 496 return -EIO;
485 497
486 498 err = snd_usb_caiaq_send_command(cdev, EP1_CMD_GET_DEVICE_INFO, NULL, 0);
@@ -530,7 +542,7 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
530 542 return 0;
531 543
532 544 err_kill_urb:
533 - usb_kill_urb(&cdev->ep1_in_urb);
545 + usb_kill_urb(cdev->ep1_in_urb);
534 546 return err;
535 547 }
536 548
@@ -576,8 +588,8 @@ static void snd_disconnect(struct usb_interface *intf)
576 588 #endif
577 589 snd_usb_caiaq_audio_disconnect(cdev);
578 590
579 - usb_kill_urb(&cdev->ep1_in_urb);
580 - usb_kill_urb(&cdev->midi_out_urb);
591 + usb_kill_urb(cdev->ep1_in_urb);
592 + usb_kill_urb(cdev->midi_out_urb);
581 593
582 594 snd_card_free_when_closed(card);
583 595 }
modified sound/usb/caiaq/device.h
@@ -60,8 +60,8 @@ struct snd_usb_caiaq_cb_info;
60 60 struct snd_usb_caiaqdev {
61 61 struct snd_usb_audio chip;
62 62
63 - struct urb ep1_in_urb;
64 - struct urb midi_out_urb;
63 + struct urb *ep1_in_urb;
64 + struct urb *midi_out_urb;
65 65 struct urb **data_urbs_in;
66 66 struct urb **data_urbs_out;
67 67 struct snd_usb_caiaq_cb_info *data_cb_info;
modified sound/usb/caiaq/midi.c
@@ -43,7 +43,7 @@ static int snd_usb_caiaq_midi_output_close(struct snd_rawmidi_substream *substre
43 43 {
44 44 struct snd_usb_caiaqdev *cdev = substream->rmidi->private_data;
45 45 if (cdev->midi_out_active) {
46 - usb_kill_urb(&cdev->midi_out_urb);
46 + usb_kill_urb(cdev->midi_out_urb);
47 47 cdev->midi_out_active = 0;
48 48 }
49 49 return 0;
@@ -64,9 +64,9 @@ static void snd_usb_caiaq_midi_send(struct snd_usb_caiaqdev *cdev,
64 64 return;
65 65
66 66 cdev->midi_out_buf[2] = len;
67 - cdev->midi_out_urb.transfer_buffer_length = len+3;
67 + cdev->midi_out_urb->transfer_buffer_length = len+3;
68 68
69 - ret = usb_submit_urb(&cdev->midi_out_urb, GFP_ATOMIC);
69 + ret = usb_submit_urb(cdev->midi_out_urb, GFP_ATOMIC);
70 70 if (ret < 0)
71 71 dev_err(dev,
72 72 "snd_usb_caiaq_midi_send(%p): usb_submit_urb() failed,"
modified sound/usb/hiface/pcm.c
@@ -24,7 +24,7 @@
24 24 struct pcm_urb {
25 25 struct hiface_chip *chip;
26 26
27 - struct urb instance;
27 + struct urb *instance;
28 28 struct usb_anchor submitted;
29 29 u8 *buffer;
30 30 };
@@ -193,7 +193,7 @@ static void hiface_pcm_stream_stop(struct pcm_runtime *rt)
193 193 if (!time)
194 194 usb_kill_anchored_urbs(
195 195 &rt->out_urbs[i].submitted);
196 - usb_kill_urb(&rt->out_urbs[i].instance);
196 + usb_kill_urb(rt->out_urbs[i].instance);
197 197 }
198 198
199 199 rt->stream_state = STREAM_DISABLED;
@@ -215,9 +215,9 @@ static int hiface_pcm_stream_start(struct pcm_runtime *rt)
215 215 rt->stream_state = STREAM_STARTING;
216 216 for (i = 0; i < PCM_N_URBS; i++) {
217 217 memset(rt->out_urbs[i].buffer, 0, PCM_PACKET_SIZE);
218 - usb_anchor_urb(&rt->out_urbs[i].instance,
218 + usb_anchor_urb(rt->out_urbs[i].instance,
219 219 &rt->out_urbs[i].submitted);
220 - ret = usb_submit_urb(&rt->out_urbs[i].instance,
220 + ret = usb_submit_urb(rt->out_urbs[i].instance,
221 221 GFP_ATOMIC);
222 222 if (ret) {
223 223 hiface_pcm_stream_stop(rt);
@@ -334,7 +334,7 @@ static void hiface_pcm_out_urb_handler(struct urb *usb_urb)
334 334 if (do_period_elapsed)
335 335 snd_pcm_period_elapsed(sub->instance);
336 336
337 - ret = usb_submit_urb(&out_urb->instance, GFP_ATOMIC);
337 + ret = usb_submit_urb(out_urb->instance, GFP_ATOMIC);
338 338 if (ret < 0)
339 339 goto out_fail;
340 340
@@ -492,16 +492,18 @@ static int hiface_pcm_init_urb(struct pcm_urb *urb,
492 492 void (*handler)(struct urb *))
493 493 {
494 494 urb->chip = chip;
495 - usb_init_urb(&urb->instance);
495 + urb->instance = usb_alloc_urb(0, GFP_KERNEL);
496 + if (!urb->instance)
497 + return -ENOMEM;
496 498
497 499 urb->buffer = kzalloc(PCM_PACKET_SIZE, GFP_KERNEL);
498 500 if (!urb->buffer)
499 501 return -ENOMEM;
500 502
501 - usb_fill_bulk_urb(&urb->instance, chip->dev,
503 + usb_fill_bulk_urb(urb->instance, chip->dev,
502 504 usb_sndbulkpipe(chip->dev, ep), (void *)urb->buffer,
503 505 PCM_PACKET_SIZE, handler, urb);
504 - if (usb_urb_ep_type_check(&urb->instance))
506 + if (usb_urb_ep_type_check(urb->instance))
505 507 return -EINVAL;
506 508 init_usb_anchor(&urb->submitted);
507 509
@@ -520,24 +522,26 @@ void hiface_pcm_abort(struct hiface_chip *chip)
520 522 }
521 523 }
522 524
523 - static void hiface_pcm_destroy(struct hiface_chip *chip)
525 + static void hiface_pcm_destroy(struct pcm_runtime *rt)
524 526 {
525 - struct pcm_runtime *rt = chip->pcm;
526 527 int i;
527 528
528 - for (i = 0; i < PCM_N_URBS; i++)
529 - kfree(rt->out_urbs[i].buffer);
529 + if (!rt)
530 + return;
531 +
532 + if (rt->chip)
533 + rt->chip->pcm = NULL;
530 534
531 - kfree(chip->pcm);
532 - chip->pcm = NULL;
535 + for (i = 0; i < PCM_N_URBS; i++) {
536 + usb_free_urb(rt->out_urbs[i].instance);
537 + kfree(rt->out_urbs[i].buffer);
538 + }
539 + kfree(rt);
533 540 }
534 541
535 542 static void hiface_pcm_free(struct snd_pcm *pcm)
536 543 {
537 - struct pcm_runtime *rt = pcm->private_data;
538 -
539 - if (rt)
540 - hiface_pcm_destroy(rt->chip);
544 + hiface_pcm_destroy(pcm->private_data);
541 545 }
542 546
543 547 int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq)
@@ -587,8 +591,6 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq)
587 591 return 0;
588 592
589 593 error:
590 - for (i = 0; i < PCM_N_URBS; i++)
591 - kfree(rt->out_urbs[i].buffer);
592 - kfree(rt);
594 + hiface_pcm_destroy(rt);
593 595 return ret;
594 596 }
modified sound/usb/misc/ua101.c
@@ -109,10 +109,10 @@ struct ua101 {
109 109 unsigned int buffer_pos;
110 110 unsigned int queue_length;
111 111 struct ua101_urb {
112 - struct urb urb;
113 - struct usb_iso_packet_descriptor iso_frame_desc[1];
112 + struct urb *urb;
114 113 struct list_head ready_list;
115 - } *urbs[MAX_QUEUE_LENGTH];
114 + struct ua101 *ua;
115 + } urbs[MAX_QUEUE_LENGTH];
116 116 struct {
117 117 unsigned int size;
118 118 void *addr;
@@ -167,15 +167,15 @@ static void abort_usb_playback(struct ua101 *ua)
167 167 wake_up(&ua->alsa_playback_wait);
168 168 }
169 169
170 - static void playback_urb_complete(struct urb *usb_urb)
170 + static void playback_urb_complete(struct urb *urb)
171 171 {
172 - struct ua101_urb *urb = (struct ua101_urb *)usb_urb;
173 - struct ua101 *ua = urb->urb.context;
172 + struct ua101_urb *ua_urb = urb->context;
173 + struct ua101 *ua = ua_urb->ua;
174 174
175 - if (unlikely(urb->urb.status == -ENOENT || /* unlinked */
176 - urb->urb.status == -ENODEV || /* device removed */
177 - urb->urb.status == -ECONNRESET || /* unlinked */
178 - urb->urb.status == -ESHUTDOWN)) { /* device disabled */
175 + if (unlikely(urb->status == -ENOENT || /* unlinked */
176 + urb->status == -ENODEV || /* device removed */
177 + urb->status == -ECONNRESET || /* unlinked */
178 + urb->status == -ESHUTDOWN)) { /* device disabled */
179 179 abort_usb_playback(ua);
180 180 abort_alsa_playback(ua);
181 181 return;
@@ -184,18 +184,19 @@ static void playback_urb_complete(struct urb *usb_urb)
184 184 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) {
185 185 /* append URB to FIFO */
186 186 guard(spinlock_irqsave)(&ua->lock);
187 - list_add_tail(&urb->ready_list, &ua->ready_playback_urbs);
187 + list_add_tail(&ua_urb->ready_list, &ua->ready_playback_urbs);
188 188 if (ua->rate_feedback_count > 0)
189 189 queue_work(system_highpri_wq, &ua->playback_work);
190 190 ua->playback.substream->runtime->delay -=
191 - urb->urb.iso_frame_desc[0].length /
191 + urb->iso_frame_desc[0].length /
192 192 ua->playback.frame_bytes;
193 193 }
194 194 }
195 195
196 196 static void first_playback_urb_complete(struct urb *urb)
197 197 {
198 - struct ua101 *ua = urb->context;
198 + struct ua101_urb *ua_urb = urb->context;
199 + struct ua101 *ua = ua_urb->ua;
199 200
200 201 urb->complete = playback_urb_complete;
201 202 playback_urb_complete(urb);
@@ -248,7 +249,8 @@ static void playback_work(struct work_struct *work)
248 249 {
249 250 struct ua101 *ua = container_of(work, struct ua101, playback_work);
250 251 unsigned int frames;
251 - struct ua101_urb *urb;
252 + struct ua101_urb *ua_urb;
253 + struct urb *urb;
252 254 bool do_period_elapsed = false;
253 255 int err;
254 256
@@ -275,23 +277,24 @@ static void playback_work(struct work_struct *work)
275 277 ua->rate_feedback_count--;
276 278
277 279 /* take URB out of FIFO */
278 - urb = list_first_entry(&ua->ready_playback_urbs,
279 - struct ua101_urb, ready_list);
280 - list_del(&urb->ready_list);
280 + ua_urb = list_first_entry(&ua->ready_playback_urbs,
281 + struct ua101_urb, ready_list);
282 + list_del(&ua_urb->ready_list);
283 + urb = ua_urb->urb;
281 284
282 285 /* fill packet with data or silence */
283 - urb->urb.iso_frame_desc[0].length =
286 + urb->iso_frame_desc[0].length =
284 287 frames * ua->playback.frame_bytes;
285 288 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
286 289 do_period_elapsed |= copy_playback_data(&ua->playback,
287 - &urb->urb,
290 + urb,
288 291 frames);
289 292 else
290 - memset(urb->urb.transfer_buffer, 0,
291 - urb->urb.iso_frame_desc[0].length);
293 + memset(urb->transfer_buffer, 0,
294 + urb->iso_frame_desc[0].length);
292 295
293 296 /* and off you go ... */
294 - err = usb_submit_urb(&urb->urb, GFP_ATOMIC);
297 + err = usb_submit_urb(urb, GFP_ATOMIC);
295 298 if (unlikely(err < 0)) {
296 299 abort_usb_playback(ua);
297 300 abort_alsa_playback(ua);
@@ -342,7 +345,8 @@ static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb,
342 345
343 346 static void capture_urb_complete(struct urb *urb)
344 347 {
345 - struct ua101 *ua = urb->context;
348 + struct ua101_urb *ua_urb = urb->context;
349 + struct ua101 *ua = ua_urb->ua;
346 350 struct ua101_stream *stream = &ua->capture;
347 351 unsigned int frames, write_ptr;
348 352 bool do_period_elapsed;
@@ -413,7 +417,8 @@ stream_stopped:
413 417
414 418 static void first_capture_urb_complete(struct urb *urb)
415 419 {
416 - struct ua101 *ua = urb->context;
420 + struct ua101_urb *ua_urb = urb->context;
421 + struct ua101 *ua = ua_urb->ua;
417 422
418 423 urb->complete = capture_urb_complete;
419 424 capture_urb_complete(urb);
@@ -427,7 +432,7 @@ static int submit_stream_urbs(struct ua101 *ua, struct ua101_stream *stream)
427 432 unsigned int i;
428 433
429 434 for (i = 0; i < stream->queue_length; ++i) {
430 - int err = usb_submit_urb(&stream->urbs[i]->urb, GFP_KERNEL);
435 + int err = usb_submit_urb(stream->urbs[i].urb, GFP_KERNEL);
431 436 if (err < 0) {
432 437 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
433 438 err, usb_error_string(err));
@@ -442,8 +447,8 @@ static void kill_stream_urbs(struct ua101_stream *stream)
442 447 unsigned int i;
443 448
444 449 for (i = 0; i < stream->queue_length; ++i)
445 - if (stream->urbs[i])
446 - usb_kill_urb(&stream->urbs[i]->urb);
450 + if (stream->urbs[i].urb)
451 + usb_kill_urb(stream->urbs[i].urb);
447 452 }
448 453
449 454 static int enable_iso_interface(struct ua101 *ua, unsigned int intf_index)
@@ -508,7 +513,7 @@ static int start_usb_capture(struct ua101 *ua)
508 513 return err;
509 514
510 515 clear_bit(CAPTURE_URB_COMPLETED, &ua->states);
511 - ua->capture.urbs[0]->urb.complete = first_capture_urb_complete;
516 + ua->capture.urbs[0].urb->complete = first_capture_urb_complete;
512 517 ua->rate_feedback_start = 0;
513 518 ua->rate_feedback_count = 0;
514 519
@@ -550,7 +555,7 @@ static int start_usb_playback(struct ua101 *ua)
550 555 return err;
551 556
552 557 clear_bit(PLAYBACK_URB_COMPLETED, &ua->states);
553 - ua->playback.urbs[0]->urb.complete =
558 + ua->playback.urbs[0].urb->complete =
554 559 first_playback_urb_complete;
555 560 scoped_guard(spinlock_irq, &ua->lock) {
556 561 INIT_LIST_HEAD(&ua->ready_playback_urbs);
@@ -580,7 +585,7 @@ static int start_usb_playback(struct ua101 *ua)
580 585 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
581 586 ua->rate_feedback_count--;
582 587 }
583 - urb = &ua->playback.urbs[i]->urb;
588 + urb = ua->playback.urbs[i].urb;
584 589 urb->iso_frame_desc[0].length =
585 590 frames * ua->playback.frame_bytes;
586 591 memset(urb->transfer_buffer, 0,
@@ -1059,7 +1064,7 @@ static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
1059 1064 void (*urb_complete)(struct urb *))
1060 1065 {
1061 1066 unsigned max_packet_size = stream->max_packet_bytes;
1062 - struct ua101_urb *urb;
1067 + struct urb *urb;
1063 1068 unsigned int b, u = 0;
1064 1069
1065 1070 for (b = 0; b < ARRAY_SIZE(stream->buffers); ++b) {
@@ -1070,23 +1075,24 @@ static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
1070 1075 while (size >= max_packet_size) {
1071 1076 if (u >= stream->queue_length)
1072 1077 goto bufsize_error;
1073 - urb = kmalloc_obj(*urb);
1078 + urb = usb_alloc_urb(1, GFP_KERNEL);
1074 1079 if (!urb)
1075 1080 return -ENOMEM;
1076 - usb_init_urb(&urb->urb);
1077 - urb->urb.dev = ua->dev;
1078 - urb->urb.pipe = stream->usb_pipe;
1079 - urb->urb.transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1080 - urb->urb.transfer_buffer = addr;
1081 - urb->urb.transfer_dma = dma;
1082 - urb->urb.transfer_buffer_length = max_packet_size;
1083 - urb->urb.number_of_packets = 1;
1084 - urb->urb.interval = 1;
1085 - urb->urb.context = ua;
1086 - urb->urb.complete = urb_complete;
1087 - urb->urb.iso_frame_desc[0].offset = 0;
1088 - urb->urb.iso_frame_desc[0].length = max_packet_size;
1089 - stream->urbs[u++] = urb;
1081 + urb->dev = ua->dev;
1082 + urb->pipe = stream->usb_pipe;
1083 + urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1084 + urb->transfer_buffer = addr;
1085 + urb->transfer_dma = dma;
1086 + urb->transfer_buffer_length = max_packet_size;
1087 + urb->number_of_packets = 1;
1088 + urb->interval = 1;
1089 + urb->context = &stream->urbs[u];
1090 + urb->complete = urb_complete;
1091 + urb->iso_frame_desc[0].offset = 0;
1092 + urb->iso_frame_desc[0].length = max_packet_size;
1093 + stream->urbs[u].ua = ua;
1094 + stream->urbs[u].urb = urb;
1095 + u++;
1090 1096 size -= max_packet_size;
1091 1097 addr += max_packet_size;
1092 1098 dma += max_packet_size;
@@ -1104,8 +1110,8 @@ static void free_stream_urbs(struct ua101_stream *stream)
1104 1110 unsigned int i;
1105 1111
1106 1112 for (i = 0; i < stream->queue_length; ++i) {
1107 - kfree(stream->urbs[i]);
1108 - stream->urbs[i] = NULL;
1113 + usb_free_urb(stream->urbs[i].urb);
1114 + stream->urbs[i].urb = NULL;
1109 1115 }
1110 1116 }
1111 1117
modified sound/usb/quirks.c
@@ -849,6 +849,27 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
849 849 return 0;
850 850 }
851 851
852 + /*
853 + * A post configuration device descriptor read is needed to make the CM1A
854 + * operational after reenumeration.
855 + */
856 + static int snd_usb_cm1a_boot_quirk(struct usb_device *dev)
857 + {
858 + struct usb_device_descriptor *desc __free(kfree) = kmalloc_obj(*desc);
859 + int err;
860 +
861 + if (!desc)
862 + return -ENOMEM;
863 +
864 + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, sizeof(*desc));
865 + if (err < 0) {
866 + dev_err(&dev->dev, "failed to read device descriptor: %d\n", err);
867 + return err;
868 + }
869 +
870 + return 0;
871 + }
872 +
852 873 /*
853 874 * Some sound cards from Native Instruments are in fact compliant to the USB
854 875 * audio standard of version 2 and other approved USB standards, even though
@@ -1681,6 +1702,8 @@ int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
1681 1702 switch (id) {
1682 1703 case USB_ID(0x07fd, 0x0008): /* MOTU M Series, 1st hardware version */
1683 1704 return snd_usb_motu_m_series_boot_quirk(dev);
1705 + case USB_ID(0x1397, 0x1234): /* Behringer CM1A */
1706 + return snd_usb_cm1a_boot_quirk(dev);
1684 1707 }
1685 1708
1686 1709 return 0;
@@ -2390,6 +2413,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2390 2413 QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2391 2414 DEVICE_FLG(0x1397, 0x050c, /* Behringer Flow 8 */
2392 2415 QUIRK_FLAG_IFB_SILENCE_ON_EMPTY),
2416 + DEVICE_FLG(0x1397, 0x0510, /* Behringer UV1 */
2417 + QUIRK_FLAG_PLAYBACK_FIRST | QUIRK_FLAG_GENERIC_IMPLICIT_FB),
2393 2418 DEVICE_FLG(0x13e5, 0x0001, /* Serato Phono */
2394 2419 QUIRK_FLAG_IGNORE_CTL_ERROR),
2395 2420 DEVICE_FLG(0x152a, 0x85dd, /* SMSL USB DAC */
modified sound/usb/usx2y/us122l.c
@@ -180,8 +180,11 @@ static int usb_stream_hwdep_mmap(struct snd_hwdep *hw,
180 180 guard(mutex)(&us122l->mutex);
181 181 s = us122l->sk.s;
182 182 read = offset < s->read_size;
183 - if (read && area->vm_flags & VM_WRITE)
184 - return -EPERM;
183 + if (read) {
184 + if (area->vm_flags & VM_WRITE)
185 + return -EPERM;
186 + vm_flags_clear(area, VM_MAYWRITE);
187 + }
185 188 /* if userspace tries to mmap beyond end of our buffer, fail */
186 189 if (size > PAGE_ALIGN(read ? s->read_size : s->write_size)) {
187 190 dev_warn(hw->card->dev, "%s: size %lu > %u\n", __func__,
modified sound/usb/usx2y/usbusx2y.c
@@ -189,6 +189,9 @@ static void i_usx2y_in04_int(struct urb *urb)
189 189 return;
190 190 }
191 191
192 + if (urb->actual_length < USX2Y_IN04_SIZE)
193 + goto resubmit;
194 +
192 195 if (us428ctls) {
193 196 diff = -1;
194 197 if (us428ctls->ctl_snapshot_last == -2) {
@@ -196,7 +199,7 @@ static void i_usx2y_in04_int(struct urb *urb)
196 199 memcpy(usx2y->in04_last, usx2y->in04_buf, sizeof(usx2y->in04_last));
197 200 us428ctls->ctl_snapshot_last = -1;
198 201 } else {
199 - for (i = 0; i < 21; i++) {
202 + for (i = 0; i < USX2Y_IN04_SIZE; i++) {
200 203 if (usx2y->in04_last[i] != ((char *)usx2y->in04_buf)[i]) {
201 204 if (diff < 0)
202 205 diff = i;
@@ -253,6 +256,7 @@ static void i_usx2y_in04_int(struct urb *urb)
253 256 if (err)
254 257 dev_err(&urb->dev->dev, "in04_int() usb_submit_urb err=%i\n", err);
255 258
259 + resubmit:
256 260 urb->dev = usx2y->dev;
257 261 usb_submit_urb(urb, GFP_ATOMIC);
258 262 }
@@ -305,7 +309,7 @@ int usx2y_in04_init(struct usx2ydev *usx2y)
305 309 goto error;
306 310 }
307 311
308 - usx2y->in04_buf = kmalloc(21, GFP_KERNEL);
312 + usx2y->in04_buf = kzalloc(USX2Y_IN04_SIZE, GFP_KERNEL);
309 313 if (!usx2y->in04_buf) {
310 314 err = -ENOMEM;
311 315 goto error;
@@ -313,7 +317,7 @@ int usx2y_in04_init(struct usx2ydev *usx2y)
313 317
314 318 init_waitqueue_head(&usx2y->in04_wait_queue);
315 319 usb_fill_int_urb(usx2y->in04_urb, usx2y->dev, usb_rcvintpipe(usx2y->dev, 0x4),
316 - usx2y->in04_buf, 21,
320 + usx2y->in04_buf, USX2Y_IN04_SIZE,
317 321 i_usx2y_in04_int, usx2y,
318 322 10);
319 323 if (usb_urb_ep_type_check(usx2y->in04_urb)) {
modified sound/usb/usx2y/usbusx2y.h
@@ -5,6 +5,8 @@
5 5 #include "../midi.h"
6 6 #include "usbus428ctldefs.h"
7 7
8 + #define USX2Y_IN04_SIZE sizeof(struct us428_ctls)
9 +
8 10 #define NRURBS 2
9 11
10 12 /* Default value used for nr of packs per urb.
@@ -55,7 +57,7 @@ struct usx2ydev {
55 57 int stride;
56 58 struct urb *in04_urb;
57 59 void *in04_buf;
58 - char in04_last[24];
60 + char in04_last[USX2Y_IN04_SIZE];
59 61 unsigned int in04_int_calls;
60 62 struct snd_usx2y_urb_seq *us04;
61 63 wait_queue_head_t in04_wait_queue;
modified tools/bootconfig/main.c
@@ -140,6 +140,9 @@ static int load_xbc_fd(int fd, char **buf, int size)
140 140 {
141 141 int ret;
142 142
143 + if (size < 0 || size > XBC_DATA_MAX)
144 + return -EINVAL;
145 +
143 146 *buf = malloc(size + 1);
144 147 if (!*buf)
145 148 return -ENOMEM;
@@ -168,6 +171,13 @@ static int load_xbc_file(const char *path, char **buf)
168 171 return ret;
169 172 }
170 173
174 + if (stat.st_size > XBC_DATA_MAX) {
175 + pr_err("%s size is too big\n", path);
176 + ret = -E2BIG;
177 + close(fd);
178 + return ret;
179 + }
180 +
171 181 ret = load_xbc_fd(fd, buf, stat.st_size);
172 182
173 183 close(fd);
@@ -218,7 +228,8 @@ static int load_xbc_from_initrd(int fd, char **buf)
218 228 csum = le32toh(csum);
219 229
220 230 /* Wrong size error */
221 - if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
231 + if (size > XBC_DATA_MAX ||
232 + size > stat.st_size - BOOTCONFIG_FOOTER_SIZE) {
222 233 pr_err("bootconfig size is too big\n");
223 234 return -E2BIG;
224 235 }
modified tools/objtool/klp-checksum.c
@@ -54,6 +54,19 @@ static int checksum_debug_init(struct objtool_file *file)
54 54 return 0;
55 55 }
56 56
57 + /*
58 + * Detect a reference to anonymous constant pool data which the compiler places
59 + * in .rodata.cst<num> and which either has an .LC<num> symbol associated with
60 + * it or (with Clang) no symbol at all. These are typically initializers for
61 + * local function stack data, so they're considered part of the function rather
62 + * than data per se.
63 + */
64 + static bool is_anonymous_const_data(struct symbol *sym)
65 + {
66 + return strstarts(sym->sec->name, ".rodata.cst") &&
67 + (is_sec_sym(sym) || strstarts(sym->name, ".LC"));
68 + }
69 +
57 70 static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
58 71 struct instruction *insn)
59 72 {
@@ -129,6 +142,14 @@ static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
129 142 goto alts;
130 143 }
131 144
145 + if (is_anonymous_const_data(sym)) {
146 + void *cst;
147 +
148 + cst = sym->sec->data->d_buf + sym->offset + offset;
149 + __checksum_update_insn(func, insn, cst, sym->sec->sh.sh_entsize);
150 + goto alts;
151 + }
152 +
132 153 if (is_sec_sym(sym)) {
133 154 sym = find_symbol_containing(reloc->sym->sec, offset);
134 155 if (!sym)
modified tools/testing/selftests/landlock/scoped_abstract_unix_test.c
@@ -1222,7 +1222,7 @@ FIXTURE_SETUP(trace_unix)
1222 1222 int ret;
1223 1223
1224 1224 set_cap(_metadata, CAP_SYS_ADMIN);
1225 - ASSERT_EQ(0, unshare(CLONE_NEWNS));
1225 + ASSERT_EQ(0, unshare(CLONE_NEWNS | CLONE_NEWNET));
1226 1226 ASSERT_EQ(0, mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL));
1227 1227
1228 1228 ret = tracefs_fixture_setup();
@@ -1252,6 +1252,11 @@ FIXTURE_TEARDOWN(trace_unix)
1252 1252 clear_cap(_metadata, CAP_SYS_ADMIN);
1253 1253 }
1254 1254
1255 + static const char
1256 + trace_unix_max_name[sizeof(((struct sockaddr_un *)0)->sun_path)] = {
1257 + [0 ... sizeof(trace_unix_max_name) - 2] = 'x',
1258 + };
1259 +
1255 1260 /* clang-format off */
1256 1261 FIXTURE_VARIANT(trace_unix) {
1257 1262 /* clang-format on */
@@ -1259,6 +1264,8 @@ FIXTURE_VARIANT(trace_unix) {
1259 1264 bool sandbox;
1260 1265 bool sandbox_target; /* Peer owned by a domain: peer_domain != 0. */
1261 1266 int expect_denied;
1267 + const char *name; /* NULL generates a PID-based binary name. */
1268 + size_t name_len;
1262 1269 };
1263 1270
1264 1271 /* clang-format off */
@@ -1281,6 +1288,26 @@ FIXTURE_VARIANT_ADD(trace_unix, stream_allowed) {
1281 1288 .sandbox_target = false, .expect_denied = 0,
1282 1289 };
1283 1290
1291 + /* Stream: lower abstract-name length boundary. */
1292 + FIXTURE_VARIANT_ADD(trace_unix, stream_denied_empty_name) {
1293 + .sock_type = SOCK_STREAM,
1294 + .sandbox = true,
1295 + .sandbox_target = false,
1296 + .expect_denied = 1,
1297 + .name = "",
1298 + .name_len = 0,
1299 + };
1300 +
1301 + /* Stream: upper abstract-name length boundary. */
1302 + FIXTURE_VARIANT_ADD(trace_unix, stream_denied_max_name) {
1303 + .sock_type = SOCK_STREAM,
1304 + .sandbox = true,
1305 + .sandbox_target = false,
1306 + .expect_denied = 1,
1307 + .name = trace_unix_max_name,
1308 + .name_len = sizeof(trace_unix_max_name) - 1,
1309 + };
1310 +
1284 1311 /* Datagram: sandboxed client sendto() an unsandboxed peer (peer_domain=0). */
1285 1312 FIXTURE_VARIANT_ADD(trace_unix, dgram_denied) {
1286 1313 .sock_type = SOCK_DGRAM, .sandbox = true,
@@ -1304,12 +1331,11 @@ FIXTURE_VARIANT_ADD(trace_unix, dgram_allowed) {
1304 1331 /*
1305 1332 * A sandboxed thread reaching an abstract unix socket peer through connect(2)
1306 1333 * (stream) or sendto(2) (datagram) is denied and emits
1307 - * landlock_deny_scope_abstract_unix_socket. The abstract name is crafted with
1308 - * a space and an embedded NUL followed by an "END" marker to check the
1309 - * tracepoint escaping and its length handling (a raw space would break the
1310 - * sun_path field regex; strlen() would truncate at the NUL and drop "END").
1311 - * peer_pid is only meaningful for a stream peer (a datagram peer has no
1312 - * SO_PEERCRED), so it is asserted only there.
1334 + * landlock_deny_scope_abstract_unix_socket. The default abstract name has a
1335 + * space and an embedded NUL followed by an "END" marker to check escaping and
1336 + * binary length handling. Additional stream variants cover the minimum and
1337 + * maximum abstract-name lengths. peer_pid is only meaningful for a stream peer
1338 + * (a datagram peer has no SO_PEERCRED), so it is asserted only there.
1313 1339 */
1314 1340 TEST_F(trace_unix, deny_scope_unix)
1315 1341 {
@@ -1336,12 +1362,19 @@ TEST_F(trace_unix, deny_scope_unix)
1336 1362 ASSERT_LE(0, server_fd);
1337 1363
1338 1364 addr.sun_path[0] = '\0';
1339 - name_len = snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1,
1340 - "landlock_trace_test_%d ", getpid());
1341 - addr.sun_path[1 + name_len] = '\0';
1342 - memcpy(addr.sun_path + 1 + name_len + 1, "END", 3);
1343 - addr_len =
1344 - offsetof(struct sockaddr_un, sun_path) + 1 + name_len + 1 + 3;
1365 + if (variant->name) {
1366 + ASSERT_LE(variant->name_len, sizeof(addr.sun_path) - 1);
1367 + memcpy(addr.sun_path + 1, variant->name, variant->name_len);
1368 + name_len = variant->name_len;
1369 + } else {
1370 + name_len = snprintf(addr.sun_path + 1,
1371 + sizeof(addr.sun_path) - 1,
1372 + "landlock_trace_test_%d ", getpid());
1373 + addr.sun_path[1 + name_len] = '\0';
1374 + memcpy(addr.sun_path + 1 + name_len + 1, "END", 3);
1375 + name_len += 1 + 3;
1376 + }
1377 + addr_len = offsetof(struct sockaddr_un, sun_path) + 1 + name_len;
1345 1378
1346 1379 ASSERT_EQ(0, bind(server_fd, (struct sockaddr *)&addr, addr_len));
1347 1380 if (variant->sock_type == SOCK_STREAM)
@@ -1430,19 +1463,18 @@ TEST_F(trace_unix, deny_scope_unix)
1430 1463 count, buf);
1431 1464 }
1432 1465
1433 - /*
1434 - * sun_path is escaped: a raw space would break this field's [^ ]*$
1435 - * regex, so a successful extract proves the space was escaped, and its
1436 - * full length is honored: the "END" marker after the embedded NUL must
1437 - * survive (strlen() would truncate it at the NUL).
1438 - */
1439 1466 ASSERT_EQ(0, tracefs_extract_field(
1440 1467 buf,
1441 1468 REGEX_DENY_SCOPE_ABSTRACT_UNIX_SOCKET(TRACE_TASK),
1442 1469 "sun_path", field, sizeof(field)));
1443 - EXPECT_NE(NULL, strstr(field, "END"))
1444 - {
1445 - TH_LOG("sun_path truncated or unescaped: %s", field);
1470 + if (variant->name) {
1471 + EXPECT_STREQ(variant->name, field);
1472 + } else {
1473 + /* An embedded NUL must not truncate the following marker. */
1474 + EXPECT_NE(NULL, strstr(field, "END"))
1475 + {
1476 + TH_LOG("sun_path truncated or unescaped: %s", field);
1477 + }
1446 1478 }
1447 1479
1448 1480 /* peer_pid is the parent's PID for a stream peer (0 for datagram). */
modified tools/testing/selftests/landlock/trace_fs_test.c
@@ -6,8 +6,10 @@
6 6 */
7 7
8 8 #define _GNU_SOURCE
9 + #include <assert.h>
9 10 #include <errno.h>
10 11 #include <fcntl.h>
12 + #include <limits.h>
11 13 #include <linux/landlock.h>
12 14 #include <sched.h>
13 15 #include <stdio.h>
@@ -23,6 +25,63 @@
23 25
24 26 #define TRACE_TASK "trace_fs_test"
25 27
28 + /* Mirrors TRACE_SEQ_SIZE, conservatively larger than the usable buffer. */
29 + #define TRACE_SEQUENCE_SIZE 8192
30 + #define OCTAL_ESCAPE_LEN 4
31 + #define LONG_PATH_COMPONENT_COUNT 11
32 + #define LONG_PATH_COMPONENT_LEN 240
33 + #define LONG_PATH_LEN \
34 + (LONG_PATH_COMPONENT_COUNT * (LONG_PATH_COMPONENT_LEN + 1) + \
35 + sizeof("/tmp"))
36 + #define LONG_ESCAPED_PATH_LEN \
37 + (LONG_PATH_COMPONENT_COUNT * LONG_PATH_COMPONENT_LEN * OCTAL_ESCAPE_LEN)
38 +
39 + static_assert(LONG_ESCAPED_PATH_LEN > TRACE_SEQUENCE_SIZE,
40 + "escaped path must exceed the trace sequence");
41 + static_assert(LONG_PATH_LEN < PATH_MAX, "path must fit in PATH_MAX");
42 +
43 + static void create_long_path(struct __test_metadata *const _metadata,
44 + char *path)
45 + {
46 + size_t path_len;
47 +
48 + strcpy(path, "/tmp");
49 + path_len = strlen(path);
50 +
51 + set_cap(_metadata, CAP_SYS_ADMIN);
52 + ASSERT_EQ(0, mount("tmpfs", "/tmp", "tmpfs", 0, NULL));
53 + clear_cap(_metadata, CAP_SYS_ADMIN);
54 +
55 + for (int i = 0; i < LONG_PATH_COMPONENT_COUNT; i++) {
56 + path[path_len++] = '/';
57 + memset(path + path_len, ' ', LONG_PATH_COMPONENT_LEN);
58 + path_len += LONG_PATH_COMPONENT_LEN;
59 + path[path_len] = '\0';
60 + ASSERT_EQ(0, mkdir(path, 0700));
61 + }
62 + }
63 +
64 + static void expect_truncated_path(struct __test_metadata *const _metadata,
65 + const char *const trace,
66 + const char *const event_regex)
67 + {
68 + static const char marker[] = "\xe2\x80\xa6";
69 + char *path;
70 + size_t path_len;
71 +
72 + path = malloc(TRACE_SEQUENCE_SIZE);
73 + ASSERT_NE(NULL, path);
74 + ASSERT_EQ(0, tracefs_extract_field(trace, event_regex, "path", path,
75 + TRACE_SEQUENCE_SIZE));
76 + EXPECT_EQ(path, strstr(path, "/tmp/"));
77 + EXPECT_NE(NULL, strstr(path, "\\040"));
78 +
79 + path_len = strlen(path);
80 + ASSERT_LE(sizeof(marker) - 1, path_len);
81 + EXPECT_STREQ(marker, path + path_len - (sizeof(marker) - 1));
82 + free(path);
83 + }
84 +
26 85 /*
27 86 * Like REGEX_DENY_ACCESS_FS(), but pins the logged field to a specific value
28 87 * ("0" or "1") so a test can tell a suppressed (quiet) denial from a logged
@@ -183,6 +242,107 @@ TEST_F(trace_fs, add_rule_fs)
183 242 free(buf);
184 243 }
185 244
245 + /*
246 + * Verifies that a path whose escaping exceeds the trace scratch sequence does
247 + * not corrupt a sibling symbolic field.
248 + */
249 + TEST_F(trace_fs, add_rule_fs_escaped_path_overflow)
250 + {
251 + static const char access_prefix[] = "execute|write_file|read_file|";
252 + static const char access_suffix[] = "|ioctl_dev|resolve_unix";
253 + struct landlock_ruleset_attr ruleset_attr = {
254 + .handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE,
255 + };
256 + struct landlock_path_beneath_attr path_beneath = {
257 + .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
258 + };
259 + char path[PATH_MAX];
260 + char *buf, field_buf[256];
261 + size_t field_len;
262 + int ruleset_fd, count;
263 +
264 + create_long_path(_metadata, path);
265 +
266 + ruleset_fd =
267 + landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
268 + ASSERT_LE(0, ruleset_fd);
269 + path_beneath.parent_fd = open(path, O_PATH | O_DIRECTORY | O_CLOEXEC);
270 + ASSERT_LE(0, path_beneath.parent_fd);
271 +
272 + ASSERT_EQ(0, landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
273 + &path_beneath, 0));
274 + ASSERT_EQ(0, close(path_beneath.parent_fd));
275 + ASSERT_EQ(0, close(ruleset_fd));
276 +
277 + buf = tracefs_read_buf();
278 + ASSERT_NE(NULL, buf);
279 +
280 + count = tracefs_count_matches(buf, REGEX_ADD_RULE_FS(TRACE_TASK));
281 + EXPECT_EQ(1, count)
282 + {
283 + TH_LOG("Expected 1 add_rule_fs event, got %d\n%s", count, buf);
284 + }
285 +
286 + /*
287 + * The marker catches a full revert with any compiler. The symbolic
288 + * field also catches scratch-sequence poisoning when the compiler
289 + * evaluates the overflowing path first, as GCC currently does.
290 + */
291 + ASSERT_EQ(0, tracefs_extract_field(buf, REGEX_ADD_RULE_FS(TRACE_TASK),
292 + "access_rights", field_buf,
293 + sizeof(field_buf)));
294 + EXPECT_EQ(0,
295 + strncmp(field_buf, access_prefix, sizeof(access_prefix) - 1));
296 + EXPECT_EQ(NULL, strstr(field_buf, "|refer|"));
297 + field_len = strlen(field_buf);
298 + ASSERT_LE(sizeof(access_suffix) - 1, field_len);
299 + EXPECT_STREQ(access_suffix,
300 + field_buf + field_len - (sizeof(access_suffix) - 1));
301 + expect_truncated_path(_metadata, buf, REGEX_ADD_RULE_FS(TRACE_TASK));
302 +
303 + free(buf);
304 + }
305 +
306 + /*
307 + * Verifies that an overflowing denied path does not corrupt its sibling
308 + * symbolic blockers field.
309 + */
310 + TEST_F(trace_fs, deny_access_fs_escaped_path_overflow)
311 + {
312 + char path[PATH_MAX];
313 + char *buf, field_buf[64];
314 + int count, err;
315 +
316 + create_long_path(_metadata, path);
317 + ASSERT_EQ(0, tracefs_clear_buf());
318 +
319 + sandbox_child_fs_access(_metadata, "/usr", LANDLOCK_ACCESS_FS_READ_DIR,
320 + LANDLOCK_ACCESS_FS_READ_DIR, path);
321 +
322 + buf = tracefs_read_buf();
323 + ASSERT_NE(NULL, buf);
324 +
325 + count = tracefs_count_matches(buf, REGEX_DENY_ACCESS_FS(TRACE_TASK));
326 + EXPECT_EQ(1, count)
327 + {
328 + TH_LOG("Expected 1 deny_access_fs event, got %d\n%s", count,
329 + buf);
330 + }
331 +
332 + /*
333 + * The marker catches a full revert with any compiler. The symbolic
334 + * field also catches scratch-sequence poisoning when the compiler
335 + * evaluates the overflowing path first, as GCC currently does.
336 + */
337 + err = tracefs_extract_field(buf, REGEX_DENY_ACCESS_FS(TRACE_TASK),
338 + "blockers", field_buf, sizeof(field_buf));
339 + ASSERT_EQ(0, err);
340 + EXPECT_STREQ("read_dir", field_buf);
341 + expect_truncated_path(_metadata, buf, REGEX_DENY_ACCESS_FS(TRACE_TASK));
342 +
343 + free(buf);
344 + }
345 +
186 346 /*
187 347 * Verifies that an allowed access emits check_rule events (rule matched during
188 348 * pathwalk) but does NOT emit deny_access events (no denial).
modified tools/testing/selftests/net/Makefile
@@ -25,6 +25,7 @@ TEST_PROGS := \
25 25 cmsg_so_mark.sh \
26 26 cmsg_so_priority.sh \
27 27 cmsg_time.sh \
28 + cork_fragsize.py \
28 29 double_udp_encap.sh \
29 30 drop_monitor_tests.sh \
30 31 ecmp_rehash.sh \
modified tools/testing/selftests/net/af_unix/msg_oob.c
@@ -290,6 +290,25 @@ static void __setinlinepair(struct __test_metadata *_metadata,
290 290 }
291 291 }
292 292
293 + static void __setblockingpair(struct __test_metadata *_metadata,
294 + FIXTURE_DATA(msg_oob) *self)
295 + {
296 + int i;
297 +
298 + for (i = 0; i < 2; i++) {
299 + int ret, old_flags, flags;
300 +
301 + old_flags = fcntl(self->fd[i * 2 + 1], F_GETFL, 0);
302 + ASSERT_NE(-1, old_flags);
303 +
304 + ret = fcntl(self->fd[i * 2 + 1], F_SETFL, old_flags & ~O_NONBLOCK);
305 + ASSERT_EQ(0, ret);
306 +
307 + flags = fcntl(self->fd[i * 2 + 1], F_GETFL, 0);
308 + ASSERT_EQ(old_flags & ~O_NONBLOCK, flags);
309 + }
310 + }
311 +
293 312 static void __siocatmarkpair(struct __test_metadata *_metadata,
294 313 FIXTURE_DATA(msg_oob) *self,
295 314 bool oob_head)
@@ -347,6 +366,9 @@ static void __resetpair(struct __test_metadata *_metadata,
347 366 #define setinlinepair() \
348 367 __setinlinepair(_metadata, self)
349 368
369 + #define setblockingpair() \
370 + __setblockingpair(_metadata, self)
371 +
350 372 #define resetpair(reset) \
351 373 __resetpair(_metadata, self, variant, reset)
352 374
@@ -888,4 +910,49 @@ TEST_F(msg_oob, inline_ex_oob_siocatmark)
888 910 resetpair(true);
889 911 }
890 912
913 + TEST_F(msg_oob, zero_buf_oob)
914 + {
915 + sendpair("a", 1, MSG_OOB);
916 + recvpair("", 0, 0, 0);
917 + }
918 +
919 + TEST_F(msg_oob, zero_buf_oob_blocking)
920 + {
921 + sendpair("a", 1, MSG_OOB);
922 + setblockingpair();
923 + recvpair("", 0, 0, 0);
924 + }
925 +
926 + TEST_F(msg_oob, zero_buf_non_oob_oob)
927 + {
928 + sendpair("ab", 2, MSG_OOB);
929 + recvpair("", 0, 0, 0);
930 + }
931 +
932 + TEST_F(msg_oob, zero_buf_non_oob_oob_blocking)
933 + {
934 + sendpair("ab", 2, MSG_OOB);
935 + setblockingpair();
936 + recvpair("", 0, 0, 0);
937 + }
938 +
939 + TEST_F(msg_oob, zero_buf_ex_oob_oob)
940 + {
941 + sendpair("a", 1, MSG_OOB);
942 + recvpair("a", 1, 1, MSG_OOB);
943 +
944 + sendpair("b", 1, MSG_OOB);
945 + recvpair("", 0, 0, 0);
946 + }
947 +
948 + TEST_F(msg_oob, zero_buf_ex_oob_oob_blocking)
949 + {
950 + sendpair("a", 1, MSG_OOB);
951 + recvpair("a", 1, 1, MSG_OOB);
952 +
953 + sendpair("b", 1, MSG_OOB);
954 + setblockingpair();
955 + recvpair("", 0, 0, 0);
956 + }
957 +
891 958 TEST_HARNESS_MAIN
added tools/testing/selftests/net/cork_fragsize.py mode 100755
@@ -0,0 +1,187 @@
1 + #!/usr/bin/env python3
2 + # SPDX-License-Identifier: GPL-2.0
3 +
4 + '''Test possible UDP length overflow in udp_send_skb/udp_v6_send_skb.'''
5 +
6 + import errno
7 + import gzip
8 + import os
9 + import socket
10 + import struct
11 + import subprocess
12 + from contextlib import contextmanager
13 +
14 + from lib.py import (
15 + KsftNamedVariant,
16 + KsftSkipEx,
17 + NetNS,
18 + NetNSEnter,
19 + defer,
20 + ip,
21 + ksft_eq,
22 + ksft_exit,
23 + ksft_pr,
24 + ksft_raises,
25 + ksft_run,
26 + ksft_true,
27 + ksft_variants,
28 + )
29 +
30 + IP_MTU_DISCOVER = 10
31 + IP_PMTUDISC_PROBE = 3
32 + IPV6_MTU_DISCOVER = 23
33 + IPV6_PMTUDISC_DO = 2
34 + IPV6_PMTUDISC_PROBE = 3
35 + IPV6_TLV_JUMBO = 194
36 +
37 +
38 + def check_kernel_config(option: str) -> bool | None:
39 + '''
40 + Check whether the option is enabled in the config of the running kernel.
41 + Returns None if the config is not found; otherwise returns True/False
42 + depending on the option value in the config.
43 + '''
44 +
45 + for filename, method in [
46 + ('/proc/config.gz', gzip.open),
47 + (f'/boot/config-{os.uname().release}', open),
48 + ]:
49 + try:
50 + with method(filename, 'rt') as config:
51 + for line in config:
52 + if line.rstrip() == f'{option}=y':
53 + return True
54 + return False
55 + except OSError:
56 + continue
57 + return None
58 +
59 +
60 + def assert_debug_kernel() -> None:
61 + '''
62 + Skip the test if CONFIG_DEBUG_NET is not set in the kernel config.
63 + '''
64 +
65 + res = check_kernel_config('CONFIG_DEBUG_NET')
66 + if res is None:
67 + ksft_pr("WARN: Can't read kernel config; assuming debug kernel, and running the test")
68 + elif not res:
69 + raise KsftSkipEx('CONFIG_DEBUG_NET is not set')
70 +
71 +
72 + def check_dmesg_clean(func: str) -> bool:
73 + '''
74 + Check if the given function produced a WARN in dmesg.
75 + '''
76 +
77 + with subprocess.Popen(['dmesg'], stdout=subprocess.PIPE) as dmesg:
78 + res = subprocess.run(['grep', '-q', f'WARNING:.*{func}'], stdin=dmesg.stdout, check=False)
79 + return res.returncode != 0 and dmesg.returncode == 0
80 +
81 +
82 + @contextmanager
83 + def dummy_netdev(ns: NetNS, mtu: int, ipv6: bool) -> None:
84 + '''
85 + Create a dummy netdev inside the given namespace, and tune it for the test.
86 + '''
87 +
88 + ip('link add dummy type dummy', ns=ns)
89 + with defer(ip, 'link del dummy', ns=ns):
90 + ip(f'link set dummy mtu {mtu}', ns=ns)
91 + ip('link set dummy up', ns=ns)
92 + flag = '-6' if ipv6 else ''
93 + nodad = 'nodad' if ipv6 else ''
94 + local = 'fd00::1/64' if ipv6 else '10.0.0.1/24'
95 + remote = 'fd00::2' if ipv6 else '10.0.0.2'
96 + ip(f'{flag} addr add {local} dev dummy {nodad}', ns=ns)
97 + ip(f'{flag} neigh add {remote} lladdr 02:00:00:00:00:02 dev dummy nud permanent', ns=ns)
98 + yield
99 +
100 +
101 + @ksft_variants([
102 + KsftNamedVariant(
103 + 'ipv6',
104 + True,
105 + socket.AF_INET6,
106 + (socket.IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_DO),
107 + 'fd00::2',
108 + 'udp_v6_send_skb',
109 + ),
110 + KsftNamedVariant(
111 + 'ipv4',
112 + False,
113 + socket.AF_INET,
114 + (socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_PROBE),
115 + '10.0.0.2',
116 + 'udp_send_skb',
117 + ),
118 + ])
119 + def test_udp(
120 + ipv6: bool,
121 + af: socket.AddressFamily,
122 + sockopts: tuple[int, int, int],
123 + destip: str,
124 + func: str
125 + ) -> None:
126 + '''
127 + Test that sending an oversized UDP packet over a UDP socket doesn't overflow
128 + the 16-bit length field in the UDP header, which could happen on older
129 + kernels in udp_send_skb/udp_v6_send_skb.
130 +
131 + IPv4: The packet will be dropped with EMSGSIZE, but the overflow could
132 + happen before it happens. The only way to test this is to check dmesg on
133 + CONFIG_DEBUG_NET=y kernels that have udp_set_len_short with the warning.
134 +
135 + IPv6: The packet will be dropped with EMSGSIZE on fixed kernels, and will be
136 + sent corrupted on older kernels. Test both: sendto must return EMSGSIZE, and
137 + dmesg must be clean of warnings on CONFIG_DEBUG_NET=y kernels.
138 + '''
139 +
140 + if not ipv6:
141 + assert_debug_kernel()
142 +
143 + with (
144 + NetNS() as ns,
145 + dummy_netdev(ns, 65556 + 20 * ipv6, ipv6),
146 + NetNSEnter(ns),
147 + socket.socket(af, socket.SOCK_DGRAM) as fd,
148 + ):
149 + fd.setsockopt(*sockopts)
150 + with ksft_raises(OSError) as e:
151 + fd.sendto(b' ' * 65528, (destip, 1234))
152 + # IPv6: EMSGSIZE happens on kernels with the fix.
153 + # IPv4: EMSGSIZE happens on both fixed and unfixed kernels, after the
154 + # WARN is printed - ignore it and rely on the dmesg check.
155 + if e.exception is not None:
156 + ksft_eq(e.exception.errno, errno.EMSGSIZE)
157 +
158 + ksft_true(check_dmesg_clean(func), 'WARNING detected in dmesg')
159 +
160 +
161 + def test_ipv6_jumbo() -> None:
162 + '''
163 + Test that sending UDP jumbograms over a raw IPv6 socket works, despite
164 + having the fix for oversized UDP packets. sendto must not raise an OSError
165 + exception (when raised, the test fails automatically).
166 + '''
167 +
168 + with (
169 + NetNS() as ns,
170 + dummy_netdev(ns, 65584, True),
171 + NetNSEnter(ns),
172 + socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_UDP) as fd,
173 + ):
174 + hopopts = struct.pack('!BBBBI', 0, 0, IPV6_TLV_JUMBO, 4, 65544)
175 + fd.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_HOPOPTS, hopopts)
176 + fd.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_CHECKSUM, 6)
177 + fd.setsockopt(socket.IPPROTO_IPV6, IPV6_MTU_DISCOVER, IPV6_PMTUDISC_PROBE)
178 + udp = struct.pack('!HHHH', 1234, 1234, 0, 0) + b' ' * 65528
179 + fd.sendto(udp, ('fd00::2', 0))
180 +
181 +
182 + if __name__ == "__main__":
183 + ksft_run([
184 + test_udp,
185 + test_ipv6_jumbo,
186 + ])
187 + ksft_exit()
modified tools/testing/selftests/net/fib_nexthops.sh
@@ -533,6 +533,20 @@ ipv6_fdb_grp_fcnal()
533 533 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 61 self"
534 534 log_test $? 255 "Fdb mac add with nexthop"
535 535
536 + # fdb entries with a nexthop group cannot be aged out
537 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:15 dev vx10 nhid 102 self static"
538 + log_test $? 0 "Fdb mac add with nexthop group and static state"
539 +
540 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic"
541 + log_test $? 255 "Fdb mac add with nexthop group and dynamic state"
542 +
543 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self"
544 + run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic"
545 + log_test $? 255 "Fdb mac replace with nexthop group and dynamic state"
546 +
547 + run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 2001:db8:91::11 self dynamic"
548 + log_test $? 255 "Fdb mac append with nexthop group and dynamic state"
549 +
536 550 run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 66"
537 551 log_test $? 2 "Route add with fdb nexthop"
538 552
@@ -669,6 +683,20 @@ ipv4_fdb_grp_fcnal()
669 683 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 12 self"
670 684 log_test $? 255 "Fdb mac add with nexthop"
671 685
686 + # fdb entries with a nexthop group cannot be aged out
687 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:15 dev vx10 nhid 102 self static"
688 + log_test $? 0 "Fdb mac add with nexthop group and static state"
689 +
690 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:16 dev vx10 nhid 102 self dynamic"
691 + log_test $? 255 "Fdb mac add with nexthop group and dynamic state"
692 +
693 + run_cmd "$BRIDGE fdb add 02:02:00:00:00:17 dev vx10 nhid 102 self"
694 + run_cmd "$BRIDGE fdb replace 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic"
695 + log_test $? 255 "Fdb mac replace with nexthop group and dynamic state"
696 +
697 + run_cmd "$BRIDGE fdb append 02:02:00:00:00:17 dev vx10 dst 10.0.0.3 self dynamic"

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