Re: [rfc patch] i386: don't save eflags on task switch

From: Linus Torvalds
Date: Sun Nov 05 2006 - 13:04:21 EST




On Sun, 5 Nov 2006, Arjan van de Ven wrote:
>
> actually lockdep is pretty good at finding this type of bug IMMEDIATELY
> even without the actual race triggering ;)

Ehh. Last time this happened, lockdep didn't find _squat_.

This was when NT and AC leaked across context switches, because the
context switching had removed the "expensive" save/restore.

The thing is, complexity is in the unintended side effects, not in the
code itself. For example, let's say that we changed "restore_flags()" to
do

static inline void restore_flags(unsigned long x)
{
if (x & 0x200)
asm volatile("sti");
}

(I didn't check that IF is 0x200, but it's something like that) and it was
two cycles faster on average than just doing a "popf". The _complexity_
here is that now there might be some other x86-architecture-specific code
sequence that nobody even _realized_ actually depended on saving the other
flags too. Like the context switching thing did.

Is it likely? Maybe not. But that's the thing about complexity - you'd not
know, would you?

Do a few of these kinds of things, and _individually_ they are unlikely to
add new bugs, but once you've done ten or twenty of them, the likelihood
that _one_ of them added a subtle bug that it will take months or years to
find is suddenly not all that small any more.

This is why "robust" is so important. So _much_ more important than a
cycle or two. The fact is, saving and restoring all the eflags over a
context switch is just _more_robust_. If you do a pushfl/popfl, there's
simply not a lot you can screw up.

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/