2 * Copyright (C) 2012 Red Hat, Inc.
4 * Author: Mikulas Patocka <mpatocka@redhat.com>
6 * Based on Chromium dm-verity driver (C) 2011 The Chromium OS Authors
8 * This file is released under the GPLv2.
10 * In the file "/sys/module/dm_verity/parameters/prefetch_cluster" you can set
11 * default prefetch value. Data are read in "prefetch_cluster" chunks from the
12 * hash device. Setting this greatly improves performance when data and hash
13 * are on the same disk on different partitions on devices with poor random
19 #include <linux/module.h>
20 #include <linux/device-mapper.h>
21 #include <linux/reboot.h>
22 #include <crypto/hash.h>
24 #define DM_MSG_PREFIX "verity"
26 #define DM_VERITY_ENV_LENGTH 42
27 #define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR"
29 #define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
31 #define DM_VERITY_MAX_LEVELS 63
32 #define DM_VERITY_MAX_CORRUPTED_ERRS 100
34 #define DM_VERITY_OPT_LOGGING "ignore_corruption"
35 #define DM_VERITY_OPT_RESTART "restart_on_corruption"
37 #define DM_VERITY_OPTS_MAX 1
39 static unsigned dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE;
41 module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, S_IRUGO | S_IWUSR);
45 DM_VERITY_MODE_LOGGING,
46 DM_VERITY_MODE_RESTART
49 enum verity_block_type {
50 DM_VERITY_BLOCK_TYPE_DATA,
51 DM_VERITY_BLOCK_TYPE_METADATA
55 struct dm_dev *data_dev;
56 struct dm_dev *hash_dev;
58 struct dm_bufio_client *bufio;
60 struct crypto_shash *tfm;
61 u8 *root_digest; /* digest of the root block */
62 u8 *salt; /* salt: its size is salt_size */
64 sector_t data_start; /* data offset in 512-byte sectors */
65 sector_t hash_start; /* hash start in blocks */
66 sector_t data_blocks; /* the number of data blocks */
67 sector_t hash_blocks; /* the number of hash blocks */
68 unsigned char data_dev_block_bits; /* log2(data blocksize) */
69 unsigned char hash_dev_block_bits; /* log2(hash blocksize) */
70 unsigned char hash_per_block_bits; /* log2(hashes in hash block) */
71 unsigned char levels; /* the number of tree levels */
72 unsigned char version;
73 unsigned digest_size; /* digest size for the current hash algorithm */
74 unsigned shash_descsize;/* the size of temporary space for crypto */
75 int hash_failed; /* set to 1 if hash of any block failed */
76 enum verity_mode mode; /* mode for handling verification errors */
77 unsigned corrupted_errs;/* Number of errors for corrupted blocks */
79 struct workqueue_struct *verify_wq;
81 /* starting blocks for each tree level. 0 is the lowest level. */
82 sector_t hash_level_block[DM_VERITY_MAX_LEVELS];
88 /* original value of bio->bi_end_io */
89 bio_end_io_t *orig_bi_end_io;
94 struct bvec_iter iter;
96 struct work_struct work;
99 * Three variably-size fields follow this struct:
101 * u8 hash_desc[v->shash_descsize];
102 * u8 real_digest[v->digest_size];
103 * u8 want_digest[v->digest_size];
105 * To access them use: io_hash_desc(), io_real_digest() and io_want_digest().
109 struct dm_verity_prefetch_work {
110 struct work_struct work;
116 static struct shash_desc *io_hash_desc(struct dm_verity *v, struct dm_verity_io *io)
118 return (struct shash_desc *)(io + 1);
121 static u8 *io_real_digest(struct dm_verity *v, struct dm_verity_io *io)
123 return (u8 *)(io + 1) + v->shash_descsize;
126 static u8 *io_want_digest(struct dm_verity *v, struct dm_verity_io *io)
128 return (u8 *)(io + 1) + v->shash_descsize + v->digest_size;
132 * Auxiliary structure appended to each dm-bufio buffer. If the value
133 * hash_verified is nonzero, hash of the block has been verified.
135 * The variable hash_verified is set to 0 when allocating the buffer, then
136 * it can be changed to 1 and it is never reset to 0 again.
138 * There is no lock around this value, a race condition can at worst cause
139 * that multiple processes verify the hash of the same buffer simultaneously
140 * and write 1 to hash_verified simultaneously.
141 * This condition is harmless, so we don't need locking.
148 * Initialize struct buffer_aux for a freshly created buffer.
150 static void dm_bufio_alloc_callback(struct dm_buffer *buf)
152 struct buffer_aux *aux = dm_bufio_get_aux_data(buf);
154 aux->hash_verified = 0;
158 * Translate input sector number to the sector number on the target device.
160 static sector_t verity_map_sector(struct dm_verity *v, sector_t bi_sector)
162 return v->data_start + dm_target_offset(v->ti, bi_sector);
166 * Return hash position of a specified block at a specified tree level
167 * (0 is the lowest level).
168 * The lowest "hash_per_block_bits"-bits of the result denote hash position
169 * inside a hash block. The remaining bits denote location of the hash block.
171 static sector_t verity_position_at_level(struct dm_verity *v, sector_t block,
174 return block >> (level * v->hash_per_block_bits);
178 * Wrapper for crypto_shash_init, which handles verity salting.
180 static int verity_hash_init(struct dm_verity *v, struct shash_desc *desc)
185 desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
187 r = crypto_shash_init(desc);
189 if (unlikely(r < 0)) {
190 DMERR("crypto_shash_init failed: %d", r);
194 if (likely(v->version >= 1)) {
195 r = crypto_shash_update(desc, v->salt, v->salt_size);
197 if (unlikely(r < 0)) {
198 DMERR("crypto_shash_update failed: %d", r);
206 static int verity_hash_update(struct dm_verity *v, struct shash_desc *desc,
207 const u8 *data, size_t len)
209 int r = crypto_shash_update(desc, data, len);
212 DMERR("crypto_shash_update failed: %d", r);
217 static int verity_hash_final(struct dm_verity *v, struct shash_desc *desc,
222 if (unlikely(!v->version)) {
223 r = crypto_shash_update(desc, v->salt, v->salt_size);
226 DMERR("crypto_shash_update failed: %d", r);
231 r = crypto_shash_final(desc, digest);
234 DMERR("crypto_shash_final failed: %d", r);
239 static int verity_hash(struct dm_verity *v, struct shash_desc *desc,
240 const u8 *data, size_t len, u8 *digest)
244 r = verity_hash_init(v, desc);
248 r = verity_hash_update(v, desc, data, len);
252 return verity_hash_final(v, desc, digest);
255 static void verity_hash_at_level(struct dm_verity *v, sector_t block, int level,
256 sector_t *hash_block, unsigned *offset)
258 sector_t position = verity_position_at_level(v, block, level);
261 *hash_block = v->hash_level_block[level] + (position >> v->hash_per_block_bits);
266 idx = position & ((1 << v->hash_per_block_bits) - 1);
268 *offset = idx * v->digest_size;
270 *offset = idx << (v->hash_dev_block_bits - v->hash_per_block_bits);
274 * Handle verification errors.
276 static int verity_handle_err(struct dm_verity *v, enum verity_block_type type,
277 unsigned long long block)
279 char verity_env[DM_VERITY_ENV_LENGTH];
280 char *envp[] = { verity_env, NULL };
281 const char *type_str = "";
282 struct mapped_device *md = dm_table_get_md(v->ti->table);
284 /* Corruption should be visible in device status in all modes */
287 if (v->corrupted_errs >= DM_VERITY_MAX_CORRUPTED_ERRS)
293 case DM_VERITY_BLOCK_TYPE_DATA:
296 case DM_VERITY_BLOCK_TYPE_METADATA:
297 type_str = "metadata";
303 DMERR("%s: %s block %llu is corrupted", v->data_dev->name, type_str,
306 if (v->corrupted_errs == DM_VERITY_MAX_CORRUPTED_ERRS)
307 DMERR("%s: reached maximum errors", v->data_dev->name);
309 snprintf(verity_env, DM_VERITY_ENV_LENGTH, "%s=%d,%llu",
310 DM_VERITY_ENV_VAR_NAME, type, block);
312 kobject_uevent_env(&disk_to_dev(dm_disk(md))->kobj, KOBJ_CHANGE, envp);
315 if (v->mode == DM_VERITY_MODE_LOGGING)
318 if (v->mode == DM_VERITY_MODE_RESTART)
319 kernel_restart("dm-verity device corrupted");
325 * Verify hash of a metadata block pertaining to the specified data block
326 * ("block" argument) at a specified level ("level" argument).
328 * On successful return, io_want_digest(v, io) contains the hash value for
329 * a lower tree level or for the data block (if we're at the lowest leve).
331 * If "skip_unverified" is true, unverified buffer is skipped and 1 is returned.
332 * If "skip_unverified" is false, unverified buffer is hashed and verified
333 * against current value of io_want_digest(v, io).
335 static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
336 sector_t block, int level, bool skip_unverified,
339 struct dm_buffer *buf;
340 struct buffer_aux *aux;
346 verity_hash_at_level(v, block, level, &hash_block, &offset);
348 data = dm_bufio_read(v->bufio, hash_block, &buf);
350 return PTR_ERR(data);
352 aux = dm_bufio_get_aux_data(buf);
354 if (!aux->hash_verified) {
355 if (skip_unverified) {
360 r = verity_hash(v, io_hash_desc(v, io),
361 data, 1 << v->hash_dev_block_bits,
362 io_real_digest(v, io));
366 if (likely(memcmp(io_real_digest(v, io), want_digest,
367 v->digest_size) == 0))
368 aux->hash_verified = 1;
369 else if (verity_handle_err(v,
370 DM_VERITY_BLOCK_TYPE_METADATA,
378 memcpy(want_digest, data, v->digest_size);
382 dm_bufio_release(buf);
387 * Find a hash for a given block, write it to digest and verify the integrity
388 * of the hash tree if necessary.
390 static int verity_hash_for_block(struct dm_verity *v, struct dm_verity_io *io,
391 sector_t block, u8 *digest)
396 if (likely(v->levels)) {
398 * First, we try to get the requested hash for
399 * the current block. If the hash block itself is
400 * verified, zero is returned. If it isn't, this
401 * function returns 1 and we fall back to whole
402 * chain verification.
404 r = verity_verify_level(v, io, block, 0, true, digest);
409 memcpy(digest, v->root_digest, v->digest_size);
411 for (i = v->levels - 1; i >= 0; i--) {
412 r = verity_verify_level(v, io, block, i, false, digest);
421 * Verify one "dm_verity_io" structure.
423 static int verity_verify_io(struct dm_verity_io *io)
425 struct dm_verity *v = io->v;
426 struct bio *bio = dm_bio_from_per_bio_data(io,
427 v->ti->per_bio_data_size);
430 for (b = 0; b < io->n_blocks; b++) {
433 struct shash_desc *desc = io_hash_desc(v, io);
435 r = verity_hash_for_block(v, io, io->block + b,
436 io_want_digest(v, io));
440 r = verity_hash_init(v, desc);
444 todo = 1 << v->data_dev_block_bits;
448 struct bio_vec bv = bio_iter_iovec(bio, io->iter);
450 page = kmap_atomic(bv.bv_page);
452 if (likely(len >= todo))
454 r = verity_hash_update(v, desc, page + bv.bv_offset,
461 bio_advance_iter(bio, &io->iter, len);
465 r = verity_hash_final(v, desc, io_real_digest(v, io));
469 if (likely(memcmp(io_real_digest(v, io),
470 io_want_digest(v, io), v->digest_size) == 0))
472 else if (verity_handle_err(v, DM_VERITY_BLOCK_TYPE_DATA,
481 * End one "io" structure with a given error.
483 static void verity_finish_io(struct dm_verity_io *io, int error)
485 struct dm_verity *v = io->v;
486 struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_bio_data_size);
488 bio->bi_end_io = io->orig_bi_end_io;
489 bio->bi_error = error;
494 static void verity_work(struct work_struct *w)
496 struct dm_verity_io *io = container_of(w, struct dm_verity_io, work);
498 verity_finish_io(io, verity_verify_io(io));
501 static void verity_end_io(struct bio *bio)
503 struct dm_verity_io *io = bio->bi_private;
506 verity_finish_io(io, bio->bi_error);
510 INIT_WORK(&io->work, verity_work);
511 queue_work(io->v->verify_wq, &io->work);
515 * Prefetch buffers for the specified io.
516 * The root buffer is not prefetched, it is assumed that it will be cached
519 static void verity_prefetch_io(struct work_struct *work)
521 struct dm_verity_prefetch_work *pw =
522 container_of(work, struct dm_verity_prefetch_work, work);
523 struct dm_verity *v = pw->v;
526 for (i = v->levels - 2; i >= 0; i--) {
527 sector_t hash_block_start;
528 sector_t hash_block_end;
529 verity_hash_at_level(v, pw->block, i, &hash_block_start, NULL);
530 verity_hash_at_level(v, pw->block + pw->n_blocks - 1, i, &hash_block_end, NULL);
532 unsigned cluster = ACCESS_ONCE(dm_verity_prefetch_cluster);
534 cluster >>= v->data_dev_block_bits;
535 if (unlikely(!cluster))
536 goto no_prefetch_cluster;
538 if (unlikely(cluster & (cluster - 1)))
539 cluster = 1 << __fls(cluster);
541 hash_block_start &= ~(sector_t)(cluster - 1);
542 hash_block_end |= cluster - 1;
543 if (unlikely(hash_block_end >= v->hash_blocks))
544 hash_block_end = v->hash_blocks - 1;
547 dm_bufio_prefetch(v->bufio, hash_block_start,
548 hash_block_end - hash_block_start + 1);
554 static void verity_submit_prefetch(struct dm_verity *v, struct dm_verity_io *io)
556 struct dm_verity_prefetch_work *pw;
558 pw = kmalloc(sizeof(struct dm_verity_prefetch_work),
559 GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
564 INIT_WORK(&pw->work, verity_prefetch_io);
566 pw->block = io->block;
567 pw->n_blocks = io->n_blocks;
568 queue_work(v->verify_wq, &pw->work);
572 * Bio map function. It allocates dm_verity_io structure and bio vector and
573 * fills them. Then it issues prefetches and the I/O.
575 static int verity_map(struct dm_target *ti, struct bio *bio)
577 struct dm_verity *v = ti->private;
578 struct dm_verity_io *io;
580 bio->bi_bdev = v->data_dev->bdev;
581 bio->bi_iter.bi_sector = verity_map_sector(v, bio->bi_iter.bi_sector);
583 if (((unsigned)bio->bi_iter.bi_sector | bio_sectors(bio)) &
584 ((1 << (v->data_dev_block_bits - SECTOR_SHIFT)) - 1)) {
585 DMERR_LIMIT("unaligned io");
589 if (bio_end_sector(bio) >>
590 (v->data_dev_block_bits - SECTOR_SHIFT) > v->data_blocks) {
591 DMERR_LIMIT("io out of range");
595 if (bio_data_dir(bio) == WRITE)
598 io = dm_per_bio_data(bio, ti->per_bio_data_size);
600 io->orig_bi_end_io = bio->bi_end_io;
601 io->block = bio->bi_iter.bi_sector >> (v->data_dev_block_bits - SECTOR_SHIFT);
602 io->n_blocks = bio->bi_iter.bi_size >> v->data_dev_block_bits;
604 bio->bi_end_io = verity_end_io;
605 bio->bi_private = io;
606 io->iter = bio->bi_iter;
608 verity_submit_prefetch(v, io);
610 generic_make_request(bio);
612 return DM_MAPIO_SUBMITTED;
616 * Status: V (valid) or C (corruption found)
618 static void verity_status(struct dm_target *ti, status_type_t type,
619 unsigned status_flags, char *result, unsigned maxlen)
621 struct dm_verity *v = ti->private;
626 case STATUSTYPE_INFO:
627 DMEMIT("%c", v->hash_failed ? 'C' : 'V');
629 case STATUSTYPE_TABLE:
630 DMEMIT("%u %s %s %u %u %llu %llu %s ",
634 1 << v->data_dev_block_bits,
635 1 << v->hash_dev_block_bits,
636 (unsigned long long)v->data_blocks,
637 (unsigned long long)v->hash_start,
640 for (x = 0; x < v->digest_size; x++)
641 DMEMIT("%02x", v->root_digest[x]);
646 for (x = 0; x < v->salt_size; x++)
647 DMEMIT("%02x", v->salt[x]);
648 if (v->mode != DM_VERITY_MODE_EIO) {
651 case DM_VERITY_MODE_LOGGING:
652 DMEMIT(DM_VERITY_OPT_LOGGING);
654 case DM_VERITY_MODE_RESTART:
655 DMEMIT(DM_VERITY_OPT_RESTART);
665 static int verity_prepare_ioctl(struct dm_target *ti,
666 struct block_device **bdev, fmode_t *mode)
668 struct dm_verity *v = ti->private;
670 *bdev = v->data_dev->bdev;
673 ti->len != i_size_read(v->data_dev->bdev->bd_inode) >> SECTOR_SHIFT)
678 static int verity_iterate_devices(struct dm_target *ti,
679 iterate_devices_callout_fn fn, void *data)
681 struct dm_verity *v = ti->private;
683 return fn(ti, v->data_dev, v->data_start, ti->len, data);
686 static void verity_io_hints(struct dm_target *ti, struct queue_limits *limits)
688 struct dm_verity *v = ti->private;
690 if (limits->logical_block_size < 1 << v->data_dev_block_bits)
691 limits->logical_block_size = 1 << v->data_dev_block_bits;
693 if (limits->physical_block_size < 1 << v->data_dev_block_bits)
694 limits->physical_block_size = 1 << v->data_dev_block_bits;
696 blk_limits_io_min(limits, limits->logical_block_size);
699 static void verity_dtr(struct dm_target *ti)
701 struct dm_verity *v = ti->private;
704 destroy_workqueue(v->verify_wq);
707 dm_bufio_client_destroy(v->bufio);
710 kfree(v->root_digest);
713 crypto_free_shash(v->tfm);
718 dm_put_device(ti, v->hash_dev);
721 dm_put_device(ti, v->data_dev);
726 static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v)
730 struct dm_target *ti = v->ti;
731 const char *arg_name;
733 static struct dm_arg _args[] = {
734 {0, DM_VERITY_OPTS_MAX, "Invalid number of feature args"},
737 r = dm_read_arg_group(_args, as, &argc, &ti->error);
745 arg_name = dm_shift_arg(as);
748 if (!strcasecmp(arg_name, DM_VERITY_OPT_LOGGING)) {
749 v->mode = DM_VERITY_MODE_LOGGING;
752 } else if (!strcasecmp(arg_name, DM_VERITY_OPT_RESTART)) {
753 v->mode = DM_VERITY_MODE_RESTART;
757 ti->error = "Unrecognized verity feature request";
759 } while (argc && !r);
766 * <version> The current format is version 1.
767 * Vsn 0 is compatible with original Chromium OS releases.
772 * <the number of data blocks>
776 * <salt> Hex string or "-" if no salt.
778 static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
781 struct dm_arg_set as;
783 unsigned long long num_ll;
786 sector_t hash_position;
789 v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL);
791 ti->error = "Cannot allocate verity structure";
797 if ((dm_table_get_mode(ti->table) & ~FMODE_READ)) {
798 ti->error = "Device must be readonly";
804 ti->error = "Not enough arguments";
809 if (sscanf(argv[0], "%u%c", &num, &dummy) != 1 ||
811 ti->error = "Invalid version";
817 r = dm_get_device(ti, argv[1], FMODE_READ, &v->data_dev);
819 ti->error = "Data device lookup failed";
823 r = dm_get_device(ti, argv[2], FMODE_READ, &v->hash_dev);
825 ti->error = "Data device lookup failed";
829 if (sscanf(argv[3], "%u%c", &num, &dummy) != 1 ||
830 !num || (num & (num - 1)) ||
831 num < bdev_logical_block_size(v->data_dev->bdev) ||
833 ti->error = "Invalid data device block size";
837 v->data_dev_block_bits = __ffs(num);
839 if (sscanf(argv[4], "%u%c", &num, &dummy) != 1 ||
840 !num || (num & (num - 1)) ||
841 num < bdev_logical_block_size(v->hash_dev->bdev) ||
843 ti->error = "Invalid hash device block size";
847 v->hash_dev_block_bits = __ffs(num);
849 if (sscanf(argv[5], "%llu%c", &num_ll, &dummy) != 1 ||
850 (sector_t)(num_ll << (v->data_dev_block_bits - SECTOR_SHIFT))
851 >> (v->data_dev_block_bits - SECTOR_SHIFT) != num_ll) {
852 ti->error = "Invalid data blocks";
856 v->data_blocks = num_ll;
858 if (ti->len > (v->data_blocks << (v->data_dev_block_bits - SECTOR_SHIFT))) {
859 ti->error = "Data device is too small";
864 if (sscanf(argv[6], "%llu%c", &num_ll, &dummy) != 1 ||
865 (sector_t)(num_ll << (v->hash_dev_block_bits - SECTOR_SHIFT))
866 >> (v->hash_dev_block_bits - SECTOR_SHIFT) != num_ll) {
867 ti->error = "Invalid hash start";
871 v->hash_start = num_ll;
873 v->alg_name = kstrdup(argv[7], GFP_KERNEL);
875 ti->error = "Cannot allocate algorithm name";
880 v->tfm = crypto_alloc_shash(v->alg_name, 0, 0);
881 if (IS_ERR(v->tfm)) {
882 ti->error = "Cannot initialize hash function";
887 v->digest_size = crypto_shash_digestsize(v->tfm);
888 if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) {
889 ti->error = "Digest size too big";
894 sizeof(struct shash_desc) + crypto_shash_descsize(v->tfm);
896 v->root_digest = kmalloc(v->digest_size, GFP_KERNEL);
897 if (!v->root_digest) {
898 ti->error = "Cannot allocate root digest";
902 if (strlen(argv[8]) != v->digest_size * 2 ||
903 hex2bin(v->root_digest, argv[8], v->digest_size)) {
904 ti->error = "Invalid root digest";
909 if (strcmp(argv[9], "-")) {
910 v->salt_size = strlen(argv[9]) / 2;
911 v->salt = kmalloc(v->salt_size, GFP_KERNEL);
913 ti->error = "Cannot allocate salt";
917 if (strlen(argv[9]) != v->salt_size * 2 ||
918 hex2bin(v->salt, argv[9], v->salt_size)) {
919 ti->error = "Invalid salt";
928 /* Optional parameters */
933 r = verity_parse_opt_args(&as, v);
938 v->hash_per_block_bits =
939 __fls((1 << v->hash_dev_block_bits) / v->digest_size);
943 while (v->hash_per_block_bits * v->levels < 64 &&
944 (unsigned long long)(v->data_blocks - 1) >>
945 (v->hash_per_block_bits * v->levels))
948 if (v->levels > DM_VERITY_MAX_LEVELS) {
949 ti->error = "Too many tree levels";
954 hash_position = v->hash_start;
955 for (i = v->levels - 1; i >= 0; i--) {
957 v->hash_level_block[i] = hash_position;
958 s = (v->data_blocks + ((sector_t)1 << ((i + 1) * v->hash_per_block_bits)) - 1)
959 >> ((i + 1) * v->hash_per_block_bits);
960 if (hash_position + s < hash_position) {
961 ti->error = "Hash device offset overflow";
967 v->hash_blocks = hash_position;
969 v->bufio = dm_bufio_client_create(v->hash_dev->bdev,
970 1 << v->hash_dev_block_bits, 1, sizeof(struct buffer_aux),
971 dm_bufio_alloc_callback, NULL);
972 if (IS_ERR(v->bufio)) {
973 ti->error = "Cannot initialize dm-bufio";
974 r = PTR_ERR(v->bufio);
979 if (dm_bufio_get_device_size(v->bufio) < v->hash_blocks) {
980 ti->error = "Hash device is too small";
985 ti->per_bio_data_size = roundup(sizeof(struct dm_verity_io) + v->shash_descsize + v->digest_size * 2, __alignof__(struct dm_verity_io));
987 /* WQ_UNBOUND greatly improves performance when running on ramdisk */
988 v->verify_wq = alloc_workqueue("kverityd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND, num_online_cpus());
990 ti->error = "Cannot allocate workqueue";
1003 static struct target_type verity_target = {
1005 .version = {1, 2, 0},
1006 .module = THIS_MODULE,
1010 .status = verity_status,
1011 .prepare_ioctl = verity_prepare_ioctl,
1012 .iterate_devices = verity_iterate_devices,
1013 .io_hints = verity_io_hints,
1016 static int __init dm_verity_init(void)
1020 r = dm_register_target(&verity_target);
1022 DMERR("register failed %d", r);
1027 static void __exit dm_verity_exit(void)
1029 dm_unregister_target(&verity_target);
1032 module_init(dm_verity_init);
1033 module_exit(dm_verity_exit);
1035 MODULE_AUTHOR("Mikulas Patocka <mpatocka@redhat.com>");
1036 MODULE_AUTHOR("Mandeep Baines <msb@chromium.org>");
1037 MODULE_AUTHOR("Will Drewry <wad@chromium.org>");
1038 MODULE_DESCRIPTION(DM_NAME " target for transparent disk integrity checking");
1039 MODULE_LICENSE("GPL");