aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColy Li <colyli@suse.de>2018-07-19 00:37:24 +0800
committerColy Li <colyli@suse.de>2018-07-19 00:37:24 +0800
commite2637ec1441ee3b8517225a8f02f20463cf671b0 (patch)
treee1ef9fb52d9ac18237e6616c50b7d572383429c1
parentcc2d14b5c36eebf2261d17b6d4980787b5aed3e7 (diff)
downloadbcache-patches-e2637ec1441ee3b8517225a8f02f20463cf671b0.tar.gz
for-test: update crc patches
-rw-r--r--for-test/libcrc64/v4-0000-cover-letter.patch (renamed from for-test/libcrc64/0000-cover-letter.patch)59
-rw-r--r--for-test/libcrc64/v4-0001-lib-add-crc64-calculation-routines.patch (renamed from for-test/libcrc64/v3-0001-lib-add-crc64-calculation-routines.patch)102
-rw-r--r--for-test/libcrc64/v4-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch (renamed from for-test/libcrc64/v3-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch)127
-rw-r--r--for-test/libcrc64/v4-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch (renamed from for-test/libcrc64/v3-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch)141
4 files changed, 167 insertions, 262 deletions
diff --git a/for-test/libcrc64/0000-cover-letter.patch b/for-test/libcrc64/v4-0000-cover-letter.patch
index c8a7106..59ee1ac 100644
--- a/for-test/libcrc64/0000-cover-letter.patch
+++ b/for-test/libcrc64/v4-0000-cover-letter.patch
@@ -1,24 +1,21 @@
-From a0d51df2563ddf707b31f8639b6533b8d4d5fb48 Mon Sep 17 00:00:00 2001
+From 7825d2a35f9b35912b666cd695478f12aeb1d2c1 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
-Date: Thu, 28 Jun 2018 15:05:18 +0800
-Subject: [PATCH v3 0/3] add crc64 calculation as kernel library
+Date: Wed, 18 Jul 2018 23:39:02 +0800
+Subject: [PATCH v4 0/3] add crc64 calculation as kernel library
This patch set adds basic implementation of crc64 calculation as Linux
kernel library. Since bcache already does crc64 by itself, this patch
set also modifies bcache code to use the new crc64 library routine.
+Currently bcache is the only user of crc64 calculation, another potential
+user is bcachefs which is on the way to be in mainline kernel. Therefore
+it makes sense to make crc64 calculation to be a public library.
+
bcache uses crc64 as storage checksum, if a change of crc lib routines
results an inconsistent result, the unmatched checksum may make bcache
'think' the on-disk is corrupted, such change should be avoided or
detected as early as possible. Therefore the last patch in this series
-adds a crc test framework, to check consistency of different calculations.
-
-Changelog:
-v3: Remove little endian restriction and remove 'le' from function names.
- Fixes all review comments of v2
-v2: Combine first two patches into one
- Fixes all review comments of v1
-v1: Initial version.
+adds a crc test framework, to check consistency of different calculations.
Coly Li
@@ -29,30 +26,36 @@ Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Michael Lyle <mlyle@lyle.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Randy Dunlap <rdunlap@infradead.org>
---
-Andy Shevchenko (1):
- lib/crc64: add crc64 option to lib/Kconfig
+Changelog:
+v4: Only keep crc64_be() in lib/crc64.c, tested bcache specific stuffs
+ moved back to bcache code.
+ Fixes all review comments of v3.
+v3: Remove little endian restriction and remove 'le' from function names.
+ Fixes all review comments of v2
+v2: Combine first two patches into one
+ Fixes all review comments of v1
+v1: Initial version.
Coly Li (3):
lib: add crc64 calculation routines
bcache: use routines from lib/crc64.c for CRC64 calculation
lib/test_crc: Add test cases for crc calculation
- drivers/md/bcache/bcache.h | 7 +-
- drivers/md/bcache/btree.c | 2 +-
- drivers/md/bcache/request.c | 2 +-
- drivers/md/bcache/super.c | 5 +-
- drivers/md/bcache/util.c | 131 ----------------------------------
- drivers/md/bcache/util.h | 5 +-
- include/linux/crc64.h | 15 ++++
- lib/.gitignore | 2 +
- lib/Kconfig | 8 +++
- lib/Kconfig.debug | 11 +++
- lib/Makefile | 12 ++++
- lib/crc64.c | 71 +++++++++++++++++++
- lib/gen_crc64table.c | 76 ++++++++++++++++++++
- lib/test_crc.c | 136 ++++++++++++++++++++++++++++++++++++
- 14 files changed, 341 insertions(+), 142 deletions(-)
+ drivers/md/bcache/Kconfig | 1 +
+ drivers/md/bcache/util.c | 131 --------------------------------------
+ drivers/md/bcache/util.h | 21 ++++--
+ include/linux/crc64.h | 11 ++++
+ lib/.gitignore | 2 +
+ lib/Kconfig | 8 +++
+ lib/Kconfig.debug | 10 +++
+ lib/Makefile | 12 ++++
+ lib/crc64.c | 56 ++++++++++++++++
+ lib/gen_crc64table.c | 68 ++++++++++++++++++++
+ lib/test_crc.c | 93 +++++++++++++++++++++++++++
+ 11 files changed, 278 insertions(+), 135 deletions(-)
create mode 100644 include/linux/crc64.h
create mode 100644 lib/crc64.c
create mode 100644 lib/gen_crc64table.c
diff --git a/for-test/libcrc64/v3-0001-lib-add-crc64-calculation-routines.patch b/for-test/libcrc64/v4-0001-lib-add-crc64-calculation-routines.patch
index 1548ccf..d2e5989 100644
--- a/for-test/libcrc64/v3-0001-lib-add-crc64-calculation-routines.patch
+++ b/for-test/libcrc64/v4-0001-lib-add-crc64-calculation-routines.patch
@@ -1,7 +1,7 @@
-From 2084f5bfe95016b3a027212d8c34df160d26a033 Mon Sep 17 00:00:00 2001
+From c95bf6ff1479a0a2caf949a88676c589ce8f3ec9 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
Date: Tue, 17 Jul 2018 14:37:58 +0800
-Subject: [PATCH v3 1/3] lib: add crc64 calculation routines
+Subject: [PATCH v4 1/3] lib: add crc64 calculation routines
This patch adds the re-write crc64 calculation routines for Linux kernel.
The CRC64 polynomical arithmetic follows ECMA-182 specification, inspired
@@ -13,23 +13,20 @@ All the changes work in this way,
- When Linux kernel is built, host program lib/gen_crc64table.c will be
compiled to lib/gen_crc64table and executed.
- The output of gen_crc64table execution is an array called as lookup
- table (a.k.a POLY 0x42f0e1eba9ea369) which contain 256 64bits-long
+ table (a.k.a POLY 0x42f0e1eba9ea369) which contain 256 64-bit long
numbers, this talbe is dumped into header file lib/crc64table.h.
- Then the header file is included by lib/crc64.c for normal 64bit crc
calculation.
- Function declaration of the crc64 calculation routines is placed in
include/linux/crc64.h
-Changelog:
-v3: More fixes for review comments of v2
- By review comments from Eric Biggers, current functions naming with
- 'le' is misleading. Remove 'le' from the crc function names, and use
- u64 to replace __le64 in parameters and return values.
-v2: Fix reivew comments of v1
-v1: Initial version.
+Currently bcache is the only user of crc64_be(), another potential user
+is bcachefs which is on the way to be in mainline kernel. Therefore it
+makes sense to move crc64 calculation into lib/crc64.c as public code.
Signed-off-by: Coly Li <colyli@suse.de>
Co-developed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
+Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
@@ -39,24 +36,37 @@ Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Eric Biggers <ebiggers3@gmail.com>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Randy Dunlap <rdunlap@infradead.org>
---
- include/linux/crc64.h | 13 ++++++++
+Changelog:
+v4: Only keep crc64_be() in lib/crc64.c, move rested bcache specific
+ stuffs back to bcache code.
+ Other fixes from the review comments of v3
+v3: More fixes for review comments of v2
+ By review comments from Eric Biggers, current functions naming with
+ 'le' is misleading. Remove 'le' from the crc function names, and use
+ u64 to replace __le64 in parameters and return values.
+v2: Fix reivew comments of v1
+v1: Initial version.
+
+ include/linux/crc64.h | 11 +++++++
lib/.gitignore | 2 ++
lib/Kconfig | 8 +++++
lib/Makefile | 11 +++++++
- lib/crc64.c | 71 +++++++++++++++++++++++++++++++++++++++++++
- lib/gen_crc64table.c | 69 +++++++++++++++++++++++++++++++++++++++++
- 6 files changed, 174 insertions(+)
+ lib/crc64.c | 56 +++++++++++++++++++++++++++++++++++
+ lib/gen_crc64table.c | 68 +++++++++++++++++++++++++++++++++++++++++++
+ 6 files changed, 156 insertions(+)
create mode 100644 include/linux/crc64.h
create mode 100644 lib/crc64.c
create mode 100644 lib/gen_crc64table.c
diff --git a/include/linux/crc64.h b/include/linux/crc64.h
new file mode 100644
-index 000000000000..3e87b61cd54f
+index 000000000000..1fc9f0710c10
--- /dev/null
+++ b/include/linux/crc64.h
-@@ -0,0 +1,13 @@
+@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * See lib/crc64.c for the related specification and polynomical arithmetic.
@@ -66,9 +76,7 @@ index 000000000000..3e87b61cd54f
+
+#include <linux/types.h>
+
-+u64 __pure crc64_update(u64 crc, const void *_p, size_t len);
-+u64 __pure crc64(const void *p, size_t len);
-+u64 __pure crc64_bch(const void *p, size_t len);
++u64 __pure crc64_be(u64 crc, const void *p, size_t len);
+#endif /* _LINUX_CRC64_H */
diff --git a/lib/.gitignore b/lib/.gitignore
index 09aae85418ab..f2a39c9e5485 100644
@@ -140,13 +148,13 @@ index 90dc5520b784..40c215181687 100644
#
diff --git a/lib/crc64.c b/lib/crc64.c
new file mode 100644
-index 000000000000..64b5f1ec3016
+index 000000000000..d093298ba2c6
--- /dev/null
+++ b/lib/crc64.c
-@@ -0,0 +1,71 @@
+@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
-+ * Normal 64bit CRC calculation.
++ * Normal 64-bit CRC calculation.
+ *
+ * This is a basic crc64 implementation following ECMA-182 specification,
+ * which can be found from,
@@ -158,7 +166,7 @@ index 000000000000..64b5f1ec3016
+ * from,
+ * http://www.ross.net/crc/download/crc_v3.txt
+ *
-+ * crc64table[256] is the lookup table of a table-driver 64bit CRC
++ * crc64table[256] is the lookup table of a table-driver 64-bit CRC
+ * calculation, which is generated by gen_crc64table.c in kernel build
+ * time. The polynomial of crc64 arithmetic is from ECMA-182 specification
+ * as well, which is defined as,
@@ -170,7 +178,6 @@ index 000000000000..64b5f1ec3016
+ *
+ * Copyright 2018 SUSE Linux.
+ * Author: Coly Li <colyli@suse.de>
-+ *
+ */
+
+#include <linux/module.h>
@@ -180,47 +187,33 @@ index 000000000000..64b5f1ec3016
+MODULE_DESCRIPTION("CRC64 calculations");
+MODULE_LICENSE("GPL v2");
+
-+u64 __pure crc64_update(u64 crc, const void *_p, size_t len)
++/**
++ * crc64_be - Calculate bitwise big-endian ECMA-182 CRC64
++ * @crc: seed value for computation. 0 for a new CRC computing, or the
++ * previous crc64 value if computing incrementally.
++ * @p: pointer to buffer over which CRC64 is run
++ * @len: length of buffer @p
++ */
++u64 __pure crc64_be(u64 crc, const void *p, size_t len)
+{
+ size_t i, t;
+
-+ const unsigned char *p = _p;
++ const unsigned char *_p = p;
+
+ for (i = 0; i < len; i++) {
-+ t = ((crc >> 56) ^ (*p++)) & 0xFF;
++ t = ((crc >> 56) ^ (*_p++)) & 0xFF;
+ crc = crc64table[t] ^ (crc << 8);
+ }
+
+ return crc;
+}
-+EXPORT_SYMBOL_GPL(crc64_update);
-+
-+u64 __pure crc64(const void *p, size_t len)
-+{
-+ u64 crc = 0x0ULL;
-+
-+ crc = crc64_update(crc, p, len);
-+
-+ return crc;
-+}
-+EXPORT_SYMBOL_GPL(crc64);
-+
-+/* For checksum calculation in drivers/md/bcache/ */
-+u64 __pure crc64_bch(const void *p, size_t len)
-+{
-+ u64 crc = 0xFFFFFFFFFFFFFFFFULL;
-+
-+ crc = crc64_update(crc, p, len);
-+
-+ return (crc ^ 0xFFFFFFFFFFFFFFFFULL);
-+}
-+EXPORT_SYMBOL_GPL(crc64_bch);
++EXPORT_SYMBOL_GPL(crc64_be);
diff --git a/lib/gen_crc64table.c b/lib/gen_crc64table.c
new file mode 100644
-index 000000000000..af9c4d12c0a1
+index 000000000000..8296b0c3ea30
--- /dev/null
+++ b/lib/gen_crc64table.c
-@@ -0,0 +1,69 @@
+@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generate lookup table for the talbe-driven CRC64 calculation.
@@ -235,16 +228,15 @@ index 000000000000..af9c4d12c0a1
+ *
+ * Copyright 2018 SUSE Linux.
+ * Author: Coly Li <colyli@suse.de>
-+ *
+ */
-+
+#include <inttypes.h>
+#include <stdio.h>
++
+#include <linux/swab.h>
+
+#define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL
+
-+static int64_t crc64_table[256] = {0,};
++static int64_t crc64_table[256] = {0};
+
+static void generate_crc64_table(void)
+{
@@ -271,7 +263,7 @@ index 000000000000..af9c4d12c0a1
+ int i;
+
+ printf("/* this file is generated - do not edit */\n\n");
-+ printf("#include <uapi/linux/types.h>\n");
++ printf("#include <linux/types.h>\n");
+ printf("#include <linux/cache.h>\n\n");
+ printf("static const u64 ____cacheline_aligned crc64table[256] = {\n");
+ for (i = 0; i < 256; i++) {
diff --git a/for-test/libcrc64/v3-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch b/for-test/libcrc64/v4-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch
index e257073..e28e0cc 100644
--- a/for-test/libcrc64/v3-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch
+++ b/for-test/libcrc64/v4-0002-bcache-use-routines-from-lib-crc64.c-for-CRC64-ca.patch
@@ -1,7 +1,7 @@
-From b0e31c4eae7e9af59b37f21eed8fc57bbccd42e6 Mon Sep 17 00:00:00 2001
+From caf78a4c9a120fdff8390b70d2fd0eeaedfb4531 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
Date: Wed, 23 May 2018 16:02:35 +0800
-Subject: [PATCH v3 2/3] bcache: use routines from lib/crc64.c for CRC64
+Subject: [PATCH v4 2/3] bcache: use routines from lib/crc64.c for CRC64
calculation
Now we have crc64 calculation in lib/crc64.c, it is unnecessary for
@@ -10,21 +10,25 @@ crc64 routines in lib/crc64.c.
Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
-Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
+Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Lyle <mlyle@lyle.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Randy Dunlap <rdunlap@infradead.org>
---
- drivers/md/bcache/Kconfig | 1 +
- drivers/md/bcache/bcache.h | 7 +-
- drivers/md/bcache/btree.c | 2 +-
- drivers/md/bcache/request.c | 2 +-
- drivers/md/bcache/super.c | 5 +-
- drivers/md/bcache/util.c | 131 ------------------------------------
- drivers/md/bcache/util.h | 5 +-
- 7 files changed, 11 insertions(+), 142 deletions(-)
+Changelog:
+v3: Only call crc64_be() from lib/crc64.c, and implemennt bch_crc64()
+ and bch_crc64_update() based on crc64_be().
+v2: Call crc64_le_bch(), crc64_le_update() from lib/crc64.c
+v1: Initial version
+
+ drivers/md/bcache/Kconfig | 1 +
+ drivers/md/bcache/util.c | 131 --------------------------------------
+ drivers/md/bcache/util.h | 21 ++++--
+ 3 files changed, 18 insertions(+), 135 deletions(-)
diff --git a/drivers/md/bcache/Kconfig b/drivers/md/bcache/Kconfig
index 17bf109c58e9..af247298409a 100644
@@ -38,80 +42,6 @@ index 17bf109c58e9..af247298409a 100644
---help---
Allows a block device to be used as cache for other devices; uses
a btree for indexing and the layout is optimized for SSDs.
-diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
-index d6bf294f3907..6d4d2356c3cc 100644
---- a/drivers/md/bcache/bcache.h
-+++ b/drivers/md/bcache/bcache.h
-@@ -189,6 +189,7 @@
- #include <linux/types.h>
- #include <linux/workqueue.h>
- #include <linux/kthread.h>
-+#include <linux/crc64.h>
-
- #include "bset.h"
- #include "util.h"
-@@ -803,9 +804,9 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
- * jset: The checksum is _always_ the first 8 bytes of these structs
- */
- #define csum_set(i) \
-- bch_crc64(((void *) (i)) + sizeof(uint64_t), \
-- ((void *) bset_bkey_last(i)) - \
-- (((void *) (i)) + sizeof(uint64_t)))
-+ crc64_bch(((void *) (i)) + sizeof(uint64_t), \
-+ ((void *) bset_bkey_last(i)) - \
-+ (((void *) (i)) + sizeof(uint64_t)))
-
- /* Error handling macros */
-
-diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
-index 547c9eedc2f4..72619508c928 100644
---- a/drivers/md/bcache/btree.c
-+++ b/drivers/md/bcache/btree.c
-@@ -194,7 +194,7 @@ static uint64_t btree_csum_set(struct btree *b, struct bset *i)
- uint64_t crc = b->key.ptr[0];
- void *data = (void *) i + 8, *end = bset_bkey_last(i);
-
-- crc = bch_crc64_update(crc, data, end - data);
-+ crc = crc64_update(crc, data, end - data);
- return crc ^ 0xffffffffffffffffULL;
- }
-
-diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
-index ae67f5fa8047..28b2fb11a3d5 100644
---- a/drivers/md/bcache/request.c
-+++ b/drivers/md/bcache/request.c
-@@ -45,7 +45,7 @@ static void bio_csum(struct bio *bio, struct bkey *k)
-
- bio_for_each_segment(bv, bio, iter) {
- void *d = kmap(bv.bv_page) + bv.bv_offset;
-- csum = bch_crc64_update(csum, d, bv.bv_len);
-+ csum = crc64_update(csum, d, bv.bv_len);
- kunmap(bv.bv_page);
- }
-
-diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
-index fa4058e43202..c425c52f0c42 100644
---- a/drivers/md/bcache/super.c
-+++ b/drivers/md/bcache/super.c
-@@ -549,7 +549,7 @@ void bch_prio_write(struct cache *ca)
-
- p->next_bucket = ca->prio_buckets[i + 1];
- p->magic = pset_magic(&ca->sb);
-- p->csum = bch_crc64(&p->magic, bucket_bytes(ca) - 8);
-+ p->csum = crc64_bch(&p->magic, bucket_bytes(ca) - 8);
-
- bucket = bch_bucket_alloc(ca, RESERVE_PRIO, true);
- BUG_ON(bucket == -1);
-@@ -599,7 +599,8 @@ static void prio_read(struct cache *ca, uint64_t bucket)
-
- prio_io(ca, bucket, REQ_OP_READ, 0);
-
-- if (p->csum != bch_crc64(&p->magic, bucket_bytes(ca) - 8))
-+ if (p->csum != crc64_bch(&p->magic,
-+ bucket_bytes(ca) - 8))
- pr_warn("bad csum reading priorities");
-
- if (p->magic != pset_magic(&ca->sb))
diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
index fc479b026d6d..f912c372978c 100644
--- a/drivers/md/bcache/util.c
@@ -252,7 +182,7 @@ index fc479b026d6d..f912c372978c 100644
- return crc ^ 0xffffffffffffffffULL;
-}
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
-index cced87f8eb27..b1deec0dc958 100644
+index cced87f8eb27..a1579e28049f 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -11,6 +11,7 @@
@@ -263,7 +193,30 @@ index cced87f8eb27..b1deec0dc958 100644
#include "closure.h"
-@@ -561,8 +562,4 @@ static inline sector_t bdev_sectors(struct block_device *bdev)
+@@ -542,6 +543,22 @@ dup: \
+ #define RB_PREV(ptr, member) \
+ container_of_or_null(rb_prev(&(ptr)->member), typeof(*ptr), member)
+
++static inline uint64_t bch_crc64(const void *p, size_t len)
++{
++ uint64_t crc = 0xffffffffffffffffULL;
++
++ crc = crc64_be(crc, p, len);
++ return crc ^ 0xffffffffffffffffULL;
++}
++
++static inline uint64_t bch_crc64_update(uint64_t crc,
++ const void *p,
++ size_t len)
++{
++ crc = crc64_be(crc, p, len);
++ return crc;
++}
++
+ /* Does linear interpolation between powers of two */
+ static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits)
+ {
+@@ -561,8 +578,4 @@ static inline sector_t bdev_sectors(struct block_device *bdev)
{
return bdev->bd_inode->i_size >> 9;
}
diff --git a/for-test/libcrc64/v3-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch b/for-test/libcrc64/v4-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch
index 2d97f06..946bbc6 100644
--- a/for-test/libcrc64/v3-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch
+++ b/for-test/libcrc64/v4-0003-lib-test_crc-Add-test-cases-for-crc-calculation.patch
@@ -1,32 +1,21 @@
-From c90be04f1726a38e8c941a6a5e9b4d7d3f3c1cf2 Mon Sep 17 00:00:00 2001
+From 7825d2a35f9b35912b666cd695478f12aeb1d2c1 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
Date: Wed, 6 Jun 2018 21:20:46 +0800
-Subject: [PATCH v3 3/3] lib/test_crc: Add test cases for crc calculation
+Subject: [PATCH v4 3/3] lib/test_crc: Add test cases for crc calculation
This patch adds a kernel module to test the consistency of multiple crc
calculation in Linux kernel. It is enabled with CONFIG_TEST_CRC enabled.
The test results are printed into kernel message, which look like,
-test_crc: crc64: PASSED (0x4e6b1ff972fa8c55, expected 0x4e6b1ff972fa8c55)
-test_crc: crc64_bch: PASSED (0x0e4f1391d7a4a62e, expected 0x0e4f1391d7a4a62e)
-test_crc: crc64_update: FAILED (0x03d4d0d85685d9a1, expected 0x3d4d0d85685d9a1f)
+test_crc: crc64_be: FAILED (0x03d4d0d85685d9a1, expected 0x3d4d0d85685d9a1f)
kernel 0day system has framework to check kernel message, then the above
result can be handled by 0day system. If crc calculation inconsistency
happens, it can be detected quite soon.
lib/test_crc.c is a testing frame work for many crc consistency
-testings. For now, there are only test caes for 3 crc routines,
-- crc64()
-- crc64_bch()
-- crc64_update()
-
-Changelog:
-v3: Add test cases passed/failed statistic
- More fixes for review comments of v2
-v2: Fixes for review comments of v1
-v1: Initial version.
+testings. For now, there is only one test caes for crc64_be().
Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
@@ -34,11 +23,24 @@ Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Randy Dunlap <rdunlap@infradead.org>
+Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
+Cc: Noah Massey <noah.massey@gmail.com>
---
- lib/Kconfig.debug | 10 ++++
- lib/Makefile | 1 +
- lib/test_crc.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++
- 3 files changed, 149 insertions(+)
+Changelog:
+v4: Improve error statistic and failure message display by suggestion
+ from Andy Shevchenko and Noah Massey.
+ Fixes for review commennts of v3
+v3: Add test cases passed/failed statistic
+ More fixes for review comments of v2
+v2: Fixes for review comments of v1
+v1: Initial version.
+
+ lib/Kconfig.debug | 10 +++++
+ lib/Makefile | 1 +
+ lib/test_crc.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 104 insertions(+)
create mode 100644 lib/test_crc.c
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
@@ -76,10 +78,10 @@ index 40c215181687..224d047d026a 100644
CFLAGS_test_kasan.o += -fno-builtin
diff --git a/lib/test_crc.c b/lib/test_crc.c
new file mode 100644
-index 000000000000..441bf835fbd3
+index 000000000000..324e8ad419d7
--- /dev/null
+++ b/lib/test_crc.c
-@@ -0,0 +1,138 @@
+@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * CRC test driver
@@ -93,22 +95,10 @@ index 000000000000..441bf835fbd3
+ * when this test driver is loaded.
+ *
+ * Current test routines are,
-+ * - crc64()
-+ * - crc64_bch()
-+ * - crc64_update()
-+ *
++ * - crc64_be()
+ */
+
-+#include <linux/async.h>
-+#include <linux/delay.h>
-+#include <linux/fs.h>
-+#include <linux/list.h>
+#include <linux/module.h>
-+#include <linux/printk.h>
-+#include <linux/miscdevice.h>
-+#include <linux/slab.h>
-+#include <linux/uaccess.h>
-+#include <linux/vmalloc.h>
+#include <linux/crc64.h>
+
+struct crc_test_record {
@@ -116,48 +106,30 @@ index 000000000000..441bf835fbd3
+ u64 data[4];
+ u64 initval;
+ u64 expval;
-+ int (*handler)(struct crc_test_record *rec);
++ void (*handler)(struct crc_test_record *rec);
+};
+
-+static int chk_and_msg(const char *name, u64 crc, u64 expval)
-+{
-+ int ret = 0;
-+
-+ if (crc == expval) {
-+ pr_info("test_crc: %s: PASSED:(0x%016llx, expected 0x%016llx)\n",
-+ name, crc, expval);
-+ } else {
-+ pr_err("test_crc: %s: FAILED:(0x%016llx, expected 0x%016llx)\n",
-+ name, crc, expval);
-+ ret = -EINVAL;
-+ }
-+
-+ return ret;
-+}
++int failed_tests;
++int total_tests;
+
-+/* Add your crc test cases here */
-+static int test_crc64(struct crc_test_record *rec)
++static void chk_and_msg(const char *name, u64 crc, u64 expval)
+{
-+ u64 crc;
++ total_tests++;
++ if (crc == expval)
++ return;
+
-+ crc = crc64(rec->data, sizeof(rec->data));
-+ return chk_and_msg(rec->name, crc, rec->expval);
++ pr_err("test_crc: %s: FAILED:(0x%016llx, expected 0x%016llx)\n",
++ name, crc, expval);
++ failed_tests++;
+}
+
-+static int test_crc64_bch(struct crc_test_record *rec)
++/* Add your crc test cases here */
++static void test_crc64_be(struct crc_test_record *rec)
+{
+ u64 crc;
+
-+ crc = crc64_bch(rec->data, sizeof(rec->data));
-+ return chk_and_msg(rec->name, crc, rec->expval);
-+}
-+
-+static int test_crc64_update(struct crc_test_record *rec)
-+{
-+ u64 crc = rec->initval;
-+
-+ crc = crc64_update(crc, rec->data, sizeof(rec->data));
-+ return chk_and_msg(rec->name, crc, rec->expval);
++ crc = crc64_be(rec->initval, rec->data, sizeof(rec->data));
++ chk_and_msg(rec->name, crc, rec->expval);
+}
+
+/*
@@ -166,26 +138,12 @@ index 000000000000..441bf835fbd3
+ * pre-calculated values.
+ */
+static struct crc_test_record test_data[] = {
-+ { .name = "crc64",
-+ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
-+ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
-+ .initval = 0,
-+ .expval = 0xe2b9911e7b997201,
-+ .handler = test_crc64,
-+ },
-+ { .name = "crc64_bch",
-+ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
-+ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
-+ .initval = 0,
-+ .expval = 0xd2753a20fd862892,
-+ .handler = test_crc64_bch,
-+ },
-+ { .name = "crc64_update",
++ { .name = "crc64_be",
+ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
+ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
+ .initval = 0x61C8864680B583EB,
+ .expval = 0xb2c863673f4292bf,
-+ .handler = test_crc64_update,
++ .handler = test_crc64_be,
+ },
+ {}
+};
@@ -193,22 +151,21 @@ index 000000000000..441bf835fbd3
+static int __init test_crc_init(void)
+{
+ int i;
-+ int v, err = 0;
+
-+ pr_info("Kernel CRC consitency testing:\n");
-+ for (i = 0; test_data[i].name; i++) {
-+ v = test_data[i].handler(&test_data[i]);
-+ if (v < 0)
-+ err++;
-+ }
++ failed_tests = 0;
++ total_tests = 0;
++
++ pr_info("Kernel CRC consistency testing:\n");
++ for (i = 0; test_data[i].name; i++)
++ test_data[i].handler(&test_data[i]);
+
-+ if (err == 0)
++ if (failed_tests == 0)
+ pr_info("test_crc: all %d tests passed\n", i);
+ else
+ pr_err("test_crc: %d cases tested, %d passed, %d failed\n",
-+ i, i - err, err);
++ total_tests, total_tests - failed_tests, failed_tests);
+
-+ return (err == 0) ? 0 : -EINVAL;
++ return (failed_tests == 0) ? 0 : -EINVAL;
+}
+late_initcall(test_crc_init);
+