android_kernel_xiaomi_sm7250/drivers/md/dm-linear.c
Ivaylo Georgiev 45991f3d2a Merge android-4.19.18 (26bf816) into msm-4.19
* refs/heads/tmp-26bf816:
  Linux 4.19.18
  ipmi: Don't initialize anything in the core until something uses it
  ipmi:ssif: Fix handling of multi-part return messages
  ipmi: Prevent use-after-free in deliver_response
  ipmi: msghandler: Fix potential Spectre v1 vulnerabilities
  ipmi: fix use-after-free of user->release_barrier.rda
  Bluetooth: Fix unnecessary error message for HCI request completion
  iwlwifi: mvm: Send LQ command as async when necessary
  mm, proc: be more verbose about unstable VMA flags in /proc/<pid>/smaps
  userfaultfd: clear flag if remap event not enabled
  mm/swap: use nr_node_ids for avail_lists in swap_info_struct
  mm/page-writeback.c: don't break integrity writeback on ->writepage() error
  ocfs2: fix panic due to unrecovered local alloc
  iomap: don't search past page end in iomap_is_partially_uptodate
  scsi: megaraid: fix out-of-bound array accesses
  scsi: smartpqi: call pqi_free_interrupts() in pqi_shutdown()
  ath10k: fix peer stats null pointer dereference
  scsi: smartpqi: correct lun reset issues
  scsi: mpt3sas: fix memory ordering on 64bit writes
  IB/usnic: Fix potential deadlock
  sysfs: Disable lockdep for driver bind/unbind files
  ALSA: bebob: fix model-id of unit for Apogee Ensemble
  Bluetooth: btusb: Add support for Intel bluetooth device 8087:0029
  dm: Check for device sector overflow if CONFIG_LBDAF is not set
  clocksource/drivers/integrator-ap: Add missing of_node_put()
  quota: Lock s_umount in exclusive mode for Q_XQUOTA{ON,OFF} quotactls.
  perf tools: Add missing open_memstream() prototype for systems lacking it
  perf tools: Add missing sigqueue() prototype for systems lacking it
  perf cs-etm: Correct packets swapping in cs_etm__flush()
  dm snapshot: Fix excessive memory usage and workqueue stalls
  tools lib subcmd: Don't add the kernel sources to the include path
  perf stat: Avoid segfaults caused by negated options
  dm kcopyd: Fix bug causing workqueue stalls
  dm crypt: use u64 instead of sector_t to store iv_offset
  x86/topology: Use total_cpus for max logical packages calculation
  netfilter: ipt_CLUSTERIP: fix deadlock in netns exit routine
  netfilter: ipt_CLUSTERIP: remove wrong WARN_ON_ONCE in netns exit routine
  netfilter: ipt_CLUSTERIP: check MAC address when duplicate config is set
  perf vendor events intel: Fix Load_Miss_Real_Latency on SKL/SKX
  perf parse-events: Fix unchecked usage of strncpy()
  perf svghelper: Fix unchecked usage of strncpy()
  perf tests ARM: Disable breakpoint tests 32-bit
  perf intel-pt: Fix error with config term "pt=0"
  tty/serial: do not free trasnmit buffer page under port lock
  btrfs: improve error handling of btrfs_add_link
  btrfs: fix use-after-free due to race between replace start and cancel
  btrfs: alloc_chunk: fix more DUP stripe size handling
  btrfs: volumes: Make sure there is no overlap of dev extents at mount time
  mmc: atmel-mci: do not assume idle after atmci_request_end
  kconfig: fix memory leak when EOF is encountered in quotation
  kconfig: fix file name and line number of warn_ignored_character()
  bpf: relax verifier restriction on BPF_MOV | BPF_ALU
  arm64: Fix minor issues with the dcache_by_line_op macro
  clk: imx6q: reset exclusive gates on init
  arm64: kasan: Increase stack size for KASAN_EXTRA
  selftests: do not macro-expand failed assertion expressions
  scsi: target/core: Make sure that target_wait_for_sess_cmds() waits long enough
  scsi: target: use consistent left-aligned ASCII INQUIRY data
  net: call sk_dst_reset when set SO_DONTROUTE
  staging: erofs: fix use-after-free of on-stack `z_erofs_vle_unzip_io'
  media: venus: core: Set dma maximum segment size
  ASoC: use dma_ops of parent device for acp_audio_dma
  media: firewire: Fix app_info parameter type in avc_ca{,_app}_info
  powerpc/pseries/cpuidle: Fix preempt warning
  powerpc/xmon: Fix invocation inside lock region
  media: uvcvideo: Refactor teardown of uvc on USB disconnect
  pstore/ram: Do not treat empty buffers as valid
  clk: imx: make mux parent strings const
  jffs2: Fix use of uninitialized delayed_work, lockdep breakage
  efi/libstub: Disable some warnings for x86{,_64}
  rxe: IB_WR_REG_MR does not capture MR's iova field
  drm/amdgpu: Reorder uvd ring init before uvd resume
  scsi: qedi: Check for session online before getting iSCSI TLV data.
  ASoC: pcm3168a: Don't disable pcm3168a when CONFIG_PM defined
  selinux: always allow mounting submounts
  fpga: altera-cvp: fix probing for multiple FPGAs on the bus
  usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device
  samples: bpf: fix: error handling regarding kprobe_events
  clk: meson: meson8b: fix incorrect divider mapping in cpu_scale_table
  drm/atomic-helper: Complete fake_commit->flip_done potentially earlier
  arm64: perf: set suppress_bind_attrs flag to true
  crypto: ecc - regularize scalar for scalar multiplication
  MIPS: SiByte: Enable swiotlb for SWARM, LittleSur and BigSur
  x86/mce: Fix -Wmissing-prototypes warnings
  ALSA: oxfw: add support for APOGEE duet FireWire
  bpf: Allow narrow loads with offset > 0
  serial: set suppress_bind_attrs flag only if builtin
  writeback: don't decrement wb->refcnt if !wb->bdi
  of: overlay: add missing of_node_put() after add new node to changeset
  selftests/bpf: enable (uncomment) all tests in test_libbpf.sh
  usb: typec: tcpm: Do not disconnect link for self powered devices
  e1000e: allow non-monotonic SYSTIM readings
  platform/x86: asus-wmi: Tell the EC the OS will handle the display off hotkey
  ixgbe: allow IPsec Tx offload in VEPA mode
  drm/amdkfd: fix interrupt spin lock
  drm/amd/display: Guard against null stream_state in set_crc_source
  gpio: pl061: Move irq_chip definition inside struct pl061
  netfilter: ipset: Allow matching on destination MAC address for mac and ipmac sets
  net: clear skb->tstamp in bridge forwarding path
  ipv6: Take rcu_read_lock in __inet6_bind for mapped addresses
  r8169: Add support for new Realtek Ethernet
  qmi_wwan: add MTU default to qmap network interface
  net, skbuff: do not prefer skb allocation fails early
  net: dsa: mv88x6xxx: mv88e6390 errata
  mlxsw: spectrum_switchdev: Set PVID correctly during VLAN deletion
  mlxsw: spectrum: Disable lag port TX before removing it
  ipv6: Consider sk_bound_dev_if when binding a socket to a v4 mapped address
  UPSTREAM: dm: do not allow readahead to limit IO size
  UPSTREAM: ppp: Move PFC decompression to PPP generic layer
  UPSTREAM: l2tp: Add protocol field decompression

Conflicts:
	include/linux/swap.h

Change-Id: I72fecd7d04341015f9397afe60d8469d548b4cb6
Signed-off-by: Ivaylo Georgiev <irgeorgiev@codeaurora.org>
2019-02-27 02:23:25 -08:00

248 lines
5.8 KiB
C

/*
* Copyright (C) 2001-2003 Sistina Software (UK) Limited.
*
* This file is released under the GPL.
*/
#include "dm.h"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/bio.h>
#include <linux/dax.h>
#include <linux/slab.h>
#include <linux/device-mapper.h>
#define DM_MSG_PREFIX "linear"
/*
* Linear: maps a linear range of a device.
*/
struct linear_c {
struct dm_dev *dev;
sector_t start;
};
/*
* Construct a linear mapping: <dev_path> <offset>
*/
int dm_linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct linear_c *lc;
unsigned long long tmp;
char dummy;
int ret;
if (argc != 2) {
ti->error = "Invalid argument count";
return -EINVAL;
}
lc = kmalloc(sizeof(*lc), GFP_KERNEL);
if (lc == NULL) {
ti->error = "Cannot allocate linear context";
return -ENOMEM;
}
ret = -EINVAL;
if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 || tmp != (sector_t)tmp) {
ti->error = "Invalid device sector";
goto bad;
}
lc->start = tmp;
ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev);
if (ret) {
ti->error = "Device lookup failed";
goto bad;
}
ti->num_flush_bios = 1;
ti->num_discard_bios = 1;
ti->num_secure_erase_bios = 1;
ti->num_write_same_bios = 1;
ti->num_write_zeroes_bios = 1;
ti->private = lc;
return 0;
bad:
kfree(lc);
return ret;
}
void dm_linear_dtr(struct dm_target *ti)
{
struct linear_c *lc = (struct linear_c *) ti->private;
dm_put_device(ti, lc->dev);
kfree(lc);
}
static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
{
struct linear_c *lc = ti->private;
return lc->start + dm_target_offset(ti, bi_sector);
}
static void linear_map_bio(struct dm_target *ti, struct bio *bio)
{
struct linear_c *lc = ti->private;
bio_set_dev(bio, lc->dev->bdev);
if (bio_sectors(bio) || bio_op(bio) == REQ_OP_ZONE_RESET)
bio->bi_iter.bi_sector =
linear_map_sector(ti, bio->bi_iter.bi_sector);
}
int dm_linear_map(struct dm_target *ti, struct bio *bio)
{
linear_map_bio(ti, bio);
return DM_MAPIO_REMAPPED;
}
#ifdef CONFIG_BLK_DEV_ZONED
int dm_linear_end_io(struct dm_target *ti, struct bio *bio,
blk_status_t *error)
{
struct linear_c *lc = ti->private;
if (!*error && bio_op(bio) == REQ_OP_ZONE_REPORT)
dm_remap_zone_report(ti, bio, lc->start);
return DM_ENDIO_DONE;
}
EXPORT_SYMBOL_GPL(dm_linear_end_io);
#endif
void dm_linear_status(struct dm_target *ti, status_type_t type,
unsigned status_flags, char *result, unsigned maxlen)
{
struct linear_c *lc = (struct linear_c *) ti->private;
switch (type) {
case STATUSTYPE_INFO:
result[0] = '\0';
break;
case STATUSTYPE_TABLE:
snprintf(result, maxlen, "%s %llu", lc->dev->name,
(unsigned long long)lc->start);
break;
}
}
int dm_linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
{
struct linear_c *lc = (struct linear_c *) ti->private;
struct dm_dev *dev = lc->dev;
*bdev = dev->bdev;
/*
* Only pass ioctls through if the device sizes match exactly.
*/
if (lc->start ||
ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
return 1;
return 0;
}
int dm_linear_iterate_devices(struct dm_target *ti,
iterate_devices_callout_fn fn, void *data)
{
struct linear_c *lc = ti->private;
return fn(ti, lc->dev, lc->start, ti->len, data);
}
#if IS_ENABLED(CONFIG_DAX_DRIVER)
long dm_linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
long nr_pages, void **kaddr, pfn_t *pfn)
{
long ret;
struct linear_c *lc = ti->private;
struct block_device *bdev = lc->dev->bdev;
struct dax_device *dax_dev = lc->dev->dax_dev;
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
dev_sector = linear_map_sector(ti, sector);
ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff);
if (ret)
return ret;
return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
}
EXPORT_SYMBOL_GPL(dm_linear_dax_direct_access);
size_t dm_linear_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i)
{
struct linear_c *lc = ti->private;
struct block_device *bdev = lc->dev->bdev;
struct dax_device *dax_dev = lc->dev->dax_dev;
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
dev_sector = linear_map_sector(ti, sector);
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
return 0;
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
}
EXPORT_SYMBOL_GPL(dm_linear_dax_copy_from_iter);
static size_t dm_linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
void *addr, size_t bytes, struct iov_iter *i)
{
struct linear_c *lc = ti->private;
struct block_device *bdev = lc->dev->bdev;
struct dax_device *dax_dev = lc->dev->dax_dev;
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
dev_sector = linear_map_sector(ti, sector);
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
return 0;
return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
}
#else
#define dm_linear_dax_direct_access NULL
#define dm_linear_dax_copy_from_iter NULL
#define dm_linear_dax_copy_to_iter NULL
#endif
static struct target_type linear_target = {
.name = "linear",
.version = {1, 4, 0},
#ifdef CONFIG_BLK_DEV_ZONED
.end_io = dm_linear_end_io,
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_ZONED_HM,
#else
.features = DM_TARGET_PASSES_INTEGRITY,
#endif
.module = THIS_MODULE,
.ctr = dm_linear_ctr,
.dtr = dm_linear_dtr,
.map = dm_linear_map,
.status = dm_linear_status,
.prepare_ioctl = dm_linear_prepare_ioctl,
.iterate_devices = dm_linear_iterate_devices,
.direct_access = dm_linear_dax_direct_access,
.dax_copy_from_iter = dm_linear_dax_copy_from_iter,
.dax_copy_to_iter = dm_linear_dax_copy_to_iter,
};
int __init dm_linear_init(void)
{
int r = dm_register_target(&linear_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
}
void dm_linear_exit(void)
{
dm_unregister_target(&linear_target);
}