android_kernel_xiaomi_sm8350/mm/page_io.c
Srinivasarao Pathipati 630e7df8c5 Merge android11-5.4.197+ (3970bc6) into msm-5.4
* refs/heads/tmp-3970bc6:
  UPSTREAM: Revert "net: af_key: add check for pfkey_broadcast in function pfkey_process"
  FROMGIT: arm64: fix oops in concurrently setting insn_emulation sysctls
  ANDROID: abi_gki_aarch64_qcom: Add vmemdup_user to qcom symbol list
  ANDROID: GKI: update Sony KMI symbol list
  UPSTREAM: mm: fix misplaced unlock_page in do_wp_page()
  BACKPORT: mm: do_wp_page() simplification
  UPSTREAM: mm/ksm: Remove reuse_ksm_page()
  BACKPORT: ALSA: pcm: Fix races among concurrent prealloc proc writes
  BACKPORT: ALSA: pcm: Fix races among concurrent prepare and hw_params/hw_free calls
  BACKPORT: ALSA: pcm: Fix races among concurrent read/write and buffer changes
  ANDROID: Fix up abi issue with struct snd_pcm_runtime
  BACKPORT: ALSA: pcm: Fix races among concurrent hw_params and hw_free calls
  BACKPORT: nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs
  Linux 5.4.197
  bpf: Enlarge offset check value to INT_MAX in bpf_skb_{load,store}_bytes
  NFSD: Fix possible sleep during nfsd4_release_lockowner()
  NFS: Memory allocation failures are not server fatal errors
  docs: submitting-patches: Fix crossref to 'The canonical patch format'
  tpm: ibmvtpm: Correct the return value in tpm_ibmvtpm_probe()
  tpm: Fix buffer access in tpm2_get_tpm_pt()
  HID: multitouch: Add support for Google Whiskers Touchpad
  raid5: introduce MD_BROKEN
  dm verity: set DM_TARGET_IMMUTABLE feature flag
  dm stats: add cond_resched when looping over entries
  dm crypt: make printing of the key constant-time
  dm integrity: fix error code in dm_integrity_ctr()
  zsmalloc: fix races between asynchronous zspage free and page migration
  crypto: ecrdsa - Fix incorrect use of vli_cmp
  netfilter: conntrack: re-fetch conntrack after insertion
  exec: Force single empty string when argv is empty
  drm/i915: Fix -Wstringop-overflow warning in call to intel_read_wm_latency()
  cfg80211: set custom regdomain after wiphy registration
  assoc_array: Fix BUG_ON during garbage collect
  drivers: i2c: thunderx: Allow driver to work with ACPI defined TWSI controllers
  i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
  net: ftgmac100: Disable hardware checksum on AST2600
  net: af_key: check encryption module availability consistency
  pinctrl: sunxi: fix f1c100s uart2 function
  ACPI: sysfs: Fix BERT error region memory mapping
  ACPI: sysfs: Make sparse happy about address space in use
  media: vim2m: initialize the media device earlier
  media: vim2m: Register video device after setting up internals
  secure_seq: use the 64 bits of the siphash for port offset calculation
  tcp: change source port randomizarion at connect() time
  Input: goodix - fix spurious key release events
  staging: rtl8723bs: prevent ->Ssid overflow in rtw_wx_set_scan()
  x86/pci/xen: Disable PCI/MSI[-X] masking for XEN_HVM guests
  lockdown: also lock down previous kgdb use
  Linux 5.4.196
  afs: Fix afs_getattr() to refetch file status if callback break occurred
  i2c: mt7621: fix missing clk_disable_unprepare() on error in mtk_i2c_probe()
  x86/xen: Mark cpu_bringup_and_idle() as dead_end_function
  x86/xen: fix booting 32-bit pv guest
  Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE""
  ARM: dts: imx7: Use audio_mclk_post_div instead audio_mclk_root_clk
  firmware_loader: use kernel credentials when reading firmware
  net: stmmac: disable Split Header (SPH) for Intel platforms
  block: return ELEVATOR_DISCARD_MERGE if possible
  Input: ili210x - fix reset timing
  net: atlantic: verify hw_head_ lies within TX buffer ring
  net: stmmac: fix missing pci_disable_device() on error in stmmac_pci_probe()
  ethernet: tulip: fix missing pci_disable_device() on error in tulip_init_one()
  selftests: add ping test with ping_group_range tuned
  mac80211: fix rx reordering with non explicit / psmp ack policy
  scsi: qla2xxx: Fix missed DMA unmap for aborted commands
  perf bench numa: Address compiler error on s390
  gpio: mvebu/pwm: Refuse requests with inverted polarity
  gpio: gpio-vf610: do not touch other bits when set the target bit
  net: bridge: Clear offload_fwd_mark when passing frame up bridge interface.
  igb: skip phy status check where unavailable
  ARM: 9197/1: spectre-bhb: fix loop8 sequence for Thumb2
  ARM: 9196/1: spectre-bhb: enable for Cortex-A15
  net: af_key: add check for pfkey_broadcast in function pfkey_process
  net/mlx5e: Properly block LRO when XDP is enabled
  NFC: nci: fix sleep in atomic context bugs caused by nci_skb_alloc
  net/qla3xxx: Fix a test in ql_reset_work()
  clk: at91: generated: consider range when calculating best rate
  ice: fix possible under reporting of ethtool Tx and Rx statistics
  net: vmxnet3: fix possible NULL pointer dereference in vmxnet3_rq_cleanup()
  net: vmxnet3: fix possible use-after-free bugs in vmxnet3_rq_alloc_rx_buf()
  net/sched: act_pedit: sanitize shift argument before usage
  net: macb: Increment rx bd head after allocating skb and buffer
  ARM: dts: aspeed-g6: fix SPI1/SPI2 quad pin group
  ARM: dts: aspeed-g6: remove FWQSPID group in pinctrl dtsi
  dma-buf: fix use of DMA_BUF_SET_NAME_{A,B} in userspace
  drm/dp/mst: fix a possible memory leak in fetch_monitor_name()
  crypto: qcom-rng - fix infinite loop on requests not multiple of WORD_SZ
  KVM: x86/mmu: Update number of zapped pages even if page list is stable
  PCI/PM: Avoid putting Elo i2 PCIe Ports in D3cold
  Fix double fget() in vhost_net_set_backend()
  perf: Fix sys_perf_event_open() race against self
  ALSA: wavefront: Proper check of get_user() error
  SUNRPC: Ensure we flush any closed sockets before xs_xprt_free()
  SUNRPC: Don't call connect() more than once on a TCP socket
  SUNRPC: Prevent immediate close+reconnect
  SUNRPC: Clean up scheduling of autoclose
  mmc: core: Default to generic_cmd6_time as timeout in __mmc_switch()
  mmc: block: Use generic_cmd6_time when modifying INAND_CMD38_ARG_EXT_CSD
  mmc: core: Specify timeouts for BKOPS and CACHE_FLUSH for eMMC
  nilfs2: fix lockdep warnings during disk space reclamation
  nilfs2: fix lockdep warnings in page operations for btree nodes
  ARM: 9191/1: arm/stacktrace, kasan: Silence KASAN warnings in unwind_frame()
  platform/chrome: cros_ec_debugfs: detach log reader wq from devm
  drbd: remove usage of list iterator variable after loop
  MIPS: lantiq: check the return value of kzalloc()
  rtc: mc146818-lib: Fix the AltCentury for AMD platforms
  nvme-multipath: fix hang when disk goes live over reconnect
  ALSA: hda/realtek: Enable headset mic on Lenovo P360
  crypto: x86/chacha20 - Avoid spurious jumps to other functions
  crypto: stm32 - fix reference leak in stm32_crc_remove
  Input: stmfts - fix reference leak in stmfts_input_open
  Input: add bounds checking to input_set_capability()
  um: Cleanup syscall_handler_t definition/cast, fix warning
  rtc: fix use-after-free on device removal
  x86/xen: Make the secondary CPU idle tasks reliable
  x86/xen: Make the boot CPU idle task reliable
  floppy: use a statically allocated error counter
  ANDROID: fix up abi issue with struct snd_pcm_runtime
  Linux 5.4.195
  tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe()
  ping: fix address binding wrt vrf
  arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map
  net: phy: Fix race condition on link status change
  MIPS: fix build with gcc-12
  drm/vmwgfx: Initialize drm_mode_fb_cmd2
  cgroup/cpuset: Remove cpus_allowed/mems_allowed setup in cpuset_init_smp()
  i40e: i40e_main: fix a missing check on list iterator
  drm/nouveau/tegra: Stop using iommu_present()
  serial: 8250_mtk: Fix register address for XON/XOFF character
  serial: 8250_mtk: Fix UART_EFR register address
  slimbus: qcom: Fix IRQ check in qcom_slim_probe
  USB: serial: option: add Fibocom MA510 modem
  USB: serial: option: add Fibocom L610 modem
  USB: serial: qcserial: add support for Sierra Wireless EM7590
  USB: serial: pl2303: add device id for HP LM930 Display
  usb: typec: tcpci: Don't skip cleanup in .remove() on error
  usb: cdc-wdm: fix reading stuck on device close
  tty: n_gsm: fix mux activation issues in gsm_config()
  tcp: resalt the secret every 10 seconds
  net: emaclite: Don't advertise 1000BASE-T and do auto negotiation
  s390: disable -Warray-bounds
  ASoC: ops: Validate input values in snd_soc_put_volsw_range()
  ASoC: max98090: Generate notifications on changes for custom control
  ASoC: max98090: Reject invalid values in custom control put()
  hwmon: (f71882fg) Fix negative temperature
  gfs2: Fix filesystem block deallocation for short writes
  net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe()
  net/smc: non blocking recvmsg() return -EAGAIN when no data and signal_pending
  net/sched: act_pedit: really ensure the skb is writable
  s390/lcs: fix variable dereferenced before check
  s390/ctcm: fix potential memory leak
  s390/ctcm: fix variable dereferenced before check
  hwmon: (ltq-cputemp) restrict it to SOC_XWAY
  dim: initialize all struct fields
  mac80211_hwsim: call ieee80211_tx_prepare_skb under RCU protection
  netlink: do not reset transport header in netlink_recvmsg()
  drm/nouveau: Fix a potential theorical leak in nouveau_get_backlight_name()
  ipv4: drop dst in multicast routing path
  net: Fix features skip in for_each_netdev_feature()
  mac80211: Reset MBSSID parameters upon connection
  hwmon: (tmp401) Add OF device ID table
  batman-adv: Don't skb_split skbuffs with frag_list
  Linux 5.4.194
  mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic()
  mm: hugetlb: fix missing cache flush in copy_huge_page_from_user()
  mm: fix missing cache flush for all tail pages of compound page
  Bluetooth: Fix the creation of hdev->name
  KVM: x86/svm: Account for family 17h event renumberings in amd_pmc_perf_hw_id
  x86: kprobes: Prohibit probing on instruction which has emulate prefix
  x86: xen: insn: Decode Xen and KVM emulate-prefix signature
  x86: xen: kvm: Gather the definition of emulate prefixes
  x86/asm: Allow to pass macros to __ASM_FORM()
  KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id()
  arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
  can: grcan: only use the NAPI poll budget for RX
  can: grcan: grcan_probe(): fix broken system id check for errata workaround needs
  nfp: bpf: silence bitwise vs. logical OR warning
  drm/i915: Cast remain to unsigned long in eb_relocate_vma
  drm/amd/display/dc/gpio/gpio_service: Pass around correct dce_{version, environment} types
  block: drbd: drbd_nl: Make conversion to 'enum drbd_ret_code' explicit
  MIPS: Use address-of operator on section symbols
  ANDROID: GKI: update the abi .xml file
  Revert "tcp: ensure to use the most recently sent skb when filling the rate sample"
  Linux 5.4.193
  mmc: rtsx: add 74 Clocks in power on flow
  PCI: aardvark: Fix reading MSI interrupt number
  PCI: aardvark: Clear all MSIs at setup
  dm: interlock pending dm_io and dm_wait_for_bios_completion
  dm: fix mempool NULL pointer race when completing IO
  tcp: make sure treq->af_specific is initialized
  ALSA: pcm: Fix potential AB/BA lock with buffer_mutex and mmap_lock
  ALSA: pcm: Fix races among concurrent prealloc proc writes
  ALSA: pcm: Fix races among concurrent prepare and hw_params/hw_free calls
  ALSA: pcm: Fix races among concurrent read/write and buffer changes
  ALSA: pcm: Fix races among concurrent hw_params and hw_free calls
  mm: fix unexpected zeroed page mapping with zram swap
  block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern
  net: ipv6: ensure we call ipv6_mc_down() at most once
  KVM: LAPIC: Enable timer posted-interrupt only when mwait/hlt is advertised
  x86/kvm: Preserve BSP MSR_KVM_POLL_CONTROL across suspend/resume
  kvm: x86/cpuid: Only provide CPUID leaf 0xA if host has architectural PMU
  NFSv4: Don't invalidate inode attributes on delegation return
  drm/amdkfd: Use drm_priv to pass VM from KFD to amdgpu
  net: igmp: respect RCU rules in ip_mc_source() and ip_mc_msfilter()
  btrfs: always log symlinks in full mode
  smsc911x: allow using IRQ0
  bnxt_en: Fix possible bnxt_open() failure caused by wrong RFS flag
  selftests: mirror_gre_bridge_1q: Avoid changing PVID while interface is operational
  net: emaclite: Add error handling for of_address_to_resource()
  net: stmmac: dwmac-sun8i: add missing of_node_put() in sun8i_dwmac_register_mdio_mux()
  net: ethernet: mediatek: add missing of_node_put() in mtk_sgmii_init()
  RDMA/siw: Fix a condition race issue in MPA request processing
  ASoC: dmaengine: Restore NULL prepare_slave_config() callback
  hwmon: (adt7470) Fix warning on module removal
  NFC: netlink: fix sleep in atomic bug when firmware download timeout
  nfc: nfcmrvl: main: reorder destructive operations in nfcmrvl_nci_unregister_dev to avoid bugs
  nfc: replace improper check device_is_registered() in netlink related functions
  can: grcan: use ofdev->dev when allocating DMA memory
  can: grcan: grcan_close(): fix deadlock
  s390/dasd: Fix read inconsistency for ESE DASD devices
  s390/dasd: Fix read for ESE with blksize < 4k
  s390/dasd: prevent double format of tracks for ESE devices
  s390/dasd: fix data corruption for ESE devices
  ASoC: meson: Fix event generation for G12A tohdmi mux
  ASoC: wm8958: Fix change notifications for DSP controls
  ASoC: da7219: Fix change notifications for tone generator frequency
  genirq: Synchronize interrupt thread startup
  ACPICA: Always create namespace nodes using acpi_ns_create_node()
  firewire: core: extend card->lock in fw_core_handle_bus_reset
  firewire: remove check of list iterator against head past the loop body
  firewire: fix potential uaf in outbound_phy_packet_callback()
  Revert "SUNRPC: attempt AF_LOCAL connect on setup"
  gpiolib: of: fix bounds check for 'gpio-reserved-ranges'
  ALSA: fireworks: fix wrong return count shorter than expected by 4 bytes
  parisc: Merge model and model name into one line in /proc/cpuinfo
  MIPS: Fix CP0 counter erratum detection for R4k CPUs
  Linux 5.4.192
  mm, hugetlb: allow for "high" userspace addresses
  hugetlbfs: get unmapped area below TASK_UNMAPPED_BASE for hugetlbfs
  tty: n_gsm: fix incorrect UA handling
  tty: n_gsm: fix wrong command frame length field encoding
  tty: n_gsm: fix wrong command retry handling
  tty: n_gsm: fix missing explicit ldisc flush
  tty: n_gsm: fix insufficient txframe size
  netfilter: nft_socket: only do sk lookups when indev is available
  tty: n_gsm: fix malformed counter for out of frame data
  tty: n_gsm: fix wrong signal octet encoding in convergence layer type 2
  x86/cpu: Load microcode during restore_processor_state()
  net: ethernet: stmmac: fix write to sgmii_adapter_base
  drivers: net: hippi: Fix deadlock in rr_close()
  cifs: destage any unwritten data to the server before calling copychunk_write
  x86: __memcpy_flushcache: fix wrong alignment if size > 2^32
  ip6_gre: Avoid updating tunnel->tun_hlen in __gre6_xmit()
  ASoC: wm8731: Disable the regulator when probing fails
  tcp: fix F-RTO may not work correctly when receiving DSACK
  ixgbe: ensure IPsec VF<->PF compatibility
  bnx2x: fix napi API usage sequence
  tls: Skip tls_append_frag on zero copy size
  drm/amd/display: Fix memory leak in dcn21_clock_source_create
  net: dsa: lantiq_gswip: Don't set GSWIP_MII_CFG_RMII_CLK
  net: bcmgenet: hide status block before TX timestamping
  clk: sunxi: sun9i-mmc: check return value after calling platform_get_resource()
  bus: sunxi-rsb: Fix the return value of sunxi_rsb_device_create()
  tcp: fix potential xmit stalls caused by TCP_NOTSENT_LOWAT
  ip_gre: Make o_seqno start from 0 in native mode
  net/smc: sync err code when tcp connection was refused
  net: hns3: add validity check for message data length
  cpufreq: fix memory leak in sun50i_cpufreq_nvmem_probe
  pinctrl: pistachio: fix use of irq_of_parse_and_map()
  arm64: dts: imx8mn-ddr4-evk: Describe the 32.768 kHz PMIC clock
  ARM: dts: imx6ull-colibri: fix vqmmc regulator
  sctp: check asoc strreset_chunk in sctp_generate_reconf_event
  tcp: ensure to use the most recently sent skb when filling the rate sample
  tcp: md5: incorrect tcp_header_len for incoming connections
  bpf, lwt: Fix crash when using bpf_skb_set_tunnel_key() from bpf_xmit lwt hook
  mtd: rawnand: Fix return value check of wait_for_completion_timeout
  ipvs: correctly print the memory size of ip_vs_conn_tab
  ARM: dts: logicpd-som-lv: Fix wrong pinmuxing on OMAP35
  ARM: dts: am3517-evm: Fix misc pinmuxing
  ARM: dts: Fix mmc order for omap3-gta04
  phy: ti: Add missing pm_runtime_disable() in serdes_am654_probe
  phy: mapphone-mdm6600: Fix PM error handling in phy_mdm6600_probe
  ARM: dts: at91: Map MCLK for wm8731 on at91sam9g20ek
  phy: ti: omap-usb2: Fix error handling in omap_usb2_enable_clocks
  ARM: OMAP2+: Fix refcount leak in omap_gic_of_init
  phy: samsung: exynos5250-sata: fix missing device put in probe error paths
  phy: samsung: Fix missing of_node_put() in exynos_sata_phy_probe
  ARM: dts: imx6qdl-apalis: Fix sgtl5000 detection issue
  USB: Fix xhci event ring dequeue pointer ERDP update issue
  mtd: rawnand: fix ecc parameters for mt7622
  arm64: dts: meson: remove CPU opps below 1GHz for SM1 boards
  arm64: dts: meson: remove CPU opps below 1GHz for G12B boards
  video: fbdev: udlfb: properly check endpoint type
  hex2bin: fix access beyond string end
  hex2bin: make the function hex_to_bin constant-time
  arch_topology: Do not set llc_sibling if llc_id is invalid
  serial: 8250: Correct the clock for EndRun PTP/1588 PCIe device
  serial: 8250: Also set sticky MCR bits in console restoration
  serial: imx: fix overrun interrupts in DMA mode
  usb: dwc3: gadget: Return proper request status
  usb: dwc3: core: Fix tx/rx threshold settings
  usb: gadget: configfs: clear deactivation flag in configfs_composite_unbind()
  usb: gadget: uvc: Fix crash when encoding data for usb request
  usb: typec: ucsi: Fix role swapping
  usb: misc: fix improper handling of refcount in uss720_probe()
  iio: magnetometer: ak8975: Fix the error handling in ak8975_power_on()
  iio: dac: ad5446: Fix read_raw not returning set value
  iio: dac: ad5592r: Fix the missing return value.
  xhci: increase usb U3 -> U0 link resume timeout from 100ms to 500ms
  xhci: stop polling roothubs after shutdown
  USB: serial: option: add Telit 0x1057, 0x1058, 0x1075 compositions
  USB: serial: option: add support for Cinterion MV32-WA/MV32-WB
  USB: serial: cp210x: add PIDs for Kamstrup USB Meter Reader
  USB: serial: whiteheat: fix heap overflow in WHITEHEAT_GET_DTR_RTS
  USB: quirks: add STRING quirk for VCOM device
  USB: quirks: add a Realtek card reader
  usb: mtu3: fix USB 3.0 dual-role-switch from device to host
  lightnvm: disable the subsystem
  hamradio: remove needs_free_netdev to avoid UAF
  hamradio: defer 6pack kfree after unregister_netdev
  floppy: disable FDRAWCMD by default

 Conflicts:
	drivers/usb/dwc3/gadget.c
	include/linux/dma-mapping.h
	include/linux/stmmac.h
	mm/memory.c

Change-Id: I3bf49e11ae4aeaf1db353efbdfee950cd12de8cf
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
2022-08-16 16:52:01 +05:30

390 lines
9.1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* linux/mm/page_io.c
*
* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
*
* Swap reorganised 29.12.95,
* Asynchronous swapping added 30.12.95. Stephen Tweedie
* Removed race in async swapping. 14.4.1996. Bruno Haible
* Add swap of shared pages through the page cache. 20.2.1998. Stephen Tweedie
* Always use brw_page, life becomes simpler. 12 May 1998 Eric Biederman
*/
#include <linux/mm.h>
#include <linux/kernel_stat.h>
#include <linux/gfp.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
#include <linux/bio.h>
#include <linux/swapops.h>
#include <linux/buffer_head.h>
#include <linux/writeback.h>
#include <linux/frontswap.h>
#include <linux/blkdev.h>
#include <linux/psi.h>
#include <linux/uio.h>
#include <linux/sched/task.h>
#include <asm/pgtable.h>
static struct bio *get_swap_bio(gfp_t gfp_flags,
struct page *page, bio_end_io_t end_io)
{
struct bio *bio;
bio = bio_alloc(gfp_flags, 1);
if (bio) {
struct block_device *bdev;
bio->bi_iter.bi_sector = map_swap_page(page, &bdev);
bio_set_dev(bio, bdev);
bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
bio->bi_end_io = end_io;
bio_add_page(bio, page, PAGE_SIZE * hpage_nr_pages(page), 0);
}
return bio;
}
void end_swap_bio_write(struct bio *bio)
{
struct page *page = bio_first_page_all(bio);
if (bio->bi_status) {
SetPageError(page);
/*
* We failed to write the page out to swap-space.
* Re-dirty the page in order to avoid it being reclaimed.
* Also print a dire warning that things will go BAD (tm)
* very quickly.
*
* Also clear PG_reclaim to avoid rotate_reclaimable_page()
*/
set_page_dirty(page);
pr_alert_ratelimited("Write-error on swap-device (%u:%u:%llu)\n",
MAJOR(bio_dev(bio)),
MINOR(bio_dev(bio)),
(unsigned long long)bio->bi_iter.bi_sector);
ClearPageReclaim(page);
}
end_page_writeback(page);
bio_put(bio);
}
static void end_swap_bio_read(struct bio *bio)
{
struct page *page = bio_first_page_all(bio);
struct task_struct *waiter = bio->bi_private;
if (bio->bi_status) {
SetPageError(page);
ClearPageUptodate(page);
pr_alert("Read-error on swap-device (%u:%u:%llu)\n",
MAJOR(bio_dev(bio)), MINOR(bio_dev(bio)),
(unsigned long long)bio->bi_iter.bi_sector);
goto out;
}
SetPageUptodate(page);
out:
unlock_page(page);
WRITE_ONCE(bio->bi_private, NULL);
bio_put(bio);
if (waiter) {
blk_wake_io_task(waiter);
put_task_struct(waiter);
}
}
int generic_swapfile_activate(struct swap_info_struct *sis,
struct file *swap_file,
sector_t *span)
{
struct address_space *mapping = swap_file->f_mapping;
struct inode *inode = mapping->host;
unsigned blocks_per_page;
unsigned long page_no;
unsigned blkbits;
sector_t probe_block;
sector_t last_block;
sector_t lowest_block = -1;
sector_t highest_block = 0;
int nr_extents = 0;
int ret;
blkbits = inode->i_blkbits;
blocks_per_page = PAGE_SIZE >> blkbits;
/*
* Map all the blocks into the extent tree. This code doesn't try
* to be very smart.
*/
probe_block = 0;
page_no = 0;
last_block = i_size_read(inode) >> blkbits;
while ((probe_block + blocks_per_page) <= last_block &&
page_no < sis->max) {
unsigned block_in_page;
sector_t first_block;
cond_resched();
first_block = bmap(inode, probe_block);
if (first_block == 0)
goto bad_bmap;
/*
* It must be PAGE_SIZE aligned on-disk
*/
if (first_block & (blocks_per_page - 1)) {
probe_block++;
goto reprobe;
}
for (block_in_page = 1; block_in_page < blocks_per_page;
block_in_page++) {
sector_t block;
block = bmap(inode, probe_block + block_in_page);
if (block == 0)
goto bad_bmap;
if (block != first_block + block_in_page) {
/* Discontiguity */
probe_block++;
goto reprobe;
}
}
first_block >>= (PAGE_SHIFT - blkbits);
if (page_no) { /* exclude the header page */
if (first_block < lowest_block)
lowest_block = first_block;
if (first_block > highest_block)
highest_block = first_block;
}
/*
* We found a PAGE_SIZE-length, PAGE_SIZE-aligned run of blocks
*/
ret = add_swap_extent(sis, page_no, 1, first_block);
if (ret < 0)
goto out;
nr_extents += ret;
page_no++;
probe_block += blocks_per_page;
reprobe:
continue;
}
ret = nr_extents;
*span = 1 + highest_block - lowest_block;
if (page_no == 0)
page_no = 1; /* force Empty message */
sis->max = page_no;
sis->pages = page_no - 1;
sis->highest_bit = page_no - 1;
out:
return ret;
bad_bmap:
pr_err("swapon: swapfile has holes\n");
ret = -EINVAL;
goto out;
}
/*
* We may have stale swap cache pages in memory: notice
* them here and get rid of the unnecessary final write.
*/
int swap_writepage(struct page *page, struct writeback_control *wbc)
{
int ret = 0;
if (try_to_free_swap(page)) {
unlock_page(page);
goto out;
}
if (frontswap_store(page) == 0) {
set_page_writeback(page);
unlock_page(page);
end_page_writeback(page);
goto out;
}
ret = __swap_writepage(page, wbc, end_swap_bio_write);
out:
return ret;
}
static inline void count_swpout_vm_event(struct page *page)
{
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
if (unlikely(PageTransHuge(page)))
count_vm_event(THP_SWPOUT);
#endif
count_vm_events(PSWPOUT, hpage_nr_pages(page));
}
int __swap_writepage(struct page *page, struct writeback_control *wbc,
bio_end_io_t end_write_func)
{
struct bio *bio;
int ret;
struct swap_info_struct *sis = page_swap_info(page);
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
if (sis->flags & SWP_FS) {
struct kiocb kiocb;
struct file *swap_file = sis->swap_file;
struct address_space *mapping = swap_file->f_mapping;
struct bio_vec bv = {
.bv_page = page,
.bv_len = PAGE_SIZE,
.bv_offset = 0
};
struct iov_iter from;
iov_iter_bvec(&from, WRITE, &bv, 1, PAGE_SIZE);
init_sync_kiocb(&kiocb, swap_file);
kiocb.ki_pos = page_file_offset(page);
set_page_writeback(page);
unlock_page(page);
ret = mapping->a_ops->direct_IO(&kiocb, &from);
if (ret == PAGE_SIZE) {
count_vm_event(PSWPOUT);
ret = 0;
} else {
/*
* In the case of swap-over-nfs, this can be a
* temporary failure if the system has limited
* memory for allocating transmit buffers.
* Mark the page dirty and avoid
* rotate_reclaimable_page but rate-limit the
* messages but do not flag PageError like
* the normal direct-to-bio case as it could
* be temporary.
*/
set_page_dirty(page);
ClearPageReclaim(page);
pr_err_ratelimited("Write error on dio swapfile (%llu)\n",
page_file_offset(page));
}
end_page_writeback(page);
return ret;
}
ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc);
if (!ret) {
count_swpout_vm_event(page);
return 0;
}
ret = 0;
bio = get_swap_bio(GFP_NOIO, page, end_write_func);
if (bio == NULL) {
set_page_dirty(page);
unlock_page(page);
ret = -ENOMEM;
goto out;
}
bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc);
bio_associate_blkg_from_page(bio, page);
count_swpout_vm_event(page);
set_page_writeback(page);
unlock_page(page);
submit_bio(bio);
out:
return ret;
}
int swap_readpage(struct page *page, bool synchronous)
{
struct bio *bio;
int ret = 0;
struct swap_info_struct *sis = page_swap_info(page);
blk_qc_t qc;
struct gendisk *disk;
unsigned long pflags;
VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
VM_BUG_ON_PAGE(!PageLocked(page), page);
VM_BUG_ON_PAGE(PageUptodate(page), page);
/*
* Count submission time as memory stall. When the device is congested,
* or the submitting cgroup IO-throttled, submission can be a
* significant part of overall IO time.
*/
psi_memstall_enter(&pflags);
if (frontswap_load(page) == 0) {
SetPageUptodate(page);
unlock_page(page);
goto out;
}
if (sis->flags & SWP_FS) {
struct file *swap_file = sis->swap_file;
struct address_space *mapping = swap_file->f_mapping;
ret = mapping->a_ops->readpage(swap_file, page);
if (!ret)
count_vm_event(PSWPIN);
goto out;
}
ret = bdev_read_page(sis->bdev, swap_page_sector(page), page);
if (!ret) {
count_vm_event(PSWPIN);
goto out;
}
ret = 0;
bio = get_swap_bio(GFP_KERNEL, page, end_swap_bio_read);
if (bio == NULL) {
unlock_page(page);
ret = -ENOMEM;
goto out;
}
disk = bio->bi_disk;
/*
* Keep this task valid during swap readpage because the oom killer may
* attempt to access it in the page fault retry time check.
*/
bio_set_op_attrs(bio, REQ_OP_READ, 0);
if (synchronous) {
bio->bi_opf |= REQ_HIPRI;
get_task_struct(current);
bio->bi_private = current;
}
count_vm_event(PSWPIN);
bio_get(bio);
qc = submit_bio(bio);
while (synchronous) {
set_current_state(TASK_UNINTERRUPTIBLE);
if (!READ_ONCE(bio->bi_private))
break;
if (!blk_poll(disk->queue, qc, true))
io_schedule();
}
__set_current_state(TASK_RUNNING);
bio_put(bio);
out:
psi_memstall_leave(&pflags);
return ret;
}
int swap_set_page_dirty(struct page *page)
{
struct swap_info_struct *sis = page_swap_info(page);
if (sis->flags & SWP_FS) {
struct address_space *mapping = sis->swap_file->f_mapping;
VM_BUG_ON_PAGE(!PageSwapCache(page), page);
return mapping->a_ops->set_page_dirty(page);
} else {
return __set_page_dirty_no_writeback(page);
}
}