mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wolfgang Walter <wolfgang.walter@stwm.de>
To: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@elte.hu>
Subject: Re: Kernel oops with 2.6.26, padlock and ipsec: probably problem with fpu state changes
Date: Fri, 8 Aug 2008 21:09:46 +0200	[thread overview]
Message-ID: <200808082109.47284.wolfgang.walter@stwm.de> (raw)
In-Reply-To: <200808081236.55172.wolfgang.walter@stwm.de>

Am Freitag, 8. August 2008 12:36 schrieb Wolfgang Walter:
> Am Donnerstag, 7. August 2008 18:23 schrieb Wolfgang Walter:
> > =======================================================
> > diff -ur ../linux-2.6.26/drivers/crypto/padlock-aes.c
> > ./drivers/crypto/padlock-aes.c ---
> > ../linux-2.6.26/drivers/crypto/padlock-aes.c	2008-07-15
> > 11:29:32.000000000 +0200 +++ ./drivers/crypto/padlock-aes.c	2008-08-07
> > 17:46:55.000000000 +0200 @@ -16,6 +16,7 @@
> >  #include <linux/interrupt.h>
> >  #include <linux/kernel.h>
> >  #include <asm/byteorder.h>
> > +#include <asm/i387.h>
> >  #include "padlock.h"
> >
> >  /* Control word. */
> > @@ -144,9 +145,11 @@
> >  static inline void padlock_xcrypt(const u8 *input, u8 *output, void
> > *key, void *control_word)
> >  {
> > +	kernel_fpu_begin();
> >  	asm volatile (".byte 0xf3,0x0f,0xa7,0xc8"	/* rep xcryptecb */
> >
> >  		      : "+S"(input), "+D"(output)
> >  		      : "d"(control_word), "b"(key), "c"(1));
> >
> > +	kernel_fpu_end();
> >  }
> >
> >  static void aes_crypt_copy(const u8 *in, u8 *out, u32 *key, struct cword
> > *cword) @@ -179,6 +182,7 @@
> >  		return;
> >  	}
> >
> > +	kernel_fpu_begin();
> >  	asm volatile ("test $1, %%cl;"
> >  		      "je 1f;"
> >  		      "lea -1(%%ecx), %%eax;"
> > @@ -190,15 +194,18 @@
> >
> >  		      : "+S"(input), "+D"(output)
> >  		      : "d"(control_word), "b"(key), "c"(count)
> >  		      : "ax");
> >
> > +	kernel_fpu_end();
> >  }
> >
> >  static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void
> > *key, u8 *iv, void *control_word, u32 count)
> >  {
> >  	/* rep xcryptcbc */
> > +	kernel_fpu_begin();
> >  	asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
> >
> >  		      : "+S" (input), "+D" (output), "+a" (iv)
> >  		      : "d" (control_word), "b" (key), "c" (count));
> >
> > +	kernel_fpu_end();
> >  	return iv;
> >  }
> >
> > =============================================================
> >
> > I found that kernel_fpu_begin(); kernel_fpu_begin(); is used with
> > MMX and/or SSE:
> >
> > include/asm/xor_32.h
> > drivers/md/raid6mmx.c
> > drivers/md/raid6sse1.c
> > drivers/md/raid6sse2.c
> >
> >
> > With this change I its a little bit more stable, I needed more then 5
> > minutes to crash the kernel (repeated it several times). If I read
> > the code correctly this disables preemption for the time the padlock cmd
> > is executing.
>
> Forget that - I booted the wrong kernel.
>
> I now really test this modification and it seems to be stable. The router
> now runs for 45 minutes without oops.

It now runs for 8 hours.

So how to proceed?

Here a summary:

1) 2.6.25.x works

2) 2.6.26 without padlock works

3a) 2.6.26 using padlock and ipsec chrashes. 

Always the same reason:

	__switch_to() wants to fxsave but there is no memory allocated

which means that TS_USEDFPU has been set.

3b) 2.6.26 with padlock code from 2.6.25: using padlock and ipsec chrashes.

4) Reverting the fpu patches (from 2.6.25 to 2.6.26) fixes the problem.

5) Protecting the padlock cmds with kernel_fpu_begin(); kernel_fpu_begin(); 
fixes the problem.


Some thoughts:

4) probably fixes the problem because memory for fxsave is always allocated.

Maybe this is also the reason why 2.6.25 and earlier work.

5) is interesting:

kernel_fpu_begin() will save the fpu state if TS_USEDFPU is set - exactly as 
__unlazy_fpu in __switch_to would do. So when the crypto code calls padlock 
the world is ok: if TS_USEDFPU is set then memory has been allocated.

This makes me rather sure that there is no memory corruption by the network 
code and/or crypto code itself overwriting the task_info stucture and setting 
TS_USEDFPU.

I don't know though why kernel_fpu_begin exactly fixes the problem:

Maybe preemption must be disabled when padlocks RNG, ACE, Hash-engine etc. is 
used. Maybe just some barrier is needed which preempt_disable provides.

The padlock programming guide states that padlock's RNG, ACE, ... internally 
use SSE. Especially "it temporary enables SSE until no further SSE 
instruction or XSTORE, ... is seen". Further it may overlap with execution of 
non-SSE instructions.


Probably it is the best to treat the padlock opcodes as SSE instructions.



What should I do now?


Regards,
-- 
Wolfgang Walter
Studentenwerk München
Anstalt des öffentlichen Rechts

  parent reply	other threads:[~2008-08-08 19:10 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200807171653.59177.wolfgang.walter@stwm.de>
     [not found] ` <200807301411.01622.wolfgang.walter@stwm.de>
     [not found]   ` <20080806103354.GA31623@gondor.apana.org.au>
2008-08-06 17:33     ` Wolfgang Walter
2008-08-06 20:14       ` Suresh Siddha
2008-08-06 21:21         ` Suresh Siddha
2008-08-07  0:38           ` Wolfgang Walter
2008-08-08  8:44           ` Wolfgang Walter
2008-08-08 18:31           ` Vegard Nossum
2008-08-07 16:23         ` Wolfgang Walter
2008-08-08 10:36           ` Wolfgang Walter
2008-08-08 18:53             ` Suresh Siddha
2008-08-08 19:01               ` H. Peter Anvin
2008-08-08 19:19                 ` Wolfgang Walter
2008-08-08 23:11                 ` Suresh Siddha
2008-08-09  0:38                   ` Herbert Xu
2008-08-09  1:23                     ` Herbert Xu
2008-08-09  1:54                     ` Wolfgang Walter
2008-08-09  2:16                       ` Herbert Xu
2008-08-09  3:09                         ` Wolfgang Walter
2008-08-09  3:20                           ` Herbert Xu
2008-08-09 14:29                     ` Herbert Xu
2008-08-09 14:32                       ` Herbert Xu
2008-08-09 17:52                         ` Suresh Siddha
2008-08-10  5:30                           ` Herbert Xu
2008-08-10  5:41                             ` H. Peter Anvin
2008-08-11 22:57                               ` Suresh Siddha
2008-08-09 17:48                     ` Suresh Siddha
2008-08-09  1:28                   ` Wolfgang Walter
2008-08-09 13:31                   ` Herbert Xu
2008-08-09 14:37                   ` Herbert Xu
2008-08-09 15:14                     ` Wolfgang Walter
2008-08-09 15:57                     ` Wolfgang Walter
2008-08-09 16:10                       ` H. Peter Anvin
2008-08-09 17:02                         ` Wolfgang Walter
2008-08-09 18:52                         ` Suresh Siddha
2008-08-09 19:37                           ` Suresh Siddha
2008-08-09 22:59                             ` Wolfgang Walter
2008-08-10  3:05                             ` Herbert Xu
2008-08-11 19:01                               ` Suresh Siddha
2008-08-11 19:22                                 ` Ingo Molnar
2008-08-11 19:24                                   ` H. Peter Anvin
2008-08-11 20:19                                     ` Suresh Siddha
2008-08-12  0:39                                       ` Herbert Xu
2008-08-12  0:42                                         ` H. Peter Anvin
2008-08-12  0:46                                           ` Herbert Xu
2008-08-12  0:48                                             ` H. Peter Anvin
2008-08-12  0:52                                               ` Herbert Xu
2008-08-12  0:38                                 ` Wolfgang Walter
2008-08-12 11:43                                 ` Wolfgang Walter
2008-08-12 12:02                                   ` Herbert Xu
2008-08-12 18:28                                     ` Suresh Siddha
2008-08-12 23:40                                       ` Herbert Xu
2008-08-09 18:12                       ` Suresh Siddha
2008-08-09 18:54                         ` Suresh Siddha
2008-08-09 16:05                     ` H. Peter Anvin
2008-08-09 18:14                       ` Suresh Siddha
2008-08-10  0:29                       ` Herbert Xu
2008-08-10  1:56                         ` Wolfgang Walter
2008-08-10  1:59                           ` Herbert Xu
2008-08-09 17:59                     ` Suresh Siddha
2008-08-10  1:40                       ` Herbert Xu
2008-08-09  1:49                 ` Herbert Xu
2008-08-09  1:59                   ` H. Peter Anvin
2008-08-09  2:43                   ` Wolfgang Walter
2008-08-09  3:30                     ` H. Peter Anvin
2008-08-09 10:50                       ` Wolfgang Walter
2008-08-08 19:09             ` Wolfgang Walter [this message]
2008-08-08 19:32               ` Suresh Siddha
2008-08-08 23:10                 ` Wolfgang Walter
2008-08-08 23:15                   ` Suresh Siddha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200808082109.47284.wolfgang.walter@stwm.de \
    --to=wolfgang.walter@stwm.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=suresh.b.siddha@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®