Compare
f90f8afb61beb268ca8092e7f3a826b520d3e8da..6a8bf59de3ef47ff51face6ea826395a1098baa0
drm/i915/cx0_phy: Fix ARL-S host bridge detection
Fix is_arrowlake_s_by_host_bridge() which always returned false.
The while loop always exits with pdev as NULL, so the return
condition was always false, causing the wrong tx_misc value to be used.
Check the host bridge ID inside the loop body. Once found early exit
from the loop release the pci reference "pdev" and return true.
v2:
- Update commit message (Chaitanya)
Bspec:74165,74491
Suggested-by: Jani Nikula <jani.nikula@intel.com>
Cc: <stable@vger.kernel.org>
Fixes: 3630a47b700e ("drm/i915/cx0_phy: Update HDMI TMDS C20 algorithm value")
Signed-off-by: Dnyaneshwar Bhadane <dnyaneshwar.bhadane@intel.com>
Reviewed-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Signed-off-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Link: https://patch.msgid.link/20260921090226.946472-1-dnyaneshwar.bhadane@intel.com
(cherry picked from commit 0507cc5a476af0b6d037b19248bdd20dbe27487d)
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Dnyaneshwar Bhadane <dnyaneshwar.bhadane@intel.com> · 2026-09-21 09:02 UTC · committed by Joonas Lahtinen
391 files changed,
+10799
−1766
- .mailmap
- Documentation/admin-guide/ext4.rst
- Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
- Documentation/filesystems/propagate_umount.txt
- Documentation/filesystems/sharedsubtree.rst
- Documentation/networking/strparser.rst
- MAINTAINERS
- Makefile
- arch/arm64/boot/dts/freescale/fsl-lx216x.dtsi
- arch/arm64/boot/dts/freescale/imx8mp-var-dart-sonata.dts
- arch/arm64/boot/dts/qcom/x1-microsoft-denali.dtsi
- arch/arm64/include/asm/el2_setup.h
- arch/arm64/kernel/Makefile
- arch/riscv/Kconfig
- arch/riscv/Kconfig.errata
- arch/riscv/Kconfig.socs
- arch/riscv/errata/sifive/errata.c
- arch/riscv/include/asm/cpufeature.h
- arch/riscv/include/asm/errata_list_vendors.h
- arch/riscv/include/asm/futex.h
- arch/riscv/include/asm/insn-def.h
- arch/riscv/include/asm/scs.h
- arch/riscv/include/asm/vector.h
- arch/riscv/include/uapi/asm/vendor/mips.h
- arch/riscv/kernel/cpufeature.c
- arch/riscv/kernel/entry.S
- arch/riscv/kernel/patch.c
- arch/riscv/kernel/ptrace.c
- arch/riscv/kernel/setup.c
- arch/riscv/kernel/smpboot.c
- arch/riscv/kernel/suspend.c
- arch/riscv/lib/strnlen.S
- arch/riscv/mm/extable.c
- arch/um/drivers/vector_transports.c
- arch/x86/include/asm/cpufeatures.h
- arch/x86/include/asm/tlb.h
- arch/x86/kernel/cpu/amd.c
- drivers/accessibility/braille/braille_console.c
- drivers/ata/libata-scsi.c
- drivers/block/zloop.c
- drivers/bluetooth/btintel_pcie.c
- drivers/char/mem.c
- drivers/clk/qcom/gcc-eliza.c
- drivers/clk/qcom/gcc-hawi.c
- drivers/clk/qcom/gcc-kaanapali.c
- drivers/clk/qcom/gpucc-glymur.c
- drivers/clk/qcom/gpucc-kaanapali.c
- drivers/edac/amd64_edac.c
- drivers/gpio/gpio-exar.c
- drivers/gpio/gpio-mpsse.c
- drivers/gpio/gpio-xilinx.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
- drivers/gpu/drm/amd/amdkfd/kfd_priv.h
- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
- drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
- drivers/gpu/drm/aspeed/aspeed_gfx_drv.c
- drivers/gpu/drm/bridge/th1520-dw-hdmi.c
- drivers/gpu/drm/display/drm_dp_helper.c
- drivers/gpu/drm/drm_bridge.c
- drivers/gpu/drm/drm_fb_helper.c
- drivers/gpu/drm/gud/gud_pipe.c
- drivers/gpu/drm/i915/display/intel_cx0_phy.c
- drivers/gpu/drm/i915/display/intel_dmc.c
- drivers/gpu/drm/i915/display/intel_dmc_regs.h
- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
- drivers/gpu/drm/i915/gt/intel_rps.c
- drivers/gpu/drm/imagination/pvr_mmu.c
- drivers/gpu/drm/imagination/pvr_vm.c
- drivers/gpu/drm/nouveau/nouveau_abi16.c
- drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
- drivers/gpu/drm/panthor/panthor_sched.c
- drivers/gpu/drm/vc4/vc4_bo.c
- drivers/gpu/drm/vc4/vc4_drv.c
- drivers/gpu/drm/vc4/vc4_drv.h
- drivers/gpu/drm/vc4/vc4_gem.c
- drivers/gpu/drm/vc4/vc4_irq.c
- drivers/gpu/drm/vc4/vc4_v3d.c
- drivers/gpu/drm/vc4/vc4_validate.c
- drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
- drivers/gpu/drm/xe/display/xe_fb_pin.c
- drivers/gpu/drm/xe/xe_bo.c
- drivers/gpu/drm/xe/xe_bo.h
- drivers/gpu/drm/xe/xe_i2c.c
- drivers/gpu/drm/xe/xe_lrc.c
- drivers/gpu/drm/xe/xe_mmio.c
- drivers/gpu/drm/xe/xe_sysctrl_mailbox.c
- drivers/i2c/busses/i2c-qcom-geni.c
- drivers/input/joystick/xpad.c
- drivers/input/misc/ati_remote2.c
- drivers/iommu/dma-iommu.c
- drivers/md/dm-crypt.c
- drivers/md/dm-integrity.c
- drivers/md/dm-ioctl.c
- drivers/md/dm-snap.c
- drivers/media/usb/em28xx/em28xx-video.c
- drivers/memstick/core/memstick.c
- drivers/memstick/host/rtsx_usb_ms.c
- drivers/mmc/host/cavium-octeon.c
- drivers/mmc/host/cavium-thunderx.c
- drivers/mmc/host/mtk-sd.c
- drivers/mmc/host/sdhci-sprd.c
- drivers/net/amt.c
- drivers/net/bareudp.c
- drivers/net/bonding/bond_main.c
- drivers/net/can/dev/skb.c
- drivers/net/can/usb/f81604.c
- drivers/net/can/vxcan.c
- drivers/net/dsa/microchip/ksz_common.h
- drivers/net/ethernet/airoha/airoha_eth.c
- drivers/net/ethernet/airoha/airoha_eth.h
- drivers/net/ethernet/allwinner/sun4i-emac.c
- drivers/net/ethernet/broadcom/bnxt/bnxt.c
- drivers/net/ethernet/broadcom/bnxt/bnxt.h
- drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c
- drivers/net/ethernet/cadence/macb_main.c
- drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
- drivers/net/ethernet/google/gve/gve_main.c
- drivers/net/ethernet/google/gve/gve_rx_dqo.c
- drivers/net/ethernet/ibm/ibmveth.c
- drivers/net/ethernet/intel/e1000e/netdev.c
- drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
- drivers/net/ethernet/intel/iavf/iavf.h
- drivers/net/ethernet/intel/iavf/iavf_main.c
- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
- drivers/net/ethernet/intel/ice/devlink/port.c
- drivers/net/ethernet/intel/ice/ice_eswitch.c
- drivers/net/ethernet/intel/ice/ice_sriov.c
- drivers/net/ethernet/intel/ice/ice_txrx.c
- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
- drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
- drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
- drivers/net/ethernet/mellanox/mlx5/core/vport.c
- drivers/net/ethernet/mellanox/mlxsw/spectrum.h
- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
- drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
- drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
- drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
- drivers/net/ethernet/microsoft/mana/mana_bpf.c
- drivers/net/ethernet/microsoft/mana/mana_en.c
- drivers/net/ethernet/microsoft/mana/mana_ethtool.c
- drivers/net/ethernet/stmicro/stmmac/hwif.h
- drivers/net/ethernet/stmicro/stmmac/stmmac.h
- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
- drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
- drivers/net/ethernet/xilinx/xilinx_axienet.h
- drivers/net/ethernet/xilinx/xilinx_axienet_main.c
- drivers/net/pfcp.c
- drivers/net/team/team_core.c
- drivers/net/team/team_mode_broadcast.c
- drivers/net/tun.c
- drivers/net/usb/ax88179_178a.c
- drivers/net/veth.c
- drivers/net/virtio_net.c
- drivers/net/wireguard/noise.c
- drivers/net/wireguard/queueing.h
- drivers/net/wireless/ath/ath12k/core.c
- drivers/net/wireless/ath/ath12k/core.h
- drivers/net/wireless/ath/ath12k/hif.h
- drivers/net/wireless/ath/ath12k/pci.c
- drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
- drivers/net/wireless/marvell/libertas/tx.c
- drivers/net/wireless/mediatek/mt76/mt76.h
- drivers/net/wireless/mediatek/mt76/mt7603/init.c
- drivers/net/wireless/mediatek/mt76/mt7915/init.c
- drivers/net/wireless/mediatek/mt76/mt7915/main.c
- drivers/net/wireless/mediatek/mt76/mt7925/mac.c
- drivers/net/wireless/mediatek/mt76/mt7925/main.c
- drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
- drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h
- drivers/net/wireless/mediatek/mt76/mt7996/init.c
- drivers/net/wireless/mediatek/mt76/mt7996/main.c
- drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
- drivers/net/wireless/mediatek/mt76/tx.c
- drivers/net/wireless/nxp/nxpwifi/11n.c
- drivers/net/wireless/nxp/nxpwifi/11n_aggr.c
- drivers/net/wireless/nxp/nxpwifi/11n_rxreorder.c
- drivers/net/wireless/nxp/nxpwifi/cfg80211.c
- drivers/net/wireless/nxp/nxpwifi/init.c
- drivers/net/wireless/nxp/nxpwifi/main.c
- drivers/net/wireless/nxp/nxpwifi/uap_event.c
- drivers/net/wireless/nxp/nxpwifi/util.c
- drivers/net/xen-netfront.c
- drivers/nvme/host/core.c
- drivers/nvme/target/core.c
- drivers/nvme/target/pr.c
- drivers/pci/pcie/aer.c
- drivers/pmdomain/imx/imx8m-blk-ctrl.c
- drivers/pmdomain/rockchip/pm-domains.c
- drivers/power/sequencing/pwrseq-pcie-m2.c
- drivers/ptp/ptp_ocp.c
- drivers/regulator/ltc3676.c
- drivers/regulator/of_regulator.c
- drivers/regulator/tps6594-regulator.c
- drivers/scsi/ch.c
- drivers/scsi/qedi/qedi_main.c
- drivers/spi/spi-cadence-quadspi.c
- drivers/spi/spi-nxp-fspi.c
- drivers/spi/spi-sg2044-nor.c
- drivers/tee/optee/ffa_abi.c
- drivers/tee/optee/optee_msg.h
- drivers/tee/optee/smc_abi.c
- drivers/tee/qcomtee/async.c
- drivers/tee/qcomtee/qcomtee_msg.h
- drivers/tee/qcomtee/qcomtee_object.h
- drivers/tee/tee_shm.c
- drivers/tty/serial/8250/8250_port.c
- drivers/tty/serial/amba-pl011.c
- drivers/tty/serial/imx.c
- drivers/tty/serial/sifive.c
- drivers/ufs/core/ufs-mcq.c
- drivers/ufs/core/ufshcd.c
- drivers/ufs/host/ufs-mediatek.c
- drivers/usb/mtu3/mtu3_trace.h
- fs/btrfs/inode.c
- fs/btrfs/ioctl.c
- fs/btrfs/scrub.c
- fs/btrfs/transaction.c
- fs/btrfs/xattr.c
- fs/dcache.c
- fs/ext4/super.c
- fs/fcntl.c
- fs/fhandle.c
- fs/file_table.c
- fs/fs_context.c
- fs/mount.h
- fs/namei.c
- fs/namespace.c
- fs/notify/mark.c
- fs/nullfs.c
- fs/pnode.c
- fs/readdir.c
- fs/verity/fsverity_private.h
- fs/verity/open.c
- fs/xfs/libxfs/xfs_exchmaps.c
- fs/xfs/libxfs/xfs_log_format.h
- fs/xfs/xfs_bmap_util.c
- fs/xfs/xfs_exchrange.c
- include/linux/can/core.h
- include/linux/can/skb.h
- include/linux/console.h
- include/linux/fs.h
- include/linux/io_uring_types.h
- include/linux/mount.h
- include/linux/nsproxy.h
- include/linux/nvme.h
- include/linux/sched/ext.h
- include/linux/virtio_net.h
- include/net/amt.h
- include/net/bluetooth/rfcomm.h
- include/net/can.h
- include/net/ip.h
- include/net/mana/mana.h
- include/net/strparser.h
- io_uring/cancel.c
- io_uring/io_uring.c
- io_uring/kbuf.c
- io_uring/memmap.c
- io_uring/memmap.h
- io_uring/net.c
- io_uring/register.c
- io_uring/zcrx.c
- kernel/cgroup/cpuset.c
- kernel/dma/swiotlb.c
- kernel/fork.c
- kernel/nsproxy.c
- kernel/printk/nbcon.c
- kernel/rcu/srcutree.c
- kernel/sched/ext/ext.c
- kernel/sched/ext/inlines.h
- kernel/sched/ext/internal.h
- kernel/sched/ext/sub.c
- kernel/sched/sched.h
- kernel/workqueue.c
- lib/Kconfig.debug
- lib/dim/Makefile
- lib/dim/dim.c
- lib/dim/dim_kunit.c
- mm/mremap.c
- mm/pgtable-generic.c
- mm/vma.c
- mm/vma.h
- net/bluetooth/hci_core.c
- net/bluetooth/hci_sock.c
- net/bluetooth/hci_sync.c
- net/bluetooth/iso.c
- net/bluetooth/mgmt.c
- net/bluetooth/rfcomm/core.c
- net/bluetooth/rfcomm/sock.c
- net/bluetooth/rfcomm/tty.c
- net/bluetooth/sco.c
- net/bridge/br_multicast.c
- net/bridge/netfilter/nf_conntrack_bridge.c
- net/can/af_can.c
- net/can/gw.c
- net/can/isotp.c
- net/can/raw.c
- net/core/dev.c
- net/core/flow_dissector.c
- net/core/skbuff.c
- net/devlink/core.c
- net/ipv4/af_inet.c
- net/ipv4/cipso_ipv4.c
- net/ipv4/fib_semantics.c
- net/ipv4/fib_trie.c
- net/ipv4/ip_output.c
- net/ipv4/route.c
- net/ipv4/tcp.c
- net/ipv4/tcp_ipv4.c
- net/ipv6/ip6_gre.c
- net/ipv6/route.c
- net/mac80211/airtime.c
- net/netfilter/nfnetlink_queue.c
- net/netfilter/xt_CHECKSUM.c
- net/openvswitch/actions.c
- net/openvswitch/datapath.c
- net/packet/af_packet.c
- net/sched/cls_route.c
- net/sched/em_text.c
- net/sctp/socket.c
- net/smc/af_smc.c
- net/strparser/strparser.c
- net/tipc/node.c
- net/tipc/topsrv.c
- net/vmw_vsock/af_vsock.c
- net/vmw_vsock/virtio_transport_common.c
- net/xfrm/xfrm_output.c
- security/keys/key.c
- security/keys/persistent.c
- security/landlock/domain.h
- security/selinux/avc.c
- security/selinux/hooks.c
- sound/hda/codecs/realtek/alc269.c
- sound/hda/codecs/side-codecs/tas2781_hda.c
- sound/pci/ctxfi/ctdaio.c
- sound/soc/sof/ipc4-topology.c
- sound/soc/sof/sof-client.c
- sound/usb/quirks.c
- tools/testing/selftests/Makefile
- tools/testing/selftests/drivers/net/mlxsw/port_range_occ.sh
- tools/testing/selftests/filesystems/.gitignore
- tools/testing/selftests/filesystems/Makefile
- tools/testing/selftests/filesystems/empty_mntns/.gitignore
- tools/testing/selftests/filesystems/empty_mntns/Makefile
- tools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c
- tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c
- tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c
- tools/testing/selftests/filesystems/mntns_unbindable/Makefile
- tools/testing/selftests/filesystems/mntns_unbindable/mntns_unbindable_test.c
- tools/testing/selftests/filesystems/mount_cycle/.gitignore
- tools/testing/selftests/filesystems/mount_cycle/Makefile
- tools/testing/selftests/filesystems/mount_cycle/config
- tools/testing/selftests/filesystems/mount_cycle/locked_handle_test.c
- tools/testing/selftests/filesystems/mount_cycle/loop_cycle_test.c
- tools/testing/selftests/filesystems/mount_cycle/mount_cover_test.c
- tools/testing/selftests/filesystems/mount_cycle/nsfs_rbind_loop_test.c
- tools/testing/selftests/filesystems/mount_cycle/overmount_ns_file_test.c
- tools/testing/selftests/filesystems/mount_cycle/overmount_reparent_test.c
- tools/testing/selftests/filesystems/mount_cycle/settings
- tools/testing/selftests/filesystems/mount_cycle/unmounted_tree_test.c
- tools/testing/selftests/filesystems/open_tree_ns/.gitignore
- tools/testing/selftests/filesystems/open_tree_ns/Makefile
- tools/testing/selftests/filesystems/open_tree_ns/open_tree_ns_covered_test.c
- tools/testing/selftests/filesystems/overlayfs/.gitignore
- tools/testing/selftests/filesystems/overlayfs/Makefile
- tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c
- tools/testing/selftests/filesystems/readdir_hold.h
- tools/testing/selftests/filesystems/rw_hint_test.c
- tools/testing/selftests/filesystems/umount_propagation/Makefile
- tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
- tools/testing/selftests/filesystems/umount_propagation/shrink_submounts_test.c
- tools/testing/selftests/filesystems/umount_propagation/umount_propagation_test.c
- tools/testing/selftests/mm/hugetlb-mmap.c
- tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
- tools/testing/selftests/net/amt.sh
- tools/testing/selftests/net/tun.c
- tools/testing/selftests/net/veth.sh
- tools/testing/selftests/sched_ext/Makefile
- tools/testing/selftests/sched_ext/dequeue_remote.bpf.c
- tools/testing/selftests/sched_ext/dequeue_remote.c
- tools/testing/selftests/tc-testing/tc-tests/filters/route.json
- tools/testing/vma/tests/vma.c
modified .mailmap
| @@ -101,6 +101,7 @@ Andy Chiu <andybnac@gmail.com> <andy.chiu@sifive.com> | |||
| 101 | 101 | Andy Chiu <andybnac@gmail.com> <taochiu@synology.com> | |
| 102 | 102 | Andy Shevchenko <andy@kernel.org> <andy@smile.org.ua> | |
| 103 | 103 | Andy Shevchenko <andy@kernel.org> <ext-andriy.shevchenko@nokia.com> | |
| 104 | + | Andy Yan <andyshrk@163.com> <andy.yan@rock-chips.com> | |
| 104 | 105 | Anilkumar Kolli <quic_akolli@quicinc.com> <akolli@codeaurora.org> | |
| 105 | 106 | Anirudh Ghayal <quic_aghayal@quicinc.com> <aghayal@codeaurora.org> | |
| 106 | 107 | Antoine Tenart <atenart@kernel.org> <antoine.tenart@bootlin.com> | |
| @@ -461,7 +462,8 @@ Johan Hovold <johan@kernel.org> <jhovold@gmail.com> | |||
| 461 | 462 | Johan Hovold <johan@kernel.org> <johan@hovoldconsulting.com> | |
| 462 | 463 | John Crispin <john@phrozen.org> <blogic@openwrt.org> | |
| 463 | 464 | John Fastabend <john.fastabend@gmail.com> <john.r.fastabend@intel.com> | |
| 464 | - | John Garry <john.g.garry@oracle.com> <john.garry@huawei.com> | |
| 465 | + | John Garry <john.garry@linux.dev> <john.garry@huawei.com> | |
| 466 | + | John Garry <john.garry@linux.dev> <john.g.garry@oracle.com> | |
| 465 | 467 | John Keeping <john@keeping.me.uk> <john@metanate.com> | |
| 466 | 468 | John Moon <john@jmoon.dev> <quic_johmoo@quicinc.com> | |
| 467 | 469 | John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> | |
| @@ -486,6 +488,7 @@ Juha Yrjola <juha.yrjola@nokia.com> | |||
| 486 | 488 | Juha Yrjola <juha.yrjola@solidboot.com> | |
| 487 | 489 | Julien Thierry <julien.thierry.kdev@gmail.com> <julien.thierry@arm.com> | |
| 488 | 490 | Justin Iurman <justin.iurman@gmail.com> <justin.iurman@uliege.be> | |
| 491 | + | Imre Kaloz <kaloz@kernel.org> <kaloz@openwrt.org> | |
| 489 | 492 | Ira Weiny <iweiny@kernel.org> <ira.weiny@intel.com> | |
| 490 | 493 | Iskren Chernev <me@iskren.info> <iskren.chernev@gmail.com> | |
| 491 | 494 | Kalle Valo <kvalo@kernel.org> <kvalo@codeaurora.org> | |
modified Documentation/admin-guide/ext4.rst
| @@ -172,7 +172,8 @@ When mounting an ext4 filesystem, the following option are accepted: | |||
| 172 | 172 | data=journal | |
| 173 | 173 | All data are committed into the journal prior to being written into the | |
| 174 | 174 | main file system. Enabling this mode will disable delayed allocation | |
| 175 | - | and O_DIRECT support. | |
| 175 | + | and O_DIRECT support. This feature is deprecated and support | |
| 176 | + | will be removed in January 2028. | |
| 176 | 177 | ||
| 177 | 178 | data=ordered (*) | |
| 178 | 179 | All data are forced directly out to the main file system prior to its | |
| @@ -418,7 +419,8 @@ There are 3 different data modes: | |||
| 418 | 419 | consistent state. This mode is the slowest except when data needs to be read | |
| 419 | 420 | from and written to disk at the same time where it outperforms all others | |
| 420 | 421 | modes. Enabling this mode will disable delayed allocation and O_DIRECT | |
| 421 | - | support. | |
| 422 | + | support. The data=journal feature is deprecated and support will be | |
| 423 | + | removed in January 2028. | |
| 422 | 424 | ||
| 423 | 425 | /proc entries | |
| 424 | 426 | ============= | |
modified Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
| @@ -77,6 +77,7 @@ properties: | |||
| 77 | 77 | - mscc,ocelot-spi | |
| 78 | 78 | - mscc,jaguar2-spi | |
| 79 | 79 | - sophgo,sg2042-spi | |
| 80 | + | - syna,sl2610-spi | |
| 80 | 81 | - thead,th1520-spi | |
| 81 | 82 | - ultrarisc,dp1000-spi | |
| 82 | 83 | - const: snps,dw-apb-ssi | |
modified Documentation/filesystems/propagate_umount.txt
| @@ -32,12 +32,12 @@ of set. They can be reparented to the place where the bottom of | |||
| 32 | 32 | stack is attached to a mount that will survive. NOTE: doing that | |
| 33 | 33 | will violate a constraint on having no more than one mount with | |
| 34 | 34 | the same parent/mountpoint pair; however, the caller (umount_tree()) | |
| 35 | - | will immediately remedy that - it may keep unmounted element attached | |
| 36 | - | to parent, but only if the parent itself is unmounted. Since all | |
| 37 | - | conflicts created by reparenting have common parent *not* in the | |
| 38 | - | set and one side of the conflict (bottom of the stack of overmounts) | |
| 39 | - | is in the set, it will be resolved. However, we rely upon umount_tree() | |
| 40 | - | doing that pretty much immediately after the call of propagate_umount(). | |
| 35 | + | will immediately remedy that - it detaches every element of the set | |
| 36 | + | from its parent. Since all conflicts created by reparenting have | |
| 37 | + | common parent *not* in the set and one side of the conflict (bottom | |
| 38 | + | of the stack of overmounts) is in the set, it will be resolved. | |
| 39 | + | However, we rely upon umount_tree() doing that pretty much immediately | |
| 40 | + | after the call of propagate_umount(). | |
| 41 | 41 | ||
| 42 | 42 | Algorithm is based on two statements: | |
| 43 | 43 | 1) for any set S, there is a maximal non-shifting subset of S | |
modified Documentation/networking/strparser.rst
| @@ -77,7 +77,7 @@ Functions | |||
| 77 | 77 | ||
| 78 | 78 | strp_done is called to release any resources held by the stream | |
| 79 | 79 | parser instance. This must be called after the stream processor | |
| 80 | - | has been stopped. | |
| 80 | + | has been stopped. The socket lock must not be held. | |
| 81 | 81 | ||
| 82 | 82 | :: | |
| 83 | 83 | ||
modified MAINTAINERS
| @@ -3012,7 +3012,7 @@ F: arch/arm/boot/dts/ti/omap/omap3-igep* | |||
| 3012 | 3012 | ||
| 3013 | 3013 | ARM/INTEL IXP4XX ARM ARCHITECTURE | |
| 3014 | 3014 | M: Linus Walleij <linusw@kernel.org> | |
| 3015 | - | M: Imre Kaloz <kaloz@openwrt.org> | |
| 3015 | + | M: Imre Kaloz <kaloz@kernel.org> | |
| 3016 | 3016 | L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) | |
| 3017 | 3017 | S: Maintained | |
| 3018 | 3018 | F: Documentation/devicetree/bindings/arm/intel-ixp4xx.yaml | |
| @@ -9861,7 +9861,7 @@ L: linux-ext4@vger.kernel.org | |||
| 9861 | 9861 | S: Maintained | |
| 9862 | 9862 | W: http://ext4.wiki.kernel.org | |
| 9863 | 9863 | Q: http://patchwork.ozlabs.org/project/linux-ext4/list/ | |
| 9864 | - | T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git | |
| 9864 | + | T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev | |
| 9865 | 9865 | F: Documentation/filesystems/ext4/ | |
| 9866 | 9866 | F: fs/ext4/ | |
| 9867 | 9867 | F: include/trace/events/ext4.h | |
modified Makefile
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | VERSION = 7 | |
| 3 | 3 | PATCHLEVEL = 3 | |
| 4 | 4 | SUBLEVEL = 0 | |
| 5 | - | EXTRAVERSION = -rc6 | |
| 5 | + | EXTRAVERSION = -rc7 | |
| 6 | 6 | NAME = Baby Opossum Posse | |
| 7 | 7 | ||
| 8 | 8 | # *DOCUMENTATION* | |
modified arch/arm64/boot/dts/freescale/fsl-lx216x.dtsi
| @@ -1602,7 +1602,7 @@ | |||
| 1602 | 1602 | }; | |
| 1603 | 1603 | ||
| 1604 | 1604 | dspi2_miso_mosi_pins: iic5-spi3-pins { | |
| 1605 | - | pinctrl-single,bits = <0x3 (0x2 << 9) (0x7 << 9)>; | |
| 1605 | + | pinctrl-single,bits = <0x0 (0x3 << 9) (0x7 << 9)>; | |
| 1606 | 1606 | }; | |
| 1607 | 1607 | ||
| 1608 | 1608 | i2c5_pins: iic6-i2c-pins { | |
| @@ -1622,7 +1622,7 @@ | |||
| 1622 | 1622 | }; | |
| 1623 | 1623 | ||
| 1624 | 1624 | gpio1_31_28_pins: xspi1-data74-gpio-pins { | |
| 1625 | - | pinctrl-single,bits = <0x0 0x1 (0x7 << 15)>; | |
| 1625 | + | pinctrl-single,bits = <0x0 (0x1 << 15) (0x7 << 15)>; | |
| 1626 | 1626 | }; | |
| 1627 | 1627 | ||
| 1628 | 1628 | fspi_data30_pins: xspi1-data30-pins { | |
| @@ -1630,7 +1630,7 @@ | |||
| 1630 | 1630 | }; | |
| 1631 | 1631 | ||
| 1632 | 1632 | gpio1_27_24_pins: xspi1-data30-gpio-pins { | |
| 1633 | - | pinctrl-single,bits = <0x0 0x1 (0x7 << 18)>; | |
| 1633 | + | pinctrl-single,bits = <0x0 (0x1 << 18) (0x7 << 18)>; | |
| 1634 | 1634 | }; | |
| 1635 | 1635 | ||
| 1636 | 1636 | fspi_dqs_sck_cs10_pins: xspi1-base-pins { | |
| @@ -1638,7 +1638,7 @@ | |||
| 1638 | 1638 | }; | |
| 1639 | 1639 | ||
| 1640 | 1640 | gpio1_23_20_pins: xspi1-base-gpio-pins { | |
| 1641 | - | pinctrl-single,bits = <0x0 0x1 (0x7 << 21)>; | |
| 1641 | + | pinctrl-single,bits = <0x0 (0x1 << 21) (0x7 << 21)>; | |
| 1642 | 1642 | }; | |
| 1643 | 1643 | ||
| 1644 | 1644 | esdhc0_cmd_data30_clk_vsel_pins: sdhc1-base-sdhc-vsel-pins { | |
| @@ -1687,12 +1687,19 @@ | |||
| 1687 | 1687 | }; | |
| 1688 | 1688 | ||
| 1689 | 1689 | /* RCWSR14 */ | |
| 1690 | + | /* | |
| 1691 | + | * IIC1_PMUX is a single bit at RCWSR14[10], but bit-per-mux | |
| 1692 | + | * uses the mask for the field to clear before applying the | |
| 1693 | + | * value. | |
| 1694 | + | * So bits 11 and 12, which are reserved, are written as 0 | |
| 1695 | + | * on every mux switch, it is harmless. | |
| 1696 | + | */ | |
| 1690 | 1697 | i2c0_pins: iic1-i2c-pins { | |
| 1691 | - | pinctrl-single,bits = <0x8 0x0 (0x1 << 10)>; | |
| 1698 | + | pinctrl-single,bits = <0x8 0x0 (0x7 << 10)>; | |
| 1692 | 1699 | }; | |
| 1693 | 1700 | ||
| 1694 | 1701 | gpio0_3_2_pins: iic1-gpio-pins { | |
| 1695 | - | pinctrl-single,bits = <0x8 (0x1 << 10) (0x1 << 10)>; | |
| 1702 | + | pinctrl-single,bits = <0x8 (0x1 << 10) (0x7 << 10)>; | |
| 1696 | 1703 | }; | |
| 1697 | 1704 | }; | |
| 1698 | 1705 | ||
modified arch/arm64/boot/dts/freescale/imx8mp-var-dart-sonata.dts
| @@ -511,6 +511,7 @@ | |||
| 511 | 511 | pinctrl-2 = <&pinctrl_usdhc2_200mhz>, <&pinctrl_usdhc2_gpio>; | |
| 512 | 512 | cd-gpios = <&gpio2 12 GPIO_ACTIVE_LOW>; | |
| 513 | 513 | vmmc-supply = <®_usdhc2_vmmc>; | |
| 514 | + | vqmmc-supply = <&ldo5>; | |
| 514 | 515 | bus-width = <4>; | |
| 515 | 516 | status = "okay"; | |
| 516 | 517 | }; | |
modified arch/arm64/boot/dts/qcom/x1-microsoft-denali.dtsi
| @@ -863,11 +863,11 @@ | |||
| 863 | 863 | }; | |
| 864 | 864 | ||
| 865 | 865 | &lpass_vamacro { | |
| 866 | - | pinctrl-0 = <&dmic01_default>, <&dmic23_default>; | |
| 866 | + | pinctrl-0 = <&dmic01_default>; | |
| 867 | 867 | pinctrl-names = "default"; | |
| 868 | 868 | ||
| 869 | 869 | vdd-micb-supply = <&vreg_l1b_1p8>; | |
| 870 | - | qcom,dmic-sample-rate = <4800000>; | |
| 870 | + | qcom,dmic-sample-rate = <2400000>; | |
| 871 | 871 | }; | |
| 872 | 872 | ||
| 873 | 873 | &mdss { | |
modified arch/arm64/include/asm/el2_setup.h
| @@ -421,8 +421,9 @@ | |||
| 421 | 421 | mov x2, xzr | |
| 422 | 422 | mrs x1, id_aa64dfr0_el1 | |
| 423 | 423 | ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 | |
| 424 | - | cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9 | |
| 425 | - | b.lt .Lskip_pmuv3p9_\@ | |
| 424 | + | cmp x1, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF | |
| 425 | + | ccmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9, #8, ne | |
| 426 | + | b.lt .Lskip_pmuv3p9_\@ // Skip if < PMUv3p9 or IMP_DEF | |
| 426 | 427 | ||
| 427 | 428 | orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0 | |
| 428 | 429 | orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0 | |
modified arch/arm64/kernel/Makefile
| @@ -25,6 +25,9 @@ KASAN_SANITIZE_stacktrace.o := n | |||
| 25 | 25 | KCOV_INSTRUMENT_entry-common.o := n | |
| 26 | 26 | KCOV_INSTRUMENT_idle.o := n | |
| 27 | 27 | ||
| 28 | + | # Softirq stack switching can run outside interrupt context. | |
| 29 | + | KCOV_INSTRUMENT_irq.o := n | |
| 30 | + | ||
| 28 | 31 | # Object file lists. | |
| 29 | 32 | obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ | |
| 30 | 33 | entry-common.o process.o ptrace.o \ | |
modified arch/riscv/Kconfig
| @@ -453,9 +453,10 @@ config SMP | |||
| 453 | 453 | config NR_CPUS | |
| 454 | 454 | int "Maximum number of CPUs (2-512)" | |
| 455 | 455 | depends on SMP | |
| 456 | - | range 2 512 if !RISCV_SBI_V01 | |
| 457 | - | range 2 32 if RISCV_SBI_V01 && 32BIT | |
| 456 | + | range 2 512 if !RISCV_SBI_V01 && 64BIT | |
| 457 | + | range 2 128 if !RISCV_SBI_V01 && 32BIT | |
| 458 | 458 | range 2 64 if RISCV_SBI_V01 && 64BIT | |
| 459 | + | range 2 32 if RISCV_SBI_V01 && 32BIT | |
| 459 | 460 | default "32" if 32BIT | |
| 460 | 461 | default "64" if RISCV_SBI_V01 && 64BIT | |
| 461 | 462 | default "256" if !RISCV_SBI_V01 && 64BIT | |
modified arch/riscv/Kconfig.errata
| @@ -46,7 +46,7 @@ config ERRATA_MIPS_P8700_PAUSE_OPCODE | |||
| 46 | 46 | ||
| 47 | 47 | config ERRATA_SIFIVE | |
| 48 | 48 | bool "SiFive errata" | |
| 49 | - | depends on RISCV_ALTERNATIVE | |
| 49 | + | depends on RISCV_ALTERNATIVE && 64BIT | |
| 50 | 50 | help | |
| 51 | 51 | All SiFive errata Kconfig depend on this Kconfig. Disabling | |
| 52 | 52 | this Kconfig will disable all SiFive errata. Please say "Y" | |
| @@ -96,6 +96,20 @@ config ERRATA_STARFIVE_JH7100 | |||
| 96 | 96 | Say "Y" if you want to support the BeagleV Starlight and/or | |
| 97 | 97 | StarFive VisionFive V1 boards. | |
| 98 | 98 | ||
| 99 | + | config ERRATA_SIFIVE_MAL_9092 | |
| 100 | + | bool "Apply SiFive HLV/HLVX/HSV fence errata" | |
| 101 | + | depends on ERRATA_SIFIVE && 64BIT | |
| 102 | + | default y | |
| 103 | + | help | |
| 104 | + | This will apply the SiFive MAL-9092 errata to add fence.rw | |
| 105 | + | instructions around all HLV/HLVX/HSV instructions. | |
| 106 | + | ||
| 107 | + | Note: HSTATUS.HU is cleared during KVM initialization. If future | |
| 108 | + | changes enable HSTATUS.HU to allow hypervisor instructions in | |
| 109 | + | U-mode, additional errata handling may be required. | |
| 110 | + | ||
| 111 | + | If you don't know what to do here, say "Y". | |
| 112 | + | ||
| 99 | 113 | config ERRATA_THEAD | |
| 100 | 114 | bool "T-HEAD errata" | |
| 101 | 115 | depends on RISCV_ALTERNATIVE | |
| @@ -146,6 +160,7 @@ config ERRATA_THEAD_PMU | |||
| 146 | 160 | config ERRATA_THEAD_GHOSTWRITE | |
| 147 | 161 | bool "Apply T-Head Ghostwrite errata" | |
| 148 | 162 | depends on ERRATA_THEAD && RISCV_ISA_XTHEADVECTOR | |
| 163 | + | select RISCV_ALTERNATIVE_EARLY | |
| 149 | 164 | default y | |
| 150 | 165 | help | |
| 151 | 166 | The T-Head C9xx cores have a vulnerability in the xtheadvector | |
modified arch/riscv/Kconfig.socs
| @@ -34,6 +34,7 @@ config ARCH_RENESAS | |||
| 34 | 34 | config ARCH_SIFIVE | |
| 35 | 35 | bool "SiFive SoCs" | |
| 36 | 36 | select ERRATA_SIFIVE | |
| 37 | + | depends on 64BIT | |
| 37 | 38 | help | |
| 38 | 39 | This enables support for SiFive SoC platform hardware. | |
| 39 | 40 | ||
modified arch/riscv/errata/sifive/errata.c
| @@ -51,6 +51,22 @@ static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long imp | |||
| 51 | 51 | return true; | |
| 52 | 52 | } | |
| 53 | 53 | ||
| 54 | + | static bool errata_mal_9092_check_func(unsigned long arch_id, unsigned long impid) | |
| 55 | + | { | |
| 56 | + | /* | |
| 57 | + | * Affected cores: | |
| 58 | + | * Architecture ID: 0x8000000000000109 | |
| 59 | + | * Implementation ID: 0x19251031, 0x19251217, 0x19260320 | |
| 60 | + | */ | |
| 61 | + | ||
| 62 | + | if (arch_id != 0x8000000000000109) | |
| 63 | + | return false; | |
| 64 | + | if (impid != 0x19251031 && impid != 0x19251217 && impid != 0x19260320) | |
| 65 | + | return false; | |
| 66 | + | ||
| 67 | + | return true; | |
| 68 | + | } | |
| 69 | + | ||
| 54 | 70 | static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = { | |
| 55 | 71 | { | |
| 56 | 72 | .name = "cip-453", | |
| @@ -60,6 +76,10 @@ static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = { | |||
| 60 | 76 | .name = "cip-1200", | |
| 61 | 77 | .check_func = errata_cip_1200_check_func | |
| 62 | 78 | }, | |
| 79 | + | { | |
| 80 | + | .name = "mal-9092", | |
| 81 | + | .check_func = errata_mal_9092_check_func | |
| 82 | + | }, | |
| 63 | 83 | }; | |
| 64 | 84 | ||
| 65 | 85 | static u32 __init_or_module sifive_errata_probe(unsigned long archid, | |
modified arch/riscv/include/asm/cpufeature.h
| @@ -40,6 +40,8 @@ extern u32 thead_vlenb_of; | |||
| 40 | 40 | ||
| 41 | 41 | void __init riscv_user_isa_enable(void); | |
| 42 | 42 | ||
| 43 | + | void riscv_clear_hypervisor_csr(void); | |
| 44 | + | ||
| 43 | 45 | #define _RISCV_ISA_EXT_DATA(_name, _id, _subset_exts, _subset_exts_size, _validate) { \ | |
| 44 | 46 | .name = #_name, \ | |
| 45 | 47 | .property = #_name, \ | |
modified arch/riscv/include/asm/errata_list_vendors.h
| @@ -11,7 +11,8 @@ | |||
| 11 | 11 | #ifdef CONFIG_ERRATA_SIFIVE | |
| 12 | 12 | #define ERRATA_SIFIVE_CIP_453 0 | |
| 13 | 13 | #define ERRATA_SIFIVE_CIP_1200 1 | |
| 14 | - | #define ERRATA_SIFIVE_NUMBER 2 | |
| 14 | + | #define ERRATA_SIFIVE_MAL_9092 2 | |
| 15 | + | #define ERRATA_SIFIVE_NUMBER 3 | |
| 15 | 16 | #endif | |
| 16 | 17 | ||
| 17 | 18 | #ifdef CONFIG_ERRATA_THEAD | |
modified arch/riscv/include/asm/futex.h
| @@ -40,6 +40,7 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr) | |||
| 40 | 40 | ||
| 41 | 41 | if (!access_ok(uaddr, sizeof(u32))) | |
| 42 | 42 | return -EFAULT; | |
| 43 | + | uaddr = untagged_addr(uaddr); | |
| 43 | 44 | ||
| 44 | 45 | switch (op) { | |
| 45 | 46 | case FUTEX_OP_SET: | |
| @@ -82,6 +83,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, | |||
| 82 | 83 | ||
| 83 | 84 | if (!access_ok(uaddr, sizeof(u32))) | |
| 84 | 85 | return -EFAULT; | |
| 86 | + | uaddr = untagged_addr(uaddr); | |
| 85 | 87 | ||
| 86 | 88 | __enable_user_access(); | |
| 87 | 89 | __asm__ __volatile__ ( | |
modified arch/riscv/include/asm/insn-def.h
| @@ -192,18 +192,28 @@ | |||
| 192 | 192 | INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(49), \ | |
| 193 | 193 | __RD(0), RS1(gaddr), RS2(vmid)) | |
| 194 | 194 | ||
| 195 | + | #define ALT_SIFIVE_MAL_9092_FENCE \ | |
| 196 | + | ALTERNATIVE("nop", "fence rw, rw", SIFIVE_VENDOR_ID, \ | |
| 197 | + | ERRATA_SIFIVE_MAL_9092, CONFIG_ERRATA_SIFIVE_MAL_9092) | |
| 198 | + | ||
| 195 | 199 | #define HLVX_HU(dest, addr) \ | |
| 200 | + | ALT_SIFIVE_MAL_9092_FENCE "\n" \ | |
| 196 | 201 | INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(50), \ | |
| 197 | - | RD(dest), RS1(addr), __RS2(3)) | |
| 202 | + | RD(dest), RS1(addr), __RS2(3)) "\n" \ | |
| 203 | + | ALT_SIFIVE_MAL_9092_FENCE | |
| 198 | 204 | ||
| 199 | 205 | #define HLV_W(dest, addr) \ | |
| 206 | + | ALT_SIFIVE_MAL_9092_FENCE "\n" \ | |
| 200 | 207 | INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(52), \ | |
| 201 | - | RD(dest), RS1(addr), __RS2(0)) | |
| 208 | + | RD(dest), RS1(addr), __RS2(0)) "\n" \ | |
| 209 | + | ALT_SIFIVE_MAL_9092_FENCE | |
| 202 | 210 | ||
| 203 | 211 | #ifdef CONFIG_64BIT | |
| 204 | 212 | #define HLV_D(dest, addr) \ | |
| 213 | + | ALT_SIFIVE_MAL_9092_FENCE "\n" \ | |
| 205 | 214 | INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(54), \ | |
| 206 | - | RD(dest), RS1(addr), __RS2(0)) | |
| 215 | + | RD(dest), RS1(addr), __RS2(0)) "\n" \ | |
| 216 | + | ALT_SIFIVE_MAL_9092_FENCE | |
| 207 | 217 | #else | |
| 208 | 218 | #define HLV_D(dest, addr) \ | |
| 209 | 219 | __ASM_STR(.error "hlv.d requires 64-bit support") | |
modified arch/riscv/include/asm/scs.h
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | #ifdef __ASSEMBLER__ | |
| 6 | 6 | #include <asm/asm-offsets.h> | |
| 7 | + | #include <asm/csr.h> | |
| 7 | 8 | ||
| 8 | 9 | #ifdef CONFIG_SHADOW_CALL_STACK | |
| 9 | 10 | ||
| @@ -22,9 +23,17 @@ | |||
| 22 | 23 | REG_L gp, TASK_TI_SCS_SP(tp) | |
| 23 | 24 | .endm | |
| 24 | 25 | ||
| 25 | - | /* Load task_scs_sp(current) to gp, but only if tp has changed. */ | |
| 26 | - | .macro scs_load_current_if_task_changed prev | |
| 27 | - | beq \prev, tp, _skip_scs | |
| 26 | + | /* | |
| 27 | + | * Load task_scs_sp(current) to gp, but only when the trap came from U-mode. | |
| 28 | + | * The source privilege level is taken from the saved sstatus.SPP bit (written | |
| 29 | + | * by hardware on trap entry), not by comparing tp. tp is a user-writable | |
| 30 | + | * register, so gating the shadow call stack reload on it let a user task that | |
| 31 | + | * set tp == ¤t skip the reload and run the kernel with an attacker | |
| 32 | + | * controlled gp (the shadow call stack pointer). | |
| 33 | + | */ | |
| 34 | + | .macro scs_load_current_if_from_user status, tmp | |
| 35 | + | andi \tmp, \status, SR_SPP | |
| 36 | + | bnez \tmp, _skip_scs | |
| 28 | 37 | scs_load_current | |
| 29 | 38 | _skip_scs: | |
| 30 | 39 | .endm | |
| @@ -42,7 +51,7 @@ _skip_scs: | |||
| 42 | 51 | .endm | |
| 43 | 52 | .macro scs_load_current | |
| 44 | 53 | .endm | |
| 45 | - | .macro scs_load_current_if_task_changed prev | |
| 54 | + | .macro scs_load_current_if_from_user status, tmp | |
| 46 | 55 | .endm | |
| 47 | 56 | .macro scs_save_current | |
| 48 | 57 | .endm | |
modified arch/riscv/include/asm/vector.h
| @@ -137,8 +137,8 @@ static __always_inline void __vstate_csr_save(struct __riscv_v_ext_state *dest) | |||
| 137 | 137 | "csrr %0, " __stringify(CSR_VSTART) "\n\t" | |
| 138 | 138 | "csrr %1, " __stringify(CSR_VTYPE) "\n\t" | |
| 139 | 139 | "csrr %2, " __stringify(CSR_VL) "\n\t" | |
| 140 | - | : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl), | |
| 141 | - | "=r" (dest->vcsr) : :); | |
| 140 | + | : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl) | |
| 141 | + | : :); | |
| 142 | 142 | ||
| 143 | 143 | if (has_xtheadvector()) { | |
| 144 | 144 | unsigned long status; | |
| @@ -230,7 +230,7 @@ static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to, | |||
| 230 | 230 | "add %1, %1, %0\n\t" | |
| 231 | 231 | "vse8.v v24, (%1)\n\t" | |
| 232 | 232 | ".option pop\n\t" | |
| 233 | - | : "=&r" (vl) : "r" (datap) : "memory"); | |
| 233 | + | : "=&r" (vl), "+r" (datap) : : "memory"); | |
| 234 | 234 | } | |
| 235 | 235 | riscv_v_disable(); | |
| 236 | 236 | } | |
| @@ -266,7 +266,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_ | |||
| 266 | 266 | "add %1, %1, %0\n\t" | |
| 267 | 267 | "vle8.v v24, (%1)\n\t" | |
| 268 | 268 | ".option pop\n\t" | |
| 269 | - | : "=&r" (vl) : "r" (datap) : "memory"); | |
| 269 | + | : "=&r" (vl), "+r" (datap) : : "memory"); | |
| 270 | 270 | } | |
| 271 | 271 | __vstate_csr_restore(restore_from); | |
| 272 | 272 | riscv_v_disable(); | |
modified arch/riscv/include/uapi/asm/vendor/mips.h
| @@ -1,3 +1,5 @@ | |||
| 1 | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | |
| 2 | 2 | ||
| 3 | - | #define RISCV_HWPROBE_VENDOR_EXT_XMIPSEXECTL BIT(0) | |
| 3 | + | #include <linux/const.h> | |
| 4 | + | ||
| 5 | + | #define RISCV_HWPROBE_VENDOR_EXT_XMIPSEXECTL _BITULL(0) | |
modified arch/riscv/kernel/cpufeature.c
| @@ -1233,6 +1233,18 @@ void __init riscv_user_isa_enable(void) | |||
| 1233 | 1233 | pr_warn("Zicbop disabled as it is unavailable on some harts\n"); | |
| 1234 | 1234 | } | |
| 1235 | 1235 | ||
| 1236 | + | void riscv_clear_hypervisor_csr(void) | |
| 1237 | + | { | |
| 1238 | + | if (!riscv_has_extension_unlikely(RISCV_ISA_EXT_H)) | |
| 1239 | + | return; | |
| 1240 | + | ||
| 1241 | + | /* | |
| 1242 | + | * Clear HSTATUS.HU to restrict hypervisor instructions to HS-mode. | |
| 1243 | + | * This prevents user-mode from executing HLV/HSV instructions. | |
| 1244 | + | */ | |
| 1245 | + | csr_clear(CSR_HSTATUS, HSTATUS_HU); | |
| 1246 | + | } | |
| 1247 | + | ||
| 1236 | 1248 | #ifdef CONFIG_RISCV_ALTERNATIVE | |
| 1237 | 1249 | /* | |
| 1238 | 1250 | * Alternative patch sites consider 48 bits when determining when to patch | |
modified arch/riscv/kernel/entry.S
| @@ -208,7 +208,7 @@ SYM_CODE_START(handle_exception) | |||
| 208 | 208 | load_global_pointer | |
| 209 | 209 | ||
| 210 | 210 | /* Load the kernel shadow call stack pointer if coming from userspace */ | |
| 211 | - | scs_load_current_if_task_changed s5 | |
| 211 | + | scs_load_current_if_from_user s1, s5 | |
| 212 | 212 | ||
| 213 | 213 | #ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE | |
| 214 | 214 | move a0, sp | |
modified arch/riscv/kernel/patch.c
| @@ -48,7 +48,7 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) | |||
| 48 | 48 | if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) | |
| 49 | 49 | return addr; | |
| 50 | 50 | phys = __pa_symbol(addr); | |
| 51 | - | } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { | |
| 51 | + | } else if (IS_ENABLED(CONFIG_EXECMEM)) { | |
| 52 | 52 | struct page *page = vmalloc_to_page(addr); | |
| 53 | 53 | ||
| 54 | 54 | BUG_ON(!page); | |
modified arch/riscv/kernel/ptrace.c
| @@ -230,6 +230,7 @@ static int riscv_vr_set(struct task_struct *target, | |||
| 230 | 230 | return -ENODATA; | |
| 231 | 231 | ||
| 232 | 232 | /* Copy rest of the vstate except datap */ | |
| 233 | + | memset(&ptrace_vstate, 0, sizeof(ptrace_vstate)); | |
| 233 | 234 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ptrace_vstate, 0, | |
| 234 | 235 | sizeof(struct __riscv_v_regset_state)); | |
| 235 | 236 | if (unlikely(ret)) | |
| @@ -299,6 +300,9 @@ static int riscv_cfi_get(struct task_struct *target, | |||
| 299 | 300 | struct user_cfi_state user_cfi; | |
| 300 | 301 | struct pt_regs *regs; | |
| 301 | 302 | ||
| 303 | + | if (!is_user_lpad_enabled() && !is_user_shstk_enabled()) | |
| 304 | + | return -EINVAL; | |
| 305 | + | ||
| 302 | 306 | memset(&user_cfi, 0, sizeof(user_cfi)); | |
| 303 | 307 | regs = task_pt_regs(target); | |
| 304 | 308 | ||
| @@ -337,8 +341,12 @@ static int riscv_cfi_set(struct task_struct *target, | |||
| 337 | 341 | struct user_cfi_state user_cfi; | |
| 338 | 342 | struct pt_regs *regs; | |
| 339 | 343 | ||
| 344 | + | if (!is_user_lpad_enabled() && !is_user_shstk_enabled()) | |
| 345 | + | return -EINVAL; | |
| 346 | + | ||
| 340 | 347 | regs = task_pt_regs(target); | |
| 341 | 348 | ||
| 349 | + | memset(&user_cfi, 0, sizeof(user_cfi)); | |
| 342 | 350 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &user_cfi, 0, -1); | |
| 343 | 351 | if (ret) | |
| 344 | 352 | return ret; | |
modified arch/riscv/kernel/setup.c
| @@ -366,6 +366,8 @@ void __init setup_arch(char **cmdline_p) | |||
| 366 | 366 | ||
| 367 | 367 | if (!IS_ENABLED(CONFIG_RISCV_ISA_ZBB) || !riscv_isa_extension_available(NULL, ZBB)) | |
| 368 | 368 | static_branch_disable(&efficient_ffs_key); | |
| 369 | + | ||
| 370 | + | riscv_clear_hypervisor_csr(); | |
| 369 | 371 | } | |
| 370 | 372 | ||
| 371 | 373 | bool arch_cpu_is_hotpluggable(int cpu) | |
modified arch/riscv/kernel/smpboot.c
| @@ -244,6 +244,8 @@ asmlinkage __visible void smp_callin(void) | |||
| 244 | 244 | ||
| 245 | 245 | numa_add_cpu(curr_cpuid); | |
| 246 | 246 | ||
| 247 | + | riscv_clear_hypervisor_csr(); | |
| 248 | + | ||
| 247 | 249 | pr_debug("CPU%u: Booted secondary hartid %lu\n", curr_cpuid, | |
| 248 | 250 | cpuid_to_hartid_map(curr_cpuid)); | |
| 249 | 251 | ||
modified arch/riscv/kernel/suspend.c
| @@ -43,6 +43,8 @@ void suspend_save_csrs(struct suspend_context *context) | |||
| 43 | 43 | ||
| 44 | 44 | void suspend_restore_csrs(struct suspend_context *context) | |
| 45 | 45 | { | |
| 46 | + | riscv_clear_hypervisor_csr(); | |
| 47 | + | ||
| 46 | 48 | csr_write(CSR_SCRATCH, 0); | |
| 47 | 49 | if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG)) | |
| 48 | 50 | csr_write(CSR_ENVCFG, context->envcfg); | |
modified arch/riscv/lib/strnlen.S
| @@ -87,9 +87,25 @@ strnlen_zbb: | |||
| 87 | 87 | * Aligned boundary. Use the address of the last valid byte | |
| 88 | 88 | * (s + count - 1) to avoid loading a word past the count | |
| 89 | 89 | * boundary in the loop below. count == 0 is handled above. | |
| 90 | + | * | |
| 91 | + | * Saturate the boundary when s + count would wrap around (very | |
| 92 | + | * large counts, e.g. SIZE_MAX passed by FORTIFY strcat/strlcat | |
| 93 | + | * with a destination whose size is unknown at compile time). | |
| 94 | + | * Without this, the wrapped boundary lands before s and the | |
| 95 | + | * pre-loop guard below always exits, returning a truncated | |
| 96 | + | * length. | |
| 97 | + | * | |
| 98 | + | * Clamping the increment to ~s (== SIZE_MAX - s) keeps the | |
| 99 | + | * computation branchless and wrap-free: | |
| 100 | + | * | |
| 101 | + | * s + min(count - 1, ~s) == saturating_add(s, count - 1) | |
| 102 | + | * | |
| 103 | + | * Saturating makes the scan equivalent to strlen(). | |
| 90 | 104 | */ | |
| 91 | - | add t4, a0, a1 | |
| 92 | - | addi t4, t4, -1 | |
| 105 | + | addi t4, a1, -1 /* count - 1 */ | |
| 106 | + | not t1, a0 /* SIZE_MAX - s */ | |
| 107 | + | minu t4, t4, t1 /* clamp, so s + t4 can never wrap */ | |
| 108 | + | add t4, a0, t4 /* saturated s + count - 1 */ | |
| 93 | 109 | andi t4, t4, -SZREG | |
| 94 | 110 | ||
| 95 | 111 | /* Get the first word. */ | |
modified arch/riscv/mm/extable.c
| @@ -68,8 +68,8 @@ ex_handler_load_unaligned_zeropad(const struct exception_table_entry *ex, | |||
| 68 | 68 | ||
| 69 | 69 | addr = regs_get_gpr(regs, reg_addr * sizeof(unsigned long)); | |
| 70 | 70 | ||
| 71 | - | offset = addr & 0x7UL; | |
| 72 | - | addr &= ~0x7UL; | |
| 71 | + | offset = addr & (sizeof(data) - 1); | |
| 72 | + | addr &= ~(sizeof(data) - 1); | |
| 73 | 73 | ||
| 74 | 74 | data = *(unsigned long *)addr >> (offset * 8); | |
| 75 | 75 | ||
modified arch/um/drivers/vector_transports.c
| @@ -209,6 +209,7 @@ static int raw_verify_header( | |||
| 209 | 209 | if ((vheader->flags & VIRTIO_NET_HDR_F_DATA_VALID) > 0) | |
| 210 | 210 | return 1; | |
| 211 | 211 | ||
| 212 | + | skb_set_network_header(skb, ETH_HLEN); | |
| 212 | 213 | virtio_net_hdr_to_skb(skb, vheader, virtio_legacy_is_little_endian()); | |
| 213 | 214 | return 0; | |
| 214 | 215 | } | |
modified arch/x86/include/asm/cpufeatures.h
| @@ -477,6 +477,8 @@ | |||
| 477 | 477 | #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* No Nested Data Breakpoints */ | |
| 478 | 478 | #define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1) /* WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */ | |
| 479 | 479 | #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* LFENCE always serializing / synchronizes RDTSC */ | |
| 480 | + | ||
| 481 | + | #define X86_FEATURE_TLBSYNC_SFW_NO (20*32+ 4) /* TLBI Erratum #1718 fixed in microcode */ | |
| 480 | 482 | #define X86_FEATURE_VERW_CLEAR (20*32+ 5) /* The memory form of VERW mitigates TSA */ | |
| 481 | 483 | #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6) /* Null Selector Clears Base */ | |
| 482 | 484 | ||
| @@ -587,4 +589,5 @@ | |||
| 587 | 589 | #define X86_BUG_TSA X86_BUG( 1*32+ 9) /* "tsa" CPU is affected by Transient Scheduler Attacks */ | |
| 588 | 590 | #define X86_BUG_VMSCAPE X86_BUG( 1*32+10) /* "vmscape" CPU is affected by VMSCAPE attacks from guests */ | |
| 589 | 591 | #define X86_BUG_SEAMRET_INVD_VMCS X86_BUG( 1*32+11) /* "seamret_invd_vmcs" SEAMRET from P-SEAMLDR clears the current VMCS */ | |
| 592 | + | #define X86_BUG_TLBI X86_BUG( 1*32+12) /* "tlbi" AMD TLBI Erratum #1718 */ | |
| 590 | 593 | #endif /* _ASM_X86_CPUFEATURES_H */ | |
modified arch/x86/include/asm/tlb.h
| @@ -110,6 +110,12 @@ static inline void __tlbsync(void) | |||
| 110 | 110 | ||
| 111 | 111 | /* TLBSYNC: supported in binutils >= 0.36. */ | |
| 112 | 112 | asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory"); | |
| 113 | + | ||
| 114 | + | if (!static_cpu_has_bug(X86_BUG_TLBI)) | |
| 115 | + | return; | |
| 116 | + | ||
| 117 | + | /* TLBSYNC: supported in binutils >= 0.36. */ | |
| 118 | + | asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory"); | |
| 113 | 119 | } | |
| 114 | 120 | #else | |
| 115 | 121 | /* Some compilers (I'm looking at you clang!) simply can't do DCE */ | |
modified arch/x86/kernel/cpu/amd.c
| @@ -1049,6 +1049,10 @@ static void init_amd_zen5(struct cpuinfo_x86 *c) | |||
| 1049 | 1049 | msr_clear_bit(MSR_AMD64_CPUID_FN_7, 18); | |
| 1050 | 1050 | pr_emerg_once("RDSEED32 is broken. Disabling the corresponding CPUID bit.\n"); | |
| 1051 | 1051 | } | |
| 1052 | + | ||
| 1053 | + | if (cpu_has(c, X86_FEATURE_INVLPGB) && | |
| 1054 | + | !cpu_has(c, X86_FEATURE_TLBSYNC_SFW_NO)) | |
| 1055 | + | set_cpu_bug(c, X86_BUG_TLBI); | |
| 1052 | 1056 | } | |
| 1053 | 1057 | ||
| 1054 | 1058 | static void init_amd(struct cpuinfo_x86 *c) | |
modified drivers/accessibility/braille/braille_console.c
| @@ -62,14 +62,50 @@ 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; | |
| 65 | 67 | u16 out; | |
| 66 | 68 | int i; | |
| 67 | 69 | ||
| 68 | 70 | if (!braille_co) | |
| 69 | 71 | return; | |
| 70 | 72 | ||
| 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 | + | ||
| 71 | 107 | if (!memcmp(lastwrite, buf, WIDTH * sizeof(*buf))) | |
| 72 | - | return; | |
| 108 | + | goto unlock_nbcon; | |
| 73 | 109 | memcpy(lastwrite, buf, WIDTH * sizeof(*buf)); | |
| 74 | 110 | ||
| 75 | 111 | #define SOH 1 | |
| @@ -102,7 +138,24 @@ static void braille_write(u16 *buf) | |||
| 102 | 138 | *c++ = csum; | |
| 103 | 139 | *c++ = ETX; | |
| 104 | 140 | ||
| 105 | - | braille_co->write(braille_co, data, c - data); | |
| 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 | + | } | |
| 106 | 159 | } | |
| 107 | 160 | ||
| 108 | 161 | /* Follow the VC cursor*/ | |
modified drivers/ata/libata-scsi.c
| @@ -3059,10 +3059,15 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
| 3059 | 3059 | if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) | |
| 3060 | 3060 | qc->dev->sdev->locked = 0; | |
| 3061 | 3061 | ||
| 3062 | - | if (cmd->result) | |
| 3063 | - | ata_scsi_qc_done(qc, false, 0); | |
| 3064 | - | else | |
| 3065 | - | ata_scsi_qc_done(qc, true, SAM_STAT_CHECK_CONDITION); | |
| 3062 | + | /* | |
| 3063 | + | * Report CHECK CONDITION unless the command was terminated | |
| 3064 | + | * with a host byte set. Only set the status byte, so that the | |
| 3065 | + | * SCSI midlayer internal byte, which scsi_check_sense() may | |
| 3066 | + | * have set from the sense data, is preserved. | |
| 3067 | + | */ | |
| 3068 | + | if (get_host_byte(cmd) == DID_OK) | |
| 3069 | + | set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); | |
| 3070 | + | ata_scsi_qc_done(qc, false, 0); | |
| 3066 | 3071 | goto schedule_deferred; | |
| 3067 | 3072 | } | |
| 3068 | 3073 | ||
modified drivers/block/zloop.c
| @@ -800,6 +800,27 @@ static void zloop_cmd_workfn(struct work_struct *work) | |||
| 800 | 800 | current->flags = orig_flags; | |
| 801 | 801 | } | |
| 802 | 802 | ||
| 803 | + | static void zloop_fill_zero_rq(struct request *rq, unsigned int zero_from) | |
| 804 | + | { | |
| 805 | + | struct req_iterator iter; | |
| 806 | + | struct bio_vec bv; | |
| 807 | + | unsigned int pos = 0; | |
| 808 | + | unsigned int end, off; | |
| 809 | + | ||
| 810 | + | rq_for_each_segment(bv, rq, iter) { | |
| 811 | + | end = pos + bv.bv_len; | |
| 812 | + | if (end > zero_from) { | |
| 813 | + | if (pos < zero_from) | |
| 814 | + | off = zero_from - pos; | |
| 815 | + | else | |
| 816 | + | off = 0; | |
| 817 | + | memzero_page(bv.bv_page, bv.bv_offset + off, | |
| 818 | + | bv.bv_len - off); | |
| 819 | + | } | |
| 820 | + | pos = end; | |
| 821 | + | } | |
| 822 | + | } | |
| 823 | + | ||
| 803 | 824 | static void zloop_complete_rq(struct request *rq) | |
| 804 | 825 | { | |
| 805 | 826 | struct zloop_cmd *cmd = blk_mq_rq_to_pdu(rq); | |
| @@ -814,13 +835,9 @@ static void zloop_complete_rq(struct request *rq) | |||
| 814 | 835 | pr_err("Zone %u: failed read sector %llu, %llu sectors\n", | |
| 815 | 836 | zone_no, cmd->sector, cmd->nr_sectors); | |
| 816 | 837 | ||
| 817 | - | if (cmd->ret >= 0 && cmd->ret != blk_rq_bytes(rq)) { | |
| 818 | - | /* short read */ | |
| 819 | - | struct bio *bio; | |
| 820 | - | ||
| 821 | - | __rq_for_each_bio(bio, rq) | |
| 822 | - | zero_fill_bio(bio); | |
| 823 | - | } | |
| 838 | + | /* Short read. Zero out the unread tail beyond cmd->ret. */ | |
| 839 | + | if (cmd->ret >= 0 && cmd->ret != blk_rq_bytes(rq)) | |
| 840 | + | zloop_fill_zero_rq(rq, cmd->ret); | |
| 824 | 841 | break; | |
| 825 | 842 | case REQ_OP_WRITE: | |
| 826 | 843 | case REQ_OP_ZONE_APPEND: | |
modified drivers/bluetooth/btintel_pcie.c
| @@ -401,7 +401,7 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data, | |||
| 401 | 401 | ||
| 402 | 402 | tfd_index = data->ia.tr_hia[BTINTEL_PCIE_TXQ_NUM]; | |
| 403 | 403 | ||
| 404 | - | if (tfd_index > txq->count) | |
| 404 | + | if (tfd_index >= txq->count) | |
| 405 | 405 | return -ERANGE; | |
| 406 | 406 | ||
| 407 | 407 | if (skb->len > BTINTEL_PCIE_BUFFER_SIZE - BTINTEL_PCIE_HCI_TYPE_LEN) { | |
| @@ -1777,7 +1777,7 @@ static irqreturn_t btintel_pcie_irq_msix_handler(int irq, void *dev_id) | |||
| 1777 | 1777 | static int btintel_pcie_setup_irq(struct btintel_pcie_data *data) | |
| 1778 | 1778 | { | |
| 1779 | 1779 | int err; | |
| 1780 | - | int num_irqs, i; | |
| 1780 | + | int num_irqs, i, j; | |
| 1781 | 1781 | ||
| 1782 | 1782 | for (i = 0; i < BTINTEL_PCIE_MSIX_VEC_MAX; i++) | |
| 1783 | 1783 | data->msix_entries[i].entry = i; | |
| @@ -1806,6 +1806,10 @@ static int btintel_pcie_setup_irq(struct btintel_pcie_data *data) | |||
| 1806 | 1806 | KBUILD_MODNAME, | |
| 1807 | 1807 | msix_entry); | |
| 1808 | 1808 | if (err) { | |
| 1809 | + | for (j = 0; j < i; j++) | |
| 1810 | + | devm_free_irq(&data->pdev->dev, | |
| 1811 | + | data->msix_entries[j].vector, | |
| 1812 | + | &data->msix_entries[j]); | |
| 1809 | 1813 | pci_free_irq_vectors(data->pdev); | |
| 1810 | 1814 | data->alloc_vecs = 0; | |
| 1811 | 1815 | return err; | |
| @@ -1877,6 +1881,13 @@ static int btintel_pcie_config_pcie(struct pci_dev *pdev, | |||
| 1877 | 1881 | if (IS_ERR(data->base_addr)) | |
| 1878 | 1882 | return PTR_ERR(data->base_addr); | |
| 1879 | 1883 | ||
| 1884 | + | /* Do shared hardware reset to ensure a clean start before | |
| 1885 | + | * configuring interrupts. | |
| 1886 | + | */ | |
| 1887 | + | err = btintel_pcie_reset_bt(data); | |
| 1888 | + | if (err) | |
| 1889 | + | return err; | |
| 1890 | + | ||
| 1880 | 1891 | err = btintel_pcie_setup_irq(data); | |
| 1881 | 1892 | if (err) | |
| 1882 | 1893 | return err; | |
| @@ -3138,7 +3149,7 @@ static void btintel_pcie_remove(struct pci_dev *pdev) | |||
| 3138 | 3149 | struct msix_entry *msix_entry; | |
| 3139 | 3150 | ||
| 3140 | 3151 | msix_entry = &data->msix_entries[i]; | |
| 3141 | - | free_irq(msix_entry->vector, msix_entry); | |
| 3152 | + | devm_free_irq(&pdev->dev, msix_entry->vector, msix_entry); | |
| 3142 | 3153 | } | |
| 3143 | 3154 | ||
| 3144 | 3155 | pci_free_irq_vectors(pdev); | |
modified drivers/char/mem.c
| @@ -503,7 +503,7 @@ static int mmap_zero_prepare(struct vm_area_desc *desc) | |||
| 503 | 503 | #ifndef CONFIG_MMU | |
| 504 | 504 | return -ENOSYS; | |
| 505 | 505 | #endif | |
| 506 | - | if (vma_desc_test(desc, VMA_SHARED_BIT)) | |
| 506 | + | if (vma_desc_test(desc, VMA_MAYSHARE_BIT)) | |
| 507 | 507 | return shmem_zero_setup_desc(desc); | |
| 508 | 508 | ||
| 509 | 509 | /* | |
modified drivers/clk/qcom/gcc-eliza.c
| @@ -3010,8 +3010,6 @@ static const u32 gcc_eliza_critical_cbcrs[] = { | |||
| 3010 | 3010 | 0x26034, /* GCC_CAMERA_XO_CLK */ | |
| 3011 | 3011 | 0x27004, /* GCC_DISP_AHB_CLK */ | |
| 3012 | 3012 | 0x71004, /* GCC_GPU_CFG_AHB_CLK */ | |
| 3013 | - | 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3014 | - | 0x52010, /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3015 | 3013 | 0x32004, /* GCC_VIDEO_AHB_CLK */ | |
| 3016 | 3014 | 0x32038, /* GCC_VIDEO_XO_CLK */ | |
| 3017 | 3015 | }; | |
| @@ -3045,6 +3043,10 @@ static const struct regmap_config gcc_eliza_regmap_config = { | |||
| 3045 | 3043 | ||
| 3046 | 3044 | static void clk_eliza_regs_configure(struct device *dev, struct regmap *regmap) | |
| 3047 | 3045 | { | |
| 3046 | + | /* Keep clocks always enabled */ | |
| 3047 | + | regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3048 | + | regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3049 | + | ||
| 3048 | 3050 | /* FORCE_MEM_CORE_ON for ufs phy ice core and gcc ufs phy axi clocks */ | |
| 3049 | 3051 | qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true); | |
| 3050 | 3052 | qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_axi_clk, true); | |
modified drivers/clk/qcom/gcc-hawi.c
| @@ -3692,8 +3692,6 @@ static const u32 gcc_hawi_critical_cbcrs[] = { | |||
| 3692 | 3692 | 0x67084, /* GCC_PCIE_1_RSC_CORE_CLK */ | |
| 3693 | 3693 | 0x43014, /* GCC_PCIE_LINK_XO_CLK */ | |
| 3694 | 3694 | 0x6b088, /* GCC_PCIE_RSC_CORE_CLK */ | |
| 3695 | - | 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3696 | - | 0x52010, /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3697 | 3695 | 0x32004, /* GCC_VIDEO_AHB_CLK */ | |
| 3698 | 3696 | 0x32028, /* GCC_VIDEO_XO_CLK */ | |
| 3699 | 3697 | }; | |
| @@ -3763,6 +3761,10 @@ static const struct regmap_config gcc_hawi_regmap_config = { | |||
| 3763 | 3761 | ||
| 3764 | 3762 | static void clk_hawi_regs_configure(struct device *dev, struct regmap *regmap) | |
| 3765 | 3763 | { | |
| 3764 | + | /* Keep clocks always enabled */ | |
| 3765 | + | regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3766 | + | regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3767 | + | ||
| 3766 | 3768 | /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */ | |
| 3767 | 3769 | qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true); | |
| 3768 | 3770 | } | |
modified drivers/clk/qcom/gcc-kaanapali.c
| @@ -3464,8 +3464,6 @@ static const u32 gcc_kaanapali_critical_cbcrs[] = { | |||
| 3464 | 3464 | 0x9f004, /* GCC_EVA_AHB_CLK */ | |
| 3465 | 3465 | 0x9f024, /* GCC_EVA_XO_CLK */ | |
| 3466 | 3466 | 0x71004, /* GCC_GPU_CFG_AHB_CLK */ | |
| 3467 | - | 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3468 | - | 0x52010, /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3469 | 3467 | 0x32004, /* GCC_VIDEO_AHB_CLK */ | |
| 3470 | 3468 | 0x32040, /* GCC_VIDEO_XO_CLK */ | |
| 3471 | 3469 | }; | |
| @@ -3480,6 +3478,10 @@ static const struct regmap_config gcc_kaanapali_regmap_config = { | |||
| 3480 | 3478 | ||
| 3481 | 3479 | static void clk_kaanapali_regs_configure(struct device *dev, struct regmap *regmap) | |
| 3482 | 3480 | { | |
| 3481 | + | /* Keep clocks always enabled */ | |
| 3482 | + | regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */ | |
| 3483 | + | regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */ | |
| 3484 | + | ||
| 3483 | 3485 | /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */ | |
| 3484 | 3486 | qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true); | |
| 3485 | 3487 | } | |
modified drivers/clk/qcom/gpucc-glymur.c
| @@ -510,7 +510,7 @@ static struct gdsc gpu_cc_cx_gdsc = { | |||
| 510 | 510 | .name = "gpu_cc_cx_gdsc", | |
| 511 | 511 | }, | |
| 512 | 512 | .pwrsts = PWRSTS_OFF_ON, | |
| 513 | - | .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE, | |
| 513 | + | .flags = RETAIN_FF_ENABLE | VOTABLE, | |
| 514 | 514 | }; | |
| 515 | 515 | ||
| 516 | 516 | static struct clk_regmap *gpu_cc_glymur_clocks[] = { | |
modified drivers/clk/qcom/gpucc-kaanapali.c
| @@ -380,7 +380,7 @@ static struct gdsc gpu_cc_cx_gdsc = { | |||
| 380 | 380 | .name = "gpu_cc_cx_gdsc", | |
| 381 | 381 | }, | |
| 382 | 382 | .pwrsts = PWRSTS_OFF_ON, | |
| 383 | - | .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE, | |
| 383 | + | .flags = RETAIN_FF_ENABLE | VOTABLE, | |
| 384 | 384 | }; | |
| 385 | 385 | ||
| 386 | 386 | static struct clk_regmap *gpu_cc_kaanapali_clocks[] = { | |
modified drivers/edac/amd64_edac.c
| @@ -2796,13 +2796,13 @@ static inline void decode_bus_error(int node_id, struct mce *m) | |||
| 2796 | 2796 | * the instance_id. For example, instance_id=0xYXXXXX where Y is the channel | |
| 2797 | 2797 | * number. | |
| 2798 | 2798 | * | |
| 2799 | - | * For DRAM ECC errors, the Chip Select number is given in bits [2:0] of | |
| 2799 | + | * For DRAM ECC errors, the Chip Select number is given in bits [1:0] of | |
| 2800 | 2800 | * the MCA_SYND[ErrorInformation] field. | |
| 2801 | 2801 | */ | |
| 2802 | 2802 | static void umc_get_err_info(struct mce *m, struct err_info *err) | |
| 2803 | 2803 | { | |
| 2804 | 2804 | err->channel = (m->ipid & GENMASK(31, 0)) >> 20; | |
| 2805 | - | err->csrow = m->synd & 0x7; | |
| 2805 | + | err->csrow = m->synd & 0x3; | |
| 2806 | 2806 | } | |
| 2807 | 2807 | ||
| 2808 | 2808 | static void decode_umc_error(int node_id, struct mce *m) | |
modified drivers/gpio/gpio-exar.c
| @@ -199,6 +199,7 @@ static int gpio_exar_probe(struct platform_device *pdev) | |||
| 199 | 199 | index = ida_alloc(&ida_index, GFP_KERNEL); | |
| 200 | 200 | if (index < 0) | |
| 201 | 201 | return index; | |
| 202 | + | exar_gpio->index = index; | |
| 202 | 203 | ||
| 203 | 204 | ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio); | |
| 204 | 205 | if (ret) | |
| @@ -214,7 +215,6 @@ static int gpio_exar_probe(struct platform_device *pdev) | |||
| 214 | 215 | exar_gpio->gpio_chip.set = exar_set_value; | |
| 215 | 216 | exar_gpio->gpio_chip.base = -1; | |
| 216 | 217 | exar_gpio->gpio_chip.ngpio = ngpios; | |
| 217 | - | exar_gpio->index = index; | |
| 218 | 218 | exar_gpio->first_pin = first_pin; | |
| 219 | 219 | ||
| 220 | 220 | ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio); | |
modified drivers/gpio/gpio-mpsse.c
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | #include <linux/cleanup.h> | |
| 11 | 11 | #include <linux/gpio/driver.h> | |
| 12 | 12 | #include <linux/mutex.h> | |
| 13 | + | #include <linux/rcupdate.h> | |
| 13 | 14 | #include <linux/spinlock.h> | |
| 14 | 15 | #include <linux/usb.h> | |
| 15 | 16 | ||
| @@ -24,6 +25,7 @@ struct mpsse_priv { | |||
| 24 | 25 | raw_spinlock_t irq_spin; /* protects worker list */ | |
| 25 | 26 | atomic_t irq_type[16]; /* pin -> edge detection type */ | |
| 26 | 27 | atomic_t irq_enabled; | |
| 28 | + | atomic_t dying; /* no new workers after disconnect */ | |
| 27 | 29 | int id; | |
| 28 | 30 | ||
| 29 | 31 | u8 gpio_outputs[2]; /* Output states for GPIOs [L, H] */ | |
| @@ -46,6 +48,7 @@ struct mpsse_worker { | |||
| 46 | 48 | atomic_t cancelled; | |
| 47 | 49 | struct list_head list; /* linked list */ | |
| 48 | 50 | struct list_head destroy; /* teardown linked list */ | |
| 51 | + | struct rcu_head rcu; /* deferred free for dying path */ | |
| 49 | 52 | }; | |
| 50 | 53 | ||
| 51 | 54 | struct bulk_desc { | |
| @@ -525,10 +528,24 @@ static void gpio_mpsse_irq_enable(struct irq_data *irqd) | |||
| 525 | 528 | worker->priv = priv; | |
| 526 | 529 | INIT_LIST_HEAD(&worker->list); | |
| 527 | 530 | INIT_WORK(&worker->work, gpio_mpsse_poll); | |
| 528 | - | schedule_work(&worker->work); | |
| 529 | 531 | ||
| 530 | - | scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) | |
| 532 | + | scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) { | |
| 533 | + | if (atomic_read(&priv->dying)) { | |
| 534 | + | /* | |
| 535 | + | * Cannot kfree() here: this callback | |
| 536 | + | * runs with the IRQ descriptor's raw | |
| 537 | + | * spinlock held and kfree() may sleep | |
| 538 | + | * on PREEMPT_RT. The worker is not | |
| 539 | + | * yet published, so the deferred free | |
| 540 | + | * is unobservable. | |
| 541 | + | */ | |
| 542 | + | kfree_rcu(worker, rcu); | |
| 543 | + | return; | |
| 544 | + | } | |
| 545 | + | ||
| 531 | 546 | list_add(&worker->list, &priv->workers); | |
| 547 | + | schedule_work(&worker->work); | |
| 548 | + | } | |
| 532 | 549 | } | |
| 533 | 550 | } | |
| 534 | 551 | ||
| @@ -704,6 +721,9 @@ static void gpio_mpsse_disconnect(struct usb_interface *intf) | |||
| 704 | 721 | { | |
| 705 | 722 | struct mpsse_priv *priv = usb_get_intfdata(intf); | |
| 706 | 723 | ||
| 724 | + | scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) | |
| 725 | + | atomic_set(&priv->dying, 1); | |
| 726 | + | ||
| 707 | 727 | /* | |
| 708 | 728 | * Lock prevents double-free of worker from here and the teardown | |
| 709 | 729 | * step at the beginning of gpio_mpsse_poll | |
modified drivers/gpio/gpio-xilinx.c
| @@ -271,14 +271,7 @@ static void xgpio_save_regs(struct xgpio_instance *chip) | |||
| 271 | 271 | ||
| 272 | 272 | static int xgpio_request(struct gpio_chip *chip, unsigned int offset) | |
| 273 | 273 | { | |
| 274 | - | int ret; | |
| 275 | - | ||
| 276 | - | ret = pm_runtime_get_sync(chip->parent); | |
| 277 | - | /* | |
| 278 | - | * If the device is already active pm_runtime_get() will return 1 on | |
| 279 | - | * success, but gpio_request still needs to return 0. | |
| 280 | - | */ | |
| 281 | - | return ret < 0 ? ret : 0; | |
| 274 | + | return pm_runtime_resume_and_get(chip->parent); | |
| 282 | 275 | } | |
| 283 | 276 | ||
| 284 | 277 | static void xgpio_free(struct gpio_chip *chip, unsigned int offset) | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
| @@ -598,14 +598,18 @@ int amdgpu_amdkfd_get_dmabuf_info(struct amdgpu_device *adev, int dma_buf_fd, | |||
| 598 | 598 | /* first get metadata_size by buffer = NULL */ | |
| 599 | 599 | r = amdgpu_bo_get_metadata(bo, NULL, 0, | |
| 600 | 600 | metadata_size, NULL); | |
| 601 | + | if (r) | |
| 602 | + | goto out_put; | |
| 601 | 603 | ||
| 602 | 604 | /* user buf_size is bigger than bo metadata_size | |
| 603 | 605 | * allocate a buf at kernel space and copy */ | |
| 604 | 606 | if (*metadata_size <= buffer_size) { | |
| 605 | 607 | *metadata_buffer = kzalloc(*metadata_size, GFP_KERNEL); | |
| 606 | 608 | ||
| 607 | - | if (!*metadata_buffer) | |
| 608 | - | return -ENOMEM; | |
| 609 | + | if (!*metadata_buffer) { | |
| 610 | + | r = -ENOMEM; | |
| 611 | + | goto out_put; | |
| 612 | + | } | |
| 609 | 613 | ||
| 610 | 614 | r = amdgpu_bo_get_metadata(bo, *metadata_buffer, *metadata_size, | |
| 611 | 615 | NULL, &metadata_flags); | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
| @@ -121,6 +121,20 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f, | |||
| 121 | 121 | ||
| 122 | 122 | *pos &= (1UL << 22) - 1; | |
| 123 | 123 | ||
| 124 | + | if (size > PAGE_SIZE) | |
| 125 | + | return -EINVAL; | |
| 126 | + | ||
| 127 | + | /* | |
| 128 | + | * Access the user buffer only while none of the locks below are held: | |
| 129 | + | * a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest | |
| 130 | + | * inside it. | |
| 131 | + | */ | |
| 132 | + | u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL); | |
| 133 | + | if (!data) | |
| 134 | + | return -ENOMEM; | |
| 135 | + | if (!read && copy_from_user(data, buf, size)) | |
| 136 | + | return -EFAULT; | |
| 137 | + | ||
| 124 | 138 | r = pm_runtime_get_sync(adev_to_drm(adev)->dev); | |
| 125 | 139 | if (r < 0) { | |
| 126 | 140 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
| @@ -152,28 +166,16 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f, | |||
| 152 | 166 | mutex_lock(&adev->pm.mutex); | |
| 153 | 167 | ||
| 154 | 168 | while (size) { | |
| 155 | - | uint32_t value; | |
| 156 | - | ||
| 157 | - | if (read) { | |
| 158 | - | value = RREG32(*pos >> 2); | |
| 159 | - | r = put_user(value, (uint32_t *)buf); | |
| 160 | - | } else { | |
| 161 | - | r = get_user(value, (uint32_t *)buf); | |
| 162 | - | if (!r) | |
| 163 | - | amdgpu_mm_wreg_mmio_rlc(adev, *pos >> 2, value, 0); | |
| 164 | - | } | |
| 165 | - | if (r) { | |
| 166 | - | result = r; | |
| 167 | - | goto end; | |
| 168 | - | } | |
| 169 | + | if (read) | |
| 170 | + | data[result >> 2] = RREG32(*pos >> 2); | |
| 171 | + | else | |
| 172 | + | amdgpu_mm_wreg_mmio_rlc(adev, *pos >> 2, data[result >> 2], 0); | |
| 169 | 173 | ||
| 170 | 174 | result += 4; | |
| 171 | - | buf += 4; | |
| 172 | 175 | *pos += 4; | |
| 173 | 176 | size -= 4; | |
| 174 | 177 | } | |
| 175 | 178 | ||
| 176 | - | end: | |
| 177 | 179 | if (use_bank) { | |
| 178 | 180 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0); | |
| 179 | 181 | mutex_unlock(&adev->grbm_idx_mutex); | |
| @@ -188,6 +190,10 @@ end: | |||
| 188 | 190 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
| 189 | 191 | ||
| 190 | 192 | amdgpu_virt_disable_access_debugfs(adev); | |
| 193 | + | ||
| 194 | + | if (read && copy_to_user(buf, data, result)) | |
| 195 | + | return -EFAULT; | |
| 196 | + | ||
| 191 | 197 | return result; | |
| 192 | 198 | } | |
| 193 | 199 | ||
| @@ -238,11 +244,24 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 off | |||
| 238 | 244 | struct amdgpu_device *adev = rd->adev; | |
| 239 | 245 | ssize_t result = 0; | |
| 240 | 246 | int r; | |
| 241 | - | uint32_t value; | |
| 242 | 247 | ||
| 243 | 248 | if (size & 0x3 || offset & 0x3) | |
| 244 | 249 | return -EINVAL; | |
| 245 | 250 | ||
| 251 | + | if (size > PAGE_SIZE) | |
| 252 | + | return -EINVAL; | |
| 253 | + | ||
| 254 | + | /* | |
| 255 | + | * Access the user buffer only while none of the locks below are held: | |
| 256 | + | * a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest | |
| 257 | + | * inside it. | |
| 258 | + | */ | |
| 259 | + | u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL); | |
| 260 | + | if (!data) | |
| 261 | + | return -ENOMEM; | |
| 262 | + | if (write_en && copy_from_user(data, buf, size)) | |
| 263 | + | return -EFAULT; | |
| 264 | + | ||
| 246 | 265 | r = pm_runtime_get_sync(adev_to_drm(adev)->dev); | |
| 247 | 266 | if (r < 0) { | |
| 248 | 267 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
| @@ -281,24 +300,16 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 off | |||
| 281 | 300 | mutex_lock(&adev->pm.mutex); | |
| 282 | 301 | ||
| 283 | 302 | while (size) { | |
| 284 | - | if (!write_en) { | |
| 285 | - | value = RREG32(offset >> 2); | |
| 286 | - | r = put_user(value, (uint32_t *)buf); | |
| 287 | - | } else { | |
| 288 | - | r = get_user(value, (uint32_t *)buf); | |
| 289 | - | if (!r) | |
| 290 | - | amdgpu_mm_wreg_mmio_rlc(adev, offset >> 2, value, rd->id.xcc_id); | |
| 291 | - | } | |
| 292 | - | if (r) { | |
| 293 | - | result = r; | |
| 294 | - | goto end; | |
| 295 | - | } | |
| 303 | + | if (!write_en) | |
| 304 | + | data[result >> 2] = RREG32(offset >> 2); | |
| 305 | + | else | |
| 306 | + | amdgpu_mm_wreg_mmio_rlc(adev, offset >> 2, data[result >> 2], | |
| 307 | + | rd->id.xcc_id); | |
| 296 | 308 | offset += 4; | |
| 297 | 309 | size -= 4; | |
| 298 | 310 | result += 4; | |
| 299 | - | buf += 4; | |
| 300 | 311 | } | |
| 301 | - | end: | |
| 312 | + | ||
| 302 | 313 | if (rd->id.use_grbm) { | |
| 303 | 314 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, rd->id.xcc_id); | |
| 304 | 315 | mutex_unlock(&adev->grbm_idx_mutex); | |
| @@ -317,6 +328,10 @@ end: | |||
| 317 | 328 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
| 318 | 329 | ||
| 319 | 330 | amdgpu_virt_disable_access_debugfs(adev); | |
| 331 | + | ||
| 332 | + | if (!write_en && copy_to_user(buf, data, result)) | |
| 333 | + | return -EFAULT; | |
| 334 | + | ||
| 320 | 335 | return result; | |
| 321 | 336 | } | |
| 322 | 337 | ||
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
| @@ -1080,20 +1080,17 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev) | |||
| 1080 | 1080 | case CHIP_RENOIR: | |
| 1081 | 1081 | adev->mman.keep_stolen_vga_memory = true; | |
| 1082 | 1082 | break; | |
| 1083 | - | case CHIP_POLARIS10: | |
| 1084 | - | case CHIP_POLARIS11: | |
| 1085 | - | case CHIP_POLARIS12: | |
| 1086 | - | /* MacBookPros with switchable graphics put VRAM at 0 when | |
| 1087 | - | * the iGPU is enabled which results in cursor issues if | |
| 1088 | - | * the cursor ends up at 0. Reserve vram at 0 in that case. | |
| 1089 | - | */ | |
| 1090 | - | if (adev->gmc.vram_start == 0) | |
| 1091 | - | adev->mman.keep_stolen_vga_memory = true; | |
| 1092 | - | break; | |
| 1093 | 1083 | default: | |
| 1094 | 1084 | adev->mman.keep_stolen_vga_memory = false; | |
| 1095 | 1085 | break; | |
| 1096 | 1086 | } | |
| 1087 | + | /* MacBookPros with switchable graphics put VRAM at 0 when | |
| 1088 | + | * the iGPU is enabled which results in cursor issues if | |
| 1089 | + | * the cursor ends up at 0. Reserve vram at 0 in that case. | |
| 1090 | + | */ | |
| 1091 | + | if ((adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) && | |
| 1092 | + | (adev->gmc.vram_start == 0)) | |
| 1093 | + | adev->mman.keep_stolen_vga_memory = true; | |
| 1097 | 1094 | ||
| 1098 | 1095 | if (amdgpu_sriov_vf(adev) || | |
| 1099 | 1096 | !amdgpu_device_has_display_hardware(adev)) { | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
| @@ -30,6 +30,7 @@ | |||
| 30 | 30 | #include <drm/amdgpu_drm.h> | |
| 31 | 31 | #include <drm/drm_drv.h> | |
| 32 | 32 | #include <drm/drm_fb_helper.h> | |
| 33 | + | #include <drm/drm_vblank.h> | |
| 33 | 34 | #include "amdgpu_uvd.h" | |
| 34 | 35 | #include "amdgpu_vce.h" | |
| 35 | 36 | #include "atom.h" | |
| @@ -1660,6 +1661,9 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc) | |||
| 1660 | 1661 | DRM_ERROR("Invalid crtc %u\n", pipe); | |
| 1661 | 1662 | return -EINVAL; | |
| 1662 | 1663 | } | |
| 1664 | + | if (!down_read_trylock(&adev->reset_domain->sem)) | |
| 1665 | + | return drm_crtc_vblank_count(crtc); | |
| 1666 | + | ||
| 1663 | 1667 | ||
| 1664 | 1668 | /* The hw increments its frame counter at start of vsync, not at start | |
| 1665 | 1669 | * of vblank, as is required by DRM core vblank counter handling. | |
| @@ -1705,6 +1709,7 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc) | |||
| 1705 | 1709 | DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n"); | |
| 1706 | 1710 | } | |
| 1707 | 1711 | ||
| 1712 | + | up_read(&adev->reset_domain->sem); | |
| 1708 | 1713 | return count; | |
| 1709 | 1714 | } | |
| 1710 | 1715 | ||
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
| @@ -472,6 +472,7 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, | |||
| 472 | 472 | u64 doorbell_index; | |
| 473 | 473 | struct drm_gem_object *gobj; | |
| 474 | 474 | struct amdgpu_userq_obj *db_obj = db_info->db_obj; | |
| 475 | + | struct amdgpu_bo *abo; | |
| 475 | 476 | int r, db_size; | |
| 476 | 477 | ||
| 477 | 478 | gobj = drm_gem_object_lookup(filp, db_info->doorbell_handle); | |
| @@ -480,7 +481,17 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, | |||
| 480 | 481 | return -EINVAL; | |
| 481 | 482 | } | |
| 482 | 483 | ||
| 483 | - | db_obj->obj = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj)); | |
| 484 | + | /* | |
| 485 | + | * Pinning a regular BO into the doorbell domain would discard its | |
| 486 | + | * contents, possibly those of a buffer shared by another client. | |
| 487 | + | */ | |
| 488 | + | abo = gem_to_amdgpu_bo(gobj); | |
| 489 | + | if (!(abo->preferred_domains & AMDGPU_GEM_DOMAIN_DOORBELL)) { | |
| 490 | + | drm_gem_object_put(gobj); | |
| 491 | + | return -EINVAL; | |
| 492 | + | } | |
| 493 | + | ||
| 494 | + | db_obj->obj = amdgpu_bo_ref(abo); | |
| 484 | 495 | drm_gem_object_put(gobj); | |
| 485 | 496 | ||
| 486 | 497 | r = amdgpu_bo_reserve(db_obj->obj, true); | |
modified drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
| @@ -361,8 +361,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, | |||
| 361 | 361 | ||
| 362 | 362 | compute_mqd = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size); | |
| 363 | 363 | if (IS_ERR(compute_mqd)) { | |
| 364 | - | DRM_ERROR("Failed to read user MQD\n"); | |
| 365 | - | r = -ENOMEM; | |
| 364 | + | r = PTR_ERR(compute_mqd); | |
| 366 | 365 | goto free_mqd; | |
| 367 | 366 | } | |
| 368 | 367 | ||
| @@ -406,8 +405,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, | |||
| 406 | 405 | ||
| 407 | 406 | mqd_gfx_v11 = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size); | |
| 408 | 407 | if (IS_ERR(mqd_gfx_v11)) { | |
| 409 | - | DRM_ERROR("Failed to read user MQD\n"); | |
| 410 | - | r = -ENOMEM; | |
| 408 | + | r = PTR_ERR(mqd_gfx_v11); | |
| 411 | 409 | goto free_mqd; | |
| 412 | 410 | } | |
| 413 | 411 | ||
| @@ -451,8 +449,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, | |||
| 451 | 449 | ||
| 452 | 450 | mqd_sdma_v11 = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size); | |
| 453 | 451 | if (IS_ERR(mqd_sdma_v11)) { | |
| 454 | - | DRM_ERROR("Failed to read sdma user MQD\n"); | |
| 455 | - | r = -ENOMEM; | |
| 452 | + | r = PTR_ERR(mqd_sdma_v11); | |
| 456 | 453 | goto free_mqd; | |
| 457 | 454 | } | |
| 458 | 455 | ||
modified drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
| @@ -572,12 +572,32 @@ static int allocate_doorbell(struct qcm_process_device *qpd, | |||
| 572 | 572 | * we need the physical sdma engine id in order to get the | |
| 573 | 573 | * correct doorbell offset. | |
| 574 | 574 | */ | |
| 575 | - | uint32_t valid_id = idx_offset[qpd->dqm->dev->node_id * | |
| 576 | - | get_num_all_sdma_engines(qpd->dqm) + | |
| 577 | - | q->properties.sdma_engine_id] | |
| 578 | - | + (q->properties.sdma_queue_id & 1) | |
| 579 | - | * KFD_QUEUE_DOORBELL_MIRROR_OFFSET | |
| 580 | - | + (q->properties.sdma_queue_id >> 1); | |
| 575 | + | u32 engine_base = idx_offset[dev->node_id * | |
| 576 | + | get_num_all_sdma_engines(qpd->dqm) + | |
| 577 | + | q->properties.sdma_engine_id]; | |
| 578 | + | u32 valid_id; | |
| 579 | + | ||
| 580 | + | /* | |
| 581 | + | * With the aqua_vanjaram doorbell layout, a shader doorbell | |
| 582 | + | * write whose 32-byte block starts in the previous engine's | |
| 583 | + | * range rings that engine instead. Engine ranges are 10 | |
| 584 | + | * indices apart (sdma_doorbell_range = 20 dwords, halved for | |
| 585 | + | * 8-byte doorbells, in aqua_vanjaram_doorbell_index_init()), | |
| 586 | + | * which puts odd engines 2 indices into a shared block. | |
| 587 | + | * Aligning costs at most 2 indices, and 8 queues per engine use | |
| 588 | + | * only 4 of the 10, so the aligned base stays in range. The | |
| 589 | + | * 512-index mirror offset keeps the alignment. | |
| 590 | + | */ | |
| 591 | + | if (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 3) || | |
| 592 | + | KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 4) || | |
| 593 | + | KFD_GC_VERSION(dev) == IP_VERSION(9, 5, 0)) | |
| 594 | + | engine_base = ALIGN(engine_base, | |
| 595 | + | KFD_SDMA_SHADER_DOORBELL_GRANULARITY); | |
| 596 | + | ||
| 597 | + | valid_id = engine_base + | |
| 598 | + | (q->properties.sdma_queue_id & 1) * | |
| 599 | + | KFD_QUEUE_DOORBELL_MIRROR_OFFSET + | |
| 600 | + | (q->properties.sdma_queue_id >> 1); | |
| 581 | 601 | ||
| 582 | 602 | if (restore_id && *restore_id != valid_id) | |
| 583 | 603 | return -EINVAL; | |
modified drivers/gpu/drm/amd/amdkfd/kfd_priv.h
| @@ -133,6 +133,13 @@ | |||
| 133 | 133 | */ | |
| 134 | 134 | #define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512 | |
| 135 | 135 | ||
| 136 | + | /* | |
| 137 | + | * On GC 9.4.3, 9.4.4 and 9.5.0, doorbell writes issued from shaders are | |
| 138 | + | * routed to an SDMA engine at 32-byte granularity, i.e. 4 indices with the | |
| 139 | + | * 8-byte SDMA doorbells used on SOC15. | |
| 140 | + | */ | |
| 141 | + | #define KFD_SDMA_SHADER_DOORBELL_GRANULARITY 4 | |
| 142 | + | ||
| 136 | 143 | /** | |
| 137 | 144 | * enum kfd_ioctl_flags - KFD ioctl flags | |
| 138 | 145 | * Various flags that can be set in &amdkfd_ioctl_desc.flags to control how | |
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
| @@ -3708,6 +3708,13 @@ static void amdgpu_dm_enable_self_refresh(struct amdgpu_display_manager *dm, | |||
| 3708 | 3708 | struct amdgpu_dm_connector *aconn = | |
| 3709 | 3709 | (struct amdgpu_dm_connector *)acrtc_state->stream->dm_stream_context; | |
| 3710 | 3710 | ||
| 3711 | + | if (!acrtc_state->base.async_flip) { | |
| 3712 | + | amdgpu_dm_psr_set_event(dm, acrtc_state->stream, false, | |
| 3713 | + | psr_event_immediate_flip, false); | |
| 3714 | + | amdgpu_dm_replay_set_event(dm, acrtc_state->stream, false, | |
| 3715 | + | replay_event_immediate_flip, false); | |
| 3716 | + | } | |
| 3717 | + | ||
| 3711 | 3718 | /* Decrement skip count when SR is enabled and we're doing fast updates. */ | |
| 3712 | 3719 | if (acrtc_state->update_type == UPDATE_TYPE_FAST && | |
| 3713 | 3720 | (psr->psr_feature_enabled || pr->replay_feature_enabled)) { | |
| @@ -4118,6 +4125,18 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state, | |||
| 4118 | 4125 | spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags); | |
| 4119 | 4126 | } | |
| 4120 | 4127 | mutex_lock(&dm->dc_lock); | |
| 4128 | + | /* | |
| 4129 | + | * Tearing (immediate) flips cannot work with panel self-refresh | |
| 4130 | + | * features. The event is cleared by | |
| 4131 | + | * amdgpu_dm_enable_self_refresh() once async flips stop. | |
| 4132 | + | */ | |
| 4133 | + | if (immediate_flip) { | |
| 4134 | + | dc_exit_ips_for_hw_access(dm->dc); | |
| 4135 | + | amdgpu_dm_psr_set_event(dm, acrtc_state->stream, true, | |
| 4136 | + | psr_event_immediate_flip, true); | |
| 4137 | + | amdgpu_dm_replay_set_event(dm, acrtc_state->stream, true, | |
| 4138 | + | replay_event_immediate_flip, true); | |
| 4139 | + | } | |
| 4121 | 4140 | update_planes_and_stream_adapter(dm->dc, | |
| 4122 | 4141 | acrtc_state->update_type, | |
| 4123 | 4142 | planes_count, | |
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
| @@ -1012,10 +1012,15 @@ decide_crtc_timing_for_drm_display_mode(struct drm_display_mode *drm_mode, | |||
| 1012 | 1012 | const struct drm_display_mode *native_mode, | |
| 1013 | 1013 | bool scale_enabled) | |
| 1014 | 1014 | { | |
| 1015 | + | /* Inserted modes copy the native sync; a sink mode with equal totals may not */ | |
| 1015 | 1016 | if (scale_enabled || ( | |
| 1016 | 1017 | native_mode->clock == drm_mode->clock && | |
| 1017 | 1018 | native_mode->htotal == drm_mode->htotal && | |
| 1018 | - | native_mode->vtotal == drm_mode->vtotal)) { | |
| 1019 | + | native_mode->vtotal == drm_mode->vtotal && | |
| 1020 | + | native_mode->hsync_start == drm_mode->hsync_start && | |
| 1021 | + | native_mode->hsync_end == drm_mode->hsync_end && | |
| 1022 | + | native_mode->vsync_start == drm_mode->vsync_start && | |
| 1023 | + | native_mode->vsync_end == drm_mode->vsync_end)) { | |
| 1019 | 1024 | if (native_mode->crtc_clock) | |
| 1020 | 1025 | copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode); | |
| 1021 | 1026 | } else { | |
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
| @@ -112,25 +112,7 @@ void amdgpu_dm_plane_fill_blending_from_plane_state(const struct drm_plane_state | |||
| 112 | 112 | ||
| 113 | 113 | if (plane_state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI || | |
| 114 | 114 | plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE) { | |
| 115 | - | static const uint32_t alpha_formats[] = { | |
| 116 | - | DRM_FORMAT_ARGB8888, | |
| 117 | - | DRM_FORMAT_RGBA8888, | |
| 118 | - | DRM_FORMAT_ABGR8888, | |
| 119 | - | DRM_FORMAT_ARGB2101010, | |
| 120 | - | DRM_FORMAT_ABGR2101010, | |
| 121 | - | DRM_FORMAT_ARGB16161616, | |
| 122 | - | DRM_FORMAT_ABGR16161616, | |
| 123 | - | DRM_FORMAT_ARGB16161616F, | |
| 124 | - | }; | |
| 125 | - | uint32_t format = plane_state->fb->format->format; | |
| 126 | - | unsigned int i; | |
| 127 | - | ||
| 128 | - | for (i = 0; i < ARRAY_SIZE(alpha_formats); ++i) { | |
| 129 | - | if (format == alpha_formats[i]) { | |
| 130 | - | *per_pixel_alpha = true; | |
| 131 | - | break; | |
| 132 | - | } | |
| 133 | - | } | |
| 115 | + | *per_pixel_alpha = plane_state->fb->format->has_alpha; | |
| 134 | 116 | ||
| 135 | 117 | if (*per_pixel_alpha && plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE) | |
| 136 | 118 | *pre_multiplied_alpha = false; | |
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
| @@ -1572,6 +1572,46 @@ static void dm_test_decide_crtc_timing_no_crtc_clock(struct kunit *test) | |||
| 1572 | 1572 | KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 0); | |
| 1573 | 1573 | } | |
| 1574 | 1574 | ||
| 1575 | + | static void dm_test_decide_crtc_timing_sink_mode_same_totals(struct kunit *test) | |
| 1576 | + | { | |
| 1577 | + | struct drm_display_mode native_mode = { | |
| 1578 | + | DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016, 4104, | |
| 1579 | + | 4400, 0, 2160, 2168, 2178, 2250, 0, | |
| 1580 | + | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }; | |
| 1581 | + | struct drm_display_mode drm_mode = { | |
| 1582 | + | DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184, 4272, | |
| 1583 | + | 4400, 0, 2160, 2168, 2178, 2250, 0, | |
| 1584 | + | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }; | |
| 1585 | + | ||
| 1586 | + | drm_mode_set_crtcinfo(&native_mode, 0); | |
| 1587 | + | drm_mode_set_crtcinfo(&drm_mode, 0); | |
| 1588 | + | ||
| 1589 | + | decide_crtc_timing_for_drm_display_mode(&drm_mode, &native_mode, false); | |
| 1590 | + | ||
| 1591 | + | KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 4096); | |
| 1592 | + | KUNIT_EXPECT_EQ(test, drm_mode.crtc_hsync_start, 4184); | |
| 1593 | + | } | |
| 1594 | + | ||
| 1595 | + | static void dm_test_decide_crtc_timing_inserted_mode(struct kunit *test) | |
| 1596 | + | { | |
| 1597 | + | struct drm_display_mode native_mode = { | |
| 1598 | + | DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016, 4104, | |
| 1599 | + | 4400, 0, 2160, 2168, 2178, 2250, 0, | |
| 1600 | + | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }; | |
| 1601 | + | struct drm_display_mode drm_mode; | |
| 1602 | + | ||
| 1603 | + | drm_mode_set_crtcinfo(&native_mode, 0); | |
| 1604 | + | drm_mode = native_mode; | |
| 1605 | + | drm_mode.hdisplay = 1920; | |
| 1606 | + | drm_mode.vdisplay = 1080; | |
| 1607 | + | drm_mode_set_crtcinfo(&drm_mode, 0); | |
| 1608 | + | ||
| 1609 | + | decide_crtc_timing_for_drm_display_mode(&drm_mode, &native_mode, false); | |
| 1610 | + | ||
| 1611 | + | KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 3840); | |
| 1612 | + | KUNIT_EXPECT_EQ(test, drm_mode.crtc_vdisplay, 2160); | |
| 1613 | + | } | |
| 1614 | + | ||
| 1575 | 1615 | /* Tests for amdgpu_dm_connector_funcs_reset() */ | |
| 1576 | 1616 | ||
| 1577 | 1617 | static const struct drm_connector_funcs dm_test_connector_funcs = { | |
| @@ -5635,6 +5675,8 @@ static struct kunit_case amdgpu_dm_connector_tests[] = { | |||
| 5635 | 5675 | KUNIT_CASE(dm_test_decide_crtc_timing_matching_mode), | |
| 5636 | 5676 | KUNIT_CASE(dm_test_decide_crtc_timing_no_copy), | |
| 5637 | 5677 | KUNIT_CASE(dm_test_decide_crtc_timing_no_crtc_clock), | |
| 5678 | + | KUNIT_CASE(dm_test_decide_crtc_timing_sink_mode_same_totals), | |
| 5679 | + | KUNIT_CASE(dm_test_decide_crtc_timing_inserted_mode), | |
| 5638 | 5680 | /* amdgpu_dm_connector_funcs_reset */ | |
| 5639 | 5681 | KUNIT_CASE(dm_test_funcs_reset_sets_defaults), | |
| 5640 | 5682 | KUNIT_CASE(dm_test_funcs_reset_edp_abm_level), | |
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/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/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_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_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/gud/gud_pipe.c
| @@ -507,6 +507,7 @@ int gud_plane_atomic_check(struct drm_plane *plane, | |||
| 507 | 507 | for_each_new_connector_in_state(state, connector, connector_state, i) { | |
| 508 | 508 | if (connector_state->crtc) | |
| 509 | 509 | break; | |
| 510 | + | connector_state = NULL; | |
| 510 | 511 | } | |
| 511 | 512 | ||
| 512 | 513 | /* | |
modified drivers/gpu/drm/i915/display/intel_cx0_phy.c
| @@ -2342,12 +2342,14 @@ static void intel_c10pll_dump_hw_state(struct drm_printer *p, | |||
| 2342 | 2342 | static bool is_arrowlake_s_by_host_bridge(void) | |
| 2343 | 2343 | { | |
| 2344 | 2344 | struct pci_dev *pdev = NULL; | |
| 2345 | - | u16 host_bridge_pci_dev_id; | |
| 2346 | - | ||
| 2347 | - | while ((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, pdev))) | |
| 2348 | - | host_bridge_pci_dev_id = pdev->device; | |
| 2345 | + | while ((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, pdev))) { | |
| 2346 | + | if (IS_ARROWLAKE_S_BY_HOST_BRIDGE_ID(pdev->device)) { | |
| 2347 | + | pci_dev_put(pdev); | |
| 2348 | + | return true; | |
| 2349 | + | } | |
| 2350 | + | } | |
| 2349 | 2351 | ||
| 2350 | - | return pdev && IS_ARROWLAKE_S_BY_HOST_BRIDGE_ID(host_bridge_pci_dev_id); | |
| 2352 | + | return false; | |
| 2351 | 2353 | } | |
| 2352 | 2354 | ||
| 2353 | 2355 | static u16 intel_c20_hdmi_tmds_tx_cgf_1(struct intel_display *display) | |
modified drivers/gpu/drm/i915/display/intel_dmc.c
| @@ -1023,6 +1023,55 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc, | |||
| 1023 | 1023 | } | |
| 1024 | 1024 | } | |
| 1025 | 1025 | ||
| 1026 | + | /* | |
| 1027 | + | * Check if the load address is within the valid range for the given DMC ID. | |
| 1028 | + | */ | |
| 1029 | + | static bool dmc_load_addr_sanity_check(struct intel_dmc *dmc, | |
| 1030 | + | u32 start_addr, u32 payload_size, | |
| 1031 | + | int header_ver, enum intel_dmc_id dmc_id) | |
| 1032 | + | { | |
| 1033 | + | u32 start_range, end_range, end_addr; | |
| 1034 | + | ||
| 1035 | + | if (header_ver != 3) | |
| 1036 | + | return true; | |
| 1037 | + | ||
| 1038 | + | switch (dmc_id) { | |
| 1039 | + | case DMC_FW_MAIN: | |
| 1040 | + | start_range = DMC_MAIN_PROGRAM_BASE_START; | |
| 1041 | + | end_range = DMC_MAIN_PROGRAM_BASE_END; | |
| 1042 | + | break; | |
| 1043 | + | case DMC_FW_PIPEA: | |
| 1044 | + | start_range = DMC_PIPEA_PROGRAM_BASE_START; | |
| 1045 | + | end_range = DMC_PIPEA_PROGRAM_BASE_END; | |
| 1046 | + | break; | |
| 1047 | + | case DMC_FW_PIPEB: | |
| 1048 | + | start_range = DMC_PIPEB_PROGRAM_BASE_START; | |
| 1049 | + | end_range = DMC_PIPEB_PROGRAM_BASE_END; | |
| 1050 | + | break; | |
| 1051 | + | case DMC_FW_PIPEC: | |
| 1052 | + | start_range = DMC_PIPEC_PROGRAM_BASE_START; | |
| 1053 | + | end_range = DMC_PIPEC_PROGRAM_BASE_END; | |
| 1054 | + | break; | |
| 1055 | + | case DMC_FW_PIPED: | |
| 1056 | + | start_range = DMC_PIPED_PROGRAM_BASE_START; | |
| 1057 | + | end_range = DMC_PIPED_PROGRAM_BASE_END; | |
| 1058 | + | break; | |
| 1059 | + | default: | |
| 1060 | + | MISSING_CASE(dmc_id); | |
| 1061 | + | return false; | |
| 1062 | + | } | |
| 1063 | + | ||
| 1064 | + | if (payload_size == 0) | |
| 1065 | + | end_addr = start_addr; | |
| 1066 | + | else if (check_add_overflow(start_addr, payload_size - 1, &end_addr)) | |
| 1067 | + | return false; | |
| 1068 | + | ||
| 1069 | + | if (start_addr < start_range || end_addr > end_range) | |
| 1070 | + | return false; | |
| 1071 | + | ||
| 1072 | + | return true; | |
| 1073 | + | } | |
| 1074 | + | ||
| 1026 | 1075 | static bool dmc_mmio_addr_sanity_check(struct intel_dmc *dmc, | |
| 1027 | 1076 | const u32 *mmioaddr, u32 mmio_count, | |
| 1028 | 1077 | int header_ver, enum intel_dmc_id dmc_id) | |
| @@ -1120,7 +1169,7 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1120 | 1169 | } | |
| 1121 | 1170 | ||
| 1122 | 1171 | /* Cache the dmc header info. */ | |
| 1123 | - | if (mmio_count > mmio_count_max) { | |
| 1172 | + | if (!mmio_count || mmio_count > mmio_count_max) { | |
| 1124 | 1173 | drm_err(display->drm, "DMC firmware has wrong mmio count %u\n", mmio_count); | |
| 1125 | 1174 | return 0; | |
| 1126 | 1175 | } | |
| @@ -1166,13 +1215,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1166 | 1215 | disable_dmc_evt(display, dmc_id, dmc_info->mmioaddr[i], | |
| 1167 | 1216 | dmc_info->mmiodata[i]) ? " (disabling)" : ""); | |
| 1168 | 1217 | } | |
| 1169 | - | dmc_info->mmio_count = mmio_count; | |
| 1170 | - | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1171 | 1218 | ||
| 1172 | 1219 | rem_size -= header_len_bytes; | |
| 1173 | 1220 | ||
| 1174 | 1221 | /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */ | |
| 1175 | - | payload_size = dmc_header->fw_size * 4; | |
| 1222 | + | if (check_mul_overflow(dmc_header->fw_size, 4u, &payload_size)) { | |
| 1223 | + | drm_err(display->drm, "DMC fw_size too large (%u dwords)\n", | |
| 1224 | + | dmc_header->fw_size); | |
| 1225 | + | return 0; | |
| 1226 | + | } | |
| 1227 | + | ||
| 1228 | + | if (!payload_size) { | |
| 1229 | + | drm_err(display->drm, "DMC firmware has empty payload\n"); | |
| 1230 | + | return 0; | |
| 1231 | + | } | |
| 1232 | + | ||
| 1176 | 1233 | if (rem_size < payload_size) | |
| 1177 | 1234 | goto error_truncated; | |
| 1178 | 1235 | ||
| @@ -1180,12 +1237,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc, | |||
| 1180 | 1237 | drm_err(display->drm, "DMC FW too big (%u bytes)\n", payload_size); | |
| 1181 | 1238 | return 0; | |
| 1182 | 1239 | } | |
| 1183 | - | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1240 | + | ||
| 1241 | + | if (!dmc_load_addr_sanity_check(dmc, start_mmioaddr, payload_size, | |
| 1242 | + | dmc_header->header_ver, dmc_id)) { | |
| 1243 | + | drm_err(display->drm, "DMC %d: firmware has wrong load address\n", dmc_id); | |
| 1244 | + | return 0; | |
| 1245 | + | } | |
| 1184 | 1246 | ||
| 1185 | 1247 | dmc_info->payload = kmalloc(payload_size, GFP_KERNEL); | |
| 1186 | 1248 | if (!dmc_info->payload) | |
| 1187 | 1249 | return 0; | |
| 1188 | 1250 | ||
| 1251 | + | dmc_info->mmio_count = mmio_count; | |
| 1252 | + | dmc_info->start_mmioaddr = start_mmioaddr; | |
| 1253 | + | dmc_info->dmc_fw_size = dmc_header->fw_size; | |
| 1254 | + | ||
| 1189 | 1255 | payload = (u8 *)(dmc_header) + header_len_bytes; | |
| 1190 | 1256 | memcpy(dmc_info->payload, payload, payload_size); | |
| 1191 | 1257 | ||
modified drivers/gpu/drm/i915/display/intel_dmc_regs.h
| @@ -521,6 +521,18 @@ enum pipedmc_event_id { | |||
| 521 | 521 | #define TGL_PIPE_MMIO_END(dmc_id) _PICK_EVEN(((dmc_id) - 1), _TGL_PIPEA_MMIO_END,\ | |
| 522 | 522 | _TGL_PIPEB_MMIO_END) | |
| 523 | 523 | ||
| 524 | + | /* For DMC header version v3*/ | |
| 525 | + | #define DMC_MAIN_PROGRAM_BASE_START 0x80000 | |
| 526 | + | #define DMC_MAIN_PROGRAM_BASE_END 0x86fff | |
| 527 | + | #define DMC_PIPEA_PROGRAM_BASE_START 0x90000 | |
| 528 | + | #define DMC_PIPEA_PROGRAM_BASE_END 0x96fff | |
| 529 | + | #define DMC_PIPEB_PROGRAM_BASE_START 0x98000 | |
| 530 | + | #define DMC_PIPEB_PROGRAM_BASE_END 0x9efff | |
| 531 | + | #define DMC_PIPEC_PROGRAM_BASE_START 0x52000 | |
| 532 | + | #define DMC_PIPEC_PROGRAM_BASE_END 0x53fff | |
| 533 | + | #define DMC_PIPED_PROGRAM_BASE_START 0x59000 | |
| 534 | + | #define DMC_PIPED_PROGRAM_BASE_END 0x5afff | |
| 535 | + | ||
| 524 | 536 | #define SKL_DMC_DC3_DC5_COUNT _MMIO(0x80030) | |
| 525 | 537 | #define SKL_DMC_DC5_DC6_COUNT _MMIO(0x8002C) | |
| 526 | 538 | #define BXT_DMC_DC3_DC5_COUNT _MMIO(0x80038) | |
modified drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
| @@ -1766,6 +1766,7 @@ static int eb_reinit_userptr(struct i915_execbuffer *eb) | |||
| 1766 | 1766 | ||
| 1767 | 1767 | static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb) | |
| 1768 | 1768 | { | |
| 1769 | + | const unsigned int count = eb->buffer_count; | |
| 1769 | 1770 | bool have_copy = false; | |
| 1770 | 1771 | struct eb_vma *ev; | |
| 1771 | 1772 | int err = 0; | |
| @@ -1868,7 +1869,6 @@ err: | |||
| 1868 | 1869 | ||
| 1869 | 1870 | out: | |
| 1870 | 1871 | if (have_copy) { | |
| 1871 | - | const unsigned int count = eb->buffer_count; | |
| 1872 | 1872 | unsigned int i; | |
| 1873 | 1873 | ||
| 1874 | 1874 | for (i = 0; i < count; i++) { | |
modified drivers/gpu/drm/i915/gt/intel_rps.c
| @@ -1904,7 +1904,8 @@ static void rps_work(struct work_struct *work) | |||
| 1904 | 1904 | ||
| 1905 | 1905 | out: | |
| 1906 | 1906 | spin_lock_irq(gt->irq_lock); | |
| 1907 | - | gen6_gt_pm_unmask_irq(gt, rps->pm_events); | |
| 1907 | + | if (intel_rps_is_active(rps)) | |
| 1908 | + | gen6_gt_pm_unmask_irq(gt, rps->pm_events); | |
| 1908 | 1909 | spin_unlock_irq(gt->irq_lock); | |
| 1909 | 1910 | } | |
| 1910 | 1911 | ||
modified drivers/gpu/drm/imagination/pvr_mmu.c
| @@ -2337,7 +2337,7 @@ void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx) | |||
| 2337 | 2337 | * @ctx: MMU context associated with owning VM context. | |
| 2338 | 2338 | * @sgt: Scatter gather table containing pages pinned for use by this context. | |
| 2339 | 2339 | * @device_addr: Virtual device address at the start of the requested mapping. | |
| 2340 | - | * @sgt_offset: Start offset of the requested device-virtual memory mapping. | |
| 2340 | + | * @sgt_offset: Offset into @sgt of the start of the requested mapping. | |
| 2341 | 2341 | * @size: Size in bytes of the requested device-virtual memory mapping. For an | |
| 2342 | 2342 | * unmapping, this should be zero so that no page tables are allocated. | |
| 2343 | 2343 | * | |
| @@ -2350,7 +2350,6 @@ struct pvr_mmu_op_context * | |||
| 2350 | 2350 | pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt, | |
| 2351 | 2351 | u64 device_addr, u64 sgt_offset, u64 size) | |
| 2352 | 2352 | { | |
| 2353 | - | u64 start_addr = device_addr + sgt_offset; | |
| 2354 | 2353 | int err; | |
| 2355 | 2354 | ||
| 2356 | 2355 | struct pvr_mmu_op_context *op_ctx = kzalloc_obj(*op_ctx); | |
| @@ -2365,18 +2364,18 @@ pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt, | |||
| 2365 | 2364 | ||
| 2366 | 2365 | if (size) { | |
| 2367 | 2366 | /* | |
| 2368 | - | * The number of page table objects we need to prealloc is | |
| 2369 | - | * indicated by the mapping size, start address and the sizes | |
| 2370 | - | * of the areas mapped per PT or PD. The range calculation is | |
| 2371 | - | * identical to that for the index into a table for a device | |
| 2372 | - | * 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. | |
| 2373 | 2371 | */ | |
| 2374 | - | const u32 l1_start_idx = pvr_page_table_l2_idx(start_addr); | |
| 2375 | - | const u32 l1_end_idx = pvr_page_table_l2_idx(start_addr + size); | |
| 2376 | - | const u32 l1_count = l1_end_idx - l1_start_idx + 1; | |
| 2377 | - | const u32 l0_start_idx = pvr_page_table_l1_idx(start_addr); | |
| 2378 | - | const u32 l0_end_idx = pvr_page_table_l1_idx(start_addr + size); | |
| 2379 | - | 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; | |
| 2380 | 2379 | ||
| 2381 | 2380 | /* | |
| 2382 | 2381 | * Alloc and push page table entries until we have enough of | |
modified drivers/gpu/drm/imagination/pvr_vm.c
| @@ -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/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/nvkm/engine/device/user.c
| @@ -201,7 +201,7 @@ nvkm_udevice_gcx_ready(struct nvkm_udevice *udev, void *data, u32 size) | |||
| 201 | 201 | } *args = data; | |
| 202 | 202 | int ret = -ENOSYS; | |
| 203 | 203 | ||
| 204 | - | if (!gsp) { | |
| 204 | + | if (!gsp || !gsp->rm) { | |
| 205 | 205 | args->v0.ready = NV_DEVICE_GC6_READY | NV_DEVICE_GCOFF_READY; | |
| 206 | 206 | return 0; | |
| 207 | 207 | } | |
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/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_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_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/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/display/xe_fb_pin.c
| @@ -356,7 +356,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct drm_gem_object *obj, bool is_dpt, | |||
| 356 | 356 | drm_exec_retry_on_contention(&exec); | |
| 357 | 357 | xe_validation_retry_on_oom(&ctx, &ret); | |
| 358 | 358 | if (!ret) | |
| 359 | - | ttm_bo_pin(&bo->ttm); | |
| 359 | + | xe_bo_pin_account(bo); | |
| 360 | 360 | } | |
| 361 | 361 | if (ret) | |
| 362 | 362 | goto err; | |
| @@ -373,7 +373,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct drm_gem_object *obj, bool is_dpt, | |||
| 373 | 373 | ||
| 374 | 374 | err_unpin: | |
| 375 | 375 | ttm_bo_reserve(&bo->ttm, false, false, NULL); | |
| 376 | - | ttm_bo_unpin(&bo->ttm); | |
| 376 | + | xe_bo_unpin_account(bo); | |
| 377 | 377 | ttm_bo_unreserve(&bo->ttm); | |
| 378 | 378 | err: | |
| 379 | 379 | kfree(vma); | |
| @@ -393,7 +393,7 @@ static void __xe_unpin_fb_vma(struct i915_vma *vma) | |||
| 393 | 393 | xe_ggtt_node_remove(vma->node, false); | |
| 394 | 394 | ||
| 395 | 395 | ttm_bo_reserve(&vma->bo->ttm, false, false, NULL); | |
| 396 | - | ttm_bo_unpin(&vma->bo->ttm); | |
| 396 | + | xe_bo_unpin_account(vma->bo); | |
| 397 | 397 | ttm_bo_unreserve(&vma->bo->ttm); | |
| 398 | 398 | kfree(vma); | |
| 399 | 399 | } | |
modified drivers/gpu/drm/xe/xe_bo.c
| @@ -455,6 +455,100 @@ static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt) | |||
| 455 | 455 | xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0); | |
| 456 | 456 | } | |
| 457 | 457 | ||
| 458 | + | static bool xe_ttm_bo_is_imported(struct ttm_buffer_object *tbo) | |
| 459 | + | { | |
| 460 | + | dma_resv_assert_held(tbo->base.resv); | |
| 461 | + | ||
| 462 | + | return tbo->ttm && | |
| 463 | + | (tbo->ttm->page_flags & (TTM_TT_FLAG_EXTERNAL | TTM_TT_FLAG_EXTERNAL_MAPPABLE)) == | |
| 464 | + | TTM_TT_FLAG_EXTERNAL; | |
| 465 | + | } | |
| 466 | + | ||
| 467 | + | /* | |
| 468 | + | * Account @bo's pages as pinned for the shrinker. Removes @bo's pages | |
| 469 | + | * from the shrinker's shrinkable / purgeable counts on the transition | |
| 470 | + | * from unpinned to pinned. Must be called with @bo's dma-resv held, | |
| 471 | + | * after &ttm_buffer_object.pin_count has been incremented by | |
| 472 | + | * ttm_bo_pin(). Safe to call unconditionally regardless of which pin | |
| 473 | + | * path (kernel, external, framebuffer, backup object, ...) is pinning | |
| 474 | + | * @bo, since it only acts on the true 0->1 pin_count transition. | |
| 475 | + | * | |
| 476 | + | * Imported bos (xe_ttm_bo_is_imported()) are excluded: for those, | |
| 477 | + | * xe_ttm_tt_populate() never actually populates the tt or calls | |
| 478 | + | * xe_ttm_tt_account_add(), but TTM core's ttm_tt_populate() still | |
| 479 | + | * unconditionally marks the tt as populated on driver-hook success. | |
| 480 | + | * Relying on ttm_tt_is_populated() for these would subtract pages that | |
| 481 | + | * were never added, underflowing the shrinker's counts. | |
| 482 | + | */ | |
| 483 | + | static void xe_bo_account_pin(struct xe_bo *bo) | |
| 484 | + | { | |
| 485 | + | struct xe_device *xe = xe_bo_device(bo); | |
| 486 | + | ||
| 487 | + | if (bo->ttm.pin_count == 1 && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) && | |
| 488 | + | !xe_ttm_bo_is_imported(&bo->ttm)) | |
| 489 | + | xe_ttm_tt_account_subtract(xe, bo->ttm.ttm); | |
| 490 | + | } | |
| 491 | + | ||
| 492 | + | /* | |
| 493 | + | * Counterpart to xe_bo_account_pin(). Must be called with @bo's dma-resv | |
| 494 | + | * held, before &ttm_buffer_object.pin_count is decremented by | |
| 495 | + | * ttm_bo_unpin(), so that the check against the true 1->0 transition sees | |
| 496 | + | * the pin count that is about to be released. See xe_bo_account_pin() for | |
| 497 | + | * why imported bos are excluded. | |
| 498 | + | * | |
| 499 | + | * On the true last unpin, also removes @bo from whichever pinned-bo list | |
| 500 | + | * (external or kernel_bo_present) it may currently be linked on, since a | |
| 501 | + | * bo's final unpin can happen through a pin path (e.g. framebuffer, | |
| 502 | + | * backup object) that has no notion of, or ownership over, that list. | |
| 503 | + | * This is safe and list-agnostic: list_del_init() only needs the node | |
| 504 | + | * itself, not knowledge of which list it is threaded through, and is a | |
| 505 | + | * no-op if @bo is not linked. | |
| 506 | + | */ | |
| 507 | + | static void xe_bo_account_unpin(struct xe_bo *bo) | |
| 508 | + | { | |
| 509 | + | struct xe_device *xe = xe_bo_device(bo); | |
| 510 | + | bool last_unpin = bo->ttm.pin_count == 1; | |
| 511 | + | ||
| 512 | + | if (last_unpin && !list_empty(&bo->pinned_link)) { | |
| 513 | + | spin_lock(&xe->pinned.lock); | |
| 514 | + | list_del_init(&bo->pinned_link); | |
| 515 | + | spin_unlock(&xe->pinned.lock); | |
| 516 | + | } | |
| 517 | + | ||
| 518 | + | if (last_unpin && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) && | |
| 519 | + | !xe_ttm_bo_is_imported(&bo->ttm)) | |
| 520 | + | xe_ttm_tt_account_add(xe, bo->ttm.ttm); | |
| 521 | + | } | |
| 522 | + | ||
| 523 | + | /** | |
| 524 | + | * xe_bo_pin_account() - Pin a bo and account its pages for the shrinker | |
| 525 | + | * @bo: The buffer object to pin. | |
| 526 | + | * | |
| 527 | + | * Pins @bo via ttm_bo_pin() and updates the shrinker's shrinkable / | |
| 528 | + | * purgeable page accounting to match. Must be called with @bo's dma-resv | |
| 529 | + | * held. Safe to call regardless of which pin path (kernel, external, | |
| 530 | + | * framebuffer, backup object, ...) is pinning @bo. | |
| 531 | + | */ | |
| 532 | + | void xe_bo_pin_account(struct xe_bo *bo) | |
| 533 | + | { | |
| 534 | + | ttm_bo_pin(&bo->ttm); | |
| 535 | + | xe_bo_account_pin(bo); | |
| 536 | + | } | |
| 537 | + | ||
| 538 | + | /** | |
| 539 | + | * xe_bo_unpin_account() - Unpin a bo and account its pages for the shrinker | |
| 540 | + | * @bo: The buffer object to unpin. | |
| 541 | + | * | |
| 542 | + | * Counterpart to xe_bo_pin_account(). Updates the shrinker's shrinkable / | |
| 543 | + | * purgeable page accounting to match, then unpins @bo via ttm_bo_unpin(). | |
| 544 | + | * Must be called with @bo's dma-resv held. | |
| 545 | + | */ | |
| 546 | + | void xe_bo_unpin_account(struct xe_bo *bo) | |
| 547 | + | { | |
| 548 | + | xe_bo_account_unpin(bo); | |
| 549 | + | ttm_bo_unpin(&bo->ttm); | |
| 550 | + | } | |
| 551 | + | ||
| 458 | 552 | static void update_global_total_pages(struct ttm_device *ttm_dev, | |
| 459 | 553 | long num_pages) | |
| 460 | 554 | { | |
| @@ -1389,7 +1483,8 @@ int xe_bo_notifier_prepare_pinned(struct xe_bo *bo) | |||
| 1389 | 1483 | } | |
| 1390 | 1484 | ||
| 1391 | 1485 | backup->parent_obj = xe_bo_get(bo); /* Released by bo_destroy */ | |
| 1392 | - | ttm_bo_pin(&backup->ttm); | |
| 1486 | + | /* Note: XE_BO_FLAG_SYSTEM resolves to XE_PL_TT so already populated. */ | |
| 1487 | + | xe_bo_pin_account(backup); | |
| 1393 | 1488 | bo->backup_obj = backup; | |
| 1394 | 1489 | } | |
| 1395 | 1490 | ||
| @@ -1409,7 +1504,7 @@ int xe_bo_notifier_unprepare_pinned(struct xe_bo *bo) | |||
| 1409 | 1504 | { | |
| 1410 | 1505 | xe_bo_lock(bo, false); | |
| 1411 | 1506 | if (bo->backup_obj) { | |
| 1412 | - | ttm_bo_unpin(&bo->backup_obj->ttm); | |
| 1507 | + | xe_bo_unpin_account(bo->backup_obj); | |
| 1413 | 1508 | xe_bo_put(bo->backup_obj); | |
| 1414 | 1509 | bo->backup_obj = NULL; | |
| 1415 | 1510 | } | |
| @@ -1620,7 +1715,7 @@ out_backup: | |||
| 1620 | 1715 | xe_bo_vunmap(backup); | |
| 1621 | 1716 | if (!bo->backup_obj) { | |
| 1622 | 1717 | if (xe_bo_is_pinned(backup)) | |
| 1623 | - | ttm_bo_unpin(&backup->ttm); | |
| 1718 | + | xe_bo_unpin_account(backup); | |
| 1624 | 1719 | xe_bo_put(backup); | |
| 1625 | 1720 | } | |
| 1626 | 1721 | out_unlock_bo: | |
| @@ -2012,15 +2107,6 @@ static vm_fault_t xe_err_to_fault_t(int err) | |||
| 2012 | 2107 | return VM_FAULT_SIGBUS; | |
| 2013 | 2108 | } | |
| 2014 | 2109 | ||
| 2015 | - | static bool xe_ttm_bo_is_imported(struct ttm_buffer_object *tbo) | |
| 2016 | - | { | |
| 2017 | - | dma_resv_assert_held(tbo->base.resv); | |
| 2018 | - | ||
| 2019 | - | return tbo->ttm && | |
| 2020 | - | (tbo->ttm->page_flags & (TTM_TT_FLAG_EXTERNAL | TTM_TT_FLAG_EXTERNAL_MAPPABLE)) == | |
| 2021 | - | TTM_TT_FLAG_EXTERNAL; | |
| 2022 | - | } | |
| 2023 | - | ||
| 2024 | 2110 | static vm_fault_t xe_bo_cpu_fault_fastpath(struct vm_fault *vmf, struct xe_device *xe, | |
| 2025 | 2111 | struct xe_bo *bo, bool needs_rpm) | |
| 2026 | 2112 | { | |
| @@ -3141,12 +3227,13 @@ uint64_t vram_region_gpu_offset(struct ttm_resource *res) | |||
| 3141 | 3227 | int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec) | |
| 3142 | 3228 | { | |
| 3143 | 3229 | struct xe_device *xe = xe_bo_device(bo); | |
| 3230 | + | bool first_pin = !xe_bo_is_pinned(bo); | |
| 3144 | 3231 | int err; | |
| 3145 | 3232 | ||
| 3146 | 3233 | xe_assert(xe, !bo->vm); | |
| 3147 | 3234 | xe_assert(xe, xe_bo_is_user(bo)); | |
| 3148 | 3235 | ||
| 3149 | - | if (!xe_bo_is_pinned(bo)) { | |
| 3236 | + | if (first_pin) { | |
| 3150 | 3237 | if (!in_place) { | |
| 3151 | 3238 | err = xe_bo_validate(bo, NULL, false, exec); | |
| 3152 | 3239 | if (err) | |
| @@ -3158,9 +3245,7 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec) | |||
| 3158 | 3245 | spin_unlock(&xe->pinned.lock); | |
| 3159 | 3246 | } | |
| 3160 | 3247 | ||
| 3161 | - | ttm_bo_pin(&bo->ttm); | |
| 3162 | - | if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm)) | |
| 3163 | - | xe_ttm_tt_account_subtract(xe, bo->ttm.ttm); | |
| 3248 | + | xe_bo_pin_account(bo); | |
| 3164 | 3249 | ||
| 3165 | 3250 | /* | |
| 3166 | 3251 | * FIXME: If we always use the reserve / unreserve functions for locking | |
| @@ -3216,9 +3301,7 @@ int xe_bo_pin(struct xe_bo *bo, struct drm_exec *exec) | |||
| 3216 | 3301 | spin_unlock(&xe->pinned.lock); | |
| 3217 | 3302 | } | |
| 3218 | 3303 | ||
| 3219 | - | ttm_bo_pin(&bo->ttm); | |
| 3220 | - | if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm)) | |
| 3221 | - | xe_ttm_tt_account_subtract(xe, bo->ttm.ttm); | |
| 3304 | + | xe_bo_pin_account(bo); | |
| 3222 | 3305 | ||
| 3223 | 3306 | /* | |
| 3224 | 3307 | * FIXME: If we always use the reserve / unreserve functions for locking | |
| @@ -3247,14 +3330,7 @@ void xe_bo_unpin_external(struct xe_bo *bo) | |||
| 3247 | 3330 | xe_assert(xe, xe_bo_is_pinned(bo)); | |
| 3248 | 3331 | xe_assert(xe, xe_bo_is_user(bo)); | |
| 3249 | 3332 | ||
| 3250 | - | spin_lock(&xe->pinned.lock); | |
| 3251 | - | if (bo->ttm.pin_count == 1 && !list_empty(&bo->pinned_link)) | |
| 3252 | - | list_del_init(&bo->pinned_link); | |
| 3253 | - | spin_unlock(&xe->pinned.lock); | |
| 3254 | - | ||
| 3255 | - | ttm_bo_unpin(&bo->ttm); | |
| 3256 | - | if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm)) | |
| 3257 | - | xe_ttm_tt_account_add(xe, bo->ttm.ttm); | |
| 3333 | + | xe_bo_unpin_account(bo); | |
| 3258 | 3334 | ||
| 3259 | 3335 | /* | |
| 3260 | 3336 | * FIXME: If we always use the reserve / unreserve functions for locking | |
| @@ -3272,21 +3348,16 @@ void xe_bo_unpin(struct xe_bo *bo) | |||
| 3272 | 3348 | xe_assert(xe, xe_bo_is_pinned(bo)); | |
| 3273 | 3349 | ||
| 3274 | 3350 | if (mem_type_is_vram(place->mem_type) || bo->flags & XE_BO_FLAG_GGTT) { | |
| 3275 | - | spin_lock(&xe->pinned.lock); | |
| 3276 | 3351 | xe_assert(xe, !list_empty(&bo->pinned_link)); | |
| 3277 | - | list_del_init(&bo->pinned_link); | |
| 3278 | - | spin_unlock(&xe->pinned.lock); | |
| 3279 | 3352 | ||
| 3280 | 3353 | if (bo->backup_obj) { | |
| 3281 | 3354 | if (xe_bo_is_pinned(bo->backup_obj)) | |
| 3282 | - | ttm_bo_unpin(&bo->backup_obj->ttm); | |
| 3355 | + | xe_bo_unpin_account(bo->backup_obj); | |
| 3283 | 3356 | xe_bo_put(bo->backup_obj); | |
| 3284 | 3357 | bo->backup_obj = NULL; | |
| 3285 | 3358 | } | |
| 3286 | 3359 | } | |
| 3287 | - | ttm_bo_unpin(&bo->ttm); | |
| 3288 | - | if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm)) | |
| 3289 | - | xe_ttm_tt_account_add(xe, bo->ttm.ttm); | |
| 3360 | + | xe_bo_unpin_account(bo); | |
| 3290 | 3361 | } | |
| 3291 | 3362 | ||
| 3292 | 3363 | /** | |
modified drivers/gpu/drm/xe/xe_bo.h
| @@ -229,6 +229,8 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec); | |||
| 229 | 229 | int xe_bo_pin(struct xe_bo *bo, struct drm_exec *exec); | |
| 230 | 230 | void xe_bo_unpin_external(struct xe_bo *bo); | |
| 231 | 231 | void xe_bo_unpin(struct xe_bo *bo); | |
| 232 | + | void xe_bo_pin_account(struct xe_bo *bo); | |
| 233 | + | void xe_bo_unpin_account(struct xe_bo *bo); | |
| 232 | 234 | int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict, | |
| 233 | 235 | struct drm_exec *exec); | |
| 234 | 236 | ||
modified drivers/gpu/drm/xe/xe_i2c.c
| @@ -324,12 +324,15 @@ static void xe_i2c_remove(void *data) | |||
| 324 | 324 | xe_i2c_irq_reset(xe); | |
| 325 | 325 | xe_amc_exit(i2c); | |
| 326 | 326 | ||
| 327 | + | /* Stop the notifier from arming the client work before teardown. */ | |
| 328 | + | bus_unregister_notifier(&i2c_bus_type, &i2c->bus_notifier); | |
| 329 | + | cancel_work_sync(&i2c->work); | |
| 330 | + | ||
| 327 | 331 | for (i = 0; i < XE_I2C_MAX_CLIENTS; i++) { | |
| 328 | 332 | i2c_unregister_device(i2c->client[i]); | |
| 329 | 333 | i2c->client[i] = NULL; | |
| 330 | 334 | } | |
| 331 | 335 | ||
| 332 | - | bus_unregister_notifier(&i2c_bus_type, &i2c->bus_notifier); | |
| 333 | 336 | xe_i2c_unregister_adapter(i2c); | |
| 334 | 337 | xe->i2c = NULL; | |
| 335 | 338 | } | |
modified drivers/gpu/drm/xe/xe_lrc.c
| @@ -1099,8 +1099,7 @@ static void xe_lrc_finish(struct xe_lrc *lrc) | |||
| 1099 | 1099 | #define CONTEXT_ACTIVE XE_LRC_CTX_TIMESTAMP_ACTIVE | |
| 1100 | 1100 | static ssize_t setup_utilization_wa(struct xe_lrc *lrc, | |
| 1101 | 1101 | struct xe_hw_engine *hwe, | |
| 1102 | - | u32 *batch, | |
| 1103 | - | size_t max_len) | |
| 1102 | + | u32 *batch, size_t max_len, bool indirect) | |
| 1104 | 1103 | { | |
| 1105 | 1104 | u32 *cmd = batch; | |
| 1106 | 1105 | ||
| @@ -1131,19 +1130,25 @@ static ssize_t setup_utilization_wa(struct xe_lrc *lrc, | |||
| 1131 | 1130 | } | |
| 1132 | 1131 | ||
| 1133 | 1132 | static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe, | |
| 1134 | - | u32 *batch, size_t max_len) | |
| 1133 | + | u32 *batch, size_t max_len, bool indirect) | |
| 1135 | 1134 | { | |
| 1136 | 1135 | const u32 ts_addr = __xe_lrc_ctx_timestamp_ggtt_addr(lrc); | |
| 1137 | 1136 | u32 *cmd = batch; | |
| 1138 | 1137 | ||
| 1139 | - | if (!XE_GT_WA(lrc->gt, 16010904313) || | |
| 1140 | - | !(hwe->class == XE_ENGINE_CLASS_RENDER || | |
| 1141 | - | hwe->class == XE_ENGINE_CLASS_COMPUTE || | |
| 1142 | - | hwe->class == XE_ENGINE_CLASS_COPY || | |
| 1138 | + | if (!XE_GT_WA(lrc->gt, 16010904313)) | |
| 1139 | + | return 0; | |
| 1140 | + | ||
| 1141 | + | if (!indirect && | |
| 1142 | + | !(hwe->class == XE_ENGINE_CLASS_COPY || | |
| 1143 | 1143 | hwe->class == XE_ENGINE_CLASS_VIDEO_DECODE || | |
| 1144 | 1144 | hwe->class == XE_ENGINE_CLASS_VIDEO_ENHANCE)) | |
| 1145 | 1145 | return 0; | |
| 1146 | 1146 | ||
| 1147 | + | if (indirect && | |
| 1148 | + | !(hwe->class == XE_ENGINE_CLASS_RENDER || | |
| 1149 | + | hwe->class == XE_ENGINE_CLASS_COMPUTE)) | |
| 1150 | + | return 0; | |
| 1151 | + | ||
| 1147 | 1152 | if (xe_gt_WARN_ON(lrc->gt, max_len < 12)) | |
| 1148 | 1153 | return -ENOSPC; | |
| 1149 | 1154 | ||
| @@ -1169,7 +1174,8 @@ static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe, | |||
| 1169 | 1174 | ||
| 1170 | 1175 | static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc, | |
| 1171 | 1176 | struct xe_hw_engine *hwe, | |
| 1172 | - | u32 *batch, size_t max_len) | |
| 1177 | + | u32 *batch, size_t max_len, | |
| 1178 | + | bool indirect) | |
| 1173 | 1179 | { | |
| 1174 | 1180 | struct xe_device *xe = gt_to_xe(lrc->gt); | |
| 1175 | 1181 | const u32 *user_batch; | |
| @@ -1198,7 +1204,8 @@ static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc, | |||
| 1198 | 1204 | ||
| 1199 | 1205 | static ssize_t setup_configfs_mid_ctx_restore_bb(struct xe_lrc *lrc, | |
| 1200 | 1206 | struct xe_hw_engine *hwe, | |
| 1201 | - | u32 *batch, size_t max_len) | |
| 1207 | + | u32 *batch, size_t max_len, | |
| 1208 | + | bool indirect) | |
| 1202 | 1209 | { | |
| 1203 | 1210 | struct xe_device *xe = gt_to_xe(lrc->gt); | |
| 1204 | 1211 | const u32 *user_batch; | |
| @@ -1227,7 +1234,8 @@ static ssize_t setup_configfs_mid_ctx_restore_bb(struct xe_lrc *lrc, | |||
| 1227 | 1234 | ||
| 1228 | 1235 | static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc, | |
| 1229 | 1236 | struct xe_hw_engine *hwe, | |
| 1230 | - | u32 *batch, size_t max_len) | |
| 1237 | + | u32 *batch, size_t max_len, | |
| 1238 | + | bool indirect) | |
| 1231 | 1239 | { | |
| 1232 | 1240 | u32 *cmd = batch; | |
| 1233 | 1241 | ||
| @@ -1247,7 +1255,8 @@ static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc, | |||
| 1247 | 1255 | ||
| 1248 | 1256 | static ssize_t setup_invalidate_auxccs_wa(struct xe_lrc *lrc, | |
| 1249 | 1257 | struct xe_hw_engine *hwe, | |
| 1250 | - | u32 *batch, size_t max_len) | |
| 1258 | + | u32 *batch, size_t max_len, | |
| 1259 | + | bool indirect) | |
| 1251 | 1260 | { | |
| 1252 | 1261 | struct xe_gt *gt = lrc->gt; | |
| 1253 | 1262 | u32 *(*emit)(struct xe_gt *gt, u32 *cmd) = | |
| @@ -1264,7 +1273,7 @@ static ssize_t setup_invalidate_auxccs_wa(struct xe_lrc *lrc, | |||
| 1264 | 1273 | ||
| 1265 | 1274 | struct bo_setup { | |
| 1266 | 1275 | ssize_t (*setup)(struct xe_lrc *lrc, struct xe_hw_engine *hwe, | |
| 1267 | - | u32 *batch, size_t max_size); | |
| 1276 | + | u32 *batch, size_t max_size, bool indirect); | |
| 1268 | 1277 | }; | |
| 1269 | 1278 | ||
| 1270 | 1279 | struct bo_setup_state { | |
| @@ -1273,6 +1282,7 @@ struct bo_setup_state { | |||
| 1273 | 1282 | struct xe_hw_engine *hwe; | |
| 1274 | 1283 | size_t max_size; | |
| 1275 | 1284 | size_t reserve_dw; | |
| 1285 | + | bool indirect; | |
| 1276 | 1286 | unsigned int offset; | |
| 1277 | 1287 | const struct bo_setup *funcs; | |
| 1278 | 1288 | unsigned int num_funcs; | |
| @@ -1298,7 +1308,8 @@ static int setup_bo(struct bo_setup_state *state) | |||
| 1298 | 1308 | ||
| 1299 | 1309 | for (size_t i = 0; i < state->num_funcs; i++) { | |
| 1300 | 1310 | ssize_t len = state->funcs[i].setup(state->lrc, state->hwe, | |
| 1301 | - | state->ptr, remain); | |
| 1311 | + | state->ptr, remain, | |
| 1312 | + | state->indirect); | |
| 1302 | 1313 | ||
| 1303 | 1314 | remain -= len; | |
| 1304 | 1315 | ||
| @@ -1404,6 +1415,7 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe) | |||
| 1404 | 1415 | struct bo_setup_state state = { | |
| 1405 | 1416 | .lrc = lrc, | |
| 1406 | 1417 | .hwe = hwe, | |
| 1418 | + | .indirect = true, | |
| 1407 | 1419 | .max_size = (63 * 64) /* max 63 cachelines */, | |
| 1408 | 1420 | .buffer = NULL, | |
| 1409 | 1421 | .offset = __xe_lrc_indirect_ctx_offset(lrc), | |
modified drivers/gpu/drm/xe/xe_mmio.c
| @@ -320,6 +320,7 @@ u64 xe_mmio_read64_2x32(struct xe_mmio *mmio, struct xe_reg reg) | |||
| 320 | 320 | return (u64)udw << 32 | ldw; | |
| 321 | 321 | } | |
| 322 | 322 | ||
| 323 | + | #define __XE_MMIO_WAIT_MAX_BACKOFF_100MS (100 * USEC_PER_MSEC) | |
| 323 | 324 | static int __xe_mmio_wait32(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u32 val, | |
| 324 | 325 | u32 timeout_us, u32 *out_val, bool atomic, bool expect_match) | |
| 325 | 326 | { | |
| @@ -350,10 +351,10 @@ static int __xe_mmio_wait32(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u | |||
| 350 | 351 | wait = ktime_us_delta(end, cur); | |
| 351 | 352 | ||
| 352 | 353 | if (atomic) | |
| 353 | - | udelay(wait); | |
| 354 | + | udelay(min_t(s64, wait, (MAX_UDELAY_MS * 1000))); | |
| 354 | 355 | else | |
| 355 | 356 | usleep_range(wait, wait << 1); | |
| 356 | - | wait <<= 1; | |
| 357 | + | wait = min_t(s64, wait << 1, __XE_MMIO_WAIT_MAX_BACKOFF_100MS); | |
| 357 | 358 | } | |
| 358 | 359 | ||
| 359 | 360 | if (ret != 0) { | |
modified drivers/gpu/drm/xe/xe_sysctrl_mailbox.c
| @@ -19,20 +19,20 @@ | |||
| 19 | 19 | #include "xe_sysctrl_mailbox_types.h" | |
| 20 | 20 | ||
| 21 | 21 | struct xe_sysctrl_mailbox_msg_hdr { | |
| 22 | - | __le32 data; | |
| 23 | - | } __packed; | |
| 22 | + | u32 data; | |
| 23 | + | }; | |
| 24 | 24 | ||
| 25 | 25 | #define XE_SYSCTRL_HDR_GROUP_ID(hdr) \ | |
| 26 | - | FIELD_GET(SYSCTRL_HDR_GROUP_ID_MASK, le32_to_cpu((hdr)->data)) | |
| 26 | + | FIELD_GET(SYSCTRL_HDR_GROUP_ID_MASK, (hdr)->data) | |
| 27 | 27 | ||
| 28 | 28 | #define XE_SYSCTRL_HDR_COMMAND(hdr) \ | |
| 29 | - | FIELD_GET(SYSCTRL_HDR_COMMAND_MASK, le32_to_cpu((hdr)->data)) | |
| 29 | + | FIELD_GET(SYSCTRL_HDR_COMMAND_MASK, (hdr)->data) | |
| 30 | 30 | ||
| 31 | 31 | #define XE_SYSCTRL_HDR_IS_RESPONSE(hdr) \ | |
| 32 | - | FIELD_GET(SYSCTRL_HDR_IS_RESPONSE, le32_to_cpu((hdr)->data)) | |
| 32 | + | FIELD_GET(SYSCTRL_HDR_IS_RESPONSE, (hdr)->data) | |
| 33 | 33 | ||
| 34 | 34 | #define XE_SYSCTRL_HDR_RESULT(hdr) \ | |
| 35 | - | FIELD_GET(SYSCTRL_HDR_RESULT_MASK, le32_to_cpu((hdr)->data)) | |
| 35 | + | FIELD_GET(SYSCTRL_HDR_RESULT_MASK, (hdr)->data) | |
| 36 | 36 | ||
| 37 | 37 | static bool sysctrl_wait_bit_clear(struct xe_sysctrl *sc, u32 bit_mask, | |
| 38 | 38 | unsigned int timeout_ms) | |
| @@ -126,8 +126,8 @@ static int sysctrl_prepare_command(struct xe_device *xe, | |||
| 126 | 126 | return -ENOMEM; | |
| 127 | 127 | ||
| 128 | 128 | hdr = (struct xe_sysctrl_mailbox_msg_hdr *)buffer; | |
| 129 | - | hdr->data = cpu_to_le32(FIELD_PREP(SYSCTRL_HDR_GROUP_ID_MASK, group_id) | | |
| 130 | - | FIELD_PREP(SYSCTRL_HDR_COMMAND_MASK, command)); | |
| 129 | + | hdr->data = FIELD_PREP(SYSCTRL_HDR_GROUP_ID_MASK, group_id) | | |
| 130 | + | FIELD_PREP(SYSCTRL_HDR_COMMAND_MASK, command); | |
| 131 | 131 | ||
| 132 | 132 | if (data_in && data_in_len) | |
| 133 | 133 | memcpy(buffer + sizeof(*hdr), data_in, data_in_len); | |
modified drivers/i2c/busses/i2c-qcom-geni.c
| @@ -1003,13 +1003,14 @@ static int geni_i2c_xfer(struct i2c_adapter *adap, | |||
| 1003 | 1003 | ||
| 1004 | 1004 | ret = gi2c->dev_data->set_rate(&gi2c->se, gi2c->clk_freq_out); | |
| 1005 | 1005 | if (ret) | |
| 1006 | - | return ret; | |
| 1006 | + | goto out_pm; | |
| 1007 | 1007 | ||
| 1008 | 1008 | if (gi2c->gpi_mode) | |
| 1009 | 1009 | ret = geni_i2c_gpi_xfer(gi2c, msgs, num); | |
| 1010 | 1010 | else | |
| 1011 | 1011 | ret = geni_i2c_fifo_xfer(gi2c, msgs, num); | |
| 1012 | 1012 | ||
| 1013 | + | out_pm: | |
| 1013 | 1014 | pm_runtime_put_autosuspend(gi2c->se.dev); | |
| 1014 | 1015 | gi2c->cur = NULL; | |
| 1015 | 1016 | gi2c->err = 0; | |
modified drivers/input/joystick/xpad.c
| @@ -302,6 +302,8 @@ static const struct xpad_device { | |||
| 302 | 302 | { 0x17ef, 0x6182, "Lenovo Legion Controller for Windows", 0, XTYPE_XBOX360 }, | |
| 303 | 303 | { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 }, | |
| 304 | 304 | { 0x1a86, 0xe310, "Legion Go S", 0, XTYPE_XBOX360 }, | |
| 305 | + | { 0x1b1c, 0x2b1f, "Corsair Novablade Pro (Wired)", 0, XTYPE_XBOX360 }, | |
| 306 | + | { 0x1b1c, 0x2b2b, "Corsair Novablade Pro (2.4 GHz Receiver)", 0, XTYPE_XBOX360 }, | |
| 305 | 307 | { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 }, | |
| 306 | 308 | { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, | |
| 307 | 309 | { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, | |
| @@ -379,6 +381,7 @@ static const struct xpad_device { | |||
| 379 | 381 | { 0x2993, 0x2001, "TECNO Pocket Go", 0, XTYPE_XBOX360 }, | |
| 380 | 382 | { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE }, | |
| 381 | 383 | { 0x2dc8, 0x200f, "8BitDo Ultimate 3-mode Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE }, | |
| 384 | + | { 0x2dc8, 0x201e, "8BitDo Pro 2 Wired Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE }, | |
| 382 | 385 | { 0x2dc8, 0x3106, "8BitDo Ultimate Wireless / Pro 2 Wired Controller", 0, XTYPE_XBOX360 }, | |
| 383 | 386 | { 0x2dc8, 0x3109, "8BitDo Ultimate Wireless Bluetooth", 0, XTYPE_XBOX360 }, | |
| 384 | 387 | { 0x2dc8, 0x310a, "8BitDo Ultimate 2C Wireless Controller", 0, XTYPE_XBOX360 }, | |
| @@ -545,6 +548,7 @@ static const struct usb_device_id xpad_table[] = { | |||
| 545 | 548 | XPAD_XBOX360_VENDOR(0x17ef), /* Lenovo */ | |
| 546 | 549 | XPAD_XBOX360_VENDOR(0x1949), /* Amazon controllers */ | |
| 547 | 550 | XPAD_XBOX360_VENDOR(0x1a86), /* Nanjing Qinheng Microelectronics (WCH) */ | |
| 551 | + | XPAD_XBOX360_VENDOR(0x1b1c), /* Corsair controllers */ | |
| 548 | 552 | XPAD_XBOX360_VENDOR(0x1bad), /* Harmonix Rock Band guitar and drums */ | |
| 549 | 553 | XPAD_XBOX360_VENDOR(0x1ee9), /* ZOTAC Technology Limited */ | |
| 550 | 554 | XPAD_XBOX360_VENDOR(0x20bc), /* BETOP wireless dongles */ | |
modified drivers/input/misc/ati_remote2.c
| @@ -672,8 +672,7 @@ static ssize_t ati_remote2_show_channel_mask(struct device *dev, | |||
| 672 | 672 | struct device_attribute *attr, | |
| 673 | 673 | char *buf) | |
| 674 | 674 | { | |
| 675 | - | struct usb_device *udev = to_usb_device(dev); | |
| 676 | - | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); | |
| 675 | + | struct usb_interface *intf = to_usb_interface(dev); | |
| 677 | 676 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); | |
| 678 | 677 | ||
| 679 | 678 | return sprintf(buf, "0x%04x\n", ar2->channel_mask); | |
| @@ -683,8 +682,7 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev, | |||
| 683 | 682 | struct device_attribute *attr, | |
| 684 | 683 | const char *buf, size_t count) | |
| 685 | 684 | { | |
| 686 | - | struct usb_device *udev = to_usb_device(dev); | |
| 687 | - | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); | |
| 685 | + | struct usb_interface *intf = to_usb_interface(dev); | |
| 688 | 686 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); | |
| 689 | 687 | unsigned int mask; | |
| 690 | 688 | int r; | |
| @@ -720,8 +718,7 @@ static ssize_t ati_remote2_show_mode_mask(struct device *dev, | |||
| 720 | 718 | struct device_attribute *attr, | |
| 721 | 719 | char *buf) | |
| 722 | 720 | { | |
| 723 | - | struct usb_device *udev = to_usb_device(dev); | |
| 724 | - | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); | |
| 721 | + | struct usb_interface *intf = to_usb_interface(dev); | |
| 725 | 722 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); | |
| 726 | 723 | ||
| 727 | 724 | return sprintf(buf, "0x%02x\n", ar2->mode_mask); | |
| @@ -731,8 +728,7 @@ static ssize_t ati_remote2_store_mode_mask(struct device *dev, | |||
| 731 | 728 | struct device_attribute *attr, | |
| 732 | 729 | const char *buf, size_t count) | |
| 733 | 730 | { | |
| 734 | - | struct usb_device *udev = to_usb_device(dev); | |
| 735 | - | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); | |
| 731 | + | struct usb_interface *intf = to_usb_interface(dev); | |
| 736 | 732 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); | |
| 737 | 733 | unsigned int mask; | |
| 738 | 734 | int err; | |
modified drivers/iommu/dma-iommu.c
| @@ -1228,9 +1228,9 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size, | |||
| 1228 | 1228 | * If both the physical buffer start address and size are page aligned, | |
| 1229 | 1229 | * we don't need to use a bounce page. | |
| 1230 | 1230 | */ | |
| 1231 | - | if (dev_use_swiotlb(dev, size, dir) && | |
| 1231 | + | if (!(attrs & DMA_ATTR_MMIO) && dev_use_swiotlb(dev, size, dir) && | |
| 1232 | 1232 | iova_unaligned(iovad, phys, size)) { | |
| 1233 | - | if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT)) | |
| 1233 | + | if (attrs & DMA_ATTR_REQUIRE_COHERENT) | |
| 1234 | 1234 | return DMA_MAPPING_ERROR; | |
| 1235 | 1235 | ||
| 1236 | 1236 | phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs); | |
modified drivers/md/dm-crypt.c
| @@ -2894,8 +2894,13 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key | |||
| 2894 | 2894 | } | |
| 2895 | 2895 | } | |
| 2896 | 2896 | ||
| 2897 | - | if (*ivmode && !strcmp(*ivmode, "lmk")) | |
| 2897 | + | if (*ivmode && !strcmp(*ivmode, "lmk")) { | |
| 2898 | + | if (crypt_integrity_aead(cc)) { | |
| 2899 | + | ti->error = "AEAD transforms not supported for LMK"; | |
| 2900 | + | return -EINVAL; | |
| 2901 | + | } | |
| 2898 | 2902 | cc->tfms_count = 64; | |
| 2903 | + | } | |
| 2899 | 2904 | ||
| 2900 | 2905 | if (*ivmode && !strcmp(*ivmode, "essiv")) { | |
| 2901 | 2906 | if (!*ivopts) { | |
modified drivers/md/dm-integrity.c
| @@ -180,6 +180,7 @@ struct dm_integrity_c { | |||
| 180 | 180 | struct dm_bufio_client *bufio; | |
| 181 | 181 | struct workqueue_struct *metadata_wq; | |
| 182 | 182 | struct superblock *sb; | |
| 183 | + | struct superblock *sb_copy; | |
| 183 | 184 | unsigned int journal_pages; | |
| 184 | 185 | unsigned int n_bitmap_blocks; | |
| 185 | 186 | ||
| @@ -2721,7 +2722,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w) | |||
| 2721 | 2722 | outgoing_data = dio->integrity_payload + PAGE_SIZE; | |
| 2722 | 2723 | ||
| 2723 | 2724 | while (dio->bio_details.bi_iter.bi_size) { | |
| 2724 | - | char digest[HASH_MAX_DIGESTSIZE]; | |
| 2725 | + | char digest[MAX_T(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)]; | |
| 2725 | 2726 | int r; | |
| 2726 | 2727 | struct bio_integrity_payload *bip; | |
| 2727 | 2728 | struct bio_vec bv; | |
| @@ -2788,7 +2789,7 @@ static inline bool dm_integrity_check(struct dm_integrity_c *ic, struct dm_integ | |||
| 2788 | 2789 | unsigned pos = 0; | |
| 2789 | 2790 | ||
| 2790 | 2791 | while (dio->bio_details.bi_iter.bi_size) { | |
| 2791 | - | char digest[HASH_MAX_DIGESTSIZE]; | |
| 2792 | + | char digest[MAX_T(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)]; | |
| 2792 | 2793 | struct bio_vec bv = bio_iter_iovec(bio, dio->bio_details.bi_iter); | |
| 2793 | 2794 | char *mem = integrity_kmap(ic, bv.bv_page); | |
| 2794 | 2795 | integrity_sector_checksum(ic, &dio->ahash_req, dio->bio_details.bi_iter.bi_sector, mem, bv.bv_offset, digest); | |
| @@ -3858,6 +3859,35 @@ static void dm_integrity_postsuspend(struct dm_target *ti) | |||
| 3858 | 3859 | ic->journal_uptodate = true; | |
| 3859 | 3860 | } | |
| 3860 | 3861 | ||
| 3862 | + | /* | |
| 3863 | + | * The superblock is re-read from the device on every resume, so that we pick | |
| 3864 | + | * up the flags and the recalculate position. The geometry described by the | |
| 3865 | + | * superblock must not change though - the in-memory structures (and the | |
| 3866 | + | * journal in particular) were sized according to the superblock that was | |
| 3867 | + | * validated in the constructor. Reject a superblock that was modified behind | |
| 3868 | + | * our back. | |
| 3869 | + | * | |
| 3870 | + | * Only the fields that the driver never rewrites may be tested here. In | |
| 3871 | + | * particular, "version" is recalculated by sb_set_version on every superblock | |
| 3872 | + | * write and it depends on SB_FLAG_RECALCULATING and SB_FLAG_DIRTY_BITMAP, and | |
| 3873 | + | * SB_FLAG_DISCARD_KEYED may be set by dm_integrity_resume itself. | |
| 3874 | + | */ | |
| 3875 | + | static bool superblock_changed(struct dm_integrity_c *ic) | |
| 3876 | + | { | |
| 3877 | + | const __le32 immutable_flags = cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC | | |
| 3878 | + | SB_FLAG_FIXED_PADDING | | |
| 3879 | + | SB_FLAG_FIXED_HMAC | | |
| 3880 | + | SB_FLAG_INLINE); | |
| 3881 | + | ||
| 3882 | + | return memcmp(ic->sb->magic, ic->sb_copy->magic, sizeof(ic->sb->magic)) != 0 || | |
| 3883 | + | ic->sb->log2_interleave_sectors != ic->sb_copy->log2_interleave_sectors || | |
| 3884 | + | ic->sb->integrity_tag_size != ic->sb_copy->integrity_tag_size || | |
| 3885 | + | ic->sb->journal_sections != ic->sb_copy->journal_sections || | |
| 3886 | + | ic->sb->log2_sectors_per_block != ic->sb_copy->log2_sectors_per_block || | |
| 3887 | + | ((ic->sb->flags ^ ic->sb_copy->flags) & immutable_flags) != 0 || | |
| 3888 | + | memcmp(ic->sb->salt, ic->sb_copy->salt, SALT_SIZE) != 0; | |
| 3889 | + | } | |
| 3890 | + | ||
| 3861 | 3891 | static void dm_integrity_resume(struct dm_target *ti) | |
| 3862 | 3892 | { | |
| 3863 | 3893 | struct dm_integrity_c *ic = ti->private; | |
| @@ -3876,6 +3906,18 @@ static void dm_integrity_resume(struct dm_target *ti) | |||
| 3876 | 3906 | if (r) | |
| 3877 | 3907 | dm_integrity_io_error(ic, "reading superblock", r); | |
| 3878 | 3908 | ||
| 3909 | + | if (unlikely(superblock_changed(ic))) { | |
| 3910 | + | /* | |
| 3911 | + | * Restore the superblock that we validated in the constructor, | |
| 3912 | + | * so that the rest of the driver doesn't operate on values | |
| 3913 | + | * that don't match the in-memory structures. | |
| 3914 | + | */ | |
| 3915 | + | memcpy(ic->sb, ic->sb_copy, sizeof(struct superblock)); | |
| 3916 | + | DMERR("The superblock was changed while the device was suspended"); | |
| 3917 | + | dm_integrity_io_error(ic, "superblock check", -EINVAL); | |
| 3918 | + | goto skip_writes; | |
| 3919 | + | } | |
| 3920 | + | ||
| 3879 | 3921 | if (ic->mode == 'R') | |
| 3880 | 3922 | goto skip_writes; | |
| 3881 | 3923 | ||
| @@ -5427,6 +5469,13 @@ try_smaller_buffer: | |||
| 5427 | 5469 | ic->just_formatted = true; | |
| 5428 | 5470 | } | |
| 5429 | 5471 | ||
| 5472 | + | ic->sb_copy = kmemdup(ic->sb, sizeof(struct superblock), GFP_KERNEL); | |
| 5473 | + | if (!ic->sb_copy) { | |
| 5474 | + | ti->error = "Cannot allocate superblock copy"; | |
| 5475 | + | r = -ENOMEM; | |
| 5476 | + | goto bad; | |
| 5477 | + | } | |
| 5478 | + | ||
| 5430 | 5479 | if (!ic->meta_dev && ic->mode != 'I') { | |
| 5431 | 5480 | r = dm_set_target_max_io_len(ti, 1U << ic->sb->log2_interleave_sectors); | |
| 5432 | 5481 | if (r) | |
| @@ -5525,6 +5574,7 @@ static void dm_integrity_dtr(struct dm_target *ti) | |||
| 5525 | 5574 | kvfree(ic->journal_tree); | |
| 5526 | 5575 | if (ic->sb) | |
| 5527 | 5576 | free_pages_exact(ic->sb, SB_SECTORS << SECTOR_SHIFT); | |
| 5577 | + | kfree(ic->sb_copy); | |
| 5528 | 5578 | ||
| 5529 | 5579 | if (ic->internal_shash) | |
| 5530 | 5580 | crypto_free_shash(ic->internal_shash); | |
modified drivers/md/dm-ioctl.c
| @@ -656,10 +656,16 @@ static void *get_result_buffer(struct dm_ioctl *param, size_t param_size, | |||
| 656 | 656 | { | |
| 657 | 657 | param->data_start = align_ptr(param + 1) - (void *) param; | |
| 658 | 658 | ||
| 659 | - | if (param->data_start < param_size) | |
| 659 | + | if (param->data_start < param_size) { | |
| 660 | 660 | *len = param_size - param->data_start; | |
| 661 | - | else | |
| 661 | + | } else { | |
| 662 | + | /* | |
| 663 | + | * The buffer can be as small as offsetof(*param, data), which | |
| 664 | + | * is less than sizeof(*param), so don't run off the end of it. | |
| 665 | + | */ | |
| 662 | 666 | *len = 0; | |
| 667 | + | param->data_start = param_size; | |
| 668 | + | } | |
| 663 | 669 | ||
| 664 | 670 | return ((void *) param) + param->data_start; | |
| 665 | 671 | } | |
| @@ -1267,6 +1273,7 @@ static int do_resume(struct dm_ioctl *param) | |||
| 1267 | 1273 | /* Do we need to load a new map ? */ | |
| 1268 | 1274 | if (new_map) { | |
| 1269 | 1275 | sector_t old_size, new_size; | |
| 1276 | + | blk_mode_t new_map_mode; | |
| 1270 | 1277 | ||
| 1271 | 1278 | dm_ima_context_table_op(md, ima_context, DM_IMA_TABLE_SAVE); | |
| 1272 | 1279 | /* Suspend if it isn't already suspended */ | |
| @@ -1299,6 +1306,7 @@ static int do_resume(struct dm_ioctl *param) | |||
| 1299 | 1306 | } | |
| 1300 | 1307 | } | |
| 1301 | 1308 | ||
| 1309 | + | new_map_mode = dm_table_get_mode(new_map); | |
| 1302 | 1310 | old_size = dm_get_size(md); | |
| 1303 | 1311 | old_map = dm_swap_table(md, new_map); | |
| 1304 | 1312 | if (IS_ERR(old_map)) { | |
| @@ -1314,7 +1322,7 @@ static int do_resume(struct dm_ioctl *param) | |||
| 1314 | 1322 | if (old_size && new_size && old_size != new_size) | |
| 1315 | 1323 | need_resize_uevent = true; | |
| 1316 | 1324 | ||
| 1317 | - | if (dm_table_get_mode(new_map) & BLK_OPEN_WRITE) | |
| 1325 | + | if (new_map_mode & BLK_OPEN_WRITE) | |
| 1318 | 1326 | set_disk_ro(dm_disk(md), 0); | |
| 1319 | 1327 | else | |
| 1320 | 1328 | set_disk_ro(dm_disk(md), 1); | |
modified drivers/md/dm-snap.c
| @@ -1292,6 +1292,20 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |||
| 1292 | 1292 | goto bad_store; | |
| 1293 | 1293 | } | |
| 1294 | 1294 | ||
| 1295 | + | /* | |
| 1296 | + | * snapshot-merge requires the optional prepare_merge/commit_merge | |
| 1297 | + | * callbacks; the transient exception store does not implement them. | |
| 1298 | + | * The handover path checks this in __validate_exception_handover(), | |
| 1299 | + | * but a directly constructed snapshot-merge never goes through it. | |
| 1300 | + | */ | |
| 1301 | + | if (dm_target_is_snapshot_merge(ti) && | |
| 1302 | + | (!s->store->type->prepare_merge || | |
| 1303 | + | !s->store->type->commit_merge)) { | |
| 1304 | + | ti->error = "Snapshot exception store does not support snapshot-merge."; | |
| 1305 | + | r = -EINVAL; | |
| 1306 | + | goto bad_hash_tables; | |
| 1307 | + | } | |
| 1308 | + | ||
| 1295 | 1309 | argv += args_used; | |
| 1296 | 1310 | argc -= args_used; | |
| 1297 | 1311 | ||
modified drivers/media/usb/em28xx/em28xx-video.c
| @@ -2416,7 +2416,7 @@ static int em28xx_v4l2_fini(struct em28xx *dev) | |||
| 2416 | 2416 | if (video_is_registered(&v4l2->radio_dev)) { | |
| 2417 | 2417 | dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", | |
| 2418 | 2418 | video_device_node_name(&v4l2->radio_dev)); | |
| 2419 | - | vb2_video_unregister_device(&v4l2->radio_dev); | |
| 2419 | + | video_unregister_device(&v4l2->radio_dev); | |
| 2420 | 2420 | } | |
| 2421 | 2421 | if (video_is_registered(&v4l2->vbi_dev)) { | |
| 2422 | 2422 | dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n", | |
| @@ -3082,7 +3082,7 @@ unregister_dev: | |||
| 3082 | 3082 | dev_info(&dev->intf->dev, | |
| 3083 | 3083 | "V4L2 device %s deregistered\n", | |
| 3084 | 3084 | video_device_node_name(&v4l2->radio_dev)); | |
| 3085 | - | vb2_video_unregister_device(&v4l2->radio_dev); | |
| 3085 | + | video_unregister_device(&v4l2->radio_dev); | |
| 3086 | 3086 | } | |
| 3087 | 3087 | if (video_is_registered(&v4l2->vbi_dev)) { | |
| 3088 | 3088 | dev_info(&dev->intf->dev, | |
modified drivers/memstick/core/memstick.c
| @@ -370,9 +370,7 @@ int memstick_set_rw_addr(struct memstick_dev *card) | |||
| 370 | 370 | { | |
| 371 | 371 | card->next_request = h_memstick_set_rw_addr; | |
| 372 | 372 | memstick_new_req(card->host); | |
| 373 | - | if (!wait_for_completion_timeout(&card->mrq_complete, | |
| 374 | - | msecs_to_jiffies(500))) | |
| 375 | - | card->current_mrq.error = -ETIMEDOUT; | |
| 373 | + | wait_for_completion(&card->mrq_complete); | |
| 376 | 374 | ||
| 377 | 375 | return card->current_mrq.error; | |
| 378 | 376 | } | |
| @@ -405,9 +403,7 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host) | |||
| 405 | 403 | ||
| 406 | 404 | card->next_request = h_memstick_read_dev_id; | |
| 407 | 405 | memstick_new_req(host); | |
| 408 | - | if (!wait_for_completion_timeout(&card->mrq_complete, | |
| 409 | - | msecs_to_jiffies(500))) | |
| 410 | - | card->current_mrq.error = -ETIMEDOUT; | |
| 406 | + | wait_for_completion(&card->mrq_complete); | |
| 411 | 407 | ||
| 412 | 408 | if (card->current_mrq.error) | |
| 413 | 409 | goto err_out; | |
modified drivers/memstick/host/rtsx_usb_ms.c
| @@ -27,7 +27,6 @@ struct rtsx_usb_ms { | |||
| 27 | 27 | struct memstick_host *msh; | |
| 28 | 28 | struct memstick_request *req; | |
| 29 | 29 | ||
| 30 | - | struct mutex host_mutex; | |
| 31 | 30 | struct work_struct handle_req; | |
| 32 | 31 | struct delayed_work poll_card; | |
| 33 | 32 | ||
| @@ -514,6 +513,13 @@ static void rtsx_usb_ms_handle_req(struct work_struct *work) | |||
| 514 | 513 | struct memstick_host *msh = host->msh; | |
| 515 | 514 | int rc; | |
| 516 | 515 | ||
| 516 | + | /* Fail requests after eject so their waiters are released. */ | |
| 517 | + | if (host->eject) { | |
| 518 | + | while (!memstick_next_req(msh, &host->req)) | |
| 519 | + | host->req->error = -ENOMEDIUM; | |
| 520 | + | return; | |
| 521 | + | } | |
| 522 | + | ||
| 517 | 523 | if (!host->req) { | |
| 518 | 524 | pm_runtime_get_sync(ms_dev(host)); | |
| 519 | 525 | do { | |
| @@ -547,8 +553,7 @@ static void rtsx_usb_ms_request(struct memstick_host *msh) | |||
| 547 | 553 | ||
| 548 | 554 | dev_dbg(ms_dev(host), "--> %s\n", __func__); | |
| 549 | 555 | ||
| 550 | - | if (!host->eject) | |
| 551 | - | schedule_work(&host->handle_req); | |
| 556 | + | schedule_work(&host->handle_req); | |
| 552 | 557 | } | |
| 553 | 558 | ||
| 554 | 559 | static int rtsx_usb_ms_set_param(struct memstick_host *msh, | |
| @@ -781,7 +786,6 @@ static int rtsx_usb_ms_drv_probe(struct platform_device *pdev) | |||
| 781 | 786 | host->power_mode = MEMSTICK_POWER_OFF; | |
| 782 | 787 | platform_set_drvdata(pdev, host); | |
| 783 | 788 | ||
| 784 | - | mutex_init(&host->host_mutex); | |
| 785 | 789 | INIT_WORK(&host->handle_req, rtsx_usb_ms_handle_req); | |
| 786 | 790 | ||
| 787 | 791 | INIT_DELAYED_WORK(&host->poll_card, rtsx_usb_ms_poll_card); | |
| @@ -812,27 +816,12 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev) | |||
| 812 | 816 | { | |
| 813 | 817 | struct rtsx_usb_ms *host = platform_get_drvdata(pdev); | |
| 814 | 818 | struct memstick_host *msh = host->msh; | |
| 815 | - | int err; | |
| 816 | 819 | ||
| 817 | 820 | host->eject = true; | |
| 818 | 821 | msh->removing = true; | |
| 819 | - | cancel_work_sync(&host->handle_req); | |
| 822 | + | flush_work(&host->handle_req); | |
| 820 | 823 | cancel_delayed_work_sync(&host->poll_card); | |
| 821 | 824 | ||
| 822 | - | mutex_lock(&host->host_mutex); | |
| 823 | - | if (host->req) { | |
| 824 | - | dev_dbg(ms_dev(host), | |
| 825 | - | "%s: Controller removed during transfer\n", | |
| 826 | - | dev_name(&msh->dev)); | |
| 827 | - | host->req->error = -ENOMEDIUM; | |
| 828 | - | do { | |
| 829 | - | err = memstick_next_req(msh, &host->req); | |
| 830 | - | if (!err) | |
| 831 | - | host->req->error = -ENOMEDIUM; | |
| 832 | - | } while (!err); | |
| 833 | - | } | |
| 834 | - | mutex_unlock(&host->host_mutex); | |
| 835 | - | ||
| 836 | 825 | /* Balance possible unbalanced usage count | |
| 837 | 826 | * e.g. unconditional module removal | |
| 838 | 827 | */ | |
| @@ -841,6 +830,8 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev) | |||
| 841 | 830 | ||
| 842 | 831 | pm_runtime_disable(ms_dev(host)); | |
| 843 | 832 | memstick_remove_host(msh); | |
| 833 | + | /* No card, no new requests; wait for the last failed one to finish. */ | |
| 834 | + | cancel_work_sync(&host->handle_req); | |
| 844 | 835 | dev_dbg(ms_dev(host), | |
| 845 | 836 | ": Realtek USB Memstick controller has been removed\n"); | |
| 846 | 837 | memstick_free_host(msh); | |
modified drivers/mmc/host/cavium-octeon.c
| @@ -295,9 +295,12 @@ static void octeon_mmc_remove(struct platform_device *pdev) | |||
| 295 | 295 | u64 dma_cfg; | |
| 296 | 296 | int i; | |
| 297 | 297 | ||
| 298 | - | for (i = 0; i < CAVIUM_MAX_MMC; i++) | |
| 298 | + | for (i = 0; i < CAVIUM_MAX_MMC; i++) { | |
| 299 | 299 | if (host->slot[i]) | |
| 300 | 300 | cvm_mmc_of_slot_remove(host->slot[i]); | |
| 301 | + | if (host->slot_pdev[i]) | |
| 302 | + | of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL); | |
| 303 | + | } | |
| 301 | 304 | ||
| 302 | 305 | dma_cfg = readq(host->dma_base + MIO_EMM_DMA_CFG(host)); | |
| 303 | 306 | dma_cfg &= ~MIO_EMM_DMA_CFG_EN; | |
modified drivers/mmc/host/cavium-thunderx.c
| @@ -173,9 +173,12 @@ static void thunder_mmc_remove(struct pci_dev *pdev) | |||
| 173 | 173 | u64 dma_cfg; | |
| 174 | 174 | int i; | |
| 175 | 175 | ||
| 176 | - | for (i = 0; i < CAVIUM_MAX_MMC; i++) | |
| 176 | + | for (i = 0; i < CAVIUM_MAX_MMC; i++) { | |
| 177 | 177 | if (host->slot[i]) | |
| 178 | 178 | cvm_mmc_of_slot_remove(host->slot[i]); | |
| 179 | + | if (host->slot_pdev[i]) | |
| 180 | + | of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL); | |
| 181 | + | } | |
| 179 | 182 | ||
| 180 | 183 | dma_cfg = readq(host->dma_base + MIO_EMM_DMA_CFG(host)); | |
| 181 | 184 | dma_cfg &= ~MIO_EMM_DMA_CFG_EN; | |
modified drivers/mmc/host/mtk-sd.c
| @@ -3216,6 +3216,7 @@ static void msdc_drv_remove(struct platform_device *pdev) | |||
| 3216 | 3216 | ||
| 3217 | 3217 | platform_set_drvdata(pdev, NULL); | |
| 3218 | 3218 | mmc_remove_host(mmc); | |
| 3219 | + | cancel_delayed_work_sync(&host->req_timeout); | |
| 3219 | 3220 | msdc_deinit_hw(host); | |
| 3220 | 3221 | msdc_gate_clock(host); | |
| 3221 | 3222 | ||
modified drivers/mmc/host/sdhci-sprd.c
| @@ -890,6 +890,10 @@ static void sdhci_sprd_remove(struct platform_device *pdev) | |||
| 890 | 890 | struct sdhci_host *host = platform_get_drvdata(pdev); | |
| 891 | 891 | struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host); | |
| 892 | 892 | ||
| 893 | + | pm_runtime_get_sync(&pdev->dev); | |
| 894 | + | pm_runtime_disable(&pdev->dev); | |
| 895 | + | pm_runtime_put_noidle(&pdev->dev); | |
| 896 | + | ||
| 893 | 897 | sdhci_remove_host(host, 0); | |
| 894 | 898 | ||
| 895 | 899 | clk_disable_unprepare(sprd_host->clk_sdio); | |
modified drivers/net/amt.c
| @@ -80,15 +80,6 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT; | |||
| 80 | 80 | static struct mld2_grec mldv2_zero_grec; | |
| 81 | 81 | #endif | |
| 82 | 82 | ||
| 83 | - | static struct amt_skb_cb *amt_skb_cb(struct sk_buff *skb) | |
| 84 | - | { | |
| 85 | - | BUILD_BUG_ON(sizeof(struct amt_skb_cb) + sizeof(struct tc_skb_cb) > | |
| 86 | - | sizeof_field(struct sk_buff, cb)); | |
| 87 | - | ||
| 88 | - | return (struct amt_skb_cb *)((void *)skb->cb + | |
| 89 | - | sizeof(struct tc_skb_cb)); | |
| 90 | - | } | |
| 91 | - | ||
| 92 | 83 | static void __amt_source_gc_work(void) | |
| 93 | 84 | { | |
| 94 | 85 | struct amt_source_node *snode; | |
| @@ -791,6 +782,11 @@ out: | |||
| 791 | 782 | rcu_read_unlock(); | |
| 792 | 783 | } | |
| 793 | 784 | ||
| 785 | + | static bool amt_send_membership_query(struct amt_dev *amt, | |
| 786 | + | struct sk_buff *skb, | |
| 787 | + | struct amt_tunnel_list *tunnel, | |
| 788 | + | bool v6); | |
| 789 | + | ||
| 794 | 790 | static void amt_send_igmp_gq(struct amt_dev *amt, | |
| 795 | 791 | struct amt_tunnel_list *tunnel) | |
| 796 | 792 | { | |
| @@ -800,8 +796,11 @@ static void amt_send_igmp_gq(struct amt_dev *amt, | |||
| 800 | 796 | if (!skb) | |
| 801 | 797 | return; | |
| 802 | 798 | ||
| 803 | - | amt_skb_cb(skb)->tunnel = tunnel; | |
| 804 | - | dev_queue_xmit(skb); | |
| 799 | + | skb_pull(skb, sizeof(struct ethhdr)); | |
| 800 | + | if (amt_send_membership_query(amt, skb, tunnel, false)) { | |
| 801 | + | amt->dev->stats.tx_dropped++; | |
| 802 | + | kfree_skb(skb); | |
| 803 | + | } | |
| 805 | 804 | } | |
| 806 | 805 | ||
| 807 | 806 | #if IS_ENABLED(CONFIG_IPV6) | |
| @@ -885,8 +884,11 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) | |||
| 885 | 884 | if (!skb) | |
| 886 | 885 | return; | |
| 887 | 886 | ||
| 888 | - | amt_skb_cb(skb)->tunnel = tunnel; | |
| 889 | - | dev_queue_xmit(skb); | |
| 887 | + | skb_pull(skb, sizeof(struct ethhdr)); | |
| 888 | + | if (amt_send_membership_query(amt, skb, tunnel, true)) { | |
| 889 | + | amt->dev->stats.tx_dropped++; | |
| 890 | + | kfree_skb(skb); | |
| 891 | + | } | |
| 890 | 892 | } | |
| 891 | 893 | #else | |
| 892 | 894 | static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) | |
| @@ -1186,7 +1188,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 1186 | 1188 | #endif | |
| 1187 | 1189 | bool report = false; | |
| 1188 | 1190 | struct igmphdr *ih; | |
| 1189 | - | bool query = false; | |
| 1190 | 1191 | struct iphdr *iph; | |
| 1191 | 1192 | bool data = false; | |
| 1192 | 1193 | bool v6 = false; | |
| @@ -1204,9 +1205,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 1204 | 1205 | case IGMP_HOST_MEMBERSHIP_REPORT: | |
| 1205 | 1206 | report = true; | |
| 1206 | 1207 | break; | |
| 1207 | - | case IGMP_HOST_MEMBERSHIP_QUERY: | |
| 1208 | - | query = true; | |
| 1209 | - | break; | |
| 1210 | 1208 | default: | |
| 1211 | 1209 | goto free; | |
| 1212 | 1210 | } | |
| @@ -1228,9 +1226,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 1228 | 1226 | case ICMPV6_MLD2_REPORT: | |
| 1229 | 1227 | report = true; | |
| 1230 | 1228 | break; | |
| 1231 | - | case ICMPV6_MGM_QUERY: | |
| 1232 | - | query = true; | |
| 1233 | - | break; | |
| 1234 | 1229 | default: | |
| 1235 | 1230 | goto free; | |
| 1236 | 1231 | } | |
| @@ -1261,19 +1256,6 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 1261 | 1256 | goto free; | |
| 1262 | 1257 | goto unlock; | |
| 1263 | 1258 | } else if (amt->mode == AMT_MODE_RELAY) { | |
| 1264 | - | if (query) { | |
| 1265 | - | tunnel = amt_skb_cb(skb)->tunnel; | |
| 1266 | - | if (!tunnel) { | |
| 1267 | - | WARN_ON(1); | |
| 1268 | - | goto free; | |
| 1269 | - | } | |
| 1270 | - | ||
| 1271 | - | /* Do not forward unexpected query */ | |
| 1272 | - | if (amt_send_membership_query(amt, skb, tunnel, v6)) | |
| 1273 | - | goto free; | |
| 1274 | - | goto unlock; | |
| 1275 | - | } | |
| 1276 | - | ||
| 1277 | 1259 | if (!data) | |
| 1278 | 1260 | goto free; | |
| 1279 | 1261 | list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) { | |
modified drivers/net/bareudp.c
| @@ -356,7 +356,7 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev, | |||
| 356 | 356 | if (err) | |
| 357 | 357 | goto free_dst; | |
| 358 | 358 | ||
| 359 | - | skb_set_inner_protocol(skb, bareudp->ethertype); | |
| 359 | + | skb_set_inner_protocol(skb, skb->protocol); | |
| 360 | 360 | udp_tunnel_xmit_skb(rt, sk, skb, saddr, info->key.u.ipv4.dst, | |
| 361 | 361 | tos, ttl, df, sport, bareudp->port, | |
| 362 | 362 | !net_eq(bareudp->net, dev_net(bareudp->dev)), | |
| @@ -424,6 +424,7 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev, | |||
| 424 | 424 | if (err) | |
| 425 | 425 | goto free_dst; | |
| 426 | 426 | ||
| 427 | + | skb_set_inner_protocol(skb, skb->protocol); | |
| 427 | 428 | daddr = info->key.u.ipv6.dst; | |
| 428 | 429 | udp_tunnel6_xmit_skb(dst, sk, skb, dev, | |
| 429 | 430 | &saddr, &daddr, prio, ttl, | |
modified drivers/net/bonding/bond_main.c
| @@ -5732,12 +5732,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog, | |||
| 5732 | 5732 | bpf_prog_inc(prog); | |
| 5733 | 5733 | } | |
| 5734 | 5734 | ||
| 5735 | - | if (prog) { | |
| 5735 | + | if (prog && !old_prog) | |
| 5736 | 5736 | static_branch_inc(&bpf_master_redirect_enabled_key); | |
| 5737 | - | } else if (old_prog) { | |
| 5738 | - | bpf_prog_put(old_prog); | |
| 5737 | + | else if (!prog && old_prog) | |
| 5739 | 5738 | static_branch_dec(&bpf_master_redirect_enabled_key); | |
| 5740 | - | } | |
| 5739 | + | if (old_prog) | |
| 5740 | + | bpf_prog_put(old_prog); | |
| 5741 | 5741 | ||
| 5742 | 5742 | return 0; | |
| 5743 | 5743 | ||
modified drivers/net/can/dev/skb.c
| @@ -210,6 +210,10 @@ static void init_can_skb(struct sk_buff *skb) | |||
| 210 | 210 | { | |
| 211 | 211 | skb->pkt_type = PACKET_BROADCAST; | |
| 212 | 212 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
| 213 | + | ||
| 214 | + | skb_reset_mac_header(skb); | |
| 215 | + | skb_reset_network_header(skb); | |
| 216 | + | skb_reset_transport_header(skb); | |
| 213 | 217 | } | |
| 214 | 218 | ||
| 215 | 219 | struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf) | |
modified drivers/net/can/usb/f81604.c
| @@ -169,7 +169,7 @@ struct f81604_int_data { | |||
| 169 | 169 | u8 rxerr; | |
| 170 | 170 | u8 txerr; | |
| 171 | 171 | u8 val; | |
| 172 | - | } __packed __aligned(4); | |
| 172 | + | } __packed; | |
| 173 | 173 | ||
| 174 | 174 | struct f81604_sff { | |
| 175 | 175 | __be16 id; | |
modified drivers/net/can/vxcan.c
| @@ -79,6 +79,9 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *oskb, struct net_device *dev) | |||
| 79 | 79 | ||
| 80 | 80 | /* reset CAN GW hop counter */ | |
| 81 | 81 | csx->can_gw_hops = 0; | |
| 82 | + | /* start with new CAN skb UID in the other namespace */ | |
| 83 | + | csx->can_skb_uid = 0; | |
| 84 | + | ||
| 82 | 85 | skb->pkt_type = PACKET_BROADCAST; | |
| 83 | 86 | skb->dev = peer; | |
| 84 | 87 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
modified drivers/net/dsa/microchip/ksz_common.h
| @@ -853,7 +853,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port) | |||
| 853 | 853 | #define KSZ88_FAMILY_ID 0x88 | |
| 854 | 854 | #define KSZ8895_FAMILY_ID 0x95 | |
| 855 | 855 | ||
| 856 | - | #define KSZ8_PORT_STATUS_0 0x08 | |
| 856 | + | #define KSZ8_PORT_STATUS_0 0x18 | |
| 857 | 857 | #define KSZ8_PORT_FIBER_MODE BIT(7) | |
| 858 | 858 | ||
| 859 | 859 | #define SW_CHIP_ID_M GENMASK(7, 4) | |
modified drivers/net/ethernet/airoha/airoha_eth.c
| @@ -2800,14 +2800,34 @@ static int airoha_qdma_set_trtcm_param(struct airoha_qdma *qdma, int channel, | |||
| 2800 | 2800 | FIELD_PREP(TRTCM_METER_GROUP_MASK, group) | | |
| 2801 | 2801 | FIELD_PREP(TRTCM_PARAM_INDEX_MASK, idx) | | |
| 2802 | 2802 | FIELD_PREP(TRTCM_PARAM_RATE_TYPE_MASK, mode); | |
| 2803 | + | int i; | |
| 2803 | 2804 | ||
| 2804 | - | airoha_qdma_wr(qdma, REG_TRTCM_DATA_LOW(addr), val); | |
| 2805 | - | airoha_qdma_wr(qdma, REG_TRTCM_CFG_PARAM(addr), config); | |
| 2805 | + | /* | |
| 2806 | + | * HW might be in the middle of bucket handling and might | |
| 2807 | + | * require an additional try to actually apply the new TRTCM | |
| 2808 | + | * config. | |
| 2809 | + | */ | |
| 2810 | + | for (i = 0; i < TRTCM_CONFIG_RETRY_MAX; i++) { | |
| 2811 | + | u32 data = 0; | |
| 2806 | 2812 | ||
| 2807 | - | return read_poll_timeout(airoha_qdma_rr, val, | |
| 2808 | - | val & TRTCM_PARAM_RW_DONE_MASK, | |
| 2809 | - | USEC_PER_MSEC, 10 * USEC_PER_MSEC, true, | |
| 2810 | - | qdma, REG_TRTCM_CFG_PARAM(addr)); | |
| 2813 | + | airoha_qdma_wr(qdma, REG_TRTCM_DATA_LOW(addr), val); | |
| 2814 | + | airoha_qdma_wr(qdma, REG_TRTCM_CFG_PARAM(addr), config); | |
| 2815 | + | ||
| 2816 | + | if (read_poll_timeout(airoha_qdma_rr, data, | |
| 2817 | + | data & TRTCM_PARAM_RW_DONE_MASK, | |
| 2818 | + | USEC_PER_MSEC, 10 * USEC_PER_MSEC, | |
| 2819 | + | true, qdma, REG_TRTCM_CFG_PARAM(addr))) | |
| 2820 | + | continue; | |
| 2821 | + | ||
| 2822 | + | if (airoha_qdma_get_trtcm_param(qdma, channel, addr, param, | |
| 2823 | + | mode, &data, NULL)) | |
| 2824 | + | continue; | |
| 2825 | + | ||
| 2826 | + | if (data == val) | |
| 2827 | + | return 0; | |
| 2828 | + | } | |
| 2829 | + | ||
| 2830 | + | return -EBUSY; | |
| 2811 | 2831 | } | |
| 2812 | 2832 | ||
| 2813 | 2833 | static int airoha_qdma_set_trtcm_config(struct airoha_qdma *qdma, int channel, | |
modified drivers/net/ethernet/airoha/airoha_eth.h
| @@ -171,6 +171,8 @@ enum trtcm_param { | |||
| 171 | 171 | #define TRTCM_TOKEN_RATE_MASK GENMASK(23, 6) | |
| 172 | 172 | #define TRTCM_TOKEN_RATE_FRACTION_MASK GENMASK(5, 0) | |
| 173 | 173 | ||
| 174 | + | #define TRTCM_CONFIG_RETRY_MAX 2 | |
| 175 | + | ||
| 174 | 176 | enum airoha_dma_map_type { | |
| 175 | 177 | AIROHA_DMA_UNMAPPED, | |
| 176 | 178 | AIROHA_DMA_MAP_SINGLE, | |
modified drivers/net/ethernet/allwinner/sun4i-emac.c
| @@ -300,7 +300,7 @@ static int emac_dma_inblk_32bit(struct emac_board_info *db, | |||
| 300 | 300 | if (!req) { | |
| 301 | 301 | dev_err(db->dev, "alloc emac dma req error.\n"); | |
| 302 | 302 | ret = -ENOMEM; | |
| 303 | - | goto alloc_req_err; | |
| 303 | + | goto prepare_err; | |
| 304 | 304 | } | |
| 305 | 305 | ||
| 306 | 306 | desc->callback_param = req; | |
| @@ -319,9 +319,6 @@ static int emac_dma_inblk_32bit(struct emac_board_info *db, | |||
| 319 | 319 | submit_err: | |
| 320 | 320 | emac_free_dma_req(req); | |
| 321 | 321 | ||
| 322 | - | alloc_req_err: | |
| 323 | - | dmaengine_desc_free(desc); | |
| 324 | - | ||
| 325 | 322 | prepare_err: | |
| 326 | 323 | dma_unmap_single(db->dev, rxbuf, count, DMA_FROM_DEVICE); | |
| 327 | 324 | return ret; | |
modified drivers/net/ethernet/broadcom/bnxt/bnxt.c
| @@ -486,7 +486,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 486 | 486 | struct netdev_queue *txq; | |
| 487 | 487 | int i; | |
| 488 | 488 | dma_addr_t mapping; | |
| 489 | - | unsigned int length, pad = 0; | |
| 489 | + | unsigned int length; | |
| 490 | 490 | u32 len, free_size, vlan_tag_flags, cfa_action, flags; | |
| 491 | 491 | struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; | |
| 492 | 492 | struct pci_dev *pdev = bp->pdev; | |
| @@ -536,6 +536,16 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 536 | 536 | return rc < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK; | |
| 537 | 537 | } | |
| 538 | 538 | ||
| 539 | + | /* Pad after the SW USO branch: bnxt_sw_udp_gso_xmit() would | |
| 540 | + | * otherwise account the padding as UDP payload. | |
| 541 | + | * Must be done before skb_shinfo(skb)->nr_frags is sampled, | |
| 542 | + | * because skb_put_padto() might linearize the skb. | |
| 543 | + | */ | |
| 544 | + | if (skb_put_padto(skb, BNXT_MIN_PKT_SIZE)) { | |
| 545 | + | /* SKB already freed. */ | |
| 546 | + | goto tx_kick_pending; | |
| 547 | + | } | |
| 548 | + | ||
| 539 | 549 | free_size = bnxt_tx_avail(bp, txr); | |
| 540 | 550 | if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) { | |
| 541 | 551 | /* We must have raced with NAPI cleanup */ | |
| @@ -672,14 +682,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 672 | 682 | } | |
| 673 | 683 | ||
| 674 | 684 | normal_tx: | |
| 675 | - | if (length < BNXT_MIN_PKT_SIZE) { | |
| 676 | - | pad = BNXT_MIN_PKT_SIZE - length; | |
| 677 | - | if (skb_pad(skb, pad)) | |
| 678 | - | /* SKB already freed. */ | |
| 679 | - | goto tx_kick_pending; | |
| 680 | - | length = BNXT_MIN_PKT_SIZE; | |
| 681 | - | } | |
| 682 | - | ||
| 683 | 685 | mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE); | |
| 684 | 686 | ||
| 685 | 687 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) | |
| @@ -759,10 +761,7 @@ normal_tx: | |||
| 759 | 761 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); | |
| 760 | 762 | } | |
| 761 | 763 | ||
| 762 | - | flags &= ~TX_BD_LEN; | |
| 763 | - | txbd->tx_bd_len_flags_type = | |
| 764 | - | cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags | | |
| 765 | - | TX_BD_FLAGS_PACKET_END); | |
| 764 | + | txbd->tx_bd_len_flags_type |= cpu_to_le32(TX_BD_FLAGS_PACKET_END); | |
| 766 | 765 | ||
| 767 | 766 | netdev_tx_sent_queue(txq, skb->len); | |
| 768 | 767 | ||
| @@ -15547,7 +15546,7 @@ static void bnxt_fw_reset_task(struct work_struct *work) | |||
| 15547 | 15546 | if (test_and_clear_bit(BNXT_STATE_FW_ACTIVATE_RESET, &bp->state) && | |
| 15548 | 15547 | !test_bit(BNXT_STATE_FW_ACTIVATE, &bp->state)) | |
| 15549 | 15548 | bnxt_dl_remote_reload(bp); | |
| 15550 | - | if (pci_enable_device(bp->pdev)) { | |
| 15549 | + | if (!pci_is_enabled(bp->pdev) && pci_enable_device(bp->pdev)) { | |
| 15551 | 15550 | netdev_err(bp->dev, "Cannot re-enable PCI device\n"); | |
| 15552 | 15551 | rc = -ENODEV; | |
| 15553 | 15552 | goto fw_reset_abort; | |
| @@ -17111,6 +17110,51 @@ void bnxt_print_device_info(struct bnxt *bp) | |||
| 17111 | 17110 | pcie_print_link_status(bp->pdev); | |
| 17112 | 17111 | } | |
| 17113 | 17112 | ||
| 17113 | + | static void bnxt_clear_bars(struct pci_dev *pdev) | |
| 17114 | + | { | |
| 17115 | + | int off; | |
| 17116 | + | ||
| 17117 | + | for (off = PCI_BASE_ADDRESS_0; off <= PCI_BASE_ADDRESS_5; off += 4) | |
| 17118 | + | pci_write_config_dword(pdev, off, 0); | |
| 17119 | + | } | |
| 17120 | + | ||
| 17121 | + | /* Clear any pending DMA transactions from crash kernel while loading driver in | |
| 17122 | + | * capture kernel. | |
| 17123 | + | */ | |
| 17124 | + | static int bnxt_kdump_reset(struct pci_dev *pdev) | |
| 17125 | + | { | |
| 17126 | + | int rc, i; | |
| 17127 | + | u16 cmd; | |
| 17128 | + | ||
| 17129 | + | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
| 17130 | + | cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); | |
| 17131 | + | pci_write_config_word(pdev, PCI_COMMAND, cmd); | |
| 17132 | + | ||
| 17133 | + | if (pci_save_state(pdev)) | |
| 17134 | + | dev_warn(&pdev->dev, "Failed to save PCI state, PCI restore may be incomplete\n"); | |
| 17135 | + | ||
| 17136 | + | rc = pcie_flr(pdev); | |
| 17137 | + | if (rc) | |
| 17138 | + | dev_warn(&pdev->dev, "pcie_flr() failed (rc: %d), trying to continue\n", | |
| 17139 | + | rc); | |
| 17140 | + | ||
| 17141 | + | /* In case device is not returning CRS, wait 5 seconds longer */ | |
| 17142 | + | for (i = 0; i < 50; i++) { | |
| 17143 | + | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
| 17144 | + | if (!PCI_POSSIBLE_ERROR(cmd)) | |
| 17145 | + | break; | |
| 17146 | + | msleep(100); | |
| 17147 | + | } | |
| 17148 | + | if (PCI_POSSIBLE_ERROR(cmd)) { | |
| 17149 | + | dev_err(&pdev->dev, "PCI config space inaccessible after FLR, aborting\n"); | |
| 17150 | + | return -ENODEV; | |
| 17151 | + | } | |
| 17152 | + | ||
| 17153 | + | bnxt_clear_bars(pdev); | |
| 17154 | + | pci_restore_state(pdev); | |
| 17155 | + | return 0; | |
| 17156 | + | } | |
| 17157 | + | ||
| 17114 | 17158 | static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |
| 17115 | 17159 | { | |
| 17116 | 17160 | struct bnxt_hw_resc *hw_resc; | |
| @@ -17126,12 +17170,10 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
| 17126 | 17170 | return -ENODEV; | |
| 17127 | 17171 | } | |
| 17128 | 17172 | ||
| 17129 | - | /* Clear any pending DMA transactions from crash kernel | |
| 17130 | - | * while loading driver in capture kernel. | |
| 17131 | - | */ | |
| 17132 | 17173 | if (is_kdump_kernel()) { | |
| 17133 | - | pci_clear_master(pdev); | |
| 17134 | - | pcie_flr(pdev); | |
| 17174 | + | rc = bnxt_kdump_reset(pdev); | |
| 17175 | + | if (rc) | |
| 17176 | + | return rc; | |
| 17135 | 17177 | } | |
| 17136 | 17178 | ||
| 17137 | 17179 | max_irqs = bnxt_get_max_irq(pdev); | |
| @@ -17565,10 +17607,8 @@ static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev, | |||
| 17565 | 17607 | * so we disable bus master to prevent any potential bad DMAs before | |
| 17566 | 17608 | * freeing kernel memory. | |
| 17567 | 17609 | */ | |
| 17568 | - | if (state == pci_channel_io_frozen) { | |
| 17569 | - | set_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state); | |
| 17610 | + | if (state == pci_channel_io_frozen) | |
| 17570 | 17611 | bnxt_fw_fatal_close(bp); | |
| 17571 | - | } | |
| 17572 | 17612 | ||
| 17573 | 17613 | if (netif_running(netdev)) | |
| 17574 | 17614 | __bnxt_close_nic(bp, true, true); | |
| @@ -17598,69 +17638,80 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) | |||
| 17598 | 17638 | struct bnxt *bp = netdev_priv(netdev); | |
| 17599 | 17639 | int retry = 0; | |
| 17600 | 17640 | int err = 0; | |
| 17601 | - | int off; | |
| 17641 | + | u16 cmd; | |
| 17602 | 17642 | ||
| 17603 | 17643 | netdev_info(bp->dev, "PCI Slot Reset\n"); | |
| 17604 | 17644 | ||
| 17605 | - | if (test_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state)) { | |
| 17606 | - | /* After DPC, the chip should return CRS when the vendor ID | |
| 17607 | - | * config register is read until it is ready. On all chips, | |
| 17608 | - | * this is not happening reliably so add a 5-second delay as a | |
| 17609 | - | * workaround. | |
| 17610 | - | */ | |
| 17611 | - | msleep(5000); | |
| 17612 | - | } | |
| 17645 | + | /* After a PCIe hot reset, the chip should return CRS when the | |
| 17646 | + | * vendor ID config register is read until it is ready. On all | |
| 17647 | + | * chips, this is not happening reliably so add a 5-second delay | |
| 17648 | + | * as a workaround. | |
| 17649 | + | */ | |
| 17650 | + | msleep(5000); | |
| 17613 | 17651 | ||
| 17614 | 17652 | netdev_lock(netdev); | |
| 17615 | 17653 | ||
| 17616 | - | if (pci_enable_device(pdev)) { | |
| 17654 | + | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
| 17655 | + | if (PCI_POSSIBLE_ERROR(cmd)) { | |
| 17617 | 17656 | dev_err(&pdev->dev, | |
| 17618 | - | "Cannot re-enable PCI device after reset.\n"); | |
| 17619 | - | } else { | |
| 17620 | - | pci_set_master(pdev); | |
| 17621 | - | /* Upon fatal error, our device internal logic that latches to | |
| 17622 | - | * BAR value is getting reset and will restore only upon | |
| 17623 | - | * rewriting the BARs. | |
| 17624 | - | * | |
| 17625 | - | * As pci_restore_state() does not re-write the BARs if the | |
| 17626 | - | * value is same as saved value earlier, driver needs to | |
| 17627 | - | * write the BARs to 0 to force restore, in case of fatal error. | |
| 17628 | - | */ | |
| 17629 | - | if (test_and_clear_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, | |
| 17630 | - | &bp->state)) { | |
| 17631 | - | for (off = PCI_BASE_ADDRESS_0; | |
| 17632 | - | off <= PCI_BASE_ADDRESS_5; off += 4) | |
| 17633 | - | pci_write_config_dword(bp->pdev, off, 0); | |
| 17634 | - | } | |
| 17635 | - | pci_restore_state(pdev); | |
| 17657 | + | "PCI config space inaccessible after reset\n"); | |
| 17658 | + | goto reset_exit; | |
| 17659 | + | } | |
| 17636 | 17660 | ||
| 17637 | - | bnxt_inv_fw_health_reg(bp); | |
| 17638 | - | bnxt_try_map_fw_health_reg(bp); | |
| 17661 | + | /* Upon PCIe error, our device internal logic that latches to | |
| 17662 | + | * BAR value is getting reset and will restore only upon | |
| 17663 | + | * rewriting the BARs. | |
| 17664 | + | * | |
| 17665 | + | * As pci_restore_state() does not re-write the BARs if the | |
| 17666 | + | * value is same as saved value earlier, driver needs to | |
| 17667 | + | * write the BARs to 0 to force restore. | |
| 17668 | + | */ | |
| 17669 | + | pci_clear_master(pdev); | |
| 17670 | + | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
| 17671 | + | cmd &= ~PCI_COMMAND_MEMORY; | |
| 17672 | + | pci_write_config_word(pdev, PCI_COMMAND, cmd); | |
| 17639 | 17673 | ||
| 17640 | - | /* In some PCIe AER scenarios, firmware may take up to | |
| 17641 | - | * 10 seconds to become ready in the worst case. | |
| 17642 | - | */ | |
| 17643 | - | do { | |
| 17644 | - | err = bnxt_try_recover_fw(bp); | |
| 17645 | - | if (!err) | |
| 17646 | - | break; | |
| 17647 | - | retry++; | |
| 17648 | - | } while (retry < BNXT_FW_SLOT_RESET_RETRY); | |
| 17674 | + | bnxt_clear_bars(pdev); | |
| 17675 | + | pci_restore_state(pdev); | |
| 17649 | 17676 | ||
| 17650 | - | if (err) { | |
| 17651 | - | dev_err(&pdev->dev, "Firmware not ready\n"); | |
| 17652 | - | goto reset_exit; | |
| 17677 | + | if (!pci_is_enabled(pdev) && pci_enable_device(pdev)) { | |
| 17678 | + | dev_err(&pdev->dev, | |
| 17679 | + | "Cannot re-enable PCI device after reset.\n"); | |
| 17680 | + | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
| 17681 | + | if (!PCI_POSSIBLE_ERROR(cmd)) { | |
| 17682 | + | cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); | |
| 17683 | + | pci_write_config_word(pdev, PCI_COMMAND, cmd); | |
| 17653 | 17684 | } | |
| 17685 | + | goto reset_exit; | |
| 17686 | + | } | |
| 17687 | + | pci_set_master(pdev); | |
| 17654 | 17688 | ||
| 17655 | - | err = bnxt_hwrm_func_reset(bp); | |
| 17689 | + | bnxt_inv_fw_health_reg(bp); | |
| 17690 | + | bnxt_try_map_fw_health_reg(bp); | |
| 17691 | + | ||
| 17692 | + | /* In some PCIe AER scenarios, firmware may take up to | |
| 17693 | + | * 10 seconds to become ready in the worst case. | |
| 17694 | + | */ | |
| 17695 | + | do { | |
| 17696 | + | err = bnxt_try_recover_fw(bp); | |
| 17656 | 17697 | if (!err) | |
| 17657 | - | result = PCI_ERS_RESULT_RECOVERED; | |
| 17698 | + | break; | |
| 17699 | + | retry++; | |
| 17700 | + | } while (retry < BNXT_FW_SLOT_RESET_RETRY); | |
| 17658 | 17701 | ||
| 17659 | - | /* IRQ will be initialized later in bnxt_io_resume */ | |
| 17660 | - | bnxt_ulp_irq_stop(bp); | |
| 17661 | - | bnxt_clear_int_mode(bp); | |
| 17702 | + | if (err) { | |
| 17703 | + | dev_err(&pdev->dev, "Firmware not ready\n"); | |
| 17704 | + | goto reset_exit; | |
| 17662 | 17705 | } | |
| 17663 | 17706 | ||
| 17707 | + | err = bnxt_hwrm_func_reset(bp); | |
| 17708 | + | if (!err) | |
| 17709 | + | result = PCI_ERS_RESULT_RECOVERED; | |
| 17710 | + | ||
| 17711 | + | /* IRQ will be initialized later in bnxt_io_resume */ | |
| 17712 | + | bnxt_ulp_irq_stop(bp); | |
| 17713 | + | bnxt_clear_int_mode(bp); | |
| 17714 | + | ||
| 17664 | 17715 | reset_exit: | |
| 17665 | 17716 | clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); | |
| 17666 | 17717 | bnxt_clear_reservations(bp, true); | |
modified drivers/net/ethernet/broadcom/bnxt/bnxt.h
| @@ -2468,7 +2468,6 @@ struct bnxt { | |||
| 2468 | 2468 | #define BNXT_STATE_ABORT_ERR 5 | |
| 2469 | 2469 | #define BNXT_STATE_FW_FATAL_COND 6 | |
| 2470 | 2470 | #define BNXT_STATE_DRV_REGISTERED 7 | |
| 2471 | - | #define BNXT_STATE_PCI_CHANNEL_IO_FROZEN 8 | |
| 2472 | 2471 | #define BNXT_STATE_NAPI_DISABLED 9 | |
| 2473 | 2472 | #define BNXT_STATE_FW_ACTIVATE 11 | |
| 2474 | 2473 | #define BNXT_STATE_RECOVER 12 | |
modified drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c
| @@ -253,6 +253,17 @@ int bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv, | |||
| 253 | 253 | reg = bcmgenet_umac_readl(priv, UMAC_CMD); | |
| 254 | 254 | reg &= ~CMD_CRC_FWD; | |
| 255 | 255 | bcmgenet_umac_writel(priv, reg, UMAC_CMD); | |
| 256 | + | ||
| 257 | + | /* | |
| 258 | + | * Mirror wol_power_down_cfg(). If only UMAC_RX | |
| 259 | + | * is enabled, then we must place the UMAC back | |
| 260 | + | * into SW_RESET. | |
| 261 | + | */ | |
| 262 | + | reg = bcmgenet_umac_readl(priv, UMAC_CMD); | |
| 263 | + | if ((reg & CMD_RX_EN) && !(reg & CMD_TX_EN)) { | |
| 264 | + | reg |= CMD_SW_RESET; | |
| 265 | + | bcmgenet_umac_writel(priv, reg, UMAC_CMD); | |
| 266 | + | } | |
| 256 | 267 | spin_unlock_bh(&priv->reg_lock); | |
| 257 | 268 | ||
| 258 | 269 | /* Resume link status tracking */ | |
modified drivers/net/ethernet/cadence/macb_main.c
| @@ -2421,34 +2421,40 @@ static inline int macb_clear_csum(struct sk_buff *skb) | |||
| 2421 | 2421 | return 0; | |
| 2422 | 2422 | } | |
| 2423 | 2423 | ||
| 2424 | + | static bool macb_needs_sw_fcs(struct sk_buff *skb, struct net_device *netdev) | |
| 2425 | + | { | |
| 2426 | + | return netdev->features & NETIF_F_HW_CSUM && | |
| 2427 | + | skb->ip_summed != CHECKSUM_PARTIAL && | |
| 2428 | + | !skb_shinfo(skb)->gso_size && !ptp_one_step_sync(skb); | |
| 2429 | + | } | |
| 2430 | + | ||
| 2424 | 2431 | /* Returns a negative errno, or the FCS bytes appended (0 or ETH_FCS_LEN). */ | |
| 2425 | - | static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *netdev) | |
| 2432 | + | static int macb_pad_and_fcs(struct sk_buff **skb, bool add_fcs) | |
| 2426 | 2433 | { | |
| 2427 | 2434 | bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb) || | |
| 2428 | 2435 | skb_is_nonlinear(*skb); | |
| 2429 | 2436 | int padlen = ETH_ZLEN - (*skb)->len; | |
| 2430 | 2437 | int tailroom = skb_tailroom(*skb); | |
| 2438 | + | bool shared = skb_shared(*skb); | |
| 2431 | 2439 | struct sk_buff *nskb; | |
| 2432 | 2440 | u32 fcs; | |
| 2433 | 2441 | ||
| 2434 | - | if (!(netdev->features & NETIF_F_HW_CSUM) || | |
| 2435 | - | !((*skb)->ip_summed != CHECKSUM_PARTIAL) || | |
| 2436 | - | skb_shinfo(*skb)->gso_size || ptp_one_step_sync(*skb)) | |
| 2442 | + | if (!add_fcs) | |
| 2437 | 2443 | return 0; | |
| 2438 | 2444 | ||
| 2439 | 2445 | if (padlen <= 0) { | |
| 2440 | - | /* FCS could be appeded to tailroom. */ | |
| 2441 | - | if (tailroom >= ETH_FCS_LEN) | |
| 2446 | + | /* FCS could be appended to tailroom. */ | |
| 2447 | + | if (!shared && !skb_is_nonlinear(*skb) && | |
| 2448 | + | tailroom >= ETH_FCS_LEN) | |
| 2442 | 2449 | goto add_fcs; | |
| 2443 | - | /* No room for FCS, need to reallocate skb. */ | |
| 2444 | - | else | |
| 2445 | - | padlen = ETH_FCS_LEN; | |
| 2450 | + | /* Reallocate with room for the FCS. */ | |
| 2451 | + | padlen = ETH_FCS_LEN; | |
| 2446 | 2452 | } else { | |
| 2447 | 2453 | /* Add room for FCS. */ | |
| 2448 | 2454 | padlen += ETH_FCS_LEN; | |
| 2449 | 2455 | } | |
| 2450 | 2456 | ||
| 2451 | - | if (cloned || tailroom < padlen) { | |
| 2457 | + | if (shared || cloned || tailroom < padlen) { | |
| 2452 | 2458 | nskb = skb_copy_expand(*skb, 0, padlen, GFP_ATOMIC); | |
| 2453 | 2459 | if (!nskb) | |
| 2454 | 2460 | return -ENOMEM; | |
| @@ -2481,27 +2487,15 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, | |||
| 2481 | 2487 | unsigned int desc_cnt, nr_frags, frag_size, f; | |
| 2482 | 2488 | struct macb_queue *queue = &bp->queues[q]; | |
| 2483 | 2489 | netdev_tx_t ret = NETDEV_TX_OK; | |
| 2484 | - | unsigned int hdrlen; | |
| 2490 | + | unsigned int hdrlen, tx_len; | |
| 2491 | + | bool add_fcs, is_lso; | |
| 2485 | 2492 | unsigned long flags; | |
| 2486 | 2493 | int fcs_len; | |
| 2487 | - | bool is_lso; | |
| 2488 | - | ||
| 2489 | - | if (macb_clear_csum(skb)) { | |
| 2490 | - | dev_kfree_skb_any(skb); | |
| 2491 | - | return ret; | |
| 2492 | - | } | |
| 2493 | - | ||
| 2494 | - | fcs_len = macb_pad_and_fcs(&skb, netdev); | |
| 2495 | - | if (fcs_len < 0) { | |
| 2496 | - | dev_kfree_skb_any(skb); | |
| 2497 | - | return ret; | |
| 2498 | - | } | |
| 2499 | - | ||
| 2500 | - | if (macb_dma_ptp(bp) && | |
| 2501 | - | (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) | |
| 2502 | - | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | |
| 2503 | 2494 | ||
| 2495 | + | add_fcs = macb_needs_sw_fcs(skb, netdev); | |
| 2504 | 2496 | is_lso = (skb_shinfo(skb)->gso_size != 0); | |
| 2497 | + | tx_len = add_fcs ? max_t(unsigned int, skb->len, ETH_ZLEN) + | |
| 2498 | + | ETH_FCS_LEN : skb->len; | |
| 2505 | 2499 | ||
| 2506 | 2500 | if (is_lso) { | |
| 2507 | 2501 | /* length of headers */ | |
| @@ -2515,8 +2509,11 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, | |||
| 2515 | 2509 | /* if this is required, would need to copy to single buffer */ | |
| 2516 | 2510 | return NETDEV_TX_BUSY; | |
| 2517 | 2511 | } | |
| 2518 | - | } else | |
| 2512 | + | } else if (add_fcs) { | |
| 2513 | + | hdrlen = umin(tx_len, bp->max_tx_length); | |
| 2514 | + | } else { | |
| 2519 | 2515 | hdrlen = umin(skb_headlen(skb), bp->max_tx_length); | |
| 2516 | + | } | |
| 2520 | 2517 | ||
| 2521 | 2518 | #if defined(DEBUG) && defined(VERBOSE_DEBUG) | |
| 2522 | 2519 | netdev_vdbg(bp->netdev, | |
| @@ -2531,12 +2528,18 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, | |||
| 2531 | 2528 | * socket buffer: skb fragments of jumbo frames may need to be | |
| 2532 | 2529 | * split into many buffer descriptors. | |
| 2533 | 2530 | */ | |
| 2534 | - | if (is_lso && (skb_headlen(skb) > hdrlen)) | |
| 2531 | + | if (add_fcs) { | |
| 2532 | + | /* macb_pad_and_fcs() linearizes the skb before adding the FCS. */ | |
| 2533 | + | desc_cnt = DIV_ROUND_UP(tx_len, bp->max_tx_length); | |
| 2534 | + | nr_frags = 0; | |
| 2535 | + | } else if (is_lso && (skb_headlen(skb) > hdrlen)) { | |
| 2535 | 2536 | /* extra header descriptor if also payload in first buffer */ | |
| 2536 | 2537 | desc_cnt = DIV_ROUND_UP((skb_headlen(skb) - hdrlen), bp->max_tx_length) + 1; | |
| 2537 | - | else | |
| 2538 | + | nr_frags = skb_shinfo(skb)->nr_frags; | |
| 2539 | + | } else { | |
| 2538 | 2540 | desc_cnt = DIV_ROUND_UP(skb_headlen(skb), bp->max_tx_length); | |
| 2539 | - | nr_frags = skb_shinfo(skb)->nr_frags; | |
| 2541 | + | nr_frags = skb_shinfo(skb)->nr_frags; | |
| 2542 | + | } | |
| 2540 | 2543 | for (f = 0; f < nr_frags; f++) { | |
| 2541 | 2544 | frag_size = skb_frag_size(&skb_shinfo(skb)->frags[f]); | |
| 2542 | 2545 | desc_cnt += DIV_ROUND_UP(frag_size, bp->max_tx_length); | |
| @@ -2554,6 +2557,21 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, | |||
| 2554 | 2557 | goto unlock; | |
| 2555 | 2558 | } | |
| 2556 | 2559 | ||
| 2560 | + | if (macb_clear_csum(skb)) { | |
| 2561 | + | dev_kfree_skb_any(skb); | |
| 2562 | + | goto unlock; | |
| 2563 | + | } | |
| 2564 | + | ||
| 2565 | + | fcs_len = macb_pad_and_fcs(&skb, add_fcs); | |
| 2566 | + | if (fcs_len < 0) { | |
| 2567 | + | dev_kfree_skb_any(skb); | |
| 2568 | + | goto unlock; | |
| 2569 | + | } | |
| 2570 | + | ||
| 2571 | + | if (macb_dma_ptp(bp) && | |
| 2572 | + | (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) | |
| 2573 | + | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | |
| 2574 | + | ||
| 2557 | 2575 | /* Map socket buffer for DMA transfer */ | |
| 2558 | 2576 | if (macb_tx_map(bp, queue, skb, hdrlen, fcs_len)) { | |
| 2559 | 2577 | dev_kfree_skb_any(skb); | |
modified drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
| @@ -389,7 +389,7 @@ static void chcr_ktls_dev_del(struct net_device *netdev, | |||
| 389 | 389 | cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan, | |
| 390 | 390 | tx_info->tid, tx_info->ip_family); | |
| 391 | 391 | ||
| 392 | - | xa_erase(&u_ctx->tid_list, tx_info->tid); | |
| 392 | + | xa_erase_bh(&u_ctx->tid_list, tx_info->tid); | |
| 393 | 393 | } | |
| 394 | 394 | ||
| 395 | 395 | port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id]; | |
| @@ -577,7 +577,7 @@ free_tid: | |||
| 577 | 577 | cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan, | |
| 578 | 578 | tx_info->tid, tx_info->ip_family); | |
| 579 | 579 | ||
| 580 | - | xa_erase(&u_ctx->tid_list, tx_info->tid); | |
| 580 | + | xa_erase_bh(&u_ctx->tid_list, tx_info->tid); | |
| 581 | 581 | ||
| 582 | 582 | put_module: | |
| 583 | 583 | /* release module refcount */ | |
modified drivers/net/ethernet/google/gve/gve_main.c
| @@ -1708,17 +1708,17 @@ static int gve_xsk_pool_disable(struct net_device *dev, | |||
| 1708 | 1708 | } | |
| 1709 | 1709 | ||
| 1710 | 1710 | napi_rx = &priv->ntfy_blocks[priv->rx[qid].ntfy_id].napi; | |
| 1711 | - | napi_disable(napi_rx); /* make sure current rx poll is done */ | |
| 1711 | + | napi_disable_locked(napi_rx); /* make sure current rx poll is done */ | |
| 1712 | 1712 | ||
| 1713 | 1713 | tx_qid = gve_xdp_tx_queue_id(priv, qid); | |
| 1714 | 1714 | napi_tx = &priv->ntfy_blocks[priv->tx[tx_qid].ntfy_id].napi; | |
| 1715 | - | napi_disable(napi_tx); /* make sure current tx poll is done */ | |
| 1715 | + | napi_disable_locked(napi_tx); /* make sure current tx poll is done */ | |
| 1716 | 1716 | ||
| 1717 | 1717 | gve_unreg_xsk_pool(priv, qid); | |
| 1718 | 1718 | smp_mb(); /* Make sure it is visible to the workers on datapath */ | |
| 1719 | 1719 | ||
| 1720 | - | napi_enable(napi_rx); | |
| 1721 | - | napi_enable(napi_tx); | |
| 1720 | + | napi_enable_locked(napi_rx); | |
| 1721 | + | napi_enable_locked(napi_tx); | |
| 1722 | 1722 | if (gve_is_gqi(priv)) { | |
| 1723 | 1723 | if (gve_rx_work_pending(&priv->rx[qid])) | |
| 1724 | 1724 | napi_schedule(napi_rx); | |
modified drivers/net/ethernet/google/gve/gve_rx_dqo.c
| @@ -113,6 +113,12 @@ static void gve_rx_reset_ring_dqo(struct gve_priv *priv, int idx) | |||
| 113 | 113 | gve_free_to_page_pool(rx, bs, false); | |
| 114 | 114 | else | |
| 115 | 115 | gve_free_qpl_page_dqo(bs); | |
| 116 | + | ||
| 117 | + | if (gve_buf_state_is_allocated(rx, bs) && | |
| 118 | + | bs->xsk_buff) { | |
| 119 | + | xsk_buff_free(bs->xsk_buff); | |
| 120 | + | bs->xsk_buff = NULL; | |
| 121 | + | } | |
| 116 | 122 | } | |
| 117 | 123 | } | |
| 118 | 124 | ||
| @@ -836,7 +842,12 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx, | |||
| 836 | 842 | } | |
| 837 | 843 | ||
| 838 | 844 | if (unlikely(compl_desc->rx_error)) { | |
| 839 | - | gve_free_buffer(rx, buf_state); | |
| 845 | + | if (buf_state->xsk_buff) { | |
| 846 | + | xsk_buff_free(buf_state->xsk_buff); | |
| 847 | + | gve_free_buf_state(rx, buf_state); | |
| 848 | + | } else { | |
| 849 | + | gve_free_buffer(rx, buf_state); | |
| 850 | + | } | |
| 840 | 851 | return -EINVAL; | |
| 841 | 852 | } | |
| 842 | 853 | ||
modified drivers/net/ethernet/ibm/ibmveth.c
| @@ -553,10 +553,15 @@ static int ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter, | |||
| 553 | 553 | ||
| 554 | 554 | static void ibmveth_free_tx_ltb(struct ibmveth_adapter *adapter, int idx) | |
| 555 | 555 | { | |
| 556 | + | void *ptr = adapter->tx_ltb_ptr[idx]; | |
| 557 | + | ||
| 558 | + | if (!ptr) | |
| 559 | + | return; | |
| 560 | + | ||
| 561 | + | adapter->tx_ltb_ptr[idx] = NULL; | |
| 556 | 562 | dma_unmap_single(&adapter->vdev->dev, adapter->tx_ltb_dma[idx], | |
| 557 | 563 | adapter->tx_ltb_size, DMA_TO_DEVICE); | |
| 558 | - | kfree(adapter->tx_ltb_ptr[idx]); | |
| 559 | - | adapter->tx_ltb_ptr[idx] = NULL; | |
| 564 | + | kfree(ptr); | |
| 560 | 565 | } | |
| 561 | 566 | ||
| 562 | 567 | static int ibmveth_allocate_tx_ltb(struct ibmveth_adapter *adapter, int idx) | |
| @@ -667,7 +672,7 @@ static int ibmveth_open(struct net_device *netdev) | |||
| 667 | 672 | ||
| 668 | 673 | for (i = 0; i < netdev->real_num_tx_queues; i++) { | |
| 669 | 674 | if (ibmveth_allocate_tx_ltb(adapter, i)) | |
| 670 | - | goto out_free_tx_ltb; | |
| 675 | + | goto out_unmap_filter_list; | |
| 671 | 676 | } | |
| 672 | 677 | ||
| 673 | 678 | adapter->rx_queue.index = 0; | |
| @@ -718,10 +723,6 @@ static int ibmveth_open(struct net_device *netdev) | |||
| 718 | 723 | if (rc != 0) { | |
| 719 | 724 | netdev_err(netdev, "unable to request irq 0x%x, rc %d\n", | |
| 720 | 725 | netdev->irq, rc); | |
| 721 | - | do { | |
| 722 | - | lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); | |
| 723 | - | } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); | |
| 724 | - | ||
| 725 | 726 | goto out_free_buffer_pools; | |
| 726 | 727 | } | |
| 727 | 728 | ||
| @@ -737,6 +738,9 @@ static int ibmveth_open(struct net_device *netdev) | |||
| 737 | 738 | return 0; | |
| 738 | 739 | ||
| 739 | 740 | out_free_buffer_pools: | |
| 741 | + | do { | |
| 742 | + | lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); | |
| 743 | + | } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); | |
| 740 | 744 | while (--i >= 0) { | |
| 741 | 745 | if (adapter->rx_buff_pool[i].active) | |
| 742 | 746 | ibmveth_free_buffer_pool(adapter, | |
| @@ -746,10 +750,8 @@ out_unmap_filter_list: | |||
| 746 | 750 | dma_unmap_single(dev, adapter->filter_list_dma, 4096, | |
| 747 | 751 | DMA_BIDIRECTIONAL); | |
| 748 | 752 | ||
| 749 | - | out_free_tx_ltb: | |
| 750 | - | while (--i >= 0) { | |
| 753 | + | for (i = netdev->real_num_tx_queues - 1; i >= 0; i--) | |
| 751 | 754 | ibmveth_free_tx_ltb(adapter, i); | |
| 752 | - | } | |
| 753 | 755 | ||
| 754 | 756 | out_unmap_buffer_list: | |
| 755 | 757 | dma_unmap_single(dev, adapter->buffer_list_dma, 4096, | |
modified drivers/net/ethernet/intel/e1000e/netdev.c
| @@ -67,6 +67,13 @@ static const struct dmi_system_id disable_k1_list[] = { | |||
| 67 | 67 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell Pro 16 Plus PB16250"), | |
| 68 | 68 | }, | |
| 69 | 69 | }, | |
| 70 | + | { | |
| 71 | + | .ident = "Lenovo ThinkPad P14s Gen 5", | |
| 72 | + | .matches = { | |
| 73 | + | DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), | |
| 74 | + | DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad P14s Gen 5"), | |
| 75 | + | }, | |
| 76 | + | }, | |
| 70 | 77 | {} | |
| 71 | 78 | }; | |
| 72 | 79 | ||
modified drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
| @@ -4943,6 +4943,20 @@ out: | |||
| 4943 | 4943 | return ret; | |
| 4944 | 4944 | } | |
| 4945 | 4945 | ||
| 4946 | + | /** | |
| 4947 | + | * i40e_setup_vf_trust - Enable/disable VF trust mode without reset | |
| 4948 | + | * @vf: VF to configure | |
| 4949 | + | * @setting: trust setting | |
| 4950 | + | * | |
| 4951 | + | * Update VF flags when changing trust without performing a VF reset. | |
| 4952 | + | * This is only called when it's safe to skip the reset (VF has no advanced | |
| 4953 | + | * features configured that need cleanup). | |
| 4954 | + | */ | |
| 4955 | + | static void i40e_setup_vf_trust(struct i40e_vf *vf, bool setting) | |
| 4956 | + | { | |
| 4957 | + | assign_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps, setting); | |
| 4958 | + | } | |
| 4959 | + | ||
| 4946 | 4960 | /** | |
| 4947 | 4961 | * i40e_ndo_set_vf_trust | |
| 4948 | 4962 | * @netdev: network interface device structure of the pf | |
| @@ -4987,19 +5001,20 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting) | |||
| 4987 | 5001 | set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state); | |
| 4988 | 5002 | pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
| 4989 | 5003 | ||
| 4990 | - | i40e_vc_reset_vf(vf, true); | |
| 5004 | + | /* Reset only if revoking trust and VF has advanced features configured */ | |
| 5005 | + | if (!setting && | |
| 5006 | + | (vf->adq_enabled || vf->num_cloud_filters > 0 || | |
| 5007 | + | test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states) || | |
| 5008 | + | test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))) { | |
| 5009 | + | i40e_vc_reset_vf(vf, true); | |
| 5010 | + | i40e_del_all_cloud_filters(vf); | |
| 5011 | + | } else { | |
| 5012 | + | i40e_setup_vf_trust(vf, setting); | |
| 5013 | + | } | |
| 5014 | + | ||
| 4991 | 5015 | dev_info(&pf->pdev->dev, "VF %u is now %strusted\n", | |
| 4992 | 5016 | vf_id, setting ? "" : "un"); | |
| 4993 | 5017 | ||
| 4994 | - | if (vf->adq_enabled) { | |
| 4995 | - | if (!vf->trusted) { | |
| 4996 | - | dev_info(&pf->pdev->dev, | |
| 4997 | - | "VF %u no longer Trusted, deleting all cloud filters\n", | |
| 4998 | - | vf_id); | |
| 4999 | - | i40e_del_all_cloud_filters(vf); | |
| 5000 | - | } | |
| 5001 | - | } | |
| 5002 | - | ||
| 5003 | 5018 | out: | |
| 5004 | 5019 | clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state); | |
| 5005 | 5020 | return ret; | |
modified drivers/net/ethernet/intel/iavf/iavf.h
| @@ -259,7 +259,6 @@ struct iavf_adapter { | |||
| 259 | 259 | struct work_struct adminq_task; | |
| 260 | 260 | struct work_struct finish_config; | |
| 261 | 261 | wait_queue_head_t down_waitqueue; | |
| 262 | - | wait_queue_head_t vc_waitqueue; | |
| 263 | 262 | struct iavf_q_vector *q_vectors; | |
| 264 | 263 | struct list_head vlan_filter_list; | |
| 265 | 264 | int num_vlan_filters; | |
| @@ -588,8 +587,9 @@ void iavf_configure_queues(struct iavf_adapter *adapter); | |||
| 588 | 587 | void iavf_enable_queues(struct iavf_adapter *adapter); | |
| 589 | 588 | void iavf_disable_queues(struct iavf_adapter *adapter); | |
| 590 | 589 | void iavf_map_queues(struct iavf_adapter *adapter); | |
| 591 | - | void iavf_add_ether_addrs(struct iavf_adapter *adapter); | |
| 590 | + | int iavf_add_ether_addrs(struct iavf_adapter *adapter); | |
| 592 | 591 | void iavf_del_ether_addrs(struct iavf_adapter *adapter); | |
| 592 | + | void iavf_mac_add_reject(struct iavf_adapter *adapter); | |
| 593 | 593 | void iavf_add_vlans(struct iavf_adapter *adapter); | |
| 594 | 594 | void iavf_del_vlans(struct iavf_adapter *adapter); | |
| 595 | 595 | void iavf_set_promiscuous(struct iavf_adapter *adapter); | |
| @@ -606,6 +606,13 @@ void iavf_disable_vlan_stripping(struct iavf_adapter *adapter); | |||
| 606 | 606 | void iavf_virtchnl_completion(struct iavf_adapter *adapter, | |
| 607 | 607 | enum virtchnl_ops v_opcode, | |
| 608 | 608 | enum iavf_status v_retval, u8 *msg, u16 msglen); | |
| 609 | + | int iavf_poll_virtchnl_response(struct iavf_adapter *adapter, | |
| 610 | + | struct iavf_arq_event_info *event, | |
| 611 | + | bool (*condition)(struct iavf_adapter *adapter, | |
| 612 | + | const void *data, | |
| 613 | + | enum virtchnl_ops v_op), | |
| 614 | + | const void *cond_data, | |
| 615 | + | unsigned int timeout_ms); | |
| 609 | 616 | int iavf_config_rss(struct iavf_adapter *adapter); | |
| 610 | 617 | void iavf_cfg_queues_bw(struct iavf_adapter *adapter); | |
| 611 | 618 | void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter); | |
modified drivers/net/ethernet/intel/iavf/iavf_main.c
| @@ -1029,6 +1029,60 @@ static bool iavf_is_mac_set_handled(struct net_device *netdev, | |||
| 1029 | 1029 | return ret; | |
| 1030 | 1030 | } | |
| 1031 | 1031 | ||
| 1032 | + | /** | |
| 1033 | + | * iavf_mac_change_done - Check if MAC change completed | |
| 1034 | + | * @adapter: board private structure | |
| 1035 | + | * @data: MAC address being checked (as const void *) | |
| 1036 | + | * @v_op: virtchnl opcode from processed message | |
| 1037 | + | * | |
| 1038 | + | * Callback for iavf_poll_virtchnl_response() to check if MAC change completed. | |
| 1039 | + | * | |
| 1040 | + | * Return: true if MAC change completed, false otherwise | |
| 1041 | + | */ | |
| 1042 | + | static bool iavf_mac_change_done(struct iavf_adapter *adapter, | |
| 1043 | + | const void *data, enum virtchnl_ops v_op) | |
| 1044 | + | { | |
| 1045 | + | const u8 *addr = data; | |
| 1046 | + | ||
| 1047 | + | return iavf_is_mac_set_handled(adapter->netdev, addr); | |
| 1048 | + | } | |
| 1049 | + | ||
| 1050 | + | /** | |
| 1051 | + | * iavf_set_mac_sync - Synchronously change MAC address | |
| 1052 | + | * @adapter: board private structure | |
| 1053 | + | * @addr: MAC address to set | |
| 1054 | + | * | |
| 1055 | + | * Send MAC change request to PF and poll admin queue for response. | |
| 1056 | + | * Caller must hold netdev_lock. This can sleep for up to 2.5 seconds. | |
| 1057 | + | * Event buffer is allocated before sending to avoid state mismatch if | |
| 1058 | + | * allocation fails after message is sent to PF. | |
| 1059 | + | * | |
| 1060 | + | * Return: 0 on success, negative on failure | |
| 1061 | + | */ | |
| 1062 | + | static int iavf_set_mac_sync(struct iavf_adapter *adapter, const u8 *addr) | |
| 1063 | + | { | |
| 1064 | + | struct iavf_arq_event_info event; | |
| 1065 | + | int ret; | |
| 1066 | + | ||
| 1067 | + | netdev_assert_locked(adapter->netdev); | |
| 1068 | + | ||
| 1069 | + | event.buf_len = IAVF_MAX_AQ_BUF_SIZE; | |
| 1070 | + | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); | |
| 1071 | + | if (!event.msg_buf) | |
| 1072 | + | return -ENOMEM; | |
| 1073 | + | ||
| 1074 | + | ret = iavf_add_ether_addrs(adapter); | |
| 1075 | + | if (ret) | |
| 1076 | + | goto out; | |
| 1077 | + | ||
| 1078 | + | ret = iavf_poll_virtchnl_response(adapter, &event, | |
| 1079 | + | iavf_mac_change_done, addr, 2500); | |
| 1080 | + | ||
| 1081 | + | out: | |
| 1082 | + | kfree(event.msg_buf); | |
| 1083 | + | return ret; | |
| 1084 | + | } | |
| 1085 | + | ||
| 1032 | 1086 | /** | |
| 1033 | 1087 | * iavf_set_mac - NDO callback to set port MAC address | |
| 1034 | 1088 | * @netdev: network interface device structure | |
| @@ -1046,25 +1100,23 @@ static int iavf_set_mac(struct net_device *netdev, void *p) | |||
| 1046 | 1100 | return -EADDRNOTAVAIL; | |
| 1047 | 1101 | ||
| 1048 | 1102 | ret = iavf_replace_primary_mac(adapter, addr->sa_data); | |
| 1049 | - | ||
| 1050 | 1103 | if (ret) | |
| 1051 | 1104 | return ret; | |
| 1052 | 1105 | ||
| 1053 | - | ret = wait_event_interruptible_timeout(adapter->vc_waitqueue, | |
| 1054 | - | iavf_is_mac_set_handled(netdev, addr->sa_data), | |
| 1055 | - | msecs_to_jiffies(2500)); | |
| 1056 | - | ||
| 1057 | - | /* If ret < 0 then it means wait was interrupted. | |
| 1058 | - | * If ret == 0 then it means we got a timeout. | |
| 1059 | - | * else it means we got response for set MAC from PF, | |
| 1060 | - | * check if netdev MAC was updated to requested MAC, | |
| 1061 | - | * if yes then set MAC succeeded otherwise it failed return -EACCES | |
| 1062 | - | */ | |
| 1063 | - | if (ret < 0) | |
| 1106 | + | ret = iavf_set_mac_sync(adapter, addr->sa_data); | |
| 1107 | + | if (ret) { | |
| 1108 | + | /* Rollback only if send failed (message never reached PF). | |
| 1109 | + | * Don't rollback on timeout (-EAGAIN) because the message was | |
| 1110 | + | * sent and PF will eventually respond. When the response arrives, | |
| 1111 | + | * iavf_virtchnl_completion() will handle rollback (on PF error) | |
| 1112 | + | * or acceptance (on PF success) automatically. | |
| 1113 | + | */ | |
| 1114 | + | if (ret != -EAGAIN) { | |
| 1115 | + | iavf_mac_add_reject(adapter); | |
| 1116 | + | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); | |
| 1117 | + | } | |
| 1064 | 1118 | return ret; | |
| 1065 | - | ||
| 1066 | - | if (!ret) | |
| 1067 | - | return -EAGAIN; | |
| 1119 | + | } | |
| 1068 | 1120 | ||
| 1069 | 1121 | if (!ether_addr_equal(netdev->dev_addr, addr->sa_data)) | |
| 1070 | 1122 | return -EACCES; | |
| @@ -5394,9 +5446,6 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
| 5394 | 5446 | /* Setup the wait queue for indicating transition to down status */ | |
| 5395 | 5447 | init_waitqueue_head(&adapter->down_waitqueue); | |
| 5396 | 5448 | ||
| 5397 | - | /* Setup the wait queue for indicating virtchannel events */ | |
| 5398 | - | init_waitqueue_head(&adapter->vc_waitqueue); | |
| 5399 | - | ||
| 5400 | 5449 | INIT_LIST_HEAD(&adapter->ptp.aq_cmds); | |
| 5401 | 5450 | init_waitqueue_head(&adapter->ptp.phc_time_waitqueue); | |
| 5402 | 5451 | mutex_init(&adapter->ptp.aq_cmd_lock); | |
modified drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | /* Copyright(c) 2013 - 2018 Intel Corporation. */ | |
| 3 | 3 | ||
| 4 | 4 | #include <linux/net/intel/libie/rx.h> | |
| 5 | + | #include <net/netdev_lock.h> | |
| 5 | 6 | ||
| 6 | 7 | #include "iavf.h" | |
| 7 | 8 | #include "iavf_ptp.h" | |
| @@ -555,20 +556,23 @@ iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr, | |||
| 555 | 556 | * @adapter: adapter structure | |
| 556 | 557 | * | |
| 557 | 558 | * Request that the PF add one or more addresses to our filters. | |
| 558 | - | **/ | |
| 559 | - | void iavf_add_ether_addrs(struct iavf_adapter *adapter) | |
| 559 | + | * | |
| 560 | + | * Return: 0 on success, negative on failure | |
| 561 | + | */ | |
| 562 | + | int iavf_add_ether_addrs(struct iavf_adapter *adapter) | |
| 560 | 563 | { | |
| 561 | 564 | struct virtchnl_ether_addr_list *veal; | |
| 562 | 565 | struct iavf_mac_filter *f; | |
| 563 | 566 | int i = 0, count = 0; | |
| 564 | 567 | bool more = false; | |
| 565 | 568 | size_t len; | |
| 569 | + | int ret; | |
| 566 | 570 | ||
| 567 | 571 | if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { | |
| 568 | 572 | /* bail because we already have a command pending */ | |
| 569 | 573 | dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n", | |
| 570 | 574 | adapter->current_op); | |
| 571 | - | return; | |
| 575 | + | return -EBUSY; | |
| 572 | 576 | } | |
| 573 | 577 | ||
| 574 | 578 | spin_lock_bh(&adapter->mac_vlan_list_lock); | |
| @@ -580,7 +584,7 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter) | |||
| 580 | 584 | if (!count) { | |
| 581 | 585 | adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER; | |
| 582 | 586 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
| 583 | - | return; | |
| 587 | + | return 0; | |
| 584 | 588 | } | |
| 585 | 589 | adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR; | |
| 586 | 590 | ||
| @@ -594,8 +598,9 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter) | |||
| 594 | 598 | ||
| 595 | 599 | veal = kzalloc(len, GFP_ATOMIC); | |
| 596 | 600 | if (!veal) { | |
| 601 | + | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
| 597 | 602 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
| 598 | - | return; | |
| 603 | + | return -ENOMEM; | |
| 599 | 604 | } | |
| 600 | 605 | ||
| 601 | 606 | veal->vsi_id = adapter->vsi_res->vsi_id; | |
| @@ -615,8 +620,15 @@ void iavf_add_ether_addrs(struct iavf_adapter *adapter) | |||
| 615 | 620 | ||
| 616 | 621 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
| 617 | 622 | ||
| 618 | - | iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len); | |
| 623 | + | ret = iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len); | |
| 619 | 624 | kfree(veal); | |
| 625 | + | if (ret) { | |
| 626 | + | dev_err(&adapter->pdev->dev, | |
| 627 | + | "Unable to send ADD_ETH_ADDR message to PF, error %d\n", ret); | |
| 628 | + | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
| 629 | + | } | |
| 630 | + | ||
| 631 | + | return ret; | |
| 620 | 632 | } | |
| 621 | 633 | ||
| 622 | 634 | /** | |
| @@ -712,8 +724,8 @@ static void iavf_mac_add_ok(struct iavf_adapter *adapter) | |||
| 712 | 724 | * @adapter: adapter structure | |
| 713 | 725 | * | |
| 714 | 726 | * Remove filters from list based on PF response. | |
| 715 | - | **/ | |
| 716 | - | static void iavf_mac_add_reject(struct iavf_adapter *adapter) | |
| 727 | + | */ | |
| 728 | + | void iavf_mac_add_reject(struct iavf_adapter *adapter) | |
| 717 | 729 | { | |
| 718 | 730 | struct net_device *netdev = adapter->netdev; | |
| 719 | 731 | struct iavf_mac_filter *f, *ftmp; | |
| @@ -2364,7 +2376,6 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, | |||
| 2364 | 2376 | iavf_mac_add_reject(adapter); | |
| 2365 | 2377 | /* restore administratively set MAC address */ | |
| 2366 | 2378 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); | |
| 2367 | - | wake_up(&adapter->vc_waitqueue); | |
| 2368 | 2379 | break; | |
| 2369 | 2380 | case VIRTCHNL_OP_DEL_ETH_ADDR: | |
| 2370 | 2381 | dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n", | |
| @@ -2555,7 +2566,6 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, | |||
| 2555 | 2566 | eth_hw_addr_set(netdev, adapter->hw.mac.addr); | |
| 2556 | 2567 | netif_addr_unlock_bh(netdev); | |
| 2557 | 2568 | } | |
| 2558 | - | wake_up(&adapter->vc_waitqueue); | |
| 2559 | 2569 | break; | |
| 2560 | 2570 | case VIRTCHNL_OP_GET_STATS: { | |
| 2561 | 2571 | struct iavf_eth_stats *stats = | |
| @@ -2950,3 +2960,72 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, | |||
| 2950 | 2960 | } /* switch v_opcode */ | |
| 2951 | 2961 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
| 2952 | 2962 | } | |
| 2963 | + | ||
| 2964 | + | /** | |
| 2965 | + | * iavf_poll_virtchnl_response - Poll admin queue for virtchnl response | |
| 2966 | + | * @adapter: adapter structure | |
| 2967 | + | * @event: pre-allocated event buffer to use for polling | |
| 2968 | + | * @condition: callback to check if desired response received | |
| 2969 | + | * @cond_data: context data passed to condition callback | |
| 2970 | + | * @timeout_ms: maximum time to wait in milliseconds | |
| 2971 | + | * | |
| 2972 | + | * Polls the admin queue and processes all incoming virtchnl messages. | |
| 2973 | + | * After processing each valid message, calls the condition callback to check | |
| 2974 | + | * if the expected response has been received. The callback receives the opcode | |
| 2975 | + | * of the processed message to identify which response was received. Continues | |
| 2976 | + | * polling until the callback returns true or timeout expires. | |
| 2977 | + | * | |
| 2978 | + | * Caller must allocate event buffer before sending any messages to PF to avoid | |
| 2979 | + | * state mismatch if allocation fails after message is sent. | |
| 2980 | + | * | |
| 2981 | + | * Caller must hold netdev_lock. This can sleep for up to timeout_ms while | |
| 2982 | + | * polling hardware. | |
| 2983 | + | * | |
| 2984 | + | * Return: 0 on success (condition met), -EAGAIN on timeout, or error code | |
| 2985 | + | */ | |
| 2986 | + | int iavf_poll_virtchnl_response(struct iavf_adapter *adapter, | |
| 2987 | + | struct iavf_arq_event_info *event, | |
| 2988 | + | bool (*condition)(struct iavf_adapter *adapter, | |
| 2989 | + | const void *data, | |
| 2990 | + | enum virtchnl_ops v_op), | |
| 2991 | + | const void *cond_data, | |
| 2992 | + | unsigned int timeout_ms) | |
| 2993 | + | { | |
| 2994 | + | struct iavf_hw *hw = &adapter->hw; | |
| 2995 | + | enum virtchnl_ops received_op; | |
| 2996 | + | unsigned long timeout; | |
| 2997 | + | int ret = -EAGAIN; | |
| 2998 | + | u16 pending = 0; | |
| 2999 | + | u32 v_retval; | |
| 3000 | + | ||
| 3001 | + | netdev_assert_locked(adapter->netdev); | |
| 3002 | + | ||
| 3003 | + | timeout = jiffies + msecs_to_jiffies(timeout_ms); | |
| 3004 | + | do { | |
| 3005 | + | if (!pending) | |
| 3006 | + | usleep_range(50, 75); | |
| 3007 | + | ||
| 3008 | + | if (iavf_clean_arq_element(hw, event, &pending) == IAVF_SUCCESS) { | |
| 3009 | + | received_op = (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high); | |
| 3010 | + | if (received_op != VIRTCHNL_OP_UNKNOWN) { | |
| 3011 | + | v_retval = le32_to_cpu(event->desc.cookie_low); | |
| 3012 | + | ||
| 3013 | + | iavf_virtchnl_completion(adapter, received_op, | |
| 3014 | + | (enum iavf_status)v_retval, | |
| 3015 | + | event->msg_buf, event->msg_len); | |
| 3016 | + | ||
| 3017 | + | if (condition(adapter, cond_data, received_op)) { | |
| 3018 | + | ret = 0; | |
| 3019 | + | break; | |
| 3020 | + | } | |
| 3021 | + | } | |
| 3022 | + | ||
| 3023 | + | memset(event->msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE); | |
| 3024 | + | ||
| 3025 | + | if (pending) | |
| 3026 | + | continue; | |
| 3027 | + | } | |
| 3028 | + | } while (time_before(jiffies, timeout)); | |
| 3029 | + | ||
| 3030 | + | return ret; | |
| 3031 | + | } | |
modified drivers/net/ethernet/intel/ice/devlink/port.c
| @@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port) | |||
| 590 | 590 | ||
| 591 | 591 | xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf); | |
| 592 | 592 | ice_eswitch_detach_sf(pf, dyn_port); | |
| 593 | - | ice_vsi_free(dyn_port->vsi); | |
| 594 | 593 | xa_erase(&pf->dyn_ports, dyn_port->vsi->idx); | |
| 594 | + | ice_vsi_free(dyn_port->vsi); | |
| 595 | 595 | kfree(dyn_port); | |
| 596 | 596 | } | |
| 597 | 597 | ||
modified drivers/net/ethernet/intel/ice/ice_eswitch.c
| @@ -95,7 +95,7 @@ ice_eswitch_release_repr(struct ice_pf *pf, struct ice_repr *repr) | |||
| 95 | 95 | return; | |
| 96 | 96 | ||
| 97 | 97 | ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof); | |
| 98 | - | metadata_dst_free(repr->dst); | |
| 98 | + | dst_release(&repr->dst->dst); | |
| 99 | 99 | repr->dst = NULL; | |
| 100 | 100 | ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac, | |
| 101 | 101 | ICE_FWD_TO_VSI); | |
modified drivers/net/ethernet/intel/ice/ice_sriov.c
| @@ -1366,6 +1366,20 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) | |||
| 1366 | 1366 | return __ice_set_vf_mac(ice_netdev_to_pf(netdev), vf_id, mac); | |
| 1367 | 1367 | } | |
| 1368 | 1368 | ||
| 1369 | + | /** | |
| 1370 | + | * ice_setup_vf_trust - Enable/disable VF trust mode without reset | |
| 1371 | + | * @vf: VF to configure | |
| 1372 | + | * @setting: trust setting | |
| 1373 | + | * | |
| 1374 | + | * Update VF flags when changing trust without performing a VF reset. | |
| 1375 | + | * This is only called when it's safe to skip the reset (VF has no advanced | |
| 1376 | + | * features configured that need cleanup). | |
| 1377 | + | */ | |
| 1378 | + | static void ice_setup_vf_trust(struct ice_vf *vf, bool setting) | |
| 1379 | + | { | |
| 1380 | + | assign_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps, setting); | |
| 1381 | + | } | |
| 1382 | + | ||
| 1369 | 1383 | /** | |
| 1370 | 1384 | * ice_set_vf_trust | |
| 1371 | 1385 | * @netdev: network interface device structure | |
| @@ -1401,11 +1415,19 @@ int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted) | |||
| 1401 | 1415 | ||
| 1402 | 1416 | mutex_lock(&vf->cfg_lock); | |
| 1403 | 1417 | ||
| 1404 | - | while (!trusted && vf->num_mac_lldp) | |
| 1405 | - | ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false); | |
| 1406 | - | ||
| 1407 | - | vf->trusted = trusted; | |
| 1408 | - | ice_reset_vf(vf, ICE_VF_RESET_NOTIFY); | |
| 1418 | + | /* Reset only if revoking trust and VF has advanced features configured */ | |
| 1419 | + | if (!trusted && | |
| 1420 | + | (vf->num_mac_lldp > 0 || | |
| 1421 | + | test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) || | |
| 1422 | + | test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))) { | |
| 1423 | + | while (vf->num_mac_lldp) | |
| 1424 | + | ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false); | |
| 1425 | + | vf->trusted = trusted; | |
| 1426 | + | ice_reset_vf(vf, ICE_VF_RESET_NOTIFY); | |
| 1427 | + | } else { | |
| 1428 | + | vf->trusted = trusted; | |
| 1429 | + | ice_setup_vf_trust(vf, trusted); | |
| 1430 | + | } | |
| 1409 | 1431 | dev_info(ice_pf_to_dev(pf), "VF %u is now %strusted\n", | |
| 1410 | 1432 | vf_id, trusted ? "" : "un"); | |
| 1411 | 1433 | ||
modified drivers/net/ethernet/intel/ice/ice_txrx.c
| @@ -1561,10 +1561,10 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct ice_tx_buf *first, | |||
| 1561 | 1561 | } | |
| 1562 | 1562 | } | |
| 1563 | 1563 | tstamp_ring->next_to_use = j; | |
| 1564 | - | writel_relaxed(j, tstamp_ring->tail); | |
| 1564 | + | writel(j, tstamp_ring->tail); | |
| 1565 | 1565 | } else { | |
| 1566 | 1566 | ring_kick: | |
| 1567 | - | writel_relaxed(i, tx_ring->tail); | |
| 1567 | + | writel(i, tx_ring->tail); | |
| 1568 | 1568 | } | |
| 1569 | 1569 | return; | |
| 1570 | 1570 | ||
modified drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
| @@ -908,10 +908,12 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) | |||
| 908 | 908 | } while (!last_wqe); | |
| 909 | 909 | } while ((++i < MLX5E_TX_CQ_POLL_BUDGET) && (cqe = mlx5_cqwq_get_cqe(&cq->wq))); | |
| 910 | 910 | ||
| 911 | - | sq->cc = sqcc; | |
| 912 | - | ||
| 913 | 911 | mlx5_cqwq_update_db_record(&cq->wq); | |
| 914 | 912 | ||
| 913 | + | /* ensure cq space is freed before enabling more cqes */ | |
| 914 | + | dma_wmb(); | |
| 915 | + | ||
| 916 | + | sq->cc = sqcc; | |
| 915 | 917 | return i; | |
| 916 | 918 | } | |
| 917 | 919 | ||
modified drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
| @@ -11,26 +11,6 @@ int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport, | |||
| 11 | 11 | ||
| 12 | 12 | lockdep_assert_held(&dev->priv.eswitch->state_lock); | |
| 13 | 13 | ||
| 14 | - | if (MLX5_CAP_ESW(dev, esw_vport_state_max_tx_speed)) { | |
| 15 | - | u8 op_mod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT; | |
| 16 | - | struct mlx5_vport *esw_vport; | |
| 17 | - | u32 speed = 0; | |
| 18 | - | int err; | |
| 19 | - | ||
| 20 | - | err = mlx5_query_vport_max_tx_speed(dev, op_mod, vport, | |
| 21 | - | true, &speed, NULL); | |
| 22 | - | if (err) { | |
| 23 | - | esw_vport = mlx5_eswitch_get_vport(dev->priv.eswitch, | |
| 24 | - | vport); | |
| 25 | - | speed = IS_ERR(esw_vport) ? 0 : | |
| 26 | - | esw_vport->agg_max_tx_speed; | |
| 27 | - | mlx5_core_dbg(dev, | |
| 28 | - | "Failed to query vport %d max tx speed, err=%d, using cached %u\n", | |
| 29 | - | vport, err, speed); | |
| 30 | - | } | |
| 31 | - | MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed); | |
| 32 | - | } | |
| 33 | - | ||
| 34 | 14 | MLX5_SET(modify_vport_state_in, in, opcode, | |
| 35 | 15 | MLX5_CMD_OP_MODIFY_VPORT_STATE); | |
| 36 | 16 | MLX5_SET(modify_vport_state_in, in, op_mod, | |
modified drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
| @@ -1432,30 +1432,40 @@ static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond) | |||
| 1432 | 1432 | } | |
| 1433 | 1433 | ||
| 1434 | 1434 | #ifdef CONFIG_MLX5_ESWITCH | |
| 1435 | - | static int | |
| 1436 | - | mlx5_lag_sum_devices_speed(struct mlx5_lag *ldev, u32 *sum_speed, | |
| 1437 | - | int (*get_speed)(struct mlx5_core_dev *, u32 *)) | |
| 1435 | + | static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, | |
| 1436 | + | u32 *sum_speed) | |
| 1438 | 1437 | { | |
| 1439 | - | struct mlx5_core_dev *pf_mdev; | |
| 1440 | - | struct lag_func *pf; | |
| 1441 | 1438 | int pf_idx; | |
| 1442 | - | u32 speed; | |
| 1443 | - | int ret; | |
| 1444 | 1439 | ||
| 1445 | 1440 | *sum_speed = 0; | |
| 1446 | 1441 | mlx5_ldev_for_each(pf_idx, 0, ldev) { | |
| 1442 | + | u8 opmod = MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT; | |
| 1443 | + | struct mlx5_core_dev *pf_mdev; | |
| 1444 | + | struct lag_func *pf; | |
| 1445 | + | u32 speed; | |
| 1446 | + | u8 state; | |
| 1447 | + | int ret; | |
| 1448 | + | ||
| 1447 | 1449 | pf = mlx5_lag_pf(ldev, pf_idx); | |
| 1448 | 1450 | if (!pf) | |
| 1449 | 1451 | continue; | |
| 1450 | 1452 | pf_mdev = pf->dev; | |
| 1451 | 1453 | if (!pf_mdev) | |
| 1452 | 1454 | continue; | |
| 1455 | + | ret = mlx5_query_vport_max_tx_speed(pf_mdev, opmod, 0, 0, | |
| 1456 | + | &speed, &state); | |
| 1457 | + | if (ret) { | |
| 1458 | + | mlx5_core_dbg(pf_mdev, "State query failed (err=%d)\n", | |
| 1459 | + | ret); | |
| 1460 | + | return ret; | |
| 1461 | + | } | |
| 1462 | + | if (state != VPORT_STATE_UP) | |
| 1463 | + | continue; | |
| 1453 | 1464 | ||
| 1454 | - | ret = get_speed(pf_mdev, &speed); | |
| 1465 | + | ret = mlx5_port_oper_linkspeed(pf_mdev, &speed); | |
| 1455 | 1466 | if (ret) { | |
| 1456 | 1467 | mlx5_core_dbg(pf_mdev, | |
| 1457 | - | "Failed to get device speed using %ps. Device %s speed is not available (err=%d)\n", | |
| 1458 | - | get_speed, dev_name(pf_mdev->device), | |
| 1468 | + | "Failed to get oper speed (err=%d)\n", | |
| 1459 | 1469 | ret); | |
| 1460 | 1470 | return ret; | |
| 1461 | 1471 | } | |
| @@ -1466,17 +1476,42 @@ mlx5_lag_sum_devices_speed(struct mlx5_lag *ldev, u32 *sum_speed, | |||
| 1466 | 1476 | return 0; | |
| 1467 | 1477 | } | |
| 1468 | 1478 | ||
| 1469 | - | static int mlx5_lag_sum_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed) | |
| 1479 | + | static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed) | |
| 1470 | 1480 | { | |
| 1471 | - | return mlx5_lag_sum_devices_speed(ldev, max_speed, | |
| 1472 | - | mlx5_port_max_linkspeed); | |
| 1473 | - | } | |
| 1481 | + | bool take_max; | |
| 1482 | + | int pf_idx; | |
| 1474 | 1483 | ||
| 1475 | - | static int mlx5_lag_sum_devices_oper_speed(struct mlx5_lag *ldev, | |
| 1476 | - | u32 *oper_speed) | |
| 1477 | - | { | |
| 1478 | - | return mlx5_lag_sum_devices_speed(ldev, oper_speed, | |
| 1479 | - | mlx5_port_oper_linkspeed); | |
| 1484 | + | take_max = ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP; | |
| 1485 | + | if (ldev->mode == MLX5_LAG_MODE_MPESW) | |
| 1486 | + | take_max = false; | |
| 1487 | + | ||
| 1488 | + | *max_speed = 0; | |
| 1489 | + | mlx5_ldev_for_each(pf_idx, 0, ldev) { | |
| 1490 | + | struct mlx5_core_dev *pf_mdev; | |
| 1491 | + | struct lag_func *pf; | |
| 1492 | + | u32 speed; | |
| 1493 | + | int ret; | |
| 1494 | + | ||
| 1495 | + | pf = mlx5_lag_pf(ldev, pf_idx); | |
| 1496 | + | if (!pf) | |
| 1497 | + | continue; | |
| 1498 | + | pf_mdev = pf->dev; | |
| 1499 | + | if (!pf_mdev) | |
| 1500 | + | continue; | |
| 1501 | + | ||
| 1502 | + | ret = mlx5_port_max_linkspeed(pf_mdev, &speed); | |
| 1503 | + | if (ret) { | |
| 1504 | + | mlx5_core_dbg(pf_mdev, | |
| 1505 | + | "Failed to get max speed (err=%d)\n", | |
| 1506 | + | ret); | |
| 1507 | + | return ret; | |
| 1508 | + | } | |
| 1509 | + | ||
| 1510 | + | *max_speed = take_max ? | |
| 1511 | + | max(*max_speed, speed) : *max_speed + speed; | |
| 1512 | + | } | |
| 1513 | + | ||
| 1514 | + | return 0; | |
| 1480 | 1515 | } | |
| 1481 | 1516 | ||
| 1482 | 1517 | static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev, | |
| @@ -1525,7 +1560,7 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) | |||
| 1525 | 1560 | int pf_idx; | |
| 1526 | 1561 | ||
| 1527 | 1562 | if (ldev->mode == MLX5_LAG_MODE_MPESW) { | |
| 1528 | - | if (mlx5_lag_sum_devices_oper_speed(ldev, &speed)) | |
| 1563 | + | if (mlx5_lag_get_devices_oper_speed(ldev, &speed)) | |
| 1529 | 1564 | return; | |
| 1530 | 1565 | } else { | |
| 1531 | 1566 | speed = ldev->tracker.bond_speed_mbps; | |
| @@ -1533,8 +1568,8 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) | |||
| 1533 | 1568 | return; | |
| 1534 | 1569 | } | |
| 1535 | 1570 | ||
| 1536 | - | /* If speed is not set, use the sum of max speeds of all PFs */ | |
| 1537 | - | if (!speed && mlx5_lag_sum_devices_max_speed(ldev, &speed)) | |
| 1571 | + | /* If speed is not set, fall back to the max achievable speed */ | |
| 1572 | + | if (!speed && mlx5_lag_get_devices_max_speed(ldev, &speed)) | |
| 1538 | 1573 | return; | |
| 1539 | 1574 | ||
| 1540 | 1575 | speed = speed / MLX5_MAX_TX_SPEED_UNIT; | |
modified drivers/net/ethernet/mellanox/mlx5/core/vport.c
| @@ -93,30 +93,6 @@ int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, | |||
| 93 | 93 | lockdep_assert_held(&mdev->priv.eswitch->state_lock); | |
| 94 | 94 | #endif | |
| 95 | 95 | ||
| 96 | - | if (MLX5_CAP_ESW(mdev, esw_vport_state_max_tx_speed) && | |
| 97 | - | opmod == MLX5_VPORT_STATE_OP_MOD_ESW_VPORT && | |
| 98 | - | vport != MLX5_VPORT_UPLINK) { | |
| 99 | - | u32 speed = 0; | |
| 100 | - | int err; | |
| 101 | - | ||
| 102 | - | err = mlx5_query_vport_max_tx_speed(mdev, opmod, vport, | |
| 103 | - | other_vport, &speed, NULL); | |
| 104 | - | if (err) { | |
| 105 | - | #ifdef CONFIG_MLX5_ESWITCH | |
| 106 | - | struct mlx5_vport *esw_vport; | |
| 107 | - | ||
| 108 | - | esw_vport = mlx5_eswitch_get_vport(mdev->priv.eswitch, | |
| 109 | - | vport); | |
| 110 | - | speed = IS_ERR(esw_vport) ? 0 : | |
| 111 | - | esw_vport->agg_max_tx_speed; | |
| 112 | - | #endif | |
| 113 | - | mlx5_core_dbg(mdev, | |
| 114 | - | "Failed to query vport %d max tx speed, err=%d, using cached %u\n", | |
| 115 | - | vport, err, speed); | |
| 116 | - | } | |
| 117 | - | MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed); | |
| 118 | - | } | |
| 119 | - | ||
| 120 | 96 | MLX5_SET(modify_vport_state_in, in, opcode, | |
| 121 | 97 | MLX5_CMD_OP_MODIFY_VPORT_STATE); | |
| 122 | 98 | MLX5_SET(modify_vport_state_in, in, op_mod, opmod); | |
modified drivers/net/ethernet/mellanox/mlxsw/spectrum.h
| @@ -989,6 +989,8 @@ void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset, | |||
| 989 | 989 | struct mlxsw_sp_acl_rule_info * | |
| 990 | 990 | mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl, | |
| 991 | 991 | struct mlxsw_afa_block *afa_block); | |
| 992 | + | void mlxsw_sp_acl_rulei_free(struct mlxsw_sp *mlxsw_sp, | |
| 993 | + | const struct mlxsw_sp_acl_rule_info *rulei); | |
| 992 | 994 | void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp, | |
| 993 | 995 | struct mlxsw_sp_acl_rule_info *rulei); | |
| 994 | 996 | int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei); | |
modified drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
| @@ -340,8 +340,8 @@ err_afa_block_create: | |||
| 340 | 340 | return ERR_PTR(err); | |
| 341 | 341 | } | |
| 342 | 342 | ||
| 343 | - | void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp, | |
| 344 | - | struct mlxsw_sp_acl_rule_info *rulei) | |
| 343 | + | void mlxsw_sp_acl_rulei_free(struct mlxsw_sp *mlxsw_sp, | |
| 344 | + | const struct mlxsw_sp_acl_rule_info *rulei) | |
| 345 | 345 | { | |
| 346 | 346 | if (rulei->action_created) | |
| 347 | 347 | mlxsw_afa_block_destroy(rulei->act_block); | |
| @@ -351,6 +351,12 @@ void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp, | |||
| 351 | 351 | if (rulei->dst_port_range_reg_valid) | |
| 352 | 352 | mlxsw_sp_port_range_reg_put(mlxsw_sp, | |
| 353 | 353 | rulei->dst_port_range_reg_index); | |
| 354 | + | } | |
| 355 | + | ||
| 356 | + | void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp, | |
| 357 | + | struct mlxsw_sp_acl_rule_info *rulei) | |
| 358 | + | { | |
| 359 | + | mlxsw_sp_acl_rulei_free(mlxsw_sp, rulei); | |
| 354 | 360 | kfree(rulei); | |
| 355 | 361 | } | |
| 356 | 362 | ||
modified drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
| @@ -862,14 +862,19 @@ int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp, | |||
| 862 | 862 | memset(&rulei, 0, sizeof(rulei)); | |
| 863 | 863 | err = mlxsw_sp_flower_parse(mlxsw_sp, block, &rulei, f); | |
| 864 | 864 | if (err) | |
| 865 | - | return err; | |
| 865 | + | goto out; | |
| 866 | + | ||
| 866 | 867 | ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block, | |
| 867 | 868 | f->common.chain_index, | |
| 868 | 869 | MLXSW_SP_ACL_PROFILE_FLOWER, | |
| 869 | 870 | &rulei.values.elusage); | |
| 871 | + | err = PTR_ERR_OR_ZERO(ruleset); | |
| 872 | + | ||
| 873 | + | out: | |
| 874 | + | mlxsw_sp_acl_rulei_free(mlxsw_sp, &rulei); | |
| 870 | 875 | ||
| 871 | 876 | /* keep the reference to the ruleset */ | |
| 872 | - | return PTR_ERR_OR_ZERO(ruleset); | |
| 877 | + | return err; | |
| 873 | 878 | } | |
| 874 | 879 | ||
| 875 | 880 | void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp, | |
modified drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
| @@ -622,18 +622,9 @@ int sparx5_ptp_init(struct sparx5 *sparx5) | |||
| 622 | 622 | sparx5->ptp = 1; | |
| 623 | 623 | } | |
| 624 | 624 | ||
| 625 | - | if (!sparx5->ptp) | |
| 626 | - | return 0; | |
| 627 | - | ||
| 628 | - | for (i = 0; i < SPARX5_PHC_COUNT; ++i) { | |
| 629 | - | err = sparx5_ptp_phc_init(sparx5, i, &sparx5_ptp_clock_info); | |
| 630 | - | if (err) | |
| 631 | - | return err; | |
| 632 | - | } | |
| 633 | - | ||
| 634 | - | spin_lock_init(&sparx5->ptp_clock_lock); | |
| 635 | - | spin_lock_init(&sparx5->ptp_ts_id_lock); | |
| 636 | - | mutex_init(&sparx5->ptp_lock); | |
| 625 | + | /* The base, non-PTP-capable lan969x variants need the | |
| 626 | + | * first TOD counter running to forward frames. | |
| 627 | + | */ | |
| 637 | 628 | ||
| 638 | 629 | /* Disable master counters */ | |
| 639 | 630 | spx5_wr(PTP_PTP_DOM_CFG_PTP_ENA_SET(0), sparx5, PTP_PTP_DOM_CFG); | |
| @@ -657,6 +648,19 @@ int sparx5_ptp_init(struct sparx5 *sparx5) | |||
| 657 | 648 | /* Enable master counters */ | |
| 658 | 649 | spx5_wr(PTP_PTP_DOM_CFG_PTP_ENA_SET(0x7), sparx5, PTP_PTP_DOM_CFG); | |
| 659 | 650 | ||
| 651 | + | if (!sparx5->ptp) | |
| 652 | + | return 0; | |
| 653 | + | ||
| 654 | + | for (i = 0; i < SPARX5_PHC_COUNT; ++i) { | |
| 655 | + | err = sparx5_ptp_phc_init(sparx5, i, &sparx5_ptp_clock_info); | |
| 656 | + | if (err) | |
| 657 | + | return err; | |
| 658 | + | } | |
| 659 | + | ||
| 660 | + | spin_lock_init(&sparx5->ptp_clock_lock); | |
| 661 | + | spin_lock_init(&sparx5->ptp_ts_id_lock); | |
| 662 | + | mutex_init(&sparx5->ptp_lock); | |
| 663 | + | ||
| 660 | 664 | for (i = 0; i < sparx5->data->consts->n_ports; i++) { | |
| 661 | 665 | port = sparx5->ports[i]; | |
| 662 | 666 | if (!port) | |
modified drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
| @@ -160,6 +160,7 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev, | |||
| 160 | 160 | } | |
| 161 | 161 | ||
| 162 | 162 | list_del(&entry->list); | |
| 163 | + | kfree(entry); | |
| 163 | 164 | ||
| 164 | 165 | return err; | |
| 165 | 166 | } | |
modified drivers/net/ethernet/microsoft/mana/mana_bpf.c
| @@ -91,7 +91,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, | |||
| 91 | 91 | goto out; | |
| 92 | 92 | ||
| 93 | 93 | xdp_init_buff(xdp, PAGE_SIZE, &rxq->xdp_rxq); | |
| 94 | - | xdp_prepare_buff(xdp, buf_va, XDP_PACKET_HEADROOM, pkt_len, true); | |
| 94 | + | xdp_prepare_buff(xdp, buf_va, rxq->headroom, pkt_len, true); | |
| 95 | 95 | ||
| 96 | 96 | act = bpf_prog_run_xdp(prog, xdp); | |
| 97 | 97 | ||
| @@ -183,9 +183,9 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog, | |||
| 183 | 183 | if (!old_prog && !prog) | |
| 184 | 184 | return 0; | |
| 185 | 185 | ||
| 186 | - | if (prog && ndev->mtu > MANA_XDP_MTU_MAX) { | |
| 186 | + | if (prog && ndev->mtu > MANA_XDP_MTU_MAX(ndev)) { | |
| 187 | 187 | netdev_err(ndev, "XDP: mtu:%u too large, mtu_max:%lu\n", | |
| 188 | - | ndev->mtu, MANA_XDP_MTU_MAX); | |
| 188 | + | ndev->mtu, MANA_XDP_MTU_MAX(ndev)); | |
| 189 | 189 | NL_SET_ERR_MSG_MOD(extack, "XDP: mtu too large"); | |
| 190 | 190 | ||
| 191 | 191 | return -EOPNOTSUPP; | |
| @@ -238,7 +238,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog, | |||
| 238 | 238 | bpf_prog_put(old_prog); | |
| 239 | 239 | ||
| 240 | 240 | if (prog) | |
| 241 | - | ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX, | |
| 241 | + | ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX(ndev), | |
| 242 | 242 | gc->adapter_mtu - ETH_HLEN); | |
| 243 | 243 | else | |
| 244 | 244 | ndev->max_mtu = gc->adapter_mtu - ETH_HLEN; | |
modified drivers/net/ethernet/microsoft/mana/mana_en.c
| @@ -758,6 +758,44 @@ static void *mana_get_rxbuf_pre(struct mana_rxq *rxq, dma_addr_t *da) | |||
| 758 | 758 | return va; | |
| 759 | 759 | } | |
| 760 | 760 | ||
| 761 | + | /* Reserve enough headroom to satisfy the skb_cow() in ip_forward() and avoid | |
| 762 | + | * reallocation: the TX path keeps the SGE DMA mappings in struct mana_skb_head | |
| 763 | + | * at skb->head, so the port advertises ndev->needed_headroom = MANA_HEADROOM. | |
| 764 | + | */ | |
| 765 | + | static u32 mana_get_rxbuf_headroom(struct mana_port_context *apc) | |
| 766 | + | { | |
| 767 | + | if (mana_xdp_get(apc)) | |
| 768 | + | return mana_xdp_headroom(apc->ndev); | |
| 769 | + | ||
| 770 | + | return LL_RESERVED_SPACE(apc->ndev); | |
| 771 | + | } | |
| 772 | + | ||
| 773 | + | static u32 mana_get_rxbuf_size(struct mana_port_context *apc, u32 mtu) | |
| 774 | + | { | |
| 775 | + | u32 len = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD + | |
| 776 | + | mana_get_rxbuf_headroom(apc)); | |
| 777 | + | ||
| 778 | + | return ALIGN(len, MANA_RX_FRAG_ALIGNMENT); | |
| 779 | + | } | |
| 780 | + | ||
| 781 | + | /* Returns true when one RX buffer per page is already required by XDP or by | |
| 782 | + | * the buffer size implied by the MTU, i.e. regardless of the | |
| 783 | + | * MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF private flag. | |
| 784 | + | */ | |
| 785 | + | bool mana_single_rxbuf_per_page_forced(struct mana_port_context *apc, u32 mtu) | |
| 786 | + | { | |
| 787 | + | /* For xdp make sure only one packet fits per page. */ | |
| 788 | + | if (mana_xdp_get(apc)) | |
| 789 | + | return true; | |
| 790 | + | ||
| 791 | + | /* Only use the page_pool fragment path when at least two buffers, | |
| 792 | + | * including the headroom each of them has to reserve, actually fit | |
| 793 | + | * into one page. Otherwise the fragment path degenerates into one | |
| 794 | + | * buffer per page while still paying the fragment accounting cost. | |
| 795 | + | */ | |
| 796 | + | return PAGE_SIZE / mana_get_rxbuf_size(apc, mtu) < 2; | |
| 797 | + | } | |
| 798 | + | ||
| 761 | 799 | static bool | |
| 762 | 800 | mana_use_single_rxbuf_per_page(struct mana_port_context *apc, u32 mtu) | |
| 763 | 801 | { | |
| @@ -770,32 +808,27 @@ mana_use_single_rxbuf_per_page(struct mana_port_context *apc, u32 mtu) | |||
| 770 | 808 | if (apc->priv_flags & BIT(MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF)) | |
| 771 | 809 | return true; | |
| 772 | 810 | ||
| 773 | - | /* For xdp and jumbo frames make sure only one packet fits per page. */ | |
| 774 | - | if (mtu + MANA_RXBUF_PAD > PAGE_SIZE / 2 || mana_xdp_get(apc)) | |
| 775 | - | return true; | |
| 776 | - | ||
| 777 | - | return false; | |
| 811 | + | return mana_single_rxbuf_per_page_forced(apc, mtu); | |
| 778 | 812 | } | |
| 779 | 813 | ||
| 780 | - | /* Get RX buffer's data size, alloc size, XDP headroom based on MTU */ | |
| 814 | + | /* Get RX buffer's data size, alloc size, headroom and frag count based on MTU */ | |
| 781 | 815 | static void mana_get_rxbuf_cfg(struct mana_port_context *apc, | |
| 782 | 816 | int mtu, u32 *datasize, u32 *alloc_size, | |
| 783 | 817 | u32 *headroom, u32 *frag_count) | |
| 784 | 818 | { | |
| 785 | - | u32 len, buf_size; | |
| 819 | + | u32 buf_size; | |
| 786 | 820 | ||
| 787 | 821 | /* Calculate datasize first (consistent across all cases) */ | |
| 788 | 822 | *datasize = mtu + ETH_HLEN; | |
| 789 | 823 | ||
| 824 | + | *headroom = mana_get_rxbuf_headroom(apc); | |
| 825 | + | ||
| 790 | 826 | if (mana_use_single_rxbuf_per_page(apc, mtu)) { | |
| 791 | - | if (mana_xdp_get(apc)) { | |
| 792 | - | *headroom = XDP_PACKET_HEADROOM; | |
| 827 | + | if (mana_xdp_get(apc)) | |
| 793 | 828 | *alloc_size = PAGE_SIZE; | |
| 794 | - | } else { | |
| 795 | - | *headroom = 0; /* no support for XDP */ | |
| 829 | + | else | |
| 796 | 830 | *alloc_size = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD + | |
| 797 | 831 | *headroom); | |
| 798 | - | } | |
| 799 | 832 | ||
| 800 | 833 | *frag_count = 1; | |
| 801 | 834 | ||
| @@ -809,11 +842,7 @@ static void mana_get_rxbuf_cfg(struct mana_port_context *apc, | |||
| 809 | 842 | } | |
| 810 | 843 | ||
| 811 | 844 | /* Standard MTU case - optimize for multiple packets per page */ | |
| 812 | - | *headroom = 0; | |
| 813 | - | ||
| 814 | - | /* Calculate base buffer size needed */ | |
| 815 | - | len = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD + *headroom); | |
| 816 | - | buf_size = ALIGN(len, MANA_RX_FRAG_ALIGNMENT); | |
| 845 | + | buf_size = mana_get_rxbuf_size(apc, mtu); | |
| 817 | 846 | ||
| 818 | 847 | /* Calculate how many packets can fit in a page */ | |
| 819 | 848 | *frag_count = PAGE_SIZE / buf_size; | |
modified drivers/net/ethernet/microsoft/mana/mana_ethtool.c
| @@ -815,12 +815,12 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags) | |||
| 815 | 815 | if (!apc->port_is_up) | |
| 816 | 816 | return 0; | |
| 817 | 817 | ||
| 818 | - | /* If XDP is attached or MTU is jumbo, single-buffer-per-page | |
| 819 | - | * is already forced regardless of this flag. Skip the | |
| 820 | - | * expensive detach/attach cycle since nothing changes. | |
| 818 | + | /* If XDP is attached or the MTU already forces one buffer per | |
| 819 | + | * page, single-buffer-per-page is used regardless of this | |
| 820 | + | * flag. Skip the expensive detach/attach cycle since nothing | |
| 821 | + | * changes. | |
| 821 | 822 | */ | |
| 822 | - | if (ndev->mtu + MANA_RXBUF_PAD > PAGE_SIZE / 2 || | |
| 823 | - | mana_xdp_get(apc)) | |
| 823 | + | if (mana_single_rxbuf_per_page_forced(apc, ndev->mtu)) | |
| 824 | 824 | return 0; | |
| 825 | 825 | ||
| 826 | 826 | /* Block RDMA from grabbing the vport during detach/attach */ | |
modified drivers/net/ethernet/stmicro/stmmac/hwif.h
| @@ -633,7 +633,7 @@ struct stmmac_est_ops { | |||
| 633 | 633 | struct stmmac_vlan_ops { | |
| 634 | 634 | /* VLAN */ | |
| 635 | 635 | void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash, | |
| 636 | - | u16 perfect_match, bool is_double); | |
| 636 | + | bool is_svlan); | |
| 637 | 637 | void (*enable_vlan)(struct mac_device_info *hw, u32 type); | |
| 638 | 638 | void (*rx_hw_vlan)(struct mac_device_info *hw, struct dma_desc *rx_desc, | |
| 639 | 639 | struct sk_buff *skb); | |
modified drivers/net/ethernet/stmicro/stmmac/stmmac.h
| @@ -344,7 +344,7 @@ struct stmmac_priv { | |||
| 344 | 344 | void __iomem *ptpaddr; | |
| 345 | 345 | void __iomem *estaddr; | |
| 346 | 346 | unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; | |
| 347 | - | unsigned int num_double_vlans; | |
| 347 | + | unsigned int num_svlans; | |
| 348 | 348 | int sfty_irq; | |
| 349 | 349 | struct stmmac_msi *msi; | |
| 350 | 350 | ||
modified drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
| @@ -6226,6 +6226,13 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev, | |||
| 6226 | 6226 | if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN)) | |
| 6227 | 6227 | features &= ~NETIF_F_CSUM_MASK; | |
| 6228 | 6228 | ||
| 6229 | + | if (priv->plat->core_type == DWMAC_CORE_XGMAC) { | |
| 6230 | + | if (features & NETIF_F_HW_VLAN_CTAG_RX) | |
| 6231 | + | features |= NETIF_F_HW_VLAN_STAG_RX; | |
| 6232 | + | else | |
| 6233 | + | features &= ~NETIF_F_HW_VLAN_STAG_RX; | |
| 6234 | + | } | |
| 6235 | + | ||
| 6229 | 6236 | return features; | |
| 6230 | 6237 | } | |
| 6231 | 6238 | ||
| @@ -6850,32 +6857,21 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le) | |||
| 6850 | 6857 | return crc; | |
| 6851 | 6858 | } | |
| 6852 | 6859 | ||
| 6853 | - | static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double) | |
| 6860 | + | static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_svlan) | |
| 6854 | 6861 | { | |
| 6855 | 6862 | u32 crc, hash = 0; | |
| 6856 | - | u16 pmatch = 0; | |
| 6857 | - | int count = 0; | |
| 6858 | 6863 | u16 vid = 0; | |
| 6859 | 6864 | ||
| 6860 | 6865 | for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) { | |
| 6861 | 6866 | __le16 vid_le = cpu_to_le16(vid); | |
| 6862 | 6867 | crc = bitrev32(~stmmac_vid_crc32_le(vid_le)) >> 28; | |
| 6863 | 6868 | hash |= (1 << crc); | |
| 6864 | - | count++; | |
| 6865 | - | } | |
| 6866 | - | ||
| 6867 | - | if (!priv->dma_cap.vlhash) { | |
| 6868 | - | if (count > 2) /* VID = 0 always passes filter */ | |
| 6869 | - | return -EOPNOTSUPP; | |
| 6870 | - | ||
| 6871 | - | pmatch = vid; | |
| 6872 | - | hash = 0; | |
| 6873 | 6869 | } | |
| 6874 | 6870 | ||
| 6875 | 6871 | if (!netif_running(priv->dev)) | |
| 6876 | 6872 | return 0; | |
| 6877 | 6873 | ||
| 6878 | - | return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double); | |
| 6874 | + | return stmmac_update_vlan_hash(priv, priv->hw, hash, is_svlan); | |
| 6879 | 6875 | } | |
| 6880 | 6876 | ||
| 6881 | 6877 | /* FIXME: This may need RXC to be running, but it may be called with BH | |
| @@ -6884,8 +6880,8 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double) | |||
| 6884 | 6880 | static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid) | |
| 6885 | 6881 | { | |
| 6886 | 6882 | struct stmmac_priv *priv = netdev_priv(ndev); | |
| 6887 | - | unsigned int num_double_vlans; | |
| 6888 | - | bool is_double = false; | |
| 6883 | + | unsigned int num_svlans; | |
| 6884 | + | bool is_svlan = false; | |
| 6889 | 6885 | int ret; | |
| 6890 | 6886 | ||
| 6891 | 6887 | ret = pm_runtime_resume_and_get(priv->device); | |
| @@ -6893,11 +6889,11 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid | |||
| 6893 | 6889 | return ret; | |
| 6894 | 6890 | ||
| 6895 | 6891 | if (be16_to_cpu(proto) == ETH_P_8021AD) | |
| 6896 | - | is_double = true; | |
| 6892 | + | is_svlan = true; | |
| 6897 | 6893 | ||
| 6898 | 6894 | set_bit(vid, priv->active_vlans); | |
| 6899 | - | num_double_vlans = priv->num_double_vlans + is_double; | |
| 6900 | - | ret = stmmac_vlan_update(priv, num_double_vlans); | |
| 6895 | + | num_svlans = priv->num_svlans + is_svlan; | |
| 6896 | + | ret = stmmac_vlan_update(priv, num_svlans); | |
| 6901 | 6897 | if (ret) { | |
| 6902 | 6898 | clear_bit(vid, priv->active_vlans); | |
| 6903 | 6899 | goto err_pm_put; | |
| @@ -6907,12 +6903,12 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid | |||
| 6907 | 6903 | ret = stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); | |
| 6908 | 6904 | if (ret) { | |
| 6909 | 6905 | clear_bit(vid, priv->active_vlans); | |
| 6910 | - | stmmac_vlan_update(priv, priv->num_double_vlans); | |
| 6906 | + | stmmac_vlan_update(priv, priv->num_svlans); | |
| 6911 | 6907 | goto err_pm_put; | |
| 6912 | 6908 | } | |
| 6913 | 6909 | } | |
| 6914 | 6910 | ||
| 6915 | - | priv->num_double_vlans = num_double_vlans; | |
| 6911 | + | priv->num_svlans = num_svlans; | |
| 6916 | 6912 | ||
| 6917 | 6913 | err_pm_put: | |
| 6918 | 6914 | pm_runtime_put(priv->device); | |
| @@ -6926,8 +6922,8 @@ err_pm_put: | |||
| 6926 | 6922 | static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid) | |
| 6927 | 6923 | { | |
| 6928 | 6924 | struct stmmac_priv *priv = netdev_priv(ndev); | |
| 6929 | - | unsigned int num_double_vlans; | |
| 6930 | - | bool is_double = false; | |
| 6925 | + | unsigned int num_svlans; | |
| 6926 | + | bool is_svlan = false; | |
| 6931 | 6927 | int ret; | |
| 6932 | 6928 | ||
| 6933 | 6929 | ret = pm_runtime_resume_and_get(priv->device); | |
| @@ -6935,11 +6931,11 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi | |||
| 6935 | 6931 | return ret; | |
| 6936 | 6932 | ||
| 6937 | 6933 | if (be16_to_cpu(proto) == ETH_P_8021AD) | |
| 6938 | - | is_double = true; | |
| 6934 | + | is_svlan = true; | |
| 6939 | 6935 | ||
| 6940 | 6936 | clear_bit(vid, priv->active_vlans); | |
| 6941 | - | num_double_vlans = priv->num_double_vlans - is_double; | |
| 6942 | - | ret = stmmac_vlan_update(priv, num_double_vlans); | |
| 6937 | + | num_svlans = priv->num_svlans - is_svlan; | |
| 6938 | + | ret = stmmac_vlan_update(priv, num_svlans); | |
| 6943 | 6939 | if (ret) { | |
| 6944 | 6940 | set_bit(vid, priv->active_vlans); | |
| 6945 | 6941 | goto del_vlan_error; | |
| @@ -6949,12 +6945,12 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi | |||
| 6949 | 6945 | ret = stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); | |
| 6950 | 6946 | if (ret) { | |
| 6951 | 6947 | set_bit(vid, priv->active_vlans); | |
| 6952 | - | stmmac_vlan_update(priv, priv->num_double_vlans); | |
| 6948 | + | stmmac_vlan_update(priv, priv->num_svlans); | |
| 6953 | 6949 | goto del_vlan_error; | |
| 6954 | 6950 | } | |
| 6955 | 6951 | } | |
| 6956 | 6952 | ||
| 6957 | - | priv->num_double_vlans = num_double_vlans; | |
| 6953 | + | priv->num_svlans = num_svlans; | |
| 6958 | 6954 | ||
| 6959 | 6955 | del_vlan_error: | |
| 6960 | 6956 | pm_runtime_put(priv->device); | |
| @@ -6970,7 +6966,7 @@ static void stmmac_vlan_restore(struct stmmac_priv *priv) | |||
| 6970 | 6966 | if (priv->hw->num_vlan) | |
| 6971 | 6967 | stmmac_restore_hw_vlan_rx_fltr(priv, priv->dev, priv->hw); | |
| 6972 | 6968 | ||
| 6973 | - | stmmac_vlan_update(priv, priv->num_double_vlans); | |
| 6969 | + | stmmac_vlan_update(priv, priv->num_svlans); | |
| 6974 | 6970 | } | |
| 6975 | 6971 | ||
| 6976 | 6972 | static int stmmac_bpf(struct net_device *dev, struct netdev_bpf *bpf) | |
| @@ -8009,14 +8005,18 @@ static int __stmmac_dvr_probe(struct device *device, | |||
| 8009 | 8005 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); | |
| 8010 | 8006 | #ifdef STMMAC_VLAN_TAG_USED | |
| 8011 | 8007 | /* Both mac100 and gmac support receive VLAN tag detection */ | |
| 8012 | - | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX; | |
| 8008 | + | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; | |
| 8009 | + | if (priv->plat->core_type == DWMAC_CORE_XGMAC) | |
| 8010 | + | ndev->features |= NETIF_F_HW_VLAN_STAG_RX; | |
| 8011 | + | ||
| 8013 | 8012 | if (dwmac_is_xmac(priv->plat->core_type)) { | |
| 8014 | 8013 | ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX; | |
| 8015 | 8014 | priv->hw->hw_vlan_en = true; | |
| 8016 | 8015 | } | |
| 8017 | 8016 | if (priv->dma_cap.vlhash) { | |
| 8018 | 8017 | ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; | |
| 8019 | - | ndev->features |= NETIF_F_HW_VLAN_STAG_FILTER; | |
| 8018 | + | if (priv->plat->core_type == DWMAC_CORE_XGMAC) | |
| 8019 | + | ndev->features |= NETIF_F_HW_VLAN_STAG_FILTER; | |
| 8020 | 8020 | } | |
| 8021 | 8021 | if (priv->dma_cap.vlins) | |
| 8022 | 8022 | ndev->features |= NETIF_F_HW_VLAN_CTAG_TX; | |
modified drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
| @@ -243,7 +243,7 @@ struct stmmac_test_priv { | |||
| 243 | 243 | int (*func)(struct sk_buff *skb, struct net_device *ndev, | |
| 244 | 244 | struct packet_type *pt, struct net_device *orig_ndev); | |
| 245 | 245 | bool capture_all; | |
| 246 | - | int double_vlan; | |
| 246 | + | int svlan; | |
| 247 | 247 | int vlan_id; | |
| 248 | 248 | int ok; | |
| 249 | 249 | }; | |
| @@ -285,7 +285,7 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb, | |||
| 285 | 285 | } | |
| 286 | 286 | ||
| 287 | 287 | ihdr = ip_hdr(skb); | |
| 288 | - | if (tpriv->double_vlan) | |
| 288 | + | if (tpriv->svlan) | |
| 289 | 289 | ihdr = (struct iphdr *)(skb_network_header(skb) + 4); | |
| 290 | 290 | ||
| 291 | 291 | if (tpriv->packet->tcp) { | |
| @@ -936,7 +936,7 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb, | |||
| 936 | 936 | struct iphdr *ihdr; | |
| 937 | 937 | u16 proto; | |
| 938 | 938 | ||
| 939 | - | proto = tpriv->double_vlan ? ETH_P_8021AD : ETH_P_8021Q; | |
| 939 | + | proto = tpriv->svlan ? ETH_P_8021AD : ETH_P_8021Q; | |
| 940 | 940 | ||
| 941 | 941 | skb = skb_unshare(skb, GFP_ATOMIC); | |
| 942 | 942 | if (!skb) | |
| @@ -963,7 +963,7 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb, | |||
| 963 | 963 | } | |
| 964 | 964 | ||
| 965 | 965 | ihdr = ip_hdr(skb); | |
| 966 | - | if (tpriv->double_vlan) | |
| 966 | + | if (tpriv->svlan) | |
| 967 | 967 | ihdr = (struct iphdr *)(skb_network_header(skb) + 4); | |
| 968 | 968 | if (ihdr->protocol != IPPROTO_UDP) | |
| 969 | 969 | goto out; | |
| @@ -1080,7 +1080,7 @@ static int stmmac_test_vlanfilt_perfect(struct stmmac_priv *priv) | |||
| 1080 | 1080 | return ret; | |
| 1081 | 1081 | } | |
| 1082 | 1082 | ||
| 1083 | - | static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv) | |
| 1083 | + | static int __stmmac_test_svlanfilt(struct stmmac_priv *priv) | |
| 1084 | 1084 | { | |
| 1085 | 1085 | struct stmmac_packet_attrs attr = { }; | |
| 1086 | 1086 | struct stmmac_test_priv *tpriv; | |
| @@ -1092,7 +1092,7 @@ static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv) | |||
| 1092 | 1092 | return -ENOMEM; | |
| 1093 | 1093 | ||
| 1094 | 1094 | tpriv->ok = false; | |
| 1095 | - | tpriv->double_vlan = true; | |
| 1095 | + | tpriv->svlan = true; | |
| 1096 | 1096 | init_completion(&tpriv->comp); | |
| 1097 | 1097 | ||
| 1098 | 1098 | tpriv->pt.type = htons(ETH_P_8021Q); | |
| @@ -1155,15 +1155,15 @@ cleanup: | |||
| 1155 | 1155 | return ret; | |
| 1156 | 1156 | } | |
| 1157 | 1157 | ||
| 1158 | - | static int stmmac_test_dvlanfilt(struct stmmac_priv *priv) | |
| 1158 | + | static int stmmac_test_svlanfilt(struct stmmac_priv *priv) | |
| 1159 | 1159 | { | |
| 1160 | 1160 | if (!priv->dma_cap.vlhash) | |
| 1161 | 1161 | return -EOPNOTSUPP; | |
| 1162 | 1162 | ||
| 1163 | - | return __stmmac_test_dvlanfilt(priv); | |
| 1163 | + | return __stmmac_test_svlanfilt(priv); | |
| 1164 | 1164 | } | |
| 1165 | 1165 | ||
| 1166 | - | static int stmmac_test_dvlanfilt_perfect(struct stmmac_priv *priv) | |
| 1166 | + | static int stmmac_test_svlanfilt_perfect(struct stmmac_priv *priv) | |
| 1167 | 1167 | { | |
| 1168 | 1168 | int ret, prev_cap = priv->dma_cap.vlhash; | |
| 1169 | 1169 | ||
| @@ -1171,7 +1171,7 @@ static int stmmac_test_dvlanfilt_perfect(struct stmmac_priv *priv) | |||
| 1171 | 1171 | return -EOPNOTSUPP; | |
| 1172 | 1172 | ||
| 1173 | 1173 | priv->dma_cap.vlhash = 0; | |
| 1174 | - | ret = __stmmac_test_dvlanfilt(priv); | |
| 1174 | + | ret = __stmmac_test_svlanfilt(priv); | |
| 1175 | 1175 | priv->dma_cap.vlhash = prev_cap; | |
| 1176 | 1176 | ||
| 1177 | 1177 | return ret; | |
| @@ -1372,7 +1372,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan) | |||
| 1372 | 1372 | proto = svlan ? ETH_P_8021AD : ETH_P_8021Q; | |
| 1373 | 1373 | ||
| 1374 | 1374 | tpriv->ok = false; | |
| 1375 | - | tpriv->double_vlan = svlan; | |
| 1375 | + | tpriv->svlan = svlan; | |
| 1376 | 1376 | init_completion(&tpriv->comp); | |
| 1377 | 1377 | ||
| 1378 | 1378 | tpriv->pt.type = svlan ? htons(ETH_P_8021Q) : htons(ETH_P_IP); | |
| @@ -1960,11 +1960,11 @@ static const struct stmmac_test { | |||
| 1960 | 1960 | .name = "VLAN Filtering (perf) ", | |
| 1961 | 1961 | .fn = stmmac_test_vlanfilt_perfect, | |
| 1962 | 1962 | }, { | |
| 1963 | - | .name = "Double VLAN Filter ", | |
| 1964 | - | .fn = stmmac_test_dvlanfilt, | |
| 1963 | + | .name = "SVLAN Filtering ", | |
| 1964 | + | .fn = stmmac_test_svlanfilt, | |
| 1965 | 1965 | }, { | |
| 1966 | - | .name = "Double VLAN Filter (perf) ", | |
| 1967 | - | .fn = stmmac_test_dvlanfilt_perfect, | |
| 1966 | + | .name = "SVLAN Filtering (perf) ", | |
| 1967 | + | .fn = stmmac_test_svlanfilt_perfect, | |
| 1968 | 1968 | }, { | |
| 1969 | 1969 | .name = "Flexible RX Parser ", | |
| 1970 | 1970 | .fn = stmmac_test_rxp, | |
modified drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
| @@ -162,7 +162,7 @@ static void vlan_restore_hw_rx_fltr(struct net_device *dev, | |||
| 162 | 162 | } | |
| 163 | 163 | ||
| 164 | 164 | static void vlan_update_hash(struct mac_device_info *hw, u32 hash, | |
| 165 | - | u16 perfect_match, bool is_double) | |
| 165 | + | bool is_svlan) | |
| 166 | 166 | { | |
| 167 | 167 | void __iomem *ioaddr = hw->pcsr; | |
| 168 | 168 | u32 value; | |
| @@ -173,34 +173,17 @@ static void vlan_update_hash(struct mac_device_info *hw, u32 hash, | |||
| 173 | 173 | ||
| 174 | 174 | if (hash) { | |
| 175 | 175 | value |= VLAN_VTHM | VLAN_ETV; | |
| 176 | - | if (is_double) { | |
| 177 | - | value |= VLAN_EDVLP; | |
| 176 | + | if (is_svlan) { | |
| 178 | 177 | value |= VLAN_ESVL; | |
| 179 | 178 | value |= VLAN_DOVLTC; | |
| 180 | 179 | } else { | |
| 181 | - | value &= ~VLAN_EDVLP; | |
| 182 | 180 | value &= ~VLAN_ESVL; | |
| 183 | 181 | value &= ~VLAN_DOVLTC; | |
| 184 | 182 | } | |
| 185 | 183 | ||
| 186 | 184 | writel(value, ioaddr + VLAN_TAG); | |
| 187 | - | } else if (perfect_match) { | |
| 188 | - | u32 value = VLAN_ETV; | |
| 189 | - | ||
| 190 | - | if (is_double) { | |
| 191 | - | value |= VLAN_EDVLP; | |
| 192 | - | value |= VLAN_ESVL; | |
| 193 | - | value |= VLAN_DOVLTC; | |
| 194 | - | } else { | |
| 195 | - | value &= ~VLAN_EDVLP; | |
| 196 | - | value &= ~VLAN_ESVL; | |
| 197 | - | value &= ~VLAN_DOVLTC; | |
| 198 | - | } | |
| 199 | - | ||
| 200 | - | writel(value | perfect_match, ioaddr + VLAN_TAG); | |
| 201 | 185 | } else { | |
| 202 | - | value &= ~(VLAN_VTHM | VLAN_ETV); | |
| 203 | - | value &= ~(VLAN_EDVLP | VLAN_ESVL); | |
| 186 | + | value &= ~(VLAN_VTHM | VLAN_ETV | VLAN_ESVL); | |
| 204 | 187 | value &= ~VLAN_DOVLTC; | |
| 205 | 188 | value &= ~VLAN_VID; | |
| 206 | 189 | ||
| @@ -236,6 +219,7 @@ static void vlan_set_hw_mode(struct mac_device_info *hw) | |||
| 236 | 219 | void __iomem *ioaddr = hw->pcsr; | |
| 237 | 220 | u32 value = readl(ioaddr + VLAN_TAG); | |
| 238 | 221 | ||
| 222 | + | value |= VLAN_EDVLP; | |
| 239 | 223 | value &= ~VLAN_TAG_CTRL_EVLS_MASK; | |
| 240 | 224 | ||
| 241 | 225 | if (hw->hw_vlan_en) | |
| @@ -251,7 +235,7 @@ static void vlan_set_hw_mode(struct mac_device_info *hw) | |||
| 251 | 235 | } | |
| 252 | 236 | ||
| 253 | 237 | static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash, | |
| 254 | - | u16 perfect_match, bool is_double) | |
| 238 | + | bool is_svlan) | |
| 255 | 239 | { | |
| 256 | 240 | void __iomem *ioaddr = hw->pcsr; | |
| 257 | 241 | ||
| @@ -267,41 +251,16 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash, | |||
| 267 | 251 | value = readl(ioaddr + VLAN_TAG); | |
| 268 | 252 | ||
| 269 | 253 | value |= VLAN_VTHM | VLAN_ETV; | |
| 270 | - | if (is_double) { | |
| 271 | - | value |= VLAN_EDVLP; | |
| 254 | + | if (is_svlan) { | |
| 272 | 255 | value |= VLAN_ESVL; | |
| 273 | 256 | value |= VLAN_DOVLTC; | |
| 274 | 257 | } else { | |
| 275 | - | value &= ~VLAN_EDVLP; | |
| 276 | 258 | value &= ~VLAN_ESVL; | |
| 277 | 259 | value &= ~VLAN_DOVLTC; | |
| 278 | 260 | } | |
| 279 | 261 | ||
| 280 | 262 | value &= ~VLAN_VID; | |
| 281 | 263 | writel(value, ioaddr + VLAN_TAG); | |
| 282 | - | } else if (perfect_match) { | |
| 283 | - | u32 value = readl(ioaddr + XGMAC_PACKET_FILTER); | |
| 284 | - | ||
| 285 | - | value |= XGMAC_FILTER_VTFE; | |
| 286 | - | ||
| 287 | - | writel(value, ioaddr + XGMAC_PACKET_FILTER); | |
| 288 | - | ||
| 289 | - | value = readl(ioaddr + VLAN_TAG); | |
| 290 | - | ||
| 291 | - | value &= ~VLAN_VTHM; | |
| 292 | - | value |= VLAN_ETV; | |
| 293 | - | if (is_double) { | |
| 294 | - | value |= VLAN_EDVLP; | |
| 295 | - | value |= VLAN_ESVL; | |
| 296 | - | value |= VLAN_DOVLTC; | |
| 297 | - | } else { | |
| 298 | - | value &= ~VLAN_EDVLP; | |
| 299 | - | value &= ~VLAN_ESVL; | |
| 300 | - | value &= ~VLAN_DOVLTC; | |
| 301 | - | } | |
| 302 | - | ||
| 303 | - | value &= ~VLAN_VID; | |
| 304 | - | writel(value | perfect_match, ioaddr + VLAN_TAG); | |
| 305 | 264 | } else { | |
| 306 | 265 | u32 value = readl(ioaddr + XGMAC_PACKET_FILTER); | |
| 307 | 266 | ||
| @@ -311,8 +270,7 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash, | |||
| 311 | 270 | ||
| 312 | 271 | value = readl(ioaddr + VLAN_TAG); | |
| 313 | 272 | ||
| 314 | - | value &= ~(VLAN_VTHM | VLAN_ETV); | |
| 315 | - | value &= ~(VLAN_EDVLP | VLAN_ESVL); | |
| 273 | + | value &= ~(VLAN_VTHM | VLAN_ETV | VLAN_ESVL); | |
| 316 | 274 | value &= ~VLAN_DOVLTC; | |
| 317 | 275 | value &= ~VLAN_VID; | |
| 318 | 276 | ||
| @@ -320,6 +278,14 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash, | |||
| 320 | 278 | } | |
| 321 | 279 | } | |
| 322 | 280 | ||
| 281 | + | static void dwxlgmac2_set_hw_vlan_mode(struct mac_device_info *hw) | |
| 282 | + | { | |
| 283 | + | void __iomem *ioaddr = hw->pcsr; | |
| 284 | + | u32 value = readl(ioaddr + VLAN_TAG); | |
| 285 | + | ||
| 286 | + | writel(value | VLAN_EDVLP, ioaddr + VLAN_TAG); | |
| 287 | + | } | |
| 288 | + | ||
| 323 | 289 | const struct stmmac_vlan_ops dwmac_vlan_ops = { | |
| 324 | 290 | .update_vlan_hash = vlan_update_hash, | |
| 325 | 291 | .enable_vlan = vlan_enable, | |
| @@ -333,6 +299,7 @@ const struct stmmac_vlan_ops dwmac_vlan_ops = { | |||
| 333 | 299 | const struct stmmac_vlan_ops dwxlgmac2_vlan_ops = { | |
| 334 | 300 | .update_vlan_hash = dwxgmac2_update_vlan_hash, | |
| 335 | 301 | .enable_vlan = vlan_enable, | |
| 302 | + | .set_hw_vlan_mode = dwxlgmac2_set_hw_vlan_mode, | |
| 336 | 303 | }; | |
| 337 | 304 | ||
| 338 | 305 | const struct stmmac_vlan_ops dwxgmac210_vlan_ops = { | |
modified drivers/net/ethernet/xilinx/xilinx_axienet.h
| @@ -523,8 +523,9 @@ struct skbuf_dma_descriptor { | |||
| 523 | 523 | * @stats_work: Work for reading the hardware statistics counters often enough | |
| 524 | 524 | * to catch overflows. | |
| 525 | 525 | * @dma_err_task: Work structure to process Axi DMA errors | |
| 526 | - | * @stopping: Set when @dma_err_task shouldn't do anything because we are | |
| 527 | - | * about to stop the device. | |
| 526 | + | * @stopping: Set when we are about to stop the device: makes @dma_err_task | |
| 527 | + | * a no-op (legacy DMA path) and fences RX descriptor | |
| 528 | + | * resubmission in axienet_dma_rx_cb() (dmaengine path). | |
| 528 | 529 | * @tx_irq: Axidma TX IRQ number | |
| 529 | 530 | * @rx_irq: Axidma RX IRQ number | |
| 530 | 531 | * @eth_irq: Ethernet core IRQ number | |
| @@ -545,6 +546,7 @@ struct skbuf_dma_descriptor { | |||
| 545 | 546 | * @tx_ring_tail: TX skb ring buffer tail index. | |
| 546 | 547 | * @rx_ring_head: RX skb ring buffer head index. | |
| 547 | 548 | * @rx_ring_tail: RX skb ring buffer tail index. | |
| 549 | + | * @rx_submit_lock: Protects RX ring resubmission vs teardown in dmaengine path. | |
| 548 | 550 | */ | |
| 549 | 551 | struct axienet_local { | |
| 550 | 552 | struct net_device *ndev; | |
| @@ -626,6 +628,7 @@ struct axienet_local { | |||
| 626 | 628 | int tx_ring_tail; | |
| 627 | 629 | int rx_ring_head; | |
| 628 | 630 | int rx_ring_tail; | |
| 631 | + | spinlock_t rx_submit_lock; | |
| 629 | 632 | }; | |
| 630 | 633 | ||
| 631 | 634 | /** | |
modified drivers/net/ethernet/xilinx/xilinx_axienet_main.c
| @@ -881,6 +881,7 @@ static void axienet_dma_tx_cb(void *data, const struct dmaengine_result *result) | |||
| 881 | 881 | u64_stats_update_end(&lp->tx_stat_sync); | |
| 882 | 882 | dma_unmap_sg(lp->dev, skbuf_dma->sgl, skbuf_dma->sg_len, DMA_TO_DEVICE); | |
| 883 | 883 | dev_consume_skb_any(skbuf_dma->skb); | |
| 884 | + | skbuf_dma->skb = NULL; | |
| 884 | 885 | netif_txq_completed_wake(txq, 1, len, | |
| 885 | 886 | CIRC_SPACE(lp->tx_ring_head, lp->tx_ring_tail, TX_BD_NUM_MAX), | |
| 886 | 887 | 2); | |
| @@ -1171,6 +1172,7 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result) | |||
| 1171 | 1172 | &meta_max_len); | |
| 1172 | 1173 | dma_unmap_single(lp->dev, skbuf_dma->dma_address, lp->max_frm_size, | |
| 1173 | 1174 | DMA_FROM_DEVICE); | |
| 1175 | + | skbuf_dma->skb = NULL; | |
| 1174 | 1176 | ||
| 1175 | 1177 | if (IS_ERR(app_metadata)) { | |
| 1176 | 1178 | if (net_ratelimit()) | |
| @@ -1193,10 +1195,17 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result) | |||
| 1193 | 1195 | u64_stats_update_end(&lp->rx_stat_sync); | |
| 1194 | 1196 | ||
| 1195 | 1197 | rx_submit: | |
| 1198 | + | spin_lock(&lp->rx_submit_lock); | |
| 1199 | + | if (lp->stopping) { | |
| 1200 | + | spin_unlock(&lp->rx_submit_lock); | |
| 1201 | + | return; | |
| 1202 | + | } | |
| 1203 | + | ||
| 1196 | 1204 | for (i = 0; i < CIRC_SPACE(lp->rx_ring_head, lp->rx_ring_tail, | |
| 1197 | 1205 | RX_BUF_NUM_DEFAULT); i++) | |
| 1198 | 1206 | axienet_rx_submit_desc(lp->ndev); | |
| 1199 | 1207 | dma_async_issue_pending(lp->rx_chan); | |
| 1208 | + | spin_unlock(&lp->rx_submit_lock); | |
| 1200 | 1209 | } | |
| 1201 | 1210 | ||
| 1202 | 1211 | /** | |
| @@ -1541,6 +1550,7 @@ static int axienet_init_dmaengine(struct net_device *ndev) | |||
| 1541 | 1550 | lp->tx_ring_head = 0; | |
| 1542 | 1551 | lp->rx_ring_tail = 0; | |
| 1543 | 1552 | lp->rx_ring_head = 0; | |
| 1553 | + | lp->stopping = false; | |
| 1544 | 1554 | lp->tx_skb_ring = kzalloc_objs(*lp->tx_skb_ring, TX_BD_NUM_MAX); | |
| 1545 | 1555 | if (!lp->tx_skb_ring) { | |
| 1546 | 1556 | ret = -ENOMEM; | |
| @@ -1752,20 +1762,42 @@ static int axienet_stop(struct net_device *ndev) | |||
| 1752 | 1762 | free_irq(lp->rx_irq, ndev); | |
| 1753 | 1763 | axienet_dma_bd_release(ndev); | |
| 1754 | 1764 | } else { | |
| 1765 | + | struct skbuf_dma_descriptor *skbuf_dma; | |
| 1766 | + | ||
| 1767 | + | spin_lock_bh(&lp->rx_submit_lock); | |
| 1768 | + | lp->stopping = true; | |
| 1769 | + | spin_unlock_bh(&lp->rx_submit_lock); | |
| 1770 | + | ||
| 1755 | 1771 | dmaengine_terminate_sync(lp->tx_chan); | |
| 1756 | - | dmaengine_synchronize(lp->tx_chan); | |
| 1757 | 1772 | dmaengine_terminate_sync(lp->rx_chan); | |
| 1758 | - | dmaengine_synchronize(lp->rx_chan); | |
| 1759 | - | ||
| 1760 | - | for (i = 0; i < TX_BD_NUM_MAX; i++) | |
| 1761 | - | kfree(lp->tx_skb_ring[i]); | |
| 1762 | - | kfree(lp->tx_skb_ring); | |
| 1763 | - | for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) | |
| 1764 | - | kfree(lp->rx_skb_ring[i]); | |
| 1765 | - | kfree(lp->rx_skb_ring); | |
| 1766 | 1773 | ||
| 1767 | 1774 | dma_release_channel(lp->rx_chan); | |
| 1768 | 1775 | dma_release_channel(lp->tx_chan); | |
| 1776 | + | ||
| 1777 | + | /* Unmap and free any buffer the terminate did not reclaim, so it | |
| 1778 | + | * is not leaked; a non-NULL skb marks such a slot. | |
| 1779 | + | */ | |
| 1780 | + | for (i = 0; i < TX_BD_NUM_MAX; i++) { | |
| 1781 | + | skbuf_dma = lp->tx_skb_ring[i]; | |
| 1782 | + | if (skbuf_dma && skbuf_dma->skb) { | |
| 1783 | + | dma_unmap_sg(lp->dev, skbuf_dma->sgl, | |
| 1784 | + | skbuf_dma->sg_len, DMA_TO_DEVICE); | |
| 1785 | + | dev_kfree_skb_any(skbuf_dma->skb); | |
| 1786 | + | } | |
| 1787 | + | kfree(skbuf_dma); | |
| 1788 | + | } | |
| 1789 | + | kfree(lp->tx_skb_ring); | |
| 1790 | + | ||
| 1791 | + | for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) { | |
| 1792 | + | skbuf_dma = lp->rx_skb_ring[i]; | |
| 1793 | + | if (skbuf_dma && skbuf_dma->skb) { | |
| 1794 | + | dma_unmap_single(lp->dev, skbuf_dma->dma_address, | |
| 1795 | + | lp->max_frm_size, DMA_FROM_DEVICE); | |
| 1796 | + | dev_kfree_skb_any(skbuf_dma->skb); | |
| 1797 | + | } | |
| 1798 | + | kfree(skbuf_dma); | |
| 1799 | + | } | |
| 1800 | + | kfree(lp->rx_skb_ring); | |
| 1769 | 1801 | } | |
| 1770 | 1802 | ||
| 1771 | 1803 | netdev_reset_queue(ndev); | |
| @@ -3065,6 +3097,7 @@ static int axienet_probe(struct platform_device *pdev) | |||
| 3065 | 3097 | ||
| 3066 | 3098 | spin_lock_init(&lp->rx_cr_lock); | |
| 3067 | 3099 | spin_lock_init(&lp->tx_cr_lock); | |
| 3100 | + | spin_lock_init(&lp->rx_submit_lock); | |
| 3068 | 3101 | INIT_WORK(&lp->rx_dim.work, axienet_rx_dim_work); | |
| 3069 | 3102 | lp->rx_dim_enabled = true; | |
| 3070 | 3103 | lp->rx_dim.profile_ix = 1; | |
modified drivers/net/pfcp.c
| @@ -65,6 +65,13 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) | |||
| 65 | 65 | goto drop; | |
| 66 | 66 | ||
| 67 | 67 | unparsed = pfcp_hdr(skb); | |
| 68 | + | if (unparsed->flags & PFCP_SEID_FLAG) { | |
| 69 | + | if (unlikely(!pskb_may_pull(skb, PFCP_HLEN + | |
| 70 | + | offsetofend(struct pfcphdr_session, | |
| 71 | + | seid)))) | |
| 72 | + | goto drop; | |
| 73 | + | unparsed = pfcp_hdr(skb); | |
| 74 | + | } | |
| 68 | 75 | ||
| 69 | 76 | ip_tunnel_flags_zero(flags); | |
| 70 | 77 | tun_dst = udp_tun_rx_dst(skb, sk->sk_family, flags, 0, | |
modified drivers/net/team/team_core.c
| @@ -820,7 +820,8 @@ static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id) | |||
| 820 | 820 | /* | |
| 821 | 821 | * note: already called with rcu_read_lock | |
| 822 | 822 | */ | |
| 823 | - | static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb) | |
| 823 | + | static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb, | |
| 824 | + | bool *tx_success) | |
| 824 | 825 | { | |
| 825 | 826 | struct list_head *qom_list; | |
| 826 | 827 | struct team_port *port; | |
| @@ -828,11 +829,11 @@ static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb) | |||
| 828 | 829 | if (!team->queue_override_enabled || !skb->queue_mapping) | |
| 829 | 830 | return false; | |
| 830 | 831 | qom_list = __team_get_qom_list(team, skb->queue_mapping); | |
| 831 | - | list_for_each_entry_rcu(port, qom_list, qom_list) { | |
| 832 | - | if (!team_dev_queue_xmit(team, port, skb)) | |
| 833 | - | return true; | |
| 834 | - | } | |
| 835 | - | return false; | |
| 832 | + | port = list_first_or_null_rcu(qom_list, struct team_port, qom_list); | |
| 833 | + | if (!port) | |
| 834 | + | return false; | |
| 835 | + | *tx_success = !team_dev_queue_xmit(team, port, skb); | |
| 836 | + | return true; | |
| 836 | 837 | } | |
| 837 | 838 | ||
| 838 | 839 | static void __team_queue_override_port_del(struct team *team, | |
| @@ -1864,8 +1865,7 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 1864 | 1865 | bool tx_success; | |
| 1865 | 1866 | unsigned int len = skb->len; | |
| 1866 | 1867 | ||
| 1867 | - | tx_success = team_queue_override_transmit(team, skb); | |
| 1868 | - | if (!tx_success) | |
| 1868 | + | if (!team_queue_override_transmit(team, skb, &tx_success)) | |
| 1869 | 1869 | tx_success = READ_ONCE(team->ops.transmit)(team, skb); | |
| 1870 | 1870 | if (tx_success) { | |
| 1871 | 1871 | struct team_pcpu_stats *pcpu_stats; | |
modified drivers/net/team/team_mode_broadcast.c
| @@ -37,6 +37,8 @@ static bool bc_transmit(struct team *team, struct sk_buff *skb) | |||
| 37 | 37 | ret = !team_dev_queue_xmit(team, last, skb); | |
| 38 | 38 | if (!sum_ret) | |
| 39 | 39 | sum_ret = ret; | |
| 40 | + | } else { | |
| 41 | + | dev_kfree_skb_any(skb); | |
| 40 | 42 | } | |
| 41 | 43 | return sum_ret; | |
| 42 | 44 | } | |
modified drivers/net/tun.c
| @@ -1897,12 +1897,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
| 1897 | 1897 | } | |
| 1898 | 1898 | } | |
| 1899 | 1899 | ||
| 1900 | - | if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) { | |
| 1901 | - | atomic_long_inc(&tun->rx_frame_errors); | |
| 1902 | - | err = -EINVAL; | |
| 1903 | - | goto free_skb; | |
| 1904 | - | } | |
| 1905 | - | ||
| 1900 | + | skb->dev = tun->dev; | |
| 1906 | 1901 | switch (tun->flags & TUN_TYPE_MASK) { | |
| 1907 | 1902 | case IFF_TUN: | |
| 1908 | 1903 | if (tun->flags & IFF_NO_PI) { | |
| @@ -1927,9 +1922,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
| 1927 | 1922 | } | |
| 1928 | 1923 | } | |
| 1929 | 1924 | ||
| 1930 | - | skb_reset_mac_header(skb); | |
| 1925 | + | skb_reset_network_header(skb); | |
| 1931 | 1926 | skb->protocol = pi.proto; | |
| 1932 | - | skb->dev = tun->dev; | |
| 1933 | 1927 | break; | |
| 1934 | 1928 | case IFF_TAP: | |
| 1935 | 1929 | if (!pskb_may_pull(skb, ETH_HLEN)) { | |
| @@ -1937,10 +1931,19 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
| 1937 | 1931 | drop_reason = SKB_DROP_REASON_HDR_TRUNC; | |
| 1938 | 1932 | goto drop; | |
| 1939 | 1933 | } | |
| 1940 | - | skb->protocol = eth_type_trans(skb, tun->dev); | |
| 1934 | + | skb_set_network_header(skb, ETH_HLEN); | |
| 1941 | 1935 | break; | |
| 1942 | 1936 | } | |
| 1943 | 1937 | ||
| 1938 | + | if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) { | |
| 1939 | + | atomic_long_inc(&tun->rx_frame_errors); | |
| 1940 | + | err = -EINVAL; | |
| 1941 | + | goto free_skb; | |
| 1942 | + | } | |
| 1943 | + | ||
| 1944 | + | if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) | |
| 1945 | + | skb->protocol = eth_type_trans(skb, tun->dev); | |
| 1946 | + | ||
| 1944 | 1947 | /* copy skb_ubuf_info for callback when skb has no error */ | |
| 1945 | 1948 | if (zerocopy) { | |
| 1946 | 1949 | skb_zcopy_init(skb, msg_control); | |
| @@ -2600,6 +2603,8 @@ build: | |||
| 2600 | 2603 | ||
| 2601 | 2604 | features = tun_vnet_hdr_guest_features(READ_ONCE(tun->vnet_hdr_sz)); | |
| 2602 | 2605 | tnl_hdr = (struct virtio_net_hdr_v1_hash_tunnel *)gso; | |
| 2606 | + | skb->dev = tun->dev; | |
| 2607 | + | skb_set_network_header(skb, ETH_HLEN); | |
| 2603 | 2608 | if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr)) { | |
| 2604 | 2609 | atomic_long_inc(&tun->rx_frame_errors); | |
| 2605 | 2610 | kfree_skb(skb); | |
modified drivers/net/usb/ax88179_178a.c
| @@ -1457,11 +1457,11 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | |||
| 1457 | 1457 | return 1; | |
| 1458 | 1458 | } | |
| 1459 | 1459 | ||
| 1460 | - | ax_skb = netdev_alloc_skb_ip_align(dev->net, pkt_len); | |
| 1460 | + | ax_skb = netdev_alloc_skb_ip_align(dev->net, pkt_len - 2); | |
| 1461 | 1461 | if (!ax_skb) | |
| 1462 | 1462 | return 0; | |
| 1463 | - | skb_put(ax_skb, pkt_len); | |
| 1464 | - | memcpy(ax_skb->data, skb->data + 2, pkt_len); | |
| 1463 | + | skb_put(ax_skb, pkt_len - 2); | |
| 1464 | + | memcpy(ax_skb->data, skb->data + 2, pkt_len - 2); | |
| 1465 | 1465 | ||
| 1466 | 1466 | ax88179_rx_checksum(ax_skb, pkt_hdr); | |
| 1467 | 1467 | usbnet_skb_return(dev, ax_skb); | |
modified drivers/net/veth.c
| @@ -1415,6 +1415,7 @@ static int veth_open(struct net_device *dev) | |||
| 1415 | 1415 | } | |
| 1416 | 1416 | ||
| 1417 | 1417 | veth_set_xdp_features(dev); | |
| 1418 | + | veth_set_xdp_features(peer); | |
| 1418 | 1419 | ||
| 1419 | 1420 | return 0; | |
| 1420 | 1421 | } | |
modified drivers/net/virtio_net.c
| @@ -2515,6 +2515,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue * | |||
| 2515 | 2515 | goto frame_err; | |
| 2516 | 2516 | } | |
| 2517 | 2517 | ||
| 2518 | + | skb->dev = dev; | |
| 2519 | + | skb_set_network_header(skb, ETH_HLEN); | |
| 2518 | 2520 | if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, vi->rx_tnl, | |
| 2519 | 2521 | vi->rx_tnl_csum, | |
| 2520 | 2522 | virtio_is_little_endian(vi->vdev))) { | |
modified drivers/net/wireguard/noise.c
| @@ -784,10 +784,11 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src, | |||
| 784 | 784 | ||
| 785 | 785 | /* Success! Copy everything to peer */ | |
| 786 | 786 | down_write(&handshake->lock); | |
| 787 | - | /* It's important to check that the state is still the same, while we | |
| 788 | - | * have an exclusive lock. | |
| 787 | + | /* Check that the state is the same and that this is still the | |
| 788 | + | * initiation we started with, while we have an exclusive lock. | |
| 789 | 789 | */ | |
| 790 | - | if (handshake->state != state) { | |
| 790 | + | if (handshake->state != state || | |
| 791 | + | crypto_memneq(handshake->ephemeral_private, ephemeral_private, NOISE_PUBLIC_KEY_LEN)) { | |
| 791 | 792 | up_write(&handshake->lock); | |
| 792 | 793 | goto fail; | |
| 793 | 794 | } | |
modified drivers/net/wireguard/queueing.h
| @@ -78,12 +78,14 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating) | |||
| 78 | 78 | u8 l4_hash = skb->l4_hash; | |
| 79 | 79 | u8 sw_hash = skb->sw_hash; | |
| 80 | 80 | u32 hash = skb->hash; | |
| 81 | + | u8 tstamp_type = skb->tstamp_type; | |
| 81 | 82 | skb_scrub_packet(skb, true); | |
| 82 | 83 | memset(&skb->headers, 0, sizeof(skb->headers)); | |
| 83 | 84 | if (encapsulating) { | |
| 84 | 85 | skb->l4_hash = l4_hash; | |
| 85 | 86 | skb->sw_hash = sw_hash; | |
| 86 | 87 | skb->hash = hash; | |
| 88 | + | skb->tstamp_type = tstamp_type; | |
| 87 | 89 | } | |
| 88 | 90 | skb->queue_mapping = 0; | |
| 89 | 91 | skb->nohdr = 0; | |
modified drivers/net/wireless/ath/ath12k/core.c
| @@ -1776,29 +1776,6 @@ int ath12k_core_pre_init(struct ath12k_base *ab) | |||
| 1776 | 1776 | return 0; | |
| 1777 | 1777 | } | |
| 1778 | 1778 | ||
| 1779 | - | static int ath12k_core_panic_handler(struct notifier_block *nb, | |
| 1780 | - | unsigned long action, void *data) | |
| 1781 | - | { | |
| 1782 | - | struct ath12k_base *ab = container_of(nb, struct ath12k_base, | |
| 1783 | - | panic_nb); | |
| 1784 | - | ||
| 1785 | - | return ath12k_hif_panic_handler(ab); | |
| 1786 | - | } | |
| 1787 | - | ||
| 1788 | - | static int ath12k_core_panic_notifier_register(struct ath12k_base *ab) | |
| 1789 | - | { | |
| 1790 | - | ab->panic_nb.notifier_call = ath12k_core_panic_handler; | |
| 1791 | - | ||
| 1792 | - | return atomic_notifier_chain_register(&panic_notifier_list, | |
| 1793 | - | &ab->panic_nb); | |
| 1794 | - | } | |
| 1795 | - | ||
| 1796 | - | static void ath12k_core_panic_notifier_unregister(struct ath12k_base *ab) | |
| 1797 | - | { | |
| 1798 | - | atomic_notifier_chain_unregister(&panic_notifier_list, | |
| 1799 | - | &ab->panic_nb); | |
| 1800 | - | } | |
| 1801 | - | ||
| 1802 | 1779 | static inline | |
| 1803 | 1780 | bool ath12k_core_hw_group_create_ready(struct ath12k_hw_group *ag) | |
| 1804 | 1781 | { | |
| @@ -2214,18 +2191,13 @@ int ath12k_core_init(struct ath12k_base *ab) | |||
| 2214 | 2191 | struct ath12k_hw_group *ag; | |
| 2215 | 2192 | int ret; | |
| 2216 | 2193 | ||
| 2217 | - | ret = ath12k_core_panic_notifier_register(ab); | |
| 2218 | - | if (ret) | |
| 2219 | - | ath12k_warn(ab, "failed to register panic handler: %d\n", ret); | |
| 2220 | - | ||
| 2221 | 2194 | mutex_lock(&ath12k_hw_group_mutex); | |
| 2222 | 2195 | ||
| 2223 | 2196 | ag = ath12k_core_hw_group_assign(ab); | |
| 2224 | 2197 | if (!ag) { | |
| 2225 | 2198 | mutex_unlock(&ath12k_hw_group_mutex); | |
| 2226 | 2199 | ath12k_warn(ab, "unable to get hw group\n"); | |
| 2227 | - | ret = -ENODEV; | |
| 2228 | - | goto err_unregister_notifier; | |
| 2200 | + | return -ENODEV; | |
| 2229 | 2201 | } | |
| 2230 | 2202 | ||
| 2231 | 2203 | mutex_unlock(&ath12k_hw_group_mutex); | |
| @@ -2250,8 +2222,6 @@ int ath12k_core_init(struct ath12k_base *ab) | |||
| 2250 | 2222 | ||
| 2251 | 2223 | err_unassign_hw_group: | |
| 2252 | 2224 | ath12k_core_hw_group_unassign(ab); | |
| 2253 | - | err_unregister_notifier: | |
| 2254 | - | ath12k_core_panic_notifier_unregister(ab); | |
| 2255 | 2225 | ||
| 2256 | 2226 | return ret; | |
| 2257 | 2227 | } | |
| @@ -2260,7 +2230,6 @@ void ath12k_core_deinit(struct ath12k_base *ab) | |||
| 2260 | 2230 | { | |
| 2261 | 2231 | ath12k_core_hw_group_destroy(ab->ag); | |
| 2262 | 2232 | ath12k_core_hw_group_unassign(ab); | |
| 2263 | - | ath12k_core_panic_notifier_unregister(ab); | |
| 2264 | 2233 | } | |
| 2265 | 2234 | ||
| 2266 | 2235 | void ath12k_core_free(struct ath12k_base *ab) | |
modified drivers/net/wireless/ath/ath12k/core.h
| @@ -15,7 +15,6 @@ | |||
| 15 | 15 | #include <linux/ctype.h> | |
| 16 | 16 | #include <linux/firmware.h> | |
| 17 | 17 | #include <linux/of_reserved_mem.h> | |
| 18 | - | #include <linux/panic_notifier.h> | |
| 19 | 18 | #include <linux/average.h> | |
| 20 | 19 | #include <linux/of.h> | |
| 21 | 20 | #include <linux/rhashtable.h> | |
| @@ -1139,8 +1138,6 @@ struct ath12k_base { | |||
| 1139 | 1138 | ||
| 1140 | 1139 | #endif /* CONFIG_ACPI */ | |
| 1141 | 1140 | ||
| 1142 | - | struct notifier_block panic_nb; | |
| 1143 | - | ||
| 1144 | 1141 | struct ath12k_hw_group *ag; | |
| 1145 | 1142 | struct ath12k_wsi_info wsi_info; | |
| 1146 | 1143 | enum ath12k_qmi_firmware_mode fw_mode; | |
modified drivers/net/wireless/ath/ath12k/hif.h
| @@ -30,7 +30,6 @@ struct ath12k_hif_ops { | |||
| 30 | 30 | void (*ce_irq_enable)(struct ath12k_base *ab); | |
| 31 | 31 | void (*ce_irq_disable)(struct ath12k_base *ab); | |
| 32 | 32 | void (*get_ce_msi_idx)(struct ath12k_base *ab, u32 ce_id, u32 *msi_idx); | |
| 33 | - | int (*panic_handler)(struct ath12k_base *ab); | |
| 34 | 33 | void (*coredump_download)(struct ath12k_base *ab); | |
| 35 | 34 | }; | |
| 36 | 35 | ||
| @@ -149,14 +148,6 @@ static inline void ath12k_hif_power_down(struct ath12k_base *ab, bool is_suspend | |||
| 149 | 148 | ab->hif.ops->power_down(ab, is_suspend); | |
| 150 | 149 | } | |
| 151 | 150 | ||
| 152 | - | static inline int ath12k_hif_panic_handler(struct ath12k_base *ab) | |
| 153 | - | { | |
| 154 | - | if (!ab->hif.ops->panic_handler) | |
| 155 | - | return NOTIFY_DONE; | |
| 156 | - | ||
| 157 | - | return ab->hif.ops->panic_handler(ab); | |
| 158 | - | } | |
| 159 | - | ||
| 160 | 151 | static inline void ath12k_hif_coredump_download(struct ath12k_base *ab) | |
| 161 | 152 | { | |
| 162 | 153 | if (ab->hif.ops->coredump_download) | |
modified drivers/net/wireless/ath/ath12k/pci.c
| @@ -1484,13 +1484,6 @@ void ath12k_pci_power_down(struct ath12k_base *ab, bool is_suspend) | |||
| 1484 | 1484 | ath12k_pci_sw_reset(ab_pci->ab, false); | |
| 1485 | 1485 | } | |
| 1486 | 1486 | ||
| 1487 | - | static int ath12k_pci_panic_handler(struct ath12k_base *ab) | |
| 1488 | - | { | |
| 1489 | - | ath12k_pci_sw_reset(ab, false); | |
| 1490 | - | ||
| 1491 | - | return NOTIFY_OK; | |
| 1492 | - | } | |
| 1493 | - | ||
| 1494 | 1487 | static const struct ath12k_hif_ops ath12k_pci_hif_ops = { | |
| 1495 | 1488 | .start = ath12k_pci_start, | |
| 1496 | 1489 | .stop = ath12k_pci_stop, | |
| @@ -1508,7 +1501,6 @@ static const struct ath12k_hif_ops ath12k_pci_hif_ops = { | |||
| 1508 | 1501 | .ce_irq_enable = ath12k_pci_hif_ce_irq_enable, | |
| 1509 | 1502 | .ce_irq_disable = ath12k_pci_hif_ce_irq_disable, | |
| 1510 | 1503 | .get_ce_msi_idx = ath12k_pci_get_ce_msi_idx, | |
| 1511 | - | .panic_handler = ath12k_pci_panic_handler, | |
| 1512 | 1504 | #ifdef CONFIG_ATH12K_COREDUMP | |
| 1513 | 1505 | .coredump_download = ath12k_pci_coredump_download, | |
| 1514 | 1506 | #endif | |
modified drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
| @@ -1489,8 +1489,31 @@ void brcmf_detach(struct device *dev) | |||
| 1489 | 1489 | brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN); | |
| 1490 | 1490 | /* make sure primary interface removed last */ | |
| 1491 | 1491 | for (i = BRCMF_MAX_IFS - 1; i > -1; i--) { | |
| 1492 | - | if (drvr->iflist[i]) | |
| 1493 | - | brcmf_remove_interface(drvr->iflist[i], false); | |
| 1492 | + | struct brcmf_if *ifp = drvr->iflist[i]; | |
| 1493 | + | ||
| 1494 | + | if (!ifp) | |
| 1495 | + | continue; | |
| 1496 | + | ||
| 1497 | + | if (ifp->ndev) { | |
| 1498 | + | brcmf_remove_interface(ifp, false); | |
| 1499 | + | continue; | |
| 1500 | + | } | |
| 1501 | + | ||
| 1502 | + | /* The P2P device interface has no netdev. Its removal can | |
| 1503 | + | * race with NL80211_CMD_DEL_INTERFACE issued by a user space | |
| 1504 | + | * process that is exiting (e.g. wpa_supplicant), which ends | |
| 1505 | + | * in brcmf_p2p_del_vif() under RTNL and the wiphy mutex. If | |
| 1506 | + | * both paths remove the interface, the wdev is unregistered | |
| 1507 | + | * twice and the vif is used after being freed. Take the same | |
| 1508 | + | * locks and re-read iflist, so only one path removes it. | |
| 1509 | + | */ | |
| 1510 | + | rtnl_lock(); | |
| 1511 | + | wiphy_lock(drvr->wiphy); | |
| 1512 | + | ifp = drvr->iflist[i]; | |
| 1513 | + | if (ifp) | |
| 1514 | + | brcmf_remove_interface(ifp, true); | |
| 1515 | + | wiphy_unlock(drvr->wiphy); | |
| 1516 | + | rtnl_unlock(); | |
| 1494 | 1517 | } | |
| 1495 | 1518 | brcmf_bus_stop(drvr->bus_if); | |
| 1496 | 1519 | ||
modified drivers/net/wireless/marvell/libertas/tx.c
| @@ -117,13 +117,6 @@ netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 117 | 117 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) { | |
| 118 | 118 | struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data; | |
| 119 | 119 | ||
| 120 | - | if (skb->len < sizeof(*rtap_hdr) + 4 + ETH_ALEN) { | |
| 121 | - | lbs_deb_tx("tx err: short monitor frame %u\n", skb->len); | |
| 122 | - | dev->stats.tx_dropped++; | |
| 123 | - | dev->stats.tx_errors++; | |
| 124 | - | goto free; | |
| 125 | - | } | |
| 126 | - | ||
| 127 | 120 | /* set txpd fields from the radiotap header */ | |
| 128 | 121 | txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate)); | |
| 129 | 122 | ||
modified drivers/net/wireless/mediatek/mt76/mt76.h
| @@ -1426,6 +1426,13 @@ mtxq_to_txq(struct mt76_txq *mtxq) | |||
| 1426 | 1426 | return container_of(ptr, struct ieee80211_txq, drv_priv); | |
| 1427 | 1427 | } | |
| 1428 | 1428 | ||
| 1429 | + | /* peer-wide state uses the wcid of the primary link */ | |
| 1430 | + | static inline struct mt76_wcid * | |
| 1431 | + | mt76_wcid_primary(struct mt76_wcid *wcid) | |
| 1432 | + | { | |
| 1433 | + | return wcid->def_wcid ? wcid->def_wcid : wcid; | |
| 1434 | + | } | |
| 1435 | + | ||
| 1429 | 1436 | static inline struct ieee80211_sta * | |
| 1430 | 1437 | wcid_to_sta(struct mt76_wcid *wcid) | |
| 1431 | 1438 | { | |
modified drivers/net/wireless/mediatek/mt76/mt7603/init.c
| @@ -230,6 +230,7 @@ mt7603_mac_init(struct mt7603_dev *dev) | |||
| 230 | 230 | ||
| 231 | 231 | eth_broadcast_addr(bc_addr); | |
| 232 | 232 | mt7603_wtbl_init(dev, MT7603_WTBL_RESERVED, -1, bc_addr); | |
| 233 | + | mt76_wcid_init(&dev->global_sta.wcid, 0); | |
| 233 | 234 | dev->global_sta.wcid.idx = MT7603_WTBL_RESERVED; | |
| 234 | 235 | rcu_assign_pointer(dev->mt76.wcid[MT7603_WTBL_RESERVED], | |
| 235 | 236 | &dev->global_sta.wcid); | |
modified drivers/net/wireless/mediatek/mt76/mt7915/init.c
| @@ -1238,6 +1238,12 @@ static void mt7915_unregister_ext_phy(struct mt7915_dev *dev) | |||
| 1238 | 1238 | ||
| 1239 | 1239 | static void mt7915_stop_hardware(struct mt7915_dev *dev) | |
| 1240 | 1240 | { | |
| 1241 | + | int i; | |
| 1242 | + | ||
| 1243 | + | mt76_for_each_q_rx(&dev->mt76, i) { | |
| 1244 | + | if (!mt76_queue_is_wed_rro(&dev->mt76.q_rx[i])) | |
| 1245 | + | napi_disable(&dev->mt76.napi[i]); | |
| 1246 | + | } | |
| 1241 | 1247 | mt7915_mcu_exit(dev); | |
| 1242 | 1248 | mt76_connac2_tx_token_put(&dev->mt76); | |
| 1243 | 1249 | mt7915_dma_cleanup(dev); | |
modified drivers/net/wireless/mediatek/mt76/mt7915/main.c
| @@ -805,6 +805,7 @@ __mt7915_drop_sta(void *ptr, u8 *mac, struct ieee80211_vif *vif) | |||
| 805 | 805 | ||
| 806 | 806 | msta = (struct mt7915_sta *)sta->drv_priv; | |
| 807 | 807 | mt7915_mcu_add_sta(data->dev, vif, sta, CONN_STATE_DISCONNECT, false); | |
| 808 | + | msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET; | |
| 808 | 809 | msta->wcid.sta_disabled = 1; | |
| 809 | 810 | msta->wcid.sta = 0; | |
| 810 | 811 | } | |
| @@ -871,6 +872,7 @@ int mt7915_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, | |||
| 871 | 872 | mutex_unlock(&dev->mt76.mutex); | |
| 872 | 873 | ||
| 873 | 874 | mt7915_mcu_add_sta(dev, vif, sta, CONN_STATE_DISCONNECT, false); | |
| 875 | + | msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET; | |
| 874 | 876 | msta->wcid.sta_disabled = 1; | |
| 875 | 877 | msta->wcid.sta = 0; | |
| 876 | 878 | return 0; | |
modified drivers/net/wireless/mediatek/mt76/mt7925/mac.c
| @@ -798,7 +798,8 @@ mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi, | |||
| 798 | 798 | val = FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) | | |
| 799 | 799 | FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx); | |
| 800 | 800 | ||
| 801 | - | if (band_idx) | |
| 801 | + | /* 0xff means BAND_AUTO to the firmware, and TGID cannot encode it */ | |
| 802 | + | if (band_idx && band_idx != 0xff) | |
| 802 | 803 | val |= FIELD_PREP(MT_TXD1_TGID, band_idx); | |
| 803 | 804 | ||
| 804 | 805 | txwi[1] = cpu_to_le32(val); | |
modified drivers/net/wireless/mediatek/mt76/mt7925/main.c
| @@ -2294,6 +2294,18 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |||
| 2294 | 2294 | ||
| 2295 | 2295 | mvif->valid_links = new_links; | |
| 2296 | 2296 | ||
| 2297 | + | /* Restore the legacy BSS after disabling MLO */ | |
| 2298 | + | if (old_links && !new_links) { | |
| 2299 | + | mt792x_mac_link_bss_remove(dev, &mvif->bss_conf, | |
| 2300 | + | &mvif->sta.deflink); | |
| 2301 | + | err = mt7925_mac_link_bss_add(dev, &vif->bss_conf, | |
| 2302 | + | &mvif->sta.deflink); | |
| 2303 | + | if (err < 0) { | |
| 2304 | + | mt792x_mutex_release(dev); | |
| 2305 | + | return err; | |
| 2306 | + | } | |
| 2307 | + | } | |
| 2308 | + | ||
| 2297 | 2309 | mt792x_mutex_release(dev); | |
| 2298 | 2310 | ||
| 2299 | 2311 | return 0; | |
modified drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
| @@ -108,68 +108,98 @@ mt792x_asar_acpi_read_mtcl(struct mt792x_dev *dev, u8 **table, u8 *version) | |||
| 108 | 108 | return ret; | |
| 109 | 109 | } | |
| 110 | 110 | ||
| 111 | + | /* A table's layout is decided by the version byte in MTCL, but some firmware | |
| 112 | + | * labels a version 2 table as version 1. Accept whichever layout the table | |
| 113 | + | * actually has: for every accepted entry count the two do not overlap, since | |
| 114 | + | * one is 6 + 5n bytes and the other 7 + 7n. | |
| 115 | + | */ | |
| 116 | + | static bool | |
| 117 | + | mt792x_asar_fits(u8 *table, int len, int prelen, int sarlen, int nr_off, | |
| 118 | + | int min, int max) | |
| 119 | + | { | |
| 120 | + | int tblcnt; | |
| 121 | + | ||
| 122 | + | if (len < prelen || (len - prelen) % sarlen) | |
| 123 | + | return false; | |
| 124 | + | ||
| 125 | + | tblcnt = (len - prelen) / sarlen; | |
| 126 | + | if (tblcnt < min || tblcnt > max) | |
| 127 | + | return false; | |
| 128 | + | ||
| 129 | + | return tblcnt == table[nr_off]; | |
| 130 | + | } | |
| 131 | + | ||
| 111 | 132 | /* MTDS : Dynamic SAR Power Table */ | |
| 112 | 133 | static int | |
| 113 | - | mt792x_asar_acpi_read_mtds(struct mt792x_dev *dev, u8 **table, u8 version) | |
| 134 | + | mt792x_asar_acpi_read_mtds(struct mt792x_dev *dev, u8 **table, u8 version, | |
| 135 | + | u8 *used) | |
| 114 | 136 | { | |
| 115 | - | int len, ret, sarlen, prelen, tblcnt; | |
| 116 | - | bool enable; | |
| 137 | + | int len, ret; | |
| 138 | + | u8 *t; | |
| 117 | 139 | ||
| 118 | 140 | ret = mt792x_acpi_read(dev, MT792x_ACPI_MTDS, table, &len); | |
| 119 | 141 | if (ret) | |
| 120 | 142 | return ret; | |
| 121 | 143 | ||
| 144 | + | t = *table; | |
| 145 | + | ||
| 122 | 146 | /* Table content validation */ | |
| 123 | - | switch (version) { | |
| 124 | - | case 1: | |
| 125 | - | enable = ((struct mt792x_asar_dyn *)*table)->enable; | |
| 126 | - | sarlen = sizeof(struct mt792x_asar_dyn_limit); | |
| 127 | - | prelen = sizeof(struct mt792x_asar_dyn); | |
| 128 | - | break; | |
| 129 | - | case 2: | |
| 130 | - | enable = ((struct mt792x_asar_dyn_v2 *)*table)->enable; | |
| 131 | - | sarlen = sizeof(struct mt792x_asar_dyn_limit_v2); | |
| 132 | - | prelen = sizeof(struct mt792x_asar_dyn_v2); | |
| 133 | - | break; | |
| 134 | - | default: | |
| 147 | + | if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_dyn), | |
| 148 | + | sizeof(struct mt792x_asar_dyn_limit), | |
| 149 | + | offsetof(struct mt792x_asar_dyn, nr_tbl), | |
| 150 | + | MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN)) | |
| 151 | + | *used = 1; | |
| 152 | + | else if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_dyn_v2), | |
| 153 | + | sizeof(struct mt792x_asar_dyn_limit_v2), | |
| 154 | + | offsetof(struct mt792x_asar_dyn_v2, nr_tbl), | |
| 155 | + | MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN)) | |
| 156 | + | *used = 2; | |
| 157 | + | else | |
| 135 | 158 | return -EINVAL; | |
| 136 | - | } | |
| 137 | 159 | ||
| 138 | - | tblcnt = (len - prelen) / sarlen; | |
| 139 | - | if (!enable || | |
| 140 | - | tblcnt > MT792x_ASAR_MAX_DYN || tblcnt < MT792x_ASAR_MIN_DYN) | |
| 160 | + | if (!t[offsetof(struct mt792x_asar_dyn, enable)]) | |
| 141 | 161 | return -EINVAL; | |
| 142 | 162 | ||
| 163 | + | if (version && *used != version) | |
| 164 | + | dev_info(dev->mt76.dev, | |
| 165 | + | "MTDS is v%u, MTCL says v%u; using v%u\n", | |
| 166 | + | *used, version, *used); | |
| 167 | + | ||
| 143 | 168 | return 0; | |
| 144 | 169 | } | |
| 145 | 170 | ||
| 146 | 171 | /* MTGS : Geo SAR Power Table */ | |
| 147 | 172 | static int | |
| 148 | - | mt792x_asar_acpi_read_mtgs(struct mt792x_dev *dev, u8 **table, u8 version) | |
| 173 | + | mt792x_asar_acpi_read_mtgs(struct mt792x_dev *dev, u8 **table, u8 version, | |
| 174 | + | u8 *used) | |
| 149 | 175 | { | |
| 150 | - | int len, ret, sarlen, prelen, tblcnt; | |
| 176 | + | int len, ret; | |
| 177 | + | u8 *t; | |
| 151 | 178 | ||
| 152 | 179 | ret = mt792x_acpi_read(dev, MT792x_ACPI_MTGS, table, &len); | |
| 153 | 180 | if (ret) | |
| 154 | 181 | return ret; | |
| 155 | 182 | ||
| 183 | + | t = *table; | |
| 184 | + | ||
| 156 | 185 | /* Table content validation */ | |
| 157 | - | switch (version) { | |
| 158 | - | case 1: | |
| 159 | - | sarlen = sizeof(struct mt792x_asar_geo_limit); | |
| 160 | - | prelen = sizeof(struct mt792x_asar_geo); | |
| 161 | - | break; | |
| 162 | - | case 2: | |
| 163 | - | sarlen = sizeof(struct mt792x_asar_geo_limit_v2); | |
| 164 | - | prelen = sizeof(struct mt792x_asar_geo_v2); | |
| 165 | - | break; | |
| 166 | - | default: | |
| 186 | + | if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_geo), | |
| 187 | + | sizeof(struct mt792x_asar_geo_limit), | |
| 188 | + | offsetof(struct mt792x_asar_geo, nr_tbl), | |
| 189 | + | MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO)) | |
| 190 | + | *used = 1; | |
| 191 | + | else if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_geo_v2), | |
| 192 | + | sizeof(struct mt792x_asar_geo_limit_v2), | |
| 193 | + | offsetof(struct mt792x_asar_geo_v2, nr_tbl), | |
| 194 | + | MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO)) | |
| 195 | + | *used = 2; | |
| 196 | + | else | |
| 167 | 197 | return -EINVAL; | |
| 168 | - | } | |
| 169 | 198 | ||
| 170 | - | tblcnt = (len - prelen) / sarlen; | |
| 171 | - | if (tblcnt > MT792x_ASAR_MAX_GEO || tblcnt < MT792x_ASAR_MIN_GEO) | |
| 172 | - | return -EINVAL; | |
| 199 | + | if (version && *used != version) | |
| 200 | + | dev_info(dev->mt76.dev, | |
| 201 | + | "MTGS is v%u, MTCL says v%u; using v%u\n", | |
| 202 | + | *used, version, *used); | |
| 173 | 203 | ||
| 174 | 204 | return 0; | |
| 175 | 205 | } | |
| @@ -205,14 +235,16 @@ int mt792x_init_acpi_sar(struct mt792x_dev *dev) | |||
| 205 | 235 | asar->countrylist = NULL; | |
| 206 | 236 | } | |
| 207 | 237 | ||
| 208 | - | ret = mt792x_asar_acpi_read_mtds(dev, (u8 **)&asar->dyn, asar->ver); | |
| 238 | + | ret = mt792x_asar_acpi_read_mtds(dev, (u8 **)&asar->dyn, asar->ver, | |
| 239 | + | &asar->dyn_ver); | |
| 209 | 240 | if (ret) { | |
| 210 | 241 | devm_kfree(dev->mt76.dev, asar->dyn); | |
| 211 | 242 | asar->dyn = NULL; | |
| 212 | 243 | } | |
| 213 | 244 | ||
| 214 | 245 | /* MTGS is optional */ | |
| 215 | - | ret = mt792x_asar_acpi_read_mtgs(dev, (u8 **)&asar->geo, asar->ver); | |
| 246 | + | ret = mt792x_asar_acpi_read_mtgs(dev, (u8 **)&asar->geo, asar->ver, | |
| 247 | + | &asar->geo_ver); | |
| 216 | 248 | if (ret) { | |
| 217 | 249 | devm_kfree(dev->mt76.dev, asar->geo); | |
| 218 | 250 | asar->geo = NULL; | |
| @@ -254,7 +286,7 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy, | |||
| 254 | 286 | break; | |
| 255 | 287 | } | |
| 256 | 288 | ||
| 257 | - | if (asar->ver == 1) { | |
| 289 | + | if (asar->geo_ver == 1) { | |
| 258 | 290 | band_pwr = &asar->geo->tbl[idx].band[0]; | |
| 259 | 291 | max = ARRAY_SIZE(asar->geo->tbl[idx].band); | |
| 260 | 292 | } else { | |
| @@ -279,10 +311,18 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy, | |||
| 279 | 311 | if (idx >= max) | |
| 280 | 312 | return dyn_power; | |
| 281 | 313 | ||
| 282 | - | geo_power = (band_pwr + idx)->pwr; | |
| 283 | - | dyn_power += (band_pwr + idx)->offset; | |
| 314 | + | band_pwr += idx; | |
| 315 | + | ||
| 316 | + | /* Some OEM tables carry 0xff here; narrowed to s8 that is -1 and | |
| 317 | + | * wins the min() below. Take it as no limit. | |
| 318 | + | */ | |
| 319 | + | if (band_pwr->pwr == 0xff) | |
| 320 | + | return dyn_power; | |
| 321 | + | ||
| 322 | + | geo_power = band_pwr->pwr; | |
| 284 | 323 | ||
| 285 | - | return min(geo_power, dyn_power); | |
| 324 | + | return min_t(int, geo_power, | |
| 325 | + | min_t(int, dyn_power + band_pwr->offset, 127)); | |
| 286 | 326 | } | |
| 287 | 327 | ||
| 288 | 328 | static s8 | |
| @@ -297,7 +337,7 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy, | |||
| 297 | 337 | if (!capa) | |
| 298 | 338 | return 127; | |
| 299 | 339 | ||
| 300 | - | if (asar->ver == 1) { | |
| 340 | + | if (asar->dyn_ver == 1) { | |
| 301 | 341 | limit = &asar->dyn->tbl[0].frp[0]; | |
| 302 | 342 | max = ARRAY_SIZE(asar->dyn->tbl[0].frp); | |
| 303 | 343 | } else { | |
| @@ -315,7 +355,9 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy, | |||
| 315 | 355 | else | |
| 316 | 356 | band = NL80211_BAND_2GHZ; | |
| 317 | 357 | ||
| 318 | - | return mt792x_asar_get_geo_pwr(phy, band, limit[idx]); | |
| 358 | + | /* 0xff: no dynamic limit, see mt792x_asar_get_geo_pwr() */ | |
| 359 | + | return mt792x_asar_get_geo_pwr(phy, band, | |
| 360 | + | limit[idx] == 0xff ? 127 : limit[idx]); | |
| 319 | 361 | } | |
| 320 | 362 | ||
| 321 | 363 | int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default) | |
modified drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h
| @@ -105,6 +105,8 @@ struct mt792x_asar_fg { | |||
| 105 | 105 | ||
| 106 | 106 | struct mt792x_acpi_sar { | |
| 107 | 107 | u8 ver; | |
| 108 | + | u8 dyn_ver; | |
| 109 | + | u8 geo_ver; | |
| 108 | 110 | union { | |
| 109 | 111 | struct mt792x_asar_dyn *dyn; | |
| 110 | 112 | struct mt792x_asar_dyn_v2 *dyn_v2; | |
modified drivers/net/wireless/mediatek/mt76/mt7996/init.c
| @@ -540,6 +540,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed) | |||
| 540 | 540 | ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR); | |
| 541 | 541 | ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); | |
| 542 | 542 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); | |
| 543 | + | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
| 543 | 544 | ||
| 544 | 545 | hw->max_tx_fragments = 4; | |
| 545 | 546 | wiphy->txq_memory_limit = 32 << 20; /* 32 MiB */ | |
| @@ -1247,7 +1248,7 @@ static int mt7996_variant_fem_init(struct mt7996_dev *dev) | |||
| 1247 | 1248 | adie_ver = u32_get_bits(regval, MT_ADIE_VERSION_MASK); | |
| 1248 | 1249 | idx = MT7976C_EFUSE_OFFSET % MT7996_EEPROM_BLOCK_SIZE; | |
| 1249 | 1250 | is_7976c = adie_ver == 0x8a10 || adie_ver == 0x8b00 || | |
| 1250 | - | adie_ver == 0x8c10 || buf[idx] == 0xc; | |
| 1251 | + | adie_ver == 0x8c10 || (!ret && buf[idx] == 0xc); | |
| 1251 | 1252 | ||
| 1252 | 1253 | adie_id = u32_get_bits(regval, MT_ADIE_CHIP_ID_MASK); | |
| 1253 | 1254 | if (adie_id == 0x7975 || adie_id == 0x7979 || | |
modified drivers/net/wireless/mediatek/mt76/mt7996/main.c
| @@ -310,7 +310,14 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif, | |||
| 310 | 310 | if (vif->type == NL80211_IFTYPE_AP) | |
| 311 | 311 | return mt7996_mcu_mld_link_oper(dev, link_conf, link, | |
| 312 | 312 | true); | |
| 313 | - | return 0; | |
| 313 | + | ||
| 314 | + | /* update the link address */ | |
| 315 | + | ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true); | |
| 316 | + | if (ret) | |
| 317 | + | return ret; | |
| 318 | + | ||
| 319 | + | return mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink, | |
| 320 | + | msta_link, true); | |
| 314 | 321 | } | |
| 315 | 322 | ||
| 316 | 323 | mlink->idx = __ffs64(~dev->mt76.vif_mask); | |
| @@ -1426,6 +1433,7 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif, | |||
| 1426 | 1433 | else if (sta->mlo && links == BIT(link_id)) /* last link */ | |
| 1427 | 1434 | mt7996_mcu_teardown_mld_sta(dev, link, | |
| 1428 | 1435 | msta_link); | |
| 1436 | + | msta_link->wcid.tx_info &= ~MT_WCID_TX_INFO_SET; | |
| 1429 | 1437 | msta_link->wcid.sta_disabled = 1; | |
| 1430 | 1438 | msta_link->wcid.sta = 0; | |
| 1431 | 1439 | links = links & ~BIT(link_id); | |
modified drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
| @@ -284,6 +284,9 @@ struct mt7996_mcu_wed_rro_ba_delete_event { | |||
| 284 | 284 | __le16 len; | |
| 285 | 285 | ||
| 286 | 286 | __le16 session_id; | |
| 287 | + | __le16 wlan_id; | |
| 288 | + | u8 tid; | |
| 289 | + | u8 __rsv1; | |
| 287 | 290 | u8 __rsv2[2]; | |
| 288 | 291 | } __packed; | |
| 289 | 292 | ||
modified drivers/net/wireless/mediatek/mt76/tx.c
| @@ -234,6 +234,8 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid, | |||
| 234 | 234 | if (!wcid || info->tx_time_est) | |
| 235 | 235 | return; | |
| 236 | 236 | ||
| 237 | + | wcid = mt76_wcid_primary(wcid); | |
| 238 | + | ||
| 237 | 239 | pending = atomic_dec_return(&wcid->non_aql_packets); | |
| 238 | 240 | if (pending < 0) | |
| 239 | 241 | atomic_cmpxchg(&wcid->non_aql_packets, pending, 0); | |
| @@ -344,7 +346,8 @@ __mt76_tx_queue_skb(struct mt76_phy *phy, int qid, struct sk_buff *skb, | |||
| 344 | 346 | if (!non_aql) | |
| 345 | 347 | return idx; | |
| 346 | 348 | ||
| 347 | - | pending = atomic_inc_return(&wcid->non_aql_packets); | |
| 349 | + | /* the hardware can report the completion on a different link */ | |
| 350 | + | pending = atomic_inc_return(&mt76_wcid_primary(wcid)->non_aql_packets); | |
| 348 | 351 | if (stop && pending >= MT_MAX_NON_AQL_PKT) | |
| 349 | 352 | *stop = true; | |
| 350 | 353 | ||
| @@ -506,7 +509,8 @@ mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q, | |||
| 506 | 509 | return 0; | |
| 507 | 510 | } | |
| 508 | 511 | ||
| 509 | - | if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT) | |
| 512 | + | if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >= | |
| 513 | + | MT_MAX_NON_AQL_PKT) | |
| 510 | 514 | return 0; | |
| 511 | 515 | ||
| 512 | 516 | skb = mt76_txq_dequeue(phy, mtxq); | |
| @@ -603,7 +607,8 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid) | |||
| 603 | 607 | continue; | |
| 604 | 608 | } | |
| 605 | 609 | ||
| 606 | - | if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT) | |
| 610 | + | if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >= | |
| 611 | + | MT_MAX_NON_AQL_PKT) | |
| 607 | 612 | continue; | |
| 608 | 613 | if (dev->queue_ops->tx_cleanup && | |
| 609 | 614 | q->queued + 2 * MT_TXQ_FREE_THR >= q->ndesc) { | |
| @@ -675,7 +680,8 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid, | |||
| 675 | 680 | if ((dev->drv->drv_flags & MT_DRV_HW_MGMT_TXQ) && | |
| 676 | 681 | !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && | |
| 677 | 682 | !ieee80211_is_data_present(hdr->frame_control) && | |
| 678 | - | (!ieee80211_is_bufferable_mmpdu(skb) || | |
| 683 | + | (!(wcid->tx_info & MT_WCID_TX_INFO_SET) || | |
| 684 | + | !ieee80211_is_bufferable_mmpdu(skb) || | |
| 679 | 685 | ieee80211_is_deauth(hdr->frame_control) || | |
| 680 | 686 | ieee80211_is_disassoc(hdr->frame_control) || | |
| 681 | 687 | head == &wcid->tx_offchannel)) | |
modified drivers/net/wireless/nxp/nxpwifi/11n.c
| @@ -451,7 +451,7 @@ void | |||
| 451 | 451 | nxpwifi_11n_delete_tx_ba_stream_tbl_entry(struct nxpwifi_private *priv, | |
| 452 | 452 | struct nxpwifi_tx_ba_stream_tbl *tbl) | |
| 453 | 453 | { | |
| 454 | - | if (!tbl || nxpwifi_is_tx_ba_stream_ptr_valid(priv, tbl)) | |
| 454 | + | if (!tbl || !nxpwifi_is_tx_ba_stream_ptr_valid(priv, tbl)) | |
| 455 | 455 | return; | |
| 456 | 456 | ||
| 457 | 457 | nxpwifi_dbg(priv->adapter, INFO, | |
modified drivers/net/wireless/nxp/nxpwifi/11n_aggr.c
| @@ -168,6 +168,7 @@ nxpwifi_11n_aggregate_pkt(struct nxpwifi_private *priv, | |||
| 168 | 168 | ||
| 169 | 169 | if (!nxpwifi_is_ralist_valid(priv, pra_list, ptrindex)) { | |
| 170 | 170 | spin_unlock_bh(&priv->wmm.ra_list_spinlock); | |
| 171 | + | nxpwifi_write_data_complete(adapter, skb_aggr, 1, -1); | |
| 171 | 172 | return -ENOENT; | |
| 172 | 173 | } | |
| 173 | 174 | ||
modified drivers/net/wireless/nxp/nxpwifi/11n_rxreorder.c
| @@ -205,11 +205,12 @@ void nxpwifi_11n_del_rx_reorder_tbl_by_ta(struct nxpwifi_private *priv, u8 *ta) | |||
| 205 | 205 | return; | |
| 206 | 206 | ||
| 207 | 207 | for (i = 0; i < MAX_NUM_TID; i++) { | |
| 208 | - | guard(rcu)(); | |
| 209 | - | list_for_each_entry_rcu(tbl, &priv->rx_reorder_tbl_ptr[i], list) { | |
| 210 | - | if (!memcmp(tbl->ta, ta, ETH_ALEN)) { | |
| 211 | - | INIT_LIST_HEAD(&tbl->tmp_list); | |
| 212 | - | list_add_tail(&tbl->tmp_list, &to_delete); | |
| 208 | + | scoped_guard(rcu) { | |
| 209 | + | list_for_each_entry_rcu(tbl, &priv->rx_reorder_tbl_ptr[i], list) { | |
| 210 | + | if (!memcmp(tbl->ta, ta, ETH_ALEN)) { | |
| 211 | + | INIT_LIST_HEAD(&tbl->tmp_list); | |
| 212 | + | list_add_tail(&tbl->tmp_list, &to_delete); | |
| 213 | + | } | |
| 213 | 214 | } | |
| 214 | 215 | } | |
| 215 | 216 | ||
modified drivers/net/wireless/nxp/nxpwifi/cfg80211.c
| @@ -1539,9 +1539,11 @@ nxpwifi_cfg80211_del_station(struct wiphy *wiphy, struct wireless_dev *wdev, | |||
| 1539 | 1539 | ||
| 1540 | 1540 | eth_zero_addr(deauth_mac); | |
| 1541 | 1541 | ||
| 1542 | + | rcu_read_lock(); | |
| 1542 | 1543 | sta_node = nxpwifi_get_sta_entry(priv, params->mac); | |
| 1543 | 1544 | if (sta_node) | |
| 1544 | 1545 | ether_addr_copy(deauth_mac, params->mac); | |
| 1546 | + | rcu_read_unlock(); | |
| 1545 | 1547 | ||
| 1546 | 1548 | if (is_valid_ether_addr(deauth_mac)) { | |
| 1547 | 1549 | ret = nxpwifi_uap_sta_deauth(priv, deauth_mac); | |
| @@ -3323,6 +3325,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy, | |||
| 3323 | 3325 | struct nxpwifi_adapter *adapter = priv->adapter; | |
| 3324 | 3326 | struct sk_buff *skb; | |
| 3325 | 3327 | u16 pkt_len, auth_alg; | |
| 3328 | + | size_t frame_len; | |
| 3326 | 3329 | int ret; | |
| 3327 | 3330 | struct ieee80211_mgmt *mgmt; | |
| 3328 | 3331 | struct nxpwifi_txinfo *tx_info; | |
| @@ -3396,13 +3399,25 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy, | |||
| 3396 | 3399 | ||
| 3397 | 3400 | nxpwifi_cancel_scan(adapter); | |
| 3398 | 3401 | ||
| 3399 | - | pkt_len = (u16)req->ie_len + req->auth_data_len + | |
| 3400 | - | NXPWIFI_MGMT_HEADER_LEN + NXPWIFI_AUTH_BODY_LEN; | |
| 3402 | + | frame_len = req->ie_len + req->auth_data_len + | |
| 3403 | + | sizeof(struct ieee80211_hdr_3addr) + NXPWIFI_AUTH_BODY_LEN; | |
| 3401 | 3404 | ||
| 3402 | 3405 | if (req->auth_data_len >= 4) | |
| 3403 | - | pkt_len -= 4; | |
| 3406 | + | frame_len -= 4; | |
| 3407 | + | ||
| 3408 | + | /* nxpwifi_form_mgmt_frame() inserts address4, so the frame handed to | |
| 3409 | + | * the firmware is ETH_ALEN longer than the one built here. | |
| 3410 | + | */ | |
| 3411 | + | if (frame_len > U16_MAX - ETH_ALEN) { | |
| 3412 | + | nxpwifi_dbg(adapter, ERROR, | |
| 3413 | + | "auth frame too long: %zu bytes\n", frame_len); | |
| 3414 | + | return -EINVAL; | |
| 3415 | + | } | |
| 3416 | + | pkt_len = frame_len + ETH_ALEN; | |
| 3404 | 3417 | ||
| 3405 | - | mgmt = kzalloc(pkt_len, GFP_KERNEL); | |
| 3418 | + | mgmt = kzalloc(frame_len, GFP_KERNEL); | |
| 3419 | + | if (!mgmt) | |
| 3420 | + | return -ENOMEM; | |
| 3406 | 3421 | ||
| 3407 | 3422 | skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN + | |
| 3408 | 3423 | NXPWIFI_MGMT_FRAME_HEADER_SIZE + | |
| @@ -3410,6 +3425,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy, | |||
| 3410 | 3425 | if (!skb) { | |
| 3411 | 3426 | nxpwifi_dbg(adapter, ERROR, | |
| 3412 | 3427 | "allocate skb failed for management frame\n"); | |
| 3428 | + | kfree(mgmt); | |
| 3413 | 3429 | return -ENOMEM; | |
| 3414 | 3430 | } | |
| 3415 | 3431 | ||
| @@ -3448,7 +3464,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy, | |||
| 3448 | 3464 | memcpy((u8 *)varptr, req->ie, req->ie_len); | |
| 3449 | 3465 | } | |
| 3450 | 3466 | ||
| 3451 | - | nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, pkt_len); | |
| 3467 | + | nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, frame_len); | |
| 3452 | 3468 | kfree(mgmt); | |
| 3453 | 3469 | priv->auth_flag = HOST_MLME_AUTH_PENDING; | |
| 3454 | 3470 | priv->auth_alg = auth_alg; | |
| @@ -3729,8 +3745,9 @@ int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter) | |||
| 3729 | 3745 | * additional active scan request for hidden SSIDs on passive channels. | |
| 3730 | 3746 | */ | |
| 3731 | 3747 | adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a); | |
| 3732 | - | adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats), | |
| 3733 | - | adapter->num_in_chan_stats)); | |
| 3748 | + | adapter->chan_stats = kcalloc(adapter->num_in_chan_stats, | |
| 3749 | + | sizeof(*adapter->chan_stats), | |
| 3750 | + | GFP_KERNEL); | |
| 3734 | 3751 | ||
| 3735 | 3752 | if (!adapter->chan_stats) | |
| 3736 | 3753 | return -ENOMEM; | |
modified drivers/net/wireless/nxp/nxpwifi/init.c
| @@ -328,7 +328,7 @@ static void nxpwifi_invalidate_lists(struct nxpwifi_adapter *adapter) | |||
| 328 | 328 | static void | |
| 329 | 329 | nxpwifi_adapter_cleanup(struct nxpwifi_adapter *adapter) | |
| 330 | 330 | { | |
| 331 | - | timer_delete(&adapter->wakeup_timer); | |
| 331 | + | timer_delete_sync(&adapter->wakeup_timer); | |
| 332 | 332 | nxpwifi_cancel_all_pending_cmd(adapter); | |
| 333 | 333 | wake_up_interruptible(&adapter->cmd_wait_q.wait); | |
| 334 | 334 | wake_up_interruptible(&adapter->hs_activate_wait_q); | |
modified drivers/net/wireless/nxp/nxpwifi/main.c
| @@ -644,7 +644,7 @@ static int _nxpwifi_fw_dpc(const struct firmware *firmware, void *context) | |||
| 644 | 644 | goto done; | |
| 645 | 645 | ||
| 646 | 646 | err_add_intf: | |
| 647 | - | vfree(adapter->chan_stats); | |
| 647 | + | kfree(adapter->chan_stats); | |
| 648 | 648 | err_init_chan_scan: | |
| 649 | 649 | wiphy_unregister(adapter->wiphy); | |
| 650 | 650 | wiphy_free(adapter->wiphy); | |
| @@ -1384,7 +1384,7 @@ static void nxpwifi_uninit_sw(struct nxpwifi_adapter *adapter) | |||
| 1384 | 1384 | wiphy_free(adapter->wiphy); | |
| 1385 | 1385 | adapter->wiphy = NULL; | |
| 1386 | 1386 | ||
| 1387 | - | vfree(adapter->chan_stats); | |
| 1387 | + | kfree(adapter->chan_stats); | |
| 1388 | 1388 | nxpwifi_free_cmd_buffers(adapter); | |
| 1389 | 1389 | } | |
| 1390 | 1390 | ||
modified drivers/net/wireless/nxp/nxpwifi/uap_event.c
| @@ -75,6 +75,7 @@ nxpwifi_uap_event_sta_deauth(struct nxpwifi_private *priv) | |||
| 75 | 75 | nxpwifi_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac); | |
| 76 | 76 | } | |
| 77 | 77 | nxpwifi_wmm_del_peer_ra_list(priv, deauth_mac); | |
| 78 | + | nxpwifi_del_sta_entry(priv, deauth_mac); | |
| 78 | 79 | ||
| 79 | 80 | return 0; | |
| 80 | 81 | } | |
modified drivers/net/wireless/nxp/nxpwifi/util.c
| @@ -1041,19 +1041,23 @@ nxpwifi_set_sta_ht_cap(struct nxpwifi_private *priv, const u8 *ies, | |||
| 1041 | 1041 | } | |
| 1042 | 1042 | } | |
| 1043 | 1043 | ||
| 1044 | - | /* Delete a station from list; called under cfg80211 mutex. */ | |
| 1044 | + | /* Delete a station from list. */ | |
| 1045 | 1045 | ||
| 1046 | 1046 | void nxpwifi_del_sta_entry(struct nxpwifi_private *priv, const u8 *mac) | |
| 1047 | 1047 | { | |
| 1048 | 1048 | struct nxpwifi_sta_node *node; | |
| 1049 | 1049 | ||
| 1050 | - | list_for_each_entry_rcu(node, &priv->sta_list, list) { | |
| 1050 | + | spin_lock_bh(&priv->sta_list_spinlock); | |
| 1051 | + | ||
| 1052 | + | list_for_each_entry(node, &priv->sta_list, list) { | |
| 1051 | 1053 | if (!memcmp(node->mac_addr, mac, ETH_ALEN)) { | |
| 1052 | 1054 | list_del_rcu(&node->list); | |
| 1053 | 1055 | kfree_rcu(node, rcu); | |
| 1054 | 1056 | break; | |
| 1055 | 1057 | } | |
| 1056 | 1058 | } | |
| 1059 | + | ||
| 1060 | + | spin_unlock_bh(&priv->sta_list_spinlock); | |
| 1057 | 1061 | } | |
| 1058 | 1062 | ||
| 1059 | 1063 | /* Delete all stations from list. */ | |
modified drivers/net/xen-netfront.c
| @@ -1234,8 +1234,16 @@ static int handle_incoming_queue(struct netfront_queue *queue, | |||
| 1234 | 1234 | while ((skb = __skb_dequeue(rxq)) != NULL) { | |
| 1235 | 1235 | int pull_to = NETFRONT_SKB_CB(skb)->pull_to; | |
| 1236 | 1236 | ||
| 1237 | - | if (pull_to > skb_headlen(skb)) | |
| 1238 | - | __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); | |
| 1237 | + | /* pull_to comes from the first slot's length, which the | |
| 1238 | + | * backend controls. Make sure the head holds at least an | |
| 1239 | + | * Ethernet header for eth_type_trans(). | |
| 1240 | + | */ | |
| 1241 | + | if (!pskb_may_pull(skb, max(pull_to, ETH_HLEN))) { | |
| 1242 | + | kfree_skb(skb); | |
| 1243 | + | packets_dropped++; | |
| 1244 | + | queue->info->netdev->stats.rx_errors++; | |
| 1245 | + | continue; | |
| 1246 | + | } | |
| 1239 | 1247 | ||
| 1240 | 1248 | /* Ethernet work: Delayed to here as it peeks the header. */ | |
| 1241 | 1249 | skb->protocol = eth_type_trans(skb, queue->info->netdev); | |
| @@ -1338,8 +1346,10 @@ err: | |||
| 1338 | 1346 | skb->data_len = rx->status; | |
| 1339 | 1347 | skb->len += rx->status; | |
| 1340 | 1348 | ||
| 1341 | - | if (unlikely(xennet_fill_frags(queue, skb, &tmpq))) | |
| 1349 | + | if (unlikely(xennet_fill_frags(queue, skb, &tmpq))) { | |
| 1350 | + | __skb_queue_head(&tmpq, skb); | |
| 1342 | 1351 | goto err; | |
| 1352 | + | } | |
| 1343 | 1353 | ||
| 1344 | 1354 | if (rx->flags & XEN_NETRXF_csum_blank) | |
| 1345 | 1355 | skb->ip_summed = CHECKSUM_PARTIAL; | |
modified drivers/nvme/host/core.c
| @@ -598,6 +598,7 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, | |||
| 598 | 598 | break; | |
| 599 | 599 | case NVME_CTRL_RESETTING: | |
| 600 | 600 | switch (old_state) { | |
| 601 | + | case NVME_CTRL_NEW: | |
| 601 | 602 | case NVME_CTRL_LIVE: | |
| 602 | 603 | changed = true; | |
| 603 | 604 | atomic_long_inc(&ctrl->nr_reset); | |
| @@ -2616,10 +2617,19 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info) | |||
| 2616 | 2617 | set_capacity_and_notify(ns->head->disk, get_capacity(ns->disk)); | |
| 2617 | 2618 | set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); | |
| 2618 | 2619 | nvme_mpath_revalidate_paths(ns->head); | |
| 2619 | - | ret = nvme_mpath_revalidate_zones(ns->head); | |
| 2620 | 2620 | ||
| 2621 | 2621 | unfreeze_head_queue: | |
| 2622 | 2622 | blk_mq_unfreeze_queue(ns->head->disk->queue, memflags); | |
| 2623 | + | ||
| 2624 | + | /* | |
| 2625 | + | * Wait until the head queue is unfrozen before revalidating | |
| 2626 | + | * its zones. blk_revalidate_disk_zones() takes the queue limits | |
| 2627 | + | * lock and then freezes the queue on its own, so it must not be | |
| 2628 | + | * called with the queue already frozen. This is also what | |
| 2629 | + | * nvme_update_ns_info_block() does for ns->disk. | |
| 2630 | + | */ | |
| 2631 | + | if (!ret) | |
| 2632 | + | ret = nvme_mpath_revalidate_zones(ns->head); | |
| 2623 | 2633 | } | |
| 2624 | 2634 | ||
| 2625 | 2635 | return ret; | |
modified drivers/nvme/target/core.c
| @@ -1325,7 +1325,7 @@ static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev, | |||
| 1325 | 1325 | ||
| 1326 | 1326 | return 0; | |
| 1327 | 1327 | out_free_sg: | |
| 1328 | - | pci_p2pmem_free_sgl(req->p2p_dev, req->sg); | |
| 1328 | + | pci_p2pmem_free_sgl(p2p_dev, req->sg); | |
| 1329 | 1329 | out_err: | |
| 1330 | 1330 | return -ENOMEM; | |
| 1331 | 1331 | } | |
modified drivers/nvme/target/pr.c
| @@ -51,6 +51,8 @@ u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask) | |||
| 51 | 51 | ||
| 52 | 52 | if (nsid != U32_MAX) { | |
| 53 | 53 | status = nvmet_req_find_ns(req); | |
| 54 | + | if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR)) | |
| 55 | + | return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; | |
| 54 | 56 | if (status) | |
| 55 | 57 | return status; | |
| 56 | 58 | if (!req->ns->pr.enable) | |
| @@ -75,6 +77,8 @@ u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req) | |||
| 75 | 77 | u16 status; | |
| 76 | 78 | ||
| 77 | 79 | status = nvmet_req_find_ns(req); | |
| 80 | + | if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR)) | |
| 81 | + | return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; | |
| 78 | 82 | if (status) | |
| 79 | 83 | return status; | |
| 80 | 84 | ||
modified drivers/pci/pcie/aer.c
| @@ -1360,8 +1360,10 @@ static DEFINE_KFIFO(aer_recover_ring, struct aer_recover_entry, | |||
| 1360 | 1360 | ||
| 1361 | 1361 | static void aer_recover_work_func(struct work_struct *work) | |
| 1362 | 1362 | { | |
| 1363 | + | struct aer_capability_regs *regs; | |
| 1363 | 1364 | struct aer_recover_entry entry; | |
| 1364 | 1365 | struct pci_dev *pdev; | |
| 1366 | + | u32 err; | |
| 1365 | 1367 | ||
| 1366 | 1368 | while (kfifo_get(&aer_recover_ring, &entry)) { | |
| 1367 | 1369 | pdev = pci_get_domain_bus_and_slot(entry.domain, entry.bus, | |
| @@ -1375,6 +1377,12 @@ static void aer_recover_work_func(struct work_struct *work) | |||
| 1375 | 1377 | } | |
| 1376 | 1378 | pci_print_aer(pdev, entry.severity, entry.regs); | |
| 1377 | 1379 | ||
| 1380 | + | regs = entry.regs; | |
| 1381 | + | if (entry.severity == AER_CORRECTABLE) | |
| 1382 | + | err = regs->cor_status & ~regs->cor_mask; | |
| 1383 | + | else | |
| 1384 | + | err = regs->uncor_status & ~regs->uncor_mask; | |
| 1385 | + | ||
| 1378 | 1386 | /* | |
| 1379 | 1387 | * Memory for aer_capability_regs(entry.regs) is being | |
| 1380 | 1388 | * allocated from the ghes_estatus_pool to protect it from | |
| @@ -1385,12 +1393,14 @@ static void aer_recover_work_func(struct work_struct *work) | |||
| 1385 | 1393 | ghes_estatus_pool_region_free((unsigned long)entry.regs, | |
| 1386 | 1394 | sizeof(struct aer_capability_regs)); | |
| 1387 | 1395 | ||
| 1388 | - | if (entry.severity == AER_NONFATAL) | |
| 1389 | - | pcie_do_recovery(pdev, pci_channel_io_normal, | |
| 1390 | - | aer_root_reset); | |
| 1391 | - | else if (entry.severity == AER_FATAL) | |
| 1392 | - | pcie_do_recovery(pdev, pci_channel_io_frozen, | |
| 1393 | - | aer_root_reset); | |
| 1396 | + | if (err) { | |
| 1397 | + | if (entry.severity == AER_NONFATAL) | |
| 1398 | + | pcie_do_recovery(pdev, pci_channel_io_normal, | |
| 1399 | + | aer_root_reset); | |
| 1400 | + | else if (entry.severity == AER_FATAL) | |
| 1401 | + | pcie_do_recovery(pdev, pci_channel_io_frozen, | |
| 1402 | + | aer_root_reset); | |
| 1403 | + | } | |
| 1394 | 1404 | pci_dev_put(pdev); | |
| 1395 | 1405 | } | |
| 1396 | 1406 | } | |
modified drivers/pmdomain/imx/imx8m-blk-ctrl.c
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | #include <linux/pm_runtime.h> | |
| 16 | 16 | #include <linux/regmap.h> | |
| 17 | 17 | #include <linux/clk.h> | |
| 18 | + | #include <linux/mutex.h> | |
| 18 | 19 | ||
| 19 | 20 | #include <dt-bindings/power/imx8mm-power.h> | |
| 20 | 21 | #include <dt-bindings/power/imx8mn-power.h> | |
| @@ -34,6 +35,12 @@ struct imx8m_blk_ctrl { | |||
| 34 | 35 | struct regmap *regmap; | |
| 35 | 36 | struct imx8m_blk_ctrl_domain *domains; | |
| 36 | 37 | struct genpd_onecell_data onecell_data; | |
| 38 | + | /* | |
| 39 | + | * Serializes the blk-ctrl reset/clock sequence across sibling domains; | |
| 40 | + | * their transitions interact through the shared VPUMIX bus domain, | |
| 41 | + | * VPU_NOC and the not-ack-verified ADB400 handshake (ERR050531). | |
| 42 | + | */ | |
| 43 | + | struct mutex power_lock; | |
| 37 | 44 | }; | |
| 38 | 45 | ||
| 39 | 46 | struct imx8m_blk_ctrl_domain_data { | |
| @@ -98,6 +105,8 @@ static int imx8m_blk_ctrl_power_on(struct generic_pm_domain *genpd) | |||
| 98 | 105 | struct imx8m_blk_ctrl *bc = domain->bc; | |
| 99 | 106 | int ret; | |
| 100 | 107 | ||
| 108 | + | guard(mutex)(&bc->power_lock); | |
| 109 | + | ||
| 101 | 110 | /* make sure bus domain is awake */ | |
| 102 | 111 | ret = pm_runtime_get_sync(bc->bus_power_dev); | |
| 103 | 112 | if (ret < 0) { | |
| @@ -164,6 +173,8 @@ static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd) | |||
| 164 | 173 | const struct imx8m_blk_ctrl_domain_data *data = domain->data; | |
| 165 | 174 | struct imx8m_blk_ctrl *bc = domain->bc; | |
| 166 | 175 | ||
| 176 | + | guard(mutex)(&bc->power_lock); | |
| 177 | + | ||
| 167 | 178 | /* put devices into reset and disable clocks */ | |
| 168 | 179 | if (data->mipi_phy_rst_mask) | |
| 169 | 180 | regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask); | |
| @@ -202,6 +213,10 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev) | |||
| 202 | 213 | ||
| 203 | 214 | bc->dev = dev; | |
| 204 | 215 | ||
| 216 | + | ret = devm_mutex_init(dev, &bc->power_lock); | |
| 217 | + | if (ret) | |
| 218 | + | return ret; | |
| 219 | + | ||
| 205 | 220 | bc_data = of_device_get_match_data(dev); | |
| 206 | 221 | ||
| 207 | 222 | base = devm_platform_ioremap_resource(pdev, 0); | |
modified drivers/pmdomain/rockchip/pm-domains.c
| @@ -759,7 +759,19 @@ static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd, | |||
| 759 | 759 | } | |
| 760 | 760 | ||
| 761 | 761 | i = 0; | |
| 762 | - | while ((clk = of_clk_get(dev->of_node, i++)) && !IS_ERR(clk)) { | |
| 762 | + | while (1) { | |
| 763 | + | clk = of_clk_get(dev->of_node, i++); | |
| 764 | + | if (IS_ERR(clk)) { | |
| 765 | + | error = PTR_ERR(clk); | |
| 766 | + | if (error == -ENOENT) | |
| 767 | + | break; | |
| 768 | + | ||
| 769 | + | dev_err(dev, "failed to get clock %d: %d\n", i - 1, | |
| 770 | + | error); | |
| 771 | + | pm_clk_destroy(dev); | |
| 772 | + | return error; | |
| 773 | + | } | |
| 774 | + | ||
| 763 | 775 | dev_dbg(dev, "adding clock '%pC' to list of PM clocks\n", clk); | |
| 764 | 776 | error = pm_clk_add_clk(dev, clk); | |
| 765 | 777 | if (error) { | |
| @@ -842,7 +854,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, | |||
| 842 | 854 | dev_err(pmu->dev, | |
| 843 | 855 | "%pOFn: failed to get clk at index %d: %d\n", | |
| 844 | 856 | node, i, error); | |
| 845 | - | return error; | |
| 857 | + | goto err_put_clocks; | |
| 846 | 858 | } | |
| 847 | 859 | } | |
| 848 | 860 | ||
| @@ -1018,7 +1030,9 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu, | |||
| 1018 | 1030 | parent_domain->name, child_domain->name); | |
| 1019 | 1031 | } | |
| 1020 | 1032 | ||
| 1021 | - | rockchip_pm_add_subdomain(pmu, np); | |
| 1033 | + | error = rockchip_pm_add_subdomain(pmu, np); | |
| 1034 | + | if (error) | |
| 1035 | + | return error; | |
| 1022 | 1036 | } | |
| 1023 | 1037 | ||
| 1024 | 1038 | return 0; | |
modified drivers/power/sequencing/pwrseq-pcie-m2.c
| @@ -197,6 +197,8 @@ static const struct pci_device_id pwrseq_m2_pci_ids[] = { | |||
| 197 | 197 | .driver_data = (kernel_ulong_t)"qcom,wcn6855-bt" }, | |
| 198 | 198 | { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_QCOM, 0x337c), | |
| 199 | 199 | .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" }, | |
| 200 | + | { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_LENOVO, 0xe0e9), | |
| 201 | + | .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" }, | |
| 200 | 202 | { } /* Sentinel */ | |
| 201 | 203 | }; | |
| 202 | 204 | ||
| @@ -570,6 +572,7 @@ err_destroy_mutex: | |||
| 570 | 572 | mutex_destroy(&ctx->list_lock); | |
| 571 | 573 | err_free_regulators: | |
| 572 | 574 | regulator_bulk_free(ctx->num_vregs, ctx->regs); | |
| 575 | + | kfree(ctx->regs); | |
| 573 | 576 | ||
| 574 | 577 | return ret; | |
| 575 | 578 | } | |
| @@ -583,6 +586,7 @@ static void pwrseq_pcie_m2_remove(struct platform_device *pdev) | |||
| 583 | 586 | mutex_destroy(&ctx->list_lock); | |
| 584 | 587 | ||
| 585 | 588 | regulator_bulk_free(ctx->num_vregs, ctx->regs); | |
| 589 | + | kfree(ctx->regs); | |
| 586 | 590 | } | |
| 587 | 591 | ||
| 588 | 592 | static const struct of_device_id pwrseq_pcie_m2_of_match[] = { | |
modified drivers/ptp/ptp_ocp.c
| @@ -1825,7 +1825,7 @@ ptp_ocp_watchdog(struct timer_list *t) | |||
| 1825 | 1825 | static void | |
| 1826 | 1826 | ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp) | |
| 1827 | 1827 | { | |
| 1828 | - | ktime_t start, end, delay = U64_MAX; | |
| 1828 | + | ktime_t start, end, delay = KTIME_MAX; | |
| 1829 | 1829 | u32 ctrl; | |
| 1830 | 1830 | int i; | |
| 1831 | 1831 | ||
modified drivers/regulator/ltc3676.c
| @@ -232,7 +232,7 @@ static const struct regulator_desc ltc3676_regulators[LTC3676_NUM_REGULATORS] = | |||
| 232 | 232 | LTC3676_FIXED_REG(LDO4, ldo4, LDOB, 2), | |
| 233 | 233 | }; | |
| 234 | 234 | ||
| 235 | - | static bool ltc3676_readable_writeable_reg(struct device *dev, unsigned int reg) | |
| 235 | + | static bool ltc3676_writeable_reg(struct device *dev, unsigned int reg) | |
| 236 | 236 | { | |
| 237 | 237 | switch (reg) { | |
| 238 | 238 | case LTC3676_BUCK1 ... LTC3676_IRQSTAT: | |
| @@ -243,6 +243,15 @@ static bool ltc3676_readable_writeable_reg(struct device *dev, unsigned int reg) | |||
| 243 | 243 | return false; | |
| 244 | 244 | } | |
| 245 | 245 | ||
| 246 | + | static bool ltc3676_readable_reg(struct device *dev, unsigned int reg) | |
| 247 | + | { | |
| 248 | + | switch (reg) { | |
| 249 | + | case LTC3676_BUCK1 ... LTC3676_IRQSTAT: | |
| 250 | + | return true; | |
| 251 | + | } | |
| 252 | + | return false; | |
| 253 | + | } | |
| 254 | + | ||
| 246 | 255 | static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg) | |
| 247 | 256 | { | |
| 248 | 257 | switch (reg) { | |
| @@ -255,8 +264,8 @@ static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg) | |||
| 255 | 264 | static const struct regmap_config ltc3676_regmap_config = { | |
| 256 | 265 | .reg_bits = 8, | |
| 257 | 266 | .val_bits = 8, | |
| 258 | - | .writeable_reg = ltc3676_readable_writeable_reg, | |
| 259 | - | .readable_reg = ltc3676_readable_writeable_reg, | |
| 267 | + | .writeable_reg = ltc3676_writeable_reg, | |
| 268 | + | .readable_reg = ltc3676_readable_reg, | |
| 260 | 269 | .volatile_reg = ltc3676_volatile_reg, | |
| 261 | 270 | .max_register = LTC3676_CLIRQ, | |
| 262 | 271 | .use_single_read = true, | |
modified drivers/regulator/of_regulator.c
| @@ -929,21 +929,26 @@ static int is_supply_name(const char *name) | |||
| 929 | 929 | * before returning to the caller, and @consumers will not be | |
| 930 | 930 | * changed. | |
| 931 | 931 | * | |
| 932 | + | * On success the array is allocated here and handed to the caller, which | |
| 933 | + | * owns it from then on: release the regulators with regulator_bulk_free() | |
| 934 | + | * and free the array itself with kfree(). The supply names live in the | |
| 935 | + | * same allocation, so they are gone once the array is freed. | |
| 936 | + | * | |
| 932 | 937 | * Return: Number of regulators on success, or a negative error number | |
| 933 | 938 | * on failure. | |
| 934 | 939 | */ | |
| 935 | 940 | int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, | |
| 936 | 941 | struct regulator_bulk_data **consumers) | |
| 937 | 942 | { | |
| 938 | - | int num_consumers = 0; | |
| 943 | + | int num_consumers = 0, names_len = 0; | |
| 939 | 944 | struct regulator *tmp; | |
| 940 | 945 | struct regulator_bulk_data *_consumers = NULL; | |
| 941 | 946 | struct property *prop; | |
| 947 | + | char *names; | |
| 942 | 948 | int i, n = 0, ret; | |
| 943 | - | char name[64]; | |
| 944 | 949 | ||
| 945 | 950 | /* | |
| 946 | - | * first pass: get numbers of xxx-supply | |
| 951 | + | * first pass: get numbers of xxx-supply and the room their names take | |
| 947 | 952 | * second pass: fill consumers | |
| 948 | 953 | */ | |
| 949 | 954 | restart: | |
| @@ -953,16 +958,19 @@ restart: | |||
| 953 | 958 | continue; | |
| 954 | 959 | if (!_consumers) { | |
| 955 | 960 | num_consumers++; | |
| 961 | + | names_len += i + 1; | |
| 956 | 962 | continue; | |
| 957 | 963 | } else { | |
| 958 | - | memcpy(name, prop->name, i); | |
| 959 | - | name[i] = '\0'; | |
| 960 | - | tmp = regulator_get(dev, name); | |
| 964 | + | memcpy(names, prop->name, i); | |
| 965 | + | names[i] = '\0'; | |
| 966 | + | tmp = regulator_get(dev, names); | |
| 961 | 967 | if (IS_ERR(tmp)) { | |
| 962 | 968 | ret = PTR_ERR(tmp); | |
| 963 | 969 | goto error; | |
| 964 | 970 | } | |
| 971 | + | _consumers[n].supply = names; | |
| 965 | 972 | _consumers[n].consumer = tmp; | |
| 973 | + | names += i + 1; | |
| 966 | 974 | n++; | |
| 967 | 975 | continue; | |
| 968 | 976 | } | |
| @@ -973,9 +981,16 @@ restart: | |||
| 973 | 981 | } | |
| 974 | 982 | if (num_consumers == 0) | |
| 975 | 983 | return 0; | |
| 976 | - | _consumers = kmalloc_objs(struct regulator_bulk_data, num_consumers); | |
| 984 | + | /* | |
| 985 | + | * The supply names are kept in the same allocation as the array, so | |
| 986 | + | * that they share its lifetime and the caller has nothing extra to | |
| 987 | + | * free. | |
| 988 | + | */ | |
| 989 | + | _consumers = kzalloc(size_add(size_mul(num_consumers, sizeof(*_consumers)), | |
| 990 | + | names_len), GFP_KERNEL); | |
| 977 | 991 | if (!_consumers) | |
| 978 | 992 | return -ENOMEM; | |
| 993 | + | names = (char *)(_consumers + num_consumers); | |
| 979 | 994 | goto restart; | |
| 980 | 995 | ||
| 981 | 996 | error: | |
modified drivers/regulator/tps6594-regulator.c
| @@ -241,21 +241,21 @@ static const struct regulator_desc tps65224_buck_regs[] = { | |||
| 241 | 241 | TPS65224_MASK_BUCKS_VSET, | |
| 242 | 242 | TPS6594_REG_BUCKX_CTRL(1), | |
| 243 | 243 | TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges, | |
| 244 | - | 4, 0, 0, NULL, 0, 0), | |
| 244 | + | ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0), | |
| 245 | 245 | TPS6594_REGULATOR("BUCK3", "buck3", TPS6594_BUCK_3, | |
| 246 | 246 | REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS65224_MASK_BUCKS_VSET, | |
| 247 | 247 | TPS6594_REG_BUCKX_VOUT_1(2), | |
| 248 | 248 | TPS65224_MASK_BUCKS_VSET, | |
| 249 | 249 | TPS6594_REG_BUCKX_CTRL(2), | |
| 250 | 250 | TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges, | |
| 251 | - | 4, 0, 0, NULL, 0, 0), | |
| 251 | + | ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0), | |
| 252 | 252 | TPS6594_REGULATOR("BUCK4", "buck4", TPS6594_BUCK_4, | |
| 253 | 253 | REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS65224_MASK_BUCKS_VSET, | |
| 254 | 254 | TPS6594_REG_BUCKX_VOUT_1(3), | |
| 255 | 255 | TPS65224_MASK_BUCKS_VSET, | |
| 256 | 256 | TPS6594_REG_BUCKX_CTRL(3), | |
| 257 | 257 | TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges, | |
| 258 | - | 4, 0, 0, NULL, 0, 0), | |
| 258 | + | ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0), | |
| 259 | 259 | }; | |
| 260 | 260 | ||
| 261 | 261 | static const struct tps6594_regulator_irq_type tps6594_buck1_irq_types[] = { | |
modified drivers/scsi/ch.c
| @@ -112,7 +112,6 @@ typedef struct { | |||
| 112 | 112 | int minor; | |
| 113 | 113 | char name[8]; | |
| 114 | 114 | struct scsi_device *device; | |
| 115 | - | struct scsi_device **dt; /* ptrs to data transfer elements */ | |
| 116 | 115 | u_int firsts[CH_TYPES]; | |
| 117 | 116 | u_int counts[CH_TYPES]; | |
| 118 | 117 | u_int voltags; | |
| @@ -363,15 +362,10 @@ ch_readconfig(scsi_changer *ch) | |||
| 363 | 362 | vendor_labels[i]); | |
| 364 | 363 | } | |
| 365 | 364 | ||
| 366 | - | /* look up the devices of the data transfer elements */ | |
| 367 | - | ch->dt = kzalloc_objs(*ch->dt, ch->counts[CHET_DT]); | |
| 368 | - | ||
| 369 | - | if (!ch->dt) { | |
| 370 | - | kfree(buffer); | |
| 371 | - | return -ENOMEM; | |
| 372 | - | } | |
| 373 | - | ||
| 365 | + | /* report the devices of the data transfer elements */ | |
| 374 | 366 | for (elem = 0; elem < ch->counts[CHET_DT]; elem++) { | |
| 367 | + | struct scsi_device *sdev; | |
| 368 | + | ||
| 375 | 369 | id = -1; | |
| 376 | 370 | lun = 0; | |
| 377 | 371 | if (elem < CH_DT_MAX && -1 != dt_id[elem]) { | |
| @@ -387,10 +381,8 @@ ch_readconfig(scsi_changer *ch) | |||
| 387 | 381 | VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]); | |
| 388 | 382 | if (data[6] & 0x80) { | |
| 389 | 383 | VPRINTK(KERN_CONT, "not this SCSI bus\n"); | |
| 390 | - | ch->dt[elem] = NULL; | |
| 391 | 384 | } else if (0 == (data[6] & 0x30)) { | |
| 392 | 385 | VPRINTK(KERN_CONT, "ID/LUN unknown\n"); | |
| 393 | - | ch->dt[elem] = NULL; | |
| 394 | 386 | } else { | |
| 395 | 387 | id = ch->device->id; | |
| 396 | 388 | lun = 0; | |
| @@ -400,18 +392,16 @@ ch_readconfig(scsi_changer *ch) | |||
| 400 | 392 | } | |
| 401 | 393 | if (-1 != id) { | |
| 402 | 394 | VPRINTK(KERN_CONT, "ID %i, LUN %i, ",id,lun); | |
| 403 | - | ch->dt[elem] = | |
| 404 | - | scsi_device_lookup(ch->device->host, | |
| 405 | - | ch->device->channel, | |
| 406 | - | id,lun); | |
| 407 | - | if (!ch->dt[elem]) { | |
| 395 | + | sdev = scsi_device_lookup(ch->device->host, | |
| 396 | + | ch->device->channel, | |
| 397 | + | id, lun); | |
| 398 | + | if (!sdev) { | |
| 408 | 399 | /* should not happen */ | |
| 409 | 400 | VPRINTK(KERN_CONT, "Huh? device not found!\n"); | |
| 410 | 401 | } else { | |
| 411 | 402 | VPRINTK(KERN_CONT, "name: %8.8s %16.16s %4.4s\n", | |
| 412 | - | ch->dt[elem]->vendor, | |
| 413 | - | ch->dt[elem]->model, | |
| 414 | - | ch->dt[elem]->rev); | |
| 403 | + | sdev->vendor, sdev->model, sdev->rev); | |
| 404 | + | scsi_device_put(sdev); | |
| 415 | 405 | } | |
| 416 | 406 | } | |
| 417 | 407 | } | |
| @@ -575,7 +565,6 @@ static void ch_destroy(struct kref *ref) | |||
| 575 | 565 | scsi_changer *ch = container_of(ref, scsi_changer, ref); | |
| 576 | 566 | ||
| 577 | 567 | ch->device = NULL; | |
| 578 | - | kfree(ch->dt); | |
| 579 | 568 | kfree(ch); | |
| 580 | 569 | } | |
| 581 | 570 | ||
modified drivers/scsi/qedi/qedi_main.c
| @@ -2652,8 +2652,6 @@ retry_probe: | |||
| 2652 | 2652 | snprintf(host_buf, sizeof(host_buf), "host_%d", qedi->shost->host_no); | |
| 2653 | 2653 | qedi_ops->common->set_name(qedi->cdev, host_buf); | |
| 2654 | 2654 | ||
| 2655 | - | qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi); | |
| 2656 | - | ||
| 2657 | 2655 | memset(¶ms, 0, sizeof(params)); | |
| 2658 | 2656 | params.mtu = DEF_PATH_MTU + IPV6_HDR_LEN + TCP_HDR_LEN; | |
| 2659 | 2657 | qedi->ll2_mtu = DEF_PATH_MTU; | |
| @@ -2670,6 +2668,7 @@ retry_probe: | |||
| 2670 | 2668 | spin_lock_init(&qedi->task_idx_lock); | |
| 2671 | 2669 | mutex_init(&qedi->stats_lock); | |
| 2672 | 2670 | } | |
| 2671 | + | qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi); | |
| 2673 | 2672 | qedi_ops->ll2->register_cb_ops(qedi->cdev, &qedi_ll2_cb_ops, qedi); | |
| 2674 | 2673 | qedi_ops->ll2->start(qedi->cdev, ¶ms); | |
| 2675 | 2674 | ||
modified drivers/spi/spi-cadence-quadspi.c
| @@ -1056,8 +1056,7 @@ static int cqspi_write_setup(struct cqspi_flash_pdata *f_pdata, | |||
| 1056 | 1056 | * care of polling the status register. | |
| 1057 | 1057 | */ | |
| 1058 | 1058 | if (cqspi->wr_completion) { | |
| 1059 | - | reg = readl(reg_base + CQSPI_REG_WR_COMPLETION_CTRL); | |
| 1060 | - | reg |= CQSPI_REG_WR_DISABLE_AUTO_POLL; | |
| 1059 | + | reg = CQSPI_REG_WR_DISABLE_AUTO_POLL; | |
| 1061 | 1060 | writel(reg, reg_base + CQSPI_REG_WR_COMPLETION_CTRL); | |
| 1062 | 1061 | /* | |
| 1063 | 1062 | * DAC mode require auto polling as flash needs to be polled | |
modified drivers/spi/spi-nxp-fspi.c
| @@ -898,10 +898,10 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi, | |||
| 898 | 898 | dev_dbg(f->dev, "Target device [CS:%x] selected\n", spi_get_chipselect(spi, 0)); | |
| 899 | 899 | ||
| 900 | 900 | /* | |
| 901 | - | * Per the FlexSPI reference manual (initialization sequence), MCR0 and | |
| 902 | - | * the DLL control registers should be configured while the module is in | |
| 903 | - | * stop mode (MCR0[MDIS] = 1). Enter stop mode before reconfiguring the | |
| 904 | - | * RX sample clock source and the DLL, then exit stop mode afterwards. | |
| 901 | + | * Per the FlexSPI reference manual (initialization sequence), MCR0 | |
| 902 | + | * should be configured while the module is in stop mode (MCR0[MDIS] = 1). | |
| 903 | + | * Enter stop mode before reconfiguring the RX sample clock source, then | |
| 904 | + | * exit stop mode afterwards. | |
| 905 | 905 | */ | |
| 906 | 906 | reg = fspi_readl(f, f->iobase + FSPI_MCR0); | |
| 907 | 907 | fspi_writel(f, reg | FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); | |
| @@ -936,6 +936,16 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi, | |||
| 936 | 936 | if (ret) | |
| 937 | 937 | return ret; | |
| 938 | 938 | ||
| 939 | + | /* | |
| 940 | + | * Exit stop mode before running the DLL calibration. The DLL | |
| 941 | + | * reference clock is derived from the module clock domain, which is | |
| 942 | + | * gated while MCR0[MDIS] = 1. Calibrating the DLL in stop mode leaves | |
| 943 | + | * the STS2 lock bits stuck at 0 (the DLL never runs), so clear MDIS | |
| 944 | + | * first and let the module and reference clock run. | |
| 945 | + | */ | |
| 946 | + | reg = fspi_readl(f, f->iobase + FSPI_MCR0); | |
| 947 | + | fspi_writel(f, reg & ~FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); | |
| 948 | + | ||
| 939 | 949 | /* | |
| 940 | 950 | * If clock rate > 100MHz, then switch from DLL override mode to | |
| 941 | 951 | * DLL calibration mode. | |
| @@ -945,10 +955,6 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi, | |||
| 945 | 955 | else | |
| 946 | 956 | nxp_fspi_dll_override(f); | |
| 947 | 957 | ||
| 948 | - | /* Exit stop mode now that MCR0 and the DLL have been reconfigured. */ | |
| 949 | - | reg = fspi_readl(f, f->iobase + FSPI_MCR0); | |
| 950 | - | fspi_writel(f, reg & ~FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); | |
| 951 | - | ||
| 952 | 958 | f->pre_op_rate = op->max_freq; | |
| 953 | 959 | ||
| 954 | 960 | f->selected = spi_get_chipselect(spi, 0); | |
modified drivers/spi/spi-sg2044-nor.c
| @@ -307,15 +307,15 @@ static ssize_t sg2044_spifmc_tran_cmd(struct sg2044_spifmc *spifmc, | |||
| 307 | 307 | return 0; | |
| 308 | 308 | } | |
| 309 | 309 | ||
| 310 | - | static void sg2044_spifmc_trans(struct sg2044_spifmc *spifmc, | |
| 311 | - | const struct spi_mem_op *op) | |
| 310 | + | static int sg2044_spifmc_trans(struct sg2044_spifmc *spifmc, | |
| 311 | + | const struct spi_mem_op *op) | |
| 312 | 312 | { | |
| 313 | 313 | if (op->data.dir == SPI_MEM_DATA_IN) | |
| 314 | - | sg2044_spifmc_read(spifmc, op); | |
| 314 | + | return sg2044_spifmc_read(spifmc, op); | |
| 315 | 315 | else if (op->data.dir == SPI_MEM_DATA_OUT) | |
| 316 | - | sg2044_spifmc_write(spifmc, op); | |
| 316 | + | return sg2044_spifmc_write(spifmc, op); | |
| 317 | 317 | else | |
| 318 | - | sg2044_spifmc_tran_cmd(spifmc, op); | |
| 318 | + | return sg2044_spifmc_tran_cmd(spifmc, op); | |
| 319 | 319 | } | |
| 320 | 320 | ||
| 321 | 321 | static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc, | |
| @@ -385,29 +385,64 @@ static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc, | |||
| 385 | 385 | return 0; | |
| 386 | 386 | } | |
| 387 | 387 | ||
| 388 | + | static int sg2044_spifmc_set_speed(struct sg2044_spifmc *spifmc, | |
| 389 | + | unsigned int speed_hz) | |
| 390 | + | { | |
| 391 | + | unsigned long rate = clk_get_rate(spifmc->clk); | |
| 392 | + | u64 div; | |
| 393 | + | u32 reg; | |
| 394 | + | ||
| 395 | + | if (!rate) | |
| 396 | + | return -EINVAL; | |
| 397 | + | ||
| 398 | + | /* SCK = HCLK / (2 * (SckDiv + 1)); round down the resulting SCK. */ | |
| 399 | + | div = speed_hz ? DIV_ROUND_UP_ULL(rate, 2ULL * speed_hz) : 1; | |
| 400 | + | if (div > SPIFMC_CTRL_SCK_DIV_MASK + 1) | |
| 401 | + | return -EINVAL; | |
| 402 | + | ||
| 403 | + | reg = readl(spifmc->io_base + SPIFMC_CTRL); | |
| 404 | + | reg &= ~SPIFMC_CTRL_SCK_DIV_MASK; | |
| 405 | + | reg |= div - 1; | |
| 406 | + | writel(reg, spifmc->io_base + SPIFMC_CTRL); | |
| 407 | + | ||
| 408 | + | return 0; | |
| 409 | + | } | |
| 410 | + | ||
| 388 | 411 | static int sg2044_spifmc_exec_op(struct spi_mem *mem, | |
| 389 | 412 | const struct spi_mem_op *op) | |
| 390 | 413 | { | |
| 391 | 414 | struct sg2044_spifmc *spifmc; | |
| 415 | + | int ret; | |
| 392 | 416 | ||
| 393 | 417 | spifmc = spi_controller_get_devdata(mem->spi->controller); | |
| 394 | 418 | ||
| 395 | 419 | mutex_lock(&spifmc->lock); | |
| 396 | 420 | ||
| 421 | + | ret = sg2044_spifmc_set_speed(spifmc, op->max_freq ? | |
| 422 | + | min(op->max_freq, mem->spi->max_speed_hz) : | |
| 423 | + | mem->spi->max_speed_hz); | |
| 424 | + | if (ret) | |
| 425 | + | goto out_unlock; | |
| 426 | + | ||
| 397 | 427 | if (op->addr.nbytes == 0) | |
| 398 | - | sg2044_spifmc_trans_reg(spifmc, op); | |
| 428 | + | ret = sg2044_spifmc_trans_reg(spifmc, op); | |
| 399 | 429 | else | |
| 400 | - | sg2044_spifmc_trans(spifmc, op); | |
| 430 | + | ret = sg2044_spifmc_trans(spifmc, op); | |
| 401 | 431 | ||
| 432 | + | out_unlock: | |
| 402 | 433 | mutex_unlock(&spifmc->lock); | |
| 403 | 434 | ||
| 404 | - | return 0; | |
| 435 | + | return ret; | |
| 405 | 436 | } | |
| 406 | 437 | ||
| 407 | 438 | static const struct spi_controller_mem_ops sg2044_spifmc_mem_ops = { | |
| 408 | 439 | .exec_op = sg2044_spifmc_exec_op, | |
| 409 | 440 | }; | |
| 410 | 441 | ||
| 442 | + | static const struct spi_controller_mem_caps sg2044_spifmc_mem_caps = { | |
| 443 | + | .per_op_freq = true, | |
| 444 | + | }; | |
| 445 | + | ||
| 411 | 446 | static void sg2044_spifmc_init(struct sg2044_spifmc *spifmc) | |
| 412 | 447 | { | |
| 413 | 448 | u32 tran_csr; | |
| @@ -447,6 +482,10 @@ static int sg2044_spifmc_probe(struct platform_device *pdev) | |||
| 447 | 482 | if (IS_ERR(spifmc->clk)) | |
| 448 | 483 | return dev_err_probe(dev, PTR_ERR(spifmc->clk), "Cannot get and enable AHB clock\n"); | |
| 449 | 484 | ||
| 485 | + | ctrl->max_speed_hz = clk_get_rate(spifmc->clk) / 2; | |
| 486 | + | if (!ctrl->max_speed_hz) | |
| 487 | + | return dev_err_probe(dev, -EINVAL, "Invalid AHB clock rate\n"); | |
| 488 | + | ||
| 450 | 489 | spifmc->dev = &pdev->dev; | |
| 451 | 490 | spifmc->ctrl = ctrl; | |
| 452 | 491 | ||
| @@ -458,6 +497,7 @@ static int sg2044_spifmc_probe(struct platform_device *pdev) | |||
| 458 | 497 | ctrl->bits_per_word_mask = SPI_BPW_MASK(8); | |
| 459 | 498 | ctrl->auto_runtime_pm = false; | |
| 460 | 499 | ctrl->mem_ops = &sg2044_spifmc_mem_ops; | |
| 500 | + | ctrl->mem_caps = &sg2044_spifmc_mem_caps; | |
| 461 | 501 | ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD; | |
| 462 | 502 | ||
| 463 | 503 | ret = devm_mutex_init(dev, &spifmc->lock); | |
modified drivers/tee/optee/ffa_abi.c
| @@ -198,7 +198,8 @@ static int to_msg_param_ffa_mem(struct optee_msg_param *mp, | |||
| 198 | 198 | if (shm) { | |
| 199 | 199 | u64 shm_offs = p->u.memref.shm_offs; | |
| 200 | 200 | ||
| 201 | - | mp->u.fmem.internal_offs = shm->offset; | |
| 201 | + | mp->u.fmem.internal_offs = tee_shm_get_page_offset(shm) & | |
| 202 | + | (FFA_PAGE_SIZE - 1); | |
| 202 | 203 | ||
| 203 | 204 | mp->u.fmem.offs_low = shm_offs; | |
| 204 | 205 | mp->u.fmem.offs_high = shm_offs >> 32; | |
| @@ -284,14 +285,26 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm, | |||
| 284 | 285 | .nattrs = 1, | |
| 285 | 286 | }; | |
| 286 | 287 | struct sg_table sgt; | |
| 288 | + | size_t ffa_offs; | |
| 287 | 289 | int rc; | |
| 288 | 290 | ||
| 291 | + | if (!num_pages) | |
| 292 | + | return -EINVAL; | |
| 293 | + | ||
| 289 | 294 | rc = optee_check_mem_type(start, num_pages); | |
| 290 | 295 | if (rc) | |
| 291 | 296 | return rc; | |
| 292 | 297 | ||
| 293 | - | rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, 0, | |
| 294 | - | num_pages * PAGE_SIZE, GFP_KERNEL); | |
| 298 | + | /* | |
| 299 | + | * Start the FF-A descriptor at the 4 KiB page containing the shared | |
| 300 | + | * buffer, skipping unused leading 4 KiB pages when PAGE_SIZE is | |
| 301 | + | * larger. Same approach as optee_fill_pages_list() in the SMC ABI. | |
| 302 | + | * This leaves only the offset into that 4 KiB page for internal_offs. | |
| 303 | + | */ | |
| 304 | + | ffa_offs = round_down(tee_shm_get_page_offset(shm), FFA_PAGE_SIZE); | |
| 305 | + | rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, ffa_offs, | |
| 306 | + | num_pages * PAGE_SIZE - ffa_offs, | |
| 307 | + | GFP_KERNEL); | |
| 295 | 308 | if (rc) | |
| 296 | 309 | return rc; | |
| 297 | 310 | args.sg = sgt.sgl; | |
| @@ -458,7 +471,8 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx, | |||
| 458 | 471 | .attr = OPTEE_MSG_ATTR_TYPE_FMEM_OUTPUT, | |
| 459 | 472 | .u.fmem.size = tee_shm_get_size(shm), | |
| 460 | 473 | .u.fmem.global_id = shm->sec_world_id, | |
| 461 | - | .u.fmem.internal_offs = shm->offset, | |
| 474 | + | .u.fmem.internal_offs = tee_shm_get_page_offset(shm) & | |
| 475 | + | (FFA_PAGE_SIZE - 1), | |
| 462 | 476 | }; | |
| 463 | 477 | ||
| 464 | 478 | arg->ret = TEEC_SUCCESS; | |
| @@ -1123,14 +1137,6 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev) | |||
| 1123 | 1137 | ||
| 1124 | 1138 | optee_set_dev_group(optee); | |
| 1125 | 1139 | ||
| 1126 | - | rc = tee_device_register(optee->teedev); | |
| 1127 | - | if (rc) | |
| 1128 | - | goto err_unreg_supp_teedev; | |
| 1129 | - | ||
| 1130 | - | rc = tee_device_register(optee->supp_teedev); | |
| 1131 | - | if (rc) | |
| 1132 | - | goto err_unreg_supp_teedev; | |
| 1133 | - | ||
| 1134 | 1140 | rc = rhashtable_init(&optee->ffa.global_ids, &shm_rhash_params); | |
| 1135 | 1141 | if (rc) | |
| 1136 | 1142 | goto err_unreg_supp_teedev; | |
| @@ -1159,6 +1165,14 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev) | |||
| 1159 | 1165 | if (optee_ffa_protmem_pool_init(optee, sec_caps)) | |
| 1160 | 1166 | pr_info("Protected memory service not available\n"); | |
| 1161 | 1167 | ||
| 1168 | + | rc = tee_device_register(optee->teedev); | |
| 1169 | + | if (rc) | |
| 1170 | + | goto err_unregister_devices; | |
| 1171 | + | ||
| 1172 | + | rc = tee_device_register(optee->supp_teedev); | |
| 1173 | + | if (rc) | |
| 1174 | + | goto err_unregister_devices; | |
| 1175 | + | ||
| 1162 | 1176 | rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES); | |
| 1163 | 1177 | if (rc) | |
| 1164 | 1178 | goto err_unregister_devices; | |
modified drivers/tee/optee/optee_msg.h
| @@ -136,8 +136,8 @@ struct optee_msg_param_rmem { | |||
| 136 | 136 | * struct optee_msg_param_fmem - FF-A memory reference parameter | |
| 137 | 137 | * @offs_low: lower bits of offset into shared memory reference | |
| 138 | 138 | * @offs_high: higher bits of offset into shared memory reference | |
| 139 | - | * @internal_offs: internal offset into the first page of shared memory | |
| 140 | - | * reference | |
| 139 | + | * @internal_offs: offset into the first 4 KiB page of the FF-A shared | |
| 140 | + | * memory region | |
| 141 | 141 | * @size: size of the buffer | |
| 142 | 142 | * @global_id: global identifier of the shared memory | |
| 143 | 143 | */ | |
modified drivers/tee/optee/smc_abi.c
| @@ -1849,14 +1849,6 @@ static int optee_probe(struct platform_device *pdev) | |||
| 1849 | 1849 | ||
| 1850 | 1850 | optee_set_dev_group(optee); | |
| 1851 | 1851 | ||
| 1852 | - | rc = tee_device_register(optee->teedev); | |
| 1853 | - | if (rc) | |
| 1854 | - | goto err_unreg_supp_teedev; | |
| 1855 | - | ||
| 1856 | - | rc = tee_device_register(optee->supp_teedev); | |
| 1857 | - | if (rc) | |
| 1858 | - | goto err_unreg_supp_teedev; | |
| 1859 | - | ||
| 1860 | 1852 | optee_cq_init(&optee->call_queue, thread_count); | |
| 1861 | 1853 | optee_supp_init(&optee->supp); | |
| 1862 | 1854 | optee->smc.memremaped_shm = memremaped_shm; | |
| @@ -1916,6 +1908,14 @@ static int optee_probe(struct platform_device *pdev) | |||
| 1916 | 1908 | if (optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) | |
| 1917 | 1909 | pr_info("dynamic shared memory is enabled\n"); | |
| 1918 | 1910 | ||
| 1911 | + | rc = tee_device_register(optee->teedev); | |
| 1912 | + | if (rc) | |
| 1913 | + | goto err_disable_shm_cache; | |
| 1914 | + | ||
| 1915 | + | rc = tee_device_register(optee->supp_teedev); | |
| 1916 | + | if (rc) | |
| 1917 | + | goto err_disable_shm_cache; | |
| 1918 | + | ||
| 1919 | 1919 | rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES); | |
| 1920 | 1920 | if (rc) | |
| 1921 | 1921 | goto err_disable_shm_cache; | |
| @@ -1942,7 +1942,6 @@ err_supp_uninit: | |||
| 1942 | 1942 | optee_shm_arg_cache_uninit(optee); | |
| 1943 | 1943 | optee_supp_uninit(&optee->supp); | |
| 1944 | 1944 | mutex_destroy(&optee->call_queue.mutex); | |
| 1945 | - | err_unreg_supp_teedev: | |
| 1946 | 1945 | tee_device_unregister(optee->supp_teedev); | |
| 1947 | 1946 | err_unreg_teedev: | |
| 1948 | 1947 | tee_device_unregister(optee->teedev); | |
modified drivers/tee/qcomtee/async.c
| @@ -97,10 +97,10 @@ static void qcomtee_get_async_buffer(struct qcomtee_object_invoke_ctx *oic, | |||
| 97 | 97 | /** | |
| 98 | 98 | * async_release() - Process QTEE async release requests. | |
| 99 | 99 | * @oic: context used for the current invocation. | |
| 100 | - | * @msg: async message for object release. | |
| 100 | + | * @async_msg: async message for object release. | |
| 101 | 101 | * @size: size of the async buffer available. | |
| 102 | 102 | * | |
| 103 | - | * Return: Size of the outbound buffer used when processing @msg. | |
| 103 | + | * Return: Size of the outbound buffer used when processing @async_msg. | |
| 104 | 104 | */ | |
| 105 | 105 | static size_t async_release(struct qcomtee_object_invoke_ctx *oic, | |
| 106 | 106 | struct qcomtee_async_msg_hdr *async_msg, | |
modified drivers/tee/qcomtee/qcomtee_msg.h
| @@ -112,7 +112,7 @@ union qcomtee_msg_arg { | |||
| 112 | 112 | ||
| 113 | 113 | /** | |
| 114 | 114 | * struct qcomtee_msg_object_invoke - Direct object invocation message. | |
| 115 | - | * @ctx: object ID hosted in QTEE. | |
| 115 | + | * @cxt: object ID hosted in QTEE. | |
| 116 | 116 | * @op: operation for the object. | |
| 117 | 117 | * @counts: number of different types of arguments in @args. | |
| 118 | 118 | * @args: array of arguments. | |
modified drivers/tee/qcomtee/qcomtee_object.h
| @@ -74,6 +74,7 @@ enum qcomtee_object_type { | |||
| 74 | 74 | * @QCOMTEE_ARG_TYPE_OO: output object (OO). | |
| 75 | 75 | * @QCOMTEE_ARG_TYPE_IB: input buffer (IB). | |
| 76 | 76 | * @QCOMTEE_ARG_TYPE_IO: input object (IO). | |
| 77 | + | * @QCOMTEE_ARG_TYPE_NR: number of argument types. | |
| 77 | 78 | * | |
| 78 | 79 | * Use the invalid type to specify the end of the argument array. | |
| 79 | 80 | */ | |
modified drivers/tee/tee_shm.c
| @@ -343,6 +343,10 @@ int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align, | |||
| 343 | 343 | unsigned int i; | |
| 344 | 344 | int rc = 0; | |
| 345 | 345 | ||
| 346 | + | /* get_order(0) is undefined and exceeds MAX_PAGE_ORDER. */ | |
| 347 | + | if (!nr_pages) | |
| 348 | + | return -EINVAL; | |
| 349 | + | ||
| 346 | 350 | /* | |
| 347 | 351 | * Ignore alignment since this is already going to be page aligned | |
| 348 | 352 | * and there's no need for any larger alignment. | |
modified drivers/tty/serial/8250/8250_port.c
| @@ -3417,8 +3417,11 @@ 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. | |
| 3420 | 3423 | */ | |
| 3421 | - | if (!up->console_line_ended) { | |
| 3424 | + | if (unlikely(!up->console_line_ended && !nbcon_write_context_is_braille(wctxt))) { | |
| 3422 | 3425 | if (use_fifo) | |
| 3423 | 3426 | __serial8250_console_fifo_write(up, wctxt, "\n", 1); | |
| 3424 | 3427 | 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 (!uap->console_line_ended) | |
| 2659 | + | if (unlikely(!uap->console_line_ended && !nbcon_is_braille(co))) | |
| 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 (!sport->last_putchar_was_newline) | |
| 2139 | + | if (unlikely(!sport->last_putchar_was_newline && !nbcon_is_braille(co))) | |
| 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 (!ssp->console_line_ended) | |
| 824 | + | if (unlikely(!ssp->console_line_ended && !nbcon_is_braille(co))) | |
| 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/ufs/core/ufs-mcq.c
| @@ -312,20 +312,24 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe) | |||
| 312 | 312 | UFSHCD_NUM_RESERVED; | |
| 313 | 313 | } | |
| 314 | 314 | ||
| 315 | + | static void ufshcd_mcq_compl_cqe(struct ufs_hba *hba, struct cq_entry *cqe) | |
| 316 | + | { | |
| 317 | + | int tag = ufshcd_mcq_get_tag(hba, cqe); | |
| 318 | + | ||
| 319 | + | ufshcd_compl_one_cqe(hba, tag, cqe); | |
| 320 | + | /* After processing the CQE, mark it as an empty (invalid) entry. */ | |
| 321 | + | cqe->command_desc_base_addr = 0; | |
| 322 | + | } | |
| 323 | + | ||
| 315 | 324 | static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, | |
| 316 | 325 | struct ufs_hw_queue *hwq) | |
| 317 | 326 | { | |
| 318 | 327 | struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq); | |
| 319 | 328 | ||
| 320 | - | if (cqe->command_desc_base_addr) { | |
| 321 | - | int tag = ufshcd_mcq_get_tag(hba, cqe); | |
| 322 | - | ||
| 323 | - | ufshcd_compl_one_cqe(hba, tag, cqe); | |
| 324 | - | /* After processed the cqe, mark it empty (invalid) entry */ | |
| 325 | - | cqe->command_desc_base_addr = 0; | |
| 326 | - | } else { | |
| 329 | + | if (cqe->command_desc_base_addr) | |
| 330 | + | ufshcd_mcq_compl_cqe(hba, cqe); | |
| 331 | + | else | |
| 327 | 332 | dev_err(hba->dev, "Abnormal CQ entry!\n"); | |
| 328 | - | } | |
| 329 | 333 | } | |
| 330 | 334 | ||
| 331 | 335 | /* | |
| @@ -333,7 +337,7 @@ static void ufshcd_mcq_process_cqe(struct ufs_hba *hba, | |||
| 333 | 337 | * controller disabled (HCE = 0). Reading host controller registers, e.g. the | |
| 334 | 338 | * CQ tail pointer (CQTPy), may not be safe with the host controller disabled. | |
| 335 | 339 | * Hence, iterate over all completion queue entries. This won't result in | |
| 336 | - | * double completions because ufshcd_mcq_process_cqe() clears a CQE after it | |
| 340 | + | * double completions because ufshcd_mcq_compl_cqe() clears a CQE after it | |
| 337 | 341 | * has been processed. | |
| 338 | 342 | */ | |
| 339 | 343 | void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, | |
| @@ -344,13 +348,13 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba, | |||
| 344 | 348 | ||
| 345 | 349 | spin_lock_irqsave(&hwq->cq_lock, flags); | |
| 346 | 350 | while (entries > 0) { | |
| 347 | - | ufshcd_mcq_process_cqe(hba, hwq); | |
| 351 | + | struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq); | |
| 352 | + | ||
| 353 | + | if (cqe->command_desc_base_addr) | |
| 354 | + | ufshcd_mcq_compl_cqe(hba, cqe); | |
| 348 | 355 | ufshcd_mcq_inc_cq_head_slot(hwq); | |
| 349 | 356 | entries--; | |
| 350 | 357 | } | |
| 351 | - | ||
| 352 | - | ufshcd_mcq_update_cq_tail_slot(hwq); | |
| 353 | - | hwq->cq_head_slot = hwq->cq_tail_slot; | |
| 354 | 358 | spin_unlock_irqrestore(&hwq->cq_lock, flags); | |
| 355 | 359 | } | |
| 356 | 360 | ||
modified drivers/ufs/core/ufshcd.c
| @@ -6044,8 +6044,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) | |||
| 6044 | 6044 | if (blk_mq_is_reserved_rq(rq) || !hwq) | |
| 6045 | 6045 | return true; | |
| 6046 | 6046 | ||
| 6047 | - | ufshcd_mcq_compl_all_cqes_lock(hba, hwq); | |
| 6048 | - | ||
| 6049 | 6047 | /* | |
| 6050 | 6048 | * For those cmds of which the cqes are not present in the cq, complete | |
| 6051 | 6049 | * them explicitly. | |
| @@ -6061,19 +6059,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) | |||
| 6061 | 6059 | return true; | |
| 6062 | 6060 | } | |
| 6063 | 6061 | ||
| 6064 | - | static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) | |
| 6065 | - | { | |
| 6066 | - | struct scsi_device *sdev = rq->q->queuedata; | |
| 6067 | - | struct Scsi_Host *shost = sdev->host; | |
| 6068 | - | struct ufs_hba *hba = shost_priv(shost); | |
| 6069 | - | struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); | |
| 6070 | - | ||
| 6071 | - | if (!blk_mq_is_reserved_rq(rq) && hwq) | |
| 6072 | - | ufshcd_mcq_poll_cqe_lock(hba, hwq); | |
| 6073 | - | ||
| 6074 | - | return true; | |
| 6075 | - | } | |
| 6076 | - | ||
| 6077 | 6062 | /** | |
| 6078 | 6063 | * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is | |
| 6079 | 6064 | * invoked from the error handler context or ufshcd_host_reset_and_restore() | |
| @@ -6088,10 +6073,18 @@ static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) | |||
| 6088 | 6073 | static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, | |
| 6089 | 6074 | bool force_compl) | |
| 6090 | 6075 | { | |
| 6091 | - | blk_mq_tagset_busy_iter(&hba->host->tag_set, | |
| 6092 | - | force_compl ? ufshcd_mcq_force_compl_one : | |
| 6093 | - | ufshcd_mcq_compl_one, | |
| 6094 | - | NULL); | |
| 6076 | + | int i; | |
| 6077 | + | ||
| 6078 | + | for (i = 0; i < hba->nr_hw_queues; i++) { | |
| 6079 | + | if (force_compl) | |
| 6080 | + | ufshcd_mcq_compl_all_cqes_lock(hba, &hba->uhq[i]); | |
| 6081 | + | else | |
| 6082 | + | ufshcd_mcq_poll_cqe_lock(hba, &hba->uhq[i]); | |
| 6083 | + | } | |
| 6084 | + | ||
| 6085 | + | if (force_compl) | |
| 6086 | + | blk_mq_tagset_busy_iter(&hba->host->tag_set, | |
| 6087 | + | ufshcd_mcq_force_compl_one, NULL); | |
| 6095 | 6088 | } | |
| 6096 | 6089 | ||
| 6097 | 6090 | /** | |
| @@ -9556,6 +9549,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) | |||
| 9556 | 9549 | ret = ufshcd_add_lus(hba); | |
| 9557 | 9550 | ||
| 9558 | 9551 | out: | |
| 9552 | + | ufshcd_release(hba); | |
| 9559 | 9553 | pm_runtime_put_sync(hba->dev); | |
| 9560 | 9554 | ||
| 9561 | 9555 | if (ret) | |
| @@ -11278,6 +11272,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11278 | 11272 | ||
| 11279 | 11273 | ufshcd_init_clk_gating(hba); | |
| 11280 | 11274 | ||
| 11275 | + | /* Released by ufshcd_async_scan(), or by out_release on failure. */ | |
| 11276 | + | ufshcd_hold(hba); | |
| 11277 | + | ||
| 11281 | 11278 | ufshcd_init_clk_scaling(hba); | |
| 11282 | 11279 | ||
| 11283 | 11280 | /* | |
| @@ -11298,7 +11295,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11298 | 11295 | err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba); | |
| 11299 | 11296 | if (err) { | |
| 11300 | 11297 | dev_err(hba->dev, "request irq failed\n"); | |
| 11301 | - | goto out_disable; | |
| 11298 | + | goto out_release; | |
| 11302 | 11299 | } else { | |
| 11303 | 11300 | hba->is_irq_enabled = true; | |
| 11304 | 11301 | } | |
| @@ -11314,7 +11311,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11314 | 11311 | dev_err(hba->dev, "Host controller enable failed\n"); | |
| 11315 | 11312 | ufshcd_print_evt_hist(hba); | |
| 11316 | 11313 | ufshcd_print_host_state(hba); | |
| 11317 | - | goto out_disable; | |
| 11314 | + | goto out_release; | |
| 11318 | 11315 | } | |
| 11319 | 11316 | ||
| 11320 | 11317 | INIT_DELAYED_WORK(&hba->rpm_dev_flush_recheck_work, ufshcd_rpm_dev_flush_recheck_work); | |
| @@ -11328,7 +11325,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11328 | 11325 | ||
| 11329 | 11326 | err = ufshcd_add_scsi_host(hba); | |
| 11330 | 11327 | if (err) | |
| 11331 | - | goto out_disable; | |
| 11328 | + | goto out_release; | |
| 11332 | 11329 | ||
| 11333 | 11330 | /* Hold auto suspend until async scan completes */ | |
| 11334 | 11331 | pm_runtime_get_sync(dev); | |
| @@ -11348,7 +11345,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11348 | 11345 | ||
| 11349 | 11346 | err = ufshcd_link_startup(hba); | |
| 11350 | 11347 | if (err) | |
| 11351 | - | goto out_disable; | |
| 11348 | + | goto out_release; | |
| 11352 | 11349 | ||
| 11353 | 11350 | if (hba->mcq_enabled) | |
| 11354 | 11351 | ufshcd_config_mcq(hba); | |
| @@ -11365,23 +11362,23 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) | |||
| 11365 | 11362 | /* Verify device initialization by sending NOP OUT UPIU */ | |
| 11366 | 11363 | err = ufshcd_verify_dev_init(hba); | |
| 11367 | 11364 | if (err) | |
| 11368 | - | goto out_disable; | |
| 11365 | + | goto out_release; | |
| 11369 | 11366 | ||
| 11370 | 11367 | /* Initiate UFS initialization, and waiting until completion */ | |
| 11371 | 11368 | err = ufshcd_complete_dev_init(hba); | |
| 11372 | 11369 | if (err) | |
| 11373 | - | goto out_disable; | |
| 11370 | + | goto out_release; | |
| 11374 | 11371 | ||
| 11375 | 11372 | err = ufshcd_device_params_init(hba); | |
| 11376 | 11373 | if (err) | |
| 11377 | - | goto out_disable; | |
| 11374 | + | goto out_release; | |
| 11378 | 11375 | ||
| 11379 | 11376 | err = ufshcd_post_device_init(hba); | |
| 11380 | 11377 | ||
| 11381 | 11378 | initialized: | |
| 11382 | 11379 | ufshcd_process_probe_result(hba, probe_start, err); | |
| 11383 | 11380 | if (err) | |
| 11384 | - | goto out_disable; | |
| 11381 | + | goto out_release; | |
| 11385 | 11382 | ||
| 11386 | 11383 | ufs_sysfs_add_nodes(hba->dev); | |
| 11387 | 11384 | hba->dme_qos_sysfs_handle = sysfs_get_dirent(hba->dev->kobj.sd, | |
| @@ -11392,6 +11389,8 @@ initialized: | |||
| 11392 | 11389 | ufshcd_pm_qos_init(hba); | |
| 11393 | 11390 | return 0; | |
| 11394 | 11391 | ||
| 11392 | + | out_release: | |
| 11393 | + | ufshcd_release(hba); | |
| 11395 | 11394 | out_disable: | |
| 11396 | 11395 | hba->is_irq_enabled = false; | |
| 11397 | 11396 | ufshcd_hba_exit(hba); | |
modified drivers/ufs/host/ufs-mediatek.c
| @@ -509,6 +509,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on) | |||
| 509 | 509 | struct ufs_mtk_host *host = ufshcd_get_variant(hba); | |
| 510 | 510 | struct phy *mphy = host->mphy; | |
| 511 | 511 | struct arm_smccc_res res; | |
| 512 | + | int err; | |
| 512 | 513 | int ret = 0; | |
| 513 | 514 | ||
| 514 | 515 | if (!mphy || !(on ^ host->mphy_powered_on)) | |
| @@ -523,7 +524,18 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on) | |||
| 523 | 524 | usleep_range(200, 210); | |
| 524 | 525 | ufs_mtk_va09_pwr_ctrl(res, 1); | |
| 525 | 526 | } | |
| 526 | - | phy_power_on(mphy); | |
| 527 | + | ret = phy_power_on(mphy); | |
| 528 | + | if (ret) { | |
| 529 | + | if (ufs_mtk_is_va09_supported(hba)) { | |
| 530 | + | ufs_mtk_va09_pwr_ctrl(res, 0); | |
| 531 | + | err = regulator_disable(host->reg_va09); | |
| 532 | + | if (err) | |
| 533 | + | dev_err(hba->dev, | |
| 534 | + | "failed to unwind va09: %d\n", err); | |
| 535 | + | } | |
| 536 | + | dev_err(hba->dev, "failed to enable mphy: %d\n", ret); | |
| 537 | + | return ret; | |
| 538 | + | } | |
| 527 | 539 | } else { | |
| 528 | 540 | phy_power_off(mphy); | |
| 529 | 541 | if (ufs_mtk_is_va09_supported(hba)) { | |
| @@ -1295,7 +1307,9 @@ static int ufs_mtk_init(struct ufs_hba *hba) | |||
| 1295 | 1307 | * | |
| 1296 | 1308 | * Enable phy clocks specifically here. | |
| 1297 | 1309 | */ | |
| 1298 | - | ufs_mtk_mphy_power_on(hba, true); | |
| 1310 | + | err = ufs_mtk_mphy_power_on(hba, true); | |
| 1311 | + | if (err) | |
| 1312 | + | goto out_variant_clear; | |
| 1299 | 1313 | ||
| 1300 | 1314 | if (ufs_mtk_is_rtff_mtcmos(hba)) { | |
| 1301 | 1315 | /* First Restore here, to avoid backup unexpected value */ | |
modified drivers/usb/mtu3/mtu3_trace.h
| @@ -224,6 +224,7 @@ DECLARE_EVENT_CLASS(mtu3_log_ep, | |||
| 224 | 224 | __field(unsigned int, flags) | |
| 225 | 225 | __field(unsigned int, direction) | |
| 226 | 226 | __field(struct mtu3_gpd_ring *, gpd_ring) | |
| 227 | + | __field(dma_addr_t, gpd_ring_dma) | |
| 227 | 228 | ), | |
| 228 | 229 | TP_fast_assign( | |
| 229 | 230 | __assign_str(name); | |
| @@ -235,12 +236,13 @@ DECLARE_EVENT_CLASS(mtu3_log_ep, | |||
| 235 | 236 | __entry->flags = mep->flags; | |
| 236 | 237 | __entry->direction = mep->is_in; | |
| 237 | 238 | __entry->gpd_ring = &mep->gpd_ring; | |
| 239 | + | __entry->gpd_ring_dma = mep->gpd_ring.dma | |
| 238 | 240 | ), | |
| 239 | 241 | TP_printk("%s: type %s maxp %d slot %d mult %d burst %d ring %p/%pad flags %c:%c%c%c:%c", | |
| 240 | 242 | __get_str(name), usb_ep_type_string(__entry->type), | |
| 241 | 243 | __entry->maxp, __entry->slot, | |
| 242 | 244 | __entry->mult, __entry->maxburst, | |
| 243 | - | __entry->gpd_ring, &__entry->gpd_ring->dma, | |
| 245 | + | __entry->gpd_ring, &__entry->gpd_ring_dma, | |
| 244 | 246 | __entry->flags & MTU3_EP_ENABLED ? 'E' : 'e', | |
| 245 | 247 | __entry->flags & MTU3_EP_STALL ? 'S' : 's', | |
| 246 | 248 | __entry->flags & MTU3_EP_WEDGE ? 'W' : 'w', | |
modified fs/btrfs/inode.c
| @@ -9623,7 +9623,6 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, | |||
| 9623 | 9623 | struct completion sync_reads; | |
| 9624 | 9624 | unsigned long i = 0; | |
| 9625 | 9625 | struct btrfs_bio *bbio; | |
| 9626 | - | int ret; | |
| 9627 | 9626 | ||
| 9628 | 9627 | /* | |
| 9629 | 9628 | * Fast path for synchronous reads which completes in this call, io_uring | |
| @@ -9670,10 +9669,10 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode, | |||
| 9670 | 9669 | ||
| 9671 | 9670 | if (uring_ctx) { | |
| 9672 | 9671 | if (refcount_dec_and_test(&priv->pending_refs)) { | |
| 9673 | - | ret = blk_status_to_errno(READ_ONCE(priv->status)); | |
| 9674 | - | btrfs_uring_read_extent_endio(uring_ctx, ret); | |
| 9672 | + | int error = blk_status_to_errno(READ_ONCE(priv->status)); | |
| 9673 | + | ||
| 9674 | + | btrfs_uring_read_extent_endio(uring_ctx, error); | |
| 9675 | 9675 | kfree(priv); | |
| 9676 | - | return ret; | |
| 9677 | 9676 | } | |
| 9678 | 9677 | ||
| 9679 | 9678 | return -EIOCBQUEUED; | |
modified fs/btrfs/ioctl.c
| @@ -4601,7 +4601,7 @@ static void btrfs_uring_read_finished(struct io_tw_req tw_req, io_tw_token_t tw) | |||
| 4601 | 4601 | size_t page_offset; | |
| 4602 | 4602 | ssize_t ret; | |
| 4603 | 4603 | ||
| 4604 | - | /* The inode lock has already been acquired in btrfs_uring_read_extent. */ | |
| 4604 | + | /* The inode lock has already been acquired in btrfs_encoded_read(). */ | |
| 4605 | 4605 | btrfs_lockdep_inode_acquire(inode, i_rwsem); | |
| 4606 | 4606 | ||
| 4607 | 4607 | if (priv->err) { | |
| @@ -4667,7 +4667,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter, | |||
| 4667 | 4667 | struct iovec *iov, struct io_uring_cmd *cmd) | |
| 4668 | 4668 | { | |
| 4669 | 4669 | struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp)); | |
| 4670 | - | struct extent_io_tree *io_tree = &inode->io_tree; | |
| 4671 | 4670 | struct page **pages = NULL; | |
| 4672 | 4671 | struct btrfs_uring_priv *priv = NULL; | |
| 4673 | 4672 | unsigned long nr_pages; | |
| @@ -4723,8 +4722,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter, | |||
| 4723 | 4722 | return -EIOCBQUEUED; | |
| 4724 | 4723 | ||
| 4725 | 4724 | out_fail: | |
| 4726 | - | btrfs_unlock_extent(io_tree, start, lockend, &cached_state); | |
| 4727 | - | btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); | |
| 4728 | 4725 | kfree(priv); | |
| 4729 | 4726 | for (int i = 0; i < nr_pages; i++) { | |
| 4730 | 4727 | if (pages[i]) | |
| @@ -4837,7 +4834,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue | |||
| 4837 | 4834 | ret = btrfs_encoded_read(&kiocb, &data->iter, &data->args, &cached_state, | |
| 4838 | 4835 | &disk_bytenr, &disk_io_size); | |
| 4839 | 4836 | if (ret == -EAGAIN) | |
| 4840 | - | goto out_acct; | |
| 4837 | + | goto out_free; | |
| 4841 | 4838 | if (ret < 0 && ret != -EIOCBQUEUED) | |
| 4842 | 4839 | goto out_free; | |
| 4843 | 4840 | ||
| @@ -4865,8 +4862,10 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue | |||
| 4865 | 4862 | cached_state, disk_bytenr, disk_io_size, | |
| 4866 | 4863 | count, data->args.compression, | |
| 4867 | 4864 | data->iov, cmd); | |
| 4868 | - | ||
| 4869 | - | goto out_acct; | |
| 4865 | + | if (ret == -EIOCBQUEUED) | |
| 4866 | + | goto out_acct; | |
| 4867 | + | btrfs_unlock_extent(io_tree, start, lockend, &cached_state); | |
| 4868 | + | btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); | |
| 4870 | 4869 | } | |
| 4871 | 4870 | ||
| 4872 | 4871 | out_free: | |
| @@ -4877,8 +4876,10 @@ out_acct: | |||
| 4877 | 4876 | add_rchar(current, ret); | |
| 4878 | 4877 | inc_syscr(current); | |
| 4879 | 4878 | ||
| 4880 | - | if (ret != -EIOCBQUEUED && ret != -EAGAIN) | |
| 4879 | + | if (ret != -EIOCBQUEUED) { | |
| 4881 | 4880 | kfree(data); | |
| 4881 | + | bc->data = NULL; | |
| 4882 | + | } | |
| 4882 | 4883 | ||
| 4883 | 4884 | return ret; | |
| 4884 | 4885 | } | |
| @@ -4907,6 +4908,11 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu | |||
| 4907 | 4908 | goto out_acct; | |
| 4908 | 4909 | } | |
| 4909 | 4910 | ||
| 4911 | + | if (issue_flags & IO_URING_F_NONBLOCK) { | |
| 4912 | + | ret = -EAGAIN; | |
| 4913 | + | goto out_acct; | |
| 4914 | + | } | |
| 4915 | + | ||
| 4910 | 4916 | if (!data) { | |
| 4911 | 4917 | data = kzalloc_obj(*data, GFP_NOFS); | |
| 4912 | 4918 | if (!data) { | |
| @@ -4975,11 +4981,6 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu | |||
| 4975 | 4981 | } | |
| 4976 | 4982 | } | |
| 4977 | 4983 | ||
| 4978 | - | if (issue_flags & IO_URING_F_NONBLOCK) { | |
| 4979 | - | ret = -EAGAIN; | |
| 4980 | - | goto out_acct; | |
| 4981 | - | } | |
| 4982 | - | ||
| 4983 | 4984 | pos = data->args.offset; | |
| 4984 | 4985 | ret = rw_verify_area(WRITE, file, &pos, data->args.len); | |
| 4985 | 4986 | if (ret < 0) | |
| @@ -5005,8 +5006,8 @@ out_acct: | |||
| 5005 | 5006 | add_wchar(current, ret); | |
| 5006 | 5007 | inc_syscw(current); | |
| 5007 | 5008 | ||
| 5008 | - | if (ret != -EAGAIN) | |
| 5009 | - | kfree(data); | |
| 5009 | + | kfree(data); | |
| 5010 | + | bc->data = NULL; | |
| 5010 | 5011 | return ret; | |
| 5011 | 5012 | } | |
| 5012 | 5013 | ||
modified fs/btrfs/scrub.c
| @@ -536,8 +536,10 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes, | |||
| 536 | 536 | } | |
| 537 | 537 | ret = paths_from_inode(inum, ipath); | |
| 538 | 538 | ||
| 539 | - | if (ret < 0) | |
| 539 | + | if (ret < 0) { | |
| 540 | + | btrfs_put_root(local_root); | |
| 540 | 541 | goto err; | |
| 542 | + | } | |
| 541 | 543 | ||
| 542 | 544 | /* | |
| 543 | 545 | * we deliberately ignore the bit ipath might have been too small to | |
modified fs/btrfs/transaction.c
| @@ -432,6 +432,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans, | |||
| 432 | 432 | spin_lock(&fs_info->fs_roots_radix_lock); | |
| 433 | 433 | if (btrfs_get_root_last_trans(root) == trans->transid && !force) { | |
| 434 | 434 | spin_unlock(&fs_info->fs_roots_radix_lock); | |
| 435 | + | clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); | |
| 435 | 436 | return 0; | |
| 436 | 437 | } | |
| 437 | 438 | radix_tree_tag_set(&fs_info->fs_roots_radix, | |
modified fs/btrfs/xattr.c
| @@ -161,6 +161,7 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode, | |||
| 161 | 161 | const u16 old_data_len = btrfs_dir_data_len(leaf, di); | |
| 162 | 162 | const u32 item_size = btrfs_item_size(leaf, slot); | |
| 163 | 163 | const u32 data_size = sizeof(*di) + name_len + size; | |
| 164 | + | unsigned long name_ptr; | |
| 164 | 165 | unsigned long data_ptr; | |
| 165 | 166 | char *ptr; | |
| 166 | 167 | ||
| @@ -189,8 +190,16 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode, | |||
| 189 | 190 | ptr = btrfs_item_ptr(leaf, slot, char); | |
| 190 | 191 | ptr += btrfs_item_size(leaf, slot) - data_size; | |
| 191 | 192 | di = (struct btrfs_dir_item *)ptr; | |
| 193 | + | memzero_extent_buffer(leaf, (unsigned long)ptr + | |
| 194 | + | offsetof(struct btrfs_dir_item, location), | |
| 195 | + | sizeof(struct btrfs_disk_key)); | |
| 196 | + | btrfs_set_dir_flags(leaf, di, BTRFS_FT_XATTR); | |
| 197 | + | btrfs_set_dir_transid(leaf, di, trans->transid); | |
| 198 | + | btrfs_set_dir_name_len(leaf, di, name_len); | |
| 192 | 199 | btrfs_set_dir_data_len(leaf, di, size); | |
| 200 | + | name_ptr = (unsigned long)(di + 1); | |
| 193 | 201 | data_ptr = ((unsigned long)(di + 1)) + name_len; | |
| 202 | + | write_extent_buffer(leaf, name, name_ptr, name_len); | |
| 194 | 203 | write_extent_buffer(leaf, value, data_ptr, size); | |
| 195 | 204 | } else { | |
| 196 | 205 | /* | |
| @@ -320,10 +329,8 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
| 320 | 329 | if (!size) | |
| 321 | 330 | goto next; | |
| 322 | 331 | ||
| 323 | - | if (!buffer || (name_len + 1) > size_left) { | |
| 324 | - | iter_ret = -ERANGE; | |
| 325 | - | break; | |
| 326 | - | } | |
| 332 | + | if (!buffer || (name_len + 1) > size_left) | |
| 333 | + | return -ERANGE; | |
| 327 | 334 | ||
| 328 | 335 | read_extent_buffer(leaf, buffer, name_ptr, name_len); | |
| 329 | 336 | buffer[name_len] = '\0'; | |
modified fs/dcache.c
| @@ -1583,6 +1583,8 @@ EXPORT_SYMBOL(path_has_submounts); | |||
| 1583 | 1583 | * | |
| 1584 | 1584 | * Only one of d_invalidate() and d_set_mounted() must succeed. For | |
| 1585 | 1585 | * this reason take rename_lock and d_lock on dentry and ancestors. | |
| 1586 | + | * Likewise for dont_mount() which marks a dentry that is being removed | |
| 1587 | + | * under d_lock. | |
| 1586 | 1588 | */ | |
| 1587 | 1589 | int d_set_mounted(struct dentry *dentry) | |
| 1588 | 1590 | { | |
| @@ -1599,7 +1601,7 @@ int d_set_mounted(struct dentry *dentry) | |||
| 1599 | 1601 | spin_unlock(&p->d_lock); | |
| 1600 | 1602 | } | |
| 1601 | 1603 | spin_lock(&dentry->d_lock); | |
| 1602 | - | if (!d_unlinked(dentry)) { | |
| 1604 | + | if (!d_unlinked(dentry) && !cant_mount(dentry)) { | |
| 1603 | 1605 | ret = -EBUSY; | |
| 1604 | 1606 | if (!d_mountpoint(dentry)) { | |
| 1605 | 1607 | dentry->d_flags |= DCACHE_MOUNTED; | |
modified fs/ext4/super.c
| @@ -5057,6 +5057,7 @@ out: | |||
| 5057 | 5057 | static int ext4_check_journal_data_mode(struct super_block *sb) | |
| 5058 | 5058 | { | |
| 5059 | 5059 | if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { | |
| 5060 | + | printk(KERN_WARNING "EXT4-fs: The data=journal mount option is deprecated and support will be removed in January 2028\n"); | |
| 5060 | 5061 | printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with " | |
| 5061 | 5062 | "data=journal disables delayed allocation, " | |
| 5062 | 5063 | "dioread_nolock, O_DIRECT and fast_commit support!\n"); | |
modified fs/fcntl.c
| @@ -372,6 +372,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned long arg) | |||
| 372 | 372 | u64 __user *argp = (u64 __user *)arg; | |
| 373 | 373 | u64 hint; | |
| 374 | 374 | ||
| 375 | + | /* nothing is ever written to it */ | |
| 376 | + | if (IS_IMMUTABLE(inode)) | |
| 377 | + | return -EPERM; | |
| 375 | 378 | if (!inode_owner_or_capable(file_mnt_idmap(file), inode)) | |
| 376 | 379 | return -EPERM; | |
| 377 | 380 | ||
modified fs/fhandle.c
| @@ -298,6 +298,22 @@ static bool capable_wrt_mount(struct mount *mount) | |||
| 298 | 298 | return mnt_ns && ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN); | |
| 299 | 299 | } | |
| 300 | 300 | ||
| 301 | + | /* | |
| 302 | + | * Does the caller have an unobstructed way to everything below @root? Only | |
| 303 | + | * if the mount is mounted, the caller is privileged over its mount namespace | |
| 304 | + | * and no locked child covers something below @root->dentry. One answer from | |
| 305 | + | * under mount_lock: an umount in between clears ->mnt_ns and takes the | |
| 306 | + | * children off the mount, the locked ones too. | |
| 307 | + | */ | |
| 308 | + | static bool subtree_unobstructed(const struct path *root) | |
| 309 | + | { | |
| 310 | + | struct mount *mnt = real_mount(root->mnt); | |
| 311 | + | ||
| 312 | + | guard(mount_locked_reader)(); | |
| 313 | + | return is_mounted(root->mnt) && capable_wrt_mount(mnt) && | |
| 314 | + | !has_locked_children(mnt, root->dentry); | |
| 315 | + | } | |
| 316 | + | ||
| 301 | 317 | static inline int may_decode_fh(struct handle_to_path_ctx *ctx, | |
| 302 | 318 | unsigned int o_flags) | |
| 303 | 319 | { | |
| @@ -332,9 +348,7 @@ static inline int may_decode_fh(struct handle_to_path_ctx *ctx, | |||
| 332 | 348 | ||
| 333 | 349 | if (ns_capable(root->mnt->mnt_sb->s_user_ns, CAP_SYS_ADMIN)) | |
| 334 | 350 | ctx->flags = HANDLE_CHECK_PERMS; | |
| 335 | - | else if (is_mounted(root->mnt) && | |
| 336 | - | capable_wrt_mount(real_mount(root->mnt)) && | |
| 337 | - | !has_locked_children(real_mount(root->mnt), root->dentry)) | |
| 351 | + | else if (subtree_unobstructed(root)) | |
| 338 | 352 | ctx->flags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE; | |
| 339 | 353 | else | |
| 340 | 354 | return -EPERM; | |
modified fs/file_table.c
| @@ -520,7 +520,8 @@ static void __fput(struct file *file) | |||
| 520 | 520 | dput(dentry); | |
| 521 | 521 | if (unlikely(mode & FMODE_NEED_UNMOUNT)) | |
| 522 | 522 | dissolve_on_fput(mnt); | |
| 523 | - | mntput(mnt); | |
| 523 | + | else | |
| 524 | + | mntput(mnt); | |
| 524 | 525 | out: | |
| 525 | 526 | file_free(file); | |
| 526 | 527 | } | |
modified fs/fs_context.c
| @@ -315,6 +315,10 @@ struct fs_context *fs_context_for_reconfigure(struct dentry *dentry, | |||
| 315 | 315 | unsigned int sb_flags, | |
| 316 | 316 | unsigned int sb_flags_mask) | |
| 317 | 317 | { | |
| 318 | + | /* kernel-internal superblocks are nobody's to reconfigure */ | |
| 319 | + | if (dentry->d_sb->s_flags & SB_NOUSER) | |
| 320 | + | return ERR_PTR(-EINVAL); | |
| 321 | + | ||
| 318 | 322 | return alloc_fs_context(dentry->d_sb->s_type, dentry, sb_flags, | |
| 319 | 323 | sb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE); | |
| 320 | 324 | } | |
modified fs/mount.h
| @@ -6,6 +6,8 @@ | |||
| 6 | 6 | #include <linux/fs_pin.h> | |
| 7 | 7 | ||
| 8 | 8 | extern struct file_system_type nullfs_fs_type; | |
| 9 | + | extern struct dentry *nullfs_new_file(struct super_block *sb); | |
| 10 | + | extern struct vfsmount *knullfs; | |
| 9 | 11 | extern struct list_head notify_list; | |
| 10 | 12 | ||
| 11 | 13 | struct mnt_namespace { | |
| @@ -33,16 +35,20 @@ struct mnt_namespace { | |||
| 33 | 35 | } __randomize_layout; | |
| 34 | 36 | ||
| 35 | 37 | struct mnt_pcp { | |
| 36 | - | int mnt_count; | |
| 38 | + | unsigned int mnt_gets; | |
| 39 | + | unsigned int mnt_puts; | |
| 37 | 40 | int mnt_writers; | |
| 38 | 41 | }; | |
| 39 | 42 | ||
| 40 | 43 | struct mountpoint { | |
| 41 | 44 | struct hlist_node m_hash; | |
| 42 | 45 | struct dentry *m_dentry; | |
| 43 | - | struct hlist_head m_list; | |
| 46 | + | struct hlist_head m_list; /* mounts on it and pins */ | |
| 47 | + | struct hlist_head m_covers; /* covers of unmounted parents */ | |
| 44 | 48 | }; | |
| 45 | 49 | ||
| 50 | + | struct mnt_cover; | |
| 51 | + | ||
| 46 | 52 | struct mount { | |
| 47 | 53 | struct hlist_node mnt_hash; | |
| 48 | 54 | struct mount *mnt_parent; | |
| @@ -84,7 +90,7 @@ struct mount { | |||
| 84 | 90 | struct mountpoint *mnt_mp; /* where is it mounted */ | |
| 85 | 91 | union { | |
| 86 | 92 | struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */ | |
| 87 | - | struct hlist_node mnt_umount; | |
| 93 | + | struct hlist_node mnt_umount; /* on the unmounted list */ | |
| 88 | 94 | }; | |
| 89 | 95 | #ifdef CONFIG_FSNOTIFY | |
| 90 | 96 | struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks; | |
| @@ -98,7 +104,8 @@ struct mount { | |||
| 98 | 104 | int mnt_group_id; /* peer group identifier */ | |
| 99 | 105 | int mnt_expiry_mark; /* true if marked for expiry */ | |
| 100 | 106 | struct hlist_head mnt_pins; | |
| 101 | - | struct hlist_head mnt_stuck_children; | |
| 107 | + | struct mnt_cover *mnt_cover; /* the one it may leave behind */ | |
| 108 | + | struct hlist_head mnt_covers; /* left behind by its unmounted children */ | |
| 102 | 109 | struct hlist_node mnt_ns_visible; /* link in ns->mnt_visible_mounts */ | |
| 103 | 110 | struct mount *overmount; /* mounted on ->mnt_root */ | |
| 104 | 111 | } __randomize_layout; | |
| @@ -233,6 +240,9 @@ static inline struct mnt_namespace *to_mnt_ns(struct ns_common *ns) | |||
| 233 | 240 | #ifdef CONFIG_FSNOTIFY | |
| 234 | 241 | static inline void mnt_notify_add(struct mount *m) | |
| 235 | 242 | { | |
| 243 | + | /* queued already under this namespace_sem hold */ | |
| 244 | + | if (!list_empty(&m->to_notify)) | |
| 245 | + | return; | |
| 236 | 246 | /* Optimize the case where there are no watches */ | |
| 237 | 247 | if ((m->mnt_ns && m->mnt_ns->n_fsnotify_marks) || | |
| 238 | 248 | (m->prev_ns && m->prev_ns->n_fsnotify_marks)) | |
modified fs/namei.c
| @@ -2086,6 +2086,33 @@ all_done: // pure jump | |||
| 2086 | 2086 | return NULL; | |
| 2087 | 2087 | } | |
| 2088 | 2088 | ||
| 2089 | + | /* | |
| 2090 | + | * Be careful in case the dentry is unlinked or renamed. Any mounts | |
| 2091 | + | * stacked on top of it are going away. We need to make sure that we | |
| 2092 | + | * don't reveal the underyling dentry during refwalk. In rcuwalk we | |
| 2093 | + | * catch this via d_seq and another lookup for the name. Give the same | |
| 2094 | + | * guarantee in refwalk. | |
| 2095 | + | */ | |
| 2096 | + | static bool unlink_may_reveal(struct nameidata *nd, int flags, | |
| 2097 | + | struct path *path, struct dentry *dentry) | |
| 2098 | + | { | |
| 2099 | + | /* ".." and LOOKUP_DOWN may land on an unhashed directory */ | |
| 2100 | + | if (flags & WALK_NOFOLLOW) | |
| 2101 | + | return false; | |
| 2102 | + | if (nd->flags & LOOKUP_REVAL) | |
| 2103 | + | return false; | |
| 2104 | + | /* We crossed onto a mount and the name led us here while it still existed */ | |
| 2105 | + | if (path->mnt != nd->path.mnt) | |
| 2106 | + | return false; | |
| 2107 | + | /* only a name on its way out is flagged */ | |
| 2108 | + | if (likely(!cant_mount(dentry))) | |
| 2109 | + | return false; | |
| 2110 | + | if (!d_unlinked(dentry)) | |
| 2111 | + | return false; | |
| 2112 | + | dput(no_free_ptr(path->dentry)); | |
| 2113 | + | return true; | |
| 2114 | + | } | |
| 2115 | + | ||
| 2089 | 2116 | /* | |
| 2090 | 2117 | * Do we need to follow links? We _really_ want to be able | |
| 2091 | 2118 | * to do this check without having to look at inode->i_op, | |
| @@ -2115,6 +2142,8 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags, | |||
| 2115 | 2142 | if (unlikely(!inode)) | |
| 2116 | 2143 | return ERR_PTR(-ENOENT); | |
| 2117 | 2144 | } else { | |
| 2145 | + | if (unlikely(unlink_may_reveal(nd, flags, &path, dentry))) | |
| 2146 | + | return ERR_PTR(-ESTALE); | |
| 2118 | 2147 | dput(nd->path.dentry); | |
| 2119 | 2148 | if (nd->path.mnt != path.mnt) | |
| 2120 | 2149 | mntput(nd->path.mnt); | |
modified fs/namespace.c
| @@ -80,6 +80,8 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET; | |||
| 80 | 80 | static struct hlist_head *mount_hashtable __ro_after_init; | |
| 81 | 81 | static struct hlist_head *mountpoint_hashtable __ro_after_init; | |
| 82 | 82 | static struct kmem_cache *mnt_cache __ro_after_init; | |
| 83 | + | struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */ | |
| 84 | + | static struct vfsmount *knullfs_file __ro_after_init; /* its regular file */ | |
| 83 | 85 | static DECLARE_RWSEM(namespace_sem); | |
| 84 | 86 | static HLIST_HEAD(unmounted); /* protected by namespace_sem */ | |
| 85 | 87 | static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */ | |
| @@ -130,7 +132,6 @@ static void mnt_ns_release(struct mnt_namespace *ns) | |||
| 130 | 132 | { | |
| 131 | 133 | /* keep alive for {list,stat}mount() */ | |
| 132 | 134 | if (ns && refcount_dec_and_test(&ns->passive)) { | |
| 133 | - | fsnotify_mntns_delete(ns); | |
| 134 | 135 | put_user_ns(ns->user_ns); | |
| 135 | 136 | kfree(ns); | |
| 136 | 137 | } | |
| @@ -210,6 +211,19 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry) | |||
| 210 | 211 | return &mountpoint_hashtable[tmp & mp_hash_mask]; | |
| 211 | 212 | } | |
| 212 | 213 | ||
| 214 | + | /* | |
| 215 | + | * What an unmounted mount leaves behind at its unmounted parent instead of | |
| 216 | + | * staying attached to it. A lookup on the parent at the mountpoint finds | |
| 217 | + | * a stand-in for as long as the cover is there. The parent frees it. | |
| 218 | + | */ | |
| 219 | + | struct mnt_cover { | |
| 220 | + | struct hlist_node node; /* parent->mnt_covers, RCU */ | |
| 221 | + | struct hlist_node pin; /* mp->m_covers, keeps the mountpoint */ | |
| 222 | + | struct dentry *dentry; | |
| 223 | + | struct mountpoint *mp; | |
| 224 | + | struct rcu_head rcu; | |
| 225 | + | }; | |
| 226 | + | ||
| 213 | 227 | static int mnt_alloc_id(struct mount *mnt) | |
| 214 | 228 | { | |
| 215 | 229 | int res; | |
| @@ -249,16 +263,24 @@ void mnt_release_group_id(struct mount *mnt) | |||
| 249 | 263 | mnt->mnt_group_id = 0; | |
| 250 | 264 | } | |
| 251 | 265 | ||
| 252 | - | /* | |
| 253 | - | * vfsmount lock must be held for read | |
| 254 | - | */ | |
| 255 | - | static inline void mnt_add_count(struct mount *mnt, int n) | |
| 266 | + | static inline void mnt_inc_count(struct mount *mnt) | |
| 267 | + | { | |
| 268 | + | #ifdef CONFIG_SMP | |
| 269 | + | this_cpu_inc(mnt->mnt_pcp->mnt_gets); | |
| 270 | + | #else | |
| 271 | + | preempt_disable(); | |
| 272 | + | mnt->mnt_count++; | |
| 273 | + | preempt_enable(); | |
| 274 | + | #endif | |
| 275 | + | } | |
| 276 | + | ||
| 277 | + | static inline void mnt_dec_count(struct mount *mnt) | |
| 256 | 278 | { | |
| 257 | 279 | #ifdef CONFIG_SMP | |
| 258 | - | this_cpu_add(mnt->mnt_pcp->mnt_count, n); | |
| 280 | + | this_cpu_inc(mnt->mnt_pcp->mnt_puts); | |
| 259 | 281 | #else | |
| 260 | 282 | preempt_disable(); | |
| 261 | - | mnt->mnt_count += n; | |
| 283 | + | mnt->mnt_count--; | |
| 262 | 284 | preempt_enable(); | |
| 263 | 285 | #endif | |
| 264 | 286 | } | |
| @@ -269,14 +291,17 @@ static inline void mnt_add_count(struct mount *mnt, int n) | |||
| 269 | 291 | int mnt_get_count(struct mount *mnt) | |
| 270 | 292 | { | |
| 271 | 293 | #ifdef CONFIG_SMP | |
| 272 | - | int count = 0; | |
| 294 | + | unsigned int gets = 0, puts = 0; | |
| 273 | 295 | int cpu; | |
| 274 | 296 | ||
| 275 | - | for_each_possible_cpu(cpu) { | |
| 276 | - | count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count; | |
| 277 | - | } | |
| 297 | + | /* puts first, so a put counted here has its get counted below */ | |
| 298 | + | for_each_possible_cpu(cpu) | |
| 299 | + | puts += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_puts; | |
| 300 | + | smp_mb(); /* pairs with the smp_wmb() in mntput_no_expire() */ | |
| 301 | + | for_each_possible_cpu(cpu) | |
| 302 | + | gets += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_gets; | |
| 278 | 303 | ||
| 279 | - | return count; | |
| 304 | + | return gets - puts; | |
| 280 | 305 | #else | |
| 281 | 306 | return mnt->mnt_count; | |
| 282 | 307 | #endif | |
| @@ -288,6 +313,10 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
| 288 | 313 | if (mnt) { | |
| 289 | 314 | int err; | |
| 290 | 315 | ||
| 316 | + | mnt->mnt_cover = kzalloc_obj(struct mnt_cover, GFP_KERNEL_ACCOUNT); | |
| 317 | + | if (!mnt->mnt_cover) | |
| 318 | + | goto out_free_cache; | |
| 319 | + | ||
| 291 | 320 | err = mnt_alloc_id(mnt); | |
| 292 | 321 | if (err) | |
| 293 | 322 | goto out_free_cache; | |
| @@ -305,7 +334,7 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
| 305 | 334 | if (!mnt->mnt_pcp) | |
| 306 | 335 | goto out_free_devname; | |
| 307 | 336 | ||
| 308 | - | this_cpu_add(mnt->mnt_pcp->mnt_count, 1); | |
| 337 | + | this_cpu_inc(mnt->mnt_pcp->mnt_gets); | |
| 309 | 338 | #else | |
| 310 | 339 | mnt->mnt_count = 1; | |
| 311 | 340 | mnt->mnt_writers = 0; | |
| @@ -320,8 +349,11 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
| 320 | 349 | INIT_HLIST_HEAD(&mnt->mnt_slave_list); | |
| 321 | 350 | INIT_HLIST_NODE(&mnt->mnt_slave); | |
| 322 | 351 | INIT_HLIST_NODE(&mnt->mnt_mp_list); | |
| 323 | - | INIT_HLIST_HEAD(&mnt->mnt_stuck_children); | |
| 352 | + | INIT_HLIST_HEAD(&mnt->mnt_covers); | |
| 324 | 353 | INIT_HLIST_NODE(&mnt->mnt_ns_visible); | |
| 354 | + | #ifdef CONFIG_FSNOTIFY | |
| 355 | + | INIT_LIST_HEAD(&mnt->to_notify); | |
| 356 | + | #endif | |
| 325 | 357 | RB_CLEAR_NODE(&mnt->mnt_node); | |
| 326 | 358 | mnt->mnt.mnt_idmap = &nop_mnt_idmap; | |
| 327 | 359 | } | |
| @@ -334,6 +366,7 @@ out_free_devname: | |||
| 334 | 366 | out_free_id: | |
| 335 | 367 | mnt_free_id(mnt); | |
| 336 | 368 | out_free_cache: | |
| 369 | + | kfree(mnt->mnt_cover); | |
| 337 | 370 | kmem_cache_free(mnt_cache, mnt); | |
| 338 | 371 | return NULL; | |
| 339 | 372 | } | |
| @@ -725,6 +758,8 @@ int sb_prepare_remount_readonly(struct super_block *sb) | |||
| 725 | 758 | static void free_vfsmnt(struct mount *mnt) | |
| 726 | 759 | { | |
| 727 | 760 | mnt_idmap_put(mnt_idmap(&mnt->mnt)); | |
| 761 | + | /* NULL if it left it behind */ | |
| 762 | + | kfree(mnt->mnt_cover); | |
| 728 | 763 | kfree_const(mnt->mnt_devname); | |
| 729 | 764 | #ifdef CONFIG_SMP | |
| 730 | 765 | free_percpu(mnt->mnt_pcp); | |
| @@ -746,13 +781,13 @@ int __legitimize_mnt(struct vfsmount *bastard, unsigned seq) | |||
| 746 | 781 | if (bastard == NULL) | |
| 747 | 782 | return 0; | |
| 748 | 783 | mnt = real_mount(bastard); | |
| 749 | - | mnt_add_count(mnt, 1); | |
| 750 | - | smp_mb(); // see mntput_no_expire() and do_umount() | |
| 784 | + | mnt_inc_count(mnt); | |
| 785 | + | smp_mb(); /* see mntput_no_expire_slowpath() and do_umount() */ | |
| 751 | 786 | if (likely(!read_seqretry(&mount_lock, seq))) | |
| 752 | 787 | return 0; | |
| 753 | 788 | lock_mount_hash(); | |
| 754 | 789 | if (unlikely(bastard->mnt_flags & (MNT_SYNC_UMOUNT | MNT_DOOMED))) { | |
| 755 | - | mnt_add_count(mnt, -1); | |
| 790 | + | mnt_dec_count(mnt); | |
| 756 | 791 | unlock_mount_hash(); | |
| 757 | 792 | return 1; | |
| 758 | 793 | } | |
| @@ -781,20 +816,31 @@ static bool legitimize_mnt(struct vfsmount *bastard, unsigned seq) | |||
| 781 | 816 | * @dentry: dentry of mountpoint | |
| 782 | 817 | * | |
| 783 | 818 | * If @mnt has a child mount @c mounted on @dentry find and return it. | |
| 819 | + | * If @mnt is unmounted and a child that was unmounted with it left its | |
| 820 | + | * cover behind at @dentry, return the stand-in for it instead: knullfs | |
| 821 | + | * for a directory, its regular file for anything else. | |
| 784 | 822 | * Caller must either hold the spinlock component of @mount_lock or | |
| 785 | 823 | * hold rcu_read_lock(), sample the seqcount component before the call | |
| 786 | 824 | * and recheck it afterwards. | |
| 787 | 825 | * | |
| 788 | - | * Return: The child of @mnt mounted on @dentry or %NULL. | |
| 826 | + | * Return: The child of @mnt mounted on @dentry, a stand-in or %NULL. | |
| 789 | 827 | */ | |
| 790 | 828 | struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry) | |
| 791 | 829 | { | |
| 792 | 830 | struct hlist_head *head = m_hash(mnt, dentry); | |
| 831 | + | struct mnt_cover *cover; | |
| 793 | 832 | struct mount *p; | |
| 794 | 833 | ||
| 795 | 834 | hlist_for_each_entry_rcu(p, head, mnt_hash) | |
| 796 | 835 | if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry) | |
| 797 | 836 | return p; | |
| 837 | + | /* an unmounted mount keeps the covers its unmounted children left */ | |
| 838 | + | /* a lockless caller rechecks mount_lock after a miss, a stale flag is harmless */ | |
| 839 | + | if (unlikely(data_race(mnt->mnt_flags) & MNT_UMOUNT)) { | |
| 840 | + | hlist_for_each_entry_rcu(cover, &real_mount(mnt)->mnt_covers, node) | |
| 841 | + | if (cover->dentry == dentry) | |
| 842 | + | return real_mount(d_is_dir(dentry) ? knullfs : knullfs_file); | |
| 843 | + | } | |
| 798 | 844 | return NULL; | |
| 799 | 845 | } | |
| 800 | 846 | ||
| @@ -910,6 +956,7 @@ mountpoint: | |||
| 910 | 956 | mp->m_dentry = dget(dentry); | |
| 911 | 957 | hlist_add_head(&mp->m_hash, mp_hash(dentry)); | |
| 912 | 958 | INIT_HLIST_HEAD(&mp->m_list); | |
| 959 | + | INIT_HLIST_HEAD(&mp->m_covers); | |
| 913 | 960 | hlist_add_head(&m->node, &mp->m_list); | |
| 914 | 961 | m->mp = no_free_ptr(mp); | |
| 915 | 962 | read_sequnlock_excl(&mount_lock); | |
| @@ -922,7 +969,7 @@ mountpoint: | |||
| 922 | 969 | */ | |
| 923 | 970 | static void maybe_free_mountpoint(struct mountpoint *mp, struct list_head *list) | |
| 924 | 971 | { | |
| 925 | - | if (hlist_empty(&mp->m_list)) { | |
| 972 | + | if (hlist_empty(&mp->m_list) && hlist_empty(&mp->m_covers)) { | |
| 926 | 973 | struct dentry *dentry = mp->m_dentry; | |
| 927 | 974 | spin_lock(&dentry->d_lock); | |
| 928 | 975 | dentry->d_flags &= ~DCACHE_MOUNTED; | |
| @@ -1009,6 +1056,36 @@ static void umount_mnt(struct mount *mnt) | |||
| 1009 | 1056 | __umount_mnt(mnt, &ex_mountpoints); | |
| 1010 | 1057 | } | |
| 1011 | 1058 | ||
| 1059 | + | /* | |
| 1060 | + | * @mnt is unmounted together with its parent and would have stayed attached | |
| 1061 | + | * to it. Leave its cover behind before it is detached so that a lookup on the | |
| 1062 | + | * parent at the mountpoint keeps finding a mount instead of what @mnt covered. | |
| 1063 | + | * | |
| 1064 | + | * locks: mount_lock[write_seqlock] | |
| 1065 | + | */ | |
| 1066 | + | static void leave_cover(struct mount *mnt) | |
| 1067 | + | { | |
| 1068 | + | struct mnt_cover *cover = mnt->mnt_cover; | |
| 1069 | + | ||
| 1070 | + | mnt->mnt_cover = NULL; | |
| 1071 | + | cover->dentry = mnt->mnt_mountpoint; | |
| 1072 | + | cover->mp = mnt->mnt_mp; | |
| 1073 | + | /* keeps the mountpoint once @mnt has let go of it */ | |
| 1074 | + | hlist_add_head(&cover->pin, &cover->mp->m_covers); | |
| 1075 | + | hlist_add_head_rcu(&cover->node, &mnt->mnt_parent->mnt_covers); | |
| 1076 | + | } | |
| 1077 | + | ||
| 1078 | + | /* | |
| 1079 | + | * locks: mount_lock[write_seqlock] | |
| 1080 | + | */ | |
| 1081 | + | static void drop_cover(struct mnt_cover *cover, struct list_head *shrink_list) | |
| 1082 | + | { | |
| 1083 | + | hlist_del_rcu(&cover->node); | |
| 1084 | + | hlist_del(&cover->pin); | |
| 1085 | + | maybe_free_mountpoint(cover->mp, shrink_list); | |
| 1086 | + | kfree_rcu(cover, rcu); | |
| 1087 | + | } | |
| 1088 | + | ||
| 1012 | 1089 | /* | |
| 1013 | 1090 | * vfsmount lock must be held for write | |
| 1014 | 1091 | */ | |
| @@ -1058,7 +1135,10 @@ static void attach_mnt(struct mount *mnt, struct mount *parent, | |||
| 1058 | 1135 | void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct mount *mnt) | |
| 1059 | 1136 | { | |
| 1060 | 1137 | struct mountpoint *old_mp = mnt->mnt_mp; | |
| 1138 | + | struct mount *old_parent = mnt->mnt_parent; | |
| 1061 | 1139 | ||
| 1140 | + | if (old_parent->overmount == mnt) | |
| 1141 | + | old_parent->overmount = NULL; | |
| 1062 | 1142 | list_del_init(&mnt->mnt_child); | |
| 1063 | 1143 | hlist_del_init(&mnt->mnt_mp_list); | |
| 1064 | 1144 | hlist_del_init_rcu(&mnt->mnt_hash); | |
| @@ -1254,6 +1334,7 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, | |||
| 1254 | 1334 | ||
| 1255 | 1335 | mnt->mnt.mnt_flags = READ_ONCE(old->mnt.mnt_flags) & | |
| 1256 | 1336 | ~MNT_INTERNAL_FLAGS; | |
| 1337 | + | mnt->mnt_t_flags = old->mnt_t_flags & T_UNBINDABLE; | |
| 1257 | 1338 | ||
| 1258 | 1339 | if (flag & (CL_SLAVE | CL_PRIVATE)) | |
| 1259 | 1340 | mnt->mnt_group_id = 0; /* not a peer of original */ | |
| @@ -1296,8 +1377,6 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, | |||
| 1296 | 1377 | ||
| 1297 | 1378 | static void cleanup_mnt(struct mount *mnt) | |
| 1298 | 1379 | { | |
| 1299 | - | struct hlist_node *p; | |
| 1300 | - | struct mount *m; | |
| 1301 | 1380 | /* | |
| 1302 | 1381 | * The warning here probably indicates that somebody messed | |
| 1303 | 1382 | * up a mnt_want/drop_write() pair. If this happens, the | |
| @@ -1308,10 +1387,6 @@ static void cleanup_mnt(struct mount *mnt) | |||
| 1308 | 1387 | WARN_ON(mnt_get_writers(mnt)); | |
| 1309 | 1388 | if (unlikely(mnt->mnt_pins.first)) | |
| 1310 | 1389 | mnt_pin_kill(mnt); | |
| 1311 | - | hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) { | |
| 1312 | - | hlist_del(&m->mnt_umount); | |
| 1313 | - | mntput(&m->mnt); | |
| 1314 | - | } | |
| 1315 | 1390 | fsnotify_vfsmount_delete(&mnt->mnt); | |
| 1316 | 1391 | dput(mnt->mnt.mnt_root); | |
| 1317 | 1392 | deactivate_super(mnt->mnt.mnt_sb); | |
| @@ -1337,6 +1412,8 @@ static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput); | |||
| 1337 | 1412 | ||
| 1338 | 1413 | static void noinline mntput_no_expire_slowpath(struct mount *mnt) | |
| 1339 | 1414 | { | |
| 1415 | + | struct mnt_cover *cover; | |
| 1416 | + | struct hlist_node *n; | |
| 1340 | 1417 | LIST_HEAD(list); | |
| 1341 | 1418 | int count; | |
| 1342 | 1419 | ||
| @@ -1347,7 +1424,7 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt) | |||
| 1347 | 1424 | * mount_lock, we'll see their refcount increment here. | |
| 1348 | 1425 | */ | |
| 1349 | 1426 | smp_mb(); | |
| 1350 | - | mnt_add_count(mnt, -1); | |
| 1427 | + | mnt_dec_count(mnt); | |
| 1351 | 1428 | count = mnt_get_count(mnt); | |
| 1352 | 1429 | if (count != 0) { | |
| 1353 | 1430 | WARN_ON(count < 0); | |
| @@ -1367,13 +1444,10 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt) | |||
| 1367 | 1444 | if (unlikely(!list_empty(&mnt->mnt_expire))) | |
| 1368 | 1445 | list_del(&mnt->mnt_expire); | |
| 1369 | 1446 | ||
| 1370 | - | if (unlikely(!list_empty(&mnt->mnt_mounts))) { | |
| 1371 | - | struct mount *p, *tmp; | |
| 1372 | - | list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) { | |
| 1373 | - | __umount_mnt(p, &list); | |
| 1374 | - | hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children); | |
| 1375 | - | } | |
| 1376 | - | } | |
| 1447 | + | /* nothing stays attached to an unmounted mount */ | |
| 1448 | + | VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts)); | |
| 1449 | + | hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node) | |
| 1450 | + | drop_cover(cover, &list); | |
| 1377 | 1451 | unlock_mount_hash(); | |
| 1378 | 1452 | shrink_dentry_list(&list); | |
| 1379 | 1453 | ||
| @@ -1404,7 +1478,8 @@ static void mntput_no_expire(struct mount *mnt) | |||
| 1404 | 1478 | * non-NULL under rcu_read_lock(), the reference | |
| 1405 | 1479 | * we are dropping is not the final one. | |
| 1406 | 1480 | */ | |
| 1407 | - | mnt_add_count(mnt, -1); | |
| 1481 | + | smp_wmb(); /* pairs with the smp_mb() in mnt_get_count() */ | |
| 1482 | + | mnt_dec_count(mnt); | |
| 1408 | 1483 | rcu_read_unlock(); | |
| 1409 | 1484 | return; | |
| 1410 | 1485 | } | |
| @@ -1426,7 +1501,7 @@ EXPORT_SYMBOL(mntput); | |||
| 1426 | 1501 | struct vfsmount *mntget(struct vfsmount *mnt) | |
| 1427 | 1502 | { | |
| 1428 | 1503 | if (mnt) | |
| 1429 | - | mnt_add_count(real_mount(mnt), 1); | |
| 1504 | + | mnt_inc_count(real_mount(mnt)); | |
| 1430 | 1505 | return mnt; | |
| 1431 | 1506 | } | |
| 1432 | 1507 | EXPORT_SYMBOL(mntget); | |
| @@ -1737,36 +1812,17 @@ static inline void namespace_lock(void) | |||
| 1737 | 1812 | enum umount_tree_flags { | |
| 1738 | 1813 | UMOUNT_SYNC = 1, | |
| 1739 | 1814 | UMOUNT_PROPAGATE = 2, | |
| 1740 | - | UMOUNT_CONNECTED = 4, | |
| 1815 | + | UMOUNT_COVER = 4, | |
| 1741 | 1816 | }; | |
| 1742 | 1817 | ||
| 1743 | - | static bool disconnect_mount(struct mount *mnt, enum umount_tree_flags how) | |
| 1818 | + | /* Do we need to leave the mountpoint on the parent covered? */ | |
| 1819 | + | static bool needs_cover(struct mount *mnt, enum umount_tree_flags how) | |
| 1744 | 1820 | { | |
| 1745 | - | /* Leaving mounts connected is only valid for lazy umounts */ | |
| 1746 | 1821 | if (how & UMOUNT_SYNC) | |
| 1747 | - | return true; | |
| 1748 | - | ||
| 1749 | - | /* A mount without a parent has nothing to be connected to */ | |
| 1750 | - | if (!mnt_has_parent(mnt)) | |
| 1751 | - | return true; | |
| 1752 | - | ||
| 1753 | - | /* Because the reference counting rules change when mounts are | |
| 1754 | - | * unmounted and connected, umounted mounts may not be | |
| 1755 | - | * connected to mounted mounts. | |
| 1756 | - | */ | |
| 1757 | - | if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) | |
| 1758 | - | return true; | |
| 1759 | - | ||
| 1760 | - | /* Has it been requested that the mount remain connected? */ | |
| 1761 | - | if (how & UMOUNT_CONNECTED) | |
| 1762 | 1822 | return false; | |
| 1763 | - | ||
| 1764 | - | /* Is the mount locked such that it needs to remain connected? */ | |
| 1765 | - | if (IS_MNT_LOCKED(mnt)) | |
| 1823 | + | if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT)) | |
| 1766 | 1824 | return false; | |
| 1767 | - | ||
| 1768 | - | /* By default disconnect the mount */ | |
| 1769 | - | return true; | |
| 1825 | + | return (how & UMOUNT_COVER) || IS_MNT_LOCKED(mnt); | |
| 1770 | 1826 | } | |
| 1771 | 1827 | ||
| 1772 | 1828 | /* | |
| @@ -1783,6 +1839,8 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) | |||
| 1783 | 1839 | ||
| 1784 | 1840 | /* Gather the mounts to umount */ | |
| 1785 | 1841 | for (p = mnt; p; p = next_mnt(p, mnt)) { | |
| 1842 | + | /* A mount is unmounted once. */ | |
| 1843 | + | VFS_WARN_ON_ONCE(p->mnt.mnt_flags & MNT_UMOUNT); | |
| 1786 | 1844 | p->mnt.mnt_flags |= MNT_UMOUNT; | |
| 1787 | 1845 | if (mnt_ns_attached(p)) | |
| 1788 | 1846 | move_from_ns(p); | |
| @@ -1802,7 +1860,6 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) | |||
| 1802 | 1860 | ||
| 1803 | 1861 | while (!list_empty(&tmp_list)) { | |
| 1804 | 1862 | struct mnt_namespace *ns; | |
| 1805 | - | bool disconnect; | |
| 1806 | 1863 | p = list_first_entry(&tmp_list, struct mount, mnt_list); | |
| 1807 | 1864 | list_del_init(&p->mnt_expire); | |
| 1808 | 1865 | list_del_init(&p->mnt_list); | |
| @@ -1815,17 +1872,12 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) | |||
| 1815 | 1872 | if (how & UMOUNT_SYNC) | |
| 1816 | 1873 | p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; | |
| 1817 | 1874 | ||
| 1818 | - | disconnect = disconnect_mount(p, how); | |
| 1819 | 1875 | if (mnt_has_parent(p)) { | |
| 1820 | - | if (!disconnect) { | |
| 1821 | - | /* Don't forget about p */ | |
| 1822 | - | list_add_tail(&p->mnt_child, &p->mnt_parent->mnt_mounts); | |
| 1823 | - | } else { | |
| 1824 | - | umount_mnt(p); | |
| 1825 | - | } | |
| 1876 | + | if (needs_cover(p, how)) | |
| 1877 | + | leave_cover(p); | |
| 1878 | + | umount_mnt(p); | |
| 1826 | 1879 | } | |
| 1827 | - | if (disconnect) | |
| 1828 | - | hlist_add_head(&p->mnt_umount, &unmounted); | |
| 1880 | + | hlist_add_head(&p->mnt_umount, &unmounted); | |
| 1829 | 1881 | ||
| 1830 | 1882 | /* | |
| 1831 | 1883 | * At this point p->mnt_ns is NULL, notification will be queued | |
| @@ -1976,11 +2028,16 @@ out: | |||
| 1976 | 2028 | * detach_mounts allows lazily unmounting those mounts instead of | |
| 1977 | 2029 | * leaking them. | |
| 1978 | 2030 | * | |
| 2031 | + | * The dentry is unhashed before the mounts go so that no lookup finds | |
| 2032 | + | * what they covered. The caller removes it for good afterwards. | |
| 2033 | + | * | |
| 1979 | 2034 | * The caller may hold dentry->d_inode->i_rwsem. | |
| 1980 | 2035 | */ | |
| 1981 | 2036 | void __detach_mounts(struct dentry *dentry) | |
| 1982 | 2037 | { | |
| 1983 | 2038 | struct pinned_mountpoint mp = {}; | |
| 2039 | + | struct mnt_cover *cover; | |
| 2040 | + | struct hlist_node *n; | |
| 1984 | 2041 | struct mount *mnt; | |
| 1985 | 2042 | ||
| 1986 | 2043 | guard(namespace_excl)(); | |
| @@ -1989,15 +2046,16 @@ void __detach_mounts(struct dentry *dentry) | |||
| 1989 | 2046 | if (!lookup_mountpoint(dentry, &mp)) | |
| 1990 | 2047 | return; | |
| 1991 | 2048 | ||
| 2049 | + | /* the name goes first, what covered it goes second */ | |
| 2050 | + | d_drop(dentry); | |
| 1992 | 2051 | event++; | |
| 1993 | 2052 | while (mp.node.next) { | |
| 1994 | 2053 | mnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list); | |
| 1995 | - | if (mnt->mnt.mnt_flags & MNT_UMOUNT) { | |
| 1996 | - | umount_mnt(mnt); | |
| 1997 | - | hlist_add_head(&mnt->mnt_umount, &unmounted); | |
| 1998 | - | } | |
| 1999 | - | else umount_tree(mnt, UMOUNT_CONNECTED); | |
| 2054 | + | umount_tree(mnt, UMOUNT_COVER); | |
| 2000 | 2055 | } | |
| 2056 | + | /* the dentry goes away, so do the covers left behind on it */ | |
| 2057 | + | hlist_for_each_entry_safe(cover, n, &mp.mp->m_covers, pin) | |
| 2058 | + | drop_cover(cover, &ex_mountpoints); | |
| 2001 | 2059 | unpin_mountpoint(&mp); | |
| 2002 | 2060 | } | |
| 2003 | 2061 | ||
| @@ -2294,9 +2352,11 @@ void drop_collected_paths(const struct path *paths, const struct path *prealloc) | |||
| 2294 | 2352 | ||
| 2295 | 2353 | static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *, bool); | |
| 2296 | 2354 | ||
| 2355 | + | /* Consumes the caller's reference to @mnt. */ | |
| 2297 | 2356 | void dissolve_on_fput(struct vfsmount *mnt) | |
| 2298 | 2357 | { | |
| 2299 | - | struct mount *m = real_mount(mnt); | |
| 2358 | + | struct vfsmount *p __free(mntput) = mnt; | |
| 2359 | + | struct mount *m = real_mount(p); | |
| 2300 | 2360 | ||
| 2301 | 2361 | /* | |
| 2302 | 2362 | * m used to be the root of anon namespace; if it still is one, | |
| @@ -2319,13 +2379,14 @@ void dissolve_on_fput(struct vfsmount *mnt) | |||
| 2319 | 2379 | ||
| 2320 | 2380 | emptied_ns = m->mnt_ns; | |
| 2321 | 2381 | lock_mount_hash(); | |
| 2322 | - | umount_tree(m, UMOUNT_CONNECTED); | |
| 2382 | + | umount_tree(m, UMOUNT_COVER); | |
| 2323 | 2383 | unlock_mount_hash(); | |
| 2384 | + | mntput(no_free_ptr(p)); | |
| 2324 | 2385 | } | |
| 2325 | 2386 | } | |
| 2326 | 2387 | ||
| 2327 | 2388 | /* locks: namespace_shared && pinned(mnt) || mount_locked_reader */ | |
| 2328 | - | static bool __has_locked_children(struct mount *mnt, struct dentry *dentry) | |
| 2389 | + | bool has_locked_children(struct mount *mnt, struct dentry *dentry) | |
| 2329 | 2390 | { | |
| 2330 | 2391 | struct mount *child; | |
| 2331 | 2392 | ||
| @@ -2339,10 +2400,16 @@ static bool __has_locked_children(struct mount *mnt, struct dentry *dentry) | |||
| 2339 | 2400 | return false; | |
| 2340 | 2401 | } | |
| 2341 | 2402 | ||
| 2342 | - | bool has_locked_children(struct mount *mnt, struct dentry *dentry) | |
| 2403 | + | /* locks: namespace_shared && pinned(mnt) || mount_locked_reader */ | |
| 2404 | + | static bool __has_children(struct mount *mnt, struct dentry *dentry) | |
| 2343 | 2405 | { | |
| 2344 | - | guard(mount_locked_reader)(); | |
| 2345 | - | return __has_locked_children(mnt, dentry); | |
| 2406 | + | struct mount *child; | |
| 2407 | + | ||
| 2408 | + | list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { | |
| 2409 | + | if (is_subdir(child->mnt_mountpoint, dentry)) | |
| 2410 | + | return true; | |
| 2411 | + | } | |
| 2412 | + | return false; | |
| 2346 | 2413 | } | |
| 2347 | 2414 | ||
| 2348 | 2415 | /* | |
| @@ -2401,7 +2468,7 @@ struct vfsmount *clone_private_mount(const struct path *path) | |||
| 2401 | 2468 | if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN)) | |
| 2402 | 2469 | return ERR_PTR(-EPERM); | |
| 2403 | 2470 | ||
| 2404 | - | if (__has_locked_children(old_mnt, path->dentry)) | |
| 2471 | + | if (has_locked_children(old_mnt, path->dentry)) | |
| 2405 | 2472 | return ERR_PTR(-EINVAL); | |
| 2406 | 2473 | ||
| 2407 | 2474 | new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE); | |
| @@ -2564,11 +2631,11 @@ enum mnt_tree_flags_t { | |||
| 2564 | 2631 | static int attach_recursive_mnt(struct mount *source_mnt, | |
| 2565 | 2632 | const struct pinned_mountpoint *dest) | |
| 2566 | 2633 | { | |
| 2567 | - | struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns; | |
| 2568 | 2634 | struct mount *dest_mnt = dest->parent; | |
| 2569 | 2635 | struct mountpoint *dest_mp = dest->mp; | |
| 2570 | 2636 | HLIST_HEAD(tree_list); | |
| 2571 | 2637 | struct mnt_namespace *ns = dest_mnt->mnt_ns; | |
| 2638 | + | struct user_namespace *user_ns = ns->user_ns; | |
| 2572 | 2639 | struct pinned_mountpoint root = {}; | |
| 2573 | 2640 | struct mountpoint *shorter = NULL; | |
| 2574 | 2641 | struct mount *child, *p; | |
| @@ -2577,13 +2644,31 @@ static int attach_recursive_mnt(struct mount *source_mnt, | |||
| 2577 | 2644 | int err = 0; | |
| 2578 | 2645 | bool moving = mnt_has_parent(source_mnt); | |
| 2579 | 2646 | ||
| 2647 | + | /* | |
| 2648 | + | * A caller in an unprivileged mount namespaces may trigger an | |
| 2649 | + | * automount and propagate locked mounts into privileged mount | |
| 2650 | + | * namespaces. Take ownership from the target mount namespace. | |
| 2651 | + | * It's equivalent for everything but the automount case. | |
| 2652 | + | * | |
| 2653 | + | * Detached trees in anonymous mount namespaces by be handed | |
| 2654 | + | * over via SCM_RIGHTS or inherited in other ways on purpose | |
| 2655 | + | * the attaching task's mount namespace is authoritative, not | |
| 2656 | + | * the creator of the detached tree. | |
| 2657 | + | */ | |
| 2658 | + | if (is_anon_ns(ns)) | |
| 2659 | + | user_ns = current->nsproxy->mnt_ns->user_ns; | |
| 2660 | + | else | |
| 2661 | + | user_ns = ns->user_ns; | |
| 2662 | + | ||
| 2580 | 2663 | /* | |
| 2581 | 2664 | * Preallocate a mountpoint in case the new mounts need to be | |
| 2582 | 2665 | * mounted beneath mounts on the same mountpoint. | |
| 2583 | 2666 | */ | |
| 2584 | - | for (top = source_mnt; unlikely(top->overmount); top = top->overmount) { | |
| 2667 | + | for (top = source_mnt; ; top = top->overmount) { | |
| 2585 | 2668 | if (!shorter && is_mnt_ns_file(top->mnt.mnt_root)) | |
| 2586 | 2669 | shorter = top->mnt_mp; | |
| 2670 | + | if (likely(!top->overmount)) | |
| 2671 | + | break; | |
| 2587 | 2672 | } | |
| 2588 | 2673 | err = get_mountpoint(top->mnt.mnt_root, &root); | |
| 2589 | 2674 | if (err) | |
| @@ -2654,15 +2739,17 @@ static int attach_recursive_mnt(struct mount *source_mnt, | |||
| 2654 | 2739 | /* | |
| 2655 | 2740 | * If @q was locked it was meant to hide | |
| 2656 | 2741 | * whatever was under it. Let @child take over | |
| 2657 | - | * that job and lock it, then we can unlock @q. | |
| 2658 | - | * That'll allow another namespace to shed @q | |
| 2659 | - | * and reveal @child. Clearly, that mounter | |
| 2660 | - | * consented to this by not severing the mount | |
| 2661 | - | * relationship. Otherwise, what's the point. | |
| 2742 | + | * that job and lock it. If @child is the mount | |
| 2743 | + | * the caller placed we can then unlock @q: | |
| 2744 | + | * nothing another namespace does removes it | |
| 2745 | + | * again. A propagated copy goes away when the | |
| 2746 | + | * mounter of the original unmounts it, so @q | |
| 2747 | + | * keeps its lock. | |
| 2662 | 2748 | */ | |
| 2663 | 2749 | if (IS_MNT_LOCKED(q)) { | |
| 2664 | 2750 | child->mnt.mnt_flags |= MNT_LOCKED; | |
| 2665 | - | q->mnt.mnt_flags &= ~MNT_LOCKED; | |
| 2751 | + | if (child == source_mnt) | |
| 2752 | + | q->mnt.mnt_flags &= ~MNT_LOCKED; | |
| 2666 | 2753 | } | |
| 2667 | 2754 | mnt_change_mountpoint(r, mp, q); | |
| 2668 | 2755 | } | |
| @@ -2759,6 +2846,11 @@ static void do_lock_mount(const struct path *path, | |||
| 2759 | 2846 | ||
| 2760 | 2847 | scoped_guard(mount_locked_reader) { | |
| 2761 | 2848 | m = where_to_mount(path, &dentry, beneath); | |
| 2849 | + | /* sticky, so it takes no locks to refuse it */ | |
| 2850 | + | if (unlikely(cant_mount(dentry))) { | |
| 2851 | + | res->parent = ERR_PTR(-ENOENT); | |
| 2852 | + | return; | |
| 2853 | + | } | |
| 2762 | 2854 | if (&m->mnt != path->mnt) { | |
| 2763 | 2855 | mntget(&m->mnt); | |
| 2764 | 2856 | dget(dentry); | |
| @@ -2989,7 +3081,14 @@ static struct mount *__do_loopback(const struct path *old_path, | |||
| 2989 | 3081 | if (!may_copy_tree(old_path)) | |
| 2990 | 3082 | return ERR_PTR(-EINVAL); | |
| 2991 | 3083 | ||
| 2992 | - | if (!recurse && __has_locked_children(old, old_path->dentry)) | |
| 3084 | + | /* a pseudo dentry is freed without an RCU delay, no walk may find it */ | |
| 3085 | + | if (old_path->dentry->d_flags & DCACHE_NORCU) | |
| 3086 | + | return ERR_PTR(-EINVAL); | |
| 3087 | + | ||
| 3088 | + | if (recurse && !old->mnt_ns) | |
| 3089 | + | return ERR_PTR(-EINVAL); | |
| 3090 | + | ||
| 3091 | + | if (!recurse && has_locked_children(old, old_path->dentry)) | |
| 2993 | 3092 | return ERR_PTR(-EINVAL); | |
| 2994 | 3093 | ||
| 2995 | 3094 | if (recurse) | |
| @@ -3028,7 +3127,11 @@ static int do_loopback(const struct path *path, const char *old_name, | |||
| 3028 | 3127 | if (IS_ERR(mnt)) | |
| 3029 | 3128 | return PTR_ERR(mnt); | |
| 3030 | 3129 | ||
| 3031 | - | err = graft_tree(mnt, &mp); | |
| 3130 | + | /* the copy may carry mount namespace files from below the source */ | |
| 3131 | + | if (recurse && !check_for_nsfs_mounts(mnt)) | |
| 3132 | + | err = -EINVAL; | |
| 3133 | + | else | |
| 3134 | + | err = graft_tree(mnt, &mp); | |
| 3032 | 3135 | if (err) { | |
| 3033 | 3136 | lock_mount_hash(); | |
| 3034 | 3137 | umount_tree(mnt, UMOUNT_SYNC); | |
| @@ -3088,7 +3191,7 @@ static struct file *open_detached_copy(struct path *path, unsigned int flags) | |||
| 3088 | 3191 | path->mnt = mntget(&ns->root->mnt); | |
| 3089 | 3192 | file = dentry_open(path, O_PATH, current_cred()); | |
| 3090 | 3193 | if (IS_ERR(file)) | |
| 3091 | - | dissolve_on_fput(path->mnt); | |
| 3194 | + | dissolve_on_fput(no_free_ptr(path->mnt)); | |
| 3092 | 3195 | else | |
| 3093 | 3196 | file->f_mode |= FMODE_NEED_UNMOUNT; | |
| 3094 | 3197 | return file; | |
| @@ -3110,12 +3213,18 @@ static struct mnt_namespace *create_new_namespace(struct path *path, | |||
| 3110 | 3213 | struct mount *mnt; | |
| 3111 | 3214 | unsigned int copy_flags = 0; | |
| 3112 | 3215 | bool locked = false, recurse = flags & MOUNT_COPY_RECURSIVE; | |
| 3216 | + | bool foreign = user_ns != ns->user_ns; | |
| 3113 | 3217 | ||
| 3114 | 3218 | if (unlikely(!d_can_lookup(path->dentry))) | |
| 3115 | 3219 | return ERR_PTR(-ENOTDIR); | |
| 3116 | 3220 | ||
| 3117 | - | if (user_ns != ns->user_ns) | |
| 3118 | - | copy_flags |= CL_SLAVE; | |
| 3221 | + | /* | |
| 3222 | + | * Without privileges over the mount namespace the copy is made from | |
| 3223 | + | * nothing mounted below @path may be left out. It would reveal what | |
| 3224 | + | * it covers. That's what unshare() gives such a caller as well. | |
| 3225 | + | */ | |
| 3226 | + | if (foreign) | |
| 3227 | + | copy_flags |= CL_SLAVE | CL_COPY_UNBINDABLE; | |
| 3119 | 3228 | ||
| 3120 | 3229 | new_ns = alloc_mnt_ns(user_ns, false); | |
| 3121 | 3230 | if (IS_ERR(new_ns)) | |
| @@ -3149,10 +3258,14 @@ static struct mnt_namespace *create_new_namespace(struct path *path, | |||
| 3149 | 3258 | /* | |
| 3150 | 3259 | * We don't emulate unshare()ing a mount namespace. We stick to | |
| 3151 | 3260 | * the restrictions of creating detached bind-mounts. It has a | |
| 3152 | - | * lot saner and simpler semantics. | |
| 3261 | + | * lot saner and simpler semantics. A caller without privileges | |
| 3262 | + | * over the mount namespace can't leave out any child though. | |
| 3153 | 3263 | */ | |
| 3154 | 3264 | if (flags & MOUNT_COPY_NEW) | |
| 3155 | 3265 | mnt = clone_mnt(real_mount(path->mnt), path->dentry, copy_flags); | |
| 3266 | + | else if (foreign && !recurse && | |
| 3267 | + | __has_children(real_mount(path->mnt), path->dentry)) | |
| 3268 | + | mnt = ERR_PTR(-EINVAL); | |
| 3156 | 3269 | else | |
| 3157 | 3270 | mnt = __do_loopback(path, recurse, copy_flags); | |
| 3158 | 3271 | scoped_guard(mount_writer) { | |
| @@ -3169,7 +3282,7 @@ static struct mnt_namespace *create_new_namespace(struct path *path, | |||
| 3169 | 3282 | * of the real rootfs we created. | |
| 3170 | 3283 | */ | |
| 3171 | 3284 | attach_mnt(mnt, new_ns_root, mp.mp); | |
| 3172 | - | if (user_ns != ns->user_ns) | |
| 3285 | + | if (foreign) | |
| 3173 | 3286 | lock_mnt_tree(new_ns_root); | |
| 3174 | 3287 | } | |
| 3175 | 3288 | ||
| @@ -3463,11 +3576,11 @@ static int do_set_group(const struct path *from_path, const struct path *to_path | |||
| 3463 | 3576 | return -EINVAL; | |
| 3464 | 3577 | ||
| 3465 | 3578 | /* From mount should not have locked children in place of To's root */ | |
| 3466 | - | if (__has_locked_children(from, to->mnt.mnt_root)) | |
| 3579 | + | if (has_locked_children(from, to->mnt.mnt_root)) | |
| 3467 | 3580 | return -EINVAL; | |
| 3468 | 3581 | ||
| 3469 | 3582 | /* Setting sharing groups is only allowed on private mounts */ | |
| 3470 | - | if (IS_MNT_SHARED(to) || IS_MNT_SLAVE(to)) | |
| 3583 | + | if (IS_MNT_SHARED(to) || IS_MNT_SLAVE(to) || IS_MNT_UNBINDABLE(to)) | |
| 3471 | 3584 | return -EINVAL; | |
| 3472 | 3585 | ||
| 3473 | 3586 | /* From should not be private */ | |
| @@ -3743,7 +3856,7 @@ static int do_add_mount(struct mount *newmnt, const struct pinned_mountpoint *mp | |||
| 3743 | 3856 | if (!(mnt_flags & MNT_SHRINKABLE)) | |
| 3744 | 3857 | return -EINVAL; | |
| 3745 | 3858 | /* ... and for those we'd better have mountpoint still alive */ | |
| 3746 | - | if (!parent->mnt_ns) | |
| 3859 | + | if (!is_mounted(&parent->mnt)) | |
| 3747 | 3860 | return -EINVAL; | |
| 3748 | 3861 | } | |
| 3749 | 3862 | ||
| @@ -3953,6 +4066,8 @@ void mark_mounts_for_expiry(struct list_head *mounts) | |||
| 3953 | 4066 | list_for_each_entry_safe(mnt, next, mounts, mnt_expire) { | |
| 3954 | 4067 | if (!is_mounted(&mnt->mnt)) | |
| 3955 | 4068 | continue; | |
| 4069 | + | /* lock_mnt_tree() leaves expirable mounts alone */ | |
| 4070 | + | VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt)); | |
| 3956 | 4071 | if (!xchg(&mnt->mnt_expiry_mark, 1) || | |
| 3957 | 4072 | propagate_mount_busy(mnt, 1)) | |
| 3958 | 4073 | continue; | |
| @@ -3960,6 +4075,11 @@ void mark_mounts_for_expiry(struct list_head *mounts) | |||
| 3960 | 4075 | } | |
| 3961 | 4076 | while (!list_empty(&graveyard)) { | |
| 3962 | 4077 | mnt = list_first_entry(&graveyard, struct mount, mnt_expire); | |
| 4078 | + | /* an earlier umount_tree() may have moved a busy mount here */ | |
| 4079 | + | if (propagate_mount_busy(mnt, 1)) { | |
| 4080 | + | list_move(&mnt->mnt_expire, mounts); | |
| 4081 | + | continue; | |
| 4082 | + | } | |
| 3963 | 4083 | touch_mnt_namespace(mnt->mnt_ns); | |
| 3964 | 4084 | umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); | |
| 3965 | 4085 | } | |
| @@ -3967,17 +4087,38 @@ void mark_mounts_for_expiry(struct list_head *mounts) | |||
| 3967 | 4087 | ||
| 3968 | 4088 | EXPORT_SYMBOL_GPL(mark_mounts_for_expiry); | |
| 3969 | 4089 | ||
| 4090 | + | /* | |
| 4091 | + | * Unmount @mnt if it's a shrinkable mount without children that nobody uses. | |
| 4092 | + | * | |
| 4093 | + | * mount_lock must be held for write | |
| 4094 | + | */ | |
| 4095 | + | static bool shrink_submount(struct mount *mnt) | |
| 4096 | + | { | |
| 4097 | + | /* not the kernel's to remove either */ | |
| 4098 | + | if (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1)) | |
| 4099 | + | return false; | |
| 4100 | + | touch_mnt_namespace(mnt->mnt_ns); | |
| 4101 | + | umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC); | |
| 4102 | + | return true; | |
| 4103 | + | } | |
| 4104 | + | ||
| 3970 | 4105 | /* | |
| 3971 | 4106 | * Ripoff of 'select_parent()' | |
| 3972 | 4107 | * | |
| 3973 | - | * search the list of submounts for a given mountpoint, and move any | |
| 3974 | - | * shrinkable submounts to the 'graveyard' list. | |
| 4108 | + | * unmount the shrinkable submounts of @parent that aren't busy, children | |
| 4109 | + | * before their parent, and say whether anything went | |
| 4110 | + | * | |
| 4111 | + | * The cursor into the children of @this_parent survives the umount of a | |
| 4112 | + | * child mount without child mounts. The mounts that get umounted together with | |
| 4113 | + | * it are located under receiving mounts of @this_parent and never under | |
| 4114 | + | * @this_parent itself. The one exception is @this_parent getting unmounted | |
| 4115 | + | * then the walk starts over. | |
| 3975 | 4116 | */ | |
| 3976 | - | static int select_submounts(struct mount *parent, struct list_head *graveyard) | |
| 4117 | + | static bool __shrink_submounts(struct mount *parent) | |
| 3977 | 4118 | { | |
| 3978 | 4119 | struct mount *this_parent = parent; | |
| 3979 | 4120 | struct list_head *next; | |
| 3980 | - | int found = 0; | |
| 4121 | + | bool shrunk = false; | |
| 3981 | 4122 | ||
| 3982 | 4123 | repeat: | |
| 3983 | 4124 | next = this_parent->mnt_mounts.next; | |
| @@ -3996,42 +4137,45 @@ resume: | |||
| 3996 | 4137 | this_parent = mnt; | |
| 3997 | 4138 | goto repeat; | |
| 3998 | 4139 | } | |
| 3999 | - | ||
| 4000 | - | if (!propagate_mount_busy(mnt, 1)) { | |
| 4001 | - | list_move_tail(&mnt->mnt_expire, graveyard); | |
| 4002 | - | found++; | |
| 4003 | - | } | |
| 4140 | + | if (!shrink_submount(mnt)) | |
| 4141 | + | continue; | |
| 4142 | + | shrunk = true; | |
| 4143 | + | if (unlikely(this_parent->mnt.mnt_flags & MNT_UMOUNT)) | |
| 4144 | + | return true; | |
| 4004 | 4145 | } | |
| 4005 | 4146 | /* | |
| 4006 | 4147 | * All done at this level ... ascend and resume the search | |
| 4007 | 4148 | */ | |
| 4008 | 4149 | if (this_parent != parent) { | |
| 4009 | - | next = this_parent->mnt_child.next; | |
| 4010 | - | this_parent = this_parent->mnt_parent; | |
| 4150 | + | struct mount *mnt = this_parent; | |
| 4151 | + | ||
| 4152 | + | next = mnt->mnt_child.next; | |
| 4153 | + | this_parent = mnt->mnt_parent; | |
| 4154 | + | /* its children are gone, maybe it can go as well */ | |
| 4155 | + | if (shrink_submount(mnt)) { | |
| 4156 | + | shrunk = true; | |
| 4157 | + | if (unlikely(this_parent->mnt.mnt_flags & MNT_UMOUNT)) | |
| 4158 | + | return true; | |
| 4159 | + | } | |
| 4011 | 4160 | goto resume; | |
| 4012 | 4161 | } | |
| 4013 | - | return found; | |
| 4162 | + | return shrunk; | |
| 4014 | 4163 | } | |
| 4015 | 4164 | ||
| 4016 | 4165 | /* | |
| 4017 | - | * process a list of expirable mountpoints with the intent of discarding any | |
| 4018 | - | * submounts of a specific parent mountpoint | |
| 4166 | + | * unmount the shrinkable submounts of @mnt that aren't busy | |
| 4167 | + | * | |
| 4168 | + | * The busy check and the umount of a mount are adjacent. An umount can | |
| 4169 | + | * still empty or move a mount in a part of the tree that was walked | |
| 4170 | + | * already, so walk again until nothing goes. | |
| 4019 | 4171 | * | |
| 4020 | 4172 | * mount_lock must be held for write | |
| 4021 | 4173 | */ | |
| 4022 | 4174 | static void shrink_submounts(struct mount *mnt) | |
| 4023 | 4175 | { | |
| 4024 | - | LIST_HEAD(graveyard); | |
| 4025 | - | struct mount *m; | |
| 4026 | - | ||
| 4027 | - | /* extract submounts of 'mountpoint' from the expiration list */ | |
| 4028 | - | while (select_submounts(mnt, &graveyard)) { | |
| 4029 | - | while (!list_empty(&graveyard)) { | |
| 4030 | - | m = list_first_entry(&graveyard, struct mount, | |
| 4031 | - | mnt_expire); | |
| 4032 | - | touch_mnt_namespace(m->mnt_ns); | |
| 4033 | - | umount_tree(m, UMOUNT_PROPAGATE|UMOUNT_SYNC); | |
| 4034 | - | } | |
| 4176 | + | for (;;) { | |
| 4177 | + | if (!__shrink_submounts(mnt)) | |
| 4178 | + | break; | |
| 4035 | 4179 | } | |
| 4036 | 4180 | } | |
| 4037 | 4181 | ||
| @@ -4196,6 +4340,8 @@ static void free_mnt_ns(struct mnt_namespace *ns) | |||
| 4196 | 4340 | if (!is_anon_ns(ns)) | |
| 4197 | 4341 | ns_common_free(ns); | |
| 4198 | 4342 | dec_mnt_namespaces(ns->ucounts); | |
| 4343 | + | /* the last active reference is gone, no mark can show up anymore */ | |
| 4344 | + | fsnotify_mntns_delete(ns); | |
| 4199 | 4345 | mnt_ns_tree_remove(ns); | |
| 4200 | 4346 | } | |
| 4201 | 4347 | ||
| @@ -4545,7 +4691,7 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, | |||
| 4545 | 4691 | FD_PREPARE(fdf, (flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0, | |
| 4546 | 4692 | dentry_open(&new_path, O_PATH, fc->cred)); | |
| 4547 | 4693 | if (fdf.err) { | |
| 4548 | - | dissolve_on_fput(new_path.mnt); | |
| 4694 | + | dissolve_on_fput(no_free_ptr(new_path.mnt)); | |
| 4549 | 4695 | return fdf.err; | |
| 4550 | 4696 | } | |
| 4551 | 4697 | ||
| @@ -4697,14 +4843,15 @@ int path_pivot_root(struct path *new, struct path *old) | |||
| 4697 | 4843 | ||
| 4698 | 4844 | new_mnt = real_mount(new->mnt); | |
| 4699 | 4845 | root_mnt = real_mount(root.mnt); | |
| 4846 | + | /* only a mounted mount has a parent that namespace_sem pins */ | |
| 4847 | + | if (!check_mnt(root_mnt) || !check_mnt(new_mnt)) | |
| 4848 | + | return -EINVAL; | |
| 4700 | 4849 | ex_parent = new_mnt->mnt_parent; | |
| 4701 | 4850 | root_parent = root_mnt->mnt_parent; | |
| 4702 | 4851 | if (IS_MNT_SHARED(old_mnt) || | |
| 4703 | 4852 | IS_MNT_SHARED(ex_parent) || | |
| 4704 | 4853 | IS_MNT_SHARED(root_parent)) | |
| 4705 | 4854 | return -EINVAL; | |
| 4706 | - | if (!check_mnt(root_mnt) || !check_mnt(new_mnt)) | |
| 4707 | - | return -EINVAL; | |
| 4708 | 4855 | if (new_mnt->mnt.mnt_flags & MNT_LOCKED) | |
| 4709 | 4856 | return -EINVAL; | |
| 4710 | 4857 | if (d_unlinked(new->dentry)) | |
| @@ -4955,6 +5102,11 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr) | |||
| 4955 | 5102 | * propagation. | |
| 4956 | 5103 | */ | |
| 4957 | 5104 | namespace_lock(); | |
| 5105 | + | /* invent_group_ids() walks the tree, only walk a mounted one */ | |
| 5106 | + | if (!anon_ns_root(mnt) && !check_mnt(mnt)) { | |
| 5107 | + | namespace_unlock(); | |
| 5108 | + | return -EINVAL; | |
| 5109 | + | } | |
| 4958 | 5110 | if (kattr->propagation == MS_SHARED) { | |
| 4959 | 5111 | err = invent_group_ids(mnt, kattr->kflags & MOUNT_KATTR_RECURSE); | |
| 4960 | 5112 | if (err) { | |
| @@ -4967,6 +5119,7 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr) | |||
| 4967 | 5119 | err = -EINVAL; | |
| 4968 | 5120 | lock_mount_hash(); | |
| 4969 | 5121 | ||
| 5122 | + | /* Checked under namespace_sem already if the propagation changes. */ | |
| 4970 | 5123 | if (!anon_ns_root(mnt) && !check_mnt(mnt)) | |
| 4971 | 5124 | goto out; | |
| 4972 | 5125 | ||
| @@ -5319,15 +5472,25 @@ static void statmount_sb_basic(struct kstatmount *s) | |||
| 5319 | 5472 | s->sm.sb_flags = sb->s_flags & (SB_RDONLY|SB_SYNCHRONOUS|SB_DIRSYNC|SB_LAZYTIME); | |
| 5320 | 5473 | } | |
| 5321 | 5474 | ||
| 5475 | + | static void statmount_mnt_parent(struct kstatmount *s, const struct mount *m) | |
| 5476 | + | { | |
| 5477 | + | s->sm.mnt_parent_id = m->mnt_parent->mnt_id_unique; | |
| 5478 | + | s->sm.mnt_parent_id_old = m->mnt_parent->mnt_id; | |
| 5479 | + | } | |
| 5480 | + | ||
| 5322 | 5481 | static void statmount_mnt_basic(struct kstatmount *s) | |
| 5323 | 5482 | { | |
| 5324 | 5483 | struct mount *m = real_mount(s->mnt); | |
| 5325 | 5484 | ||
| 5326 | 5485 | s->sm.mask |= STATMOUNT_MNT_BASIC; | |
| 5327 | 5486 | s->sm.mnt_id = m->mnt_id_unique; | |
| 5328 | - | s->sm.mnt_parent_id = m->mnt_parent->mnt_id_unique; | |
| 5329 | 5487 | s->sm.mnt_id_old = m->mnt_id; | |
| 5330 | - | s->sm.mnt_parent_id_old = m->mnt_parent->mnt_id; | |
| 5488 | + | /* An unmounted mount is cut loose from its parent under mount_lock alone. */ | |
| 5489 | + | if (likely(is_mounted(s->mnt))) | |
| 5490 | + | statmount_mnt_parent(s, m); | |
| 5491 | + | else | |
| 5492 | + | scoped_guard(mount_locked_reader) | |
| 5493 | + | statmount_mnt_parent(s, m); | |
| 5331 | 5494 | s->sm.mnt_attr = mnt_to_attr_flags(&m->mnt); | |
| 5332 | 5495 | s->sm.mnt_propagation = mnt_to_propagation_flags(m); | |
| 5333 | 5496 | s->sm.mnt_peer_group = m->mnt_group_id; | |
| @@ -6199,6 +6362,25 @@ static void __init mount_rootfs_on_nullfs(struct vfsmount *mnt, | |||
| 6199 | 6362 | attach_mnt(real_mount(mnt), mp.parent, mp.mp); | |
| 6200 | 6363 | } | |
| 6201 | 6364 | ||
| 6365 | + | static struct vfsmount *__init knullfs_file_mount(void) | |
| 6366 | + | { | |
| 6367 | + | struct dentry *file; | |
| 6368 | + | struct mount *mnt; | |
| 6369 | + | ||
| 6370 | + | file = nullfs_new_file(knullfs->mnt_sb); | |
| 6371 | + | if (IS_ERR(file)) | |
| 6372 | + | return ERR_CAST(file); | |
| 6373 | + | mnt = clone_mnt(real_mount(knullfs), file, CL_PRIVATE); | |
| 6374 | + | dput(file); | |
| 6375 | + | if (IS_ERR(mnt)) | |
| 6376 | + | return ERR_CAST(mnt); | |
| 6377 | + | mnt->mnt_ns = MNT_NS_INTERNAL; | |
| 6378 | + | mnt->mnt.mnt_flags |= MNT_INTERNAL; | |
| 6379 | + | mnt->mnt.mnt_flags &= ~MNT_READONLY; | |
| 6380 | + | dont_mount(mnt->mnt.mnt_root); | |
| 6381 | + | return &mnt->mnt; | |
| 6382 | + | } | |
| 6383 | + | ||
| 6202 | 6384 | static void __init init_mount_tree(void) | |
| 6203 | 6385 | { | |
| 6204 | 6386 | struct vfsmount *mnt, *nullfs_mnt; | |
| @@ -6210,10 +6392,14 @@ static void __init init_mount_tree(void) | |||
| 6210 | 6392 | * | |
| 6211 | 6393 | * (1) nullfs with mount id 1 | |
| 6212 | 6394 | * (2) mutable rootfs with mount id 2 | |
| 6213 | - | * (3) private nullfs for kthreads (SB_KERNMOUNT) | |
| 6395 | + | * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs | |
| 6396 | + | * (4) a second mount of (3) rooted on a regular file, kept in | |
| 6397 | + | * knullfs_file | |
| 6214 | 6398 | * | |
| 6215 | 6399 | * with (2) mounted on top of (1). The init_task's root and pwd | |
| 6216 | 6400 | * are pointed at (3) so all kthreads start isolated in nullfs. | |
| 6401 | + | * A lookup at the cover an unmounted mount left behind finds (3) | |
| 6402 | + | * or (4), see __lookup_mnt(). | |
| 6217 | 6403 | */ | |
| 6218 | 6404 | nullfs_mnt = vfs_kern_mount(&nullfs_fs_type, 0, "nullfs", NULL); | |
| 6219 | 6405 | if (IS_ERR(nullfs_mnt)) | |
| @@ -6245,11 +6431,18 @@ static void __init init_mount_tree(void) | |||
| 6245 | 6431 | init_mnt_ns.nr_mounts++; | |
| 6246 | 6432 | } | |
| 6247 | 6433 | ||
| 6248 | - | nullfs_mnt = kern_mount(&nullfs_fs_type); | |
| 6249 | - | if (IS_ERR(nullfs_mnt)) | |
| 6434 | + | knullfs = kern_mount(&nullfs_fs_type); | |
| 6435 | + | if (IS_ERR(knullfs)) | |
| 6250 | 6436 | panic("VFS: Failed to create private nullfs instance"); | |
| 6251 | - | root.mnt = nullfs_mnt; | |
| 6252 | - | root.dentry = nullfs_mnt->mnt_root; | |
| 6437 | + | /* nothing is ever mounted on the root of a kernel thread */ | |
| 6438 | + | dont_mount(knullfs->mnt_root); | |
| 6439 | + | /* and nothing is ever written through it */ | |
| 6440 | + | knullfs->mnt_flags |= MNT_READONLY; | |
| 6441 | + | knullfs_file = knullfs_file_mount(); | |
| 6442 | + | if (IS_ERR(knullfs_file)) | |
| 6443 | + | panic("VFS: Failed to create the nullfs file stand-in"); | |
| 6444 | + | root.mnt = knullfs; | |
| 6445 | + | root.dentry = knullfs->mnt_root; | |
| 6253 | 6446 | ||
| 6254 | 6447 | init_task.nsproxy->mnt_ns = &init_mnt_ns; | |
| 6255 | 6448 | get_mnt_ns(&init_mnt_ns); | |
modified fs/notify/mark.c
| @@ -903,6 +903,10 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj, | |||
| 903 | 903 | if (WARN_ON(!fsnotify_valid_obj_type(obj_type))) | |
| 904 | 904 | return -EINVAL; | |
| 905 | 905 | ||
| 906 | + | /* the filesystem doesn't want its objects watched */ | |
| 907 | + | if (sb && (sb->s_type->fs_flags & FS_DISALLOW_NOTIFY)) | |
| 908 | + | return -EINVAL; | |
| 909 | + | ||
| 906 | 910 | /* | |
| 907 | 911 | * Attach the sb info before attaching a connector to any object on sb. | |
| 908 | 912 | * The sb info will remain attached as long as sb lives. | |
modified fs/nullfs.c
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | #include <linux/fs/super_types.h> | |
| 4 | 4 | #include <linux/fs_context.h> | |
| 5 | 5 | #include <linux/magic.h> | |
| 6 | + | #include <linux/splice.h> | |
| 7 | + | #include <linux/uio.h> | |
| 6 | 8 | ||
| 7 | 9 | #include "mount.h" | |
| 8 | 10 | ||
| @@ -10,6 +12,121 @@ static const struct super_operations nullfs_super_operations = { | |||
| 10 | 12 | .statfs = simple_statfs, | |
| 11 | 13 | }; | |
| 12 | 14 | ||
| 15 | + | static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence) | |
| 16 | + | { | |
| 17 | + | /* an empty directory has two entries . and .. at offsets 0 and 1 */ | |
| 18 | + | return generic_file_llseek_size(file, offset, whence, 2, 2); | |
| 19 | + | } | |
| 20 | + | ||
| 21 | + | static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx) | |
| 22 | + | { | |
| 23 | + | dir_emit_dots(file, ctx); | |
| 24 | + | return 0; | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | /* the one inode of nullfs is shared by every holder, so no locks on it */ | |
| 28 | + | static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl) | |
| 29 | + | { | |
| 30 | + | return -ENOLCK; | |
| 31 | + | } | |
| 32 | + | ||
| 33 | + | /* what libfs gives an empty directory, plus the refusal of file locks */ | |
| 34 | + | static const struct file_operations nullfs_dir_operations = { | |
| 35 | + | .llseek = nullfs_dir_llseek, | |
| 36 | + | .read = generic_read_dir, | |
| 37 | + | .iterate_shared = nullfs_dir_readdir, | |
| 38 | + | .fsync = noop_fsync, | |
| 39 | + | .lock = nullfs_nolock, | |
| 40 | + | .flock = nullfs_nolock, | |
| 41 | + | .fop_flags = FOP_IMMUTABLE, | |
| 42 | + | }; | |
| 43 | + | ||
| 44 | + | static ssize_t nullfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) | |
| 45 | + | { | |
| 46 | + | return 0; | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | static ssize_t nullfs_file_splice_read(struct file *in, loff_t *ppos, | |
| 50 | + | struct pipe_inode_info *pipe, | |
| 51 | + | size_t len, unsigned int flags) | |
| 52 | + | { | |
| 53 | + | return 0; | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | static ssize_t nullfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |
| 57 | + | { | |
| 58 | + | size_t count = iov_iter_count(from); | |
| 59 | + | ||
| 60 | + | iov_iter_advance(from, count); | |
| 61 | + | return count; | |
| 62 | + | } | |
| 63 | + | ||
| 64 | + | static int nullfs_pipe_to_null(struct pipe_inode_info *pipe, | |
| 65 | + | struct pipe_buffer *buf, struct splice_desc *sd) | |
| 66 | + | { | |
| 67 | + | return sd->len; | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | static ssize_t nullfs_file_splice_write(struct pipe_inode_info *pipe, | |
| 71 | + | struct file *out, loff_t *ppos, | |
| 72 | + | size_t len, unsigned int flags) | |
| 73 | + | { | |
| 74 | + | return splice_from_pipe(pipe, out, ppos, len, flags, nullfs_pipe_to_null); | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | static int nullfs_file_setattr(struct mnt_idmap *idmap, struct dentry *dentry, | |
| 78 | + | struct iattr *attr) | |
| 79 | + | { | |
| 80 | + | if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)) | |
| 81 | + | return -EPERM; | |
| 82 | + | return 0; | |
| 83 | + | } | |
| 84 | + | ||
| 85 | + | static const struct inode_operations nullfs_file_inode_operations = { | |
| 86 | + | .setattr = nullfs_file_setattr, | |
| 87 | + | }; | |
| 88 | + | ||
| 89 | + | static const struct file_operations nullfs_file_operations = { | |
| 90 | + | .llseek = generic_file_llseek, | |
| 91 | + | .read_iter = nullfs_file_read_iter, | |
| 92 | + | .write_iter = nullfs_file_write_iter, | |
| 93 | + | .splice_read = nullfs_file_splice_read, | |
| 94 | + | .splice_write = nullfs_file_splice_write, | |
| 95 | + | .fsync = noop_fsync, | |
| 96 | + | .lock = nullfs_nolock, | |
| 97 | + | .flock = nullfs_nolock, | |
| 98 | + | }; | |
| 99 | + | ||
| 100 | + | /* | |
| 101 | + | * An empty regular file on @sb as a dentry of its own, never hashed under | |
| 102 | + | * the root so no lookup finds it. | |
| 103 | + | */ | |
| 104 | + | struct dentry *nullfs_new_file(struct super_block *sb) | |
| 105 | + | { | |
| 106 | + | struct dentry *dentry; | |
| 107 | + | struct inode *inode; | |
| 108 | + | ||
| 109 | + | inode = new_inode(sb); | |
| 110 | + | if (!inode) | |
| 111 | + | return ERR_PTR(-ENOMEM); | |
| 112 | + | ||
| 113 | + | /* the root directory is 1 */ | |
| 114 | + | inode->i_ino = 2; | |
| 115 | + | inode->i_mode = S_IFREG | 0666; | |
| 116 | + | inode->i_op = &nullfs_file_inode_operations; | |
| 117 | + | inode->i_fop = &nullfs_file_operations; | |
| 118 | + | simple_inode_init_ts(inode); | |
| 119 | + | inode->i_flags |= S_NOATIME; | |
| 120 | + | ||
| 121 | + | dentry = d_alloc_anon(sb); | |
| 122 | + | if (!dentry) { | |
| 123 | + | iput(inode); | |
| 124 | + | return ERR_PTR(-ENOMEM); | |
| 125 | + | } | |
| 126 | + | d_instantiate(dentry, inode); | |
| 127 | + | return dentry; | |
| 128 | + | } | |
| 129 | + | ||
| 13 | 130 | static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc) | |
| 14 | 131 | { | |
| 15 | 132 | struct inode *inode; | |
| @@ -30,10 +147,11 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc) | |||
| 30 | 147 | ||
| 31 | 148 | /* nullfs is permanently empty... */ | |
| 32 | 149 | make_empty_dir_inode(inode); | |
| 150 | + | inode->i_fop = &nullfs_dir_operations; | |
| 33 | 151 | simple_inode_init_ts(inode); | |
| 34 | 152 | inode->i_ino = 1; | |
| 35 | - | /* ... and immutable. */ | |
| 36 | - | inode->i_flags |= S_IMMUTABLE; | |
| 153 | + | /* ... and immutable, reading it leaves no trace either. */ | |
| 154 | + | inode->i_flags |= S_IMMUTABLE | S_NOATIME; | |
| 37 | 155 | ||
| 38 | 156 | s->s_root = d_make_root(inode); | |
| 39 | 157 | if (!s->s_root) | |
| @@ -61,6 +179,7 @@ static int nullfs_init_fs_context(struct fs_context *fc) | |||
| 61 | 179 | ||
| 62 | 180 | struct file_system_type nullfs_fs_type = { | |
| 63 | 181 | .name = "nullfs", | |
| 182 | + | .fs_flags = FS_DISALLOW_NOTIFY, | |
| 64 | 183 | .init_fs_context = nullfs_init_fs_context, | |
| 65 | 184 | .kill_sb = kill_anon_super, | |
| 66 | 185 | }; | |
modified fs/pnode.c
| @@ -410,19 +410,99 @@ bool propagation_would_overmount(const struct mount *from, | |||
| 410 | 410 | return false; | |
| 411 | 411 | } | |
| 412 | 412 | ||
| 413 | + | /* Does @m receive propagation from @parent? */ | |
| 414 | + | static bool receives_from(struct mount *m, struct mount *parent) | |
| 415 | + | { | |
| 416 | + | if (m == parent) | |
| 417 | + | return false; | |
| 418 | + | for (; m; m = m->mnt_master) | |
| 419 | + | if (m == parent || peers(m, parent)) | |
| 420 | + | return true; | |
| 421 | + | return false; | |
| 422 | + | } | |
| 423 | + | ||
| 424 | + | /* | |
| 425 | + | * Does @m receive propagation from the victim's parent as well? If so, then | |
| 426 | + | * the mount at the victim's mountpoint inside of @m is a umount candidate as | |
| 427 | + | * well. So it's the next candidate in the chain. Otherwise the chain ends at | |
| 428 | + | * @m. | |
| 429 | + | */ | |
| 430 | + | static struct mount *next_candidate(struct mount *m, struct mount *victim) | |
| 431 | + | { | |
| 432 | + | if (!receives_from(m, victim->mnt_parent)) | |
| 433 | + | return NULL; | |
| 434 | + | return __lookup_mnt(&m->mnt, victim->mnt_mountpoint); | |
| 435 | + | } | |
| 436 | + | ||
| 437 | + | /* | |
| 438 | + | * Would propagate_umount() pull out a mount of the chain of candidates that | |
| 439 | + | * starts at @c, and does that mount have references beyond its own? | |
| 440 | + | * | |
| 441 | + | * This mirrors how trim_one(), trim_ancestors() and handle_locked() handle a | |
| 442 | + | * synchronous umount: | |
| 443 | + | * | |
| 444 | + | * - single victim | |
| 445 | + | * - without children | |
| 446 | + | * - with MNT_LOCKED already cleared on every candidate by propagate_mount_unlock() | |
| 447 | + | * | |
| 448 | + | * A copy of the victim gets unmounted when each of its children is | |
| 449 | + | * the next candidate in the chain or its overmount, unless the next | |
| 450 | + | * unmount candidate is not its overmount and some unmount candidate further | |
| 451 | + | * down has a child outside the chain. Keep this in sync with | |
| 452 | + | * Documentation/filesystems/propagate_umount.txt. | |
| 453 | + | */ | |
| 454 | + | static bool chain_busy(struct mount *c, struct mount *victim) | |
| 455 | + | { | |
| 456 | + | struct mount *m, *n, *next, *deepest = NULL; | |
| 457 | + | bool above; | |
| 458 | + | ||
| 459 | + | /* the deepest candidate with a child outside the chain */ | |
| 460 | + | for (m = c; m; m = next) { | |
| 461 | + | next = next_candidate(m, victim); | |
| 462 | + | list_for_each_entry(n, &m->mnt_mounts, mnt_child) { | |
| 463 | + | if (n != next && n != victim) { | |
| 464 | + | deepest = m; | |
| 465 | + | break; | |
| 466 | + | } | |
| 467 | + | } | |
| 468 | + | } | |
| 469 | + | ||
| 470 | + | above = deepest != NULL; /* @deepest is at or below @m */ | |
| 471 | + | for (m = c; m; m = next) { | |
| 472 | + | bool goes = true; | |
| 473 | + | ||
| 474 | + | next = next_candidate(m, victim); | |
| 475 | + | list_for_each_entry(n, &m->mnt_mounts, mnt_child) { | |
| 476 | + | if (n != next && n != m->overmount && n != victim) { | |
| 477 | + | goes = false; | |
| 478 | + | break; | |
| 479 | + | } | |
| 480 | + | } | |
| 481 | + | if (goes && next && next != m->overmount && above && m != deepest) | |
| 482 | + | goes = false; | |
| 483 | + | if (m == deepest) | |
| 484 | + | above = false; | |
| 485 | + | if (goes && do_refcount_check(m, 1)) | |
| 486 | + | return true; | |
| 487 | + | } | |
| 488 | + | return false; | |
| 489 | + | } | |
| 490 | + | ||
| 413 | 491 | /* | |
| 414 | 492 | * check if the mount 'mnt' can be unmounted successfully. | |
| 415 | 493 | * @mnt: the mount to be checked for unmount | |
| 416 | 494 | * NOTE: unmounting 'mnt' would naturally propagate to all | |
| 417 | 495 | * other mounts its parent propagates to. | |
| 418 | - | * Check if any of these mounts that **do not have submounts** | |
| 419 | - | * have more references than 'refcnt'. If so return busy. | |
| 496 | + | * Check if any of the mounts that propagate_umount() would pull out | |
| 497 | + | * along with it have more references than their own. If so return busy. | |
| 420 | 498 | * | |
| 421 | 499 | * vfsmount lock must be held for write | |
| 422 | 500 | */ | |
| 423 | 501 | int propagate_mount_busy(struct mount *mnt, int refcnt) | |
| 424 | 502 | { | |
| 425 | 503 | struct mount *parent = mnt->mnt_parent; | |
| 504 | + | struct dentry *mp = mnt->mnt_mountpoint; | |
| 505 | + | struct mount *m; | |
| 426 | 506 | ||
| 427 | 507 | /* | |
| 428 | 508 | * quickly check if the current mount can be unmounted. | |
| @@ -435,24 +515,16 @@ int propagate_mount_busy(struct mount *mnt, int refcnt) | |||
| 435 | 515 | if (mnt == parent) | |
| 436 | 516 | return 0; | |
| 437 | 517 | ||
| 438 | - | for (struct mount *m = propagation_next(parent, parent); m; | |
| 439 | - | m = propagation_next(m, parent)) { | |
| 440 | - | struct list_head *head; | |
| 441 | - | struct mount *child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint); | |
| 518 | + | /* the candidates are the mounts at @mp below the receivers */ | |
| 519 | + | for (m = propagation_next(parent, parent); m; | |
| 520 | + | m = propagation_next(m, parent)) { | |
| 521 | + | struct mount *c = __lookup_mnt(&m->mnt, mp); | |
| 442 | 522 | ||
| 443 | - | if (!child) | |
| 523 | + | /* each chain once, from its top: skip receivers that are candidates */ | |
| 524 | + | if (!c || (mnt_has_parent(m) && m->mnt_mountpoint == mp && | |
| 525 | + | receives_from(m->mnt_parent, parent))) | |
| 444 | 526 | continue; | |
| 445 | - | ||
| 446 | - | head = &child->mnt_mounts; | |
| 447 | - | if (!list_empty(head)) { | |
| 448 | - | /* | |
| 449 | - | * a mount that covers child completely wouldn't prevent | |
| 450 | - | * it being pulled out; any other would. | |
| 451 | - | */ | |
| 452 | - | if (!list_is_singular(head) || !child->overmount) | |
| 453 | - | continue; | |
| 454 | - | } | |
| 455 | - | if (do_refcount_check(child, 1)) | |
| 527 | + | if (chain_busy(c, mnt)) | |
| 456 | 528 | return 1; | |
| 457 | 529 | } | |
| 458 | 530 | return 0; | |
| @@ -625,8 +697,8 @@ static void handle_locked(struct mount *m, struct list_head *to_umount) | |||
| 625 | 697 | * the same parent and mountpoint; that will be remedied as soon as we | |
| 626 | 698 | * return from propagate_umount() - its caller (umount_tree()) will detach | |
| 627 | 699 | * the stack from the parent it (and now @m) is attached to. umount_tree() | |
| 628 | - | * might choose to keep unmounted pieces stuck to each other, but it always | |
| 629 | - | * detaches them from the mounts that remain in the tree. | |
| 700 | + | * detaches every unmounted mount from its parent, whether that parent | |
| 701 | + | * remains in the tree or not. | |
| 630 | 702 | */ | |
| 631 | 703 | static void reparent(struct mount *m) | |
| 632 | 704 | { | |
modified fs/readdir.c
| @@ -87,6 +87,8 @@ EXPORT_SYMBOL(wrap_directory_iterator); | |||
| 87 | 87 | int iterate_dir(struct file *file, struct dir_context *ctx) | |
| 88 | 88 | { | |
| 89 | 89 | struct inode *inode = file_inode(file); | |
| 90 | + | /* never an entry, never removed: nothing for the lock to keep still */ | |
| 91 | + | bool locked = !(file->f_op->fop_flags & FOP_IMMUTABLE); | |
| 90 | 92 | int res = -ENOTDIR; | |
| 91 | 93 | ||
| 92 | 94 | if (!file->f_op->iterate_shared) | |
| @@ -100,9 +102,11 @@ int iterate_dir(struct file *file, struct dir_context *ctx) | |||
| 100 | 102 | if (res) | |
| 101 | 103 | goto out; | |
| 102 | 104 | ||
| 103 | - | res = down_read_killable(&inode->i_rwsem); | |
| 104 | - | if (res) | |
| 105 | - | goto out; | |
| 105 | + | if (locked) { | |
| 106 | + | res = down_read_killable(&inode->i_rwsem); | |
| 107 | + | if (res) | |
| 108 | + | goto out; | |
| 109 | + | } | |
| 106 | 110 | ||
| 107 | 111 | res = -ENOENT; | |
| 108 | 112 | if (!IS_DEADDIR(inode)) { | |
| @@ -112,7 +116,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx) | |||
| 112 | 116 | fsnotify_access(file); | |
| 113 | 117 | file_accessed(file); | |
| 114 | 118 | } | |
| 115 | - | inode_unlock_shared(inode); | |
| 119 | + | if (locked) | |
| 120 | + | inode_unlock_shared(inode); | |
| 116 | 121 | out: | |
| 117 | 122 | return res; | |
| 118 | 123 | } | |
modified fs/verity/fsverity_private.h
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | #define pr_fmt(fmt) "fs-verity: " fmt | |
| 12 | 12 | ||
| 13 | 13 | #include <linux/fsverity.h> | |
| 14 | + | #include <linux/rcupdate.h> | |
| 14 | 15 | #include <linux/rhashtable.h> | |
| 15 | 16 | ||
| 16 | 17 | /* | |
| @@ -76,7 +77,19 @@ struct merkle_tree_params { | |||
| 76 | 77 | struct fsverity_info { | |
| 77 | 78 | struct rhash_head rhash_head; | |
| 78 | 79 | struct merkle_tree_params tree_params; | |
| 79 | - | u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE]; | |
| 80 | + | union { | |
| 81 | + | u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE]; | |
| 82 | + | ||
| 83 | + | /* | |
| 84 | + | * Used for final freeing of the struct, in which case root_hash | |
| 85 | + | * is no longer needed. Specifically, the only fields needed | |
| 86 | + | * besides the rcu_head are those needed by fsverity_free_info() | |
| 87 | + | * itself, and those that can be accessed by fsverity_get_info() | |
| 88 | + | * (rhash_head and inode) during the RCU-protected rhashtable | |
| 89 | + | * chain search trying to find another inode's fsverity_info. | |
| 90 | + | */ | |
| 91 | + | struct rcu_head rcu_head; | |
| 92 | + | }; | |
| 80 | 93 | u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE]; | |
| 81 | 94 | struct inode *inode; | |
| 82 | 95 | unsigned long *hash_block_verified; | |
modified fs/verity/open.c
| @@ -399,11 +399,22 @@ void fsverity_free_info(struct fsverity_info *vi) | |||
| 399 | 399 | kmem_cache_free(fsverity_info_cachep, vi); | |
| 400 | 400 | } | |
| 401 | 401 | ||
| 402 | + | static void fsverity_free_info_rcu(struct rcu_head *head) | |
| 403 | + | { | |
| 404 | + | fsverity_free_info(container_of(head, struct fsverity_info, rcu_head)); | |
| 405 | + | } | |
| 406 | + | ||
| 402 | 407 | void fsverity_remove_info(struct fsverity_info *vi) | |
| 403 | 408 | { | |
| 404 | 409 | rhashtable_remove_fast(&fsverity_info_hash, &vi->rhash_head, | |
| 405 | 410 | fsverity_info_hash_params); | |
| 406 | - | fsverity_free_info(vi); | |
| 411 | + | /* | |
| 412 | + | * The freeing must be RCU-delayed because __fsverity_get_info() for a | |
| 413 | + | * *different* inode's fsverity_info in the same rhashtable hash chain | |
| 414 | + | * can still be accessing *this* fsverity_info's rhash_head and inode | |
| 415 | + | * fields as part of the RCU-protected hash chain search. | |
| 416 | + | */ | |
| 417 | + | call_rcu(&vi->rcu_head, fsverity_free_info_rcu); | |
| 407 | 418 | } | |
| 408 | 419 | ||
| 409 | 420 | void fsverity_cleanup_inode(struct inode *inode) | |
modified fs/xfs/libxfs/xfs_exchmaps.c
| @@ -49,7 +49,7 @@ struct xfs_exchmaps_adjacent { | |||
| 49 | 49 | .right2 = { .br_startblock = HOLESTARTBLOCK }, \ | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | - | /* Information to reset reflink flag / CoW fork state after an exchange. */ | |
| 52 | + | /* Information to reset CoW fork state after an exchange. */ | |
| 53 | 53 | ||
| 54 | 54 | /* | |
| 55 | 55 | * If the reflink flag is set on either inode, make sure it has an incore CoW | |
| @@ -127,9 +127,7 @@ xmi_has_more_exchange_work(const struct xfs_exchmaps_intent *xmi) | |||
| 127 | 127 | static inline bool | |
| 128 | 128 | xmi_has_postop_work(const struct xfs_exchmaps_intent *xmi) | |
| 129 | 129 | { | |
| 130 | - | return xmi->xmi_flags & (XFS_EXCHMAPS_CLEAR_INO1_REFLINK | | |
| 131 | - | XFS_EXCHMAPS_CLEAR_INO2_REFLINK | | |
| 132 | - | __XFS_EXCHMAPS_INO2_SHORTFORM); | |
| 130 | + | return xmi->xmi_flags & __XFS_EXCHMAPS_INO2_SHORTFORM; | |
| 133 | 131 | } | |
| 134 | 132 | ||
| 135 | 133 | /* Check all mappings to make sure we can actually exchange them. */ | |
| @@ -525,18 +523,6 @@ free: | |||
| 525 | 523 | return error; | |
| 526 | 524 | } | |
| 527 | 525 | ||
| 528 | - | /* Clear the reflink flag after an exchange. */ | |
| 529 | - | static inline void | |
| 530 | - | xfs_exchmaps_clear_reflink( | |
| 531 | - | struct xfs_trans *tp, | |
| 532 | - | struct xfs_inode *ip) | |
| 533 | - | { | |
| 534 | - | trace_xfs_reflink_unset_inode_flag(ip); | |
| 535 | - | ||
| 536 | - | ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; | |
| 537 | - | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | |
| 538 | - | } | |
| 539 | - | ||
| 540 | 526 | /* Finish whatever work might come after an exchange operation. */ | |
| 541 | 527 | static int | |
| 542 | 528 | xfs_exchmaps_do_postop_work( | |
| @@ -557,16 +543,6 @@ xfs_exchmaps_do_postop_work( | |||
| 557 | 543 | return error; | |
| 558 | 544 | } | |
| 559 | 545 | ||
| 560 | - | if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO1_REFLINK) { | |
| 561 | - | xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip1); | |
| 562 | - | xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO1_REFLINK; | |
| 563 | - | } | |
| 564 | - | ||
| 565 | - | if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO2_REFLINK) { | |
| 566 | - | xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip2); | |
| 567 | - | xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO2_REFLINK; | |
| 568 | - | } | |
| 569 | - | ||
| 570 | 546 | return 0; | |
| 571 | 547 | } | |
| 572 | 548 | ||
| @@ -948,46 +924,14 @@ xfs_exchmaps_intent_destroy_cache(void) | |||
| 948 | 924 | } | |
| 949 | 925 | ||
| 950 | 926 | /* | |
| 951 | - | * Decide if we will exchange the reflink flags between the two files after the | |
| 952 | - | * exchange. The only time we want to do this is if we're exchanging all | |
| 953 | - | * mappings under EOF and the inode reflink flags have different states. | |
| 927 | + | * Allocate and initialize a new incore intent item from a request. | |
| 954 | 928 | */ | |
| 955 | - | static inline bool | |
| 956 | - | xmi_can_exchange_reflink_flags( | |
| 957 | - | const struct xfs_exchmaps_req *req, | |
| 958 | - | unsigned int reflink_state) | |
| 959 | - | { | |
| 960 | - | struct xfs_mount *mp = req->ip1->i_mount; | |
| 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 | - | ||
| 972 | - | if (hweight32(reflink_state) != 1) | |
| 973 | - | return false; | |
| 974 | - | if (req->startoff1 != 0 || req->startoff2 != 0) | |
| 975 | - | return false; | |
| 976 | - | if (req->blockcount != XFS_B_TO_FSB(mp, req->ip1->i_disk_size)) | |
| 977 | - | return false; | |
| 978 | - | if (req->blockcount != XFS_B_TO_FSB(mp, req->ip2->i_disk_size)) | |
| 979 | - | return false; | |
| 980 | - | return true; | |
| 981 | - | } | |
| 982 | - | ||
| 983 | - | ||
| 984 | - | /* Allocate and initialize a new incore intent item from a request. */ | |
| 985 | 929 | struct xfs_exchmaps_intent * | |
| 986 | 930 | xfs_exchmaps_init_intent( | |
| 987 | 931 | const struct xfs_exchmaps_req *req) | |
| 988 | 932 | { | |
| 989 | 933 | struct xfs_exchmaps_intent *xmi; | |
| 990 | - | unsigned int rs = 0; | |
| 934 | + | struct xfs_mount *mp = req->ip1->i_mount; | |
| 991 | 935 | ||
| 992 | 936 | xmi = kmem_cache_zalloc(xfs_exchmaps_intent_cache, | |
| 993 | 937 | GFP_NOFS | __GFP_NOFAIL); | |
| @@ -1005,27 +949,18 @@ xfs_exchmaps_init_intent( | |||
| 1005 | 949 | return xmi; | |
| 1006 | 950 | } | |
| 1007 | 951 | ||
| 1008 | - | if (req->flags & XFS_EXCHMAPS_SET_SIZES) { | |
| 1009 | - | xmi->xmi_flags |= XFS_EXCHMAPS_SET_SIZES; | |
| 1010 | - | xmi->xmi_isize1 = req->ip2->i_disk_size; | |
| 1011 | - | xmi->xmi_isize2 = req->ip1->i_disk_size; | |
| 1012 | - | } | |
| 1013 | - | ||
| 1014 | - | /* Record the state of each inode's reflink flag before the op. */ | |
| 1015 | - | if (xfs_is_reflink_inode(req->ip1)) | |
| 1016 | - | rs |= 1; | |
| 1017 | - | if (xfs_is_reflink_inode(req->ip2)) | |
| 1018 | - | rs |= 2; | |
| 1019 | - | ||
| 1020 | 952 | /* | |
| 1021 | - | * Figure out if we're clearing the reflink flags (which effectively | |
| 1022 | - | * exchanges them) after the operation. | |
| 953 | + | * If the caller wanted, set each file's size to that file's exchange | |
| 954 | + | * offset + length exchanged from the other file because the ranges in | |
| 955 | + | * each file might be different lengths. | |
| 1023 | 956 | */ | |
| 1024 | - | if (xmi_can_exchange_reflink_flags(req, rs)) { | |
| 1025 | - | if (rs & 1) | |
| 1026 | - | xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO1_REFLINK; | |
| 1027 | - | if (rs & 2) | |
| 1028 | - | xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO2_REFLINK; | |
| 957 | + | if (req->flags & XFS_EXCHMAPS_SET_SIZES) { | |
| 958 | + | loff_t off1 = XFS_FSB_TO_B(mp, xmi->xmi_startoff1); | |
| 959 | + | loff_t off2 = XFS_FSB_TO_B(mp, xmi->xmi_startoff2); | |
| 960 | + | ||
| 961 | + | xmi->xmi_flags |= XFS_EXCHMAPS_SET_SIZES; | |
| 962 | + | xmi->xmi_isize1 = off1 + (req->ip2->i_disk_size - off2); | |
| 963 | + | xmi->xmi_isize2 = off2 + (req->ip1->i_disk_size - off1); | |
| 1029 | 964 | } | |
| 1030 | 965 | ||
| 1031 | 966 | if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode) || | |
modified fs/xfs/libxfs/xfs_log_format.h
| @@ -927,10 +927,8 @@ struct xfs_xmi_log_format { | |||
| 927 | 927 | */ | |
| 928 | 928 | #define XFS_EXCHMAPS_INO1_WRITTEN (1ULL << 2) | |
| 929 | 929 | ||
| 930 | - | /* Clear the reflink flag from inode1 after the operation. */ | |
| 930 | + | /* No longer set, but older intents may carry them; keep them valid. */ | |
| 931 | 931 | #define XFS_EXCHMAPS_CLEAR_INO1_REFLINK (1ULL << 3) | |
| 932 | - | ||
| 933 | - | /* Clear the reflink flag from inode2 after the operation. */ | |
| 934 | 932 | #define XFS_EXCHMAPS_CLEAR_INO2_REFLINK (1ULL << 4) | |
| 935 | 933 | ||
| 936 | 934 | #define XFS_EXCHMAPS_LOGGED_FLAGS (XFS_EXCHMAPS_ATTR_FORK | \ | |
modified fs/xfs/xfs_bmap_util.c
| @@ -1544,7 +1544,6 @@ xfs_swap_extents( | |||
| 1544 | 1544 | struct xfs_bstat *sbp = &sxp->sx_stat; | |
| 1545 | 1545 | int src_log_flags, target_log_flags; | |
| 1546 | 1546 | int error = 0; | |
| 1547 | - | uint64_t f; | |
| 1548 | 1547 | int resblks = 0; | |
| 1549 | 1548 | unsigned int flags = 0; | |
| 1550 | 1549 | struct timespec64 ctime, mtime; | |
| @@ -1700,14 +1699,12 @@ xfs_swap_extents( | |||
| 1700 | 1699 | if (error) | |
| 1701 | 1700 | goto out_trans_cancel; | |
| 1702 | 1701 | ||
| 1703 | - | /* Do we have to swap reflink flags? */ | |
| 1704 | - | if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^ | |
| 1705 | - | (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) { | |
| 1706 | - | f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK; | |
| 1707 | - | ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; | |
| 1708 | - | ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK; | |
| 1709 | - | tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; | |
| 1710 | - | tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK; | |
| 1702 | + | /* Either inode may now own shared blocks; flag both, with CoW forks. */ | |
| 1703 | + | if ((ip->i_diflags2 | tip->i_diflags2) & XFS_DIFLAG2_REFLINK) { | |
| 1704 | + | ip->i_diflags2 |= XFS_DIFLAG2_REFLINK; | |
| 1705 | + | tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; | |
| 1706 | + | xfs_ifork_init_cow(ip); | |
| 1707 | + | xfs_ifork_init_cow(tip); | |
| 1711 | 1708 | } | |
| 1712 | 1709 | ||
| 1713 | 1710 | /* Swap the cow forks. */ | |
modified fs/xfs/xfs_exchrange.c
| @@ -290,17 +290,20 @@ retry: | |||
| 290 | 290 | goto out_unlock; | |
| 291 | 291 | ||
| 292 | 292 | /* | |
| 293 | - | * If the caller wanted us to exchange the contents of two complete | |
| 294 | - | * files of unequal length, exchange the incore sizes now. This should | |
| 295 | - | * be safe because we flushed both files' page caches, exchanged all | |
| 296 | - | * the mappings, and updated the ondisk sizes. | |
| 293 | + | * If the caller wanted, set each file's size to that file's exchange | |
| 294 | + | * offset + length exchanged from the other file because the ranges in | |
| 295 | + | * each file might be different lengths. This should be safe because | |
| 296 | + | * we flushed both files' page caches, exchanged all the mappings, and | |
| 297 | + | * updated the ondisk sizes. | |
| 297 | 298 | */ | |
| 298 | 299 | if (fxr->flags & XFS_EXCHANGE_RANGE_TO_EOF) { | |
| 299 | - | loff_t temp; | |
| 300 | + | loff_t old_ip1_size = i_size_read(VFS_I(ip1)); | |
| 301 | + | loff_t old_ip2_size = i_size_read(VFS_I(ip2)); | |
| 300 | 302 | ||
| 301 | - | temp = i_size_read(VFS_I(ip2)); | |
| 302 | - | i_size_write(VFS_I(ip2), i_size_read(VFS_I(ip1))); | |
| 303 | - | i_size_write(VFS_I(ip1), temp); | |
| 303 | + | i_size_write(VFS_I(ip2), fxr->file2_offset + | |
| 304 | + | (old_ip1_size - fxr->file1_offset)); | |
| 305 | + | i_size_write(VFS_I(ip1), fxr->file1_offset + | |
| 306 | + | (old_ip2_size - fxr->file2_offset)); | |
| 304 | 307 | } | |
| 305 | 308 | ||
| 306 | 309 | out_unlock: | |
| @@ -445,6 +448,30 @@ xfs_exchange_range_checks( | |||
| 445 | 448 | return blen == fxr->length ? 0 : -EINVAL; | |
| 446 | 449 | } | |
| 447 | 450 | ||
| 451 | + | /* Flush all relevant dirty pagecache near the range to be exchanged. */ | |
| 452 | + | static inline int | |
| 453 | + | xfs_exchange_range_flush( | |
| 454 | + | struct xfs_inode *ip, | |
| 455 | + | const struct xfs_exchrange *fxr, | |
| 456 | + | loff_t offset) | |
| 457 | + | { | |
| 458 | + | /* | |
| 459 | + | * If TO_EOF is set, the ondisk file size update logic depends on the | |
| 460 | + | * ondisk file size matching the incore file size. Flush everything. | |
| 461 | + | */ | |
| 462 | + | if (fxr->flags & XFS_EXCHANGE_RANGE_TO_EOF) | |
| 463 | + | return filemap_write_and_wait(VFS_I(ip)->i_mapping); | |
| 464 | + | ||
| 465 | + | /* | |
| 466 | + | * Because we're updating the ondisk mappings, flush all dirty data | |
| 467 | + | * between the ondisk size and the exchange offset to reduce the chance | |
| 468 | + | * of zeroed file contents in that gap after a crash. | |
| 469 | + | */ | |
| 470 | + | return filemap_write_and_wait_range(VFS_I(ip)->i_mapping, | |
| 471 | + | min(offset, ip->i_disk_size), | |
| 472 | + | offset + fxr->length - 1); | |
| 473 | + | } | |
| 474 | + | ||
| 448 | 475 | /* | |
| 449 | 476 | * Check that the two inodes are eligible for range exchanges, the ranges make | |
| 450 | 477 | * sense, and then flush all dirty data. Caller must ensure that the inodes | |
| @@ -470,15 +497,11 @@ xfs_exchange_range_prep( | |||
| 470 | 497 | if (!same_inode) | |
| 471 | 498 | inode_dio_wait(inode2); | |
| 472 | 499 | ||
| 473 | - | error = filemap_write_and_wait_range(inode1->i_mapping, | |
| 474 | - | fxr->file1_offset, | |
| 475 | - | fxr->file1_offset + fxr->length - 1); | |
| 500 | + | error = xfs_exchange_range_flush(XFS_I(inode1), fxr, fxr->file1_offset); | |
| 476 | 501 | if (error) | |
| 477 | 502 | return error; | |
| 478 | 503 | ||
| 479 | - | error = filemap_write_and_wait_range(inode2->i_mapping, | |
| 480 | - | fxr->file2_offset, | |
| 481 | - | fxr->file2_offset + fxr->length - 1); | |
| 504 | + | error = xfs_exchange_range_flush(XFS_I(inode2), fxr, fxr->file2_offset); | |
| 482 | 505 | if (error) | |
| 483 | 506 | return error; | |
| 484 | 507 | ||
modified include/linux/can/core.h
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | #include <linux/can.h> | |
| 18 | 18 | #include <linux/skbuff.h> | |
| 19 | 19 | #include <linux/netdevice.h> | |
| 20 | + | #include <net/can.h> | |
| 20 | 21 | ||
| 21 | 22 | #define DNAME(dev) ((dev) ? (dev)->name : "any") | |
| 22 | 23 | ||
| @@ -58,7 +59,7 @@ extern void can_rx_unregister(struct net *net, struct net_device *dev, | |||
| 58 | 59 | void *data); | |
| 59 | 60 | ||
| 60 | 61 | extern int can_send(struct sk_buff *skb, int loop); | |
| 61 | - | void can_set_skb_uid(struct sk_buff *skb); | |
| 62 | + | void can_set_skb_uid(struct can_skb_ext *csx); | |
| 62 | 63 | void can_sock_destruct(struct sock *sk); | |
| 63 | 64 | ||
| 64 | 65 | #endif /* !_CAN_CORE_H */ | |
modified include/linux/can/skb.h
| @@ -43,8 +43,10 @@ static inline struct can_skb_ext *can_skb_ext_add(struct sk_buff *skb) | |||
| 43 | 43 | struct can_skb_ext *csx = skb_ext_add(skb, SKB_EXT_CAN); | |
| 44 | 44 | ||
| 45 | 45 | /* skb_ext_add() returns uninitialized space */ | |
| 46 | - | if (csx) | |
| 46 | + | if (csx) { | |
| 47 | 47 | csx->can_gw_hops = 0; | |
| 48 | + | csx->can_skb_uid = 0; | |
| 49 | + | } | |
| 48 | 50 | ||
| 49 | 51 | return csx; | |
| 50 | 52 | } | |
modified include/linux/console.h
| @@ -615,6 +615,15 @@ 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 | + | } | |
| 618 | 627 | ||
| 619 | 628 | /* | |
| 620 | 629 | * Check if the given console is currently capable and allowed to print | |
| @@ -678,8 +687,14 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { } | |||
| 678 | 687 | static inline bool nbcon_kdb_try_acquire(struct console *con, | |
| 679 | 688 | struct nbcon_write_context *wctxt) { return false; } | |
| 680 | 689 | 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; } | |
| 681 | 692 | static inline bool console_is_usable(struct console *con, short flags, | |
| 682 | 693 | 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; } | |
| 683 | 698 | #endif | |
| 684 | 699 | ||
| 685 | 700 | extern int console_set_on_cmdline; | |
modified include/linux/fs.h
| @@ -1978,6 +1978,8 @@ struct file_operations { | |||
| 1978 | 1978 | #define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6)) | |
| 1979 | 1979 | /* File system supports uncached read/write buffered IO */ | |
| 1980 | 1980 | #define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7)) | |
| 1981 | + | /* Never changes and is never removed, readdir of a directory takes no lock */ | |
| 1982 | + | #define FOP_IMMUTABLE ((__force fop_flags_t)(1 << 8)) | |
| 1981 | 1983 | ||
| 1982 | 1984 | /* Wrap a directory iterator that needs exclusive inode access */ | |
| 1983 | 1985 | int wrap_directory_iterator(struct file *, struct dir_context *, | |
| @@ -2296,6 +2298,7 @@ struct file_system_type { | |||
| 2296 | 2298 | #define FS_POWER_FREEZE 256 /* Always freeze on suspend/hibernate */ | |
| 2297 | 2299 | #define FS_USERNS_MOUNT_RESTRICTED 512 /* Restrict mount in userns if not already visible */ | |
| 2298 | 2300 | #define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside */ | |
| 2301 | + | #define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */ | |
| 2299 | 2302 | #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ | |
| 2300 | 2303 | int (*init_fs_context)(struct fs_context *); | |
| 2301 | 2304 | const struct fs_parameter_spec *parameters; | |
modified include/linux/io_uring_types.h
| @@ -322,6 +322,8 @@ enum { | |||
| 322 | 322 | IO_RING_F_DRAIN_DISABLED = BIT(10), | |
| 323 | 323 | IO_RING_F_COMPAT = BIT(11), | |
| 324 | 324 | IO_RING_F_IOWQ_LIMITS_SET = BIT(12), | |
| 325 | + | /* restrictions were inherited from the task that created the ring */ | |
| 326 | + | IO_RING_F_RESTRICT_INHERITED = BIT(13), | |
| 325 | 327 | }; | |
| 326 | 328 | ||
| 327 | 329 | struct iou_ctx {}; | |
modified include/linux/mount.h
| @@ -52,7 +52,7 @@ enum mount_flags { | |||
| 52 | 52 | MNT_ATIME_MASK = MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME, | |
| 53 | 53 | ||
| 54 | 54 | MNT_INTERNAL_FLAGS = MNT_INTERNAL | MNT_DOOMED | | |
| 55 | - | MNT_SYNC_UMOUNT | MNT_LOCKED | |
| 55 | + | MNT_SYNC_UMOUNT | MNT_LOCKED | MNT_UMOUNT | |
| 56 | 56 | }; | |
| 57 | 57 | ||
| 58 | 58 | struct vfsmount { | |
modified include/linux/nsproxy.h
| @@ -100,6 +100,7 @@ void exit_cred_namespaces(struct task_struct *tsk); | |||
| 100 | 100 | void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new); | |
| 101 | 101 | int exec_task_namespaces(void); | |
| 102 | 102 | void deactivate_nsproxy(struct nsproxy *ns); | |
| 103 | + | void nsproxy_free(struct nsproxy *ns); | |
| 103 | 104 | int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **, | |
| 104 | 105 | struct cred *, struct fs_struct *); | |
| 105 | 106 | int __init nsproxy_cache_init(void); | |
modified include/linux/nvme.h
| @@ -1266,8 +1266,8 @@ enum { | |||
| 1266 | 1266 | NVME_ZRASF_ZONE_STATE_IMP_OPEN = 0x02, | |
| 1267 | 1267 | NVME_ZRASF_ZONE_STATE_EXP_OPEN = 0x03, | |
| 1268 | 1268 | NVME_ZRASF_ZONE_STATE_CLOSED = 0x04, | |
| 1269 | - | NVME_ZRASF_ZONE_STATE_READONLY = 0x05, | |
| 1270 | - | NVME_ZRASF_ZONE_STATE_FULL = 0x06, | |
| 1269 | + | NVME_ZRASF_ZONE_STATE_FULL = 0x05, | |
| 1270 | + | NVME_ZRASF_ZONE_STATE_READONLY = 0x06, | |
| 1271 | 1271 | NVME_ZRASF_ZONE_STATE_OFFLINE = 0x07, | |
| 1272 | 1272 | NVME_REPORT_ZONE_PARTIAL = 1, | |
| 1273 | 1273 | }; | |
modified include/linux/sched/ext.h
| @@ -207,6 +207,7 @@ struct sched_ext_entity { | |||
| 207 | 207 | s32 holding_cpu; | |
| 208 | 208 | s32 selected_cpu; | |
| 209 | 209 | s32 runnable_cpu; /* cpu @p is runnable on, -1 if not */ | |
| 210 | + | u32 ops_qseq; /* protected by rq lock */ | |
| 210 | 211 | struct task_struct *kf_tasks[2]; /* see SCX_CALL_OP_TASK() */ | |
| 211 | 212 | ||
| 212 | 213 | struct list_head runnable_node; /* rq->scx.runnable_list */ | |
modified include/linux/virtio_net.h
| @@ -111,48 +111,38 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb, | |||
| 111 | 111 | p_off = nh_min_len + thlen; | |
| 112 | 112 | if (!pskb_may_pull(skb, p_off)) | |
| 113 | 113 | return -EINVAL; | |
| 114 | - | } else { | |
| 114 | + | } else if (gso_type) { | |
| 115 | 115 | /* gso packets without NEEDS_CSUM do not set transport_offset. | |
| 116 | 116 | * probe and drop if does not match one of the above types. | |
| 117 | 117 | */ | |
| 118 | - | if (gso_type && skb->network_header) { | |
| 119 | - | struct flow_keys_basic keys; | |
| 120 | - | ||
| 121 | - | if (!skb->protocol) { | |
| 122 | - | __be16 protocol = dev_parse_header_protocol(skb); | |
| 123 | - | ||
| 124 | - | if (!protocol) | |
| 125 | - | virtio_net_hdr_set_proto(skb, hdr); | |
| 126 | - | else if (!virtio_net_hdr_match_proto(protocol, | |
| 127 | - | hdr_gso_type)) | |
| 128 | - | return -EINVAL; | |
| 129 | - | else | |
| 130 | - | skb->protocol = protocol; | |
| 131 | - | } | |
| 118 | + | struct flow_keys_basic keys; | |
| 119 | + | ||
| 120 | + | if (!skb->protocol) { | |
| 121 | + | skb->protocol = dev_parse_header_protocol(skb); | |
| 122 | + | if (!skb->protocol) | |
| 123 | + | virtio_net_hdr_set_proto(skb, hdr); | |
| 124 | + | } | |
| 132 | 125 | retry: | |
| 133 | - | if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys, | |
| 134 | - | NULL, 0, 0, 0, | |
| 135 | - | 0)) { | |
| 136 | - | /* UFO does not specify ipv4 or 6: try both */ | |
| 137 | - | if (gso_type & SKB_GSO_UDP && | |
| 138 | - | skb->protocol == htons(ETH_P_IP)) { | |
| 139 | - | skb->protocol = htons(ETH_P_IPV6); | |
| 140 | - | goto retry; | |
| 141 | - | } | |
| 142 | - | return -EINVAL; | |
| 126 | + | if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys, | |
| 127 | + | NULL, 0, 0, 0, | |
| 128 | + | 0)) { | |
| 129 | + | /* UFO does not specify ipv4 or 6: try both */ | |
| 130 | + | if (gso_type & SKB_GSO_UDP && | |
| 131 | + | skb->protocol == htons(ETH_P_IP)) { | |
| 132 | + | skb->protocol = htons(ETH_P_IPV6); | |
| 133 | + | goto retry; | |
| 143 | 134 | } | |
| 135 | + | return -EINVAL; | |
| 136 | + | } | |
| 144 | 137 | ||
| 145 | - | p_off = keys.control.thoff + thlen; | |
| 146 | - | if (!pskb_may_pull(skb, p_off) || | |
| 147 | - | keys.basic.ip_proto != ip_proto) | |
| 148 | - | return -EINVAL; | |
| 138 | + | p_off = keys.control.thoff + thlen; | |
| 139 | + | if (!pskb_may_pull(skb, p_off) || | |
| 140 | + | keys.basic.ip_proto != ip_proto || | |
| 141 | + | !virtio_net_hdr_match_proto(keys.basic.n_proto, | |
| 142 | + | hdr_gso_type)) | |
| 143 | + | return -EINVAL; | |
| 149 | 144 | ||
| 150 | - | skb_set_transport_header(skb, keys.control.thoff); | |
| 151 | - | } else if (gso_type) { | |
| 152 | - | p_off = nh_min_len + thlen; | |
| 153 | - | if (!pskb_may_pull(skb, p_off)) | |
| 154 | - | return -EINVAL; | |
| 155 | - | } | |
| 145 | + | skb_set_transport_header(skb, keys.control.thoff); | |
| 156 | 146 | } | |
| 157 | 147 | ||
| 158 | 148 | if (hdr_gso_type != VIRTIO_NET_HDR_GSO_NONE) { | |
modified include/net/amt.h
| @@ -231,10 +231,6 @@ struct amt_relay_headers { | |||
| 231 | 231 | }; | |
| 232 | 232 | } __packed; | |
| 233 | 233 | ||
| 234 | - | struct amt_skb_cb { | |
| 235 | - | struct amt_tunnel_list *tunnel; | |
| 236 | - | }; | |
| 237 | - | ||
| 238 | 234 | struct amt_tunnel_list { | |
| 239 | 235 | struct list_head list; | |
| 240 | 236 | /* Protect All resources under an amt_tunne_list */ | |
modified include/net/bluetooth/rfcomm.h
| @@ -207,6 +207,7 @@ struct rfcomm_dlc { | |||
| 207 | 207 | #define RFCOMM_AUTH_REJECT 7 | |
| 208 | 208 | #define RFCOMM_DEFER_SETUP 8 | |
| 209 | 209 | #define RFCOMM_ENC_DROP 9 | |
| 210 | + | #define RFCOMM_CLOSED 10 | |
| 210 | 211 | ||
| 211 | 212 | /* Scheduling flags and events */ | |
| 212 | 213 | #define RFCOMM_SCHED_WAKEUP 31 | |
modified include/net/can.h
| @@ -17,12 +17,14 @@ | |||
| 17 | 17 | * @can_framelen: cached echo CAN frame length for bql | |
| 18 | 18 | * @can_gw_hops: can-gw CAN frame time-to-live counter | |
| 19 | 19 | * @can_ext_flags: CAN skb extensions flags | |
| 20 | + | * @can_skb_uid: CAN skb UID for raw_rcv and isotp echo handling | |
| 20 | 21 | */ | |
| 21 | 22 | struct can_skb_ext { | |
| 22 | 23 | int can_iif; | |
| 23 | 24 | u16 can_framelen; | |
| 24 | 25 | u8 can_gw_hops; | |
| 25 | 26 | u8 can_ext_flags; | |
| 27 | + | u32 can_skb_uid; | |
| 26 | 28 | }; | |
| 27 | 29 | ||
| 28 | 30 | #endif /* _NET_CAN_H */ | |
modified include/net/ip.h
| @@ -74,6 +74,13 @@ static inline unsigned int ip_hdrlen(const struct sk_buff *skb) | |||
| 74 | 74 | return ip_hdr(skb)->ihl * 4; | |
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | + | static inline int ip_check_csum_start(const struct sk_buff *skb) | |
| 78 | + | { | |
| 79 | + | if (unlikely(skb->csum_start < skb->network_header + ip_hdrlen(skb))) | |
| 80 | + | return -EINVAL; | |
| 81 | + | return 0; | |
| 82 | + | } | |
| 83 | + | ||
| 77 | 84 | struct ipcm_cookie { | |
| 78 | 85 | struct sockcm_cookie sockc; | |
| 79 | 86 | __be32 addr; | |
modified include/net/mana/mana.h
| @@ -377,7 +377,18 @@ struct mana_recv_buf_oob { | |||
| 377 | 377 | #define MANA_RXBUF_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) \ | |
| 378 | 378 | + ETH_HLEN) | |
| 379 | 379 | ||
| 380 | - | #define MANA_XDP_MTU_MAX (PAGE_SIZE - MANA_RXBUF_PAD - XDP_PACKET_HEADROOM) | |
| 380 | + | /* Headroom an RX buffer has to reserve while XDP is attached: the XDP program | |
| 381 | + | * needs XDP_PACKET_HEADROOM, and the TX path needs LL_RESERVED_SPACE() (see | |
| 382 | + | * mana_get_rxbuf_headroom()). LL_RESERVED_SPACE() grows with MAX_SKB_FRAGS and | |
| 383 | + | * exceeds XDP_PACKET_HEADROOM once CONFIG_MAX_SKB_FRAGS is 19 or more. | |
| 384 | + | */ | |
| 385 | + | static inline u32 mana_xdp_headroom(struct net_device *ndev) | |
| 386 | + | { | |
| 387 | + | return max_t(u32, LL_RESERVED_SPACE(ndev), XDP_PACKET_HEADROOM); | |
| 388 | + | } | |
| 389 | + | ||
| 390 | + | #define MANA_XDP_MTU_MAX(ndev) \ | |
| 391 | + | (PAGE_SIZE - MANA_RXBUF_PAD - mana_xdp_headroom(ndev)) | |
| 381 | 392 | ||
| 382 | 393 | struct mana_rxq { | |
| 383 | 394 | struct gdma_queue *gdma_rq; | |
| @@ -691,6 +702,7 @@ int mana_query_link_cfg(struct mana_port_context *apc); | |||
| 691 | 702 | int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, | |
| 692 | 703 | int enable_clamping); | |
| 693 | 704 | void mana_query_phy_stats(struct mana_port_context *apc); | |
| 705 | + | bool mana_single_rxbuf_per_page_forced(struct mana_port_context *apc, u32 mtu); | |
| 694 | 706 | int mana_pre_alloc_rxbufs(struct mana_port_context *apc, int mtu, int num_queues); | |
| 695 | 707 | void mana_pre_dealloc_rxbufs(struct mana_port_context *apc); | |
| 696 | 708 | void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc); | |
modified include/net/strparser.h
| @@ -91,11 +91,11 @@ static inline struct strp_msg *strp_msg(struct sk_buff *skb) | |||
| 91 | 91 | struct strparser { | |
| 92 | 92 | struct sock *sk; | |
| 93 | 93 | ||
| 94 | - | u32 stopped : 1; | |
| 95 | - | u32 paused : 1; | |
| 96 | - | u32 aborted : 1; | |
| 97 | - | u32 interrupted : 1; | |
| 98 | - | u32 unrecov_intr : 1; | |
| 94 | + | u8 stopped; | |
| 95 | + | u8 paused; | |
| 96 | + | u8 aborted; | |
| 97 | + | u8 interrupted; | |
| 98 | + | u8 unrecov_intr; | |
| 99 | 99 | ||
| 100 | 100 | struct sk_buff **skb_nextp; | |
| 101 | 101 | struct sk_buff *skb_head; | |
modified io_uring/cancel.c
| @@ -634,12 +634,11 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd) | |||
| 634 | 634 | prepare_to_wait(&tctx->wait, &wait, TASK_INTERRUPTIBLE); | |
| 635 | 635 | io_run_task_work(); | |
| 636 | 636 | io_uring_drop_tctx_refs(current); | |
| 637 | + | /* only skip the sleep for local work this task may run */ | |
| 637 | 638 | xa_for_each(&tctx->xa, index, node) { | |
| 638 | - | if (io_local_work_pending(node->ctx)) { | |
| 639 | - | WARN_ON_ONCE(node->ctx->submitter_task && | |
| 640 | - | node->ctx->submitter_task != current); | |
| 639 | + | if (io_local_work_pending(node->ctx) && | |
| 640 | + | io_allowed_defer_tw_run(node->ctx)) | |
| 641 | 641 | goto end_wait; | |
| 642 | - | } | |
| 643 | 642 | } | |
| 644 | 643 | /* | |
| 645 | 644 | * If we've seen completions, retry without waiting. This | |
modified io_uring/io_uring.c
| @@ -2070,8 +2070,9 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) | |||
| 2070 | 2070 | ||
| 2071 | 2071 | static void io_rings_free(struct io_ring_ctx *ctx) | |
| 2072 | 2072 | { | |
| 2073 | - | io_free_region(ctx->user, &ctx->sq_region); | |
| 2074 | - | io_free_region(ctx->user, &ctx->ring_region); | |
| 2073 | + | /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */ | |
| 2074 | + | io_free_region(NULL, &ctx->sq_region); | |
| 2075 | + | io_free_region(NULL, &ctx->ring_region); | |
| 2075 | 2076 | ctx->rings = NULL; | |
| 2076 | 2077 | RCU_INIT_POINTER(ctx->rings_rcu, NULL); | |
| 2077 | 2078 | ctx->sq_sqes = NULL; | |
| @@ -2735,7 +2736,8 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx, | |||
| 2735 | 2736 | rd.user_addr = p->cq_off.user_addr; | |
| 2736 | 2737 | rd.flags |= IORING_MEM_REGION_TYPE_USER; | |
| 2737 | 2738 | } | |
| 2738 | - | ret = io_create_region(ctx, &ctx->ring_region, &rd, IORING_OFF_CQ_RING); | |
| 2739 | + | /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */ | |
| 2740 | + | ret = io_create_region(NULL, &ctx->ring_region, &rd, IORING_OFF_CQ_RING); | |
| 2739 | 2741 | if (ret) | |
| 2740 | 2742 | return ret; | |
| 2741 | 2743 | ctx->rings = rings = io_region_get_ptr(&ctx->ring_region); | |
| @@ -2749,7 +2751,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx, | |||
| 2749 | 2751 | rd.user_addr = p->sq_off.user_addr; | |
| 2750 | 2752 | rd.flags |= IORING_MEM_REGION_TYPE_USER; | |
| 2751 | 2753 | } | |
| 2752 | - | ret = io_create_region(ctx, &ctx->sq_region, &rd, IORING_OFF_SQES); | |
| 2754 | + | ret = io_create_region(NULL, &ctx->sq_region, &rd, IORING_OFF_SQES); | |
| 2753 | 2755 | if (ret) { | |
| 2754 | 2756 | io_rings_free(ctx); | |
| 2755 | 2757 | return ret; | |
| @@ -2960,7 +2962,8 @@ static void io_ctx_restriction_clone(struct io_ring_ctx *ctx, | |||
| 2960 | 2962 | if (dst->op_registered) | |
| 2961 | 2963 | ctx->int_flags |= IO_RING_F_OP_RESTRICTED; | |
| 2962 | 2964 | if (dst->reg_registered) | |
| 2963 | - | ctx->int_flags |= IO_RING_F_REG_RESTRICTED; | |
| 2965 | + | ctx->int_flags |= IO_RING_F_REG_RESTRICTED | | |
| 2966 | + | IO_RING_F_RESTRICT_INHERITED; | |
| 2964 | 2967 | } | |
| 2965 | 2968 | ||
| 2966 | 2969 | static __cold int io_uring_create(struct io_ctx_config *config) | |
modified io_uring/kbuf.c
| @@ -459,7 +459,7 @@ static int io_remove_buffers_legacy(struct io_ring_ctx *ctx, | |||
| 459 | 459 | static void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl) | |
| 460 | 460 | { | |
| 461 | 461 | if (bl->flags & IOBL_BUF_RING) | |
| 462 | - | io_free_region(ctx->user, &bl->region); | |
| 462 | + | io_free_region(NULL, &bl->region); | |
| 463 | 463 | else | |
| 464 | 464 | io_remove_buffers_legacy(ctx, bl, -1U); | |
| 465 | 465 | ||
| @@ -676,7 +676,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) | |||
| 676 | 676 | rd.user_addr = reg.ring_addr; | |
| 677 | 677 | rd.flags |= IORING_MEM_REGION_TYPE_USER; | |
| 678 | 678 | } | |
| 679 | - | ret = io_create_region(ctx, &bl->region, &rd, mmap_offset); | |
| 679 | + | ret = io_create_region(NULL, &bl->region, &rd, mmap_offset); | |
| 680 | 680 | if (ret) | |
| 681 | 681 | goto fail; | |
| 682 | 682 | br = io_region_get_ptr(&bl->region); | |
| @@ -709,7 +709,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg) | |||
| 709 | 709 | if (!ret) | |
| 710 | 710 | return 0; | |
| 711 | 711 | fail: | |
| 712 | - | io_free_region(ctx->user, &bl->region); | |
| 712 | + | io_free_region(NULL, &bl->region); | |
| 713 | 713 | kfree(bl); | |
| 714 | 714 | return ret; | |
| 715 | 715 | } | |
modified io_uring/memmap.c
| @@ -204,7 +204,7 @@ done: | |||
| 204 | 204 | return 0; | |
| 205 | 205 | } | |
| 206 | 206 | ||
| 207 | - | int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr, | |
| 207 | + | int io_create_region(struct user_struct *user, struct io_mapped_region *mr, | |
| 208 | 208 | struct io_uring_region_desc *reg, | |
| 209 | 209 | unsigned long mmap_offset) | |
| 210 | 210 | { | |
| @@ -230,8 +230,8 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr, | |||
| 230 | 230 | return -EOVERFLOW; | |
| 231 | 231 | ||
| 232 | 232 | nr_pages = reg->size >> PAGE_SHIFT; | |
| 233 | - | if (ctx->user) { | |
| 234 | - | ret = __io_account_mem(ctx->user, nr_pages); | |
| 233 | + | if (user) { | |
| 234 | + | ret = __io_account_mem(user, nr_pages); | |
| 235 | 235 | if (ret) | |
| 236 | 236 | return ret; | |
| 237 | 237 | } | |
| @@ -240,7 +240,7 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr, | |||
| 240 | 240 | if (reg->flags & IORING_MEM_REGION_TYPE_USER) | |
| 241 | 241 | ret = io_region_pin_pages(mr, reg); | |
| 242 | 242 | else | |
| 243 | - | ret = io_region_allocate_pages(mr, reg, mmap_offset, ctx->user); | |
| 243 | + | ret = io_region_allocate_pages(mr, reg, mmap_offset, user); | |
| 244 | 244 | if (ret) | |
| 245 | 245 | goto out_free; | |
| 246 | 246 | ||
| @@ -249,7 +249,7 @@ int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr, | |||
| 249 | 249 | goto out_free; | |
| 250 | 250 | return 0; | |
| 251 | 251 | out_free: | |
| 252 | - | io_free_region(ctx->user, mr); | |
| 252 | + | io_free_region(user, mr); | |
| 253 | 253 | return ret; | |
| 254 | 254 | } | |
| 255 | 255 | ||
modified io_uring/memmap.h
| @@ -18,7 +18,7 @@ unsigned long io_uring_get_unmapped_area(struct file *file, unsigned long addr, | |||
| 18 | 18 | int io_uring_mmap(struct file *file, struct vm_area_struct *vma); | |
| 19 | 19 | ||
| 20 | 20 | void io_free_region(struct user_struct *user, struct io_mapped_region *mr); | |
| 21 | - | int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr, | |
| 21 | + | int io_create_region(struct user_struct *user, struct io_mapped_region *mr, | |
| 22 | 22 | struct io_uring_region_desc *reg, | |
| 23 | 23 | unsigned long mmap_offset); | |
| 24 | 24 | ||
modified io_uring/net.c
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | #include <linux/un.h> | |
| 8 | 8 | #include <linux/compat.h> | |
| 9 | 9 | #include <net/compat.h> | |
| 10 | + | #include <net/ipv6.h> | |
| 10 | 11 | #include <linux/io_uring.h> | |
| 11 | 12 | ||
| 12 | 13 | #include <uapi/linux/io_uring.h> | |
| @@ -1741,7 +1742,8 @@ void io_connect_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req | |||
| 1741 | 1742 | case AF_INET6: { | |
| 1742 | 1743 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ss; | |
| 1743 | 1744 | ||
| 1744 | - | if (conn->addr_len < (int)sizeof(*sin6)) | |
| 1745 | + | /* The IPv6 stack accepts SIN6_LEN_RFC2133; port and addr are in it. */ | |
| 1746 | + | if (conn->addr_len < SIN6_LEN_RFC2133) | |
| 1745 | 1747 | break; | |
| 1746 | 1748 | bctx->connect.port = sin6->sin6_port; | |
| 1747 | 1749 | memcpy(bctx->connect.v6_addr, &sin6->sin6_addr, | |
modified io_uring/register.c
| @@ -480,8 +480,9 @@ struct io_ring_ctx_rings { | |||
| 480 | 480 | static void io_register_free_rings(struct io_ring_ctx *ctx, | |
| 481 | 481 | struct io_ring_ctx_rings *r) | |
| 482 | 482 | { | |
| 483 | - | io_free_region(ctx->user, &r->sq_region); | |
| 484 | - | io_free_region(ctx->user, &r->ring_region); | |
| 483 | + | /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */ | |
| 484 | + | io_free_region(NULL, &r->sq_region); | |
| 485 | + | io_free_region(NULL, &r->ring_region); | |
| 485 | 486 | } | |
| 486 | 487 | ||
| 487 | 488 | #define swap_old(ctx, o, n, field) \ | |
| @@ -529,7 +530,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg) | |||
| 529 | 530 | rd.user_addr = p->cq_off.user_addr; | |
| 530 | 531 | rd.flags |= IORING_MEM_REGION_TYPE_USER; | |
| 531 | 532 | } | |
| 532 | - | ret = io_create_region(ctx, &n.ring_region, &rd, IORING_OFF_CQ_RING); | |
| 533 | + | ret = io_create_region(NULL, &n.ring_region, &rd, IORING_OFF_CQ_RING); | |
| 533 | 534 | if (ret) | |
| 534 | 535 | return ret; | |
| 535 | 536 | ||
| @@ -559,7 +560,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg) | |||
| 559 | 560 | rd.user_addr = p->sq_off.user_addr; | |
| 560 | 561 | rd.flags |= IORING_MEM_REGION_TYPE_USER; | |
| 561 | 562 | } | |
| 562 | - | ret = io_create_region(ctx, &n.sq_region, &rd, IORING_OFF_SQES); | |
| 563 | + | ret = io_create_region(NULL, &n.sq_region, &rd, IORING_OFF_SQES); | |
| 563 | 564 | if (ret) { | |
| 564 | 565 | io_register_free_rings(ctx, &n); | |
| 565 | 566 | return ret; | |
| @@ -730,7 +731,8 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg) | |||
| 730 | 731 | !(ctx->flags & IORING_SETUP_R_DISABLED)) | |
| 731 | 732 | return -EINVAL; | |
| 732 | 733 | ||
| 733 | - | ret = io_create_region(ctx, ®ion, &rd, IORING_MAP_OFF_PARAM_REGION); | |
| 734 | + | ret = io_create_region(ctx->user, ®ion, &rd, | |
| 735 | + | IORING_MAP_OFF_PARAM_REGION); | |
| 734 | 736 | if (ret) | |
| 735 | 737 | return ret; | |
| 736 | 738 | if (copy_to_user(rd_uptr, &rd, sizeof(rd))) { | |
| @@ -764,7 +766,14 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, | |||
| 764 | 766 | if (ctx->submitter_task && ctx->submitter_task != current) | |
| 765 | 767 | return -EEXIST; | |
| 766 | 768 | ||
| 767 | - | if ((ctx->int_flags & IO_RING_F_REG_RESTRICTED) && !(ctx->flags & IORING_SETUP_R_DISABLED)) { | |
| 769 | + | /* | |
| 770 | + | * A disabled ring is exempt from its own register restrictions, so | |
| 771 | + | * that the creator can set them up and then enable the ring. That | |
| 772 | + | * does not apply to restrictions inherited from the task. | |
| 773 | + | */ | |
| 774 | + | if ((ctx->int_flags & IO_RING_F_REG_RESTRICTED) && | |
| 775 | + | (!(ctx->flags & IORING_SETUP_R_DISABLED) || | |
| 776 | + | (ctx->int_flags & IO_RING_F_RESTRICT_INHERITED))) { | |
| 768 | 777 | opcode = array_index_nospec(opcode, IORING_REGISTER_LAST); | |
| 769 | 778 | if (!test_bit(opcode, ctx->restrictions.register_op)) | |
| 770 | 779 | return -EACCES; | |
modified io_uring/zcrx.c
| @@ -432,7 +432,7 @@ static int io_allocate_rbuf_ring(struct io_ring_ctx *ctx, | |||
| 432 | 432 | mmap_offset = IORING_MAP_OFF_ZCRX_REGION; | |
| 433 | 433 | mmap_offset += (u64)id << IORING_OFF_ZCRX_SHIFT; | |
| 434 | 434 | ||
| 435 | - | ret = io_create_region(ctx, &ifq->rq_region, rd, mmap_offset); | |
| 435 | + | ret = io_create_region(ctx->user, &ifq->rq_region, rd, mmap_offset); | |
| 436 | 436 | if (ret < 0) | |
| 437 | 437 | return ret; | |
| 438 | 438 | ||
modified kernel/cgroup/cpuset.c
| @@ -152,6 +152,12 @@ static cpumask_var_t isolated_cpus; /* CSCB */ | |||
| 152 | 152 | */ | |
| 153 | 153 | static bool update_housekeeping; /* RWCS */ | |
| 154 | 154 | ||
| 155 | + | /* | |
| 156 | + | * Set if "cpuset_v2_mode" mount option is used | |
| 157 | + | * Cached at bind time and not lock protected; accessed via {READ,WRITE}_ONCE | |
| 158 | + | */ | |
| 159 | + | static bool cpuset_v2_mode; | |
| 160 | + | ||
| 155 | 161 | /* | |
| 156 | 162 | * Copy of isolated_cpus to be passed to housekeeping_update() | |
| 157 | 163 | */ | |
| @@ -439,8 +445,7 @@ static inline bool cpuset_v2(void) | |||
| 439 | 445 | */ | |
| 440 | 446 | static inline bool is_in_v2_mode(void) | |
| 441 | 447 | { | |
| 442 | - | return cpuset_v2() || | |
| 443 | - | (cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE); | |
| 448 | + | return cpuset_v2() || READ_ONCE(cpuset_v2_mode); | |
| 444 | 449 | } | |
| 445 | 450 | ||
| 446 | 451 | /** | |
| @@ -513,10 +518,26 @@ static void guarantee_active_cpus(struct task_struct *tsk, | |||
| 513 | 518 | rcu_read_lock(); | |
| 514 | 519 | cs = task_cs(tsk); | |
| 515 | 520 | ||
| 516 | - | while (!cpumask_intersects(cs->effective_cpus, pmask)) | |
| 521 | + | while (!cpumask_intersects(cs->effective_cpus, pmask)) { | |
| 517 | 522 | cs = parent_cs(cs); | |
| 518 | - | ||
| 523 | + | if (unlikely(!cs)) { | |
| 524 | + | /* | |
| 525 | + | * The top cpuset doesn't have any active cpu as a | |
| 526 | + | * consequence of a race between its caller and the cpu | |
| 527 | + | * hotplug operation where cpu_active_mask is updated | |
| 528 | + | * asynchronously before cpuset_handle_hotplug() is | |
| 529 | + | * being called to adjust the effective_cpus of the | |
| 530 | + | * affected cpusets. But we know the top cpuset's | |
| 531 | + | * effective_cpus is on its way to be identical to | |
| 532 | + | * cpu_active_mask minus the exclusive CPUs dedicated | |
| 533 | + | * to other valid cpuset partitions. Just pass back | |
| 534 | + | * the filtered cpu_active_mask in this case. | |
| 535 | + | */ | |
| 536 | + | goto out_unlock; | |
| 537 | + | } | |
| 538 | + | } | |
| 519 | 539 | cpumask_and(pmask, pmask, cs->effective_cpus); | |
| 540 | + | out_unlock: | |
| 520 | 541 | rcu_read_unlock(); | |
| 521 | 542 | } | |
| 522 | 543 | ||
| @@ -3732,6 +3753,8 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css) | |||
| 3732 | 3753 | mutex_lock(&cpuset_mutex); | |
| 3733 | 3754 | spin_lock_irq(&callback_lock); | |
| 3734 | 3755 | ||
| 3756 | + | WRITE_ONCE(cpuset_v2_mode, | |
| 3757 | + | !!(cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE)); | |
| 3735 | 3758 | if (is_in_v2_mode()) { | |
| 3736 | 3759 | cpumask_copy(top_cpuset.cpus_allowed, cpu_possible_mask); | |
| 3737 | 3760 | cpumask_copy(top_cpuset.effective_xcpus, cpu_possible_mask); | |
| @@ -4044,15 +4067,16 @@ static void cpuset_handle_hotplug(void) | |||
| 4044 | 4067 | static cpumask_t new_cpus; | |
| 4045 | 4068 | static nodemask_t new_mems; | |
| 4046 | 4069 | bool cpus_updated, mems_updated; | |
| 4047 | - | bool on_dfl = is_in_v2_mode(); | |
| 4070 | + | bool on_dfl; | |
| 4048 | 4071 | struct tmpmasks tmp, *ptmp = NULL; | |
| 4049 | 4072 | ||
| 4050 | - | if (on_dfl && !alloc_tmpmasks(&tmp)) | |
| 4051 | - | ptmp = &tmp; | |
| 4052 | - | ||
| 4053 | 4073 | lockdep_assert_cpus_held(); | |
| 4054 | 4074 | mutex_lock(&cpuset_mutex); | |
| 4055 | 4075 | ||
| 4076 | + | on_dfl = is_in_v2_mode(); | |
| 4077 | + | if (on_dfl && !alloc_tmpmasks(&tmp)) | |
| 4078 | + | ptmp = &tmp; | |
| 4079 | + | ||
| 4056 | 4080 | /* fetch the available cpus/mems and find out which changed how */ | |
| 4057 | 4081 | cpumask_copy(&new_cpus, cpu_active_mask); | |
| 4058 | 4082 | new_mems = node_states[N_MEMORY]; | |
modified kernel/dma/swiotlb.c
| @@ -1844,10 +1844,10 @@ phys_addr_t default_swiotlb_base(void) | |||
| 1844 | 1844 | phys_addr_t default_swiotlb_limit(void) | |
| 1845 | 1845 | { | |
| 1846 | 1846 | #ifdef CONFIG_SWIOTLB_DYNAMIC | |
| 1847 | - | return io_tlb_default_mem.phys_limit; | |
| 1848 | - | #else | |
| 1849 | - | return io_tlb_default_mem.defpool.end - 1; | |
| 1847 | + | if (io_tlb_default_mem.can_grow) | |
| 1848 | + | return io_tlb_default_mem.phys_limit; | |
| 1850 | 1849 | #endif | |
| 1850 | + | return io_tlb_default_mem.defpool.end - 1; | |
| 1851 | 1851 | } | |
| 1852 | 1852 | ||
| 1853 | 1853 | #ifdef CONFIG_DEBUG_FS | |
modified kernel/fork.c
| @@ -3317,14 +3317,17 @@ int ksys_unshare(unsigned long unshare_flags) | |||
| 3317 | 3317 | shm_init_task(current); | |
| 3318 | 3318 | } | |
| 3319 | 3319 | ||
| 3320 | + | if (new_fs) { | |
| 3321 | + | new_fs = switch_fs_struct(new_fs); | |
| 3322 | + | if (new_fs) | |
| 3323 | + | free_fs_struct(no_free_ptr(new_fs)); | |
| 3324 | + | } | |
| 3325 | + | ||
| 3320 | 3326 | if (new_nsproxy) { | |
| 3321 | 3327 | switch_task_namespaces(current, new_nsproxy); | |
| 3322 | 3328 | new_nsproxy = NULL; | |
| 3323 | 3329 | } | |
| 3324 | 3330 | ||
| 3325 | - | if (new_fs) | |
| 3326 | - | new_fs = switch_fs_struct(new_fs); | |
| 3327 | - | ||
| 3328 | 3331 | if (new_fd) { | |
| 3329 | 3332 | guard(task_lock)(current); | |
| 3330 | 3333 | swap(current->files, new_fd); | |
| @@ -3340,8 +3343,9 @@ int ksys_unshare(unsigned long unshare_flags) | |||
| 3340 | 3343 | perf_event_namespaces(current); | |
| 3341 | 3344 | ||
| 3342 | 3345 | bad_unshare_cleanup_nsproxy: | |
| 3346 | + | /* never installed, so no active references to drop */ | |
| 3343 | 3347 | if (new_nsproxy) | |
| 3344 | - | put_nsproxy(new_nsproxy); | |
| 3348 | + | nsproxy_free(new_nsproxy); | |
| 3345 | 3349 | bad_unshare_cleanup_cred: | |
| 3346 | 3350 | if (new_cred) | |
| 3347 | 3351 | put_cred(new_cred); | |
modified kernel/nsproxy.c
| @@ -61,7 +61,7 @@ static inline struct nsproxy *create_nsproxy(void) | |||
| 61 | 61 | return nsproxy; | |
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | - | static inline void nsproxy_free(struct nsproxy *ns) | |
| 64 | + | void nsproxy_free(struct nsproxy *ns) | |
| 65 | 65 | { | |
| 66 | 66 | put_mnt_ns(ns->mnt_ns); | |
| 67 | 67 | put_uts_ns(ns->uts_ns); | |
modified kernel/printk/nbcon.c
| @@ -1887,6 +1887,7 @@ 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(). */ | |
| 1890 | 1891 | ctxt->prio = NBCON_PRIO_NORMAL; | |
| 1891 | 1892 | ||
| 1892 | 1893 | if (!nbcon_context_try_acquire(ctxt, false)) | |
| @@ -2002,3 +2003,81 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt) | |||
| 2002 | 2003 | */ | |
| 2003 | 2004 | __nbcon_atomic_flush_pending_con(ctxt->console, prb_next_reserve_seq(prb)); | |
| 2004 | 2005 | } | |
| 2006 | + | ||
| 2007 | + | /** | |
| 2008 | + | * nbcon_is_braille - Checks whether the nbcon write context is using Braille console | |
| 2009 | + | * | |
| 2010 | + | * @wctxt: checked nbcon write context | |
| 2011 | + | * | |
| 2012 | + | * Return: True when the write context is associated with a Braille console. | |
| 2013 | + | * Otherwise, return false. | |
| 2014 | + | * | |
| 2015 | + | * Context: Can be called in any context but only when Braille console is | |
| 2016 | + | * registered and the struct console could not disappear. | |
| 2017 | + | */ | |
| 2018 | + | bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt) | |
| 2019 | + | { | |
| 2020 | + | struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); | |
| 2021 | + | struct console *con = ctxt->console; | |
| 2022 | + | ||
| 2023 | + | return con && con->flags & CON_BRL; | |
| 2024 | + | } | |
| 2025 | + | EXPORT_SYMBOL_GPL(nbcon_write_context_is_braille); | |
| 2026 | + | ||
| 2027 | + | /** | |
| 2028 | + | * nbcon_braille_try_acquire - Try to acquire nbcon console for braille_write() | |
| 2029 | + | * | |
| 2030 | + | * @con: The nbcon console to acquire | |
| 2031 | + | * @wctxt: The nbcon write context to be used on success | |
| 2032 | + | * | |
| 2033 | + | * Context: braille_write() for emitting a single buffer on Braille console. | |
| 2034 | + | * | |
| 2035 | + | * Return: True if the console was acquired. False otherwise. | |
| 2036 | + | * | |
| 2037 | + | * Braille console is not registered as a proper printk consoles. Instead, | |
| 2038 | + | * it is integrated with the graphical virtual terminal. | |
| 2039 | + | * | |
| 2040 | + | * This function is going to synchronize the Braille write against other | |
| 2041 | + | * operations on the used serial port. The port can be used also for a user | |
| 2042 | + | * input but printk() won't emit the messages there directly. It means | |
| 2043 | + | * the other operations will get synchronized using nbcon_device_try_acquire(). | |
| 2044 | + | */ | |
| 2045 | + | bool nbcon_braille_try_acquire(struct console *con, | |
| 2046 | + | struct nbcon_write_context *wctxt) | |
| 2047 | + | { | |
| 2048 | + | struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); | |
| 2049 | + | bool success; | |
| 2050 | + | ||
| 2051 | + | memset(ctxt, 0, sizeof(*ctxt)); | |
| 2052 | + | ctxt->console = con; | |
| 2053 | + | /* Keep in sync with nbcon_device_try_acquire(). */ | |
| 2054 | + | if (panic_on_this_cpu()) | |
| 2055 | + | ctxt->prio = NBCON_PRIO_PANIC; | |
| 2056 | + | else | |
| 2057 | + | ctxt->prio = NBCON_PRIO_NORMAL; | |
| 2058 | + | ||
| 2059 | + | success = nbcon_context_try_acquire(ctxt, false); | |
| 2060 | + | /* | |
| 2061 | + | * Try hard in panic, otherwise the Braille console would | |
| 2062 | + | * miss a text on the related VT. | |
| 2063 | + | */ | |
| 2064 | + | if (panic_on_this_cpu() && !success) { | |
| 2065 | + | ctxt->allow_unsafe_takeover = true; | |
| 2066 | + | success = nbcon_context_try_acquire(ctxt, false); | |
| 2067 | + | } | |
| 2068 | + | ||
| 2069 | + | return success; | |
| 2070 | + | } | |
| 2071 | + | ||
| 2072 | + | /** | |
| 2073 | + | * nbcon_braille_release - Release the nbcon console | |
| 2074 | + | * | |
| 2075 | + | * @wctxt: The nbcon write context initialized by a successful | |
| 2076 | + | * nbcon_braille_try_acquire() | |
| 2077 | + | */ | |
| 2078 | + | void nbcon_braille_release(struct nbcon_write_context *wctxt) | |
| 2079 | + | { | |
| 2080 | + | struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); | |
| 2081 | + | ||
| 2082 | + | nbcon_context_release(ctxt); | |
| 2083 | + | } | |
modified kernel/rcu/srcutree.c
| @@ -704,7 +704,7 @@ void cleanup_srcu_struct(struct srcu_struct *ssp) | |||
| 704 | 704 | // Call srcu_barrier() before this cleanup_srcu_struct() | |
| 705 | 705 | // to avoid triggering this WARN_ON(). | |
| 706 | 706 | if (WARN_ON(timer_delete_sync(&sdp->delay_work) && | |
| 707 | - | rcu_segcblist_n_cbs(&sdp->srcu_cblist)) && | |
| 707 | + | !rcu_segcblist_empty(&sdp->srcu_cblist)) && | |
| 708 | 708 | rcu_cpu_beenfullyonline(sdp->cpu)) | |
| 709 | 709 | queue_work_on(sdp->cpu, rcu_gp_wq, &sdp->work); | |
| 710 | 710 | flush_work(&sdp->work); | |
modified kernel/sched/ext/ext.c
| @@ -2057,8 +2057,14 @@ void scx_do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags, | |||
| 2057 | 2057 | if (unlikely(!SCX_HAS_OP(sch, enqueue))) | |
| 2058 | 2058 | goto global; | |
| 2059 | 2059 | ||
| 2060 | - | /* DSQ bypass didn't trigger, enqueue on the BPF scheduler */ | |
| 2061 | - | qseq = rq->scx.ops_qseq++ << SCX_OPSS_QSEQ_SHIFT; | |
| 2060 | + | /* | |
| 2061 | + | * DSQ bypass didn't trigger, enqueue on the BPF scheduler. Wrap the | |
| 2062 | + | * per-task qseq counter where the QSEQ field wraps and skip 0, which is | |
| 2063 | + | * what scx_bpf_dsq_insert() records for a task in NONE or DISPATCHING. | |
| 2064 | + | */ | |
| 2065 | + | p->scx.ops_qseq = ((p->scx.ops_qseq + 1) & | |
| 2066 | + | (SCX_OPSS_QSEQ_MASK >> SCX_OPSS_QSEQ_SHIFT)) ?: 1; | |
| 2067 | + | qseq = (unsigned long)p->scx.ops_qseq << SCX_OPSS_QSEQ_SHIFT; | |
| 2062 | 2068 | ||
| 2063 | 2069 | WARN_ON_ONCE(atomic_long_read(&p->scx.ops_state) != SCX_OPSS_NONE); | |
| 2064 | 2070 | atomic_long_set(&p->scx.ops_state, SCX_OPSS_QUEUEING | qseq); | |
| @@ -2123,8 +2129,8 @@ static void set_task_runnable(struct rq *rq, struct task_struct *p) | |||
| 2123 | 2129 | } | |
| 2124 | 2130 | ||
| 2125 | 2131 | /* | |
| 2126 | - | * list_add_tail() must be used. scx_bypass() depends on tasks being | |
| 2127 | - | * appended to the runnable_list. | |
| 2132 | + | * list_add_tail() must be used. scx_bypass() and rq_offline_scx() | |
| 2133 | + | * depend on tasks being appended to the runnable_list. | |
| 2128 | 2134 | */ | |
| 2129 | 2135 | list_add_tail(&p->scx.runnable_node, &rq->scx.runnable_list); | |
| 2130 | 2136 | ||
| @@ -2152,6 +2158,13 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int core_enq_ | |||
| 2152 | 2158 | int sticky_cpu = p->scx.sticky_cpu; | |
| 2153 | 2159 | u64 enq_flags = core_enq_flags | rq->scx.remote_activate_enq_flags; | |
| 2154 | 2160 | ||
| 2161 | + | /* | |
| 2162 | + | * An SCX-internal migration ends on arrival. Clear sticky_cpu so @p can | |
| 2163 | + | * leave custody when inserted into the destination DSQ. | |
| 2164 | + | */ | |
| 2165 | + | if (sticky_cpu >= 0) | |
| 2166 | + | p->scx.sticky_cpu = -1; | |
| 2167 | + | ||
| 2155 | 2168 | /* | |
| 2156 | 2169 | * SCX_RQ_IN_WAKEUP promises a task_woken_scx() call once this enqueue | |
| 2157 | 2170 | * returns. Only the core's wakeup path delivers one. The flags stashed | |
| @@ -2190,9 +2203,6 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int core_enq_ | |||
| 2190 | 2203 | dl_server_start(&rq->ext_server); | |
| 2191 | 2204 | ||
| 2192 | 2205 | scx_do_enqueue_task(rq, p, enq_flags, sticky_cpu); | |
| 2193 | - | ||
| 2194 | - | if (sticky_cpu >= 0) | |
| 2195 | - | p->scx.sticky_cpu = -1; | |
| 2196 | 2206 | out: | |
| 2197 | 2207 | rq->scx.flags &= ~SCX_RQ_IN_WAKEUP; | |
| 2198 | 2208 | ||
| @@ -3731,8 +3741,26 @@ static void rq_online_scx(struct rq *rq) | |||
| 3731 | 3741 | ||
| 3732 | 3742 | static void rq_offline_scx(struct rq *rq) | |
| 3733 | 3743 | { | |
| 3744 | + | struct task_struct *p, *n; | |
| 3745 | + | ||
| 3734 | 3746 | rq->scx.flags &= ~SCX_RQ_ONLINE; | |
| 3747 | + | ||
| 3748 | + | /* sched domain rebuilds call rq_offline with the CPU staying alive */ | |
| 3749 | + | if (cpu_active(cpu_of(rq))) | |
| 3750 | + | return; | |
| 3751 | + | ||
| 3735 | 3752 | scx_rescue_flush(rq); | |
| 3753 | + | ||
| 3754 | + | /* | |
| 3755 | + | * An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks | |
| 3756 | + | * onto the local DSQ so that they run here and balance_push() moves | |
| 3757 | + | * them off. | |
| 3758 | + | */ | |
| 3759 | + | list_for_each_entry_safe_reverse(p, n, &rq->scx.runnable_list, scx.runnable_node) { | |
| 3760 | + | if (p->scx.dsq == &rq->scx.local_dsq) | |
| 3761 | + | continue; | |
| 3762 | + | guard(sched_change)(p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK); | |
| 3763 | + | } | |
| 3736 | 3764 | } | |
| 3737 | 3765 | ||
| 3738 | 3766 | static bool check_rq_for_timeouts(struct rq *rq) | |
| @@ -6947,9 +6975,9 @@ static void scx_dump_cpu(struct scx_sched *sch, struct seq_buf *s, | |||
| 6947 | 6975 | seq_buf_init(&ns, buf, avail); | |
| 6948 | 6976 | ||
| 6949 | 6977 | dump_newline(&ns); | |
| 6950 | - | scx_dump_line(&ns, "CPU %-4d: nr_run=%u flags=0x%x cpu_rel=%d ops_qseq=%lu ksync=%lu", | |
| 6978 | + | scx_dump_line(&ns, "CPU %-4d: nr_run=%u flags=0x%x cpu_rel=%d ksync=%lu", | |
| 6951 | 6979 | cpu, rq->scx.nr_running, rq->scx.flags, rq->scx.cpu_released, | |
| 6952 | - | rq->scx.ops_qseq, rq->scx.kick_sync); | |
| 6980 | + | rq->scx.kick_sync); | |
| 6953 | 6981 | scx_rescue_dump(&ns, rq); | |
| 6954 | 6982 | scx_dump_line(&ns, " curr=%s[%d] class=%ps", | |
| 6955 | 6983 | rq->curr->comm, rq->curr->pid, rq->curr->sched_class); | |
modified kernel/sched/ext/inlines.h
| @@ -70,7 +70,13 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq, | |||
| 70 | 70 | #endif /* CONFIG_EXT_SUB_SCHED */ | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | - | if (unlikely(!SCX_HAS_OP(sch, dispatch)) || !scx_rq_online(rq)) | |
| 73 | + | /* | |
| 74 | + | * scx_rq_online() can't be used. Its cpu_active() test goes false | |
| 75 | + | * before CPU hotplug waits for an RCU grace period, and | |
| 76 | + | * rq_offline_scx() moves this CPU's tasks to the local DSQ only after | |
| 77 | + | * the wait. The grace period can depend on those tasks running. | |
| 78 | + | */ | |
| 79 | + | if (unlikely(!SCX_HAS_OP(sch, dispatch)) || !(rq->scx.flags & SCX_RQ_ONLINE)) | |
| 74 | 80 | return SCX_DSP_NONE; | |
| 75 | 81 | ||
| 76 | 82 | dspc->rq = rq; | |
modified kernel/sched/ext/internal.h
| @@ -1998,6 +1998,11 @@ enum scx_ops_state { | |||
| 1998 | 1998 | * dequeue/requeue, the dispatcher can tell whether it still has a claim | |
| 1999 | 1999 | * on the task being dispatched. | |
| 2000 | 2000 | * | |
| 2001 | + | * QSEQ is generated from the per-task p->scx.ops_qseq counter so that | |
| 2002 | + | * it doesn't repeat across QUEUED instances of the same task even if | |
| 2003 | + | * the task moves between rqs. 0 is never used as a valid QSEQ since | |
| 2004 | + | * NONE and DISPATCHING map to this value. | |
| 2005 | + | * | |
| 2001 | 2006 | * As some 32bit archs can't do 64bit store_release/load_acquire, | |
| 2002 | 2007 | * p->scx.ops_state is atomic_long_t which leaves 30 bits for QSEQ on | |
| 2003 | 2008 | * 32bit machines. The dispatch race window QSEQ protects is very narrow | |
modified kernel/sched/ext/sub.c
| @@ -585,10 +585,6 @@ void scx_rescue_flush(struct rq *rq) | |||
| 585 | 585 | ||
| 586 | 586 | lockdep_assert_rq_held(rq); | |
| 587 | 587 | ||
| 588 | - | /* sched domain rebuilds call rq_offline with the CPU staying alive */ | |
| 589 | - | if (cpu_active(cpu_of(rq))) | |
| 590 | - | return; | |
| 591 | - | ||
| 592 | 588 | /* end the current rescue */ | |
| 593 | 589 | if (rq->scx.rescue.curr) | |
| 594 | 590 | scx_task_slice_ended(rq, rq->scx.rescue.curr); | |
modified kernel/sched/sched.h
| @@ -816,7 +816,6 @@ struct scx_rq { | |||
| 816 | 816 | #endif | |
| 817 | 817 | struct list_head runnable_list; /* runnable tasks on this rq */ | |
| 818 | 818 | struct list_head ddsp_deferred_locals; /* deferred ddsps from enq */ | |
| 819 | - | unsigned long ops_qseq; | |
| 820 | 819 | /* both stashed across the activate_task() in move_remote_task_to_local_dsq() */ | |
| 821 | 820 | u64 remote_activate_enq_flags; | |
| 822 | 821 | struct scx_sched *remote_activate_sch; | |
| @@ -4222,8 +4221,9 @@ extern void balance_callbacks(struct rq *rq, struct balance_callback *head); | |||
| 4222 | 4221 | * after which it is enqueued again. | |
| 4223 | 4222 | * | |
| 4224 | 4223 | * Typically this must be called while holding task_rq_lock, since most/all | |
| 4225 | - | * properties are serialized under those locks. There is currently one | |
| 4226 | - | * exception to this rule in sched/ext which only holds rq->lock. | |
| 4224 | + | * properties are serialized under those locks. There are currently two | |
| 4225 | + | * exceptions to this rule in sched/ext which only hold rq->lock: scx_bypass() | |
| 4226 | + | * and rq_offline_scx(). | |
| 4227 | 4227 | */ | |
| 4228 | 4228 | ||
| 4229 | 4229 | /* | |
modified kernel/workqueue.c
| @@ -2290,7 +2290,7 @@ static bool is_chained_work(struct workqueue_struct *wq) | |||
| 2290 | 2290 | * Return %true iff I'm a worker executing a work item on @wq. If | |
| 2291 | 2291 | * I'm @worker, it's safe to dereference it without locking. | |
| 2292 | 2292 | */ | |
| 2293 | - | return worker && worker->current_pwq->wq == wq; | |
| 2293 | + | return worker && worker->current_pwq && worker->current_pwq->wq == wq; | |
| 2294 | 2294 | } | |
| 2295 | 2295 | ||
| 2296 | 2296 | /* | |
modified lib/Kconfig.debug
| @@ -2906,6 +2906,21 @@ config LIVEUPDATE_TEST | |||
| 2906 | 2906 | ||
| 2907 | 2907 | If unsure, say N | |
| 2908 | 2908 | ||
| 2909 | + | config DIMLIB_KUNIT_TEST | |
| 2910 | + | tristate "KUnit test for the DIM library" if !KUNIT_ALL_TESTS | |
| 2911 | + | depends on KUNIT && NET | |
| 2912 | + | select DIMLIB | |
| 2913 | + | default KUNIT_ALL_TESTS | |
| 2914 | + | help | |
| 2915 | + | This builds the KUnit test for the Dynamic Interrupt Moderation | |
| 2916 | + | library (lib/dim/), which checks the rate statistics computed by | |
| 2917 | + | dim_calc_stats(). | |
| 2918 | + | ||
| 2919 | + | For more information on KUnit and unit tests in general please refer | |
| 2920 | + | to the KUnit documentation in Documentation/dev-tools/kunit/. | |
| 2921 | + | ||
| 2922 | + | If unsure, say N. | |
| 2923 | + | ||
| 2909 | 2924 | config CMDLINE_KUNIT_TEST | |
| 2910 | 2925 | tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS | |
| 2911 | 2926 | depends on KUNIT | |
modified lib/dim/Makefile
| @@ -5,3 +5,5 @@ | |||
| 5 | 5 | obj-$(CONFIG_DIMLIB) += dimlib.o | |
| 6 | 6 | ||
| 7 | 7 | dimlib-y := dim.o net_dim.o rdma_dim.o | |
| 8 | + | ||
| 9 | + | obj-$(CONFIG_DIMLIB_KUNIT_TEST) += dim_kunit.o | |
modified lib/dim/dim.c
| @@ -69,11 +69,15 @@ bool dim_calc_stats(const struct dim_sample *start, | |||
| 69 | 69 | if (!delta_us) | |
| 70 | 70 | return false; | |
| 71 | 71 | ||
| 72 | - | curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us); | |
| 73 | - | curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us); | |
| 72 | + | /* u32 * USEC_PER_MSEC overflows a 32-bit long */ | |
| 73 | + | curr_stats->ppms = DIV_ROUND_UP_ULL((u64)npkts * USEC_PER_MSEC, | |
| 74 | + | delta_us); | |
| 75 | + | curr_stats->bpms = DIV_ROUND_UP_ULL((u64)nbytes * USEC_PER_MSEC, | |
| 76 | + | delta_us); | |
| 74 | 77 | curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC, | |
| 75 | 78 | delta_us); | |
| 76 | - | curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us); | |
| 79 | + | curr_stats->cpms = DIV_ROUND_UP_ULL((u64)ncomps * USEC_PER_MSEC, | |
| 80 | + | delta_us); | |
| 77 | 81 | if (curr_stats->epms != 0) | |
| 78 | 82 | curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL( | |
| 79 | 83 | curr_stats->cpms * 100, curr_stats->epms); | |
added lib/dim/dim_kunit.c mode 100644
| @@ -0,0 +1,126 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * KUnit tests for the Dynamic Interrupt Moderation library | |
| 4 | + | */ | |
| 5 | + | ||
| 6 | + | #include <kunit/test.h> | |
| 7 | + | #include <linux/dim.h> | |
| 8 | + | #include <linux/ktime.h> | |
| 9 | + | #include <linux/module.h> | |
| 10 | + | ||
| 11 | + | struct dim_calc_stats_case { | |
| 12 | + | const char *name; | |
| 13 | + | u32 delta_us; | |
| 14 | + | u32 start_pkts, end_pkts; | |
| 15 | + | u32 start_bytes, end_bytes; | |
| 16 | + | u32 start_comps, end_comps; | |
| 17 | + | int ppms, bpms, cpms; | |
| 18 | + | }; | |
| 19 | + | ||
| 20 | + | static const struct dim_calc_stats_case dim_calc_stats_cases[] = { | |
| 21 | + | { | |
| 22 | + | .name = "small", | |
| 23 | + | .delta_us = 1000, | |
| 24 | + | .end_pkts = 640, .end_bytes = 640 * 1500, .end_comps = 64, | |
| 25 | + | .ppms = 640, .bpms = 960000, .cpms = 64, | |
| 26 | + | }, | |
| 27 | + | { | |
| 28 | + | .name = "round_up", | |
| 29 | + | .delta_us = 3000, | |
| 30 | + | .end_pkts = 10, .end_bytes = 10, .end_comps = 1, | |
| 31 | + | .ppms = 4, .bpms = 4, .cpms = 1, | |
| 32 | + | }, | |
| 33 | + | { | |
| 34 | + | .name = "counter_wrap", | |
| 35 | + | .delta_us = 1000, | |
| 36 | + | .start_pkts = 0xffffff00, .end_pkts = 0x100, | |
| 37 | + | .start_bytes = 0xfffff000, .end_bytes = 0x1000, | |
| 38 | + | .start_comps = 0xfffffff0, .end_comps = 0x10, | |
| 39 | + | .ppms = 0x200, .bpms = 0x2000, .cpms = 0x20, | |
| 40 | + | }, | |
| 41 | + | { | |
| 42 | + | /* 30 MB in 10 ms (24 Gbit/s): nbytes * 1000 exceeds 32 bits */ | |
| 43 | + | .name = "many_bytes", | |
| 44 | + | .delta_us = 10000, | |
| 45 | + | .end_pkts = 20000, .end_bytes = 30000000, .end_comps = 64, | |
| 46 | + | .ppms = 2000, .bpms = 3000000, .cpms = 7, | |
| 47 | + | }, | |
| 48 | + | { | |
| 49 | + | /* 4.3 MB in 16 ms (2.15 Gbit/s), just above the 32-bit limit */ | |
| 50 | + | .name = "bytes_32bit_limit", | |
| 51 | + | .delta_us = 16000, | |
| 52 | + | .end_pkts = 2900, .end_bytes = 4300000, .end_comps = 64, | |
| 53 | + | .ppms = 182, .bpms = 268750, .cpms = 4, | |
| 54 | + | }, | |
| 55 | + | { | |
| 56 | + | /* 5 MB in 40 ms: a 1 Gbit/s link at line rate */ | |
| 57 | + | .name = "gigabit", | |
| 58 | + | .delta_us = 40000, | |
| 59 | + | .end_pkts = 3300, .end_bytes = 5000000, .end_comps = 64, | |
| 60 | + | .ppms = 83, .bpms = 125000, .cpms = 2, | |
| 61 | + | }, | |
| 62 | + | { | |
| 63 | + | /* 5 million packets and completions in 2 s */ | |
| 64 | + | .name = "many_packets", | |
| 65 | + | .delta_us = 2000000, | |
| 66 | + | .end_pkts = 5000000, .end_bytes = 5000000, .end_comps = 5000000, | |
| 67 | + | .ppms = 2500, .bpms = 2500, .cpms = 2500, | |
| 68 | + | }, | |
| 69 | + | }; | |
| 70 | + | ||
| 71 | + | static void dim_calc_stats_case_desc(const struct dim_calc_stats_case *t, | |
| 72 | + | char *desc) | |
| 73 | + | { | |
| 74 | + | strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE); | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | KUNIT_ARRAY_PARAM(dim_calc_stats, dim_calc_stats_cases, | |
| 78 | + | dim_calc_stats_case_desc); | |
| 79 | + | ||
| 80 | + | static void dim_calc_stats_test(struct kunit *test) | |
| 81 | + | { | |
| 82 | + | const struct dim_calc_stats_case *t = test->param_value; | |
| 83 | + | struct dim_sample start = {}, end = {}; | |
| 84 | + | struct dim_stats stats = {}; | |
| 85 | + | ||
| 86 | + | dim_update_sample_with_comps(0, t->start_pkts, t->start_bytes, | |
| 87 | + | t->start_comps, &start); | |
| 88 | + | dim_update_sample_with_comps(DIM_NEVENTS, t->end_pkts, t->end_bytes, | |
| 89 | + | t->end_comps, &end); | |
| 90 | + | /* dim_update_sample() stamps ktime_get(); use fixed times instead */ | |
| 91 | + | start.time = ktime_set(1000, 0); | |
| 92 | + | end.time = ktime_add_us(start.time, t->delta_us); | |
| 93 | + | ||
| 94 | + | KUNIT_ASSERT_TRUE(test, dim_calc_stats(&start, &end, &stats)); | |
| 95 | + | KUNIT_EXPECT_EQ(test, stats.ppms, t->ppms); | |
| 96 | + | KUNIT_EXPECT_EQ(test, stats.bpms, t->bpms); | |
| 97 | + | KUNIT_EXPECT_EQ(test, stats.cpms, t->cpms); | |
| 98 | + | KUNIT_EXPECT_EQ(test, stats.epms, | |
| 99 | + | (int)DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC, | |
| 100 | + | t->delta_us)); | |
| 101 | + | } | |
| 102 | + | ||
| 103 | + | static void dim_calc_stats_no_time_test(struct kunit *test) | |
| 104 | + | { | |
| 105 | + | struct dim_sample sample = {}; | |
| 106 | + | struct dim_stats stats = {}; | |
| 107 | + | ||
| 108 | + | dim_update_sample_with_comps(0, 100, 1000, 10, &sample); | |
| 109 | + | KUNIT_EXPECT_FALSE(test, dim_calc_stats(&sample, &sample, &stats)); | |
| 110 | + | } | |
| 111 | + | ||
| 112 | + | static struct kunit_case dim_test_cases[] = { | |
| 113 | + | KUNIT_CASE_PARAM(dim_calc_stats_test, dim_calc_stats_gen_params), | |
| 114 | + | KUNIT_CASE(dim_calc_stats_no_time_test), | |
| 115 | + | {} | |
| 116 | + | }; | |
| 117 | + | ||
| 118 | + | static struct kunit_suite dim_test_suite = { | |
| 119 | + | .name = "dim", | |
| 120 | + | .test_cases = dim_test_cases, | |
| 121 | + | }; | |
| 122 | + | ||
| 123 | + | kunit_test_suite(dim_test_suite); | |
| 124 | + | ||
| 125 | + | MODULE_DESCRIPTION("KUnit tests for the DIM library"); | |
| 126 | + | MODULE_LICENSE("GPL"); | |
modified mm/mremap.c
| @@ -1037,6 +1037,7 @@ static void vrm_stat_account(struct vma_remap_struct *vrm, | |||
| 1037 | 1037 | } | |
| 1038 | 1038 | ||
| 1039 | 1039 | static bool __check_map_count_against_split(struct mm_struct *mm, | |
| 1040 | + | bool pre_split, | |
| 1040 | 1041 | bool before_unmaps) | |
| 1041 | 1042 | { | |
| 1042 | 1043 | const int sys_map_count = get_sysctl_max_map_count(); | |
| @@ -1088,26 +1089,42 @@ static bool __check_map_count_against_split(struct mm_struct *mm, | |||
| 1088 | 1089 | * Therefore we must check to ensure we have headroom of 2 additional | |
| 1089 | 1090 | * VMAs. | |
| 1090 | 1091 | */ | |
| 1091 | - | return map_count + 2 <= sys_map_count; | |
| 1092 | + | map_count += 2; | |
| 1093 | + | ||
| 1094 | + | /* If pre-split, the -1 observed above doesn't apply. */ | |
| 1095 | + | if (pre_split) | |
| 1096 | + | map_count++; | |
| 1097 | + | ||
| 1098 | + | return map_count <= sys_map_count; | |
| 1099 | + | } | |
| 1100 | + | ||
| 1101 | + | static bool needs_pre_split(struct vma_remap_struct *vrm) | |
| 1102 | + | { | |
| 1103 | + | /* | |
| 1104 | + | * An MREMAP_DONTUNMAP of a mlock()'d VMA needs to unlock the | |
| 1105 | + | * source VMA, so split in this case. | |
| 1106 | + | */ | |
| 1107 | + | return (vrm->flags & MREMAP_DONTUNMAP) && | |
| 1108 | + | vma_test(vrm->vma, VMA_LOCKED_BIT); | |
| 1092 | 1109 | } | |
| 1093 | 1110 | ||
| 1094 | 1111 | /* Do we violate the map count limit if we split VMAs when moving the VMA? */ | |
| 1095 | - | static bool check_map_count_against_split(void) | |
| 1112 | + | static bool check_map_count_against_split(struct vma_remap_struct *vrm) | |
| 1096 | 1113 | { | |
| 1097 | 1114 | return __check_map_count_against_split(current->mm, | |
| 1098 | - | /*before_unmaps=*/false); | |
| 1115 | + | needs_pre_split(vrm), /*before_unmaps=*/false); | |
| 1099 | 1116 | } | |
| 1100 | 1117 | ||
| 1101 | 1118 | /* Do we violate the map count limit if we split VMAs prior to early unmaps? */ | |
| 1102 | - | static bool check_map_count_against_split_early(void) | |
| 1119 | + | static bool check_map_count_against_split_early(struct vma_remap_struct *vrm) | |
| 1103 | 1120 | { | |
| 1104 | 1121 | return __check_map_count_against_split(current->mm, | |
| 1105 | - | /*before_unmaps=*/true); | |
| 1122 | + | vrm->flags & MREMAP_DONTUNMAP, /*before_unmaps=*/true); | |
| 1106 | 1123 | } | |
| 1107 | 1124 | ||
| 1108 | 1125 | /* | |
| 1109 | - | * Perform checks before attempting to write a VMA prior to it being | |
| 1110 | - | * moved. | |
| 1126 | + | * Perform checks and preparation before attempting to write a VMA prior to it | |
| 1127 | + | * being moved. | |
| 1111 | 1128 | */ | |
| 1112 | 1129 | static unsigned long prep_move_vma(struct vma_remap_struct *vrm) | |
| 1113 | 1130 | { | |
| @@ -1116,19 +1133,17 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm) | |||
| 1116 | 1133 | unsigned long old_addr = vrm->addr; | |
| 1117 | 1134 | unsigned long old_len = vrm->old_len; | |
| 1118 | 1135 | vm_flags_t dummy = vma->vm_flags; | |
| 1136 | + | const bool split_before = vma->vm_start != old_addr; | |
| 1137 | + | const bool split_after = vma->vm_end != old_addr + old_len; | |
| 1119 | 1138 | ||
| 1120 | - | /* | |
| 1121 | - | * We'd prefer to avoid failure later on in do_munmap: we copy a VMA, | |
| 1122 | - | * which may not merge, then (if MREMAP_DONTUNMAP is not set) unmap the | |
| 1123 | - | * source, which may split, causing a net increase of 2 mappings. | |
| 1124 | - | */ | |
| 1125 | - | if (!check_map_count_against_split()) | |
| 1139 | + | /* Avoid failure later on. */ | |
| 1140 | + | if (!check_map_count_against_split(vrm)) | |
| 1126 | 1141 | return -ENOMEM; | |
| 1127 | 1142 | ||
| 1128 | 1143 | if (vma->vm_ops && vma->vm_ops->may_split) { | |
| 1129 | - | if (vma->vm_start != old_addr) | |
| 1144 | + | if (split_before) | |
| 1130 | 1145 | err = vma->vm_ops->may_split(vma, old_addr); | |
| 1131 | - | if (!err && vma->vm_end != old_addr + old_len) | |
| 1146 | + | if (!err && split_after) | |
| 1132 | 1147 | err = vma->vm_ops->may_split(vma, old_addr + old_len); | |
| 1133 | 1148 | if (err) | |
| 1134 | 1149 | return err; | |
| @@ -1146,6 +1161,21 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm) | |||
| 1146 | 1161 | if (err) | |
| 1147 | 1162 | return err; | |
| 1148 | 1163 | ||
| 1164 | + | /* | |
| 1165 | + | * To account mlock()'d pages correctly in the MREMAP_DONTUNMAP | |
| 1166 | + | * case perform any split ahead of time for an mlock()'d VMA. | |
| 1167 | + | */ | |
| 1168 | + | if (needs_pre_split(vrm)) { | |
| 1169 | + | VMA_ITERATOR(vmi, vma->vm_mm, old_addr); | |
| 1170 | + | ||
| 1171 | + | if (split_before) | |
| 1172 | + | err = split_vma(&vmi, vma, old_addr, 1); | |
| 1173 | + | if (!err && split_after) | |
| 1174 | + | err = split_vma(&vmi, vma, old_addr + old_len, 0); | |
| 1175 | + | vrm->vmi_needs_invalidate = true; | |
| 1176 | + | return err; | |
| 1177 | + | } | |
| 1178 | + | ||
| 1149 | 1179 | return 0; | |
| 1150 | 1180 | } | |
| 1151 | 1181 | ||
| @@ -1275,7 +1305,8 @@ static int copy_vma_and_data(struct vma_remap_struct *vrm, | |||
| 1275 | 1305 | PAGETABLE_MOVE(pmc, NULL, NULL, vrm->addr, vrm->new_addr, vrm->old_len); | |
| 1276 | 1306 | ||
| 1277 | 1307 | new_vma = copy_vma(&vma, vrm->new_addr, vrm->new_len, new_pgoff, | |
| 1278 | - | new_anon_pgoff, &pmc.need_rmap_locks); | |
| 1308 | + | new_anon_pgoff, &pmc.need_rmap_locks, | |
| 1309 | + | vrm->flags & MREMAP_DONTUNMAP); | |
| 1279 | 1310 | if (!new_vma) { | |
| 1280 | 1311 | vrm_uncharge(vrm); | |
| 1281 | 1312 | *new_vma_ptr = NULL; | |
| @@ -1335,6 +1366,9 @@ static void dontunmap_complete(struct vma_remap_struct *vrm, | |||
| 1335 | 1366 | unsigned long old_start = vma->vm_start; | |
| 1336 | 1367 | unsigned long old_end = vma->vm_end; | |
| 1337 | 1368 | ||
| 1369 | + | /* Self-merge is disallowed. */ | |
| 1370 | + | VM_WARN_ON_ONCE(new_vma == vma); | |
| 1371 | + | ||
| 1338 | 1372 | /* We always clear VMA_LOCKED[ONFAULT]_BIT on the old VMA. */ | |
| 1339 | 1373 | vma_clear_flags_mask(vma, VMA_LOCKED_MASK); | |
| 1340 | 1374 | ||
| @@ -1342,7 +1376,7 @@ static void dontunmap_complete(struct vma_remap_struct *vrm, | |||
| 1342 | 1376 | * anon_vma links of the old vma is no longer needed after its page | |
| 1343 | 1377 | * table has been moved. | |
| 1344 | 1378 | */ | |
| 1345 | - | if (new_vma != vma && start == old_start && end == old_end) { | |
| 1379 | + | if (start == old_start && end == old_end) { | |
| 1346 | 1380 | const pgoff_t pgoff_unfaulted = vma->vm_start >> PAGE_SHIFT; | |
| 1347 | 1381 | ||
| 1348 | 1382 | unlink_anon_vmas(vma); | |
| @@ -2002,7 +2036,7 @@ static unsigned long do_mremap(struct vma_remap_struct *vrm) | |||
| 2002 | 2036 | return -EINTR; | |
| 2003 | 2037 | vrm->mmap_locked = true; | |
| 2004 | 2038 | ||
| 2005 | - | if (!check_map_count_against_split_early()) { | |
| 2039 | + | if (!check_map_count_against_split_early(vrm)) { | |
| 2006 | 2040 | mmap_write_unlock(mm); | |
| 2007 | 2041 | return -ENOMEM; | |
| 2008 | 2042 | } | |
modified mm/pgtable-generic.c
| @@ -438,12 +438,30 @@ static void kernel_pgtable_work_func(struct work_struct *work) | |||
| 438 | 438 | __pagetable_free(pt); | |
| 439 | 439 | } | |
| 440 | 440 | ||
| 441 | + | static void schedule_kernel_pgtable_free(void) | |
| 442 | + | { | |
| 443 | + | schedule_work(&kernel_pgtable_work.work); | |
| 444 | + | } | |
| 445 | + | ||
| 441 | 446 | void pagetable_free_kernel(struct ptdesc *pt) | |
| 442 | 447 | { | |
| 443 | 448 | spin_lock(&kernel_pgtable_work.lock); | |
| 444 | 449 | list_add(&pt->pt_list, &kernel_pgtable_work.list); | |
| 445 | 450 | spin_unlock(&kernel_pgtable_work.lock); | |
| 446 | 451 | ||
| 447 | - | schedule_work(&kernel_pgtable_work.work); | |
| 452 | + | /* | |
| 453 | + | * The workqueue may not exist yet while the system is booting. | |
| 454 | + | * kernel_pgtable_drain_early() schedules the work once it does. | |
| 455 | + | */ | |
| 456 | + | if (system_state != SYSTEM_BOOTING) | |
| 457 | + | schedule_kernel_pgtable_free(); | |
| 458 | + | } | |
| 459 | + | ||
| 460 | + | static int __init kernel_pgtable_drain_early(void) | |
| 461 | + | { | |
| 462 | + | /* Free the kernel page tables queued while booting. */ | |
| 463 | + | schedule_kernel_pgtable_free(); | |
| 464 | + | return 0; | |
| 448 | 465 | } | |
| 466 | + | core_initcall(kernel_pgtable_drain_early); | |
| 449 | 467 | #endif | |
modified mm/vma.c
| @@ -634,8 +634,8 @@ out_free_vma: | |||
| 634 | 634 | * Split a vma into two pieces at address 'addr', a new vma is allocated | |
| 635 | 635 | * either for the first part or the tail. | |
| 636 | 636 | */ | |
| 637 | - | static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, | |
| 638 | - | unsigned long addr, int new_below) | |
| 637 | + | int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, | |
| 638 | + | unsigned long addr, int new_below) | |
| 639 | 639 | { | |
| 640 | 640 | if (vma->vm_mm->map_count >= get_sysctl_max_map_count()) | |
| 641 | 641 | return -ENOMEM; | |
| @@ -1943,7 +1943,7 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma) | |||
| 1943 | 1943 | */ | |
| 1944 | 1944 | struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, | |
| 1945 | 1945 | unsigned long addr, unsigned long len, pgoff_t pgoff, | |
| 1946 | - | pgoff_t anon_pgoff, bool *need_rmap_locks) | |
| 1946 | + | pgoff_t anon_pgoff, bool *need_rmap_locks, bool keep_source) | |
| 1947 | 1947 | { | |
| 1948 | 1948 | struct vm_area_struct *vma = *vmap; | |
| 1949 | 1949 | unsigned long old_vma_start = vma->vm_start; | |
| @@ -1981,6 +1981,21 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, | |||
| 1981 | 1981 | vmg.pgoff = pgoff; | |
| 1982 | 1982 | vmg.anon_pgoff = anon_pgoff; | |
| 1983 | 1983 | vmg.next = vma_iter_next_rewind(&vmi, NULL); | |
| 1984 | + | ||
| 1985 | + | /* | |
| 1986 | + | * If the original VMA is kept (MREMAP_DONTUNMAP), the source and | |
| 1987 | + | * destination VMA must be treated distinctly. | |
| 1988 | + | * | |
| 1989 | + | * A merge violates this, so in this case disallow a self-merge. | |
| 1990 | + | */ | |
| 1991 | + | if (can_self_merge && keep_source) { | |
| 1992 | + | if (vmg.prev == vma) | |
| 1993 | + | vmg.prev = NULL; | |
| 1994 | + | if (vmg.next == vma) | |
| 1995 | + | vmg.next = NULL; | |
| 1996 | + | can_self_merge = false; | |
| 1997 | + | } | |
| 1998 | + | ||
| 1984 | 1999 | new_vma = vma_merge_copied_range(&vmg); | |
| 1985 | 2000 | ||
| 1986 | 2001 | if (new_vma) { | |
modified mm/vma.h
| @@ -535,7 +535,7 @@ void unlink_file_vma_batch_add(struct unlink_vma_file_batch *vb, | |||
| 535 | 535 | ||
| 536 | 536 | struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, | |
| 537 | 537 | unsigned long addr, unsigned long len, pgoff_t pgoff, | |
| 538 | - | pgoff_t anon_pgoff, bool *need_rmap_locks); | |
| 538 | + | pgoff_t anon_pgoff, bool *need_rmap_locks, bool keep_source); | |
| 539 | 539 | ||
| 540 | 540 | struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma); | |
| 541 | 541 | ||
| @@ -556,6 +556,11 @@ int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *brkvma, | |||
| 556 | 556 | unsigned long unmapped_area(struct vm_unmapped_area_info *info); | |
| 557 | 557 | unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info); | |
| 558 | 558 | ||
| 559 | + | #ifdef CONFIG_MMU | |
| 560 | + | int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, | |
| 561 | + | unsigned long addr, int new_below); | |
| 562 | + | #endif | |
| 563 | + | ||
| 559 | 564 | static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma) | |
| 560 | 565 | { | |
| 561 | 566 | /* | |
modified net/bluetooth/hci_core.c
| @@ -4115,9 +4115,11 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) | |||
| 4115 | 4115 | ||
| 4116 | 4116 | bt_dev_dbg(hdev, "skb %p", skb); | |
| 4117 | 4117 | ||
| 4118 | + | hci_dev_lock(hdev); | |
| 4118 | 4119 | kfree_skb(hdev->sent_cmd); | |
| 4119 | 4120 | ||
| 4120 | 4121 | hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); | |
| 4122 | + | hci_dev_unlock(hdev); | |
| 4121 | 4123 | if (!hdev->sent_cmd) { | |
| 4122 | 4124 | skb_queue_head(&hdev->cmd_q, skb); | |
| 4123 | 4125 | queue_work(hdev->workqueue, &hdev->cmd_work); | |
| @@ -4138,8 +4140,10 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) | |||
| 4138 | 4140 | ||
| 4139 | 4141 | if (READ_ONCE(hdev->req_status) == HCI_REQ_PEND && | |
| 4140 | 4142 | !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) { | |
| 4143 | + | hci_dev_lock(hdev); | |
| 4141 | 4144 | kfree_skb(hdev->req_skb); | |
| 4142 | 4145 | hdev->req_skb = skb_get(hdev->sent_cmd); | |
| 4146 | + | hci_dev_unlock(hdev); | |
| 4143 | 4147 | } | |
| 4144 | 4148 | ||
| 4145 | 4149 | return err; | |
modified net/bluetooth/hci_sock.c
| @@ -1223,8 +1223,10 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr, | |||
| 1223 | 1223 | */ | |
| 1224 | 1224 | hdev = hci_pi(sk)->hdev; | |
| 1225 | 1225 | if (hdev && hci_dev_test_flag(hdev, HCI_UNREGISTER)) { | |
| 1226 | + | write_lock(&hci_sk_list.lock); | |
| 1226 | 1227 | hci_pi(sk)->hdev = NULL; | |
| 1227 | 1228 | sk->sk_state = BT_OPEN; | |
| 1229 | + | write_unlock(&hci_sk_list.lock); | |
| 1228 | 1230 | hci_dev_put(hdev); | |
| 1229 | 1231 | } | |
| 1230 | 1232 | hdev = NULL; | |
modified net/bluetooth/hci_sync.c
| @@ -32,8 +32,10 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, | |||
| 32 | 32 | WRITE_ONCE(hdev->req_status, HCI_REQ_DONE); | |
| 33 | 33 | ||
| 34 | 34 | /* Free the request command so it is not used as response */ | |
| 35 | + | hci_dev_lock(hdev); | |
| 35 | 36 | kfree_skb(hdev->req_skb); | |
| 36 | 37 | hdev->req_skb = NULL; | |
| 38 | + | hci_dev_unlock(hdev); | |
| 37 | 39 | ||
| 38 | 40 | if (skb) { | |
| 39 | 41 | struct sock *sk = hci_skb_sk(skb); | |
| @@ -3064,15 +3066,21 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, | |||
| 3064 | 3066 | */ | |
| 3065 | 3067 | if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { | |
| 3066 | 3068 | struct hci_cp_le_add_to_accept_list *sent; | |
| 3069 | + | bdaddr_t bdaddr; | |
| 3067 | 3070 | ||
| 3071 | + | hci_dev_lock(hdev); | |
| 3068 | 3072 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); | |
| 3073 | + | if (sent) | |
| 3074 | + | bacpy(&bdaddr, &sent->bdaddr); | |
| 3075 | + | hci_dev_unlock(hdev); | |
| 3076 | + | ||
| 3069 | 3077 | if (sent) { | |
| 3070 | 3078 | struct hci_conn *conn; | |
| 3071 | 3079 | ||
| 3072 | 3080 | rcu_read_lock(); | |
| 3073 | 3081 | ||
| 3074 | 3082 | conn = hci_conn_hash_lookup_ba(hdev, PA_LINK, | |
| 3075 | - | &sent->bdaddr); | |
| 3083 | + | &bdaddr); | |
| 3076 | 3084 | if (conn) { | |
| 3077 | 3085 | struct bt_iso_qos *qos = &conn->iso_qos; | |
| 3078 | 3086 | ||
modified net/bluetooth/iso.c
| @@ -61,6 +61,7 @@ enum { | |||
| 61 | 61 | BT_SK_BIG_SYNC, | |
| 62 | 62 | BT_SK_PA_SYNC, | |
| 63 | 63 | BT_SK_KILLED, | |
| 64 | + | BT_SK_CONNECTING, | |
| 64 | 65 | }; | |
| 65 | 66 | ||
| 66 | 67 | struct iso_pinfo { | |
| @@ -350,6 +351,9 @@ static int __iso_chan_add(struct iso_conn *conn, struct sock *sk, | |||
| 350 | 351 | return -EBUSY; | |
| 351 | 352 | } | |
| 352 | 353 | ||
| 354 | + | if (iso_pi(sk)->conn) | |
| 355 | + | return -EISCONN; | |
| 356 | + | ||
| 353 | 357 | if (!conn->hcon) { | |
| 354 | 358 | BT_ERR("conn->hcon missing"); | |
| 355 | 359 | return -EIO; | |
| @@ -410,6 +414,11 @@ static int iso_connect_bis(struct sock *sk) | |||
| 410 | 414 | hci_dev_lock(hdev); | |
| 411 | 415 | lock_sock(sk); | |
| 412 | 416 | ||
| 417 | + | if (iso_pi(sk)->conn) { | |
| 418 | + | err = -EISCONN; | |
| 419 | + | goto unlock; | |
| 420 | + | } | |
| 421 | + | ||
| 413 | 422 | if (!bis_capable(hdev)) { | |
| 414 | 423 | err = -EOPNOTSUPP; | |
| 415 | 424 | goto unlock; | |
| @@ -562,6 +571,13 @@ static int iso_connect_cis(struct sock *sk) | |||
| 562 | 571 | ||
| 563 | 572 | lockdep_assert_held(&hcon->hdev->lock); | |
| 564 | 573 | ||
| 574 | + | /* The socket lock keeps the current attachment and its hcon stable. */ | |
| 575 | + | if (iso_pi(sk)->conn && iso_pi(sk)->conn->hcon != hcon) { | |
| 576 | + | hci_conn_drop(hcon); | |
| 577 | + | err = -EISCONN; | |
| 578 | + | goto unlock; | |
| 579 | + | } | |
| 580 | + | ||
| 565 | 581 | conn = iso_conn_add(hcon); | |
| 566 | 582 | if (!conn) { | |
| 567 | 583 | hci_conn_drop(hcon); | |
| @@ -1269,17 +1285,26 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr, | |||
| 1269 | 1285 | addr->sa_family != AF_BLUETOOTH) | |
| 1270 | 1286 | return -EINVAL; | |
| 1271 | 1287 | ||
| 1272 | - | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) | |
| 1273 | - | return -EBADFD; | |
| 1288 | + | lock_sock(sk); | |
| 1274 | 1289 | ||
| 1275 | - | if (sk->sk_type != SOCK_SEQPACKET) | |
| 1276 | - | return -EINVAL; | |
| 1290 | + | if ((sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) || | |
| 1291 | + | test_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags)) { | |
| 1292 | + | err = -EBADFD; | |
| 1293 | + | goto done; | |
| 1294 | + | } | |
| 1295 | + | ||
| 1296 | + | if (sk->sk_type != SOCK_SEQPACKET) { | |
| 1297 | + | err = -EINVAL; | |
| 1298 | + | goto done; | |
| 1299 | + | } | |
| 1277 | 1300 | ||
| 1278 | 1301 | /* Check if the address type is of LE type */ | |
| 1279 | - | if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) | |
| 1280 | - | return -EINVAL; | |
| 1302 | + | if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) { | |
| 1303 | + | err = -EINVAL; | |
| 1304 | + | goto done; | |
| 1305 | + | } | |
| 1281 | 1306 | ||
| 1282 | - | lock_sock(sk); | |
| 1307 | + | set_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags); | |
| 1283 | 1308 | ||
| 1284 | 1309 | bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr); | |
| 1285 | 1310 | iso_pi(sk)->dst_type = sa->iso_bdaddr_type; | |
| @@ -1291,16 +1316,18 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr, | |||
| 1291 | 1316 | else | |
| 1292 | 1317 | err = iso_connect_bis(sk); | |
| 1293 | 1318 | ||
| 1294 | - | if (err) | |
| 1295 | - | return err; | |
| 1296 | - | ||
| 1297 | 1319 | lock_sock(sk); | |
| 1298 | 1320 | ||
| 1321 | + | clear_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags); | |
| 1322 | + | if (err) | |
| 1323 | + | goto done; | |
| 1324 | + | ||
| 1299 | 1325 | if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { | |
| 1300 | 1326 | err = bt_sock_wait_state(sk, BT_CONNECTED, | |
| 1301 | 1327 | sock_sndtimeo(sk, flags & O_NONBLOCK)); | |
| 1302 | 1328 | } | |
| 1303 | 1329 | ||
| 1330 | + | done: | |
| 1304 | 1331 | release_sock(sk); | |
| 1305 | 1332 | return err; | |
| 1306 | 1333 | } | |
| @@ -1340,6 +1367,11 @@ static int iso_listen_bis(struct sock *sk) | |||
| 1340 | 1367 | hci_dev_lock(hdev); | |
| 1341 | 1368 | lock_sock(sk); | |
| 1342 | 1369 | ||
| 1370 | + | if (sk->sk_state != BT_BOUND || iso_pi(sk)->conn) { | |
| 1371 | + | err = -EBADFD; | |
| 1372 | + | goto unlock; | |
| 1373 | + | } | |
| 1374 | + | ||
| 1343 | 1375 | /* Fail if user set invalid QoS */ | |
| 1344 | 1376 | if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) { | |
| 1345 | 1377 | iso_pi(sk)->qos = default_qos; | |
modified net/bluetooth/mgmt.c
| @@ -1495,7 +1495,7 @@ static void cmd_complete_rsp(struct mgmt_pending_cmd *cmd, void *data) | |||
| 1495 | 1495 | return; | |
| 1496 | 1496 | } | |
| 1497 | 1497 | ||
| 1498 | - | cmd_status_rsp(cmd, data); | |
| 1498 | + | cmd_status_rsp(cmd, &match->mgmt_status); | |
| 1499 | 1499 | } | |
| 1500 | 1500 | ||
| 1501 | 1501 | static int generic_cmd_complete(struct mgmt_pending_cmd *cmd, u8 status) | |
modified net/bluetooth/rfcomm/core.c
| @@ -62,10 +62,9 @@ static void rfcomm_make_uih(struct sk_buff *skb, u8 addr); | |||
| 62 | 62 | ||
| 63 | 63 | static void rfcomm_process_connect(struct rfcomm_session *s); | |
| 64 | 64 | ||
| 65 | - | static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, | |
| 66 | - | bdaddr_t *dst, | |
| 67 | - | u8 sec_level, | |
| 68 | - | int *err); | |
| 65 | + | static struct socket *rfcomm_session_connect(bdaddr_t *src, bdaddr_t *dst, | |
| 66 | + | u8 sec_level, int *err); | |
| 67 | + | static struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state); | |
| 69 | 68 | static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst); | |
| 70 | 69 | static struct rfcomm_session *rfcomm_session_del(struct rfcomm_session *s); | |
| 71 | 70 | ||
| @@ -365,28 +364,17 @@ static int rfcomm_check_channel(u8 channel) | |||
| 365 | 364 | return channel < 1 || channel > 30; | |
| 366 | 365 | } | |
| 367 | 366 | ||
| 368 | - | static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel) | |
| 367 | + | static int __rfcomm_dlc_open(struct rfcomm_dlc *d, struct rfcomm_session *s, | |
| 368 | + | u8 channel) | |
| 369 | 369 | { | |
| 370 | - | struct rfcomm_session *s; | |
| 371 | - | int err = 0; | |
| 372 | 370 | u8 dlci; | |
| 373 | 371 | ||
| 374 | - | BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d", | |
| 375 | - | d, d->state, src, dst, channel); | |
| 376 | - | ||
| 377 | - | if (rfcomm_check_channel(channel)) | |
| 378 | - | return -EINVAL; | |
| 372 | + | BT_DBG("dlc %p state %ld session %p channel %d", | |
| 373 | + | d, d->state, s, channel); | |
| 379 | 374 | ||
| 380 | 375 | if (d->state != BT_OPEN && d->state != BT_CLOSED) | |
| 381 | 376 | return 0; | |
| 382 | 377 | ||
| 383 | - | s = rfcomm_session_get(src, dst); | |
| 384 | - | if (!s) { | |
| 385 | - | s = rfcomm_session_create(src, dst, d->sec_level, &err); | |
| 386 | - | if (!s) | |
| 387 | - | return err; | |
| 388 | - | } | |
| 389 | - | ||
| 390 | 378 | dlci = __dlci(__session_dir(s), channel); | |
| 391 | 379 | ||
| 392 | 380 | /* Check if DLCI already exists */ | |
| @@ -421,14 +409,84 @@ static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, | |||
| 421 | 409 | ||
| 422 | 410 | int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel) | |
| 423 | 411 | { | |
| 424 | - | int r; | |
| 412 | + | struct rfcomm_session *s; | |
| 413 | + | struct socket *sock; | |
| 414 | + | int err; | |
| 415 | + | ||
| 416 | + | BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d", | |
| 417 | + | d, d->state, src, dst, channel); | |
| 418 | + | ||
| 419 | + | if (rfcomm_check_channel(channel)) | |
| 420 | + | return -EINVAL; | |
| 425 | 421 | ||
| 426 | 422 | rfcomm_lock(); | |
| 427 | 423 | ||
| 428 | - | r = __rfcomm_dlc_open(d, src, dst, channel); | |
| 424 | + | clear_bit(RFCOMM_CLOSED, &d->flags); | |
| 429 | 425 | ||
| 426 | + | /* Do not page the remote device for a DLC that cannot be opened | |
| 427 | + | * anyway. __rfcomm_dlc_open() looks at the state again once the | |
| 428 | + | * lock has been re-acquired below. | |
| 429 | + | */ | |
| 430 | + | if (d->state != BT_OPEN && d->state != BT_CLOSED) { | |
| 431 | + | rfcomm_unlock(); | |
| 432 | + | return 0; | |
| 433 | + | } | |
| 434 | + | ||
| 435 | + | s = rfcomm_session_get(src, dst); | |
| 436 | + | if (s) { | |
| 437 | + | err = __rfcomm_dlc_open(d, s, channel); | |
| 438 | + | rfcomm_unlock(); | |
| 439 | + | return err; | |
| 440 | + | } | |
| 430 | 441 | rfcomm_unlock(); | |
| 431 | - | return r; | |
| 442 | + | ||
| 443 | + | /* There is no session for this pair yet. kernel_connect() ends up in | |
| 444 | + | * l2cap_chan_connect(), which takes hdev->lock, and the HCI event | |
| 445 | + | * path takes rfcomm_mutex while holding hdev->lock, so the socket has | |
| 446 | + | * to be connected with rfcomm_mutex released. | |
| 447 | + | */ | |
| 448 | + | sock = rfcomm_session_connect(src, dst, d->sec_level, &err); | |
| 449 | + | if (!sock) | |
| 450 | + | return err; | |
| 451 | + | ||
| 452 | + | rfcomm_lock(); | |
| 453 | + | ||
| 454 | + | /* The DLC may have been closed while the socket was connecting. It | |
| 455 | + | * was not on a session, so rfcomm_dlc_close() could only mark it; | |
| 456 | + | * attaching it now would leave it with no owner. | |
| 457 | + | */ | |
| 458 | + | if (test_bit(RFCOMM_CLOSED, &d->flags)) { | |
| 459 | + | rfcomm_unlock(); | |
| 460 | + | sock_release(sock); | |
| 461 | + | return -ECONNRESET; | |
| 462 | + | } | |
| 463 | + | ||
| 464 | + | /* Another opener may have added a session for the same pair in the | |
| 465 | + | * meantime; that one is used and this socket is dropped. | |
| 466 | + | */ | |
| 467 | + | s = rfcomm_session_get(src, dst); | |
| 468 | + | if (!s) { | |
| 469 | + | s = rfcomm_session_add(sock, BT_BOUND); | |
| 470 | + | if (s) { | |
| 471 | + | s->initiator = 1; | |
| 472 | + | sock = NULL; | |
| 473 | + | } | |
| 474 | + | } | |
| 475 | + | ||
| 476 | + | err = s ? __rfcomm_dlc_open(d, s, channel) : -ENOMEM; | |
| 477 | + | ||
| 478 | + | rfcomm_unlock(); | |
| 479 | + | ||
| 480 | + | if (sock) | |
| 481 | + | sock_release(sock); | |
| 482 | + | ||
| 483 | + | /* Over an existing ACL link the connection can complete before the | |
| 484 | + | * session reaches the list, and that wakeup is then lost, so let | |
| 485 | + | * krfcommd look at the socket state now. | |
| 486 | + | */ | |
| 487 | + | rfcomm_schedule(); | |
| 488 | + | ||
| 489 | + | return err; | |
| 432 | 490 | } | |
| 433 | 491 | ||
| 434 | 492 | static void __rfcomm_dlc_disconn(struct rfcomm_dlc *d) | |
| @@ -508,8 +566,14 @@ int rfcomm_dlc_close(struct rfcomm_dlc *d, int err) | |||
| 508 | 566 | rfcomm_lock(); | |
| 509 | 567 | ||
| 510 | 568 | s = d->session; | |
| 511 | - | if (!s) | |
| 569 | + | if (!s) { | |
| 570 | + | /* Not on a session yet: rfcomm_dlc_open() may be connecting a | |
| 571 | + | * socket for it with rfcomm_mutex released. Leave a mark so | |
| 572 | + | * that it does not attach the DLC once it holds the lock again. | |
| 573 | + | */ | |
| 574 | + | set_bit(RFCOMM_CLOSED, &d->flags); | |
| 512 | 575 | goto no_session; | |
| 576 | + | } | |
| 513 | 577 | ||
| 514 | 578 | /* after waiting on the mutex check the session still exists | |
| 515 | 579 | * then check the dlc still exists | |
| @@ -757,12 +821,12 @@ static struct rfcomm_session *rfcomm_session_close(struct rfcomm_session *s, | |||
| 757 | 821 | return rfcomm_session_del(s); | |
| 758 | 822 | } | |
| 759 | 823 | ||
| 760 | - | static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, | |
| 761 | - | bdaddr_t *dst, | |
| 762 | - | u8 sec_level, | |
| 763 | - | int *err) | |
| 824 | + | /* Creates the L2CAP socket a new session will run on and starts connecting | |
| 825 | + | * it. Must be called with rfcomm_mutex released. | |
| 826 | + | */ | |
| 827 | + | static struct socket *rfcomm_session_connect(bdaddr_t *src, bdaddr_t *dst, | |
| 828 | + | u8 sec_level, int *err) | |
| 764 | 829 | { | |
| 765 | - | struct rfcomm_session *s = NULL; | |
| 766 | 830 | struct sockaddr_l2 addr; | |
| 767 | 831 | struct socket *sock; | |
| 768 | 832 | struct sock *sk; | |
| @@ -792,24 +856,16 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, | |||
| 792 | 856 | l2cap_pi(sk)->chan->mode = L2CAP_MODE_ERTM; | |
| 793 | 857 | release_sock(sk); | |
| 794 | 858 | ||
| 795 | - | s = rfcomm_session_add(sock, BT_BOUND); | |
| 796 | - | if (!s) { | |
| 797 | - | *err = -ENOMEM; | |
| 798 | - | goto failed; | |
| 799 | - | } | |
| 800 | - | ||
| 801 | - | s->initiator = 1; | |
| 802 | - | ||
| 803 | 859 | bacpy(&addr.l2_bdaddr, dst); | |
| 804 | 860 | addr.l2_family = AF_BLUETOOTH; | |
| 805 | 861 | addr.l2_psm = cpu_to_le16(L2CAP_PSM_RFCOMM); | |
| 806 | 862 | addr.l2_cid = 0; | |
| 807 | 863 | addr.l2_bdaddr_type = BDADDR_BREDR; | |
| 808 | 864 | *err = kernel_connect(sock, (struct sockaddr_unsized *)&addr, sizeof(addr), O_NONBLOCK); | |
| 809 | - | if (*err == 0 || *err == -EINPROGRESS) | |
| 810 | - | return s; | |
| 865 | + | if (*err && *err != -EINPROGRESS) | |
| 866 | + | goto failed; | |
| 811 | 867 | ||
| 812 | - | return rfcomm_session_del(s); | |
| 868 | + | return sock; | |
| 813 | 869 | ||
| 814 | 870 | failed: | |
| 815 | 871 | sock_release(sock); | |
modified net/bluetooth/rfcomm/sock.c
| @@ -48,8 +48,11 @@ static void rfcomm_sock_kill(struct sock *sk); | |||
| 48 | 48 | static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb) | |
| 49 | 49 | { | |
| 50 | 50 | struct sock *sk = d->owner; | |
| 51 | - | if (!sk) | |
| 51 | + | ||
| 52 | + | if (!sk) { | |
| 53 | + | kfree_skb(skb); | |
| 52 | 54 | return; | |
| 55 | + | } | |
| 53 | 56 | ||
| 54 | 57 | atomic_add(skb->len, &sk->sk_rmem_alloc); | |
| 55 | 58 | skb_queue_tail(&sk->sk_receive_queue, skb); | |
modified net/bluetooth/rfcomm/tty.c
| @@ -128,7 +128,7 @@ static void rfcomm_dev_shutdown(struct tty_port *port) | |||
| 128 | 128 | { | |
| 129 | 129 | struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port); | |
| 130 | 130 | ||
| 131 | - | if (dev->tty_dev->parent) | |
| 131 | + | if (dev->tty_dev && dev->tty_dev->parent) | |
| 132 | 132 | device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST); | |
| 133 | 133 | ||
| 134 | 134 | /* close the dlc */ | |
modified net/bluetooth/sco.c
| @@ -84,12 +84,14 @@ static void sco_conn_free(struct kref *ref) | |||
| 84 | 84 | if (conn->sk) | |
| 85 | 85 | sco_pi(conn->sk)->conn = NULL; | |
| 86 | 86 | ||
| 87 | - | if (conn->hcon) { | |
| 88 | - | conn->hcon->sco_data = NULL; | |
| 89 | - | hci_conn_drop(conn->hcon); | |
| 90 | - | } | |
| 87 | + | /* hcon->sco_data is cleared and the association's reference on the | |
| 88 | + | * sco_conn is dropped in sco_conn_del() under hdev->lock, and the | |
| 89 | + | * hci_conn is now owned by the socket (held in __sco_chan_add() and | |
| 90 | + | * dropped in sco_chan_del()/sco_sock_destruct()), so there is nothing | |
| 91 | + | * left to release towards hcon here. | |
| 92 | + | */ | |
| 91 | 93 | ||
| 92 | - | /* Ensure no more work items will run since hci_conn has been dropped */ | |
| 94 | + | /* Ensure no more work items will run before the connection is freed */ | |
| 93 | 95 | disable_delayed_work_sync(&conn->timeout_work); | |
| 94 | 96 | ||
| 95 | 97 | kfree(conn); | |
| @@ -188,25 +190,19 @@ static void sco_sock_clear_timer(struct sock *sk) | |||
| 188 | 190 | } | |
| 189 | 191 | ||
| 190 | 192 | /* ---- SCO connections ---- */ | |
| 191 | - | /* Consumes a reference on @hcon, which the returned sco_conn owns until it is | |
| 192 | - | * freed. On failure (NULL return) the reference is left for the caller to drop. | |
| 193 | + | /* Returns a new reference the caller must drop with sco_conn_put(). The | |
| 194 | + | * hcon->sco_data association holds its own reference on the sco_conn for the | |
| 195 | + | * connection's lifetime; it is dropped in sco_conn_del() under hdev->lock. | |
| 196 | + | * @hcon is not consumed: the hci_conn reference is taken and owned by the | |
| 197 | + | * socket in __sco_chan_add(). | |
| 193 | 198 | */ | |
| 194 | 199 | static struct sco_conn *sco_conn_add(struct hci_conn *hcon) | |
| 195 | 200 | { | |
| 196 | 201 | struct sco_conn *conn = hcon->sco_data; | |
| 197 | 202 | ||
| 198 | 203 | conn = sco_conn_hold_unless_zero(conn); | |
| 199 | - | if (conn) { | |
| 200 | - | if (!conn->hcon) { | |
| 201 | - | sco_conn_lock(conn); | |
| 202 | - | conn->hcon = hcon; | |
| 203 | - | sco_conn_unlock(conn); | |
| 204 | - | } else { | |
| 205 | - | /* conn already owns a reference on hcon */ | |
| 206 | - | hci_conn_drop(hcon); | |
| 207 | - | } | |
| 204 | + | if (conn) | |
| 208 | 205 | return conn; | |
| 209 | - | } | |
| 210 | 206 | ||
| 211 | 207 | conn = kzalloc_obj(struct sco_conn); | |
| 212 | 208 | if (!conn) | |
| @@ -227,7 +223,10 @@ static struct sco_conn *sco_conn_add(struct hci_conn *hcon) | |||
| 227 | 223 | ||
| 228 | 224 | BT_DBG("hcon %p conn %p", hcon, conn); | |
| 229 | 225 | ||
| 230 | - | return conn; | |
| 226 | + | /* kref_init() above set the association reference owned by | |
| 227 | + | * hcon->sco_data; hand the caller its own reference. | |
| 228 | + | */ | |
| 229 | + | return sco_conn_hold(conn); | |
| 231 | 230 | } | |
| 232 | 231 | ||
| 233 | 232 | /* Delete channel. | |
| @@ -242,6 +241,19 @@ static void sco_chan_del(struct sock *sk, int err) | |||
| 242 | 241 | BT_DBG("sk %p, conn %p, err %d", sk, conn, err); | |
| 243 | 242 | ||
| 244 | 243 | if (conn) { | |
| 244 | + | struct hci_conn *hcon; | |
| 245 | + | ||
| 246 | + | sco_conn_lock(conn); | |
| 247 | + | hcon = conn->hcon; | |
| 248 | + | sco_conn_unlock(conn); | |
| 249 | + | ||
| 250 | + | /* Drop the socket's hci_conn reference BEFORE clearing | |
| 251 | + | * conn->sk, so sco_conn_del() on another CPU cannot free | |
| 252 | + | * the hci_conn while we still hold a pointer to it. | |
| 253 | + | */ | |
| 254 | + | if (hcon) | |
| 255 | + | hci_conn_drop(hcon); | |
| 256 | + | ||
| 245 | 257 | sco_conn_lock(conn); | |
| 246 | 258 | conn->sk = NULL; | |
| 247 | 259 | sco_conn_unlock(conn); | |
| @@ -266,6 +278,13 @@ static void sco_conn_del(struct hci_conn *hcon, int err) | |||
| 266 | 278 | ||
| 267 | 279 | BT_DBG("hcon %p conn %p, err %d", hcon, conn, err); | |
| 268 | 280 | ||
| 281 | + | /* Detach from the hci_conn and drop the association's reference. | |
| 282 | + | * The caller holds hdev->lock, which serialises this against the | |
| 283 | + | * read of hcon->sco_data in sco_recv_scodata(). | |
| 284 | + | */ | |
| 285 | + | hcon->sco_data = NULL; | |
| 286 | + | sco_conn_put(conn); | |
| 287 | + | ||
| 269 | 288 | sco_conn_lock(conn); | |
| 270 | 289 | sk = sco_sock_hold(conn); | |
| 271 | 290 | sco_conn_unlock(conn); | |
| @@ -290,6 +309,11 @@ static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, | |||
| 290 | 309 | sco_pi(sk)->conn = sco_conn_hold(conn); | |
| 291 | 310 | conn->sk = sk; | |
| 292 | 311 | ||
| 312 | + | /* The socket owns an hci_conn reference for as long as it stays | |
| 313 | + | * attached; it is dropped in sco_chan_del()/sco_sock_destruct(). | |
| 314 | + | */ | |
| 315 | + | hci_conn_hold(conn->hcon); | |
| 316 | + | ||
| 293 | 317 | if (parent) | |
| 294 | 318 | bt_accept_enqueue(parent, sk, true); | |
| 295 | 319 | } | |
| @@ -371,6 +395,7 @@ static int sco_connect(struct sock *sk) | |||
| 371 | 395 | if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) { | |
| 372 | 396 | release_sock(sk); | |
| 373 | 397 | sco_conn_put(conn); | |
| 398 | + | hci_conn_drop(hcon); | |
| 374 | 399 | err = -EBADFD; | |
| 375 | 400 | goto unlock; | |
| 376 | 401 | } | |
| @@ -379,9 +404,13 @@ static int sco_connect(struct sock *sk) | |||
| 379 | 404 | sco_conn_put(conn); | |
| 380 | 405 | if (err) { | |
| 381 | 406 | release_sock(sk); | |
| 407 | + | hci_conn_drop(hcon); | |
| 382 | 408 | goto unlock; | |
| 383 | 409 | } | |
| 384 | 410 | ||
| 411 | + | /* __sco_chan_add() took its own hci_conn reference; drop ours. */ | |
| 412 | + | hci_conn_drop(hcon); | |
| 413 | + | ||
| 385 | 414 | /* Update source addr of the socket */ | |
| 386 | 415 | bacpy(&sco_pi(sk)->src, &hcon->src); | |
| 387 | 416 | ||
| @@ -495,9 +524,25 @@ static struct sock *sco_get_sock_listen(bdaddr_t *src) | |||
| 495 | 524 | ||
| 496 | 525 | static void sco_sock_destruct(struct sock *sk) | |
| 497 | 526 | { | |
| 527 | + | struct sco_conn *conn = sco_pi(sk)->conn; | |
| 528 | + | ||
| 498 | 529 | BT_DBG("sk %p", sk); | |
| 499 | 530 | ||
| 500 | - | sco_conn_put(sco_pi(sk)->conn); | |
| 531 | + | /* If the channel was not already torn down via sco_chan_del(), drop | |
| 532 | + | * the socket's own references here. | |
| 533 | + | */ | |
| 534 | + | if (conn) { | |
| 535 | + | struct hci_conn *hcon; | |
| 536 | + | ||
| 537 | + | sco_conn_lock(conn); | |
| 538 | + | hcon = conn->hcon; | |
| 539 | + | sco_conn_unlock(conn); | |
| 540 | + | ||
| 541 | + | if (hcon) | |
| 542 | + | hci_conn_drop(hcon); | |
| 543 | + | sco_pi(sk)->conn = NULL; | |
| 544 | + | sco_conn_put(conn); | |
| 545 | + | } | |
| 501 | 546 | ||
| 502 | 547 | skb_queue_purge(&sk->sk_receive_queue); | |
| 503 | 548 | skb_queue_purge(&sk->sk_write_queue); | |
| @@ -1511,12 +1556,10 @@ static void sco_connect_cfm(struct hci_conn *hcon, __u8 status) | |||
| 1511 | 1556 | if (!status) { | |
| 1512 | 1557 | struct sco_conn *conn; | |
| 1513 | 1558 | ||
| 1514 | - | conn = sco_conn_add(hci_conn_hold(hcon)); | |
| 1559 | + | conn = sco_conn_add(hcon); | |
| 1515 | 1560 | if (conn) { | |
| 1516 | 1561 | sco_conn_ready(conn); | |
| 1517 | 1562 | sco_conn_put(conn); | |
| 1518 | - | } else { | |
| 1519 | - | hci_conn_drop(hcon); | |
| 1520 | 1563 | } | |
| 1521 | 1564 | } else | |
| 1522 | 1565 | sco_conn_del(hcon, bt_to_errno(status)); | |
modified net/bridge/br_multicast.c
| @@ -81,6 +81,10 @@ __br_multicast_add_group(struct net_bridge_mcast *brmctx, | |||
| 81 | 81 | bool blocked); | |
| 82 | 82 | static void br_multicast_find_del_pg(struct net_bridge *br, | |
| 83 | 83 | struct net_bridge_port_group *pg); | |
| 84 | + | static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |
| 85 | + | struct net_bridge_port_group *pg, | |
| 86 | + | struct net_bridge_port_group __rcu **pp, | |
| 87 | + | bool sg_del_exclude_ports); | |
| 84 | 88 | static void __br_multicast_stop(struct net_bridge_mcast *brmctx); | |
| 85 | 89 | ||
| 86 | 90 | static int br_mc_disabled_update(struct net_device *dev, bool value, | |
| @@ -458,7 +462,7 @@ static void br_multicast_sg_del_exclude_ports(struct net_bridge_mdb_entry *sgmp) | |||
| 458 | 462 | for (pp = &sgmp->ports; | |
| 459 | 463 | (p = mlock_dereference(*pp, sgmp->br)) != NULL;) { | |
| 460 | 464 | if (!(p->flags & MDB_PG_FLAGS_PERMANENT)) | |
| 461 | - | br_multicast_del_pg(sgmp, p, pp); | |
| 465 | + | __br_multicast_del_pg(sgmp, p, pp, false); | |
| 462 | 466 | else | |
| 463 | 467 | pp = &p->next; | |
| 464 | 468 | } | |
| @@ -799,9 +803,10 @@ static void br_multicast_destroy_port_group(struct net_bridge_mcast_gc *gc) | |||
| 799 | 803 | kfree_rcu(pg, rcu); | |
| 800 | 804 | } | |
| 801 | 805 | ||
| 802 | - | void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |
| 803 | - | struct net_bridge_port_group *pg, | |
| 804 | - | struct net_bridge_port_group __rcu **pp) | |
| 806 | + | static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |
| 807 | + | struct net_bridge_port_group *pg, | |
| 808 | + | struct net_bridge_port_group __rcu **pp, | |
| 809 | + | bool sg_del_exclude_ports) | |
| 805 | 810 | { | |
| 806 | 811 | struct net_bridge *br = pg->key.port->br; | |
| 807 | 812 | struct net_bridge_group_src *ent; | |
| @@ -820,7 +825,8 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |||
| 820 | 825 | if (!br_multicast_is_star_g(&mp->addr)) { | |
| 821 | 826 | rhashtable_remove_fast(&br->sg_port_tbl, &pg->rhnode, | |
| 822 | 827 | br_sg_port_rht_params); | |
| 823 | - | br_multicast_sg_del_exclude_ports(mp); | |
| 828 | + | if (sg_del_exclude_ports) | |
| 829 | + | br_multicast_sg_del_exclude_ports(mp); | |
| 824 | 830 | } else { | |
| 825 | 831 | br_multicast_star_g_handle_mode(pg, MCAST_INCLUDE); | |
| 826 | 832 | } | |
| @@ -832,6 +838,13 @@ void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |||
| 832 | 838 | mod_timer(&mp->timer, jiffies); | |
| 833 | 839 | } | |
| 834 | 840 | ||
| 841 | + | void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, | |
| 842 | + | struct net_bridge_port_group *pg, | |
| 843 | + | struct net_bridge_port_group __rcu **pp) | |
| 844 | + | { | |
| 845 | + | __br_multicast_del_pg(mp, pg, pp, true); | |
| 846 | + | } | |
| 847 | + | ||
| 835 | 848 | static void br_multicast_find_del_pg(struct net_bridge *br, | |
| 836 | 849 | struct net_bridge_port_group *pg) | |
| 837 | 850 | { | |
modified net/bridge/netfilter/nf_conntrack_bridge.c
| @@ -39,9 +39,13 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk, | |||
| 39 | 39 | int err = 0; | |
| 40 | 40 | ||
| 41 | 41 | /* for offloaded checksums cleanup checksum before fragmentation */ | |
| 42 | - | if (skb->ip_summed == CHECKSUM_PARTIAL && | |
| 43 | - | (err = skb_checksum_help(skb))) | |
| 44 | - | goto blackhole; | |
| 42 | + | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
| 43 | + | err = ip_check_csum_start(skb); | |
| 44 | + | if (!err) | |
| 45 | + | err = skb_checksum_help(skb); | |
| 46 | + | if (err) | |
| 47 | + | goto blackhole; | |
| 48 | + | } | |
| 45 | 49 | ||
| 46 | 50 | iph = ip_hdr(skb); | |
| 47 | 51 | ||
modified net/can/af_can.c
| @@ -641,13 +641,10 @@ static int can_rcv_filter(struct can_dev_rcv_lists *dev_rcv_lists, struct sk_buf | |||
| 641 | 641 | return matches; | |
| 642 | 642 | } | |
| 643 | 643 | ||
| 644 | - | void can_set_skb_uid(struct sk_buff *skb) | |
| 644 | + | void can_set_skb_uid(struct can_skb_ext *csx) | |
| 645 | 645 | { | |
| 646 | - | /* create non-zero unique skb identifier together with *skb */ | |
| 647 | - | while (!(skb->hash)) | |
| 648 | - | skb->hash = atomic_inc_return(&skbcounter); | |
| 649 | - | ||
| 650 | - | skb->sw_hash = 1; | |
| 646 | + | while (!(csx->can_skb_uid)) | |
| 647 | + | csx->can_skb_uid = atomic_inc_return(&skbcounter); | |
| 651 | 648 | } | |
| 652 | 649 | EXPORT_SYMBOL(can_set_skb_uid); | |
| 653 | 650 | ||
| @@ -662,8 +659,6 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev) | |||
| 662 | 659 | atomic_long_inc(&pkg_stats->rx_frames); | |
| 663 | 660 | atomic_long_inc(&pkg_stats->rx_frames_delta); | |
| 664 | 661 | ||
| 665 | - | can_set_skb_uid(skb); | |
| 666 | - | ||
| 667 | 662 | rcu_read_lock(); | |
| 668 | 663 | ||
| 669 | 664 | /* deliver the packet to sockets listening on all devices */ | |
| @@ -687,8 +682,10 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev) | |||
| 687 | 682 | static int can_rcv(struct sk_buff *skb, struct net_device *dev, | |
| 688 | 683 | struct packet_type *pt, struct net_device *orig_dev) | |
| 689 | 684 | { | |
| 685 | + | struct can_skb_ext *csx = can_skb_ext_find(skb); | |
| 686 | + | ||
| 690 | 687 | if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || | |
| 691 | - | !can_skb_ext_find(skb) || !can_is_can_skb(skb))) { | |
| 688 | + | !csx || !can_is_can_skb(skb))) { | |
| 692 | 689 | pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n", | |
| 693 | 690 | dev->type, skb->len); | |
| 694 | 691 | ||
| @@ -696,6 +693,14 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, | |||
| 696 | 693 | return NET_RX_DROP; | |
| 697 | 694 | } | |
| 698 | 695 | ||
| 696 | + | /* create unshared CAN skb_extension for netem/mirred skb clones */ | |
| 697 | + | csx = skb_ext_add(skb, SKB_EXT_CAN); | |
| 698 | + | if (unlikely(!csx)) { | |
| 699 | + | kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM); | |
| 700 | + | return NET_RX_DROP; | |
| 701 | + | } | |
| 702 | + | ||
| 703 | + | can_set_skb_uid(csx); | |
| 699 | 704 | can_receive(skb, dev); | |
| 700 | 705 | return NET_RX_SUCCESS; | |
| 701 | 706 | } | |
| @@ -703,8 +708,10 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, | |||
| 703 | 708 | static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, | |
| 704 | 709 | struct packet_type *pt, struct net_device *orig_dev) | |
| 705 | 710 | { | |
| 711 | + | struct can_skb_ext *csx = can_skb_ext_find(skb); | |
| 712 | + | ||
| 706 | 713 | if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || | |
| 707 | - | !can_skb_ext_find(skb) || !can_is_canfd_skb(skb))) { | |
| 714 | + | !csx || !can_is_canfd_skb(skb))) { | |
| 708 | 715 | pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n", | |
| 709 | 716 | dev->type, skb->len); | |
| 710 | 717 | ||
| @@ -712,6 +719,14 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, | |||
| 712 | 719 | return NET_RX_DROP; | |
| 713 | 720 | } | |
| 714 | 721 | ||
| 722 | + | /* create unshared CAN skb_extension for netem/mirred skb clones */ | |
| 723 | + | csx = skb_ext_add(skb, SKB_EXT_CAN); | |
| 724 | + | if (unlikely(!csx)) { | |
| 725 | + | kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM); | |
| 726 | + | return NET_RX_DROP; | |
| 727 | + | } | |
| 728 | + | ||
| 729 | + | can_set_skb_uid(csx); | |
| 715 | 730 | can_receive(skb, dev); | |
| 716 | 731 | return NET_RX_SUCCESS; | |
| 717 | 732 | } | |
| @@ -719,8 +734,10 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev, | |||
| 719 | 734 | static int canxl_rcv(struct sk_buff *skb, struct net_device *dev, | |
| 720 | 735 | struct packet_type *pt, struct net_device *orig_dev) | |
| 721 | 736 | { | |
| 737 | + | struct can_skb_ext *csx = can_skb_ext_find(skb); | |
| 738 | + | ||
| 722 | 739 | if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || | |
| 723 | - | !can_skb_ext_find(skb) || !can_is_canxl_skb(skb))) { | |
| 740 | + | !csx || !can_is_canxl_skb(skb))) { | |
| 724 | 741 | pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n", | |
| 725 | 742 | dev->type, skb->len); | |
| 726 | 743 | ||
| @@ -728,6 +745,14 @@ static int canxl_rcv(struct sk_buff *skb, struct net_device *dev, | |||
| 728 | 745 | return NET_RX_DROP; | |
| 729 | 746 | } | |
| 730 | 747 | ||
| 748 | + | /* create unshared CAN skb_extension for netem/mirred skb clones */ | |
| 749 | + | csx = skb_ext_add(skb, SKB_EXT_CAN); | |
| 750 | + | if (unlikely(!csx)) { | |
| 751 | + | kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM); | |
| 752 | + | return NET_RX_DROP; | |
| 753 | + | } | |
| 754 | + | ||
| 755 | + | can_set_skb_uid(csx); | |
| 731 | 756 | can_receive(skb, dev); | |
| 732 | 757 | return NET_RX_SUCCESS; | |
| 733 | 758 | } | |
modified net/can/gw.c
| @@ -527,6 +527,9 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data) | |||
| 527 | 527 | /* put the incremented hop counter in the cloned skb */ | |
| 528 | 528 | ncsx->can_gw_hops = csx->can_gw_hops + 1; | |
| 529 | 529 | ||
| 530 | + | /* force a new CAN UID generation for the routed frame */ | |
| 531 | + | ncsx->can_skb_uid = 0; | |
| 532 | + | ||
| 530 | 533 | /* first processing of this CAN frame -> adjust to private hop limit */ | |
| 531 | 534 | if (gwj->limit_hops && ncsx->can_gw_hops == 1) | |
| 532 | 535 | ncsx->can_gw_hops = max_hops - gwj->limit_hops + 1; | |
modified net/can/isotp.c
| @@ -891,7 +891,7 @@ static void isotp_send_cframe(struct isotp_sock *so) | |||
| 891 | 891 | csx->can_iif = dev->ifindex; | |
| 892 | 892 | ||
| 893 | 893 | /* set uid in tx skb to identify CF echo frames */ | |
| 894 | - | can_set_skb_uid(skb); | |
| 894 | + | can_set_skb_uid(csx); | |
| 895 | 895 | ||
| 896 | 896 | cf = (struct canfd_frame *)skb->data; | |
| 897 | 897 | skb_put_zero(skb, so->ll.mtu); | |
| @@ -917,7 +917,7 @@ static void isotp_send_cframe(struct isotp_sock *so) | |||
| 917 | 917 | pr_notice_once("can-isotp: cfecho is %08X != 0\n", old_cfecho); | |
| 918 | 918 | ||
| 919 | 919 | /* set consecutive frame echo tag */ | |
| 920 | - | WRITE_ONCE(so->cfecho, skb->hash); | |
| 920 | + | WRITE_ONCE(so->cfecho, csx->can_skb_uid); | |
| 921 | 921 | ||
| 922 | 922 | /* send frame with local echo enabled */ | |
| 923 | 923 | can_send_ret = can_send(skb, 1); | |
| @@ -969,18 +969,22 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data) | |||
| 969 | 969 | { | |
| 970 | 970 | struct sock *sk = (struct sock *)data; | |
| 971 | 971 | struct isotp_sock *so = isotp_sk(sk); | |
| 972 | + | struct can_skb_ext *csx = can_skb_ext_find(skb); | |
| 972 | 973 | ||
| 973 | 974 | /* only handle my own local echo CF/SF skb's (no FF!) */ | |
| 974 | 975 | if (skb->sk != sk) | |
| 975 | 976 | return; | |
| 976 | 977 | ||
| 978 | + | if (WARN_ON_ONCE(!csx)) | |
| 979 | + | return; | |
| 980 | + | ||
| 977 | 981 | /* unlike isotp_rcv_fc()/isotp_rcv_cf(), not already under so->rx_lock | |
| 978 | 982 | * (no isotp_rcv() caller here), so take it ourselves | |
| 979 | 983 | */ | |
| 980 | 984 | spin_lock(&so->rx_lock); | |
| 981 | 985 | ||
| 982 | 986 | /* so->cfecho may since belong to a new transfer; recheck under lock */ | |
| 983 | - | if (READ_ONCE(so->cfecho) != skb->hash) | |
| 987 | + | if (READ_ONCE(so->cfecho) != csx->can_skb_uid) | |
| 984 | 988 | goto out_unlock; | |
| 985 | 989 | ||
| 986 | 990 | /* cancel local echo timeout */ | |
| @@ -1222,7 +1226,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
| 1222 | 1226 | csx->can_iif = dev->ifindex; | |
| 1223 | 1227 | ||
| 1224 | 1228 | /* set uid in tx skb to identify CF echo frames */ | |
| 1225 | - | can_set_skb_uid(skb); | |
| 1229 | + | can_set_skb_uid(csx); | |
| 1226 | 1230 | ||
| 1227 | 1231 | so->tx.len = size; | |
| 1228 | 1232 | so->tx.idx = 0; | |
| @@ -1261,7 +1265,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
| 1261 | 1265 | cf->data[ae] |= size; | |
| 1262 | 1266 | ||
| 1263 | 1267 | /* set CF echo tag for isotp_rcv_echo() (SF-mode) */ | |
| 1264 | - | WRITE_ONCE(so->cfecho, skb->hash); | |
| 1268 | + | WRITE_ONCE(so->cfecho, csx->can_skb_uid); | |
| 1265 | 1269 | } else { | |
| 1266 | 1270 | /* send first frame */ | |
| 1267 | 1271 | ||
| @@ -1278,7 +1282,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
| 1278 | 1282 | so->txfc.bs = 0; | |
| 1279 | 1283 | ||
| 1280 | 1284 | /* set CF echo tag for isotp_rcv_echo() (CF-mode) */ | |
| 1281 | - | WRITE_ONCE(so->cfecho, skb->hash); | |
| 1285 | + | WRITE_ONCE(so->cfecho, csx->can_skb_uid); | |
| 1282 | 1286 | } else { | |
| 1283 | 1287 | /* standard flow control check */ | |
| 1284 | 1288 | new_state = ISOTP_WAIT_FIRST_FC; | |
modified net/can/raw.c
| @@ -77,7 +77,7 @@ MODULE_ALIAS("can-proto-1"); | |||
| 77 | 77 | ||
| 78 | 78 | struct uniqframe { | |
| 79 | 79 | const struct sk_buff *skb; | |
| 80 | - | u32 hash; | |
| 80 | + | u32 can_skb_uid; | |
| 81 | 81 | unsigned int join_rx_count; | |
| 82 | 82 | }; | |
| 83 | 83 | ||
| @@ -133,12 +133,16 @@ static void raw_rcv(struct sk_buff *oskb, void *data) | |||
| 133 | 133 | enum skb_drop_reason reason; | |
| 134 | 134 | struct sockaddr_can *addr; | |
| 135 | 135 | struct sk_buff *skb; | |
| 136 | + | struct can_skb_ext *csx = can_skb_ext_find(oskb); | |
| 136 | 137 | unsigned int *pflags; | |
| 137 | 138 | ||
| 138 | 139 | /* check the received tx sock reference */ | |
| 139 | 140 | if (!ro->recv_own_msgs && oskb->sk == sk) | |
| 140 | 141 | return; | |
| 141 | 142 | ||
| 143 | + | if (WARN_ON_ONCE(!csx)) | |
| 144 | + | return; | |
| 145 | + | ||
| 142 | 146 | /* make sure to not pass oversized frames to the socket */ | |
| 143 | 147 | if (!ro->fd_frames && can_is_canfd_skb(oskb)) | |
| 144 | 148 | return; | |
| @@ -165,7 +169,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) | |||
| 165 | 169 | ||
| 166 | 170 | /* eliminate multiple filter matches for the same skb */ | |
| 167 | 171 | if (this_cpu_ptr(ro->uniq)->skb == oskb && | |
| 168 | - | this_cpu_ptr(ro->uniq)->hash == oskb->hash) { | |
| 172 | + | this_cpu_ptr(ro->uniq)->can_skb_uid == csx->can_skb_uid) { | |
| 169 | 173 | if (!ro->join_filters) | |
| 170 | 174 | return; | |
| 171 | 175 | ||
| @@ -175,7 +179,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) | |||
| 175 | 179 | return; | |
| 176 | 180 | } else { | |
| 177 | 181 | this_cpu_ptr(ro->uniq)->skb = oskb; | |
| 178 | - | this_cpu_ptr(ro->uniq)->hash = oskb->hash; | |
| 182 | + | this_cpu_ptr(ro->uniq)->can_skb_uid = csx->can_skb_uid; | |
| 179 | 183 | this_cpu_ptr(ro->uniq)->join_rx_count = 1; | |
| 180 | 184 | /* drop first frame to check all enabled filters? */ | |
| 181 | 185 | if (ro->join_filters && ro->count > 1) | |
modified net/core/dev.c
| @@ -10364,13 +10364,15 @@ EXPORT_SYMBOL_GPL(dev_xdp_prog_count); | |||
| 10364 | 10364 | ||
| 10365 | 10365 | u8 dev_xdp_sb_prog_count(struct net_device *dev) | |
| 10366 | 10366 | { | |
| 10367 | + | struct bpf_prog *prog; | |
| 10367 | 10368 | u8 count = 0; | |
| 10368 | 10369 | int i; | |
| 10369 | 10370 | ||
| 10370 | - | for (i = 0; i < __MAX_XDP_MODE; i++) | |
| 10371 | - | if (dev->xdp_state[i].prog && | |
| 10372 | - | !dev->xdp_state[i].prog->aux->xdp_has_frags) | |
| 10371 | + | for (i = 0; i < __MAX_XDP_MODE; i++) { | |
| 10372 | + | prog = dev_xdp_prog(dev, i); | |
| 10373 | + | if (prog && !prog->aux->xdp_has_frags) | |
| 10373 | 10374 | count++; | |
| 10375 | + | } | |
| 10374 | 10376 | return count; | |
| 10375 | 10377 | } | |
| 10376 | 10378 | ||
| @@ -10750,11 +10752,12 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog, | |||
| 10750 | 10752 | bpf_op = dev_xdp_bpf_op(xdp_link->dev, mode); | |
| 10751 | 10753 | err = dev_xdp_install(xdp_link->dev, mode, bpf_op, NULL, | |
| 10752 | 10754 | xdp_link->flags, new_prog); | |
| 10755 | + | if (!err) | |
| 10756 | + | old_prog = xchg(&link->prog, new_prog); | |
| 10753 | 10757 | netdev_unlock_ops(xdp_link->dev); | |
| 10754 | 10758 | if (err) | |
| 10755 | 10759 | goto out_unlock; | |
| 10756 | 10760 | ||
| 10757 | - | old_prog = xchg(&link->prog, new_prog); | |
| 10758 | 10761 | bpf_prog_put(old_prog); | |
| 10759 | 10762 | ||
| 10760 | 10763 | out_unlock: | |
modified net/core/flow_dissector.c
| @@ -1023,6 +1023,8 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, | |||
| 1023 | 1023 | ||
| 1024 | 1024 | result = bpf_prog_run_pin_on_cpu(prog, ctx); | |
| 1025 | 1025 | ||
| 1026 | + | /* bpf_flow_keys offsets are u16: do not let @hlen be truncated. */ | |
| 1027 | + | hlen = min_t(int, hlen, U16_MAX); | |
| 1026 | 1028 | flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen); | |
| 1027 | 1029 | flow_keys->thoff = clamp_t(u16, flow_keys->thoff, | |
| 1028 | 1030 | flow_keys->nhoff, hlen); | |
| @@ -1071,6 +1073,7 @@ bool __skb_flow_dissect(const struct net *net, | |||
| 1071 | 1073 | int mpls_lse = 0; | |
| 1072 | 1074 | int num_hdrs = 0; | |
| 1073 | 1075 | u8 ip_proto = 0; | |
| 1076 | + | u32 thoff; | |
| 1074 | 1077 | bool ret; | |
| 1075 | 1078 | ||
| 1076 | 1079 | if (!data) { | |
| @@ -1692,7 +1695,13 @@ out_good: | |||
| 1692 | 1695 | ret = true; | |
| 1693 | 1696 | ||
| 1694 | 1697 | out: | |
| 1695 | - | key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen); | |
| 1698 | + | thoff = min_t(u32, nhoff, skb ? skb->len : hlen); | |
| 1699 | + | if (unlikely(thoff > U16_MAX)) { | |
| 1700 | + | /* Cannot be represented in key_control->thoff. */ | |
| 1701 | + | thoff = U16_MAX; | |
| 1702 | + | ret = false; | |
| 1703 | + | } | |
| 1704 | + | key_control->thoff = thoff; | |
| 1696 | 1705 | key_basic->n_proto = proto; | |
| 1697 | 1706 | key_basic->ip_proto = ip_proto; | |
| 1698 | 1707 | ||
modified net/core/skbuff.c
| @@ -3633,8 +3633,12 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, | |||
| 3633 | 3633 | pos = copy; | |
| 3634 | 3634 | } | |
| 3635 | 3635 | ||
| 3636 | - | if (!skb_frags_readable(skb)) | |
| 3636 | + | if (!skb_frags_readable(skb)) { | |
| 3637 | + | /* Don't hand the caller a buffer with stale bytes in it. */ | |
| 3638 | + | if (len > 0) | |
| 3639 | + | memset(to, 0, len); | |
| 3637 | 3640 | return 0; | |
| 3641 | + | } | |
| 3638 | 3642 | ||
| 3639 | 3643 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
| 3640 | 3644 | int end; | |
modified net/devlink/core.c
| @@ -112,13 +112,19 @@ rel_put: | |||
| 112 | 112 | return; | |
| 113 | 113 | ||
| 114 | 114 | reschedule_work: | |
| 115 | - | schedule_delayed_work(&rel->nested_in.notify_work, 1); | |
| 115 | + | /* The work may have been queued again meanwhile, which took its own | |
| 116 | + | * reference. Drop ours in that case. | |
| 117 | + | */ | |
| 118 | + | if (!schedule_delayed_work(&rel->nested_in.notify_work, 1)) | |
| 119 | + | __devlink_rel_put(rel); | |
| 116 | 120 | } | |
| 117 | 121 | ||
| 118 | 122 | static void devlink_rel_nested_in_notify_work_schedule(struct devlink_rel *rel) | |
| 119 | 123 | { | |
| 120 | 124 | __devlink_rel_get(rel); | |
| 121 | - | schedule_delayed_work(&rel->nested_in.notify_work, 0); | |
| 125 | + | /* The pending work holds a reference already, drop the new one. */ | |
| 126 | + | if (!schedule_delayed_work(&rel->nested_in.notify_work, 0)) | |
| 127 | + | __devlink_rel_put(rel); | |
| 122 | 128 | } | |
| 123 | 129 | ||
| 124 | 130 | static struct devlink_rel *devlink_rel_alloc(void) | |
modified net/ipv4/af_inet.c
| @@ -161,7 +161,7 @@ void inet_sock_destruct(struct sock *sk) | |||
| 161 | 161 | WARN_ON_ONCE(sk->sk_wmem_queued); | |
| 162 | 162 | WARN_ON_ONCE(sk->sk_forward_alloc); | |
| 163 | 163 | ||
| 164 | - | kfree(rcu_dereference_protected(inet->inet_opt, 1)); | |
| 164 | + | kfree_rcu(rcu_dereference_protected(inet->inet_opt, 1), rcu); | |
| 165 | 165 | dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1)); | |
| 166 | 166 | dst_release(rcu_dereference_protected(sk->sk_rx_dst, 1)); | |
| 167 | 167 | psp_sk_assoc_free(sk); | |
modified net/ipv4/cipso_ipv4.c
| @@ -2287,6 +2287,14 @@ int cipso_v4_skbuff_delattr(struct sk_buff *skb) | |||
| 2287 | 2287 | new_hdr_len - new_hdr_len_actual); | |
| 2288 | 2288 | ||
| 2289 | 2289 | opt->optlen -= hdr_len_delta; | |
| 2290 | + | if (opt->srr > opt->cipso) | |
| 2291 | + | opt->srr -= cipso_len; | |
| 2292 | + | if (opt->rr > opt->cipso) | |
| 2293 | + | opt->rr -= cipso_len; | |
| 2294 | + | if (opt->ts > opt->cipso) | |
| 2295 | + | opt->ts -= cipso_len; | |
| 2296 | + | if (opt->router_alert > opt->cipso) | |
| 2297 | + | opt->router_alert -= cipso_len; | |
| 2290 | 2298 | opt->cipso = 0; | |
| 2291 | 2299 | opt->is_changed = 1; | |
| 2292 | 2300 | if (hdr_len_delta != 0) { | |
modified net/ipv4/fib_semantics.c
| @@ -542,6 +542,9 @@ size_t fib_nlmsg_size(struct fib_info *fi) | |||
| 542 | 542 | struct fib_nh_common *nhc = fib_info_nhc(fi, i); | |
| 543 | 543 | size_t nhsize; | |
| 544 | 544 | ||
| 545 | + | if (!nhc) | |
| 546 | + | break; | |
| 547 | + | ||
| 545 | 548 | nhsize = fib_nexthop_nlmsg_size(nhc, nhs != 1); | |
| 546 | 549 | ||
| 547 | 550 | if (nhs != 1) | |
modified net/ipv4/fib_trie.c
| @@ -1079,8 +1079,6 @@ void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri) | |||
| 1079 | 1079 | ||
| 1080 | 1080 | err = fib_dump_info(skb, 0, 0, RTM_NEWROUTE, fri, 0); | |
| 1081 | 1081 | if (err < 0) { | |
| 1082 | - | /* -EMSGSIZE implies BUG in fib_nlmsg_size() */ | |
| 1083 | - | WARN_ON(err == -EMSGSIZE); | |
| 1084 | 1082 | kfree_skb(skb); | |
| 1085 | 1083 | goto errout; | |
| 1086 | 1084 | } | |
modified net/ipv4/ip_output.c
| @@ -771,9 +771,13 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, | |||
| 771 | 771 | int err = 0; | |
| 772 | 772 | ||
| 773 | 773 | /* for offloaded checksums cleanup checksum before fragmentation */ | |
| 774 | - | if (skb->ip_summed == CHECKSUM_PARTIAL && | |
| 775 | - | (err = skb_checksum_help(skb))) | |
| 776 | - | goto fail; | |
| 774 | + | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
| 775 | + | err = ip_check_csum_start(skb); | |
| 776 | + | if (!err) | |
| 777 | + | err = skb_checksum_help(skb); | |
| 778 | + | if (err) | |
| 779 | + | goto fail; | |
| 780 | + | } | |
| 777 | 781 | ||
| 778 | 782 | /* | |
| 779 | 783 | * Point into the IP datagram header. | |
modified net/ipv4/route.c
| @@ -1082,6 +1082,8 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) | |||
| 1082 | 1082 | ||
| 1083 | 1083 | for (nhsel = 0; nhsel < fib_info_num_path(res.fi); nhsel++) { | |
| 1084 | 1084 | nhc = fib_info_nhc(res.fi, nhsel); | |
| 1085 | + | if (!nhc) | |
| 1086 | + | break; | |
| 1085 | 1087 | update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock, | |
| 1086 | 1088 | jiffies + net->ipv4.ip_rt_mtu_expires); | |
| 1087 | 1089 | } | |
| @@ -3168,6 +3170,9 @@ int fib_dump_info_fnhe(struct sk_buff *skb, struct netlink_callback *cb, | |||
| 3168 | 3170 | struct fnhe_hash_bucket *bucket; | |
| 3169 | 3171 | int err; | |
| 3170 | 3172 | ||
| 3173 | + | if (!nhc) | |
| 3174 | + | break; | |
| 3175 | + | ||
| 3171 | 3176 | if (nhc->nhc_flags & RTNH_F_DEAD) | |
| 3172 | 3177 | continue; | |
| 3173 | 3178 | ||
modified net/ipv4/tcp.c
| @@ -1908,6 +1908,8 @@ static bool can_map_frag(const skb_frag_t *frag) | |||
| 1908 | 1908 | ||
| 1909 | 1909 | if (skb_frag_size(frag) != PAGE_SIZE || skb_frag_off(frag)) | |
| 1910 | 1910 | return false; | |
| 1911 | + | if (skb_frag_is_net_iov(frag)) | |
| 1912 | + | return false; | |
| 1911 | 1913 | ||
| 1912 | 1914 | page = skb_frag_page(frag); | |
| 1913 | 1915 | ||
modified net/ipv4/tcp_ipv4.c
| @@ -1209,7 +1209,7 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst, | |||
| 1209 | 1209 | */ | |
| 1210 | 1210 | static void tcp_v4_reqsk_destructor(struct request_sock *req) | |
| 1211 | 1211 | { | |
| 1212 | - | kfree(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1)); | |
| 1212 | + | kfree_rcu(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1), rcu); | |
| 1213 | 1213 | } | |
| 1214 | 1214 | ||
| 1215 | 1215 | #ifdef CONFIG_TCP_MD5SIG | |
modified net/ipv6/ip6_gre.c
| @@ -923,7 +923,6 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, | |||
| 923 | 923 | { | |
| 924 | 924 | struct ip_tunnel_info *tun_info = NULL; | |
| 925 | 925 | struct ip6_tnl *t = netdev_priv(dev); | |
| 926 | - | struct dst_entry *dst = skb_dst(skb); | |
| 927 | 926 | IP_TUNNEL_DECLARE_FLAGS(flags) = { }; | |
| 928 | 927 | bool truncate = false; | |
| 929 | 928 | int encap_limit = -1; | |
| @@ -1058,12 +1057,6 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, | |||
| 1058 | 1057 | gre_build_header(skb, 8, flags, proto, 0, | |
| 1059 | 1058 | htonl(atomic_fetch_inc(&t->o_seqno))); | |
| 1060 | 1059 | ||
| 1061 | - | /* TooBig packet may have updated dst->dev's mtu */ | |
| 1062 | - | if (!t->parms.collect_md && dst) { | |
| 1063 | - | mtu = READ_ONCE(dst_dev(dst)->mtu); | |
| 1064 | - | if (dst_mtu(dst) > mtu) | |
| 1065 | - | dst->ops->update_pmtu(dst, NULL, skb, mtu, false); | |
| 1066 | - | } | |
| 1067 | 1060 | err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, | |
| 1068 | 1061 | NEXTHDR_GRE); | |
| 1069 | 1062 | if (err != 0) { | |
modified net/ipv6/route.c
| @@ -6509,8 +6509,6 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i, | |||
| 6509 | 6509 | err = rt6_fill_node(net, skb, f6i, NULL, NULL, NULL, 0, RTM_NEWROUTE, 0, | |
| 6510 | 6510 | 0, 0, RT_DEL_REASON_UNSPEC); | |
| 6511 | 6511 | if (err < 0) { | |
| 6512 | - | /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ | |
| 6513 | - | WARN_ON(err == -EMSGSIZE); | |
| 6514 | 6512 | kfree_skb(skb); | |
| 6515 | 6513 | goto errout; | |
| 6516 | 6514 | } | |
modified net/mac80211/airtime.c
| @@ -632,6 +632,22 @@ static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw, | |||
| 632 | 632 | if (!ri || !sband) | |
| 633 | 633 | return false; | |
| 634 | 634 | ||
| 635 | + | /* | |
| 636 | + | * ieee80211_get_rate_duration() only handles these widths. Drivers | |
| 637 | + | * may also report e.g. HE/EHT RU allocations, which cannot be used | |
| 638 | + | * to estimate airtime here. | |
| 639 | + | */ | |
| 640 | + | switch (ri->bw) { | |
| 641 | + | case RATE_INFO_BW_20: | |
| 642 | + | case RATE_INFO_BW_40: | |
| 643 | + | case RATE_INFO_BW_80: | |
| 644 | + | case RATE_INFO_BW_160: | |
| 645 | + | case RATE_INFO_BW_320: | |
| 646 | + | break; | |
| 647 | + | default: | |
| 648 | + | return false; | |
| 649 | + | } | |
| 650 | + | ||
| 635 | 651 | stat->bw = ri->bw; | |
| 636 | 652 | stat->nss = ri->nss; | |
| 637 | 653 | stat->rate_idx = ri->mcs; | |
| @@ -770,6 +786,8 @@ u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw, | |||
| 770 | 786 | return ieee80211_calc_rx_airtime(hw, &stat, len) * 1024; | |
| 771 | 787 | ||
| 772 | 788 | duration = ieee80211_get_rate_duration(hw, &stat, &overhead); | |
| 789 | + | if (!duration) | |
| 790 | + | return 0; | |
| 773 | 791 | ||
| 774 | 792 | /* | |
| 775 | 793 | * Assume that HT/VHT transmission on any AC except VO will | |
modified net/netfilter/nfnetlink_queue.c
| @@ -40,6 +40,7 @@ | |||
| 40 | 40 | #include <linux/udp.h> | |
| 41 | 41 | #include <net/gre.h> | |
| 42 | 42 | #include <net/gso.h> | |
| 43 | + | #include <net/ip.h> | |
| 43 | 44 | #include <net/sock.h> | |
| 44 | 45 | #include <net/tcp_states.h> | |
| 45 | 46 | #include <net/netfilter/nf_queue.h> | |
| @@ -674,6 +675,12 @@ nla_put_failure: | |||
| 674 | 675 | ||
| 675 | 676 | static int nf_queue_checksum_help(struct sk_buff *entskb) | |
| 676 | 677 | { | |
| 678 | + | if (entskb->protocol == htons(ETH_P_IP)) { | |
| 679 | + | if (!pskb_network_may_pull(entskb, sizeof(struct iphdr)) || | |
| 680 | + | ip_check_csum_start(entskb)) | |
| 681 | + | return -EINVAL; | |
| 682 | + | } | |
| 683 | + | ||
| 677 | 684 | if (skb_csum_is_sctp(entskb)) | |
| 678 | 685 | return skb_crc32c_csum_help(entskb); | |
| 679 | 686 | ||
modified net/netfilter/xt_CHECKSUM.c
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | #include <linux/netfilter_ipv4/ip_tables.h> | |
| 17 | 17 | #include <linux/netfilter_ipv6/ip6_tables.h> | |
| 18 | + | #include <net/ip.h> | |
| 18 | 19 | ||
| 19 | 20 | MODULE_LICENSE("GPL"); | |
| 20 | 21 | MODULE_AUTHOR("Michael S. Tsirkin <mst@redhat.com>"); | |
| @@ -25,8 +26,11 @@ MODULE_ALIAS("ip6t_CHECKSUM"); | |||
| 25 | 26 | static unsigned int | |
| 26 | 27 | checksum_tg(struct sk_buff *skb, const struct xt_action_param *par) | |
| 27 | 28 | { | |
| 28 | - | if (skb->ip_summed == CHECKSUM_PARTIAL && !skb_is_gso(skb)) | |
| 29 | + | if (skb->ip_summed == CHECKSUM_PARTIAL && !skb_is_gso(skb)) { | |
| 30 | + | if (xt_family(par) == NFPROTO_IPV4 && ip_check_csum_start(skb)) | |
| 31 | + | return NF_DROP; | |
| 29 | 32 | skb_checksum_help(skb); | |
| 33 | + | } | |
| 30 | 34 | ||
| 31 | 35 | return XT_CONTINUE; | |
| 32 | 36 | } | |
modified net/openvswitch/actions.c
| @@ -358,7 +358,12 @@ static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh, | |||
| 358 | 358 | static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto, | |
| 359 | 359 | __be32 addr[4], const __be32 new_addr[4]) | |
| 360 | 360 | { | |
| 361 | - | int transport_len = skb->len - skb_transport_offset(skb); | |
| 361 | + | int transport_len; | |
| 362 | + | ||
| 363 | + | if (l4_proto == NEXTHDR_FRAGMENT) | |
| 364 | + | return; | |
| 365 | + | ||
| 366 | + | transport_len = skb->len - skb_transport_offset(skb); | |
| 362 | 367 | ||
| 363 | 368 | if (l4_proto == NEXTHDR_TCP) { | |
| 364 | 369 | if (likely(transport_len >= sizeof(struct tcphdr))) | |
modified net/openvswitch/datapath.c
| @@ -1532,6 +1532,12 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1532 | 1532 | return -ENODEV; | |
| 1533 | 1533 | } | |
| 1534 | 1534 | ||
| 1535 | + | /* | |
| 1536 | + | * Not needed for safety. Stops every spin_unlock_bh() in | |
| 1537 | + | * ovs_flow_stats_get() from running the softirq backlog. | |
| 1538 | + | */ | |
| 1539 | + | local_bh_disable(); | |
| 1540 | + | ||
| 1535 | 1541 | ti = rcu_dereference(dp->table.ti); | |
| 1536 | 1542 | for (;;) { | |
| 1537 | 1543 | struct sw_flow *flow; | |
| @@ -1552,6 +1558,8 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1552 | 1558 | cb->args[0] = bucket; | |
| 1553 | 1559 | cb->args[1] = obj; | |
| 1554 | 1560 | } | |
| 1561 | + | ||
| 1562 | + | local_bh_enable(); | |
| 1555 | 1563 | rcu_read_unlock(); | |
| 1556 | 1564 | return skb->len; | |
| 1557 | 1565 | } | |
modified net/packet/af_packet.c
| @@ -1911,7 +1911,8 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, | |||
| 1911 | 1911 | ||
| 1912 | 1912 | spkt = &PACKET_SKB_CB(skb)->sa.pkt; | |
| 1913 | 1913 | ||
| 1914 | - | skb_push(skb, skb->data - skb_mac_header(skb)); | |
| 1914 | + | if (dev_has_header(dev)) | |
| 1915 | + | skb_push(skb, skb->data - skb_mac_header(skb)); | |
| 1915 | 1916 | ||
| 1916 | 1917 | /* | |
| 1917 | 1918 | * The SOCK_PACKET socket receives _all_ frames. | |
| @@ -1942,8 +1943,7 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock) | |||
| 1942 | 1943 | /* On TX skb->data is the L2 header; anchor it for all socket types. */ | |
| 1943 | 1944 | skb_reset_mac_header(skb); | |
| 1944 | 1945 | ||
| 1945 | - | if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) && | |
| 1946 | - | sock->type == SOCK_RAW) | |
| 1946 | + | if (!skb->protocol && sock->type == SOCK_RAW) | |
| 1947 | 1947 | skb->protocol = dev_parse_header_protocol(skb); | |
| 1948 | 1948 | ||
| 1949 | 1949 | skb_probe_transport_header(skb); | |
| @@ -2613,7 +2613,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, | |||
| 2613 | 2613 | struct page *page; | |
| 2614 | 2614 | int err; | |
| 2615 | 2615 | ||
| 2616 | - | skb->protocol = proto; | |
| 2616 | + | if (proto != htons(ETH_P_ALL)) | |
| 2617 | + | skb->protocol = proto; | |
| 2617 | 2618 | skb->dev = dev; | |
| 2618 | 2619 | skb->priority = sockc->priority; | |
| 2619 | 2620 | skb->mark = sockc->mark; | |
| @@ -2677,8 +2678,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, | |||
| 2677 | 2678 | if (unlikely(!skb->len)) | |
| 2678 | 2679 | return -EINVAL; | |
| 2679 | 2680 | ||
| 2680 | - | packet_parse_headers(skb, sock); | |
| 2681 | - | ||
| 2682 | 2681 | return tp_len; | |
| 2683 | 2682 | } | |
| 2684 | 2683 | ||
| @@ -2918,9 +2917,13 @@ tpacket_error: | |||
| 2918 | 2917 | tp_len = -EINVAL; | |
| 2919 | 2918 | goto tpacket_error; | |
| 2920 | 2919 | } | |
| 2921 | - | virtio_net_hdr_set_proto(skb, &vnet_hdr); | |
| 2922 | 2920 | } | |
| 2923 | 2921 | ||
| 2922 | + | packet_parse_headers(skb, po->sk.sk_socket); | |
| 2923 | + | ||
| 2924 | + | if (has_vnet_hdr) | |
| 2925 | + | virtio_net_hdr_set_proto(skb, &vnet_hdr); | |
| 2926 | + | ||
| 2924 | 2927 | uarg = kmalloc(sizeof(*uarg), GFP_KERNEL); | |
| 2925 | 2928 | if (unlikely(!uarg)) { | |
| 2926 | 2929 | if (likely(len_sum > 0)) | |
| @@ -3121,7 +3124,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) | |||
| 3121 | 3124 | goto out_free; | |
| 3122 | 3125 | } | |
| 3123 | 3126 | ||
| 3124 | - | skb->protocol = proto; | |
| 3127 | + | if (proto != htons(ETH_P_ALL)) | |
| 3128 | + | skb->protocol = proto; | |
| 3125 | 3129 | skb->dev = dev; | |
| 3126 | 3130 | skb->priority = sockc.priority; | |
| 3127 | 3131 | skb->mark = sockc.mark; | |
| @@ -3130,16 +3134,18 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) | |||
| 3130 | 3134 | if (unlikely(extra_len == 4)) | |
| 3131 | 3135 | skb->no_fcs = 1; | |
| 3132 | 3136 | ||
| 3133 | - | packet_parse_headers(skb, sock); | |
| 3134 | - | ||
| 3135 | 3137 | if (vnet_hdr_sz) { | |
| 3136 | 3138 | err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le()); | |
| 3137 | 3139 | if (err) | |
| 3138 | 3140 | goto out_free; | |
| 3139 | 3141 | len += vnet_hdr_sz; | |
| 3140 | - | virtio_net_hdr_set_proto(skb, &vnet_hdr); | |
| 3141 | 3142 | } | |
| 3142 | 3143 | ||
| 3144 | + | packet_parse_headers(skb, sock); | |
| 3145 | + | ||
| 3146 | + | if (vnet_hdr_sz) | |
| 3147 | + | virtio_net_hdr_set_proto(skb, &vnet_hdr); | |
| 3148 | + | ||
| 3143 | 3149 | err = packet_xmit(po, skb); | |
| 3144 | 3150 | ||
| 3145 | 3151 | if (unlikely(err != 0)) { | |
modified net/sched/cls_route.c
| @@ -434,6 +434,12 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, | |||
| 434 | 434 | if (handle && (!fold || nhandle == (handle & ~0x7F00))) | |
| 435 | 435 | nhandle |= handle & 0x7F00; | |
| 436 | 436 | ||
| 437 | + | if (fold && !tb[TCA_ROUTE4_TO] && !tb[TCA_ROUTE4_FROM] && | |
| 438 | + | !tb[TCA_ROUTE4_IIF] && nhandle != fold->handle) { | |
| 439 | + | NL_SET_ERR_MSG(extack, "Routing attributes required"); | |
| 440 | + | return -EINVAL; | |
| 441 | + | } | |
| 442 | + | ||
| 437 | 443 | if (handle && !fold && nhandle != handle) { | |
| 438 | 444 | NL_SET_ERR_MSG_FMT(extack, | |
| 439 | 445 | "Handle mismatch constructed: %x (expected: %x)", | |
modified net/sched/em_text.c
| @@ -58,6 +58,9 @@ static int em_text_change(struct net *net, void *data, int len, | |||
| 58 | 58 | if (len < sizeof(*conf) || len < (sizeof(*conf) + conf->pattern_len)) | |
| 59 | 59 | return -EINVAL; | |
| 60 | 60 | ||
| 61 | + | if (!memchr(conf->algo, '\0', sizeof(conf->algo))) | |
| 62 | + | return -EINVAL; | |
| 63 | + | ||
| 61 | 64 | if (conf->from_layer > conf->to_layer) | |
| 62 | 65 | return -EINVAL; | |
| 63 | 66 | ||
modified net/sctp/socket.c
| @@ -7569,11 +7569,7 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len, | |||
| 7569 | 7569 | /* Not allocated yet, means all stats are 0 */ | |
| 7570 | 7570 | params.sprstat_abandoned_unsent = 0; | |
| 7571 | 7571 | params.sprstat_abandoned_sent = 0; | |
| 7572 | - | retval = 0; | |
| 7573 | - | goto out; | |
| 7574 | - | } | |
| 7575 | - | ||
| 7576 | - | if (policy == SCTP_PR_SCTP_ALL) { | |
| 7572 | + | } else if (policy == SCTP_PR_SCTP_ALL) { | |
| 7577 | 7573 | params.sprstat_abandoned_unsent = 0; | |
| 7578 | 7574 | params.sprstat_abandoned_sent = 0; | |
| 7579 | 7575 | for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) { | |
modified net/smc/af_smc.c
| @@ -2784,6 +2784,7 @@ int smc_getname(struct socket *sock, struct sockaddr *addr, | |||
| 2784 | 2784 | int peer) | |
| 2785 | 2785 | { | |
| 2786 | 2786 | struct smc_sock *smc; | |
| 2787 | + | int rc = -EBADF; | |
| 2787 | 2788 | ||
| 2788 | 2789 | if (peer && (sock->sk->sk_state != SMC_ACTIVE) && | |
| 2789 | 2790 | (sock->sk->sk_state != SMC_APPCLOSEWAIT1)) | |
| @@ -2791,7 +2792,11 @@ int smc_getname(struct socket *sock, struct sockaddr *addr, | |||
| 2791 | 2792 | ||
| 2792 | 2793 | smc = smc_sk(sock->sk); | |
| 2793 | 2794 | ||
| 2794 | - | return smc->clcsock->ops->getname(smc->clcsock, addr, peer); | |
| 2795 | + | mutex_lock(&smc->clcsock_release_lock); | |
| 2796 | + | if (smc->clcsock) | |
| 2797 | + | rc = smc->clcsock->ops->getname(smc->clcsock, addr, peer); | |
| 2798 | + | mutex_unlock(&smc->clcsock_release_lock); | |
| 2799 | + | return rc; | |
| 2795 | 2800 | } | |
| 2796 | 2801 | ||
| 2797 | 2802 | int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) | |
modified net/strparser/strparser.c
| @@ -505,12 +505,16 @@ void strp_unpause(struct strparser *strp) | |||
| 505 | 505 | EXPORT_SYMBOL_GPL(strp_unpause); | |
| 506 | 506 | ||
| 507 | 507 | /* strp must already be stopped so that strp_recv will no longer be called. | |
| 508 | - | * Note that strp_done is not called with the lower socket held. | |
| 508 | + | * Note that strp_done must not be called with the lower socket held. | |
| 509 | 509 | */ | |
| 510 | 510 | void strp_done(struct strparser *strp) | |
| 511 | 511 | { | |
| 512 | 512 | WARN_ON(!strp->stopped); | |
| 513 | 513 | ||
| 514 | + | lock_sock(strp->sk); | |
| 515 | + | /* sync with pending strp_recv */ | |
| 516 | + | release_sock(strp->sk); | |
| 517 | + | ||
| 514 | 518 | cancel_delayed_work_sync(&strp->msg_timer_work); | |
| 515 | 519 | cancel_work_sync(&strp->work); | |
| 516 | 520 | ||
modified net/tipc/node.c
| @@ -2421,8 +2421,11 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net, | |||
| 2421 | 2421 | } | |
| 2422 | 2422 | } | |
| 2423 | 2423 | tipc_node_read_unlock(n); | |
| 2424 | - | if (found_node) | |
| 2424 | + | if (found_node) { | |
| 2425 | + | if (!kref_get_unless_zero(&found_node->kref)) | |
| 2426 | + | found_node = NULL; | |
| 2425 | 2427 | break; | |
| 2428 | + | } | |
| 2426 | 2429 | } | |
| 2427 | 2430 | rcu_read_unlock(); | |
| 2428 | 2431 | ||
| @@ -2507,6 +2510,7 @@ out: | |||
| 2507 | 2510 | tipc_node_read_unlock(node); | |
| 2508 | 2511 | tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr, | |
| 2509 | 2512 | NULL); | |
| 2513 | + | tipc_node_put(node); | |
| 2510 | 2514 | return res; | |
| 2511 | 2515 | } | |
| 2512 | 2516 | ||
| @@ -2558,12 +2562,14 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) | |||
| 2558 | 2562 | link = node->links[bearer_id].link; | |
| 2559 | 2563 | if (!link) { | |
| 2560 | 2564 | tipc_node_read_unlock(node); | |
| 2565 | + | tipc_node_put(node); | |
| 2561 | 2566 | err = -EINVAL; | |
| 2562 | 2567 | goto err_free; | |
| 2563 | 2568 | } | |
| 2564 | 2569 | ||
| 2565 | 2570 | err = __tipc_nl_add_link(net, &msg, link, 0); | |
| 2566 | 2571 | tipc_node_read_unlock(node); | |
| 2572 | + | tipc_node_put(node); | |
| 2567 | 2573 | if (err) | |
| 2568 | 2574 | goto err_free; | |
| 2569 | 2575 | } | |
| @@ -2634,11 +2640,13 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info) | |||
| 2634 | 2640 | if (!link) { | |
| 2635 | 2641 | spin_unlock_bh(&le->lock); | |
| 2636 | 2642 | tipc_node_read_unlock(node); | |
| 2643 | + | tipc_node_put(node); | |
| 2637 | 2644 | return -EINVAL; | |
| 2638 | 2645 | } | |
| 2639 | 2646 | tipc_link_reset_stats(link); | |
| 2640 | 2647 | spin_unlock_bh(&le->lock); | |
| 2641 | 2648 | tipc_node_read_unlock(node); | |
| 2649 | + | tipc_node_put(node); | |
| 2642 | 2650 | return 0; | |
| 2643 | 2651 | } | |
| 2644 | 2652 | ||
modified net/tipc/topsrv.c
| @@ -55,7 +55,7 @@ | |||
| 55 | 55 | /** | |
| 56 | 56 | * struct tipc_topsrv - TIPC server structure | |
| 57 | 57 | * @conn_idr: identifier set of connection | |
| 58 | - | * @idr_lock: protect the connection identifier set | |
| 58 | + | * @idr_lock: protect the connection identifier set and listener | |
| 59 | 59 | * @idr_in_use: amount of allocated identifier entry | |
| 60 | 60 | * @net: network namespace instance | |
| 61 | 61 | * @awork: accept work item | |
| @@ -218,6 +218,10 @@ static struct tipc_conn *tipc_conn_lookup(struct tipc_topsrv *s, int conid) | |||
| 218 | 218 | struct tipc_conn *con; | |
| 219 | 219 | ||
| 220 | 220 | spin_lock_bh(&s->idr_lock); | |
| 221 | + | if (!s->listener) { | |
| 222 | + | spin_unlock_bh(&s->idr_lock); | |
| 223 | + | return NULL; | |
| 224 | + | } | |
| 221 | 225 | con = idr_find(&s->conn_idr, conid); | |
| 222 | 226 | if (!connected(con) || !kref_get_unless_zero(&con->kref)) | |
| 223 | 227 | con = NULL; | |
| @@ -301,10 +305,20 @@ static void tipc_conn_send_to_sock(struct tipc_conn *con) | |||
| 301 | 305 | static void tipc_conn_send_work(struct work_struct *work) | |
| 302 | 306 | { | |
| 303 | 307 | struct tipc_conn *con = container_of(work, struct tipc_conn, swork); | |
| 308 | + | struct tipc_topsrv *srv; | |
| 309 | + | ||
| 310 | + | srv = con->server; | |
| 311 | + | spin_lock_bh(&srv->idr_lock); | |
| 312 | + | if (!srv->listener) { | |
| 313 | + | spin_unlock_bh(&srv->idr_lock); | |
| 314 | + | goto out; | |
| 315 | + | } | |
| 316 | + | spin_unlock_bh(&srv->idr_lock); | |
| 304 | 317 | ||
| 305 | 318 | if (connected(con)) | |
| 306 | 319 | tipc_conn_send_to_sock(con); | |
| 307 | 320 | ||
| 321 | + | out: | |
| 308 | 322 | conn_put(con); | |
| 309 | 323 | } | |
| 310 | 324 | ||
| @@ -334,8 +348,14 @@ void tipc_topsrv_queue_evt(struct net *net, int conid, | |||
| 334 | 348 | list_add_tail(&e->list, &con->outqueue); | |
| 335 | 349 | spin_unlock_bh(&con->outqueue_lock); | |
| 336 | 350 | ||
| 337 | - | if (queue_work(srv->send_wq, &con->swork)) | |
| 338 | - | return; | |
| 351 | + | spin_lock_bh(&srv->idr_lock); | |
| 352 | + | if (srv->listener) { | |
| 353 | + | if (queue_work(srv->send_wq, &con->swork)) { | |
| 354 | + | spin_unlock_bh(&srv->idr_lock); | |
| 355 | + | return; | |
| 356 | + | } | |
| 357 | + | } | |
| 358 | + | spin_unlock_bh(&srv->idr_lock); | |
| 339 | 359 | err: | |
| 340 | 360 | conn_put(con); | |
| 341 | 361 | } | |
| @@ -346,14 +366,20 @@ err: | |||
| 346 | 366 | */ | |
| 347 | 367 | static void tipc_conn_write_space(struct sock *sk) | |
| 348 | 368 | { | |
| 369 | + | struct tipc_topsrv *srv; | |
| 349 | 370 | struct tipc_conn *con; | |
| 350 | 371 | ||
| 351 | 372 | read_lock_bh(&sk->sk_callback_lock); | |
| 352 | 373 | con = sk->sk_user_data; | |
| 353 | 374 | if (connected(con)) { | |
| 354 | - | conn_get(con); | |
| 355 | - | if (!queue_work(con->server->send_wq, &con->swork)) | |
| 356 | - | conn_put(con); | |
| 375 | + | srv = con->server; | |
| 376 | + | spin_lock_bh(&srv->idr_lock); | |
| 377 | + | if (srv->listener) { | |
| 378 | + | conn_get(con); | |
| 379 | + | if (!queue_work(srv->send_wq, &con->swork)) | |
| 380 | + | conn_put(con); | |
| 381 | + | } | |
| 382 | + | spin_unlock_bh(&srv->idr_lock); | |
| 357 | 383 | } | |
| 358 | 384 | read_unlock_bh(&sk->sk_callback_lock); | |
| 359 | 385 | } | |
| @@ -418,8 +444,17 @@ static int tipc_conn_rcv_from_sock(struct tipc_conn *con) | |||
| 418 | 444 | static void tipc_conn_recv_work(struct work_struct *work) | |
| 419 | 445 | { | |
| 420 | 446 | struct tipc_conn *con = container_of(work, struct tipc_conn, rwork); | |
| 447 | + | struct tipc_topsrv *srv; | |
| 421 | 448 | int count = 0; | |
| 422 | 449 | ||
| 450 | + | srv = con->server; | |
| 451 | + | spin_lock_bh(&srv->idr_lock); | |
| 452 | + | if (!srv->listener) { | |
| 453 | + | spin_unlock_bh(&srv->idr_lock); | |
| 454 | + | goto out; | |
| 455 | + | } | |
| 456 | + | spin_unlock_bh(&srv->idr_lock); | |
| 457 | + | ||
| 423 | 458 | while (connected(con)) { | |
| 424 | 459 | if (tipc_conn_rcv_from_sock(con)) | |
| 425 | 460 | break; | |
| @@ -430,6 +465,7 @@ static void tipc_conn_recv_work(struct work_struct *work) | |||
| 430 | 465 | count = 0; | |
| 431 | 466 | } | |
| 432 | 467 | } | |
| 468 | + | out: | |
| 433 | 469 | conn_put(con); | |
| 434 | 470 | } | |
| 435 | 471 | ||
| @@ -438,6 +474,7 @@ static void tipc_conn_recv_work(struct work_struct *work) | |||
| 438 | 474 | */ | |
| 439 | 475 | static void tipc_conn_data_ready(struct sock *sk) | |
| 440 | 476 | { | |
| 477 | + | struct tipc_topsrv *srv; | |
| 441 | 478 | struct tipc_conn *con; | |
| 442 | 479 | ||
| 443 | 480 | trace_sk_data_ready(sk); | |
| @@ -445,9 +482,14 @@ static void tipc_conn_data_ready(struct sock *sk) | |||
| 445 | 482 | read_lock_bh(&sk->sk_callback_lock); | |
| 446 | 483 | con = sk->sk_user_data; | |
| 447 | 484 | if (connected(con)) { | |
| 448 | - | conn_get(con); | |
| 449 | - | if (!queue_work(con->server->rcv_wq, &con->rwork)) | |
| 450 | - | conn_put(con); | |
| 485 | + | srv = con->server; | |
| 486 | + | spin_lock_bh(&srv->idr_lock); | |
| 487 | + | if (srv->listener) { | |
| 488 | + | conn_get(con); | |
| 489 | + | if (!queue_work(srv->rcv_wq, &con->rwork)) | |
| 490 | + | conn_put(con); | |
| 491 | + | } | |
| 492 | + | spin_unlock_bh(&srv->idr_lock); | |
| 451 | 493 | } | |
| 452 | 494 | read_unlock_bh(&sk->sk_callback_lock); | |
| 453 | 495 | } | |
| @@ -503,8 +545,12 @@ static void tipc_topsrv_listener_data_ready(struct sock *sk) | |||
| 503 | 545 | ||
| 504 | 546 | read_lock_bh(&sk->sk_callback_lock); | |
| 505 | 547 | srv = sk->sk_user_data; | |
| 506 | - | if (srv) | |
| 507 | - | queue_work(srv->rcv_wq, &srv->awork); | |
| 548 | + | if (srv) { | |
| 549 | + | spin_lock_bh(&srv->idr_lock); | |
| 550 | + | if (srv->listener) | |
| 551 | + | queue_work(srv->rcv_wq, &srv->awork); | |
| 552 | + | spin_unlock_bh(&srv->idr_lock); | |
| 553 | + | } | |
| 508 | 554 | read_unlock_bh(&sk->sk_callback_lock); | |
| 509 | 555 | } | |
| 510 | 556 | ||
| @@ -700,23 +746,27 @@ static void tipc_topsrv_stop(struct net *net) | |||
| 700 | 746 | struct tipc_conn *con; | |
| 701 | 747 | int id; | |
| 702 | 748 | ||
| 749 | + | spin_lock_bh(&srv->idr_lock); | |
| 750 | + | srv->listener = NULL; | |
| 751 | + | spin_unlock_bh(&srv->idr_lock); | |
| 752 | + | tipc_topsrv_work_stop(srv); | |
| 753 | + | ||
| 703 | 754 | spin_lock_bh(&srv->idr_lock); | |
| 704 | 755 | for (id = 0; srv->idr_in_use; id++) { | |
| 705 | 756 | con = idr_find(&srv->conn_idr, id); | |
| 706 | 757 | if (con) { | |
| 707 | - | conn_get(con); | |
| 708 | 758 | spin_unlock_bh(&srv->idr_lock); | |
| 709 | 759 | tipc_conn_close(con); | |
| 710 | - | conn_put(con); | |
| 711 | 760 | spin_lock_bh(&srv->idr_lock); | |
| 761 | + | continue; | |
| 712 | 762 | } | |
| 763 | + | spin_unlock_bh(&srv->idr_lock); | |
| 764 | + | spin_lock_bh(&srv->idr_lock); | |
| 713 | 765 | } | |
| 714 | 766 | __module_get(lsock->ops->owner); | |
| 715 | 767 | __module_get(lsock->sk->sk_prot_creator->owner); | |
| 716 | - | srv->listener = NULL; | |
| 717 | 768 | spin_unlock_bh(&srv->idr_lock); | |
| 718 | 769 | ||
| 719 | - | tipc_topsrv_work_stop(srv); | |
| 720 | 770 | sock_release(lsock); | |
| 721 | 771 | idr_destroy(&srv->conn_idr); | |
| 722 | 772 | kfree(srv); | |
modified net/vmw_vsock/af_vsock.c
| @@ -1048,6 +1048,8 @@ static void vsock_sk_destruct(struct sock *sk) | |||
| 1048 | 1048 | { | |
| 1049 | 1049 | struct vsock_sock *vsk = vsock_sk(sk); | |
| 1050 | 1050 | ||
| 1051 | + | /* Socket buffers may remain in the queue in VMCI datagram mode */ | |
| 1052 | + | __skb_queue_purge(&sk->sk_receive_queue); | |
| 1051 | 1053 | /* Flush MSG_ZEROCOPY leftovers. */ | |
| 1052 | 1054 | __skb_queue_purge(&sk->sk_error_queue); | |
| 1053 | 1055 | ||
modified net/vmw_vsock/virtio_transport_common.c
| @@ -1927,6 +1927,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto | |||
| 1927 | 1927 | struct sock *sk = sk_vsock(vsk); | |
| 1928 | 1928 | struct virtio_vsock_hdr *hdr; | |
| 1929 | 1929 | struct sk_buff *skb; | |
| 1930 | + | u32 bytes_read; | |
| 1930 | 1931 | u32 pkt_len; | |
| 1931 | 1932 | int off = 0; | |
| 1932 | 1933 | int err; | |
| @@ -1946,7 +1947,8 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto | |||
| 1946 | 1947 | vvs->msg_count--; | |
| 1947 | 1948 | ||
| 1948 | 1949 | pkt_len = le32_to_cpu(hdr->len); | |
| 1949 | - | virtio_transport_dec_rx_pkt(vvs, pkt_len, pkt_len); | |
| 1950 | + | bytes_read = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->offset; | |
| 1951 | + | virtio_transport_dec_rx_pkt(vvs, bytes_read, pkt_len); | |
| 1950 | 1952 | spin_unlock_bh(&vvs->rx_lock); | |
| 1951 | 1953 | ||
| 1952 | 1954 | virtio_transport_send_credit_update(vsk); | |
modified net/xfrm/xfrm_output.c
| @@ -823,16 +823,22 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) | |||
| 823 | 823 | } | |
| 824 | 824 | ||
| 825 | 825 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
| 826 | - | err = skb_checksum_help(skb); | |
| 827 | - | if (err) { | |
| 828 | - | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR); | |
| 829 | - | kfree_skb(skb); | |
| 830 | - | return err; | |
| 826 | + | if (skb->protocol == htons(ETH_P_IP)) { | |
| 827 | + | err = ip_check_csum_start(skb); | |
| 828 | + | if (err) | |
| 829 | + | goto error; | |
| 831 | 830 | } | |
| 831 | + | err = skb_checksum_help(skb); | |
| 832 | + | if (err) | |
| 833 | + | goto error; | |
| 832 | 834 | } | |
| 833 | 835 | ||
| 834 | 836 | out: | |
| 835 | 837 | return xfrm_output2(net, sk, skb); | |
| 838 | + | error: | |
| 839 | + | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR); | |
| 840 | + | kfree_skb(skb); | |
| 841 | + | return err; | |
| 836 | 842 | } | |
| 837 | 843 | EXPORT_SYMBOL_GPL(xfrm_output); | |
| 838 | 844 | ||
modified security/keys/key.c
| @@ -840,9 +840,6 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, | |||
| 840 | 840 | ||
| 841 | 841 | key_check(keyring); | |
| 842 | 842 | ||
| 843 | - | if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION)) | |
| 844 | - | restrict_link = keyring->restrict_link; | |
| 845 | - | ||
| 846 | 843 | key_ref = ERR_PTR(-ENOTDIR); | |
| 847 | 844 | if (keyring->type != &key_type_keyring) | |
| 848 | 845 | goto error_put_type; | |
| @@ -880,6 +877,9 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref, | |||
| 880 | 877 | goto error_link_end; | |
| 881 | 878 | } | |
| 882 | 879 | ||
| 880 | + | if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION)) | |
| 881 | + | restrict_link = keyring->restrict_link; | |
| 882 | + | ||
| 883 | 883 | if (restrict_link && restrict_link->check) { | |
| 884 | 884 | ret = restrict_link->check(keyring, index_key.type, | |
| 885 | 885 | &prep.payload, restrict_link->key); | |
modified security/keys/persistent.c
| @@ -33,25 +33,31 @@ static int key_create_persistent_register(struct user_namespace *ns) | |||
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | /* | |
| 36 | - | * Create the persistent keyring for the specified user. | |
| 36 | + | * Get or create the persistent keyring for the specified user. | |
| 37 | 37 | * | |
| 38 | 38 | * Called with the namespace's sem locked for writing. | |
| 39 | + | * | |
| 40 | + | * Returns a boolean indicating whether the keyring already existed, | |
| 41 | + | * or a negative error. On success, *persistent_ref holds a reference | |
| 42 | + | * to the keyring. | |
| 39 | 43 | */ | |
| 40 | - | static key_ref_t key_create_persistent(struct user_namespace *ns, kuid_t uid, | |
| 41 | - | struct keyring_index_key *index_key) | |
| 44 | + | static int key_get_or_create_persistent(struct user_namespace *ns, kuid_t uid, | |
| 45 | + | struct keyring_index_key *index_key, | |
| 46 | + | key_ref_t *persistent_ref) | |
| 42 | 47 | { | |
| 43 | 48 | struct key *persistent; | |
| 44 | - | key_ref_t reg_ref, persistent_ref; | |
| 49 | + | key_ref_t reg_ref; | |
| 45 | 50 | ||
| 46 | 51 | if (!ns->persistent_keyring_register) { | |
| 47 | - | long err = key_create_persistent_register(ns); | |
| 52 | + | int err = key_create_persistent_register(ns); | |
| 53 | + | ||
| 48 | 54 | if (err < 0) | |
| 49 | - | return ERR_PTR(err); | |
| 55 | + | return err; | |
| 50 | 56 | } else { | |
| 51 | 57 | reg_ref = make_key_ref(ns->persistent_keyring_register, true); | |
| 52 | - | persistent_ref = find_key_to_update(reg_ref, index_key); | |
| 53 | - | if (persistent_ref) | |
| 54 | - | return persistent_ref; | |
| 58 | + | *persistent_ref = find_key_to_update(reg_ref, index_key); | |
| 59 | + | if (*persistent_ref) | |
| 60 | + | return 1; | |
| 55 | 61 | } | |
| 56 | 62 | ||
| 57 | 63 | persistent = keyring_alloc(index_key->description, | |
| @@ -61,9 +67,10 @@ static key_ref_t key_create_persistent(struct user_namespace *ns, kuid_t uid, | |||
| 61 | 67 | KEY_ALLOC_NOT_IN_QUOTA, NULL, | |
| 62 | 68 | ns->persistent_keyring_register); | |
| 63 | 69 | if (IS_ERR(persistent)) | |
| 64 | - | return ERR_CAST(persistent); | |
| 70 | + | return PTR_ERR(persistent); | |
| 65 | 71 | ||
| 66 | - | return make_key_ref(persistent, true); | |
| 72 | + | *persistent_ref = make_key_ref(persistent, true); | |
| 73 | + | return 0; | |
| 67 | 74 | } | |
| 68 | 75 | ||
| 69 | 76 | /* | |
| @@ -78,6 +85,7 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid, | |||
| 78 | 85 | key_ref_t reg_ref, persistent_ref; | |
| 79 | 86 | char buf[32]; | |
| 80 | 87 | long ret; | |
| 88 | + | bool created = false; | |
| 81 | 89 | ||
| 82 | 90 | /* Look in the register if it exists */ | |
| 83 | 91 | memset(&index_key, 0, sizeof(index_key)); | |
| @@ -100,23 +108,24 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid, | |||
| 100 | 108 | * also need to create the register. | |
| 101 | 109 | */ | |
| 102 | 110 | down_write(&ns->keyring_sem); | |
| 103 | - | persistent_ref = key_create_persistent(ns, uid, &index_key); | |
| 111 | + | ret = key_get_or_create_persistent(ns, uid, &index_key, | |
| 112 | + | &persistent_ref); | |
| 104 | 113 | up_write(&ns->keyring_sem); | |
| 105 | - | if (!IS_ERR(persistent_ref)) | |
| 106 | - | goto found; | |
| 107 | - | ||
| 108 | - | return PTR_ERR(persistent_ref); | |
| 114 | + | if (ret < 0) | |
| 115 | + | return ret; | |
| 116 | + | created = ret == 0; | |
| 109 | 117 | ||
| 110 | 118 | found: | |
| 119 | + | persistent = key_ref_to_ptr(persistent_ref); | |
| 111 | 120 | ret = key_task_permission(persistent_ref, current_cred(), KEY_NEED_LINK); | |
| 112 | - | if (ret == 0) { | |
| 113 | - | persistent = key_ref_to_ptr(persistent_ref); | |
| 121 | + | if (ret == 0) | |
| 114 | 122 | ret = key_link(key_ref_to_ptr(dest_ref), persistent); | |
| 115 | - | if (ret == 0) { | |
| 116 | - | key_set_timeout(persistent, persistent_keyring_expiry); | |
| 117 | - | ret = persistent->serial; | |
| 118 | - | } | |
| 119 | - | } | |
| 123 | + | ||
| 124 | + | if (ret == 0 || created) | |
| 125 | + | key_set_timeout(persistent, persistent_keyring_expiry); | |
| 126 | + | ||
| 127 | + | if (ret == 0) | |
| 128 | + | ret = persistent->serial; | |
| 120 | 129 | ||
| 121 | 130 | key_ref_put(persistent_ref); | |
| 122 | 131 | return ret; | |
modified security/landlock/domain.h
| @@ -242,9 +242,14 @@ struct landlock_domain { | |||
| 242 | 242 | * to properly handle merged rulesets without | |
| 243 | 243 | * overlapping access rights. These layers are set once | |
| 244 | 244 | * and never changed for the lifetime of the domain. | |
| 245 | + | * | |
| 246 | + | * Not annotated with __counted_by(num_layers): clang | |
| 247 | + | * miscomputes the counter address for a FAM nested in | |
| 248 | + | * an anonymous struct within a union, which trips | |
| 249 | + | * FORTIFY: | |
| 250 | + | * https://github.com/llvm/llvm-project/pull/228309 | |
| 245 | 251 | */ | |
| 246 | - | struct access_masks | |
| 247 | - | handled_masks[] __counted_by(num_layers); | |
| 252 | + | struct access_masks handled_masks[]; | |
| 248 | 253 | }; | |
| 249 | 254 | }; | |
| 250 | 255 | }; | |
modified security/selinux/avc.c
| @@ -578,7 +578,7 @@ static int avc_latest_notif_update(u32 seqno, int is_insert) | |||
| 578 | 578 | } | |
| 579 | 579 | } else { | |
| 580 | 580 | if (seqno > selinux_avc.avc_cache.latest_notif) | |
| 581 | - | selinux_avc.avc_cache.latest_notif = seqno; | |
| 581 | + | WRITE_ONCE(selinux_avc.avc_cache.latest_notif, seqno); | |
| 582 | 582 | } | |
| 583 | 583 | spin_unlock_irqrestore(¬if_lock, flag); | |
| 584 | 584 | ||
| @@ -1206,5 +1206,6 @@ int avc_has_perm(u32 ssid, u32 tsid, u16 tclass, | |||
| 1206 | 1206 | ||
| 1207 | 1207 | u32 avc_policy_seqno(void) | |
| 1208 | 1208 | { | |
| 1209 | - | return selinux_avc.avc_cache.latest_notif; | |
| 1209 | + | /* Writers hold notif_lock; readers only sample the sequence number. */ | |
| 1210 | + | return READ_ONCE(selinux_avc.avc_cache.latest_notif); | |
| 1210 | 1211 | } | |
modified security/selinux/hooks.c
| @@ -690,8 +690,12 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
| 690 | 690 | * will be used for both mounts) | |
| 691 | 691 | */ | |
| 692 | 692 | if ((sbsec->flags & SE_SBINITIALIZED) && (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA) | |
| 693 | - | && !opts) | |
| 693 | + | && !opts) { | |
| 694 | + | if ((kern_flags & SECURITY_LSM_NATIVE_LABELS) && | |
| 695 | + | sbsec->behavior == SECURITY_FS_USE_NATIVE) | |
| 696 | + | *set_kern_flags |= SECURITY_LSM_NATIVE_LABELS; | |
| 694 | 697 | goto out; | |
| 698 | + | } | |
| 695 | 699 | ||
| 696 | 700 | root_isec = backing_inode_security_novalidate(root); | |
| 697 | 701 | ||
| @@ -735,6 +739,9 @@ static int selinux_set_mnt_opts(struct super_block *sb, | |||
| 735 | 739 | /* previously mounted with options, but not on this attempt? */ | |
| 736 | 740 | if ((sbsec->flags & SE_MNTMASK) && !opts) | |
| 737 | 741 | goto out_double_mount; | |
| 742 | + | if ((kern_flags & SECURITY_LSM_NATIVE_LABELS) && | |
| 743 | + | sbsec->behavior == SECURITY_FS_USE_NATIVE) | |
| 744 | + | *set_kern_flags |= SECURITY_LSM_NATIVE_LABELS; | |
| 738 | 745 | rc = 0; | |
| 739 | 746 | goto out; | |
| 740 | 747 | } | |
modified sound/hda/codecs/realtek/alc269.c
| @@ -7646,6 +7646,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = { | |||
| 7646 | 7646 | SND_PCI_QUIRK(0x103c, 0x8be8, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2), | |
| 7647 | 7647 | SND_PCI_QUIRK(0x103c, 0x8be9, "HP Envy x360 2-in-1 Laptop 15-fh0xxx", ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX), | |
| 7648 | 7648 | SND_PCI_QUIRK(0x103c, 0x8bf0, "HP", ALC236_FIXUP_HP_GPIO_LED), | |
| 7649 | + | SND_PCI_QUIRK(0x103c, 0x8bfd, "HP Pavilion 15-eg3xxx", ALC287_FIXUP_HP_GPIO_LED), | |
| 7649 | 7650 | SND_PCI_QUIRK(0x103c, 0x8c15, "HP Spectre x360 2-in-1 Laptop 14-eu0xxx", ALC245_FIXUP_HP_SPECTRE_X360_EU0XXX), | |
| 7650 | 7651 | SND_PCI_QUIRK(0x103c, 0x8c16, "HP Spectre x360 2-in-1 Laptop 16-aa0xxx", ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX), | |
| 7651 | 7652 | SND_PCI_QUIRK(0x103c, 0x8c17, "HP Spectre x360 2-in-1 Laptop 16-aa0xxx", ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX), | |
| @@ -8346,6 +8347,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = { | |||
| 8346 | 8347 | SND_PCI_QUIRK(0x17aa, 0x9e56, "Lenovo ZhaoYang CF4620Z", ALC286_FIXUP_SONY_MIC_NO_PRESENCE), | |
| 8347 | 8348 | SND_PCI_QUIRK(0x1849, 0x0269, "Positivo Master C6400", ALC269VB_FIXUP_ASUS_ZENBOOK), | |
| 8348 | 8349 | SND_PCI_QUIRK(0x1849, 0x1233, "ASRock NUC Box 1100", ALC233_FIXUP_NO_AUDIO_JACK), | |
| 8350 | + | SND_PCI_QUIRK(0x1849, 0x6256, "ASRock NUC Box 358H", ALC233_FIXUP_NO_AUDIO_JACK), | |
| 8349 | 8351 | SND_PCI_QUIRK(0x1849, 0xa233, "Positivo Master C6300", ALC269_FIXUP_HEADSET_MIC), | |
| 8350 | 8352 | SND_PCI_QUIRK(0x1854, 0x0440, "LG CQ6", ALC256_FIXUP_HEADPHONE_AMP_VOL), | |
| 8351 | 8353 | SND_PCI_QUIRK(0x1854, 0x0441, "LG CQ6 AIO", ALC256_FIXUP_HEADPHONE_AMP_VOL), | |
modified sound/hda/codecs/side-codecs/tas2781_hda.c
| @@ -139,9 +139,21 @@ static void tas2781_apply_calib(struct tasdevice_priv *p) | |||
| 139 | 139 | */ | |
| 140 | 140 | crc = crc32(~0, data, 84) ^ ~0; | |
| 141 | 141 | if (crc != tmp_val[21]) { | |
| 142 | - | cali_data->total_sz = 0; | |
| 143 | - | dev_err(p->dev, "%s: V1 CRC error\n", __func__); | |
| 144 | - | return; | |
| 142 | + | /* | |
| 143 | + | * Some Lenovo BIOSes (e.g. Legion Pro 7 16IRX9H, | |
| 144 | + | * SSID 17aa:38cd) store valid V1 calibration data | |
| 145 | + | * but leave TimeStamp and CRC zeroed. | |
| 146 | + | */ | |
| 147 | + | if (!tmp_val[20] && !tmp_val[21] && | |
| 148 | + | tmp_val[0] && tmp_val[1]) { | |
| 149 | + | dev_warn(p->dev, | |
| 150 | + | "%s: V1 data without CRC, accepting\n", | |
| 151 | + | __func__); | |
| 152 | + | } else { | |
| 153 | + | cali_data->total_sz = 0; | |
| 154 | + | dev_err(p->dev, "%s: V1 CRC error\n", __func__); | |
| 155 | + | return; | |
| 156 | + | } | |
| 145 | 157 | } | |
| 146 | 158 | ||
| 147 | 159 | for (j = p->ndev - 1; j >= 0; j--) { | |
modified sound/pci/ctxfi/ctdaio.c
| @@ -221,14 +221,18 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input) | |||
| 221 | 221 | ||
| 222 | 222 | static int dao_clear_input(struct dao *dao, unsigned int start, unsigned int end) | |
| 223 | 223 | { | |
| 224 | + | struct imapper *entry; | |
| 224 | 225 | unsigned int i; | |
| 225 | 226 | ||
| 226 | - | if (!dao->imappers[start]) | |
| 227 | + | entry = dao->imappers[start]; | |
| 228 | + | if (!entry) | |
| 227 | 229 | return 0; | |
| 230 | + | ||
| 228 | 231 | for (i = start; i < end; i++) { | |
| 229 | 232 | dao->mgr->imap_delete(dao->mgr, dao->imappers[i]); | |
| 230 | 233 | dao->imappers[i] = NULL; | |
| 231 | 234 | } | |
| 235 | + | kfree(entry); | |
| 232 | 236 | ||
| 233 | 237 | return 0; | |
| 234 | 238 | } | |
modified sound/soc/sof/ipc4-topology.c
| @@ -2458,14 +2458,11 @@ _sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget, | |||
| 2458 | 2458 | ch_map >>= 4; | |
| 2459 | 2459 | } | |
| 2460 | 2460 | ||
| 2461 | - | if ((swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) || | |
| 2462 | - | ch_count < blob->alh_cfg.device_count) { | |
| 2461 | + | if (swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) { | |
| 2463 | 2462 | /* | |
| 2464 | 2463 | * For playback DAI widgets where the channel number is equal to | |
| 2465 | - | * the output reference channels, or when there are fewer | |
| 2466 | - | * channels than aggregated devices (e.g. a mono capture | |
| 2467 | - | * stream split across multiple links), set step = 0 to | |
| 2468 | - | * ensure all the ch_mask is applied to all alh mappings. | |
| 2464 | + | * the output reference channels, set the step = 0 to ensure all | |
| 2465 | + | * the ch_mask is applied to all alh mappings. | |
| 2469 | 2466 | */ | |
| 2470 | 2467 | mask = ch_mask; | |
| 2471 | 2468 | step = 0; | |
modified sound/soc/sof/sof-client.c
| @@ -576,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev, | |||
| 576 | 576 | struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev); | |
| 577 | 577 | struct sof_ipc_event_entry *event; | |
| 578 | 578 | ||
| 579 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 579 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 580 | 580 | ||
| 581 | 581 | list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) { | |
| 582 | 582 | if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) { | |
| @@ -593,7 +593,7 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev) | |||
| 593 | 593 | { | |
| 594 | 594 | struct sof_state_event_entry *event; | |
| 595 | 595 | ||
| 596 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 596 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 597 | 597 | ||
| 598 | 598 | list_for_each_entry(event, &sdev->fw_state_handler_list, list) | |
| 599 | 599 | event->callback(event->cdev, sdev->fw_state); | |
| @@ -628,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev) | |||
| 628 | 628 | struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev); | |
| 629 | 629 | struct sof_state_event_entry *event; | |
| 630 | 630 | ||
| 631 | - | guard(mutex)(&sdev->client_event_handler_mutex); | |
| 631 | + | guard(mutex)(&sdev->ipc_client_mutex); | |
| 632 | 632 | ||
| 633 | 633 | list_for_each_entry(event, &sdev->fw_state_handler_list, list) { | |
| 634 | 634 | if (event->cdev == cdev) { | |
modified sound/usb/quirks.c
| @@ -2510,6 +2510,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { | |||
| 2510 | 2510 | QUIRK_FLAG_DSD_RAW), | |
| 2511 | 2511 | DEVICE_FLG(0x21b4, 0x0232, /* Ayre QX-5 Twenty */ | |
| 2512 | 2512 | QUIRK_FLAG_DSD_RAW), | |
| 2513 | + | DEVICE_FLG(0x22e8, 0xca10, /* Cambridge Audio streamers */ | |
| 2514 | + | QUIRK_FLAG_DSD_RAW), | |
| 2513 | 2515 | DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */ | |
| 2514 | 2516 | QUIRK_FLAG_SET_IFACE_FIRST), | |
| 2515 | 2517 | DEVICE_FLG(0x25aa, 0x600b, /* TAE1159 */ | |
modified tools/testing/selftests/Makefile
| @@ -43,6 +43,7 @@ TARGETS += filesystems/open_tree_ns | |||
| 43 | 43 | TARGETS += filesystems/overlayfs | |
| 44 | 44 | TARGETS += filesystems/statmount | |
| 45 | 45 | TARGETS += filesystems/mount-notify | |
| 46 | + | TARGETS += filesystems/mount_cycle | |
| 46 | 47 | TARGETS += filesystems/nsfs | |
| 47 | 48 | TARGETS += filesystems/fuse | |
| 48 | 49 | TARGETS += filesystems/move_mount | |
| @@ -50,6 +51,8 @@ TARGETS += filesystems/empty_mntns | |||
| 50 | 51 | TARGETS += filesystems/fsmount_ns | |
| 51 | 52 | TARGETS += filesystems/fscontext_ns | |
| 52 | 53 | TARGETS += filesystems/xattr | |
| 54 | + | TARGETS += filesystems/mntns_unbindable | |
| 55 | + | TARGETS += filesystems/umount_propagation | |
| 53 | 56 | TARGETS += firmware | |
| 54 | 57 | TARGETS += fpu | |
| 55 | 58 | TARGETS += ftrace | |
modified tools/testing/selftests/drivers/net/mlxsw/port_range_occ.sh
| @@ -9,6 +9,7 @@ lib_dir=$(dirname $0)/../../../net/forwarding | |||
| 9 | 9 | ||
| 10 | 10 | ALL_TESTS=" | |
| 11 | 11 | port_range_occ_test | |
| 12 | + | port_range_occ_tmplt_test | |
| 12 | 13 | " | |
| 13 | 14 | NUM_NETIFS=2 | |
| 14 | 15 | source $lib_dir/lib.sh | |
| @@ -101,6 +102,31 @@ port_range_occ_test() | |||
| 101 | 102 | log_test "port range occupancy" | |
| 102 | 103 | } | |
| 103 | 104 | ||
| 105 | + | port_range_occ_tmplt_test() | |
| 106 | + | { | |
| 107 | + | local occ | |
| 108 | + | ||
| 109 | + | RET=0 | |
| 110 | + | occ=$(port_range_occ_get) | |
| 111 | + | ||
| 112 | + | # Addition of a chain template should not impact occupancy. | |
| 113 | + | tc chain add dev "$swp1" ingress chain 1 protocol ip \ | |
| 114 | + | flower ip_proto udp src_port 501-600 dst_port 701-800 | |
| 115 | + | check_err $? "Could not add chain template" | |
| 116 | + | ||
| 117 | + | (( occ == $(port_range_occ_get) )) | |
| 118 | + | check_err $? "Got occupancy $(port_range_occ_get), expected $occ" | |
| 119 | + | ||
| 120 | + | # And just for completeness sake, neither should deletion. | |
| 121 | + | tc chain del dev "$swp1" ingress chain 1 | |
| 122 | + | check_err $? "Could not delete chain template" | |
| 123 | + | ||
| 124 | + | (( occ == $(port_range_occ_get) )) | |
| 125 | + | check_err $? "Got occupancy $(port_range_occ_get), expected $occ" | |
| 126 | + | ||
| 127 | + | log_test "port range occupancy after template create/destroy" | |
| 128 | + | } | |
| 129 | + | ||
| 104 | 130 | trap cleanup EXIT | |
| 105 | 131 | ||
| 106 | 132 | setup_prepare | |
modified tools/testing/selftests/filesystems/.gitignore
| @@ -7,3 +7,4 @@ anon_inode_test | |||
| 7 | 7 | kernfs_test | |
| 8 | 8 | idmapped_tmpfile | |
| 9 | 9 | ustat_test | |
| 10 | + | rw_hint_test | |
modified tools/testing/selftests/filesystems/Makefile
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | 2 | ||
| 3 | 3 | CFLAGS += $(KHDR_INCLUDES) | |
| 4 | - | TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test | |
| 4 | + | TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test | |
| 5 | 5 | TEST_GEN_PROGS += idmapped_tmpfile | |
| 6 | 6 | TEST_GEN_PROGS_EXTENDED := dnotify_test | |
| 7 | 7 | ||
modified tools/testing/selftests/filesystems/empty_mntns/.gitignore
| @@ -2,3 +2,6 @@ | |||
| 2 | 2 | clone3_empty_mntns_test | |
| 3 | 3 | empty_mntns_test | |
| 4 | 4 | overmount_chroot_test | |
| 5 | + | internal_sb_reconfigure_test | |
| 6 | + | nullfs_atime_test | |
| 7 | + | root_readdir_test | |
modified tools/testing/selftests/filesystems/empty_mntns/Makefile
| @@ -4,9 +4,14 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) | |||
| 4 | 4 | LDLIBS += -lcap | |
| 5 | 5 | ||
| 6 | 6 | TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test | |
| 7 | + | TEST_GEN_PROGS += internal_sb_reconfigure_test nullfs_atime_test root_readdir_test | |
| 8 | + | ||
| 9 | + | LOCAL_HDRS += ../readdir_hold.h | |
| 7 | 10 | ||
| 8 | 11 | include ../../lib.mk | |
| 9 | 12 | ||
| 10 | 13 | $(OUTPUT)/empty_mntns_test: ../utils.c | |
| 11 | 14 | $(OUTPUT)/overmount_chroot_test: ../utils.c | |
| 12 | 15 | $(OUTPUT)/clone3_empty_mntns_test: ../utils.c | |
| 16 | + | $(OUTPUT)/internal_sb_reconfigure_test: ../utils.c | |
| 17 | + | $(OUTPUT)/root_readdir_test: LDLIBS += -pthread | |
added tools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c mode 100644
| @@ -0,0 +1,108 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0-or-later | |
| 2 | + | /* | |
| 3 | + | * The root of an empty mount namespace is a nullfs mount. Its superblock is | |
| 4 | + | * kernel-internal and shared by every mount namespace. It can't be | |
| 5 | + | * reconfigured, neither through fspick() nor through mount(MS_REMOUNT) nor | |
| 6 | + | * through umount() of the root which remounts it read-only. | |
| 7 | + | */ | |
| 8 | + | #define _GNU_SOURCE | |
| 9 | + | #include <errno.h> | |
| 10 | + | #include <fcntl.h> | |
| 11 | + | #include <sched.h> | |
| 12 | + | #include <stdio.h> | |
| 13 | + | #include <string.h> | |
| 14 | + | #include <sys/mount.h> | |
| 15 | + | #include <sys/statfs.h> | |
| 16 | + | #include <sys/statvfs.h> | |
| 17 | + | #include <sys/syscall.h> | |
| 18 | + | #include <sys/vfs.h> | |
| 19 | + | #include <sys/wait.h> | |
| 20 | + | #include <unistd.h> | |
| 21 | + | ||
| 22 | + | #include "../utils.h" | |
| 23 | + | #include "../wrappers.h" | |
| 24 | + | #include "empty_mntns.h" | |
| 25 | + | #include "kselftest_harness.h" | |
| 26 | + | ||
| 27 | + | #ifndef __NR_fspick | |
| 28 | + | #define __NR_fspick 433 | |
| 29 | + | #endif | |
| 30 | + | ||
| 31 | + | static int sys_fspick(int dfd, const char *path, unsigned int flags) | |
| 32 | + | { | |
| 33 | + | return syscall(__NR_fspick, dfd, path, flags); | |
| 34 | + | } | |
| 35 | + | ||
| 36 | + | /* Child exit codes. */ | |
| 37 | + | enum { | |
| 38 | + | CHILD_OK, | |
| 39 | + | CHILD_USERNS, /* could not create the user namespace */ | |
| 40 | + | CHILD_UNSHARE, /* could not create the empty mount namespace */ | |
| 41 | + | CHILD_FSPICK, /* fspick() of the root was not refused with EINVAL */ | |
| 42 | + | CHILD_REMOUNT, /* mount(MS_REMOUNT) was not refused with EINVAL */ | |
| 43 | + | CHILD_UMOUNT, /* umount() of the root succeeded */ | |
| 44 | + | CHILD_STATFS, /* statfs() of the root failed */ | |
| 45 | + | CHILD_RDONLY, /* the root ended up read-only */ | |
| 46 | + | }; | |
| 47 | + | ||
| 48 | + | static int empty_mntns_child(void) | |
| 49 | + | { | |
| 50 | + | struct statfs st; | |
| 51 | + | ||
| 52 | + | if (enter_userns()) | |
| 53 | + | return CHILD_USERNS; | |
| 54 | + | if (unshare(UNSHARE_EMPTY_MNTNS)) | |
| 55 | + | return CHILD_UNSHARE; | |
| 56 | + | ||
| 57 | + | if (sys_fspick(AT_FDCWD, "/", 0) >= 0 || errno != EINVAL) | |
| 58 | + | return CHILD_FSPICK; | |
| 59 | + | if (!mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL) || | |
| 60 | + | errno != EINVAL) | |
| 61 | + | return CHILD_REMOUNT; | |
| 62 | + | if (!umount2("/", 0)) | |
| 63 | + | return CHILD_UMOUNT; | |
| 64 | + | if (statfs("/", &st)) | |
| 65 | + | return CHILD_STATFS; | |
| 66 | + | if (st.f_flags & ST_RDONLY) | |
| 67 | + | return CHILD_RDONLY; | |
| 68 | + | return CHILD_OK; | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | FIXTURE(internal_sb_reconfigure) {}; | |
| 72 | + | ||
| 73 | + | FIXTURE_SETUP(internal_sb_reconfigure) | |
| 74 | + | { | |
| 75 | + | pid_t pid; | |
| 76 | + | int status; | |
| 77 | + | ||
| 78 | + | pid = fork(); | |
| 79 | + | ASSERT_GE(pid, 0); | |
| 80 | + | if (pid == 0) { | |
| 81 | + | if (enter_userns()) | |
| 82 | + | _exit(1); | |
| 83 | + | if (unshare(UNSHARE_EMPTY_MNTNS)) | |
| 84 | + | _exit(1); | |
| 85 | + | _exit(0); | |
| 86 | + | } | |
| 87 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 88 | + | if (!WIFEXITED(status) || WEXITSTATUS(status)) | |
| 89 | + | SKIP(return, "UNSHARE_EMPTY_MNTNS not supported"); | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | FIXTURE_TEARDOWN(internal_sb_reconfigure) {} | |
| 93 | + | ||
| 94 | + | TEST_F(internal_sb_reconfigure, nullfs_root) | |
| 95 | + | { | |
| 96 | + | pid_t pid; | |
| 97 | + | int status; | |
| 98 | + | ||
| 99 | + | pid = fork(); | |
| 100 | + | ASSERT_GE(pid, 0); | |
| 101 | + | if (pid == 0) | |
| 102 | + | _exit(empty_mntns_child()); | |
| 103 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 104 | + | ASSERT_TRUE(WIFEXITED(status)); | |
| 105 | + | ASSERT_EQ(WEXITSTATUS(status), CHILD_OK); | |
| 106 | + | } | |
| 107 | + | ||
| 108 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c mode 100644
| @@ -0,0 +1,129 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * The root of every empty mount namespace is the same nullfs inode. A read | |
| 4 | + | * of it by one user must not change the access time another user sees. | |
| 5 | + | */ | |
| 6 | + | #define _GNU_SOURCE | |
| 7 | + | #include <dirent.h> | |
| 8 | + | #include <errno.h> | |
| 9 | + | #include <fcntl.h> | |
| 10 | + | #include <sched.h> | |
| 11 | + | #include <stdio.h> | |
| 12 | + | #include <stdlib.h> | |
| 13 | + | #include <string.h> | |
| 14 | + | #include <unistd.h> | |
| 15 | + | #include <sys/stat.h> | |
| 16 | + | #include <sys/wait.h> | |
| 17 | + | ||
| 18 | + | #include "../../kselftest_harness.h" | |
| 19 | + | ||
| 20 | + | #ifndef UNSHARE_EMPTY_MNTNS | |
| 21 | + | #define UNSHARE_EMPTY_MNTNS 0x00100000 | |
| 22 | + | #endif | |
| 23 | + | ||
| 24 | + | enum { | |
| 25 | + | CHILD_OK, | |
| 26 | + | CHILD_UNSUPPORTED, | |
| 27 | + | CHILD_SETUP, | |
| 28 | + | CHILD_CHANGED, | |
| 29 | + | }; | |
| 30 | + | ||
| 31 | + | static int wait_byte(int fd) | |
| 32 | + | { | |
| 33 | + | char c; | |
| 34 | + | ||
| 35 | + | return read(fd, &c, 1) == 1 ? 0 : -1; | |
| 36 | + | } | |
| 37 | + | ||
| 38 | + | static int send_byte(int fd) | |
| 39 | + | { | |
| 40 | + | return write(fd, "x", 1) == 1 ? 0 : -1; | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | static int empty_mntns(void) | |
| 44 | + | { | |
| 45 | + | if (!unshare(UNSHARE_EMPTY_MNTNS)) | |
| 46 | + | return 0; | |
| 47 | + | return errno == EINVAL ? CHILD_UNSUPPORTED : CHILD_SETUP; | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | /* the watcher: stats its root before and after the reader read its own */ | |
| 51 | + | static int watcher(int to_reader, int from_reader) | |
| 52 | + | { | |
| 53 | + | struct stat before, after; | |
| 54 | + | int ret; | |
| 55 | + | ||
| 56 | + | ret = empty_mntns(); | |
| 57 | + | if (ret) | |
| 58 | + | return ret; | |
| 59 | + | if (stat("/", &before)) | |
| 60 | + | return CHILD_SETUP; | |
| 61 | + | if (send_byte(to_reader) || wait_byte(from_reader)) | |
| 62 | + | return CHILD_SETUP; | |
| 63 | + | if (stat("/", &after)) | |
| 64 | + | return CHILD_SETUP; | |
| 65 | + | if (before.st_atim.tv_sec != after.st_atim.tv_sec || | |
| 66 | + | before.st_atim.tv_nsec != after.st_atim.tv_nsec) | |
| 67 | + | return CHILD_CHANGED; | |
| 68 | + | return CHILD_OK; | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | /* the reader: lists its own root, which is the same inode */ | |
| 72 | + | static int reader(int to_watcher, int from_watcher) | |
| 73 | + | { | |
| 74 | + | struct dirent *de; | |
| 75 | + | DIR *d; | |
| 76 | + | int ret; | |
| 77 | + | ||
| 78 | + | ret = empty_mntns(); | |
| 79 | + | if (ret) | |
| 80 | + | return ret; | |
| 81 | + | if (wait_byte(from_watcher)) | |
| 82 | + | return CHILD_SETUP; | |
| 83 | + | d = opendir("/"); | |
| 84 | + | if (!d) | |
| 85 | + | return CHILD_SETUP; | |
| 86 | + | while ((de = readdir(d))) | |
| 87 | + | ; | |
| 88 | + | closedir(d); | |
| 89 | + | return send_byte(to_watcher) ? CHILD_SETUP : CHILD_OK; | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | static int wait_child(pid_t pid) | |
| 93 | + | { | |
| 94 | + | int status; | |
| 95 | + | ||
| 96 | + | if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) | |
| 97 | + | return -1; | |
| 98 | + | return WEXITSTATUS(status); | |
| 99 | + | } | |
| 100 | + | ||
| 101 | + | TEST(empty_mntns_root_atime) | |
| 102 | + | { | |
| 103 | + | int to_reader[2], to_watcher[2], w, r; | |
| 104 | + | pid_t watcher_pid, reader_pid; | |
| 105 | + | ||
| 106 | + | if (geteuid()) | |
| 107 | + | SKIP(return, "test requires root"); | |
| 108 | + | ASSERT_EQ(pipe(to_reader), 0); | |
| 109 | + | ASSERT_EQ(pipe(to_watcher), 0); | |
| 110 | + | ||
| 111 | + | watcher_pid = fork(); | |
| 112 | + | ASSERT_GE(watcher_pid, 0); | |
| 113 | + | if (watcher_pid == 0) | |
| 114 | + | _exit(watcher(to_reader[1], to_watcher[0])); | |
| 115 | + | reader_pid = fork(); | |
| 116 | + | ASSERT_GE(reader_pid, 0); | |
| 117 | + | if (reader_pid == 0) | |
| 118 | + | _exit(reader(to_watcher[1], to_reader[0])); | |
| 119 | + | ||
| 120 | + | r = wait_child(reader_pid); | |
| 121 | + | w = wait_child(watcher_pid); | |
| 122 | + | if (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED) | |
| 123 | + | SKIP(return, "UNSHARE_EMPTY_MNTNS not supported"); | |
| 124 | + | EXPECT_EQ(r, CHILD_OK); | |
| 125 | + | EXPECT_EQ(w, CHILD_OK) | |
| 126 | + | TH_LOG("the access time of the root changed while this namespace did nothing"); | |
| 127 | + | } | |
| 128 | + | ||
| 129 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c mode 100644
| @@ -0,0 +1,45 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * Reading the root of an empty mount namespace holds nothing that anybody | |
| 4 | + | * else waits for: the directory never has an entry, so a readdir stuck in | |
| 5 | + | * the page fault of its buffer stalls neither a create nor a lookup in it. | |
| 6 | + | */ | |
| 7 | + | #define _GNU_SOURCE | |
| 8 | + | #include <errno.h> | |
| 9 | + | #include <fcntl.h> | |
| 10 | + | #include <sched.h> | |
| 11 | + | #include <stdio.h> | |
| 12 | + | #include <stdlib.h> | |
| 13 | + | #include <unistd.h> | |
| 14 | + | ||
| 15 | + | #include "../../kselftest_harness.h" | |
| 16 | + | #include "../readdir_hold.h" | |
| 17 | + | #include "empty_mntns.h" | |
| 18 | + | ||
| 19 | + | TEST(readdir_blocks_nobody) | |
| 20 | + | { | |
| 21 | + | struct readdir_hold hold; | |
| 22 | + | bool stalled; | |
| 23 | + | int dfd; | |
| 24 | + | ||
| 25 | + | if (geteuid()) | |
| 26 | + | SKIP(return, "test requires root"); | |
| 27 | + | if (readdir_hold_init(&hold)) | |
| 28 | + | SKIP(return, "test requires userfaultfd"); | |
| 29 | + | if (unshare(UNSHARE_EMPTY_MNTNS)) { | |
| 30 | + | readdir_hold_destroy(&hold); | |
| 31 | + | if (errno == EINVAL) | |
| 32 | + | SKIP(return, "UNSHARE_EMPTY_MNTNS not supported"); | |
| 33 | + | ASSERT_TRUE(false) | |
| 34 | + | TH_LOG("unshare(UNSHARE_EMPTY_MNTNS): %m"); | |
| 35 | + | } | |
| 36 | + | dfd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 37 | + | ASSERT_GE(dfd, 0); | |
| 38 | + | ASSERT_EQ(readdir_hold_check(&hold, dfd, &stalled), 0); | |
| 39 | + | /* the lookup came back while the readdir was stuck in its fault */ | |
| 40 | + | EXPECT_FALSE(stalled); | |
| 41 | + | close(dfd); | |
| 42 | + | readdir_hold_destroy(&hold); | |
| 43 | + | } | |
| 44 | + | ||
| 45 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mntns_unbindable/Makefile mode 100644
| @@ -0,0 +1,6 @@ | |||
| 1 | + | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | TEST_GEN_PROGS := mntns_unbindable_test | |
| 3 | + | ||
| 4 | + | CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) | |
| 5 | + | ||
| 6 | + | include ../../lib.mk | |
added tools/testing/selftests/filesystems/mntns_unbindable/mntns_unbindable_test.c mode 100644
| @@ -0,0 +1,227 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * An unbindable mount stays unbindable in a cloned mount namespace. | |
| 4 | + | */ | |
| 5 | + | #define _GNU_SOURCE | |
| 6 | + | #include <errno.h> | |
| 7 | + | #include <fcntl.h> | |
| 8 | + | #include <sched.h> | |
| 9 | + | #include <stdio.h> | |
| 10 | + | #include <stdlib.h> | |
| 11 | + | #include <string.h> | |
| 12 | + | #include <sys/mount.h> | |
| 13 | + | #include <sys/stat.h> | |
| 14 | + | #include <sys/syscall.h> | |
| 15 | + | #include <sys/wait.h> | |
| 16 | + | #include <unistd.h> | |
| 17 | + | ||
| 18 | + | #include "../../kselftest_harness.h" | |
| 19 | + | ||
| 20 | + | #ifndef OPEN_TREE_CLONE | |
| 21 | + | #define OPEN_TREE_CLONE 1 | |
| 22 | + | #endif | |
| 23 | + | #ifndef OPEN_TREE_CLOEXEC | |
| 24 | + | #define OPEN_TREE_CLOEXEC O_CLOEXEC | |
| 25 | + | #endif | |
| 26 | + | ||
| 27 | + | static int sys_open_tree(int dfd, const char *filename, unsigned int flags) | |
| 28 | + | { | |
| 29 | + | return syscall(__NR_open_tree, dfd, filename, flags); | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | /* Child exit codes. */ | |
| 33 | + | enum { | |
| 34 | + | CHILD_OK, /* the operation failed with EINVAL as it must */ | |
| 35 | + | CHILD_ALLOWED, /* the operation succeeded: the flag was lost */ | |
| 36 | + | CHILD_UNSHARE, /* unshare(CLONE_NEWNS) failed */ | |
| 37 | + | CHILD_ERRNO, /* the operation failed with some other errno */ | |
| 38 | + | CHILD_MOUNTINFO, /* the mount was not found in mountinfo */ | |
| 39 | + | }; | |
| 40 | + | ||
| 41 | + | FIXTURE(mntns_unbindable) | |
| 42 | + | { | |
| 43 | + | char base[64]; | |
| 44 | + | char src[80]; | |
| 45 | + | char dst[80]; | |
| 46 | + | bool mounted; | |
| 47 | + | }; | |
| 48 | + | ||
| 49 | + | FIXTURE_SETUP(mntns_unbindable) | |
| 50 | + | { | |
| 51 | + | self->mounted = false; | |
| 52 | + | ||
| 53 | + | if (geteuid() != 0) | |
| 54 | + | SKIP(return, "test requires CAP_SYS_ADMIN"); | |
| 55 | + | ||
| 56 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 57 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 58 | + | ||
| 59 | + | snprintf(self->base, sizeof(self->base), "/tmp/mntns_unbindable.XXXXXX"); | |
| 60 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 61 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0); | |
| 62 | + | self->mounted = true; | |
| 63 | + | ||
| 64 | + | snprintf(self->src, sizeof(self->src), "%s/src", self->base); | |
| 65 | + | snprintf(self->dst, sizeof(self->dst), "%s/dst", self->base); | |
| 66 | + | ASSERT_EQ(mkdir(self->src, 0755), 0); | |
| 67 | + | ASSERT_EQ(mkdir(self->dst, 0755), 0); | |
| 68 | + | ||
| 69 | + | ASSERT_EQ(mount("tmpfs", self->src, "tmpfs", 0, NULL), 0); | |
| 70 | + | ASSERT_EQ(mount(NULL, self->src, NULL, MS_UNBINDABLE, NULL), 0); | |
| 71 | + | } | |
| 72 | + | ||
| 73 | + | FIXTURE_TEARDOWN(mntns_unbindable) | |
| 74 | + | { | |
| 75 | + | if (self->mounted) | |
| 76 | + | umount2(self->base, MNT_DETACH); | |
| 77 | + | rmdir(self->base); | |
| 78 | + | } | |
| 79 | + | ||
| 80 | + | static int classify(int ret, int err) | |
| 81 | + | { | |
| 82 | + | if (ret >= 0) | |
| 83 | + | return CHILD_ALLOWED; | |
| 84 | + | return err == EINVAL ? CHILD_OK : CHILD_ERRNO; | |
| 85 | + | } | |
| 86 | + | ||
| 87 | + | /* Is the mount on @mountpoint marked unbindable in /proc/self/mountinfo? */ | |
| 88 | + | static int mountinfo_unbindable(const char *mountpoint) | |
| 89 | + | { | |
| 90 | + | char line[4096]; | |
| 91 | + | FILE *f; | |
| 92 | + | int ret = CHILD_MOUNTINFO; | |
| 93 | + | ||
| 94 | + | f = fopen("/proc/self/mountinfo", "re"); | |
| 95 | + | if (!f) | |
| 96 | + | return CHILD_ERRNO; | |
| 97 | + | ||
| 98 | + | while (fgets(line, sizeof(line), f)) { | |
| 99 | + | char *fields[6], *p = line, *opt; | |
| 100 | + | int i; | |
| 101 | + | ||
| 102 | + | for (i = 0; i < 6; i++) { | |
| 103 | + | fields[i] = strsep(&p, " "); | |
| 104 | + | if (!fields[i]) | |
| 105 | + | break; | |
| 106 | + | } | |
| 107 | + | if (i < 6 || strcmp(fields[4], mountpoint)) | |
| 108 | + | continue; | |
| 109 | + | ||
| 110 | + | /* the optional fields, up to the "-" separator */ | |
| 111 | + | ret = CHILD_ALLOWED; | |
| 112 | + | while ((opt = strsep(&p, " ")) && strcmp(opt, "-")) { | |
| 113 | + | if (!strcmp(opt, "unbindable")) | |
| 114 | + | ret = CHILD_OK; | |
| 115 | + | } | |
| 116 | + | break; | |
| 117 | + | } | |
| 118 | + | fclose(f); | |
| 119 | + | return ret; | |
| 120 | + | } | |
| 121 | + | ||
| 122 | + | static int run_in_child(int (*fn)(const char *src, const char *dst), | |
| 123 | + | const char *src, const char *dst) | |
| 124 | + | { | |
| 125 | + | int status; | |
| 126 | + | pid_t pid; | |
| 127 | + | ||
| 128 | + | pid = fork(); | |
| 129 | + | if (pid < 0) | |
| 130 | + | return -1; | |
| 131 | + | if (pid == 0) | |
| 132 | + | _exit(fn(src, dst)); | |
| 133 | + | if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) | |
| 134 | + | return -1; | |
| 135 | + | return WEXITSTATUS(status); | |
| 136 | + | } | |
| 137 | + | ||
| 138 | + | static int bind_after_clone(const char *src, const char *dst) | |
| 139 | + | { | |
| 140 | + | int ret; | |
| 141 | + | ||
| 142 | + | if (unshare(CLONE_NEWNS)) | |
| 143 | + | return CHILD_UNSHARE; | |
| 144 | + | ret = mount(src, dst, NULL, MS_BIND, NULL); | |
| 145 | + | return classify(ret, errno); | |
| 146 | + | } | |
| 147 | + | ||
| 148 | + | static int rbind_after_clone(const char *src, const char *dst) | |
| 149 | + | { | |
| 150 | + | int ret; | |
| 151 | + | ||
| 152 | + | if (unshare(CLONE_NEWNS)) | |
| 153 | + | return CHILD_UNSHARE; | |
| 154 | + | ret = mount(src, dst, NULL, MS_BIND | MS_REC, NULL); | |
| 155 | + | return classify(ret, errno); | |
| 156 | + | } | |
| 157 | + | ||
| 158 | + | static int open_tree_after_clone(const char *src, const char *dst) | |
| 159 | + | { | |
| 160 | + | int ret; | |
| 161 | + | ||
| 162 | + | if (unshare(CLONE_NEWNS)) | |
| 163 | + | return CHILD_UNSHARE; | |
| 164 | + | ret = sys_open_tree(AT_FDCWD, src, OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 165 | + | return classify(ret, errno); | |
| 166 | + | } | |
| 167 | + | ||
| 168 | + | static int mountinfo_after_clone(const char *src, const char *dst) | |
| 169 | + | { | |
| 170 | + | if (unshare(CLONE_NEWNS)) | |
| 171 | + | return CHILD_UNSHARE; | |
| 172 | + | return mountinfo_unbindable(src); | |
| 173 | + | } | |
| 174 | + | ||
| 175 | + | static int bind_after_two_clones(const char *src, const char *dst) | |
| 176 | + | { | |
| 177 | + | int ret; | |
| 178 | + | ||
| 179 | + | if (unshare(CLONE_NEWNS)) | |
| 180 | + | return CHILD_UNSHARE; | |
| 181 | + | if (unshare(CLONE_NEWNS)) | |
| 182 | + | return CHILD_UNSHARE; | |
| 183 | + | ret = mount(src, dst, NULL, MS_BIND, NULL); | |
| 184 | + | return classify(ret, errno); | |
| 185 | + | } | |
| 186 | + | ||
| 187 | + | /* The namespace the mount was made unbindable in. */ | |
| 188 | + | TEST_F(mntns_unbindable, refuses_bind) | |
| 189 | + | { | |
| 190 | + | int ret = mount(self->src, self->dst, NULL, MS_BIND, NULL); | |
| 191 | + | ||
| 192 | + | ASSERT_EQ(classify(ret, errno), CHILD_OK); | |
| 193 | + | ASSERT_EQ(mountinfo_unbindable(self->src), CHILD_OK); | |
| 194 | + | } | |
| 195 | + | ||
| 196 | + | /* A copy of the namespace must not turn the mount bindable. */ | |
| 197 | + | TEST_F(mntns_unbindable, refuses_bind_after_clone) | |
| 198 | + | { | |
| 199 | + | ASSERT_EQ(run_in_child(bind_after_clone, self->src, self->dst), CHILD_OK) | |
| 200 | + | TH_LOG("bind of an unbindable mount allowed in a copied mount namespace"); | |
| 201 | + | } | |
| 202 | + | ||
| 203 | + | TEST_F(mntns_unbindable, refuses_rbind_after_clone) | |
| 204 | + | { | |
| 205 | + | ASSERT_EQ(run_in_child(rbind_after_clone, self->src, self->dst), CHILD_OK) | |
| 206 | + | TH_LOG("rbind of an unbindable mount allowed in a copied mount namespace"); | |
| 207 | + | } | |
| 208 | + | ||
| 209 | + | TEST_F(mntns_unbindable, refuses_open_tree_after_clone) | |
| 210 | + | { | |
| 211 | + | ASSERT_EQ(run_in_child(open_tree_after_clone, self->src, self->dst), CHILD_OK) | |
| 212 | + | TH_LOG("OPEN_TREE_CLONE of an unbindable mount allowed in a copied mount namespace"); | |
| 213 | + | } | |
| 214 | + | ||
| 215 | + | TEST_F(mntns_unbindable, mountinfo_after_clone) | |
| 216 | + | { | |
| 217 | + | ASSERT_EQ(run_in_child(mountinfo_after_clone, self->src, self->dst), CHILD_OK) | |
| 218 | + | TH_LOG("mountinfo does not show the mount as unbindable in a copied mount namespace"); | |
| 219 | + | } | |
| 220 | + | ||
| 221 | + | TEST_F(mntns_unbindable, refuses_bind_after_two_clones) | |
| 222 | + | { | |
| 223 | + | ASSERT_EQ(run_in_child(bind_after_two_clones, self->src, self->dst), CHILD_OK) | |
| 224 | + | TH_LOG("bind of an unbindable mount allowed two mount namespace copies down"); | |
| 225 | + | } | |
| 226 | + | ||
| 227 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/.gitignore mode 100644
| @@ -0,0 +1,8 @@ | |||
| 1 | + | # SPDX-License-Identifier: GPL-2.0-only | |
| 2 | + | loop_cycle_test | |
| 3 | + | unmounted_tree_test | |
| 4 | + | overmount_reparent_test | |
| 5 | + | mount_cover_test | |
| 6 | + | locked_handle_test | |
| 7 | + | nsfs_rbind_loop_test | |
| 8 | + | overmount_ns_file_test | |
added tools/testing/selftests/filesystems/mount_cycle/Makefile mode 100644
| @@ -0,0 +1,12 @@ | |||
| 1 | + | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | TEST_GEN_PROGS := loop_cycle_test unmounted_tree_test overmount_reparent_test mount_cover_test locked_handle_test | |
| 3 | + | TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test | |
| 4 | + | ||
| 5 | + | CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) | |
| 6 | + | ||
| 7 | + | LOCAL_HDRS += ../readdir_hold.h | |
| 8 | + | ||
| 9 | + | include ../../lib.mk | |
| 10 | + | ||
| 11 | + | $(OUTPUT)/locked_handle_test: LDLIBS += -pthread | |
| 12 | + | $(OUTPUT)/mount_cover_test: LDLIBS += -pthread | |
added tools/testing/selftests/filesystems/mount_cycle/config mode 100644
| @@ -0,0 +1,39 @@ | |||
| 1 | + | CONFIG_USER_NS=y | |
| 2 | + | CONFIG_TMPFS=y | |
| 3 | + | CONFIG_BLK_DEV_LOOP=y | |
| 4 | + | CONFIG_VFAT_FS=y | |
| 5 | + | CONFIG_MSDOS_FS=y | |
| 6 | + | CONFIG_NLS_CODEPAGE_437=y | |
| 7 | + | CONFIG_NLS_ISO8859_1=y | |
| 8 | + | CONFIG_MINIX_FS=y | |
| 9 | + | CONFIG_AUTOFS_FS=y | |
| 10 | + | CONFIG_ZRAM=y | |
| 11 | + | CONFIG_ZRAM_WRITEBACK=y | |
| 12 | + | CONFIG_KEYS=y | |
| 13 | + | CONFIG_ECRYPT_FS=y | |
| 14 | + | CONFIG_BINFMT_MISC=y | |
| 15 | + | CONFIG_FUSE_FS=y | |
| 16 | + | CONFIG_FUSE_PASSTHROUGH=y | |
| 17 | + | CONFIG_BLK_DEV_ZONED=y | |
| 18 | + | CONFIG_BLK_DEV_ZONED_LOOP=y | |
| 19 | + | CONFIG_CONFIGFS_FS=y | |
| 20 | + | CONFIG_USB_SUPPORT=y | |
| 21 | + | CONFIG_USB=y | |
| 22 | + | CONFIG_USB_STORAGE=y | |
| 23 | + | CONFIG_SCSI=y | |
| 24 | + | CONFIG_BLK_DEV_SD=y | |
| 25 | + | CONFIG_USB_GADGET=y | |
| 26 | + | CONFIG_USB_DUMMY_HCD=y | |
| 27 | + | CONFIG_USB_CONFIGFS=y | |
| 28 | + | CONFIG_USB_CONFIGFS_MASS_STORAGE=y | |
| 29 | + | CONFIG_MD=y | |
| 30 | + | CONFIG_BLK_DEV_MD=y | |
| 31 | + | CONFIG_MD_RAID1=y | |
| 32 | + | CONFIG_MD_BITMAP=y | |
| 33 | + | CONFIG_MD_BITMAP_FILE=y | |
| 34 | + | CONFIG_INOTIFY_USER=y | |
| 35 | + | CONFIG_DNOTIFY=y | |
| 36 | + | CONFIG_FANOTIFY=y | |
| 37 | + | CONFIG_FILE_LOCKING=y | |
| 38 | + | CONFIG_CRYPTO_AES=y | |
| 39 | + | CONFIG_USERFAULTFD=y | |
added tools/testing/selftests/filesystems/mount_cycle/locked_handle_test.c mode 100644
| @@ -0,0 +1,377 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * may_decode_fh() refuses a file handle below a mount with locked children | |
| 4 | + | * to root in a user namespace. That has to hold while the mount is lazily | |
| 5 | + | * unmounted and its children, the locked ones too, are taken off it. | |
| 6 | + | */ | |
| 7 | + | #define _GNU_SOURCE | |
| 8 | + | #include <errno.h> | |
| 9 | + | #include <fcntl.h> | |
| 10 | + | #include <pthread.h> | |
| 11 | + | #include <sched.h> | |
| 12 | + | #include <stdatomic.h> | |
| 13 | + | #include <stdbool.h> | |
| 14 | + | #include <stdio.h> | |
| 15 | + | #include <stdlib.h> | |
| 16 | + | #include <string.h> | |
| 17 | + | #include <unistd.h> | |
| 18 | + | #include <sys/mount.h> | |
| 19 | + | #include <sys/prctl.h> | |
| 20 | + | #include <sys/stat.h> | |
| 21 | + | #include <sys/syscall.h> | |
| 22 | + | #include <sys/wait.h> | |
| 23 | + | ||
| 24 | + | #include "../../kselftest_harness.h" | |
| 25 | + | ||
| 26 | + | #ifndef OPEN_TREE_CLONE | |
| 27 | + | #define OPEN_TREE_CLONE 1 | |
| 28 | + | #endif | |
| 29 | + | #ifndef OPEN_TREE_CLOEXEC | |
| 30 | + | #define OPEN_TREE_CLOEXEC O_CLOEXEC | |
| 31 | + | #endif | |
| 32 | + | #ifndef AT_RECURSIVE | |
| 33 | + | #define AT_RECURSIVE 0x8000 | |
| 34 | + | #endif | |
| 35 | + | ||
| 36 | + | #define DIR_LEN 64 | |
| 37 | + | #define PATH_LEN 128 | |
| 38 | + | ||
| 39 | + | #define ROUNDS 100 /* lazy umounts raced per test */ | |
| 40 | + | #define RACERS 3 /* threads in open_by_handle_at() */ | |
| 41 | + | #define EXTRA_MOUNTS 64 /* make umount_tree() hold mount_lock longer */ | |
| 42 | + | #define MAX_DELAY_US 3000 /* before the umount */ | |
| 43 | + | #define TAIL_US 2000 /* after it */ | |
| 44 | + | ||
| 45 | + | struct handle { | |
| 46 | + | struct file_handle fh; | |
| 47 | + | unsigned char buf[MAX_HANDLE_SZ]; | |
| 48 | + | }; | |
| 49 | + | ||
| 50 | + | /* exit codes of the child */ | |
| 51 | + | enum { | |
| 52 | + | CHILD_OK, | |
| 53 | + | CHILD_SETUP, | |
| 54 | + | CHILD_DECODED, /* decoded past a locked child */ | |
| 55 | + | CHILD_MOUNTED, /* not refused while mounted */ | |
| 56 | + | CHILD_UNMOUNTED, /* not refused once unmounted */ | |
| 57 | + | CHILD_ALLOWED, /* refused where nothing is locked */ | |
| 58 | + | CHILD_NOUSERNS, /* no user namespace to be had */ | |
| 59 | + | }; | |
| 60 | + | ||
| 61 | + | static int write_file(const char *path, const char *s) | |
| 62 | + | { | |
| 63 | + | ssize_t n = -1; | |
| 64 | + | int fd; | |
| 65 | + | ||
| 66 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 67 | + | if (fd >= 0) { | |
| 68 | + | n = write(fd, s, strlen(s)); | |
| 69 | + | close(fd); | |
| 70 | + | } | |
| 71 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 72 | + | } | |
| 73 | + | ||
| 74 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 75 | + | static int enter_userns(void) | |
| 76 | + | { | |
| 77 | + | uid_t uid = getuid(); | |
| 78 | + | gid_t gid = getgid(); | |
| 79 | + | char map[32]; | |
| 80 | + | ||
| 81 | + | prctl(PR_SET_DUMPABLE, 1); | |
| 82 | + | /* EINVAL: no USER_NS, ENOSPC: user.max_user_namespaces is 0, EPERM: an LSM */ | |
| 83 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 84 | + | return errno == EINVAL || errno == ENOSPC || errno == EPERM ? | |
| 85 | + | CHILD_NOUSERNS : CHILD_SETUP; | |
| 86 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 87 | + | return CHILD_SETUP; | |
| 88 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 89 | + | if (write_file("/proc/self/uid_map", map)) | |
| 90 | + | return CHILD_SETUP; | |
| 91 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 92 | + | if (write_file("/proc/self/gid_map", map)) | |
| 93 | + | return CHILD_SETUP; | |
| 94 | + | if (setgid(0) || setuid(0)) | |
| 95 | + | return CHILD_SETUP; | |
| 96 | + | if (mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL)) | |
| 97 | + | return CHILD_SETUP; | |
| 98 | + | return CHILD_OK; | |
| 99 | + | } | |
| 100 | + | ||
| 101 | + | static int get_handle(const char *path, struct handle *h) | |
| 102 | + | { | |
| 103 | + | int mntid; | |
| 104 | + | ||
| 105 | + | h->fh.handle_bytes = MAX_HANDLE_SZ; | |
| 106 | + | return name_to_handle_at(AT_FDCWD, path, &h->fh, &mntid, 0); | |
| 107 | + | } | |
| 108 | + | ||
| 109 | + | static int decode(int dfd, struct handle *h) | |
| 110 | + | { | |
| 111 | + | return open_by_handle_at(dfd, &h->fh, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 112 | + | } | |
| 113 | + | ||
| 114 | + | struct race { | |
| 115 | + | int dfd; | |
| 116 | + | struct handle *h; | |
| 117 | + | atomic_int go; | |
| 118 | + | atomic_int stop; | |
| 119 | + | atomic_int won; /* the first decoded descriptor */ | |
| 120 | + | }; | |
| 121 | + | ||
| 122 | + | static void *racer(void *arg) | |
| 123 | + | { | |
| 124 | + | struct race *r = arg; | |
| 125 | + | ||
| 126 | + | while (!atomic_load(&r->go)) | |
| 127 | + | ; | |
| 128 | + | while (!atomic_load(&r->stop)) { | |
| 129 | + | int none = -1; | |
| 130 | + | int fd; | |
| 131 | + | ||
| 132 | + | fd = decode(r->dfd, r->h); | |
| 133 | + | if (fd < 0) | |
| 134 | + | continue; | |
| 135 | + | if (!atomic_compare_exchange_strong(&r->won, &none, fd)) | |
| 136 | + | close(fd); | |
| 137 | + | } | |
| 138 | + | return NULL; | |
| 139 | + | } | |
| 140 | + | ||
| 141 | + | /* stop the @n racers started so far and wait for them, they spin on @r */ | |
| 142 | + | static void stop_racers(struct race *r, pthread_t *th, int n) | |
| 143 | + | { | |
| 144 | + | int i; | |
| 145 | + | ||
| 146 | + | atomic_store(&r->stop, 1); | |
| 147 | + | atomic_store(&r->go, 1); /* one still waiting for the start sees stop next */ | |
| 148 | + | for (i = 0; i < n; i++) | |
| 149 | + | pthread_join(th[i], NULL); | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | /* | |
| 153 | + | * Bind @h recursively at @w, or take a detached copy of it, and race | |
| 154 | + | * open_by_handle_at() of @inner against the lazy umount. The decoded | |
| 155 | + | * descriptor, if there was one, is left in @won. | |
| 156 | + | */ | |
| 157 | + | static int race_round(const char *h, const char *w, struct handle *inner, | |
| 158 | + | bool dissolve, int *won) | |
| 159 | + | { | |
| 160 | + | struct race r = { .h = inner, .won = -1 }; | |
| 161 | + | pthread_t th[RACERS]; | |
| 162 | + | int treefd = -1, fd, i; | |
| 163 | + | ||
| 164 | + | if (dissolve) { | |
| 165 | + | treefd = syscall(__NR_open_tree, AT_FDCWD, h, | |
| 166 | + | OPEN_TREE_CLONE | AT_RECURSIVE | OPEN_TREE_CLOEXEC); | |
| 167 | + | if (treefd < 0) | |
| 168 | + | return CHILD_SETUP; | |
| 169 | + | /* an ordinary descriptor on the copy, treefd's close dissolves it */ | |
| 170 | + | r.dfd = openat(treefd, ".", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 171 | + | } else { | |
| 172 | + | if (mount(h, w, NULL, MS_BIND | MS_REC, NULL)) | |
| 173 | + | return CHILD_SETUP; | |
| 174 | + | r.dfd = open(w, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 175 | + | } | |
| 176 | + | if (r.dfd < 0) | |
| 177 | + | return CHILD_SETUP; | |
| 178 | + | ||
| 179 | + | fd = decode(r.dfd, inner); | |
| 180 | + | if (fd >= 0 || errno != EPERM) { | |
| 181 | + | if (fd >= 0) | |
| 182 | + | close(fd); | |
| 183 | + | return CHILD_MOUNTED; | |
| 184 | + | } | |
| 185 | + | ||
| 186 | + | for (i = 0; i < RACERS; i++) { | |
| 187 | + | if (pthread_create(&th[i], NULL, racer, &r)) { | |
| 188 | + | stop_racers(&r, th, i); | |
| 189 | + | return CHILD_SETUP; | |
| 190 | + | } | |
| 191 | + | } | |
| 192 | + | atomic_store(&r.go, 1); | |
| 193 | + | usleep(rand() % MAX_DELAY_US); | |
| 194 | + | if (dissolve) | |
| 195 | + | close(treefd); | |
| 196 | + | else if (umount2(w, MNT_DETACH)) { | |
| 197 | + | stop_racers(&r, th, RACERS); | |
| 198 | + | return CHILD_SETUP; | |
| 199 | + | } | |
| 200 | + | usleep(TAIL_US); | |
| 201 | + | stop_racers(&r, th, RACERS); | |
| 202 | + | ||
| 203 | + | fd = decode(r.dfd, inner); | |
| 204 | + | if (fd >= 0) { | |
| 205 | + | close(fd); | |
| 206 | + | return CHILD_UNMOUNTED; | |
| 207 | + | } | |
| 208 | + | close(r.dfd); | |
| 209 | + | *won = atomic_load(&r.won); | |
| 210 | + | return CHILD_OK; | |
| 211 | + | } | |
| 212 | + | ||
| 213 | + | static int race_child(const char *h, const char *w, struct handle *inner, | |
| 214 | + | bool dissolve) | |
| 215 | + | { | |
| 216 | + | int ret, won, i; | |
| 217 | + | ||
| 218 | + | srand(getpid()); | |
| 219 | + | ret = enter_userns(); | |
| 220 | + | if (ret) | |
| 221 | + | return ret; | |
| 222 | + | for (i = 0; i < ROUNDS; i++) { | |
| 223 | + | ret = race_round(h, w, inner, dissolve, &won); | |
| 224 | + | if (ret) | |
| 225 | + | return ret; | |
| 226 | + | if (won >= 0) | |
| 227 | + | return CHILD_DECODED; | |
| 228 | + | } | |
| 229 | + | return CHILD_OK; | |
| 230 | + | } | |
| 231 | + | ||
| 232 | + | /* a bind without locked children decodes while mounted and not after */ | |
| 233 | + | static int allowed_child(const char *plain, const char *w, struct handle *h) | |
| 234 | + | { | |
| 235 | + | int dfd, fd, ret; | |
| 236 | + | ||
| 237 | + | ret = enter_userns(); | |
| 238 | + | if (ret) | |
| 239 | + | return ret; | |
| 240 | + | if (mount(plain, w, NULL, MS_BIND | MS_REC, NULL)) | |
| 241 | + | return CHILD_SETUP; | |
| 242 | + | dfd = open(w, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 243 | + | if (dfd < 0) | |
| 244 | + | return CHILD_SETUP; | |
| 245 | + | fd = decode(dfd, h); | |
| 246 | + | if (fd < 0) | |
| 247 | + | return CHILD_ALLOWED; | |
| 248 | + | close(fd); | |
| 249 | + | if (umount2(w, MNT_DETACH)) | |
| 250 | + | return CHILD_SETUP; | |
| 251 | + | fd = decode(dfd, h); | |
| 252 | + | if (fd >= 0) { | |
| 253 | + | close(fd); | |
| 254 | + | return CHILD_UNMOUNTED; | |
| 255 | + | } | |
| 256 | + | return errno == EPERM ? CHILD_OK : CHILD_UNMOUNTED; | |
| 257 | + | } | |
| 258 | + | ||
| 259 | + | FIXTURE(locked_handle) { | |
| 260 | + | char base[DIR_LEN]; | |
| 261 | + | char h[PATH_LEN]; /* the tree with the covered directory */ | |
| 262 | + | char plain[PATH_LEN]; /* a tree with no mount in it */ | |
| 263 | + | char w[PATH_LEN]; /* where the child binds either */ | |
| 264 | + | struct handle inner; /* h/top/secret/inner, covered */ | |
| 265 | + | struct handle uncovered; /* plain/inner */ | |
| 266 | + | }; | |
| 267 | + | ||
| 268 | + | FIXTURE_SETUP(locked_handle) | |
| 269 | + | { | |
| 270 | + | char p[PATH_LEN], e[PATH_LEN]; | |
| 271 | + | int i; | |
| 272 | + | ||
| 273 | + | if (geteuid()) | |
| 274 | + | SKIP(return, "test requires root"); | |
| 275 | + | ||
| 276 | + | snprintf(self->base, sizeof(self->base), "/tmp/locked_handle.XXXXXX"); | |
| 277 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 278 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 279 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 280 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0); | |
| 281 | + | ||
| 282 | + | snprintf(self->h, sizeof(self->h), "%s/h", self->base); | |
| 283 | + | snprintf(self->plain, sizeof(self->plain), "%s/plain", self->base); | |
| 284 | + | snprintf(self->w, sizeof(self->w), "%s/w", self->base); | |
| 285 | + | ASSERT_EQ(mkdir(self->h, 0755), 0); | |
| 286 | + | ASSERT_EQ(mkdir(self->plain, 0755), 0); | |
| 287 | + | ASSERT_EQ(mkdir(self->w, 0755), 0); | |
| 288 | + | snprintf(p, sizeof(p), "%s/plain/inner", self->base); | |
| 289 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 290 | + | ASSERT_EQ(get_handle(p, &self->uncovered), 0); | |
| 291 | + | ||
| 292 | + | /* the handle is for this filesystem */ | |
| 293 | + | ASSERT_EQ(mount("tmpfs", self->h, "tmpfs", 0, NULL), 0); | |
| 294 | + | snprintf(p, sizeof(p), "%s/h/top", self->base); | |
| 295 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 296 | + | snprintf(p, sizeof(p), "%s/h/top/secret", self->base); | |
| 297 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 298 | + | snprintf(p, sizeof(p), "%s/h/top/secret/inner", self->base); | |
| 299 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 300 | + | ASSERT_EQ(get_handle(p, &self->inner), 0); | |
| 301 | + | snprintf(e, sizeof(e), "%s/h/empty", self->base); | |
| 302 | + | ASSERT_EQ(mkdir(e, 0755), 0); | |
| 303 | + | ||
| 304 | + | /* cover it, and some more so the umount takes longer */ | |
| 305 | + | snprintf(p, sizeof(p), "%s/h/top/secret", self->base); | |
| 306 | + | ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, NULL), 0); | |
| 307 | + | for (i = 0; i < EXTRA_MOUNTS; i++) { | |
| 308 | + | snprintf(p, sizeof(p), "%s/h/c%d", self->base, i); | |
| 309 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 310 | + | ASSERT_EQ(mount(e, p, NULL, MS_BIND, NULL), 0); | |
| 311 | + | } | |
| 312 | + | } | |
| 313 | + | ||
| 314 | + | FIXTURE_TEARDOWN(locked_handle) | |
| 315 | + | { | |
| 316 | + | umount2(self->base, MNT_DETACH); | |
| 317 | + | rmdir(self->base); | |
| 318 | + | } | |
| 319 | + | ||
| 320 | + | static int wait_child(pid_t pid) | |
| 321 | + | { | |
| 322 | + | int status; | |
| 323 | + | ||
| 324 | + | if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) | |
| 325 | + | return -1; | |
| 326 | + | return WEXITSTATUS(status); | |
| 327 | + | } | |
| 328 | + | ||
| 329 | + | TEST_F(locked_handle, lazy_umount) | |
| 330 | + | { | |
| 331 | + | pid_t pid; | |
| 332 | + | int ret; | |
| 333 | + | ||
| 334 | + | pid = fork(); | |
| 335 | + | ASSERT_GE(pid, 0); | |
| 336 | + | if (pid == 0) | |
| 337 | + | _exit(race_child(self->h, self->w, &self->inner, false)); | |
| 338 | + | ret = wait_child(pid); | |
| 339 | + | TH_LOG("child exit code %d", ret); | |
| 340 | + | if (ret == CHILD_NOUSERNS) | |
| 341 | + | SKIP(return, "no user namespaces"); | |
| 342 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 343 | + | } | |
| 344 | + | ||
| 345 | + | TEST_F(locked_handle, dissolve) | |
| 346 | + | { | |
| 347 | + | pid_t pid; | |
| 348 | + | int ret; | |
| 349 | + | ||
| 350 | + | pid = fork(); | |
| 351 | + | ASSERT_GE(pid, 0); | |
| 352 | + | if (pid == 0) | |
| 353 | + | _exit(race_child(self->h, self->w, &self->inner, true)); | |
| 354 | + | ret = wait_child(pid); | |
| 355 | + | TH_LOG("child exit code %d", ret); | |
| 356 | + | if (ret == CHILD_NOUSERNS) | |
| 357 | + | SKIP(return, "no user namespaces"); | |
| 358 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 359 | + | } | |
| 360 | + | ||
| 361 | + | TEST_F(locked_handle, allowed_use) | |
| 362 | + | { | |
| 363 | + | pid_t pid; | |
| 364 | + | int ret; | |
| 365 | + | ||
| 366 | + | pid = fork(); | |
| 367 | + | ASSERT_GE(pid, 0); | |
| 368 | + | if (pid == 0) | |
| 369 | + | _exit(allowed_child(self->plain, self->w, &self->uncovered)); | |
| 370 | + | ret = wait_child(pid); | |
| 371 | + | TH_LOG("child exit code %d", ret); | |
| 372 | + | if (ret == CHILD_NOUSERNS) | |
| 373 | + | SKIP(return, "no user namespaces"); | |
| 374 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 375 | + | } | |
| 376 | + | ||
| 377 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/loop_cycle_test.c mode 100644
| @@ -0,0 +1,1542 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A mount that another namespace's rmdir detached, or that went down with | |
| 4 | + | * the detached tree it was in when the tree's last fd was closed, keeps | |
| 5 | + | * its submounts connected, and a connected submount is put by its | |
| 6 | + | * parent's final mntput(). A submount whose filesystem keeps a file open | |
| 7 | + | * on the parent then holds the parent's count above zero for good: | |
| 8 | + | * nothing in userspace refers to either mount any more and nothing can | |
| 9 | + | * release them. A loop device is the simplest such filesystem, its | |
| 10 | + | * backing file sits on the parent. | |
| 11 | + | */ | |
| 12 | + | #define _GNU_SOURCE | |
| 13 | + | #include <dirent.h> | |
| 14 | + | #include <errno.h> | |
| 15 | + | #include <fcntl.h> | |
| 16 | + | #include <sched.h> | |
| 17 | + | #include <stdio.h> | |
| 18 | + | #include <stdlib.h> | |
| 19 | + | #include <string.h> | |
| 20 | + | #include <sys/ioctl.h> | |
| 21 | + | #include <sys/mount.h> | |
| 22 | + | #include <sys/stat.h> | |
| 23 | + | #include <stdbool.h> | |
| 24 | + | #include <sys/wait.h> | |
| 25 | + | #include <unistd.h> | |
| 26 | + | #include <linux/fuse.h> | |
| 27 | + | #include <linux/keyctl.h> | |
| 28 | + | #include <linux/major.h> | |
| 29 | + | #include <linux/raid/md_u.h> | |
| 30 | + | #include <linux/raid/md_p.h> | |
| 31 | + | #include <linux/loop.h> | |
| 32 | + | #include <linux/magic.h> | |
| 33 | + | #include <sys/syscall.h> | |
| 34 | + | #include <sys/sysmacros.h> | |
| 35 | + | #include <sys/uio.h> | |
| 36 | + | ||
| 37 | + | #include "../wrappers.h" | |
| 38 | + | #include "../../kselftest_harness.h" | |
| 39 | + | ||
| 40 | + | #define IMAGE_SIZE (1440 * 1024) | |
| 41 | + | #define SECTOR 512 | |
| 42 | + | ||
| 43 | + | /* | |
| 44 | + | * The tmpfs of the fixture. A directory of its own from mkdtemp(), so that | |
| 45 | + | * the test needs no writable root directory and two instances don't take | |
| 46 | + | * each other's mounts down. | |
| 47 | + | */ | |
| 48 | + | static char base[64]; | |
| 49 | + | ||
| 50 | + | /* The configfs directory of the gadget, named after the test process. */ | |
| 51 | + | static char gadget[96]; | |
| 52 | + | ||
| 53 | + | /* A path below the base directory. Eight of them can be in use at a time. */ | |
| 54 | + | static const char *at(const char *rel) | |
| 55 | + | { | |
| 56 | + | static char buf[8][PATH_MAX]; | |
| 57 | + | static unsigned int next; | |
| 58 | + | char *p = buf[next++ % 8]; | |
| 59 | + | ||
| 60 | + | snprintf(p, PATH_MAX, "%s/%s", base, rel); | |
| 61 | + | return p; | |
| 62 | + | } | |
| 63 | + | ||
| 64 | + | /* A path below the gadget's configfs directory. */ | |
| 65 | + | static const char *gat(const char *rel) | |
| 66 | + | { | |
| 67 | + | static char buf[4][PATH_MAX]; | |
| 68 | + | static unsigned int next; | |
| 69 | + | char *p = buf[next++ % 4]; | |
| 70 | + | ||
| 71 | + | snprintf(p, PATH_MAX, "%s%s", gadget, rel); | |
| 72 | + | return p; | |
| 73 | + | } | |
| 74 | + | ||
| 75 | + | /* The loop devices this process has bound, to release them on every path. */ | |
| 76 | + | #define MAX_LOOPS 4 | |
| 77 | + | static int bound[MAX_LOOPS]; | |
| 78 | + | static int nr_bound; | |
| 79 | + | ||
| 80 | + | /* What a child tells its parent: the loop devices it has bound, -1 for none. */ | |
| 81 | + | struct report { | |
| 82 | + | int n[2]; | |
| 83 | + | }; | |
| 84 | + | ||
| 85 | + | /* A blank FAT12 floppy image: boot sector, two FATs, an empty root directory. */ | |
| 86 | + | static int write_fat12(int fd) | |
| 87 | + | { | |
| 88 | + | struct stat st; | |
| 89 | + | unsigned char sector[SECTOR] = { | |
| 90 | + | 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1', | |
| 91 | + | [11] = 0x00, 0x02, /* bytes per sector: 512 */ | |
| 92 | + | [13] = 1, /* sectors per cluster */ | |
| 93 | + | [14] = 1, 0, /* reserved sectors */ | |
| 94 | + | [16] = 2, /* FATs */ | |
| 95 | + | [17] = 0xe0, 0x00, /* root directory entries: 224 */ | |
| 96 | + | [19] = 0x40, 0x0b, /* total sectors: 2880 */ | |
| 97 | + | [21] = 0xf0, /* media descriptor */ | |
| 98 | + | [22] = 9, 0, /* sectors per FAT */ | |
| 99 | + | [24] = 18, 0, /* sectors per track */ | |
| 100 | + | [26] = 2, 0, /* heads */ | |
| 101 | + | [38] = 0x29, /* extended boot signature */ | |
| 102 | + | [39] = 0x12, 0x34, 0x56, 0x78, | |
| 103 | + | [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ', | |
| 104 | + | [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ', | |
| 105 | + | [510] = 0x55, 0xaa, | |
| 106 | + | }; | |
| 107 | + | unsigned char fat[SECTOR] = { 0xf0, 0xff, 0xff }; | |
| 108 | + | ||
| 109 | + | if (pwrite(fd, sector, SECTOR, 0) != SECTOR) | |
| 110 | + | return -1; | |
| 111 | + | /* the first FAT and the second one, one sector each is enough */ | |
| 112 | + | if (pwrite(fd, fat, SECTOR, 1 * SECTOR) != SECTOR || | |
| 113 | + | pwrite(fd, fat, SECTOR, 10 * SECTOR) != SECTOR) | |
| 114 | + | return -1; | |
| 115 | + | if (fstat(fd, &st) || S_ISBLK(st.st_mode)) | |
| 116 | + | return 0; | |
| 117 | + | return ftruncate(fd, IMAGE_SIZE); | |
| 118 | + | } | |
| 119 | + | ||
| 120 | + | /* | |
| 121 | + | * A blank FAT12 image with 4 KiB sectors and @sectors of them, for a device | |
| 122 | + | * with 4 KiB logical blocks (zram) or for a bigger image than a floppy. | |
| 123 | + | */ | |
| 124 | + | static int write_fat12_4k(int fd, unsigned int sectors) | |
| 125 | + | { | |
| 126 | + | unsigned int fat_sectors = (sectors * 3 / 2 + 4095) / 4096; | |
| 127 | + | unsigned char sector[4096] = { | |
| 128 | + | 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1', | |
| 129 | + | [11] = 0x00, 0x10, /* bytes per sector: 4096 */ | |
| 130 | + | [13] = 1, /* sectors per cluster */ | |
| 131 | + | [14] = 1, 0, /* reserved sectors */ | |
| 132 | + | [16] = 2, /* FATs */ | |
| 133 | + | [17] = 128, 0, /* root directory entries: one sector */ | |
| 134 | + | [19] = sectors & 0xff, sectors >> 8, | |
| 135 | + | [21] = 0xf8, /* media descriptor */ | |
| 136 | + | [22] = fat_sectors, 0, | |
| 137 | + | [24] = 63, 0, /* sectors per track */ | |
| 138 | + | [26] = 255, 0, /* heads */ | |
| 139 | + | [38] = 0x29, /* extended boot signature */ | |
| 140 | + | [39] = 0x12, 0x34, 0x56, 0x78, | |
| 141 | + | [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ', | |
| 142 | + | [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ', | |
| 143 | + | [510] = 0x55, 0xaa, | |
| 144 | + | }; | |
| 145 | + | unsigned char fat[4096] = { 0xf8, 0xff, 0xff }; | |
| 146 | + | struct stat st; | |
| 147 | + | ||
| 148 | + | if (pwrite(fd, sector, sizeof(sector), 0) != sizeof(sector)) | |
| 149 | + | return -1; | |
| 150 | + | if (pwrite(fd, fat, sizeof(fat), 1 * 4096) != sizeof(fat) || | |
| 151 | + | pwrite(fd, fat, sizeof(fat), (1 + fat_sectors) * 4096) != sizeof(fat)) | |
| 152 | + | return -1; | |
| 153 | + | if (fstat(fd, &st) || S_ISBLK(st.st_mode)) | |
| 154 | + | return 0; | |
| 155 | + | return ftruncate(fd, (off_t)sectors * 4096); | |
| 156 | + | } | |
| 157 | + | ||
| 158 | + | #define MINIX_BLOCK 1024 | |
| 159 | + | #define MINIX_BLOCKS 4096 /* a 4 MiB image */ | |
| 160 | + | #define MINIX_INODES 512 | |
| 161 | + | #define MINIX_ITABLE (MINIX_INODES * 32 / MINIX_BLOCK) | |
| 162 | + | #define MINIX_FIRSTDATA (2 + 1 + 1 + MINIX_ITABLE) /* boot, super, imap, zmap, inodes */ | |
| 163 | + | ||
| 164 | + | /* | |
| 165 | + | * A blank minix v1 image, for the holders that need a FIFO or a device | |
| 166 | + | * node on the dying mount, which vfat can't hold. Superblock in block 1, | |
| 167 | + | * one block each for the inode and zone bitmaps, the inode table, and | |
| 168 | + | * the root directory in the first data zone. | |
| 169 | + | */ | |
| 170 | + | static int write_minix(int fd) | |
| 171 | + | { | |
| 172 | + | struct { | |
| 173 | + | __u16 s_ninodes, s_nzones, s_imap_blocks, s_zmap_blocks; | |
| 174 | + | __u16 s_firstdatazone, s_log_zone_size; | |
| 175 | + | __u32 s_max_size; | |
| 176 | + | __u16 s_magic, s_state; | |
| 177 | + | } sb = { | |
| 178 | + | .s_ninodes = MINIX_INODES, | |
| 179 | + | .s_nzones = MINIX_BLOCKS, | |
| 180 | + | .s_imap_blocks = 1, | |
| 181 | + | .s_zmap_blocks = 1, | |
| 182 | + | .s_firstdatazone = MINIX_FIRSTDATA, | |
| 183 | + | .s_max_size = (7 + 512 + 512 * 512) * MINIX_BLOCK, | |
| 184 | + | .s_magic = MINIX_SUPER_MAGIC, | |
| 185 | + | .s_state = 1, /* MINIX_VALID_FS */ | |
| 186 | + | }; | |
| 187 | + | struct { | |
| 188 | + | __u16 i_mode, i_uid; | |
| 189 | + | __u32 i_size, i_time; | |
| 190 | + | __u8 i_gid, i_nlinks; | |
| 191 | + | __u16 i_zone[9]; | |
| 192 | + | } root = { | |
| 193 | + | .i_mode = S_IFDIR | 0755, | |
| 194 | + | .i_size = 2 * 16, | |
| 195 | + | .i_nlinks = 2, | |
| 196 | + | .i_zone = { MINIX_FIRSTDATA }, | |
| 197 | + | }; | |
| 198 | + | unsigned char imap[MINIX_BLOCK], zmap[MINIX_BLOCK], dir[MINIX_BLOCK] = {}; | |
| 199 | + | int i; | |
| 200 | + | ||
| 201 | + | /* bit 0 is reserved in both maps, the root inode and its zone are in use */ | |
| 202 | + | memset(imap, 0xff, sizeof(imap)); | |
| 203 | + | for (i = 2; i <= MINIX_INODES; i++) | |
| 204 | + | imap[i / 8] &= ~(1 << (i % 8)); | |
| 205 | + | memset(zmap, 0xff, sizeof(zmap)); | |
| 206 | + | for (i = 2; i <= MINIX_BLOCKS - MINIX_FIRSTDATA; i++) | |
| 207 | + | zmap[i / 8] &= ~(1 << (i % 8)); | |
| 208 | + | dir[0] = 1; | |
| 209 | + | dir[2] = '.'; | |
| 210 | + | dir[16] = 1; | |
| 211 | + | dir[18] = '.'; | |
| 212 | + | dir[19] = '.'; | |
| 213 | + | ||
| 214 | + | if (pwrite(fd, &sb, sizeof(sb), 1 * MINIX_BLOCK) != sizeof(sb) || | |
| 215 | + | pwrite(fd, imap, sizeof(imap), 2 * MINIX_BLOCK) != sizeof(imap) || | |
| 216 | + | pwrite(fd, zmap, sizeof(zmap), 3 * MINIX_BLOCK) != sizeof(zmap) || | |
| 217 | + | pwrite(fd, &root, sizeof(root), 4 * MINIX_BLOCK) != sizeof(root) || | |
| 218 | + | pwrite(fd, dir, sizeof(dir), MINIX_FIRSTDATA * MINIX_BLOCK) != sizeof(dir)) | |
| 219 | + | return -1; | |
| 220 | + | return ftruncate(fd, (off_t)MINIX_BLOCKS * MINIX_BLOCK); | |
| 221 | + | } | |
| 222 | + | ||
| 223 | + | static int read_sysfs(const char *path, char *buf, size_t size) | |
| 224 | + | { | |
| 225 | + | ssize_t n; | |
| 226 | + | int fd; | |
| 227 | + | ||
| 228 | + | fd = open(path, O_RDONLY); | |
| 229 | + | if (fd < 0) | |
| 230 | + | return -1; | |
| 231 | + | n = read(fd, buf, size - 1); | |
| 232 | + | close(fd); | |
| 233 | + | if (n < 0) | |
| 234 | + | return -1; | |
| 235 | + | buf[n] = '\0'; | |
| 236 | + | return 0; | |
| 237 | + | } | |
| 238 | + | ||
| 239 | + | /* Is @dev the mount source of this line of mountinfo? loop1 is not loop10. */ | |
| 240 | + | static bool line_has_source(const char *line, const char *dev) | |
| 241 | + | { | |
| 242 | + | const char *sep, *src, *end; | |
| 243 | + | ||
| 244 | + | sep = strstr(line, " - "); | |
| 245 | + | if (!sep) | |
| 246 | + | return false; | |
| 247 | + | src = strchr(sep + 3, ' '); /* skip the filesystem type */ | |
| 248 | + | if (!src) | |
| 249 | + | return false; | |
| 250 | + | src++; | |
| 251 | + | end = strchr(src, ' '); | |
| 252 | + | if (!end) | |
| 253 | + | return false; | |
| 254 | + | return (size_t)(end - src) == strlen(dev) && !strncmp(src, dev, end - src); | |
| 255 | + | } | |
| 256 | + | ||
| 257 | + | /* | |
| 258 | + | * Does a mount namespace of a process that /proc shows have a mount of @dev? | |
| 259 | + | * The mounts under test are in no namespace at this point on any kernel, so | |
| 260 | + | * this only checks that the test got as far as it thinks. | |
| 261 | + | */ | |
| 262 | + | static bool mounted_anywhere(const char *dev) | |
| 263 | + | { | |
| 264 | + | char path[PATH_MAX], line[4096]; | |
| 265 | + | struct dirent *de; | |
| 266 | + | bool found = false; | |
| 267 | + | DIR *proc; | |
| 268 | + | FILE *f; | |
| 269 | + | ||
| 270 | + | proc = opendir("/proc"); | |
| 271 | + | if (!proc) | |
| 272 | + | return false; | |
| 273 | + | while (!found && (de = readdir(proc))) { | |
| 274 | + | if (de->d_name[0] < '0' || de->d_name[0] > '9') | |
| 275 | + | continue; | |
| 276 | + | snprintf(path, sizeof(path), "/proc/%s/mountinfo", de->d_name); | |
| 277 | + | f = fopen(path, "re"); | |
| 278 | + | if (!f) | |
| 279 | + | continue; | |
| 280 | + | while (fgets(line, sizeof(line), f)) { | |
| 281 | + | if (line_has_source(line, dev)) { | |
| 282 | + | found = true; | |
| 283 | + | break; | |
| 284 | + | } | |
| 285 | + | } | |
| 286 | + | fclose(f); | |
| 287 | + | } | |
| 288 | + | closedir(proc); | |
| 289 | + | return found; | |
| 290 | + | } | |
| 291 | + | ||
| 292 | + | /* Wait up to @ms milliseconds for the loop device to give up its backing file. */ | |
| 293 | + | static bool loop_released(const char *sysfs, int ms) | |
| 294 | + | { | |
| 295 | + | char buf[PATH_MAX]; | |
| 296 | + | ||
| 297 | + | for (; ms > 0; ms -= 100) { | |
| 298 | + | if (read_sysfs(sysfs, buf, sizeof(buf)) < 0) | |
| 299 | + | return errno == ENOENT; | |
| 300 | + | usleep(100000); | |
| 301 | + | } | |
| 302 | + | return read_sysfs(sysfs, buf, sizeof(buf)) < 0 && errno == ENOENT; | |
| 303 | + | } | |
| 304 | + | ||
| 305 | + | /* Tell the loop device to give its file up, now or when its last user is gone. */ | |
| 306 | + | static void loop_clear(int n) | |
| 307 | + | { | |
| 308 | + | char dev[32]; | |
| 309 | + | int lfd; | |
| 310 | + | ||
| 311 | + | if (n < 0) | |
| 312 | + | return; | |
| 313 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 314 | + | lfd = open(dev, O_RDWR); | |
| 315 | + | if (lfd < 0) | |
| 316 | + | return; | |
| 317 | + | ioctl(lfd, LOOP_CLR_FD); | |
| 318 | + | close(lfd); | |
| 319 | + | } | |
| 320 | + | ||
| 321 | + | FIXTURE(loop_cycle) { | |
| 322 | + | char dev[32]; /* the loop device the child set up */ | |
| 323 | + | char sysfs[64]; /* its backing_file attribute */ | |
| 324 | + | int loops[MAX_LOOPS]; /* every loop device the case has bound */ | |
| 325 | + | int nr_loops; | |
| 326 | + | bool gadget; /* the gadget's configfs directory exists */ | |
| 327 | + | }; | |
| 328 | + | ||
| 329 | + | static void remember_loop(FIXTURE_DATA(loop_cycle) *self, int n) | |
| 330 | + | { | |
| 331 | + | if (n >= 0 && self->nr_loops < MAX_LOOPS) | |
| 332 | + | self->loops[self->nr_loops++] = n; | |
| 333 | + | } | |
| 334 | + | ||
| 335 | + | FIXTURE_SETUP(loop_cycle) | |
| 336 | + | { | |
| 337 | + | if (geteuid() != 0) | |
| 338 | + | SKIP(return, "test requires CAP_SYS_ADMIN"); | |
| 339 | + | if (access("/dev/loop-control", R_OK | W_OK)) | |
| 340 | + | SKIP(return, "test requires loop devices"); | |
| 341 | + | ||
| 342 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 343 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 344 | + | ||
| 345 | + | snprintf(base, sizeof(base), "/tmp/loop_cycle.XXXXXX"); | |
| 346 | + | ASSERT_NE(mkdtemp(base), NULL); | |
| 347 | + | /* a failed assertion in the setup does not run the teardown */ | |
| 348 | + | ASSERT_EQ(mount("tmpfs", base, "tmpfs", 0, NULL), 0) | |
| 349 | + | rmdir(base); | |
| 350 | + | snprintf(gadget, sizeof(gadget), | |
| 351 | + | "/sys/kernel/config/usb_gadget/kselftest_cycle_%d", getpid()); | |
| 352 | + | self->dev[0] = '\0'; | |
| 353 | + | self->nr_loops = 0; | |
| 354 | + | self->gadget = false; | |
| 355 | + | } | |
| 356 | + | ||
| 357 | + | static int mount_configfs(void); | |
| 358 | + | static void gadget_remove(void); | |
| 359 | + | ||
| 360 | + | FIXTURE_TEARDOWN(loop_cycle) | |
| 361 | + | { | |
| 362 | + | if (self->gadget) | |
| 363 | + | gadget_remove(); | |
| 364 | + | /* whatever a failed assertion has left bound */ | |
| 365 | + | for (int i = 0; i < self->nr_loops; i++) | |
| 366 | + | loop_clear(self->loops[i]); | |
| 367 | + | umount2(base, MNT_DETACH); | |
| 368 | + | rmdir(base); | |
| 369 | + | } | |
| 370 | + | ||
| 371 | + | /* Child exit codes. */ | |
| 372 | + | enum { | |
| 373 | + | CHILD_OK, | |
| 374 | + | CHILD_NS, /* could not set up the namespace or the tmpfs */ | |
| 375 | + | CHILD_IMAGE, /* could not write the image */ | |
| 376 | + | CHILD_LOOP, /* could not set up the loop device */ | |
| 377 | + | CHILD_MOUNT, /* could not mount it (vfat and msdos both refused) */ | |
| 378 | + | CHILD_PIPE, /* the parent went away */ | |
| 379 | + | CHILD_HOLDER, /* could not set the holder up below the mount */ | |
| 380 | + | CHILD_SKIP, /* the kernel lacks what the holder needs */ | |
| 381 | + | CHILD_NOFS, /* the kernel lacks the filesystem of the image */ | |
| 382 | + | }; | |
| 383 | + | ||
| 384 | + | /* Bind the loop device that LOOP_CTL_GET_FREE names to @ifd; the device number. */ | |
| 385 | + | static int loop_bind_free(int ifd) | |
| 386 | + | { | |
| 387 | + | int cfd, lfd, n; | |
| 388 | + | char dev[32]; | |
| 389 | + | ||
| 390 | + | cfd = open("/dev/loop-control", O_RDWR); | |
| 391 | + | if (cfd < 0) | |
| 392 | + | return -1; | |
| 393 | + | n = ioctl(cfd, LOOP_CTL_GET_FREE); | |
| 394 | + | close(cfd); | |
| 395 | + | if (n < 0) | |
| 396 | + | return -1; | |
| 397 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 398 | + | lfd = open(dev, O_RDWR); | |
| 399 | + | if (lfd < 0) | |
| 400 | + | return -1; | |
| 401 | + | if (ioctl(lfd, LOOP_SET_FD, ifd)) | |
| 402 | + | n = -1; | |
| 403 | + | close(lfd); | |
| 404 | + | return n; | |
| 405 | + | } | |
| 406 | + | ||
| 407 | + | /* | |
| 408 | + | * Bind a free loop device to the open image @ifd; the device number. The | |
| 409 | + | * device is free when LOOP_CTL_GET_FREE names it and may be somebody else's | |
| 410 | + | * a moment later, so try again when it is busy. | |
| 411 | + | */ | |
| 412 | + | static int loop_bind(int ifd) | |
| 413 | + | { | |
| 414 | + | int n = -1; | |
| 415 | + | ||
| 416 | + | for (int i = 0; i < 64 && n < 0; i++) { | |
| 417 | + | n = loop_bind_free(ifd); | |
| 418 | + | if (n < 0 && errno != EBUSY) | |
| 419 | + | return -1; | |
| 420 | + | } | |
| 421 | + | if (n >= 0 && nr_bound < MAX_LOOPS) | |
| 422 | + | bound[nr_bound++] = n; | |
| 423 | + | return n; | |
| 424 | + | } | |
| 425 | + | ||
| 426 | + | /* Mount a FAT image, as vfat or as msdos; -1 with ENODEV if the kernel has neither. */ | |
| 427 | + | static int mount_fat(const char *dev, const char *mp) | |
| 428 | + | { | |
| 429 | + | int err; | |
| 430 | + | ||
| 431 | + | if (!mount(dev, mp, "vfat", 0, NULL)) | |
| 432 | + | return 0; | |
| 433 | + | err = errno; | |
| 434 | + | if (!mount(dev, mp, "msdos", 0, NULL)) | |
| 435 | + | return 0; | |
| 436 | + | if (err != ENODEV) | |
| 437 | + | errno = err; | |
| 438 | + | return -1; | |
| 439 | + | } | |
| 440 | + | ||
| 441 | + | /* | |
| 442 | + | * A child that gives up has to take down what it has set up: nobody else | |
| 443 | + | * knows about it. Unmount, then tell the loop devices to let go. The mounts | |
| 444 | + | * are released after this process is gone and the devices follow them. | |
| 445 | + | */ | |
| 446 | + | static int child_fails(int ret) | |
| 447 | + | { | |
| 448 | + | umount2(at("vol"), MNT_DETACH); | |
| 449 | + | umount2(at("vol2"), MNT_DETACH); | |
| 450 | + | umount2(at("p"), MNT_DETACH); | |
| 451 | + | umount2(at("img"), MNT_DETACH); | |
| 452 | + | for (int i = 0; i < nr_bound; i++) | |
| 453 | + | loop_clear(bound[i]); | |
| 454 | + | return ret; | |
| 455 | + | } | |
| 456 | + | ||
| 457 | + | /* Write an image to @img, bind a loop device to it and mount that at @mp; the device number. */ | |
| 458 | + | static int loop_mount(const char *img, const char *mp) | |
| 459 | + | { | |
| 460 | + | char dev[32]; | |
| 461 | + | int ifd, n; | |
| 462 | + | ||
| 463 | + | ifd = open(img, O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 464 | + | if (ifd < 0 || write_fat12(ifd)) | |
| 465 | + | return -CHILD_IMAGE; | |
| 466 | + | n = loop_bind(ifd); | |
| 467 | + | close(ifd); /* the loop device holds the file from now on */ | |
| 468 | + | if (n < 0) | |
| 469 | + | return -CHILD_LOOP; | |
| 470 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 471 | + | if (mkdir(mp, 0755)) | |
| 472 | + | return -CHILD_MOUNT; | |
| 473 | + | if (mount_fat(dev, mp)) | |
| 474 | + | return errno == ENODEV ? -CHILD_NOFS : -CHILD_MOUNT; | |
| 475 | + | return n; | |
| 476 | + | } | |
| 477 | + | ||
| 478 | + | /* | |
| 479 | + | * Two tmpfs mounts, each carrying the image of the loop mount below the | |
| 480 | + | * other: the loop mount below vol has its image on vol2 and the other way | |
| 481 | + | * round. | |
| 482 | + | */ | |
| 483 | + | static int crossed_child(int to_parent, int from_parent) | |
| 484 | + | { | |
| 485 | + | struct report r; | |
| 486 | + | char c; | |
| 487 | + | ||
| 488 | + | if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL)) | |
| 489 | + | return CHILD_NS; | |
| 490 | + | if (mkdir(at("vol"), 0755) || mount("tmpfs", at("vol"), "tmpfs", 0, NULL) || | |
| 491 | + | mkdir(at("vol2"), 0755) || mount("tmpfs", at("vol2"), "tmpfs", 0, NULL)) | |
| 492 | + | return child_fails(CHILD_NS); | |
| 493 | + | r.n[0] = loop_mount(at("vol2/img"), at("vol/mnt")); | |
| 494 | + | if (r.n[0] < 0) | |
| 495 | + | return child_fails(-r.n[0]); | |
| 496 | + | r.n[1] = loop_mount(at("vol/img"), at("vol2/mnt")); | |
| 497 | + | if (r.n[1] < 0) | |
| 498 | + | return child_fails(-r.n[1]); | |
| 499 | + | if (write(to_parent, &r, sizeof(r)) != sizeof(r)) | |
| 500 | + | return child_fails(CHILD_PIPE); | |
| 501 | + | if (read(from_parent, &c, 1) != 1) | |
| 502 | + | return child_fails(CHILD_PIPE); | |
| 503 | + | return CHILD_OK; | |
| 504 | + | } | |
| 505 | + | ||
| 506 | + | /* | |
| 507 | + | * In its own mount namespace the child mounts a tmpfs on vol, | |
| 508 | + | * puts a filesystem image on it, binds a loop device to the image and | |
| 509 | + | * mounts that loop device below. The loop device's backing file is a | |
| 510 | + | * reference on the mount the image is on, held by the loop device, held | |
| 511 | + | * by the mounted filesystem, held by the mount below. | |
| 512 | + | */ | |
| 513 | + | static int loop_child(int to_parent, int from_parent) | |
| 514 | + | { | |
| 515 | + | struct report r = { { -1, -1 } }; | |
| 516 | + | char c; | |
| 517 | + | ||
| 518 | + | if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL)) | |
| 519 | + | return CHILD_NS; | |
| 520 | + | if (mkdir(at("vol"), 0755) || mount("tmpfs", at("vol"), "tmpfs", 0, NULL)) | |
| 521 | + | return child_fails(CHILD_NS); | |
| 522 | + | r.n[0] = loop_mount(at("vol/img"), at("vol/mnt")); | |
| 523 | + | if (r.n[0] < 0) | |
| 524 | + | return child_fails(-r.n[0]); | |
| 525 | + | ||
| 526 | + | if (write(to_parent, &r, sizeof(r)) != sizeof(r)) | |
| 527 | + | return child_fails(CHILD_PIPE); | |
| 528 | + | /* keep the namespace alive while the parent removes the directory */ | |
| 529 | + | if (read(from_parent, &c, 1) != 1) | |
| 530 | + | return child_fails(CHILD_PIPE); | |
| 531 | + | return CHILD_OK; | |
| 532 | + | } | |
| 533 | + | ||
| 534 | + | /* | |
| 535 | + | * The child did not report. Skip if the kernel lacks something, fail with | |
| 536 | + | * what the child said otherwise. A child that a signal killed has failed. | |
| 537 | + | */ | |
| 538 | + | #define CHILD_GAVE_UP(pid) do { \ | |
| 539 | + | int __status; \ | |
| 540 | + | \ | |
| 541 | + | ASSERT_EQ(waitpid(pid, &__status, 0), pid); \ | |
| 542 | + | if (WIFEXITED(__status) && WEXITSTATUS(__status) == CHILD_NOFS) \ | |
| 543 | + | SKIP(return, "test requires the filesystem of the image (FAT or minix)"); \ | |
| 544 | + | if (WIFEXITED(__status) && WEXITSTATUS(__status) == CHILD_SKIP) \ | |
| 545 | + | SKIP(return, "the kernel lacks what this holder needs"); \ | |
| 546 | + | ASSERT_TRUE(false) \ | |
| 547 | + | TH_LOG("child failed to set up: %s %d", \ | |
| 548 | + | WIFEXITED(__status) ? "exit status" : "signal", \ | |
| 549 | + | WIFEXITED(__status) ? WEXITSTATUS(__status) : WTERMSIG(__status)); \ | |
| 550 | + | } while (0) | |
| 551 | + | ||
| 552 | + | /* The child has to leave by itself and with nothing to complain about. */ | |
| 553 | + | #define CHILD_LEFT(pid) do { \ | |
| 554 | + | int __status; \ | |
| 555 | + | \ | |
| 556 | + | ASSERT_EQ(waitpid(pid, &__status, 0), pid); \ | |
| 557 | + | ASSERT_TRUE(WIFEXITED(__status)); \ | |
| 558 | + | ASSERT_EQ(WEXITSTATUS(__status), CHILD_OK); \ | |
| 559 | + | } while (0) | |
| 560 | + | ||
| 561 | + | /* | |
| 562 | + | * An exclusive open of the device fails while a filesystem holds it, and | |
| 563 | + | * the only filesystem that ever did is the one mounted below the dead | |
| 564 | + | * mount. Give a release in flight a moment. Then the device must clear | |
| 565 | + | * right away rather than only be marked for autoclear. | |
| 566 | + | */ | |
| 567 | + | static void assert_loop_released(struct __test_metadata *_metadata, | |
| 568 | + | FIXTURE_DATA(loop_cycle) *self) | |
| 569 | + | { | |
| 570 | + | int lfd; | |
| 571 | + | ||
| 572 | + | for (int i = 0; i < 20; i++) { | |
| 573 | + | lfd = open(self->dev, O_RDONLY | O_EXCL); | |
| 574 | + | if (lfd >= 0) | |
| 575 | + | break; | |
| 576 | + | usleep(100000); | |
| 577 | + | } | |
| 578 | + | EXPECT_GE(lfd, 0) | |
| 579 | + | TH_LOG("%s is still held by the loop mount below the dead mount: nothing refers to either mount and nothing can release them", | |
| 580 | + | self->dev); | |
| 581 | + | if (lfd >= 0) | |
| 582 | + | close(lfd); | |
| 583 | + | ||
| 584 | + | lfd = open(self->dev, O_RDWR); | |
| 585 | + | ASSERT_GE(lfd, 0); | |
| 586 | + | ASSERT_EQ(ioctl(lfd, LOOP_CLR_FD), 0); | |
| 587 | + | close(lfd); | |
| 588 | + | ASSERT_TRUE(loop_released(self->sysfs, 5000)) | |
| 589 | + | TH_LOG("%s kept its backing file after LOOP_CLR_FD: the filesystem on it is still mounted somewhere nobody can reach", | |
| 590 | + | self->dev); | |
| 591 | + | /* somebody else may bind it from now on, so the teardown leaves it alone */ | |
| 592 | + | for (int i = 0; i < self->nr_loops; i++) { | |
| 593 | + | char dev[32]; | |
| 594 | + | ||
| 595 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", self->loops[i]); | |
| 596 | + | if (!strcmp(dev, self->dev)) | |
| 597 | + | self->loops[i] = -1; | |
| 598 | + | } | |
| 599 | + | } | |
| 600 | + | ||
| 601 | + | /* | |
| 602 | + | * rmdir of vol from here, where it is not a mountpoint, detaches | |
| 603 | + | * the child's tmpfs with the loop mount connected below it. Once the child | |
| 604 | + | * is gone nothing refers to either mount. The loop device must then be | |
| 605 | + | * free to give up its backing file, which only happens when the mounted | |
| 606 | + | * filesystem below the detached tmpfs has been released. | |
| 607 | + | */ | |
| 608 | + | TEST_F(loop_cycle, detached_loop_mount_released) | |
| 609 | + | { | |
| 610 | + | int to_parent[2], to_child[2]; | |
| 611 | + | struct report r = { { -1, -1 } }; | |
| 612 | + | char buf[PATH_MAX]; | |
| 613 | + | pid_t pid; | |
| 614 | + | ||
| 615 | + | ASSERT_EQ(pipe(to_parent), 0); | |
| 616 | + | ASSERT_EQ(pipe(to_child), 0); | |
| 617 | + | ||
| 618 | + | pid = fork(); | |
| 619 | + | ASSERT_GE(pid, 0); | |
| 620 | + | if (pid == 0) { | |
| 621 | + | close(to_parent[0]); | |
| 622 | + | close(to_child[1]); | |
| 623 | + | _exit(loop_child(to_parent[1], to_child[0])); | |
| 624 | + | } | |
| 625 | + | close(to_parent[1]); | |
| 626 | + | close(to_child[0]); | |
| 627 | + | ||
| 628 | + | if (read(to_parent[0], &r, sizeof(r)) != sizeof(r)) | |
| 629 | + | CHILD_GAVE_UP(pid); | |
| 630 | + | remember_loop(self, r.n[0]); | |
| 631 | + | snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", r.n[0]); | |
| 632 | + | snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", r.n[0]); | |
| 633 | + | ASSERT_EQ(read_sysfs(self->sysfs, buf, sizeof(buf)), 0); | |
| 634 | + | ASSERT_NE(strstr(buf, "/vol/img"), NULL); | |
| 635 | + | ||
| 636 | + | /* not a mountpoint in this namespace, so the directory can go */ | |
| 637 | + | ASSERT_EQ(rmdir(at("vol")), 0); | |
| 638 | + | ||
| 639 | + | /* the child leaves: its namespace and every reference it held are gone */ | |
| 640 | + | ASSERT_EQ(write(to_child[1], "", 1), 1); | |
| 641 | + | CHILD_LEFT(pid); | |
| 642 | + | close(to_parent[0]); | |
| 643 | + | close(to_child[1]); | |
| 644 | + | ||
| 645 | + | /* nothing can reach the two mounts any more */ | |
| 646 | + | ASSERT_EQ(access(at("vol"), F_OK), -1); | |
| 647 | + | ASSERT_FALSE(mounted_anywhere(self->dev)); | |
| 648 | + | ||
| 649 | + | assert_loop_released(_metadata, self); | |
| 650 | + | } | |
| 651 | + | ||
| 652 | + | /* | |
| 653 | + | * The same two mounts in a detached tree: a clone of vol from | |
| 654 | + | * open_tree(), the image opened through the clone so that the loop device | |
| 655 | + | * holds the clone, and the loop mount moved below the clone. The last | |
| 656 | + | * close of the tree's fd dissolves the tree with the loop mount left | |
| 657 | + | * connected below the dead clone, and nothing refers to either afterwards. | |
| 658 | + | */ | |
| 659 | + | TEST_F(loop_cycle, dissolved_tree_loop_mount_released) | |
| 660 | + | { | |
| 661 | + | int tfd, ifd, fsfd, mfd, n; | |
| 662 | + | char buf[PATH_MAX]; | |
| 663 | + | ||
| 664 | + | fsfd = sys_fsopen("vfat", 0); | |
| 665 | + | if (fsfd < 0) | |
| 666 | + | fsfd = sys_fsopen("msdos", 0); | |
| 667 | + | if (fsfd < 0) | |
| 668 | + | SKIP(return, "test requires a FAT filesystem"); | |
| 669 | + | ||
| 670 | + | ASSERT_EQ(mkdir(at("vol"), 0755), 0); | |
| 671 | + | ASSERT_EQ(mount("tmpfs", at("vol"), "tmpfs", 0, NULL), 0); | |
| 672 | + | tfd = sys_open_tree(AT_FDCWD, at("vol"), OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 673 | + | ASSERT_GE(tfd, 0); | |
| 674 | + | ||
| 675 | + | /* the image, opened through the clone: the loop device holds the clone */ | |
| 676 | + | ifd = openat(tfd, "img", O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 677 | + | ASSERT_GE(ifd, 0); | |
| 678 | + | ASSERT_EQ(write_fat12(ifd), 0); | |
| 679 | + | n = loop_bind(ifd); | |
| 680 | + | close(ifd); | |
| 681 | + | ASSERT_GE(n, 0); | |
| 682 | + | remember_loop(self, n); | |
| 683 | + | snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", n); | |
| 684 | + | snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", n); | |
| 685 | + | ||
| 686 | + | /* the loop mount, moved below the clone */ | |
| 687 | + | ASSERT_EQ(mkdirat(tfd, "mnt", 0755), 0); | |
| 688 | + | ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "source", self->dev, 0), 0); | |
| 689 | + | ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0); | |
| 690 | + | mfd = sys_fsmount(fsfd, 0, 0); | |
| 691 | + | ASSERT_GE(mfd, 0); | |
| 692 | + | close(fsfd); | |
| 693 | + | ASSERT_EQ(sys_move_mount(mfd, "", tfd, "mnt", MOVE_MOUNT_F_EMPTY_PATH), 0); | |
| 694 | + | close(mfd); | |
| 695 | + | ||
| 696 | + | ASSERT_EQ(read_sysfs(self->sysfs, buf, sizeof(buf)), 0); | |
| 697 | + | ASSERT_NE(strstr(buf, "img"), NULL); | |
| 698 | + | ||
| 699 | + | /* the last fd of the tree: both mounts die, the loop mount connected */ | |
| 700 | + | close(tfd); | |
| 701 | + | ||
| 702 | + | /* nothing can reach the two mounts any more */ | |
| 703 | + | ASSERT_FALSE(mounted_anywhere(self->dev)); | |
| 704 | + | ||
| 705 | + | assert_loop_released(_metadata, self); | |
| 706 | + | } | |
| 707 | + | ||
| 708 | + | /* | |
| 709 | + | * The cycle in two steps: rmdir of vol leaves the loop mount below it | |
| 710 | + | * connected while its image's mount, vol2, is alive; then rmdir of vol2 | |
| 711 | + | * takes that one with the loop mount whose image is on the dead vol. Each | |
| 712 | + | * dead mount now owns a loop mount whose filesystem pins the other. | |
| 713 | + | */ | |
| 714 | + | TEST_F(loop_cycle, crossed_images_released) | |
| 715 | + | { | |
| 716 | + | int to_parent[2], to_child[2]; | |
| 717 | + | struct report r = { { -1, -1 } }; | |
| 718 | + | char sysfs[2][64], dev[2][32]; | |
| 719 | + | pid_t pid; | |
| 720 | + | ||
| 721 | + | ASSERT_EQ(pipe(to_parent), 0); | |
| 722 | + | ASSERT_EQ(pipe(to_child), 0); | |
| 723 | + | ||
| 724 | + | pid = fork(); | |
| 725 | + | ASSERT_GE(pid, 0); | |
| 726 | + | if (pid == 0) { | |
| 727 | + | close(to_parent[0]); | |
| 728 | + | close(to_child[1]); | |
| 729 | + | _exit(crossed_child(to_parent[1], to_child[0])); | |
| 730 | + | } | |
| 731 | + | close(to_parent[1]); | |
| 732 | + | close(to_child[0]); | |
| 733 | + | ||
| 734 | + | if (read(to_parent[0], &r, sizeof(r)) != sizeof(r)) | |
| 735 | + | CHILD_GAVE_UP(pid); | |
| 736 | + | for (int i = 0; i < 2; i++) { | |
| 737 | + | remember_loop(self, r.n[i]); | |
| 738 | + | snprintf(dev[i], sizeof(dev[i]), "/dev/loop%d", r.n[i]); | |
| 739 | + | snprintf(sysfs[i], sizeof(sysfs[i]), "/sys/block/loop%d/loop/backing_file", r.n[i]); | |
| 740 | + | } | |
| 741 | + | ||
| 742 | + | /* step one: the mount with the first loop mount below it goes */ | |
| 743 | + | ASSERT_EQ(rmdir(at("vol")), 0); | |
| 744 | + | ||
| 745 | + | /* step two: the other one, with the loop mount whose image is on the first */ | |
| 746 | + | ASSERT_EQ(rmdir(at("vol2")), 0); | |
| 747 | + | ||
| 748 | + | /* the child leaves: its namespace and every reference it held are gone */ | |
| 749 | + | ASSERT_EQ(write(to_child[1], "", 1), 1); | |
| 750 | + | CHILD_LEFT(pid); | |
| 751 | + | close(to_parent[0]); | |
| 752 | + | close(to_child[1]); | |
| 753 | + | ||
| 754 | + | /* nothing can reach the four mounts any more */ | |
| 755 | + | for (int i = 0; i < 2; i++) { | |
| 756 | + | ASSERT_FALSE(mounted_anywhere(dev[i])); | |
| 757 | + | strcpy(self->dev, dev[i]); | |
| 758 | + | strcpy(self->sysfs, sysfs[i]); | |
| 759 | + | assert_loop_released(_metadata, self); | |
| 760 | + | } | |
| 761 | + | } | |
| 762 | + | ||
| 763 | + | /* | |
| 764 | + | * The holders. Each keeps a file or a path on a mount P for as long as | |
| 765 | + | * its own filesystem or device lives, and each has that filesystem or | |
| 766 | + | * device mounted at C below P. Once another namespace's rmdir has | |
| 767 | + | * detached P with C connected below it and the child is gone, P is owned | |
| 768 | + | * by nobody, C by P, and P is kept by whatever the holder still holds. | |
| 769 | + | * | |
| 770 | + | * P is a loop mount so that its death can be observed: the loop device | |
| 771 | + | * gives its backing file up when P's superblock goes. The image sits on | |
| 772 | + | * a tmpfs next to P, not above it, so the loop device's own reference is | |
| 773 | + | * not part of the picture. | |
| 774 | + | */ | |
| 775 | + | enum holder { | |
| 776 | + | HOLDER_AUTOFS, /* a FIFO on P as the daemon's pipe */ | |
| 777 | + | HOLDER_ZRAM, /* a device node on P as the writeback device */ | |
| 778 | + | HOLDER_ECRYPTFS, /* a directory on P as the lower directory */ | |
| 779 | + | HOLDER_BINFMT_MISC, /* an executable on P as an 'F' interpreter */ | |
| 780 | + | HOLDER_FUSE, /* a file on P as a passthrough backing file */ | |
| 781 | + | HOLDER_ZLOOP, /* a directory on P for the zone files */ | |
| 782 | + | HOLDER_GADGET, /* a file on P as a mass storage LUN, over dummy_hcd */ | |
| 783 | + | HOLDER_MD, /* a file on P as an array's bitmap file */ | |
| 784 | + | }; | |
| 785 | + | ||
| 786 | + | #define HOLDER_IMG at("img/p.img") | |
| 787 | + | #define HOLDER_MNT at("p") | |
| 788 | + | #define HOLDER_BELOW at("p/c") | |
| 789 | + | ||
| 790 | + | static int write_file(const char *path, const char *s) | |
| 791 | + | { | |
| 792 | + | int fd = open(path, O_WRONLY); | |
| 793 | + | ssize_t n; | |
| 794 | + | ||
| 795 | + | if (fd < 0) | |
| 796 | + | return -1; | |
| 797 | + | n = write(fd, s, strlen(s)); | |
| 798 | + | close(fd); | |
| 799 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 800 | + | } | |
| 801 | + | ||
| 802 | + | /* Bind a free loop device to @img; the device number. */ | |
| 803 | + | static int loop_attach(const char *img) | |
| 804 | + | { | |
| 805 | + | int ifd, n; | |
| 806 | + | ||
| 807 | + | ifd = open(img, O_RDWR); | |
| 808 | + | if (ifd < 0) | |
| 809 | + | return -1; | |
| 810 | + | n = loop_bind(ifd); | |
| 811 | + | close(ifd); | |
| 812 | + | return n; | |
| 813 | + | } | |
| 814 | + | ||
| 815 | + | static int holder_autofs(void) | |
| 816 | + | { | |
| 817 | + | char opts[64]; | |
| 818 | + | int pfd; | |
| 819 | + | ||
| 820 | + | if (mkfifo(at("p/pipe"), 0600)) | |
| 821 | + | return CHILD_HOLDER; | |
| 822 | + | pfd = open(at("p/pipe"), O_RDWR); | |
| 823 | + | if (pfd < 0) | |
| 824 | + | return CHILD_HOLDER; | |
| 825 | + | snprintf(opts, sizeof(opts), "fd=%d,minproto=5,maxproto=5", pfd); | |
| 826 | + | if (mount("autofs", HOLDER_BELOW, "autofs", 0, opts)) | |
| 827 | + | return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER; | |
| 828 | + | close(pfd); /* the mount keeps its own */ | |
| 829 | + | return CHILD_OK; | |
| 830 | + | } | |
| 831 | + | ||
| 832 | + | /* | |
| 833 | + | * zram's writeback device has to be a block device node, and that node has | |
| 834 | + | * to be on P. Point it at a second loop device. | |
| 835 | + | */ | |
| 836 | + | static void zram_reset(void); | |
| 837 | + | ||
| 838 | + | static int holder_zram(void) | |
| 839 | + | { | |
| 840 | + | char dev[32], buf[64]; | |
| 841 | + | struct stat st; | |
| 842 | + | int fd, n; | |
| 843 | + | ||
| 844 | + | if (access("/sys/block/zram0/backing_dev", W_OK)) | |
| 845 | + | return CHILD_SKIP; | |
| 846 | + | /* somebody else's device, leave it alone */ | |
| 847 | + | if (read_sysfs("/sys/block/zram0/initstate", buf, sizeof(buf)) || buf[0] != '0') | |
| 848 | + | return CHILD_SKIP; | |
| 849 | + | fd = open(at("img/wb.img"), O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 850 | + | if (fd < 0 || ftruncate(fd, IMAGE_SIZE)) | |
| 851 | + | return CHILD_HOLDER; | |
| 852 | + | close(fd); | |
| 853 | + | n = loop_attach(at("img/wb.img")); | |
| 854 | + | if (n < 0) | |
| 855 | + | return CHILD_HOLDER; | |
| 856 | + | /* the minor is not the number of the device when loop has partitions */ | |
| 857 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 858 | + | if (stat(dev, &st) || mknod(at("p/wbdev"), S_IFBLK | 0600, st.st_rdev)) | |
| 859 | + | return CHILD_HOLDER; | |
| 860 | + | if (write_file("/sys/block/zram0/backing_dev", at("p/wbdev"))) | |
| 861 | + | return CHILD_HOLDER; | |
| 862 | + | snprintf(buf, sizeof(buf), "%d", 4 * 1024 * 1024); | |
| 863 | + | if (write_file("/sys/block/zram0/disksize", buf)) | |
| 864 | + | goto undo; | |
| 865 | + | fd = open("/dev/zram0", O_RDWR); | |
| 866 | + | if (fd < 0) | |
| 867 | + | goto undo; | |
| 868 | + | n = write_fat12_4k(fd, 1024); /* zram has 4 KiB blocks */ | |
| 869 | + | close(fd); /* the reset in undo is refused while the device is open */ | |
| 870 | + | if (n) | |
| 871 | + | goto undo; | |
| 872 | + | if (mount_fat("/dev/zram0", HOLDER_BELOW)) { | |
| 873 | + | n = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER; | |
| 874 | + | zram_reset(); | |
| 875 | + | return n; | |
| 876 | + | } | |
| 877 | + | return CHILD_OK; | |
| 878 | + | undo: | |
| 879 | + | zram_reset(); | |
| 880 | + | return CHILD_HOLDER; | |
| 881 | + | } | |
| 882 | + | ||
| 883 | + | /* Is @alg in /proc/crypto? A module is listed once a request has loaded it. */ | |
| 884 | + | static bool crypto_has(const char *alg) | |
| 885 | + | { | |
| 886 | + | char line[256], name[64]; | |
| 887 | + | bool found = false; | |
| 888 | + | FILE *f; | |
| 889 | + | ||
| 890 | + | f = fopen("/proc/crypto", "r"); | |
| 891 | + | if (!f) | |
| 892 | + | return true; /* no way to tell, assume it is */ | |
| 893 | + | while (!found && fgets(line, sizeof(line), f)) | |
| 894 | + | found = sscanf(line, "name : %63s", name) == 1 && !strcmp(name, alg); | |
| 895 | + | fclose(f); | |
| 896 | + | return found; | |
| 897 | + | } | |
| 898 | + | ||
| 899 | + | /* The kernel's auth token layout, which userspace has to match byte for byte. */ | |
| 900 | + | struct ecryptfs_auth_tok { | |
| 901 | + | __u16 version; | |
| 902 | + | __u16 token_type; | |
| 903 | + | __u32 flags; | |
| 904 | + | struct { | |
| 905 | + | __u32 flags, encrypted_key_size, decrypted_key_size; | |
| 906 | + | __u8 encrypted_key[512], decrypted_key[64]; | |
| 907 | + | } session_key; | |
| 908 | + | __u8 reserved[32]; | |
| 909 | + | struct { | |
| 910 | + | __u32 password_bytes; | |
| 911 | + | __s32 hash_algo; | |
| 912 | + | __u32 hash_iterations, session_key_encryption_key_bytes, flags; | |
| 913 | + | __u8 session_key_encryption_key[64]; | |
| 914 | + | __u8 signature[17]; | |
| 915 | + | __u8 salt[8]; | |
| 916 | + | } password; | |
| 917 | + | } __attribute__((packed)); | |
| 918 | + | ||
| 919 | + | #define ECRYPTFS_SIG "0123456789abcdef" | |
| 920 | + | ||
| 921 | + | static int holder_ecryptfs(void) | |
| 922 | + | { | |
| 923 | + | struct ecryptfs_auth_tok tok = { | |
| 924 | + | .version = 0x0004, | |
| 925 | + | .token_type = 0, /* ECRYPTFS_PASSWORD */ | |
| 926 | + | .password.session_key_encryption_key_bytes = 16, | |
| 927 | + | .password.flags = 0x02, /* ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET */ | |
| 928 | + | .password.signature = ECRYPTFS_SIG, | |
| 929 | + | }; | |
| 930 | + | ||
| 931 | + | /* a session keyring of this child's own, so that the key goes with it */ | |
| 932 | + | if (syscall(__NR_keyctl, KEYCTL_JOIN_SESSION_KEYRING, NULL) < 0) | |
| 933 | + | return errno == ENOSYS ? CHILD_SKIP : CHILD_HOLDER; | |
| 934 | + | if (syscall(__NR_add_key, "user", ECRYPTFS_SIG, &tok, sizeof(tok), | |
| 935 | + | KEY_SPEC_SESSION_KEYRING) < 0) | |
| 936 | + | return CHILD_HOLDER; | |
| 937 | + | if (mkdir(at("p/lower"), 0755)) | |
| 938 | + | return CHILD_HOLDER; | |
| 939 | + | if (mount(at("p/lower"), HOLDER_BELOW, "ecryptfs", 0, | |
| 940 | + | "ecryptfs_sig=" ECRYPTFS_SIG ",ecryptfs_cipher=aes,ecryptfs_key_bytes=16")) { | |
| 941 | + | /* EINVAL without the cipher; a module is loaded by the attempt */ | |
| 942 | + | if (errno == ENODEV || (errno == EINVAL && !crypto_has("aes"))) | |
| 943 | + | return CHILD_SKIP; | |
| 944 | + | return CHILD_HOLDER; | |
| 945 | + | } | |
| 946 | + | return CHILD_OK; | |
| 947 | + | } | |
| 948 | + | ||
| 949 | + | /* | |
| 950 | + | * binfmt_misc instances are per user namespace, so the mount below P is | |
| 951 | + | * made from a new one, which gets a copy of P. | |
| 952 | + | */ | |
| 953 | + | static int holder_binfmt_misc(void) | |
| 954 | + | { | |
| 955 | + | static const char interp[] = "#!/bin/true\n"; | |
| 956 | + | char reg[PATH_MAX]; | |
| 957 | + | int out; | |
| 958 | + | ||
| 959 | + | /* 'F' opens the interpreter at registration, nothing runs it here */ | |
| 960 | + | out = open(at("p/interp"), O_WRONLY | O_CREAT | O_EXCL, 0755); | |
| 961 | + | if (out < 0 || write(out, interp, sizeof(interp) - 1) != sizeof(interp) - 1) | |
| 962 | + | return CHILD_HOLDER; | |
| 963 | + | close(out); | |
| 964 | + | ||
| 965 | + | /* ENOSPC: user.max_user_namespaces is 0, EPERM: an LSM says no */ | |
| 966 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) { | |
| 967 | + | if (errno == EINVAL || errno == ENOSPC || errno == EPERM) | |
| 968 | + | return CHILD_SKIP; | |
| 969 | + | return CHILD_HOLDER; | |
| 970 | + | } | |
| 971 | + | if (write_file("/proc/self/setgroups", "deny") || | |
| 972 | + | write_file("/proc/self/uid_map", "0 0 1") || | |
| 973 | + | write_file("/proc/self/gid_map", "0 0 1")) | |
| 974 | + | return CHILD_HOLDER; | |
| 975 | + | if (mount("binfmt_misc", HOLDER_BELOW, "binfmt_misc", 0, NULL)) | |
| 976 | + | return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER; | |
| 977 | + | snprintf(reg, sizeof(reg), ":cycle:E::cyc::%s:F", at("p/interp")); | |
| 978 | + | if (write_file(at("p/c/register"), reg)) | |
| 979 | + | return CHILD_HOLDER; | |
| 980 | + | return CHILD_OK; | |
| 981 | + | } | |
| 982 | + | ||
| 983 | + | /* | |
| 984 | + | * A fuse server that only ever answers FUSE_INIT, with passthrough on, and | |
| 985 | + | * then registers a file on P as a backing file. The registration alone | |
| 986 | + | * makes the fuse superblock hold the file. | |
| 987 | + | */ | |
| 988 | + | static int holder_fuse(void) | |
| 989 | + | { | |
| 990 | + | struct fuse_backing_map map = {}; | |
| 991 | + | struct fuse_in_header *ih; | |
| 992 | + | struct fuse_init_out init = { | |
| 993 | + | .major = FUSE_KERNEL_VERSION, | |
| 994 | + | .minor = FUSE_KERNEL_MINOR_VERSION, | |
| 995 | + | .flags = FUSE_INIT_EXT, | |
| 996 | + | .flags2 = FUSE_PASSTHROUGH >> 32, | |
| 997 | + | .max_write = 4096, | |
| 998 | + | .max_stack_depth = 1, | |
| 999 | + | }; | |
| 1000 | + | struct fuse_out_header oh = { .len = sizeof(oh) + sizeof(init) }; | |
| 1001 | + | struct iovec iov[2] = { { &oh, sizeof(oh) }, { &init, sizeof(init) } }; | |
| 1002 | + | char opts[64], buf[8192]; | |
| 1003 | + | int ffd, bfd; | |
| 1004 | + | ssize_t n; | |
| 1005 | + | ||
| 1006 | + | bfd = open(at("p/backing"), O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 1007 | + | if (bfd < 0) | |
| 1008 | + | return CHILD_HOLDER; | |
| 1009 | + | ffd = open("/dev/fuse", O_RDWR); | |
| 1010 | + | if (ffd < 0) | |
| 1011 | + | return CHILD_SKIP; | |
| 1012 | + | snprintf(opts, sizeof(opts), "fd=%d,rootmode=40000,user_id=0,group_id=0", ffd); | |
| 1013 | + | if (mount("fuse", HOLDER_BELOW, "fuse", 0, opts)) | |
| 1014 | + | return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER; | |
| 1015 | + | ||
| 1016 | + | n = read(ffd, buf, sizeof(buf)); | |
| 1017 | + | ih = (void *)buf; | |
| 1018 | + | if (n < (ssize_t)sizeof(*ih) || ih->opcode != FUSE_INIT) | |
| 1019 | + | return CHILD_HOLDER; | |
| 1020 | + | oh.unique = ih->unique; | |
| 1021 | + | if (writev(ffd, iov, 2) != (ssize_t)oh.len) | |
| 1022 | + | return CHILD_HOLDER; | |
| 1023 | + | ||
| 1024 | + | map.fd = bfd; | |
| 1025 | + | if (ioctl(ffd, FUSE_DEV_IOC_BACKING_OPEN, &map) < 0) { | |
| 1026 | + | /* EOPNOTSUPP: no FUSE_PASSTHROUGH, ENOTTY: no such ioctl */ | |
| 1027 | + | if (errno == EPERM || errno == EOPNOTSUPP || errno == ENOTTY) | |
| 1028 | + | return CHILD_SKIP; | |
| 1029 | + | return CHILD_HOLDER; | |
| 1030 | + | } | |
| 1031 | + | close(bfd); /* the connection keeps its own */ | |
| 1032 | + | return CHILD_OK; /* ffd stays open until the child exits */ | |
| 1033 | + | } | |
| 1034 | + | ||
| 1035 | + | /* Wait for a device node the kernel is about to create. */ | |
| 1036 | + | static int open_when_there(const char *dev, int flags, int ms) | |
| 1037 | + | { | |
| 1038 | + | int fd; | |
| 1039 | + | ||
| 1040 | + | for (; ms > 0; ms -= 100) { | |
| 1041 | + | fd = open(dev, flags); | |
| 1042 | + | if (fd >= 0) | |
| 1043 | + | return fd; | |
| 1044 | + | usleep(100000); | |
| 1045 | + | } | |
| 1046 | + | return -1; | |
| 1047 | + | } | |
| 1048 | + | ||
| 1049 | + | /* | |
| 1050 | + | * zloop keeps every zone file open. One conventional zone is enough for a | |
| 1051 | + | * FAT image, the sequential one stays empty. | |
| 1052 | + | */ | |
| 1053 | + | static int holder_zloop(void) | |
| 1054 | + | { | |
| 1055 | + | char cmd[PATH_MAX]; | |
| 1056 | + | int fd, ret = CHILD_HOLDER; | |
| 1057 | + | ||
| 1058 | + | if (access("/dev/zloop-control", W_OK)) | |
| 1059 | + | return CHILD_SKIP; | |
| 1060 | + | /* somebody else's device, leave it alone */ | |
| 1061 | + | if (!access("/sys/block/zloop0", F_OK)) | |
| 1062 | + | return CHILD_SKIP; | |
| 1063 | + | if (mkdir(at("p/zl"), 0755) || mkdir(at("p/zl/0"), 0755)) | |
| 1064 | + | return CHILD_HOLDER; | |
| 1065 | + | snprintf(cmd, sizeof(cmd), | |
| 1066 | + | "add id=0,capacity_mb=8,zone_size_mb=4,conv_zones=1,base_dir=%s", | |
| 1067 | + | at("p/zl")); | |
| 1068 | + | if (write_file("/dev/zloop-control", cmd)) | |
| 1069 | + | return CHILD_HOLDER; | |
| 1070 | + | fd = open_when_there("/dev/zloop0", O_RDWR, 5000); | |
| 1071 | + | if (fd < 0 || write_fat12_4k(fd, 1024)) /* 4 KiB blocks, like P */ | |
| 1072 | + | goto undo; | |
| 1073 | + | close(fd); | |
| 1074 | + | fd = -1; | |
| 1075 | + | if (mount_fat("/dev/zloop0", HOLDER_BELOW)) { | |
| 1076 | + | ret = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER; | |
| 1077 | + | goto undo; | |
| 1078 | + | } | |
| 1079 | + | return CHILD_OK; | |
| 1080 | + | undo: | |
| 1081 | + | if (fd >= 0) | |
| 1082 | + | close(fd); | |
| 1083 | + | write_file("/dev/zloop-control", "remove id=0"); | |
| 1084 | + | return ret; | |
| 1085 | + | } | |
| 1086 | + | ||
| 1087 | + | static int mount_configfs(void) | |
| 1088 | + | { | |
| 1089 | + | if (access("/sys/kernel/config", F_OK)) | |
| 1090 | + | return -1; | |
| 1091 | + | if (mount("configfs", "/sys/kernel/config", "configfs", 0, NULL) && errno != EBUSY) | |
| 1092 | + | return -1; | |
| 1093 | + | return 0; | |
| 1094 | + | } | |
| 1095 | + | ||
| 1096 | + | /* Take the gadget out of configfs again, in the reverse order of its creation. */ | |
| 1097 | + | static void gadget_remove(void) | |
| 1098 | + | { | |
| 1099 | + | if (mount_configfs()) | |
| 1100 | + | return; | |
| 1101 | + | write_file(gat("/functions/mass_storage.0/lun.0/file"), "\n"); | |
| 1102 | + | write_file(gat("/UDC"), "\n"); | |
| 1103 | + | unlink(gat("/configs/c.1/mass_storage.0")); | |
| 1104 | + | rmdir(gat("/configs/c.1/strings/0x409")); | |
| 1105 | + | rmdir(gat("/configs/c.1")); | |
| 1106 | + | rmdir(gat("/functions/mass_storage.0")); | |
| 1107 | + | rmdir(gat("/strings/0x409")); | |
| 1108 | + | rmdir(gat("")); | |
| 1109 | + | } | |
| 1110 | + | ||
| 1111 | + | /* The disk usb-storage created for the gadget, by the LUN's inquiry string. */ | |
| 1112 | + | static int find_gadget_disk(char *dev, size_t len, int ms) | |
| 1113 | + | { | |
| 1114 | + | char path[PATH_MAX], model[64]; | |
| 1115 | + | struct dirent *de; | |
| 1116 | + | DIR *d; | |
| 1117 | + | ||
| 1118 | + | for (; ms > 0; ms -= 100, usleep(100000)) { | |
| 1119 | + | d = opendir("/sys/block"); | |
| 1120 | + | if (!d) | |
| 1121 | + | return -1; | |
| 1122 | + | while ((de = readdir(d))) { | |
| 1123 | + | if (strncmp(de->d_name, "sd", 2)) | |
| 1124 | + | continue; | |
| 1125 | + | snprintf(path, sizeof(path), "/sys/block/%s/device/model", de->d_name); | |
| 1126 | + | if (read_sysfs(path, model, sizeof(model)) || | |
| 1127 | + | strncmp(model, "File-Stor Gadget", 16)) | |
| 1128 | + | continue; | |
| 1129 | + | snprintf(dev, len, "/dev/%s", de->d_name); | |
| 1130 | + | closedir(d); | |
| 1131 | + | return 0; | |
| 1132 | + | } | |
| 1133 | + | closedir(d); | |
| 1134 | + | } | |
| 1135 | + | return -1; | |
| 1136 | + | } | |
| 1137 | + | ||
| 1138 | + | /* | |
| 1139 | + | * A mass storage gadget bound to the dummy UDC, so that this kernel is | |
| 1140 | + | * also the USB host that sees the LUN as a SCSI disk. sd locks the | |
| 1141 | + | * medium on open, which is what keeps the LUN's file from being ejected. | |
| 1142 | + | */ | |
| 1143 | + | #define GADGET_STEP(x) do { \ | |
| 1144 | + | if (x) { \ | |
| 1145 | + | fprintf(stderr, "gadget: %s failed: %s\n", #x, strerror(errno)); \ | |
| 1146 | + | gadget_remove(); \ | |
| 1147 | + | return CHILD_HOLDER; \ | |
| 1148 | + | } \ | |
| 1149 | + | } while (0) | |
| 1150 | + | ||
| 1151 | + | static int holder_gadget(void) | |
| 1152 | + | { | |
| 1153 | + | char dev[PATH_MAX]; | |
| 1154 | + | int fd; | |
| 1155 | + | ||
| 1156 | + | if (mount_configfs()) | |
| 1157 | + | return CHILD_SKIP; | |
| 1158 | + | if (access("/sys/kernel/config/usb_gadget", F_OK) || | |
| 1159 | + | access("/sys/class/udc/dummy_udc.0", F_OK)) | |
| 1160 | + | return CHILD_SKIP; | |
| 1161 | + | ||
| 1162 | + | fd = open(at("p/lun.img"), O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 1163 | + | if (fd < 0 || write_fat12(fd)) | |
| 1164 | + | return CHILD_HOLDER; | |
| 1165 | + | close(fd); | |
| 1166 | + | ||
| 1167 | + | GADGET_STEP(mkdir(gat(""), 0755)); | |
| 1168 | + | GADGET_STEP(write_file(gat("/idVendor"), "0x1d6b")); | |
| 1169 | + | GADGET_STEP(write_file(gat("/idProduct"), "0x0104")); | |
| 1170 | + | GADGET_STEP(mkdir(gat("/strings/0x409"), 0755)); | |
| 1171 | + | GADGET_STEP(write_file(gat("/strings/0x409/serialnumber"), "1")); | |
| 1172 | + | GADGET_STEP(write_file(gat("/strings/0x409/manufacturer"), "kselftest")); | |
| 1173 | + | GADGET_STEP(write_file(gat("/strings/0x409/product"), "cycle")); | |
| 1174 | + | GADGET_STEP(mkdir(gat("/configs/c.1"), 0755)); | |
| 1175 | + | GADGET_STEP(mkdir(gat("/configs/c.1/strings/0x409"), 0755)); | |
| 1176 | + | GADGET_STEP(write_file(gat("/configs/c.1/strings/0x409/configuration"), "c")); | |
| 1177 | + | GADGET_STEP(mkdir(gat("/functions/mass_storage.0"), 0755)); | |
| 1178 | + | GADGET_STEP(write_file(gat("/functions/mass_storage.0/lun.0/removable"), "1")); | |
| 1179 | + | GADGET_STEP(write_file(gat("/functions/mass_storage.0/lun.0/file"), at("p/lun.img"))); | |
| 1180 | + | GADGET_STEP(symlink(gat("/functions/mass_storage.0"), gat("/configs/c.1/mass_storage.0"))); | |
| 1181 | + | /* EBUSY: the controller is somebody else's, leave it alone */ | |
| 1182 | + | if (write_file(gat("/UDC"), "dummy_udc.0")) { | |
| 1183 | + | fd = errno == EBUSY ? CHILD_SKIP : CHILD_HOLDER; | |
| 1184 | + | gadget_remove(); | |
| 1185 | + | return fd; | |
| 1186 | + | } | |
| 1187 | + | ||
| 1188 | + | /* usb-storage waits a second before it scans the device */ | |
| 1189 | + | if (find_gadget_disk(dev, sizeof(dev), 15000)) { | |
| 1190 | + | /* without usb-storage and sd the LUN never shows up as a disk */ | |
| 1191 | + | fd = (access("/sys/bus/usb/drivers/usb-storage", F_OK) || | |
| 1192 | + | access("/sys/bus/scsi/drivers/sd", F_OK)) ? CHILD_SKIP : CHILD_HOLDER; | |
| 1193 | + | gadget_remove(); | |
| 1194 | + | return fd; | |
| 1195 | + | } | |
| 1196 | + | fd = open_when_there(dev, O_RDONLY, 5000); | |
| 1197 | + | GADGET_STEP(fd < 0); | |
| 1198 | + | close(fd); | |
| 1199 | + | if (mount_fat(dev, HOLDER_BELOW)) { | |
| 1200 | + | fd = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER; | |
| 1201 | + | gadget_remove(); | |
| 1202 | + | return fd; | |
| 1203 | + | } | |
| 1204 | + | return CHILD_OK; | |
| 1205 | + | } | |
| 1206 | + | ||
| 1207 | + | #define BITMAP_MAGIC 0x6d746962 | |
| 1208 | + | ||
| 1209 | + | /* | |
| 1210 | + | * A RAID1 of one loop device, not persistent, with its bitmap in a file | |
| 1211 | + | * on P. The bitmap file needs a superblock the kernel accepts; sync_size, | |
| 1212 | + | * uuid and events are not looked at for a non-persistent array. | |
| 1213 | + | */ | |
| 1214 | + | static int holder_md(void) | |
| 1215 | + | { | |
| 1216 | + | struct { | |
| 1217 | + | __u32 magic, version; | |
| 1218 | + | __u8 uuid[16]; | |
| 1219 | + | __u64 events, events_cleared, sync_size; | |
| 1220 | + | __u32 state, chunksize, daemon_sleep, write_behind; | |
| 1221 | + | } bsb = { | |
| 1222 | + | .magic = BITMAP_MAGIC, | |
| 1223 | + | .version = 4, | |
| 1224 | + | .chunksize = 64 * 1024, | |
| 1225 | + | .daemon_sleep = 5, | |
| 1226 | + | }; | |
| 1227 | + | mdu_array_info_t info = { | |
| 1228 | + | .level = 1, | |
| 1229 | + | .raid_disks = 1, | |
| 1230 | + | .size = 8 * 1024, /* KiB */ | |
| 1231 | + | .not_persistent = 1, | |
| 1232 | + | }; | |
| 1233 | + | mdu_disk_info_t disk = { | |
| 1234 | + | .major = 7, | |
| 1235 | + | .state = (1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC), | |
| 1236 | + | }; | |
| 1237 | + | int fd, mdfd, bfd, n, ret = CHILD_HOLDER; | |
| 1238 | + | char dev[32], buf[4096]; | |
| 1239 | + | struct stat st; | |
| 1240 | + | ||
| 1241 | + | fd = open(at("img/md.img"), O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 1242 | + | if (fd < 0 || ftruncate(fd, 8 * 1024 * 1024)) | |
| 1243 | + | return CHILD_HOLDER; | |
| 1244 | + | close(fd); | |
| 1245 | + | n = loop_attach(at("img/md.img")); | |
| 1246 | + | if (n < 0) | |
| 1247 | + | return CHILD_HOLDER; | |
| 1248 | + | /* the minor is not the number of the device when loop has partitions */ | |
| 1249 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 1250 | + | if (stat(dev, &st)) | |
| 1251 | + | return CHILD_HOLDER; | |
| 1252 | + | disk.major = major(st.st_rdev); | |
| 1253 | + | disk.minor = minor(st.st_rdev); | |
| 1254 | + | ||
| 1255 | + | bfd = open(at("p/bitmap"), O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 1256 | + | if (bfd < 0 || write(bfd, &bsb, sizeof(bsb)) != sizeof(bsb) || ftruncate(bfd, 4096)) | |
| 1257 | + | return CHILD_HOLDER; | |
| 1258 | + | ||
| 1259 | + | if (read_sysfs("/proc/mdstat", buf, sizeof(buf))) { | |
| 1260 | + | fprintf(stderr, "md: no /proc/mdstat\n"); | |
| 1261 | + | return CHILD_SKIP; | |
| 1262 | + | } | |
| 1263 | + | if (!strstr(buf, "[raid1]")) { | |
| 1264 | + | fprintf(stderr, "md: no raid1 personality: %s\n", buf); | |
| 1265 | + | return CHILD_SKIP; | |
| 1266 | + | } | |
| 1267 | + | /* a node of our own: /dev may not have one and is not ours to change */ | |
| 1268 | + | if (mknod(at("img/md0"), S_IFBLK | 0600, makedev(MD_MAJOR, 0))) | |
| 1269 | + | return CHILD_HOLDER; | |
| 1270 | + | mdfd = open(at("img/md0"), O_RDWR); | |
| 1271 | + | if (mdfd < 0) | |
| 1272 | + | return CHILD_SKIP; | |
| 1273 | + | /* somebody else's array: SET_ARRAY_INFO would say EINVAL, not EBUSY */ | |
| 1274 | + | if (!read_sysfs("/sys/block/md0/md/array_state", buf, sizeof(buf)) && | |
| 1275 | + | strncmp(buf, "clear", 5)) { | |
| 1276 | + | fprintf(stderr, "md: md0 is in use: %s", buf); | |
| 1277 | + | close(mdfd); | |
| 1278 | + | return CHILD_SKIP; | |
| 1279 | + | } | |
| 1280 | + | /* the bitmap ops are only installed once a bitmap type is chosen */ | |
| 1281 | + | write_file("/sys/block/md0/md/bitmap_type", "bitmap"); | |
| 1282 | + | /* EBUSY: somebody else's array, leave it alone */ | |
| 1283 | + | if (ioctl(mdfd, SET_ARRAY_INFO, &info)) | |
| 1284 | + | return errno == EBUSY ? CHILD_SKIP : CHILD_HOLDER; | |
| 1285 | + | /* the array is ours from here on and has to be stopped on every path */ | |
| 1286 | + | if (ioctl(mdfd, ADD_NEW_DISK, &disk)) | |
| 1287 | + | goto undo; | |
| 1288 | + | /* attach the bitmap file before the array runs, the way mdadm does */ | |
| 1289 | + | if (ioctl(mdfd, SET_BITMAP_FILE, bfd)) { | |
| 1290 | + | fprintf(stderr, "md: SET_BITMAP_FILE: %s\n", strerror(errno)); | |
| 1291 | + | if (errno == EINVAL) | |
| 1292 | + | ret = CHILD_SKIP; | |
| 1293 | + | goto undo; | |
| 1294 | + | } | |
| 1295 | + | close(bfd); /* the array keeps its own */ | |
| 1296 | + | if (ioctl(mdfd, RUN_ARRAY, NULL)) { | |
| 1297 | + | fprintf(stderr, "md: RUN_ARRAY: %s\n", strerror(errno)); | |
| 1298 | + | goto undo; | |
| 1299 | + | } | |
| 1300 | + | if (write_fat12(mdfd)) | |
| 1301 | + | goto undo; | |
| 1302 | + | close(mdfd); | |
| 1303 | + | if (mount_fat(at("img/md0"), HOLDER_BELOW)) { | |
| 1304 | + | ret = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER; | |
| 1305 | + | mdfd = open(at("img/md0"), O_RDWR); | |
| 1306 | + | goto undo; | |
| 1307 | + | } | |
| 1308 | + | return CHILD_OK; | |
| 1309 | + | undo: | |
| 1310 | + | if (mdfd >= 0) { | |
| 1311 | + | ioctl(mdfd, STOP_ARRAY); | |
| 1312 | + | close(mdfd); | |
| 1313 | + | } | |
| 1314 | + | return ret; | |
| 1315 | + | } | |
| 1316 | + | ||
| 1317 | + | /* | |
| 1318 | + | * A device keeps its file for as long as it is configured, so once nothing | |
| 1319 | + | * below the dead mount is left the device has to be told to let go. With | |
| 1320 | + | * the cycle unbroken C's filesystem still holds the device and every one | |
| 1321 | + | * of these refuses. | |
| 1322 | + | */ | |
| 1323 | + | static int holder_let_go_once(enum holder holder) | |
| 1324 | + | { | |
| 1325 | + | int fd, ret; | |
| 1326 | + | ||
| 1327 | + | switch (holder) { | |
| 1328 | + | case HOLDER_ZRAM: | |
| 1329 | + | return write_file("/sys/block/zram0/reset", "1"); | |
| 1330 | + | case HOLDER_ZLOOP: | |
| 1331 | + | return write_file("/dev/zloop-control", "remove id=0"); | |
| 1332 | + | case HOLDER_GADGET: | |
| 1333 | + | if (mount_configfs()) | |
| 1334 | + | return -1; | |
| 1335 | + | /* a zero-length write is a no-op for configfs; a newline ejects */ | |
| 1336 | + | return write_file(gat("/functions/mass_storage.0/lun.0/file"), "\n"); | |
| 1337 | + | case HOLDER_MD: | |
| 1338 | + | fd = open(at("img/md0"), O_RDONLY); | |
| 1339 | + | if (fd < 0) { | |
| 1340 | + | /* the child's node went with its tmpfs */ | |
| 1341 | + | mknod(at("md0"), S_IFBLK | 0600, makedev(MD_MAJOR, 0)); | |
| 1342 | + | fd = open(at("md0"), O_RDONLY); | |
| 1343 | + | } | |
| 1344 | + | if (fd < 0) | |
| 1345 | + | return -1; | |
| 1346 | + | ret = ioctl(fd, STOP_ARRAY); | |
| 1347 | + | close(fd); | |
| 1348 | + | return ret; | |
| 1349 | + | default: | |
| 1350 | + | return 0; | |
| 1351 | + | } | |
| 1352 | + | } | |
| 1353 | + | ||
| 1354 | + | static void zram_reset(void) | |
| 1355 | + | { | |
| 1356 | + | holder_let_go_once(HOLDER_ZRAM); | |
| 1357 | + | } | |
| 1358 | + | ||
| 1359 | + | /* | |
| 1360 | + | * In its own mount namespace the child puts the image on a tmpfs next to | |
| 1361 | + | * P, mounts P from a loop device, and sets the holder up with its own | |
| 1362 | + | * filesystem or device mounted at C below P. | |
| 1363 | + | */ | |
| 1364 | + | static int holder_child(int to_parent, int from_parent, enum holder holder) | |
| 1365 | + | { | |
| 1366 | + | bool fifo = holder == HOLDER_AUTOFS || holder == HOLDER_ZRAM; | |
| 1367 | + | /* room for a 4 MiB zone file or a floppy image on P */ | |
| 1368 | + | bool big = holder == HOLDER_ZLOOP || holder == HOLDER_GADGET; | |
| 1369 | + | struct report r = { { -1, -1 } }; | |
| 1370 | + | char dev[32], c; | |
| 1371 | + | int ifd, n, ret; | |
| 1372 | + | ||
| 1373 | + | if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL)) | |
| 1374 | + | return CHILD_NS; | |
| 1375 | + | if (mkdir(at("img"), 0755) || mount("tmpfs", at("img"), "tmpfs", 0, NULL)) | |
| 1376 | + | return child_fails(CHILD_NS); | |
| 1377 | + | ||
| 1378 | + | ifd = open(HOLDER_IMG, O_RDWR | O_CREAT | O_EXCL, 0600); | |
| 1379 | + | if (ifd < 0 || (fifo ? write_minix(ifd) : | |
| 1380 | + | big ? write_fat12_4k(ifd, 3072) : write_fat12(ifd))) | |
| 1381 | + | return child_fails(CHILD_IMAGE); | |
| 1382 | + | close(ifd); | |
| 1383 | + | n = loop_attach(HOLDER_IMG); | |
| 1384 | + | if (n < 0) | |
| 1385 | + | return child_fails(CHILD_LOOP); | |
| 1386 | + | snprintf(dev, sizeof(dev), "/dev/loop%d", n); | |
| 1387 | + | if (mkdir(HOLDER_MNT, 0755)) | |
| 1388 | + | return child_fails(CHILD_MOUNT); | |
| 1389 | + | if (fifo ? mount(dev, HOLDER_MNT, "minix", 0, NULL) : mount_fat(dev, HOLDER_MNT)) | |
| 1390 | + | return child_fails(errno == ENODEV ? CHILD_NOFS : CHILD_MOUNT); | |
| 1391 | + | if (mkdir(HOLDER_BELOW, 0755)) | |
| 1392 | + | return child_fails(CHILD_MOUNT); | |
| 1393 | + | ||
| 1394 | + | switch (holder) { | |
| 1395 | + | case HOLDER_AUTOFS: | |
| 1396 | + | ret = holder_autofs(); | |
| 1397 | + | break; | |
| 1398 | + | case HOLDER_ZRAM: | |
| 1399 | + | ret = holder_zram(); | |
| 1400 | + | break; | |
| 1401 | + | case HOLDER_ECRYPTFS: | |
| 1402 | + | ret = holder_ecryptfs(); | |
| 1403 | + | break; | |
| 1404 | + | case HOLDER_BINFMT_MISC: | |
| 1405 | + | ret = holder_binfmt_misc(); | |
| 1406 | + | break; | |
| 1407 | + | case HOLDER_FUSE: | |
| 1408 | + | ret = holder_fuse(); | |
| 1409 | + | break; | |
| 1410 | + | case HOLDER_ZLOOP: | |
| 1411 | + | ret = holder_zloop(); | |
| 1412 | + | break; | |
| 1413 | + | case HOLDER_GADGET: | |
| 1414 | + | ret = holder_gadget(); | |
| 1415 | + | break; | |
| 1416 | + | case HOLDER_MD: | |
| 1417 | + | ret = holder_md(); | |
| 1418 | + | break; | |
| 1419 | + | default: | |
| 1420 | + | ret = CHILD_HOLDER; | |
| 1421 | + | } | |
| 1422 | + | if (ret != CHILD_OK) | |
| 1423 | + | return child_fails(ret); | |
| 1424 | + | ||
| 1425 | + | /* P's device first, then the one the holder has bound for itself */ | |
| 1426 | + | r.n[0] = n; | |
| 1427 | + | if (nr_bound > 1) | |
| 1428 | + | r.n[1] = bound[1]; | |
| 1429 | + | if (write(to_parent, &r, sizeof(r)) != sizeof(r) || | |
| 1430 | + | read(from_parent, &c, 1) != 1) { | |
| 1431 | + | /* the parent went away and will not tell the devices to let go */ | |
| 1432 | + | umount2(HOLDER_BELOW, MNT_DETACH); | |
| 1433 | + | for (int i = 0; i < 50 && holder_let_go_once(holder); i++) | |
| 1434 | + | usleep(100000); | |
| 1435 | + | if (holder == HOLDER_GADGET) | |
| 1436 | + | gadget_remove(); | |
| 1437 | + | return child_fails(CHILD_PIPE); | |
| 1438 | + | } | |
| 1439 | + | return CHILD_OK; | |
| 1440 | + | } | |
| 1441 | + | ||
| 1442 | + | /* | |
| 1443 | + | * The release of C's filesystem may still be in flight when the child is | |
| 1444 | + | * gone, and a device that is still held refuses to let go, so try for a | |
| 1445 | + | * while. With the cycle unbroken it refuses for good. | |
| 1446 | + | */ | |
| 1447 | + | static void holder_let_go(enum holder holder) | |
| 1448 | + | { | |
| 1449 | + | for (int i = 0; i < 50; i++) { | |
| 1450 | + | if (!holder_let_go_once(holder)) | |
| 1451 | + | return; | |
| 1452 | + | usleep(100000); | |
| 1453 | + | } | |
| 1454 | + | } | |
| 1455 | + | ||
| 1456 | + | /* | |
| 1457 | + | * rmdir of p from here, where it is a plain directory, detaches | |
| 1458 | + | * P in the child's namespace with C connected below it. Once the child is | |
| 1459 | + | * gone the holder's file on P is the only thing left that refers to P, | |
| 1460 | + | * and it is dropped only when C's filesystem dies, which waits for P. | |
| 1461 | + | * The loop device backing P tells whether that resolved. | |
| 1462 | + | */ | |
| 1463 | + | static void holder_cycle(struct __test_metadata *_metadata, | |
| 1464 | + | FIXTURE_DATA(loop_cycle) *self, enum holder holder) | |
| 1465 | + | { | |
| 1466 | + | struct report r = { { -1, -1 } }; | |
| 1467 | + | int to_parent[2], from_parent[2]; | |
| 1468 | + | pid_t pid; | |
| 1469 | + | ||
| 1470 | + | ASSERT_EQ(pipe(to_parent), 0); | |
| 1471 | + | ASSERT_EQ(pipe(from_parent), 0); | |
| 1472 | + | pid = fork(); | |
| 1473 | + | ASSERT_GE(pid, 0); | |
| 1474 | + | if (pid == 0) { | |
| 1475 | + | close(to_parent[0]); | |
| 1476 | + | close(from_parent[1]); | |
| 1477 | + | _exit(holder_child(to_parent[1], from_parent[0], holder)); | |
| 1478 | + | } | |
| 1479 | + | close(to_parent[1]); | |
| 1480 | + | close(from_parent[0]); | |
| 1481 | + | ||
| 1482 | + | if (read(to_parent[0], &r, sizeof(r)) != sizeof(r)) | |
| 1483 | + | CHILD_GAVE_UP(pid); | |
| 1484 | + | self->gadget = holder == HOLDER_GADGET; | |
| 1485 | + | remember_loop(self, r.n[0]); | |
| 1486 | + | remember_loop(self, r.n[1]); | |
| 1487 | + | snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", r.n[0]); | |
| 1488 | + | snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", r.n[0]); | |
| 1489 | + | ||
| 1490 | + | ASSERT_EQ(rmdir(HOLDER_MNT), 0); | |
| 1491 | + | ASSERT_EQ(write(from_parent[1], "x", 1), 1); | |
| 1492 | + | CHILD_LEFT(pid); | |
| 1493 | + | close(to_parent[0]); | |
| 1494 | + | close(from_parent[1]); | |
| 1495 | + | ||
| 1496 | + | holder_let_go(holder); | |
| 1497 | + | assert_loop_released(_metadata, self); | |
| 1498 | + | /* the teardown takes the gadget and the holder's own loop device away */ | |
| 1499 | + | } | |
| 1500 | + | ||
| 1501 | + | TEST_F(loop_cycle, autofs_pipe_on_dead_mount_released) | |
| 1502 | + | { | |
| 1503 | + | holder_cycle(_metadata, self, HOLDER_AUTOFS); | |
| 1504 | + | } | |
| 1505 | + | ||
| 1506 | + | TEST_F(loop_cycle, zram_writeback_node_on_dead_mount_released) | |
| 1507 | + | { | |
| 1508 | + | holder_cycle(_metadata, self, HOLDER_ZRAM); | |
| 1509 | + | } | |
| 1510 | + | ||
| 1511 | + | TEST_F(loop_cycle, ecryptfs_lower_on_dead_mount_released) | |
| 1512 | + | { | |
| 1513 | + | holder_cycle(_metadata, self, HOLDER_ECRYPTFS); | |
| 1514 | + | } | |
| 1515 | + | ||
| 1516 | + | TEST_F(loop_cycle, binfmt_misc_interpreter_on_dead_mount_released) | |
| 1517 | + | { | |
| 1518 | + | holder_cycle(_metadata, self, HOLDER_BINFMT_MISC); | |
| 1519 | + | } | |
| 1520 | + | ||
| 1521 | + | TEST_F(loop_cycle, fuse_backing_file_on_dead_mount_released) | |
| 1522 | + | { | |
| 1523 | + | holder_cycle(_metadata, self, HOLDER_FUSE); | |
| 1524 | + | } | |
| 1525 | + | ||
| 1526 | + | TEST_F(loop_cycle, zloop_zone_files_on_dead_mount_released) | |
| 1527 | + | { | |
| 1528 | + | holder_cycle(_metadata, self, HOLDER_ZLOOP); | |
| 1529 | + | } | |
| 1530 | + | ||
| 1531 | + | /* up to 15 s for the disk to show up and 12 s for a device that is held */ | |
| 1532 | + | TEST_F_TIMEOUT(loop_cycle, mass_storage_lun_on_dead_mount_released, 120) | |
| 1533 | + | { | |
| 1534 | + | holder_cycle(_metadata, self, HOLDER_GADGET); | |
| 1535 | + | } | |
| 1536 | + | ||
| 1537 | + | TEST_F(loop_cycle, md_bitmap_file_on_dead_mount_released) | |
| 1538 | + | { | |
| 1539 | + | holder_cycle(_metadata, self, HOLDER_MD); | |
| 1540 | + | } | |
| 1541 | + | ||
| 1542 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/mount_cover_test.c mode 100644
| @@ -0,0 +1,579 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * An unmounted mount that would have stayed attached to its unmounted parent | |
| 4 | + | * leaves a cover behind instead. A lookup on the parent at the mountpoint | |
| 5 | + | * finds knullfs: an empty read-only directory that is shared by every cover | |
| 6 | + | * and every kernel thread, so it can't be watched or locked and nothing can | |
| 7 | + | * be mounted on it. The mount itself is a root from then on. Where a file | |
| 8 | + | * was mounted, the stand-in is an empty regular file of the same instance. | |
| 9 | + | */ | |
| 10 | + | #define _GNU_SOURCE | |
| 11 | + | #include <errno.h> | |
| 12 | + | #include <fcntl.h> | |
| 13 | + | #include <sched.h> | |
| 14 | + | #include <stdint.h> | |
| 15 | + | #include <stdio.h> | |
| 16 | + | #include <stdlib.h> | |
| 17 | + | #include <string.h> | |
| 18 | + | #include <unistd.h> | |
| 19 | + | #include <sys/fanotify.h> | |
| 20 | + | #include <sys/file.h> | |
| 21 | + | #include <sys/inotify.h> | |
| 22 | + | #include <sys/mount.h> | |
| 23 | + | #include <sys/prctl.h> | |
| 24 | + | #include <sys/stat.h> | |
| 25 | + | #include <sys/statvfs.h> | |
| 26 | + | #include <sys/syscall.h> | |
| 27 | + | #include <sys/vfs.h> | |
| 28 | + | #include <sys/wait.h> | |
| 29 | + | ||
| 30 | + | #include "../../kselftest_harness.h" | |
| 31 | + | #include "../readdir_hold.h" | |
| 32 | + | ||
| 33 | + | #ifndef NULL_FS_MAGIC | |
| 34 | + | #define NULL_FS_MAGIC 0x4E554C4C | |
| 35 | + | #endif | |
| 36 | + | ||
| 37 | + | #ifndef TMPFS_MAGIC | |
| 38 | + | #define TMPFS_MAGIC 0x01021994 | |
| 39 | + | #endif | |
| 40 | + | ||
| 41 | + | #ifndef F_SETDELEG | |
| 42 | + | #define F_SETDELEG (F_SETLEASE + 16) | |
| 43 | + | #endif | |
| 44 | + | ||
| 45 | + | /* struct delegation of <linux/fcntl.h>, which doesn't mix with <fcntl.h> */ | |
| 46 | + | struct delegation_req { | |
| 47 | + | uint32_t d_flags; | |
| 48 | + | uint16_t d_type; | |
| 49 | + | uint16_t __pad; | |
| 50 | + | }; | |
| 51 | + | ||
| 52 | + | #define DIR_LEN 64 | |
| 53 | + | #define PATH_LEN 128 | |
| 54 | + | ||
| 55 | + | /* what the parent asks the child to do */ | |
| 56 | + | #define CMD_RMDIR 'r' | |
| 57 | + | #define CMD_CLOSE_T 't' | |
| 58 | + | #define CMD_QUIT 'q' | |
| 59 | + | ||
| 60 | + | static int write_file(const char *path, const char *s) | |
| 61 | + | { | |
| 62 | + | ssize_t n = -1; | |
| 63 | + | int fd; | |
| 64 | + | ||
| 65 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 66 | + | if (fd >= 0) { | |
| 67 | + | n = write(fd, s, strlen(s)); | |
| 68 | + | close(fd); | |
| 69 | + | } | |
| 70 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 71 | + | } | |
| 72 | + | ||
| 73 | + | static int touch(const char *path) | |
| 74 | + | { | |
| 75 | + | int fd; | |
| 76 | + | ||
| 77 | + | fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644); | |
| 78 | + | if (fd < 0) | |
| 79 | + | return -1; | |
| 80 | + | close(fd); | |
| 81 | + | return 0; | |
| 82 | + | } | |
| 83 | + | ||
| 84 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 85 | + | static int enter_userns(void) | |
| 86 | + | { | |
| 87 | + | uid_t uid = getuid(); | |
| 88 | + | gid_t gid = getgid(); | |
| 89 | + | char map[32]; | |
| 90 | + | ||
| 91 | + | prctl(PR_SET_DUMPABLE, 1); | |
| 92 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 93 | + | return -1; | |
| 94 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 95 | + | return -1; | |
| 96 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 97 | + | if (write_file("/proc/self/uid_map", map)) | |
| 98 | + | return -1; | |
| 99 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 100 | + | if (write_file("/proc/self/gid_map", map)) | |
| 101 | + | return -1; | |
| 102 | + | if (setgid(0) || setuid(0)) | |
| 103 | + | return -1; | |
| 104 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 105 | + | } | |
| 106 | + | ||
| 107 | + | /* | |
| 108 | + | * The child mounts P on @base/p, C on P/covered and the file P/src on P/file | |
| 109 | + | * in a mount namespace of its own, binds P a second time at @base/q and hands | |
| 110 | + | * out descriptors on P and on C. rmdir() of @base/p from here unmounts P | |
| 111 | + | * together with C and the file bind. P and C are held by the descriptors and | |
| 112 | + | * the unmounted children leave their covers behind. On request the child | |
| 113 | + | * removes C's mountpoint through the bind. | |
| 114 | + | * | |
| 115 | + | * It also mounts T on @base/t with a child on T/covered, binds T at @base/u | |
| 116 | + | * with a second child on the same dentry and hands out descriptors on T and | |
| 117 | + | * U. rmdir() of both from here leaves two covers on one mountpoint. On request | |
| 118 | + | * the child lets go of T. | |
| 119 | + | */ | |
| 120 | + | static int cover_child(const char *base, int to_parent, int from_parent) | |
| 121 | + | { | |
| 122 | + | char p[PATH_LEN], c[PATH_LEN], q[PATH_LEN], qc[PATH_LEN]; | |
| 123 | + | char f[PATH_LEN], src[PATH_LEN], t[PATH_LEN], u[PATH_LEN], tc[PATH_LEN]; | |
| 124 | + | int fds[4], ret; | |
| 125 | + | char cmd; | |
| 126 | + | ||
| 127 | + | if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL)) | |
| 128 | + | return 1; | |
| 129 | + | snprintf(p, sizeof(p), "%s/p", base); | |
| 130 | + | if (mkdir(p, 0755) || mount("tmpfs", p, "tmpfs", 0, NULL)) | |
| 131 | + | return 2; | |
| 132 | + | snprintf(c, sizeof(c), "%s/p/covered", base); | |
| 133 | + | if (mkdir(c, 0755) || mount("tmpfs", c, "tmpfs", 0, NULL)) | |
| 134 | + | return 3; | |
| 135 | + | snprintf(f, sizeof(f), "%s/p/file", base); | |
| 136 | + | snprintf(src, sizeof(src), "%s/p/src", base); | |
| 137 | + | if (touch(src) || touch(f) || mount(src, f, NULL, MS_BIND, NULL)) | |
| 138 | + | return 4; | |
| 139 | + | snprintf(q, sizeof(q), "%s/q", base); | |
| 140 | + | if (mkdir(q, 0755) || mount(p, q, NULL, MS_BIND, NULL)) | |
| 141 | + | return 5; | |
| 142 | + | snprintf(t, sizeof(t), "%s/t", base); | |
| 143 | + | if (mkdir(t, 0755) || mount("tmpfs", t, "tmpfs", 0, NULL)) | |
| 144 | + | return 6; | |
| 145 | + | snprintf(tc, sizeof(tc), "%s/t/covered", base); | |
| 146 | + | if (mkdir(tc, 0755) || mount("tmpfs", tc, "tmpfs", 0, NULL)) | |
| 147 | + | return 7; | |
| 148 | + | snprintf(u, sizeof(u), "%s/u", base); | |
| 149 | + | if (mkdir(u, 0755) || mount(t, u, NULL, MS_BIND, NULL)) | |
| 150 | + | return 8; | |
| 151 | + | snprintf(tc, sizeof(tc), "%s/u/covered", base); | |
| 152 | + | if (mount("tmpfs", tc, "tmpfs", 0, NULL)) | |
| 153 | + | return 9; | |
| 154 | + | fds[0] = open(p, O_PATH | O_DIRECTORY | O_CLOEXEC); | |
| 155 | + | fds[1] = open(c, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 156 | + | fds[2] = open(t, O_PATH | O_DIRECTORY | O_CLOEXEC); | |
| 157 | + | fds[3] = open(u, O_PATH | O_DIRECTORY | O_CLOEXEC); | |
| 158 | + | if (fds[0] < 0 || fds[1] < 0 || fds[2] < 0 || fds[3] < 0) | |
| 159 | + | return 10; | |
| 160 | + | if (write(to_parent, fds, sizeof(fds)) != sizeof(fds)) | |
| 161 | + | return 11; | |
| 162 | + | ||
| 163 | + | snprintf(qc, sizeof(qc), "%s/q/covered", base); | |
| 164 | + | for (;;) { | |
| 165 | + | if (read(from_parent, &cmd, 1) != 1) | |
| 166 | + | return 12; | |
| 167 | + | switch (cmd) { | |
| 168 | + | case CMD_RMDIR: | |
| 169 | + | ret = rmdir(qc) ? errno : 0; | |
| 170 | + | if (write(to_parent, &ret, sizeof(ret)) != sizeof(ret)) | |
| 171 | + | return 13; | |
| 172 | + | break; | |
| 173 | + | case CMD_CLOSE_T: | |
| 174 | + | ret = close(fds[2]) ? errno : 0; | |
| 175 | + | if (write(to_parent, &ret, sizeof(ret)) != sizeof(ret)) | |
| 176 | + | return 13; | |
| 177 | + | break; | |
| 178 | + | case CMD_QUIT: | |
| 179 | + | return 0; | |
| 180 | + | default: | |
| 181 | + | return 14; | |
| 182 | + | } | |
| 183 | + | } | |
| 184 | + | } | |
| 185 | + | ||
| 186 | + | FIXTURE(mount_cover) { | |
| 187 | + | char base[DIR_LEN]; | |
| 188 | + | pid_t child; | |
| 189 | + | int to_child; | |
| 190 | + | int from_child; | |
| 191 | + | int dfd; /* P, unmounted, held */ | |
| 192 | + | int cfd; /* C, unmounted, held */ | |
| 193 | + | int fd; /* what a lookup on P finds at C's mountpoint */ | |
| 194 | + | int tfd; /* T, unmounted, held */ | |
| 195 | + | int ufd; /* U, a bind of T, unmounted, held */ | |
| 196 | + | int fan; /* fanotify group from before the user namespace, or -1 */ | |
| 197 | + | struct readdir_hold hold; /* likewise from before, uffd -1 without */ | |
| 198 | + | }; | |
| 199 | + | ||
| 200 | + | /* | |
| 201 | + | * Everything the setup has made. The harness does not run the teardown | |
| 202 | + | * when an assertion of the setup fails, so the setup calls this itself. | |
| 203 | + | */ | |
| 204 | + | static void cover_cleanup(FIXTURE_DATA(mount_cover) *self) | |
| 205 | + | { | |
| 206 | + | char cmd = CMD_QUIT; | |
| 207 | + | int status; | |
| 208 | + | ||
| 209 | + | if (self->fd >= 0) | |
| 210 | + | close(self->fd); | |
| 211 | + | if (self->cfd >= 0) | |
| 212 | + | close(self->cfd); | |
| 213 | + | if (self->dfd >= 0) | |
| 214 | + | close(self->dfd); | |
| 215 | + | if (self->tfd >= 0) | |
| 216 | + | close(self->tfd); | |
| 217 | + | if (self->ufd >= 0) | |
| 218 | + | close(self->ufd); | |
| 219 | + | if (self->fan >= 0) | |
| 220 | + | close(self->fan); | |
| 221 | + | readdir_hold_destroy(&self->hold); | |
| 222 | + | if (self->child > 0) { | |
| 223 | + | if (write(self->to_child, &cmd, 1) != 1) | |
| 224 | + | kill(self->child, SIGKILL); | |
| 225 | + | waitpid(self->child, &status, 0); | |
| 226 | + | } | |
| 227 | + | if (self->to_child >= 0) | |
| 228 | + | close(self->to_child); | |
| 229 | + | if (self->from_child >= 0) | |
| 230 | + | close(self->from_child); | |
| 231 | + | umount2(self->base, MNT_DETACH); | |
| 232 | + | rmdir(self->base); | |
| 233 | + | } | |
| 234 | + | ||
| 235 | + | static int same_file(int fd1, int fd2) | |
| 236 | + | { | |
| 237 | + | struct stat st1, st2; | |
| 238 | + | ||
| 239 | + | if (fstat(fd1, &st1) || fstat(fd2, &st2)) | |
| 240 | + | return 0; | |
| 241 | + | return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; | |
| 242 | + | } | |
| 243 | + | ||
| 244 | + | FIXTURE_SETUP(mount_cover) | |
| 245 | + | { | |
| 246 | + | int to_parent[2], to_child[2], fds[4], pidfd, status; | |
| 247 | + | char dir[PATH_LEN]; | |
| 248 | + | struct statfs sf; | |
| 249 | + | ||
| 250 | + | self->child = 0; | |
| 251 | + | self->to_child = self->from_child = -1; | |
| 252 | + | self->dfd = self->cfd = self->fd = self->tfd = self->ufd = -1; | |
| 253 | + | ||
| 254 | + | /* | |
| 255 | + | * A group for plain events takes CAP_SYS_ADMIN in the initial user | |
| 256 | + | * namespace, so get one before that is gone. An inode mark can be | |
| 257 | + | * added to it from anywhere. | |
| 258 | + | */ | |
| 259 | + | self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_CLOEXEC, O_RDONLY); | |
| 260 | + | /* same for the userfaultfd that holds a readdir in its fault */ | |
| 261 | + | readdir_hold_init(&self->hold); | |
| 262 | + | ||
| 263 | + | snprintf(self->base, sizeof(self->base), "/tmp/mount_cover.XXXXXX"); | |
| 264 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 265 | + | if (enter_userns()) { | |
| 266 | + | cover_cleanup(self); | |
| 267 | + | SKIP(return, "test requires user namespaces"); | |
| 268 | + | } | |
| 269 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0) | |
| 270 | + | cover_cleanup(self); | |
| 271 | + | ||
| 272 | + | snprintf(dir, sizeof(dir), "%s/p", self->base); | |
| 273 | + | ASSERT_EQ(pipe(to_parent), 0) | |
| 274 | + | cover_cleanup(self); | |
| 275 | + | ASSERT_EQ(pipe(to_child), 0) | |
| 276 | + | cover_cleanup(self); | |
| 277 | + | self->child = fork(); | |
| 278 | + | ASSERT_GE(self->child, 0) | |
| 279 | + | cover_cleanup(self); | |
| 280 | + | if (self->child == 0) { | |
| 281 | + | close(to_parent[0]); | |
| 282 | + | close(to_child[1]); | |
| 283 | + | _exit(cover_child(self->base, to_parent[1], to_child[0])); | |
| 284 | + | } | |
| 285 | + | close(to_parent[1]); | |
| 286 | + | close(to_child[0]); | |
| 287 | + | self->to_child = to_child[1]; | |
| 288 | + | self->from_child = to_parent[0]; | |
| 289 | + | if (read(self->from_child, fds, sizeof(fds)) != sizeof(fds)) { | |
| 290 | + | pid_t pid = self->child; | |
| 291 | + | ||
| 292 | + | waitpid(pid, &status, 0); | |
| 293 | + | self->child = 0; | |
| 294 | + | cover_cleanup(self); | |
| 295 | + | ASSERT_TRUE(false) | |
| 296 | + | TH_LOG("child failed to set up: %s %d", | |
| 297 | + | WIFEXITED(status) ? "step" : "signal", | |
| 298 | + | WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status)); | |
| 299 | + | } | |
| 300 | + | ||
| 301 | + | pidfd = syscall(__NR_pidfd_open, self->child, 0); | |
| 302 | + | ASSERT_GE(pidfd, 0) | |
| 303 | + | cover_cleanup(self); | |
| 304 | + | self->dfd = syscall(__NR_pidfd_getfd, pidfd, fds[0], 0); | |
| 305 | + | self->cfd = syscall(__NR_pidfd_getfd, pidfd, fds[1], 0); | |
| 306 | + | self->tfd = syscall(__NR_pidfd_getfd, pidfd, fds[2], 0); | |
| 307 | + | self->ufd = syscall(__NR_pidfd_getfd, pidfd, fds[3], 0); | |
| 308 | + | close(pidfd); | |
| 309 | + | ASSERT_GE(self->dfd, 0) | |
| 310 | + | cover_cleanup(self); | |
| 311 | + | ASSERT_GE(self->cfd, 0) | |
| 312 | + | cover_cleanup(self); | |
| 313 | + | ASSERT_GE(self->tfd, 0) | |
| 314 | + | cover_cleanup(self); | |
| 315 | + | ASSERT_GE(self->ufd, 0) | |
| 316 | + | cover_cleanup(self); | |
| 317 | + | ||
| 318 | + | /* unmounts P and C, C leaves its cover behind */ | |
| 319 | + | ASSERT_EQ(rmdir(dir), 0) | |
| 320 | + | cover_cleanup(self); | |
| 321 | + | /* unmounts T and U with their children, two covers on one mountpoint */ | |
| 322 | + | snprintf(dir, sizeof(dir), "%s/t", self->base); | |
| 323 | + | ASSERT_EQ(rmdir(dir), 0) | |
| 324 | + | cover_cleanup(self); | |
| 325 | + | snprintf(dir, sizeof(dir), "%s/u", self->base); | |
| 326 | + | ASSERT_EQ(rmdir(dir), 0) | |
| 327 | + | cover_cleanup(self); | |
| 328 | + | ||
| 329 | + | self->fd = openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 330 | + | ASSERT_GE(self->fd, 0) | |
| 331 | + | cover_cleanup(self); | |
| 332 | + | ASSERT_EQ(fstatfs(self->fd, &sf), 0) | |
| 333 | + | cover_cleanup(self); | |
| 334 | + | ASSERT_EQ(sf.f_type, NULL_FS_MAGIC) | |
| 335 | + | cover_cleanup(self); | |
| 336 | + | } | |
| 337 | + | ||
| 338 | + | FIXTURE_TEARDOWN(mount_cover) | |
| 339 | + | { | |
| 340 | + | cover_cleanup(self); | |
| 341 | + | } | |
| 342 | + | ||
| 343 | + | TEST_F(mount_cover, not_watchable) | |
| 344 | + | { | |
| 345 | + | char p[PATH_LEN]; | |
| 346 | + | int ifd; | |
| 347 | + | ||
| 348 | + | snprintf(p, sizeof(p), "/proc/self/fd/%d", self->fd); | |
| 349 | + | ||
| 350 | + | ifd = inotify_init1(IN_CLOEXEC); | |
| 351 | + | if (ifd < 0 && errno == ENOSYS) { | |
| 352 | + | TH_LOG("no inotify in this kernel, skipping that part"); | |
| 353 | + | } else { | |
| 354 | + | ASSERT_GE(ifd, 0); | |
| 355 | + | EXPECT_EQ(inotify_add_watch(ifd, p, IN_OPEN), -1); | |
| 356 | + | EXPECT_EQ(errno, EINVAL); | |
| 357 | + | close(ifd); | |
| 358 | + | } | |
| 359 | + | ||
| 360 | + | /* dnotify ends up at the same place */ | |
| 361 | + | EXPECT_EQ(fcntl(self->fd, F_NOTIFY, DN_ACCESS), -1); | |
| 362 | + | EXPECT_EQ(errno, EINVAL); | |
| 363 | + | ||
| 364 | + | if (self->fan < 0) { | |
| 365 | + | TH_LOG("no fanotify group without CAP_SYS_ADMIN in the initial user namespace, skipping the fanotify part"); | |
| 366 | + | return; | |
| 367 | + | } | |
| 368 | + | EXPECT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD, FAN_OPEN, self->fd, NULL), -1); | |
| 369 | + | EXPECT_EQ(errno, EINVAL); | |
| 370 | + | } | |
| 371 | + | ||
| 372 | + | TEST_F(mount_cover, not_lockable) | |
| 373 | + | { | |
| 374 | + | struct flock fl = { | |
| 375 | + | .l_type = F_RDLCK, | |
| 376 | + | .l_whence = SEEK_SET, | |
| 377 | + | }; | |
| 378 | + | ||
| 379 | + | EXPECT_EQ(flock(self->fd, LOCK_EX | LOCK_NB), -1); | |
| 380 | + | EXPECT_EQ(errno, ENOLCK); | |
| 381 | + | EXPECT_EQ(fcntl(self->fd, F_SETLK, &fl), -1); | |
| 382 | + | EXPECT_EQ(errno, ENOLCK); | |
| 383 | + | EXPECT_EQ(fcntl(self->fd, F_GETLK, &fl), -1); | |
| 384 | + | EXPECT_EQ(errno, ENOLCK); | |
| 385 | + | } | |
| 386 | + | ||
| 387 | + | /* a lease is refused for the owner and for everybody else alike */ | |
| 388 | + | TEST_F(mount_cover, not_leasable) | |
| 389 | + | { | |
| 390 | + | struct delegation_req deleg = { | |
| 391 | + | .d_type = F_RDLCK, | |
| 392 | + | }; | |
| 393 | + | ||
| 394 | + | EXPECT_EQ(fcntl(self->fd, F_SETLEASE, F_RDLCK), -1); | |
| 395 | + | EXPECT_TRUE(errno == EINVAL || errno == EACCES); | |
| 396 | + | EXPECT_EQ(fcntl(self->fd, F_SETDELEG, &deleg), -1); | |
| 397 | + | EXPECT_TRUE(errno == EINVAL || errno == EACCES); | |
| 398 | + | } | |
| 399 | + | ||
| 400 | + | TEST_F(mount_cover, not_mountable) | |
| 401 | + | { | |
| 402 | + | char p[PATH_LEN]; | |
| 403 | + | ||
| 404 | + | snprintf(p, sizeof(p), "/proc/self/fd/%d", self->fd); | |
| 405 | + | EXPECT_EQ(mount("tmpfs", p, "tmpfs", 0, NULL), -1); | |
| 406 | + | EXPECT_EQ(errno, ENOENT); | |
| 407 | + | } | |
| 408 | + | ||
| 409 | + | TEST_F(mount_cover, read_only) | |
| 410 | + | { | |
| 411 | + | struct statvfs sv; | |
| 412 | + | ||
| 413 | + | EXPECT_EQ(mkdirat(self->fd, "x", 0755), -1); | |
| 414 | + | EXPECT_EQ(errno, ENOENT); | |
| 415 | + | EXPECT_EQ(fchmod(self->fd, 0777), -1); | |
| 416 | + | EXPECT_EQ(errno, EROFS); | |
| 417 | + | /* the immutable inode is checked before the read-only mount */ | |
| 418 | + | EXPECT_EQ(faccessat(self->fd, ".", W_OK, 0), -1); | |
| 419 | + | EXPECT_EQ(errno, EPERM); | |
| 420 | + | ASSERT_EQ(fstatvfs(self->fd, &sv), 0); | |
| 421 | + | EXPECT_TRUE(sv.f_flag & ST_RDONLY); | |
| 422 | + | } | |
| 423 | + | ||
| 424 | + | /* the stand-in is a root of its own, ".." stays put */ | |
| 425 | + | TEST_F(mount_cover, island) | |
| 426 | + | { | |
| 427 | + | int fd; | |
| 428 | + | ||
| 429 | + | fd = openat(self->fd, "..", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 430 | + | ASSERT_GE(fd, 0); | |
| 431 | + | EXPECT_TRUE(same_file(fd, self->fd)); | |
| 432 | + | close(fd); | |
| 433 | + | } | |
| 434 | + | ||
| 435 | + | /* | |
| 436 | + | * C is alive for as long as the child holds it, but it can't be reached | |
| 437 | + | * through P anymore and it's a root of its own as well. | |
| 438 | + | */ | |
| 439 | + | TEST_F(mount_cover, held_child_detached) | |
| 440 | + | { | |
| 441 | + | struct statfs sf; | |
| 442 | + | int fd; | |
| 443 | + | ||
| 444 | + | ASSERT_EQ(fstatfs(self->cfd, &sf), 0); | |
| 445 | + | EXPECT_EQ(sf.f_type, TMPFS_MAGIC); | |
| 446 | + | ||
| 447 | + | fd = openat(self->cfd, "..", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 448 | + | ASSERT_GE(fd, 0); | |
| 449 | + | EXPECT_TRUE(same_file(fd, self->cfd)); | |
| 450 | + | close(fd); | |
| 451 | + | ||
| 452 | + | fd = openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 453 | + | ASSERT_GE(fd, 0); | |
| 454 | + | ASSERT_EQ(fstatfs(fd, &sf), 0); | |
| 455 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 456 | + | close(fd); | |
| 457 | + | } | |
| 458 | + | ||
| 459 | + | /* | |
| 460 | + | * The cover goes with its mountpoint: once the child has removed C's | |
| 461 | + | * mountpoint through the bind of P, the name is gone from P as well. | |
| 462 | + | * What was opened through the cover before stays open. | |
| 463 | + | */ | |
| 464 | + | TEST_F(mount_cover, cover_goes_with_mountpoint) | |
| 465 | + | { | |
| 466 | + | char cmd = CMD_RMDIR; | |
| 467 | + | struct statfs sf; | |
| 468 | + | int ret; | |
| 469 | + | ||
| 470 | + | ASSERT_EQ(write(self->to_child, &cmd, 1), 1); | |
| 471 | + | ASSERT_EQ(read(self->from_child, &ret, sizeof(ret)), sizeof(ret)); | |
| 472 | + | ASSERT_EQ(ret, 0); | |
| 473 | + | ||
| 474 | + | EXPECT_EQ(openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC), -1); | |
| 475 | + | EXPECT_EQ(errno, ENOENT); | |
| 476 | + | ASSERT_EQ(fstatfs(self->fd, &sf), 0); | |
| 477 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 478 | + | } | |
| 479 | + | ||
| 480 | + | /* | |
| 481 | + | * A readdir of the stand-in holds nothing that others wait for: one holder | |
| 482 | + | * sticks in the page fault of its buffer, and a create and a lookup of | |
| 483 | + | * another come back meanwhile. | |
| 484 | + | */ | |
| 485 | + | TEST_F(mount_cover, readdir_blocks_nobody) | |
| 486 | + | { | |
| 487 | + | bool stalled; | |
| 488 | + | ||
| 489 | + | if (self->hold.uffd < 0) | |
| 490 | + | SKIP(return, "test requires userfaultfd"); | |
| 491 | + | ASSERT_EQ(readdir_hold_check(&self->hold, self->fd, &stalled), 0); | |
| 492 | + | EXPECT_FALSE(stalled); | |
| 493 | + | } | |
| 494 | + | ||
| 495 | + | /* where a file was mounted, the stand-in is an empty regular file */ | |
| 496 | + | TEST_F(mount_cover, file_stand_in) | |
| 497 | + | { | |
| 498 | + | char src[PATH_LEN], p[PATH_LEN]; | |
| 499 | + | struct statfs sf; | |
| 500 | + | struct stat st; | |
| 501 | + | char c; | |
| 502 | + | int fd; | |
| 503 | + | ||
| 504 | + | fd = openat(self->dfd, "file", O_RDONLY | O_CLOEXEC); | |
| 505 | + | ASSERT_GE(fd, 0); | |
| 506 | + | ASSERT_EQ(fstat(fd, &st), 0); | |
| 507 | + | EXPECT_TRUE(S_ISREG(st.st_mode)); | |
| 508 | + | ASSERT_EQ(fstatfs(fd, &sf), 0); | |
| 509 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 510 | + | /* the two stand-ins are two inodes */ | |
| 511 | + | EXPECT_FALSE(same_file(fd, self->fd)); | |
| 512 | + | EXPECT_EQ(read(fd, &c, 1), 0); | |
| 513 | + | EXPECT_EQ(flock(fd, LOCK_EX | LOCK_NB), -1); | |
| 514 | + | EXPECT_EQ(errno, ENOLCK); | |
| 515 | + | ||
| 516 | + | snprintf(src, sizeof(src), "%s/src", self->base); | |
| 517 | + | ASSERT_EQ(touch(src), 0); | |
| 518 | + | snprintf(p, sizeof(p), "/proc/self/fd/%d", fd); | |
| 519 | + | EXPECT_EQ(mount(src, p, NULL, MS_BIND, NULL), -1); | |
| 520 | + | EXPECT_EQ(errno, ENOENT); | |
| 521 | + | close(fd); | |
| 522 | + | ||
| 523 | + | /* writes and truncates go nowhere, like /dev/null */ | |
| 524 | + | fd = openat(self->dfd, "file", O_WRONLY | O_TRUNC | O_CLOEXEC); | |
| 525 | + | ASSERT_GE(fd, 0); | |
| 526 | + | EXPECT_EQ(write(fd, "xy", 2), 2); | |
| 527 | + | EXPECT_EQ(ftruncate(fd, 4), 0); | |
| 528 | + | ASSERT_EQ(fstat(fd, &st), 0); | |
| 529 | + | EXPECT_EQ(st.st_size, 0); | |
| 530 | + | /* the shared inode keeps its identity */ | |
| 531 | + | EXPECT_EQ(fchmod(fd, 0600), -1); | |
| 532 | + | EXPECT_EQ(errno, EPERM); | |
| 533 | + | close(fd); | |
| 534 | + | fd = openat(self->dfd, "file", O_RDONLY | O_CLOEXEC); | |
| 535 | + | ASSERT_GE(fd, 0); | |
| 536 | + | EXPECT_EQ(read(fd, &c, 1), 0); | |
| 537 | + | close(fd); | |
| 538 | + | ||
| 539 | + | EXPECT_EQ(openat(self->dfd, "file", O_RDONLY | O_DIRECTORY | O_CLOEXEC), -1); | |
| 540 | + | EXPECT_EQ(errno, ENOTDIR); | |
| 541 | + | } | |
| 542 | + | ||
| 543 | + | /* | |
| 544 | + | * Two unmounted parents left covers on the same dentry. A lookup on | |
| 545 | + | * either finds a stand-in, and U's cover stays when T goes. | |
| 546 | + | */ | |
| 547 | + | TEST_F(mount_cover, shared_mountpoint) | |
| 548 | + | { | |
| 549 | + | char cmd = CMD_CLOSE_T; | |
| 550 | + | struct statfs sf; | |
| 551 | + | int fd, ret; | |
| 552 | + | ||
| 553 | + | fd = openat(self->tfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 554 | + | ASSERT_GE(fd, 0); | |
| 555 | + | ASSERT_EQ(fstatfs(fd, &sf), 0); | |
| 556 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 557 | + | close(fd); | |
| 558 | + | ||
| 559 | + | fd = openat(self->ufd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 560 | + | ASSERT_GE(fd, 0); | |
| 561 | + | ASSERT_EQ(fstatfs(fd, &sf), 0); | |
| 562 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 563 | + | close(fd); | |
| 564 | + | ||
| 565 | + | /* the last references to T go, with T its cover */ | |
| 566 | + | ASSERT_EQ(write(self->to_child, &cmd, 1), 1); | |
| 567 | + | ASSERT_EQ(read(self->from_child, &ret, sizeof(ret)), sizeof(ret)); | |
| 568 | + | ASSERT_EQ(ret, 0); | |
| 569 | + | close(self->tfd); | |
| 570 | + | self->tfd = -1; | |
| 571 | + | ||
| 572 | + | fd = openat(self->ufd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 573 | + | ASSERT_GE(fd, 0); | |
| 574 | + | ASSERT_EQ(fstatfs(fd, &sf), 0); | |
| 575 | + | EXPECT_EQ(sf.f_type, NULL_FS_MAGIC); | |
| 576 | + | close(fd); | |
| 577 | + | } | |
| 578 | + | ||
| 579 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/nsfs_rbind_loop_test.c mode 100644
| @@ -0,0 +1,193 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A recursive bind mount of a namespace file that lives in another mount | |
| 4 | + | * namespace copies whatever is stacked on top of it there. If that includes | |
| 5 | + | * the file of the caller's own mount namespace, or of an older one, the copy | |
| 6 | + | * would pin the namespace it is put in forever. The bind mount has to be | |
| 7 | + | * refused, a plain bind mount of the file itself still works. | |
| 8 | + | */ | |
| 9 | + | #define _GNU_SOURCE | |
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <sched.h> | |
| 13 | + | #include <stdio.h> | |
| 14 | + | #include <stdlib.h> | |
| 15 | + | #include <string.h> | |
| 16 | + | #include <unistd.h> | |
| 17 | + | #include <sys/mount.h> | |
| 18 | + | #include <sys/stat.h> | |
| 19 | + | #include <sys/wait.h> | |
| 20 | + | ||
| 21 | + | #include "../../kselftest_harness.h" | |
| 22 | + | ||
| 23 | + | #define DIR_LEN 64 | |
| 24 | + | #define PATH_LEN 128 | |
| 25 | + | ||
| 26 | + | /* Child exit codes. */ | |
| 27 | + | enum { | |
| 28 | + | CHILD_OK, | |
| 29 | + | CHILD_UNSHARE, /* could not create the newer mount namespace */ | |
| 30 | + | CHILD_PIPE, /* the parent went away */ | |
| 31 | + | CHILD_TMPFS, /* could not mount the tmpfs in the new namespace */ | |
| 32 | + | CHILD_REC_ALLOWED, /* the recursive bind mount was not refused */ | |
| 33 | + | CHILD_REC_ERRNO, /* it was refused with the wrong error */ | |
| 34 | + | CHILD_PLAIN_REFUSED, /* the plain bind mount of the file was refused */ | |
| 35 | + | }; | |
| 36 | + | ||
| 37 | + | static int write_file(const char *path, const char *s) | |
| 38 | + | { | |
| 39 | + | ssize_t n = -1; | |
| 40 | + | int fd; | |
| 41 | + | ||
| 42 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 43 | + | if (fd >= 0) { | |
| 44 | + | n = write(fd, s, strlen(s)); | |
| 45 | + | close(fd); | |
| 46 | + | } | |
| 47 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | static int create_file(const char *path) | |
| 51 | + | { | |
| 52 | + | int fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); | |
| 53 | + | ||
| 54 | + | if (fd < 0) | |
| 55 | + | return -1; | |
| 56 | + | close(fd); | |
| 57 | + | return 0; | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 61 | + | static int enter_userns(void) | |
| 62 | + | { | |
| 63 | + | uid_t uid = getuid(); | |
| 64 | + | gid_t gid = getgid(); | |
| 65 | + | char map[32]; | |
| 66 | + | ||
| 67 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 68 | + | return -1; | |
| 69 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 70 | + | return -1; | |
| 71 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 72 | + | if (write_file("/proc/self/uid_map", map)) | |
| 73 | + | return -1; | |
| 74 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 75 | + | if (write_file("/proc/self/gid_map", map)) | |
| 76 | + | return -1; | |
| 77 | + | if (setgid(0) || setuid(0)) | |
| 78 | + | return -1; | |
| 79 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 80 | + | } | |
| 81 | + | ||
| 82 | + | static int send_msg(int fd, char msg) | |
| 83 | + | { | |
| 84 | + | return write(fd, &msg, 1) == 1 ? 0 : -1; | |
| 85 | + | } | |
| 86 | + | ||
| 87 | + | static char recv_msg(int fd) | |
| 88 | + | { | |
| 89 | + | char msg; | |
| 90 | + | ||
| 91 | + | if (read(fd, &msg, 1) != 1) | |
| 92 | + | return 0; | |
| 93 | + | return msg; | |
| 94 | + | } | |
| 95 | + | ||
| 96 | + | FIXTURE(nsfs_rbind_loop) { | |
| 97 | + | char dir[DIR_LEN]; | |
| 98 | + | char x[PATH_LEN]; | |
| 99 | + | }; | |
| 100 | + | ||
| 101 | + | FIXTURE_SETUP(nsfs_rbind_loop) | |
| 102 | + | { | |
| 103 | + | snprintf(self->dir, sizeof(self->dir), "/tmp/nsfs_rbind_loop.XXXXXX"); | |
| 104 | + | ASSERT_NE(mkdtemp(self->dir), NULL); | |
| 105 | + | if (enter_userns()) { | |
| 106 | + | rmdir(self->dir); | |
| 107 | + | SKIP(return, "test requires user namespaces"); | |
| 108 | + | } | |
| 109 | + | ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0); | |
| 110 | + | snprintf(self->x, sizeof(self->x), "%s/x", self->dir); | |
| 111 | + | ASSERT_EQ(create_file(self->x), 0); | |
| 112 | + | } | |
| 113 | + | ||
| 114 | + | FIXTURE_TEARDOWN(nsfs_rbind_loop) | |
| 115 | + | { | |
| 116 | + | umount2(self->dir, MNT_DETACH); | |
| 117 | + | rmdir(self->dir); | |
| 118 | + | } | |
| 119 | + | ||
| 120 | + | /* | |
| 121 | + | * The child in the newer mount namespace binds the network namespace file | |
| 122 | + | * mount of the parent through @fd. Recursively that would copy the mount of | |
| 123 | + | * its own mount namespace file that the parent stacked on top. | |
| 124 | + | */ | |
| 125 | + | static int newer_ns_child(const char *dir, int fd, int to_parent, int from_parent) | |
| 126 | + | { | |
| 127 | + | char src[32], y[PATH_LEN]; | |
| 128 | + | ||
| 129 | + | if (unshare(CLONE_NEWNS)) | |
| 130 | + | return CHILD_UNSHARE; | |
| 131 | + | if (send_msg(to_parent, 'r') || recv_msg(from_parent) != 'g') | |
| 132 | + | return CHILD_PIPE; | |
| 133 | + | ||
| 134 | + | snprintf(y, sizeof(y), "%s/y", dir); | |
| 135 | + | if (mount("tmpfs", y, "tmpfs", 0, NULL)) | |
| 136 | + | return CHILD_TMPFS; | |
| 137 | + | snprintf(src, sizeof(src), "/proc/self/fd/%d", fd); | |
| 138 | + | snprintf(y, sizeof(y), "%s/y/f", dir); | |
| 139 | + | if (create_file(y)) | |
| 140 | + | return CHILD_TMPFS; | |
| 141 | + | ||
| 142 | + | if (!mount(src, y, NULL, MS_BIND | MS_REC, NULL)) | |
| 143 | + | return CHILD_REC_ALLOWED; | |
| 144 | + | if (errno != EINVAL) | |
| 145 | + | return CHILD_REC_ERRNO; | |
| 146 | + | if (mount(src, y, NULL, MS_BIND, NULL)) | |
| 147 | + | return CHILD_PLAIN_REFUSED; | |
| 148 | + | umount2(y, MNT_DETACH); | |
| 149 | + | return CHILD_OK; | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | TEST_F(nsfs_rbind_loop, own_ns_file_below_foreign_source) | |
| 153 | + | { | |
| 154 | + | int to_child[2], to_parent[2], fd, status; | |
| 155 | + | char p[PATH_LEN]; | |
| 156 | + | pid_t pid; | |
| 157 | + | ||
| 158 | + | snprintf(p, sizeof(p), "%s/y", self->dir); | |
| 159 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 160 | + | ||
| 161 | + | /* M, a mount of our network namespace file, held by a descriptor */ | |
| 162 | + | ASSERT_EQ(mount("/proc/self/ns/net", self->x, NULL, MS_BIND, NULL), 0); | |
| 163 | + | fd = open(self->x, O_PATH | O_CLOEXEC); | |
| 164 | + | ASSERT_GE(fd, 0); | |
| 165 | + | ||
| 166 | + | ASSERT_EQ(pipe(to_child), 0); | |
| 167 | + | ASSERT_EQ(pipe(to_parent), 0); | |
| 168 | + | pid = fork(); | |
| 169 | + | ASSERT_GE(pid, 0); | |
| 170 | + | if (pid == 0) { | |
| 171 | + | close(to_child[1]); | |
| 172 | + | close(to_parent[0]); | |
| 173 | + | _exit(newer_ns_child(self->dir, fd, to_parent[1], to_child[0])); | |
| 174 | + | } | |
| 175 | + | close(to_child[0]); | |
| 176 | + | close(to_parent[1]); | |
| 177 | + | ASSERT_EQ(recv_msg(to_parent[0]), 'r'); | |
| 178 | + | ||
| 179 | + | /* the child's mount namespace file on top of M */ | |
| 180 | + | snprintf(p, sizeof(p), "/proc/%d/ns/mnt", pid); | |
| 181 | + | ASSERT_EQ(mount(p, self->x, NULL, MS_BIND, NULL), 0); | |
| 182 | + | ||
| 183 | + | ASSERT_EQ(send_msg(to_child[1], 'g'), 0); | |
| 184 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 185 | + | ASSERT_TRUE(WIFEXITED(status)); | |
| 186 | + | ASSERT_EQ(WEXITSTATUS(status), CHILD_OK); | |
| 187 | + | ||
| 188 | + | close(fd); | |
| 189 | + | ASSERT_EQ(umount2(self->x, MNT_DETACH), 0); | |
| 190 | + | ASSERT_EQ(umount2(self->x, MNT_DETACH), 0); | |
| 191 | + | } | |
| 192 | + | ||
| 193 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/overmount_ns_file_test.c mode 100644
| @@ -0,0 +1,190 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A mount namespace file bind-mounted on top of the mount that is moved | |
| 4 | + | * onto a shared mount isn't copied to the peers and slaves. The mount that | |
| 5 | + | * already sits at the destination in a slave has to end up on top of the | |
| 6 | + | * propagated copy, not below the root of the mount namespace file where no | |
| 7 | + | * path walk ever finds it. | |
| 8 | + | */ | |
| 9 | + | #define _GNU_SOURCE | |
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <sched.h> | |
| 13 | + | #include <signal.h> | |
| 14 | + | #include <stdio.h> | |
| 15 | + | #include <stdlib.h> | |
| 16 | + | #include <string.h> | |
| 17 | + | #include <unistd.h> | |
| 18 | + | #include <sys/mount.h> | |
| 19 | + | #include <sys/stat.h> | |
| 20 | + | #include <sys/syscall.h> | |
| 21 | + | #include <sys/wait.h> | |
| 22 | + | ||
| 23 | + | #include "../wrappers.h" | |
| 24 | + | #include "../../kselftest_harness.h" | |
| 25 | + | ||
| 26 | + | #define DIR_LEN 64 | |
| 27 | + | #define PATH_LEN 128 | |
| 28 | + | ||
| 29 | + | static int write_file(const char *path, const char *s) | |
| 30 | + | { | |
| 31 | + | ssize_t n = -1; | |
| 32 | + | int fd; | |
| 33 | + | ||
| 34 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 35 | + | if (fd >= 0) { | |
| 36 | + | n = write(fd, s, strlen(s)); | |
| 37 | + | close(fd); | |
| 38 | + | } | |
| 39 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | static int create_file(const char *path, const char *s) | |
| 43 | + | { | |
| 44 | + | ssize_t n = -1; | |
| 45 | + | int fd; | |
| 46 | + | ||
| 47 | + | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); | |
| 48 | + | if (fd >= 0) { | |
| 49 | + | n = write(fd, s, strlen(s)); | |
| 50 | + | close(fd); | |
| 51 | + | } | |
| 52 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 53 | + | } | |
| 54 | + | ||
| 55 | + | /* the first bytes of the file at @path, "" if it can't be read */ | |
| 56 | + | static const char *read_file(const char *path, char *buf, size_t len) | |
| 57 | + | { | |
| 58 | + | ssize_t n = -1; | |
| 59 | + | int fd; | |
| 60 | + | ||
| 61 | + | fd = open(path, O_RDONLY | O_CLOEXEC); | |
| 62 | + | if (fd >= 0) { | |
| 63 | + | n = read(fd, buf, len - 1); | |
| 64 | + | close(fd); | |
| 65 | + | } | |
| 66 | + | buf[n > 0 ? n : 0] = '\0'; | |
| 67 | + | return buf; | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 71 | + | static int enter_userns(void) | |
| 72 | + | { | |
| 73 | + | uid_t uid = getuid(); | |
| 74 | + | gid_t gid = getgid(); | |
| 75 | + | char map[32]; | |
| 76 | + | ||
| 77 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 78 | + | return -1; | |
| 79 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 80 | + | return -1; | |
| 81 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 82 | + | if (write_file("/proc/self/uid_map", map)) | |
| 83 | + | return -1; | |
| 84 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 85 | + | if (write_file("/proc/self/gid_map", map)) | |
| 86 | + | return -1; | |
| 87 | + | if (setgid(0) || setuid(0)) | |
| 88 | + | return -1; | |
| 89 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | FIXTURE(overmount_ns_file) { | |
| 93 | + | char dir[DIR_LEN]; | |
| 94 | + | pid_t child; | |
| 95 | + | }; | |
| 96 | + | ||
| 97 | + | FIXTURE_SETUP(overmount_ns_file) | |
| 98 | + | { | |
| 99 | + | self->child = -1; | |
| 100 | + | snprintf(self->dir, sizeof(self->dir), "/tmp/overmount_ns_file.XXXXXX"); | |
| 101 | + | ASSERT_NE(mkdtemp(self->dir), NULL); | |
| 102 | + | if (enter_userns()) { | |
| 103 | + | rmdir(self->dir); | |
| 104 | + | SKIP(return, "test requires user namespaces"); | |
| 105 | + | } | |
| 106 | + | ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0); | |
| 107 | + | } | |
| 108 | + | ||
| 109 | + | FIXTURE_TEARDOWN(overmount_ns_file) | |
| 110 | + | { | |
| 111 | + | if (self->child > 0) { | |
| 112 | + | kill(self->child, SIGKILL); | |
| 113 | + | waitpid(self->child, NULL, 0); | |
| 114 | + | } | |
| 115 | + | umount2(self->dir, MNT_DETACH); | |
| 116 | + | rmdir(self->dir); | |
| 117 | + | } | |
| 118 | + | ||
| 119 | + | /* | |
| 120 | + | * A is a shared tmpfs and B its slave with Q, a bind mount of a file, on | |
| 121 | + | * B/file. S is a bind mount of a file with N, a bind mount of a newer mount | |
| 122 | + | * namespace's file, on top of it. S is moved onto A/file. Its copy S' lands | |
| 123 | + | * on B/file below Q, without N. B/file keeps reading Q and once Q is | |
| 124 | + | * unmounted it reads S'. | |
| 125 | + | */ | |
| 126 | + | TEST_F(overmount_ns_file, existing_mount_stays_on_top) | |
| 127 | + | { | |
| 128 | + | char a[PATH_LEN], b[PATH_LEN], s[PATH_LEN], p[PATH_LEN], buf[16]; | |
| 129 | + | int fd, pfd[2]; | |
| 130 | + | char c; | |
| 131 | + | ||
| 132 | + | snprintf(a, sizeof(a), "%s/A", self->dir); | |
| 133 | + | snprintf(b, sizeof(b), "%s/B", self->dir); | |
| 134 | + | snprintf(s, sizeof(s), "%s/s", self->dir); | |
| 135 | + | ASSERT_EQ(mkdir(a, 0755), 0); | |
| 136 | + | ASSERT_EQ(mkdir(b, 0755), 0); | |
| 137 | + | ASSERT_EQ(mkdir(s, 0755), 0); | |
| 138 | + | ||
| 139 | + | /* A shared, B its slave, Q on B/file */ | |
| 140 | + | ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0); | |
| 141 | + | ASSERT_EQ(mount(NULL, a, NULL, MS_SHARED, NULL), 0); | |
| 142 | + | snprintf(p, sizeof(p), "%s/A/file", self->dir); | |
| 143 | + | ASSERT_EQ(create_file(p, "A"), 0); | |
| 144 | + | ASSERT_EQ(mount(a, b, NULL, MS_BIND, NULL), 0); | |
| 145 | + | ASSERT_EQ(mount(NULL, b, NULL, MS_SLAVE, NULL), 0); | |
| 146 | + | snprintf(p, sizeof(p), "%s/Q", self->dir); | |
| 147 | + | ASSERT_EQ(create_file(p, "Q"), 0); | |
| 148 | + | snprintf(b, sizeof(b), "%s/B/file", self->dir); | |
| 149 | + | ASSERT_EQ(mount(p, b, NULL, MS_BIND, NULL), 0); | |
| 150 | + | ||
| 151 | + | /* S on s/f, pinned by a file descriptor before N goes on top */ | |
| 152 | + | ASSERT_EQ(mount("tmpfs", s, "tmpfs", 0, NULL), 0); | |
| 153 | + | snprintf(p, sizeof(p), "%s/s/f", self->dir); | |
| 154 | + | ASSERT_EQ(create_file(p, "f"), 0); | |
| 155 | + | snprintf(s, sizeof(s), "%s/s/S", self->dir); | |
| 156 | + | ASSERT_EQ(create_file(s, "S"), 0); | |
| 157 | + | ASSERT_EQ(mount(s, p, NULL, MS_BIND, NULL), 0); | |
| 158 | + | fd = open(p, O_PATH | O_CLOEXEC); | |
| 159 | + | ASSERT_GE(fd, 0); | |
| 160 | + | ||
| 161 | + | /* a newer mount namespace whose file can be bound */ | |
| 162 | + | ASSERT_EQ(pipe(pfd), 0); | |
| 163 | + | self->child = fork(); | |
| 164 | + | ASSERT_GE(self->child, 0); | |
| 165 | + | if (self->child == 0) { | |
| 166 | + | close(pfd[0]); | |
| 167 | + | if (unshare(CLONE_NEWNS) || write(pfd[1], "r", 1) != 1) | |
| 168 | + | _exit(1); | |
| 169 | + | pause(); | |
| 170 | + | _exit(0); | |
| 171 | + | } | |
| 172 | + | close(pfd[1]); | |
| 173 | + | ASSERT_EQ(read(pfd[0], &c, 1), 1); | |
| 174 | + | close(pfd[0]); | |
| 175 | + | snprintf(s, sizeof(s), "/proc/%d/ns/mnt", self->child); | |
| 176 | + | ASSERT_EQ(mount(s, p, NULL, MS_BIND, NULL), 0); | |
| 177 | + | ||
| 178 | + | ASSERT_STREQ(read_file(b, buf, sizeof(buf)), "Q"); | |
| 179 | + | ||
| 180 | + | snprintf(a, sizeof(a), "%s/A/file", self->dir); | |
| 181 | + | ASSERT_EQ(sys_move_mount(fd, "", AT_FDCWD, a, MOVE_MOUNT_F_EMPTY_PATH), 0); | |
| 182 | + | close(fd); | |
| 183 | + | ||
| 184 | + | /* Q is still on top of the copy in B and can be unmounted */ | |
| 185 | + | EXPECT_STREQ(read_file(b, buf, sizeof(buf)), "Q"); | |
| 186 | + | EXPECT_EQ(umount2(b, 0), 0); | |
| 187 | + | EXPECT_STREQ(read_file(b, buf, sizeof(buf)), "S"); | |
| 188 | + | } | |
| 189 | + | ||
| 190 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/overmount_reparent_test.c mode 100644
| @@ -0,0 +1,181 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * propagate_umount() slides a surviving overmount off a mount that is being | |
| 4 | + | * unmounted and unmounts that mount right after. If a file descriptor keeps | |
| 5 | + | * the unmounted mount alive its ->overmount is left pointing at the moved | |
| 6 | + | * mount, which is freed on its own schedule. move_mount(MOVE_MOUNT_BENEATH) | |
| 7 | + | * with such a file descriptor as the target walks ->overmount in | |
| 8 | + | * topmost_overmount() before it checks that the target is still mounted and | |
| 9 | + | * must not step into the freed mount. | |
| 10 | + | */ | |
| 11 | + | #define _GNU_SOURCE | |
| 12 | + | #include <errno.h> | |
| 13 | + | #include <fcntl.h> | |
| 14 | + | #include <sched.h> | |
| 15 | + | #include <stdio.h> | |
| 16 | + | #include <stdlib.h> | |
| 17 | + | #include <string.h> | |
| 18 | + | #include <unistd.h> | |
| 19 | + | #include <sys/mount.h> | |
| 20 | + | #include <sys/stat.h> | |
| 21 | + | #include <sys/syscall.h> | |
| 22 | + | ||
| 23 | + | #include "../wrappers.h" | |
| 24 | + | #include "../../kselftest_harness.h" | |
| 25 | + | ||
| 26 | + | #ifndef MOVE_MOUNT_BENEATH | |
| 27 | + | #define MOVE_MOUNT_BENEATH 0x00000200 | |
| 28 | + | #endif | |
| 29 | + | ||
| 30 | + | #ifndef FSCONFIG_CMD_CREATE | |
| 31 | + | #define FSCONFIG_CMD_CREATE 6 | |
| 32 | + | #endif | |
| 33 | + | ||
| 34 | + | #define DIR_LEN 64 | |
| 35 | + | #define PATH_LEN 128 | |
| 36 | + | ||
| 37 | + | static int write_file(const char *path, const char *s) | |
| 38 | + | { | |
| 39 | + | ssize_t n = -1; | |
| 40 | + | int fd; | |
| 41 | + | ||
| 42 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 43 | + | if (fd >= 0) { | |
| 44 | + | n = write(fd, s, strlen(s)); | |
| 45 | + | close(fd); | |
| 46 | + | } | |
| 47 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 51 | + | static int enter_userns(void) | |
| 52 | + | { | |
| 53 | + | uid_t uid = getuid(); | |
| 54 | + | gid_t gid = getgid(); | |
| 55 | + | char map[32]; | |
| 56 | + | ||
| 57 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 58 | + | return -1; | |
| 59 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 60 | + | return -1; | |
| 61 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 62 | + | if (write_file("/proc/self/uid_map", map)) | |
| 63 | + | return -1; | |
| 64 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 65 | + | if (write_file("/proc/self/gid_map", map)) | |
| 66 | + | return -1; | |
| 67 | + | if (setgid(0) || setuid(0)) | |
| 68 | + | return -1; | |
| 69 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 70 | + | } | |
| 71 | + | ||
| 72 | + | /* A detached tmpfs mount to serve as the source of a move. */ | |
| 73 | + | static int detached_tmpfs(void) | |
| 74 | + | { | |
| 75 | + | int sfd, mfd; | |
| 76 | + | ||
| 77 | + | sfd = sys_fsopen("tmpfs", 0); | |
| 78 | + | if (sfd < 0) | |
| 79 | + | return -1; | |
| 80 | + | if (sys_fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) { | |
| 81 | + | close(sfd); | |
| 82 | + | return -1; | |
| 83 | + | } | |
| 84 | + | mfd = sys_fsmount(sfd, 0, 0); | |
| 85 | + | close(sfd); | |
| 86 | + | return mfd; | |
| 87 | + | } | |
| 88 | + | ||
| 89 | + | FIXTURE(overmount_reparent) { | |
| 90 | + | char dir[DIR_LEN]; | |
| 91 | + | }; | |
| 92 | + | ||
| 93 | + | FIXTURE_SETUP(overmount_reparent) | |
| 94 | + | { | |
| 95 | + | snprintf(self->dir, sizeof(self->dir), "/tmp/overmount_reparent.XXXXXX"); | |
| 96 | + | ASSERT_NE(mkdtemp(self->dir), NULL); | |
| 97 | + | if (enter_userns()) { | |
| 98 | + | rmdir(self->dir); | |
| 99 | + | SKIP(return, "test requires user namespaces"); | |
| 100 | + | } | |
| 101 | + | } | |
| 102 | + | ||
| 103 | + | FIXTURE_TEARDOWN(overmount_reparent) | |
| 104 | + | { | |
| 105 | + | char p[PATH_LEN]; | |
| 106 | + | ||
| 107 | + | snprintf(p, sizeof(p), "%s/b", self->dir); | |
| 108 | + | umount2(p, MNT_DETACH); | |
| 109 | + | snprintf(p, sizeof(p), "%s/a", self->dir); | |
| 110 | + | umount2(p, MNT_DETACH); | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | /* | |
| 114 | + | * A shared mount base_a is bind-mounted to base_b as its peer. A mount X on | |
| 115 | + | * base_a/mp propagates a copy X_b onto base_b/mp. A file descriptor pins X_b, | |
| 116 | + | * then X_b is made private and an overmount is stacked on its root. | |
| 117 | + | * | |
| 118 | + | * A lazy unmount of X propagates to X_b: X_b is committed to the unmount while | |
| 119 | + | * its overmount survives, so propagate_umount() reparents the overmount onto | |
| 120 | + | * base_b and unmounts X_b, which the file descriptor keeps alive. Unmounting | |
| 121 | + | * the reparented overmount frees it. X_b->overmount now dangles unless | |
| 122 | + | * mnt_change_mountpoint() reset it. | |
| 123 | + | * | |
| 124 | + | * move_mount(MOVE_MOUNT_BENEATH) through the file descriptor makes | |
| 125 | + | * do_lock_mount() follow X_b->overmount in topmost_overmount() before it | |
| 126 | + | * notices that X_b is no longer mounted. With the pointer reset the move fails | |
| 127 | + | * cleanly with ENOENT; otherwise it reads the freed overmount. | |
| 128 | + | */ | |
| 129 | + | TEST_F(overmount_reparent, dead_overmount_holder_not_followed) | |
| 130 | + | { | |
| 131 | + | char a[PATH_LEN], b[PATH_LEN], amp[PATH_LEN], bmp[PATH_LEN]; | |
| 132 | + | int fd, mfd, ret; | |
| 133 | + | ||
| 134 | + | snprintf(a, sizeof(a), "%s/a", self->dir); | |
| 135 | + | snprintf(b, sizeof(b), "%s/b", self->dir); | |
| 136 | + | ASSERT_EQ(mkdir(a, 0755), 0); | |
| 137 | + | ASSERT_EQ(mkdir(b, 0755), 0); | |
| 138 | + | ||
| 139 | + | ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0); | |
| 140 | + | ASSERT_EQ(mount(NULL, a, NULL, MS_SHARED, NULL), 0); | |
| 141 | + | ASSERT_EQ(mount(a, b, NULL, MS_BIND, NULL), 0); | |
| 142 | + | ||
| 143 | + | snprintf(amp, sizeof(amp), "%s/a/mp", self->dir); | |
| 144 | + | snprintf(bmp, sizeof(bmp), "%s/b/mp", self->dir); | |
| 145 | + | /* base_a and base_b share one superblock, so this dir is in both. */ | |
| 146 | + | ASSERT_EQ(mkdir(amp, 0755), 0); | |
| 147 | + | ||
| 148 | + | /* X on base_a/mp propagates a copy X_b onto base_b/mp. */ | |
| 149 | + | ASSERT_EQ(mount("tmpfs", amp, "tmpfs", 0, NULL), 0); | |
| 150 | + | ||
| 151 | + | /* Pin X_b before anything is stacked on top of it. */ | |
| 152 | + | fd = open(bmp, O_PATH | O_CLOEXEC); | |
| 153 | + | ASSERT_GE(fd, 0); | |
| 154 | + | ||
| 155 | + | /* Keep the overmount local to X_b. */ | |
| 156 | + | ASSERT_EQ(mount(NULL, bmp, NULL, MS_PRIVATE, NULL), 0); | |
| 157 | + | ||
| 158 | + | /* The overmount on X_b's root: X_b->overmount points at it. */ | |
| 159 | + | ASSERT_EQ(mount("tmpfs", bmp, "tmpfs", 0, NULL), 0); | |
| 160 | + | ||
| 161 | + | /* Reparents the overmount onto base_b and unmounts X_b. */ | |
| 162 | + | ASSERT_EQ(umount2(amp, MNT_DETACH), 0); | |
| 163 | + | ||
| 164 | + | /* Free the reparented overmount. */ | |
| 165 | + | ASSERT_EQ(umount2(bmp, MNT_DETACH), 0); | |
| 166 | + | usleep(100000); | |
| 167 | + | ||
| 168 | + | mfd = detached_tmpfs(); | |
| 169 | + | ASSERT_GE(mfd, 0); | |
| 170 | + | ||
| 171 | + | ret = sys_move_mount(mfd, "", fd, "", | |
| 172 | + | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH | | |
| 173 | + | MOVE_MOUNT_BENEATH); | |
| 174 | + | EXPECT_EQ(ret, -1); | |
| 175 | + | EXPECT_EQ(errno, ENOENT); | |
| 176 | + | ||
| 177 | + | close(mfd); | |
| 178 | + | close(fd); | |
| 179 | + | } | |
| 180 | + | ||
| 181 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/mount_cycle/settings mode 100644
| @@ -0,0 +1 @@ | |||
| 1 | + | timeout=300 | |
added tools/testing/selftests/filesystems/mount_cycle/unmounted_tree_test.c mode 100644
| @@ -0,0 +1,484 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * An unmounted mount tree that a file descriptor keeps alive is put and | |
| 4 | + | * vacated behind the root's back, so nothing may walk it under | |
| 5 | + | * namespace_sem: it can't be copied recursively and its propagation can't | |
| 6 | + | * be changed. The mount at its root alone can still be copied and that copy | |
| 7 | + | * is an ordinary mount. | |
| 8 | + | */ | |
| 9 | + | #define _GNU_SOURCE | |
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <sched.h> | |
| 13 | + | #include <stdio.h> | |
| 14 | + | #include <stdlib.h> | |
| 15 | + | #include <string.h> | |
| 16 | + | #include <sys/mount.h> | |
| 17 | + | #include <sys/stat.h> | |
| 18 | + | #include <sys/syscall.h> | |
| 19 | + | #include <sys/wait.h> | |
| 20 | + | #include <unistd.h> | |
| 21 | + | #include <linux/mount.h> | |
| 22 | + | ||
| 23 | + | #include "../wrappers.h" | |
| 24 | + | #include "../../kselftest_harness.h" | |
| 25 | + | ||
| 26 | + | #ifndef __NR_mount_setattr | |
| 27 | + | #define __NR_mount_setattr 442 | |
| 28 | + | #endif | |
| 29 | + | ||
| 30 | + | #ifndef __NR_pidfd_open | |
| 31 | + | #define __NR_pidfd_open 434 | |
| 32 | + | #endif | |
| 33 | + | ||
| 34 | + | #define PATH_LEN 64 | |
| 35 | + | ||
| 36 | + | static inline int sys_mount_setattr(int dfd, const char *path, unsigned int flags, | |
| 37 | + | struct mount_attr *attr, size_t size) | |
| 38 | + | { | |
| 39 | + | return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | static inline int sys_pidfd_open(pid_t pid, unsigned int flags) | |
| 43 | + | { | |
| 44 | + | return syscall(__NR_pidfd_open, pid, flags); | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | static int write_file(const char *path, const char *s) | |
| 48 | + | { | |
| 49 | + | ssize_t n = -1; | |
| 50 | + | int fd; | |
| 51 | + | ||
| 52 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 53 | + | if (fd >= 0) { | |
| 54 | + | n = write(fd, s, strlen(s)); | |
| 55 | + | close(fd); | |
| 56 | + | } | |
| 57 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | static int touch(const char *path) | |
| 61 | + | { | |
| 62 | + | int fd; | |
| 63 | + | ||
| 64 | + | fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644); | |
| 65 | + | if (fd < 0) | |
| 66 | + | return -1; | |
| 67 | + | close(fd); | |
| 68 | + | return 0; | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | /* Become root in a new user namespace with a private mount namespace. */ | |
| 72 | + | static int enter_userns(void) | |
| 73 | + | { | |
| 74 | + | uid_t uid = getuid(); | |
| 75 | + | gid_t gid = getgid(); | |
| 76 | + | char map[32]; | |
| 77 | + | ||
| 78 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 79 | + | return -1; | |
| 80 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 81 | + | return -1; | |
| 82 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 83 | + | if (write_file("/proc/self/uid_map", map)) | |
| 84 | + | return -1; | |
| 85 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 86 | + | if (write_file("/proc/self/gid_map", map)) | |
| 87 | + | return -1; | |
| 88 | + | if (setgid(0) || setuid(0)) | |
| 89 | + | return -1; | |
| 90 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | /* A private mount namespace of our own, all mounts private. */ | |
| 94 | + | static int own_mntns(void) | |
| 95 | + | { | |
| 96 | + | if (unshare(CLONE_NEWNS)) | |
| 97 | + | return -1; | |
| 98 | + | return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL); | |
| 99 | + | } | |
| 100 | + | ||
| 101 | + | FIXTURE(unmounted_tree) { | |
| 102 | + | char dir[PATH_LEN]; | |
| 103 | + | }; | |
| 104 | + | ||
| 105 | + | FIXTURE_SETUP(unmounted_tree) | |
| 106 | + | { | |
| 107 | + | snprintf(self->dir, sizeof(self->dir), "/tmp/unmounted_tree.XXXXXX"); | |
| 108 | + | ASSERT_NE(mkdtemp(self->dir), NULL); | |
| 109 | + | if (enter_userns()) { | |
| 110 | + | rmdir(self->dir); | |
| 111 | + | SKIP(return, "test requires user namespaces"); | |
| 112 | + | } | |
| 113 | + | ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0); | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | FIXTURE_TEARDOWN(unmounted_tree) | |
| 117 | + | { | |
| 118 | + | umount2(self->dir, MNT_DETACH); | |
| 119 | + | rmdir(self->dir); | |
| 120 | + | } | |
| 121 | + | ||
| 122 | + | /* A recursive copy of the mount @fd refers to must fail with EINVAL. */ | |
| 123 | + | static void assert_not_walked(struct __test_metadata *_metadata, int fd, | |
| 124 | + | const char *target) | |
| 125 | + | { | |
| 126 | + | char link[PATH_LEN]; | |
| 127 | + | int tfd; | |
| 128 | + | ||
| 129 | + | snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); | |
| 130 | + | EXPECT_EQ(mount(link, target, NULL, MS_BIND | MS_REC, NULL), -1); | |
| 131 | + | EXPECT_EQ(errno, EINVAL); | |
| 132 | + | ||
| 133 | + | tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | AT_RECURSIVE | OPEN_TREE_CLONE | | |
| 134 | + | OPEN_TREE_CLOEXEC); | |
| 135 | + | EXPECT_LT(tfd, 0); | |
| 136 | + | EXPECT_EQ(errno, EINVAL); | |
| 137 | + | if (tfd >= 0) | |
| 138 | + | close(tfd); | |
| 139 | + | } | |
| 140 | + | ||
| 141 | + | /* The mount @fd refers to can be copied on its own and mounted on @target. */ | |
| 142 | + | static void assert_root_copied(struct __test_metadata *_metadata, int fd, | |
| 143 | + | const char *target) | |
| 144 | + | { | |
| 145 | + | int tfd; | |
| 146 | + | ||
| 147 | + | tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 148 | + | ASSERT_GE(tfd, 0); | |
| 149 | + | ASSERT_EQ(sys_move_mount(tfd, "", AT_FDCWD, target, MOVE_MOUNT_F_EMPTY_PATH), 0); | |
| 150 | + | close(tfd); | |
| 151 | + | ASSERT_EQ(umount2(target, MNT_DETACH), 0); | |
| 152 | + | } | |
| 153 | + | ||
| 154 | + | /* | |
| 155 | + | * A lazily unmounted bind mount of an nsfs file, kept alive by an fd, can't | |
| 156 | + | * be copied recursively anymore. Copying the mount itself still works and | |
| 157 | + | * so does copying a mounted bind mount of the same file. | |
| 158 | + | */ | |
| 159 | + | TEST_F(unmounted_tree, detached_nsfs_bind_not_walked) | |
| 160 | + | { | |
| 161 | + | char x[PATH_LEN], y[PATH_LEN], z[PATH_LEN], link[PATH_LEN]; | |
| 162 | + | int fd, tfd; | |
| 163 | + | ||
| 164 | + | snprintf(x, sizeof(x), "%s/x", self->dir); | |
| 165 | + | snprintf(y, sizeof(y), "%s/y", self->dir); | |
| 166 | + | snprintf(z, sizeof(z), "%s/z", self->dir); | |
| 167 | + | ASSERT_EQ(touch(x), 0); | |
| 168 | + | ASSERT_EQ(touch(y), 0); | |
| 169 | + | ASSERT_EQ(touch(z), 0); | |
| 170 | + | ||
| 171 | + | ASSERT_EQ(mount("/proc/self/ns/net", x, NULL, MS_BIND, NULL), 0); | |
| 172 | + | fd = open(x, O_PATH | O_CLOEXEC); | |
| 173 | + | ASSERT_GE(fd, 0); | |
| 174 | + | ASSERT_EQ(umount2(x, MNT_DETACH), 0); | |
| 175 | + | ||
| 176 | + | assert_not_walked(_metadata, fd, y); | |
| 177 | + | ||
| 178 | + | snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); | |
| 179 | + | ASSERT_EQ(mount(link, y, NULL, MS_BIND, NULL), 0); | |
| 180 | + | ASSERT_EQ(umount2(y, MNT_DETACH), 0); | |
| 181 | + | assert_root_copied(_metadata, fd, y); | |
| 182 | + | /* opening it is fine too */ | |
| 183 | + | tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLOEXEC); | |
| 184 | + | ASSERT_GE(tfd, 0); | |
| 185 | + | close(tfd); | |
| 186 | + | close(fd); | |
| 187 | + | ||
| 188 | + | ASSERT_EQ(mount("/proc/self/ns/net", y, NULL, MS_BIND, NULL), 0); | |
| 189 | + | ASSERT_EQ(mount(y, z, NULL, MS_BIND | MS_REC, NULL), 0); | |
| 190 | + | tfd = sys_open_tree(AT_FDCWD, y, AT_RECURSIVE | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 191 | + | ASSERT_GE(tfd, 0); | |
| 192 | + | close(tfd); | |
| 193 | + | } | |
| 194 | + | ||
| 195 | + | /* Bind-mount the pidfd @pidfd on @target the way pidfd_bind_mount does. */ | |
| 196 | + | static int bind_pidfd(int pidfd, const char *target) | |
| 197 | + | { | |
| 198 | + | int tfd, ret; | |
| 199 | + | ||
| 200 | + | tfd = sys_open_tree(pidfd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 201 | + | if (tfd < 0) | |
| 202 | + | return -1; | |
| 203 | + | ret = sys_move_mount(tfd, "", AT_FDCWD, target, MOVE_MOUNT_F_EMPTY_PATH); | |
| 204 | + | close(tfd); | |
| 205 | + | return ret; | |
| 206 | + | } | |
| 207 | + | ||
| 208 | + | /* The same for a bind mount of a pidfd. */ | |
| 209 | + | TEST_F(unmounted_tree, detached_pidfs_bind_not_walked) | |
| 210 | + | { | |
| 211 | + | char x[PATH_LEN], y[PATH_LEN]; | |
| 212 | + | int pidfd, fd, tfd; | |
| 213 | + | ||
| 214 | + | snprintf(x, sizeof(x), "%s/x", self->dir); | |
| 215 | + | snprintf(y, sizeof(y), "%s/y", self->dir); | |
| 216 | + | ASSERT_EQ(touch(x), 0); | |
| 217 | + | ASSERT_EQ(touch(y), 0); | |
| 218 | + | ||
| 219 | + | pidfd = sys_pidfd_open(getpid(), 0); | |
| 220 | + | ASSERT_GE(pidfd, 0); | |
| 221 | + | ASSERT_EQ(bind_pidfd(pidfd, x), 0); | |
| 222 | + | fd = open(x, O_PATH | O_CLOEXEC); | |
| 223 | + | ASSERT_GE(fd, 0); | |
| 224 | + | ASSERT_EQ(umount2(x, MNT_DETACH), 0); | |
| 225 | + | ||
| 226 | + | assert_not_walked(_metadata, fd, y); | |
| 227 | + | assert_root_copied(_metadata, fd, y); | |
| 228 | + | close(fd); | |
| 229 | + | ||
| 230 | + | ASSERT_EQ(bind_pidfd(pidfd, y), 0); | |
| 231 | + | tfd = sys_open_tree(AT_FDCWD, y, AT_RECURSIVE | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 232 | + | ASSERT_GE(tfd, 0); | |
| 233 | + | close(tfd); | |
| 234 | + | close(pidfd); | |
| 235 | + | } | |
| 236 | + | ||
| 237 | + | /* What a child in its own mount namespace reports back. */ | |
| 238 | + | enum { | |
| 239 | + | CHILD_OK, | |
| 240 | + | CHILD_NS, /* could not set up the mount namespace */ | |
| 241 | + | CHILD_MOUNT, /* could not set up the mounts */ | |
| 242 | + | CHILD_PIPE, /* the parent went away */ | |
| 243 | + | CHILD_WALKED, /* the detached tree was copied recursively */ | |
| 244 | + | CHILD_ROOT_REFUSED, /* the mount at its root wasn't copied */ | |
| 245 | + | CHILD_STILL_MOUNTED, /* the copy survived the unlink of its mountpoint */ | |
| 246 | + | CHILD_ERRNO, /* refused, but not with EINVAL */ | |
| 247 | + | }; | |
| 248 | + | ||
| 249 | + | static const char *child_reason(int code) | |
| 250 | + | { | |
| 251 | + | static const char *const reasons[] = { | |
| 252 | + | [CHILD_OK] = "ok", | |
| 253 | + | [CHILD_NS] = "could not set up the mount namespace", | |
| 254 | + | [CHILD_MOUNT] = "could not set up the mounts", | |
| 255 | + | [CHILD_PIPE] = "the parent went away", | |
| 256 | + | [CHILD_WALKED] = "the detached tree was copied recursively", | |
| 257 | + | [CHILD_ROOT_REFUSED] = "the mount at its root wasn't copied", | |
| 258 | + | [CHILD_STILL_MOUNTED] = "the copy survived the unlink of its mountpoint", | |
| 259 | + | [CHILD_ERRNO] = "refused, but not with EINVAL", | |
| 260 | + | }; | |
| 261 | + | ||
| 262 | + | if (code < 0 || code >= (int)(sizeof(reasons) / sizeof(reasons[0]))) | |
| 263 | + | return "child died"; | |
| 264 | + | return reasons[code]; | |
| 265 | + | } | |
| 266 | + | ||
| 267 | + | struct child_args { | |
| 268 | + | const char *x; /* the nsfs bind mount goes here */ | |
| 269 | + | const char *s; /* a file to bind on top of it */ | |
| 270 | + | const char *y; /* a target to copy to */ | |
| 271 | + | }; | |
| 272 | + | ||
| 273 | + | /* | |
| 274 | + | * Run @fn in a child in a mount namespace of its own. Once the child | |
| 275 | + | * reports that its mounts are in place, unlink @victim here, where it is a | |
| 276 | + | * plain file, and let the child carry on. Returns what the child reported. | |
| 277 | + | */ | |
| 278 | + | static int run_child(struct __test_metadata *_metadata, | |
| 279 | + | int (*fn)(const struct child_args *, int, int), | |
| 280 | + | const struct child_args *a, const char *victim) | |
| 281 | + | { | |
| 282 | + | int to_parent[2], to_child[2], status; | |
| 283 | + | pid_t pid; | |
| 284 | + | char c; | |
| 285 | + | ||
| 286 | + | if (pipe(to_parent) || pipe(to_child)) | |
| 287 | + | return -1; | |
| 288 | + | pid = fork(); | |
| 289 | + | if (pid < 0) | |
| 290 | + | return -1; | |
| 291 | + | if (pid == 0) { | |
| 292 | + | close(to_parent[0]); | |
| 293 | + | close(to_child[1]); | |
| 294 | + | _exit(fn(a, to_parent[1], to_child[0])); | |
| 295 | + | } | |
| 296 | + | close(to_parent[1]); | |
| 297 | + | close(to_child[0]); | |
| 298 | + | if (read(to_parent[0], &c, 1) == 1) { | |
| 299 | + | /* not a mountpoint in this namespace, so the file can go */ | |
| 300 | + | EXPECT_EQ(unlink(victim), 0); | |
| 301 | + | EXPECT_EQ(write(to_child[1], "", 1), 1); | |
| 302 | + | } | |
| 303 | + | close(to_parent[0]); | |
| 304 | + | close(to_child[1]); | |
| 305 | + | if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) | |
| 306 | + | return -1; | |
| 307 | + | return WEXITSTATUS(status); | |
| 308 | + | } | |
| 309 | + | ||
| 310 | + | /* | |
| 311 | + | * An nsfs bind mount on @x, an fd on it and a bind mount of @s on top. Once | |
| 312 | + | * the parent has unlinked @x underneath, the first mount is detached and the | |
| 313 | + | * second one, which stayed attached to it, has been vacated. The tree may | |
| 314 | + | * not be walked, the mount at its root may still be copied. | |
| 315 | + | */ | |
| 316 | + | static int vacant_child(const struct child_args *a, int to_parent, int from_parent) | |
| 317 | + | { | |
| 318 | + | char link[PATH_LEN]; | |
| 319 | + | int fd, tfd; | |
| 320 | + | char c; | |
| 321 | + | ||
| 322 | + | if (own_mntns()) | |
| 323 | + | return CHILD_NS; | |
| 324 | + | if (mount("/proc/self/ns/net", a->x, NULL, MS_BIND, NULL)) | |
| 325 | + | return CHILD_MOUNT; | |
| 326 | + | fd = open(a->x, O_PATH | O_CLOEXEC); | |
| 327 | + | if (fd < 0 || mount(a->s, a->x, NULL, MS_BIND, NULL)) | |
| 328 | + | return CHILD_MOUNT; | |
| 329 | + | ||
| 330 | + | if (write(to_parent, "", 1) != 1 || read(from_parent, &c, 1) != 1) | |
| 331 | + | return CHILD_PIPE; | |
| 332 | + | ||
| 333 | + | tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | AT_RECURSIVE | OPEN_TREE_CLONE | | |
| 334 | + | OPEN_TREE_CLOEXEC); | |
| 335 | + | if (tfd >= 0) { | |
| 336 | + | close(tfd); | |
| 337 | + | return CHILD_WALKED; | |
| 338 | + | } | |
| 339 | + | if (errno != EINVAL) | |
| 340 | + | return CHILD_ERRNO; | |
| 341 | + | snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); | |
| 342 | + | if (!mount(link, a->y, NULL, MS_BIND | MS_REC, NULL)) | |
| 343 | + | return CHILD_WALKED; | |
| 344 | + | if (errno != EINVAL) | |
| 345 | + | return CHILD_ERRNO; | |
| 346 | + | ||
| 347 | + | tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); | |
| 348 | + | if (tfd < 0) | |
| 349 | + | return CHILD_ROOT_REFUSED; | |
| 350 | + | close(tfd); | |
| 351 | + | /* the last reference on the detached mount collects the vacant one */ | |
| 352 | + | close(fd); | |
| 353 | + | return CHILD_OK; | |
| 354 | + | } | |
| 355 | + | ||
| 356 | + | /* | |
| 357 | + | * unlink() of the child's mountpoint from here, where it is a plain file, | |
| 358 | + | * detaches the child's nsfs bind mount with the mount on top left attached | |
| 359 | + | * to it. The mount on top loses its last reference right there and is | |
| 360 | + | * vacated. The child must not be able to walk that tree. | |
| 361 | + | */ | |
| 362 | + | TEST_F(unmounted_tree, vacant_child_not_copied) | |
| 363 | + | { | |
| 364 | + | char x[PATH_LEN], s[PATH_LEN], y[PATH_LEN]; | |
| 365 | + | struct child_args a = { .x = x, .s = s, .y = y }; | |
| 366 | + | int ret; | |
| 367 | + | ||
| 368 | + | snprintf(x, sizeof(x), "%s/x", self->dir); | |
| 369 | + | snprintf(s, sizeof(s), "%s/s", self->dir); | |
| 370 | + | snprintf(y, sizeof(y), "%s/y", self->dir); | |
| 371 | + | ASSERT_EQ(touch(x), 0); | |
| 372 | + | ASSERT_EQ(touch(s), 0); | |
| 373 | + | ASSERT_EQ(touch(y), 0); | |
| 374 | + | ||
| 375 | + | ret = run_child(_metadata, vacant_child, &a, x); | |
| 376 | + | ASSERT_EQ(ret, CHILD_OK) | |
| 377 | + | TH_LOG("child: %s", child_reason(ret)); | |
| 378 | + | } | |
| 379 | + | ||
| 380 | + | /* | |
| 381 | + | * An nsfs bind mount on @x, lazily unmounted but kept alive by an fd, and a | |
| 382 | + | * copy of it on @y. That copy is a mount like any other: once the parent has | |
| 383 | + | * unlinked @y underneath, it is unmounted and its attributes can't be changed | |
| 384 | + | * anymore. A copy that took the flag along is only unhooked, stays in the | |
| 385 | + | * namespace and still takes the change. | |
| 386 | + | */ | |
| 387 | + | static int ordinary_copy(const struct child_args *a, int to_parent, int from_parent) | |
| 388 | + | { | |
| 389 | + | struct mount_attr attr = { | |
| 390 | + | .attr_set = MOUNT_ATTR_NOSUID, | |
| 391 | + | }; | |
| 392 | + | char link[PATH_LEN]; | |
| 393 | + | int fd, fdy; | |
| 394 | + | char c; | |
| 395 | + | ||
| 396 | + | if (own_mntns()) | |
| 397 | + | return CHILD_NS; | |
| 398 | + | if (mount("/proc/self/ns/net", a->x, NULL, MS_BIND, NULL)) | |
| 399 | + | return CHILD_MOUNT; | |
| 400 | + | fd = open(a->x, O_PATH | O_CLOEXEC); | |
| 401 | + | if (fd < 0 || umount2(a->x, MNT_DETACH)) | |
| 402 | + | return CHILD_MOUNT; | |
| 403 | + | snprintf(link, sizeof(link), "/proc/self/fd/%d", fd); | |
| 404 | + | if (mount(link, a->y, NULL, MS_BIND, NULL)) | |
| 405 | + | return CHILD_MOUNT; | |
| 406 | + | fdy = open(a->y, O_PATH | O_CLOEXEC); | |
| 407 | + | if (fdy < 0) | |
| 408 | + | return CHILD_MOUNT; | |
| 409 | + | ||
| 410 | + | if (write(to_parent, "", 1) != 1 || read(from_parent, &c, 1) != 1) | |
| 411 | + | return CHILD_PIPE; | |
| 412 | + | ||
| 413 | + | if (!sys_mount_setattr(fdy, "", AT_EMPTY_PATH, &attr, sizeof(attr))) | |
| 414 | + | return CHILD_STILL_MOUNTED; | |
| 415 | + | if (errno != EINVAL) | |
| 416 | + | return CHILD_ERRNO; | |
| 417 | + | close(fdy); | |
| 418 | + | close(fd); | |
| 419 | + | return CHILD_OK; | |
| 420 | + | } | |
| 421 | + | ||
| 422 | + | /* | |
| 423 | + | * A copy of a detached nsfs bind mount must not take after its source and | |
| 424 | + | * read as unmounted. unlink() of its mountpoint from here unmounts it like | |
| 425 | + | * any other mount, so the child can't change its attributes anymore. | |
| 426 | + | */ | |
| 427 | + | TEST_F(unmounted_tree, copy_of_detached_bind_is_ordinary) | |
| 428 | + | { | |
| 429 | + | char x[PATH_LEN], y[PATH_LEN]; | |
| 430 | + | struct child_args a = { .x = x, .y = y }; | |
| 431 | + | int ret; | |
| 432 | + | ||
| 433 | + | snprintf(x, sizeof(x), "%s/x", self->dir); | |
| 434 | + | snprintf(y, sizeof(y), "%s/y", self->dir); | |
| 435 | + | ASSERT_EQ(touch(x), 0); | |
| 436 | + | ASSERT_EQ(touch(y), 0); | |
| 437 | + | ||
| 438 | + | ret = run_child(_metadata, ordinary_copy, &a, y); | |
| 439 | + | ASSERT_EQ(ret, CHILD_OK) | |
| 440 | + | TH_LOG("child: %s", child_reason(ret)); | |
| 441 | + | } | |
| 442 | + | ||
| 443 | + | /* | |
| 444 | + | * mount_setattr() may change the propagation of a detached tree while that | |
| 445 | + | * tree is still the root of an anonymous mount namespace, but not once the | |
| 446 | + | * tree has been dissolved and only a second fd keeps its root alive. | |
| 447 | + | */ | |
| 448 | + | TEST_F(unmounted_tree, detached_tree_setattr_refused) | |
| 449 | + | { | |
| 450 | + | struct mount_attr attr = { | |
| 451 | + | .propagation = MS_SHARED, | |
| 452 | + | }; | |
| 453 | + | char a[PATH_LEN], b[PATH_LEN]; | |
| 454 | + | int tfd, fd; | |
| 455 | + | ||
| 456 | + | snprintf(a, sizeof(a), "%s/a", self->dir); | |
| 457 | + | snprintf(b, sizeof(b), "%s/a/b", self->dir); | |
| 458 | + | ASSERT_EQ(mkdir(a, 0755), 0); | |
| 459 | + | ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0); | |
| 460 | + | ASSERT_EQ(mkdir(b, 0755), 0); | |
| 461 | + | ASSERT_EQ(mount("tmpfs", b, "tmpfs", 0, NULL), 0); | |
| 462 | + | ||
| 463 | + | tfd = sys_open_tree(AT_FDCWD, self->dir, AT_RECURSIVE | OPEN_TREE_CLONE | | |
| 464 | + | OPEN_TREE_CLOEXEC); | |
| 465 | + | ASSERT_GE(tfd, 0); | |
| 466 | + | ASSERT_EQ(sys_mount_setattr(tfd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), 0); | |
| 467 | + | attr.propagation = MS_PRIVATE; | |
| 468 | + | ASSERT_EQ(sys_mount_setattr(tfd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), 0); | |
| 469 | + | ||
| 470 | + | /* a second reference on the root, then dissolve the tree */ | |
| 471 | + | fd = sys_open_tree(tfd, "", AT_EMPTY_PATH | OPEN_TREE_CLOEXEC); | |
| 472 | + | ASSERT_GE(fd, 0); | |
| 473 | + | close(tfd); | |
| 474 | + | ||
| 475 | + | attr.propagation = MS_SHARED; | |
| 476 | + | ASSERT_EQ(sys_mount_setattr(fd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), -1); | |
| 477 | + | ASSERT_EQ(errno, EINVAL); | |
| 478 | + | attr.propagation = MS_PRIVATE; | |
| 479 | + | ASSERT_EQ(sys_mount_setattr(fd, "", AT_EMPTY_PATH, &attr, sizeof(attr)), -1); | |
| 480 | + | ASSERT_EQ(errno, EINVAL); | |
| 481 | + | close(fd); | |
| 482 | + | } | |
| 483 | + | ||
| 484 | + | TEST_HARNESS_MAIN | |
modified tools/testing/selftests/filesystems/open_tree_ns/.gitignore
| @@ -1 +1,2 @@ | |||
| 1 | 1 | open_tree_ns_test | |
| 2 | + | open_tree_ns_covered_test | |
modified tools/testing/selftests/filesystems/open_tree_ns/Makefile
| @@ -1,5 +1,5 @@ | |||
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | - | TEST_GEN_PROGS := open_tree_ns_test | |
| 2 | + | TEST_GEN_PROGS := open_tree_ns_test open_tree_ns_covered_test | |
| 3 | 3 | ||
| 4 | 4 | CFLAGS += -Wall -O0 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) | |
| 5 | 5 | LDLIBS := -lcap | |
added tools/testing/selftests/filesystems/open_tree_ns/open_tree_ns_covered_test.c mode 100644
| @@ -0,0 +1,195 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * open_tree(OPEN_TREE_NAMESPACE) by a caller that isn't privileged over the | |
| 4 | + | * mount namespace it copies from must not reveal what the mounts below the | |
| 5 | + | * copied mount cover. Without AT_RECURSIVE the copy is refused when there's | |
| 6 | + | * anything mounted below the requested directory. With AT_RECURSIVE | |
| 7 | + | * unbindable mounts are copied as well. | |
| 8 | + | */ | |
| 9 | + | #define _GNU_SOURCE | |
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <sched.h> | |
| 13 | + | #include <stdio.h> | |
| 14 | + | #include <stdlib.h> | |
| 15 | + | #include <string.h> | |
| 16 | + | #include <unistd.h> | |
| 17 | + | #include <sys/mount.h> | |
| 18 | + | #include <sys/stat.h> | |
| 19 | + | #include <sys/wait.h> | |
| 20 | + | ||
| 21 | + | #include "../wrappers.h" | |
| 22 | + | #include "../../kselftest_harness.h" | |
| 23 | + | ||
| 24 | + | #ifndef OPEN_TREE_NAMESPACE | |
| 25 | + | #define OPEN_TREE_NAMESPACE (1 << 1) | |
| 26 | + | #endif | |
| 27 | + | ||
| 28 | + | #define DIR_LEN 64 | |
| 29 | + | #define PATH_LEN 128 | |
| 30 | + | ||
| 31 | + | /* Child exit codes. */ | |
| 32 | + | enum { | |
| 33 | + | CHILD_OK, | |
| 34 | + | CHILD_USERNS, /* could not create the child user namespace */ | |
| 35 | + | CHILD_NONREC_ALLOWED, /* the non-recursive copy was not refused */ | |
| 36 | + | CHILD_NONREC_ERRNO, /* it was refused with the wrong error */ | |
| 37 | + | CHILD_REC_REFUSED, /* the recursive copy failed */ | |
| 38 | + | CHILD_SETNS, /* could not enter the new mount namespace */ | |
| 39 | + | CHILD_NO_COVER, /* the covering mount is missing in the copy */ | |
| 40 | + | CHILD_REVEALED, /* the covered file is visible in the copy */ | |
| 41 | + | }; | |
| 42 | + | ||
| 43 | + | static int write_file(const char *path, const char *s) | |
| 44 | + | { | |
| 45 | + | ssize_t n = -1; | |
| 46 | + | int fd; | |
| 47 | + | ||
| 48 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 49 | + | if (fd >= 0) { | |
| 50 | + | n = write(fd, s, strlen(s)); | |
| 51 | + | close(fd); | |
| 52 | + | } | |
| 53 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | static int create_file(const char *path, const char *s) | |
| 57 | + | { | |
| 58 | + | ssize_t n = -1; | |
| 59 | + | int fd; | |
| 60 | + | ||
| 61 | + | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); | |
| 62 | + | if (fd >= 0) { | |
| 63 | + | n = write(fd, s, strlen(s)); | |
| 64 | + | close(fd); | |
| 65 | + | } | |
| 66 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | /* Become root in a new user namespace, the uid @uid is mapped to 0. */ | |
| 70 | + | static int enter_userns(uid_t uid, gid_t gid) | |
| 71 | + | { | |
| 72 | + | char map[32]; | |
| 73 | + | ||
| 74 | + | if (unshare(CLONE_NEWUSER)) | |
| 75 | + | return -1; | |
| 76 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 77 | + | return -1; | |
| 78 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 79 | + | if (write_file("/proc/self/uid_map", map)) | |
| 80 | + | return -1; | |
| 81 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 82 | + | if (write_file("/proc/self/gid_map", map)) | |
| 83 | + | return -1; | |
| 84 | + | return setgid(0) || setuid(0) ? -1 : 0; | |
| 85 | + | } | |
| 86 | + | ||
| 87 | + | FIXTURE(open_tree_ns_covered) { | |
| 88 | + | char dir[DIR_LEN]; | |
| 89 | + | char cover[PATH_LEN]; | |
| 90 | + | }; | |
| 91 | + | ||
| 92 | + | FIXTURE_VARIANT(open_tree_ns_covered) { | |
| 93 | + | int propagation; | |
| 94 | + | }; | |
| 95 | + | ||
| 96 | + | FIXTURE_VARIANT_ADD(open_tree_ns_covered, private_cover) { | |
| 97 | + | .propagation = MS_PRIVATE, | |
| 98 | + | }; | |
| 99 | + | ||
| 100 | + | FIXTURE_VARIANT_ADD(open_tree_ns_covered, unbindable_cover) { | |
| 101 | + | .propagation = MS_UNBINDABLE, | |
| 102 | + | }; | |
| 103 | + | ||
| 104 | + | /* | |
| 105 | + | * Root in a user namespace owns a private mount namespace with a tmpfs | |
| 106 | + | * on @dir and a second tmpfs covering @dir/covered/under.txt. | |
| 107 | + | */ | |
| 108 | + | FIXTURE_SETUP(open_tree_ns_covered) | |
| 109 | + | { | |
| 110 | + | char p[PATH_LEN]; | |
| 111 | + | int fd; | |
| 112 | + | ||
| 113 | + | snprintf(self->dir, sizeof(self->dir), "/tmp/open_tree_ns_covered.XXXXXX"); | |
| 114 | + | ASSERT_NE(mkdtemp(self->dir), NULL); | |
| 115 | + | if (enter_userns(getuid(), getgid()) || unshare(CLONE_NEWNS)) { | |
| 116 | + | rmdir(self->dir); | |
| 117 | + | SKIP(return, "test requires user namespaces"); | |
| 118 | + | } | |
| 119 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 120 | + | ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0); | |
| 121 | + | ||
| 122 | + | /* the flag has to exist before its rules can be checked */ | |
| 123 | + | fd = sys_open_tree(AT_FDCWD, self->dir, | |
| 124 | + | OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC); | |
| 125 | + | if (fd < 0 && (errno == EINVAL || errno == ENOSYS)) { | |
| 126 | + | umount2(self->dir, MNT_DETACH); | |
| 127 | + | rmdir(self->dir); | |
| 128 | + | SKIP(return, "OPEN_TREE_NAMESPACE not supported"); | |
| 129 | + | } | |
| 130 | + | ASSERT_GE(fd, 0); | |
| 131 | + | close(fd); | |
| 132 | + | ||
| 133 | + | snprintf(self->cover, sizeof(self->cover), "%s/covered", self->dir); | |
| 134 | + | ASSERT_EQ(mkdir(self->cover, 0755), 0); | |
| 135 | + | snprintf(p, sizeof(p), "%s/covered/under.txt", self->dir); | |
| 136 | + | ASSERT_EQ(create_file(p, "hidden"), 0); | |
| 137 | + | ASSERT_EQ(mount("tmpfs", self->cover, "tmpfs", 0, NULL), 0); | |
| 138 | + | ASSERT_EQ(mount(NULL, self->cover, NULL, variant->propagation, NULL), 0); | |
| 139 | + | } | |
| 140 | + | ||
| 141 | + | FIXTURE_TEARDOWN(open_tree_ns_covered) | |
| 142 | + | { | |
| 143 | + | umount2(self->dir, MNT_DETACH); | |
| 144 | + | rmdir(self->dir); | |
| 145 | + | } | |
| 146 | + | ||
| 147 | + | /* A caller in a new user namespace that doesn't own the mount namespace. */ | |
| 148 | + | static int foreign_child(const char *dir) | |
| 149 | + | { | |
| 150 | + | struct stat st; | |
| 151 | + | int fd; | |
| 152 | + | ||
| 153 | + | if (enter_userns(0, 0)) | |
| 154 | + | return CHILD_USERNS; | |
| 155 | + | ||
| 156 | + | fd = sys_open_tree(AT_FDCWD, dir, OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC); | |
| 157 | + | if (fd >= 0) | |
| 158 | + | return CHILD_NONREC_ALLOWED; | |
| 159 | + | if (errno != EINVAL) | |
| 160 | + | return CHILD_NONREC_ERRNO; | |
| 161 | + | ||
| 162 | + | fd = sys_open_tree(AT_FDCWD, dir, | |
| 163 | + | OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC | AT_RECURSIVE); | |
| 164 | + | if (fd < 0) | |
| 165 | + | return CHILD_REC_REFUSED; | |
| 166 | + | if (setns(fd, CLONE_NEWNS)) | |
| 167 | + | return CHILD_SETNS; | |
| 168 | + | if (stat("/covered", &st)) | |
| 169 | + | return CHILD_NO_COVER; | |
| 170 | + | if (!access("/covered/under.txt", F_OK) || errno != ENOENT) | |
| 171 | + | return CHILD_REVEALED; | |
| 172 | + | return CHILD_OK; | |
| 173 | + | } | |
| 174 | + | ||
| 175 | + | TEST_F(open_tree_ns_covered, foreign_user_namespace) | |
| 176 | + | { | |
| 177 | + | int status, fd; | |
| 178 | + | pid_t pid; | |
| 179 | + | ||
| 180 | + | pid = fork(); | |
| 181 | + | ASSERT_GE(pid, 0); | |
| 182 | + | if (pid == 0) | |
| 183 | + | _exit(foreign_child(self->dir)); | |
| 184 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 185 | + | ASSERT_TRUE(WIFEXITED(status)); | |
| 186 | + | ASSERT_EQ(WEXITSTATUS(status), CHILD_OK); | |
| 187 | + | ||
| 188 | + | /* the owner of the mount namespace keeps bind mount semantics */ | |
| 189 | + | fd = sys_open_tree(AT_FDCWD, self->dir, | |
| 190 | + | OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC); | |
| 191 | + | ASSERT_GE(fd, 0); | |
| 192 | + | close(fd); | |
| 193 | + | } | |
| 194 | + | ||
| 195 | + | TEST_HARNESS_MAIN | |
modified tools/testing/selftests/filesystems/overlayfs/.gitignore
| @@ -2,3 +2,4 @@ | |||
| 2 | 2 | dev_in_maps | |
| 3 | 3 | set_layers_via_fds | |
| 4 | 4 | idmapped_mounts | |
| 5 | + | automount_in_layer | |
modified tools/testing/selftests/filesystems/overlayfs/Makefile
| @@ -9,6 +9,7 @@ LOCAL_HDRS += ../wrappers.h log.h | |||
| 9 | 9 | TEST_GEN_PROGS := dev_in_maps | |
| 10 | 10 | TEST_GEN_PROGS += set_layers_via_fds | |
| 11 | 11 | TEST_GEN_PROGS += idmapped_mounts | |
| 12 | + | TEST_GEN_PROGS += automount_in_layer | |
| 12 | 13 | ||
| 13 | 14 | include ../../lib.mk | |
| 14 | 15 | ||
added tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c mode 100644
| @@ -0,0 +1,174 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A layer of an overlay is a private clone of the mount it was given and | |
| 4 | + | * belongs to no mount namespace. fanotify hands out descriptors on it. An | |
| 5 | + | * automount triggered through one has no namespace to go into: the open has | |
| 6 | + | * to fail, not oops with namespace_sem held. | |
| 7 | + | */ | |
| 8 | + | #define _GNU_SOURCE | |
| 9 | + | #include <dirent.h> | |
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <poll.h> | |
| 13 | + | #include <sched.h> | |
| 14 | + | #include <stdio.h> | |
| 15 | + | #include <stdlib.h> | |
| 16 | + | #include <string.h> | |
| 17 | + | #include <unistd.h> | |
| 18 | + | #include <linux/magic.h> | |
| 19 | + | #include <sys/fanotify.h> | |
| 20 | + | #include <sys/mount.h> | |
| 21 | + | #include <sys/stat.h> | |
| 22 | + | #include <sys/vfs.h> | |
| 23 | + | ||
| 24 | + | #include "../../kselftest_harness.h" | |
| 25 | + | ||
| 26 | + | #define DIR_LEN 64 | |
| 27 | + | #define PATH_LEN 192 | |
| 28 | + | ||
| 29 | + | static bool have_fs(const char *name) | |
| 30 | + | { | |
| 31 | + | char line[128]; | |
| 32 | + | bool found = false; | |
| 33 | + | FILE *f; | |
| 34 | + | ||
| 35 | + | f = fopen("/proc/filesystems", "re"); | |
| 36 | + | if (!f) | |
| 37 | + | return false; | |
| 38 | + | while (fgets(line, sizeof(line), f)) { | |
| 39 | + | char *nl = strchr(line, '\n'); | |
| 40 | + | char *tab = strchr(line, '\t'); | |
| 41 | + | ||
| 42 | + | if (nl) | |
| 43 | + | *nl = 0; | |
| 44 | + | if (tab && !strcmp(tab + 1, name)) | |
| 45 | + | found = true; | |
| 46 | + | } | |
| 47 | + | fclose(f); | |
| 48 | + | return found; | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | static int mnt_id_of(int fd) | |
| 52 | + | { | |
| 53 | + | char path[64], buf[4096], *p; | |
| 54 | + | ssize_t n; | |
| 55 | + | int info; | |
| 56 | + | ||
| 57 | + | snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); | |
| 58 | + | info = open(path, O_RDONLY | O_CLOEXEC); | |
| 59 | + | if (info < 0) | |
| 60 | + | return -1; | |
| 61 | + | n = read(info, buf, sizeof(buf) - 1); | |
| 62 | + | close(info); | |
| 63 | + | if (n <= 0) | |
| 64 | + | return -1; | |
| 65 | + | buf[n] = 0; | |
| 66 | + | p = strstr(buf, "mnt_id:"); | |
| 67 | + | return p ? atoi(p + strlen("mnt_id:")) : -1; | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | static bool on_debugfs(int fd) | |
| 71 | + | { | |
| 72 | + | struct statfs sf; | |
| 73 | + | ||
| 74 | + | return !fstatfs(fd, &sf) && sf.f_type == DEBUGFS_MAGIC; | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | FIXTURE(layer) { | |
| 78 | + | char base[DIR_LEN]; | |
| 79 | + | int fan; | |
| 80 | + | int evfd; /* on the layer clone of the lower debugfs */ | |
| 81 | + | }; | |
| 82 | + | ||
| 83 | + | FIXTURE_SETUP(layer) | |
| 84 | + | { | |
| 85 | + | char lower[PATH_LEN], other[PATH_LEN], ovl[PATH_LEN], opts[2 * PATH_LEN + 16]; | |
| 86 | + | struct fanotify_event_metadata *ev; | |
| 87 | + | struct pollfd pfd; | |
| 88 | + | char buf[4096]; | |
| 89 | + | int lfd, lower_id; | |
| 90 | + | ssize_t n; | |
| 91 | + | DIR *d; | |
| 92 | + | ||
| 93 | + | self->fan = -1; | |
| 94 | + | self->evfd = -1; | |
| 95 | + | if (geteuid()) | |
| 96 | + | SKIP(return, "test requires root"); | |
| 97 | + | if (!have_fs("debugfs") || !have_fs("tracefs")) | |
| 98 | + | SKIP(return, "test requires debugfs with the tracefs automount"); | |
| 99 | + | if (!have_fs("overlay")) | |
| 100 | + | SKIP(return, "test requires overlayfs"); | |
| 101 | + | ||
| 102 | + | snprintf(self->base, sizeof(self->base), "/tmp/layer.XXXXXX"); | |
| 103 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 104 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 105 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 106 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0); | |
| 107 | + | snprintf(lower, sizeof(lower), "%s/lower", self->base); | |
| 108 | + | snprintf(other, sizeof(other), "%s/other", self->base); | |
| 109 | + | snprintf(ovl, sizeof(ovl), "%s/ovl", self->base); | |
| 110 | + | ASSERT_EQ(mkdir(lower, 0755), 0); | |
| 111 | + | ASSERT_EQ(mkdir(other, 0755), 0); | |
| 112 | + | ASSERT_EQ(mkdir(ovl, 0755), 0); | |
| 113 | + | ASSERT_EQ(mount("debugfs", lower, "debugfs", 0, NULL), 0); | |
| 114 | + | snprintf(opts, sizeof(opts), "lowerdir=%s:%s", lower, other); | |
| 115 | + | ASSERT_EQ(mount("overlay", ovl, "overlay", MS_RDONLY, opts), 0); | |
| 116 | + | ||
| 117 | + | self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK | FAN_CLOEXEC, | |
| 118 | + | O_RDONLY | O_CLOEXEC); | |
| 119 | + | ASSERT_GE(self->fan, 0); | |
| 120 | + | ASSERT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, | |
| 121 | + | FAN_OPEN | FAN_ONDIR, AT_FDCWD, lower), 0); | |
| 122 | + | lfd = open(lower, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 123 | + | ASSERT_GE(lfd, 0); | |
| 124 | + | lower_id = mnt_id_of(lfd); | |
| 125 | + | close(lfd); | |
| 126 | + | ||
| 127 | + | /* the overlay opens its lower directory through the layer clone */ | |
| 128 | + | d = opendir(ovl); | |
| 129 | + | ASSERT_NE(d, NULL); | |
| 130 | + | closedir(d); | |
| 131 | + | pfd.fd = self->fan; | |
| 132 | + | pfd.events = POLLIN; | |
| 133 | + | ASSERT_EQ(poll(&pfd, 1, 5000), 1); | |
| 134 | + | n = read(self->fan, buf, sizeof(buf)); | |
| 135 | + | ASSERT_GT(n, 0); | |
| 136 | + | for (ev = (void *)buf; FAN_EVENT_OK(ev, n); ev = FAN_EVENT_NEXT(ev, n)) { | |
| 137 | + | if (ev->fd < 0) | |
| 138 | + | continue; | |
| 139 | + | if (self->evfd < 0 && on_debugfs(ev->fd) && | |
| 140 | + | mnt_id_of(ev->fd) != lower_id) | |
| 141 | + | self->evfd = ev->fd; | |
| 142 | + | else | |
| 143 | + | close(ev->fd); | |
| 144 | + | } | |
| 145 | + | ASSERT_GE(self->evfd, 0) | |
| 146 | + | TH_LOG("no event on the layer clone"); | |
| 147 | + | } | |
| 148 | + | ||
| 149 | + | FIXTURE_TEARDOWN(layer) | |
| 150 | + | { | |
| 151 | + | if (self->evfd >= 0) | |
| 152 | + | close(self->evfd); | |
| 153 | + | if (self->fan >= 0) | |
| 154 | + | close(self->fan); | |
| 155 | + | umount2(self->base, MNT_DETACH); | |
| 156 | + | rmdir(self->base); | |
| 157 | + | } | |
| 158 | + | ||
| 159 | + | TEST_F(layer, automount_below_the_clone_is_refused) | |
| 160 | + | { | |
| 161 | + | struct stat st; | |
| 162 | + | int fd; | |
| 163 | + | ||
| 164 | + | /* the automount point is there */ | |
| 165 | + | ASSERT_EQ(fstatat(self->evfd, "tracing", &st, AT_NO_AUTOMOUNT), 0); | |
| 166 | + | /* the clone is in no namespace, so the automount has nowhere to go */ | |
| 167 | + | fd = openat(self->evfd, "tracing", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 168 | + | EXPECT_LT(fd, 0); | |
| 169 | + | EXPECT_EQ(errno, EINVAL); | |
| 170 | + | if (fd >= 0) | |
| 171 | + | close(fd); | |
| 172 | + | } | |
| 173 | + | ||
| 174 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/readdir_hold.h mode 100644
| @@ -0,0 +1,224 @@ | |||
| 1 | + | /* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | + | /* | |
| 3 | + | * Hold a readdir of a directory in the page fault of its buffer and see | |
| 4 | + | * whether a create and a lookup in that directory wait for it. For a | |
| 5 | + | * directory that is permanently empty they must not. | |
| 6 | + | */ | |
| 7 | + | #ifndef __SELFTESTS_READDIR_HOLD_H | |
| 8 | + | #define __SELFTESTS_READDIR_HOLD_H | |
| 9 | + | ||
| 10 | + | #include <errno.h> | |
| 11 | + | #include <fcntl.h> | |
| 12 | + | #include <poll.h> | |
| 13 | + | #include <pthread.h> | |
| 14 | + | #include <stdbool.h> | |
| 15 | + | #include <stdio.h> | |
| 16 | + | #include <stdlib.h> | |
| 17 | + | #include <string.h> | |
| 18 | + | #include <unistd.h> | |
| 19 | + | #include <linux/userfaultfd.h> | |
| 20 | + | #include <sys/ioctl.h> | |
| 21 | + | #include <sys/mman.h> | |
| 22 | + | #include <sys/stat.h> | |
| 23 | + | #include <sys/syscall.h> | |
| 24 | + | ||
| 25 | + | #define HOLD_FAULT_MS 5000 /* for the reader to reach the fault */ | |
| 26 | + | #define HOLD_QUEUE_MS 2000 /* for the create to queue up behind it */ | |
| 27 | + | #define HOLD_LOOKUP_MS 5000 /* for the lookup to come back */ | |
| 28 | + | ||
| 29 | + | struct readdir_hold { | |
| 30 | + | int uffd; | |
| 31 | + | int taskdir; /* /proc/self/task, from before any namespace change */ | |
| 32 | + | long page_size; | |
| 33 | + | char *page; /* faults until released */ | |
| 34 | + | int dfd; | |
| 35 | + | pid_t creator_tid; | |
| 36 | + | int created; | |
| 37 | + | int done[2]; /* the finder writes a byte when it is back */ | |
| 38 | + | }; | |
| 39 | + | ||
| 40 | + | /* | |
| 41 | + | * The fault happens in the kernel, so the userfaultfd needs CAP_SYS_PTRACE | |
| 42 | + | * in the initial user namespace or vm.unprivileged_userfaultfd. Call this | |
| 43 | + | * before entering a user namespace. | |
| 44 | + | */ | |
| 45 | + | static inline int readdir_hold_init(struct readdir_hold *h) | |
| 46 | + | { | |
| 47 | + | struct uffdio_api api = { .api = UFFD_API }; | |
| 48 | + | ||
| 49 | + | h->page = MAP_FAILED; | |
| 50 | + | h->page_size = sysconf(_SC_PAGESIZE); | |
| 51 | + | h->taskdir = open("/proc/self/task", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 52 | + | h->uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); | |
| 53 | + | if (h->uffd < 0 || h->taskdir < 0 || ioctl(h->uffd, UFFDIO_API, &api)) { | |
| 54 | + | if (h->uffd >= 0) | |
| 55 | + | close(h->uffd); | |
| 56 | + | if (h->taskdir >= 0) | |
| 57 | + | close(h->taskdir); | |
| 58 | + | h->uffd = h->taskdir = -1; | |
| 59 | + | return -1; | |
| 60 | + | } | |
| 61 | + | return 0; | |
| 62 | + | } | |
| 63 | + | ||
| 64 | + | static inline void readdir_hold_destroy(struct readdir_hold *h) | |
| 65 | + | { | |
| 66 | + | if (h->uffd >= 0) | |
| 67 | + | close(h->uffd); | |
| 68 | + | if (h->taskdir >= 0) | |
| 69 | + | close(h->taskdir); | |
| 70 | + | h->uffd = h->taskdir = -1; | |
| 71 | + | } | |
| 72 | + | ||
| 73 | + | static inline void *readdir_hold_reader(void *arg) | |
| 74 | + | { | |
| 75 | + | struct readdir_hold *h = arg; | |
| 76 | + | ||
| 77 | + | /* the first byte written to the buffer faults until released */ | |
| 78 | + | syscall(__NR_getdents64, h->dfd, h->page, h->page_size); | |
| 79 | + | return NULL; | |
| 80 | + | } | |
| 81 | + | ||
| 82 | + | static inline void *readdir_hold_creator(void *arg) | |
| 83 | + | { | |
| 84 | + | struct readdir_hold *h = arg; | |
| 85 | + | ||
| 86 | + | h->creator_tid = syscall(__NR_gettid); | |
| 87 | + | /* takes the directory lock exclusive before it fails */ | |
| 88 | + | mkdirat(h->dfd, "x", 0755); | |
| 89 | + | __atomic_store_n(&h->created, 1, __ATOMIC_RELEASE); | |
| 90 | + | return NULL; | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | static inline void *readdir_hold_finder(void *arg) | |
| 94 | + | { | |
| 95 | + | struct readdir_hold *h = arg; | |
| 96 | + | int fd; | |
| 97 | + | ||
| 98 | + | /* a lookup that misses the dcache takes the lock shared */ | |
| 99 | + | fd = openat(h->dfd, "no_such_name", O_RDONLY | O_CLOEXEC); | |
| 100 | + | if (fd >= 0) | |
| 101 | + | close(fd); | |
| 102 | + | if (write(h->done[1], "x", 1) != 1) | |
| 103 | + | perror("readdir_hold: finder"); | |
| 104 | + | return NULL; | |
| 105 | + | } | |
| 106 | + | ||
| 107 | + | /* the creator is back, or waits in the kernel for the lock */ | |
| 108 | + | static inline bool readdir_hold_creator_settled(struct readdir_hold *h) | |
| 109 | + | { | |
| 110 | + | char path[32], buf[256], *p; | |
| 111 | + | ssize_t n; | |
| 112 | + | int fd; | |
| 113 | + | ||
| 114 | + | if (__atomic_load_n(&h->created, __ATOMIC_ACQUIRE)) | |
| 115 | + | return true; | |
| 116 | + | if (!h->creator_tid) | |
| 117 | + | return false; | |
| 118 | + | snprintf(path, sizeof(path), "%d/stat", h->creator_tid); | |
| 119 | + | fd = openat(h->taskdir, path, O_RDONLY | O_CLOEXEC); | |
| 120 | + | if (fd < 0) | |
| 121 | + | return false; | |
| 122 | + | n = read(fd, buf, sizeof(buf) - 1); | |
| 123 | + | close(fd); | |
| 124 | + | if (n <= 0) | |
| 125 | + | return false; | |
| 126 | + | buf[n] = 0; | |
| 127 | + | /* "pid (comm) state ..." */ | |
| 128 | + | p = strrchr(buf, ')'); | |
| 129 | + | return p && p[1] == ' ' && p[2] == 'D'; | |
| 130 | + | } | |
| 131 | + | ||
| 132 | + | static inline bool readdir_hold_faulted(struct readdir_hold *h) | |
| 133 | + | { | |
| 134 | + | struct pollfd pfd = { .fd = h->uffd, .events = POLLIN }; | |
| 135 | + | struct uffd_msg msg; | |
| 136 | + | ||
| 137 | + | if (poll(&pfd, 1, HOLD_FAULT_MS) != 1) | |
| 138 | + | return false; | |
| 139 | + | if (read(h->uffd, &msg, sizeof(msg)) != sizeof(msg)) | |
| 140 | + | return false; | |
| 141 | + | return msg.event == UFFD_EVENT_PAGEFAULT; | |
| 142 | + | } | |
| 143 | + | ||
| 144 | + | /* let the reader go on */ | |
| 145 | + | static inline void readdir_hold_release(struct readdir_hold *h) | |
| 146 | + | { | |
| 147 | + | struct uffdio_copy cp = { | |
| 148 | + | .dst = (unsigned long)h->page, | |
| 149 | + | .len = h->page_size, | |
| 150 | + | }; | |
| 151 | + | void *zero; | |
| 152 | + | ||
| 153 | + | zero = calloc(1, h->page_size); | |
| 154 | + | if (!zero) | |
| 155 | + | return; | |
| 156 | + | cp.src = (unsigned long)zero; | |
| 157 | + | if (ioctl(h->uffd, UFFDIO_COPY, &cp) && errno != EEXIST) | |
| 158 | + | perror("readdir_hold: UFFDIO_COPY"); | |
| 159 | + | free(zero); | |
| 160 | + | } | |
| 161 | + | ||
| 162 | + | /* | |
| 163 | + | * A readdir of @dfd that sticks in the fault of its buffer, then a create | |
| 164 | + | * and a lookup in @dfd. Whether the lookup came back while the readdir was | |
| 165 | + | * still stuck goes to @stalled. Returns -1 when that could not be found | |
| 166 | + | * out. | |
| 167 | + | */ | |
| 168 | + | static inline int readdir_hold_check(struct readdir_hold *h, int dfd, | |
| 169 | + | bool *stalled) | |
| 170 | + | { | |
| 171 | + | pthread_t reader, creator, finder; | |
| 172 | + | struct uffdio_register reg = {}; | |
| 173 | + | struct pollfd pfd; | |
| 174 | + | int ret = -1, i; | |
| 175 | + | ||
| 176 | + | h->dfd = dfd; | |
| 177 | + | h->created = 0; | |
| 178 | + | h->creator_tid = 0; | |
| 179 | + | h->page = mmap(NULL, h->page_size, PROT_READ | PROT_WRITE, | |
| 180 | + | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
| 181 | + | if (h->page == MAP_FAILED) | |
| 182 | + | return -1; | |
| 183 | + | reg.range.start = (unsigned long)h->page; | |
| 184 | + | reg.range.len = h->page_size; | |
| 185 | + | reg.mode = UFFDIO_REGISTER_MODE_MISSING; | |
| 186 | + | if (ioctl(h->uffd, UFFDIO_REGISTER, ®) || pipe2(h->done, O_CLOEXEC)) | |
| 187 | + | goto out_page; | |
| 188 | + | ||
| 189 | + | if (pthread_create(&reader, NULL, readdir_hold_reader, h)) | |
| 190 | + | goto out_pipe; | |
| 191 | + | if (!readdir_hold_faulted(h)) | |
| 192 | + | goto out_reader; | |
| 193 | + | if (pthread_create(&creator, NULL, readdir_hold_creator, h)) | |
| 194 | + | goto out_reader; | |
| 195 | + | for (i = 0; i < HOLD_QUEUE_MS / 10 && !readdir_hold_creator_settled(h); i++) | |
| 196 | + | usleep(10000); | |
| 197 | + | if (pthread_create(&finder, NULL, readdir_hold_finder, h)) | |
| 198 | + | goto out_creator; | |
| 199 | + | ||
| 200 | + | pfd.fd = h->done[0]; | |
| 201 | + | pfd.events = POLLIN; | |
| 202 | + | *stalled = poll(&pfd, 1, HOLD_LOOKUP_MS) != 1; | |
| 203 | + | ret = 0; | |
| 204 | + | ||
| 205 | + | readdir_hold_release(h); | |
| 206 | + | pthread_join(finder, NULL); | |
| 207 | + | out_creator: | |
| 208 | + | if (ret) | |
| 209 | + | readdir_hold_release(h); | |
| 210 | + | pthread_join(creator, NULL); | |
| 211 | + | out_reader: | |
| 212 | + | if (ret) | |
| 213 | + | readdir_hold_release(h); | |
| 214 | + | pthread_join(reader, NULL); | |
| 215 | + | out_pipe: | |
| 216 | + | close(h->done[0]); | |
| 217 | + | close(h->done[1]); | |
| 218 | + | out_page: | |
| 219 | + | munmap(h->page, h->page_size); | |
| 220 | + | h->page = MAP_FAILED; | |
| 221 | + | return ret; | |
| 222 | + | } | |
| 223 | + | ||
| 224 | + | #endif /* __SELFTESTS_READDIR_HOLD_H */ | |
added tools/testing/selftests/filesystems/rw_hint_test.c mode 100644
| @@ -0,0 +1,129 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * F_SET_RW_HINT is refused on an immutable inode. Nothing is ever written | |
| 4 | + | * to it and it may be shared with everybody, like a namespace file or the | |
| 5 | + | * root of an empty mount namespace. | |
| 6 | + | */ | |
| 7 | + | #define _GNU_SOURCE | |
| 8 | + | #include <errno.h> | |
| 9 | + | #include <fcntl.h> | |
| 10 | + | #include <sched.h> | |
| 11 | + | #include <stdint.h> | |
| 12 | + | #include <stdio.h> | |
| 13 | + | #include <stdlib.h> | |
| 14 | + | #include <string.h> | |
| 15 | + | #include <unistd.h> | |
| 16 | + | #include <sys/ioctl.h> | |
| 17 | + | #include <sys/stat.h> | |
| 18 | + | #include <sys/wait.h> | |
| 19 | + | ||
| 20 | + | #include "../kselftest_harness.h" | |
| 21 | + | ||
| 22 | + | /* <linux/fs.h> and <linux/fcntl.h> don't mix with the libc headers */ | |
| 23 | + | #ifndef FS_IOC_GETFLAGS | |
| 24 | + | #define FS_IOC_GETFLAGS _IOR('f', 1, long) | |
| 25 | + | #define FS_IOC_SETFLAGS _IOW('f', 2, long) | |
| 26 | + | #endif | |
| 27 | + | #ifndef FS_IMMUTABLE_FL | |
| 28 | + | #define FS_IMMUTABLE_FL 0x00000010 | |
| 29 | + | #endif | |
| 30 | + | #ifndef F_LINUX_SPECIFIC_BASE | |
| 31 | + | #define F_LINUX_SPECIFIC_BASE 1024 | |
| 32 | + | #endif | |
| 33 | + | #ifndef F_GET_RW_HINT | |
| 34 | + | #define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11) | |
| 35 | + | #define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12) | |
| 36 | + | #endif | |
| 37 | + | #ifndef RWH_WRITE_LIFE_SHORT | |
| 38 | + | #define RWH_WRITE_LIFE_SHORT 2 | |
| 39 | + | #endif | |
| 40 | + | #ifndef UNSHARE_EMPTY_MNTNS | |
| 41 | + | #define UNSHARE_EMPTY_MNTNS 0x00100000 | |
| 42 | + | #endif | |
| 43 | + | ||
| 44 | + | static int set_hint(int fd, uint64_t hint) | |
| 45 | + | { | |
| 46 | + | return fcntl(fd, F_SET_RW_HINT, &hint); | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | static long get_hint(int fd) | |
| 50 | + | { | |
| 51 | + | uint64_t hint; | |
| 52 | + | ||
| 53 | + | if (fcntl(fd, F_GET_RW_HINT, &hint)) | |
| 54 | + | return -1; | |
| 55 | + | return hint; | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | TEST(immutable_file) | |
| 59 | + | { | |
| 60 | + | char path[] = "/tmp/rw_hint.XXXXXX"; | |
| 61 | + | int fd, flags; | |
| 62 | + | ||
| 63 | + | if (geteuid()) | |
| 64 | + | SKIP(return, "test requires root"); | |
| 65 | + | ||
| 66 | + | fd = mkstemp(path); | |
| 67 | + | ASSERT_GE(fd, 0); | |
| 68 | + | unlink(path); | |
| 69 | + | ASSERT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0); | |
| 70 | + | EXPECT_EQ(get_hint(fd), RWH_WRITE_LIFE_SHORT); | |
| 71 | + | ||
| 72 | + | if (ioctl(fd, FS_IOC_GETFLAGS, &flags)) { | |
| 73 | + | close(fd); | |
| 74 | + | SKIP(return, "no file attributes on this filesystem"); | |
| 75 | + | } | |
| 76 | + | flags |= FS_IMMUTABLE_FL; | |
| 77 | + | ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0); | |
| 78 | + | EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1); | |
| 79 | + | EXPECT_EQ(errno, EPERM); | |
| 80 | + | flags &= ~FS_IMMUTABLE_FL; | |
| 81 | + | ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0); | |
| 82 | + | EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0); | |
| 83 | + | close(fd); | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | TEST(namespace_file) | |
| 87 | + | { | |
| 88 | + | int fd; | |
| 89 | + | ||
| 90 | + | if (geteuid()) | |
| 91 | + | SKIP(return, "test requires root"); | |
| 92 | + | ||
| 93 | + | fd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC); | |
| 94 | + | ASSERT_GE(fd, 0); | |
| 95 | + | EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1); | |
| 96 | + | EXPECT_EQ(errno, EPERM); | |
| 97 | + | close(fd); | |
| 98 | + | } | |
| 99 | + | ||
| 100 | + | TEST(empty_mntns_root) | |
| 101 | + | { | |
| 102 | + | int status; | |
| 103 | + | pid_t pid; | |
| 104 | + | ||
| 105 | + | if (geteuid()) | |
| 106 | + | SKIP(return, "test requires root"); | |
| 107 | + | ||
| 108 | + | pid = fork(); | |
| 109 | + | ASSERT_GE(pid, 0); | |
| 110 | + | if (pid == 0) { | |
| 111 | + | int fd; | |
| 112 | + | ||
| 113 | + | if (unshare(UNSHARE_EMPTY_MNTNS)) | |
| 114 | + | _exit(errno == EINVAL ? 100 : 1); | |
| 115 | + | fd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 116 | + | if (fd < 0) | |
| 117 | + | _exit(2); | |
| 118 | + | if (set_hint(fd, RWH_WRITE_LIFE_SHORT) == 0) | |
| 119 | + | _exit(3); | |
| 120 | + | _exit(errno == EPERM ? 0 : 4); | |
| 121 | + | } | |
| 122 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 123 | + | ASSERT_TRUE(WIFEXITED(status)); | |
| 124 | + | if (WEXITSTATUS(status) == 100) | |
| 125 | + | SKIP(return, "UNSHARE_EMPTY_MNTNS not supported"); | |
| 126 | + | EXPECT_EQ(WEXITSTATUS(status), 0); | |
| 127 | + | } | |
| 128 | + | ||
| 129 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/umount_propagation/Makefile mode 100644
| @@ -0,0 +1,6 @@ | |||
| 1 | + | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test locked_mount_test | |
| 3 | + | ||
| 4 | + | CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) | |
| 5 | + | ||
| 6 | + | include ../../lib.mk | |
added tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c mode 100644
| @@ -0,0 +1,432 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * MNT_LOCKED keeps the owner of a user namespace from revealing what a | |
| 4 | + | * mount covers. The lock has to be set on the copy in that namespace and | |
| 5 | + | * only there, it has to survive the expiry of a mount placed beneath the | |
| 6 | + | * locked one, and it has to survive the propagated umount of such a copy. | |
| 7 | + | */ | |
| 8 | + | #define _GNU_SOURCE | |
| 9 | + | #include <errno.h> | |
| 10 | + | #include <fcntl.h> | |
| 11 | + | #include <sched.h> | |
| 12 | + | #include <stdio.h> | |
| 13 | + | #include <stdlib.h> | |
| 14 | + | #include <string.h> | |
| 15 | + | #include <unistd.h> | |
| 16 | + | #include <sys/mount.h> | |
| 17 | + | #include <sys/prctl.h> | |
| 18 | + | #include <sys/stat.h> | |
| 19 | + | #include <sys/syscall.h> | |
| 20 | + | #include <sys/wait.h> | |
| 21 | + | ||
| 22 | + | #include "../../kselftest_harness.h" | |
| 23 | + | ||
| 24 | + | #ifndef MOVE_MOUNT_F_EMPTY_PATH | |
| 25 | + | #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 | |
| 26 | + | #endif | |
| 27 | + | #ifndef MOVE_MOUNT_BENEATH | |
| 28 | + | #define MOVE_MOUNT_BENEATH 0x00000200 | |
| 29 | + | #endif | |
| 30 | + | ||
| 31 | + | #define DIR_LEN 64 | |
| 32 | + | #define PATH_LEN 192 | |
| 33 | + | #define FLAGS (MS_NOSUID | MS_NODEV | MS_NOEXEC) | |
| 34 | + | ||
| 35 | + | /* exit codes of the children, each test says what they mean */ | |
| 36 | + | enum { | |
| 37 | + | CHILD_OK, | |
| 38 | + | CHILD_SETUP, | |
| 39 | + | CHILD_STEP1, | |
| 40 | + | CHILD_STEP2, | |
| 41 | + | CHILD_STEP3, | |
| 42 | + | CHILD_STEP4, | |
| 43 | + | }; | |
| 44 | + | ||
| 45 | + | static int write_file(const char *path, const char *s) | |
| 46 | + | { | |
| 47 | + | ssize_t n = -1; | |
| 48 | + | int fd; | |
| 49 | + | ||
| 50 | + | fd = open(path, O_WRONLY | O_CLOEXEC); | |
| 51 | + | if (fd >= 0) { | |
| 52 | + | n = write(fd, s, strlen(s)); | |
| 53 | + | close(fd); | |
| 54 | + | } | |
| 55 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | static int create_file(const char *path, const char *s) | |
| 59 | + | { | |
| 60 | + | ssize_t n = -1; | |
| 61 | + | int fd; | |
| 62 | + | ||
| 63 | + | fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644); | |
| 64 | + | if (fd >= 0) { | |
| 65 | + | n = write(fd, s, strlen(s)); | |
| 66 | + | close(fd); | |
| 67 | + | } | |
| 68 | + | return n == (ssize_t)strlen(s) ? 0 : -1; | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | /* Root in a new user namespace with a copy of the mount namespace. */ | |
| 72 | + | static int enter_userns(void) | |
| 73 | + | { | |
| 74 | + | uid_t uid = getuid(); | |
| 75 | + | gid_t gid = getgid(); | |
| 76 | + | char map[32]; | |
| 77 | + | ||
| 78 | + | prctl(PR_SET_DUMPABLE, 1); | |
| 79 | + | if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) | |
| 80 | + | return -1; | |
| 81 | + | if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT) | |
| 82 | + | return -1; | |
| 83 | + | snprintf(map, sizeof(map), "0 %d 1", uid); | |
| 84 | + | if (write_file("/proc/self/uid_map", map)) | |
| 85 | + | return -1; | |
| 86 | + | snprintf(map, sizeof(map), "0 %d 1", gid); | |
| 87 | + | if (write_file("/proc/self/gid_map", map)) | |
| 88 | + | return -1; | |
| 89 | + | return setgid(0) || setuid(0) ? -1 : 0; | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | static int wait_child(pid_t pid) | |
| 93 | + | { | |
| 94 | + | int status; | |
| 95 | + | ||
| 96 | + | if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) | |
| 97 | + | return -1; | |
| 98 | + | return WEXITSTATUS(status); | |
| 99 | + | } | |
| 100 | + | ||
| 101 | + | static int wait_byte(int fd) | |
| 102 | + | { | |
| 103 | + | char c; | |
| 104 | + | ||
| 105 | + | return read(fd, &c, 1) == 1 ? 0 : -1; | |
| 106 | + | } | |
| 107 | + | ||
| 108 | + | static int send_byte(int fd) | |
| 109 | + | { | |
| 110 | + | return write(fd, "x", 1) == 1 ? 0 : -1; | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | /* A read of @path fails: the file is covered. */ | |
| 114 | + | static bool covered(const char *path) | |
| 115 | + | { | |
| 116 | + | int fd = open(path, O_RDONLY | O_CLOEXEC); | |
| 117 | + | ||
| 118 | + | if (fd >= 0) | |
| 119 | + | close(fd); | |
| 120 | + | return fd < 0; | |
| 121 | + | } | |
| 122 | + | ||
| 123 | + | FIXTURE(locked_mount) { | |
| 124 | + | char base[DIR_LEN]; | |
| 125 | + | bool tracing; /* debugfs with the tracefs automount is there */ | |
| 126 | + | }; | |
| 127 | + | ||
| 128 | + | FIXTURE_SETUP(locked_mount) | |
| 129 | + | { | |
| 130 | + | char p[PATH_LEN]; | |
| 131 | + | struct stat st; | |
| 132 | + | ||
| 133 | + | if (geteuid()) | |
| 134 | + | SKIP(return, "test requires root"); | |
| 135 | + | ||
| 136 | + | snprintf(self->base, sizeof(self->base), "/tmp/locked_mount.XXXXXX"); | |
| 137 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 138 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 139 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 140 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0); | |
| 141 | + | ||
| 142 | + | /* an automount that a user can name: the tracefs below debugfs */ | |
| 143 | + | snprintf(p, sizeof(p), "%s/dbg", self->base); | |
| 144 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 145 | + | self->tracing = !mount("debugfs", p, "debugfs", FLAGS, NULL); | |
| 146 | + | if (self->tracing) { | |
| 147 | + | /* the cases trigger it themselves */ | |
| 148 | + | snprintf(p, sizeof(p), "%s/dbg/tracing", self->base); | |
| 149 | + | self->tracing = !fstatat(AT_FDCWD, p, &st, AT_NO_AUTOMOUNT) && | |
| 150 | + | S_ISDIR(st.st_mode); | |
| 151 | + | } | |
| 152 | + | } | |
| 153 | + | ||
| 154 | + | FIXTURE_TEARDOWN(locked_mount) | |
| 155 | + | { | |
| 156 | + | umount2(self->base, MNT_DETACH); | |
| 157 | + | rmdir(self->base); | |
| 158 | + | } | |
| 159 | + | ||
| 160 | + | /* | |
| 161 | + | * The child keeps a directory descriptor on the host's debugfs mount, moves | |
| 162 | + | * to a user namespace of its own and triggers the automount through the | |
| 163 | + | * descriptor. The mount goes below the host's mount and propagates into the | |
| 164 | + | * child's copy. The child's copy has to be locked, the host's not. | |
| 165 | + | */ | |
| 166 | + | static int automount_child(const char *base, int dfd, int to_host, int from_host) | |
| 167 | + | { | |
| 168 | + | char p[PATH_LEN]; | |
| 169 | + | struct stat st; | |
| 170 | + | ||
| 171 | + | if (enter_userns()) | |
| 172 | + | return CHILD_SETUP; | |
| 173 | + | if (fstatat(dfd, "tracing/.", &st, 0)) | |
| 174 | + | return CHILD_STEP1; | |
| 175 | + | if (send_byte(to_host) || wait_byte(from_host)) | |
| 176 | + | return CHILD_SETUP; | |
| 177 | + | /* the flags of the copy are locked: EPERM */ | |
| 178 | + | snprintf(p, sizeof(p), "%s/dbg/tracing", base); | |
| 179 | + | if (!mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL) || errno != EPERM) | |
| 180 | + | return CHILD_STEP2; | |
| 181 | + | return CHILD_OK; | |
| 182 | + | } | |
| 183 | + | ||
| 184 | + | TEST_F(locked_mount, automount_locked_in_the_triggering_namespace) | |
| 185 | + | { | |
| 186 | + | int to_host[2], from_host[2], dfd, ret; | |
| 187 | + | char p[PATH_LEN]; | |
| 188 | + | pid_t pid; | |
| 189 | + | ||
| 190 | + | if (!self->tracing) | |
| 191 | + | SKIP(return, "test requires debugfs with the tracefs automount"); | |
| 192 | + | ||
| 193 | + | snprintf(p, sizeof(p), "%s/dbg", self->base); | |
| 194 | + | ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0); | |
| 195 | + | dfd = open(p, O_RDONLY | O_DIRECTORY | O_CLOEXEC); | |
| 196 | + | ASSERT_GE(dfd, 0); | |
| 197 | + | ASSERT_EQ(pipe(to_host), 0); | |
| 198 | + | ASSERT_EQ(pipe(from_host), 0); | |
| 199 | + | ||
| 200 | + | pid = fork(); | |
| 201 | + | ASSERT_GE(pid, 0); | |
| 202 | + | if (pid == 0) | |
| 203 | + | _exit(automount_child(self->base, dfd, to_host[1], from_host[0])); | |
| 204 | + | close(dfd); | |
| 205 | + | ASSERT_EQ(wait_byte(to_host[0]), 0); | |
| 206 | + | ||
| 207 | + | /* the host's own mount isn't locked: the flags can go */ | |
| 208 | + | snprintf(p, sizeof(p), "%s/dbg/tracing", self->base); | |
| 209 | + | EXPECT_EQ(mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL), 0); | |
| 210 | + | ||
| 211 | + | ASSERT_EQ(send_byte(from_host[1]), 0); | |
| 212 | + | ret = wait_child(pid); | |
| 213 | + | TH_LOG("child exit code %d", ret); | |
| 214 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 215 | + | } | |
| 216 | + | ||
| 217 | + | /* | |
| 218 | + | * A copy of a tree with a locked cover. The child puts a shrinkable mount | |
| 219 | + | * beneath the cover, which hands the lock down, unmounts the cover and then | |
| 220 | + | * asks for the umount of an unlocked ancestor. That expires the shrinkable | |
| 221 | + | * mount on a kernel that doesn't look at the lock, and the covered | |
| 222 | + | * directory is bare. | |
| 223 | + | */ | |
| 224 | + | static int expiry_child(const char *base) | |
| 225 | + | { | |
| 226 | + | char srv[PATH_LEN], shr[PATH_LEN], x[PATH_LEN], c[PATH_LEN]; | |
| 227 | + | char hidden[PATH_LEN], secret[PATH_LEN]; | |
| 228 | + | ||
| 229 | + | snprintf(srv, sizeof(srv), "%s/srv", base); | |
| 230 | + | snprintf(shr, sizeof(shr), "%s/shr", base); | |
| 231 | + | snprintf(x, sizeof(x), "%s/x", base); | |
| 232 | + | snprintf(c, sizeof(c), "%s/c", base); | |
| 233 | + | snprintf(hidden, sizeof(hidden), "%s/x/hidden", base); | |
| 234 | + | snprintf(secret, sizeof(secret), "%s/x/hidden/secret", base); | |
| 235 | + | ||
| 236 | + | if (enter_userns()) | |
| 237 | + | return CHILD_SETUP; | |
| 238 | + | if (mount(srv, x, NULL, MS_BIND | MS_REC, NULL) || | |
| 239 | + | mount(shr, c, NULL, MS_BIND, NULL)) | |
| 240 | + | return CHILD_SETUP; | |
| 241 | + | /* the cover is locked */ | |
| 242 | + | if (!umount2(hidden, 0) || errno != EINVAL) | |
| 243 | + | return CHILD_STEP1; | |
| 244 | + | if (syscall(__NR_move_mount, AT_FDCWD, c, AT_FDCWD, hidden, MOVE_MOUNT_BENEATH)) | |
| 245 | + | return CHILD_STEP2; | |
| 246 | + | /* the lock moved down, the cover may go */ | |
| 247 | + | if (umount2(hidden, 0)) | |
| 248 | + | return CHILD_STEP3; | |
| 249 | + | /* the holder of the lock may not, in any way */ | |
| 250 | + | if (!umount2(hidden, 0) || errno != EINVAL) | |
| 251 | + | return CHILD_STEP4; | |
| 252 | + | if (chdir(x)) | |
| 253 | + | return CHILD_SETUP; | |
| 254 | + | umount2(x, 0); | |
| 255 | + | return covered(secret) ? CHILD_OK : CHILD_STEP4; | |
| 256 | + | } | |
| 257 | + | ||
| 258 | + | TEST_F(locked_mount, expiry_leaves_a_locked_mount_alone) | |
| 259 | + | { | |
| 260 | + | char p[PATH_LEN], q[PATH_LEN]; | |
| 261 | + | pid_t pid; | |
| 262 | + | int ret; | |
| 263 | + | ||
| 264 | + | if (!self->tracing) | |
| 265 | + | SKIP(return, "test requires debugfs with the tracefs automount"); | |
| 266 | + | ||
| 267 | + | snprintf(p, sizeof(p), "%s/dbg/tracing", self->base); | |
| 268 | + | snprintf(q, sizeof(q), "%s/shr", self->base); | |
| 269 | + | ASSERT_EQ(mkdir(q, 0755), 0); | |
| 270 | + | /* a bind of an automount is shrinkable as well */ | |
| 271 | + | ASSERT_EQ(mount(p, q, NULL, MS_BIND, NULL), 0); | |
| 272 | + | snprintf(p, sizeof(p), "%s/srv", self->base); | |
| 273 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 274 | + | ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0); | |
| 275 | + | snprintf(p, sizeof(p), "%s/srv/hidden", self->base); | |
| 276 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 277 | + | snprintf(p, sizeof(p), "%s/srv/hidden/secret", self->base); | |
| 278 | + | ASSERT_EQ(create_file(p, "covered-by-root\n"), 0); | |
| 279 | + | snprintf(p, sizeof(p), "%s/srv/hidden", self->base); | |
| 280 | + | ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0); | |
| 281 | + | snprintf(p, sizeof(p), "%s/x", self->base); | |
| 282 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 283 | + | snprintf(p, sizeof(p), "%s/c", self->base); | |
| 284 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 285 | + | ||
| 286 | + | pid = fork(); | |
| 287 | + | ASSERT_GE(pid, 0); | |
| 288 | + | if (pid == 0) | |
| 289 | + | _exit(expiry_child(self->base)); | |
| 290 | + | ret = wait_child(pid); | |
| 291 | + | TH_LOG("child exit code %d", ret); | |
| 292 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 293 | + | } | |
| 294 | + | ||
| 295 | + | /* | |
| 296 | + | * The copy of the mount tree that a user namespace gets at its creation has | |
| 297 | + | * the automounts in it locked unless they are on an expiry list. A bind of | |
| 298 | + | * such a tree inside the namespace copies the lock to the automount but not | |
| 299 | + | * to the root of the bind, so the child may ask for the umount of that root. | |
| 300 | + | * That must not expire the locked automount below it: the root is busy, the | |
| 301 | + | * umount fails and the automount has to be there afterwards. | |
| 302 | + | */ | |
| 303 | + | static int copied_tree_child(const char *base) | |
| 304 | + | { | |
| 305 | + | char dbg[PATH_LEN], x[PATH_LEN], tracing[PATH_LEN]; | |
| 306 | + | struct stat root, st; | |
| 307 | + | ||
| 308 | + | snprintf(dbg, sizeof(dbg), "%s/dbg", base); | |
| 309 | + | snprintf(x, sizeof(x), "%s/x", base); | |
| 310 | + | snprintf(tracing, sizeof(tracing), "%s/x/tracing", base); | |
| 311 | + | ||
| 312 | + | if (enter_userns()) | |
| 313 | + | return CHILD_SETUP; | |
| 314 | + | if (mount(dbg, x, NULL, MS_BIND | MS_REC, NULL)) | |
| 315 | + | return CHILD_SETUP; | |
| 316 | + | /* the copy of the automount carries the lock */ | |
| 317 | + | if (!umount2(tracing, 0) || errno != EINVAL) | |
| 318 | + | return CHILD_STEP1; | |
| 319 | + | /* the root of the bind doesn't; keep it busy */ | |
| 320 | + | if (chdir(x)) | |
| 321 | + | return CHILD_SETUP; | |
| 322 | + | if (!umount2(x, 0) || errno != EBUSY) | |
| 323 | + | return CHILD_STEP2; | |
| 324 | + | /* the automount below it must not have gone */ | |
| 325 | + | if (stat(x, &root) || fstatat(AT_FDCWD, tracing, &st, AT_NO_AUTOMOUNT)) | |
| 326 | + | return CHILD_SETUP; | |
| 327 | + | return st.st_dev != root.st_dev ? CHILD_OK : CHILD_STEP3; | |
| 328 | + | } | |
| 329 | + | ||
| 330 | + | TEST_F(locked_mount, umount_of_a_bind_leaves_a_locked_automount_alone) | |
| 331 | + | { | |
| 332 | + | char p[PATH_LEN]; | |
| 333 | + | struct stat st; | |
| 334 | + | pid_t pid; | |
| 335 | + | int ret; | |
| 336 | + | ||
| 337 | + | if (!self->tracing) | |
| 338 | + | SKIP(return, "test requires debugfs with the tracefs automount"); | |
| 339 | + | ||
| 340 | + | /* the copy the child gets has to contain the automount */ | |
| 341 | + | snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base); | |
| 342 | + | ASSERT_EQ(stat(p, &st), 0); | |
| 343 | + | snprintf(p, sizeof(p), "%s/x", self->base); | |
| 344 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 345 | + | ||
| 346 | + | pid = fork(); | |
| 347 | + | ASSERT_GE(pid, 0); | |
| 348 | + | if (pid == 0) | |
| 349 | + | _exit(copied_tree_child(self->base)); | |
| 350 | + | ret = wait_child(pid); | |
| 351 | + | TH_LOG("child exit code %d", ret); | |
| 352 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 353 | + | } | |
| 354 | + | ||
| 355 | + | /* | |
| 356 | + | * Z is a user namespace with a copy of a tree in which P/d is covered by a | |
| 357 | + | * locked mount. The host mounts X on P/d, which propagates beneath Z's | |
| 358 | + | * cover, and unmounts it again. Z's cover has to be locked afterwards as | |
| 359 | + | * it was before. | |
| 360 | + | */ | |
| 361 | + | static int propagation_child(const char *base, int to_host, int from_host) | |
| 362 | + | { | |
| 363 | + | char d[PATH_LEN], secret[PATH_LEN]; | |
| 364 | + | ||
| 365 | + | snprintf(d, sizeof(d), "%s/P/d", base); | |
| 366 | + | snprintf(secret, sizeof(secret), "%s/P/d/secret", base); | |
| 367 | + | ||
| 368 | + | if (enter_userns()) | |
| 369 | + | return CHILD_SETUP; | |
| 370 | + | /* the cover is locked */ | |
| 371 | + | if (!umount2(d, 0) || errno != EINVAL) | |
| 372 | + | return CHILD_STEP1; | |
| 373 | + | if (send_byte(to_host) || wait_byte(from_host)) | |
| 374 | + | return CHILD_SETUP; | |
| 375 | + | /* X came and went beneath it: still locked */ | |
| 376 | + | if (!umount2(d, 0) || errno != EINVAL) | |
| 377 | + | return CHILD_STEP2; | |
| 378 | + | return covered(secret) ? CHILD_OK : CHILD_STEP3; | |
| 379 | + | } | |
| 380 | + | ||
| 381 | + | TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked) | |
| 382 | + | { | |
| 383 | + | int to_host[2], from_host[2], ret; | |
| 384 | + | char p[PATH_LEN]; | |
| 385 | + | pid_t pid; | |
| 386 | + | ||
| 387 | + | snprintf(p, sizeof(p), "%s/P", self->base); | |
| 388 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 389 | + | ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0); | |
| 390 | + | ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0); | |
| 391 | + | snprintf(p, sizeof(p), "%s/P/d", self->base); | |
| 392 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 393 | + | snprintf(p, sizeof(p), "%s/P/d/secret", self->base); | |
| 394 | + | ASSERT_EQ(create_file(p, "covered-by-root\n"), 0); | |
| 395 | + | ASSERT_EQ(pipe(to_host), 0); | |
| 396 | + | ASSERT_EQ(pipe(from_host), 0); | |
| 397 | + | ||
| 398 | + | pid = fork(); | |
| 399 | + | ASSERT_GE(pid, 0); | |
| 400 | + | if (pid == 0) { | |
| 401 | + | /* M: a manager's namespace that covers P/d for Z */ | |
| 402 | + | pid_t z; | |
| 403 | + | ||
| 404 | + | if (unshare(CLONE_NEWNS)) | |
| 405 | + | _exit(CHILD_SETUP); | |
| 406 | + | snprintf(p, sizeof(p), "%s/P", self->base); | |
| 407 | + | if (mount(NULL, p, NULL, MS_SLAVE, NULL)) | |
| 408 | + | _exit(CHILD_SETUP); | |
| 409 | + | snprintf(p, sizeof(p), "%s/P/d", self->base); | |
| 410 | + | if (mount("tmpfs", p, "tmpfs", 0, "mode=0755")) | |
| 411 | + | _exit(CHILD_SETUP); | |
| 412 | + | z = fork(); | |
| 413 | + | if (z < 0) | |
| 414 | + | _exit(CHILD_SETUP); | |
| 415 | + | if (z == 0) | |
| 416 | + | _exit(propagation_child(self->base, to_host[1], from_host[0])); | |
| 417 | + | _exit(wait_child(z)); | |
| 418 | + | } | |
| 419 | + | ASSERT_EQ(wait_byte(to_host[0]), 0); | |
| 420 | + | ||
| 421 | + | /* the host mounts on P/d and unmounts again; both propagate */ | |
| 422 | + | snprintf(p, sizeof(p), "%s/P/d", self->base); | |
| 423 | + | ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0); | |
| 424 | + | ASSERT_EQ(umount2(p, 0), 0); | |
| 425 | + | ||
| 426 | + | ASSERT_EQ(send_byte(from_host[1]), 0); | |
| 427 | + | ret = wait_child(pid); | |
| 428 | + | TH_LOG("child exit code %d", ret); | |
| 429 | + | EXPECT_EQ(ret, CHILD_OK); | |
| 430 | + | } | |
| 431 | + | ||
| 432 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/umount_propagation/shrink_submounts_test.c mode 100644
| @@ -0,0 +1,211 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A synchronous umount first unmounts the shrinkable submounts of the | |
| 4 | + | * victim that aren't busy. Every one of them has to be checked right | |
| 5 | + | * before it is unmounted: unmounting one can slide a busy mount to where | |
| 6 | + | * the propagated copy of the next one is looked up. | |
| 7 | + | */ | |
| 8 | + | #define _GNU_SOURCE | |
| 9 | + | #include <errno.h> | |
| 10 | + | #include <fcntl.h> | |
| 11 | + | #include <sched.h> | |
| 12 | + | #include <stdio.h> | |
| 13 | + | #include <stdlib.h> | |
| 14 | + | #include <string.h> | |
| 15 | + | #include <unistd.h> | |
| 16 | + | #include <sys/fanotify.h> | |
| 17 | + | #include <sys/mount.h> | |
| 18 | + | #include <sys/stat.h> | |
| 19 | + | #include <sys/statfs.h> | |
| 20 | + | #include <sys/vfs.h> | |
| 21 | + | #include <linux/magic.h> | |
| 22 | + | ||
| 23 | + | #include "../../kselftest_harness.h" | |
| 24 | + | ||
| 25 | + | #ifndef FAN_REPORT_MNT | |
| 26 | + | #define FAN_REPORT_MNT 0x00004000 | |
| 27 | + | #endif | |
| 28 | + | #ifndef FAN_MARK_MNTNS | |
| 29 | + | #define FAN_MARK_MNTNS 0x00000110 | |
| 30 | + | #endif | |
| 31 | + | #ifndef FAN_MNT_ATTACH | |
| 32 | + | #define FAN_MNT_ATTACH 0x01000000 | |
| 33 | + | #endif | |
| 34 | + | #ifndef FAN_MNT_DETACH | |
| 35 | + | #define FAN_MNT_DETACH 0x02000000 | |
| 36 | + | #endif | |
| 37 | + | ||
| 38 | + | #define DIR_LEN 64 | |
| 39 | + | #define PATH_LEN 128 | |
| 40 | + | ||
| 41 | + | FIXTURE(shrink_submounts) { | |
| 42 | + | char base[DIR_LEN]; | |
| 43 | + | char automount[PATH_LEN]; | |
| 44 | + | bool mounted; | |
| 45 | + | int fan; | |
| 46 | + | }; | |
| 47 | + | ||
| 48 | + | /* | |
| 49 | + | * Shrinkable mounts come from an automount. The tracefs mount below debugfs | |
| 50 | + | * is one and bind mounts inherit the flag. | |
| 51 | + | */ | |
| 52 | + | FIXTURE_SETUP(shrink_submounts) | |
| 53 | + | { | |
| 54 | + | struct stat st; | |
| 55 | + | char p[PATH_LEN]; | |
| 56 | + | ||
| 57 | + | self->mounted = false; | |
| 58 | + | self->fan = -1; | |
| 59 | + | ||
| 60 | + | if (geteuid() != 0) | |
| 61 | + | SKIP(return, "test requires CAP_SYS_ADMIN"); | |
| 62 | + | ||
| 63 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 64 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 65 | + | ||
| 66 | + | snprintf(self->base, sizeof(self->base), "/tmp/shrink_submounts.XXXXXX"); | |
| 67 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 68 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0); | |
| 69 | + | self->mounted = true; | |
| 70 | + | ASSERT_EQ(mount(NULL, self->base, NULL, MS_PRIVATE, NULL), 0); | |
| 71 | + | ||
| 72 | + | snprintf(p, sizeof(p), "%s/dbg", self->base); | |
| 73 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 74 | + | if (mount("debugfs", p, "debugfs", 0, NULL)) { | |
| 75 | + | umount2(self->base, MNT_DETACH); | |
| 76 | + | rmdir(self->base); | |
| 77 | + | SKIP(return, "test requires debugfs"); | |
| 78 | + | } | |
| 79 | + | snprintf(self->automount, sizeof(self->automount), "%s/dbg/tracing", | |
| 80 | + | self->base); | |
| 81 | + | snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base); | |
| 82 | + | if (stat(p, &st)) { | |
| 83 | + | umount2(self->base, MNT_DETACH); | |
| 84 | + | rmdir(self->base); | |
| 85 | + | SKIP(return, "test requires the tracefs automount"); | |
| 86 | + | } | |
| 87 | + | } | |
| 88 | + | ||
| 89 | + | FIXTURE_TEARDOWN(shrink_submounts) | |
| 90 | + | { | |
| 91 | + | if (self->fan >= 0) | |
| 92 | + | close(self->fan); | |
| 93 | + | chdir("/"); | |
| 94 | + | if (self->mounted) | |
| 95 | + | umount2(self->base, MNT_DETACH); | |
| 96 | + | rmdir(self->base); | |
| 97 | + | } | |
| 98 | + | ||
| 99 | + | static bool mounted_tmpfs(const char *path) | |
| 100 | + | { | |
| 101 | + | struct statfs st; | |
| 102 | + | ||
| 103 | + | return !statfs(path, &st) && st.f_type == TMPFS_MAGIC; | |
| 104 | + | } | |
| 105 | + | ||
| 106 | + | /* | |
| 107 | + | * P is a shared bind mount of the automount, P1 a slave of P that is shared | |
| 108 | + | * in turn and P2 its peer. B, another bind mount of the automount, goes on | |
| 109 | + | * P/options and propagates copies Bc1 and Bc2 onto P1/options and | |
| 110 | + | * P2/options. R, a tmpfs and our working directory, sits on top of Bc2 which | |
| 111 | + | * is made private first. P, with B on it, is moved to P1/instances. | |
| 112 | + | * | |
| 113 | + | * A synchronous umount of P1 unmounts the shrinkable submounts Bc1 and B | |
| 114 | + | * first. Unmounting Bc1 takes Bc2 along and slides R to P2/options where | |
| 115 | + | * the propagated copy of B is looked up next. R is busy, so B has to stay | |
| 116 | + | * and the umount fails with EBUSY. | |
| 117 | + | */ | |
| 118 | + | TEST_F(shrink_submounts, busy_mount_moved_into_reach) | |
| 119 | + | { | |
| 120 | + | char p[PATH_LEN], p1[PATH_LEN], p2[PATH_LEN], r[PATH_LEN], cwd[PATH_LEN]; | |
| 121 | + | int nsfd; | |
| 122 | + | ||
| 123 | + | snprintf(p, sizeof(p), "%s/p", self->base); | |
| 124 | + | snprintf(p1, sizeof(p1), "%s/p1", self->base); | |
| 125 | + | snprintf(p2, sizeof(p2), "%s/p2", self->base); | |
| 126 | + | ASSERT_EQ(mkdir(p, 0755), 0); | |
| 127 | + | ASSERT_EQ(mkdir(p1, 0755), 0); | |
| 128 | + | ASSERT_EQ(mkdir(p2, 0755), 0); | |
| 129 | + | ||
| 130 | + | /* watch the mount namespace so that the detached mounts get queued */ | |
| 131 | + | self->fan = fanotify_init(FAN_REPORT_MNT, O_RDONLY); | |
| 132 | + | if (self->fan >= 0) { | |
| 133 | + | nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC); | |
| 134 | + | ASSERT_GE(nsfd, 0); | |
| 135 | + | EXPECT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_MNTNS, | |
| 136 | + | FAN_MNT_ATTACH | FAN_MNT_DETACH, nsfd, NULL), 0); | |
| 137 | + | close(nsfd); | |
| 138 | + | } | |
| 139 | + | ||
| 140 | + | ASSERT_EQ(mount(self->automount, p, NULL, MS_BIND, NULL), 0); | |
| 141 | + | ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0); | |
| 142 | + | ASSERT_EQ(mount(p, p1, NULL, MS_BIND, NULL), 0); | |
| 143 | + | ASSERT_EQ(mount(NULL, p1, NULL, MS_SLAVE, NULL), 0); | |
| 144 | + | ASSERT_EQ(mount(NULL, p1, NULL, MS_SHARED, NULL), 0); | |
| 145 | + | ASSERT_EQ(mount(p1, p2, NULL, MS_BIND, NULL), 0); | |
| 146 | + | ||
| 147 | + | /* B on P/options, copies on P1/options and P2/options */ | |
| 148 | + | snprintf(r, sizeof(r), "%s/p/options", self->base); | |
| 149 | + | ASSERT_EQ(mount(self->automount, r, NULL, MS_BIND, NULL), 0); | |
| 150 | + | ||
| 151 | + | /* R on top of Bc2 */ | |
| 152 | + | snprintf(r, sizeof(r), "%s/p2/options", self->base); | |
| 153 | + | ASSERT_EQ(mount(NULL, r, NULL, MS_PRIVATE, NULL), 0); | |
| 154 | + | ASSERT_EQ(mount("R", r, "tmpfs", 0, NULL), 0); | |
| 155 | + | ASSERT_EQ(chdir(r), 0); | |
| 156 | + | ||
| 157 | + | /* P, with B on it, below the victim */ | |
| 158 | + | snprintf(cwd, sizeof(cwd), "%s/p1/instances", self->base); | |
| 159 | + | ASSERT_EQ(mount(p, cwd, NULL, MS_MOVE, NULL), 0); | |
| 160 | + | ||
| 161 | + | ASSERT_TRUE(mounted_tmpfs(r)); | |
| 162 | + | ASSERT_EQ(umount2(p1, 0), -1); | |
| 163 | + | EXPECT_EQ(errno, EBUSY); | |
| 164 | + | ||
| 165 | + | /* R is still mounted and still our working directory */ | |
| 166 | + | EXPECT_TRUE(mounted_tmpfs(r)); | |
| 167 | + | ASSERT_NE(getcwd(cwd, sizeof(cwd)), NULL); | |
| 168 | + | EXPECT_STREQ(cwd, r); | |
| 169 | + | } | |
| 170 | + | ||
| 171 | + | /* | |
| 172 | + | * T is shared and Q, a slave of T, has T moved into it, so Q receives | |
| 173 | + | * propagation from its own child. M, another bind mount of the automount, is | |
| 174 | + | * on T/options and that is the dentry T sits on in Q. Unmounting M makes T | |
| 175 | + | * the propagated victim at that dentry in Q and takes T along. The shrink | |
| 176 | + | * walk of V has just unmounted M and continues in the children of T. | |
| 177 | + | */ | |
| 178 | + | TEST_F(shrink_submounts, parent_goes_with_child) | |
| 179 | + | { | |
| 180 | + | char v[PATH_LEN], t[PATH_LEN], q[PATH_LEN], p[PATH_LEN]; | |
| 181 | + | struct stat before, after; | |
| 182 | + | ||
| 183 | + | snprintf(v, sizeof(v), "%s/v", self->base); | |
| 184 | + | snprintf(t, sizeof(t), "%s/v/t", self->base); | |
| 185 | + | snprintf(q, sizeof(q), "%s/v/q", self->base); | |
| 186 | + | ASSERT_EQ(mkdir(v, 0755), 0); | |
| 187 | + | ASSERT_EQ(mount("V", v, "tmpfs", 0, NULL), 0); | |
| 188 | + | ASSERT_EQ(mount(NULL, v, NULL, MS_PRIVATE, NULL), 0); | |
| 189 | + | ASSERT_EQ(stat(v, &before), 0); | |
| 190 | + | ASSERT_EQ(mkdir(t, 0755), 0); | |
| 191 | + | ASSERT_EQ(mkdir(q, 0755), 0); | |
| 192 | + | ||
| 193 | + | /* T shared, M on T/options before anything receives from T */ | |
| 194 | + | ASSERT_EQ(mount(self->automount, t, NULL, MS_BIND, NULL), 0); | |
| 195 | + | ASSERT_EQ(mount(NULL, t, NULL, MS_SHARED, NULL), 0); | |
| 196 | + | snprintf(p, sizeof(p), "%s/v/t/options", self->base); | |
| 197 | + | ASSERT_EQ(mount(self->automount, p, NULL, MS_BIND, NULL), 0); | |
| 198 | + | ||
| 199 | + | /* Q, a slave of T, and T moved into Q at the dentry M sits on */ | |
| 200 | + | ASSERT_EQ(mount(t, q, NULL, MS_BIND, NULL), 0); | |
| 201 | + | ASSERT_EQ(mount(NULL, q, NULL, MS_SLAVE, NULL), 0); | |
| 202 | + | snprintf(p, sizeof(p), "%s/v/q/options", self->base); | |
| 203 | + | ASSERT_EQ(mount(t, p, NULL, MS_MOVE, NULL), 0); | |
| 204 | + | ||
| 205 | + | /* M, T and then Q go, V is empty and can be unmounted */ | |
| 206 | + | ASSERT_EQ(umount2(v, 0), 0); | |
| 207 | + | ASSERT_EQ(stat(v, &after), 0); | |
| 208 | + | EXPECT_NE(before.st_dev, after.st_dev); | |
| 209 | + | } | |
| 210 | + | ||
| 211 | + | TEST_HARNESS_MAIN | |
added tools/testing/selftests/filesystems/umount_propagation/umount_propagation_test.c mode 100644
| @@ -0,0 +1,226 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * A synchronous umount fails with EBUSY when a mount it would pull out by | |
| 4 | + | * propagation is still in use. | |
| 5 | + | */ | |
| 6 | + | #define _GNU_SOURCE | |
| 7 | + | #include <errno.h> | |
| 8 | + | #include <fcntl.h> | |
| 9 | + | #include <sched.h> | |
| 10 | + | #include <stdio.h> | |
| 11 | + | #include <stdlib.h> | |
| 12 | + | #include <string.h> | |
| 13 | + | #include <sys/mount.h> | |
| 14 | + | #include <sys/stat.h> | |
| 15 | + | #include <sys/syscall.h> | |
| 16 | + | #include <sys/wait.h> | |
| 17 | + | #include <unistd.h> | |
| 18 | + | #include <linux/mount.h> | |
| 19 | + | #include <linux/stat.h> | |
| 20 | + | ||
| 21 | + | #include "../../kselftest_harness.h" | |
| 22 | + | ||
| 23 | + | #ifndef OPEN_TREE_CLONE | |
| 24 | + | #define OPEN_TREE_CLONE 1 | |
| 25 | + | #endif | |
| 26 | + | #ifndef OPEN_TREE_CLOEXEC | |
| 27 | + | #define OPEN_TREE_CLOEXEC O_CLOEXEC | |
| 28 | + | #endif | |
| 29 | + | #ifndef AT_RECURSIVE | |
| 30 | + | #define AT_RECURSIVE 0x8000 | |
| 31 | + | #endif | |
| 32 | + | #ifndef MOVE_MOUNT_F_EMPTY_PATH | |
| 33 | + | #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 | |
| 34 | + | #endif | |
| 35 | + | #ifndef MOVE_MOUNT_BENEATH | |
| 36 | + | #define MOVE_MOUNT_BENEATH 0x00000200 | |
| 37 | + | #endif | |
| 38 | + | #ifndef STATX_MNT_ID | |
| 39 | + | #define STATX_MNT_ID 0x00001000U | |
| 40 | + | #endif | |
| 41 | + | ||
| 42 | + | static int sys_open_tree(int dfd, const char *filename, unsigned int flags) | |
| 43 | + | { | |
| 44 | + | return syscall(__NR_open_tree, dfd, filename, flags); | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | static int sys_move_mount(int from_dfd, const char *from_pathname, | |
| 48 | + | int to_dfd, const char *to_pathname, | |
| 49 | + | unsigned int flags) | |
| 50 | + | { | |
| 51 | + | return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, | |
| 52 | + | to_pathname, flags); | |
| 53 | + | } | |
| 54 | + | ||
| 55 | + | /* Child exit codes. */ | |
| 56 | + | enum { | |
| 57 | + | CHILD_OK, | |
| 58 | + | CHILD_UNSHARE, /* could not set up the slave namespace */ | |
| 59 | + | CHILD_OPEN_TREE, /* open_tree() failed */ | |
| 60 | + | CHILD_MOVE_MOUNT, /* move_mount() failed */ | |
| 61 | + | CHILD_STATX, /* statx() failed */ | |
| 62 | + | CHILD_PIPE, /* the parent went away */ | |
| 63 | + | }; | |
| 64 | + | ||
| 65 | + | /* Messages between parent and child. */ | |
| 66 | + | enum { | |
| 67 | + | MSG_READY = 'r', /* child: the copy is mounted and referenced */ | |
| 68 | + | MSG_CHECK = 'c', /* parent: check that the copy is still attached */ | |
| 69 | + | MSG_ATTACHED = 'a', /* child: it is */ | |
| 70 | + | MSG_DETACHED = 'd', /* child: it is not */ | |
| 71 | + | MSG_CLOSE = 'x', /* parent: drop the reference */ | |
| 72 | + | MSG_CLOSED = 'y', /* child: dropped */ | |
| 73 | + | MSG_EXIT = 'e', /* parent: done */ | |
| 74 | + | }; | |
| 75 | + | ||
| 76 | + | FIXTURE(umount_propagation) | |
| 77 | + | { | |
| 78 | + | char base[64]; | |
| 79 | + | char victim[80]; | |
| 80 | + | bool mounted; | |
| 81 | + | }; | |
| 82 | + | ||
| 83 | + | FIXTURE_SETUP(umount_propagation) | |
| 84 | + | { | |
| 85 | + | self->mounted = false; | |
| 86 | + | ||
| 87 | + | if (geteuid() != 0) | |
| 88 | + | SKIP(return, "test requires CAP_SYS_ADMIN"); | |
| 89 | + | ||
| 90 | + | ASSERT_EQ(unshare(CLONE_NEWNS), 0); | |
| 91 | + | ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0); | |
| 92 | + | ||
| 93 | + | snprintf(self->base, sizeof(self->base), "/tmp/umount_propagation.XXXXXX"); | |
| 94 | + | ASSERT_NE(mkdtemp(self->base), NULL); | |
| 95 | + | ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0); | |
| 96 | + | self->mounted = true; | |
| 97 | + | ASSERT_EQ(mount(NULL, self->base, NULL, MS_SHARED, NULL), 0); | |
| 98 | + | ||
| 99 | + | snprintf(self->victim, sizeof(self->victim), "%s/victim", self->base); | |
| 100 | + | ASSERT_EQ(mkdir(self->victim, 0755), 0); | |
| 101 | + | ASSERT_EQ(mount("tmpfs", self->victim, "tmpfs", 0, NULL), 0); | |
| 102 | + | } | |
| 103 | + | ||
| 104 | + | FIXTURE_TEARDOWN(umount_propagation) | |
| 105 | + | { | |
| 106 | + | if (self->mounted) | |
| 107 | + | umount2(self->base, MNT_DETACH); | |
| 108 | + | rmdir(self->base); | |
| 109 | + | } | |
| 110 | + | ||
| 111 | + | static int send_msg(int fd, char msg) | |
| 112 | + | { | |
| 113 | + | return write(fd, &msg, 1) == 1 ? 0 : -1; | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | static char recv_msg(int fd) | |
| 117 | + | { | |
| 118 | + | char msg; | |
| 119 | + | ||
| 120 | + | if (read(fd, &msg, 1) != 1) | |
| 121 | + | return 0; | |
| 122 | + | return msg; | |
| 123 | + | } | |
| 124 | + | ||
| 125 | + | /* Is the mount with id @mnt_id attached in this mount namespace? */ | |
| 126 | + | static bool mount_attached(__u64 mnt_id) | |
| 127 | + | { | |
| 128 | + | char line[4096]; | |
| 129 | + | bool found = false; | |
| 130 | + | FILE *f; | |
| 131 | + | ||
| 132 | + | f = fopen("/proc/self/mountinfo", "re"); | |
| 133 | + | if (!f) | |
| 134 | + | return false; | |
| 135 | + | ||
| 136 | + | while (fgets(line, sizeof(line), f)) { | |
| 137 | + | if (strtoull(line, NULL, 10) == mnt_id) { | |
| 138 | + | found = true; | |
| 139 | + | break; | |
| 140 | + | } | |
| 141 | + | } | |
| 142 | + | fclose(f); | |
| 143 | + | return found; | |
| 144 | + | } | |
| 145 | + | ||
| 146 | + | /* | |
| 147 | + | * The slave namespace: take a detached copy of the shared tree and move it | |
| 148 | + | * beneath the propagated copy of the victim, keeping the open_tree() | |
| 149 | + | * descriptor as a reference on it. | |
| 150 | + | */ | |
| 151 | + | static int slave_child(const char *base, const char *victim, int to_parent, | |
| 152 | + | int from_parent) | |
| 153 | + | { | |
| 154 | + | struct statx stx; | |
| 155 | + | int fd; | |
| 156 | + | ||
| 157 | + | if (unshare(CLONE_NEWNS)) | |
| 158 | + | return CHILD_UNSHARE; | |
| 159 | + | if (mount("", "/", NULL, MS_REC | MS_SLAVE, NULL)) | |
| 160 | + | return CHILD_UNSHARE; | |
| 161 | + | ||
| 162 | + | fd = sys_open_tree(AT_FDCWD, base, | |
| 163 | + | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_RECURSIVE); | |
| 164 | + | if (fd < 0) | |
| 165 | + | return CHILD_OPEN_TREE; | |
| 166 | + | if (sys_move_mount(fd, "", AT_FDCWD, victim, | |
| 167 | + | MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_BENEATH)) | |
| 168 | + | return CHILD_MOVE_MOUNT; | |
| 169 | + | if (statx(fd, "", AT_EMPTY_PATH, STATX_MNT_ID, &stx)) | |
| 170 | + | return CHILD_STATX; | |
| 171 | + | ||
| 172 | + | if (send_msg(to_parent, MSG_READY) || recv_msg(from_parent) != MSG_CHECK) | |
| 173 | + | return CHILD_PIPE; | |
| 174 | + | if (send_msg(to_parent, mount_attached(stx.stx_mnt_id) ? | |
| 175 | + | MSG_ATTACHED : MSG_DETACHED)) | |
| 176 | + | return CHILD_PIPE; | |
| 177 | + | ||
| 178 | + | if (recv_msg(from_parent) != MSG_CLOSE) | |
| 179 | + | return CHILD_PIPE; | |
| 180 | + | close(fd); | |
| 181 | + | if (send_msg(to_parent, MSG_CLOSED) || recv_msg(from_parent) != MSG_EXIT) | |
| 182 | + | return CHILD_PIPE; | |
| 183 | + | return CHILD_OK; | |
| 184 | + | } | |
| 185 | + | ||
| 186 | + | TEST_F(umount_propagation, busy_copy_pulled_out) | |
| 187 | + | { | |
| 188 | + | int to_child[2], to_parent[2]; | |
| 189 | + | int status; | |
| 190 | + | pid_t pid; | |
| 191 | + | ||
| 192 | + | ASSERT_EQ(pipe(to_child), 0); | |
| 193 | + | ASSERT_EQ(pipe(to_parent), 0); | |
| 194 | + | ||
| 195 | + | pid = fork(); | |
| 196 | + | ASSERT_GE(pid, 0); | |
| 197 | + | if (pid == 0) { | |
| 198 | + | close(to_child[1]); | |
| 199 | + | close(to_parent[0]); | |
| 200 | + | _exit(slave_child(self->base, self->victim, to_parent[1], | |
| 201 | + | to_child[0])); | |
| 202 | + | } | |
| 203 | + | close(to_child[0]); | |
| 204 | + | close(to_parent[1]); | |
| 205 | + | ||
| 206 | + | ASSERT_EQ(recv_msg(to_parent[0]), MSG_READY); | |
| 207 | + | ||
| 208 | + | /* the copy in the slave namespace is in use */ | |
| 209 | + | ASSERT_EQ(umount2(self->victim, 0), -1); | |
| 210 | + | ASSERT_EQ(errno, EBUSY); | |
| 211 | + | ||
| 212 | + | ASSERT_EQ(send_msg(to_child[1], MSG_CHECK), 0); | |
| 213 | + | ASSERT_EQ(recv_msg(to_parent[0]), MSG_ATTACHED); | |
| 214 | + | ||
| 215 | + | /* and once it is not, the umount goes through */ | |
| 216 | + | ASSERT_EQ(send_msg(to_child[1], MSG_CLOSE), 0); | |
| 217 | + | ASSERT_EQ(recv_msg(to_parent[0]), MSG_CLOSED); | |
| 218 | + | ASSERT_EQ(umount2(self->victim, 0), 0); | |
| 219 | + | ||
| 220 | + | ASSERT_EQ(send_msg(to_child[1], MSG_EXIT), 0); | |
| 221 | + | ASSERT_EQ(waitpid(pid, &status, 0), pid); | |
| 222 | + | ASSERT_TRUE(WIFEXITED(status)); | |
| 223 | + | ASSERT_EQ(WEXITSTATUS(status), CHILD_OK); | |
| 224 | + | } | |
| 225 | + | ||
| 226 | + | TEST_HARNESS_MAIN | |
modified tools/testing/selftests/mm/hugetlb-mmap.c
| @@ -122,7 +122,7 @@ int main(int argc, char **argv) | |||
| 122 | 122 | hugepage_size = default_huge_page_size(); | |
| 123 | 123 | if (!hugepage_size) | |
| 124 | 124 | ksft_exit_skip("Could not detect default hugetlb page size."); | |
| 125 | - | ksft_print_msg("Default size hugepages (%lu kB)\n", hugepage_size >> 10); | |
| 125 | + | ksft_print_msg("Default size hugepages (%zu kB)\n", hugepage_size >> 10); | |
| 126 | 126 | } | |
| 127 | 127 | ||
| 128 | 128 | /* munmap will fail if the length is not page aligned */ | |
| @@ -131,7 +131,7 @@ int main(int argc, char **argv) | |||
| 131 | 131 | ||
| 132 | 132 | hugetlb_set_nr_pages(hugepage_size, nr); | |
| 133 | 133 | if (hugetlb_free_pages(hugepage_size) < nr) | |
| 134 | - | ksft_exit_skip("Not enough %lu Kb pages\n", hugepage_size >> 10); | |
| 134 | + | ksft_exit_skip("Not enough %zu Kb pages\n", hugepage_size >> 10); | |
| 135 | 135 | ||
| 136 | 136 | ksft_set_plan(2); | |
| 137 | 137 | ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20); | |
modified tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
| @@ -146,17 +146,19 @@ static void null_endofword(char *word) | |||
| 146 | 146 | *word = '\0'; | |
| 147 | 147 | } | |
| 148 | 148 | ||
| 149 | - | static bool is_shared_mount(const char *path) | |
| 149 | + | /* Does the mount on @path carry the optional field @field in mountinfo? */ | |
| 150 | + | static bool mount_has_field(const char *path, const char *field) | |
| 150 | 151 | { | |
| 151 | 152 | size_t len = 0; | |
| 152 | 153 | char *line = NULL; | |
| 153 | 154 | FILE *f = NULL; | |
| 155 | + | bool found = false; | |
| 154 | 156 | ||
| 155 | 157 | f = fopen("/proc/self/mountinfo", "re"); | |
| 156 | 158 | if (!f) | |
| 157 | 159 | return false; | |
| 158 | 160 | ||
| 159 | - | while (getline(&line, &len, f) != -1) { | |
| 161 | + | while (!found && getline(&line, &len, f) != -1) { | |
| 160 | 162 | char *opts, *target; | |
| 161 | 163 | ||
| 162 | 164 | target = get_field(line, 4); | |
| @@ -172,15 +174,29 @@ static bool is_shared_mount(const char *path) | |||
| 172 | 174 | if (strcmp(target, path) != 0) | |
| 173 | 175 | continue; | |
| 174 | 176 | ||
| 175 | - | null_endofword(opts); | |
| 176 | - | if (strstr(opts, "shared:")) | |
| 177 | - | return true; | |
| 177 | + | /* the optional fields end at the "-" separator */ | |
| 178 | + | while (opts && *opts != '-') { | |
| 179 | + | char *next = strchr(opts, ' '); | |
| 180 | + | ||
| 181 | + | if (next) | |
| 182 | + | *next++ = '\0'; | |
| 183 | + | if (!strncmp(opts, field, strlen(field))) { | |
| 184 | + | found = true; | |
| 185 | + | break; | |
| 186 | + | } | |
| 187 | + | opts = next; | |
| 188 | + | } | |
| 178 | 189 | } | |
| 179 | 190 | ||
| 180 | 191 | free(line); | |
| 181 | 192 | fclose(f); | |
| 182 | 193 | ||
| 183 | - | return false; | |
| 194 | + | return found; | |
| 195 | + | } | |
| 196 | + | ||
| 197 | + | static bool is_shared_mount(const char *path) | |
| 198 | + | { | |
| 199 | + | return mount_has_field(path, "shared:"); | |
| 184 | 200 | } | |
| 185 | 201 | ||
| 186 | 202 | /* Attempt to de-conflict with the selftests tree. */ | |
| @@ -372,4 +388,50 @@ TEST_F(move_mount_set_group, complex_sharing_copying) | |||
| 372 | 388 | ASSERT_EQ(is_shared_mount(SET_GROUP_A), 1); | |
| 373 | 389 | } | |
| 374 | 390 | ||
| 391 | + | #define SET_GROUP_B "/tmp/B" | |
| 392 | + | #define SET_GROUP_C "/tmp/C" | |
| 393 | + | ||
| 394 | + | /* | |
| 395 | + | * An unbindable mount is neither shared nor a slave, so it must not be | |
| 396 | + | * accepted as the target: with a slave source it would end up unbindable | |
| 397 | + | * and a slave at the same time. | |
| 398 | + | */ | |
| 399 | + | TEST_F(move_mount_set_group, unbindable_target) | |
| 400 | + | { | |
| 401 | + | bool ret; | |
| 402 | + | ||
| 403 | + | ret = move_mount_set_group_supported(); | |
| 404 | + | ASSERT_GE(ret, 0); | |
| 405 | + | if (!ret) | |
| 406 | + | SKIP(return, "move_mount(MOVE_MOUNT_SET_GROUP) is not supported"); | |
| 407 | + | ||
| 408 | + | ASSERT_EQ(mount(NULL, SET_GROUP_A, NULL, MS_SHARED, 0), 0); | |
| 409 | + | ||
| 410 | + | /* B: a slave of A's peer group */ | |
| 411 | + | ASSERT_EQ(mkdir(SET_GROUP_B, 0777), 0); | |
| 412 | + | ASSERT_EQ(mount(SET_GROUP_A, SET_GROUP_B, NULL, MS_BIND, NULL), 0); | |
| 413 | + | ASSERT_EQ(mount(NULL, SET_GROUP_B, NULL, MS_SLAVE, 0), 0); | |
| 414 | + | ASSERT_TRUE(mount_has_field(SET_GROUP_B, "master:")); | |
| 415 | + | ||
| 416 | + | /* C: unbindable */ | |
| 417 | + | ASSERT_EQ(mkdir(SET_GROUP_C, 0777), 0); | |
| 418 | + | ASSERT_EQ(mount(SET_GROUP_A, SET_GROUP_C, NULL, MS_BIND, NULL), 0); | |
| 419 | + | ASSERT_EQ(mount(NULL, SET_GROUP_C, NULL, MS_UNBINDABLE, 0), 0); | |
| 420 | + | ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable")); | |
| 421 | + | ||
| 422 | + | /* from a slave */ | |
| 423 | + | ASSERT_EQ(syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_B, | |
| 424 | + | AT_FDCWD, SET_GROUP_C, MOVE_MOUNT_SET_GROUP), -1); | |
| 425 | + | ASSERT_EQ(errno, EINVAL); | |
| 426 | + | ASSERT_FALSE(mount_has_field(SET_GROUP_C, "master:")); | |
| 427 | + | ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable")); | |
| 428 | + | ||
| 429 | + | /* from a shared mount */ | |
| 430 | + | ASSERT_EQ(syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_A, | |
| 431 | + | AT_FDCWD, SET_GROUP_C, MOVE_MOUNT_SET_GROUP), -1); | |
| 432 | + | ASSERT_EQ(errno, EINVAL); | |
| 433 | + | ASSERT_FALSE(mount_has_field(SET_GROUP_C, "shared:")); | |
| 434 | + | ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable")); | |
| 435 | + | } | |
| 436 | + | ||
| 375 | 437 | TEST_HARNESS_MAIN | |
modified tools/testing/selftests/net/amt.sh
| @@ -150,6 +150,13 @@ setup_interface() | |||
| 150 | 150 | ip netns exec "${RELAY}" ip a a 10.0.0.2/24 dev relay_gw | |
| 151 | 151 | ip netns exec "${RELAY}" ip link add amtr type amt mode relay \ | |
| 152 | 152 | local 10.0.0.2 dev relay_gw relay_port 2268 max_tunnels 4 | |
| 153 | + | # Count the IGMP and MLD queries that leave the relay through its own | |
| 154 | + | # amt device; test_query_egress expects none. | |
| 155 | + | ip netns exec "${RELAY}" tc qdisc add dev amtr clsact | |
| 156 | + | ip netns exec "${RELAY}" tc filter add dev amtr egress pref 1 \ | |
| 157 | + | protocol ip flower ip_proto 0x2 action pass | |
| 158 | + | ip netns exec "${RELAY}" tc filter add dev amtr egress pref 2 \ | |
| 159 | + | protocol ipv6 flower ip_proto icmpv6 type 130 action pass | |
| 153 | 160 | ip netns exec "${RELAY}" ip a a 172.17.0.1/24 dev relay_src | |
| 154 | 161 | ip netns exec "${RELAY}" ip a a 2001:db8:3::1/64 dev relay_src | |
| 155 | 162 | ip netns exec "${SOURCE}" ip a a 172.17.0.2/24 dev src_relay | |
| @@ -246,6 +253,27 @@ test_ipv6_forward() | |||
| 246 | 253 | fi | |
| 247 | 254 | } | |
| 248 | 255 | ||
| 256 | + | # The relay sends its General Queries straight from the receive path, in | |
| 257 | + | # the same context that found the tunnel. A query queued on the amt device | |
| 258 | + | # instead could outlive the tunnel it was built for. The forwarding tests | |
| 259 | + | # above show that the gateway got its queries. | |
| 260 | + | test_query_egress() | |
| 261 | + | { | |
| 262 | + | local n4 n6 | |
| 263 | + | ||
| 264 | + | n4=$(ip netns exec "${RELAY}" tc -s -j filter show dev amtr egress \ | |
| 265 | + | pref 1 | jq '[.[].options.actions[0].stats.packets // empty] | add // 0') | |
| 266 | + | n6=$(ip netns exec "${RELAY}" tc -s -j filter show dev amtr egress \ | |
| 267 | + | pref 2 | jq '[.[].options.actions[0].stats.packets // empty] | add // 0') | |
| 268 | + | if [ "$n4" -eq 0 ] && [ "$n6" -eq 0 ]; then | |
| 269 | + | printf "TEST: %-60s [ OK ]\n" "amt relay queries bypass the amt device" | |
| 270 | + | else | |
| 271 | + | printf "TEST: %-60s [FAIL]\n" "amt relay queries bypass the amt device" | |
| 272 | + | echo "IGMP queries on amtr egress: $n4, MLD queries: $n6" >&2 | |
| 273 | + | ERR=1 | |
| 274 | + | fi | |
| 275 | + | } | |
| 276 | + | ||
| 249 | 277 | send_mcast4() | |
| 250 | 278 | { | |
| 251 | 279 | sleep 5 | |
| @@ -287,6 +315,7 @@ wait $pid || err=$? | |||
| 287 | 315 | if [ $err -eq 1 ]; then | |
| 288 | 316 | ERR=1 | |
| 289 | 317 | fi | |
| 318 | + | test_query_egress | |
| 290 | 319 | printf "TEST: %-50s" "IPv4 amt traffic forwarding torture" | |
| 291 | 320 | send_mcast_torture4 | |
| 292 | 321 | printf " [ OK ]\n" | |
modified tools/testing/selftests/net/tun.c
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | #include <string.h> | |
| 10 | 10 | #include <unistd.h> | |
| 11 | 11 | #include <linux/if_tun.h> | |
| 12 | + | #include <netinet/tcp.h> | |
| 12 | 13 | #include <sys/ioctl.h> | |
| 13 | 14 | #include <sys/socket.h> | |
| 14 | 15 | ||
| @@ -542,6 +543,141 @@ TEST_F(tun, reattach_close_delete) | |||
| 542 | 543 | EXPECT_EQ(tun_delete(self->ifname), 0); | |
| 543 | 544 | } | |
| 544 | 545 | ||
| 546 | + | FIXTURE(tun_vnet_gso) | |
| 547 | + | { | |
| 548 | + | char ifname[IFNAMSIZ]; | |
| 549 | + | int fd; | |
| 550 | + | }; | |
| 551 | + | ||
| 552 | + | FIXTURE_SETUP(tun_vnet_gso) | |
| 553 | + | { | |
| 554 | + | int flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR; | |
| 555 | + | ||
| 556 | + | memset(self->ifname, 0, sizeof(self->ifname)); | |
| 557 | + | self->fd = tun_open(self->ifname, flags, 0, 0, NULL); | |
| 558 | + | ASSERT_GE(self->fd, 0); | |
| 559 | + | } | |
| 560 | + | ||
| 561 | + | FIXTURE_TEARDOWN(tun_vnet_gso) | |
| 562 | + | { | |
| 563 | + | if (self->fd >= 0) | |
| 564 | + | close(self->fd); | |
| 565 | + | } | |
| 566 | + | ||
| 567 | + | static int build_vlan_tcpv4_gso_packet(uint8_t *buf, int payload_len) | |
| 568 | + | { | |
| 569 | + | uint16_t vlan_tag[2] = { htons(100), htons(ETH_P_IP) }; | |
| 570 | + | uint8_t *cur = buf + sizeof(struct virtio_net_hdr); | |
| 571 | + | struct virtio_net_hdr vh = { 0 }; | |
| 572 | + | struct tcphdr tcph = { 0 }; | |
| 573 | + | uint32_t sum; | |
| 574 | + | ||
| 575 | + | cur += build_eth(cur, ETH_P_8021Q, param_hwaddr_outer_src, | |
| 576 | + | param_hwaddr_outer_dst); | |
| 577 | + | ||
| 578 | + | /* 802.1Q tag: VID=100, inner protocol=ETH_P_IP */ | |
| 579 | + | memcpy(cur, vlan_tag, sizeof(vlan_tag)); | |
| 580 | + | cur += sizeof(vlan_tag); | |
| 581 | + | ||
| 582 | + | cur += build_ipv4_header(cur, IPPROTO_TCP, | |
| 583 | + | sizeof(tcph) + payload_len, | |
| 584 | + | ¶m_ipaddr4_outer_src, | |
| 585 | + | ¶m_ipaddr4_outer_dst); | |
| 586 | + | ||
| 587 | + | tcph.source = htons(12345); | |
| 588 | + | tcph.dest = htons(80); | |
| 589 | + | tcph.seq = htonl(1); | |
| 590 | + | tcph.doff = sizeof(tcph) / 4; | |
| 591 | + | tcph.ack = 1; | |
| 592 | + | tcph.window = htons(65535); | |
| 593 | + | memcpy(cur, &tcph, sizeof(tcph)); | |
| 594 | + | memset(cur + sizeof(tcph), PKT_DATA, payload_len); | |
| 595 | + | ||
| 596 | + | sum = add_csum((const uint8_t *)¶m_ipaddr4_outer_src, | |
| 597 | + | sizeof(param_ipaddr4_outer_src)); | |
| 598 | + | sum += add_csum((const uint8_t *)¶m_ipaddr4_outer_dst, | |
| 599 | + | sizeof(param_ipaddr4_outer_dst)); | |
| 600 | + | sum += htons(IPPROTO_TCP) + htons(sizeof(tcph) + payload_len); | |
| 601 | + | sum += add_csum(cur, sizeof(tcph) + payload_len); | |
| 602 | + | tcph.check = finish_ip_csum(sum); | |
| 603 | + | memcpy(cur, &tcph, sizeof(tcph)); | |
| 604 | + | cur += sizeof(tcph) + payload_len; | |
| 605 | + | ||
| 606 | + | vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; | |
| 607 | + | vh.gso_size = 1400; | |
| 608 | + | vh.hdr_len = (cur - buf) - sizeof(vh) - payload_len; | |
| 609 | + | memcpy(buf, &vh, sizeof(vh)); | |
| 610 | + | ||
| 611 | + | return cur - buf; | |
| 612 | + | } | |
| 613 | + | ||
| 614 | + | TEST_F(tun_vnet_gso, vlan_tcpv4_gso_no_csum) | |
| 615 | + | { | |
| 616 | + | struct virtio_net_hdr vh; | |
| 617 | + | uint8_t pkt[4096] = { 0 }; | |
| 618 | + | int len, ret; | |
| 619 | + | ||
| 620 | + | len = build_vlan_tcpv4_gso_packet(pkt, 2800); | |
| 621 | + | memcpy(&vh, pkt, sizeof(vh)); | |
| 622 | + | ||
| 623 | + | /* Valid VLAN-tagged TCPv4 GSO with flags = 0 (no NEEDS_CSUM) */ | |
| 624 | + | vh.flags = 0; | |
| 625 | + | memcpy(pkt, &vh, sizeof(vh)); | |
| 626 | + | ret = write(self->fd, pkt, len); | |
| 627 | + | ASSERT_EQ(ret, len); | |
| 628 | + | ||
| 629 | + | /* Valid VLAN-tagged TCPv4 GSO with flags = DATA_VALID */ | |
| 630 | + | vh.flags = VIRTIO_NET_HDR_F_DATA_VALID; | |
| 631 | + | memcpy(pkt, &vh, sizeof(vh)); | |
| 632 | + | ret = write(self->fd, pkt, len); | |
| 633 | + | ASSERT_EQ(ret, len); | |
| 634 | + | ||
| 635 | + | /* Mismatched GSO type (TCPV6 on VLAN-tagged IPv4 packet) */ | |
| 636 | + | vh.flags = 0; | |
| 637 | + | vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV6; | |
| 638 | + | memcpy(pkt, &vh, sizeof(vh)); | |
| 639 | + | ret = write(self->fd, pkt, len); | |
| 640 | + | ASSERT_EQ(ret, -1); | |
| 641 | + | ASSERT_EQ(errno, EINVAL); | |
| 642 | + | ||
| 643 | + | /* TCP header truncated after 10 bytes, without NEEDS_CSUM. | |
| 644 | + | * Requires the transport header offset found by flow dissection: | |
| 645 | + | * pulling only sizeof(struct iphdr) + sizeof(struct tcphdr) bytes | |
| 646 | + | * from the mac header would accept this frame. | |
| 647 | + | */ | |
| 648 | + | vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; | |
| 649 | + | vh.hdr_len = ETH_HLEN + 4 + sizeof(struct iphdr) + 10; | |
| 650 | + | memcpy(pkt, &vh, sizeof(vh)); | |
| 651 | + | ret = write(self->fd, pkt, sizeof(vh) + vh.hdr_len); | |
| 652 | + | ASSERT_EQ(ret, -1); | |
| 653 | + | ASSERT_EQ(errno, EINVAL); | |
| 654 | + | } | |
| 655 | + | ||
| 656 | + | TEST_F(tun_vnet_gso, vlan_tcpv4_gso_no_csum_64k) | |
| 657 | + | { | |
| 658 | + | /* Ethernet frame of 65540 bytes: skb->len is above U16_MAX when the | |
| 659 | + | * frame is flow-dissected, before eth_type_trans() pulls ETH_HLEN. | |
| 660 | + | */ | |
| 661 | + | const int payload_len = 65540 - ETH_HLEN - 4 - | |
| 662 | + | sizeof(struct iphdr) - sizeof(struct tcphdr); | |
| 663 | + | struct virtio_net_hdr vh; | |
| 664 | + | uint8_t *pkt; | |
| 665 | + | int len, ret; | |
| 666 | + | ||
| 667 | + | pkt = calloc(1, sizeof(vh) + 65540); | |
| 668 | + | ASSERT_NE(pkt, NULL); | |
| 669 | + | ||
| 670 | + | len = build_vlan_tcpv4_gso_packet(pkt, payload_len); | |
| 671 | + | ASSERT_EQ(len, sizeof(vh) + 65540); | |
| 672 | + | memcpy(&vh, pkt, sizeof(vh)); | |
| 673 | + | ||
| 674 | + | vh.flags = 0; | |
| 675 | + | memcpy(pkt, &vh, sizeof(vh)); | |
| 676 | + | ret = write(self->fd, pkt, len); | |
| 677 | + | free(pkt); | |
| 678 | + | ASSERT_EQ(ret, len); | |
| 679 | + | } | |
| 680 | + | ||
| 545 | 681 | FIXTURE(tun_vnet_udptnl) | |
| 546 | 682 | { | |
| 547 | 683 | char ifname[IFNAMSIZ]; | |
modified tools/testing/selftests/net/veth.sh
| @@ -9,6 +9,8 @@ readonly DST=1 | |||
| 9 | 9 | readonly DST_NAT=100 | |
| 10 | 10 | readonly NS_SRC=$BASE$SRC | |
| 11 | 11 | readonly NS_DST=$BASE$DST | |
| 12 | + | # shellcheck disable=SC2155 # prefer RO variable over return value from cmd | |
| 13 | + | readonly YNL="$(dirname "$(readlink -f "$0")")/../../../net/ynl/pyynl/cli.py" | |
| 12 | 14 | ||
| 13 | 15 | # "baremetal" network used for raw UDP traffic | |
| 14 | 16 | readonly BM_NET_V4=192.168.1. | |
| @@ -74,6 +76,37 @@ chk_tso_flag() { | |||
| 74 | 76 | __chk_flag "$1" $2 $3 tcp-segmentation-offload | |
| 75 | 77 | } | |
| 76 | 78 | ||
| 79 | + | chk_xdp_feature() { | |
| 80 | + | local msg="$1" | |
| 81 | + | local target=$2 | |
| 82 | + | local expected=$3 | |
| 83 | + | local feature=$4 | |
| 84 | + | local ifindex | |
| 85 | + | local out | |
| 86 | + | local st | |
| 87 | + | local flag | |
| 88 | + | ||
| 89 | + | ifindex=`ip netns exec $BASE$target cat /sys/class/net/veth$target/ifindex` | |
| 90 | + | out=`ip netns exec $BASE$target "$YNL" --family netdev --do dev-get \ | |
| 91 | + | --output-json --json "{\"ifindex\": $ifindex}" 2>&1` | |
| 92 | + | st=$? | |
| 93 | + | ||
| 94 | + | printf "%-60s" "$msg" | |
| 95 | + | if [ $st -ne 0 ]; then | |
| 96 | + | echo " fail - ynl cli error: $out" | |
| 97 | + | ret=1 | |
| 98 | + | return | |
| 99 | + | fi | |
| 100 | + | ||
| 101 | + | flag=`echo "$out" | grep -c "\"$feature\""` | |
| 102 | + | if [ "$flag" = "$expected" ]; then | |
| 103 | + | echo " ok " | |
| 104 | + | else | |
| 105 | + | echo " fail - expected $expected found $flag" | |
| 106 | + | ret=1 | |
| 107 | + | fi | |
| 108 | + | } | |
| 109 | + | ||
| 77 | 110 | chk_channels() { | |
| 78 | 111 | local msg="$1" | |
| 79 | 112 | local target=$2 | |
| @@ -222,6 +255,7 @@ fi | |||
| 222 | 255 | ||
| 223 | 256 | [ $CPUS -lt 2 ] && echo "Only one CPU available, some tests will be skipped" | |
| 224 | 257 | [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too" | |
| 258 | + | [ ! -f "$YNL" ] && echo "ynl cli not found, ndo-xmit tests will be skipped" | |
| 225 | 259 | ||
| 226 | 260 | create_ns | |
| 227 | 261 | chk_gro_flag "default - gro flag" $SRC off | |
| @@ -283,6 +317,18 @@ chk_gro_flag " - peer gro flag" $SRC off | |||
| 283 | 317 | chk_tso_flag " - tso flag" $SRC on | |
| 284 | 318 | chk_tso_flag " - peer tso flag" $DST on | |
| 285 | 319 | ip -n $NS_DST link set dev veth$DST up | |
| 320 | + | if [ -f "$YNL" ]; then | |
| 321 | + | chk_xdp_feature " - peer ndo-xmit" $SRC 1 ndo-xmit | |
| 322 | + | # make sure the peer flag is set before disabling gro while down | |
| 323 | + | ip netns exec $NS_DST ethtool -K veth$DST gro off | |
| 324 | + | ip netns exec $NS_DST ethtool -K veth$DST gro on | |
| 325 | + | chk_xdp_feature " - peer ndo-xmit re-armed" $SRC 1 ndo-xmit | |
| 326 | + | ip -n $NS_DST link set dev veth$DST down | |
| 327 | + | ip netns exec $NS_DST ethtool -K veth$DST gro off | |
| 328 | + | ip -n $NS_DST link set dev veth$DST up | |
| 329 | + | chk_xdp_feature " - peer ndo-xmit cleared" $SRC 0 ndo-xmit | |
| 330 | + | ip netns exec $NS_DST ethtool -K veth$DST gro on | |
| 331 | + | fi | |
| 286 | 332 | ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off | |
| 287 | 333 | ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on | |
| 288 | 334 | chk_gro " - aggregation with TSO off" 1 | |
modified tools/testing/selftests/sched_ext/Makefile
| @@ -165,6 +165,7 @@ auto-test-targets := \ | |||
| 165 | 165 | create_dsq \ | |
| 166 | 166 | dequeue \ | |
| 167 | 167 | dequeue_iter \ | |
| 168 | + | dequeue_remote \ | |
| 168 | 169 | enq_last_no_enq_fails \ | |
| 169 | 170 | ddsp_bogus_dsq_fail \ | |
| 170 | 171 | ddsp_vtimelocal_fail \ | |
added tools/testing/selftests/sched_ext/dequeue_remote.bpf.c mode 100644
| @@ -0,0 +1,270 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * Verify that ops.dequeue() is called when a task leaves the BPF scheduler's | |
| 4 | + | * custody by being moved to the local DSQ of a CPU other than the one whose | |
| 5 | + | * rq it's on (move_remote_task_to_local_dsq()). | |
| 6 | + | * | |
| 7 | + | * ops.enqueue() puts every task into custody and ops.dispatch() moves it to | |
| 8 | + | * the dispatching CPU's local DSQ, so most moves cross CPUs. With | |
| 9 | + | * @test_use_move_to_local, tasks are queued on a user DSQ and consumed with | |
| 10 | + | * scx_bpf_dsq_move_to_local(). Otherwise, they are queued in a BPF queue and | |
| 11 | + | * dispatched with SCX_DSQ_LOCAL_ON. | |
| 12 | + | * | |
| 13 | + | * Copyright (c) 2026 Google LLC. | |
| 14 | + | */ | |
| 15 | + | ||
| 16 | + | #include <scx/common.bpf.h> | |
| 17 | + | ||
| 18 | + | #define SHARED_DSQ 0 | |
| 19 | + | #define MAX_DISPATCH_POPS 8 | |
| 20 | + | ||
| 21 | + | char _license[] SEC("license") = "GPL"; | |
| 22 | + | ||
| 23 | + | UEI_DEFINE(uei); | |
| 24 | + | ||
| 25 | + | struct { | |
| 26 | + | __uint(type, BPF_MAP_TYPE_QUEUE); | |
| 27 | + | __uint(max_entries, 32768); | |
| 28 | + | __type(value, s32); | |
| 29 | + | } global_queue SEC(".maps"); | |
| 30 | + | ||
| 31 | + | enum task_state { | |
| 32 | + | TASK_NONE = 0, | |
| 33 | + | TASK_ENQUEUED, /* in BPF custody, waiting for ops.dequeue() */ | |
| 34 | + | TASK_DISPATCHED, /* left custody */ | |
| 35 | + | }; | |
| 36 | + | ||
| 37 | + | struct task_ctx { | |
| 38 | + | enum task_state state; | |
| 39 | + | s32 enq_cpu; /* scx_bpf_task_cpu() at ops.enqueue() */ | |
| 40 | + | u64 enqueue_seq; | |
| 41 | + | }; | |
| 42 | + | ||
| 43 | + | struct { | |
| 44 | + | __uint(type, BPF_MAP_TYPE_TASK_STORAGE); | |
| 45 | + | __uint(map_flags, BPF_F_NO_PREALLOC); | |
| 46 | + | __type(key, int); | |
| 47 | + | __type(value, struct task_ctx); | |
| 48 | + | } task_ctx_stor SEC(".maps"); | |
| 49 | + | ||
| 50 | + | /* core_cookie only exists with CONFIG_SCHED_CORE */ | |
| 51 | + | struct task_struct___core_sched { | |
| 52 | + | unsigned long core_cookie; | |
| 53 | + | } __attribute__((preserve_access_index)); | |
| 54 | + | ||
| 55 | + | bool test_use_move_to_local; | |
| 56 | + | ||
| 57 | + | u64 enqueue_cnt, dequeue_cnt, dispatch_dequeue_cnt, change_dequeue_cnt; | |
| 58 | + | u64 remote_dispatch_cnt, remote_running_cnt, missed_dequeue_cnt; | |
| 59 | + | u64 core_sched_exec_dequeue_cnt; | |
| 60 | + | ||
| 61 | + | static struct task_ctx *lookup_task_ctx(struct task_struct *p) | |
| 62 | + | { | |
| 63 | + | return bpf_task_storage_get(&task_ctx_stor, p, 0, 0); | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | static bool task_has_core_cookie(struct task_struct *p) | |
| 67 | + | { | |
| 68 | + | struct task_struct___core_sched *t = (void *)p; | |
| 69 | + | ||
| 70 | + | if (!bpf_core_field_exists(t->core_cookie)) | |
| 71 | + | return false; | |
| 72 | + | return BPF_CORE_READ(t, core_cookie); | |
| 73 | + | } | |
| 74 | + | ||
| 75 | + | s32 BPF_STRUCT_OPS(dequeue_remote_select_cpu, struct task_struct *p, | |
| 76 | + | s32 prev_cpu, u64 wake_flags) | |
| 77 | + | { | |
| 78 | + | /* no direct dispatch, always go through ops.enqueue() */ | |
| 79 | + | return prev_cpu; | |
| 80 | + | } | |
| 81 | + | ||
| 82 | + | void BPF_STRUCT_OPS(dequeue_remote_enqueue, struct task_struct *p, u64 enq_flags) | |
| 83 | + | { | |
| 84 | + | struct task_ctx *tctx; | |
| 85 | + | s32 pid = p->pid; | |
| 86 | + | ||
| 87 | + | tctx = lookup_task_ctx(p); | |
| 88 | + | if (!tctx) { | |
| 89 | + | scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); | |
| 90 | + | return; | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | /* the previous custody period must have ended with ops.dequeue() */ | |
| 94 | + | if (tctx->state == TASK_ENQUEUED) | |
| 95 | + | scx_bpf_error("%d (%s): enqueue while in ENQUEUED state seq=%llu", | |
| 96 | + | p->pid, p->comm, tctx->enqueue_seq); | |
| 97 | + | ||
| 98 | + | /* | |
| 99 | + | * Mark @p as enqueued before making it visible to ops.dispatch() on | |
| 100 | + | * other CPUs, which skips queue entries of tasks not in ENQUEUED | |
| 101 | + | * state as stale. | |
| 102 | + | */ | |
| 103 | + | tctx->state = TASK_ENQUEUED; | |
| 104 | + | tctx->enq_cpu = scx_bpf_task_cpu(p); | |
| 105 | + | tctx->enqueue_seq++; | |
| 106 | + | ||
| 107 | + | if (test_use_move_to_local) { | |
| 108 | + | scx_bpf_dsq_insert(p, SHARED_DSQ, SCX_SLICE_DFL, enq_flags); | |
| 109 | + | } else if (bpf_map_push_elem(&global_queue, &pid, 0)) { | |
| 110 | + | scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags); | |
| 111 | + | tctx->state = TASK_DISPATCHED; | |
| 112 | + | tctx->enq_cpu = -1; | |
| 113 | + | goto out; | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | __sync_fetch_and_add(&enqueue_cnt, 1); | |
| 117 | + | out: | |
| 118 | + | scx_bpf_kick_cpu(scx_bpf_task_cpu(p), SCX_KICK_IDLE); | |
| 119 | + | } | |
| 120 | + | ||
| 121 | + | void BPF_STRUCT_OPS(dequeue_remote_dequeue, struct task_struct *p, u64 deq_flags) | |
| 122 | + | { | |
| 123 | + | struct task_ctx *tctx; | |
| 124 | + | ||
| 125 | + | __sync_fetch_and_add(&dequeue_cnt, 1); | |
| 126 | + | ||
| 127 | + | tctx = lookup_task_ctx(p); | |
| 128 | + | if (!tctx) | |
| 129 | + | return; | |
| 130 | + | ||
| 131 | + | /* | |
| 132 | + | * Only core scheduling can pick a task straight out of custody, and | |
| 133 | + | * only if the task has a core cookie. Otherwise, the custody exit was | |
| 134 | + | * missed when @p was inserted into a local DSQ and got deferred until | |
| 135 | + | * @p was picked. | |
| 136 | + | */ | |
| 137 | + | if ((deq_flags & SCX_DEQ_CORE_SCHED_EXEC) && !task_has_core_cookie(p)) { | |
| 138 | + | __sync_fetch_and_add(&core_sched_exec_dequeue_cnt, 1); | |
| 139 | + | scx_bpf_error("%d (%s): late ops.dequeue() with SCX_DEQ_CORE_SCHED_EXEC (enq_cpu=%d cpu=%d seq=%llu)", | |
| 140 | + | p->pid, p->comm, tctx->enq_cpu, | |
| 141 | + | scx_bpf_task_cpu(p), tctx->enqueue_seq); | |
| 142 | + | } | |
| 143 | + | ||
| 144 | + | /* ops.dequeue() ends the custody period started by ops.enqueue() */ | |
| 145 | + | if (tctx->state != TASK_ENQUEUED) | |
| 146 | + | scx_bpf_error("%d (%s): dequeue outside custody deq_flags=0x%llx state=%d seq=%llu", | |
| 147 | + | p->pid, p->comm, deq_flags, tctx->state, | |
| 148 | + | tctx->enqueue_seq); | |
| 149 | + | ||
| 150 | + | if (deq_flags & SCX_DEQ_SCHED_CHANGE) { | |
| 151 | + | __sync_fetch_and_add(&change_dequeue_cnt, 1); | |
| 152 | + | tctx->state = TASK_NONE; | |
| 153 | + | } else { | |
| 154 | + | __sync_fetch_and_add(&dispatch_dequeue_cnt, 1); | |
| 155 | + | tctx->state = TASK_DISPATCHED; | |
| 156 | + | } | |
| 157 | + | } | |
| 158 | + | ||
| 159 | + | void BPF_STRUCT_OPS(dequeue_remote_dispatch, s32 cpu, struct task_struct *prev) | |
| 160 | + | { | |
| 161 | + | struct task_ctx *tctx; | |
| 162 | + | struct task_struct *p; | |
| 163 | + | s32 pid; | |
| 164 | + | int i; | |
| 165 | + | ||
| 166 | + | if (test_use_move_to_local) { | |
| 167 | + | scx_bpf_dsq_move_to_local(SHARED_DSQ, 0); | |
| 168 | + | return; | |
| 169 | + | } | |
| 170 | + | ||
| 171 | + | /* pop past stale entries so that they don't leave this CPU idle */ | |
| 172 | + | bpf_for(i, 0, MAX_DISPATCH_POPS) { | |
| 173 | + | if (bpf_map_pop_elem(&global_queue, &pid)) | |
| 174 | + | return; | |
| 175 | + | ||
| 176 | + | p = bpf_task_from_pid(pid); | |
| 177 | + | if (!p) | |
| 178 | + | continue; | |
| 179 | + | ||
| 180 | + | /* | |
| 181 | + | * Entries are stale if @p left custody through a property | |
| 182 | + | * change dequeue or was dispatched from a duplicate entry. | |
| 183 | + | */ | |
| 184 | + | tctx = lookup_task_ctx(p); | |
| 185 | + | if (!tctx || tctx->state != TASK_ENQUEUED) { | |
| 186 | + | bpf_task_release(p); | |
| 187 | + | continue; | |
| 188 | + | } | |
| 189 | + | ||
| 190 | + | if (bpf_cpumask_test_cpu(cpu, p->cpus_ptr)) { | |
| 191 | + | if (scx_bpf_task_cpu(p) != cpu) | |
| 192 | + | __sync_fetch_and_add(&remote_dispatch_cnt, 1); | |
| 193 | + | scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL_ON | cpu, | |
| 194 | + | SCX_SLICE_DFL, 0); | |
| 195 | + | } else { | |
| 196 | + | scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, 0); | |
| 197 | + | } | |
| 198 | + | ||
| 199 | + | bpf_task_release(p); | |
| 200 | + | return; | |
| 201 | + | } | |
| 202 | + | ||
| 203 | + | /* out of pops with entries left, retry instead of idling this CPU */ | |
| 204 | + | if (!bpf_map_peek_elem(&global_queue, &pid)) | |
| 205 | + | scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE); | |
| 206 | + | } | |
| 207 | + | ||
| 208 | + | void BPF_STRUCT_OPS(dequeue_remote_running, struct task_struct *p) | |
| 209 | + | { | |
| 210 | + | struct task_ctx *tctx; | |
| 211 | + | ||
| 212 | + | tctx = lookup_task_ctx(p); | |
| 213 | + | if (!tctx) | |
| 214 | + | return; | |
| 215 | + | ||
| 216 | + | /* tasks can only run from a local DSQ, i.e. after leaving custody */ | |
| 217 | + | if (tctx->state == TASK_ENQUEUED) { | |
| 218 | + | __sync_fetch_and_add(&missed_dequeue_cnt, 1); | |
| 219 | + | scx_bpf_error("%d (%s): running without ops.dequeue() (enq_cpu=%d cpu=%d seq=%llu)", | |
| 220 | + | p->pid, p->comm, tctx->enq_cpu, | |
| 221 | + | scx_bpf_task_cpu(p), tctx->enqueue_seq); | |
| 222 | + | return; | |
| 223 | + | } | |
| 224 | + | ||
| 225 | + | if (tctx->enq_cpu >= 0 && tctx->enq_cpu != scx_bpf_task_cpu(p)) | |
| 226 | + | __sync_fetch_and_add(&remote_running_cnt, 1); | |
| 227 | + | tctx->enq_cpu = -1; | |
| 228 | + | } | |
| 229 | + | ||
| 230 | + | s32 BPF_STRUCT_OPS(dequeue_remote_init_task, struct task_struct *p, | |
| 231 | + | struct scx_init_task_args *args) | |
| 232 | + | { | |
| 233 | + | struct task_ctx *tctx; | |
| 234 | + | ||
| 235 | + | tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, | |
| 236 | + | BPF_LOCAL_STORAGE_GET_F_CREATE); | |
| 237 | + | if (!tctx) | |
| 238 | + | return -ENOMEM; | |
| 239 | + | ||
| 240 | + | /* task storage persists across attachments, start from scratch */ | |
| 241 | + | tctx->state = TASK_NONE; | |
| 242 | + | tctx->enq_cpu = -1; | |
| 243 | + | tctx->enqueue_seq = 0; | |
| 244 | + | ||
| 245 | + | return 0; | |
| 246 | + | } | |
| 247 | + | ||
| 248 | + | s32 BPF_STRUCT_OPS_SLEEPABLE(dequeue_remote_init) | |
| 249 | + | { | |
| 250 | + | return scx_bpf_create_dsq(SHARED_DSQ, -1); | |
| 251 | + | } | |
| 252 | + | ||
| 253 | + | void BPF_STRUCT_OPS(dequeue_remote_exit, struct scx_exit_info *ei) | |
| 254 | + | { | |
| 255 | + | UEI_RECORD(uei, ei); | |
| 256 | + | } | |
| 257 | + | ||
| 258 | + | SEC(".struct_ops.link") | |
| 259 | + | struct sched_ext_ops dequeue_remote_ops = { | |
| 260 | + | .select_cpu = (void *)dequeue_remote_select_cpu, | |
| 261 | + | .enqueue = (void *)dequeue_remote_enqueue, | |
| 262 | + | .dequeue = (void *)dequeue_remote_dequeue, | |
| 263 | + | .dispatch = (void *)dequeue_remote_dispatch, | |
| 264 | + | .running = (void *)dequeue_remote_running, | |
| 265 | + | .init_task = (void *)dequeue_remote_init_task, | |
| 266 | + | .init = (void *)dequeue_remote_init, | |
| 267 | + | .exit = (void *)dequeue_remote_exit, | |
| 268 | + | .flags = SCX_OPS_ENQ_LAST, | |
| 269 | + | .name = "dequeue_remote", | |
| 270 | + | }; | |
added tools/testing/selftests/sched_ext/dequeue_remote.c mode 100644
| @@ -0,0 +1,204 @@ | |||
| 1 | + | // SPDX-License-Identifier: GPL-2.0 | |
| 2 | + | /* | |
| 3 | + | * Verify that ops.dequeue() is called for tasks leaving BPF custody through | |
| 4 | + | * an SCX-internal cross-CPU migration (move_remote_task_to_local_dsq()). | |
| 5 | + | * | |
| 6 | + | * Copyright (c) 2026 Google LLC. | |
| 7 | + | */ | |
| 8 | + | #define _GNU_SOURCE | |
| 9 | + | #include <stdio.h> | |
| 10 | + | #include <stdlib.h> | |
| 11 | + | #include <string.h> | |
| 12 | + | #include <unistd.h> | |
| 13 | + | #include <signal.h> | |
| 14 | + | #include <time.h> | |
| 15 | + | #include <sched.h> | |
| 16 | + | #include <bpf/bpf.h> | |
| 17 | + | #include <scx/common.h> | |
| 18 | + | #include <sys/wait.h> | |
| 19 | + | #include "scx_test.h" | |
| 20 | + | #include "dequeue_remote.bpf.skel.h" | |
| 21 | + | ||
| 22 | + | #define MAX_WORKERS 64 | |
| 23 | + | #define RUN_MS 2000 | |
| 24 | + | ||
| 25 | + | static int nr_cpus; | |
| 26 | + | ||
| 27 | + | static long long now_ms(void) | |
| 28 | + | { | |
| 29 | + | struct timespec ts; | |
| 30 | + | ||
| 31 | + | clock_gettime(CLOCK_MONOTONIC, &ts); | |
| 32 | + | return ts.tv_sec * 1000LL + ts.tv_nsec / 1000000; | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | /* mix of short bursts and sleeps to generate lots of enqueues and wakeups */ | |
| 36 | + | static void worker_fn(int id) | |
| 37 | + | { | |
| 38 | + | long long end = now_ms() + RUN_MS; | |
| 39 | + | volatile unsigned long sum = 0; | |
| 40 | + | ||
| 41 | + | while (now_ms() < end) { | |
| 42 | + | unsigned long j; | |
| 43 | + | ||
| 44 | + | for (j = 0; j < 20000 + id * 1000; j++) | |
| 45 | + | sum += j; | |
| 46 | + | if (id & 1) | |
| 47 | + | usleep(100); | |
| 48 | + | else | |
| 49 | + | sched_yield(); | |
| 50 | + | } | |
| 51 | + | ||
| 52 | + | exit(0); | |
| 53 | + | } | |
| 54 | + | ||
| 55 | + | static enum scx_test_status run_scenario(struct dequeue_remote *skel, | |
| 56 | + | bool use_move_to_local, | |
| 57 | + | const char *name) | |
| 58 | + | { | |
| 59 | + | enum scx_test_status ret = SCX_TEST_PASS; | |
| 60 | + | struct bpf_link *link; | |
| 61 | + | pid_t pids[MAX_WORKERS]; | |
| 62 | + | int nr_workers, nr_forked, i; | |
| 63 | + | ||
| 64 | + | nr_workers = 2 * nr_cpus; | |
| 65 | + | if (nr_workers < 4) | |
| 66 | + | nr_workers = 4; | |
| 67 | + | if (nr_workers > MAX_WORKERS) | |
| 68 | + | nr_workers = MAX_WORKERS; | |
| 69 | + | ||
| 70 | + | skel->bss->test_use_move_to_local = use_move_to_local; | |
| 71 | + | skel->bss->enqueue_cnt = 0; | |
| 72 | + | skel->bss->dequeue_cnt = 0; | |
| 73 | + | skel->bss->dispatch_dequeue_cnt = 0; | |
| 74 | + | skel->bss->change_dequeue_cnt = 0; | |
| 75 | + | skel->bss->remote_dispatch_cnt = 0; | |
| 76 | + | skel->bss->remote_running_cnt = 0; | |
| 77 | + | skel->bss->missed_dequeue_cnt = 0; | |
| 78 | + | skel->bss->core_sched_exec_dequeue_cnt = 0; | |
| 79 | + | memset(&skel->data->uei, 0, sizeof(skel->data->uei)); | |
| 80 | + | ||
| 81 | + | link = bpf_map__attach_struct_ops(skel->maps.dequeue_remote_ops); | |
| 82 | + | SCX_FAIL_IF(!link, "Failed to attach struct_ops for %s", name); | |
| 83 | + | ||
| 84 | + | fflush(stdout); | |
| 85 | + | fflush(stderr); | |
| 86 | + | ||
| 87 | + | for (nr_forked = 0; nr_forked < nr_workers; nr_forked++) { | |
| 88 | + | pid_t pid = fork(); | |
| 89 | + | ||
| 90 | + | if (pid < 0) { | |
| 91 | + | SCX_ERR("Failed to fork worker %d", nr_forked); | |
| 92 | + | ret = SCX_TEST_FAIL; | |
| 93 | + | break; | |
| 94 | + | } | |
| 95 | + | if (pid == 0) | |
| 96 | + | worker_fn(nr_forked); | |
| 97 | + | pids[nr_forked] = pid; | |
| 98 | + | } | |
| 99 | + | ||
| 100 | + | /* on failure, kill the remaining workers but still reap them */ | |
| 101 | + | for (i = 0; i < nr_forked; i++) { | |
| 102 | + | int status; | |
| 103 | + | ||
| 104 | + | if (ret != SCX_TEST_PASS) | |
| 105 | + | kill(pids[i], SIGKILL); | |
| 106 | + | ||
| 107 | + | if (waitpid(pids[i], &status, 0) != pids[i]) { | |
| 108 | + | SCX_ERR("Failed to wait for worker %d", i); | |
| 109 | + | ret = SCX_TEST_FAIL; | |
| 110 | + | } else if (ret == SCX_TEST_PASS && status != 0) { | |
| 111 | + | SCX_ERR("Worker %d exited with status %d", i, status); | |
| 112 | + | ret = SCX_TEST_FAIL; | |
| 113 | + | } | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | bpf_link__destroy(link); | |
| 117 | + | ||
| 118 | + | if (ret != SCX_TEST_PASS) | |
| 119 | + | return ret; | |
| 120 | + | ||
| 121 | + | printf("%s:\n", name); | |
| 122 | + | printf(" workers: %d\n", nr_workers); | |
| 123 | + | printf(" enqueues: %lu\n", (unsigned long)skel->bss->enqueue_cnt); | |
| 124 | + | printf(" dequeues: %lu (dispatch: %lu, property_change: %lu)\n", | |
| 125 | + | (unsigned long)skel->bss->dequeue_cnt, | |
| 126 | + | (unsigned long)skel->bss->dispatch_dequeue_cnt, | |
| 127 | + | (unsigned long)skel->bss->change_dequeue_cnt); | |
| 128 | + | if (!use_move_to_local) | |
| 129 | + | printf(" remote SCX_DSQ_LOCAL_ON dispatches: %lu\n", | |
| 130 | + | (unsigned long)skel->bss->remote_dispatch_cnt); | |
| 131 | + | printf(" ran on a CPU other than the enqueue CPU: %lu\n", | |
| 132 | + | (unsigned long)skel->bss->remote_running_cnt); | |
| 133 | + | printf(" ran without ops.dequeue(): %lu\n", | |
| 134 | + | (unsigned long)skel->bss->missed_dequeue_cnt); | |
| 135 | + | printf(" late SCX_DEQ_CORE_SCHED_EXEC dequeues: %lu\n", | |
| 136 | + | (unsigned long)skel->bss->core_sched_exec_dequeue_cnt); | |
| 137 | + | ||
| 138 | + | if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_UNREG)) | |
| 139 | + | SCX_ERR("Scheduler exited with kind=%lld: %s", | |
| 140 | + | (long long)skel->data->uei.kind, skel->data->uei.msg); | |
| 141 | + | SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG)); | |
| 142 | + | ||
| 143 | + | /* the test is meaningless if no task was moved across CPUs */ | |
| 144 | + | SCX_GT(skel->bss->remote_running_cnt, 0); | |
| 145 | + | SCX_EQ(skel->bss->enqueue_cnt, skel->bss->dequeue_cnt); | |
| 146 | + | ||
| 147 | + | return SCX_TEST_PASS; | |
| 148 | + | } | |
| 149 | + | ||
| 150 | + | static enum scx_test_status setup(void **ctx) | |
| 151 | + | { | |
| 152 | + | struct dequeue_remote *skel; | |
| 153 | + | cpu_set_t cpus; | |
| 154 | + | ||
| 155 | + | SCX_FAIL_IF(sched_getaffinity(0, sizeof(cpus), &cpus), | |
| 156 | + | "Failed to get CPU affinity"); | |
| 157 | + | nr_cpus = CPU_COUNT(&cpus); | |
| 158 | + | if (nr_cpus < 2) { | |
| 159 | + | fprintf(stderr, "Skipping: requires at least 2 usable CPUs\n"); | |
| 160 | + | return SCX_TEST_SKIP; | |
| 161 | + | } | |
| 162 | + | ||
| 163 | + | skel = SCX_OPS_OPEN(dequeue_remote_ops, dequeue_remote); | |
| 164 | + | SCX_OPS_LOAD(skel, dequeue_remote_ops, dequeue_remote, uei); | |
| 165 | + | ||
| 166 | + | *ctx = skel; | |
| 167 | + | ||
| 168 | + | return SCX_TEST_PASS; | |
| 169 | + | } | |
| 170 | + | ||
| 171 | + | static enum scx_test_status run(void *ctx) | |
| 172 | + | { | |
| 173 | + | struct dequeue_remote *skel = ctx; | |
| 174 | + | enum scx_test_status status; | |
| 175 | + | ||
| 176 | + | status = run_scenario(skel, false, | |
| 177 | + | "BPF queue -> SCX_DSQ_LOCAL_ON | cpu"); | |
| 178 | + | if (status != SCX_TEST_PASS) | |
| 179 | + | return status; | |
| 180 | + | ||
| 181 | + | status = run_scenario(skel, true, | |
| 182 | + | "user DSQ -> scx_bpf_dsq_move_to_local()"); | |
| 183 | + | if (status != SCX_TEST_PASS) | |
| 184 | + | return status; | |
| 185 | + | ||
| 186 | + | return SCX_TEST_PASS; | |
| 187 | + | } | |
| 188 | + | ||
| 189 | + | static void cleanup(void *ctx) | |
| 190 | + | { | |
| 191 | + | struct dequeue_remote *skel = ctx; | |
| 192 | + | ||
| 193 | + | dequeue_remote__destroy(skel); | |
| 194 | + | } | |
| 195 | + | ||
| 196 | + | struct scx_test dequeue_remote_test = { | |
| 197 | + | .name = "dequeue_remote", | |
| 198 | + | .description = "Verify ops.dequeue() on SCX-internal cross-CPU migrations", | |
| 199 | + | .setup = setup, | |
| 200 | + | .run = run, | |
| 201 | + | .cleanup = cleanup, | |
| 202 | + | }; | |
| 203 | + | ||
| 204 | + | REGISTER_SCX_TEST(&dequeue_remote_test) | |
modified tools/testing/selftests/tc-testing/tc-tests/filters/route.json
| @@ -412,5 +412,51 @@ | |||
| 412 | 412 | "teardown": [ | |
| 413 | 413 | "$TC qdisc del dev $DEV1 ingress" | |
| 414 | 414 | ] | |
| 415 | + | }, | |
| 416 | + | { | |
| 417 | + | "id": "4000", | |
| 418 | + | "name": "Change a wildcard route filter classid only (no routing attribute)", | |
| 419 | + | "category": [ | |
| 420 | + | "filter", | |
| 421 | + | "route" | |
| 422 | + | ], | |
| 423 | + | "plugins": { | |
| 424 | + | "requires": "nsPlugin" | |
| 425 | + | }, | |
| 426 | + | "setup": [ | |
| 427 | + | "$TC qdisc add dev $DEV1 ingress", | |
| 428 | + | "$TC filter add dev $DEV1 parent ffff: protocol ip prio 100 route classid 1:1" | |
| 429 | + | ], | |
| 430 | + | "cmdUnderTest": "$TC filter change dev $DEV1 parent ffff: protocol ip prio 100 route classid 1:9", | |
| 431 | + | "expExitCode": "0", | |
| 432 | + | "verifyCmd": "$TC filter ls dev $DEV1 parent ffff:", | |
| 433 | + | "matchPattern": "fh 0xffff8000 flowid 1:9", | |
| 434 | + | "matchCount": "1", | |
| 435 | + | "teardown": [ | |
| 436 | + | "$TC qdisc del dev $DEV1 ingress" | |
| 437 | + | ] | |
| 438 | + | }, | |
| 439 | + | { | |
| 440 | + | "id": "907a", | |
| 441 | + | "name": "Try to change a route filter with no routing attribute and a non-wildcard handle", | |
| 442 | + | "category": [ | |
| 443 | + | "filter", | |
| 444 | + | "route" | |
| 445 | + | ], | |
| 446 | + | "plugins": { | |
| 447 | + | "requires": "nsPlugin" | |
| 448 | + | }, | |
| 449 | + | "setup": [ | |
| 450 | + | "$TC qdisc add dev $DEV1 ingress", | |
| 451 | + | "$TC filter add dev $DEV1 parent ffff: protocol ip prio 100 route from 1 to 1 classid 1:1" | |
| 452 | + | ], | |
| 453 | + | "cmdUnderTest": "$TC filter change dev $DEV1 parent ffff: protocol ip prio 100 handle 0x10001 route classid 1:2", | |
| 454 | + | "expExitCode": "2", | |
| 455 | + | "verifyCmd": "$TC filter ls dev $DEV1 parent ffff:", | |
| 456 | + | "matchPattern": "fh 0x00010001 flowid 1:1 to 1 from 1", | |
| 457 | + | "matchCount": "1", | |
| 458 | + | "teardown": [ | |
| 459 | + | "$TC qdisc del dev $DEV1 ingress" | |
| 460 | + | ] | |
| 415 | 461 | } | |
| 416 | 462 | ] | |
modified tools/testing/vma/tests/vma.c
| @@ -40,7 +40,7 @@ static bool test_copy_vma(void) | |||
| 40 | 40 | vma = alloc_and_link_vma(&mm, 0x1000, 0x2000, 1, vma_flags); | |
| 41 | 41 | vma_set_anonymous(vma); | |
| 42 | 42 | vma_orig = vma; | |
| 43 | - | vma_new = copy_vma(&vma, 0x2000, 0x1000, 1, 1, &need_locks); | |
| 43 | + | vma_new = copy_vma(&vma, 0x2000, 0x1000, 1, 1, &need_locks, false); | |
| 44 | 44 | ASSERT_EQ(vma_new, vma_orig); | |
| 45 | 45 | ASSERT_EQ(vma, vma_orig); | |
| 46 | 46 | ASSERT_EQ(vma_new->vm_start, 0x1000); | |
| @@ -53,7 +53,7 @@ static bool test_copy_vma(void) | |||
| 53 | 53 | vma = alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, vma_flags); | |
| 54 | 54 | vma_set_anonymous(vma); | |
| 55 | 55 | vma_orig = vma; | |
| 56 | - | vma_new = copy_vma(&vma, 0x1000, 0x1000, 2, 2, &need_locks); | |
| 56 | + | vma_new = copy_vma(&vma, 0x1000, 0x1000, 2, 2, &need_locks, false); | |
| 57 | 57 | ASSERT_EQ(vma_new, vma_orig); | |
| 58 | 58 | ASSERT_EQ(vma, vma_orig); | |
| 59 | 59 | ASSERT_EQ(vma_new->vm_start, 0x1000); | |
| @@ -71,7 +71,7 @@ static bool test_copy_vma(void) | |||
| 71 | 71 | vma = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, vma_flags); | |
| 72 | 72 | vma_set_anonymous(vma); | |
| 73 | 73 | vma_orig = vma; | |
| 74 | - | vma_new = copy_vma(&vma, 0x2000, 0x1000, 3, 3, &need_locks); | |
| 74 | + | vma_new = copy_vma(&vma, 0x2000, 0x1000, 3, 3, &need_locks, false); | |
| 75 | 75 | ASSERT_NE(vma_new, vma_orig); | |
| 76 | 76 | ASSERT_EQ(vma_new, vma); | |
| 77 | 77 | ASSERT_EQ(vma_new->vm_start, 0x1000); | |
| @@ -82,7 +82,7 @@ static bool test_copy_vma(void) | |||
| 82 | 82 | /* Move backwards and do not merge. */ | |
| 83 | 83 | ||
| 84 | 84 | vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, vma_flags); | |
| 85 | - | vma_new = copy_vma(&vma, 0, 0x2000, 0, 3, &need_locks); | |
| 85 | + | vma_new = copy_vma(&vma, 0, 0x2000, 0, 3, &need_locks, false); | |
| 86 | 86 | ASSERT_NE(vma_new, vma); | |
| 87 | 87 | ASSERT_EQ(vma_new->vm_start, 0); | |
| 88 | 88 | ASSERT_EQ(vma_new->vm_end, 0x2000); | |
| @@ -95,7 +95,7 @@ static bool test_copy_vma(void) | |||
| 95 | 95 | ||
| 96 | 96 | vma = alloc_and_link_vma(&mm, 0, 0x2000, 0, vma_flags); | |
| 97 | 97 | vma_next = alloc_and_link_vma(&mm, 0x6000, 0x8000, 6, vma_flags); | |
| 98 | - | vma_new = copy_vma(&vma, 0x4000, 0x2000, 4, 4, &need_locks); | |
| 98 | + | vma_new = copy_vma(&vma, 0x4000, 0x2000, 4, 4, &need_locks, false); | |
| 99 | 99 | vma_assert_attached(vma_new); | |
| 100 | 100 | ||
| 101 | 101 | ASSERT_EQ(vma_new, vma_next); | |