-----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmWy7o0ACgkQONu9yGCS
aT76JA/9Gh3VNSLG35LaLyq3xGd827N6DPsMzeFHi+MGSyPVg0auE77QkHD/gZl9
KynmBmz2+9DSoFxymWAS9oEPM8d/vw87AMuSTTct3GKkjEeUcj9lbeOEzgZydXX8
cJSXvcCeKE3FESU/YbQKxo0N+r7tUDmnCR0edss5/FpYni3jPdg7jdESzGhiCHXj
r5rjrTE6h7Z/d+2kaKqlheL4o4OkV0YwnFnU2gC3MOOvLmgvXdOVQQsyaZ+WgSAN
0JS0Q6Xk1xyYWx8iFaLGWIs1pUsQPKxIiRG3N/1KmXITopf2Pu68Yy7ST+YryDkO
nLcNrr3gsQxrM6MYnEhLzlxs3H1KuAVxJ4Y/dNqJnDxn0OJjcY3repwempz5Sxtk
0OLDOsCICAiMHeF8rYIGhm09WdowLz0EH+sqadIGqWKzW/BcXqD+r9mpF1lwk1ZL
FJLgLmtOaG4amI46lEUHQ6ujN7Oad3gLYzudq2zKLeqonSIjm1TuDoMRvHWFsspO
5i9I0x7Vlo3PqCl7kkKVL9PvVHx6BXJGFShABJqa9ao/oHxkOWuIt26pxUoLUN3P
7Wa5WnfdlDd9nR3VGHcVe2ncuRmEfuriYpXvItJ7/KJKyIPkGoPehAh+vbZMoEy0
DwhtD9PPsTlnUufbcZdHavYA1E4y/uXDMOIGB+ERpsTdXh9DwEo=
=2XHn
-----END PGP SIGNATURE-----
Merge 6.1.75 into android14-6.1-lts
Changes in 6.1.75
x86/lib: Fix overflow when counting digits
x86/mce/inject: Clear test status value
EDAC/thunderx: Fix possible out-of-bounds string access
powerpc: remove checks for binutils older than 2.25
powerpc: add crtsavres.o to always-y instead of extra-y
powerpc/44x: select I2C for CURRITUCK
powerpc/pseries/memhp: Fix access beyond end of drmem array
selftests/powerpc: Fix error handling in FPU/VMX preemption tests
powerpc/powernv: Add a null pointer check to scom_debug_init_one()
powerpc/powernv: Add a null pointer check in opal_event_init()
powerpc/powernv: Add a null pointer check in opal_powercap_init()
powerpc/imc-pmu: Add a null pointer check in update_events_in_group()
spi: spi-zynqmp-gqspi: fix driver kconfig dependencies
mtd: rawnand: Increment IFC_TIMEOUT_MSECS for nand controller response
ACPI: video: check for error while searching for backlight device parent
ACPI: LPIT: Avoid u32 multiplication overflow
KEYS: encrypted: Add check for strsep
platform/x86/intel/vsec: Enhance and Export intel_vsec_add_aux()
platform/x86/intel/vsec: Support private data
platform/x86/intel/vsec: Use mutex for ida_alloc() and ida_free()
platform/x86/intel/vsec: Fix xa_alloc memory leak
of: Add of_property_present() helper
cpufreq: Use of_property_present() for testing DT property presence
cpufreq: scmi: process the result of devm_of_clk_add_hw_provider()
calipso: fix memory leak in netlbl_calipso_add_pass()
efivarfs: force RO when remounting if SetVariable is not supported
efivarfs: Free s_fs_info on unmount
spi: sh-msiof: Enforce fixed DTDL for R-Car H3
ACPI: LPSS: Fix the fractional clock divider flags
ACPI: extlog: Clear Extended Error Log status when RAS_CEC handled the error
kunit: debugfs: Fix unchecked dereference in debugfs_print_results()
mtd: Fix gluebi NULL pointer dereference caused by ftl notifier
selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket
crypto: virtio - Handle dataq logic with tasklet
crypto: sa2ul - Return crypto_aead_setkey to transfer the error
crypto: ccp - fix memleak in ccp_init_dm_workarea
crypto: af_alg - Disallow multiple in-flight AIO requests
crypto: safexcel - Add error handling for dma_map_sg() calls
crypto: sahara - remove FLAGS_NEW_KEY logic
crypto: sahara - fix cbc selftest failure
crypto: sahara - fix ahash selftest failure
crypto: sahara - fix processing requests with cryptlen < sg->length
crypto: sahara - fix error handling in sahara_hw_descriptor_create()
crypto: hisilicon/qm - save capability registers in qm init process
crypto: hisilicon/zip - add zip comp high perf mode configuration
crypto: hisilicon/qm - add a function to set qm algs
crypto: hisilicon/hpre - save capability registers in probe process
crypto: hisilicon/sec2 - save capability registers in probe process
crypto: hisilicon/zip - save capability registers in probe process
pstore: ram_core: fix possible overflow in persistent_ram_init_ecc()
erofs: fix memory leak on short-lived bounced pages
fs: indicate request originates from old mount API
gfs2: Fix kernel NULL pointer dereference in gfs2_rgrp_dump
crypto: virtio - Wait for tasklet to complete on device remove
crypto: sahara - avoid skcipher fallback code duplication
crypto: sahara - handle zero-length aes requests
crypto: sahara - fix ahash reqsize
crypto: sahara - fix wait_for_completion_timeout() error handling
crypto: sahara - improve error handling in sahara_sha_process()
crypto: sahara - fix processing hash requests with req->nbytes < sg->length
crypto: sahara - do not resize req->src when doing hash operations
crypto: scomp - fix req->dst buffer overflow
csky: fix arch_jump_label_transform_static override
blocklayoutdriver: Fix reference leak of pnfs_device_node
NFSv4.1/pnfs: Ensure we handle the error NFS4ERR_RETURNCONFLICT
SUNRPC: fix _xprt_switch_find_current_entry logic
pNFS: Fix the pnfs block driver's calculation of layoutget size
wifi: plfxlc: check for allocation failure in plfxlc_usb_wreq_async()
wifi: rtw88: fix RX filter in FIF_ALLMULTI flag
bpf, lpm: Fix check prefixlen before walking trie
bpf: Add crosstask check to __bpf_get_stack
wifi: ath11k: Defer on rproc_get failure
wifi: libertas: stop selecting wext
ARM: dts: qcom: apq8064: correct XOADC register address
net/ncsi: Fix netlink major/minor version numbers
firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create()
firmware: meson_sm: populate platform devices from sm device tree data
wifi: rtlwifi: rtl8821ae: phy: fix an undefined bitwise shift behavior
arm64: dts: ti: k3-am62a-main: Fix GPIO pin count in DT nodes
arm64: dts: ti: k3-am65-main: Fix DSS irq trigger type
selftests/bpf: Fix erroneous bitmask operation
md: synchronize flush io with array reconfiguration
bpf: enforce precision of R0 on callback return
ARM: dts: qcom: sdx65: correct SPMI node name
arm64: dts: qcom: sc7180: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sc7280: Mark some nodes as 'reserved'
arm64: dts: qcom: sc7280: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sdm845: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sm8150: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sm8250: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sc8280xp: Make watchdog bark interrupt edge triggered
arm64: dts: qcom: sm6350: Make watchdog bark interrupt edge triggered
rcu-tasks: Provide rcu_trace_implies_rcu_gp()
bpf: add percpu stats for bpf_map elements insertions/deletions
bpf: Add map and need_defer parameters to .map_fd_put_ptr()
bpf: Defer the free of inner map when necessary
selftests/net: specify the interface when do arping
bpf: fix check for attempt to corrupt spilled pointer
scsi: fnic: Return error if vmalloc() failed
arm64: dts: qcom: qrb5165-rb5: correct LED panic indicator
arm64: dts: qcom: sdm845-db845c: correct LED panic indicator
arm64: dts: qcom: sm8350: Fix DMA0 address
arm64: dts: qcom: sc7280: Fix up GPU SIDs
arm64: dts: qcom: sc7280: Mark Adreno SMMU as DMA coherent
arm64: dts: qcom: sc7280: fix usb_2 wakeup interrupt types
wifi: mt76: mt7921s: fix workqueue problem causes STA association fail
bpf: Fix verification of indirect var-off stack access
arm64: dts: hisilicon: hikey970-pmic: fix regulator cells properties
dt-bindings: media: mediatek: mdp3: correct RDMA and WROT node with generic names
arm64: dts: mediatek: mt8183: correct MDP3 DMA-related nodes
wifi: mt76: mt7921: fix country count limitation for CLC
selftests/bpf: Relax time_tai test for equal timestamps in tai_forward
block: Set memalloc_noio to false on device_add_disk() error path
arm64: dts: renesas: white-hawk-cpu: Fix missing serial console pin control
arm64: dts: imx8mm: Reduce GPU to nominal speed
scsi: hisi_sas: Replace with standard error code return value
scsi: hisi_sas: Rollback some operations if FLR failed
scsi: hisi_sas: Correct the number of global debugfs registers
ARM: dts: stm32: don't mix SCMI and non-SCMI board compatibles
selftests/net: fix grep checking for fib_nexthop_multiprefix
ipmr: support IP_PKTINFO on cache report IGMP msg
virtio/vsock: fix logic which reduces credit update messages
dma-mapping: clear dev->dma_mem to NULL after freeing it
soc: qcom: llcc: Fix dis_cap_alloc and retain_on_pc configuration
arm64: dts: qcom: sm8150-hdk: fix SS USB regulators
block: add check of 'minors' and 'first_minor' in device_add_disk()
arm64: dts: qcom: sc7280: Mark SDHCI hosts as cache-coherent
arm64: dts: qcom: ipq6018: fix clock rates for GCC_USB0_MOCK_UTMI_CLK
arm64: dts: qcom: ipq6018: improve pcie phy pcs reg table
arm64: dts: qcom: ipq6018: Use lowercase hex
arm64: dts: qcom: ipq6018: Pad addresses to 8 hex digits
arm64: dts: qcom: ipq6018: Fix up indentation
wifi: rtlwifi: add calculate_bit_shift()
wifi: rtlwifi: rtl8188ee: phy: using calculate_bit_shift()
wifi: rtlwifi: rtl8192c: using calculate_bit_shift()
wifi: rtlwifi: rtl8192cu: using calculate_bit_shift()
wifi: rtlwifi: rtl8192ce: using calculate_bit_shift()
wifi: rtlwifi: rtl8192de: using calculate_bit_shift()
wifi: rtlwifi: rtl8192ee: using calculate_bit_shift()
wifi: rtlwifi: rtl8192se: using calculate_bit_shift()
wifi: iwlwifi: mvm: set siso/mimo chains to 1 in FW SMPS request
wifi: iwlwifi: mvm: send TX path flush in rfkill
netfilter: nf_tables: mark newset as dead on transaction abort
Bluetooth: Fix bogus check for re-auth no supported with non-ssp
Bluetooth: btmtkuart: fix recv_buf() return value
block: make BLK_DEF_MAX_SECTORS unsigned
null_blk: don't cap max_hw_sectors to BLK_DEF_MAX_SECTORS
bpf: sockmap, fix proto update hook to avoid dup calls
sctp: support MSG_ERRQUEUE flag in recvmsg()
sctp: fix busy polling
net/sched: act_ct: fix skb leak and crash on ooo frags
mlxbf_gige: Fix intermittent no ip issue
mlxbf_gige: Enable the GigE port in mlxbf_gige_open
ip6_tunnel: fix NEXTHDR_FRAGMENT handling in ip6_tnl_parse_tlv_enc_lim()
ARM: davinci: always select CONFIG_CPU_ARM926T
Revert "drm/tidss: Annotate dma-fence critical section in commit path"
Revert "drm/omapdrm: Annotate dma-fence critical section in commit path"
drm/panfrost: Really power off GPU cores in panfrost_gpu_power_off()
RDMA/usnic: Silence uninitialized symbol smatch warnings
RDMA/hns: Fix inappropriate err code for unsupported operations
drm/panel-elida-kd35t133: hold panel in reset for unprepare
drm/nouveau/fence:: fix warning directly dereferencing a rcu pointer
drm/bridge: tpd12s015: Drop buggy __exit annotation for remove function
drm/tilcdc: Fix irq free on unload
media: pvrusb2: fix use after free on context disconnection
media: mtk-jpegdec: export jpeg decoder functions
media: mtk-jpeg: Remove cancel worker in mtk_jpeg_remove to avoid the crash of multi-core JPEG devices
media: verisilicon: Hook the (TRY_)DECODER_CMD stateless ioctls
media: rkvdec: Hook the (TRY_)DECODER_CMD stateless ioctls
drm/bridge: Fix typo in post_disable() description
f2fs: fix to avoid dirent corruption
drm/radeon/r600_cs: Fix possible int overflows in r600_cs_check_reg()
drm/radeon/r100: Fix integer overflow issues in r100_cs_track_check()
drm/radeon: check return value of radeon_ring_lock()
drm/tidss: Move reset to the end of dispc_init()
drm/tidss: Return error value from from softreset
drm/tidss: Check for K2G in in dispc_softreset()
drm/tidss: Fix dss reset
ASoC: cs35l33: Fix GPIO name and drop legacy include
ASoC: cs35l34: Fix GPIO name and drop legacy include
drm/msm/mdp4: flush vblank event on disable
drm/msm/dsi: Use pm_runtime_resume_and_get to prevent refcnt leaks
drm/drv: propagate errors from drm_modeset_register_all()
ASoC: Intel: glk_rt5682_max98357a: fix board id mismatch
drm/panfrost: Ignore core_mask for poweroff and disable PWRTRANS irq
drm/radeon: check the alloc_workqueue return value in radeon_crtc_init()
drm/radeon/dpm: fix a memleak in sumo_parse_power_table
drm/radeon/trinity_dpm: fix a memleak in trinity_parse_power_table
drm/bridge: cdns-mhdp8546: Fix use of uninitialized variable
drm/bridge: tc358767: Fix return value on error case
media: cx231xx: fix a memleak in cx231xx_init_isoc
RDMA/hns: Fix memory leak in free_mr_init()
clk: qcom: gpucc-sm8150: Update the gpu_cc_pll1 config
media: imx-mipi-csis: Fix clock handling in remove()
media: dt-bindings: media: rkisp1: Fix the port description for the parallel interface
media: rkisp1: Fix media device memory leak
drm/panel: st7701: Fix AVCL calculation
f2fs: fix to wait on block writeback for post_read case
f2fs: fix to check compress file in f2fs_move_file_range()
f2fs: fix to update iostat correctly in f2fs_filemap_fault()
media: dvbdev: drop refcount on error path in dvb_device_open()
media: dvb-frontends: m88ds3103: Fix a memory leak in an error handling path of m88ds3103_probe()
clk: renesas: rzg2l-cpg: Reuse code in rzg2l_cpg_reset()
clk: renesas: rzg2l: Check reset monitor registers
drm/msm/dpu: Set input_sel bit for INTF
drm/msm/dpu: Drop enable and frame_count parameters from dpu_hw_setup_misr()
drm/mediatek: Return error if MDP RDMA failed to enable the clock
drm/mediatek: Fix underrun in VDO1 when switches off the layer
drm/amdgpu/debugfs: fix error code when smc register accessors are NULL
drm/amd/pm: fix a double-free in si_dpm_init
drivers/amd/pm: fix a use-after-free in kv_parse_power_table
gpu/drm/radeon: fix two memleaks in radeon_vm_init
drm/amd/pm: fix a double-free in amdgpu_parse_extended_power_table
f2fs: fix to check return value of f2fs_recover_xattr_data
dt-bindings: clock: Update the videocc resets for sm8150
clk: qcom: videocc-sm8150: Update the videocc resets
clk: qcom: videocc-sm8150: Add missing PLL config property
drivers: clk: zynqmp: calculate closest mux rate
drivers: clk: zynqmp: update divider round rate logic
watchdog: set cdev owner before adding
watchdog/hpwdt: Only claim UNKNOWN NMI if from iLO
watchdog: bcm2835_wdt: Fix WDIOC_SETTIMEOUT handling
watchdog: rti_wdt: Drop runtime pm reference count when watchdog is unused
clk: si5341: fix an error code problem in si5341_output_clk_set_rate
drm/mediatek: dp: Add phy_mtk_dp module as pre-dependency
accel/habanalabs: fix information leak in sec_attest_info()
clk: fixed-rate: fix clk_hw_register_fixed_rate_with_accuracy_parent_hw
pwm: stm32: Use regmap_clear_bits and regmap_set_bits where applicable
pwm: stm32: Use hweight32 in stm32_pwm_detect_channels
pwm: stm32: Fix enable count for clk in .probe()
ASoC: rt5645: Drop double EF20 entry from dmi_platform_data[]
ALSA: scarlett2: Add missing error check to scarlett2_config_save()
ALSA: scarlett2: Add missing error check to scarlett2_usb_set_config()
ALSA: scarlett2: Allow passing any output to line_out_remap()
ALSA: scarlett2: Add missing error checks to *_ctl_get()
ALSA: scarlett2: Add clamp() in scarlett2_mixer_ctl_put()
mmc: sdhci_am654: Fix TI SoC dependencies
mmc: sdhci_omap: Fix TI SoC dependencies
IB/iser: Prevent invalidating wrong MR
drm/amdkfd: Confirm list is non-empty before utilizing list_first_entry in kfd_topology.c
drm/amd/pm/smu7: fix a memleak in smu7_hwmgr_backend_init
kselftest/alsa - mixer-test: fix the number of parameters to ksft_exit_fail_msg()
kselftest/alsa - mixer-test: Fix the print format specifier warning
ksmbd: validate the zero field of packet header
of: Fix double free in of_parse_phandle_with_args_map
fbdev: imxfb: fix left margin setting
of: unittest: Fix of_count_phandle_with_args() expected value message
selftests/bpf: Add assert for user stacks in test_task_stack
keys, dns: Fix size check of V1 server-list header
binder: fix async space check for 0-sized buffers
binder: fix unused alloc->free_async_space
mips/smp: Call rcutree_report_cpu_starting() earlier
Input: atkbd - use ab83 as id when skipping the getid command
xen-netback: don't produce zero-size SKB frags
binder: fix race between mmput() and do_exit()
clocksource/drivers/timer-ti-dm: Fix make W=n kerneldoc warnings
powerpc/64s: Increase default stack size to 32KB
tick-sched: Fix idle and iowait sleeptime accounting vs CPU hotplug
usb: phy: mxs: remove CONFIG_USB_OTG condition for mxs_phy_is_otg_host()
usb: dwc: ep0: Update request status in dwc3_ep0_stall_restart
Revert "usb: dwc3: Soft reset phy on probe for host"
Revert "usb: dwc3: don't reset device side if dwc3 was configured as host-only"
usb: chipidea: wait controller resume finished for wakeup irq
usb: cdns3: fix uvc failure work since sg support enabled
usb: cdns3: fix iso transfer error when mult is not zero
usb: cdns3: Fix uvc fail when DMA cross 4k boundery since sg enabled
Revert "usb: typec: class: fix typec_altmode_put_partner to put plugs"
usb: typec: class: fix typec_altmode_put_partner to put plugs
usb: mon: Fix atomicity violation in mon_bin_vma_fault
serial: core: fix sanitizing check for RTS settings
serial: core: make sure RS485 cannot be enabled when it is not supported
serial: 8250_bcm2835aux: Restore clock error handling
serial: core, imx: do not set RS485 enabled if it is not supported
serial: imx: Ensure that imx_uart_rs485_config() is called with enabled clock
serial: 8250_exar: Set missing rs485_supported flag
serial: omap: do not override settings for RS485 support
drm/vmwgfx: Fix possible invalid drm gem put calls
drm/vmwgfx: Keep a gem reference to user bos in surfaces
ALSA: oxygen: Fix right channel of capture volume mixer
ALSA: hda/relatek: Enable Mute LED on HP Laptop 15s-fq2xxx
ALSA: hda/realtek: Enable mute/micmute LEDs and limit mic boost on HP ZBook
ALSA: hda/realtek: Enable headset mic on Lenovo M70 Gen5
ksmbd: validate mech token in session setup
ksmbd: fix UAF issue in ksmbd_tcp_new_connection()
ksmbd: only v2 leases handle the directory
io_uring/rw: ensure io->bytes_done is always initialized
fbdev: flush deferred work in fb_deferred_io_fsync()
fbdev: flush deferred IO before closing
scsi: ufs: core: Simplify power management during async scan
scsi: target: core: add missing file_{start,end}_write()
scsi: mpi3mr: Refresh sdev queue depth after controller reset
scsi: mpi3mr: Block PEL Enable Command on Controller Reset and Unrecoverable State
drm/amd: Enable PCIe PME from D3
block: add check that partition length needs to be aligned with block size
block: Fix iterating over an empty bio with bio_for_each_folio_all
netfilter: nf_tables: check if catch-all set element is active in next generation
pwm: jz4740: Don't use dev_err_probe() in .request()
pwm: Fix out-of-bounds access in of_pwm_single_xlate()
md/raid1: Use blk_opf_t for read and write operations
rootfs: Fix support for rootfstype= when root= is given
Bluetooth: Fix atomicity violation in {min,max}_key_size_set
bpf: Fix re-attachment branch in bpf_tracing_prog_attach
LoongArch: Fix and simplify fcsr initialization on execve()
iommu/arm-smmu-qcom: Add missing GMU entry to match table
iommu/dma: Trace bounce buffer usage when mapping buffers
wifi: mt76: fix broken precal loading from MTD for mt7915
wifi: rtlwifi: Remove bogus and dangerous ASPM disable/enable code
wifi: rtlwifi: Convert LNKCTL change to PCIe cap RMW accessors
wifi: mwifiex: configure BSSID consistently when starting AP
Revert "net: rtnetlink: Enslave device before bringing it up"
cxl/port: Fix decoder initialization when nr_targets > interleave_ways
PCI/P2PDMA: Remove reference to pci_p2pdma_map_sg()
PCI: dwc: endpoint: Fix dw_pcie_ep_raise_msix_irq() alignment support
PCI: mediatek: Clear interrupt status before dispatching handler
x86/kvm: Do not try to disable kvmclock if it was not enabled
KVM: arm64: vgic-v4: Restore pending state on host userspace write
KVM: arm64: vgic-its: Avoid potential UAF in LPI translation cache
iio: adc: ad7091r: Pass iio_dev to event handler
HID: wacom: Correct behavior when processing some confidence == false touches
serial: sc16is7xx: add check for unsupported SPI modes during probe
serial: sc16is7xx: set safe default SPI clock frequency
ARM: 9330/1: davinci: also select PINCTRL
mfd: syscon: Fix null pointer dereference in of_syscon_register()
leds: aw2013: Select missing dependency REGMAP_I2C
mfd: intel-lpss: Fix the fractional clock divider flags
mips: dmi: Fix early remap on MIPS32
mips: Fix incorrect max_low_pfn adjustment
riscv: Check if the code to patch lies in the exit section
riscv: Fix module_alloc() that did not reset the linear mapping permissions
riscv: Fix set_memory_XX() and set_direct_map_XX() by splitting huge linear mappings
riscv: Fix set_direct_map_default_noflush() to reset _PAGE_EXEC
riscv: Fixed wrong register in XIP_FIXUP_FLASH_OFFSET macro
MIPS: Alchemy: Fix an out-of-bound access in db1200_dev_setup()
MIPS: Alchemy: Fix an out-of-bound access in db1550_dev_setup()
power: supply: cw2015: correct time_to_empty units in sysfs
power: supply: bq256xx: fix some problem in bq256xx_hw_init
serial: 8250: omap: Don't skip resource freeing if pm_runtime_resume_and_get() failed
libapi: Add missing linux/types.h header to get the __u64 type on io.h
base/node.c: initialize the accessor list before registering
acpi: property: Let args be NULL in __acpi_node_get_property_reference
software node: Let args be NULL in software_node_get_reference_args
serial: imx: fix tx statemachine deadlock
selftests/sgx: Fix uninitialized pointer dereference in error path
selftests/sgx: Fix uninitialized pointer dereferences in encl_get_entry
selftests/sgx: Include memory clobber for inline asm in test enclave
selftests/sgx: Skip non X86_64 platform
iio: adc: ad9467: fix reset gpio handling
iio: adc: ad9467: don't ignore error codes
iio: adc: ad9467: fix scale setting
perf header: Fix one memory leakage in perf_event__fprintf_event_update()
perf hisi-ptt: Fix one memory leakage in hisi_ptt_process_auxtrace_event()
perf genelf: Set ELF program header addresses properly
tty: change tty_write_lock()'s ndelay parameter to bool
tty: early return from send_break() on TTY_DRIVER_HARDWARE_BREAK
tty: don't check for signal_pending() in send_break()
tty: use 'if' in send_break() instead of 'goto'
usb: cdc-acm: return correct error code on unsupported break
spmi: mtk-pmif: Serialize PMIF status check and command submission
vdpa: Fix an error handling path in eni_vdpa_probe()
nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length
nvmet-tcp: fix a crash in nvmet_req_complete()
perf env: Avoid recursively taking env->bpf_progs.lock
cxl/region: fix x9 interleave typo
apparmor: avoid crash when parsed profile name is empty
usb: xhci-mtk: fix a short packet issue of gen1 isoc-in transfer
serial: imx: Correct clock error message in function probe()
nvmet: re-fix tracing strncpy() warning
nvme: trace: avoid memcpy overflow warning
nvmet-tcp: Fix the H2C expected PDU len calculation
PCI: keystone: Fix race condition when initializing PHYs
PCI: mediatek-gen3: Fix translation window size calculation
ASoC: mediatek: sof-common: Add NULL check for normal_link string
s390/pci: fix max size calculation in zpci_memcpy_toio()
net: qualcomm: rmnet: fix global oob in rmnet_policy
net: ethernet: ti: am65-cpsw: Fix max mtu to fit ethernet frames
amt: do not use overwrapped cb area
net: phy: micrel: populate .soft_reset for KSZ9131
mptcp: mptcp_parse_option() fix for MPTCPOPT_MP_JOIN
mptcp: strict validation before using mp_opt->hmac
mptcp: use OPTION_MPTCP_MPJ_SYNACK in subflow_finish_connect()
mptcp: use OPTION_MPTCP_MPJ_SYN in subflow_check_req()
mptcp: refine opt_mp_capable determination
block: ensure we hold a queue reference when using queue limits
udp: annotate data-races around up->pending
net: ravb: Fix dma_addr_t truncation in error case
dt-bindings: gpio: xilinx: Fix node address in gpio
drm/amdkfd: Use resource_size() helper function
drm/amdkfd: fixes for HMM mem allocation
net: stmmac: ethtool: Fixed calltrace caused by unbalanced disable_irq_wake calls
bpf: Reject variable offset alu on PTR_TO_FLOW_KEYS
net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe
LoongArch: BPF: Prevent out-of-bounds memory access
mptcp: relax check on MPC passive fallback
netfilter: nf_tables: reject invalid set policy
netfilter: nft_limit: do not ignore unsupported flags
netfilter: nfnetlink_log: use proper helper for fetching physinif
netfilter: nf_queue: remove excess nf_bridge variable
netfilter: propagate net to nf_bridge_get_physindev
netfilter: bridge: replace physindev with physinif in nf_bridge_info
netfilter: nf_tables: do not allow mismatch field size and set key length
netfilter: nf_tables: skip dead set elements in netlink dump
netfilter: nf_tables: reject NFT_SET_CONCAT with not field length description
ipvs: avoid stat macros calls from preemptible context
kdb: Fix a potential buffer overflow in kdb_local()
ethtool: netlink: Add missing ethnl_ops_begin/complete
loop: fix the the direct I/O support check when used on top of block devices
mlxsw: spectrum_acl_erp: Fix error flow of pool allocation failure
selftests: mlxsw: qos_pfc: Adjust the test to support 8 lanes
ipv6: mcast: fix data-race in ipv6_mc_down / mld_ifc_work
i2c: s3c24xx: fix read transfers in polling mode
i2c: s3c24xx: fix transferring more than one message in polling mode
block: Remove special-casing of compound pages
riscv: Fix wrong usage of lm_alias() when splitting a huge linear mapping
Revert "KEYS: encrypted: Add check for strsep"
arm64: dts: armada-3720-turris-mox: set irq type for RTC
Revert "Revert "md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d""
Linux 6.1.75
Change-Id: I60398ecc9a2e50206fd9d25c0d6c9ad6e1ca71a0
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1297 lines
35 KiB
C
1297 lines
35 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* binder_alloc.c
|
|
*
|
|
* Android IPC Subsystem
|
|
*
|
|
* Copyright (C) 2007-2017 Google, Inc.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/module.h>
|
|
#include <linux/rtmutex.h>
|
|
#include <linux/rbtree.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/list_lru.h>
|
|
#include <linux/ratelimit.h>
|
|
#include <asm/cacheflush.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/sizes.h>
|
|
#include "binder_alloc.h"
|
|
#include "binder_trace.h"
|
|
#include <trace/hooks/binder.h>
|
|
|
|
struct list_lru binder_alloc_lru;
|
|
|
|
static DEFINE_MUTEX(binder_alloc_mmap_lock);
|
|
|
|
enum {
|
|
BINDER_DEBUG_USER_ERROR = 1U << 0,
|
|
BINDER_DEBUG_OPEN_CLOSE = 1U << 1,
|
|
BINDER_DEBUG_BUFFER_ALLOC = 1U << 2,
|
|
BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3,
|
|
};
|
|
static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR;
|
|
|
|
module_param_named(debug_mask, binder_alloc_debug_mask,
|
|
uint, 0644);
|
|
|
|
#define binder_alloc_debug(mask, x...) \
|
|
do { \
|
|
if (binder_alloc_debug_mask & mask) \
|
|
pr_info_ratelimited(x); \
|
|
} while (0)
|
|
|
|
static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer)
|
|
{
|
|
return list_entry(buffer->entry.next, struct binder_buffer, entry);
|
|
}
|
|
|
|
static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer)
|
|
{
|
|
return list_entry(buffer->entry.prev, struct binder_buffer, entry);
|
|
}
|
|
|
|
static size_t binder_alloc_buffer_size(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
if (list_is_last(&buffer->entry, &alloc->buffers))
|
|
return alloc->buffer + alloc->buffer_size - buffer->user_data;
|
|
return binder_buffer_next(buffer)->user_data - buffer->user_data;
|
|
}
|
|
|
|
static void binder_insert_free_buffer(struct binder_alloc *alloc,
|
|
struct binder_buffer *new_buffer)
|
|
{
|
|
struct rb_node **p = &alloc->free_buffers.rb_node;
|
|
struct rb_node *parent = NULL;
|
|
struct binder_buffer *buffer;
|
|
size_t buffer_size;
|
|
size_t new_buffer_size;
|
|
|
|
BUG_ON(!new_buffer->free);
|
|
|
|
new_buffer_size = binder_alloc_buffer_size(alloc, new_buffer);
|
|
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: add free buffer, size %zd, at %pK\n",
|
|
alloc->pid, new_buffer_size, new_buffer);
|
|
|
|
while (*p) {
|
|
parent = *p;
|
|
buffer = rb_entry(parent, struct binder_buffer, rb_node);
|
|
BUG_ON(!buffer->free);
|
|
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
|
|
if (new_buffer_size < buffer_size)
|
|
p = &parent->rb_left;
|
|
else
|
|
p = &parent->rb_right;
|
|
}
|
|
rb_link_node(&new_buffer->rb_node, parent, p);
|
|
rb_insert_color(&new_buffer->rb_node, &alloc->free_buffers);
|
|
}
|
|
|
|
static void binder_insert_allocated_buffer_locked(
|
|
struct binder_alloc *alloc, struct binder_buffer *new_buffer)
|
|
{
|
|
struct rb_node **p = &alloc->allocated_buffers.rb_node;
|
|
struct rb_node *parent = NULL;
|
|
struct binder_buffer *buffer;
|
|
|
|
BUG_ON(new_buffer->free);
|
|
|
|
while (*p) {
|
|
parent = *p;
|
|
buffer = rb_entry(parent, struct binder_buffer, rb_node);
|
|
BUG_ON(buffer->free);
|
|
|
|
if (new_buffer->user_data < buffer->user_data)
|
|
p = &parent->rb_left;
|
|
else if (new_buffer->user_data > buffer->user_data)
|
|
p = &parent->rb_right;
|
|
else
|
|
BUG();
|
|
}
|
|
rb_link_node(&new_buffer->rb_node, parent, p);
|
|
rb_insert_color(&new_buffer->rb_node, &alloc->allocated_buffers);
|
|
}
|
|
|
|
static struct binder_buffer *binder_alloc_prepare_to_free_locked(
|
|
struct binder_alloc *alloc,
|
|
uintptr_t user_ptr)
|
|
{
|
|
struct rb_node *n = alloc->allocated_buffers.rb_node;
|
|
struct binder_buffer *buffer;
|
|
void __user *uptr;
|
|
|
|
uptr = (void __user *)user_ptr;
|
|
|
|
while (n) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
BUG_ON(buffer->free);
|
|
|
|
if (uptr < buffer->user_data)
|
|
n = n->rb_left;
|
|
else if (uptr > buffer->user_data)
|
|
n = n->rb_right;
|
|
else {
|
|
/*
|
|
* Guard against user threads attempting to
|
|
* free the buffer when in use by kernel or
|
|
* after it's already been freed.
|
|
*/
|
|
if (!buffer->allow_user_free)
|
|
return ERR_PTR(-EPERM);
|
|
buffer->allow_user_free = 0;
|
|
return buffer;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_prepare_to_free() - get buffer given user ptr
|
|
* @alloc: binder_alloc for this proc
|
|
* @user_ptr: User pointer to buffer data
|
|
*
|
|
* Validate userspace pointer to buffer data and return buffer corresponding to
|
|
* that user pointer. Search the rb tree for buffer that matches user data
|
|
* pointer.
|
|
*
|
|
* Return: Pointer to buffer or NULL
|
|
*/
|
|
struct binder_buffer *binder_alloc_prepare_to_free(struct binder_alloc *alloc,
|
|
uintptr_t user_ptr)
|
|
{
|
|
struct binder_buffer *buffer;
|
|
|
|
mutex_lock(&alloc->mutex);
|
|
buffer = binder_alloc_prepare_to_free_locked(alloc, user_ptr);
|
|
mutex_unlock(&alloc->mutex);
|
|
return buffer;
|
|
}
|
|
|
|
static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
|
|
void __user *start, void __user *end)
|
|
{
|
|
void __user *page_addr;
|
|
unsigned long user_page_addr;
|
|
struct binder_lru_page *page;
|
|
struct vm_area_struct *vma = NULL;
|
|
struct mm_struct *mm = NULL;
|
|
bool need_mm = false;
|
|
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: %s pages %pK-%pK\n", alloc->pid,
|
|
allocate ? "allocate" : "free", start, end);
|
|
|
|
if (end <= start)
|
|
return 0;
|
|
|
|
trace_binder_update_page_range(alloc, allocate, start, end);
|
|
|
|
if (allocate == 0)
|
|
goto free_range;
|
|
|
|
for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
|
|
page = &alloc->pages[(page_addr - alloc->buffer) / PAGE_SIZE];
|
|
if (!page->page_ptr) {
|
|
need_mm = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (need_mm && mmget_not_zero(alloc->mm))
|
|
mm = alloc->mm;
|
|
|
|
if (mm) {
|
|
mmap_write_lock(mm);
|
|
vma = alloc->vma;
|
|
}
|
|
|
|
if (!vma && need_mm) {
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"%d: binder_alloc_buf failed to map pages in userspace, no vma\n",
|
|
alloc->pid);
|
|
goto err_no_vma;
|
|
}
|
|
|
|
for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
|
|
int ret;
|
|
bool on_lru;
|
|
size_t index;
|
|
|
|
index = (page_addr - alloc->buffer) / PAGE_SIZE;
|
|
page = &alloc->pages[index];
|
|
|
|
if (page->page_ptr) {
|
|
trace_binder_alloc_lru_start(alloc, index);
|
|
|
|
on_lru = list_lru_del(&binder_alloc_lru, &page->lru);
|
|
WARN_ON(!on_lru);
|
|
|
|
trace_binder_alloc_lru_end(alloc, index);
|
|
continue;
|
|
}
|
|
|
|
if (WARN_ON(!vma))
|
|
goto err_page_ptr_cleared;
|
|
|
|
trace_binder_alloc_page_start(alloc, index);
|
|
page->page_ptr = alloc_page(GFP_KERNEL |
|
|
__GFP_HIGHMEM |
|
|
__GFP_ZERO);
|
|
if (!page->page_ptr) {
|
|
pr_err("%d: binder_alloc_buf failed for page at %pK\n",
|
|
alloc->pid, page_addr);
|
|
goto err_alloc_page_failed;
|
|
}
|
|
page->alloc = alloc;
|
|
INIT_LIST_HEAD(&page->lru);
|
|
|
|
user_page_addr = (uintptr_t)page_addr;
|
|
ret = vm_insert_page(vma, user_page_addr, page[0].page_ptr);
|
|
if (ret) {
|
|
pr_err("%d: binder_alloc_buf failed to map page at %lx in userspace\n",
|
|
alloc->pid, user_page_addr);
|
|
goto err_vm_insert_page_failed;
|
|
}
|
|
|
|
if (index + 1 > alloc->pages_high)
|
|
alloc->pages_high = index + 1;
|
|
|
|
trace_binder_alloc_page_end(alloc, index);
|
|
}
|
|
if (mm) {
|
|
mmap_write_unlock(mm);
|
|
mmput_async(mm);
|
|
}
|
|
return 0;
|
|
|
|
free_range:
|
|
for (page_addr = end - PAGE_SIZE; 1; page_addr -= PAGE_SIZE) {
|
|
bool ret;
|
|
size_t index;
|
|
|
|
index = (page_addr - alloc->buffer) / PAGE_SIZE;
|
|
page = &alloc->pages[index];
|
|
|
|
trace_binder_free_lru_start(alloc, index);
|
|
|
|
ret = list_lru_add(&binder_alloc_lru, &page->lru);
|
|
WARN_ON(!ret);
|
|
|
|
trace_binder_free_lru_end(alloc, index);
|
|
if (page_addr == start)
|
|
break;
|
|
continue;
|
|
|
|
err_vm_insert_page_failed:
|
|
__free_page(page->page_ptr);
|
|
page->page_ptr = NULL;
|
|
err_alloc_page_failed:
|
|
err_page_ptr_cleared:
|
|
if (page_addr == start)
|
|
break;
|
|
}
|
|
err_no_vma:
|
|
if (mm) {
|
|
mmap_write_unlock(mm);
|
|
mmput_async(mm);
|
|
}
|
|
return vma ? -ENOMEM : -ESRCH;
|
|
}
|
|
|
|
static inline void binder_alloc_set_vma(struct binder_alloc *alloc,
|
|
struct vm_area_struct *vma)
|
|
{
|
|
/* pairs with smp_load_acquire in binder_alloc_get_vma() */
|
|
smp_store_release(&alloc->vma, vma);
|
|
}
|
|
|
|
static inline struct vm_area_struct *binder_alloc_get_vma(
|
|
struct binder_alloc *alloc)
|
|
{
|
|
/* pairs with smp_store_release in binder_alloc_set_vma() */
|
|
return smp_load_acquire(&alloc->vma);
|
|
}
|
|
|
|
static bool debug_low_async_space_locked(struct binder_alloc *alloc, int pid)
|
|
{
|
|
/*
|
|
* Find the amount and size of buffers allocated by the current caller;
|
|
* The idea is that once we cross the threshold, whoever is responsible
|
|
* for the low async space is likely to try to send another async txn,
|
|
* and at some point we'll catch them in the act. This is more efficient
|
|
* than keeping a map per pid.
|
|
*/
|
|
struct rb_node *n;
|
|
struct binder_buffer *buffer;
|
|
size_t total_alloc_size = 0;
|
|
size_t num_buffers = 0;
|
|
|
|
for (n = rb_first(&alloc->allocated_buffers); n != NULL;
|
|
n = rb_next(n)) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
if (buffer->pid != pid)
|
|
continue;
|
|
if (!buffer->async_transaction)
|
|
continue;
|
|
total_alloc_size += binder_alloc_buffer_size(alloc, buffer);
|
|
num_buffers++;
|
|
}
|
|
|
|
/*
|
|
* Warn if this pid has more than 50 transactions, or more than 50% of
|
|
* async space (which is 25% of total buffer size). Oneway spam is only
|
|
* detected when the threshold is exceeded.
|
|
*/
|
|
if (num_buffers > 50 || total_alloc_size > alloc->buffer_size / 4) {
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"%d: pid %d spamming oneway? %zd buffers allocated for a total size of %zd\n",
|
|
alloc->pid, pid, num_buffers, total_alloc_size);
|
|
if (!alloc->oneway_spam_detected) {
|
|
alloc->oneway_spam_detected = true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static struct binder_buffer *binder_alloc_new_buf_locked(
|
|
struct binder_alloc *alloc,
|
|
size_t data_size,
|
|
size_t offsets_size,
|
|
size_t extra_buffers_size,
|
|
int is_async,
|
|
int pid)
|
|
{
|
|
struct rb_node *n = alloc->free_buffers.rb_node;
|
|
struct binder_buffer *buffer;
|
|
size_t buffer_size;
|
|
struct rb_node *best_fit = NULL;
|
|
void __user *has_page_addr;
|
|
void __user *end_page_addr;
|
|
size_t size, data_offsets_size;
|
|
int ret;
|
|
bool should_fail = false;
|
|
|
|
/* Check binder_alloc is fully initialized */
|
|
if (!binder_alloc_get_vma(alloc)) {
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"%d: binder_alloc_buf, no vma\n",
|
|
alloc->pid);
|
|
return ERR_PTR(-ESRCH);
|
|
}
|
|
|
|
data_offsets_size = ALIGN(data_size, sizeof(void *)) +
|
|
ALIGN(offsets_size, sizeof(void *));
|
|
|
|
if (data_offsets_size < data_size || data_offsets_size < offsets_size) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: got transaction with invalid size %zd-%zd\n",
|
|
alloc->pid, data_size, offsets_size);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
size = data_offsets_size + ALIGN(extra_buffers_size, sizeof(void *));
|
|
if (size < data_offsets_size || size < extra_buffers_size) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: got transaction with invalid extra_buffers_size %zd\n",
|
|
alloc->pid, extra_buffers_size);
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
trace_android_vh_binder_alloc_new_buf_locked(size, &alloc->free_async_space, is_async);
|
|
trace_android_vh_binder_detect_low_async_space_locked(is_async, &alloc->free_async_space, pid, &should_fail);
|
|
if (should_fail) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: binder_alloc_buf size %zd failed, not allowed to alloc more async space\n",
|
|
alloc->pid, size);
|
|
return ERR_PTR(-EPERM);
|
|
}
|
|
|
|
/* Pad 0-size buffers so they get assigned unique addresses */
|
|
size = max(size, sizeof(void *));
|
|
|
|
if (is_async && alloc->free_async_space < size) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: binder_alloc_buf size %zd failed, no async space left\n",
|
|
alloc->pid, size);
|
|
return ERR_PTR(-ENOSPC);
|
|
}
|
|
|
|
while (n) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
BUG_ON(!buffer->free);
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
|
|
if (size < buffer_size) {
|
|
best_fit = n;
|
|
n = n->rb_left;
|
|
} else if (size > buffer_size)
|
|
n = n->rb_right;
|
|
else {
|
|
best_fit = n;
|
|
break;
|
|
}
|
|
}
|
|
if (best_fit == NULL) {
|
|
size_t allocated_buffers = 0;
|
|
size_t largest_alloc_size = 0;
|
|
size_t total_alloc_size = 0;
|
|
size_t free_buffers = 0;
|
|
size_t largest_free_size = 0;
|
|
size_t total_free_size = 0;
|
|
|
|
for (n = rb_first(&alloc->allocated_buffers); n != NULL;
|
|
n = rb_next(n)) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
allocated_buffers++;
|
|
total_alloc_size += buffer_size;
|
|
if (buffer_size > largest_alloc_size)
|
|
largest_alloc_size = buffer_size;
|
|
}
|
|
for (n = rb_first(&alloc->free_buffers); n != NULL;
|
|
n = rb_next(n)) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
free_buffers++;
|
|
total_free_size += buffer_size;
|
|
if (buffer_size > largest_free_size)
|
|
largest_free_size = buffer_size;
|
|
}
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"%d: binder_alloc_buf size %zd failed, no address space\n",
|
|
alloc->pid, size);
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
|
|
total_alloc_size, allocated_buffers,
|
|
largest_alloc_size, total_free_size,
|
|
free_buffers, largest_free_size);
|
|
return ERR_PTR(-ENOSPC);
|
|
}
|
|
if (n == NULL) {
|
|
buffer = rb_entry(best_fit, struct binder_buffer, rb_node);
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
}
|
|
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: binder_alloc_buf size %zd got buffer %pK size %zd\n",
|
|
alloc->pid, size, buffer, buffer_size);
|
|
|
|
has_page_addr = (void __user *)
|
|
(((uintptr_t)buffer->user_data + buffer_size) & PAGE_MASK);
|
|
WARN_ON(n && buffer_size != size);
|
|
end_page_addr =
|
|
(void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data + size);
|
|
if (end_page_addr > has_page_addr)
|
|
end_page_addr = has_page_addr;
|
|
ret = binder_update_page_range(alloc, 1, (void __user *)
|
|
PAGE_ALIGN((uintptr_t)buffer->user_data), end_page_addr);
|
|
if (ret)
|
|
return ERR_PTR(ret);
|
|
|
|
if (buffer_size != size) {
|
|
struct binder_buffer *new_buffer;
|
|
|
|
new_buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
|
|
if (!new_buffer) {
|
|
pr_err("%s: %d failed to alloc new buffer struct\n",
|
|
__func__, alloc->pid);
|
|
goto err_alloc_buf_struct_failed;
|
|
}
|
|
new_buffer->user_data = (u8 __user *)buffer->user_data + size;
|
|
list_add(&new_buffer->entry, &buffer->entry);
|
|
new_buffer->free = 1;
|
|
binder_insert_free_buffer(alloc, new_buffer);
|
|
}
|
|
|
|
rb_erase(best_fit, &alloc->free_buffers);
|
|
buffer->free = 0;
|
|
buffer->allow_user_free = 0;
|
|
binder_insert_allocated_buffer_locked(alloc, buffer);
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: binder_alloc_buf size %zd got %pK\n",
|
|
alloc->pid, size, buffer);
|
|
buffer->data_size = data_size;
|
|
buffer->offsets_size = offsets_size;
|
|
buffer->async_transaction = is_async;
|
|
buffer->extra_buffers_size = extra_buffers_size;
|
|
buffer->pid = pid;
|
|
buffer->oneway_spam_suspect = false;
|
|
if (is_async) {
|
|
alloc->free_async_space -= size;
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC,
|
|
"%d: binder_alloc_buf size %zd async free %zd\n",
|
|
alloc->pid, size, alloc->free_async_space);
|
|
if (alloc->free_async_space < alloc->buffer_size / 10) {
|
|
/*
|
|
* Start detecting spammers once we have less than 20%
|
|
* of async space left (which is less than 10% of total
|
|
* buffer size).
|
|
*/
|
|
buffer->oneway_spam_suspect = debug_low_async_space_locked(alloc, pid);
|
|
} else {
|
|
alloc->oneway_spam_detected = false;
|
|
}
|
|
}
|
|
return buffer;
|
|
|
|
err_alloc_buf_struct_failed:
|
|
binder_update_page_range(alloc, 0, (void __user *)
|
|
PAGE_ALIGN((uintptr_t)buffer->user_data),
|
|
end_page_addr);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_new_buf() - Allocate a new binder buffer
|
|
* @alloc: binder_alloc for this proc
|
|
* @data_size: size of user data buffer
|
|
* @offsets_size: user specified buffer offset
|
|
* @extra_buffers_size: size of extra space for meta-data (eg, security context)
|
|
* @is_async: buffer for async transaction
|
|
* @pid: pid to attribute allocation to (used for debugging)
|
|
*
|
|
* Allocate a new buffer given the requested sizes. Returns
|
|
* the kernel version of the buffer pointer. The size allocated
|
|
* is the sum of the three given sizes (each rounded up to
|
|
* pointer-sized boundary)
|
|
*
|
|
* Return: The allocated buffer or %ERR_PTR(-errno) if error
|
|
*/
|
|
struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc,
|
|
size_t data_size,
|
|
size_t offsets_size,
|
|
size_t extra_buffers_size,
|
|
int is_async,
|
|
int pid)
|
|
{
|
|
struct binder_buffer *buffer;
|
|
|
|
mutex_lock(&alloc->mutex);
|
|
buffer = binder_alloc_new_buf_locked(alloc, data_size, offsets_size,
|
|
extra_buffers_size, is_async, pid);
|
|
mutex_unlock(&alloc->mutex);
|
|
return buffer;
|
|
}
|
|
|
|
static void __user *buffer_start_page(struct binder_buffer *buffer)
|
|
{
|
|
return (void __user *)((uintptr_t)buffer->user_data & PAGE_MASK);
|
|
}
|
|
|
|
static void __user *prev_buffer_end_page(struct binder_buffer *buffer)
|
|
{
|
|
return (void __user *)
|
|
(((uintptr_t)(buffer->user_data) - 1) & PAGE_MASK);
|
|
}
|
|
|
|
static void binder_delete_free_buffer(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
struct binder_buffer *prev, *next = NULL;
|
|
bool to_free = true;
|
|
|
|
BUG_ON(alloc->buffers.next == &buffer->entry);
|
|
prev = binder_buffer_prev(buffer);
|
|
BUG_ON(!prev->free);
|
|
if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) {
|
|
to_free = false;
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: merge free, buffer %pK share page with %pK\n",
|
|
alloc->pid, buffer->user_data,
|
|
prev->user_data);
|
|
}
|
|
|
|
if (!list_is_last(&buffer->entry, &alloc->buffers)) {
|
|
next = binder_buffer_next(buffer);
|
|
if (buffer_start_page(next) == buffer_start_page(buffer)) {
|
|
to_free = false;
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: merge free, buffer %pK share page with %pK\n",
|
|
alloc->pid,
|
|
buffer->user_data,
|
|
next->user_data);
|
|
}
|
|
}
|
|
|
|
if (PAGE_ALIGNED(buffer->user_data)) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: merge free, buffer start %pK is page aligned\n",
|
|
alloc->pid, buffer->user_data);
|
|
to_free = false;
|
|
}
|
|
|
|
if (to_free) {
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: merge free, buffer %pK do not share page with %pK or %pK\n",
|
|
alloc->pid, buffer->user_data,
|
|
prev->user_data,
|
|
next ? next->user_data : NULL);
|
|
binder_update_page_range(alloc, 0, buffer_start_page(buffer),
|
|
buffer_start_page(buffer) + PAGE_SIZE);
|
|
}
|
|
list_del(&buffer->entry);
|
|
kfree(buffer);
|
|
}
|
|
|
|
static void binder_free_buf_locked(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
size_t size, buffer_size;
|
|
|
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
|
|
size = ALIGN(buffer->data_size, sizeof(void *)) +
|
|
ALIGN(buffer->offsets_size, sizeof(void *)) +
|
|
ALIGN(buffer->extra_buffers_size, sizeof(void *));
|
|
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%d: binder_free_buf %pK size %zd buffer_size %zd\n",
|
|
alloc->pid, buffer, size, buffer_size);
|
|
|
|
BUG_ON(buffer->free);
|
|
BUG_ON(size > buffer_size);
|
|
BUG_ON(buffer->transaction != NULL);
|
|
BUG_ON(buffer->user_data < alloc->buffer);
|
|
BUG_ON(buffer->user_data > alloc->buffer + alloc->buffer_size);
|
|
|
|
if (buffer->async_transaction) {
|
|
alloc->free_async_space += buffer_size;
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC,
|
|
"%d: binder_free_buf size %zd async free %zd\n",
|
|
alloc->pid, size, alloc->free_async_space);
|
|
}
|
|
|
|
binder_update_page_range(alloc, 0,
|
|
(void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data),
|
|
(void __user *)(((uintptr_t)
|
|
buffer->user_data + buffer_size) & PAGE_MASK));
|
|
|
|
rb_erase(&buffer->rb_node, &alloc->allocated_buffers);
|
|
buffer->free = 1;
|
|
if (!list_is_last(&buffer->entry, &alloc->buffers)) {
|
|
struct binder_buffer *next = binder_buffer_next(buffer);
|
|
|
|
if (next->free) {
|
|
rb_erase(&next->rb_node, &alloc->free_buffers);
|
|
binder_delete_free_buffer(alloc, next);
|
|
}
|
|
}
|
|
if (alloc->buffers.next != &buffer->entry) {
|
|
struct binder_buffer *prev = binder_buffer_prev(buffer);
|
|
|
|
if (prev->free) {
|
|
binder_delete_free_buffer(alloc, buffer);
|
|
rb_erase(&prev->rb_node, &alloc->free_buffers);
|
|
buffer = prev;
|
|
}
|
|
}
|
|
binder_insert_free_buffer(alloc, buffer);
|
|
}
|
|
|
|
static void binder_alloc_clear_buf(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer);
|
|
/**
|
|
* binder_alloc_free_buf() - free a binder buffer
|
|
* @alloc: binder_alloc for this proc
|
|
* @buffer: kernel pointer to buffer
|
|
*
|
|
* Free the buffer allocated via binder_alloc_new_buf()
|
|
*/
|
|
void binder_alloc_free_buf(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
/*
|
|
* We could eliminate the call to binder_alloc_clear_buf()
|
|
* from binder_alloc_deferred_release() by moving this to
|
|
* binder_free_buf_locked(). However, that could
|
|
* increase contention for the alloc mutex if clear_on_free
|
|
* is used frequently for large buffers. The mutex is not
|
|
* needed for correctness here.
|
|
*/
|
|
if (buffer->clear_on_free) {
|
|
binder_alloc_clear_buf(alloc, buffer);
|
|
buffer->clear_on_free = false;
|
|
}
|
|
mutex_lock(&alloc->mutex);
|
|
binder_free_buf_locked(alloc, buffer);
|
|
mutex_unlock(&alloc->mutex);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_mmap_handler() - map virtual address space for proc
|
|
* @alloc: alloc structure for this proc
|
|
* @vma: vma passed to mmap()
|
|
*
|
|
* Called by binder_mmap() to initialize the space specified in
|
|
* vma for allocating binder buffers
|
|
*
|
|
* Return:
|
|
* 0 = success
|
|
* -EBUSY = address space already mapped
|
|
* -ENOMEM = failed to map memory to given address space
|
|
*/
|
|
int binder_alloc_mmap_handler(struct binder_alloc *alloc,
|
|
struct vm_area_struct *vma)
|
|
{
|
|
int ret;
|
|
const char *failure_string;
|
|
struct binder_buffer *buffer;
|
|
|
|
if (unlikely(vma->vm_mm != alloc->mm)) {
|
|
ret = -EINVAL;
|
|
failure_string = "invalid vma->vm_mm";
|
|
goto err_invalid_mm;
|
|
}
|
|
|
|
mutex_lock(&binder_alloc_mmap_lock);
|
|
if (alloc->buffer_size) {
|
|
ret = -EBUSY;
|
|
failure_string = "already mapped";
|
|
goto err_already_mapped;
|
|
}
|
|
alloc->buffer_size = min_t(unsigned long, vma->vm_end - vma->vm_start,
|
|
SZ_4M);
|
|
mutex_unlock(&binder_alloc_mmap_lock);
|
|
|
|
alloc->buffer = (void __user *)vma->vm_start;
|
|
|
|
alloc->pages = kcalloc(alloc->buffer_size / PAGE_SIZE,
|
|
sizeof(alloc->pages[0]),
|
|
GFP_KERNEL);
|
|
if (alloc->pages == NULL) {
|
|
ret = -ENOMEM;
|
|
failure_string = "alloc page array";
|
|
goto err_alloc_pages_failed;
|
|
}
|
|
|
|
buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
|
|
if (!buffer) {
|
|
ret = -ENOMEM;
|
|
failure_string = "alloc buffer struct";
|
|
goto err_alloc_buf_struct_failed;
|
|
}
|
|
|
|
buffer->user_data = alloc->buffer;
|
|
list_add(&buffer->entry, &alloc->buffers);
|
|
buffer->free = 1;
|
|
binder_insert_free_buffer(alloc, buffer);
|
|
alloc->free_async_space = alloc->buffer_size / 2;
|
|
|
|
/* Signal binder_alloc is fully initialized */
|
|
binder_alloc_set_vma(alloc, vma);
|
|
|
|
return 0;
|
|
|
|
err_alloc_buf_struct_failed:
|
|
kfree(alloc->pages);
|
|
alloc->pages = NULL;
|
|
err_alloc_pages_failed:
|
|
alloc->buffer = NULL;
|
|
mutex_lock(&binder_alloc_mmap_lock);
|
|
alloc->buffer_size = 0;
|
|
err_already_mapped:
|
|
mutex_unlock(&binder_alloc_mmap_lock);
|
|
err_invalid_mm:
|
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
|
"%s: %d %lx-%lx %s failed %d\n", __func__,
|
|
alloc->pid, vma->vm_start, vma->vm_end,
|
|
failure_string, ret);
|
|
return ret;
|
|
}
|
|
|
|
|
|
void binder_alloc_deferred_release(struct binder_alloc *alloc)
|
|
{
|
|
struct rb_node *n;
|
|
int buffers, page_count;
|
|
struct binder_buffer *buffer;
|
|
|
|
buffers = 0;
|
|
mutex_lock(&alloc->mutex);
|
|
BUG_ON(alloc->vma);
|
|
|
|
while ((n = rb_first(&alloc->allocated_buffers))) {
|
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
|
|
/* Transaction should already have been freed */
|
|
BUG_ON(buffer->transaction);
|
|
|
|
if (buffer->clear_on_free) {
|
|
binder_alloc_clear_buf(alloc, buffer);
|
|
buffer->clear_on_free = false;
|
|
}
|
|
binder_free_buf_locked(alloc, buffer);
|
|
buffers++;
|
|
}
|
|
|
|
while (!list_empty(&alloc->buffers)) {
|
|
buffer = list_first_entry(&alloc->buffers,
|
|
struct binder_buffer, entry);
|
|
WARN_ON(!buffer->free);
|
|
|
|
list_del(&buffer->entry);
|
|
WARN_ON_ONCE(!list_empty(&alloc->buffers));
|
|
kfree(buffer);
|
|
}
|
|
|
|
page_count = 0;
|
|
if (alloc->pages) {
|
|
int i;
|
|
|
|
for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {
|
|
void __user *page_addr;
|
|
bool on_lru;
|
|
|
|
if (!alloc->pages[i].page_ptr)
|
|
continue;
|
|
|
|
on_lru = list_lru_del(&binder_alloc_lru,
|
|
&alloc->pages[i].lru);
|
|
page_addr = alloc->buffer + i * PAGE_SIZE;
|
|
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
|
|
"%s: %d: page %d at %pK %s\n",
|
|
__func__, alloc->pid, i, page_addr,
|
|
on_lru ? "on lru" : "active");
|
|
__free_page(alloc->pages[i].page_ptr);
|
|
page_count++;
|
|
}
|
|
kfree(alloc->pages);
|
|
}
|
|
mutex_unlock(&alloc->mutex);
|
|
if (alloc->mm)
|
|
mmdrop(alloc->mm);
|
|
|
|
binder_alloc_debug(BINDER_DEBUG_OPEN_CLOSE,
|
|
"%s: %d buffers %d, pages %d\n",
|
|
__func__, alloc->pid, buffers, page_count);
|
|
}
|
|
|
|
static void print_binder_buffer(struct seq_file *m, const char *prefix,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
seq_printf(m, "%s %d: %pK size %zd:%zd:%zd %s\n",
|
|
prefix, buffer->debug_id, buffer->user_data,
|
|
buffer->data_size, buffer->offsets_size,
|
|
buffer->extra_buffers_size,
|
|
buffer->transaction ? "active" : "delivered");
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_print_allocated() - print buffer info
|
|
* @m: seq_file for output via seq_printf()
|
|
* @alloc: binder_alloc for this proc
|
|
*
|
|
* Prints information about every buffer associated with
|
|
* the binder_alloc state to the given seq_file
|
|
*/
|
|
void binder_alloc_print_allocated(struct seq_file *m,
|
|
struct binder_alloc *alloc)
|
|
{
|
|
struct rb_node *n;
|
|
|
|
mutex_lock(&alloc->mutex);
|
|
for (n = rb_first(&alloc->allocated_buffers); n != NULL; n = rb_next(n))
|
|
print_binder_buffer(m, " buffer",
|
|
rb_entry(n, struct binder_buffer, rb_node));
|
|
mutex_unlock(&alloc->mutex);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_print_pages() - print page usage
|
|
* @m: seq_file for output via seq_printf()
|
|
* @alloc: binder_alloc for this proc
|
|
*/
|
|
void binder_alloc_print_pages(struct seq_file *m,
|
|
struct binder_alloc *alloc)
|
|
{
|
|
struct binder_lru_page *page;
|
|
int i;
|
|
int active = 0;
|
|
int lru = 0;
|
|
int free = 0;
|
|
|
|
mutex_lock(&alloc->mutex);
|
|
/*
|
|
* Make sure the binder_alloc is fully initialized, otherwise we might
|
|
* read inconsistent state.
|
|
*/
|
|
if (binder_alloc_get_vma(alloc) != NULL) {
|
|
for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {
|
|
page = &alloc->pages[i];
|
|
if (!page->page_ptr)
|
|
free++;
|
|
else if (list_empty(&page->lru))
|
|
active++;
|
|
else
|
|
lru++;
|
|
}
|
|
}
|
|
mutex_unlock(&alloc->mutex);
|
|
seq_printf(m, " pages: %d:%d:%d\n", active, lru, free);
|
|
seq_printf(m, " pages high watermark: %zu\n", alloc->pages_high);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_get_allocated_count() - return count of buffers
|
|
* @alloc: binder_alloc for this proc
|
|
*
|
|
* Return: count of allocated buffers
|
|
*/
|
|
int binder_alloc_get_allocated_count(struct binder_alloc *alloc)
|
|
{
|
|
struct rb_node *n;
|
|
int count = 0;
|
|
|
|
mutex_lock(&alloc->mutex);
|
|
for (n = rb_first(&alloc->allocated_buffers); n != NULL; n = rb_next(n))
|
|
count++;
|
|
mutex_unlock(&alloc->mutex);
|
|
return count;
|
|
}
|
|
|
|
|
|
/**
|
|
* binder_alloc_vma_close() - invalidate address space
|
|
* @alloc: binder_alloc for this proc
|
|
*
|
|
* Called from binder_vma_close() when releasing address space.
|
|
* Clears alloc->vma to prevent new incoming transactions from
|
|
* allocating more buffers.
|
|
*/
|
|
void binder_alloc_vma_close(struct binder_alloc *alloc)
|
|
{
|
|
binder_alloc_set_vma(alloc, NULL);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_free_page() - shrinker callback to free pages
|
|
* @item: item to free
|
|
* @lock: lock protecting the item
|
|
* @cb_arg: callback argument
|
|
*
|
|
* Called from list_lru_walk() in binder_shrink_scan() to free
|
|
* up pages when the system is under memory pressure.
|
|
*/
|
|
enum lru_status binder_alloc_free_page(struct list_head *item,
|
|
struct list_lru_one *lru,
|
|
spinlock_t *lock,
|
|
void *cb_arg)
|
|
__must_hold(lock)
|
|
{
|
|
struct mm_struct *mm = NULL;
|
|
struct binder_lru_page *page = container_of(item,
|
|
struct binder_lru_page,
|
|
lru);
|
|
struct binder_alloc *alloc;
|
|
uintptr_t page_addr;
|
|
size_t index;
|
|
struct vm_area_struct *vma;
|
|
|
|
alloc = page->alloc;
|
|
if (!mutex_trylock(&alloc->mutex))
|
|
goto err_get_alloc_mutex_failed;
|
|
|
|
if (!page->page_ptr)
|
|
goto err_page_already_freed;
|
|
|
|
index = page - alloc->pages;
|
|
page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE;
|
|
|
|
mm = alloc->mm;
|
|
if (!mmget_not_zero(mm))
|
|
goto err_mmget;
|
|
if (!mmap_read_trylock(mm))
|
|
goto err_mmap_read_lock_failed;
|
|
vma = vma_lookup(mm, page_addr);
|
|
if (vma && vma != binder_alloc_get_vma(alloc))
|
|
goto err_invalid_vma;
|
|
|
|
list_lru_isolate(lru, item);
|
|
spin_unlock(lock);
|
|
|
|
if (vma) {
|
|
trace_binder_unmap_user_start(alloc, index);
|
|
|
|
zap_page_range(vma, page_addr, PAGE_SIZE);
|
|
|
|
trace_binder_unmap_user_end(alloc, index);
|
|
}
|
|
mmap_read_unlock(mm);
|
|
mmput_async(mm);
|
|
|
|
trace_binder_unmap_kernel_start(alloc, index);
|
|
|
|
__free_page(page->page_ptr);
|
|
page->page_ptr = NULL;
|
|
|
|
trace_binder_unmap_kernel_end(alloc, index);
|
|
|
|
spin_lock(lock);
|
|
mutex_unlock(&alloc->mutex);
|
|
return LRU_REMOVED_RETRY;
|
|
|
|
err_invalid_vma:
|
|
mmap_read_unlock(mm);
|
|
err_mmap_read_lock_failed:
|
|
mmput_async(mm);
|
|
err_mmget:
|
|
err_page_already_freed:
|
|
mutex_unlock(&alloc->mutex);
|
|
err_get_alloc_mutex_failed:
|
|
return LRU_SKIP;
|
|
}
|
|
|
|
static unsigned long
|
|
binder_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
|
|
{
|
|
return list_lru_count(&binder_alloc_lru);
|
|
}
|
|
|
|
static unsigned long
|
|
binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
|
|
{
|
|
return list_lru_walk(&binder_alloc_lru, binder_alloc_free_page,
|
|
NULL, sc->nr_to_scan);
|
|
}
|
|
|
|
static struct shrinker binder_shrinker = {
|
|
.count_objects = binder_shrink_count,
|
|
.scan_objects = binder_shrink_scan,
|
|
.seeks = DEFAULT_SEEKS,
|
|
};
|
|
|
|
/**
|
|
* binder_alloc_init() - called by binder_open() for per-proc initialization
|
|
* @alloc: binder_alloc for this proc
|
|
*
|
|
* Called from binder_open() to initialize binder_alloc fields for
|
|
* new binder proc
|
|
*/
|
|
void binder_alloc_init(struct binder_alloc *alloc)
|
|
{
|
|
alloc->pid = current->group_leader->pid;
|
|
alloc->mm = current->mm;
|
|
mmgrab(alloc->mm);
|
|
mutex_init(&alloc->mutex);
|
|
INIT_LIST_HEAD(&alloc->buffers);
|
|
}
|
|
|
|
int binder_alloc_shrinker_init(void)
|
|
{
|
|
int ret = list_lru_init(&binder_alloc_lru);
|
|
|
|
if (ret == 0) {
|
|
ret = register_shrinker(&binder_shrinker, "android-binder");
|
|
if (ret)
|
|
list_lru_destroy(&binder_alloc_lru);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void binder_alloc_shrinker_exit(void)
|
|
{
|
|
unregister_shrinker(&binder_shrinker);
|
|
list_lru_destroy(&binder_alloc_lru);
|
|
}
|
|
|
|
/**
|
|
* check_buffer() - verify that buffer/offset is safe to access
|
|
* @alloc: binder_alloc for this proc
|
|
* @buffer: binder buffer to be accessed
|
|
* @offset: offset into @buffer data
|
|
* @bytes: bytes to access from offset
|
|
*
|
|
* Check that the @offset/@bytes are within the size of the given
|
|
* @buffer and that the buffer is currently active and not freeable.
|
|
* Offsets must also be multiples of sizeof(u32). The kernel is
|
|
* allowed to touch the buffer in two cases:
|
|
*
|
|
* 1) when the buffer is being created:
|
|
* (buffer->free == 0 && buffer->allow_user_free == 0)
|
|
* 2) when the buffer is being torn down:
|
|
* (buffer->free == 0 && buffer->transaction == NULL).
|
|
*
|
|
* Return: true if the buffer is safe to access
|
|
*/
|
|
static inline bool check_buffer(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t offset, size_t bytes)
|
|
{
|
|
size_t buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
|
|
return buffer_size >= bytes &&
|
|
offset <= buffer_size - bytes &&
|
|
IS_ALIGNED(offset, sizeof(u32)) &&
|
|
!buffer->free &&
|
|
(!buffer->allow_user_free || !buffer->transaction);
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_get_page() - get kernel pointer for given buffer offset
|
|
* @alloc: binder_alloc for this proc
|
|
* @buffer: binder buffer to be accessed
|
|
* @buffer_offset: offset into @buffer data
|
|
* @pgoffp: address to copy final page offset to
|
|
*
|
|
* Lookup the struct page corresponding to the address
|
|
* at @buffer_offset into @buffer->user_data. If @pgoffp is not
|
|
* NULL, the byte-offset into the page is written there.
|
|
*
|
|
* The caller is responsible to ensure that the offset points
|
|
* to a valid address within the @buffer and that @buffer is
|
|
* not freeable by the user. Since it can't be freed, we are
|
|
* guaranteed that the corresponding elements of @alloc->pages[]
|
|
* cannot change.
|
|
*
|
|
* Return: struct page
|
|
*/
|
|
static struct page *binder_alloc_get_page(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t buffer_offset,
|
|
pgoff_t *pgoffp)
|
|
{
|
|
binder_size_t buffer_space_offset = buffer_offset +
|
|
(buffer->user_data - alloc->buffer);
|
|
pgoff_t pgoff = buffer_space_offset & ~PAGE_MASK;
|
|
size_t index = buffer_space_offset >> PAGE_SHIFT;
|
|
struct binder_lru_page *lru_page;
|
|
|
|
lru_page = &alloc->pages[index];
|
|
*pgoffp = pgoff;
|
|
return lru_page->page_ptr;
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_clear_buf() - zero out buffer
|
|
* @alloc: binder_alloc for this proc
|
|
* @buffer: binder buffer to be cleared
|
|
*
|
|
* memset the given buffer to 0
|
|
*/
|
|
static void binder_alloc_clear_buf(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer)
|
|
{
|
|
size_t bytes = binder_alloc_buffer_size(alloc, buffer);
|
|
binder_size_t buffer_offset = 0;
|
|
|
|
while (bytes) {
|
|
unsigned long size;
|
|
struct page *page;
|
|
pgoff_t pgoff;
|
|
|
|
page = binder_alloc_get_page(alloc, buffer,
|
|
buffer_offset, &pgoff);
|
|
size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
|
|
memset_page(page, pgoff, 0, size);
|
|
bytes -= size;
|
|
buffer_offset += size;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* binder_alloc_copy_user_to_buffer() - copy src user to tgt user
|
|
* @alloc: binder_alloc for this proc
|
|
* @buffer: binder buffer to be accessed
|
|
* @buffer_offset: offset into @buffer data
|
|
* @from: userspace pointer to source buffer
|
|
* @bytes: bytes to copy
|
|
*
|
|
* Copy bytes from source userspace to target buffer.
|
|
*
|
|
* Return: bytes remaining to be copied
|
|
*/
|
|
unsigned long
|
|
binder_alloc_copy_user_to_buffer(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t buffer_offset,
|
|
const void __user *from,
|
|
size_t bytes)
|
|
{
|
|
if (!check_buffer(alloc, buffer, buffer_offset, bytes))
|
|
return bytes;
|
|
|
|
while (bytes) {
|
|
unsigned long size;
|
|
unsigned long ret;
|
|
struct page *page;
|
|
pgoff_t pgoff;
|
|
void *kptr;
|
|
|
|
page = binder_alloc_get_page(alloc, buffer,
|
|
buffer_offset, &pgoff);
|
|
size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
|
|
kptr = kmap_local_page(page) + pgoff;
|
|
ret = copy_from_user(kptr, from, size);
|
|
kunmap_local(kptr);
|
|
if (ret)
|
|
return bytes - size + ret;
|
|
bytes -= size;
|
|
from += size;
|
|
buffer_offset += size;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int binder_alloc_do_buffer_copy(struct binder_alloc *alloc,
|
|
bool to_buffer,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t buffer_offset,
|
|
void *ptr,
|
|
size_t bytes)
|
|
{
|
|
/* All copies must be 32-bit aligned and 32-bit size */
|
|
if (!check_buffer(alloc, buffer, buffer_offset, bytes))
|
|
return -EINVAL;
|
|
|
|
while (bytes) {
|
|
unsigned long size;
|
|
struct page *page;
|
|
pgoff_t pgoff;
|
|
|
|
page = binder_alloc_get_page(alloc, buffer,
|
|
buffer_offset, &pgoff);
|
|
size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
|
|
if (to_buffer)
|
|
memcpy_to_page(page, pgoff, ptr, size);
|
|
else
|
|
memcpy_from_page(ptr, page, pgoff, size);
|
|
bytes -= size;
|
|
pgoff = 0;
|
|
ptr = ptr + size;
|
|
buffer_offset += size;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int binder_alloc_copy_to_buffer(struct binder_alloc *alloc,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t buffer_offset,
|
|
void *src,
|
|
size_t bytes)
|
|
{
|
|
return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset,
|
|
src, bytes);
|
|
}
|
|
|
|
int binder_alloc_copy_from_buffer(struct binder_alloc *alloc,
|
|
void *dest,
|
|
struct binder_buffer *buffer,
|
|
binder_size_t buffer_offset,
|
|
size_t bytes)
|
|
{
|
|
return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset,
|
|
dest, bytes);
|
|
}
|
|
|