07a9371271
https://source.android.com/security/bulletin/2021-05-01 CVE-2020-29661 * tag 'ASB-2021-05-05_4.19-stable' of https://github.com/aosp-mirror/kernel_common: ANDROID: Add allowed symbols requried from Qualcomm drivers ANDROID: GKI: QoS: Prevent usage of dev_pm_qos_request as pm_qos_request Linux 4.19.189 USB: CDC-ACM: fix poison/unpoison imbalance net: hso: fix NULL-deref on disconnect regression x86/crash: Fix crash_setup_memmap_entries() out-of-bounds access ia64: tools: remove duplicate definition of ia64_mf() on ia64 ia64: fix discontig.c section mismatches cavium/liquidio: Fix duplicate argument xen-netback: Check for hotplug-status existence before watching s390/entry: save the caller of psw_idle net: geneve: check skb is large enough for IPv4/IPv6 header ARM: dts: Fix swapped mmc order for omap3 HID: wacom: Assign boolean values to a bool variable HID: alps: fix error return code in alps_input_configured() HID: google: add don USB id perf/x86/intel/uncore: Remove uncore extra PCI dev HSWEP_PCI_PCU_3 locking/qrwlock: Fix ordering in queued_write_lock_slowpath() pinctrl: lewisburg: Update number of pins in community gup: document and work around "COW can break either way" issue net: phy: marvell: fix detection of PHY on Topaz switches ARM: 9071/1: uprobes: Don't hook on thumb instructions ARM: footbridge: fix PCI interrupt mapping ibmvnic: remove duplicate napi_schedule call in open function ibmvnic: remove duplicate napi_schedule call in do_reset function ibmvnic: avoid calling napi_disable() twice i40e: fix the panic when running bpf in xdpdrv mode net: ip6_tunnel: Unregister catch-all devices net: sit: Unregister catch-all devices net: davicom: Fix regulator not turned off on failed probe netfilter: nft_limit: avoid possible divide error in nft_limit_init netfilter: conntrack: do not print icmpv6 as unknown via /proc scsi: libsas: Reset num_scatter if libata marks qc as NODATA arm64: alternatives: Move length validation in alternative_{insn, endif} arm64: fix inline asm in load_unaligned_zeropad() readdir: make sure to verify directory entry for legacy interfaces too dm verity fec: fix misaligned RS roots IO HID: wacom: set EV_KEY and EV_ABS only for non-HID_GENERIC type of devices Input: i8042 - fix Pegatron C15B ID entry Input: s6sy761 - fix coordinate read bit shift mac80211: clear sta->fast_rx when STA removed from 4-addr VLAN pcnet32: Use pci_resource_len to validate PCI resource net: ieee802154: forbid monitor for add llsec seclevel net: ieee802154: stop dump llsec seclevels for monitors net: ieee802154: forbid monitor for add llsec devkey net: ieee802154: stop dump llsec devkeys for monitors net: ieee802154: forbid monitor for add llsec dev net: ieee802154: stop dump llsec devs for monitors net: ieee802154: stop dump llsec keys for monitors scsi: scsi_transport_srp: Don't block target in SRP_PORT_LOST state ASoC: fsl_esai: Fix TDM slot setup for I2S mode drm/msm: Fix a5xx/a6xx timestamps ARM: keystone: fix integer overflow warning neighbour: Disregard DEAD dst in neigh_update arc: kernel: Return -EFAULT if copy_to_user() fails lockdep: Add a missing initialization hint to the "INFO: Trying to register non-static key" message ARM: dts: Fix moving mmc devices with aliases for omap4 & 5 ARM: dts: Drop duplicate sha2md5_fck to fix clk_disable race dmaengine: dw: Make it dependent to HAS_IOMEM gpio: sysfs: Obey valid_mask Input: nspire-keypad - enable interrupts only when opened net/sctp: fix race condition in sctp_destroy_sock ANDROID: GKI: update allowed list for incrementalfs.ko ANDROID: fs-verity: Export function to check signatures UPSTREAM: fs-verity: move structs needed for file signing to UAPI header UPSTREAM: fs-verity: rename "file measurement" to "file digest" UPSTREAM: fs-verity: rename fsverity_signed_digest to fsverity_formatted_digest UPSTREAM: fs-verity: remove filenames from file comments ANDROID: clang: update to 12.0.5 Linux 4.19.188 xen/events: fix setting irq affinity perf map: Tighten snprintf() string precision to pass gcc check on some 32-bit arches driver core: Fix locking bug in deferred_probe_timeout_work_func() netfilter: x_tables: fix compat match/target pad out-of-bound write staging: m57621-mmc: delete driver from the tree. net: phy: broadcom: Only advertise EEE for supported modes riscv,entry: fix misaligned base for excp_vect_table block: only update parent bi_status when bio fail drm/tegra: dc: Don't set PLL clock to 0Hz gfs2: report "already frozen/thawed" errors drm/imx: imx-ldb: fix out of bounds array access warning KVM: arm64: Disable guest access to trace filter controls KVM: arm64: Hide system instruction access to Trace registers Revert "net: xfrm: Localize sequence counter per network namespace" ANDROID: Incremental fs: Set credentials before reading/writing Linux 4.19.187 Revert "cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath." net: ieee802154: stop dump llsec params for monitors net: ieee802154: forbid monitor for del llsec seclevel net: ieee802154: forbid monitor for set llsec params net: ieee802154: fix nl802154 del llsec devkey net: ieee802154: fix nl802154 add llsec key net: ieee802154: fix nl802154 del llsec dev net: ieee802154: fix nl802154 del llsec key net: ieee802154: nl-mac: fix check on panid net: mac802154: Fix general protection fault drivers: net: fix memory leak in peak_usb_create_dev drivers: net: fix memory leak in atusb_probe net: tun: set tun->dev->addr_len during TUNSETLINK processing cfg80211: remove WARN_ON() in cfg80211_sme_connect net: sched: bump refcount for new action in ACT replace mode clk: socfpga: fix iomem pointer cast on 64-bit RDMA/cxgb4: check for ipv6 address properly while destroying listener net/mlx5: Fix PBMC register mapping net/mlx5: Fix placement of log_max_flow_counter s390/cpcmd: fix inline assembly register clobbering workqueue: Move the position of debug_work_activate() in __queue_work() clk: fix invalid usage of list cursor in unregister clk: fix invalid usage of list cursor in register soc/fsl: qbman: fix conflicting alignment attributes ASoC: sunxi: sun4i-codec: fill ASoC card owner net/ncsi: Avoid channel_monitor hrtimer deadlock ARM: dts: imx6: pbab01: Set vmmc supply for both SD interfaces net:tipc: Fix a double free in tipc_sk_mcast_rcv cxgb4: avoid collecting SGE_QBASE regs during traffic gianfar: Handle error code at MAC address change sch_red: fix off-by-one checks in red_check_params() amd-xgbe: Update DMA coherency values i40e: Fix kernel oops when i40e driver removes VF's i40e: Added Asym_Pause to supported link modes ASoC: wm8960: Fix wrong bclk and lrclk with pll enabled for some chips net: xfrm: Localize sequence counter per network namespace regulator: bd9571mwv: Fix AVS and DVFS voltage range xfrm: interface: fix ipv4 pmtu check to honor ip header df virtio_net: Add XDP meta data support i2c: turn recovery error on init to debug usbip: synchronize event handler with sysfs code paths usbip: vudc synchronize sysfs code paths usbip: stub-dev synchronize sysfs code paths usbip: add sysfs_lock to synchronize sysfs code paths net-ipv6: bugfix - raw & sctp - switch to ipv6_can_nonlocal_bind() net: sched: sch_teql: fix null-pointer dereference net: ensure mac header is set in virtio_net_hdr_to_skb() net: hso: fix null-ptr-deref during tty device unregistration ice: Increase control queue timeout batman-adv: initialize "struct batadv_tvlv_tt_vlan_data"->reserved field ARM: dts: turris-omnia: configure LED[2]/INTn pin as interrupt pin parisc: avoid a warning on u8 cast for cmpxchg on u8 pointers parisc: parisc-agp requires SBA IOMMU driver fs: direct-io: fix missing sdio->boundary ocfs2: fix deadlock between setattr and dio_end_io_write nds32: flush_dcache_page: use page_mapping_file to avoid races with swapoff ia64: fix user_stack_pointer() for ptrace() net: ipv6: check for validity before dereferencing cfg->fc_nlinfo.nlh xen/evtchn: Change irq_info lock to raw_spinlock_t nfc: Avoid endless loops caused by repeated llcp_sock_connect() nfc: fix memory leak in llcp_sock_connect() nfc: fix refcount leak in llcp_sock_connect() nfc: fix refcount leak in llcp_sock_bind() ASoC: intel: atom: Stop advertising non working S24LE support ALSA: aloop: Fix initialization of controls Linux 4.19.186 init/Kconfig: make COMPILE_TEST depend on HAS_IOMEM init/Kconfig: make COMPILE_TEST depend on !S390 bpf, x86: Validate computation of branch displacements for x86-32 bpf, x86: Validate computation of branch displacements for x86-64 cifs: Silently ignore unknown oplock break handle cifs: revalidate mapping when we open files for SMB1 POSIX ia64: fix format strings for err_inject ia64: mca: allocate early mca with GFP_ATOMIC scsi: target: pscsi: Clean up after failure in pscsi_map_sg() x86/build: Turn off -fcf-protection for realmode targets platform/x86: thinkpad_acpi: Allow the FnLock LED to change state drm/msm: Ratelimit invalid-fence message mac80211: choose first enabled channel for monitor mISDN: fix crash in fritzpci net: pxa168_eth: Fix a potential data race in pxa168_eth_remove platform/x86: intel-hid: Support Lenovo ThinkPad X1 Tablet Gen 2 bus: ti-sysc: Fix warning on unbind if reset is not deasserted ARM: dts: am33xx: add aliases for mmc interfaces Linux 4.19.185 drivers: video: fbcon: fix NULL dereference in fbcon_cursor() staging: rtl8192e: Change state information from u16 to u8 staging: rtl8192e: Fix incorrect source in memcpy() usb: dwc2: Fix HPRT0.PrtSusp bit setting for HiKey 960 board. usb: gadget: udc: amd5536udc_pci fix null-ptr-dereference USB: cdc-acm: fix use-after-free after probe failure USB: cdc-acm: fix double free on probe failure USB: cdc-acm: downgrade message to debug USB: cdc-acm: untangle a circular dependency between callback and softint cdc-acm: fix BREAK rx code path adding necessary calls usb: xhci-mtk: fix broken streams issue on 0.96 xHCI usb: musb: Fix suspend with devices connected for a64 USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem usbip: vhci_hcd fix shift out-of-bounds in vhci_hub_control() firewire: nosy: Fix a use-after-free bug in nosy_ioctl() extcon: Fix error handling in extcon_dev_register extcon: Add stubs for extcon_register_notifier_all() functions pinctrl: rockchip: fix restore error in resume reiserfs: update reiserfs_xattrs_initialized() condition drm/amdgpu: check alignment on CPU page for bo map drm/amdgpu: fix offset calculation in amdgpu_vm_bo_clear_mappings() mm: fix race by making init_zero_pfn() early_initcall tracing: Fix stack trace event size PM: runtime: Fix ordering in pm_runtime_get_suppliers() PM: runtime: Fix race getting/putting suppliers at probe ALSA: hda/realtek: call alc_update_headset_mode() in hp_automute_hook ALSA: hda/realtek: fix a determine_headset_type issue for a Dell AIO ALSA: usb-audio: Apply sample rate quirk to Logitech Connect bpf: Remove MTU check in __bpf_skb_max_len net: wan/lmc: unregister device when no matching device is found appletalk: Fix skb allocation size in loopback case net: ethernet: aquantia: Handle error cleanup of start on open ath10k: hold RCU lock when calling ieee80211_find_sta_by_ifaddr() brcmfmac: clear EAP/association status bits on linkdown events ext4: do not iput inode under running transaction in ext4_rename() locking/ww_mutex: Simplify use_ww_ctx & ww_ctx handling thermal/core: Add NULL pointer check before using cooling device stats ASoC: rt5659: Update MCLK rate in set_sysclk() staging: comedi: cb_pcidas64: fix request_irq() warn staging: comedi: cb_pcidas: fix request_irq() warn scsi: qla2xxx: Fix broken #endif placement scsi: st: Fix a use after free in st_open() vhost: Fix vhost_vq_reset() ASoC: cs42l42: Always wait at least 3ms after reset ASoC: cs42l42: Fix mixer volume control ASoC: cs42l42: Fix channel width support ASoC: cs42l42: Fix Bitclock polarity inversion ASoC: es8316: Simplify adc_pga_gain_tlv table ASoC: sgtl5000: set DAP_AVC_CTRL register to correct default value on probe ASoC: rt5651: Fix dac- and adc- vol-tlv values being off by a factor of 10 ASoC: rt5640: Fix dac- and adc- vol-tlv values being off by a factor of 10 rpc: fix NULL dereference on kmalloc failure ext4: fix bh ref count on error paths ipv6: weaken the v4mapped source check tcp: relookup sock for RST+ACK packets handled by obsolete req sock selinux: vsock: Set SID for socket returned by accept() Revert "can: dev: Move device back to init netns on owning netns delete" Linux 4.19.184 xen-blkback: don't leak persistent grants from xen_blkbk_map() can: peak_usb: Revert "can: peak_usb: add forgotten supported devices" ext4: add reclaim checks to xattr code mac80211: fix double free in ibss_leave net: qrtr: fix a kernel-infoleak in qrtr_recvmsg() net: sched: validate stab values can: dev: Move device back to init netns on owning netns delete x86/mem_encrypt: Correct physical address calculation in __set_clr_pte_enc() locking/mutex: Fix non debug version of mutex_lock_io_nested() scsi: mpt3sas: Fix error return code of mpt3sas_base_attach() scsi: qedi: Fix error return code of qedi_alloc_global_queues() perf auxtrace: Fix auxtrace queue conflict dm verity: add root hash pkcs#7 signature verification ACPI: scan: Use unique number for instance_no ACPI: scan: Rearrange memory allocation in acpi_device_add() Revert "netfilter: x_tables: Update remaining dereference to RCU" netfilter: x_tables: Use correct memory barriers. Revert "netfilter: x_tables: Switch synchronization to RCU" bpf: Don't do bpf_cgroup_storage_set() for kuprobe/tp programs RDMA/cxgb4: Fix adapter LE hash errors while destroying ipv6 listening server net/mlx5e: Fix error path for ethtool set-priv-flag arm64: kdump: update ppos when reading elfcorehdr drm/msm: fix shutdown hook in case GPU components failed to bind net: stmmac: dwmac-sun8i: Provide TX and RX fifo sizes net: cdc-phonet: fix data-interface release on probe failure mac80211: fix rate mask reset can: m_can: m_can_do_rx_poll(): fix extraneous msg loss warning can: c_can: move runtime PM enable/disable to c_can_platform can: c_can_pci: c_can_pci_remove(): fix use-after-free can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate can: peak_usb: add forgotten supported devices netfilter: ctnetlink: fix dump of the expect mask attribute ftgmac100: Restart MAC HW once net/qlcnic: Fix a use after free in qlcnic_83xx_get_minidump_template e1000e: Fix error handling in e1000_set_d0_lplu_state_82571 e1000e: add rtnl_lock() to e1000_reset_task net: dsa: bcm_sf2: Qualify phydev->dev_flags based on port macvlan: macvlan_count_rx() needs to be aware of preemption libbpf: Fix INSTALL flag order veth: Store queue_mapping independently of XDP prog presence bus: omap_l3_noc: mark l3 irqs as IRQF_NO_THREAD dm ioctl: fix out of bounds array access when no devices ARM: dts: at91-sama5d27_som1: fix phy address to 7 arm64: dts: ls1043a: mark crypto engine dma coherent arm64: dts: ls1012a: mark crypto engine dma coherent arm64: dts: ls1046a: mark crypto engine dma coherent squashfs: fix xattr id and id lookup sanity checks squashfs: fix inode lookup sanity checks platform/x86: intel-vbtn: Stop reporting SW_DOCK events netsec: restore phy power state after controller reset ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls block: Suppress uevent for hidden device when removed nfs: we don't support removing system.nfs4_acl drm/radeon: fix AGP dependency u64_stats,lockdep: Fix u64_stats_init() vs lockdep sparc64: Fix opcode filtering in handling of no fault loads atm: idt77252: fix null-ptr-dereference atm: uPD98402: fix incorrect allocation net: wan: fix error return code of uhdlc_init() net: hisilicon: hns: fix error return code of hns_nic_clear_all_rx_fetch() NFS: Correct size calculation for create reply length nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default gpiolib: acpi: Add missing IRQF_ONESHOT gianfar: fix jumbo packets+napi+rx overrun crash sun/niu: fix wrong RXMAC_BC_FRM_CNT_COUNT count net: tehuti: fix error return code in bdx_probe() ixgbe: Fix memleak in ixgbe_configure_clsu32 Revert "r8152: adjust the settings about MAC clock speed down for RTL8153" atm: lanai: dont run lanai_dev_close if not open atm: eni: dont release is never initialized powerpc/4xx: Fix build errors from mfdcr() net: fec: ptp: avoid register access when ipg clock is disabled Change-Id: Iba7c8569b32ea50c97004cf182ccd907a3022d0b Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com> Conflicts: kernel/locking/lockdep.c kernel/power/qos.c net/qrtr/qrtr.c
871 lines
22 KiB
C
871 lines
22 KiB
C
/*
|
|
* Copyright (C) 2015 Google, Inc.
|
|
*
|
|
* Author: Sami Tolvanen <samitolvanen@google.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*/
|
|
|
|
#include "dm-verity-fec.h"
|
|
#include <linux/math64.h>
|
|
#include <linux/sysfs.h>
|
|
|
|
#define DM_MSG_PREFIX "verity-fec"
|
|
|
|
/*
|
|
* If error correction has been configured, returns true.
|
|
*/
|
|
bool verity_fec_is_enabled(struct dm_verity *v)
|
|
{
|
|
return v->fec && v->fec->dev;
|
|
}
|
|
|
|
/*
|
|
* Return a pointer to dm_verity_fec_io after dm_verity_io and its variable
|
|
* length fields.
|
|
*/
|
|
static inline struct dm_verity_fec_io *fec_io(struct dm_verity_io *io)
|
|
{
|
|
return (struct dm_verity_fec_io *) verity_io_digest_end(io->v, io);
|
|
}
|
|
|
|
/*
|
|
* Return an interleaved offset for a byte in RS block.
|
|
*/
|
|
static inline u64 fec_interleave(struct dm_verity *v, u64 offset)
|
|
{
|
|
u32 mod;
|
|
|
|
mod = do_div(offset, v->fec->rsn);
|
|
return offset + mod * (v->fec->rounds << v->data_dev_block_bits);
|
|
}
|
|
|
|
/*
|
|
* Decode an RS block using Reed-Solomon.
|
|
*/
|
|
static int fec_decode_rs8(struct dm_verity *v, struct dm_verity_fec_io *fio,
|
|
u8 *data, u8 *fec, int neras)
|
|
{
|
|
int i;
|
|
uint16_t par[DM_VERITY_FEC_RSM - DM_VERITY_FEC_MIN_RSN];
|
|
|
|
for (i = 0; i < v->fec->roots; i++)
|
|
par[i] = fec[i];
|
|
|
|
return decode_rs8(fio->rs, data, par, v->fec->rsn, NULL, neras,
|
|
fio->erasures, 0, NULL);
|
|
}
|
|
|
|
/*
|
|
* Read error-correcting codes for the requested RS block. Returns a pointer
|
|
* to the data block. Caller is responsible for releasing buf.
|
|
*/
|
|
static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
|
|
unsigned *offset, struct dm_buffer **buf)
|
|
{
|
|
u64 position, block, rem;
|
|
u8 *res;
|
|
|
|
position = (index + rsb) * v->fec->roots;
|
|
block = div64_u64_rem(position, v->fec->io_size, &rem);
|
|
*offset = (unsigned)rem;
|
|
|
|
res = dm_bufio_read(v->fec->bufio, block, buf);
|
|
if (unlikely(IS_ERR(res))) {
|
|
DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
|
|
v->data_dev->name, (unsigned long long)rsb,
|
|
(unsigned long long)block, PTR_ERR(res));
|
|
*buf = NULL;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
/* Loop over each preallocated buffer slot. */
|
|
#define fec_for_each_prealloc_buffer(__i) \
|
|
for (__i = 0; __i < DM_VERITY_FEC_BUF_PREALLOC; __i++)
|
|
|
|
/* Loop over each extra buffer slot. */
|
|
#define fec_for_each_extra_buffer(io, __i) \
|
|
for (__i = DM_VERITY_FEC_BUF_PREALLOC; __i < DM_VERITY_FEC_BUF_MAX; __i++)
|
|
|
|
/* Loop over each allocated buffer. */
|
|
#define fec_for_each_buffer(io, __i) \
|
|
for (__i = 0; __i < (io)->nbufs; __i++)
|
|
|
|
/* Loop over each RS block in each allocated buffer. */
|
|
#define fec_for_each_buffer_rs_block(io, __i, __j) \
|
|
fec_for_each_buffer(io, __i) \
|
|
for (__j = 0; __j < 1 << DM_VERITY_FEC_BUF_RS_BITS; __j++)
|
|
|
|
/*
|
|
* Return a pointer to the current RS block when called inside
|
|
* fec_for_each_buffer_rs_block.
|
|
*/
|
|
static inline u8 *fec_buffer_rs_block(struct dm_verity *v,
|
|
struct dm_verity_fec_io *fio,
|
|
unsigned i, unsigned j)
|
|
{
|
|
return &fio->bufs[i][j * v->fec->rsn];
|
|
}
|
|
|
|
/*
|
|
* Return an index to the current RS block when called inside
|
|
* fec_for_each_buffer_rs_block.
|
|
*/
|
|
static inline unsigned fec_buffer_rs_index(unsigned i, unsigned j)
|
|
{
|
|
return (i << DM_VERITY_FEC_BUF_RS_BITS) + j;
|
|
}
|
|
|
|
/*
|
|
* Decode all RS blocks from buffers and copy corrected bytes into fio->output
|
|
* starting from block_offset.
|
|
*/
|
|
static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
|
|
u64 rsb, int byte_index, unsigned block_offset,
|
|
int neras)
|
|
{
|
|
int r, corrected = 0, res;
|
|
struct dm_buffer *buf;
|
|
unsigned n, i, offset;
|
|
u8 *par, *block;
|
|
|
|
par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
|
|
if (IS_ERR(par))
|
|
return PTR_ERR(par);
|
|
|
|
/*
|
|
* Decode the RS blocks we have in bufs. Each RS block results in
|
|
* one corrected target byte and consumes fec->roots parity bytes.
|
|
*/
|
|
fec_for_each_buffer_rs_block(fio, n, i) {
|
|
block = fec_buffer_rs_block(v, fio, n, i);
|
|
res = fec_decode_rs8(v, fio, block, &par[offset], neras);
|
|
if (res < 0) {
|
|
r = res;
|
|
goto error;
|
|
}
|
|
|
|
corrected += res;
|
|
fio->output[block_offset] = block[byte_index];
|
|
|
|
block_offset++;
|
|
if (block_offset >= 1 << v->data_dev_block_bits)
|
|
goto done;
|
|
|
|
/* read the next block when we run out of parity bytes */
|
|
offset += v->fec->roots;
|
|
if (offset >= v->fec->io_size) {
|
|
dm_bufio_release(buf);
|
|
|
|
par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
|
|
if (unlikely(IS_ERR(par)))
|
|
return PTR_ERR(par);
|
|
}
|
|
}
|
|
done:
|
|
r = corrected;
|
|
error:
|
|
dm_bufio_release(buf);
|
|
|
|
if (r < 0 && neras)
|
|
DMERR_LIMIT("%s: FEC %llu: failed to correct: %d",
|
|
v->data_dev->name, (unsigned long long)rsb, r);
|
|
else if (r > 0) {
|
|
DMWARN_LIMIT("%s: FEC %llu: corrected %d errors",
|
|
v->data_dev->name, (unsigned long long)rsb, r);
|
|
atomic_add_unless(&v->fec->corrected, 1, INT_MAX);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
/*
|
|
* Locate data block erasures using verity hashes.
|
|
*/
|
|
static int fec_is_erasure(struct dm_verity *v, struct dm_verity_io *io,
|
|
u8 *want_digest, u8 *data)
|
|
{
|
|
if (unlikely(verity_hash(v, verity_io_hash_req(v, io),
|
|
data, 1 << v->data_dev_block_bits,
|
|
verity_io_real_digest(v, io))))
|
|
return 0;
|
|
|
|
return memcmp(verity_io_real_digest(v, io), want_digest,
|
|
v->digest_size) != 0;
|
|
}
|
|
|
|
/*
|
|
* Read data blocks that are part of the RS block and deinterleave as much as
|
|
* fits into buffers. Check for erasure locations if @neras is non-NULL.
|
|
*/
|
|
static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io,
|
|
u64 rsb, u64 target, unsigned block_offset,
|
|
int *neras)
|
|
{
|
|
bool is_zero;
|
|
int i, j, target_index = -1;
|
|
struct dm_buffer *buf;
|
|
struct dm_bufio_client *bufio;
|
|
struct dm_verity_fec_io *fio = fec_io(io);
|
|
u64 block, ileaved;
|
|
u8 *bbuf, *rs_block;
|
|
u8 want_digest[HASH_MAX_DIGESTSIZE];
|
|
unsigned n, k;
|
|
|
|
if (neras)
|
|
*neras = 0;
|
|
|
|
if (WARN_ON(v->digest_size > sizeof(want_digest)))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* read each of the rsn data blocks that are part of the RS block, and
|
|
* interleave contents to available bufs
|
|
*/
|
|
for (i = 0; i < v->fec->rsn; i++) {
|
|
ileaved = fec_interleave(v, rsb * v->fec->rsn + i);
|
|
|
|
/*
|
|
* target is the data block we want to correct, target_index is
|
|
* the index of this block within the rsn RS blocks
|
|
*/
|
|
if (ileaved == target)
|
|
target_index = i;
|
|
|
|
block = ileaved >> v->data_dev_block_bits;
|
|
bufio = v->fec->data_bufio;
|
|
|
|
if (block >= v->data_blocks) {
|
|
block -= v->data_blocks;
|
|
|
|
/*
|
|
* blocks outside the area were assumed to contain
|
|
* zeros when encoding data was generated
|
|
*/
|
|
if (unlikely(block >= v->fec->hash_blocks))
|
|
continue;
|
|
|
|
block += v->hash_start;
|
|
bufio = v->bufio;
|
|
}
|
|
|
|
bbuf = dm_bufio_read(bufio, block, &buf);
|
|
if (unlikely(IS_ERR(bbuf))) {
|
|
DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld",
|
|
v->data_dev->name,
|
|
(unsigned long long)rsb,
|
|
(unsigned long long)block, PTR_ERR(bbuf));
|
|
|
|
/* assume the block is corrupted */
|
|
if (neras && *neras <= v->fec->roots)
|
|
fio->erasures[(*neras)++] = i;
|
|
|
|
continue;
|
|
}
|
|
|
|
/* locate erasures if the block is on the data device */
|
|
if (bufio == v->fec->data_bufio &&
|
|
verity_hash_for_block(v, io, block, want_digest,
|
|
&is_zero) == 0) {
|
|
/* skip known zero blocks entirely */
|
|
if (is_zero)
|
|
goto done;
|
|
|
|
/*
|
|
* skip if we have already found the theoretical
|
|
* maximum number (i.e. fec->roots) of erasures
|
|
*/
|
|
if (neras && *neras <= v->fec->roots &&
|
|
fec_is_erasure(v, io, want_digest, bbuf))
|
|
fio->erasures[(*neras)++] = i;
|
|
}
|
|
|
|
/*
|
|
* deinterleave and copy the bytes that fit into bufs,
|
|
* starting from block_offset
|
|
*/
|
|
fec_for_each_buffer_rs_block(fio, n, j) {
|
|
k = fec_buffer_rs_index(n, j) + block_offset;
|
|
|
|
if (k >= 1 << v->data_dev_block_bits)
|
|
goto done;
|
|
|
|
rs_block = fec_buffer_rs_block(v, fio, n, j);
|
|
rs_block[i] = bbuf[k];
|
|
}
|
|
done:
|
|
dm_bufio_release(buf);
|
|
}
|
|
|
|
return target_index;
|
|
}
|
|
|
|
/*
|
|
* Allocate RS control structure and FEC buffers from preallocated mempools,
|
|
* and attempt to allocate as many extra buffers as available.
|
|
*/
|
|
static int fec_alloc_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio)
|
|
{
|
|
unsigned n;
|
|
|
|
if (!fio->rs)
|
|
fio->rs = mempool_alloc(&v->fec->rs_pool, GFP_NOIO);
|
|
|
|
fec_for_each_prealloc_buffer(n) {
|
|
if (fio->bufs[n])
|
|
continue;
|
|
|
|
fio->bufs[n] = mempool_alloc(&v->fec->prealloc_pool, GFP_NOWAIT);
|
|
if (unlikely(!fio->bufs[n])) {
|
|
DMERR("failed to allocate FEC buffer");
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
/* try to allocate the maximum number of buffers */
|
|
fec_for_each_extra_buffer(fio, n) {
|
|
if (fio->bufs[n])
|
|
continue;
|
|
|
|
fio->bufs[n] = mempool_alloc(&v->fec->extra_pool, GFP_NOWAIT);
|
|
/* we can manage with even one buffer if necessary */
|
|
if (unlikely(!fio->bufs[n]))
|
|
break;
|
|
}
|
|
fio->nbufs = n;
|
|
|
|
if (!fio->output)
|
|
fio->output = mempool_alloc(&v->fec->output_pool, GFP_NOIO);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Initialize buffers and clear erasures. fec_read_bufs() assumes buffers are
|
|
* zeroed before deinterleaving.
|
|
*/
|
|
static void fec_init_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio)
|
|
{
|
|
unsigned n;
|
|
|
|
fec_for_each_buffer(fio, n)
|
|
memset(fio->bufs[n], 0, v->fec->rsn << DM_VERITY_FEC_BUF_RS_BITS);
|
|
|
|
memset(fio->erasures, 0, sizeof(fio->erasures));
|
|
}
|
|
|
|
/*
|
|
* Decode all RS blocks in a single data block and return the target block
|
|
* (indicated by @offset) in fio->output. If @use_erasures is non-zero, uses
|
|
* hashes to locate erasures.
|
|
*/
|
|
static int fec_decode_rsb(struct dm_verity *v, struct dm_verity_io *io,
|
|
struct dm_verity_fec_io *fio, u64 rsb, u64 offset,
|
|
bool use_erasures)
|
|
{
|
|
int r, neras = 0;
|
|
unsigned pos;
|
|
|
|
r = fec_alloc_bufs(v, fio);
|
|
if (unlikely(r < 0))
|
|
return r;
|
|
|
|
for (pos = 0; pos < 1 << v->data_dev_block_bits; ) {
|
|
fec_init_bufs(v, fio);
|
|
|
|
r = fec_read_bufs(v, io, rsb, offset, pos,
|
|
use_erasures ? &neras : NULL);
|
|
if (unlikely(r < 0))
|
|
return r;
|
|
|
|
r = fec_decode_bufs(v, fio, rsb, r, pos, neras);
|
|
if (r < 0)
|
|
return r;
|
|
|
|
pos += fio->nbufs << DM_VERITY_FEC_BUF_RS_BITS;
|
|
}
|
|
|
|
/* Always re-validate the corrected block against the expected hash */
|
|
r = verity_hash(v, verity_io_hash_req(v, io), fio->output,
|
|
1 << v->data_dev_block_bits,
|
|
verity_io_real_digest(v, io));
|
|
if (unlikely(r < 0))
|
|
return r;
|
|
|
|
if (memcmp(verity_io_real_digest(v, io), verity_io_want_digest(v, io),
|
|
v->digest_size)) {
|
|
DMERR_LIMIT("%s: FEC %llu: failed to correct (%d erasures)",
|
|
v->data_dev->name, (unsigned long long)rsb, neras);
|
|
return -EILSEQ;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int fec_bv_copy(struct dm_verity *v, struct dm_verity_io *io, u8 *data,
|
|
size_t len)
|
|
{
|
|
struct dm_verity_fec_io *fio = fec_io(io);
|
|
|
|
memcpy(data, &fio->output[fio->output_pos], len);
|
|
fio->output_pos += len;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Correct errors in a block. Copies corrected block to dest if non-NULL,
|
|
* otherwise to a bio_vec starting from iter.
|
|
*/
|
|
int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io,
|
|
enum verity_block_type type, sector_t block, u8 *dest,
|
|
struct bvec_iter *iter)
|
|
{
|
|
int r;
|
|
struct dm_verity_fec_io *fio = fec_io(io);
|
|
u64 offset, res, rsb;
|
|
|
|
if (!verity_fec_is_enabled(v))
|
|
return -EOPNOTSUPP;
|
|
|
|
if (fio->level >= DM_VERITY_FEC_MAX_RECURSION) {
|
|
DMWARN_LIMIT("%s: FEC: recursion too deep", v->data_dev->name);
|
|
return -EIO;
|
|
}
|
|
|
|
fio->level++;
|
|
|
|
if (type == DM_VERITY_BLOCK_TYPE_METADATA)
|
|
block = block - v->hash_start + v->data_blocks;
|
|
|
|
/*
|
|
* For RS(M, N), the continuous FEC data is divided into blocks of N
|
|
* bytes. Since block size may not be divisible by N, the last block
|
|
* is zero padded when decoding.
|
|
*
|
|
* Each byte of the block is covered by a different RS(M, N) code,
|
|
* and each code is interleaved over N blocks to make it less likely
|
|
* that bursty corruption will leave us in unrecoverable state.
|
|
*/
|
|
|
|
offset = block << v->data_dev_block_bits;
|
|
res = div64_u64(offset, v->fec->rounds << v->data_dev_block_bits);
|
|
|
|
/*
|
|
* The base RS block we can feed to the interleaver to find out all
|
|
* blocks required for decoding.
|
|
*/
|
|
rsb = offset - res * (v->fec->rounds << v->data_dev_block_bits);
|
|
|
|
/*
|
|
* Locating erasures is slow, so attempt to recover the block without
|
|
* them first. Do a second attempt with erasures if the corruption is
|
|
* bad enough.
|
|
*/
|
|
r = fec_decode_rsb(v, io, fio, rsb, offset, false);
|
|
if (r < 0) {
|
|
r = fec_decode_rsb(v, io, fio, rsb, offset, true);
|
|
if (r < 0)
|
|
goto done;
|
|
}
|
|
|
|
if (dest)
|
|
memcpy(dest, fio->output, 1 << v->data_dev_block_bits);
|
|
else if (iter) {
|
|
fio->output_pos = 0;
|
|
r = verity_for_bv_block(v, io, iter, fec_bv_copy);
|
|
}
|
|
|
|
done:
|
|
fio->level--;
|
|
return r;
|
|
}
|
|
|
|
/*
|
|
* Clean up per-bio data.
|
|
*/
|
|
void verity_fec_finish_io(struct dm_verity_io *io)
|
|
{
|
|
unsigned n;
|
|
struct dm_verity_fec *f = io->v->fec;
|
|
struct dm_verity_fec_io *fio = fec_io(io);
|
|
|
|
if (!verity_fec_is_enabled(io->v))
|
|
return;
|
|
|
|
mempool_free(fio->rs, &f->rs_pool);
|
|
|
|
fec_for_each_prealloc_buffer(n)
|
|
mempool_free(fio->bufs[n], &f->prealloc_pool);
|
|
|
|
fec_for_each_extra_buffer(fio, n)
|
|
mempool_free(fio->bufs[n], &f->extra_pool);
|
|
|
|
mempool_free(fio->output, &f->output_pool);
|
|
}
|
|
|
|
/*
|
|
* Initialize per-bio data.
|
|
*/
|
|
void verity_fec_init_io(struct dm_verity_io *io)
|
|
{
|
|
struct dm_verity_fec_io *fio = fec_io(io);
|
|
|
|
if (!verity_fec_is_enabled(io->v))
|
|
return;
|
|
|
|
fio->rs = NULL;
|
|
memset(fio->bufs, 0, sizeof(fio->bufs));
|
|
fio->nbufs = 0;
|
|
fio->output = NULL;
|
|
fio->level = 0;
|
|
}
|
|
|
|
/*
|
|
* Append feature arguments and values to the status table.
|
|
*/
|
|
unsigned verity_fec_status_table(struct dm_verity *v, unsigned sz,
|
|
char *result, unsigned maxlen)
|
|
{
|
|
if (!verity_fec_is_enabled(v))
|
|
return sz;
|
|
|
|
DMEMIT(" " DM_VERITY_OPT_FEC_DEV " %s "
|
|
DM_VERITY_OPT_FEC_BLOCKS " %llu "
|
|
DM_VERITY_OPT_FEC_START " %llu "
|
|
DM_VERITY_OPT_FEC_ROOTS " %d",
|
|
v->fec->dev->name,
|
|
(unsigned long long)v->fec->blocks,
|
|
(unsigned long long)v->fec->start,
|
|
v->fec->roots);
|
|
|
|
return sz;
|
|
}
|
|
|
|
void verity_fec_dtr(struct dm_verity *v)
|
|
{
|
|
struct dm_verity_fec *f = v->fec;
|
|
struct kobject *kobj = &f->kobj_holder.kobj;
|
|
|
|
if (!verity_fec_is_enabled(v))
|
|
goto out;
|
|
|
|
mempool_exit(&f->rs_pool);
|
|
mempool_exit(&f->prealloc_pool);
|
|
mempool_exit(&f->extra_pool);
|
|
mempool_exit(&f->output_pool);
|
|
kmem_cache_destroy(f->cache);
|
|
|
|
if (f->data_bufio)
|
|
dm_bufio_client_destroy(f->data_bufio);
|
|
if (f->bufio)
|
|
dm_bufio_client_destroy(f->bufio);
|
|
|
|
if (f->dev)
|
|
dm_put_device(v->ti, f->dev);
|
|
|
|
if (kobj->state_initialized) {
|
|
kobject_put(kobj);
|
|
wait_for_completion(dm_get_completion_from_kobject(kobj));
|
|
}
|
|
|
|
out:
|
|
kfree(f);
|
|
v->fec = NULL;
|
|
}
|
|
|
|
static void *fec_rs_alloc(gfp_t gfp_mask, void *pool_data)
|
|
{
|
|
struct dm_verity *v = (struct dm_verity *)pool_data;
|
|
|
|
return init_rs_gfp(8, 0x11d, 0, 1, v->fec->roots, gfp_mask);
|
|
}
|
|
|
|
static void fec_rs_free(void *element, void *pool_data)
|
|
{
|
|
struct rs_control *rs = (struct rs_control *)element;
|
|
|
|
if (rs)
|
|
free_rs(rs);
|
|
}
|
|
|
|
bool verity_is_fec_opt_arg(const char *arg_name)
|
|
{
|
|
return (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_DEV) ||
|
|
!strcasecmp(arg_name, DM_VERITY_OPT_FEC_BLOCKS) ||
|
|
!strcasecmp(arg_name, DM_VERITY_OPT_FEC_START) ||
|
|
!strcasecmp(arg_name, DM_VERITY_OPT_FEC_ROOTS));
|
|
}
|
|
|
|
int verity_fec_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
|
|
unsigned *argc, const char *arg_name)
|
|
{
|
|
int r;
|
|
struct dm_target *ti = v->ti;
|
|
const char *arg_value;
|
|
unsigned long long num_ll;
|
|
unsigned char num_c;
|
|
char dummy;
|
|
|
|
if (!*argc) {
|
|
ti->error = "FEC feature arguments require a value";
|
|
return -EINVAL;
|
|
}
|
|
|
|
arg_value = dm_shift_arg(as);
|
|
(*argc)--;
|
|
|
|
if (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_DEV)) {
|
|
r = dm_get_device(ti, arg_value, FMODE_READ, &v->fec->dev);
|
|
if (r) {
|
|
ti->error = "FEC device lookup failed";
|
|
return r;
|
|
}
|
|
|
|
} else if (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_BLOCKS)) {
|
|
if (sscanf(arg_value, "%llu%c", &num_ll, &dummy) != 1 ||
|
|
((sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT))
|
|
>> (v->data_dev_block_bits - SECTOR_SHIFT) != num_ll)) {
|
|
ti->error = "Invalid " DM_VERITY_OPT_FEC_BLOCKS;
|
|
return -EINVAL;
|
|
}
|
|
v->fec->blocks = num_ll;
|
|
|
|
} else if (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_START)) {
|
|
if (sscanf(arg_value, "%llu%c", &num_ll, &dummy) != 1 ||
|
|
((sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT)) >>
|
|
(v->data_dev_block_bits - SECTOR_SHIFT) != num_ll)) {
|
|
ti->error = "Invalid " DM_VERITY_OPT_FEC_START;
|
|
return -EINVAL;
|
|
}
|
|
v->fec->start = num_ll;
|
|
|
|
} else if (!strcasecmp(arg_name, DM_VERITY_OPT_FEC_ROOTS)) {
|
|
if (sscanf(arg_value, "%hhu%c", &num_c, &dummy) != 1 || !num_c ||
|
|
num_c < (DM_VERITY_FEC_RSM - DM_VERITY_FEC_MAX_RSN) ||
|
|
num_c > (DM_VERITY_FEC_RSM - DM_VERITY_FEC_MIN_RSN)) {
|
|
ti->error = "Invalid " DM_VERITY_OPT_FEC_ROOTS;
|
|
return -EINVAL;
|
|
}
|
|
v->fec->roots = num_c;
|
|
|
|
} else {
|
|
ti->error = "Unrecognized verity FEC feature request";
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t corrected_show(struct kobject *kobj, struct kobj_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct dm_verity_fec *f = container_of(kobj, struct dm_verity_fec,
|
|
kobj_holder.kobj);
|
|
|
|
return sprintf(buf, "%d\n", atomic_read(&f->corrected));
|
|
}
|
|
|
|
static struct kobj_attribute attr_corrected = __ATTR_RO(corrected);
|
|
|
|
static struct attribute *fec_attrs[] = {
|
|
&attr_corrected.attr,
|
|
NULL
|
|
};
|
|
|
|
static struct kobj_type fec_ktype = {
|
|
.sysfs_ops = &kobj_sysfs_ops,
|
|
.default_attrs = fec_attrs,
|
|
.release = dm_kobject_release
|
|
};
|
|
|
|
/*
|
|
* Allocate dm_verity_fec for v->fec. Must be called before verity_fec_ctr.
|
|
*/
|
|
int verity_fec_ctr_alloc(struct dm_verity *v)
|
|
{
|
|
struct dm_verity_fec *f;
|
|
|
|
f = kzalloc(sizeof(struct dm_verity_fec), GFP_KERNEL);
|
|
if (!f) {
|
|
v->ti->error = "Cannot allocate FEC structure";
|
|
return -ENOMEM;
|
|
}
|
|
v->fec = f;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Validate arguments and preallocate memory. Must be called after arguments
|
|
* have been parsed using verity_fec_parse_opt_args.
|
|
*/
|
|
int verity_fec_ctr(struct dm_verity *v)
|
|
{
|
|
int r;
|
|
struct dm_verity_fec *f = v->fec;
|
|
struct dm_target *ti = v->ti;
|
|
struct mapped_device *md = dm_table_get_md(ti->table);
|
|
u64 hash_blocks, fec_blocks;
|
|
int ret;
|
|
|
|
if (!verity_fec_is_enabled(v)) {
|
|
verity_fec_dtr(v);
|
|
return 0;
|
|
}
|
|
|
|
/* Create a kobject and sysfs attributes */
|
|
init_completion(&f->kobj_holder.completion);
|
|
|
|
r = kobject_init_and_add(&f->kobj_holder.kobj, &fec_ktype,
|
|
&disk_to_dev(dm_disk(md))->kobj, "%s", "fec");
|
|
if (r) {
|
|
ti->error = "Cannot create kobject";
|
|
return r;
|
|
}
|
|
|
|
/*
|
|
* FEC is computed over data blocks, possible metadata, and
|
|
* hash blocks. In other words, FEC covers total of fec_blocks
|
|
* blocks consisting of the following:
|
|
*
|
|
* data blocks | hash blocks | metadata (optional)
|
|
*
|
|
* We allow metadata after hash blocks to support a use case
|
|
* where all data is stored on the same device and FEC covers
|
|
* the entire area.
|
|
*
|
|
* If metadata is included, we require it to be available on the
|
|
* hash device after the hash blocks.
|
|
*/
|
|
|
|
hash_blocks = v->hash_blocks - v->hash_start;
|
|
|
|
/*
|
|
* Require matching block sizes for data and hash devices for
|
|
* simplicity.
|
|
*/
|
|
if (v->data_dev_block_bits != v->hash_dev_block_bits) {
|
|
ti->error = "Block sizes must match to use FEC";
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (!f->roots) {
|
|
ti->error = "Missing " DM_VERITY_OPT_FEC_ROOTS;
|
|
return -EINVAL;
|
|
}
|
|
f->rsn = DM_VERITY_FEC_RSM - f->roots;
|
|
|
|
if (!f->blocks) {
|
|
ti->error = "Missing " DM_VERITY_OPT_FEC_BLOCKS;
|
|
return -EINVAL;
|
|
}
|
|
|
|
f->rounds = f->blocks;
|
|
if (sector_div(f->rounds, f->rsn))
|
|
f->rounds++;
|
|
|
|
/*
|
|
* Due to optional metadata, f->blocks can be larger than
|
|
* data_blocks and hash_blocks combined.
|
|
*/
|
|
if (f->blocks < v->data_blocks + hash_blocks || !f->rounds) {
|
|
ti->error = "Invalid " DM_VERITY_OPT_FEC_BLOCKS;
|
|
return -EINVAL;
|
|
}
|
|
|
|
/*
|
|
* Metadata is accessed through the hash device, so we require
|
|
* it to be large enough.
|
|
*/
|
|
f->hash_blocks = f->blocks - v->data_blocks;
|
|
if (dm_bufio_get_device_size(v->bufio) < f->hash_blocks) {
|
|
ti->error = "Hash device is too small for "
|
|
DM_VERITY_OPT_FEC_BLOCKS;
|
|
return -E2BIG;
|
|
}
|
|
|
|
if ((f->roots << SECTOR_SHIFT) & ((1 << v->data_dev_block_bits) - 1))
|
|
f->io_size = 1 << v->data_dev_block_bits;
|
|
else
|
|
f->io_size = v->fec->roots << SECTOR_SHIFT;
|
|
|
|
f->bufio = dm_bufio_client_create(f->dev->bdev,
|
|
f->io_size,
|
|
1, 0, NULL, NULL);
|
|
if (IS_ERR(f->bufio)) {
|
|
ti->error = "Cannot initialize FEC bufio client";
|
|
return PTR_ERR(f->bufio);
|
|
}
|
|
|
|
dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
|
|
|
|
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
|
|
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
|
|
ti->error = "FEC device is too small";
|
|
return -E2BIG;
|
|
}
|
|
|
|
f->data_bufio = dm_bufio_client_create(v->data_dev->bdev,
|
|
1 << v->data_dev_block_bits,
|
|
1, 0, NULL, NULL);
|
|
if (IS_ERR(f->data_bufio)) {
|
|
ti->error = "Cannot initialize FEC data bufio client";
|
|
return PTR_ERR(f->data_bufio);
|
|
}
|
|
|
|
if (dm_bufio_get_device_size(f->data_bufio) < v->data_blocks) {
|
|
ti->error = "Data device is too small";
|
|
return -E2BIG;
|
|
}
|
|
|
|
/* Preallocate an rs_control structure for each worker thread */
|
|
ret = mempool_init(&f->rs_pool, num_online_cpus(), fec_rs_alloc,
|
|
fec_rs_free, (void *) v);
|
|
if (ret) {
|
|
ti->error = "Cannot allocate RS pool";
|
|
return ret;
|
|
}
|
|
|
|
f->cache = kmem_cache_create("dm_verity_fec_buffers",
|
|
f->rsn << DM_VERITY_FEC_BUF_RS_BITS,
|
|
0, 0, NULL);
|
|
if (!f->cache) {
|
|
ti->error = "Cannot create FEC buffer cache";
|
|
return -ENOMEM;
|
|
}
|
|
|
|
/* Preallocate DM_VERITY_FEC_BUF_PREALLOC buffers for each thread */
|
|
ret = mempool_init_slab_pool(&f->prealloc_pool, num_online_cpus() *
|
|
DM_VERITY_FEC_BUF_PREALLOC,
|
|
f->cache);
|
|
if (ret) {
|
|
ti->error = "Cannot allocate FEC buffer prealloc pool";
|
|
return ret;
|
|
}
|
|
|
|
ret = mempool_init_slab_pool(&f->extra_pool, 0, f->cache);
|
|
if (ret) {
|
|
ti->error = "Cannot allocate FEC buffer extra pool";
|
|
return ret;
|
|
}
|
|
|
|
/* Preallocate an output buffer for each thread */
|
|
ret = mempool_init_kmalloc_pool(&f->output_pool, num_online_cpus(),
|
|
1 << v->data_dev_block_bits);
|
|
if (ret) {
|
|
ti->error = "Cannot allocate FEC output pool";
|
|
return ret;
|
|
}
|
|
|
|
/* Reserve space for our per-bio data */
|
|
ti->per_io_data_size += sizeof(struct dm_verity_fec_io);
|
|
|
|
return 0;
|
|
}
|