Changes in 5.15.33
Revert "swiotlb: rework "fix info leak with DMA_FROM_DEVICE""
USB: serial: pl2303: add IBM device IDs
dt-bindings: usb: hcd: correct usb-device path
USB: serial: pl2303: fix GS type detection
USB: serial: simple: add Nokia phone driver
mm: kfence: fix missing objcg housekeeping for SLAB
hv: utils: add PTP_1588_CLOCK to Kconfig to fix build
HID: logitech-dj: add new lightspeed receiver id
HID: Add support for open wheel and no attachment to T300
xfrm: fix tunnel model fragmentation behavior
ARM: mstar: Select HAVE_ARM_ARCH_TIMER
virtio_console: break out of buf poll on remove
vdpa/mlx5: should verify CTRL_VQ feature exists for MQ
tools/virtio: fix virtio_test execution
ethernet: sun: Free the coherent when failing in probing
gpio: Revert regression in sysfs-gpio (gpiolib.c)
spi: Fix invalid sgs value
net:mcf8390: Use platform_get_irq() to get the interrupt
Revert "gpio: Revert regression in sysfs-gpio (gpiolib.c)"
spi: Fix erroneous sgs value with min_t()
Input: zinitix - do not report shadow fingers
af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register
net: dsa: microchip: add spi_device_id tables
selftests: vm: fix clang build error multiple output files
locking/lockdep: Avoid potential access of invalid memory in lock_class
drm/amdgpu: move PX checking into amdgpu_device_ip_early_init
drm/amdgpu: only check for _PR3 on dGPUs
iommu/iova: Improve 32-bit free space estimate
virtio-blk: Use blk_validate_block_size() to validate block size
tpm: fix reference counting for struct tpm_chip
usb: typec: tipd: Forward plug orientation to typec subsystem
USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c
xhci: fix garbage USBSTS being logged in some cases
xhci: fix runtime PM imbalance in USB2 resume
xhci: make xhci_handshake timeout for xhci_reset() adjustable
xhci: fix uninitialized string returned by xhci_decode_ctrl_ctx()
mei: me: disable driver on the ign firmware
mei: me: add Alder Lake N device id.
mei: avoid iterator usage outside of list_for_each_entry
bus: mhi: pci_generic: Add mru_default for Quectel EM1xx series
bus: mhi: Fix MHI DMA structure endianness
docs: sphinx/requirements: Limit jinja2<3.1
coresight: Fix TRCCONFIGR.QE sysfs interface
coresight: syscfg: Fix memleak on registration failure in cscfg_create_device
iio: afe: rescale: use s64 for temporary scale calculations
iio: inkern: apply consumer scale on IIO_VAL_INT cases
iio: inkern: apply consumer scale when no channel scale is available
iio: inkern: make a best effort on offset calculation
greybus: svc: fix an error handling bug in gb_svc_hello()
clk: rockchip: re-add rational best approximation algorithm to the fractional divider
clk: uniphier: Fix fixed-rate initialization
ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE
cifs: fix handlecache and multiuser
cifs: we do not need a spinlock around the tree access during umount
KEYS: fix length validation in keyctl_pkey_params_get_2()
KEYS: asymmetric: enforce that sig algo matches key algo
KEYS: asymmetric: properly validate hash_algo and encoding
Documentation: add link to stable release candidate tree
Documentation: update stable tree link
firmware: stratix10-svc: add missing callback parameter on RSU
firmware: sysfb: fix platform-device leak in error path
HID: intel-ish-hid: Use dma_alloc_coherent for firmware update
SUNRPC: avoid race between mod_timer() and del_timer_sync()
NFS: NFSv2/v3 clients should never be setting NFS_CAP_XATTR
NFSD: prevent underflow in nfssvc_decode_writeargs()
NFSD: prevent integer overflow on 32 bit systems
f2fs: fix to unlock page correctly in error path of is_alive()
f2fs: quota: fix loop condition at f2fs_quota_sync()
f2fs: fix to do sanity check on .cp_pack_total_block_count
remoteproc: Fix count check in rproc_coredump_write()
mm/mlock: fix two bugs in user_shm_lock()
pinctrl: ingenic: Fix regmap on X series SoCs
pinctrl: samsung: drop pin banks references on error paths
net: bnxt_ptp: fix compilation error
spi: mxic: Fix the transmit path
mtd: rawnand: protect access to rawnand devices while in suspend
can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path
can: m_can: m_can_tx_handler(): fix use after free of skb
can: usb_8dev: usb_8dev_start_xmit(): fix double dev_kfree_skb() in error path
jffs2: fix use-after-free in jffs2_clear_xattr_subsystem
jffs2: fix memory leak in jffs2_do_mount_fs
jffs2: fix memory leak in jffs2_scan_medium
mm: fs: fix lru_cache_disabled race in bh_lru
mm/pages_alloc.c: don't create ZONE_MOVABLE beyond the end of a node
mm: invalidate hwpoison page cache page in fault path
mempolicy: mbind_range() set_policy() after vma_merge()
scsi: core: sd: Add silence_suspend flag to suppress some PM messages
scsi: ufs: Fix runtime PM messages never-ending cycle
scsi: scsi_transport_fc: Fix FPIN Link Integrity statistics counters
scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands
qed: display VF trust config
qed: validate and restrict untrusted VFs vlan promisc mode
riscv: dts: canaan: Fix SPI3 bus width
riscv: Fix fill_callchain return value
riscv: Increase stack size under KASAN
Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads"
cifs: prevent bad output lengths in smb2_ioctl_query_info()
cifs: fix NULL ptr dereference in smb2_ioctl_query_info()
ALSA: cs4236: fix an incorrect NULL check on list iterator
ALSA: hda: Avoid unsol event during RPM suspending
ALSA: pcm: Fix potential AB/BA lock with buffer_mutex and mmap_lock
ALSA: hda/realtek: Fix audio regression on Mi Notebook Pro 2020
rtc: mc146818-lib: fix locking in mc146818_set_time
rtc: pl031: fix rtc features null pointer dereference
ocfs2: fix crash when mount with quota enabled
drm/simpledrm: Add "panel orientation" property on non-upright mounted LCD panels
mm: madvise: skip unmapped vma holes passed to process_madvise
mm: madvise: return correct bytes advised with process_madvise
Revert "mm: madvise: skip unmapped vma holes passed to process_madvise"
mm,hwpoison: unmap poisoned page before invalidation
mm/kmemleak: reset tag when compare object pointer
dm stats: fix too short end duration_ns when using precise_timestamps
dm: fix use-after-free in dm_cleanup_zoned_dev()
dm: interlock pending dm_io and dm_wait_for_bios_completion
dm: fix double accounting of flush with data
dm integrity: set journal entry unused when shrinking device
tracing: Have trace event string test handle zero length strings
drbd: fix potential silent data corruption
powerpc/kvm: Fix kvm_use_magic_page
PCI: fu740: Force 2.5GT/s for initial device probe
arm64: signal: nofpsimd: Do not allocate fp/simd context when not available
arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones
arm64: dts: qcom: sm8250: Fix MSI IRQ for PCIe1 and PCIe2
arm64: dts: ti: k3-am65: Fix gic-v3 compatible regs
arm64: dts: ti: k3-j721e: Fix gic-v3 compatible regs
arm64: dts: ti: k3-j7200: Fix gic-v3 compatible regs
arm64: dts: ti: k3-am64: Fix gic-v3 compatible regs
ASoC: SOF: Intel: Fix NULL ptr dereference when ENOMEM
Revert "ACPI: Pass the same capabilities to the _OSC regardless of the query flag"
ACPI: properties: Consistently return -ENOENT if there are no more references
coredump: Also dump first pages of non-executable ELF libraries
ext4: fix ext4_fc_stats trace point
ext4: fix fs corruption when tring to remove a non-empty directory with IO error
ext4: make mb_optimize_scan performance mount option work with extents
drivers: hamradio: 6pack: fix UAF bug caused by mod_timer()
samples/landlock: Fix path_list memory leak
landlock: Use square brackets around "landlock-ruleset"
mailbox: tegra-hsp: Flush whole channel
block: limit request dispatch loop duration
block: don't merge across cgroup boundaries if blkcg is enabled
drm/edid: check basic audio support on CEA extension block
fbdev: Hot-unplug firmware fb devices on forced removal
video: fbdev: sm712fb: Fix crash in smtcfb_read()
video: fbdev: atari: Atari 2 bpp (STe) palette bugfix
rfkill: make new event layout opt-in
ARM: dts: at91: sama7g5: Remove unused properties in i2c nodes
ARM: dts: at91: sama5d2: Fix PMERRLOC resource size
ARM: dts: exynos: fix UART3 pins configuration in Exynos5250
ARM: dts: exynos: add missing HDMI supplies on SMDK5250
ARM: dts: exynos: add missing HDMI supplies on SMDK5420
mgag200 fix memmapsl configuration in GCTL6 register
carl9170: fix missing bit-wise or operator for tx_params
pstore: Don't use semaphores in always-atomic-context code
thermal: int340x: Increase bitmap size
lib/raid6/test: fix multiple definition linking error
exec: Force single empty string when argv is empty
crypto: rsa-pkcs1pad - only allow with rsa
crypto: rsa-pkcs1pad - correctly get hash from source scatterlist
crypto: rsa-pkcs1pad - restore signature length check
crypto: rsa-pkcs1pad - fix buffer overread in pkcs1pad_verify_complete()
bcache: fixup multiple threads crash
PM: domains: Fix sleep-in-atomic bug caused by genpd_debug_remove()
DEC: Limit PMAX memory probing to R3k systems
media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC
media: venus: hfi_cmds: List HDR10 property as unsupported for v1 and v3
media: venus: venc: Fix h264 8x8 transform control
media: davinci: vpif: fix unbalanced runtime PM get
media: davinci: vpif: fix unbalanced runtime PM enable
btrfs: zoned: mark relocation as writing
btrfs: extend locking to all space_info members accesses
btrfs: verify the tranisd of the to-be-written dirty extent buffer
xtensa: define update_mmu_tlb function
xtensa: fix stop_machine_cpuslocked call in patch_text
xtensa: fix xtensa_wsr always writing 0
drm/syncobj: flatten dma_fence_chains on transfer
drm/nouveau/backlight: Fix LVDS backlight detection on some laptops
drm/nouveau/backlight: Just set all backlight types as RAW
drm/fb-helper: Mark screen buffers in system memory with FBINFO_VIRTFB
brcmfmac: firmware: Allocate space for default boardrev in nvram
brcmfmac: pcie: Release firmwares in the brcmf_pcie_setup error path
brcmfmac: pcie: Declare missing firmware files in pcie.c
brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio
brcmfmac: pcie: Fix crashes due to early IRQs
drm/i915/opregion: check port number bounds for SWSCI display power state
drm/i915/gem: add missing boundary check in vm_access
PCI: imx6: Allow to probe when dw_pcie_wait_for_link() fails
PCI: pciehp: Clear cmd_busy bit in polling mode
PCI: xgene: Revert "PCI: xgene: Fix IB window setup"
regulator: qcom_smd: fix for_each_child.cocci warnings
selinux: access superblock_security_struct in LSM blob way
selinux: check return value of sel_make_avc_files
crypto: ccp - Ensure psp_ret is always init'd in __sev_platform_init_locked()
hwrng: cavium - Check health status while reading random data
hwrng: cavium - HW_RANDOM_CAVIUM should depend on ARCH_THUNDER
crypto: sun8i-ss - really disable hash on A80
crypto: authenc - Fix sleep in atomic context in decrypt_tail
crypto: mxs-dcp - Fix scatterlist processing
selinux: Fix selinux_sb_mnt_opts_compat()
thermal: int340x: Check for NULL after calling kmemdup()
crypto: octeontx2 - remove CONFIG_DM_CRYPT check
spi: tegra114: Add missing IRQ check in tegra_spi_probe
spi: tegra210-quad: Fix missin IRQ check in tegra_qspi_probe
stack: Constrain and fix stack offset randomization with Clang builds
arm64/mm: avoid fixmap race condition when create pud mapping
blk-cgroup: set blkg iostat after percpu stat aggregation
selftests/x86: Add validity check and allow field splitting
selftests/sgx: Treat CC as one argument
crypto: rockchip - ECB does not need IV
audit: log AUDIT_TIME_* records only from rules
EVM: fix the evm= __setup handler return value
crypto: ccree - don't attempt 0 len DMA mappings
crypto: hisilicon/sec - fix the aead software fallback for engine
spi: pxa2xx-pci: Balance reference count for PCI DMA device
hwmon: (pmbus) Add mutex to regulator ops
hwmon: (sch56xx-common) Replace WDOG_ACTIVE with WDOG_HW_RUNNING
nvme: cleanup __nvme_check_ids
nvme: fix the check for duplicate unique identifiers
block: don't delete queue kobject before its children
PM: hibernate: fix __setup handler error handling
PM: suspend: fix return value of __setup handler
spi: spi-zynqmp-gqspi: Handle error for dma_set_mask
hwrng: atmel - disable trng on failure path
crypto: sun8i-ss - call finalize with bh disabled
crypto: sun8i-ce - call finalize with bh disabled
crypto: amlogic - call finalize with bh disabled
crypto: gemini - call finalize with bh disabled
crypto: vmx - add missing dependencies
clocksource/drivers/timer-ti-dm: Fix regression from errata i940 fix
clocksource/drivers/exynos_mct: Refactor resources allocation
clocksource/drivers/exynos_mct: Handle DTS with higher number of interrupts
clocksource/drivers/timer-microchip-pit64b: Use notrace
clocksource/drivers/timer-of: Check return value of of_iomap in timer_of_base_init()
arm64: prevent instrumentation of bp hardening callbacks
KEYS: trusted: Fix trusted key backends when building as module
KEYS: trusted: Avoid calling null function trusted_key_exit
ACPI: APEI: fix return value of __setup handlers
crypto: ccp - ccp_dmaengine_unregister release dma channels
crypto: ccree - Fix use after free in cc_cipher_exit()
hwrng: nomadik - Change clk_disable to clk_disable_unprepare
hwmon: (pmbus) Add Vin unit off handling
clocksource: acpi_pm: fix return value of __setup handler
io_uring: don't check unrelated req->open.how in accept request
io_uring: terminate manual loop iterator loop correctly for non-vecs
watch_queue: Fix NULL dereference in error cleanup
watch_queue: Actually free the watch
f2fs: fix to enable ATGC correctly via gc_idle sysfs interface
sched/debug: Remove mpol_get/put and task_lock/unlock from sched_show_numa
sched/core: Export pelt_thermal_tp
sched/uclamp: Fix iowait boost escaping uclamp restriction
rseq: Remove broken uapi field layout on 32-bit little endian
perf/core: Fix address filter parser for multiple filters
perf/x86/intel/pt: Fix address filter config for 32-bit kernel
sched/fair: Improve consistency of allowed NUMA balance calculations
f2fs: fix missing free nid in f2fs_handle_failed_inode
nfsd: more robust allocation failure handling in nfsd_file_cache_init
sched/cpuacct: Fix charge percpu cpuusage
sched/rt: Plug rt_mutex_setprio() vs push_rt_task() race
f2fs: fix to avoid potential deadlock
btrfs: fix unexpected error path when reflinking an inline extent
f2fs: fix compressed file start atomic write may cause data corruption
selftests, x86: fix how check_cc.sh is being invoked
drivers/base/memory: add memory block to memory group after registration succeeded
kunit: make kunit_test_timeout compatible with comment
pinctrl: samsung: Remove EINT handler for Exynos850 ALIVE and CMGP gpios
media: staging: media: zoran: fix usage of vb2_dma_contig_set_max_seg_size
media: camss: csid-170: fix non-10bit formats
media: camss: csid-170: don't enable unused irqs
media: camss: csid-170: set the right HALT_CMD when disabled
media: camss: vfe-170: fix "VFE halt timeout" error
media: staging: media: imx: imx7-mipi-csis: Make subdev name unique
media: v4l2-mem2mem: Apply DST_QUEUE_OFF_BASE on MMAP buffers across ioctls
media: mtk-vcodec: potential dereference of null pointer
media: imx: imx8mq-mipi-csi2: remove wrong irq config write operation
media: imx: imx8mq-mipi_csi2: fix system resume
media: bttv: fix WARNING regression on tunerless devices
media: atmel: atmel-sama7g5-isc: fix ispck leftover
ASoC: sh: rz-ssi: Drop calling rz_ssi_pio_recv() recursively
ASoC: codecs: Check for error pointer after calling devm_regmap_init_mmio
ASoC: xilinx: xlnx_formatter_pcm: Handle sysclk setting
ASoC: simple-card-utils: Set sysclk on all components
media: coda: Fix missing put_device() call in coda_get_vdoa_data
media: meson: vdec: potential dereference of null pointer
media: hantro: Fix overfill bottom register field name
media: ov6650: Fix set format try processing path
media: v4l: Avoid unaligned access warnings when printing 4cc modifiers
media: ov5648: Don't pack controls struct
media: aspeed: Correct value for h-total-pixels
video: fbdev: matroxfb: set maxvram of vbG200eW to the same as vbG200 to avoid black screen
video: fbdev: controlfb: Fix COMPILE_TEST build
video: fbdev: smscufx: Fix null-ptr-deref in ufx_usb_probe()
video: fbdev: atmel_lcdfb: fix an error code in atmel_lcdfb_probe()
video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name()
ARM: dts: Fix OpenBMC flash layout label addresses
firmware: qcom: scm: Remove reassignment to desc following initializer
ARM: dts: qcom: ipq4019: fix sleep clock
soc: qcom: rpmpd: Check for null return of devm_kcalloc
soc: qcom: ocmem: Fix missing put_device() call in of_get_ocmem
soc: qcom: aoss: remove spurious IRQF_ONESHOT flags
arm64: dts: qcom: sdm845: fix microphone bias properties and values
arm64: dts: qcom: sm8250: fix PCIe bindings to follow schema
arm64: dts: broadcom: bcm4908: use proper TWD binding
arm64: dts: qcom: sm8150: Correct TCS configuration for apps rsc
arm64: dts: qcom: sm8350: Correct TCS configuration for apps rsc
firmware: ti_sci: Fix compilation failure when CONFIG_TI_SCI_PROTOCOL is not defined
soc: ti: wkup_m3_ipc: Fix IRQ check in wkup_m3_ipc_probe
ARM: dts: sun8i: v3s: Move the csi1 block to follow address order
vsprintf: Fix potential unaligned access
ARM: dts: imx: Add missing LVDS decoder on M53Menlo
media: mexon-ge2d: fixup frames size in registers
media: video/hdmi: handle short reads of hdmi info frame.
media: ti-vpe: cal: Fix a NULL pointer dereference in cal_ctx_v4l2_init_formats()
media: em28xx: initialize refcount before kref_get
media: usb: go7007: s2250-board: fix leak in probe()
media: cedrus: H265: Fix neighbour info buffer size
media: cedrus: h264: Fix neighbour info buffer size
ASoC: codecs: rx-macro: fix accessing compander for aux
ASoC: codecs: rx-macro: fix accessing array out of bounds for enum type
ASoC: codecs: va-macro: fix accessing array out of bounds for enum type
ASoC: codecs: wc938x: fix accessing array out of bounds for enum type
ASoC: codecs: wcd938x: fix kcontrol max values
ASoC: codecs: wcd934x: fix kcontrol max values
ASoC: codecs: wcd934x: fix return value of wcd934x_rx_hph_mode_put
media: v4l2-core: Initialize h264 scaling matrix
media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
selftests/lkdtm: Add UBSAN config
lib: uninline simple_strntoull() as well
vsprintf: Fix %pK with kptr_restrict == 0
uaccess: fix nios2 and microblaze get_user_8()
ASoC: rt5663: check the return value of devm_kzalloc() in rt5663_parse_dp()
soc: mediatek: pm-domains: Add wakeup capacity support in power domain
mmc: sdhci_am654: Fix the driver data of AM64 SoC
ASoC: ti: davinci-i2s: Add check for clk_enable()
ALSA: spi: Add check for clk_enable()
arm64: dts: ns2: Fix spi-cpol and spi-cpha property
arm64: dts: broadcom: Fix sata nodename
printk: fix return value of printk.devkmsg __setup handler
ASoC: mxs-saif: Handle errors for clk_enable
ASoC: atmel_ssc_dai: Handle errors for clk_enable
ASoC: dwc-i2s: Handle errors for clk_enable
ASoC: soc-compress: prevent the potentially use of null pointer
memory: emif: Add check for setup_interrupts
memory: emif: check the pointer temp in get_device_details()
ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction
arm64: dts: rockchip: Fix SDIO regulator supply properties on rk3399-firefly
m68k: coldfire/device.c: only build for MCF_EDMA when h/w macros are defined
media: stk1160: If start stream fails, return buffers with VB2_BUF_STATE_QUEUED
media: vidtv: Check for null return of vzalloc
ASoC: atmel: Add missing of_node_put() in at91sam9g20ek_audio_probe
ASoC: wm8350: Handle error for wm8350_register_irq
ASoC: fsi: Add check for clk_enable
video: fbdev: omapfb: Add missing of_node_put() in dvic_probe_of
media: saa7134: fix incorrect use to determine if list is empty
ivtv: fix incorrect device_caps for ivtvfb
ASoC: atmel: Fix error handling in snd_proto_probe
ASoC: rockchip: i2s: Fix missing clk_disable_unprepare() in rockchip_i2s_probe
ASoC: SOF: Add missing of_node_put() in imx8m_probe
ASoC: mediatek: use of_device_get_match_data()
ASoC: mediatek: mt8192-mt6359: Fix error handling in mt8192_mt6359_dev_probe
ASoC: rk817: Fix missing clk_disable_unprepare() in rk817_platform_probe
ASoC: dmaengine: do not use a NULL prepare_slave_config() callback
ASoC: mxs: Fix error handling in mxs_sgtl5000_probe
ASoC: fsl_spdif: Disable TX clock when stop
ASoC: imx-es8328: Fix error return code in imx_es8328_probe()
ASoC: SOF: Intel: enable DMI L1 for playback streams
ASoC: msm8916-wcd-digital: Fix missing clk_disable_unprepare() in msm8916_wcd_digital_probe
mmc: davinci_mmc: Handle error for clk_enable
ASoC: atmel: Fix error handling in sam9x5_wm8731_driver_probe
ASoC: msm8916-wcd-analog: Fix error handling in pm8916_wcd_analog_spmi_probe
ASoC: codecs: wcd934x: Add missing of_node_put() in wcd934x_codec_parse_data
ASoC: amd: Fix reference to PCM buffer address
ARM: configs: multi_v5_defconfig: re-enable CONFIG_V4L_PLATFORM_DRIVERS
ARM: configs: multi_v5_defconfig: re-enable DRM_PANEL and FB_xxx
drm/meson: osd_afbcd: Add an exit callback to struct meson_afbcd_ops
drm/meson: Make use of the helper function devm_platform_ioremap_resourcexxx()
drm/meson: split out encoder from meson_dw_hdmi
drm/meson: Fix error handling when afbcd.ops->init fails
drm/bridge: Fix free wrong object in sii8620_init_rcp_input_dev
drm/bridge: Add missing pm_runtime_disable() in __dw_mipi_dsi_probe
drm/bridge: nwl-dsi: Fix PM disable depth imbalance in nwl_dsi_probe
drm: bridge: adv7511: Fix ADV7535 HPD enablement
ath10k: fix memory overwrite of the WoWLAN wakeup packet pattern
drm/v3d/v3d_drv: Check for error num after setting mask
drm/panfrost: Check for error num after setting mask
libbpf: Fix possible NULL pointer dereference when destroying skeleton
bpftool: Only set obj->skeleton on complete success
udmabuf: validate ubuf->pagecount
bpf: Fix UAF due to race between btf_try_get_module and load_module
drm/selftests/test-drm_dp_mst_helper: Fix memory leak in sideband_msg_req_encode_decode
selftests: bpf: Fix bind on used port
Bluetooth: btintel: Fix WBS setting for Intel legacy ROM products
Bluetooth: hci_serdev: call init_rwsem() before p->open()
mtd: onenand: Check for error irq
mtd: rawnand: gpmi: fix controller timings setting
drm/edid: Don't clear formats if using deep color
drm/edid: Split deep color modes between RGB and YUV444
ionic: fix type complaint in ionic_dev_cmd_clean()
ionic: start watchdog after all is setup
ionic: Don't send reset commands if FW isn't running
drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl()
drm/amd/display: Fix a NULL pointer dereference in amdgpu_dm_connector_add_common_modes()
drm/amd/pm: return -ENOTSUPP if there is no get_dpm_ultimate_freq function
net: phy: at803x: move page selection fix to config_init
selftests/bpf: Normalize XDP section names in selftests
selftests/bpf/test_xdp_redirect_multi: use temp netns for testing
ath9k_htc: fix uninit value bugs
RDMA/core: Set MR type in ib_reg_user_mr
KVM: PPC: Fix vmx/vsx mixup in mmio emulation
selftests/net: timestamping: Fix bind_phc check
i40e: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
i40e: respect metadata on XSK Rx to skb
igc: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
ixgbe: pass bi->xdp to ixgbe_construct_skb_zc() directly
ixgbe: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb
ixgbe: respect metadata on XSK Rx to skb
power: reset: gemini-poweroff: Fix IRQ check in gemini_poweroff_probe
ray_cs: Check ioremap return value
powerpc: dts: t1040rdb: fix ports names for Seville Ethernet switch
KVM: PPC: Book3S HV: Check return value of kvmppc_radix_init
powerpc/perf: Don't use perf_hw_context for trace IMC PMU
mt76: connac: fix sta_rec_wtbl tag len
mt76: mt7915: use proper aid value in mt7915_mcu_wtbl_generic_tlv in sta mode
mt76: mt7915: use proper aid value in mt7915_mcu_sta_basic_tlv
mt76: mt7921: fix a leftover race in runtime-pm
mt76: mt7615: fix a leftover race in runtime-pm
mt76: mt7603: check sta_rates pointer in mt7603_sta_rate_tbl_update
mt76: mt7615: check sta_rates pointer in mt7615_sta_rate_tbl_update
ptp: unregister virtual clocks when unregistering physical clock.
net: dsa: mv88e6xxx: Enable port policy support on 6097
mac80211: Remove a couple of obsolete TODO
mac80211: limit bandwidth in HE capabilities
scripts/dtc: Call pkg-config POSIXly correct
livepatch: Fix build failure on 32 bits processors
net: asix: add proper error handling of usb read errors
i2c: bcm2835: Use platform_get_irq() to get the interrupt
i2c: bcm2835: Fix the error handling in 'bcm2835_i2c_probe()'
mtd: mchp23k256: Add SPI ID table
mtd: mchp48l640: Add SPI ID table
igc: avoid kernel warning when changing RX ring parameters
igb: refactor XDP registration
PCI: aardvark: Fix reading MSI interrupt number
PCI: aardvark: Fix reading PCI_EXP_RTSTA_PME bit on emulated bridge
RDMA/rxe: Check the last packet by RXE_END_MASK
libbpf: Fix signedness bug in btf_dump_array_data()
cxl/core: Fix cxl_probe_component_regs() error message
cxl/regs: Fix size of CXL Capability Header Register
net:enetc: allocate CBD ring data memory using DMA coherent methods
libbpf: Fix compilation warning due to mismatched printf format
drm/bridge: dw-hdmi: use safe format when first in bridge chain
libbpf: Use dynamically allocated buffer when receiving netlink messages
power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports
iommu/ipmmu-vmsa: Check for error num after setting mask
drm/bridge: anx7625: Fix overflow issue on reading EDID
bpftool: Fix the error when lookup in no-btf maps
drm/amd/pm: enable pm sysfs write for one VF mode
drm/amd/display: Add affected crtcs to atomic state for dsc mst unplug
libbpf: Fix memleak in libbpf_netlink_recv()
IB/cma: Allow XRC INI QPs to set their local ACK timeout
dax: make sure inodes are flushed before destroy cache
selftests: mptcp: add csum mib check for mptcp_connect
iwlwifi: mvm: Don't call iwl_mvm_sta_from_mac80211() with NULL sta
iwlwifi: mvm: don't iterate unadded vifs when handling FW SMPS req
iwlwifi: mvm: align locking in D3 test debugfs
iwlwifi: yoyo: remove DBGI_SRAM address reset writing
iwlwifi: Fix -EIO error code that is never returned
iwlwifi: mvm: Fix an error code in iwl_mvm_up()
mtd: rawnand: pl353: Set the nand chip node as the flash node
drm/msm/dp: populate connector of struct dp_panel
drm/msm/dp: stop link training after link training 2 failed
drm/msm/dp: always add fail-safe mode into connector mode list
drm/msm/dsi: Use "ref" fw clock instead of global name for VCO parent
drm/msm/dsi/phy: fix 7nm v4.0 settings for C-PHY mode
drm/msm/dpu: add DSPP blocks teardown
drm/msm/dpu: fix dp audio condition
dm crypt: fix get_key_size compiler warning if !CONFIG_KEYS
vfio/pci: fix memory leak during D3hot to D0 transition
vfio/pci: wake-up devices around reset functions
scsi: fnic: Fix a tracing statement
scsi: pm8001: Fix command initialization in pm80XX_send_read_log()
scsi: pm8001: Fix command initialization in pm8001_chip_ssp_tm_req()
scsi: pm8001: Fix payload initialization in pm80xx_set_thermal_config()
scsi: pm8001: Fix le32 values handling in pm80xx_set_sas_protocol_timer_config()
scsi: pm8001: Fix payload initialization in pm80xx_encrypt_update()
scsi: pm8001: Fix le32 values handling in pm80xx_chip_ssp_io_req()
scsi: pm8001: Fix le32 values handling in pm80xx_chip_sata_req()
scsi: pm8001: Fix NCQ NON DATA command task initialization
scsi: pm8001: Fix NCQ NON DATA command completion handling
scsi: pm8001: Fix abort all task initialization
RDMA/mlx5: Fix the flow of a miss in the allocation of a cache ODP MR
drm/amd/display: Remove vupdate_int_entry definition
TOMOYO: fix __setup handlers return values
power: supply: sbs-charger: Don't cancel work that is not initialized
ext2: correct max file size computing
drm/tegra: Fix reference leak in tegra_dsi_ganged_probe
power: supply: bq24190_charger: Fix bq24190_vbus_is_enabled() wrong false return
scsi: hisi_sas: Change permission of parameter prot_mask
drm/bridge: cdns-dsi: Make sure to to create proper aliases for dt
bpf, arm64: Call build_prologue() first in first JIT pass
bpf, arm64: Feed byte-offset into bpf line info
xsk: Fix race at socket teardown
RDMA/irdma: Fix netdev notifications for vlan's
RDMA/irdma: Fix Passthrough mode in VM
RDMA/irdma: Remove incorrect masking of PD
gpu: host1x: Fix a memory leak in 'host1x_remove()'
libbpf: Skip forward declaration when counting duplicated type names
powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()
powerpc/Makefile: Don't pass -mcpu=powerpc64 when building 32-bit
KVM: x86: Fix emulation in writing cr8
KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor()
hv_balloon: rate-limit "Unhandled message" warning
i2c: xiic: Make bus names unique
power: supply: wm8350-power: Handle error for wm8350_register_irq
power: supply: wm8350-power: Add missing free in free_charger_irq
IB/hfi1: Allow larger MTU without AIP
RDMA/core: Fix ib_qp_usecnt_dec() called when error
PCI: Reduce warnings on possible RW1C corruption
net: axienet: fix RX ring refill allocation failure handling
drm/msm/a6xx: Fix missing ARRAY_SIZE() check
mips: DEC: honor CONFIG_MIPS_FP_SUPPORT=n
MIPS: Sanitise Cavium switch cases in TLB handler synthesizers
powerpc/sysdev: fix incorrect use to determine if list is empty
powerpc/64s: Don't use DSISR for SLB faults
mfd: mc13xxx: Add check for mc13xxx_irq_request
libbpf: Unmap rings when umem deleted
selftests/bpf: Make test_lwt_ip_encap more stable and faster
platform/x86: huawei-wmi: check the return value of device_create_file()
scsi: mpt3sas: Fix incorrect 4GB boundary check
powerpc: 8xx: fix a return value error in mpc8xx_pic_init
vxcan: enable local echo for sent CAN frames
ath10k: Fix error handling in ath10k_setup_msa_resources
mips: cdmm: Fix refcount leak in mips_cdmm_phys_base
MIPS: RB532: fix return value of __setup handler
MIPS: pgalloc: fix memory leak caused by pgd_free()
mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
power: ab8500_chargalg: Use CLOCK_MONOTONIC
RDMA/irdma: Prevent some integer underflows
Revert "RDMA/core: Fix ib_qp_usecnt_dec() called when error"
RDMA/mlx5: Fix memory leak in error flow for subscribe event routine
bpf, sockmap: Fix memleak in sk_psock_queue_msg
bpf, sockmap: Fix memleak in tcp_bpf_sendmsg while sk msg is full
bpf, sockmap: Fix more uncharged while msg has more_data
bpf, sockmap: Fix double uncharge the mem of sk_msg
samples/bpf, xdpsock: Fix race when running for fix duration of time
USB: storage: ums-realtek: fix error code in rts51x_read_mem()
drm/i915/display: Fix HPD short pulse handling for eDP
netfilter: flowtable: Fix QinQ and pppoe support for inet table
mt76: mt7921: fix mt7921_queues_acq implementation
can: isotp: sanitize CAN ID checks in isotp_bind()
can: isotp: return -EADDRNOTAVAIL when reading from unbound socket
can: isotp: support MSG_TRUNC flag when reading from socket
bareudp: use ipv6_mod_enabled to check if IPv6 enabled
ibmvnic: fix race between xmit and reset
af_unix: Fix some data-races around unix_sk(sk)->oob_skb.
selftests/bpf: Fix error reporting from sock_fields programs
Bluetooth: hci_uart: add missing NULL check in h5_enqueue
Bluetooth: call hci_le_conn_failed with hdev lock in hci_le_conn_failed
Bluetooth: btmtksdio: Fix kernel oops in btmtksdio_interrupt
ipv4: Fix route lookups when handling ICMP redirects and PMTU updates
af_netlink: Fix shift out of bounds in group mask calculation
i2c: meson: Fix wrong speed use from probe
netfilter: conntrack: Add and use nf_ct_set_auto_assign_helper_warned()
i2c: mux: demux-pinctrl: do not deactivate a master that is not active
powerpc/pseries: Fix use after free in remove_phb_dynamic()
selftests/bpf/test_lirc_mode2.sh: Exit with proper code
PCI: Avoid broken MSI on SB600 USB devices
net: bcmgenet: Use stronger register read/writes to assure ordering
tcp: ensure PMTU updates are processed during fastopen
openvswitch: always update flow key after nat
net: dsa: fix panic on shutdown if multi-chip tree failed to probe
tipc: fix the timer expires after interval 100ms
mfd: asic3: Add missing iounmap() on error asic3_mfd_probe
ice: fix 'scheduling while atomic' on aux critical err interrupt
ice: don't allow to run ice_send_event_to_aux() in atomic ctx
drivers: ethernet: cpsw: fix panic when interrupt coaleceing is set via ethtool
kernel/resource: fix kfree() of bootmem memory again
staging: r8188eu: convert DBG_88E_LEVEL call in hal/rtl8188e_hal_init.c
staging: r8188eu: release_firmware is not called if allocation fails
mxser: fix xmit_buf leak in activate when LSR == 0xff
fsi: scom: Fix error handling
fsi: scom: Remove retries in indirect scoms
pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add()
pps: clients: gpio: Propagate return value from pps_gpio_probe
fsi: Aspeed: Fix a potential double free
misc: alcor_pci: Fix an error handling path
cpufreq: qcom-cpufreq-nvmem: fix reading of PVS Valid fuse
soundwire: intel: fix wrong register name in intel_shim_wake
clk: qcom: ipq8074: fix PCI-E clock oops
dmaengine: idxd: check GENCAP config support for gencfg register
dmaengine: idxd: change bandwidth token to read buffers
dmaengine: idxd: restore traffic class defaults after wq reset
iio: mma8452: Fix probe failing when an i2c_device_id is used
serial: 8250_aspeed_vuart: add PORT_ASPEED_VUART port type
staging:iio:adc:ad7280a: Fix handing of device address bit reversing.
pinctrl: renesas: r8a77470: Reduce size for narrow VIN1 channel
pinctrl: renesas: checker: Fix miscalculation of number of states
clk: qcom: ipq8074: Use floor ops for SDCC1 clock
phy: dphy: Correct lpx parameter and its derivatives(ta_{get,go,sure})
phy: phy-brcm-usb: fixup BCM4908 support
serial: 8250_mid: Balance reference count for PCI DMA device
serial: 8250_lpss: Balance reference count for PCI DMA device
NFS: Use of mapping_set_error() results in spurious errors
serial: 8250: Fix race condition in RTS-after-send handling
iio: adc: Add check for devm_request_threaded_irq
habanalabs: Add check for pci_enable_device
NFS: Return valid errors from nfs2/3_decode_dirent()
staging: r8188eu: fix endless loop in recv_func
dma-debug: fix return value of __setup handlers
clk: imx7d: Remove audio_mclk_root_clk
clk: imx: off by one in imx_lpcg_parse_clks_from_dt()
clk: at91: sama7g5: fix parents of PDMCs' GCLK
clk: qcom: clk-rcg2: Update logic to calculate D value for RCG
clk: qcom: clk-rcg2: Update the frac table for pixel clock
dmaengine: hisi_dma: fix MSI allocate fail when reload hisi_dma
remoteproc: qcom: Fix missing of_node_put in adsp_alloc_memory_region
remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region
remoteproc: qcom_q6v5_mss: Fix some leaks in q6v5_alloc_memory_region
nvdimm/region: Fix default alignment for small regions
clk: actions: Terminate clk_div_table with sentinel element
clk: loongson1: Terminate clk_div_table with sentinel element
clk: hisilicon: Terminate clk_div_table with sentinel element
clk: clps711x: Terminate clk_div_table with sentinel element
clk: Fix clk_hw_get_clk() when dev is NULL
clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver
mailbox: imx: fix crash in resume on i.mx8ulp
NFS: remove unneeded check in decode_devicenotify_args()
staging: mt7621-dts: fix LEDs and pinctrl on GB-PC1 devicetree
staging: mt7621-dts: fix formatting
staging: mt7621-dts: fix pinctrl properties for ethernet
staging: mt7621-dts: fix GB-PC2 devicetree
pinctrl: mediatek: Fix missing of_node_put() in mtk_pctrl_init
pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_* readback
pinctrl: mediatek: paris: Fix "argument" argument type for mtk_pinconf_get()
pinctrl: mediatek: paris: Fix pingroup pin config state readback
pinctrl: mediatek: paris: Skip custom extra pin config dump for virtual GPIOs
pinctrl: microchip sgpio: use reset driver
pinctrl: microchip-sgpio: lock RMW access
pinctrl: nomadik: Add missing of_node_put() in nmk_pinctrl_probe
pinctrl/rockchip: Add missing of_node_put() in rockchip_pinctrl_probe
tty: hvc: fix return value of __setup handler
kgdboc: fix return value of __setup handler
serial: 8250: fix XOFF/XON sending when DMA is used
virt: acrn: obtain pa from VMA with PFNMAP flag
virt: acrn: fix a memory leak in acrn_dev_ioctl()
kgdbts: fix return value of __setup handler
firmware: google: Properly state IOMEM dependency
driver core: dd: fix return value of __setup handler
jfs: fix divide error in dbNextAG
netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options
SUNRPC don't resend a task on an offlined transport
NFSv4.1: don't retry BIND_CONN_TO_SESSION on session error
kdb: Fix the putarea helper function
perf stat: Fix forked applications enablement of counters
clk: qcom: gcc-msm8994: Fix gpll4 width
vsock/virtio: initialize vdev->priv before using VQs
vsock/virtio: read the negotiated features before using VQs
vsock/virtio: enable VQs early on probe
clk: Initialize orphan req_rate
xen: fix is_xen_pmu()
net: enetc: report software timestamping via SO_TIMESTAMPING
net: hns3: fix bug when PF set the duplicate MAC address for VFs
net: hns3: fix port base vlan add fail when concurrent with reset
net: hns3: add vlan list lock to protect vlan list
net: hns3: format the output of the MAC address
net: hns3: refine the process when PF set VF VLAN
net: phy: broadcom: Fix brcm_fet_config_init()
selftests: test_vxlan_under_vrf: Fix broken test case
NFS: Don't loop forever in nfs_do_recoalesce()
net: hns3: clean residual vf config after disable sriov
net: sparx5: depends on PTP_1588_CLOCK_OPTIONAL
qlcnic: dcb: default to returning -EOPNOTSUPP
net/x25: Fix null-ptr-deref caused by x25_disconnect
net: sparx5: switchdev: fix possible NULL pointer dereference
octeontx2-af: initialize action variable
net: prefer nf_ct_put instead of nf_conntrack_put
net/sched: act_ct: fix ref leak when switching zones
NFSv4/pNFS: Fix another issue with a list iterator pointing to the head
net: dsa: bcm_sf2_cfp: fix an incorrect NULL check on list iterator
fs: fd tables have to be multiples of BITS_PER_LONG
lib/test: use after free in register_test_dev_kmod()
fs: fix fd table size alignment properly
LSM: general protection fault in legacy_parse_param
regulator: rpi-panel: Handle I2C errors/timing to the Atmel
crypto: hisilicon/qm - cleanup warning in qm_vf_read_qos
gcc-plugins/stackleak: Exactly match strings instead of prefixes
pinctrl: npcm: Fix broken references to chip->parent_device
rcu: Mark writes to the rcu_segcblist structure's ->flags field
block/bfq_wf2q: correct weight to ioprio
crypto: xts - Add softdep on ecb
crypto: hisilicon/sec - not need to enable sm4 extra mode at HW V3
block, bfq: don't move oom_bfqq
selinux: use correct type for context length
arm64: module: remove (NOLOAD) from linker script
selinux: allow FIOCLEX and FIONCLEX with policy capability
loop: use sysfs_emit() in the sysfs xxx show()
Fix incorrect type in assignment of ipv6 port for audit
irqchip/qcom-pdc: Fix broken locking
irqchip/nvic: Release nvic_base upon failure
fs/binfmt_elf: Fix AT_PHDR for unusual ELF files
bfq: fix use-after-free in bfq_dispatch_request
ACPICA: Avoid walking the ACPI Namespace if it is not there
lib/raid6/test/Makefile: Use $(pound) instead of \# for Make 4.3
Revert "Revert "block, bfq: honor already-setup queue merges""
ACPI/APEI: Limit printable size of BERT table data
PM: core: keep irq flags in device_pm_check_callbacks()
parisc: Fix handling off probe non-access faults
nvme-tcp: lockdep: annotate in-kernel sockets
spi: tegra20: Use of_device_get_match_data()
atomics: Fix atomic64_{read_acquire,set_release} fallbacks
locking/lockdep: Iterate lock_classes directly when reading lockdep files
ext4: correct cluster len and clusters changed accounting in ext4_mb_mark_bb
ext4: fix ext4_mb_mark_bb() with flex_bg with fast_commit
sched/tracing: Report TASK_RTLOCK_WAIT tasks as TASK_UNINTERRUPTIBLE
ext4: don't BUG if someone dirty pages without asking ext4 first
f2fs: fix to do sanity check on curseg->alloc_type
NFSD: Fix nfsd_breaker_owns_lease() return values
f2fs: don't get FREEZE lock in f2fs_evict_inode in frozen fs
btrfs: harden identification of a stale device
btrfs: make search_csum_tree return 0 if we get -EFBIG
f2fs: use spin_lock to avoid hang
f2fs: compress: fix to print raw data size in error path of lz4 decompression
Adjust cifssb maximum read size
ntfs: add sanity check on allocation size
media: staging: media: zoran: move videodev alloc
media: staging: media: zoran: calculate the right buffer number for zoran_reap_stat_com
media: staging: media: zoran: fix various V4L2 compliance errors
media: atmel: atmel-isc-base: report frame sizes as full supported range
media: ir_toy: free before error exiting
ASoC: sh: rz-ssi: Make the data structures available before registering the handlers
ASoC: SOF: Intel: match sdw version on link_slaves_found
media: imx-jpeg: Prevent decoding NV12M jpegs into single-planar buffers
media: iommu/mediatek-v1: Free the existed fwspec if the master dev already has
media: iommu/mediatek: Return ENODEV if the device is NULL
media: iommu/mediatek: Add device_link between the consumer and the larb devices
video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow
video: fbdev: w100fb: Reset global state
video: fbdev: cirrusfb: check pixclock to avoid divide by zero
video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit
ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960
ARM: dts: bcm2837: Add the missing L1/L2 cache information
ASoC: madera: Add dependencies on MFD
media: atomisp_gmin_platform: Add DMI quirk to not turn AXP ELDO2 regulator off on some boards
media: atomisp: fix dummy_ptr check to avoid duplicate active_bo
ARM: ftrace: avoid redundant loads or clobbering IP
ARM: dts: imx7: Use audio_mclk_post_div instead audio_mclk_root_clk
arm64: defconfig: build imx-sdma as a module
video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf()
video: fbdev: omapfb: panel-tpo-td043mtea1: Use sysfs_emit() instead of snprintf()
video: fbdev: udlfb: replace snprintf in show functions with sysfs_emit
ARM: dts: bcm2711: Add the missing L1/L2 cache information
ASoC: soc-core: skip zero num_dai component in searching dai name
media: imx-jpeg: fix a bug of accessing array out of bounds
media: cx88-mpeg: clear interrupt status register before streaming video
uaccess: fix type mismatch warnings from access_ok()
lib/test_lockup: fix kernel pointer check for separate address spaces
ARM: tegra: tamonten: Fix I2C3 pad setting
ARM: mmp: Fix failure to remove sram device
ASoC: amd: vg: fix for pm resume callback sequence
video: fbdev: sm712fb: Fix crash in smtcfb_write()
media: i2c: ov5648: Fix lockdep error
media: Revert "media: em28xx: add missing em28xx_close_extension"
media: hdpvr: initialize dev->worker at hdpvr_register_videodev
ASoC: Intel: sof_sdw: fix quirks for 2022 HP Spectre x360 13"
tracing: Have TRACE_DEFINE_ENUM affect trace event types as well
mmc: host: Return an error when ->enable_sdio_irq() ops is missing
media: atomisp: fix bad usage at error handling logic
ALSA: hda/realtek: Add alc256-samsung-headphone fixup
KVM: x86: Reinitialize context if host userspace toggles EFER.LME
KVM: x86/mmu: Move "invalid" check out of kvm_tdp_mmu_get_root()
KVM: x86/mmu: Zap _all_ roots when unmapping gfn range in TDP MMU
KVM: x86/mmu: Check for present SPTE when clearing dirty bit in TDP MMU
KVM: x86: hyper-v: Drop redundant 'ex' parameter from kvm_hv_send_ipi()
KVM: x86: hyper-v: Drop redundant 'ex' parameter from kvm_hv_flush_tlb()
KVM: x86: hyper-v: Fix the maximum number of sparse banks for XMM fast TLB flush hypercalls
KVM: x86: hyper-v: HVCALL_SEND_IPI_EX is an XMM fast hypercall
powerpc/kasan: Fix early region not updated correctly
powerpc/lib/sstep: Fix 'sthcx' instruction
powerpc/lib/sstep: Fix build errors with newer binutils
powerpc: Add set_memory_{p/np}() and remove set_memory_attr()
powerpc: Fix build errors with newer binutils
drm/dp: Fix off-by-one in register cache size
drm/i915: Treat SAGV block time 0 as SAGV disabled
drm/i915: Fix PSF GV point mask when SAGV is not possible
drm/i915: Reject unsupported TMDS rates on ICL+
scsi: qla2xxx: Refactor asynchronous command initialization
scsi: qla2xxx: Implement ref count for SRB
scsi: qla2xxx: Fix stuck session in gpdb
scsi: qla2xxx: Fix warning message due to adisc being flushed
scsi: qla2xxx: Fix scheduling while atomic
scsi: qla2xxx: Fix premature hw access after PCI error
scsi: qla2xxx: Fix wrong FDMI data for 64G adapter
scsi: qla2xxx: Fix warning for missing error code
scsi: qla2xxx: Fix device reconnect in loop topology
scsi: qla2xxx: edif: Fix clang warning
scsi: qla2xxx: Fix T10 PI tag escape and IP guard options for 28XX adapters
scsi: qla2xxx: Add devids and conditionals for 28xx
scsi: qla2xxx: Check for firmware dump already collected
scsi: qla2xxx: Suppress a kernel complaint in qla_create_qpair()
scsi: qla2xxx: Fix disk failure to rediscover
scsi: qla2xxx: Fix incorrect reporting of task management failure
scsi: qla2xxx: Fix hang due to session stuck
scsi: qla2xxx: Fix missed DMA unmap for NVMe ls requests
scsi: qla2xxx: Fix N2N inconsistent PLOGI
scsi: qla2xxx: Fix stuck session of PRLI reject
scsi: qla2xxx: Reduce false trigger to login
scsi: qla2xxx: Use correct feature type field during RFF_ID processing
platform: chrome: Split trace include file
KVM: x86: Check lapic_in_kernel() before attempting to set a SynIC irq
KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast()
KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated
KVM: Prevent module exit until all VMs are freed
KVM: x86: fix sending PV IPI
KVM: SVM: fix panic on out-of-bounds guest IRQ
ubifs: rename_whiteout: Fix double free for whiteout_ui->data
ubifs: Fix deadlock in concurrent rename whiteout and inode writeback
ubifs: Add missing iput if do_tmpfile() failed in rename whiteout
ubifs: Rename whiteout atomically
ubifs: Fix 'ui->dirty' race between do_tmpfile() and writeback work
ubifs: Rectify space amount budget for mkdir/tmpfile operations
ubifs: setflags: Make dirtied_ino_d 8 bytes aligned
ubifs: Fix read out-of-bounds in ubifs_wbuf_write_nolock()
ubifs: Fix to add refcount once page is set private
ubifs: rename_whiteout: correct old_dir size computing
nvme: allow duplicate NSIDs for private namespaces
nvme: fix the read-only state for zoned namespaces with unsupposed features
wireguard: queueing: use CFI-safe ptr_ring cleanup function
wireguard: socket: free skb in send6 when ipv6 is disabled
wireguard: socket: ignore v6 endpoints when ipv6 is disabled
XArray: Fix xas_create_range() when multi-order entry present
can: mcba_usb: mcba_usb_start_xmit(): fix double dev_kfree_skb in error path
can: mcba_usb: properly check endpoint type
can: mcp251xfd: mcp251xfd_register_get_dev_id(): fix return of error value
XArray: Update the LRU list in xas_split()
modpost: restore the warning message for missing symbol versions
rtc: check if __rtc_read_time was successful
gfs2: gfs2_setattr_size error path fix
gfs2: Make sure FITRIM minlen is rounded up to fs block size
net: hns3: fix the concurrency between functions reading debugfs
net: hns3: fix software vlan talbe of vlan 0 inconsistent with hardware
rxrpc: fix some null-ptr-deref bugs in server_key.c
rxrpc: Fix call timer start racing with call destruction
mailbox: imx: fix wakeup failure from freeze mode
crypto: arm/aes-neonbs-cbc - Select generic cbc and aes
watch_queue: Free the page array when watch_queue is dismantled
pinctrl: pinconf-generic: Print arguments for bias-pull-*
watchdog: rti-wdt: Add missing pm_runtime_disable() in probe function
net: sparx5: uses, depends on BRIDGE or !BRIDGE
pinctrl: nuvoton: npcm7xx: Rename DS() macro to DSTR()
pinctrl: nuvoton: npcm7xx: Use %zu printk format for ARRAY_SIZE()
ASoC: mediatek: mt6358: add missing EXPORT_SYMBOLs
ubi: Fix race condition between ctrl_cdev_ioctl and ubi_cdev_ioctl
ARM: iop32x: offset IRQ numbers by 1
block: Fix the maximum minor value is blk_alloc_ext_minor()
io_uring: fix memory leak of uid in files registration
riscv module: remove (NOLOAD)
ACPI: CPPC: Avoid out of bounds access when parsing _CPC data
vhost: handle error while adding split ranges to iotlb
spi: Fix Tegra QSPI example
platform/chrome: cros_ec_typec: Check for EC device
can: isotp: restore accidentally removed MSG_PEEK feature
proc: bootconfig: Add null pointer check
drm/connector: Fix typo in documentation
scsi: qla2xxx: Add qla2x00_async_done() for async routines
staging: mt7621-dts: fix pinctrl-0 items to be size-1 items on ethernet
arm64: mm: Drop 'const' from conditional arm64_dma_phys_limit definition
ASoC: soc-compress: Change the check for codec_dai
Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE""
tracing: Have type enum modifications copy the strings
net: add skb_set_end_offset() helper
net: preserve skb_end_offset() in skb_unclone_keeptruesize()
mm/mmap: return 1 from stack_guard_gap __setup() handler
ARM: 9187/1: JIVE: fix return value of __setup handler
mm/memcontrol: return 1 from cgroup.memory __setup() handler
mm/usercopy: return 1 from hardened_usercopy __setup() handler
af_unix: Support POLLPRI for OOB.
bpf: Adjust BPF stack helper functions to accommodate skip > 0
bpf: Fix comment for helper bpf_current_task_under_cgroup()
mmc: rtsx: Use pm_runtime_{get,put}() to handle runtime PM
dt-bindings: mtd: nand-controller: Fix the reg property description
dt-bindings: mtd: nand-controller: Fix a comment in the examples
dt-bindings: spi: mxic: The interrupt property is not mandatory
dt-bindings: memory: mtk-smi: No need mediatek,larb-id for mt8167
dt-bindings: pinctrl: pinctrl-microchip-sgpio: Fix example
ubi: fastmap: Return error code if memory allocation fails in add_aeb()
ASoC: SOF: Intel: Fix build error without SND_SOC_SOF_PCI_DEV
ASoC: topology: Allow TLV control to be either read or write
perf vendor events: Update metrics for SkyLake Server
media: ov6650: Add try support to selection API operations
media: ov6650: Fix crop rectangle affected by set format
spi: mediatek: support tick_delay without enhance_timing
ARM: dts: spear1340: Update serial node properties
ARM: dts: spear13xx: Update SPI dma properties
arm64: dts: ls1043a: Update i2c dma properties
arm64: dts: ls1046a: Update i2c node dma properties
um: Fix uml_mconsole stop/go
docs: sysctl/kernel: add missing bit to panic_print
openvswitch: Fixed nd target mask field in the flow dump.
torture: Make torture.sh help message match reality
n64cart: convert bi_disk to bi_bdev->bd_disk fix build
mmc: rtsx: Let MMC core handle runtime PM
mmc: rtsx: Fix build errors/warnings for unused variable
KVM: x86/mmu: do compare-and-exchange of gPTE via the user address
iommu/dma: Skip extra sync during unmap w/swiotlb
iommu/dma: Fold _swiotlb helpers into callers
iommu/dma: Check CONFIG_SWIOTLB more broadly
swiotlb: Support aligned swiotlb buffers
iommu/dma: Account for min_align_mask w/swiotlb
coredump: Snapshot the vmas in do_coredump
coredump: Remove the WARN_ON in dump_vma_snapshot
coredump/elf: Pass coredump_params into fill_note_info
coredump: Use the vma snapshot in fill_files_note
PCI: xgene: Revert "PCI: xgene: Use inbound resources for setup"
Linux 5.15.33
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Id62bd8a22d0bfa7c2096539d253ffce804bed017
3033 lines
75 KiB
C
3033 lines
75 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Simple NUMA memory policy for the Linux kernel.
|
|
*
|
|
* Copyright 2003,2004 Andi Kleen, SuSE Labs.
|
|
* (C) Copyright 2005 Christoph Lameter, Silicon Graphics, Inc.
|
|
*
|
|
* NUMA policy allows the user to give hints in which node(s) memory should
|
|
* be allocated.
|
|
*
|
|
* Support four policies per VMA and per process:
|
|
*
|
|
* The VMA policy has priority over the process policy for a page fault.
|
|
*
|
|
* interleave Allocate memory interleaved over a set of nodes,
|
|
* with normal fallback if it fails.
|
|
* For VMA based allocations this interleaves based on the
|
|
* offset into the backing object or offset into the mapping
|
|
* for anonymous memory. For process policy an process counter
|
|
* is used.
|
|
*
|
|
* bind Only allocate memory on a specific set of nodes,
|
|
* no fallback.
|
|
* FIXME: memory is allocated starting with the first node
|
|
* to the last. It would be better if bind would truly restrict
|
|
* the allocation to memory nodes instead
|
|
*
|
|
* preferred Try a specific node first before normal fallback.
|
|
* As a special case NUMA_NO_NODE here means do the allocation
|
|
* on the local CPU. This is normally identical to default,
|
|
* but useful to set in a VMA when you have a non default
|
|
* process policy.
|
|
*
|
|
* preferred many Try a set of nodes first before normal fallback. This is
|
|
* similar to preferred without the special case.
|
|
*
|
|
* default Allocate on the local node first, or when on a VMA
|
|
* use the process policy. This is what Linux always did
|
|
* in a NUMA aware kernel and still does by, ahem, default.
|
|
*
|
|
* The process policy is applied for most non interrupt memory allocations
|
|
* in that process' context. Interrupts ignore the policies and always
|
|
* try to allocate on the local CPU. The VMA policy is only applied for memory
|
|
* allocations for a VMA in the VM.
|
|
*
|
|
* Currently there are a few corner cases in swapping where the policy
|
|
* is not applied, but the majority should be handled. When process policy
|
|
* is used it is not remembered over swap outs/swap ins.
|
|
*
|
|
* Only the highest zone in the zone hierarchy gets policied. Allocations
|
|
* requesting a lower zone just use default policy. This implies that
|
|
* on systems with highmem kernel lowmem allocation don't get policied.
|
|
* Same with GFP_DMA allocations.
|
|
*
|
|
* For shmfs/tmpfs/hugetlbfs shared memory the policy is shared between
|
|
* all users and remembered even when nobody has memory mapped.
|
|
*/
|
|
|
|
/* Notebook:
|
|
fix mmap readahead to honour policy and enable policy for any page cache
|
|
object
|
|
statistics for bigpages
|
|
global policy for page cache? currently it uses process policy. Requires
|
|
first item above.
|
|
handle mremap for shared memory (currently ignored for the policy)
|
|
grows down?
|
|
make bind policy root only? It can trigger oom much faster and the
|
|
kernel is not always grateful with that.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/mempolicy.h>
|
|
#include <linux/pagewalk.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/sched/numa_balancing.h>
|
|
#include <linux/sched/task.h>
|
|
#include <linux/nodemask.h>
|
|
#include <linux/cpuset.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <linux/export.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/init.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/ptrace.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/migrate.h>
|
|
#include <linux/ksm.h>
|
|
#include <linux/rmap.h>
|
|
#include <linux/security.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/mm_inline.h>
|
|
#include <linux/mmu_notifier.h>
|
|
#include <linux/printk.h>
|
|
#include <linux/swapops.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
#include "internal.h"
|
|
|
|
/* Internal flags */
|
|
#define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0) /* Skip checks for continuous vmas */
|
|
#define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1) /* Invert check for nodemask */
|
|
|
|
static struct kmem_cache *policy_cache;
|
|
static struct kmem_cache *sn_cache;
|
|
|
|
/* Highest zone. An specific allocation for a zone below that is not
|
|
policied. */
|
|
enum zone_type policy_zone = 0;
|
|
|
|
/*
|
|
* run-time system-wide default policy => local allocation
|
|
*/
|
|
static struct mempolicy default_policy = {
|
|
.refcnt = ATOMIC_INIT(1), /* never free it */
|
|
.mode = MPOL_LOCAL,
|
|
};
|
|
|
|
static struct mempolicy preferred_node_policy[MAX_NUMNODES];
|
|
|
|
/**
|
|
* numa_map_to_online_node - Find closest online node
|
|
* @node: Node id to start the search
|
|
*
|
|
* Lookup the next closest node by distance if @nid is not online.
|
|
*/
|
|
int numa_map_to_online_node(int node)
|
|
{
|
|
int min_dist = INT_MAX, dist, n, min_node;
|
|
|
|
if (node == NUMA_NO_NODE || node_online(node))
|
|
return node;
|
|
|
|
min_node = node;
|
|
for_each_online_node(n) {
|
|
dist = node_distance(node, n);
|
|
if (dist < min_dist) {
|
|
min_dist = dist;
|
|
min_node = n;
|
|
}
|
|
}
|
|
|
|
return min_node;
|
|
}
|
|
EXPORT_SYMBOL_GPL(numa_map_to_online_node);
|
|
|
|
struct mempolicy *get_task_policy(struct task_struct *p)
|
|
{
|
|
struct mempolicy *pol = p->mempolicy;
|
|
int node;
|
|
|
|
if (pol)
|
|
return pol;
|
|
|
|
node = numa_node_id();
|
|
if (node != NUMA_NO_NODE) {
|
|
pol = &preferred_node_policy[node];
|
|
/* preferred_node_policy is not initialised early in boot */
|
|
if (pol->mode)
|
|
return pol;
|
|
}
|
|
|
|
return &default_policy;
|
|
}
|
|
|
|
static const struct mempolicy_operations {
|
|
int (*create)(struct mempolicy *pol, const nodemask_t *nodes);
|
|
void (*rebind)(struct mempolicy *pol, const nodemask_t *nodes);
|
|
} mpol_ops[MPOL_MAX];
|
|
|
|
static inline int mpol_store_user_nodemask(const struct mempolicy *pol)
|
|
{
|
|
return pol->flags & MPOL_MODE_FLAGS;
|
|
}
|
|
|
|
static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
|
|
const nodemask_t *rel)
|
|
{
|
|
nodemask_t tmp;
|
|
nodes_fold(tmp, *orig, nodes_weight(*rel));
|
|
nodes_onto(*ret, tmp, *rel);
|
|
}
|
|
|
|
static int mpol_new_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
|
|
{
|
|
if (nodes_empty(*nodes))
|
|
return -EINVAL;
|
|
pol->nodes = *nodes;
|
|
return 0;
|
|
}
|
|
|
|
static int mpol_new_preferred(struct mempolicy *pol, const nodemask_t *nodes)
|
|
{
|
|
if (nodes_empty(*nodes))
|
|
return -EINVAL;
|
|
|
|
nodes_clear(pol->nodes);
|
|
node_set(first_node(*nodes), pol->nodes);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
|
|
* any, for the new policy. mpol_new() has already validated the nodes
|
|
* parameter with respect to the policy mode and flags.
|
|
*
|
|
* Must be called holding task's alloc_lock to protect task's mems_allowed
|
|
* and mempolicy. May also be called holding the mmap_lock for write.
|
|
*/
|
|
static int mpol_set_nodemask(struct mempolicy *pol,
|
|
const nodemask_t *nodes, struct nodemask_scratch *nsc)
|
|
{
|
|
int ret;
|
|
|
|
/*
|
|
* Default (pol==NULL) resp. local memory policies are not a
|
|
* subject of any remapping. They also do not need any special
|
|
* constructor.
|
|
*/
|
|
if (!pol || pol->mode == MPOL_LOCAL)
|
|
return 0;
|
|
|
|
/* Check N_MEMORY */
|
|
nodes_and(nsc->mask1,
|
|
cpuset_current_mems_allowed, node_states[N_MEMORY]);
|
|
|
|
VM_BUG_ON(!nodes);
|
|
|
|
if (pol->flags & MPOL_F_RELATIVE_NODES)
|
|
mpol_relative_nodemask(&nsc->mask2, nodes, &nsc->mask1);
|
|
else
|
|
nodes_and(nsc->mask2, *nodes, nsc->mask1);
|
|
|
|
if (mpol_store_user_nodemask(pol))
|
|
pol->w.user_nodemask = *nodes;
|
|
else
|
|
pol->w.cpuset_mems_allowed = cpuset_current_mems_allowed;
|
|
|
|
ret = mpol_ops[pol->mode].create(pol, &nsc->mask2);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* This function just creates a new policy, does some check and simple
|
|
* initialization. You must invoke mpol_set_nodemask() to set nodes.
|
|
*/
|
|
static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,
|
|
nodemask_t *nodes)
|
|
{
|
|
struct mempolicy *policy;
|
|
|
|
pr_debug("setting mode %d flags %d nodes[0] %lx\n",
|
|
mode, flags, nodes ? nodes_addr(*nodes)[0] : NUMA_NO_NODE);
|
|
|
|
if (mode == MPOL_DEFAULT) {
|
|
if (nodes && !nodes_empty(*nodes))
|
|
return ERR_PTR(-EINVAL);
|
|
return NULL;
|
|
}
|
|
VM_BUG_ON(!nodes);
|
|
|
|
/*
|
|
* MPOL_PREFERRED cannot be used with MPOL_F_STATIC_NODES or
|
|
* MPOL_F_RELATIVE_NODES if the nodemask is empty (local allocation).
|
|
* All other modes require a valid pointer to a non-empty nodemask.
|
|
*/
|
|
if (mode == MPOL_PREFERRED) {
|
|
if (nodes_empty(*nodes)) {
|
|
if (((flags & MPOL_F_STATIC_NODES) ||
|
|
(flags & MPOL_F_RELATIVE_NODES)))
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
mode = MPOL_LOCAL;
|
|
}
|
|
} else if (mode == MPOL_LOCAL) {
|
|
if (!nodes_empty(*nodes) ||
|
|
(flags & MPOL_F_STATIC_NODES) ||
|
|
(flags & MPOL_F_RELATIVE_NODES))
|
|
return ERR_PTR(-EINVAL);
|
|
} else if (nodes_empty(*nodes))
|
|
return ERR_PTR(-EINVAL);
|
|
policy = kmem_cache_alloc(policy_cache, GFP_KERNEL);
|
|
if (!policy)
|
|
return ERR_PTR(-ENOMEM);
|
|
atomic_set(&policy->refcnt, 1);
|
|
policy->mode = mode;
|
|
policy->flags = flags;
|
|
|
|
return policy;
|
|
}
|
|
|
|
/* Slow path of a mpol destructor. */
|
|
void __mpol_put(struct mempolicy *p)
|
|
{
|
|
if (!atomic_dec_and_test(&p->refcnt))
|
|
return;
|
|
kmem_cache_free(policy_cache, p);
|
|
}
|
|
|
|
static void mpol_rebind_default(struct mempolicy *pol, const nodemask_t *nodes)
|
|
{
|
|
}
|
|
|
|
static void mpol_rebind_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
|
|
{
|
|
nodemask_t tmp;
|
|
|
|
if (pol->flags & MPOL_F_STATIC_NODES)
|
|
nodes_and(tmp, pol->w.user_nodemask, *nodes);
|
|
else if (pol->flags & MPOL_F_RELATIVE_NODES)
|
|
mpol_relative_nodemask(&tmp, &pol->w.user_nodemask, nodes);
|
|
else {
|
|
nodes_remap(tmp, pol->nodes, pol->w.cpuset_mems_allowed,
|
|
*nodes);
|
|
pol->w.cpuset_mems_allowed = *nodes;
|
|
}
|
|
|
|
if (nodes_empty(tmp))
|
|
tmp = *nodes;
|
|
|
|
pol->nodes = tmp;
|
|
}
|
|
|
|
static void mpol_rebind_preferred(struct mempolicy *pol,
|
|
const nodemask_t *nodes)
|
|
{
|
|
pol->w.cpuset_mems_allowed = *nodes;
|
|
}
|
|
|
|
/*
|
|
* mpol_rebind_policy - Migrate a policy to a different set of nodes
|
|
*
|
|
* Per-vma policies are protected by mmap_lock. Allocations using per-task
|
|
* policies are protected by task->mems_allowed_seq to prevent a premature
|
|
* OOM/allocation failure due to parallel nodemask modification.
|
|
*/
|
|
static void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *newmask)
|
|
{
|
|
if (!pol)
|
|
return;
|
|
if (!mpol_store_user_nodemask(pol) &&
|
|
nodes_equal(pol->w.cpuset_mems_allowed, *newmask))
|
|
return;
|
|
|
|
mpol_ops[pol->mode].rebind(pol, newmask);
|
|
}
|
|
|
|
/*
|
|
* Wrapper for mpol_rebind_policy() that just requires task
|
|
* pointer, and updates task mempolicy.
|
|
*
|
|
* Called with task's alloc_lock held.
|
|
*/
|
|
|
|
void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new)
|
|
{
|
|
mpol_rebind_policy(tsk->mempolicy, new);
|
|
}
|
|
|
|
/*
|
|
* Rebind each vma in mm to new nodemask.
|
|
*
|
|
* Call holding a reference to mm. Takes mm->mmap_lock during call.
|
|
*/
|
|
|
|
void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
|
|
mmap_write_lock(mm);
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next)
|
|
mpol_rebind_policy(vma->vm_policy, new);
|
|
mmap_write_unlock(mm);
|
|
}
|
|
|
|
static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
|
|
[MPOL_DEFAULT] = {
|
|
.rebind = mpol_rebind_default,
|
|
},
|
|
[MPOL_INTERLEAVE] = {
|
|
.create = mpol_new_nodemask,
|
|
.rebind = mpol_rebind_nodemask,
|
|
},
|
|
[MPOL_PREFERRED] = {
|
|
.create = mpol_new_preferred,
|
|
.rebind = mpol_rebind_preferred,
|
|
},
|
|
[MPOL_BIND] = {
|
|
.create = mpol_new_nodemask,
|
|
.rebind = mpol_rebind_nodemask,
|
|
},
|
|
[MPOL_LOCAL] = {
|
|
.rebind = mpol_rebind_default,
|
|
},
|
|
[MPOL_PREFERRED_MANY] = {
|
|
.create = mpol_new_nodemask,
|
|
.rebind = mpol_rebind_preferred,
|
|
},
|
|
};
|
|
|
|
static int migrate_page_add(struct page *page, struct list_head *pagelist,
|
|
unsigned long flags);
|
|
|
|
struct queue_pages {
|
|
struct list_head *pagelist;
|
|
unsigned long flags;
|
|
nodemask_t *nmask;
|
|
unsigned long start;
|
|
unsigned long end;
|
|
struct vm_area_struct *first;
|
|
};
|
|
|
|
/*
|
|
* Check if the page's nid is in qp->nmask.
|
|
*
|
|
* If MPOL_MF_INVERT is set in qp->flags, check if the nid is
|
|
* in the invert of qp->nmask.
|
|
*/
|
|
static inline bool queue_pages_required(struct page *page,
|
|
struct queue_pages *qp)
|
|
{
|
|
int nid = page_to_nid(page);
|
|
unsigned long flags = qp->flags;
|
|
|
|
return node_isset(nid, *qp->nmask) == !(flags & MPOL_MF_INVERT);
|
|
}
|
|
|
|
/*
|
|
* queue_pages_pmd() has four possible return values:
|
|
* 0 - pages are placed on the right node or queued successfully, or
|
|
* special page is met, i.e. huge zero page.
|
|
* 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were
|
|
* specified.
|
|
* 2 - THP was split.
|
|
* -EIO - is migration entry or only MPOL_MF_STRICT was specified and an
|
|
* existing page was already on a node that does not follow the
|
|
* policy.
|
|
*/
|
|
static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr,
|
|
unsigned long end, struct mm_walk *walk)
|
|
__releases(ptl)
|
|
{
|
|
int ret = 0;
|
|
struct page *page;
|
|
struct queue_pages *qp = walk->private;
|
|
unsigned long flags;
|
|
|
|
if (unlikely(is_pmd_migration_entry(*pmd))) {
|
|
ret = -EIO;
|
|
goto unlock;
|
|
}
|
|
page = pmd_page(*pmd);
|
|
if (is_huge_zero_page(page)) {
|
|
spin_unlock(ptl);
|
|
walk->action = ACTION_CONTINUE;
|
|
goto out;
|
|
}
|
|
if (!queue_pages_required(page, qp))
|
|
goto unlock;
|
|
|
|
flags = qp->flags;
|
|
/* go to thp migration */
|
|
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
|
|
if (!vma_migratable(walk->vma) ||
|
|
migrate_page_add(page, qp->pagelist, flags)) {
|
|
ret = 1;
|
|
goto unlock;
|
|
}
|
|
} else
|
|
ret = -EIO;
|
|
unlock:
|
|
spin_unlock(ptl);
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Scan through pages checking if pages follow certain conditions,
|
|
* and move them to the pagelist if they do.
|
|
*
|
|
* queue_pages_pte_range() has three possible return values:
|
|
* 0 - pages are placed on the right node or queued successfully, or
|
|
* special page is met, i.e. zero page.
|
|
* 1 - there is unmovable page, and MPOL_MF_MOVE* & MPOL_MF_STRICT were
|
|
* specified.
|
|
* -EIO - only MPOL_MF_STRICT was specified and an existing page was already
|
|
* on a node that does not follow the policy.
|
|
*/
|
|
static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
|
|
unsigned long end, struct mm_walk *walk)
|
|
{
|
|
struct vm_area_struct *vma = walk->vma;
|
|
struct page *page;
|
|
struct queue_pages *qp = walk->private;
|
|
unsigned long flags = qp->flags;
|
|
int ret;
|
|
bool has_unmovable = false;
|
|
pte_t *pte, *mapped_pte;
|
|
spinlock_t *ptl;
|
|
|
|
ptl = pmd_trans_huge_lock(pmd, vma);
|
|
if (ptl) {
|
|
ret = queue_pages_pmd(pmd, ptl, addr, end, walk);
|
|
if (ret != 2)
|
|
return ret;
|
|
}
|
|
/* THP was split, fall through to pte walk */
|
|
|
|
if (pmd_trans_unstable(pmd))
|
|
return 0;
|
|
|
|
mapped_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
|
|
for (; addr != end; pte++, addr += PAGE_SIZE) {
|
|
if (!pte_present(*pte))
|
|
continue;
|
|
page = vm_normal_page(vma, addr, *pte);
|
|
if (!page)
|
|
continue;
|
|
/*
|
|
* vm_normal_page() filters out zero pages, but there might
|
|
* still be PageReserved pages to skip, perhaps in a VDSO.
|
|
*/
|
|
if (PageReserved(page))
|
|
continue;
|
|
if (!queue_pages_required(page, qp))
|
|
continue;
|
|
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
|
|
/* MPOL_MF_STRICT must be specified if we get here */
|
|
if (!vma_migratable(vma)) {
|
|
has_unmovable = true;
|
|
break;
|
|
}
|
|
|
|
/*
|
|
* Do not abort immediately since there may be
|
|
* temporary off LRU pages in the range. Still
|
|
* need migrate other LRU pages.
|
|
*/
|
|
if (migrate_page_add(page, qp->pagelist, flags))
|
|
has_unmovable = true;
|
|
} else
|
|
break;
|
|
}
|
|
pte_unmap_unlock(mapped_pte, ptl);
|
|
cond_resched();
|
|
|
|
if (has_unmovable)
|
|
return 1;
|
|
|
|
return addr != end ? -EIO : 0;
|
|
}
|
|
|
|
static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask,
|
|
unsigned long addr, unsigned long end,
|
|
struct mm_walk *walk)
|
|
{
|
|
int ret = 0;
|
|
#ifdef CONFIG_HUGETLB_PAGE
|
|
struct queue_pages *qp = walk->private;
|
|
unsigned long flags = (qp->flags & MPOL_MF_VALID);
|
|
struct page *page;
|
|
spinlock_t *ptl;
|
|
pte_t entry;
|
|
|
|
ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte);
|
|
entry = huge_ptep_get(pte);
|
|
if (!pte_present(entry))
|
|
goto unlock;
|
|
page = pte_page(entry);
|
|
if (!queue_pages_required(page, qp))
|
|
goto unlock;
|
|
|
|
if (flags == MPOL_MF_STRICT) {
|
|
/*
|
|
* STRICT alone means only detecting misplaced page and no
|
|
* need to further check other vma.
|
|
*/
|
|
ret = -EIO;
|
|
goto unlock;
|
|
}
|
|
|
|
if (!vma_migratable(walk->vma)) {
|
|
/*
|
|
* Must be STRICT with MOVE*, otherwise .test_walk() have
|
|
* stopped walking current vma.
|
|
* Detecting misplaced page but allow migrating pages which
|
|
* have been queued.
|
|
*/
|
|
ret = 1;
|
|
goto unlock;
|
|
}
|
|
|
|
/* With MPOL_MF_MOVE, we migrate only unshared hugepage. */
|
|
if (flags & (MPOL_MF_MOVE_ALL) ||
|
|
(flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) {
|
|
if (!isolate_huge_page(page, qp->pagelist) &&
|
|
(flags & MPOL_MF_STRICT))
|
|
/*
|
|
* Failed to isolate page but allow migrating pages
|
|
* which have been queued.
|
|
*/
|
|
ret = 1;
|
|
}
|
|
unlock:
|
|
spin_unlock(ptl);
|
|
#else
|
|
BUG();
|
|
#endif
|
|
return ret;
|
|
}
|
|
|
|
#ifdef CONFIG_NUMA_BALANCING
|
|
/*
|
|
* This is used to mark a range of virtual addresses to be inaccessible.
|
|
* These are later cleared by a NUMA hinting fault. Depending on these
|
|
* faults, pages may be migrated for better NUMA placement.
|
|
*
|
|
* This is assuming that NUMA faults are handled using PROT_NONE. If
|
|
* an architecture makes a different choice, it will need further
|
|
* changes to the core.
|
|
*/
|
|
unsigned long change_prot_numa(struct vm_area_struct *vma,
|
|
unsigned long addr, unsigned long end)
|
|
{
|
|
int nr_updated;
|
|
|
|
nr_updated = change_protection(vma, addr, end, PAGE_NONE, MM_CP_PROT_NUMA);
|
|
if (nr_updated)
|
|
count_vm_numa_events(NUMA_PTE_UPDATES, nr_updated);
|
|
|
|
return nr_updated;
|
|
}
|
|
#else
|
|
static unsigned long change_prot_numa(struct vm_area_struct *vma,
|
|
unsigned long addr, unsigned long end)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif /* CONFIG_NUMA_BALANCING */
|
|
|
|
static int queue_pages_test_walk(unsigned long start, unsigned long end,
|
|
struct mm_walk *walk)
|
|
{
|
|
struct vm_area_struct *vma = walk->vma;
|
|
struct queue_pages *qp = walk->private;
|
|
unsigned long endvma = vma->vm_end;
|
|
unsigned long flags = qp->flags;
|
|
|
|
/* range check first */
|
|
VM_BUG_ON_VMA(!range_in_vma(vma, start, end), vma);
|
|
|
|
if (!qp->first) {
|
|
qp->first = vma;
|
|
if (!(flags & MPOL_MF_DISCONTIG_OK) &&
|
|
(qp->start < vma->vm_start))
|
|
/* hole at head side of range */
|
|
return -EFAULT;
|
|
}
|
|
if (!(flags & MPOL_MF_DISCONTIG_OK) &&
|
|
((vma->vm_end < qp->end) &&
|
|
(!vma->vm_next || vma->vm_end < vma->vm_next->vm_start)))
|
|
/* hole at middle or tail of range */
|
|
return -EFAULT;
|
|
|
|
/*
|
|
* Need check MPOL_MF_STRICT to return -EIO if possible
|
|
* regardless of vma_migratable
|
|
*/
|
|
if (!vma_migratable(vma) &&
|
|
!(flags & MPOL_MF_STRICT))
|
|
return 1;
|
|
|
|
if (endvma > end)
|
|
endvma = end;
|
|
|
|
if (flags & MPOL_MF_LAZY) {
|
|
/* Similar to task_numa_work, skip inaccessible VMAs */
|
|
if (!is_vm_hugetlb_page(vma) && vma_is_accessible(vma) &&
|
|
!(vma->vm_flags & VM_MIXEDMAP))
|
|
change_prot_numa(vma, start, endvma);
|
|
return 1;
|
|
}
|
|
|
|
/* queue pages from current vma */
|
|
if (flags & MPOL_MF_VALID)
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
static const struct mm_walk_ops queue_pages_walk_ops = {
|
|
.hugetlb_entry = queue_pages_hugetlb,
|
|
.pmd_entry = queue_pages_pte_range,
|
|
.test_walk = queue_pages_test_walk,
|
|
};
|
|
|
|
/*
|
|
* Walk through page tables and collect pages to be migrated.
|
|
*
|
|
* If pages found in a given range are on a set of nodes (determined by
|
|
* @nodes and @flags,) it's isolated and queued to the pagelist which is
|
|
* passed via @private.
|
|
*
|
|
* queue_pages_range() has three possible return values:
|
|
* 1 - there is unmovable page, but MPOL_MF_MOVE* & MPOL_MF_STRICT were
|
|
* specified.
|
|
* 0 - queue pages successfully or no misplaced page.
|
|
* errno - i.e. misplaced pages with MPOL_MF_STRICT specified (-EIO) or
|
|
* memory range specified by nodemask and maxnode points outside
|
|
* your accessible address space (-EFAULT)
|
|
*/
|
|
static int
|
|
queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,
|
|
nodemask_t *nodes, unsigned long flags,
|
|
struct list_head *pagelist)
|
|
{
|
|
int err;
|
|
struct queue_pages qp = {
|
|
.pagelist = pagelist,
|
|
.flags = flags,
|
|
.nmask = nodes,
|
|
.start = start,
|
|
.end = end,
|
|
.first = NULL,
|
|
};
|
|
|
|
err = walk_page_range(mm, start, end, &queue_pages_walk_ops, &qp);
|
|
|
|
if (!qp.first)
|
|
/* whole range in hole */
|
|
err = -EFAULT;
|
|
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Apply policy to a single VMA
|
|
* This must be called with the mmap_lock held for writing.
|
|
*/
|
|
static int vma_replace_policy(struct vm_area_struct *vma,
|
|
struct mempolicy *pol)
|
|
{
|
|
int err;
|
|
struct mempolicy *old;
|
|
struct mempolicy *new;
|
|
|
|
pr_debug("vma %lx-%lx/%lx vm_ops %p vm_file %p set_policy %p\n",
|
|
vma->vm_start, vma->vm_end, vma->vm_pgoff,
|
|
vma->vm_ops, vma->vm_file,
|
|
vma->vm_ops ? vma->vm_ops->set_policy : NULL);
|
|
|
|
new = mpol_dup(pol);
|
|
if (IS_ERR(new))
|
|
return PTR_ERR(new);
|
|
|
|
if (vma->vm_ops && vma->vm_ops->set_policy) {
|
|
err = vma->vm_ops->set_policy(vma, new);
|
|
if (err)
|
|
goto err_out;
|
|
}
|
|
|
|
old = vma->vm_policy;
|
|
vma->vm_policy = new; /* protected by mmap_lock */
|
|
mpol_put(old);
|
|
|
|
return 0;
|
|
err_out:
|
|
mpol_put(new);
|
|
return err;
|
|
}
|
|
|
|
/* Step 2: apply policy to a range and do splits. */
|
|
static int mbind_range(struct mm_struct *mm, unsigned long start,
|
|
unsigned long end, struct mempolicy *new_pol)
|
|
{
|
|
struct vm_area_struct *prev;
|
|
struct vm_area_struct *vma;
|
|
int err = 0;
|
|
pgoff_t pgoff;
|
|
unsigned long vmstart;
|
|
unsigned long vmend;
|
|
|
|
vma = find_vma(mm, start);
|
|
VM_BUG_ON(!vma);
|
|
|
|
prev = vma->vm_prev;
|
|
if (start > vma->vm_start)
|
|
prev = vma;
|
|
|
|
for (; vma && vma->vm_start < end; prev = vma, vma = vma->vm_next) {
|
|
vmstart = max(start, vma->vm_start);
|
|
vmend = min(end, vma->vm_end);
|
|
|
|
if (mpol_equal(vma_policy(vma), new_pol))
|
|
continue;
|
|
|
|
pgoff = vma->vm_pgoff +
|
|
((vmstart - vma->vm_start) >> PAGE_SHIFT);
|
|
prev = vma_merge(mm, prev, vmstart, vmend, vma->vm_flags,
|
|
vma->anon_vma, vma->vm_file, pgoff,
|
|
new_pol, vma->vm_userfaultfd_ctx,
|
|
anon_vma_name(vma));
|
|
if (prev) {
|
|
vma = prev;
|
|
goto replace;
|
|
}
|
|
if (vma->vm_start != vmstart) {
|
|
err = split_vma(vma->vm_mm, vma, vmstart, 1);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
if (vma->vm_end != vmend) {
|
|
err = split_vma(vma->vm_mm, vma, vmend, 0);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
replace:
|
|
err = vma_replace_policy(vma, new_pol);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/* Set the process memory policy */
|
|
static long do_set_mempolicy(unsigned short mode, unsigned short flags,
|
|
nodemask_t *nodes)
|
|
{
|
|
struct mempolicy *new, *old;
|
|
NODEMASK_SCRATCH(scratch);
|
|
int ret;
|
|
|
|
if (!scratch)
|
|
return -ENOMEM;
|
|
|
|
new = mpol_new(mode, flags, nodes);
|
|
if (IS_ERR(new)) {
|
|
ret = PTR_ERR(new);
|
|
goto out;
|
|
}
|
|
|
|
ret = mpol_set_nodemask(new, nodes, scratch);
|
|
if (ret) {
|
|
mpol_put(new);
|
|
goto out;
|
|
}
|
|
task_lock(current);
|
|
old = current->mempolicy;
|
|
current->mempolicy = new;
|
|
if (new && new->mode == MPOL_INTERLEAVE)
|
|
current->il_prev = MAX_NUMNODES-1;
|
|
task_unlock(current);
|
|
mpol_put(old);
|
|
ret = 0;
|
|
out:
|
|
NODEMASK_SCRATCH_FREE(scratch);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Return nodemask for policy for get_mempolicy() query
|
|
*
|
|
* Called with task's alloc_lock held
|
|
*/
|
|
static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
|
|
{
|
|
nodes_clear(*nodes);
|
|
if (p == &default_policy)
|
|
return;
|
|
|
|
switch (p->mode) {
|
|
case MPOL_BIND:
|
|
case MPOL_INTERLEAVE:
|
|
case MPOL_PREFERRED:
|
|
case MPOL_PREFERRED_MANY:
|
|
*nodes = p->nodes;
|
|
break;
|
|
case MPOL_LOCAL:
|
|
/* return empty node mask for local allocation */
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
static int lookup_node(struct mm_struct *mm, unsigned long addr)
|
|
{
|
|
struct page *p = NULL;
|
|
int err;
|
|
|
|
int locked = 1;
|
|
err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked);
|
|
if (err > 0) {
|
|
err = page_to_nid(p);
|
|
put_page(p);
|
|
}
|
|
if (locked)
|
|
mmap_read_unlock(mm);
|
|
return err;
|
|
}
|
|
|
|
/* Retrieve NUMA policy */
|
|
static long do_get_mempolicy(int *policy, nodemask_t *nmask,
|
|
unsigned long addr, unsigned long flags)
|
|
{
|
|
int err;
|
|
struct mm_struct *mm = current->mm;
|
|
struct vm_area_struct *vma = NULL;
|
|
struct mempolicy *pol = current->mempolicy, *pol_refcount = NULL;
|
|
|
|
if (flags &
|
|
~(unsigned long)(MPOL_F_NODE|MPOL_F_ADDR|MPOL_F_MEMS_ALLOWED))
|
|
return -EINVAL;
|
|
|
|
if (flags & MPOL_F_MEMS_ALLOWED) {
|
|
if (flags & (MPOL_F_NODE|MPOL_F_ADDR))
|
|
return -EINVAL;
|
|
*policy = 0; /* just so it's initialized */
|
|
task_lock(current);
|
|
*nmask = cpuset_current_mems_allowed;
|
|
task_unlock(current);
|
|
return 0;
|
|
}
|
|
|
|
if (flags & MPOL_F_ADDR) {
|
|
/*
|
|
* Do NOT fall back to task policy if the
|
|
* vma/shared policy at addr is NULL. We
|
|
* want to return MPOL_DEFAULT in this case.
|
|
*/
|
|
mmap_read_lock(mm);
|
|
vma = vma_lookup(mm, addr);
|
|
if (!vma) {
|
|
mmap_read_unlock(mm);
|
|
return -EFAULT;
|
|
}
|
|
if (vma->vm_ops && vma->vm_ops->get_policy)
|
|
pol = vma->vm_ops->get_policy(vma, addr);
|
|
else
|
|
pol = vma->vm_policy;
|
|
} else if (addr)
|
|
return -EINVAL;
|
|
|
|
if (!pol)
|
|
pol = &default_policy; /* indicates default behavior */
|
|
|
|
if (flags & MPOL_F_NODE) {
|
|
if (flags & MPOL_F_ADDR) {
|
|
/*
|
|
* Take a refcount on the mpol, lookup_node()
|
|
* will drop the mmap_lock, so after calling
|
|
* lookup_node() only "pol" remains valid, "vma"
|
|
* is stale.
|
|
*/
|
|
pol_refcount = pol;
|
|
vma = NULL;
|
|
mpol_get(pol);
|
|
err = lookup_node(mm, addr);
|
|
if (err < 0)
|
|
goto out;
|
|
*policy = err;
|
|
} else if (pol == current->mempolicy &&
|
|
pol->mode == MPOL_INTERLEAVE) {
|
|
*policy = next_node_in(current->il_prev, pol->nodes);
|
|
} else {
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
} else {
|
|
*policy = pol == &default_policy ? MPOL_DEFAULT :
|
|
pol->mode;
|
|
/*
|
|
* Internal mempolicy flags must be masked off before exposing
|
|
* the policy to userspace.
|
|
*/
|
|
*policy |= (pol->flags & MPOL_MODE_FLAGS);
|
|
}
|
|
|
|
err = 0;
|
|
if (nmask) {
|
|
if (mpol_store_user_nodemask(pol)) {
|
|
*nmask = pol->w.user_nodemask;
|
|
} else {
|
|
task_lock(current);
|
|
get_policy_nodemask(pol, nmask);
|
|
task_unlock(current);
|
|
}
|
|
}
|
|
|
|
out:
|
|
mpol_cond_put(pol);
|
|
if (vma)
|
|
mmap_read_unlock(mm);
|
|
if (pol_refcount)
|
|
mpol_put(pol_refcount);
|
|
return err;
|
|
}
|
|
|
|
#ifdef CONFIG_MIGRATION
|
|
/*
|
|
* page migration, thp tail pages can be passed.
|
|
*/
|
|
static int migrate_page_add(struct page *page, struct list_head *pagelist,
|
|
unsigned long flags)
|
|
{
|
|
struct page *head = compound_head(page);
|
|
/*
|
|
* Avoid migrating a page that is shared with others.
|
|
*/
|
|
if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(head) == 1) {
|
|
if (!isolate_lru_page(head)) {
|
|
list_add_tail(&head->lru, pagelist);
|
|
mod_node_page_state(page_pgdat(head),
|
|
NR_ISOLATED_ANON + page_is_file_lru(head),
|
|
thp_nr_pages(head));
|
|
} else if (flags & MPOL_MF_STRICT) {
|
|
/*
|
|
* Non-movable page may reach here. And, there may be
|
|
* temporary off LRU pages or non-LRU movable pages.
|
|
* Treat them as unmovable pages since they can't be
|
|
* isolated, so they can't be moved at the moment. It
|
|
* should return -EIO for this case too.
|
|
*/
|
|
return -EIO;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Migrate pages from one node to a target node.
|
|
* Returns error or the number of pages not migrated.
|
|
*/
|
|
static int migrate_to_node(struct mm_struct *mm, int source, int dest,
|
|
int flags)
|
|
{
|
|
nodemask_t nmask;
|
|
LIST_HEAD(pagelist);
|
|
int err = 0;
|
|
struct migration_target_control mtc = {
|
|
.nid = dest,
|
|
.gfp_mask = GFP_HIGHUSER_MOVABLE | __GFP_THISNODE,
|
|
};
|
|
|
|
nodes_clear(nmask);
|
|
node_set(source, nmask);
|
|
|
|
/*
|
|
* This does not "check" the range but isolates all pages that
|
|
* need migration. Between passing in the full user address
|
|
* space range and MPOL_MF_DISCONTIG_OK, this call can not fail.
|
|
*/
|
|
VM_BUG_ON(!(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)));
|
|
queue_pages_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
|
|
flags | MPOL_MF_DISCONTIG_OK, &pagelist);
|
|
|
|
if (!list_empty(&pagelist)) {
|
|
err = migrate_pages(&pagelist, alloc_migration_target, NULL,
|
|
(unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL, NULL);
|
|
if (err)
|
|
putback_movable_pages(&pagelist);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Move pages between the two nodesets so as to preserve the physical
|
|
* layout as much as possible.
|
|
*
|
|
* Returns the number of page that could not be moved.
|
|
*/
|
|
int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
|
|
const nodemask_t *to, int flags)
|
|
{
|
|
int busy = 0;
|
|
int err = 0;
|
|
nodemask_t tmp;
|
|
|
|
lru_cache_disable();
|
|
|
|
mmap_read_lock(mm);
|
|
|
|
/*
|
|
* Find a 'source' bit set in 'tmp' whose corresponding 'dest'
|
|
* bit in 'to' is not also set in 'tmp'. Clear the found 'source'
|
|
* bit in 'tmp', and return that <source, dest> pair for migration.
|
|
* The pair of nodemasks 'to' and 'from' define the map.
|
|
*
|
|
* If no pair of bits is found that way, fallback to picking some
|
|
* pair of 'source' and 'dest' bits that are not the same. If the
|
|
* 'source' and 'dest' bits are the same, this represents a node
|
|
* that will be migrating to itself, so no pages need move.
|
|
*
|
|
* If no bits are left in 'tmp', or if all remaining bits left
|
|
* in 'tmp' correspond to the same bit in 'to', return false
|
|
* (nothing left to migrate).
|
|
*
|
|
* This lets us pick a pair of nodes to migrate between, such that
|
|
* if possible the dest node is not already occupied by some other
|
|
* source node, minimizing the risk of overloading the memory on a
|
|
* node that would happen if we migrated incoming memory to a node
|
|
* before migrating outgoing memory source that same node.
|
|
*
|
|
* A single scan of tmp is sufficient. As we go, we remember the
|
|
* most recent <s, d> pair that moved (s != d). If we find a pair
|
|
* that not only moved, but what's better, moved to an empty slot
|
|
* (d is not set in tmp), then we break out then, with that pair.
|
|
* Otherwise when we finish scanning from_tmp, we at least have the
|
|
* most recent <s, d> pair that moved. If we get all the way through
|
|
* the scan of tmp without finding any node that moved, much less
|
|
* moved to an empty node, then there is nothing left worth migrating.
|
|
*/
|
|
|
|
tmp = *from;
|
|
while (!nodes_empty(tmp)) {
|
|
int s, d;
|
|
int source = NUMA_NO_NODE;
|
|
int dest = 0;
|
|
|
|
for_each_node_mask(s, tmp) {
|
|
|
|
/*
|
|
* do_migrate_pages() tries to maintain the relative
|
|
* node relationship of the pages established between
|
|
* threads and memory areas.
|
|
*
|
|
* However if the number of source nodes is not equal to
|
|
* the number of destination nodes we can not preserve
|
|
* this node relative relationship. In that case, skip
|
|
* copying memory from a node that is in the destination
|
|
* mask.
|
|
*
|
|
* Example: [2,3,4] -> [3,4,5] moves everything.
|
|
* [0-7] - > [3,4,5] moves only 0,1,2,6,7.
|
|
*/
|
|
|
|
if ((nodes_weight(*from) != nodes_weight(*to)) &&
|
|
(node_isset(s, *to)))
|
|
continue;
|
|
|
|
d = node_remap(s, *from, *to);
|
|
if (s == d)
|
|
continue;
|
|
|
|
source = s; /* Node moved. Memorize */
|
|
dest = d;
|
|
|
|
/* dest not in remaining from nodes? */
|
|
if (!node_isset(dest, tmp))
|
|
break;
|
|
}
|
|
if (source == NUMA_NO_NODE)
|
|
break;
|
|
|
|
node_clear(source, tmp);
|
|
err = migrate_to_node(mm, source, dest, flags);
|
|
if (err > 0)
|
|
busy += err;
|
|
if (err < 0)
|
|
break;
|
|
}
|
|
mmap_read_unlock(mm);
|
|
|
|
lru_cache_enable();
|
|
if (err < 0)
|
|
return err;
|
|
return busy;
|
|
|
|
}
|
|
|
|
/*
|
|
* Allocate a new page for page migration based on vma policy.
|
|
* Start by assuming the page is mapped by the same vma as contains @start.
|
|
* Search forward from there, if not. N.B., this assumes that the
|
|
* list of pages handed to migrate_pages()--which is how we get here--
|
|
* is in virtual address order.
|
|
*/
|
|
static struct page *new_page(struct page *page, unsigned long start)
|
|
{
|
|
struct vm_area_struct *vma;
|
|
unsigned long address;
|
|
|
|
vma = find_vma(current->mm, start);
|
|
while (vma) {
|
|
address = page_address_in_vma(page, vma);
|
|
if (address != -EFAULT)
|
|
break;
|
|
vma = vma->vm_next;
|
|
}
|
|
|
|
if (PageHuge(page)) {
|
|
return alloc_huge_page_vma(page_hstate(compound_head(page)),
|
|
vma, address);
|
|
} else if (PageTransHuge(page)) {
|
|
struct page *thp;
|
|
|
|
thp = alloc_hugepage_vma(GFP_TRANSHUGE, vma, address,
|
|
HPAGE_PMD_ORDER);
|
|
if (!thp)
|
|
return NULL;
|
|
prep_transhuge_page(thp);
|
|
return thp;
|
|
}
|
|
/*
|
|
* if !vma, alloc_page_vma() will use task or system default policy
|
|
*/
|
|
return alloc_page_vma(GFP_HIGHUSER_MOVABLE | __GFP_RETRY_MAYFAIL,
|
|
vma, address);
|
|
}
|
|
#else
|
|
|
|
static int migrate_page_add(struct page *page, struct list_head *pagelist,
|
|
unsigned long flags)
|
|
{
|
|
return -EIO;
|
|
}
|
|
|
|
int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
|
|
const nodemask_t *to, int flags)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
|
|
static struct page *new_page(struct page *page, unsigned long start)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
static long do_mbind(unsigned long start, unsigned long len,
|
|
unsigned short mode, unsigned short mode_flags,
|
|
nodemask_t *nmask, unsigned long flags)
|
|
{
|
|
struct mm_struct *mm = current->mm;
|
|
struct mempolicy *new;
|
|
unsigned long end;
|
|
int err;
|
|
int ret;
|
|
LIST_HEAD(pagelist);
|
|
|
|
if (flags & ~(unsigned long)MPOL_MF_VALID)
|
|
return -EINVAL;
|
|
if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
|
|
return -EPERM;
|
|
|
|
if (start & ~PAGE_MASK)
|
|
return -EINVAL;
|
|
|
|
if (mode == MPOL_DEFAULT)
|
|
flags &= ~MPOL_MF_STRICT;
|
|
|
|
len = (len + PAGE_SIZE - 1) & PAGE_MASK;
|
|
end = start + len;
|
|
|
|
if (end < start)
|
|
return -EINVAL;
|
|
if (end == start)
|
|
return 0;
|
|
|
|
new = mpol_new(mode, mode_flags, nmask);
|
|
if (IS_ERR(new))
|
|
return PTR_ERR(new);
|
|
|
|
if (flags & MPOL_MF_LAZY)
|
|
new->flags |= MPOL_F_MOF;
|
|
|
|
/*
|
|
* If we are using the default policy then operation
|
|
* on discontinuous address spaces is okay after all
|
|
*/
|
|
if (!new)
|
|
flags |= MPOL_MF_DISCONTIG_OK;
|
|
|
|
pr_debug("mbind %lx-%lx mode:%d flags:%d nodes:%lx\n",
|
|
start, start + len, mode, mode_flags,
|
|
nmask ? nodes_addr(*nmask)[0] : NUMA_NO_NODE);
|
|
|
|
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
|
|
|
|
lru_cache_disable();
|
|
}
|
|
{
|
|
NODEMASK_SCRATCH(scratch);
|
|
if (scratch) {
|
|
mmap_write_lock(mm);
|
|
err = mpol_set_nodemask(new, nmask, scratch);
|
|
if (err)
|
|
mmap_write_unlock(mm);
|
|
} else
|
|
err = -ENOMEM;
|
|
NODEMASK_SCRATCH_FREE(scratch);
|
|
}
|
|
if (err)
|
|
goto mpol_out;
|
|
|
|
ret = queue_pages_range(mm, start, end, nmask,
|
|
flags | MPOL_MF_INVERT, &pagelist);
|
|
|
|
if (ret < 0) {
|
|
err = ret;
|
|
goto up_out;
|
|
}
|
|
|
|
err = mbind_range(mm, start, end, new);
|
|
|
|
if (!err) {
|
|
int nr_failed = 0;
|
|
|
|
if (!list_empty(&pagelist)) {
|
|
WARN_ON_ONCE(flags & MPOL_MF_LAZY);
|
|
nr_failed = migrate_pages(&pagelist, new_page, NULL,
|
|
start, MIGRATE_SYNC, MR_MEMPOLICY_MBIND, NULL);
|
|
if (nr_failed)
|
|
putback_movable_pages(&pagelist);
|
|
}
|
|
|
|
if ((ret > 0) || (nr_failed && (flags & MPOL_MF_STRICT)))
|
|
err = -EIO;
|
|
} else {
|
|
up_out:
|
|
if (!list_empty(&pagelist))
|
|
putback_movable_pages(&pagelist);
|
|
}
|
|
|
|
mmap_write_unlock(mm);
|
|
mpol_out:
|
|
mpol_put(new);
|
|
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL))
|
|
lru_cache_enable();
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* User space interface with variable sized bitmaps for nodelists.
|
|
*/
|
|
static int get_bitmap(unsigned long *mask, const unsigned long __user *nmask,
|
|
unsigned long maxnode)
|
|
{
|
|
unsigned long nlongs = BITS_TO_LONGS(maxnode);
|
|
int ret;
|
|
|
|
if (in_compat_syscall())
|
|
ret = compat_get_bitmap(mask,
|
|
(const compat_ulong_t __user *)nmask,
|
|
maxnode);
|
|
else
|
|
ret = copy_from_user(mask, nmask,
|
|
nlongs * sizeof(unsigned long));
|
|
|
|
if (ret)
|
|
return -EFAULT;
|
|
|
|
if (maxnode % BITS_PER_LONG)
|
|
mask[nlongs - 1] &= (1UL << (maxnode % BITS_PER_LONG)) - 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Copy a node mask from user space. */
|
|
static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask,
|
|
unsigned long maxnode)
|
|
{
|
|
--maxnode;
|
|
nodes_clear(*nodes);
|
|
if (maxnode == 0 || !nmask)
|
|
return 0;
|
|
if (maxnode > PAGE_SIZE*BITS_PER_BYTE)
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* When the user specified more nodes than supported just check
|
|
* if the non supported part is all zero, one word at a time,
|
|
* starting at the end.
|
|
*/
|
|
while (maxnode > MAX_NUMNODES) {
|
|
unsigned long bits = min_t(unsigned long, maxnode, BITS_PER_LONG);
|
|
unsigned long t;
|
|
|
|
if (get_bitmap(&t, &nmask[maxnode / BITS_PER_LONG], bits))
|
|
return -EFAULT;
|
|
|
|
if (maxnode - bits >= MAX_NUMNODES) {
|
|
maxnode -= bits;
|
|
} else {
|
|
maxnode = MAX_NUMNODES;
|
|
t &= ~((1UL << (MAX_NUMNODES % BITS_PER_LONG)) - 1);
|
|
}
|
|
if (t)
|
|
return -EINVAL;
|
|
}
|
|
|
|
return get_bitmap(nodes_addr(*nodes), nmask, maxnode);
|
|
}
|
|
|
|
/* Copy a kernel node mask to user space */
|
|
static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode,
|
|
nodemask_t *nodes)
|
|
{
|
|
unsigned long copy = ALIGN(maxnode-1, 64) / 8;
|
|
unsigned int nbytes = BITS_TO_LONGS(nr_node_ids) * sizeof(long);
|
|
bool compat = in_compat_syscall();
|
|
|
|
if (compat)
|
|
nbytes = BITS_TO_COMPAT_LONGS(nr_node_ids) * sizeof(compat_long_t);
|
|
|
|
if (copy > nbytes) {
|
|
if (copy > PAGE_SIZE)
|
|
return -EINVAL;
|
|
if (clear_user((char __user *)mask + nbytes, copy - nbytes))
|
|
return -EFAULT;
|
|
copy = nbytes;
|
|
maxnode = nr_node_ids;
|
|
}
|
|
|
|
if (compat)
|
|
return compat_put_bitmap((compat_ulong_t __user *)mask,
|
|
nodes_addr(*nodes), maxnode);
|
|
|
|
return copy_to_user(mask, nodes_addr(*nodes), copy) ? -EFAULT : 0;
|
|
}
|
|
|
|
/* Basic parameter sanity check used by both mbind() and set_mempolicy() */
|
|
static inline int sanitize_mpol_flags(int *mode, unsigned short *flags)
|
|
{
|
|
*flags = *mode & MPOL_MODE_FLAGS;
|
|
*mode &= ~MPOL_MODE_FLAGS;
|
|
|
|
if ((unsigned int)(*mode) >= MPOL_MAX)
|
|
return -EINVAL;
|
|
if ((*flags & MPOL_F_STATIC_NODES) && (*flags & MPOL_F_RELATIVE_NODES))
|
|
return -EINVAL;
|
|
if (*flags & MPOL_F_NUMA_BALANCING) {
|
|
if (*mode != MPOL_BIND)
|
|
return -EINVAL;
|
|
*flags |= (MPOL_F_MOF | MPOL_F_MORON);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static long kernel_mbind(unsigned long start, unsigned long len,
|
|
unsigned long mode, const unsigned long __user *nmask,
|
|
unsigned long maxnode, unsigned int flags)
|
|
{
|
|
unsigned short mode_flags;
|
|
nodemask_t nodes;
|
|
int lmode = mode;
|
|
int err;
|
|
|
|
start = untagged_addr(start);
|
|
err = sanitize_mpol_flags(&lmode, &mode_flags);
|
|
if (err)
|
|
return err;
|
|
|
|
err = get_nodes(&nodes, nmask, maxnode);
|
|
if (err)
|
|
return err;
|
|
|
|
return do_mbind(start, len, lmode, mode_flags, &nodes, flags);
|
|
}
|
|
|
|
SYSCALL_DEFINE6(mbind, unsigned long, start, unsigned long, len,
|
|
unsigned long, mode, const unsigned long __user *, nmask,
|
|
unsigned long, maxnode, unsigned int, flags)
|
|
{
|
|
return kernel_mbind(start, len, mode, nmask, maxnode, flags);
|
|
}
|
|
|
|
/* Set the process memory policy */
|
|
static long kernel_set_mempolicy(int mode, const unsigned long __user *nmask,
|
|
unsigned long maxnode)
|
|
{
|
|
unsigned short mode_flags;
|
|
nodemask_t nodes;
|
|
int lmode = mode;
|
|
int err;
|
|
|
|
err = sanitize_mpol_flags(&lmode, &mode_flags);
|
|
if (err)
|
|
return err;
|
|
|
|
err = get_nodes(&nodes, nmask, maxnode);
|
|
if (err)
|
|
return err;
|
|
|
|
return do_set_mempolicy(lmode, mode_flags, &nodes);
|
|
}
|
|
|
|
SYSCALL_DEFINE3(set_mempolicy, int, mode, const unsigned long __user *, nmask,
|
|
unsigned long, maxnode)
|
|
{
|
|
return kernel_set_mempolicy(mode, nmask, maxnode);
|
|
}
|
|
|
|
static int kernel_migrate_pages(pid_t pid, unsigned long maxnode,
|
|
const unsigned long __user *old_nodes,
|
|
const unsigned long __user *new_nodes)
|
|
{
|
|
struct mm_struct *mm = NULL;
|
|
struct task_struct *task;
|
|
nodemask_t task_nodes;
|
|
int err;
|
|
nodemask_t *old;
|
|
nodemask_t *new;
|
|
NODEMASK_SCRATCH(scratch);
|
|
|
|
if (!scratch)
|
|
return -ENOMEM;
|
|
|
|
old = &scratch->mask1;
|
|
new = &scratch->mask2;
|
|
|
|
err = get_nodes(old, old_nodes, maxnode);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = get_nodes(new, new_nodes, maxnode);
|
|
if (err)
|
|
goto out;
|
|
|
|
/* Find the mm_struct */
|
|
rcu_read_lock();
|
|
task = pid ? find_task_by_vpid(pid) : current;
|
|
if (!task) {
|
|
rcu_read_unlock();
|
|
err = -ESRCH;
|
|
goto out;
|
|
}
|
|
get_task_struct(task);
|
|
|
|
err = -EINVAL;
|
|
|
|
/*
|
|
* Check if this process has the right to modify the specified process.
|
|
* Use the regular "ptrace_may_access()" checks.
|
|
*/
|
|
if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) {
|
|
rcu_read_unlock();
|
|
err = -EPERM;
|
|
goto out_put;
|
|
}
|
|
rcu_read_unlock();
|
|
|
|
task_nodes = cpuset_mems_allowed(task);
|
|
/* Is the user allowed to access the target nodes? */
|
|
if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) {
|
|
err = -EPERM;
|
|
goto out_put;
|
|
}
|
|
|
|
task_nodes = cpuset_mems_allowed(current);
|
|
nodes_and(*new, *new, task_nodes);
|
|
if (nodes_empty(*new))
|
|
goto out_put;
|
|
|
|
err = security_task_movememory(task);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
mm = get_task_mm(task);
|
|
put_task_struct(task);
|
|
|
|
if (!mm) {
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
|
|
err = do_migrate_pages(mm, old, new,
|
|
capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
|
|
|
|
mmput(mm);
|
|
out:
|
|
NODEMASK_SCRATCH_FREE(scratch);
|
|
|
|
return err;
|
|
|
|
out_put:
|
|
put_task_struct(task);
|
|
goto out;
|
|
|
|
}
|
|
|
|
SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
|
|
const unsigned long __user *, old_nodes,
|
|
const unsigned long __user *, new_nodes)
|
|
{
|
|
return kernel_migrate_pages(pid, maxnode, old_nodes, new_nodes);
|
|
}
|
|
|
|
|
|
/* Retrieve NUMA policy */
|
|
static int kernel_get_mempolicy(int __user *policy,
|
|
unsigned long __user *nmask,
|
|
unsigned long maxnode,
|
|
unsigned long addr,
|
|
unsigned long flags)
|
|
{
|
|
int err;
|
|
int pval;
|
|
nodemask_t nodes;
|
|
|
|
if (nmask != NULL && maxnode < nr_node_ids)
|
|
return -EINVAL;
|
|
|
|
addr = untagged_addr(addr);
|
|
|
|
err = do_get_mempolicy(&pval, &nodes, addr, flags);
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
if (policy && put_user(pval, policy))
|
|
return -EFAULT;
|
|
|
|
if (nmask)
|
|
err = copy_nodes_to_user(nmask, maxnode, &nodes);
|
|
|
|
return err;
|
|
}
|
|
|
|
SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
|
|
unsigned long __user *, nmask, unsigned long, maxnode,
|
|
unsigned long, addr, unsigned long, flags)
|
|
{
|
|
return kernel_get_mempolicy(policy, nmask, maxnode, addr, flags);
|
|
}
|
|
|
|
bool vma_migratable(struct vm_area_struct *vma)
|
|
{
|
|
if (vma->vm_flags & (VM_IO | VM_PFNMAP))
|
|
return false;
|
|
|
|
/*
|
|
* DAX device mappings require predictable access latency, so avoid
|
|
* incurring periodic faults.
|
|
*/
|
|
if (vma_is_dax(vma))
|
|
return false;
|
|
|
|
if (is_vm_hugetlb_page(vma) &&
|
|
!hugepage_migration_supported(hstate_vma(vma)))
|
|
return false;
|
|
|
|
/*
|
|
* Migration allocates pages in the highest zone. If we cannot
|
|
* do so then migration (at least from node to node) is not
|
|
* possible.
|
|
*/
|
|
if (vma->vm_file &&
|
|
gfp_zone(mapping_gfp_mask(vma->vm_file->f_mapping))
|
|
< policy_zone)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
|
|
unsigned long addr)
|
|
{
|
|
struct mempolicy *pol = NULL;
|
|
|
|
if (vma) {
|
|
if (vma->vm_ops && vma->vm_ops->get_policy) {
|
|
pol = vma->vm_ops->get_policy(vma, addr);
|
|
} else if (vma->vm_policy) {
|
|
pol = vma->vm_policy;
|
|
|
|
/*
|
|
* shmem_alloc_page() passes MPOL_F_SHARED policy with
|
|
* a pseudo vma whose vma->vm_ops=NULL. Take a reference
|
|
* count on these policies which will be dropped by
|
|
* mpol_cond_put() later
|
|
*/
|
|
if (mpol_needs_cond_ref(pol))
|
|
mpol_get(pol);
|
|
}
|
|
}
|
|
|
|
return pol;
|
|
}
|
|
|
|
/*
|
|
* get_vma_policy(@vma, @addr)
|
|
* @vma: virtual memory area whose policy is sought
|
|
* @addr: address in @vma for shared policy lookup
|
|
*
|
|
* Returns effective policy for a VMA at specified address.
|
|
* Falls back to current->mempolicy or system default policy, as necessary.
|
|
* Shared policies [those marked as MPOL_F_SHARED] require an extra reference
|
|
* count--added by the get_policy() vm_op, as appropriate--to protect against
|
|
* freeing by another task. It is the caller's responsibility to free the
|
|
* extra reference for shared policies.
|
|
*/
|
|
static struct mempolicy *get_vma_policy(struct vm_area_struct *vma,
|
|
unsigned long addr)
|
|
{
|
|
struct mempolicy *pol = __get_vma_policy(vma, addr);
|
|
|
|
if (!pol)
|
|
pol = get_task_policy(current);
|
|
|
|
return pol;
|
|
}
|
|
|
|
bool vma_policy_mof(struct vm_area_struct *vma)
|
|
{
|
|
struct mempolicy *pol;
|
|
|
|
if (vma->vm_ops && vma->vm_ops->get_policy) {
|
|
bool ret = false;
|
|
|
|
pol = vma->vm_ops->get_policy(vma, vma->vm_start);
|
|
if (pol && (pol->flags & MPOL_F_MOF))
|
|
ret = true;
|
|
mpol_cond_put(pol);
|
|
|
|
return ret;
|
|
}
|
|
|
|
pol = vma->vm_policy;
|
|
if (!pol)
|
|
pol = get_task_policy(current);
|
|
|
|
return pol->flags & MPOL_F_MOF;
|
|
}
|
|
|
|
static int apply_policy_zone(struct mempolicy *policy, enum zone_type zone)
|
|
{
|
|
enum zone_type dynamic_policy_zone = policy_zone;
|
|
|
|
BUG_ON(dynamic_policy_zone == ZONE_MOVABLE);
|
|
|
|
/*
|
|
* if policy->nodes has movable memory only,
|
|
* we apply policy when gfp_zone(gfp) = ZONE_MOVABLE only.
|
|
*
|
|
* policy->nodes is intersect with node_states[N_MEMORY].
|
|
* so if the following test fails, it implies
|
|
* policy->nodes has movable memory only.
|
|
*/
|
|
if (!nodes_intersects(policy->nodes, node_states[N_HIGH_MEMORY]))
|
|
dynamic_policy_zone = ZONE_MOVABLE;
|
|
|
|
return zone >= dynamic_policy_zone;
|
|
}
|
|
|
|
/*
|
|
* Return a nodemask representing a mempolicy for filtering nodes for
|
|
* page allocation
|
|
*/
|
|
nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)
|
|
{
|
|
int mode = policy->mode;
|
|
|
|
/* Lower zones don't get a nodemask applied for MPOL_BIND */
|
|
if (unlikely(mode == MPOL_BIND) &&
|
|
apply_policy_zone(policy, gfp_zone(gfp)) &&
|
|
cpuset_nodemask_valid_mems_allowed(&policy->nodes))
|
|
return &policy->nodes;
|
|
|
|
if (mode == MPOL_PREFERRED_MANY)
|
|
return &policy->nodes;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
* Return the preferred node id for 'prefer' mempolicy, and return
|
|
* the given id for all other policies.
|
|
*
|
|
* policy_node() is always coupled with policy_nodemask(), which
|
|
* secures the nodemask limit for 'bind' and 'prefer-many' policy.
|
|
*/
|
|
static int policy_node(gfp_t gfp, struct mempolicy *policy, int nd)
|
|
{
|
|
if (policy->mode == MPOL_PREFERRED) {
|
|
nd = first_node(policy->nodes);
|
|
} else {
|
|
/*
|
|
* __GFP_THISNODE shouldn't even be used with the bind policy
|
|
* because we might easily break the expectation to stay on the
|
|
* requested node and not break the policy.
|
|
*/
|
|
WARN_ON_ONCE(policy->mode == MPOL_BIND && (gfp & __GFP_THISNODE));
|
|
}
|
|
|
|
return nd;
|
|
}
|
|
|
|
/* Do dynamic interleaving for a process */
|
|
static unsigned interleave_nodes(struct mempolicy *policy)
|
|
{
|
|
unsigned next;
|
|
struct task_struct *me = current;
|
|
|
|
next = next_node_in(me->il_prev, policy->nodes);
|
|
if (next < MAX_NUMNODES)
|
|
me->il_prev = next;
|
|
return next;
|
|
}
|
|
|
|
/*
|
|
* Depending on the memory policy provide a node from which to allocate the
|
|
* next slab entry.
|
|
*/
|
|
unsigned int mempolicy_slab_node(void)
|
|
{
|
|
struct mempolicy *policy;
|
|
int node = numa_mem_id();
|
|
|
|
if (!in_task())
|
|
return node;
|
|
|
|
policy = current->mempolicy;
|
|
if (!policy)
|
|
return node;
|
|
|
|
switch (policy->mode) {
|
|
case MPOL_PREFERRED:
|
|
return first_node(policy->nodes);
|
|
|
|
case MPOL_INTERLEAVE:
|
|
return interleave_nodes(policy);
|
|
|
|
case MPOL_BIND:
|
|
case MPOL_PREFERRED_MANY:
|
|
{
|
|
struct zoneref *z;
|
|
|
|
/*
|
|
* Follow bind policy behavior and start allocation at the
|
|
* first node.
|
|
*/
|
|
struct zonelist *zonelist;
|
|
enum zone_type highest_zoneidx = gfp_zone(GFP_KERNEL);
|
|
zonelist = &NODE_DATA(node)->node_zonelists[ZONELIST_FALLBACK];
|
|
z = first_zones_zonelist(zonelist, highest_zoneidx,
|
|
&policy->nodes);
|
|
return z->zone ? zone_to_nid(z->zone) : node;
|
|
}
|
|
case MPOL_LOCAL:
|
|
return node;
|
|
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Do static interleaving for a VMA with known offset @n. Returns the n'th
|
|
* node in pol->nodes (starting from n=0), wrapping around if n exceeds the
|
|
* number of present nodes.
|
|
*/
|
|
static unsigned offset_il_node(struct mempolicy *pol, unsigned long n)
|
|
{
|
|
nodemask_t nodemask = pol->nodes;
|
|
unsigned int target, nnodes;
|
|
int i;
|
|
int nid;
|
|
/*
|
|
* The barrier will stabilize the nodemask in a register or on
|
|
* the stack so that it will stop changing under the code.
|
|
*
|
|
* Between first_node() and next_node(), pol->nodes could be changed
|
|
* by other threads. So we put pol->nodes in a local stack.
|
|
*/
|
|
barrier();
|
|
|
|
nnodes = nodes_weight(nodemask);
|
|
if (!nnodes)
|
|
return numa_node_id();
|
|
target = (unsigned int)n % nnodes;
|
|
nid = first_node(nodemask);
|
|
for (i = 0; i < target; i++)
|
|
nid = next_node(nid, nodemask);
|
|
return nid;
|
|
}
|
|
|
|
/* Determine a node number for interleave */
|
|
static inline unsigned interleave_nid(struct mempolicy *pol,
|
|
struct vm_area_struct *vma, unsigned long addr, int shift)
|
|
{
|
|
if (vma) {
|
|
unsigned long off;
|
|
|
|
/*
|
|
* for small pages, there is no difference between
|
|
* shift and PAGE_SHIFT, so the bit-shift is safe.
|
|
* for huge pages, since vm_pgoff is in units of small
|
|
* pages, we need to shift off the always 0 bits to get
|
|
* a useful offset.
|
|
*/
|
|
BUG_ON(shift < PAGE_SHIFT);
|
|
off = vma->vm_pgoff >> (shift - PAGE_SHIFT);
|
|
off += (addr - vma->vm_start) >> shift;
|
|
return offset_il_node(pol, off);
|
|
} else
|
|
return interleave_nodes(pol);
|
|
}
|
|
|
|
#ifdef CONFIG_HUGETLBFS
|
|
/*
|
|
* huge_node(@vma, @addr, @gfp_flags, @mpol)
|
|
* @vma: virtual memory area whose policy is sought
|
|
* @addr: address in @vma for shared policy lookup and interleave policy
|
|
* @gfp_flags: for requested zone
|
|
* @mpol: pointer to mempolicy pointer for reference counted mempolicy
|
|
* @nodemask: pointer to nodemask pointer for 'bind' and 'prefer-many' policy
|
|
*
|
|
* Returns a nid suitable for a huge page allocation and a pointer
|
|
* to the struct mempolicy for conditional unref after allocation.
|
|
* If the effective policy is 'bind' or 'prefer-many', returns a pointer
|
|
* to the mempolicy's @nodemask for filtering the zonelist.
|
|
*
|
|
* Must be protected by read_mems_allowed_begin()
|
|
*/
|
|
int huge_node(struct vm_area_struct *vma, unsigned long addr, gfp_t gfp_flags,
|
|
struct mempolicy **mpol, nodemask_t **nodemask)
|
|
{
|
|
int nid;
|
|
int mode;
|
|
|
|
*mpol = get_vma_policy(vma, addr);
|
|
*nodemask = NULL;
|
|
mode = (*mpol)->mode;
|
|
|
|
if (unlikely(mode == MPOL_INTERLEAVE)) {
|
|
nid = interleave_nid(*mpol, vma, addr,
|
|
huge_page_shift(hstate_vma(vma)));
|
|
} else {
|
|
nid = policy_node(gfp_flags, *mpol, numa_node_id());
|
|
if (mode == MPOL_BIND || mode == MPOL_PREFERRED_MANY)
|
|
*nodemask = &(*mpol)->nodes;
|
|
}
|
|
return nid;
|
|
}
|
|
|
|
/*
|
|
* init_nodemask_of_mempolicy
|
|
*
|
|
* If the current task's mempolicy is "default" [NULL], return 'false'
|
|
* to indicate default policy. Otherwise, extract the policy nodemask
|
|
* for 'bind' or 'interleave' policy into the argument nodemask, or
|
|
* initialize the argument nodemask to contain the single node for
|
|
* 'preferred' or 'local' policy and return 'true' to indicate presence
|
|
* of non-default mempolicy.
|
|
*
|
|
* We don't bother with reference counting the mempolicy [mpol_get/put]
|
|
* because the current task is examining it's own mempolicy and a task's
|
|
* mempolicy is only ever changed by the task itself.
|
|
*
|
|
* N.B., it is the caller's responsibility to free a returned nodemask.
|
|
*/
|
|
bool init_nodemask_of_mempolicy(nodemask_t *mask)
|
|
{
|
|
struct mempolicy *mempolicy;
|
|
|
|
if (!(mask && current->mempolicy))
|
|
return false;
|
|
|
|
task_lock(current);
|
|
mempolicy = current->mempolicy;
|
|
switch (mempolicy->mode) {
|
|
case MPOL_PREFERRED:
|
|
case MPOL_PREFERRED_MANY:
|
|
case MPOL_BIND:
|
|
case MPOL_INTERLEAVE:
|
|
*mask = mempolicy->nodes;
|
|
break;
|
|
|
|
case MPOL_LOCAL:
|
|
init_nodemask_of_node(mask, numa_node_id());
|
|
break;
|
|
|
|
default:
|
|
BUG();
|
|
}
|
|
task_unlock(current);
|
|
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* mempolicy_in_oom_domain
|
|
*
|
|
* If tsk's mempolicy is "bind", check for intersection between mask and
|
|
* the policy nodemask. Otherwise, return true for all other policies
|
|
* including "interleave", as a tsk with "interleave" policy may have
|
|
* memory allocated from all nodes in system.
|
|
*
|
|
* Takes task_lock(tsk) to prevent freeing of its mempolicy.
|
|
*/
|
|
bool mempolicy_in_oom_domain(struct task_struct *tsk,
|
|
const nodemask_t *mask)
|
|
{
|
|
struct mempolicy *mempolicy;
|
|
bool ret = true;
|
|
|
|
if (!mask)
|
|
return ret;
|
|
|
|
task_lock(tsk);
|
|
mempolicy = tsk->mempolicy;
|
|
if (mempolicy && mempolicy->mode == MPOL_BIND)
|
|
ret = nodes_intersects(mempolicy->nodes, *mask);
|
|
task_unlock(tsk);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Allocate a page in interleaved policy.
|
|
Own path because it needs to do special accounting. */
|
|
static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
|
|
unsigned nid)
|
|
{
|
|
struct page *page;
|
|
|
|
page = __alloc_pages(gfp, order, nid, NULL);
|
|
/* skip NUMA_INTERLEAVE_HIT counter update if numa stats is disabled */
|
|
if (!static_branch_likely(&vm_numa_stat_key))
|
|
return page;
|
|
if (page && page_to_nid(page) == nid) {
|
|
preempt_disable();
|
|
__count_numa_event(page_zone(page), NUMA_INTERLEAVE_HIT);
|
|
preempt_enable();
|
|
}
|
|
return page;
|
|
}
|
|
|
|
static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int order,
|
|
int nid, struct mempolicy *pol)
|
|
{
|
|
struct page *page;
|
|
gfp_t preferred_gfp;
|
|
|
|
/*
|
|
* This is a two pass approach. The first pass will only try the
|
|
* preferred nodes but skip the direct reclaim and allow the
|
|
* allocation to fail, while the second pass will try all the
|
|
* nodes in system.
|
|
*/
|
|
preferred_gfp = gfp | __GFP_NOWARN;
|
|
preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL);
|
|
page = __alloc_pages(preferred_gfp, order, nid, &pol->nodes);
|
|
if (!page)
|
|
page = __alloc_pages(gfp, order, numa_node_id(), NULL);
|
|
|
|
return page;
|
|
}
|
|
|
|
/**
|
|
* alloc_pages_vma - Allocate a page for a VMA.
|
|
* @gfp: GFP flags.
|
|
* @order: Order of the GFP allocation.
|
|
* @vma: Pointer to VMA or NULL if not available.
|
|
* @addr: Virtual address of the allocation. Must be inside @vma.
|
|
* @node: Which node to prefer for allocation (modulo policy).
|
|
* @hugepage: For hugepages try only the preferred node if possible.
|
|
*
|
|
* Allocate a page for a specific address in @vma, using the appropriate
|
|
* NUMA policy. When @vma is not NULL the caller must hold the mmap_lock
|
|
* of the mm_struct of the VMA to prevent it from going away. Should be
|
|
* used for all allocations for pages that will be mapped into user space.
|
|
*
|
|
* Return: The page on success or NULL if allocation fails.
|
|
*/
|
|
struct page *alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
|
|
unsigned long addr, int node, bool hugepage)
|
|
{
|
|
struct mempolicy *pol;
|
|
struct page *page;
|
|
int preferred_nid;
|
|
nodemask_t *nmask;
|
|
|
|
pol = get_vma_policy(vma, addr);
|
|
|
|
if (pol->mode == MPOL_INTERLEAVE) {
|
|
unsigned nid;
|
|
|
|
nid = interleave_nid(pol, vma, addr, PAGE_SHIFT + order);
|
|
mpol_cond_put(pol);
|
|
page = alloc_page_interleave(gfp, order, nid);
|
|
goto out;
|
|
}
|
|
|
|
if (pol->mode == MPOL_PREFERRED_MANY) {
|
|
page = alloc_pages_preferred_many(gfp, order, node, pol);
|
|
mpol_cond_put(pol);
|
|
goto out;
|
|
}
|
|
|
|
if (unlikely(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hugepage)) {
|
|
int hpage_node = node;
|
|
|
|
/*
|
|
* For hugepage allocation and non-interleave policy which
|
|
* allows the current node (or other explicitly preferred
|
|
* node) we only try to allocate from the current/preferred
|
|
* node and don't fall back to other nodes, as the cost of
|
|
* remote accesses would likely offset THP benefits.
|
|
*
|
|
* If the policy is interleave or does not allow the current
|
|
* node in its nodemask, we allocate the standard way.
|
|
*/
|
|
if (pol->mode == MPOL_PREFERRED)
|
|
hpage_node = first_node(pol->nodes);
|
|
|
|
nmask = policy_nodemask(gfp, pol);
|
|
if (!nmask || node_isset(hpage_node, *nmask)) {
|
|
mpol_cond_put(pol);
|
|
/*
|
|
* First, try to allocate THP only on local node, but
|
|
* don't reclaim unnecessarily, just compact.
|
|
*/
|
|
page = __alloc_pages_node(hpage_node,
|
|
gfp | __GFP_THISNODE | __GFP_NORETRY, order);
|
|
|
|
/*
|
|
* If hugepage allocations are configured to always
|
|
* synchronous compact or the vma has been madvised
|
|
* to prefer hugepage backing, retry allowing remote
|
|
* memory with both reclaim and compact as well.
|
|
*/
|
|
if (!page && (gfp & __GFP_DIRECT_RECLAIM))
|
|
page = __alloc_pages(gfp, order, hpage_node, nmask);
|
|
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
nmask = policy_nodemask(gfp, pol);
|
|
preferred_nid = policy_node(gfp, pol, node);
|
|
page = __alloc_pages(gfp, order, preferred_nid, nmask);
|
|
mpol_cond_put(pol);
|
|
out:
|
|
return page;
|
|
}
|
|
EXPORT_SYMBOL(alloc_pages_vma);
|
|
|
|
/**
|
|
* alloc_pages - Allocate pages.
|
|
* @gfp: GFP flags.
|
|
* @order: Power of two of number of pages to allocate.
|
|
*
|
|
* Allocate 1 << @order contiguous pages. The physical address of the
|
|
* first page is naturally aligned (eg an order-3 allocation will be aligned
|
|
* to a multiple of 8 * PAGE_SIZE bytes). The NUMA policy of the current
|
|
* process is honoured when in process context.
|
|
*
|
|
* Context: Can be called from any context, providing the appropriate GFP
|
|
* flags are used.
|
|
* Return: The page on success or NULL if allocation fails.
|
|
*/
|
|
struct page *alloc_pages(gfp_t gfp, unsigned order)
|
|
{
|
|
struct mempolicy *pol = &default_policy;
|
|
struct page *page;
|
|
|
|
if (!in_interrupt() && !(gfp & __GFP_THISNODE))
|
|
pol = get_task_policy(current);
|
|
|
|
/*
|
|
* No reference counting needed for current->mempolicy
|
|
* nor system default_policy
|
|
*/
|
|
if (pol->mode == MPOL_INTERLEAVE)
|
|
page = alloc_page_interleave(gfp, order, interleave_nodes(pol));
|
|
else if (pol->mode == MPOL_PREFERRED_MANY)
|
|
page = alloc_pages_preferred_many(gfp, order,
|
|
numa_node_id(), pol);
|
|
else
|
|
page = __alloc_pages(gfp, order,
|
|
policy_node(gfp, pol, numa_node_id()),
|
|
policy_nodemask(gfp, pol));
|
|
|
|
return page;
|
|
}
|
|
EXPORT_SYMBOL(alloc_pages);
|
|
|
|
int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
|
|
{
|
|
struct mempolicy *pol = mpol_dup(vma_policy(src));
|
|
|
|
if (IS_ERR(pol))
|
|
return PTR_ERR(pol);
|
|
dst->vm_policy = pol;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* If mpol_dup() sees current->cpuset == cpuset_being_rebound, then it
|
|
* rebinds the mempolicy its copying by calling mpol_rebind_policy()
|
|
* with the mems_allowed returned by cpuset_mems_allowed(). This
|
|
* keeps mempolicies cpuset relative after its cpuset moves. See
|
|
* further kernel/cpuset.c update_nodemask().
|
|
*
|
|
* current's mempolicy may be rebinded by the other task(the task that changes
|
|
* cpuset's mems), so we needn't do rebind work for current task.
|
|
*/
|
|
|
|
/* Slow path of a mempolicy duplicate */
|
|
struct mempolicy *__mpol_dup(struct mempolicy *old)
|
|
{
|
|
struct mempolicy *new = kmem_cache_alloc(policy_cache, GFP_KERNEL);
|
|
|
|
if (!new)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
/* task's mempolicy is protected by alloc_lock */
|
|
if (old == current->mempolicy) {
|
|
task_lock(current);
|
|
*new = *old;
|
|
task_unlock(current);
|
|
} else
|
|
*new = *old;
|
|
|
|
if (current_cpuset_is_being_rebound()) {
|
|
nodemask_t mems = cpuset_mems_allowed(current);
|
|
mpol_rebind_policy(new, &mems);
|
|
}
|
|
atomic_set(&new->refcnt, 1);
|
|
return new;
|
|
}
|
|
|
|
/* Slow path of a mempolicy comparison */
|
|
bool __mpol_equal(struct mempolicy *a, struct mempolicy *b)
|
|
{
|
|
if (!a || !b)
|
|
return false;
|
|
if (a->mode != b->mode)
|
|
return false;
|
|
if (a->flags != b->flags)
|
|
return false;
|
|
if (mpol_store_user_nodemask(a))
|
|
if (!nodes_equal(a->w.user_nodemask, b->w.user_nodemask))
|
|
return false;
|
|
|
|
switch (a->mode) {
|
|
case MPOL_BIND:
|
|
case MPOL_INTERLEAVE:
|
|
case MPOL_PREFERRED:
|
|
case MPOL_PREFERRED_MANY:
|
|
return !!nodes_equal(a->nodes, b->nodes);
|
|
case MPOL_LOCAL:
|
|
return true;
|
|
default:
|
|
BUG();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Shared memory backing store policy support.
|
|
*
|
|
* Remember policies even when nobody has shared memory mapped.
|
|
* The policies are kept in Red-Black tree linked from the inode.
|
|
* They are protected by the sp->lock rwlock, which should be held
|
|
* for any accesses to the tree.
|
|
*/
|
|
|
|
/*
|
|
* lookup first element intersecting start-end. Caller holds sp->lock for
|
|
* reading or for writing
|
|
*/
|
|
static struct sp_node *
|
|
sp_lookup(struct shared_policy *sp, unsigned long start, unsigned long end)
|
|
{
|
|
struct rb_node *n = sp->root.rb_node;
|
|
|
|
while (n) {
|
|
struct sp_node *p = rb_entry(n, struct sp_node, nd);
|
|
|
|
if (start >= p->end)
|
|
n = n->rb_right;
|
|
else if (end <= p->start)
|
|
n = n->rb_left;
|
|
else
|
|
break;
|
|
}
|
|
if (!n)
|
|
return NULL;
|
|
for (;;) {
|
|
struct sp_node *w = NULL;
|
|
struct rb_node *prev = rb_prev(n);
|
|
if (!prev)
|
|
break;
|
|
w = rb_entry(prev, struct sp_node, nd);
|
|
if (w->end <= start)
|
|
break;
|
|
n = prev;
|
|
}
|
|
return rb_entry(n, struct sp_node, nd);
|
|
}
|
|
|
|
/*
|
|
* Insert a new shared policy into the list. Caller holds sp->lock for
|
|
* writing.
|
|
*/
|
|
static void sp_insert(struct shared_policy *sp, struct sp_node *new)
|
|
{
|
|
struct rb_node **p = &sp->root.rb_node;
|
|
struct rb_node *parent = NULL;
|
|
struct sp_node *nd;
|
|
|
|
while (*p) {
|
|
parent = *p;
|
|
nd = rb_entry(parent, struct sp_node, nd);
|
|
if (new->start < nd->start)
|
|
p = &(*p)->rb_left;
|
|
else if (new->end > nd->end)
|
|
p = &(*p)->rb_right;
|
|
else
|
|
BUG();
|
|
}
|
|
rb_link_node(&new->nd, parent, p);
|
|
rb_insert_color(&new->nd, &sp->root);
|
|
pr_debug("inserting %lx-%lx: %d\n", new->start, new->end,
|
|
new->policy ? new->policy->mode : 0);
|
|
}
|
|
|
|
/* Find shared policy intersecting idx */
|
|
struct mempolicy *
|
|
mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
|
|
{
|
|
struct mempolicy *pol = NULL;
|
|
struct sp_node *sn;
|
|
|
|
if (!sp->root.rb_node)
|
|
return NULL;
|
|
read_lock(&sp->lock);
|
|
sn = sp_lookup(sp, idx, idx+1);
|
|
if (sn) {
|
|
mpol_get(sn->policy);
|
|
pol = sn->policy;
|
|
}
|
|
read_unlock(&sp->lock);
|
|
return pol;
|
|
}
|
|
|
|
static void sp_free(struct sp_node *n)
|
|
{
|
|
mpol_put(n->policy);
|
|
kmem_cache_free(sn_cache, n);
|
|
}
|
|
|
|
/**
|
|
* mpol_misplaced - check whether current page node is valid in policy
|
|
*
|
|
* @page: page to be checked
|
|
* @vma: vm area where page mapped
|
|
* @addr: virtual address where page mapped
|
|
*
|
|
* Lookup current policy node id for vma,addr and "compare to" page's
|
|
* node id. Policy determination "mimics" alloc_page_vma().
|
|
* Called from fault path where we know the vma and faulting address.
|
|
*
|
|
* Return: NUMA_NO_NODE if the page is in a node that is valid for this
|
|
* policy, or a suitable node ID to allocate a replacement page from.
|
|
*/
|
|
int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long addr)
|
|
{
|
|
struct mempolicy *pol;
|
|
struct zoneref *z;
|
|
int curnid = page_to_nid(page);
|
|
unsigned long pgoff;
|
|
int thiscpu = raw_smp_processor_id();
|
|
int thisnid = cpu_to_node(thiscpu);
|
|
int polnid = NUMA_NO_NODE;
|
|
int ret = NUMA_NO_NODE;
|
|
|
|
pol = get_vma_policy(vma, addr);
|
|
if (!(pol->flags & MPOL_F_MOF))
|
|
goto out;
|
|
|
|
switch (pol->mode) {
|
|
case MPOL_INTERLEAVE:
|
|
pgoff = vma->vm_pgoff;
|
|
pgoff += (addr - vma->vm_start) >> PAGE_SHIFT;
|
|
polnid = offset_il_node(pol, pgoff);
|
|
break;
|
|
|
|
case MPOL_PREFERRED:
|
|
if (node_isset(curnid, pol->nodes))
|
|
goto out;
|
|
polnid = first_node(pol->nodes);
|
|
break;
|
|
|
|
case MPOL_LOCAL:
|
|
polnid = numa_node_id();
|
|
break;
|
|
|
|
case MPOL_BIND:
|
|
/* Optimize placement among multiple nodes via NUMA balancing */
|
|
if (pol->flags & MPOL_F_MORON) {
|
|
if (node_isset(thisnid, pol->nodes))
|
|
break;
|
|
goto out;
|
|
}
|
|
fallthrough;
|
|
|
|
case MPOL_PREFERRED_MANY:
|
|
/*
|
|
* use current page if in policy nodemask,
|
|
* else select nearest allowed node, if any.
|
|
* If no allowed nodes, use current [!misplaced].
|
|
*/
|
|
if (node_isset(curnid, pol->nodes))
|
|
goto out;
|
|
z = first_zones_zonelist(
|
|
node_zonelist(numa_node_id(), GFP_HIGHUSER),
|
|
gfp_zone(GFP_HIGHUSER),
|
|
&pol->nodes);
|
|
polnid = zone_to_nid(z->zone);
|
|
break;
|
|
|
|
default:
|
|
BUG();
|
|
}
|
|
|
|
/* Migrate the page towards the node whose CPU is referencing it */
|
|
if (pol->flags & MPOL_F_MORON) {
|
|
polnid = thisnid;
|
|
|
|
if (!should_numa_migrate_memory(current, page, curnid, thiscpu))
|
|
goto out;
|
|
}
|
|
|
|
if (curnid != polnid)
|
|
ret = polnid;
|
|
out:
|
|
mpol_cond_put(pol);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Drop the (possibly final) reference to task->mempolicy. It needs to be
|
|
* dropped after task->mempolicy is set to NULL so that any allocation done as
|
|
* part of its kmem_cache_free(), such as by KASAN, doesn't reference a freed
|
|
* policy.
|
|
*/
|
|
void mpol_put_task_policy(struct task_struct *task)
|
|
{
|
|
struct mempolicy *pol;
|
|
|
|
task_lock(task);
|
|
pol = task->mempolicy;
|
|
task->mempolicy = NULL;
|
|
task_unlock(task);
|
|
mpol_put(pol);
|
|
}
|
|
|
|
static void sp_delete(struct shared_policy *sp, struct sp_node *n)
|
|
{
|
|
pr_debug("deleting %lx-l%lx\n", n->start, n->end);
|
|
rb_erase(&n->nd, &sp->root);
|
|
sp_free(n);
|
|
}
|
|
|
|
static void sp_node_init(struct sp_node *node, unsigned long start,
|
|
unsigned long end, struct mempolicy *pol)
|
|
{
|
|
node->start = start;
|
|
node->end = end;
|
|
node->policy = pol;
|
|
}
|
|
|
|
static struct sp_node *sp_alloc(unsigned long start, unsigned long end,
|
|
struct mempolicy *pol)
|
|
{
|
|
struct sp_node *n;
|
|
struct mempolicy *newpol;
|
|
|
|
n = kmem_cache_alloc(sn_cache, GFP_KERNEL);
|
|
if (!n)
|
|
return NULL;
|
|
|
|
newpol = mpol_dup(pol);
|
|
if (IS_ERR(newpol)) {
|
|
kmem_cache_free(sn_cache, n);
|
|
return NULL;
|
|
}
|
|
newpol->flags |= MPOL_F_SHARED;
|
|
sp_node_init(n, start, end, newpol);
|
|
|
|
return n;
|
|
}
|
|
|
|
/* Replace a policy range. */
|
|
static int shared_policy_replace(struct shared_policy *sp, unsigned long start,
|
|
unsigned long end, struct sp_node *new)
|
|
{
|
|
struct sp_node *n;
|
|
struct sp_node *n_new = NULL;
|
|
struct mempolicy *mpol_new = NULL;
|
|
int ret = 0;
|
|
|
|
restart:
|
|
write_lock(&sp->lock);
|
|
n = sp_lookup(sp, start, end);
|
|
/* Take care of old policies in the same range. */
|
|
while (n && n->start < end) {
|
|
struct rb_node *next = rb_next(&n->nd);
|
|
if (n->start >= start) {
|
|
if (n->end <= end)
|
|
sp_delete(sp, n);
|
|
else
|
|
n->start = end;
|
|
} else {
|
|
/* Old policy spanning whole new range. */
|
|
if (n->end > end) {
|
|
if (!n_new)
|
|
goto alloc_new;
|
|
|
|
*mpol_new = *n->policy;
|
|
atomic_set(&mpol_new->refcnt, 1);
|
|
sp_node_init(n_new, end, n->end, mpol_new);
|
|
n->end = start;
|
|
sp_insert(sp, n_new);
|
|
n_new = NULL;
|
|
mpol_new = NULL;
|
|
break;
|
|
} else
|
|
n->end = start;
|
|
}
|
|
if (!next)
|
|
break;
|
|
n = rb_entry(next, struct sp_node, nd);
|
|
}
|
|
if (new)
|
|
sp_insert(sp, new);
|
|
write_unlock(&sp->lock);
|
|
ret = 0;
|
|
|
|
err_out:
|
|
if (mpol_new)
|
|
mpol_put(mpol_new);
|
|
if (n_new)
|
|
kmem_cache_free(sn_cache, n_new);
|
|
|
|
return ret;
|
|
|
|
alloc_new:
|
|
write_unlock(&sp->lock);
|
|
ret = -ENOMEM;
|
|
n_new = kmem_cache_alloc(sn_cache, GFP_KERNEL);
|
|
if (!n_new)
|
|
goto err_out;
|
|
mpol_new = kmem_cache_alloc(policy_cache, GFP_KERNEL);
|
|
if (!mpol_new)
|
|
goto err_out;
|
|
goto restart;
|
|
}
|
|
|
|
/**
|
|
* mpol_shared_policy_init - initialize shared policy for inode
|
|
* @sp: pointer to inode shared policy
|
|
* @mpol: struct mempolicy to install
|
|
*
|
|
* Install non-NULL @mpol in inode's shared policy rb-tree.
|
|
* On entry, the current task has a reference on a non-NULL @mpol.
|
|
* This must be released on exit.
|
|
* This is called at get_inode() calls and we can use GFP_KERNEL.
|
|
*/
|
|
void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol)
|
|
{
|
|
int ret;
|
|
|
|
sp->root = RB_ROOT; /* empty tree == default mempolicy */
|
|
rwlock_init(&sp->lock);
|
|
|
|
if (mpol) {
|
|
struct vm_area_struct pvma;
|
|
struct mempolicy *new;
|
|
NODEMASK_SCRATCH(scratch);
|
|
|
|
if (!scratch)
|
|
goto put_mpol;
|
|
/* contextualize the tmpfs mount point mempolicy */
|
|
new = mpol_new(mpol->mode, mpol->flags, &mpol->w.user_nodemask);
|
|
if (IS_ERR(new))
|
|
goto free_scratch; /* no valid nodemask intersection */
|
|
|
|
task_lock(current);
|
|
ret = mpol_set_nodemask(new, &mpol->w.user_nodemask, scratch);
|
|
task_unlock(current);
|
|
if (ret)
|
|
goto put_new;
|
|
|
|
/* Create pseudo-vma that contains just the policy */
|
|
vma_init(&pvma, NULL);
|
|
pvma.vm_end = TASK_SIZE; /* policy covers entire file */
|
|
mpol_set_shared_policy(sp, &pvma, new); /* adds ref */
|
|
|
|
put_new:
|
|
mpol_put(new); /* drop initial ref */
|
|
free_scratch:
|
|
NODEMASK_SCRATCH_FREE(scratch);
|
|
put_mpol:
|
|
mpol_put(mpol); /* drop our incoming ref on sb mpol */
|
|
}
|
|
}
|
|
|
|
int mpol_set_shared_policy(struct shared_policy *info,
|
|
struct vm_area_struct *vma, struct mempolicy *npol)
|
|
{
|
|
int err;
|
|
struct sp_node *new = NULL;
|
|
unsigned long sz = vma_pages(vma);
|
|
|
|
pr_debug("set_shared_policy %lx sz %lu %d %d %lx\n",
|
|
vma->vm_pgoff,
|
|
sz, npol ? npol->mode : -1,
|
|
npol ? npol->flags : -1,
|
|
npol ? nodes_addr(npol->nodes)[0] : NUMA_NO_NODE);
|
|
|
|
if (npol) {
|
|
new = sp_alloc(vma->vm_pgoff, vma->vm_pgoff + sz, npol);
|
|
if (!new)
|
|
return -ENOMEM;
|
|
}
|
|
err = shared_policy_replace(info, vma->vm_pgoff, vma->vm_pgoff+sz, new);
|
|
if (err && new)
|
|
sp_free(new);
|
|
return err;
|
|
}
|
|
|
|
/* Free a backing policy store on inode delete. */
|
|
void mpol_free_shared_policy(struct shared_policy *p)
|
|
{
|
|
struct sp_node *n;
|
|
struct rb_node *next;
|
|
|
|
if (!p->root.rb_node)
|
|
return;
|
|
write_lock(&p->lock);
|
|
next = rb_first(&p->root);
|
|
while (next) {
|
|
n = rb_entry(next, struct sp_node, nd);
|
|
next = rb_next(&n->nd);
|
|
sp_delete(p, n);
|
|
}
|
|
write_unlock(&p->lock);
|
|
}
|
|
|
|
#ifdef CONFIG_NUMA_BALANCING
|
|
static int __initdata numabalancing_override;
|
|
|
|
static void __init check_numabalancing_enable(void)
|
|
{
|
|
bool numabalancing_default = false;
|
|
|
|
if (IS_ENABLED(CONFIG_NUMA_BALANCING_DEFAULT_ENABLED))
|
|
numabalancing_default = true;
|
|
|
|
/* Parsed by setup_numabalancing. override == 1 enables, -1 disables */
|
|
if (numabalancing_override)
|
|
set_numabalancing_state(numabalancing_override == 1);
|
|
|
|
if (num_online_nodes() > 1 && !numabalancing_override) {
|
|
pr_info("%s automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl\n",
|
|
numabalancing_default ? "Enabling" : "Disabling");
|
|
set_numabalancing_state(numabalancing_default);
|
|
}
|
|
}
|
|
|
|
static int __init setup_numabalancing(char *str)
|
|
{
|
|
int ret = 0;
|
|
if (!str)
|
|
goto out;
|
|
|
|
if (!strcmp(str, "enable")) {
|
|
numabalancing_override = 1;
|
|
ret = 1;
|
|
} else if (!strcmp(str, "disable")) {
|
|
numabalancing_override = -1;
|
|
ret = 1;
|
|
}
|
|
out:
|
|
if (!ret)
|
|
pr_warn("Unable to parse numa_balancing=\n");
|
|
|
|
return ret;
|
|
}
|
|
__setup("numa_balancing=", setup_numabalancing);
|
|
#else
|
|
static inline void __init check_numabalancing_enable(void)
|
|
{
|
|
}
|
|
#endif /* CONFIG_NUMA_BALANCING */
|
|
|
|
/* assumes fs == KERNEL_DS */
|
|
void __init numa_policy_init(void)
|
|
{
|
|
nodemask_t interleave_nodes;
|
|
unsigned long largest = 0;
|
|
int nid, prefer = 0;
|
|
|
|
policy_cache = kmem_cache_create("numa_policy",
|
|
sizeof(struct mempolicy),
|
|
0, SLAB_PANIC, NULL);
|
|
|
|
sn_cache = kmem_cache_create("shared_policy_node",
|
|
sizeof(struct sp_node),
|
|
0, SLAB_PANIC, NULL);
|
|
|
|
for_each_node(nid) {
|
|
preferred_node_policy[nid] = (struct mempolicy) {
|
|
.refcnt = ATOMIC_INIT(1),
|
|
.mode = MPOL_PREFERRED,
|
|
.flags = MPOL_F_MOF | MPOL_F_MORON,
|
|
.nodes = nodemask_of_node(nid),
|
|
};
|
|
}
|
|
|
|
/*
|
|
* Set interleaving policy for system init. Interleaving is only
|
|
* enabled across suitably sized nodes (default is >= 16MB), or
|
|
* fall back to the largest node if they're all smaller.
|
|
*/
|
|
nodes_clear(interleave_nodes);
|
|
for_each_node_state(nid, N_MEMORY) {
|
|
unsigned long total_pages = node_present_pages(nid);
|
|
|
|
/* Preserve the largest node */
|
|
if (largest < total_pages) {
|
|
largest = total_pages;
|
|
prefer = nid;
|
|
}
|
|
|
|
/* Interleave this node? */
|
|
if ((total_pages << PAGE_SHIFT) >= (16 << 20))
|
|
node_set(nid, interleave_nodes);
|
|
}
|
|
|
|
/* All too small, use the largest */
|
|
if (unlikely(nodes_empty(interleave_nodes)))
|
|
node_set(prefer, interleave_nodes);
|
|
|
|
if (do_set_mempolicy(MPOL_INTERLEAVE, 0, &interleave_nodes))
|
|
pr_err("%s: interleaving failed\n", __func__);
|
|
|
|
check_numabalancing_enable();
|
|
}
|
|
|
|
/* Reset policy of current process to default */
|
|
void numa_default_policy(void)
|
|
{
|
|
do_set_mempolicy(MPOL_DEFAULT, 0, NULL);
|
|
}
|
|
|
|
/*
|
|
* Parse and format mempolicy from/to strings
|
|
*/
|
|
|
|
static const char * const policy_modes[] =
|
|
{
|
|
[MPOL_DEFAULT] = "default",
|
|
[MPOL_PREFERRED] = "prefer",
|
|
[MPOL_BIND] = "bind",
|
|
[MPOL_INTERLEAVE] = "interleave",
|
|
[MPOL_LOCAL] = "local",
|
|
[MPOL_PREFERRED_MANY] = "prefer (many)",
|
|
};
|
|
|
|
|
|
#ifdef CONFIG_TMPFS
|
|
/**
|
|
* mpol_parse_str - parse string to mempolicy, for tmpfs mpol mount option.
|
|
* @str: string containing mempolicy to parse
|
|
* @mpol: pointer to struct mempolicy pointer, returned on success.
|
|
*
|
|
* Format of input:
|
|
* <mode>[=<flags>][:<nodelist>]
|
|
*
|
|
* On success, returns 0, else 1
|
|
*/
|
|
int mpol_parse_str(char *str, struct mempolicy **mpol)
|
|
{
|
|
struct mempolicy *new = NULL;
|
|
unsigned short mode_flags;
|
|
nodemask_t nodes;
|
|
char *nodelist = strchr(str, ':');
|
|
char *flags = strchr(str, '=');
|
|
int err = 1, mode;
|
|
|
|
if (flags)
|
|
*flags++ = '\0'; /* terminate mode string */
|
|
|
|
if (nodelist) {
|
|
/* NUL-terminate mode or flags string */
|
|
*nodelist++ = '\0';
|
|
if (nodelist_parse(nodelist, nodes))
|
|
goto out;
|
|
if (!nodes_subset(nodes, node_states[N_MEMORY]))
|
|
goto out;
|
|
} else
|
|
nodes_clear(nodes);
|
|
|
|
mode = match_string(policy_modes, MPOL_MAX, str);
|
|
if (mode < 0)
|
|
goto out;
|
|
|
|
switch (mode) {
|
|
case MPOL_PREFERRED:
|
|
/*
|
|
* Insist on a nodelist of one node only, although later
|
|
* we use first_node(nodes) to grab a single node, so here
|
|
* nodelist (or nodes) cannot be empty.
|
|
*/
|
|
if (nodelist) {
|
|
char *rest = nodelist;
|
|
while (isdigit(*rest))
|
|
rest++;
|
|
if (*rest)
|
|
goto out;
|
|
if (nodes_empty(nodes))
|
|
goto out;
|
|
}
|
|
break;
|
|
case MPOL_INTERLEAVE:
|
|
/*
|
|
* Default to online nodes with memory if no nodelist
|
|
*/
|
|
if (!nodelist)
|
|
nodes = node_states[N_MEMORY];
|
|
break;
|
|
case MPOL_LOCAL:
|
|
/*
|
|
* Don't allow a nodelist; mpol_new() checks flags
|
|
*/
|
|
if (nodelist)
|
|
goto out;
|
|
break;
|
|
case MPOL_DEFAULT:
|
|
/*
|
|
* Insist on a empty nodelist
|
|
*/
|
|
if (!nodelist)
|
|
err = 0;
|
|
goto out;
|
|
case MPOL_PREFERRED_MANY:
|
|
case MPOL_BIND:
|
|
/*
|
|
* Insist on a nodelist
|
|
*/
|
|
if (!nodelist)
|
|
goto out;
|
|
}
|
|
|
|
mode_flags = 0;
|
|
if (flags) {
|
|
/*
|
|
* Currently, we only support two mutually exclusive
|
|
* mode flags.
|
|
*/
|
|
if (!strcmp(flags, "static"))
|
|
mode_flags |= MPOL_F_STATIC_NODES;
|
|
else if (!strcmp(flags, "relative"))
|
|
mode_flags |= MPOL_F_RELATIVE_NODES;
|
|
else
|
|
goto out;
|
|
}
|
|
|
|
new = mpol_new(mode, mode_flags, &nodes);
|
|
if (IS_ERR(new))
|
|
goto out;
|
|
|
|
/*
|
|
* Save nodes for mpol_to_str() to show the tmpfs mount options
|
|
* for /proc/mounts, /proc/pid/mounts and /proc/pid/mountinfo.
|
|
*/
|
|
if (mode != MPOL_PREFERRED) {
|
|
new->nodes = nodes;
|
|
} else if (nodelist) {
|
|
nodes_clear(new->nodes);
|
|
node_set(first_node(nodes), new->nodes);
|
|
} else {
|
|
new->mode = MPOL_LOCAL;
|
|
}
|
|
|
|
/*
|
|
* Save nodes for contextualization: this will be used to "clone"
|
|
* the mempolicy in a specific context [cpuset] at a later time.
|
|
*/
|
|
new->w.user_nodemask = nodes;
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
/* Restore string for error message */
|
|
if (nodelist)
|
|
*--nodelist = ':';
|
|
if (flags)
|
|
*--flags = '=';
|
|
if (!err)
|
|
*mpol = new;
|
|
return err;
|
|
}
|
|
#endif /* CONFIG_TMPFS */
|
|
|
|
/**
|
|
* mpol_to_str - format a mempolicy structure for printing
|
|
* @buffer: to contain formatted mempolicy string
|
|
* @maxlen: length of @buffer
|
|
* @pol: pointer to mempolicy to be formatted
|
|
*
|
|
* Convert @pol into a string. If @buffer is too short, truncate the string.
|
|
* Recommend a @maxlen of at least 32 for the longest mode, "interleave", the
|
|
* longest flag, "relative", and to display at least a few node ids.
|
|
*/
|
|
void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol)
|
|
{
|
|
char *p = buffer;
|
|
nodemask_t nodes = NODE_MASK_NONE;
|
|
unsigned short mode = MPOL_DEFAULT;
|
|
unsigned short flags = 0;
|
|
|
|
if (pol && pol != &default_policy && !(pol->flags & MPOL_F_MORON)) {
|
|
mode = pol->mode;
|
|
flags = pol->flags;
|
|
}
|
|
|
|
switch (mode) {
|
|
case MPOL_DEFAULT:
|
|
case MPOL_LOCAL:
|
|
break;
|
|
case MPOL_PREFERRED:
|
|
case MPOL_PREFERRED_MANY:
|
|
case MPOL_BIND:
|
|
case MPOL_INTERLEAVE:
|
|
nodes = pol->nodes;
|
|
break;
|
|
default:
|
|
WARN_ON_ONCE(1);
|
|
snprintf(p, maxlen, "unknown");
|
|
return;
|
|
}
|
|
|
|
p += snprintf(p, maxlen, "%s", policy_modes[mode]);
|
|
|
|
if (flags & MPOL_MODE_FLAGS) {
|
|
p += snprintf(p, buffer + maxlen - p, "=");
|
|
|
|
/*
|
|
* Currently, the only defined flags are mutually exclusive
|
|
*/
|
|
if (flags & MPOL_F_STATIC_NODES)
|
|
p += snprintf(p, buffer + maxlen - p, "static");
|
|
else if (flags & MPOL_F_RELATIVE_NODES)
|
|
p += snprintf(p, buffer + maxlen - p, "relative");
|
|
}
|
|
|
|
if (!nodes_empty(nodes))
|
|
p += scnprintf(p, buffer + maxlen - p, ":%*pbl",
|
|
nodemask_pr_args(&nodes));
|
|
}
|
|
|
|
bool numa_demotion_enabled = false;
|
|
|
|
#ifdef CONFIG_SYSFS
|
|
static ssize_t numa_demotion_enabled_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *buf)
|
|
{
|
|
return sysfs_emit(buf, "%s\n",
|
|
numa_demotion_enabled? "true" : "false");
|
|
}
|
|
|
|
static ssize_t numa_demotion_enabled_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
if (!strncmp(buf, "true", 4) || !strncmp(buf, "1", 1))
|
|
numa_demotion_enabled = true;
|
|
else if (!strncmp(buf, "false", 5) || !strncmp(buf, "0", 1))
|
|
numa_demotion_enabled = false;
|
|
else
|
|
return -EINVAL;
|
|
|
|
return count;
|
|
}
|
|
|
|
static struct kobj_attribute numa_demotion_enabled_attr =
|
|
__ATTR(demotion_enabled, 0644, numa_demotion_enabled_show,
|
|
numa_demotion_enabled_store);
|
|
|
|
static struct attribute *numa_attrs[] = {
|
|
&numa_demotion_enabled_attr.attr,
|
|
NULL,
|
|
};
|
|
|
|
static const struct attribute_group numa_attr_group = {
|
|
.attrs = numa_attrs,
|
|
};
|
|
|
|
static int __init numa_init_sysfs(void)
|
|
{
|
|
int err;
|
|
struct kobject *numa_kobj;
|
|
|
|
numa_kobj = kobject_create_and_add("numa", mm_kobj);
|
|
if (!numa_kobj) {
|
|
pr_err("failed to create numa kobject\n");
|
|
return -ENOMEM;
|
|
}
|
|
err = sysfs_create_group(numa_kobj, &numa_attr_group);
|
|
if (err) {
|
|
pr_err("failed to register numa group\n");
|
|
goto delete_obj;
|
|
}
|
|
return 0;
|
|
|
|
delete_obj:
|
|
kobject_put(numa_kobj);
|
|
return err;
|
|
}
|
|
subsys_initcall(numa_init_sysfs);
|
|
#endif
|