purge linux/scatterlist.h usage
There are only 4 users of this scatterlist API:
- dm-bht.c: dm_bht_verify_block (and internal funcs only it calls)
- dm-bht-userspace.c: dm_bht_compute_hash
- crypto.c: crypto_hash_digest & crypto_hash_update
For crypto.c, nothing calls crypto_hash_digest. So purge that.
For dm-bht.c, dm_bht_verify_block has long required that offset == 0.
This allows us to inline that offset down through dm_bht_compute_hash.
That leaves dm_bht_compute_hash which is processing a single buffer to
crypto_hash_update ...
For dm-bht-userspace.c, we see the same pattern. dm_bht_compute_hash
always has an offset == 0, and passes a single buffer at a time down
to crypto_hash_update ...
That leaves us with crypto_hash_update. Since it only cares about a
single buffer, rewrite the crypto API to accept the buffer directly
rather than going through the scatterlist structure.
At this point, nothing uses scatterlist, so drop it entirely.
BUG=chromium:878440
TEST=build works
Change-Id: I5188263b19df79d58a3f34ee1eeb6d31e75c151e
Reviewed-on: https://chromium-review.googlesource.com/1215182
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
diff --git a/dm-bht-userspace.c b/dm-bht-userspace.c
index 457ff83..8ded77f 100644
--- a/dm-bht-userspace.c
+++ b/dm-bht-userspace.c
@@ -11,7 +11,6 @@
#include <asm/page.h>
#include <linux/device-mapper.h>
-#include <linux/scatterlist.h>
#include "verity/dm-bht.h"
@@ -20,26 +19,21 @@
/**
* dm_bht_compute_hash: hashes a page of data
*/
-static int dm_bht_compute_hash(struct dm_bht *bht, struct page *pg,
- unsigned int offset, u8 *digest)
+static int dm_bht_compute_hash(struct dm_bht *bht, struct page *pg, u8 *digest)
{
struct hash_desc *hash_desc = &bht->hash_desc[0];
- struct scatterlist sg;
- sg_init_table(&sg, 1);
- sg_set_page(&sg, pg, PAGE_SIZE, offset);
/* Note, this is synchronous. */
if (crypto_hash_init(hash_desc)) {
DMCRIT("failed to reinitialize crypto hash");
return -EINVAL;
}
- if (crypto_hash_update(hash_desc, &sg, PAGE_SIZE)) {
+ if (crypto_hash_update(hash_desc, (const u8 *)pg, PAGE_SIZE)) {
DMCRIT("crypto_hash_update failed");
return -EINVAL;
}
if (bht->have_salt) {
- sg_set_buf(&sg, bht->salt, sizeof(bht->salt));
- if (crypto_hash_update(hash_desc, &sg, sizeof(bht->salt))) {
+ if (crypto_hash_update(hash_desc, bht->salt, sizeof(bht->salt))) {
DMCRIT("crypto_hash_update failed");
return -EINVAL;
}
@@ -103,7 +97,7 @@
struct page *pg = virt_to_page(child->nodes);
u8 *digest = dm_bht_node(bht, entry, j);
- r = dm_bht_compute_hash(bht, pg, 0, digest);
+ r = dm_bht_compute_hash(bht, pg, digest);
if (r) {
DMERR("Failed to update (d=%d,i=%u)",
depth, i);
@@ -114,7 +108,7 @@
}
r = dm_bht_compute_hash(bht,
virt_to_page(bht->levels[0].entries->nodes),
- 0, bht->root_digest);
+ bht->root_digest);
if (r)
DMERR("Failed to update root hash");
@@ -143,5 +137,5 @@
struct dm_bht_entry *entry = dm_bht_get_entry(bht, depth - 1, block);
u8 *node = dm_bht_get_node(bht, entry, depth, block);
- return dm_bht_compute_hash(bht, virt_to_page(block_data), 0, node);
+ return dm_bht_compute_hash(bht, virt_to_page(block_data), node);
}
diff --git a/dm-bht.c b/dm-bht.c
index 70add0b..3c19f7f 100644
--- a/dm-bht.c
+++ b/dm-bht.c
@@ -16,7 +16,6 @@
#include <linux/device-mapper.h>
#include <linux/errno.h>
#include <linux/kernel.h>
-#include <linux/scatterlist.h>
#include "verity/dm-bht.h"
@@ -106,27 +105,22 @@
/**
* dm_bht_compute_hash: hashes a page of data
*/
-static int dm_bht_compute_hash(struct dm_bht *bht, struct page *pg,
- unsigned int offset, u8 *digest)
+static int dm_bht_compute_hash(struct dm_bht *bht, struct page *pg, u8 *digest)
{
struct hash_desc *hash_desc = &bht->hash_desc[smp_processor_id()];
- struct scatterlist sg;
- sg_init_table(&sg, 1);
- sg_set_page(&sg, pg, PAGE_SIZE, offset);
/* Note, this is synchronous. */
if (crypto_hash_init(hash_desc)) {
DMCRIT("failed to reinitialize crypto hash (proc:%d)",
smp_processor_id());
return -EINVAL;
}
- if (crypto_hash_update(hash_desc, &sg, PAGE_SIZE)) {
+ if (crypto_hash_update(hash_desc, (const u8 *)pg, PAGE_SIZE)) {
DMCRIT("crypto_hash_update failed");
return -EINVAL;
}
if (bht->have_salt) {
- sg_set_buf(&sg, bht->salt, sizeof(bht->salt));
- if (crypto_hash_update(hash_desc, &sg, sizeof(bht->salt))) {
+ if (crypto_hash_update(hash_desc, bht->salt, sizeof(bht->salt))) {
DMCRIT("crypto_hash_update failed");
return -EINVAL;
}
@@ -368,7 +362,7 @@
* Verifies the path. Returns 0 on ok.
*/
static int dm_bht_verify_path(struct dm_bht *bht, unsigned int block,
- struct page *pg, unsigned int offset)
+ struct page *pg)
{
int depth = bht->depth;
u8 digest[DM_BHT_MAX_DIGEST_SIZE];
@@ -388,7 +382,7 @@
BUG_ON(state < DM_BHT_ENTRY_READY);
node = dm_bht_get_node(bht, entry, depth, block);
- if (dm_bht_compute_hash(bht, pg, offset, digest) ||
+ if (dm_bht_compute_hash(bht, pg, digest) ||
memcmp(digest, node, bht->digest_size))
goto mismatch;
@@ -396,11 +390,10 @@
* next pass.
*/
pg = virt_to_page(entry->nodes);
- offset = 0;
} while (--depth > 0 && state != DM_BHT_ENTRY_VERIFIED);
if (depth == 0 && state != DM_BHT_ENTRY_VERIFIED) {
- if (dm_bht_compute_hash(bht, pg, offset, digest) ||
+ if (dm_bht_compute_hash(bht, pg, digest) ||
memcmp(digest, bht->root_digest, bht->digest_size))
goto mismatch;
entry->state = DM_BHT_ENTRY_VERIFIED;
@@ -549,7 +542,7 @@
{
BUG_ON(offset != 0);
- return dm_bht_verify_path(bht, block, pg, offset);
+ return dm_bht_verify_path(bht, block, pg);
}
/**
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index b731aee..04a2e10 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -34,15 +34,11 @@
struct hash_tfm *tfm;
};
-struct scatterlist;
-
struct hash_tfm *crypto_alloc_hash(const char *alg_name, int a, int b);
void crypto_free_hash(struct hash_tfm *tfm);
unsigned int crypto_hash_digestsize(struct hash_tfm *tfm);
int crypto_hash_init(struct hash_desc *h);
-int crypto_hash_digest(struct hash_desc *h, struct scatterlist *sg,
- unsigned int sz, u8 *dst);
-int crypto_hash_update(struct hash_desc *h, struct scatterlist *sg,
+int crypto_hash_update(struct hash_desc *h, const u8 *buffer,
unsigned int size);
int crypto_hash_final(struct hash_desc *h, u8 *dst);
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
deleted file mode 100644
index f3592cb..0000000
--- a/include/linux/scatterlist.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Copyright (C) 2010 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by the GPL v2 license that can
- * be found in the LICENSE file.
- *
- * Parts of this file are derived from the Linux kernel from the file with
- * the same name and path under include/.
- */
-#ifndef VERITY_INCLUDE_LINUX_SCATTERLIST_H_
-#define VERITY_INCLUDE_LINUX_SCATTERLIST_H_
-#include <asm/page.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* We only support one page. */
-struct scatterlist {
- const void *buffer;
- size_t length;
- size_t offset;
-};
-
-void sg_init_table(struct scatterlist *sg, int pages);
-void sg_set_page(struct scatterlist *sg, struct page *page,
- unsigned int len, unsigned int offset);
-void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int len);
-void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int len);
-/* Non-standard. Only since we aren't playing tricks with the buffers addrs */
-void sg_destroy(struct scatterlist *sg);
-
-#endif /* VERITY_INCLUDE_LINUX_SCATTERLIST_ */
diff --git a/kernel/crypto.c b/kernel/crypto.c
index 28c3071..495d39b 100644
--- a/kernel/crypto.c
+++ b/kernel/crypto.c
@@ -7,7 +7,6 @@
*/
#include <linux/bug.h>
-#include <linux/scatterlist.h>
#include <linux/crypto.h>
#include <linux/init.h>
#include <crypto/hash.h>
@@ -66,22 +65,10 @@
return alg->init(desc);
}
-int crypto_hash_digest(struct hash_desc *h, struct scatterlist *sg,
- unsigned int sz, u8 *dst)
+int crypto_hash_update(struct hash_desc *h, const u8 *buffer, unsigned int size)
{
const struct shash_alg *alg = h->tfm->alg;
struct shash_desc *desc = &h->tfm->desc;
- u8 *buffer = (u8 *)(sg->buffer) + sg->offset;
-
- return alg->digest(desc, buffer, sz, dst);
-}
-
-int crypto_hash_update(struct hash_desc *h, struct scatterlist *sg,
- unsigned int size)
-{
- const struct shash_alg *alg = h->tfm->alg;
- struct shash_desc *desc = &h->tfm->desc;
- u8 *buffer = (u8 *)(sg->buffer) + sg->offset;
return alg->update(desc, buffer, size);
}
diff --git a/kernel/scatterlist.c b/kernel/scatterlist.c
deleted file mode 100644
index 64517df..0000000
--- a/kernel/scatterlist.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* Copyright (C) 2010 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by the GPL v2 license that can
- * be found in the LICENSE file.
- *
- * These files provide equivalent implementations for kernel calls for
- * compatibility with files under SRC/include.
- */
-
-#include <stdlib.h>
-
-#include <linux/bug.h>
-#include <linux/scatterlist.h>
-
-void sg_init_table(struct scatterlist *sg, int pages)
-{
- /* Pages is ignored at present. */
- if (pages > 1) abort();
- sg->buffer = NULL;
- sg->length = 0;
- sg->offset = 0;
-}
-
-void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int len)
-{
- sg->buffer = buf;
- sg->length = len;
- sg->offset = 0;
-}
-
-void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int len)
-{
- sg_init_table(sg, 1);
- sg_set_buf(sg, buf, len);
-}
-
-
-void sg_set_page(struct scatterlist *sg, struct page *page,
- unsigned int len, unsigned int offset)
-{
- sg_set_buf(sg, page->data, len);
- sg->offset = offset;
-}
-
-void sg_destroy(struct scatterlist *sg)
-{
- sg_init_table(sg, 0);
-}