Skip to contentSkip to conversation

Remove pcrypt

PATCH In review Eric Biggers 6 participants 15 messages Jul 13 – Jul 24

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover Remove pcrypt

This series removes the obsolete 'pcrypt' module, along with the serialized job support in padata which was used only by pcrypt.

Changed in v2:
- Added patch that removes the serialized job support from padata.

Eric Biggers (2):
crypto: pcrypt - Remove pcrypt
padata: Remove serialized job support

 Documentation/core-api/padata.rst           | 145 +---
 MAINTAINERS                                 |   7 -
 arch/loongarch/configs/loongson32_defconfig |   1 -
 arch/loongarch/configs/loongson64_defconfig |   1 -
 arch/s390/configs/debug_defconfig           |   1 -
 arch/s390/configs/defconfig                 |   1 -
 crypto/Kconfig                              |  10 -
 crypto/Makefile                             |   1 -
 crypto/pcrypt.c                             | 394 ---------
 include/crypto/pcrypt.h                     |  39 -
 include/linux/padata.h                      | 145 +---
 kernel/padata.c                             | 902 +-------------------
 tools/crypto/tcrypt/tcrypt_speed_compare.py |   7 +-
 13 files changed, 18 insertions(+), 1636 deletions(-)
 delete mode 100644 crypto/pcrypt.c
 delete mode 100644 include/crypto/pcrypt.h

base-commit: 0f26556c5eeea62cc934fa8938b148aa5844a6b6

Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 crypto: pcrypt - Remove pcrypt

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

Cc Steffen Klassert <[email protected]>
---
 MAINTAINERS                                 |   7 -
 arch/loongarch/configs/loongson32_defconfig |   1 -
 arch/loongarch/configs/loongson64_defconfig |   1 -
 arch/s390/configs/debug_defconfig           |   1 -
 arch/s390/configs/defconfig                 |   1 -
 crypto/Kconfig                              |  10 -
 crypto/Makefile                             |   1 -
 crypto/pcrypt.c                             | 394 --------------------
 include/crypto/pcrypt.h                     |  39 --
 tools/crypto/tcrypt/tcrypt_speed_compare.py |   7 +-
 10 files changed, 2 insertions(+), 460 deletions(-)
 delete mode 100644 crypto/pcrypt.c
 delete mode 100644 include/crypto/pcrypt.h
MAINTAINERS +0 -7
index 806bd2d80d15..260b3bdc7614 100644
@@ -21085,13 +21085,6 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/amd/pcnet32.c
 
-PCRYPT PARALLEL CRYPTO ENGINE
-M:	Steffen Klassert <[email protected]>
-L:	[email protected]
-S:	Maintained
-F:	crypto/pcrypt.c
-F:	include/crypto/pcrypt.h
-
 PDS DSC VIRTIO DATA PATH ACCELERATOR
 R:	Brett Creeley <[email protected]>
 F:	drivers/vdpa/pds/
arch/loongarch/configs/loongson32_defconfig +0 -1
index 7c8f01513ed2..cf97f4493573 100644
@@ -1063,7 +1063,6 @@ CONFIG_SECURITY_YAMA=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_CRYPTO_USER=m
 CONFIG_CRYPTO_SELFTESTS=y
-CONFIG_CRYPTO_PCRYPT=m
 CONFIG_CRYPTO_CRYPTD=m
 CONFIG_CRYPTO_ANUBIS=m
 CONFIG_CRYPTO_BLOWFISH=m
arch/loongarch/configs/loongson64_defconfig +0 -1
index 8e3906d3bd70..d0ece7920f21 100644
@@ -1096,7 +1096,6 @@ CONFIG_SECURITY_YAMA=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_CRYPTO_USER=m
 CONFIG_CRYPTO_SELFTESTS=y
-CONFIG_CRYPTO_PCRYPT=m
 CONFIG_CRYPTO_CRYPTD=m
 CONFIG_CRYPTO_ANUBIS=m
 CONFIG_CRYPTO_BLOWFISH=m
arch/s390/configs/debug_defconfig +0 -1
index 54637be87fb7..15f51cb924db 100644
@@ -765,7 +765,6 @@ CONFIG_CRYPTO_USER=m
 CONFIG_CRYPTO_SELFTESTS=y
 CONFIG_CRYPTO_SELFTESTS_FULL=y
 CONFIG_CRYPTO_NULL=y
-CONFIG_CRYPTO_PCRYPT=m
 CONFIG_CRYPTO_CRYPTD=m
 CONFIG_CRYPTO_BENCHMARK=m
 CONFIG_CRYPTO_DH=m
arch/s390/configs/defconfig +0 -1
index 5f5114a253cf..88257ff3c2c6 100644
@@ -749,7 +749,6 @@ CONFIG_CRYPTO_FIPS=y
 CONFIG_CRYPTO_USER=m
 CONFIG_CRYPTO_SELFTESTS=y
 CONFIG_CRYPTO_NULL=y
-CONFIG_CRYPTO_PCRYPT=m
 CONFIG_CRYPTO_CRYPTD=m
 CONFIG_CRYPTO_BENCHMARK=m
 CONFIG_CRYPTO_DH=m
crypto/Kconfig +0 -10
index f1e372195273..228a7ac9f063 100644
@@ -201,16 +201,6 @@ config CRYPTO_NULL
 	help
 	  These are 'Null' algorithms, used by IPsec, which do nothing.
 
-config CRYPTO_PCRYPT
-	tristate "Parallel crypto engine"
-	depends on SMP
-	select PADATA
-	select CRYPTO_MANAGER
-	select CRYPTO_AEAD
-	help
-	  This converts an arbitrary crypto algorithm into a parallel
-	  algorithm that executes in kernel threads.
-
 config CRYPTO_CRYPTD
 	tristate "Software async crypto daemon"
 	select CRYPTO_AEAD
crypto/Makefile +0 -1
index 8386d55a9755..2e487c946e63 100644
@@ -120,7 +120,6 @@ CFLAGS_aegis128-neon-inner.o += $(aegis128-cflags-y)
 aegis128-$(CONFIG_CRYPTO_AEGIS128_SIMD) += aegis128-neon.o aegis128-neon-inner.o
 endif
 
-obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
 obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
 obj-$(CONFIG_CRYPTO_DES) += des_generic.o
 obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o
crypto/pcrypt.c deleted +0 -394

394 lines not on this page · raw message

include/crypto/pcrypt.h deleted +0 -39
deleted file mode 100644
index 234d7cf3cf5e..000000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * pcrypt - Parallel crypto engine.
- *
- * Copyright (C) 2009 secunet Security Networks AG
- * Copyright (C) 2009 Steffen Klassert <[email protected]>
- */
-
-#ifndef _CRYPTO_PCRYPT_H
-#define _CRYPTO_PCRYPT_H
-
-#include <linux/container_of.h>
-#include <linux/crypto.h>
-#include <linux/padata.h>
-
-struct pcrypt_request {
-	struct padata_priv	padata;
-	void			*data;
-	void			*__ctx[] CRYPTO_MINALIGN_ATTR;
-};
-
-static inline void *pcrypt_request_ctx(struct pcrypt_request *req)
-{
-	return req->__ctx;
-}
-
-static inline
-struct padata_priv *pcrypt_request_padata(struct pcrypt_request *req)
-{
-	return &req->padata;
-}
-
-static inline
-struct pcrypt_request *pcrypt_padata_request(struct padata_priv *padata)
-{
-	return container_of(padata, struct pcrypt_request, padata);
-}
-
-#endif
tools/crypto/tcrypt/tcrypt_speed_compare.py +2 -5
index f3f5783cdc06..0bf38c073dbc 100755
@@ -28,19 +28,16 @@ num_mb=8
 mode=211
 
 # base speed test
-lsmod | grep pcrypt && modprobe -r pcrypt
 dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+modprobe tcrypt alg="rfc4106(gcm(aes))" type=3
 modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
 dmesg > ${seq_num}_base_dmesg.log
 
 # new speed test
-lsmod | grep pcrypt && modprobe -r pcrypt
 dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+modprobe tcrypt alg="rfc4106(gcm(aes))" type=3
 modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
 dmesg > ${seq_num}_new_dmesg.log
-lsmod | grep pcrypt && modprobe -r pcrypt
 
 tools/crypto/tcrypt/tcrypt_speed_compare.py \
     ${seq_num}_base_dmesg.log \
Signature · 1 line
2.55.0
#12 lore raw

PATCH 2/2 padata: Remove serialized job support

In reply to Eric Biggers

Now that pcrypt has been removed, also remove all the code in padata whose only user was pcrypt.

Cc Steffen Klassert <[email protected]>
---
 Documentation/core-api/padata.rst | 145 +----
 include/linux/padata.h            | 145 +----
 kernel/padata.c                   | 902 +-----------------------------
 3 files changed, 16 insertions(+), 1176 deletions(-)
Documentation/core-api/padata.rst +2 -143
index 05b73c6c105f..d7dc7e33054d 100644
@@ -7,152 +7,11 @@ The padata parallel execution mechanism
 :Date: May 2020
 
 Padata is a mechanism by which the kernel can farm jobs out to be done in
-parallel on multiple CPUs while optionally retaining their ordering.
+parallel on multiple CPUs while coordinating between threads.
 
-It was originally developed for IPsec, which needs to perform encryption and
-decryption on large numbers of packets without reordering those packets.  This
-is currently the sole consumer of padata's serialized job support.
-
-Padata also supports multithreaded jobs, splitting up the job evenly while load
+Padata supports multithreaded jobs, splitting up the job evenly while load
 balancing and coordinating between threads.
 
-Running Serialized Jobs
-=======================
-
-Initializing
-------------
-
-The first step in using padata to run serialized jobs is to set up a
-padata_instance structure for overall control of how jobs are to be run::
-
-    #include <linux/padata.h>
-
-    struct padata_instance *padata_alloc(const char *name);
-
-'name' simply identifies the instance.
-
-Then, complete padata initialization by allocating a padata_shell::
-
-   struct padata_shell *padata_alloc_shell(struct padata_instance *pinst);
-
-A padata_shell is used to submit a job to padata and allows a series of such
-jobs to be serialized independently.  A padata_instance may have one or more
-padata_shells associated with it, each allowing a separate series of jobs.
-
-Modifying cpumasks
-------------------
-
-The CPUs used to run jobs can be changed in two ways, programmatically with
-padata_set_cpumask() or via sysfs.  The former is defined::
-
-    int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type,
-			   cpumask_var_t cpumask);
-
-Here cpumask_type is one of PADATA_CPU_PARALLEL or PADATA_CPU_SERIAL, where a
-parallel cpumask describes which processors will be used to execute jobs
-submitted to this instance in parallel and a serial cpumask defines which
-processors are allowed to be used as the serialization callback processor.
-cpumask specifies the new cpumask to use.
-
-There may be sysfs files for an instance's cpumasks.  For example, pcrypt's
-live in /sys/kernel/pcrypt/<instance-name>.  Within an instance's directory
-there are two files, parallel_cpumask and serial_cpumask, and either cpumask
-may be changed by echoing a bitmask into the file, for example::
-
-    echo f > /sys/kernel/pcrypt/pencrypt/parallel_cpumask
-
-Reading one of these files shows the user-supplied cpumask, which may be
-different from the 'usable' cpumask.
-
-Padata maintains two pairs of cpumasks internally, the user-supplied cpumasks
-and the 'usable' cpumasks.  (Each pair consists of a parallel and a serial
-cpumask.)  The user-supplied cpumasks default to all possible CPUs on instance
-allocation and may be changed as above.  The usable cpumasks are always a
-subset of the user-supplied cpumasks and contain only the online CPUs in the
-user-supplied masks; these are the cpumasks padata actually uses.  So it is
-legal to supply a cpumask to padata that contains offline CPUs.  Once an
-offline CPU in the user-supplied cpumask comes online, padata is going to use
-it.
-
-Changing the CPU masks are expensive operations, so it should not be done with
-great frequency.
-
-Running A Job
--------------
-
-Actually submitting work to the padata instance requires the creation of a
-padata_priv structure, which represents one job::
-
-    struct padata_priv {
-        /* Other stuff here... */
-	void                    (*parallel)(struct padata_priv *padata);
-	void                    (*serial)(struct padata_priv *padata);
-    };
-
-This structure will almost certainly be embedded within some larger
-structure specific to the work to be done.  Most of its fields are private to
-padata, but the structure should be zeroed at initialisation time, and the
-parallel() and serial() functions should be provided.  Those functions will
-be called in the process of getting the work done as we will see
-momentarily.
-
-The submission of the job is done with::
-
-    int padata_do_parallel(struct padata_shell *ps,
-		           struct padata_priv *padata, int *cb_cpu);
-
-The ps and padata structures must be set up as described above; cb_cpu
-points to the preferred CPU to be used for the final callback when the job is
-done; it must be in the current instance's CPU mask (if not the cb_cpu pointer
-is updated to point to the CPU actually chosen).  The return value from
-padata_do_parallel() is zero on success, indicating that the job is in
-progress. -EBUSY means that somebody, somewhere else is messing with the
-instance's CPU mask, while -EINVAL is a complaint about cb_cpu not being in the
-serial cpumask, no online CPUs in the parallel or serial cpumasks, or a stopped
-instance.
-
-Each job submitted to padata_do_parallel() will, in turn, be passed to
-exactly one call to the above-mentioned parallel() function, on one CPU, so
-true parallelism is achieved by submitting multiple jobs.  parallel() runs with
-software interrupts disabled and thus cannot sleep.  The parallel()
-function gets the padata_priv structure pointer as its lone parameter;
-information about the actual work to be done is probably obtained by using
-container_of() to find the enclosing structure.
-
-Note that parallel() has no return value; the padata subsystem assumes that
-parallel() will take responsibility for the job from this point.  The job
-need not be completed during this call, but, if parallel() leaves work
-outstanding, it should be prepared to be called again with a new job before
-the previous one completes.
-
-Serializing Jobs
-----------------
-
-When a job does complete, parallel() (or whatever function actually finishes
-the work) should inform padata of the fact with a call to::
-
-    void padata_do_serial(struct padata_priv *padata);
-
-At some point in the future, padata_do_serial() will trigger a call to the
-serial() function in the padata_priv structure.  That call will happen on
-the CPU requested in the initial call to padata_do_parallel(); it, too, is
-run with local software interrupts disabled.
-Note that this call may be deferred for a while since the padata code takes
-pains to ensure that jobs are completed in the order in which they were
-submitted.
-
-Destroying
-----------
-
-Cleaning up a padata instance predictably involves calling the two free
-functions that correspond to the allocation in reverse::
-
-    void padata_free_shell(struct padata_shell *ps);
-    void padata_free(struct padata_instance *pinst);
-
-It is the user's responsibility to ensure all outstanding jobs are complete
-before any of the above are called.
-
 Running Multithreaded Jobs
 ==========================
 
include/linux/padata.h +2 -143

160 lines not on this page · raw message

kernel/padata.c +12 -890

944 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

In reply to Eric Biggers
Quoted 33 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

Cc Steffen Klassert <[email protected]>
---
  MAINTAINERS                                 |   7 -
  arch/loongarch/configs/loongson32_defconfig |   1 -
  arch/loongarch/configs/loongson64_defconfig |   1 -
  arch/s390/configs/debug_defconfig           |   1 -
  arch/s390/configs/defconfig                 |   1 -
  crypto/Kconfig                              |  10 -
  crypto/Makefile                             |   1 -
  crypto/pcrypt.c                             | 394 --------------------
  include/crypto/pcrypt.h                     |  39 --
  tools/crypto/tcrypt/tcrypt_speed_compare.py |   7 +-
  10 files changed, 2 insertions(+), 460 deletions(-)
Quoted 2 lines

delete mode 100644 crypto/pcrypt.c
delete mode 100644 include/crypto/pcrypt.h

Thanks!

Reviewed-by on v1 2/2
#13 lore raw

Re: [PATCH 2/2] padata: Remove serialized job support

In reply to Eric Biggers
Quoted 10 lines · Eric Biggers

Now that pcrypt has been removed, also remove all the code in padata whose only user was pcrypt.

Cc Steffen Klassert <[email protected]>
---
  Documentation/core-api/padata.rst | 145 +----
  include/linux/padata.h            | 145 +----
  kernel/padata.c                   | 902 +-----------------------------
  3 files changed, 16 insertions(+), 1176 deletions(-)

Nice clean-up!

#3 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

In reply to Eric Biggers

Hello,

Quoted 13 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Quoted 6 lines

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

my company is a user. We have a hardware platform based on an IMX6 SoC using IPSec and configure pcrypt using crconf. Current performance difference:

iperf3 -c <IP> --time 60 -R

pcrypt:
Download: 107 Mbits/sec

No pcrypt:
Download: 59.3 Mbits/sec

iperf3 -c <IP> --time 60

pcrypt:
Upload: 65.9 Mbits/sec

No pcrypt:
Upload: 52.0 Mbits/sec

The relevant crypto templates are configured in early userspace and since i got curious, that has been the case since 2017.

Mostly using

pcrypt(gcm_base(ctr-aes-neonbs,ghash-generic))

nowadays, AES-CBC in the past/as a fallback option.

So at least on some platforms there is still a significant performance boots, at least for downloads in this case.

Regards,
Hendrik

Quoted 587 lines
Cc Steffen Klassert <[email protected]>
---
  MAINTAINERS                                 |   7 -
  arch/loongarch/configs/loongson32_defconfig |   1 -
  arch/loongarch/configs/loongson64_defconfig |   1 -
  arch/s390/configs/debug_defconfig           |   1 -
  arch/s390/configs/defconfig                 |   1 -
  crypto/Kconfig                              |  10 -
  crypto/Makefile                             |   1 -
  crypto/pcrypt.c                             | 394 --------------------
  include/crypto/pcrypt.h                     |  39 --
  tools/crypto/tcrypt/tcrypt_speed_compare.py |   7 +-
  10 files changed, 2 insertions(+), 460 deletions(-)

delete mode 100644 crypto/pcrypt.c
delete mode 100644 include/crypto/pcrypt.h

MAINTAINERS +0 -7
index 806bd2d80d15..260b3bdc7614 100644
@@ -21085,13 +21085,6 @@ L:	[email protected]
  S:	Maintained
  F:	drivers/net/ethernet/amd/pcnet32.c
 
-PCRYPT PARALLEL CRYPTO ENGINE
-M:	Steffen Klassert <[email protected]>
-L:	[email protected]
-S:	Maintained
-F:	crypto/pcrypt.c
-F:	include/crypto/pcrypt.h
-
  PDS DSC VIRTIO DATA PATH ACCELERATOR
  R:	Brett Creeley <[email protected]>
  F:	drivers/vdpa/pds/
arch/loongarch/configs/loongson32_defconfig +0 -1
index 7c8f01513ed2..cf97f4493573 100644
@@ -1063,7 +1063,6 @@ CONFIG_SECURITY_YAMA=y
  CONFIG_DEFAULT_SECURITY_DAC=y
  CONFIG_CRYPTO_USER=m
  CONFIG_CRYPTO_SELFTESTS=y
-CONFIG_CRYPTO_PCRYPT=m
  CONFIG_CRYPTO_CRYPTD=m
  CONFIG_CRYPTO_ANUBIS=m
  CONFIG_CRYPTO_BLOWFISH=m
arch/loongarch/configs/loongson64_defconfig +0 -1
index 8e3906d3bd70..d0ece7920f21 100644
@@ -1096,7 +1096,6 @@ CONFIG_SECURITY_YAMA=y
  CONFIG_DEFAULT_SECURITY_DAC=y
  CONFIG_CRYPTO_USER=m
  CONFIG_CRYPTO_SELFTESTS=y
-CONFIG_CRYPTO_PCRYPT=m
  CONFIG_CRYPTO_CRYPTD=m
  CONFIG_CRYPTO_ANUBIS=m
  CONFIG_CRYPTO_BLOWFISH=m
arch/s390/configs/debug_defconfig +0 -1
index 54637be87fb7..15f51cb924db 100644
@@ -765,7 +765,6 @@ CONFIG_CRYPTO_USER=m
  CONFIG_CRYPTO_SELFTESTS=y
  CONFIG_CRYPTO_SELFTESTS_FULL=y
  CONFIG_CRYPTO_NULL=y
-CONFIG_CRYPTO_PCRYPT=m
  CONFIG_CRYPTO_CRYPTD=m
  CONFIG_CRYPTO_BENCHMARK=m
  CONFIG_CRYPTO_DH=m
arch/s390/configs/defconfig +0 -1
index 5f5114a253cf..88257ff3c2c6 100644
@@ -749,7 +749,6 @@ CONFIG_CRYPTO_FIPS=y
  CONFIG_CRYPTO_USER=m
  CONFIG_CRYPTO_SELFTESTS=y
  CONFIG_CRYPTO_NULL=y
-CONFIG_CRYPTO_PCRYPT=m
  CONFIG_CRYPTO_CRYPTD=m
  CONFIG_CRYPTO_BENCHMARK=m
  CONFIG_CRYPTO_DH=m
crypto/Kconfig +0 -10
index f1e372195273..228a7ac9f063 100644
@@ -201,16 +201,6 @@ config CRYPTO_NULL
  	help
  	  These are 'Null' algorithms, used by IPsec, which do nothing.
 
-config CRYPTO_PCRYPT
-	tristate "Parallel crypto engine"
-	depends on SMP
-	select PADATA
-	select CRYPTO_MANAGER
-	select CRYPTO_AEAD
-	help
-	  This converts an arbitrary crypto algorithm into a parallel
-	  algorithm that executes in kernel threads.
-
  config CRYPTO_CRYPTD
  	tristate "Software async crypto daemon"
  	select CRYPTO_AEAD
crypto/Makefile +0 -1
index 8386d55a9755..2e487c946e63 100644
@@ -120,7 +120,6 @@ CFLAGS_aegis128-neon-inner.o += $(aegis128-cflags-y)
  aegis128-$(CONFIG_CRYPTO_AEGIS128_SIMD) += aegis128-neon.o aegis128-neon-inner.o
  endif
 
-obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
  obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
  obj-$(CONFIG_CRYPTO_DES) += des_generic.o
  obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o
crypto/pcrypt.c deleted +0 -394
deleted file mode 100644
index 9f372442981e..000000000000
@@ -1,394 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * pcrypt - Parallel crypto wrapper.
- *
- * Copyright (C) 2009 secunet Security Networks AG
- * Copyright (C) 2009 Steffen Klassert <[email protected]>
- */
-
-#include <crypto/algapi.h>
-#include <crypto/internal/aead.h>
-#include <linux/atomic.h>
-#include <linux/err.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/kobject.h>
-#include <linux/cpu.h>
-#include <crypto/pcrypt.h>
-
-static struct padata_instance *pencrypt;
-static struct padata_instance *pdecrypt;
-static struct kset           *pcrypt_kset;
-
-struct pcrypt_instance_ctx {
-	struct crypto_aead_spawn spawn;
-	struct padata_shell *psenc;
-	struct padata_shell *psdec;
-	atomic_t tfm_count;
-};
-
-struct pcrypt_aead_ctx {
-	struct crypto_aead *child;
-	unsigned int cb_cpu;
-};
-
-static inline struct pcrypt_instance_ctx *pcrypt_tfm_ictx(
-	struct crypto_aead *tfm)
-{
-	return aead_instance_ctx(aead_alg_instance(tfm));
-}
-
-static int pcrypt_aead_setkey(struct crypto_aead *parent,
-			      const u8 *key, unsigned int keylen)
-{
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(parent);
-
-	return crypto_aead_setkey(ctx->child, key, keylen);
-}
-
-static int pcrypt_aead_setauthsize(struct crypto_aead *parent,
-				   unsigned int authsize)
-{
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(parent);
-
-	return crypto_aead_setauthsize(ctx->child, authsize);
-}
-
-static void pcrypt_aead_serial(struct padata_priv *padata)
-{
-	struct pcrypt_request *preq = pcrypt_padata_request(padata);
-	struct aead_request *req = pcrypt_request_ctx(preq);
-
-	aead_request_complete(req->base.data, padata->info);
-}
-
-static void pcrypt_aead_done(void *data, int err)
-{
-	struct aead_request *req = data;
-	struct pcrypt_request *preq = aead_request_ctx(req);
-	struct padata_priv *padata = pcrypt_request_padata(preq);
-
-	if (err == -EINPROGRESS)
-		return;
-
-	padata->info = err;
-
-	padata_do_serial(padata);
-}
-
-static void pcrypt_aead_enc(struct padata_priv *padata)
-{
-	struct pcrypt_request *preq = pcrypt_padata_request(padata);
-	struct aead_request *req = pcrypt_request_ctx(preq);
-	int ret;
-
-	ret = crypto_aead_encrypt(req);
-
-	if (ret == -EINPROGRESS || ret == -EBUSY)
-		return;
-
-	padata->info = ret;
-	padata_do_serial(padata);
-}
-
-static int pcrypt_aead_encrypt(struct aead_request *req)
-{
-	int err;
-	struct pcrypt_request *preq = aead_request_ctx(req);
-	struct aead_request *creq = pcrypt_request_ctx(preq);
-	struct padata_priv *padata = pcrypt_request_padata(preq);
-	struct crypto_aead *aead = crypto_aead_reqtfm(req);
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(aead);
-	u32 flags = aead_request_flags(req);
-	struct pcrypt_instance_ctx *ictx;
-
-	ictx = pcrypt_tfm_ictx(aead);
-
-	memset(padata, 0, sizeof(struct padata_priv));
-
-	padata->parallel = pcrypt_aead_enc;
-	padata->serial = pcrypt_aead_serial;
-
-	aead_request_set_tfm(creq, ctx->child);
-	aead_request_set_callback(creq, flags & ~CRYPTO_TFM_REQ_MAY_SLEEP,
-				  pcrypt_aead_done, req);
-	aead_request_set_crypt(creq, req->src, req->dst,
-			       req->cryptlen, req->iv);
-	aead_request_set_ad(creq, req->assoclen);
-
-	err = padata_do_parallel(ictx->psenc, padata, &ctx->cb_cpu);
-	if (!err)
-		return -EINPROGRESS;
-	if (err == -EBUSY) {
-		/* try non-parallel mode */
-		aead_request_set_callback(creq, flags, req->base.complete,
-					  req->base.data);
-		return crypto_aead_encrypt(creq);
-	}
-
-	return err;
-}
-
-static void pcrypt_aead_dec(struct padata_priv *padata)
-{
-	struct pcrypt_request *preq = pcrypt_padata_request(padata);
-	struct aead_request *req = pcrypt_request_ctx(preq);
-	int ret;
-
-	ret = crypto_aead_decrypt(req);
-
-	if (ret == -EINPROGRESS || ret == -EBUSY)
-		return;
-
-	padata->info = ret;
-	padata_do_serial(padata);
-}
-
-static int pcrypt_aead_decrypt(struct aead_request *req)
-{
-	int err;
-	struct pcrypt_request *preq = aead_request_ctx(req);
-	struct aead_request *creq = pcrypt_request_ctx(preq);
-	struct padata_priv *padata = pcrypt_request_padata(preq);
-	struct crypto_aead *aead = crypto_aead_reqtfm(req);
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(aead);
-	u32 flags = aead_request_flags(req);
-	struct pcrypt_instance_ctx *ictx;
-
-	ictx = pcrypt_tfm_ictx(aead);
-
-	memset(padata, 0, sizeof(struct padata_priv));
-
-	padata->parallel = pcrypt_aead_dec;
-	padata->serial = pcrypt_aead_serial;
-
-	aead_request_set_tfm(creq, ctx->child);
-	aead_request_set_callback(creq, flags & ~CRYPTO_TFM_REQ_MAY_SLEEP,
-				  pcrypt_aead_done, req);
-	aead_request_set_crypt(creq, req->src, req->dst,
-			       req->cryptlen, req->iv);
-	aead_request_set_ad(creq, req->assoclen);
-
-	err = padata_do_parallel(ictx->psdec, padata, &ctx->cb_cpu);
-	if (!err)
-		return -EINPROGRESS;
-	if (err == -EBUSY) {
-		/* try non-parallel mode */
-		aead_request_set_callback(creq, flags, req->base.complete,
-					  req->base.data);
-		return crypto_aead_decrypt(creq);
-	}
-
-	return err;
-}
-
-static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
-{
-	int cpu_index;
-	struct aead_instance *inst = aead_alg_instance(tfm);
-	struct pcrypt_instance_ctx *ictx = aead_instance_ctx(inst);
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(tfm);
-	struct crypto_aead *cipher;
-
-	cpu_index = (unsigned int)atomic_inc_return(&ictx->tfm_count) %
-		    cpumask_weight(cpu_online_mask);
-
-	ctx->cb_cpu = cpumask_nth(cpu_index, cpu_online_mask);
-	cipher = crypto_spawn_aead(&ictx->spawn);
-
-	if (IS_ERR(cipher))
-		return PTR_ERR(cipher);
-
-	ctx->child = cipher;
-	crypto_aead_set_reqsize(tfm, sizeof(struct pcrypt_request) +
-				     sizeof(struct aead_request) +
-				     crypto_aead_reqsize(cipher));
-
-	return 0;
-}
-
-static void pcrypt_aead_exit_tfm(struct crypto_aead *tfm)
-{
-	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(tfm);
-
-	crypto_free_aead(ctx->child);
-}
-
-static void pcrypt_free(struct aead_instance *inst)
-{
-	struct pcrypt_instance_ctx *ctx = aead_instance_ctx(inst);
-
-	crypto_drop_aead(&ctx->spawn);
-	padata_free_shell(ctx->psdec);
-	padata_free_shell(ctx->psenc);
-	kfree(inst);
-}
-
-static int pcrypt_init_instance(struct crypto_instance *inst,
-				struct crypto_alg *alg)
-{
-	if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
-		     "pcrypt(%s)", alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
-		return -ENAMETOOLONG;
-
-	memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
-
-	inst->alg.cra_priority = alg->cra_priority + 100;
-	inst->alg.cra_blocksize = alg->cra_blocksize;
-	inst->alg.cra_alignmask = alg->cra_alignmask;
-
-	return 0;
-}
-
-static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
-			      struct crypto_attr_type *algt)
-{
-	struct pcrypt_instance_ctx *ctx;
-	struct aead_instance *inst;
-	struct aead_alg *alg;
-	u32 mask = crypto_algt_inherited_mask(algt);
-	int err;
-
-	inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
-	if (!inst)
-		return -ENOMEM;
-
-	err = -ENOMEM;
-
-	ctx = aead_instance_ctx(inst);
-	ctx->psenc = padata_alloc_shell(pencrypt);
-	if (!ctx->psenc)
-		goto err_free_inst;
-
-	ctx->psdec = padata_alloc_shell(pdecrypt);
-	if (!ctx->psdec)
-		goto err_free_inst;
-
-	err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
-			       crypto_attr_alg_name(tb[1]), 0, mask);
-	if (err)
-		goto err_free_inst;
-
-	alg = crypto_spawn_aead_alg(&ctx->spawn);
-	err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base);
-	if (err)
-		goto err_free_inst;
-
-	inst->alg.base.cra_flags |= CRYPTO_ALG_ASYNC;
-
-	inst->alg.ivsize = crypto_aead_alg_ivsize(alg);
-	inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg);
-
-	inst->alg.base.cra_ctxsize = sizeof(struct pcrypt_aead_ctx);
-
-	inst->alg.init = pcrypt_aead_init_tfm;
-	inst->alg.exit = pcrypt_aead_exit_tfm;
-
-	inst->alg.setkey = pcrypt_aead_setkey;
-	inst->alg.setauthsize = pcrypt_aead_setauthsize;
-	inst->alg.encrypt = pcrypt_aead_encrypt;
-	inst->alg.decrypt = pcrypt_aead_decrypt;
-
-	inst->free = pcrypt_free;
-
-	err = aead_register_instance(tmpl, inst);
-	if (err) {
-err_free_inst:
-		pcrypt_free(inst);
-	}
-	return err;
-}
-
-static int pcrypt_create(struct crypto_template *tmpl, struct rtattr **tb)
-{
-	struct crypto_attr_type *algt;
-
-	algt = crypto_get_attr_type(tb);
-	if (IS_ERR(algt))
-		return PTR_ERR(algt);
-
-	switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
-	case CRYPTO_ALG_TYPE_AEAD:
-		return pcrypt_create_aead(tmpl, tb, algt);
-	}
-
-	return -EINVAL;
-}
-
-static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
-{
-	int ret;
-
-	pinst->kobj.kset = pcrypt_kset;
-	ret = kobject_add(&pinst->kobj, NULL, "%s", name);
-	if (!ret)
-		kobject_uevent(&pinst->kobj, KOBJ_ADD);
-
-	return ret;
-}
-
-static int pcrypt_init_padata(struct padata_instance **pinst, const char *name)
-{
-	int ret = -ENOMEM;
-
-	*pinst = padata_alloc(name);
-	if (!*pinst)
-		return ret;
-
-	ret = pcrypt_sysfs_add(*pinst, name);
-	if (ret)
-		padata_free(*pinst);
-
-	return ret;
-}
-
-static struct crypto_template pcrypt_tmpl = {
-	.name = "pcrypt",
-	.create = pcrypt_create,
-	.module = THIS_MODULE,
-};
-
-static int __init pcrypt_init(void)
-{
-	int err = -ENOMEM;
-
-	pcrypt_kset = kset_create_and_add("pcrypt", NULL, kernel_kobj);
-	if (!pcrypt_kset)
-		goto err;
-
-	err = pcrypt_init_padata(&pencrypt, "pencrypt");
-	if (err)
-		goto err_unreg_kset;
-
-	err = pcrypt_init_padata(&pdecrypt, "pdecrypt");
-	if (err)
-		goto err_deinit_pencrypt;
-
-	return crypto_register_template(&pcrypt_tmpl);
-
-err_deinit_pencrypt:
-	padata_free(pencrypt);
-err_unreg_kset:
-	kset_unregister(pcrypt_kset);
-err:
-	return err;
-}
-
-static void __exit pcrypt_exit(void)
-{
-	crypto_unregister_template(&pcrypt_tmpl);
-
-	padata_free(pencrypt);
-	padata_free(pdecrypt);
-
-	kset_unregister(pcrypt_kset);
-}
-
-module_init(pcrypt_init);
-module_exit(pcrypt_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Steffen Klassert <[email protected]>");
-MODULE_DESCRIPTION("Parallel crypto wrapper");
-MODULE_ALIAS_CRYPTO("pcrypt");
include/crypto/pcrypt.h deleted +0 -39
deleted file mode 100644
index 234d7cf3cf5e..000000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * pcrypt - Parallel crypto engine.
- *
- * Copyright (C) 2009 secunet Security Networks AG
- * Copyright (C) 2009 Steffen Klassert <[email protected]>
- */
-
-#ifndef _CRYPTO_PCRYPT_H
-#define _CRYPTO_PCRYPT_H
-
-#include <linux/container_of.h>
-#include <linux/crypto.h>
-#include <linux/padata.h>
-
-struct pcrypt_request {
-	struct padata_priv	padata;
-	void			*data;
-	void			*__ctx[] CRYPTO_MINALIGN_ATTR;
-};
-
-static inline void *pcrypt_request_ctx(struct pcrypt_request *req)
-{
-	return req->__ctx;
-}
-
-static inline
-struct padata_priv *pcrypt_request_padata(struct pcrypt_request *req)
-{
-	return &req->padata;
-}
-
-static inline
-struct pcrypt_request *pcrypt_padata_request(struct padata_priv *padata)
-{
-	return container_of(padata, struct pcrypt_request, padata);
-}
-
-#endif
tools/crypto/tcrypt/tcrypt_speed_compare.py +2 -5
index f3f5783cdc06..0bf38c073dbc 100755
@@ -28,19 +28,16 @@ num_mb=8
  mode=211
 
  # base speed test
-lsmod | grep pcrypt && modprobe -r pcrypt
  dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+modprobe tcrypt alg="rfc4106(gcm(aes))" type=3
  modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
  dmesg > ${seq_num}_base_dmesg.log
 
  # new speed test
-lsmod | grep pcrypt && modprobe -r pcrypt
  dmesg -C
-modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
+modprobe tcrypt alg="rfc4106(gcm(aes))" type=3
  modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
  dmesg > ${seq_num}_new_dmesg.log
-lsmod | grep pcrypt && modprobe -r pcrypt
 
  tools/crypto/tcrypt/tcrypt_speed_compare.py \
      ${seq_num}_base_dmesg.log \
#4 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Quoted 46 lines · Hendrik Donner

Hello,

Quoted 13 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Quoted 6 lines

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

my company is a user. We have a hardware platform based on an IMX6 SoC using IPSec and configure pcrypt using crconf. Current performance difference:

iperf3 -c <IP> --time 60 -R

pcrypt:
Download: 107 Mbits/sec

No pcrypt:
Download: 59.3 Mbits/sec

iperf3 -c <IP> --time 60

pcrypt:
Upload: 65.9 Mbits/sec

No pcrypt:
Upload: 52.0 Mbits/sec

The relevant crypto templates are configured in early userspace and since i got curious, that has been the case since 2017.

Quoted 8 lines

Mostly using

pcrypt(gcm_base(ctr-aes-neonbs,ghash-generic))

nowadays, AES-CBC in the past/as a fallback option.

So at least on some platforms there is still a significant performance boots, at least for downloads in this case.

Thanks for bringing up your use case.

Have you looked into alternative solutions such as Receive Side Scaling
(https://docs.kernel.org/networking/scaling.html#rss-receive-side-scaling)?
AFAIK it's not just the crypto performance that makes pcrypt unnecessary these days, but also the design of the networking layer.

I understand that i.MX6 doesn't have the ARMv8 crypto extensions. However, surely you could at least use the NEON-optimized GHASH code? Is there a reason you're not using it?

- Eric

#5 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Hello,

Quoted 56 lines · Eric Biggers
Quoted 46 lines · Hendrik Donner

Hello,

Quoted 13 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Quoted 6 lines

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

my company is a user. We have a hardware platform based on an IMX6 SoC using IPSec and configure pcrypt using crconf. Current performance difference:

iperf3 -c <IP> --time 60 -R

pcrypt:
Download: 107 Mbits/sec

No pcrypt:
Download: 59.3 Mbits/sec

iperf3 -c <IP> --time 60

pcrypt:
Upload: 65.9 Mbits/sec

No pcrypt:
Upload: 52.0 Mbits/sec

The relevant crypto templates are configured in early userspace and since i got curious, that has been the case since 2017.

Quoted 8 lines

Mostly using

pcrypt(gcm_base(ctr-aes-neonbs,ghash-generic))

nowadays, AES-CBC in the past/as a fallback option.

So at least on some platforms there is still a significant performance boots, at least for downloads in this case.

Quoted 6 lines

Thanks for bringing up your use case.

Have you looked into alternative solutions such as Receive Side Scaling
(https://docs.kernel.org/networking/scaling.html#rss-receive-side-scaling)?
AFAIK it's not just the crypto performance that makes pcrypt unnecessary these days, but also the design of the networking layer.

I'm looking into this more, the IMX.6 is a bit limited with IRQ handling and queue distribution.

Quoted 4 lines

I understand that i.MX6 doesn't have the ARMv8 crypto extensions. However, surely you could at least use the NEON-optimized GHASH code? Is there a reason you're not using it?

I think it was historically not working well for us, retested:

NEON GHASH with pcrypt:

Download: 116 Mbits/sec
Upload: 74.3 Mbits/sec

NEON GHASH baseline:

Download: 90.7 Mbits/sec
Upload: 60.8 Mbits/sec

Looks better, still a ~15 Mbit improvement with pcrypt.

I want to point out that without IPSec our baseline is:

Download: 942 Mbits/sec
Upload: 942 Mbits/sec

Intel IGB ethernet.

Regards,
Hendrik

Quoted 2 lines

- Eric

#6 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Quoted 61 lines · Hendrik Donner

Hello,

Quoted 58 lines · Eric Biggers
Quoted 46 lines · Hendrik Donner

Hello,

Quoted 13 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Quoted 6 lines

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

my company is a user. We have a hardware platform based on an IMX6 SoC using IPSec and configure pcrypt using crconf. Current performance difference:

iperf3 -c <IP> --time 60 -R

pcrypt:
Download: 107 Mbits/sec

No pcrypt:
Download: 59.3 Mbits/sec

iperf3 -c <IP> --time 60

pcrypt:
Upload: 65.9 Mbits/sec

No pcrypt:
Upload: 52.0 Mbits/sec

The relevant crypto templates are configured in early userspace and since i got curious, that has been the case since 2017.

Quoted 8 lines

Mostly using

pcrypt(gcm_base(ctr-aes-neonbs,ghash-generic))

nowadays, AES-CBC in the past/as a fallback option.

So at least on some platforms there is still a significant performance boots, at least for downloads in this case.

Thanks for bringing up your use case.

Quoted 7 lines
Quoted 4 lines

Have you looked into alternative solutions such as Receive Side Scaling
(https://docs.kernel.org/networking/scaling.html#rss-receive-side-scaling)?
AFAIK it's not just the crypto performance that makes pcrypt unnecessary these days, but also the design of the networking layer.

I'm looking into this more, the IMX.6 is a bit limited with IRQ handling and queue distribution.

Thanks! Maybe Steffen and the other IPsec folks would have some advice too.

Quoted 16 lines
Quoted 3 lines

I understand that i.MX6 doesn't have the ARMv8 crypto extensions. However, surely you could at least use the NEON-optimized GHASH code? Is there a reason you're not using it?

I think it was historically not working well for us, retested:

NEON GHASH with pcrypt:

Download: 116 Mbits/sec
Upload: 74.3 Mbits/sec

NEON GHASH baseline:

Download: 90.7 Mbits/sec
Upload: 60.8 Mbits/sec

Quoted 8 lines

Looks better, still a ~15 Mbit improvement with pcrypt.

I want to point out that without IPSec our baseline is:

Download: 942 Mbits/sec
Upload: 942 Mbits/sec

Intel IGB ethernet.

That already shows that about two-thirds of the improvement you were getting from pcrypt can be gotten just by using the correct GHASH implementation for the platform (59.3 => 90.7 download, vs 59.3 => 107; and 52.0 => 60.8 upload, vs 52.0 => 65.9).

And with that new baseline, for downloads, pcrypt adds just 28% more throughput (90.7 => 116) rather than 80% as it did before (59.3 => 107).

It seems clear that the usefulness of pcrypt rapidly decreases as the actual crypto gets faster.

Note: we've been enabling crypto optimizations by default in recent kernels, so that people can no longer use the generic code by accident. For example in v7.1 and later, GHASH optimizations are always enabled.

I'm working on further optimizations to the AES-GCM code as well, specifically implementing AES-GCM directly on all platforms without the inefficient gcm_base template that is being used here.

So while maybe pcrypt does still help a bit on this platform for now, the approach does seem quite dated and largely a workaround for inefficiencies elsewhere in the stack (including systems where the optimized crypto code is accidentally not enabled).

- Eric

#7 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Hi,

Quoted 4 lines · Eric Biggers

So while maybe pcrypt does still help a bit on this platform for now, the approach does seem quite dated and largely a workaround for inefficiencies elsewhere in the stack (including systems where the optimized crypto code is accidentally not enabled).

There is one additional aspect: offloading frees the CPU to do something else -- and that is where even offload engines that are slower than the CPU can still be beneficial in the big picture.

Simon

#8 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Quoted 4 lines · On Thu, 23 Jul 2026 08:30:47 +0900 Simon Richter <[email protected]>…

Hi,

On 7/23/26 4:40 AM, Eric Biggers wrote:

Quoted 8 lines
Quoted 4 lines

So while maybe pcrypt does still help a bit on this platform for now, the approach does seem quite dated and largely a workaround for inefficiencies elsewhere in the stack (including systems where the optimized crypto code is accidentally not enabled).

There is one additional aspect: offloading frees the CPU to do something else -- and that is where even offload engines that are slower than the CPU can still be beneficial in the big picture.

Provided what is being offload actually takes long enough to allow for setting up the iommu, the two context switches and the interrupt as well as the obvious setup costs.

David

Quoted 3 lines

Simon

#9 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

In reply to Eric Biggers

Hallo,

Quoted 67 lines · Eric Biggers
Quoted 66 lines · Hendrik Donner

Hello,

Quoted 62 lines · Eric Biggers
Quoted 46 lines · Hendrik Donner

Hello,

Quoted 13 lines · Eric Biggers

pcrypt was originally intended to improve IPsec performance. However, it's no longer useful for that. Reports from the rare cases that anyone has actually tried to use it over the years indicate that it actually reduces IPsec performance, e.g.:

* https://github.com/libreswan/libreswan/wiki/Internals:-Cryptographic-Acceleration#obsoleted-ipsec-accelerations
* https://users.strongswan.narkive.com/liqTaTq8/strongswan-problem-with-pcrypt
* https://unix.stackexchange.com/questions/594336/ipsec-multithreading-via-pcrypt-worse-than-single-thread

It's also undocumented and quite difficult to actually use. Its design is also broken, in that any unprivileged program can enable pcrypt systemwide at any time (by instantiating it using AF_ALG).

Quoted 6 lines

Meanwhile, pcrypt has been a regular source of bugs, including at least four that have received CVEs.

Let's just remove it. No one seems to care about it anymore other than people looking for vulnerabilities.

my company is a user. We have a hardware platform based on an IMX6 SoC using IPSec and configure pcrypt using crconf. Current performance difference:

iperf3 -c <IP> --time 60 -R

pcrypt:
Download: 107 Mbits/sec

No pcrypt:
Download: 59.3 Mbits/sec

iperf3 -c <IP> --time 60

pcrypt:
Upload: 65.9 Mbits/sec

No pcrypt:
Upload: 52.0 Mbits/sec

The relevant crypto templates are configured in early userspace and since i got curious, that has been the case since 2017.

Quoted 8 lines

Mostly using

pcrypt(gcm_base(ctr-aes-neonbs,ghash-generic))

nowadays, AES-CBC in the past/as a fallback option.

So at least on some platforms there is still a significant performance boots, at least for downloads in this case.

Thanks for bringing up your use case.

Have you looked into alternative solutions such as Receive Side Scaling
(https://docs.kernel.org/networking/scaling.html#rss-receive-side-scaling)?
AFAIK it's not just the crypto performance that makes pcrypt unnecessary these days, but also the design of the networking layer.

Quoted 6 lines
Quoted 2 lines

I'm looking into this more, the IMX.6 is a bit limited with IRQ handling and queue distribution.

Thanks! Maybe Steffen and the other IPsec folks would have some advice too.

so i'm now on 7.1.4 with

PCI: imx6: Keep i.MX6 Root Port MSI/MSI-X Capabilities with iMSI-RX
to work around hardware bug

on top to be able to tune queue settings. And to have a working ethernet in the first place, without the patch the NETDEV WATCHDOG resets the card all the time due to queues stalling. But now more than 1 CPU are serving IRQs.

With pcrypt (seqiv(rfc4106(pcrypt(gcm_base(ctr-aes-neonbs,ghash-lib))))):

Upload:
[ 4] 0.00-60.00 sec 901 MBytes 126 Mbits/sec

Download:
[ 4] 0.00-60.00 sec 1.23 GBytes 177 Mbits/sec

Without pcrypt (seqiv(rfc4106(gcm_base(ctr-aes-neonbs,ghash-lib)))):

Upload:
[ 4] 0.00-60.00 sec 679 MBytes 94.9 Mbits/sec

Download:
[ 4] 0.00-60.00 sec 674 MBytes 94.3 Mbits/sec

So counterintuitively pcrypt matters more again. I repeated the tests a few times, those numbers are fairly representative. Every run is over a 60 sec window.

Regards,
Hendrik

Quoted 50 lines
Quoted 16 lines
Quoted 3 lines

I understand that i.MX6 doesn't have the ARMv8 crypto extensions. However, surely you could at least use the NEON-optimized GHASH code? Is there a reason you're not using it?

I think it was historically not working well for us, retested:

NEON GHASH with pcrypt:

Download: 116 Mbits/sec
Upload: 74.3 Mbits/sec

NEON GHASH baseline:

Download: 90.7 Mbits/sec
Upload: 60.8 Mbits/sec

Quoted 8 lines

Looks better, still a ~15 Mbit improvement with pcrypt.

I want to point out that without IPSec our baseline is:

Download: 942 Mbits/sec
Upload: 942 Mbits/sec

Intel IGB ethernet.

That already shows that about two-thirds of the improvement you were getting from pcrypt can be gotten just by using the correct GHASH implementation for the platform (59.3 => 90.7 download, vs 59.3 => 107; and 52.0 => 60.8 upload, vs 52.0 => 65.9).

And with that new baseline, for downloads, pcrypt adds just 28% more throughput (90.7 => 116) rather than 80% as it did before (59.3 => 107).

It seems clear that the usefulness of pcrypt rapidly decreases as the actual crypto gets faster.

Note: we've been enabling crypto optimizations by default in recent kernels, so that people can no longer use the generic code by accident. For example in v7.1 and later, GHASH optimizations are always enabled.

I'm working on further optimizations to the AES-GCM code as well, specifically implementing AES-GCM directly on all platforms without the inefficient gcm_base template that is being used here.

So while maybe pcrypt does still help a bit on this platform for now, the approach does seem quite dated and largely a workaround for inefficiencies elsewhere in the stack (including systems where the optimized crypto code is accidentally not enabled).

- Eric

#10 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Quoted 26 lines · Hendrik Donner

so i'm now on 7.1.4 with

PCI: imx6: Keep i.MX6 Root Port MSI/MSI-X Capabilities with iMSI-RX to
work around hardware bug

on top to be able to tune queue settings. And to have a working ethernet in the first place, without the patch the NETDEV WATCHDOG resets the card all the time due to queues stalling. But now more than 1 CPU are serving IRQs.

With pcrypt (seqiv(rfc4106(pcrypt(gcm_base(ctr-aes-neonbs,ghash-lib))))):

Upload:
[ 4] 0.00-60.00 sec 901 MBytes 126 Mbits/sec

Download:
[ 4] 0.00-60.00 sec 1.23 GBytes 177 Mbits/sec

Without pcrypt (seqiv(rfc4106(gcm_base(ctr-aes-neonbs,ghash-lib)))):

Upload:
[ 4] 0.00-60.00 sec 679 MBytes 94.9 Mbits/sec

Quoted 6 lines

Download:
[ 4] 0.00-60.00 sec 674 MBytes 94.3 Mbits/sec

So counterintuitively pcrypt matters more again. I repeated the tests a few times, those numbers are fairly representative. Every run is over a 60 sec window.

Thanks for trying it. Perhaps this is related to the iperf3 test using only a single flow? Does that reflect the real-world case for you?

I'm also curious whether you're particularly attached to AES-GCM, or whether you've considered switching to ChaCha20Poly1305 which would be much faster on that CPU. This could be done either by switching to "rfc7539esp(chacha20,poly1305)" within IPsec, or by just switching to WireGuard.

If none of those are options for you and you do want pcrypt to be kept around, could you confirm that you're solely using 'crconf' (run as root) to enable it, and in particular you're not relying on the misfeature of also being able to enable it as an unprivileged user using AF_ALG? We can keep it around for a bit longer if really needed, but the unprivileged stuff definitely has to go. We should also keep in mind that pcrypt does not get tested very well (as the crypto self-tests just test serial use) and historically has had a lot of issues.

- Eric

#11 lore raw

Re: [PATCH 1/2] crypto: pcrypt - Remove pcrypt

Hello,

Quoted 30 lines · Eric Biggers
Quoted 29 lines · Hendrik Donner

so i'm now on 7.1.4 with

PCI: imx6: Keep i.MX6 Root Port MSI/MSI-X Capabilities with iMSI-RX to
work around hardware bug

on top to be able to tune queue settings. And to have a working ethernet in the first place, without the patch the NETDEV WATCHDOG resets the card all the time due to queues stalling. But now more than 1 CPU are serving IRQs.

With pcrypt (seqiv(rfc4106(pcrypt(gcm_base(ctr-aes-neonbs,ghash-lib))))):

Upload:
[ 4] 0.00-60.00 sec 901 MBytes 126 Mbits/sec

Download:
[ 4] 0.00-60.00 sec 1.23 GBytes 177 Mbits/sec

Without pcrypt (seqiv(rfc4106(gcm_base(ctr-aes-neonbs,ghash-lib)))):

Upload:
[ 4] 0.00-60.00 sec 679 MBytes 94.9 Mbits/sec

Download:
[ 4] 0.00-60.00 sec 674 MBytes 94.3 Mbits/sec

Quoted 6 lines
Quoted 3 lines

So counterintuitively pcrypt matters more again. I repeated the tests a few times, those numbers are fairly representative. Every run is over a 60 sec window.

Thanks for trying it. Perhaps this is related to the iperf3 test using only a single flow? Does that reflect the real-world case for you?

probably flow related, i would need a different test setup to create different flows, but for example single file downloads matter to our userbase.

Quoted 7 lines

I'm also curious whether you're particularly attached to AES-GCM, or whether you've considered switching to ChaCha20Poly1305 which would be much faster on that CPU. This could be done either by switching to "rfc7539esp(chacha20,poly1305)" within IPsec, or by just switching to WireGuard.

Unfortunately the technical specification the system has to comply to says IPSec and AES-GCM and/or AES-CBC with HMAC-SHA256. CBC is on its way out though and barely seen in production anymore.

Quoted 9 lines

If none of those are options for you and you do want pcrypt to be kept around, could you confirm that you're solely using 'crconf' (run as root) to enable it, and in particular you're not relying on the misfeature of also being able to enable it as an unprivileged user using AF_ALG? We can keep it around for a bit longer if really needed, but the unprivileged stuff definitely has to go. We should also keep in mind that pcrypt does not get tested very well (as the crypto self-tests just test serial use) and historically has had a lot of issues.

For configuring the IPSec related templates only crconf is used in production. On that kernel configuration AF_ALG is completely off.

Test environments use CONFIG_CRYPTO_USER_API_RNG only, everything else concerning AF_ALG is disabled.

Regards,
Hendrik

Quoted 1 line

- Eric