From f89d2072795407d7c3afff865b988e021c1451a2 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Mon, 17 Jun 2019 19:49:08 +0000 Subject: [PATCH] Separate kernel crc32() implementation to its own header (gsb_crc32.h) and rename the source to gsb_crc32.c. This is a prerequisite of unifying kernel zlib instances. PR: 229763 Submitted by: Yoshihiro Ota Differential Revision: https://reviews.freebsd.org/D20193 --- lib/libufs/Makefile | 3 +- stand/libsa/crc32_libkern.c | 2 +- sys/conf/files | 2 +- sys/dev/iscsi/icl_soft.c | 1 + sys/dev/iscsi_initiator/isc_subr.c | 1 + sys/dev/liquidio/lio_bsd.h | 1 + sys/dev/usb/net/if_cdce.c | 2 +- sys/fs/ext2fs/ext2_csum.c | 1 + sys/fs/nandfs/nandfs_segment.c | 1 + sys/fs/nandfs/nandfs_subr.c | 1 + sys/fs/nandfs/nandfs_vfsops.c | 1 + sys/geom/part/g_part_bsd64.c | 1 + sys/geom/part/g_part_gpt.c | 1 + sys/geom/raid/md_ddf.c | 1 + sys/kern/subr_compressor.c | 1 + sys/libkern/{crc32.c => gsb_crc32.c} | 1 + sys/libkern/x86/crc32_sse42.c | 9 ++---- sys/netinet/libalias/alias_sctp.c | 1 + sys/netinet/sctp_crc32.c | 1 + sys/netpfil/pf/pf.c | 1 + sys/sys/gsb_crc32.h | 47 ++++++++++++++++++++++++++++ sys/sys/libkern.h | 33 ------------------- sys/sys/param.h | 2 +- sys/ufs/ffs/ffs_alloc.c | 1 + sys/ufs/ffs/ffs_snapshot.c | 1 + sys/ufs/ffs/ffs_subr.c | 1 + sys/ufs/ffs/ffs_vfsops.c | 1 + tests/sys/kern/Makefile | 1 - tests/sys/kern/libkern_crc32.c | 7 ++--- 29 files changed, 77 insertions(+), 50 deletions(-) rename sys/libkern/{crc32.c => gsb_crc32.c} (99%) create mode 100644 sys/sys/gsb_crc32.h diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile index 2685f7318ac1..a3f4cb3991ed 100644 --- a/lib/libufs/Makefile +++ b/lib/libufs/Makefile @@ -5,7 +5,8 @@ LIB= ufs SHLIBDIR?= /lib SHLIB_MAJOR= 7 -SRCS= block.c cgroup.c crc32.c inode.c sblock.c type.c ffs_subr.c ffs_tables.c +SRCS= block.c cgroup.c gsb_crc32.c inode.c sblock.c type.c ffs_subr.c +SRCS+= ffs_tables.c INCS= libufs.h MAN= bread.3 cgread.3 getinode.3 libufs.3 sbread.3 ufs_disk_close.3 diff --git a/stand/libsa/crc32_libkern.c b/stand/libsa/crc32_libkern.c index 995815294d58..d2bd738d4c20 100644 --- a/stand/libsa/crc32_libkern.c +++ b/stand/libsa/crc32_libkern.c @@ -1,3 +1,3 @@ /* $FreeBSD$ */ -#include "../../sys/libkern/crc32.c" +#include "../../sys/libkern/gsb_crc32.c" diff --git a/sys/conf/files b/sys/conf/files index 3c5146977747..b449a90febc4 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3982,9 +3982,9 @@ crypto/chacha20/chacha.c standard libkern/asprintf.c standard libkern/bcd.c standard libkern/bsearch.c standard -libkern/crc32.c standard libkern/explicit_bzero.c standard libkern/fnmatch.c standard +libkern/gsb_crc32.c standard libkern/iconv.c optional libiconv libkern/iconv_converter_if.m optional libiconv libkern/iconv_ucs.c optional libiconv diff --git a/sys/dev/iscsi/icl_soft.c b/sys/dev/iscsi/icl_soft.c index 66df484f4308..0b4f4f64c720 100644 --- a/sys/dev/iscsi/icl_soft.c +++ b/sys/dev/iscsi/icl_soft.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/dev/iscsi_initiator/isc_subr.c b/sys/dev/iscsi_initiator/isc_subr.c index f3dfcb715e2f..9c27c7313d85 100644 --- a/sys/dev/iscsi_initiator/isc_subr.c +++ b/sys/dev/iscsi_initiator/isc_subr.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/dev/liquidio/lio_bsd.h b/sys/dev/liquidio/lio_bsd.h index ac170c9c654f..fd6402ea2297 100644 --- a/sys/dev/liquidio/lio_bsd.h +++ b/sys/dev/liquidio/lio_bsd.h @@ -36,6 +36,7 @@ #define __LIO_BSD_H__ #include +#include #include #include #include diff --git a/sys/dev/usb/net/if_cdce.c b/sys/dev/usb/net/if_cdce.c index c5d0233c0258..d63539da7e89 100644 --- a/sys/dev/usb/net/if_cdce.c +++ b/sys/dev/usb/net/if_cdce.c @@ -50,7 +50,7 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include #include #include diff --git a/sys/fs/ext2fs/ext2_csum.c b/sys/fs/ext2fs/ext2_csum.c index de8f8019f4bc..0ca258f12f72 100644 --- a/sys/fs/ext2fs/ext2_csum.c +++ b/sys/fs/ext2fs/ext2_csum.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/sys/fs/nandfs/nandfs_segment.c b/sys/fs/nandfs/nandfs_segment.c index c6c5885891ef..36efc89af409 100644 --- a/sys/fs/nandfs/nandfs_segment.c +++ b/sys/fs/nandfs/nandfs_segment.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/fs/nandfs/nandfs_subr.c b/sys/fs/nandfs/nandfs_subr.c index 1f0521b69152..0a3f65a50543 100644 --- a/sys/fs/nandfs/nandfs_subr.c +++ b/sys/fs/nandfs/nandfs_subr.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include diff --git a/sys/fs/nandfs/nandfs_vfsops.c b/sys/fs/nandfs/nandfs_vfsops.c index c8d6daa9a3cd..f703044728ef 100644 --- a/sys/fs/nandfs/nandfs_vfsops.c +++ b/sys/fs/nandfs/nandfs_vfsops.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/geom/part/g_part_bsd64.c b/sys/geom/part/g_part_bsd64.c index ff5d7ef6d054..6332a38096fd 100644 --- a/sys/geom/part/g_part_bsd64.c +++ b/sys/geom/part/g_part_bsd64.c @@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c index e1bea703a154..dca10c9534cb 100644 --- a/sys/geom/part/g_part_gpt.c +++ b/sys/geom/part/g_part_gpt.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/geom/raid/md_ddf.c b/sys/geom/raid/md_ddf.c index 3ac13bded073..a731da89d8ea 100644 --- a/sys/geom/raid/md_ddf.c +++ b/sys/geom/raid/md_ddf.c @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include diff --git a/sys/kern/subr_compressor.c b/sys/kern/subr_compressor.c index 62c818439271..03dd295388ad 100644 --- a/sys/kern/subr_compressor.c +++ b/sys/kern/subr_compressor.c @@ -66,6 +66,7 @@ SET_DECLARE(compressors, struct compressor_methods); #ifdef GZIO +#include #include struct gz_stream { diff --git a/sys/libkern/crc32.c b/sys/libkern/gsb_crc32.c similarity index 99% rename from sys/libkern/crc32.c rename to sys/libkern/gsb_crc32.c index 149de3de6dee..46d6517f7940 100644 --- a/sys/libkern/crc32.c +++ b/sys/libkern/gsb_crc32.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #ifdef _KERNEL #include #include +#include #if defined(__amd64__) || defined(__i386__) #include diff --git a/sys/libkern/x86/crc32_sse42.c b/sys/libkern/x86/crc32_sse42.c index 50e457410ad9..712b21cda46e 100644 --- a/sys/libkern/x86/crc32_sse42.c +++ b/sys/libkern/x86/crc32_sse42.c @@ -29,14 +29,14 @@ __FBSDID("$FreeBSD$"); /* * This file is compiled in userspace in order to run ATF unit tests. */ -#ifdef USERSPACE_TESTING +#ifndef _KERNEL #include #include #else #include -#include #include #endif +#include static __inline uint32_t _mm_crc32_u8(uint32_t x, uint8_t y) @@ -199,7 +199,7 @@ crc32c_shift(uint32_t zeros[][256], uint32_t crc) /* Initialize tables for shifting crcs. */ static void -#ifdef USERSPACE_TESTING +#ifndef _KERNEL __attribute__((__constructor__)) #endif crc32c_init_hw(void) @@ -214,9 +214,6 @@ SYSINIT(crc32c_sse42, SI_SUB_LOCK, SI_ORDER_ANY, crc32c_init_hw, NULL); #endif /* Compute CRC-32C using the Intel hardware instruction. */ -#ifdef USERSPACE_TESTING -uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); -#endif uint32_t sse42_crc32c(uint32_t crc, const unsigned char *buf, unsigned len) { diff --git a/sys/netinet/libalias/alias_sctp.c b/sys/netinet/libalias/alias_sctp.c index dd9b97b57475..da2dd8c5b8ac 100644 --- a/sys/netinet/libalias/alias_sctp.c +++ b/sys/netinet/libalias/alias_sctp.c @@ -75,6 +75,7 @@ #ifdef _KERNEL #include #include +#include #include #include #include diff --git a/sys/netinet/sctp_crc32.c b/sys/netinet/sctp_crc32.c index da5df194b8b3..1c3421a15585 100644 --- a/sys/netinet/sctp_crc32.c +++ b/sys/netinet/sctp_crc32.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include "opt_sctp.h" +#include #ifdef SCTP #include #include diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 97c826f77911..a3a1e512d8cd 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/sys/gsb_crc32.h b/sys/sys/gsb_crc32.h new file mode 100644 index 000000000000..c5a42d3d3152 --- /dev/null +++ b/sys/sys/gsb_crc32.h @@ -0,0 +1,47 @@ +/*- + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + * code or tables extracted from it, as desired without restriction. + * + * $FreeBSD$ + */ + +#ifndef _SYS_GSB_CRC32_H_ +#define _SYS_GSB_CRC32_H_ + +#include + +#ifdef _KERNEL + +extern const uint32_t crc32_tab[]; + +static __inline uint32_t +crc32_raw(const void *buf, size_t size, uint32_t crc) +{ + const uint8_t *p = (const uint8_t *)buf; + + while (size--) + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + return (crc); +} + +static __inline uint32_t +crc32(const void *buf, size_t size) +{ + uint32_t crc; + + crc = crc32_raw(buf, size, ~0U); + return (crc ^ ~0U); +} + +uint32_t calculate_crc32c(uint32_t crc32c, const unsigned char *buffer, + unsigned int length); +#endif + +#if defined(__amd64__) || defined(__i386__) +uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); +#endif +#if defined(__aarch64__) +uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); +#endif + +#endif /* !_SYS_GSB_CRC32_H_ */ diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h index 123f6eeda3f3..1e343f31bcaa 100644 --- a/sys/sys/libkern.h +++ b/sys/sys/libkern.h @@ -190,39 +190,6 @@ size_t strspn(const char *, const char *); char *strstr(const char *, const char *); int strvalid(const char *, size_t); -extern const uint32_t crc32_tab[]; - -static __inline uint32_t -crc32_raw(const void *buf, size_t size, uint32_t crc) -{ - const uint8_t *p = (const uint8_t *)buf; - - while (size--) - crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); - return (crc); -} - -static __inline uint32_t -crc32(const void *buf, size_t size) -{ - uint32_t crc; - - crc = crc32_raw(buf, size, ~0U); - return (crc ^ ~0U); -} - -uint32_t -calculate_crc32c(uint32_t crc32c, const unsigned char *buffer, - unsigned int length); -#ifdef _KERNEL -#if defined(__amd64__) || defined(__i386__) -uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); -#endif -#if defined(__aarch64__) -uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); -#endif -#endif - static __inline char * index(const char *p, int ch) { diff --git a/sys/sys/param.h b/sys/sys/param.h index bf1c73c26406..2534537558c5 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1300031 /* Master, propagated to newvers */ +#define __FreeBSD_version 1300032 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index e0062cc73c6e..9ebdec0c88c4 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index 36449e9cb2cf..bc279e27269f 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c index b284cbf41f6b..fccccb7ce4b3 100644 --- a/sys/ufs/ffs/ffs_subr.c +++ b/sys/ufs/ffs/ffs_subr.c @@ -59,6 +59,7 @@ struct malloc_type; #else /* _KERNEL */ #include +#include #include #include #include diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index a3bec1a39dc7..3174dc4de129 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include "opt_ddb.h" #include +#include #include #include #include diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index cf2d04706a1c..180734f4d242 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -46,7 +46,6 @@ LIBADD.mqueue_test+= rt ${MACHINE_ARCH} == "i386" || \ ${MACHINE_ARCH} == "aarch64" ATF_TESTS_C+= libkern_crc32 -CFLAGS.libkern_crc32+= -DUSERSPACE_TESTING .if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" LDADD.libkern_crc32+= ${SRCTOP}/sys/libkern/x86/crc32_sse42.c .else diff --git a/tests/sys/kern/libkern_crc32.c b/tests/sys/kern/libkern_crc32.c index 03d023124346..39cb8ca5aeeb 100644 --- a/tests/sys/kern/libkern_crc32.c +++ b/tests/sys/kern/libkern_crc32.c @@ -27,16 +27,13 @@ */ #include +#include #include #include -#if defined(__amd64__) || defined(__i386__) -extern uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); -#elif defined(__aarch64__) -extern uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned); -#else +#if !defined(__amd64__) && !defined(__i386__) && !defined(__aarch64__) #error These tests are not supported on this platform #endif