netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suresh Siddha <suresh.b.siddha@intel.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "Siddha, Suresh B" <suresh.b.siddha@intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Wolfgang Walter <wolfgang.walter@stwm.de>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	"viro@ZenIV.linux.org.uk" <viro@ZenIV.linux.org.uk>,
	"vegard.nossum@gmail.com" <vegard.nossum@gmail.com>
Subject: Re: Kernel oops with 2.6.26, padlock and ipsec: probably problem with fpu state changes
Date: Sat, 9 Aug 2008 10:59:40 -0700	[thread overview]
Message-ID: <20080809175940.GE13158@linux-os.sc.intel.com> (raw)
In-Reply-To: <20080809143727.GA30499@gondor.apana.org.au>

On Sat, Aug 09, 2008 at 07:37:27AM -0700, Herbert Xu wrote:
> On Fri, Aug 08, 2008 at 04:11:21PM -0700, Suresh Siddha wrote:
> >
> > With out the recent dynamic fpu allocation changes, while we don't see oops,
> > there is a possible race still present in older kernels(for example,
> > while kernel is using kernel_fpu_begin() in some optimized clear/copy
> > page and an interrupt/softirq happens which uses these padlock
> > instructions generating DNA fault).
> 
> No this wasn't a problem because kernel_fpu_begin clears TS and
> therefore we don't get faults on SSE instructions.
> 
> However, with your patch it will become a problem due to the
> fact that it wasn't designed to be nested.

No. Here is the case that can fail on 2.6.25 aswell.

0. CPU's TS flag is set

1. kernel using FPU in some optimized copy  routine and while doing
kernel_fpu_begin() takes an interrupt just before doing clts()

2. Takes an interrupt and ipsec uses padlock instruction. And we
take a DNA fault as TS flag is still set.

3. We handle the DNA fault and set TS_USEDFPU and clear cr0.ts

4. We complete the padlock routine

5. Go back to step-1, which resumes clts() in kernel_fpu_begin(), finishes
the optimized copy routine and does kernel_fpu_end(). At this point,
we have cr0.ts again set to '1' but the task's TS_USEFPU is stilll
set and not cleared.

6. Now kernel resumes its user operation. And at the next context
switch, kernel sees it has do a FP save as TS_USEDFPU is still set
and then will do a unlazy_fpu() in __switch_to(). unlazy_fpu()
will take a DNA fault, as cr0.ts is '1' and now, because we are
in __switch_to(), math_state_restore() will get confused and will
restore the next task's FP state and will save it in prev tasks's FP state.
Remember, in __switch_to() we are already on the stack of the next task
but take a DNA fault for the prev task.

This causes the fpu leakage. We didn't encounter this so far on via
platforms because we don't have any optimized routines that use FP/SSE
in the kernel?

thanks,
suresh

  parent reply	other threads:[~2008-08-09 17:59 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-17 14:53 Kernel oops with 2.6.26 and ipsec (Was: Re: IPSEC in 2.6.25 causes stalled connections) Wolfgang Walter
2008-07-17 20:42 ` Kernel oops with 2.6.26 and ipsec Wolfgang Walter
     [not found] ` <200807301411.01622.wolfgang.walter@stwm.de>
     [not found]   ` <20080806103354.GA31623@gondor.apana.org.au>
2008-08-06 17:33     ` Kernel oops with 2.6.26, padlock and ipsec: probably problem with fpu state changes 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 [this message]
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
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=20080809175940.GE13158@linux-os.sc.intel.com \
    --to=suresh.b.siddha@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=vegard.nossum@gmail.com \
    --cc=viro@ZenIV.linux.org.uk \
    --cc=wolfgang.walter@stwm.de \
    /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;
as well as URLs for NNTP newsgroup(s).