buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] package/ocf-linux: fix build with kernels up to version 4.14
@ 2022-10-08 13:44 James Hilliard
  2022-11-01 22:31 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2022-10-08 13:44 UTC (permalink / raw)
  To: buildroot; +Cc: James Hilliard

Add patches fixing build on kernels up to version 4.14.

Depend on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_15 as builds fail on 4.15
and newer currently.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 package/cryptodev/Config.in                   |   1 +
 ...gnal.h-include-on-linux-below-4.11.0.patch |  36 +++
 ...functions-on-kernels-4.6.0-and-newer.patch | 222 ++++++++++++++++++
 ...ssing-crypto_alloc_ablkcipher-symbol.patch |  35 +++
 4 files changed, 294 insertions(+)
 create mode 100644 package/ocf-linux/0001-Fix-signal.h-include-on-linux-below-4.11.0.patch
 create mode 100644 package/ocf-linux/0002-Fix-crypto_hash-functions-on-kernels-4.6.0-and-newer.patch
 create mode 100644 package/ocf-linux/0003-Fix-missing-crypto_alloc_ablkcipher-symbol.patch

diff --git a/package/cryptodev/Config.in b/package/cryptodev/Config.in
index d1e64498a8..e243cab6f0 100644
--- a/package/cryptodev/Config.in
+++ b/package/cryptodev/Config.in
@@ -28,6 +28,7 @@ config BR2_PACKAGE_CRYPTODEV_LINUX
 
 config BR2_PACKAGE_OCF_LINUX
 	bool "ocf-linux"
+	depends on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_15
 	select BR2_PACKAGE_HAS_CRYPTODEV
 	help
 	  OCF-Linux is a Linux port of the OpenBSD/FreeBSD Cryptographic
diff --git a/package/ocf-linux/0001-Fix-signal.h-include-on-linux-below-4.11.0.patch b/package/ocf-linux/0001-Fix-signal.h-include-on-linux-below-4.11.0.patch
new file mode 100644
index 0000000000..2517c19547
--- /dev/null
+++ b/package/ocf-linux/0001-Fix-signal.h-include-on-linux-below-4.11.0.patch
@@ -0,0 +1,36 @@
+From 9e361206c6f0c8e0f62449cdec3b277f96277cd6 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Fri, 7 Oct 2022 22:25:37 -0400
+Subject: [PATCH] Fix signal.h include on linux below 4.11.0
+
+The linux/signal.h header was moved to linux/sched/signal.h as
+of linux version 4.11.0.
+
+As such linux/sched/signal.h is not available on linux below 4.11.0.
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://sourceforge.net/p/ocf-linux/mailman/message/37718258/]
+---
+ ocf/crypto.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/ocf/crypto.c b/ocf/crypto.c
+index 4e50328..5691b2a 100644
+--- a/ocf/crypto.c
++++ b/ocf/crypto.c
+@@ -73,7 +73,11 @@ __FBSDID("$FreeBSD: src/sys/opencrypto/crypto.c,v 1.16 2005/01/07 02:29:16 imp E
+ #include <linux/slab.h>
+ #include <linux/wait.h>
+ #include <linux/sched.h>
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
++#include <linux/signal.h>
++#else
+ #include <linux/sched/signal.h>
++#endif
+ #include <linux/spinlock.h>
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
+ #include <linux/kthread.h>
+-- 
+2.37.3
+
diff --git a/package/ocf-linux/0002-Fix-crypto_hash-functions-on-kernels-4.6.0-and-newer.patch b/package/ocf-linux/0002-Fix-crypto_hash-functions-on-kernels-4.6.0-and-newer.patch
new file mode 100644
index 0000000000..c82a878b21
--- /dev/null
+++ b/package/ocf-linux/0002-Fix-crypto_hash-functions-on-kernels-4.6.0-and-newer.patch
@@ -0,0 +1,222 @@
+From 7dd718b7b6132c2e8e1e685b03c7b10c0658609e Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Sat, 8 Oct 2022 04:25:00 -0400
+Subject: [PATCH] Fix crypto_hash functions on kernels 4.6.0 and newer
+
+The legacy crypto_hash interface was removed as of kernel version
+4.6.0, adapt this interface to be compatible with the replacement
+crypto_shash interface.
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://sourceforge.net/p/ocf-linux/mailman/message/37718260/]
+---
+ ocf/cryptosoft.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 185 insertions(+)
+
+diff --git a/ocf/cryptosoft.c b/ocf/cryptosoft.c
+index caf9c06..d903b6e 100644
+--- a/ocf/cryptosoft.c
++++ b/ocf/cryptosoft.c
+@@ -56,6 +56,9 @@
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
+ #include <crypto/hash.h>
+ #endif
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
++#include <linux/highmem.h>
++#endif
+ 
+ #include <cryptodev.h>
+ #include <uio.h>
+@@ -184,6 +187,188 @@ static struct kmem_cache *swcr_req_cache;
+ 	#define crypto_alloc_comp(X, Y, Z)		crypto_alloc_tfm(X, mode)
+ 	#define plain(X)	#X , 0
+ #else
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
++	#define hash_desc		shash_desc
++	#define crypto_free_hash	crypto_free_shash
++	#define crypto_hash_tfm		crypto_shash_tfm
++	#define crypto_alloc_hash	crypto_alloc_shash
++	#define crypto_hash_digestsize	crypto_shash_digestsize
++	#define crypto_hash_setkey	crypto_shash_setkey
++	#define crypto_has_hash		crypto_has_ahash
++	#define crypto_hash_cast(X)	container_of(X, struct crypto_shash, base)
++
++struct crypto_hash_walk {
++	char *data;
++
++	unsigned int offset;
++	unsigned int alignmask;
++
++	struct page *pg;
++	unsigned int entrylen;
++
++	unsigned int total;
++	struct scatterlist *sg;
++
++	unsigned int flags;
++};
++
++static int hash_walk_next(struct crypto_hash_walk *walk)
++{
++	unsigned int alignmask = walk->alignmask;
++	unsigned int offset = walk->offset;
++	unsigned int nbytes = min(walk->entrylen,
++				  ((unsigned int)(PAGE_SIZE)) - offset);
++
++	if (walk->flags & CRYPTO_ALG_ASYNC)
++		walk->data = kmap(walk->pg);
++	else
++		walk->data = kmap_atomic(walk->pg);
++	walk->data += offset;
++
++	if (offset & alignmask) {
++		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
++
++		if (nbytes > unaligned)
++			nbytes = unaligned;
++	}
++
++	walk->entrylen -= nbytes;
++	return nbytes;
++}
++
++static int hash_walk_new_entry(struct crypto_hash_walk *walk)
++{
++	struct scatterlist *sg;
++
++	sg = walk->sg;
++	walk->offset = sg->offset;
++	walk->pg = sg_page(walk->sg) + (walk->offset >> PAGE_SHIFT);
++	walk->offset = offset_in_page(walk->offset);
++	walk->entrylen = sg->length;
++
++	if (walk->entrylen > walk->total)
++		walk->entrylen = walk->total;
++	walk->total -= walk->entrylen;
++
++	return hash_walk_next(walk);
++}
++
++static int crypto_hash_walk_first_compat(struct shash_desc *sdesc,
++				  struct crypto_hash_walk *walk,
++				  struct scatterlist *sg, unsigned int len)
++{
++	walk->total = len;
++
++	if (!walk->total) {
++		walk->entrylen = 0;
++		return 0;
++	}
++
++	walk->alignmask = crypto_shash_alignmask(sdesc->tfm);
++	walk->sg = sg;
++	walk->flags = sdesc->flags & CRYPTO_TFM_REQ_MASK;
++
++	return hash_walk_new_entry(walk);
++}
++
++static inline void crypto_yield(u32 flags)
++{
++	if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
++		cond_resched();
++}
++
++static int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
++{
++	unsigned int alignmask = walk->alignmask;
++	unsigned int nbytes = walk->entrylen;
++
++	walk->data -= walk->offset;
++
++	if (nbytes && walk->offset & alignmask && !err) {
++		walk->offset = ALIGN(walk->offset, alignmask + 1);
++		walk->data += walk->offset;
++
++		nbytes = min(nbytes,
++			     ((unsigned int)(PAGE_SIZE)) - walk->offset);
++		walk->entrylen -= nbytes;
++
++		return nbytes;
++	}
++
++	if (walk->flags & CRYPTO_ALG_ASYNC)
++		kunmap(walk->pg);
++	else {
++		kunmap_atomic(walk->data);
++		/*
++		 * The may sleep test only makes sense for sync users.
++		 * Async users don't need to sleep here anyway.
++		 */
++		crypto_yield(walk->flags);
++	}
++
++	if (err)
++		return err;
++
++	if (nbytes) {
++		walk->offset = 0;
++		walk->pg++;
++		return hash_walk_next(walk);
++	}
++
++	if (!walk->total)
++		return 0;
++
++	walk->sg = sg_next(walk->sg);
++
++	return hash_walk_new_entry(walk);
++}
++
++static int shash_compat_update(struct shash_desc *desc, struct scatterlist *sg,
++			       unsigned int len)
++{
++	struct crypto_hash_walk walk;
++	int nbytes;
++
++	for (nbytes = crypto_hash_walk_first_compat(desc, &walk, sg, len);
++	     nbytes > 0; nbytes = crypto_hash_walk_done(&walk, nbytes))
++		nbytes = crypto_shash_update(desc, walk.data, nbytes);
++
++	return nbytes;
++}
++
++static int crypto_hash_digest(struct shash_desc *desc, struct scatterlist *sg,
++			       unsigned int nbytes, u8 *out)
++{
++	unsigned int offset = sg->offset;
++	int err;
++
++	if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) {
++		void *data;
++
++		desc->flags = desc->flags;
++
++		data = kmap_atomic(sg_page(sg));
++		err = crypto_shash_digest(desc, data + offset, nbytes, out);
++		kunmap_atomic(data);
++		crypto_yield(desc->flags);
++		goto out;
++	}
++
++	err = crypto_shash_init(desc);
++	if (err)
++		goto out;
++
++	err = shash_compat_update(desc, sg, nbytes);
++	if (err)
++		goto out;
++
++	err = crypto_shash_final(desc, out);
++
++out:
++	return err;
++}
++
++#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) */
+ 	#define ecb(X)	"ecb(" #X ")" , 0
+ 	#define cbc(X)	"cbc(" #X ")" , 0
+ 	#define hmac(X)	"hmac(" #X ")" , 0
+-- 
+2.37.3
+
diff --git a/package/ocf-linux/0003-Fix-missing-crypto_alloc_ablkcipher-symbol.patch b/package/ocf-linux/0003-Fix-missing-crypto_alloc_ablkcipher-symbol.patch
new file mode 100644
index 0000000000..7e420f6747
--- /dev/null
+++ b/package/ocf-linux/0003-Fix-missing-crypto_alloc_ablkcipher-symbol.patch
@@ -0,0 +1,35 @@
+From 3a847686f8a18a50149f2f3d4ed8a661ed507154 Mon Sep 17 00:00:00 2001
+From: James Hilliard <james.hilliard1@gmail.com>
+Date: Fri, 7 Oct 2022 22:44:58 -0400
+Subject: [PATCH] Fix missing crypto_alloc_ablkcipher symbol
+
+The crypto_alloc_ablkcipher symbol was removed as of linux
+version 4.8.0.
+
+Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
+[Upstream status:
+https://sourceforge.net/p/ocf-linux/mailman/message/37718259/]
+---
+ ocf/cryptosoft.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/ocf/cryptosoft.c b/ocf/cryptosoft.c
+index caf9c06..841d41e 100644
+--- a/ocf/cryptosoft.c
++++ b/ocf/cryptosoft.c
+@@ -190,9 +190,11 @@ static struct kmem_cache *swcr_req_cache;
+ 	#define plain(X)	#X , 0
+ #endif /* if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) */
+ 
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) || LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)
++#define crypto_alloc_ablkcipher(a,b,c)		(NULL)
++#endif
+ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
+ /* no ablkcipher in older kernels */
+-#define crypto_alloc_ablkcipher(a,b,c)		(NULL)
+ #define crypto_ablkcipher_tfm(x)			((struct crypto_tfm *)(x))
+ #define crypto_ablkcipher_set_flags(a, b)	/* nop */
+ #define crypto_ablkcipher_setkey(x, y, z)	(-EINVAL)
+-- 
+2.37.3
+
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Buildroot] [PATCH 1/1] package/ocf-linux: fix build with kernels up to version 4.14
  2022-10-08 13:44 [Buildroot] [PATCH 1/1] package/ocf-linux: fix build with kernels up to version 4.14 James Hilliard
@ 2022-11-01 22:31 ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2022-11-01 22:31 UTC (permalink / raw)
  To: James Hilliard; +Cc: buildroot

Hello James,

On Sat,  8 Oct 2022 07:44:14 -0600
James Hilliard <james.hilliard1@gmail.com> wrote:

> Add patches fixing build on kernels up to version 4.14.
> 
> Depend on !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_15 as builds fail on 4.15
> and newer currently.

Thing is that !BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_15 does not guarantee
that the kernel is < 4.15. Indeed, the kernel version can be much more
recent than the kernel headers version. For example, you can be using
an external toolchain with headers 4.9... and be building a 6.0 Linux
kernel, against which the ocf-linux kernel modules will be built.. and
fail to build.

To be honest, the last release of ocf-linux was in 2017. It doesn't
build after 4.14, and even 4.14 requires patches. I would advocate for
dropping ocf-linux entirely. It was added by Gustavo back in the days,
and nobody ever cared about this package except you earlier this year
with the bump to 20171122. All other changes on ocf-linux have been
related to tree-wide cleanup/infrastructure changes.

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-01 22:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-08 13:44 [Buildroot] [PATCH 1/1] package/ocf-linux: fix build with kernels up to version 4.14 James Hilliard
2022-11-01 22:31 ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).