Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 166 lines 4.8 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Copyright (C) 2015 Google, Inc. 4 * 5 * Author: Sami Tolvanen <samitolvanen@google.com> 6 */ 7 8#ifndef DM_VERITY_FEC_H 9#define DM_VERITY_FEC_H 10 11#include "dm-verity.h" 12#include <linux/rslib.h> 13 14/* Reed-Solomon(n, k) parameters */ 15#define DM_VERITY_FEC_RS_N 255 16#define DM_VERITY_FEC_MIN_ROOTS 2 /* RS(255, 253): ~0.8% space overhead */ 17#define DM_VERITY_FEC_MAX_ROOTS 24 /* RS(255, 231): ~10% space overhead */ 18 19/* buffers for deinterleaving and decoding */ 20#define DM_VERITY_FEC_BUF_RS_BITS 4 /* log2(RS messages per buffer) */ 21 22#define DM_VERITY_OPT_FEC_DEV "use_fec_from_device" 23#define DM_VERITY_OPT_FEC_BLOCKS "fec_blocks" 24#define DM_VERITY_OPT_FEC_START "fec_start" 25#define DM_VERITY_OPT_FEC_ROOTS "fec_roots" 26 27/* configuration */ 28struct dm_verity_fec { 29 struct dm_dev *dev; /* parity data device */ 30 struct dm_bufio_client *data_bufio; /* for data dev access */ 31 struct dm_bufio_client *bufio; /* for parity data access */ 32 size_t block_size; /* size of data, hash, and parity blocks in bytes */ 33 sector_t start; /* parity data start in blocks */ 34 sector_t blocks; /* number of blocks covered */ 35 sector_t region_blocks; /* blocks per region: ceil(blocks / rs_k) */ 36 sector_t hash_blocks; /* blocks covered after v->hash_start */ 37 unsigned char roots; /* parity bytes per RS codeword, n-k of RS(n, k) */ 38 unsigned char rs_k; /* message bytes per RS codeword, k of RS(n, k) */ 39 mempool_t fio_pool; /* mempool for dm_verity_fec_io */ 40 mempool_t rs_pool; /* mempool for fio->rs */ 41 mempool_t prealloc_pool; /* mempool for preallocated buffers */ 42 mempool_t output_pool; /* mempool for output */ 43 struct kmem_cache *cache; /* cache for buffers */ 44 atomic64_t corrected; /* corrected errors */ 45}; 46 47/* per-bio data */ 48struct dm_verity_fec_io { 49 struct rs_control *rs; /* Reed-Solomon state */ 50 int erasures[DM_VERITY_FEC_MAX_ROOTS + 1]; /* erasures for decode_rs8 */ 51 u8 *output; /* buffer for corrected output */ 52 unsigned int level; /* recursion level */ 53 unsigned int nbufs; /* number of buffers allocated */ 54 /* 55 * Buffers for deinterleaving RS codewords. Each buffer has space for 56 * the message bytes of (1 << DM_VERITY_FEC_BUF_RS_BITS) RS codewords. 57 * The array length is fec_max_nbufs(v), and we try to allocate that 58 * many buffers. However, in low-memory situations we may be unable to 59 * allocate all buffers. 'nbufs' holds the number actually allocated. 60 */ 61 u8 *bufs[]; 62}; 63 64#ifdef CONFIG_DM_VERITY_FEC 65 66/* each feature parameter requires a value */ 67#define DM_VERITY_OPTS_FEC 8 68 69/* Returns true if forward error correction is enabled. */ 70static inline bool verity_fec_is_enabled(struct dm_verity *v) 71{ 72 return v->fec && v->fec->dev; 73} 74 75extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io, 76 enum verity_block_type type, const u8 *want_digest, 77 sector_t block, u8 *dest); 78 79extern unsigned int verity_fec_status_table(struct dm_verity *v, unsigned int sz, 80 char *result, unsigned int maxlen); 81 82extern void __verity_fec_finish_io(struct dm_verity_io *io); 83static inline void verity_fec_finish_io(struct dm_verity_io *io) 84{ 85 if (unlikely(io->fec_io)) 86 __verity_fec_finish_io(io); 87} 88 89static inline void verity_fec_init_io(struct dm_verity_io *io) 90{ 91 io->fec_io = NULL; 92} 93 94extern bool verity_is_fec_opt_arg(const char *arg_name); 95extern int verity_fec_parse_opt_args(struct dm_arg_set *as, 96 struct dm_verity *v, unsigned int *argc, 97 const char *arg_name); 98 99extern void verity_fec_dtr(struct dm_verity *v); 100 101extern int verity_fec_ctr_alloc(struct dm_verity *v); 102extern int verity_fec_ctr(struct dm_verity *v); 103 104#else /* !CONFIG_DM_VERITY_FEC */ 105 106#define DM_VERITY_OPTS_FEC 0 107 108static inline bool verity_fec_is_enabled(struct dm_verity *v) 109{ 110 return false; 111} 112 113static inline int verity_fec_decode(struct dm_verity *v, 114 struct dm_verity_io *io, 115 enum verity_block_type type, 116 const u8 *want_digest, 117 sector_t block, u8 *dest) 118{ 119 return -EOPNOTSUPP; 120} 121 122static inline unsigned int verity_fec_status_table(struct dm_verity *v, 123 unsigned int sz, char *result, 124 unsigned int maxlen) 125{ 126 return sz; 127} 128 129static inline void verity_fec_finish_io(struct dm_verity_io *io) 130{ 131} 132 133static inline void verity_fec_init_io(struct dm_verity_io *io) 134{ 135} 136 137static inline bool verity_is_fec_opt_arg(const char *arg_name) 138{ 139 return false; 140} 141 142static inline int verity_fec_parse_opt_args(struct dm_arg_set *as, 143 struct dm_verity *v, 144 unsigned int *argc, 145 const char *arg_name) 146{ 147 return -EINVAL; 148} 149 150static inline void verity_fec_dtr(struct dm_verity *v) 151{ 152} 153 154static inline int verity_fec_ctr_alloc(struct dm_verity *v) 155{ 156 return 0; 157} 158 159static inline int verity_fec_ctr(struct dm_verity *v) 160{ 161 return 0; 162} 163 164#endif /* CONFIG_DM_VERITY_FEC */ 165 166#endif /* DM_VERITY_FEC_H */