<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/arch/x86/include/asm, branch v3.3.1</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/arch/x86/include/asm?h=v3.3.1</id>
<link rel='self' href='https://git.amat.us/linux/atom/arch/x86/include/asm?h=v3.3.1'/>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/'/>
<updated>2012-03-02T11:16:39Z</updated>
<entry>
<title>perf/x86/kvm: Fix Host-Only/Guest-Only counting with SVM disabled</title>
<updated>2012-03-02T11:16:39Z</updated>
<author>
<name>Joerg Roedel</name>
<email>joerg.roedel@amd.com</email>
</author>
<published>2012-02-29T13:57:32Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=1018faa6cf23b256bf25919ef203cd7c129f06f2'/>
<id>urn:sha1:1018faa6cf23b256bf25919ef203cd7c129f06f2</id>
<content type='text'>
It turned out that a performance counter on AMD does not
count at all when the GO or HO bit is set in the control
register and SVM is disabled in EFER.

This patch works around this issue by masking out the HO bit
in the performance counter control register when SVM is not
enabled.

The GO bit is not touched because it is only set when the
user wants to count in guest-mode only. So when SVM is
disabled the counter should not run at all and the
not-counting is the intended behaviour.

Signed-off-by: Joerg Roedel &lt;joerg.roedel@amd.com&gt;
Signed-off-by: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Cc: Avi Kivity &lt;avi@redhat.com&gt;
Cc: Stephane Eranian &lt;eranian@google.com&gt;
Cc: David Ahern &lt;dsahern@gmail.com&gt;
Cc: Gleb Natapov &lt;gleb@redhat.com&gt;
Cc: Robert Richter &lt;robert.richter@amd.com&gt;
Cc: stable@vger.kernel.org # v3.2
Link: http://lkml.kernel.org/r/1330523852-19566-1-git-send-email-joerg.roedel@amd.com
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
</content>
</entry>
<entry>
<title>i387: support lazy restore of FPU state</title>
<updated>2012-02-20T18:58:54Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-19T21:27:00Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=7e16838d94b566a17b65231073d179bc04d590c8'/>
<id>urn:sha1:7e16838d94b566a17b65231073d179bc04d590c8</id>
<content type='text'>
This makes us recognize when we try to restore FPU state that matches
what we already have in the FPU on this CPU, and avoids the restore
entirely if so.

To do this, we add two new data fields:

 - a percpu 'fpu_owner_task' variable that gets written any time we
   update the "has_fpu" field, and thus acts as a kind of back-pointer
   to the task that owns the CPU.  The exception is when we save the FPU
   state as part of a context switch - if the save can keep the FPU
   state around, we leave the 'fpu_owner_task' variable pointing at the
   task whose FP state still remains on the CPU.

 - a per-thread 'last_cpu' field, that indicates which CPU that thread
   used its FPU on last.  We update this on every context switch
   (writing an invalid CPU number if the last context switch didn't
   leave the FPU in a lazily usable state), so we know that *that*
   thread has done nothing else with the FPU since.

These two fields together can be used when next switching back to the
task to see if the CPU still matches: if 'fpu_owner_task' matches the
task we are switching to, we know that no other task (or kernel FPU
usage) touched the FPU on this CPU in the meantime, and if the current
CPU number matches the 'last_cpu' field, we know that this thread did no
other FP work on any other CPU, so the FPU state on the CPU must match
what was saved on last context switch.

In that case, we can avoid the 'f[x]rstor' entirely, and just clear the
CR0.TS bit.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: use 'restore_fpu_checking()' directly in task switching code</title>
<updated>2012-02-20T18:58:28Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-19T19:48:44Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=80ab6f1e8c981b1b6604b2f22e36c917526235cd'/>
<id>urn:sha1:80ab6f1e8c981b1b6604b2f22e36c917526235cd</id>
<content type='text'>
This inlines what is usually just a couple of instructions, but more
importantly it also fixes the theoretical error case (can that FPU
restore really ever fail? Maybe we should remove the checking).

We can't start sending signals from within the scheduler, we're much too
deep in the kernel and are holding the runqueue lock etc.  So don't
bother even trying.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: fix up some fpu_counter confusion</title>
<updated>2012-02-20T18:24:09Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-20T18:24:09Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=cea20ca3f3181fc36788a15bc65d1062b96a0a6c'/>
<id>urn:sha1:cea20ca3f3181fc36788a15bc65d1062b96a0a6c</id>
<content type='text'>
This makes sure we clear the FPU usage counter for newly created tasks,
just so that we start off in a known state (for example, don't try to
preload the FPU state on the first task switch etc).

It also fixes a thinko in when we increment the fpu_counter at task
switch time, introduced by commit 34ddc81a230b ("i387: re-introduce FPU
state preloading at context switch time").  We should increment the
*new* task fpu_counter, not the old task, and only if we decide to use
that state (whether lazily or preloaded).

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: re-introduce FPU state preloading at context switch time</title>
<updated>2012-02-18T22:03:48Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-18T20:56:35Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=34ddc81a230b15c0e345b6b253049db731499f7e'/>
<id>urn:sha1:34ddc81a230b15c0e345b6b253049db731499f7e</id>
<content type='text'>
After all the FPU state cleanups and finally finding the problem that
caused all our FPU save/restore problems, this re-introduces the
preloading of FPU state that was removed in commit b3b0870ef3ff ("i387:
do not preload FPU state at task switch time").

However, instead of simply reverting the removal, this reimplements
preloading with several fixes, most notably

 - properly abstracted as a true FPU state switch, rather than as
   open-coded save and restore with various hacks.

   In particular, implementing it as a proper FPU state switch allows us
   to optimize the CR0.TS flag accesses: there is no reason to set the
   TS bit only to then almost immediately clear it again.  CR0 accesses
   are quite slow and expensive, don't flip the bit back and forth for
   no good reason.

 - Make sure that the same model works for both x86-32 and x86-64, so
   that there are no gratuitous differences between the two due to the
   way they save and restore segment state differently due to
   architectural differences that really don't matter to the FPU state.

 - Avoid exposing the "preload" state to the context switch routines,
   and in particular allow the concept of lazy state restore: if nothing
   else has used the FPU in the meantime, and the process is still on
   the same CPU, we can avoid restoring state from memory entirely, just
   re-expose the state that is still in the FPU unit.

   That optimized lazy restore isn't actually implemented here, but the
   infrastructure is set up for it.  Of course, older CPU's that use
   'fnsave' to save the state cannot take advantage of this, since the
   state saving also trashes the state.

In other words, there is now an actual _design_ to the FPU state saving,
rather than just random historical baggage.  Hopefully it's easier to
follow as a result.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: move TS_USEDFPU flag from thread_info to task_struct</title>
<updated>2012-02-18T18:19:41Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-18T05:48:54Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=f94edacf998516ac9d849f7bc6949a703977a7f3'/>
<id>urn:sha1:f94edacf998516ac9d849f7bc6949a703977a7f3</id>
<content type='text'>
This moves the bit that indicates whether a thread has ownership of the
FPU from the TS_USEDFPU bit in thread_info-&gt;status to a word of its own
(called 'has_fpu') in task_struct-&gt;thread.has_fpu.

This fixes two independent bugs at the same time:

 - changing 'thread_info-&gt;status' from the scheduler causes nasty
   problems for the other users of that variable, since it is defined to
   be thread-synchronous (that's what the "TS_" part of the naming was
   supposed to indicate).

   So perfectly valid code could (and did) do

	ti-&gt;status |= TS_RESTORE_SIGMASK;

   and the compiler was free to do that as separate load, or and store
   instructions.  Which can cause problems with preemption, since a task
   switch could happen in between, and change the TS_USEDFPU bit. The
   change to TS_USEDFPU would be overwritten by the final store.

   In practice, this seldom happened, though, because the 'status' field
   was seldom used more than once, so gcc would generally tend to
   generate code that used a read-modify-write instruction and thus
   happened to avoid this problem - RMW instructions are naturally low
   fat and preemption-safe.

 - On x86-32, the current_thread_info() pointer would, during interrupts
   and softirqs, point to a *copy* of the real thread_info, because
   x86-32 uses %esp to calculate the thread_info address, and thus the
   separate irq (and softirq) stacks would cause these kinds of odd
   thread_info copy aliases.

   This is normally not a problem, since interrupts aren't supposed to
   look at thread information anyway (what thread is running at
   interrupt time really isn't very well-defined), but it confused the
   heck out of irq_fpu_usable() and the code that tried to squirrel
   away the FPU state.

   (It also caused untold confusion for us poor kernel developers).

It also turns out that using 'task_struct' is actually much more natural
for most of the call sites that care about the FPU state, since they
tend to work with the task struct for other reasons anyway (ie
scheduling).  And the FPU data that we are going to save/restore is
found there too.

Thanks to Arjan Van De Ven &lt;arjan@linux.intel.com&gt; for pointing us to
the %esp issue.

Cc: Arjan van de Ven &lt;arjan@linux.intel.com&gt;
Reported-and-tested-by: Raphael Prevost &lt;raphael@buro.asia&gt;
Acked-and-tested-by: Suresh Siddha &lt;suresh.b.siddha@intel.com&gt;
Tested-by: Peter Anvin &lt;hpa@zytor.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: move AMD K7/K8 fpu fxsave/fxrstor workaround from save to restore</title>
<updated>2012-02-17T03:11:15Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-17T03:11:15Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=4903062b5485f0e2c286a23b44c9b59d9b017d53'/>
<id>urn:sha1:4903062b5485f0e2c286a23b44c9b59d9b017d53</id>
<content type='text'>
The AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception is
pending.  In order to not leak FIP state from one process to another, we
need to do a floating point load after the fxsave of the old process,
and before the fxrstor of the new FPU state.  That resets the state to
the (uninteresting) kernel load, rather than some potentially sensitive
user information.

We used to do this directly after the FPU state save, but that is
actually very inconvenient, since it

 (a) corrupts what is potentially perfectly good FPU state that we might
     want to lazy avoid restoring later and

 (b) on x86-64 it resulted in a very annoying ordering constraint, where
     "__unlazy_fpu()" in the task switch needs to be delayed until after
     the DS segment has been reloaded just to get the new DS value.

Coupling it to the fxrstor instead of the fxsave automatically avoids
both of these issues, and also ensures that we only do it when actually
necessary (the FP state after a save may never actually get used).  It's
simply a much more natural place for the leaked state cleanup.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: do not preload FPU state at task switch time</title>
<updated>2012-02-16T23:45:23Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-16T23:45:23Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=b3b0870ef3ffed72b92415423da864f440f57ad6'/>
<id>urn:sha1:b3b0870ef3ffed72b92415423da864f440f57ad6</id>
<content type='text'>
Yes, taking the trap to re-load the FPU/MMX state is expensive, but so
is spending several days looking for a bug in the state save/restore
code.  And the preload code has some rather subtle interactions with
both paravirtualization support and segment state restore, so it's not
nearly as simple as it should be.

Also, now that we no longer necessarily depend on a single bit (ie
TS_USEDFPU) for keeping track of the state of the FPU, we migth be able
to do better.  If we are really switching between two processes that
keep touching the FP state, save/restore is inevitable, but in the case
of having one process that does most of the FPU usage, we may actually
be able to do much better than the preloading.

In particular, we may be able to keep track of which CPU the process ran
on last, and also per CPU keep track of which process' FP state that CPU
has.  For modern CPU's that don't destroy the FPU contents on save time,
that would allow us to do a lazy restore by just re-enabling the
existing FPU state - with no restore cost at all!

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: don't ever touch TS_USEDFPU directly, use helper functions</title>
<updated>2012-02-16T21:33:12Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-16T21:33:12Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=6d59d7a9f5b723a7ac1925c136e93ec83c0c3043'/>
<id>urn:sha1:6d59d7a9f5b723a7ac1925c136e93ec83c0c3043</id>
<content type='text'>
This creates three helper functions that do the TS_USEDFPU accesses, and
makes everybody that used to do it by hand use those helpers instead.

In addition, there's a couple of helper functions for the "change both
CR0.TS and TS_USEDFPU at the same time" case, and the places that do
that together have been changed to use those.  That means that we have
fewer random places that open-code this situation.

The intent is partly to clarify the code without actually changing any
semantics yet (since we clearly still have some hard to reproduce bug in
this area), but also to make it much easier to use another approach
entirely to caching the CR0.TS bit for software accesses.

Right now we use a bit in the thread-info 'status' variable (this patch
does not change that), but we might want to make it a full field of its
own or even make it a per-cpu variable.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>i387: move TS_USEDFPU clearing out of __save_init_fpu and into callers</title>
<updated>2012-02-16T20:22:48Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2012-02-16T20:22:48Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=b6c66418dcad0fcf83cd1d0a39482db37bf4fc41'/>
<id>urn:sha1:b6c66418dcad0fcf83cd1d0a39482db37bf4fc41</id>
<content type='text'>
Touching TS_USEDFPU without touching CR0.TS is confusing, so don't do
it.  By moving it into the callers, we always do the TS_USEDFPU next to
the CR0.TS accesses in the source code, and it's much easier to see how
the two go hand in hand.

Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
