Changes in 4.9.220 bus: sunxi-rsb: Return correct data when mixing 16-bit and 8-bit reads net: vxge: fix wrong __VA_ARGS__ usage qlcnic: Fix bad kzalloc null test i2c: st: fix missing struct parameter description irqchip/versatile-fpga: Handle chained IRQs properly sched: Avoid scale real weight down to zero selftests/x86/ptrace_syscall_32: Fix no-vDSO segfault libata: Remove extra scsi_host_put() in ata_scsi_add_hosts() gfs2: Don't demote a glock until its revokes are written x86/boot: Use unsigned comparison for addresses locking/lockdep: Avoid recursion in lockdep_count_{for,back}ward_deps() btrfs: remove a BUG_ON() from merge_reloc_roots() btrfs: track reloc roots based on their commit root bytenr misc: rtsx: set correct pcr_ops for rts522A ASoC: fix regwmask ASoC: dapm: connect virtual mux with default value ASoC: dpcm: allow start or stop during pause for backend ASoC: topology: use name_prefix for new kcontrol usb: gadget: f_fs: Fix use after free issue as part of queue failure usb: gadget: composite: Inform controller driver of self-powered ALSA: usb-audio: Add mixer workaround for TRX40 and co ALSA: hda: Add driver blacklist ALSA: hda: Fix potential access overflow in beep helper ALSA: ice1724: Fix invalid access for enumerated ctl items ALSA: pcm: oss: Fix regression by buffer overflow fix media: ti-vpe: cal: fix disable_irqs to only the intended target acpi/x86: ignore unspecified bit positions in the ACPI global lock field thermal: devfreq_cooling: inline all stubs for CONFIG_DEVFREQ_THERMAL=n KEYS: reaching the keys quotas correctly irqchip/versatile-fpga: Apply clear-mask earlier MIPS: OCTEON: irq: Fix potential NULL pointer dereference ath9k: Handle txpower changes even when TPC is disabled signal: Extend exec_id to 64bits x86/entry/32: Add missing ASM_CLAC to general_protection entry KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks KVM: s390: vsie: Fix delivery of addressing exceptions KVM: x86: Allocate new rmap and large page tracking when moving memslot KVM: VMX: Always VMCLEAR in-use VMCSes during crash with kexec support KVM: VMX: fix crash cleanup when KVM wasn't used btrfs: drop block from cache on error in relocation crypto: mxs-dcp - fix scatterlist linearization for hash ALSA: hda: Initialize power_state field properly x86/speculation: Remove redundant arch_smt_update() invocation tools: gpio: Fix out-of-tree build regression mm: Use fixed constant in page_frag_alloc instead of size + 1 dm verity fec: fix memory leak in verity_fec_dtr scsi: zfcp: fix missing erp_lock in port recovery trigger for point-to-point arm64: armv8_deprecated: Fix undef_hook mask for thumb setend rtc: omap: Use define directive for PIN_CONFIG_ACTIVE_HIGH ext4: fix a data race at inode->i_blocks ocfs2: no need try to truncate file beyond i_size s390/diag: fix display of diagnose call statistics Input: i8042 - add Acer Aspire 5738z to nomux list kmod: make request_module() return an error when autoloading is disabled cpufreq: powernv: Fix use-after-free hfsplus: fix crash and filesystem corruption when deleting files libata: Return correct status in sata_pmp_eh_recover_pm() when ATA_DFLAG_DETACH is set powerpc/64/tm: Don't let userspace set regs->trap via sigreturn Btrfs: fix crash during unmount due to race with delayed inode workers drm/dp_mst: Fix clearing payload state on topology disable drm: Remove PageReserved manipulation from drm_pci_alloc ipmi: fix hung processes in __get_guid() powerpc/fsl_booke: Avoid creating duplicate tlb1 entry misc: echo: Remove unnecessary parentheses and simplify check for zero mfd: dln2: Fix sanity checking for endpoints hsr: check protocol version in hsr_newlink() net: ipv4: devinet: Fix crash when add/del multicast IP with autojoin net: qrtr: send msgs from local of same id as broadcast net: ipv6: do not consider routes via gateways for anycast address check scsi: ufs: Fix ufshcd_hold() caused scheduling while atomic jbd2: improve comments about freeing data buffers whose page mapping is NULL ext4: fix incorrect group count in ext4_fill_super error message ext4: fix incorrect inodes per group in error message ASoC: Intel: mrfld: fix incorrect check on p->sink ASoC: Intel: mrfld: return error codes when an error occurs ALSA: usb-audio: Don't override ignore_ctl_error value from the map btrfs: check commit root generation in should_ignore_root mac80211_hwsim: Use kstrndup() in place of kasprintf() ext4: do not zeroout extents beyond i_disksize dm flakey: check for null arg_name in parse_features() kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD scsi: target: remove boilerplate code scsi: target: fix hang when multiple threads try to destroy the same iscsi session tracing: Fix the race between registering 'snapshot' event trigger and triggering 'snapshot' operation objtool: Fix switch table detection in .text.unlikely scsi: sg: add sg_remove_request in sg_common_write ALSA: hda: Don't release card at firmware loading error video: fbdev: sis: Remove unnecessary parentheses and commented code drm: NULL pointer dereference [null-pointer-deref] (CWE 476) problem Revert "gpio: set up initial state from .get_direction()" wil6210: increase firmware ready timeout wil6210: fix temperature debugfs scsi: ufs: make sure all interrupts are processed scsi: ufs: ufs-qcom: remove broken hci version quirk wil6210: rate limit wil_rx_refill error rtc: pm8xxx: Fix issue in RTC write path wil6210: fix length check in __wmi_send soc: qcom: smem: Use le32_to_cpu for comparison of: fix missing kobject init for !SYSFS && OF_DYNAMIC config arm64: cpu_errata: include required headers of: unittest: kmemleak in of_unittest_platform_populate() clk: at91: usb: continue if clk_hw_round_rate() return zero power: supply: bq27xxx_battery: Silence deferred-probe error clk: tegra: Fix Tegra PMC clock out parents NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails s390/cpuinfo: fix wrong output when CPU0 is offline powerpc/maple: Fix declaration made after definition ext4: do not commit super on read-only bdev percpu_counter: fix a data race at vm_committed_as compiler.h: fix error in BUILD_BUG_ON() reporting KVM: s390: vsie: Fix possible race when shadowing region 3 tables NFS: Fix memory leaks in nfs_pageio_stop_mirroring() ext2: fix empty body warnings when -Wextra is used ext2: fix debug reference to ext2_xattr_cache libnvdimm: Out of bounds read in __nd_ioctl() iommu/amd: Fix the configuration of GCR3 table root pointer fbdev: potential information leak in do_fb_ioctl() tty: evh_bytechan: Fix out of bounds accesses locktorture: Print ratio of acquisitions, not failures mtd: lpddr: Fix a double free in probe() mtd: phram: fix a double free issue in error path x86/CPU: Add native CPUID variants returning a single datum x86/microcode/intel: replace sync_core() with native_cpuid_reg(eax) x86/vdso: Fix lsl operand order Linux 4.9.220 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I130bead53d151b84c03bac575c0f3760e14538a6
464 lines
10 KiB
C
464 lines
10 KiB
C
/*
|
|
* Copyright (C) 2003 Sistina Software (UK) Limited.
|
|
* Copyright (C) 2004, 2010-2011 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is released under the GPL.
|
|
*/
|
|
|
|
#include <linux/device-mapper.h>
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/bio.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define DM_MSG_PREFIX "flakey"
|
|
|
|
#define all_corrupt_bio_flags_match(bio, fc) \
|
|
(((bio)->bi_opf & (fc)->corrupt_bio_flags) == (fc)->corrupt_bio_flags)
|
|
|
|
/*
|
|
* Flakey: Used for testing only, simulates intermittent,
|
|
* catastrophic device failure.
|
|
*/
|
|
struct flakey_c {
|
|
struct dm_dev *dev;
|
|
unsigned long start_time;
|
|
sector_t start;
|
|
unsigned up_interval;
|
|
unsigned down_interval;
|
|
unsigned long flags;
|
|
unsigned corrupt_bio_byte;
|
|
unsigned corrupt_bio_rw;
|
|
unsigned corrupt_bio_value;
|
|
unsigned corrupt_bio_flags;
|
|
};
|
|
|
|
enum feature_flag_bits {
|
|
DROP_WRITES
|
|
};
|
|
|
|
struct per_bio_data {
|
|
bool bio_submitted;
|
|
};
|
|
|
|
static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
|
|
struct dm_target *ti)
|
|
{
|
|
int r;
|
|
unsigned argc;
|
|
const char *arg_name;
|
|
|
|
static struct dm_arg _args[] = {
|
|
{0, 6, "Invalid number of feature args"},
|
|
{1, UINT_MAX, "Invalid corrupt bio byte"},
|
|
{0, 255, "Invalid corrupt value to write into bio byte (0-255)"},
|
|
{0, UINT_MAX, "Invalid corrupt bio flags mask"},
|
|
};
|
|
|
|
/* No feature arguments supplied. */
|
|
if (!as->argc)
|
|
return 0;
|
|
|
|
r = dm_read_arg_group(_args, as, &argc, &ti->error);
|
|
if (r)
|
|
return r;
|
|
|
|
while (argc) {
|
|
arg_name = dm_shift_arg(as);
|
|
argc--;
|
|
|
|
if (!arg_name) {
|
|
ti->error = "Insufficient feature arguments";
|
|
return -EINVAL;
|
|
}
|
|
|
|
/*
|
|
* drop_writes
|
|
*/
|
|
if (!strcasecmp(arg_name, "drop_writes")) {
|
|
if (test_and_set_bit(DROP_WRITES, &fc->flags)) {
|
|
ti->error = "Feature drop_writes duplicated";
|
|
return -EINVAL;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
/*
|
|
* corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>
|
|
*/
|
|
if (!strcasecmp(arg_name, "corrupt_bio_byte")) {
|
|
if (!argc) {
|
|
ti->error = "Feature corrupt_bio_byte requires parameters";
|
|
return -EINVAL;
|
|
}
|
|
|
|
r = dm_read_arg(_args + 1, as, &fc->corrupt_bio_byte, &ti->error);
|
|
if (r)
|
|
return r;
|
|
argc--;
|
|
|
|
/*
|
|
* Direction r or w?
|
|
*/
|
|
arg_name = dm_shift_arg(as);
|
|
if (!strcasecmp(arg_name, "w"))
|
|
fc->corrupt_bio_rw = WRITE;
|
|
else if (!strcasecmp(arg_name, "r"))
|
|
fc->corrupt_bio_rw = READ;
|
|
else {
|
|
ti->error = "Invalid corrupt bio direction (r or w)";
|
|
return -EINVAL;
|
|
}
|
|
argc--;
|
|
|
|
/*
|
|
* Value of byte (0-255) to write in place of correct one.
|
|
*/
|
|
r = dm_read_arg(_args + 2, as, &fc->corrupt_bio_value, &ti->error);
|
|
if (r)
|
|
return r;
|
|
argc--;
|
|
|
|
/*
|
|
* Only corrupt bios with these flags set.
|
|
*/
|
|
r = dm_read_arg(_args + 3, as, &fc->corrupt_bio_flags, &ti->error);
|
|
if (r)
|
|
return r;
|
|
argc--;
|
|
|
|
continue;
|
|
}
|
|
|
|
ti->error = "Unrecognised flakey feature requested";
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (test_bit(DROP_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) {
|
|
ti->error = "drop_writes is incompatible with corrupt_bio_byte with the WRITE flag set";
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Construct a flakey mapping:
|
|
* <dev_path> <offset> <up interval> <down interval> [<#feature args> [<arg>]*]
|
|
*
|
|
* Feature args:
|
|
* [drop_writes]
|
|
* [corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>]
|
|
*
|
|
* Nth_byte starts from 1 for the first byte.
|
|
* Direction is r for READ or w for WRITE.
|
|
* bio_flags is ignored if 0.
|
|
*/
|
|
static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
|
|
{
|
|
static struct dm_arg _args[] = {
|
|
{0, UINT_MAX, "Invalid up interval"},
|
|
{0, UINT_MAX, "Invalid down interval"},
|
|
};
|
|
|
|
int r;
|
|
struct flakey_c *fc;
|
|
unsigned long long tmpll;
|
|
struct dm_arg_set as;
|
|
const char *devname;
|
|
char dummy;
|
|
|
|
as.argc = argc;
|
|
as.argv = argv;
|
|
|
|
if (argc < 4) {
|
|
ti->error = "Invalid argument count";
|
|
return -EINVAL;
|
|
}
|
|
|
|
fc = kzalloc(sizeof(*fc), GFP_KERNEL);
|
|
if (!fc) {
|
|
ti->error = "Cannot allocate context";
|
|
return -ENOMEM;
|
|
}
|
|
fc->start_time = jiffies;
|
|
|
|
devname = dm_shift_arg(&as);
|
|
|
|
r = -EINVAL;
|
|
if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) {
|
|
ti->error = "Invalid device sector";
|
|
goto bad;
|
|
}
|
|
fc->start = tmpll;
|
|
|
|
r = dm_read_arg(_args, &as, &fc->up_interval, &ti->error);
|
|
if (r)
|
|
goto bad;
|
|
|
|
r = dm_read_arg(_args, &as, &fc->down_interval, &ti->error);
|
|
if (r)
|
|
goto bad;
|
|
|
|
if (!(fc->up_interval + fc->down_interval)) {
|
|
ti->error = "Total (up + down) interval is zero";
|
|
r = -EINVAL;
|
|
goto bad;
|
|
}
|
|
|
|
if (fc->up_interval + fc->down_interval < fc->up_interval) {
|
|
ti->error = "Interval overflow";
|
|
r = -EINVAL;
|
|
goto bad;
|
|
}
|
|
|
|
r = parse_features(&as, fc, ti);
|
|
if (r)
|
|
goto bad;
|
|
|
|
r = dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev);
|
|
if (r) {
|
|
ti->error = "Device lookup failed";
|
|
goto bad;
|
|
}
|
|
|
|
ti->num_flush_bios = 1;
|
|
ti->num_discard_bios = 1;
|
|
ti->per_io_data_size = sizeof(struct per_bio_data);
|
|
ti->private = fc;
|
|
return 0;
|
|
|
|
bad:
|
|
kfree(fc);
|
|
return r;
|
|
}
|
|
|
|
static void flakey_dtr(struct dm_target *ti)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
|
|
dm_put_device(ti, fc->dev);
|
|
kfree(fc);
|
|
}
|
|
|
|
static sector_t flakey_map_sector(struct dm_target *ti, sector_t bi_sector)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
|
|
return fc->start + dm_target_offset(ti, bi_sector);
|
|
}
|
|
|
|
static void flakey_map_bio(struct dm_target *ti, struct bio *bio)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
|
|
bio->bi_bdev = fc->dev->bdev;
|
|
if (bio_sectors(bio))
|
|
bio->bi_iter.bi_sector =
|
|
flakey_map_sector(ti, bio->bi_iter.bi_sector);
|
|
}
|
|
|
|
static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)
|
|
{
|
|
unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1;
|
|
|
|
struct bvec_iter iter;
|
|
struct bio_vec bvec;
|
|
|
|
if (!bio_has_data(bio))
|
|
return;
|
|
|
|
/*
|
|
* Overwrite the Nth byte of the bio's data, on whichever page
|
|
* it falls.
|
|
*/
|
|
bio_for_each_segment(bvec, bio, iter) {
|
|
if (bio_iter_len(bio, iter) > corrupt_bio_byte) {
|
|
char *segment = (page_address(bio_iter_page(bio, iter))
|
|
+ bio_iter_offset(bio, iter));
|
|
segment[corrupt_bio_byte] = fc->corrupt_bio_value;
|
|
DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
|
|
"(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n",
|
|
bio, fc->corrupt_bio_value, fc->corrupt_bio_byte,
|
|
(bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
|
|
(unsigned long long)bio->bi_iter.bi_sector, bio->bi_iter.bi_size);
|
|
break;
|
|
}
|
|
corrupt_bio_byte -= bio_iter_len(bio, iter);
|
|
}
|
|
}
|
|
|
|
static int flakey_map(struct dm_target *ti, struct bio *bio)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
unsigned elapsed;
|
|
struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
|
|
pb->bio_submitted = false;
|
|
|
|
/* Are we alive ? */
|
|
elapsed = (jiffies - fc->start_time) / HZ;
|
|
if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {
|
|
/*
|
|
* Flag this bio as submitted while down.
|
|
*/
|
|
pb->bio_submitted = true;
|
|
|
|
/*
|
|
* Error reads if neither corrupt_bio_byte or drop_writes are set.
|
|
* Otherwise, flakey_end_io() will decide if the reads should be modified.
|
|
*/
|
|
if (bio_data_dir(bio) == READ) {
|
|
if (!fc->corrupt_bio_byte && !test_bit(DROP_WRITES, &fc->flags))
|
|
return -EIO;
|
|
goto map_bio;
|
|
}
|
|
|
|
/*
|
|
* Drop writes?
|
|
*/
|
|
if (test_bit(DROP_WRITES, &fc->flags)) {
|
|
bio_endio(bio);
|
|
return DM_MAPIO_SUBMITTED;
|
|
}
|
|
|
|
/*
|
|
* Corrupt matching writes.
|
|
*/
|
|
if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == WRITE)) {
|
|
if (all_corrupt_bio_flags_match(bio, fc))
|
|
corrupt_bio_data(bio, fc);
|
|
goto map_bio;
|
|
}
|
|
|
|
/*
|
|
* By default, error all I/O.
|
|
*/
|
|
return -EIO;
|
|
}
|
|
|
|
map_bio:
|
|
flakey_map_bio(ti, bio);
|
|
|
|
return DM_MAPIO_REMAPPED;
|
|
}
|
|
|
|
static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
|
|
|
|
if (!error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
|
|
if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
|
|
all_corrupt_bio_flags_match(bio, fc)) {
|
|
/*
|
|
* Corrupt successful matching READs while in down state.
|
|
*/
|
|
corrupt_bio_data(bio, fc);
|
|
|
|
} else if (!test_bit(DROP_WRITES, &fc->flags)) {
|
|
/*
|
|
* Error read during the down_interval if drop_writes
|
|
* wasn't configured.
|
|
*/
|
|
return -EIO;
|
|
}
|
|
}
|
|
|
|
return error;
|
|
}
|
|
|
|
static void flakey_status(struct dm_target *ti, status_type_t type,
|
|
unsigned status_flags, char *result, unsigned maxlen)
|
|
{
|
|
unsigned sz = 0;
|
|
struct flakey_c *fc = ti->private;
|
|
unsigned drop_writes;
|
|
|
|
switch (type) {
|
|
case STATUSTYPE_INFO:
|
|
result[0] = '\0';
|
|
break;
|
|
|
|
case STATUSTYPE_TABLE:
|
|
DMEMIT("%s %llu %u %u ", fc->dev->name,
|
|
(unsigned long long)fc->start, fc->up_interval,
|
|
fc->down_interval);
|
|
|
|
drop_writes = test_bit(DROP_WRITES, &fc->flags);
|
|
DMEMIT("%u ", drop_writes + (fc->corrupt_bio_byte > 0) * 5);
|
|
|
|
if (drop_writes)
|
|
DMEMIT("drop_writes ");
|
|
|
|
if (fc->corrupt_bio_byte)
|
|
DMEMIT("corrupt_bio_byte %u %c %u %u ",
|
|
fc->corrupt_bio_byte,
|
|
(fc->corrupt_bio_rw == WRITE) ? 'w' : 'r',
|
|
fc->corrupt_bio_value, fc->corrupt_bio_flags);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int flakey_prepare_ioctl(struct dm_target *ti,
|
|
struct block_device **bdev, fmode_t *mode)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
|
|
*bdev = fc->dev->bdev;
|
|
|
|
/*
|
|
* Only pass ioctls through if the device sizes match exactly.
|
|
*/
|
|
if (fc->start ||
|
|
ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data)
|
|
{
|
|
struct flakey_c *fc = ti->private;
|
|
|
|
return fn(ti, fc->dev, fc->start, ti->len, data);
|
|
}
|
|
|
|
static struct target_type flakey_target = {
|
|
.name = "flakey",
|
|
.version = {1, 3, 1},
|
|
.module = THIS_MODULE,
|
|
.ctr = flakey_ctr,
|
|
.dtr = flakey_dtr,
|
|
.map = flakey_map,
|
|
.end_io = flakey_end_io,
|
|
.status = flakey_status,
|
|
.prepare_ioctl = flakey_prepare_ioctl,
|
|
.iterate_devices = flakey_iterate_devices,
|
|
};
|
|
|
|
static int __init dm_flakey_init(void)
|
|
{
|
|
int r = dm_register_target(&flakey_target);
|
|
|
|
if (r < 0)
|
|
DMERR("register failed %d", r);
|
|
|
|
return r;
|
|
}
|
|
|
|
static void __exit dm_flakey_exit(void)
|
|
{
|
|
dm_unregister_target(&flakey_target);
|
|
}
|
|
|
|
/* Module hooks */
|
|
module_init(dm_flakey_init);
|
|
module_exit(dm_flakey_exit);
|
|
|
|
MODULE_DESCRIPTION(DM_NAME " flakey target");
|
|
MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
|
|
MODULE_LICENSE("GPL");
|