mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-05 19:31:57 -04:00
* refs/heads/tmp-dc8c919:
Revert dwc3 changes
ANDROID: GKI: Update FCNT KMI symbol list No new symbols added that are not already in the .xml file.
ANDROID: GKI : Update symbols to symbol list
BACKPORT: crypto: arch - conditionalize crypto api in arch glue for lib code
BACKPORT: crypto: arch/lib - limit simd usage to 4k chunks
UPSTREAM: crypto: arm/blake2s - fix for big endian
ANDROID: gki_defconfig: enable BLAKE2b support
BACKPORT: crypto: arm/blake2b - add NEON-accelerated BLAKE2b
BACKPORT: crypto: blake2b - update file comment
BACKPORT: crypto: blake2b - sync with blake2s implementation
UPSTREAM: crypto: arm/blake2s - add ARM scalar optimized BLAKE2s
UPSTREAM: crypto: blake2s - include <linux/bug.h> instead of <asm/bug.h>
UPSTREAM: crypto: blake2s - adjust include guard naming
UPSTREAM: crypto: blake2s - add comment for blake2s_state fields
UPSTREAM: crypto: blake2s - optimize blake2s initialization
BACKPORT: crypto: blake2s - share the "shash" API boilerplate code
UPSTREAM: crypto: blake2s - move update and final logic to internal/blake2s.h
UPSTREAM: crypto: blake2s - remove unneeded includes
UPSTREAM: crypto: x86/blake2s - define shash_alg structs using macros
UPSTREAM: crypto: blake2s - define shash_alg structs using macros
UPSTREAM: crypto: lib/blake2s - Move selftest prototype into header file
UPSTREAM: crypto: blake2b - Fix clang optimization for ARMv7-M
UPSTREAM: crypto: blake2b - rename tfm context and _setkey callback
UPSTREAM: crypto: blake2b - merge _update to api callback
UPSTREAM: crypto: blake2b - open code set last block helper
UPSTREAM: crypto: blake2b - delete unused structs or members
UPSTREAM: crypto: blake2b - simplify key init
UPSTREAM: crypto: blake2b - merge blake2 init to api callback
UPSTREAM: crypto: blake2b - merge _final implementation to callback
BACKPORT: crypto: testmgr - add test vectors for blake2b
BACKPORT: crypto: blake2b - add blake2b generic implementation
UPSTREAM: crypto: blake2s - x86_64 SIMD implementation
UPSTREAM: crypto: blake2s - implement generic shash driver
UPSTREAM: crypto: testmgr - add test cases for Blake2s
UPSTREAM: crypto: blake2s - generic C library implementation and selftest
UPSTREAM: crypto: lib - tidy up lib/crypto Kconfig and Makefile
ANDROID: ion heap: init ion heaps in subsys_initcall
UPSTREAM: ovl: simplify file splice
ANDROID: ABI: update allowed list for galaxy
ANDROID: ABI: Update allowed list for QCOM
ANDROID: distribute Module.symvers
UPSTREAM: usb: max-3421: Prevent corruption of freed memory
ANDROID: ABI: Update allowed list for QCOM
UPSTREAM: driver core: Prevent warning when removing a device link from unregistered consumer
UPSTREAM: udp: properly flush normal packet at GRO time
UPSTREAM: net/xfrm/compat: Copy xfrm_spdattr_type_t atributes
UPSTREAM: f2fs: Advertise encrypted casefolding in sysfs
UPSTREAM: loop: Fix missing discard support when using LOOP_CONFIGURE
UPSTREAM: thermal/drivers/sprd: Add missing MODULE_DEVICE_TABLE
UPSTREAM: nvmem: sprd: Fix an error message
UPSTREAM: usb: musb: Fix an error message
UPSTREAM: scsi: ufs: core: Cancel rpm_dev_flush_recheck_work during system suspend
UPSTREAM: scsi: ufs: core: Do not put UFS power into LPM if link is broken
UPSTREAM: selinux: add proper NULL termination to the secclass_map permissions
UPSTREAM: of: property: fw_devlink: do not link ".*,nr-gpios"
UPSTREAM: udp: never accept GSO_FRAGLIST packets
UPSTREAM: udp: skip L4 aggregation for UDP tunnel packets
UPSTREAM: xfrm/compat: Cleanup WARN()s that can be user-triggered
UPSTREAM: pinctrl: sunxi: fix irq bank map for the Allwinner A100 pin controller
UPSTREAM: loop: Set correct device size when using LOOP_CONFIGURE
UPSTREAM: loop: unset GENHD_FL_NO_PART_SCAN on LOOP_CONFIGURE
ANDROID: ion_system_heap: Add __GFP_NOWARN to mid-order allocations
ANDROID: drivers: gpu: drm: increase the MAX_DRM_OPEN_COUNT
UPSTREAM: af_unix: fix garbage collect vs MSG_PEEK
Linux 5.4.147
Revert "time: Handle negative seconds correctly in timespec64_to_ns()"
Revert "posix-cpu-timers: Force next expiration recalc after itimer reset"
Revert "block: nbd: add sanity check for first_minor"
Revert "Bluetooth: Move shutdown callback before flushing tx and rx queue"
Linux 5.4.146
clk: kirkwood: Fix a clocking boot regression
backlight: pwm_bl: Improve bootloader/kernel device handover
fbmem: don't allow too huge resolutions
IMA: remove the dependency on CRYPTO_MD5
IMA: remove -Wmissing-prototypes warning
fuse: flush extending writes
fuse: truncate pagecache on atomic_o_trunc
KVM: nVMX: Unconditionally clear nested.pi_pending on nested VM-Enter
KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted
KVM: s390: index kvm->arch.idle_mask by vcpu_idx
x86/resctrl: Fix a maybe-uninitialized build warning treated as error
perf/x86/amd/ibs: Extend PERF_PMU_CAP_NO_EXCLUDE to IBS Op
tty: Fix data race between tiocsti() and flush_to_ldisc()
time: Handle negative seconds correctly in timespec64_to_ns()
bpf: Fix pointer arithmetic mask tightening under state pruning
bpf: verifier: Allocate idmap scratch in verifier env
bpf: Fix leakage due to insufficient speculative store bypass mitigation
bpf: Introduce BPF nospec instruction for mitigating Spectre v4
ipv4: fix endianness issue in inet_rtm_getroute_build_skb()
octeontx2-af: Fix loop in free and unmap counter
net: qualcomm: fix QCA7000 checksum handling
net: sched: Fix qdisc_rate_table refcount leak when get tcf_block failed
ipv4: make exception cache less predictible
ipv6: make exception cache less predictible
brcmfmac: pcie: fix oops on failure to resume and reprobe
bcma: Fix memory leak for internally-handled cores
ath6kl: wmi: fix an error code in ath6kl_wmi_sync_point()
ASoC: wcd9335: Disable irq on slave ports in the remove function
ASoC: wcd9335: Fix a memory leak in the error handling path of the probe function
ASoC: wcd9335: Fix a double irq free in the remove function
tty: serial: fsl_lpuart: fix the wrong mapbase value
usb: bdc: Fix an error handling path in 'bdc_probe()' when no suitable DMA config is available
usb: ehci-orion: Handle errors of clk_prepare_enable() in probe
i2c: mt65xx: fix IRQ check
CIFS: Fix a potencially linear read overflow
bpf: Fix possible out of bound write in narrow load handling
mmc: moxart: Fix issue with uninitialized dma_slave_config
mmc: dw_mmc: Fix issue with uninitialized dma_slave_config
ASoC: Intel: Skylake: Fix module resource and format selection
ASoC: Intel: Skylake: Leave data as is when invoking TLV IPCs
rsi: fix an error code in rsi_probe()
rsi: fix error code in rsi_load_9116_firmware()
i2c: s3c2410: fix IRQ check
i2c: iop3xx: fix deferred probing
Bluetooth: add timeout sanity check to hci_inquiry
mm/swap: consider max pages in iomap_swapfile_add_extent
usb: gadget: mv_u3d: request_irq() after initializing UDC
nfsd4: Fix forced-expiry locking
lockd: Fix invalid lockowner cast after vfs_test_lock
mac80211: Fix insufficient headroom issue for AMSDU
usb: phy: tahvo: add IRQ check
usb: host: ohci-tmio: add IRQ check
Bluetooth: Move shutdown callback before flushing tx and rx queue
usb: gadget: udc: renesas_usb3: Fix soc_device_match() abuse
usb: phy: twl6030: add IRQ checks
usb: phy: fsl-usb: add IRQ check
usb: gadget: udc: at91: add IRQ check
drm/msm/dsi: Fix some reference counted resource leaks
Bluetooth: fix repeated calls to sco_sock_kill
counter: 104-quad-8: Return error when invalid mode during ceiling_write
arm64: dts: exynos: correct GIC CPU interfaces address range on Exynos7
drm/msm/dpu: make dpu_hw_ctl_clear_all_blendstages clear necessary LMs
PM: EM: Increase energy calculation precision
Bluetooth: increase BTNAMSIZ to 21 chars to fix potential buffer overflow
debugfs: Return error during {full/open}_proxy_open() on rmmod
soc: qcom: smsm: Fix missed interrupts if state changes while masked
PCI: PM: Enable PME if it can be signaled from D3cold
PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently
media: venus: venc: Fix potential null pointer dereference on pointer fmt
media: em28xx-input: fix refcount bug in em28xx_usb_disconnect
leds: trigger: audio: Add an activate callback to ensure the initial brightness is set
leds: lt3593: Put fwnode in any case during ->probe()
i2c: highlander: add IRQ check
net: cipso: fix warnings in netlbl_cipsov4_add_std
cgroup/cpuset: Fix a partition bug with hotplug
net/mlx5e: Prohibit inner indir TIRs in IPoIB
ARM: dts: meson8b: ec100: Fix the pwm regulator supply properties
ARM: dts: meson8b: mxq: Fix the pwm regulator supply properties
ARM: dts: meson8b: odroidc1: Fix the pwm regulator supply properties
ARM: dts: meson8: Use a higher default GPU clock frequency
tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos
drm/amdgpu/acp: Make PM domain really work
netns: protect netns ID lookups with RCU
6lowpan: iphc: Fix an off-by-one check of array index
Bluetooth: sco: prevent information leak in sco_conn_defer_accept()
media: coda: fix frame_mem_ctrl for YUV420 and YVU420 formats
media: go7007: remove redundant initialization
media: dvb-usb: Fix error handling in dvb_usb_i2c_init
media: dvb-usb: fix uninit-value in vp702x_read_mac_addr
media: dvb-usb: fix uninit-value in dvb_usb_adapter_dvb_init
soc: qcom: rpmhpd: Use corner in power_off
arm64: dts: renesas: r8a77995: draak: Remove bogus adv7511w properties
ARM: dts: aspeed-g6: Fix HVI3C function-group in pinctrl dtsi
bpf: Fix potential memleak and UAF in the verifier.
bpf: Fix a typo of reuseport map in bpf.h.
media: cxd2880-spi: Fix an error handling path
soc: rockchip: ROCKCHIP_GRF should not default to y, unconditionally
media: TDA1997x: enable EDID support
drm/panfrost: Fix missing clk_disable_unprepare() on error in panfrost_clk_init()
EDAC/i10nm: Fix NVDIMM detection
spi: spi-zynq-qspi: use wait_for_completion_timeout to make zynq_qspi_exec_mem_op not interruptible
spi: sprd: Fix the wrong WDG_LOAD_VAL
regulator: vctrl: Avoid lockdep warning in enable/disable ops
regulator: vctrl: Use locked regulator_get_voltage in probe path
certs: Trigger creation of RSA module signing key if it's not an RSA key
crypto: qat - use proper type for vf_mask
block: nbd: add sanity check for first_minor
clocksource/drivers/sh_cmt: Fix wrong setting if don't request IRQ for clock source channel
lib/mpi: use kcalloc in mpi_resize
genirq/timings: Fix error return code in irq_timings_test_irqs()
spi: spi-pic32: Fix issue with uninitialized dma_slave_config
spi: spi-fsl-dspi: Fix issue with uninitialized dma_slave_config
sched: Fix UCLAMP_FLAG_IDLE setting
m68k: emu: Fix invalid free in nfeth_cleanup()
s390/debug: fix debug area life cycle
s390/kasan: fix large PMD pages address alignment check
udf_get_extendedattr() had no boundary checks.
fcntl: fix potential deadlock for &fasync_struct.fa_lock
crypto: qat - do not export adf_iov_putmsg()
crypto: qat - fix naming for init/shutdown VF to PF notifications
crypto: qat - fix reuse of completion variable
crypto: qat - handle both source of interrupt in VF ISR
crypto: qat - do not ignore errors from enable_vf2pf_comms()
libata: fix ata_host_start()
s390/cio: add dev_busid sysfs entry for each subchannel
power: supply: max17042_battery: fix typo in MAx17042_TOFF
nvmet: pass back cntlid on successful completion
nvme-rdma: don't update queue count when failing to set io queues
nvme-tcp: don't update queue count when failing to set io queues
bcache: add proper error unwinding in bcache_device_init
isofs: joliet: Fix iocharset=utf8 mount option
udf: Fix iocharset=utf8 mount option
udf: Check LVID earlier
hrtimer: Ensure timerfd notification for HIGHRES=n
hrtimer: Avoid double reprogramming in __hrtimer_start_range_ns()
posix-cpu-timers: Force next expiration recalc after itimer reset
rcu/tree: Handle VM stoppage in stall detection
sched/deadline: Fix missing clock update in migrate_task_rq_dl()
crypto: omap-sham - clear dma flags only after omap_sham_update_dma_stop()
power: supply: axp288_fuel_gauge: Report register-address on readb / writeb errors
sched/deadline: Fix reset_on_fork reporting of DL tasks
crypto: mxs-dcp - Check for DMA mapping errors
regmap: fix the offset of register error log
locking/mutex: Fix HANDOFF condition
ANDROID: GKI: db845c: Update symbols list and ABI for lts v5.4.144
Linux 5.4.145
PCI: Call Max Payload Size-related fixup quirks early
x86/reboot: Limit Dell Optiplex 990 quirk to early BIOS versions
xhci: fix unsafe memory usage in xhci tracing
usb: mtu3: fix the wrong HS mult value
usb: mtu3: use @mult for HS isoc or intr
usb: host: xhci-rcar: Don't reload firmware after the completion
ALSA: usb-audio: Add registration quirk for JBL Quantum 800
Revert "btrfs: compression: don't try to compress if we don't have enough pages"
x86/events/amd/iommu: Fix invalid Perf result due to IOMMU PMC power-gating
Revert "r8169: avoid link-up interrupt issue on RTL8106e if user enables ASPM"
mm/page_alloc: speed up the iteration of max_order
net: ll_temac: Remove left-over debug message
powerpc/boot: Delete unneeded .globl _zimage_start
ipv4/icmp: l3mdev: Perform icmp error route lookup on source device routing table (v2)
USB: serial: mos7720: improve OOM-handling in read_mos_reg()
igmp: Add ip_mc_list lock in ip_check_mc_rcu
media: stkwebcam: fix memory leak in stk_camera_probe
ARC: wireup clone3 syscall
ALSA: pcm: fix divide error in snd_pcm_lib_ioctl
ALSA: hda/realtek: Workaround for conflicting SSID on ASUS ROG Strix G17
ARM: 8918/2: only build return_address() if needed
cryptoloop: add a deprecation warning
perf/x86/amd/power: Assign pmu.module
perf/x86/amd/ibs: Work around erratum #1197
perf/x86/intel/pt: Fix mask of num_address_ranges
qede: Fix memset corruption
net: macb: Add a NULL check on desc_ptp
qed: Fix the VF msix vectors flow
reset: reset-zynqmp: Fixed the argument data type
gpu: ipu-v3: Fix i.MX IPU-v3 offset calculations for (semi)planar U/V formats
xtensa: fix kconfig unmet dependency warning for HAVE_FUTEX_CMPXCHG
kthread: Fix PF_KTHREAD vs to_kthread() race
ubifs: report correct st_size for encrypted symlinks
f2fs: report correct st_size for encrypted symlinks
ext4: report correct st_size for encrypted symlinks
fscrypt: add fscrypt_symlink_getattr() for computing st_size
ext4: fix race writing to an inline_data file while its xattrs are changing
Revert "once: Fix panic when module unload"
Linux 5.4.144
audit: move put_tree() to avoid trim_trees refcount underflow and UAF
net: don't unconditionally copy_from_user a struct ifreq for socket ioctls
Revert "parisc: Add assembly implementations for memset, strlen, strcpy, strncpy and strcat"
Revert "floppy: reintroduce O_NDELAY fix"
btrfs: fix NULL pointer dereference when deleting device by invalid id
arm64: dts: qcom: msm8994-angler: Fix gpio-reserved-ranges 85-88
KVM: x86/mmu: Treat NX as used (not reserved) for all !TDP shadow MMUs
net: dsa: mt7530: fix VLAN traffic leaks again
bpf: Fix cast to pointer from integer of different size warning
bpf: Track contents of read-only maps as scalars
vt_kdsetmode: extend console locking
btrfs: fix race between marking inode needs to be logged and log syncing
net/rds: dma_map_sg is entitled to merge entries
drm/nouveau/disp: power down unused DP links during init
drm: Copy drm_wait_vblank to user before returning
qed: Fix null-pointer dereference in qed_rdma_create_qp()
qed: qed ll2 race condition fixes
vringh: Use wiov->used to check for read/write desc order
virtio_pci: Support surprise removal of virtio pci device
virtio: Improve vq->broken access to avoid any compiler optimization
opp: remove WARN when no valid OPPs remain
perf/x86/intel/uncore: Fix integer overflow on 23 bit left shift of a u32
usb: gadget: u_audio: fix race condition on endpoint stop
drm/i915: Fix syncmap memory leak
net: hns3: fix get wrong pfc_en when query PFC configuration
net: hns3: fix duplicate node in VLAN list
net: hns3: clear hardware resource when loading driver
rtnetlink: Return correct error on changing device netns
net: marvell: fix MVNETA_TX_IN_PRGRS bit number
xgene-v2: Fix a resource leak in the error handling path of 'xge_probe()'
ip_gre: add validation for csum_start
RDMA/efa: Free IRQ vectors on error flow
e1000e: Fix the max snoop/no-snoop latency for 10M
IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs()
RDMA/bnxt_re: Add missing spin lock initialization
scsi: core: Fix hang of freezing queue between blocking and running device
usb: dwc3: gadget: Stop EP0 transfers during pullup disable
usb: dwc3: gadget: Fix dwc3_calc_trbs_left()
USB: serial: option: add new VID/PID to support Fibocom FG150
Revert "USB: serial: ch341: fix character loss at high transfer rates"
can: usb: esd_usb2: esd_usb2_rx_event(): fix the interchange of the CAN RX and TX error counters
mm, oom: make the calculation of oom badness more accurate
mmc: sdhci-msm: Update the software timeout value for sdhc
ovl: fix uninitialized pointer read in ovl_lookup_real_one()
once: Fix panic when module unload
netfilter: conntrack: collect all entries in one cycle
ARC: Fix CONFIG_STACKDEPOT
net: qrtr: fix another OOB Read in qrtr_endpoint_post
Revert "virtio: Protect vqs list access"
Revert "net: igmp: fix data-race in igmp_ifc_timer_expire()"
Revert "net: igmp: increase size of mr_ifc_count"
Revert "PCI/MSI: Protect msi_desc::masked for multi-MSI"
Linux 5.4.143
netfilter: nft_exthdr: fix endianness of tcp option cast
fs: warn about impending deprecation of mandatory locks
mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim
mm, memcg: avoid stale protection values when cgroup is above protection
ASoC: intel: atom: Fix breakage for PCM buffer address setup
PCI: Increase D3 delay for AMD Renoir/Cezanne XHCI
btrfs: prevent rename2 from exchanging a subvol with a directory from different parents
ipack: tpci200: fix memory leak in the tpci200_register
ipack: tpci200: fix many double free issues in tpci200_pci_probe
slimbus: ngd: reset dma setup during runtime pm
slimbus: messaging: check for valid transaction id
slimbus: messaging: start transaction ids from 1 instead of zero
tracing / histogram: Fix NULL pointer dereference on strcmp() on NULL event name
ALSA: hda - fix the 'Capture Switch' value change notifications
mmc: dw_mmc: Fix hang on data CRC error
ovl: add splice file read write helper
iavf: Fix ping is lost after untrusted VF had tried to change MAC
i40e: Fix ATR queue selection
ovs: clear skb->tstamp in forwarding path
net: mdio-mux: Handle -EPROBE_DEFER correctly
net: mdio-mux: Don't ignore memory allocation errors
net: qlcnic: add missed unlock in qlcnic_83xx_flash_read32
virtio-net: use NETIF_F_GRO_HW instead of NETIF_F_LRO
virtio-net: support XDP when not more queues
vrf: Reset skb conntrack connection on VRF rcv
bnxt_en: Add missing DMA memory barriers
ptp_pch: Restore dependency on PCI
net: 6pack: fix slab-out-of-bounds in decode_data
bnxt: disable napi before canceling DIM
bnxt: don't lock the tx queue from napi poll
bpf: Clear zext_dst of dead insns
vhost: Fix the calculation in vhost_overflow()
virtio: Protect vqs list access
dccp: add do-while-0 stubs for dccp_pr_debug macros
cpufreq: armada-37xx: forbid cpufreq for 1.2 GHz variant
iommu: Check if group is NULL before remove device
Bluetooth: hidp: use correct wait queue when removing ctrl_wait
drm/amd/display: Fix Dynamic bpp issue with 8K30 with Navi 1X
net: usb: lan78xx: don't modify phy_device state concurrently
ARM: dts: nomadik: Fix up interrupt controller node names
scsi: core: Fix capacity set to zero after offlinining device
scsi: core: Avoid printing an error if target_alloc() returns -ENXIO
scsi: scsi_dh_rdac: Avoid crash during rdac_bus_attach()
scsi: megaraid_mm: Fix end of loop tests for list_for_each_entry()
dmaengine: of-dma: router_xlate to return -EPROBE_DEFER if controller is not yet available
ARM: dts: am43x-epos-evm: Reduce i2c0 bus speed for tps65218
dmaengine: usb-dmac: Fix PM reference leak in usb_dmac_probe()
dmaengine: xilinx_dma: Fix read-after-free bug when terminating transfers
USB: core: Avoid WARNings for 0-length descriptor requests
media: drivers/media/usb: fix memory leak in zr364xx_probe
media: zr364xx: fix memory leaks in probe()
media: zr364xx: propagate errors from zr364xx_start_readpipe()
mtd: cfi_cmdset_0002: fix crash when erasing/writing AMD cards
ath9k: Postpone key cache entry deletion for TXQ frames reference it
ath: Modify ath_key_delete() to not need full key entry
ath: Export ath_hw_keysetmac()
ath9k: Clear key cache explicitly on disabling hardware
ath: Use safer key clearing with key cache entries
x86/fpu: Make init_fpstate correct with optimized XSAVE
ext4: fix EXT4_MAX_LOGICAL_BLOCK macro
Linux 5.4.142
KVM: nSVM: always intercept VMLOAD/VMSAVE when nested (CVE-2021-3656)
KVM: nSVM: avoid picking up unsupported bits from L2 in int_ctl (CVE-2021-3653)
iommu/vt-d: Fix agaw for a supported 48 bit guest address width
vmlinux.lds.h: Handle clang's module.{c,d}tor sections
ceph: take snap_empty_lock atomically with snaprealm refcount change
ceph: clean up locking annotation for ceph_get_snap_realm and __lookup_snap_realm
ceph: add some lockdep assertions around snaprealm handling
KVM: VMX: Use current VMCS to query WAITPKG support for MSR emulation
PCI/MSI: Protect msi_desc::masked for multi-MSI
PCI/MSI: Use msi_mask_irq() in pci_msi_shutdown()
PCI/MSI: Correct misleading comments
PCI/MSI: Do not set invalid bits in MSI mask
PCI/MSI: Enforce MSI[X] entry updates to be visible
PCI/MSI: Enforce that MSI-X table entry is masked for update
PCI/MSI: Mask all unused MSI-X entries
PCI/MSI: Enable and mask MSI-X early
genirq/timings: Prevent potential array overflow in __irq_timings_store()
genirq/msi: Ensure deactivation on teardown
x86/resctrl: Fix default monitoring groups reporting
x86/ioapic: Force affinity setup before startup
x86/msi: Force affinity setup before startup
genirq: Provide IRQCHIP_AFFINITY_PRE_STARTUP
x86/tools: Fix objdump version check again
powerpc/kprobes: Fix kprobe Oops happens in booke
nbd: Aovid double completion of a request
vsock/virtio: avoid potential deadlock when vsock device remove
xen/events: Fix race in set_evtchn_to_irq
net: igmp: increase size of mr_ifc_count
tcp_bbr: fix u32 wrap bug in round logic if bbr_init() called after 2B packets
net: linkwatch: fix failure to restore device state across suspend/resume
net: bridge: fix memleak in br_add_if()
net: dsa: sja1105: fix broken backpressure in .port_fdb_dump
net: dsa: lantiq: fix broken backpressure in .port_fdb_dump
net: dsa: lan9303: fix broken backpressure in .port_fdb_dump
net: igmp: fix data-race in igmp_ifc_timer_expire()
net: Fix memory leak in ieee802154_raw_deliver
net: dsa: microchip: Fix ksz_read64()
drm/meson: fix colour distortion from HDR set during vendor u-boot
net/mlx5: Fix return value from tracer initialization
psample: Add a fwd declaration for skbuff
iavf: Set RSS LUT and key in reset handle path
net: sched: act_mirred: Reset ct info when mirror/redirect skb
ppp: Fix generating ifname when empty IFLA_IFNAME is specified
net: phy: micrel: Fix link detection on ksz87xx switch"
platform/x86: pcengines-apuv2: Add missing terminating entries to gpio-lookup tables
platform/x86: pcengines-apuv2: revert wiring up simswitch GPIO as LED
net: dsa: mt7530: add the missing RxUnicast MIB counter
ASoC: cs42l42: Fix LRCLK frame start edge
netfilter: nf_conntrack_bridge: Fix memory leak when error
ASoC: cs42l42: Remove duplicate control for WNF filter frequency
ASoC: cs42l42: Fix inversion of ADC Notch Switch control
ASoC: cs42l42: Don't allow SND_SOC_DAIFMT_LEFT_J
ASoC: cs42l42: Correct definition of ADC Volume control
ieee802154: hwsim: fix GPF in hwsim_new_edge_nl
ieee802154: hwsim: fix GPF in hwsim_set_edge_lqi
libnvdimm/region: Fix label activation vs errors
ACPI: NFIT: Fix support for virtual SPA ranges
ceph: reduce contention in ceph_check_delayed_caps()
i2c: dev: zero out array used for i2c reads from userspace
ASoC: intel: atom: Fix reference to PCM buffer address
ASoC: xilinx: Fix reference to PCM buffer address
iio: adc: Fix incorrect exit of for-loop
iio: humidity: hdc100x: Add margin to the conversion time
iio: adc: ti-ads7950: Ensure CS is deasserted after reading channels
Linux 5.4.141
btrfs: don't flush from btrfs_delayed_inode_reserve_metadata
btrfs: export and rename qgroup_reserve_meta
btrfs: qgroup: don't commit transaction when we already hold the handle
net: xilinx_emaclite: Do not print real IOMEM pointer
btrfs: fix lockdep splat when enabling and disabling qgroups
btrfs: qgroup: remove ASYNC_COMMIT mechanism in favor of reserve retry-after-EDQUOT
btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED
btrfs: qgroup: try to flush qgroup space when we get -EDQUOT
btrfs: qgroup: allow to unreserve range without releasing other ranges
btrfs: make btrfs_qgroup_reserve_data take btrfs_inode
btrfs: make qgroup_free_reserved_data take btrfs_inode
ovl: prevent private clone if bind mount is not allowed
ppp: Fix generating ppp unit id when ifname is not specified
ALSA: hda: Add quirk for ASUS Flow x13
USB:ehci:fix Kunpeng920 ehci hardware problem
KVM: X86: MMU: Use the correct inherited permissions to get shadow page
usb: dwc3: gadget: Avoid runtime resume if disabling pullup
usb: dwc3: gadget: Disable gadget IRQ during pullup disable
usb: dwc3: gadget: Clear DEP flags after stop transfers in ep disable
usb: dwc3: gadget: Prevent EP queuing while stopping transfers
usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup
usb: dwc3: gadget: Allow runtime suspend if UDC unbinded
usb: dwc3: Stop active transfers before halting the controller
tracing: Reject string operand in the histogram expression
media: v4l2-mem2mem: always consider OUTPUT queue during poll
tee: Correct inappropriate usage of TEE_SHM_DMA_BUF flag
KVM: SVM: Fix off-by-one indexing when nullifying last used SEV VMCB
Linux 5.4.140
arm64: fix compat syscall return truncation
net/qla3xxx: fix schedule while atomic in ql_wait_for_drvr_lock and ql_adapter_reset
alpha: Send stop IPI to send to online CPUs
virt_wifi: fix error on connect
reiserfs: check directory items on read from disk
reiserfs: add check for root_inode in reiserfs_fill_super
libata: fix ata_pio_sector for CONFIG_HIGHMEM
bpf, selftests: Adjust few selftest result_unpriv outcomes
perf/x86/amd: Don't touch the AMD64_EVENTSEL_HOSTONLY bit inside the guest
soc: ixp4xx/qmgr: fix invalid __iomem access
spi: meson-spicc: fix memory leak in meson_spicc_remove
soc: ixp4xx: fix printing resources
arm64: vdso: Avoid ISB after reading from cntvct_el0
KVM: x86/mmu: Fix per-cpu counter corruption on 32-bit builds
KVM: Do not leak memory for duplicate debugfs directories
KVM: x86: accept userspace interrupt only if no event is injected
md/raid10: properly indicate failure when ending a failed write request
pcmcia: i82092: fix a null pointer dereference bug
timers: Move clearing of base::timer_running under base:: Lock
serial: 8250_pci: Avoid irq sharing for MSI(-X) interrupts.
serial: 8250_pci: Enumerate Elkhart Lake UARTs via dedicated driver
MIPS: Malta: Do not byte-swap accesses to the CBUS UART
serial: 8250: Mask out floating 16/32-bit bus bits
serial: 8250_mtk: fix uart corruption issue when rx power off
serial: tegra: Only print FIFO error message when an error occurs
ext4: fix potential htree corruption when growing large_dir directories
pipe: increase minimum default pipe size to 2 pages
media: rtl28xxu: fix zero-length control request
staging: rtl8712: get rid of flush_scheduled_work
staging: rtl8723bs: Fix a resource leak in sd_int_dpc
tpm_ftpm_tee: Free and unregister TEE shared memory during kexec
optee: Fix memory leak when failing to register shm pages
tee: add tee_shm_alloc_kernel_buf()
optee: Clear stale cache entries during initialization
tracing / histogram: Give calculation hist_fields a size
scripts/tracing: fix the bug that can't parse raw_trace_func
clk: fix leak on devm_clk_bulk_get_all() unwind
usb: otg-fsm: Fix hrtimer list corruption
usb: gadget: f_hid: idle uses the highest byte for duration
usb: gadget: f_hid: fixed NULL pointer dereference
usb: gadget: f_hid: added GET_IDLE and SET_IDLE handlers
usb: cdns3: Fixed incorrect gadget state
ALSA: usb-audio: Add registration quirk for JBL Quantum 600
ALSA: hda/realtek: add mic quirk for Acer SF314-42
firmware_loader: fix use-after-free in firmware_fallback_sysfs
firmware_loader: use -ETIMEDOUT instead of -EAGAIN in fw_load_sysfs_fallback
USB: serial: ftdi_sio: add device ID for Auto-M3 OP-COM v2
USB: serial: ch341: fix character loss at high transfer rates
USB: serial: option: add Telit FD980 composition 0x1056
USB: usbtmc: Fix RCU stall warning
Bluetooth: defer cleanup of resources in hci_unregister_dev()
blk-iolatency: error out if blk_get_queue() failed in iolatency_set_limit()
net: vxge: fix use-after-free in vxge_device_unregister
net: fec: fix use-after-free in fec_drv_remove
net: pegasus: fix uninit-value in get_interrupt_interval
bnx2x: fix an error code in bnx2x_nic_load()
mips: Fix non-POSIX regexp
net: ipv6: fix returned variable type in ip6_skb_dst_mtu
nfp: update ethtool reporting of pauseframe control
sctp: move the active_key update after sh_keys is added
gpio: tqmx86: really make IRQ optional
net: natsemi: Fix missing pci_disable_device() in probe and remove
net: phy: micrel: Fix detection of ksz87xx switch
net: dsa: sja1105: invalidate dynamic FDB entries learned concurrently with statically added ones
net: dsa: sja1105: overwrite dynamic FDB entries with static ones in .port_fdb_add
net, gro: Set inner transport header offset in tcp/udp GRO hook
dmaengine: imx-dma: configure the generic DMA type to make it work
media: videobuf2-core: dequeue if start_streaming fails
scsi: sr: Return correct event when media event code is 3
spi: imx: mx51-ecspi: Fix low-speed CONFIGREG delay calculation
spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay
omap5-board-common: remove not physically existing vdds_1v8_main fixed-regulator
ARM: dts: am437x-l4: fix typo in can@0 node
clk: stm32f4: fix post divisor setup for I2S/SAI PLLs
ALSA: usb-audio: fix incorrect clock source setting
arm64: dts: armada-3720-turris-mox: remove mrvl,i2c-fast-mode
ARM: dts: imx: Swap M53Menlo pinctrl_power_button/pinctrl_power_out pins
ARM: imx: fix missing 3rd argument in macro imx_mmdc_perf_init
ARM: dts: colibri-imx6ull: limit SDIO clock to 25MHz
ARM: dts: imx6qdl-sr-som: Increase the PHY reset duration to 10ms
ARM: imx: add missing clk_disable_unprepare()
ARM: imx: add missing iounmap()
arm64: dts: ls1028a: fix node name for the sysclk
ALSA: seq: Fix racy deletion of subscriber
Revert "ACPICA: Fix memory leak caused by _CID repair function"
ANDROID: GKI: fix up android/abi_gki_aarch64.xml merge
Linux 5.4.139
spi: mediatek: Fix fifo transfer
bpf, selftests: Adjust few selftest outcomes wrt unreachable code
bpf, selftests: Add a verifier test for assigning 32bit reg states to 64bit ones
bpf: Test_verifier, add alu32 bounds tracking tests
bpf: Fix leakage under speculation on mispredicted branches
bpf: Do not mark insn as seen under speculative path verification
bpf: Inherit expanded/patched seen count from old aux data
Revert "watchdog: iTCO_wdt: Account for rebooting on second timeout"
firmware: arm_scmi: Add delayed response status check
firmware: arm_scmi: Ensure drivers provide a probe function
Revert "Bluetooth: Shutdown controller after workqueues are flushed or cancelled"
ACPI: fix NULL pointer dereference
nvme: fix nvme_setup_command metadata trace event
net: Fix zero-copy head len calculation.
qed: fix possible unpaired spin_{un}lock_bh in _qed_mcp_cmd_and_union()
r8152: Fix potential PM refcount imbalance
ASoC: tlv320aic31xx: fix reversed bclk/wclk master bits
spi: stm32h7: fix full duplex irq handler handling
regulator: rt5033: Fix n_voltages settings for BUCK and LDO
btrfs: fix lost inode on log replay after mix of fsync, rename and inode eviction
btrfs: fix race causing unnecessary inode logging during link and rename
btrfs: do not commit logs and transactions during link and rename operations
btrfs: delete duplicated words + other fixes in comments
Linux 5.4.138
can: j1939: j1939_session_deactivate(): clarify lifetime of session object
i40e: Add additional info to PHY type error
Revert "perf map: Fix dso->nsinfo refcounting"
powerpc/pseries: Fix regression while building external modules
PCI: mvebu: Setup BAR0 in order to fix MSI
can: hi311x: fix a signedness bug in hi3110_cmd()
sis900: Fix missing pci_disable_device() in probe and remove
tulip: windbond-840: Fix missing pci_disable_device() in probe and remove
sctp: fix return value check in __sctp_rcv_asconf_lookup
net/mlx5e: Fix nullptr in mlx5e_hairpin_get_mdev()
net/mlx5: Fix flow table chaining
net: llc: fix skb_over_panic
mlx4: Fix missing error code in mlx4_load_one()
net: Set true network header for ECN decapsulation
tipc: fix sleeping in tipc accept routine
i40e: Fix log TC creation failure when max num of queues is exceeded
i40e: Fix queue-to-TC mapping on Tx
i40e: Fix firmware LLDP agent related warning
i40e: Fix logic of disabling queues
netfilter: nft_nat: allow to specify layer 4 protocol NAT only
netfilter: conntrack: adjust stop timestamp to real expiry value
cfg80211: Fix possible memory leak in function cfg80211_bss_update
nfc: nfcsim: fix use after free during module unload
NIU: fix incorrect error return, missed in previous revert
HID: wacom: Re-enable touch by default for Cintiq 24HDT / 27QHDT
can: esd_usb2: fix memory leak
can: ems_usb: fix memory leak
can: usb_8dev: fix memory leak
can: mcba_usb_start(): add missing urb->transfer_dma initialization
can: raw: raw_setsockopt(): fix raw_rcv panic for sock UAF
can: j1939: j1939_xtp_rx_dat_one(): fix rxtimer value between consecutive TP.DT to 750ms
ocfs2: issue zeroout to EOF blocks
ocfs2: fix zero out valid data
KVM: add missing compat KVM_CLEAR_DIRTY_LOG
x86/kvm: fix vcpu-id indexed array sizes
Revert "ACPI: resources: Add checks for ACPI IRQ override"
btrfs: mark compressed range uptodate only if all bio succeed
btrfs: fix rw device counting in __btrfs_free_extra_devids
x86/asm: Ensure asm/proto.h can be included stand-alone
net_sched: check error pointer in tcf_dump_walker()
Linux 5.4.137
ipv6: ip6_finish_output2: set sk into newly allocated nskb
ARM: dts: versatile: Fix up interrupt controller node names
iomap: remove the length variable in iomap_seek_hole
iomap: remove the length variable in iomap_seek_data
cifs: fix the out of range assignment to bit fields in parse_server_interfaces
firmware: arm_scmi: Fix range check for the maximum number of pending messages
firmware: arm_scmi: Fix possible scmi_linux_errmap buffer overflow
hfs: add lock nesting notation to hfs_find_init
hfs: fix high memory mapping in hfs_bnode_read
hfs: add missing clean-up in hfs_fill_super
ipv6: allocate enough headroom in ip6_finish_output2()
sctp: move 198 addresses from unusable to private scope
net: annotate data race around sk_ll_usec
net/802/garp: fix memleak in garp_request_join()
net/802/mrp: fix memleak in mrp_request_join()
cgroup1: fix leaked context root causing sporadic NULL deref in LTP
workqueue: fix UAF in pwq_unbound_release_workfn()
af_unix: fix garbage collect vs MSG_PEEK
KVM: x86: determine if an exception has an error code only when injecting it.
tools: Allow proper CC/CXX/... override with LLVM=1 in Makefile.include
selftest: fix build error in tools/testing/selftests/vm/userfaultfd.c
ANDROID: Update android/abi_gki_aarch64.xml
ANDROID: Update android/abi_gki_aarch64_goldfish
Linux 5.4.136
xhci: add xhci_get_virt_ep() helper
perf inject: Close inject.output on exit
PCI: Mark AMD Navi14 GPU ATS as broken
btrfs: compression: don't try to compress if we don't have enough pages
iio: accel: bma180: Fix BMA25x bandwidth register values
iio: accel: bma180: Use explicit member assignment
net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear
net: dsa: mv88e6xxx: use correct .stats_set_histogram() on Topaz
drm: Return -ENOTTY for non-drm ioctls
nds32: fix up stack guard gap
rbd: always kick acquire on "acquired" and "released" notifications
rbd: don't hold lock_rwsem while running_list is being drained
hugetlbfs: fix mount mode command line processing
userfaultfd: do not untag user pointers
selftest: use mmap instead of posix_memalign to allocate memory
ixgbe: Fix packet corruption due to missing DMA sync
media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf()
btrfs: check for missing device in btrfs_trim_fs
tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop.
tracing/histogram: Rename "cpu" to "common_cpu"
firmware/efi: Tell memblock about EFI iomem reservations
usb: dwc2: gadget: Fix sending zero length packet in DDMA mode.
USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick
USB: serial: cp210x: fix comments for GE CS1000
USB: serial: option: add support for u-blox LARA-R6 family
usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop()
usb: max-3421: Prevent corruption of freed memory
USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS
usb: hub: Fix link power management max exit latency (MEL) calculations
usb: hub: Disable USB 3 device initiated lpm if exit latency is too high
KVM: PPC: Book3S HV Nested: Sanitise H_ENTER_NESTED TM state
KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow
xhci: Fix lost USB 2 remote wake
ALSA: hdmi: Expose all pins on MSI MS-7C94 board
ALSA: sb: Fix potential ABBA deadlock in CSP driver
ALSA: usb-audio: Add registration quirk for JBL Quantum headsets
ALSA: usb-audio: Add missing proc text entry for BESPOKEN type
s390/boot: fix use of expolines in the DMA code
s390/ftrace: fix ftrace_update_ftrace_func implementation
Revert "MIPS: add PMD table accounting into MIPS'pmd_alloc_one"
proc: Avoid mixing integer types in mem_rw()
drm/panel: raspberrypi-touchscreen: Prevent double-free
net: sched: cls_api: Fix the the wrong parameter
sctp: update active_key for asoc when old key is being replaced
nvme: set the PRACT bit when using Write Zeroes with T10 PI
r8169: Avoid duplicate sysfs entry creation error
afs: Fix tracepoint string placement with built-in AFS
Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem"
nvme-pci: don't WARN_ON in nvme_reset_work if ctrl.state is not RESETTING
ipv6: fix another slab-out-of-bounds in fib6_nh_flush_exceptions
net/sched: act_skbmod: Skip non-Ethernet packets
net: hns3: fix rx VLAN offload state inconsistent issue
net/tcp_fastopen: fix data races around tfo_active_disable_stamp
net: hisilicon: rename CACHE_LINE_MASK to avoid redefinition
bnxt_en: Check abort error state in bnxt_half_open_nic()
bnxt_en: Add missing check for BNXT_STATE_ABORT_ERR in bnxt_fw_rset_task()
bnxt_en: Refresh RoCE capabilities in bnxt_ulp_probe()
bnxt_en: Improve bnxt_ulp_stop()/bnxt_ulp_start() call sequence.
spi: cadence: Correct initialisation of runtime PM again
scsi: target: Fix protect handling in WRITE SAME(32)
scsi: iscsi: Fix iface sysfs attr detection
netrom: Decrease sock refcount when sock timers expire
net: sched: fix memory leak in tcindex_partial_destroy_work
KVM: PPC: Fix kvm_arch_vcpu_ioctl vcpu_load leak
KVM: PPC: Book3S: Fix CONFIG_TRANSACTIONAL_MEM=n crash
net: decnet: Fix sleeping inside in af_decnet
efi/tpm: Differentiate missing and invalid final event log table.
net: fix uninit-value in caif_seqpkt_sendmsg
bpftool: Check malloc return value in mount_bpffs_for_pin
bpf, sockmap, tcp: sk_prot needs inuse_idx set for proc stats
s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1]
liquidio: Fix unintentional sign extension issue on left shift of u16
ASoC: rt5631: Fix regcache sync errors on resume
spi: mediatek: fix fifo rx mode
regulator: hi6421: Fix getting wrong drvdata
regulator: hi6421: Use correct variable type for regmap api val argument
spi: stm32: fixes pm_runtime calls in probe/remove
spi: stm32: Use dma_request_chan() instead dma_request_slave_channel()
spi: imx: add a check for speed_hz before calculating the clock
perf data: Close all files in close_dir()
perf probe-file: Delete namelist in del_events() on the error path
perf lzma: Close lzma stream on exit
perf script: Fix memory 'threads' and 'cpus' leaks on exit
perf dso: Fix memory leak in dso__new_map()
perf test event_update: Fix memory leak of evlist
perf test session_topology: Delete session->evlist
perf env: Fix sibling_dies memory leak
perf probe: Fix dso->nsinfo refcounting
perf map: Fix dso->nsinfo refcounting
nvme-pci: do not call nvme_dev_remove_admin from nvme_remove
cxgb4: fix IRQ free race during driver unload
pwm: sprd: Ensure configuring period and duty_cycle isn't wrongly skipped
selftests: icmp_redirect: IPv6 PMTU info should be cleared after redirect
selftests: icmp_redirect: remove from checking for IPv6 route get
ipv6: fix 'disable_policy' for fwd packets
gve: Fix an error handling path in 'gve_probe()'
igb: Fix position of assignment to *ring
igb: Check if num of q_vectors is smaller than max before array access
iavf: Fix an error handling path in 'iavf_probe()'
e1000e: Fix an error handling path in 'e1000_probe()'
fm10k: Fix an error handling path in 'fm10k_probe()'
igb: Fix an error handling path in 'igb_probe()'
igc: Fix an error handling path in 'igc_probe()'
igc: Prefer to use the pci_release_mem_regions method
ixgbe: Fix an error handling path in 'ixgbe_probe()'
igc: change default return of igc_read_phy_reg()
igb: Fix use-after-free error during reset
igc: Fix use-after-free error during reset
Linux 5.4.135
udp: annotate data races around unix_sk(sk)->gso_size
perf test bpf: Free obj_buf
bpftool: Properly close va_list 'ap' by va_end() on error
ipv6: tcp: drop silly ICMPv6 packet too big messages
tcp: annotate data races around tp->mtu_info
dma-buf/sync_file: Don't leak fences on merge failure
net: fddi: fix UAF in fza_probe
net: validate lwtstate->data before returning from skb_tunnel_info()
net: send SYNACK packet with accepted fwmark
net: ti: fix UAF in tlan_remove_one
net: qcom/emac: fix UAF in emac_remove
net: moxa: fix UAF in moxart_mac_probe
net: ip_tunnel: fix mtu calculation for ETHER tunnel devices
net: bcmgenet: Ensure all TX/RX queues DMAs are disabled
net: bridge: sync fdb to new unicast-filtering ports
net/sched: act_ct: fix err check for nf_conntrack_confirm
netfilter: ctnetlink: suspicious RCU usage in ctnetlink_dump_helpinfo
net: ipv6: fix return value of ip6_skb_dst_mtu
net: dsa: mv88e6xxx: enable .rmu_disable() on Topaz
net: dsa: mv88e6xxx: enable .port_set_policy() on Topaz
dm writecache: return the exact table values that were set
mm: slab: fix kmem_cache_create failed when sysfs node not destroyed
usb: cdns3: Enable TDL_CHK only for OUT ep
f2fs: Show casefolding support only when supported
arm64: dts: marvell: armada-37xx: move firmware node to generic dtsi file
firmware: turris-mox-rwtm: add marvell,armada-3700-rwtm-firmware compatible string
arm64: dts: armada-3720-turris-mox: add firmware node
cifs: prevent NULL deref in cifs_compose_mount_options()
s390: introduce proper type handling call_on_stack() macro
sched/fair: Fix CFS bandwidth hrtimer expiry type
scsi: qedf: Add check to synchronize abort and flush
scsi: libfc: Fix array index out of bound exception
scsi: libsas: Add LUN number check in .slave_alloc callback
scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8
rtc: max77686: Do not enforce (incorrect) interrupt trigger type
kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set
thermal/core: Correct function name thermal_zone_device_unregister()
arm64: dts: imx8mq: assign PCIe clocks
arm64: dts: ls208xa: remove bus-num from dspi node
firmware: tegra: bpmp: Fix Tegra234-only builds
soc/tegra: fuse: Fix Tegra234-only builds
ARM: dts: stm32: move stmmac axi config in ethernet node on stm32mp15
ARM: dts: stm32: fix i2c node name on stm32f746 to prevent warnings
ARM: dts: rockchip: fix supply properties in io-domains nodes
arm64: dts: juno: Update SCPI nodes as per the YAML schema
ARM: dts: stm32: fix timer nodes on STM32 MCU to prevent warnings
ARM: dts: stm32: fix RCC node name on stm32f429 MCU
ARM: dts: stm32: fix gpio-keys node on STM32 MCU boards
ARM: dts: am437x-gp-evm: fix ti,no-reset-on-init flag for gpios
ARM: dts: am57xx-cl-som-am57x: fix ti,no-reset-on-init flag for gpios
kbuild: sink stdout from cmd for silent build
rtc: mxc_v2: add missing MODULE_DEVICE_TABLE
ARM: imx: pm-imx5: Fix references to imx5_cpu_suspend_info
ARM: dts: imx6: phyFLEX: Fix UART hardware flow control
ARM: dts: Hurricane 2: Fix NAND nodes names
ARM: dts: BCM63xx: Fix NAND nodes names
ARM: NSP: dts: fix NAND nodes names
ARM: Cygnus: dts: fix NAND nodes names
ARM: brcmstb: dts: fix NAND nodes names
reset: ti-syscon: fix to_ti_syscon_reset_data macro
arm64: dts: rockchip: Fix power-controller node names for rk3328
arm64: dts: rockchip: Fix power-controller node names for px30
ARM: dts: rockchip: Fix power-controller node names for rk3288
ARM: dts: rockchip: Fix power-controller node names for rk3188
ARM: dts: rockchip: Fix power-controller node names for rk3066a
ARM: dts: rockchip: Fix IOMMU nodes properties on rk322x
ARM: dts: rockchip: Fix the timer clocks order
arm64: dts: rockchip: fix pinctrl sleep nodename for rk3399.dtsi
ARM: dts: rockchip: fix pinctrl sleep nodename for rk3036-kylin and rk3288
ARM: dts: gemini: add device_type on pci
ARM: dts: gemini: rename mdio to the right name
Conflicts:
drivers/mmc/host/sdhci-msm.c
drivers/scsi/ufs/ufshcd.c
drivers/staging/android/ion/heaps/ion_cma_heap.c
drivers/usb/dwc3/gadget.c
include/linux/oom.h
kernel/time/hrtimer.c
mm/oom_kill.c
net/qrtr/qrtr.c
Change-Id: I1c29c9ef4233acd05550475b29b8f7d30b6c452d
Signed-off-by: Srinivasarao Pathipati <quic_spathi@quicinc.com>
2004 lines
52 KiB
C
2004 lines
52 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* fs/userfaultfd.c
|
|
*
|
|
* Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
|
|
* Copyright (C) 2008-2009 Red Hat, Inc.
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
*
|
|
* Some part derived from fs/eventfd.c (anon inode setup) and
|
|
* mm/ksm.c (mm hashing).
|
|
*/
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/hashtable.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/poll.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/file.h>
|
|
#include <linux/bug.h>
|
|
#include <linux/anon_inodes.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/userfaultfd_k.h>
|
|
#include <linux/mempolicy.h>
|
|
#include <linux/ioctl.h>
|
|
#include <linux/security.h>
|
|
#include <linux/hugetlb.h>
|
|
|
|
int sysctl_unprivileged_userfaultfd __read_mostly = 1;
|
|
|
|
static struct kmem_cache *userfaultfd_ctx_cachep __read_mostly;
|
|
|
|
enum userfaultfd_state {
|
|
UFFD_STATE_WAIT_API,
|
|
UFFD_STATE_RUNNING,
|
|
};
|
|
|
|
/*
|
|
* Start with fault_pending_wqh and fault_wqh so they're more likely
|
|
* to be in the same cacheline.
|
|
*
|
|
* Locking order:
|
|
* fd_wqh.lock
|
|
* fault_pending_wqh.lock
|
|
* fault_wqh.lock
|
|
* event_wqh.lock
|
|
*
|
|
* To avoid deadlocks, IRQs must be disabled when taking any of the above locks,
|
|
* since fd_wqh.lock is taken by aio_poll() while it's holding a lock that's
|
|
* also taken in IRQ context.
|
|
*/
|
|
struct userfaultfd_ctx {
|
|
/* waitqueue head for the pending (i.e. not read) userfaults */
|
|
wait_queue_head_t fault_pending_wqh;
|
|
/* waitqueue head for the userfaults */
|
|
wait_queue_head_t fault_wqh;
|
|
/* waitqueue head for the pseudo fd to wakeup poll/read */
|
|
wait_queue_head_t fd_wqh;
|
|
/* waitqueue head for events */
|
|
wait_queue_head_t event_wqh;
|
|
/* a refile sequence protected by fault_pending_wqh lock */
|
|
struct seqcount refile_seq;
|
|
/* pseudo fd refcounting */
|
|
refcount_t refcount;
|
|
/* userfaultfd syscall flags */
|
|
unsigned int flags;
|
|
/* features requested from the userspace */
|
|
unsigned int features;
|
|
/* state machine */
|
|
enum userfaultfd_state state;
|
|
/* released */
|
|
bool released;
|
|
/* memory mappings are changing because of non-cooperative event */
|
|
bool mmap_changing;
|
|
/* mm with one ore more vmas attached to this userfaultfd_ctx */
|
|
struct mm_struct *mm;
|
|
};
|
|
|
|
struct userfaultfd_fork_ctx {
|
|
struct userfaultfd_ctx *orig;
|
|
struct userfaultfd_ctx *new;
|
|
struct list_head list;
|
|
};
|
|
|
|
struct userfaultfd_unmap_ctx {
|
|
struct userfaultfd_ctx *ctx;
|
|
unsigned long start;
|
|
unsigned long end;
|
|
struct list_head list;
|
|
};
|
|
|
|
struct userfaultfd_wait_queue {
|
|
struct uffd_msg msg;
|
|
wait_queue_entry_t wq;
|
|
struct userfaultfd_ctx *ctx;
|
|
bool waken;
|
|
};
|
|
|
|
struct userfaultfd_wake_range {
|
|
unsigned long start;
|
|
unsigned long len;
|
|
};
|
|
|
|
static int userfaultfd_wake_function(wait_queue_entry_t *wq, unsigned mode,
|
|
int wake_flags, void *key)
|
|
{
|
|
struct userfaultfd_wake_range *range = key;
|
|
int ret;
|
|
struct userfaultfd_wait_queue *uwq;
|
|
unsigned long start, len;
|
|
|
|
uwq = container_of(wq, struct userfaultfd_wait_queue, wq);
|
|
ret = 0;
|
|
/* len == 0 means wake all */
|
|
start = range->start;
|
|
len = range->len;
|
|
if (len && (start > uwq->msg.arg.pagefault.address ||
|
|
start + len <= uwq->msg.arg.pagefault.address))
|
|
goto out;
|
|
WRITE_ONCE(uwq->waken, true);
|
|
/*
|
|
* The Program-Order guarantees provided by the scheduler
|
|
* ensure uwq->waken is visible before the task is woken.
|
|
*/
|
|
ret = wake_up_state(wq->private, mode);
|
|
if (ret) {
|
|
/*
|
|
* Wake only once, autoremove behavior.
|
|
*
|
|
* After the effect of list_del_init is visible to the other
|
|
* CPUs, the waitqueue may disappear from under us, see the
|
|
* !list_empty_careful() in handle_userfault().
|
|
*
|
|
* try_to_wake_up() has an implicit smp_mb(), and the
|
|
* wq->private is read before calling the extern function
|
|
* "wake_up_state" (which in turns calls try_to_wake_up).
|
|
*/
|
|
list_del_init(&wq->entry);
|
|
}
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* userfaultfd_ctx_get - Acquires a reference to the internal userfaultfd
|
|
* context.
|
|
* @ctx: [in] Pointer to the userfaultfd context.
|
|
*/
|
|
static void userfaultfd_ctx_get(struct userfaultfd_ctx *ctx)
|
|
{
|
|
refcount_inc(&ctx->refcount);
|
|
}
|
|
|
|
/**
|
|
* userfaultfd_ctx_put - Releases a reference to the internal userfaultfd
|
|
* context.
|
|
* @ctx: [in] Pointer to userfaultfd context.
|
|
*
|
|
* The userfaultfd context reference must have been previously acquired either
|
|
* with userfaultfd_ctx_get() or userfaultfd_ctx_fdget().
|
|
*/
|
|
static void userfaultfd_ctx_put(struct userfaultfd_ctx *ctx)
|
|
{
|
|
if (refcount_dec_and_test(&ctx->refcount)) {
|
|
VM_BUG_ON(spin_is_locked(&ctx->fault_pending_wqh.lock));
|
|
VM_BUG_ON(waitqueue_active(&ctx->fault_pending_wqh));
|
|
VM_BUG_ON(spin_is_locked(&ctx->fault_wqh.lock));
|
|
VM_BUG_ON(waitqueue_active(&ctx->fault_wqh));
|
|
VM_BUG_ON(spin_is_locked(&ctx->event_wqh.lock));
|
|
VM_BUG_ON(waitqueue_active(&ctx->event_wqh));
|
|
VM_BUG_ON(spin_is_locked(&ctx->fd_wqh.lock));
|
|
VM_BUG_ON(waitqueue_active(&ctx->fd_wqh));
|
|
mmdrop(ctx->mm);
|
|
kmem_cache_free(userfaultfd_ctx_cachep, ctx);
|
|
}
|
|
}
|
|
|
|
static inline void msg_init(struct uffd_msg *msg)
|
|
{
|
|
BUILD_BUG_ON(sizeof(struct uffd_msg) != 32);
|
|
/*
|
|
* Must use memset to zero out the paddings or kernel data is
|
|
* leaked to userland.
|
|
*/
|
|
memset(msg, 0, sizeof(struct uffd_msg));
|
|
}
|
|
|
|
static inline struct uffd_msg userfault_msg(unsigned long address,
|
|
unsigned int flags,
|
|
unsigned long reason,
|
|
unsigned int features)
|
|
{
|
|
struct uffd_msg msg;
|
|
msg_init(&msg);
|
|
msg.event = UFFD_EVENT_PAGEFAULT;
|
|
msg.arg.pagefault.address = address;
|
|
if (flags & FAULT_FLAG_WRITE)
|
|
/*
|
|
* If UFFD_FEATURE_PAGEFAULT_FLAG_WP was set in the
|
|
* uffdio_api.features and UFFD_PAGEFAULT_FLAG_WRITE
|
|
* was not set in a UFFD_EVENT_PAGEFAULT, it means it
|
|
* was a read fault, otherwise if set it means it's
|
|
* a write fault.
|
|
*/
|
|
msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WRITE;
|
|
if (reason & VM_UFFD_WP)
|
|
/*
|
|
* If UFFD_FEATURE_PAGEFAULT_FLAG_WP was set in the
|
|
* uffdio_api.features and UFFD_PAGEFAULT_FLAG_WP was
|
|
* not set in a UFFD_EVENT_PAGEFAULT, it means it was
|
|
* a missing fault, otherwise if set it means it's a
|
|
* write protect fault.
|
|
*/
|
|
msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WP;
|
|
if (features & UFFD_FEATURE_THREAD_ID)
|
|
msg.arg.pagefault.feat.ptid = task_pid_vnr(current);
|
|
return msg;
|
|
}
|
|
|
|
#ifdef CONFIG_HUGETLB_PAGE
|
|
/*
|
|
* Same functionality as userfaultfd_must_wait below with modifications for
|
|
* hugepmd ranges.
|
|
*/
|
|
static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,
|
|
struct vm_area_struct *vma,
|
|
unsigned long address,
|
|
unsigned long flags,
|
|
unsigned long reason)
|
|
{
|
|
struct mm_struct *mm = ctx->mm;
|
|
pte_t *ptep, pte;
|
|
bool ret = true;
|
|
|
|
VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
|
|
|
|
ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma));
|
|
|
|
if (!ptep)
|
|
goto out;
|
|
|
|
ret = false;
|
|
pte = huge_ptep_get(ptep);
|
|
|
|
/*
|
|
* Lockless access: we're in a wait_event so it's ok if it
|
|
* changes under us.
|
|
*/
|
|
if (huge_pte_none(pte))
|
|
ret = true;
|
|
if (!huge_pte_write(pte) && (reason & VM_UFFD_WP))
|
|
ret = true;
|
|
out:
|
|
return ret;
|
|
}
|
|
#else
|
|
static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,
|
|
struct vm_area_struct *vma,
|
|
unsigned long address,
|
|
unsigned long flags,
|
|
unsigned long reason)
|
|
{
|
|
return false; /* should never get here */
|
|
}
|
|
#endif /* CONFIG_HUGETLB_PAGE */
|
|
|
|
/*
|
|
* Verify the pagetables are still not ok after having reigstered into
|
|
* the fault_pending_wqh to avoid userland having to UFFDIO_WAKE any
|
|
* userfault that has already been resolved, if userfaultfd_read and
|
|
* UFFDIO_COPY|ZEROPAGE are being run simultaneously on two different
|
|
* threads.
|
|
*/
|
|
static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,
|
|
unsigned long address,
|
|
unsigned long flags,
|
|
unsigned long reason)
|
|
{
|
|
struct mm_struct *mm = ctx->mm;
|
|
pgd_t *pgd;
|
|
p4d_t *p4d;
|
|
pud_t *pud;
|
|
pmd_t *pmd, _pmd;
|
|
pte_t *pte;
|
|
bool ret = true;
|
|
|
|
VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
|
|
|
|
pgd = pgd_offset(mm, address);
|
|
if (!pgd_present(*pgd))
|
|
goto out;
|
|
p4d = p4d_offset(pgd, address);
|
|
if (!p4d_present(*p4d))
|
|
goto out;
|
|
pud = pud_offset(p4d, address);
|
|
if (!pud_present(*pud))
|
|
goto out;
|
|
pmd = pmd_offset(pud, address);
|
|
/*
|
|
* READ_ONCE must function as a barrier with narrower scope
|
|
* and it must be equivalent to:
|
|
* _pmd = *pmd; barrier();
|
|
*
|
|
* This is to deal with the instability (as in
|
|
* pmd_trans_unstable) of the pmd.
|
|
*/
|
|
_pmd = READ_ONCE(*pmd);
|
|
if (pmd_none(_pmd))
|
|
goto out;
|
|
|
|
ret = false;
|
|
if (!pmd_present(_pmd))
|
|
goto out;
|
|
|
|
if (pmd_trans_huge(_pmd))
|
|
goto out;
|
|
|
|
/*
|
|
* the pmd is stable (as in !pmd_trans_unstable) so we can re-read it
|
|
* and use the standard pte_offset_map() instead of parsing _pmd.
|
|
*/
|
|
pte = pte_offset_map(pmd, address);
|
|
/*
|
|
* Lockless access: we're in a wait_event so it's ok if it
|
|
* changes under us.
|
|
*/
|
|
if (pte_none(*pte))
|
|
ret = true;
|
|
pte_unmap(pte);
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* The locking rules involved in returning VM_FAULT_RETRY depending on
|
|
* FAULT_FLAG_ALLOW_RETRY, FAULT_FLAG_RETRY_NOWAIT and
|
|
* FAULT_FLAG_KILLABLE are not straightforward. The "Caution"
|
|
* recommendation in __lock_page_or_retry is not an understatement.
|
|
*
|
|
* If FAULT_FLAG_ALLOW_RETRY is set, the mmap_sem must be released
|
|
* before returning VM_FAULT_RETRY only if FAULT_FLAG_RETRY_NOWAIT is
|
|
* not set.
|
|
*
|
|
* If FAULT_FLAG_ALLOW_RETRY is set but FAULT_FLAG_KILLABLE is not
|
|
* set, VM_FAULT_RETRY can still be returned if and only if there are
|
|
* fatal_signal_pending()s, and the mmap_sem must be released before
|
|
* returning it.
|
|
*/
|
|
vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)
|
|
{
|
|
struct mm_struct *mm = vmf->vma->vm_mm;
|
|
struct userfaultfd_ctx *ctx;
|
|
struct userfaultfd_wait_queue uwq;
|
|
vm_fault_t ret = VM_FAULT_SIGBUS;
|
|
bool must_wait, return_to_userland;
|
|
long blocking_state;
|
|
|
|
/*
|
|
* We don't do userfault handling for the final child pid update.
|
|
*
|
|
* We also don't do userfault handling during
|
|
* coredumping. hugetlbfs has the special
|
|
* follow_hugetlb_page() to skip missing pages in the
|
|
* FOLL_DUMP case, anon memory also checks for FOLL_DUMP with
|
|
* the no_page_table() helper in follow_page_mask(), but the
|
|
* shmem_vm_ops->fault method is invoked even during
|
|
* coredumping without mmap_sem and it ends up here.
|
|
*/
|
|
if (current->flags & (PF_EXITING|PF_DUMPCORE))
|
|
goto out;
|
|
|
|
/*
|
|
* Coredumping runs without mmap_sem so we can only check that
|
|
* the mmap_sem is held, if PF_DUMPCORE was not set.
|
|
*/
|
|
WARN_ON_ONCE(!rwsem_is_locked(&mm->mmap_sem));
|
|
|
|
ctx = vmf->vma->vm_userfaultfd_ctx.ctx;
|
|
if (!ctx)
|
|
goto out;
|
|
|
|
BUG_ON(ctx->mm != mm);
|
|
|
|
VM_BUG_ON(reason & ~(VM_UFFD_MISSING|VM_UFFD_WP));
|
|
VM_BUG_ON(!(reason & VM_UFFD_MISSING) ^ !!(reason & VM_UFFD_WP));
|
|
|
|
if (ctx->features & UFFD_FEATURE_SIGBUS)
|
|
goto out;
|
|
|
|
/*
|
|
* If it's already released don't get it. This avoids to loop
|
|
* in __get_user_pages if userfaultfd_release waits on the
|
|
* caller of handle_userfault to release the mmap_sem.
|
|
*/
|
|
if (unlikely(READ_ONCE(ctx->released))) {
|
|
/*
|
|
* Don't return VM_FAULT_SIGBUS in this case, so a non
|
|
* cooperative manager can close the uffd after the
|
|
* last UFFDIO_COPY, without risking to trigger an
|
|
* involuntary SIGBUS if the process was starting the
|
|
* userfaultfd while the userfaultfd was still armed
|
|
* (but after the last UFFDIO_COPY). If the uffd
|
|
* wasn't already closed when the userfault reached
|
|
* this point, that would normally be solved by
|
|
* userfaultfd_must_wait returning 'false'.
|
|
*
|
|
* If we were to return VM_FAULT_SIGBUS here, the non
|
|
* cooperative manager would be instead forced to
|
|
* always call UFFDIO_UNREGISTER before it can safely
|
|
* close the uffd.
|
|
*/
|
|
ret = VM_FAULT_NOPAGE;
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* Check that we can return VM_FAULT_RETRY.
|
|
*
|
|
* NOTE: it should become possible to return VM_FAULT_RETRY
|
|
* even if FAULT_FLAG_TRIED is set without leading to gup()
|
|
* -EBUSY failures, if the userfaultfd is to be extended for
|
|
* VM_UFFD_WP tracking and we intend to arm the userfault
|
|
* without first stopping userland access to the memory. For
|
|
* VM_UFFD_MISSING userfaults this is enough for now.
|
|
*/
|
|
if (unlikely(!(vmf->flags & FAULT_FLAG_ALLOW_RETRY))) {
|
|
/*
|
|
* Validate the invariant that nowait must allow retry
|
|
* to be sure not to return SIGBUS erroneously on
|
|
* nowait invocations.
|
|
*/
|
|
BUG_ON(vmf->flags & FAULT_FLAG_RETRY_NOWAIT);
|
|
#ifdef CONFIG_DEBUG_VM
|
|
if (printk_ratelimit()) {
|
|
printk(KERN_WARNING
|
|
"FAULT_FLAG_ALLOW_RETRY missing %x\n",
|
|
vmf->flags);
|
|
dump_stack();
|
|
}
|
|
#endif
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* Handle nowait, not much to do other than tell it to retry
|
|
* and wait.
|
|
*/
|
|
ret = VM_FAULT_RETRY;
|
|
if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)
|
|
goto out;
|
|
|
|
/* take the reference before dropping the mmap_sem */
|
|
userfaultfd_ctx_get(ctx);
|
|
|
|
init_waitqueue_func_entry(&uwq.wq, userfaultfd_wake_function);
|
|
uwq.wq.private = current;
|
|
uwq.msg = userfault_msg(vmf->address, vmf->flags, reason,
|
|
ctx->features);
|
|
uwq.ctx = ctx;
|
|
uwq.waken = false;
|
|
|
|
return_to_userland =
|
|
(vmf->flags & (FAULT_FLAG_USER|FAULT_FLAG_KILLABLE)) ==
|
|
(FAULT_FLAG_USER|FAULT_FLAG_KILLABLE);
|
|
blocking_state = return_to_userland ? TASK_INTERRUPTIBLE :
|
|
TASK_KILLABLE;
|
|
|
|
spin_lock_irq(&ctx->fault_pending_wqh.lock);
|
|
/*
|
|
* After the __add_wait_queue the uwq is visible to userland
|
|
* through poll/read().
|
|
*/
|
|
__add_wait_queue(&ctx->fault_pending_wqh, &uwq.wq);
|
|
/*
|
|
* The smp_mb() after __set_current_state prevents the reads
|
|
* following the spin_unlock to happen before the list_add in
|
|
* __add_wait_queue.
|
|
*/
|
|
set_current_state(blocking_state);
|
|
spin_unlock_irq(&ctx->fault_pending_wqh.lock);
|
|
|
|
if (!is_vm_hugetlb_page(vmf->vma))
|
|
must_wait = userfaultfd_must_wait(ctx, vmf->address, vmf->flags,
|
|
reason);
|
|
else
|
|
must_wait = userfaultfd_huge_must_wait(ctx, vmf->vma,
|
|
vmf->address,
|
|
vmf->flags, reason);
|
|
up_read(&mm->mmap_sem);
|
|
|
|
if (likely(must_wait && !READ_ONCE(ctx->released) &&
|
|
(return_to_userland ? !signal_pending(current) :
|
|
!fatal_signal_pending(current)))) {
|
|
wake_up_poll(&ctx->fd_wqh, EPOLLIN);
|
|
schedule();
|
|
ret |= VM_FAULT_MAJOR;
|
|
|
|
/*
|
|
* False wakeups can orginate even from rwsem before
|
|
* up_read() however userfaults will wait either for a
|
|
* targeted wakeup on the specific uwq waitqueue from
|
|
* wake_userfault() or for signals or for uffd
|
|
* release.
|
|
*/
|
|
while (!READ_ONCE(uwq.waken)) {
|
|
/*
|
|
* This needs the full smp_store_mb()
|
|
* guarantee as the state write must be
|
|
* visible to other CPUs before reading
|
|
* uwq.waken from other CPUs.
|
|
*/
|
|
set_current_state(blocking_state);
|
|
if (READ_ONCE(uwq.waken) ||
|
|
READ_ONCE(ctx->released) ||
|
|
(return_to_userland ? signal_pending(current) :
|
|
fatal_signal_pending(current)))
|
|
break;
|
|
schedule();
|
|
}
|
|
}
|
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
if (return_to_userland) {
|
|
if (signal_pending(current) &&
|
|
!fatal_signal_pending(current)) {
|
|
/*
|
|
* If we got a SIGSTOP or SIGCONT and this is
|
|
* a normal userland page fault, just let
|
|
* userland return so the signal will be
|
|
* handled and gdb debugging works. The page
|
|
* fault code immediately after we return from
|
|
* this function is going to release the
|
|
* mmap_sem and it's not depending on it
|
|
* (unlike gup would if we were not to return
|
|
* VM_FAULT_RETRY).
|
|
*
|
|
* If a fatal signal is pending we still take
|
|
* the streamlined VM_FAULT_RETRY failure path
|
|
* and there's no need to retake the mmap_sem
|
|
* in such case.
|
|
*/
|
|
down_read(&mm->mmap_sem);
|
|
ret = VM_FAULT_NOPAGE;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Here we race with the list_del; list_add in
|
|
* userfaultfd_ctx_read(), however because we don't ever run
|
|
* list_del_init() to refile across the two lists, the prev
|
|
* and next pointers will never point to self. list_add also
|
|
* would never let any of the two pointers to point to
|
|
* self. So list_empty_careful won't risk to see both pointers
|
|
* pointing to self at any time during the list refile. The
|
|
* only case where list_del_init() is called is the full
|
|
* removal in the wake function and there we don't re-list_add
|
|
* and it's fine not to block on the spinlock. The uwq on this
|
|
* kernel stack can be released after the list_del_init.
|
|
*/
|
|
if (!list_empty_careful(&uwq.wq.entry)) {
|
|
spin_lock_irq(&ctx->fault_pending_wqh.lock);
|
|
/*
|
|
* No need of list_del_init(), the uwq on the stack
|
|
* will be freed shortly anyway.
|
|
*/
|
|
list_del(&uwq.wq.entry);
|
|
spin_unlock_irq(&ctx->fault_pending_wqh.lock);
|
|
}
|
|
|
|
/*
|
|
* ctx may go away after this if the userfault pseudo fd is
|
|
* already released.
|
|
*/
|
|
userfaultfd_ctx_put(ctx);
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx,
|
|
struct userfaultfd_wait_queue *ewq)
|
|
{
|
|
struct userfaultfd_ctx *release_new_ctx;
|
|
|
|
if (WARN_ON_ONCE(current->flags & PF_EXITING))
|
|
goto out;
|
|
|
|
ewq->ctx = ctx;
|
|
init_waitqueue_entry(&ewq->wq, current);
|
|
release_new_ctx = NULL;
|
|
|
|
spin_lock_irq(&ctx->event_wqh.lock);
|
|
/*
|
|
* After the __add_wait_queue the uwq is visible to userland
|
|
* through poll/read().
|
|
*/
|
|
__add_wait_queue(&ctx->event_wqh, &ewq->wq);
|
|
for (;;) {
|
|
set_current_state(TASK_KILLABLE);
|
|
if (ewq->msg.event == 0)
|
|
break;
|
|
if (READ_ONCE(ctx->released) ||
|
|
fatal_signal_pending(current)) {
|
|
/*
|
|
* &ewq->wq may be queued in fork_event, but
|
|
* __remove_wait_queue ignores the head
|
|
* parameter. It would be a problem if it
|
|
* didn't.
|
|
*/
|
|
__remove_wait_queue(&ctx->event_wqh, &ewq->wq);
|
|
if (ewq->msg.event == UFFD_EVENT_FORK) {
|
|
struct userfaultfd_ctx *new;
|
|
|
|
new = (struct userfaultfd_ctx *)
|
|
(unsigned long)
|
|
ewq->msg.arg.reserved.reserved1;
|
|
release_new_ctx = new;
|
|
}
|
|
break;
|
|
}
|
|
|
|
spin_unlock_irq(&ctx->event_wqh.lock);
|
|
|
|
wake_up_poll(&ctx->fd_wqh, EPOLLIN);
|
|
schedule();
|
|
|
|
spin_lock_irq(&ctx->event_wqh.lock);
|
|
}
|
|
__set_current_state(TASK_RUNNING);
|
|
spin_unlock_irq(&ctx->event_wqh.lock);
|
|
|
|
if (release_new_ctx) {
|
|
struct vm_area_struct *vma;
|
|
struct mm_struct *mm = release_new_ctx->mm;
|
|
|
|
/* the various vma->vm_userfaultfd_ctx still points to it */
|
|
down_write(&mm->mmap_sem);
|
|
/* no task can run (and in turn coredump) yet */
|
|
VM_WARN_ON(!mmget_still_valid(mm));
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next)
|
|
if (vma->vm_userfaultfd_ctx.ctx == release_new_ctx) {
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING);
|
|
}
|
|
up_write(&mm->mmap_sem);
|
|
|
|
userfaultfd_ctx_put(release_new_ctx);
|
|
}
|
|
|
|
/*
|
|
* ctx may go away after this if the userfault pseudo fd is
|
|
* already released.
|
|
*/
|
|
out:
|
|
WRITE_ONCE(ctx->mmap_changing, false);
|
|
userfaultfd_ctx_put(ctx);
|
|
}
|
|
|
|
static void userfaultfd_event_complete(struct userfaultfd_ctx *ctx,
|
|
struct userfaultfd_wait_queue *ewq)
|
|
{
|
|
ewq->msg.event = 0;
|
|
wake_up_locked(&ctx->event_wqh);
|
|
__remove_wait_queue(&ctx->event_wqh, &ewq->wq);
|
|
}
|
|
|
|
int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs)
|
|
{
|
|
struct userfaultfd_ctx *ctx = NULL, *octx;
|
|
struct userfaultfd_fork_ctx *fctx;
|
|
|
|
octx = vma->vm_userfaultfd_ctx.ctx;
|
|
if (!octx || !(octx->features & UFFD_FEATURE_EVENT_FORK)) {
|
|
vm_write_begin(vma);
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
WRITE_ONCE(vma->vm_flags,
|
|
vma->vm_flags & ~(VM_UFFD_WP | VM_UFFD_MISSING));
|
|
vm_write_end(vma);
|
|
return 0;
|
|
}
|
|
|
|
list_for_each_entry(fctx, fcs, list)
|
|
if (fctx->orig == octx) {
|
|
ctx = fctx->new;
|
|
break;
|
|
}
|
|
|
|
if (!ctx) {
|
|
fctx = kmalloc(sizeof(*fctx), GFP_KERNEL);
|
|
if (!fctx)
|
|
return -ENOMEM;
|
|
|
|
ctx = kmem_cache_alloc(userfaultfd_ctx_cachep, GFP_KERNEL);
|
|
if (!ctx) {
|
|
kfree(fctx);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
refcount_set(&ctx->refcount, 1);
|
|
ctx->flags = octx->flags;
|
|
ctx->state = UFFD_STATE_RUNNING;
|
|
ctx->features = octx->features;
|
|
ctx->released = false;
|
|
ctx->mmap_changing = false;
|
|
ctx->mm = vma->vm_mm;
|
|
mmgrab(ctx->mm);
|
|
|
|
userfaultfd_ctx_get(octx);
|
|
WRITE_ONCE(octx->mmap_changing, true);
|
|
fctx->orig = octx;
|
|
fctx->new = ctx;
|
|
list_add_tail(&fctx->list, fcs);
|
|
}
|
|
|
|
vma->vm_userfaultfd_ctx.ctx = ctx;
|
|
return 0;
|
|
}
|
|
|
|
static void dup_fctx(struct userfaultfd_fork_ctx *fctx)
|
|
{
|
|
struct userfaultfd_ctx *ctx = fctx->orig;
|
|
struct userfaultfd_wait_queue ewq;
|
|
|
|
msg_init(&ewq.msg);
|
|
|
|
ewq.msg.event = UFFD_EVENT_FORK;
|
|
ewq.msg.arg.reserved.reserved1 = (unsigned long)fctx->new;
|
|
|
|
userfaultfd_event_wait_completion(ctx, &ewq);
|
|
}
|
|
|
|
void dup_userfaultfd_complete(struct list_head *fcs)
|
|
{
|
|
struct userfaultfd_fork_ctx *fctx, *n;
|
|
|
|
list_for_each_entry_safe(fctx, n, fcs, list) {
|
|
dup_fctx(fctx);
|
|
list_del(&fctx->list);
|
|
kfree(fctx);
|
|
}
|
|
}
|
|
|
|
void mremap_userfaultfd_prep(struct vm_area_struct *vma,
|
|
struct vm_userfaultfd_ctx *vm_ctx)
|
|
{
|
|
struct userfaultfd_ctx *ctx;
|
|
|
|
ctx = vma->vm_userfaultfd_ctx.ctx;
|
|
|
|
if (!ctx)
|
|
return;
|
|
|
|
if (ctx->features & UFFD_FEATURE_EVENT_REMAP) {
|
|
vm_ctx->ctx = ctx;
|
|
userfaultfd_ctx_get(ctx);
|
|
WRITE_ONCE(ctx->mmap_changing, true);
|
|
} else {
|
|
/* Drop uffd context if remap feature not enabled */
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
vma->vm_flags &= ~(VM_UFFD_WP | VM_UFFD_MISSING);
|
|
}
|
|
}
|
|
|
|
void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *vm_ctx,
|
|
unsigned long from, unsigned long to,
|
|
unsigned long len)
|
|
{
|
|
struct userfaultfd_ctx *ctx = vm_ctx->ctx;
|
|
struct userfaultfd_wait_queue ewq;
|
|
|
|
if (!ctx)
|
|
return;
|
|
|
|
if (to & ~PAGE_MASK) {
|
|
userfaultfd_ctx_put(ctx);
|
|
return;
|
|
}
|
|
|
|
msg_init(&ewq.msg);
|
|
|
|
ewq.msg.event = UFFD_EVENT_REMAP;
|
|
ewq.msg.arg.remap.from = from;
|
|
ewq.msg.arg.remap.to = to;
|
|
ewq.msg.arg.remap.len = len;
|
|
|
|
userfaultfd_event_wait_completion(ctx, &ewq);
|
|
}
|
|
|
|
bool userfaultfd_remove(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
struct userfaultfd_ctx *ctx;
|
|
struct userfaultfd_wait_queue ewq;
|
|
|
|
ctx = vma->vm_userfaultfd_ctx.ctx;
|
|
if (!ctx || !(ctx->features & UFFD_FEATURE_EVENT_REMOVE))
|
|
return true;
|
|
|
|
userfaultfd_ctx_get(ctx);
|
|
WRITE_ONCE(ctx->mmap_changing, true);
|
|
up_read(&mm->mmap_sem);
|
|
|
|
msg_init(&ewq.msg);
|
|
|
|
ewq.msg.event = UFFD_EVENT_REMOVE;
|
|
ewq.msg.arg.remove.start = start;
|
|
ewq.msg.arg.remove.end = end;
|
|
|
|
userfaultfd_event_wait_completion(ctx, &ewq);
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool has_unmap_ctx(struct userfaultfd_ctx *ctx, struct list_head *unmaps,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
struct userfaultfd_unmap_ctx *unmap_ctx;
|
|
|
|
list_for_each_entry(unmap_ctx, unmaps, list)
|
|
if (unmap_ctx->ctx == ctx && unmap_ctx->start == start &&
|
|
unmap_ctx->end == end)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
int userfaultfd_unmap_prep(struct vm_area_struct *vma,
|
|
unsigned long start, unsigned long end,
|
|
struct list_head *unmaps)
|
|
{
|
|
for ( ; vma && vma->vm_start < end; vma = vma->vm_next) {
|
|
struct userfaultfd_unmap_ctx *unmap_ctx;
|
|
struct userfaultfd_ctx *ctx = vma->vm_userfaultfd_ctx.ctx;
|
|
|
|
if (!ctx || !(ctx->features & UFFD_FEATURE_EVENT_UNMAP) ||
|
|
has_unmap_ctx(ctx, unmaps, start, end))
|
|
continue;
|
|
|
|
unmap_ctx = kzalloc(sizeof(*unmap_ctx), GFP_KERNEL);
|
|
if (!unmap_ctx)
|
|
return -ENOMEM;
|
|
|
|
userfaultfd_ctx_get(ctx);
|
|
WRITE_ONCE(ctx->mmap_changing, true);
|
|
unmap_ctx->ctx = ctx;
|
|
unmap_ctx->start = start;
|
|
unmap_ctx->end = end;
|
|
list_add_tail(&unmap_ctx->list, unmaps);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void userfaultfd_unmap_complete(struct mm_struct *mm, struct list_head *uf)
|
|
{
|
|
struct userfaultfd_unmap_ctx *ctx, *n;
|
|
struct userfaultfd_wait_queue ewq;
|
|
|
|
list_for_each_entry_safe(ctx, n, uf, list) {
|
|
msg_init(&ewq.msg);
|
|
|
|
ewq.msg.event = UFFD_EVENT_UNMAP;
|
|
ewq.msg.arg.remove.start = ctx->start;
|
|
ewq.msg.arg.remove.end = ctx->end;
|
|
|
|
userfaultfd_event_wait_completion(ctx->ctx, &ewq);
|
|
|
|
list_del(&ctx->list);
|
|
kfree(ctx);
|
|
}
|
|
}
|
|
|
|
static int userfaultfd_release(struct inode *inode, struct file *file)
|
|
{
|
|
struct userfaultfd_ctx *ctx = file->private_data;
|
|
struct mm_struct *mm = ctx->mm;
|
|
struct vm_area_struct *vma, *prev;
|
|
/* len == 0 means wake all */
|
|
struct userfaultfd_wake_range range = { .len = 0, };
|
|
unsigned long new_flags;
|
|
bool still_valid;
|
|
|
|
WRITE_ONCE(ctx->released, true);
|
|
|
|
if (!mmget_not_zero(mm))
|
|
goto wakeup;
|
|
|
|
/*
|
|
* Flush page faults out of all CPUs. NOTE: all page faults
|
|
* must be retried without returning VM_FAULT_SIGBUS if
|
|
* userfaultfd_ctx_get() succeeds but vma->vma_userfault_ctx
|
|
* changes while handle_userfault released the mmap_sem. So
|
|
* it's critical that released is set to true (above), before
|
|
* taking the mmap_sem for writing.
|
|
*/
|
|
down_write(&mm->mmap_sem);
|
|
still_valid = mmget_still_valid(mm);
|
|
prev = NULL;
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
|
cond_resched();
|
|
BUG_ON(!!vma->vm_userfaultfd_ctx.ctx ^
|
|
!!(vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP)));
|
|
if (vma->vm_userfaultfd_ctx.ctx != ctx) {
|
|
prev = vma;
|
|
continue;
|
|
}
|
|
new_flags = vma->vm_flags & ~(VM_UFFD_MISSING | VM_UFFD_WP);
|
|
if (still_valid) {
|
|
prev = vma_merge(mm, prev, vma->vm_start, vma->vm_end,
|
|
new_flags, vma->anon_vma,
|
|
vma->vm_file, vma->vm_pgoff,
|
|
vma_policy(vma),
|
|
NULL_VM_UFFD_CTX,
|
|
vma_get_anon_name(vma));
|
|
if (prev)
|
|
vma = prev;
|
|
else
|
|
prev = vma;
|
|
}
|
|
vm_write_begin(vma);
|
|
WRITE_ONCE(vma->vm_flags, new_flags);
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
vm_write_end(vma);
|
|
}
|
|
up_write(&mm->mmap_sem);
|
|
mmput(mm);
|
|
wakeup:
|
|
/*
|
|
* After no new page faults can wait on this fault_*wqh, flush
|
|
* the last page faults that may have been already waiting on
|
|
* the fault_*wqh.
|
|
*/
|
|
spin_lock_irq(&ctx->fault_pending_wqh.lock);
|
|
__wake_up_locked_key(&ctx->fault_pending_wqh, TASK_NORMAL, &range);
|
|
__wake_up(&ctx->fault_wqh, TASK_NORMAL, 1, &range);
|
|
spin_unlock_irq(&ctx->fault_pending_wqh.lock);
|
|
|
|
/* Flush pending events that may still wait on event_wqh */
|
|
wake_up_all(&ctx->event_wqh);
|
|
|
|
wake_up_poll(&ctx->fd_wqh, EPOLLHUP);
|
|
userfaultfd_ctx_put(ctx);
|
|
return 0;
|
|
}
|
|
|
|
/* fault_pending_wqh.lock must be hold by the caller */
|
|
static inline struct userfaultfd_wait_queue *find_userfault_in(
|
|
wait_queue_head_t *wqh)
|
|
{
|
|
wait_queue_entry_t *wq;
|
|
struct userfaultfd_wait_queue *uwq;
|
|
|
|
lockdep_assert_held(&wqh->lock);
|
|
|
|
uwq = NULL;
|
|
if (!waitqueue_active(wqh))
|
|
goto out;
|
|
/* walk in reverse to provide FIFO behavior to read userfaults */
|
|
wq = list_last_entry(&wqh->head, typeof(*wq), entry);
|
|
uwq = container_of(wq, struct userfaultfd_wait_queue, wq);
|
|
out:
|
|
return uwq;
|
|
}
|
|
|
|
static inline struct userfaultfd_wait_queue *find_userfault(
|
|
struct userfaultfd_ctx *ctx)
|
|
{
|
|
return find_userfault_in(&ctx->fault_pending_wqh);
|
|
}
|
|
|
|
static inline struct userfaultfd_wait_queue *find_userfault_evt(
|
|
struct userfaultfd_ctx *ctx)
|
|
{
|
|
return find_userfault_in(&ctx->event_wqh);
|
|
}
|
|
|
|
static __poll_t userfaultfd_poll(struct file *file, poll_table *wait)
|
|
{
|
|
struct userfaultfd_ctx *ctx = file->private_data;
|
|
__poll_t ret;
|
|
|
|
poll_wait(file, &ctx->fd_wqh, wait);
|
|
|
|
switch (ctx->state) {
|
|
case UFFD_STATE_WAIT_API:
|
|
return EPOLLERR;
|
|
case UFFD_STATE_RUNNING:
|
|
/*
|
|
* poll() never guarantees that read won't block.
|
|
* userfaults can be waken before they're read().
|
|
*/
|
|
if (unlikely(!(file->f_flags & O_NONBLOCK)))
|
|
return EPOLLERR;
|
|
/*
|
|
* lockless access to see if there are pending faults
|
|
* __pollwait last action is the add_wait_queue but
|
|
* the spin_unlock would allow the waitqueue_active to
|
|
* pass above the actual list_add inside
|
|
* add_wait_queue critical section. So use a full
|
|
* memory barrier to serialize the list_add write of
|
|
* add_wait_queue() with the waitqueue_active read
|
|
* below.
|
|
*/
|
|
ret = 0;
|
|
smp_mb();
|
|
if (waitqueue_active(&ctx->fault_pending_wqh))
|
|
ret = EPOLLIN;
|
|
else if (waitqueue_active(&ctx->event_wqh))
|
|
ret = EPOLLIN;
|
|
|
|
return ret;
|
|
default:
|
|
WARN_ON_ONCE(1);
|
|
return EPOLLERR;
|
|
}
|
|
}
|
|
|
|
static const struct file_operations userfaultfd_fops;
|
|
|
|
static int resolve_userfault_fork(struct userfaultfd_ctx *ctx,
|
|
struct userfaultfd_ctx *new,
|
|
struct uffd_msg *msg)
|
|
{
|
|
int fd;
|
|
|
|
fd = anon_inode_getfd("[userfaultfd]", &userfaultfd_fops, new,
|
|
O_RDWR | (new->flags & UFFD_SHARED_FCNTL_FLAGS));
|
|
if (fd < 0)
|
|
return fd;
|
|
|
|
msg->arg.reserved.reserved1 = 0;
|
|
msg->arg.fork.ufd = fd;
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait,
|
|
struct uffd_msg *msg)
|
|
{
|
|
ssize_t ret;
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
struct userfaultfd_wait_queue *uwq;
|
|
/*
|
|
* Handling fork event requires sleeping operations, so
|
|
* we drop the event_wqh lock, then do these ops, then
|
|
* lock it back and wake up the waiter. While the lock is
|
|
* dropped the ewq may go away so we keep track of it
|
|
* carefully.
|
|
*/
|
|
LIST_HEAD(fork_event);
|
|
struct userfaultfd_ctx *fork_nctx = NULL;
|
|
|
|
/* always take the fd_wqh lock before the fault_pending_wqh lock */
|
|
spin_lock_irq(&ctx->fd_wqh.lock);
|
|
__add_wait_queue(&ctx->fd_wqh, &wait);
|
|
for (;;) {
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
spin_lock(&ctx->fault_pending_wqh.lock);
|
|
uwq = find_userfault(ctx);
|
|
if (uwq) {
|
|
/*
|
|
* Use a seqcount to repeat the lockless check
|
|
* in wake_userfault() to avoid missing
|
|
* wakeups because during the refile both
|
|
* waitqueue could become empty if this is the
|
|
* only userfault.
|
|
*/
|
|
write_seqcount_begin(&ctx->refile_seq);
|
|
|
|
/*
|
|
* The fault_pending_wqh.lock prevents the uwq
|
|
* to disappear from under us.
|
|
*
|
|
* Refile this userfault from
|
|
* fault_pending_wqh to fault_wqh, it's not
|
|
* pending anymore after we read it.
|
|
*
|
|
* Use list_del() by hand (as
|
|
* userfaultfd_wake_function also uses
|
|
* list_del_init() by hand) to be sure nobody
|
|
* changes __remove_wait_queue() to use
|
|
* list_del_init() in turn breaking the
|
|
* !list_empty_careful() check in
|
|
* handle_userfault(). The uwq->wq.head list
|
|
* must never be empty at any time during the
|
|
* refile, or the waitqueue could disappear
|
|
* from under us. The "wait_queue_head_t"
|
|
* parameter of __remove_wait_queue() is unused
|
|
* anyway.
|
|
*/
|
|
list_del(&uwq->wq.entry);
|
|
add_wait_queue(&ctx->fault_wqh, &uwq->wq);
|
|
|
|
write_seqcount_end(&ctx->refile_seq);
|
|
|
|
/* careful to always initialize msg if ret == 0 */
|
|
*msg = uwq->msg;
|
|
spin_unlock(&ctx->fault_pending_wqh.lock);
|
|
ret = 0;
|
|
break;
|
|
}
|
|
spin_unlock(&ctx->fault_pending_wqh.lock);
|
|
|
|
spin_lock(&ctx->event_wqh.lock);
|
|
uwq = find_userfault_evt(ctx);
|
|
if (uwq) {
|
|
*msg = uwq->msg;
|
|
|
|
if (uwq->msg.event == UFFD_EVENT_FORK) {
|
|
fork_nctx = (struct userfaultfd_ctx *)
|
|
(unsigned long)
|
|
uwq->msg.arg.reserved.reserved1;
|
|
list_move(&uwq->wq.entry, &fork_event);
|
|
/*
|
|
* fork_nctx can be freed as soon as
|
|
* we drop the lock, unless we take a
|
|
* reference on it.
|
|
*/
|
|
userfaultfd_ctx_get(fork_nctx);
|
|
spin_unlock(&ctx->event_wqh.lock);
|
|
ret = 0;
|
|
break;
|
|
}
|
|
|
|
userfaultfd_event_complete(ctx, uwq);
|
|
spin_unlock(&ctx->event_wqh.lock);
|
|
ret = 0;
|
|
break;
|
|
}
|
|
spin_unlock(&ctx->event_wqh.lock);
|
|
|
|
if (signal_pending(current)) {
|
|
ret = -ERESTARTSYS;
|
|
break;
|
|
}
|
|
if (no_wait) {
|
|
ret = -EAGAIN;
|
|
break;
|
|
}
|
|
spin_unlock_irq(&ctx->fd_wqh.lock);
|
|
schedule();
|
|
spin_lock_irq(&ctx->fd_wqh.lock);
|
|
}
|
|
__remove_wait_queue(&ctx->fd_wqh, &wait);
|
|
__set_current_state(TASK_RUNNING);
|
|
spin_unlock_irq(&ctx->fd_wqh.lock);
|
|
|
|
if (!ret && msg->event == UFFD_EVENT_FORK) {
|
|
ret = resolve_userfault_fork(ctx, fork_nctx, msg);
|
|
spin_lock_irq(&ctx->event_wqh.lock);
|
|
if (!list_empty(&fork_event)) {
|
|
/*
|
|
* The fork thread didn't abort, so we can
|
|
* drop the temporary refcount.
|
|
*/
|
|
userfaultfd_ctx_put(fork_nctx);
|
|
|
|
uwq = list_first_entry(&fork_event,
|
|
typeof(*uwq),
|
|
wq.entry);
|
|
/*
|
|
* If fork_event list wasn't empty and in turn
|
|
* the event wasn't already released by fork
|
|
* (the event is allocated on fork kernel
|
|
* stack), put the event back to its place in
|
|
* the event_wq. fork_event head will be freed
|
|
* as soon as we return so the event cannot
|
|
* stay queued there no matter the current
|
|
* "ret" value.
|
|
*/
|
|
list_del(&uwq->wq.entry);
|
|
__add_wait_queue(&ctx->event_wqh, &uwq->wq);
|
|
|
|
/*
|
|
* Leave the event in the waitqueue and report
|
|
* error to userland if we failed to resolve
|
|
* the userfault fork.
|
|
*/
|
|
if (likely(!ret))
|
|
userfaultfd_event_complete(ctx, uwq);
|
|
} else {
|
|
/*
|
|
* Here the fork thread aborted and the
|
|
* refcount from the fork thread on fork_nctx
|
|
* has already been released. We still hold
|
|
* the reference we took before releasing the
|
|
* lock above. If resolve_userfault_fork
|
|
* failed we've to drop it because the
|
|
* fork_nctx has to be freed in such case. If
|
|
* it succeeded we'll hold it because the new
|
|
* uffd references it.
|
|
*/
|
|
if (ret)
|
|
userfaultfd_ctx_put(fork_nctx);
|
|
}
|
|
spin_unlock_irq(&ctx->event_wqh.lock);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static ssize_t userfaultfd_read(struct file *file, char __user *buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct userfaultfd_ctx *ctx = file->private_data;
|
|
ssize_t _ret, ret = 0;
|
|
struct uffd_msg msg;
|
|
int no_wait = file->f_flags & O_NONBLOCK;
|
|
|
|
if (ctx->state == UFFD_STATE_WAIT_API)
|
|
return -EINVAL;
|
|
|
|
for (;;) {
|
|
if (count < sizeof(msg))
|
|
return ret ? ret : -EINVAL;
|
|
_ret = userfaultfd_ctx_read(ctx, no_wait, &msg);
|
|
if (_ret < 0)
|
|
return ret ? ret : _ret;
|
|
if (copy_to_user((__u64 __user *) buf, &msg, sizeof(msg)))
|
|
return ret ? ret : -EFAULT;
|
|
ret += sizeof(msg);
|
|
buf += sizeof(msg);
|
|
count -= sizeof(msg);
|
|
/*
|
|
* Allow to read more than one fault at time but only
|
|
* block if waiting for the very first one.
|
|
*/
|
|
no_wait = O_NONBLOCK;
|
|
}
|
|
}
|
|
|
|
static void __wake_userfault(struct userfaultfd_ctx *ctx,
|
|
struct userfaultfd_wake_range *range)
|
|
{
|
|
spin_lock_irq(&ctx->fault_pending_wqh.lock);
|
|
/* wake all in the range and autoremove */
|
|
if (waitqueue_active(&ctx->fault_pending_wqh))
|
|
__wake_up_locked_key(&ctx->fault_pending_wqh, TASK_NORMAL,
|
|
range);
|
|
if (waitqueue_active(&ctx->fault_wqh))
|
|
__wake_up(&ctx->fault_wqh, TASK_NORMAL, 1, range);
|
|
spin_unlock_irq(&ctx->fault_pending_wqh.lock);
|
|
}
|
|
|
|
static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx,
|
|
struct userfaultfd_wake_range *range)
|
|
{
|
|
unsigned seq;
|
|
bool need_wakeup;
|
|
|
|
/*
|
|
* To be sure waitqueue_active() is not reordered by the CPU
|
|
* before the pagetable update, use an explicit SMP memory
|
|
* barrier here. PT lock release or up_read(mmap_sem) still
|
|
* have release semantics that can allow the
|
|
* waitqueue_active() to be reordered before the pte update.
|
|
*/
|
|
smp_mb();
|
|
|
|
/*
|
|
* Use waitqueue_active because it's very frequent to
|
|
* change the address space atomically even if there are no
|
|
* userfaults yet. So we take the spinlock only when we're
|
|
* sure we've userfaults to wake.
|
|
*/
|
|
do {
|
|
seq = read_seqcount_begin(&ctx->refile_seq);
|
|
need_wakeup = waitqueue_active(&ctx->fault_pending_wqh) ||
|
|
waitqueue_active(&ctx->fault_wqh);
|
|
cond_resched();
|
|
} while (read_seqcount_retry(&ctx->refile_seq, seq));
|
|
if (need_wakeup)
|
|
__wake_userfault(ctx, range);
|
|
}
|
|
|
|
static __always_inline int validate_range(struct mm_struct *mm,
|
|
__u64 start, __u64 len)
|
|
{
|
|
__u64 task_size = mm->task_size;
|
|
|
|
if (start & ~PAGE_MASK)
|
|
return -EINVAL;
|
|
if (len & ~PAGE_MASK)
|
|
return -EINVAL;
|
|
if (!len)
|
|
return -EINVAL;
|
|
if (start < mmap_min_addr)
|
|
return -EINVAL;
|
|
if (start >= task_size)
|
|
return -EINVAL;
|
|
if (len > task_size - start)
|
|
return -EINVAL;
|
|
return 0;
|
|
}
|
|
|
|
static inline bool vma_can_userfault(struct vm_area_struct *vma)
|
|
{
|
|
return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) ||
|
|
vma_is_shmem(vma);
|
|
}
|
|
|
|
static int userfaultfd_register(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
struct mm_struct *mm = ctx->mm;
|
|
struct vm_area_struct *vma, *prev, *cur;
|
|
int ret;
|
|
struct uffdio_register uffdio_register;
|
|
struct uffdio_register __user *user_uffdio_register;
|
|
unsigned long vm_flags, new_flags;
|
|
bool found;
|
|
bool basic_ioctls;
|
|
unsigned long start, end, vma_end;
|
|
|
|
user_uffdio_register = (struct uffdio_register __user *) arg;
|
|
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_register, user_uffdio_register,
|
|
sizeof(uffdio_register)-sizeof(__u64)))
|
|
goto out;
|
|
|
|
ret = -EINVAL;
|
|
if (!uffdio_register.mode)
|
|
goto out;
|
|
if (uffdio_register.mode & ~(UFFDIO_REGISTER_MODE_MISSING|
|
|
UFFDIO_REGISTER_MODE_WP))
|
|
goto out;
|
|
vm_flags = 0;
|
|
if (uffdio_register.mode & UFFDIO_REGISTER_MODE_MISSING)
|
|
vm_flags |= VM_UFFD_MISSING;
|
|
if (uffdio_register.mode & UFFDIO_REGISTER_MODE_WP) {
|
|
vm_flags |= VM_UFFD_WP;
|
|
/*
|
|
* FIXME: remove the below error constraint by
|
|
* implementing the wprotect tracking mode.
|
|
*/
|
|
ret = -EINVAL;
|
|
goto out;
|
|
}
|
|
|
|
ret = validate_range(mm, uffdio_register.range.start,
|
|
uffdio_register.range.len);
|
|
if (ret)
|
|
goto out;
|
|
|
|
start = uffdio_register.range.start;
|
|
end = start + uffdio_register.range.len;
|
|
|
|
ret = -ENOMEM;
|
|
if (!mmget_not_zero(mm))
|
|
goto out;
|
|
|
|
down_write(&mm->mmap_sem);
|
|
if (!mmget_still_valid(mm))
|
|
goto out_unlock;
|
|
vma = find_vma_prev(mm, start, &prev);
|
|
if (!vma)
|
|
goto out_unlock;
|
|
|
|
/* check that there's at least one vma in the range */
|
|
ret = -EINVAL;
|
|
if (vma->vm_start >= end)
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* If the first vma contains huge pages, make sure start address
|
|
* is aligned to huge page size.
|
|
*/
|
|
if (is_vm_hugetlb_page(vma)) {
|
|
unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
|
|
|
|
if (start & (vma_hpagesize - 1))
|
|
goto out_unlock;
|
|
}
|
|
|
|
/*
|
|
* Search for not compatible vmas.
|
|
*/
|
|
found = false;
|
|
basic_ioctls = false;
|
|
for (cur = vma; cur && cur->vm_start < end; cur = cur->vm_next) {
|
|
cond_resched();
|
|
|
|
BUG_ON(!!cur->vm_userfaultfd_ctx.ctx ^
|
|
!!(cur->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP)));
|
|
|
|
/* check not compatible vmas */
|
|
ret = -EINVAL;
|
|
if (!vma_can_userfault(cur))
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* UFFDIO_COPY will fill file holes even without
|
|
* PROT_WRITE. This check enforces that if this is a
|
|
* MAP_SHARED, the process has write permission to the backing
|
|
* file. If VM_MAYWRITE is set it also enforces that on a
|
|
* MAP_SHARED vma: there is no F_WRITE_SEAL and no further
|
|
* F_WRITE_SEAL can be taken until the vma is destroyed.
|
|
*/
|
|
ret = -EPERM;
|
|
if (unlikely(!(cur->vm_flags & VM_MAYWRITE)))
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* If this vma contains ending address, and huge pages
|
|
* check alignment.
|
|
*/
|
|
if (is_vm_hugetlb_page(cur) && end <= cur->vm_end &&
|
|
end > cur->vm_start) {
|
|
unsigned long vma_hpagesize = vma_kernel_pagesize(cur);
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (end & (vma_hpagesize - 1))
|
|
goto out_unlock;
|
|
}
|
|
|
|
/*
|
|
* Check that this vma isn't already owned by a
|
|
* different userfaultfd. We can't allow more than one
|
|
* userfaultfd to own a single vma simultaneously or we
|
|
* wouldn't know which one to deliver the userfaults to.
|
|
*/
|
|
ret = -EBUSY;
|
|
if (cur->vm_userfaultfd_ctx.ctx &&
|
|
cur->vm_userfaultfd_ctx.ctx != ctx)
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* Note vmas containing huge pages
|
|
*/
|
|
if (is_vm_hugetlb_page(cur))
|
|
basic_ioctls = true;
|
|
|
|
found = true;
|
|
}
|
|
BUG_ON(!found);
|
|
|
|
if (vma->vm_start < start)
|
|
prev = vma;
|
|
|
|
ret = 0;
|
|
do {
|
|
cond_resched();
|
|
|
|
BUG_ON(!vma_can_userfault(vma));
|
|
BUG_ON(vma->vm_userfaultfd_ctx.ctx &&
|
|
vma->vm_userfaultfd_ctx.ctx != ctx);
|
|
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
|
|
|
|
/*
|
|
* Nothing to do: this vma is already registered into this
|
|
* userfaultfd and with the right tracking mode too.
|
|
*/
|
|
if (vma->vm_userfaultfd_ctx.ctx == ctx &&
|
|
(vma->vm_flags & vm_flags) == vm_flags)
|
|
goto skip;
|
|
|
|
if (vma->vm_start > start)
|
|
start = vma->vm_start;
|
|
vma_end = min(end, vma->vm_end);
|
|
|
|
new_flags = (vma->vm_flags & ~vm_flags) | vm_flags;
|
|
prev = vma_merge(mm, prev, start, vma_end, new_flags,
|
|
vma->anon_vma, vma->vm_file, vma->vm_pgoff,
|
|
vma_policy(vma),
|
|
((struct vm_userfaultfd_ctx){ ctx }),
|
|
vma_get_anon_name(vma));
|
|
if (prev) {
|
|
vma = prev;
|
|
goto next;
|
|
}
|
|
if (vma->vm_start < start) {
|
|
ret = split_vma(mm, vma, start, 1);
|
|
if (ret)
|
|
break;
|
|
}
|
|
if (vma->vm_end > end) {
|
|
ret = split_vma(mm, vma, end, 0);
|
|
if (ret)
|
|
break;
|
|
}
|
|
next:
|
|
/*
|
|
* In the vma_merge() successful mprotect-like case 8:
|
|
* the next vma was merged into the current one and
|
|
* the current one has not been updated yet.
|
|
*/
|
|
vm_write_begin(vma);
|
|
WRITE_ONCE(vma->vm_flags, new_flags);
|
|
vma->vm_userfaultfd_ctx.ctx = ctx;
|
|
vm_write_end(vma);
|
|
|
|
skip:
|
|
prev = vma;
|
|
start = vma->vm_end;
|
|
vma = vma->vm_next;
|
|
} while (vma && vma->vm_start < end);
|
|
out_unlock:
|
|
up_write(&mm->mmap_sem);
|
|
mmput(mm);
|
|
if (!ret) {
|
|
/*
|
|
* Now that we scanned all vmas we can already tell
|
|
* userland which ioctls methods are guaranteed to
|
|
* succeed on this range.
|
|
*/
|
|
if (put_user(basic_ioctls ? UFFD_API_RANGE_IOCTLS_BASIC :
|
|
UFFD_API_RANGE_IOCTLS,
|
|
&user_uffdio_register->ioctls))
|
|
ret = -EFAULT;
|
|
}
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
struct mm_struct *mm = ctx->mm;
|
|
struct vm_area_struct *vma, *prev, *cur;
|
|
int ret;
|
|
struct uffdio_range uffdio_unregister;
|
|
unsigned long new_flags;
|
|
bool found;
|
|
unsigned long start, end, vma_end;
|
|
const void __user *buf = (void __user *)arg;
|
|
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_unregister, buf, sizeof(uffdio_unregister)))
|
|
goto out;
|
|
|
|
ret = validate_range(mm, uffdio_unregister.start,
|
|
uffdio_unregister.len);
|
|
if (ret)
|
|
goto out;
|
|
|
|
start = uffdio_unregister.start;
|
|
end = start + uffdio_unregister.len;
|
|
|
|
ret = -ENOMEM;
|
|
if (!mmget_not_zero(mm))
|
|
goto out;
|
|
|
|
down_write(&mm->mmap_sem);
|
|
if (!mmget_still_valid(mm))
|
|
goto out_unlock;
|
|
vma = find_vma_prev(mm, start, &prev);
|
|
if (!vma)
|
|
goto out_unlock;
|
|
|
|
/* check that there's at least one vma in the range */
|
|
ret = -EINVAL;
|
|
if (vma->vm_start >= end)
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* If the first vma contains huge pages, make sure start address
|
|
* is aligned to huge page size.
|
|
*/
|
|
if (is_vm_hugetlb_page(vma)) {
|
|
unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
|
|
|
|
if (start & (vma_hpagesize - 1))
|
|
goto out_unlock;
|
|
}
|
|
|
|
/*
|
|
* Search for not compatible vmas.
|
|
*/
|
|
found = false;
|
|
ret = -EINVAL;
|
|
for (cur = vma; cur && cur->vm_start < end; cur = cur->vm_next) {
|
|
cond_resched();
|
|
|
|
BUG_ON(!!cur->vm_userfaultfd_ctx.ctx ^
|
|
!!(cur->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP)));
|
|
|
|
/*
|
|
* Check not compatible vmas, not strictly required
|
|
* here as not compatible vmas cannot have an
|
|
* userfaultfd_ctx registered on them, but this
|
|
* provides for more strict behavior to notice
|
|
* unregistration errors.
|
|
*/
|
|
if (!vma_can_userfault(cur))
|
|
goto out_unlock;
|
|
|
|
found = true;
|
|
}
|
|
BUG_ON(!found);
|
|
|
|
if (vma->vm_start < start)
|
|
prev = vma;
|
|
|
|
ret = 0;
|
|
do {
|
|
cond_resched();
|
|
|
|
BUG_ON(!vma_can_userfault(vma));
|
|
|
|
/*
|
|
* Nothing to do: this vma is already registered into this
|
|
* userfaultfd and with the right tracking mode too.
|
|
*/
|
|
if (!vma->vm_userfaultfd_ctx.ctx)
|
|
goto skip;
|
|
|
|
WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
|
|
|
|
if (vma->vm_start > start)
|
|
start = vma->vm_start;
|
|
vma_end = min(end, vma->vm_end);
|
|
|
|
if (userfaultfd_missing(vma)) {
|
|
/*
|
|
* Wake any concurrent pending userfault while
|
|
* we unregister, so they will not hang
|
|
* permanently and it avoids userland to call
|
|
* UFFDIO_WAKE explicitly.
|
|
*/
|
|
struct userfaultfd_wake_range range;
|
|
range.start = start;
|
|
range.len = vma_end - start;
|
|
wake_userfault(vma->vm_userfaultfd_ctx.ctx, &range);
|
|
}
|
|
|
|
new_flags = vma->vm_flags & ~(VM_UFFD_MISSING | VM_UFFD_WP);
|
|
prev = vma_merge(mm, prev, start, vma_end, new_flags,
|
|
vma->anon_vma, vma->vm_file, vma->vm_pgoff,
|
|
vma_policy(vma),
|
|
NULL_VM_UFFD_CTX,
|
|
vma_get_anon_name(vma));
|
|
if (prev) {
|
|
vma = prev;
|
|
goto next;
|
|
}
|
|
if (vma->vm_start < start) {
|
|
ret = split_vma(mm, vma, start, 1);
|
|
if (ret)
|
|
break;
|
|
}
|
|
if (vma->vm_end > end) {
|
|
ret = split_vma(mm, vma, end, 0);
|
|
if (ret)
|
|
break;
|
|
}
|
|
next:
|
|
/*
|
|
* In the vma_merge() successful mprotect-like case 8:
|
|
* the next vma was merged into the current one and
|
|
* the current one has not been updated yet.
|
|
*/
|
|
vm_write_begin(vma);
|
|
WRITE_ONCE(vma->vm_flags, new_flags);
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
vm_write_end(vma);
|
|
|
|
skip:
|
|
prev = vma;
|
|
start = vma->vm_end;
|
|
vma = vma->vm_next;
|
|
} while (vma && vma->vm_start < end);
|
|
out_unlock:
|
|
up_write(&mm->mmap_sem);
|
|
mmput(mm);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* userfaultfd_wake may be used in combination with the
|
|
* UFFDIO_*_MODE_DONTWAKE to wakeup userfaults in batches.
|
|
*/
|
|
static int userfaultfd_wake(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
int ret;
|
|
struct uffdio_range uffdio_wake;
|
|
struct userfaultfd_wake_range range;
|
|
const void __user *buf = (void __user *)arg;
|
|
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_wake, buf, sizeof(uffdio_wake)))
|
|
goto out;
|
|
|
|
ret = validate_range(ctx->mm, uffdio_wake.start, uffdio_wake.len);
|
|
if (ret)
|
|
goto out;
|
|
|
|
range.start = uffdio_wake.start;
|
|
range.len = uffdio_wake.len;
|
|
|
|
/*
|
|
* len == 0 means wake all and we don't want to wake all here,
|
|
* so check it again to be sure.
|
|
*/
|
|
VM_BUG_ON(!range.len);
|
|
|
|
wake_userfault(ctx, &range);
|
|
ret = 0;
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static int userfaultfd_copy(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
__s64 ret;
|
|
struct uffdio_copy uffdio_copy;
|
|
struct uffdio_copy __user *user_uffdio_copy;
|
|
struct userfaultfd_wake_range range;
|
|
|
|
user_uffdio_copy = (struct uffdio_copy __user *) arg;
|
|
|
|
ret = -EAGAIN;
|
|
if (READ_ONCE(ctx->mmap_changing))
|
|
goto out;
|
|
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_copy, user_uffdio_copy,
|
|
/* don't copy "copy" last field */
|
|
sizeof(uffdio_copy)-sizeof(__s64)))
|
|
goto out;
|
|
|
|
ret = validate_range(ctx->mm, uffdio_copy.dst, uffdio_copy.len);
|
|
if (ret)
|
|
goto out;
|
|
/*
|
|
* double check for wraparound just in case. copy_from_user()
|
|
* will later check uffdio_copy.src + uffdio_copy.len to fit
|
|
* in the userland range.
|
|
*/
|
|
ret = -EINVAL;
|
|
if (uffdio_copy.src + uffdio_copy.len <= uffdio_copy.src)
|
|
goto out;
|
|
if (uffdio_copy.mode & ~UFFDIO_COPY_MODE_DONTWAKE)
|
|
goto out;
|
|
if (mmget_not_zero(ctx->mm)) {
|
|
ret = mcopy_atomic(ctx->mm, uffdio_copy.dst, uffdio_copy.src,
|
|
uffdio_copy.len, &ctx->mmap_changing);
|
|
mmput(ctx->mm);
|
|
} else {
|
|
return -ESRCH;
|
|
}
|
|
if (unlikely(put_user(ret, &user_uffdio_copy->copy)))
|
|
return -EFAULT;
|
|
if (ret < 0)
|
|
goto out;
|
|
BUG_ON(!ret);
|
|
/* len == 0 would wake all */
|
|
range.len = ret;
|
|
if (!(uffdio_copy.mode & UFFDIO_COPY_MODE_DONTWAKE)) {
|
|
range.start = uffdio_copy.dst;
|
|
wake_userfault(ctx, &range);
|
|
}
|
|
ret = range.len == uffdio_copy.len ? 0 : -EAGAIN;
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
__s64 ret;
|
|
struct uffdio_zeropage uffdio_zeropage;
|
|
struct uffdio_zeropage __user *user_uffdio_zeropage;
|
|
struct userfaultfd_wake_range range;
|
|
|
|
user_uffdio_zeropage = (struct uffdio_zeropage __user *) arg;
|
|
|
|
ret = -EAGAIN;
|
|
if (READ_ONCE(ctx->mmap_changing))
|
|
goto out;
|
|
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_zeropage, user_uffdio_zeropage,
|
|
/* don't copy "zeropage" last field */
|
|
sizeof(uffdio_zeropage)-sizeof(__s64)))
|
|
goto out;
|
|
|
|
ret = validate_range(ctx->mm, uffdio_zeropage.range.start,
|
|
uffdio_zeropage.range.len);
|
|
if (ret)
|
|
goto out;
|
|
ret = -EINVAL;
|
|
if (uffdio_zeropage.mode & ~UFFDIO_ZEROPAGE_MODE_DONTWAKE)
|
|
goto out;
|
|
|
|
if (mmget_not_zero(ctx->mm)) {
|
|
ret = mfill_zeropage(ctx->mm, uffdio_zeropage.range.start,
|
|
uffdio_zeropage.range.len,
|
|
&ctx->mmap_changing);
|
|
mmput(ctx->mm);
|
|
} else {
|
|
return -ESRCH;
|
|
}
|
|
if (unlikely(put_user(ret, &user_uffdio_zeropage->zeropage)))
|
|
return -EFAULT;
|
|
if (ret < 0)
|
|
goto out;
|
|
/* len == 0 would wake all */
|
|
BUG_ON(!ret);
|
|
range.len = ret;
|
|
if (!(uffdio_zeropage.mode & UFFDIO_ZEROPAGE_MODE_DONTWAKE)) {
|
|
range.start = uffdio_zeropage.range.start;
|
|
wake_userfault(ctx, &range);
|
|
}
|
|
ret = range.len == uffdio_zeropage.range.len ? 0 : -EAGAIN;
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static inline unsigned int uffd_ctx_features(__u64 user_features)
|
|
{
|
|
/*
|
|
* For the current set of features the bits just coincide
|
|
*/
|
|
return (unsigned int)user_features;
|
|
}
|
|
|
|
/*
|
|
* userland asks for a certain API version and we return which bits
|
|
* and ioctl commands are implemented in this kernel for such API
|
|
* version or -EINVAL if unknown.
|
|
*/
|
|
static int userfaultfd_api(struct userfaultfd_ctx *ctx,
|
|
unsigned long arg)
|
|
{
|
|
struct uffdio_api uffdio_api;
|
|
void __user *buf = (void __user *)arg;
|
|
int ret;
|
|
__u64 features;
|
|
|
|
ret = -EINVAL;
|
|
if (ctx->state != UFFD_STATE_WAIT_API)
|
|
goto out;
|
|
ret = -EFAULT;
|
|
if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api)))
|
|
goto out;
|
|
features = uffdio_api.features;
|
|
ret = -EINVAL;
|
|
if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES))
|
|
goto err_out;
|
|
ret = -EPERM;
|
|
if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE))
|
|
goto err_out;
|
|
/* report all available features and ioctls to userland */
|
|
uffdio_api.features = UFFD_API_FEATURES;
|
|
uffdio_api.ioctls = UFFD_API_IOCTLS;
|
|
ret = -EFAULT;
|
|
if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
|
|
goto out;
|
|
ctx->state = UFFD_STATE_RUNNING;
|
|
/* only enable the requested features for this uffd context */
|
|
ctx->features = uffd_ctx_features(features);
|
|
ret = 0;
|
|
out:
|
|
return ret;
|
|
err_out:
|
|
memset(&uffdio_api, 0, sizeof(uffdio_api));
|
|
if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
|
|
ret = -EFAULT;
|
|
goto out;
|
|
}
|
|
|
|
static long userfaultfd_ioctl(struct file *file, unsigned cmd,
|
|
unsigned long arg)
|
|
{
|
|
int ret = -EINVAL;
|
|
struct userfaultfd_ctx *ctx = file->private_data;
|
|
|
|
if (cmd != UFFDIO_API && ctx->state == UFFD_STATE_WAIT_API)
|
|
return -EINVAL;
|
|
|
|
switch(cmd) {
|
|
case UFFDIO_API:
|
|
ret = userfaultfd_api(ctx, arg);
|
|
break;
|
|
case UFFDIO_REGISTER:
|
|
ret = userfaultfd_register(ctx, arg);
|
|
break;
|
|
case UFFDIO_UNREGISTER:
|
|
ret = userfaultfd_unregister(ctx, arg);
|
|
break;
|
|
case UFFDIO_WAKE:
|
|
ret = userfaultfd_wake(ctx, arg);
|
|
break;
|
|
case UFFDIO_COPY:
|
|
ret = userfaultfd_copy(ctx, arg);
|
|
break;
|
|
case UFFDIO_ZEROPAGE:
|
|
ret = userfaultfd_zeropage(ctx, arg);
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
static void userfaultfd_show_fdinfo(struct seq_file *m, struct file *f)
|
|
{
|
|
struct userfaultfd_ctx *ctx = f->private_data;
|
|
wait_queue_entry_t *wq;
|
|
unsigned long pending = 0, total = 0;
|
|
|
|
spin_lock_irq(&ctx->fault_pending_wqh.lock);
|
|
list_for_each_entry(wq, &ctx->fault_pending_wqh.head, entry) {
|
|
pending++;
|
|
total++;
|
|
}
|
|
list_for_each_entry(wq, &ctx->fault_wqh.head, entry) {
|
|
total++;
|
|
}
|
|
spin_unlock_irq(&ctx->fault_pending_wqh.lock);
|
|
|
|
/*
|
|
* If more protocols will be added, there will be all shown
|
|
* separated by a space. Like this:
|
|
* protocols: aa:... bb:...
|
|
*/
|
|
seq_printf(m, "pending:\t%lu\ntotal:\t%lu\nAPI:\t%Lx:%x:%Lx\n",
|
|
pending, total, UFFD_API, ctx->features,
|
|
UFFD_API_IOCTLS|UFFD_API_RANGE_IOCTLS);
|
|
}
|
|
#endif
|
|
|
|
static const struct file_operations userfaultfd_fops = {
|
|
#ifdef CONFIG_PROC_FS
|
|
.show_fdinfo = userfaultfd_show_fdinfo,
|
|
#endif
|
|
.release = userfaultfd_release,
|
|
.poll = userfaultfd_poll,
|
|
.read = userfaultfd_read,
|
|
.unlocked_ioctl = userfaultfd_ioctl,
|
|
.compat_ioctl = userfaultfd_ioctl,
|
|
.llseek = noop_llseek,
|
|
};
|
|
|
|
static void init_once_userfaultfd_ctx(void *mem)
|
|
{
|
|
struct userfaultfd_ctx *ctx = (struct userfaultfd_ctx *) mem;
|
|
|
|
init_waitqueue_head(&ctx->fault_pending_wqh);
|
|
init_waitqueue_head(&ctx->fault_wqh);
|
|
init_waitqueue_head(&ctx->event_wqh);
|
|
init_waitqueue_head(&ctx->fd_wqh);
|
|
seqcount_init(&ctx->refile_seq);
|
|
}
|
|
|
|
SYSCALL_DEFINE1(userfaultfd, int, flags)
|
|
{
|
|
struct userfaultfd_ctx *ctx;
|
|
int fd;
|
|
|
|
if (!sysctl_unprivileged_userfaultfd && !capable(CAP_SYS_PTRACE))
|
|
return -EPERM;
|
|
|
|
BUG_ON(!current->mm);
|
|
|
|
/* Check the UFFD_* constants for consistency. */
|
|
BUILD_BUG_ON(UFFD_CLOEXEC != O_CLOEXEC);
|
|
BUILD_BUG_ON(UFFD_NONBLOCK != O_NONBLOCK);
|
|
|
|
if (flags & ~UFFD_SHARED_FCNTL_FLAGS)
|
|
return -EINVAL;
|
|
|
|
ctx = kmem_cache_alloc(userfaultfd_ctx_cachep, GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
|
|
refcount_set(&ctx->refcount, 1);
|
|
ctx->flags = flags;
|
|
ctx->features = 0;
|
|
ctx->state = UFFD_STATE_WAIT_API;
|
|
ctx->released = false;
|
|
ctx->mmap_changing = false;
|
|
ctx->mm = current->mm;
|
|
/* prevent the mm struct to be freed */
|
|
mmgrab(ctx->mm);
|
|
|
|
fd = anon_inode_getfd("[userfaultfd]", &userfaultfd_fops, ctx,
|
|
O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
|
|
if (fd < 0) {
|
|
mmdrop(ctx->mm);
|
|
kmem_cache_free(userfaultfd_ctx_cachep, ctx);
|
|
}
|
|
return fd;
|
|
}
|
|
|
|
static int __init userfaultfd_init(void)
|
|
{
|
|
userfaultfd_ctx_cachep = kmem_cache_create("userfaultfd_ctx_cache",
|
|
sizeof(struct userfaultfd_ctx),
|
|
0,
|
|
SLAB_HWCACHE_ALIGN|SLAB_PANIC,
|
|
init_once_userfaultfd_ctx);
|
|
return 0;
|
|
}
|
|
__initcall(userfaultfd_init);
|