-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmcuLG4ACgkQONu9yGCS aT7BrA/+NGLfwp3lfOunHEhrw/IwD/tbMJuAOn5P2rvrg3f2aCVjboJpHh0pwL6O Axt4uEmJOo7++8mEo9cCBdLPSv5lQPK+j1uIXjKfdISODJYVqLf6g7GGHSdq/Ijj BCSW24P+Kl+XK0NHiyzlS2+XFP+Xk6T5yErV0cBwt6KFotYWjaAlpwDlCGHtvdra RROVwCQWVxGrCDLPEYeQIP3cD1fp/A3Q/d3quJLK1xo6SXAFBZjlYcOvl76i4ogj 6ZZPBdIusk24pjpnhaIwmlzbmfqWbp5T2uJHJGaXNfSioIKSs1CdKP9zsOnGxoDl Iv3c65O/IZbLz/77z1yKDPWn9lQ1uu0sr15Bq6G720HOvk1reKbBwP+XeWNnl8PF RLdDxVAYqIFxfMsWGHgc7NzToRH/Z2AkqmTcm+uYHh+u9z4gXbVKXcgOX/EBFKKL rlVjwOsTzPm2NV81EP4bDKNag+3D6yoYn1zJV6Qdu7j/Wsn69OjFEuMIVeXf1olv BGGdTwleHgA8ml18xZkoCun3J9NORhaCgdfz979fwSdxBBpGHxDcklWZtQMJxfgl UpD0huZWoD3mjIx557N9Rxh270L7ETQMSLd3B6Bu2qy6Gd9V4Ik0R33nEEiodPfU bxmZ3r/Fzqs8Zzc3V/NrKCgxopf/yLcdXfOJCpNyL9oXaxCH8oQ= =W8Y0 -----END PGP SIGNATURE----- Merge 5.4.285 into android11-5.4-lts Changes in 5.4.285 usbnet: ipheth: fix carrier detection in modes 1 and 4 net: ethernet: use ip_hdrlen() instead of bit shift net: phy: vitesse: repair vsc73xx autonegotiation scripts: kconfig: merge_config: config files: add a trailing newline arm64: dts: rockchip: override BIOS_DISABLE signal via GPIO hog on RK3399 Puma ice: fix accounting for filters shared by multiple VSIs net/mlx5e: Add missing link modes to ptys2ethtool_map net: ftgmac100: Enable TX interrupt to avoid TX timeout net: dpaa: Pad packets to ETH_ZLEN spi: nxp-fspi: fix the KASAN report out-of-bounds bug soundwire: stream: Revert "soundwire: stream: fix programming slave ports for non-continous port maps" selftests: breakpoints: Fix a typo of function name ASoC: allow module autoloading for table db1200_pids ALSA: hda/realtek - Fixed ALC256 headphone no sound ALSA: hda/realtek - FIxed ALC285 headphone no sound pinctrl: at91: make it work with current gpiolib microblaze: don't treat zero reserved memory regions as error net: ftgmac100: Ensure tx descriptor updates are visible wifi: iwlwifi: mvm: fix iwl_mvm_max_scan_ie_fw_cmd_room() wifi: iwlwifi: mvm: don't wait for tx queues if firmware is dead ASoC: tda7419: fix module autoloading drm: komeda: Fix an issue related to normalized zpos spi: bcm63xx: Enable module autoloading x86/hyperv: Set X86_FEATURE_TSC_KNOWN_FREQ when Hyper-V provides frequency ocfs2: add bounds checking to ocfs2_xattr_find_entry() ocfs2: strict bound check before memcmp in ocfs2_xattr_find_entry() gpio: prevent potential speculation leaks in gpio_device_get_desc() inet: inet_defrag: prevent sk release while still in use bpf: Fix DEVMAP_HASH overflow check on 32-bit arches USB: serial: pl2303: add device id for Macrosilicon MS3020 USB: usbtmc: prevent kernel-usb-infoleak ACPI: PMIC: Remove unneeded check in tps68470_pmic_opregion_probe() wifi: ath9k: fix parameter check in ath9k_init_debug() wifi: ath9k: Remove error checks when creating debugfs entries fs: explicitly unregister per-superblock BDIs mount: warn only once about timestamp range expiration fs/namespace: fnic: Switch to use %ptTd mount: handle OOM on mnt_warn_timestamp_expiry can: j1939: use correct function name in comment netfilter: nf_tables: elements with timeout below CONFIG_HZ never expire netfilter: nf_tables: reject element expiration with no timeout netfilter: nf_tables: reject expiration higher than timeout wifi: cfg80211: fix UBSAN noise in cfg80211_wext_siwscan() wifi: cfg80211: fix two more possible UBSAN-detected off-by-one errors mac80211: parse radiotap header when selecting Tx queue wifi: mac80211: use two-phase skb reclamation in ieee80211_do_stop() wifi: wilc1000: fix potential RCU dereference issue in wilc_parse_join_bss_param sock_map: Add a cond_resched() in sock_hash_free() can: bcm: Clear bo->bcm_proc_read after remove_proc_entry(). Bluetooth: btusb: Fix not handling ZPL/short-transfer net: tipc: avoid possible garbage value block, bfq: fix possible UAF for bfqq->bic with merge chain block, bfq: choose the last bfqq from merge chain in bfq_setup_cooperator() block, bfq: don't break merge chain in bfq_split_bfqq() spi: ppc4xx: handle irq_of_parse_and_map() errors spi: ppc4xx: Avoid returning 0 when failed to parse and map IRQ ARM: dts: imx7d-zii-rmu2: fix Ethernet PHY pinctrl property ARM: versatile: fix OF node leak in CPUs prepare reset: berlin: fix OF node leak in probe() error path clocksource/drivers/qcom: Add missing iounmap() on errors in msm_dt_timer_init() hwmon: (max16065) Fix overflows seen when writing limits mtd: slram: insert break after errors in parsing the map hwmon: (ntc_thermistor) fix module autoloading power: supply: axp20x_battery: allow disabling battery charging power: supply: axp20x_battery: Remove design from min and max voltage power: supply: max17042_battery: Fix SOC threshold calc w/ no current sense fbdev: hpfb: Fix an error handling path in hpfb_dio_probe() mtd: powernv: Add check devm_kasprintf() returned value drm/stm: Fix an error handling path in stm_drm_platform_probe() drm/amdgpu: Replace one-element array with flexible-array member drm/amdgpu: properly handle vbios fake edid sizing drm/radeon: Replace one-element array with flexible-array member drm/radeon: properly handle vbios fake edid sizing drm/rockchip: vop: Allow 4096px width scaling drm/rockchip: dw_hdmi: Fix reading EDID when using a forced mode drm/radeon/evergreen_cs: fix int overflow errors in cs track offsets jfs: fix out-of-bounds in dbNextAG() and diAlloc() drm/msm: Fix incorrect file name output in adreno_request_fw() drm/msm/a5xx: disable preemption in submits by default drm/msm/a5xx: properly clear preemption records on resume drm/msm/a5xx: fix races in preemption evaluation stage ipmi: docs: don't advertise deprecated sysfs entries drm/msm: fix %s null argument error drivers:drm:exynos_drm_gsc:Fix wrong assignment in gsc_bind() xen: use correct end address of kernel for conflict checking xen/swiotlb: add alignment check for dma buffers tpm: Clean up TPM space after command failure selftests/bpf: Fix compile error from rlim_t in sk_storage_map.c selftests/bpf: Fix compiling flow_dissector.c with musl-libc selftests/bpf: Fix compiling tcp_rtt.c with musl-libc selftests/bpf: Fix error compiling test_lru_map.c xz: cleanup CRC32 edits from 2018 kthread: add kthread_work tracepoints kthread: fix task state in kthread worker if being frozen jbd2: introduce/export functions jbd2_journal_submit|finish_inode_data_buffers() ext4: clear EXT4_GROUP_INFO_WAS_TRIMMED_BIT even mount with discard smackfs: Use rcu_assign_pointer() to ensure safe assignment in smk_set_cipso ext4: avoid negative min_clusters in find_group_orlov() ext4: return error on ext4_find_inline_entry ext4: avoid OOB when system.data xattr changes underneath the filesystem nilfs2: fix potential null-ptr-deref in nilfs_btree_insert() nilfs2: determine empty node blocks as corrupted nilfs2: fix potential oob read in nilfs_btree_check_delete() bpf: Fix bpf_strtol and bpf_strtoul helpers for 32bit perf sched timehist: Fix missing free of session in perf_sched__timehist() perf sched timehist: Fixed timestamp error when unable to confirm event sched_in time perf time-utils: Fix 32-bit nsec parsing clk: rockchip: Set parent rate for DCLK_VOP clock on RK3228 drivers: media: dvb-frontends/rtl2832: fix an out-of-bounds write error drivers: media: dvb-frontends/rtl2830: fix an out-of-bounds write error PCI: keystone: Fix if-statement expression in ks_pcie_quirk() PCI: xilinx-nwl: Fix register misspelling RDMA/iwcm: Fix WARNING:at_kernel/workqueue.c:#check_flush_dependency pinctrl: single: fix missing error code in pcs_probe() clk: ti: dra7-atl: Fix leak of of_nodes pinctrl: mvebu: Fix devinit_dove_pinctrl_probe function watchdog: imx_sc_wdt: Don't disable WDT in suspend RDMA/hns: Optimize hem allocation performance riscv: Fix fp alignment bug in perf_callchain_user() RDMA/cxgb4: Added NULL check for lookup_atid ntb: intel: Fix the NULL vs IS_ERR() bug for debugfs_create_dir() nfsd: call cache_put if xdr_reserve_space returns NULL nfsd: return -EINVAL when namelen is 0 f2fs: enhance to update i_mode and acl atomically in f2fs_setattr() f2fs: fix typo f2fs: fix to update i_ctime in __f2fs_setxattr() f2fs: remove unneeded check condition in __f2fs_setxattr() f2fs: reduce expensive checkpoint trigger frequency iio: adc: ad7606: fix oversampling gpio array iio: adc: ad7606: fix standby gpio state to match the documentation coresight: tmc: sg: Do not leak sg_table netfilter: nf_reject_ipv6: fix nf_reject_ip6_tcphdr_put() net: seeq: Fix use after free vulnerability in ether3 Driver Due to Race Condition tcp: check skb is non-NULL in tcp_rto_delta_us() net: qrtr: Update packets cloning when broadcasting netfilter: ctnetlink: compile ctnetlink_label_size with CONFIG_NF_CONNTRACK_EVENTS crypto: aead,cipher - zeroize key buffer after use Remove *.orig pattern from .gitignore soc: versatile: integrator: fix OF node leak in probe() error path drm/amd/display: Round calculated vtotal USB: appledisplay: close race between probe and completion handler USB: misc: cypress_cy7c63: check for short transfer USB: class: CDC-ACM: fix race between get_serial and set_serial firmware_loader: Block path traversal tty: rp2: Fix reset with non forgiving PCIe host bridges drbd: Fix atomicity violation in drbd_uuid_set_bm() drbd: Add NULL check for net_conf to prevent dereference in state validation ACPI: sysfs: validate return type of _STR method ACPI: resource: Add another DMI match for the TongFang GMxXGxx wifi: rtw88: 8822c: Fix reported RX band width debugobjects: Fix conditions in fill_pool() f2fs: prevent possible int overflow in dir_block_index() f2fs: avoid potential int overflow in sanity_check_area_boundary() hwrng: mtk - Use devm_pm_runtime_enable vfs: fix race between evice_inodes() and find_inode()&iput() fs: Fix file_set_fowner LSM hook inconsistencies nfs: fix memory leak in error path of nfs4_do_reclaim ASoC: meson: axg: extract sound card utils ASoC: meson: axg-card: fix 'use-after-free' PCI: xilinx-nwl: Use irq_data_get_irq_chip_data() PCI: xilinx-nwl: Fix off-by-one in INTx IRQ handler soc: versatile: realview: fix memory leak during device remove soc: versatile: realview: fix soc_dev leak during device remove usb: yurex: Replace snprintf() with the safer scnprintf() variant USB: misc: yurex: fix race between read and write pps: remove usage of the deprecated ida_simple_xx() API pps: add an error check in parport_attach mm: only enforce minimum stack gap size if it's sensible i2c: aspeed: Update the stop sw state when the bus recovery occurs i2c: isch: Add missed 'else' usb: yurex: Fix inconsistent locking bug in yurex_read() mailbox: rockchip: fix a typo in module autoloading mailbox: bcm2835: Fix timeout during suspend mode ceph: remove the incorrect Fw reference check when dirtying pages Minor fixes to the CAIF Transport drivers Kconfig file drivers: net: Fix Kconfig indentation, continued ieee802154: Fix build error net/mlx5: Added cond_resched() to crdump collection netfilter: uapi: NFTA_FLOWTABLE_HOOK is NLA_NESTED net: ieee802154: mcr20a: Use IRQF_NO_AUTOEN flag in request_irq() netfilter: nf_tables: prevent nf_skb_duplicated corruption Bluetooth: btmrvl_sdio: Refactor irq wakeup Bluetooth: btmrvl: Use IRQF_NO_AUTOEN flag in request_irq() net: ethernet: lantiq_etop: fix memory disclosure net: avoid potential underflow in qdisc_pkt_len_init() with UFO net: add more sanity checks to qdisc_pkt_len_init() ipv4: ip_gre: Fix drops of small packets in ipgre_xmit sctp: set sk_state back to CLOSED if autobind fails in sctp_listen_start ALSA: hda/realtek: Fix the push button function for the ALC257 ALSA: hda/generic: Unconditionally prefer preferred_dacs pairs ALSA: hda/conexant: Fix conflicting quirk for System76 Pangolin f2fs: Require FMODE_WRITE for atomic write ioctls wifi: ath9k: fix possible integer overflow in ath9k_get_et_stats() wifi: ath9k_htc: Use __skb_set_length() for resetting urb before resubmit ice: Adjust over allocation of memory in ice_sched_add_root_node() and ice_sched_add_node() net: hisilicon: hip04: fix OF node leak in probe() net: hisilicon: hns_dsaf_mac: fix OF node leak in hns_mac_get_info() net: hisilicon: hns_mdio: fix OF node leak in probe() ACPICA: Fix memory leak if acpi_ps_get_next_namepath() fails ACPICA: Fix memory leak if acpi_ps_get_next_field() fails net: sched: consistently use rcu_replace_pointer() in taprio_change() wifi: rtw88: select WANT_DEV_COREDUMP ACPI: EC: Do not release locks during operation region accesses ACPICA: check null return of ACPI_ALLOCATE_ZEROED() in acpi_db_convert_to_package() tipc: guard against string buffer overrun net: mvpp2: Increase size of queue_name buffer ipv4: Check !in_dev earlier for ioctl(SIOCSIFADDR). ipv4: Mask upper DSCP bits and ECN bits in NETLINK_FIB_LOOKUP family tcp: avoid reusing FIN_WAIT2 when trying to find port in connect() process ACPICA: iasl: handle empty connection_node proc: add config & param to block forcing mem writes wifi: mwifiex: Fix memcpy() field-spanning write warning in mwifiex_cmd_802_11_scan_ext() nfp: Use IRQF_NO_AUTOEN flag in request_irq() signal: Replace BUG_ON()s ALSA: asihpi: Fix potential OOB array access ALSA: hdsp: Break infinite MIDI input flush loop x86/syscall: Avoid memcpy() for ia32 syscall_get_arguments() fbdev: pxafb: Fix possible use after free in pxafb_task() power: reset: brcmstb: Do not go into infinite loop if reset fails ata: sata_sil: Rename sil_blacklist to sil_quirks jfs: UBSAN: shift-out-of-bounds in dbFindBits jfs: Fix uaf in dbFreeBits jfs: check if leafidx greater than num leaves per dmap tree jfs: Fix uninit-value access of new_ea in ea_buffer drm/amd/display: Check stream before comparing them drm/amd/display: Fix index out of bounds in degamma hardware format translation drm/amd/display: Initialize get_bytes_per_element's default to 1 drm/printer: Allow NULL data in devcoredump printer scsi: aacraid: Rearrange order of struct aac_srb_unit drm/radeon/r100: Handle unknown family in r100_cp_init_microcode() of/irq: Refer to actual buffer size in of_irq_parse_one() ext4: ext4_search_dir should return a proper error ext4: fix i_data_sem unlock order in ext4_ind_migrate() spi: s3c64xx: fix timeout counters in flush_fifo selftests: breakpoints: use remaining time to check if suspend succeed selftests: vDSO: fix vDSO symbols lookup for powerpc64 i2c: stm32f7: Do not prepare/unprepare clock during runtime suspend/resume i2c: xiic: Wait for TX empty to avoid missed TX NAKs firmware: tegra: bpmp: Drop unused mbox_client_to_bpmp() spi: bcm63xx: Fix module autoloading perf/core: Fix small negative period being ignored parisc: Fix itlb miss handler for 64-bit programs drm: Consistently use struct drm_mode_rect for FB_DAMAGE_CLIPS ALSA: core: add isascii() check to card ID generator ext4: no need to continue when the number of entries is 1 ext4: propagate errors from ext4_find_extent() in ext4_insert_range() ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space() ext4: aovid use-after-free in ext4_ext_insert_extent() ext4: fix double brelse() the buffer of the extents path ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() parisc: Fix 64-bit userspace syscall path parisc: Fix stack start for ADDR_NO_RANDOMIZE personality of/irq: Support #msi-cells=<0> in of_msi_get_domain drm: omapdrm: Add missing check for alloc_ordered_workqueue jbd2: stop waiting for space when jbd2_cleanup_journal_tail() returns error mm: krealloc: consider spare memory for __GFP_ZERO ocfs2: fix the la space leak when unmounting an ocfs2 volume ocfs2: fix uninit-value in ocfs2_get_block() ocfs2: reserve space for inline xattr before attaching reflink tree ocfs2: cancel dqi_sync_work before freeing oinfo ocfs2: remove unreasonable unlock in ocfs2_read_blocks ocfs2: fix null-ptr-deref when journal load failed. ocfs2: fix possible null-ptr-deref in ocfs2_set_buffer_uptodate riscv: define ILLEGAL_POINTER_VALUE for 64bit aoe: fix the potential use-after-free problem in more places clk: rockchip: fix error for unknown clocks media: sun4i_csi: Implement link validate for sun4i_csi subdev media: uapi/linux/cec.h: cec_msg_set_reply_to: zero flags media: venus: fix use after free bug in venus_remove due to race condition iio: magnetometer: ak8975: Fix reading for ak099xx sensors tomoyo: fallback to realpath if symlink's pathname does not exist rtc: at91sam9: fix OF node leak in probe() error path Input: adp5589-keys - fix adp5589_gpio_get_value() ACPI: resource: Add Asus Vivobook X1704VAP to irq1_level_low_skip_override[] ACPI: resource: Add Asus ExpertBook B2502CVA to irq1_level_low_skip_override[] btrfs: fix a NULL pointer dereference when failed to start a new trasacntion btrfs: wait for fixup workers before stopping cleaner kthread during umount gpio: davinci: fix lazy disable i2c: qcom-geni: Let firmware specify irq trigger flags i2c: qcom-geni: Grow a dev pointer to simplify code i2c: qcom-geni: Use IRQF_NO_AUTOEN flag in request_irq() arm64: Add Cortex-715 CPU part definition arm64: cputype: Add Neoverse-N3 definitions arm64: errata: Expand speculative SSBS workaround once more uprobes: fix kernel info leak via "[uprobes]" vma nfsd: use ktime_get_seconds() for timestamps nfsd: fix delegation_blocked() to block correctly for at least 30 seconds clk: qcom: rpmh: Simplify clk_rpmh_bcm_send_cmd() clk: qcom: clk-rpmh: Fix overflow in BCM vote r8169: Fix spelling mistake: "tx_underun" -> "tx_underrun" r8169: add tally counter fields added with RTL8125 ACPI: battery: Simplify battery hook locking ACPI: battery: Fix possible crash when unregistering a battery hook ext4: fix inode tree inconsistency caused by ENOMEM unicode: Don't special case ignorable code points net: ethernet: cortina: Drop TSO support tracing: Remove precision vsnprintf() check from print event drm/crtc: fix uninitialized variable use even harder tracing: Have saved_cmdlines arrays all in one allocation virtio_console: fix misc probe bugs Input: synaptics-rmi4 - fix UAF of IRQ domain on driver removal bpf: Check percpu map value size first s390/facility: Disable compile time optimization for decompressor code s390/mm: Add cond_resched() to cmm_alloc/free_pages() ext4: nested locking for xattr inode s390/cpum_sf: Remove WARN_ON_ONCE statements ktest.pl: Avoid false positives with grub2 skip regex clk: bcm: bcm53573: fix OF node leak in init PCI: Add ACS quirk for Qualcomm SA8775P i2c: i801: Use a different adapter-name for IDF adapters PCI: Mark Creative Labs EMU20k2 INTx masking as broken ntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition media: videobuf2-core: clear memory related fields in __vb2_plane_dmabuf_put() usb: chipidea: udc: enable suspend interrupt after usb reset usb: dwc2: Adjust the timing of USB Driver Interrupt Registration in the Crashkernel Scenario virtio_pmem: Check device status before requesting flush tools/iio: Add memory allocation failure check for trigger_name driver core: bus: Return -EIO instead of 0 when show/store invalid bus attribute fbdev: sisfb: Fix strbuf array overflow RDMA/rxe: Fix seg fault in rxe_comp_queue_pkt ice: fix VLAN replay after reset SUNRPC: Fix integer overflow in decode_rc_list() tcp: fix to allow timestamp undo if no retransmits were sent tcp: fix tcp_enter_recovery() to zero retrans_stamp when it's safe netfilter: br_netfilter: fix panic with metadata_dst skb Bluetooth: RFCOMM: FIX possible deadlock in rfcomm_sk_state_change gpio: aspeed: Add the flush write to ensure the write complete. gpio: aspeed: Use devm_clk api to manage clock source igb: Do not bring the device up after non-fatal error net/sched: accept TCA_STAB only for root qdisc net: ibm: emac: mal: fix wrong goto net: annotate lockless accesses to sk->sk_ack_backlog net: annotate lockless accesses to sk->sk_max_ack_backlog sctp: ensure sk_state is set to CLOSED if hashing fails in sctp_listen_start ppp: fix ppp_async_encode() illegal access slip: make slhc_remember() more robust against malicious packets locking/lockdep: Fix bad recursion pattern locking/lockdep: Rework lockdep_lock locking/lockdep: Avoid potential access of invalid memory in lock_class lockdep: fix deadlock issue between lockdep and rcu resource: fix region_intersects() vs add_memory_driver_managed() CDC-NCM: avoid overflow in sanity checking HID: plantronics: Workaround for an unexcepted opposite volume key Revert "usb: yurex: Replace snprintf() with the safer scnprintf() variant" usb: dwc3: core: Stop processing of pending events if controller is halted usb: xhci: Fix problem with xhci resume from suspend usb: storage: ignore bogus device raised by JieLi BR21 USB sound chip hid: intel-ish-hid: Fix uninitialized variable 'rv' in ish_fw_xfer_direct_dma net: Fix an unsafe loop on the list nouveau/dmem: Fix vulnerability in migrate_to_ram upon copy error posix-clock: Fix missing timespec64 check in pc_clock_settime() arm64: probes: Remove broken LDR (literal) uprobe support arm64: probes: Fix simulate_ldr*_literal() tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols tracing/kprobes: Fix symbol counting logic by looking at modules as well PCI: Add function 0 DMA alias quirk for Glenfly Arise chip fat: fix uninitialized variable mm/swapfile: skip HugeTLB pages for unuse_vma wifi: mac80211: fix potential key use-after-free KVM: Fix a data race on last_boosted_vcpu in kvm_vcpu_on_spin() s390/sclp_vt220: Convert newlines to CRLF instead of LFCR KVM: s390: Change virtual to physical address access in diag 0x258 handler x86/cpufeatures: Define X86_FEATURE_AMD_IBPB_RET blk-rq-qos: fix crash on rq_qos_wait vs. rq_qos_wake_function race drm/vmwgfx: Handle surface check failure correctly iio: dac: ltc1660: add missing select REGMAP_SPI in Kconfig iio: dac: stm32-dac-core: add missing select REGMAP_MMIO in Kconfig iio: adc: ti-ads8688: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig iio: hid-sensors: Fix an error handling path in _hid_sensor_set_report_latency() iio: light: opt3001: add missing full-scale range value iio: proximity: mb1232: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig iio: adc: ti-ads124s08: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig Bluetooth: Remove debugfs directory on module init failure Bluetooth: btusb: Fix regression with fake CSR controllers 0a12:0001 xhci: Fix incorrect stream context type macro USB: serial: option: add support for Quectel EG916Q-GL USB: serial: option: add Telit FN920C04 MBIM compositions parport: Proper fix for array out-of-bounds access x86/resctrl: Annotate get_mem_config() functions as __init x86/apic: Always explicitly disarm TSC-deadline timer nilfs2: propagate directory read errors from nilfs_find_entry() erofs: fix lz4 inplace decompression mac80211: Fix NULL ptr deref for injected rate info RDMA/bnxt_re: Fix incorrect AVID type in WQE structure ARM: dts: bcm2837-rpi-cm3-io3: Fix HDMI hpd-gpio pin RDMA/cxgb4: Fix RDMA_CM_EVENT_UNREACHABLE error for iWARP ipv4: give an IPv4 dev to blackhole_netdev RDMA/bnxt_re: Return more meaningful error drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation macsec: don't increment counters for an unrelated SA net: ethernet: aeroflex: fix potential memory leak in greth_start_xmit_gbit() net: systemport: fix potential memory leak in bcm_sysport_xmit() genetlink: hold RCU in genlmsg_mcast() smb: client: fix OOBs when building SMB2_IOCTL request usb: typec: altmode should keep reference to parent Bluetooth: bnep: fix wild-memory-access in proto_unregister arm64:uprobe fix the uprobe SWBP_INSN in big-endian arm64: probes: Fix uprobes for big-endian kernels KVM: s390: gaccess: Refactor gpa and length calculation KVM: s390: gaccess: Refactor access address range check KVM: s390: gaccess: Cleanup access to guest pages KVM: s390: gaccess: Check if guest address is in memslot drm/vboxvideo: Replace fake VLA at end of vbva_mouse_pointer_shape with real VLA udf: fix uninit-value use in udf_get_fileshortad jfs: Fix sanity check in dbMount tracing: Consider the NULL character when validating the event length net/sun3_82586: fix potential memory leak in sun3_82586_send_packet() be2net: fix potential memory leak in be_xmit() net: usb: usbnet: fix name regression net: sched: fix use-after-free in taprio_change() r8169: avoid unsolicited interrupts posix-clock: posix-clock: Fix unbalanced locking in pc_clock_settime() ALSA: firewire-lib: Avoid division by zero in apply_constraint_to_size() ALSA: hda/realtek: Update default depop procedure drm/amd: Guard against bad data for ATIF ACPI method ACPI: resource: Add LG 16T90SP to irq1_level_low_skip_override[] ACPI: button: Add DMI quirk for Samsung Galaxy Book2 to fix initial lid detection issue nilfs2: fix kernel bug due to missing clearing of buffer delay flag ALSA: hda/realtek: Add subwoofer quirk for Acer Predator G9-593 hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event selinux: improve error checking in sel_write_load() arm64/uprobes: change the uprobe_opcode_t typedef to fix the sparse warning xfrm: validate new SA's prefixlen using SA family when sel.family is unset cgroup: Fix potential overflow issue when checking max_depth wifi: mac80211: skip non-uploaded keys in ieee80211_iter_keys mac80211: do drv_reconfig_complete() before restarting all mac80211: Add support to trigger sta disconnect on hardware restart wifi: iwlwifi: mvm: disconnect station vifs if recovery failed wifi: iwlwifi: mvm: Fix response handling in iwl_mvm_send_recovery_cmd() ASoC: cs42l51: Fix some error handling paths in cs42l51_probe() dt-bindings: gpu: Convert Samsung Image Rotator to dt-schema gtp: simplify error handling code in 'gtp_encap_enable()' gtp: allow -1 to be specified as file description from userspace net/sched: stop qdisc_tree_reduce_backlog on TC_H_ROOT bpf: Fix out-of-bounds write in trie_get_next_key() net: support ip generic csum processing in skb_csum_hwoffload_help net: skip offload for NETIF_F_IPV6_CSUM if ipv6 header contains extension netfilter: nft_payload: sanitize offset and length before calling skb_checksum() drivers/misc: ti-st: Remove unneeded variable in st_tty_open firmware: arm_sdei: Fix the input parameter of cpuhp_remove_state() net: amd: mvme147: Fix probe banner message misc: sgi-gru: Don't disable preemption in GRU driver usbip: tools: Fix detach_port() invalid port error path usb: phy: Fix API devm_usb_put_phy() can not release the phy xhci: Fix Link TRB DMA in command ring stopped completion event Revert "driver core: Fix uevent_show() vs driver detach race" wifi: mac80211: do not pass a stopped vif to the driver in .get_txpower wifi: ath10k: Fix memory leak in management tx wifi: iwlegacy: Clear stale interrupts before resuming device staging: iio: frequency: ad9832: fix division by zero in ad9832_calc_freqreg() nilfs2: fix potential deadlock with newly created symlinks riscv: Remove unused GENERATING_ASM_OFFSETS ocfs2: pass u64 to ocfs2_truncate_inline maybe overflow nilfs2: fix kernel bug due to missing clearing of checked flag mm: shmem: fix data-race in shmem_getattr() Revert "drm/mipi-dsi: Set the fwnode for mipi_dsi_device" vt: prevent kernel-infoleak in con_font_get() mac80211: always have ieee80211_sta_restart() mm: krealloc: Fix MTE false alarm in __do_krealloc Linux 5.4.285 Change-Id: Ie1859b6122e2fdacf18a1fe83f792b855fd0e54c Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1367 lines
37 KiB
C
1367 lines
37 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Kernel thread helper functions.
|
|
* Copyright (C) 2004 IBM Corporation, Rusty Russell.
|
|
*
|
|
* Creation is done via kthreadd, so that we get a clean environment
|
|
* even if we're invoked from userspace (think modprobe, hotplug cpu,
|
|
* etc.).
|
|
*/
|
|
#include <uapi/linux/sched/types.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/sched/task.h>
|
|
#include <linux/sched/wake_q.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/err.h>
|
|
#include <linux/cgroup.h>
|
|
#include <linux/cpuset.h>
|
|
#include <linux/unistd.h>
|
|
#include <linux/file.h>
|
|
#include <linux/export.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/ptrace.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/numa.h>
|
|
#include <trace/events/sched.h>
|
|
|
|
static DEFINE_SPINLOCK(kthread_create_lock);
|
|
static LIST_HEAD(kthread_create_list);
|
|
struct task_struct *kthreadd_task;
|
|
|
|
struct kthread_create_info
|
|
{
|
|
/* Information passed to kthread() from kthreadd. */
|
|
int (*threadfn)(void *data);
|
|
void *data;
|
|
int node;
|
|
|
|
/* Result passed back to kthread_create() from kthreadd. */
|
|
struct task_struct *result;
|
|
struct completion *done;
|
|
|
|
struct list_head list;
|
|
};
|
|
|
|
struct kthread {
|
|
unsigned long flags;
|
|
unsigned int cpu;
|
|
void *data;
|
|
struct completion parked;
|
|
struct completion exited;
|
|
#ifdef CONFIG_BLK_CGROUP
|
|
struct cgroup_subsys_state *blkcg_css;
|
|
#endif
|
|
};
|
|
|
|
enum KTHREAD_BITS {
|
|
KTHREAD_IS_PER_CPU = 0,
|
|
KTHREAD_SHOULD_STOP,
|
|
KTHREAD_SHOULD_PARK,
|
|
};
|
|
|
|
static inline void set_kthread_struct(void *kthread)
|
|
{
|
|
/*
|
|
* We abuse ->set_child_tid to avoid the new member and because it
|
|
* can't be wrongly copied by copy_process(). We also rely on fact
|
|
* that the caller can't exec, so PF_KTHREAD can't be cleared.
|
|
*/
|
|
current->set_child_tid = (__force void __user *)kthread;
|
|
}
|
|
|
|
static inline struct kthread *to_kthread(struct task_struct *k)
|
|
{
|
|
WARN_ON(!(k->flags & PF_KTHREAD));
|
|
return (__force void *)k->set_child_tid;
|
|
}
|
|
|
|
/*
|
|
* Variant of to_kthread() that doesn't assume @p is a kthread.
|
|
*
|
|
* Per construction; when:
|
|
*
|
|
* (p->flags & PF_KTHREAD) && p->set_child_tid
|
|
*
|
|
* the task is both a kthread and struct kthread is persistent. However
|
|
* PF_KTHREAD on it's own is not, kernel_thread() can exec() (See umh.c and
|
|
* begin_new_exec()).
|
|
*/
|
|
static inline struct kthread *__to_kthread(struct task_struct *p)
|
|
{
|
|
void *kthread = (__force void *)p->set_child_tid;
|
|
if (kthread && !(p->flags & PF_KTHREAD))
|
|
kthread = NULL;
|
|
return kthread;
|
|
}
|
|
|
|
void free_kthread_struct(struct task_struct *k)
|
|
{
|
|
struct kthread *kthread;
|
|
|
|
/*
|
|
* Can be NULL if this kthread was created by kernel_thread()
|
|
* or if kmalloc() in kthread() failed.
|
|
*/
|
|
kthread = to_kthread(k);
|
|
#ifdef CONFIG_BLK_CGROUP
|
|
WARN_ON_ONCE(kthread && kthread->blkcg_css);
|
|
#endif
|
|
kfree(kthread);
|
|
}
|
|
|
|
/**
|
|
* kthread_should_stop - should this kthread return now?
|
|
*
|
|
* When someone calls kthread_stop() on your kthread, it will be woken
|
|
* and this will return true. You should then return, and your return
|
|
* value will be passed through to kthread_stop().
|
|
*/
|
|
bool kthread_should_stop(void)
|
|
{
|
|
return test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags);
|
|
}
|
|
EXPORT_SYMBOL(kthread_should_stop);
|
|
|
|
bool __kthread_should_park(struct task_struct *k)
|
|
{
|
|
return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(k)->flags);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__kthread_should_park);
|
|
|
|
/**
|
|
* kthread_should_park - should this kthread park now?
|
|
*
|
|
* When someone calls kthread_park() on your kthread, it will be woken
|
|
* and this will return true. You should then do the necessary
|
|
* cleanup and call kthread_parkme()
|
|
*
|
|
* Similar to kthread_should_stop(), but this keeps the thread alive
|
|
* and in a park position. kthread_unpark() "restarts" the thread and
|
|
* calls the thread function again.
|
|
*/
|
|
bool kthread_should_park(void)
|
|
{
|
|
return __kthread_should_park(current);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_should_park);
|
|
|
|
/**
|
|
* kthread_freezable_should_stop - should this freezable kthread return now?
|
|
* @was_frozen: optional out parameter, indicates whether %current was frozen
|
|
*
|
|
* kthread_should_stop() for freezable kthreads, which will enter
|
|
* refrigerator if necessary. This function is safe from kthread_stop() /
|
|
* freezer deadlock and freezable kthreads should use this function instead
|
|
* of calling try_to_freeze() directly.
|
|
*/
|
|
bool kthread_freezable_should_stop(bool *was_frozen)
|
|
{
|
|
bool frozen = false;
|
|
|
|
might_sleep();
|
|
|
|
if (unlikely(freezing(current)))
|
|
frozen = __refrigerator(true);
|
|
|
|
if (was_frozen)
|
|
*was_frozen = frozen;
|
|
|
|
return kthread_should_stop();
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_freezable_should_stop);
|
|
|
|
/**
|
|
* kthread_data - return data value specified on kthread creation
|
|
* @task: kthread task in question
|
|
*
|
|
* Return the data value specified when kthread @task was created.
|
|
* The caller is responsible for ensuring the validity of @task when
|
|
* calling this function.
|
|
*/
|
|
void *kthread_data(struct task_struct *task)
|
|
{
|
|
return to_kthread(task)->data;
|
|
}
|
|
|
|
/**
|
|
* kthread_probe_data - speculative version of kthread_data()
|
|
* @task: possible kthread task in question
|
|
*
|
|
* @task could be a kthread task. Return the data value specified when it
|
|
* was created if accessible. If @task isn't a kthread task or its data is
|
|
* inaccessible for any reason, %NULL is returned. This function requires
|
|
* that @task itself is safe to dereference.
|
|
*/
|
|
void *kthread_probe_data(struct task_struct *task)
|
|
{
|
|
struct kthread *kthread = __to_kthread(task);
|
|
void *data = NULL;
|
|
|
|
if (kthread)
|
|
probe_kernel_read(&data, &kthread->data, sizeof(data));
|
|
return data;
|
|
}
|
|
|
|
static void __kthread_parkme(struct kthread *self)
|
|
{
|
|
for (;;) {
|
|
/*
|
|
* TASK_PARKED is a special state; we must serialize against
|
|
* possible pending wakeups to avoid store-store collisions on
|
|
* task->state.
|
|
*
|
|
* Such a collision might possibly result in the task state
|
|
* changin from TASK_PARKED and us failing the
|
|
* wait_task_inactive() in kthread_park().
|
|
*/
|
|
set_special_state(TASK_PARKED);
|
|
if (!test_bit(KTHREAD_SHOULD_PARK, &self->flags))
|
|
break;
|
|
|
|
/*
|
|
* Thread is going to call schedule(), do not preempt it,
|
|
* or the caller of kthread_park() may spend more time in
|
|
* wait_task_inactive().
|
|
*/
|
|
preempt_disable();
|
|
complete(&self->parked);
|
|
schedule_preempt_disabled();
|
|
preempt_enable();
|
|
}
|
|
__set_current_state(TASK_RUNNING);
|
|
}
|
|
|
|
void kthread_parkme(void)
|
|
{
|
|
__kthread_parkme(to_kthread(current));
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_parkme);
|
|
|
|
static int kthread(void *_create)
|
|
{
|
|
/* Copy data: it's on kthread's stack */
|
|
struct kthread_create_info *create = _create;
|
|
int (*threadfn)(void *data) = create->threadfn;
|
|
void *data = create->data;
|
|
struct completion *done;
|
|
struct kthread *self;
|
|
int ret;
|
|
|
|
self = kzalloc(sizeof(*self), GFP_KERNEL);
|
|
set_kthread_struct(self);
|
|
|
|
/* If user was SIGKILLed, I release the structure. */
|
|
done = xchg(&create->done, NULL);
|
|
if (!done) {
|
|
kfree(create);
|
|
do_exit(-EINTR);
|
|
}
|
|
|
|
if (!self) {
|
|
create->result = ERR_PTR(-ENOMEM);
|
|
complete(done);
|
|
do_exit(-ENOMEM);
|
|
}
|
|
|
|
self->data = data;
|
|
init_completion(&self->exited);
|
|
init_completion(&self->parked);
|
|
current->vfork_done = &self->exited;
|
|
|
|
/* OK, tell user we're spawned, wait for stop or wakeup */
|
|
__set_current_state(TASK_UNINTERRUPTIBLE);
|
|
create->result = current;
|
|
/*
|
|
* Thread is going to call schedule(), do not preempt it,
|
|
* or the creator may spend more time in wait_task_inactive().
|
|
*/
|
|
preempt_disable();
|
|
complete(done);
|
|
schedule_preempt_disabled();
|
|
preempt_enable();
|
|
|
|
ret = -EINTR;
|
|
if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) {
|
|
cgroup_kthread_ready();
|
|
__kthread_parkme(self);
|
|
ret = threadfn(data);
|
|
}
|
|
do_exit(ret);
|
|
}
|
|
|
|
/* called from do_fork() to get node information for about to be created task */
|
|
int tsk_fork_get_node(struct task_struct *tsk)
|
|
{
|
|
#ifdef CONFIG_NUMA
|
|
if (tsk == kthreadd_task)
|
|
return tsk->pref_node_fork;
|
|
#endif
|
|
return NUMA_NO_NODE;
|
|
}
|
|
|
|
static void create_kthread(struct kthread_create_info *create)
|
|
{
|
|
int pid;
|
|
|
|
#ifdef CONFIG_NUMA
|
|
current->pref_node_fork = create->node;
|
|
#endif
|
|
/* We want our own signal handler (we take no signals by default). */
|
|
pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
|
|
if (pid < 0) {
|
|
/* If user was SIGKILLed, I release the structure. */
|
|
struct completion *done = xchg(&create->done, NULL);
|
|
|
|
if (!done) {
|
|
kfree(create);
|
|
return;
|
|
}
|
|
create->result = ERR_PTR(pid);
|
|
complete(done);
|
|
}
|
|
}
|
|
|
|
static __printf(4, 0)
|
|
struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
|
|
void *data, int node,
|
|
const char namefmt[],
|
|
va_list args)
|
|
{
|
|
DECLARE_COMPLETION_ONSTACK(done);
|
|
struct task_struct *task;
|
|
struct kthread_create_info *create = kmalloc(sizeof(*create),
|
|
GFP_KERNEL);
|
|
|
|
if (!create)
|
|
return ERR_PTR(-ENOMEM);
|
|
create->threadfn = threadfn;
|
|
create->data = data;
|
|
create->node = node;
|
|
create->done = &done;
|
|
|
|
spin_lock(&kthread_create_lock);
|
|
list_add_tail(&create->list, &kthread_create_list);
|
|
spin_unlock(&kthread_create_lock);
|
|
|
|
wake_up_process(kthreadd_task);
|
|
/*
|
|
* Wait for completion in killable state, for I might be chosen by
|
|
* the OOM killer while kthreadd is trying to allocate memory for
|
|
* new kernel thread.
|
|
*/
|
|
if (unlikely(wait_for_completion_killable(&done))) {
|
|
/*
|
|
* If I was SIGKILLed before kthreadd (or new kernel thread)
|
|
* calls complete(), leave the cleanup of this structure to
|
|
* that thread.
|
|
*/
|
|
if (xchg(&create->done, NULL))
|
|
return ERR_PTR(-EINTR);
|
|
/*
|
|
* kthreadd (or new kernel thread) will call complete()
|
|
* shortly.
|
|
*/
|
|
wait_for_completion(&done);
|
|
}
|
|
task = create->result;
|
|
if (!IS_ERR(task)) {
|
|
static const struct sched_param param = { .sched_priority = 0 };
|
|
char name[TASK_COMM_LEN];
|
|
|
|
/*
|
|
* task is already visible to other tasks, so updating
|
|
* COMM must be protected.
|
|
*/
|
|
vsnprintf(name, sizeof(name), namefmt, args);
|
|
set_task_comm(task, name);
|
|
/*
|
|
* root may have changed our (kthreadd's) priority or CPU mask.
|
|
* The kernel thread should not inherit these properties.
|
|
*/
|
|
sched_setscheduler_nocheck(task, SCHED_NORMAL, ¶m);
|
|
set_cpus_allowed_ptr(task, cpu_all_mask);
|
|
}
|
|
kfree(create);
|
|
return task;
|
|
}
|
|
|
|
/**
|
|
* kthread_create_on_node - create a kthread.
|
|
* @threadfn: the function to run until signal_pending(current).
|
|
* @data: data ptr for @threadfn.
|
|
* @node: task and thread structures for the thread are allocated on this node
|
|
* @namefmt: printf-style name for the thread.
|
|
*
|
|
* Description: This helper function creates and names a kernel
|
|
* thread. The thread will be stopped: use wake_up_process() to start
|
|
* it. See also kthread_run(). The new thread has SCHED_NORMAL policy and
|
|
* is affine to all CPUs.
|
|
*
|
|
* If thread is going to be bound on a particular cpu, give its node
|
|
* in @node, to get NUMA affinity for kthread stack, or else give NUMA_NO_NODE.
|
|
* When woken, the thread will run @threadfn() with @data as its
|
|
* argument. @threadfn() can either call do_exit() directly if it is a
|
|
* standalone thread for which no one will call kthread_stop(), or
|
|
* return when 'kthread_should_stop()' is true (which means
|
|
* kthread_stop() has been called). The return value should be zero
|
|
* or a negative error number; it will be passed to kthread_stop().
|
|
*
|
|
* Returns a task_struct or ERR_PTR(-ENOMEM) or ERR_PTR(-EINTR).
|
|
*/
|
|
struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
|
|
void *data, int node,
|
|
const char namefmt[],
|
|
...)
|
|
{
|
|
struct task_struct *task;
|
|
va_list args;
|
|
|
|
va_start(args, namefmt);
|
|
task = __kthread_create_on_node(threadfn, data, node, namefmt, args);
|
|
va_end(args);
|
|
|
|
return task;
|
|
}
|
|
EXPORT_SYMBOL(kthread_create_on_node);
|
|
|
|
static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state)
|
|
{
|
|
unsigned long flags;
|
|
|
|
if (!wait_task_inactive(p, state)) {
|
|
WARN_ON(1);
|
|
return;
|
|
}
|
|
|
|
/* It's safe because the task is inactive. */
|
|
raw_spin_lock_irqsave(&p->pi_lock, flags);
|
|
do_set_cpus_allowed(p, mask);
|
|
p->flags |= PF_NO_SETAFFINITY;
|
|
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
|
|
}
|
|
|
|
static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
|
|
{
|
|
__kthread_bind_mask(p, cpumask_of(cpu), state);
|
|
}
|
|
|
|
void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
|
|
{
|
|
__kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
|
|
}
|
|
|
|
/**
|
|
* kthread_bind - bind a just-created kthread to a cpu.
|
|
* @p: thread created by kthread_create().
|
|
* @cpu: cpu (might not be online, must be possible) for @k to run on.
|
|
*
|
|
* Description: This function is equivalent to set_cpus_allowed(),
|
|
* except that @cpu doesn't need to be online, and the thread must be
|
|
* stopped (i.e., just returned from kthread_create()).
|
|
*/
|
|
void kthread_bind(struct task_struct *p, unsigned int cpu)
|
|
{
|
|
__kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE);
|
|
}
|
|
EXPORT_SYMBOL(kthread_bind);
|
|
|
|
/**
|
|
* kthread_create_on_cpu - Create a cpu bound kthread
|
|
* @threadfn: the function to run until signal_pending(current).
|
|
* @data: data ptr for @threadfn.
|
|
* @cpu: The cpu on which the thread should be bound,
|
|
* @namefmt: printf-style name for the thread. Format is restricted
|
|
* to "name.*%u". Code fills in cpu number.
|
|
*
|
|
* Description: This helper function creates and names a kernel thread
|
|
* The thread will be woken and put into park mode.
|
|
*/
|
|
struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
|
|
void *data, unsigned int cpu,
|
|
const char *namefmt)
|
|
{
|
|
struct task_struct *p;
|
|
|
|
p = kthread_create_on_node(threadfn, data, cpu_to_node(cpu), namefmt,
|
|
cpu);
|
|
if (IS_ERR(p))
|
|
return p;
|
|
kthread_bind(p, cpu);
|
|
/* CPU hotplug need to bind once again when unparking the thread. */
|
|
to_kthread(p)->cpu = cpu;
|
|
return p;
|
|
}
|
|
|
|
void kthread_set_per_cpu(struct task_struct *k, int cpu)
|
|
{
|
|
struct kthread *kthread = to_kthread(k);
|
|
if (!kthread)
|
|
return;
|
|
|
|
WARN_ON_ONCE(!(k->flags & PF_NO_SETAFFINITY));
|
|
|
|
if (cpu < 0) {
|
|
clear_bit(KTHREAD_IS_PER_CPU, &kthread->flags);
|
|
return;
|
|
}
|
|
|
|
kthread->cpu = cpu;
|
|
set_bit(KTHREAD_IS_PER_CPU, &kthread->flags);
|
|
}
|
|
|
|
bool kthread_is_per_cpu(struct task_struct *p)
|
|
{
|
|
struct kthread *kthread = __to_kthread(p);
|
|
if (!kthread)
|
|
return false;
|
|
|
|
return test_bit(KTHREAD_IS_PER_CPU, &kthread->flags);
|
|
}
|
|
|
|
/**
|
|
* kthread_unpark - unpark a thread created by kthread_create().
|
|
* @k: thread created by kthread_create().
|
|
*
|
|
* Sets kthread_should_park() for @k to return false, wakes it, and
|
|
* waits for it to return. If the thread is marked percpu then its
|
|
* bound to the cpu again.
|
|
*/
|
|
void kthread_unpark(struct task_struct *k)
|
|
{
|
|
struct kthread *kthread = to_kthread(k);
|
|
|
|
/*
|
|
* Newly created kthread was parked when the CPU was offline.
|
|
* The binding was lost and we need to set it again.
|
|
*/
|
|
if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags))
|
|
__kthread_bind(k, kthread->cpu, TASK_PARKED);
|
|
|
|
clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
|
|
/*
|
|
* __kthread_parkme() will either see !SHOULD_PARK or get the wakeup.
|
|
*/
|
|
wake_up_state(k, TASK_PARKED);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_unpark);
|
|
|
|
/**
|
|
* kthread_park - park a thread created by kthread_create().
|
|
* @k: thread created by kthread_create().
|
|
*
|
|
* Sets kthread_should_park() for @k to return true, wakes it, and
|
|
* waits for it to return. This can also be called after kthread_create()
|
|
* instead of calling wake_up_process(): the thread will park without
|
|
* calling threadfn().
|
|
*
|
|
* Returns 0 if the thread is parked, -ENOSYS if the thread exited.
|
|
* If called by the kthread itself just the park bit is set.
|
|
*/
|
|
int kthread_park(struct task_struct *k)
|
|
{
|
|
struct kthread *kthread = to_kthread(k);
|
|
|
|
if (WARN_ON(k->flags & PF_EXITING))
|
|
return -ENOSYS;
|
|
|
|
if (WARN_ON_ONCE(test_bit(KTHREAD_SHOULD_PARK, &kthread->flags)))
|
|
return -EBUSY;
|
|
|
|
set_bit(KTHREAD_SHOULD_PARK, &kthread->flags);
|
|
if (k != current) {
|
|
wake_up_process(k);
|
|
/*
|
|
* Wait for __kthread_parkme() to complete(), this means we
|
|
* _will_ have TASK_PARKED and are about to call schedule().
|
|
*/
|
|
wait_for_completion(&kthread->parked);
|
|
/*
|
|
* Now wait for that schedule() to complete and the task to
|
|
* get scheduled out.
|
|
*/
|
|
WARN_ON_ONCE(!wait_task_inactive(k, TASK_PARKED));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_park);
|
|
|
|
/**
|
|
* kthread_stop - stop a thread created by kthread_create().
|
|
* @k: thread created by kthread_create().
|
|
*
|
|
* Sets kthread_should_stop() for @k to return true, wakes it, and
|
|
* waits for it to exit. This can also be called after kthread_create()
|
|
* instead of calling wake_up_process(): the thread will exit without
|
|
* calling threadfn().
|
|
*
|
|
* If threadfn() may call do_exit() itself, the caller must ensure
|
|
* task_struct can't go away.
|
|
*
|
|
* Returns the result of threadfn(), or %-EINTR if wake_up_process()
|
|
* was never called.
|
|
*/
|
|
int kthread_stop(struct task_struct *k)
|
|
{
|
|
struct kthread *kthread;
|
|
int ret;
|
|
|
|
trace_sched_kthread_stop(k);
|
|
|
|
get_task_struct(k);
|
|
kthread = to_kthread(k);
|
|
set_bit(KTHREAD_SHOULD_STOP, &kthread->flags);
|
|
kthread_unpark(k);
|
|
wake_up_process(k);
|
|
wait_for_completion(&kthread->exited);
|
|
ret = k->exit_code;
|
|
put_task_struct(k);
|
|
|
|
trace_sched_kthread_stop_ret(ret);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(kthread_stop);
|
|
|
|
int kthreadd(void *unused)
|
|
{
|
|
struct task_struct *tsk = current;
|
|
|
|
/* Setup a clean context for our children to inherit. */
|
|
set_task_comm(tsk, "kthreadd");
|
|
ignore_signals(tsk);
|
|
set_cpus_allowed_ptr(tsk, cpu_all_mask);
|
|
set_mems_allowed(node_states[N_MEMORY]);
|
|
|
|
current->flags |= PF_NOFREEZE;
|
|
cgroup_init_kthreadd();
|
|
|
|
for (;;) {
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
if (list_empty(&kthread_create_list))
|
|
schedule();
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
spin_lock(&kthread_create_lock);
|
|
while (!list_empty(&kthread_create_list)) {
|
|
struct kthread_create_info *create;
|
|
|
|
create = list_entry(kthread_create_list.next,
|
|
struct kthread_create_info, list);
|
|
list_del_init(&create->list);
|
|
spin_unlock(&kthread_create_lock);
|
|
|
|
create_kthread(create);
|
|
|
|
spin_lock(&kthread_create_lock);
|
|
}
|
|
spin_unlock(&kthread_create_lock);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void __kthread_init_worker(struct kthread_worker *worker,
|
|
const char *name,
|
|
struct lock_class_key *key)
|
|
{
|
|
memset(worker, 0, sizeof(struct kthread_worker));
|
|
raw_spin_lock_init(&worker->lock);
|
|
lockdep_set_class_and_name(&worker->lock, key, name);
|
|
INIT_LIST_HEAD(&worker->work_list);
|
|
INIT_LIST_HEAD(&worker->delayed_work_list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__kthread_init_worker);
|
|
|
|
/**
|
|
* kthread_worker_fn - kthread function to process kthread_worker
|
|
* @worker_ptr: pointer to initialized kthread_worker
|
|
*
|
|
* This function implements the main cycle of kthread worker. It processes
|
|
* work_list until it is stopped with kthread_stop(). It sleeps when the queue
|
|
* is empty.
|
|
*
|
|
* The works are not allowed to keep any locks, disable preemption or interrupts
|
|
* when they finish. There is defined a safe point for freezing when one work
|
|
* finishes and before a new one is started.
|
|
*
|
|
* Also the works must not be handled by more than one worker at the same time,
|
|
* see also kthread_queue_work().
|
|
*/
|
|
int kthread_worker_fn(void *worker_ptr)
|
|
{
|
|
struct kthread_worker *worker = worker_ptr;
|
|
struct kthread_work *work;
|
|
|
|
/*
|
|
* FIXME: Update the check and remove the assignment when all kthread
|
|
* worker users are created using kthread_create_worker*() functions.
|
|
*/
|
|
WARN_ON(worker->task && worker->task != current);
|
|
worker->task = current;
|
|
|
|
if (worker->flags & KTW_FREEZABLE)
|
|
set_freezable();
|
|
|
|
repeat:
|
|
set_current_state(TASK_INTERRUPTIBLE); /* mb paired w/ kthread_stop */
|
|
|
|
if (kthread_should_stop()) {
|
|
__set_current_state(TASK_RUNNING);
|
|
raw_spin_lock_irq(&worker->lock);
|
|
worker->task = NULL;
|
|
raw_spin_unlock_irq(&worker->lock);
|
|
return 0;
|
|
}
|
|
|
|
work = NULL;
|
|
raw_spin_lock_irq(&worker->lock);
|
|
if (!list_empty(&worker->work_list)) {
|
|
work = list_first_entry(&worker->work_list,
|
|
struct kthread_work, node);
|
|
list_del_init(&work->node);
|
|
}
|
|
worker->current_work = work;
|
|
raw_spin_unlock_irq(&worker->lock);
|
|
|
|
if (work) {
|
|
kthread_work_func_t func = work->func;
|
|
__set_current_state(TASK_RUNNING);
|
|
trace_sched_kthread_work_execute_start(work);
|
|
work->func(work);
|
|
/*
|
|
* Avoid dereferencing work after this point. The trace
|
|
* event only cares about the address.
|
|
*/
|
|
trace_sched_kthread_work_execute_end(work, func);
|
|
} else if (!freezing(current)) {
|
|
schedule();
|
|
} else {
|
|
/*
|
|
* Handle the case where the current remains
|
|
* TASK_INTERRUPTIBLE. try_to_freeze() expects
|
|
* the current to be TASK_RUNNING.
|
|
*/
|
|
__set_current_state(TASK_RUNNING);
|
|
}
|
|
|
|
try_to_freeze();
|
|
cond_resched();
|
|
goto repeat;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_worker_fn);
|
|
|
|
static __printf(3, 0) struct kthread_worker *
|
|
__kthread_create_worker(int cpu, unsigned int flags,
|
|
const char namefmt[], va_list args)
|
|
{
|
|
struct kthread_worker *worker;
|
|
struct task_struct *task;
|
|
int node = NUMA_NO_NODE;
|
|
|
|
worker = kzalloc(sizeof(*worker), GFP_KERNEL);
|
|
if (!worker)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
kthread_init_worker(worker);
|
|
|
|
if (cpu >= 0)
|
|
node = cpu_to_node(cpu);
|
|
|
|
task = __kthread_create_on_node(kthread_worker_fn, worker,
|
|
node, namefmt, args);
|
|
if (IS_ERR(task))
|
|
goto fail_task;
|
|
|
|
if (cpu >= 0)
|
|
kthread_bind(task, cpu);
|
|
|
|
worker->flags = flags;
|
|
worker->task = task;
|
|
wake_up_process(task);
|
|
return worker;
|
|
|
|
fail_task:
|
|
kfree(worker);
|
|
return ERR_CAST(task);
|
|
}
|
|
|
|
/**
|
|
* kthread_create_worker - create a kthread worker
|
|
* @flags: flags modifying the default behavior of the worker
|
|
* @namefmt: printf-style name for the kthread worker (task).
|
|
*
|
|
* Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM)
|
|
* when the needed structures could not get allocated, and ERR_PTR(-EINTR)
|
|
* when the worker was SIGKILLed.
|
|
*/
|
|
struct kthread_worker *
|
|
kthread_create_worker(unsigned int flags, const char namefmt[], ...)
|
|
{
|
|
struct kthread_worker *worker;
|
|
va_list args;
|
|
|
|
va_start(args, namefmt);
|
|
worker = __kthread_create_worker(-1, flags, namefmt, args);
|
|
va_end(args);
|
|
|
|
return worker;
|
|
}
|
|
EXPORT_SYMBOL(kthread_create_worker);
|
|
|
|
/**
|
|
* kthread_create_worker_on_cpu - create a kthread worker and bind it
|
|
* it to a given CPU and the associated NUMA node.
|
|
* @cpu: CPU number
|
|
* @flags: flags modifying the default behavior of the worker
|
|
* @namefmt: printf-style name for the kthread worker (task).
|
|
*
|
|
* Use a valid CPU number if you want to bind the kthread worker
|
|
* to the given CPU and the associated NUMA node.
|
|
*
|
|
* A good practice is to add the cpu number also into the worker name.
|
|
* For example, use kthread_create_worker_on_cpu(cpu, "helper/%d", cpu).
|
|
*
|
|
* Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM)
|
|
* when the needed structures could not get allocated, and ERR_PTR(-EINTR)
|
|
* when the worker was SIGKILLed.
|
|
*/
|
|
struct kthread_worker *
|
|
kthread_create_worker_on_cpu(int cpu, unsigned int flags,
|
|
const char namefmt[], ...)
|
|
{
|
|
struct kthread_worker *worker;
|
|
va_list args;
|
|
|
|
va_start(args, namefmt);
|
|
worker = __kthread_create_worker(cpu, flags, namefmt, args);
|
|
va_end(args);
|
|
|
|
return worker;
|
|
}
|
|
EXPORT_SYMBOL(kthread_create_worker_on_cpu);
|
|
|
|
/*
|
|
* Returns true when the work could not be queued at the moment.
|
|
* It happens when it is already pending in a worker list
|
|
* or when it is being cancelled.
|
|
*/
|
|
static inline bool queuing_blocked(struct kthread_worker *worker,
|
|
struct kthread_work *work)
|
|
{
|
|
lockdep_assert_held(&worker->lock);
|
|
|
|
return !list_empty(&work->node) || work->canceling;
|
|
}
|
|
|
|
static void kthread_insert_work_sanity_check(struct kthread_worker *worker,
|
|
struct kthread_work *work)
|
|
{
|
|
lockdep_assert_held(&worker->lock);
|
|
WARN_ON_ONCE(!list_empty(&work->node));
|
|
/* Do not use a work with >1 worker, see kthread_queue_work() */
|
|
WARN_ON_ONCE(work->worker && work->worker != worker);
|
|
}
|
|
|
|
/* insert @work before @pos in @worker */
|
|
static void kthread_insert_work(struct kthread_worker *worker,
|
|
struct kthread_work *work,
|
|
struct list_head *pos,
|
|
struct wake_q_head *wake_q)
|
|
{
|
|
kthread_insert_work_sanity_check(worker, work);
|
|
|
|
trace_sched_kthread_work_queue_work(worker, work);
|
|
|
|
list_add_tail(&work->node, pos);
|
|
work->worker = worker;
|
|
if (!worker->current_work && likely(worker->task))
|
|
wake_q_add(wake_q, worker->task);
|
|
}
|
|
|
|
/**
|
|
* kthread_queue_work - queue a kthread_work
|
|
* @worker: target kthread_worker
|
|
* @work: kthread_work to queue
|
|
*
|
|
* Queue @work to work processor @task for async execution. @task
|
|
* must have been created with kthread_worker_create(). Returns %true
|
|
* if @work was successfully queued, %false if it was already pending.
|
|
*
|
|
* Reinitialize the work if it needs to be used by another worker.
|
|
* For example, when the worker was stopped and started again.
|
|
*/
|
|
bool kthread_queue_work(struct kthread_worker *worker,
|
|
struct kthread_work *work)
|
|
{
|
|
DEFINE_WAKE_Q(wake_q);
|
|
unsigned long flags;
|
|
bool ret = false;
|
|
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
if (!queuing_blocked(worker, work)) {
|
|
kthread_insert_work(worker, work, &worker->work_list, &wake_q);
|
|
ret = true;
|
|
}
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
|
|
wake_up_q(&wake_q);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_queue_work);
|
|
|
|
/**
|
|
* kthread_delayed_work_timer_fn - callback that queues the associated kthread
|
|
* delayed work when the timer expires.
|
|
* @t: pointer to the expired timer
|
|
*
|
|
* The format of the function is defined by struct timer_list.
|
|
* It should have been called from irqsafe timer with irq already off.
|
|
*/
|
|
void kthread_delayed_work_timer_fn(struct timer_list *t)
|
|
{
|
|
struct kthread_delayed_work *dwork = from_timer(dwork, t, timer);
|
|
struct kthread_work *work = &dwork->work;
|
|
struct kthread_worker *worker = work->worker;
|
|
DEFINE_WAKE_Q(wake_q);
|
|
unsigned long flags;
|
|
|
|
/*
|
|
* This might happen when a pending work is reinitialized.
|
|
* It means that it is used a wrong way.
|
|
*/
|
|
if (WARN_ON_ONCE(!worker))
|
|
return;
|
|
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
/* Work must not be used with >1 worker, see kthread_queue_work(). */
|
|
WARN_ON_ONCE(work->worker != worker);
|
|
|
|
/* Move the work from worker->delayed_work_list. */
|
|
WARN_ON_ONCE(list_empty(&work->node));
|
|
list_del_init(&work->node);
|
|
if (!work->canceling)
|
|
kthread_insert_work(worker, work, &worker->work_list, &wake_q);
|
|
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
|
|
wake_up_q(&wake_q);
|
|
}
|
|
EXPORT_SYMBOL(kthread_delayed_work_timer_fn);
|
|
|
|
static void __kthread_queue_delayed_work(struct kthread_worker *worker,
|
|
struct kthread_delayed_work *dwork,
|
|
unsigned long delay,
|
|
struct wake_q_head *wake_q)
|
|
{
|
|
struct timer_list *timer = &dwork->timer;
|
|
struct kthread_work *work = &dwork->work;
|
|
|
|
#ifndef CONFIG_CFI_CLANG
|
|
WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn);
|
|
#endif
|
|
|
|
/*
|
|
* If @delay is 0, queue @dwork->work immediately. This is for
|
|
* both optimization and correctness. The earliest @timer can
|
|
* expire is on the closest next tick and delayed_work users depend
|
|
* on that there's no such delay when @delay is 0.
|
|
*/
|
|
if (!delay) {
|
|
kthread_insert_work(worker, work, &worker->work_list, wake_q);
|
|
return;
|
|
}
|
|
|
|
/* Be paranoid and try to detect possible races already now. */
|
|
kthread_insert_work_sanity_check(worker, work);
|
|
|
|
list_add(&work->node, &worker->delayed_work_list);
|
|
work->worker = worker;
|
|
timer->expires = jiffies + delay;
|
|
add_timer(timer);
|
|
}
|
|
|
|
/**
|
|
* kthread_queue_delayed_work - queue the associated kthread work
|
|
* after a delay.
|
|
* @worker: target kthread_worker
|
|
* @dwork: kthread_delayed_work to queue
|
|
* @delay: number of jiffies to wait before queuing
|
|
*
|
|
* If the work has not been pending it starts a timer that will queue
|
|
* the work after the given @delay. If @delay is zero, it queues the
|
|
* work immediately.
|
|
*
|
|
* Return: %false if the @work has already been pending. It means that
|
|
* either the timer was running or the work was queued. It returns %true
|
|
* otherwise.
|
|
*/
|
|
bool kthread_queue_delayed_work(struct kthread_worker *worker,
|
|
struct kthread_delayed_work *dwork,
|
|
unsigned long delay)
|
|
{
|
|
struct kthread_work *work = &dwork->work;
|
|
DEFINE_WAKE_Q(wake_q);
|
|
unsigned long flags;
|
|
bool ret = false;
|
|
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
|
|
if (!queuing_blocked(worker, work)) {
|
|
__kthread_queue_delayed_work(worker, dwork, delay, &wake_q);
|
|
ret = true;
|
|
}
|
|
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
|
|
wake_up_q(&wake_q);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_queue_delayed_work);
|
|
|
|
struct kthread_flush_work {
|
|
struct kthread_work work;
|
|
struct completion done;
|
|
};
|
|
|
|
static void kthread_flush_work_fn(struct kthread_work *work)
|
|
{
|
|
struct kthread_flush_work *fwork =
|
|
container_of(work, struct kthread_flush_work, work);
|
|
complete(&fwork->done);
|
|
}
|
|
|
|
/**
|
|
* kthread_flush_work - flush a kthread_work
|
|
* @work: work to flush
|
|
*
|
|
* If @work is queued or executing, wait for it to finish execution.
|
|
*/
|
|
void kthread_flush_work(struct kthread_work *work)
|
|
{
|
|
struct kthread_flush_work fwork = {
|
|
KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn),
|
|
COMPLETION_INITIALIZER_ONSTACK(fwork.done),
|
|
};
|
|
DEFINE_WAKE_Q(wake_q);
|
|
struct kthread_worker *worker;
|
|
bool noop = false;
|
|
|
|
worker = work->worker;
|
|
if (!worker)
|
|
return;
|
|
|
|
raw_spin_lock_irq(&worker->lock);
|
|
/* Work must not be used with >1 worker, see kthread_queue_work(). */
|
|
WARN_ON_ONCE(work->worker != worker);
|
|
|
|
if (!list_empty(&work->node))
|
|
kthread_insert_work(worker, &fwork.work,
|
|
work->node.next, &wake_q);
|
|
else if (worker->current_work == work)
|
|
kthread_insert_work(worker, &fwork.work,
|
|
worker->work_list.next, &wake_q);
|
|
else
|
|
noop = true;
|
|
|
|
raw_spin_unlock_irq(&worker->lock);
|
|
|
|
wake_up_q(&wake_q);
|
|
|
|
if (!noop)
|
|
wait_for_completion(&fwork.done);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_flush_work);
|
|
|
|
/*
|
|
* Make sure that the timer is neither set nor running and could
|
|
* not manipulate the work list_head any longer.
|
|
*
|
|
* The function is called under worker->lock. The lock is temporary
|
|
* released but the timer can't be set again in the meantime.
|
|
*/
|
|
static void kthread_cancel_delayed_work_timer(struct kthread_work *work,
|
|
unsigned long *flags)
|
|
{
|
|
struct kthread_delayed_work *dwork =
|
|
container_of(work, struct kthread_delayed_work, work);
|
|
struct kthread_worker *worker = work->worker;
|
|
|
|
/*
|
|
* del_timer_sync() must be called to make sure that the timer
|
|
* callback is not running. The lock must be temporary released
|
|
* to avoid a deadlock with the callback. In the meantime,
|
|
* any queuing is blocked by setting the canceling counter.
|
|
*/
|
|
work->canceling++;
|
|
raw_spin_unlock_irqrestore(&worker->lock, *flags);
|
|
del_timer_sync(&dwork->timer);
|
|
raw_spin_lock_irqsave(&worker->lock, *flags);
|
|
work->canceling--;
|
|
}
|
|
|
|
/*
|
|
* This function removes the work from the worker queue.
|
|
*
|
|
* It is called under worker->lock. The caller must make sure that
|
|
* the timer used by delayed work is not running, e.g. by calling
|
|
* kthread_cancel_delayed_work_timer().
|
|
*
|
|
* The work might still be in use when this function finishes. See the
|
|
* current_work proceed by the worker.
|
|
*
|
|
* Return: %true if @work was pending and successfully canceled,
|
|
* %false if @work was not pending
|
|
*/
|
|
static bool __kthread_cancel_work(struct kthread_work *work)
|
|
{
|
|
/*
|
|
* Try to remove the work from a worker list. It might either
|
|
* be from worker->work_list or from worker->delayed_work_list.
|
|
*/
|
|
if (!list_empty(&work->node)) {
|
|
list_del_init(&work->node);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* kthread_mod_delayed_work - modify delay of or queue a kthread delayed work
|
|
* @worker: kthread worker to use
|
|
* @dwork: kthread delayed work to queue
|
|
* @delay: number of jiffies to wait before queuing
|
|
*
|
|
* If @dwork is idle, equivalent to kthread_queue_delayed_work(). Otherwise,
|
|
* modify @dwork's timer so that it expires after @delay. If @delay is zero,
|
|
* @work is guaranteed to be queued immediately.
|
|
*
|
|
* Return: %false if @dwork was idle and queued, %true otherwise.
|
|
*
|
|
* A special case is when the work is being canceled in parallel.
|
|
* It might be caused either by the real kthread_cancel_delayed_work_sync()
|
|
* or yet another kthread_mod_delayed_work() call. We let the other command
|
|
* win and return %true here. The return value can be used for reference
|
|
* counting and the number of queued works stays the same. Anyway, the caller
|
|
* is supposed to synchronize these operations a reasonable way.
|
|
*
|
|
* This function is safe to call from any context including IRQ handler.
|
|
* See __kthread_cancel_work() and kthread_delayed_work_timer_fn()
|
|
* for details.
|
|
*/
|
|
bool kthread_mod_delayed_work(struct kthread_worker *worker,
|
|
struct kthread_delayed_work *dwork,
|
|
unsigned long delay)
|
|
{
|
|
struct kthread_work *work = &dwork->work;
|
|
DEFINE_WAKE_Q(wake_q);
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
|
|
/* Do not bother with canceling when never queued. */
|
|
if (!work->worker) {
|
|
ret = false;
|
|
goto fast_queue;
|
|
}
|
|
|
|
/* Work must not be used with >1 worker, see kthread_queue_work() */
|
|
WARN_ON_ONCE(work->worker != worker);
|
|
|
|
/*
|
|
* Temporary cancel the work but do not fight with another command
|
|
* that is canceling the work as well.
|
|
*
|
|
* It is a bit tricky because of possible races with another
|
|
* mod_delayed_work() and cancel_delayed_work() callers.
|
|
*
|
|
* The timer must be canceled first because worker->lock is released
|
|
* when doing so. But the work can be removed from the queue (list)
|
|
* only when it can be queued again so that the return value can
|
|
* be used for reference counting.
|
|
*/
|
|
kthread_cancel_delayed_work_timer(work, &flags);
|
|
if (work->canceling) {
|
|
/* The number of works in the queue does not change. */
|
|
ret = true;
|
|
goto out;
|
|
}
|
|
ret = __kthread_cancel_work(work);
|
|
|
|
fast_queue:
|
|
__kthread_queue_delayed_work(worker, dwork, delay, &wake_q);
|
|
out:
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
|
|
wake_up_q(&wake_q);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_mod_delayed_work);
|
|
|
|
static bool __kthread_cancel_work_sync(struct kthread_work *work, bool is_dwork)
|
|
{
|
|
struct kthread_worker *worker = work->worker;
|
|
unsigned long flags;
|
|
int ret = false;
|
|
|
|
if (!worker)
|
|
goto out;
|
|
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
/* Work must not be used with >1 worker, see kthread_queue_work(). */
|
|
WARN_ON_ONCE(work->worker != worker);
|
|
|
|
if (is_dwork)
|
|
kthread_cancel_delayed_work_timer(work, &flags);
|
|
|
|
ret = __kthread_cancel_work(work);
|
|
|
|
if (worker->current_work != work)
|
|
goto out_fast;
|
|
|
|
/*
|
|
* The work is in progress and we need to wait with the lock released.
|
|
* In the meantime, block any queuing by setting the canceling counter.
|
|
*/
|
|
work->canceling++;
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
kthread_flush_work(work);
|
|
raw_spin_lock_irqsave(&worker->lock, flags);
|
|
work->canceling--;
|
|
|
|
out_fast:
|
|
raw_spin_unlock_irqrestore(&worker->lock, flags);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* kthread_cancel_work_sync - cancel a kthread work and wait for it to finish
|
|
* @work: the kthread work to cancel
|
|
*
|
|
* Cancel @work and wait for its execution to finish. This function
|
|
* can be used even if the work re-queues itself. On return from this
|
|
* function, @work is guaranteed to be not pending or executing on any CPU.
|
|
*
|
|
* kthread_cancel_work_sync(&delayed_work->work) must not be used for
|
|
* delayed_work's. Use kthread_cancel_delayed_work_sync() instead.
|
|
*
|
|
* The caller must ensure that the worker on which @work was last
|
|
* queued can't be destroyed before this function returns.
|
|
*
|
|
* Return: %true if @work was pending, %false otherwise.
|
|
*/
|
|
bool kthread_cancel_work_sync(struct kthread_work *work)
|
|
{
|
|
return __kthread_cancel_work_sync(work, false);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_cancel_work_sync);
|
|
|
|
/**
|
|
* kthread_cancel_delayed_work_sync - cancel a kthread delayed work and
|
|
* wait for it to finish.
|
|
* @dwork: the kthread delayed work to cancel
|
|
*
|
|
* This is kthread_cancel_work_sync() for delayed works.
|
|
*
|
|
* Return: %true if @dwork was pending, %false otherwise.
|
|
*/
|
|
bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *dwork)
|
|
{
|
|
return __kthread_cancel_work_sync(&dwork->work, true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_cancel_delayed_work_sync);
|
|
|
|
/**
|
|
* kthread_flush_worker - flush all current works on a kthread_worker
|
|
* @worker: worker to flush
|
|
*
|
|
* Wait until all currently executing or pending works on @worker are
|
|
* finished.
|
|
*/
|
|
void kthread_flush_worker(struct kthread_worker *worker)
|
|
{
|
|
struct kthread_flush_work fwork = {
|
|
KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn),
|
|
COMPLETION_INITIALIZER_ONSTACK(fwork.done),
|
|
};
|
|
|
|
kthread_queue_work(worker, &fwork.work);
|
|
wait_for_completion(&fwork.done);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kthread_flush_worker);
|
|
|
|
/**
|
|
* kthread_destroy_worker - destroy a kthread worker
|
|
* @worker: worker to be destroyed
|
|
*
|
|
* Flush and destroy @worker. The simple flush is enough because the kthread
|
|
* worker API is used only in trivial scenarios. There are no multi-step state
|
|
* machines needed.
|
|
*/
|
|
void kthread_destroy_worker(struct kthread_worker *worker)
|
|
{
|
|
struct task_struct *task;
|
|
|
|
task = worker->task;
|
|
if (WARN_ON(!task))
|
|
return;
|
|
|
|
kthread_flush_worker(worker);
|
|
kthread_stop(task);
|
|
WARN_ON(!list_empty(&worker->work_list));
|
|
kfree(worker);
|
|
}
|
|
EXPORT_SYMBOL(kthread_destroy_worker);
|
|
|
|
#ifdef CONFIG_BLK_CGROUP
|
|
/**
|
|
* kthread_associate_blkcg - associate blkcg to current kthread
|
|
* @css: the cgroup info
|
|
*
|
|
* Current thread must be a kthread. The thread is running jobs on behalf of
|
|
* other threads. In some cases, we expect the jobs attach cgroup info of
|
|
* original threads instead of that of current thread. This function stores
|
|
* original thread's cgroup info in current kthread context for later
|
|
* retrieval.
|
|
*/
|
|
void kthread_associate_blkcg(struct cgroup_subsys_state *css)
|
|
{
|
|
struct kthread *kthread = __to_kthread(current);
|
|
|
|
|
|
if (!kthread)
|
|
return;
|
|
|
|
if (kthread->blkcg_css) {
|
|
css_put(kthread->blkcg_css);
|
|
kthread->blkcg_css = NULL;
|
|
}
|
|
if (css) {
|
|
css_get(css);
|
|
kthread->blkcg_css = css;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(kthread_associate_blkcg);
|
|
|
|
/**
|
|
* kthread_blkcg - get associated blkcg css of current kthread
|
|
*
|
|
* Current thread must be a kthread.
|
|
*/
|
|
struct cgroup_subsys_state *kthread_blkcg(void)
|
|
{
|
|
struct kthread *kthread = __to_kthread(current);
|
|
|
|
if (kthread)
|
|
return kthread->blkcg_css;
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(kthread_blkcg);
|
|
#endif
|