
Changes in 5.10.110 swiotlb: fix info leak with DMA_FROM_DEVICE USB: serial: pl2303: add IBM device IDs USB: serial: simple: add Nokia phone driver hv: utils: add PTP_1588_CLOCK to Kconfig to fix build netdevice: add the case if dev is NULL HID: logitech-dj: add new lightspeed receiver id 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 locking/lockdep: Avoid potential access of invalid memory in lock_class iommu/iova: Improve 32-bit free space estimate tpm: fix reference counting for struct tpm_chip virtio-blk: Use blk_validate_block_size() to validate block size 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: add Alder Lake N device id. mei: avoid iterator usage outside of list_for_each_entry coresight: Fix TRCCONFIGR.QE sysfs interface 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: uniphier: Fix fixed-rate initialization ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE KEYS: fix length validation in keyctl_pkey_params_get_2() Documentation: add link to stable release candidate tree Documentation: update stable tree link firmware: stratix10-svc: add missing callback parameter on RSU HID: intel-ish-hid: Use dma_alloc_coherent for firmware update SUNRPC: avoid race between mod_timer() and del_timer_sync() 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() pinctrl: samsung: drop pin banks references on error paths 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 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/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: 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: 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 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 integrity: set journal entry unused when shrinking device drbd: fix potential silent data corruption can: isotp: sanitize CAN ID checks in isotp_bind() powerpc/kvm: Fix kvm_use_magic_page udp: call udp_encap_enable for v6 sockets when enabling encap arm64: signal: nofpsimd: Do not allocate fp/simd context when not available 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 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 drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() 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 video: fbdev: sm712fb: Fix crash in smtcfb_read() video: fbdev: atari: Atari 2 bpp (STe) palette bugfix 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 DEC: Limit PMAX memory probing to R3k systems media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC media: davinci: vpif: fix unbalanced runtime PM get media: davinci: vpif: fix unbalanced runtime PM enable xtensa: fix stop_machine_cpuslocked call in patch_text xtensa: fix xtensa_wsr always writing 0 brcmfmac: firmware: Allocate space for default boardrev in nvram brcmfmac: pcie: Release firmwares in the brcmf_pcie_setup error path 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: 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: check return value of sel_make_avc_files 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 thermal: int340x: Check for NULL after calling kmemdup() spi: tegra114: Add missing IRQ check in tegra_spi_probe arm64/mm: avoid fixmap race condition when create pud mapping selftests/x86: Add validity check and allow field splitting 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 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 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: 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() 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() vfio: platform: simplify device removal amba: Make the remove callback return void 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: 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 rseq: Optimise rseq_get_rseq_cs() and clear_rseq_cs() 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 f2fs: fix missing free nid in f2fs_handle_failed_inode nfsd: more robust allocation failure handling in nfsd_file_cache_init f2fs: fix to avoid potential deadlock btrfs: fix unexpected error path when reflinking an inline extent f2fs: compress: remove unneeded read when rewrite whole cluster f2fs: fix compressed file start atomic write may cause data corruption selftests, x86: fix how check_cc.sh is being invoked kunit: make kunit_test_timeout compatible with comment media: staging: media: zoran: fix usage of vb2_dma_contig_set_max_seg_size media: v4l2-mem2mem: Apply DST_QUEUE_OFF_BASE on MMAP buffers across ioctls media: mtk-vcodec: potential dereference of null pointer media: bttv: fix WARNING regression on tunerless devices ASoC: xilinx: xlnx_formatter_pcm: Handle sysclk setting ASoC: generic: simple-card-utils: remove useless assignment 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: 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 set but not used warnings 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() 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: sm8150: 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 ARM: dts: imx: Add missing LVDS decoder on M53Menlo media: video/hdmi: handle short reads of hdmi info frame. 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: wcd934x: fix return value of wcd934x_rx_hph_mode_put uaccess: fix nios2 and microblaze get_user_8() ASoC: rt5663: check the return value of devm_kzalloc() in rt5663_parse_dp() 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: convert list_for_each to entry variant media: saa7134: fix incorrect use to determine if list is empty ivtv: fix incorrect device_caps for ivtvfb ASoC: rockchip: i2s: Use devm_platform_get_and_ioremap_resource() ASoC: rockchip: i2s: Fix missing clk_disable_unprepare() in rockchip_i2s_probe ASoC: SOF: Add missing of_node_put() in imx8m_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: msm8916-wcd-digital: Fix missing clk_disable_unprepare() in msm8916_wcd_digital_probe mmc: davinci_mmc: Handle error for clk_enable ASoC: atmel: sam9x5_wm8731: use devm_snd_soc_register_card() 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 ARM: configs: multi_v5_defconfig: re-enable CONFIG_V4L_PLATFORM_DRIVERS drm/meson: osd_afbcd: Add an exit callback to struct meson_afbcd_ops 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/panfrost: Check for error num after setting mask libbpf: Fix possible NULL pointer dereference when destroying skeleton udmabuf: validate ubuf->pagecount 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 ionic: fix type complaint in ionic_dev_cmd_clean() 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 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 i40e: don't reserve excessive XDP_PACKET_HEADROOM on XSK Rx to skb i40e: 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: 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: mt7603: check sta_rates pointer in mt7603_sta_rate_tbl_update mt76: mt7615: check sta_rates pointer in mt7615_sta_rate_tbl_update net: dsa: mv88e6xxx: Enable port policy support on 6097 scripts/dtc: Call pkg-config POSIXly correct livepatch: Fix build failure on 32 bits processors PCI: aardvark: Fix reading PCI_EXP_RTSTA_PME bit on emulated bridge drm/bridge: dw-hdmi: use safe format when first in bridge chain 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/amd/pm: enable pm sysfs write for one VF mode drm/amd/display: Add affected crtcs to atomic state for dsc mst unplug IB/cma: Allow XRC INI QPs to set their local ACK timeout dax: make sure inodes are flushed before destroy cache iwlwifi: Fix -EIO error code that is never returned iwlwifi: mvm: Fix an error code in iwl_mvm_up() drm/msm/dp: populate connector of struct dp_panel 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 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 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 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 PCI: Reduce warnings on possible RW1C corruption net: axienet: fix RX ring refill allocation failure handling mips: DEC: honor CONFIG_MIPS_FP_SUPPORT=n powerpc/sysdev: fix incorrect use to determine if list is empty 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() 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 RDMA/mlx5: Fix memory leak in error flow for subscribe event routine 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() 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 selftests/bpf: Fix error reporting from sock_fields programs 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 i2c: mux: demux-pinctrl: do not deactivate a master that is not active 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 tipc: fix the timer expires after interval 100ms mfd: asic3: Add missing iounmap() on error asic3_mfd_probe mxser: fix xmit_buf leak in activate when LSR == 0xff pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() fsi: aspeed: convert to devm_platform_ioremap_resource 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 iio: mma8452: Fix probe failing when an i2c_device_id is used 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}) 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() dma-debug: fix return value of __setup handlers clk: imx7d: Remove audio_mclk_root_clk 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: clps711x: Terminate clk_div_table with sentinel element clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver 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: 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 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 NFSv4.1: don't retry BIND_CONN_TO_SESSION on session error kdb: Fix the putarea helper function clk: qcom: gcc-msm8994: Fix gpll4 width 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: phy: broadcom: Fix brcm_fet_config_init() selftests: test_vxlan_under_vrf: Fix broken test case qlcnic: dcb: default to returning -EOPNOTSUPP net/x25: Fix null-ptr-deref caused by x25_disconnect 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 gcc-plugins/stackleak: Exactly match strings instead of prefixes pinctrl: npcm: Fix broken references to chip->parent_device block, bfq: don't move oom_bfqq selinux: use correct type for context length 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() 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 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: compress: fix to print raw data size in error path of lz4 decompression 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: ir_toy: free before error exiting 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: 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 video: fbdev: sm712fb: Fix crash in smtcfb_write() media: Revert "media: em28xx: add missing em28xx_close_extension" media: hdpvr: initialize dev->worker at hdpvr_register_videodev 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/mmu: Check for present SPTE when clearing dirty bit in TDP MMU powerpc/kasan: Fix early region not updated correctly powerpc/lib/sstep: Fix 'sthcx' instruction powerpc/lib/sstep: Fix build errors with newer binutils powerpc: Fix build errors with newer binutils scsi: qla2xxx: Fix stuck session in gpdb scsi: qla2xxx: Fix scheduling while atomic 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: 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: Reduce false trigger to login scsi: qla2xxx: Use correct feature type field during RFF_ID processing platform: chrome: Split trace include file 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 ASoC: SOF: Intel: Fix NULL ptr dereference when ENOMEM 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: 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 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() rtc: check if __rtc_read_time was successful gfs2: Make sure FITRIM minlen is rounded up to fs block size net: hns3: fix software vlan talbe of vlan 0 inconsistent with hardware 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 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 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 platform/chrome: cros_ec_typec: Check for EC device can: isotp: restore accidentally removed MSG_PEEK feature proc: bootconfig: Add null pointer check staging: mt7621-dts: fix pinctrl-0 items to be size-1 items on ethernet ASoC: soc-compress: Change the check for codec_dai batman-adv: Check ptr for NULL before reducing its refcnt 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 bpf: Adjust BPF stack helper functions to accommodate skip > 0 bpf: Fix comment for helper bpf_current_task_under_cgroup() 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 ubi: fastmap: Return error code if memory allocation fails in add_aeb() ASoC: topology: Allow TLV control to be either read or write ARM: dts: spear1340: Update serial node properties ARM: dts: spear13xx: Update SPI 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. KVM: x86/mmu: do compare-and-exchange of gPTE via the user address 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 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 arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones PCI: xgene: Revert "PCI: xgene: Use inbound resources for setup" Linux 5.10.110 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I12fbe227793dd40c0582588e1700cf88cafd0ac6
1344 lines
30 KiB
C
1344 lines
30 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* kernel/power/hibernate.c - Hibernation (a.k.a suspend-to-disk) support.
|
|
*
|
|
* Copyright (c) 2003 Patrick Mochel
|
|
* Copyright (c) 2003 Open Source Development Lab
|
|
* Copyright (c) 2004 Pavel Machek <pavel@ucw.cz>
|
|
* Copyright (c) 2009 Rafael J. Wysocki, Novell Inc.
|
|
* Copyright (C) 2012 Bojan Smojver <bojan@rexursive.com>
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "PM: hibernation: " fmt
|
|
|
|
#include <linux/export.h>
|
|
#include <linux/suspend.h>
|
|
#include <linux/reboot.h>
|
|
#include <linux/string.h>
|
|
#include <linux/device.h>
|
|
#include <linux/async.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/nmi.h>
|
|
#include <linux/console.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/syscore_ops.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/genhd.h>
|
|
#include <linux/ktime.h>
|
|
#include <linux/security.h>
|
|
#include <trace/events/power.h>
|
|
|
|
#include "power.h"
|
|
|
|
|
|
static int nocompress;
|
|
static int noresume;
|
|
static int nohibernate;
|
|
static int resume_wait;
|
|
static unsigned int resume_delay;
|
|
static char resume_file[256] = CONFIG_PM_STD_PARTITION;
|
|
dev_t swsusp_resume_device;
|
|
sector_t swsusp_resume_block;
|
|
__visible int in_suspend __nosavedata;
|
|
|
|
enum {
|
|
HIBERNATION_INVALID,
|
|
HIBERNATION_PLATFORM,
|
|
HIBERNATION_SHUTDOWN,
|
|
HIBERNATION_REBOOT,
|
|
#ifdef CONFIG_SUSPEND
|
|
HIBERNATION_SUSPEND,
|
|
#endif
|
|
HIBERNATION_TEST_RESUME,
|
|
/* keep last */
|
|
__HIBERNATION_AFTER_LAST
|
|
};
|
|
#define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
|
|
#define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
|
|
|
|
static int hibernation_mode = HIBERNATION_SHUTDOWN;
|
|
|
|
bool freezer_test_done;
|
|
|
|
static const struct platform_hibernation_ops *hibernation_ops;
|
|
|
|
static atomic_t hibernate_atomic = ATOMIC_INIT(1);
|
|
|
|
bool hibernate_acquire(void)
|
|
{
|
|
return atomic_add_unless(&hibernate_atomic, -1, 0);
|
|
}
|
|
|
|
void hibernate_release(void)
|
|
{
|
|
atomic_inc(&hibernate_atomic);
|
|
}
|
|
|
|
bool hibernation_available(void)
|
|
{
|
|
return nohibernate == 0 && !security_locked_down(LOCKDOWN_HIBERNATION);
|
|
}
|
|
|
|
/**
|
|
* hibernation_set_ops - Set the global hibernate operations.
|
|
* @ops: Hibernation operations to use in subsequent hibernation transitions.
|
|
*/
|
|
void hibernation_set_ops(const struct platform_hibernation_ops *ops)
|
|
{
|
|
if (ops && !(ops->begin && ops->end && ops->pre_snapshot
|
|
&& ops->prepare && ops->finish && ops->enter && ops->pre_restore
|
|
&& ops->restore_cleanup && ops->leave)) {
|
|
WARN_ON(1);
|
|
return;
|
|
}
|
|
lock_system_sleep();
|
|
hibernation_ops = ops;
|
|
if (ops)
|
|
hibernation_mode = HIBERNATION_PLATFORM;
|
|
else if (hibernation_mode == HIBERNATION_PLATFORM)
|
|
hibernation_mode = HIBERNATION_SHUTDOWN;
|
|
|
|
unlock_system_sleep();
|
|
}
|
|
EXPORT_SYMBOL_GPL(hibernation_set_ops);
|
|
|
|
static bool entering_platform_hibernation;
|
|
|
|
bool system_entering_hibernation(void)
|
|
{
|
|
return entering_platform_hibernation;
|
|
}
|
|
EXPORT_SYMBOL(system_entering_hibernation);
|
|
|
|
#ifdef CONFIG_PM_DEBUG
|
|
static void hibernation_debug_sleep(void)
|
|
{
|
|
pr_info("debug: Waiting for 5 seconds.\n");
|
|
mdelay(5000);
|
|
}
|
|
|
|
static int hibernation_test(int level)
|
|
{
|
|
if (pm_test_level == level) {
|
|
hibernation_debug_sleep();
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
#else /* !CONFIG_PM_DEBUG */
|
|
static int hibernation_test(int level) { return 0; }
|
|
#endif /* !CONFIG_PM_DEBUG */
|
|
|
|
/**
|
|
* platform_begin - Call platform to start hibernation.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*/
|
|
static int platform_begin(int platform_mode)
|
|
{
|
|
return (platform_mode && hibernation_ops) ?
|
|
hibernation_ops->begin(PMSG_FREEZE) : 0;
|
|
}
|
|
|
|
/**
|
|
* platform_end - Call platform to finish transition to the working state.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*/
|
|
static void platform_end(int platform_mode)
|
|
{
|
|
if (platform_mode && hibernation_ops)
|
|
hibernation_ops->end();
|
|
}
|
|
|
|
/**
|
|
* platform_pre_snapshot - Call platform to prepare the machine for hibernation.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Use the platform driver to prepare the system for creating a hibernate image,
|
|
* if so configured, and return an error code if that fails.
|
|
*/
|
|
|
|
static int platform_pre_snapshot(int platform_mode)
|
|
{
|
|
return (platform_mode && hibernation_ops) ?
|
|
hibernation_ops->pre_snapshot() : 0;
|
|
}
|
|
|
|
/**
|
|
* platform_leave - Call platform to prepare a transition to the working state.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Use the platform driver prepare to prepare the machine for switching to the
|
|
* normal mode of operation.
|
|
*
|
|
* This routine is called on one CPU with interrupts disabled.
|
|
*/
|
|
static void platform_leave(int platform_mode)
|
|
{
|
|
if (platform_mode && hibernation_ops)
|
|
hibernation_ops->leave();
|
|
}
|
|
|
|
/**
|
|
* platform_finish - Call platform to switch the system to the working state.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Use the platform driver to switch the machine to the normal mode of
|
|
* operation.
|
|
*
|
|
* This routine must be called after platform_prepare().
|
|
*/
|
|
static void platform_finish(int platform_mode)
|
|
{
|
|
if (platform_mode && hibernation_ops)
|
|
hibernation_ops->finish();
|
|
}
|
|
|
|
/**
|
|
* platform_pre_restore - Prepare for hibernate image restoration.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Use the platform driver to prepare the system for resume from a hibernation
|
|
* image.
|
|
*
|
|
* If the restore fails after this function has been called,
|
|
* platform_restore_cleanup() must be called.
|
|
*/
|
|
static int platform_pre_restore(int platform_mode)
|
|
{
|
|
return (platform_mode && hibernation_ops) ?
|
|
hibernation_ops->pre_restore() : 0;
|
|
}
|
|
|
|
/**
|
|
* platform_restore_cleanup - Switch to the working state after failing restore.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Use the platform driver to switch the system to the normal mode of operation
|
|
* after a failing restore.
|
|
*
|
|
* If platform_pre_restore() has been called before the failing restore, this
|
|
* function must be called too, regardless of the result of
|
|
* platform_pre_restore().
|
|
*/
|
|
static void platform_restore_cleanup(int platform_mode)
|
|
{
|
|
if (platform_mode && hibernation_ops)
|
|
hibernation_ops->restore_cleanup();
|
|
}
|
|
|
|
/**
|
|
* platform_recover - Recover from a failure to suspend devices.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*/
|
|
static void platform_recover(int platform_mode)
|
|
{
|
|
if (platform_mode && hibernation_ops && hibernation_ops->recover)
|
|
hibernation_ops->recover();
|
|
}
|
|
|
|
/**
|
|
* swsusp_show_speed - Print time elapsed between two events during hibernation.
|
|
* @start: Starting event.
|
|
* @stop: Final event.
|
|
* @nr_pages: Number of memory pages processed between @start and @stop.
|
|
* @msg: Additional diagnostic message to print.
|
|
*/
|
|
void swsusp_show_speed(ktime_t start, ktime_t stop,
|
|
unsigned nr_pages, char *msg)
|
|
{
|
|
ktime_t diff;
|
|
u64 elapsed_centisecs64;
|
|
unsigned int centisecs;
|
|
unsigned int k;
|
|
unsigned int kps;
|
|
|
|
diff = ktime_sub(stop, start);
|
|
elapsed_centisecs64 = ktime_divns(diff, 10*NSEC_PER_MSEC);
|
|
centisecs = elapsed_centisecs64;
|
|
if (centisecs == 0)
|
|
centisecs = 1; /* avoid div-by-zero */
|
|
k = nr_pages * (PAGE_SIZE / 1024);
|
|
kps = (k * 100) / centisecs;
|
|
pr_info("%s %u kbytes in %u.%02u seconds (%u.%02u MB/s)\n",
|
|
msg, k, centisecs / 100, centisecs % 100, kps / 1000,
|
|
(kps % 1000) / 10);
|
|
}
|
|
|
|
__weak int arch_resume_nosmt(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* create_image - Create a hibernation image.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Execute device drivers' "late" and "noirq" freeze callbacks, create a
|
|
* hibernation image and run the drivers' "noirq" and "early" thaw callbacks.
|
|
*
|
|
* Control reappears in this routine after the subsequent restore.
|
|
*/
|
|
static int create_image(int platform_mode)
|
|
{
|
|
int error;
|
|
|
|
error = dpm_suspend_end(PMSG_FREEZE);
|
|
if (error) {
|
|
pr_err("Some devices failed to power down, aborting\n");
|
|
return error;
|
|
}
|
|
|
|
error = platform_pre_snapshot(platform_mode);
|
|
if (error || hibernation_test(TEST_PLATFORM))
|
|
goto Platform_finish;
|
|
|
|
error = suspend_disable_secondary_cpus();
|
|
if (error || hibernation_test(TEST_CPUS))
|
|
goto Enable_cpus;
|
|
|
|
local_irq_disable();
|
|
|
|
system_state = SYSTEM_SUSPEND;
|
|
|
|
error = syscore_suspend();
|
|
if (error) {
|
|
pr_err("Some system devices failed to power down, aborting\n");
|
|
goto Enable_irqs;
|
|
}
|
|
|
|
if (hibernation_test(TEST_CORE) || pm_wakeup_pending())
|
|
goto Power_up;
|
|
|
|
in_suspend = 1;
|
|
save_processor_state();
|
|
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, true);
|
|
error = swsusp_arch_suspend();
|
|
/* Restore control flow magically appears here */
|
|
restore_processor_state();
|
|
trace_suspend_resume(TPS("machine_suspend"), PM_EVENT_HIBERNATE, false);
|
|
if (error)
|
|
pr_err("Error %d creating image\n", error);
|
|
|
|
if (!in_suspend) {
|
|
events_check_enabled = false;
|
|
clear_or_poison_free_pages();
|
|
}
|
|
|
|
platform_leave(platform_mode);
|
|
|
|
Power_up:
|
|
syscore_resume();
|
|
|
|
Enable_irqs:
|
|
system_state = SYSTEM_RUNNING;
|
|
local_irq_enable();
|
|
|
|
Enable_cpus:
|
|
suspend_enable_secondary_cpus();
|
|
|
|
/* Allow architectures to do nosmt-specific post-resume dances */
|
|
if (!in_suspend)
|
|
error = arch_resume_nosmt();
|
|
|
|
Platform_finish:
|
|
platform_finish(platform_mode);
|
|
|
|
dpm_resume_start(in_suspend ?
|
|
(error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
|
|
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* hibernation_snapshot - Quiesce devices and create a hibernation image.
|
|
* @platform_mode: If set, use platform driver to prepare for the transition.
|
|
*
|
|
* This routine must be called with system_transition_mutex held.
|
|
*/
|
|
int hibernation_snapshot(int platform_mode)
|
|
{
|
|
pm_message_t msg;
|
|
int error;
|
|
|
|
pm_suspend_clear_flags();
|
|
error = platform_begin(platform_mode);
|
|
if (error)
|
|
goto Close;
|
|
|
|
/* Preallocate image memory before shutting down devices. */
|
|
error = hibernate_preallocate_memory();
|
|
if (error)
|
|
goto Close;
|
|
|
|
error = freeze_kernel_threads();
|
|
if (error)
|
|
goto Cleanup;
|
|
|
|
if (hibernation_test(TEST_FREEZER)) {
|
|
|
|
/*
|
|
* Indicate to the caller that we are returning due to a
|
|
* successful freezer test.
|
|
*/
|
|
freezer_test_done = true;
|
|
goto Thaw;
|
|
}
|
|
|
|
error = dpm_prepare(PMSG_FREEZE);
|
|
if (error) {
|
|
dpm_complete(PMSG_RECOVER);
|
|
goto Thaw;
|
|
}
|
|
|
|
suspend_console();
|
|
pm_restrict_gfp_mask();
|
|
|
|
error = dpm_suspend(PMSG_FREEZE);
|
|
|
|
if (error || hibernation_test(TEST_DEVICES))
|
|
platform_recover(platform_mode);
|
|
else
|
|
error = create_image(platform_mode);
|
|
|
|
/*
|
|
* In the case that we call create_image() above, the control
|
|
* returns here (1) after the image has been created or the
|
|
* image creation has failed and (2) after a successful restore.
|
|
*/
|
|
|
|
/* We may need to release the preallocated image pages here. */
|
|
if (error || !in_suspend)
|
|
swsusp_free();
|
|
|
|
msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
|
|
dpm_resume(msg);
|
|
|
|
if (error || !in_suspend)
|
|
pm_restore_gfp_mask();
|
|
|
|
resume_console();
|
|
dpm_complete(msg);
|
|
|
|
Close:
|
|
platform_end(platform_mode);
|
|
return error;
|
|
|
|
Thaw:
|
|
thaw_kernel_threads();
|
|
Cleanup:
|
|
swsusp_free();
|
|
goto Close;
|
|
}
|
|
|
|
int __weak hibernate_resume_nonboot_cpu_disable(void)
|
|
{
|
|
return suspend_disable_secondary_cpus();
|
|
}
|
|
|
|
/**
|
|
* resume_target_kernel - Restore system state from a hibernation image.
|
|
* @platform_mode: Whether or not to use the platform driver.
|
|
*
|
|
* Execute device drivers' "noirq" and "late" freeze callbacks, restore the
|
|
* contents of highmem that have not been restored yet from the image and run
|
|
* the low-level code that will restore the remaining contents of memory and
|
|
* switch to the just restored target kernel.
|
|
*/
|
|
static int resume_target_kernel(bool platform_mode)
|
|
{
|
|
int error;
|
|
|
|
error = dpm_suspend_end(PMSG_QUIESCE);
|
|
if (error) {
|
|
pr_err("Some devices failed to power down, aborting resume\n");
|
|
return error;
|
|
}
|
|
|
|
error = platform_pre_restore(platform_mode);
|
|
if (error)
|
|
goto Cleanup;
|
|
|
|
error = hibernate_resume_nonboot_cpu_disable();
|
|
if (error)
|
|
goto Enable_cpus;
|
|
|
|
local_irq_disable();
|
|
system_state = SYSTEM_SUSPEND;
|
|
|
|
error = syscore_suspend();
|
|
if (error)
|
|
goto Enable_irqs;
|
|
|
|
save_processor_state();
|
|
error = restore_highmem();
|
|
if (!error) {
|
|
error = swsusp_arch_resume();
|
|
/*
|
|
* The code below is only ever reached in case of a failure.
|
|
* Otherwise, execution continues at the place where
|
|
* swsusp_arch_suspend() was called.
|
|
*/
|
|
BUG_ON(!error);
|
|
/*
|
|
* This call to restore_highmem() reverts the changes made by
|
|
* the previous one.
|
|
*/
|
|
restore_highmem();
|
|
}
|
|
/*
|
|
* The only reason why swsusp_arch_resume() can fail is memory being
|
|
* very tight, so we have to free it as soon as we can to avoid
|
|
* subsequent failures.
|
|
*/
|
|
swsusp_free();
|
|
restore_processor_state();
|
|
touch_softlockup_watchdog();
|
|
|
|
syscore_resume();
|
|
|
|
Enable_irqs:
|
|
system_state = SYSTEM_RUNNING;
|
|
local_irq_enable();
|
|
|
|
Enable_cpus:
|
|
suspend_enable_secondary_cpus();
|
|
|
|
Cleanup:
|
|
platform_restore_cleanup(platform_mode);
|
|
|
|
dpm_resume_start(PMSG_RECOVER);
|
|
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* hibernation_restore - Quiesce devices and restore from a hibernation image.
|
|
* @platform_mode: If set, use platform driver to prepare for the transition.
|
|
*
|
|
* This routine must be called with system_transition_mutex held. If it is
|
|
* successful, control reappears in the restored target kernel in
|
|
* hibernation_snapshot().
|
|
*/
|
|
int hibernation_restore(int platform_mode)
|
|
{
|
|
int error;
|
|
|
|
pm_prepare_console();
|
|
suspend_console();
|
|
pm_restrict_gfp_mask();
|
|
error = dpm_suspend_start(PMSG_QUIESCE);
|
|
if (!error) {
|
|
error = resume_target_kernel(platform_mode);
|
|
/*
|
|
* The above should either succeed and jump to the new kernel,
|
|
* or return with an error. Otherwise things are just
|
|
* undefined, so let's be paranoid.
|
|
*/
|
|
BUG_ON(!error);
|
|
}
|
|
dpm_resume_end(PMSG_RECOVER);
|
|
pm_restore_gfp_mask();
|
|
resume_console();
|
|
pm_restore_console();
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* hibernation_platform_enter - Power off the system using the platform driver.
|
|
*/
|
|
int hibernation_platform_enter(void)
|
|
{
|
|
int error;
|
|
|
|
if (!hibernation_ops)
|
|
return -ENOSYS;
|
|
|
|
/*
|
|
* We have cancelled the power transition by running
|
|
* hibernation_ops->finish() before saving the image, so we should let
|
|
* the firmware know that we're going to enter the sleep state after all
|
|
*/
|
|
error = hibernation_ops->begin(PMSG_HIBERNATE);
|
|
if (error)
|
|
goto Close;
|
|
|
|
entering_platform_hibernation = true;
|
|
suspend_console();
|
|
error = dpm_suspend_start(PMSG_HIBERNATE);
|
|
if (error) {
|
|
if (hibernation_ops->recover)
|
|
hibernation_ops->recover();
|
|
goto Resume_devices;
|
|
}
|
|
|
|
error = dpm_suspend_end(PMSG_HIBERNATE);
|
|
if (error)
|
|
goto Resume_devices;
|
|
|
|
error = hibernation_ops->prepare();
|
|
if (error)
|
|
goto Platform_finish;
|
|
|
|
error = suspend_disable_secondary_cpus();
|
|
if (error)
|
|
goto Enable_cpus;
|
|
|
|
local_irq_disable();
|
|
system_state = SYSTEM_SUSPEND;
|
|
syscore_suspend();
|
|
if (pm_wakeup_pending()) {
|
|
error = -EAGAIN;
|
|
goto Power_up;
|
|
}
|
|
|
|
hibernation_ops->enter();
|
|
/* We should never get here */
|
|
while (1);
|
|
|
|
Power_up:
|
|
syscore_resume();
|
|
system_state = SYSTEM_RUNNING;
|
|
local_irq_enable();
|
|
|
|
Enable_cpus:
|
|
suspend_enable_secondary_cpus();
|
|
|
|
Platform_finish:
|
|
hibernation_ops->finish();
|
|
|
|
dpm_resume_start(PMSG_RESTORE);
|
|
|
|
Resume_devices:
|
|
entering_platform_hibernation = false;
|
|
dpm_resume_end(PMSG_RESTORE);
|
|
resume_console();
|
|
|
|
Close:
|
|
hibernation_ops->end();
|
|
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* power_down - Shut the machine down for hibernation.
|
|
*
|
|
* Use the platform driver, if configured, to put the system into the sleep
|
|
* state corresponding to hibernation, or try to power it off or reboot,
|
|
* depending on the value of hibernation_mode.
|
|
*/
|
|
static void power_down(void)
|
|
{
|
|
#ifdef CONFIG_SUSPEND
|
|
int error;
|
|
|
|
if (hibernation_mode == HIBERNATION_SUSPEND) {
|
|
error = suspend_devices_and_enter(PM_SUSPEND_MEM);
|
|
if (error) {
|
|
hibernation_mode = hibernation_ops ?
|
|
HIBERNATION_PLATFORM :
|
|
HIBERNATION_SHUTDOWN;
|
|
} else {
|
|
/* Restore swap signature. */
|
|
error = swsusp_unmark();
|
|
if (error)
|
|
pr_err("Swap will be unusable! Try swapon -a.\n");
|
|
|
|
return;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
switch (hibernation_mode) {
|
|
case HIBERNATION_REBOOT:
|
|
kernel_restart(NULL);
|
|
break;
|
|
case HIBERNATION_PLATFORM:
|
|
hibernation_platform_enter();
|
|
fallthrough;
|
|
case HIBERNATION_SHUTDOWN:
|
|
if (pm_power_off)
|
|
kernel_power_off();
|
|
break;
|
|
}
|
|
kernel_halt();
|
|
/*
|
|
* Valid image is on the disk, if we continue we risk serious data
|
|
* corruption after resume.
|
|
*/
|
|
pr_crit("Power down manually\n");
|
|
while (1)
|
|
cpu_relax();
|
|
}
|
|
|
|
static int load_image_and_restore(void)
|
|
{
|
|
int error;
|
|
unsigned int flags;
|
|
|
|
pm_pr_dbg("Loading hibernation image.\n");
|
|
|
|
lock_device_hotplug();
|
|
error = create_basic_memory_bitmaps();
|
|
if (error)
|
|
goto Unlock;
|
|
|
|
error = swsusp_read(&flags);
|
|
swsusp_close(FMODE_READ | FMODE_EXCL);
|
|
if (!error)
|
|
error = hibernation_restore(flags & SF_PLATFORM_MODE);
|
|
|
|
pr_err("Failed to load image, recovering.\n");
|
|
swsusp_free();
|
|
free_basic_memory_bitmaps();
|
|
Unlock:
|
|
unlock_device_hotplug();
|
|
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* hibernate - Carry out system hibernation, including saving the image.
|
|
*/
|
|
int hibernate(void)
|
|
{
|
|
bool snapshot_test = false;
|
|
int error;
|
|
|
|
if (!hibernation_available()) {
|
|
pm_pr_dbg("Hibernation not available.\n");
|
|
return -EPERM;
|
|
}
|
|
|
|
lock_system_sleep();
|
|
/* The snapshot device should not be opened while we're running */
|
|
if (!hibernate_acquire()) {
|
|
error = -EBUSY;
|
|
goto Unlock;
|
|
}
|
|
|
|
pr_info("hibernation entry\n");
|
|
pm_prepare_console();
|
|
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
|
|
if (error)
|
|
goto Restore;
|
|
|
|
ksys_sync_helper();
|
|
|
|
error = freeze_processes();
|
|
if (error)
|
|
goto Exit;
|
|
|
|
lock_device_hotplug();
|
|
/* Allocate memory management structures */
|
|
error = create_basic_memory_bitmaps();
|
|
if (error)
|
|
goto Thaw;
|
|
|
|
error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
|
|
if (error || freezer_test_done)
|
|
goto Free_bitmaps;
|
|
|
|
if (in_suspend) {
|
|
unsigned int flags = 0;
|
|
|
|
if (hibernation_mode == HIBERNATION_PLATFORM)
|
|
flags |= SF_PLATFORM_MODE;
|
|
if (nocompress)
|
|
flags |= SF_NOCOMPRESS_MODE;
|
|
else
|
|
flags |= SF_CRC32_MODE;
|
|
|
|
pm_pr_dbg("Writing hibernation image.\n");
|
|
error = swsusp_write(flags);
|
|
swsusp_free();
|
|
if (!error) {
|
|
if (hibernation_mode == HIBERNATION_TEST_RESUME)
|
|
snapshot_test = true;
|
|
else
|
|
power_down();
|
|
}
|
|
in_suspend = 0;
|
|
pm_restore_gfp_mask();
|
|
} else {
|
|
pm_pr_dbg("Hibernation image restored successfully.\n");
|
|
}
|
|
|
|
Free_bitmaps:
|
|
free_basic_memory_bitmaps();
|
|
Thaw:
|
|
unlock_device_hotplug();
|
|
if (snapshot_test) {
|
|
pm_pr_dbg("Checking hibernation image\n");
|
|
error = swsusp_check();
|
|
if (!error)
|
|
error = load_image_and_restore();
|
|
}
|
|
thaw_processes();
|
|
|
|
/* Don't bother checking whether freezer_test_done is true */
|
|
freezer_test_done = false;
|
|
Exit:
|
|
pm_notifier_call_chain(PM_POST_HIBERNATION);
|
|
Restore:
|
|
pm_restore_console();
|
|
hibernate_release();
|
|
Unlock:
|
|
unlock_system_sleep();
|
|
pr_info("hibernation exit\n");
|
|
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* hibernate_quiet_exec - Execute a function with all devices frozen.
|
|
* @func: Function to execute.
|
|
* @data: Data pointer to pass to @func.
|
|
*
|
|
* Return the @func return value or an error code if it cannot be executed.
|
|
*/
|
|
int hibernate_quiet_exec(int (*func)(void *data), void *data)
|
|
{
|
|
int error;
|
|
|
|
lock_system_sleep();
|
|
|
|
if (!hibernate_acquire()) {
|
|
error = -EBUSY;
|
|
goto unlock;
|
|
}
|
|
|
|
pm_prepare_console();
|
|
|
|
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
|
|
if (error)
|
|
goto restore;
|
|
|
|
error = freeze_processes();
|
|
if (error)
|
|
goto exit;
|
|
|
|
lock_device_hotplug();
|
|
|
|
pm_suspend_clear_flags();
|
|
|
|
error = platform_begin(true);
|
|
if (error)
|
|
goto thaw;
|
|
|
|
error = freeze_kernel_threads();
|
|
if (error)
|
|
goto thaw;
|
|
|
|
error = dpm_prepare(PMSG_FREEZE);
|
|
if (error)
|
|
goto dpm_complete;
|
|
|
|
suspend_console();
|
|
|
|
error = dpm_suspend(PMSG_FREEZE);
|
|
if (error)
|
|
goto dpm_resume;
|
|
|
|
error = dpm_suspend_end(PMSG_FREEZE);
|
|
if (error)
|
|
goto dpm_resume;
|
|
|
|
error = platform_pre_snapshot(true);
|
|
if (error)
|
|
goto skip;
|
|
|
|
error = func(data);
|
|
|
|
skip:
|
|
platform_finish(true);
|
|
|
|
dpm_resume_start(PMSG_THAW);
|
|
|
|
dpm_resume:
|
|
dpm_resume(PMSG_THAW);
|
|
|
|
resume_console();
|
|
|
|
dpm_complete:
|
|
dpm_complete(PMSG_THAW);
|
|
|
|
thaw_kernel_threads();
|
|
|
|
thaw:
|
|
platform_end(true);
|
|
|
|
unlock_device_hotplug();
|
|
|
|
thaw_processes();
|
|
|
|
exit:
|
|
pm_notifier_call_chain(PM_POST_HIBERNATION);
|
|
|
|
restore:
|
|
pm_restore_console();
|
|
|
|
hibernate_release();
|
|
|
|
unlock:
|
|
unlock_system_sleep();
|
|
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(hibernate_quiet_exec);
|
|
|
|
/**
|
|
* software_resume - Resume from a saved hibernation image.
|
|
*
|
|
* This routine is called as a late initcall, when all devices have been
|
|
* discovered and initialized already.
|
|
*
|
|
* The image reading code is called to see if there is a hibernation image
|
|
* available for reading. If that is the case, devices are quiesced and the
|
|
* contents of memory is restored from the saved image.
|
|
*
|
|
* If this is successful, control reappears in the restored target kernel in
|
|
* hibernation_snapshot() which returns to hibernate(). Otherwise, the routine
|
|
* attempts to recover gracefully and make the kernel return to the normal mode
|
|
* of operation.
|
|
*/
|
|
static int software_resume(void)
|
|
{
|
|
int error;
|
|
|
|
/*
|
|
* If the user said "noresume".. bail out early.
|
|
*/
|
|
if (noresume || !hibernation_available())
|
|
return 0;
|
|
|
|
/*
|
|
* name_to_dev_t() below takes a sysfs buffer mutex when sysfs
|
|
* is configured into the kernel. Since the regular hibernate
|
|
* trigger path is via sysfs which takes a buffer mutex before
|
|
* calling hibernate functions (which take system_transition_mutex)
|
|
* this can cause lockdep to complain about a possible ABBA deadlock
|
|
* which cannot happen since we're in the boot code here and
|
|
* sysfs can't be invoked yet. Therefore, we use a subclass
|
|
* here to avoid lockdep complaining.
|
|
*/
|
|
mutex_lock_nested(&system_transition_mutex, SINGLE_DEPTH_NESTING);
|
|
|
|
if (swsusp_resume_device)
|
|
goto Check_image;
|
|
|
|
if (!strlen(resume_file)) {
|
|
error = -ENOENT;
|
|
goto Unlock;
|
|
}
|
|
|
|
pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
|
|
|
|
if (resume_delay) {
|
|
pr_info("Waiting %dsec before reading resume device ...\n",
|
|
resume_delay);
|
|
ssleep(resume_delay);
|
|
}
|
|
|
|
/* Check if the device is there */
|
|
swsusp_resume_device = name_to_dev_t(resume_file);
|
|
if (!swsusp_resume_device) {
|
|
/*
|
|
* Some device discovery might still be in progress; we need
|
|
* to wait for this to finish.
|
|
*/
|
|
wait_for_device_probe();
|
|
|
|
if (resume_wait) {
|
|
while ((swsusp_resume_device = name_to_dev_t(resume_file)) == 0)
|
|
msleep(10);
|
|
async_synchronize_full();
|
|
}
|
|
|
|
swsusp_resume_device = name_to_dev_t(resume_file);
|
|
if (!swsusp_resume_device) {
|
|
error = -ENODEV;
|
|
goto Unlock;
|
|
}
|
|
}
|
|
|
|
Check_image:
|
|
pm_pr_dbg("Hibernation image partition %d:%d present\n",
|
|
MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
|
|
|
|
pm_pr_dbg("Looking for hibernation image.\n");
|
|
error = swsusp_check();
|
|
if (error)
|
|
goto Unlock;
|
|
|
|
/* The snapshot device should not be opened while we're running */
|
|
if (!hibernate_acquire()) {
|
|
error = -EBUSY;
|
|
swsusp_close(FMODE_READ | FMODE_EXCL);
|
|
goto Unlock;
|
|
}
|
|
|
|
pr_info("resume from hibernation\n");
|
|
pm_prepare_console();
|
|
error = pm_notifier_call_chain_robust(PM_RESTORE_PREPARE, PM_POST_RESTORE);
|
|
if (error)
|
|
goto Restore;
|
|
|
|
pm_pr_dbg("Preparing processes for hibernation restore.\n");
|
|
error = freeze_processes();
|
|
if (error)
|
|
goto Close_Finish;
|
|
|
|
error = freeze_kernel_threads();
|
|
if (error) {
|
|
thaw_processes();
|
|
goto Close_Finish;
|
|
}
|
|
|
|
error = load_image_and_restore();
|
|
thaw_processes();
|
|
Finish:
|
|
pm_notifier_call_chain(PM_POST_RESTORE);
|
|
Restore:
|
|
pm_restore_console();
|
|
pr_info("resume failed (%d)\n", error);
|
|
hibernate_release();
|
|
/* For success case, the suspend path will release the lock */
|
|
Unlock:
|
|
mutex_unlock(&system_transition_mutex);
|
|
pm_pr_dbg("Hibernation image not present or could not be loaded.\n");
|
|
return error;
|
|
Close_Finish:
|
|
swsusp_close(FMODE_READ | FMODE_EXCL);
|
|
goto Finish;
|
|
}
|
|
|
|
late_initcall_sync(software_resume);
|
|
|
|
|
|
static const char * const hibernation_modes[] = {
|
|
[HIBERNATION_PLATFORM] = "platform",
|
|
[HIBERNATION_SHUTDOWN] = "shutdown",
|
|
[HIBERNATION_REBOOT] = "reboot",
|
|
#ifdef CONFIG_SUSPEND
|
|
[HIBERNATION_SUSPEND] = "suspend",
|
|
#endif
|
|
[HIBERNATION_TEST_RESUME] = "test_resume",
|
|
};
|
|
|
|
/*
|
|
* /sys/power/disk - Control hibernation mode.
|
|
*
|
|
* Hibernation can be handled in several ways. There are a few different ways
|
|
* to put the system into the sleep state: using the platform driver (e.g. ACPI
|
|
* or other hibernation_ops), powering it off or rebooting it (for testing
|
|
* mostly).
|
|
*
|
|
* The sysfs file /sys/power/disk provides an interface for selecting the
|
|
* hibernation mode to use. Reading from this file causes the available modes
|
|
* to be printed. There are 3 modes that can be supported:
|
|
*
|
|
* 'platform'
|
|
* 'shutdown'
|
|
* 'reboot'
|
|
*
|
|
* If a platform hibernation driver is in use, 'platform' will be supported
|
|
* and will be used by default. Otherwise, 'shutdown' will be used by default.
|
|
* The selected option (i.e. the one corresponding to the current value of
|
|
* hibernation_mode) is enclosed by a square bracket.
|
|
*
|
|
* To select a given hibernation mode it is necessary to write the mode's
|
|
* string representation (as returned by reading from /sys/power/disk) back
|
|
* into /sys/power/disk.
|
|
*/
|
|
|
|
static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
char *buf)
|
|
{
|
|
int i;
|
|
char *start = buf;
|
|
|
|
if (!hibernation_available())
|
|
return sprintf(buf, "[disabled]\n");
|
|
|
|
for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
|
|
if (!hibernation_modes[i])
|
|
continue;
|
|
switch (i) {
|
|
case HIBERNATION_SHUTDOWN:
|
|
case HIBERNATION_REBOOT:
|
|
#ifdef CONFIG_SUSPEND
|
|
case HIBERNATION_SUSPEND:
|
|
#endif
|
|
case HIBERNATION_TEST_RESUME:
|
|
break;
|
|
case HIBERNATION_PLATFORM:
|
|
if (hibernation_ops)
|
|
break;
|
|
/* not a valid mode, continue with loop */
|
|
continue;
|
|
}
|
|
if (i == hibernation_mode)
|
|
buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
|
|
else
|
|
buf += sprintf(buf, "%s ", hibernation_modes[i]);
|
|
}
|
|
buf += sprintf(buf, "\n");
|
|
return buf-start;
|
|
}
|
|
|
|
static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|
const char *buf, size_t n)
|
|
{
|
|
int error = 0;
|
|
int i;
|
|
int len;
|
|
char *p;
|
|
int mode = HIBERNATION_INVALID;
|
|
|
|
if (!hibernation_available())
|
|
return -EPERM;
|
|
|
|
p = memchr(buf, '\n', n);
|
|
len = p ? p - buf : n;
|
|
|
|
lock_system_sleep();
|
|
for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
|
|
if (len == strlen(hibernation_modes[i])
|
|
&& !strncmp(buf, hibernation_modes[i], len)) {
|
|
mode = i;
|
|
break;
|
|
}
|
|
}
|
|
if (mode != HIBERNATION_INVALID) {
|
|
switch (mode) {
|
|
case HIBERNATION_SHUTDOWN:
|
|
case HIBERNATION_REBOOT:
|
|
#ifdef CONFIG_SUSPEND
|
|
case HIBERNATION_SUSPEND:
|
|
#endif
|
|
case HIBERNATION_TEST_RESUME:
|
|
hibernation_mode = mode;
|
|
break;
|
|
case HIBERNATION_PLATFORM:
|
|
if (hibernation_ops)
|
|
hibernation_mode = mode;
|
|
else
|
|
error = -EINVAL;
|
|
}
|
|
} else
|
|
error = -EINVAL;
|
|
|
|
if (!error)
|
|
pm_pr_dbg("Hibernation mode set to '%s'\n",
|
|
hibernation_modes[mode]);
|
|
unlock_system_sleep();
|
|
return error ? error : n;
|
|
}
|
|
|
|
power_attr(disk);
|
|
|
|
static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
char *buf)
|
|
{
|
|
return sprintf(buf, "%d:%d\n", MAJOR(swsusp_resume_device),
|
|
MINOR(swsusp_resume_device));
|
|
}
|
|
|
|
static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|
const char *buf, size_t n)
|
|
{
|
|
dev_t res;
|
|
int len = n;
|
|
char *name;
|
|
|
|
if (len && buf[len-1] == '\n')
|
|
len--;
|
|
name = kstrndup(buf, len, GFP_KERNEL);
|
|
if (!name)
|
|
return -ENOMEM;
|
|
|
|
res = name_to_dev_t(name);
|
|
kfree(name);
|
|
if (!res)
|
|
return -EINVAL;
|
|
|
|
lock_system_sleep();
|
|
swsusp_resume_device = res;
|
|
unlock_system_sleep();
|
|
pm_pr_dbg("Configured hibernation resume from disk to %u\n",
|
|
swsusp_resume_device);
|
|
noresume = 0;
|
|
software_resume();
|
|
return n;
|
|
}
|
|
|
|
power_attr(resume);
|
|
|
|
static ssize_t resume_offset_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *buf)
|
|
{
|
|
return sprintf(buf, "%llu\n", (unsigned long long)swsusp_resume_block);
|
|
}
|
|
|
|
static ssize_t resume_offset_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr, const char *buf,
|
|
size_t n)
|
|
{
|
|
unsigned long long offset;
|
|
int rc;
|
|
|
|
rc = kstrtoull(buf, 0, &offset);
|
|
if (rc)
|
|
return rc;
|
|
swsusp_resume_block = offset;
|
|
|
|
return n;
|
|
}
|
|
|
|
power_attr(resume_offset);
|
|
|
|
static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
char *buf)
|
|
{
|
|
return sprintf(buf, "%lu\n", image_size);
|
|
}
|
|
|
|
static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
|
|
const char *buf, size_t n)
|
|
{
|
|
unsigned long size;
|
|
|
|
if (sscanf(buf, "%lu", &size) == 1) {
|
|
image_size = size;
|
|
return n;
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
power_attr(image_size);
|
|
|
|
static ssize_t reserved_size_show(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *buf)
|
|
{
|
|
return sprintf(buf, "%lu\n", reserved_size);
|
|
}
|
|
|
|
static ssize_t reserved_size_store(struct kobject *kobj,
|
|
struct kobj_attribute *attr,
|
|
const char *buf, size_t n)
|
|
{
|
|
unsigned long size;
|
|
|
|
if (sscanf(buf, "%lu", &size) == 1) {
|
|
reserved_size = size;
|
|
return n;
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
power_attr(reserved_size);
|
|
|
|
static struct attribute *g[] = {
|
|
&disk_attr.attr,
|
|
&resume_offset_attr.attr,
|
|
&resume_attr.attr,
|
|
&image_size_attr.attr,
|
|
&reserved_size_attr.attr,
|
|
NULL,
|
|
};
|
|
|
|
|
|
static const struct attribute_group attr_group = {
|
|
.attrs = g,
|
|
};
|
|
|
|
|
|
static int __init pm_disk_init(void)
|
|
{
|
|
return sysfs_create_group(power_kobj, &attr_group);
|
|
}
|
|
|
|
core_initcall(pm_disk_init);
|
|
|
|
|
|
static int __init resume_setup(char *str)
|
|
{
|
|
if (noresume)
|
|
return 1;
|
|
|
|
strncpy(resume_file, str, 255);
|
|
return 1;
|
|
}
|
|
|
|
static int __init resume_offset_setup(char *str)
|
|
{
|
|
unsigned long long offset;
|
|
|
|
if (noresume)
|
|
return 1;
|
|
|
|
if (sscanf(str, "%llu", &offset) == 1)
|
|
swsusp_resume_block = offset;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int __init hibernate_setup(char *str)
|
|
{
|
|
if (!strncmp(str, "noresume", 8)) {
|
|
noresume = 1;
|
|
} else if (!strncmp(str, "nocompress", 10)) {
|
|
nocompress = 1;
|
|
} else if (!strncmp(str, "no", 2)) {
|
|
noresume = 1;
|
|
nohibernate = 1;
|
|
} else if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)
|
|
&& !strncmp(str, "protect_image", 13)) {
|
|
enable_restore_image_protection();
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int __init noresume_setup(char *str)
|
|
{
|
|
noresume = 1;
|
|
return 1;
|
|
}
|
|
|
|
static int __init resumewait_setup(char *str)
|
|
{
|
|
resume_wait = 1;
|
|
return 1;
|
|
}
|
|
|
|
static int __init resumedelay_setup(char *str)
|
|
{
|
|
int rc = kstrtouint(str, 0, &resume_delay);
|
|
|
|
if (rc)
|
|
pr_warn("resumedelay: bad option string '%s'\n", str);
|
|
return 1;
|
|
}
|
|
|
|
static int __init nohibernate_setup(char *str)
|
|
{
|
|
noresume = 1;
|
|
nohibernate = 1;
|
|
return 1;
|
|
}
|
|
|
|
__setup("noresume", noresume_setup);
|
|
__setup("resume_offset=", resume_offset_setup);
|
|
__setup("resume=", resume_setup);
|
|
__setup("hibernate=", hibernate_setup);
|
|
__setup("resumewait", resumewait_setup);
|
|
__setup("resumedelay=", resumedelay_setup);
|
|
__setup("nohibernate", nohibernate_setup);
|