aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColy Li <colyli@suse.de>2018-06-28 15:31:49 +0800
committerColy Li <colyli@suse.de>2018-06-28 15:31:49 +0800
commitea3bb0c654a08f48a7467b030577e6c15d2e76eb (patch)
treebf685fdf88addf41cc626a80c053c098043f0fc3
parentf491e8e7d8c43aacce2b829d7b49f9e15d509640 (diff)
downloadbcache-patches-ea3bb0c654a08f48a7467b030577e6c15d2e76eb.tar.gz
for-test: update lib crc64
-rw-r--r--for-test/libcrc64/0000-cover-letter.patch48
-rw-r--r--for-test/libcrc64/0001-lib-crc64-add-crc64-option-to-lib-Kconfig.patch8
-rw-r--r--for-test/libcrc64/0002-lib-add-crc64-calculation-routines.patch (renamed from for-test/libcrc64/0003-lib-crc64-add-64bits-CRC-calculation.patch)114
-rw-r--r--for-test/libcrc64/0002-lib-crc64-add-crc64-entries-into-lib-Makefile.patch57
-rw-r--r--for-test/libcrc64/0003-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch (renamed from for-test/libcrc64/0004-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch)41
-rw-r--r--for-test/libcrc64/0004-lib-test_crc-Add-test-cases-for-crc-calculation.patch213
6 files changed, 356 insertions, 125 deletions
diff --git a/for-test/libcrc64/0000-cover-letter.patch b/for-test/libcrc64/0000-cover-letter.patch
new file mode 100644
index 0000000..727989e
--- /dev/null
+++ b/for-test/libcrc64/0000-cover-letter.patch
@@ -0,0 +1,48 @@
+From a0d51df2563ddf707b31f8639b6533b8d4d5fb48 Mon Sep 17 00:00:00 2001
+From: Coly Li <colyli@suse.de>
+Date: Thu, 28 Jun 2018 15:05:18 +0800
+Subject: [PATCH 0/4] 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.
+
+Because crc64 is used by bcache as storage checksum, inconsistent
+calculation result by future possible change may make bcache 'think' the
+on-disk is corrupted, such future changes should be avoided or detected
+as early as possible. The last patch in this series adds a crc test
+framework, to check consistency of different calculations.
+
+Coly Li
+---
+Andy Shevchenko (1):
+ lib/crc64: add crc64 option to lib/Kconfig
+
+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(-)
+ create mode 100644 include/linux/crc64.h
+ create mode 100644 lib/crc64.c
+ create mode 100644 lib/gen_crc64table.c
+ create mode 100644 lib/test_crc.c
+
+--
+2.17.1
+
diff --git a/for-test/libcrc64/0001-lib-crc64-add-crc64-option-to-lib-Kconfig.patch b/for-test/libcrc64/0001-lib-crc64-add-crc64-option-to-lib-Kconfig.patch
index d6dd858..306f4ca 100644
--- a/for-test/libcrc64/0001-lib-crc64-add-crc64-option-to-lib-Kconfig.patch
+++ b/for-test/libcrc64/0001-lib-crc64-add-crc64-option-to-lib-Kconfig.patch
@@ -1,4 +1,4 @@
-From 73d4830984a4bf86c1cf8e565a6ac59becc3323b Mon Sep 17 00:00:00 2001
+From a8db527ec7ae6f762e0a8144982d0e8b4725d51d Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Wed, 23 May 2018 13:23:32 +0800
Subject: [PATCH 1/4] lib/crc64: add crc64 option to lib/Kconfig
@@ -9,12 +9,14 @@ and compose the commit log for a re-written crc64 source code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Coly Li <colyli@suse.de>
+Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Cc: Luis R. Rodriguez <mcgrof@suse.com>
---
lib/Kconfig | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/Kconfig b/lib/Kconfig
-index 5fe577673b98..fd94ea64aab7 100644
+index 706836ec314d..4059df9ec4c7 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -170,6 +170,14 @@ config CRC32_BIT
@@ -33,5 +35,5 @@ index 5fe577673b98..fd94ea64aab7 100644
tristate "CRC4 functions"
help
--
-2.16.3
+2.17.1
diff --git a/for-test/libcrc64/0003-lib-crc64-add-64bits-CRC-calculation.patch b/for-test/libcrc64/0002-lib-add-crc64-calculation-routines.patch
index b7cec2a..1931d3e 100644
--- a/for-test/libcrc64/0003-lib-crc64-add-64bits-CRC-calculation.patch
+++ b/for-test/libcrc64/0002-lib-add-crc64-calculation-routines.patch
@@ -1,43 +1,45 @@
-From 933315666eadef3824b2c355f07b518b17979827 Mon Sep 17 00:00:00 2001
+From 31a6632d9e5b428d5f87c41542e6b5a3f27a7d29 Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
-Date: Wed, 23 May 2018 15:18:43 +0800
-Subject: [PATCH 3/4] lib/crc64: add 64bits CRC calculation
+Date: Thu, 28 Jun 2018 11:19:24 +0800
+Subject: [PATCH 2/4] lib: add crc64 calculation routines
-This patch is a re-write of normal CRC64 implementation, like other
-numerous code in public domain. The CRC64 polynomical arithmetic follows
-ECMA-182 specification, inspired by CRC paper of Dr. Ross N. Williams
+This patch adds the re-write crc64 calculation routines for Linux kernel.
+The CRC64 polynomical arithmetic follows ECMA-182 specification, inspired
+by CRC paper of Dr. Ross N. Williams
(see http://www.ross.net/crc/download/crc_v3.txt) and other public domain
implementations.
-- lib/gen_crc64table.c is the host application to generate crc64 lookup
-table (a.k.a POLY 0x42f0e1eba9ea369) into lib/crc64table.h
-- lib/crc64.c then includes lib/crc64table.h to reference the lookup table
-for CRC64 calculation.
-- include/linux/crc64.h has functions declaration exported by lib/crc64.c.
-
-Currently bcache (drivers/md/bcache) is the only user of lib/crc64.c, the
-original idea of moving crc64 code into lib/crc64.c was from Andy
-Shevchenko and Michael Lyle. Unfortunately the crc64 code from bcache is
-not pure GPL licensed (which is PostgreSQL license), so I have to rewrite
-from scratch for a GPL version.
+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
+ 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
Signed-off-by: Coly Li <colyli@suse.de>
+Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Lyle <mlyle@lyle.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
+Cc: Luis R. Rodriguez <mcgrof@suse.com>
---
include/linux/crc64.h | 15 +++++++++
lib/.gitignore | 2 ++
- lib/crc64.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++
- lib/gen_crc64table.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
- 4 files changed, 179 insertions(+)
+ lib/Makefile | 11 +++++++
+ lib/crc64.c | 71 ++++++++++++++++++++++++++++++++++++++++
+ lib/gen_crc64table.c | 76 +++++++++++++++++++++++++++++++++++++++++++
+ 5 files changed, 175 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..dd32906c229e
+index 000000000000..cbd10a47d861
--- /dev/null
+++ b/include/linux/crc64.h
@@ -0,0 +1,15 @@
@@ -54,7 +56,7 @@ index 000000000000..dd32906c229e
+
+__le64 crc64_le_update(__le64 crc, const void *_p, size_t len);
+__le64 crc64_le(const void *p, size_t len);
-+__le64 crc64_le_we(const void *p, size_t len);
++__le64 crc64_le_bch(const void *p, size_t len);
+#endif /* _LINUX_CRC64_H */
diff --git a/lib/.gitignore b/lib/.gitignore
index 09aae85418ab..f2a39c9e5485 100644
@@ -68,12 +70,49 @@ index 09aae85418ab..f2a39c9e5485 100644
crc32table.h
+crc64table.h
oid_registry_data.c
+diff --git a/lib/Makefile b/lib/Makefile
+index 90dc5520b784..40c215181687 100644
+--- a/lib/Makefile
++++ b/lib/Makefile
+@@ -102,6 +102,7 @@ obj-$(CONFIG_CRC16) += crc16.o
+ obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
+ obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o
+ obj-$(CONFIG_CRC32) += crc32.o
++obj-$(CONFIG_CRC64) += crc64.o
+ obj-$(CONFIG_CRC32_SELFTEST) += crc32test.o
+ obj-$(CONFIG_CRC4) += crc4.o
+ obj-$(CONFIG_CRC7) += crc7.o
+@@ -215,7 +216,9 @@ obj-$(CONFIG_FONT_SUPPORT) += fonts/
+ obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o
+
+ hostprogs-y := gen_crc32table
++hostprogs-y += gen_crc64table
+ clean-files := crc32table.h
++clean-files += crc64table.h
+
+ $(obj)/crc32.o: $(obj)/crc32table.h
+
+@@ -225,6 +228,14 @@ quiet_cmd_crc32 = GEN $@
+ $(obj)/crc32table.h: $(obj)/gen_crc32table
+ $(call cmd,crc32)
+
++$(obj)/crc64.o: $(obj)/crc64table.h
++
++quiet_cmd_crc64 = GEN $@
++ cmd_crc64 = $< > $@
++
++$(obj)/crc64table.h: $(obj)/gen_crc64table
++ $(call cmd,crc64)
++
+ #
+ # Build a fast OID lookip registry from include/linux/oid_registry.h
+ #
diff --git a/lib/crc64.c b/lib/crc64.c
new file mode 100644
-index 000000000000..8393b2cb17c3
+index 000000000000..03f078303bd3
--- /dev/null
+++ b/lib/crc64.c
-@@ -0,0 +1,78 @@
+@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Normal 64bit CRC calculation.
@@ -101,14 +140,6 @@ index 000000000000..8393b2cb17c3
+ * Copyright 2018 SUSE Linux.
+ * Author: Coly Li <colyli@suse.de>
+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License version
-+ * 2 as published by the Free Software Foundation;
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
@@ -143,7 +174,8 @@ index 000000000000..8393b2cb17c3
+}
+EXPORT_SYMBOL_GPL(crc64_le);
+
-+__le64 crc64_le_we(const void *p, size_t len)
++/* For checksum calculation in drivers/md/bcache/ */
++__le64 crc64_le_bch(const void *p, size_t len)
+{
+ __le64 crc = 0xFFFFFFFFFFFFFFFFULL;
+
@@ -151,13 +183,13 @@ index 000000000000..8393b2cb17c3
+
+ return (crc ^ 0xFFFFFFFFFFFFFFFFULL);
+}
-+EXPORT_SYMBOL_GPL(crc64_le_we);
++EXPORT_SYMBOL_GPL(crc64_le_bch);
diff --git a/lib/gen_crc64table.c b/lib/gen_crc64table.c
new file mode 100644
-index 000000000000..6cd6cd807b2a
+index 000000000000..d0526813b1db
--- /dev/null
+++ b/lib/gen_crc64table.c
-@@ -0,0 +1,84 @@
+@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generate lookup table for the talbe-driven CRC64 calculation.
@@ -173,14 +205,6 @@ index 000000000000..6cd6cd807b2a
+ * Copyright 2018 SUSE Linux.
+ * Author: Coly Li <colyli@suse.de>
+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License version
-+ * 2 as published by the Free Software Foundation;
-+ *
-+ * This program is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
+ */
+
+#include <inttypes.h>
@@ -243,5 +267,5 @@ index 000000000000..6cd6cd807b2a
+ return 0;
+}
--
-2.16.3
+2.17.1
diff --git a/for-test/libcrc64/0002-lib-crc64-add-crc64-entries-into-lib-Makefile.patch b/for-test/libcrc64/0002-lib-crc64-add-crc64-entries-into-lib-Makefile.patch
deleted file mode 100644
index 1828975..0000000
--- a/for-test/libcrc64/0002-lib-crc64-add-crc64-entries-into-lib-Makefile.patch
+++ /dev/null
@@ -1,57 +0,0 @@
-From 475dc0239a72070e69b6658446326bdf712d9a9d Mon Sep 17 00:00:00 2001
-From: Coly Li <colyli@suse.de>
-Date: Wed, 23 May 2018 13:29:54 +0800
-Subject: [PATCH 2/4] lib/crc64: add crc64 entries into lib/Makefile
-
-This patch changes lib/Makefile for lib/gen_crc64table.c and lib/crc64.c.
-When Linux kernel is built, lib/gen_crc64table.c will be compiled to
-lib/gen_crc64table and executed. The output of execution is an array called
-as lookup table which contain 256 64bits-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.
-
-Signed-off-by: Coly Li <colyli@suse.de>
----
- lib/Makefile | 11 +++++++++++
- 1 file changed, 11 insertions(+)
-
-diff --git a/lib/Makefile b/lib/Makefile
-index ce20696d5a92..21873fc4085b 100644
---- a/lib/Makefile
-+++ b/lib/Makefile
-@@ -107,6 +107,7 @@ obj-$(CONFIG_CRC16) += crc16.o
- obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
- obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o
- obj-$(CONFIG_CRC32) += crc32.o
-+obj-$(CONFIG_CRC64) += crc64.o
- obj-$(CONFIG_CRC32_SELFTEST) += crc32test.o
- obj-$(CONFIG_CRC4) += crc4.o
- obj-$(CONFIG_CRC7) += crc7.o
-@@ -223,7 +224,9 @@ obj-$(CONFIG_FONT_SUPPORT) += fonts/
- obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o
-
- hostprogs-y := gen_crc32table
-+hostprogs-y += gen_crc64table
- clean-files := crc32table.h
-+clean-files += crc64table.h
-
- $(obj)/crc32.o: $(obj)/crc32table.h
-
-@@ -233,6 +236,14 @@ quiet_cmd_crc32 = GEN $@
- $(obj)/crc32table.h: $(obj)/gen_crc32table
- $(call cmd,crc32)
-
-+$(obj)/crc64.o: $(obj)/crc64table.h
-+
-+quiet_cmd_crc64 = GEN $@
-+ cmd_crc64 = $< > $@
-+
-+$(obj)/crc64table.h: $(obj)/gen_crc64table
-+ $(call cmd,crc64)
-+
- #
- # Build a fast OID lookip registry from include/linux/oid_registry.h
- #
---
-2.16.3
-
diff --git a/for-test/libcrc64/0004-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch b/for-test/libcrc64/0003-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch
index c493e91..9fa2f78 100644
--- a/for-test/libcrc64/0004-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch
+++ b/for-test/libcrc64/0003-bcache-use-routines-from-lib-crc64.c-for-CRC64-calcu.patch
@@ -1,27 +1,28 @@
-From 3422438ae433843295dbe85c363f1921a594e51b Mon Sep 17 00:00:00 2001
+From 2a5f4442c9595627c076095c9e48f131624e340c Mon Sep 17 00:00:00 2001
From: Coly Li <colyli@suse.de>
Date: Wed, 23 May 2018 16:02:35 +0800
-Subject: [PATCH 4/4] bcache: use routines from lib/crc64.c for CRC64
+Subject: [PATCH 3/4] bcache: use routines from lib/crc64.c for CRC64
calculation
-This patch removes the PostgreSQL licennsed CRC64 code from bcache, and
-uses routinesfrom lib/crc64.c to do bcache CRC64 calculationn.
+Now we have crc64 calculation in lib/crc64.c, it is unnecessary for
+bcache to use it own version. This patch changes bcache code to use
+crc64 routines in lib/crc64.c.
Signed-off-by: Coly Li <colyli@suse.de>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Michael Lyle <mlyle@lyle.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
---
- drivers/md/bcache/bcache.h | 7 ++-
+ 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.c | 131 ------------------------------------
drivers/md/bcache/util.h | 5 +-
6 files changed, 10 insertions(+), 142 deletions(-)
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
-index 3a0cfb237af9..edcbd1a0a8db 100644
+index d6bf294f3907..3f7934f56648 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -189,6 +189,7 @@
@@ -32,21 +33,21 @@ index 3a0cfb237af9..edcbd1a0a8db 100644
#include "bset.h"
#include "util.h"
-@@ -801,9 +802,9 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
+@@ -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_le_we(((void *) (i)) + sizeof(uint64_t), \
++ crc64_le_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 17936b2dc7d6..7867e65ed686 100644
+index 547c9eedc2f4..378dd6688d26 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)
@@ -59,7 +60,7 @@ index 17936b2dc7d6..7867e65ed686 100644
}
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
-index 8e3e8655ed63..7a191b4bdeb6 100644
+index ae67f5fa8047..4efe6550df94 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)
@@ -72,19 +73,19 @@ index 8e3e8655ed63..7a191b4bdeb6 100644
}
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
-index 3dea06b41d43..ead7c7e12862 100644
+index fa4058e43202..f45d92c5eca7 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
-@@ -567,7 +567,7 @@ void bch_prio_write(struct cache *ca)
+@@ -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_le_we(&p->magic, bucket_bytes(ca) - 8);
++ p->csum = crc64_le_bch(&p->magic, bucket_bytes(ca) - 8);
bucket = bch_bucket_alloc(ca, RESERVE_PRIO, true);
BUG_ON(bucket == -1);
-@@ -617,7 +617,8 @@ static void prio_read(struct cache *ca, uint64_t bucket)
+@@ -599,7 +599,8 @@ static void prio_read(struct cache *ca, uint64_t bucket)
prio_io(ca, bucket, REQ_OP_READ, 0);
@@ -95,10 +96,10 @@ index 3dea06b41d43..ead7c7e12862 100644
if (p->magic != pset_magic(&ca->sb))
diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
-index 74febd5230df..cdf822c0ac1b 100644
+index fc479b026d6d..f912c372978c 100644
--- a/drivers/md/bcache/util.c
+++ b/drivers/md/bcache/util.c
-@@ -314,134 +314,3 @@ int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask)
+@@ -279,134 +279,3 @@ int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask)
return 0;
}
@@ -234,7 +235,7 @@ index 74febd5230df..cdf822c0ac1b 100644
- return crc ^ 0xffffffffffffffffULL;
-}
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
-index 268024529edd..a68298bd777c 100644
+index cced87f8eb27..b1deec0dc958 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -11,6 +11,7 @@
@@ -245,7 +246,7 @@ index 268024529edd..a68298bd777c 100644
#include "closure.h"
-@@ -566,8 +567,4 @@ static inline sector_t bdev_sectors(struct block_device *bdev)
+@@ -561,8 +562,4 @@ static inline sector_t bdev_sectors(struct block_device *bdev)
{
return bdev->bd_inode->i_size >> 9;
}
@@ -255,5 +256,5 @@ index 268024529edd..a68298bd777c 100644
-
#endif /* _BCACHE_UTIL_H */
--
-2.16.3
+2.17.1
diff --git a/for-test/libcrc64/0004-lib-test_crc-Add-test-cases-for-crc-calculation.patch b/for-test/libcrc64/0004-lib-test_crc-Add-test-cases-for-crc-calculation.patch
new file mode 100644
index 0000000..4bce45c
--- /dev/null
+++ b/for-test/libcrc64/0004-lib-test_crc-Add-test-cases-for-crc-calculation.patch
@@ -0,0 +1,213 @@
+From 1e0422a3f41133120f171bc12d8aafef97660a0d Mon Sep 17 00:00:00 2001
+From: Coly Li <colyli@suse.de>
+Date: Wed, 6 Jun 2018 21:20:46 +0800
+Subject: [PATCH 4/4] 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_le: PASSED (0x4e6b1ff972fa8c55, expval 0x4e6b1ff972fa8c55)
+test_crc: crc64_le_bch: PASSED (0x0e4f1391d7a4a62e, expval 0x0e4f1391d7a4a62e)
+test_crc: crc64_le_update: FAILED (0x03d4d0d85685d9a1, expval 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 can is a testing frame work for all crc consistency
+testings. For now, there are only test caes for 3 crc routines,
+- crc64_le()
+- crc64_le_bch()
+- crc64_le_update()
+
+Signed-off-by: Coly Li <colyli@suse.de>
+Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Cc: Luis R. Rodriguez <mcgrof@suse.com>
+---
+ lib/Kconfig.debug | 11 ++++
+ lib/Makefile | 1 +
+ lib/test_crc.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 148 insertions(+)
+ create mode 100644 lib/test_crc.c
+
+diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
+index 8838d1158d19..c7deb4e2e4eb 100644
+--- a/lib/Kconfig.debug
++++ b/lib/Kconfig.debug
+@@ -1911,6 +1911,17 @@ config TEST_SYSCTL
+
+ If unsure, say N.
+
++config TEST_CRC
++ tristate "CRC calculation test driver"
++ default n
++ depends on CRC64
++ help
++ This builds the "test_crc" module. This driver enables to test the
++ CRC calculation consistency to make sure new modification does not
++ break existing checksum calculation.
++
++ if unsure, say N.
++
+ config TEST_UDELAY
+ tristate "udelay test driver"
+ default n
+diff --git a/lib/Makefile b/lib/Makefile
+index 40c215181687..224d047d026a 100644
+--- a/lib/Makefile
++++ b/lib/Makefile
+@@ -49,6 +49,7 @@ obj-$(CONFIG_FIND_BIT_BENCHMARK) += find_bit_benchmark.o
+ obj-$(CONFIG_TEST_BPF) += test_bpf.o
+ obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
+ obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
++obj-$(CONFIG_TEST_CRC) += test_crc.o
+ obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
+ obj-$(CONFIG_TEST_KASAN) += test_kasan.o
+ CFLAGS_test_kasan.o += -fno-builtin
+diff --git a/lib/test_crc.c b/lib/test_crc.c
+new file mode 100644
+index 000000000000..e90b5402640c
+--- /dev/null
++++ b/lib/test_crc.c
+@@ -0,0 +1,136 @@
++// SPDX-License-Identifier: GPL-2.0
++/*
++ * CRC test driver
++ *
++ * Copyright (C) 2018 Coly Li <colyli@suse.de>
++ *
++ * This module provides an simple framework to check the consistency of
++ * Linux kernel crc calculation routines in lib/crc*.c. This driver
++ * requires CONFIG_CRC* items to be enabled if the associated routines are
++ * tested here. The test results will be printed to kernel message
++ * when this test driver is loaded.
++ *
++ * Current test routines are,
++ * - crc64_le()
++ * - crc64_le_bch()
++ * - crc64_le_update()
++ *
++ */
++
++#include <linux/init.h>
++#include <linux/list.h>
++#include <linux/module.h>
++#include <linux/printk.h>
++#include <linux/fs.h>
++#include <linux/miscdevice.h>
++#include <linux/slab.h>
++#include <linux/uaccess.h>
++#include <linux/async.h>
++#include <linux/delay.h>
++#include <linux/vmalloc.h>
++#include <linux/crc64.h>
++
++struct crc_test_record {
++
++ char *name;
++ __le64 data[4];
++ __le64 initval;
++ __le64 expval;
++ int (*handler)(struct crc_test_record *rec);
++};
++
++static int chk_and_msg(const char *name, __le64 crc, __le64 expval)
++{
++ int ret = 0;
++
++ if (crc == expval) {
++ pr_info("test_crc: %s: PASSED:(0x%016llx, expval 0x%016llx)",
++ name, crc, expval);
++ } else {
++ pr_err("test_crc: %s: FAILED:(0x%016llx, expval 0x%016llx)",
++ name, crc, expval);
++ ret = -EINVAL;
++ }
++
++ return ret;
++}
++
++/* Add your crc test caese here */
++static int test_crc64_le(struct crc_test_record *rec)
++{
++ __le64 crc;
++
++ crc = crc64_le(rec->data, sizeof(rec->data));
++ return chk_and_msg(rec->name, crc, rec->expval);
++
++}
++
++static int test_crc64_le_bch(struct crc_test_record *rec)
++{
++ __le64 crc;
++
++ crc = crc64_le_bch(rec->data, sizeof(rec->data));
++ return chk_and_msg(rec->name, crc, rec->expval);
++}
++
++static int test_crc64_le_update(struct crc_test_record *rec)
++{
++ __le64 crc = rec->initval;
++
++ crc = crc64_le_update(crc, rec->data, sizeof(rec->data));
++ return chk_and_msg(rec->name, crc, rec->expval);
++}
++
++/*
++ * Set up your crc test initial data here.
++ * Do not change the existing items, they are hard coded with
++ * pre-calculated values.
++ */
++static struct crc_test_record test_data[] = {
++ { .name = "crc64_le",
++ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
++ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
++ .initval = 0,
++ .expval = 0x4e6b1ff972fa8c55,
++ .handler = test_crc64_le,
++ },
++ { .name = "crc64_le_bch",
++ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
++ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
++ .initval = 0,
++ .expval = 0x0e4f1391d7a4a62e,
++ .handler = test_crc64_le_bch,
++ },
++ { .name = "crc64_le_update",
++ .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26,
++ 0xC711223CFA3E5BB5, 0x493366450E42ECDF },
++ .initval = 0x61C8864680B583EB,
++ .expval = 0x03d4d0d85685d9a1,
++ .handler = test_crc64_le_update,
++ },
++ { .name = NULL, }
++};
++
++
++static int __init test_crc_init(void)
++{
++ int i;
++ int v, ret = 0;
++
++ pr_info("Kernel crc consitency testing:");
++ for (i = 0; test_data[i].name; i++) {
++ v = test_data[i].handler(&test_data[i]);
++ if (v < 0 && ret != 0)
++ ret = -EINVAL;
++ }
++
++ return ret;
++}
++late_initcall(test_crc_init);
++
++static void __exit test_crc_exit(void) { }
++module_exit(test_crc_exit);
++
++MODULE_DESCRIPTION("CRC consistency testing driver");
++MODULE_AUTHOR("Coly Li <colyli@suse.de>");
++MODULE_LICENSE("GPL");
+--
+2.17.1
+