Revert "ANDROID: dm verity: add minimum prefetch size"
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / drivers / md / dm-verity-target.c
index be1e8888112293cc24bf161a0601709c5ddee4a9..23600f24faffa36cd9cbf42899c8f46d8fe7d50b 100644 (file)
@@ -140,10 +140,26 @@ static int verity_hash_update(struct dm_verity *v, struct ahash_request *req,
 {
        struct scatterlist sg;
 
-       sg_init_one(&sg, data, len);
-       ahash_request_set_crypt(req, &sg, NULL, len);
-
-       return verity_complete_op(res, crypto_ahash_update(req));
+       if (likely(!is_vmalloc_addr(data))) {
+               sg_init_one(&sg, data, len);
+               ahash_request_set_crypt(req, &sg, NULL, len);
+               return verity_complete_op(res, crypto_ahash_update(req));
+       } else {
+               do {
+                       int r;
+                       size_t this_step = min_t(size_t, len, PAGE_SIZE - offset_in_page(data));
+                       flush_kernel_vmap_range((void *)data, this_step);
+                       sg_init_table(&sg, 1);
+                       sg_set_page(&sg, vmalloc_to_page(data), this_step, offset_in_page(data));
+                       ahash_request_set_crypt(req, &sg, NULL, this_step);
+                       r = verity_complete_op(res, crypto_ahash_update(req));
+                       if (unlikely(r))
+                               return r;
+                       data += this_step;
+                       len -= this_step;
+               } while (len);
+               return 0;
+       }
 }
 
 /*
@@ -609,7 +625,6 @@ static void verity_prefetch_io(struct work_struct *work)
                container_of(work, struct dm_verity_prefetch_work, work);
        struct dm_verity *v = pw->v;
        int i;
-       sector_t prefetch_size;
 
        for (i = v->levels - 2; i >= 0; i--) {
                sector_t hash_block_start;
@@ -632,14 +647,8 @@ static void verity_prefetch_io(struct work_struct *work)
                                hash_block_end = v->hash_blocks - 1;
                }
 no_prefetch_cluster:
-               // for emmc, it is more efficient to send bigger read
-               prefetch_size = max((sector_t)CONFIG_DM_VERITY_HASH_PREFETCH_MIN_SIZE,
-                       hash_block_end - hash_block_start + 1);
-               if ((hash_block_start + prefetch_size) >= (v->hash_start + v->hash_blocks)) {
-                       prefetch_size = hash_block_end - hash_block_start + 1;
-               }
                dm_bufio_prefetch(v->bufio, hash_block_start,
-                                 prefetch_size);
+                                 hash_block_end - hash_block_start + 1);
        }
 
        kfree(pw);