stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: mips/poly1305 - enable for all MIPS processors
@ 2021-03-03  1:16 Maciej W. Rozycki
  2021-03-03  8:17 ` Jason A. Donenfeld
  2021-03-08 10:54 ` Thomas Bogendoerfer
  0 siblings, 2 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2021-03-03  1:16 UTC (permalink / raw)
  To: Jason A. Donenfeld, Thomas Bogendoerfer
  Cc: open list:BROADCOM NVRAM DRIVER, LKML, Ralf Baechle,
	George Cherian, Huacai Chen, Jiaxun Yang, stable

The MIPS Poly1305 implementation is generic MIPS code written such as to 
support down to the original MIPS I and MIPS III ISA for the 32-bit and 
64-bit variant respectively.  Lift the current limitation then to enable 
code for MIPSr1 ISA or newer processors only and have it available for 
all MIPS processors.

Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Fixes: a11d055e7a64 ("crypto: mips/poly1305 - incorporate OpenSSL/CRYPTOGAMS optimized implementation")
Cc: stable@vger.kernel.org # v5.5+
---
On Wed, 3 Mar 2021, Jason A. Donenfeld wrote:

> >> Would you mind sending this for 5.12 in an rc at some point, rather
> >> than waiting for 5.13? I'd like to see this backported to 5.10 and 5.4
> >> for OpenWRT.
> >
> > why is this so important for OpenWRT ? Just to select CRYPTO_POLY1305_MIPS
> > ?
> 
> Yes. The performance boost on Octeon is significant for WireGuard users.

 But that's the wrong fix for that purpose.  I've skimmed over that module 
and there's nothing MIPS64-specific there.  In fact it's plain generic 
MIPS assembly, with some R2 optimisations enabled where applicable but not 
necessary (and then R6 tweaks, but that's irrelevant here).

 As a matter of interest I have just built it successfully for a MIPS I 
DECstation configuration:

$ file arch/mips/crypto/poly1305-mips.ko
arch/mips/crypto/poly1305-mips.ko: ELF 32-bit LSB relocatable, MIPS, MIPS-I version 1 (SYSV), BuildID[sha1]=d36384d94f60ba7deff638ca8a24500120b45b56, not stripped
$ 

Patch included, please apply.

 So while your change is surely right, what you want is this really.

  Maciej
---
 arch/mips/crypto/Makefile |    4 ++--
 crypto/Kconfig            |    2 +-
 drivers/net/Kconfig       |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Index: linux/arch/mips/crypto/Makefile
===================================================================
--- linux.orig/arch/mips/crypto/Makefile
+++ linux/arch/mips/crypto/Makefile
@@ -12,8 +12,8 @@ AFLAGS_chacha-core.o += -O2 # needed to
 obj-$(CONFIG_CRYPTO_POLY1305_MIPS) += poly1305-mips.o
 poly1305-mips-y := poly1305-core.o poly1305-glue.o
 
-perlasm-flavour-$(CONFIG_CPU_MIPS32) := o32
-perlasm-flavour-$(CONFIG_CPU_MIPS64) := 64
+perlasm-flavour-$(CONFIG_32BIT) := o32
+perlasm-flavour-$(CONFIG_64BIT) := 64
 
 quiet_cmd_perlasm = PERLASM $@
       cmd_perlasm = $(PERL) $(<) $(perlasm-flavour-y) $(@)
Index: linux/crypto/Kconfig
===================================================================
--- linux.orig/crypto/Kconfig
+++ linux/crypto/Kconfig
@@ -772,7 +772,7 @@ config CRYPTO_POLY1305_X86_64
 
 config CRYPTO_POLY1305_MIPS
 	tristate "Poly1305 authenticator algorithm (MIPS optimized)"
-	depends on CPU_MIPS32 || (CPU_MIPS64 && 64BIT)
+	depends on MIPS
 	select CRYPTO_ARCH_HAVE_LIB_POLY1305
 
 config CRYPTO_MD4
Index: linux/drivers/net/Kconfig
===================================================================
--- linux.orig/drivers/net/Kconfig
+++ linux/drivers/net/Kconfig
@@ -92,7 +92,7 @@ config WIREGUARD
 	select CRYPTO_POLY1305_ARM if ARM
 	select CRYPTO_CURVE25519_NEON if ARM && KERNEL_MODE_NEON
 	select CRYPTO_CHACHA_MIPS if CPU_MIPS32_R2
-	select CRYPTO_POLY1305_MIPS if CPU_MIPS32 || (CPU_MIPS64 && 64BIT)
+	select CRYPTO_POLY1305_MIPS if MIPS
 	help
 	  WireGuard is a secure, fast, and easy to use replacement for IPSec
 	  that uses modern cryptography and clever networking tricks. It's

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

* Re: [PATCH] crypto: mips/poly1305 - enable for all MIPS processors
  2021-03-03  1:16 [PATCH] crypto: mips/poly1305 - enable for all MIPS processors Maciej W. Rozycki
@ 2021-03-03  8:17 ` Jason A. Donenfeld
  2021-03-03 12:31   ` Andy Polyakov
  2021-03-08 10:54 ` Thomas Bogendoerfer
  1 sibling, 1 reply; 5+ messages in thread
From: Jason A. Donenfeld @ 2021-03-03  8:17 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Thomas Bogendoerfer, open list:BROADCOM NVRAM DRIVER, LKML,
	Ralf Baechle, George Cherian, Huacai Chen, Jiaxun Yang, stable,
	Andy Polyakov

Hi Maciej,

On Wed, Mar 3, 2021 at 2:16 AM Maciej W. Rozycki <macro@orcam.me.uk> wrote:
>
> The MIPS Poly1305 implementation is generic MIPS code written such as to
> support down to the original MIPS I and MIPS III ISA for the 32-bit and
> 64-bit variant respectively.  Lift the current limitation then to enable
> code for MIPSr1 ISA or newer processors only and have it available for
> all MIPS processors.

That sounds like a good solution to me. Thanks for doing the research
on it. Assuming your findings hold up:

Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>

I'm also CC'ing Andy on this, who wrote the original assembly, in case
he has some last minute objection.

Jason

>
> Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
> Fixes: a11d055e7a64 ("crypto: mips/poly1305 - incorporate OpenSSL/CRYPTOGAMS optimized implementation")
> Cc: stable@vger.kernel.org # v5.5+
> ---
> On Wed, 3 Mar 2021, Jason A. Donenfeld wrote:
>
> > >> Would you mind sending this for 5.12 in an rc at some point, rather
> > >> than waiting for 5.13? I'd like to see this backported to 5.10 and 5.4
> > >> for OpenWRT.
> > >
> > > why is this so important for OpenWRT ? Just to select CRYPTO_POLY1305_MIPS
> > > ?
> >
> > Yes. The performance boost on Octeon is significant for WireGuard users.
>
>  But that's the wrong fix for that purpose.  I've skimmed over that module
> and there's nothing MIPS64-specific there.  In fact it's plain generic
> MIPS assembly, with some R2 optimisations enabled where applicable but not
> necessary (and then R6 tweaks, but that's irrelevant here).
>
>  As a matter of interest I have just built it successfully for a MIPS I
> DECstation configuration:
>
> $ file arch/mips/crypto/poly1305-mips.ko
> arch/mips/crypto/poly1305-mips.ko: ELF 32-bit LSB relocatable, MIPS, MIPS-I version 1 (SYSV), BuildID[sha1]=d36384d94f60ba7deff638ca8a24500120b45b56, not stripped
> $
>
> Patch included, please apply.
>
>  So while your change is surely right, what you want is this really.
>
>   Maciej
> ---
>  arch/mips/crypto/Makefile |    4 ++--
>  crypto/Kconfig            |    2 +-
>  drivers/net/Kconfig       |    2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
>
> Index: linux/arch/mips/crypto/Makefile
> ===================================================================
> --- linux.orig/arch/mips/crypto/Makefile
> +++ linux/arch/mips/crypto/Makefile
> @@ -12,8 +12,8 @@ AFLAGS_chacha-core.o += -O2 # needed to
>  obj-$(CONFIG_CRYPTO_POLY1305_MIPS) += poly1305-mips.o
>  poly1305-mips-y := poly1305-core.o poly1305-glue.o
>
> -perlasm-flavour-$(CONFIG_CPU_MIPS32) := o32
> -perlasm-flavour-$(CONFIG_CPU_MIPS64) := 64
> +perlasm-flavour-$(CONFIG_32BIT) := o32
> +perlasm-flavour-$(CONFIG_64BIT) := 64
>
>  quiet_cmd_perlasm = PERLASM $@
>        cmd_perlasm = $(PERL) $(<) $(perlasm-flavour-y) $(@)
> Index: linux/crypto/Kconfig
> ===================================================================
> --- linux.orig/crypto/Kconfig
> +++ linux/crypto/Kconfig
> @@ -772,7 +772,7 @@ config CRYPTO_POLY1305_X86_64
>
>  config CRYPTO_POLY1305_MIPS
>         tristate "Poly1305 authenticator algorithm (MIPS optimized)"
> -       depends on CPU_MIPS32 || (CPU_MIPS64 && 64BIT)
> +       depends on MIPS
>         select CRYPTO_ARCH_HAVE_LIB_POLY1305
>
>  config CRYPTO_MD4
> Index: linux/drivers/net/Kconfig
> ===================================================================
> --- linux.orig/drivers/net/Kconfig
> +++ linux/drivers/net/Kconfig
> @@ -92,7 +92,7 @@ config WIREGUARD
>         select CRYPTO_POLY1305_ARM if ARM
>         select CRYPTO_CURVE25519_NEON if ARM && KERNEL_MODE_NEON
>         select CRYPTO_CHACHA_MIPS if CPU_MIPS32_R2
> -       select CRYPTO_POLY1305_MIPS if CPU_MIPS32 || (CPU_MIPS64 && 64BIT)
> +       select CRYPTO_POLY1305_MIPS if MIPS
>         help
>           WireGuard is a secure, fast, and easy to use replacement for IPSec
>           that uses modern cryptography and clever networking tricks. It's

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

* Re: [PATCH] crypto: mips/poly1305 - enable for all MIPS processors
  2021-03-03  8:17 ` Jason A. Donenfeld
@ 2021-03-03 12:31   ` Andy Polyakov
  2021-03-03 12:32     ` Jason A. Donenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Polyakov @ 2021-03-03 12:31 UTC (permalink / raw)
  To: Jason A. Donenfeld, Maciej W. Rozycki
  Cc: Thomas Bogendoerfer, open list:BROADCOM NVRAM DRIVER, LKML,
	Ralf Baechle, George Cherian, Huacai Chen, Jiaxun Yang, stable

Hi,

> I'm also CC'ing Andy on this, who wrote the original assembly, in case
> he has some last minute objection.

Just "what took you so long":-) On potentially related note cryptogams
chacha-mips is as universal as poly1305-mips. "Universal" in sense that
it can be compiled for all MIPS stripes.

Cheers.

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

* Re: [PATCH] crypto: mips/poly1305 - enable for all MIPS processors
  2021-03-03 12:31   ` Andy Polyakov
@ 2021-03-03 12:32     ` Jason A. Donenfeld
  0 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2021-03-03 12:32 UTC (permalink / raw)
  To: Andy Polyakov
  Cc: Maciej W. Rozycki, Thomas Bogendoerfer,
	open list:BROADCOM NVRAM DRIVER, LKML, Ralf Baechle,
	George Cherian, Huacai Chen, Jiaxun Yang, stable

On Wed, Mar 3, 2021 at 1:31 PM Andy Polyakov <appro@cryptogams.org> wrote:
>
> Hi,
>
> > I'm also CC'ing Andy on this, who wrote the original assembly, in case
> > he has some last minute objection.
>
> Just "what took you so long":-) On potentially related note cryptogams
> chacha-mips is as universal as poly1305-mips. "Universal" in sense that
> it can be compiled for all MIPS stripes.

Oh great. I didn't realize you had a ChaCha mips implementation. I'll
look into having that replace my junky mips32r2 one.

Jason

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

* Re: [PATCH] crypto: mips/poly1305 - enable for all MIPS processors
  2021-03-03  1:16 [PATCH] crypto: mips/poly1305 - enable for all MIPS processors Maciej W. Rozycki
  2021-03-03  8:17 ` Jason A. Donenfeld
@ 2021-03-08 10:54 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Bogendoerfer @ 2021-03-08 10:54 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Jason A. Donenfeld, open list:BROADCOM NVRAM DRIVER, LKML,
	Ralf Baechle, George Cherian, Huacai Chen, Jiaxun Yang, stable

On Wed, Mar 03, 2021 at 02:16:04AM +0100, Maciej W. Rozycki wrote:
> The MIPS Poly1305 implementation is generic MIPS code written such as to 
> support down to the original MIPS I and MIPS III ISA for the 32-bit and 
> 64-bit variant respectively.  Lift the current limitation then to enable 
> code for MIPSr1 ISA or newer processors only and have it available for 
> all MIPS processors.
> 
> Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
> Fixes: a11d055e7a64 ("crypto: mips/poly1305 - incorporate OpenSSL/CRYPTOGAMS optimized implementation")
> Cc: stable@vger.kernel.org # v5.5+
> ---
> On Wed, 3 Mar 2021, Jason A. Donenfeld wrote:
> 
> > >> Would you mind sending this for 5.12 in an rc at some point, rather
> > >> than waiting for 5.13? I'd like to see this backported to 5.10 and 5.4
> > >> for OpenWRT.
> > >
> > > why is this so important for OpenWRT ? Just to select CRYPTO_POLY1305_MIPS
> > > ?
> > 
> > Yes. The performance boost on Octeon is significant for WireGuard users.
> 
>  But that's the wrong fix for that purpose.  I've skimmed over that module 
> and there's nothing MIPS64-specific there.  In fact it's plain generic 
> MIPS assembly, with some R2 optimisations enabled where applicable but not 
> necessary (and then R6 tweaks, but that's irrelevant here).
> 
>  As a matter of interest I have just built it successfully for a MIPS I 
> DECstation configuration:
> 
> $ file arch/mips/crypto/poly1305-mips.ko
> arch/mips/crypto/poly1305-mips.ko: ELF 32-bit LSB relocatable, MIPS, MIPS-I version 1 (SYSV), BuildID[sha1]=d36384d94f60ba7deff638ca8a24500120b45b56, not stripped
> $ 
> 
> Patch included, please apply.
> 
>  So while your change is surely right, what you want is this really.
> 
>   Maciej
> ---
>  arch/mips/crypto/Makefile |    4 ++--
>  crypto/Kconfig            |    2 +-
>  drivers/net/Kconfig       |    2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)

applied to mips-fixes.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

end of thread, other threads:[~2021-03-08 10:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  1:16 [PATCH] crypto: mips/poly1305 - enable for all MIPS processors Maciej W. Rozycki
2021-03-03  8:17 ` Jason A. Donenfeld
2021-03-03 12:31   ` Andy Polyakov
2021-03-03 12:32     ` Jason A. Donenfeld
2021-03-08 10:54 ` Thomas Bogendoerfer

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).